at91sam9g45_devices.c 37 KB

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