2 * ADM5120 generic platform devices
4 * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/list.h>
15 #include <linux/device.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/platform_device.h>
18 #include <linux/gpio.h>
20 #include <asm/bootinfo.h>
22 #include <asm/mach-adm5120/adm5120_defs.h>
23 #include <asm/mach-adm5120/adm5120_info.h>
24 #include <asm/mach-adm5120/adm5120_irq.h>
25 #include <asm/mach-adm5120/adm5120_switch.h>
26 #include <asm/mach-adm5120/adm5120_nand.h>
27 #include <asm/mach-adm5120/adm5120_platform.h>
31 * TODO:remove global adm5120_eth* variables when the switch driver will be
32 * converted into a real platform driver
34 unsigned int adm5120_eth_num_ports = 6;
35 EXPORT_SYMBOL_GPL(adm5120_eth_num_ports);
37 unsigned char adm5120_eth_macs[6][6] = {
38 {'\00', 'A', 'D', 'M', '\x51', '\x20' },
39 {'\00', 'A', 'D', 'M', '\x51', '\x21' },
40 {'\00', 'A', 'D', 'M', '\x51', '\x22' },
41 {'\00', 'A', 'D', 'M', '\x51', '\x23' },
42 {'\00', 'A', 'D', 'M', '\x51', '\x24' },
43 {'\00', 'A', 'D', 'M', '\x51', '\x25' }
45 EXPORT_SYMBOL_GPL(adm5120_eth_macs);
47 unsigned char adm5120_eth_vlans[6] = {
48 0x41, 0x42, 0x44, 0x48, 0x50, 0x60
50 EXPORT_SYMBOL_GPL(adm5120_eth_vlans);
53 void __init adm5120_setup_eth_macs(u8 *mac_base)
58 t = ((u32) mac_base[3] << 16) | ((u32) mac_base[4] << 8)
59 | ((u32) mac_base[5]);
61 for (i = 0; i < ARRAY_SIZE(adm5120_eth_macs); i++) {
62 for (j = 0; j < 3; j++)
63 adm5120_eth_macs[i][j] = mac_base[j];
65 adm5120_eth_macs[i][3] = (t >> 16) & 0xff;
66 adm5120_eth_macs[i][4] = (t >> 8) & 0xff;
67 adm5120_eth_macs[i][5] = t & 0xff;
74 * Built-in ethernet switch
76 struct resource adm5120_switch_resources[] = {
78 .start = ADM5120_SWITCH_BASE,
79 .end = ADM5120_SWITCH_BASE+ADM5120_SWITCH_SIZE-1,
80 .flags = IORESOURCE_MEM,
83 .start = ADM5120_IRQ_SWITCH,
84 .end = ADM5120_IRQ_SWITCH,
85 .flags = IORESOURCE_IRQ,
89 struct adm5120_switch_platform_data adm5120_switch_data;
90 struct platform_device adm5120_switch_device = {
91 .name = "adm5120-switch",
93 .num_resources = ARRAY_SIZE(adm5120_switch_resources),
94 .resource = adm5120_switch_resources,
95 .dev.platform_data = &adm5120_switch_data,
98 void __init adm5120_add_device_switch(unsigned num_ports, u8 *vlan_map)
101 adm5120_eth_num_ports = num_ports;
104 memcpy(adm5120_eth_vlans, vlan_map, sizeof(adm5120_eth_vlans));
106 platform_device_register(&adm5120_switch_device);
110 * USB Host Controller
112 struct resource adm5120_hcd_resources[] = {
114 .start = ADM5120_USBC_BASE,
115 .end = ADM5120_USBC_BASE+ADM5120_USBC_SIZE-1,
116 .flags = IORESOURCE_MEM,
119 .start = ADM5120_IRQ_USBC,
120 .end = ADM5120_IRQ_USBC,
121 .flags = IORESOURCE_IRQ,
125 static u64 adm5120_hcd_dma_mask = DMA_BIT_MASK(24);
126 struct platform_device adm5120_hcd_device = {
127 .name = "adm5120-hcd",
129 .num_resources = ARRAY_SIZE(adm5120_hcd_resources),
130 .resource = adm5120_hcd_resources,
132 .dma_mask = &adm5120_hcd_dma_mask,
133 .coherent_dma_mask = DMA_BIT_MASK(24),
137 void __init adm5120_add_device_usb(void)
139 platform_device_register(&adm5120_hcd_device);
145 struct adm5120_flash_platform_data adm5120_flash0_data;
146 struct platform_device adm5120_flash0_device = {
147 .name = "adm5120-flash",
149 .dev.platform_data = &adm5120_flash0_data,
152 struct adm5120_flash_platform_data adm5120_flash1_data;
153 struct platform_device adm5120_flash1_device = {
154 .name = "adm5120-flash",
156 .dev.platform_data = &adm5120_flash1_data,
159 void __init adm5120_add_device_flash(unsigned id)
161 struct platform_device *pdev;
165 pdev = &adm5120_flash0_device;
168 pdev = &adm5120_flash1_device;
176 platform_device_register(pdev);
182 static void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base,
187 struct amba_pl010_data adm5120_uart0_data = {
188 .set_mctrl = adm5120_uart_set_mctrl
191 struct amba_device adm5120_uart0_device = {
193 .bus_id = "APB:UART0",
194 .platform_data = &adm5120_uart0_data,
197 .start = ADM5120_UART0_BASE,
198 .end = ADM5120_UART0_BASE + ADM5120_UART_SIZE - 1,
199 .flags = IORESOURCE_MEM,
201 .irq = { ADM5120_IRQ_UART0, -1 },
202 .periphid = 0x0041010,
205 struct amba_pl010_data adm5120_uart1_data = {
206 .set_mctrl = adm5120_uart_set_mctrl
209 struct amba_device adm5120_uart1_device = {
211 .bus_id = "APB:UART1",
212 .platform_data = &adm5120_uart1_data,
215 .start = ADM5120_UART1_BASE,
216 .end = ADM5120_UART1_BASE + ADM5120_UART_SIZE - 1,
217 .flags = IORESOURCE_MEM,
219 .irq = { ADM5120_IRQ_UART1, -1 },
220 .periphid = 0x0041010,
223 void __init adm5120_add_device_uart(unsigned id)
225 struct amba_device *dev;
229 dev = &adm5120_uart0_device;
232 dev = &adm5120_uart1_device;
240 amba_device_register(dev, &iomem_resource);
246 #define ADM5120_BUTTON_INTERVAL 20
247 struct gpio_buttons_platform_data adm5120_gpio_buttons_data = {
248 .poll_interval = ADM5120_BUTTON_INTERVAL,
251 struct platform_device adm5120_gpio_buttons_device = {
252 .name = "gpio-buttons",
254 .dev.platform_data = &adm5120_gpio_buttons_data,
257 void __init adm5120_add_device_gpio_buttons(unsigned nbuttons,
258 struct gpio_button *buttons)
260 struct gpio_button *p;
262 p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
266 memcpy(p, buttons, nbuttons * sizeof(*p));
267 adm5120_gpio_buttons_data.nbuttons = nbuttons;
268 adm5120_gpio_buttons_data.buttons = p;
270 platform_device_register(&adm5120_gpio_buttons_device);
276 struct gpio_led_platform_data adm5120_gpio_leds_data;
277 struct platform_device adm5120_gpio_leds_device = {
280 .dev.platform_data = &adm5120_gpio_leds_data,
283 void __init adm5120_add_device_gpio_leds(unsigned num_leds,
284 struct gpio_led *leds)
288 p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
292 memcpy(p, leds, num_leds * sizeof(*p));
293 adm5120_gpio_leds_data.num_leds = num_leds;
294 adm5120_gpio_leds_data.leds = p;
296 platform_device_register(&adm5120_gpio_leds_device);
302 static struct resource adm5120_gpio_resource[] __initdata = {
308 void __init adm5120_add_device_gpio(u32 disable_mask)
310 if (adm5120_package_pqfp())
311 disable_mask |= 0xf0;
313 adm5120_gpio_resource[0].start &= ~disable_mask;
314 platform_device_register_simple("GPIODEV", -1,
315 adm5120_gpio_resource,
316 ARRAY_SIZE(adm5120_gpio_resource));
322 struct resource adm5120_nand_resources[] = {
324 .start = ADM5120_NAND_BASE,
325 .end = ADM5120_NAND_BASE + ADM5120_NAND_SIZE-1,
326 .flags = IORESOURCE_MEM,
330 static int adm5120_nand_ready(struct mtd_info *mtd)
332 return ((adm5120_nand_get_status() & ADM5120_NAND_STATUS_READY) != 0);
335 static void adm5120_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
338 if (ctrl & NAND_CTRL_CHANGE) {
339 adm5120_nand_set_cle(ctrl & NAND_CLE);
340 adm5120_nand_set_ale(ctrl & NAND_ALE);
341 adm5120_nand_set_cen(ctrl & NAND_NCE);
344 if (cmd != NAND_CMD_NONE)
345 NAND_WRITE_REG(NAND_REG_DATA, cmd);
348 void __init adm5120_add_device_nand(struct platform_nand_data *pdata)
350 struct platform_device *pdev;
353 pdev = platform_device_alloc("gen_nand", -1);
357 err = platform_device_add_resources(pdev, adm5120_nand_resources,
358 ARRAY_SIZE(adm5120_nand_resources));
362 err = platform_device_add_data(pdev, pdata, sizeof(*pdata));
366 pdata = pdev->dev.platform_data;
367 pdata->ctrl.dev_ready = adm5120_nand_ready;
368 pdata->ctrl.cmd_ctrl = adm5120_nand_cmd_ctrl;
370 err = platform_device_add(pdev);
377 platform_device_put(pdev);