at91sam9263_devices.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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. };
  842. static struct platform_device at91sam9263_rtt0_device = {
  843. .name = "at91_rtt",
  844. .id = 0,
  845. .resource = rtt0_resources,
  846. };
  847. static struct resource rtt1_resources[] = {
  848. {
  849. .start = AT91SAM9263_BASE_RTT1,
  850. .end = AT91SAM9263_BASE_RTT1 + SZ_16 - 1,
  851. .flags = IORESOURCE_MEM,
  852. }, {
  853. .flags = IORESOURCE_MEM,
  854. }
  855. };
  856. static struct platform_device at91sam9263_rtt1_device = {
  857. .name = "at91_rtt",
  858. .id = 1,
  859. .resource = rtt1_resources,
  860. };
  861. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  862. static void __init at91_add_device_rtt_rtc(void)
  863. {
  864. struct platform_device *pdev;
  865. struct resource *r;
  866. switch (CONFIG_RTC_DRV_AT91SAM9_RTT) {
  867. case 0:
  868. /*
  869. * The second resource is needed only for the chosen RTT:
  870. * GPBR will serve as the storage for RTC time offset
  871. */
  872. at91sam9263_rtt0_device.num_resources = 2;
  873. at91sam9263_rtt1_device.num_resources = 1;
  874. pdev = &at91sam9263_rtt0_device;
  875. r = rtt0_resources;
  876. break;
  877. case 1:
  878. at91sam9263_rtt0_device.num_resources = 1;
  879. at91sam9263_rtt1_device.num_resources = 2;
  880. pdev = &at91sam9263_rtt1_device;
  881. r = rtt1_resources;
  882. break;
  883. default:
  884. pr_err("at91sam9263: only supports 2 RTT (%d)\n",
  885. CONFIG_RTC_DRV_AT91SAM9_RTT);
  886. return;
  887. }
  888. pdev->name = "rtc-at91sam9";
  889. r[1].start = AT91SAM9263_BASE_GPBR + 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  890. r[1].end = r[1].start + 3;
  891. }
  892. #else
  893. static void __init at91_add_device_rtt_rtc(void)
  894. {
  895. /* Only one resource is needed: RTT not used as RTC */
  896. at91sam9263_rtt0_device.num_resources = 1;
  897. at91sam9263_rtt1_device.num_resources = 1;
  898. }
  899. #endif
  900. static void __init at91_add_device_rtt(void)
  901. {
  902. at91_add_device_rtt_rtc();
  903. platform_device_register(&at91sam9263_rtt0_device);
  904. platform_device_register(&at91sam9263_rtt1_device);
  905. }
  906. /* --------------------------------------------------------------------
  907. * Watchdog
  908. * -------------------------------------------------------------------- */
  909. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  910. static struct resource wdt_resources[] = {
  911. {
  912. .start = AT91SAM9263_BASE_WDT,
  913. .end = AT91SAM9263_BASE_WDT + SZ_16 - 1,
  914. .flags = IORESOURCE_MEM,
  915. }
  916. };
  917. static struct platform_device at91sam9263_wdt_device = {
  918. .name = "at91_wdt",
  919. .id = -1,
  920. .resource = wdt_resources,
  921. .num_resources = ARRAY_SIZE(wdt_resources),
  922. };
  923. static void __init at91_add_device_watchdog(void)
  924. {
  925. platform_device_register(&at91sam9263_wdt_device);
  926. }
  927. #else
  928. static void __init at91_add_device_watchdog(void) {}
  929. #endif
  930. /* --------------------------------------------------------------------
  931. * PWM
  932. * --------------------------------------------------------------------*/
  933. #if defined(CONFIG_ATMEL_PWM)
  934. static u32 pwm_mask;
  935. static struct resource pwm_resources[] = {
  936. [0] = {
  937. .start = AT91SAM9263_BASE_PWMC,
  938. .end = AT91SAM9263_BASE_PWMC + SZ_16K - 1,
  939. .flags = IORESOURCE_MEM,
  940. },
  941. [1] = {
  942. .start = NR_IRQS_LEGACY + AT91SAM9263_ID_PWMC,
  943. .end = NR_IRQS_LEGACY + AT91SAM9263_ID_PWMC,
  944. .flags = IORESOURCE_IRQ,
  945. },
  946. };
  947. static struct platform_device at91sam9263_pwm0_device = {
  948. .name = "atmel_pwm",
  949. .id = -1,
  950. .dev = {
  951. .platform_data = &pwm_mask,
  952. },
  953. .resource = pwm_resources,
  954. .num_resources = ARRAY_SIZE(pwm_resources),
  955. };
  956. void __init at91_add_device_pwm(u32 mask)
  957. {
  958. if (mask & (1 << AT91_PWM0))
  959. at91_set_B_periph(AT91_PIN_PB7, 1); /* enable PWM0 */
  960. if (mask & (1 << AT91_PWM1))
  961. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
  962. if (mask & (1 << AT91_PWM2))
  963. at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
  964. if (mask & (1 << AT91_PWM3))
  965. at91_set_B_periph(AT91_PIN_PB29, 1); /* enable PWM3 */
  966. pwm_mask = mask;
  967. platform_device_register(&at91sam9263_pwm0_device);
  968. }
  969. #else
  970. void __init at91_add_device_pwm(u32 mask) {}
  971. #endif
  972. /* --------------------------------------------------------------------
  973. * SSC -- Synchronous Serial Controller
  974. * -------------------------------------------------------------------- */
  975. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  976. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  977. static struct resource ssc0_resources[] = {
  978. [0] = {
  979. .start = AT91SAM9263_BASE_SSC0,
  980. .end = AT91SAM9263_BASE_SSC0 + SZ_16K - 1,
  981. .flags = IORESOURCE_MEM,
  982. },
  983. [1] = {
  984. .start = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC0,
  985. .end = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC0,
  986. .flags = IORESOURCE_IRQ,
  987. },
  988. };
  989. static struct platform_device at91sam9263_ssc0_device = {
  990. .name = "ssc",
  991. .id = 0,
  992. .dev = {
  993. .dma_mask = &ssc0_dmamask,
  994. .coherent_dma_mask = DMA_BIT_MASK(32),
  995. },
  996. .resource = ssc0_resources,
  997. .num_resources = ARRAY_SIZE(ssc0_resources),
  998. };
  999. static inline void configure_ssc0_pins(unsigned pins)
  1000. {
  1001. if (pins & ATMEL_SSC_TF)
  1002. at91_set_B_periph(AT91_PIN_PB0, 1);
  1003. if (pins & ATMEL_SSC_TK)
  1004. at91_set_B_periph(AT91_PIN_PB1, 1);
  1005. if (pins & ATMEL_SSC_TD)
  1006. at91_set_B_periph(AT91_PIN_PB2, 1);
  1007. if (pins & ATMEL_SSC_RD)
  1008. at91_set_B_periph(AT91_PIN_PB3, 1);
  1009. if (pins & ATMEL_SSC_RK)
  1010. at91_set_B_periph(AT91_PIN_PB4, 1);
  1011. if (pins & ATMEL_SSC_RF)
  1012. at91_set_B_periph(AT91_PIN_PB5, 1);
  1013. }
  1014. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  1015. static struct resource ssc1_resources[] = {
  1016. [0] = {
  1017. .start = AT91SAM9263_BASE_SSC1,
  1018. .end = AT91SAM9263_BASE_SSC1 + SZ_16K - 1,
  1019. .flags = IORESOURCE_MEM,
  1020. },
  1021. [1] = {
  1022. .start = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC1,
  1023. .end = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC1,
  1024. .flags = IORESOURCE_IRQ,
  1025. },
  1026. };
  1027. static struct platform_device at91sam9263_ssc1_device = {
  1028. .name = "ssc",
  1029. .id = 1,
  1030. .dev = {
  1031. .dma_mask = &ssc1_dmamask,
  1032. .coherent_dma_mask = DMA_BIT_MASK(32),
  1033. },
  1034. .resource = ssc1_resources,
  1035. .num_resources = ARRAY_SIZE(ssc1_resources),
  1036. };
  1037. static inline void configure_ssc1_pins(unsigned pins)
  1038. {
  1039. if (pins & ATMEL_SSC_TF)
  1040. at91_set_A_periph(AT91_PIN_PB6, 1);
  1041. if (pins & ATMEL_SSC_TK)
  1042. at91_set_A_periph(AT91_PIN_PB7, 1);
  1043. if (pins & ATMEL_SSC_TD)
  1044. at91_set_A_periph(AT91_PIN_PB8, 1);
  1045. if (pins & ATMEL_SSC_RD)
  1046. at91_set_A_periph(AT91_PIN_PB9, 1);
  1047. if (pins & ATMEL_SSC_RK)
  1048. at91_set_A_periph(AT91_PIN_PB10, 1);
  1049. if (pins & ATMEL_SSC_RF)
  1050. at91_set_A_periph(AT91_PIN_PB11, 1);
  1051. }
  1052. /*
  1053. * SSC controllers are accessed through library code, instead of any
  1054. * kind of all-singing/all-dancing driver. For example one could be
  1055. * used by a particular I2S audio codec's driver, while another one
  1056. * on the same system might be used by a custom data capture driver.
  1057. */
  1058. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  1059. {
  1060. struct platform_device *pdev;
  1061. /*
  1062. * NOTE: caller is responsible for passing information matching
  1063. * "pins" to whatever will be using each particular controller.
  1064. */
  1065. switch (id) {
  1066. case AT91SAM9263_ID_SSC0:
  1067. pdev = &at91sam9263_ssc0_device;
  1068. configure_ssc0_pins(pins);
  1069. break;
  1070. case AT91SAM9263_ID_SSC1:
  1071. pdev = &at91sam9263_ssc1_device;
  1072. configure_ssc1_pins(pins);
  1073. break;
  1074. default:
  1075. return;
  1076. }
  1077. platform_device_register(pdev);
  1078. }
  1079. #else
  1080. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  1081. #endif
  1082. /* --------------------------------------------------------------------
  1083. * UART
  1084. * -------------------------------------------------------------------- */
  1085. #if defined(CONFIG_SERIAL_ATMEL)
  1086. static struct resource dbgu_resources[] = {
  1087. [0] = {
  1088. .start = AT91SAM9263_BASE_DBGU,
  1089. .end = AT91SAM9263_BASE_DBGU + SZ_512 - 1,
  1090. .flags = IORESOURCE_MEM,
  1091. },
  1092. [1] = {
  1093. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  1094. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  1095. .flags = IORESOURCE_IRQ,
  1096. },
  1097. };
  1098. static struct atmel_uart_data dbgu_data = {
  1099. .use_dma_tx = 0,
  1100. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  1101. };
  1102. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  1103. static struct platform_device at91sam9263_dbgu_device = {
  1104. .name = "atmel_usart",
  1105. .id = 0,
  1106. .dev = {
  1107. .dma_mask = &dbgu_dmamask,
  1108. .coherent_dma_mask = DMA_BIT_MASK(32),
  1109. .platform_data = &dbgu_data,
  1110. },
  1111. .resource = dbgu_resources,
  1112. .num_resources = ARRAY_SIZE(dbgu_resources),
  1113. };
  1114. static inline void configure_dbgu_pins(void)
  1115. {
  1116. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  1117. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  1118. }
  1119. static struct resource uart0_resources[] = {
  1120. [0] = {
  1121. .start = AT91SAM9263_BASE_US0,
  1122. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  1123. .flags = IORESOURCE_MEM,
  1124. },
  1125. [1] = {
  1126. .start = NR_IRQS_LEGACY + AT91SAM9263_ID_US0,
  1127. .end = NR_IRQS_LEGACY + AT91SAM9263_ID_US0,
  1128. .flags = IORESOURCE_IRQ,
  1129. },
  1130. };
  1131. static struct atmel_uart_data uart0_data = {
  1132. .use_dma_tx = 1,
  1133. .use_dma_rx = 1,
  1134. };
  1135. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  1136. static struct platform_device at91sam9263_uart0_device = {
  1137. .name = "atmel_usart",
  1138. .id = 1,
  1139. .dev = {
  1140. .dma_mask = &uart0_dmamask,
  1141. .coherent_dma_mask = DMA_BIT_MASK(32),
  1142. .platform_data = &uart0_data,
  1143. },
  1144. .resource = uart0_resources,
  1145. .num_resources = ARRAY_SIZE(uart0_resources),
  1146. };
  1147. static inline void configure_usart0_pins(unsigned pins)
  1148. {
  1149. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  1150. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  1151. if (pins & ATMEL_UART_RTS)
  1152. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  1153. if (pins & ATMEL_UART_CTS)
  1154. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  1155. }
  1156. static struct resource uart1_resources[] = {
  1157. [0] = {
  1158. .start = AT91SAM9263_BASE_US1,
  1159. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  1160. .flags = IORESOURCE_MEM,
  1161. },
  1162. [1] = {
  1163. .start = NR_IRQS_LEGACY + AT91SAM9263_ID_US1,
  1164. .end = NR_IRQS_LEGACY + AT91SAM9263_ID_US1,
  1165. .flags = IORESOURCE_IRQ,
  1166. },
  1167. };
  1168. static struct atmel_uart_data uart1_data = {
  1169. .use_dma_tx = 1,
  1170. .use_dma_rx = 1,
  1171. };
  1172. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  1173. static struct platform_device at91sam9263_uart1_device = {
  1174. .name = "atmel_usart",
  1175. .id = 2,
  1176. .dev = {
  1177. .dma_mask = &uart1_dmamask,
  1178. .coherent_dma_mask = DMA_BIT_MASK(32),
  1179. .platform_data = &uart1_data,
  1180. },
  1181. .resource = uart1_resources,
  1182. .num_resources = ARRAY_SIZE(uart1_resources),
  1183. };
  1184. static inline void configure_usart1_pins(unsigned pins)
  1185. {
  1186. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  1187. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  1188. if (pins & ATMEL_UART_RTS)
  1189. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  1190. if (pins & ATMEL_UART_CTS)
  1191. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  1192. }
  1193. static struct resource uart2_resources[] = {
  1194. [0] = {
  1195. .start = AT91SAM9263_BASE_US2,
  1196. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  1197. .flags = IORESOURCE_MEM,
  1198. },
  1199. [1] = {
  1200. .start = NR_IRQS_LEGACY + AT91SAM9263_ID_US2,
  1201. .end = NR_IRQS_LEGACY + AT91SAM9263_ID_US2,
  1202. .flags = IORESOURCE_IRQ,
  1203. },
  1204. };
  1205. static struct atmel_uart_data uart2_data = {
  1206. .use_dma_tx = 1,
  1207. .use_dma_rx = 1,
  1208. };
  1209. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  1210. static struct platform_device at91sam9263_uart2_device = {
  1211. .name = "atmel_usart",
  1212. .id = 3,
  1213. .dev = {
  1214. .dma_mask = &uart2_dmamask,
  1215. .coherent_dma_mask = DMA_BIT_MASK(32),
  1216. .platform_data = &uart2_data,
  1217. },
  1218. .resource = uart2_resources,
  1219. .num_resources = ARRAY_SIZE(uart2_resources),
  1220. };
  1221. static inline void configure_usart2_pins(unsigned pins)
  1222. {
  1223. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  1224. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  1225. if (pins & ATMEL_UART_RTS)
  1226. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  1227. if (pins & ATMEL_UART_CTS)
  1228. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  1229. }
  1230. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1231. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1232. {
  1233. struct platform_device *pdev;
  1234. struct atmel_uart_data *pdata;
  1235. switch (id) {
  1236. case 0: /* DBGU */
  1237. pdev = &at91sam9263_dbgu_device;
  1238. configure_dbgu_pins();
  1239. break;
  1240. case AT91SAM9263_ID_US0:
  1241. pdev = &at91sam9263_uart0_device;
  1242. configure_usart0_pins(pins);
  1243. break;
  1244. case AT91SAM9263_ID_US1:
  1245. pdev = &at91sam9263_uart1_device;
  1246. configure_usart1_pins(pins);
  1247. break;
  1248. case AT91SAM9263_ID_US2:
  1249. pdev = &at91sam9263_uart2_device;
  1250. configure_usart2_pins(pins);
  1251. break;
  1252. default:
  1253. return;
  1254. }
  1255. pdata = pdev->dev.platform_data;
  1256. pdata->num = portnr; /* update to mapped ID */
  1257. if (portnr < ATMEL_MAX_UART)
  1258. at91_uarts[portnr] = pdev;
  1259. }
  1260. void __init at91_add_device_serial(void)
  1261. {
  1262. int i;
  1263. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1264. if (at91_uarts[i])
  1265. platform_device_register(at91_uarts[i]);
  1266. }
  1267. }
  1268. #else
  1269. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1270. void __init at91_add_device_serial(void) {}
  1271. #endif
  1272. /* -------------------------------------------------------------------- */
  1273. /*
  1274. * These devices are always present and don't need any board-specific
  1275. * setup.
  1276. */
  1277. static int __init at91_add_standard_devices(void)
  1278. {
  1279. if (of_have_populated_dt())
  1280. return 0;
  1281. at91_add_device_rtt();
  1282. at91_add_device_watchdog();
  1283. at91_add_device_tc();
  1284. return 0;
  1285. }
  1286. arch_initcall(at91_add_standard_devices);