at91sam9g45_devices.c 41 KB

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