Support for ES2.2 pandaboard
[pandora-x-loader.git] / board / omap4430panda / clock.c
1 /*
2  * (C) Copyright 2009
3  * Texas Instruments, <www.ti.com>
4  * Richard Woodruff <r-woodruff2@ti.com>
5  * Rajendra Nayak <rnayak@ti.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <asm/arch/cpu.h>
25 #include <asm/io.h>
26 #include <asm/arch/bits.h>
27 #include <asm/arch/clocks.h>
28 #include <asm/arch/mem.h>
29 #include <asm/arch/sys_proto.h>
30 #include <asm/arch/sys_info.h>
31 #include <asm/arch/clocks443x.h>
32 #include <command.h>
33
34 #define CONFIG_OMAP4_SDC 1
35
36 /* Used to index into DPLL parameter tables */
37 struct dpll_param {
38         unsigned int m;
39         unsigned int n;
40         unsigned int m2;
41         unsigned int m3;
42         unsigned int m4;
43         unsigned int m5;
44         unsigned int m6;
45         unsigned int m7;
46 };
47
48 /* Tables having M,N,M2 et al values for different sys_clk speeds
49  * This table is generated only for OPP100
50  * The tables are organized as follows:
51  * Rows : 1 - 12M, 2 - 13M, 3 - 16.8M, 4 - 19.2M, 5 - 26M, 6 - 27M, 7 - 38.4M
52  */
53
54 /* MPU parameters */
55 struct dpll_param mpu_dpll_param[7] = {
56         /* 12M values */
57         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
58         /* 13M values */
59         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
60         /* 16.8M values */
61         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
62         /* 19.2M values */
63         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
64         /* 26M values */
65         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
66         /* 27M values */
67         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
68         /* 38.4M values */
69 #ifdef CONFIG_MPU_600
70         /* RUN MPU @ 600 MHz */
71         {0x7d, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00},
72 #elif CONFIG_MPU_1000
73         {0x69, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00},
74 #else
75         {0x1a, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00},       
76 #endif
77 };
78
79 /* IVA parameters */
80 struct dpll_param iva_dpll_param[7] = {
81         /* 12M values */
82         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
83         /* 13M values */
84         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
85         /* 16.8M values */
86         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
87         /* 19.2M values */
88         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
89         /* 26M values */
90         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
91         /* 27M values */
92         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
93         /* 38.4M values */
94 #ifdef CONFIG_OMAP4_SDC
95         {0x61, 0x03, 0x00, 0x00, 0x04, 0x07, 0x00, 0x00},
96 #else
97         {0x61, 0x03, 0x00, 0x00, 0x04, 0x07, 0x00, 0x00},
98 #endif
99 };
100
101 /* CORE parameters */
102 struct dpll_param core_dpll_param[7] = {
103         /* 12M values */
104         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
105         /* 13M values */
106         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
107         /* 16.8M values */
108         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
109         /* 19.2M values */
110         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
111         /* 26M values */
112         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
113         /* 27M values */
114         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
115         /* 38.4M values - DDR@200MHz*/
116         {0x7d, 0x05, 0x02, 0x05, 0x08, 0x04, 0x06, 0x05},
117 };
118
119 /* CORE parameters - ES2.1 */
120 struct dpll_param core_dpll_param_ddr400[7] = {
121         /* 12M values */
122         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
123         /* 13M values */
124         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
125         /* 16.8M values */
126         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
127         /* 19.2M values */
128         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
129         /* 26M values */
130         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
131         /* 27M values */
132         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
133         /* 38.4M values - DDR@400MHz*/
134         {0x7d, 0x05, 0x01, 0x05, 0x08, 0x04, 0x06, 0x05},
135 };
136
137 /* CORE parameters for L3 at 190 MHz - For ES1 only*/
138 struct dpll_param core_dpll_param_l3_190[7] = {
139         /* 12M values */
140         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
141         /* 13M values */
142         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
143         /* 16.8M values */
144         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
145         /* 19.2M values */
146         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
147         /* 26M values */
148         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
149         /* 27M values */
150         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
151         /* 38.4M values */
152 #ifdef CONFIG_OMAP4_SDC
153 #ifdef CORE_190MHZ 
154         {0x1f0, 0x18, 0x01, 0x05, 0x08, 0x04, 0x06, 0x05},
155 #else /* Default CORE @166MHz */
156         {0x1b0, 0x18, 0x01, 0x05, 0x08, 0x04, 0x06, 0x05},
157 #endif
158 #else
159         {0x7d, 0x05, 0x01, 0x05, 0x08, 0x04, 0x06, 0x08},
160 #endif
161 };
162
163 /* PER parameters */
164 struct dpll_param per_dpll_param[7] = {
165         /* 12M values */
166         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
167         /* 13M values */
168         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
169         /* 16.8M values */
170         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
171         /* 19.2M values */
172         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
173         /* 26M values */
174         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
175         /* 27M values */
176         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
177         /* 38.4M values */
178 #if 0
179         /* SDC settings */
180         {0x0a, 0x00, 0x04, 0x03, 0x06, 0x05, 0x02, 0x03},
181 #endif
182         {0x14, 0x00, 0x08, 0x06, 0x0c, 0x09, 0x04, 0x05},
183 };
184
185 /* ABE parameters */
186 struct dpll_param abe_dpll_param[7] = {
187         /* 12M values */
188         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
189         /* 13M values */
190         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
191         /* 16.8M values */
192         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
193         /* 19.2M values */
194         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
195         /* 26M values */
196         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
197         /* 27M values */
198         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
199         /* 38.4M values */
200 #ifdef CONFIG_OMAP4_SDC
201         {0x40, 0x18, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0},
202 #else
203         {0x40, 0x18, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0},
204 #endif
205 };
206
207 /* USB parameters */
208 struct dpll_param usb_dpll_param[7] = {
209         /* 12M values */
210         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
211         /* 13M values */
212         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
213         /* 16.8M values */
214         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
215         /* 19.2M values */
216         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
217         /* 26M values */
218         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
219         /* 27M values */
220         {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
221         /* 38.4M values */
222 #ifdef CONFIG_OMAP4_SDC
223         {0x32, 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0},
224 #else
225         {0x32, 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0},
226 #endif
227 };
228
229 typedef struct dpll_param dpll_param;
230
231 static void configure_mpu_dpll(u32 clk_index)
232 {
233         dpll_param *dpll_param_p;
234
235         /* Unlock the MPU dpll */
236         sr32(CM_CLKMODE_DPLL_MPU, 0, 3, PLL_MN_POWER_BYPASS);
237         wait_on_value(BIT0, 0, CM_IDLEST_DPLL_MPU, LDELAY);
238
239         /* Program MPU DPLL */
240         dpll_param_p = &mpu_dpll_param[clk_index];
241
242         sr32(CM_AUTOIDLE_DPLL_MPU, 0, 3, 0x0); /* Disable DPLL autoidle */
243
244         /* Set M,N,M2 values */
245         sr32(CM_CLKSEL_DPLL_MPU, 8, 11, dpll_param_p->m);
246         sr32(CM_CLKSEL_DPLL_MPU, 0, 6, dpll_param_p->n);
247         sr32(CM_DIV_M2_DPLL_MPU, 0, 5, dpll_param_p->m2);
248         sr32(CM_DIV_M2_DPLL_MPU, 8, 1, 0x1);
249
250         /* Lock the mpu dpll */
251         sr32(CM_CLKMODE_DPLL_MPU, 0, 3, PLL_LOCK | 0x10);
252         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_MPU, LDELAY);
253
254         return;
255 }
256
257 static void configure_iva_dpll(u32 clk_index)
258 {
259         dpll_param *dpll_param_p;
260
261         /* Unlock the IVA dpll */
262         sr32(CM_CLKMODE_DPLL_IVA, 0, 3, PLL_MN_POWER_BYPASS);
263         wait_on_value(BIT0, 0, CM_IDLEST_DPLL_IVA, LDELAY);
264
265         /* CM_BYPCLK_DPLL_IVA = CORE_X2_CLK/2 */
266         sr32(CM_BYPCLK_DPLL_IVA, 0, 2, 0x1);
267
268         /* Program IVA DPLL */
269         dpll_param_p = &iva_dpll_param[clk_index];
270
271         sr32(CM_AUTOIDLE_DPLL_IVA, 0, 3, 0x0); /* Disable DPLL autoidle */
272
273         /* Set M,N,M4,M5 */
274         sr32(CM_CLKSEL_DPLL_IVA, 8, 11, dpll_param_p->m);
275         sr32(CM_CLKSEL_DPLL_IVA, 0, 7, dpll_param_p->n);
276         sr32(CM_DIV_M4_DPLL_IVA, 0, 5, dpll_param_p->m4);
277         sr32(CM_DIV_M4_DPLL_IVA, 8, 1, 0x1);
278         sr32(CM_DIV_M5_DPLL_IVA, 0, 5, dpll_param_p->m5);
279         sr32(CM_DIV_M5_DPLL_IVA, 8, 1, 0x1);
280
281         /* Lock the iva dpll */
282         sr32(CM_CLKMODE_DPLL_IVA, 0, 3, PLL_LOCK);
283         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_IVA, LDELAY);
284
285         return;
286 }
287
288 static void configure_per_dpll(u32 clk_index)
289 {
290         dpll_param *dpll_param_p;
291
292         /* Unlock the PER dpll */
293         sr32(CM_CLKMODE_DPLL_PER, 0, 3, PLL_MN_POWER_BYPASS);
294         wait_on_value(BIT0, 0, CM_IDLEST_DPLL_PER, LDELAY);
295
296         /* Program PER DPLL */
297         dpll_param_p = &per_dpll_param[clk_index];
298
299         /* Disable autoidle */
300         sr32(CM_AUTOIDLE_DPLL_PER, 0, 3, 0x0);
301
302         sr32(CM_CLKSEL_DPLL_PER, 8, 11, dpll_param_p->m);
303         sr32(CM_CLKSEL_DPLL_PER, 0, 6, dpll_param_p->n);
304         sr32(CM_DIV_M2_DPLL_PER, 0, 5, dpll_param_p->m2);
305         sr32(CM_DIV_M3_DPLL_PER, 0, 5, dpll_param_p->m3);
306         sr32(CM_DIV_M4_DPLL_PER, 0, 5, dpll_param_p->m4);
307         sr32(CM_DIV_M5_DPLL_PER, 0, 5, dpll_param_p->m5);
308         sr32(CM_DIV_M6_DPLL_PER, 0, 5, dpll_param_p->m6);
309         sr32(CM_DIV_M7_DPLL_PER, 0, 5, dpll_param_p->m7);
310
311 //      if(omap_revision() == OMAP4430_ES1_0)
312 //      {
313                 /* Do this only on ES1.0 */
314                 sr32(CM_DIV_M2_DPLL_PER, 8, 1, 0x1);
315                 sr32(CM_DIV_M3_DPLL_PER, 8, 1, 0x1);
316                 sr32(CM_DIV_M4_DPLL_PER, 8, 1, 0x1);
317                 sr32(CM_DIV_M5_DPLL_PER, 8, 1, 0x1);
318                 sr32(CM_DIV_M6_DPLL_PER, 8, 1, 0x1);
319                 sr32(CM_DIV_M7_DPLL_PER, 8, 1, 0x1);
320 //      }
321
322         /* Lock the per dpll */
323         sr32(CM_CLKMODE_DPLL_PER, 0, 3, PLL_LOCK);
324         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_PER, LDELAY);
325
326         return;
327 }
328
329 static void configure_abe_dpll(u32 clk_index)
330 {
331         dpll_param *dpll_param_p;
332
333         /* Select sys_clk as ref clk for ABE dpll */
334         sr32(CM_ABE_PLL_REF_CLKSEL, 0, 32, 0x0);
335
336         /* Enable slimbus and pad clocks */
337         sr32(CM_CLKSEL_ABE, 0, 32, 0x500);
338
339         /* Unlock the ABE dpll */
340         sr32(CM_CLKMODE_DPLL_ABE, 0, 3, PLL_MN_POWER_BYPASS);
341         wait_on_value(BIT0, 0, CM_IDLEST_DPLL_ABE, LDELAY);
342
343         /* Program ABE DPLL */
344         dpll_param_p = &abe_dpll_param[clk_index];
345
346         /* Disable autoidle */
347         sr32(CM_AUTOIDLE_DPLL_ABE, 0, 3, 0x0);
348
349         sr32(CM_CLKSEL_DPLL_ABE, 8, 11, dpll_param_p->m);
350         sr32(CM_CLKSEL_DPLL_ABE, 0, 6, dpll_param_p->n);
351
352         /* Force DPLL CLKOUTHIF to stay enabled */
353         sr32(CM_DIV_M2_DPLL_ABE, 0, 32, 0x500);
354         sr32(CM_DIV_M2_DPLL_ABE, 0, 5, dpll_param_p->m2);
355         sr32(CM_DIV_M2_DPLL_ABE, 8, 1, 0x1);
356         /* Force DPLL CLKOUTHIF to stay enabled */
357         sr32(CM_DIV_M3_DPLL_ABE, 0, 32, 0x100);
358         sr32(CM_DIV_M3_DPLL_ABE, 0, 5, dpll_param_p->m3);
359         sr32(CM_DIV_M3_DPLL_ABE, 8, 1, 0x1);
360
361         /* Lock the abe dpll */
362         sr32(CM_CLKMODE_DPLL_ABE, 0, 3, PLL_LOCK);
363         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_ABE, LDELAY);
364
365         return;
366 }
367
368 static void configure_usb_dpll(u32 clk_index)
369 {
370         dpll_param *dpll_param_p;
371
372         /* Select the 60Mhz clock 480/8 = 60*/
373         sr32(CM_CLKSEL_USB_60MHz, 0, 32, 0x1);
374
375         /* Unlock the USB dpll */
376         sr32(CM_CLKMODE_DPLL_USB, 0, 3, PLL_MN_POWER_BYPASS);
377         wait_on_value(BIT0, 0, CM_IDLEST_DPLL_USB, LDELAY);
378
379         /* Program USB DPLL */
380         dpll_param_p = &usb_dpll_param[clk_index];
381
382         /* Disable autoidle */
383         sr32(CM_AUTOIDLE_DPLL_USB, 0, 3, 0x0);
384
385         sr32(CM_CLKSEL_DPLL_USB, 8, 11, dpll_param_p->m);
386         sr32(CM_CLKSEL_DPLL_USB, 0, 6, dpll_param_p->n);
387
388         /* Force DPLL CLKOUT to stay active */
389         sr32(CM_DIV_M2_DPLL_USB, 0, 32, 0x100);
390         sr32(CM_DIV_M2_DPLL_USB, 0, 5, dpll_param_p->m2);
391         sr32(CM_DIV_M2_DPLL_USB, 8, 1, 0x1);
392         sr32(CM_CLKDCOLDO_DPLL_USB, 8, 1, 0x1);
393
394         /* Lock the usb dpll */
395         sr32(CM_CLKMODE_DPLL_USB, 0, 3, PLL_LOCK);
396         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_USB, LDELAY);
397
398         /* force enable the CLKDCOLDO clock */
399         sr32(CM_CLKDCOLDO_DPLL_USB, 0, 32, 0x100);
400
401         return;
402 }
403
404 static void configure_core_dpll(clk_index)
405 {
406         dpll_param *dpll_param_p;
407
408         /* Get the sysclk speed from cm_sys_clksel
409          * Set it to 38.4 MHz, in case ROM code is bypassed
410          */
411         if (!clk_index)
412                 return;
413
414         /* CORE_CLK=CORE_X2_CLK/2, L3_CLK=CORE_CLK/2, L4_CLK=L3_CLK/2 */
415         sr32(CM_CLKSEL_CORE, 0, 32, 0x110);
416
417         /* Unlock the CORE dpll */
418         sr32(CM_CLKMODE_DPLL_CORE, 0, 3, PLL_MN_POWER_BYPASS);
419         wait_on_value(BIT0, 0, CM_IDLEST_DPLL_CORE, LDELAY);
420
421         /* Program Core DPLL */
422         if(omap_revision() == OMAP4430_ES1_0)
423                 dpll_param_p = &core_dpll_param_l3_190[clk_index];
424         else if(omap_revision() == OMAP4430_ES2_0)
425                 dpll_param_p = &core_dpll_param[clk_index];
426         else if(omap_revision() >= OMAP4430_ES2_1)
427                 dpll_param_p = &core_dpll_param_ddr400[clk_index];
428
429         /* Disable autoidle */
430         sr32(CM_AUTOIDLE_DPLL_CORE, 0, 3, 0x0);
431
432         sr32(CM_CLKSEL_DPLL_CORE, 8, 11, dpll_param_p->m);
433         sr32(CM_CLKSEL_DPLL_CORE, 0, 6, dpll_param_p->n);
434         sr32(CM_DIV_M2_DPLL_CORE, 0, 5, dpll_param_p->m2);
435         sr32(CM_DIV_M3_DPLL_CORE, 0, 5, dpll_param_p->m3);
436         sr32(CM_DIV_M4_DPLL_CORE, 0, 5, dpll_param_p->m4);
437         sr32(CM_DIV_M5_DPLL_CORE, 0, 5, dpll_param_p->m5);
438         sr32(CM_DIV_M6_DPLL_CORE, 0, 5, dpll_param_p->m6);
439         sr32(CM_DIV_M7_DPLL_CORE, 0, 5, dpll_param_p->m7);
440
441         if(omap_revision() == OMAP4430_ES1_0)
442         {
443                 /* Do this only on ES1.0 */
444                 sr32(CM_DIV_M2_DPLL_CORE, 8, 1, 0x1);
445                 sr32(CM_DIV_M3_DPLL_CORE, 8, 1, 0x1);
446                 sr32(CM_DIV_M4_DPLL_CORE, 8, 1, 0x1);
447                 sr32(CM_DIV_M5_DPLL_CORE, 8, 1, 0x1);
448                 sr32(CM_DIV_M6_DPLL_CORE, 8, 1, 0x0);
449                 sr32(CM_DIV_M7_DPLL_CORE, 8, 1, 0x1);
450         }
451
452
453         /* Lock the core dpll */
454         sr32(CM_CLKMODE_DPLL_CORE, 0, 3, PLL_LOCK);
455         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_CORE, LDELAY);
456
457         return;
458 }
459
460
461 void configure_core_dpll_no_lock(void)
462 {
463         dpll_param *dpll_param_p;
464         u32 clk_index;
465
466         /* Get the sysclk speed from cm_sys_clksel
467          * Set it to 38.4 MHz, in case ROM code is bypassed
468          */
469         __raw_writel(0x7,CM_SYS_CLKSEL);
470         clk_index = 7;
471
472         clk_index = clk_index - 1;
473         /* CORE_CLK=CORE_X2_CLK/2, L3_CLK=CORE_CLK/2, L4_CLK=L3_CLK/2 */
474         sr32(CM_CLKSEL_CORE, 0, 32, 0x110);
475
476         /* Unlock the CORE dpll */
477         sr32(CM_CLKMODE_DPLL_CORE, 0, 3, PLL_MN_POWER_BYPASS);
478         wait_on_value(BIT0, 0, CM_IDLEST_DPLL_CORE, LDELAY);
479
480         /* Program Core DPLL */
481         if(omap_revision() == OMAP4430_ES1_0)
482                 dpll_param_p = &core_dpll_param_l3_190[clk_index];
483         else if(omap_revision() == OMAP4430_ES2_0)
484                 dpll_param_p = &core_dpll_param[clk_index];
485         else if(omap_revision() >= OMAP4430_ES2_1)
486                 dpll_param_p = &core_dpll_param_ddr400[clk_index];
487
488         /* Disable autoidle */
489         sr32(CM_AUTOIDLE_DPLL_CORE, 0, 3, 0x0);
490
491         sr32(CM_CLKSEL_DPLL_CORE, 8, 11, dpll_param_p->m);
492         sr32(CM_CLKSEL_DPLL_CORE, 0, 6, dpll_param_p->n);
493         sr32(CM_DIV_M2_DPLL_CORE, 0, 5, dpll_param_p->m2);
494         sr32(CM_DIV_M3_DPLL_CORE, 0, 5, dpll_param_p->m3);
495         sr32(CM_DIV_M4_DPLL_CORE, 0, 5, dpll_param_p->m4);
496         sr32(CM_DIV_M5_DPLL_CORE, 0, 5, dpll_param_p->m5);
497         sr32(CM_DIV_M6_DPLL_CORE, 0, 5, dpll_param_p->m6);
498         sr32(CM_DIV_M7_DPLL_CORE, 0, 5, dpll_param_p->m7);
499
500 //      if(omap_revision() == OMAP4430_ES1_0)
501 //      {
502                 /* Do this only on ES1.0 */
503                 sr32(CM_DIV_M2_DPLL_CORE, 8, 1, 0x1);
504                 sr32(CM_DIV_M3_DPLL_CORE, 8, 1, 0x1);
505                 sr32(CM_DIV_M4_DPLL_CORE, 8, 1, 0x1);
506                 sr32(CM_DIV_M5_DPLL_CORE, 8, 1, 0x1);
507                 sr32(CM_DIV_M6_DPLL_CORE, 8, 1, 0x0);
508                 sr32(CM_DIV_M7_DPLL_CORE, 8, 1, 0x1);
509 //      }
510
511         return;
512 }
513
514 void lock_core_dpll(void)
515 {
516         /* Lock the core dpll */
517         sr32(CM_CLKMODE_DPLL_CORE, 0, 3, PLL_LOCK);
518         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_CORE, LDELAY);
519
520         return;
521 }
522
523 void lock_core_dpll_shadow(void)
524 {
525         dpll_param *dpll_param_p;
526         /* Lock the core dpll using freq update method */
527         *(volatile int*)0x4A004120 = 10;        //(CM_CLKMODE_DPLL_CORE)
528
529         if(omap_revision() == OMAP4430_ES1_0)
530                 dpll_param_p = &core_dpll_param_l3_190[6];
531         else if(omap_revision() == OMAP4430_ES2_0)
532                 dpll_param_p = &core_dpll_param[6];
533         else if(omap_revision() >= OMAP4430_ES2_1)
534                 dpll_param_p = &core_dpll_param_ddr400[6];
535
536         /* CM_SHADOW_FREQ_CONFIG1: DLL_OVERRIDE = 1(hack), DLL_RESET = 1,
537          * DPLL_CORE_M2_DIV =1, DPLL_CORE_DPLL_EN = 0x7, FREQ_UPDATE = 1
538          */
539         *(volatile int*)0x4A004260 = 0x70D | (dpll_param_p->m2 << 11);
540
541         /* Wait for Freq_Update to get cleared: CM_SHADOW_FREQ_CONFIG1 */
542         while( ( (*(volatile int*)0x4A004260) & 0x1) == 0x1 );
543
544         /* Wait for DPLL to Lock : CM_IDLEST_DPLL_CORE */
545         wait_on_value(BIT0, 1, CM_IDLEST_DPLL_CORE, LDELAY);
546         //lock_core_dpll();
547
548         return;
549 }
550
551 static void enable_all_clocks(void)
552 {
553         volatile int regvalue = 0;
554
555         /* Enable Ducati clocks */
556         sr32(CM_DUCATI_DUCATI_CLKCTRL, 0, 32, 0x1);
557         sr32(CM_DUCATI_CLKSTCTRL, 0, 32, 0x2);
558
559         wait_on_value(BIT8, BIT8, CM_DUCATI_CLKSTCTRL, LDELAY);
560         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_DUCATI_DUCATI_CLKCTRL, LDELAY);
561
562         /* Enable ivahd and sl2 clocks */
563         sr32(IVAHD_IVAHD_CLKCTRL, 0, 32, 0x1);
564         sr32(IVAHD_SL2_CLKCTRL, 0, 32, 0x1);
565         sr32(IVAHD_CLKSTCTRL, 0, 32, 0x2);
566
567         wait_on_value(BIT8, BIT8, IVAHD_CLKSTCTRL, LDELAY);
568
569         /* wait for ivahd to become accessible */
570         //wait_on_value(BIT18|BIT17|BIT16, 0, IVAHD_IVAHD_CLKCTRL, LDELAY);
571         /* wait for sl2 to become accessible */
572         //wait_on_value(BIT17|BIT16, 0, IVAHD_SL2_CLKCTRL, LDELAY);
573
574         /* Enable Tesla clocks */
575         sr32(DSP_DSP_CLKCTRL, 0, 32, 0x1);
576         sr32(DSP_CLKSTCTRL, 0, 32, 0x2);
577
578         wait_on_value(BIT8, BIT8, DSP_CLKSTCTRL, LDELAY);
579
580         /* wait for tesla to become accessible */
581         //wait_on_value(BIT18|BIT17|BIT16, 0, DSP_DSP_CLKCTRL, LDELAY);
582
583         /* TODO: Some hack needed by MM: Clean this */
584         #if 0 /* Doesn't work on some Zebu */
585         *(volatile int*)0x4a306910 = 0x00000003;
586         *(volatile int*)0x550809a0 = 0x00000001;
587         *(volatile int*)0x55080a20 = 0x00000007;
588         #endif
589
590         /* ABE clocks */
591         sr32(CM1_ABE_CLKSTCTRL, 0, 32, 0x3);
592         sr32(CM1_ABE_AESS_CLKCTRL, 0, 32, 0x2);
593         //wait_on_value(BIT18|BIT17|BIT16, 0, CM1_ABE_AESS_CLKCTRL, LDELAY);
594         sr32(CM1_ABE_PDM_CLKCTRL, 0, 32, 0x2);
595         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_PDM_CLKCTRL, LDELAY);
596         sr32(CM1_ABE_DMIC_CLKCTRL, 0, 32, 0x2);
597         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_DMIC_CLKCTRL, LDELAY);
598         sr32(CM1_ABE_MCASP_CLKCTRL, 0, 32, 0x2);
599         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_MCASP_CLKCTRL, LDELAY);
600         sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x08000002);
601         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_MCBSP1_CLKCTRL, LDELAY);
602         sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x08000002);
603         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_MCBSP2_CLKCTRL, LDELAY);
604         sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x08000002);
605         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_MCBSP3_CLKCTRL, LDELAY);
606         sr32(CM1_ABE_SLIMBUS_CLKCTRL, 0, 32, 0xf02);
607         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_SLIMBUS_CLKCTRL, LDELAY);
608         sr32(CM1_ABE_TIMER5_CLKCTRL, 0, 32, 0x2);
609         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_TIMER5_CLKCTRL, LDELAY);
610         sr32(CM1_ABE_TIMER6_CLKCTRL, 0, 32, 0x2);
611         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_TIMER6_CLKCTRL, LDELAY);
612         sr32(CM1_ABE_TIMER7_CLKCTRL, 0, 32, 0x2);
613         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_TIMER7_CLKCTRL, LDELAY);
614         sr32(CM1_ABE_TIMER8_CLKCTRL, 0, 32, 0x2);
615         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_TIMER8_CLKCTRL, LDELAY);
616         sr32(CM1_ABE_WDT3_CLKCTRL, 0, 32, 0x2);
617         //wait_on_value(BIT17|BIT16, 0, CM1_ABE_WDT3_CLKCTRL, LDELAY);
618         /* Disable sleep transitions */
619         sr32(CM1_ABE_CLKSTCTRL, 0, 32, 0x0);
620
621         /* L4PER clocks */
622         sr32(CM_L4PER_CLKSTCTRL, 0, 32, 0x2);
623         sr32(CM_L4PER_DMTIMER10_CLKCTRL, 0, 32, 0x2);
624         wait_on_value(BIT17|BIT16, 0, CM_L4PER_DMTIMER10_CLKCTRL, LDELAY);
625         sr32(CM_L4PER_DMTIMER11_CLKCTRL, 0, 32, 0x2);
626         wait_on_value(BIT17|BIT16, 0, CM_L4PER_DMTIMER11_CLKCTRL, LDELAY);
627         sr32(CM_L4PER_DMTIMER2_CLKCTRL, 0, 32, 0x2);
628         wait_on_value(BIT17|BIT16, 0, CM_L4PER_DMTIMER2_CLKCTRL, LDELAY);
629         sr32(CM_L4PER_DMTIMER3_CLKCTRL, 0, 32, 0x2);
630         wait_on_value(BIT17|BIT16, 0, CM_L4PER_DMTIMER3_CLKCTRL, LDELAY);
631         sr32(CM_L4PER_DMTIMER4_CLKCTRL, 0, 32, 0x2);
632         wait_on_value(BIT17|BIT16, 0, CM_L4PER_DMTIMER4_CLKCTRL, LDELAY);
633         sr32(CM_L4PER_DMTIMER9_CLKCTRL, 0, 32, 0x2);
634         wait_on_value(BIT17|BIT16, 0, CM_L4PER_DMTIMER9_CLKCTRL, LDELAY);
635
636         /* GPIO clocks */
637         sr32(CM_L4PER_GPIO2_CLKCTRL, 0 ,32, 0x1);
638         wait_on_value(BIT17|BIT16, 0, CM_L4PER_GPIO2_CLKCTRL, LDELAY);
639         sr32(CM_L4PER_GPIO3_CLKCTRL, 0, 32, 0x1);
640         wait_on_value(BIT17|BIT16, 0, CM_L4PER_GPIO3_CLKCTRL, LDELAY);
641         sr32(CM_L4PER_GPIO4_CLKCTRL, 0, 32, 0x1);
642         wait_on_value(BIT17|BIT16, 0, CM_L4PER_GPIO4_CLKCTRL, LDELAY);
643         sr32(CM_L4PER_GPIO5_CLKCTRL, 0, 32, 0x1);
644         wait_on_value(BIT17|BIT16, 0, CM_L4PER_GPIO5_CLKCTRL, LDELAY);
645         sr32(CM_L4PER_GPIO6_CLKCTRL, 0, 32, 0x1);
646         wait_on_value(BIT17|BIT16, 0, CM_L4PER_GPIO6_CLKCTRL, LDELAY);
647
648         sr32(CM_L4PER_HDQ1W_CLKCTRL, 0, 32, 0x2);
649
650         /* I2C clocks */
651         sr32(CM_L4PER_I2C1_CLKCTRL, 0, 32, 0x2);
652         wait_on_value(BIT17|BIT16, 0, CM_L4PER_I2C1_CLKCTRL, LDELAY);
653         sr32(CM_L4PER_I2C2_CLKCTRL, 0, 32, 0x2);
654         wait_on_value(BIT17|BIT16, 0, CM_L4PER_I2C2_CLKCTRL, LDELAY);
655         sr32(CM_L4PER_I2C3_CLKCTRL, 0, 32, 0x2);
656         wait_on_value(BIT17|BIT16, 0, CM_L4PER_I2C3_CLKCTRL, LDELAY);
657         sr32(CM_L4PER_I2C4_CLKCTRL, 0, 32, 0x2);
658         wait_on_value(BIT17|BIT16, 0, CM_L4PER_I2C4_CLKCTRL, LDELAY);
659
660         sr32(CM_L4PER_MCBSP4_CLKCTRL, 0, 32, 0x2);
661         wait_on_value(BIT17|BIT16, 0, CM_L4PER_MCBSP4_CLKCTRL, LDELAY);
662
663         /* MCSPI clocks */
664         sr32(CM_L4PER_MCSPI1_CLKCTRL, 0, 32, 0x2);
665         wait_on_value(BIT17|BIT16, 0, CM_L4PER_MCSPI1_CLKCTRL, LDELAY);
666         sr32(CM_L4PER_MCSPI2_CLKCTRL, 0, 32, 0x2);
667         wait_on_value(BIT17|BIT16, 0, CM_L4PER_MCSPI2_CLKCTRL, LDELAY);
668         sr32(CM_L4PER_MCSPI3_CLKCTRL, 0, 32, 0x2);
669         wait_on_value(BIT17|BIT16, 0, CM_L4PER_MCSPI3_CLKCTRL, LDELAY);
670         sr32(CM_L4PER_MCSPI4_CLKCTRL, 0, 32, 0x2);
671         wait_on_value(BIT17|BIT16, 0, CM_L4PER_MCSPI4_CLKCTRL, LDELAY);
672
673         /* MMC clocks */
674         sr32(CM_L3INIT_HSMMC1_CLKCTRL, 0, 2, 0x2);
675         sr32(CM_L3INIT_HSMMC1_CLKCTRL, 24, 1, 0x1);
676         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_L3INIT_HSMMC1_CLKCTRL, LDELAY);
677         sr32(CM_L3INIT_HSMMC2_CLKCTRL, 0, 2, 0x2);
678         sr32(CM_L3INIT_HSMMC2_CLKCTRL, 24, 1, 0x1);
679         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_L3INIT_HSMMC2_CLKCTRL, LDELAY);
680         sr32(CM_L4PER_MMCSD3_CLKCTRL, 0, 32, 0x2);
681         wait_on_value(BIT18|BIT17|BIT16, 0, CM_L4PER_MMCSD3_CLKCTRL, LDELAY);
682         sr32(CM_L4PER_MMCSD4_CLKCTRL, 0, 32, 0x2);
683         wait_on_value(BIT18|BIT17|BIT16, 0, CM_L4PER_MMCSD4_CLKCTRL, LDELAY);
684         sr32(CM_L4PER_MMCSD5_CLKCTRL, 0, 32, 0x2);
685         wait_on_value(BIT17|BIT16, 0, CM_L4PER_MMCSD5_CLKCTRL, LDELAY);
686
687         /* UART clocks */
688         sr32(CM_L4PER_UART1_CLKCTRL, 0, 32, 0x2);
689         wait_on_value(BIT17|BIT16, 0, CM_L4PER_UART1_CLKCTRL, LDELAY);
690         sr32(CM_L4PER_UART2_CLKCTRL, 0, 32, 0x2);
691         wait_on_value(BIT17|BIT16, 0, CM_L4PER_UART2_CLKCTRL, LDELAY);
692         sr32(CM_L4PER_UART3_CLKCTRL, 0, 32, 0x2);
693         wait_on_value(BIT17|BIT16, 0, CM_L4PER_UART3_CLKCTRL, LDELAY);
694         sr32(CM_L4PER_UART4_CLKCTRL, 0, 32, 0x2);
695         wait_on_value(BIT17|BIT16, 0, CM_L4PER_UART4_CLKCTRL, LDELAY);
696
697         /* WKUP clocks */
698         sr32(CM_WKUP_GPIO1_CLKCTRL, 0, 32, 0x1);
699         wait_on_value(BIT17|BIT16, 0, CM_WKUP_GPIO1_CLKCTRL, LDELAY);
700         sr32(CM_WKUP_TIMER1_CLKCTRL, 0, 32, 0x01000002);
701         wait_on_value(BIT17|BIT16, 0, CM_WKUP_TIMER1_CLKCTRL, LDELAY);
702
703         sr32(CM_WKUP_KEYBOARD_CLKCTRL, 0, 32, 0x2);
704         wait_on_value(BIT17|BIT16, 0, CM_WKUP_KEYBOARD_CLKCTRL, LDELAY);
705
706         sr32(CM_SDMA_CLKSTCTRL, 0, 32, 0x0);
707         sr32(CM_MEMIF_CLKSTCTRL, 0, 32, 0x3);
708         sr32(CM_MEMIF_EMIF_1_CLKCTRL, 0, 32, 0x1);
709         wait_on_value(BIT17|BIT16, 0, CM_MEMIF_EMIF_1_CLKCTRL, LDELAY);
710         sr32(CM_MEMIF_EMIF_2_CLKCTRL, 0, 32, 0x1);
711         wait_on_value(BIT17|BIT16, 0, CM_MEMIF_EMIF_2_CLKCTRL, LDELAY);
712         sr32(CM_D2D_CLKSTCTRL, 0, 32, 0x3);
713         sr32(CM_L3_2_GPMC_CLKCTRL, 0, 32, 0x1);
714         wait_on_value(BIT17|BIT16, 0, CM_L3_2_GPMC_CLKCTRL, LDELAY);
715         sr32(CM_L3INSTR_L3_3_CLKCTRL, 0, 32, 0x1);
716         wait_on_value(BIT17|BIT16, 0, CM_L3INSTR_L3_3_CLKCTRL, LDELAY);
717         sr32(CM_L3INSTR_L3_INSTR_CLKCTRL, 0, 32, 0x1);
718         wait_on_value(BIT17|BIT16, 0, CM_L3INSTR_L3_INSTR_CLKCTRL, LDELAY);
719         sr32(CM_L3INSTR_OCP_WP1_CLKCTRL, 0, 32, 0x1);
720         wait_on_value(BIT17|BIT16, 0, CM_L3INSTR_OCP_WP1_CLKCTRL, LDELAY);
721
722         /* WDT clocks */
723         sr32(CM_WKUP_WDT2_CLKCTRL, 0, 32, 0x2);
724         wait_on_value(BIT17|BIT16, 0, CM_WKUP_WDT2_CLKCTRL, LDELAY);
725
726         /* Enable Camera clocks */
727         sr32(CM_CAM_CLKSTCTRL, 0, 32, 0x3);
728         sr32(CM_CAM_ISS_CLKCTRL, 0, 32, 0x102);
729         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_CAM_ISS_CLKCTRL, LDELAY);
730         sr32(CM_CAM_FDIF_CLKCTRL, 0, 32, 0x2);
731         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_CAM_FDIF_CLKCTRL, LDELAY);
732         sr32(CM_CAM_CLKSTCTRL, 0, 32, 0x0);
733
734         /* Enable DSS clocks */
735         /* PM_DSS_PWRSTCTRL ON State and LogicState = 1 (Retention) */
736         *(volatile int*)0x4A307100 = 0x7; //DSS_PRM
737         sr32(CM_DSS_CLKSTCTRL, 0, 32, 0x2);
738         sr32(CM_DSS_DSS_CLKCTRL, 0, 32, 0xf02);
739         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_DSS_DSS_CLKCTRL, LDELAY);
740         sr32(CM_DSS_DEISS_CLKCTRL, 0, 32, 0x2);
741         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_DSS_DEISS_CLKCTRL, LDELAY);
742         /* Check for DSS Clocks */
743         while (((*(volatile int*)0x4A009100) & 0xF00) != 0xE00)
744         /* Set HW_AUTO transition mode */
745         sr32(CM_DSS_CLKSTCTRL, 0, 32, 0x3);
746
747         /* Enable SGX clocks */
748         sr32(CM_SGX_CLKSTCTRL, 0, 32, 0x2);
749         sr32(CM_SGX_SGX_CLKCTRL, 0, 32, 0x2);
750         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_SGX_SGX_CLKCTRL, LDELAY);
751         /* Check for SGX FCLK and ICLK */
752         while ( (*(volatile int*)0x4A009200) != 0x302 );
753         //sr32(CM_SGX_CLKSTCTRL, 0, 32, 0x0);
754         /* Enable hsi/unipro/usb clocks */
755         sr32(CM_L3INIT_HSI_CLKCTRL, 0, 32, 0x1);
756         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_L3INIT_HSI_CLKCTRL, LDELAY);
757         sr32(CM_L3INIT_UNIPRO1_CLKCTRL, 0, 32, 0x2);
758         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_L3INIT_UNIPRO1_CLKCTRL, LDELAY);
759         sr32(CM_L3INIT_HSUSBHOST_CLKCTRL, 0, 32, 0x2);
760         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_L3INIT_HSUSBHOST_CLKCTRL, LDELAY);
761         sr32(CM_L3INIT_HSUSBOTG_CLKCTRL, 0, 32, 0x1);
762         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_L3INIT_HSUSBOTG_CLKCTRL, LDELAY);
763         sr32(CM_L3INIT_HSUSBTLL_CLKCTRL, 0, 32, 0x1);
764         //wait_on_value(BIT17|BIT16, 0, CM_L3INIT_HSUSBTLL_CLKCTRL, LDELAY);
765         sr32(CM_L3INIT_FSUSB_CLKCTRL, 0, 32, 0x2);
766         //wait_on_value(BIT18|BIT17|BIT16, 0, CM_L3INIT_FSUSB_CLKCTRL, LDELAY);
767         /* enable the 32K, 48M optional clocks and enable the module */
768         sr32(CM_L3INIT_USBPHY_CLKCTRL, 0, 32, 0x301);
769         //wait_on_value(BIT17|BIT16, 0, CM_L3INIT_USBPHY_CLKCTRL, LDELAY);
770         return;
771 }
772
773 /******************************************************************************
774  * prcm_init() - inits clocks for PRCM as defined in clocks.h
775  *   -- called from SRAM, or Flash (using temp SRAM stack).
776  *****************************************************************************/
777 void prcm_init(void)
778 {
779         u32 clk_index;
780
781         /* Get the sysclk speed from cm_sys_clksel
782          * Set the CM_SYS_CLKSEL in case ROM code has not set
783          */
784         __raw_writel(0x7,CM_SYS_CLKSEL);
785         clk_index = readl(CM_SYS_CLKSEL);
786         if (!clk_index)
787                 return; /* Sys clk uninitialized */
788         /* Core DPLL is locked using FREQ update method */
789         /* configure_core_dpll(clk_index - 1); */
790
791         /* Configure all DPLL's at 100% OPP */
792         configure_mpu_dpll(clk_index - 1);
793         configure_iva_dpll(clk_index - 1);
794         configure_per_dpll(clk_index - 1);
795         configure_abe_dpll(clk_index - 1);
796         configure_usb_dpll(clk_index - 1);
797
798 #ifdef CONFIG_OMAP4_SDC
799         /* Enable all clocks */
800         enable_all_clocks();
801 #endif
802
803         return;
804 }