Merge branch 'for-2.6.25' of git://git.kernel.org/pub/scm/linux/kernel/git/olof/pasem...
[sfrench/cifs-2.6.git] / arch / arm / mach-at91 / at91sam9263_devices.c
1 /*
2  * arch/arm/mach-at91/at91sam9263_devices.c
3  *
4  *  Copyright (C) 2007 Atmel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  */
12 #include <asm/mach/arch.h>
13 #include <asm/mach/map.h>
14
15 #include <linux/platform_device.h>
16 #include <linux/i2c-gpio.h>
17
18 #include <linux/fb.h>
19 #include <video/atmel_lcdc.h>
20
21 #include <asm/arch/board.h>
22 #include <asm/arch/gpio.h>
23 #include <asm/arch/at91sam9263.h>
24 #include <asm/arch/at91sam926x_mc.h>
25 #include <asm/arch/at91sam9263_matrix.h>
26
27 #include "generic.h"
28
29
30 /* --------------------------------------------------------------------
31  *  USB Host
32  * -------------------------------------------------------------------- */
33
34 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
35 static u64 ohci_dmamask = 0xffffffffUL;
36 static struct at91_usbh_data usbh_data;
37
38 static struct resource usbh_resources[] = {
39         [0] = {
40                 .start  = AT91SAM9263_UHP_BASE,
41                 .end    = AT91SAM9263_UHP_BASE + SZ_1M - 1,
42                 .flags  = IORESOURCE_MEM,
43         },
44         [1] = {
45                 .start  = AT91SAM9263_ID_UHP,
46                 .end    = AT91SAM9263_ID_UHP,
47                 .flags  = IORESOURCE_IRQ,
48         },
49 };
50
51 static struct platform_device at91_usbh_device = {
52         .name           = "at91_ohci",
53         .id             = -1,
54         .dev            = {
55                                 .dma_mask               = &ohci_dmamask,
56                                 .coherent_dma_mask      = 0xffffffff,
57                                 .platform_data          = &usbh_data,
58         },
59         .resource       = usbh_resources,
60         .num_resources  = ARRAY_SIZE(usbh_resources),
61 };
62
63 void __init at91_add_device_usbh(struct at91_usbh_data *data)
64 {
65         int i;
66
67         if (!data)
68                 return;
69
70         /* Enable VBus control for UHP ports */
71         for (i = 0; i < data->ports; i++) {
72                 if (data->vbus_pin[i])
73                         at91_set_gpio_output(data->vbus_pin[i], 0);
74         }
75
76         usbh_data = *data;
77         platform_device_register(&at91_usbh_device);
78 }
79 #else
80 void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
81 #endif
82
83
84 /* --------------------------------------------------------------------
85  *  USB Device (Gadget)
86  * -------------------------------------------------------------------- */
87
88 #ifdef CONFIG_USB_GADGET_AT91
89 static struct at91_udc_data udc_data;
90
91 static struct resource udc_resources[] = {
92         [0] = {
93                 .start  = AT91SAM9263_BASE_UDP,
94                 .end    = AT91SAM9263_BASE_UDP + SZ_16K - 1,
95                 .flags  = IORESOURCE_MEM,
96         },
97         [1] = {
98                 .start  = AT91SAM9263_ID_UDP,
99                 .end    = AT91SAM9263_ID_UDP,
100                 .flags  = IORESOURCE_IRQ,
101         },
102 };
103
104 static struct platform_device at91_udc_device = {
105         .name           = "at91_udc",
106         .id             = -1,
107         .dev            = {
108                                 .platform_data          = &udc_data,
109         },
110         .resource       = udc_resources,
111         .num_resources  = ARRAY_SIZE(udc_resources),
112 };
113
114 void __init at91_add_device_udc(struct at91_udc_data *data)
115 {
116         if (!data)
117                 return;
118
119         if (data->vbus_pin) {
120                 at91_set_gpio_input(data->vbus_pin, 0);
121                 at91_set_deglitch(data->vbus_pin, 1);
122         }
123
124         /* Pullup pin is handled internally by USB device peripheral */
125
126         udc_data = *data;
127         platform_device_register(&at91_udc_device);
128 }
129 #else
130 void __init at91_add_device_udc(struct at91_udc_data *data) {}
131 #endif
132
133
134 /* --------------------------------------------------------------------
135  *  Ethernet
136  * -------------------------------------------------------------------- */
137
138 #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
139 static u64 eth_dmamask = 0xffffffffUL;
140 static struct at91_eth_data eth_data;
141
142 static struct resource eth_resources[] = {
143         [0] = {
144                 .start  = AT91SAM9263_BASE_EMAC,
145                 .end    = AT91SAM9263_BASE_EMAC + SZ_16K - 1,
146                 .flags  = IORESOURCE_MEM,
147         },
148         [1] = {
149                 .start  = AT91SAM9263_ID_EMAC,
150                 .end    = AT91SAM9263_ID_EMAC,
151                 .flags  = IORESOURCE_IRQ,
152         },
153 };
154
155 static struct platform_device at91sam9263_eth_device = {
156         .name           = "macb",
157         .id             = -1,
158         .dev            = {
159                                 .dma_mask               = &eth_dmamask,
160                                 .coherent_dma_mask      = 0xffffffff,
161                                 .platform_data          = &eth_data,
162         },
163         .resource       = eth_resources,
164         .num_resources  = ARRAY_SIZE(eth_resources),
165 };
166
167 void __init at91_add_device_eth(struct at91_eth_data *data)
168 {
169         if (!data)
170                 return;
171
172         if (data->phy_irq_pin) {
173                 at91_set_gpio_input(data->phy_irq_pin, 0);
174                 at91_set_deglitch(data->phy_irq_pin, 1);
175         }
176
177         /* Pins used for MII and RMII */
178         at91_set_A_periph(AT91_PIN_PE21, 0);    /* ETXCK_EREFCK */
179         at91_set_B_periph(AT91_PIN_PC25, 0);    /* ERXDV */
180         at91_set_A_periph(AT91_PIN_PE25, 0);    /* ERX0 */
181         at91_set_A_periph(AT91_PIN_PE26, 0);    /* ERX1 */
182         at91_set_A_periph(AT91_PIN_PE27, 0);    /* ERXER */
183         at91_set_A_periph(AT91_PIN_PE28, 0);    /* ETXEN */
184         at91_set_A_periph(AT91_PIN_PE23, 0);    /* ETX0 */
185         at91_set_A_periph(AT91_PIN_PE24, 0);    /* ETX1 */
186         at91_set_A_periph(AT91_PIN_PE30, 0);    /* EMDIO */
187         at91_set_A_periph(AT91_PIN_PE29, 0);    /* EMDC */
188
189         if (!data->is_rmii) {
190                 at91_set_A_periph(AT91_PIN_PE22, 0);    /* ECRS */
191                 at91_set_B_periph(AT91_PIN_PC26, 0);    /* ECOL */
192                 at91_set_B_periph(AT91_PIN_PC22, 0);    /* ERX2 */
193                 at91_set_B_periph(AT91_PIN_PC23, 0);    /* ERX3 */
194                 at91_set_B_periph(AT91_PIN_PC27, 0);    /* ERXCK */
195                 at91_set_B_periph(AT91_PIN_PC20, 0);    /* ETX2 */
196                 at91_set_B_periph(AT91_PIN_PC21, 0);    /* ETX3 */
197                 at91_set_B_periph(AT91_PIN_PC24, 0);    /* ETXER */
198         }
199
200         eth_data = *data;
201         platform_device_register(&at91sam9263_eth_device);
202 }
203 #else
204 void __init at91_add_device_eth(struct at91_eth_data *data) {}
205 #endif
206
207
208 /* --------------------------------------------------------------------
209  *  MMC / SD
210  * -------------------------------------------------------------------- */
211
212 #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
213 static u64 mmc_dmamask = 0xffffffffUL;
214 static struct at91_mmc_data mmc0_data, mmc1_data;
215
216 static struct resource mmc0_resources[] = {
217         [0] = {
218                 .start  = AT91SAM9263_BASE_MCI0,
219                 .end    = AT91SAM9263_BASE_MCI0 + SZ_16K - 1,
220                 .flags  = IORESOURCE_MEM,
221         },
222         [1] = {
223                 .start  = AT91SAM9263_ID_MCI0,
224                 .end    = AT91SAM9263_ID_MCI0,
225                 .flags  = IORESOURCE_IRQ,
226         },
227 };
228
229 static struct platform_device at91sam9263_mmc0_device = {
230         .name           = "at91_mci",
231         .id             = 0,
232         .dev            = {
233                                 .dma_mask               = &mmc_dmamask,
234                                 .coherent_dma_mask      = 0xffffffff,
235                                 .platform_data          = &mmc0_data,
236         },
237         .resource       = mmc0_resources,
238         .num_resources  = ARRAY_SIZE(mmc0_resources),
239 };
240
241 static struct resource mmc1_resources[] = {
242         [0] = {
243                 .start  = AT91SAM9263_BASE_MCI1,
244                 .end    = AT91SAM9263_BASE_MCI1 + SZ_16K - 1,
245                 .flags  = IORESOURCE_MEM,
246         },
247         [1] = {
248                 .start  = AT91SAM9263_ID_MCI1,
249                 .end    = AT91SAM9263_ID_MCI1,
250                 .flags  = IORESOURCE_IRQ,
251         },
252 };
253
254 static struct platform_device at91sam9263_mmc1_device = {
255         .name           = "at91_mci",
256         .id             = 1,
257         .dev            = {
258                                 .dma_mask               = &mmc_dmamask,
259                                 .coherent_dma_mask      = 0xffffffff,
260                                 .platform_data          = &mmc1_data,
261         },
262         .resource       = mmc1_resources,
263         .num_resources  = ARRAY_SIZE(mmc1_resources),
264 };
265
266 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
267 {
268         if (!data)
269                 return;
270
271         /* input/irq */
272         if (data->det_pin) {
273                 at91_set_gpio_input(data->det_pin, 1);
274                 at91_set_deglitch(data->det_pin, 1);
275         }
276         if (data->wp_pin)
277                 at91_set_gpio_input(data->wp_pin, 1);
278         if (data->vcc_pin)
279                 at91_set_gpio_output(data->vcc_pin, 0);
280
281         if (mmc_id == 0) {              /* MCI0 */
282                 /* CLK */
283                 at91_set_A_periph(AT91_PIN_PA12, 0);
284
285                 if (data->slot_b) {
286                         /* CMD */
287                         at91_set_A_periph(AT91_PIN_PA16, 1);
288
289                         /* DAT0, maybe DAT1..DAT3 */
290                         at91_set_A_periph(AT91_PIN_PA17, 1);
291                         if (data->wire4) {
292                                 at91_set_A_periph(AT91_PIN_PA18, 1);
293                                 at91_set_A_periph(AT91_PIN_PA19, 1);
294                                 at91_set_A_periph(AT91_PIN_PA20, 1);
295                         }
296                 } else {
297                         /* CMD */
298                         at91_set_A_periph(AT91_PIN_PA1, 1);
299
300                         /* DAT0, maybe DAT1..DAT3 */
301                         at91_set_A_periph(AT91_PIN_PA0, 1);
302                         if (data->wire4) {
303                                 at91_set_A_periph(AT91_PIN_PA3, 1);
304                                 at91_set_A_periph(AT91_PIN_PA4, 1);
305                                 at91_set_A_periph(AT91_PIN_PA5, 1);
306                         }
307                 }
308
309                 mmc0_data = *data;
310                 at91_clock_associate("mci0_clk", &at91sam9263_mmc1_device.dev, "mci_clk");
311                 platform_device_register(&at91sam9263_mmc0_device);
312         } else {                        /* MCI1 */
313                 /* CLK */
314                 at91_set_A_periph(AT91_PIN_PA6, 0);
315
316                 if (data->slot_b) {
317                         /* CMD */
318                         at91_set_A_periph(AT91_PIN_PA21, 1);
319
320                         /* DAT0, maybe DAT1..DAT3 */
321                         at91_set_A_periph(AT91_PIN_PA22, 1);
322                         if (data->wire4) {
323                                 at91_set_A_periph(AT91_PIN_PA23, 1);
324                                 at91_set_A_periph(AT91_PIN_PA24, 1);
325                                 at91_set_A_periph(AT91_PIN_PA25, 1);
326                         }
327                 } else {
328                         /* CMD */
329                         at91_set_A_periph(AT91_PIN_PA7, 1);
330
331                         /* DAT0, maybe DAT1..DAT3 */
332                         at91_set_A_periph(AT91_PIN_PA8, 1);
333                         if (data->wire4) {
334                                 at91_set_A_periph(AT91_PIN_PA9, 1);
335                                 at91_set_A_periph(AT91_PIN_PA10, 1);
336                                 at91_set_A_periph(AT91_PIN_PA11, 1);
337                         }
338                 }
339
340                 mmc1_data = *data;
341                 at91_clock_associate("mci1_clk", &at91sam9263_mmc1_device.dev, "mci_clk");
342                 platform_device_register(&at91sam9263_mmc1_device);
343         }
344 }
345 #else
346 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
347 #endif
348
349
350 /* --------------------------------------------------------------------
351  *  NAND / SmartMedia
352  * -------------------------------------------------------------------- */
353
354 #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
355 static struct at91_nand_data nand_data;
356
357 #define NAND_BASE       AT91_CHIPSELECT_3
358
359 static struct resource nand_resources[] = {
360         {
361                 .start  = NAND_BASE,
362                 .end    = NAND_BASE + SZ_256M - 1,
363                 .flags  = IORESOURCE_MEM,
364         }
365 };
366
367 static struct platform_device at91sam9263_nand_device = {
368         .name           = "at91_nand",
369         .id             = -1,
370         .dev            = {
371                                 .platform_data  = &nand_data,
372         },
373         .resource       = nand_resources,
374         .num_resources  = ARRAY_SIZE(nand_resources),
375 };
376
377 void __init at91_add_device_nand(struct at91_nand_data *data)
378 {
379         unsigned long csa, mode;
380
381         if (!data)
382                 return;
383
384         csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
385         at91_sys_write(AT91_MATRIX_EBI0CSA, csa | AT91_MATRIX_EBI0_CS3A_SMC);
386
387         /* set the bus interface characteristics */
388         at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
389                         | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
390
391         at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
392                         | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
393
394         at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
395
396         if (data->bus_width_16)
397                 mode = AT91_SMC_DBW_16;
398         else
399                 mode = AT91_SMC_DBW_8;
400         at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
401
402         /* enable pin */
403         if (data->enable_pin)
404                 at91_set_gpio_output(data->enable_pin, 1);
405
406         /* ready/busy pin */
407         if (data->rdy_pin)
408                 at91_set_gpio_input(data->rdy_pin, 1);
409
410         /* card detect pin */
411         if (data->det_pin)
412                 at91_set_gpio_input(data->det_pin, 1);
413
414         nand_data = *data;
415         platform_device_register(&at91sam9263_nand_device);
416 }
417 #else
418 void __init at91_add_device_nand(struct at91_nand_data *data) {}
419 #endif
420
421
422 /* --------------------------------------------------------------------
423  *  TWI (i2c)
424  * -------------------------------------------------------------------- */
425
426 /*
427  * Prefer the GPIO code since the TWI controller isn't robust
428  * (gets overruns and underruns under load) and can only issue
429  * repeated STARTs in one scenario (the driver doesn't yet handle them).
430  */
431 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
432
433 static struct i2c_gpio_platform_data pdata = {
434         .sda_pin                = AT91_PIN_PB4,
435         .sda_is_open_drain      = 1,
436         .scl_pin                = AT91_PIN_PB5,
437         .scl_is_open_drain      = 1,
438         .udelay                 = 2,            /* ~100 kHz */
439 };
440
441 static struct platform_device at91sam9263_twi_device = {
442         .name                   = "i2c-gpio",
443         .id                     = -1,
444         .dev.platform_data      = &pdata,
445 };
446
447 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
448 {
449         at91_set_GPIO_periph(AT91_PIN_PB4, 1);          /* TWD (SDA) */
450         at91_set_multi_drive(AT91_PIN_PB4, 1);
451
452         at91_set_GPIO_periph(AT91_PIN_PB5, 1);          /* TWCK (SCL) */
453         at91_set_multi_drive(AT91_PIN_PB5, 1);
454
455         i2c_register_board_info(0, devices, nr_devices);
456         platform_device_register(&at91sam9263_twi_device);
457 }
458
459 #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
460
461 static struct resource twi_resources[] = {
462         [0] = {
463                 .start  = AT91SAM9263_BASE_TWI,
464                 .end    = AT91SAM9263_BASE_TWI + SZ_16K - 1,
465                 .flags  = IORESOURCE_MEM,
466         },
467         [1] = {
468                 .start  = AT91SAM9263_ID_TWI,
469                 .end    = AT91SAM9263_ID_TWI,
470                 .flags  = IORESOURCE_IRQ,
471         },
472 };
473
474 static struct platform_device at91sam9263_twi_device = {
475         .name           = "at91_i2c",
476         .id             = -1,
477         .resource       = twi_resources,
478         .num_resources  = ARRAY_SIZE(twi_resources),
479 };
480
481 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
482 {
483         /* pins used for TWI interface */
484         at91_set_A_periph(AT91_PIN_PB4, 0);             /* TWD */
485         at91_set_multi_drive(AT91_PIN_PB4, 1);
486
487         at91_set_A_periph(AT91_PIN_PB5, 0);             /* TWCK */
488         at91_set_multi_drive(AT91_PIN_PB5, 1);
489
490         i2c_register_board_info(0, devices, nr_devices);
491         platform_device_register(&at91sam9263_twi_device);
492 }
493 #else
494 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
495 #endif
496
497
498 /* --------------------------------------------------------------------
499  *  SPI
500  * -------------------------------------------------------------------- */
501
502 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
503 static u64 spi_dmamask = 0xffffffffUL;
504
505 static struct resource spi0_resources[] = {
506         [0] = {
507                 .start  = AT91SAM9263_BASE_SPI0,
508                 .end    = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
509                 .flags  = IORESOURCE_MEM,
510         },
511         [1] = {
512                 .start  = AT91SAM9263_ID_SPI0,
513                 .end    = AT91SAM9263_ID_SPI0,
514                 .flags  = IORESOURCE_IRQ,
515         },
516 };
517
518 static struct platform_device at91sam9263_spi0_device = {
519         .name           = "atmel_spi",
520         .id             = 0,
521         .dev            = {
522                                 .dma_mask               = &spi_dmamask,
523                                 .coherent_dma_mask      = 0xffffffff,
524         },
525         .resource       = spi0_resources,
526         .num_resources  = ARRAY_SIZE(spi0_resources),
527 };
528
529 static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
530
531 static struct resource spi1_resources[] = {
532         [0] = {
533                 .start  = AT91SAM9263_BASE_SPI1,
534                 .end    = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
535                 .flags  = IORESOURCE_MEM,
536         },
537         [1] = {
538                 .start  = AT91SAM9263_ID_SPI1,
539                 .end    = AT91SAM9263_ID_SPI1,
540                 .flags  = IORESOURCE_IRQ,
541         },
542 };
543
544 static struct platform_device at91sam9263_spi1_device = {
545         .name           = "atmel_spi",
546         .id             = 1,
547         .dev            = {
548                                 .dma_mask               = &spi_dmamask,
549                                 .coherent_dma_mask      = 0xffffffff,
550         },
551         .resource       = spi1_resources,
552         .num_resources  = ARRAY_SIZE(spi1_resources),
553 };
554
555 static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
556
557 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
558 {
559         int i;
560         unsigned long cs_pin;
561         short enable_spi0 = 0;
562         short enable_spi1 = 0;
563
564         /* Choose SPI chip-selects */
565         for (i = 0; i < nr_devices; i++) {
566                 if (devices[i].controller_data)
567                         cs_pin = (unsigned long) devices[i].controller_data;
568                 else if (devices[i].bus_num == 0)
569                         cs_pin = spi0_standard_cs[devices[i].chip_select];
570                 else
571                         cs_pin = spi1_standard_cs[devices[i].chip_select];
572
573                 if (devices[i].bus_num == 0)
574                         enable_spi0 = 1;
575                 else
576                         enable_spi1 = 1;
577
578                 /* enable chip-select pin */
579                 at91_set_gpio_output(cs_pin, 1);
580
581                 /* pass chip-select pin to driver */
582                 devices[i].controller_data = (void *) cs_pin;
583         }
584
585         spi_register_board_info(devices, nr_devices);
586
587         /* Configure SPI bus(es) */
588         if (enable_spi0) {
589                 at91_set_B_periph(AT91_PIN_PA0, 0);     /* SPI0_MISO */
590                 at91_set_B_periph(AT91_PIN_PA1, 0);     /* SPI0_MOSI */
591                 at91_set_B_periph(AT91_PIN_PA2, 0);     /* SPI0_SPCK */
592
593                 at91_clock_associate("spi0_clk", &at91sam9263_spi0_device.dev, "spi_clk");
594                 platform_device_register(&at91sam9263_spi0_device);
595         }
596         if (enable_spi1) {
597                 at91_set_A_periph(AT91_PIN_PB12, 0);    /* SPI1_MISO */
598                 at91_set_A_periph(AT91_PIN_PB13, 0);    /* SPI1_MOSI */
599                 at91_set_A_periph(AT91_PIN_PB14, 0);    /* SPI1_SPCK */
600
601                 at91_clock_associate("spi1_clk", &at91sam9263_spi1_device.dev, "spi_clk");
602                 platform_device_register(&at91sam9263_spi1_device);
603         }
604 }
605 #else
606 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
607 #endif
608
609
610 /* --------------------------------------------------------------------
611  *  AC97
612  * -------------------------------------------------------------------- */
613
614 #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
615 static u64 ac97_dmamask = 0xffffffffUL;
616 static struct atmel_ac97_data ac97_data;
617
618 static struct resource ac97_resources[] = {
619         [0] = {
620                 .start  = AT91SAM9263_BASE_AC97C,
621                 .end    = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
622                 .flags  = IORESOURCE_MEM,
623         },
624         [1] = {
625                 .start  = AT91SAM9263_ID_AC97C,
626                 .end    = AT91SAM9263_ID_AC97C,
627                 .flags  = IORESOURCE_IRQ,
628         },
629 };
630
631 static struct platform_device at91sam9263_ac97_device = {
632         .name           = "ac97c",
633         .id             = 1,
634         .dev            = {
635                                 .dma_mask               = &ac97_dmamask,
636                                 .coherent_dma_mask      = 0xffffffff,
637                                 .platform_data          = &ac97_data,
638         },
639         .resource       = ac97_resources,
640         .num_resources  = ARRAY_SIZE(ac97_resources),
641 };
642
643 void __init at91_add_device_ac97(struct atmel_ac97_data *data)
644 {
645         if (!data)
646                 return;
647
648         at91_set_A_periph(AT91_PIN_PB0, 0);     /* AC97FS */
649         at91_set_A_periph(AT91_PIN_PB1, 0);     /* AC97CK */
650         at91_set_A_periph(AT91_PIN_PB2, 0);     /* AC97TX */
651         at91_set_A_periph(AT91_PIN_PB3, 0);     /* AC97RX */
652
653         /* reset */
654         if (data->reset_pin)
655                 at91_set_gpio_output(data->reset_pin, 0);
656
657         ac97_data = *ek_data;
658         platform_device_register(&at91sam9263_ac97_device);
659 }
660 #else
661 void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
662 #endif
663
664
665 /* --------------------------------------------------------------------
666  *  LCD Controller
667  * -------------------------------------------------------------------- */
668
669 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
670 static u64 lcdc_dmamask = 0xffffffffUL;
671 static struct atmel_lcdfb_info lcdc_data;
672
673 static struct resource lcdc_resources[] = {
674         [0] = {
675                 .start  = AT91SAM9263_LCDC_BASE,
676                 .end    = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
677                 .flags  = IORESOURCE_MEM,
678         },
679         [1] = {
680                 .start  = AT91SAM9263_ID_LCDC,
681                 .end    = AT91SAM9263_ID_LCDC,
682                 .flags  = IORESOURCE_IRQ,
683         },
684 };
685
686 static struct platform_device at91_lcdc_device = {
687         .name           = "atmel_lcdfb",
688         .id             = 0,
689         .dev            = {
690                                 .dma_mask               = &lcdc_dmamask,
691                                 .coherent_dma_mask      = 0xffffffff,
692                                 .platform_data          = &lcdc_data,
693         },
694         .resource       = lcdc_resources,
695         .num_resources  = ARRAY_SIZE(lcdc_resources),
696 };
697
698 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
699 {
700         if (!data)
701                 return;
702
703         at91_set_A_periph(AT91_PIN_PC1, 0);     /* LCDHSYNC */
704         at91_set_A_periph(AT91_PIN_PC2, 0);     /* LCDDOTCK */
705         at91_set_A_periph(AT91_PIN_PC3, 0);     /* LCDDEN */
706         at91_set_B_periph(AT91_PIN_PB9, 0);     /* LCDCC */
707         at91_set_A_periph(AT91_PIN_PC6, 0);     /* LCDD2 */
708         at91_set_A_periph(AT91_PIN_PC7, 0);     /* LCDD3 */
709         at91_set_A_periph(AT91_PIN_PC8, 0);     /* LCDD4 */
710         at91_set_A_periph(AT91_PIN_PC9, 0);     /* LCDD5 */
711         at91_set_A_periph(AT91_PIN_PC10, 0);    /* LCDD6 */
712         at91_set_A_periph(AT91_PIN_PC11, 0);    /* LCDD7 */
713         at91_set_A_periph(AT91_PIN_PC14, 0);    /* LCDD10 */
714         at91_set_A_periph(AT91_PIN_PC15, 0);    /* LCDD11 */
715         at91_set_A_periph(AT91_PIN_PC16, 0);    /* LCDD12 */
716         at91_set_B_periph(AT91_PIN_PC12, 0);    /* LCDD13 */
717         at91_set_A_periph(AT91_PIN_PC18, 0);    /* LCDD14 */
718         at91_set_A_periph(AT91_PIN_PC19, 0);    /* LCDD15 */
719         at91_set_A_periph(AT91_PIN_PC22, 0);    /* LCDD18 */
720         at91_set_A_periph(AT91_PIN_PC23, 0);    /* LCDD19 */
721         at91_set_A_periph(AT91_PIN_PC24, 0);    /* LCDD20 */
722         at91_set_B_periph(AT91_PIN_PC17, 0);    /* LCDD21 */
723         at91_set_A_periph(AT91_PIN_PC26, 0);    /* LCDD22 */
724         at91_set_A_periph(AT91_PIN_PC27, 0);    /* LCDD23 */
725
726         lcdc_data = *data;
727         platform_device_register(&at91_lcdc_device);
728 }
729 #else
730 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
731 #endif
732
733
734 /* --------------------------------------------------------------------
735  *  LEDs
736  * -------------------------------------------------------------------- */
737
738 #if defined(CONFIG_LEDS)
739 u8 at91_leds_cpu;
740 u8 at91_leds_timer;
741
742 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
743 {
744         /* Enable GPIO to access the LEDs */
745         at91_set_gpio_output(cpu_led, 1);
746         at91_set_gpio_output(timer_led, 1);
747
748         at91_leds_cpu   = cpu_led;
749         at91_leds_timer = timer_led;
750 }
751 #else
752 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
753 #endif
754
755
756 /* --------------------------------------------------------------------
757  *  UART
758  * -------------------------------------------------------------------- */
759
760 #if defined(CONFIG_SERIAL_ATMEL)
761
762 static struct resource dbgu_resources[] = {
763         [0] = {
764                 .start  = AT91_VA_BASE_SYS + AT91_DBGU,
765                 .end    = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
766                 .flags  = IORESOURCE_MEM,
767         },
768         [1] = {
769                 .start  = AT91_ID_SYS,
770                 .end    = AT91_ID_SYS,
771                 .flags  = IORESOURCE_IRQ,
772         },
773 };
774
775 static struct atmel_uart_data dbgu_data = {
776         .use_dma_tx     = 0,
777         .use_dma_rx     = 0,            /* DBGU not capable of receive DMA */
778         .regs           = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
779 };
780
781 static struct platform_device at91sam9263_dbgu_device = {
782         .name           = "atmel_usart",
783         .id             = 0,
784         .dev            = {
785                                 .platform_data  = &dbgu_data,
786                                 .coherent_dma_mask = 0xffffffff,
787         },
788         .resource       = dbgu_resources,
789         .num_resources  = ARRAY_SIZE(dbgu_resources),
790 };
791
792 static inline void configure_dbgu_pins(void)
793 {
794         at91_set_A_periph(AT91_PIN_PC30, 0);            /* DRXD */
795         at91_set_A_periph(AT91_PIN_PC31, 1);            /* DTXD */
796 }
797
798 static struct resource uart0_resources[] = {
799         [0] = {
800                 .start  = AT91SAM9263_BASE_US0,
801                 .end    = AT91SAM9263_BASE_US0 + SZ_16K - 1,
802                 .flags  = IORESOURCE_MEM,
803         },
804         [1] = {
805                 .start  = AT91SAM9263_ID_US0,
806                 .end    = AT91SAM9263_ID_US0,
807                 .flags  = IORESOURCE_IRQ,
808         },
809 };
810
811 static struct atmel_uart_data uart0_data = {
812         .use_dma_tx     = 1,
813         .use_dma_rx     = 1,
814 };
815
816 static struct platform_device at91sam9263_uart0_device = {
817         .name           = "atmel_usart",
818         .id             = 1,
819         .dev            = {
820                                 .platform_data  = &uart0_data,
821                                 .coherent_dma_mask = 0xffffffff,
822         },
823         .resource       = uart0_resources,
824         .num_resources  = ARRAY_SIZE(uart0_resources),
825 };
826
827 static inline void configure_usart0_pins(void)
828 {
829         at91_set_A_periph(AT91_PIN_PA26, 1);            /* TXD0 */
830         at91_set_A_periph(AT91_PIN_PA27, 0);            /* RXD0 */
831         at91_set_A_periph(AT91_PIN_PA28, 0);            /* RTS0 */
832         at91_set_A_periph(AT91_PIN_PA29, 0);            /* CTS0 */
833 }
834
835 static struct resource uart1_resources[] = {
836         [0] = {
837                 .start  = AT91SAM9263_BASE_US1,
838                 .end    = AT91SAM9263_BASE_US1 + SZ_16K - 1,
839                 .flags  = IORESOURCE_MEM,
840         },
841         [1] = {
842                 .start  = AT91SAM9263_ID_US1,
843                 .end    = AT91SAM9263_ID_US1,
844                 .flags  = IORESOURCE_IRQ,
845         },
846 };
847
848 static struct atmel_uart_data uart1_data = {
849         .use_dma_tx     = 1,
850         .use_dma_rx     = 1,
851 };
852
853 static struct platform_device at91sam9263_uart1_device = {
854         .name           = "atmel_usart",
855         .id             = 2,
856         .dev            = {
857                                 .platform_data  = &uart1_data,
858                                 .coherent_dma_mask = 0xffffffff,
859         },
860         .resource       = uart1_resources,
861         .num_resources  = ARRAY_SIZE(uart1_resources),
862 };
863
864 static inline void configure_usart1_pins(void)
865 {
866         at91_set_A_periph(AT91_PIN_PD0, 1);             /* TXD1 */
867         at91_set_A_periph(AT91_PIN_PD1, 0);             /* RXD1 */
868         at91_set_B_periph(AT91_PIN_PD7, 0);             /* RTS1 */
869         at91_set_B_periph(AT91_PIN_PD8, 0);             /* CTS1 */
870 }
871
872 static struct resource uart2_resources[] = {
873         [0] = {
874                 .start  = AT91SAM9263_BASE_US2,
875                 .end    = AT91SAM9263_BASE_US2 + SZ_16K - 1,
876                 .flags  = IORESOURCE_MEM,
877         },
878         [1] = {
879                 .start  = AT91SAM9263_ID_US2,
880                 .end    = AT91SAM9263_ID_US2,
881                 .flags  = IORESOURCE_IRQ,
882         },
883 };
884
885 static struct atmel_uart_data uart2_data = {
886         .use_dma_tx     = 1,
887         .use_dma_rx     = 1,
888 };
889
890 static struct platform_device at91sam9263_uart2_device = {
891         .name           = "atmel_usart",
892         .id             = 3,
893         .dev            = {
894                                 .platform_data  = &uart2_data,
895                                 .coherent_dma_mask = 0xffffffff,
896         },
897         .resource       = uart2_resources,
898         .num_resources  = ARRAY_SIZE(uart2_resources),
899 };
900
901 static inline void configure_usart2_pins(void)
902 {
903         at91_set_A_periph(AT91_PIN_PD2, 1);             /* TXD2 */
904         at91_set_A_periph(AT91_PIN_PD3, 0);             /* RXD2 */
905         at91_set_B_periph(AT91_PIN_PD5, 0);             /* RTS2 */
906         at91_set_B_periph(AT91_PIN_PD6, 0);             /* CTS2 */
907 }
908
909 struct platform_device *at91_uarts[ATMEL_MAX_UART];     /* the UARTs to use */
910 struct platform_device *atmel_default_console_device;   /* the serial console device */
911
912 void __init at91_init_serial(struct at91_uart_config *config)
913 {
914         int i;
915
916         /* Fill in list of supported UARTs */
917         for (i = 0; i < config->nr_tty; i++) {
918                 switch (config->tty_map[i]) {
919                         case 0:
920                                 configure_usart0_pins();
921                                 at91_uarts[i] = &at91sam9263_uart0_device;
922                                 at91_clock_associate("usart0_clk", &at91sam9263_uart0_device.dev, "usart");
923                                 break;
924                         case 1:
925                                 configure_usart1_pins();
926                                 at91_uarts[i] = &at91sam9263_uart1_device;
927                                 at91_clock_associate("usart1_clk", &at91sam9263_uart1_device.dev, "usart");
928                                 break;
929                         case 2:
930                                 configure_usart2_pins();
931                                 at91_uarts[i] = &at91sam9263_uart2_device;
932                                 at91_clock_associate("usart2_clk", &at91sam9263_uart2_device.dev, "usart");
933                                 break;
934                         case 3:
935                                 configure_dbgu_pins();
936                                 at91_uarts[i] = &at91sam9263_dbgu_device;
937                                 at91_clock_associate("mck", &at91sam9263_dbgu_device.dev, "usart");
938                                 break;
939                         default:
940                                 continue;
941                 }
942                 at91_uarts[i]->id = i;          /* update ID number to mapped ID */
943         }
944
945         /* Set serial console device */
946         if (config->console_tty < ATMEL_MAX_UART)
947                 atmel_default_console_device = at91_uarts[config->console_tty];
948         if (!atmel_default_console_device)
949                 printk(KERN_INFO "AT91: No default serial console defined.\n");
950 }
951
952 void __init at91_add_device_serial(void)
953 {
954         int i;
955
956         for (i = 0; i < ATMEL_MAX_UART; i++) {
957                 if (at91_uarts[i])
958                         platform_device_register(at91_uarts[i]);
959         }
960 }
961 #else
962 void __init at91_init_serial(struct at91_uart_config *config) {}
963 void __init at91_add_device_serial(void) {}
964 #endif
965
966
967 /* -------------------------------------------------------------------- */
968 /*
969  * These devices are always present and don't need any board-specific
970  * setup.
971  */
972 static int __init at91_add_standard_devices(void)
973 {
974         return 0;
975 }
976
977 arch_initcall(at91_add_standard_devices);