devices.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /*
  2. * arch/arm/mach-at91rm9200/devices.c
  3. *
  4. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  5. * Copyright (C) 2005 David Brownell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <asm/mach/arch.h>
  14. #include <asm/mach/map.h>
  15. #include <linux/platform_device.h>
  16. #include <asm/hardware.h>
  17. #include <asm/arch/board.h>
  18. #include <asm/arch/gpio.h>
  19. #include "generic.h"
  20. #define SZ_512 0x00000200
  21. #define SZ_256 0x00000100
  22. #define SZ_16 0x00000010
  23. /* --------------------------------------------------------------------
  24. * USB Host
  25. * -------------------------------------------------------------------- */
  26. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  27. static u64 ohci_dmamask = 0xffffffffUL;
  28. static struct at91_usbh_data usbh_data;
  29. static struct resource at91_usbh_resources[] = {
  30. [0] = {
  31. .start = AT91_UHP_BASE,
  32. .end = AT91_UHP_BASE + SZ_1M - 1,
  33. .flags = IORESOURCE_MEM,
  34. },
  35. [1] = {
  36. .start = AT91_ID_UHP,
  37. .end = AT91_ID_UHP,
  38. .flags = IORESOURCE_IRQ,
  39. },
  40. };
  41. static struct platform_device at91rm9200_usbh_device = {
  42. .name = "at91_ohci",
  43. .id = -1,
  44. .dev = {
  45. .dma_mask = &ohci_dmamask,
  46. .coherent_dma_mask = 0xffffffff,
  47. .platform_data = &usbh_data,
  48. },
  49. .resource = at91_usbh_resources,
  50. .num_resources = ARRAY_SIZE(at91_usbh_resources),
  51. };
  52. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  53. {
  54. if (!data)
  55. return;
  56. usbh_data = *data;
  57. platform_device_register(&at91rm9200_usbh_device);
  58. }
  59. #else
  60. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  61. #endif
  62. /* --------------------------------------------------------------------
  63. * USB Device (Gadget)
  64. * -------------------------------------------------------------------- */
  65. #ifdef CONFIG_USB_GADGET_AT91
  66. static struct at91_udc_data udc_data;
  67. static struct resource at91_udc_resources[] = {
  68. [0] = {
  69. .start = AT91_BASE_UDP,
  70. .end = AT91_BASE_UDP + SZ_16K - 1,
  71. .flags = IORESOURCE_MEM,
  72. },
  73. [1] = {
  74. .start = AT91_ID_UDP,
  75. .end = AT91_ID_UDP,
  76. .flags = IORESOURCE_IRQ,
  77. },
  78. };
  79. static struct platform_device at91rm9200_udc_device = {
  80. .name = "at91_udc",
  81. .id = -1,
  82. .dev = {
  83. .platform_data = &udc_data,
  84. },
  85. .resource = at91_udc_resources,
  86. .num_resources = ARRAY_SIZE(at91_udc_resources),
  87. };
  88. void __init at91_add_device_udc(struct at91_udc_data *data)
  89. {
  90. if (!data)
  91. return;
  92. if (data->vbus_pin) {
  93. at91_set_gpio_input(data->vbus_pin, 0);
  94. at91_set_deglitch(data->vbus_pin, 1);
  95. }
  96. if (data->pullup_pin)
  97. at91_set_gpio_output(data->pullup_pin, 0);
  98. udc_data = *data;
  99. platform_device_register(&at91rm9200_udc_device);
  100. }
  101. #else
  102. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  103. #endif
  104. /* --------------------------------------------------------------------
  105. * Ethernet
  106. * -------------------------------------------------------------------- */
  107. #if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
  108. static u64 eth_dmamask = 0xffffffffUL;
  109. static struct at91_eth_data eth_data;
  110. static struct resource at91_eth_resources[] = {
  111. [0] = {
  112. .start = AT91_BASE_EMAC,
  113. .end = AT91_BASE_EMAC + SZ_16K - 1,
  114. .flags = IORESOURCE_MEM,
  115. },
  116. [1] = {
  117. .start = AT91_ID_EMAC,
  118. .end = AT91_ID_EMAC,
  119. .flags = IORESOURCE_IRQ,
  120. },
  121. };
  122. static struct platform_device at91rm9200_eth_device = {
  123. .name = "at91_ether",
  124. .id = -1,
  125. .dev = {
  126. .dma_mask = &eth_dmamask,
  127. .coherent_dma_mask = 0xffffffff,
  128. .platform_data = &eth_data,
  129. },
  130. .resource = at91_eth_resources,
  131. .num_resources = ARRAY_SIZE(at91_eth_resources),
  132. };
  133. void __init at91_add_device_eth(struct at91_eth_data *data)
  134. {
  135. if (!data)
  136. return;
  137. if (data->phy_irq_pin) {
  138. at91_set_gpio_input(data->phy_irq_pin, 0);
  139. at91_set_deglitch(data->phy_irq_pin, 1);
  140. }
  141. /* Pins used for MII and RMII */
  142. at91_set_A_periph(AT91_PIN_PA16, 0); /* EMDIO */
  143. at91_set_A_periph(AT91_PIN_PA15, 0); /* EMDC */
  144. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERXER */
  145. at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
  146. at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
  147. at91_set_A_periph(AT91_PIN_PA11, 0); /* ECRS_ECRSDV */
  148. at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX1 */
  149. at91_set_A_periph(AT91_PIN_PA9, 0); /* ETX0 */
  150. at91_set_A_periph(AT91_PIN_PA8, 0); /* ETXEN */
  151. at91_set_A_periph(AT91_PIN_PA7, 0); /* ETXCK_EREFCK */
  152. if (!data->is_rmii) {
  153. at91_set_B_periph(AT91_PIN_PB19, 0); /* ERXCK */
  154. at91_set_B_periph(AT91_PIN_PB18, 0); /* ECOL */
  155. at91_set_B_periph(AT91_PIN_PB17, 0); /* ERXDV */
  156. at91_set_B_periph(AT91_PIN_PB16, 0); /* ERX3 */
  157. at91_set_B_periph(AT91_PIN_PB15, 0); /* ERX2 */
  158. at91_set_B_periph(AT91_PIN_PB14, 0); /* ETXER */
  159. at91_set_B_periph(AT91_PIN_PB13, 0); /* ETX3 */
  160. at91_set_B_periph(AT91_PIN_PB12, 0); /* ETX2 */
  161. }
  162. eth_data = *data;
  163. platform_device_register(&at91rm9200_eth_device);
  164. }
  165. #else
  166. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  167. #endif
  168. /* --------------------------------------------------------------------
  169. * Compact Flash / PCMCIA
  170. * -------------------------------------------------------------------- */
  171. #if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  172. static struct at91_cf_data cf_data;
  173. static struct resource at91_cf_resources[] = {
  174. [0] = {
  175. .start = AT91_CF_BASE,
  176. /* ties up CS4, CS5 and CS6 */
  177. .end = AT91_CF_BASE + (0x30000000 - 1),
  178. .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
  179. },
  180. };
  181. static struct platform_device at91rm9200_cf_device = {
  182. .name = "at91_cf",
  183. .id = -1,
  184. .dev = {
  185. .platform_data = &cf_data,
  186. },
  187. .resource = at91_cf_resources,
  188. .num_resources = ARRAY_SIZE(at91_cf_resources),
  189. };
  190. void __init at91_add_device_cf(struct at91_cf_data *data)
  191. {
  192. if (!data)
  193. return;
  194. /* input/irq */
  195. if (data->irq_pin) {
  196. at91_set_gpio_input(data->irq_pin, 1);
  197. at91_set_deglitch(data->irq_pin, 1);
  198. }
  199. at91_set_gpio_input(data->det_pin, 1);
  200. at91_set_deglitch(data->det_pin, 1);
  201. /* outputs, initially off */
  202. if (data->vcc_pin)
  203. at91_set_gpio_output(data->vcc_pin, 0);
  204. at91_set_gpio_output(data->rst_pin, 0);
  205. /* force poweron defaults for these pins ... */
  206. at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
  207. at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
  208. at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
  209. at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
  210. cf_data = *data;
  211. platform_device_register(&at91rm9200_cf_device);
  212. }
  213. #else
  214. void __init at91_add_device_cf(struct at91_cf_data *data) {}
  215. #endif
  216. /* --------------------------------------------------------------------
  217. * MMC / SD
  218. * -------------------------------------------------------------------- */
  219. #if defined(CONFIG_MMC_AT91RM9200) || defined(CONFIG_MMC_AT91RM9200_MODULE)
  220. static u64 mmc_dmamask = 0xffffffffUL;
  221. static struct at91_mmc_data mmc_data;
  222. static struct resource at91_mmc_resources[] = {
  223. [0] = {
  224. .start = AT91_BASE_MCI,
  225. .end = AT91_BASE_MCI + SZ_16K - 1,
  226. .flags = IORESOURCE_MEM,
  227. },
  228. [1] = {
  229. .start = AT91_ID_MCI,
  230. .end = AT91_ID_MCI,
  231. .flags = IORESOURCE_IRQ,
  232. },
  233. };
  234. static struct platform_device at91rm9200_mmc_device = {
  235. .name = "at91_mci",
  236. .id = -1,
  237. .dev = {
  238. .dma_mask = &mmc_dmamask,
  239. .coherent_dma_mask = 0xffffffff,
  240. .platform_data = &mmc_data,
  241. },
  242. .resource = at91_mmc_resources,
  243. .num_resources = ARRAY_SIZE(at91_mmc_resources),
  244. };
  245. void __init at91_add_device_mmc(struct at91_mmc_data *data)
  246. {
  247. if (!data)
  248. return;
  249. /* input/irq */
  250. if (data->det_pin) {
  251. at91_set_gpio_input(data->det_pin, 1);
  252. at91_set_deglitch(data->det_pin, 1);
  253. }
  254. if (data->wp_pin)
  255. at91_set_gpio_input(data->wp_pin, 1);
  256. /* CLK */
  257. at91_set_A_periph(AT91_PIN_PA27, 0);
  258. if (data->is_b) {
  259. /* CMD */
  260. at91_set_B_periph(AT91_PIN_PA8, 0);
  261. /* DAT0, maybe DAT1..DAT3 */
  262. at91_set_B_periph(AT91_PIN_PA9, 0);
  263. if (data->wire4) {
  264. at91_set_B_periph(AT91_PIN_PA10, 0);
  265. at91_set_B_periph(AT91_PIN_PA11, 0);
  266. at91_set_B_periph(AT91_PIN_PA12, 0);
  267. }
  268. } else {
  269. /* CMD */
  270. at91_set_A_periph(AT91_PIN_PA28, 0);
  271. /* DAT0, maybe DAT1..DAT3 */
  272. at91_set_A_periph(AT91_PIN_PA29, 0);
  273. if (data->wire4) {
  274. at91_set_B_periph(AT91_PIN_PB3, 0);
  275. at91_set_B_periph(AT91_PIN_PB4, 0);
  276. at91_set_B_periph(AT91_PIN_PB5, 0);
  277. }
  278. }
  279. mmc_data = *data;
  280. platform_device_register(&at91rm9200_mmc_device);
  281. }
  282. #else
  283. void __init at91_add_device_mmc(struct at91_mmc_data *data) {}
  284. #endif
  285. /* --------------------------------------------------------------------
  286. * NAND / SmartMedia
  287. * -------------------------------------------------------------------- */
  288. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  289. static struct at91_nand_data nand_data;
  290. static struct resource at91_nand_resources[] = {
  291. {
  292. .start = AT91_SMARTMEDIA_BASE,
  293. .end = AT91_SMARTMEDIA_BASE + SZ_8M - 1,
  294. .flags = IORESOURCE_MEM,
  295. }
  296. };
  297. static struct platform_device at91_nand_device = {
  298. .name = "at91_nand",
  299. .id = -1,
  300. .dev = {
  301. .platform_data = &nand_data,
  302. },
  303. .resource = at91_nand_resources,
  304. .num_resources = ARRAY_SIZE(at91_nand_resources),
  305. };
  306. void __init at91_add_device_nand(struct at91_nand_data *data)
  307. {
  308. if (!data)
  309. return;
  310. /* enable pin */
  311. if (data->enable_pin)
  312. at91_set_gpio_output(data->enable_pin, 1);
  313. /* ready/busy pin */
  314. if (data->rdy_pin)
  315. at91_set_gpio_input(data->rdy_pin, 1);
  316. /* card detect pin */
  317. if (data->det_pin)
  318. at91_set_gpio_input(data->det_pin, 1);
  319. at91_set_A_periph(AT91_PIN_PC1, 0); /* SMOE */
  320. at91_set_A_periph(AT91_PIN_PC3, 0); /* SMWE */
  321. nand_data = *data;
  322. platform_device_register(&at91_nand_device);
  323. }
  324. #else
  325. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  326. #endif
  327. /* --------------------------------------------------------------------
  328. * TWI (i2c)
  329. * -------------------------------------------------------------------- */
  330. #if defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  331. static struct platform_device at91rm9200_twi_device = {
  332. .name = "at91_i2c",
  333. .id = -1,
  334. .num_resources = 0,
  335. };
  336. void __init at91_add_device_i2c(void)
  337. {
  338. /* pins used for TWI interface */
  339. at91_set_A_periph(AT91_PIN_PA25, 0); /* TWD */
  340. at91_set_multi_drive(AT91_PIN_PA25, 1);
  341. at91_set_A_periph(AT91_PIN_PA26, 0); /* TWCK */
  342. at91_set_multi_drive(AT91_PIN_PA26, 1);
  343. platform_device_register(&at91rm9200_twi_device);
  344. }
  345. #else
  346. void __init at91_add_device_i2c(void) {}
  347. #endif
  348. /* --------------------------------------------------------------------
  349. * SPI
  350. * -------------------------------------------------------------------- */
  351. #if defined(CONFIG_SPI_AT91) || defined(CONFIG_SPI_AT91_MODULE) || defined(CONFIG_AT91_SPI) || defined(CONFIG_AT91_SPI_MODULE)
  352. static u64 spi_dmamask = 0xffffffffUL;
  353. static struct resource at91_spi_resources[] = {
  354. [0] = {
  355. .start = AT91_BASE_SPI,
  356. .end = AT91_BASE_SPI + SZ_16K - 1,
  357. .flags = IORESOURCE_MEM,
  358. },
  359. [1] = {
  360. .start = AT91_ID_SPI,
  361. .end = AT91_ID_SPI,
  362. .flags = IORESOURCE_IRQ,
  363. },
  364. };
  365. static struct platform_device at91rm9200_spi_device = {
  366. .name = "at91_spi",
  367. .id = 0,
  368. .dev = {
  369. .dma_mask = &spi_dmamask,
  370. .coherent_dma_mask = 0xffffffff,
  371. },
  372. .resource = at91_spi_resources,
  373. .num_resources = ARRAY_SIZE(at91_spi_resources),
  374. };
  375. static const unsigned at91_spi_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
  376. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  377. {
  378. int i;
  379. unsigned long cs_pin;
  380. at91_set_A_periph(AT91_PIN_PA0, 0); /* MISO */
  381. at91_set_A_periph(AT91_PIN_PA1, 0); /* MOSI */
  382. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPCK */
  383. /* Enable SPI chip-selects */
  384. for (i = 0; i < nr_devices; i++) {
  385. if (devices[i].controller_data)
  386. cs_pin = (unsigned long) devices[i].controller_data;
  387. else
  388. cs_pin = at91_spi_standard_cs[devices[i].chip_select];
  389. #ifdef CONFIG_SPI_AT91_MANUAL_CS
  390. at91_set_gpio_output(cs_pin, 1);
  391. #else
  392. at91_set_A_periph(cs_pin, 0);
  393. #endif
  394. /* pass chip-select pin to driver */
  395. devices[i].controller_data = (void *) cs_pin;
  396. }
  397. spi_register_board_info(devices, nr_devices);
  398. at91_clock_associate("spi0_clk", &at91rm9200_spi_device.dev, "spi");
  399. platform_device_register(&at91rm9200_spi_device);
  400. }
  401. #else
  402. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  403. #endif
  404. /* --------------------------------------------------------------------
  405. * RTC
  406. * -------------------------------------------------------------------- */
  407. #if defined(CONFIG_RTC_DRV_AT91) || defined(CONFIG_RTC_DRV_AT91_MODULE)
  408. static struct platform_device at91rm9200_rtc_device = {
  409. .name = "at91_rtc",
  410. .id = -1,
  411. .num_resources = 0,
  412. };
  413. static void __init at91_add_device_rtc(void)
  414. {
  415. platform_device_register(&at91rm9200_rtc_device);
  416. }
  417. #else
  418. static void __init at91_add_device_rtc(void) {}
  419. #endif
  420. /* --------------------------------------------------------------------
  421. * Watchdog
  422. * -------------------------------------------------------------------- */
  423. #if defined(CONFIG_AT91_WATCHDOG) || defined(CONFIG_AT91_WATCHDOG_MODULE)
  424. static struct platform_device at91rm9200_wdt_device = {
  425. .name = "at91_wdt",
  426. .id = -1,
  427. .num_resources = 0,
  428. };
  429. static void __init at91_add_device_watchdog(void)
  430. {
  431. platform_device_register(&at91rm9200_wdt_device);
  432. }
  433. #else
  434. static void __init at91_add_device_watchdog(void) {}
  435. #endif
  436. /* --------------------------------------------------------------------
  437. * LEDs
  438. * -------------------------------------------------------------------- */
  439. #if defined(CONFIG_LEDS)
  440. u8 at91_leds_cpu;
  441. u8 at91_leds_timer;
  442. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  443. {
  444. at91_leds_cpu = cpu_led;
  445. at91_leds_timer = timer_led;
  446. }
  447. #else
  448. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  449. #endif
  450. /* --------------------------------------------------------------------
  451. * UART
  452. * -------------------------------------------------------------------- */
  453. #if defined(CONFIG_SERIAL_AT91)
  454. static struct resource dbgu_resources[] = {
  455. [0] = {
  456. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  457. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  458. .flags = IORESOURCE_MEM,
  459. },
  460. [1] = {
  461. .start = AT91_ID_SYS,
  462. .end = AT91_ID_SYS,
  463. .flags = IORESOURCE_IRQ,
  464. },
  465. };
  466. static struct at91_uart_data dbgu_data = {
  467. .use_dma_tx = 0,
  468. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  469. };
  470. static struct platform_device at91rm9200_dbgu_device = {
  471. .name = "at91_usart",
  472. .id = 0,
  473. .dev = {
  474. .platform_data = &dbgu_data,
  475. .coherent_dma_mask = 0xffffffff,
  476. },
  477. .resource = dbgu_resources,
  478. .num_resources = ARRAY_SIZE(dbgu_resources),
  479. };
  480. static inline void configure_dbgu_pins(void)
  481. {
  482. at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
  483. at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
  484. }
  485. static struct resource uart0_resources[] = {
  486. [0] = {
  487. .start = AT91_BASE_US0,
  488. .end = AT91_BASE_US0 + SZ_16K - 1,
  489. .flags = IORESOURCE_MEM,
  490. },
  491. [1] = {
  492. .start = AT91_ID_US0,
  493. .end = AT91_ID_US0,
  494. .flags = IORESOURCE_IRQ,
  495. },
  496. };
  497. static struct at91_uart_data uart0_data = {
  498. .use_dma_tx = 1,
  499. .use_dma_rx = 1,
  500. };
  501. static struct platform_device at91rm9200_uart0_device = {
  502. .name = "at91_usart",
  503. .id = 1,
  504. .dev = {
  505. .platform_data = &uart0_data,
  506. .coherent_dma_mask = 0xffffffff,
  507. },
  508. .resource = uart0_resources,
  509. .num_resources = ARRAY_SIZE(uart0_resources),
  510. };
  511. static inline void configure_usart0_pins(void)
  512. {
  513. at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
  514. at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
  515. at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
  516. /*
  517. * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
  518. * We need to drive the pin manually. Default is off (RTS is active low).
  519. */
  520. at91_set_gpio_output(AT91_PIN_PA21, 1);
  521. }
  522. static struct resource uart1_resources[] = {
  523. [0] = {
  524. .start = AT91_BASE_US1,
  525. .end = AT91_BASE_US1 + SZ_16K - 1,
  526. .flags = IORESOURCE_MEM,
  527. },
  528. [1] = {
  529. .start = AT91_ID_US1,
  530. .end = AT91_ID_US1,
  531. .flags = IORESOURCE_IRQ,
  532. },
  533. };
  534. static struct at91_uart_data uart1_data = {
  535. .use_dma_tx = 1,
  536. .use_dma_rx = 1,
  537. };
  538. static struct platform_device at91rm9200_uart1_device = {
  539. .name = "at91_usart",
  540. .id = 2,
  541. .dev = {
  542. .platform_data = &uart1_data,
  543. .coherent_dma_mask = 0xffffffff,
  544. },
  545. .resource = uart1_resources,
  546. .num_resources = ARRAY_SIZE(uart1_resources),
  547. };
  548. static inline void configure_usart1_pins(void)
  549. {
  550. at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
  551. at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
  552. at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
  553. at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
  554. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
  555. at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
  556. at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
  557. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
  558. }
  559. static struct resource uart2_resources[] = {
  560. [0] = {
  561. .start = AT91_BASE_US2,
  562. .end = AT91_BASE_US2 + SZ_16K - 1,
  563. .flags = IORESOURCE_MEM,
  564. },
  565. [1] = {
  566. .start = AT91_ID_US2,
  567. .end = AT91_ID_US2,
  568. .flags = IORESOURCE_IRQ,
  569. },
  570. };
  571. static struct at91_uart_data uart2_data = {
  572. .use_dma_tx = 1,
  573. .use_dma_rx = 1,
  574. };
  575. static struct platform_device at91rm9200_uart2_device = {
  576. .name = "at91_usart",
  577. .id = 3,
  578. .dev = {
  579. .platform_data = &uart2_data,
  580. .coherent_dma_mask = 0xffffffff,
  581. },
  582. .resource = uart2_resources,
  583. .num_resources = ARRAY_SIZE(uart2_resources),
  584. };
  585. static inline void configure_usart2_pins(void)
  586. {
  587. at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
  588. at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
  589. }
  590. static struct resource uart3_resources[] = {
  591. [0] = {
  592. .start = AT91_BASE_US3,
  593. .end = AT91_BASE_US3 + SZ_16K - 1,
  594. .flags = IORESOURCE_MEM,
  595. },
  596. [1] = {
  597. .start = AT91_ID_US3,
  598. .end = AT91_ID_US3,
  599. .flags = IORESOURCE_IRQ,
  600. },
  601. };
  602. static struct at91_uart_data uart3_data = {
  603. .use_dma_tx = 1,
  604. .use_dma_rx = 1,
  605. };
  606. static struct platform_device at91rm9200_uart3_device = {
  607. .name = "at91_usart",
  608. .id = 4,
  609. .dev = {
  610. .platform_data = &uart3_data,
  611. .coherent_dma_mask = 0xffffffff,
  612. },
  613. .resource = uart3_resources,
  614. .num_resources = ARRAY_SIZE(uart3_resources),
  615. };
  616. static inline void configure_usart3_pins(void)
  617. {
  618. at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
  619. at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
  620. }
  621. struct platform_device *at91_uarts[AT91_NR_UART]; /* the UARTs to use */
  622. struct platform_device *at91_default_console_device; /* the serial console device */
  623. void __init at91_init_serial(struct at91_uart_config *config)
  624. {
  625. int i;
  626. /* Fill in list of supported UARTs */
  627. for (i = 0; i < config->nr_tty; i++) {
  628. switch (config->tty_map[i]) {
  629. case 0:
  630. configure_usart0_pins();
  631. at91_uarts[i] = &at91rm9200_uart0_device;
  632. at91_clock_associate("usart0_clk", &at91rm9200_uart0_device.dev, "usart");
  633. break;
  634. case 1:
  635. configure_usart1_pins();
  636. at91_uarts[i] = &at91rm9200_uart1_device;
  637. at91_clock_associate("usart1_clk", &at91rm9200_uart1_device.dev, "usart");
  638. break;
  639. case 2:
  640. configure_usart2_pins();
  641. at91_uarts[i] = &at91rm9200_uart2_device;
  642. at91_clock_associate("usart2_clk", &at91rm9200_uart2_device.dev, "usart");
  643. break;
  644. case 3:
  645. configure_usart3_pins();
  646. at91_uarts[i] = &at91rm9200_uart3_device;
  647. at91_clock_associate("usart3_clk", &at91rm9200_uart3_device.dev, "usart");
  648. break;
  649. case 4:
  650. configure_dbgu_pins();
  651. at91_uarts[i] = &at91rm9200_dbgu_device;
  652. at91_clock_associate("mck", &at91rm9200_dbgu_device.dev, "usart");
  653. break;
  654. default:
  655. continue;
  656. }
  657. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  658. }
  659. /* Set serial console device */
  660. if (config->console_tty < AT91_NR_UART)
  661. at91_default_console_device = at91_uarts[config->console_tty];
  662. if (!at91_default_console_device)
  663. printk(KERN_INFO "AT91: No default serial console defined.\n");
  664. }
  665. void __init at91_add_device_serial(void)
  666. {
  667. int i;
  668. for (i = 0; i < AT91_NR_UART; i++) {
  669. if (at91_uarts[i])
  670. platform_device_register(at91_uarts[i]);
  671. }
  672. }
  673. #else
  674. void __init at91_init_serial(struct at91_uart_config *config) {}
  675. void __init at91_add_device_serial(void) {}
  676. #endif
  677. /* -------------------------------------------------------------------- */
  678. /*
  679. * These devices are always present and don't need any board-specific
  680. * setup.
  681. */
  682. static int __init at91_add_standard_devices(void)
  683. {
  684. at91_add_device_rtc();
  685. at91_add_device_watchdog();
  686. return 0;
  687. }
  688. arch_initcall(at91_add_standard_devices);