[ARM] 3393/2: AT91RM9200 LED support
[linux-2.6.git] / arch / arm / mach-at91rm9200 / devices.c
1 /*
2  * arch/arm/mach-at91rm9200/devices.c
3  *
4  *  Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
5  *  Copyright (C) 2005 David Brownell
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  */
13 #include <asm/mach/arch.h>
14 #include <asm/mach/map.h>
15
16 #include <linux/config.h>
17 #include <linux/platform_device.h>
18
19 #include <asm/arch/board.h>
20 #include <asm/arch/pio.h>
21
22
23 /* --------------------------------------------------------------------
24  *  USB Host
25  * -------------------------------------------------------------------- */
26
27 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
28 static u64 ohci_dmamask = 0xffffffffUL;
29 static struct at91_usbh_data usbh_data;
30
31 static struct resource at91rm9200_usbh_resource[] = {
32         [0] = {
33                 .start  = AT91_UHP_BASE,
34                 .end    = AT91_UHP_BASE + SZ_1M -1,
35                 .flags  = IORESOURCE_MEM,
36         },
37         [1] = {
38                 .start  = AT91_ID_UHP,
39                 .end    = AT91_ID_UHP,
40                 .flags  = IORESOURCE_IRQ,
41         },
42 };
43
44 static struct platform_device at91rm9200_usbh_device = {
45         .name           = "at91rm9200-ohci",
46         .id             = -1,
47         .dev            = {
48                                 .dma_mask               = &ohci_dmamask,
49                                 .coherent_dma_mask      = 0xffffffff,
50                                 .platform_data          = &usbh_data,
51         },
52         .resource       = at91rm9200_usbh_resource,
53         .num_resources  = ARRAY_SIZE(at91rm9200_usbh_resource),
54 };
55
56 void __init at91_add_device_usbh(struct at91_usbh_data *data)
57 {
58         if (!data)
59                 return;
60
61         usbh_data = *data;
62         platform_device_register(&at91rm9200_usbh_device);
63 }
64 #else
65 void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
66 #endif
67
68
69 /* --------------------------------------------------------------------
70  *  USB Device (Gadget)
71  * -------------------------------------------------------------------- */
72
73 #ifdef CONFIG_USB_GADGET_AT91
74 static struct at91_udc_data udc_data;
75
76 static struct resource at91_udc_resources[] = {
77         {
78                 .start  = AT91_BASE_UDP,
79                 .end    = AT91_BASE_UDP + SZ_16K - 1,
80                 .flags  = IORESOURCE_MEM,
81         }
82 };
83
84 static struct platform_device at91rm9200_udc_device = {
85         .name           = "at91_udc",
86         .id             = -1,
87         .dev            = {
88                                 .platform_data          = &udc_data,
89         },
90         .resource       = at91_udc_resources,
91         .num_resources  = ARRAY_SIZE(at91_udc_resources),
92 };
93
94 void __init at91_add_device_udc(struct at91_udc_data *data)
95 {
96         if (!data)
97                 return;
98
99         if (data->vbus_pin) {
100                 at91_set_gpio_input(data->vbus_pin, 0);
101                 at91_set_deglitch(data->vbus_pin, 1);
102         }
103         if (data->pullup_pin) {
104                 at91_set_gpio_output(data->pullup_pin, 0);
105                 at91_set_multi_drive(data->pullup_pin, 1);
106         }
107
108         udc_data = *data;
109         platform_device_register(&at91rm9200_udc_device);
110 }
111 #else
112 void __init at91_add_device_udc(struct at91_udc_data *data) {}
113 #endif
114
115
116 /* --------------------------------------------------------------------
117  *  Ethernet
118  * -------------------------------------------------------------------- */
119
120 #if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
121 static u64 eth_dmamask = 0xffffffffUL;
122 static struct at91_eth_data eth_data;
123
124 static struct platform_device at91rm9200_eth_device = {
125         .name           = "at91_ether",
126         .id             = -1,
127         .dev            = {
128                                 .dma_mask               = &eth_dmamask,
129                                 .coherent_dma_mask      = 0xffffffff,
130                                 .platform_data          = &eth_data,
131         },
132         .num_resources  = 0,
133 };
134
135 void __init at91_add_device_eth(struct at91_eth_data *data)
136 {
137         if (!data)
138                 return;
139
140         if (data->phy_irq_pin) {
141                 at91_set_gpio_input(data->phy_irq_pin, 0);
142                 at91_set_deglitch(data->phy_irq_pin, 1);
143         }
144
145         /* Pins used for MII and RMII */
146         at91_set_A_periph(AT91_PIN_PA16, 0);    /* EMDIO */
147         at91_set_A_periph(AT91_PIN_PA15, 0);    /* EMDC */
148         at91_set_A_periph(AT91_PIN_PA14, 0);    /* ERXER */
149         at91_set_A_periph(AT91_PIN_PA13, 0);    /* ERX1 */
150         at91_set_A_periph(AT91_PIN_PA12, 0);    /* ERX0 */
151         at91_set_A_periph(AT91_PIN_PA11, 0);    /* ECRS_ECRSDV */
152         at91_set_A_periph(AT91_PIN_PA10, 0);    /* ETX1 */
153         at91_set_A_periph(AT91_PIN_PA9, 0);     /* ETX0 */
154         at91_set_A_periph(AT91_PIN_PA8, 0);     /* ETXEN */
155         at91_set_A_periph(AT91_PIN_PA7, 0);     /* ETXCK_EREFCK */
156
157         if (!data->is_rmii) {
158                 at91_set_B_periph(AT91_PIN_PB19, 0);    /* ERXCK */
159                 at91_set_B_periph(AT91_PIN_PB18, 0);    /* ECOL */
160                 at91_set_B_periph(AT91_PIN_PB17, 0);    /* ERXDV */
161                 at91_set_B_periph(AT91_PIN_PB16, 0);    /* ERX3 */
162                 at91_set_B_periph(AT91_PIN_PB15, 0);    /* ERX2 */
163                 at91_set_B_periph(AT91_PIN_PB14, 0);    /* ETXER */
164                 at91_set_B_periph(AT91_PIN_PB13, 0);    /* ETX3 */
165                 at91_set_B_periph(AT91_PIN_PB12, 0);    /* ETX2 */
166         }
167
168         eth_data = *data;
169         platform_device_register(&at91rm9200_eth_device);
170 }
171 #else
172 void __init at91_add_device_eth(struct at91_eth_data *data) {}
173 #endif
174
175
176 /* --------------------------------------------------------------------
177  *  Compact Flash / PCMCIA
178  * -------------------------------------------------------------------- */
179
180 #if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
181 static struct at91_cf_data cf_data;
182
183 static struct platform_device at91rm9200_cf_device = {
184         .name           = "at91_cf",
185         .id             = -1,
186         .dev            = {
187                                 .platform_data          = &cf_data,
188         },
189         .num_resources  = 0,
190 };
191
192 void __init at91_add_device_cf(struct at91_cf_data *data)
193 {
194         if (!data)
195                 return;
196
197         /* input/irq */
198         if (data->irq_pin) {
199                 at91_set_gpio_input(data->irq_pin, 1);
200                 at91_set_deglitch(data->irq_pin, 1);
201         }
202         at91_set_gpio_input(data->det_pin, 1);
203         at91_set_deglitch(data->det_pin, 1);
204
205         /* outputs, initially off */
206         if (data->vcc_pin)
207                 at91_set_gpio_output(data->vcc_pin, 0);
208         at91_set_gpio_output(data->rst_pin, 0);
209
210         cf_data = *data;
211         platform_device_register(&at91rm9200_cf_device);
212 }
213 #else
214 void __init at91_add_device_cf(struct at91_cf_data *data) {}
215 #endif
216
217
218 /* --------------------------------------------------------------------
219  *  MMC / SD
220  * -------------------------------------------------------------------- */
221
222 #if defined(CONFIG_MMC_AT91RM9200) || defined(CONFIG_MMC_AT91RM9200_MODULE)
223 static u64 mmc_dmamask = 0xffffffffUL;
224 static struct at91_mmc_data mmc_data;
225
226 static struct resource at91_mmc_resources[] = {
227         {
228                 .start  = AT91_BASE_MCI,
229                 .end    = AT91_BASE_MCI + SZ_16K - 1,
230                 .flags  = IORESOURCE_MEM,
231         }
232 };
233
234 static struct platform_device at91rm9200_mmc_device = {
235         .name           = "at91rm9200_mci",
236         .id             = -1,
237         .dev            = {
238                                 .dma_mask               = &mmc_dmamask,
239                                 .coherent_dma_mask      = 0xffffffff,
240                                 .platform_data          = &mmc_data,
241         },
242         .resource       = at91_mmc_resources,
243         .num_resources  = ARRAY_SIZE(at91_mmc_resources),
244 };
245
246 void __init at91_add_device_mmc(struct at91_mmc_data *data)
247 {
248         if (!data)
249                 return;
250
251         /* input/irq */
252         if (data->det_pin) {
253                 at91_set_gpio_input(data->det_pin, 1);
254                 at91_set_deglitch(data->det_pin, 1);
255         }
256         if (data->wp_pin)
257                 at91_set_gpio_input(data->wp_pin, 1);
258
259         /* CLK */
260         at91_set_A_periph(AT91_PIN_PA27, 0);
261
262         if (data->is_b) {
263                 /* CMD */
264                 at91_set_B_periph(AT91_PIN_PA8, 0);
265
266                 /* DAT0, maybe DAT1..DAT3 */
267                 at91_set_B_periph(AT91_PIN_PA9, 0);
268                 if (data->wire4) {
269                         at91_set_B_periph(AT91_PIN_PA10, 0);
270                         at91_set_B_periph(AT91_PIN_PA11, 0);
271                         at91_set_B_periph(AT91_PIN_PA12, 0);
272                 }
273         } else {
274                 /* CMD */
275                 at91_set_A_periph(AT91_PIN_PA28, 0);
276
277                 /* DAT0, maybe DAT1..DAT3 */
278                 at91_set_A_periph(AT91_PIN_PA29, 0);
279                 if (data->wire4) {
280                         at91_set_B_periph(AT91_PIN_PB3, 0);
281                         at91_set_B_periph(AT91_PIN_PB4, 0);
282                         at91_set_B_periph(AT91_PIN_PB5, 0);
283                 }
284         }
285
286         mmc_data = *data;
287         platform_device_register(&at91rm9200_mmc_device);
288 }
289 #else
290 void __init at91_add_device_mmc(struct at91_mmc_data *data) {}
291 #endif
292
293 /* --------------------------------------------------------------------
294  *  LEDs
295  * -------------------------------------------------------------------- */
296
297 #if defined(CONFIG_LEDS)
298 u8 at91_leds_cpu;
299 u8 at91_leds_timer;
300
301 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
302 {
303         at91_leds_cpu   = cpu_led;
304         at91_leds_timer = timer_led;
305 }
306
307 #else
308 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
309 #endif
310
311
312 /* -------------------------------------------------------------------- */