]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-at91/at91sam9261_devices.c
17f3f6a2479692e93eb5f7433c295eedcaceb5fb
[linux-2.6-omap-h63xx.git] / arch / arm / mach-at91 / at91sam9261_devices.c
1 /*
2  * arch/arm/mach-at91/at91sam9261_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 <linux/fb.h>
20 #include <video/atmel_lcdc.h>
21
22 #include <asm/arch/board.h>
23 #include <asm/arch/gpio.h>
24 #include <asm/arch/at91sam9261.h>
25 #include <asm/arch/at91sam9261_matrix.h>
26 #include <asm/arch/at91sam926x_mc.h>
27
28 #include "generic.h"
29
30
31 /* --------------------------------------------------------------------
32  *  USB Host
33  * -------------------------------------------------------------------- */
34
35 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
36 static u64 ohci_dmamask = 0xffffffffUL;
37 static struct at91_usbh_data usbh_data;
38
39 static struct resource usbh_resources[] = {
40         [0] = {
41                 .start  = AT91SAM9261_UHP_BASE,
42                 .end    = AT91SAM9261_UHP_BASE + SZ_1M - 1,
43                 .flags  = IORESOURCE_MEM,
44         },
45         [1] = {
46                 .start  = AT91SAM9261_ID_UHP,
47                 .end    = AT91SAM9261_ID_UHP,
48                 .flags  = IORESOURCE_IRQ,
49         },
50 };
51
52 static struct platform_device at91sam9261_usbh_device = {
53         .name           = "at91_ohci",
54         .id             = -1,
55         .dev            = {
56                                 .dma_mask               = &ohci_dmamask,
57                                 .coherent_dma_mask      = 0xffffffff,
58                                 .platform_data          = &usbh_data,
59         },
60         .resource       = usbh_resources,
61         .num_resources  = ARRAY_SIZE(usbh_resources),
62 };
63
64 void __init at91_add_device_usbh(struct at91_usbh_data *data)
65 {
66         if (!data)
67                 return;
68
69         usbh_data = *data;
70         platform_device_register(&at91sam9261_usbh_device);
71 }
72 #else
73 void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
74 #endif
75
76
77 /* --------------------------------------------------------------------
78  *  USB Device (Gadget)
79  * -------------------------------------------------------------------- */
80
81 #ifdef CONFIG_USB_GADGET_AT91
82 static struct at91_udc_data udc_data;
83
84 static struct resource udc_resources[] = {
85         [0] = {
86                 .start  = AT91SAM9261_BASE_UDP,
87                 .end    = AT91SAM9261_BASE_UDP + SZ_16K - 1,
88                 .flags  = IORESOURCE_MEM,
89         },
90         [1] = {
91                 .start  = AT91SAM9261_ID_UDP,
92                 .end    = AT91SAM9261_ID_UDP,
93                 .flags  = IORESOURCE_IRQ,
94         },
95 };
96
97 static struct platform_device at91sam9261_udc_device = {
98         .name           = "at91_udc",
99         .id             = -1,
100         .dev            = {
101                                 .platform_data          = &udc_data,
102         },
103         .resource       = udc_resources,
104         .num_resources  = ARRAY_SIZE(udc_resources),
105 };
106
107 void __init at91_add_device_udc(struct at91_udc_data *data)
108 {
109         unsigned long x;
110
111         if (!data)
112                 return;
113
114         if (data->vbus_pin) {
115                 at91_set_gpio_input(data->vbus_pin, 0);
116                 at91_set_deglitch(data->vbus_pin, 1);
117         }
118
119         /* Pullup pin is handled internally */
120         x = at91_sys_read(AT91_MATRIX_USBPUCR);
121         at91_sys_write(AT91_MATRIX_USBPUCR, x | AT91_MATRIX_USBPUCR_PUON);
122
123         udc_data = *data;
124         platform_device_register(&at91sam9261_udc_device);
125 }
126 #else
127 void __init at91_add_device_udc(struct at91_udc_data *data) {}
128 #endif
129
130 /* --------------------------------------------------------------------
131  *  MMC / SD
132  * -------------------------------------------------------------------- */
133
134 #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
135 static u64 mmc_dmamask = 0xffffffffUL;
136 static struct at91_mmc_data mmc_data;
137
138 static struct resource mmc_resources[] = {
139         [0] = {
140                 .start  = AT91SAM9261_BASE_MCI,
141                 .end    = AT91SAM9261_BASE_MCI + SZ_16K - 1,
142                 .flags  = IORESOURCE_MEM,
143         },
144         [1] = {
145                 .start  = AT91SAM9261_ID_MCI,
146                 .end    = AT91SAM9261_ID_MCI,
147                 .flags  = IORESOURCE_IRQ,
148         },
149 };
150
151 static struct platform_device at91sam9261_mmc_device = {
152         .name           = "at91_mci",
153         .id             = -1,
154         .dev            = {
155                                 .dma_mask               = &mmc_dmamask,
156                                 .coherent_dma_mask      = 0xffffffff,
157                                 .platform_data          = &mmc_data,
158         },
159         .resource       = mmc_resources,
160         .num_resources  = ARRAY_SIZE(mmc_resources),
161 };
162
163 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
164 {
165         if (!data)
166                 return;
167
168         /* input/irq */
169         if (data->det_pin) {
170                 at91_set_gpio_input(data->det_pin, 1);
171                 at91_set_deglitch(data->det_pin, 1);
172         }
173         if (data->wp_pin)
174                 at91_set_gpio_input(data->wp_pin, 1);
175         if (data->vcc_pin)
176                 at91_set_gpio_output(data->vcc_pin, 0);
177
178         /* CLK */
179         at91_set_B_periph(AT91_PIN_PA2, 0);
180
181         /* CMD */
182         at91_set_B_periph(AT91_PIN_PA1, 1);
183
184         /* DAT0, maybe DAT1..DAT3 */
185         at91_set_B_periph(AT91_PIN_PA0, 1);
186         if (data->wire4) {
187                 at91_set_B_periph(AT91_PIN_PA4, 1);
188                 at91_set_B_periph(AT91_PIN_PA5, 1);
189                 at91_set_B_periph(AT91_PIN_PA6, 1);
190         }
191
192         mmc_data = *data;
193         platform_device_register(&at91sam9261_mmc_device);
194 }
195 #else
196 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
197 #endif
198
199
200 /* --------------------------------------------------------------------
201  *  NAND / SmartMedia
202  * -------------------------------------------------------------------- */
203
204 #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
205 static struct at91_nand_data nand_data;
206
207 #define NAND_BASE       AT91_CHIPSELECT_3
208
209 static struct resource nand_resources[] = {
210         {
211                 .start  = NAND_BASE,
212                 .end    = NAND_BASE + SZ_256M - 1,
213                 .flags  = IORESOURCE_MEM,
214         }
215 };
216
217 static struct platform_device at91_nand_device = {
218         .name           = "at91_nand",
219         .id             = -1,
220         .dev            = {
221                                 .platform_data  = &nand_data,
222         },
223         .resource       = nand_resources,
224         .num_resources  = ARRAY_SIZE(nand_resources),
225 };
226
227 void __init at91_add_device_nand(struct at91_nand_data *data)
228 {
229         unsigned long csa, mode;
230
231         if (!data)
232                 return;
233
234         csa = at91_sys_read(AT91_MATRIX_EBICSA);
235         at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC);
236
237         /* set the bus interface characteristics */
238         at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
239                         | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
240
241         at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
242                         | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
243
244         at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
245
246         if (data->bus_width_16)
247                 mode = AT91_SMC_DBW_16;
248         else
249                 mode = AT91_SMC_DBW_8;
250         at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
251
252         /* enable pin */
253         if (data->enable_pin)
254                 at91_set_gpio_output(data->enable_pin, 1);
255
256         /* ready/busy pin */
257         if (data->rdy_pin)
258                 at91_set_gpio_input(data->rdy_pin, 1);
259
260         /* card detect pin */
261         if (data->det_pin)
262                 at91_set_gpio_input(data->det_pin, 1);
263
264         at91_set_A_periph(AT91_PIN_PC0, 0);             /* NANDOE */
265         at91_set_A_periph(AT91_PIN_PC1, 0);             /* NANDWE */
266
267         nand_data = *data;
268         platform_device_register(&at91_nand_device);
269 }
270
271 #else
272 void __init at91_add_device_nand(struct at91_nand_data *data) {}
273 #endif
274
275
276 /* --------------------------------------------------------------------
277  *  TWI (i2c)
278  * -------------------------------------------------------------------- */
279
280 /*
281  * Prefer the GPIO code since the TWI controller isn't robust
282  * (gets overruns and underruns under load) and can only issue
283  * repeated STARTs in one scenario (the driver doesn't yet handle them).
284  */
285 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
286
287 static struct i2c_gpio_platform_data pdata = {
288         .sda_pin                = AT91_PIN_PA7,
289         .sda_is_open_drain      = 1,
290         .scl_pin                = AT91_PIN_PA8,
291         .scl_is_open_drain      = 1,
292         .udelay                 = 2,            /* ~100 kHz */
293 };
294
295 static struct platform_device at91sam9261_twi_device = {
296         .name                   = "i2c-gpio",
297         .id                     = -1,
298         .dev.platform_data      = &pdata,
299 };
300
301 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
302 {
303         at91_set_GPIO_periph(AT91_PIN_PA7, 1);          /* TWD (SDA) */
304         at91_set_multi_drive(AT91_PIN_PA7, 1);
305
306         at91_set_GPIO_periph(AT91_PIN_PA8, 1);          /* TWCK (SCL) */
307         at91_set_multi_drive(AT91_PIN_PA8, 1);
308
309         i2c_register_board_info(0, devices, nr_devices);
310         platform_device_register(&at91sam9261_twi_device);
311 }
312
313 #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
314
315 static struct resource twi_resources[] = {
316         [0] = {
317                 .start  = AT91SAM9261_BASE_TWI,
318                 .end    = AT91SAM9261_BASE_TWI + SZ_16K - 1,
319                 .flags  = IORESOURCE_MEM,
320         },
321         [1] = {
322                 .start  = AT91SAM9261_ID_TWI,
323                 .end    = AT91SAM9261_ID_TWI,
324                 .flags  = IORESOURCE_IRQ,
325         },
326 };
327
328 static struct platform_device at91sam9261_twi_device = {
329         .name           = "at91_i2c",
330         .id             = -1,
331         .resource       = twi_resources,
332         .num_resources  = ARRAY_SIZE(twi_resources),
333 };
334
335 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
336 {
337         /* pins used for TWI interface */
338         at91_set_A_periph(AT91_PIN_PA7, 0);             /* TWD */
339         at91_set_multi_drive(AT91_PIN_PA7, 1);
340
341         at91_set_A_periph(AT91_PIN_PA8, 0);             /* TWCK */
342         at91_set_multi_drive(AT91_PIN_PA8, 1);
343
344         i2c_register_board_info(0, devices, nr_devices);
345         platform_device_register(&at91sam9261_twi_device);
346 }
347 #else
348 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
349 #endif
350
351
352 /* --------------------------------------------------------------------
353  *  SPI
354  * -------------------------------------------------------------------- */
355
356 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
357 static u64 spi_dmamask = 0xffffffffUL;
358
359 static struct resource spi0_resources[] = {
360         [0] = {
361                 .start  = AT91SAM9261_BASE_SPI0,
362                 .end    = AT91SAM9261_BASE_SPI0 + SZ_16K - 1,
363                 .flags  = IORESOURCE_MEM,
364         },
365         [1] = {
366                 .start  = AT91SAM9261_ID_SPI0,
367                 .end    = AT91SAM9261_ID_SPI0,
368                 .flags  = IORESOURCE_IRQ,
369         },
370 };
371
372 static struct platform_device at91sam9261_spi0_device = {
373         .name           = "atmel_spi",
374         .id             = 0,
375         .dev            = {
376                                 .dma_mask               = &spi_dmamask,
377                                 .coherent_dma_mask      = 0xffffffff,
378         },
379         .resource       = spi0_resources,
380         .num_resources  = ARRAY_SIZE(spi0_resources),
381 };
382
383 static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
384
385 static struct resource spi1_resources[] = {
386         [0] = {
387                 .start  = AT91SAM9261_BASE_SPI1,
388                 .end    = AT91SAM9261_BASE_SPI1 + SZ_16K - 1,
389                 .flags  = IORESOURCE_MEM,
390         },
391         [1] = {
392                 .start  = AT91SAM9261_ID_SPI1,
393                 .end    = AT91SAM9261_ID_SPI1,
394                 .flags  = IORESOURCE_IRQ,
395         },
396 };
397
398 static struct platform_device at91sam9261_spi1_device = {
399         .name           = "atmel_spi",
400         .id             = 1,
401         .dev            = {
402                                 .dma_mask               = &spi_dmamask,
403                                 .coherent_dma_mask      = 0xffffffff,
404         },
405         .resource       = spi1_resources,
406         .num_resources  = ARRAY_SIZE(spi1_resources),
407 };
408
409 static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB28, AT91_PIN_PA24, AT91_PIN_PA25, AT91_PIN_PA26 };
410
411 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
412 {
413         int i;
414         unsigned long cs_pin;
415         short enable_spi0 = 0;
416         short enable_spi1 = 0;
417
418         /* Choose SPI chip-selects */
419         for (i = 0; i < nr_devices; i++) {
420                 if (devices[i].controller_data)
421                         cs_pin = (unsigned long) devices[i].controller_data;
422                 else if (devices[i].bus_num == 0)
423                         cs_pin = spi0_standard_cs[devices[i].chip_select];
424                 else
425                         cs_pin = spi1_standard_cs[devices[i].chip_select];
426
427                 if (devices[i].bus_num == 0)
428                         enable_spi0 = 1;
429                 else
430                         enable_spi1 = 1;
431
432                 /* enable chip-select pin */
433                 at91_set_gpio_output(cs_pin, 1);
434
435                 /* pass chip-select pin to driver */
436                 devices[i].controller_data = (void *) cs_pin;
437         }
438
439         spi_register_board_info(devices, nr_devices);
440
441         /* Configure SPI bus(es) */
442         if (enable_spi0) {
443                 at91_set_A_periph(AT91_PIN_PA0, 0);     /* SPI0_MISO */
444                 at91_set_A_periph(AT91_PIN_PA1, 0);     /* SPI0_MOSI */
445                 at91_set_A_periph(AT91_PIN_PA2, 0);     /* SPI0_SPCK */
446
447                 at91_clock_associate("spi0_clk", &at91sam9261_spi0_device.dev, "spi_clk");
448                 platform_device_register(&at91sam9261_spi0_device);
449         }
450         if (enable_spi1) {
451                 at91_set_A_periph(AT91_PIN_PB30, 0);    /* SPI1_MISO */
452                 at91_set_A_periph(AT91_PIN_PB31, 0);    /* SPI1_MOSI */
453                 at91_set_A_periph(AT91_PIN_PB29, 0);    /* SPI1_SPCK */
454
455                 at91_clock_associate("spi1_clk", &at91sam9261_spi1_device.dev, "spi_clk");
456                 platform_device_register(&at91sam9261_spi1_device);
457         }
458 }
459 #else
460 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
461 #endif
462
463
464 /* --------------------------------------------------------------------
465  *  LCD Controller
466  * -------------------------------------------------------------------- */
467
468 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
469 static u64 lcdc_dmamask = 0xffffffffUL;
470 static struct atmel_lcdfb_info lcdc_data;
471
472 static struct resource lcdc_resources[] = {
473         [0] = {
474                 .start  = AT91SAM9261_LCDC_BASE,
475                 .end    = AT91SAM9261_LCDC_BASE + SZ_4K - 1,
476                 .flags  = IORESOURCE_MEM,
477         },
478         [1] = {
479                 .start  = AT91SAM9261_ID_LCDC,
480                 .end    = AT91SAM9261_ID_LCDC,
481                 .flags  = IORESOURCE_IRQ,
482         },
483 #if defined(CONFIG_FB_INTSRAM)
484         [2] = {
485                 .start  = AT91SAM9261_SRAM_BASE,
486                 .end    = AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE - 1,
487                 .flags  = IORESOURCE_MEM,
488         },
489 #endif
490 };
491
492 static struct platform_device at91_lcdc_device = {
493         .name           = "atmel_lcdfb",
494         .id             = 0,
495         .dev            = {
496                                 .dma_mask               = &lcdc_dmamask,
497                                 .coherent_dma_mask      = 0xffffffff,
498                                 .platform_data          = &lcdc_data,
499         },
500         .resource       = lcdc_resources,
501         .num_resources  = ARRAY_SIZE(lcdc_resources),
502 };
503
504 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
505 {
506         if (!data) {
507                 return;
508         }
509
510 #if defined(CONFIG_FB_ATMEL_STN)
511         at91_set_A_periph(AT91_PIN_PB0, 0);     /* LCDVSYNC */
512         at91_set_A_periph(AT91_PIN_PB1, 0);     /* LCDHSYNC */
513         at91_set_A_periph(AT91_PIN_PB2, 0);     /* LCDDOTCK */
514         at91_set_A_periph(AT91_PIN_PB3, 0);     /* LCDDEN */
515         at91_set_A_periph(AT91_PIN_PB4, 0);     /* LCDCC */
516         at91_set_A_periph(AT91_PIN_PB5, 0);     /* LCDD0 */
517         at91_set_A_periph(AT91_PIN_PB6, 0);     /* LCDD1 */
518         at91_set_A_periph(AT91_PIN_PB7, 0);     /* LCDD2 */
519         at91_set_A_periph(AT91_PIN_PB8, 0);     /* LCDD3 */
520 #else
521         at91_set_A_periph(AT91_PIN_PB1, 0);     /* LCDHSYNC */
522         at91_set_A_periph(AT91_PIN_PB2, 0);     /* LCDDOTCK */
523         at91_set_A_periph(AT91_PIN_PB3, 0);     /* LCDDEN */
524         at91_set_A_periph(AT91_PIN_PB4, 0);     /* LCDCC */
525         at91_set_A_periph(AT91_PIN_PB7, 0);     /* LCDD2 */
526         at91_set_A_periph(AT91_PIN_PB8, 0);     /* LCDD3 */
527         at91_set_A_periph(AT91_PIN_PB9, 0);     /* LCDD4 */
528         at91_set_A_periph(AT91_PIN_PB10, 0);    /* LCDD5 */
529         at91_set_A_periph(AT91_PIN_PB11, 0);    /* LCDD6 */
530         at91_set_A_periph(AT91_PIN_PB12, 0);    /* LCDD7 */
531         at91_set_A_periph(AT91_PIN_PB15, 0);    /* LCDD10 */
532         at91_set_A_periph(AT91_PIN_PB16, 0);    /* LCDD11 */
533         at91_set_A_periph(AT91_PIN_PB17, 0);    /* LCDD12 */
534         at91_set_A_periph(AT91_PIN_PB18, 0);    /* LCDD13 */
535         at91_set_A_periph(AT91_PIN_PB19, 0);    /* LCDD14 */
536         at91_set_A_periph(AT91_PIN_PB20, 0);    /* LCDD15 */
537         at91_set_B_periph(AT91_PIN_PB23, 0);    /* LCDD18 */
538         at91_set_B_periph(AT91_PIN_PB24, 0);    /* LCDD19 */
539         at91_set_B_periph(AT91_PIN_PB25, 0);    /* LCDD20 */
540         at91_set_B_periph(AT91_PIN_PB26, 0);    /* LCDD21 */
541         at91_set_B_periph(AT91_PIN_PB27, 0);    /* LCDD22 */
542         at91_set_B_periph(AT91_PIN_PB28, 0);    /* LCDD23 */
543 #endif
544
545         lcdc_data = *data;
546         platform_device_register(&at91_lcdc_device);
547 }
548 #else
549 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
550 #endif
551
552
553 /* --------------------------------------------------------------------
554  *  RTT
555  * -------------------------------------------------------------------- */
556
557 static struct resource rtt_resources[] = {
558         {
559                 .start  = AT91_BASE_SYS + AT91_RTT,
560                 .end    = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
561                 .flags  = IORESOURCE_MEM,
562         }
563 };
564
565 static struct platform_device at91sam9261_rtt_device = {
566         .name           = "at91_rtt",
567         .id             = -1,
568         .resource       = rtt_resources,
569         .num_resources  = ARRAY_SIZE(rtt_resources),
570 };
571
572 static void __init at91_add_device_rtt(void)
573 {
574         platform_device_register(&at91sam9261_rtt_device);
575 }
576
577
578 /* --------------------------------------------------------------------
579  *  Watchdog
580  * -------------------------------------------------------------------- */
581
582 #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
583 static struct platform_device at91sam9261_wdt_device = {
584         .name           = "at91_wdt",
585         .id             = -1,
586         .num_resources  = 0,
587 };
588
589 static void __init at91_add_device_watchdog(void)
590 {
591         platform_device_register(&at91sam9261_wdt_device);
592 }
593 #else
594 static void __init at91_add_device_watchdog(void) {}
595 #endif
596
597
598 /* --------------------------------------------------------------------
599  *  LEDs
600  * -------------------------------------------------------------------- */
601
602 #if defined(CONFIG_LEDS)
603 u8 at91_leds_cpu;
604 u8 at91_leds_timer;
605
606 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
607 {
608         /* Enable GPIO to access the LEDs */
609         at91_set_gpio_output(cpu_led, 1);
610         at91_set_gpio_output(timer_led, 1);
611
612         at91_leds_cpu   = cpu_led;
613         at91_leds_timer = timer_led;
614 }
615 #else
616 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
617 #endif
618
619
620 /* --------------------------------------------------------------------
621  *  UART
622  * -------------------------------------------------------------------- */
623
624 #if defined(CONFIG_SERIAL_ATMEL)
625 static struct resource dbgu_resources[] = {
626         [0] = {
627                 .start  = AT91_VA_BASE_SYS + AT91_DBGU,
628                 .end    = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
629                 .flags  = IORESOURCE_MEM,
630         },
631         [1] = {
632                 .start  = AT91_ID_SYS,
633                 .end    = AT91_ID_SYS,
634                 .flags  = IORESOURCE_IRQ,
635         },
636 };
637
638 static struct atmel_uart_data dbgu_data = {
639         .use_dma_tx     = 0,
640         .use_dma_rx     = 0,            /* DBGU not capable of receive DMA */
641         .regs           = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
642 };
643
644 static struct platform_device at91sam9261_dbgu_device = {
645         .name           = "atmel_usart",
646         .id             = 0,
647         .dev            = {
648                                 .platform_data  = &dbgu_data,
649                                 .coherent_dma_mask = 0xffffffff,
650         },
651         .resource       = dbgu_resources,
652         .num_resources  = ARRAY_SIZE(dbgu_resources),
653 };
654
655 static inline void configure_dbgu_pins(void)
656 {
657         at91_set_A_periph(AT91_PIN_PA9, 0);             /* DRXD */
658         at91_set_A_periph(AT91_PIN_PA10, 1);            /* DTXD */
659 }
660
661 static struct resource uart0_resources[] = {
662         [0] = {
663                 .start  = AT91SAM9261_BASE_US0,
664                 .end    = AT91SAM9261_BASE_US0 + SZ_16K - 1,
665                 .flags  = IORESOURCE_MEM,
666         },
667         [1] = {
668                 .start  = AT91SAM9261_ID_US0,
669                 .end    = AT91SAM9261_ID_US0,
670                 .flags  = IORESOURCE_IRQ,
671         },
672 };
673
674 static struct atmel_uart_data uart0_data = {
675         .use_dma_tx     = 1,
676         .use_dma_rx     = 1,
677 };
678
679 static struct platform_device at91sam9261_uart0_device = {
680         .name           = "atmel_usart",
681         .id             = 1,
682         .dev            = {
683                                 .platform_data  = &uart0_data,
684                                 .coherent_dma_mask = 0xffffffff,
685         },
686         .resource       = uart0_resources,
687         .num_resources  = ARRAY_SIZE(uart0_resources),
688 };
689
690 static inline void configure_usart0_pins(void)
691 {
692         at91_set_A_periph(AT91_PIN_PC8, 1);             /* TXD0 */
693         at91_set_A_periph(AT91_PIN_PC9, 0);             /* RXD0 */
694         at91_set_A_periph(AT91_PIN_PC10, 0);            /* RTS0 */
695         at91_set_A_periph(AT91_PIN_PC11, 0);            /* CTS0 */
696 }
697
698 static struct resource uart1_resources[] = {
699         [0] = {
700                 .start  = AT91SAM9261_BASE_US1,
701                 .end    = AT91SAM9261_BASE_US1 + SZ_16K - 1,
702                 .flags  = IORESOURCE_MEM,
703         },
704         [1] = {
705                 .start  = AT91SAM9261_ID_US1,
706                 .end    = AT91SAM9261_ID_US1,
707                 .flags  = IORESOURCE_IRQ,
708         },
709 };
710
711 static struct atmel_uart_data uart1_data = {
712         .use_dma_tx     = 1,
713         .use_dma_rx     = 1,
714 };
715
716 static struct platform_device at91sam9261_uart1_device = {
717         .name           = "atmel_usart",
718         .id             = 2,
719         .dev            = {
720                                 .platform_data  = &uart1_data,
721                                 .coherent_dma_mask = 0xffffffff,
722         },
723         .resource       = uart1_resources,
724         .num_resources  = ARRAY_SIZE(uart1_resources),
725 };
726
727 static inline void configure_usart1_pins(void)
728 {
729         at91_set_A_periph(AT91_PIN_PC12, 1);            /* TXD1 */
730         at91_set_A_periph(AT91_PIN_PC13, 0);            /* RXD1 */
731 }
732
733 static struct resource uart2_resources[] = {
734         [0] = {
735                 .start  = AT91SAM9261_BASE_US2,
736                 .end    = AT91SAM9261_BASE_US2 + SZ_16K - 1,
737                 .flags  = IORESOURCE_MEM,
738         },
739         [1] = {
740                 .start  = AT91SAM9261_ID_US2,
741                 .end    = AT91SAM9261_ID_US2,
742                 .flags  = IORESOURCE_IRQ,
743         },
744 };
745
746 static struct atmel_uart_data uart2_data = {
747         .use_dma_tx     = 1,
748         .use_dma_rx     = 1,
749 };
750
751 static struct platform_device at91sam9261_uart2_device = {
752         .name           = "atmel_usart",
753         .id             = 3,
754         .dev            = {
755                                 .platform_data  = &uart2_data,
756                                 .coherent_dma_mask = 0xffffffff,
757         },
758         .resource       = uart2_resources,
759         .num_resources  = ARRAY_SIZE(uart2_resources),
760 };
761
762 static inline void configure_usart2_pins(void)
763 {
764         at91_set_A_periph(AT91_PIN_PC15, 0);            /* RXD2 */
765         at91_set_A_periph(AT91_PIN_PC14, 1);            /* TXD2 */
766 }
767
768 struct platform_device *at91_uarts[ATMEL_MAX_UART];     /* the UARTs to use */
769 struct platform_device *atmel_default_console_device;   /* the serial console device */
770
771 void __init at91_init_serial(struct at91_uart_config *config)
772 {
773         int i;
774
775         /* Fill in list of supported UARTs */
776         for (i = 0; i < config->nr_tty; i++) {
777                 switch (config->tty_map[i]) {
778                         case 0:
779                                 configure_usart0_pins();
780                                 at91_uarts[i] = &at91sam9261_uart0_device;
781                                 at91_clock_associate("usart0_clk", &at91sam9261_uart0_device.dev, "usart");
782                                 break;
783                         case 1:
784                                 configure_usart1_pins();
785                                 at91_uarts[i] = &at91sam9261_uart1_device;
786                                 at91_clock_associate("usart1_clk", &at91sam9261_uart1_device.dev, "usart");
787                                 break;
788                         case 2:
789                                 configure_usart2_pins();
790                                 at91_uarts[i] = &at91sam9261_uart2_device;
791                                 at91_clock_associate("usart2_clk", &at91sam9261_uart2_device.dev, "usart");
792                                 break;
793                         case 3:
794                                 configure_dbgu_pins();
795                                 at91_uarts[i] = &at91sam9261_dbgu_device;
796                                 at91_clock_associate("mck", &at91sam9261_dbgu_device.dev, "usart");
797                                 break;
798                         default:
799                                 continue;
800                 }
801                 at91_uarts[i]->id = i;          /* update ID number to mapped ID */
802         }
803
804         /* Set serial console device */
805         if (config->console_tty < ATMEL_MAX_UART)
806                 atmel_default_console_device = at91_uarts[config->console_tty];
807         if (!atmel_default_console_device)
808                 printk(KERN_INFO "AT91: No default serial console defined.\n");
809 }
810
811 void __init at91_add_device_serial(void)
812 {
813         int i;
814
815         for (i = 0; i < ATMEL_MAX_UART; i++) {
816                 if (at91_uarts[i])
817                         platform_device_register(at91_uarts[i]);
818         }
819 }
820 #else
821 void __init at91_init_serial(struct at91_uart_config *config) {}
822 void __init at91_add_device_serial(void) {}
823 #endif
824
825
826 /* -------------------------------------------------------------------- */
827
828 /*
829  * These devices are always present and don't need any board-specific
830  * setup.
831  */
832 static int __init at91_add_standard_devices(void)
833 {
834         at91_add_device_rtt();
835         at91_add_device_watchdog();
836         return 0;
837 }
838
839 arch_initcall(at91_add_standard_devices);