at91sam9rl_devices.c 31 KB

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