at91sam9263_devices.c 39 KB

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