at91rm9200_devices.c 23 KB

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