at91rm9200_devices.c 22 KB

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