at91sam9g45_devices.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. /*
  2. * On-Chip devices setup code for the AT91SAM9G45 family
  3. *
  4. * Copyright (C) 2009 Atmel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <asm/mach/arch.h>
  13. #include <asm/mach/map.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/i2c-gpio.h>
  17. #include <linux/fb.h>
  18. #include <video/atmel_lcdc.h>
  19. #include <mach/board.h>
  20. #include <mach/gpio.h>
  21. #include <mach/at91sam9g45.h>
  22. #include <mach/at91sam9g45_matrix.h>
  23. #include <mach/at91sam9_smc.h>
  24. #include <mach/at_hdmac.h>
  25. #include "generic.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 at_dma_platform_data atdma_pdata = {
  32. .nr_channels = 8,
  33. };
  34. static struct resource hdmac_resources[] = {
  35. [0] = {
  36. .start = AT91_BASE_SYS + AT91_DMA,
  37. .end = AT91_BASE_SYS + AT91_DMA + SZ_512 - 1,
  38. .flags = IORESOURCE_MEM,
  39. },
  40. [2] = {
  41. .start = AT91SAM9G45_ID_DMA,
  42. .end = AT91SAM9G45_ID_DMA,
  43. .flags = IORESOURCE_IRQ,
  44. },
  45. };
  46. static struct platform_device at_hdmac_device = {
  47. .name = "at_hdmac",
  48. .id = -1,
  49. .dev = {
  50. .dma_mask = &hdmac_dmamask,
  51. .coherent_dma_mask = DMA_BIT_MASK(32),
  52. .platform_data = &atdma_pdata,
  53. },
  54. .resource = hdmac_resources,
  55. .num_resources = ARRAY_SIZE(hdmac_resources),
  56. };
  57. void __init at91_add_device_hdmac(void)
  58. {
  59. dma_cap_set(DMA_MEMCPY, atdma_pdata.cap_mask);
  60. dma_cap_set(DMA_SLAVE, atdma_pdata.cap_mask);
  61. platform_device_register(&at_hdmac_device);
  62. }
  63. #else
  64. void __init at91_add_device_hdmac(void) {}
  65. #endif
  66. /* --------------------------------------------------------------------
  67. * USB Host (OHCI)
  68. * -------------------------------------------------------------------- */
  69. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  70. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  71. static struct at91_usbh_data usbh_ohci_data;
  72. static struct resource usbh_ohci_resources[] = {
  73. [0] = {
  74. .start = AT91SAM9G45_OHCI_BASE,
  75. .end = AT91SAM9G45_OHCI_BASE + SZ_1M - 1,
  76. .flags = IORESOURCE_MEM,
  77. },
  78. [1] = {
  79. .start = AT91SAM9G45_ID_UHPHS,
  80. .end = AT91SAM9G45_ID_UHPHS,
  81. .flags = IORESOURCE_IRQ,
  82. },
  83. };
  84. static struct platform_device at91_usbh_ohci_device = {
  85. .name = "at91_ohci",
  86. .id = -1,
  87. .dev = {
  88. .dma_mask = &ohci_dmamask,
  89. .coherent_dma_mask = DMA_BIT_MASK(32),
  90. .platform_data = &usbh_ohci_data,
  91. },
  92. .resource = usbh_ohci_resources,
  93. .num_resources = ARRAY_SIZE(usbh_ohci_resources),
  94. };
  95. void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data)
  96. {
  97. int i;
  98. if (!data)
  99. return;
  100. /* Enable VBus control for UHP ports */
  101. for (i = 0; i < data->ports; i++) {
  102. if (data->vbus_pin[i])
  103. at91_set_gpio_output(data->vbus_pin[i], 0);
  104. }
  105. usbh_ohci_data = *data;
  106. platform_device_register(&at91_usbh_ohci_device);
  107. }
  108. #else
  109. void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data) {}
  110. #endif
  111. /* --------------------------------------------------------------------
  112. * USB HS Device (Gadget)
  113. * -------------------------------------------------------------------- */
  114. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  115. static struct resource usba_udc_resources[] = {
  116. [0] = {
  117. .start = AT91SAM9G45_UDPHS_FIFO,
  118. .end = AT91SAM9G45_UDPHS_FIFO + SZ_512K - 1,
  119. .flags = IORESOURCE_MEM,
  120. },
  121. [1] = {
  122. .start = AT91SAM9G45_BASE_UDPHS,
  123. .end = AT91SAM9G45_BASE_UDPHS + SZ_1K - 1,
  124. .flags = IORESOURCE_MEM,
  125. },
  126. [2] = {
  127. .start = AT91SAM9G45_ID_UDPHS,
  128. .end = AT91SAM9G45_ID_UDPHS,
  129. .flags = IORESOURCE_IRQ,
  130. },
  131. };
  132. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  133. [idx] = { \
  134. .name = nam, \
  135. .index = idx, \
  136. .fifo_size = maxpkt, \
  137. .nr_banks = maxbk, \
  138. .can_dma = dma, \
  139. .can_isoc = isoc, \
  140. }
  141. static struct usba_ep_data usba_udc_ep[] __initdata = {
  142. EP("ep0", 0, 64, 1, 0, 0),
  143. EP("ep1", 1, 1024, 2, 1, 1),
  144. EP("ep2", 2, 1024, 2, 1, 1),
  145. EP("ep3", 3, 1024, 3, 1, 0),
  146. EP("ep4", 4, 1024, 3, 1, 0),
  147. EP("ep5", 5, 1024, 3, 1, 1),
  148. EP("ep6", 6, 1024, 3, 1, 1),
  149. };
  150. #undef EP
  151. /*
  152. * pdata doesn't have room for any endpoints, so we need to
  153. * append room for the ones we need right after it.
  154. */
  155. static struct {
  156. struct usba_platform_data pdata;
  157. struct usba_ep_data ep[7];
  158. } usba_udc_data;
  159. static struct platform_device at91_usba_udc_device = {
  160. .name = "atmel_usba_udc",
  161. .id = -1,
  162. .dev = {
  163. .platform_data = &usba_udc_data.pdata,
  164. },
  165. .resource = usba_udc_resources,
  166. .num_resources = ARRAY_SIZE(usba_udc_resources),
  167. };
  168. void __init at91_add_device_usba(struct usba_platform_data *data)
  169. {
  170. usba_udc_data.pdata.vbus_pin = -EINVAL;
  171. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  172. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  173. if (data && data->vbus_pin > 0) {
  174. at91_set_gpio_input(data->vbus_pin, 0);
  175. at91_set_deglitch(data->vbus_pin, 1);
  176. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  177. }
  178. /* Pullup pin is handled internally by USB device peripheral */
  179. /* Clocks */
  180. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  181. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  182. platform_device_register(&at91_usba_udc_device);
  183. }
  184. #else
  185. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  186. #endif
  187. /* --------------------------------------------------------------------
  188. * Ethernet
  189. * -------------------------------------------------------------------- */
  190. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  191. static u64 eth_dmamask = DMA_BIT_MASK(32);
  192. static struct at91_eth_data eth_data;
  193. static struct resource eth_resources[] = {
  194. [0] = {
  195. .start = AT91SAM9G45_BASE_EMAC,
  196. .end = AT91SAM9G45_BASE_EMAC + SZ_16K - 1,
  197. .flags = IORESOURCE_MEM,
  198. },
  199. [1] = {
  200. .start = AT91SAM9G45_ID_EMAC,
  201. .end = AT91SAM9G45_ID_EMAC,
  202. .flags = IORESOURCE_IRQ,
  203. },
  204. };
  205. static struct platform_device at91sam9g45_eth_device = {
  206. .name = "macb",
  207. .id = -1,
  208. .dev = {
  209. .dma_mask = &eth_dmamask,
  210. .coherent_dma_mask = DMA_BIT_MASK(32),
  211. .platform_data = &eth_data,
  212. },
  213. .resource = eth_resources,
  214. .num_resources = ARRAY_SIZE(eth_resources),
  215. };
  216. void __init at91_add_device_eth(struct at91_eth_data *data)
  217. {
  218. if (!data)
  219. return;
  220. if (data->phy_irq_pin) {
  221. at91_set_gpio_input(data->phy_irq_pin, 0);
  222. at91_set_deglitch(data->phy_irq_pin, 1);
  223. }
  224. /* Pins used for MII and RMII */
  225. at91_set_A_periph(AT91_PIN_PA17, 0); /* ETXCK_EREFCK */
  226. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERXDV */
  227. at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
  228. at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
  229. at91_set_A_periph(AT91_PIN_PA16, 0); /* ERXER */
  230. at91_set_A_periph(AT91_PIN_PA14, 0); /* ETXEN */
  231. at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX0 */
  232. at91_set_A_periph(AT91_PIN_PA11, 0); /* ETX1 */
  233. at91_set_A_periph(AT91_PIN_PA19, 0); /* EMDIO */
  234. at91_set_A_periph(AT91_PIN_PA18, 0); /* EMDC */
  235. if (!data->is_rmii) {
  236. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECRS */
  237. at91_set_B_periph(AT91_PIN_PA30, 0); /* ECOL */
  238. at91_set_B_periph(AT91_PIN_PA8, 0); /* ERX2 */
  239. at91_set_B_periph(AT91_PIN_PA9, 0); /* ERX3 */
  240. at91_set_B_periph(AT91_PIN_PA28, 0); /* ERXCK */
  241. at91_set_B_periph(AT91_PIN_PA6, 0); /* ETX2 */
  242. at91_set_B_periph(AT91_PIN_PA7, 0); /* ETX3 */
  243. at91_set_B_periph(AT91_PIN_PA27, 0); /* ETXER */
  244. }
  245. eth_data = *data;
  246. platform_device_register(&at91sam9g45_eth_device);
  247. }
  248. #else
  249. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  250. #endif
  251. /* --------------------------------------------------------------------
  252. * NAND / SmartMedia
  253. * -------------------------------------------------------------------- */
  254. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  255. static struct atmel_nand_data nand_data;
  256. #define NAND_BASE AT91_CHIPSELECT_3
  257. static struct resource nand_resources[] = {
  258. [0] = {
  259. .start = NAND_BASE,
  260. .end = NAND_BASE + SZ_256M - 1,
  261. .flags = IORESOURCE_MEM,
  262. },
  263. [1] = {
  264. .start = AT91_BASE_SYS + AT91_ECC,
  265. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  266. .flags = IORESOURCE_MEM,
  267. }
  268. };
  269. static struct platform_device at91sam9g45_nand_device = {
  270. .name = "atmel_nand",
  271. .id = -1,
  272. .dev = {
  273. .platform_data = &nand_data,
  274. },
  275. .resource = nand_resources,
  276. .num_resources = ARRAY_SIZE(nand_resources),
  277. };
  278. void __init at91_add_device_nand(struct atmel_nand_data *data)
  279. {
  280. unsigned long csa;
  281. if (!data)
  282. return;
  283. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  284. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
  285. /* enable pin */
  286. if (data->enable_pin)
  287. at91_set_gpio_output(data->enable_pin, 1);
  288. /* ready/busy pin */
  289. if (data->rdy_pin)
  290. at91_set_gpio_input(data->rdy_pin, 1);
  291. /* card detect pin */
  292. if (data->det_pin)
  293. at91_set_gpio_input(data->det_pin, 1);
  294. nand_data = *data;
  295. platform_device_register(&at91sam9g45_nand_device);
  296. }
  297. #else
  298. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  299. #endif
  300. /* --------------------------------------------------------------------
  301. * TWI (i2c)
  302. * -------------------------------------------------------------------- */
  303. /*
  304. * Prefer the GPIO code since the TWI controller isn't robust
  305. * (gets overruns and underruns under load) and can only issue
  306. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  307. */
  308. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  309. static struct i2c_gpio_platform_data pdata_i2c0 = {
  310. .sda_pin = AT91_PIN_PA20,
  311. .sda_is_open_drain = 1,
  312. .scl_pin = AT91_PIN_PA21,
  313. .scl_is_open_drain = 1,
  314. .udelay = 2, /* ~100 kHz */
  315. };
  316. static struct platform_device at91sam9g45_twi0_device = {
  317. .name = "i2c-gpio",
  318. .id = 0,
  319. .dev.platform_data = &pdata_i2c0,
  320. };
  321. static struct i2c_gpio_platform_data pdata_i2c1 = {
  322. .sda_pin = AT91_PIN_PB10,
  323. .sda_is_open_drain = 1,
  324. .scl_pin = AT91_PIN_PB11,
  325. .scl_is_open_drain = 1,
  326. .udelay = 2, /* ~100 kHz */
  327. };
  328. static struct platform_device at91sam9g45_twi1_device = {
  329. .name = "i2c-gpio",
  330. .id = 1,
  331. .dev.platform_data = &pdata_i2c1,
  332. };
  333. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  334. {
  335. i2c_register_board_info(i2c_id, devices, nr_devices);
  336. if (i2c_id == 0) {
  337. at91_set_GPIO_periph(AT91_PIN_PA20, 1); /* TWD (SDA) */
  338. at91_set_multi_drive(AT91_PIN_PA20, 1);
  339. at91_set_GPIO_periph(AT91_PIN_PA21, 1); /* TWCK (SCL) */
  340. at91_set_multi_drive(AT91_PIN_PA21, 1);
  341. platform_device_register(&at91sam9g45_twi0_device);
  342. } else {
  343. at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* TWD (SDA) */
  344. at91_set_multi_drive(AT91_PIN_PB10, 1);
  345. at91_set_GPIO_periph(AT91_PIN_PB11, 1); /* TWCK (SCL) */
  346. at91_set_multi_drive(AT91_PIN_PB11, 1);
  347. platform_device_register(&at91sam9g45_twi1_device);
  348. }
  349. }
  350. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  351. static struct resource twi0_resources[] = {
  352. [0] = {
  353. .start = AT91SAM9G45_BASE_TWI0,
  354. .end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1,
  355. .flags = IORESOURCE_MEM,
  356. },
  357. [1] = {
  358. .start = AT91SAM9G45_ID_TWI0,
  359. .end = AT91SAM9G45_ID_TWI0,
  360. .flags = IORESOURCE_IRQ,
  361. },
  362. };
  363. static struct platform_device at91sam9g45_twi0_device = {
  364. .name = "at91_i2c",
  365. .id = 0,
  366. .resource = twi0_resources,
  367. .num_resources = ARRAY_SIZE(twi0_resources),
  368. };
  369. static struct resource twi1_resources[] = {
  370. [0] = {
  371. .start = AT91SAM9G45_BASE_TWI1,
  372. .end = AT91SAM9G45_BASE_TWI1 + SZ_16K - 1,
  373. .flags = IORESOURCE_MEM,
  374. },
  375. [1] = {
  376. .start = AT91SAM9G45_ID_TWI1,
  377. .end = AT91SAM9G45_ID_TWI1,
  378. .flags = IORESOURCE_IRQ,
  379. },
  380. };
  381. static struct platform_device at91sam9g45_twi1_device = {
  382. .name = "at91_i2c",
  383. .id = 1,
  384. .resource = twi1_resources,
  385. .num_resources = ARRAY_SIZE(twi1_resources),
  386. };
  387. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  388. {
  389. i2c_register_board_info(i2c_id, devices, nr_devices);
  390. /* pins used for TWI interface */
  391. if (i2c_id == 0) {
  392. at91_set_A_periph(AT91_PIN_PA20, 0); /* TWD */
  393. at91_set_multi_drive(AT91_PIN_PA20, 1);
  394. at91_set_A_periph(AT91_PIN_PA21, 0); /* TWCK */
  395. at91_set_multi_drive(AT91_PIN_PA21, 1);
  396. platform_device_register(&at91sam9g45_twi0_device);
  397. } else {
  398. at91_set_A_periph(AT91_PIN_PB10, 0); /* TWD */
  399. at91_set_multi_drive(AT91_PIN_PB10, 1);
  400. at91_set_A_periph(AT91_PIN_PB11, 0); /* TWCK */
  401. at91_set_multi_drive(AT91_PIN_PB11, 1);
  402. platform_device_register(&at91sam9g45_twi1_device);
  403. }
  404. }
  405. #else
  406. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {}
  407. #endif
  408. /* --------------------------------------------------------------------
  409. * SPI
  410. * -------------------------------------------------------------------- */
  411. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  412. static u64 spi_dmamask = DMA_BIT_MASK(32);
  413. static struct resource spi0_resources[] = {
  414. [0] = {
  415. .start = AT91SAM9G45_BASE_SPI0,
  416. .end = AT91SAM9G45_BASE_SPI0 + SZ_16K - 1,
  417. .flags = IORESOURCE_MEM,
  418. },
  419. [1] = {
  420. .start = AT91SAM9G45_ID_SPI0,
  421. .end = AT91SAM9G45_ID_SPI0,
  422. .flags = IORESOURCE_IRQ,
  423. },
  424. };
  425. static struct platform_device at91sam9g45_spi0_device = {
  426. .name = "atmel_spi",
  427. .id = 0,
  428. .dev = {
  429. .dma_mask = &spi_dmamask,
  430. .coherent_dma_mask = DMA_BIT_MASK(32),
  431. },
  432. .resource = spi0_resources,
  433. .num_resources = ARRAY_SIZE(spi0_resources),
  434. };
  435. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PB18, AT91_PIN_PB19, AT91_PIN_PD27 };
  436. static struct resource spi1_resources[] = {
  437. [0] = {
  438. .start = AT91SAM9G45_BASE_SPI1,
  439. .end = AT91SAM9G45_BASE_SPI1 + SZ_16K - 1,
  440. .flags = IORESOURCE_MEM,
  441. },
  442. [1] = {
  443. .start = AT91SAM9G45_ID_SPI1,
  444. .end = AT91SAM9G45_ID_SPI1,
  445. .flags = IORESOURCE_IRQ,
  446. },
  447. };
  448. static struct platform_device at91sam9g45_spi1_device = {
  449. .name = "atmel_spi",
  450. .id = 1,
  451. .dev = {
  452. .dma_mask = &spi_dmamask,
  453. .coherent_dma_mask = DMA_BIT_MASK(32),
  454. },
  455. .resource = spi1_resources,
  456. .num_resources = ARRAY_SIZE(spi1_resources),
  457. };
  458. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB17, AT91_PIN_PD28, AT91_PIN_PD18, AT91_PIN_PD19 };
  459. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  460. {
  461. int i;
  462. unsigned long cs_pin;
  463. short enable_spi0 = 0;
  464. short enable_spi1 = 0;
  465. /* Choose SPI chip-selects */
  466. for (i = 0; i < nr_devices; i++) {
  467. if (devices[i].controller_data)
  468. cs_pin = (unsigned long) devices[i].controller_data;
  469. else if (devices[i].bus_num == 0)
  470. cs_pin = spi0_standard_cs[devices[i].chip_select];
  471. else
  472. cs_pin = spi1_standard_cs[devices[i].chip_select];
  473. if (devices[i].bus_num == 0)
  474. enable_spi0 = 1;
  475. else
  476. enable_spi1 = 1;
  477. /* enable chip-select pin */
  478. at91_set_gpio_output(cs_pin, 1);
  479. /* pass chip-select pin to driver */
  480. devices[i].controller_data = (void *) cs_pin;
  481. }
  482. spi_register_board_info(devices, nr_devices);
  483. /* Configure SPI bus(es) */
  484. if (enable_spi0) {
  485. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI0_MISO */
  486. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI0_MOSI */
  487. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI0_SPCK */
  488. at91_clock_associate("spi0_clk", &at91sam9g45_spi0_device.dev, "spi_clk");
  489. platform_device_register(&at91sam9g45_spi0_device);
  490. }
  491. if (enable_spi1) {
  492. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_MISO */
  493. at91_set_A_periph(AT91_PIN_PB15, 0); /* SPI1_MOSI */
  494. at91_set_A_periph(AT91_PIN_PB16, 0); /* SPI1_SPCK */
  495. at91_clock_associate("spi1_clk", &at91sam9g45_spi1_device.dev, "spi_clk");
  496. platform_device_register(&at91sam9g45_spi1_device);
  497. }
  498. }
  499. #else
  500. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  501. #endif
  502. /* --------------------------------------------------------------------
  503. * LCD Controller
  504. * -------------------------------------------------------------------- */
  505. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  506. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  507. static struct atmel_lcdfb_info lcdc_data;
  508. static struct resource lcdc_resources[] = {
  509. [0] = {
  510. .start = AT91SAM9G45_LCDC_BASE,
  511. .end = AT91SAM9G45_LCDC_BASE + SZ_4K - 1,
  512. .flags = IORESOURCE_MEM,
  513. },
  514. [1] = {
  515. .start = AT91SAM9G45_ID_LCDC,
  516. .end = AT91SAM9G45_ID_LCDC,
  517. .flags = IORESOURCE_IRQ,
  518. },
  519. };
  520. static struct platform_device at91_lcdc_device = {
  521. .name = "atmel_lcdfb",
  522. .id = 0,
  523. .dev = {
  524. .dma_mask = &lcdc_dmamask,
  525. .coherent_dma_mask = DMA_BIT_MASK(32),
  526. .platform_data = &lcdc_data,
  527. },
  528. .resource = lcdc_resources,
  529. .num_resources = ARRAY_SIZE(lcdc_resources),
  530. };
  531. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  532. {
  533. if (!data)
  534. return;
  535. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  536. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  537. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  538. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  539. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  540. at91_set_A_periph(AT91_PIN_PE6, 0); /* LCDDEN */
  541. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  542. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  543. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  544. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  545. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  546. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  547. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  548. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  549. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  550. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  551. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  552. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  553. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  554. at91_set_A_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  555. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  556. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  557. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  558. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  559. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  560. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  561. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  562. at91_set_A_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  563. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  564. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  565. lcdc_data = *data;
  566. platform_device_register(&at91_lcdc_device);
  567. }
  568. #else
  569. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  570. #endif
  571. /* --------------------------------------------------------------------
  572. * Timer/Counter block
  573. * -------------------------------------------------------------------- */
  574. #ifdef CONFIG_ATMEL_TCLIB
  575. static struct resource tcb0_resources[] = {
  576. [0] = {
  577. .start = AT91SAM9G45_BASE_TCB0,
  578. .end = AT91SAM9G45_BASE_TCB0 + SZ_16K - 1,
  579. .flags = IORESOURCE_MEM,
  580. },
  581. [1] = {
  582. .start = AT91SAM9G45_ID_TCB,
  583. .end = AT91SAM9G45_ID_TCB,
  584. .flags = IORESOURCE_IRQ,
  585. },
  586. };
  587. static struct platform_device at91sam9g45_tcb0_device = {
  588. .name = "atmel_tcb",
  589. .id = 0,
  590. .resource = tcb0_resources,
  591. .num_resources = ARRAY_SIZE(tcb0_resources),
  592. };
  593. /* TCB1 begins with TC3 */
  594. static struct resource tcb1_resources[] = {
  595. [0] = {
  596. .start = AT91SAM9G45_BASE_TCB1,
  597. .end = AT91SAM9G45_BASE_TCB1 + SZ_16K - 1,
  598. .flags = IORESOURCE_MEM,
  599. },
  600. [1] = {
  601. .start = AT91SAM9G45_ID_TCB,
  602. .end = AT91SAM9G45_ID_TCB,
  603. .flags = IORESOURCE_IRQ,
  604. },
  605. };
  606. static struct platform_device at91sam9g45_tcb1_device = {
  607. .name = "atmel_tcb",
  608. .id = 1,
  609. .resource = tcb1_resources,
  610. .num_resources = ARRAY_SIZE(tcb1_resources),
  611. };
  612. static void __init at91_add_device_tc(void)
  613. {
  614. /* this chip has one clock and irq for all six TC channels */
  615. at91_clock_associate("tcb_clk", &at91sam9g45_tcb0_device.dev, "t0_clk");
  616. platform_device_register(&at91sam9g45_tcb0_device);
  617. at91_clock_associate("tcb_clk", &at91sam9g45_tcb1_device.dev, "t0_clk");
  618. platform_device_register(&at91sam9g45_tcb1_device);
  619. }
  620. #else
  621. static void __init at91_add_device_tc(void) { }
  622. #endif
  623. /* --------------------------------------------------------------------
  624. * RTC
  625. * -------------------------------------------------------------------- */
  626. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  627. static struct platform_device at91sam9g45_rtc_device = {
  628. .name = "at91_rtc",
  629. .id = -1,
  630. .num_resources = 0,
  631. };
  632. static void __init at91_add_device_rtc(void)
  633. {
  634. platform_device_register(&at91sam9g45_rtc_device);
  635. }
  636. #else
  637. static void __init at91_add_device_rtc(void) {}
  638. #endif
  639. /* --------------------------------------------------------------------
  640. * RTT
  641. * -------------------------------------------------------------------- */
  642. static struct resource rtt_resources[] = {
  643. {
  644. .start = AT91_BASE_SYS + AT91_RTT,
  645. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  646. .flags = IORESOURCE_MEM,
  647. }
  648. };
  649. static struct platform_device at91sam9g45_rtt_device = {
  650. .name = "at91_rtt",
  651. .id = 0,
  652. .resource = rtt_resources,
  653. .num_resources = ARRAY_SIZE(rtt_resources),
  654. };
  655. static void __init at91_add_device_rtt(void)
  656. {
  657. platform_device_register(&at91sam9g45_rtt_device);
  658. }
  659. /* --------------------------------------------------------------------
  660. * Watchdog
  661. * -------------------------------------------------------------------- */
  662. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  663. static struct platform_device at91sam9g45_wdt_device = {
  664. .name = "at91_wdt",
  665. .id = -1,
  666. .num_resources = 0,
  667. };
  668. static void __init at91_add_device_watchdog(void)
  669. {
  670. platform_device_register(&at91sam9g45_wdt_device);
  671. }
  672. #else
  673. static void __init at91_add_device_watchdog(void) {}
  674. #endif
  675. /* --------------------------------------------------------------------
  676. * PWM
  677. * --------------------------------------------------------------------*/
  678. #if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE)
  679. static u32 pwm_mask;
  680. static struct resource pwm_resources[] = {
  681. [0] = {
  682. .start = AT91SAM9G45_BASE_PWMC,
  683. .end = AT91SAM9G45_BASE_PWMC + SZ_16K - 1,
  684. .flags = IORESOURCE_MEM,
  685. },
  686. [1] = {
  687. .start = AT91SAM9G45_ID_PWMC,
  688. .end = AT91SAM9G45_ID_PWMC,
  689. .flags = IORESOURCE_IRQ,
  690. },
  691. };
  692. static struct platform_device at91sam9g45_pwm0_device = {
  693. .name = "atmel_pwm",
  694. .id = -1,
  695. .dev = {
  696. .platform_data = &pwm_mask,
  697. },
  698. .resource = pwm_resources,
  699. .num_resources = ARRAY_SIZE(pwm_resources),
  700. };
  701. void __init at91_add_device_pwm(u32 mask)
  702. {
  703. if (mask & (1 << AT91_PWM0))
  704. at91_set_B_periph(AT91_PIN_PD24, 1); /* enable PWM0 */
  705. if (mask & (1 << AT91_PWM1))
  706. at91_set_B_periph(AT91_PIN_PD31, 1); /* enable PWM1 */
  707. if (mask & (1 << AT91_PWM2))
  708. at91_set_B_periph(AT91_PIN_PD26, 1); /* enable PWM2 */
  709. if (mask & (1 << AT91_PWM3))
  710. at91_set_B_periph(AT91_PIN_PD0, 1); /* enable PWM3 */
  711. pwm_mask = mask;
  712. platform_device_register(&at91sam9g45_pwm0_device);
  713. }
  714. #else
  715. void __init at91_add_device_pwm(u32 mask) {}
  716. #endif
  717. /* --------------------------------------------------------------------
  718. * SSC -- Synchronous Serial Controller
  719. * -------------------------------------------------------------------- */
  720. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  721. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  722. static struct resource ssc0_resources[] = {
  723. [0] = {
  724. .start = AT91SAM9G45_BASE_SSC0,
  725. .end = AT91SAM9G45_BASE_SSC0 + SZ_16K - 1,
  726. .flags = IORESOURCE_MEM,
  727. },
  728. [1] = {
  729. .start = AT91SAM9G45_ID_SSC0,
  730. .end = AT91SAM9G45_ID_SSC0,
  731. .flags = IORESOURCE_IRQ,
  732. },
  733. };
  734. static struct platform_device at91sam9g45_ssc0_device = {
  735. .name = "ssc",
  736. .id = 0,
  737. .dev = {
  738. .dma_mask = &ssc0_dmamask,
  739. .coherent_dma_mask = DMA_BIT_MASK(32),
  740. },
  741. .resource = ssc0_resources,
  742. .num_resources = ARRAY_SIZE(ssc0_resources),
  743. };
  744. static inline void configure_ssc0_pins(unsigned pins)
  745. {
  746. if (pins & ATMEL_SSC_TF)
  747. at91_set_A_periph(AT91_PIN_PD1, 1);
  748. if (pins & ATMEL_SSC_TK)
  749. at91_set_A_periph(AT91_PIN_PD0, 1);
  750. if (pins & ATMEL_SSC_TD)
  751. at91_set_A_periph(AT91_PIN_PD2, 1);
  752. if (pins & ATMEL_SSC_RD)
  753. at91_set_A_periph(AT91_PIN_PD3, 1);
  754. if (pins & ATMEL_SSC_RK)
  755. at91_set_A_periph(AT91_PIN_PD4, 1);
  756. if (pins & ATMEL_SSC_RF)
  757. at91_set_A_periph(AT91_PIN_PD5, 1);
  758. }
  759. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  760. static struct resource ssc1_resources[] = {
  761. [0] = {
  762. .start = AT91SAM9G45_BASE_SSC1,
  763. .end = AT91SAM9G45_BASE_SSC1 + SZ_16K - 1,
  764. .flags = IORESOURCE_MEM,
  765. },
  766. [1] = {
  767. .start = AT91SAM9G45_ID_SSC1,
  768. .end = AT91SAM9G45_ID_SSC1,
  769. .flags = IORESOURCE_IRQ,
  770. },
  771. };
  772. static struct platform_device at91sam9g45_ssc1_device = {
  773. .name = "ssc",
  774. .id = 1,
  775. .dev = {
  776. .dma_mask = &ssc1_dmamask,
  777. .coherent_dma_mask = DMA_BIT_MASK(32),
  778. },
  779. .resource = ssc1_resources,
  780. .num_resources = ARRAY_SIZE(ssc1_resources),
  781. };
  782. static inline void configure_ssc1_pins(unsigned pins)
  783. {
  784. if (pins & ATMEL_SSC_TF)
  785. at91_set_A_periph(AT91_PIN_PD14, 1);
  786. if (pins & ATMEL_SSC_TK)
  787. at91_set_A_periph(AT91_PIN_PD12, 1);
  788. if (pins & ATMEL_SSC_TD)
  789. at91_set_A_periph(AT91_PIN_PD10, 1);
  790. if (pins & ATMEL_SSC_RD)
  791. at91_set_A_periph(AT91_PIN_PD11, 1);
  792. if (pins & ATMEL_SSC_RK)
  793. at91_set_A_periph(AT91_PIN_PD13, 1);
  794. if (pins & ATMEL_SSC_RF)
  795. at91_set_A_periph(AT91_PIN_PD15, 1);
  796. }
  797. /*
  798. * SSC controllers are accessed through library code, instead of any
  799. * kind of all-singing/all-dancing driver. For example one could be
  800. * used by a particular I2S audio codec's driver, while another one
  801. * on the same system might be used by a custom data capture driver.
  802. */
  803. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  804. {
  805. struct platform_device *pdev;
  806. /*
  807. * NOTE: caller is responsible for passing information matching
  808. * "pins" to whatever will be using each particular controller.
  809. */
  810. switch (id) {
  811. case AT91SAM9G45_ID_SSC0:
  812. pdev = &at91sam9g45_ssc0_device;
  813. configure_ssc0_pins(pins);
  814. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  815. break;
  816. case AT91SAM9G45_ID_SSC1:
  817. pdev = &at91sam9g45_ssc1_device;
  818. configure_ssc1_pins(pins);
  819. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  820. break;
  821. default:
  822. return;
  823. }
  824. platform_device_register(pdev);
  825. }
  826. #else
  827. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  828. #endif
  829. /* --------------------------------------------------------------------
  830. * UART
  831. * -------------------------------------------------------------------- */
  832. #if defined(CONFIG_SERIAL_ATMEL)
  833. static struct resource dbgu_resources[] = {
  834. [0] = {
  835. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  836. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  837. .flags = IORESOURCE_MEM,
  838. },
  839. [1] = {
  840. .start = AT91_ID_SYS,
  841. .end = AT91_ID_SYS,
  842. .flags = IORESOURCE_IRQ,
  843. },
  844. };
  845. static struct atmel_uart_data dbgu_data = {
  846. .use_dma_tx = 0,
  847. .use_dma_rx = 0,
  848. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  849. };
  850. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  851. static struct platform_device at91sam9g45_dbgu_device = {
  852. .name = "atmel_usart",
  853. .id = 0,
  854. .dev = {
  855. .dma_mask = &dbgu_dmamask,
  856. .coherent_dma_mask = DMA_BIT_MASK(32),
  857. .platform_data = &dbgu_data,
  858. },
  859. .resource = dbgu_resources,
  860. .num_resources = ARRAY_SIZE(dbgu_resources),
  861. };
  862. static inline void configure_dbgu_pins(void)
  863. {
  864. at91_set_A_periph(AT91_PIN_PB12, 0); /* DRXD */
  865. at91_set_A_periph(AT91_PIN_PB13, 1); /* DTXD */
  866. }
  867. static struct resource uart0_resources[] = {
  868. [0] = {
  869. .start = AT91SAM9G45_BASE_US0,
  870. .end = AT91SAM9G45_BASE_US0 + SZ_16K - 1,
  871. .flags = IORESOURCE_MEM,
  872. },
  873. [1] = {
  874. .start = AT91SAM9G45_ID_US0,
  875. .end = AT91SAM9G45_ID_US0,
  876. .flags = IORESOURCE_IRQ,
  877. },
  878. };
  879. static struct atmel_uart_data uart0_data = {
  880. .use_dma_tx = 1,
  881. .use_dma_rx = 1,
  882. };
  883. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  884. static struct platform_device at91sam9g45_uart0_device = {
  885. .name = "atmel_usart",
  886. .id = 1,
  887. .dev = {
  888. .dma_mask = &uart0_dmamask,
  889. .coherent_dma_mask = DMA_BIT_MASK(32),
  890. .platform_data = &uart0_data,
  891. },
  892. .resource = uart0_resources,
  893. .num_resources = ARRAY_SIZE(uart0_resources),
  894. };
  895. static inline void configure_usart0_pins(unsigned pins)
  896. {
  897. at91_set_A_periph(AT91_PIN_PB19, 1); /* TXD0 */
  898. at91_set_A_periph(AT91_PIN_PB18, 0); /* RXD0 */
  899. if (pins & ATMEL_UART_RTS)
  900. at91_set_B_periph(AT91_PIN_PB17, 0); /* RTS0 */
  901. if (pins & ATMEL_UART_CTS)
  902. at91_set_B_periph(AT91_PIN_PB15, 0); /* CTS0 */
  903. }
  904. static struct resource uart1_resources[] = {
  905. [0] = {
  906. .start = AT91SAM9G45_BASE_US1,
  907. .end = AT91SAM9G45_BASE_US1 + SZ_16K - 1,
  908. .flags = IORESOURCE_MEM,
  909. },
  910. [1] = {
  911. .start = AT91SAM9G45_ID_US1,
  912. .end = AT91SAM9G45_ID_US1,
  913. .flags = IORESOURCE_IRQ,
  914. },
  915. };
  916. static struct atmel_uart_data uart1_data = {
  917. .use_dma_tx = 1,
  918. .use_dma_rx = 1,
  919. };
  920. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  921. static struct platform_device at91sam9g45_uart1_device = {
  922. .name = "atmel_usart",
  923. .id = 2,
  924. .dev = {
  925. .dma_mask = &uart1_dmamask,
  926. .coherent_dma_mask = DMA_BIT_MASK(32),
  927. .platform_data = &uart1_data,
  928. },
  929. .resource = uart1_resources,
  930. .num_resources = ARRAY_SIZE(uart1_resources),
  931. };
  932. static inline void configure_usart1_pins(unsigned pins)
  933. {
  934. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD1 */
  935. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD1 */
  936. if (pins & ATMEL_UART_RTS)
  937. at91_set_A_periph(AT91_PIN_PD16, 0); /* RTS1 */
  938. if (pins & ATMEL_UART_CTS)
  939. at91_set_A_periph(AT91_PIN_PD17, 0); /* CTS1 */
  940. }
  941. static struct resource uart2_resources[] = {
  942. [0] = {
  943. .start = AT91SAM9G45_BASE_US2,
  944. .end = AT91SAM9G45_BASE_US2 + SZ_16K - 1,
  945. .flags = IORESOURCE_MEM,
  946. },
  947. [1] = {
  948. .start = AT91SAM9G45_ID_US2,
  949. .end = AT91SAM9G45_ID_US2,
  950. .flags = IORESOURCE_IRQ,
  951. },
  952. };
  953. static struct atmel_uart_data uart2_data = {
  954. .use_dma_tx = 1,
  955. .use_dma_rx = 1,
  956. };
  957. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  958. static struct platform_device at91sam9g45_uart2_device = {
  959. .name = "atmel_usart",
  960. .id = 3,
  961. .dev = {
  962. .dma_mask = &uart2_dmamask,
  963. .coherent_dma_mask = DMA_BIT_MASK(32),
  964. .platform_data = &uart2_data,
  965. },
  966. .resource = uart2_resources,
  967. .num_resources = ARRAY_SIZE(uart2_resources),
  968. };
  969. static inline void configure_usart2_pins(unsigned pins)
  970. {
  971. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD2 */
  972. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD2 */
  973. if (pins & ATMEL_UART_RTS)
  974. at91_set_B_periph(AT91_PIN_PC9, 0); /* RTS2 */
  975. if (pins & ATMEL_UART_CTS)
  976. at91_set_B_periph(AT91_PIN_PC11, 0); /* CTS2 */
  977. }
  978. static struct resource uart3_resources[] = {
  979. [0] = {
  980. .start = AT91SAM9G45_BASE_US3,
  981. .end = AT91SAM9G45_BASE_US3 + SZ_16K - 1,
  982. .flags = IORESOURCE_MEM,
  983. },
  984. [1] = {
  985. .start = AT91SAM9G45_ID_US3,
  986. .end = AT91SAM9G45_ID_US3,
  987. .flags = IORESOURCE_IRQ,
  988. },
  989. };
  990. static struct atmel_uart_data uart3_data = {
  991. .use_dma_tx = 1,
  992. .use_dma_rx = 1,
  993. };
  994. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  995. static struct platform_device at91sam9g45_uart3_device = {
  996. .name = "atmel_usart",
  997. .id = 4,
  998. .dev = {
  999. .dma_mask = &uart3_dmamask,
  1000. .coherent_dma_mask = DMA_BIT_MASK(32),
  1001. .platform_data = &uart3_data,
  1002. },
  1003. .resource = uart3_resources,
  1004. .num_resources = ARRAY_SIZE(uart3_resources),
  1005. };
  1006. static inline void configure_usart3_pins(unsigned pins)
  1007. {
  1008. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD3 */
  1009. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD3 */
  1010. if (pins & ATMEL_UART_RTS)
  1011. at91_set_B_periph(AT91_PIN_PA23, 0); /* RTS3 */
  1012. if (pins & ATMEL_UART_CTS)
  1013. at91_set_B_periph(AT91_PIN_PA24, 0); /* CTS3 */
  1014. }
  1015. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1016. struct platform_device *atmel_default_console_device; /* the serial console device */
  1017. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1018. {
  1019. struct platform_device *pdev;
  1020. switch (id) {
  1021. case 0: /* DBGU */
  1022. pdev = &at91sam9g45_dbgu_device;
  1023. configure_dbgu_pins();
  1024. at91_clock_associate("mck", &pdev->dev, "usart");
  1025. break;
  1026. case AT91SAM9G45_ID_US0:
  1027. pdev = &at91sam9g45_uart0_device;
  1028. configure_usart0_pins(pins);
  1029. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  1030. break;
  1031. case AT91SAM9G45_ID_US1:
  1032. pdev = &at91sam9g45_uart1_device;
  1033. configure_usart1_pins(pins);
  1034. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  1035. break;
  1036. case AT91SAM9G45_ID_US2:
  1037. pdev = &at91sam9g45_uart2_device;
  1038. configure_usart2_pins(pins);
  1039. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  1040. break;
  1041. case AT91SAM9G45_ID_US3:
  1042. pdev = &at91sam9g45_uart3_device;
  1043. configure_usart3_pins(pins);
  1044. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  1045. break;
  1046. default:
  1047. return;
  1048. }
  1049. pdev->id = portnr; /* update to mapped ID */
  1050. if (portnr < ATMEL_MAX_UART)
  1051. at91_uarts[portnr] = pdev;
  1052. }
  1053. void __init at91_set_serial_console(unsigned portnr)
  1054. {
  1055. if (portnr < ATMEL_MAX_UART)
  1056. atmel_default_console_device = at91_uarts[portnr];
  1057. }
  1058. void __init at91_add_device_serial(void)
  1059. {
  1060. int i;
  1061. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1062. if (at91_uarts[i])
  1063. platform_device_register(at91_uarts[i]);
  1064. }
  1065. if (!atmel_default_console_device)
  1066. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1067. }
  1068. #else
  1069. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1070. void __init at91_set_serial_console(unsigned portnr) {}
  1071. void __init at91_add_device_serial(void) {}
  1072. #endif
  1073. /* -------------------------------------------------------------------- */
  1074. /*
  1075. * These devices are always present and don't need any board-specific
  1076. * setup.
  1077. */
  1078. static int __init at91_add_standard_devices(void)
  1079. {
  1080. at91_add_device_hdmac();
  1081. at91_add_device_rtc();
  1082. at91_add_device_rtt();
  1083. at91_add_device_watchdog();
  1084. at91_add_device_tc();
  1085. return 0;
  1086. }
  1087. arch_initcall(at91_add_standard_devices);