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 "generic.h"
  23. /* --------------------------------------------------------------------
  24. * USB Host
  25. * -------------------------------------------------------------------- */
  26. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  27. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  28. static struct at91_usbh_data usbh_data;
  29. static struct resource usbh_resources[] = {
  30. [0] = {
  31. .start = AT91RM9200_UHP_BASE,
  32. .end = AT91RM9200_UHP_BASE + SZ_1M - 1,
  33. .flags = IORESOURCE_MEM,
  34. },
  35. [1] = {
  36. .start = AT91RM9200_ID_UHP,
  37. .end = AT91RM9200_ID_UHP,
  38. .flags = IORESOURCE_IRQ,
  39. },
  40. };
  41. static struct platform_device at91rm9200_usbh_device = {
  42. .name = "at91_ohci",
  43. .id = -1,
  44. .dev = {
  45. .dma_mask = &ohci_dmamask,
  46. .coherent_dma_mask = DMA_BIT_MASK(32),
  47. .platform_data = &usbh_data,
  48. },
  49. .resource = usbh_resources,
  50. .num_resources = ARRAY_SIZE(usbh_resources),
  51. };
  52. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  53. {
  54. int i;
  55. if (!data)
  56. return;
  57. /* Enable overcurrent notification */
  58. for (i = 0; i < data->ports; i++) {
  59. if (data->overcurrent_pin[i])
  60. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  61. }
  62. usbh_data = *data;
  63. platform_device_register(&at91rm9200_usbh_device);
  64. }
  65. #else
  66. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  67. #endif
  68. /* --------------------------------------------------------------------
  69. * USB Device (Gadget)
  70. * -------------------------------------------------------------------- */
  71. #ifdef CONFIG_USB_AT91
  72. static struct at91_udc_data udc_data;
  73. static struct resource udc_resources[] = {
  74. [0] = {
  75. .start = AT91RM9200_BASE_UDP,
  76. .end = AT91RM9200_BASE_UDP + SZ_16K - 1,
  77. .flags = IORESOURCE_MEM,
  78. },
  79. [1] = {
  80. .start = AT91RM9200_ID_UDP,
  81. .end = AT91RM9200_ID_UDP,
  82. .flags = IORESOURCE_IRQ,
  83. },
  84. };
  85. static struct platform_device at91rm9200_udc_device = {
  86. .name = "at91_udc",
  87. .id = -1,
  88. .dev = {
  89. .platform_data = &udc_data,
  90. },
  91. .resource = udc_resources,
  92. .num_resources = ARRAY_SIZE(udc_resources),
  93. };
  94. void __init at91_add_device_udc(struct at91_udc_data *data)
  95. {
  96. if (!data)
  97. return;
  98. if (gpio_is_valid(data->vbus_pin)) {
  99. at91_set_gpio_input(data->vbus_pin, 0);
  100. at91_set_deglitch(data->vbus_pin, 1);
  101. }
  102. if (gpio_is_valid(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 macb_platform_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 macb_platform_data *data)
  140. {
  141. if (!data)
  142. return;
  143. if (gpio_is_valid(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 macb_platform_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 (gpio_is_valid(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 (gpio_is_valid(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 (gpio_is_valid(data->det_pin)) {
  279. at91_set_gpio_input(data->det_pin, 1);
  280. at91_set_deglitch(data->det_pin, 1);
  281. }
  282. if (gpio_is_valid(data->wp_pin))
  283. at91_set_gpio_input(data->wp_pin, 1);
  284. if (gpio_is_valid(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 (gpio_is_valid(data->enable_pin))
  354. at91_set_gpio_output(data->enable_pin, 1);
  355. /* ready/busy pin */
  356. if (gpio_is_valid(data->rdy_pin))
  357. at91_set_gpio_input(data->rdy_pin, 1);
  358. /* card detect pin */
  359. if (gpio_is_valid(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 resource rtc_resources[] = {
  558. [0] = {
  559. .start = AT91RM9200_BASE_RTC,
  560. .end = AT91RM9200_BASE_RTC + SZ_256 - 1,
  561. .flags = IORESOURCE_MEM,
  562. },
  563. [1] = {
  564. .start = AT91_ID_SYS,
  565. .end = AT91_ID_SYS,
  566. .flags = IORESOURCE_IRQ,
  567. },
  568. };
  569. static struct platform_device at91rm9200_rtc_device = {
  570. .name = "at91_rtc",
  571. .id = -1,
  572. .resource = rtc_resources,
  573. .num_resources = ARRAY_SIZE(rtc_resources),
  574. };
  575. static void __init at91_add_device_rtc(void)
  576. {
  577. platform_device_register(&at91rm9200_rtc_device);
  578. }
  579. #else
  580. static void __init at91_add_device_rtc(void) {}
  581. #endif
  582. /* --------------------------------------------------------------------
  583. * Watchdog
  584. * -------------------------------------------------------------------- */
  585. #if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
  586. static struct platform_device at91rm9200_wdt_device = {
  587. .name = "at91_wdt",
  588. .id = -1,
  589. .num_resources = 0,
  590. };
  591. static void __init at91_add_device_watchdog(void)
  592. {
  593. platform_device_register(&at91rm9200_wdt_device);
  594. }
  595. #else
  596. static void __init at91_add_device_watchdog(void) {}
  597. #endif
  598. /* --------------------------------------------------------------------
  599. * SSC -- Synchronous Serial Controller
  600. * -------------------------------------------------------------------- */
  601. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  602. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  603. static struct resource ssc0_resources[] = {
  604. [0] = {
  605. .start = AT91RM9200_BASE_SSC0,
  606. .end = AT91RM9200_BASE_SSC0 + SZ_16K - 1,
  607. .flags = IORESOURCE_MEM,
  608. },
  609. [1] = {
  610. .start = AT91RM9200_ID_SSC0,
  611. .end = AT91RM9200_ID_SSC0,
  612. .flags = IORESOURCE_IRQ,
  613. },
  614. };
  615. static struct platform_device at91rm9200_ssc0_device = {
  616. .name = "ssc",
  617. .id = 0,
  618. .dev = {
  619. .dma_mask = &ssc0_dmamask,
  620. .coherent_dma_mask = DMA_BIT_MASK(32),
  621. },
  622. .resource = ssc0_resources,
  623. .num_resources = ARRAY_SIZE(ssc0_resources),
  624. };
  625. static inline void configure_ssc0_pins(unsigned pins)
  626. {
  627. if (pins & ATMEL_SSC_TF)
  628. at91_set_A_periph(AT91_PIN_PB0, 1);
  629. if (pins & ATMEL_SSC_TK)
  630. at91_set_A_periph(AT91_PIN_PB1, 1);
  631. if (pins & ATMEL_SSC_TD)
  632. at91_set_A_periph(AT91_PIN_PB2, 1);
  633. if (pins & ATMEL_SSC_RD)
  634. at91_set_A_periph(AT91_PIN_PB3, 1);
  635. if (pins & ATMEL_SSC_RK)
  636. at91_set_A_periph(AT91_PIN_PB4, 1);
  637. if (pins & ATMEL_SSC_RF)
  638. at91_set_A_periph(AT91_PIN_PB5, 1);
  639. }
  640. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  641. static struct resource ssc1_resources[] = {
  642. [0] = {
  643. .start = AT91RM9200_BASE_SSC1,
  644. .end = AT91RM9200_BASE_SSC1 + SZ_16K - 1,
  645. .flags = IORESOURCE_MEM,
  646. },
  647. [1] = {
  648. .start = AT91RM9200_ID_SSC1,
  649. .end = AT91RM9200_ID_SSC1,
  650. .flags = IORESOURCE_IRQ,
  651. },
  652. };
  653. static struct platform_device at91rm9200_ssc1_device = {
  654. .name = "ssc",
  655. .id = 1,
  656. .dev = {
  657. .dma_mask = &ssc1_dmamask,
  658. .coherent_dma_mask = DMA_BIT_MASK(32),
  659. },
  660. .resource = ssc1_resources,
  661. .num_resources = ARRAY_SIZE(ssc1_resources),
  662. };
  663. static inline void configure_ssc1_pins(unsigned pins)
  664. {
  665. if (pins & ATMEL_SSC_TF)
  666. at91_set_A_periph(AT91_PIN_PB6, 1);
  667. if (pins & ATMEL_SSC_TK)
  668. at91_set_A_periph(AT91_PIN_PB7, 1);
  669. if (pins & ATMEL_SSC_TD)
  670. at91_set_A_periph(AT91_PIN_PB8, 1);
  671. if (pins & ATMEL_SSC_RD)
  672. at91_set_A_periph(AT91_PIN_PB9, 1);
  673. if (pins & ATMEL_SSC_RK)
  674. at91_set_A_periph(AT91_PIN_PB10, 1);
  675. if (pins & ATMEL_SSC_RF)
  676. at91_set_A_periph(AT91_PIN_PB11, 1);
  677. }
  678. static u64 ssc2_dmamask = DMA_BIT_MASK(32);
  679. static struct resource ssc2_resources[] = {
  680. [0] = {
  681. .start = AT91RM9200_BASE_SSC2,
  682. .end = AT91RM9200_BASE_SSC2 + SZ_16K - 1,
  683. .flags = IORESOURCE_MEM,
  684. },
  685. [1] = {
  686. .start = AT91RM9200_ID_SSC2,
  687. .end = AT91RM9200_ID_SSC2,
  688. .flags = IORESOURCE_IRQ,
  689. },
  690. };
  691. static struct platform_device at91rm9200_ssc2_device = {
  692. .name = "ssc",
  693. .id = 2,
  694. .dev = {
  695. .dma_mask = &ssc2_dmamask,
  696. .coherent_dma_mask = DMA_BIT_MASK(32),
  697. },
  698. .resource = ssc2_resources,
  699. .num_resources = ARRAY_SIZE(ssc2_resources),
  700. };
  701. static inline void configure_ssc2_pins(unsigned pins)
  702. {
  703. if (pins & ATMEL_SSC_TF)
  704. at91_set_A_periph(AT91_PIN_PB12, 1);
  705. if (pins & ATMEL_SSC_TK)
  706. at91_set_A_periph(AT91_PIN_PB13, 1);
  707. if (pins & ATMEL_SSC_TD)
  708. at91_set_A_periph(AT91_PIN_PB14, 1);
  709. if (pins & ATMEL_SSC_RD)
  710. at91_set_A_periph(AT91_PIN_PB15, 1);
  711. if (pins & ATMEL_SSC_RK)
  712. at91_set_A_periph(AT91_PIN_PB16, 1);
  713. if (pins & ATMEL_SSC_RF)
  714. at91_set_A_periph(AT91_PIN_PB17, 1);
  715. }
  716. /*
  717. * SSC controllers are accessed through library code, instead of any
  718. * kind of all-singing/all-dancing driver. For example one could be
  719. * used by a particular I2S audio codec's driver, while another one
  720. * on the same system might be used by a custom data capture driver.
  721. */
  722. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  723. {
  724. struct platform_device *pdev;
  725. /*
  726. * NOTE: caller is responsible for passing information matching
  727. * "pins" to whatever will be using each particular controller.
  728. */
  729. switch (id) {
  730. case AT91RM9200_ID_SSC0:
  731. pdev = &at91rm9200_ssc0_device;
  732. configure_ssc0_pins(pins);
  733. break;
  734. case AT91RM9200_ID_SSC1:
  735. pdev = &at91rm9200_ssc1_device;
  736. configure_ssc1_pins(pins);
  737. break;
  738. case AT91RM9200_ID_SSC2:
  739. pdev = &at91rm9200_ssc2_device;
  740. configure_ssc2_pins(pins);
  741. break;
  742. default:
  743. return;
  744. }
  745. platform_device_register(pdev);
  746. }
  747. #else
  748. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  749. #endif
  750. /* --------------------------------------------------------------------
  751. * UART
  752. * -------------------------------------------------------------------- */
  753. #if defined(CONFIG_SERIAL_ATMEL)
  754. static struct resource dbgu_resources[] = {
  755. [0] = {
  756. .start = AT91RM9200_BASE_DBGU,
  757. .end = AT91RM9200_BASE_DBGU + SZ_512 - 1,
  758. .flags = IORESOURCE_MEM,
  759. },
  760. [1] = {
  761. .start = AT91_ID_SYS,
  762. .end = AT91_ID_SYS,
  763. .flags = IORESOURCE_IRQ,
  764. },
  765. };
  766. static struct atmel_uart_data dbgu_data = {
  767. .use_dma_tx = 0,
  768. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  769. };
  770. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  771. static struct platform_device at91rm9200_dbgu_device = {
  772. .name = "atmel_usart",
  773. .id = 0,
  774. .dev = {
  775. .dma_mask = &dbgu_dmamask,
  776. .coherent_dma_mask = DMA_BIT_MASK(32),
  777. .platform_data = &dbgu_data,
  778. },
  779. .resource = dbgu_resources,
  780. .num_resources = ARRAY_SIZE(dbgu_resources),
  781. };
  782. static inline void configure_dbgu_pins(void)
  783. {
  784. at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
  785. at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
  786. }
  787. static struct resource uart0_resources[] = {
  788. [0] = {
  789. .start = AT91RM9200_BASE_US0,
  790. .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
  791. .flags = IORESOURCE_MEM,
  792. },
  793. [1] = {
  794. .start = AT91RM9200_ID_US0,
  795. .end = AT91RM9200_ID_US0,
  796. .flags = IORESOURCE_IRQ,
  797. },
  798. };
  799. static struct atmel_uart_data uart0_data = {
  800. .use_dma_tx = 1,
  801. .use_dma_rx = 1,
  802. };
  803. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  804. static struct platform_device at91rm9200_uart0_device = {
  805. .name = "atmel_usart",
  806. .id = 1,
  807. .dev = {
  808. .dma_mask = &uart0_dmamask,
  809. .coherent_dma_mask = DMA_BIT_MASK(32),
  810. .platform_data = &uart0_data,
  811. },
  812. .resource = uart0_resources,
  813. .num_resources = ARRAY_SIZE(uart0_resources),
  814. };
  815. static inline void configure_usart0_pins(unsigned pins)
  816. {
  817. at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
  818. at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
  819. if (pins & ATMEL_UART_CTS)
  820. at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
  821. if (pins & ATMEL_UART_RTS) {
  822. /*
  823. * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
  824. * We need to drive the pin manually. Default is off (RTS is active low).
  825. */
  826. at91_set_gpio_output(AT91_PIN_PA21, 1);
  827. }
  828. }
  829. static struct resource uart1_resources[] = {
  830. [0] = {
  831. .start = AT91RM9200_BASE_US1,
  832. .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
  833. .flags = IORESOURCE_MEM,
  834. },
  835. [1] = {
  836. .start = AT91RM9200_ID_US1,
  837. .end = AT91RM9200_ID_US1,
  838. .flags = IORESOURCE_IRQ,
  839. },
  840. };
  841. static struct atmel_uart_data uart1_data = {
  842. .use_dma_tx = 1,
  843. .use_dma_rx = 1,
  844. };
  845. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  846. static struct platform_device at91rm9200_uart1_device = {
  847. .name = "atmel_usart",
  848. .id = 2,
  849. .dev = {
  850. .dma_mask = &uart1_dmamask,
  851. .coherent_dma_mask = DMA_BIT_MASK(32),
  852. .platform_data = &uart1_data,
  853. },
  854. .resource = uart1_resources,
  855. .num_resources = ARRAY_SIZE(uart1_resources),
  856. };
  857. static inline void configure_usart1_pins(unsigned pins)
  858. {
  859. at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
  860. at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
  861. if (pins & ATMEL_UART_RI)
  862. at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
  863. if (pins & ATMEL_UART_DTR)
  864. at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
  865. if (pins & ATMEL_UART_DCD)
  866. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
  867. if (pins & ATMEL_UART_CTS)
  868. at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
  869. if (pins & ATMEL_UART_DSR)
  870. at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
  871. if (pins & ATMEL_UART_RTS)
  872. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
  873. }
  874. static struct resource uart2_resources[] = {
  875. [0] = {
  876. .start = AT91RM9200_BASE_US2,
  877. .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
  878. .flags = IORESOURCE_MEM,
  879. },
  880. [1] = {
  881. .start = AT91RM9200_ID_US2,
  882. .end = AT91RM9200_ID_US2,
  883. .flags = IORESOURCE_IRQ,
  884. },
  885. };
  886. static struct atmel_uart_data uart2_data = {
  887. .use_dma_tx = 1,
  888. .use_dma_rx = 1,
  889. };
  890. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  891. static struct platform_device at91rm9200_uart2_device = {
  892. .name = "atmel_usart",
  893. .id = 3,
  894. .dev = {
  895. .dma_mask = &uart2_dmamask,
  896. .coherent_dma_mask = DMA_BIT_MASK(32),
  897. .platform_data = &uart2_data,
  898. },
  899. .resource = uart2_resources,
  900. .num_resources = ARRAY_SIZE(uart2_resources),
  901. };
  902. static inline void configure_usart2_pins(unsigned pins)
  903. {
  904. at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
  905. at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
  906. if (pins & ATMEL_UART_CTS)
  907. at91_set_B_periph(AT91_PIN_PA30, 0); /* CTS2 */
  908. if (pins & ATMEL_UART_RTS)
  909. at91_set_B_periph(AT91_PIN_PA31, 0); /* RTS2 */
  910. }
  911. static struct resource uart3_resources[] = {
  912. [0] = {
  913. .start = AT91RM9200_BASE_US3,
  914. .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
  915. .flags = IORESOURCE_MEM,
  916. },
  917. [1] = {
  918. .start = AT91RM9200_ID_US3,
  919. .end = AT91RM9200_ID_US3,
  920. .flags = IORESOURCE_IRQ,
  921. },
  922. };
  923. static struct atmel_uart_data uart3_data = {
  924. .use_dma_tx = 1,
  925. .use_dma_rx = 1,
  926. };
  927. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  928. static struct platform_device at91rm9200_uart3_device = {
  929. .name = "atmel_usart",
  930. .id = 4,
  931. .dev = {
  932. .dma_mask = &uart3_dmamask,
  933. .coherent_dma_mask = DMA_BIT_MASK(32),
  934. .platform_data = &uart3_data,
  935. },
  936. .resource = uart3_resources,
  937. .num_resources = ARRAY_SIZE(uart3_resources),
  938. };
  939. static inline void configure_usart3_pins(unsigned pins)
  940. {
  941. at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
  942. at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
  943. if (pins & ATMEL_UART_CTS)
  944. at91_set_B_periph(AT91_PIN_PB1, 0); /* CTS3 */
  945. if (pins & ATMEL_UART_RTS)
  946. at91_set_B_periph(AT91_PIN_PB0, 0); /* RTS3 */
  947. }
  948. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  949. struct platform_device *atmel_default_console_device; /* the serial console device */
  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 __deprecated at91_init_serial(struct at91_uart_config *config) {}
  1002. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1003. void __init at91_set_serial_console(unsigned portnr) {}
  1004. void __init at91_add_device_serial(void) {}
  1005. #endif
  1006. /* -------------------------------------------------------------------- */
  1007. /*
  1008. * These devices are always present and don't need any board-specific
  1009. * setup.
  1010. */
  1011. static int __init at91_add_standard_devices(void)
  1012. {
  1013. at91_add_device_rtc();
  1014. at91_add_device_watchdog();
  1015. at91_add_device_tc();
  1016. return 0;
  1017. }
  1018. arch_initcall(at91_add_standard_devices);