at91rm9200_devices.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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_AT91) || defined(CONFIG_SPI_AT91_MODULE) || defined(CONFIG_AT91_SPI) || defined(CONFIG_AT91_SPI_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 = "at91_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. #ifdef CONFIG_SPI_AT91_MANUAL_CS
  437. at91_set_gpio_output(cs_pin, 1);
  438. #else
  439. at91_set_A_periph(cs_pin, 0);
  440. #endif
  441. /* pass chip-select pin to driver */
  442. devices[i].controller_data = (void *) cs_pin;
  443. }
  444. spi_register_board_info(devices, nr_devices);
  445. at91_clock_associate("spi_clk", &at91rm9200_spi_device.dev, "spi");
  446. platform_device_register(&at91rm9200_spi_device);
  447. }
  448. #else
  449. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  450. #endif
  451. /* --------------------------------------------------------------------
  452. * RTC
  453. * -------------------------------------------------------------------- */
  454. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  455. static struct platform_device at91rm9200_rtc_device = {
  456. .name = "at91_rtc",
  457. .id = -1,
  458. .num_resources = 0,
  459. };
  460. static void __init at91_add_device_rtc(void)
  461. {
  462. platform_device_register(&at91rm9200_rtc_device);
  463. }
  464. #else
  465. static void __init at91_add_device_rtc(void) {}
  466. #endif
  467. /* --------------------------------------------------------------------
  468. * Watchdog
  469. * -------------------------------------------------------------------- */
  470. #if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
  471. static struct platform_device at91rm9200_wdt_device = {
  472. .name = "at91_wdt",
  473. .id = -1,
  474. .num_resources = 0,
  475. };
  476. static void __init at91_add_device_watchdog(void)
  477. {
  478. platform_device_register(&at91rm9200_wdt_device);
  479. }
  480. #else
  481. static void __init at91_add_device_watchdog(void) {}
  482. #endif
  483. /* --------------------------------------------------------------------
  484. * LEDs
  485. * -------------------------------------------------------------------- */
  486. #if defined(CONFIG_LEDS)
  487. u8 at91_leds_cpu;
  488. u8 at91_leds_timer;
  489. void __init at91_init_leds(u8 cpu_led, u8 timer_led)
  490. {
  491. /* Enable GPIO to access the LEDs */
  492. at91_set_gpio_output(cpu_led, 1);
  493. at91_set_gpio_output(timer_led, 1);
  494. at91_leds_cpu = cpu_led;
  495. at91_leds_timer = timer_led;
  496. }
  497. #else
  498. void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
  499. #endif
  500. /* --------------------------------------------------------------------
  501. * UART
  502. * -------------------------------------------------------------------- */
  503. #if defined(CONFIG_SERIAL_ATMEL)
  504. static struct resource dbgu_resources[] = {
  505. [0] = {
  506. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  507. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  508. .flags = IORESOURCE_MEM,
  509. },
  510. [1] = {
  511. .start = AT91_ID_SYS,
  512. .end = AT91_ID_SYS,
  513. .flags = IORESOURCE_IRQ,
  514. },
  515. };
  516. static struct atmel_uart_data dbgu_data = {
  517. .use_dma_tx = 0,
  518. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  519. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  520. };
  521. static struct platform_device at91rm9200_dbgu_device = {
  522. .name = "atmel_usart",
  523. .id = 0,
  524. .dev = {
  525. .platform_data = &dbgu_data,
  526. .coherent_dma_mask = 0xffffffff,
  527. },
  528. .resource = dbgu_resources,
  529. .num_resources = ARRAY_SIZE(dbgu_resources),
  530. };
  531. static inline void configure_dbgu_pins(void)
  532. {
  533. at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
  534. at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
  535. }
  536. static struct resource uart0_resources[] = {
  537. [0] = {
  538. .start = AT91RM9200_BASE_US0,
  539. .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
  540. .flags = IORESOURCE_MEM,
  541. },
  542. [1] = {
  543. .start = AT91RM9200_ID_US0,
  544. .end = AT91RM9200_ID_US0,
  545. .flags = IORESOURCE_IRQ,
  546. },
  547. };
  548. static struct atmel_uart_data uart0_data = {
  549. .use_dma_tx = 1,
  550. .use_dma_rx = 1,
  551. };
  552. static struct platform_device at91rm9200_uart0_device = {
  553. .name = "atmel_usart",
  554. .id = 1,
  555. .dev = {
  556. .platform_data = &uart0_data,
  557. .coherent_dma_mask = 0xffffffff,
  558. },
  559. .resource = uart0_resources,
  560. .num_resources = ARRAY_SIZE(uart0_resources),
  561. };
  562. static inline void configure_usart0_pins(void)
  563. {
  564. at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
  565. at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
  566. at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
  567. /*
  568. * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
  569. * We need to drive the pin manually. Default is off (RTS is active low).
  570. */
  571. at91_set_gpio_output(AT91_PIN_PA21, 1);
  572. }
  573. static struct resource uart1_resources[] = {
  574. [0] = {
  575. .start = AT91RM9200_BASE_US1,
  576. .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
  577. .flags = IORESOURCE_MEM,
  578. },
  579. [1] = {
  580. .start = AT91RM9200_ID_US1,
  581. .end = AT91RM9200_ID_US1,
  582. .flags = IORESOURCE_IRQ,
  583. },
  584. };
  585. static struct atmel_uart_data uart1_data = {
  586. .use_dma_tx = 1,
  587. .use_dma_rx = 1,
  588. };
  589. static struct platform_device at91rm9200_uart1_device = {
  590. .name = "atmel_usart",
  591. .id = 2,
  592. .dev = {
  593. .platform_data = &uart1_data,
  594. .coherent_dma_mask = 0xffffffff,
  595. },
  596. .resource = uart1_resources,
  597. .num_resources = ARRAY_SIZE(uart1_resources),
  598. };
  599. static inline void configure_usart1_pins(void)
  600. {
  601. at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
  602. at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
  603. at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
  604. at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
  605. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
  606. at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
  607. at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
  608. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
  609. }
  610. static struct resource uart2_resources[] = {
  611. [0] = {
  612. .start = AT91RM9200_BASE_US2,
  613. .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
  614. .flags = IORESOURCE_MEM,
  615. },
  616. [1] = {
  617. .start = AT91RM9200_ID_US2,
  618. .end = AT91RM9200_ID_US2,
  619. .flags = IORESOURCE_IRQ,
  620. },
  621. };
  622. static struct atmel_uart_data uart2_data = {
  623. .use_dma_tx = 1,
  624. .use_dma_rx = 1,
  625. };
  626. static struct platform_device at91rm9200_uart2_device = {
  627. .name = "atmel_usart",
  628. .id = 3,
  629. .dev = {
  630. .platform_data = &uart2_data,
  631. .coherent_dma_mask = 0xffffffff,
  632. },
  633. .resource = uart2_resources,
  634. .num_resources = ARRAY_SIZE(uart2_resources),
  635. };
  636. static inline void configure_usart2_pins(void)
  637. {
  638. at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
  639. at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
  640. }
  641. static struct resource uart3_resources[] = {
  642. [0] = {
  643. .start = AT91RM9200_BASE_US3,
  644. .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
  645. .flags = IORESOURCE_MEM,
  646. },
  647. [1] = {
  648. .start = AT91RM9200_ID_US3,
  649. .end = AT91RM9200_ID_US3,
  650. .flags = IORESOURCE_IRQ,
  651. },
  652. };
  653. static struct atmel_uart_data uart3_data = {
  654. .use_dma_tx = 1,
  655. .use_dma_rx = 1,
  656. };
  657. static struct platform_device at91rm9200_uart3_device = {
  658. .name = "atmel_usart",
  659. .id = 4,
  660. .dev = {
  661. .platform_data = &uart3_data,
  662. .coherent_dma_mask = 0xffffffff,
  663. },
  664. .resource = uart3_resources,
  665. .num_resources = ARRAY_SIZE(uart3_resources),
  666. };
  667. static inline void configure_usart3_pins(void)
  668. {
  669. at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
  670. at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
  671. }
  672. struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  673. struct platform_device *atmel_default_console_device; /* the serial console device */
  674. void __init at91_init_serial(struct at91_uart_config *config)
  675. {
  676. int i;
  677. /* Fill in list of supported UARTs */
  678. for (i = 0; i < config->nr_tty; i++) {
  679. switch (config->tty_map[i]) {
  680. case 0:
  681. configure_usart0_pins();
  682. at91_uarts[i] = &at91rm9200_uart0_device;
  683. at91_clock_associate("usart0_clk", &at91rm9200_uart0_device.dev, "usart");
  684. break;
  685. case 1:
  686. configure_usart1_pins();
  687. at91_uarts[i] = &at91rm9200_uart1_device;
  688. at91_clock_associate("usart1_clk", &at91rm9200_uart1_device.dev, "usart");
  689. break;
  690. case 2:
  691. configure_usart2_pins();
  692. at91_uarts[i] = &at91rm9200_uart2_device;
  693. at91_clock_associate("usart2_clk", &at91rm9200_uart2_device.dev, "usart");
  694. break;
  695. case 3:
  696. configure_usart3_pins();
  697. at91_uarts[i] = &at91rm9200_uart3_device;
  698. at91_clock_associate("usart3_clk", &at91rm9200_uart3_device.dev, "usart");
  699. break;
  700. case 4:
  701. configure_dbgu_pins();
  702. at91_uarts[i] = &at91rm9200_dbgu_device;
  703. at91_clock_associate("mck", &at91rm9200_dbgu_device.dev, "usart");
  704. break;
  705. default:
  706. continue;
  707. }
  708. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  709. }
  710. /* Set serial console device */
  711. if (config->console_tty < ATMEL_MAX_UART)
  712. atmel_default_console_device = at91_uarts[config->console_tty];
  713. if (!atmel_default_console_device)
  714. printk(KERN_INFO "AT91: No default serial console defined.\n");
  715. }
  716. void __init at91_add_device_serial(void)
  717. {
  718. int i;
  719. for (i = 0; i < ATMEL_MAX_UART; i++) {
  720. if (at91_uarts[i])
  721. platform_device_register(at91_uarts[i]);
  722. }
  723. }
  724. #else
  725. void __init at91_init_serial(struct at91_uart_config *config) {}
  726. void __init at91_add_device_serial(void) {}
  727. #endif
  728. /* -------------------------------------------------------------------- */
  729. /*
  730. * These devices are always present and don't need any board-specific
  731. * setup.
  732. */
  733. static int __init at91_add_standard_devices(void)
  734. {
  735. at91_add_device_rtc();
  736. at91_add_device_watchdog();
  737. return 0;
  738. }
  739. arch_initcall(at91_add_standard_devices);