adm5120: fix build error on 2.6.34
[openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / common / platform.c
1 /*
2  *  ADM5120 generic platform devices
3  *
4  *  Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
5  *
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.
9  *
10  */
11
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
22 #include <asm/bootinfo.h>
23
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>
29
30 #if 1
31 /*
32  * TODO:remove global adm5120_eth* variables when the switch driver will be
33  *      converted into a real platform driver
34  */
35 unsigned int adm5120_eth_num_ports = 6;
36 EXPORT_SYMBOL_GPL(adm5120_eth_num_ports);
37
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' }
45 };
46 EXPORT_SYMBOL_GPL(adm5120_eth_macs);
47
48 unsigned char adm5120_eth_vlans[6] = {
49         0x41, 0x42, 0x44, 0x48, 0x50, 0x60
50 };
51 EXPORT_SYMBOL_GPL(adm5120_eth_vlans);
52 #endif
53
54 void __init adm5120_setup_eth_macs(u8 *mac_base)
55 {
56         u32 t;
57         int i, j;
58
59         t = ((u32) mac_base[3] << 16) | ((u32) mac_base[4] << 8)
60                 | ((u32) mac_base[5]);
61
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];
65
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;
69
70                 t++;
71         }
72 }
73
74 /*
75  * Built-in ethernet switch
76  */
77 struct resource adm5120_switch_resources[] = {
78         [0] = {
79                 .start  = ADM5120_SWITCH_BASE,
80                 .end    = ADM5120_SWITCH_BASE+ADM5120_SWITCH_SIZE-1,
81                 .flags  = IORESOURCE_MEM,
82         },
83         [1] = {
84                 .start  = ADM5120_IRQ_SWITCH,
85                 .end    = ADM5120_IRQ_SWITCH,
86                 .flags  = IORESOURCE_IRQ,
87         },
88 };
89
90 struct adm5120_switch_platform_data adm5120_switch_data;
91 struct platform_device adm5120_switch_device = {
92         .name           = "adm5120-switch",
93         .id             = -1,
94         .num_resources  = ARRAY_SIZE(adm5120_switch_resources),
95         .resource       = adm5120_switch_resources,
96         .dev.platform_data = &adm5120_switch_data,
97 };
98
99 void __init adm5120_add_device_switch(unsigned num_ports, u8 *vlan_map)
100 {
101         if (num_ports > 0)
102                 adm5120_eth_num_ports = num_ports;
103
104         if (vlan_map)
105                 memcpy(adm5120_eth_vlans, vlan_map, sizeof(adm5120_eth_vlans));
106
107         platform_device_register(&adm5120_switch_device);
108 }
109
110 /*
111  * USB Host Controller
112  */
113 struct resource adm5120_hcd_resources[] = {
114         [0] = {
115                 .start  = ADM5120_USBC_BASE,
116                 .end    = ADM5120_USBC_BASE+ADM5120_USBC_SIZE-1,
117                 .flags  = IORESOURCE_MEM,
118         },
119         [1] = {
120                 .start  = ADM5120_IRQ_USBC,
121                 .end    = ADM5120_IRQ_USBC,
122                 .flags  = IORESOURCE_IRQ,
123         },
124 };
125
126 static u64 adm5120_hcd_dma_mask = DMA_BIT_MASK(24);
127 struct platform_device adm5120_hcd_device = {
128         .name           = "adm5120-hcd",
129         .id             = -1,
130         .num_resources  = ARRAY_SIZE(adm5120_hcd_resources),
131         .resource       = adm5120_hcd_resources,
132         .dev = {
133                 .dma_mask               = &adm5120_hcd_dma_mask,
134                 .coherent_dma_mask      = DMA_BIT_MASK(24),
135         }
136 };
137
138 void __init adm5120_add_device_usb(void)
139 {
140         platform_device_register(&adm5120_hcd_device);
141 }
142
143 /*
144  * NOR flash devices
145  */
146 struct adm5120_flash_platform_data adm5120_flash0_data;
147 struct platform_device adm5120_flash0_device =  {
148         .name                   = "adm5120-flash",
149         .id                     = 0,
150         .dev.platform_data      = &adm5120_flash0_data,
151 };
152
153 struct adm5120_flash_platform_data adm5120_flash1_data;
154 struct platform_device adm5120_flash1_device =  {
155         .name                   = "adm5120-flash",
156         .id                     = 1,
157         .dev.platform_data      = &adm5120_flash1_data,
158 };
159
160 void __init adm5120_add_device_flash(unsigned id)
161 {
162         struct platform_device *pdev;
163
164         switch (id) {
165         case 0:
166                 pdev = &adm5120_flash0_device;
167                 break;
168         case 1:
169                 pdev = &adm5120_flash1_device;
170                 break;
171         default:
172                 pdev = NULL;
173                 break;
174         }
175
176         if (pdev)
177                 platform_device_register(pdev);
178 }
179
180 /*
181  * built-in UARTs
182  */
183 static void adm5120_uart_set_mctrl(struct amba_device *dev, void __iomem *base,
184                 unsigned int mctrl)
185 {
186 }
187
188 struct amba_pl010_data adm5120_uart0_data = {
189         .set_mctrl = adm5120_uart_set_mctrl
190 };
191
192 struct amba_device adm5120_uart0_device = {
193         .dev            = {
194                 .init_name = "apb:uart0",
195                 .platform_data = &adm5120_uart0_data,
196         },
197         .res            = {
198                 .start  = ADM5120_UART0_BASE,
199                 .end    = ADM5120_UART0_BASE + ADM5120_UART_SIZE - 1,
200                 .flags  = IORESOURCE_MEM,
201         },
202         .irq            = { ADM5120_IRQ_UART0, -1 },
203         .periphid       = 0x0041010,
204 };
205
206 struct amba_pl010_data adm5120_uart1_data = {
207         .set_mctrl = adm5120_uart_set_mctrl
208 };
209
210 struct amba_device adm5120_uart1_device = {
211         .dev            = {
212                 .init_name = "apb:uart1",
213                 .platform_data = &adm5120_uart1_data,
214         },
215         .res            = {
216                 .start  = ADM5120_UART1_BASE,
217                 .end    = ADM5120_UART1_BASE + ADM5120_UART_SIZE - 1,
218                 .flags  = IORESOURCE_MEM,
219         },
220         .irq            = { ADM5120_IRQ_UART1, -1 },
221         .periphid       = 0x0041010,
222 };
223
224 void __init adm5120_add_device_uart(unsigned id)
225 {
226         struct amba_device *dev;
227
228         switch (id) {
229         case 0:
230                 dev = &adm5120_uart0_device;
231                 break;
232         case 1:
233                 dev = &adm5120_uart1_device;
234                 break;
235         default:
236                 dev = NULL;
237                 break;
238         }
239
240         if (dev)
241                 amba_device_register(dev, &iomem_resource);
242 }
243
244 /*
245  * GPIO buttons
246  */
247 #define ADM5120_BUTTON_INTERVAL 20
248 struct gpio_buttons_platform_data adm5120_gpio_buttons_data = {
249         .poll_interval  = ADM5120_BUTTON_INTERVAL,
250 };
251
252 struct platform_device adm5120_gpio_buttons_device = {
253         .name           = "gpio-buttons",
254         .id             = -1,
255         .dev.platform_data = &adm5120_gpio_buttons_data,
256 };
257
258 void __init adm5120_add_device_gpio_buttons(unsigned nbuttons,
259                                     struct gpio_button *buttons)
260 {
261         struct gpio_button *p;
262
263         p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
264         if (!p)
265                 return;
266
267         memcpy(p, buttons, nbuttons * sizeof(*p));
268         adm5120_gpio_buttons_data.nbuttons = nbuttons;
269         adm5120_gpio_buttons_data.buttons = p;
270
271         platform_device_register(&adm5120_gpio_buttons_device);
272 }
273
274 /*
275  * GPIO LEDS
276  */
277 struct gpio_led_platform_data adm5120_gpio_leds_data;
278 struct platform_device adm5120_gpio_leds_device = {
279         .name           = "leds-gpio",
280         .id             = -1,
281         .dev.platform_data = &adm5120_gpio_leds_data,
282 };
283
284 void __init adm5120_add_device_gpio_leds(unsigned num_leds,
285                                     struct gpio_led *leds)
286 {
287         struct gpio_led *p;
288
289         p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
290         if (!p)
291                 return;
292
293         memcpy(p, leds, num_leds * sizeof(*p));
294         adm5120_gpio_leds_data.num_leds = num_leds;
295         adm5120_gpio_leds_data.leds = p;
296
297         platform_device_register(&adm5120_gpio_leds_device);
298 }
299
300 /*
301  * GPIO device
302  */
303 static struct resource adm5120_gpio_resource[] __initdata = {
304         {
305                 .start  = 0x3fffff,
306         },
307 };
308
309 void __init adm5120_add_device_gpio(u32 disable_mask)
310 {
311         if (adm5120_package_pqfp())
312                 disable_mask |= 0xf0;
313
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));
318 }
319
320 /*
321  * NAND flash
322  */
323 struct resource adm5120_nand_resources[] = {
324         [0] = {
325                 .start  = ADM5120_NAND_BASE,
326                 .end    = ADM5120_NAND_BASE + ADM5120_NAND_SIZE-1,
327                 .flags  = IORESOURCE_MEM,
328         },
329 };
330
331 static int adm5120_nand_ready(struct mtd_info *mtd)
332 {
333         return ((adm5120_nand_get_status() & ADM5120_NAND_STATUS_READY) != 0);
334 }
335
336 static void adm5120_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
337                                         unsigned int ctrl)
338 {
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);
343         }
344
345         if (cmd != NAND_CMD_NONE)
346                 NAND_WRITE_REG(NAND_REG_DATA, cmd);
347 }
348
349 void __init adm5120_add_device_nand(struct platform_nand_data *pdata)
350 {
351         struct platform_device *pdev;
352         int err;
353
354         pdev = platform_device_alloc("gen_nand", -1);
355         if (!pdev)
356                 goto err_out;
357
358         err = platform_device_add_resources(pdev, adm5120_nand_resources,
359                                         ARRAY_SIZE(adm5120_nand_resources));
360         if (err)
361                 goto err_put;
362
363         err = platform_device_add_data(pdev, pdata, sizeof(*pdata));
364         if (err)
365                 goto err_put;
366
367         pdata = pdev->dev.platform_data;
368         pdata->ctrl.dev_ready = adm5120_nand_ready;
369         pdata->ctrl.cmd_ctrl = adm5120_nand_cmd_ctrl;
370
371         err = platform_device_add(pdev);
372         if (err)
373                 goto err_put;
374
375         return;
376
377 err_put:
378         platform_device_put(pdev);
379 err_out:
380         return;
381 }