at91sam9rl_devices.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. /*
  2. * Copyright (C) 2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file COPYING in the main directory of this archive for
  6. * more details.
  7. */
  8. #include <asm/mach/arch.h>
  9. #include <asm/mach/map.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/i2c-gpio.h>
  13. #include <linux/fb.h>
  14. #include <video/atmel_lcdc.h>
  15. #include <asm/arch/board.h>
  16. #include <asm/arch/gpio.h>
  17. #include <asm/arch/at91sam9rl.h>
  18. #include <asm/arch/at91sam9rl_matrix.h>
  19. #include <asm/arch/at91sam9_smc.h>
  20. #include "generic.h"
  21. /* --------------------------------------------------------------------
  22. * MMC / SD
  23. * -------------------------------------------------------------------- */
  24. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  25. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  26. static struct at91_mmc_data mmc_data;
  27. static struct resource mmc_resources[] = {
  28. [0] = {
  29. .start = AT91SAM9RL_BASE_MCI,
  30. .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
  31. .flags = IORESOURCE_MEM,
  32. },
  33. [1] = {
  34. .start = AT91SAM9RL_ID_MCI,
  35. .end = AT91SAM9RL_ID_MCI,
  36. .flags = IORESOURCE_IRQ,
  37. },
  38. };
  39. static struct platform_device at91sam9rl_mmc_device = {
  40. .name = "at91_mci",
  41. .id = -1,
  42. .dev = {
  43. .dma_mask = &mmc_dmamask,
  44. .coherent_dma_mask = DMA_BIT_MASK(32),
  45. .platform_data = &mmc_data,
  46. },
  47. .resource = mmc_resources,
  48. .num_resources = ARRAY_SIZE(mmc_resources),
  49. };
  50. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  51. {
  52. if (!data)
  53. return;
  54. /* input/irq */
  55. if (data->det_pin) {
  56. at91_set_gpio_input(data->det_pin, 1);
  57. at91_set_deglitch(data->det_pin, 1);
  58. }
  59. if (data->wp_pin)
  60. at91_set_gpio_input(data->wp_pin, 1);
  61. if (data->vcc_pin)
  62. at91_set_gpio_output(data->vcc_pin, 0);
  63. /* CLK */
  64. at91_set_A_periph(AT91_PIN_PA2, 0);
  65. /* CMD */
  66. at91_set_A_periph(AT91_PIN_PA1, 1);
  67. /* DAT0, maybe DAT1..DAT3 */
  68. at91_set_A_periph(AT91_PIN_PA0, 1);
  69. if (data->wire4) {
  70. at91_set_A_periph(AT91_PIN_PA3, 1);
  71. at91_set_A_periph(AT91_PIN_PA4, 1);
  72. at91_set_A_periph(AT91_PIN_PA5, 1);
  73. }
  74. mmc_data = *data;
  75. platform_device_register(&at91sam9rl_mmc_device);
  76. }
  77. #else
  78. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  79. #endif
  80. /* --------------------------------------------------------------------
  81. * NAND / SmartMedia
  82. * -------------------------------------------------------------------- */
  83. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  84. static struct at91_nand_data nand_data;
  85. #define NAND_BASE AT91_CHIPSELECT_3
  86. static struct resource nand_resources[] = {
  87. [0] = {
  88. .start = NAND_BASE,
  89. .end = NAND_BASE + SZ_256M - 1,
  90. .flags = IORESOURCE_MEM,
  91. },
  92. [1] = {
  93. .start = AT91_BASE_SYS + AT91_ECC,
  94. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  95. .flags = IORESOURCE_MEM,
  96. }
  97. };
  98. static struct platform_device at91_nand_device = {
  99. .name = "at91_nand",
  100. .id = -1,
  101. .dev = {
  102. .platform_data = &nand_data,
  103. },
  104. .resource = nand_resources,
  105. .num_resources = ARRAY_SIZE(nand_resources),
  106. };
  107. void __init at91_add_device_nand(struct at91_nand_data *data)
  108. {
  109. unsigned long csa;
  110. if (!data)
  111. return;
  112. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  113. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  114. /* set the bus interface characteristics */
  115. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(0) | AT91_SMC_NCS_WRSETUP_(0)
  116. | AT91_SMC_NRDSETUP_(0) | AT91_SMC_NCS_RDSETUP_(0));
  117. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(2) | AT91_SMC_NCS_WRPULSE_(5)
  118. | AT91_SMC_NRDPULSE_(2) | AT91_SMC_NCS_RDPULSE_(5));
  119. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(7) | AT91_SMC_NRDCYCLE_(7));
  120. at91_sys_write(AT91_SMC_MODE(3), AT91_SMC_DBW_8 | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
  121. /* enable pin */
  122. if (data->enable_pin)
  123. at91_set_gpio_output(data->enable_pin, 1);
  124. /* ready/busy pin */
  125. if (data->rdy_pin)
  126. at91_set_gpio_input(data->rdy_pin, 1);
  127. /* card detect pin */
  128. if (data->det_pin)
  129. at91_set_gpio_input(data->det_pin, 1);
  130. at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
  131. at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
  132. nand_data = *data;
  133. platform_device_register(&at91_nand_device);
  134. }
  135. #else
  136. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  137. #endif
  138. /* --------------------------------------------------------------------
  139. * TWI (i2c)
  140. * -------------------------------------------------------------------- */
  141. /*
  142. * Prefer the GPIO code since the TWI controller isn't robust
  143. * (gets overruns and underruns under load) and can only issue
  144. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  145. */
  146. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  147. static struct i2c_gpio_platform_data pdata = {
  148. .sda_pin = AT91_PIN_PA23,
  149. .sda_is_open_drain = 1,
  150. .scl_pin = AT91_PIN_PA24,
  151. .scl_is_open_drain = 1,
  152. .udelay = 2, /* ~100 kHz */
  153. };
  154. static struct platform_device at91sam9rl_twi_device = {
  155. .name = "i2c-gpio",
  156. .id = -1,
  157. .dev.platform_data = &pdata,
  158. };
  159. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  160. {
  161. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  162. at91_set_multi_drive(AT91_PIN_PA23, 1);
  163. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  164. at91_set_multi_drive(AT91_PIN_PA24, 1);
  165. i2c_register_board_info(0, devices, nr_devices);
  166. platform_device_register(&at91sam9rl_twi_device);
  167. }
  168. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  169. static struct resource twi_resources[] = {
  170. [0] = {
  171. .start = AT91SAM9RL_BASE_TWI0,
  172. .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
  173. .flags = IORESOURCE_MEM,
  174. },
  175. [1] = {
  176. .start = AT91SAM9RL_ID_TWI0,
  177. .end = AT91SAM9RL_ID_TWI0,
  178. .flags = IORESOURCE_IRQ,
  179. },
  180. };
  181. static struct platform_device at91sam9rl_twi_device = {
  182. .name = "at91_i2c",
  183. .id = -1,
  184. .resource = twi_resources,
  185. .num_resources = ARRAY_SIZE(twi_resources),
  186. };
  187. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  188. {
  189. /* pins used for TWI interface */
  190. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  191. at91_set_multi_drive(AT91_PIN_PA23, 1);
  192. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  193. at91_set_multi_drive(AT91_PIN_PA24, 1);
  194. i2c_register_board_info(0, devices, nr_devices);
  195. platform_device_register(&at91sam9rl_twi_device);
  196. }
  197. #else
  198. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  199. #endif
  200. /* --------------------------------------------------------------------
  201. * SPI
  202. * -------------------------------------------------------------------- */
  203. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  204. static u64 spi_dmamask = DMA_BIT_MASK(32);
  205. static struct resource spi_resources[] = {
  206. [0] = {
  207. .start = AT91SAM9RL_BASE_SPI,
  208. .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
  209. .flags = IORESOURCE_MEM,
  210. },
  211. [1] = {
  212. .start = AT91SAM9RL_ID_SPI,
  213. .end = AT91SAM9RL_ID_SPI,
  214. .flags = IORESOURCE_IRQ,
  215. },
  216. };
  217. static struct platform_device at91sam9rl_spi_device = {
  218. .name = "atmel_spi",
  219. .id = 0,
  220. .dev = {
  221. .dma_mask = &spi_dmamask,
  222. .coherent_dma_mask = DMA_BIT_MASK(32),
  223. },
  224. .resource = spi_resources,
  225. .num_resources = ARRAY_SIZE(spi_resources),
  226. };
  227. static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
  228. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  229. {
  230. int i;
  231. unsigned long cs_pin;
  232. at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
  233. at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
  234. at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
  235. /* Enable SPI chip-selects */
  236. for (i = 0; i < nr_devices; i++) {
  237. if (devices[i].controller_data)
  238. cs_pin = (unsigned long) devices[i].controller_data;
  239. else
  240. cs_pin = spi_standard_cs[devices[i].chip_select];
  241. /* enable chip-select pin */
  242. at91_set_gpio_output(cs_pin, 1);
  243. /* pass chip-select pin to driver */
  244. devices[i].controller_data = (void *) cs_pin;
  245. }
  246. spi_register_board_info(devices, nr_devices);
  247. platform_device_register(&at91sam9rl_spi_device);
  248. }
  249. #else
  250. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  251. #endif
  252. /* --------------------------------------------------------------------
  253. * LCD Controller
  254. * -------------------------------------------------------------------- */
  255. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  256. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  257. static struct atmel_lcdfb_info lcdc_data;
  258. static struct resource lcdc_resources[] = {
  259. [0] = {
  260. .start = AT91SAM9RL_LCDC_BASE,
  261. .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
  262. .flags = IORESOURCE_MEM,
  263. },
  264. [1] = {
  265. .start = AT91SAM9RL_ID_LCDC,
  266. .end = AT91SAM9RL_ID_LCDC,
  267. .flags = IORESOURCE_IRQ,
  268. },
  269. #if defined(CONFIG_FB_INTSRAM)
  270. [2] = {
  271. .start = AT91SAM9RL_SRAM_BASE,
  272. .end = AT91SAM9RL_SRAM_BASE + AT91SAM9RL_SRAM_SIZE - 1,
  273. .flags = IORESOURCE_MEM,
  274. },
  275. #endif
  276. };
  277. static struct platform_device at91_lcdc_device = {
  278. .name = "atmel_lcdfb",
  279. .id = 0,
  280. .dev = {
  281. .dma_mask = &lcdc_dmamask,
  282. .coherent_dma_mask = DMA_BIT_MASK(32),
  283. .platform_data = &lcdc_data,
  284. },
  285. .resource = lcdc_resources,
  286. .num_resources = ARRAY_SIZE(lcdc_resources),
  287. };
  288. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  289. {
  290. if (!data) {
  291. return;
  292. }
  293. at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
  294. at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
  295. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
  296. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
  297. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
  298. at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
  299. at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
  300. at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
  301. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
  302. at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
  303. at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  304. at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  305. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  306. at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  307. at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  308. at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
  309. at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
  310. at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
  311. at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
  312. at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
  313. at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
  314. lcdc_data = *data;
  315. platform_device_register(&at91_lcdc_device);
  316. }
  317. #else
  318. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  319. #endif
  320. /* --------------------------------------------------------------------
  321. * RTC
  322. * -------------------------------------------------------------------- */
  323. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  324. static struct platform_device at91sam9rl_rtc_device = {
  325. .name = "at91_rtc",
  326. .id = -1,
  327. .num_resources = 0,
  328. };
  329. static void __init at91_add_device_rtc(void)
  330. {
  331. platform_device_register(&at91sam9rl_rtc_device);
  332. }
  333. #else
  334. static void __init at91_add_device_rtc(void) {}
  335. #endif
  336. /* --------------------------------------------------------------------
  337. * RTT
  338. * -------------------------------------------------------------------- */
  339. static struct resource rtt_resources[] = {
  340. {
  341. .start = AT91_BASE_SYS + AT91_RTT,
  342. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  343. .flags = IORESOURCE_MEM,
  344. }
  345. };
  346. static struct platform_device at91sam9rl_rtt_device = {
  347. .name = "at91_rtt",
  348. .id = -1,
  349. .resource = rtt_resources,
  350. .num_resources = ARRAY_SIZE(rtt_resources),
  351. };
  352. static void __init at91_add_device_rtt(void)
  353. {
  354. platform_device_register(&at91sam9rl_rtt_device);
  355. }
  356. /* --------------------------------------------------------------------
  357. * Watchdog
  358. * -------------------------------------------------------------------- */
  359. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  360. static struct platform_device at91sam9rl_wdt_device = {
  361. .name = "at91_wdt",
  362. .id = -1,
  363. .num_resources = 0,
  364. };
  365. static void __init at91_add_device_watchdog(void)
  366. {
  367. platform_device_register(&at91sam9rl_wdt_device);
  368. }
  369. #else
  370. static void __init at91_add_device_watchdog(void) {}
  371. #endif
  372. /* --------------------------------------------------------------------
  373. * SSC -- Synchronous Serial Controller
  374. * -------------------------------------------------------------------- */
  375. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  376. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  377. static struct resource ssc0_resources[] = {
  378. [0] = {
  379. .start = AT91SAM9RL_BASE_SSC0,
  380. .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
  381. .flags = IORESOURCE_MEM,
  382. },
  383. [1] = {
  384. .start = AT91SAM9RL_ID_SSC0,
  385. .end = AT91SAM9RL_ID_SSC0,
  386. .flags = IORESOURCE_IRQ,
  387. },
  388. };
  389. static struct platform_device at91sam9rl_ssc0_device = {
  390. .name = "ssc",
  391. .id = 0,
  392. .dev = {
  393. .dma_mask = &ssc0_dmamask,
  394. .coherent_dma_mask = DMA_BIT_MASK(32),
  395. },
  396. .resource = ssc0_resources,
  397. .num_resources = ARRAY_SIZE(ssc0_resources),
  398. };
  399. static inline void configure_ssc0_pins(unsigned pins)
  400. {
  401. if (pins & ATMEL_SSC_TF)
  402. at91_set_A_periph(AT91_PIN_PC0, 1);
  403. if (pins & ATMEL_SSC_TK)
  404. at91_set_A_periph(AT91_PIN_PC1, 1);
  405. if (pins & ATMEL_SSC_TD)
  406. at91_set_A_periph(AT91_PIN_PA15, 1);
  407. if (pins & ATMEL_SSC_RD)
  408. at91_set_A_periph(AT91_PIN_PA16, 1);
  409. if (pins & ATMEL_SSC_RK)
  410. at91_set_B_periph(AT91_PIN_PA10, 1);
  411. if (pins & ATMEL_SSC_RF)
  412. at91_set_B_periph(AT91_PIN_PA22, 1);
  413. }
  414. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  415. static struct resource ssc1_resources[] = {
  416. [0] = {
  417. .start = AT91SAM9RL_BASE_SSC1,
  418. .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
  419. .flags = IORESOURCE_MEM,
  420. },
  421. [1] = {
  422. .start = AT91SAM9RL_ID_SSC1,
  423. .end = AT91SAM9RL_ID_SSC1,
  424. .flags = IORESOURCE_IRQ,
  425. },
  426. };
  427. static struct platform_device at91sam9rl_ssc1_device = {
  428. .name = "ssc",
  429. .id = 1,
  430. .dev = {
  431. .dma_mask = &ssc1_dmamask,
  432. .coherent_dma_mask = DMA_BIT_MASK(32),
  433. },
  434. .resource = ssc1_resources,
  435. .num_resources = ARRAY_SIZE(ssc1_resources),
  436. };
  437. static inline void configure_ssc1_pins(unsigned pins)
  438. {
  439. if (pins & ATMEL_SSC_TF)
  440. at91_set_B_periph(AT91_PIN_PA29, 1);
  441. if (pins & ATMEL_SSC_TK)
  442. at91_set_B_periph(AT91_PIN_PA30, 1);
  443. if (pins & ATMEL_SSC_TD)
  444. at91_set_B_periph(AT91_PIN_PA13, 1);
  445. if (pins & ATMEL_SSC_RD)
  446. at91_set_B_periph(AT91_PIN_PA14, 1);
  447. if (pins & ATMEL_SSC_RK)
  448. at91_set_B_periph(AT91_PIN_PA9, 1);
  449. if (pins & ATMEL_SSC_RF)
  450. at91_set_B_periph(AT91_PIN_PA8, 1);
  451. }
  452. /*
  453. * Return the device node so that board init code can use it as the
  454. * parent for the device node reflecting how it's used on this board.
  455. *
  456. * SSC controllers are accessed through library code, instead of any
  457. * kind of all-singing/all-dancing driver. For example one could be
  458. * used by a particular I2S audio codec's driver, while another one
  459. * on the same system might be used by a custom data capture driver.
  460. */
  461. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  462. {
  463. struct platform_device *pdev;
  464. /*
  465. * NOTE: caller is responsible for passing information matching
  466. * "pins" to whatever will be using each particular controller.
  467. */
  468. switch (id) {
  469. case AT91SAM9RL_ID_SSC0:
  470. pdev = &at91sam9rl_ssc0_device;
  471. configure_ssc0_pins(pins);
  472. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  473. break;
  474. case AT91SAM9RL_ID_SSC1:
  475. pdev = &at91sam9rl_ssc1_device;
  476. configure_ssc1_pins(pins);
  477. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  478. break;
  479. default:
  480. return;
  481. }
  482. platform_device_register(pdev);
  483. }
  484. #else
  485. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  486. #endif
  487. /* --------------------------------------------------------------------
  488. * UART
  489. * -------------------------------------------------------------------- */
  490. #if defined(CONFIG_SERIAL_ATMEL)
  491. static struct resource dbgu_resources[] = {
  492. [0] = {
  493. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  494. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  495. .flags = IORESOURCE_MEM,
  496. },
  497. [1] = {
  498. .start = AT91_ID_SYS,
  499. .end = AT91_ID_SYS,
  500. .flags = IORESOURCE_IRQ,
  501. },
  502. };
  503. static struct atmel_uart_data dbgu_data = {
  504. .use_dma_tx = 0,
  505. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  506. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  507. };
  508. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  509. static struct platform_device at91sam9rl_dbgu_device = {
  510. .name = "atmel_usart",
  511. .id = 0,
  512. .dev = {
  513. .dma_mask = &dbgu_dmamask,
  514. .coherent_dma_mask = DMA_BIT_MASK(32),
  515. .platform_data = &dbgu_data,
  516. },
  517. .resource = dbgu_resources,
  518. .num_resources = ARRAY_SIZE(dbgu_resources),
  519. };
  520. static inline void configure_dbgu_pins(void)
  521. {
  522. at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
  523. at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
  524. }
  525. static struct resource uart0_resources[] = {
  526. [0] = {
  527. .start = AT91SAM9RL_BASE_US0,
  528. .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
  529. .flags = IORESOURCE_MEM,
  530. },
  531. [1] = {
  532. .start = AT91SAM9RL_ID_US0,
  533. .end = AT91SAM9RL_ID_US0,
  534. .flags = IORESOURCE_IRQ,
  535. },
  536. };
  537. static struct atmel_uart_data uart0_data = {
  538. .use_dma_tx = 1,
  539. .use_dma_rx = 1,
  540. };
  541. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  542. static struct platform_device at91sam9rl_uart0_device = {
  543. .name = "atmel_usart",
  544. .id = 1,
  545. .dev = {
  546. .dma_mask = &uart0_dmamask,
  547. .coherent_dma_mask = DMA_BIT_MASK(32),
  548. .platform_data = &uart0_data,
  549. },
  550. .resource = uart0_resources,
  551. .num_resources = ARRAY_SIZE(uart0_resources),
  552. };
  553. static inline void configure_usart0_pins(unsigned pins)
  554. {
  555. at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
  556. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  557. if (pins & ATMEL_UART_RTS)
  558. at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
  559. if (pins & ATMEL_UART_CTS)
  560. at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
  561. if (pins & ATMEL_UART_DSR)
  562. at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
  563. if (pins & ATMEL_UART_DTR)
  564. at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
  565. if (pins & ATMEL_UART_DCD)
  566. at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
  567. if (pins & ATMEL_UART_RI)
  568. at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
  569. }
  570. static struct resource uart1_resources[] = {
  571. [0] = {
  572. .start = AT91SAM9RL_BASE_US1,
  573. .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
  574. .flags = IORESOURCE_MEM,
  575. },
  576. [1] = {
  577. .start = AT91SAM9RL_ID_US1,
  578. .end = AT91SAM9RL_ID_US1,
  579. .flags = IORESOURCE_IRQ,
  580. },
  581. };
  582. static struct atmel_uart_data uart1_data = {
  583. .use_dma_tx = 1,
  584. .use_dma_rx = 1,
  585. };
  586. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  587. static struct platform_device at91sam9rl_uart1_device = {
  588. .name = "atmel_usart",
  589. .id = 2,
  590. .dev = {
  591. .dma_mask = &uart1_dmamask,
  592. .coherent_dma_mask = DMA_BIT_MASK(32),
  593. .platform_data = &uart1_data,
  594. },
  595. .resource = uart1_resources,
  596. .num_resources = ARRAY_SIZE(uart1_resources),
  597. };
  598. static inline void configure_usart1_pins(unsigned pins)
  599. {
  600. at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
  601. at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
  602. if (pins & ATMEL_UART_RTS)
  603. at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
  604. if (pins & ATMEL_UART_CTS)
  605. at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
  606. }
  607. static struct resource uart2_resources[] = {
  608. [0] = {
  609. .start = AT91SAM9RL_BASE_US2,
  610. .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
  611. .flags = IORESOURCE_MEM,
  612. },
  613. [1] = {
  614. .start = AT91SAM9RL_ID_US2,
  615. .end = AT91SAM9RL_ID_US2,
  616. .flags = IORESOURCE_IRQ,
  617. },
  618. };
  619. static struct atmel_uart_data uart2_data = {
  620. .use_dma_tx = 1,
  621. .use_dma_rx = 1,
  622. };
  623. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  624. static struct platform_device at91sam9rl_uart2_device = {
  625. .name = "atmel_usart",
  626. .id = 3,
  627. .dev = {
  628. .dma_mask = &uart2_dmamask,
  629. .coherent_dma_mask = DMA_BIT_MASK(32),
  630. .platform_data = &uart2_data,
  631. },
  632. .resource = uart2_resources,
  633. .num_resources = ARRAY_SIZE(uart2_resources),
  634. };
  635. static inline void configure_usart2_pins(unsigned pins)
  636. {
  637. at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
  638. at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
  639. if (pins & ATMEL_UART_RTS)
  640. at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
  641. if (pins & ATMEL_UART_CTS)
  642. at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
  643. }
  644. static struct resource uart3_resources[] = {
  645. [0] = {
  646. .start = AT91SAM9RL_BASE_US3,
  647. .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
  648. .flags = IORESOURCE_MEM,
  649. },
  650. [1] = {
  651. .start = AT91SAM9RL_ID_US3,
  652. .end = AT91SAM9RL_ID_US3,
  653. .flags = IORESOURCE_IRQ,
  654. },
  655. };
  656. static struct atmel_uart_data uart3_data = {
  657. .use_dma_tx = 1,
  658. .use_dma_rx = 1,
  659. };
  660. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  661. static struct platform_device at91sam9rl_uart3_device = {
  662. .name = "atmel_usart",
  663. .id = 4,
  664. .dev = {
  665. .dma_mask = &uart3_dmamask,
  666. .coherent_dma_mask = DMA_BIT_MASK(32),
  667. .platform_data = &uart3_data,
  668. },
  669. .resource = uart3_resources,
  670. .num_resources = ARRAY_SIZE(uart3_resources),
  671. };
  672. static inline void configure_usart3_pins(unsigned pins)
  673. {
  674. at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
  675. at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
  676. if (pins & ATMEL_UART_RTS)
  677. at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
  678. if (pins & ATMEL_UART_CTS)
  679. at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
  680. }
  681. static struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  682. struct platform_device *atmel_default_console_device; /* the serial console device */
  683. void __init __deprecated at91_init_serial(struct at91_uart_config *config)
  684. {
  685. int i;
  686. /* Fill in list of supported UARTs */
  687. for (i = 0; i < config->nr_tty; i++) {
  688. switch (config->tty_map[i]) {
  689. case 0:
  690. configure_usart0_pins(ATMEL_UART_CTS | ATMEL_UART_RTS);
  691. at91_uarts[i] = &at91sam9rl_uart0_device;
  692. at91_clock_associate("usart0_clk", &at91sam9rl_uart0_device.dev, "usart");
  693. break;
  694. case 1:
  695. configure_usart1_pins(0);
  696. at91_uarts[i] = &at91sam9rl_uart1_device;
  697. at91_clock_associate("usart1_clk", &at91sam9rl_uart1_device.dev, "usart");
  698. break;
  699. case 2:
  700. configure_usart2_pins(0);
  701. at91_uarts[i] = &at91sam9rl_uart2_device;
  702. at91_clock_associate("usart2_clk", &at91sam9rl_uart2_device.dev, "usart");
  703. break;
  704. case 3:
  705. configure_usart3_pins(0);
  706. at91_uarts[i] = &at91sam9rl_uart3_device;
  707. at91_clock_associate("usart3_clk", &at91sam9rl_uart3_device.dev, "usart");
  708. break;
  709. case 4:
  710. configure_dbgu_pins();
  711. at91_uarts[i] = &at91sam9rl_dbgu_device;
  712. at91_clock_associate("mck", &at91sam9rl_dbgu_device.dev, "usart");
  713. break;
  714. default:
  715. continue;
  716. }
  717. at91_uarts[i]->id = i; /* update ID number to mapped ID */
  718. }
  719. /* Set serial console device */
  720. if (config->console_tty < ATMEL_MAX_UART)
  721. atmel_default_console_device = at91_uarts[config->console_tty];
  722. if (!atmel_default_console_device)
  723. printk(KERN_INFO "AT91: No default serial console defined.\n");
  724. }
  725. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  726. {
  727. struct platform_device *pdev;
  728. switch (id) {
  729. case 0: /* DBGU */
  730. pdev = &at91sam9rl_dbgu_device;
  731. configure_dbgu_pins();
  732. at91_clock_associate("mck", &pdev->dev, "usart");
  733. break;
  734. case AT91SAM9RL_ID_US0:
  735. pdev = &at91sam9rl_uart0_device;
  736. configure_usart0_pins(pins);
  737. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  738. break;
  739. case AT91SAM9RL_ID_US1:
  740. pdev = &at91sam9rl_uart1_device;
  741. configure_usart1_pins(pins);
  742. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  743. break;
  744. case AT91SAM9RL_ID_US2:
  745. pdev = &at91sam9rl_uart2_device;
  746. configure_usart2_pins(pins);
  747. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  748. break;
  749. case AT91SAM9RL_ID_US3:
  750. pdev = &at91sam9rl_uart3_device;
  751. configure_usart3_pins(pins);
  752. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  753. break;
  754. default:
  755. return;
  756. }
  757. pdev->id = portnr; /* update to mapped ID */
  758. if (portnr < ATMEL_MAX_UART)
  759. at91_uarts[portnr] = pdev;
  760. }
  761. void __init at91_set_serial_console(unsigned portnr)
  762. {
  763. if (portnr < ATMEL_MAX_UART)
  764. atmel_default_console_device = at91_uarts[portnr];
  765. if (!atmel_default_console_device)
  766. printk(KERN_INFO "AT91: No default serial console defined.\n");
  767. }
  768. void __init at91_add_device_serial(void)
  769. {
  770. int i;
  771. for (i = 0; i < ATMEL_MAX_UART; i++) {
  772. if (at91_uarts[i])
  773. platform_device_register(at91_uarts[i]);
  774. }
  775. }
  776. #else
  777. void __init __deprecated at91_init_serial(struct at91_uart_config *config) {}
  778. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  779. void __init at91_set_serial_console(unsigned portnr) {}
  780. void __init at91_add_device_serial(void) {}
  781. #endif
  782. /* -------------------------------------------------------------------- */
  783. /*
  784. * These devices are always present and don't need any board-specific
  785. * setup.
  786. */
  787. static int __init at91_add_standard_devices(void)
  788. {
  789. at91_add_device_rtc();
  790. at91_add_device_rtt();
  791. at91_add_device_watchdog();
  792. return 0;
  793. }
  794. arch_initcall(at91_add_standard_devices);