blob: ef2ac982171fc41fe43e552e649234fde09664d7 [file] [log] [blame]
Aneesh V0d2628b2011-07-21 09:10:07 -04001/*
2 *
3 * Clock initialization for OMAP4
4 *
5 * (C) Copyright 2010
6 * Texas Instruments, <www.ti.com>
7 *
8 * Aneesh V <aneesh@ti.com>
9 *
10 * Based on previous work by:
11 * Santosh Shilimkar <santosh.shilimkar@ti.com>
12 * Rajendra Nayak <rnayak@ti.com>
13 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020014 * SPDX-License-Identifier: GPL-2.0+
Aneesh V0d2628b2011-07-21 09:10:07 -040015 */
16#include <common.h>
Lokesh Vutla36852972013-05-30 03:19:29 +000017#include <i2c.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040018#include <asm/omap_common.h>
Sanjeev Premi0c2c8ac2011-09-08 10:48:39 -040019#include <asm/gpio.h>
Lokesh Vutla61c517f2013-05-30 02:54:32 +000020#include <asm/arch/clock.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040021#include <asm/arch/sys_proto.h>
22#include <asm/utils.h>
Aneesh V0fa1d1b2011-07-21 09:29:32 -040023#include <asm/omap_gpio.h>
Lokesh Vutlafef54c32013-02-04 04:21:59 +000024#include <asm/emif.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040025
26#ifndef CONFIG_SPL_BUILD
27/*
28 * printing to console doesn't work unless
29 * this code is executed from SPL
30 */
31#define printf(fmt, args...)
32#define puts(s)
33#endif
34
SRICHARAN R1a79cab2013-02-04 04:22:01 +000035const u32 sys_clk_array[8] = {
36 12000000, /* 12 MHz */
Lokesh Vutla16523262013-05-30 03:19:38 +000037 20000000, /* 20 MHz */
SRICHARAN R1a79cab2013-02-04 04:22:01 +000038 16800000, /* 16.8 MHz */
39 19200000, /* 19.2 MHz */
40 26000000, /* 26 MHz */
41 27000000, /* 27 MHz */
42 38400000, /* 38.4 MHz */
43};
44
Aneesh V0d2628b2011-07-21 09:10:07 -040045static inline u32 __get_sys_clk_index(void)
46{
Lokesh Vutla5e70e292013-02-12 21:29:05 +000047 s8 ind;
Aneesh V0d2628b2011-07-21 09:10:07 -040048 /*
49 * For ES1 the ROM code calibration of sys clock is not reliable
50 * due to hw issue. So, use hard-coded value. If this value is not
51 * correct for any board over-ride this function in board file
52 * From ES2.0 onwards you will get this information from
53 * CM_SYS_CLKSEL
54 */
55 if (omap_revision() == OMAP4430_ES1_0)
56 ind = OMAP_SYS_CLK_IND_38_4_MHZ;
57 else {
58 /* SYS_CLKSEL - 1 to match the dpll param array indices */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +000059 ind = (readl((*prcm)->cm_sys_clksel) &
Aneesh V0d2628b2011-07-21 09:10:07 -040060 CM_SYS_CLKSEL_SYS_CLKSEL_MASK) - 1;
61 }
62 return ind;
63}
64
65u32 get_sys_clk_index(void)
66 __attribute__ ((weak, alias("__get_sys_clk_index")));
67
68u32 get_sys_clk_freq(void)
69{
70 u8 index = get_sys_clk_index();
71 return sys_clk_array[index];
72}
73
SRICHARAN R1a79cab2013-02-04 04:22:01 +000074void setup_post_dividers(u32 const base, const struct dpll_params *params)
75{
76 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
77
78 /* Setup post-dividers */
79 if (params->m2 >= 0)
80 writel(params->m2, &dpll_regs->cm_div_m2_dpll);
81 if (params->m3 >= 0)
82 writel(params->m3, &dpll_regs->cm_div_m3_dpll);
83 if (params->m4_h11 >= 0)
84 writel(params->m4_h11, &dpll_regs->cm_div_m4_h11_dpll);
85 if (params->m5_h12 >= 0)
86 writel(params->m5_h12, &dpll_regs->cm_div_m5_h12_dpll);
87 if (params->m6_h13 >= 0)
88 writel(params->m6_h13, &dpll_regs->cm_div_m6_h13_dpll);
89 if (params->m7_h14 >= 0)
90 writel(params->m7_h14, &dpll_regs->cm_div_m7_h14_dpll);
SRICHARAN Ra04ed142013-02-12 01:33:43 +000091 if (params->h21 >= 0)
92 writel(params->h21, &dpll_regs->cm_div_h21_dpll);
SRICHARAN R1a79cab2013-02-04 04:22:01 +000093 if (params->h22 >= 0)
94 writel(params->h22, &dpll_regs->cm_div_h22_dpll);
95 if (params->h23 >= 0)
96 writel(params->h23, &dpll_regs->cm_div_h23_dpll);
SRICHARAN Ra04ed142013-02-12 01:33:43 +000097 if (params->h24 >= 0)
98 writel(params->h24, &dpll_regs->cm_div_h24_dpll);
SRICHARAN R1a79cab2013-02-04 04:22:01 +000099}
100
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000101static inline void do_bypass_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400102{
103 struct dpll_regs *dpll_regs = (struct dpll_regs *)base;
104
105 clrsetbits_le32(&dpll_regs->cm_clkmode_dpll,
106 CM_CLKMODE_DPLL_DPLL_EN_MASK,
107 DPLL_EN_FAST_RELOCK_BYPASS <<
108 CM_CLKMODE_DPLL_EN_SHIFT);
109}
110
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000111static inline void wait_for_bypass(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400112{
113 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
114
115 if (!wait_on_value(ST_DPLL_CLK_MASK, 0, &dpll_regs->cm_idlest_dpll,
116 LDELAY)) {
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000117 printf("Bypassing DPLL failed %x\n", base);
Aneesh V0d2628b2011-07-21 09:10:07 -0400118 }
119}
120
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000121static inline void do_lock_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400122{
123 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
124
125 clrsetbits_le32(&dpll_regs->cm_clkmode_dpll,
126 CM_CLKMODE_DPLL_DPLL_EN_MASK,
127 DPLL_EN_LOCK << CM_CLKMODE_DPLL_EN_SHIFT);
128}
129
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000130static inline void wait_for_lock(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400131{
132 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
133
134 if (!wait_on_value(ST_DPLL_CLK_MASK, ST_DPLL_CLK_MASK,
135 &dpll_regs->cm_idlest_dpll, LDELAY)) {
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000136 printf("DPLL locking failed for %x\n", base);
Aneesh V0d2628b2011-07-21 09:10:07 -0400137 hang();
138 }
139}
140
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000141inline u32 check_for_lock(u32 const base)
Sricharan308fe922011-11-15 09:50:03 -0500142{
143 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
144 u32 lock = readl(&dpll_regs->cm_idlest_dpll) & ST_DPLL_CLK_MASK;
145
146 return lock;
147}
148
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000149const struct dpll_params *get_mpu_dpll_params(struct dplls const *dpll_data)
150{
151 u32 sysclk_ind = get_sys_clk_index();
152 return &dpll_data->mpu[sysclk_ind];
153}
154
155const struct dpll_params *get_core_dpll_params(struct dplls const *dpll_data)
156{
157 u32 sysclk_ind = get_sys_clk_index();
158 return &dpll_data->core[sysclk_ind];
159}
160
161const struct dpll_params *get_per_dpll_params(struct dplls const *dpll_data)
162{
163 u32 sysclk_ind = get_sys_clk_index();
164 return &dpll_data->per[sysclk_ind];
165}
166
167const struct dpll_params *get_iva_dpll_params(struct dplls const *dpll_data)
168{
169 u32 sysclk_ind = get_sys_clk_index();
170 return &dpll_data->iva[sysclk_ind];
171}
172
173const struct dpll_params *get_usb_dpll_params(struct dplls const *dpll_data)
174{
175 u32 sysclk_ind = get_sys_clk_index();
176 return &dpll_data->usb[sysclk_ind];
177}
178
179const struct dpll_params *get_abe_dpll_params(struct dplls const *dpll_data)
180{
181#ifdef CONFIG_SYS_OMAP_ABE_SYSCK
182 u32 sysclk_ind = get_sys_clk_index();
183 return &dpll_data->abe[sysclk_ind];
184#else
185 return dpll_data->abe;
186#endif
187}
188
Lokesh Vutla5e70e292013-02-12 21:29:05 +0000189static const struct dpll_params *get_ddr_dpll_params
190 (struct dplls const *dpll_data)
191{
192 u32 sysclk_ind = get_sys_clk_index();
193
194 if (!dpll_data->ddr)
195 return NULL;
196 return &dpll_data->ddr[sysclk_ind];
197}
198
Lokesh Vutlaadc52df2013-07-08 16:04:39 +0530199#ifdef CONFIG_DRIVER_TI_CPSW
200static const struct dpll_params *get_gmac_dpll_params
201 (struct dplls const *dpll_data)
202{
203 u32 sysclk_ind = get_sys_clk_index();
204
205 if (!dpll_data->gmac)
206 return NULL;
207 return &dpll_data->gmac[sysclk_ind];
208}
209#endif
210
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000211static void do_setup_dpll(u32 const base, const struct dpll_params *params,
Sricharan308fe922011-11-15 09:50:03 -0500212 u8 lock, char *dpll)
Aneesh V0d2628b2011-07-21 09:10:07 -0400213{
Sricharan308fe922011-11-15 09:50:03 -0500214 u32 temp, M, N;
Aneesh V0d2628b2011-07-21 09:10:07 -0400215 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
216
Lokesh Vutla5e70e292013-02-12 21:29:05 +0000217 if (!params)
218 return;
219
Sricharan308fe922011-11-15 09:50:03 -0500220 temp = readl(&dpll_regs->cm_clksel_dpll);
221
222 if (check_for_lock(base)) {
223 /*
224 * The Dpll has already been locked by rom code using CH.
225 * Check if M,N are matching with Ideal nominal opp values.
226 * If matches, skip the rest otherwise relock.
227 */
228 M = (temp & CM_CLKSEL_DPLL_M_MASK) >> CM_CLKSEL_DPLL_M_SHIFT;
229 N = (temp & CM_CLKSEL_DPLL_N_MASK) >> CM_CLKSEL_DPLL_N_SHIFT;
230 if ((M != (params->m)) || (N != (params->n))) {
231 debug("\n %s Dpll locked, but not for ideal M = %d,"
232 "N = %d values, current values are M = %d,"
233 "N= %d" , dpll, params->m, params->n,
234 M, N);
235 } else {
236 /* Dpll locked with ideal values for nominal opps. */
237 debug("\n %s Dpll already locked with ideal"
238 "nominal opp values", dpll);
239 goto setup_post_dividers;
240 }
241 }
242
Aneesh V0d2628b2011-07-21 09:10:07 -0400243 bypass_dpll(base);
244
245 /* Set M & N */
Aneesh V0d2628b2011-07-21 09:10:07 -0400246 temp &= ~CM_CLKSEL_DPLL_M_MASK;
247 temp |= (params->m << CM_CLKSEL_DPLL_M_SHIFT) & CM_CLKSEL_DPLL_M_MASK;
248
249 temp &= ~CM_CLKSEL_DPLL_N_MASK;
250 temp |= (params->n << CM_CLKSEL_DPLL_N_SHIFT) & CM_CLKSEL_DPLL_N_MASK;
251
252 writel(temp, &dpll_regs->cm_clksel_dpll);
253
254 /* Lock */
255 if (lock)
256 do_lock_dpll(base);
257
Sricharan308fe922011-11-15 09:50:03 -0500258setup_post_dividers:
Sricharan9784f1f2011-11-15 09:49:58 -0500259 setup_post_dividers(base, params);
Aneesh V0d2628b2011-07-21 09:10:07 -0400260
261 /* Wait till the DPLL locks */
262 if (lock)
263 wait_for_lock(base);
264}
265
Sricharan9784f1f2011-11-15 09:49:58 -0500266u32 omap_ddr_clk(void)
Aneesh V0d2628b2011-07-21 09:10:07 -0400267{
Sricharan9784f1f2011-11-15 09:49:58 -0500268 u32 ddr_clk, sys_clk_khz, omap_rev, divider;
Aneesh V0d2628b2011-07-21 09:10:07 -0400269 const struct dpll_params *core_dpll_params;
270
Sricharan9784f1f2011-11-15 09:49:58 -0500271 omap_rev = omap_revision();
Aneesh V0d2628b2011-07-21 09:10:07 -0400272 sys_clk_khz = get_sys_clk_freq() / 1000;
273
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000274 core_dpll_params = get_core_dpll_params(*dplls_data);
Aneesh V0d2628b2011-07-21 09:10:07 -0400275
276 debug("sys_clk %d\n ", sys_clk_khz * 1000);
277
278 /* Find Core DPLL locked frequency first */
279 ddr_clk = sys_clk_khz * 2 * core_dpll_params->m /
280 (core_dpll_params->n + 1);
Sricharan9784f1f2011-11-15 09:49:58 -0500281
282 if (omap_rev < OMAP5430_ES1_0) {
283 /*
284 * DDR frequency is PHY_ROOT_CLK/2
285 * PHY_ROOT_CLK = Fdpll/2/M2
286 */
287 divider = 4;
288 } else {
289 /*
290 * DDR frequency is PHY_ROOT_CLK
291 * PHY_ROOT_CLK = Fdpll/2/M2
292 */
293 divider = 2;
294 }
Aneesh V0d2628b2011-07-21 09:10:07 -0400295
Sricharan9784f1f2011-11-15 09:49:58 -0500296 ddr_clk = ddr_clk / divider / core_dpll_params->m2;
Aneesh V0d2628b2011-07-21 09:10:07 -0400297 ddr_clk *= 1000; /* convert to Hz */
298 debug("ddr_clk %d\n ", ddr_clk);
299
300 return ddr_clk;
301}
302
Aneesh Va47a79f2011-07-21 09:29:36 -0400303/*
304 * Lock MPU dpll
305 *
306 * Resulting MPU frequencies:
307 * 4430 ES1.0 : 600 MHz
308 * 4430 ES2.x : 792 MHz (OPP Turbo)
309 * 4460 : 920 MHz (OPP Turbo) - DCC disabled
310 */
311void configure_mpu_dpll(void)
312{
313 const struct dpll_params *params;
314 struct dpll_regs *mpu_dpll_regs;
Sricharan9784f1f2011-11-15 09:49:58 -0500315 u32 omap_rev;
316 omap_rev = omap_revision();
Aneesh Va47a79f2011-07-21 09:29:36 -0400317
Sricharan9784f1f2011-11-15 09:49:58 -0500318 /*
319 * DCC and clock divider settings for 4460.
320 * DCC is required, if more than a certain frequency is required.
321 * For, 4460 > 1GHZ.
322 * 5430 > 1.4GHZ.
323 */
324 if ((omap_rev >= OMAP4460_ES1_0) && (omap_rev < OMAP5430_ES1_0)) {
Aneesh Va47a79f2011-07-21 09:29:36 -0400325 mpu_dpll_regs =
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000326 (struct dpll_regs *)((*prcm)->cm_clkmode_dpll_mpu);
327 bypass_dpll((*prcm)->cm_clkmode_dpll_mpu);
328 clrbits_le32((*prcm)->cm_mpu_mpu_clkctrl,
Aneesh Va47a79f2011-07-21 09:29:36 -0400329 MPU_CLKCTRL_CLKSEL_EMIF_DIV_MODE_MASK);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000330 setbits_le32((*prcm)->cm_mpu_mpu_clkctrl,
Aneesh Va47a79f2011-07-21 09:29:36 -0400331 MPU_CLKCTRL_CLKSEL_ABE_DIV_MODE_MASK);
332 clrbits_le32(&mpu_dpll_regs->cm_clksel_dpll,
333 CM_CLKSEL_DCC_EN_MASK);
334 }
335
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000336 params = get_mpu_dpll_params(*dplls_data);
Sricharan308fe922011-11-15 09:50:03 -0500337
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000338 do_setup_dpll((*prcm)->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu");
Aneesh Va47a79f2011-07-21 09:29:36 -0400339 debug("MPU DPLL locked\n");
340}
341
Paul Kocialkowskiec3ec832016-02-27 19:19:01 +0100342#if defined(CONFIG_USB_EHCI_OMAP) || defined(CONFIG_USB_XHCI_OMAP) || \
343 defined(CONFIG_USB_MUSB_OMAP2PLUS)
Govindraj.Rad4426b2012-02-06 03:55:36 +0000344static void setup_usb_dpll(void)
345{
346 const struct dpll_params *params;
347 u32 sys_clk_khz, sd_div, num, den;
348
349 sys_clk_khz = get_sys_clk_freq() / 1000;
350 /*
351 * USB:
352 * USB dpll is J-type. Need to set DPLL_SD_DIV for jitter correction
353 * DPLL_SD_DIV = CEILING ([DPLL_MULT/(DPLL_DIV+1)]* CLKINP / 250)
354 * - where CLKINP is sys_clk in MHz
355 * Use CLKINP in KHz and adjust the denominator accordingly so
356 * that we have enough accuracy and at the same time no overflow
357 */
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000358 params = get_usb_dpll_params(*dplls_data);
Govindraj.Rad4426b2012-02-06 03:55:36 +0000359 num = params->m * sys_clk_khz;
360 den = (params->n + 1) * 250 * 1000;
361 num += den - 1;
362 sd_div = num / den;
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000363 clrsetbits_le32((*prcm)->cm_clksel_dpll_usb,
Govindraj.Rad4426b2012-02-06 03:55:36 +0000364 CM_CLKSEL_DPLL_DPLL_SD_DIV_MASK,
365 sd_div << CM_CLKSEL_DPLL_DPLL_SD_DIV_SHIFT);
366
367 /* Now setup the dpll with the regular function */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000368 do_setup_dpll((*prcm)->cm_clkmode_dpll_usb, params, DPLL_LOCK, "usb");
Govindraj.Rad4426b2012-02-06 03:55:36 +0000369}
370#endif
371
Aneesh V0d2628b2011-07-21 09:10:07 -0400372static void setup_dplls(void)
373{
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000374 u32 temp;
Aneesh V0d2628b2011-07-21 09:10:07 -0400375 const struct dpll_params *params;
Tom Rinibe8d6352015-06-05 15:51:11 +0530376 struct emif_reg_struct *emif = (struct emif_reg_struct *)EMIF1_BASE;
Aneesh V0d2628b2011-07-21 09:10:07 -0400377
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000378 debug("setup_dplls\n");
Aneesh V0d2628b2011-07-21 09:10:07 -0400379
380 /* CORE dpll */
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000381 params = get_core_dpll_params(*dplls_data); /* default - safest */
Aneesh V0d2628b2011-07-21 09:10:07 -0400382 /*
383 * Do not lock the core DPLL now. Just set it up.
384 * Core DPLL will be locked after setting up EMIF
385 * using the FREQ_UPDATE method(freq_update_core())
386 */
Tom Rinibe8d6352015-06-05 15:51:11 +0530387 if (emif_sdram_type(readl(&emif->emif_sdram_config)) ==
388 EMIF_SDRAM_TYPE_LPDDR2)
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000389 do_setup_dpll((*prcm)->cm_clkmode_dpll_core, params,
Lokesh Vutlacdfc4ea2012-05-22 00:03:26 +0000390 DPLL_NO_LOCK, "core");
391 else
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000392 do_setup_dpll((*prcm)->cm_clkmode_dpll_core, params,
Lokesh Vutlacdfc4ea2012-05-22 00:03:26 +0000393 DPLL_LOCK, "core");
Aneesh V0d2628b2011-07-21 09:10:07 -0400394 /* Set the ratios for CORE_CLK, L3_CLK, L4_CLK */
395 temp = (CLKSEL_CORE_X2_DIV_1 << CLKSEL_CORE_SHIFT) |
396 (CLKSEL_L3_CORE_DIV_2 << CLKSEL_L3_SHIFT) |
397 (CLKSEL_L4_L3_DIV_2 << CLKSEL_L4_SHIFT);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000398 writel(temp, (*prcm)->cm_clksel_core);
Aneesh V0d2628b2011-07-21 09:10:07 -0400399 debug("Core DPLL configured\n");
400
401 /* lock PER dpll */
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000402 params = get_per_dpll_params(*dplls_data);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000403 do_setup_dpll((*prcm)->cm_clkmode_dpll_per,
Sricharan308fe922011-11-15 09:50:03 -0500404 params, DPLL_LOCK, "per");
Aneesh V0d2628b2011-07-21 09:10:07 -0400405 debug("PER DPLL locked\n");
406
407 /* MPU dpll */
Aneesh Va47a79f2011-07-21 09:29:36 -0400408 configure_mpu_dpll();
Govindraj.Rad4426b2012-02-06 03:55:36 +0000409
Paul Kocialkowskiec3ec832016-02-27 19:19:01 +0100410#if defined(CONFIG_USB_EHCI_OMAP) || defined(CONFIG_USB_XHCI_OMAP) || \
411 defined(CONFIG_USB_MUSB_OMAP2PLUS)
Govindraj.Rad4426b2012-02-06 03:55:36 +0000412 setup_usb_dpll();
413#endif
Lokesh Vutla5e70e292013-02-12 21:29:05 +0000414 params = get_ddr_dpll_params(*dplls_data);
415 do_setup_dpll((*prcm)->cm_clkmode_dpll_ddrphy,
416 params, DPLL_LOCK, "ddr");
Lokesh Vutlaadc52df2013-07-08 16:04:39 +0530417
418#ifdef CONFIG_DRIVER_TI_CPSW
419 params = get_gmac_dpll_params(*dplls_data);
420 do_setup_dpll((*prcm)->cm_clkmode_dpll_gmac, params,
421 DPLL_LOCK, "gmac");
422#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400423}
424
SRICHARAN R00d328c2013-02-04 04:22:02 +0000425u32 get_offset_code(u32 volt_offset, struct pmic_data *pmic)
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400426{
SRICHARAN R00d328c2013-02-04 04:22:02 +0000427 u32 offset_code;
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400428
SRICHARAN R00d328c2013-02-04 04:22:02 +0000429 volt_offset -= pmic->base_offset;
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400430
SRICHARAN R00d328c2013-02-04 04:22:02 +0000431 offset_code = (volt_offset + pmic->step - 1) / pmic->step;
Nishanth Menona0f45c12012-03-01 14:17:38 +0000432
SRICHARAN R00d328c2013-02-04 04:22:02 +0000433 /*
434 * Offset codes 1-6 all give the base voltage in Palmas
435 * Offset code 0 switches OFF the SMPS
436 */
437 return offset_code + pmic->start_code;
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400438}
439
SRICHARAN R00d328c2013-02-04 04:22:02 +0000440void do_scale_vcore(u32 vcore_reg, u32 volt_mv, struct pmic_data *pmic)
Aneesh V0d2628b2011-07-21 09:10:07 -0400441{
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000442 u32 offset_code;
Aneesh V0d2628b2011-07-21 09:10:07 -0400443 u32 offset = volt_mv;
Lubomir Popov21f34062014-12-19 17:34:31 +0200444#ifndef CONFIG_DRA7XX
SRICHARAN R00d328c2013-02-04 04:22:02 +0000445 int ret = 0;
Lubomir Popov21f34062014-12-19 17:34:31 +0200446#endif
SRICHARAN R00d328c2013-02-04 04:22:02 +0000447
Lokesh Vutla36852972013-05-30 03:19:29 +0000448 if (!volt_mv)
449 return;
450
Lokesh Vutlaae49f6d2013-05-30 02:54:33 +0000451 pmic->pmic_bus_init();
Lubomir Popov21f34062014-12-19 17:34:31 +0200452#ifndef CONFIG_DRA7XX
SRICHARAN R00d328c2013-02-04 04:22:02 +0000453 /* See if we can first get the GPIO if needed */
454 if (pmic->gpio_en)
455 ret = gpio_request(pmic->gpio, "PMIC_GPIO");
456
457 if (ret < 0) {
458 printf("%s: gpio %d request failed %d\n", __func__,
459 pmic->gpio, ret);
460 return;
461 }
462
463 /* Pull the GPIO low to select SET0 register, while we program SET1 */
464 if (pmic->gpio_en)
465 gpio_direction_output(pmic->gpio, 0);
Lubomir Popov21f34062014-12-19 17:34:31 +0200466#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400467 /* convert to uV for better accuracy in the calculations */
468 offset *= 1000;
469
SRICHARAN R00d328c2013-02-04 04:22:02 +0000470 offset_code = get_offset_code(offset, pmic);
Aneesh V0d2628b2011-07-21 09:10:07 -0400471
472 debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv,
473 offset_code);
SRICHARAN R698a1f22012-03-12 02:25:38 +0000474
Lokesh Vutlaae49f6d2013-05-30 02:54:33 +0000475 if (pmic->pmic_write(pmic->i2c_slave_addr, vcore_reg, offset_code))
Aneesh V0d2628b2011-07-21 09:10:07 -0400476 printf("Scaling voltage failed for 0x%x\n", vcore_reg);
Lubomir Popov21f34062014-12-19 17:34:31 +0200477#ifndef CONFIG_DRA7XX
SRICHARAN R00d328c2013-02-04 04:22:02 +0000478 if (pmic->gpio_en)
479 gpio_direction_output(pmic->gpio, 1);
Lubomir Popov21f34062014-12-19 17:34:31 +0200480#endif
SRICHARAN R00d328c2013-02-04 04:22:02 +0000481}
482
Nishanth Menon93cdb282013-05-30 03:19:31 +0000483static u32 optimize_vcore_voltage(struct volts const *v)
484{
485 u32 val;
486 if (!v->value)
487 return 0;
488 if (!v->efuse.reg)
489 return v->value;
490
491 switch (v->efuse.reg_bits) {
492 case 16:
493 val = readw(v->efuse.reg);
494 break;
495 case 32:
496 val = readl(v->efuse.reg);
497 break;
498 default:
499 printf("Error: efuse 0x%08x bits=%d unknown\n",
500 v->efuse.reg, v->efuse.reg_bits);
501 return v->value;
502 }
503
504 if (!val) {
505 printf("Error: efuse 0x%08x bits=%d val=0, using %d\n",
506 v->efuse.reg, v->efuse.reg_bits, v->value);
507 return v->value;
508 }
509
510 debug("%s:efuse 0x%08x bits=%d Vnom=%d, using efuse value %d\n",
511 __func__, v->efuse.reg, v->efuse.reg_bits, v->value, val);
512 return val;
513}
514
Lokesh Vutla3de40ac2015-06-04 16:42:36 +0530515#ifdef CONFIG_IODELAY_RECALIBRATION
516void __weak recalibrate_iodelay(void)
517{
518}
519#endif
520
SRICHARAN R00d328c2013-02-04 04:22:02 +0000521/*
Lubomir Popov21f34062014-12-19 17:34:31 +0200522 * Setup the voltages for the main SoC core power domains.
523 * We start with the maximum voltages allowed here, as set in the corresponding
524 * vcores_data struct, and then scale (usually down) to the fused values that
525 * are retrieved from the SoC. The scaling happens only if the efuse.reg fields
526 * are initialised.
527 * Rail grouping is supported for the DRA7xx SoCs only, therefore the code is
528 * compiled conditionally. Note that the new code writes the scaled (or zeroed)
529 * values back to the vcores_data struct for eventual reuse. Zero values mean
530 * that the corresponding rails are not controlled separately, and are not sent
531 * to the PMIC.
SRICHARAN R00d328c2013-02-04 04:22:02 +0000532 */
533void scale_vcores(struct vcores_data const *vcores)
534{
Lubomir Popov21f34062014-12-19 17:34:31 +0200535#if defined(CONFIG_DRA7XX)
536 int i;
537 struct volts *pv = (struct volts *)vcores;
538 struct volts *px;
539
540 for (i=0; i<(sizeof(struct vcores_data)/sizeof(struct volts)); i++) {
541 debug("%d -> ", pv->value);
542 if (pv->value) {
543 /* Handle non-empty members only */
544 pv->value = optimize_vcore_voltage(pv);
545 px = (struct volts *)vcores;
546 while (px < pv) {
547 /*
548 * Scan already handled non-empty members to see
549 * if we have a group and find the max voltage,
550 * which is set to the first occurance of the
551 * particular SMPS; the other group voltages are
552 * zeroed.
553 */
554 if (px->value) {
555 if ((pv->pmic->i2c_slave_addr ==
556 px->pmic->i2c_slave_addr) &&
557 (pv->addr == px->addr)) {
558 /* Same PMIC, same SMPS */
559 if (pv->value > px->value)
560 px->value = pv->value;
561
562 pv->value = 0;
563 }
564 }
565 px++;
566 }
567 }
568 debug("%d\n", pv->value);
569 pv++;
570 }
571
572 debug("cor: %d\n", vcores->core.value);
573 do_scale_vcore(vcores->core.addr, vcores->core.value, vcores->core.pmic);
Lokesh Vutla3de40ac2015-06-04 16:42:36 +0530574 /*
575 * IO delay recalibration should be done immediately after
576 * adjusting AVS voltages for VDD_CORE_L.
577 * Respective boards should call __recalibrate_iodelay()
578 * with proper mux, virtual and manual mode configurations.
579 */
580#ifdef CONFIG_IODELAY_RECALIBRATION
581 recalibrate_iodelay();
582#endif
583
Lubomir Popov21f34062014-12-19 17:34:31 +0200584 debug("mpu: %d\n", vcores->mpu.value);
585 do_scale_vcore(vcores->mpu.addr, vcores->mpu.value, vcores->mpu.pmic);
586 /* Configure MPU ABB LDO after scale */
Nishanth Menon4493e7d2016-04-21 14:34:22 -0500587 abb_setup(vcores->mpu.efuse.reg,
Lubomir Popov21f34062014-12-19 17:34:31 +0200588 (*ctrl)->control_wkup_ldovbb_mpu_voltage_ctrl,
589 (*prcm)->prm_abbldo_mpu_setup,
590 (*prcm)->prm_abbldo_mpu_ctrl,
591 (*prcm)->prm_irqstatus_mpu_2,
Nishanth Menon1eb62b42016-04-21 14:34:23 -0500592 vcores->mpu.abb_tx_done_mask,
Lubomir Popov21f34062014-12-19 17:34:31 +0200593 OMAP_ABB_FAST_OPP);
594
595 /* The .mm member is not used for the DRA7xx */
596
597 debug("gpu: %d\n", vcores->gpu.value);
598 do_scale_vcore(vcores->gpu.addr, vcores->gpu.value, vcores->gpu.pmic);
Nishanth Menon59b92af2016-04-21 14:34:25 -0500599 /* Configure GPU ABB LDO after scale */
600 abb_setup(vcores->gpu.efuse.reg,
601 (*ctrl)->control_wkup_ldovbb_gpu_voltage_ctrl,
602 (*prcm)->prm_abbldo_gpu_setup,
603 (*prcm)->prm_abbldo_gpu_ctrl,
604 (*prcm)->prm_irqstatus_mpu,
605 vcores->gpu.abb_tx_done_mask,
606 OMAP_ABB_FAST_OPP);
Lubomir Popov21f34062014-12-19 17:34:31 +0200607 debug("eve: %d\n", vcores->eve.value);
608 do_scale_vcore(vcores->eve.addr, vcores->eve.value, vcores->eve.pmic);
Nishanth Menon59b92af2016-04-21 14:34:25 -0500609 /* Configure EVE ABB LDO after scale */
610 abb_setup(vcores->eve.efuse.reg,
611 (*ctrl)->control_wkup_ldovbb_eve_voltage_ctrl,
612 (*prcm)->prm_abbldo_eve_setup,
613 (*prcm)->prm_abbldo_eve_ctrl,
614 (*prcm)->prm_irqstatus_mpu,
615 vcores->eve.abb_tx_done_mask,
616 OMAP_ABB_FAST_OPP);
Lubomir Popov21f34062014-12-19 17:34:31 +0200617 debug("iva: %d\n", vcores->iva.value);
618 do_scale_vcore(vcores->iva.addr, vcores->iva.value, vcores->iva.pmic);
Nishanth Menon59b92af2016-04-21 14:34:25 -0500619 /* Configure IVA ABB LDO after scale */
620 abb_setup(vcores->iva.efuse.reg,
621 (*ctrl)->control_wkup_ldovbb_iva_voltage_ctrl,
622 (*prcm)->prm_abbldo_iva_setup,
623 (*prcm)->prm_abbldo_iva_ctrl,
624 (*prcm)->prm_irqstatus_mpu,
625 vcores->iva.abb_tx_done_mask,
626 OMAP_ABB_FAST_OPP);
Lubomir Popov21f34062014-12-19 17:34:31 +0200627 /* Might need udelay(1000) here if debug is enabled to see all prints */
628#else
Nishanth Menon93cdb282013-05-30 03:19:31 +0000629 u32 val;
SRICHARAN R00d328c2013-02-04 04:22:02 +0000630
Nishanth Menon93cdb282013-05-30 03:19:31 +0000631 val = optimize_vcore_voltage(&vcores->core);
632 do_scale_vcore(vcores->core.addr, val, vcores->core.pmic);
633
Lokesh Vutla3de40ac2015-06-04 16:42:36 +0530634 /*
635 * IO delay recalibration should be done immediately after
636 * adjusting AVS voltages for VDD_CORE_L.
637 * Respective boards should call __recalibrate_iodelay()
638 * with proper mux, virtual and manual mode configurations.
639 */
640#ifdef CONFIG_IODELAY_RECALIBRATION
641 recalibrate_iodelay();
642#endif
643
Nishanth Menon93cdb282013-05-30 03:19:31 +0000644 val = optimize_vcore_voltage(&vcores->mpu);
645 do_scale_vcore(vcores->mpu.addr, val, vcores->mpu.pmic);
SRICHARAN R00d328c2013-02-04 04:22:02 +0000646
Andrii Tseglytskyi84bd3252013-05-20 22:42:09 +0000647 /* Configure MPU ABB LDO after scale */
Nishanth Menon4493e7d2016-04-21 14:34:22 -0500648 abb_setup(vcores->mpu.efuse.reg,
Andrii Tseglytskyi84bd3252013-05-20 22:42:09 +0000649 (*ctrl)->control_wkup_ldovbb_mpu_voltage_ctrl,
650 (*prcm)->prm_abbldo_mpu_setup,
651 (*prcm)->prm_abbldo_mpu_ctrl,
652 (*prcm)->prm_irqstatus_mpu_2,
Nishanth Menon1eb62b42016-04-21 14:34:23 -0500653 vcores->mpu.abb_tx_done_mask,
Andrii Tseglytskyi84bd3252013-05-20 22:42:09 +0000654 OMAP_ABB_FAST_OPP);
655
Nishanth Menon93cdb282013-05-30 03:19:31 +0000656 val = optimize_vcore_voltage(&vcores->mm);
657 do_scale_vcore(vcores->mm.addr, val, vcores->mm.pmic);
SRICHARAN R00d328c2013-02-04 04:22:02 +0000658
Nishanth Menon07be7572016-04-21 14:34:24 -0500659 /* Configure MM ABB LDO after scale */
660 abb_setup(vcores->mm.efuse.reg,
661 (*ctrl)->control_wkup_ldovbb_mm_voltage_ctrl,
662 (*prcm)->prm_abbldo_mm_setup,
663 (*prcm)->prm_abbldo_mm_ctrl,
664 (*prcm)->prm_irqstatus_mpu,
665 vcores->mm.abb_tx_done_mask,
666 OMAP_ABB_FAST_OPP);
667
Nishanth Menon93cdb282013-05-30 03:19:31 +0000668 val = optimize_vcore_voltage(&vcores->gpu);
669 do_scale_vcore(vcores->gpu.addr, val, vcores->gpu.pmic);
Lokesh Vutla36852972013-05-30 03:19:29 +0000670
Nishanth Menon93cdb282013-05-30 03:19:31 +0000671 val = optimize_vcore_voltage(&vcores->eve);
672 do_scale_vcore(vcores->eve.addr, val, vcores->eve.pmic);
Lokesh Vutla36852972013-05-30 03:19:29 +0000673
Nishanth Menon93cdb282013-05-30 03:19:31 +0000674 val = optimize_vcore_voltage(&vcores->iva);
675 do_scale_vcore(vcores->iva.addr, val, vcores->iva.pmic);
Lubomir Popov21f34062014-12-19 17:34:31 +0200676#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400677}
678
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000679static inline void enable_clock_domain(u32 const clkctrl_reg, u32 enable_mode)
Aneesh V0d2628b2011-07-21 09:10:07 -0400680{
681 clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK,
682 enable_mode << CD_CLKCTRL_CLKTRCTRL_SHIFT);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000683 debug("Enable clock domain - %x\n", clkctrl_reg);
Aneesh V0d2628b2011-07-21 09:10:07 -0400684}
685
Kishon Vijay Abraham I920f156f2015-08-17 13:29:51 +0530686static inline void disable_clock_domain(u32 const clkctrl_reg)
687{
688 clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK,
689 CD_CLKCTRL_CLKTRCTRL_SW_SLEEP <<
690 CD_CLKCTRL_CLKTRCTRL_SHIFT);
691 debug("Disable clock domain - %x\n", clkctrl_reg);
692}
693
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000694static inline void wait_for_clk_enable(u32 clkctrl_addr)
Aneesh V0d2628b2011-07-21 09:10:07 -0400695{
696 u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_DISABLED;
697 u32 bound = LDELAY;
698
699 while ((idlest == MODULE_CLKCTRL_IDLEST_DISABLED) ||
700 (idlest == MODULE_CLKCTRL_IDLEST_TRANSITIONING)) {
701
702 clkctrl = readl(clkctrl_addr);
703 idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >>
704 MODULE_CLKCTRL_IDLEST_SHIFT;
705 if (--bound == 0) {
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000706 printf("Clock enable failed for 0x%x idlest 0x%x\n",
Aneesh V0d2628b2011-07-21 09:10:07 -0400707 clkctrl_addr, clkctrl);
708 return;
709 }
710 }
711}
712
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000713static inline void enable_clock_module(u32 const clkctrl_addr, u32 enable_mode,
Aneesh V0d2628b2011-07-21 09:10:07 -0400714 u32 wait_for_enable)
715{
716 clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK,
717 enable_mode << MODULE_CLKCTRL_MODULEMODE_SHIFT);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000718 debug("Enable clock module - %x\n", clkctrl_addr);
Aneesh V0d2628b2011-07-21 09:10:07 -0400719 if (wait_for_enable)
720 wait_for_clk_enable(clkctrl_addr);
721}
722
Kishon Vijay Abraham I920f156f2015-08-17 13:29:51 +0530723static inline void wait_for_clk_disable(u32 clkctrl_addr)
724{
725 u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_FULLY_FUNCTIONAL;
726 u32 bound = LDELAY;
727
728 while ((idlest != MODULE_CLKCTRL_IDLEST_DISABLED)) {
729 clkctrl = readl(clkctrl_addr);
730 idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >>
731 MODULE_CLKCTRL_IDLEST_SHIFT;
732 if (--bound == 0) {
733 printf("Clock disable failed for 0x%x idlest 0x%x\n",
734 clkctrl_addr, clkctrl);
735 return;
736 }
737 }
738}
739
740static inline void disable_clock_module(u32 const clkctrl_addr,
741 u32 wait_for_disable)
742{
743 clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK,
744 MODULE_CLKCTRL_MODULEMODE_SW_DISABLE <<
745 MODULE_CLKCTRL_MODULEMODE_SHIFT);
746 debug("Disable clock module - %x\n", clkctrl_addr);
747 if (wait_for_disable)
748 wait_for_clk_disable(clkctrl_addr);
749}
750
Aneesh V0d2628b2011-07-21 09:10:07 -0400751void freq_update_core(void)
752{
753 u32 freq_config1 = 0;
754 const struct dpll_params *core_dpll_params;
SRICHARAN R3d534962012-03-12 02:25:37 +0000755 u32 omap_rev = omap_revision();
Aneesh V0d2628b2011-07-21 09:10:07 -0400756
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000757 core_dpll_params = get_core_dpll_params(*dplls_data);
Aneesh V0d2628b2011-07-21 09:10:07 -0400758 /* Put EMIF clock domain in sw wakeup mode */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000759 enable_clock_domain((*prcm)->cm_memif_clkstctrl,
Aneesh V0d2628b2011-07-21 09:10:07 -0400760 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000761 wait_for_clk_enable((*prcm)->cm_memif_emif_1_clkctrl);
762 wait_for_clk_enable((*prcm)->cm_memif_emif_2_clkctrl);
Aneesh V0d2628b2011-07-21 09:10:07 -0400763
764 freq_config1 = SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK |
765 SHADOW_FREQ_CONFIG1_DLL_RESET_MASK;
766
767 freq_config1 |= (DPLL_EN_LOCK << SHADOW_FREQ_CONFIG1_DPLL_EN_SHIFT) &
768 SHADOW_FREQ_CONFIG1_DPLL_EN_MASK;
769
770 freq_config1 |= (core_dpll_params->m2 <<
771 SHADOW_FREQ_CONFIG1_M2_DIV_SHIFT) &
772 SHADOW_FREQ_CONFIG1_M2_DIV_MASK;
773
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000774 writel(freq_config1, (*prcm)->cm_shadow_freq_config1);
Aneesh V0d2628b2011-07-21 09:10:07 -0400775 if (!wait_on_value(SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK, 0,
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000776 (u32 *) (*prcm)->cm_shadow_freq_config1, LDELAY)) {
Aneesh V0d2628b2011-07-21 09:10:07 -0400777 puts("FREQ UPDATE procedure failed!!");
778 hang();
779 }
780
SRICHARAN R3d534962012-03-12 02:25:37 +0000781 /*
782 * Putting EMIF in HW_AUTO is seen to be causing issues with
Lubomir Popova01f0b02013-04-04 05:51:45 +0000783 * EMIF clocks and the master DLL. Keep EMIF in SW_WKUP
SRICHARAN R3d534962012-03-12 02:25:37 +0000784 * in OMAP5430 ES1.0 silicon
785 */
786 if (omap_rev != OMAP5430_ES1_0) {
787 /* Put EMIF clock domain back in hw auto mode */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000788 enable_clock_domain((*prcm)->cm_memif_clkstctrl,
SRICHARAN R3d534962012-03-12 02:25:37 +0000789 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000790 wait_for_clk_enable((*prcm)->cm_memif_emif_1_clkctrl);
791 wait_for_clk_enable((*prcm)->cm_memif_emif_2_clkctrl);
SRICHARAN R3d534962012-03-12 02:25:37 +0000792 }
Aneesh V0d2628b2011-07-21 09:10:07 -0400793}
794
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000795void bypass_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400796{
797 do_bypass_dpll(base);
798 wait_for_bypass(base);
799}
800
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000801void lock_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400802{
803 do_lock_dpll(base);
804 wait_for_lock(base);
805}
806
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600807static void setup_clocks_for_console(void)
Aneesh Vb8e60b92011-07-21 09:10:21 -0400808{
809 /* Do not add any spl_debug prints in this function */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000810 clrsetbits_le32((*prcm)->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400811 CD_CLKCTRL_CLKTRCTRL_SW_WKUP <<
812 CD_CLKCTRL_CLKTRCTRL_SHIFT);
813
814 /* Enable all UARTs - console will be on one of them */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000815 clrsetbits_le32((*prcm)->cm_l4per_uart1_clkctrl,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400816 MODULE_CLKCTRL_MODULEMODE_MASK,
817 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
818 MODULE_CLKCTRL_MODULEMODE_SHIFT);
819
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000820 clrsetbits_le32((*prcm)->cm_l4per_uart2_clkctrl,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400821 MODULE_CLKCTRL_MODULEMODE_MASK,
822 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
823 MODULE_CLKCTRL_MODULEMODE_SHIFT);
824
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000825 clrsetbits_le32((*prcm)->cm_l4per_uart3_clkctrl,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400826 MODULE_CLKCTRL_MODULEMODE_MASK,
827 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
828 MODULE_CLKCTRL_MODULEMODE_SHIFT);
829
Lubomir Popova01f0b02013-04-04 05:51:45 +0000830 clrsetbits_le32((*prcm)->cm_l4per_uart4_clkctrl,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400831 MODULE_CLKCTRL_MODULEMODE_MASK,
832 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
833 MODULE_CLKCTRL_MODULEMODE_SHIFT);
834
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000835 clrsetbits_le32((*prcm)->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400836 CD_CLKCTRL_CLKTRCTRL_HW_AUTO <<
837 CD_CLKCTRL_CLKTRCTRL_SHIFT);
838}
839
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000840void do_enable_clocks(u32 const *clk_domains,
841 u32 const *clk_modules_hw_auto,
842 u32 const *clk_modules_explicit_en,
Sricharan9784f1f2011-11-15 09:49:58 -0500843 u8 wait_for_enable)
844{
845 u32 i, max = 100;
846
847 /* Put the clock domains in SW_WKUP mode */
848 for (i = 0; (i < max) && clk_domains[i]; i++) {
849 enable_clock_domain(clk_domains[i],
850 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
851 }
852
853 /* Clock modules that need to be put in HW_AUTO */
854 for (i = 0; (i < max) && clk_modules_hw_auto[i]; i++) {
855 enable_clock_module(clk_modules_hw_auto[i],
856 MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
857 wait_for_enable);
858 };
859
860 /* Clock modules that need to be put in SW_EXPLICIT_EN mode */
861 for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
862 enable_clock_module(clk_modules_explicit_en[i],
863 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
864 wait_for_enable);
865 };
866
867 /* Put the clock domains in HW_AUTO mode now */
868 for (i = 0; (i < max) && clk_domains[i]; i++) {
869 enable_clock_domain(clk_domains[i],
870 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
871 }
872}
873
Kishon Vijay Abraham I920f156f2015-08-17 13:29:51 +0530874void do_disable_clocks(u32 const *clk_domains,
875 u32 const *clk_modules_disable,
876 u8 wait_for_disable)
877{
878 u32 i, max = 100;
879
880
881 /* Clock modules that need to be put in SW_DISABLE */
882 for (i = 0; (i < max) && clk_modules_disable[i]; i++)
883 disable_clock_module(clk_modules_disable[i],
884 wait_for_disable);
885
886 /* Put the clock domains in SW_SLEEP mode */
887 for (i = 0; (i < max) && clk_domains[i]; i++)
888 disable_clock_domain(clk_domains[i]);
889}
890
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600891/**
892 * setup_early_clocks() - Setup early clocks needed for SoC
893 *
894 * Setup clocks for console, SPL basic initialization clocks and initialize
895 * the timer. This is invoked prior prcm_init.
896 */
897void setup_early_clocks(void)
Aneesh V0d2628b2011-07-21 09:10:07 -0400898{
Sricharan9310ff72011-11-15 09:49:55 -0500899 switch (omap_hw_init_context()) {
Aneesh V0d2628b2011-07-21 09:10:07 -0400900 case OMAP_INIT_CONTEXT_SPL:
901 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
902 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600903 setup_clocks_for_console();
Aneesh V9a390882011-07-21 09:29:29 -0400904 enable_basic_clocks();
Lokesh Vutlad9c839a2013-05-30 03:19:30 +0000905 timer_init();
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600906 /* Fall through */
907 }
908}
909
910void prcm_init(void)
911{
912 switch (omap_hw_init_context()) {
913 case OMAP_INIT_CONTEXT_SPL:
914 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
915 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
SRICHARAN R00d328c2013-02-04 04:22:02 +0000916 scale_vcores(*omap_vcores);
Aneesh V0d2628b2011-07-21 09:10:07 -0400917 setup_dplls();
Lokesh Vutla100c2d82013-04-17 20:49:40 +0000918 setup_warmreset_time();
Aneesh V0d2628b2011-07-21 09:10:07 -0400919 break;
920 default:
921 break;
922 }
Sricharan308fe922011-11-15 09:50:03 -0500923
924 if (OMAP_INIT_CONTEXT_SPL != omap_hw_init_context())
925 enable_basic_uboot_clocks();
Aneesh V0d2628b2011-07-21 09:10:07 -0400926}
Lokesh Vutla36852972013-05-30 03:19:29 +0000927
928void gpi2c_init(void)
929{
930 static int gpi2c = 1;
931
932 if (gpi2c) {
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200933 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
934 CONFIG_SYS_OMAP24_I2C_SLAVE);
Lokesh Vutla36852972013-05-30 03:19:29 +0000935 gpi2c = 0;
936 }
937}