at91sam9rl_devices.c 25 KB

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