blob: 0886f92431ad87ace2cd2823196580b8cd3693e7 [file] [log] [blame]
Sricharan9784f1f2011-11-15 09:49:58 -05001/*
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 *
14 * See file CREDITS for list of people who contributed to this
15 * project.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA 02111-1307 USA
31 */
32#include <common.h>
33#include <asm/omap_common.h>
34#include <asm/gpio.h>
35#include <asm/arch/clocks.h>
36#include <asm/arch/sys_proto.h>
37#include <asm/utils.h>
38#include <asm/omap_gpio.h>
39
40#ifndef CONFIG_SPL_BUILD
41/*
42 * printing to console doesn't work unless
43 * this code is executed from SPL
44 */
45#define printf(fmt, args...)
46#define puts(s)
47#endif
48
49#define abs(x) (((x) < 0) ? ((x)*-1) : (x))
50
51struct omap4_prcm_regs *const prcm = (struct omap4_prcm_regs *)0x4A004100;
52
53const u32 sys_clk_array[8] = {
54 12000000, /* 12 MHz */
55 13000000, /* 13 MHz */
56 16800000, /* 16.8 MHz */
57 19200000, /* 19.2 MHz */
58 26000000, /* 26 MHz */
59 27000000, /* 27 MHz */
60 38400000, /* 38.4 MHz */
61};
62
63/*
64 * The M & N values in the following tables are created using the
65 * following tool:
66 * tools/omap/clocks_get_m_n.c
67 * Please use this tool for creating the table for any new frequency.
68 */
69
70/* dpll locked at 1840 MHz MPU clk at 920 MHz(OPP Turbo 4460) - DCC OFF */
71static const struct dpll_params mpu_dpll_params_1840mhz[NUM_SYS_CLKS] = {
72 {230, 2, 1, -1, -1, -1, -1, -1}, /* 12 MHz */
73 {920, 12, 1, -1, -1, -1, -1, -1}, /* 13 MHz */
74 {219, 3, 1, -1, -1, -1, -1, -1}, /* 16.8 MHz */
75 {575, 11, 1, -1, -1, -1, -1, -1}, /* 19.2 MHz */
76 {460, 12, 1, -1, -1, -1, -1, -1}, /* 26 MHz */
77 {920, 26, 1, -1, -1, -1, -1, -1}, /* 27 MHz */
78 {575, 23, 1, -1, -1, -1, -1, -1} /* 38.4 MHz */
79};
80
81/* dpll locked at 1584 MHz - MPU clk at 792 MHz(OPP Turbo 4430) */
82static const struct dpll_params mpu_dpll_params_1600mhz[NUM_SYS_CLKS] = {
83 {200, 2, 1, -1, -1, -1, -1, -1}, /* 12 MHz */
84 {800, 12, 1, -1, -1, -1, -1, -1}, /* 13 MHz */
85 {619, 12, 1, -1, -1, -1, -1, -1}, /* 16.8 MHz */
86 {125, 2, 1, -1, -1, -1, -1, -1}, /* 19.2 MHz */
87 {400, 12, 1, -1, -1, -1, -1, -1}, /* 26 MHz */
88 {800, 26, 1, -1, -1, -1, -1, -1}, /* 27 MHz */
89 {125, 5, 1, -1, -1, -1, -1, -1} /* 38.4 MHz */
90};
91
92/* dpll locked at 1200 MHz - MPU clk at 600 MHz */
93static const struct dpll_params mpu_dpll_params_1200mhz[NUM_SYS_CLKS] = {
94 {50, 0, 1, -1, -1, -1, -1, -1}, /* 12 MHz */
95 {600, 12, 1, -1, -1, -1, -1, -1}, /* 13 MHz */
96 {250, 6, 1, -1, -1, -1, -1, -1}, /* 16.8 MHz */
97 {125, 3, 1, -1, -1, -1, -1, -1}, /* 19.2 MHz */
98 {300, 12, 1, -1, -1, -1, -1, -1}, /* 26 MHz */
99 {200, 8, 1, -1, -1, -1, -1, -1}, /* 27 MHz */
100 {125, 7, 1, -1, -1, -1, -1, -1} /* 38.4 MHz */
101};
102
103static const struct dpll_params core_dpll_params_1600mhz[NUM_SYS_CLKS] = {
104 {200, 2, 1, 5, 8, 4, 6, 5}, /* 12 MHz */
105 {800, 12, 1, 5, 8, 4, 6, 5}, /* 13 MHz */
106 {619, 12, 1, 5, 8, 4, 6, 5}, /* 16.8 MHz */
107 {125, 2, 1, 5, 8, 4, 6, 5}, /* 19.2 MHz */
108 {400, 12, 1, 5, 8, 4, 6, 5}, /* 26 MHz */
109 {800, 26, 1, 5, 8, 4, 6, 5}, /* 27 MHz */
110 {125, 5, 1, 5, 8, 4, 6, 5} /* 38.4 MHz */
111};
112
113static const struct dpll_params core_dpll_params_es1_1524mhz[NUM_SYS_CLKS] = {
114 {127, 1, 1, 5, 8, 4, 6, 5}, /* 12 MHz */
115 {762, 12, 1, 5, 8, 4, 6, 5}, /* 13 MHz */
116 {635, 13, 1, 5, 8, 4, 6, 5}, /* 16.8 MHz */
117 {635, 15, 1, 5, 8, 4, 6, 5}, /* 19.2 MHz */
118 {381, 12, 1, 5, 8, 4, 6, 5}, /* 26 MHz */
119 {254, 8, 1, 5, 8, 4, 6, 5}, /* 27 MHz */
120 {496, 24, 1, 5, 8, 4, 6, 5} /* 38.4 MHz */
121};
122
123static const struct dpll_params
124 core_dpll_params_es2_1600mhz_ddr200mhz[NUM_SYS_CLKS] = {
125 {200, 2, 2, 5, 8, 4, 6, 5}, /* 12 MHz */
126 {800, 12, 2, 5, 8, 4, 6, 5}, /* 13 MHz */
127 {619, 12, 2, 5, 8, 4, 6, 5}, /* 16.8 MHz */
128 {125, 2, 2, 5, 8, 4, 6, 5}, /* 19.2 MHz */
129 {400, 12, 2, 5, 8, 4, 6, 5}, /* 26 MHz */
130 {800, 26, 2, 5, 8, 4, 6, 5}, /* 27 MHz */
131 {125, 5, 2, 5, 8, 4, 6, 5} /* 38.4 MHz */
132};
133
134static const struct dpll_params per_dpll_params_1536mhz[NUM_SYS_CLKS] = {
135 {64, 0, 8, 6, 12, 9, 4, 5}, /* 12 MHz */
136 {768, 12, 8, 6, 12, 9, 4, 5}, /* 13 MHz */
137 {320, 6, 8, 6, 12, 9, 4, 5}, /* 16.8 MHz */
138 {40, 0, 8, 6, 12, 9, 4, 5}, /* 19.2 MHz */
139 {384, 12, 8, 6, 12, 9, 4, 5}, /* 26 MHz */
140 {256, 8, 8, 6, 12, 9, 4, 5}, /* 27 MHz */
141 {20, 0, 8, 6, 12, 9, 4, 5} /* 38.4 MHz */
142};
143
144static const struct dpll_params iva_dpll_params_1862mhz[NUM_SYS_CLKS] = {
145 {931, 11, -1, -1, 4, 7, -1, -1}, /* 12 MHz */
146 {931, 12, -1, -1, 4, 7, -1, -1}, /* 13 MHz */
147 {665, 11, -1, -1, 4, 7, -1, -1}, /* 16.8 MHz */
148 {727, 14, -1, -1, 4, 7, -1, -1}, /* 19.2 MHz */
149 {931, 25, -1, -1, 4, 7, -1, -1}, /* 26 MHz */
150 {931, 26, -1, -1, 4, 7, -1, -1}, /* 27 MHz */
151 {412, 16, -1, -1, 4, 7, -1, -1} /* 38.4 MHz */
152};
153
154/* ABE M & N values with sys_clk as source */
155static const struct dpll_params
156 abe_dpll_params_sysclk_196608khz[NUM_SYS_CLKS] = {
157 {49, 5, 1, 1, -1, -1, -1, -1}, /* 12 MHz */
158 {68, 8, 1, 1, -1, -1, -1, -1}, /* 13 MHz */
159 {35, 5, 1, 1, -1, -1, -1, -1}, /* 16.8 MHz */
160 {46, 8, 1, 1, -1, -1, -1, -1}, /* 19.2 MHz */
161 {34, 8, 1, 1, -1, -1, -1, -1}, /* 26 MHz */
162 {29, 7, 1, 1, -1, -1, -1, -1}, /* 27 MHz */
163 {64, 24, 1, 1, -1, -1, -1, -1} /* 38.4 MHz */
164};
165
166/* ABE M & N values with 32K clock as source */
167static const struct dpll_params abe_dpll_params_32k_196608khz = {
168 750, 0, 1, 1, -1, -1, -1, -1
169};
170
171static const struct dpll_params usb_dpll_params_1920mhz[NUM_SYS_CLKS] = {
172 {80, 0, 2, -1, -1, -1, -1, -1}, /* 12 MHz */
173 {960, 12, 2, -1, -1, -1, -1, -1}, /* 13 MHz */
174 {400, 6, 2, -1, -1, -1, -1, -1}, /* 16.8 MHz */
175 {50, 0, 2, -1, -1, -1, -1, -1}, /* 19.2 MHz */
176 {480, 12, 2, -1, -1, -1, -1, -1}, /* 26 MHz */
177 {320, 8, 2, -1, -1, -1, -1, -1}, /* 27 MHz */
178 {25, 0, 2, -1, -1, -1, -1, -1} /* 38.4 MHz */
179};
180
181void setup_post_dividers(u32 *const base, const struct dpll_params *params)
182{
183 struct dpll_regs *const dpll_regs = (struct dpll_regs *)base;
184
185 /* Setup post-dividers */
186 if (params->m2 >= 0)
187 writel(params->m2, &dpll_regs->cm_div_m2_dpll);
188 if (params->m3 >= 0)
189 writel(params->m3, &dpll_regs->cm_div_m3_dpll);
190 if (params->m4 >= 0)
191 writel(params->m4, &dpll_regs->cm_div_m4_dpll);
192 if (params->m5 >= 0)
193 writel(params->m5, &dpll_regs->cm_div_m5_dpll);
194 if (params->m6 >= 0)
195 writel(params->m6, &dpll_regs->cm_div_m6_dpll);
196 if (params->m7 >= 0)
197 writel(params->m7, &dpll_regs->cm_div_m7_dpll);
198}
199
200/*
201 * Lock MPU dpll
202 *
203 * Resulting MPU frequencies:
204 * 4430 ES1.0 : 600 MHz
205 * 4430 ES2.x : 792 MHz (OPP Turbo)
206 * 4460 : 920 MHz (OPP Turbo) - DCC disabled
207 */
208const struct dpll_params *get_mpu_dpll_params(void)
209{
210 u32 omap_rev, sysclk_ind;
211
212 omap_rev = omap_revision();
213 sysclk_ind = get_sys_clk_index();
214
215 if (omap_rev == OMAP4430_ES1_0)
216 return &mpu_dpll_params_1200mhz[sysclk_ind];
217 else if (omap_rev < OMAP4460_ES1_0)
218 return &mpu_dpll_params_1600mhz[sysclk_ind];
219 else
220 return &mpu_dpll_params_1840mhz[sysclk_ind];
221}
222
223const struct dpll_params *get_core_dpll_params(void)
224{
225 u32 sysclk_ind = get_sys_clk_index();
226
227 switch (omap_revision()) {
228 case OMAP4430_ES1_0:
229 return &core_dpll_params_es1_1524mhz[sysclk_ind];
230 case OMAP4430_ES2_0:
231 case OMAP4430_SILICON_ID_INVALID:
232 /* safest */
233 return &core_dpll_params_es2_1600mhz_ddr200mhz[sysclk_ind];
234 default:
235 return &core_dpll_params_1600mhz[sysclk_ind];
236 }
237}
238
239
240const struct dpll_params *get_per_dpll_params(void)
241{
242 u32 sysclk_ind = get_sys_clk_index();
243 return &per_dpll_params_1536mhz[sysclk_ind];
244}
245
246const struct dpll_params *get_iva_dpll_params(void)
247{
248 u32 sysclk_ind = get_sys_clk_index();
249 return &iva_dpll_params_1862mhz[sysclk_ind];
250}
251
252const struct dpll_params *get_usb_dpll_params(void)
253{
254 u32 sysclk_ind = get_sys_clk_index();
255 return &usb_dpll_params_1920mhz[sysclk_ind];
256}
257
258const struct dpll_params *get_abe_dpll_params(void)
259{
260#ifdef CONFIG_SYS_OMAP_ABE_SYSCK
261 u32 sysclk_ind = get_sys_clk_index();
262 return &abe_dpll_params_sysclk_196608khz[sysclk_ind];
263#else
264 return &abe_dpll_params_32k_196608khz;
265#endif
266}
267
268/*
269 * Setup the voltages for vdd_mpu, vdd_core, and vdd_iva
270 * We set the maximum voltages allowed here because Smart-Reflex is not
271 * enabled in bootloader. Voltage initialization in the kernel will set
272 * these to the nominal values after enabling Smart-Reflex
273 */
274void scale_vcores(void)
275{
276 u32 volt, omap_rev;
277
278 setup_sri2c();
279
280 omap_rev = omap_revision();
281 /* TPS - supplies vdd_mpu on 4460 */
282 if (omap_rev >= OMAP4460_ES1_0) {
283 volt = 1313;
284 do_scale_tps62361(TPS62361_REG_ADDR_SET1, volt);
285 }
286
287 /*
288 * VCORE 1
289 *
290 * 4430 : supplies vdd_mpu
291 * Setting a high voltage for Nitro mode as smart reflex is not enabled.
292 * We use the maximum possible value in the AVS range because the next
293 * higher voltage in the discrete range (code >= 0b111010) is way too
294 * high
295 *
296 * 4460 : supplies vdd_core
297 */
298 if (omap_rev < OMAP4460_ES1_0) {
299 volt = 1325;
300 do_scale_vcore(SMPS_REG_ADDR_VCORE1, volt);
301 } else {
302 volt = 1200;
303 do_scale_vcore(SMPS_REG_ADDR_VCORE1, volt);
304 }
305
306 /* VCORE 2 - supplies vdd_iva */
307 volt = 1200;
308 do_scale_vcore(SMPS_REG_ADDR_VCORE2, volt);
309
310 /*
311 * VCORE 3
312 * 4430 : supplies vdd_core
313 * 4460 : not connected
314 */
315 if (omap_rev < OMAP4460_ES1_0) {
316 volt = 1200;
317 do_scale_vcore(SMPS_REG_ADDR_VCORE3, volt);
318 }
319}
320
321/*
322 * Enable essential clock domains, modules and
323 * do some additional special settings needed
324 */
325void enable_basic_clocks(void)
326{
327 u32 *const clk_domains_essential[] = {
328 &prcm->cm_l4per_clkstctrl,
329 &prcm->cm_l3init_clkstctrl,
330 &prcm->cm_memif_clkstctrl,
331 &prcm->cm_l4cfg_clkstctrl,
332 0
333 };
334
335 u32 *const clk_modules_hw_auto_essential[] = {
Sricharan308fe922011-11-15 09:50:03 -0500336 &prcm->cm_memif_emif_1_clkctrl,
337 &prcm->cm_memif_emif_2_clkctrl,
338 &prcm->cm_l4cfg_l4_cfg_clkctrl,
Sricharan9784f1f2011-11-15 09:49:58 -0500339 &prcm->cm_wkup_gpio1_clkctrl,
340 &prcm->cm_l4per_gpio2_clkctrl,
341 &prcm->cm_l4per_gpio3_clkctrl,
342 &prcm->cm_l4per_gpio4_clkctrl,
343 &prcm->cm_l4per_gpio5_clkctrl,
344 &prcm->cm_l4per_gpio6_clkctrl,
Sricharan9784f1f2011-11-15 09:49:58 -0500345 0
346 };
347
348 u32 *const clk_modules_explicit_en_essential[] = {
Sricharan308fe922011-11-15 09:50:03 -0500349 &prcm->cm_wkup_gptimer1_clkctrl,
Sricharan9784f1f2011-11-15 09:49:58 -0500350 &prcm->cm_l3init_hsmmc1_clkctrl,
351 &prcm->cm_l3init_hsmmc2_clkctrl,
Sricharan308fe922011-11-15 09:50:03 -0500352 &prcm->cm_l4per_gptimer2_clkctrl,
Sricharan9784f1f2011-11-15 09:49:58 -0500353 &prcm->cm_wkup_wdtimer2_clkctrl,
354 &prcm->cm_l4per_uart3_clkctrl,
355 0
356 };
357
358 /* Enable optional additional functional clock for GPIO4 */
359 setbits_le32(&prcm->cm_l4per_gpio4_clkctrl,
360 GPIO4_CLKCTRL_OPTFCLKEN_MASK);
361
362 /* Enable 96 MHz clock for MMC1 & MMC2 */
363 setbits_le32(&prcm->cm_l3init_hsmmc1_clkctrl,
364 HSMMC_CLKCTRL_CLKSEL_MASK);
365 setbits_le32(&prcm->cm_l3init_hsmmc2_clkctrl,
366 HSMMC_CLKCTRL_CLKSEL_MASK);
367
368 /* Select 32KHz clock as the source of GPTIMER1 */
369 setbits_le32(&prcm->cm_wkup_gptimer1_clkctrl,
370 GPTIMER1_CLKCTRL_CLKSEL_MASK);
371
372 /* Enable optional 48M functional clock for USB PHY */
373 setbits_le32(&prcm->cm_l3init_usbphy_clkctrl,
374 USBPHY_CLKCTRL_OPTFCLKEN_PHY_48M_MASK);
375
376 do_enable_clocks(clk_domains_essential,
377 clk_modules_hw_auto_essential,
378 clk_modules_explicit_en_essential,
379 1);
380}
381
Sricharan308fe922011-11-15 09:50:03 -0500382void enable_basic_uboot_clocks(void)
383{
384 u32 *const clk_domains_essential[] = {
385 0
386 };
387
388 u32 *const clk_modules_hw_auto_essential[] = {
389 &prcm->cm_l3init_hsusbotg_clkctrl,
390 &prcm->cm_l3init_usbphy_clkctrl,
391 0
392 };
393
394 u32 *const clk_modules_explicit_en_essential[] = {
395 &prcm->cm_l4per_mcspi1_clkctrl,
396 &prcm->cm_l4per_i2c1_clkctrl,
397 &prcm->cm_l4per_i2c2_clkctrl,
398 &prcm->cm_l4per_i2c3_clkctrl,
399 &prcm->cm_l4per_i2c4_clkctrl,
400 0
401 };
402
403 do_enable_clocks(clk_domains_essential,
404 clk_modules_hw_auto_essential,
405 clk_modules_explicit_en_essential,
406 1);
407}
408
Sricharan9784f1f2011-11-15 09:49:58 -0500409/*
410 * Enable non-essential clock domains, modules and
411 * do some additional special settings needed
412 */
413void enable_non_essential_clocks(void)
414{
415 u32 *const clk_domains_non_essential[] = {
416 &prcm->cm_mpu_m3_clkstctrl,
417 &prcm->cm_ivahd_clkstctrl,
418 &prcm->cm_dsp_clkstctrl,
419 &prcm->cm_dss_clkstctrl,
420 &prcm->cm_sgx_clkstctrl,
421 &prcm->cm1_abe_clkstctrl,
422 &prcm->cm_c2c_clkstctrl,
423 &prcm->cm_cam_clkstctrl,
424 &prcm->cm_dss_clkstctrl,
425 &prcm->cm_sdma_clkstctrl,
426 0
427 };
428
429 u32 *const clk_modules_hw_auto_non_essential[] = {
430 &prcm->cm_mpu_m3_mpu_m3_clkctrl,
431 &prcm->cm_ivahd_ivahd_clkctrl,
432 &prcm->cm_ivahd_sl2_clkctrl,
433 &prcm->cm_dsp_dsp_clkctrl,
434 &prcm->cm_l3_2_gpmc_clkctrl,
435 &prcm->cm_l3instr_l3_3_clkctrl,
436 &prcm->cm_l3instr_l3_instr_clkctrl,
437 &prcm->cm_l3instr_intrconn_wp1_clkctrl,
438 &prcm->cm_l3init_hsi_clkctrl,
439 &prcm->cm_l3init_hsusbtll_clkctrl,
440 0
441 };
442
443 u32 *const clk_modules_explicit_en_non_essential[] = {
444 &prcm->cm1_abe_aess_clkctrl,
445 &prcm->cm1_abe_pdm_clkctrl,
446 &prcm->cm1_abe_dmic_clkctrl,
447 &prcm->cm1_abe_mcasp_clkctrl,
448 &prcm->cm1_abe_mcbsp1_clkctrl,
449 &prcm->cm1_abe_mcbsp2_clkctrl,
450 &prcm->cm1_abe_mcbsp3_clkctrl,
451 &prcm->cm1_abe_slimbus_clkctrl,
452 &prcm->cm1_abe_timer5_clkctrl,
453 &prcm->cm1_abe_timer6_clkctrl,
454 &prcm->cm1_abe_timer7_clkctrl,
455 &prcm->cm1_abe_timer8_clkctrl,
456 &prcm->cm1_abe_wdt3_clkctrl,
457 &prcm->cm_l4per_gptimer9_clkctrl,
458 &prcm->cm_l4per_gptimer10_clkctrl,
459 &prcm->cm_l4per_gptimer11_clkctrl,
460 &prcm->cm_l4per_gptimer3_clkctrl,
461 &prcm->cm_l4per_gptimer4_clkctrl,
462 &prcm->cm_l4per_hdq1w_clkctrl,
463 &prcm->cm_l4per_mcbsp4_clkctrl,
464 &prcm->cm_l4per_mcspi2_clkctrl,
465 &prcm->cm_l4per_mcspi3_clkctrl,
466 &prcm->cm_l4per_mcspi4_clkctrl,
467 &prcm->cm_l4per_mmcsd3_clkctrl,
468 &prcm->cm_l4per_mmcsd4_clkctrl,
469 &prcm->cm_l4per_mmcsd5_clkctrl,
470 &prcm->cm_l4per_uart1_clkctrl,
471 &prcm->cm_l4per_uart2_clkctrl,
472 &prcm->cm_l4per_uart4_clkctrl,
473 &prcm->cm_wkup_keyboard_clkctrl,
474 &prcm->cm_wkup_wdtimer2_clkctrl,
475 &prcm->cm_cam_iss_clkctrl,
476 &prcm->cm_cam_fdif_clkctrl,
477 &prcm->cm_dss_dss_clkctrl,
478 &prcm->cm_sgx_sgx_clkctrl,
479 &prcm->cm_l3init_hsusbhost_clkctrl,
480 &prcm->cm_l3init_fsusb_clkctrl,
481 0
482 };
483
484 /* Enable optional functional clock for ISS */
485 setbits_le32(&prcm->cm_cam_iss_clkctrl, ISS_CLKCTRL_OPTFCLKEN_MASK);
486
487 /* Enable all optional functional clocks of DSS */
488 setbits_le32(&prcm->cm_dss_dss_clkctrl, DSS_CLKCTRL_OPTFCLKEN_MASK);
489
490 do_enable_clocks(clk_domains_non_essential,
491 clk_modules_hw_auto_non_essential,
492 clk_modules_explicit_en_non_essential,
493 0);
494
495 /* Put camera module in no sleep mode */
496 clrsetbits_le32(&prcm->cm_cam_clkstctrl, MODULE_CLKCTRL_MODULEMODE_MASK,
497 CD_CLKCTRL_CLKTRCTRL_NO_SLEEP <<
498 MODULE_CLKCTRL_MODULEMODE_SHIFT);
499}