1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/kernel.h>
21#include <linux/param.h>
22#include <linux/init.h>
23#include <linux/io.h>
24#include <asm/machdep.h>
25#include <asm/coldfire.h>
26#include <asm/mcfsim.h>
27#include <asm/mcfuart.h>
28#include <asm/mcfdma.h>
29#include <asm/mcfwdebug.h>
30#include <asm/mcfclk.h>
31
32
33
34DEFINE_CLK(0, "flexbus", 2, MCF_CLK);
35DEFINE_CLK(0, "mcfcan.0", 8, MCF_CLK);
36DEFINE_CLK(0, "fec.0", 12, MCF_CLK);
37DEFINE_CLK(0, "edma", 17, MCF_CLK);
38DEFINE_CLK(0, "intc.0", 18, MCF_CLK);
39DEFINE_CLK(0, "intc.1", 19, MCF_CLK);
40DEFINE_CLK(0, "iack.0", 21, MCF_CLK);
41DEFINE_CLK(0, "imx1-i2c.0", 22, MCF_CLK);
42DEFINE_CLK(0, "mcfqspi.0", 23, MCF_CLK);
43DEFINE_CLK(0, "mcfuart.0", 24, MCF_BUSCLK);
44DEFINE_CLK(0, "mcfuart.1", 25, MCF_BUSCLK);
45DEFINE_CLK(0, "mcfuart.2", 26, MCF_BUSCLK);
46DEFINE_CLK(0, "mcftmr.0", 28, MCF_CLK);
47DEFINE_CLK(0, "mcftmr.1", 29, MCF_CLK);
48DEFINE_CLK(0, "mcftmr.2", 30, MCF_CLK);
49DEFINE_CLK(0, "mcftmr.3", 31, MCF_CLK);
50
51DEFINE_CLK(0, "mcfpit.0", 32, MCF_CLK);
52DEFINE_CLK(0, "mcfpit.1", 33, MCF_CLK);
53DEFINE_CLK(0, "mcfpit.2", 34, MCF_CLK);
54DEFINE_CLK(0, "mcfpit.3", 35, MCF_CLK);
55DEFINE_CLK(0, "mcfpwm.0", 36, MCF_CLK);
56DEFINE_CLK(0, "mcfeport.0", 37, MCF_CLK);
57DEFINE_CLK(0, "mcfwdt.0", 38, MCF_CLK);
58DEFINE_CLK(0, "sys.0", 40, MCF_BUSCLK);
59DEFINE_CLK(0, "gpio.0", 41, MCF_BUSCLK);
60DEFINE_CLK(0, "mcfrtc.0", 42, MCF_CLK);
61DEFINE_CLK(0, "mcflcd.0", 43, MCF_CLK);
62DEFINE_CLK(0, "mcfusb-otg.0", 44, MCF_CLK);
63DEFINE_CLK(0, "mcfusb-host.0", 45, MCF_CLK);
64DEFINE_CLK(0, "sdram.0", 46, MCF_CLK);
65DEFINE_CLK(0, "ssi.0", 47, MCF_CLK);
66DEFINE_CLK(0, "pll.0", 48, MCF_CLK);
67
68DEFINE_CLK(1, "mdha.0", 32, MCF_CLK);
69DEFINE_CLK(1, "skha.0", 33, MCF_CLK);
70DEFINE_CLK(1, "rng.0", 34, MCF_CLK);
71
72struct clk *mcf_clks[] = {
73 &__clk_0_2,
74 &__clk_0_8,
75 &__clk_0_12,
76 &__clk_0_17,
77 &__clk_0_18,
78 &__clk_0_19,
79 &__clk_0_21,
80 &__clk_0_22,
81 &__clk_0_23,
82 &__clk_0_24,
83 &__clk_0_25,
84 &__clk_0_26,
85 &__clk_0_28,
86 &__clk_0_29,
87 &__clk_0_30,
88 &__clk_0_31,
89
90 &__clk_0_32,
91 &__clk_0_33,
92 &__clk_0_34,
93 &__clk_0_35,
94 &__clk_0_36,
95 &__clk_0_37,
96 &__clk_0_38,
97 &__clk_0_40,
98 &__clk_0_41,
99 &__clk_0_42,
100 &__clk_0_43,
101 &__clk_0_44,
102 &__clk_0_45,
103 &__clk_0_46,
104 &__clk_0_47,
105 &__clk_0_48,
106
107 &__clk_1_32,
108 &__clk_1_33,
109 &__clk_1_34,
110 NULL,
111};
112
113static struct clk * const enable_clks[] __initconst = {
114 &__clk_0_2,
115 &__clk_0_18,
116 &__clk_0_19,
117 &__clk_0_21,
118 &__clk_0_24,
119 &__clk_0_25,
120 &__clk_0_26,
121 &__clk_0_28,
122 &__clk_0_29,
123 &__clk_0_32,
124 &__clk_0_33,
125 &__clk_0_37,
126 &__clk_0_40,
127 &__clk_0_41,
128 &__clk_0_46,
129 &__clk_0_48,
130};
131
132static struct clk * const disable_clks[] __initconst = {
133 &__clk_0_8,
134 &__clk_0_12,
135 &__clk_0_17,
136 &__clk_0_22,
137 &__clk_0_23,
138 &__clk_0_30,
139 &__clk_0_31,
140 &__clk_0_34,
141 &__clk_0_35,
142 &__clk_0_36,
143 &__clk_0_38,
144 &__clk_0_42,
145 &__clk_0_43,
146 &__clk_0_44,
147 &__clk_0_45,
148 &__clk_0_47,
149 &__clk_1_32,
150 &__clk_1_33,
151 &__clk_1_34,
152};
153
154
155static void __init m53xx_clk_init(void)
156{
157 unsigned i;
158
159
160 for (i = 0; i < ARRAY_SIZE(enable_clks); ++i)
161 __clk_init_enabled(enable_clks[i]);
162
163 for (i = 0; i < ARRAY_SIZE(disable_clks); ++i)
164 __clk_init_disabled(disable_clks[i]);
165}
166
167
168
169static void __init m53xx_qspi_init(void)
170{
171#if IS_ENABLED(CONFIG_SPI_COLDFIRE_QSPI)
172
173 writew(0x01f0, MCFGPIO_PAR_QSPI);
174#endif
175}
176
177
178
179static void __init m53xx_i2c_init(void)
180{
181#if IS_ENABLED(CONFIG_I2C_IMX)
182
183
184 u8 r = readb(MCFGPIO_PAR_FECI2C);
185 r |= 0x0f;
186 writeb(r, MCFGPIO_PAR_FECI2C);
187#endif
188}
189
190
191
192static void __init m53xx_uarts_init(void)
193{
194
195 writew(readw(MCFGPIO_PAR_UART) | 0x0FFF, MCFGPIO_PAR_UART);
196}
197
198
199
200static void __init m53xx_fec_init(void)
201{
202 u8 v;
203
204
205 v = readb(MCFGPIO_PAR_FECI2C);
206 v |= MCF_GPIO_PAR_FECI2C_PAR_MDC_EMDC |
207 MCF_GPIO_PAR_FECI2C_PAR_MDIO_EMDIO;
208 writeb(v, MCFGPIO_PAR_FECI2C);
209
210 v = readb(MCFGPIO_PAR_FEC);
211 v = MCF_GPIO_PAR_FEC_PAR_FEC_7W_FEC | MCF_GPIO_PAR_FEC_PAR_FEC_MII_FEC;
212 writeb(v, MCFGPIO_PAR_FEC);
213}
214
215
216
217void __init config_BSP(char *commandp, int size)
218{
219#if !defined(CONFIG_BOOTPARAM)
220
221 memcpy(commandp, (char *) 0x4000, 4);
222 if(strncmp(commandp, "kcl ", 4) == 0){
223 memcpy(commandp, (char *) 0x4004, size);
224 commandp[size-1] = 0;
225 } else {
226 memset(commandp, 0, size);
227 }
228#endif
229 mach_sched_init = hw_timer_init;
230 m53xx_clk_init();
231 m53xx_uarts_init();
232 m53xx_fec_init();
233 m53xx_qspi_init();
234 m53xx_i2c_init();
235
236#ifdef CONFIG_BDM_DISABLE
237
238
239
240
241
242 wdebug(MCFDEBUG_CSR, MCFDEBUG_CSR_PSTCLK);
243#endif
244}
245
246
247
248
249
250
251
252#define MAX_FVCO 500000
253#define MAX_FSYS 80000
254#define MIN_FSYS 58333
255#define FREF 16000
256
257
258#define MAX_MFD 135
259#define MIN_MFD 88
260#define BUSDIV 6
261
262
263
264
265#define MIN_LPD (1 << 0)
266#define MAX_LPD (1 << 15)
267#define DEFAULT_LPD (1 << 1)
268
269#define SYS_CLK_KHZ 80000
270#define SYSTEM_PERIOD 12.5
271
272
273
274#define SDRAM_BL 8
275#define SDRAM_TWR 2
276#define SDRAM_CASL 2.5
277#define SDRAM_TRCD 2
278#define SDRAM_TRP 2
279#define SDRAM_TRFC 7
280#define SDRAM_TREFI 7800
281
282#define EXT_SRAM_ADDRESS (0xC0000000)
283#define FLASH_ADDRESS (0x00000000)
284#define SDRAM_ADDRESS (0x40000000)
285
286#define NAND_FLASH_ADDRESS (0xD0000000)
287
288void wtm_init(void);
289void scm_init(void);
290void gpio_init(void);
291void fbcs_init(void);
292void sdramc_init(void);
293int clock_pll (int fsys, int flags);
294int clock_limp (int);
295int clock_exit_limp (void);
296int get_sys_clock (void);
297
298asmlinkage void __init sysinit(void)
299{
300 clock_pll(0, 0);
301
302 wtm_init();
303 scm_init();
304 gpio_init();
305 fbcs_init();
306 sdramc_init();
307}
308
309void wtm_init(void)
310{
311
312 writew(0, MCF_WTM_WCR);
313}
314
315#define MCF_SCM_BCR_GBW (0x00000100)
316#define MCF_SCM_BCR_GBR (0x00000200)
317
318void scm_init(void)
319{
320
321 writel(0x77777777, MCF_SCM_MPR);
322
323
324
325 writel(0, MCF_SCM_PACRA);
326 writel(0, MCF_SCM_PACRB);
327 writel(0, MCF_SCM_PACRC);
328 writel(0, MCF_SCM_PACRD);
329 writel(0, MCF_SCM_PACRE);
330 writel(0, MCF_SCM_PACRF);
331
332
333 writel(MCF_SCM_BCR_GBR | MCF_SCM_BCR_GBW, MCF_SCM_BCR);
334}
335
336
337void fbcs_init(void)
338{
339 writeb(0x3E, MCFGPIO_PAR_CS);
340
341
342 writel(0x10080000, MCF_FBCS1_CSAR);
343
344 writel(0x002A3780, MCF_FBCS1_CSCR);
345 writel(MCF_FBCS_CSMR_BAM_2M | MCF_FBCS_CSMR_V, MCF_FBCS1_CSMR);
346
347
348 writew(0xffff, 0x10080000);
349
350
351 writel(EXT_SRAM_ADDRESS, MCF_FBCS1_CSAR);
352 writel(MCF_FBCS_CSCR_PS_16 |
353 MCF_FBCS_CSCR_AA |
354 MCF_FBCS_CSCR_SBM |
355 MCF_FBCS_CSCR_WS(1),
356 MCF_FBCS1_CSCR);
357 writel(MCF_FBCS_CSMR_BAM_512K | MCF_FBCS_CSMR_V, MCF_FBCS1_CSMR);
358
359
360 writel(FLASH_ADDRESS, MCF_FBCS0_CSAR);
361 writel(MCF_FBCS_CSCR_PS_16 |
362 MCF_FBCS_CSCR_BEM |
363 MCF_FBCS_CSCR_AA |
364 MCF_FBCS_CSCR_SBM |
365 MCF_FBCS_CSCR_WS(7),
366 MCF_FBCS0_CSCR);
367 writel(MCF_FBCS_CSMR_BAM_32M | MCF_FBCS_CSMR_V, MCF_FBCS0_CSMR);
368}
369
370void sdramc_init(void)
371{
372
373
374
375
376 if (!(readl(MCF_SDRAMC_SDCR) & MCF_SDRAMC_SDCR_REF)) {
377
378
379
380 writel(MCF_SDRAMC_SDCS_BA(SDRAM_ADDRESS) |
381 MCF_SDRAMC_SDCS_CSSZ(MCF_SDRAMC_SDCS_CSSZ_32MBYTE),
382 MCF_SDRAMC_SDCS0);
383
384
385
386
387 writel(MCF_SDRAMC_SDCFG1_SRD2RW((int)((SDRAM_CASL + 2) + 0.5)) |
388 MCF_SDRAMC_SDCFG1_SWT2RD(SDRAM_TWR + 1) |
389 MCF_SDRAMC_SDCFG1_RDLAT((int)((SDRAM_CASL * 2) + 2)) |
390 MCF_SDRAMC_SDCFG1_ACT2RW((int)(SDRAM_TRCD + 0.5)) |
391 MCF_SDRAMC_SDCFG1_PRE2ACT((int)(SDRAM_TRP + 0.5)) |
392 MCF_SDRAMC_SDCFG1_REF2ACT((int)(SDRAM_TRFC + 0.5)) |
393 MCF_SDRAMC_SDCFG1_WTLAT(3),
394 MCF_SDRAMC_SDCFG1);
395 writel(MCF_SDRAMC_SDCFG2_BRD2PRE(SDRAM_BL / 2 + 1) |
396 MCF_SDRAMC_SDCFG2_BWT2RW(SDRAM_BL / 2 + SDRAM_TWR) |
397 MCF_SDRAMC_SDCFG2_BRD2WT((int)((SDRAM_CASL + SDRAM_BL / 2 - 1.0) + 0.5)) |
398 MCF_SDRAMC_SDCFG2_BL(SDRAM_BL - 1),
399 MCF_SDRAMC_SDCFG2);
400
401
402
403
404
405 writel(MCF_SDRAMC_SDCR_MODE_EN |
406 MCF_SDRAMC_SDCR_CKE |
407 MCF_SDRAMC_SDCR_DDR |
408 MCF_SDRAMC_SDCR_MUX(1) |
409 MCF_SDRAMC_SDCR_RCNT((int)(((SDRAM_TREFI / (SYSTEM_PERIOD * 64)) - 1) + 0.5)) |
410 MCF_SDRAMC_SDCR_PS_16 |
411 MCF_SDRAMC_SDCR_IPALL,
412 MCF_SDRAMC_SDCR);
413
414
415
416
417 writel(MCF_SDRAMC_SDMR_BNKAD_LEMR |
418 MCF_SDRAMC_SDMR_AD(0x0) |
419 MCF_SDRAMC_SDMR_CMD,
420 MCF_SDRAMC_SDMR);
421
422
423
424
425 writel(MCF_SDRAMC_SDMR_BNKAD_LMR |
426 MCF_SDRAMC_SDMR_AD(0x163) |
427 MCF_SDRAMC_SDMR_CMD,
428 MCF_SDRAMC_SDMR);
429
430
431
432
433 writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_IPALL, MCF_SDRAMC_SDCR);
434
435
436
437
438 writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_IREF, MCF_SDRAMC_SDCR);
439 writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_IREF, MCF_SDRAMC_SDCR);
440
441
442
443
444 writel(MCF_SDRAMC_SDMR_BNKAD_LMR |
445 MCF_SDRAMC_SDMR_AD(0x063) |
446 MCF_SDRAMC_SDMR_CMD,
447 MCF_SDRAMC_SDMR);
448
449
450
451
452 writel(readl(MCF_SDRAMC_SDCR) & ~MCF_SDRAMC_SDCR_MODE_EN,
453 MCF_SDRAMC_SDCR);
454 writel(MCF_SDRAMC_SDCR_REF | MCF_SDRAMC_SDCR_DQS_OE(0xC),
455 MCF_SDRAMC_SDCR);
456 }
457}
458
459void gpio_init(void)
460{
461
462 writew(MCF_GPIO_PAR_UART_PAR_URXD0 | MCF_GPIO_PAR_UART_PAR_UTXD0,
463 MCFGPIO_PAR_UART);
464
465
466
467
468
469 writeb(0x00, MCFGPIO_PAR_TIMER);
470 writeb(0x08, MCFGPIO_PDDR_TIMER);
471 writeb(0x00, MCFGPIO_PCLRR_TIMER);
472}
473
474int clock_pll(int fsys, int flags)
475{
476 int fref, temp, fout, mfd;
477 u32 i;
478
479 fref = FREF;
480
481 if (fsys == 0) {
482
483 mfd = readb(MCF_PLL_PFDR);
484
485 return (fref * mfd / (BUSDIV * 4));
486 }
487
488
489 if (fsys > MAX_FSYS)
490 fsys = MAX_FSYS;
491 if (fsys < MIN_FSYS)
492 fsys = MIN_FSYS;
493
494
495
496
497
498 temp = 100 * fsys / fref;
499 mfd = 4 * BUSDIV * temp / 100;
500
501
502 fout = (fref * mfd / (BUSDIV * 4));
503
504
505
506
507
508
509 if (readl(MCF_SDRAMC_SDCR) & MCF_SDRAMC_SDCR_REF)
510
511 writel(readl(MCF_SDRAMC_SDCR) & ~MCF_SDRAMC_SDCR_CKE,
512 MCF_SDRAMC_SDCR);
513
514
515
516
517
518
519
520 clock_limp(DEFAULT_LPD);
521
522
523 writeb(MCF_PLL_PODR_CPUDIV(BUSDIV/3) | MCF_PLL_PODR_BUSDIV(BUSDIV),
524 MCF_PLL_PODR);
525
526 writeb(mfd, MCF_PLL_PFDR);
527
528
529 clock_exit_limp();
530
531
532
533
534 if (readl(MCF_SDRAMC_SDCR) & MCF_SDRAMC_SDCR_REF)
535
536 writel(readl(MCF_SDRAMC_SDCR) | MCF_SDRAMC_SDCR_CKE,
537 MCF_SDRAMC_SDCR);
538
539
540 writel(MCF_SDRAMC_REFRESH, MCF_SDRAMC_LIMP_FIX);
541
542
543 for (i = 0; i < 0x200; i++)
544 ;
545
546 return fout;
547}
548
549int clock_limp(int div)
550{
551 u32 temp;
552
553
554 if (div < MIN_LPD)
555 div = MIN_LPD;
556 if (div > MAX_LPD)
557 div = MAX_LPD;
558
559
560
561 temp = readw(MCF_CCM_CDR) & MCF_CCM_CDR_SSIDIV(0xF);
562
563
564 writew(MCF_CCM_CDR_LPDIV(div) | MCF_CCM_CDR_SSIDIV(temp), MCF_CCM_CDR);
565
566 writew(readw(MCF_CCM_MISCCR) | MCF_CCM_MISCCR_LIMP, MCF_CCM_MISCCR);
567
568 return (FREF/(3*(1 << div)));
569}
570
571int clock_exit_limp(void)
572{
573 int fout;
574
575
576 writew(readw(MCF_CCM_MISCCR) & ~MCF_CCM_MISCCR_LIMP, MCF_CCM_MISCCR);
577
578
579 while (!(readw(MCF_CCM_MISCCR) & MCF_CCM_MISCCR_PLL_LOCK))
580 ;
581
582 fout = get_sys_clock();
583
584 return fout;
585}
586
587int get_sys_clock(void)
588{
589 int divider;
590
591
592 if (readw(MCF_CCM_MISCCR) & MCF_CCM_MISCCR_LIMP) {
593 divider = readw(MCF_CCM_CDR) & MCF_CCM_CDR_LPDIV(0xF);
594 return (FREF/(2 << divider));
595 }
596 else
597 return (FREF * readb(MCF_PLL_PFDR)) / (BUSDIV * 4);
598}
599