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>
19 #include <linux/irq.h>
20 #include <linux/slab.h>
22 #include <asm/bootinfo.h>
24 #include <asm/mach-adm5120/adm5120_defs.h>
25 #include <asm/mach-adm5120/adm5120_info.h>
26 #include <asm/mach-adm5120/adm5120_switch.h>
27 #include <asm/mach-adm5120/adm5120_nand.h>
28 #include <asm/mach-adm5120/adm5120_platform.h>
32 * TODO:remove global adm5120_eth* variables when the switch driver will be
33 * converted into a real platform driver
35 unsigned int adm5120_eth_num_ports = 6;
36 EXPORT_SYMBOL_GPL(adm5120_eth_num_ports);
38 unsigned char adm5120_eth_macs[6][6] = {
39 {'\00', 'A', 'D', 'M', '\x51', '\x20' },
40 {'\00', 'A', 'D', 'M', '\x51', '\x21' },
41 {'\00', 'A', 'D', 'M', '\x51', '\x22' },
42 {'\00', 'A', 'D', 'M', '\x51', '\x23' },
43 {'\00', 'A', 'D', 'M', '\x51', '\x24' },
44 {'\00', 'A', 'D', 'M', '\x51', '\x25' }
46 EXPORT_SYMBOL_GPL(adm5120_eth_macs);
48 unsigned char adm5120_eth_vlans[6] = {
49 0x41, 0x42, 0x44, 0x48, 0x50, 0x60
51 EXPORT_SYMBOL_GPL(adm5120_eth_vlans);
54 void __init adm5120_setup_eth_macs(u8 *mac_base)
59 t = ((u32) mac_base[3] << 16) | ((u32) mac_base[4] << 8)
60 | ((u32) mac_base[5]);
62 for (i = 0; i < ARRAY_SIZE(adm5120_eth_macs); i++) {
63 for (j = 0; j < 3; j++)
64 adm5120_eth_macs[i][j] = mac_base[j];
66 adm5120_eth_macs[i][3] = (t >> 16) & 0xff;
67 adm5120_eth_macs[i][4] = (t >> 8) & 0xff;
68 adm5120_eth_macs[i][5] = t & 0xff;
75 * Built-in ethernet switch
77 struct resource adm5120_switch_resources[] = {
79 .start = ADM5120_SWITCH_BASE,
80 .end = ADM5120_SWITCH_BASE+ADM5120_SWITCH_SIZE-1,
81 .flags = IORESOURCE_MEM,
84 .start = ADM5120_IRQ_SWITCH,
85 .end = ADM5120_IRQ_SWITCH,
86 .flags = IORESOURCE_IRQ,
90 struct adm5120_switch_platform_data adm5120_switch_data;
91 struct platform_device adm5120_switch_device = {
92 .name = "adm5120-switch",
94 .num_resources = ARRAY_SIZE(adm5120_switch_resources),
95 .resource = adm5120_switch_resources,
96 .dev.platform_data = &adm5120_switch_data,
99 void __init adm5120_add_device_switch(unsigned num_ports, u8 *vlan_map)
102 adm5120_eth_num_ports = num_ports;
105 memcpy(adm5120_eth_vlans, vlan_map, sizeof(adm5120_eth_vlans));
107 platform_device_register(&adm5120_switch_device);
111 * USB Host Controller
113 struct resource adm5120_hcd_resources[] = {
115 .start = ADM5120_USBC_BASE,
116 .end = ADM5120_USBC_BASE+ADM5120_USBC_SIZE-1,
117 .flags = IORESOURCE_MEM,
120 .start = ADM5120_IRQ_USBC,
121 .end = ADM5120_IRQ_USBC,
122 .flags = IORESOURCE_IRQ,
126 static u64 adm5120_hcd_dma_mask = DMA_BIT_MASK(24);
127 struct platform_device adm5120_hcd_device = {
128 .name = "adm5120-hcd",
130 .num_resources = ARRAY_SIZE(adm5120_hcd_resources),
131 .resource = adm5120_hcd_resources,
133 .dma_mask = &adm5120_hcd_dma_mask,
134 .coherent_dma_mask = DMA_BIT_MASK(24),
138 void __init adm5120_add_device_usb(void)
140 platform_device_register(&adm5120_hcd_device);
146 struct adm5120_flash_platform_data adm5120_flash0_data;
147 struct platform_device adm5120_flash0_device = {
148 .name = "adm5120-flash",
150 .dev.platform_data = &adm5120_flash0_data,
153 struct adm5120_flash_platform_data adm5120_flash1_data;
154 struct platform_device adm5120_flash1_device = {
155 .name = "adm5120-flash",
157 .dev.platform_data = &adm5120_flash1_data,
160 void __init adm5120_add_device_flash(unsigned id)
162 struct platform_device *pdev;
166 pdev = &adm5120_flash0_device;
169 pdev = &adm5120_flash1_device;
177 platform_device_register(pdev);
183 static void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base,
188 struct amba_pl010_data adm5120_uart0_data = {
189 .set_mctrl = adm5120_uart_set_mctrl
192 struct amba_device adm5120_uart0_device = {
194 .init_name = "apb:uart0",
195 .platform_data = &adm5120_uart0_data,
198 .start = ADM5120_UART0_BASE,
199 .end = ADM5120_UART0_BASE + ADM5120_UART_SIZE - 1,
200 .flags = IORESOURCE_MEM,
202 .irq = { ADM5120_IRQ_UART0, -1 },
203 .periphid = 0x0041010,
206 struct amba_pl010_data adm5120_uart1_data = {
207 .set_mctrl = adm5120_uart_set_mctrl
210 struct amba_device adm5120_uart1_device = {
212 .init_name = "apb:uart1",
213 .platform_data = &adm5120_uart1_data,
216 .start = ADM5120_UART1_BASE,
217 .end = ADM5120_UART1_BASE + ADM5120_UART_SIZE - 1,
218 .flags = IORESOURCE_MEM,
220 .irq = { ADM5120_IRQ_UART1, -1 },
221 .periphid = 0x0041010,
224 void __init adm5120_add_device_uart(unsigned id)
226 struct amba_device *dev;
230 dev = &adm5120_uart0_device;
233 dev = &adm5120_uart1_device;
241 amba_device_register(dev, &iomem_resource);
247 #define ADM5120_BUTTON_INTERVAL 20
248 struct gpio_buttons_platform_data adm5120_gpio_buttons_data = {
249 .poll_interval = ADM5120_BUTTON_INTERVAL,
252 struct platform_device adm5120_gpio_buttons_device = {
253 .name = "gpio-buttons",
255 .dev.platform_data = &adm5120_gpio_buttons_data,
258 void __init adm5120_add_device_gpio_buttons(unsigned nbuttons,
259 struct gpio_button *buttons)
261 struct gpio_button *p;
263 p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
267 memcpy(p, buttons, nbuttons * sizeof(*p));
268 adm5120_gpio_buttons_data.nbuttons = nbuttons;
269 adm5120_gpio_buttons_data.buttons = p;
271 platform_device_register(&adm5120_gpio_buttons_device);
277 struct gpio_led_platform_data adm5120_gpio_leds_data;
278 struct platform_device adm5120_gpio_leds_device = {
281 .dev.platform_data = &adm5120_gpio_leds_data,
284 void __init adm5120_add_device_gpio_leds(unsigned num_leds,
285 struct gpio_led *leds)
289 p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
293 memcpy(p, leds, num_leds * sizeof(*p));
294 adm5120_gpio_leds_data.num_leds = num_leds;
295 adm5120_gpio_leds_data.leds = p;
297 platform_device_register(&adm5120_gpio_leds_device);
303 static struct resource adm5120_gpio_resource[] __initdata = {
309 void __init adm5120_add_device_gpio(u32 disable_mask)
311 if (adm5120_package_pqfp())
312 disable_mask |= 0xf0;
314 adm5120_gpio_resource[0].start &= ~disable_mask;
315 platform_device_register_simple("GPIODEV", -1,
316 adm5120_gpio_resource,
317 ARRAY_SIZE(adm5120_gpio_resource));
323 struct resource adm5120_nand_resources[] = {
325 .start = ADM5120_NAND_BASE,
326 .end = ADM5120_NAND_BASE + ADM5120_NAND_SIZE-1,
327 .flags = IORESOURCE_MEM,
331 static int adm5120_nand_ready(struct mtd_info *mtd)
333 return ((adm5120_nand_get_status() & ADM5120_NAND_STATUS_READY) != 0);
336 static void adm5120_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
339 if (ctrl & NAND_CTRL_CHANGE) {
340 adm5120_nand_set_cle(ctrl & NAND_CLE);
341 adm5120_nand_set_ale(ctrl & NAND_ALE);
342 adm5120_nand_set_cen(ctrl & NAND_NCE);
345 if (cmd != NAND_CMD_NONE)
346 NAND_WRITE_REG(NAND_REG_DATA, cmd);
349 void __init adm5120_add_device_nand(struct platform_nand_data *pdata)
351 struct platform_device *pdev;
354 pdev = platform_device_alloc("gen_nand", -1);
358 err = platform_device_add_resources(pdev, adm5120_nand_resources,
359 ARRAY_SIZE(adm5120_nand_resources));
363 err = platform_device_add_data(pdev, pdata, sizeof(*pdata));
367 pdata = pdev->dev.platform_data;
368 pdata->ctrl.dev_ready = adm5120_nand_ready;
369 pdata->ctrl.cmd_ctrl = adm5120_nand_cmd_ctrl;
371 err = platform_device_add(pdev);
378 platform_device_put(pdev);