at91sam9rl_devices.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 IS_ENABLED(CONFIG_PWM_ATMEL)
  675. static struct resource pwm_resources[] = {
  676. [0] = {
  677. .start = AT91SAM9RL_BASE_PWMC,
  678. .end = AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
  679. .flags = IORESOURCE_MEM,
  680. },
  681. [1] = {
  682. .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_PWMC,
  683. .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_PWMC,
  684. .flags = IORESOURCE_IRQ,
  685. },
  686. };
  687. static struct platform_device at91sam9rl_pwm0_device = {
  688. .name = "at91sam9rl-pwm",
  689. .id = -1,
  690. .resource = pwm_resources,
  691. .num_resources = ARRAY_SIZE(pwm_resources),
  692. };
  693. void __init at91_add_device_pwm(u32 mask)
  694. {
  695. if (mask & (1 << AT91_PWM0))
  696. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM0 */
  697. if (mask & (1 << AT91_PWM1))
  698. at91_set_B_periph(AT91_PIN_PB9, 1); /* enable PWM1 */
  699. if (mask & (1 << AT91_PWM2))
  700. at91_set_B_periph(AT91_PIN_PD5, 1); /* enable PWM2 */
  701. if (mask & (1 << AT91_PWM3))
  702. at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */
  703. platform_device_register(&at91sam9rl_pwm0_device);
  704. }
  705. #else
  706. void __init at91_add_device_pwm(u32 mask) {}
  707. #endif
  708. /* --------------------------------------------------------------------
  709. * SSC -- Synchronous Serial Controller
  710. * -------------------------------------------------------------------- */
  711. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  712. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  713. static struct resource ssc0_resources[] = {
  714. [0] = {
  715. .start = AT91SAM9RL_BASE_SSC0,
  716. .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
  717. .flags = IORESOURCE_MEM,
  718. },
  719. [1] = {
  720. .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC0,
  721. .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC0,
  722. .flags = IORESOURCE_IRQ,
  723. },
  724. };
  725. static struct platform_device at91sam9rl_ssc0_device = {
  726. .name = "at91rm9200_ssc",
  727. .id = 0,
  728. .dev = {
  729. .dma_mask = &ssc0_dmamask,
  730. .coherent_dma_mask = DMA_BIT_MASK(32),
  731. },
  732. .resource = ssc0_resources,
  733. .num_resources = ARRAY_SIZE(ssc0_resources),
  734. };
  735. static inline void configure_ssc0_pins(unsigned pins)
  736. {
  737. if (pins & ATMEL_SSC_TF)
  738. at91_set_A_periph(AT91_PIN_PC0, 1);
  739. if (pins & ATMEL_SSC_TK)
  740. at91_set_A_periph(AT91_PIN_PC1, 1);
  741. if (pins & ATMEL_SSC_TD)
  742. at91_set_A_periph(AT91_PIN_PA15, 1);
  743. if (pins & ATMEL_SSC_RD)
  744. at91_set_A_periph(AT91_PIN_PA16, 1);
  745. if (pins & ATMEL_SSC_RK)
  746. at91_set_B_periph(AT91_PIN_PA10, 1);
  747. if (pins & ATMEL_SSC_RF)
  748. at91_set_B_periph(AT91_PIN_PA22, 1);
  749. }
  750. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  751. static struct resource ssc1_resources[] = {
  752. [0] = {
  753. .start = AT91SAM9RL_BASE_SSC1,
  754. .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
  755. .flags = IORESOURCE_MEM,
  756. },
  757. [1] = {
  758. .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC1,
  759. .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC1,
  760. .flags = IORESOURCE_IRQ,
  761. },
  762. };
  763. static struct platform_device at91sam9rl_ssc1_device = {
  764. .name = "at91rm9200_ssc",
  765. .id = 1,
  766. .dev = {
  767. .dma_mask = &ssc1_dmamask,
  768. .coherent_dma_mask = DMA_BIT_MASK(32),
  769. },
  770. .resource = ssc1_resources,
  771. .num_resources = ARRAY_SIZE(ssc1_resources),
  772. };
  773. static inline void configure_ssc1_pins(unsigned pins)
  774. {
  775. if (pins & ATMEL_SSC_TF)
  776. at91_set_B_periph(AT91_PIN_PA29, 1);
  777. if (pins & ATMEL_SSC_TK)
  778. at91_set_B_periph(AT91_PIN_PA30, 1);
  779. if (pins & ATMEL_SSC_TD)
  780. at91_set_B_periph(AT91_PIN_PA13, 1);
  781. if (pins & ATMEL_SSC_RD)
  782. at91_set_B_periph(AT91_PIN_PA14, 1);
  783. if (pins & ATMEL_SSC_RK)
  784. at91_set_B_periph(AT91_PIN_PA9, 1);
  785. if (pins & ATMEL_SSC_RF)
  786. at91_set_B_periph(AT91_PIN_PA8, 1);
  787. }
  788. /*
  789. * SSC controllers are accessed through library code, instead of any
  790. * kind of all-singing/all-dancing driver. For example one could be
  791. * used by a particular I2S audio codec's driver, while another one
  792. * on the same system might be used by a custom data capture driver.
  793. */
  794. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  795. {
  796. struct platform_device *pdev;
  797. /*
  798. * NOTE: caller is responsible for passing information matching
  799. * "pins" to whatever will be using each particular controller.
  800. */
  801. switch (id) {
  802. case AT91SAM9RL_ID_SSC0:
  803. pdev = &at91sam9rl_ssc0_device;
  804. configure_ssc0_pins(pins);
  805. break;
  806. case AT91SAM9RL_ID_SSC1:
  807. pdev = &at91sam9rl_ssc1_device;
  808. configure_ssc1_pins(pins);
  809. break;
  810. default:
  811. return;
  812. }
  813. platform_device_register(pdev);
  814. }
  815. #else
  816. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  817. #endif
  818. /* --------------------------------------------------------------------
  819. * UART
  820. * -------------------------------------------------------------------- */
  821. #if defined(CONFIG_SERIAL_ATMEL)
  822. static struct resource dbgu_resources[] = {
  823. [0] = {
  824. .start = AT91SAM9RL_BASE_DBGU,
  825. .end = AT91SAM9RL_BASE_DBGU + SZ_512 - 1,
  826. .flags = IORESOURCE_MEM,
  827. },
  828. [1] = {
  829. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  830. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  831. .flags = IORESOURCE_IRQ,
  832. },
  833. };
  834. static struct atmel_uart_data dbgu_data = {
  835. .use_dma_tx = 0,
  836. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  837. };
  838. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  839. static struct platform_device at91sam9rl_dbgu_device = {
  840. .name = "atmel_usart",
  841. .id = 0,
  842. .dev = {
  843. .dma_mask = &dbgu_dmamask,
  844. .coherent_dma_mask = DMA_BIT_MASK(32),
  845. .platform_data = &dbgu_data,
  846. },
  847. .resource = dbgu_resources,
  848. .num_resources = ARRAY_SIZE(dbgu_resources),
  849. };
  850. static inline void configure_dbgu_pins(void)
  851. {
  852. at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
  853. at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
  854. }
  855. static struct resource uart0_resources[] = {
  856. [0] = {
  857. .start = AT91SAM9RL_BASE_US0,
  858. .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
  859. .flags = IORESOURCE_MEM,
  860. },
  861. [1] = {
  862. .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US0,
  863. .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US0,
  864. .flags = IORESOURCE_IRQ,
  865. },
  866. };
  867. static struct atmel_uart_data uart0_data = {
  868. .use_dma_tx = 1,
  869. .use_dma_rx = 1,
  870. };
  871. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  872. static struct platform_device at91sam9rl_uart0_device = {
  873. .name = "atmel_usart",
  874. .id = 1,
  875. .dev = {
  876. .dma_mask = &uart0_dmamask,
  877. .coherent_dma_mask = DMA_BIT_MASK(32),
  878. .platform_data = &uart0_data,
  879. },
  880. .resource = uart0_resources,
  881. .num_resources = ARRAY_SIZE(uart0_resources),
  882. };
  883. static inline void configure_usart0_pins(unsigned pins)
  884. {
  885. at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
  886. at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
  887. if (pins & ATMEL_UART_RTS)
  888. at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
  889. if (pins & ATMEL_UART_CTS)
  890. at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
  891. if (pins & ATMEL_UART_DSR)
  892. at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
  893. if (pins & ATMEL_UART_DTR)
  894. at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
  895. if (pins & ATMEL_UART_DCD)
  896. at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
  897. if (pins & ATMEL_UART_RI)
  898. at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
  899. }
  900. static struct resource uart1_resources[] = {
  901. [0] = {
  902. .start = AT91SAM9RL_BASE_US1,
  903. .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
  904. .flags = IORESOURCE_MEM,
  905. },
  906. [1] = {
  907. .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US1,
  908. .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US1,
  909. .flags = IORESOURCE_IRQ,
  910. },
  911. };
  912. static struct atmel_uart_data uart1_data = {
  913. .use_dma_tx = 1,
  914. .use_dma_rx = 1,
  915. };
  916. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  917. static struct platform_device at91sam9rl_uart1_device = {
  918. .name = "atmel_usart",
  919. .id = 2,
  920. .dev = {
  921. .dma_mask = &uart1_dmamask,
  922. .coherent_dma_mask = DMA_BIT_MASK(32),
  923. .platform_data = &uart1_data,
  924. },
  925. .resource = uart1_resources,
  926. .num_resources = ARRAY_SIZE(uart1_resources),
  927. };
  928. static inline void configure_usart1_pins(unsigned pins)
  929. {
  930. at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
  931. at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
  932. if (pins & ATMEL_UART_RTS)
  933. at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
  934. if (pins & ATMEL_UART_CTS)
  935. at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
  936. }
  937. static struct resource uart2_resources[] = {
  938. [0] = {
  939. .start = AT91SAM9RL_BASE_US2,
  940. .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
  941. .flags = IORESOURCE_MEM,
  942. },
  943. [1] = {
  944. .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US2,
  945. .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US2,
  946. .flags = IORESOURCE_IRQ,
  947. },
  948. };
  949. static struct atmel_uart_data uart2_data = {
  950. .use_dma_tx = 1,
  951. .use_dma_rx = 1,
  952. };
  953. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  954. static struct platform_device at91sam9rl_uart2_device = {
  955. .name = "atmel_usart",
  956. .id = 3,
  957. .dev = {
  958. .dma_mask = &uart2_dmamask,
  959. .coherent_dma_mask = DMA_BIT_MASK(32),
  960. .platform_data = &uart2_data,
  961. },
  962. .resource = uart2_resources,
  963. .num_resources = ARRAY_SIZE(uart2_resources),
  964. };
  965. static inline void configure_usart2_pins(unsigned pins)
  966. {
  967. at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
  968. at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
  969. if (pins & ATMEL_UART_RTS)
  970. at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
  971. if (pins & ATMEL_UART_CTS)
  972. at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
  973. }
  974. static struct resource uart3_resources[] = {
  975. [0] = {
  976. .start = AT91SAM9RL_BASE_US3,
  977. .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
  978. .flags = IORESOURCE_MEM,
  979. },
  980. [1] = {
  981. .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US3,
  982. .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US3,
  983. .flags = IORESOURCE_IRQ,
  984. },
  985. };
  986. static struct atmel_uart_data uart3_data = {
  987. .use_dma_tx = 1,
  988. .use_dma_rx = 1,
  989. };
  990. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  991. static struct platform_device at91sam9rl_uart3_device = {
  992. .name = "atmel_usart",
  993. .id = 4,
  994. .dev = {
  995. .dma_mask = &uart3_dmamask,
  996. .coherent_dma_mask = DMA_BIT_MASK(32),
  997. .platform_data = &uart3_data,
  998. },
  999. .resource = uart3_resources,
  1000. .num_resources = ARRAY_SIZE(uart3_resources),
  1001. };
  1002. static inline void configure_usart3_pins(unsigned pins)
  1003. {
  1004. at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
  1005. at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
  1006. if (pins & ATMEL_UART_RTS)
  1007. at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
  1008. if (pins & ATMEL_UART_CTS)
  1009. at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
  1010. }
  1011. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1012. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1013. {
  1014. struct platform_device *pdev;
  1015. struct atmel_uart_data *pdata;
  1016. switch (id) {
  1017. case 0: /* DBGU */
  1018. pdev = &at91sam9rl_dbgu_device;
  1019. configure_dbgu_pins();
  1020. break;
  1021. case AT91SAM9RL_ID_US0:
  1022. pdev = &at91sam9rl_uart0_device;
  1023. configure_usart0_pins(pins);
  1024. break;
  1025. case AT91SAM9RL_ID_US1:
  1026. pdev = &at91sam9rl_uart1_device;
  1027. configure_usart1_pins(pins);
  1028. break;
  1029. case AT91SAM9RL_ID_US2:
  1030. pdev = &at91sam9rl_uart2_device;
  1031. configure_usart2_pins(pins);
  1032. break;
  1033. case AT91SAM9RL_ID_US3:
  1034. pdev = &at91sam9rl_uart3_device;
  1035. configure_usart3_pins(pins);
  1036. break;
  1037. default:
  1038. return;
  1039. }
  1040. pdata = pdev->dev.platform_data;
  1041. pdata->num = portnr; /* update to mapped ID */
  1042. if (portnr < ATMEL_MAX_UART)
  1043. at91_uarts[portnr] = pdev;
  1044. }
  1045. void __init at91_add_device_serial(void)
  1046. {
  1047. int i;
  1048. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1049. if (at91_uarts[i])
  1050. platform_device_register(at91_uarts[i]);
  1051. }
  1052. }
  1053. #else
  1054. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1055. void __init at91_add_device_serial(void) {}
  1056. #endif
  1057. /* -------------------------------------------------------------------- */
  1058. /*
  1059. * These devices are always present and don't need any board-specific
  1060. * setup.
  1061. */
  1062. static int __init at91_add_standard_devices(void)
  1063. {
  1064. at91_add_device_hdmac();
  1065. at91_add_device_rtc();
  1066. at91_add_device_rtt();
  1067. at91_add_device_watchdog();
  1068. at91_add_device_tc();
  1069. return 0;
  1070. }
  1071. arch_initcall(at91_add_standard_devices);