Linux Audio

Check our new training course

Loading...
v3.15
  1/*
  2 * Platform device support for Au1x00 SoCs.
  3 *
  4 * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
  5 *
  6 * (C) Copyright Embedded Alley Solutions, Inc 2005
  7 * Author: Pantelis Antoniou <pantelis@embeddedalley.com>
  8 *
  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.
 12 */
 13
 
 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>
 22
 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>
 27
 28#include <prom.h>
 29
 30static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
 31			    unsigned int old_state)
 32{
 33#ifdef CONFIG_SERIAL_8250
 34	switch (state) {
 35	case 0:
 36		alchemy_uart_enable(CPHYSADDR(port->membase));
 37		serial8250_do_pm(port, state, old_state);
 38		break;
 39	case 3:		/* power off */
 40		serial8250_do_pm(port, state, old_state);
 41		alchemy_uart_disable(CPHYSADDR(port->membase));
 42		break;
 43	default:
 44		serial8250_do_pm(port, state, old_state);
 45		break;
 46	}
 47#endif
 48}
 49
 50#define PORT(_base, _irq)					\
 51	{							\
 52		.mapbase	= _base,			\
 
 53		.irq		= _irq,				\
 54		.regshift	= 2,				\
 55		.iotype		= UPIO_AU,			\
 56		.flags		= UPF_SKIP_TEST | UPF_IOREMAP | \
 57				  UPF_FIXED_TYPE,		\
 58		.type		= PORT_16550A,			\
 59		.pm		= alchemy_8250_pm,		\
 60	}
 61
 62static 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),
 68	},
 69	[ALCHEMY_CPU_AU1500] = {
 70		PORT(AU1000_UART0_PHYS_ADDR, AU1500_UART0_INT),
 71		PORT(AU1000_UART3_PHYS_ADDR, AU1500_UART3_INT),
 72	},
 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),
 77	},
 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),
 82	},
 83	[ALCHEMY_CPU_AU1200] = {
 84		PORT(AU1000_UART0_PHYS_ADDR, AU1200_UART0_INT),
 85		PORT(AU1000_UART1_PHYS_ADDR, AU1200_UART1_INT),
 86	},
 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),
 92	},
 93};
 94
 95static struct platform_device au1xx0_uart_device = {
 96	.name			= "serial8250",
 97	.id			= PLAT8250_DEV_AU1X00,
 98};
 99
100static void __init alchemy_setup_uarts(int ctype)
101{
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;
 
106
107	ports = kzalloc(s * (c + 1), GFP_KERNEL);
 
 
 
 
 
 
 
 
 
108	if (!ports) {
109		printk(KERN_INFO "Alchemy: no memory for UART data\n");
110		return;
111	}
112	memcpy(ports, au1x00_uart_data[ctype], s * c);
113	au1xx0_uart_device.dev.platform_data = ports;
114
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");
120}
121
122
123/* The dmamask must be set for OHCI/EHCI to work */
124static u64 alchemy_ohci_dmamask = DMA_BIT_MASK(32);
125static u64 __maybe_unused alchemy_ehci_dmamask = DMA_BIT_MASK(32);
126
127/* Power on callback for the ehci platform driver */
128static int alchemy_ehci_power_on(struct platform_device *pdev)
129{
130	return alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
131}
132
133/* Power off/suspend callback for the ehci platform driver */
134static void alchemy_ehci_power_off(struct platform_device *pdev)
135{
136	alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
137}
138
139static struct usb_ehci_pdata alchemy_ehci_pdata = {
140	.no_io_watchdog = 1,
141	.power_on	= alchemy_ehci_power_on,
142	.power_off	= alchemy_ehci_power_off,
143	.power_suspend	= alchemy_ehci_power_off,
144};
145
146/* Power on callback for the ohci platform driver */
147static int alchemy_ohci_power_on(struct platform_device *pdev)
148{
149	int unit;
150
151	unit = (pdev->id == 1) ?
152		ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
153
154	return alchemy_usb_control(unit, 1);
155}
156
157/* Power off/suspend callback for the ohci platform driver */
158static void alchemy_ohci_power_off(struct platform_device *pdev)
159{
160	int unit;
161
162	unit = (pdev->id == 1) ?
163		ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
164
165	alchemy_usb_control(unit, 0);
166}
167
168static 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,
172};
173
174static 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 },
181};
182
183static 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 },
186};
187
188static int __init _new_usbres(struct resource **r, struct platform_device **d)
189{
190	*r = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
191	if (!*r)
192		return -ENOMEM;
193	*d = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
194	if (!*d) {
195		kfree(*r);
196		return -ENOMEM;
197	}
198
199	(*d)->dev.coherent_dma_mask = DMA_BIT_MASK(32);
200	(*d)->num_resources = 2;
201	(*d)->resource = *r;
202
203	return 0;
204}
205
206static void __init alchemy_setup_usb(int ctype)
207{
208	struct resource *res;
209	struct platform_device *pdev;
210
211	/* setup OHCI0.  Every variant has one */
212	if (_new_usbres(&res, &pdev))
213		return;
214
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";
222	pdev->id = 0;
223	pdev->dev.dma_mask = &alchemy_ohci_dmamask;
224	pdev->dev.platform_data = &alchemy_ohci_pdata;
225
226	if (platform_device_register(pdev))
227		printk(KERN_INFO "Alchemy USB: cannot add OHCI0\n");
228
229
230	/* setup EHCI0: Au1200/Au1300 */
231	if ((ctype == ALCHEMY_CPU_AU1200) || (ctype == ALCHEMY_CPU_AU1300)) {
232		if (_new_usbres(&res, &pdev))
233			return;
234
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";
242		pdev->id = 0;
243		pdev->dev.dma_mask = &alchemy_ehci_dmamask;
244		pdev->dev.platform_data = &alchemy_ehci_pdata;
245
246		if (platform_device_register(pdev))
247			printk(KERN_INFO "Alchemy USB: cannot add EHCI0\n");
248	}
249
250	/* Au1300: OHCI1 */
251	if (ctype == ALCHEMY_CPU_AU1300) {
252		if (_new_usbres(&res, &pdev))
253			return;
254
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";
262		pdev->id = 1;
263		pdev->dev.dma_mask = &alchemy_ohci_dmamask;
264		pdev->dev.platform_data = &alchemy_ohci_pdata;
265
266		if (platform_device_register(pdev))
267			printk(KERN_INFO "Alchemy USB: cannot add OHCI1\n");
268	}
269}
270
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)		\
274	{						\
275		.start	= _base,			\
276		.end	= _base + 0xffff,		\
277		.flags	= IORESOURCE_MEM,		\
278	},						\
279	{						\
280		.start	= _enable,			\
281		.end	= _enable + 0x3,		\
282		.flags	= IORESOURCE_MEM,		\
283	},						\
284	{						\
285		.start	= _irq,				\
286		.end	= _irq,				\
287		.flags	= IORESOURCE_IRQ		\
288	},						\
289	{						\
290		.start	= _macdma,			\
291		.end	= _macdma + 0x1ff,		\
292		.flags	= IORESOURCE_MEM,		\
293	}
294
295static 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,
299			AU1000_MAC0_DMA_INT,
300			AU1000_MACDMA0_PHYS_ADDR)
301	},
302	[ALCHEMY_CPU_AU1500] = {
303		MAC_RES(AU1500_MAC0_PHYS_ADDR,
304			AU1500_MACEN_PHYS_ADDR,
305			AU1500_MAC0_DMA_INT,
306			AU1000_MACDMA0_PHYS_ADDR)
307	},
308	[ALCHEMY_CPU_AU1100] = {
309		MAC_RES(AU1000_MAC0_PHYS_ADDR,
310			AU1000_MACEN_PHYS_ADDR,
311			AU1100_MAC0_DMA_INT,
312			AU1000_MACDMA0_PHYS_ADDR)
313	},
314	[ALCHEMY_CPU_AU1550] = {
315		MAC_RES(AU1000_MAC0_PHYS_ADDR,
316			AU1000_MACEN_PHYS_ADDR,
317			AU1550_MAC0_DMA_INT,
318			AU1000_MACDMA0_PHYS_ADDR)
319	},
320};
321
322static struct au1000_eth_platform_data au1xxx_eth0_platform_data = {
323	.phy1_search_mac0 = 1,
324};
325
326static struct platform_device au1xxx_eth0_device = {
327	.name		= "au1000-eth",
328	.id		= 0,
329	.num_resources	= MAC_RES_COUNT,
330	.dev.platform_data = &au1xxx_eth0_platform_data,
 
 
 
 
331};
332
333static 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,
337			AU1000_MAC1_DMA_INT,
338			AU1000_MACDMA1_PHYS_ADDR)
339	},
340	[ALCHEMY_CPU_AU1500] = {
341		MAC_RES(AU1500_MAC1_PHYS_ADDR,
342			AU1500_MACEN_PHYS_ADDR + 4,
343			AU1500_MAC1_DMA_INT,
344			AU1000_MACDMA1_PHYS_ADDR)
345	},
346	[ALCHEMY_CPU_AU1550] = {
347		MAC_RES(AU1000_MAC1_PHYS_ADDR,
348			AU1000_MACEN_PHYS_ADDR + 4,
349			AU1550_MAC1_DMA_INT,
350			AU1000_MACDMA1_PHYS_ADDR)
351	},
352};
353
354static struct au1000_eth_platform_data au1xxx_eth1_platform_data = {
355	.phy1_search_mac0 = 1,
356};
357
358static struct platform_device au1xxx_eth1_device = {
359	.name		= "au1000-eth",
360	.id		= 1,
361	.num_resources	= MAC_RES_COUNT,
362	.dev.platform_data = &au1xxx_eth1_platform_data,
 
 
 
 
363};
364
365void __init au1xxx_override_eth_cfg(unsigned int port,
366			struct au1000_eth_platform_data *eth_data)
367{
368	if (!eth_data || port > 1)
369		return;
370
371	if (port == 0)
372		memcpy(&au1xxx_eth0_platform_data, eth_data,
373			sizeof(struct au1000_eth_platform_data));
374	else
375		memcpy(&au1xxx_eth1_platform_data, eth_data,
376			sizeof(struct au1000_eth_platform_data));
377}
378
379static void __init alchemy_setup_macs(int ctype)
380{
381	int ret, i;
382	unsigned char ethaddr[6];
383	struct resource *macres;
384
385	/* Handle 1st MAC */
386	if (alchemy_get_macs(ctype) < 1)
387		return;
388
389	macres = kmemdup(au1xxx_eth0_resources[ctype],
390			 sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
391	if (!macres) {
392		printk(KERN_INFO "Alchemy: no memory for MAC0 resources\n");
393		return;
394	}
395	au1xxx_eth0_device.resource = macres;
396
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);
400
401	ret = platform_device_register(&au1xxx_eth0_device);
402	if (ret)
403		printk(KERN_INFO "Alchemy: failed to register MAC0\n");
404
405
406	/* Handle 2nd MAC */
407	if (alchemy_get_macs(ctype) < 2)
408		return;
409
410	macres = kmemdup(au1xxx_eth1_resources[ctype],
411			 sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
412	if (!macres) {
413		printk(KERN_INFO "Alchemy: no memory for MAC1 resources\n");
414		return;
415	}
416	au1xxx_eth1_device.resource = macres;
417
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);
421
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);
425		if (ret)
426			printk(KERN_INFO "Alchemy: failed to register MAC1\n");
427	}
428}
429
430static int __init au1xxx_platform_init(void)
431{
432	int ctype = alchemy_get_cputype();
433
434	alchemy_setup_uarts(ctype);
435	alchemy_setup_macs(ctype);
436	alchemy_setup_usb(ctype);
437
438	return 0;
439}
440
441arch_initcall(au1xxx_platform_init);
v6.8
  1/*
  2 * Platform device support for Au1x00 SoCs.
  3 *
  4 * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
  5 *
  6 * (C) Copyright Embedded Alley Solutions, Inc 2005
  7 * Author: Pantelis Antoniou <pantelis@embeddedalley.com>
  8 *
  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.
 12 */
 13
 14#include <linux/clk.h>
 15#include <linux/dma-mapping.h>
 16#include <linux/etherdevice.h>
 17#include <linux/init.h>
 18#include <linux/platform_device.h>
 19#include <linux/serial_8250.h>
 20#include <linux/slab.h>
 21#include <linux/usb/ehci_pdriver.h>
 22#include <linux/usb/ohci_pdriver.h>
 23
 24#include <asm/mach-au1x00/au1000.h>
 25#include <asm/mach-au1x00/au1xxx_dbdma.h>
 26#include <asm/mach-au1x00/au1100_mmc.h>
 27#include <asm/mach-au1x00/au1xxx_eth.h>
 28
 29#include <prom.h>
 30
 31static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
 32			    unsigned int old_state)
 33{
 34#ifdef CONFIG_SERIAL_8250
 35	switch (state) {
 36	case 0:
 37		alchemy_uart_enable(CPHYSADDR(port->membase));
 38		serial8250_do_pm(port, state, old_state);
 39		break;
 40	case 3:		/* power off */
 41		serial8250_do_pm(port, state, old_state);
 42		alchemy_uart_disable(CPHYSADDR(port->membase));
 43		break;
 44	default:
 45		serial8250_do_pm(port, state, old_state);
 46		break;
 47	}
 48#endif
 49}
 50
 51#define PORT(_base, _irq)					\
 52	{							\
 53		.mapbase	= _base,			\
 54		.mapsize	= 0x1000,			\
 55		.irq		= _irq,				\
 56		.regshift	= 2,				\
 
 57		.flags		= UPF_SKIP_TEST | UPF_IOREMAP | \
 58				  UPF_FIXED_TYPE,		\
 59		.type		= PORT_16550A,			\
 60		.pm		= alchemy_8250_pm,		\
 61	}
 62
 63static struct plat_serial8250_port au1x00_uart_data[][4] __initdata = {
 64	[ALCHEMY_CPU_AU1000] = {
 65		PORT(AU1000_UART0_PHYS_ADDR, AU1000_UART0_INT),
 66		PORT(AU1000_UART1_PHYS_ADDR, AU1000_UART1_INT),
 67		PORT(AU1000_UART2_PHYS_ADDR, AU1000_UART2_INT),
 68		PORT(AU1000_UART3_PHYS_ADDR, AU1000_UART3_INT),
 69	},
 70	[ALCHEMY_CPU_AU1500] = {
 71		PORT(AU1000_UART0_PHYS_ADDR, AU1500_UART0_INT),
 72		PORT(AU1000_UART3_PHYS_ADDR, AU1500_UART3_INT),
 73	},
 74	[ALCHEMY_CPU_AU1100] = {
 75		PORT(AU1000_UART0_PHYS_ADDR, AU1100_UART0_INT),
 76		PORT(AU1000_UART1_PHYS_ADDR, AU1100_UART1_INT),
 77		PORT(AU1000_UART3_PHYS_ADDR, AU1100_UART3_INT),
 78	},
 79	[ALCHEMY_CPU_AU1550] = {
 80		PORT(AU1000_UART0_PHYS_ADDR, AU1550_UART0_INT),
 81		PORT(AU1000_UART1_PHYS_ADDR, AU1550_UART1_INT),
 82		PORT(AU1000_UART3_PHYS_ADDR, AU1550_UART3_INT),
 83	},
 84	[ALCHEMY_CPU_AU1200] = {
 85		PORT(AU1000_UART0_PHYS_ADDR, AU1200_UART0_INT),
 86		PORT(AU1000_UART1_PHYS_ADDR, AU1200_UART1_INT),
 87	},
 88	[ALCHEMY_CPU_AU1300] = {
 89		PORT(AU1300_UART0_PHYS_ADDR, AU1300_UART0_INT),
 90		PORT(AU1300_UART1_PHYS_ADDR, AU1300_UART1_INT),
 91		PORT(AU1300_UART2_PHYS_ADDR, AU1300_UART2_INT),
 92		PORT(AU1300_UART3_PHYS_ADDR, AU1300_UART3_INT),
 93	},
 94};
 95
 96static struct platform_device au1xx0_uart_device = {
 97	.name			= "serial8250",
 98	.id			= PLAT8250_DEV_AU1X00,
 99};
100
101static void __init alchemy_setup_uarts(int ctype)
102{
103	long uartclk;
104	int s = sizeof(struct plat_serial8250_port);
105	int c = alchemy_get_uarts(ctype);
106	struct plat_serial8250_port *ports;
107	struct clk *clk = clk_get(NULL, ALCHEMY_PERIPH_CLK);
108
109	if (IS_ERR(clk))
110		return;
111	if (clk_prepare_enable(clk)) {
112		clk_put(clk);
113		return;
114	}
115	uartclk = clk_get_rate(clk);
116	clk_put(clk);
117
118	ports = kcalloc(s, (c + 1), GFP_KERNEL);
119	if (!ports) {
120		printk(KERN_INFO "Alchemy: no memory for UART data\n");
121		return;
122	}
123	memcpy(ports, au1x00_uart_data[ctype], s * c);
124	au1xx0_uart_device.dev.platform_data = ports;
125
126	/* Fill up uartclk. */
127	for (s = 0; s < c; s++) {
128		ports[s].uartclk = uartclk;
129		if (au_platform_setup(&ports[s]) < 0) {
130			kfree(ports);
131			printk(KERN_INFO "Alchemy: missing support for UARTs\n");
132			return;
133		}
134	}
135	if (platform_device_register(&au1xx0_uart_device))
136		printk(KERN_INFO "Alchemy: failed to register UARTs\n");
137}
138
139
140static u64 alchemy_all_dmamask = DMA_BIT_MASK(32);
 
 
141
142/* Power on callback for the ehci platform driver */
143static int alchemy_ehci_power_on(struct platform_device *pdev)
144{
145	return alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
146}
147
148/* Power off/suspend callback for the ehci platform driver */
149static void alchemy_ehci_power_off(struct platform_device *pdev)
150{
151	alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
152}
153
154static struct usb_ehci_pdata alchemy_ehci_pdata = {
155	.no_io_watchdog = 1,
156	.power_on	= alchemy_ehci_power_on,
157	.power_off	= alchemy_ehci_power_off,
158	.power_suspend	= alchemy_ehci_power_off,
159};
160
161/* Power on callback for the ohci platform driver */
162static int alchemy_ohci_power_on(struct platform_device *pdev)
163{
164	int unit;
165
166	unit = (pdev->id == 1) ?
167		ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
168
169	return alchemy_usb_control(unit, 1);
170}
171
172/* Power off/suspend callback for the ohci platform driver */
173static void alchemy_ohci_power_off(struct platform_device *pdev)
174{
175	int unit;
176
177	unit = (pdev->id == 1) ?
178		ALCHEMY_USB_OHCI1 : ALCHEMY_USB_OHCI0;
179
180	alchemy_usb_control(unit, 0);
181}
182
183static struct usb_ohci_pdata alchemy_ohci_pdata = {
184	.power_on		= alchemy_ohci_power_on,
185	.power_off		= alchemy_ohci_power_off,
186	.power_suspend		= alchemy_ohci_power_off,
187};
188
189static unsigned long alchemy_ohci_data[][2] __initdata = {
190	[ALCHEMY_CPU_AU1000] = { AU1000_USB_OHCI_PHYS_ADDR, AU1000_USB_HOST_INT },
191	[ALCHEMY_CPU_AU1500] = { AU1000_USB_OHCI_PHYS_ADDR, AU1500_USB_HOST_INT },
192	[ALCHEMY_CPU_AU1100] = { AU1000_USB_OHCI_PHYS_ADDR, AU1100_USB_HOST_INT },
193	[ALCHEMY_CPU_AU1550] = { AU1550_USB_OHCI_PHYS_ADDR, AU1550_USB_HOST_INT },
194	[ALCHEMY_CPU_AU1200] = { AU1200_USB_OHCI_PHYS_ADDR, AU1200_USB_INT },
195	[ALCHEMY_CPU_AU1300] = { AU1300_USB_OHCI0_PHYS_ADDR, AU1300_USB_INT },
196};
197
198static unsigned long alchemy_ehci_data[][2] __initdata = {
199	[ALCHEMY_CPU_AU1200] = { AU1200_USB_EHCI_PHYS_ADDR, AU1200_USB_INT },
200	[ALCHEMY_CPU_AU1300] = { AU1300_USB_EHCI_PHYS_ADDR, AU1300_USB_INT },
201};
202
203static int __init _new_usbres(struct resource **r, struct platform_device **d)
204{
205	*r = kcalloc(2, sizeof(struct resource), GFP_KERNEL);
206	if (!*r)
207		return -ENOMEM;
208	*d = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
209	if (!*d) {
210		kfree(*r);
211		return -ENOMEM;
212	}
213
214	(*d)->dev.coherent_dma_mask = DMA_BIT_MASK(32);
215	(*d)->num_resources = 2;
216	(*d)->resource = *r;
217
218	return 0;
219}
220
221static void __init alchemy_setup_usb(int ctype)
222{
223	struct resource *res;
224	struct platform_device *pdev;
225
226	/* setup OHCI0.  Every variant has one */
227	if (_new_usbres(&res, &pdev))
228		return;
229
230	res[0].start = alchemy_ohci_data[ctype][0];
231	res[0].end = res[0].start + 0x100 - 1;
232	res[0].flags = IORESOURCE_MEM;
233	res[1].start = alchemy_ohci_data[ctype][1];
234	res[1].end = res[1].start;
235	res[1].flags = IORESOURCE_IRQ;
236	pdev->name = "ohci-platform";
237	pdev->id = 0;
238	pdev->dev.dma_mask = &alchemy_all_dmamask;
239	pdev->dev.platform_data = &alchemy_ohci_pdata;
240
241	if (platform_device_register(pdev))
242		printk(KERN_INFO "Alchemy USB: cannot add OHCI0\n");
243
244
245	/* setup EHCI0: Au1200/Au1300 */
246	if ((ctype == ALCHEMY_CPU_AU1200) || (ctype == ALCHEMY_CPU_AU1300)) {
247		if (_new_usbres(&res, &pdev))
248			return;
249
250		res[0].start = alchemy_ehci_data[ctype][0];
251		res[0].end = res[0].start + 0x100 - 1;
252		res[0].flags = IORESOURCE_MEM;
253		res[1].start = alchemy_ehci_data[ctype][1];
254		res[1].end = res[1].start;
255		res[1].flags = IORESOURCE_IRQ;
256		pdev->name = "ehci-platform";
257		pdev->id = 0;
258		pdev->dev.dma_mask = &alchemy_all_dmamask;
259		pdev->dev.platform_data = &alchemy_ehci_pdata;
260
261		if (platform_device_register(pdev))
262			printk(KERN_INFO "Alchemy USB: cannot add EHCI0\n");
263	}
264
265	/* Au1300: OHCI1 */
266	if (ctype == ALCHEMY_CPU_AU1300) {
267		if (_new_usbres(&res, &pdev))
268			return;
269
270		res[0].start = AU1300_USB_OHCI1_PHYS_ADDR;
271		res[0].end = res[0].start + 0x100 - 1;
272		res[0].flags = IORESOURCE_MEM;
273		res[1].start = AU1300_USB_INT;
274		res[1].end = res[1].start;
275		res[1].flags = IORESOURCE_IRQ;
276		pdev->name = "ohci-platform";
277		pdev->id = 1;
278		pdev->dev.dma_mask = &alchemy_all_dmamask;
279		pdev->dev.platform_data = &alchemy_ohci_pdata;
280
281		if (platform_device_register(pdev))
282			printk(KERN_INFO "Alchemy USB: cannot add OHCI1\n");
283	}
284}
285
286/* Macro to help defining the Ethernet MAC resources */
287#define MAC_RES_COUNT	4	/* MAC regs, MAC en, MAC INT, MACDMA regs */
288#define MAC_RES(_base, _enable, _irq, _macdma)		\
289	{						\
290		.start	= _base,			\
291		.end	= _base + 0xffff,		\
292		.flags	= IORESOURCE_MEM,		\
293	},						\
294	{						\
295		.start	= _enable,			\
296		.end	= _enable + 0x3,		\
297		.flags	= IORESOURCE_MEM,		\
298	},						\
299	{						\
300		.start	= _irq,				\
301		.end	= _irq,				\
302		.flags	= IORESOURCE_IRQ		\
303	},						\
304	{						\
305		.start	= _macdma,			\
306		.end	= _macdma + 0x1ff,		\
307		.flags	= IORESOURCE_MEM,		\
308	}
309
310static struct resource au1xxx_eth0_resources[][MAC_RES_COUNT] __initdata = {
311	[ALCHEMY_CPU_AU1000] = {
312		MAC_RES(AU1000_MAC0_PHYS_ADDR,
313			AU1000_MACEN_PHYS_ADDR,
314			AU1000_MAC0_DMA_INT,
315			AU1000_MACDMA0_PHYS_ADDR)
316	},
317	[ALCHEMY_CPU_AU1500] = {
318		MAC_RES(AU1500_MAC0_PHYS_ADDR,
319			AU1500_MACEN_PHYS_ADDR,
320			AU1500_MAC0_DMA_INT,
321			AU1000_MACDMA0_PHYS_ADDR)
322	},
323	[ALCHEMY_CPU_AU1100] = {
324		MAC_RES(AU1000_MAC0_PHYS_ADDR,
325			AU1000_MACEN_PHYS_ADDR,
326			AU1100_MAC0_DMA_INT,
327			AU1000_MACDMA0_PHYS_ADDR)
328	},
329	[ALCHEMY_CPU_AU1550] = {
330		MAC_RES(AU1000_MAC0_PHYS_ADDR,
331			AU1000_MACEN_PHYS_ADDR,
332			AU1550_MAC0_DMA_INT,
333			AU1000_MACDMA0_PHYS_ADDR)
334	},
335};
336
337static struct au1000_eth_platform_data au1xxx_eth0_platform_data = {
338	.phy1_search_mac0 = 1,
339};
340
341static struct platform_device au1xxx_eth0_device = {
342	.name		= "au1000-eth",
343	.id		= 0,
344	.num_resources	= MAC_RES_COUNT,
345	.dev = {
346		.dma_mask               = &alchemy_all_dmamask,
347		.coherent_dma_mask      = DMA_BIT_MASK(32),
348		.platform_data          = &au1xxx_eth0_platform_data,
349	},
350};
351
352static struct resource au1xxx_eth1_resources[][MAC_RES_COUNT] __initdata = {
353	[ALCHEMY_CPU_AU1000] = {
354		MAC_RES(AU1000_MAC1_PHYS_ADDR,
355			AU1000_MACEN_PHYS_ADDR + 4,
356			AU1000_MAC1_DMA_INT,
357			AU1000_MACDMA1_PHYS_ADDR)
358	},
359	[ALCHEMY_CPU_AU1500] = {
360		MAC_RES(AU1500_MAC1_PHYS_ADDR,
361			AU1500_MACEN_PHYS_ADDR + 4,
362			AU1500_MAC1_DMA_INT,
363			AU1000_MACDMA1_PHYS_ADDR)
364	},
365	[ALCHEMY_CPU_AU1550] = {
366		MAC_RES(AU1000_MAC1_PHYS_ADDR,
367			AU1000_MACEN_PHYS_ADDR + 4,
368			AU1550_MAC1_DMA_INT,
369			AU1000_MACDMA1_PHYS_ADDR)
370	},
371};
372
373static struct au1000_eth_platform_data au1xxx_eth1_platform_data = {
374	.phy1_search_mac0 = 1,
375};
376
377static struct platform_device au1xxx_eth1_device = {
378	.name		= "au1000-eth",
379	.id		= 1,
380	.num_resources	= MAC_RES_COUNT,
381	.dev = {
382		.dma_mask               = &alchemy_all_dmamask,
383		.coherent_dma_mask      = DMA_BIT_MASK(32),
384		.platform_data          = &au1xxx_eth1_platform_data,
385	},
386};
387
388void __init au1xxx_override_eth_cfg(unsigned int port,
389			struct au1000_eth_platform_data *eth_data)
390{
391	if (!eth_data || port > 1)
392		return;
393
394	if (port == 0)
395		memcpy(&au1xxx_eth0_platform_data, eth_data,
396			sizeof(struct au1000_eth_platform_data));
397	else
398		memcpy(&au1xxx_eth1_platform_data, eth_data,
399			sizeof(struct au1000_eth_platform_data));
400}
401
402static void __init alchemy_setup_macs(int ctype)
403{
404	int ret, i;
405	unsigned char ethaddr[6];
406	struct resource *macres;
407
408	/* Handle 1st MAC */
409	if (alchemy_get_macs(ctype) < 1)
410		return;
411
412	macres = kmemdup(au1xxx_eth0_resources[ctype],
413			 sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
414	if (!macres) {
415		printk(KERN_INFO "Alchemy: no memory for MAC0 resources\n");
416		return;
417	}
418	au1xxx_eth0_device.resource = macres;
419
420	i = prom_get_ethernet_addr(ethaddr);
421	if (!i && !is_valid_ether_addr(au1xxx_eth0_platform_data.mac))
422		memcpy(au1xxx_eth0_platform_data.mac, ethaddr, 6);
423
424	ret = platform_device_register(&au1xxx_eth0_device);
425	if (ret)
426		printk(KERN_INFO "Alchemy: failed to register MAC0\n");
427
428
429	/* Handle 2nd MAC */
430	if (alchemy_get_macs(ctype) < 2)
431		return;
432
433	macres = kmemdup(au1xxx_eth1_resources[ctype],
434			 sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
435	if (!macres) {
436		printk(KERN_INFO "Alchemy: no memory for MAC1 resources\n");
437		return;
438	}
439	au1xxx_eth1_device.resource = macres;
440
441	ethaddr[5] += 1;	/* next addr for 2nd MAC */
442	if (!i && !is_valid_ether_addr(au1xxx_eth1_platform_data.mac))
443		memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);
444
445	/* Register second MAC if enabled in pinfunc */
446	if (!(alchemy_rdsys(AU1000_SYS_PINFUNC) & SYS_PF_NI2)) {
447		ret = platform_device_register(&au1xxx_eth1_device);
448		if (ret)
449			printk(KERN_INFO "Alchemy: failed to register MAC1\n");
450	}
451}
452
453static int __init au1xxx_platform_init(void)
454{
455	int ctype = alchemy_get_cputype();
456
457	alchemy_setup_uarts(ctype);
458	alchemy_setup_macs(ctype);
459	alchemy_setup_usb(ctype);
460
461	return 0;
462}
463
464arch_initcall(au1xxx_platform_init);