at91sam9g45_devices.c 45 KB

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