blob: 757fa3801a14cd2a2d99a3196daeaa777e2bc9c4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Aneesh V0d2628b2011-07-21 09:10:07 -04002/*
3 *
4 * Clock initialization for OMAP4
5 *
6 * (C) Copyright 2010
7 * Texas Instruments, <www.ti.com>
8 *
9 * Aneesh V <aneesh@ti.com>
10 *
11 * Based on previous work by:
12 * Santosh Shilimkar <santosh.shilimkar@ti.com>
13 * Rajendra Nayak <rnayak@ti.com>
Aneesh V0d2628b2011-07-21 09:10:07 -040014 */
15#include <common.h>
Simon Glassf11478f2019-12-28 10:45:07 -070016#include <hang.h>
Lokesh Vutla36852972013-05-30 03:19:29 +000017#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -060018#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040020#include <asm/omap_common.h>
Sanjeev Premi0c2c8ac2011-09-08 10:48:39 -040021#include <asm/gpio.h>
Lokesh Vutla61c517f2013-05-30 02:54:32 +000022#include <asm/arch/clock.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040023#include <asm/arch/sys_proto.h>
24#include <asm/utils.h>
Aneesh V0fa1d1b2011-07-21 09:29:32 -040025#include <asm/omap_gpio.h>
Lokesh Vutlafef54c32013-02-04 04:21:59 +000026#include <asm/emif.h>
Aneesh V0d2628b2011-07-21 09:10:07 -040027
28#ifndef CONFIG_SPL_BUILD
29/*
30 * printing to console doesn't work unless
31 * this code is executed from SPL
32 */
33#define printf(fmt, args...)
34#define puts(s)
35#endif
36
SRICHARAN R1a79cab2013-02-04 04:22:01 +000037const u32 sys_clk_array[8] = {
38 12000000, /* 12 MHz */
Lokesh Vutla16523262013-05-30 03:19:38 +000039 20000000, /* 20 MHz */
SRICHARAN R1a79cab2013-02-04 04:22:01 +000040 16800000, /* 16.8 MHz */
41 19200000, /* 19.2 MHz */
42 26000000, /* 26 MHz */
43 27000000, /* 27 MHz */
44 38400000, /* 38.4 MHz */
45};
46
Aneesh V0d2628b2011-07-21 09:10:07 -040047static inline u32 __get_sys_clk_index(void)
48{
Lokesh Vutla5e70e292013-02-12 21:29:05 +000049 s8 ind;
Aneesh V0d2628b2011-07-21 09:10:07 -040050 /*
51 * For ES1 the ROM code calibration of sys clock is not reliable
52 * due to hw issue. So, use hard-coded value. If this value is not
53 * correct for any board over-ride this function in board file
54 * From ES2.0 onwards you will get this information from
55 * CM_SYS_CLKSEL
56 */
57 if (omap_revision() == OMAP4430_ES1_0)
58 ind = OMAP_SYS_CLK_IND_38_4_MHZ;
59 else {
60 /* SYS_CLKSEL - 1 to match the dpll param array indices */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +000061 ind = (readl((*prcm)->cm_sys_clksel) &
Aneesh V0d2628b2011-07-21 09:10:07 -040062 CM_SYS_CLKSEL_SYS_CLKSEL_MASK) - 1;
63 }
64 return ind;
65}
66
67u32 get_sys_clk_index(void)
68 __attribute__ ((weak, alias("__get_sys_clk_index")));
69
70u32 get_sys_clk_freq(void)
71{
72 u8 index = get_sys_clk_index();
73 return sys_clk_array[index];
74}
75
SRICHARAN R1a79cab2013-02-04 04:22:01 +000076void setup_post_dividers(u32 const base, const struct dpll_params *params)
77{
78 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
79
80 /* Setup post-dividers */
81 if (params->m2 >= 0)
82 writel(params->m2, &dpll_regs->cm_div_m2_dpll);
83 if (params->m3 >= 0)
84 writel(params->m3, &dpll_regs->cm_div_m3_dpll);
85 if (params->m4_h11 >= 0)
86 writel(params->m4_h11, &dpll_regs->cm_div_m4_h11_dpll);
87 if (params->m5_h12 >= 0)
88 writel(params->m5_h12, &dpll_regs->cm_div_m5_h12_dpll);
89 if (params->m6_h13 >= 0)
90 writel(params->m6_h13, &dpll_regs->cm_div_m6_h13_dpll);
91 if (params->m7_h14 >= 0)
92 writel(params->m7_h14, &dpll_regs->cm_div_m7_h14_dpll);
SRICHARAN Ra04ed142013-02-12 01:33:43 +000093 if (params->h21 >= 0)
94 writel(params->h21, &dpll_regs->cm_div_h21_dpll);
SRICHARAN R1a79cab2013-02-04 04:22:01 +000095 if (params->h22 >= 0)
96 writel(params->h22, &dpll_regs->cm_div_h22_dpll);
97 if (params->h23 >= 0)
98 writel(params->h23, &dpll_regs->cm_div_h23_dpll);
SRICHARAN Ra04ed142013-02-12 01:33:43 +000099 if (params->h24 >= 0)
100 writel(params->h24, &dpll_regs->cm_div_h24_dpll);
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000101}
102
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000103static inline void do_bypass_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400104{
105 struct dpll_regs *dpll_regs = (struct dpll_regs *)base;
106
107 clrsetbits_le32(&dpll_regs->cm_clkmode_dpll,
108 CM_CLKMODE_DPLL_DPLL_EN_MASK,
109 DPLL_EN_FAST_RELOCK_BYPASS <<
110 CM_CLKMODE_DPLL_EN_SHIFT);
111}
112
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000113static inline void wait_for_bypass(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400114{
115 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
116
117 if (!wait_on_value(ST_DPLL_CLK_MASK, 0, &dpll_regs->cm_idlest_dpll,
118 LDELAY)) {
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000119 printf("Bypassing DPLL failed %x\n", base);
Aneesh V0d2628b2011-07-21 09:10:07 -0400120 }
121}
122
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000123static inline void do_lock_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400124{
125 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
126
127 clrsetbits_le32(&dpll_regs->cm_clkmode_dpll,
128 CM_CLKMODE_DPLL_DPLL_EN_MASK,
129 DPLL_EN_LOCK << CM_CLKMODE_DPLL_EN_SHIFT);
130}
131
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000132static inline void wait_for_lock(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400133{
134 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
135
136 if (!wait_on_value(ST_DPLL_CLK_MASK, ST_DPLL_CLK_MASK,
137 &dpll_regs->cm_idlest_dpll, LDELAY)) {
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000138 printf("DPLL locking failed for %x\n", base);
Aneesh V0d2628b2011-07-21 09:10:07 -0400139 hang();
140 }
141}
142
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000143inline u32 check_for_lock(u32 const base)
Sricharan308fe922011-11-15 09:50:03 -0500144{
145 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
146 u32 lock = readl(&dpll_regs->cm_idlest_dpll) & ST_DPLL_CLK_MASK;
147
148 return lock;
149}
150
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000151const struct dpll_params *get_mpu_dpll_params(struct dplls const *dpll_data)
152{
153 u32 sysclk_ind = get_sys_clk_index();
154 return &dpll_data->mpu[sysclk_ind];
155}
156
157const struct dpll_params *get_core_dpll_params(struct dplls const *dpll_data)
158{
159 u32 sysclk_ind = get_sys_clk_index();
160 return &dpll_data->core[sysclk_ind];
161}
162
163const struct dpll_params *get_per_dpll_params(struct dplls const *dpll_data)
164{
165 u32 sysclk_ind = get_sys_clk_index();
166 return &dpll_data->per[sysclk_ind];
167}
168
169const struct dpll_params *get_iva_dpll_params(struct dplls const *dpll_data)
170{
171 u32 sysclk_ind = get_sys_clk_index();
172 return &dpll_data->iva[sysclk_ind];
173}
174
175const struct dpll_params *get_usb_dpll_params(struct dplls const *dpll_data)
176{
177 u32 sysclk_ind = get_sys_clk_index();
178 return &dpll_data->usb[sysclk_ind];
179}
180
181const struct dpll_params *get_abe_dpll_params(struct dplls const *dpll_data)
182{
183#ifdef CONFIG_SYS_OMAP_ABE_SYSCK
184 u32 sysclk_ind = get_sys_clk_index();
185 return &dpll_data->abe[sysclk_ind];
186#else
187 return dpll_data->abe;
188#endif
189}
190
Lokesh Vutla5e70e292013-02-12 21:29:05 +0000191static const struct dpll_params *get_ddr_dpll_params
192 (struct dplls const *dpll_data)
193{
194 u32 sysclk_ind = get_sys_clk_index();
195
196 if (!dpll_data->ddr)
197 return NULL;
198 return &dpll_data->ddr[sysclk_ind];
199}
200
Lokesh Vutlaadc52df2013-07-08 16:04:39 +0530201#ifdef CONFIG_DRIVER_TI_CPSW
202static const struct dpll_params *get_gmac_dpll_params
203 (struct dplls const *dpll_data)
204{
205 u32 sysclk_ind = get_sys_clk_index();
206
207 if (!dpll_data->gmac)
208 return NULL;
209 return &dpll_data->gmac[sysclk_ind];
210}
211#endif
212
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000213static void do_setup_dpll(u32 const base, const struct dpll_params *params,
Sricharan308fe922011-11-15 09:50:03 -0500214 u8 lock, char *dpll)
Aneesh V0d2628b2011-07-21 09:10:07 -0400215{
Sricharan308fe922011-11-15 09:50:03 -0500216 u32 temp, M, N;
Aneesh V0d2628b2011-07-21 09:10:07 -0400217 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
218
Lokesh Vutla5e70e292013-02-12 21:29:05 +0000219 if (!params)
220 return;
221
Sricharan308fe922011-11-15 09:50:03 -0500222 temp = readl(&dpll_regs->cm_clksel_dpll);
223
224 if (check_for_lock(base)) {
225 /*
226 * The Dpll has already been locked by rom code using CH.
227 * Check if M,N are matching with Ideal nominal opp values.
228 * If matches, skip the rest otherwise relock.
229 */
230 M = (temp & CM_CLKSEL_DPLL_M_MASK) >> CM_CLKSEL_DPLL_M_SHIFT;
231 N = (temp & CM_CLKSEL_DPLL_N_MASK) >> CM_CLKSEL_DPLL_N_SHIFT;
232 if ((M != (params->m)) || (N != (params->n))) {
233 debug("\n %s Dpll locked, but not for ideal M = %d,"
234 "N = %d values, current values are M = %d,"
235 "N= %d" , dpll, params->m, params->n,
236 M, N);
237 } else {
238 /* Dpll locked with ideal values for nominal opps. */
239 debug("\n %s Dpll already locked with ideal"
240 "nominal opp values", dpll);
Lokesh Vutla9bd0f9a2016-05-23 13:31:19 +0530241
242 bypass_dpll(base);
Sricharan308fe922011-11-15 09:50:03 -0500243 goto setup_post_dividers;
244 }
245 }
246
Aneesh V0d2628b2011-07-21 09:10:07 -0400247 bypass_dpll(base);
248
249 /* Set M & N */
Aneesh V0d2628b2011-07-21 09:10:07 -0400250 temp &= ~CM_CLKSEL_DPLL_M_MASK;
251 temp |= (params->m << CM_CLKSEL_DPLL_M_SHIFT) & CM_CLKSEL_DPLL_M_MASK;
252
253 temp &= ~CM_CLKSEL_DPLL_N_MASK;
254 temp |= (params->n << CM_CLKSEL_DPLL_N_SHIFT) & CM_CLKSEL_DPLL_N_MASK;
255
256 writel(temp, &dpll_regs->cm_clksel_dpll);
257
Lokesh Vutla9bd0f9a2016-05-23 13:31:19 +0530258setup_post_dividers:
259 setup_post_dividers(base, params);
260
Aneesh V0d2628b2011-07-21 09:10:07 -0400261 /* Lock */
262 if (lock)
263 do_lock_dpll(base);
264
Aneesh V0d2628b2011-07-21 09:10:07 -0400265 /* Wait till the DPLL locks */
266 if (lock)
267 wait_for_lock(base);
268}
269
Sricharan9784f1f2011-11-15 09:49:58 -0500270u32 omap_ddr_clk(void)
Aneesh V0d2628b2011-07-21 09:10:07 -0400271{
Sricharan9784f1f2011-11-15 09:49:58 -0500272 u32 ddr_clk, sys_clk_khz, omap_rev, divider;
Aneesh V0d2628b2011-07-21 09:10:07 -0400273 const struct dpll_params *core_dpll_params;
274
Sricharan9784f1f2011-11-15 09:49:58 -0500275 omap_rev = omap_revision();
Aneesh V0d2628b2011-07-21 09:10:07 -0400276 sys_clk_khz = get_sys_clk_freq() / 1000;
277
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000278 core_dpll_params = get_core_dpll_params(*dplls_data);
Aneesh V0d2628b2011-07-21 09:10:07 -0400279
280 debug("sys_clk %d\n ", sys_clk_khz * 1000);
281
282 /* Find Core DPLL locked frequency first */
283 ddr_clk = sys_clk_khz * 2 * core_dpll_params->m /
284 (core_dpll_params->n + 1);
Sricharan9784f1f2011-11-15 09:49:58 -0500285
286 if (omap_rev < OMAP5430_ES1_0) {
287 /*
288 * DDR frequency is PHY_ROOT_CLK/2
289 * PHY_ROOT_CLK = Fdpll/2/M2
290 */
291 divider = 4;
292 } else {
293 /*
294 * DDR frequency is PHY_ROOT_CLK
295 * PHY_ROOT_CLK = Fdpll/2/M2
296 */
297 divider = 2;
298 }
Aneesh V0d2628b2011-07-21 09:10:07 -0400299
Sricharan9784f1f2011-11-15 09:49:58 -0500300 ddr_clk = ddr_clk / divider / core_dpll_params->m2;
Aneesh V0d2628b2011-07-21 09:10:07 -0400301 ddr_clk *= 1000; /* convert to Hz */
302 debug("ddr_clk %d\n ", ddr_clk);
303
304 return ddr_clk;
305}
306
Aneesh Va47a79f2011-07-21 09:29:36 -0400307/*
308 * Lock MPU dpll
309 *
310 * Resulting MPU frequencies:
311 * 4430 ES1.0 : 600 MHz
312 * 4430 ES2.x : 792 MHz (OPP Turbo)
313 * 4460 : 920 MHz (OPP Turbo) - DCC disabled
314 */
315void configure_mpu_dpll(void)
316{
317 const struct dpll_params *params;
318 struct dpll_regs *mpu_dpll_regs;
Sricharan9784f1f2011-11-15 09:49:58 -0500319 u32 omap_rev;
320 omap_rev = omap_revision();
Aneesh Va47a79f2011-07-21 09:29:36 -0400321
Sricharan9784f1f2011-11-15 09:49:58 -0500322 /*
323 * DCC and clock divider settings for 4460.
324 * DCC is required, if more than a certain frequency is required.
325 * For, 4460 > 1GHZ.
326 * 5430 > 1.4GHZ.
327 */
328 if ((omap_rev >= OMAP4460_ES1_0) && (omap_rev < OMAP5430_ES1_0)) {
Aneesh Va47a79f2011-07-21 09:29:36 -0400329 mpu_dpll_regs =
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000330 (struct dpll_regs *)((*prcm)->cm_clkmode_dpll_mpu);
331 bypass_dpll((*prcm)->cm_clkmode_dpll_mpu);
332 clrbits_le32((*prcm)->cm_mpu_mpu_clkctrl,
Aneesh Va47a79f2011-07-21 09:29:36 -0400333 MPU_CLKCTRL_CLKSEL_EMIF_DIV_MODE_MASK);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000334 setbits_le32((*prcm)->cm_mpu_mpu_clkctrl,
Aneesh Va47a79f2011-07-21 09:29:36 -0400335 MPU_CLKCTRL_CLKSEL_ABE_DIV_MODE_MASK);
336 clrbits_le32(&mpu_dpll_regs->cm_clksel_dpll,
337 CM_CLKSEL_DCC_EN_MASK);
338 }
339
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000340 params = get_mpu_dpll_params(*dplls_data);
Sricharan308fe922011-11-15 09:50:03 -0500341
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000342 do_setup_dpll((*prcm)->cm_clkmode_dpll_mpu, params, DPLL_LOCK, "mpu");
Aneesh Va47a79f2011-07-21 09:29:36 -0400343 debug("MPU DPLL locked\n");
344}
345
Paul Kocialkowskiec3ec832016-02-27 19:19:01 +0100346#if defined(CONFIG_USB_EHCI_OMAP) || defined(CONFIG_USB_XHCI_OMAP) || \
347 defined(CONFIG_USB_MUSB_OMAP2PLUS)
Govindraj.Rad4426b2012-02-06 03:55:36 +0000348static void setup_usb_dpll(void)
349{
350 const struct dpll_params *params;
351 u32 sys_clk_khz, sd_div, num, den;
352
353 sys_clk_khz = get_sys_clk_freq() / 1000;
354 /*
355 * USB:
356 * USB dpll is J-type. Need to set DPLL_SD_DIV for jitter correction
357 * DPLL_SD_DIV = CEILING ([DPLL_MULT/(DPLL_DIV+1)]* CLKINP / 250)
358 * - where CLKINP is sys_clk in MHz
359 * Use CLKINP in KHz and adjust the denominator accordingly so
360 * that we have enough accuracy and at the same time no overflow
361 */
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000362 params = get_usb_dpll_params(*dplls_data);
Govindraj.Rad4426b2012-02-06 03:55:36 +0000363 num = params->m * sys_clk_khz;
364 den = (params->n + 1) * 250 * 1000;
365 num += den - 1;
366 sd_div = num / den;
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000367 clrsetbits_le32((*prcm)->cm_clksel_dpll_usb,
Govindraj.Rad4426b2012-02-06 03:55:36 +0000368 CM_CLKSEL_DPLL_DPLL_SD_DIV_MASK,
369 sd_div << CM_CLKSEL_DPLL_DPLL_SD_DIV_SHIFT);
370
371 /* Now setup the dpll with the regular function */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000372 do_setup_dpll((*prcm)->cm_clkmode_dpll_usb, params, DPLL_LOCK, "usb");
Govindraj.Rad4426b2012-02-06 03:55:36 +0000373}
374#endif
375
Aneesh V0d2628b2011-07-21 09:10:07 -0400376static void setup_dplls(void)
377{
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000378 u32 temp;
Aneesh V0d2628b2011-07-21 09:10:07 -0400379 const struct dpll_params *params;
Tom Rinibe8d6352015-06-05 15:51:11 +0530380 struct emif_reg_struct *emif = (struct emif_reg_struct *)EMIF1_BASE;
Aneesh V0d2628b2011-07-21 09:10:07 -0400381
Anatolij Gustschin20f23512011-12-03 06:46:14 +0000382 debug("setup_dplls\n");
Aneesh V0d2628b2011-07-21 09:10:07 -0400383
384 /* CORE dpll */
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000385 params = get_core_dpll_params(*dplls_data); /* default - safest */
Aneesh V0d2628b2011-07-21 09:10:07 -0400386 /*
387 * Do not lock the core DPLL now. Just set it up.
388 * Core DPLL will be locked after setting up EMIF
389 * using the FREQ_UPDATE method(freq_update_core())
390 */
Tom Rinibe8d6352015-06-05 15:51:11 +0530391 if (emif_sdram_type(readl(&emif->emif_sdram_config)) ==
392 EMIF_SDRAM_TYPE_LPDDR2)
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000393 do_setup_dpll((*prcm)->cm_clkmode_dpll_core, params,
Lokesh Vutlacdfc4ea2012-05-22 00:03:26 +0000394 DPLL_NO_LOCK, "core");
395 else
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000396 do_setup_dpll((*prcm)->cm_clkmode_dpll_core, params,
Lokesh Vutlacdfc4ea2012-05-22 00:03:26 +0000397 DPLL_LOCK, "core");
Aneesh V0d2628b2011-07-21 09:10:07 -0400398 /* Set the ratios for CORE_CLK, L3_CLK, L4_CLK */
399 temp = (CLKSEL_CORE_X2_DIV_1 << CLKSEL_CORE_SHIFT) |
400 (CLKSEL_L3_CORE_DIV_2 << CLKSEL_L3_SHIFT) |
401 (CLKSEL_L4_L3_DIV_2 << CLKSEL_L4_SHIFT);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000402 writel(temp, (*prcm)->cm_clksel_core);
Aneesh V0d2628b2011-07-21 09:10:07 -0400403 debug("Core DPLL configured\n");
404
405 /* lock PER dpll */
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000406 params = get_per_dpll_params(*dplls_data);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000407 do_setup_dpll((*prcm)->cm_clkmode_dpll_per,
Sricharan308fe922011-11-15 09:50:03 -0500408 params, DPLL_LOCK, "per");
Aneesh V0d2628b2011-07-21 09:10:07 -0400409 debug("PER DPLL locked\n");
410
411 /* MPU dpll */
Aneesh Va47a79f2011-07-21 09:29:36 -0400412 configure_mpu_dpll();
Govindraj.Rad4426b2012-02-06 03:55:36 +0000413
Paul Kocialkowskiec3ec832016-02-27 19:19:01 +0100414#if defined(CONFIG_USB_EHCI_OMAP) || defined(CONFIG_USB_XHCI_OMAP) || \
415 defined(CONFIG_USB_MUSB_OMAP2PLUS)
Govindraj.Rad4426b2012-02-06 03:55:36 +0000416 setup_usb_dpll();
417#endif
Lokesh Vutla5e70e292013-02-12 21:29:05 +0000418 params = get_ddr_dpll_params(*dplls_data);
419 do_setup_dpll((*prcm)->cm_clkmode_dpll_ddrphy,
420 params, DPLL_LOCK, "ddr");
Lokesh Vutlaadc52df2013-07-08 16:04:39 +0530421
422#ifdef CONFIG_DRIVER_TI_CPSW
423 params = get_gmac_dpll_params(*dplls_data);
424 do_setup_dpll((*prcm)->cm_clkmode_dpll_gmac, params,
425 DPLL_LOCK, "gmac");
426#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400427}
428
SRICHARAN R00d328c2013-02-04 04:22:02 +0000429u32 get_offset_code(u32 volt_offset, struct pmic_data *pmic)
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400430{
SRICHARAN R00d328c2013-02-04 04:22:02 +0000431 u32 offset_code;
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400432
SRICHARAN R00d328c2013-02-04 04:22:02 +0000433 volt_offset -= pmic->base_offset;
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400434
SRICHARAN R00d328c2013-02-04 04:22:02 +0000435 offset_code = (volt_offset + pmic->step - 1) / pmic->step;
Nishanth Menona0f45c12012-03-01 14:17:38 +0000436
SRICHARAN R00d328c2013-02-04 04:22:02 +0000437 /*
438 * Offset codes 1-6 all give the base voltage in Palmas
439 * Offset code 0 switches OFF the SMPS
440 */
441 return offset_code + pmic->start_code;
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400442}
443
SRICHARAN R00d328c2013-02-04 04:22:02 +0000444void do_scale_vcore(u32 vcore_reg, u32 volt_mv, struct pmic_data *pmic)
Aneesh V0d2628b2011-07-21 09:10:07 -0400445{
Nishanth Menon41d7ab12012-03-01 14:17:37 +0000446 u32 offset_code;
Aneesh V0d2628b2011-07-21 09:10:07 -0400447 u32 offset = volt_mv;
SRICHARAN R00d328c2013-02-04 04:22:02 +0000448 int ret = 0;
449
Lokesh Vutla36852972013-05-30 03:19:29 +0000450 if (!volt_mv)
451 return;
452
Lokesh Vutlaae49f6d2013-05-30 02:54:33 +0000453 pmic->pmic_bus_init();
SRICHARAN R00d328c2013-02-04 04:22:02 +0000454 /* See if we can first get the GPIO if needed */
455 if (pmic->gpio_en)
456 ret = gpio_request(pmic->gpio, "PMIC_GPIO");
457
458 if (ret < 0) {
459 printf("%s: gpio %d request failed %d\n", __func__,
460 pmic->gpio, ret);
461 return;
462 }
463
464 /* Pull the GPIO low to select SET0 register, while we program SET1 */
465 if (pmic->gpio_en)
466 gpio_direction_output(pmic->gpio, 0);
Lokesh Vutla266b23a2016-08-17 16:25:35 +0530467
Aneesh V0d2628b2011-07-21 09:10:07 -0400468 /* convert to uV for better accuracy in the calculations */
469 offset *= 1000;
470
SRICHARAN R00d328c2013-02-04 04:22:02 +0000471 offset_code = get_offset_code(offset, pmic);
Aneesh V0d2628b2011-07-21 09:10:07 -0400472
473 debug("do_scale_vcore: volt - %d offset_code - 0x%x\n", volt_mv,
474 offset_code);
SRICHARAN R698a1f22012-03-12 02:25:38 +0000475
Lokesh Vutlaae49f6d2013-05-30 02:54:33 +0000476 if (pmic->pmic_write(pmic->i2c_slave_addr, vcore_reg, offset_code))
Aneesh V0d2628b2011-07-21 09:10:07 -0400477 printf("Scaling voltage failed for 0x%x\n", vcore_reg);
SRICHARAN R00d328c2013-02-04 04:22:02 +0000478 if (pmic->gpio_en)
479 gpio_direction_output(pmic->gpio, 1);
480}
481
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530482int __weak get_voltrail_opp(int rail_offset)
483{
484 /*
485 * By default return OPP_NOM for all voltage rails.
486 */
487 return OPP_NOM;
488}
489
490static u32 optimize_vcore_voltage(struct volts const *v, int opp)
Nishanth Menon93cdb282013-05-30 03:19:31 +0000491{
492 u32 val;
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530493
494 if (!v->value[opp])
Nishanth Menon93cdb282013-05-30 03:19:31 +0000495 return 0;
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530496 if (!v->efuse.reg[opp])
497 return v->value[opp];
Nishanth Menon93cdb282013-05-30 03:19:31 +0000498
499 switch (v->efuse.reg_bits) {
500 case 16:
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530501 val = readw(v->efuse.reg[opp]);
Nishanth Menon93cdb282013-05-30 03:19:31 +0000502 break;
503 case 32:
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530504 val = readl(v->efuse.reg[opp]);
Nishanth Menon93cdb282013-05-30 03:19:31 +0000505 break;
506 default:
507 printf("Error: efuse 0x%08x bits=%d unknown\n",
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530508 v->efuse.reg[opp], v->efuse.reg_bits);
509 return v->value[opp];
Nishanth Menon93cdb282013-05-30 03:19:31 +0000510 }
511
512 if (!val) {
513 printf("Error: efuse 0x%08x bits=%d val=0, using %d\n",
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530514 v->efuse.reg[opp], v->efuse.reg_bits, v->value[opp]);
515 return v->value[opp];
Nishanth Menon93cdb282013-05-30 03:19:31 +0000516 }
517
518 debug("%s:efuse 0x%08x bits=%d Vnom=%d, using efuse value %d\n",
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530519 __func__, v->efuse.reg[opp], v->efuse.reg_bits, v->value[opp],
520 val);
Nishanth Menon93cdb282013-05-30 03:19:31 +0000521 return val;
522}
523
Lokesh Vutla3de40ac2015-06-04 16:42:36 +0530524#ifdef CONFIG_IODELAY_RECALIBRATION
525void __weak recalibrate_iodelay(void)
526{
527}
528#endif
529
SRICHARAN R00d328c2013-02-04 04:22:02 +0000530/*
Lubomir Popov21f34062014-12-19 17:34:31 +0200531 * Setup the voltages for the main SoC core power domains.
532 * We start with the maximum voltages allowed here, as set in the corresponding
533 * vcores_data struct, and then scale (usually down) to the fused values that
534 * are retrieved from the SoC. The scaling happens only if the efuse.reg fields
535 * are initialised.
536 * Rail grouping is supported for the DRA7xx SoCs only, therefore the code is
537 * compiled conditionally. Note that the new code writes the scaled (or zeroed)
538 * values back to the vcores_data struct for eventual reuse. Zero values mean
539 * that the corresponding rails are not controlled separately, and are not sent
540 * to the PMIC.
SRICHARAN R00d328c2013-02-04 04:22:02 +0000541 */
542void scale_vcores(struct vcores_data const *vcores)
543{
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530544 int i, opp, j, ol;
Lubomir Popov21f34062014-12-19 17:34:31 +0200545 struct volts *pv = (struct volts *)vcores;
546 struct volts *px;
547
548 for (i=0; i<(sizeof(struct vcores_data)/sizeof(struct volts)); i++) {
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530549 opp = get_voltrail_opp(i);
550 debug("%d -> ", pv->value[opp]);
551
552 if (pv->value[opp]) {
Lubomir Popov21f34062014-12-19 17:34:31 +0200553 /* Handle non-empty members only */
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530554 pv->value[opp] = optimize_vcore_voltage(pv, opp);
Lubomir Popov21f34062014-12-19 17:34:31 +0200555 px = (struct volts *)vcores;
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530556 j = 0;
Lubomir Popov21f34062014-12-19 17:34:31 +0200557 while (px < pv) {
558 /*
559 * Scan already handled non-empty members to see
560 * if we have a group and find the max voltage,
561 * which is set to the first occurance of the
562 * particular SMPS; the other group voltages are
563 * zeroed.
564 */
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530565 ol = get_voltrail_opp(j);
566 if (px->value[ol] &&
567 (pv->pmic->i2c_slave_addr ==
568 px->pmic->i2c_slave_addr) &&
569 (pv->addr == px->addr)) {
570 /* Same PMIC, same SMPS */
571 if (pv->value[opp] > px->value[ol])
572 px->value[ol] = pv->value[opp];
Lubomir Popov21f34062014-12-19 17:34:31 +0200573
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530574 pv->value[opp] = 0;
575 }
Lubomir Popov21f34062014-12-19 17:34:31 +0200576 px++;
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530577 j++;
Lubomir Popov21f34062014-12-19 17:34:31 +0200578 }
579 }
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530580 debug("%d\n", pv->value[opp]);
Lubomir Popov21f34062014-12-19 17:34:31 +0200581 pv++;
582 }
583
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530584 opp = get_voltrail_opp(VOLT_CORE);
585 debug("cor: %d\n", vcores->core.value[opp]);
586 do_scale_vcore(vcores->core.addr, vcores->core.value[opp],
587 vcores->core.pmic);
Lokesh Vutla3de40ac2015-06-04 16:42:36 +0530588 /*
589 * IO delay recalibration should be done immediately after
590 * adjusting AVS voltages for VDD_CORE_L.
591 * Respective boards should call __recalibrate_iodelay()
592 * with proper mux, virtual and manual mode configurations.
593 */
594#ifdef CONFIG_IODELAY_RECALIBRATION
595 recalibrate_iodelay();
596#endif
597
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530598 opp = get_voltrail_opp(VOLT_MPU);
599 debug("mpu: %d\n", vcores->mpu.value[opp]);
600 do_scale_vcore(vcores->mpu.addr, vcores->mpu.value[opp],
601 vcores->mpu.pmic);
Lubomir Popov21f34062014-12-19 17:34:31 +0200602 /* Configure MPU ABB LDO after scale */
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530603 abb_setup(vcores->mpu.efuse.reg[opp],
Lubomir Popov21f34062014-12-19 17:34:31 +0200604 (*ctrl)->control_wkup_ldovbb_mpu_voltage_ctrl,
605 (*prcm)->prm_abbldo_mpu_setup,
606 (*prcm)->prm_abbldo_mpu_ctrl,
607 (*prcm)->prm_irqstatus_mpu_2,
Nishanth Menon1eb62b42016-04-21 14:34:23 -0500608 vcores->mpu.abb_tx_done_mask,
Lubomir Popov21f34062014-12-19 17:34:31 +0200609 OMAP_ABB_FAST_OPP);
610
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530611 opp = get_voltrail_opp(VOLT_MM);
612 debug("mm: %d\n", vcores->mm.value[opp]);
613 do_scale_vcore(vcores->mm.addr, vcores->mm.value[opp],
614 vcores->mm.pmic);
Lokesh Vutla42eae242016-08-17 16:25:36 +0530615 /* Configure MM ABB LDO after scale */
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530616 abb_setup(vcores->mm.efuse.reg[opp],
Lokesh Vutla42eae242016-08-17 16:25:36 +0530617 (*ctrl)->control_wkup_ldovbb_mm_voltage_ctrl,
618 (*prcm)->prm_abbldo_mm_setup,
619 (*prcm)->prm_abbldo_mm_ctrl,
620 (*prcm)->prm_irqstatus_mpu,
621 vcores->mm.abb_tx_done_mask,
622 OMAP_ABB_FAST_OPP);
Lubomir Popov21f34062014-12-19 17:34:31 +0200623
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530624 opp = get_voltrail_opp(VOLT_GPU);
625 debug("gpu: %d\n", vcores->gpu.value[opp]);
626 do_scale_vcore(vcores->gpu.addr, vcores->gpu.value[opp],
627 vcores->gpu.pmic);
Nishanth Menon59b92af2016-04-21 14:34:25 -0500628 /* Configure GPU ABB LDO after scale */
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530629 abb_setup(vcores->gpu.efuse.reg[opp],
Nishanth Menon59b92af2016-04-21 14:34:25 -0500630 (*ctrl)->control_wkup_ldovbb_gpu_voltage_ctrl,
631 (*prcm)->prm_abbldo_gpu_setup,
632 (*prcm)->prm_abbldo_gpu_ctrl,
633 (*prcm)->prm_irqstatus_mpu,
634 vcores->gpu.abb_tx_done_mask,
635 OMAP_ABB_FAST_OPP);
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530636
637 opp = get_voltrail_opp(VOLT_EVE);
638 debug("eve: %d\n", vcores->eve.value[opp]);
639 do_scale_vcore(vcores->eve.addr, vcores->eve.value[opp],
640 vcores->eve.pmic);
Nishanth Menon59b92af2016-04-21 14:34:25 -0500641 /* Configure EVE ABB LDO after scale */
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530642 abb_setup(vcores->eve.efuse.reg[opp],
Nishanth Menon59b92af2016-04-21 14:34:25 -0500643 (*ctrl)->control_wkup_ldovbb_eve_voltage_ctrl,
644 (*prcm)->prm_abbldo_eve_setup,
645 (*prcm)->prm_abbldo_eve_ctrl,
646 (*prcm)->prm_irqstatus_mpu,
647 vcores->eve.abb_tx_done_mask,
648 OMAP_ABB_FAST_OPP);
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530649
650 opp = get_voltrail_opp(VOLT_IVA);
651 debug("iva: %d\n", vcores->iva.value[opp]);
652 do_scale_vcore(vcores->iva.addr, vcores->iva.value[opp],
653 vcores->iva.pmic);
Nishanth Menon59b92af2016-04-21 14:34:25 -0500654 /* Configure IVA ABB LDO after scale */
Lokesh Vutla6ede0fd2016-11-23 12:54:39 +0530655 abb_setup(vcores->iva.efuse.reg[opp],
Nishanth Menon59b92af2016-04-21 14:34:25 -0500656 (*ctrl)->control_wkup_ldovbb_iva_voltage_ctrl,
657 (*prcm)->prm_abbldo_iva_setup,
658 (*prcm)->prm_abbldo_iva_ctrl,
659 (*prcm)->prm_irqstatus_mpu,
660 vcores->iva.abb_tx_done_mask,
661 OMAP_ABB_FAST_OPP);
Aneesh V0d2628b2011-07-21 09:10:07 -0400662}
663
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000664static inline void enable_clock_domain(u32 const clkctrl_reg, u32 enable_mode)
Aneesh V0d2628b2011-07-21 09:10:07 -0400665{
666 clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK,
667 enable_mode << CD_CLKCTRL_CLKTRCTRL_SHIFT);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000668 debug("Enable clock domain - %x\n", clkctrl_reg);
Aneesh V0d2628b2011-07-21 09:10:07 -0400669}
670
Kishon Vijay Abraham I920f156f2015-08-17 13:29:51 +0530671static inline void disable_clock_domain(u32 const clkctrl_reg)
672{
673 clrsetbits_le32(clkctrl_reg, CD_CLKCTRL_CLKTRCTRL_MASK,
674 CD_CLKCTRL_CLKTRCTRL_SW_SLEEP <<
675 CD_CLKCTRL_CLKTRCTRL_SHIFT);
676 debug("Disable clock domain - %x\n", clkctrl_reg);
677}
678
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000679static inline void wait_for_clk_enable(u32 clkctrl_addr)
Aneesh V0d2628b2011-07-21 09:10:07 -0400680{
681 u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_DISABLED;
682 u32 bound = LDELAY;
683
684 while ((idlest == MODULE_CLKCTRL_IDLEST_DISABLED) ||
685 (idlest == MODULE_CLKCTRL_IDLEST_TRANSITIONING)) {
686
687 clkctrl = readl(clkctrl_addr);
688 idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >>
689 MODULE_CLKCTRL_IDLEST_SHIFT;
690 if (--bound == 0) {
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000691 printf("Clock enable failed for 0x%x idlest 0x%x\n",
Aneesh V0d2628b2011-07-21 09:10:07 -0400692 clkctrl_addr, clkctrl);
693 return;
694 }
695 }
696}
697
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000698static inline void enable_clock_module(u32 const clkctrl_addr, u32 enable_mode,
Aneesh V0d2628b2011-07-21 09:10:07 -0400699 u32 wait_for_enable)
700{
701 clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK,
702 enable_mode << MODULE_CLKCTRL_MODULEMODE_SHIFT);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000703 debug("Enable clock module - %x\n", clkctrl_addr);
Aneesh V0d2628b2011-07-21 09:10:07 -0400704 if (wait_for_enable)
705 wait_for_clk_enable(clkctrl_addr);
706}
707
Kishon Vijay Abraham I920f156f2015-08-17 13:29:51 +0530708static inline void wait_for_clk_disable(u32 clkctrl_addr)
709{
710 u32 clkctrl, idlest = MODULE_CLKCTRL_IDLEST_FULLY_FUNCTIONAL;
711 u32 bound = LDELAY;
712
713 while ((idlest != MODULE_CLKCTRL_IDLEST_DISABLED)) {
714 clkctrl = readl(clkctrl_addr);
715 idlest = (clkctrl & MODULE_CLKCTRL_IDLEST_MASK) >>
716 MODULE_CLKCTRL_IDLEST_SHIFT;
717 if (--bound == 0) {
718 printf("Clock disable failed for 0x%x idlest 0x%x\n",
719 clkctrl_addr, clkctrl);
720 return;
721 }
722 }
723}
724
725static inline void disable_clock_module(u32 const clkctrl_addr,
726 u32 wait_for_disable)
727{
728 clrsetbits_le32(clkctrl_addr, MODULE_CLKCTRL_MODULEMODE_MASK,
729 MODULE_CLKCTRL_MODULEMODE_SW_DISABLE <<
730 MODULE_CLKCTRL_MODULEMODE_SHIFT);
731 debug("Disable clock module - %x\n", clkctrl_addr);
732 if (wait_for_disable)
733 wait_for_clk_disable(clkctrl_addr);
734}
735
Aneesh V0d2628b2011-07-21 09:10:07 -0400736void freq_update_core(void)
737{
738 u32 freq_config1 = 0;
739 const struct dpll_params *core_dpll_params;
SRICHARAN R3d534962012-03-12 02:25:37 +0000740 u32 omap_rev = omap_revision();
Aneesh V0d2628b2011-07-21 09:10:07 -0400741
SRICHARAN R1a79cab2013-02-04 04:22:01 +0000742 core_dpll_params = get_core_dpll_params(*dplls_data);
Aneesh V0d2628b2011-07-21 09:10:07 -0400743 /* Put EMIF clock domain in sw wakeup mode */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000744 enable_clock_domain((*prcm)->cm_memif_clkstctrl,
Aneesh V0d2628b2011-07-21 09:10:07 -0400745 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000746 wait_for_clk_enable((*prcm)->cm_memif_emif_1_clkctrl);
747 wait_for_clk_enable((*prcm)->cm_memif_emif_2_clkctrl);
Aneesh V0d2628b2011-07-21 09:10:07 -0400748
749 freq_config1 = SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK |
750 SHADOW_FREQ_CONFIG1_DLL_RESET_MASK;
751
752 freq_config1 |= (DPLL_EN_LOCK << SHADOW_FREQ_CONFIG1_DPLL_EN_SHIFT) &
753 SHADOW_FREQ_CONFIG1_DPLL_EN_MASK;
754
755 freq_config1 |= (core_dpll_params->m2 <<
756 SHADOW_FREQ_CONFIG1_M2_DIV_SHIFT) &
757 SHADOW_FREQ_CONFIG1_M2_DIV_MASK;
758
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000759 writel(freq_config1, (*prcm)->cm_shadow_freq_config1);
Aneesh V0d2628b2011-07-21 09:10:07 -0400760 if (!wait_on_value(SHADOW_FREQ_CONFIG1_FREQ_UPDATE_MASK, 0,
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000761 (u32 *) (*prcm)->cm_shadow_freq_config1, LDELAY)) {
Aneesh V0d2628b2011-07-21 09:10:07 -0400762 puts("FREQ UPDATE procedure failed!!");
763 hang();
764 }
765
SRICHARAN R3d534962012-03-12 02:25:37 +0000766 /*
767 * Putting EMIF in HW_AUTO is seen to be causing issues with
Lubomir Popova01f0b02013-04-04 05:51:45 +0000768 * EMIF clocks and the master DLL. Keep EMIF in SW_WKUP
SRICHARAN R3d534962012-03-12 02:25:37 +0000769 * in OMAP5430 ES1.0 silicon
770 */
771 if (omap_rev != OMAP5430_ES1_0) {
772 /* Put EMIF clock domain back in hw auto mode */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000773 enable_clock_domain((*prcm)->cm_memif_clkstctrl,
SRICHARAN R3d534962012-03-12 02:25:37 +0000774 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000775 wait_for_clk_enable((*prcm)->cm_memif_emif_1_clkctrl);
776 wait_for_clk_enable((*prcm)->cm_memif_emif_2_clkctrl);
SRICHARAN R3d534962012-03-12 02:25:37 +0000777 }
Aneesh V0d2628b2011-07-21 09:10:07 -0400778}
779
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000780void bypass_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400781{
782 do_bypass_dpll(base);
783 wait_for_bypass(base);
784}
785
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000786void lock_dpll(u32 const base)
Aneesh V0d2628b2011-07-21 09:10:07 -0400787{
788 do_lock_dpll(base);
789 wait_for_lock(base);
790}
791
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600792static void setup_clocks_for_console(void)
Aneesh Vb8e60b92011-07-21 09:10:21 -0400793{
794 /* Do not add any spl_debug prints in this function */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000795 clrsetbits_le32((*prcm)->cm_l4per_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400796 CD_CLKCTRL_CLKTRCTRL_SW_WKUP <<
797 CD_CLKCTRL_CLKTRCTRL_SHIFT);
798
799 /* Enable all UARTs - console will be on one of them */
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000800 clrsetbits_le32((*prcm)->cm_l4per_uart1_clkctrl,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400801 MODULE_CLKCTRL_MODULEMODE_MASK,
802 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
803 MODULE_CLKCTRL_MODULEMODE_SHIFT);
804
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000805 clrsetbits_le32((*prcm)->cm_l4per_uart2_clkctrl,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400806 MODULE_CLKCTRL_MODULEMODE_MASK,
807 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
808 MODULE_CLKCTRL_MODULEMODE_SHIFT);
809
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000810 clrsetbits_le32((*prcm)->cm_l4per_uart3_clkctrl,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400811 MODULE_CLKCTRL_MODULEMODE_MASK,
812 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN <<
813 MODULE_CLKCTRL_MODULEMODE_SHIFT);
814
Lubomir Popova01f0b02013-04-04 05:51:45 +0000815 clrsetbits_le32((*prcm)->cm_l4per_uart4_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_clkstctrl, CD_CLKCTRL_CLKTRCTRL_MASK,
Aneesh Vb8e60b92011-07-21 09:10:21 -0400821 CD_CLKCTRL_CLKTRCTRL_HW_AUTO <<
822 CD_CLKCTRL_CLKTRCTRL_SHIFT);
823}
824
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000825void do_enable_clocks(u32 const *clk_domains,
826 u32 const *clk_modules_hw_auto,
827 u32 const *clk_modules_explicit_en,
Sricharan9784f1f2011-11-15 09:49:58 -0500828 u8 wait_for_enable)
829{
830 u32 i, max = 100;
831
832 /* Put the clock domains in SW_WKUP mode */
Lukasz Majewski9e3491b2017-03-27 10:15:27 +0200833 for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
Sricharan9784f1f2011-11-15 09:49:58 -0500834 enable_clock_domain(clk_domains[i],
835 CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
836 }
837
838 /* Clock modules that need to be put in HW_AUTO */
Lukasz Majewski9e3491b2017-03-27 10:15:27 +0200839 for (i = 0; (i < max) && clk_modules_hw_auto &&
840 clk_modules_hw_auto[i]; i++) {
Sricharan9784f1f2011-11-15 09:49:58 -0500841 enable_clock_module(clk_modules_hw_auto[i],
842 MODULE_CLKCTRL_MODULEMODE_HW_AUTO,
843 wait_for_enable);
844 };
845
846 /* Clock modules that need to be put in SW_EXPLICIT_EN mode */
Lukasz Majewski9e3491b2017-03-27 10:15:27 +0200847 for (i = 0; (i < max) && clk_modules_explicit_en &&
848 clk_modules_explicit_en[i]; i++) {
Sricharan9784f1f2011-11-15 09:49:58 -0500849 enable_clock_module(clk_modules_explicit_en[i],
850 MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
851 wait_for_enable);
852 };
853
854 /* Put the clock domains in HW_AUTO mode now */
Lukasz Majewski9e3491b2017-03-27 10:15:27 +0200855 for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
Sricharan9784f1f2011-11-15 09:49:58 -0500856 enable_clock_domain(clk_domains[i],
857 CD_CLKCTRL_CLKTRCTRL_HW_AUTO);
858 }
859}
860
Kishon Vijay Abraham I920f156f2015-08-17 13:29:51 +0530861void do_disable_clocks(u32 const *clk_domains,
862 u32 const *clk_modules_disable,
863 u8 wait_for_disable)
864{
865 u32 i, max = 100;
866
867
868 /* Clock modules that need to be put in SW_DISABLE */
869 for (i = 0; (i < max) && clk_modules_disable[i]; i++)
870 disable_clock_module(clk_modules_disable[i],
871 wait_for_disable);
872
873 /* Put the clock domains in SW_SLEEP mode */
874 for (i = 0; (i < max) && clk_domains[i]; i++)
875 disable_clock_domain(clk_domains[i]);
876}
877
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600878/**
879 * setup_early_clocks() - Setup early clocks needed for SoC
880 *
881 * Setup clocks for console, SPL basic initialization clocks and initialize
882 * the timer. This is invoked prior prcm_init.
883 */
884void setup_early_clocks(void)
Aneesh V0d2628b2011-07-21 09:10:07 -0400885{
Sricharan9310ff72011-11-15 09:49:55 -0500886 switch (omap_hw_init_context()) {
Aneesh V0d2628b2011-07-21 09:10:07 -0400887 case OMAP_INIT_CONTEXT_SPL:
888 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
889 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600890 setup_clocks_for_console();
Aneesh V9a390882011-07-21 09:29:29 -0400891 enable_basic_clocks();
Lokesh Vutlad9c839a2013-05-30 03:19:30 +0000892 timer_init();
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600893 /* Fall through */
894 }
895}
896
897void prcm_init(void)
898{
899 switch (omap_hw_init_context()) {
900 case OMAP_INIT_CONTEXT_SPL:
901 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
902 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
SRICHARAN R00d328c2013-02-04 04:22:02 +0000903 scale_vcores(*omap_vcores);
Aneesh V0d2628b2011-07-21 09:10:07 -0400904 setup_dplls();
Lokesh Vutla100c2d82013-04-17 20:49:40 +0000905 setup_warmreset_time();
Aneesh V0d2628b2011-07-21 09:10:07 -0400906 break;
907 default:
908 break;
909 }
Sricharan308fe922011-11-15 09:50:03 -0500910
911 if (OMAP_INIT_CONTEXT_SPL != omap_hw_init_context())
912 enable_basic_uboot_clocks();
Aneesh V0d2628b2011-07-21 09:10:07 -0400913}
Lokesh Vutla36852972013-05-30 03:19:29 +0000914
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100915#if !defined(CONFIG_DM_I2C)
Lokesh Vutla36852972013-05-30 03:19:29 +0000916void gpi2c_init(void)
917{
918 static int gpi2c = 1;
919
920 if (gpi2c) {
Heiko Schocherf53f2b82013-10-22 11:03:18 +0200921 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
922 CONFIG_SYS_OMAP24_I2C_SLAVE);
Lokesh Vutla36852972013-05-30 03:19:29 +0000923 gpi2c = 0;
924 }
925}
Jean-Jacques Hiblot52a51512018-12-07 14:50:49 +0100926#endif