at91rm9200_devices.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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/dma-mapping.h>
  16. #include <linux/gpio.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/i2c-gpio.h>
  19. #include <mach/board.h>
  20. #include <mach/at91rm9200.h>
  21. #include <mach/at91rm9200_mc.h>
  22. #include "generic.h"
  23. /* --------------------------------------------------------------------
  24. * USB Host
  25. * -------------------------------------------------------------------- */
  26. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  27. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  28. static struct at91_usbh_data usbh_data;
  29. static struct resource usbh_resources[] = {
  30. [0] = {
  31. .start = AT91RM9200_UHP_BASE,
  32. .end = AT91RM9200_UHP_BASE + SZ_1M - 1,
  33. .flags = IORESOURCE_MEM,
  34. },
  35. [1] = {
  36. .start = AT91RM9200_ID_UHP,
  37. .end = AT91RM9200_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 = DMA_BIT_MASK(32),
  47. .platform_data = &usbh_data,
  48. },
  49. .resource = usbh_resources,
  50. .num_resources = ARRAY_SIZE(usbh_resources),
  51. };
  52. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  53. {
  54. int i;
  55. if (!data)
  56. return;
  57. /* Enable overcurrent notification */
  58. for (i = 0; i < data->ports; i++) {
  59. if (data->overcurrent_pin[i])
  60. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  61. }
  62. usbh_data = *data;
  63. platform_device_register(&at91rm9200_usbh_device);
  64. }
  65. #else
  66. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  67. #endif
  68. /* --------------------------------------------------------------------
  69. * USB Device (Gadget)
  70. * -------------------------------------------------------------------- */
  71. #ifdef CONFIG_USB_AT91
  72. static struct at91_udc_data udc_data;
  73. static struct resource udc_resources[] = {
  74. [0] = {
  75. .start = AT91RM9200_BASE_UDP,
  76. .end = AT91RM9200_BASE_UDP + SZ_16K - 1,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. [1] = {
  80. .start = AT91RM9200_ID_UDP,
  81. .end = AT91RM9200_ID_UDP,
  82. .flags = IORESOURCE_IRQ,
  83. },
  84. };
  85. static struct platform_device at91rm9200_udc_device = {
  86. .name = "at91_udc",
  87. .id = -1,
  88. .dev = {
  89. .platform_data = &udc_data,
  90. },
  91. .resource = udc_resources,
  92. .num_resources = ARRAY_SIZE(udc_resources),
  93. };
  94. void __init at91_add_device_udc(struct at91_udc_data *data)
  95. {
  96. if (!data)
  97. return;
  98. if (data->vbus_pin) {
  99. at91_set_gpio_input(data->vbus_pin, 0);
  100. at91_set_deglitch(data->vbus_pin, 1);
  101. }
  102. if (data->pullup_pin)
  103. at91_set_gpio_output(data->pullup_pin, 0);
  104. udc_data = *data;
  105. platform_device_register(&at91rm9200_udc_device);
  106. }
  107. #else
  108. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  109. #endif
  110. /* --------------------------------------------------------------------
  111. * Ethernet
  112. * -------------------------------------------------------------------- */
  113. #if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
  114. static u64 eth_dmamask = DMA_BIT_MASK(32);
  115. static struct at91_eth_data eth_data;
  116. static struct resource eth_resources[] = {
  117. [0] = {
  118. .start = AT91_VA_BASE_EMAC,
  119. .end = AT91_VA_BASE_EMAC + SZ_16K - 1,
  120. .flags = IORESOURCE_MEM,
  121. },
  122. [1] = {
  123. .start = AT91RM9200_ID_EMAC,
  124. .end = AT91RM9200_ID_EMAC,
  125. .flags = IORESOURCE_IRQ,
  126. },
  127. };
  128. static struct platform_device at91rm9200_eth_device = {
  129. .name = "at91_ether",
  130. .id = -1,
  131. .dev = {
  132. .dma_mask = &eth_dmamask,
  133. .coherent_dma_mask = DMA_BIT_MASK(32),
  134. .platform_data = &eth_data,
  135. },
  136. .resource = eth_resources,
  137. .num_resources = ARRAY_SIZE(eth_resources),
  138. };
  139. void __init at91_add_device_eth(struct at91_eth_data *data)
  140. {
  141. if (!data)
  142. return;
  143. if (data->phy_irq_pin) {
  144. at91_set_gpio_input(data->phy_irq_pin, 0);
  145. at91_set_deglitch(data->phy_irq_pin, 1);
  146. }
  147. /* Pins used for MII and RMII */
  148. at91_set_A_periph(AT91_PIN_PA16, 0); /* EMDIO */
  149. at91_set_A_periph(AT91_PIN_PA15, 0); /* EMDC */
  150. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERXER */
  151. at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
  152. at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
  153. at91_set_A_periph(AT91_PIN_PA11, 0); /* ECRS_ECRSDV */
  154. at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX1 */
  155. at91_set_A_periph(AT91_PIN_PA9, 0); /* ETX0 */
  156. at91_set_A_periph(AT91_PIN_PA8, 0); /* ETXEN */
  157. at91_set_A_periph(AT91_PIN_PA7, 0); /* ETXCK_EREFCK */
  158. if (!data->is_rmii) {
  159. at91_set_B_periph(AT91_PIN_PB19, 0); /* ERXCK */
  160. at91_set_B_periph(AT91_PIN_PB18, 0); /* ECOL */
  161. at91_set_B_periph(AT91_PIN_PB17, 0); /* ERXDV */
  162. at91_set_B_periph(AT91_PIN_PB16, 0); /* ERX3 */
  163. at91_set_B_periph(AT91_PIN_PB15, 0); /* ERX2 */
  164. at91_set_B_periph(AT91_PIN_PB14, 0); /* ETXER */
  165. at91_set_B_periph(AT91_PIN_PB13, 0); /* ETX3 */
  166. at91_set_B_periph(AT91_PIN_PB12, 0); /* ETX2 */
  167. }
  168. eth_data = *data;
  169. platform_device_register(&at91rm9200_eth_device);
  170. }
  171. #else
  172. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  173. #endif
  174. /* --------------------------------------------------------------------
  175. * Compact Flash / PCMCIA
  176. * -------------------------------------------------------------------- */
  177. #if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  178. static struct at91_cf_data cf_data;
  179. #define CF_BASE AT91_CHIPSELECT_4
  180. static struct resource cf_resources[] = {
  181. [0] = {
  182. .start = CF_BASE,
  183. /* ties up CS4, CS5 and CS6 */
  184. .end = CF_BASE + (0x30000000 - 1),
  185. .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
  186. },
  187. };
  188. static struct platform_device at91rm9200_cf_device = {
  189. .name = "at91_cf",
  190. .id = -1,
  191. .dev = {
  192. .platform_data = &cf_data,
  193. },
  194. .resource = cf_resources,
  195. .num_resources = ARRAY_SIZE(cf_resources),
  196. };
  197. void __init at91_add_device_cf(struct at91_cf_data *data)
  198. {
  199. unsigned int csa;
  200. if (!data)
  201. return;
  202. data->chipselect = 4; /* can only use EBI ChipSelect 4 */
  203. /* CF takes over CS4, CS5, CS6 */
  204. csa = at91_sys_read(AT91_EBI_CSA);
  205. at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
  206. /*
  207. * Static memory controller timing adjustments.
  208. * REVISIT: these timings are in terms of MCK cycles, so
  209. * when MCK changes (cpufreq etc) so must these values...
  210. */
  211. at91_sys_write(AT91_SMC_CSR(4),
  212. AT91_SMC_ACSS_STD
  213. | AT91_SMC_DBW_16
  214. | AT91_SMC_BAT
  215. | AT91_SMC_WSEN
  216. | AT91_SMC_NWS_(32) /* wait states */
  217. | AT91_SMC_RWSETUP_(6) /* setup time */
  218. | AT91_SMC_RWHOLD_(4) /* hold time */
  219. );
  220. /* input/irq */
  221. if (data->irq_pin) {
  222. at91_set_gpio_input(data->irq_pin, 1);
  223. at91_set_deglitch(data->irq_pin, 1);
  224. }
  225. at91_set_gpio_input(data->det_pin, 1);
  226. at91_set_deglitch(data->det_pin, 1);
  227. /* outputs, initially off */
  228. if (data->vcc_pin)
  229. at91_set_gpio_output(data->vcc_pin, 0);
  230. at91_set_gpio_output(data->rst_pin, 0);
  231. /* force poweron defaults for these pins ... */
  232. at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
  233. at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
  234. at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
  235. at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
  236. /* nWAIT is _not_ a default setting */
  237. at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
  238. cf_data = *data;
  239. platform_device_register(&at91rm9200_cf_device);
  240. }
  241. #else
  242. void __init at91_add_device_cf(struct at91_cf_data *data) {}
  243. #endif
  244. /* --------------------------------------------------------------------
  245. * MMC / SD
  246. * -------------------------------------------------------------------- */
  247. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  248. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  249. static struct at91_mmc_data mmc_data;
  250. static struct resource mmc_resources[] = {
  251. [0] = {
  252. .start = AT91RM9200_BASE_MCI,
  253. .end = AT91RM9200_BASE_MCI + SZ_16K - 1,
  254. .flags = IORESOURCE_MEM,
  255. },
  256. [1] = {
  257. .start = AT91RM9200_ID_MCI,
  258. .end = AT91RM9200_ID_MCI,
  259. .flags = IORESOURCE_IRQ,
  260. },
  261. };
  262. static struct platform_device at91rm9200_mmc_device = {
  263. .name = "at91_mci",
  264. .id = -1,
  265. .dev = {
  266. .dma_mask = &mmc_dmamask,
  267. .coherent_dma_mask = DMA_BIT_MASK(32),
  268. .platform_data = &mmc_data,
  269. },
  270. .resource = mmc_resources,
  271. .num_resources = ARRAY_SIZE(mmc_resources),
  272. };
  273. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  274. {
  275. if (!data)
  276. return;
  277. /* input/irq */
  278. if (data->det_pin) {
  279. at91_set_gpio_input(data->det_pin, 1);
  280. at91_set_deglitch(data->det_pin, 1);
  281. }
  282. if (data->wp_pin)
  283. at91_set_gpio_input(data->wp_pin, 1);
  284. if (data->vcc_pin)
  285. at91_set_gpio_output(data->vcc_pin, 0);
  286. /* CLK */
  287. at91_set_A_periph(AT91_PIN_PA27, 0);
  288. if (data->slot_b) {
  289. /* CMD */
  290. at91_set_B_periph(AT91_PIN_PA8, 1);
  291. /* DAT0, maybe DAT1..DAT3 */
  292. at91_set_B_periph(AT91_PIN_PA9, 1);
  293. if (data->wire4) {
  294. at91_set_B_periph(AT91_PIN_PA10, 1);
  295. at91_set_B_periph(AT91_PIN_PA11, 1);
  296. at91_set_B_periph(AT91_PIN_PA12, 1);
  297. }
  298. } else {
  299. /* CMD */
  300. at91_set_A_periph(AT91_PIN_PA28, 1);
  301. /* DAT0, maybe DAT1..DAT3 */
  302. at91_set_A_periph(AT91_PIN_PA29, 1);
  303. if (data->wire4) {
  304. at91_set_B_periph(AT91_PIN_PB3, 1);
  305. at91_set_B_periph(AT91_PIN_PB4, 1);
  306. at91_set_B_periph(AT91_PIN_PB5, 1);
  307. }
  308. }
  309. mmc_data = *data;
  310. platform_device_register(&at91rm9200_mmc_device);
  311. }
  312. #else
  313. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  314. #endif
  315. /* --------------------------------------------------------------------
  316. * NAND / SmartMedia
  317. * -------------------------------------------------------------------- */
  318. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  319. static struct atmel_nand_data nand_data;
  320. #define NAND_BASE AT91_CHIPSELECT_3
  321. static struct resource nand_resources[] = {
  322. {
  323. .start = NAND_BASE,
  324. .end = NAND_BASE + SZ_256M - 1,
  325. .flags = IORESOURCE_MEM,
  326. }
  327. };
  328. static struct platform_device at91rm9200_nand_device = {
  329. .name = "atmel_nand",
  330. .id = -1,
  331. .dev = {
  332. .platform_data = &nand_data,
  333. },
  334. .resource = nand_resources,
  335. .num_resources = ARRAY_SIZE(nand_resources),
  336. };
  337. void __init at91_add_device_nand(struct atmel_nand_data *data)
  338. {
  339. unsigned int csa;
  340. if (!data)
  341. return;
  342. /* enable the address range of CS3 */
  343. csa = at91_sys_read(AT91_EBI_CSA);
  344. at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS3A_SMC_SMARTMEDIA);
  345. /* set the bus interface characteristics */
  346. at91_sys_write(AT91_SMC_CSR(3), AT91_SMC_ACSS_STD | AT91_SMC_DBW_8 | AT91_SMC_WSEN
  347. | AT91_SMC_NWS_(5)
  348. | AT91_SMC_TDF_(1)
  349. | AT91_SMC_RWSETUP_(0) /* tDS Data Set up Time 30 - ns */
  350. | AT91_SMC_RWHOLD_(1) /* tDH Data Hold Time 20 - ns */
  351. );
  352. /* enable pin */
  353. if (data->enable_pin)
  354. at91_set_gpio_output(data->enable_pin, 1);
  355. /* ready/busy pin */
  356. if (data->rdy_pin)
  357. at91_set_gpio_input(data->rdy_pin, 1);
  358. /* card detect pin */
  359. if (data->det_pin)
  360. at91_set_gpio_input(data->det_pin, 1);
  361. at91_set_A_periph(AT91_PIN_PC1, 0); /* SMOE */
  362. at91_set_A_periph(AT91_PIN_PC3, 0); /* SMWE */
  363. nand_data = *data;
  364. platform_device_register(&at91rm9200_nand_device);
  365. }
  366. #else
  367. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  368. #endif
  369. /* --------------------------------------------------------------------
  370. * TWI (i2c)
  371. * -------------------------------------------------------------------- */
  372. /*
  373. * Prefer the GPIO code since the TWI controller isn't robust
  374. * (gets overruns and underruns under load) and can only issue
  375. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  376. */
  377. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  378. static struct i2c_gpio_platform_data pdata = {
  379. .sda_pin = AT91_PIN_PA25,
  380. .sda_is_open_drain = 1,
  381. .scl_pin = AT91_PIN_PA26,
  382. .scl_is_open_drain = 1,
  383. .udelay = 2, /* ~100 kHz */
  384. };
  385. static struct platform_device at91rm9200_twi_device = {
  386. .name = "i2c-gpio",
  387. .id = -1,
  388. .dev.platform_data = &pdata,
  389. };
  390. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  391. {
  392. at91_set_GPIO_periph(AT91_PIN_PA25, 1); /* TWD (SDA) */
  393. at91_set_multi_drive(AT91_PIN_PA25, 1);
  394. at91_set_GPIO_periph(AT91_PIN_PA26, 1); /* TWCK (SCL) */
  395. at91_set_multi_drive(AT91_PIN_PA26, 1);
  396. i2c_register_board_info(0, devices, nr_devices);
  397. platform_device_register(&at91rm9200_twi_device);
  398. }
  399. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  400. static struct resource twi_resources[] = {
  401. [0] = {
  402. .start = AT91RM9200_BASE_TWI,
  403. .end = AT91RM9200_BASE_TWI + SZ_16K - 1,
  404. .flags = IORESOURCE_MEM,
  405. },
  406. [1] = {
  407. .start = AT91RM9200_ID_TWI,
  408. .end = AT91RM9200_ID_TWI,
  409. .flags = IORESOURCE_IRQ,
  410. },
  411. };
  412. static struct platform_device at91rm9200_twi_device = {
  413. .name = "at91_i2c",
  414. .id = -1,
  415. .resource = twi_resources,
  416. .num_resources = ARRAY_SIZE(twi_resources),
  417. };
  418. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  419. {
  420. /* pins used for TWI interface */
  421. at91_set_A_periph(AT91_PIN_PA25, 0); /* TWD */
  422. at91_set_multi_drive(AT91_PIN_PA25, 1);
  423. at91_set_A_periph(AT91_PIN_PA26, 0); /* TWCK */
  424. at91_set_multi_drive(AT91_PIN_PA26, 1);
  425. i2c_register_board_info(0, devices, nr_devices);
  426. platform_device_register(&at91rm9200_twi_device);
  427. }
  428. #else
  429. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  430. #endif
  431. /* --------------------------------------------------------------------
  432. * SPI
  433. * -------------------------------------------------------------------- */
  434. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  435. static u64 spi_dmamask = DMA_BIT_MASK(32);
  436. static struct resource spi_resources[] = {
  437. [0] = {
  438. .start = AT91RM9200_BASE_SPI,
  439. .end = AT91RM9200_BASE_SPI + SZ_16K - 1,
  440. .flags = IORESOURCE_MEM,
  441. },
  442. [1] = {
  443. .start = AT91RM9200_ID_SPI,
  444. .end = AT91RM9200_ID_SPI,
  445. .flags = IORESOURCE_IRQ,
  446. },
  447. };
  448. static struct platform_device at91rm9200_spi_device = {
  449. .name = "atmel_spi",
  450. .id = 0,
  451. .dev = {
  452. .dma_mask = &spi_dmamask,
  453. .coherent_dma_mask = DMA_BIT_MASK(32),
  454. },
  455. .resource = spi_resources,
  456. .num_resources = ARRAY_SIZE(spi_resources),
  457. };
  458. static const unsigned spi_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
  459. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  460. {
  461. int i;
  462. unsigned long cs_pin;
  463. at91_set_A_periph(AT91_PIN_PA0, 0); /* MISO */
  464. at91_set_A_periph(AT91_PIN_PA1, 0); /* MOSI */
  465. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPCK */
  466. /* Enable SPI chip-selects */
  467. for (i = 0; i < nr_devices; i++) {
  468. if (devices[i].controller_data)
  469. cs_pin = (unsigned long) devices[i].controller_data;
  470. else
  471. cs_pin = spi_standard_cs[devices[i].chip_select];
  472. if (devices[i].chip_select == 0) /* for CS0 errata */
  473. at91_set_A_periph(cs_pin, 0);
  474. else
  475. at91_set_gpio_output(cs_pin, 1);
  476. /* pass chip-select pin to driver */
  477. devices[i].controller_data = (void *) cs_pin;
  478. }
  479. spi_register_board_info(devices, nr_devices);
  480. platform_device_register(&at91rm9200_spi_device);
  481. }
  482. #else
  483. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  484. #endif
  485. /* --------------------------------------------------------------------
  486. * Timer/Counter blocks
  487. * -------------------------------------------------------------------- */
  488. #ifdef CONFIG_ATMEL_TCLIB
  489. static struct resource tcb0_resources[] = {
  490. [0] = {
  491. .start = AT91RM9200_BASE_TCB0,
  492. .end = AT91RM9200_BASE_TCB0 + SZ_16K - 1,
  493. .flags = IORESOURCE_MEM,
  494. },
  495. [1] = {
  496. .start = AT91RM9200_ID_TC0,
  497. .end = AT91RM9200_ID_TC0,
  498. .flags = IORESOURCE_IRQ,
  499. },
  500. [2] = {
  501. .start = AT91RM9200_ID_TC1,
  502. .end = AT91RM9200_ID_TC1,
  503. .flags = IORESOURCE_IRQ,
  504. },
  505. [3] = {
  506. .start = AT91RM9200_ID_TC2,
  507. .end = AT91RM9200_ID_TC2,
  508. .flags = IORESOURCE_IRQ,
  509. },
  510. };
  511. static struct platform_device at91rm9200_tcb0_device = {
  512. .name = "atmel_tcb",
  513. .id = 0,
  514. .resource = tcb0_resources,
  515. .num_resources = ARRAY_SIZE(tcb0_resources),
  516. };
  517. static struct resource tcb1_resources[] = {
  518. [0] = {
  519. .start = AT91RM9200_BASE_TCB1,
  520. .end = AT91RM9200_BASE_TCB1 + SZ_16K - 1,
  521. .flags = IORESOURCE_MEM,
  522. },
  523. [1] = {
  524. .start = AT91RM9200_ID_TC3,
  525. .end = AT91RM9200_ID_TC3,
  526. .flags = IORESOURCE_IRQ,
  527. },
  528. [2] = {
  529. .start = AT91RM9200_ID_TC4,
  530. .end = AT91RM9200_ID_TC4,
  531. .flags = IORESOURCE_IRQ,
  532. },
  533. [3] = {
  534. .start = AT91RM9200_ID_TC5,
  535. .end = AT91RM9200_ID_TC5,
  536. .flags = IORESOURCE_IRQ,
  537. },
  538. };
  539. static struct platform_device at91rm9200_tcb1_device = {
  540. .name = "atmel_tcb",
  541. .id = 1,
  542. .resource = tcb1_resources,
  543. .num_resources = ARRAY_SIZE(tcb1_resources),
  544. };
  545. static void __init at91_add_device_tc(void)
  546. {
  547. platform_device_register(&at91rm9200_tcb0_device);
  548. platform_device_register(&at91rm9200_tcb1_device);
  549. }
  550. #else
  551. static void __init at91_add_device_tc(void) { }
  552. #endif
  553. /* --------------------------------------------------------------------
  554. * RTC
  555. * -------------------------------------------------------------------- */
  556. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  557. static struct platform_device at91rm9200_rtc_device = {
  558. .name = "at91_rtc",
  559. .id = -1,
  560. .num_resources = 0,
  561. };
  562. static void __init at91_add_device_rtc(void)
  563. {
  564. platform_device_register(&at91rm9200_rtc_device);
  565. }
  566. #else
  567. static void __init at91_add_device_rtc(void) {}
  568. #endif
  569. /* --------------------------------------------------------------------
  570. * Watchdog
  571. * -------------------------------------------------------------------- */
  572. #if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
  573. static struct platform_device at91rm9200_wdt_device = {
  574. .name = "at91_wdt",
  575. .id = -1,
  576. .num_resources = 0,
  577. };
  578. static void __init at91_add_device_watchdog(void)
  579. {
  580. platform_device_register(&at91rm9200_wdt_device);
  581. }
  582. #else
  583. static void __init at91_add_device_watchdog(void) {}
  584. #endif
  585. /* --------------------------------------------------------------------
  586. * SSC -- Synchronous Serial Controller
  587. * -------------------------------------------------------------------- */
  588. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  589. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  590. static struct resource ssc0_resources[] = {
  591. [0] = {
  592. .start = AT91RM9200_BASE_SSC0,
  593. .end = AT91RM9200_BASE_SSC0 + SZ_16K - 1,
  594. .flags = IORESOURCE_MEM,
  595. },
  596. [1] = {
  597. .start = AT91RM9200_ID_SSC0,
  598. .end = AT91RM9200_ID_SSC0,
  599. .flags = IORESOURCE_IRQ,
  600. },
  601. };
  602. static struct platform_device at91rm9200_ssc0_device = {
  603. .name = "ssc",
  604. .id = 0,
  605. .dev = {
  606. .dma_mask = &ssc0_dmamask,
  607. .coherent_dma_mask = DMA_BIT_MASK(32),
  608. },
  609. .resource = ssc0_resources,
  610. .num_resources = ARRAY_SIZE(ssc0_resources),
  611. };
  612. static inline void configure_ssc0_pins(unsigned pins)
  613. {
  614. if (pins & ATMEL_SSC_TF)
  615. at91_set_A_periph(AT91_PIN_PB0, 1);
  616. if (pins & ATMEL_SSC_TK)
  617. at91_set_A_periph(AT91_PIN_PB1, 1);
  618. if (pins & ATMEL_SSC_TD)
  619. at91_set_A_periph(AT91_PIN_PB2, 1);
  620. if (pins & ATMEL_SSC_RD)
  621. at91_set_A_periph(AT91_PIN_PB3, 1);
  622. if (pins & ATMEL_SSC_RK)
  623. at91_set_A_periph(AT91_PIN_PB4, 1);
  624. if (pins & ATMEL_SSC_RF)
  625. at91_set_A_periph(AT91_PIN_PB5, 1);
  626. }
  627. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  628. static struct resource ssc1_resources[] = {
  629. [0] = {
  630. .start = AT91RM9200_BASE_SSC1,
  631. .end = AT91RM9200_BASE_SSC1 + SZ_16K - 1,
  632. .flags = IORESOURCE_MEM,
  633. },
  634. [1] = {
  635. .start = AT91RM9200_ID_SSC1,
  636. .end = AT91RM9200_ID_SSC1,
  637. .flags = IORESOURCE_IRQ,
  638. },
  639. };
  640. static struct platform_device at91rm9200_ssc1_device = {
  641. .name = "ssc",
  642. .id = 1,
  643. .dev = {
  644. .dma_mask = &ssc1_dmamask,
  645. .coherent_dma_mask = DMA_BIT_MASK(32),
  646. },
  647. .resource = ssc1_resources,
  648. .num_resources = ARRAY_SIZE(ssc1_resources),
  649. };
  650. static inline void configure_ssc1_pins(unsigned pins)
  651. {
  652. if (pins & ATMEL_SSC_TF)
  653. at91_set_A_periph(AT91_PIN_PB6, 1);
  654. if (pins & ATMEL_SSC_TK)
  655. at91_set_A_periph(AT91_PIN_PB7, 1);
  656. if (pins & ATMEL_SSC_TD)
  657. at91_set_A_periph(AT91_PIN_PB8, 1);
  658. if (pins & ATMEL_SSC_RD)
  659. at91_set_A_periph(AT91_PIN_PB9, 1);
  660. if (pins & ATMEL_SSC_RK)
  661. at91_set_A_periph(AT91_PIN_PB10, 1);
  662. if (pins & ATMEL_SSC_RF)
  663. at91_set_A_periph(AT91_PIN_PB11, 1);
  664. }
  665. static u64 ssc2_dmamask = DMA_BIT_MASK(32);
  666. static struct resource ssc2_resources[] = {
  667. [0] = {
  668. .start = AT91RM9200_BASE_SSC2,
  669. .end = AT91RM9200_BASE_SSC2 + SZ_16K - 1,
  670. .flags = IORESOURCE_MEM,
  671. },
  672. [1] = {
  673. .start = AT91RM9200_ID_SSC2,
  674. .end = AT91RM9200_ID_SSC2,
  675. .flags = IORESOURCE_IRQ,
  676. },
  677. };
  678. static struct platform_device at91rm9200_ssc2_device = {
  679. .name = "ssc",
  680. .id = 2,
  681. .dev = {
  682. .dma_mask = &ssc2_dmamask,
  683. .coherent_dma_mask = DMA_BIT_MASK(32),
  684. },
  685. .resource = ssc2_resources,
  686. .num_resources = ARRAY_SIZE(ssc2_resources),
  687. };
  688. static inline void configure_ssc2_pins(unsigned pins)
  689. {
  690. if (pins & ATMEL_SSC_TF)
  691. at91_set_A_periph(AT91_PIN_PB12, 1);
  692. if (pins & ATMEL_SSC_TK)
  693. at91_set_A_periph(AT91_PIN_PB13, 1);
  694. if (pins & ATMEL_SSC_TD)
  695. at91_set_A_periph(AT91_PIN_PB14, 1);
  696. if (pins & ATMEL_SSC_RD)
  697. at91_set_A_periph(AT91_PIN_PB15, 1);
  698. if (pins & ATMEL_SSC_RK)
  699. at91_set_A_periph(AT91_PIN_PB16, 1);
  700. if (pins & ATMEL_SSC_RF)
  701. at91_set_A_periph(AT91_PIN_PB17, 1);
  702. }
  703. /*
  704. * SSC controllers are accessed through library code, instead of any
  705. * kind of all-singing/all-dancing driver. For example one could be
  706. * used by a particular I2S audio codec's driver, while another one
  707. * on the same system might be used by a custom data capture driver.
  708. */
  709. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  710. {
  711. struct platform_device *pdev;
  712. /*
  713. * NOTE: caller is responsible for passing information matching
  714. * "pins" to whatever will be using each particular controller.
  715. */
  716. switch (id) {
  717. case AT91RM9200_ID_SSC0:
  718. pdev = &at91rm9200_ssc0_device;
  719. configure_ssc0_pins(pins);
  720. break;
  721. case AT91RM9200_ID_SSC1:
  722. pdev = &at91rm9200_ssc1_device;
  723. configure_ssc1_pins(pins);
  724. break;
  725. case AT91RM9200_ID_SSC2:
  726. pdev = &at91rm9200_ssc2_device;
  727. configure_ssc2_pins(pins);
  728. break;
  729. default:
  730. return;
  731. }
  732. platform_device_register(pdev);
  733. }
  734. #else
  735. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  736. #endif
  737. /* --------------------------------------------------------------------
  738. * UART
  739. * -------------------------------------------------------------------- */
  740. #if defined(CONFIG_SERIAL_ATMEL)
  741. static struct resource dbgu_resources[] = {
  742. [0] = {
  743. .start = AT91_BASE_SYS + AT91_DBGU,
  744. .end = AT91_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  745. .flags = IORESOURCE_MEM,
  746. },
  747. [1] = {
  748. .start = AT91_ID_SYS,
  749. .end = AT91_ID_SYS,
  750. .flags = IORESOURCE_IRQ,
  751. },
  752. };
  753. static struct atmel_uart_data dbgu_data = {
  754. .use_dma_tx = 0,
  755. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  756. };
  757. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  758. static struct platform_device at91rm9200_dbgu_device = {
  759. .name = "atmel_usart",
  760. .id = 0,
  761. .dev = {
  762. .dma_mask = &dbgu_dmamask,
  763. .coherent_dma_mask = DMA_BIT_MASK(32),
  764. .platform_data = &dbgu_data,
  765. },
  766. .resource = dbgu_resources,
  767. .num_resources = ARRAY_SIZE(dbgu_resources),
  768. };
  769. static inline void configure_dbgu_pins(void)
  770. {
  771. at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
  772. at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
  773. }
  774. static struct resource uart0_resources[] = {
  775. [0] = {
  776. .start = AT91RM9200_BASE_US0,
  777. .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
  778. .flags = IORESOURCE_MEM,
  779. },
  780. [1] = {
  781. .start = AT91RM9200_ID_US0,
  782. .end = AT91RM9200_ID_US0,
  783. .flags = IORESOURCE_IRQ,
  784. },
  785. };
  786. static struct atmel_uart_data uart0_data = {
  787. .use_dma_tx = 1,
  788. .use_dma_rx = 1,
  789. };
  790. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  791. static struct platform_device at91rm9200_uart0_device = {
  792. .name = "atmel_usart",
  793. .id = 1,
  794. .dev = {
  795. .dma_mask = &uart0_dmamask,
  796. .coherent_dma_mask = DMA_BIT_MASK(32),
  797. .platform_data = &uart0_data,
  798. },
  799. .resource = uart0_resources,
  800. .num_resources = ARRAY_SIZE(uart0_resources),
  801. };
  802. static inline void configure_usart0_pins(unsigned pins)
  803. {
  804. at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
  805. at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
  806. if (pins & ATMEL_UART_CTS)
  807. at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
  808. if (pins & ATMEL_UART_RTS) {
  809. /*
  810. * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
  811. * We need to drive the pin manually. Default is off (RTS is active low).
  812. */
  813. at91_set_gpio_output(AT91_PIN_PA21, 1);
  814. }
  815. }
  816. static struct resource uart1_resources[] = {
  817. [0] = {
  818. .start = AT91RM9200_BASE_US1,
  819. .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
  820. .flags = IORESOURCE_MEM,
  821. },
  822. [1] = {
  823. .start = AT91RM9200_ID_US1,
  824. .end = AT91RM9200_ID_US1,
  825. .flags = IORESOURCE_IRQ,
  826. },
  827. };
  828. static struct atmel_uart_data uart1_data = {
  829. .use_dma_tx = 1,
  830. .use_dma_rx = 1,
  831. };
  832. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  833. static struct platform_device at91rm9200_uart1_device = {
  834. .name = "atmel_usart",
  835. .id = 2,
  836. .dev = {
  837. .dma_mask = &uart1_dmamask,
  838. .coherent_dma_mask = DMA_BIT_MASK(32),
  839. .platform_data = &uart1_data,
  840. },
  841. .resource = uart1_resources,
  842. .num_resources = ARRAY_SIZE(uart1_resources),
  843. };
  844. static inline void configure_usart1_pins(unsigned pins)
  845. {
  846. at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
  847. at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
  848. if (pins & ATMEL_UART_RI)
  849. at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
  850. if (pins & ATMEL_UART_DTR)
  851. at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
  852. if (pins & ATMEL_UART_DCD)
  853. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
  854. if (pins & ATMEL_UART_CTS)
  855. at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
  856. if (pins & ATMEL_UART_DSR)
  857. at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
  858. if (pins & ATMEL_UART_RTS)
  859. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
  860. }
  861. static struct resource uart2_resources[] = {
  862. [0] = {
  863. .start = AT91RM9200_BASE_US2,
  864. .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
  865. .flags = IORESOURCE_MEM,
  866. },
  867. [1] = {
  868. .start = AT91RM9200_ID_US2,
  869. .end = AT91RM9200_ID_US2,
  870. .flags = IORESOURCE_IRQ,
  871. },
  872. };
  873. static struct atmel_uart_data uart2_data = {
  874. .use_dma_tx = 1,
  875. .use_dma_rx = 1,
  876. };
  877. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  878. static struct platform_device at91rm9200_uart2_device = {
  879. .name = "atmel_usart",
  880. .id = 3,
  881. .dev = {
  882. .dma_mask = &uart2_dmamask,
  883. .coherent_dma_mask = DMA_BIT_MASK(32),
  884. .platform_data = &uart2_data,
  885. },
  886. .resource = uart2_resources,
  887. .num_resources = ARRAY_SIZE(uart2_resources),
  888. };
  889. static inline void configure_usart2_pins(unsigned pins)
  890. {
  891. at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
  892. at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
  893. if (pins & ATMEL_UART_CTS)
  894. at91_set_B_periph(AT91_PIN_PA30, 0); /* CTS2 */
  895. if (pins & ATMEL_UART_RTS)
  896. at91_set_B_periph(AT91_PIN_PA31, 0); /* RTS2 */
  897. }
  898. static struct resource uart3_resources[] = {
  899. [0] = {
  900. .start = AT91RM9200_BASE_US3,
  901. .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
  902. .flags = IORESOURCE_MEM,
  903. },
  904. [1] = {
  905. .start = AT91RM9200_ID_US3,
  906. .end = AT91RM9200_ID_US3,
  907. .flags = IORESOURCE_IRQ,
  908. },
  909. };
  910. static struct atmel_uart_data uart3_data = {
  911. .use_dma_tx = 1,
  912. .use_dma_rx = 1,
  913. };
  914. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  915. static struct platform_device at91rm9200_uart3_device = {
  916. .name = "atmel_usart",
  917. .id = 4,
  918. .dev = {
  919. .dma_mask = &uart3_dmamask,
  920. .coherent_dma_mask = DMA_BIT_MASK(32),
  921. .platform_data = &uart3_data,
  922. },
  923. .resource = uart3_resources,
  924. .num_resources = ARRAY_SIZE(uart3_resources),
  925. };
  926. static inline void configure_usart3_pins(unsigned pins)
  927. {
  928. at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
  929. at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
  930. if (pins & ATMEL_UART_CTS)
  931. at91_set_B_periph(AT91_PIN_PB1, 0); /* CTS3 */
  932. if (pins & ATMEL_UART_RTS)
  933. at91_set_B_periph(AT91_PIN_PB0, 0); /* RTS3 */
  934. }
  935. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  936. struct platform_device *atmel_default_console_device; /* the serial console device */
  937. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  938. {
  939. struct platform_device *pdev;
  940. struct atmel_uart_data *pdata;
  941. switch (id) {
  942. case 0: /* DBGU */
  943. pdev = &at91rm9200_dbgu_device;
  944. configure_dbgu_pins();
  945. break;
  946. case AT91RM9200_ID_US0:
  947. pdev = &at91rm9200_uart0_device;
  948. configure_usart0_pins(pins);
  949. break;
  950. case AT91RM9200_ID_US1:
  951. pdev = &at91rm9200_uart1_device;
  952. configure_usart1_pins(pins);
  953. break;
  954. case AT91RM9200_ID_US2:
  955. pdev = &at91rm9200_uart2_device;
  956. configure_usart2_pins(pins);
  957. break;
  958. case AT91RM9200_ID_US3:
  959. pdev = &at91rm9200_uart3_device;
  960. configure_usart3_pins(pins);
  961. break;
  962. default:
  963. return;
  964. }
  965. pdata = pdev->dev.platform_data;
  966. pdata->num = portnr; /* update to mapped ID */
  967. if (portnr < ATMEL_MAX_UART)
  968. at91_uarts[portnr] = pdev;
  969. }
  970. void __init at91_set_serial_console(unsigned portnr)
  971. {
  972. if (portnr < ATMEL_MAX_UART) {
  973. atmel_default_console_device = at91_uarts[portnr];
  974. at91rm9200_set_console_clock(at91_uarts[portnr]->id);
  975. }
  976. }
  977. void __init at91_add_device_serial(void)
  978. {
  979. int i;
  980. for (i = 0; i < ATMEL_MAX_UART; i++) {
  981. if (at91_uarts[i])
  982. platform_device_register(at91_uarts[i]);
  983. }
  984. if (!atmel_default_console_device)
  985. printk(KERN_INFO "AT91: No default serial console defined.\n");
  986. }
  987. #else
  988. void __init __deprecated at91_init_serial(struct at91_uart_config *config) {}
  989. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  990. void __init at91_set_serial_console(unsigned portnr) {}
  991. void __init at91_add_device_serial(void) {}
  992. #endif
  993. /* -------------------------------------------------------------------- */
  994. /*
  995. * These devices are always present and don't need any board-specific
  996. * setup.
  997. */
  998. static int __init at91_add_standard_devices(void)
  999. {
  1000. at91_add_device_rtc();
  1001. at91_add_device_watchdog();
  1002. at91_add_device_tc();
  1003. return 0;
  1004. }
  1005. arch_initcall(at91_add_standard_devices);