at91sam9263_devices.c 36 KB

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