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>
21 #include <linux/export.h>
23 #include <asm/bootinfo.h>
25 #include <asm/mach-adm5120/adm5120_defs.h>
26 #include <asm/mach-adm5120/adm5120_info.h>
27 #include <asm/mach-adm5120/adm5120_switch.h>
28 #include <asm/mach-adm5120/adm5120_nand.h>
29 #include <asm/mach-adm5120/adm5120_platform.h>
33 * TODO:remove global adm5120_eth* variables when the switch driver will be
34 * converted into a real platform driver
36 unsigned int adm5120_eth_num_ports = 6;
37 EXPORT_SYMBOL_GPL(adm5120_eth_num_ports);
39 unsigned char adm5120_eth_macs[6][6] = {
40 {'\00', 'A', 'D', 'M', '\x51', '\x20' },
41 {'\00', 'A', 'D', 'M', '\x51', '\x21' },
42 {'\00', 'A', 'D', 'M', '\x51', '\x22' },
43 {'\00', 'A', 'D', 'M', '\x51', '\x23' },
44 {'\00', 'A', 'D', 'M', '\x51', '\x24' },
45 {'\00', 'A', 'D', 'M', '\x51', '\x25' }
47 EXPORT_SYMBOL_GPL(adm5120_eth_macs);
49 unsigned char adm5120_eth_vlans[6] = {
50 0x41, 0x42, 0x44, 0x48, 0x50, 0x60
52 EXPORT_SYMBOL_GPL(adm5120_eth_vlans);
55 void __init adm5120_setup_eth_macs(u8 *mac_base)
60 t = ((u32) mac_base[3] << 16) | ((u32) mac_base[4] << 8)
61 | ((u32) mac_base[5]);
63 for (i = 0; i < ARRAY_SIZE(adm5120_eth_macs); i++) {
64 for (j = 0; j < 3; j++)
65 adm5120_eth_macs[i][j] = mac_base[j];
67 adm5120_eth_macs[i][3] = (t >> 16) & 0xff;
68 adm5120_eth_macs[i][4] = (t >> 8) & 0xff;
69 adm5120_eth_macs[i][5] = t & 0xff;
76 * Built-in ethernet switch
78 struct resource adm5120_switch_resources[] = {
80 .start = ADM5120_SWITCH_BASE,
81 .end = ADM5120_SWITCH_BASE+ADM5120_SWITCH_SIZE-1,
82 .flags = IORESOURCE_MEM,
85 .start = ADM5120_IRQ_SWITCH,
86 .end = ADM5120_IRQ_SWITCH,
87 .flags = IORESOURCE_IRQ,
91 struct adm5120_switch_platform_data adm5120_switch_data;
92 struct platform_device adm5120_switch_device = {
93 .name = "adm5120-switch",
95 .num_resources = ARRAY_SIZE(adm5120_switch_resources),
96 .resource = adm5120_switch_resources,
97 .dev.platform_data = &adm5120_switch_data,
100 void __init adm5120_add_device_switch(unsigned num_ports, u8 *vlan_map)
103 adm5120_eth_num_ports = num_ports;
106 memcpy(adm5120_eth_vlans, vlan_map, sizeof(adm5120_eth_vlans));
108 platform_device_register(&adm5120_switch_device);
112 * USB Host Controller
114 struct resource adm5120_hcd_resources[] = {
116 .start = ADM5120_USBC_BASE,
117 .end = ADM5120_USBC_BASE+ADM5120_USBC_SIZE-1,
118 .flags = IORESOURCE_MEM,
121 .start = ADM5120_IRQ_USBC,
122 .end = ADM5120_IRQ_USBC,
123 .flags = IORESOURCE_IRQ,
127 static u64 adm5120_hcd_dma_mask = DMA_BIT_MASK(24);
128 struct platform_device adm5120_hcd_device = {
129 .name = "adm5120-hcd",
131 .num_resources = ARRAY_SIZE(adm5120_hcd_resources),
132 .resource = adm5120_hcd_resources,
134 .dma_mask = &adm5120_hcd_dma_mask,
135 .coherent_dma_mask = DMA_BIT_MASK(24),
139 void __init adm5120_add_device_usb(void)
141 platform_device_register(&adm5120_hcd_device);
147 struct adm5120_flash_platform_data adm5120_flash0_data;
148 struct platform_device adm5120_flash0_device = {
149 .name = "adm5120-flash",
151 .dev.platform_data = &adm5120_flash0_data,
154 struct adm5120_flash_platform_data adm5120_flash1_data;
155 struct platform_device adm5120_flash1_device = {
156 .name = "adm5120-flash",
158 .dev.platform_data = &adm5120_flash1_data,
161 void __init adm5120_add_device_flash(unsigned id)
163 struct platform_device *pdev;
167 pdev = &adm5120_flash0_device;
170 pdev = &adm5120_flash1_device;
178 platform_device_register(pdev);
184 static void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base,
189 struct amba_pl010_data adm5120_uart0_data = {
190 .set_mctrl = adm5120_uart_set_mctrl
193 struct amba_device adm5120_uart0_device = {
195 .init_name = "apb:uart0",
196 .platform_data = &adm5120_uart0_data,
199 .start = ADM5120_UART0_BASE,
200 .end = ADM5120_UART0_BASE + ADM5120_UART_SIZE - 1,
201 .flags = IORESOURCE_MEM,
203 .irq = { ADM5120_IRQ_UART0, 0 },
204 .periphid = 0x0041010,
207 struct amba_pl010_data adm5120_uart1_data = {
208 .set_mctrl = adm5120_uart_set_mctrl
211 struct amba_device adm5120_uart1_device = {
213 .init_name = "apb:uart1",
214 .platform_data = &adm5120_uart1_data,
217 .start = ADM5120_UART1_BASE,
218 .end = ADM5120_UART1_BASE + ADM5120_UART_SIZE - 1,
219 .flags = IORESOURCE_MEM,
221 .irq = { ADM5120_IRQ_UART1, 0 },
222 .periphid = 0x0041010,
225 void __init adm5120_add_device_uart(unsigned id)
227 struct amba_device *dev;
231 dev = &adm5120_uart0_device;
234 dev = &adm5120_uart1_device;
242 amba_device_register(dev, &iomem_resource);
248 void __init adm5120_register_gpio_buttons(int id,
249 unsigned poll_interval,
251 struct gpio_keys_button *buttons)
253 struct platform_device *pdev;
254 struct gpio_keys_platform_data pdata;
255 struct gpio_keys_button *p;
258 p = kmemdup(buttons, nbuttons * sizeof(*p), GFP_KERNEL);
262 pdev = platform_device_alloc("gpio-keys-polled", id);
264 goto err_free_buttons;
266 memset(&pdata, 0, sizeof(pdata));
267 pdata.poll_interval = poll_interval;
268 pdata.nbuttons = nbuttons;
271 err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
275 err = platform_device_add(pdev);
282 platform_device_put(pdev);
291 struct gpio_led_platform_data adm5120_gpio_leds_data;
292 struct platform_device adm5120_gpio_leds_device = {
295 .dev.platform_data = &adm5120_gpio_leds_data,
298 void __init adm5120_add_device_gpio_leds(unsigned num_leds,
299 struct gpio_led *leds)
303 p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
307 memcpy(p, leds, num_leds * sizeof(*p));
308 adm5120_gpio_leds_data.num_leds = num_leds;
309 adm5120_gpio_leds_data.leds = p;
311 platform_device_register(&adm5120_gpio_leds_device);
317 struct resource adm5120_nand_resources[] = {
319 .start = ADM5120_NAND_BASE,
320 .end = ADM5120_NAND_BASE + ADM5120_NAND_SIZE-1,
321 .flags = IORESOURCE_MEM,
325 static int adm5120_nand_ready(struct mtd_info *mtd)
327 return ((adm5120_nand_get_status() & ADM5120_NAND_STATUS_READY) != 0);
330 static void adm5120_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
333 if (ctrl & NAND_CTRL_CHANGE) {
334 adm5120_nand_set_cle(ctrl & NAND_CLE);
335 adm5120_nand_set_ale(ctrl & NAND_ALE);
336 adm5120_nand_set_cen(ctrl & NAND_NCE);
339 if (cmd != NAND_CMD_NONE)
340 NAND_WRITE_REG(NAND_REG_DATA, cmd);
343 void __init adm5120_add_device_nand(struct platform_nand_data *pdata)
345 struct platform_device *pdev;
348 pdev = platform_device_alloc("gen_nand", -1);
352 err = platform_device_add_resources(pdev, adm5120_nand_resources,
353 ARRAY_SIZE(adm5120_nand_resources));
357 err = platform_device_add_data(pdev, pdata, sizeof(*pdata));
361 pdata = pdev->dev.platform_data;
362 pdata->ctrl.dev_ready = adm5120_nand_ready;
363 pdata->ctrl.cmd_ctrl = adm5120_nand_cmd_ctrl;
365 err = platform_device_add(pdev);
372 platform_device_put(pdev);