4 * Clocks for TI816X based boards
6 * Copyright (C) 2013, Adeneo Embedded <www.adeneo-embedded.com>
7 * Antoine Tenart, <atenart@adeneo-embedded.com>
9 * Based on TI-PSP-04.00.02.14 :
11 * Copyright (C) 2009, Texas Instruments, Incorporated
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
21 * GNU General Public License for more details.
25 #include <asm/arch/ddr_defs.h>
26 #include <asm/arch/cpu.h>
27 #include <asm/arch/clock.h>
28 #include <asm/arch/hardware.h>
33 #define CM_PLL_BASE (CTRL_BASE + 0x0400)
38 #define MAIN_INTFREQ1 0x8
39 #define MAIN_FRACFREQ1 0x800000
40 #define MAIN_MDIV1 0x2
41 #define MAIN_INTFREQ2 0xE
42 #define MAIN_FRACFREQ2 0x0
43 #define MAIN_MDIV2 0x1
44 #define MAIN_INTFREQ3 0x8
45 #define MAIN_FRACFREQ3 0xAAAAB0
46 #define MAIN_MDIV3 0x3
47 #define MAIN_INTFREQ4 0x9
48 #define MAIN_FRACFREQ4 0x55554F
49 #define MAIN_MDIV4 0x3
50 #define MAIN_INTFREQ5 0x9
51 #define MAIN_FRACFREQ5 0x374BC6
52 #define MAIN_MDIV5 0xC
53 #define MAIN_MDIV6 0x48
54 #define MAIN_MDIV7 0x4
60 #define DDR_INTFREQ2 0x8
61 #define DDR_FRACFREQ2 0xD99999
62 #define DDR_MDIV2 0x1E
63 #define DDR_INTFREQ3 0x8
64 #define DDR_FRACFREQ3 0x0
66 #define DDR_INTFREQ4 0xE /* Expansion DDR clk */
67 #define DDR_FRACFREQ4 0x0
69 #define DDR_INTFREQ5 0xE /* Expansion DDR clk */
70 #define DDR_FRACFREQ5 0x0
73 #define CONTROL_STATUS (CTRL_BASE + 0x40)
74 #define DDR_RCD (CTRL_BASE + 0x070C)
75 #define CM_TIMER1_CLKSEL (PRCM_BASE + 0x390)
76 #define CM_ALWON_CUST_EFUSE_CLKCTRL (PRCM_BASE + 0x1628)
78 #define INTCPS_SYSCONFIG 0x48200010
79 #define CM_SYSCLK10_CLKSEL 0x48180324
82 unsigned int mainpll_ctrl; /* offset 0x400 */
83 unsigned int mainpll_pwd;
84 unsigned int mainpll_freq1;
85 unsigned int mainpll_div1;
86 unsigned int mainpll_freq2;
87 unsigned int mainpll_div2;
88 unsigned int mainpll_freq3;
89 unsigned int mainpll_div3;
90 unsigned int mainpll_freq4;
91 unsigned int mainpll_div4;
92 unsigned int mainpll_freq5;
93 unsigned int mainpll_div5;
94 unsigned int resv0[1];
95 unsigned int mainpll_div6;
96 unsigned int resv1[1];
97 unsigned int mainpll_div7;
98 unsigned int ddrpll_ctrl; /* offset 0x440 */
99 unsigned int ddrpll_pwd;
100 unsigned int resv2[1];
101 unsigned int ddrpll_div1;
102 unsigned int ddrpll_freq2;
103 unsigned int ddrpll_div2;
104 unsigned int ddrpll_freq3;
105 unsigned int ddrpll_div3;
106 unsigned int ddrpll_freq4;
107 unsigned int ddrpll_div4;
108 unsigned int ddrpll_freq5;
109 unsigned int ddrpll_div5;
110 unsigned int videopll_ctrl; /* offset 0x470 */
111 unsigned int videopll_pwd;
112 unsigned int videopll_freq1;
113 unsigned int videopll_div1;
114 unsigned int videopll_freq2;
115 unsigned int videopll_div2;
116 unsigned int videopll_freq3;
117 unsigned int videopll_div3;
118 unsigned int resv3[4];
119 unsigned int audiopll_ctrl; /* offset 0x4A0 */
120 unsigned int audiopll_pwd;
121 unsigned int resv4[2];
122 unsigned int audiopll_freq2;
123 unsigned int audiopll_div2;
124 unsigned int audiopll_freq3;
125 unsigned int audiopll_div3;
126 unsigned int audiopll_freq4;
127 unsigned int audiopll_div4;
128 unsigned int audiopll_freq5;
129 unsigned int audiopll_div5;
132 const struct cm_alwon *cmalwon = (struct cm_alwon *)CM_ALWON_BASE;
133 const struct cm_def *cmdef = (struct cm_def *)CM_DEFAULT_BASE;
134 const struct cm_pll *cmpll = (struct cm_pll *)CM_PLL_BASE;
135 const struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
137 void enable_dmm_clocks(void)
139 writel(PRCM_MOD_EN, &cmdef->dmmclkctrl);
140 /* Wait for dmm to be fully functional, including OCP */
141 while (((readl(&cmdef->dmmclkctrl) >> 17) & 0x3) != 0)
145 void enable_emif_clocks(void)
147 writel(PRCM_MOD_EN, &cmdef->fwclkctrl);
148 writel(PRCM_MOD_EN, &cmdef->l3fastclkstctrl);
149 writel(PRCM_MOD_EN, &cmdef->emif0clkctrl);
150 writel(PRCM_MOD_EN, &cmdef->emif1clkctrl);
152 /* Wait for clocks to be active */
153 while ((readl(&cmdef->l3fastclkstctrl) & 0x300) != 0x300)
155 /* Wait for emif0 to be fully functional, including OCP */
156 while (((readl(&cmdef->emif0clkctrl) >> 17) & 0x3) != 0)
158 /* Wait for emif1 to be fully functional, including OCP */
159 while (((readl(&cmdef->emif1clkctrl) >> 17) & 0x3) != 0)
163 /* assume delay is aprox at least 1us */
164 static void ddr_delay(int d)
169 * read a control register.
170 * this is a bit more delay and cannot be optimized by the compiler
171 * assuming one read takes 200 cycles and A8 is runing 1 GHz
172 * somewhat conservative setting
174 for (i = 0; i < 50*d; i++)
175 readl(CONTROL_STATUS);
178 static void main_pll_init_ti816x(void)
180 u32 main_pll_ctrl = 0;
182 /* Put the PLL in bypass mode by setting BIT2 in its ctrl reg */
183 main_pll_ctrl = readl(&cmpll->mainpll_ctrl);
184 main_pll_ctrl &= 0xFFFFFFFB;
185 main_pll_ctrl |= BIT(2);
186 writel(main_pll_ctrl, &cmpll->mainpll_ctrl);
188 /* Enable PLL by setting BIT3 in its ctrl reg */
189 main_pll_ctrl = readl(&cmpll->mainpll_ctrl);
190 main_pll_ctrl &= 0xFFFFFFF7;
191 main_pll_ctrl |= BIT(3);
192 writel(main_pll_ctrl, &cmpll->mainpll_ctrl);
194 /* Write the values of N,P in the CTRL reg */
195 main_pll_ctrl = readl(&cmpll->mainpll_ctrl);
196 main_pll_ctrl &= 0xFF;
197 main_pll_ctrl |= (MAIN_N<<16 | MAIN_P<<8);
198 writel(main_pll_ctrl, &cmpll->mainpll_ctrl);
200 /* Power up clock1-7 */
201 writel(0x0, &cmpll->mainpll_pwd);
203 /* Program the freq and divider values for clock1-7 */
204 writel((1<<31 | 1<<28 | (MAIN_INTFREQ1<<24) | MAIN_FRACFREQ1),
205 &cmpll->mainpll_freq1);
206 writel(((1<<8) | MAIN_MDIV1), &cmpll->mainpll_div1);
208 writel((1<<31 | 1<<28 | (MAIN_INTFREQ2<<24) | MAIN_FRACFREQ2),
209 &cmpll->mainpll_freq2);
210 writel(((1<<8) | MAIN_MDIV2), &cmpll->mainpll_div2);
212 writel((1<<31 | 1<<28 | (MAIN_INTFREQ3<<24) | MAIN_FRACFREQ3),
213 &cmpll->mainpll_freq3);
214 writel(((1<<8) | MAIN_MDIV3), &cmpll->mainpll_div3);
216 writel((1<<31 | 1<<28 | (MAIN_INTFREQ4<<24) | MAIN_FRACFREQ4),
217 &cmpll->mainpll_freq4);
218 writel(((1<<8) | MAIN_MDIV4), &cmpll->mainpll_div4);
220 writel((1<<31 | 1<<28 | (MAIN_INTFREQ5<<24) | MAIN_FRACFREQ5),
221 &cmpll->mainpll_freq5);
222 writel(((1<<8) | MAIN_MDIV5), &cmpll->mainpll_div5);
224 writel((1<<8 | MAIN_MDIV6), &cmpll->mainpll_div6);
226 writel((1<<8 | MAIN_MDIV7), &cmpll->mainpll_div7);
228 /* Wait for PLL to lock */
229 while ((readl(&cmpll->mainpll_ctrl) & BIT(7)) != BIT(7))
232 /* Put the PLL in normal mode, disable bypass */
233 main_pll_ctrl = readl(&cmpll->mainpll_ctrl);
234 main_pll_ctrl &= 0xFFFFFFFB;
235 writel(main_pll_ctrl, &cmpll->mainpll_ctrl);
238 static void ddr_pll_bypass_ti816x(void)
240 u32 ddr_pll_ctrl = 0;
242 /* Put the PLL in bypass mode by setting BIT2 in its ctrl reg */
243 ddr_pll_ctrl = readl(&cmpll->ddrpll_ctrl);
244 ddr_pll_ctrl &= 0xFFFFFFFB;
245 ddr_pll_ctrl |= BIT(2);
246 writel(ddr_pll_ctrl, &cmpll->ddrpll_ctrl);
249 static void ddr_pll_init_ti816x(void)
251 u32 ddr_pll_ctrl = 0;
252 /* Enable PLL by setting BIT3 in its ctrl reg */
253 ddr_pll_ctrl = readl(&cmpll->ddrpll_ctrl);
254 ddr_pll_ctrl &= 0xFFFFFFF7;
255 ddr_pll_ctrl |= BIT(3);
256 writel(ddr_pll_ctrl, &cmpll->ddrpll_ctrl);
258 /* Write the values of N,P in the CTRL reg */
259 ddr_pll_ctrl = readl(&cmpll->ddrpll_ctrl);
260 ddr_pll_ctrl &= 0xFF;
261 ddr_pll_ctrl |= (DDR_N<<16 | DDR_P<<8);
262 writel(ddr_pll_ctrl, &cmpll->ddrpll_ctrl);
266 /* Power up clock1-5 */
267 writel(0x0, &cmpll->ddrpll_pwd);
269 /* Program the freq and divider values for clock1-3 */
270 writel(((0<<8) | DDR_MDIV1), &cmpll->ddrpll_div1);
272 writel(((1<<8) | DDR_MDIV1), &cmpll->ddrpll_div1);
273 writel((1<<31 | 1<<28 | (DDR_INTFREQ2<<24) | DDR_FRACFREQ2),
274 &cmpll->ddrpll_freq2);
275 writel(((1<<8) | DDR_MDIV2), &cmpll->ddrpll_div2);
276 writel(((0<<8) | DDR_MDIV3), &cmpll->ddrpll_div3);
278 writel(((1<<8) | DDR_MDIV3), &cmpll->ddrpll_div3);
280 writel((0<<31 | 1<<28 | (DDR_INTFREQ3<<24) | DDR_FRACFREQ3),
281 &cmpll->ddrpll_freq3);
283 writel((1<<31 | 1<<28 | (DDR_INTFREQ3<<24) | DDR_FRACFREQ3),
284 &cmpll->ddrpll_freq3);
288 /* Wait for PLL to lock */
289 while ((readl(&cmpll->ddrpll_ctrl) & BIT(7)) != BIT(7))
293 writel(BIT(0), DDR_RCD);
296 static void peripheral_enable(void)
298 /* Wake-up the l3_slow clock */
299 writel(PRCM_MOD_EN, &cmalwon->l3slowclkstctrl);
303 * There are 8 timers(0-7) out of which timer 0 is a secure timer.
304 * Timer 0 mux should not be changed
306 * To access the timer registers we need the to be
307 * enabled which is what we do in the first step
311 writel(PRCM_MOD_EN, &cmalwon->timer1clkctrl);
312 /* Select timer1 clock to be CLKIN (27MHz) */
313 writel(BIT(1), CM_TIMER1_CLKSEL);
315 /* Wait for timer1 to be ON-ACTIVE */
316 while (((readl(&cmalwon->l3slowclkstctrl)
317 & (0x80000<<1))>>20) != 1)
319 /* Wait for timer1 to be enabled */
320 while (((readl(&cmalwon->timer1clkctrl) & 0x30000)>>16) != 0)
322 /* Active posted mode */
323 writel(PRCM_MOD_EN, (DM_TIMER1_BASE + 0x54));
324 while (readl(DM_TIMER1_BASE + 0x10) & BIT(0))
327 writel(BIT(0), (DM_TIMER1_BASE + 0x38));
330 writel(PRCM_MOD_EN, CM_ALWON_CUST_EFUSE_CLKCTRL);
331 while (readl(CM_ALWON_CUST_EFUSE_CLKCTRL) != PRCM_MOD_EN)
335 writel(PRCM_MOD_EN, &cmalwon->gpio0clkctrl);
336 while (readl(&cmalwon->gpio0clkctrl) != PRCM_MOD_EN)
338 writel((BIT(1) | BIT(8)), &cmalwon->gpio0clkctrl);
341 writel(PRCM_MOD_EN, &cmalwon->gpio1clkctrl);
342 while (readl(&cmalwon->gpio1clkctrl) != PRCM_MOD_EN)
344 writel((BIT(1) | BIT(8)), &cmalwon->gpio1clkctrl);
347 writel(PRCM_MOD_EN, &cmalwon->spiclkctrl);
348 while (readl(&cmalwon->spiclkctrl) != PRCM_MOD_EN)
352 writel(PRCM_MOD_EN, &cmalwon->i2c0clkctrl);
353 while (readl(&cmalwon->i2c0clkctrl) != PRCM_MOD_EN)
356 /* Enable ethernet0 */
357 writel(PRCM_MOD_EN, &cmalwon->ethclkstctrl);
358 writel(PRCM_MOD_EN, &cmalwon->ethernet0clkctrl);
359 writel(PRCM_MOD_EN, &cmalwon->ethernet1clkctrl);
362 writel(PRCM_MOD_EN, &cmalwon->sdioclkctrl);
363 while (readl(&cmalwon->sdioclkctrl) != PRCM_MOD_EN)
367 void setup_clocks_for_console(void)
369 /* Fix ROM code bug - from TI-PSP-04.00.02.14 */
370 writel(0x0, CM_SYSCLK10_CLKSEL);
372 ddr_pll_bypass_ti816x();
375 writel(PRCM_MOD_EN, &cmalwon->uart0clkctrl);
376 while (readl(&cmalwon->uart0clkctrl) != PRCM_MOD_EN)
378 writel(PRCM_MOD_EN, &cmalwon->uart1clkctrl);
379 while (readl(&cmalwon->uart1clkctrl) != PRCM_MOD_EN)
381 writel(PRCM_MOD_EN, &cmalwon->uart2clkctrl);
382 while (readl(&cmalwon->uart2clkctrl) != PRCM_MOD_EN)
384 while ((readl(&cmalwon->l3slowclkstctrl) & 0x2100) != 0x2100)
388 void setup_early_clocks(void)
390 setup_clocks_for_console();
395 /* Enable the control */
396 writel(PRCM_MOD_EN, &cmalwon->controlclkctrl);
398 main_pll_init_ti816x();
399 ddr_pll_init_ti816x();
402 * With clk freqs setup to desired values,
403 * enable the required peripherals