2 * Copyright (C) 2007 Atmel Corporation
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive for
9 #include <asm/mach/arch.h>
10 #include <asm/mach/map.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/gpio.h>
14 #include <linux/platform_device.h>
15 #include <linux/i2c-gpio.h>
18 #include <video/atmel_lcdc.h>
20 #include <mach/board.h>
21 #include <mach/at91sam9rl.h>
22 #include <mach/at91sam9rl_matrix.h>
23 #include <mach/at91sam9_smc.h>
24 #include <mach/at_hdmac.h>
29 /* --------------------------------------------------------------------
30 * HDMAC - AHB DMA Controller
31 * -------------------------------------------------------------------- */
33 #if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
34 static u64 hdmac_dmamask
= DMA_BIT_MASK(32);
36 static struct resource hdmac_resources
[] = {
38 .start
= AT91SAM9RL_BASE_DMA
,
39 .end
= AT91SAM9RL_BASE_DMA
+ SZ_512
- 1,
40 .flags
= IORESOURCE_MEM
,
43 .start
= AT91SAM9RL_ID_DMA
,
44 .end
= AT91SAM9RL_ID_DMA
,
45 .flags
= IORESOURCE_IRQ
,
49 static struct platform_device at_hdmac_device
= {
50 .name
= "at91sam9rl_dma",
53 .dma_mask
= &hdmac_dmamask
,
54 .coherent_dma_mask
= DMA_BIT_MASK(32),
56 .resource
= hdmac_resources
,
57 .num_resources
= ARRAY_SIZE(hdmac_resources
),
60 void __init
at91_add_device_hdmac(void)
62 platform_device_register(&at_hdmac_device
);
65 void __init
at91_add_device_hdmac(void) {}
68 /* --------------------------------------------------------------------
69 * USB HS Device (Gadget)
70 * -------------------------------------------------------------------- */
72 #if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE)
74 static struct resource usba_udc_resources
[] = {
76 .start
= AT91SAM9RL_UDPHS_FIFO
,
77 .end
= AT91SAM9RL_UDPHS_FIFO
+ SZ_512K
- 1,
78 .flags
= IORESOURCE_MEM
,
81 .start
= AT91SAM9RL_BASE_UDPHS
,
82 .end
= AT91SAM9RL_BASE_UDPHS
+ SZ_1K
- 1,
83 .flags
= IORESOURCE_MEM
,
86 .start
= AT91SAM9RL_ID_UDPHS
,
87 .end
= AT91SAM9RL_ID_UDPHS
,
88 .flags
= IORESOURCE_IRQ
,
92 #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
96 .fifo_size = maxpkt, \
102 static struct usba_ep_data usba_udc_ep
[] __initdata
= {
103 EP("ep0", 0, 64, 1, 0, 0),
104 EP("ep1", 1, 1024, 2, 1, 1),
105 EP("ep2", 2, 1024, 2, 1, 1),
106 EP("ep3", 3, 1024, 3, 1, 0),
107 EP("ep4", 4, 1024, 3, 1, 0),
108 EP("ep5", 5, 1024, 3, 1, 1),
109 EP("ep6", 6, 1024, 3, 1, 1),
115 * pdata doesn't have room for any endpoints, so we need to
116 * append room for the ones we need right after it.
119 struct usba_platform_data pdata
;
120 struct usba_ep_data ep
[7];
123 static struct platform_device at91_usba_udc_device
= {
124 .name
= "atmel_usba_udc",
127 .platform_data
= &usba_udc_data
.pdata
,
129 .resource
= usba_udc_resources
,
130 .num_resources
= ARRAY_SIZE(usba_udc_resources
),
133 void __init
at91_add_device_usba(struct usba_platform_data
*data
)
136 * Invalid pins are 0 on AT91, but the usba driver is shared
137 * with AVR32, which use negative values instead. Once/if
138 * gpio_is_valid() is ported to AT91, revisit this code.
140 usba_udc_data
.pdata
.vbus_pin
= -EINVAL
;
141 usba_udc_data
.pdata
.num_ep
= ARRAY_SIZE(usba_udc_ep
);
142 memcpy(usba_udc_data
.ep
, usba_udc_ep
, sizeof(usba_udc_ep
));
144 if (data
&& gpio_is_valid(data
->vbus_pin
)) {
145 at91_set_gpio_input(data
->vbus_pin
, 0);
146 at91_set_deglitch(data
->vbus_pin
, 1);
147 usba_udc_data
.pdata
.vbus_pin
= data
->vbus_pin
;
150 /* Pullup pin is handled internally by USB device peripheral */
152 platform_device_register(&at91_usba_udc_device
);
155 void __init
at91_add_device_usba(struct usba_platform_data
*data
) {}
159 /* --------------------------------------------------------------------
161 * -------------------------------------------------------------------- */
163 #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
164 static u64 mmc_dmamask
= DMA_BIT_MASK(32);
165 static struct at91_mmc_data mmc_data
;
167 static struct resource mmc_resources
[] = {
169 .start
= AT91SAM9RL_BASE_MCI
,
170 .end
= AT91SAM9RL_BASE_MCI
+ SZ_16K
- 1,
171 .flags
= IORESOURCE_MEM
,
174 .start
= AT91SAM9RL_ID_MCI
,
175 .end
= AT91SAM9RL_ID_MCI
,
176 .flags
= IORESOURCE_IRQ
,
180 static struct platform_device at91sam9rl_mmc_device
= {
184 .dma_mask
= &mmc_dmamask
,
185 .coherent_dma_mask
= DMA_BIT_MASK(32),
186 .platform_data
= &mmc_data
,
188 .resource
= mmc_resources
,
189 .num_resources
= ARRAY_SIZE(mmc_resources
),
192 void __init
at91_add_device_mmc(short mmc_id
, struct at91_mmc_data
*data
)
198 if (gpio_is_valid(data
->det_pin
)) {
199 at91_set_gpio_input(data
->det_pin
, 1);
200 at91_set_deglitch(data
->det_pin
, 1);
202 if (gpio_is_valid(data
->wp_pin
))
203 at91_set_gpio_input(data
->wp_pin
, 1);
204 if (gpio_is_valid(data
->vcc_pin
))
205 at91_set_gpio_output(data
->vcc_pin
, 0);
208 at91_set_A_periph(AT91_PIN_PA2
, 0);
211 at91_set_A_periph(AT91_PIN_PA1
, 1);
213 /* DAT0, maybe DAT1..DAT3 */
214 at91_set_A_periph(AT91_PIN_PA0
, 1);
216 at91_set_A_periph(AT91_PIN_PA3
, 1);
217 at91_set_A_periph(AT91_PIN_PA4
, 1);
218 at91_set_A_periph(AT91_PIN_PA5
, 1);
222 platform_device_register(&at91sam9rl_mmc_device
);
225 void __init
at91_add_device_mmc(short mmc_id
, struct at91_mmc_data
*data
) {}
229 /* --------------------------------------------------------------------
231 * -------------------------------------------------------------------- */
233 #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
234 static struct atmel_nand_data nand_data
;
236 #define NAND_BASE AT91_CHIPSELECT_3
238 static struct resource nand_resources
[] = {
241 .end
= NAND_BASE
+ SZ_256M
- 1,
242 .flags
= IORESOURCE_MEM
,
245 .start
= AT91SAM9RL_BASE_ECC
,
246 .end
= AT91SAM9RL_BASE_ECC
+ SZ_512
- 1,
247 .flags
= IORESOURCE_MEM
,
251 static struct platform_device atmel_nand_device
= {
252 .name
= "atmel_nand",
255 .platform_data
= &nand_data
,
257 .resource
= nand_resources
,
258 .num_resources
= ARRAY_SIZE(nand_resources
),
261 void __init
at91_add_device_nand(struct atmel_nand_data
*data
)
268 csa
= at91_sys_read(AT91_MATRIX_EBICSA
);
269 at91_sys_write(AT91_MATRIX_EBICSA
, csa
| AT91_MATRIX_CS3A_SMC_SMARTMEDIA
);
272 if (gpio_is_valid(data
->enable_pin
))
273 at91_set_gpio_output(data
->enable_pin
, 1);
276 if (gpio_is_valid(data
->rdy_pin
))
277 at91_set_gpio_input(data
->rdy_pin
, 1);
279 /* card detect pin */
280 if (gpio_is_valid(data
->det_pin
))
281 at91_set_gpio_input(data
->det_pin
, 1);
283 at91_set_A_periph(AT91_PIN_PB4
, 0); /* NANDOE */
284 at91_set_A_periph(AT91_PIN_PB5
, 0); /* NANDWE */
287 platform_device_register(&atmel_nand_device
);
291 void __init
at91_add_device_nand(struct atmel_nand_data
*data
) {}
295 /* --------------------------------------------------------------------
297 * -------------------------------------------------------------------- */
300 * Prefer the GPIO code since the TWI controller isn't robust
301 * (gets overruns and underruns under load) and can only issue
302 * repeated STARTs in one scenario (the driver doesn't yet handle them).
304 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
306 static struct i2c_gpio_platform_data pdata
= {
307 .sda_pin
= AT91_PIN_PA23
,
308 .sda_is_open_drain
= 1,
309 .scl_pin
= AT91_PIN_PA24
,
310 .scl_is_open_drain
= 1,
311 .udelay
= 2, /* ~100 kHz */
314 static struct platform_device at91sam9rl_twi_device
= {
317 .dev
.platform_data
= &pdata
,
320 void __init
at91_add_device_i2c(struct i2c_board_info
*devices
, int nr_devices
)
322 at91_set_GPIO_periph(AT91_PIN_PA23
, 1); /* TWD (SDA) */
323 at91_set_multi_drive(AT91_PIN_PA23
, 1);
325 at91_set_GPIO_periph(AT91_PIN_PA24
, 1); /* TWCK (SCL) */
326 at91_set_multi_drive(AT91_PIN_PA24
, 1);
328 i2c_register_board_info(0, devices
, nr_devices
);
329 platform_device_register(&at91sam9rl_twi_device
);
332 #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
334 static struct resource twi_resources
[] = {
336 .start
= AT91SAM9RL_BASE_TWI0
,
337 .end
= AT91SAM9RL_BASE_TWI0
+ SZ_16K
- 1,
338 .flags
= IORESOURCE_MEM
,
341 .start
= AT91SAM9RL_ID_TWI0
,
342 .end
= AT91SAM9RL_ID_TWI0
,
343 .flags
= IORESOURCE_IRQ
,
347 static struct platform_device at91sam9rl_twi_device
= {
350 .resource
= twi_resources
,
351 .num_resources
= ARRAY_SIZE(twi_resources
),
354 void __init
at91_add_device_i2c(struct i2c_board_info
*devices
, int nr_devices
)
356 /* pins used for TWI interface */
357 at91_set_A_periph(AT91_PIN_PA23
, 0); /* TWD */
358 at91_set_multi_drive(AT91_PIN_PA23
, 1);
360 at91_set_A_periph(AT91_PIN_PA24
, 0); /* TWCK */
361 at91_set_multi_drive(AT91_PIN_PA24
, 1);
363 i2c_register_board_info(0, devices
, nr_devices
);
364 platform_device_register(&at91sam9rl_twi_device
);
367 void __init
at91_add_device_i2c(struct i2c_board_info
*devices
, int nr_devices
) {}
371 /* --------------------------------------------------------------------
373 * -------------------------------------------------------------------- */
375 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
376 static u64 spi_dmamask
= DMA_BIT_MASK(32);
378 static struct resource spi_resources
[] = {
380 .start
= AT91SAM9RL_BASE_SPI
,
381 .end
= AT91SAM9RL_BASE_SPI
+ SZ_16K
- 1,
382 .flags
= IORESOURCE_MEM
,
385 .start
= AT91SAM9RL_ID_SPI
,
386 .end
= AT91SAM9RL_ID_SPI
,
387 .flags
= IORESOURCE_IRQ
,
391 static struct platform_device at91sam9rl_spi_device
= {
395 .dma_mask
= &spi_dmamask
,
396 .coherent_dma_mask
= DMA_BIT_MASK(32),
398 .resource
= spi_resources
,
399 .num_resources
= ARRAY_SIZE(spi_resources
),
402 static const unsigned spi_standard_cs
[4] = { AT91_PIN_PA28
, AT91_PIN_PB7
, AT91_PIN_PD8
, AT91_PIN_PD9
};
405 void __init
at91_add_device_spi(struct spi_board_info
*devices
, int nr_devices
)
408 unsigned long cs_pin
;
410 at91_set_A_periph(AT91_PIN_PA25
, 0); /* MISO */
411 at91_set_A_periph(AT91_PIN_PA26
, 0); /* MOSI */
412 at91_set_A_periph(AT91_PIN_PA27
, 0); /* SPCK */
414 /* Enable SPI chip-selects */
415 for (i
= 0; i
< nr_devices
; i
++) {
416 if (devices
[i
].controller_data
)
417 cs_pin
= (unsigned long) devices
[i
].controller_data
;
419 cs_pin
= spi_standard_cs
[devices
[i
].chip_select
];
421 /* enable chip-select pin */
422 at91_set_gpio_output(cs_pin
, 1);
424 /* pass chip-select pin to driver */
425 devices
[i
].controller_data
= (void *) cs_pin
;
428 spi_register_board_info(devices
, nr_devices
);
429 platform_device_register(&at91sam9rl_spi_device
);
432 void __init
at91_add_device_spi(struct spi_board_info
*devices
, int nr_devices
) {}
436 /* --------------------------------------------------------------------
438 * -------------------------------------------------------------------- */
440 #if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
441 static u64 ac97_dmamask
= DMA_BIT_MASK(32);
442 static struct ac97c_platform_data ac97_data
;
444 static struct resource ac97_resources
[] = {
446 .start
= AT91SAM9RL_BASE_AC97C
,
447 .end
= AT91SAM9RL_BASE_AC97C
+ SZ_16K
- 1,
448 .flags
= IORESOURCE_MEM
,
451 .start
= AT91SAM9RL_ID_AC97C
,
452 .end
= AT91SAM9RL_ID_AC97C
,
453 .flags
= IORESOURCE_IRQ
,
457 static struct platform_device at91sam9rl_ac97_device
= {
458 .name
= "atmel_ac97c",
461 .dma_mask
= &ac97_dmamask
,
462 .coherent_dma_mask
= DMA_BIT_MASK(32),
463 .platform_data
= &ac97_data
,
465 .resource
= ac97_resources
,
466 .num_resources
= ARRAY_SIZE(ac97_resources
),
469 void __init
at91_add_device_ac97(struct ac97c_platform_data
*data
)
474 at91_set_A_periph(AT91_PIN_PD1
, 0); /* AC97FS */
475 at91_set_A_periph(AT91_PIN_PD2
, 0); /* AC97CK */
476 at91_set_A_periph(AT91_PIN_PD3
, 0); /* AC97TX */
477 at91_set_A_periph(AT91_PIN_PD4
, 0); /* AC97RX */
480 if (gpio_is_valid(data
->reset_pin
))
481 at91_set_gpio_output(data
->reset_pin
, 0);
484 platform_device_register(&at91sam9rl_ac97_device
);
487 void __init
at91_add_device_ac97(struct ac97c_platform_data
*data
) {}
491 /* --------------------------------------------------------------------
493 * -------------------------------------------------------------------- */
495 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
496 static u64 lcdc_dmamask
= DMA_BIT_MASK(32);
497 static struct atmel_lcdfb_info lcdc_data
;
499 static struct resource lcdc_resources
[] = {
501 .start
= AT91SAM9RL_LCDC_BASE
,
502 .end
= AT91SAM9RL_LCDC_BASE
+ SZ_4K
- 1,
503 .flags
= IORESOURCE_MEM
,
506 .start
= AT91SAM9RL_ID_LCDC
,
507 .end
= AT91SAM9RL_ID_LCDC
,
508 .flags
= IORESOURCE_IRQ
,
512 static struct platform_device at91_lcdc_device
= {
513 .name
= "atmel_lcdfb",
516 .dma_mask
= &lcdc_dmamask
,
517 .coherent_dma_mask
= DMA_BIT_MASK(32),
518 .platform_data
= &lcdc_data
,
520 .resource
= lcdc_resources
,
521 .num_resources
= ARRAY_SIZE(lcdc_resources
),
524 void __init
at91_add_device_lcdc(struct atmel_lcdfb_info
*data
)
530 at91_set_B_periph(AT91_PIN_PC1
, 0); /* LCDPWR */
531 at91_set_A_periph(AT91_PIN_PC5
, 0); /* LCDHSYNC */
532 at91_set_A_periph(AT91_PIN_PC6
, 0); /* LCDDOTCK */
533 at91_set_A_periph(AT91_PIN_PC7
, 0); /* LCDDEN */
534 at91_set_A_periph(AT91_PIN_PC3
, 0); /* LCDCC */
535 at91_set_B_periph(AT91_PIN_PC9
, 0); /* LCDD3 */
536 at91_set_B_periph(AT91_PIN_PC10
, 0); /* LCDD4 */
537 at91_set_B_periph(AT91_PIN_PC11
, 0); /* LCDD5 */
538 at91_set_B_periph(AT91_PIN_PC12
, 0); /* LCDD6 */
539 at91_set_B_periph(AT91_PIN_PC13
, 0); /* LCDD7 */
540 at91_set_B_periph(AT91_PIN_PC15
, 0); /* LCDD11 */
541 at91_set_B_periph(AT91_PIN_PC16
, 0); /* LCDD12 */
542 at91_set_B_periph(AT91_PIN_PC17
, 0); /* LCDD13 */
543 at91_set_B_periph(AT91_PIN_PC18
, 0); /* LCDD14 */
544 at91_set_B_periph(AT91_PIN_PC19
, 0); /* LCDD15 */
545 at91_set_B_periph(AT91_PIN_PC20
, 0); /* LCDD18 */
546 at91_set_B_periph(AT91_PIN_PC21
, 0); /* LCDD19 */
547 at91_set_B_periph(AT91_PIN_PC22
, 0); /* LCDD20 */
548 at91_set_B_periph(AT91_PIN_PC23
, 0); /* LCDD21 */
549 at91_set_B_periph(AT91_PIN_PC24
, 0); /* LCDD22 */
550 at91_set_B_periph(AT91_PIN_PC25
, 0); /* LCDD23 */
553 platform_device_register(&at91_lcdc_device
);
556 void __init
at91_add_device_lcdc(struct atmel_lcdfb_info
*data
) {}
560 /* --------------------------------------------------------------------
561 * Timer/Counter block
562 * -------------------------------------------------------------------- */
564 #ifdef CONFIG_ATMEL_TCLIB
566 static struct resource tcb_resources
[] = {
568 .start
= AT91SAM9RL_BASE_TCB0
,
569 .end
= AT91SAM9RL_BASE_TCB0
+ SZ_16K
- 1,
570 .flags
= IORESOURCE_MEM
,
573 .start
= AT91SAM9RL_ID_TC0
,
574 .end
= AT91SAM9RL_ID_TC0
,
575 .flags
= IORESOURCE_IRQ
,
578 .start
= AT91SAM9RL_ID_TC1
,
579 .end
= AT91SAM9RL_ID_TC1
,
580 .flags
= IORESOURCE_IRQ
,
583 .start
= AT91SAM9RL_ID_TC2
,
584 .end
= AT91SAM9RL_ID_TC2
,
585 .flags
= IORESOURCE_IRQ
,
589 static struct platform_device at91sam9rl_tcb_device
= {
592 .resource
= tcb_resources
,
593 .num_resources
= ARRAY_SIZE(tcb_resources
),
596 static void __init
at91_add_device_tc(void)
598 platform_device_register(&at91sam9rl_tcb_device
);
601 static void __init
at91_add_device_tc(void) { }
605 /* --------------------------------------------------------------------
607 * -------------------------------------------------------------------- */
609 #if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE)
610 static u64 tsadcc_dmamask
= DMA_BIT_MASK(32);
611 static struct at91_tsadcc_data tsadcc_data
;
613 static struct resource tsadcc_resources
[] = {
615 .start
= AT91SAM9RL_BASE_TSC
,
616 .end
= AT91SAM9RL_BASE_TSC
+ SZ_16K
- 1,
617 .flags
= IORESOURCE_MEM
,
620 .start
= AT91SAM9RL_ID_TSC
,
621 .end
= AT91SAM9RL_ID_TSC
,
622 .flags
= IORESOURCE_IRQ
,
626 static struct platform_device at91sam9rl_tsadcc_device
= {
627 .name
= "atmel_tsadcc",
630 .dma_mask
= &tsadcc_dmamask
,
631 .coherent_dma_mask
= DMA_BIT_MASK(32),
632 .platform_data
= &tsadcc_data
,
634 .resource
= tsadcc_resources
,
635 .num_resources
= ARRAY_SIZE(tsadcc_resources
),
638 void __init
at91_add_device_tsadcc(struct at91_tsadcc_data
*data
)
643 at91_set_A_periph(AT91_PIN_PA17
, 0); /* AD0_XR */
644 at91_set_A_periph(AT91_PIN_PA18
, 0); /* AD1_XL */
645 at91_set_A_periph(AT91_PIN_PA19
, 0); /* AD2_YT */
646 at91_set_A_periph(AT91_PIN_PA20
, 0); /* AD3_TB */
649 platform_device_register(&at91sam9rl_tsadcc_device
);
652 void __init
at91_add_device_tsadcc(struct at91_tsadcc_data
*data
) {}
656 /* --------------------------------------------------------------------
658 * -------------------------------------------------------------------- */
660 #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
661 static struct platform_device at91sam9rl_rtc_device
= {
667 static void __init
at91_add_device_rtc(void)
669 platform_device_register(&at91sam9rl_rtc_device
);
672 static void __init
at91_add_device_rtc(void) {}
676 /* --------------------------------------------------------------------
678 * -------------------------------------------------------------------- */
680 static struct resource rtt_resources
[] = {
682 .start
= AT91SAM9RL_BASE_RTT
,
683 .end
= AT91SAM9RL_BASE_RTT
+ SZ_16
- 1,
684 .flags
= IORESOURCE_MEM
,
688 static struct platform_device at91sam9rl_rtt_device
= {
691 .resource
= rtt_resources
,
692 .num_resources
= ARRAY_SIZE(rtt_resources
),
695 static void __init
at91_add_device_rtt(void)
697 platform_device_register(&at91sam9rl_rtt_device
);
701 /* --------------------------------------------------------------------
703 * -------------------------------------------------------------------- */
705 #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
706 static struct resource wdt_resources
[] = {
708 .start
= AT91SAM9RL_BASE_WDT
,
709 .end
= AT91SAM9RL_BASE_WDT
+ SZ_16
- 1,
710 .flags
= IORESOURCE_MEM
,
714 static struct platform_device at91sam9rl_wdt_device
= {
717 .resource
= wdt_resources
,
718 .num_resources
= ARRAY_SIZE(wdt_resources
),
721 static void __init
at91_add_device_watchdog(void)
723 platform_device_register(&at91sam9rl_wdt_device
);
726 static void __init
at91_add_device_watchdog(void) {}
730 /* --------------------------------------------------------------------
732 * --------------------------------------------------------------------*/
734 #if defined(CONFIG_ATMEL_PWM)
737 static struct resource pwm_resources
[] = {
739 .start
= AT91SAM9RL_BASE_PWMC
,
740 .end
= AT91SAM9RL_BASE_PWMC
+ SZ_16K
- 1,
741 .flags
= IORESOURCE_MEM
,
744 .start
= AT91SAM9RL_ID_PWMC
,
745 .end
= AT91SAM9RL_ID_PWMC
,
746 .flags
= IORESOURCE_IRQ
,
750 static struct platform_device at91sam9rl_pwm0_device
= {
754 .platform_data
= &pwm_mask
,
756 .resource
= pwm_resources
,
757 .num_resources
= ARRAY_SIZE(pwm_resources
),
760 void __init
at91_add_device_pwm(u32 mask
)
762 if (mask
& (1 << AT91_PWM0
))
763 at91_set_B_periph(AT91_PIN_PB8
, 1); /* enable PWM0 */
765 if (mask
& (1 << AT91_PWM1
))
766 at91_set_B_periph(AT91_PIN_PB9
, 1); /* enable PWM1 */
768 if (mask
& (1 << AT91_PWM2
))
769 at91_set_B_periph(AT91_PIN_PD5
, 1); /* enable PWM2 */
771 if (mask
& (1 << AT91_PWM3
))
772 at91_set_B_periph(AT91_PIN_PD8
, 1); /* enable PWM3 */
776 platform_device_register(&at91sam9rl_pwm0_device
);
779 void __init
at91_add_device_pwm(u32 mask
) {}
783 /* --------------------------------------------------------------------
784 * SSC -- Synchronous Serial Controller
785 * -------------------------------------------------------------------- */
787 #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
788 static u64 ssc0_dmamask
= DMA_BIT_MASK(32);
790 static struct resource ssc0_resources
[] = {
792 .start
= AT91SAM9RL_BASE_SSC0
,
793 .end
= AT91SAM9RL_BASE_SSC0
+ SZ_16K
- 1,
794 .flags
= IORESOURCE_MEM
,
797 .start
= AT91SAM9RL_ID_SSC0
,
798 .end
= AT91SAM9RL_ID_SSC0
,
799 .flags
= IORESOURCE_IRQ
,
803 static struct platform_device at91sam9rl_ssc0_device
= {
807 .dma_mask
= &ssc0_dmamask
,
808 .coherent_dma_mask
= DMA_BIT_MASK(32),
810 .resource
= ssc0_resources
,
811 .num_resources
= ARRAY_SIZE(ssc0_resources
),
814 static inline void configure_ssc0_pins(unsigned pins
)
816 if (pins
& ATMEL_SSC_TF
)
817 at91_set_A_periph(AT91_PIN_PC0
, 1);
818 if (pins
& ATMEL_SSC_TK
)
819 at91_set_A_periph(AT91_PIN_PC1
, 1);
820 if (pins
& ATMEL_SSC_TD
)
821 at91_set_A_periph(AT91_PIN_PA15
, 1);
822 if (pins
& ATMEL_SSC_RD
)
823 at91_set_A_periph(AT91_PIN_PA16
, 1);
824 if (pins
& ATMEL_SSC_RK
)
825 at91_set_B_periph(AT91_PIN_PA10
, 1);
826 if (pins
& ATMEL_SSC_RF
)
827 at91_set_B_periph(AT91_PIN_PA22
, 1);
830 static u64 ssc1_dmamask
= DMA_BIT_MASK(32);
832 static struct resource ssc1_resources
[] = {
834 .start
= AT91SAM9RL_BASE_SSC1
,
835 .end
= AT91SAM9RL_BASE_SSC1
+ SZ_16K
- 1,
836 .flags
= IORESOURCE_MEM
,
839 .start
= AT91SAM9RL_ID_SSC1
,
840 .end
= AT91SAM9RL_ID_SSC1
,
841 .flags
= IORESOURCE_IRQ
,
845 static struct platform_device at91sam9rl_ssc1_device
= {
849 .dma_mask
= &ssc1_dmamask
,
850 .coherent_dma_mask
= DMA_BIT_MASK(32),
852 .resource
= ssc1_resources
,
853 .num_resources
= ARRAY_SIZE(ssc1_resources
),
856 static inline void configure_ssc1_pins(unsigned pins
)
858 if (pins
& ATMEL_SSC_TF
)
859 at91_set_B_periph(AT91_PIN_PA29
, 1);
860 if (pins
& ATMEL_SSC_TK
)
861 at91_set_B_periph(AT91_PIN_PA30
, 1);
862 if (pins
& ATMEL_SSC_TD
)
863 at91_set_B_periph(AT91_PIN_PA13
, 1);
864 if (pins
& ATMEL_SSC_RD
)
865 at91_set_B_periph(AT91_PIN_PA14
, 1);
866 if (pins
& ATMEL_SSC_RK
)
867 at91_set_B_periph(AT91_PIN_PA9
, 1);
868 if (pins
& ATMEL_SSC_RF
)
869 at91_set_B_periph(AT91_PIN_PA8
, 1);
873 * SSC controllers are accessed through library code, instead of any
874 * kind of all-singing/all-dancing driver. For example one could be
875 * used by a particular I2S audio codec's driver, while another one
876 * on the same system might be used by a custom data capture driver.
878 void __init
at91_add_device_ssc(unsigned id
, unsigned pins
)
880 struct platform_device
*pdev
;
883 * NOTE: caller is responsible for passing information matching
884 * "pins" to whatever will be using each particular controller.
887 case AT91SAM9RL_ID_SSC0
:
888 pdev
= &at91sam9rl_ssc0_device
;
889 configure_ssc0_pins(pins
);
891 case AT91SAM9RL_ID_SSC1
:
892 pdev
= &at91sam9rl_ssc1_device
;
893 configure_ssc1_pins(pins
);
899 platform_device_register(pdev
);
903 void __init
at91_add_device_ssc(unsigned id
, unsigned pins
) {}
907 /* --------------------------------------------------------------------
909 * -------------------------------------------------------------------- */
911 #if defined(CONFIG_SERIAL_ATMEL)
912 static struct resource dbgu_resources
[] = {
914 .start
= AT91SAM9RL_BASE_DBGU
,
915 .end
= AT91SAM9RL_BASE_DBGU
+ SZ_512
- 1,
916 .flags
= IORESOURCE_MEM
,
919 .start
= AT91_ID_SYS
,
921 .flags
= IORESOURCE_IRQ
,
925 static struct atmel_uart_data dbgu_data
= {
927 .use_dma_rx
= 0, /* DBGU not capable of receive DMA */
930 static u64 dbgu_dmamask
= DMA_BIT_MASK(32);
932 static struct platform_device at91sam9rl_dbgu_device
= {
933 .name
= "atmel_usart",
936 .dma_mask
= &dbgu_dmamask
,
937 .coherent_dma_mask
= DMA_BIT_MASK(32),
938 .platform_data
= &dbgu_data
,
940 .resource
= dbgu_resources
,
941 .num_resources
= ARRAY_SIZE(dbgu_resources
),
944 static inline void configure_dbgu_pins(void)
946 at91_set_A_periph(AT91_PIN_PA21
, 0); /* DRXD */
947 at91_set_A_periph(AT91_PIN_PA22
, 1); /* DTXD */
950 static struct resource uart0_resources
[] = {
952 .start
= AT91SAM9RL_BASE_US0
,
953 .end
= AT91SAM9RL_BASE_US0
+ SZ_16K
- 1,
954 .flags
= IORESOURCE_MEM
,
957 .start
= AT91SAM9RL_ID_US0
,
958 .end
= AT91SAM9RL_ID_US0
,
959 .flags
= IORESOURCE_IRQ
,
963 static struct atmel_uart_data uart0_data
= {
968 static u64 uart0_dmamask
= DMA_BIT_MASK(32);
970 static struct platform_device at91sam9rl_uart0_device
= {
971 .name
= "atmel_usart",
974 .dma_mask
= &uart0_dmamask
,
975 .coherent_dma_mask
= DMA_BIT_MASK(32),
976 .platform_data
= &uart0_data
,
978 .resource
= uart0_resources
,
979 .num_resources
= ARRAY_SIZE(uart0_resources
),
982 static inline void configure_usart0_pins(unsigned pins
)
984 at91_set_A_periph(AT91_PIN_PA6
, 1); /* TXD0 */
985 at91_set_A_periph(AT91_PIN_PA7
, 0); /* RXD0 */
987 if (pins
& ATMEL_UART_RTS
)
988 at91_set_A_periph(AT91_PIN_PA9
, 0); /* RTS0 */
989 if (pins
& ATMEL_UART_CTS
)
990 at91_set_A_periph(AT91_PIN_PA10
, 0); /* CTS0 */
991 if (pins
& ATMEL_UART_DSR
)
992 at91_set_A_periph(AT91_PIN_PD14
, 0); /* DSR0 */
993 if (pins
& ATMEL_UART_DTR
)
994 at91_set_A_periph(AT91_PIN_PD15
, 0); /* DTR0 */
995 if (pins
& ATMEL_UART_DCD
)
996 at91_set_A_periph(AT91_PIN_PD16
, 0); /* DCD0 */
997 if (pins
& ATMEL_UART_RI
)
998 at91_set_A_periph(AT91_PIN_PD17
, 0); /* RI0 */
1001 static struct resource uart1_resources
[] = {
1003 .start
= AT91SAM9RL_BASE_US1
,
1004 .end
= AT91SAM9RL_BASE_US1
+ SZ_16K
- 1,
1005 .flags
= IORESOURCE_MEM
,
1008 .start
= AT91SAM9RL_ID_US1
,
1009 .end
= AT91SAM9RL_ID_US1
,
1010 .flags
= IORESOURCE_IRQ
,
1014 static struct atmel_uart_data uart1_data
= {
1019 static u64 uart1_dmamask
= DMA_BIT_MASK(32);
1021 static struct platform_device at91sam9rl_uart1_device
= {
1022 .name
= "atmel_usart",
1025 .dma_mask
= &uart1_dmamask
,
1026 .coherent_dma_mask
= DMA_BIT_MASK(32),
1027 .platform_data
= &uart1_data
,
1029 .resource
= uart1_resources
,
1030 .num_resources
= ARRAY_SIZE(uart1_resources
),
1033 static inline void configure_usart1_pins(unsigned pins
)
1035 at91_set_A_periph(AT91_PIN_PA11
, 1); /* TXD1 */
1036 at91_set_A_periph(AT91_PIN_PA12
, 0); /* RXD1 */
1038 if (pins
& ATMEL_UART_RTS
)
1039 at91_set_B_periph(AT91_PIN_PA18
, 0); /* RTS1 */
1040 if (pins
& ATMEL_UART_CTS
)
1041 at91_set_B_periph(AT91_PIN_PA19
, 0); /* CTS1 */
1044 static struct resource uart2_resources
[] = {
1046 .start
= AT91SAM9RL_BASE_US2
,
1047 .end
= AT91SAM9RL_BASE_US2
+ SZ_16K
- 1,
1048 .flags
= IORESOURCE_MEM
,
1051 .start
= AT91SAM9RL_ID_US2
,
1052 .end
= AT91SAM9RL_ID_US2
,
1053 .flags
= IORESOURCE_IRQ
,
1057 static struct atmel_uart_data uart2_data
= {
1062 static u64 uart2_dmamask
= DMA_BIT_MASK(32);
1064 static struct platform_device at91sam9rl_uart2_device
= {
1065 .name
= "atmel_usart",
1068 .dma_mask
= &uart2_dmamask
,
1069 .coherent_dma_mask
= DMA_BIT_MASK(32),
1070 .platform_data
= &uart2_data
,
1072 .resource
= uart2_resources
,
1073 .num_resources
= ARRAY_SIZE(uart2_resources
),
1076 static inline void configure_usart2_pins(unsigned pins
)
1078 at91_set_A_periph(AT91_PIN_PA13
, 1); /* TXD2 */
1079 at91_set_A_periph(AT91_PIN_PA14
, 0); /* RXD2 */
1081 if (pins
& ATMEL_UART_RTS
)
1082 at91_set_A_periph(AT91_PIN_PA29
, 0); /* RTS2 */
1083 if (pins
& ATMEL_UART_CTS
)
1084 at91_set_A_periph(AT91_PIN_PA30
, 0); /* CTS2 */
1087 static struct resource uart3_resources
[] = {
1089 .start
= AT91SAM9RL_BASE_US3
,
1090 .end
= AT91SAM9RL_BASE_US3
+ SZ_16K
- 1,
1091 .flags
= IORESOURCE_MEM
,
1094 .start
= AT91SAM9RL_ID_US3
,
1095 .end
= AT91SAM9RL_ID_US3
,
1096 .flags
= IORESOURCE_IRQ
,
1100 static struct atmel_uart_data uart3_data
= {
1105 static u64 uart3_dmamask
= DMA_BIT_MASK(32);
1107 static struct platform_device at91sam9rl_uart3_device
= {
1108 .name
= "atmel_usart",
1111 .dma_mask
= &uart3_dmamask
,
1112 .coherent_dma_mask
= DMA_BIT_MASK(32),
1113 .platform_data
= &uart3_data
,
1115 .resource
= uart3_resources
,
1116 .num_resources
= ARRAY_SIZE(uart3_resources
),
1119 static inline void configure_usart3_pins(unsigned pins
)
1121 at91_set_A_periph(AT91_PIN_PB0
, 1); /* TXD3 */
1122 at91_set_A_periph(AT91_PIN_PB1
, 0); /* RXD3 */
1124 if (pins
& ATMEL_UART_RTS
)
1125 at91_set_B_periph(AT91_PIN_PD4
, 0); /* RTS3 */
1126 if (pins
& ATMEL_UART_CTS
)
1127 at91_set_B_periph(AT91_PIN_PD3
, 0); /* CTS3 */
1130 static struct platform_device
*__initdata at91_uarts
[ATMEL_MAX_UART
]; /* the UARTs to use */
1131 struct platform_device
*atmel_default_console_device
; /* the serial console device */
1133 void __init
at91_register_uart(unsigned id
, unsigned portnr
, unsigned pins
)
1135 struct platform_device
*pdev
;
1136 struct atmel_uart_data
*pdata
;
1140 pdev
= &at91sam9rl_dbgu_device
;
1141 configure_dbgu_pins();
1143 case AT91SAM9RL_ID_US0
:
1144 pdev
= &at91sam9rl_uart0_device
;
1145 configure_usart0_pins(pins
);
1147 case AT91SAM9RL_ID_US1
:
1148 pdev
= &at91sam9rl_uart1_device
;
1149 configure_usart1_pins(pins
);
1151 case AT91SAM9RL_ID_US2
:
1152 pdev
= &at91sam9rl_uart2_device
;
1153 configure_usart2_pins(pins
);
1155 case AT91SAM9RL_ID_US3
:
1156 pdev
= &at91sam9rl_uart3_device
;
1157 configure_usart3_pins(pins
);
1162 pdata
= pdev
->dev
.platform_data
;
1163 pdata
->num
= portnr
; /* update to mapped ID */
1165 if (portnr
< ATMEL_MAX_UART
)
1166 at91_uarts
[portnr
] = pdev
;
1169 void __init
at91_set_serial_console(unsigned portnr
)
1171 if (portnr
< ATMEL_MAX_UART
) {
1172 atmel_default_console_device
= at91_uarts
[portnr
];
1173 at91sam9rl_set_console_clock(at91_uarts
[portnr
]->id
);
1177 void __init
at91_add_device_serial(void)
1181 for (i
= 0; i
< ATMEL_MAX_UART
; i
++) {
1183 platform_device_register(at91_uarts
[i
]);
1186 if (!atmel_default_console_device
)
1187 printk(KERN_INFO
"AT91: No default serial console defined.\n");
1190 void __init
at91_register_uart(unsigned id
, unsigned portnr
, unsigned pins
) {}
1191 void __init
at91_set_serial_console(unsigned portnr
) {}
1192 void __init
at91_add_device_serial(void) {}
1196 /* -------------------------------------------------------------------- */
1199 * These devices are always present and don't need any board-specific
1202 static int __init
at91_add_standard_devices(void)
1204 at91_add_device_hdmac();
1205 at91_add_device_rtc();
1206 at91_add_device_rtt();
1207 at91_add_device_watchdog();
1208 at91_add_device_tc();
1212 arch_initcall(at91_add_standard_devices
);