Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[sfrench/cifs-2.6.git] / arch / arm / mach-at91 / at91rm9200_devices.c
1 /*
2  * arch/arm/mach-at91/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/platform_device.h>
17 #include <linux/i2c-gpio.h>
18
19 #include <asm/arch/board.h>
20 #include <asm/arch/gpio.h>
21 #include <asm/arch/at91rm9200.h>
22 #include <asm/arch/at91rm9200_mc.h>
23
24 #include "generic.h"
25
26
27 /* --------------------------------------------------------------------
28  *  USB Host
29  * -------------------------------------------------------------------- */
30
31 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
32 static u64 ohci_dmamask = 0xffffffffUL;
33 static struct at91_usbh_data usbh_data;
34
35 static struct resource usbh_resources[] = {
36         [0] = {
37                 .start  = AT91RM9200_UHP_BASE,
38                 .end    = AT91RM9200_UHP_BASE + SZ_1M - 1,
39                 .flags  = IORESOURCE_MEM,
40         },
41         [1] = {
42                 .start  = AT91RM9200_ID_UHP,
43                 .end    = AT91RM9200_ID_UHP,
44                 .flags  = IORESOURCE_IRQ,
45         },
46 };
47
48 static struct platform_device at91rm9200_usbh_device = {
49         .name           = "at91_ohci",
50         .id             = -1,
51         .dev            = {
52                                 .dma_mask               = &ohci_dmamask,
53                                 .coherent_dma_mask      = 0xffffffff,
54                                 .platform_data          = &usbh_data,
55         },
56         .resource       = usbh_resources,
57         .num_resources  = ARRAY_SIZE(usbh_resources),
58 };
59
60 void __init at91_add_device_usbh(struct at91_usbh_data *data)
61 {
62         if (!data)
63                 return;
64
65         usbh_data = *data;
66         platform_device_register(&at91rm9200_usbh_device);
67 }
68 #else
69 void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
70 #endif
71
72
73 /* --------------------------------------------------------------------
74  *  USB Device (Gadget)
75  * -------------------------------------------------------------------- */
76
77 #ifdef CONFIG_USB_GADGET_AT91
78 static struct at91_udc_data udc_data;
79
80 static struct resource udc_resources[] = {
81         [0] = {
82                 .start  = AT91RM9200_BASE_UDP,
83                 .end    = AT91RM9200_BASE_UDP + SZ_16K - 1,
84                 .flags  = IORESOURCE_MEM,
85         },
86         [1] = {
87                 .start  = AT91RM9200_ID_UDP,
88                 .end    = AT91RM9200_ID_UDP,
89                 .flags  = IORESOURCE_IRQ,
90         },
91 };
92
93 static struct platform_device at91rm9200_udc_device = {
94         .name           = "at91_udc",
95         .id             = -1,
96         .dev            = {
97                                 .platform_data          = &udc_data,
98         },
99         .resource       = udc_resources,
100         .num_resources  = ARRAY_SIZE(udc_resources),
101 };
102
103 void __init at91_add_device_udc(struct at91_udc_data *data)
104 {
105         if (!data)
106                 return;
107
108         if (data->vbus_pin) {
109                 at91_set_gpio_input(data->vbus_pin, 0);
110                 at91_set_deglitch(data->vbus_pin, 1);
111         }
112         if (data->pullup_pin)
113                 at91_set_gpio_output(data->pullup_pin, 0);
114
115         udc_data = *data;
116         platform_device_register(&at91rm9200_udc_device);
117 }
118 #else
119 void __init at91_add_device_udc(struct at91_udc_data *data) {}
120 #endif
121
122
123 /* --------------------------------------------------------------------
124  *  Ethernet
125  * -------------------------------------------------------------------- */
126
127 #if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
128 static u64 eth_dmamask = 0xffffffffUL;
129 static struct at91_eth_data eth_data;
130
131 static struct resource eth_resources[] = {
132         [0] = {
133                 .start  = AT91_VA_BASE_EMAC,
134                 .end    = AT91_VA_BASE_EMAC + SZ_16K - 1,
135                 .flags  = IORESOURCE_MEM,
136         },
137         [1] = {
138                 .start  = AT91RM9200_ID_EMAC,
139                 .end    = AT91RM9200_ID_EMAC,
140                 .flags  = IORESOURCE_IRQ,
141         },
142 };
143
144 static struct platform_device at91rm9200_eth_device = {
145         .name           = "at91_ether",
146         .id             = -1,
147         .dev            = {
148                                 .dma_mask               = &eth_dmamask,
149                                 .coherent_dma_mask      = 0xffffffff,
150                                 .platform_data          = &eth_data,
151         },
152         .resource       = eth_resources,
153         .num_resources  = ARRAY_SIZE(eth_resources),
154 };
155
156 void __init at91_add_device_eth(struct at91_eth_data *data)
157 {
158         if (!data)
159                 return;
160
161         if (data->phy_irq_pin) {
162                 at91_set_gpio_input(data->phy_irq_pin, 0);
163                 at91_set_deglitch(data->phy_irq_pin, 1);
164         }
165
166         /* Pins used for MII and RMII */
167         at91_set_A_periph(AT91_PIN_PA16, 0);    /* EMDIO */
168         at91_set_A_periph(AT91_PIN_PA15, 0);    /* EMDC */
169         at91_set_A_periph(AT91_PIN_PA14, 0);    /* ERXER */
170         at91_set_A_periph(AT91_PIN_PA13, 0);    /* ERX1 */
171         at91_set_A_periph(AT91_PIN_PA12, 0);    /* ERX0 */
172         at91_set_A_periph(AT91_PIN_PA11, 0);    /* ECRS_ECRSDV */
173         at91_set_A_periph(AT91_PIN_PA10, 0);    /* ETX1 */
174         at91_set_A_periph(AT91_PIN_PA9, 0);     /* ETX0 */
175         at91_set_A_periph(AT91_PIN_PA8, 0);     /* ETXEN */
176         at91_set_A_periph(AT91_PIN_PA7, 0);     /* ETXCK_EREFCK */
177
178         if (!data->is_rmii) {
179                 at91_set_B_periph(AT91_PIN_PB19, 0);    /* ERXCK */
180                 at91_set_B_periph(AT91_PIN_PB18, 0);    /* ECOL */
181                 at91_set_B_periph(AT91_PIN_PB17, 0);    /* ERXDV */
182                 at91_set_B_periph(AT91_PIN_PB16, 0);    /* ERX3 */
183                 at91_set_B_periph(AT91_PIN_PB15, 0);    /* ERX2 */
184                 at91_set_B_periph(AT91_PIN_PB14, 0);    /* ETXER */
185                 at91_set_B_periph(AT91_PIN_PB13, 0);    /* ETX3 */
186                 at91_set_B_periph(AT91_PIN_PB12, 0);    /* ETX2 */
187         }
188
189         eth_data = *data;
190         platform_device_register(&at91rm9200_eth_device);
191 }
192 #else
193 void __init at91_add_device_eth(struct at91_eth_data *data) {}
194 #endif
195
196
197 /* --------------------------------------------------------------------
198  *  Compact Flash / PCMCIA
199  * -------------------------------------------------------------------- */
200
201 #if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
202 static struct at91_cf_data cf_data;
203
204 #define CF_BASE         AT91_CHIPSELECT_4
205
206 static struct resource cf_resources[] = {
207         [0] = {
208                 .start  = CF_BASE,
209                 /* ties up CS4, CS5 and CS6 */
210                 .end    = CF_BASE + (0x30000000 - 1),
211                 .flags  = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
212         },
213 };
214
215 static struct platform_device at91rm9200_cf_device = {
216         .name           = "at91_cf",
217         .id             = -1,
218         .dev            = {
219                                 .platform_data          = &cf_data,
220         },
221         .resource       = cf_resources,
222         .num_resources  = ARRAY_SIZE(cf_resources),
223 };
224
225 void __init at91_add_device_cf(struct at91_cf_data *data)
226 {
227         unsigned int csa;
228
229         if (!data)
230                 return;
231
232         data->chipselect = 4;           /* can only use EBI ChipSelect 4 */
233
234         /* CF takes over CS4, CS5, CS6 */
235         csa = at91_sys_read(AT91_EBI_CSA);
236         at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
237
238         /*
239          * Static memory controller timing adjustments.
240          * REVISIT:  these timings are in terms of MCK cycles, so
241          * when MCK changes (cpufreq etc) so must these values...
242          */
243         at91_sys_write(AT91_SMC_CSR(4),
244                                   AT91_SMC_ACSS_STD
245                                 | AT91_SMC_DBW_16
246                                 | AT91_SMC_BAT
247                                 | AT91_SMC_WSEN
248                                 | AT91_SMC_NWS_(32)     /* wait states */
249                                 | AT91_SMC_RWSETUP_(6)  /* setup time */
250                                 | AT91_SMC_RWHOLD_(4)   /* hold time */
251         );
252
253         /* input/irq */
254         if (data->irq_pin) {
255                 at91_set_gpio_input(data->irq_pin, 1);
256                 at91_set_deglitch(data->irq_pin, 1);
257         }
258         at91_set_gpio_input(data->det_pin, 1);
259         at91_set_deglitch(data->det_pin, 1);
260
261         /* outputs, initially off */
262         if (data->vcc_pin)
263                 at91_set_gpio_output(data->vcc_pin, 0);
264         at91_set_gpio_output(data->rst_pin, 0);
265
266         /* force poweron defaults for these pins ... */
267         at91_set_A_periph(AT91_PIN_PC9, 0);     /* A25/CFRNW */
268         at91_set_A_periph(AT91_PIN_PC10, 0);    /* NCS4/CFCS */
269         at91_set_A_periph(AT91_PIN_PC11, 0);    /* NCS5/CFCE1 */
270         at91_set_A_periph(AT91_PIN_PC12, 0);    /* NCS6/CFCE2 */
271
272         /* nWAIT is _not_ a default setting */
273         at91_set_A_periph(AT91_PIN_PC6, 1);     /* nWAIT */
274
275         cf_data = *data;
276         platform_device_register(&at91rm9200_cf_device);
277 }
278 #else
279 void __init at91_add_device_cf(struct at91_cf_data *data) {}
280 #endif
281
282
283 /* --------------------------------------------------------------------
284  *  MMC / SD
285  * -------------------------------------------------------------------- */
286
287 #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
288 static u64 mmc_dmamask = 0xffffffffUL;
289 static struct at91_mmc_data mmc_data;
290
291 static struct resource mmc_resources[] = {
292         [0] = {
293                 .start  = AT91RM9200_BASE_MCI,
294                 .end    = AT91RM9200_BASE_MCI + SZ_16K - 1,
295                 .flags  = IORESOURCE_MEM,
296         },
297         [1] = {
298                 .start  = AT91RM9200_ID_MCI,
299                 .end    = AT91RM9200_ID_MCI,
300                 .flags  = IORESOURCE_IRQ,
301         },
302 };
303
304 static struct platform_device at91rm9200_mmc_device = {
305         .name           = "at91_mci",
306         .id             = -1,
307         .dev            = {
308                                 .dma_mask               = &mmc_dmamask,
309                                 .coherent_dma_mask      = 0xffffffff,
310                                 .platform_data          = &mmc_data,
311         },
312         .resource       = mmc_resources,
313         .num_resources  = ARRAY_SIZE(mmc_resources),
314 };
315
316 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
317 {
318         if (!data)
319                 return;
320
321         /* input/irq */
322         if (data->det_pin) {
323                 at91_set_gpio_input(data->det_pin, 1);
324                 at91_set_deglitch(data->det_pin, 1);
325         }
326         if (data->wp_pin)
327                 at91_set_gpio_input(data->wp_pin, 1);
328         if (data->vcc_pin)
329                 at91_set_gpio_output(data->vcc_pin, 0);
330
331         /* CLK */
332         at91_set_A_periph(AT91_PIN_PA27, 0);
333
334         if (data->slot_b) {
335                 /* CMD */
336                 at91_set_B_periph(AT91_PIN_PA8, 1);
337
338                 /* DAT0, maybe DAT1..DAT3 */
339                 at91_set_B_periph(AT91_PIN_PA9, 1);
340                 if (data->wire4) {
341                         at91_set_B_periph(AT91_PIN_PA10, 1);
342                         at91_set_B_periph(AT91_PIN_PA11, 1);
343                         at91_set_B_periph(AT91_PIN_PA12, 1);
344                 }
345         } else {
346                 /* CMD */
347                 at91_set_A_periph(AT91_PIN_PA28, 1);
348
349                 /* DAT0, maybe DAT1..DAT3 */
350                 at91_set_A_periph(AT91_PIN_PA29, 1);
351                 if (data->wire4) {
352                         at91_set_B_periph(AT91_PIN_PB3, 1);
353                         at91_set_B_periph(AT91_PIN_PB4, 1);
354                         at91_set_B_periph(AT91_PIN_PB5, 1);
355                 }
356         }
357
358         mmc_data = *data;
359         platform_device_register(&at91rm9200_mmc_device);
360 }
361 #else
362 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
363 #endif
364
365
366 /* --------------------------------------------------------------------
367  *  NAND / SmartMedia
368  * -------------------------------------------------------------------- */
369
370 #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
371 static struct at91_nand_data nand_data;
372
373 #define NAND_BASE       AT91_CHIPSELECT_3
374
375 static struct resource nand_resources[] = {
376         {
377                 .start  = NAND_BASE,
378                 .end    = NAND_BASE + SZ_8M - 1,
379                 .flags  = IORESOURCE_MEM,
380         }
381 };
382
383 static struct platform_device at91rm9200_nand_device = {
384         .name           = "at91_nand",
385         .id             = -1,
386         .dev            = {
387                                 .platform_data  = &nand_data,
388         },
389         .resource       = nand_resources,
390         .num_resources  = ARRAY_SIZE(nand_resources),
391 };
392
393 void __init at91_add_device_nand(struct at91_nand_data *data)
394 {
395         unsigned int csa;
396
397         if (!data)
398                 return;
399
400         /* enable the address range of CS3 */
401         csa = at91_sys_read(AT91_EBI_CSA);
402         at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS3A_SMC_SMARTMEDIA);
403
404         /* set the bus interface characteristics */
405         at91_sys_write(AT91_SMC_CSR(3), AT91_SMC_ACSS_STD | AT91_SMC_DBW_8 | AT91_SMC_WSEN
406                 | AT91_SMC_NWS_(5)
407                 | AT91_SMC_TDF_(1)
408                 | AT91_SMC_RWSETUP_(0)  /* tDS Data Set up Time 30 - ns */
409                 | AT91_SMC_RWHOLD_(1)   /* tDH Data Hold Time 20 - ns */
410         );
411
412         /* enable pin */
413         if (data->enable_pin)
414                 at91_set_gpio_output(data->enable_pin, 1);
415
416         /* ready/busy pin */
417         if (data->rdy_pin)
418                 at91_set_gpio_input(data->rdy_pin, 1);
419
420         /* card detect pin */
421         if (data->det_pin)
422                 at91_set_gpio_input(data->det_pin, 1);
423
424         at91_set_A_periph(AT91_PIN_PC1, 0);             /* SMOE */
425         at91_set_A_periph(AT91_PIN_PC3, 0);             /* SMWE */
426
427         nand_data = *data;
428         platform_device_register(&at91rm9200_nand_device);
429 }
430 #else
431 void __init at91_add_device_nand(struct at91_nand_data *data) {}
432 #endif
433
434
435 /* --------------------------------------------------------------------
436  *  TWI (i2c)
437  * -------------------------------------------------------------------- */
438
439 /*
440  * Prefer the GPIO code since the TWI controller isn't robust
441  * (gets overruns and underruns under load) and can only issue
442  * repeated STARTs in one scenario (the driver doesn't yet handle them).
443  */
444 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
445
446 static struct i2c_gpio_platform_data pdata = {
447         .sda_pin                = AT91_PIN_PA25,
448         .sda_is_open_drain      = 1,
449         .scl_pin                = AT91_PIN_PA26,
450         .scl_is_open_drain      = 1,
451         .udelay                 = 2,            /* ~100 kHz */
452 };
453
454 static struct platform_device at91rm9200_twi_device = {
455         .name                   = "i2c-gpio",
456         .id                     = -1,
457         .dev.platform_data      = &pdata,
458 };
459
460 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
461 {
462         at91_set_GPIO_periph(AT91_PIN_PA25, 1);         /* TWD (SDA) */
463         at91_set_multi_drive(AT91_PIN_PA25, 1);
464
465         at91_set_GPIO_periph(AT91_PIN_PA26, 1);         /* TWCK (SCL) */
466         at91_set_multi_drive(AT91_PIN_PA26, 1);
467
468         i2c_register_board_info(0, devices, nr_devices);
469         platform_device_register(&at91rm9200_twi_device);
470 }
471
472 #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
473
474 static struct resource twi_resources[] = {
475         [0] = {
476                 .start  = AT91RM9200_BASE_TWI,
477                 .end    = AT91RM9200_BASE_TWI + SZ_16K - 1,
478                 .flags  = IORESOURCE_MEM,
479         },
480         [1] = {
481                 .start  = AT91RM9200_ID_TWI,
482                 .end    = AT91RM9200_ID_TWI,
483                 .flags  = IORESOURCE_IRQ,
484         },
485 };
486
487 static struct platform_device at91rm9200_twi_device = {
488         .name           = "at91_i2c",
489         .id             = -1,
490         .resource       = twi_resources,
491         .num_resources  = ARRAY_SIZE(twi_resources),
492 };
493
494 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
495 {
496         /* pins used for TWI interface */
497         at91_set_A_periph(AT91_PIN_PA25, 0);            /* TWD */
498         at91_set_multi_drive(AT91_PIN_PA25, 1);
499
500         at91_set_A_periph(AT91_PIN_PA26, 0);            /* TWCK */
501         at91_set_multi_drive(AT91_PIN_PA26, 1);
502
503         i2c_register_board_info(0, devices, nr_devices);
504         platform_device_register(&at91rm9200_twi_device);
505 }
506 #else
507 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
508 #endif
509
510
511 /* --------------------------------------------------------------------
512  *  SPI
513  * -------------------------------------------------------------------- */
514
515 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
516 static u64 spi_dmamask = 0xffffffffUL;
517
518 static struct resource spi_resources[] = {
519         [0] = {
520                 .start  = AT91RM9200_BASE_SPI,
521                 .end    = AT91RM9200_BASE_SPI + SZ_16K - 1,
522                 .flags  = IORESOURCE_MEM,
523         },
524         [1] = {
525                 .start  = AT91RM9200_ID_SPI,
526                 .end    = AT91RM9200_ID_SPI,
527                 .flags  = IORESOURCE_IRQ,
528         },
529 };
530
531 static struct platform_device at91rm9200_spi_device = {
532         .name           = "atmel_spi",
533         .id             = 0,
534         .dev            = {
535                                 .dma_mask               = &spi_dmamask,
536                                 .coherent_dma_mask      = 0xffffffff,
537         },
538         .resource       = spi_resources,
539         .num_resources  = ARRAY_SIZE(spi_resources),
540 };
541
542 static const unsigned spi_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
543
544 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
545 {
546         int i;
547         unsigned long cs_pin;
548
549         at91_set_A_periph(AT91_PIN_PA0, 0);     /* MISO */
550         at91_set_A_periph(AT91_PIN_PA1, 0);     /* MOSI */
551         at91_set_A_periph(AT91_PIN_PA2, 0);     /* SPCK */
552
553         /* Enable SPI chip-selects */
554         for (i = 0; i < nr_devices; i++) {
555                 if (devices[i].controller_data)
556                         cs_pin = (unsigned long) devices[i].controller_data;
557                 else
558                         cs_pin = spi_standard_cs[devices[i].chip_select];
559
560                 /* enable chip-select pin */
561                 at91_set_gpio_output(cs_pin, 1);
562
563                 /* pass chip-select pin to driver */
564                 devices[i].controller_data = (void *) cs_pin;
565         }
566
567         spi_register_board_info(devices, nr_devices);
568         platform_device_register(&at91rm9200_spi_device);
569 }
570 #else
571 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
572 #endif
573
574
575 /* --------------------------------------------------------------------
576  *  RTC
577  * -------------------------------------------------------------------- */
578
579 #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
580 static struct platform_device at91rm9200_rtc_device = {
581         .name           = "at91_rtc",
582         .id             = -1,
583         .num_resources  = 0,
584 };
585
586 static void __init at91_add_device_rtc(void)
587 {
588         platform_device_register(&at91rm9200_rtc_device);
589 }
590 #else
591 static void __init at91_add_device_rtc(void) {}
592 #endif
593
594
595 /* --------------------------------------------------------------------
596  *  Watchdog
597  * -------------------------------------------------------------------- */
598
599 #if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
600 static struct platform_device at91rm9200_wdt_device = {
601         .name           = "at91_wdt",
602         .id             = -1,
603         .num_resources  = 0,
604 };
605
606 static void __init at91_add_device_watchdog(void)
607 {
608         platform_device_register(&at91rm9200_wdt_device);
609 }
610 #else
611 static void __init at91_add_device_watchdog(void) {}
612 #endif
613
614
615 /* --------------------------------------------------------------------
616  *  LEDs
617  * -------------------------------------------------------------------- */
618
619 #if defined(CONFIG_LEDS)
620 u8 at91_leds_cpu;
621 u8 at91_leds_timer;
622
623 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
624 {
625         /* Enable GPIO to access the LEDs */
626         at91_set_gpio_output(cpu_led, 1);
627         at91_set_gpio_output(timer_led, 1);
628
629         at91_leds_cpu   = cpu_led;
630         at91_leds_timer = timer_led;
631 }
632 #else
633 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
634 #endif
635
636
637 /* --------------------------------------------------------------------
638  *  UART
639  * -------------------------------------------------------------------- */
640
641 #if defined(CONFIG_SERIAL_ATMEL)
642 static struct resource dbgu_resources[] = {
643         [0] = {
644                 .start  = AT91_VA_BASE_SYS + AT91_DBGU,
645                 .end    = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
646                 .flags  = IORESOURCE_MEM,
647         },
648         [1] = {
649                 .start  = AT91_ID_SYS,
650                 .end    = AT91_ID_SYS,
651                 .flags  = IORESOURCE_IRQ,
652         },
653 };
654
655 static struct atmel_uart_data dbgu_data = {
656         .use_dma_tx     = 0,
657         .use_dma_rx     = 0,            /* DBGU not capable of receive DMA */
658         .regs           = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
659 };
660
661 static struct platform_device at91rm9200_dbgu_device = {
662         .name           = "atmel_usart",
663         .id             = 0,
664         .dev            = {
665                                 .platform_data  = &dbgu_data,
666                                 .coherent_dma_mask = 0xffffffff,
667         },
668         .resource       = dbgu_resources,
669         .num_resources  = ARRAY_SIZE(dbgu_resources),
670 };
671
672 static inline void configure_dbgu_pins(void)
673 {
674         at91_set_A_periph(AT91_PIN_PA30, 0);            /* DRXD */
675         at91_set_A_periph(AT91_PIN_PA31, 1);            /* DTXD */
676 }
677
678 static struct resource uart0_resources[] = {
679         [0] = {
680                 .start  = AT91RM9200_BASE_US0,
681                 .end    = AT91RM9200_BASE_US0 + SZ_16K - 1,
682                 .flags  = IORESOURCE_MEM,
683         },
684         [1] = {
685                 .start  = AT91RM9200_ID_US0,
686                 .end    = AT91RM9200_ID_US0,
687                 .flags  = IORESOURCE_IRQ,
688         },
689 };
690
691 static struct atmel_uart_data uart0_data = {
692         .use_dma_tx     = 1,
693         .use_dma_rx     = 1,
694 };
695
696 static struct platform_device at91rm9200_uart0_device = {
697         .name           = "atmel_usart",
698         .id             = 1,
699         .dev            = {
700                                 .platform_data  = &uart0_data,
701                                 .coherent_dma_mask = 0xffffffff,
702         },
703         .resource       = uart0_resources,
704         .num_resources  = ARRAY_SIZE(uart0_resources),
705 };
706
707 static inline void configure_usart0_pins(void)
708 {
709         at91_set_A_periph(AT91_PIN_PA17, 1);            /* TXD0 */
710         at91_set_A_periph(AT91_PIN_PA18, 0);            /* RXD0 */
711         at91_set_A_periph(AT91_PIN_PA20, 0);            /* CTS0 */
712
713         /*
714          * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
715          *  We need to drive the pin manually.  Default is off (RTS is active low).
716          */
717         at91_set_gpio_output(AT91_PIN_PA21, 1);
718 }
719
720 static struct resource uart1_resources[] = {
721         [0] = {
722                 .start  = AT91RM9200_BASE_US1,
723                 .end    = AT91RM9200_BASE_US1 + SZ_16K - 1,
724                 .flags  = IORESOURCE_MEM,
725         },
726         [1] = {
727                 .start  = AT91RM9200_ID_US1,
728                 .end    = AT91RM9200_ID_US1,
729                 .flags  = IORESOURCE_IRQ,
730         },
731 };
732
733 static struct atmel_uart_data uart1_data = {
734         .use_dma_tx     = 1,
735         .use_dma_rx     = 1,
736 };
737
738 static struct platform_device at91rm9200_uart1_device = {
739         .name           = "atmel_usart",
740         .id             = 2,
741         .dev            = {
742                                 .platform_data  = &uart1_data,
743                                 .coherent_dma_mask = 0xffffffff,
744         },
745         .resource       = uart1_resources,
746         .num_resources  = ARRAY_SIZE(uart1_resources),
747 };
748
749 static inline void configure_usart1_pins(void)
750 {
751         at91_set_A_periph(AT91_PIN_PB18, 0);            /* RI1 */
752         at91_set_A_periph(AT91_PIN_PB19, 0);            /* DTR1 */
753         at91_set_A_periph(AT91_PIN_PB20, 1);            /* TXD1 */
754         at91_set_A_periph(AT91_PIN_PB21, 0);            /* RXD1 */
755         at91_set_A_periph(AT91_PIN_PB23, 0);            /* DCD1 */
756         at91_set_A_periph(AT91_PIN_PB24, 0);            /* CTS1 */
757         at91_set_A_periph(AT91_PIN_PB25, 0);            /* DSR1 */
758         at91_set_A_periph(AT91_PIN_PB26, 0);            /* RTS1 */
759 }
760
761 static struct resource uart2_resources[] = {
762         [0] = {
763                 .start  = AT91RM9200_BASE_US2,
764                 .end    = AT91RM9200_BASE_US2 + SZ_16K - 1,
765                 .flags  = IORESOURCE_MEM,
766         },
767         [1] = {
768                 .start  = AT91RM9200_ID_US2,
769                 .end    = AT91RM9200_ID_US2,
770                 .flags  = IORESOURCE_IRQ,
771         },
772 };
773
774 static struct atmel_uart_data uart2_data = {
775         .use_dma_tx     = 1,
776         .use_dma_rx     = 1,
777 };
778
779 static struct platform_device at91rm9200_uart2_device = {
780         .name           = "atmel_usart",
781         .id             = 3,
782         .dev            = {
783                                 .platform_data  = &uart2_data,
784                                 .coherent_dma_mask = 0xffffffff,
785         },
786         .resource       = uart2_resources,
787         .num_resources  = ARRAY_SIZE(uart2_resources),
788 };
789
790 static inline void configure_usart2_pins(void)
791 {
792         at91_set_A_periph(AT91_PIN_PA22, 0);            /* RXD2 */
793         at91_set_A_periph(AT91_PIN_PA23, 1);            /* TXD2 */
794 }
795
796 static struct resource uart3_resources[] = {
797         [0] = {
798                 .start  = AT91RM9200_BASE_US3,
799                 .end    = AT91RM9200_BASE_US3 + SZ_16K - 1,
800                 .flags  = IORESOURCE_MEM,
801         },
802         [1] = {
803                 .start  = AT91RM9200_ID_US3,
804                 .end    = AT91RM9200_ID_US3,
805                 .flags  = IORESOURCE_IRQ,
806         },
807 };
808
809 static struct atmel_uart_data uart3_data = {
810         .use_dma_tx     = 1,
811         .use_dma_rx     = 1,
812 };
813
814 static struct platform_device at91rm9200_uart3_device = {
815         .name           = "atmel_usart",
816         .id             = 4,
817         .dev            = {
818                                 .platform_data  = &uart3_data,
819                                 .coherent_dma_mask = 0xffffffff,
820         },
821         .resource       = uart3_resources,
822         .num_resources  = ARRAY_SIZE(uart3_resources),
823 };
824
825 static inline void configure_usart3_pins(void)
826 {
827         at91_set_B_periph(AT91_PIN_PA5, 1);             /* TXD3 */
828         at91_set_B_periph(AT91_PIN_PA6, 0);             /* RXD3 */
829 }
830
831 struct platform_device *at91_uarts[ATMEL_MAX_UART];     /* the UARTs to use */
832 struct platform_device *atmel_default_console_device;   /* the serial console device */
833
834 void __init at91_init_serial(struct at91_uart_config *config)
835 {
836         int i;
837
838         /* Fill in list of supported UARTs */
839         for (i = 0; i < config->nr_tty; i++) {
840                 switch (config->tty_map[i]) {
841                         case 0:
842                                 configure_usart0_pins();
843                                 at91_uarts[i] = &at91rm9200_uart0_device;
844                                 at91_clock_associate("usart0_clk", &at91rm9200_uart0_device.dev, "usart");
845                                 break;
846                         case 1:
847                                 configure_usart1_pins();
848                                 at91_uarts[i] = &at91rm9200_uart1_device;
849                                 at91_clock_associate("usart1_clk", &at91rm9200_uart1_device.dev, "usart");
850                                 break;
851                         case 2:
852                                 configure_usart2_pins();
853                                 at91_uarts[i] = &at91rm9200_uart2_device;
854                                 at91_clock_associate("usart2_clk", &at91rm9200_uart2_device.dev, "usart");
855                                 break;
856                         case 3:
857                                 configure_usart3_pins();
858                                 at91_uarts[i] = &at91rm9200_uart3_device;
859                                 at91_clock_associate("usart3_clk", &at91rm9200_uart3_device.dev, "usart");
860                                 break;
861                         case 4:
862                                 configure_dbgu_pins();
863                                 at91_uarts[i] = &at91rm9200_dbgu_device;
864                                 at91_clock_associate("mck", &at91rm9200_dbgu_device.dev, "usart");
865                                 break;
866                         default:
867                                 continue;
868                 }
869                 at91_uarts[i]->id = i;          /* update ID number to mapped ID */
870         }
871
872         /* Set serial console device */
873         if (config->console_tty < ATMEL_MAX_UART)
874                 atmel_default_console_device = at91_uarts[config->console_tty];
875         if (!atmel_default_console_device)
876                 printk(KERN_INFO "AT91: No default serial console defined.\n");
877 }
878
879 void __init at91_add_device_serial(void)
880 {
881         int i;
882
883         for (i = 0; i < ATMEL_MAX_UART; i++) {
884                 if (at91_uarts[i])
885                         platform_device_register(at91_uarts[i]);
886         }
887 }
888 #else
889 void __init at91_init_serial(struct at91_uart_config *config) {}
890 void __init at91_add_device_serial(void) {}
891 #endif
892
893
894 /* -------------------------------------------------------------------- */
895
896 /*
897  * These devices are always present and don't need any board-specific
898  * setup.
899  */
900 static int __init at91_add_standard_devices(void)
901 {
902         at91_add_device_rtc();
903         at91_add_device_watchdog();
904         return 0;
905 }
906
907 arch_initcall(at91_add_standard_devices);