at91sam9rl_devices.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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 <mach/board.h>
  16. #include <mach/gpio.h>
  17. #include <mach/at91sam9rl.h>
  18. #include <mach/at91sam9rl_matrix.h>
  19. #include <mach/at91sam9_smc.h>
  20. #include "generic.h"
  21. /* --------------------------------------------------------------------
  22. * USB HS Device (Gadget)
  23. * -------------------------------------------------------------------- */
  24. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  25. static struct resource usba_udc_resources[] = {
  26. [0] = {
  27. .start = AT91SAM9RL_UDPHS_FIFO,
  28. .end = AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
  29. .flags = IORESOURCE_MEM,
  30. },
  31. [1] = {
  32. .start = AT91SAM9RL_BASE_UDPHS,
  33. .end = AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. [2] = {
  37. .start = AT91SAM9RL_ID_UDPHS,
  38. .end = AT91SAM9RL_ID_UDPHS,
  39. .flags = IORESOURCE_IRQ,
  40. },
  41. };
  42. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  43. [idx] = { \
  44. .name = nam, \
  45. .index = idx, \
  46. .fifo_size = maxpkt, \
  47. .nr_banks = maxbk, \
  48. .can_dma = dma, \
  49. .can_isoc = isoc, \
  50. }
  51. static struct usba_ep_data usba_udc_ep[] __initdata = {
  52. EP("ep0", 0, 64, 1, 0, 0),
  53. EP("ep1", 1, 1024, 2, 1, 1),
  54. EP("ep2", 2, 1024, 2, 1, 1),
  55. EP("ep3", 3, 1024, 3, 1, 0),
  56. EP("ep4", 4, 1024, 3, 1, 0),
  57. EP("ep5", 5, 1024, 3, 1, 1),
  58. EP("ep6", 6, 1024, 3, 1, 1),
  59. };
  60. #undef EP
  61. /*
  62. * pdata doesn't have room for any endpoints, so we need to
  63. * append room for the ones we need right after it.
  64. */
  65. static struct {
  66. struct usba_platform_data pdata;
  67. struct usba_ep_data ep[7];
  68. } usba_udc_data;
  69. static struct platform_device at91_usba_udc_device = {
  70. .name = "atmel_usba_udc",
  71. .id = -1,
  72. .dev = {
  73. .platform_data = &usba_udc_data.pdata,
  74. },
  75. .resource = usba_udc_resources,
  76. .num_resources = ARRAY_SIZE(usba_udc_resources),
  77. };
  78. void __init at91_add_device_usba(struct usba_platform_data *data)
  79. {
  80. /*
  81. * Invalid pins are 0 on AT91, but the usba driver is shared
  82. * with AVR32, which use negative values instead. Once/if
  83. * gpio_is_valid() is ported to AT91, revisit this code.
  84. */
  85. usba_udc_data.pdata.vbus_pin = -EINVAL;
  86. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  87. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  88. if (data && data->vbus_pin > 0) {
  89. at91_set_gpio_input(data->vbus_pin, 0);
  90. at91_set_deglitch(data->vbus_pin, 1);
  91. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  92. }
  93. /* Pullup pin is handled internally by USB device peripheral */
  94. /* Clocks */
  95. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  96. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  97. platform_device_register(&at91_usba_udc_device);
  98. }
  99. #else
  100. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  101. #endif
  102. /* --------------------------------------------------------------------
  103. * MMC / SD
  104. * -------------------------------------------------------------------- */
  105. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  106. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  107. static struct at91_mmc_data mmc_data;
  108. static struct resource mmc_resources[] = {
  109. [0] = {
  110. .start = AT91SAM9RL_BASE_MCI,
  111. .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
  112. .flags = IORESOURCE_MEM,
  113. },
  114. [1] = {
  115. .start = AT91SAM9RL_ID_MCI,
  116. .end = AT91SAM9RL_ID_MCI,
  117. .flags = IORESOURCE_IRQ,
  118. },
  119. };
  120. static struct platform_device at91sam9rl_mmc_device = {
  121. .name = "at91_mci",
  122. .id = -1,
  123. .dev = {
  124. .dma_mask = &mmc_dmamask,
  125. .coherent_dma_mask = DMA_BIT_MASK(32),
  126. .platform_data = &mmc_data,
  127. },
  128. .resource = mmc_resources,
  129. .num_resources = ARRAY_SIZE(mmc_resources),
  130. };
  131. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  132. {
  133. if (!data)
  134. return;
  135. /* input/irq */
  136. if (data->det_pin) {
  137. at91_set_gpio_input(data->det_pin, 1);
  138. at91_set_deglitch(data->det_pin, 1);
  139. }
  140. if (data->wp_pin)
  141. at91_set_gpio_input(data->wp_pin, 1);
  142. if (data->vcc_pin)
  143. at91_set_gpio_output(data->vcc_pin, 0);
  144. /* CLK */
  145. at91_set_A_periph(AT91_PIN_PA2, 0);
  146. /* CMD */
  147. at91_set_A_periph(AT91_PIN_PA1, 1);
  148. /* DAT0, maybe DAT1..DAT3 */
  149. at91_set_A_periph(AT91_PIN_PA0, 1);
  150. if (data->wire4) {
  151. at91_set_A_periph(AT91_PIN_PA3, 1);
  152. at91_set_A_periph(AT91_PIN_PA4, 1);
  153. at91_set_A_periph(AT91_PIN_PA5, 1);
  154. }
  155. mmc_data = *data;
  156. platform_device_register(&at91sam9rl_mmc_device);
  157. }
  158. #else
  159. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  160. #endif
  161. /* --------------------------------------------------------------------
  162. * NAND / SmartMedia
  163. * -------------------------------------------------------------------- */
  164. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  165. static struct atmel_nand_data nand_data;
  166. #define NAND_BASE AT91_CHIPSELECT_3
  167. static struct resource nand_resources[] = {
  168. [0] = {
  169. .start = NAND_BASE,
  170. .end = NAND_BASE + SZ_256M - 1,
  171. .flags = IORESOURCE_MEM,
  172. },
  173. [1] = {
  174. .start = AT91_BASE_SYS + AT91_ECC,
  175. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  176. .flags = IORESOURCE_MEM,
  177. }
  178. };
  179. static struct platform_device atmel_nand_device = {
  180. .name = "atmel_nand",
  181. .id = -1,
  182. .dev = {
  183. .platform_data = &nand_data,
  184. },
  185. .resource = nand_resources,
  186. .num_resources = ARRAY_SIZE(nand_resources),
  187. };
  188. void __init at91_add_device_nand(struct atmel_nand_data *data)
  189. {
  190. unsigned long csa;
  191. if (!data)
  192. return;
  193. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  194. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  195. /* enable pin */
  196. if (data->enable_pin)
  197. at91_set_gpio_output(data->enable_pin, 1);
  198. /* ready/busy pin */
  199. if (data->rdy_pin)
  200. at91_set_gpio_input(data->rdy_pin, 1);
  201. /* card detect pin */
  202. if (data->det_pin)
  203. at91_set_gpio_input(data->det_pin, 1);
  204. at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
  205. at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
  206. nand_data = *data;
  207. platform_device_register(&atmel_nand_device);
  208. }
  209. #else
  210. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  211. #endif
  212. /* --------------------------------------------------------------------
  213. * TWI (i2c)
  214. * -------------------------------------------------------------------- */
  215. /*
  216. * Prefer the GPIO code since the TWI controller isn't robust
  217. * (gets overruns and underruns under load) and can only issue
  218. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  219. */
  220. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  221. static struct i2c_gpio_platform_data pdata = {
  222. .sda_pin = AT91_PIN_PA23,
  223. .sda_is_open_drain = 1,
  224. .scl_pin = AT91_PIN_PA24,
  225. .scl_is_open_drain = 1,
  226. .udelay = 2, /* ~100 kHz */
  227. };
  228. static struct platform_device at91sam9rl_twi_device = {
  229. .name = "i2c-gpio",
  230. .id = -1,
  231. .dev.platform_data = &pdata,
  232. };
  233. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  234. {
  235. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  236. at91_set_multi_drive(AT91_PIN_PA23, 1);
  237. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  238. at91_set_multi_drive(AT91_PIN_PA24, 1);
  239. i2c_register_board_info(0, devices, nr_devices);
  240. platform_device_register(&at91sam9rl_twi_device);
  241. }
  242. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  243. static struct resource twi_resources[] = {
  244. [0] = {
  245. .start = AT91SAM9RL_BASE_TWI0,
  246. .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
  247. .flags = IORESOURCE_MEM,
  248. },
  249. [1] = {
  250. .start = AT91SAM9RL_ID_TWI0,
  251. .end = AT91SAM9RL_ID_TWI0,
  252. .flags = IORESOURCE_IRQ,
  253. },
  254. };
  255. static struct platform_device at91sam9rl_twi_device = {
  256. .name = "at91_i2c",
  257. .id = -1,
  258. .resource = twi_resources,
  259. .num_resources = ARRAY_SIZE(twi_resources),
  260. };
  261. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  262. {
  263. /* pins used for TWI interface */
  264. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  265. at91_set_multi_drive(AT91_PIN_PA23, 1);
  266. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  267. at91_set_multi_drive(AT91_PIN_PA24, 1);
  268. i2c_register_board_info(0, devices, nr_devices);
  269. platform_device_register(&at91sam9rl_twi_device);
  270. }
  271. #else
  272. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  273. #endif
  274. /* --------------------------------------------------------------------
  275. * SPI
  276. * -------------------------------------------------------------------- */
  277. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  278. static u64 spi_dmamask = DMA_BIT_MASK(32);
  279. static struct resource spi_resources[] = {
  280. [0] = {
  281. .start = AT91SAM9RL_BASE_SPI,
  282. .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
  283. .flags = IORESOURCE_MEM,
  284. },
  285. [1] = {
  286. .start = AT91SAM9RL_ID_SPI,
  287. .end = AT91SAM9RL_ID_SPI,
  288. .flags = IORESOURCE_IRQ,
  289. },
  290. };
  291. static struct platform_device at91sam9rl_spi_device = {
  292. .name = "atmel_spi",
  293. .id = 0,
  294. .dev = {
  295. .dma_mask = &spi_dmamask,
  296. .coherent_dma_mask = DMA_BIT_MASK(32),
  297. },
  298. .resource = spi_resources,
  299. .num_resources = ARRAY_SIZE(spi_resources),
  300. };
  301. static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
  302. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  303. {
  304. int i;
  305. unsigned long cs_pin;
  306. at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
  307. at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
  308. at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
  309. /* Enable SPI chip-selects */
  310. for (i = 0; i < nr_devices; i++) {
  311. if (devices[i].controller_data)
  312. cs_pin = (unsigned long) devices[i].controller_data;
  313. else
  314. cs_pin = spi_standard_cs[devices[i].chip_select];
  315. /* enable chip-select pin */
  316. at91_set_gpio_output(cs_pin, 1);
  317. /* pass chip-select pin to driver */
  318. devices[i].controller_data = (void *) cs_pin;
  319. }
  320. spi_register_board_info(devices, nr_devices);
  321. platform_device_register(&at91sam9rl_spi_device);
  322. }
  323. #else
  324. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  325. #endif
  326. /* --------------------------------------------------------------------
  327. * LCD Controller
  328. * -------------------------------------------------------------------- */
  329. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  330. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  331. static struct atmel_lcdfb_info lcdc_data;
  332. static struct resource lcdc_resources[] = {
  333. [0] = {
  334. .start = AT91SAM9RL_LCDC_BASE,
  335. .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
  336. .flags = IORESOURCE_MEM,
  337. },
  338. [1] = {
  339. .start = AT91SAM9RL_ID_LCDC,
  340. .end = AT91SAM9RL_ID_LCDC,
  341. .flags = IORESOURCE_IRQ,
  342. },
  343. };
  344. static struct platform_device at91_lcdc_device = {
  345. .name = "atmel_lcdfb",
  346. .id = 0,
  347. .dev = {
  348. .dma_mask = &lcdc_dmamask,
  349. .coherent_dma_mask = DMA_BIT_MASK(32),
  350. .platform_data = &lcdc_data,
  351. },
  352. .resource = lcdc_resources,
  353. .num_resources = ARRAY_SIZE(lcdc_resources),
  354. };
  355. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  356. {
  357. if (!data) {
  358. return;
  359. }
  360. at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
  361. at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
  362. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
  363. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
  364. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
  365. at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
  366. at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
  367. at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
  368. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
  369. at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
  370. at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  371. at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  372. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  373. at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  374. at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  375. at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
  376. at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
  377. at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
  378. at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
  379. at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
  380. at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
  381. lcdc_data = *data;
  382. platform_device_register(&at91_lcdc_device);
  383. }
  384. #else
  385. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  386. #endif
  387. /* --------------------------------------------------------------------
  388. * Timer/Counter block
  389. * -------------------------------------------------------------------- */
  390. #ifdef CONFIG_ATMEL_TCLIB
  391. static struct resource tcb_resources[] = {
  392. [0] = {
  393. .start = AT91SAM9RL_BASE_TCB0,
  394. .end = AT91SAM9RL_BASE_TCB0 + SZ_16K - 1,
  395. .flags = IORESOURCE_MEM,
  396. },
  397. [1] = {
  398. .start = AT91SAM9RL_ID_TC0,
  399. .end = AT91SAM9RL_ID_TC0,
  400. .flags = IORESOURCE_IRQ,
  401. },
  402. [2] = {
  403. .start = AT91SAM9RL_ID_TC1,
  404. .end = AT91SAM9RL_ID_TC1,
  405. .flags = IORESOURCE_IRQ,
  406. },
  407. [3] = {
  408. .start = AT91SAM9RL_ID_TC2,
  409. .end = AT91SAM9RL_ID_TC2,
  410. .flags = IORESOURCE_IRQ,
  411. },
  412. };
  413. static struct platform_device at91sam9rl_tcb_device = {
  414. .name = "atmel_tcb",
  415. .id = 0,
  416. .resource = tcb_resources,
  417. .num_resources = ARRAY_SIZE(tcb_resources),
  418. };
  419. static void __init at91_add_device_tc(void)
  420. {
  421. /* this chip has a separate clock and irq for each TC channel */
  422. at91_clock_associate("tc0_clk", &at91sam9rl_tcb_device.dev, "t0_clk");
  423. at91_clock_associate("tc1_clk", &at91sam9rl_tcb_device.dev, "t1_clk");
  424. at91_clock_associate("tc2_clk", &at91sam9rl_tcb_device.dev, "t2_clk");
  425. platform_device_register(&at91sam9rl_tcb_device);
  426. }
  427. #else
  428. static void __init at91_add_device_tc(void) { }
  429. #endif
  430. /* --------------------------------------------------------------------
  431. * Touchscreen
  432. * -------------------------------------------------------------------- */
  433. #if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE)
  434. static u64 tsadcc_dmamask = DMA_BIT_MASK(32);
  435. static struct resource tsadcc_resources[] = {
  436. [0] = {
  437. .start = AT91SAM9RL_BASE_TSC,
  438. .end = AT91SAM9RL_BASE_TSC + SZ_16K - 1,
  439. .flags = IORESOURCE_MEM,
  440. },
  441. [1] = {
  442. .start = AT91SAM9RL_ID_TSC,
  443. .end = AT91SAM9RL_ID_TSC,
  444. .flags = IORESOURCE_IRQ,
  445. }
  446. };
  447. static struct platform_device at91sam9rl_tsadcc_device = {
  448. .name = "atmel_tsadcc",
  449. .id = -1,
  450. .dev = {
  451. .dma_mask = &tsadcc_dmamask,
  452. .coherent_dma_mask = DMA_BIT_MASK(32),
  453. },
  454. .resource = tsadcc_resources,
  455. .num_resources = ARRAY_SIZE(tsadcc_resources),
  456. };
  457. void __init at91_add_device_tsadcc(void)
  458. {
  459. at91_set_A_periph(AT91_PIN_PA17, 0); /* AD0_XR */
  460. at91_set_A_periph(AT91_PIN_PA18, 0); /* AD1_XL */
  461. at91_set_A_periph(AT91_PIN_PA19, 0); /* AD2_YT */
  462. at91_set_A_periph(AT91_PIN_PA20, 0); /* AD3_TB */
  463. platform_device_register(&at91sam9rl_tsadcc_device);
  464. }
  465. #else
  466. void __init at91_add_device_tsadcc(void) {}
  467. #endif
  468. /* --------------------------------------------------------------------
  469. * RTC
  470. * -------------------------------------------------------------------- */
  471. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  472. static struct platform_device at91sam9rl_rtc_device = {
  473. .name = "at91_rtc",
  474. .id = -1,
  475. .num_resources = 0,
  476. };
  477. static void __init at91_add_device_rtc(void)
  478. {
  479. platform_device_register(&at91sam9rl_rtc_device);
  480. }
  481. #else
  482. static void __init at91_add_device_rtc(void) {}
  483. #endif
  484. /* --------------------------------------------------------------------
  485. * RTT
  486. * -------------------------------------------------------------------- */
  487. static struct resource rtt_resources[] = {
  488. {
  489. .start = AT91_BASE_SYS + AT91_RTT,
  490. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  491. .flags = IORESOURCE_MEM,
  492. }
  493. };
  494. static struct platform_device at91sam9rl_rtt_device = {
  495. .name = "at91_rtt",
  496. .id = 0,
  497. .resource = rtt_resources,
  498. .num_resources = ARRAY_SIZE(rtt_resources),
  499. };
  500. static void __init at91_add_device_rtt(void)
  501. {
  502. platform_device_register(&at91sam9rl_rtt_device);
  503. }
  504. /* --------------------------------------------------------------------
  505. * Watchdog
  506. * -------------------------------------------------------------------- */
  507. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  508. static struct platform_device at91sam9rl_wdt_device = {
  509. .name = "at91_wdt",
  510. .id = -1,
  511. .num_resources = 0,
  512. };
  513. static void __init at91_add_device_watchdog(void)
  514. {
  515. platform_device_register(&at91sam9rl_wdt_device);
  516. }
  517. #else
  518. static void __init at91_add_device_watchdog(void) {}
  519. #endif
  520. /* --------------------------------------------------------------------
  521. * PWM
  522. * --------------------------------------------------------------------*/
  523. #if defined(CONFIG_ATMEL_PWM)
  524. static u32 pwm_mask;
  525. static struct resource pwm_resources[] = {
  526. [0] = {
  527. .start = AT91SAM9RL_BASE_PWMC,
  528. .end = AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
  529. .flags = IORESOURCE_MEM,
  530. },
  531. [1] = {
  532. .start = AT91SAM9RL_ID_PWMC,
  533. .end = AT91SAM9RL_ID_PWMC,
  534. .flags = IORESOURCE_IRQ,
  535. },
  536. };
  537. static struct platform_device at91sam9rl_pwm0_device = {
  538. .name = "atmel_pwm",
  539. .id = -1,
  540. .dev = {
  541. .platform_data = &pwm_mask,
  542. },
  543. .resource = pwm_resources,
  544. .num_resources = ARRAY_SIZE(pwm_resources),
  545. };
  546. void __init at91_add_device_pwm(u32 mask)
  547. {
  548. if (mask & (1 << AT91_PWM0))
  549. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM0 */
  550. if (mask & (1 << AT91_PWM1))
  551. at91_set_B_periph(AT91_PIN_PB9, 1); /* enable PWM1 */
  552. if (mask & (1 << AT91_PWM2))
  553. at91_set_B_periph(AT91_PIN_PD5, 1); /* enable PWM2 */
  554. if (mask & (1 << AT91_PWM3))
  555. at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */
  556. pwm_mask = mask;
  557. platform_device_register(&at91sam9rl_pwm0_device);
  558. }
  559. #else
  560. void __init at91_add_device_pwm(u32 mask) {}
  561. #endif
  562. /* --------------------------------------------------------------------
  563. * SSC -- Synchronous Serial Controller
  564. * -------------------------------------------------------------------- */
  565. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  566. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  567. static struct resource ssc0_resources[] = {
  568. [0] = {
  569. .start = AT91SAM9RL_BASE_SSC0,
  570. .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
  571. .flags = IORESOURCE_MEM,
  572. },
  573. [1] = {
  574. .start = AT91SAM9RL_ID_SSC0,
  575. .end = AT91SAM9RL_ID_SSC0,
  576. .flags = IORESOURCE_IRQ,
  577. },
  578. };
  579. static struct platform_device at91sam9rl_ssc0_device = {
  580. .name = "ssc",
  581. .id = 0,
  582. .dev = {
  583. .dma_mask = &ssc0_dmamask,
  584. .coherent_dma_mask = DMA_BIT_MASK(32),
  585. },
  586. .resource = ssc0_resources,
  587. .num_resources = ARRAY_SIZE(ssc0_resources),
  588. };
  589. static inline void configure_ssc0_pins(unsigned pins)
  590. {
  591. if (pins & ATMEL_SSC_TF)
  592. at91_set_A_periph(AT91_PIN_PC0, 1);
  593. if (pins & ATMEL_SSC_TK)
  594. at91_set_A_periph(AT91_PIN_PC1, 1);
  595. if (pins & ATMEL_SSC_TD)
  596. at91_set_A_periph(AT91_PIN_PA15, 1);
  597. if (pins & ATMEL_SSC_RD)
  598. at91_set_A_periph(AT91_PIN_PA16, 1);
  599. if (pins & ATMEL_SSC_RK)
  600. at91_set_B_periph(AT91_PIN_PA10, 1);
  601. if (pins & ATMEL_SSC_RF)
  602. at91_set_B_periph(AT91_PIN_PA22, 1);
  603. }
  604. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  605. static struct resource ssc1_resources[] = {
  606. [0] = {
  607. .start = AT91SAM9RL_BASE_SSC1,
  608. .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
  609. .flags = IORESOURCE_MEM,
  610. },
  611. [1] = {
  612. .start = AT91SAM9RL_ID_SSC1,
  613. .end = AT91SAM9RL_ID_SSC1,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. };
  617. static struct platform_device at91sam9rl_ssc1_device = {
  618. .name = "ssc",
  619. .id = 1,
  620. .dev = {
  621. .dma_mask = &ssc1_dmamask,
  622. .coherent_dma_mask = DMA_BIT_MASK(32),
  623. },
  624. .resource = ssc1_resources,
  625. .num_resources = ARRAY_SIZE(ssc1_resources),
  626. };
  627. static inline void configure_ssc1_pins(unsigned pins)
  628. {
  629. if (pins & ATMEL_SSC_TF)
  630. at91_set_B_periph(AT91_PIN_PA29, 1);
  631. if (pins & ATMEL_SSC_TK)
  632. at91_set_B_periph(AT91_PIN_PA30, 1);
  633. if (pins & ATMEL_SSC_TD)
  634. at91_set_B_periph(AT91_PIN_PA13, 1);
  635. if (pins & ATMEL_SSC_RD)
  636. at91_set_B_periph(AT91_PIN_PA14, 1);
  637. if (pins & ATMEL_SSC_RK)
  638. at91_set_B_periph(AT91_PIN_PA9, 1);
  639. if (pins & ATMEL_SSC_RF)
  640. at91_set_B_periph(AT91_PIN_PA8, 1);
  641. }
  642. /*
  643. * SSC controllers are accessed through library code, instead of any
  644. * kind of all-singing/all-dancing driver. For example one could be
  645. * used by a particular I2S audio codec's driver, while another one
  646. * on the same system might be used by a custom data capture driver.
  647. */
  648. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  649. {
  650. struct platform_device *pdev;
  651. /*
  652. * NOTE: caller is responsible for passing information matching
  653. * "pins" to whatever will be using each particular controller.
  654. */
  655. switch (id) {
  656. case AT91SAM9RL_ID_SSC0:
  657. pdev = &at91sam9rl_ssc0_device;
  658. configure_ssc0_pins(pins);
  659. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  660. break;
  661. case AT91SAM9RL_ID_SSC1:
  662. pdev = &at91sam9rl_ssc1_device;
  663. configure_ssc1_pins(pins);
  664. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  665. break;
  666. default:
  667. return;
  668. }
  669. platform_device_register(pdev);
  670. }
  671. #else
  672. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  673. #endif
  674. /* --------------------------------------------------------------------
  675. * UART
  676. * -------------------------------------------------------------------- */
  677. #if defined(CONFIG_SERIAL_ATMEL)
  678. static struct resource dbgu_resources[] = {
  679. [0] = {
  680. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  681. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  682. .flags = IORESOURCE_MEM,
  683. },
  684. [1] = {
  685. .start = AT91_ID_SYS,
  686. .end = AT91_ID_SYS,
  687. .flags = IORESOURCE_IRQ,
  688. },
  689. };
  690. static struct atmel_uart_data dbgu_data = {
  691. .use_dma_tx = 0,
  692. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  693. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  694. };
  695. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  696. static struct platform_device at91sam9rl_dbgu_device = {
  697. .name = "atmel_usart",
  698. .id = 0,
  699. .dev = {
  700. .dma_mask = &dbgu_dmamask,
  701. .coherent_dma_mask = DMA_BIT_MASK(32),
  702. .platform_data = &dbgu_data,
  703. },
  704. .resource = dbgu_resources,
  705. .num_resources = ARRAY_SIZE(dbgu_resources),
  706. };
  707. static inline void configure_dbgu_pins(void)
  708. {
  709. at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
  710. at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
  711. }
  712. static struct resource uart0_resources[] = {
  713. [0] = {
  714. .start = AT91SAM9RL_BASE_US0,
  715. .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
  716. .flags = IORESOURCE_MEM,
  717. },
  718. [1] = {
  719. .start = AT91SAM9RL_ID_US0,
  720. .end = AT91SAM9RL_ID_US0,
  721. .flags = IORESOURCE_IRQ,
  722. },
  723. };
  724. static struct atmel_uart_data uart0_data = {
  725. .use_dma_tx = 1,
  726. .use_dma_rx = 1,
  727. };
  728. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  729. static struct platform_device at91sam9rl_uart0_device = {
  730. .name = "atmel_usart",
  731. .id = 1,
  732. .dev = {
  733. .dma_mask = &uart0_dmamask,
  734. .coherent_dma_mask = DMA_BIT_MASK(32),
  735. .platform_data = &uart0_data,
  736. },
  737. .resource = uart0_resources,
  738. .num_resources = ARRAY_SIZE(uart0_resources),
  739. };
  740. static inline void configure_usart0_pins(unsigned pins)
  741. {
  742. at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
  743. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  744. if (pins & ATMEL_UART_RTS)
  745. at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
  746. if (pins & ATMEL_UART_CTS)
  747. at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
  748. if (pins & ATMEL_UART_DSR)
  749. at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
  750. if (pins & ATMEL_UART_DTR)
  751. at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
  752. if (pins & ATMEL_UART_DCD)
  753. at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
  754. if (pins & ATMEL_UART_RI)
  755. at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
  756. }
  757. static struct resource uart1_resources[] = {
  758. [0] = {
  759. .start = AT91SAM9RL_BASE_US1,
  760. .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
  761. .flags = IORESOURCE_MEM,
  762. },
  763. [1] = {
  764. .start = AT91SAM9RL_ID_US1,
  765. .end = AT91SAM9RL_ID_US1,
  766. .flags = IORESOURCE_IRQ,
  767. },
  768. };
  769. static struct atmel_uart_data uart1_data = {
  770. .use_dma_tx = 1,
  771. .use_dma_rx = 1,
  772. };
  773. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  774. static struct platform_device at91sam9rl_uart1_device = {
  775. .name = "atmel_usart",
  776. .id = 2,
  777. .dev = {
  778. .dma_mask = &uart1_dmamask,
  779. .coherent_dma_mask = DMA_BIT_MASK(32),
  780. .platform_data = &uart1_data,
  781. },
  782. .resource = uart1_resources,
  783. .num_resources = ARRAY_SIZE(uart1_resources),
  784. };
  785. static inline void configure_usart1_pins(unsigned pins)
  786. {
  787. at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
  788. at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
  789. if (pins & ATMEL_UART_RTS)
  790. at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
  791. if (pins & ATMEL_UART_CTS)
  792. at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
  793. }
  794. static struct resource uart2_resources[] = {
  795. [0] = {
  796. .start = AT91SAM9RL_BASE_US2,
  797. .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
  798. .flags = IORESOURCE_MEM,
  799. },
  800. [1] = {
  801. .start = AT91SAM9RL_ID_US2,
  802. .end = AT91SAM9RL_ID_US2,
  803. .flags = IORESOURCE_IRQ,
  804. },
  805. };
  806. static struct atmel_uart_data uart2_data = {
  807. .use_dma_tx = 1,
  808. .use_dma_rx = 1,
  809. };
  810. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  811. static struct platform_device at91sam9rl_uart2_device = {
  812. .name = "atmel_usart",
  813. .id = 3,
  814. .dev = {
  815. .dma_mask = &uart2_dmamask,
  816. .coherent_dma_mask = DMA_BIT_MASK(32),
  817. .platform_data = &uart2_data,
  818. },
  819. .resource = uart2_resources,
  820. .num_resources = ARRAY_SIZE(uart2_resources),
  821. };
  822. static inline void configure_usart2_pins(unsigned pins)
  823. {
  824. at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
  825. at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
  826. if (pins & ATMEL_UART_RTS)
  827. at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
  828. if (pins & ATMEL_UART_CTS)
  829. at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
  830. }
  831. static struct resource uart3_resources[] = {
  832. [0] = {
  833. .start = AT91SAM9RL_BASE_US3,
  834. .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
  835. .flags = IORESOURCE_MEM,
  836. },
  837. [1] = {
  838. .start = AT91SAM9RL_ID_US3,
  839. .end = AT91SAM9RL_ID_US3,
  840. .flags = IORESOURCE_IRQ,
  841. },
  842. };
  843. static struct atmel_uart_data uart3_data = {
  844. .use_dma_tx = 1,
  845. .use_dma_rx = 1,
  846. };
  847. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  848. static struct platform_device at91sam9rl_uart3_device = {
  849. .name = "atmel_usart",
  850. .id = 4,
  851. .dev = {
  852. .dma_mask = &uart3_dmamask,
  853. .coherent_dma_mask = DMA_BIT_MASK(32),
  854. .platform_data = &uart3_data,
  855. },
  856. .resource = uart3_resources,
  857. .num_resources = ARRAY_SIZE(uart3_resources),
  858. };
  859. static inline void configure_usart3_pins(unsigned pins)
  860. {
  861. at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
  862. at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
  863. if (pins & ATMEL_UART_RTS)
  864. at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
  865. if (pins & ATMEL_UART_CTS)
  866. at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
  867. }
  868. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  869. struct platform_device *atmel_default_console_device; /* the serial console device */
  870. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  871. {
  872. struct platform_device *pdev;
  873. switch (id) {
  874. case 0: /* DBGU */
  875. pdev = &at91sam9rl_dbgu_device;
  876. configure_dbgu_pins();
  877. at91_clock_associate("mck", &pdev->dev, "usart");
  878. break;
  879. case AT91SAM9RL_ID_US0:
  880. pdev = &at91sam9rl_uart0_device;
  881. configure_usart0_pins(pins);
  882. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  883. break;
  884. case AT91SAM9RL_ID_US1:
  885. pdev = &at91sam9rl_uart1_device;
  886. configure_usart1_pins(pins);
  887. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  888. break;
  889. case AT91SAM9RL_ID_US2:
  890. pdev = &at91sam9rl_uart2_device;
  891. configure_usart2_pins(pins);
  892. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  893. break;
  894. case AT91SAM9RL_ID_US3:
  895. pdev = &at91sam9rl_uart3_device;
  896. configure_usart3_pins(pins);
  897. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  898. break;
  899. default:
  900. return;
  901. }
  902. pdev->id = portnr; /* update to mapped ID */
  903. if (portnr < ATMEL_MAX_UART)
  904. at91_uarts[portnr] = pdev;
  905. }
  906. void __init at91_set_serial_console(unsigned portnr)
  907. {
  908. if (portnr < ATMEL_MAX_UART)
  909. atmel_default_console_device = at91_uarts[portnr];
  910. }
  911. void __init at91_add_device_serial(void)
  912. {
  913. int i;
  914. for (i = 0; i < ATMEL_MAX_UART; i++) {
  915. if (at91_uarts[i])
  916. platform_device_register(at91_uarts[i]);
  917. }
  918. if (!atmel_default_console_device)
  919. printk(KERN_INFO "AT91: No default serial console defined.\n");
  920. }
  921. #else
  922. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  923. void __init at91_set_serial_console(unsigned portnr) {}
  924. void __init at91_add_device_serial(void) {}
  925. #endif
  926. /* -------------------------------------------------------------------- */
  927. /*
  928. * These devices are always present and don't need any board-specific
  929. * setup.
  930. */
  931. static int __init at91_add_standard_devices(void)
  932. {
  933. at91_add_device_rtc();
  934. at91_add_device_rtt();
  935. at91_add_device_watchdog();
  936. at91_add_device_tc();
  937. return 0;
  938. }
  939. arch_initcall(at91_add_standard_devices);