at91sam9263_devices.c 38 KB

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