2 * Platform device support for Au1x00 SoCs.
4 * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
6 * (C) Copyright Embedded Alley Solutions, Inc 2005
7 * Author: Pantelis Antoniou <pantelis@embeddedalley.com>
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
14 #include <linux/dma-mapping.h>
15 #include <linux/etherdevice.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/serial_8250.h>
19 #include <linux/slab.h>
20 #include <linux/usb/ehci_pdriver.h>
21 #include <linux/usb/ohci_pdriver.h>
23 #include <asm/mach-au1x00/au1000.h>
24 #include <asm/mach-au1x00/au1xxx_dbdma.h>
25 #include <asm/mach-au1x00/au1100_mmc.h>
26 #include <asm/mach-au1x00/au1xxx_eth.h>
30 static void alchemy_8250_pm(struct uart_port
*port
, unsigned int state
,
31 unsigned int old_state
)
33 #ifdef CONFIG_SERIAL_8250
36 alchemy_uart_enable(CPHYSADDR(port
->membase
));
37 serial8250_do_pm(port
, state
, old_state
);
39 case 3: /* power off */
40 serial8250_do_pm(port
, state
, old_state
);
41 alchemy_uart_disable(CPHYSADDR(port
->membase
));
44 serial8250_do_pm(port
, state
, old_state
);
50 #define PORT(_base, _irq) \
56 .flags = UPF_SKIP_TEST | UPF_IOREMAP | \
58 .type = PORT_16550A, \
59 .pm = alchemy_8250_pm, \
62 static struct plat_serial8250_port au1x00_uart_data
[][4] __initdata
= {
63 [ALCHEMY_CPU_AU1000
] = {
64 PORT(AU1000_UART0_PHYS_ADDR
, AU1000_UART0_INT
),
65 PORT(AU1000_UART1_PHYS_ADDR
, AU1000_UART1_INT
),
66 PORT(AU1000_UART2_PHYS_ADDR
, AU1000_UART2_INT
),
67 PORT(AU1000_UART3_PHYS_ADDR
, AU1000_UART3_INT
),
69 [ALCHEMY_CPU_AU1500
] = {
70 PORT(AU1000_UART0_PHYS_ADDR
, AU1500_UART0_INT
),
71 PORT(AU1000_UART3_PHYS_ADDR
, AU1500_UART3_INT
),
73 [ALCHEMY_CPU_AU1100
] = {
74 PORT(AU1000_UART0_PHYS_ADDR
, AU1100_UART0_INT
),
75 PORT(AU1000_UART1_PHYS_ADDR
, AU1100_UART1_INT
),
76 PORT(AU1000_UART3_PHYS_ADDR
, AU1100_UART3_INT
),
78 [ALCHEMY_CPU_AU1550
] = {
79 PORT(AU1000_UART0_PHYS_ADDR
, AU1550_UART0_INT
),
80 PORT(AU1000_UART1_PHYS_ADDR
, AU1550_UART1_INT
),
81 PORT(AU1000_UART3_PHYS_ADDR
, AU1550_UART3_INT
),
83 [ALCHEMY_CPU_AU1200
] = {
84 PORT(AU1000_UART0_PHYS_ADDR
, AU1200_UART0_INT
),
85 PORT(AU1000_UART1_PHYS_ADDR
, AU1200_UART1_INT
),
87 [ALCHEMY_CPU_AU1300
] = {
88 PORT(AU1300_UART0_PHYS_ADDR
, AU1300_UART0_INT
),
89 PORT(AU1300_UART1_PHYS_ADDR
, AU1300_UART1_INT
),
90 PORT(AU1300_UART2_PHYS_ADDR
, AU1300_UART2_INT
),
91 PORT(AU1300_UART3_PHYS_ADDR
, AU1300_UART3_INT
),
95 static struct platform_device au1xx0_uart_device
= {
97 .id
= PLAT8250_DEV_AU1X00
,
100 static void __init
alchemy_setup_uarts(int ctype
)
102 unsigned int uartclk
= get_au1x00_uart_baud_base() * 16;
103 int s
= sizeof(struct plat_serial8250_port
);
104 int c
= alchemy_get_uarts(ctype
);
105 struct plat_serial8250_port
*ports
;
107 ports
= kzalloc(s
* (c
+ 1), GFP_KERNEL
);
109 printk(KERN_INFO
"Alchemy: no memory for UART data\n");
112 memcpy(ports
, au1x00_uart_data
[ctype
], s
* c
);
113 au1xx0_uart_device
.dev
.platform_data
= ports
;
115 /* Fill up uartclk. */
116 for (s
= 0; s
< c
; s
++)
117 ports
[s
].uartclk
= uartclk
;
118 if (platform_device_register(&au1xx0_uart_device
))
119 printk(KERN_INFO
"Alchemy: failed to register UARTs\n");
123 /* The dmamask must be set for OHCI/EHCI to work */
124 static u64 alchemy_ohci_dmamask
= DMA_BIT_MASK(32);
125 static u64 __maybe_unused alchemy_ehci_dmamask
= DMA_BIT_MASK(32);
127 /* Power on callback for the ehci platform driver */
128 static int alchemy_ehci_power_on(struct platform_device
*pdev
)
130 return alchemy_usb_control(ALCHEMY_USB_EHCI0
, 1);
133 /* Power off/suspend callback for the ehci platform driver */
134 static void alchemy_ehci_power_off(struct platform_device
*pdev
)
136 alchemy_usb_control(ALCHEMY_USB_EHCI0
, 0);
139 static struct usb_ehci_pdata alchemy_ehci_pdata
= {
141 .power_on
= alchemy_ehci_power_on
,
142 .power_off
= alchemy_ehci_power_off
,
143 .power_suspend
= alchemy_ehci_power_off
,
146 /* Power on callback for the ohci platform driver */
147 static int alchemy_ohci_power_on(struct platform_device
*pdev
)
151 unit
= (pdev
->id
== 1) ?
152 ALCHEMY_USB_OHCI1
: ALCHEMY_USB_OHCI0
;
154 return alchemy_usb_control(unit
, 1);
157 /* Power off/suspend callback for the ohci platform driver */
158 static void alchemy_ohci_power_off(struct platform_device
*pdev
)
162 unit
= (pdev
->id
== 1) ?
163 ALCHEMY_USB_OHCI1
: ALCHEMY_USB_OHCI0
;
165 alchemy_usb_control(unit
, 0);
168 static struct usb_ohci_pdata alchemy_ohci_pdata
= {
169 .power_on
= alchemy_ohci_power_on
,
170 .power_off
= alchemy_ohci_power_off
,
171 .power_suspend
= alchemy_ohci_power_off
,
174 static unsigned long alchemy_ohci_data
[][2] __initdata
= {
175 [ALCHEMY_CPU_AU1000
] = { AU1000_USB_OHCI_PHYS_ADDR
, AU1000_USB_HOST_INT
},
176 [ALCHEMY_CPU_AU1500
] = { AU1000_USB_OHCI_PHYS_ADDR
, AU1500_USB_HOST_INT
},
177 [ALCHEMY_CPU_AU1100
] = { AU1000_USB_OHCI_PHYS_ADDR
, AU1100_USB_HOST_INT
},
178 [ALCHEMY_CPU_AU1550
] = { AU1550_USB_OHCI_PHYS_ADDR
, AU1550_USB_HOST_INT
},
179 [ALCHEMY_CPU_AU1200
] = { AU1200_USB_OHCI_PHYS_ADDR
, AU1200_USB_INT
},
180 [ALCHEMY_CPU_AU1300
] = { AU1300_USB_OHCI0_PHYS_ADDR
, AU1300_USB_INT
},
183 static unsigned long alchemy_ehci_data
[][2] __initdata
= {
184 [ALCHEMY_CPU_AU1200
] = { AU1200_USB_EHCI_PHYS_ADDR
, AU1200_USB_INT
},
185 [ALCHEMY_CPU_AU1300
] = { AU1300_USB_EHCI_PHYS_ADDR
, AU1300_USB_INT
},
188 static int __init
_new_usbres(struct resource
**r
, struct platform_device
**d
)
190 *r
= kzalloc(sizeof(struct resource
) * 2, GFP_KERNEL
);
193 *d
= kzalloc(sizeof(struct platform_device
), GFP_KERNEL
);
199 (*d
)->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
200 (*d
)->num_resources
= 2;
206 static void __init
alchemy_setup_usb(int ctype
)
208 struct resource
*res
;
209 struct platform_device
*pdev
;
211 /* setup OHCI0. Every variant has one */
212 if (_new_usbres(&res
, &pdev
))
215 res
[0].start
= alchemy_ohci_data
[ctype
][0];
216 res
[0].end
= res
[0].start
+ 0x100 - 1;
217 res
[0].flags
= IORESOURCE_MEM
;
218 res
[1].start
= alchemy_ohci_data
[ctype
][1];
219 res
[1].end
= res
[1].start
;
220 res
[1].flags
= IORESOURCE_IRQ
;
221 pdev
->name
= "ohci-platform";
223 pdev
->dev
.dma_mask
= &alchemy_ohci_dmamask
;
224 pdev
->dev
.platform_data
= &alchemy_ohci_pdata
;
226 if (platform_device_register(pdev
))
227 printk(KERN_INFO
"Alchemy USB: cannot add OHCI0\n");
230 /* setup EHCI0: Au1200/Au1300 */
231 if ((ctype
== ALCHEMY_CPU_AU1200
) || (ctype
== ALCHEMY_CPU_AU1300
)) {
232 if (_new_usbres(&res
, &pdev
))
235 res
[0].start
= alchemy_ehci_data
[ctype
][0];
236 res
[0].end
= res
[0].start
+ 0x100 - 1;
237 res
[0].flags
= IORESOURCE_MEM
;
238 res
[1].start
= alchemy_ehci_data
[ctype
][1];
239 res
[1].end
= res
[1].start
;
240 res
[1].flags
= IORESOURCE_IRQ
;
241 pdev
->name
= "ehci-platform";
243 pdev
->dev
.dma_mask
= &alchemy_ehci_dmamask
;
244 pdev
->dev
.platform_data
= &alchemy_ehci_pdata
;
246 if (platform_device_register(pdev
))
247 printk(KERN_INFO
"Alchemy USB: cannot add EHCI0\n");
251 if (ctype
== ALCHEMY_CPU_AU1300
) {
252 if (_new_usbres(&res
, &pdev
))
255 res
[0].start
= AU1300_USB_OHCI1_PHYS_ADDR
;
256 res
[0].end
= res
[0].start
+ 0x100 - 1;
257 res
[0].flags
= IORESOURCE_MEM
;
258 res
[1].start
= AU1300_USB_INT
;
259 res
[1].end
= res
[1].start
;
260 res
[1].flags
= IORESOURCE_IRQ
;
261 pdev
->name
= "ohci-platform";
263 pdev
->dev
.dma_mask
= &alchemy_ohci_dmamask
;
264 pdev
->dev
.platform_data
= &alchemy_ohci_pdata
;
266 if (platform_device_register(pdev
))
267 printk(KERN_INFO
"Alchemy USB: cannot add OHCI1\n");
271 /* Macro to help defining the Ethernet MAC resources */
272 #define MAC_RES_COUNT 4 /* MAC regs, MAC en, MAC INT, MACDMA regs */
273 #define MAC_RES(_base, _enable, _irq, _macdma) \
276 .end = _base + 0xffff, \
277 .flags = IORESOURCE_MEM, \
281 .end = _enable + 0x3, \
282 .flags = IORESOURCE_MEM, \
287 .flags = IORESOURCE_IRQ \
291 .end = _macdma + 0x1ff, \
292 .flags = IORESOURCE_MEM, \
295 static struct resource au1xxx_eth0_resources
[][MAC_RES_COUNT
] __initdata
= {
296 [ALCHEMY_CPU_AU1000
] = {
297 MAC_RES(AU1000_MAC0_PHYS_ADDR
,
298 AU1000_MACEN_PHYS_ADDR
,
300 AU1000_MACDMA0_PHYS_ADDR
)
302 [ALCHEMY_CPU_AU1500
] = {
303 MAC_RES(AU1500_MAC0_PHYS_ADDR
,
304 AU1500_MACEN_PHYS_ADDR
,
306 AU1000_MACDMA0_PHYS_ADDR
)
308 [ALCHEMY_CPU_AU1100
] = {
309 MAC_RES(AU1000_MAC0_PHYS_ADDR
,
310 AU1000_MACEN_PHYS_ADDR
,
312 AU1000_MACDMA0_PHYS_ADDR
)
314 [ALCHEMY_CPU_AU1550
] = {
315 MAC_RES(AU1000_MAC0_PHYS_ADDR
,
316 AU1000_MACEN_PHYS_ADDR
,
318 AU1000_MACDMA0_PHYS_ADDR
)
322 static struct au1000_eth_platform_data au1xxx_eth0_platform_data
= {
323 .phy1_search_mac0
= 1,
326 static struct platform_device au1xxx_eth0_device
= {
327 .name
= "au1000-eth",
329 .num_resources
= MAC_RES_COUNT
,
330 .dev
.platform_data
= &au1xxx_eth0_platform_data
,
333 static struct resource au1xxx_eth1_resources
[][MAC_RES_COUNT
] __initdata
= {
334 [ALCHEMY_CPU_AU1000
] = {
335 MAC_RES(AU1000_MAC1_PHYS_ADDR
,
336 AU1000_MACEN_PHYS_ADDR
+ 4,
338 AU1000_MACDMA1_PHYS_ADDR
)
340 [ALCHEMY_CPU_AU1500
] = {
341 MAC_RES(AU1500_MAC1_PHYS_ADDR
,
342 AU1500_MACEN_PHYS_ADDR
+ 4,
344 AU1000_MACDMA1_PHYS_ADDR
)
346 [ALCHEMY_CPU_AU1550
] = {
347 MAC_RES(AU1000_MAC1_PHYS_ADDR
,
348 AU1000_MACEN_PHYS_ADDR
+ 4,
350 AU1000_MACDMA1_PHYS_ADDR
)
354 static struct au1000_eth_platform_data au1xxx_eth1_platform_data
= {
355 .phy1_search_mac0
= 1,
358 static struct platform_device au1xxx_eth1_device
= {
359 .name
= "au1000-eth",
361 .num_resources
= MAC_RES_COUNT
,
362 .dev
.platform_data
= &au1xxx_eth1_platform_data
,
365 void __init
au1xxx_override_eth_cfg(unsigned int port
,
366 struct au1000_eth_platform_data
*eth_data
)
368 if (!eth_data
|| port
> 1)
372 memcpy(&au1xxx_eth0_platform_data
, eth_data
,
373 sizeof(struct au1000_eth_platform_data
));
375 memcpy(&au1xxx_eth1_platform_data
, eth_data
,
376 sizeof(struct au1000_eth_platform_data
));
379 static void __init
alchemy_setup_macs(int ctype
)
382 unsigned char ethaddr
[6];
383 struct resource
*macres
;
386 if (alchemy_get_macs(ctype
) < 1)
389 macres
= kmemdup(au1xxx_eth0_resources
[ctype
],
390 sizeof(struct resource
) * MAC_RES_COUNT
, GFP_KERNEL
);
392 printk(KERN_INFO
"Alchemy: no memory for MAC0 resources\n");
395 au1xxx_eth0_device
.resource
= macres
;
397 i
= prom_get_ethernet_addr(ethaddr
);
398 if (!i
&& !is_valid_ether_addr(au1xxx_eth0_platform_data
.mac
))
399 memcpy(au1xxx_eth0_platform_data
.mac
, ethaddr
, 6);
401 ret
= platform_device_register(&au1xxx_eth0_device
);
403 printk(KERN_INFO
"Alchemy: failed to register MAC0\n");
407 if (alchemy_get_macs(ctype
) < 2)
410 macres
= kmemdup(au1xxx_eth1_resources
[ctype
],
411 sizeof(struct resource
) * MAC_RES_COUNT
, GFP_KERNEL
);
413 printk(KERN_INFO
"Alchemy: no memory for MAC1 resources\n");
416 au1xxx_eth1_device
.resource
= macres
;
418 ethaddr
[5] += 1; /* next addr for 2nd MAC */
419 if (!i
&& !is_valid_ether_addr(au1xxx_eth1_platform_data
.mac
))
420 memcpy(au1xxx_eth1_platform_data
.mac
, ethaddr
, 6);
422 /* Register second MAC if enabled in pinfunc */
423 if (!(au_readl(SYS_PINFUNC
) & (u32
)SYS_PF_NI2
)) {
424 ret
= platform_device_register(&au1xxx_eth1_device
);
426 printk(KERN_INFO
"Alchemy: failed to register MAC1\n");
430 static int __init
au1xxx_platform_init(void)
432 int ctype
= alchemy_get_cputype();
434 alchemy_setup_uarts(ctype
);
435 alchemy_setup_macs(ctype
);
436 alchemy_setup_usb(ctype
);
441 arch_initcall(au1xxx_platform_init
);