at91sam9263_devices.c 37 KB

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