aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin
diff options
context:
space:
mode:
authorBob Liu <lliubbo@gmail.com>2012-07-22 22:47:48 -0400
committerBob Liu <lliubbo@gmail.com>2012-07-24 01:39:49 -0400
commitf82f16d2f55a68a5134e26edbc9303fe8048764f (patch)
tree834e3cec640d2a56958bb5ced476b20a30e99a02 /arch/blackfin
parente70f466067ef980876d6a190426b3670bccee4a7 (diff)
bfin: reorg clock init steps for bf609
So that user can set the clocks through menuconfig. Signed-off-by: Bob Liu <lliubbo@gmail.com>
Diffstat (limited to 'arch/blackfin')
-rw-r--r--arch/blackfin/Kconfig5
-rw-r--r--arch/blackfin/include/asm/mem_init.h212
-rw-r--r--arch/blackfin/mach-bf609/include/mach/defBF60x_base.h1
-rw-r--r--arch/blackfin/mach-common/clocks-init.c139
4 files changed, 224 insertions, 133 deletions
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 2baa4938d741..f9f6f6971b7e 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -352,6 +352,11 @@ config MEM_MT48H32M16LFCJ_75
352 depends on (BFIN526_EZBRD) 352 depends on (BFIN526_EZBRD)
353 default y 353 default y
354 354
355config MEM_MT47H64M16
356 bool
357 depends on (BFIN609_EZKIT)
358 default y
359
355source "arch/blackfin/mach-bf518/Kconfig" 360source "arch/blackfin/mach-bf518/Kconfig"
356source "arch/blackfin/mach-bf527/Kconfig" 361source "arch/blackfin/mach-bf527/Kconfig"
357source "arch/blackfin/mach-bf533/Kconfig" 362source "arch/blackfin/mach-bf533/Kconfig"
diff --git a/arch/blackfin/include/asm/mem_init.h b/arch/blackfin/include/asm/mem_init.h
index 237579935e29..f019e9bcefe9 100644
--- a/arch/blackfin/include/asm/mem_init.h
+++ b/arch/blackfin/include/asm/mem_init.h
@@ -6,6 +6,9 @@
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
8 8
9#ifndef __MEM_INIT_H__
10#define __MEM_INIT_H__
11
9#if defined(EBIU_SDGCTL) 12#if defined(EBIU_SDGCTL)
10#if defined(CONFIG_MEM_MT48LC16M16A2TG_75) || \ 13#if defined(CONFIG_MEM_MT48LC16M16A2TG_75) || \
11 defined(CONFIG_MEM_MT48LC64M4A2FB_7E) || \ 14 defined(CONFIG_MEM_MT48LC64M4A2FB_7E) || \
@@ -277,3 +280,212 @@
277#else 280#else
278#define PLL_BYPASS 0 281#define PLL_BYPASS 0
279#endif 282#endif
283
284#ifdef CONFIG_BF60x
285
286/* DMC status bits */
287#define IDLE 0x1
288#define MEMINITDONE 0x4
289#define SRACK 0x8
290#define PDACK 0x10
291#define DPDACK 0x20
292#define DLLCALDONE 0x2000
293#define PENDREF 0xF0000
294#define PHYRDPHASE 0xF00000
295#define PHYRDPHASE_OFFSET 20
296
297/* DMC control bits */
298#define LPDDR 0x2
299#define INIT 0x4
300#define SRREQ 0x8
301#define PDREQ 0x10
302#define DPDREQ 0x20
303#define PREC 0x40
304#define ADDRMODE 0x100
305#define RDTOWR 0xE00
306#define PPREF 0x1000
307#define DLLCAL 0x2000
308
309/* DMC DLL control bits */
310#define DLLCALRDCNT 0xFF
311#define DATACYC 0xF00
312#define DATACYC_OFFSET 8
313
314/* CGU Divisor bits */
315#define CSEL_OFFSET 0
316#define S0SEL_OFFSET 5
317#define SYSSEL_OFFSET 8
318#define S1SEL_OFFSET 13
319#define DSEL_OFFSET 16
320#define OSEL_OFFSET 22
321#define ALGN 0x20000000
322#define UPDT 0x40000000
323#define LOCK 0x80000000
324
325/* CGU Status bits */
326#define PLLEN 0x1
327#define PLLBP 0x2
328#define PLOCK 0x4
329#define CLKSALGN 0x8
330
331/* CGU Control bits */
332#define MSEL_MASK 0x7F00
333#define DF_MASK 0x1
334
335struct ddr_config {
336 u32 ddr_clk;
337 u32 dmc_ddrctl;
338 u32 dmc_ddrcfg;
339 u32 dmc_ddrtr0;
340 u32 dmc_ddrtr1;
341 u32 dmc_ddrtr2;
342 u32 dmc_ddrmr;
343 u32 dmc_ddrmr1;
344};
345
346#if defined(CONFIG_MEM_MT47H64M16)
347static struct ddr_config ddr_config_table[] __attribute__((section(".data_l1"))) = {
348 [0] = {
349 .ddr_clk = 125,
350 .dmc_ddrctl = 0x00000904,
351 .dmc_ddrcfg = 0x00000422,
352 .dmc_ddrtr0 = 0x20705212,
353 .dmc_ddrtr1 = 0x201003CF,
354 .dmc_ddrtr2 = 0x00320107,
355 .dmc_ddrmr = 0x00000422,
356 .dmc_ddrmr1 = 0x4,
357 },
358 [1] = {
359 .ddr_clk = 133,
360 .dmc_ddrctl = 0x00000904,
361 .dmc_ddrcfg = 0x00000422,
362 .dmc_ddrtr0 = 0x20806313,
363 .dmc_ddrtr1 = 0x2013040D,
364 .dmc_ddrtr2 = 0x00320108,
365 .dmc_ddrmr = 0x00000632,
366 .dmc_ddrmr1 = 0x4,
367 },
368 [2] = {
369 .ddr_clk = 150,
370 .dmc_ddrctl = 0x00000904,
371 .dmc_ddrcfg = 0x00000422,
372 .dmc_ddrtr0 = 0x20A07323,
373 .dmc_ddrtr1 = 0x20160492,
374 .dmc_ddrtr2 = 0x00320209,
375 .dmc_ddrmr = 0x00000632,
376 .dmc_ddrmr1 = 0x4,
377 },
378 [3] = {
379 .ddr_clk = 166,
380 .dmc_ddrctl = 0x00000904,
381 .dmc_ddrcfg = 0x00000422,
382 .dmc_ddrtr0 = 0x20A07323,
383 .dmc_ddrtr1 = 0x2016050E,
384 .dmc_ddrtr2 = 0x00320209,
385 .dmc_ddrmr = 0x00000632,
386 .dmc_ddrmr1 = 0x4,
387 },
388 [4] = {
389 .ddr_clk = 200,
390 .dmc_ddrctl = 0x00000904,
391 .dmc_ddrcfg = 0x00000422,
392 .dmc_ddrtr0 = 0x20a07323,
393 .dmc_ddrtr1 = 0x2016050f,
394 .dmc_ddrtr2 = 0x00320509,
395 .dmc_ddrmr = 0x00000632,
396 .dmc_ddrmr1 = 0x4,
397 },
398 [5] = {
399 .ddr_clk = 225,
400 .dmc_ddrctl = 0x00000904,
401 .dmc_ddrcfg = 0x00000422,
402 .dmc_ddrtr0 = 0x20E0A424,
403 .dmc_ddrtr1 = 0x302006DB,
404 .dmc_ddrtr2 = 0x0032020D,
405 .dmc_ddrmr = 0x00000842,
406 .dmc_ddrmr1 = 0x4,
407 },
408 [6] = {
409 .ddr_clk = 250,
410 .dmc_ddrctl = 0x00000904,
411 .dmc_ddrcfg = 0x00000422,
412 .dmc_ddrtr0 = 0x20E0A424,
413 .dmc_ddrtr1 = 0x3020079E,
414 .dmc_ddrtr2 = 0x0032020D,
415 .dmc_ddrmr = 0x00000842,
416 .dmc_ddrmr1 = 0x4,
417 },
418};
419#endif
420
421static inline void dmc_enter_self_refresh(void)
422{
423 if (bfin_read_DMC0_STAT() & MEMINITDONE) {
424 bfin_write_DMC0_CTL(bfin_read_DMC0_CTL() | SRREQ);
425 while (!(bfin_read_DMC0_STAT() & SRACK))
426 continue;
427 }
428}
429
430static inline void dmc_exit_self_refresh(void)
431{
432 if (bfin_read_DMC0_STAT() & MEMINITDONE) {
433 bfin_write_DMC0_CTL(bfin_read_DMC0_CTL() & ~SRREQ);
434 while (bfin_read_DMC0_STAT() & SRACK)
435 continue;
436 }
437}
438
439static inline void init_cgu(u32 cgu_div, u32 cgu_ctl)
440{
441 dmc_enter_self_refresh();
442
443 /* Don't set the same value of MSEL and DF to CGU_CTL */
444 if ((bfin_read32(CGU0_CTL) & (MSEL_MASK | DF_MASK))
445 != cgu_ctl) {
446 bfin_write32(CGU0_DIV, cgu_div);
447 bfin_write32(CGU0_CTL, cgu_ctl);
448 while ((bfin_read32(CGU0_STAT) & (CLKSALGN | PLLBP)) ||
449 !(bfin_read32(CGU0_STAT) & PLOCK))
450 continue;
451 }
452
453 bfin_write32(CGU0_DIV, cgu_div | UPDT);
454 while (bfin_read32(CGU0_STAT) & CLKSALGN)
455 continue;
456
457 dmc_exit_self_refresh();
458}
459
460static inline void init_dmc(u32 dmc_clk)
461{
462 int i, dlldatacycle, dll_ctl;
463
464 for (i = 0; i < 7; i++) {
465 if (ddr_config_table[i].ddr_clk == dmc_clk) {
466 bfin_write_DMC0_CFG(ddr_config_table[i].dmc_ddrcfg);
467 bfin_write_DMC0_TR0(ddr_config_table[i].dmc_ddrtr0);
468 bfin_write_DMC0_TR1(ddr_config_table[i].dmc_ddrtr1);
469 bfin_write_DMC0_TR2(ddr_config_table[i].dmc_ddrtr2);
470 bfin_write_DMC0_MR(ddr_config_table[i].dmc_ddrmr);
471 bfin_write_DMC0_EMR1(ddr_config_table[i].dmc_ddrmr1);
472 bfin_write_DMC0_CTL(ddr_config_table[i].dmc_ddrctl);
473 break;
474 }
475 }
476
477 while (!(bfin_read_DMC0_STAT() & MEMINITDONE))
478 continue;
479
480 dlldatacycle = (bfin_read_DMC0_STAT() & PHYRDPHASE) >> PHYRDPHASE_OFFSET;
481 dll_ctl = bfin_read_DMC0_DLLCTL();
482 dll_ctl &= ~DATACYC;
483 bfin_write_DMC0_DLLCTL(dll_ctl | (dlldatacycle << DATACYC_OFFSET));
484
485 while (!(bfin_read_DMC0_STAT() & DLLCALDONE))
486 continue;
487}
488#endif
489
490#endif /*__MEM_INIT_H__*/
491
diff --git a/arch/blackfin/mach-bf609/include/mach/defBF60x_base.h b/arch/blackfin/mach-bf609/include/mach/defBF60x_base.h
index 6aac38544cc9..f1a6afae1a71 100644
--- a/arch/blackfin/mach-bf609/include/mach/defBF60x_base.h
+++ b/arch/blackfin/mach-bf609/include/mach/defBF60x_base.h
@@ -2665,7 +2665,6 @@
2665#define DEVSZ_1G 0x400 /* DMC External Bank Size = 1Gbit */ 2665#define DEVSZ_1G 0x400 /* DMC External Bank Size = 1Gbit */
2666#define DEVSZ_2G 0x500 /* DMC External Bank Size = 2Gbit */ 2666#define DEVSZ_2G 0x500 /* DMC External Bank Size = 2Gbit */
2667 2667
2668
2669/* ========================= 2668/* =========================
2670 L2CTL Registers 2669 L2CTL Registers
2671 ========================= */ 2670 ========================= */
diff --git a/arch/blackfin/mach-common/clocks-init.c b/arch/blackfin/mach-common/clocks-init.c
index 7ad2407d1571..2308ce52f849 100644
--- a/arch/blackfin/mach-common/clocks-init.c
+++ b/arch/blackfin/mach-common/clocks-init.c
@@ -16,23 +16,14 @@
16#include <asm/dpmc.h> 16#include <asm/dpmc.h>
17 17
18#ifdef CONFIG_BF60x 18#ifdef CONFIG_BF60x
19#define CSEL_P 0
20#define S0SEL_P 5
21#define SYSSEL_P 8
22#define S1SEL_P 13
23#define DSEL_P 16
24#define OSEL_P 22
25#define ALGN_P 29
26#define UPDT_P 30
27#define LOCK_P 31
28 19
29#define CGU_CTL_VAL ((CONFIG_VCO_MULT << 8) | CLKIN_HALF) 20#define CGU_CTL_VAL ((CONFIG_VCO_MULT << 8) | CLKIN_HALF)
30#define CGU_DIV_VAL \ 21#define CGU_DIV_VAL \
31 ((CONFIG_CCLK_DIV << CSEL_P) | \ 22 ((CONFIG_CCLK_DIV << CSEL_OFFSET) | \
32 (CONFIG_SCLK_DIV << SYSSEL_P) | \ 23 (CONFIG_SCLK_DIV << SYSSEL_OFFSET) | \
33 (CONFIG_SCLK0_DIV << S0SEL_P) | \ 24 (CONFIG_SCLK0_DIV << S0SEL_OFFSET) | \
34 (CONFIG_SCLK1_DIV << S1SEL_P) | \ 25 (CONFIG_SCLK1_DIV << S1SEL_OFFSET) | \
35 (CONFIG_DCLK_DIV << DSEL_P)) 26 (CONFIG_DCLK_DIV << DSEL_OFFSET))
36 27
37#define CONFIG_BFIN_DCLK (((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT) / CONFIG_DCLK_DIV) / 1000000) 28#define CONFIG_BFIN_DCLK (((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT) / CONFIG_DCLK_DIV) / 1000000)
38#if ((CONFIG_BFIN_DCLK != 125) && \ 29#if ((CONFIG_BFIN_DCLK != 125) && \
@@ -41,89 +32,7 @@
41 (CONFIG_BFIN_DCLK != 225) && (CONFIG_BFIN_DCLK != 250)) 32 (CONFIG_BFIN_DCLK != 225) && (CONFIG_BFIN_DCLK != 250))
42#error "DCLK must be in (125, 133, 150, 166, 200, 225, 250)MHz" 33#error "DCLK must be in (125, 133, 150, 166, 200, 225, 250)MHz"
43#endif 34#endif
44struct ddr_config {
45 u32 ddr_clk;
46 u32 dmc_ddrctl;
47 u32 dmc_ddrcfg;
48 u32 dmc_ddrtr0;
49 u32 dmc_ddrtr1;
50 u32 dmc_ddrtr2;
51 u32 dmc_ddrmr;
52 u32 dmc_ddrmr1;
53};
54 35
55struct ddr_config ddr_config_table[] __attribute__((section(".data_l1"))) = {
56 [0] = {
57 .ddr_clk = 125,
58 .dmc_ddrctl = 0x00000904,
59 .dmc_ddrcfg = 0x00000422,
60 .dmc_ddrtr0 = 0x20705212,
61 .dmc_ddrtr1 = 0x201003CF,
62 .dmc_ddrtr2 = 0x00320107,
63 .dmc_ddrmr = 0x00000422,
64 .dmc_ddrmr1 = 0x4,
65 },
66 [1] = {
67 .ddr_clk = 133,
68 .dmc_ddrctl = 0x00000904,
69 .dmc_ddrcfg = 0x00000422,
70 .dmc_ddrtr0 = 0x20806313,
71 .dmc_ddrtr1 = 0x2013040D,
72 .dmc_ddrtr2 = 0x00320108,
73 .dmc_ddrmr = 0x00000632,
74 .dmc_ddrmr1 = 0x4,
75 },
76 [2] = {
77 .ddr_clk = 150,
78 .dmc_ddrctl = 0x00000904,
79 .dmc_ddrcfg = 0x00000422,
80 .dmc_ddrtr0 = 0x20A07323,
81 .dmc_ddrtr1 = 0x20160492,
82 .dmc_ddrtr2 = 0x00320209,
83 .dmc_ddrmr = 0x00000632,
84 .dmc_ddrmr1 = 0x4,
85 },
86 [3] = {
87 .ddr_clk = 166,
88 .dmc_ddrctl = 0x00000904,
89 .dmc_ddrcfg = 0x00000422,
90 .dmc_ddrtr0 = 0x20A07323,
91 .dmc_ddrtr1 = 0x2016050E,
92 .dmc_ddrtr2 = 0x00320209,
93 .dmc_ddrmr = 0x00000632,
94 .dmc_ddrmr1 = 0x4,
95 },
96 [4] = {
97 .ddr_clk = 200,
98 .dmc_ddrctl = 0x00000904,
99 .dmc_ddrcfg = 0x00000422,
100 .dmc_ddrtr0 = 0x20a07323,
101 .dmc_ddrtr1 = 0x2016050f,
102 .dmc_ddrtr2 = 0x00320509,
103 .dmc_ddrmr = 0x00000632,
104 .dmc_ddrmr1 = 0x4,
105 },
106 [5] = {
107 .ddr_clk = 225,
108 .dmc_ddrctl = 0x00000904,
109 .dmc_ddrcfg = 0x00000422,
110 .dmc_ddrtr0 = 0x20E0A424,
111 .dmc_ddrtr1 = 0x302006DB,
112 .dmc_ddrtr2 = 0x0032020D,
113 .dmc_ddrmr = 0x00000842,
114 .dmc_ddrmr1 = 0x4,
115 },
116 [6] = {
117 .ddr_clk = 250,
118 .dmc_ddrctl = 0x00000904,
119 .dmc_ddrcfg = 0x00000422,
120 .dmc_ddrtr0 = 0x20E0A424,
121 .dmc_ddrtr1 = 0x3020079E,
122 .dmc_ddrtr2 = 0x0032020D,
123 .dmc_ddrmr = 0x00000842,
124 .dmc_ddrmr1 = 0x4,
125 },
126};
127#else 36#else
128#define SDGCTL_WIDTH (1 << 31) /* SDRAM external data path width */ 37#define SDGCTL_WIDTH (1 << 31) /* SDRAM external data path width */
129#define PLL_CTL_VAL \ 38#define PLL_CTL_VAL \
@@ -144,43 +53,9 @@ void init_clocks(void)
144 * in the middle of reprogramming things, and that'll screw us up. 53 * in the middle of reprogramming things, and that'll screw us up.
145 * For example, any automatic DMAs left by U-Boot for splash screens. 54 * For example, any automatic DMAs left by U-Boot for splash screens.
146 */ 55 */
147
148#ifdef CONFIG_BF60x 56#ifdef CONFIG_BF60x
149 int i, dlldatacycle, dll_ctl; 57 init_cgu(CGU_DIV_VAL, CGU_CTL_VAL);
150 bfin_write32(CGU0_DIV, CGU_DIV_VAL); 58 init_dmc(CONFIG_BFIN_DCLK);
151 bfin_write32(CGU0_CTL, CGU_CTL_VAL);
152 while ((bfin_read32(CGU0_STAT) & 0x8) || !(bfin_read32(CGU0_STAT) & 0x4))
153 continue;
154
155 bfin_write32(CGU0_DIV, CGU_DIV_VAL | (1 << UPDT_P));
156 while (bfin_read32(CGU0_STAT) & (1 << 3))
157 continue;
158
159 for (i = 0; i < 7; i++) {
160 if (ddr_config_table[i].ddr_clk == CONFIG_BFIN_DCLK) {
161 bfin_write_DDR0_CFG(ddr_config_table[i].dmc_ddrcfg);
162 bfin_write_DDR0_TR0(ddr_config_table[i].dmc_ddrtr0);
163 bfin_write_DDR0_TR1(ddr_config_table[i].dmc_ddrtr1);
164 bfin_write_DDR0_TR2(ddr_config_table[i].dmc_ddrtr2);
165 bfin_write_DDR0_MR(ddr_config_table[i].dmc_ddrmr);
166 bfin_write_DDR0_EMR1(ddr_config_table[i].dmc_ddrmr1);
167 bfin_write_DDR0_CTL(ddr_config_table[i].dmc_ddrctl);
168 break;
169 }
170 }
171
172 do_sync();
173 while (!(bfin_read_DDR0_STAT() & 0x4))
174 continue;
175
176 dlldatacycle = (bfin_read_DDR0_STAT() & 0x00f00000) >> 20;
177 dll_ctl = bfin_read_DDR0_DLLCTL();
178 dll_ctl &= 0x0ff;
179 bfin_write_DDR0_DLLCTL(dll_ctl | (dlldatacycle << 8));
180
181 do_sync();
182 while (!(bfin_read_DDR0_STAT() & 0x2000))
183 continue;
184#else 59#else
185 size_t i; 60 size_t i;
186 for (i = 0; i < MAX_DMA_CHANNELS; ++i) { 61 for (i = 0; i < MAX_DMA_CHANNELS; ++i) {