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/platform_device.h>
14 #include <linux/i2c-gpio.h>
17 #include <video/atmel_lcdc.h>
19 #include <mach/board.h>
20 #include <mach/gpio.h>
21 #include <mach/at91sam9rl.h>
22 #include <mach/at91sam9rl_matrix.h>
23 #include <mach/at91sam9_smc.h>
28 /* --------------------------------------------------------------------
29 * USB HS Device (Gadget)
30 * -------------------------------------------------------------------- */
32 #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
34 static struct resource usba_udc_resources[] = {
36 .start = AT91SAM9RL_UDPHS_FIFO,
37 .end = AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
38 .flags = IORESOURCE_MEM,
41 .start = AT91SAM9RL_BASE_UDPHS,
42 .end = AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
43 .flags = IORESOURCE_MEM,
46 .start = AT91SAM9RL_ID_UDPHS,
47 .end = AT91SAM9RL_ID_UDPHS,
48 .flags = IORESOURCE_IRQ,
52 #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
56 .fifo_size = maxpkt, \
62 static struct usba_ep_data usba_udc_ep[] __initdata = {
63 EP("ep0", 0, 64, 1, 0, 0),
64 EP("ep1", 1, 1024, 2, 1, 1),
65 EP("ep2", 2, 1024, 2, 1, 1),
66 EP("ep3", 3, 1024, 3, 1, 0),
67 EP("ep4", 4, 1024, 3, 1, 0),
68 EP("ep5", 5, 1024, 3, 1, 1),
69 EP("ep6", 6, 1024, 3, 1, 1),
75 * pdata doesn't have room for any endpoints, so we need to
76 * append room for the ones we need right after it.
79 struct usba_platform_data pdata;
80 struct usba_ep_data ep[7];
83 static struct platform_device at91_usba_udc_device = {
84 .name = "atmel_usba_udc",
87 .platform_data = &usba_udc_data.pdata,
89 .resource = usba_udc_resources,
90 .num_resources = ARRAY_SIZE(usba_udc_resources),
93 void __init at91_add_device_usba(struct usba_platform_data *data)
96 * Invalid pins are 0 on AT91, but the usba driver is shared
97 * with AVR32, which use negative values instead. Once/if
98 * gpio_is_valid() is ported to AT91, revisit this code.
100 usba_udc_data.pdata.vbus_pin = -EINVAL;
101 usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
102 memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
104 if (data && data->vbus_pin > 0) {
105 at91_set_gpio_input(data->vbus_pin, 0);
106 at91_set_deglitch(data->vbus_pin, 1);
107 usba_udc_data.pdata.vbus_pin = data->vbus_pin;
110 /* Pullup pin is handled internally by USB device peripheral */
113 at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
114 at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
116 platform_device_register(&at91_usba_udc_device);
119 void __init at91_add_device_usba(struct usba_platform_data *data) {}
123 /* --------------------------------------------------------------------
125 * -------------------------------------------------------------------- */
127 #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
128 static u64 mmc_dmamask = DMA_BIT_MASK(32);
129 static struct at91_mmc_data mmc_data;
131 static struct resource mmc_resources[] = {
133 .start = AT91SAM9RL_BASE_MCI,
134 .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
135 .flags = IORESOURCE_MEM,
138 .start = AT91SAM9RL_ID_MCI,
139 .end = AT91SAM9RL_ID_MCI,
140 .flags = IORESOURCE_IRQ,
144 static struct platform_device at91sam9rl_mmc_device = {
148 .dma_mask = &mmc_dmamask,
149 .coherent_dma_mask = DMA_BIT_MASK(32),
150 .platform_data = &mmc_data,
152 .resource = mmc_resources,
153 .num_resources = ARRAY_SIZE(mmc_resources),
156 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
163 at91_set_gpio_input(data->det_pin, 1);
164 at91_set_deglitch(data->det_pin, 1);
167 at91_set_gpio_input(data->wp_pin, 1);
169 at91_set_gpio_output(data->vcc_pin, 0);
172 at91_set_A_periph(AT91_PIN_PA2, 0);
175 at91_set_A_periph(AT91_PIN_PA1, 1);
177 /* DAT0, maybe DAT1..DAT3 */
178 at91_set_A_periph(AT91_PIN_PA0, 1);
180 at91_set_A_periph(AT91_PIN_PA3, 1);
181 at91_set_A_periph(AT91_PIN_PA4, 1);
182 at91_set_A_periph(AT91_PIN_PA5, 1);
186 platform_device_register(&at91sam9rl_mmc_device);
189 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
193 /* --------------------------------------------------------------------
195 * -------------------------------------------------------------------- */
197 #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
198 static struct atmel_nand_data nand_data;
200 #define NAND_BASE AT91_CHIPSELECT_3
202 static struct resource nand_resources[] = {
205 .end = NAND_BASE + SZ_256M - 1,
206 .flags = IORESOURCE_MEM,
209 .start = AT91_BASE_SYS + AT91_ECC,
210 .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
211 .flags = IORESOURCE_MEM,
215 static struct platform_device atmel_nand_device = {
216 .name = "atmel_nand",
219 .platform_data = &nand_data,
221 .resource = nand_resources,
222 .num_resources = ARRAY_SIZE(nand_resources),
225 void __init at91_add_device_nand(struct atmel_nand_data *data)
232 csa = at91_sys_read(AT91_MATRIX_EBICSA);
233 at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
236 if (data->enable_pin)
237 at91_set_gpio_output(data->enable_pin, 1);
241 at91_set_gpio_input(data->rdy_pin, 1);
243 /* card detect pin */
245 at91_set_gpio_input(data->det_pin, 1);
247 at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
248 at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
251 platform_device_register(&atmel_nand_device);
255 void __init at91_add_device_nand(struct atmel_nand_data *data) {}
259 /* --------------------------------------------------------------------
261 * -------------------------------------------------------------------- */
264 * Prefer the GPIO code since the TWI controller isn't robust
265 * (gets overruns and underruns under load) and can only issue
266 * repeated STARTs in one scenario (the driver doesn't yet handle them).
268 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
270 static struct i2c_gpio_platform_data pdata = {
271 .sda_pin = AT91_PIN_PA23,
272 .sda_is_open_drain = 1,
273 .scl_pin = AT91_PIN_PA24,
274 .scl_is_open_drain = 1,
275 .udelay = 2, /* ~100 kHz */
278 static struct platform_device at91sam9rl_twi_device = {
281 .dev.platform_data = &pdata,
284 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
286 at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
287 at91_set_multi_drive(AT91_PIN_PA23, 1);
289 at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
290 at91_set_multi_drive(AT91_PIN_PA24, 1);
292 i2c_register_board_info(0, devices, nr_devices);
293 platform_device_register(&at91sam9rl_twi_device);
296 #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
298 static struct resource twi_resources[] = {
300 .start = AT91SAM9RL_BASE_TWI0,
301 .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
302 .flags = IORESOURCE_MEM,
305 .start = AT91SAM9RL_ID_TWI0,
306 .end = AT91SAM9RL_ID_TWI0,
307 .flags = IORESOURCE_IRQ,
311 static struct platform_device at91sam9rl_twi_device = {
314 .resource = twi_resources,
315 .num_resources = ARRAY_SIZE(twi_resources),
318 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
320 /* pins used for TWI interface */
321 at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
322 at91_set_multi_drive(AT91_PIN_PA23, 1);
324 at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
325 at91_set_multi_drive(AT91_PIN_PA24, 1);
327 i2c_register_board_info(0, devices, nr_devices);
328 platform_device_register(&at91sam9rl_twi_device);
331 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
335 /* --------------------------------------------------------------------
337 * -------------------------------------------------------------------- */
339 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
340 static u64 spi_dmamask = DMA_BIT_MASK(32);
342 static struct resource spi_resources[] = {
344 .start = AT91SAM9RL_BASE_SPI,
345 .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
346 .flags = IORESOURCE_MEM,
349 .start = AT91SAM9RL_ID_SPI,
350 .end = AT91SAM9RL_ID_SPI,
351 .flags = IORESOURCE_IRQ,
355 static struct platform_device at91sam9rl_spi_device = {
359 .dma_mask = &spi_dmamask,
360 .coherent_dma_mask = DMA_BIT_MASK(32),
362 .resource = spi_resources,
363 .num_resources = ARRAY_SIZE(spi_resources),
366 static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
369 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
372 unsigned long cs_pin;
374 at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
375 at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
376 at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
378 /* Enable SPI chip-selects */
379 for (i = 0; i < nr_devices; i++) {
380 if (devices[i].controller_data)
381 cs_pin = (unsigned long) devices[i].controller_data;
383 cs_pin = spi_standard_cs[devices[i].chip_select];
385 /* enable chip-select pin */
386 at91_set_gpio_output(cs_pin, 1);
388 /* pass chip-select pin to driver */
389 devices[i].controller_data = (void *) cs_pin;
392 spi_register_board_info(devices, nr_devices);
393 platform_device_register(&at91sam9rl_spi_device);
396 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
400 /* --------------------------------------------------------------------
402 * -------------------------------------------------------------------- */
404 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
405 static u64 lcdc_dmamask = DMA_BIT_MASK(32);
406 static struct atmel_lcdfb_info lcdc_data;
408 static struct resource lcdc_resources[] = {
410 .start = AT91SAM9RL_LCDC_BASE,
411 .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
412 .flags = IORESOURCE_MEM,
415 .start = AT91SAM9RL_ID_LCDC,
416 .end = AT91SAM9RL_ID_LCDC,
417 .flags = IORESOURCE_IRQ,
421 static struct platform_device at91_lcdc_device = {
422 .name = "atmel_lcdfb",
425 .dma_mask = &lcdc_dmamask,
426 .coherent_dma_mask = DMA_BIT_MASK(32),
427 .platform_data = &lcdc_data,
429 .resource = lcdc_resources,
430 .num_resources = ARRAY_SIZE(lcdc_resources),
433 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
439 at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
440 at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
441 at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
442 at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
443 at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
444 at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
445 at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
446 at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
447 at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
448 at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
449 at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
450 at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
451 at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
452 at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
453 at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
454 at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
455 at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
456 at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
457 at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
458 at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
459 at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
462 platform_device_register(&at91_lcdc_device);
465 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
469 /* --------------------------------------------------------------------
470 * Timer/Counter block
471 * -------------------------------------------------------------------- */
473 #ifdef CONFIG_ATMEL_TCLIB
475 static struct resource tcb_resources[] = {
477 .start = AT91SAM9RL_BASE_TCB0,
478 .end = AT91SAM9RL_BASE_TCB0 + SZ_16K - 1,
479 .flags = IORESOURCE_MEM,
482 .start = AT91SAM9RL_ID_TC0,
483 .end = AT91SAM9RL_ID_TC0,
484 .flags = IORESOURCE_IRQ,
487 .start = AT91SAM9RL_ID_TC1,
488 .end = AT91SAM9RL_ID_TC1,
489 .flags = IORESOURCE_IRQ,
492 .start = AT91SAM9RL_ID_TC2,
493 .end = AT91SAM9RL_ID_TC2,
494 .flags = IORESOURCE_IRQ,
498 static struct platform_device at91sam9rl_tcb_device = {
501 .resource = tcb_resources,
502 .num_resources = ARRAY_SIZE(tcb_resources),
505 static void __init at91_add_device_tc(void)
507 /* this chip has a separate clock and irq for each TC channel */
508 at91_clock_associate("tc0_clk", &at91sam9rl_tcb_device.dev, "t0_clk");
509 at91_clock_associate("tc1_clk", &at91sam9rl_tcb_device.dev, "t1_clk");
510 at91_clock_associate("tc2_clk", &at91sam9rl_tcb_device.dev, "t2_clk");
511 platform_device_register(&at91sam9rl_tcb_device);
514 static void __init at91_add_device_tc(void) { }
518 /* --------------------------------------------------------------------
520 * -------------------------------------------------------------------- */
522 #if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE)
523 static u64 tsadcc_dmamask = DMA_BIT_MASK(32);
525 static struct resource tsadcc_resources[] = {
527 .start = AT91SAM9RL_BASE_TSC,
528 .end = AT91SAM9RL_BASE_TSC + SZ_16K - 1,
529 .flags = IORESOURCE_MEM,
532 .start = AT91SAM9RL_ID_TSC,
533 .end = AT91SAM9RL_ID_TSC,
534 .flags = IORESOURCE_IRQ,
538 static struct platform_device at91sam9rl_tsadcc_device = {
539 .name = "atmel_tsadcc",
542 .dma_mask = &tsadcc_dmamask,
543 .coherent_dma_mask = DMA_BIT_MASK(32),
545 .resource = tsadcc_resources,
546 .num_resources = ARRAY_SIZE(tsadcc_resources),
549 void __init at91_add_device_tsadcc(void)
551 at91_set_A_periph(AT91_PIN_PA17, 0); /* AD0_XR */
552 at91_set_A_periph(AT91_PIN_PA18, 0); /* AD1_XL */
553 at91_set_A_periph(AT91_PIN_PA19, 0); /* AD2_YT */
554 at91_set_A_periph(AT91_PIN_PA20, 0); /* AD3_TB */
556 platform_device_register(&at91sam9rl_tsadcc_device);
559 void __init at91_add_device_tsadcc(void) {}
563 /* --------------------------------------------------------------------
565 * -------------------------------------------------------------------- */
567 #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
568 static struct platform_device at91sam9rl_rtc_device = {
574 static void __init at91_add_device_rtc(void)
576 platform_device_register(&at91sam9rl_rtc_device);
579 static void __init at91_add_device_rtc(void) {}
583 /* --------------------------------------------------------------------
585 * -------------------------------------------------------------------- */
587 static struct resource rtt_resources[] = {
589 .start = AT91_BASE_SYS + AT91_RTT,
590 .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
591 .flags = IORESOURCE_MEM,
595 static struct platform_device at91sam9rl_rtt_device = {
598 .resource = rtt_resources,
599 .num_resources = ARRAY_SIZE(rtt_resources),
602 static void __init at91_add_device_rtt(void)
604 platform_device_register(&at91sam9rl_rtt_device);
608 /* --------------------------------------------------------------------
610 * -------------------------------------------------------------------- */
612 #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
613 static struct platform_device at91sam9rl_wdt_device = {
619 static void __init at91_add_device_watchdog(void)
621 platform_device_register(&at91sam9rl_wdt_device);
624 static void __init at91_add_device_watchdog(void) {}
628 /* --------------------------------------------------------------------
630 * --------------------------------------------------------------------*/
632 #if defined(CONFIG_ATMEL_PWM)
635 static struct resource pwm_resources[] = {
637 .start = AT91SAM9RL_BASE_PWMC,
638 .end = AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
639 .flags = IORESOURCE_MEM,
642 .start = AT91SAM9RL_ID_PWMC,
643 .end = AT91SAM9RL_ID_PWMC,
644 .flags = IORESOURCE_IRQ,
648 static struct platform_device at91sam9rl_pwm0_device = {
652 .platform_data = &pwm_mask,
654 .resource = pwm_resources,
655 .num_resources = ARRAY_SIZE(pwm_resources),
658 void __init at91_add_device_pwm(u32 mask)
660 if (mask & (1 << AT91_PWM0))
661 at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM0 */
663 if (mask & (1 << AT91_PWM1))
664 at91_set_B_periph(AT91_PIN_PB9, 1); /* enable PWM1 */
666 if (mask & (1 << AT91_PWM2))
667 at91_set_B_periph(AT91_PIN_PD5, 1); /* enable PWM2 */
669 if (mask & (1 << AT91_PWM3))
670 at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */
674 platform_device_register(&at91sam9rl_pwm0_device);
677 void __init at91_add_device_pwm(u32 mask) {}
681 /* --------------------------------------------------------------------
682 * SSC -- Synchronous Serial Controller
683 * -------------------------------------------------------------------- */
685 #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
686 static u64 ssc0_dmamask = DMA_BIT_MASK(32);
688 static struct resource ssc0_resources[] = {
690 .start = AT91SAM9RL_BASE_SSC0,
691 .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
692 .flags = IORESOURCE_MEM,
695 .start = AT91SAM9RL_ID_SSC0,
696 .end = AT91SAM9RL_ID_SSC0,
697 .flags = IORESOURCE_IRQ,
701 static struct platform_device at91sam9rl_ssc0_device = {
705 .dma_mask = &ssc0_dmamask,
706 .coherent_dma_mask = DMA_BIT_MASK(32),
708 .resource = ssc0_resources,
709 .num_resources = ARRAY_SIZE(ssc0_resources),
712 static inline void configure_ssc0_pins(unsigned pins)
714 if (pins & ATMEL_SSC_TF)
715 at91_set_A_periph(AT91_PIN_PC0, 1);
716 if (pins & ATMEL_SSC_TK)
717 at91_set_A_periph(AT91_PIN_PC1, 1);
718 if (pins & ATMEL_SSC_TD)
719 at91_set_A_periph(AT91_PIN_PA15, 1);
720 if (pins & ATMEL_SSC_RD)
721 at91_set_A_periph(AT91_PIN_PA16, 1);
722 if (pins & ATMEL_SSC_RK)
723 at91_set_B_periph(AT91_PIN_PA10, 1);
724 if (pins & ATMEL_SSC_RF)
725 at91_set_B_periph(AT91_PIN_PA22, 1);
728 static u64 ssc1_dmamask = DMA_BIT_MASK(32);
730 static struct resource ssc1_resources[] = {
732 .start = AT91SAM9RL_BASE_SSC1,
733 .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
734 .flags = IORESOURCE_MEM,
737 .start = AT91SAM9RL_ID_SSC1,
738 .end = AT91SAM9RL_ID_SSC1,
739 .flags = IORESOURCE_IRQ,
743 static struct platform_device at91sam9rl_ssc1_device = {
747 .dma_mask = &ssc1_dmamask,
748 .coherent_dma_mask = DMA_BIT_MASK(32),
750 .resource = ssc1_resources,
751 .num_resources = ARRAY_SIZE(ssc1_resources),
754 static inline void configure_ssc1_pins(unsigned pins)
756 if (pins & ATMEL_SSC_TF)
757 at91_set_B_periph(AT91_PIN_PA29, 1);
758 if (pins & ATMEL_SSC_TK)
759 at91_set_B_periph(AT91_PIN_PA30, 1);
760 if (pins & ATMEL_SSC_TD)
761 at91_set_B_periph(AT91_PIN_PA13, 1);
762 if (pins & ATMEL_SSC_RD)
763 at91_set_B_periph(AT91_PIN_PA14, 1);
764 if (pins & ATMEL_SSC_RK)
765 at91_set_B_periph(AT91_PIN_PA9, 1);
766 if (pins & ATMEL_SSC_RF)
767 at91_set_B_periph(AT91_PIN_PA8, 1);
771 * SSC controllers are accessed through library code, instead of any
772 * kind of all-singing/all-dancing driver. For example one could be
773 * used by a particular I2S audio codec's driver, while another one
774 * on the same system might be used by a custom data capture driver.
776 void __init at91_add_device_ssc(unsigned id, unsigned pins)
778 struct platform_device *pdev;
781 * NOTE: caller is responsible for passing information matching
782 * "pins" to whatever will be using each particular controller.
785 case AT91SAM9RL_ID_SSC0:
786 pdev = &at91sam9rl_ssc0_device;
787 configure_ssc0_pins(pins);
788 at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
790 case AT91SAM9RL_ID_SSC1:
791 pdev = &at91sam9rl_ssc1_device;
792 configure_ssc1_pins(pins);
793 at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
799 platform_device_register(pdev);
803 void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
807 /* --------------------------------------------------------------------
809 * -------------------------------------------------------------------- */
811 #if defined(CONFIG_SERIAL_ATMEL)
812 static struct resource dbgu_resources[] = {
814 .start = AT91_VA_BASE_SYS + AT91_DBGU,
815 .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
816 .flags = IORESOURCE_MEM,
819 .start = AT91_ID_SYS,
821 .flags = IORESOURCE_IRQ,
825 static struct atmel_uart_data dbgu_data = {
827 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
828 .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
831 static u64 dbgu_dmamask = DMA_BIT_MASK(32);
833 static struct platform_device at91sam9rl_dbgu_device = {
834 .name = "atmel_usart",
837 .dma_mask = &dbgu_dmamask,
838 .coherent_dma_mask = DMA_BIT_MASK(32),
839 .platform_data = &dbgu_data,
841 .resource = dbgu_resources,
842 .num_resources = ARRAY_SIZE(dbgu_resources),
845 static inline void configure_dbgu_pins(void)
847 at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
848 at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
851 static struct resource uart0_resources[] = {
853 .start = AT91SAM9RL_BASE_US0,
854 .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
855 .flags = IORESOURCE_MEM,
858 .start = AT91SAM9RL_ID_US0,
859 .end = AT91SAM9RL_ID_US0,
860 .flags = IORESOURCE_IRQ,
864 static struct atmel_uart_data uart0_data = {
869 static u64 uart0_dmamask = DMA_BIT_MASK(32);
871 static struct platform_device at91sam9rl_uart0_device = {
872 .name = "atmel_usart",
875 .dma_mask = &uart0_dmamask,
876 .coherent_dma_mask = DMA_BIT_MASK(32),
877 .platform_data = &uart0_data,
879 .resource = uart0_resources,
880 .num_resources = ARRAY_SIZE(uart0_resources),
883 static inline void configure_usart0_pins(unsigned pins)
885 at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
886 at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
888 if (pins & ATMEL_UART_RTS)
889 at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
890 if (pins & ATMEL_UART_CTS)
891 at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
892 if (pins & ATMEL_UART_DSR)
893 at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
894 if (pins & ATMEL_UART_DTR)
895 at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
896 if (pins & ATMEL_UART_DCD)
897 at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
898 if (pins & ATMEL_UART_RI)
899 at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
902 static struct resource uart1_resources[] = {
904 .start = AT91SAM9RL_BASE_US1,
905 .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
906 .flags = IORESOURCE_MEM,
909 .start = AT91SAM9RL_ID_US1,
910 .end = AT91SAM9RL_ID_US1,
911 .flags = IORESOURCE_IRQ,
915 static struct atmel_uart_data uart1_data = {
920 static u64 uart1_dmamask = DMA_BIT_MASK(32);
922 static struct platform_device at91sam9rl_uart1_device = {
923 .name = "atmel_usart",
926 .dma_mask = &uart1_dmamask,
927 .coherent_dma_mask = DMA_BIT_MASK(32),
928 .platform_data = &uart1_data,
930 .resource = uart1_resources,
931 .num_resources = ARRAY_SIZE(uart1_resources),
934 static inline void configure_usart1_pins(unsigned pins)
936 at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
937 at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
939 if (pins & ATMEL_UART_RTS)
940 at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
941 if (pins & ATMEL_UART_CTS)
942 at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
945 static struct resource uart2_resources[] = {
947 .start = AT91SAM9RL_BASE_US2,
948 .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
949 .flags = IORESOURCE_MEM,
952 .start = AT91SAM9RL_ID_US2,
953 .end = AT91SAM9RL_ID_US2,
954 .flags = IORESOURCE_IRQ,
958 static struct atmel_uart_data uart2_data = {
963 static u64 uart2_dmamask = DMA_BIT_MASK(32);
965 static struct platform_device at91sam9rl_uart2_device = {
966 .name = "atmel_usart",
969 .dma_mask = &uart2_dmamask,
970 .coherent_dma_mask = DMA_BIT_MASK(32),
971 .platform_data = &uart2_data,
973 .resource = uart2_resources,
974 .num_resources = ARRAY_SIZE(uart2_resources),
977 static inline void configure_usart2_pins(unsigned pins)
979 at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
980 at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
982 if (pins & ATMEL_UART_RTS)
983 at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
984 if (pins & ATMEL_UART_CTS)
985 at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
988 static struct resource uart3_resources[] = {
990 .start = AT91SAM9RL_BASE_US3,
991 .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
992 .flags = IORESOURCE_MEM,
995 .start = AT91SAM9RL_ID_US3,
996 .end = AT91SAM9RL_ID_US3,
997 .flags = IORESOURCE_IRQ,
1001 static struct atmel_uart_data uart3_data = {
1006 static u64 uart3_dmamask = DMA_BIT_MASK(32);
1008 static struct platform_device at91sam9rl_uart3_device = {
1009 .name = "atmel_usart",
1012 .dma_mask = &uart3_dmamask,
1013 .coherent_dma_mask = DMA_BIT_MASK(32),
1014 .platform_data = &uart3_data,
1016 .resource = uart3_resources,
1017 .num_resources = ARRAY_SIZE(uart3_resources),
1020 static inline void configure_usart3_pins(unsigned pins)
1022 at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
1023 at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
1025 if (pins & ATMEL_UART_RTS)
1026 at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
1027 if (pins & ATMEL_UART_CTS)
1028 at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
1031 static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1032 struct platform_device *atmel_default_console_device; /* the serial console device */
1034 void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1036 struct platform_device *pdev;
1040 pdev = &at91sam9rl_dbgu_device;
1041 configure_dbgu_pins();
1042 at91_clock_associate("mck", &pdev->dev, "usart");
1044 case AT91SAM9RL_ID_US0:
1045 pdev = &at91sam9rl_uart0_device;
1046 configure_usart0_pins(pins);
1047 at91_clock_associate("usart0_clk", &pdev->dev, "usart");
1049 case AT91SAM9RL_ID_US1:
1050 pdev = &at91sam9rl_uart1_device;
1051 configure_usart1_pins(pins);
1052 at91_clock_associate("usart1_clk", &pdev->dev, "usart");
1054 case AT91SAM9RL_ID_US2:
1055 pdev = &at91sam9rl_uart2_device;
1056 configure_usart2_pins(pins);
1057 at91_clock_associate("usart2_clk", &pdev->dev, "usart");
1059 case AT91SAM9RL_ID_US3:
1060 pdev = &at91sam9rl_uart3_device;
1061 configure_usart3_pins(pins);
1062 at91_clock_associate("usart3_clk", &pdev->dev, "usart");
1067 pdev->id = portnr; /* update to mapped ID */
1069 if (portnr < ATMEL_MAX_UART)
1070 at91_uarts[portnr] = pdev;
1073 void __init at91_set_serial_console(unsigned portnr)
1075 if (portnr < ATMEL_MAX_UART)
1076 atmel_default_console_device = at91_uarts[portnr];
1079 void __init at91_add_device_serial(void)
1083 for (i = 0; i < ATMEL_MAX_UART; i++) {
1085 platform_device_register(at91_uarts[i]);
1088 if (!atmel_default_console_device)
1089 printk(KERN_INFO "AT91: No default serial console defined.\n");
1092 void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1093 void __init at91_set_serial_console(unsigned portnr) {}
1094 void __init at91_add_device_serial(void) {}
1098 /* -------------------------------------------------------------------- */
1101 * These devices are always present and don't need any board-specific
1104 static int __init at91_add_standard_devices(void)
1106 at91_add_device_rtc();
1107 at91_add_device_rtt();
1108 at91_add_device_watchdog();
1109 at91_add_device_tc();
1113 arch_initcall(at91_add_standard_devices);