at91rm9200_devices.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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_GADGET_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_VA_BASE_SYS + AT91_DBGU,
  744. .end = AT91_VA_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. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  757. };
  758. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  759. static struct platform_device at91rm9200_dbgu_device = {
  760. .name = "atmel_usart",
  761. .id = 0,
  762. .dev = {
  763. .dma_mask = &dbgu_dmamask,
  764. .coherent_dma_mask = DMA_BIT_MASK(32),
  765. .platform_data = &dbgu_data,
  766. },
  767. .resource = dbgu_resources,
  768. .num_resources = ARRAY_SIZE(dbgu_resources),
  769. };
  770. static inline void configure_dbgu_pins(void)
  771. {
  772. at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
  773. at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
  774. }
  775. static struct resource uart0_resources[] = {
  776. [0] = {
  777. .start = AT91RM9200_BASE_US0,
  778. .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
  779. .flags = IORESOURCE_MEM,
  780. },
  781. [1] = {
  782. .start = AT91RM9200_ID_US0,
  783. .end = AT91RM9200_ID_US0,
  784. .flags = IORESOURCE_IRQ,
  785. },
  786. };
  787. static struct atmel_uart_data uart0_data = {
  788. .use_dma_tx = 1,
  789. .use_dma_rx = 1,
  790. };
  791. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  792. static struct platform_device at91rm9200_uart0_device = {
  793. .name = "atmel_usart",
  794. .id = 1,
  795. .dev = {
  796. .dma_mask = &uart0_dmamask,
  797. .coherent_dma_mask = DMA_BIT_MASK(32),
  798. .platform_data = &uart0_data,
  799. },
  800. .resource = uart0_resources,
  801. .num_resources = ARRAY_SIZE(uart0_resources),
  802. };
  803. static inline void configure_usart0_pins(unsigned pins)
  804. {
  805. at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
  806. at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
  807. if (pins & ATMEL_UART_CTS)
  808. at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
  809. if (pins & ATMEL_UART_RTS) {
  810. /*
  811. * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
  812. * We need to drive the pin manually. Default is off (RTS is active low).
  813. */
  814. at91_set_gpio_output(AT91_PIN_PA21, 1);
  815. }
  816. }
  817. static struct resource uart1_resources[] = {
  818. [0] = {
  819. .start = AT91RM9200_BASE_US1,
  820. .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
  821. .flags = IORESOURCE_MEM,
  822. },
  823. [1] = {
  824. .start = AT91RM9200_ID_US1,
  825. .end = AT91RM9200_ID_US1,
  826. .flags = IORESOURCE_IRQ,
  827. },
  828. };
  829. static struct atmel_uart_data uart1_data = {
  830. .use_dma_tx = 1,
  831. .use_dma_rx = 1,
  832. };
  833. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  834. static struct platform_device at91rm9200_uart1_device = {
  835. .name = "atmel_usart",
  836. .id = 2,
  837. .dev = {
  838. .dma_mask = &uart1_dmamask,
  839. .coherent_dma_mask = DMA_BIT_MASK(32),
  840. .platform_data = &uart1_data,
  841. },
  842. .resource = uart1_resources,
  843. .num_resources = ARRAY_SIZE(uart1_resources),
  844. };
  845. static inline void configure_usart1_pins(unsigned pins)
  846. {
  847. at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
  848. at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
  849. if (pins & ATMEL_UART_RI)
  850. at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
  851. if (pins & ATMEL_UART_DTR)
  852. at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
  853. if (pins & ATMEL_UART_DCD)
  854. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
  855. if (pins & ATMEL_UART_CTS)
  856. at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
  857. if (pins & ATMEL_UART_DSR)
  858. at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
  859. if (pins & ATMEL_UART_RTS)
  860. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
  861. }
  862. static struct resource uart2_resources[] = {
  863. [0] = {
  864. .start = AT91RM9200_BASE_US2,
  865. .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
  866. .flags = IORESOURCE_MEM,
  867. },
  868. [1] = {
  869. .start = AT91RM9200_ID_US2,
  870. .end = AT91RM9200_ID_US2,
  871. .flags = IORESOURCE_IRQ,
  872. },
  873. };
  874. static struct atmel_uart_data uart2_data = {
  875. .use_dma_tx = 1,
  876. .use_dma_rx = 1,
  877. };
  878. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  879. static struct platform_device at91rm9200_uart2_device = {
  880. .name = "atmel_usart",
  881. .id = 3,
  882. .dev = {
  883. .dma_mask = &uart2_dmamask,
  884. .coherent_dma_mask = DMA_BIT_MASK(32),
  885. .platform_data = &uart2_data,
  886. },
  887. .resource = uart2_resources,
  888. .num_resources = ARRAY_SIZE(uart2_resources),
  889. };
  890. static inline void configure_usart2_pins(unsigned pins)
  891. {
  892. at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
  893. at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
  894. if (pins & ATMEL_UART_CTS)
  895. at91_set_B_periph(AT91_PIN_PA30, 0); /* CTS2 */
  896. if (pins & ATMEL_UART_RTS)
  897. at91_set_B_periph(AT91_PIN_PA31, 0); /* RTS2 */
  898. }
  899. static struct resource uart3_resources[] = {
  900. [0] = {
  901. .start = AT91RM9200_BASE_US3,
  902. .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
  903. .flags = IORESOURCE_MEM,
  904. },
  905. [1] = {
  906. .start = AT91RM9200_ID_US3,
  907. .end = AT91RM9200_ID_US3,
  908. .flags = IORESOURCE_IRQ,
  909. },
  910. };
  911. static struct atmel_uart_data uart3_data = {
  912. .use_dma_tx = 1,
  913. .use_dma_rx = 1,
  914. };
  915. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  916. static struct platform_device at91rm9200_uart3_device = {
  917. .name = "atmel_usart",
  918. .id = 4,
  919. .dev = {
  920. .dma_mask = &uart3_dmamask,
  921. .coherent_dma_mask = DMA_BIT_MASK(32),
  922. .platform_data = &uart3_data,
  923. },
  924. .resource = uart3_resources,
  925. .num_resources = ARRAY_SIZE(uart3_resources),
  926. };
  927. static inline void configure_usart3_pins(unsigned pins)
  928. {
  929. at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
  930. at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
  931. if (pins & ATMEL_UART_CTS)
  932. at91_set_B_periph(AT91_PIN_PB1, 0); /* CTS3 */
  933. if (pins & ATMEL_UART_RTS)
  934. at91_set_B_periph(AT91_PIN_PB0, 0); /* RTS3 */
  935. }
  936. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  937. struct platform_device *atmel_default_console_device; /* the serial console device */
  938. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  939. {
  940. struct platform_device *pdev;
  941. struct atmel_uart_data *pdata;
  942. switch (id) {
  943. case 0: /* DBGU */
  944. pdev = &at91rm9200_dbgu_device;
  945. configure_dbgu_pins();
  946. break;
  947. case AT91RM9200_ID_US0:
  948. pdev = &at91rm9200_uart0_device;
  949. configure_usart0_pins(pins);
  950. break;
  951. case AT91RM9200_ID_US1:
  952. pdev = &at91rm9200_uart1_device;
  953. configure_usart1_pins(pins);
  954. break;
  955. case AT91RM9200_ID_US2:
  956. pdev = &at91rm9200_uart2_device;
  957. configure_usart2_pins(pins);
  958. break;
  959. case AT91RM9200_ID_US3:
  960. pdev = &at91rm9200_uart3_device;
  961. configure_usart3_pins(pins);
  962. break;
  963. default:
  964. return;
  965. }
  966. pdata = pdev->dev.platform_data;
  967. pdata->num = portnr; /* update to mapped ID */
  968. if (portnr < ATMEL_MAX_UART)
  969. at91_uarts[portnr] = pdev;
  970. }
  971. void __init at91_set_serial_console(unsigned portnr)
  972. {
  973. if (portnr < ATMEL_MAX_UART) {
  974. atmel_default_console_device = at91_uarts[portnr];
  975. at91rm9200_set_console_clock(at91_uarts[portnr]->id);
  976. }
  977. }
  978. void __init at91_add_device_serial(void)
  979. {
  980. int i;
  981. for (i = 0; i < ATMEL_MAX_UART; i++) {
  982. if (at91_uarts[i])
  983. platform_device_register(at91_uarts[i]);
  984. }
  985. if (!atmel_default_console_device)
  986. printk(KERN_INFO "AT91: No default serial console defined.\n");
  987. }
  988. #else
  989. void __init __deprecated at91_init_serial(struct at91_uart_config *config) {}
  990. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  991. void __init at91_set_serial_console(unsigned portnr) {}
  992. void __init at91_add_device_serial(void) {}
  993. #endif
  994. /* -------------------------------------------------------------------- */
  995. /*
  996. * These devices are always present and don't need any board-specific
  997. * setup.
  998. */
  999. static int __init at91_add_standard_devices(void)
  1000. {
  1001. at91_add_device_rtc();
  1002. at91_add_device_watchdog();
  1003. at91_add_device_tc();
  1004. return 0;
  1005. }
  1006. arch_initcall(at91_add_standard_devices);