]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-at91/at91sam9263_devices.c
b4eb21769db917421c5e173989768fa0cfdc19b5
[linux-2.6-omap-h63xx.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  *  Image Sensor Interface
736  * -------------------------------------------------------------------- */
737
738 #if defined(CONFIG_VIDEO_AT91_ISI) || defined(CONFIG_VIDEO_AT91_ISI_MODULE)
739
740 struct resource isi_resources[] = {
741         [0] = {
742                 .start  = AT91SAM9263_BASE_ISI,
743                 .end    = AT91SAM9263_BASE_ISI + SZ_16K - 1,
744                 .flags  = IORESOURCE_MEM,
745         },
746         [1] = {
747                 .start  = AT91SAM9263_ID_ISI,
748                 .end    = AT91SAM9263_ID_ISI,
749                 .flags  = IORESOURCE_IRQ,
750         },
751 };
752
753 static struct platform_device at91sam9263_isi_device = {
754         .name           = "at91_isi",
755         .id             = -1,
756         .resource       = isi_resources,
757         .num_resources  = ARRAY_SIZE(isi_resources),
758 };
759
760 void __init at91_add_device_isi(void)
761 {
762         at91_set_A_periph(AT91_PIN_PE0, 0);     /* ISI_D0 */
763         at91_set_A_periph(AT91_PIN_PE1, 0);     /* ISI_D1 */
764         at91_set_A_periph(AT91_PIN_PE2, 0);     /* ISI_D2 */
765         at91_set_A_periph(AT91_PIN_PE3, 0);     /* ISI_D3 */
766         at91_set_A_periph(AT91_PIN_PE4, 0);     /* ISI_D4 */
767         at91_set_A_periph(AT91_PIN_PE5, 0);     /* ISI_D5 */
768         at91_set_A_periph(AT91_PIN_PE6, 0);     /* ISI_D6 */
769         at91_set_A_periph(AT91_PIN_PE7, 0);     /* ISI_D7 */
770         at91_set_A_periph(AT91_PIN_PE8, 0);     /* ISI_PCK */
771         at91_set_A_periph(AT91_PIN_PE9, 0);     /* ISI_HSYNC */
772         at91_set_A_periph(AT91_PIN_PE10, 0);    /* ISI_VSYNC */
773         at91_set_B_periph(AT91_PIN_PE11, 0);    /* ISI_MCK (PCK3) */
774         at91_set_B_periph(AT91_PIN_PE12, 0);    /* ISI_PD8 */
775         at91_set_B_periph(AT91_PIN_PE13, 0);    /* ISI_PD9 */
776         at91_set_B_periph(AT91_PIN_PE14, 0);    /* ISI_PD10 */
777         at91_set_B_periph(AT91_PIN_PE15, 0);    /* ISI_PD11 */
778 }
779 #else
780 void __init at91_add_device_isi(void) {}
781 #endif
782
783
784 /* --------------------------------------------------------------------
785  *  RTT
786  * -------------------------------------------------------------------- */
787
788 static struct resource rtt0_resources[] = {
789         {
790                 .start  = AT91_BASE_SYS + AT91_RTT0,
791                 .end    = AT91_BASE_SYS + AT91_RTT0 + SZ_16 - 1,
792                 .flags  = IORESOURCE_MEM,
793         }
794 };
795
796 static struct platform_device at91sam9263_rtt0_device = {
797         .name           = "at91_rtt",
798         .id             = 0,
799         .resource       = rtt0_resources,
800         .num_resources  = ARRAY_SIZE(rtt0_resources),
801 };
802
803 static struct resource rtt1_resources[] = {
804         {
805                 .start  = AT91_BASE_SYS + AT91_RTT1,
806                 .end    = AT91_BASE_SYS + AT91_RTT1 + SZ_16 - 1,
807                 .flags  = IORESOURCE_MEM,
808         }
809 };
810
811 static struct platform_device at91sam9263_rtt1_device = {
812         .name           = "at91_rtt",
813         .id             = 1,
814         .resource       = rtt1_resources,
815         .num_resources  = ARRAY_SIZE(rtt1_resources),
816 };
817
818 static void __init at91_add_device_rtt(void)
819 {
820         platform_device_register(&at91sam9263_rtt0_device);
821         platform_device_register(&at91sam9263_rtt1_device);
822 }
823
824
825 /* --------------------------------------------------------------------
826  *  Watchdog
827  * -------------------------------------------------------------------- */
828
829 #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
830 static struct platform_device at91sam9263_wdt_device = {
831         .name           = "at91_wdt",
832         .id             = -1,
833         .num_resources  = 0,
834 };
835
836 static void __init at91_add_device_watchdog(void)
837 {
838         platform_device_register(&at91sam9263_wdt_device);
839 }
840 #else
841 static void __init at91_add_device_watchdog(void) {}
842 #endif
843
844
845 /* --------------------------------------------------------------------
846  *  LEDs
847  * -------------------------------------------------------------------- */
848
849 #if defined(CONFIG_LEDS)
850 u8 at91_leds_cpu;
851 u8 at91_leds_timer;
852
853 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
854 {
855         /* Enable GPIO to access the LEDs */
856         at91_set_gpio_output(cpu_led, 1);
857         at91_set_gpio_output(timer_led, 1);
858
859         at91_leds_cpu   = cpu_led;
860         at91_leds_timer = timer_led;
861 }
862 #else
863 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
864 #endif
865
866
867 /* --------------------------------------------------------------------
868  *  UART
869  * -------------------------------------------------------------------- */
870
871 #if defined(CONFIG_SERIAL_ATMEL)
872
873 static struct resource dbgu_resources[] = {
874         [0] = {
875                 .start  = AT91_VA_BASE_SYS + AT91_DBGU,
876                 .end    = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
877                 .flags  = IORESOURCE_MEM,
878         },
879         [1] = {
880                 .start  = AT91_ID_SYS,
881                 .end    = AT91_ID_SYS,
882                 .flags  = IORESOURCE_IRQ,
883         },
884 };
885
886 static struct atmel_uart_data dbgu_data = {
887         .use_dma_tx     = 0,
888         .use_dma_rx     = 0,            /* DBGU not capable of receive DMA */
889         .regs           = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
890 };
891
892 static struct platform_device at91sam9263_dbgu_device = {
893         .name           = "atmel_usart",
894         .id             = 0,
895         .dev            = {
896                                 .platform_data  = &dbgu_data,
897                                 .coherent_dma_mask = 0xffffffff,
898         },
899         .resource       = dbgu_resources,
900         .num_resources  = ARRAY_SIZE(dbgu_resources),
901 };
902
903 static inline void configure_dbgu_pins(void)
904 {
905         at91_set_A_periph(AT91_PIN_PC30, 0);            /* DRXD */
906         at91_set_A_periph(AT91_PIN_PC31, 1);            /* DTXD */
907 }
908
909 static struct resource uart0_resources[] = {
910         [0] = {
911                 .start  = AT91SAM9263_BASE_US0,
912                 .end    = AT91SAM9263_BASE_US0 + SZ_16K - 1,
913                 .flags  = IORESOURCE_MEM,
914         },
915         [1] = {
916                 .start  = AT91SAM9263_ID_US0,
917                 .end    = AT91SAM9263_ID_US0,
918                 .flags  = IORESOURCE_IRQ,
919         },
920 };
921
922 static struct atmel_uart_data uart0_data = {
923         .use_dma_tx     = 1,
924         .use_dma_rx     = 1,
925 };
926
927 static struct platform_device at91sam9263_uart0_device = {
928         .name           = "atmel_usart",
929         .id             = 1,
930         .dev            = {
931                                 .platform_data  = &uart0_data,
932                                 .coherent_dma_mask = 0xffffffff,
933         },
934         .resource       = uart0_resources,
935         .num_resources  = ARRAY_SIZE(uart0_resources),
936 };
937
938 static inline void configure_usart0_pins(void)
939 {
940         at91_set_A_periph(AT91_PIN_PA26, 1);            /* TXD0 */
941         at91_set_A_periph(AT91_PIN_PA27, 0);            /* RXD0 */
942         at91_set_A_periph(AT91_PIN_PA28, 0);            /* RTS0 */
943         at91_set_A_periph(AT91_PIN_PA29, 0);            /* CTS0 */
944 }
945
946 static struct resource uart1_resources[] = {
947         [0] = {
948                 .start  = AT91SAM9263_BASE_US1,
949                 .end    = AT91SAM9263_BASE_US1 + SZ_16K - 1,
950                 .flags  = IORESOURCE_MEM,
951         },
952         [1] = {
953                 .start  = AT91SAM9263_ID_US1,
954                 .end    = AT91SAM9263_ID_US1,
955                 .flags  = IORESOURCE_IRQ,
956         },
957 };
958
959 static struct atmel_uart_data uart1_data = {
960         .use_dma_tx     = 1,
961         .use_dma_rx     = 1,
962 };
963
964 static struct platform_device at91sam9263_uart1_device = {
965         .name           = "atmel_usart",
966         .id             = 2,
967         .dev            = {
968                                 .platform_data  = &uart1_data,
969                                 .coherent_dma_mask = 0xffffffff,
970         },
971         .resource       = uart1_resources,
972         .num_resources  = ARRAY_SIZE(uart1_resources),
973 };
974
975 static inline void configure_usart1_pins(void)
976 {
977         at91_set_A_periph(AT91_PIN_PD0, 1);             /* TXD1 */
978         at91_set_A_periph(AT91_PIN_PD1, 0);             /* RXD1 */
979         at91_set_B_periph(AT91_PIN_PD7, 0);             /* RTS1 */
980         at91_set_B_periph(AT91_PIN_PD8, 0);             /* CTS1 */
981 }
982
983 static struct resource uart2_resources[] = {
984         [0] = {
985                 .start  = AT91SAM9263_BASE_US2,
986                 .end    = AT91SAM9263_BASE_US2 + SZ_16K - 1,
987                 .flags  = IORESOURCE_MEM,
988         },
989         [1] = {
990                 .start  = AT91SAM9263_ID_US2,
991                 .end    = AT91SAM9263_ID_US2,
992                 .flags  = IORESOURCE_IRQ,
993         },
994 };
995
996 static struct atmel_uart_data uart2_data = {
997         .use_dma_tx     = 1,
998         .use_dma_rx     = 1,
999 };
1000
1001 static struct platform_device at91sam9263_uart2_device = {
1002         .name           = "atmel_usart",
1003         .id             = 3,
1004         .dev            = {
1005                                 .platform_data  = &uart2_data,
1006                                 .coherent_dma_mask = 0xffffffff,
1007         },
1008         .resource       = uart2_resources,
1009         .num_resources  = ARRAY_SIZE(uart2_resources),
1010 };
1011
1012 static inline void configure_usart2_pins(void)
1013 {
1014         at91_set_A_periph(AT91_PIN_PD2, 1);             /* TXD2 */
1015         at91_set_A_periph(AT91_PIN_PD3, 0);             /* RXD2 */
1016         at91_set_B_periph(AT91_PIN_PD5, 0);             /* RTS2 */
1017         at91_set_B_periph(AT91_PIN_PD6, 0);             /* CTS2 */
1018 }
1019
1020 struct platform_device *at91_uarts[ATMEL_MAX_UART];     /* the UARTs to use */
1021 struct platform_device *atmel_default_console_device;   /* the serial console device */
1022
1023 void __init at91_init_serial(struct at91_uart_config *config)
1024 {
1025         int i;
1026
1027         /* Fill in list of supported UARTs */
1028         for (i = 0; i < config->nr_tty; i++) {
1029                 switch (config->tty_map[i]) {
1030                         case 0:
1031                                 configure_usart0_pins();
1032                                 at91_uarts[i] = &at91sam9263_uart0_device;
1033                                 at91_clock_associate("usart0_clk", &at91sam9263_uart0_device.dev, "usart");
1034                                 break;
1035                         case 1:
1036                                 configure_usart1_pins();
1037                                 at91_uarts[i] = &at91sam9263_uart1_device;
1038                                 at91_clock_associate("usart1_clk", &at91sam9263_uart1_device.dev, "usart");
1039                                 break;
1040                         case 2:
1041                                 configure_usart2_pins();
1042                                 at91_uarts[i] = &at91sam9263_uart2_device;
1043                                 at91_clock_associate("usart2_clk", &at91sam9263_uart2_device.dev, "usart");
1044                                 break;
1045                         case 3:
1046                                 configure_dbgu_pins();
1047                                 at91_uarts[i] = &at91sam9263_dbgu_device;
1048                                 at91_clock_associate("mck", &at91sam9263_dbgu_device.dev, "usart");
1049                                 break;
1050                         default:
1051                                 continue;
1052                 }
1053                 at91_uarts[i]->id = i;          /* update ID number to mapped ID */
1054         }
1055
1056         /* Set serial console device */
1057         if (config->console_tty < ATMEL_MAX_UART)
1058                 atmel_default_console_device = at91_uarts[config->console_tty];
1059         if (!atmel_default_console_device)
1060                 printk(KERN_INFO "AT91: No default serial console defined.\n");
1061 }
1062
1063 void __init at91_add_device_serial(void)
1064 {
1065         int i;
1066
1067         for (i = 0; i < ATMEL_MAX_UART; i++) {
1068                 if (at91_uarts[i])
1069                         platform_device_register(at91_uarts[i]);
1070         }
1071 }
1072 #else
1073 void __init at91_init_serial(struct at91_uart_config *config) {}
1074 void __init at91_add_device_serial(void) {}
1075 #endif
1076
1077
1078 /* -------------------------------------------------------------------- */
1079 /*
1080  * These devices are always present and don't need any board-specific
1081  * setup.
1082  */
1083 static int __init at91_add_standard_devices(void)
1084 {
1085         at91_add_device_rtt();
1086         at91_add_device_watchdog();
1087         return 0;
1088 }
1089
1090 arch_initcall(at91_add_standard_devices);