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