at91sam9263_devices.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /*
  2. * arch/arm/mach-at91/at91sam9263_devices.c
  3. *
  4. * Copyright (C) 2007 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/platform_device.h>
  17. #include <linux/i2c-gpio.h>
  18. #include <linux/fb.h>
  19. #include <video/atmel_lcdc.h>
  20. #include <mach/board.h>
  21. #include <mach/at91sam9263.h>
  22. #include <mach/at91sam9263_matrix.h>
  23. #include <mach/at91_matrix.h>
  24. #include <mach/at91sam9_smc.h>
  25. #include "generic.h"
  26. /* --------------------------------------------------------------------
  27. * USB Host
  28. * -------------------------------------------------------------------- */
  29. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  30. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  31. static struct at91_usbh_data usbh_data;
  32. static struct resource usbh_resources[] = {
  33. [0] = {
  34. .start = AT91SAM9263_UHP_BASE,
  35. .end = AT91SAM9263_UHP_BASE + SZ_1M - 1,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. [1] = {
  39. .start = AT91SAM9263_ID_UHP,
  40. .end = AT91SAM9263_ID_UHP,
  41. .flags = IORESOURCE_IRQ,
  42. },
  43. };
  44. static struct platform_device at91_usbh_device = {
  45. .name = "at91_ohci",
  46. .id = -1,
  47. .dev = {
  48. .dma_mask = &ohci_dmamask,
  49. .coherent_dma_mask = DMA_BIT_MASK(32),
  50. .platform_data = &usbh_data,
  51. },
  52. .resource = usbh_resources,
  53. .num_resources = ARRAY_SIZE(usbh_resources),
  54. };
  55. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  56. {
  57. int i;
  58. if (!data)
  59. return;
  60. /* Enable VBus control for UHP ports */
  61. for (i = 0; i < data->ports; i++) {
  62. if (gpio_is_valid(data->vbus_pin[i]))
  63. at91_set_gpio_output(data->vbus_pin[i],
  64. data->vbus_pin_active_low[i]);
  65. }
  66. /* Enable overcurrent notification */
  67. for (i = 0; i < data->ports; i++) {
  68. if (data->overcurrent_pin[i])
  69. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  70. }
  71. usbh_data = *data;
  72. platform_device_register(&at91_usbh_device);
  73. }
  74. #else
  75. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  76. #endif
  77. /* --------------------------------------------------------------------
  78. * USB Device (Gadget)
  79. * -------------------------------------------------------------------- */
  80. #if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
  81. static struct at91_udc_data udc_data;
  82. static struct resource udc_resources[] = {
  83. [0] = {
  84. .start = AT91SAM9263_BASE_UDP,
  85. .end = AT91SAM9263_BASE_UDP + SZ_16K - 1,
  86. .flags = IORESOURCE_MEM,
  87. },
  88. [1] = {
  89. .start = AT91SAM9263_ID_UDP,
  90. .end = AT91SAM9263_ID_UDP,
  91. .flags = IORESOURCE_IRQ,
  92. },
  93. };
  94. static struct platform_device at91_udc_device = {
  95. .name = "at91_udc",
  96. .id = -1,
  97. .dev = {
  98. .platform_data = &udc_data,
  99. },
  100. .resource = udc_resources,
  101. .num_resources = ARRAY_SIZE(udc_resources),
  102. };
  103. void __init at91_add_device_udc(struct at91_udc_data *data)
  104. {
  105. if (!data)
  106. return;
  107. if (gpio_is_valid(data->vbus_pin)) {
  108. at91_set_gpio_input(data->vbus_pin, 0);
  109. at91_set_deglitch(data->vbus_pin, 1);
  110. }
  111. /* Pullup pin is handled internally by USB device peripheral */
  112. udc_data = *data;
  113. platform_device_register(&at91_udc_device);
  114. }
  115. #else
  116. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  117. #endif
  118. /* --------------------------------------------------------------------
  119. * Ethernet
  120. * -------------------------------------------------------------------- */
  121. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  122. static u64 eth_dmamask = DMA_BIT_MASK(32);
  123. static struct macb_platform_data eth_data;
  124. static struct resource eth_resources[] = {
  125. [0] = {
  126. .start = AT91SAM9263_BASE_EMAC,
  127. .end = AT91SAM9263_BASE_EMAC + SZ_16K - 1,
  128. .flags = IORESOURCE_MEM,
  129. },
  130. [1] = {
  131. .start = AT91SAM9263_ID_EMAC,
  132. .end = AT91SAM9263_ID_EMAC,
  133. .flags = IORESOURCE_IRQ,
  134. },
  135. };
  136. static struct platform_device at91sam9263_eth_device = {
  137. .name = "macb",
  138. .id = -1,
  139. .dev = {
  140. .dma_mask = &eth_dmamask,
  141. .coherent_dma_mask = DMA_BIT_MASK(32),
  142. .platform_data = &eth_data,
  143. },
  144. .resource = eth_resources,
  145. .num_resources = ARRAY_SIZE(eth_resources),
  146. };
  147. void __init at91_add_device_eth(struct macb_platform_data *data)
  148. {
  149. if (!data)
  150. return;
  151. if (gpio_is_valid(data->phy_irq_pin)) {
  152. at91_set_gpio_input(data->phy_irq_pin, 0);
  153. at91_set_deglitch(data->phy_irq_pin, 1);
  154. }
  155. /* Pins used for MII and RMII */
  156. at91_set_A_periph(AT91_PIN_PE21, 0); /* ETXCK_EREFCK */
  157. at91_set_B_periph(AT91_PIN_PC25, 0); /* ERXDV */
  158. at91_set_A_periph(AT91_PIN_PE25, 0); /* ERX0 */
  159. at91_set_A_periph(AT91_PIN_PE26, 0); /* ERX1 */
  160. at91_set_A_periph(AT91_PIN_PE27, 0); /* ERXER */
  161. at91_set_A_periph(AT91_PIN_PE28, 0); /* ETXEN */
  162. at91_set_A_periph(AT91_PIN_PE23, 0); /* ETX0 */
  163. at91_set_A_periph(AT91_PIN_PE24, 0); /* ETX1 */
  164. at91_set_A_periph(AT91_PIN_PE30, 0); /* EMDIO */
  165. at91_set_A_periph(AT91_PIN_PE29, 0); /* EMDC */
  166. if (!data->is_rmii) {
  167. at91_set_A_periph(AT91_PIN_PE22, 0); /* ECRS */
  168. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  169. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  170. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  171. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  172. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  173. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  174. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  175. }
  176. eth_data = *data;
  177. platform_device_register(&at91sam9263_eth_device);
  178. }
  179. #else
  180. void __init at91_add_device_eth(struct macb_platform_data *data) {}
  181. #endif
  182. /* --------------------------------------------------------------------
  183. * MMC / SD
  184. * -------------------------------------------------------------------- */
  185. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  186. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  187. static struct at91_mmc_data mmc0_data, mmc1_data;
  188. static struct resource mmc0_resources[] = {
  189. [0] = {
  190. .start = AT91SAM9263_BASE_MCI0,
  191. .end = AT91SAM9263_BASE_MCI0 + SZ_16K - 1,
  192. .flags = IORESOURCE_MEM,
  193. },
  194. [1] = {
  195. .start = AT91SAM9263_ID_MCI0,
  196. .end = AT91SAM9263_ID_MCI0,
  197. .flags = IORESOURCE_IRQ,
  198. },
  199. };
  200. static struct platform_device at91sam9263_mmc0_device = {
  201. .name = "at91_mci",
  202. .id = 0,
  203. .dev = {
  204. .dma_mask = &mmc_dmamask,
  205. .coherent_dma_mask = DMA_BIT_MASK(32),
  206. .platform_data = &mmc0_data,
  207. },
  208. .resource = mmc0_resources,
  209. .num_resources = ARRAY_SIZE(mmc0_resources),
  210. };
  211. static struct resource mmc1_resources[] = {
  212. [0] = {
  213. .start = AT91SAM9263_BASE_MCI1,
  214. .end = AT91SAM9263_BASE_MCI1 + SZ_16K - 1,
  215. .flags = IORESOURCE_MEM,
  216. },
  217. [1] = {
  218. .start = AT91SAM9263_ID_MCI1,
  219. .end = AT91SAM9263_ID_MCI1,
  220. .flags = IORESOURCE_IRQ,
  221. },
  222. };
  223. static struct platform_device at91sam9263_mmc1_device = {
  224. .name = "at91_mci",
  225. .id = 1,
  226. .dev = {
  227. .dma_mask = &mmc_dmamask,
  228. .coherent_dma_mask = DMA_BIT_MASK(32),
  229. .platform_data = &mmc1_data,
  230. },
  231. .resource = mmc1_resources,
  232. .num_resources = ARRAY_SIZE(mmc1_resources),
  233. };
  234. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  235. {
  236. if (!data)
  237. return;
  238. /* input/irq */
  239. if (gpio_is_valid(data->det_pin)) {
  240. at91_set_gpio_input(data->det_pin, 1);
  241. at91_set_deglitch(data->det_pin, 1);
  242. }
  243. if (gpio_is_valid(data->wp_pin))
  244. at91_set_gpio_input(data->wp_pin, 1);
  245. if (gpio_is_valid(data->vcc_pin))
  246. at91_set_gpio_output(data->vcc_pin, 0);
  247. if (mmc_id == 0) { /* MCI0 */
  248. /* CLK */
  249. at91_set_A_periph(AT91_PIN_PA12, 0);
  250. if (data->slot_b) {
  251. /* CMD */
  252. at91_set_A_periph(AT91_PIN_PA16, 1);
  253. /* DAT0, maybe DAT1..DAT3 */
  254. at91_set_A_periph(AT91_PIN_PA17, 1);
  255. if (data->wire4) {
  256. at91_set_A_periph(AT91_PIN_PA18, 1);
  257. at91_set_A_periph(AT91_PIN_PA19, 1);
  258. at91_set_A_periph(AT91_PIN_PA20, 1);
  259. }
  260. } else {
  261. /* CMD */
  262. at91_set_A_periph(AT91_PIN_PA1, 1);
  263. /* DAT0, maybe DAT1..DAT3 */
  264. at91_set_A_periph(AT91_PIN_PA0, 1);
  265. if (data->wire4) {
  266. at91_set_A_periph(AT91_PIN_PA3, 1);
  267. at91_set_A_periph(AT91_PIN_PA4, 1);
  268. at91_set_A_periph(AT91_PIN_PA5, 1);
  269. }
  270. }
  271. mmc0_data = *data;
  272. platform_device_register(&at91sam9263_mmc0_device);
  273. } else { /* MCI1 */
  274. /* CLK */
  275. at91_set_A_periph(AT91_PIN_PA6, 0);
  276. if (data->slot_b) {
  277. /* CMD */
  278. at91_set_A_periph(AT91_PIN_PA21, 1);
  279. /* DAT0, maybe DAT1..DAT3 */
  280. at91_set_A_periph(AT91_PIN_PA22, 1);
  281. if (data->wire4) {
  282. at91_set_A_periph(AT91_PIN_PA23, 1);
  283. at91_set_A_periph(AT91_PIN_PA24, 1);
  284. at91_set_A_periph(AT91_PIN_PA25, 1);
  285. }
  286. } else {
  287. /* CMD */
  288. at91_set_A_periph(AT91_PIN_PA7, 1);
  289. /* DAT0, maybe DAT1..DAT3 */
  290. at91_set_A_periph(AT91_PIN_PA8, 1);
  291. if (data->wire4) {
  292. at91_set_A_periph(AT91_PIN_PA9, 1);
  293. at91_set_A_periph(AT91_PIN_PA10, 1);
  294. at91_set_A_periph(AT91_PIN_PA11, 1);
  295. }
  296. }
  297. mmc1_data = *data;
  298. platform_device_register(&at91sam9263_mmc1_device);
  299. }
  300. }
  301. #else
  302. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  303. #endif
  304. /* --------------------------------------------------------------------
  305. * Compact Flash (PCMCIA or IDE)
  306. * -------------------------------------------------------------------- */
  307. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
  308. defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  309. static struct at91_cf_data cf0_data;
  310. static struct resource cf0_resources[] = {
  311. [0] = {
  312. .start = AT91_CHIPSELECT_4,
  313. .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
  314. .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
  315. }
  316. };
  317. static struct platform_device cf0_device = {
  318. .id = 0,
  319. .dev = {
  320. .platform_data = &cf0_data,
  321. },
  322. .resource = cf0_resources,
  323. .num_resources = ARRAY_SIZE(cf0_resources),
  324. };
  325. static struct at91_cf_data cf1_data;
  326. static struct resource cf1_resources[] = {
  327. [0] = {
  328. .start = AT91_CHIPSELECT_5,
  329. .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
  330. .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
  331. }
  332. };
  333. static struct platform_device cf1_device = {
  334. .id = 1,
  335. .dev = {
  336. .platform_data = &cf1_data,
  337. },
  338. .resource = cf1_resources,
  339. .num_resources = ARRAY_SIZE(cf1_resources),
  340. };
  341. void __init at91_add_device_cf(struct at91_cf_data *data)
  342. {
  343. unsigned long ebi0_csa;
  344. struct platform_device *pdev;
  345. if (!data)
  346. return;
  347. /*
  348. * assign CS4 or CS5 to SMC with Compact Flash logic support,
  349. * we assume SMC timings are configured by board code,
  350. * except True IDE where timings are controlled by driver
  351. */
  352. ebi0_csa = at91_matrix_read(AT91_MATRIX_EBI0CSA);
  353. switch (data->chipselect) {
  354. case 4:
  355. at91_set_A_periph(AT91_PIN_PD6, 0); /* EBI0_NCS4/CFCS0 */
  356. ebi0_csa |= AT91_MATRIX_EBI0_CS4A_SMC_CF1;
  357. cf0_data = *data;
  358. pdev = &cf0_device;
  359. break;
  360. case 5:
  361. at91_set_A_periph(AT91_PIN_PD7, 0); /* EBI0_NCS5/CFCS1 */
  362. ebi0_csa |= AT91_MATRIX_EBI0_CS5A_SMC_CF2;
  363. cf1_data = *data;
  364. pdev = &cf1_device;
  365. break;
  366. default:
  367. printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
  368. data->chipselect);
  369. return;
  370. }
  371. at91_matrix_write(AT91_MATRIX_EBI0CSA, ebi0_csa);
  372. if (gpio_is_valid(data->det_pin)) {
  373. at91_set_gpio_input(data->det_pin, 1);
  374. at91_set_deglitch(data->det_pin, 1);
  375. }
  376. if (gpio_is_valid(data->irq_pin)) {
  377. at91_set_gpio_input(data->irq_pin, 1);
  378. at91_set_deglitch(data->irq_pin, 1);
  379. }
  380. if (gpio_is_valid(data->vcc_pin))
  381. /* initially off */
  382. at91_set_gpio_output(data->vcc_pin, 0);
  383. /* enable EBI controlled pins */
  384. at91_set_A_periph(AT91_PIN_PD5, 1); /* NWAIT */
  385. at91_set_A_periph(AT91_PIN_PD8, 0); /* CFCE1 */
  386. at91_set_A_periph(AT91_PIN_PD9, 0); /* CFCE2 */
  387. at91_set_A_periph(AT91_PIN_PD14, 0); /* CFNRW */
  388. pdev->name = (data->flags & AT91_CF_TRUE_IDE) ? "pata_at91" : "at91_cf";
  389. platform_device_register(pdev);
  390. }
  391. #else
  392. void __init at91_add_device_cf(struct at91_cf_data *data) {}
  393. #endif
  394. /* --------------------------------------------------------------------
  395. * NAND / SmartMedia
  396. * -------------------------------------------------------------------- */
  397. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  398. static struct atmel_nand_data nand_data;
  399. #define NAND_BASE AT91_CHIPSELECT_3
  400. static struct resource nand_resources[] = {
  401. [0] = {
  402. .start = NAND_BASE,
  403. .end = NAND_BASE + SZ_256M - 1,
  404. .flags = IORESOURCE_MEM,
  405. },
  406. [1] = {
  407. .start = AT91SAM9263_BASE_ECC0,
  408. .end = AT91SAM9263_BASE_ECC0 + SZ_512 - 1,
  409. .flags = IORESOURCE_MEM,
  410. }
  411. };
  412. static struct platform_device at91sam9263_nand_device = {
  413. .name = "atmel_nand",
  414. .id = -1,
  415. .dev = {
  416. .platform_data = &nand_data,
  417. },
  418. .resource = nand_resources,
  419. .num_resources = ARRAY_SIZE(nand_resources),
  420. };
  421. void __init at91_add_device_nand(struct atmel_nand_data *data)
  422. {
  423. unsigned long csa;
  424. if (!data)
  425. return;
  426. csa = at91_matrix_read(AT91_MATRIX_EBI0CSA);
  427. at91_matrix_write(AT91_MATRIX_EBI0CSA, csa | AT91_MATRIX_EBI0_CS3A_SMC_SMARTMEDIA);
  428. /* enable pin */
  429. if (gpio_is_valid(data->enable_pin))
  430. at91_set_gpio_output(data->enable_pin, 1);
  431. /* ready/busy pin */
  432. if (gpio_is_valid(data->rdy_pin))
  433. at91_set_gpio_input(data->rdy_pin, 1);
  434. /* card detect pin */
  435. if (gpio_is_valid(data->det_pin))
  436. at91_set_gpio_input(data->det_pin, 1);
  437. nand_data = *data;
  438. platform_device_register(&at91sam9263_nand_device);
  439. }
  440. #else
  441. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  442. #endif
  443. /* --------------------------------------------------------------------
  444. * TWI (i2c)
  445. * -------------------------------------------------------------------- */
  446. /*
  447. * Prefer the GPIO code since the TWI controller isn't robust
  448. * (gets overruns and underruns under load) and can only issue
  449. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  450. */
  451. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  452. static struct i2c_gpio_platform_data pdata = {
  453. .sda_pin = AT91_PIN_PB4,
  454. .sda_is_open_drain = 1,
  455. .scl_pin = AT91_PIN_PB5,
  456. .scl_is_open_drain = 1,
  457. .udelay = 2, /* ~100 kHz */
  458. };
  459. static struct platform_device at91sam9263_twi_device = {
  460. .name = "i2c-gpio",
  461. .id = 0,
  462. .dev.platform_data = &pdata,
  463. };
  464. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  465. {
  466. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  467. at91_set_multi_drive(AT91_PIN_PB4, 1);
  468. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  469. at91_set_multi_drive(AT91_PIN_PB5, 1);
  470. i2c_register_board_info(0, devices, nr_devices);
  471. platform_device_register(&at91sam9263_twi_device);
  472. }
  473. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  474. static struct resource twi_resources[] = {
  475. [0] = {
  476. .start = AT91SAM9263_BASE_TWI,
  477. .end = AT91SAM9263_BASE_TWI + SZ_16K - 1,
  478. .flags = IORESOURCE_MEM,
  479. },
  480. [1] = {
  481. .start = AT91SAM9263_ID_TWI,
  482. .end = AT91SAM9263_ID_TWI,
  483. .flags = IORESOURCE_IRQ,
  484. },
  485. };
  486. static struct platform_device at91sam9263_twi_device = {
  487. .name = "at91_i2c",
  488. .id = -1,
  489. .resource = twi_resources,
  490. .num_resources = ARRAY_SIZE(twi_resources),
  491. };
  492. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  493. {
  494. /* pins used for TWI interface */
  495. at91_set_A_periph(AT91_PIN_PB4, 0); /* TWD */
  496. at91_set_multi_drive(AT91_PIN_PB4, 1);
  497. at91_set_A_periph(AT91_PIN_PB5, 0); /* TWCK */
  498. at91_set_multi_drive(AT91_PIN_PB5, 1);
  499. i2c_register_board_info(0, devices, nr_devices);
  500. platform_device_register(&at91sam9263_twi_device);
  501. }
  502. #else
  503. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  504. #endif
  505. /* --------------------------------------------------------------------
  506. * SPI
  507. * -------------------------------------------------------------------- */
  508. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  509. static u64 spi_dmamask = DMA_BIT_MASK(32);
  510. static struct resource spi0_resources[] = {
  511. [0] = {
  512. .start = AT91SAM9263_BASE_SPI0,
  513. .end = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
  514. .flags = IORESOURCE_MEM,
  515. },
  516. [1] = {
  517. .start = AT91SAM9263_ID_SPI0,
  518. .end = AT91SAM9263_ID_SPI0,
  519. .flags = IORESOURCE_IRQ,
  520. },
  521. };
  522. static struct platform_device at91sam9263_spi0_device = {
  523. .name = "atmel_spi",
  524. .id = 0,
  525. .dev = {
  526. .dma_mask = &spi_dmamask,
  527. .coherent_dma_mask = DMA_BIT_MASK(32),
  528. },
  529. .resource = spi0_resources,
  530. .num_resources = ARRAY_SIZE(spi0_resources),
  531. };
  532. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
  533. static struct resource spi1_resources[] = {
  534. [0] = {
  535. .start = AT91SAM9263_BASE_SPI1,
  536. .end = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
  537. .flags = IORESOURCE_MEM,
  538. },
  539. [1] = {
  540. .start = AT91SAM9263_ID_SPI1,
  541. .end = AT91SAM9263_ID_SPI1,
  542. .flags = IORESOURCE_IRQ,
  543. },
  544. };
  545. static struct platform_device at91sam9263_spi1_device = {
  546. .name = "atmel_spi",
  547. .id = 1,
  548. .dev = {
  549. .dma_mask = &spi_dmamask,
  550. .coherent_dma_mask = DMA_BIT_MASK(32),
  551. },
  552. .resource = spi1_resources,
  553. .num_resources = ARRAY_SIZE(spi1_resources),
  554. };
  555. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  556. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  557. {
  558. int i;
  559. unsigned long cs_pin;
  560. short enable_spi0 = 0;
  561. short enable_spi1 = 0;
  562. /* Choose SPI chip-selects */
  563. for (i = 0; i < nr_devices; i++) {
  564. if (devices[i].controller_data)
  565. cs_pin = (unsigned long) devices[i].controller_data;
  566. else if (devices[i].bus_num == 0)
  567. cs_pin = spi0_standard_cs[devices[i].chip_select];
  568. else
  569. cs_pin = spi1_standard_cs[devices[i].chip_select];
  570. if (!gpio_is_valid(cs_pin))
  571. continue;
  572. if (devices[i].bus_num == 0)
  573. enable_spi0 = 1;
  574. else
  575. enable_spi1 = 1;
  576. /* enable chip-select pin */
  577. at91_set_gpio_output(cs_pin, 1);
  578. /* pass chip-select pin to driver */
  579. devices[i].controller_data = (void *) cs_pin;
  580. }
  581. spi_register_board_info(devices, nr_devices);
  582. /* Configure SPI bus(es) */
  583. if (enable_spi0) {
  584. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  585. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  586. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  587. platform_device_register(&at91sam9263_spi0_device);
  588. }
  589. if (enable_spi1) {
  590. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  591. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  592. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  593. platform_device_register(&at91sam9263_spi1_device);
  594. }
  595. }
  596. #else
  597. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  598. #endif
  599. /* --------------------------------------------------------------------
  600. * AC97
  601. * -------------------------------------------------------------------- */
  602. #if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
  603. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  604. static struct ac97c_platform_data ac97_data;
  605. static struct resource ac97_resources[] = {
  606. [0] = {
  607. .start = AT91SAM9263_BASE_AC97C,
  608. .end = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
  609. .flags = IORESOURCE_MEM,
  610. },
  611. [1] = {
  612. .start = AT91SAM9263_ID_AC97C,
  613. .end = AT91SAM9263_ID_AC97C,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. };
  617. static struct platform_device at91sam9263_ac97_device = {
  618. .name = "atmel_ac97c",
  619. .id = 0,
  620. .dev = {
  621. .dma_mask = &ac97_dmamask,
  622. .coherent_dma_mask = DMA_BIT_MASK(32),
  623. .platform_data = &ac97_data,
  624. },
  625. .resource = ac97_resources,
  626. .num_resources = ARRAY_SIZE(ac97_resources),
  627. };
  628. void __init at91_add_device_ac97(struct ac97c_platform_data *data)
  629. {
  630. if (!data)
  631. return;
  632. at91_set_A_periph(AT91_PIN_PB0, 0); /* AC97FS */
  633. at91_set_A_periph(AT91_PIN_PB1, 0); /* AC97CK */
  634. at91_set_A_periph(AT91_PIN_PB2, 0); /* AC97TX */
  635. at91_set_A_periph(AT91_PIN_PB3, 0); /* AC97RX */
  636. /* reset */
  637. if (gpio_is_valid(data->reset_pin))
  638. at91_set_gpio_output(data->reset_pin, 0);
  639. ac97_data = *data;
  640. platform_device_register(&at91sam9263_ac97_device);
  641. }
  642. #else
  643. void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
  644. #endif
  645. /* --------------------------------------------------------------------
  646. * CAN Controller
  647. * -------------------------------------------------------------------- */
  648. #if defined(CONFIG_CAN_AT91) || defined(CONFIG_CAN_AT91_MODULE)
  649. static struct resource can_resources[] = {
  650. [0] = {
  651. .start = AT91SAM9263_BASE_CAN,
  652. .end = AT91SAM9263_BASE_CAN + SZ_16K - 1,
  653. .flags = IORESOURCE_MEM,
  654. },
  655. [1] = {
  656. .start = AT91SAM9263_ID_CAN,
  657. .end = AT91SAM9263_ID_CAN,
  658. .flags = IORESOURCE_IRQ,
  659. },
  660. };
  661. static struct platform_device at91sam9263_can_device = {
  662. .name = "at91_can",
  663. .id = -1,
  664. .resource = can_resources,
  665. .num_resources = ARRAY_SIZE(can_resources),
  666. };
  667. void __init at91_add_device_can(struct at91_can_data *data)
  668. {
  669. at91_set_A_periph(AT91_PIN_PA13, 0); /* CANTX */
  670. at91_set_A_periph(AT91_PIN_PA14, 0); /* CANRX */
  671. at91sam9263_can_device.dev.platform_data = data;
  672. platform_device_register(&at91sam9263_can_device);
  673. }
  674. #else
  675. void __init at91_add_device_can(struct at91_can_data *data) {}
  676. #endif
  677. /* --------------------------------------------------------------------
  678. * LCD Controller
  679. * -------------------------------------------------------------------- */
  680. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  681. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  682. static struct atmel_lcdfb_info lcdc_data;
  683. static struct resource lcdc_resources[] = {
  684. [0] = {
  685. .start = AT91SAM9263_LCDC_BASE,
  686. .end = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
  687. .flags = IORESOURCE_MEM,
  688. },
  689. [1] = {
  690. .start = AT91SAM9263_ID_LCDC,
  691. .end = AT91SAM9263_ID_LCDC,
  692. .flags = IORESOURCE_IRQ,
  693. },
  694. };
  695. static struct platform_device at91_lcdc_device = {
  696. .name = "atmel_lcdfb",
  697. .id = 0,
  698. .dev = {
  699. .dma_mask = &lcdc_dmamask,
  700. .coherent_dma_mask = DMA_BIT_MASK(32),
  701. .platform_data = &lcdc_data,
  702. },
  703. .resource = lcdc_resources,
  704. .num_resources = ARRAY_SIZE(lcdc_resources),
  705. };
  706. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  707. {
  708. if (!data)
  709. return;
  710. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  711. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  712. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  713. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  714. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  715. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  716. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  717. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  718. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  719. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  720. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  721. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  722. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  723. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
  724. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  725. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  726. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  727. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  728. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  729. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
  730. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  731. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  732. lcdc_data = *data;
  733. platform_device_register(&at91_lcdc_device);
  734. }
  735. #else
  736. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  737. #endif
  738. /* --------------------------------------------------------------------
  739. * Image Sensor Interface
  740. * -------------------------------------------------------------------- */
  741. #if defined(CONFIG_VIDEO_AT91_ISI) || defined(CONFIG_VIDEO_AT91_ISI_MODULE)
  742. struct resource isi_resources[] = {
  743. [0] = {
  744. .start = AT91SAM9263_BASE_ISI,
  745. .end = AT91SAM9263_BASE_ISI + SZ_16K - 1,
  746. .flags = IORESOURCE_MEM,
  747. },
  748. [1] = {
  749. .start = AT91SAM9263_ID_ISI,
  750. .end = AT91SAM9263_ID_ISI,
  751. .flags = IORESOURCE_IRQ,
  752. },
  753. };
  754. static struct platform_device at91sam9263_isi_device = {
  755. .name = "at91_isi",
  756. .id = -1,
  757. .resource = isi_resources,
  758. .num_resources = ARRAY_SIZE(isi_resources),
  759. };
  760. void __init at91_add_device_isi(struct isi_platform_data *data,
  761. bool use_pck_as_mck)
  762. {
  763. at91_set_A_periph(AT91_PIN_PE0, 0); /* ISI_D0 */
  764. at91_set_A_periph(AT91_PIN_PE1, 0); /* ISI_D1 */
  765. at91_set_A_periph(AT91_PIN_PE2, 0); /* ISI_D2 */
  766. at91_set_A_periph(AT91_PIN_PE3, 0); /* ISI_D3 */
  767. at91_set_A_periph(AT91_PIN_PE4, 0); /* ISI_D4 */
  768. at91_set_A_periph(AT91_PIN_PE5, 0); /* ISI_D5 */
  769. at91_set_A_periph(AT91_PIN_PE6, 0); /* ISI_D6 */
  770. at91_set_A_periph(AT91_PIN_PE7, 0); /* ISI_D7 */
  771. at91_set_A_periph(AT91_PIN_PE8, 0); /* ISI_PCK */
  772. at91_set_A_periph(AT91_PIN_PE9, 0); /* ISI_HSYNC */
  773. at91_set_A_periph(AT91_PIN_PE10, 0); /* ISI_VSYNC */
  774. at91_set_B_periph(AT91_PIN_PE12, 0); /* ISI_PD8 */
  775. at91_set_B_periph(AT91_PIN_PE13, 0); /* ISI_PD9 */
  776. at91_set_B_periph(AT91_PIN_PE14, 0); /* ISI_PD10 */
  777. at91_set_B_periph(AT91_PIN_PE15, 0); /* ISI_PD11 */
  778. if (use_pck_as_mck) {
  779. at91_set_B_periph(AT91_PIN_PE11, 0); /* ISI_MCK (PCK3) */
  780. /* TODO: register the PCK for ISI_MCK and set its parent */
  781. }
  782. }
  783. #else
  784. void __init at91_add_device_isi(struct isi_platform_data *data,
  785. bool use_pck_as_mck) {}
  786. #endif
  787. /* --------------------------------------------------------------------
  788. * Timer/Counter block
  789. * -------------------------------------------------------------------- */
  790. #ifdef CONFIG_ATMEL_TCLIB
  791. static struct resource tcb_resources[] = {
  792. [0] = {
  793. .start = AT91SAM9263_BASE_TCB0,
  794. .end = AT91SAM9263_BASE_TCB0 + SZ_16K - 1,
  795. .flags = IORESOURCE_MEM,
  796. },
  797. [1] = {
  798. .start = AT91SAM9263_ID_TCB,
  799. .end = AT91SAM9263_ID_TCB,
  800. .flags = IORESOURCE_IRQ,
  801. },
  802. };
  803. static struct platform_device at91sam9263_tcb_device = {
  804. .name = "atmel_tcb",
  805. .id = 0,
  806. .resource = tcb_resources,
  807. .num_resources = ARRAY_SIZE(tcb_resources),
  808. };
  809. static void __init at91_add_device_tc(void)
  810. {
  811. platform_device_register(&at91sam9263_tcb_device);
  812. }
  813. #else
  814. static void __init at91_add_device_tc(void) { }
  815. #endif
  816. /* --------------------------------------------------------------------
  817. * RTT
  818. * -------------------------------------------------------------------- */
  819. static struct resource rtt0_resources[] = {
  820. {
  821. .start = AT91SAM9263_BASE_RTT0,
  822. .end = AT91SAM9263_BASE_RTT0 + SZ_16 - 1,
  823. .flags = IORESOURCE_MEM,
  824. }, {
  825. .flags = IORESOURCE_MEM,
  826. }
  827. };
  828. static struct platform_device at91sam9263_rtt0_device = {
  829. .name = "at91_rtt",
  830. .id = 0,
  831. .resource = rtt0_resources,
  832. };
  833. static struct resource rtt1_resources[] = {
  834. {
  835. .start = AT91SAM9263_BASE_RTT1,
  836. .end = AT91SAM9263_BASE_RTT1 + SZ_16 - 1,
  837. .flags = IORESOURCE_MEM,
  838. }, {
  839. .flags = IORESOURCE_MEM,
  840. }
  841. };
  842. static struct platform_device at91sam9263_rtt1_device = {
  843. .name = "at91_rtt",
  844. .id = 1,
  845. .resource = rtt1_resources,
  846. };
  847. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  848. static void __init at91_add_device_rtt_rtc(void)
  849. {
  850. struct platform_device *pdev;
  851. struct resource *r;
  852. switch (CONFIG_RTC_DRV_AT91SAM9_RTT) {
  853. case 0:
  854. /*
  855. * The second resource is needed only for the chosen RTT:
  856. * GPBR will serve as the storage for RTC time offset
  857. */
  858. at91sam9263_rtt0_device.num_resources = 2;
  859. at91sam9263_rtt1_device.num_resources = 1;
  860. pdev = &at91sam9263_rtt0_device;
  861. r = rtt0_resources;
  862. break;
  863. case 1:
  864. at91sam9263_rtt0_device.num_resources = 1;
  865. at91sam9263_rtt1_device.num_resources = 2;
  866. pdev = &at91sam9263_rtt1_device;
  867. r = rtt1_resources;
  868. break;
  869. default:
  870. pr_err("at91sam9263: only supports 2 RTT (%d)\n",
  871. CONFIG_RTC_DRV_AT91SAM9_RTT);
  872. return;
  873. }
  874. pdev->name = "rtc-at91sam9";
  875. r[1].start = AT91SAM9263_BASE_GPBR + 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  876. r[1].end = r[1].start + 3;
  877. }
  878. #else
  879. static void __init at91_add_device_rtt_rtc(void)
  880. {
  881. /* Only one resource is needed: RTT not used as RTC */
  882. at91sam9263_rtt0_device.num_resources = 1;
  883. at91sam9263_rtt1_device.num_resources = 1;
  884. }
  885. #endif
  886. static void __init at91_add_device_rtt(void)
  887. {
  888. at91_add_device_rtt_rtc();
  889. platform_device_register(&at91sam9263_rtt0_device);
  890. platform_device_register(&at91sam9263_rtt1_device);
  891. }
  892. /* --------------------------------------------------------------------
  893. * Watchdog
  894. * -------------------------------------------------------------------- */
  895. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  896. static struct resource wdt_resources[] = {
  897. {
  898. .start = AT91SAM9263_BASE_WDT,
  899. .end = AT91SAM9263_BASE_WDT + SZ_16 - 1,
  900. .flags = IORESOURCE_MEM,
  901. }
  902. };
  903. static struct platform_device at91sam9263_wdt_device = {
  904. .name = "at91_wdt",
  905. .id = -1,
  906. .resource = wdt_resources,
  907. .num_resources = ARRAY_SIZE(wdt_resources),
  908. };
  909. static void __init at91_add_device_watchdog(void)
  910. {
  911. platform_device_register(&at91sam9263_wdt_device);
  912. }
  913. #else
  914. static void __init at91_add_device_watchdog(void) {}
  915. #endif
  916. /* --------------------------------------------------------------------
  917. * PWM
  918. * --------------------------------------------------------------------*/
  919. #if defined(CONFIG_ATMEL_PWM)
  920. static u32 pwm_mask;
  921. static struct resource pwm_resources[] = {
  922. [0] = {
  923. .start = AT91SAM9263_BASE_PWMC,
  924. .end = AT91SAM9263_BASE_PWMC + SZ_16K - 1,
  925. .flags = IORESOURCE_MEM,
  926. },
  927. [1] = {
  928. .start = AT91SAM9263_ID_PWMC,
  929. .end = AT91SAM9263_ID_PWMC,
  930. .flags = IORESOURCE_IRQ,
  931. },
  932. };
  933. static struct platform_device at91sam9263_pwm0_device = {
  934. .name = "atmel_pwm",
  935. .id = -1,
  936. .dev = {
  937. .platform_data = &pwm_mask,
  938. },
  939. .resource = pwm_resources,
  940. .num_resources = ARRAY_SIZE(pwm_resources),
  941. };
  942. void __init at91_add_device_pwm(u32 mask)
  943. {
  944. if (mask & (1 << AT91_PWM0))
  945. at91_set_B_periph(AT91_PIN_PB7, 1); /* enable PWM0 */
  946. if (mask & (1 << AT91_PWM1))
  947. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
  948. if (mask & (1 << AT91_PWM2))
  949. at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
  950. if (mask & (1 << AT91_PWM3))
  951. at91_set_B_periph(AT91_PIN_PB29, 1); /* enable PWM3 */
  952. pwm_mask = mask;
  953. platform_device_register(&at91sam9263_pwm0_device);
  954. }
  955. #else
  956. void __init at91_add_device_pwm(u32 mask) {}
  957. #endif
  958. /* --------------------------------------------------------------------
  959. * SSC -- Synchronous Serial Controller
  960. * -------------------------------------------------------------------- */
  961. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  962. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  963. static struct resource ssc0_resources[] = {
  964. [0] = {
  965. .start = AT91SAM9263_BASE_SSC0,
  966. .end = AT91SAM9263_BASE_SSC0 + SZ_16K - 1,
  967. .flags = IORESOURCE_MEM,
  968. },
  969. [1] = {
  970. .start = AT91SAM9263_ID_SSC0,
  971. .end = AT91SAM9263_ID_SSC0,
  972. .flags = IORESOURCE_IRQ,
  973. },
  974. };
  975. static struct platform_device at91sam9263_ssc0_device = {
  976. .name = "ssc",
  977. .id = 0,
  978. .dev = {
  979. .dma_mask = &ssc0_dmamask,
  980. .coherent_dma_mask = DMA_BIT_MASK(32),
  981. },
  982. .resource = ssc0_resources,
  983. .num_resources = ARRAY_SIZE(ssc0_resources),
  984. };
  985. static inline void configure_ssc0_pins(unsigned pins)
  986. {
  987. if (pins & ATMEL_SSC_TF)
  988. at91_set_B_periph(AT91_PIN_PB0, 1);
  989. if (pins & ATMEL_SSC_TK)
  990. at91_set_B_periph(AT91_PIN_PB1, 1);
  991. if (pins & ATMEL_SSC_TD)
  992. at91_set_B_periph(AT91_PIN_PB2, 1);
  993. if (pins & ATMEL_SSC_RD)
  994. at91_set_B_periph(AT91_PIN_PB3, 1);
  995. if (pins & ATMEL_SSC_RK)
  996. at91_set_B_periph(AT91_PIN_PB4, 1);
  997. if (pins & ATMEL_SSC_RF)
  998. at91_set_B_periph(AT91_PIN_PB5, 1);
  999. }
  1000. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  1001. static struct resource ssc1_resources[] = {
  1002. [0] = {
  1003. .start = AT91SAM9263_BASE_SSC1,
  1004. .end = AT91SAM9263_BASE_SSC1 + SZ_16K - 1,
  1005. .flags = IORESOURCE_MEM,
  1006. },
  1007. [1] = {
  1008. .start = AT91SAM9263_ID_SSC1,
  1009. .end = AT91SAM9263_ID_SSC1,
  1010. .flags = IORESOURCE_IRQ,
  1011. },
  1012. };
  1013. static struct platform_device at91sam9263_ssc1_device = {
  1014. .name = "ssc",
  1015. .id = 1,
  1016. .dev = {
  1017. .dma_mask = &ssc1_dmamask,
  1018. .coherent_dma_mask = DMA_BIT_MASK(32),
  1019. },
  1020. .resource = ssc1_resources,
  1021. .num_resources = ARRAY_SIZE(ssc1_resources),
  1022. };
  1023. static inline void configure_ssc1_pins(unsigned pins)
  1024. {
  1025. if (pins & ATMEL_SSC_TF)
  1026. at91_set_A_periph(AT91_PIN_PB6, 1);
  1027. if (pins & ATMEL_SSC_TK)
  1028. at91_set_A_periph(AT91_PIN_PB7, 1);
  1029. if (pins & ATMEL_SSC_TD)
  1030. at91_set_A_periph(AT91_PIN_PB8, 1);
  1031. if (pins & ATMEL_SSC_RD)
  1032. at91_set_A_periph(AT91_PIN_PB9, 1);
  1033. if (pins & ATMEL_SSC_RK)
  1034. at91_set_A_periph(AT91_PIN_PB10, 1);
  1035. if (pins & ATMEL_SSC_RF)
  1036. at91_set_A_periph(AT91_PIN_PB11, 1);
  1037. }
  1038. /*
  1039. * SSC controllers are accessed through library code, instead of any
  1040. * kind of all-singing/all-dancing driver. For example one could be
  1041. * used by a particular I2S audio codec's driver, while another one
  1042. * on the same system might be used by a custom data capture driver.
  1043. */
  1044. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  1045. {
  1046. struct platform_device *pdev;
  1047. /*
  1048. * NOTE: caller is responsible for passing information matching
  1049. * "pins" to whatever will be using each particular controller.
  1050. */
  1051. switch (id) {
  1052. case AT91SAM9263_ID_SSC0:
  1053. pdev = &at91sam9263_ssc0_device;
  1054. configure_ssc0_pins(pins);
  1055. break;
  1056. case AT91SAM9263_ID_SSC1:
  1057. pdev = &at91sam9263_ssc1_device;
  1058. configure_ssc1_pins(pins);
  1059. break;
  1060. default:
  1061. return;
  1062. }
  1063. platform_device_register(pdev);
  1064. }
  1065. #else
  1066. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  1067. #endif
  1068. /* --------------------------------------------------------------------
  1069. * UART
  1070. * -------------------------------------------------------------------- */
  1071. #if defined(CONFIG_SERIAL_ATMEL)
  1072. static struct resource dbgu_resources[] = {
  1073. [0] = {
  1074. .start = AT91SAM9263_BASE_DBGU,
  1075. .end = AT91SAM9263_BASE_DBGU + SZ_512 - 1,
  1076. .flags = IORESOURCE_MEM,
  1077. },
  1078. [1] = {
  1079. .start = AT91_ID_SYS,
  1080. .end = AT91_ID_SYS,
  1081. .flags = IORESOURCE_IRQ,
  1082. },
  1083. };
  1084. static struct atmel_uart_data dbgu_data = {
  1085. .use_dma_tx = 0,
  1086. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  1087. };
  1088. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  1089. static struct platform_device at91sam9263_dbgu_device = {
  1090. .name = "atmel_usart",
  1091. .id = 0,
  1092. .dev = {
  1093. .dma_mask = &dbgu_dmamask,
  1094. .coherent_dma_mask = DMA_BIT_MASK(32),
  1095. .platform_data = &dbgu_data,
  1096. },
  1097. .resource = dbgu_resources,
  1098. .num_resources = ARRAY_SIZE(dbgu_resources),
  1099. };
  1100. static inline void configure_dbgu_pins(void)
  1101. {
  1102. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  1103. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  1104. }
  1105. static struct resource uart0_resources[] = {
  1106. [0] = {
  1107. .start = AT91SAM9263_BASE_US0,
  1108. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  1109. .flags = IORESOURCE_MEM,
  1110. },
  1111. [1] = {
  1112. .start = AT91SAM9263_ID_US0,
  1113. .end = AT91SAM9263_ID_US0,
  1114. .flags = IORESOURCE_IRQ,
  1115. },
  1116. };
  1117. static struct atmel_uart_data uart0_data = {
  1118. .use_dma_tx = 1,
  1119. .use_dma_rx = 1,
  1120. };
  1121. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  1122. static struct platform_device at91sam9263_uart0_device = {
  1123. .name = "atmel_usart",
  1124. .id = 1,
  1125. .dev = {
  1126. .dma_mask = &uart0_dmamask,
  1127. .coherent_dma_mask = DMA_BIT_MASK(32),
  1128. .platform_data = &uart0_data,
  1129. },
  1130. .resource = uart0_resources,
  1131. .num_resources = ARRAY_SIZE(uart0_resources),
  1132. };
  1133. static inline void configure_usart0_pins(unsigned pins)
  1134. {
  1135. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  1136. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  1137. if (pins & ATMEL_UART_RTS)
  1138. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  1139. if (pins & ATMEL_UART_CTS)
  1140. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  1141. }
  1142. static struct resource uart1_resources[] = {
  1143. [0] = {
  1144. .start = AT91SAM9263_BASE_US1,
  1145. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  1146. .flags = IORESOURCE_MEM,
  1147. },
  1148. [1] = {
  1149. .start = AT91SAM9263_ID_US1,
  1150. .end = AT91SAM9263_ID_US1,
  1151. .flags = IORESOURCE_IRQ,
  1152. },
  1153. };
  1154. static struct atmel_uart_data uart1_data = {
  1155. .use_dma_tx = 1,
  1156. .use_dma_rx = 1,
  1157. };
  1158. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  1159. static struct platform_device at91sam9263_uart1_device = {
  1160. .name = "atmel_usart",
  1161. .id = 2,
  1162. .dev = {
  1163. .dma_mask = &uart1_dmamask,
  1164. .coherent_dma_mask = DMA_BIT_MASK(32),
  1165. .platform_data = &uart1_data,
  1166. },
  1167. .resource = uart1_resources,
  1168. .num_resources = ARRAY_SIZE(uart1_resources),
  1169. };
  1170. static inline void configure_usart1_pins(unsigned pins)
  1171. {
  1172. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  1173. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  1174. if (pins & ATMEL_UART_RTS)
  1175. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  1176. if (pins & ATMEL_UART_CTS)
  1177. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  1178. }
  1179. static struct resource uart2_resources[] = {
  1180. [0] = {
  1181. .start = AT91SAM9263_BASE_US2,
  1182. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  1183. .flags = IORESOURCE_MEM,
  1184. },
  1185. [1] = {
  1186. .start = AT91SAM9263_ID_US2,
  1187. .end = AT91SAM9263_ID_US2,
  1188. .flags = IORESOURCE_IRQ,
  1189. },
  1190. };
  1191. static struct atmel_uart_data uart2_data = {
  1192. .use_dma_tx = 1,
  1193. .use_dma_rx = 1,
  1194. };
  1195. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  1196. static struct platform_device at91sam9263_uart2_device = {
  1197. .name = "atmel_usart",
  1198. .id = 3,
  1199. .dev = {
  1200. .dma_mask = &uart2_dmamask,
  1201. .coherent_dma_mask = DMA_BIT_MASK(32),
  1202. .platform_data = &uart2_data,
  1203. },
  1204. .resource = uart2_resources,
  1205. .num_resources = ARRAY_SIZE(uart2_resources),
  1206. };
  1207. static inline void configure_usart2_pins(unsigned pins)
  1208. {
  1209. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  1210. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  1211. if (pins & ATMEL_UART_RTS)
  1212. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  1213. if (pins & ATMEL_UART_CTS)
  1214. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  1215. }
  1216. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1217. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1218. {
  1219. struct platform_device *pdev;
  1220. struct atmel_uart_data *pdata;
  1221. switch (id) {
  1222. case 0: /* DBGU */
  1223. pdev = &at91sam9263_dbgu_device;
  1224. configure_dbgu_pins();
  1225. break;
  1226. case AT91SAM9263_ID_US0:
  1227. pdev = &at91sam9263_uart0_device;
  1228. configure_usart0_pins(pins);
  1229. break;
  1230. case AT91SAM9263_ID_US1:
  1231. pdev = &at91sam9263_uart1_device;
  1232. configure_usart1_pins(pins);
  1233. break;
  1234. case AT91SAM9263_ID_US2:
  1235. pdev = &at91sam9263_uart2_device;
  1236. configure_usart2_pins(pins);
  1237. break;
  1238. default:
  1239. return;
  1240. }
  1241. pdata = pdev->dev.platform_data;
  1242. pdata->num = portnr; /* update to mapped ID */
  1243. if (portnr < ATMEL_MAX_UART)
  1244. at91_uarts[portnr] = pdev;
  1245. }
  1246. void __init at91_set_serial_console(unsigned portnr)
  1247. {
  1248. if (portnr < ATMEL_MAX_UART) {
  1249. atmel_default_console_device = at91_uarts[portnr];
  1250. at91sam9263_set_console_clock(at91_uarts[portnr]->id);
  1251. }
  1252. }
  1253. void __init at91_add_device_serial(void)
  1254. {
  1255. int i;
  1256. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1257. if (at91_uarts[i])
  1258. platform_device_register(at91_uarts[i]);
  1259. }
  1260. if (!atmel_default_console_device)
  1261. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1262. }
  1263. #else
  1264. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1265. void __init at91_set_serial_console(unsigned portnr) {}
  1266. void __init at91_add_device_serial(void) {}
  1267. #endif
  1268. /* -------------------------------------------------------------------- */
  1269. /*
  1270. * These devices are always present and don't need any board-specific
  1271. * setup.
  1272. */
  1273. static int __init at91_add_standard_devices(void)
  1274. {
  1275. at91_add_device_rtt();
  1276. at91_add_device_watchdog();
  1277. at91_add_device_tc();
  1278. return 0;
  1279. }
  1280. arch_initcall(at91_add_standard_devices);