at91rm9200_devices.c 29 KB

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