2 * arch/arm/mach-orion5x/common.c
4 * Core functions for Marvell Orion 5x SoCs
6 * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/serial_8250.h>
17 #include <linux/mbus.h>
18 #include <linux/mv643xx_eth.h>
19 #include <linux/mv643xx_i2c.h>
20 #include <linux/ata_platform.h>
21 #include <linux/spi/orion_spi.h>
24 #include <asm/setup.h>
25 #include <asm/timex.h>
26 #include <asm/mach/arch.h>
27 #include <asm/mach/map.h>
28 #include <asm/mach/time.h>
29 #include <mach/hardware.h>
30 #include <mach/orion5x.h>
31 #include <plat/ehci-orion.h>
32 #include <plat/mv_xor.h>
33 #include <plat/orion_nand.h>
34 #include <plat/orion5x_wdt.h>
35 #include <plat/time.h>
38 /*****************************************************************************
40 ****************************************************************************/
41 static struct map_desc orion5x_io_desc
[] __initdata
= {
43 .virtual = ORION5X_REGS_VIRT_BASE
,
44 .pfn
= __phys_to_pfn(ORION5X_REGS_PHYS_BASE
),
45 .length
= ORION5X_REGS_SIZE
,
48 .virtual = ORION5X_PCIE_IO_VIRT_BASE
,
49 .pfn
= __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE
),
50 .length
= ORION5X_PCIE_IO_SIZE
,
53 .virtual = ORION5X_PCI_IO_VIRT_BASE
,
54 .pfn
= __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE
),
55 .length
= ORION5X_PCI_IO_SIZE
,
58 .virtual = ORION5X_PCIE_WA_VIRT_BASE
,
59 .pfn
= __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE
),
60 .length
= ORION5X_PCIE_WA_SIZE
,
65 void __init
orion5x_map_io(void)
67 iotable_init(orion5x_io_desc
, ARRAY_SIZE(orion5x_io_desc
));
71 /*****************************************************************************
73 ****************************************************************************/
74 static struct orion_ehci_data orion5x_ehci_data
= {
75 .dram
= &orion5x_mbus_dram_info
,
76 .phy_version
= EHCI_PHY_ORION
,
79 static u64 ehci_dmamask
= 0xffffffffUL
;
82 /*****************************************************************************
84 ****************************************************************************/
85 static struct resource orion5x_ehci0_resources
[] = {
87 .start
= ORION5X_USB0_PHYS_BASE
,
88 .end
= ORION5X_USB0_PHYS_BASE
+ SZ_4K
- 1,
89 .flags
= IORESOURCE_MEM
,
91 .start
= IRQ_ORION5X_USB0_CTRL
,
92 .end
= IRQ_ORION5X_USB0_CTRL
,
93 .flags
= IORESOURCE_IRQ
,
97 static struct platform_device orion5x_ehci0
= {
101 .dma_mask
= &ehci_dmamask
,
102 .coherent_dma_mask
= 0xffffffff,
103 .platform_data
= &orion5x_ehci_data
,
105 .resource
= orion5x_ehci0_resources
,
106 .num_resources
= ARRAY_SIZE(orion5x_ehci0_resources
),
109 void __init
orion5x_ehci0_init(void)
111 platform_device_register(&orion5x_ehci0
);
115 /*****************************************************************************
117 ****************************************************************************/
118 static struct resource orion5x_ehci1_resources
[] = {
120 .start
= ORION5X_USB1_PHYS_BASE
,
121 .end
= ORION5X_USB1_PHYS_BASE
+ SZ_4K
- 1,
122 .flags
= IORESOURCE_MEM
,
124 .start
= IRQ_ORION5X_USB1_CTRL
,
125 .end
= IRQ_ORION5X_USB1_CTRL
,
126 .flags
= IORESOURCE_IRQ
,
130 static struct platform_device orion5x_ehci1
= {
131 .name
= "orion-ehci",
134 .dma_mask
= &ehci_dmamask
,
135 .coherent_dma_mask
= 0xffffffff,
136 .platform_data
= &orion5x_ehci_data
,
138 .resource
= orion5x_ehci1_resources
,
139 .num_resources
= ARRAY_SIZE(orion5x_ehci1_resources
),
142 void __init
orion5x_ehci1_init(void)
144 platform_device_register(&orion5x_ehci1
);
148 /*****************************************************************************
150 ****************************************************************************/
151 struct mv643xx_eth_shared_platform_data orion5x_eth_shared_data
= {
152 .dram
= &orion5x_mbus_dram_info
,
155 static struct resource orion5x_eth_shared_resources
[] = {
157 .start
= ORION5X_ETH_PHYS_BASE
+ 0x2000,
158 .end
= ORION5X_ETH_PHYS_BASE
+ 0x3fff,
159 .flags
= IORESOURCE_MEM
,
161 .start
= IRQ_ORION5X_ETH_ERR
,
162 .end
= IRQ_ORION5X_ETH_ERR
,
163 .flags
= IORESOURCE_IRQ
,
167 static struct platform_device orion5x_eth_shared
= {
168 .name
= MV643XX_ETH_SHARED_NAME
,
171 .platform_data
= &orion5x_eth_shared_data
,
173 .num_resources
= ARRAY_SIZE(orion5x_eth_shared_resources
),
174 .resource
= orion5x_eth_shared_resources
,
177 static struct resource orion5x_eth_resources
[] = {
180 .start
= IRQ_ORION5X_ETH_SUM
,
181 .end
= IRQ_ORION5X_ETH_SUM
,
182 .flags
= IORESOURCE_IRQ
,
186 static struct platform_device orion5x_eth
= {
187 .name
= MV643XX_ETH_NAME
,
190 .resource
= orion5x_eth_resources
,
192 .coherent_dma_mask
= 0xffffffff,
196 void __init
orion5x_eth_init(struct mv643xx_eth_platform_data
*eth_data
)
198 eth_data
->shared
= &orion5x_eth_shared
;
199 orion5x_eth
.dev
.platform_data
= eth_data
;
201 platform_device_register(&orion5x_eth_shared
);
202 platform_device_register(&orion5x_eth
);
206 /*****************************************************************************
208 ****************************************************************************/
209 static struct resource orion5x_switch_resources
[] = {
213 .flags
= IORESOURCE_IRQ
,
217 static struct platform_device orion5x_switch_device
= {
221 .resource
= orion5x_switch_resources
,
224 void __init
orion5x_eth_switch_init(struct dsa_platform_data
*d
, int irq
)
229 orion5x_switch_resources
[0].start
= irq
;
230 orion5x_switch_resources
[0].end
= irq
;
231 orion5x_switch_device
.num_resources
= 1;
234 d
->netdev
= &orion5x_eth
.dev
;
235 for (i
= 0; i
< d
->nr_chips
; i
++)
236 d
->chip
[i
].mii_bus
= &orion5x_eth_shared
.dev
;
237 orion5x_switch_device
.dev
.platform_data
= d
;
239 platform_device_register(&orion5x_switch_device
);
243 /*****************************************************************************
245 ****************************************************************************/
246 static struct mv64xxx_i2c_pdata orion5x_i2c_pdata
= {
247 .freq_m
= 8, /* assumes 166 MHz TCLK */
249 .timeout
= 1000, /* Default timeout of 1 second */
252 static struct resource orion5x_i2c_resources
[] = {
254 .start
= I2C_PHYS_BASE
,
255 .end
= I2C_PHYS_BASE
+ 0x1f,
256 .flags
= IORESOURCE_MEM
,
258 .start
= IRQ_ORION5X_I2C
,
259 .end
= IRQ_ORION5X_I2C
,
260 .flags
= IORESOURCE_IRQ
,
264 static struct platform_device orion5x_i2c
= {
265 .name
= MV64XXX_I2C_CTLR_NAME
,
267 .num_resources
= ARRAY_SIZE(orion5x_i2c_resources
),
268 .resource
= orion5x_i2c_resources
,
270 .platform_data
= &orion5x_i2c_pdata
,
274 void __init
orion5x_i2c_init(void)
276 platform_device_register(&orion5x_i2c
);
280 /*****************************************************************************
282 ****************************************************************************/
283 static struct resource orion5x_sata_resources
[] = {
286 .start
= ORION5X_SATA_PHYS_BASE
,
287 .end
= ORION5X_SATA_PHYS_BASE
+ 0x5000 - 1,
288 .flags
= IORESOURCE_MEM
,
291 .start
= IRQ_ORION5X_SATA
,
292 .end
= IRQ_ORION5X_SATA
,
293 .flags
= IORESOURCE_IRQ
,
297 static struct platform_device orion5x_sata
= {
301 .coherent_dma_mask
= 0xffffffff,
303 .num_resources
= ARRAY_SIZE(orion5x_sata_resources
),
304 .resource
= orion5x_sata_resources
,
307 void __init
orion5x_sata_init(struct mv_sata_platform_data
*sata_data
)
309 sata_data
->dram
= &orion5x_mbus_dram_info
;
310 orion5x_sata
.dev
.platform_data
= sata_data
;
311 platform_device_register(&orion5x_sata
);
315 /*****************************************************************************
317 ****************************************************************************/
318 static struct orion_spi_info orion5x_spi_plat_data
= {
320 .enable_clock_fix
= 1,
323 static struct resource orion5x_spi_resources
[] = {
326 .start
= SPI_PHYS_BASE
,
327 .end
= SPI_PHYS_BASE
+ 0x1f,
328 .flags
= IORESOURCE_MEM
,
332 static struct platform_device orion5x_spi
= {
336 .platform_data
= &orion5x_spi_plat_data
,
338 .num_resources
= ARRAY_SIZE(orion5x_spi_resources
),
339 .resource
= orion5x_spi_resources
,
342 void __init
orion5x_spi_init()
344 platform_device_register(&orion5x_spi
);
348 /*****************************************************************************
350 ****************************************************************************/
351 static struct plat_serial8250_port orion5x_uart0_data
[] = {
353 .mapbase
= UART0_PHYS_BASE
,
354 .membase
= (char *)UART0_VIRT_BASE
,
355 .irq
= IRQ_ORION5X_UART0
,
356 .flags
= UPF_SKIP_TEST
| UPF_BOOT_AUTOCONF
,
364 static struct resource orion5x_uart0_resources
[] = {
366 .start
= UART0_PHYS_BASE
,
367 .end
= UART0_PHYS_BASE
+ 0xff,
368 .flags
= IORESOURCE_MEM
,
370 .start
= IRQ_ORION5X_UART0
,
371 .end
= IRQ_ORION5X_UART0
,
372 .flags
= IORESOURCE_IRQ
,
376 static struct platform_device orion5x_uart0
= {
377 .name
= "serial8250",
378 .id
= PLAT8250_DEV_PLATFORM
,
380 .platform_data
= orion5x_uart0_data
,
382 .resource
= orion5x_uart0_resources
,
383 .num_resources
= ARRAY_SIZE(orion5x_uart0_resources
),
386 void __init
orion5x_uart0_init(void)
388 platform_device_register(&orion5x_uart0
);
392 /*****************************************************************************
394 ****************************************************************************/
395 static struct plat_serial8250_port orion5x_uart1_data
[] = {
397 .mapbase
= UART1_PHYS_BASE
,
398 .membase
= (char *)UART1_VIRT_BASE
,
399 .irq
= IRQ_ORION5X_UART1
,
400 .flags
= UPF_SKIP_TEST
| UPF_BOOT_AUTOCONF
,
408 static struct resource orion5x_uart1_resources
[] = {
410 .start
= UART1_PHYS_BASE
,
411 .end
= UART1_PHYS_BASE
+ 0xff,
412 .flags
= IORESOURCE_MEM
,
414 .start
= IRQ_ORION5X_UART1
,
415 .end
= IRQ_ORION5X_UART1
,
416 .flags
= IORESOURCE_IRQ
,
420 static struct platform_device orion5x_uart1
= {
421 .name
= "serial8250",
422 .id
= PLAT8250_DEV_PLATFORM1
,
424 .platform_data
= orion5x_uart1_data
,
426 .resource
= orion5x_uart1_resources
,
427 .num_resources
= ARRAY_SIZE(orion5x_uart1_resources
),
430 void __init
orion5x_uart1_init(void)
432 platform_device_register(&orion5x_uart1
);
436 /*****************************************************************************
438 ****************************************************************************/
439 struct mv_xor_platform_shared_data orion5x_xor_shared_data
= {
440 .dram
= &orion5x_mbus_dram_info
,
443 static struct resource orion5x_xor_shared_resources
[] = {
446 .start
= ORION5X_XOR_PHYS_BASE
,
447 .end
= ORION5X_XOR_PHYS_BASE
+ 0xff,
448 .flags
= IORESOURCE_MEM
,
451 .start
= ORION5X_XOR_PHYS_BASE
+ 0x200,
452 .end
= ORION5X_XOR_PHYS_BASE
+ 0x2ff,
453 .flags
= IORESOURCE_MEM
,
457 static struct platform_device orion5x_xor_shared
= {
458 .name
= MV_XOR_SHARED_NAME
,
461 .platform_data
= &orion5x_xor_shared_data
,
463 .num_resources
= ARRAY_SIZE(orion5x_xor_shared_resources
),
464 .resource
= orion5x_xor_shared_resources
,
467 static u64 orion5x_xor_dmamask
= DMA_BIT_MASK(32);
469 static struct resource orion5x_xor0_resources
[] = {
471 .start
= IRQ_ORION5X_XOR0
,
472 .end
= IRQ_ORION5X_XOR0
,
473 .flags
= IORESOURCE_IRQ
,
477 static struct mv_xor_platform_data orion5x_xor0_data
= {
478 .shared
= &orion5x_xor_shared
,
480 .pool_size
= PAGE_SIZE
,
483 static struct platform_device orion5x_xor0_channel
= {
486 .num_resources
= ARRAY_SIZE(orion5x_xor0_resources
),
487 .resource
= orion5x_xor0_resources
,
489 .dma_mask
= &orion5x_xor_dmamask
,
490 .coherent_dma_mask
= DMA_BIT_MASK(64),
491 .platform_data
= (void *)&orion5x_xor0_data
,
495 static struct resource orion5x_xor1_resources
[] = {
497 .start
= IRQ_ORION5X_XOR1
,
498 .end
= IRQ_ORION5X_XOR1
,
499 .flags
= IORESOURCE_IRQ
,
503 static struct mv_xor_platform_data orion5x_xor1_data
= {
504 .shared
= &orion5x_xor_shared
,
506 .pool_size
= PAGE_SIZE
,
509 static struct platform_device orion5x_xor1_channel
= {
512 .num_resources
= ARRAY_SIZE(orion5x_xor1_resources
),
513 .resource
= orion5x_xor1_resources
,
515 .dma_mask
= &orion5x_xor_dmamask
,
516 .coherent_dma_mask
= DMA_BIT_MASK(64),
517 .platform_data
= (void *)&orion5x_xor1_data
,
521 void __init
orion5x_xor_init(void)
523 platform_device_register(&orion5x_xor_shared
);
526 * two engines can't do memset simultaneously, this limitation
527 * satisfied by removing memset support from one of the engines.
529 dma_cap_set(DMA_MEMCPY
, orion5x_xor0_data
.cap_mask
);
530 dma_cap_set(DMA_XOR
, orion5x_xor0_data
.cap_mask
);
531 platform_device_register(&orion5x_xor0_channel
);
533 dma_cap_set(DMA_MEMCPY
, orion5x_xor1_data
.cap_mask
);
534 dma_cap_set(DMA_MEMSET
, orion5x_xor1_data
.cap_mask
);
535 dma_cap_set(DMA_XOR
, orion5x_xor1_data
.cap_mask
);
536 platform_device_register(&orion5x_xor1_channel
);
540 /*****************************************************************************
542 ****************************************************************************/
543 static struct orion5x_wdt_platform_data orion5x_wdt_data
= {
547 static struct platform_device orion5x_wdt_device
= {
548 .name
= "orion5x_wdt",
551 .platform_data
= &orion5x_wdt_data
,
556 void __init
orion5x_wdt_init(void)
558 orion5x_wdt_data
.tclk
= orion5x_tclk
;
559 platform_device_register(&orion5x_wdt_device
);
563 /*****************************************************************************
565 ****************************************************************************/
568 int __init
orion5x_find_tclk(void)
572 orion5x_pcie_id(&dev
, &rev
);
573 if (dev
== MV88F6183_DEV_ID
&&
574 (readl(MPP_RESET_SAMPLE
) & 0x00000200) == 0)
580 static void orion5x_timer_init(void)
582 orion5x_tclk
= orion5x_find_tclk();
583 orion_time_init(IRQ_ORION5X_BRIDGE
, orion5x_tclk
);
586 struct sys_timer orion5x_timer
= {
587 .init
= orion5x_timer_init
,
591 /*****************************************************************************
593 ****************************************************************************/
595 * Identify device ID and rev from PCIe configuration header space '0'.
597 static void __init
orion5x_id(u32
*dev
, u32
*rev
, char **dev_name
)
599 orion5x_pcie_id(dev
, rev
);
601 if (*dev
== MV88F5281_DEV_ID
) {
602 if (*rev
== MV88F5281_REV_D2
) {
603 *dev_name
= "MV88F5281-D2";
604 } else if (*rev
== MV88F5281_REV_D1
) {
605 *dev_name
= "MV88F5281-D1";
606 } else if (*rev
== MV88F5281_REV_D0
) {
607 *dev_name
= "MV88F5281-D0";
609 *dev_name
= "MV88F5281-Rev-Unsupported";
611 } else if (*dev
== MV88F5182_DEV_ID
) {
612 if (*rev
== MV88F5182_REV_A2
) {
613 *dev_name
= "MV88F5182-A2";
615 *dev_name
= "MV88F5182-Rev-Unsupported";
617 } else if (*dev
== MV88F5181_DEV_ID
) {
618 if (*rev
== MV88F5181_REV_B1
) {
619 *dev_name
= "MV88F5181-Rev-B1";
620 } else if (*rev
== MV88F5181L_REV_A1
) {
621 *dev_name
= "MV88F5181L-Rev-A1";
623 *dev_name
= "MV88F5181(L)-Rev-Unsupported";
625 } else if (*dev
== MV88F6183_DEV_ID
) {
626 if (*rev
== MV88F6183_REV_B0
) {
627 *dev_name
= "MV88F6183-Rev-B0";
629 *dev_name
= "MV88F6183-Rev-Unsupported";
632 *dev_name
= "Device-Unknown";
636 void __init
orion5x_init(void)
641 orion5x_id(&dev
, &rev
, &dev_name
);
642 printk(KERN_INFO
"Orion ID: %s. TCLK=%d.\n", dev_name
, orion5x_tclk
);
644 orion5x_eth_shared_data
.t_clk
= orion5x_tclk
;
645 orion5x_spi_plat_data
.tclk
= orion5x_tclk
;
646 orion5x_uart0_data
[0].uartclk
= orion5x_tclk
;
647 orion5x_uart1_data
[0].uartclk
= orion5x_tclk
;
650 * Setup Orion address map
652 orion5x_setup_cpu_mbus_bridge();
655 * Don't issue "Wait for Interrupt" instruction if we are
656 * running on D0 5281 silicon.
658 if (dev
== MV88F5281_DEV_ID
&& rev
== MV88F5281_REV_D0
) {
659 printk(KERN_INFO
"Orion: Applying 5281 D0 WFI workaround.\n");
664 * Register watchdog driver
670 * Many orion-based systems have buggy bootloader implementations.
671 * This is a common fixup for bogus memory tags.
673 void __init
tag_fixup_mem32(struct machine_desc
*mdesc
, struct tag
*t
,
674 char **from
, struct meminfo
*meminfo
)
676 for (; t
->hdr
.size
; t
= tag_next(t
))
677 if (t
->hdr
.tag
== ATAG_MEM
&&
678 (!t
->u
.mem
.size
|| t
->u
.mem
.size
& ~PAGE_MASK
||
679 t
->u
.mem
.start
& ~PAGE_MASK
)) {
681 "Clearing invalid memory bank %dKB@0x%08x\n",
682 t
->u
.mem
.size
/ 1024, t
->u
.mem
.start
);