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
);
54 * Built-in ethernet switch
56 struct resource adm5120_switch_resources
[] = {
58 .start
= ADM5120_SWITCH_BASE
,
59 .end
= ADM5120_SWITCH_BASE
+ADM5120_SWITCH_SIZE
-1,
60 .flags
= IORESOURCE_MEM
,
63 .start
= ADM5120_IRQ_SWITCH
,
64 .end
= ADM5120_IRQ_SWITCH
,
65 .flags
= IORESOURCE_IRQ
,
69 struct adm5120_switch_platform_data adm5120_switch_data
;
70 struct platform_device adm5120_switch_device
= {
71 .name
= "adm5120-switch",
73 .num_resources
= ARRAY_SIZE(adm5120_switch_resources
),
74 .resource
= adm5120_switch_resources
,
75 .dev
.platform_data
= &adm5120_switch_data
,
78 void __init
adm5120_add_device_switch(unsigned num_ports
, u8
*vlan_map
)
81 adm5120_eth_num_ports
= num_ports
;
84 memcpy(adm5120_eth_vlans
, vlan_map
, sizeof(adm5120_eth_vlans
));
86 platform_device_register(&adm5120_switch_device
);
92 struct resource adm5120_hcd_resources
[] = {
94 .start
= ADM5120_USBC_BASE
,
95 .end
= ADM5120_USBC_BASE
+ADM5120_USBC_SIZE
-1,
96 .flags
= IORESOURCE_MEM
,
99 .start
= ADM5120_IRQ_USBC
,
100 .end
= ADM5120_IRQ_USBC
,
101 .flags
= IORESOURCE_IRQ
,
105 static u64 adm5120_hcd_dma_mask
= DMA_BIT_MASK(24);
106 struct platform_device adm5120_hcd_device
= {
107 .name
= "adm5120-hcd",
109 .num_resources
= ARRAY_SIZE(adm5120_hcd_resources
),
110 .resource
= adm5120_hcd_resources
,
112 .dma_mask
= &adm5120_hcd_dma_mask
,
113 .coherent_dma_mask
= DMA_BIT_MASK(24),
117 void __init
adm5120_add_device_usb(void)
119 platform_device_register(&adm5120_hcd_device
);
125 struct adm5120_flash_platform_data adm5120_flash0_data
;
126 struct platform_device adm5120_flash0_device
= {
127 .name
= "adm5120-flash",
129 .dev
.platform_data
= &adm5120_flash0_data
,
132 struct adm5120_flash_platform_data adm5120_flash1_data
;
133 struct platform_device adm5120_flash1_device
= {
134 .name
= "adm5120-flash",
136 .dev
.platform_data
= &adm5120_flash1_data
,
139 void __init
adm5120_add_device_flash(unsigned id
)
141 struct platform_device
*pdev
;
145 pdev
= &adm5120_flash0_device
;
148 pdev
= &adm5120_flash1_device
;
156 platform_device_register(pdev
);
162 static void adm5120_uart_set_mctrl(struct amba_device
*dev
, void __iomem
*base
,
167 struct amba_pl010_data adm5120_uart0_data
= {
168 .set_mctrl
= adm5120_uart_set_mctrl
171 struct amba_device adm5120_uart0_device
= {
173 .bus_id
= "APB:UART0",
174 .platform_data
= &adm5120_uart0_data
,
177 .start
= ADM5120_UART0_BASE
,
178 .end
= ADM5120_UART0_BASE
+ ADM5120_UART_SIZE
- 1,
179 .flags
= IORESOURCE_MEM
,
181 .irq
= { ADM5120_IRQ_UART0
, -1 },
182 .periphid
= 0x0041010,
185 struct amba_pl010_data adm5120_uart1_data
= {
186 .set_mctrl
= adm5120_uart_set_mctrl
189 struct amba_device adm5120_uart1_device
= {
191 .bus_id
= "APB:UART1",
192 .platform_data
= &adm5120_uart1_data
,
195 .start
= ADM5120_UART1_BASE
,
196 .end
= ADM5120_UART1_BASE
+ ADM5120_UART_SIZE
- 1,
197 .flags
= IORESOURCE_MEM
,
199 .irq
= { ADM5120_IRQ_UART1
, -1 },
200 .periphid
= 0x0041010,
203 void __init
adm5120_add_device_uart(unsigned id
)
205 struct amba_device
*dev
;
209 dev
= &adm5120_uart0_device
;
212 dev
= &adm5120_uart1_device
;
220 amba_device_register(dev
, &iomem_resource
);
226 #define ADM5120_BUTTON_INTERVAL 20
227 struct gpio_buttons_platform_data adm5120_gpio_buttons_data
= {
228 .poll_interval
= ADM5120_BUTTON_INTERVAL
,
231 struct platform_device adm5120_gpio_buttons_device
= {
232 .name
= "gpio-buttons",
234 .dev
.platform_data
= &adm5120_gpio_buttons_data
,
237 void __init
adm5120_add_device_gpio_buttons(unsigned nbuttons
,
238 struct gpio_button
*buttons
)
240 struct gpio_button
*p
;
242 p
= kmalloc(nbuttons
* sizeof(*p
), GFP_KERNEL
);
246 memcpy(p
, buttons
, nbuttons
* sizeof(*p
));
247 adm5120_gpio_buttons_data
.nbuttons
= nbuttons
;
248 adm5120_gpio_buttons_data
.buttons
= p
;
250 platform_device_register(&adm5120_gpio_buttons_device
);
256 struct gpio_led_platform_data adm5120_gpio_leds_data
;
257 struct platform_device adm5120_gpio_leds_device
= {
260 .dev
.platform_data
= &adm5120_gpio_leds_data
,
263 void __init
adm5120_add_device_gpio_leds(unsigned num_leds
,
264 struct gpio_led
*leds
)
268 p
= kmalloc(num_leds
* sizeof(*p
), GFP_KERNEL
);
272 memcpy(p
, leds
, num_leds
* sizeof(*p
));
273 adm5120_gpio_leds_data
.num_leds
= num_leds
;
274 adm5120_gpio_leds_data
.leds
= p
;
276 platform_device_register(&adm5120_gpio_leds_device
);
282 static struct resource adm5120_gpio_resource
[] __initdata
= {
288 void __init
adm5120_add_device_gpio(u32 disable_mask
)
290 if (adm5120_package_pqfp())
291 disable_mask
|= 0xf0;
293 adm5120_gpio_resource
[0].start
&= ~disable_mask
;
294 platform_device_register_simple("GPIODEV", -1,
295 adm5120_gpio_resource
,
296 ARRAY_SIZE(adm5120_gpio_resource
));
302 struct resource adm5120_nand_resources
[] = {
304 .start
= ADM5120_NAND_BASE
,
305 .end
= ADM5120_NAND_BASE
+ ADM5120_NAND_SIZE
-1,
306 .flags
= IORESOURCE_MEM
,
310 static int adm5120_nand_ready(struct mtd_info
*mtd
)
312 return ((adm5120_nand_get_status() & ADM5120_NAND_STATUS_READY
) != 0);
315 static void adm5120_nand_cmd_ctrl(struct mtd_info
*mtd
, int cmd
,
318 if (ctrl
& NAND_CTRL_CHANGE
) {
319 adm5120_nand_set_cle(ctrl
& NAND_CLE
);
320 adm5120_nand_set_ale(ctrl
& NAND_ALE
);
321 adm5120_nand_set_cen(ctrl
& NAND_NCE
);
324 if (cmd
!= NAND_CMD_NONE
)
325 NAND_WRITE_REG(NAND_REG_DATA
, cmd
);
328 void __init
adm5120_add_device_nand(struct platform_nand_data
*pdata
)
330 struct platform_device
*pdev
;
333 pdev
= platform_device_alloc("gen_nand", -1);
337 err
= platform_device_add_resources(pdev
, adm5120_nand_resources
,
338 ARRAY_SIZE(adm5120_nand_resources
));
342 err
= platform_device_add_data(pdev
, pdata
, sizeof(*pdata
));
346 pdata
= pdev
->dev
.platform_data
;
347 pdata
->ctrl
.dev_ready
= adm5120_nand_ready
;
348 pdata
->ctrl
.cmd_ctrl
= adm5120_nand_cmd_ctrl
;
350 err
= platform_device_add(pdev
);
357 platform_device_put(pdev
);