1 /***************************************************************************//**
2 * \file cy_syspm_pdcm.c
3 * \version 5.150
4 *
5 * This file provides the source code for PDCM driver, where the API's are used
6 * by Syspm driver and BTSS driver.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2016-2020 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 *     http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25 
26 #include "cy_device.h"
27 #if defined (CY_IP_MXS22SRSS) && !defined (COMPONENT_SECURE_DEVICE)
28 #include "cy_secure_services.h"
29 #endif
30 #if defined(CY_IP_MXS40SSRSS) || defined(CY_IP_MXS22SRSS) || defined (CY_DOXYGEN)
31 
32 #include <stdbool.h>
33 #include <cy_syspm_pdcm.h>
34 
35 /* Macros */
36 #define CY_PD_PDCM_DEPENDENCY_MASK        0x00000001UL
37 #define CY_PD_PDCM_DEPENDENCY_CONFIG1     0x00000002UL
38 #define CY_PD_PDCM_DEPENDENCY_CONFIG2     0x00000003UL
39 
40 
41 /*******************************************************************************
42 * Function Name: cy_pd_pdcm_get_dependency
43 ****************************************************************************//**
44 *
45 * Gets the dependency between two Power Domains.
46 *
47 *  \param host_pd
48 *  This parameter contains the Host Power Domain ID from where the dependency
49 *  has to be obtained at w.r.to dest_pd(Destination Power Domain).
50 *  \ref cy_pd_pdcm_id_t.
51 *
52 *  \param dest_pd
53 *  This parameter contains the Destination Power Domain ID \ref cy_pd_pdcm_id_t
54 *
55 *  \return Contains the dependency \ref cy_pd_pdcm_dep_t
56 *
57 *******************************************************************************/
cy_pd_pdcm_get_dependency(cy_pd_pdcm_id_t host_pd,cy_pd_pdcm_id_t dest_pd)58 cy_pd_pdcm_dep_t cy_pd_pdcm_get_dependency(cy_pd_pdcm_id_t host_pd,cy_pd_pdcm_id_t dest_pd)
59 {
60     uint32_t dep;
61 
62     CY_ASSERT(CY_SYSPM_IS_PDCM_ID_VALID(host_pd));
63     CY_ASSERT(CY_SYSPM_IS_PDCM_ID_VALID(dest_pd));
64 #if defined(NO_RPC_CALL) || !defined (CY_IP_MXS22SRSS) || (defined (COMPONENT_SECURE_DEVICE) && defined (CY_IP_MXS22SRSS))
65     dep = (((_FLD2VAL(PWRMODE_PD_PD_SPT_PD_FORCE_ON, CY_PDCM_PD_SPT(host_pd)) >> ((uint32_t)dest_pd)) & CY_PD_PDCM_DEPENDENCY_MASK) |
66             (((_FLD2VAL(PWRMODE_PD_PD_SPT_PD_CONFIG_ON, CY_PDCM_PD_SPT(host_pd)) >> ((uint32_t)dest_pd)) & CY_PD_PDCM_DEPENDENCY_MASK ) << CY_PD_PDCM_DEPENDENCY_MASK));
67 
68     if((dep == CY_PD_PDCM_DEPENDENCY_CONFIG1) || (dep == CY_PD_PDCM_DEPENDENCY_CONFIG2))
69     {
70         dep = (uint32_t)CY_PD_PDCM_DEP_CONFIG;
71     }
72 #else
73     cy_rpc_args_t rpcArgs;
74     rpcArgs.argc = 2;
75     rpcArgs.argv[0] = (uint32_t)host_pd;
76     rpcArgs.argv[1] = (uint32_t)dest_pd;
77     dep = Cy_Send_RPC(CY_SECURE_SERVICE_TYPE_PM,
78                         (uint32_t)CY_SECURE_SERVICE_PD_PDCM_GET_DEP, &rpcArgs);
79 #endif
80     return (cy_pd_pdcm_dep_t)dep;
81 }
82 
83 /*******************************************************************************
84 * Function Name: cy_pd_pdcm_set_dependency
85 ****************************************************************************//**
86 *
87 * Set the dependency between two Power Domains.
88 *
89 *  \param host_pd
90 *  This Parameter contains the Host Power Domain ID from where the dependency
91 *  has to be set w.r.to dest_pd(Destination Power Domain).
92 *  \ref cy_pd_pdcm_id_t.
93 *
94 *  \param dest_pd
95 *  This Parameter contains the Destination Power Domain ID \ref cy_pd_pdcm_id_t
96 *
97 *  \return Contains the status of the API call \ref cy_en_syspm_status_t
98 *
99 *******************************************************************************/
cy_pd_pdcm_set_dependency(cy_pd_pdcm_id_t host_pd,cy_pd_pdcm_id_t dest_pd)100 cy_en_syspm_status_t cy_pd_pdcm_set_dependency(cy_pd_pdcm_id_t host_pd,cy_pd_pdcm_id_t dest_pd)
101 {
102     cy_en_syspm_status_t ret = CY_SYSPM_FAIL;
103     CY_ASSERT(CY_SYSPM_IS_PDCM_ID_VALID(host_pd));
104     CY_ASSERT(CY_SYSPM_IS_PDCM_ID_VALID(dest_pd));
105 #if defined(NO_RPC_CALL) || !defined (CY_IP_MXS22SRSS) || (defined (COMPONENT_SECURE_DEVICE) && defined (CY_IP_MXS22SRSS))
106     if(CY_PD_PDCM_DEP_CONFIG == cy_pd_pdcm_get_dependency(host_pd,dest_pd))
107     {
108         CY_PDCM_PD_SENSE(host_pd) |= (CY_PD_PDCM_DEPENDENCY_MASK << ((uint32_t)dest_pd));
109         ret = CY_SYSPM_SUCCESS;
110     }
111 #else
112     cy_rpc_args_t rpcArgs;
113     rpcArgs.argc = 2;
114     rpcArgs.argv[0] = (uint32_t)host_pd;
115     rpcArgs.argv[1] = (uint32_t)dest_pd;
116     ret = (cy_en_syspm_status_t)Cy_Send_RPC(CY_SECURE_SERVICE_TYPE_PM,
117             (uint32_t)CY_SECURE_SERVICE_PD_PDCM_SET_DEP, &rpcArgs);
118 #endif
119     return ret;
120 }
121 
122 /*******************************************************************************
123 * Function Name: cy_pd_pdcm_clear_dependency
124 ****************************************************************************//**
125 *
126 * Clears the dependency between two Power Domains.
127 *
128 *  \param host_pd
129 *  This parameter contains the Host Power Domain ID from where the dependency
130 *  has to be cleared w.r.to dest_pd(Destination Power Domain).
131 *  \ref cy_pd_pdcm_id_t.
132 *
133 *  \param dest_pd
134 *  This Parameter contains the Destination Power Domain ID \ref cy_pd_pdcm_id_t
135 *
136 *  \return Contains the status of the API call \ref cy_en_syspm_status_t
137 *
138 *******************************************************************************/
cy_pd_pdcm_clear_dependency(cy_pd_pdcm_id_t host_pd,cy_pd_pdcm_id_t dest_pd)139 cy_en_syspm_status_t cy_pd_pdcm_clear_dependency(cy_pd_pdcm_id_t host_pd,cy_pd_pdcm_id_t dest_pd)
140 {
141     cy_en_syspm_status_t ret = CY_SYSPM_FAIL;
142     CY_ASSERT(CY_SYSPM_IS_PDCM_ID_VALID(host_pd));
143     CY_ASSERT(CY_SYSPM_IS_PDCM_ID_VALID(dest_pd));
144 #if defined(NO_RPC_CALL) || !defined (CY_IP_MXS22SRSS) || (defined (COMPONENT_SECURE_DEVICE) && defined (CY_IP_MXS22SRSS))
145     if(CY_PD_PDCM_DEP_CONFIG == cy_pd_pdcm_get_dependency(host_pd,dest_pd))
146     {
147         CY_PDCM_PD_SENSE(host_pd) &= ~(CY_PD_PDCM_DEPENDENCY_MASK << ((uint32_t)dest_pd));
148         ret = CY_SYSPM_SUCCESS;
149     }
150 #else
151     cy_rpc_args_t rpcArgs;
152     rpcArgs.argc = 2;
153     rpcArgs.argv[0] = (uint32_t)host_pd;
154     rpcArgs.argv[1] = (uint32_t)dest_pd;
155     ret = (cy_en_syspm_status_t)Cy_Send_RPC(CY_SECURE_SERVICE_TYPE_PM,
156                       (uint32_t)CY_SECURE_SERVICE_PD_PDCM_CLEAR_DEP, &rpcArgs);
157 #endif
158     return ret;
159 }
160 
161 #endif /* CY_IP_MXS28SRSS,CY_IP_MXS40SSRSS */
162