at91sam9260_devices.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. /*
  2. * arch/arm/mach-at91/at91sam9260_devices.c
  3. *
  4. * Copyright (C) 2006 Atmel
  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/platform_data/at91_adc.h>
  19. #include <mach/board.h>
  20. #include <mach/cpu.h>
  21. #include <mach/at91sam9260.h>
  22. #include <mach/at91sam9260_matrix.h>
  23. #include <mach/at91_matrix.h>
  24. #include <mach/at91sam9_smc.h>
  25. #include <mach/at91_adc.h>
  26. #include "generic.h"
  27. /* --------------------------------------------------------------------
  28. * USB Host
  29. * -------------------------------------------------------------------- */
  30. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  31. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  32. static struct at91_usbh_data usbh_data;
  33. static struct resource usbh_resources[] = {
  34. [0] = {
  35. .start = AT91SAM9260_UHP_BASE,
  36. .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
  37. .flags = IORESOURCE_MEM,
  38. },
  39. [1] = {
  40. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
  41. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
  42. .flags = IORESOURCE_IRQ,
  43. },
  44. };
  45. static struct platform_device at91_usbh_device = {
  46. .name = "at91_ohci",
  47. .id = -1,
  48. .dev = {
  49. .dma_mask = &ohci_dmamask,
  50. .coherent_dma_mask = DMA_BIT_MASK(32),
  51. .platform_data = &usbh_data,
  52. },
  53. .resource = usbh_resources,
  54. .num_resources = ARRAY_SIZE(usbh_resources),
  55. };
  56. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  57. {
  58. int i;
  59. if (!data)
  60. return;
  61. /* Enable overcurrent notification */
  62. for (i = 0; i < data->ports; i++) {
  63. if (data->overcurrent_pin[i])
  64. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  65. }
  66. usbh_data = *data;
  67. platform_device_register(&at91_usbh_device);
  68. }
  69. #else
  70. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  71. #endif
  72. /* --------------------------------------------------------------------
  73. * USB Device (Gadget)
  74. * -------------------------------------------------------------------- */
  75. #if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
  76. static struct at91_udc_data udc_data;
  77. static struct resource udc_resources[] = {
  78. [0] = {
  79. .start = AT91SAM9260_BASE_UDP,
  80. .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
  81. .flags = IORESOURCE_MEM,
  82. },
  83. [1] = {
  84. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
  85. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
  86. .flags = IORESOURCE_IRQ,
  87. },
  88. };
  89. static struct platform_device at91_udc_device = {
  90. .name = "at91_udc",
  91. .id = -1,
  92. .dev = {
  93. .platform_data = &udc_data,
  94. },
  95. .resource = udc_resources,
  96. .num_resources = ARRAY_SIZE(udc_resources),
  97. };
  98. void __init at91_add_device_udc(struct at91_udc_data *data)
  99. {
  100. if (!data)
  101. return;
  102. if (gpio_is_valid(data->vbus_pin)) {
  103. at91_set_gpio_input(data->vbus_pin, 0);
  104. at91_set_deglitch(data->vbus_pin, 1);
  105. }
  106. /* Pullup pin is handled internally by USB device peripheral */
  107. udc_data = *data;
  108. platform_device_register(&at91_udc_device);
  109. }
  110. #else
  111. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  112. #endif
  113. /* --------------------------------------------------------------------
  114. * Ethernet
  115. * -------------------------------------------------------------------- */
  116. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  117. static u64 eth_dmamask = DMA_BIT_MASK(32);
  118. static struct macb_platform_data eth_data;
  119. static struct resource eth_resources[] = {
  120. [0] = {
  121. .start = AT91SAM9260_BASE_EMAC,
  122. .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. [1] = {
  126. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
  127. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
  128. .flags = IORESOURCE_IRQ,
  129. },
  130. };
  131. static struct platform_device at91sam9260_eth_device = {
  132. .name = "macb",
  133. .id = -1,
  134. .dev = {
  135. .dma_mask = &eth_dmamask,
  136. .coherent_dma_mask = DMA_BIT_MASK(32),
  137. .platform_data = &eth_data,
  138. },
  139. .resource = eth_resources,
  140. .num_resources = ARRAY_SIZE(eth_resources),
  141. };
  142. void __init at91_add_device_eth(struct macb_platform_data *data)
  143. {
  144. if (!data)
  145. return;
  146. if (gpio_is_valid(data->phy_irq_pin)) {
  147. at91_set_gpio_input(data->phy_irq_pin, 0);
  148. at91_set_deglitch(data->phy_irq_pin, 1);
  149. }
  150. /* Pins used for MII and RMII */
  151. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  152. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  153. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  154. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  155. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  156. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  157. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  158. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  159. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  160. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  161. if (!data->is_rmii) {
  162. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  163. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  164. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  165. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  166. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  167. at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
  168. at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
  169. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  170. }
  171. eth_data = *data;
  172. platform_device_register(&at91sam9260_eth_device);
  173. }
  174. #else
  175. void __init at91_add_device_eth(struct macb_platform_data *data) {}
  176. #endif
  177. /* --------------------------------------------------------------------
  178. * MMC / SD
  179. * -------------------------------------------------------------------- */
  180. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  181. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  182. static struct at91_mmc_data mmc_data;
  183. static struct resource mmc_resources[] = {
  184. [0] = {
  185. .start = AT91SAM9260_BASE_MCI,
  186. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  187. .flags = IORESOURCE_MEM,
  188. },
  189. [1] = {
  190. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  191. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  192. .flags = IORESOURCE_IRQ,
  193. },
  194. };
  195. static struct platform_device at91sam9260_mmc_device = {
  196. .name = "at91_mci",
  197. .id = -1,
  198. .dev = {
  199. .dma_mask = &mmc_dmamask,
  200. .coherent_dma_mask = DMA_BIT_MASK(32),
  201. .platform_data = &mmc_data,
  202. },
  203. .resource = mmc_resources,
  204. .num_resources = ARRAY_SIZE(mmc_resources),
  205. };
  206. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  207. {
  208. if (!data)
  209. return;
  210. /* input/irq */
  211. if (gpio_is_valid(data->det_pin)) {
  212. at91_set_gpio_input(data->det_pin, 1);
  213. at91_set_deglitch(data->det_pin, 1);
  214. }
  215. if (gpio_is_valid(data->wp_pin))
  216. at91_set_gpio_input(data->wp_pin, 1);
  217. if (gpio_is_valid(data->vcc_pin))
  218. at91_set_gpio_output(data->vcc_pin, 0);
  219. /* CLK */
  220. at91_set_A_periph(AT91_PIN_PA8, 0);
  221. if (data->slot_b) {
  222. /* CMD */
  223. at91_set_B_periph(AT91_PIN_PA1, 1);
  224. /* DAT0, maybe DAT1..DAT3 */
  225. at91_set_B_periph(AT91_PIN_PA0, 1);
  226. if (data->wire4) {
  227. at91_set_B_periph(AT91_PIN_PA5, 1);
  228. at91_set_B_periph(AT91_PIN_PA4, 1);
  229. at91_set_B_periph(AT91_PIN_PA3, 1);
  230. }
  231. } else {
  232. /* CMD */
  233. at91_set_A_periph(AT91_PIN_PA7, 1);
  234. /* DAT0, maybe DAT1..DAT3 */
  235. at91_set_A_periph(AT91_PIN_PA6, 1);
  236. if (data->wire4) {
  237. at91_set_A_periph(AT91_PIN_PA9, 1);
  238. at91_set_A_periph(AT91_PIN_PA10, 1);
  239. at91_set_A_periph(AT91_PIN_PA11, 1);
  240. }
  241. }
  242. mmc_data = *data;
  243. platform_device_register(&at91sam9260_mmc_device);
  244. }
  245. #else
  246. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  247. #endif
  248. /* --------------------------------------------------------------------
  249. * MMC / SD Slot for Atmel MCI Driver
  250. * -------------------------------------------------------------------- */
  251. #if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
  252. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  253. static struct mci_platform_data mmc_data;
  254. static struct resource mmc_resources[] = {
  255. [0] = {
  256. .start = AT91SAM9260_BASE_MCI,
  257. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  258. .flags = IORESOURCE_MEM,
  259. },
  260. [1] = {
  261. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  262. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  263. .flags = IORESOURCE_IRQ,
  264. },
  265. };
  266. static struct platform_device at91sam9260_mmc_device = {
  267. .name = "atmel_mci",
  268. .id = -1,
  269. .dev = {
  270. .dma_mask = &mmc_dmamask,
  271. .coherent_dma_mask = DMA_BIT_MASK(32),
  272. .platform_data = &mmc_data,
  273. },
  274. .resource = mmc_resources,
  275. .num_resources = ARRAY_SIZE(mmc_resources),
  276. };
  277. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
  278. {
  279. unsigned int i;
  280. unsigned int slot_count = 0;
  281. if (!data)
  282. return;
  283. for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
  284. if (data->slot[i].bus_width) {
  285. /* input/irq */
  286. if (gpio_is_valid(data->slot[i].detect_pin)) {
  287. at91_set_gpio_input(data->slot[i].detect_pin, 1);
  288. at91_set_deglitch(data->slot[i].detect_pin, 1);
  289. }
  290. if (gpio_is_valid(data->slot[i].wp_pin))
  291. at91_set_gpio_input(data->slot[i].wp_pin, 1);
  292. switch (i) {
  293. case 0:
  294. /* CMD */
  295. at91_set_A_periph(AT91_PIN_PA7, 1);
  296. /* DAT0, maybe DAT1..DAT3 */
  297. at91_set_A_periph(AT91_PIN_PA6, 1);
  298. if (data->slot[i].bus_width == 4) {
  299. at91_set_A_periph(AT91_PIN_PA9, 1);
  300. at91_set_A_periph(AT91_PIN_PA10, 1);
  301. at91_set_A_periph(AT91_PIN_PA11, 1);
  302. }
  303. slot_count++;
  304. break;
  305. case 1:
  306. /* CMD */
  307. at91_set_B_periph(AT91_PIN_PA1, 1);
  308. /* DAT0, maybe DAT1..DAT3 */
  309. at91_set_B_periph(AT91_PIN_PA0, 1);
  310. if (data->slot[i].bus_width == 4) {
  311. at91_set_B_periph(AT91_PIN_PA5, 1);
  312. at91_set_B_periph(AT91_PIN_PA4, 1);
  313. at91_set_B_periph(AT91_PIN_PA3, 1);
  314. }
  315. slot_count++;
  316. break;
  317. default:
  318. printk(KERN_ERR
  319. "AT91: SD/MMC slot %d not available\n", i);
  320. break;
  321. }
  322. }
  323. }
  324. if (slot_count) {
  325. /* CLK */
  326. at91_set_A_periph(AT91_PIN_PA8, 0);
  327. mmc_data = *data;
  328. platform_device_register(&at91sam9260_mmc_device);
  329. }
  330. }
  331. #else
  332. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
  333. #endif
  334. /* --------------------------------------------------------------------
  335. * NAND / SmartMedia
  336. * -------------------------------------------------------------------- */
  337. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  338. static struct atmel_nand_data nand_data;
  339. #define NAND_BASE AT91_CHIPSELECT_3
  340. static struct resource nand_resources[] = {
  341. [0] = {
  342. .start = NAND_BASE,
  343. .end = NAND_BASE + SZ_256M - 1,
  344. .flags = IORESOURCE_MEM,
  345. },
  346. [1] = {
  347. .start = AT91SAM9260_BASE_ECC,
  348. .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
  349. .flags = IORESOURCE_MEM,
  350. }
  351. };
  352. static struct platform_device at91sam9260_nand_device = {
  353. .name = "atmel_nand",
  354. .id = -1,
  355. .dev = {
  356. .platform_data = &nand_data,
  357. },
  358. .resource = nand_resources,
  359. .num_resources = ARRAY_SIZE(nand_resources),
  360. };
  361. void __init at91_add_device_nand(struct atmel_nand_data *data)
  362. {
  363. unsigned long csa;
  364. if (!data)
  365. return;
  366. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  367. at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  368. /* enable pin */
  369. if (gpio_is_valid(data->enable_pin))
  370. at91_set_gpio_output(data->enable_pin, 1);
  371. /* ready/busy pin */
  372. if (gpio_is_valid(data->rdy_pin))
  373. at91_set_gpio_input(data->rdy_pin, 1);
  374. /* card detect pin */
  375. if (gpio_is_valid(data->det_pin))
  376. at91_set_gpio_input(data->det_pin, 1);
  377. nand_data = *data;
  378. platform_device_register(&at91sam9260_nand_device);
  379. }
  380. #else
  381. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  382. #endif
  383. /* --------------------------------------------------------------------
  384. * TWI (i2c)
  385. * -------------------------------------------------------------------- */
  386. /*
  387. * Prefer the GPIO code since the TWI controller isn't robust
  388. * (gets overruns and underruns under load) and can only issue
  389. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  390. */
  391. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  392. static struct i2c_gpio_platform_data pdata = {
  393. .sda_pin = AT91_PIN_PA23,
  394. .sda_is_open_drain = 1,
  395. .scl_pin = AT91_PIN_PA24,
  396. .scl_is_open_drain = 1,
  397. .udelay = 2, /* ~100 kHz */
  398. };
  399. static struct platform_device at91sam9260_twi_device = {
  400. .name = "i2c-gpio",
  401. .id = -1,
  402. .dev.platform_data = &pdata,
  403. };
  404. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  405. {
  406. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  407. at91_set_multi_drive(AT91_PIN_PA23, 1);
  408. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  409. at91_set_multi_drive(AT91_PIN_PA24, 1);
  410. i2c_register_board_info(0, devices, nr_devices);
  411. platform_device_register(&at91sam9260_twi_device);
  412. }
  413. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  414. static struct resource twi_resources[] = {
  415. [0] = {
  416. .start = AT91SAM9260_BASE_TWI,
  417. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  418. .flags = IORESOURCE_MEM,
  419. },
  420. [1] = {
  421. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  422. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  423. .flags = IORESOURCE_IRQ,
  424. },
  425. };
  426. static struct platform_device at91sam9260_twi_device = {
  427. .id = -1,
  428. .resource = twi_resources,
  429. .num_resources = ARRAY_SIZE(twi_resources),
  430. };
  431. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  432. {
  433. /* IP version is not the same on 9260 and g20 */
  434. if (cpu_is_at91sam9g20()) {
  435. at91sam9260_twi_device.name = "i2c-at91sam9g20";
  436. } else {
  437. at91sam9260_twi_device.name = "i2c-at91sam9260";
  438. }
  439. /* pins used for TWI interface */
  440. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  441. at91_set_multi_drive(AT91_PIN_PA23, 1);
  442. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  443. at91_set_multi_drive(AT91_PIN_PA24, 1);
  444. i2c_register_board_info(0, devices, nr_devices);
  445. platform_device_register(&at91sam9260_twi_device);
  446. }
  447. #else
  448. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  449. #endif
  450. /* --------------------------------------------------------------------
  451. * SPI
  452. * -------------------------------------------------------------------- */
  453. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  454. static u64 spi_dmamask = DMA_BIT_MASK(32);
  455. static struct resource spi0_resources[] = {
  456. [0] = {
  457. .start = AT91SAM9260_BASE_SPI0,
  458. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  459. .flags = IORESOURCE_MEM,
  460. },
  461. [1] = {
  462. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  463. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  464. .flags = IORESOURCE_IRQ,
  465. },
  466. };
  467. static struct platform_device at91sam9260_spi0_device = {
  468. .name = "atmel_spi",
  469. .id = 0,
  470. .dev = {
  471. .dma_mask = &spi_dmamask,
  472. .coherent_dma_mask = DMA_BIT_MASK(32),
  473. },
  474. .resource = spi0_resources,
  475. .num_resources = ARRAY_SIZE(spi0_resources),
  476. };
  477. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  478. static struct resource spi1_resources[] = {
  479. [0] = {
  480. .start = AT91SAM9260_BASE_SPI1,
  481. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  482. .flags = IORESOURCE_MEM,
  483. },
  484. [1] = {
  485. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  486. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  487. .flags = IORESOURCE_IRQ,
  488. },
  489. };
  490. static struct platform_device at91sam9260_spi1_device = {
  491. .name = "atmel_spi",
  492. .id = 1,
  493. .dev = {
  494. .dma_mask = &spi_dmamask,
  495. .coherent_dma_mask = DMA_BIT_MASK(32),
  496. },
  497. .resource = spi1_resources,
  498. .num_resources = ARRAY_SIZE(spi1_resources),
  499. };
  500. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  501. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  502. {
  503. int i;
  504. unsigned long cs_pin;
  505. short enable_spi0 = 0;
  506. short enable_spi1 = 0;
  507. /* Choose SPI chip-selects */
  508. for (i = 0; i < nr_devices; i++) {
  509. if (devices[i].controller_data)
  510. cs_pin = (unsigned long) devices[i].controller_data;
  511. else if (devices[i].bus_num == 0)
  512. cs_pin = spi0_standard_cs[devices[i].chip_select];
  513. else
  514. cs_pin = spi1_standard_cs[devices[i].chip_select];
  515. if (!gpio_is_valid(cs_pin))
  516. continue;
  517. if (devices[i].bus_num == 0)
  518. enable_spi0 = 1;
  519. else
  520. enable_spi1 = 1;
  521. /* enable chip-select pin */
  522. at91_set_gpio_output(cs_pin, 1);
  523. /* pass chip-select pin to driver */
  524. devices[i].controller_data = (void *) cs_pin;
  525. }
  526. spi_register_board_info(devices, nr_devices);
  527. /* Configure SPI bus(es) */
  528. if (enable_spi0) {
  529. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  530. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  531. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  532. platform_device_register(&at91sam9260_spi0_device);
  533. }
  534. if (enable_spi1) {
  535. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  536. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  537. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  538. platform_device_register(&at91sam9260_spi1_device);
  539. }
  540. }
  541. #else
  542. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  543. #endif
  544. /* --------------------------------------------------------------------
  545. * Timer/Counter blocks
  546. * -------------------------------------------------------------------- */
  547. #ifdef CONFIG_ATMEL_TCLIB
  548. static struct resource tcb0_resources[] = {
  549. [0] = {
  550. .start = AT91SAM9260_BASE_TCB0,
  551. .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
  552. .flags = IORESOURCE_MEM,
  553. },
  554. [1] = {
  555. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  556. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  557. .flags = IORESOURCE_IRQ,
  558. },
  559. [2] = {
  560. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  561. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  562. .flags = IORESOURCE_IRQ,
  563. },
  564. [3] = {
  565. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  566. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  567. .flags = IORESOURCE_IRQ,
  568. },
  569. };
  570. static struct platform_device at91sam9260_tcb0_device = {
  571. .name = "atmel_tcb",
  572. .id = 0,
  573. .resource = tcb0_resources,
  574. .num_resources = ARRAY_SIZE(tcb0_resources),
  575. };
  576. static struct resource tcb1_resources[] = {
  577. [0] = {
  578. .start = AT91SAM9260_BASE_TCB1,
  579. .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
  580. .flags = IORESOURCE_MEM,
  581. },
  582. [1] = {
  583. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  584. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  585. .flags = IORESOURCE_IRQ,
  586. },
  587. [2] = {
  588. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  589. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  590. .flags = IORESOURCE_IRQ,
  591. },
  592. [3] = {
  593. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  594. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  595. .flags = IORESOURCE_IRQ,
  596. },
  597. };
  598. static struct platform_device at91sam9260_tcb1_device = {
  599. .name = "atmel_tcb",
  600. .id = 1,
  601. .resource = tcb1_resources,
  602. .num_resources = ARRAY_SIZE(tcb1_resources),
  603. };
  604. static void __init at91_add_device_tc(void)
  605. {
  606. platform_device_register(&at91sam9260_tcb0_device);
  607. platform_device_register(&at91sam9260_tcb1_device);
  608. }
  609. #else
  610. static void __init at91_add_device_tc(void) { }
  611. #endif
  612. /* --------------------------------------------------------------------
  613. * RTT
  614. * -------------------------------------------------------------------- */
  615. static struct resource rtt_resources[] = {
  616. {
  617. .start = AT91SAM9260_BASE_RTT,
  618. .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
  619. .flags = IORESOURCE_MEM,
  620. }, {
  621. .flags = IORESOURCE_MEM,
  622. }, {
  623. .flags = IORESOURCE_IRQ,
  624. },
  625. };
  626. static struct platform_device at91sam9260_rtt_device = {
  627. .name = "at91_rtt",
  628. .id = 0,
  629. .resource = rtt_resources,
  630. };
  631. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  632. static void __init at91_add_device_rtt_rtc(void)
  633. {
  634. at91sam9260_rtt_device.name = "rtc-at91sam9";
  635. /*
  636. * The second resource is needed:
  637. * GPBR will serve as the storage for RTC time offset
  638. */
  639. at91sam9260_rtt_device.num_resources = 3;
  640. rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
  641. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  642. rtt_resources[1].end = rtt_resources[1].start + 3;
  643. rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
  644. rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
  645. }
  646. #else
  647. static void __init at91_add_device_rtt_rtc(void)
  648. {
  649. /* Only one resource is needed: RTT not used as RTC */
  650. at91sam9260_rtt_device.num_resources = 1;
  651. }
  652. #endif
  653. static void __init at91_add_device_rtt(void)
  654. {
  655. at91_add_device_rtt_rtc();
  656. platform_device_register(&at91sam9260_rtt_device);
  657. }
  658. /* --------------------------------------------------------------------
  659. * Watchdog
  660. * -------------------------------------------------------------------- */
  661. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  662. static struct resource wdt_resources[] = {
  663. {
  664. .start = AT91SAM9260_BASE_WDT,
  665. .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
  666. .flags = IORESOURCE_MEM,
  667. }
  668. };
  669. static struct platform_device at91sam9260_wdt_device = {
  670. .name = "at91_wdt",
  671. .id = -1,
  672. .resource = wdt_resources,
  673. .num_resources = ARRAY_SIZE(wdt_resources),
  674. };
  675. static void __init at91_add_device_watchdog(void)
  676. {
  677. platform_device_register(&at91sam9260_wdt_device);
  678. }
  679. #else
  680. static void __init at91_add_device_watchdog(void) {}
  681. #endif
  682. /* --------------------------------------------------------------------
  683. * SSC -- Synchronous Serial Controller
  684. * -------------------------------------------------------------------- */
  685. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  686. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  687. static struct resource ssc_resources[] = {
  688. [0] = {
  689. .start = AT91SAM9260_BASE_SSC,
  690. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  691. .flags = IORESOURCE_MEM,
  692. },
  693. [1] = {
  694. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  695. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  696. .flags = IORESOURCE_IRQ,
  697. },
  698. };
  699. static struct platform_device at91sam9260_ssc_device = {
  700. .name = "ssc",
  701. .id = 0,
  702. .dev = {
  703. .dma_mask = &ssc_dmamask,
  704. .coherent_dma_mask = DMA_BIT_MASK(32),
  705. },
  706. .resource = ssc_resources,
  707. .num_resources = ARRAY_SIZE(ssc_resources),
  708. };
  709. static inline void configure_ssc_pins(unsigned pins)
  710. {
  711. if (pins & ATMEL_SSC_TF)
  712. at91_set_A_periph(AT91_PIN_PB17, 1);
  713. if (pins & ATMEL_SSC_TK)
  714. at91_set_A_periph(AT91_PIN_PB16, 1);
  715. if (pins & ATMEL_SSC_TD)
  716. at91_set_A_periph(AT91_PIN_PB18, 1);
  717. if (pins & ATMEL_SSC_RD)
  718. at91_set_A_periph(AT91_PIN_PB19, 1);
  719. if (pins & ATMEL_SSC_RK)
  720. at91_set_A_periph(AT91_PIN_PB20, 1);
  721. if (pins & ATMEL_SSC_RF)
  722. at91_set_A_periph(AT91_PIN_PB21, 1);
  723. }
  724. /*
  725. * SSC controllers are accessed through library code, instead of any
  726. * kind of all-singing/all-dancing driver. For example one could be
  727. * used by a particular I2S audio codec's driver, while another one
  728. * on the same system might be used by a custom data capture driver.
  729. */
  730. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  731. {
  732. struct platform_device *pdev;
  733. /*
  734. * NOTE: caller is responsible for passing information matching
  735. * "pins" to whatever will be using each particular controller.
  736. */
  737. switch (id) {
  738. case AT91SAM9260_ID_SSC:
  739. pdev = &at91sam9260_ssc_device;
  740. configure_ssc_pins(pins);
  741. break;
  742. default:
  743. return;
  744. }
  745. platform_device_register(pdev);
  746. }
  747. #else
  748. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  749. #endif
  750. /* --------------------------------------------------------------------
  751. * UART
  752. * -------------------------------------------------------------------- */
  753. #if defined(CONFIG_SERIAL_ATMEL)
  754. static struct resource dbgu_resources[] = {
  755. [0] = {
  756. .start = AT91SAM9260_BASE_DBGU,
  757. .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
  758. .flags = IORESOURCE_MEM,
  759. },
  760. [1] = {
  761. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  762. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  763. .flags = IORESOURCE_IRQ,
  764. },
  765. };
  766. static struct atmel_uart_data dbgu_data = {
  767. .use_dma_tx = 0,
  768. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  769. };
  770. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  771. static struct platform_device at91sam9260_dbgu_device = {
  772. .name = "atmel_usart",
  773. .id = 0,
  774. .dev = {
  775. .dma_mask = &dbgu_dmamask,
  776. .coherent_dma_mask = DMA_BIT_MASK(32),
  777. .platform_data = &dbgu_data,
  778. },
  779. .resource = dbgu_resources,
  780. .num_resources = ARRAY_SIZE(dbgu_resources),
  781. };
  782. static inline void configure_dbgu_pins(void)
  783. {
  784. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  785. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  786. }
  787. static struct resource uart0_resources[] = {
  788. [0] = {
  789. .start = AT91SAM9260_BASE_US0,
  790. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  791. .flags = IORESOURCE_MEM,
  792. },
  793. [1] = {
  794. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  795. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  796. .flags = IORESOURCE_IRQ,
  797. },
  798. };
  799. static struct atmel_uart_data uart0_data = {
  800. .use_dma_tx = 1,
  801. .use_dma_rx = 1,
  802. };
  803. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  804. static struct platform_device at91sam9260_uart0_device = {
  805. .name = "atmel_usart",
  806. .id = 1,
  807. .dev = {
  808. .dma_mask = &uart0_dmamask,
  809. .coherent_dma_mask = DMA_BIT_MASK(32),
  810. .platform_data = &uart0_data,
  811. },
  812. .resource = uart0_resources,
  813. .num_resources = ARRAY_SIZE(uart0_resources),
  814. };
  815. static inline void configure_usart0_pins(unsigned pins)
  816. {
  817. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  818. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  819. if (pins & ATMEL_UART_RTS)
  820. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  821. if (pins & ATMEL_UART_CTS)
  822. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  823. if (pins & ATMEL_UART_DTR)
  824. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  825. if (pins & ATMEL_UART_DSR)
  826. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  827. if (pins & ATMEL_UART_DCD)
  828. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  829. if (pins & ATMEL_UART_RI)
  830. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  831. }
  832. static struct resource uart1_resources[] = {
  833. [0] = {
  834. .start = AT91SAM9260_BASE_US1,
  835. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  836. .flags = IORESOURCE_MEM,
  837. },
  838. [1] = {
  839. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  840. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  841. .flags = IORESOURCE_IRQ,
  842. },
  843. };
  844. static struct atmel_uart_data uart1_data = {
  845. .use_dma_tx = 1,
  846. .use_dma_rx = 1,
  847. };
  848. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  849. static struct platform_device at91sam9260_uart1_device = {
  850. .name = "atmel_usart",
  851. .id = 2,
  852. .dev = {
  853. .dma_mask = &uart1_dmamask,
  854. .coherent_dma_mask = DMA_BIT_MASK(32),
  855. .platform_data = &uart1_data,
  856. },
  857. .resource = uart1_resources,
  858. .num_resources = ARRAY_SIZE(uart1_resources),
  859. };
  860. static inline void configure_usart1_pins(unsigned pins)
  861. {
  862. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  863. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  864. if (pins & ATMEL_UART_RTS)
  865. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  866. if (pins & ATMEL_UART_CTS)
  867. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  868. }
  869. static struct resource uart2_resources[] = {
  870. [0] = {
  871. .start = AT91SAM9260_BASE_US2,
  872. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  873. .flags = IORESOURCE_MEM,
  874. },
  875. [1] = {
  876. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  877. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  878. .flags = IORESOURCE_IRQ,
  879. },
  880. };
  881. static struct atmel_uart_data uart2_data = {
  882. .use_dma_tx = 1,
  883. .use_dma_rx = 1,
  884. };
  885. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  886. static struct platform_device at91sam9260_uart2_device = {
  887. .name = "atmel_usart",
  888. .id = 3,
  889. .dev = {
  890. .dma_mask = &uart2_dmamask,
  891. .coherent_dma_mask = DMA_BIT_MASK(32),
  892. .platform_data = &uart2_data,
  893. },
  894. .resource = uart2_resources,
  895. .num_resources = ARRAY_SIZE(uart2_resources),
  896. };
  897. static inline void configure_usart2_pins(unsigned pins)
  898. {
  899. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  900. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  901. if (pins & ATMEL_UART_RTS)
  902. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  903. if (pins & ATMEL_UART_CTS)
  904. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  905. }
  906. static struct resource uart3_resources[] = {
  907. [0] = {
  908. .start = AT91SAM9260_BASE_US3,
  909. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  910. .flags = IORESOURCE_MEM,
  911. },
  912. [1] = {
  913. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  914. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  915. .flags = IORESOURCE_IRQ,
  916. },
  917. };
  918. static struct atmel_uart_data uart3_data = {
  919. .use_dma_tx = 1,
  920. .use_dma_rx = 1,
  921. };
  922. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  923. static struct platform_device at91sam9260_uart3_device = {
  924. .name = "atmel_usart",
  925. .id = 4,
  926. .dev = {
  927. .dma_mask = &uart3_dmamask,
  928. .coherent_dma_mask = DMA_BIT_MASK(32),
  929. .platform_data = &uart3_data,
  930. },
  931. .resource = uart3_resources,
  932. .num_resources = ARRAY_SIZE(uart3_resources),
  933. };
  934. static inline void configure_usart3_pins(unsigned pins)
  935. {
  936. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  937. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  938. if (pins & ATMEL_UART_RTS)
  939. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  940. if (pins & ATMEL_UART_CTS)
  941. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  942. }
  943. static struct resource uart4_resources[] = {
  944. [0] = {
  945. .start = AT91SAM9260_BASE_US4,
  946. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  947. .flags = IORESOURCE_MEM,
  948. },
  949. [1] = {
  950. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  951. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  952. .flags = IORESOURCE_IRQ,
  953. },
  954. };
  955. static struct atmel_uart_data uart4_data = {
  956. .use_dma_tx = 1,
  957. .use_dma_rx = 1,
  958. };
  959. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  960. static struct platform_device at91sam9260_uart4_device = {
  961. .name = "atmel_usart",
  962. .id = 5,
  963. .dev = {
  964. .dma_mask = &uart4_dmamask,
  965. .coherent_dma_mask = DMA_BIT_MASK(32),
  966. .platform_data = &uart4_data,
  967. },
  968. .resource = uart4_resources,
  969. .num_resources = ARRAY_SIZE(uart4_resources),
  970. };
  971. static inline void configure_usart4_pins(void)
  972. {
  973. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  974. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  975. }
  976. static struct resource uart5_resources[] = {
  977. [0] = {
  978. .start = AT91SAM9260_BASE_US5,
  979. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  980. .flags = IORESOURCE_MEM,
  981. },
  982. [1] = {
  983. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  984. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  985. .flags = IORESOURCE_IRQ,
  986. },
  987. };
  988. static struct atmel_uart_data uart5_data = {
  989. .use_dma_tx = 1,
  990. .use_dma_rx = 1,
  991. };
  992. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  993. static struct platform_device at91sam9260_uart5_device = {
  994. .name = "atmel_usart",
  995. .id = 6,
  996. .dev = {
  997. .dma_mask = &uart5_dmamask,
  998. .coherent_dma_mask = DMA_BIT_MASK(32),
  999. .platform_data = &uart5_data,
  1000. },
  1001. .resource = uart5_resources,
  1002. .num_resources = ARRAY_SIZE(uart5_resources),
  1003. };
  1004. static inline void configure_usart5_pins(void)
  1005. {
  1006. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  1007. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  1008. }
  1009. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1010. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1011. {
  1012. struct platform_device *pdev;
  1013. struct atmel_uart_data *pdata;
  1014. switch (id) {
  1015. case 0: /* DBGU */
  1016. pdev = &at91sam9260_dbgu_device;
  1017. configure_dbgu_pins();
  1018. break;
  1019. case AT91SAM9260_ID_US0:
  1020. pdev = &at91sam9260_uart0_device;
  1021. configure_usart0_pins(pins);
  1022. break;
  1023. case AT91SAM9260_ID_US1:
  1024. pdev = &at91sam9260_uart1_device;
  1025. configure_usart1_pins(pins);
  1026. break;
  1027. case AT91SAM9260_ID_US2:
  1028. pdev = &at91sam9260_uart2_device;
  1029. configure_usart2_pins(pins);
  1030. break;
  1031. case AT91SAM9260_ID_US3:
  1032. pdev = &at91sam9260_uart3_device;
  1033. configure_usart3_pins(pins);
  1034. break;
  1035. case AT91SAM9260_ID_US4:
  1036. pdev = &at91sam9260_uart4_device;
  1037. configure_usart4_pins();
  1038. break;
  1039. case AT91SAM9260_ID_US5:
  1040. pdev = &at91sam9260_uart5_device;
  1041. configure_usart5_pins();
  1042. break;
  1043. default:
  1044. return;
  1045. }
  1046. pdata = pdev->dev.platform_data;
  1047. pdata->num = portnr; /* update to mapped ID */
  1048. if (portnr < ATMEL_MAX_UART)
  1049. at91_uarts[portnr] = pdev;
  1050. }
  1051. void __init at91_add_device_serial(void)
  1052. {
  1053. int i;
  1054. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1055. if (at91_uarts[i])
  1056. platform_device_register(at91_uarts[i]);
  1057. }
  1058. }
  1059. #else
  1060. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1061. void __init at91_add_device_serial(void) {}
  1062. #endif
  1063. /* --------------------------------------------------------------------
  1064. * CF/IDE
  1065. * -------------------------------------------------------------------- */
  1066. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
  1067. defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  1068. static struct at91_cf_data cf0_data;
  1069. static struct resource cf0_resources[] = {
  1070. [0] = {
  1071. .start = AT91_CHIPSELECT_4,
  1072. .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
  1073. .flags = IORESOURCE_MEM,
  1074. }
  1075. };
  1076. static struct platform_device cf0_device = {
  1077. .id = 0,
  1078. .dev = {
  1079. .platform_data = &cf0_data,
  1080. },
  1081. .resource = cf0_resources,
  1082. .num_resources = ARRAY_SIZE(cf0_resources),
  1083. };
  1084. static struct at91_cf_data cf1_data;
  1085. static struct resource cf1_resources[] = {
  1086. [0] = {
  1087. .start = AT91_CHIPSELECT_5,
  1088. .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
  1089. .flags = IORESOURCE_MEM,
  1090. }
  1091. };
  1092. static struct platform_device cf1_device = {
  1093. .id = 1,
  1094. .dev = {
  1095. .platform_data = &cf1_data,
  1096. },
  1097. .resource = cf1_resources,
  1098. .num_resources = ARRAY_SIZE(cf1_resources),
  1099. };
  1100. void __init at91_add_device_cf(struct at91_cf_data *data)
  1101. {
  1102. struct platform_device *pdev;
  1103. unsigned long csa;
  1104. if (!data)
  1105. return;
  1106. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  1107. switch (data->chipselect) {
  1108. case 4:
  1109. at91_set_multi_drive(AT91_PIN_PC8, 0);
  1110. at91_set_A_periph(AT91_PIN_PC8, 0);
  1111. csa |= AT91_MATRIX_CS4A_SMC_CF1;
  1112. cf0_data = *data;
  1113. pdev = &cf0_device;
  1114. break;
  1115. case 5:
  1116. at91_set_multi_drive(AT91_PIN_PC9, 0);
  1117. at91_set_A_periph(AT91_PIN_PC9, 0);
  1118. csa |= AT91_MATRIX_CS5A_SMC_CF2;
  1119. cf1_data = *data;
  1120. pdev = &cf1_device;
  1121. break;
  1122. default:
  1123. printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
  1124. data->chipselect);
  1125. return;
  1126. }
  1127. at91_matrix_write(AT91_MATRIX_EBICSA, csa);
  1128. if (gpio_is_valid(data->rst_pin)) {
  1129. at91_set_multi_drive(data->rst_pin, 0);
  1130. at91_set_gpio_output(data->rst_pin, 1);
  1131. }
  1132. if (gpio_is_valid(data->irq_pin)) {
  1133. at91_set_gpio_input(data->irq_pin, 0);
  1134. at91_set_deglitch(data->irq_pin, 1);
  1135. }
  1136. if (gpio_is_valid(data->det_pin)) {
  1137. at91_set_gpio_input(data->det_pin, 0);
  1138. at91_set_deglitch(data->det_pin, 1);
  1139. }
  1140. at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
  1141. at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
  1142. at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
  1143. at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
  1144. if (data->flags & AT91_CF_TRUE_IDE)
  1145. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
  1146. pdev->name = "pata_at91";
  1147. #else
  1148. #warning "board requires AT91_CF_TRUE_IDE: enable pata_at91"
  1149. #endif
  1150. else
  1151. pdev->name = "at91_cf";
  1152. platform_device_register(pdev);
  1153. }
  1154. #else
  1155. void __init at91_add_device_cf(struct at91_cf_data * data) {}
  1156. #endif
  1157. /* --------------------------------------------------------------------
  1158. * ADCs
  1159. * -------------------------------------------------------------------- */
  1160. #if IS_ENABLED(CONFIG_AT91_ADC)
  1161. static struct at91_adc_data adc_data;
  1162. static struct resource adc_resources[] = {
  1163. [0] = {
  1164. .start = AT91SAM9260_BASE_ADC,
  1165. .end = AT91SAM9260_BASE_ADC + SZ_16K - 1,
  1166. .flags = IORESOURCE_MEM,
  1167. },
  1168. [1] = {
  1169. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1170. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1171. .flags = IORESOURCE_IRQ,
  1172. },
  1173. };
  1174. static struct platform_device at91_adc_device = {
  1175. .name = "at91_adc",
  1176. .id = -1,
  1177. .dev = {
  1178. .platform_data = &adc_data,
  1179. },
  1180. .resource = adc_resources,
  1181. .num_resources = ARRAY_SIZE(adc_resources),
  1182. };
  1183. static struct at91_adc_trigger at91_adc_triggers[] = {
  1184. [0] = {
  1185. .name = "timer-counter-0",
  1186. .value = AT91_ADC_TRGSEL_TC0 | AT91_ADC_TRGEN,
  1187. },
  1188. [1] = {
  1189. .name = "timer-counter-1",
  1190. .value = AT91_ADC_TRGSEL_TC1 | AT91_ADC_TRGEN,
  1191. },
  1192. [2] = {
  1193. .name = "timer-counter-2",
  1194. .value = AT91_ADC_TRGSEL_TC2 | AT91_ADC_TRGEN,
  1195. },
  1196. [3] = {
  1197. .name = "external",
  1198. .value = AT91_ADC_TRGSEL_EXTERNAL | AT91_ADC_TRGEN,
  1199. .is_external = true,
  1200. },
  1201. };
  1202. static struct at91_adc_reg_desc at91_adc_register_g20 = {
  1203. .channel_base = AT91_ADC_CHR(0),
  1204. .drdy_mask = AT91_ADC_DRDY,
  1205. .status_register = AT91_ADC_SR,
  1206. .trigger_register = AT91_ADC_MR,
  1207. };
  1208. void __init at91_add_device_adc(struct at91_adc_data *data)
  1209. {
  1210. if (!data)
  1211. return;
  1212. if (test_bit(0, &data->channels_used))
  1213. at91_set_A_periph(AT91_PIN_PC0, 0);
  1214. if (test_bit(1, &data->channels_used))
  1215. at91_set_A_periph(AT91_PIN_PC1, 0);
  1216. if (test_bit(2, &data->channels_used))
  1217. at91_set_A_periph(AT91_PIN_PC2, 0);
  1218. if (test_bit(3, &data->channels_used))
  1219. at91_set_A_periph(AT91_PIN_PC3, 0);
  1220. if (data->use_external_triggers)
  1221. at91_set_A_periph(AT91_PIN_PA22, 0);
  1222. data->num_channels = 4;
  1223. data->startup_time = 10;
  1224. data->registers = &at91_adc_register_g20;
  1225. data->trigger_number = 4;
  1226. data->trigger_list = at91_adc_triggers;
  1227. adc_data = *data;
  1228. platform_device_register(&at91_adc_device);
  1229. }
  1230. #else
  1231. void __init at91_add_device_adc(struct at91_adc_data *data) {}
  1232. #endif
  1233. /* -------------------------------------------------------------------- */
  1234. /*
  1235. * These devices are always present and don't need any board-specific
  1236. * setup.
  1237. */
  1238. static int __init at91_add_standard_devices(void)
  1239. {
  1240. if (of_have_populated_dt())
  1241. return 0;
  1242. at91_add_device_rtt();
  1243. at91_add_device_watchdog();
  1244. at91_add_device_tc();
  1245. return 0;
  1246. }
  1247. arch_initcall(at91_add_standard_devices);