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>
15 #include <video/atmel_lcdc.h>
17 #include <asm/arch/board.h>
18 #include <asm/arch/gpio.h>
19 #include <asm/arch/at91sam9rl.h>
20 #include <asm/arch/at91sam9rl_matrix.h>
21 #include <asm/arch/at91sam926x_mc.h>
26 /* --------------------------------------------------------------------
28 * -------------------------------------------------------------------- */
30 #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
31 static u64 mmc_dmamask = 0xffffffffUL;
32 static struct at91_mmc_data mmc_data;
34 static struct resource mmc_resources[] = {
36 .start = AT91SAM9RL_BASE_MCI,
37 .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
38 .flags = IORESOURCE_MEM,
41 .start = AT91SAM9RL_ID_MCI,
42 .end = AT91SAM9RL_ID_MCI,
43 .flags = IORESOURCE_IRQ,
47 static struct platform_device at91sam9rl_mmc_device = {
51 .dma_mask = &mmc_dmamask,
52 .coherent_dma_mask = 0xffffffff,
53 .platform_data = &mmc_data,
55 .resource = mmc_resources,
56 .num_resources = ARRAY_SIZE(mmc_resources),
59 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
66 at91_set_gpio_input(data->det_pin, 1);
67 at91_set_deglitch(data->det_pin, 1);
70 at91_set_gpio_input(data->wp_pin, 1);
72 at91_set_gpio_output(data->vcc_pin, 0);
75 at91_set_A_periph(AT91_PIN_PA2, 0);
78 at91_set_A_periph(AT91_PIN_PA1, 1);
80 /* DAT0, maybe DAT1..DAT3 */
81 at91_set_A_periph(AT91_PIN_PA0, 1);
83 at91_set_A_periph(AT91_PIN_PA3, 1);
84 at91_set_A_periph(AT91_PIN_PA4, 1);
85 at91_set_A_periph(AT91_PIN_PA5, 1);
89 platform_device_register(&at91sam9rl_mmc_device);
92 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
96 /* --------------------------------------------------------------------
98 * -------------------------------------------------------------------- */
100 #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
101 static struct at91_nand_data nand_data;
103 #define NAND_BASE AT91_CHIPSELECT_3
105 static struct resource nand_resources[] = {
108 .end = NAND_BASE + SZ_256M - 1,
109 .flags = IORESOURCE_MEM,
113 static struct platform_device at91_nand_device = {
117 .platform_data = &nand_data,
119 .resource = nand_resources,
120 .num_resources = ARRAY_SIZE(nand_resources),
123 void __init at91_add_device_nand(struct at91_nand_data *data)
130 csa = at91_sys_read(AT91_MATRIX_EBICSA);
131 at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
133 /* set the bus interface characteristics */
134 at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
135 | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
137 at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
138 | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
140 at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
142 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));
145 if (data->enable_pin)
146 at91_set_gpio_output(data->enable_pin, 1);
150 at91_set_gpio_input(data->rdy_pin, 1);
152 /* card detect pin */
154 at91_set_gpio_input(data->det_pin, 1);
156 at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
157 at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
160 platform_device_register(&at91_nand_device);
164 void __init at91_add_device_nand(struct at91_nand_data *data) {}
168 /* --------------------------------------------------------------------
170 * -------------------------------------------------------------------- */
172 #if defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
174 static struct resource twi_resources[] = {
176 .start = AT91SAM9RL_BASE_TWI0,
177 .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
178 .flags = IORESOURCE_MEM,
181 .start = AT91SAM9RL_ID_TWI0,
182 .end = AT91SAM9RL_ID_TWI0,
183 .flags = IORESOURCE_IRQ,
187 static struct platform_device at91sam9rl_twi_device = {
190 .resource = twi_resources,
191 .num_resources = ARRAY_SIZE(twi_resources),
194 void __init at91_add_device_i2c(void)
196 /* pins used for TWI interface */
197 at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
198 at91_set_multi_drive(AT91_PIN_PA23, 1);
200 at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
201 at91_set_multi_drive(AT91_PIN_PA24, 1);
203 platform_device_register(&at91sam9rl_twi_device);
206 void __init at91_add_device_i2c(void) {}
210 /* --------------------------------------------------------------------
212 * -------------------------------------------------------------------- */
214 #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
215 static u64 spi_dmamask = 0xffffffffUL;
217 static struct resource spi_resources[] = {
219 .start = AT91SAM9RL_BASE_SPI,
220 .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
221 .flags = IORESOURCE_MEM,
224 .start = AT91SAM9RL_ID_SPI,
225 .end = AT91SAM9RL_ID_SPI,
226 .flags = IORESOURCE_IRQ,
230 static struct platform_device at91sam9rl_spi_device = {
234 .dma_mask = &spi_dmamask,
235 .coherent_dma_mask = 0xffffffff,
237 .resource = spi_resources,
238 .num_resources = ARRAY_SIZE(spi_resources),
241 static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
244 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
247 unsigned long cs_pin;
249 at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
250 at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
251 at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
253 /* Enable SPI chip-selects */
254 for (i = 0; i < nr_devices; i++) {
255 if (devices[i].controller_data)
256 cs_pin = (unsigned long) devices[i].controller_data;
258 cs_pin = spi_standard_cs[devices[i].chip_select];
260 /* enable chip-select pin */
261 at91_set_gpio_output(cs_pin, 1);
263 /* pass chip-select pin to driver */
264 devices[i].controller_data = (void *) cs_pin;
267 spi_register_board_info(devices, nr_devices);
268 platform_device_register(&at91sam9rl_spi_device);
271 void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
275 /* --------------------------------------------------------------------
277 * -------------------------------------------------------------------- */
279 #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
280 static u64 lcdc_dmamask = 0xffffffffUL;
281 static struct atmel_lcdfb_info lcdc_data;
283 static struct resource lcdc_resources[] = {
285 .start = AT91SAM9RL_LCDC_BASE,
286 .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
287 .flags = IORESOURCE_MEM,
290 .start = AT91SAM9RL_ID_LCDC,
291 .end = AT91SAM9RL_ID_LCDC,
292 .flags = IORESOURCE_IRQ,
294 #if defined(CONFIG_FB_INTSRAM)
296 .start = AT91SAM9RL_SRAM_BASE,
297 .end = AT91SAM9RL_SRAM_BASE + AT91SAM9RL_SRAM_SIZE - 1,
298 .flags = IORESOURCE_MEM,
303 static struct platform_device at91_lcdc_device = {
304 .name = "atmel_lcdfb",
307 .dma_mask = &lcdc_dmamask,
308 .coherent_dma_mask = 0xffffffff,
309 .platform_data = &lcdc_data,
311 .resource = lcdc_resources,
312 .num_resources = ARRAY_SIZE(lcdc_resources),
315 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
321 at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
322 at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
323 at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
324 at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
325 at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
326 at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
327 at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
328 at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
329 at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
330 at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
331 at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
332 at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
333 at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
334 at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
335 at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
336 at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
337 at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
338 at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
339 at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
340 at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
341 at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
344 platform_device_register(&at91_lcdc_device);
347 void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
351 /* --------------------------------------------------------------------
353 * -------------------------------------------------------------------- */
355 #if defined(CONFIG_LEDS)
359 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
361 /* Enable GPIO to access the LEDs */
362 at91_set_gpio_output(cpu_led, 1);
363 at91_set_gpio_output(timer_led, 1);
365 at91_leds_cpu = cpu_led;
366 at91_leds_timer = timer_led;
369 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
373 /* --------------------------------------------------------------------
375 * -------------------------------------------------------------------- */
377 #if defined(CONFIG_SERIAL_ATMEL)
378 static struct resource dbgu_resources[] = {
380 .start = AT91_VA_BASE_SYS + AT91_DBGU,
381 .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
382 .flags = IORESOURCE_MEM,
385 .start = AT91_ID_SYS,
387 .flags = IORESOURCE_IRQ,
391 static struct atmel_uart_data dbgu_data = {
393 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
394 .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
397 static struct platform_device at91sam9rl_dbgu_device = {
398 .name = "atmel_usart",
401 .platform_data = &dbgu_data,
402 .coherent_dma_mask = 0xffffffff,
404 .resource = dbgu_resources,
405 .num_resources = ARRAY_SIZE(dbgu_resources),
408 static inline void configure_dbgu_pins(void)
410 at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
411 at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
414 static struct resource uart0_resources[] = {
416 .start = AT91SAM9RL_BASE_US0,
417 .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
418 .flags = IORESOURCE_MEM,
421 .start = AT91SAM9RL_ID_US0,
422 .end = AT91SAM9RL_ID_US0,
423 .flags = IORESOURCE_IRQ,
427 static struct atmel_uart_data uart0_data = {
432 static struct platform_device at91sam9rl_uart0_device = {
433 .name = "atmel_usart",
436 .platform_data = &uart0_data,
437 .coherent_dma_mask = 0xffffffff,
439 .resource = uart0_resources,
440 .num_resources = ARRAY_SIZE(uart0_resources),
443 static inline void configure_usart0_pins(void)
445 at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
446 at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
447 at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
448 at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
451 static struct resource uart1_resources[] = {
453 .start = AT91SAM9RL_BASE_US1,
454 .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
455 .flags = IORESOURCE_MEM,
458 .start = AT91SAM9RL_ID_US1,
459 .end = AT91SAM9RL_ID_US1,
460 .flags = IORESOURCE_IRQ,
464 static struct atmel_uart_data uart1_data = {
469 static struct platform_device at91sam9rl_uart1_device = {
470 .name = "atmel_usart",
473 .platform_data = &uart1_data,
474 .coherent_dma_mask = 0xffffffff,
476 .resource = uart1_resources,
477 .num_resources = ARRAY_SIZE(uart1_resources),
480 static inline void configure_usart1_pins(void)
482 at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
483 at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
486 static struct resource uart2_resources[] = {
488 .start = AT91SAM9RL_BASE_US2,
489 .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
490 .flags = IORESOURCE_MEM,
493 .start = AT91SAM9RL_ID_US2,
494 .end = AT91SAM9RL_ID_US2,
495 .flags = IORESOURCE_IRQ,
499 static struct atmel_uart_data uart2_data = {
504 static struct platform_device at91sam9rl_uart2_device = {
505 .name = "atmel_usart",
508 .platform_data = &uart2_data,
509 .coherent_dma_mask = 0xffffffff,
511 .resource = uart2_resources,
512 .num_resources = ARRAY_SIZE(uart2_resources),
515 static inline void configure_usart2_pins(void)
517 at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
518 at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
521 static struct resource uart3_resources[] = {
523 .start = AT91SAM9RL_BASE_US3,
524 .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
525 .flags = IORESOURCE_MEM,
528 .start = AT91SAM9RL_ID_US3,
529 .end = AT91SAM9RL_ID_US3,
530 .flags = IORESOURCE_IRQ,
534 static struct atmel_uart_data uart3_data = {
539 static struct platform_device at91sam9rl_uart3_device = {
540 .name = "atmel_usart",
543 .platform_data = &uart3_data,
544 .coherent_dma_mask = 0xffffffff,
546 .resource = uart3_resources,
547 .num_resources = ARRAY_SIZE(uart3_resources),
550 static inline void configure_usart3_pins(void)
552 at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
553 at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
556 struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
557 struct platform_device *atmel_default_console_device; /* the serial console device */
559 void __init at91_init_serial(struct at91_uart_config *config)
563 /* Fill in list of supported UARTs */
564 for (i = 0; i < config->nr_tty; i++) {
565 switch (config->tty_map[i]) {
567 configure_usart0_pins();
568 at91_uarts[i] = &at91sam9rl_uart0_device;
569 at91_clock_associate("usart0_clk", &at91sam9rl_uart0_device.dev, "usart");
572 configure_usart1_pins();
573 at91_uarts[i] = &at91sam9rl_uart1_device;
574 at91_clock_associate("usart1_clk", &at91sam9rl_uart1_device.dev, "usart");
577 configure_usart2_pins();
578 at91_uarts[i] = &at91sam9rl_uart2_device;
579 at91_clock_associate("usart2_clk", &at91sam9rl_uart2_device.dev, "usart");
582 configure_usart3_pins();
583 at91_uarts[i] = &at91sam9rl_uart3_device;
584 at91_clock_associate("usart3_clk", &at91sam9rl_uart3_device.dev, "usart");
587 configure_dbgu_pins();
588 at91_uarts[i] = &at91sam9rl_dbgu_device;
589 at91_clock_associate("mck", &at91sam9rl_dbgu_device.dev, "usart");
594 at91_uarts[i]->id = i; /* update ID number to mapped ID */
597 /* Set serial console device */
598 if (config->console_tty < ATMEL_MAX_UART)
599 atmel_default_console_device = at91_uarts[config->console_tty];
600 if (!atmel_default_console_device)
601 printk(KERN_INFO "AT91: No default serial console defined.\n");
604 void __init at91_add_device_serial(void)
608 for (i = 0; i < ATMEL_MAX_UART; i++) {
610 platform_device_register(at91_uarts[i]);
614 void __init at91_init_serial(struct at91_uart_config *config) {}
615 void __init at91_add_device_serial(void) {}
619 /* -------------------------------------------------------------------- */
622 * These devices are always present and don't need any board-specific
625 static int __init at91_add_standard_devices(void)
630 arch_initcall(at91_add_standard_devices);