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/time.h>
37 /*****************************************************************************
39 ****************************************************************************/
40 static struct map_desc orion5x_io_desc
[] __initdata
= {
42 .virtual = ORION5X_REGS_VIRT_BASE
,
43 .pfn
= __phys_to_pfn(ORION5X_REGS_PHYS_BASE
),
44 .length
= ORION5X_REGS_SIZE
,
47 .virtual = ORION5X_PCIE_IO_VIRT_BASE
,
48 .pfn
= __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE
),
49 .length
= ORION5X_PCIE_IO_SIZE
,
52 .virtual = ORION5X_PCI_IO_VIRT_BASE
,
53 .pfn
= __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE
),
54 .length
= ORION5X_PCI_IO_SIZE
,
57 .virtual = ORION5X_PCIE_WA_VIRT_BASE
,
58 .pfn
= __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE
),
59 .length
= ORION5X_PCIE_WA_SIZE
,
64 void __init
orion5x_map_io(void)
66 iotable_init(orion5x_io_desc
, ARRAY_SIZE(orion5x_io_desc
));
70 /*****************************************************************************
72 ****************************************************************************/
73 static struct orion_ehci_data orion5x_ehci_data
= {
74 .dram
= &orion5x_mbus_dram_info
,
75 .phy_version
= EHCI_PHY_ORION
,
78 static u64 ehci_dmamask
= 0xffffffffUL
;
81 /*****************************************************************************
83 ****************************************************************************/
84 static struct resource orion5x_ehci0_resources
[] = {
86 .start
= ORION5X_USB0_PHYS_BASE
,
87 .end
= ORION5X_USB0_PHYS_BASE
+ SZ_4K
- 1,
88 .flags
= IORESOURCE_MEM
,
90 .start
= IRQ_ORION5X_USB0_CTRL
,
91 .end
= IRQ_ORION5X_USB0_CTRL
,
92 .flags
= IORESOURCE_IRQ
,
96 static struct platform_device orion5x_ehci0
= {
100 .dma_mask
= &ehci_dmamask
,
101 .coherent_dma_mask
= 0xffffffff,
102 .platform_data
= &orion5x_ehci_data
,
104 .resource
= orion5x_ehci0_resources
,
105 .num_resources
= ARRAY_SIZE(orion5x_ehci0_resources
),
108 void __init
orion5x_ehci0_init(void)
110 platform_device_register(&orion5x_ehci0
);
114 /*****************************************************************************
116 ****************************************************************************/
117 static struct resource orion5x_ehci1_resources
[] = {
119 .start
= ORION5X_USB1_PHYS_BASE
,
120 .end
= ORION5X_USB1_PHYS_BASE
+ SZ_4K
- 1,
121 .flags
= IORESOURCE_MEM
,
123 .start
= IRQ_ORION5X_USB1_CTRL
,
124 .end
= IRQ_ORION5X_USB1_CTRL
,
125 .flags
= IORESOURCE_IRQ
,
129 static struct platform_device orion5x_ehci1
= {
130 .name
= "orion-ehci",
133 .dma_mask
= &ehci_dmamask
,
134 .coherent_dma_mask
= 0xffffffff,
135 .platform_data
= &orion5x_ehci_data
,
137 .resource
= orion5x_ehci1_resources
,
138 .num_resources
= ARRAY_SIZE(orion5x_ehci1_resources
),
141 void __init
orion5x_ehci1_init(void)
143 platform_device_register(&orion5x_ehci1
);
147 /*****************************************************************************
149 ****************************************************************************/
150 struct mv643xx_eth_shared_platform_data orion5x_eth_shared_data
= {
151 .dram
= &orion5x_mbus_dram_info
,
154 static struct resource orion5x_eth_shared_resources
[] = {
156 .start
= ORION5X_ETH_PHYS_BASE
+ 0x2000,
157 .end
= ORION5X_ETH_PHYS_BASE
+ 0x3fff,
158 .flags
= IORESOURCE_MEM
,
160 .start
= IRQ_ORION5X_ETH_ERR
,
161 .end
= IRQ_ORION5X_ETH_ERR
,
162 .flags
= IORESOURCE_IRQ
,
166 static struct platform_device orion5x_eth_shared
= {
167 .name
= MV643XX_ETH_SHARED_NAME
,
170 .platform_data
= &orion5x_eth_shared_data
,
172 .num_resources
= ARRAY_SIZE(orion5x_eth_shared_resources
),
173 .resource
= orion5x_eth_shared_resources
,
176 static struct resource orion5x_eth_resources
[] = {
179 .start
= IRQ_ORION5X_ETH_SUM
,
180 .end
= IRQ_ORION5X_ETH_SUM
,
181 .flags
= IORESOURCE_IRQ
,
185 static struct platform_device orion5x_eth
= {
186 .name
= MV643XX_ETH_NAME
,
189 .resource
= orion5x_eth_resources
,
192 void __init
orion5x_eth_init(struct mv643xx_eth_platform_data
*eth_data
)
194 eth_data
->shared
= &orion5x_eth_shared
;
195 orion5x_eth
.dev
.platform_data
= eth_data
;
197 platform_device_register(&orion5x_eth_shared
);
198 platform_device_register(&orion5x_eth
);
202 /*****************************************************************************
204 ****************************************************************************/
205 static struct resource orion5x_switch_resources
[] = {
209 .flags
= IORESOURCE_IRQ
,
213 static struct platform_device orion5x_switch_device
= {
217 .resource
= orion5x_switch_resources
,
220 void __init
orion5x_eth_switch_init(struct dsa_platform_data
*d
, int irq
)
223 orion5x_switch_resources
[0].start
= irq
;
224 orion5x_switch_resources
[0].end
= irq
;
225 orion5x_switch_device
.num_resources
= 1;
228 d
->mii_bus
= &orion5x_eth_shared
.dev
;
229 d
->netdev
= &orion5x_eth
.dev
;
230 orion5x_switch_device
.dev
.platform_data
= d
;
232 platform_device_register(&orion5x_switch_device
);
236 /*****************************************************************************
238 ****************************************************************************/
239 static struct mv64xxx_i2c_pdata orion5x_i2c_pdata
= {
240 .freq_m
= 8, /* assumes 166 MHz TCLK */
242 .timeout
= 1000, /* Default timeout of 1 second */
245 static struct resource orion5x_i2c_resources
[] = {
248 .start
= I2C_PHYS_BASE
,
249 .end
= I2C_PHYS_BASE
+ 0x1f,
250 .flags
= IORESOURCE_MEM
,
253 .start
= IRQ_ORION5X_I2C
,
254 .end
= IRQ_ORION5X_I2C
,
255 .flags
= IORESOURCE_IRQ
,
259 static struct platform_device orion5x_i2c
= {
260 .name
= MV64XXX_I2C_CTLR_NAME
,
262 .num_resources
= ARRAY_SIZE(orion5x_i2c_resources
),
263 .resource
= orion5x_i2c_resources
,
265 .platform_data
= &orion5x_i2c_pdata
,
269 void __init
orion5x_i2c_init(void)
271 platform_device_register(&orion5x_i2c
);
275 /*****************************************************************************
277 ****************************************************************************/
278 static struct resource orion5x_sata_resources
[] = {
281 .start
= ORION5X_SATA_PHYS_BASE
,
282 .end
= ORION5X_SATA_PHYS_BASE
+ 0x5000 - 1,
283 .flags
= IORESOURCE_MEM
,
286 .start
= IRQ_ORION5X_SATA
,
287 .end
= IRQ_ORION5X_SATA
,
288 .flags
= IORESOURCE_IRQ
,
292 static struct platform_device orion5x_sata
= {
296 .coherent_dma_mask
= 0xffffffff,
298 .num_resources
= ARRAY_SIZE(orion5x_sata_resources
),
299 .resource
= orion5x_sata_resources
,
302 void __init
orion5x_sata_init(struct mv_sata_platform_data
*sata_data
)
304 sata_data
->dram
= &orion5x_mbus_dram_info
;
305 orion5x_sata
.dev
.platform_data
= sata_data
;
306 platform_device_register(&orion5x_sata
);
310 /*****************************************************************************
312 ****************************************************************************/
313 static struct orion_spi_info orion5x_spi_plat_data
= {
315 .enable_clock_fix
= 1,
318 static struct resource orion5x_spi_resources
[] = {
321 .start
= SPI_PHYS_BASE
,
322 .end
= SPI_PHYS_BASE
+ 0x1f,
323 .flags
= IORESOURCE_MEM
,
327 static struct platform_device orion5x_spi
= {
331 .platform_data
= &orion5x_spi_plat_data
,
333 .num_resources
= ARRAY_SIZE(orion5x_spi_resources
),
334 .resource
= orion5x_spi_resources
,
337 void __init
orion5x_spi_init()
339 platform_device_register(&orion5x_spi
);
343 /*****************************************************************************
345 ****************************************************************************/
346 static struct plat_serial8250_port orion5x_uart0_data
[] = {
348 .mapbase
= UART0_PHYS_BASE
,
349 .membase
= (char *)UART0_VIRT_BASE
,
350 .irq
= IRQ_ORION5X_UART0
,
351 .flags
= UPF_SKIP_TEST
| UPF_BOOT_AUTOCONF
,
359 static struct resource orion5x_uart0_resources
[] = {
361 .start
= UART0_PHYS_BASE
,
362 .end
= UART0_PHYS_BASE
+ 0xff,
363 .flags
= IORESOURCE_MEM
,
365 .start
= IRQ_ORION5X_UART0
,
366 .end
= IRQ_ORION5X_UART0
,
367 .flags
= IORESOURCE_IRQ
,
371 static struct platform_device orion5x_uart0
= {
372 .name
= "serial8250",
373 .id
= PLAT8250_DEV_PLATFORM
,
375 .platform_data
= orion5x_uart0_data
,
377 .resource
= orion5x_uart0_resources
,
378 .num_resources
= ARRAY_SIZE(orion5x_uart0_resources
),
381 void __init
orion5x_uart0_init(void)
383 platform_device_register(&orion5x_uart0
);
387 /*****************************************************************************
389 ****************************************************************************/
390 static struct plat_serial8250_port orion5x_uart1_data
[] = {
392 .mapbase
= UART1_PHYS_BASE
,
393 .membase
= (char *)UART1_VIRT_BASE
,
394 .irq
= IRQ_ORION5X_UART1
,
395 .flags
= UPF_SKIP_TEST
| UPF_BOOT_AUTOCONF
,
403 static struct resource orion5x_uart1_resources
[] = {
405 .start
= UART1_PHYS_BASE
,
406 .end
= UART1_PHYS_BASE
+ 0xff,
407 .flags
= IORESOURCE_MEM
,
409 .start
= IRQ_ORION5X_UART1
,
410 .end
= IRQ_ORION5X_UART1
,
411 .flags
= IORESOURCE_IRQ
,
415 static struct platform_device orion5x_uart1
= {
416 .name
= "serial8250",
417 .id
= PLAT8250_DEV_PLATFORM1
,
419 .platform_data
= orion5x_uart1_data
,
421 .resource
= orion5x_uart1_resources
,
422 .num_resources
= ARRAY_SIZE(orion5x_uart1_resources
),
425 void __init
orion5x_uart1_init(void)
427 platform_device_register(&orion5x_uart1
);
431 /*****************************************************************************
433 ****************************************************************************/
434 struct mv_xor_platform_shared_data orion5x_xor_shared_data
= {
435 .dram
= &orion5x_mbus_dram_info
,
438 static struct resource orion5x_xor_shared_resources
[] = {
441 .start
= ORION5X_XOR_PHYS_BASE
,
442 .end
= ORION5X_XOR_PHYS_BASE
+ 0xff,
443 .flags
= IORESOURCE_MEM
,
446 .start
= ORION5X_XOR_PHYS_BASE
+ 0x200,
447 .end
= ORION5X_XOR_PHYS_BASE
+ 0x2ff,
448 .flags
= IORESOURCE_MEM
,
452 static struct platform_device orion5x_xor_shared
= {
453 .name
= MV_XOR_SHARED_NAME
,
456 .platform_data
= &orion5x_xor_shared_data
,
458 .num_resources
= ARRAY_SIZE(orion5x_xor_shared_resources
),
459 .resource
= orion5x_xor_shared_resources
,
462 static u64 orion5x_xor_dmamask
= DMA_32BIT_MASK
;
464 static struct resource orion5x_xor0_resources
[] = {
466 .start
= IRQ_ORION5X_XOR0
,
467 .end
= IRQ_ORION5X_XOR0
,
468 .flags
= IORESOURCE_IRQ
,
472 static struct mv_xor_platform_data orion5x_xor0_data
= {
473 .shared
= &orion5x_xor_shared
,
475 .pool_size
= PAGE_SIZE
,
478 static struct platform_device orion5x_xor0_channel
= {
481 .num_resources
= ARRAY_SIZE(orion5x_xor0_resources
),
482 .resource
= orion5x_xor0_resources
,
484 .dma_mask
= &orion5x_xor_dmamask
,
485 .coherent_dma_mask
= DMA_64BIT_MASK
,
486 .platform_data
= (void *)&orion5x_xor0_data
,
490 static struct resource orion5x_xor1_resources
[] = {
492 .start
= IRQ_ORION5X_XOR1
,
493 .end
= IRQ_ORION5X_XOR1
,
494 .flags
= IORESOURCE_IRQ
,
498 static struct mv_xor_platform_data orion5x_xor1_data
= {
499 .shared
= &orion5x_xor_shared
,
501 .pool_size
= PAGE_SIZE
,
504 static struct platform_device orion5x_xor1_channel
= {
507 .num_resources
= ARRAY_SIZE(orion5x_xor1_resources
),
508 .resource
= orion5x_xor1_resources
,
510 .dma_mask
= &orion5x_xor_dmamask
,
511 .coherent_dma_mask
= DMA_64BIT_MASK
,
512 .platform_data
= (void *)&orion5x_xor1_data
,
516 void __init
orion5x_xor_init(void)
518 platform_device_register(&orion5x_xor_shared
);
521 * two engines can't do memset simultaneously, this limitation
522 * satisfied by removing memset support from one of the engines.
524 dma_cap_set(DMA_MEMCPY
, orion5x_xor0_data
.cap_mask
);
525 dma_cap_set(DMA_XOR
, orion5x_xor0_data
.cap_mask
);
526 platform_device_register(&orion5x_xor0_channel
);
528 dma_cap_set(DMA_MEMCPY
, orion5x_xor1_data
.cap_mask
);
529 dma_cap_set(DMA_MEMSET
, orion5x_xor1_data
.cap_mask
);
530 dma_cap_set(DMA_XOR
, orion5x_xor1_data
.cap_mask
);
531 platform_device_register(&orion5x_xor1_channel
);
535 /*****************************************************************************
537 ****************************************************************************/
540 int __init
orion5x_find_tclk(void)
544 orion5x_pcie_id(&dev
, &rev
);
545 if (dev
== MV88F6183_DEV_ID
&&
546 (readl(MPP_RESET_SAMPLE
) & 0x00000200) == 0)
552 static void orion5x_timer_init(void)
554 orion5x_tclk
= orion5x_find_tclk();
555 orion_time_init(IRQ_ORION5X_BRIDGE
, orion5x_tclk
);
558 struct sys_timer orion5x_timer
= {
559 .init
= orion5x_timer_init
,
563 /*****************************************************************************
565 ****************************************************************************/
567 * Identify device ID and rev from PCIe configuration header space '0'.
569 static void __init
orion5x_id(u32
*dev
, u32
*rev
, char **dev_name
)
571 orion5x_pcie_id(dev
, rev
);
573 if (*dev
== MV88F5281_DEV_ID
) {
574 if (*rev
== MV88F5281_REV_D2
) {
575 *dev_name
= "MV88F5281-D2";
576 } else if (*rev
== MV88F5281_REV_D1
) {
577 *dev_name
= "MV88F5281-D1";
578 } else if (*rev
== MV88F5281_REV_D0
) {
579 *dev_name
= "MV88F5281-D0";
581 *dev_name
= "MV88F5281-Rev-Unsupported";
583 } else if (*dev
== MV88F5182_DEV_ID
) {
584 if (*rev
== MV88F5182_REV_A2
) {
585 *dev_name
= "MV88F5182-A2";
587 *dev_name
= "MV88F5182-Rev-Unsupported";
589 } else if (*dev
== MV88F5181_DEV_ID
) {
590 if (*rev
== MV88F5181_REV_B1
) {
591 *dev_name
= "MV88F5181-Rev-B1";
592 } else if (*rev
== MV88F5181L_REV_A1
) {
593 *dev_name
= "MV88F5181L-Rev-A1";
595 *dev_name
= "MV88F5181(L)-Rev-Unsupported";
597 } else if (*dev
== MV88F6183_DEV_ID
) {
598 if (*rev
== MV88F6183_REV_B0
) {
599 *dev_name
= "MV88F6183-Rev-B0";
601 *dev_name
= "MV88F6183-Rev-Unsupported";
604 *dev_name
= "Device-Unknown";
608 void __init
orion5x_init(void)
613 orion5x_id(&dev
, &rev
, &dev_name
);
614 printk(KERN_INFO
"Orion ID: %s. TCLK=%d.\n", dev_name
, orion5x_tclk
);
616 orion5x_eth_shared_data
.t_clk
= orion5x_tclk
;
617 orion5x_spi_plat_data
.tclk
= orion5x_tclk
;
618 orion5x_uart0_data
[0].uartclk
= orion5x_tclk
;
619 orion5x_uart1_data
[0].uartclk
= orion5x_tclk
;
622 * Setup Orion address map
624 orion5x_setup_cpu_mbus_bridge();
627 * Don't issue "Wait for Interrupt" instruction if we are
628 * running on D0 5281 silicon.
630 if (dev
== MV88F5281_DEV_ID
&& rev
== MV88F5281_REV_D0
) {
631 printk(KERN_INFO
"Orion: Applying 5281 D0 WFI workaround.\n");
637 * Many orion-based systems have buggy bootloader implementations.
638 * This is a common fixup for bogus memory tags.
640 void __init
tag_fixup_mem32(struct machine_desc
*mdesc
, struct tag
*t
,
641 char **from
, struct meminfo
*meminfo
)
643 for (; t
->hdr
.size
; t
= tag_next(t
))
644 if (t
->hdr
.tag
== ATAG_MEM
&&
645 (!t
->u
.mem
.size
|| t
->u
.mem
.size
& ~PAGE_MASK
||
646 t
->u
.mem
.start
& ~PAGE_MASK
)) {
648 "Clearing invalid memory bank %dKB@0x%08x\n",
649 t
->u
.mem
.size
/ 1024, t
->u
.mem
.start
);