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/platform_device.h>
13 #include <linux/i2c-gpio.h>
16 #include <video/atmel_lcdc.h>
18 #include <asm/arch/board.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/at91sam9rl.h>
21 #include <asm/arch/at91sam9rl_matrix.h>
22 #include <asm/arch/at91sam926x_mc.h>
27 /* --------------------------------------------------------------------
29 * -------------------------------------------------------------------- */
31 #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
32 static u64 mmc_dmamask = 0xffffffffUL;
33 static struct at91_mmc_data mmc_data;
35 static struct resource mmc_resources[] = {
37 .start = AT91SAM9RL_BASE_MCI,
38 .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
39 .flags = IORESOURCE_MEM,
42 .start = AT91SAM9RL_ID_MCI,
43 .end = AT91SAM9RL_ID_MCI,
44 .flags = IORESOURCE_IRQ,
48 static struct platform_device at91sam9rl_mmc_device = {
52 .dma_mask = &mmc_dmamask,
53 .coherent_dma_mask = 0xffffffff,
54 .platform_data = &mmc_data,
56 .resource = mmc_resources,
57 .num_resources = ARRAY_SIZE(mmc_resources),
60 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
67 at91_set_gpio_input(data->det_pin, 1);
68 at91_set_deglitch(data->det_pin, 1);
71 at91_set_gpio_input(data->wp_pin, 1);
73 at91_set_gpio_output(data->vcc_pin, 0);
76 at91_set_A_periph(AT91_PIN_PA2, 0);
79 at91_set_A_periph(AT91_PIN_PA1, 1);
81 /* DAT0, maybe DAT1..DAT3 */
82 at91_set_A_periph(AT91_PIN_PA0, 1);
84 at91_set_A_periph(AT91_PIN_PA3, 1);
85 at91_set_A_periph(AT91_PIN_PA4, 1);
86 at91_set_A_periph(AT91_PIN_PA5, 1);
90 platform_device_register(&at91sam9rl_mmc_device);
93 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
97 /* --------------------------------------------------------------------
99 * -------------------------------------------------------------------- */
101 #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
102 static struct at91_nand_data nand_data;
104 #define NAND_BASE AT91_CHIPSELECT_3
106 static struct resource nand_resources[] = {
109 .end = NAND_BASE + SZ_256M - 1,
110 .flags = IORESOURCE_MEM,
114 static struct platform_device at91_nand_device = {
118 .platform_data = &nand_data,
120 .resource = nand_resources,
121 .num_resources = ARRAY_SIZE(nand_resources),
124 void __init at91_add_device_nand(struct at91_nand_data *data)
131 csa = at91_sys_read(AT91_MATRIX_EBICSA);
132 at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
134 /* set the bus interface characteristics */
135 at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
136 | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
138 at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
139 | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
141 at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
143 at91_sys_write(AT91_SMC_MODE(3), AT91_SMC_DBW_8 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
146 if (data->enable_pin)
147 at91_set_gpio_output(data->enable_pin, 1);
151 at91_set_gpio_input(data->rdy_pin, 1);
153 /* card detect pin */
155 at91_set_gpio_input(data->det_pin, 1);
157 at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
158 at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
161 platform_device_register(&at91_nand_device);
165 void __init at91_add_device_nand(struct at91_nand_data *data) {}
169 /* --------------------------------------------------------------------
171 * -------------------------------------------------------------------- */
174 * Prefer the GPIO code since the TWI controller isn't robust
175 * (gets overruns and underruns under load) and can only issue
176 * repeated STARTs in one scenario (the driver doesn't yet handle them).
178 #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
180 static struct i2c_gpio_platform_data pdata = {
181 .sda_pin = AT91_PIN_PA23,
182 .sda_is_open_drain = 1,
183 .scl_pin = AT91_PIN_PA24,
184 .scl_is_open_drain = 1,
185 .udelay = 2, /* ~100 kHz */
188 static struct platform_device at91sam9rl_twi_device = {
191 .dev.platform_data = &pdata,
194 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
196 at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
197 at91_set_multi_drive(AT91_PIN_PA23, 1);
199 at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
200 at91_set_multi_drive(AT91_PIN_PA24, 1);
202 i2c_register_board_info(0, devices, nr_devices);
203 platform_device_register(&at91sam9rl_twi_device);
206 #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
208 static struct resource twi_resources[] = {
210 .start = AT91SAM9RL_BASE_TWI0,
211 .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
212 .flags = IORESOURCE_MEM,
215 .start = AT91SAM9RL_ID_TWI0,
216 .end = AT91SAM9RL_ID_TWI0,
217 .flags = IORESOURCE_IRQ,
221 static struct platform_device at91sam9rl_twi_device = {
224 .resource = twi_resources,
225 .num_resources = ARRAY_SIZE(twi_resources),
228 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
230 /* pins used for TWI interface */
231 at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
232 at91_set_multi_drive(AT91_PIN_PA23, 1);
234 at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
235 at91_set_multi_drive(AT91_PIN_PA24, 1);
237 i2c_register_board_info(0, devices, nr_devices);
238 platform_device_register(&at91sam9rl_twi_device);
241 void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
245 /* --------------------------------------------------------------------
247 * -------------------------------------------------------------------- */
249 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
250 static u64 spi_dmamask = 0xffffffffUL;
252 static struct resource spi_resources[] = {
254 .start = AT91SAM9RL_BASE_SPI,
255 .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
256 .flags = IORESOURCE_MEM,
259 .start = AT91SAM9RL_ID_SPI,
260 .end = AT91SAM9RL_ID_SPI,
261 .flags = IORESOURCE_IRQ,
265 static struct platform_device at91sam9rl_spi_device = {
269 .dma_mask = &spi_dmamask,
270 .coherent_dma_mask = 0xffffffff,
272 .resource = spi_resources,
273 .num_resources = ARRAY_SIZE(spi_resources),
276 static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
279 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
282 unsigned long cs_pin;
284 at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
285 at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
286 at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
288 /* Enable SPI chip-selects */
289 for (i = 0; i < nr_devices; i++) {
290 if (devices[i].controller_data)
291 cs_pin = (unsigned long) devices[i].controller_data;
293 cs_pin = spi_standard_cs[devices[i].chip_select];
295 /* enable chip-select pin */
296 at91_set_gpio_output(cs_pin, 1);
298 /* pass chip-select pin to driver */
299 devices[i].controller_data = (void *) cs_pin;
302 spi_register_board_info(devices, nr_devices);
303 platform_device_register(&at91sam9rl_spi_device);
306 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
310 /* --------------------------------------------------------------------
312 * -------------------------------------------------------------------- */
314 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
315 static u64 lcdc_dmamask = 0xffffffffUL;
316 static struct atmel_lcdfb_info lcdc_data;
318 static struct resource lcdc_resources[] = {
320 .start = AT91SAM9RL_LCDC_BASE,
321 .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
322 .flags = IORESOURCE_MEM,
325 .start = AT91SAM9RL_ID_LCDC,
326 .end = AT91SAM9RL_ID_LCDC,
327 .flags = IORESOURCE_IRQ,
329 #if defined(CONFIG_FB_INTSRAM)
331 .start = AT91SAM9RL_SRAM_BASE,
332 .end = AT91SAM9RL_SRAM_BASE + AT91SAM9RL_SRAM_SIZE - 1,
333 .flags = IORESOURCE_MEM,
338 static struct platform_device at91_lcdc_device = {
339 .name = "atmel_lcdfb",
342 .dma_mask = &lcdc_dmamask,
343 .coherent_dma_mask = 0xffffffff,
344 .platform_data = &lcdc_data,
346 .resource = lcdc_resources,
347 .num_resources = ARRAY_SIZE(lcdc_resources),
350 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
356 at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
357 at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
358 at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
359 at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
360 at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
361 at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
362 at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
363 at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
364 at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
365 at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
366 at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
367 at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
368 at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
369 at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
370 at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
371 at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
372 at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
373 at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
374 at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
375 at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
376 at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
379 platform_device_register(&at91_lcdc_device);
382 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
386 /* --------------------------------------------------------------------
388 * -------------------------------------------------------------------- */
390 #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
391 static struct platform_device at91sam9rl_rtc_device = {
397 static void __init at91_add_device_rtc(void)
399 platform_device_register(&at91sam9rl_rtc_device);
402 static void __init at91_add_device_rtc(void) {}
406 /* --------------------------------------------------------------------
408 * -------------------------------------------------------------------- */
410 static struct resource rtt_resources[] = {
412 .start = AT91_BASE_SYS + AT91_RTT,
413 .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
414 .flags = IORESOURCE_MEM,
418 static struct platform_device at91sam9rl_rtt_device = {
421 .resource = rtt_resources,
422 .num_resources = ARRAY_SIZE(rtt_resources),
425 static void __init at91_add_device_rtt(void)
427 platform_device_register(&at91sam9rl_rtt_device);
431 /* --------------------------------------------------------------------
433 * -------------------------------------------------------------------- */
435 #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
436 static struct platform_device at91sam9rl_wdt_device = {
442 static void __init at91_add_device_watchdog(void)
444 platform_device_register(&at91sam9rl_wdt_device);
447 static void __init at91_add_device_watchdog(void) {}
451 /* --------------------------------------------------------------------
453 * -------------------------------------------------------------------- */
455 #if defined(CONFIG_LEDS)
459 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
461 /* Enable GPIO to access the LEDs */
462 at91_set_gpio_output(cpu_led, 1);
463 at91_set_gpio_output(timer_led, 1);
465 at91_leds_cpu = cpu_led;
466 at91_leds_timer = timer_led;
469 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
473 /* --------------------------------------------------------------------
475 * -------------------------------------------------------------------- */
477 #if defined(CONFIG_SERIAL_ATMEL)
478 static struct resource dbgu_resources[] = {
480 .start = AT91_VA_BASE_SYS + AT91_DBGU,
481 .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
482 .flags = IORESOURCE_MEM,
485 .start = AT91_ID_SYS,
487 .flags = IORESOURCE_IRQ,
491 static struct atmel_uart_data dbgu_data = {
493 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
494 .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
497 static struct platform_device at91sam9rl_dbgu_device = {
498 .name = "atmel_usart",
501 .platform_data = &dbgu_data,
502 .coherent_dma_mask = 0xffffffff,
504 .resource = dbgu_resources,
505 .num_resources = ARRAY_SIZE(dbgu_resources),
508 static inline void configure_dbgu_pins(void)
510 at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
511 at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
514 static struct resource uart0_resources[] = {
516 .start = AT91SAM9RL_BASE_US0,
517 .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
518 .flags = IORESOURCE_MEM,
521 .start = AT91SAM9RL_ID_US0,
522 .end = AT91SAM9RL_ID_US0,
523 .flags = IORESOURCE_IRQ,
527 static struct atmel_uart_data uart0_data = {
532 static struct platform_device at91sam9rl_uart0_device = {
533 .name = "atmel_usart",
536 .platform_data = &uart0_data,
537 .coherent_dma_mask = 0xffffffff,
539 .resource = uart0_resources,
540 .num_resources = ARRAY_SIZE(uart0_resources),
543 static inline void configure_usart0_pins(void)
545 at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
546 at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
547 at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
548 at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
551 static struct resource uart1_resources[] = {
553 .start = AT91SAM9RL_BASE_US1,
554 .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
555 .flags = IORESOURCE_MEM,
558 .start = AT91SAM9RL_ID_US1,
559 .end = AT91SAM9RL_ID_US1,
560 .flags = IORESOURCE_IRQ,
564 static struct atmel_uart_data uart1_data = {
569 static struct platform_device at91sam9rl_uart1_device = {
570 .name = "atmel_usart",
573 .platform_data = &uart1_data,
574 .coherent_dma_mask = 0xffffffff,
576 .resource = uart1_resources,
577 .num_resources = ARRAY_SIZE(uart1_resources),
580 static inline void configure_usart1_pins(void)
582 at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
583 at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
586 static struct resource uart2_resources[] = {
588 .start = AT91SAM9RL_BASE_US2,
589 .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
590 .flags = IORESOURCE_MEM,
593 .start = AT91SAM9RL_ID_US2,
594 .end = AT91SAM9RL_ID_US2,
595 .flags = IORESOURCE_IRQ,
599 static struct atmel_uart_data uart2_data = {
604 static struct platform_device at91sam9rl_uart2_device = {
605 .name = "atmel_usart",
608 .platform_data = &uart2_data,
609 .coherent_dma_mask = 0xffffffff,
611 .resource = uart2_resources,
612 .num_resources = ARRAY_SIZE(uart2_resources),
615 static inline void configure_usart2_pins(void)
617 at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
618 at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
621 static struct resource uart3_resources[] = {
623 .start = AT91SAM9RL_BASE_US3,
624 .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
625 .flags = IORESOURCE_MEM,
628 .start = AT91SAM9RL_ID_US3,
629 .end = AT91SAM9RL_ID_US3,
630 .flags = IORESOURCE_IRQ,
634 static struct atmel_uart_data uart3_data = {
639 static struct platform_device at91sam9rl_uart3_device = {
640 .name = "atmel_usart",
643 .platform_data = &uart3_data,
644 .coherent_dma_mask = 0xffffffff,
646 .resource = uart3_resources,
647 .num_resources = ARRAY_SIZE(uart3_resources),
650 static inline void configure_usart3_pins(void)
652 at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
653 at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
656 struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
657 struct platform_device *atmel_default_console_device; /* the serial console device */
659 void __init at91_init_serial(struct at91_uart_config *config)
663 /* Fill in list of supported UARTs */
664 for (i = 0; i < config->nr_tty; i++) {
665 switch (config->tty_map[i]) {
667 configure_usart0_pins();
668 at91_uarts[i] = &at91sam9rl_uart0_device;
669 at91_clock_associate("usart0_clk", &at91sam9rl_uart0_device.dev, "usart");
672 configure_usart1_pins();
673 at91_uarts[i] = &at91sam9rl_uart1_device;
674 at91_clock_associate("usart1_clk", &at91sam9rl_uart1_device.dev, "usart");
677 configure_usart2_pins();
678 at91_uarts[i] = &at91sam9rl_uart2_device;
679 at91_clock_associate("usart2_clk", &at91sam9rl_uart2_device.dev, "usart");
682 configure_usart3_pins();
683 at91_uarts[i] = &at91sam9rl_uart3_device;
684 at91_clock_associate("usart3_clk", &at91sam9rl_uart3_device.dev, "usart");
687 configure_dbgu_pins();
688 at91_uarts[i] = &at91sam9rl_dbgu_device;
689 at91_clock_associate("mck", &at91sam9rl_dbgu_device.dev, "usart");
694 at91_uarts[i]->id = i; /* update ID number to mapped ID */
697 /* Set serial console device */
698 if (config->console_tty < ATMEL_MAX_UART)
699 atmel_default_console_device = at91_uarts[config->console_tty];
700 if (!atmel_default_console_device)
701 printk(KERN_INFO "AT91: No default serial console defined.\n");
704 void __init at91_add_device_serial(void)
708 for (i = 0; i < ATMEL_MAX_UART; i++) {
710 platform_device_register(at91_uarts[i]);
714 void __init at91_init_serial(struct at91_uart_config *config) {}
715 void __init at91_add_device_serial(void) {}
719 /* -------------------------------------------------------------------- */
722 * These devices are always present and don't need any board-specific
725 static int __init at91_add_standard_devices(void)
727 at91_add_device_rtc();
728 at91_add_device_rtt();
729 at91_add_device_watchdog();
733 arch_initcall(at91_add_standard_devices);