at91rm9200_devices.c 30 KB

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