making the kernel build with up to date compilers again, see https://bbs.archlinux...
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / arch / arm / mach-mv78xx0 / common.c
blobb0e4e0d8f506af23f6abd53f2a6ab47d07e19daf
1 /*
2 * arch/arm/mach-mv78xx0/common.c
4 * Core functions for Marvell MV78xx0 SoCs
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/serial_8250.h>
15 #include <linux/mbus.h>
16 #include <linux/mv643xx_eth.h>
17 #include <linux/ata_platform.h>
18 #include <asm/mach/map.h>
19 #include <asm/mach/time.h>
20 #include <mach/mv78xx0.h>
21 #include <plat/cache-feroceon-l2.h>
22 #include <plat/ehci-orion.h>
23 #include <plat/orion_nand.h>
24 #include <plat/time.h>
25 #include "common.h"
28 /*****************************************************************************
29 * Common bits
30 ****************************************************************************/
31 int mv78xx0_core_index(void)
33 u32 extra;
36 * Read Extra Features register.
38 __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (extra));
40 return !!(extra & 0x00004000);
43 static int get_hclk(void)
45 int hclk;
48 * HCLK tick rate is configured by DEV_D[7:5] pins.
50 switch ((readl(SAMPLE_AT_RESET_LOW) >> 5) & 7) {
51 case 0:
52 hclk = 166666667;
53 break;
54 case 1:
55 hclk = 200000000;
56 break;
57 case 2:
58 hclk = 266666667;
59 break;
60 case 3:
61 hclk = 333333333;
62 break;
63 case 4:
64 hclk = 400000000;
65 break;
66 default:
67 panic("unknown HCLK PLL setting: %.8x\n",
68 readl(SAMPLE_AT_RESET_LOW));
71 return hclk;
74 static void get_pclk_l2clk(int hclk, int core_index, int *pclk, int *l2clk)
76 u32 cfg;
79 * Core #0 PCLK/L2CLK is configured by bits [13:8], core #1
80 * PCLK/L2CLK by bits [19:14].
82 if (core_index == 0) {
83 cfg = (readl(SAMPLE_AT_RESET_LOW) >> 8) & 0x3f;
84 } else {
85 cfg = (readl(SAMPLE_AT_RESET_LOW) >> 14) & 0x3f;
89 * Bits [11:8] ([17:14] for core #1) configure the PCLK:HCLK
90 * ratio (1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6).
92 *pclk = ((u64)hclk * (2 + (cfg & 0xf))) >> 1;
95 * Bits [13:12] ([19:18] for core #1) configure the PCLK:L2CLK
96 * ratio (1, 2, 3).
98 *l2clk = *pclk / (((cfg >> 4) & 3) + 1);
101 static int get_tclk(void)
103 int tclk;
106 * TCLK tick rate is configured by DEV_A[2:0] strap pins.
108 switch ((readl(SAMPLE_AT_RESET_HIGH) >> 6) & 7) {
109 case 1:
110 tclk = 166666667;
111 break;
112 case 3:
113 tclk = 200000000;
114 break;
115 default:
116 panic("unknown TCLK PLL setting: %.8x\n",
117 readl(SAMPLE_AT_RESET_HIGH));
120 return tclk;
124 /*****************************************************************************
125 * I/O Address Mapping
126 ****************************************************************************/
127 static struct map_desc mv78xx0_io_desc[] __initdata = {
129 .virtual = MV78XX0_CORE_REGS_VIRT_BASE,
130 .pfn = 0,
131 .length = MV78XX0_CORE_REGS_SIZE,
132 .type = MT_DEVICE,
133 }, {
134 .virtual = MV78XX0_PCIE_IO_VIRT_BASE(0),
135 .pfn = __phys_to_pfn(MV78XX0_PCIE_IO_PHYS_BASE(0)),
136 .length = MV78XX0_PCIE_IO_SIZE * 8,
137 .type = MT_DEVICE,
138 }, {
139 .virtual = MV78XX0_REGS_VIRT_BASE,
140 .pfn = __phys_to_pfn(MV78XX0_REGS_PHYS_BASE),
141 .length = MV78XX0_REGS_SIZE,
142 .type = MT_DEVICE,
146 void __init mv78xx0_map_io(void)
148 unsigned long phys;
151 * Map the right set of per-core registers depending on
152 * which core we are running on.
154 if (mv78xx0_core_index() == 0) {
155 phys = MV78XX0_CORE0_REGS_PHYS_BASE;
156 } else {
157 phys = MV78XX0_CORE1_REGS_PHYS_BASE;
159 mv78xx0_io_desc[0].pfn = __phys_to_pfn(phys);
161 iotable_init(mv78xx0_io_desc, ARRAY_SIZE(mv78xx0_io_desc));
165 /*****************************************************************************
166 * EHCI
167 ****************************************************************************/
168 static struct orion_ehci_data mv78xx0_ehci_data = {
169 .dram = &mv78xx0_mbus_dram_info,
170 .phy_version = EHCI_PHY_NA,
173 static u64 ehci_dmamask = 0xffffffffUL;
176 /*****************************************************************************
177 * EHCI0
178 ****************************************************************************/
179 static struct resource mv78xx0_ehci0_resources[] = {
181 .start = USB0_PHYS_BASE,
182 .end = USB0_PHYS_BASE + 0x0fff,
183 .flags = IORESOURCE_MEM,
184 }, {
185 .start = IRQ_MV78XX0_USB_0,
186 .end = IRQ_MV78XX0_USB_0,
187 .flags = IORESOURCE_IRQ,
191 static struct platform_device mv78xx0_ehci0 = {
192 .name = "orion-ehci",
193 .id = 0,
194 .dev = {
195 .dma_mask = &ehci_dmamask,
196 .coherent_dma_mask = 0xffffffff,
197 .platform_data = &mv78xx0_ehci_data,
199 .resource = mv78xx0_ehci0_resources,
200 .num_resources = ARRAY_SIZE(mv78xx0_ehci0_resources),
203 void __init mv78xx0_ehci0_init(void)
205 platform_device_register(&mv78xx0_ehci0);
209 /*****************************************************************************
210 * EHCI1
211 ****************************************************************************/
212 static struct resource mv78xx0_ehci1_resources[] = {
214 .start = USB1_PHYS_BASE,
215 .end = USB1_PHYS_BASE + 0x0fff,
216 .flags = IORESOURCE_MEM,
217 }, {
218 .start = IRQ_MV78XX0_USB_1,
219 .end = IRQ_MV78XX0_USB_1,
220 .flags = IORESOURCE_IRQ,
224 static struct platform_device mv78xx0_ehci1 = {
225 .name = "orion-ehci",
226 .id = 1,
227 .dev = {
228 .dma_mask = &ehci_dmamask,
229 .coherent_dma_mask = 0xffffffff,
230 .platform_data = &mv78xx0_ehci_data,
232 .resource = mv78xx0_ehci1_resources,
233 .num_resources = ARRAY_SIZE(mv78xx0_ehci1_resources),
236 void __init mv78xx0_ehci1_init(void)
238 platform_device_register(&mv78xx0_ehci1);
242 /*****************************************************************************
243 * EHCI2
244 ****************************************************************************/
245 static struct resource mv78xx0_ehci2_resources[] = {
247 .start = USB2_PHYS_BASE,
248 .end = USB2_PHYS_BASE + 0x0fff,
249 .flags = IORESOURCE_MEM,
250 }, {
251 .start = IRQ_MV78XX0_USB_2,
252 .end = IRQ_MV78XX0_USB_2,
253 .flags = IORESOURCE_IRQ,
257 static struct platform_device mv78xx0_ehci2 = {
258 .name = "orion-ehci",
259 .id = 2,
260 .dev = {
261 .dma_mask = &ehci_dmamask,
262 .coherent_dma_mask = 0xffffffff,
263 .platform_data = &mv78xx0_ehci_data,
265 .resource = mv78xx0_ehci2_resources,
266 .num_resources = ARRAY_SIZE(mv78xx0_ehci2_resources),
269 void __init mv78xx0_ehci2_init(void)
271 platform_device_register(&mv78xx0_ehci2);
275 /*****************************************************************************
276 * GE00
277 ****************************************************************************/
278 struct mv643xx_eth_shared_platform_data mv78xx0_ge00_shared_data = {
279 .t_clk = 0,
280 .dram = &mv78xx0_mbus_dram_info,
283 static struct resource mv78xx0_ge00_shared_resources[] = {
285 .name = "ge00 base",
286 .start = GE00_PHYS_BASE + 0x2000,
287 .end = GE00_PHYS_BASE + 0x3fff,
288 .flags = IORESOURCE_MEM,
289 }, {
290 .name = "ge err irq",
291 .start = IRQ_MV78XX0_GE_ERR,
292 .end = IRQ_MV78XX0_GE_ERR,
293 .flags = IORESOURCE_IRQ,
297 static struct platform_device mv78xx0_ge00_shared = {
298 .name = MV643XX_ETH_SHARED_NAME,
299 .id = 0,
300 .dev = {
301 .platform_data = &mv78xx0_ge00_shared_data,
303 .num_resources = ARRAY_SIZE(mv78xx0_ge00_shared_resources),
304 .resource = mv78xx0_ge00_shared_resources,
307 static struct resource mv78xx0_ge00_resources[] = {
309 .name = "ge00 irq",
310 .start = IRQ_MV78XX0_GE00_SUM,
311 .end = IRQ_MV78XX0_GE00_SUM,
312 .flags = IORESOURCE_IRQ,
316 static struct platform_device mv78xx0_ge00 = {
317 .name = MV643XX_ETH_NAME,
318 .id = 0,
319 .num_resources = 1,
320 .resource = mv78xx0_ge00_resources,
323 void __init mv78xx0_ge00_init(struct mv643xx_eth_platform_data *eth_data)
325 eth_data->shared = &mv78xx0_ge00_shared;
326 mv78xx0_ge00.dev.platform_data = eth_data;
328 platform_device_register(&mv78xx0_ge00_shared);
329 platform_device_register(&mv78xx0_ge00);
333 /*****************************************************************************
334 * GE01
335 ****************************************************************************/
336 struct mv643xx_eth_shared_platform_data mv78xx0_ge01_shared_data = {
337 .t_clk = 0,
338 .dram = &mv78xx0_mbus_dram_info,
339 .shared_smi = &mv78xx0_ge00_shared,
342 static struct resource mv78xx0_ge01_shared_resources[] = {
344 .name = "ge01 base",
345 .start = GE01_PHYS_BASE + 0x2000,
346 .end = GE01_PHYS_BASE + 0x3fff,
347 .flags = IORESOURCE_MEM,
351 static struct platform_device mv78xx0_ge01_shared = {
352 .name = MV643XX_ETH_SHARED_NAME,
353 .id = 1,
354 .dev = {
355 .platform_data = &mv78xx0_ge01_shared_data,
357 .num_resources = 1,
358 .resource = mv78xx0_ge01_shared_resources,
361 static struct resource mv78xx0_ge01_resources[] = {
363 .name = "ge01 irq",
364 .start = IRQ_MV78XX0_GE01_SUM,
365 .end = IRQ_MV78XX0_GE01_SUM,
366 .flags = IORESOURCE_IRQ,
370 static struct platform_device mv78xx0_ge01 = {
371 .name = MV643XX_ETH_NAME,
372 .id = 1,
373 .num_resources = 1,
374 .resource = mv78xx0_ge01_resources,
377 void __init mv78xx0_ge01_init(struct mv643xx_eth_platform_data *eth_data)
379 eth_data->shared = &mv78xx0_ge01_shared;
380 mv78xx0_ge01.dev.platform_data = eth_data;
382 platform_device_register(&mv78xx0_ge01_shared);
383 platform_device_register(&mv78xx0_ge01);
387 /*****************************************************************************
388 * GE10
389 ****************************************************************************/
390 struct mv643xx_eth_shared_platform_data mv78xx0_ge10_shared_data = {
391 .t_clk = 0,
392 .dram = &mv78xx0_mbus_dram_info,
393 .shared_smi = &mv78xx0_ge00_shared,
396 static struct resource mv78xx0_ge10_shared_resources[] = {
398 .name = "ge10 base",
399 .start = GE10_PHYS_BASE + 0x2000,
400 .end = GE10_PHYS_BASE + 0x3fff,
401 .flags = IORESOURCE_MEM,
405 static struct platform_device mv78xx0_ge10_shared = {
406 .name = MV643XX_ETH_SHARED_NAME,
407 .id = 2,
408 .dev = {
409 .platform_data = &mv78xx0_ge10_shared_data,
411 .num_resources = 1,
412 .resource = mv78xx0_ge10_shared_resources,
415 static struct resource mv78xx0_ge10_resources[] = {
417 .name = "ge10 irq",
418 .start = IRQ_MV78XX0_GE10_SUM,
419 .end = IRQ_MV78XX0_GE10_SUM,
420 .flags = IORESOURCE_IRQ,
424 static struct platform_device mv78xx0_ge10 = {
425 .name = MV643XX_ETH_NAME,
426 .id = 2,
427 .num_resources = 1,
428 .resource = mv78xx0_ge10_resources,
431 void __init mv78xx0_ge10_init(struct mv643xx_eth_platform_data *eth_data)
433 eth_data->shared = &mv78xx0_ge10_shared;
434 mv78xx0_ge10.dev.platform_data = eth_data;
436 platform_device_register(&mv78xx0_ge10_shared);
437 platform_device_register(&mv78xx0_ge10);
441 /*****************************************************************************
442 * GE11
443 ****************************************************************************/
444 struct mv643xx_eth_shared_platform_data mv78xx0_ge11_shared_data = {
445 .t_clk = 0,
446 .dram = &mv78xx0_mbus_dram_info,
447 .shared_smi = &mv78xx0_ge00_shared,
450 static struct resource mv78xx0_ge11_shared_resources[] = {
452 .name = "ge11 base",
453 .start = GE11_PHYS_BASE + 0x2000,
454 .end = GE11_PHYS_BASE + 0x3fff,
455 .flags = IORESOURCE_MEM,
459 static struct platform_device mv78xx0_ge11_shared = {
460 .name = MV643XX_ETH_SHARED_NAME,
461 .id = 3,
462 .dev = {
463 .platform_data = &mv78xx0_ge11_shared_data,
465 .num_resources = 1,
466 .resource = mv78xx0_ge11_shared_resources,
469 static struct resource mv78xx0_ge11_resources[] = {
471 .name = "ge11 irq",
472 .start = IRQ_MV78XX0_GE11_SUM,
473 .end = IRQ_MV78XX0_GE11_SUM,
474 .flags = IORESOURCE_IRQ,
478 static struct platform_device mv78xx0_ge11 = {
479 .name = MV643XX_ETH_NAME,
480 .id = 3,
481 .num_resources = 1,
482 .resource = mv78xx0_ge11_resources,
485 void __init mv78xx0_ge11_init(struct mv643xx_eth_platform_data *eth_data)
487 eth_data->shared = &mv78xx0_ge11_shared;
488 mv78xx0_ge11.dev.platform_data = eth_data;
490 platform_device_register(&mv78xx0_ge11_shared);
491 platform_device_register(&mv78xx0_ge11);
495 /*****************************************************************************
496 * SATA
497 ****************************************************************************/
498 static struct resource mv78xx0_sata_resources[] = {
500 .name = "sata base",
501 .start = SATA_PHYS_BASE,
502 .end = SATA_PHYS_BASE + 0x5000 - 1,
503 .flags = IORESOURCE_MEM,
504 }, {
505 .name = "sata irq",
506 .start = IRQ_MV78XX0_SATA,
507 .end = IRQ_MV78XX0_SATA,
508 .flags = IORESOURCE_IRQ,
512 static struct platform_device mv78xx0_sata = {
513 .name = "sata_mv",
514 .id = 0,
515 .dev = {
516 .coherent_dma_mask = 0xffffffff,
518 .num_resources = ARRAY_SIZE(mv78xx0_sata_resources),
519 .resource = mv78xx0_sata_resources,
522 void __init mv78xx0_sata_init(struct mv_sata_platform_data *sata_data)
524 sata_data->dram = &mv78xx0_mbus_dram_info;
525 mv78xx0_sata.dev.platform_data = sata_data;
526 platform_device_register(&mv78xx0_sata);
530 /*****************************************************************************
531 * UART0
532 ****************************************************************************/
533 static struct plat_serial8250_port mv78xx0_uart0_data[] = {
535 .mapbase = UART0_PHYS_BASE,
536 .membase = (char *)UART0_VIRT_BASE,
537 .irq = IRQ_MV78XX0_UART_0,
538 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
539 .iotype = UPIO_MEM,
540 .regshift = 2,
541 .uartclk = 0,
542 }, {
546 static struct resource mv78xx0_uart0_resources[] = {
548 .start = UART0_PHYS_BASE,
549 .end = UART0_PHYS_BASE + 0xff,
550 .flags = IORESOURCE_MEM,
551 }, {
552 .start = IRQ_MV78XX0_UART_0,
553 .end = IRQ_MV78XX0_UART_0,
554 .flags = IORESOURCE_IRQ,
558 static struct platform_device mv78xx0_uart0 = {
559 .name = "serial8250",
560 .id = 0,
561 .dev = {
562 .platform_data = mv78xx0_uart0_data,
564 .resource = mv78xx0_uart0_resources,
565 .num_resources = ARRAY_SIZE(mv78xx0_uart0_resources),
568 void __init mv78xx0_uart0_init(void)
570 platform_device_register(&mv78xx0_uart0);
574 /*****************************************************************************
575 * UART1
576 ****************************************************************************/
577 static struct plat_serial8250_port mv78xx0_uart1_data[] = {
579 .mapbase = UART1_PHYS_BASE,
580 .membase = (char *)UART1_VIRT_BASE,
581 .irq = IRQ_MV78XX0_UART_1,
582 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
583 .iotype = UPIO_MEM,
584 .regshift = 2,
585 .uartclk = 0,
586 }, {
590 static struct resource mv78xx0_uart1_resources[] = {
592 .start = UART1_PHYS_BASE,
593 .end = UART1_PHYS_BASE + 0xff,
594 .flags = IORESOURCE_MEM,
595 }, {
596 .start = IRQ_MV78XX0_UART_1,
597 .end = IRQ_MV78XX0_UART_1,
598 .flags = IORESOURCE_IRQ,
602 static struct platform_device mv78xx0_uart1 = {
603 .name = "serial8250",
604 .id = 1,
605 .dev = {
606 .platform_data = mv78xx0_uart1_data,
608 .resource = mv78xx0_uart1_resources,
609 .num_resources = ARRAY_SIZE(mv78xx0_uart1_resources),
612 void __init mv78xx0_uart1_init(void)
614 platform_device_register(&mv78xx0_uart1);
618 /*****************************************************************************
619 * UART2
620 ****************************************************************************/
621 static struct plat_serial8250_port mv78xx0_uart2_data[] = {
623 .mapbase = UART2_PHYS_BASE,
624 .membase = (char *)UART2_VIRT_BASE,
625 .irq = IRQ_MV78XX0_UART_2,
626 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
627 .iotype = UPIO_MEM,
628 .regshift = 2,
629 .uartclk = 0,
630 }, {
634 static struct resource mv78xx0_uart2_resources[] = {
636 .start = UART2_PHYS_BASE,
637 .end = UART2_PHYS_BASE + 0xff,
638 .flags = IORESOURCE_MEM,
639 }, {
640 .start = IRQ_MV78XX0_UART_2,
641 .end = IRQ_MV78XX0_UART_2,
642 .flags = IORESOURCE_IRQ,
646 static struct platform_device mv78xx0_uart2 = {
647 .name = "serial8250",
648 .id = 2,
649 .dev = {
650 .platform_data = mv78xx0_uart2_data,
652 .resource = mv78xx0_uart2_resources,
653 .num_resources = ARRAY_SIZE(mv78xx0_uart2_resources),
656 void __init mv78xx0_uart2_init(void)
658 platform_device_register(&mv78xx0_uart2);
662 /*****************************************************************************
663 * UART3
664 ****************************************************************************/
665 static struct plat_serial8250_port mv78xx0_uart3_data[] = {
667 .mapbase = UART3_PHYS_BASE,
668 .membase = (char *)UART3_VIRT_BASE,
669 .irq = IRQ_MV78XX0_UART_3,
670 .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
671 .iotype = UPIO_MEM,
672 .regshift = 2,
673 .uartclk = 0,
674 }, {
678 static struct resource mv78xx0_uart3_resources[] = {
680 .start = UART3_PHYS_BASE,
681 .end = UART3_PHYS_BASE + 0xff,
682 .flags = IORESOURCE_MEM,
683 }, {
684 .start = IRQ_MV78XX0_UART_3,
685 .end = IRQ_MV78XX0_UART_3,
686 .flags = IORESOURCE_IRQ,
690 static struct platform_device mv78xx0_uart3 = {
691 .name = "serial8250",
692 .id = 3,
693 .dev = {
694 .platform_data = mv78xx0_uart3_data,
696 .resource = mv78xx0_uart3_resources,
697 .num_resources = ARRAY_SIZE(mv78xx0_uart3_resources),
700 void __init mv78xx0_uart3_init(void)
702 platform_device_register(&mv78xx0_uart3);
706 /*****************************************************************************
707 * Time handling
708 ****************************************************************************/
709 static void mv78xx0_timer_init(void)
711 orion_time_init(IRQ_MV78XX0_TIMER_1, get_tclk());
714 struct sys_timer mv78xx0_timer = {
715 .init = mv78xx0_timer_init,
719 /*****************************************************************************
720 * General
721 ****************************************************************************/
722 static int __init is_l2_writethrough(void)
724 return !!(readl(CPU_CONTROL) & L2_WRITETHROUGH);
727 void __init mv78xx0_init(void)
729 int core_index;
730 int hclk;
731 int pclk;
732 int l2clk;
733 int tclk;
735 core_index = mv78xx0_core_index();
736 hclk = get_hclk();
737 get_pclk_l2clk(hclk, core_index, &pclk, &l2clk);
738 tclk = get_tclk();
740 printk(KERN_INFO "MV78xx0 core #%d, ", core_index);
741 printk("PCLK = %dMHz, ", (pclk + 499999) / 1000000);
742 printk("L2 = %dMHz, ", (l2clk + 499999) / 1000000);
743 printk("HCLK = %dMHz, ", (hclk + 499999) / 1000000);
744 printk("TCLK = %dMHz\n", (tclk + 499999) / 1000000);
746 mv78xx0_setup_cpu_mbus();
748 #ifdef CONFIG_CACHE_FEROCEON_L2
749 feroceon_l2_init(is_l2_writethrough());
750 #endif
752 mv78xx0_ge00_shared_data.t_clk = tclk;
753 mv78xx0_ge01_shared_data.t_clk = tclk;
754 mv78xx0_ge10_shared_data.t_clk = tclk;
755 mv78xx0_ge11_shared_data.t_clk = tclk;
756 mv78xx0_uart0_data[0].uartclk = tclk;
757 mv78xx0_uart1_data[0].uartclk = tclk;
758 mv78xx0_uart2_data[0].uartclk = tclk;
759 mv78xx0_uart3_data[0].uartclk = tclk;