at91sam9rl_devices.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /*
  2. * Copyright (C) 2007 Atmel Corporation
  3. *
  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
  6. * more details.
  7. */
  8. #include <asm/mach/arch.h>
  9. #include <asm/mach/map.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/i2c-gpio.h>
  12. #include <linux/fb.h>
  13. #include <video/atmel_lcdc.h>
  14. #include <asm/arch/board.h>
  15. #include <asm/arch/gpio.h>
  16. #include <asm/arch/at91sam9rl.h>
  17. #include <asm/arch/at91sam9rl_matrix.h>
  18. #include <asm/arch/at91sam926x_mc.h>
  19. #include "generic.h"
  20. /* --------------------------------------------------------------------
  21. * MMC / SD
  22. * -------------------------------------------------------------------- */
  23. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  24. static u64 mmc_dmamask = 0xffffffffUL;
  25. static struct at91_mmc_data mmc_data;
  26. static struct resource mmc_resources[] = {
  27. [0] = {
  28. .start = AT91SAM9RL_BASE_MCI,
  29. .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
  30. .flags = IORESOURCE_MEM,
  31. },
  32. [1] = {
  33. .start = AT91SAM9RL_ID_MCI,
  34. .end = AT91SAM9RL_ID_MCI,
  35. .flags = IORESOURCE_IRQ,
  36. },
  37. };
  38. static struct platform_device at91sam9rl_mmc_device = {
  39. .name = "at91_mci",
  40. .id = -1,
  41. .dev = {
  42. .dma_mask = &mmc_dmamask,
  43. .coherent_dma_mask = 0xffffffff,
  44. .platform_data = &mmc_data,
  45. },
  46. .resource = mmc_resources,
  47. .num_resources = ARRAY_SIZE(mmc_resources),
  48. };
  49. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  50. {
  51. if (!data)
  52. return;
  53. /* input/irq */
  54. if (data->det_pin) {
  55. at91_set_gpio_input(data->det_pin, 1);
  56. at91_set_deglitch(data->det_pin, 1);
  57. }
  58. if (data->wp_pin)
  59. at91_set_gpio_input(data->wp_pin, 1);
  60. if (data->vcc_pin)
  61. at91_set_gpio_output(data->vcc_pin, 0);
  62. /* CLK */
  63. at91_set_A_periph(AT91_PIN_PA2, 0);
  64. /* CMD */
  65. at91_set_A_periph(AT91_PIN_PA1, 1);
  66. /* DAT0, maybe DAT1..DAT3 */
  67. at91_set_A_periph(AT91_PIN_PA0, 1);
  68. if (data->wire4) {
  69. at91_set_A_periph(AT91_PIN_PA3, 1);
  70. at91_set_A_periph(AT91_PIN_PA4, 1);
  71. at91_set_A_periph(AT91_PIN_PA5, 1);
  72. }
  73. mmc_data = *data;
  74. platform_device_register(&at91sam9rl_mmc_device);
  75. }
  76. #else
  77. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  78. #endif
  79. /* --------------------------------------------------------------------
  80. * NAND / SmartMedia
  81. * -------------------------------------------------------------------- */
  82. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  83. static struct at91_nand_data nand_data;
  84. #define NAND_BASE AT91_CHIPSELECT_3
  85. static struct resource nand_resources[] = {
  86. {
  87. .start = NAND_BASE,
  88. .end = NAND_BASE + SZ_256M - 1,
  89. .flags = IORESOURCE_MEM,
  90. }
  91. };
  92. static struct platform_device at91_nand_device = {
  93. .name = "at91_nand",
  94. .id = -1,
  95. .dev = {
  96. .platform_data = &nand_data,
  97. },
  98. .resource = nand_resources,
  99. .num_resources = ARRAY_SIZE(nand_resources),
  100. };
  101. void __init at91_add_device_nand(struct at91_nand_data *data)
  102. {
  103. unsigned long csa;
  104. if (!data)
  105. return;
  106. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  107. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  108. /* set the bus interface characteristics */
  109. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
  110. | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  111. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
  112. | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
  113. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
  114. 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));
  115. /* enable pin */
  116. if (data->enable_pin)
  117. at91_set_gpio_output(data->enable_pin, 1);
  118. /* ready/busy pin */
  119. if (data->rdy_pin)
  120. at91_set_gpio_input(data->rdy_pin, 1);
  121. /* card detect pin */
  122. if (data->det_pin)
  123. at91_set_gpio_input(data->det_pin, 1);
  124. at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
  125. at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
  126. nand_data = *data;
  127. platform_device_register(&at91_nand_device);
  128. }
  129. #else
  130. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  131. #endif
  132. /* --------------------------------------------------------------------
  133. * TWI (i2c)
  134. * -------------------------------------------------------------------- */
  135. /*
  136. * Prefer the GPIO code since the TWI controller isn't robust
  137. * (gets overruns and underruns under load) and can only issue
  138. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  139. */
  140. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  141. static struct i2c_gpio_platform_data pdata = {
  142. .sda_pin = AT91_PIN_PA23,
  143. .sda_is_open_drain = 1,
  144. .scl_pin = AT91_PIN_PA24,
  145. .scl_is_open_drain = 1,
  146. .udelay = 2, /* ~100 kHz */
  147. };
  148. static struct platform_device at91sam9rl_twi_device = {
  149. .name = "i2c-gpio",
  150. .id = -1,
  151. .dev.platform_data = &pdata,
  152. };
  153. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  154. {
  155. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  156. at91_set_multi_drive(AT91_PIN_PA23, 1);
  157. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  158. at91_set_multi_drive(AT91_PIN_PA24, 1);
  159. i2c_register_board_info(0, devices, nr_devices);
  160. platform_device_register(&at91sam9rl_twi_device);
  161. }
  162. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  163. static struct resource twi_resources[] = {
  164. [0] = {
  165. .start = AT91SAM9RL_BASE_TWI0,
  166. .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
  167. .flags = IORESOURCE_MEM,
  168. },
  169. [1] = {
  170. .start = AT91SAM9RL_ID_TWI0,
  171. .end = AT91SAM9RL_ID_TWI0,
  172. .flags = IORESOURCE_IRQ,
  173. },
  174. };
  175. static struct platform_device at91sam9rl_twi_device = {
  176. .name = "at91_i2c",
  177. .id = -1,
  178. .resource = twi_resources,
  179. .num_resources = ARRAY_SIZE(twi_resources),
  180. };
  181. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  182. {
  183. /* pins used for TWI interface */
  184. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  185. at91_set_multi_drive(AT91_PIN_PA23, 1);
  186. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  187. at91_set_multi_drive(AT91_PIN_PA24, 1);
  188. i2c_register_board_info(0, devices, nr_devices);
  189. platform_device_register(&at91sam9rl_twi_device);
  190. }
  191. #else
  192. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  193. #endif
  194. /* --------------------------------------------------------------------
  195. * SPI
  196. * -------------------------------------------------------------------- */
  197. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  198. static u64 spi_dmamask = 0xffffffffUL;
  199. static struct resource spi_resources[] = {
  200. [0] = {
  201. .start = AT91SAM9RL_BASE_SPI,
  202. .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
  203. .flags = IORESOURCE_MEM,
  204. },
  205. [1] = {
  206. .start = AT91SAM9RL_ID_SPI,
  207. .end = AT91SAM9RL_ID_SPI,
  208. .flags = IORESOURCE_IRQ,
  209. },
  210. };
  211. static struct platform_device at91sam9rl_spi_device = {
  212. .name = "atmel_spi",
  213. .id = 0,
  214. .dev = {
  215. .dma_mask = &spi_dmamask,
  216. .coherent_dma_mask = 0xffffffff,
  217. },
  218. .resource = spi_resources,
  219. .num_resources = ARRAY_SIZE(spi_resources),
  220. };
  221. static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
  222. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  223. {
  224. int i;
  225. unsigned long cs_pin;
  226. at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
  227. at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
  228. at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
  229. /* Enable SPI chip-selects */
  230. for (i = 0; i < nr_devices; i++) {
  231. if (devices[i].controller_data)
  232. cs_pin = (unsigned long) devices[i].controller_data;
  233. else
  234. cs_pin = spi_standard_cs[devices[i].chip_select];
  235. /* enable chip-select pin */
  236. at91_set_gpio_output(cs_pin, 1);
  237. /* pass chip-select pin to driver */
  238. devices[i].controller_data = (void *) cs_pin;
  239. }
  240. spi_register_board_info(devices, nr_devices);
  241. platform_device_register(&at91sam9rl_spi_device);
  242. }
  243. #else
  244. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  245. #endif
  246. /* --------------------------------------------------------------------
  247. * LCD Controller
  248. * -------------------------------------------------------------------- */
  249. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  250. static u64 lcdc_dmamask = 0xffffffffUL;
  251. static struct atmel_lcdfb_info lcdc_data;
  252. static struct resource lcdc_resources[] = {
  253. [0] = {
  254. .start = AT91SAM9RL_LCDC_BASE,
  255. .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
  256. .flags = IORESOURCE_MEM,
  257. },
  258. [1] = {
  259. .start = AT91SAM9RL_ID_LCDC,
  260. .end = AT91SAM9RL_ID_LCDC,
  261. .flags = IORESOURCE_IRQ,
  262. },
  263. #if defined(CONFIG_FB_INTSRAM)
  264. [2] = {
  265. .start = AT91SAM9RL_SRAM_BASE,
  266. .end = AT91SAM9RL_SRAM_BASE + AT91SAM9RL_SRAM_SIZE - 1,
  267. .flags = IORESOURCE_MEM,
  268. },
  269. #endif
  270. };
  271. static struct platform_device at91_lcdc_device = {
  272. .name = "atmel_lcdfb",
  273. .id = 0,
  274. .dev = {
  275. .dma_mask = &lcdc_dmamask,
  276. .coherent_dma_mask = 0xffffffff,
  277. .platform_data = &lcdc_data,
  278. },
  279. .resource = lcdc_resources,
  280. .num_resources = ARRAY_SIZE(lcdc_resources),
  281. };
  282. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  283. {
  284. if (!data) {
  285. return;
  286. }
  287. at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
  288. at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
  289. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
  290. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
  291. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
  292. at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
  293. at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
  294. at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
  295. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
  296. at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
  297. at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  298. at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  299. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  300. at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  301. at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  302. at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
  303. at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
  304. at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
  305. at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
  306. at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
  307. at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
  308. lcdc_data = *data;
  309. platform_device_register(&at91_lcdc_device);
  310. }
  311. #else
  312. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  313. #endif
  314. /* --------------------------------------------------------------------
  315. * RTC
  316. * -------------------------------------------------------------------- */
  317. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  318. static struct platform_device at91sam9rl_rtc_device = {
  319. .name = "at91_rtc",
  320. .id = -1,
  321. .num_resources = 0,
  322. };
  323. static void __init at91_add_device_rtc(void)
  324. {
  325. platform_device_register(&at91sam9rl_rtc_device);
  326. }
  327. #else
  328. static void __init at91_add_device_rtc(void) {}
  329. #endif
  330. /* --------------------------------------------------------------------
  331. * RTT
  332. * -------------------------------------------------------------------- */
  333. static struct resource rtt_resources[] = {
  334. {
  335. .start = AT91_BASE_SYS + AT91_RTT,
  336. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  337. .flags = IORESOURCE_MEM,
  338. }
  339. };
  340. static struct platform_device at91sam9rl_rtt_device = {
  341. .name = "at91_rtt",
  342. .id = -1,
  343. .resource = rtt_resources,
  344. .num_resources = ARRAY_SIZE(rtt_resources),
  345. };
  346. static void __init at91_add_device_rtt(void)
  347. {
  348. platform_device_register(&at91sam9rl_rtt_device);
  349. }
  350. /* --------------------------------------------------------------------
  351. * Watchdog
  352. * -------------------------------------------------------------------- */
  353. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  354. static struct platform_device at91sam9rl_wdt_device = {
  355. .name = "at91_wdt",
  356. .id = -1,
  357. .num_resources = 0,
  358. };
  359. static void __init at91_add_device_watchdog(void)
  360. {
  361. platform_device_register(&at91sam9rl_wdt_device);
  362. }
  363. #else
  364. static void __init at91_add_device_watchdog(void) {}
  365. #endif
  366. /* --------------------------------------------------------------------
  367. * LEDs
  368. * -------------------------------------------------------------------- */
  369. #if defined(CONFIG_LEDS)
  370. u8 at91_leds_cpu;
  371. u8 at91_leds_timer;
  372. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  373. {
  374. /* Enable GPIO to access the LEDs */
  375. at91_set_gpio_output(cpu_led, 1);
  376. at91_set_gpio_output(timer_led, 1);
  377. at91_leds_cpu = cpu_led;
  378. at91_leds_timer = timer_led;
  379. }
  380. #else
  381. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  382. #endif
  383. /* --------------------------------------------------------------------
  384. * UART
  385. * -------------------------------------------------------------------- */
  386. #if defined(CONFIG_SERIAL_ATMEL)
  387. static struct resource dbgu_resources[] = {
  388. [0] = {
  389. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  390. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  391. .flags = IORESOURCE_MEM,
  392. },
  393. [1] = {
  394. .start = AT91_ID_SYS,
  395. .end = AT91_ID_SYS,
  396. .flags = IORESOURCE_IRQ,
  397. },
  398. };
  399. static struct atmel_uart_data dbgu_data = {
  400. .use_dma_tx = 0,
  401. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  402. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  403. };
  404. static struct platform_device at91sam9rl_dbgu_device = {
  405. .name = "atmel_usart",
  406. .id = 0,
  407. .dev = {
  408. .platform_data = &dbgu_data,
  409. .coherent_dma_mask = 0xffffffff,
  410. },
  411. .resource = dbgu_resources,
  412. .num_resources = ARRAY_SIZE(dbgu_resources),
  413. };
  414. static inline void configure_dbgu_pins(void)
  415. {
  416. at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
  417. at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
  418. }
  419. static struct resource uart0_resources[] = {
  420. [0] = {
  421. .start = AT91SAM9RL_BASE_US0,
  422. .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
  423. .flags = IORESOURCE_MEM,
  424. },
  425. [1] = {
  426. .start = AT91SAM9RL_ID_US0,
  427. .end = AT91SAM9RL_ID_US0,
  428. .flags = IORESOURCE_IRQ,
  429. },
  430. };
  431. static struct atmel_uart_data uart0_data = {
  432. .use_dma_tx = 1,
  433. .use_dma_rx = 1,
  434. };
  435. static struct platform_device at91sam9rl_uart0_device = {
  436. .name = "atmel_usart",
  437. .id = 1,
  438. .dev = {
  439. .platform_data = &uart0_data,
  440. .coherent_dma_mask = 0xffffffff,
  441. },
  442. .resource = uart0_resources,
  443. .num_resources = ARRAY_SIZE(uart0_resources),
  444. };
  445. static inline void configure_usart0_pins(void)
  446. {
  447. at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
  448. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  449. at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
  450. at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
  451. }
  452. static struct resource uart1_resources[] = {
  453. [0] = {
  454. .start = AT91SAM9RL_BASE_US1,
  455. .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
  456. .flags = IORESOURCE_MEM,
  457. },
  458. [1] = {
  459. .start = AT91SAM9RL_ID_US1,
  460. .end = AT91SAM9RL_ID_US1,
  461. .flags = IORESOURCE_IRQ,
  462. },
  463. };
  464. static struct atmel_uart_data uart1_data = {
  465. .use_dma_tx = 1,
  466. .use_dma_rx = 1,
  467. };
  468. static struct platform_device at91sam9rl_uart1_device = {
  469. .name = "atmel_usart",
  470. .id = 2,
  471. .dev = {
  472. .platform_data = &uart1_data,
  473. .coherent_dma_mask = 0xffffffff,
  474. },
  475. .resource = uart1_resources,
  476. .num_resources = ARRAY_SIZE(uart1_resources),
  477. };
  478. static inline void configure_usart1_pins(void)
  479. {
  480. at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
  481. at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
  482. }
  483. static struct resource uart2_resources[] = {
  484. [0] = {
  485. .start = AT91SAM9RL_BASE_US2,
  486. .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
  487. .flags = IORESOURCE_MEM,
  488. },
  489. [1] = {
  490. .start = AT91SAM9RL_ID_US2,
  491. .end = AT91SAM9RL_ID_US2,
  492. .flags = IORESOURCE_IRQ,
  493. },
  494. };
  495. static struct atmel_uart_data uart2_data = {
  496. .use_dma_tx = 1,
  497. .use_dma_rx = 1,
  498. };
  499. static struct platform_device at91sam9rl_uart2_device = {
  500. .name = "atmel_usart",
  501. .id = 3,
  502. .dev = {
  503. .platform_data = &uart2_data,
  504. .coherent_dma_mask = 0xffffffff,
  505. },
  506. .resource = uart2_resources,
  507. .num_resources = ARRAY_SIZE(uart2_resources),
  508. };
  509. static inline void configure_usart2_pins(void)
  510. {
  511. at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
  512. at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
  513. }
  514. static struct resource uart3_resources[] = {
  515. [0] = {
  516. .start = AT91SAM9RL_BASE_US3,
  517. .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
  518. .flags = IORESOURCE_MEM,
  519. },
  520. [1] = {
  521. .start = AT91SAM9RL_ID_US3,
  522. .end = AT91SAM9RL_ID_US3,
  523. .flags = IORESOURCE_IRQ,
  524. },
  525. };
  526. static struct atmel_uart_data uart3_data = {
  527. .use_dma_tx = 1,
  528. .use_dma_rx = 1,
  529. };
  530. static struct platform_device at91sam9rl_uart3_device = {
  531. .name = "atmel_usart",
  532. .id = 4,
  533. .dev = {
  534. .platform_data = &uart3_data,
  535. .coherent_dma_mask = 0xffffffff,
  536. },
  537. .resource = uart3_resources,
  538. .num_resources = ARRAY_SIZE(uart3_resources),
  539. };
  540. static inline void configure_usart3_pins(void)
  541. {
  542. at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
  543. at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
  544. }
  545. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  546. struct platform_device *atmel_default_console_device; /* the serial console device */
  547. void __init at91_init_serial(struct at91_uart_config *config)
  548. {
  549. int i;
  550. /* Fill in list of supported UARTs */
  551. for (i = 0; i < config->nr_tty; i++) {
  552. switch (config->tty_map[i]) {
  553. case 0:
  554. configure_usart0_pins();
  555. at91_uarts[i] = &at91sam9rl_uart0_device;
  556. at91_clock_associate("usart0_clk", &at91sam9rl_uart0_device.dev, "usart");
  557. break;
  558. case 1:
  559. configure_usart1_pins();
  560. at91_uarts[i] = &at91sam9rl_uart1_device;
  561. at91_clock_associate("usart1_clk", &at91sam9rl_uart1_device.dev, "usart");
  562. break;
  563. case 2:
  564. configure_usart2_pins();
  565. at91_uarts[i] = &at91sam9rl_uart2_device;
  566. at91_clock_associate("usart2_clk", &at91sam9rl_uart2_device.dev, "usart");
  567. break;
  568. case 3:
  569. configure_usart3_pins();
  570. at91_uarts[i] = &at91sam9rl_uart3_device;
  571. at91_clock_associate("usart3_clk", &at91sam9rl_uart3_device.dev, "usart");
  572. break;
  573. case 4:
  574. configure_dbgu_pins();
  575. at91_uarts[i] = &at91sam9rl_dbgu_device;
  576. at91_clock_associate("mck", &at91sam9rl_dbgu_device.dev, "usart");
  577. break;
  578. default:
  579. continue;
  580. }
  581. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  582. }
  583. /* Set serial console device */
  584. if (config->console_tty < ATMEL_MAX_UART)
  585. atmel_default_console_device = at91_uarts[config->console_tty];
  586. if (!atmel_default_console_device)
  587. printk(KERN_INFO "AT91: No default serial console defined.\n");
  588. }
  589. void __init at91_add_device_serial(void)
  590. {
  591. int i;
  592. for (i = 0; i < ATMEL_MAX_UART; i++) {
  593. if (at91_uarts[i])
  594. platform_device_register(at91_uarts[i]);
  595. }
  596. }
  597. #else
  598. void __init at91_init_serial(struct at91_uart_config *config) {}
  599. void __init at91_add_device_serial(void) {}
  600. #endif
  601. /* -------------------------------------------------------------------- */
  602. /*
  603. * These devices are always present and don't need any board-specific
  604. * setup.
  605. */
  606. static int __init at91_add_standard_devices(void)
  607. {
  608. at91_add_device_rtc();
  609. at91_add_device_rtt();
  610. at91_add_device_watchdog();
  611. return 0;
  612. }
  613. arch_initcall(at91_add_standard_devices);