at91sam9rl_devices.c 32 KB

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