at91sam9g45_devices.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  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->cfg = ATC_FIFOCFG_HALFFIFO
  375. | ATC_SRC_H2SEL_HW | ATC_DST_H2SEL_HW;
  376. atslave->ctrla = ATC_SCSIZE_16 | ATC_DCSIZE_16;
  377. if (mmc_id == 0) /* MCI0 */
  378. atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI0)
  379. | ATC_DST_PER(AT_DMA_ID_MCI0);
  380. else /* MCI1 */
  381. atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI1)
  382. | ATC_DST_PER(AT_DMA_ID_MCI1);
  383. data->dma_slave = alt_atslave;
  384. }
  385. #endif
  386. /* input/irq */
  387. if (gpio_is_valid(data->slot[0].detect_pin)) {
  388. at91_set_gpio_input(data->slot[0].detect_pin, 1);
  389. at91_set_deglitch(data->slot[0].detect_pin, 1);
  390. }
  391. if (gpio_is_valid(data->slot[0].wp_pin))
  392. at91_set_gpio_input(data->slot[0].wp_pin, 1);
  393. if (mmc_id == 0) { /* MCI0 */
  394. /* CLK */
  395. at91_set_A_periph(AT91_PIN_PA0, 0);
  396. /* CMD */
  397. at91_set_A_periph(AT91_PIN_PA1, 1);
  398. /* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */
  399. at91_set_A_periph(AT91_PIN_PA2, 1);
  400. if (data->slot[0].bus_width == 4) {
  401. at91_set_A_periph(AT91_PIN_PA3, 1);
  402. at91_set_A_periph(AT91_PIN_PA4, 1);
  403. at91_set_A_periph(AT91_PIN_PA5, 1);
  404. if (data->slot[0].bus_width == 8) {
  405. at91_set_A_periph(AT91_PIN_PA6, 1);
  406. at91_set_A_periph(AT91_PIN_PA7, 1);
  407. at91_set_A_periph(AT91_PIN_PA8, 1);
  408. at91_set_A_periph(AT91_PIN_PA9, 1);
  409. }
  410. }
  411. mmc0_data = *data;
  412. platform_device_register(&at91sam9g45_mmc0_device);
  413. } else { /* MCI1 */
  414. /* CLK */
  415. at91_set_A_periph(AT91_PIN_PA31, 0);
  416. /* CMD */
  417. at91_set_A_periph(AT91_PIN_PA22, 1);
  418. /* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */
  419. at91_set_A_periph(AT91_PIN_PA23, 1);
  420. if (data->slot[0].bus_width == 4) {
  421. at91_set_A_periph(AT91_PIN_PA24, 1);
  422. at91_set_A_periph(AT91_PIN_PA25, 1);
  423. at91_set_A_periph(AT91_PIN_PA26, 1);
  424. if (data->slot[0].bus_width == 8) {
  425. at91_set_A_periph(AT91_PIN_PA27, 1);
  426. at91_set_A_periph(AT91_PIN_PA28, 1);
  427. at91_set_A_periph(AT91_PIN_PA29, 1);
  428. at91_set_A_periph(AT91_PIN_PA30, 1);
  429. }
  430. }
  431. mmc1_data = *data;
  432. platform_device_register(&at91sam9g45_mmc1_device);
  433. }
  434. }
  435. #else
  436. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
  437. #endif
  438. /* --------------------------------------------------------------------
  439. * NAND / SmartMedia
  440. * -------------------------------------------------------------------- */
  441. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  442. static struct atmel_nand_data nand_data;
  443. #define NAND_BASE AT91_CHIPSELECT_3
  444. static struct resource nand_resources[] = {
  445. [0] = {
  446. .start = NAND_BASE,
  447. .end = NAND_BASE + SZ_256M - 1,
  448. .flags = IORESOURCE_MEM,
  449. },
  450. [1] = {
  451. .start = AT91SAM9G45_BASE_ECC,
  452. .end = AT91SAM9G45_BASE_ECC + SZ_512 - 1,
  453. .flags = IORESOURCE_MEM,
  454. }
  455. };
  456. static struct platform_device at91sam9g45_nand_device = {
  457. .name = "atmel_nand",
  458. .id = -1,
  459. .dev = {
  460. .platform_data = &nand_data,
  461. },
  462. .resource = nand_resources,
  463. .num_resources = ARRAY_SIZE(nand_resources),
  464. };
  465. void __init at91_add_device_nand(struct atmel_nand_data *data)
  466. {
  467. unsigned long csa;
  468. if (!data)
  469. return;
  470. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  471. at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
  472. /* enable pin */
  473. if (gpio_is_valid(data->enable_pin))
  474. at91_set_gpio_output(data->enable_pin, 1);
  475. /* ready/busy pin */
  476. if (gpio_is_valid(data->rdy_pin))
  477. at91_set_gpio_input(data->rdy_pin, 1);
  478. /* card detect pin */
  479. if (gpio_is_valid(data->det_pin))
  480. at91_set_gpio_input(data->det_pin, 1);
  481. nand_data = *data;
  482. platform_device_register(&at91sam9g45_nand_device);
  483. }
  484. #else
  485. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  486. #endif
  487. /* --------------------------------------------------------------------
  488. * TWI (i2c)
  489. * -------------------------------------------------------------------- */
  490. /*
  491. * Prefer the GPIO code since the TWI controller isn't robust
  492. * (gets overruns and underruns under load) and can only issue
  493. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  494. */
  495. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  496. static struct i2c_gpio_platform_data pdata_i2c0 = {
  497. .sda_pin = AT91_PIN_PA20,
  498. .sda_is_open_drain = 1,
  499. .scl_pin = AT91_PIN_PA21,
  500. .scl_is_open_drain = 1,
  501. .udelay = 5, /* ~100 kHz */
  502. };
  503. static struct platform_device at91sam9g45_twi0_device = {
  504. .name = "i2c-gpio",
  505. .id = 0,
  506. .dev.platform_data = &pdata_i2c0,
  507. };
  508. static struct i2c_gpio_platform_data pdata_i2c1 = {
  509. .sda_pin = AT91_PIN_PB10,
  510. .sda_is_open_drain = 1,
  511. .scl_pin = AT91_PIN_PB11,
  512. .scl_is_open_drain = 1,
  513. .udelay = 5, /* ~100 kHz */
  514. };
  515. static struct platform_device at91sam9g45_twi1_device = {
  516. .name = "i2c-gpio",
  517. .id = 1,
  518. .dev.platform_data = &pdata_i2c1,
  519. };
  520. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  521. {
  522. i2c_register_board_info(i2c_id, devices, nr_devices);
  523. if (i2c_id == 0) {
  524. at91_set_GPIO_periph(AT91_PIN_PA20, 1); /* TWD (SDA) */
  525. at91_set_multi_drive(AT91_PIN_PA20, 1);
  526. at91_set_GPIO_periph(AT91_PIN_PA21, 1); /* TWCK (SCL) */
  527. at91_set_multi_drive(AT91_PIN_PA21, 1);
  528. platform_device_register(&at91sam9g45_twi0_device);
  529. } else {
  530. at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* TWD (SDA) */
  531. at91_set_multi_drive(AT91_PIN_PB10, 1);
  532. at91_set_GPIO_periph(AT91_PIN_PB11, 1); /* TWCK (SCL) */
  533. at91_set_multi_drive(AT91_PIN_PB11, 1);
  534. platform_device_register(&at91sam9g45_twi1_device);
  535. }
  536. }
  537. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  538. static struct resource twi0_resources[] = {
  539. [0] = {
  540. .start = AT91SAM9G45_BASE_TWI0,
  541. .end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1,
  542. .flags = IORESOURCE_MEM,
  543. },
  544. [1] = {
  545. .start = AT91SAM9G45_ID_TWI0,
  546. .end = AT91SAM9G45_ID_TWI0,
  547. .flags = IORESOURCE_IRQ,
  548. },
  549. };
  550. static struct platform_device at91sam9g45_twi0_device = {
  551. .name = "at91_i2c",
  552. .id = 0,
  553. .resource = twi0_resources,
  554. .num_resources = ARRAY_SIZE(twi0_resources),
  555. };
  556. static struct resource twi1_resources[] = {
  557. [0] = {
  558. .start = AT91SAM9G45_BASE_TWI1,
  559. .end = AT91SAM9G45_BASE_TWI1 + SZ_16K - 1,
  560. .flags = IORESOURCE_MEM,
  561. },
  562. [1] = {
  563. .start = AT91SAM9G45_ID_TWI1,
  564. .end = AT91SAM9G45_ID_TWI1,
  565. .flags = IORESOURCE_IRQ,
  566. },
  567. };
  568. static struct platform_device at91sam9g45_twi1_device = {
  569. .name = "at91_i2c",
  570. .id = 1,
  571. .resource = twi1_resources,
  572. .num_resources = ARRAY_SIZE(twi1_resources),
  573. };
  574. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  575. {
  576. i2c_register_board_info(i2c_id, devices, nr_devices);
  577. /* pins used for TWI interface */
  578. if (i2c_id == 0) {
  579. at91_set_A_periph(AT91_PIN_PA20, 0); /* TWD */
  580. at91_set_multi_drive(AT91_PIN_PA20, 1);
  581. at91_set_A_periph(AT91_PIN_PA21, 0); /* TWCK */
  582. at91_set_multi_drive(AT91_PIN_PA21, 1);
  583. platform_device_register(&at91sam9g45_twi0_device);
  584. } else {
  585. at91_set_A_periph(AT91_PIN_PB10, 0); /* TWD */
  586. at91_set_multi_drive(AT91_PIN_PB10, 1);
  587. at91_set_A_periph(AT91_PIN_PB11, 0); /* TWCK */
  588. at91_set_multi_drive(AT91_PIN_PB11, 1);
  589. platform_device_register(&at91sam9g45_twi1_device);
  590. }
  591. }
  592. #else
  593. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {}
  594. #endif
  595. /* --------------------------------------------------------------------
  596. * SPI
  597. * -------------------------------------------------------------------- */
  598. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  599. static u64 spi_dmamask = DMA_BIT_MASK(32);
  600. static struct resource spi0_resources[] = {
  601. [0] = {
  602. .start = AT91SAM9G45_BASE_SPI0,
  603. .end = AT91SAM9G45_BASE_SPI0 + SZ_16K - 1,
  604. .flags = IORESOURCE_MEM,
  605. },
  606. [1] = {
  607. .start = AT91SAM9G45_ID_SPI0,
  608. .end = AT91SAM9G45_ID_SPI0,
  609. .flags = IORESOURCE_IRQ,
  610. },
  611. };
  612. static struct platform_device at91sam9g45_spi0_device = {
  613. .name = "atmel_spi",
  614. .id = 0,
  615. .dev = {
  616. .dma_mask = &spi_dmamask,
  617. .coherent_dma_mask = DMA_BIT_MASK(32),
  618. },
  619. .resource = spi0_resources,
  620. .num_resources = ARRAY_SIZE(spi0_resources),
  621. };
  622. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PB18, AT91_PIN_PB19, AT91_PIN_PD27 };
  623. static struct resource spi1_resources[] = {
  624. [0] = {
  625. .start = AT91SAM9G45_BASE_SPI1,
  626. .end = AT91SAM9G45_BASE_SPI1 + SZ_16K - 1,
  627. .flags = IORESOURCE_MEM,
  628. },
  629. [1] = {
  630. .start = AT91SAM9G45_ID_SPI1,
  631. .end = AT91SAM9G45_ID_SPI1,
  632. .flags = IORESOURCE_IRQ,
  633. },
  634. };
  635. static struct platform_device at91sam9g45_spi1_device = {
  636. .name = "atmel_spi",
  637. .id = 1,
  638. .dev = {
  639. .dma_mask = &spi_dmamask,
  640. .coherent_dma_mask = DMA_BIT_MASK(32),
  641. },
  642. .resource = spi1_resources,
  643. .num_resources = ARRAY_SIZE(spi1_resources),
  644. };
  645. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB17, AT91_PIN_PD28, AT91_PIN_PD18, AT91_PIN_PD19 };
  646. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  647. {
  648. int i;
  649. unsigned long cs_pin;
  650. short enable_spi0 = 0;
  651. short enable_spi1 = 0;
  652. /* Choose SPI chip-selects */
  653. for (i = 0; i < nr_devices; i++) {
  654. if (devices[i].controller_data)
  655. cs_pin = (unsigned long) devices[i].controller_data;
  656. else if (devices[i].bus_num == 0)
  657. cs_pin = spi0_standard_cs[devices[i].chip_select];
  658. else
  659. cs_pin = spi1_standard_cs[devices[i].chip_select];
  660. if (devices[i].bus_num == 0)
  661. enable_spi0 = 1;
  662. else
  663. enable_spi1 = 1;
  664. /* enable chip-select pin */
  665. at91_set_gpio_output(cs_pin, 1);
  666. /* pass chip-select pin to driver */
  667. devices[i].controller_data = (void *) cs_pin;
  668. }
  669. spi_register_board_info(devices, nr_devices);
  670. /* Configure SPI bus(es) */
  671. if (enable_spi0) {
  672. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI0_MISO */
  673. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI0_MOSI */
  674. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI0_SPCK */
  675. platform_device_register(&at91sam9g45_spi0_device);
  676. }
  677. if (enable_spi1) {
  678. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_MISO */
  679. at91_set_A_periph(AT91_PIN_PB15, 0); /* SPI1_MOSI */
  680. at91_set_A_periph(AT91_PIN_PB16, 0); /* SPI1_SPCK */
  681. platform_device_register(&at91sam9g45_spi1_device);
  682. }
  683. }
  684. #else
  685. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  686. #endif
  687. /* --------------------------------------------------------------------
  688. * AC97
  689. * -------------------------------------------------------------------- */
  690. #if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
  691. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  692. static struct ac97c_platform_data ac97_data;
  693. static struct resource ac97_resources[] = {
  694. [0] = {
  695. .start = AT91SAM9G45_BASE_AC97C,
  696. .end = AT91SAM9G45_BASE_AC97C + SZ_16K - 1,
  697. .flags = IORESOURCE_MEM,
  698. },
  699. [1] = {
  700. .start = AT91SAM9G45_ID_AC97C,
  701. .end = AT91SAM9G45_ID_AC97C,
  702. .flags = IORESOURCE_IRQ,
  703. },
  704. };
  705. static struct platform_device at91sam9g45_ac97_device = {
  706. .name = "atmel_ac97c",
  707. .id = 0,
  708. .dev = {
  709. .dma_mask = &ac97_dmamask,
  710. .coherent_dma_mask = DMA_BIT_MASK(32),
  711. .platform_data = &ac97_data,
  712. },
  713. .resource = ac97_resources,
  714. .num_resources = ARRAY_SIZE(ac97_resources),
  715. };
  716. void __init at91_add_device_ac97(struct ac97c_platform_data *data)
  717. {
  718. if (!data)
  719. return;
  720. at91_set_A_periph(AT91_PIN_PD8, 0); /* AC97FS */
  721. at91_set_A_periph(AT91_PIN_PD9, 0); /* AC97CK */
  722. at91_set_A_periph(AT91_PIN_PD7, 0); /* AC97TX */
  723. at91_set_A_periph(AT91_PIN_PD6, 0); /* AC97RX */
  724. /* reset */
  725. if (gpio_is_valid(data->reset_pin))
  726. at91_set_gpio_output(data->reset_pin, 0);
  727. ac97_data = *data;
  728. platform_device_register(&at91sam9g45_ac97_device);
  729. }
  730. #else
  731. void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
  732. #endif
  733. /* --------------------------------------------------------------------
  734. * Image Sensor Interface
  735. * -------------------------------------------------------------------- */
  736. #if defined(CONFIG_VIDEO_ATMEL_ISI) || defined(CONFIG_VIDEO_ATMEL_ISI_MODULE)
  737. static u64 isi_dmamask = DMA_BIT_MASK(32);
  738. static struct isi_platform_data isi_data;
  739. struct resource isi_resources[] = {
  740. [0] = {
  741. .start = AT91SAM9G45_BASE_ISI,
  742. .end = AT91SAM9G45_BASE_ISI + SZ_16K - 1,
  743. .flags = IORESOURCE_MEM,
  744. },
  745. [1] = {
  746. .start = AT91SAM9G45_ID_ISI,
  747. .end = AT91SAM9G45_ID_ISI,
  748. .flags = IORESOURCE_IRQ,
  749. },
  750. };
  751. static struct platform_device at91sam9g45_isi_device = {
  752. .name = "atmel_isi",
  753. .id = 0,
  754. .dev = {
  755. .dma_mask = &isi_dmamask,
  756. .coherent_dma_mask = DMA_BIT_MASK(32),
  757. .platform_data = &isi_data,
  758. },
  759. .resource = isi_resources,
  760. .num_resources = ARRAY_SIZE(isi_resources),
  761. };
  762. static struct clk_lookup isi_mck_lookups[] = {
  763. CLKDEV_CON_DEV_ID("isi_mck", "atmel_isi.0", NULL),
  764. };
  765. void __init at91_add_device_isi(struct isi_platform_data *data,
  766. bool use_pck_as_mck)
  767. {
  768. struct clk *pck;
  769. struct clk *parent;
  770. if (!data)
  771. return;
  772. isi_data = *data;
  773. at91_set_A_periph(AT91_PIN_PB20, 0); /* ISI_D0 */
  774. at91_set_A_periph(AT91_PIN_PB21, 0); /* ISI_D1 */
  775. at91_set_A_periph(AT91_PIN_PB22, 0); /* ISI_D2 */
  776. at91_set_A_periph(AT91_PIN_PB23, 0); /* ISI_D3 */
  777. at91_set_A_periph(AT91_PIN_PB24, 0); /* ISI_D4 */
  778. at91_set_A_periph(AT91_PIN_PB25, 0); /* ISI_D5 */
  779. at91_set_A_periph(AT91_PIN_PB26, 0); /* ISI_D6 */
  780. at91_set_A_periph(AT91_PIN_PB27, 0); /* ISI_D7 */
  781. at91_set_A_periph(AT91_PIN_PB28, 0); /* ISI_PCK */
  782. at91_set_A_periph(AT91_PIN_PB30, 0); /* ISI_HSYNC */
  783. at91_set_A_periph(AT91_PIN_PB29, 0); /* ISI_VSYNC */
  784. at91_set_B_periph(AT91_PIN_PB8, 0); /* ISI_PD8 */
  785. at91_set_B_periph(AT91_PIN_PB9, 0); /* ISI_PD9 */
  786. at91_set_B_periph(AT91_PIN_PB10, 0); /* ISI_PD10 */
  787. at91_set_B_periph(AT91_PIN_PB11, 0); /* ISI_PD11 */
  788. platform_device_register(&at91sam9g45_isi_device);
  789. if (use_pck_as_mck) {
  790. at91_set_B_periph(AT91_PIN_PB31, 0); /* ISI_MCK (PCK1) */
  791. pck = clk_get(NULL, "pck1");
  792. parent = clk_get(NULL, "plla");
  793. BUG_ON(IS_ERR(pck) || IS_ERR(parent));
  794. if (clk_set_parent(pck, parent)) {
  795. pr_err("Failed to set PCK's parent\n");
  796. } else {
  797. /* Register PCK as ISI_MCK */
  798. isi_mck_lookups[0].clk = pck;
  799. clkdev_add_table(isi_mck_lookups,
  800. ARRAY_SIZE(isi_mck_lookups));
  801. }
  802. clk_put(pck);
  803. clk_put(parent);
  804. }
  805. }
  806. #else
  807. void __init at91_add_device_isi(struct isi_platform_data *data,
  808. bool use_pck_as_mck) {}
  809. #endif
  810. /* --------------------------------------------------------------------
  811. * LCD Controller
  812. * -------------------------------------------------------------------- */
  813. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  814. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  815. static struct atmel_lcdfb_info lcdc_data;
  816. static struct resource lcdc_resources[] = {
  817. [0] = {
  818. .start = AT91SAM9G45_LCDC_BASE,
  819. .end = AT91SAM9G45_LCDC_BASE + SZ_4K - 1,
  820. .flags = IORESOURCE_MEM,
  821. },
  822. [1] = {
  823. .start = AT91SAM9G45_ID_LCDC,
  824. .end = AT91SAM9G45_ID_LCDC,
  825. .flags = IORESOURCE_IRQ,
  826. },
  827. };
  828. static struct platform_device at91_lcdc_device = {
  829. .name = "atmel_lcdfb",
  830. .id = 0,
  831. .dev = {
  832. .dma_mask = &lcdc_dmamask,
  833. .coherent_dma_mask = DMA_BIT_MASK(32),
  834. .platform_data = &lcdc_data,
  835. },
  836. .resource = lcdc_resources,
  837. .num_resources = ARRAY_SIZE(lcdc_resources),
  838. };
  839. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  840. {
  841. if (!data)
  842. return;
  843. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  844. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  845. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  846. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  847. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  848. at91_set_A_periph(AT91_PIN_PE6, 0); /* LCDDEN */
  849. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  850. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  851. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  852. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  853. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  854. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  855. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  856. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  857. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  858. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  859. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  860. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  861. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  862. at91_set_A_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  863. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  864. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  865. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  866. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  867. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  868. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  869. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  870. at91_set_A_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  871. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  872. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  873. lcdc_data = *data;
  874. platform_device_register(&at91_lcdc_device);
  875. }
  876. #else
  877. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  878. #endif
  879. /* --------------------------------------------------------------------
  880. * Timer/Counter block
  881. * -------------------------------------------------------------------- */
  882. #ifdef CONFIG_ATMEL_TCLIB
  883. static struct resource tcb0_resources[] = {
  884. [0] = {
  885. .start = AT91SAM9G45_BASE_TCB0,
  886. .end = AT91SAM9G45_BASE_TCB0 + SZ_256 - 1,
  887. .flags = IORESOURCE_MEM,
  888. },
  889. [1] = {
  890. .start = AT91SAM9G45_ID_TCB,
  891. .end = AT91SAM9G45_ID_TCB,
  892. .flags = IORESOURCE_IRQ,
  893. },
  894. };
  895. static struct platform_device at91sam9g45_tcb0_device = {
  896. .name = "atmel_tcb",
  897. .id = 0,
  898. .resource = tcb0_resources,
  899. .num_resources = ARRAY_SIZE(tcb0_resources),
  900. };
  901. /* TCB1 begins with TC3 */
  902. static struct resource tcb1_resources[] = {
  903. [0] = {
  904. .start = AT91SAM9G45_BASE_TCB1,
  905. .end = AT91SAM9G45_BASE_TCB1 + SZ_256 - 1,
  906. .flags = IORESOURCE_MEM,
  907. },
  908. [1] = {
  909. .start = AT91SAM9G45_ID_TCB,
  910. .end = AT91SAM9G45_ID_TCB,
  911. .flags = IORESOURCE_IRQ,
  912. },
  913. };
  914. static struct platform_device at91sam9g45_tcb1_device = {
  915. .name = "atmel_tcb",
  916. .id = 1,
  917. .resource = tcb1_resources,
  918. .num_resources = ARRAY_SIZE(tcb1_resources),
  919. };
  920. #if defined(CONFIG_OF)
  921. static struct of_device_id tcb_ids[] = {
  922. { .compatible = "atmel,at91rm9200-tcb" },
  923. { /*sentinel*/ }
  924. };
  925. #endif
  926. static void __init at91_add_device_tc(void)
  927. {
  928. #if defined(CONFIG_OF)
  929. struct device_node *np;
  930. np = of_find_matching_node(NULL, tcb_ids);
  931. if (np) {
  932. of_node_put(np);
  933. return;
  934. }
  935. #endif
  936. platform_device_register(&at91sam9g45_tcb0_device);
  937. platform_device_register(&at91sam9g45_tcb1_device);
  938. }
  939. #else
  940. static void __init at91_add_device_tc(void) { }
  941. #endif
  942. /* --------------------------------------------------------------------
  943. * RTC
  944. * -------------------------------------------------------------------- */
  945. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  946. static struct resource rtc_resources[] = {
  947. [0] = {
  948. .start = AT91SAM9G45_BASE_RTC,
  949. .end = AT91SAM9G45_BASE_RTC + SZ_256 - 1,
  950. .flags = IORESOURCE_MEM,
  951. },
  952. [1] = {
  953. .start = AT91_ID_SYS,
  954. .end = AT91_ID_SYS,
  955. .flags = IORESOURCE_IRQ,
  956. },
  957. };
  958. static struct platform_device at91sam9g45_rtc_device = {
  959. .name = "at91_rtc",
  960. .id = -1,
  961. .resource = rtc_resources,
  962. .num_resources = ARRAY_SIZE(rtc_resources),
  963. };
  964. static void __init at91_add_device_rtc(void)
  965. {
  966. platform_device_register(&at91sam9g45_rtc_device);
  967. }
  968. #else
  969. static void __init at91_add_device_rtc(void) {}
  970. #endif
  971. /* --------------------------------------------------------------------
  972. * Touchscreen
  973. * -------------------------------------------------------------------- */
  974. #if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE)
  975. static u64 tsadcc_dmamask = DMA_BIT_MASK(32);
  976. static struct at91_tsadcc_data tsadcc_data;
  977. static struct resource tsadcc_resources[] = {
  978. [0] = {
  979. .start = AT91SAM9G45_BASE_TSC,
  980. .end = AT91SAM9G45_BASE_TSC + SZ_16K - 1,
  981. .flags = IORESOURCE_MEM,
  982. },
  983. [1] = {
  984. .start = AT91SAM9G45_ID_TSC,
  985. .end = AT91SAM9G45_ID_TSC,
  986. .flags = IORESOURCE_IRQ,
  987. }
  988. };
  989. static struct platform_device at91sam9g45_tsadcc_device = {
  990. .name = "atmel_tsadcc",
  991. .id = -1,
  992. .dev = {
  993. .dma_mask = &tsadcc_dmamask,
  994. .coherent_dma_mask = DMA_BIT_MASK(32),
  995. .platform_data = &tsadcc_data,
  996. },
  997. .resource = tsadcc_resources,
  998. .num_resources = ARRAY_SIZE(tsadcc_resources),
  999. };
  1000. void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data)
  1001. {
  1002. if (!data)
  1003. return;
  1004. at91_set_gpio_input(AT91_PIN_PD20, 0); /* AD0_XR */
  1005. at91_set_gpio_input(AT91_PIN_PD21, 0); /* AD1_XL */
  1006. at91_set_gpio_input(AT91_PIN_PD22, 0); /* AD2_YT */
  1007. at91_set_gpio_input(AT91_PIN_PD23, 0); /* AD3_TB */
  1008. tsadcc_data = *data;
  1009. platform_device_register(&at91sam9g45_tsadcc_device);
  1010. }
  1011. #else
  1012. void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) {}
  1013. #endif
  1014. /* --------------------------------------------------------------------
  1015. * RTT
  1016. * -------------------------------------------------------------------- */
  1017. static struct resource rtt_resources[] = {
  1018. {
  1019. .start = AT91SAM9G45_BASE_RTT,
  1020. .end = AT91SAM9G45_BASE_RTT + SZ_16 - 1,
  1021. .flags = IORESOURCE_MEM,
  1022. }, {
  1023. .flags = IORESOURCE_MEM,
  1024. }
  1025. };
  1026. static struct platform_device at91sam9g45_rtt_device = {
  1027. .name = "at91_rtt",
  1028. .id = 0,
  1029. .resource = rtt_resources,
  1030. };
  1031. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  1032. static void __init at91_add_device_rtt_rtc(void)
  1033. {
  1034. at91sam9g45_rtt_device.name = "rtc-at91sam9";
  1035. /*
  1036. * The second resource is needed:
  1037. * GPBR will serve as the storage for RTC time offset
  1038. */
  1039. at91sam9g45_rtt_device.num_resources = 2;
  1040. rtt_resources[1].start = AT91SAM9G45_BASE_GPBR +
  1041. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  1042. rtt_resources[1].end = rtt_resources[1].start + 3;
  1043. }
  1044. #else
  1045. static void __init at91_add_device_rtt_rtc(void)
  1046. {
  1047. /* Only one resource is needed: RTT not used as RTC */
  1048. at91sam9g45_rtt_device.num_resources = 1;
  1049. }
  1050. #endif
  1051. static void __init at91_add_device_rtt(void)
  1052. {
  1053. at91_add_device_rtt_rtc();
  1054. platform_device_register(&at91sam9g45_rtt_device);
  1055. }
  1056. /* --------------------------------------------------------------------
  1057. * TRNG
  1058. * -------------------------------------------------------------------- */
  1059. #if defined(CONFIG_HW_RANDOM_ATMEL) || defined(CONFIG_HW_RANDOM_ATMEL_MODULE)
  1060. static struct resource trng_resources[] = {
  1061. {
  1062. .start = AT91SAM9G45_BASE_TRNG,
  1063. .end = AT91SAM9G45_BASE_TRNG + SZ_16K - 1,
  1064. .flags = IORESOURCE_MEM,
  1065. },
  1066. };
  1067. static struct platform_device at91sam9g45_trng_device = {
  1068. .name = "atmel-trng",
  1069. .id = -1,
  1070. .resource = trng_resources,
  1071. .num_resources = ARRAY_SIZE(trng_resources),
  1072. };
  1073. static void __init at91_add_device_trng(void)
  1074. {
  1075. platform_device_register(&at91sam9g45_trng_device);
  1076. }
  1077. #else
  1078. static void __init at91_add_device_trng(void) {}
  1079. #endif
  1080. /* --------------------------------------------------------------------
  1081. * Watchdog
  1082. * -------------------------------------------------------------------- */
  1083. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  1084. static struct resource wdt_resources[] = {
  1085. {
  1086. .start = AT91SAM9G45_BASE_WDT,
  1087. .end = AT91SAM9G45_BASE_WDT + SZ_16 - 1,
  1088. .flags = IORESOURCE_MEM,
  1089. }
  1090. };
  1091. static struct platform_device at91sam9g45_wdt_device = {
  1092. .name = "at91_wdt",
  1093. .id = -1,
  1094. .resource = wdt_resources,
  1095. .num_resources = ARRAY_SIZE(wdt_resources),
  1096. };
  1097. static void __init at91_add_device_watchdog(void)
  1098. {
  1099. platform_device_register(&at91sam9g45_wdt_device);
  1100. }
  1101. #else
  1102. static void __init at91_add_device_watchdog(void) {}
  1103. #endif
  1104. /* --------------------------------------------------------------------
  1105. * PWM
  1106. * --------------------------------------------------------------------*/
  1107. #if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE)
  1108. static u32 pwm_mask;
  1109. static struct resource pwm_resources[] = {
  1110. [0] = {
  1111. .start = AT91SAM9G45_BASE_PWMC,
  1112. .end = AT91SAM9G45_BASE_PWMC + SZ_16K - 1,
  1113. .flags = IORESOURCE_MEM,
  1114. },
  1115. [1] = {
  1116. .start = AT91SAM9G45_ID_PWMC,
  1117. .end = AT91SAM9G45_ID_PWMC,
  1118. .flags = IORESOURCE_IRQ,
  1119. },
  1120. };
  1121. static struct platform_device at91sam9g45_pwm0_device = {
  1122. .name = "atmel_pwm",
  1123. .id = -1,
  1124. .dev = {
  1125. .platform_data = &pwm_mask,
  1126. },
  1127. .resource = pwm_resources,
  1128. .num_resources = ARRAY_SIZE(pwm_resources),
  1129. };
  1130. void __init at91_add_device_pwm(u32 mask)
  1131. {
  1132. if (mask & (1 << AT91_PWM0))
  1133. at91_set_B_periph(AT91_PIN_PD24, 1); /* enable PWM0 */
  1134. if (mask & (1 << AT91_PWM1))
  1135. at91_set_B_periph(AT91_PIN_PD31, 1); /* enable PWM1 */
  1136. if (mask & (1 << AT91_PWM2))
  1137. at91_set_B_periph(AT91_PIN_PD26, 1); /* enable PWM2 */
  1138. if (mask & (1 << AT91_PWM3))
  1139. at91_set_B_periph(AT91_PIN_PD0, 1); /* enable PWM3 */
  1140. pwm_mask = mask;
  1141. platform_device_register(&at91sam9g45_pwm0_device);
  1142. }
  1143. #else
  1144. void __init at91_add_device_pwm(u32 mask) {}
  1145. #endif
  1146. /* --------------------------------------------------------------------
  1147. * SSC -- Synchronous Serial Controller
  1148. * -------------------------------------------------------------------- */
  1149. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  1150. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  1151. static struct resource ssc0_resources[] = {
  1152. [0] = {
  1153. .start = AT91SAM9G45_BASE_SSC0,
  1154. .end = AT91SAM9G45_BASE_SSC0 + SZ_16K - 1,
  1155. .flags = IORESOURCE_MEM,
  1156. },
  1157. [1] = {
  1158. .start = AT91SAM9G45_ID_SSC0,
  1159. .end = AT91SAM9G45_ID_SSC0,
  1160. .flags = IORESOURCE_IRQ,
  1161. },
  1162. };
  1163. static struct platform_device at91sam9g45_ssc0_device = {
  1164. .name = "ssc",
  1165. .id = 0,
  1166. .dev = {
  1167. .dma_mask = &ssc0_dmamask,
  1168. .coherent_dma_mask = DMA_BIT_MASK(32),
  1169. },
  1170. .resource = ssc0_resources,
  1171. .num_resources = ARRAY_SIZE(ssc0_resources),
  1172. };
  1173. static inline void configure_ssc0_pins(unsigned pins)
  1174. {
  1175. if (pins & ATMEL_SSC_TF)
  1176. at91_set_A_periph(AT91_PIN_PD1, 1);
  1177. if (pins & ATMEL_SSC_TK)
  1178. at91_set_A_periph(AT91_PIN_PD0, 1);
  1179. if (pins & ATMEL_SSC_TD)
  1180. at91_set_A_periph(AT91_PIN_PD2, 1);
  1181. if (pins & ATMEL_SSC_RD)
  1182. at91_set_A_periph(AT91_PIN_PD3, 1);
  1183. if (pins & ATMEL_SSC_RK)
  1184. at91_set_A_periph(AT91_PIN_PD4, 1);
  1185. if (pins & ATMEL_SSC_RF)
  1186. at91_set_A_periph(AT91_PIN_PD5, 1);
  1187. }
  1188. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  1189. static struct resource ssc1_resources[] = {
  1190. [0] = {
  1191. .start = AT91SAM9G45_BASE_SSC1,
  1192. .end = AT91SAM9G45_BASE_SSC1 + SZ_16K - 1,
  1193. .flags = IORESOURCE_MEM,
  1194. },
  1195. [1] = {
  1196. .start = AT91SAM9G45_ID_SSC1,
  1197. .end = AT91SAM9G45_ID_SSC1,
  1198. .flags = IORESOURCE_IRQ,
  1199. },
  1200. };
  1201. static struct platform_device at91sam9g45_ssc1_device = {
  1202. .name = "ssc",
  1203. .id = 1,
  1204. .dev = {
  1205. .dma_mask = &ssc1_dmamask,
  1206. .coherent_dma_mask = DMA_BIT_MASK(32),
  1207. },
  1208. .resource = ssc1_resources,
  1209. .num_resources = ARRAY_SIZE(ssc1_resources),
  1210. };
  1211. static inline void configure_ssc1_pins(unsigned pins)
  1212. {
  1213. if (pins & ATMEL_SSC_TF)
  1214. at91_set_A_periph(AT91_PIN_PD14, 1);
  1215. if (pins & ATMEL_SSC_TK)
  1216. at91_set_A_periph(AT91_PIN_PD12, 1);
  1217. if (pins & ATMEL_SSC_TD)
  1218. at91_set_A_periph(AT91_PIN_PD10, 1);
  1219. if (pins & ATMEL_SSC_RD)
  1220. at91_set_A_periph(AT91_PIN_PD11, 1);
  1221. if (pins & ATMEL_SSC_RK)
  1222. at91_set_A_periph(AT91_PIN_PD13, 1);
  1223. if (pins & ATMEL_SSC_RF)
  1224. at91_set_A_periph(AT91_PIN_PD15, 1);
  1225. }
  1226. /*
  1227. * SSC controllers are accessed through library code, instead of any
  1228. * kind of all-singing/all-dancing driver. For example one could be
  1229. * used by a particular I2S audio codec's driver, while another one
  1230. * on the same system might be used by a custom data capture driver.
  1231. */
  1232. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  1233. {
  1234. struct platform_device *pdev;
  1235. /*
  1236. * NOTE: caller is responsible for passing information matching
  1237. * "pins" to whatever will be using each particular controller.
  1238. */
  1239. switch (id) {
  1240. case AT91SAM9G45_ID_SSC0:
  1241. pdev = &at91sam9g45_ssc0_device;
  1242. configure_ssc0_pins(pins);
  1243. break;
  1244. case AT91SAM9G45_ID_SSC1:
  1245. pdev = &at91sam9g45_ssc1_device;
  1246. configure_ssc1_pins(pins);
  1247. break;
  1248. default:
  1249. return;
  1250. }
  1251. platform_device_register(pdev);
  1252. }
  1253. #else
  1254. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  1255. #endif
  1256. /* --------------------------------------------------------------------
  1257. * UART
  1258. * -------------------------------------------------------------------- */
  1259. #if defined(CONFIG_SERIAL_ATMEL)
  1260. static struct resource dbgu_resources[] = {
  1261. [0] = {
  1262. .start = AT91SAM9G45_BASE_DBGU,
  1263. .end = AT91SAM9G45_BASE_DBGU + SZ_512 - 1,
  1264. .flags = IORESOURCE_MEM,
  1265. },
  1266. [1] = {
  1267. .start = AT91_ID_SYS,
  1268. .end = AT91_ID_SYS,
  1269. .flags = IORESOURCE_IRQ,
  1270. },
  1271. };
  1272. static struct atmel_uart_data dbgu_data = {
  1273. .use_dma_tx = 0,
  1274. .use_dma_rx = 0,
  1275. };
  1276. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  1277. static struct platform_device at91sam9g45_dbgu_device = {
  1278. .name = "atmel_usart",
  1279. .id = 0,
  1280. .dev = {
  1281. .dma_mask = &dbgu_dmamask,
  1282. .coherent_dma_mask = DMA_BIT_MASK(32),
  1283. .platform_data = &dbgu_data,
  1284. },
  1285. .resource = dbgu_resources,
  1286. .num_resources = ARRAY_SIZE(dbgu_resources),
  1287. };
  1288. static inline void configure_dbgu_pins(void)
  1289. {
  1290. at91_set_A_periph(AT91_PIN_PB12, 0); /* DRXD */
  1291. at91_set_A_periph(AT91_PIN_PB13, 1); /* DTXD */
  1292. }
  1293. static struct resource uart0_resources[] = {
  1294. [0] = {
  1295. .start = AT91SAM9G45_BASE_US0,
  1296. .end = AT91SAM9G45_BASE_US0 + SZ_16K - 1,
  1297. .flags = IORESOURCE_MEM,
  1298. },
  1299. [1] = {
  1300. .start = AT91SAM9G45_ID_US0,
  1301. .end = AT91SAM9G45_ID_US0,
  1302. .flags = IORESOURCE_IRQ,
  1303. },
  1304. };
  1305. static struct atmel_uart_data uart0_data = {
  1306. .use_dma_tx = 1,
  1307. .use_dma_rx = 1,
  1308. };
  1309. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  1310. static struct platform_device at91sam9g45_uart0_device = {
  1311. .name = "atmel_usart",
  1312. .id = 1,
  1313. .dev = {
  1314. .dma_mask = &uart0_dmamask,
  1315. .coherent_dma_mask = DMA_BIT_MASK(32),
  1316. .platform_data = &uart0_data,
  1317. },
  1318. .resource = uart0_resources,
  1319. .num_resources = ARRAY_SIZE(uart0_resources),
  1320. };
  1321. static inline void configure_usart0_pins(unsigned pins)
  1322. {
  1323. at91_set_A_periph(AT91_PIN_PB19, 1); /* TXD0 */
  1324. at91_set_A_periph(AT91_PIN_PB18, 0); /* RXD0 */
  1325. if (pins & ATMEL_UART_RTS)
  1326. at91_set_B_periph(AT91_PIN_PB17, 0); /* RTS0 */
  1327. if (pins & ATMEL_UART_CTS)
  1328. at91_set_B_periph(AT91_PIN_PB15, 0); /* CTS0 */
  1329. }
  1330. static struct resource uart1_resources[] = {
  1331. [0] = {
  1332. .start = AT91SAM9G45_BASE_US1,
  1333. .end = AT91SAM9G45_BASE_US1 + SZ_16K - 1,
  1334. .flags = IORESOURCE_MEM,
  1335. },
  1336. [1] = {
  1337. .start = AT91SAM9G45_ID_US1,
  1338. .end = AT91SAM9G45_ID_US1,
  1339. .flags = IORESOURCE_IRQ,
  1340. },
  1341. };
  1342. static struct atmel_uart_data uart1_data = {
  1343. .use_dma_tx = 1,
  1344. .use_dma_rx = 1,
  1345. };
  1346. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  1347. static struct platform_device at91sam9g45_uart1_device = {
  1348. .name = "atmel_usart",
  1349. .id = 2,
  1350. .dev = {
  1351. .dma_mask = &uart1_dmamask,
  1352. .coherent_dma_mask = DMA_BIT_MASK(32),
  1353. .platform_data = &uart1_data,
  1354. },
  1355. .resource = uart1_resources,
  1356. .num_resources = ARRAY_SIZE(uart1_resources),
  1357. };
  1358. static inline void configure_usart1_pins(unsigned pins)
  1359. {
  1360. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD1 */
  1361. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD1 */
  1362. if (pins & ATMEL_UART_RTS)
  1363. at91_set_A_periph(AT91_PIN_PD16, 0); /* RTS1 */
  1364. if (pins & ATMEL_UART_CTS)
  1365. at91_set_A_periph(AT91_PIN_PD17, 0); /* CTS1 */
  1366. }
  1367. static struct resource uart2_resources[] = {
  1368. [0] = {
  1369. .start = AT91SAM9G45_BASE_US2,
  1370. .end = AT91SAM9G45_BASE_US2 + SZ_16K - 1,
  1371. .flags = IORESOURCE_MEM,
  1372. },
  1373. [1] = {
  1374. .start = AT91SAM9G45_ID_US2,
  1375. .end = AT91SAM9G45_ID_US2,
  1376. .flags = IORESOURCE_IRQ,
  1377. },
  1378. };
  1379. static struct atmel_uart_data uart2_data = {
  1380. .use_dma_tx = 1,
  1381. .use_dma_rx = 1,
  1382. };
  1383. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  1384. static struct platform_device at91sam9g45_uart2_device = {
  1385. .name = "atmel_usart",
  1386. .id = 3,
  1387. .dev = {
  1388. .dma_mask = &uart2_dmamask,
  1389. .coherent_dma_mask = DMA_BIT_MASK(32),
  1390. .platform_data = &uart2_data,
  1391. },
  1392. .resource = uart2_resources,
  1393. .num_resources = ARRAY_SIZE(uart2_resources),
  1394. };
  1395. static inline void configure_usart2_pins(unsigned pins)
  1396. {
  1397. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD2 */
  1398. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD2 */
  1399. if (pins & ATMEL_UART_RTS)
  1400. at91_set_B_periph(AT91_PIN_PC9, 0); /* RTS2 */
  1401. if (pins & ATMEL_UART_CTS)
  1402. at91_set_B_periph(AT91_PIN_PC11, 0); /* CTS2 */
  1403. }
  1404. static struct resource uart3_resources[] = {
  1405. [0] = {
  1406. .start = AT91SAM9G45_BASE_US3,
  1407. .end = AT91SAM9G45_BASE_US3 + SZ_16K - 1,
  1408. .flags = IORESOURCE_MEM,
  1409. },
  1410. [1] = {
  1411. .start = AT91SAM9G45_ID_US3,
  1412. .end = AT91SAM9G45_ID_US3,
  1413. .flags = IORESOURCE_IRQ,
  1414. },
  1415. };
  1416. static struct atmel_uart_data uart3_data = {
  1417. .use_dma_tx = 1,
  1418. .use_dma_rx = 1,
  1419. };
  1420. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  1421. static struct platform_device at91sam9g45_uart3_device = {
  1422. .name = "atmel_usart",
  1423. .id = 4,
  1424. .dev = {
  1425. .dma_mask = &uart3_dmamask,
  1426. .coherent_dma_mask = DMA_BIT_MASK(32),
  1427. .platform_data = &uart3_data,
  1428. },
  1429. .resource = uart3_resources,
  1430. .num_resources = ARRAY_SIZE(uart3_resources),
  1431. };
  1432. static inline void configure_usart3_pins(unsigned pins)
  1433. {
  1434. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD3 */
  1435. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD3 */
  1436. if (pins & ATMEL_UART_RTS)
  1437. at91_set_B_periph(AT91_PIN_PA23, 0); /* RTS3 */
  1438. if (pins & ATMEL_UART_CTS)
  1439. at91_set_B_periph(AT91_PIN_PA24, 0); /* CTS3 */
  1440. }
  1441. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1442. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1443. {
  1444. struct platform_device *pdev;
  1445. struct atmel_uart_data *pdata;
  1446. switch (id) {
  1447. case 0: /* DBGU */
  1448. pdev = &at91sam9g45_dbgu_device;
  1449. configure_dbgu_pins();
  1450. break;
  1451. case AT91SAM9G45_ID_US0:
  1452. pdev = &at91sam9g45_uart0_device;
  1453. configure_usart0_pins(pins);
  1454. break;
  1455. case AT91SAM9G45_ID_US1:
  1456. pdev = &at91sam9g45_uart1_device;
  1457. configure_usart1_pins(pins);
  1458. break;
  1459. case AT91SAM9G45_ID_US2:
  1460. pdev = &at91sam9g45_uart2_device;
  1461. configure_usart2_pins(pins);
  1462. break;
  1463. case AT91SAM9G45_ID_US3:
  1464. pdev = &at91sam9g45_uart3_device;
  1465. configure_usart3_pins(pins);
  1466. break;
  1467. default:
  1468. return;
  1469. }
  1470. pdata = pdev->dev.platform_data;
  1471. pdata->num = portnr; /* update to mapped ID */
  1472. if (portnr < ATMEL_MAX_UART)
  1473. at91_uarts[portnr] = pdev;
  1474. }
  1475. void __init at91_set_serial_console(unsigned portnr)
  1476. {
  1477. if (portnr < ATMEL_MAX_UART) {
  1478. atmel_default_console_device = at91_uarts[portnr];
  1479. at91sam9g45_set_console_clock(at91_uarts[portnr]->id);
  1480. }
  1481. }
  1482. void __init at91_add_device_serial(void)
  1483. {
  1484. int i;
  1485. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1486. if (at91_uarts[i])
  1487. platform_device_register(at91_uarts[i]);
  1488. }
  1489. if (!atmel_default_console_device)
  1490. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1491. }
  1492. #else
  1493. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1494. void __init at91_set_serial_console(unsigned portnr) {}
  1495. void __init at91_add_device_serial(void) {}
  1496. #endif
  1497. /* -------------------------------------------------------------------- */
  1498. /*
  1499. * These devices are always present and don't need any board-specific
  1500. * setup.
  1501. */
  1502. static int __init at91_add_standard_devices(void)
  1503. {
  1504. at91_add_device_hdmac();
  1505. at91_add_device_rtc();
  1506. at91_add_device_rtt();
  1507. at91_add_device_trng();
  1508. at91_add_device_watchdog();
  1509. at91_add_device_tc();
  1510. return 0;
  1511. }
  1512. arch_initcall(at91_add_standard_devices);