1 /***************************************************************************//**
2 * \file cy_syspm_ppu.c
3 * \version 5.94
4 *
5 * This file provides the source code for ARM PPU Platform PD specific driver,
6 * where the API's are used by Syspm driver for Power Management.
7 *
8 *
9 ********************************************************************************
10 * \copyright
11 * Copyright 2016-2020 Cypress Semiconductor Corporation
12 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 *******************************************************************************/
26
27 #include "cy_device.h"
28
29 #if defined (CY_IP_MXS28SRSS) || defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
30
31 #include <stdbool.h>
32 #include <ppu_v1.h>
33 #include <cy_syspm_ppu.h>
34 #include "cy_syslib.h"
35 #include "cy_syspm.h"
36
37 /**
38 * \addtogroup group_syspm_ppu_functions
39 * \{
40 */
41
42 /*******************************************************************************
43 * Function Name: cy_pd_ppu_init
44 ****************************************************************************//**
45 *
46 * Initializes the PD PPU Driver.
47 *
48 * \param ppu
49 * This parameter contains PPU base pointer for which the initialization has
50 * to be done.
51 *
52 * \return the PD PPU API status \ref cy_en_syspm_status_t.
53 *
54 *******************************************************************************/
cy_pd_ppu_init(struct ppu_v1_reg * ppu)55 cy_en_syspm_status_t cy_pd_ppu_init(struct ppu_v1_reg *ppu)
56 {
57 CY_ASSERT(ppu != NULL);
58
59 ppu_v1_init(ppu);
60
61 return CY_SYSPM_SUCCESS;
62 }
63
64 /*******************************************************************************
65 * Function Name: cy_pd_ppu_get_programmed_power_mode
66 ****************************************************************************//**
67 *
68 * Gets the programmed power mode of the particular PPU.
69 *
70 * \param ppu
71 * This parameter contains PPU base pointer for which the initialization has
72 * to be done.
73 *
74 * \return Returns the PPU Programmed Power mode
75 *
76 *******************************************************************************/
77
cy_pd_ppu_get_programmed_power_mode(struct ppu_v1_reg * ppu)78 enum ppu_v1_mode cy_pd_ppu_get_programmed_power_mode(struct ppu_v1_reg *ppu)
79 {
80 CY_ASSERT(ppu != NULL);
81 return ppu_v1_get_programmed_power_mode(ppu);
82 }
83
84
85 /*******************************************************************************
86 * Function Name: cy_pd_ppu_get_power_mode
87 ****************************************************************************//**
88 *
89 * Gets the current power mode of the particular PPU.
90 *
91 * \param ppu
92 * This parameter contains PPU base pointer for which the initialization has
93 * to be done.
94 *
95 * \return Returns the PPU Current Power mode
96 *
97 *******************************************************************************/
98
cy_pd_ppu_get_power_mode(struct ppu_v1_reg * ppu)99 enum ppu_v1_mode cy_pd_ppu_get_power_mode(struct ppu_v1_reg *ppu)
100 {
101 CY_ASSERT(ppu != NULL);
102 return ppu_v1_get_power_mode(ppu);
103 }
104
105 /*******************************************************************************
106 * Function Name: cy_pd_ppu_set_power_mode
107 ****************************************************************************//**
108 *
109 * Sets the required power mode of the particular PPU.
110 *
111 * \param ppu
112 * This parameter contains PPU base pointer for which the initialization has
113 * to be done.
114 *
115 * \param mode
116 * Contains the future power mode to be set for the PPU.
117 *
118 * \return the PD PPU API status \ref cy_en_syspm_status_t.
119 *
120 *******************************************************************************/
121
cy_pd_ppu_set_power_mode(struct ppu_v1_reg * ppu,uint32_t mode)122 cy_en_syspm_status_t cy_pd_ppu_set_power_mode(struct ppu_v1_reg *ppu, uint32_t mode)
123 {
124 cy_en_syspm_status_t status = CY_SYSPM_INVALID_STATE;
125 CY_ASSERT(ppu != NULL);
126 CY_ASSERT(mode < PPU_V1_MODE_COUNT);
127
128 (void)ppu_v1_dynamic_enable(ppu, (enum ppu_v1_mode) mode); /* Suppress a compiler warning about unused return value */
129
130 return status;
131 }
132
133 /*******************************************************************************
134 * Function Name: cy_pd_ppu_set_static_power_mode
135 ****************************************************************************//**
136 *
137 * Sets the required static power mode of the particular PPU.
138 *
139 * \param ppu
140 * This parameter contains PPU base pointer for which the initialization has
141 * to be done.
142 *
143 * \param mode
144 * Contains the future power mode to be set for the PPU.
145 *
146 * \return the PD PPU API status \ref cy_en_syspm_status_t.
147 *
148 *******************************************************************************/
149
cy_pd_ppu_set_static_power_mode(struct ppu_v1_reg * ppu,uint32_t mode)150 cy_en_syspm_status_t cy_pd_ppu_set_static_power_mode(struct ppu_v1_reg *ppu, uint32_t mode)
151 {
152 cy_en_syspm_status_t status = CY_SYSPM_INVALID_STATE;
153 CY_ASSERT(ppu != NULL);
154 CY_ASSERT(mode < PPU_V1_MODE_COUNT);
155
156 (void)ppu_v1_set_power_mode(ppu, (enum ppu_v1_mode) mode); /* Suppress a compiler warning about unused return value */
157
158 return status;
159 }
160
161
162
163 /*******************************************************************************
164 * Function Name: cy_pd_ppu_reset
165 ****************************************************************************//**
166 *
167 * Resets the PD using PPU.
168 *
169 * \param ppu
170 * This parameter contains PPU base pointer for which the initialization has
171 * to be done.
172 *
173 * \return the PD PPU API status \ref cy_en_syspm_status_t.
174 *
175 *******************************************************************************/
176
cy_pd_ppu_reset(struct ppu_v1_reg * ppu)177 cy_en_syspm_status_t cy_pd_ppu_reset(struct ppu_v1_reg *ppu)
178 {
179 cy_en_syspm_status_t status;
180 CY_ASSERT(ppu != NULL);
181
182 status = cy_pd_ppu_set_power_mode(ppu, (uint32_t)PPU_V1_MODE_OFF);
183 if (status == CY_SYSPM_SUCCESS)
184 {
185 status = cy_pd_ppu_set_power_mode(ppu, (uint32_t)PPU_V1_MODE_ON);
186 }
187
188 return status;
189 }
190
191 /*******************************************************************************
192 * Function Name: cy_pd_ppu_get_ds_fail_device
193 ****************************************************************************//**
194 *
195 * Gets the PPU's device ID(s) which caused the Deepsleep Failure.
196 *
197 * \param ppu
198 * This parameter contains PPU base pointer for which the initialization has
199 * to be done.
200 *
201 * \return Returns the PPU's device ID which caused the Deepsleep Failure
202 *
203 *******************************************************************************/
cy_pd_ppu_get_ds_fail_device(struct ppu_v1_reg * ppu)204 cy_pd_ppu_device_status_t cy_pd_ppu_get_ds_fail_device(struct ppu_v1_reg *ppu)
205 {
206 CY_ASSERT(ppu != NULL);
207 return (cy_pd_ppu_device_status_t)ppu_v1_get_failure_device_id(ppu);
208 }
209
210 /** \} group_syspm_ppu_functions */
211
212 #endif /* CY_IP_MXS28SRSS,CY_IP_MXS40SSRSS */
213