at91rm9200_devices.c 29 KB

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