at91sam9263_devices.c 39 KB

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