blob: 265685f44135c6e52a5380d4b1a2cb859ccba7aa [file] [log] [blame]
CC Ma7d116dc2015-04-13 14:47:57 +08001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30#include <mmio.h>
31#include <mt8173_def.h>
Jimmy Huang1a1ff8b2015-11-16 14:38:40 +080032#include <debug.h>
CC Ma7d116dc2015-04-13 14:47:57 +080033#include <mtcmos.h>
34#include <spm.h>
Jimmy Huang1a1ff8b2015-11-16 14:38:40 +080035#include <spm_mcdi.h>
36#include <delay_timer.h>
CC Ma7d116dc2015-04-13 14:47:57 +080037
38enum {
39 SRAM_ISOINT_B = 1U << 6,
40 SRAM_CKISO = 1U << 5,
41 PWR_CLK_DIS = 1U << 4,
42 PWR_ON_2ND = 1U << 3,
43 PWR_ON = 1U << 2,
44 PWR_ISO = 1U << 1,
45 PWR_RST_B = 1U << 0
46};
47
48enum {
49 L1_PDN_ACK = 1U << 8,
50 L1_PDN = 1U << 0
51};
52
53enum {
54 LITTLE_CPU3 = 1U << 12,
55 LITTLE_CPU2 = 1U << 11,
56 LITTLE_CPU1 = 1U << 10,
57};
58
59enum {
60 SRAM_PDN = 0xf << 8,
61 DIS_SRAM_ACK = 0x1 << 12,
62 AUD_SRAM_ACK = 0xf << 12,
63};
64
65enum {
66 DIS_PWR_STA_MASK = 0x1 << 3,
67 AUD_PWR_STA_MASK = 0x1 << 24,
68};
69
Jimmy Huang1a1ff8b2015-11-16 14:38:40 +080070#define SPM_VDE_PWR_CON 0x0210
71#define SPM_MFG_PWR_CON 0x0214
72#define SPM_VEN_PWR_CON 0x0230
73#define SPM_ISP_PWR_CON 0x0238
74#define SPM_DIS_PWR_CON 0x023c
75#define SPM_VEN2_PWR_CON 0x0298
76#define SPM_AUDIO_PWR_CON 0x029c
77#define SPM_MFG_2D_PWR_CON 0x02c0
78#define SPM_MFG_ASYNC_PWR_CON 0x02c4
79#define SPM_USB_PWR_CON 0x02cc
80
81#define MTCMOS_CTRL_SUCCESS 0
82#define MTCMOS_CTRL_ERROR -1
83
84#define MTCMOS_CTRL_EN (0x1 << 18)
85
86#define VDE_PWR_ON 0
87#define VEN_PWR_ON 1
88#define ISP_PWR_ON 2
89#define DIS_PWR_ON 3
90#define VEN2_PWR_ON 4
91#define AUDIO_PWR_ON 5
92#define MFG_ASYNC_PWR_ON 6
93#define MFG_2D_PWR_ON 7
94#define MFG_PWR_ON 8
95#define USB_PWR_ON 9
96
97#define VDE_PWR_OFF 10
98#define VEN_PWR_OFF 11
99#define ISP_PWR_OFF 12
100#define DIS_PWR_OFF 13
101#define VEN2_PWR_OFF 14
102#define AUDIO_PWR_OFF 15
103#define MFG_ASYNC_PWR_OFF 16
104#define MFG_2D_PWR_OFF 17
105#define MFG_PWR_OFF 18
106#define USB_PWR_OFF 19
107
108#define VDE_PWR_CON_PWR_STA 7
109#define VEN_PWR_CON_PWR_STA 21
110#define ISP_PWR_CON_PWR_STA 5
111#define DIS_PWR_CON_PWR_STA 3
112#define VEN2_PWR_CON_PWR_STA 20
113#define AUDIO_PWR_CON_PWR_STA 24
114#define MFG_ASYNC_PWR_CON_PWR_STA 23
115#define MFG_2D_PWR_CON_PWR_STA 22
116#define MFG_PWR_CON_PWR_STA 4
117#define USB_PWR_CON_PWR_STA 25
118
119/*
120 * Timeout if the ack is not signled after 1 second.
121 * According to designer, one mtcmos operation should be done
122 * around 10us.
123 */
124#define MTCMOS_ACK_POLLING_MAX_COUNT 10000
125#define MTCMOS_ACK_POLLING_INTERVAL 10
126
CC Ma7d116dc2015-04-13 14:47:57 +0800127static void mtcmos_ctrl_little_off(unsigned int linear_id)
128{
129 uint32_t reg_pwr_con;
130 uint32_t reg_l1_pdn;
131 uint32_t bit_cpu;
132
133 switch (linear_id) {
134 case 1:
135 reg_pwr_con = SPM_CA7_CPU1_PWR_CON;
136 reg_l1_pdn = SPM_CA7_CPU1_L1_PDN;
137 bit_cpu = LITTLE_CPU1;
138 break;
139 case 2:
140 reg_pwr_con = SPM_CA7_CPU2_PWR_CON;
141 reg_l1_pdn = SPM_CA7_CPU2_L1_PDN;
142 bit_cpu = LITTLE_CPU2;
143 break;
144 case 3:
145 reg_pwr_con = SPM_CA7_CPU3_PWR_CON;
146 reg_l1_pdn = SPM_CA7_CPU3_L1_PDN;
147 bit_cpu = LITTLE_CPU3;
148 break;
149 default:
150 /* should never come to here */
151 return;
152 }
153
154 /* enable register control */
155 mmio_write_32(SPM_POWERON_CONFIG_SET,
156 (SPM_PROJECT_CODE << 16) | (1U << 0));
157
158 mmio_setbits_32(reg_pwr_con, PWR_ISO);
159 mmio_setbits_32(reg_pwr_con, SRAM_CKISO);
160 mmio_clrbits_32(reg_pwr_con, SRAM_ISOINT_B);
161 mmio_setbits_32(reg_l1_pdn, L1_PDN);
162
163 while (!(mmio_read_32(reg_l1_pdn) & L1_PDN_ACK))
164 continue;
165
166 mmio_clrbits_32(reg_pwr_con, PWR_RST_B);
167 mmio_setbits_32(reg_pwr_con, PWR_CLK_DIS);
168 mmio_clrbits_32(reg_pwr_con, PWR_ON);
169 mmio_clrbits_32(reg_pwr_con, PWR_ON_2ND);
170
171 while ((mmio_read_32(SPM_PWR_STATUS) & bit_cpu) ||
172 (mmio_read_32(SPM_PWR_STATUS_2ND) & bit_cpu))
173 continue;
174}
175
176void mtcmos_little_cpu_off(void)
177{
178 /* turn off little cpu 1 - 3 */
179 mtcmos_ctrl_little_off(1);
180 mtcmos_ctrl_little_off(2);
181 mtcmos_ctrl_little_off(3);
182}
Jimmy Huang1a1ff8b2015-11-16 14:38:40 +0800183
184uint32_t wait_mtcmos_ack(uint32_t on, uint32_t mtcmos_sta, uint32_t spm_pwr_sta)
185{
186 int i = 0;
187 uint32_t cmp, pwr_sta, pwr_sta_2nd;
188
189 while (1) {
190 cmp = (mmio_read_32(SPM_PCM_PASR_DPD_3) >> mtcmos_sta) & 1;
191 pwr_sta = (mmio_read_32(SPM_PWR_STATUS) >> spm_pwr_sta) & 1;
192 pwr_sta_2nd =
193 (mmio_read_32(SPM_PWR_STATUS_2ND) >> spm_pwr_sta) & 1;
194 if ((cmp == on) && (pwr_sta == on) && (pwr_sta_2nd == on)) {
195 mmio_write_32(SPM_PCM_RESERVE2, 0);
196 return MTCMOS_CTRL_SUCCESS;
197 }
198 udelay(MTCMOS_ACK_POLLING_INTERVAL);
199 i++;
200 if (i > MTCMOS_ACK_POLLING_MAX_COUNT) {
201 INFO("MTCMOS control failed(%d), SPM_PWR_STA(%d),\n"
202 "SPM_PCM_RESERVE=0x%x,SPM_PCM_RESERVE2=0x%x,\n"
203 "SPM_PWR_STATUS=0x%x,SPM_PWR_STATUS_2ND=0x%x\n"
204 "SPM_PCM_PASR_DPD_3 = 0x%x\n",
205 on, spm_pwr_sta, mmio_read_32(SPM_PCM_RESERVE),
206 mmio_read_32(SPM_PCM_RESERVE2),
207 mmio_read_32(SPM_PWR_STATUS),
208 mmio_read_32(SPM_PWR_STATUS_2ND),
209 mmio_read_32(SPM_PCM_PASR_DPD_3));
210 mmio_write_32(SPM_PCM_RESERVE2, 0);
211 return MTCMOS_CTRL_ERROR;
212 }
213 }
214}
215
216uint32_t mtcmos_non_cpu_ctrl(uint32_t on, uint32_t mtcmos_num)
217{
218 uint32_t ret = MTCMOS_CTRL_SUCCESS;
219 uint32_t power_on;
220 uint32_t power_off;
221 uint32_t power_status;
222
223 spm_lock_get();
224 spm_mcdi_prepare_for_mtcmos();
225 mmio_setbits_32(SPM_PCM_RESERVE, MTCMOS_CTRL_EN);
226
227 switch (mtcmos_num) {
228 case SPM_VDE_PWR_CON:
229 power_on = VDE_PWR_ON;
230 power_off = VDE_PWR_OFF;
231 power_status = VDE_PWR_CON_PWR_STA;
232 break;
233 case SPM_MFG_PWR_CON:
234 power_on = MFG_PWR_ON;
235 power_off = MFG_PWR_OFF;
236 power_status = MFG_PWR_CON_PWR_STA;
237 break;
238 case SPM_VEN_PWR_CON:
239 power_on = VEN_PWR_ON;
240 power_off = VEN_PWR_OFF;
241 power_status = VEN_PWR_CON_PWR_STA;
242 break;
243 case SPM_ISP_PWR_CON:
244 power_on = ISP_PWR_ON;
245 power_off = ISP_PWR_OFF;
246 power_status = ISP_PWR_CON_PWR_STA;
247 break;
248 case SPM_DIS_PWR_CON:
249 power_on = DIS_PWR_ON;
250 power_off = DIS_PWR_OFF;
251 power_status = DIS_PWR_CON_PWR_STA;
252 break;
253 case SPM_VEN2_PWR_CON:
254 power_on = VEN2_PWR_ON;
255 power_off = VEN2_PWR_OFF;
256 power_status = VEN2_PWR_CON_PWR_STA;
257 break;
258 case SPM_AUDIO_PWR_CON:
259 power_on = AUDIO_PWR_ON;
260 power_off = AUDIO_PWR_OFF;
261 power_status = AUDIO_PWR_CON_PWR_STA;
262 break;
263 case SPM_MFG_2D_PWR_CON:
264 power_on = MFG_2D_PWR_ON;
265 power_off = MFG_2D_PWR_OFF;
266 power_status = MFG_2D_PWR_CON_PWR_STA;
267 break;
268 case SPM_MFG_ASYNC_PWR_CON:
269 power_on = MFG_ASYNC_PWR_ON;
270 power_off = MFG_ASYNC_PWR_OFF;
271 power_status = MFG_ASYNC_PWR_CON_PWR_STA;
272 break;
273 case SPM_USB_PWR_CON:
274 power_on = USB_PWR_ON;
275 power_off = USB_PWR_OFF;
276 power_status = USB_PWR_CON_PWR_STA;
277 break;
278 default:
279 ret = MTCMOS_CTRL_ERROR;
280 INFO("No mapping MTCMOS(%d), ret = %d\n", mtcmos_num, ret);
281 break;
282 }
283
284 if (ret == MTCMOS_CTRL_SUCCESS) {
285 mmio_setbits_32(SPM_PCM_RESERVE2, on ?
286 (1 << power_on) : (1 << power_off));
287 ret = wait_mtcmos_ack(on, power_on, power_status);
288 VERBOSE("0x%x(%d), PWR_STATUS(0x%x), ret(%d)\n",
289 power_on, on, mmio_read_32(SPM_PWR_STATUS), ret);
290 }
291
292 mmio_clrbits_32(SPM_PCM_RESERVE, MTCMOS_CTRL_EN);
293 spm_lock_release();
294
295 return ret;
296}