at91sam9260_devices.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  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. .name = "at91_i2c",
  428. .id = -1,
  429. .resource = twi_resources,
  430. .num_resources = ARRAY_SIZE(twi_resources),
  431. };
  432. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  433. {
  434. /* pins used for TWI interface */
  435. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  436. at91_set_multi_drive(AT91_PIN_PA23, 1);
  437. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  438. at91_set_multi_drive(AT91_PIN_PA24, 1);
  439. i2c_register_board_info(0, devices, nr_devices);
  440. platform_device_register(&at91sam9260_twi_device);
  441. }
  442. #else
  443. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  444. #endif
  445. /* --------------------------------------------------------------------
  446. * SPI
  447. * -------------------------------------------------------------------- */
  448. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  449. static u64 spi_dmamask = DMA_BIT_MASK(32);
  450. static struct resource spi0_resources[] = {
  451. [0] = {
  452. .start = AT91SAM9260_BASE_SPI0,
  453. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  454. .flags = IORESOURCE_MEM,
  455. },
  456. [1] = {
  457. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  458. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  459. .flags = IORESOURCE_IRQ,
  460. },
  461. };
  462. static struct platform_device at91sam9260_spi0_device = {
  463. .name = "atmel_spi",
  464. .id = 0,
  465. .dev = {
  466. .dma_mask = &spi_dmamask,
  467. .coherent_dma_mask = DMA_BIT_MASK(32),
  468. },
  469. .resource = spi0_resources,
  470. .num_resources = ARRAY_SIZE(spi0_resources),
  471. };
  472. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  473. static struct resource spi1_resources[] = {
  474. [0] = {
  475. .start = AT91SAM9260_BASE_SPI1,
  476. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  477. .flags = IORESOURCE_MEM,
  478. },
  479. [1] = {
  480. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  481. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  482. .flags = IORESOURCE_IRQ,
  483. },
  484. };
  485. static struct platform_device at91sam9260_spi1_device = {
  486. .name = "atmel_spi",
  487. .id = 1,
  488. .dev = {
  489. .dma_mask = &spi_dmamask,
  490. .coherent_dma_mask = DMA_BIT_MASK(32),
  491. },
  492. .resource = spi1_resources,
  493. .num_resources = ARRAY_SIZE(spi1_resources),
  494. };
  495. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  496. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  497. {
  498. int i;
  499. unsigned long cs_pin;
  500. short enable_spi0 = 0;
  501. short enable_spi1 = 0;
  502. /* Choose SPI chip-selects */
  503. for (i = 0; i < nr_devices; i++) {
  504. if (devices[i].controller_data)
  505. cs_pin = (unsigned long) devices[i].controller_data;
  506. else if (devices[i].bus_num == 0)
  507. cs_pin = spi0_standard_cs[devices[i].chip_select];
  508. else
  509. cs_pin = spi1_standard_cs[devices[i].chip_select];
  510. if (!gpio_is_valid(cs_pin))
  511. continue;
  512. if (devices[i].bus_num == 0)
  513. enable_spi0 = 1;
  514. else
  515. enable_spi1 = 1;
  516. /* enable chip-select pin */
  517. at91_set_gpio_output(cs_pin, 1);
  518. /* pass chip-select pin to driver */
  519. devices[i].controller_data = (void *) cs_pin;
  520. }
  521. spi_register_board_info(devices, nr_devices);
  522. /* Configure SPI bus(es) */
  523. if (enable_spi0) {
  524. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  525. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  526. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  527. platform_device_register(&at91sam9260_spi0_device);
  528. }
  529. if (enable_spi1) {
  530. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  531. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  532. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  533. platform_device_register(&at91sam9260_spi1_device);
  534. }
  535. }
  536. #else
  537. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  538. #endif
  539. /* --------------------------------------------------------------------
  540. * Timer/Counter blocks
  541. * -------------------------------------------------------------------- */
  542. #ifdef CONFIG_ATMEL_TCLIB
  543. static struct resource tcb0_resources[] = {
  544. [0] = {
  545. .start = AT91SAM9260_BASE_TCB0,
  546. .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
  547. .flags = IORESOURCE_MEM,
  548. },
  549. [1] = {
  550. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  551. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  552. .flags = IORESOURCE_IRQ,
  553. },
  554. [2] = {
  555. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  556. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  557. .flags = IORESOURCE_IRQ,
  558. },
  559. [3] = {
  560. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  561. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  562. .flags = IORESOURCE_IRQ,
  563. },
  564. };
  565. static struct platform_device at91sam9260_tcb0_device = {
  566. .name = "atmel_tcb",
  567. .id = 0,
  568. .resource = tcb0_resources,
  569. .num_resources = ARRAY_SIZE(tcb0_resources),
  570. };
  571. static struct resource tcb1_resources[] = {
  572. [0] = {
  573. .start = AT91SAM9260_BASE_TCB1,
  574. .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
  575. .flags = IORESOURCE_MEM,
  576. },
  577. [1] = {
  578. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  579. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  580. .flags = IORESOURCE_IRQ,
  581. },
  582. [2] = {
  583. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  584. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  585. .flags = IORESOURCE_IRQ,
  586. },
  587. [3] = {
  588. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  589. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  590. .flags = IORESOURCE_IRQ,
  591. },
  592. };
  593. static struct platform_device at91sam9260_tcb1_device = {
  594. .name = "atmel_tcb",
  595. .id = 1,
  596. .resource = tcb1_resources,
  597. .num_resources = ARRAY_SIZE(tcb1_resources),
  598. };
  599. static void __init at91_add_device_tc(void)
  600. {
  601. platform_device_register(&at91sam9260_tcb0_device);
  602. platform_device_register(&at91sam9260_tcb1_device);
  603. }
  604. #else
  605. static void __init at91_add_device_tc(void) { }
  606. #endif
  607. /* --------------------------------------------------------------------
  608. * RTT
  609. * -------------------------------------------------------------------- */
  610. static struct resource rtt_resources[] = {
  611. {
  612. .start = AT91SAM9260_BASE_RTT,
  613. .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
  614. .flags = IORESOURCE_MEM,
  615. }, {
  616. .flags = IORESOURCE_MEM,
  617. }, {
  618. .flags = IORESOURCE_IRQ,
  619. },
  620. };
  621. static struct platform_device at91sam9260_rtt_device = {
  622. .name = "at91_rtt",
  623. .id = 0,
  624. .resource = rtt_resources,
  625. };
  626. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  627. static void __init at91_add_device_rtt_rtc(void)
  628. {
  629. at91sam9260_rtt_device.name = "rtc-at91sam9";
  630. /*
  631. * The second resource is needed:
  632. * GPBR will serve as the storage for RTC time offset
  633. */
  634. at91sam9260_rtt_device.num_resources = 3;
  635. rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
  636. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  637. rtt_resources[1].end = rtt_resources[1].start + 3;
  638. rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
  639. rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
  640. }
  641. #else
  642. static void __init at91_add_device_rtt_rtc(void)
  643. {
  644. /* Only one resource is needed: RTT not used as RTC */
  645. at91sam9260_rtt_device.num_resources = 1;
  646. }
  647. #endif
  648. static void __init at91_add_device_rtt(void)
  649. {
  650. at91_add_device_rtt_rtc();
  651. platform_device_register(&at91sam9260_rtt_device);
  652. }
  653. /* --------------------------------------------------------------------
  654. * Watchdog
  655. * -------------------------------------------------------------------- */
  656. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  657. static struct resource wdt_resources[] = {
  658. {
  659. .start = AT91SAM9260_BASE_WDT,
  660. .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
  661. .flags = IORESOURCE_MEM,
  662. }
  663. };
  664. static struct platform_device at91sam9260_wdt_device = {
  665. .name = "at91_wdt",
  666. .id = -1,
  667. .resource = wdt_resources,
  668. .num_resources = ARRAY_SIZE(wdt_resources),
  669. };
  670. static void __init at91_add_device_watchdog(void)
  671. {
  672. platform_device_register(&at91sam9260_wdt_device);
  673. }
  674. #else
  675. static void __init at91_add_device_watchdog(void) {}
  676. #endif
  677. /* --------------------------------------------------------------------
  678. * SSC -- Synchronous Serial Controller
  679. * -------------------------------------------------------------------- */
  680. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  681. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  682. static struct resource ssc_resources[] = {
  683. [0] = {
  684. .start = AT91SAM9260_BASE_SSC,
  685. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  686. .flags = IORESOURCE_MEM,
  687. },
  688. [1] = {
  689. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  690. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  691. .flags = IORESOURCE_IRQ,
  692. },
  693. };
  694. static struct platform_device at91sam9260_ssc_device = {
  695. .name = "ssc",
  696. .id = 0,
  697. .dev = {
  698. .dma_mask = &ssc_dmamask,
  699. .coherent_dma_mask = DMA_BIT_MASK(32),
  700. },
  701. .resource = ssc_resources,
  702. .num_resources = ARRAY_SIZE(ssc_resources),
  703. };
  704. static inline void configure_ssc_pins(unsigned pins)
  705. {
  706. if (pins & ATMEL_SSC_TF)
  707. at91_set_A_periph(AT91_PIN_PB17, 1);
  708. if (pins & ATMEL_SSC_TK)
  709. at91_set_A_periph(AT91_PIN_PB16, 1);
  710. if (pins & ATMEL_SSC_TD)
  711. at91_set_A_periph(AT91_PIN_PB18, 1);
  712. if (pins & ATMEL_SSC_RD)
  713. at91_set_A_periph(AT91_PIN_PB19, 1);
  714. if (pins & ATMEL_SSC_RK)
  715. at91_set_A_periph(AT91_PIN_PB20, 1);
  716. if (pins & ATMEL_SSC_RF)
  717. at91_set_A_periph(AT91_PIN_PB21, 1);
  718. }
  719. /*
  720. * SSC controllers are accessed through library code, instead of any
  721. * kind of all-singing/all-dancing driver. For example one could be
  722. * used by a particular I2S audio codec's driver, while another one
  723. * on the same system might be used by a custom data capture driver.
  724. */
  725. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  726. {
  727. struct platform_device *pdev;
  728. /*
  729. * NOTE: caller is responsible for passing information matching
  730. * "pins" to whatever will be using each particular controller.
  731. */
  732. switch (id) {
  733. case AT91SAM9260_ID_SSC:
  734. pdev = &at91sam9260_ssc_device;
  735. configure_ssc_pins(pins);
  736. break;
  737. default:
  738. return;
  739. }
  740. platform_device_register(pdev);
  741. }
  742. #else
  743. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  744. #endif
  745. /* --------------------------------------------------------------------
  746. * UART
  747. * -------------------------------------------------------------------- */
  748. #if defined(CONFIG_SERIAL_ATMEL)
  749. static struct resource dbgu_resources[] = {
  750. [0] = {
  751. .start = AT91SAM9260_BASE_DBGU,
  752. .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
  753. .flags = IORESOURCE_MEM,
  754. },
  755. [1] = {
  756. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  757. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  758. .flags = IORESOURCE_IRQ,
  759. },
  760. };
  761. static struct atmel_uart_data dbgu_data = {
  762. .use_dma_tx = 0,
  763. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  764. };
  765. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  766. static struct platform_device at91sam9260_dbgu_device = {
  767. .name = "atmel_usart",
  768. .id = 0,
  769. .dev = {
  770. .dma_mask = &dbgu_dmamask,
  771. .coherent_dma_mask = DMA_BIT_MASK(32),
  772. .platform_data = &dbgu_data,
  773. },
  774. .resource = dbgu_resources,
  775. .num_resources = ARRAY_SIZE(dbgu_resources),
  776. };
  777. static inline void configure_dbgu_pins(void)
  778. {
  779. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  780. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  781. }
  782. static struct resource uart0_resources[] = {
  783. [0] = {
  784. .start = AT91SAM9260_BASE_US0,
  785. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  786. .flags = IORESOURCE_MEM,
  787. },
  788. [1] = {
  789. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  790. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  791. .flags = IORESOURCE_IRQ,
  792. },
  793. };
  794. static struct atmel_uart_data uart0_data = {
  795. .use_dma_tx = 1,
  796. .use_dma_rx = 1,
  797. };
  798. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  799. static struct platform_device at91sam9260_uart0_device = {
  800. .name = "atmel_usart",
  801. .id = 1,
  802. .dev = {
  803. .dma_mask = &uart0_dmamask,
  804. .coherent_dma_mask = DMA_BIT_MASK(32),
  805. .platform_data = &uart0_data,
  806. },
  807. .resource = uart0_resources,
  808. .num_resources = ARRAY_SIZE(uart0_resources),
  809. };
  810. static inline void configure_usart0_pins(unsigned pins)
  811. {
  812. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  813. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  814. if (pins & ATMEL_UART_RTS)
  815. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  816. if (pins & ATMEL_UART_CTS)
  817. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  818. if (pins & ATMEL_UART_DTR)
  819. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  820. if (pins & ATMEL_UART_DSR)
  821. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  822. if (pins & ATMEL_UART_DCD)
  823. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  824. if (pins & ATMEL_UART_RI)
  825. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  826. }
  827. static struct resource uart1_resources[] = {
  828. [0] = {
  829. .start = AT91SAM9260_BASE_US1,
  830. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  831. .flags = IORESOURCE_MEM,
  832. },
  833. [1] = {
  834. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  835. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  836. .flags = IORESOURCE_IRQ,
  837. },
  838. };
  839. static struct atmel_uart_data uart1_data = {
  840. .use_dma_tx = 1,
  841. .use_dma_rx = 1,
  842. };
  843. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  844. static struct platform_device at91sam9260_uart1_device = {
  845. .name = "atmel_usart",
  846. .id = 2,
  847. .dev = {
  848. .dma_mask = &uart1_dmamask,
  849. .coherent_dma_mask = DMA_BIT_MASK(32),
  850. .platform_data = &uart1_data,
  851. },
  852. .resource = uart1_resources,
  853. .num_resources = ARRAY_SIZE(uart1_resources),
  854. };
  855. static inline void configure_usart1_pins(unsigned pins)
  856. {
  857. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  858. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  859. if (pins & ATMEL_UART_RTS)
  860. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  861. if (pins & ATMEL_UART_CTS)
  862. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  863. }
  864. static struct resource uart2_resources[] = {
  865. [0] = {
  866. .start = AT91SAM9260_BASE_US2,
  867. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  868. .flags = IORESOURCE_MEM,
  869. },
  870. [1] = {
  871. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  872. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  873. .flags = IORESOURCE_IRQ,
  874. },
  875. };
  876. static struct atmel_uart_data uart2_data = {
  877. .use_dma_tx = 1,
  878. .use_dma_rx = 1,
  879. };
  880. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  881. static struct platform_device at91sam9260_uart2_device = {
  882. .name = "atmel_usart",
  883. .id = 3,
  884. .dev = {
  885. .dma_mask = &uart2_dmamask,
  886. .coherent_dma_mask = DMA_BIT_MASK(32),
  887. .platform_data = &uart2_data,
  888. },
  889. .resource = uart2_resources,
  890. .num_resources = ARRAY_SIZE(uart2_resources),
  891. };
  892. static inline void configure_usart2_pins(unsigned pins)
  893. {
  894. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  895. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  896. if (pins & ATMEL_UART_RTS)
  897. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  898. if (pins & ATMEL_UART_CTS)
  899. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  900. }
  901. static struct resource uart3_resources[] = {
  902. [0] = {
  903. .start = AT91SAM9260_BASE_US3,
  904. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  905. .flags = IORESOURCE_MEM,
  906. },
  907. [1] = {
  908. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  909. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  910. .flags = IORESOURCE_IRQ,
  911. },
  912. };
  913. static struct atmel_uart_data uart3_data = {
  914. .use_dma_tx = 1,
  915. .use_dma_rx = 1,
  916. };
  917. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  918. static struct platform_device at91sam9260_uart3_device = {
  919. .name = "atmel_usart",
  920. .id = 4,
  921. .dev = {
  922. .dma_mask = &uart3_dmamask,
  923. .coherent_dma_mask = DMA_BIT_MASK(32),
  924. .platform_data = &uart3_data,
  925. },
  926. .resource = uart3_resources,
  927. .num_resources = ARRAY_SIZE(uart3_resources),
  928. };
  929. static inline void configure_usart3_pins(unsigned pins)
  930. {
  931. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  932. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  933. if (pins & ATMEL_UART_RTS)
  934. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  935. if (pins & ATMEL_UART_CTS)
  936. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  937. }
  938. static struct resource uart4_resources[] = {
  939. [0] = {
  940. .start = AT91SAM9260_BASE_US4,
  941. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  942. .flags = IORESOURCE_MEM,
  943. },
  944. [1] = {
  945. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  946. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  947. .flags = IORESOURCE_IRQ,
  948. },
  949. };
  950. static struct atmel_uart_data uart4_data = {
  951. .use_dma_tx = 1,
  952. .use_dma_rx = 1,
  953. };
  954. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  955. static struct platform_device at91sam9260_uart4_device = {
  956. .name = "atmel_usart",
  957. .id = 5,
  958. .dev = {
  959. .dma_mask = &uart4_dmamask,
  960. .coherent_dma_mask = DMA_BIT_MASK(32),
  961. .platform_data = &uart4_data,
  962. },
  963. .resource = uart4_resources,
  964. .num_resources = ARRAY_SIZE(uart4_resources),
  965. };
  966. static inline void configure_usart4_pins(void)
  967. {
  968. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  969. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  970. }
  971. static struct resource uart5_resources[] = {
  972. [0] = {
  973. .start = AT91SAM9260_BASE_US5,
  974. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  975. .flags = IORESOURCE_MEM,
  976. },
  977. [1] = {
  978. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  979. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  980. .flags = IORESOURCE_IRQ,
  981. },
  982. };
  983. static struct atmel_uart_data uart5_data = {
  984. .use_dma_tx = 1,
  985. .use_dma_rx = 1,
  986. };
  987. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  988. static struct platform_device at91sam9260_uart5_device = {
  989. .name = "atmel_usart",
  990. .id = 6,
  991. .dev = {
  992. .dma_mask = &uart5_dmamask,
  993. .coherent_dma_mask = DMA_BIT_MASK(32),
  994. .platform_data = &uart5_data,
  995. },
  996. .resource = uart5_resources,
  997. .num_resources = ARRAY_SIZE(uart5_resources),
  998. };
  999. static inline void configure_usart5_pins(void)
  1000. {
  1001. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  1002. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  1003. }
  1004. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1005. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1006. {
  1007. struct platform_device *pdev;
  1008. struct atmel_uart_data *pdata;
  1009. switch (id) {
  1010. case 0: /* DBGU */
  1011. pdev = &at91sam9260_dbgu_device;
  1012. configure_dbgu_pins();
  1013. break;
  1014. case AT91SAM9260_ID_US0:
  1015. pdev = &at91sam9260_uart0_device;
  1016. configure_usart0_pins(pins);
  1017. break;
  1018. case AT91SAM9260_ID_US1:
  1019. pdev = &at91sam9260_uart1_device;
  1020. configure_usart1_pins(pins);
  1021. break;
  1022. case AT91SAM9260_ID_US2:
  1023. pdev = &at91sam9260_uart2_device;
  1024. configure_usart2_pins(pins);
  1025. break;
  1026. case AT91SAM9260_ID_US3:
  1027. pdev = &at91sam9260_uart3_device;
  1028. configure_usart3_pins(pins);
  1029. break;
  1030. case AT91SAM9260_ID_US4:
  1031. pdev = &at91sam9260_uart4_device;
  1032. configure_usart4_pins();
  1033. break;
  1034. case AT91SAM9260_ID_US5:
  1035. pdev = &at91sam9260_uart5_device;
  1036. configure_usart5_pins();
  1037. break;
  1038. default:
  1039. return;
  1040. }
  1041. pdata = pdev->dev.platform_data;
  1042. pdata->num = portnr; /* update to mapped ID */
  1043. if (portnr < ATMEL_MAX_UART)
  1044. at91_uarts[portnr] = pdev;
  1045. }
  1046. void __init at91_add_device_serial(void)
  1047. {
  1048. int i;
  1049. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1050. if (at91_uarts[i])
  1051. platform_device_register(at91_uarts[i]);
  1052. }
  1053. }
  1054. #else
  1055. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1056. void __init at91_add_device_serial(void) {}
  1057. #endif
  1058. /* --------------------------------------------------------------------
  1059. * CF/IDE
  1060. * -------------------------------------------------------------------- */
  1061. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
  1062. defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  1063. static struct at91_cf_data cf0_data;
  1064. static struct resource cf0_resources[] = {
  1065. [0] = {
  1066. .start = AT91_CHIPSELECT_4,
  1067. .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
  1068. .flags = IORESOURCE_MEM,
  1069. }
  1070. };
  1071. static struct platform_device cf0_device = {
  1072. .id = 0,
  1073. .dev = {
  1074. .platform_data = &cf0_data,
  1075. },
  1076. .resource = cf0_resources,
  1077. .num_resources = ARRAY_SIZE(cf0_resources),
  1078. };
  1079. static struct at91_cf_data cf1_data;
  1080. static struct resource cf1_resources[] = {
  1081. [0] = {
  1082. .start = AT91_CHIPSELECT_5,
  1083. .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
  1084. .flags = IORESOURCE_MEM,
  1085. }
  1086. };
  1087. static struct platform_device cf1_device = {
  1088. .id = 1,
  1089. .dev = {
  1090. .platform_data = &cf1_data,
  1091. },
  1092. .resource = cf1_resources,
  1093. .num_resources = ARRAY_SIZE(cf1_resources),
  1094. };
  1095. void __init at91_add_device_cf(struct at91_cf_data *data)
  1096. {
  1097. struct platform_device *pdev;
  1098. unsigned long csa;
  1099. if (!data)
  1100. return;
  1101. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  1102. switch (data->chipselect) {
  1103. case 4:
  1104. at91_set_multi_drive(AT91_PIN_PC8, 0);
  1105. at91_set_A_periph(AT91_PIN_PC8, 0);
  1106. csa |= AT91_MATRIX_CS4A_SMC_CF1;
  1107. cf0_data = *data;
  1108. pdev = &cf0_device;
  1109. break;
  1110. case 5:
  1111. at91_set_multi_drive(AT91_PIN_PC9, 0);
  1112. at91_set_A_periph(AT91_PIN_PC9, 0);
  1113. csa |= AT91_MATRIX_CS5A_SMC_CF2;
  1114. cf1_data = *data;
  1115. pdev = &cf1_device;
  1116. break;
  1117. default:
  1118. printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
  1119. data->chipselect);
  1120. return;
  1121. }
  1122. at91_matrix_write(AT91_MATRIX_EBICSA, csa);
  1123. if (gpio_is_valid(data->rst_pin)) {
  1124. at91_set_multi_drive(data->rst_pin, 0);
  1125. at91_set_gpio_output(data->rst_pin, 1);
  1126. }
  1127. if (gpio_is_valid(data->irq_pin)) {
  1128. at91_set_gpio_input(data->irq_pin, 0);
  1129. at91_set_deglitch(data->irq_pin, 1);
  1130. }
  1131. if (gpio_is_valid(data->det_pin)) {
  1132. at91_set_gpio_input(data->det_pin, 0);
  1133. at91_set_deglitch(data->det_pin, 1);
  1134. }
  1135. at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
  1136. at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
  1137. at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
  1138. at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
  1139. if (data->flags & AT91_CF_TRUE_IDE)
  1140. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
  1141. pdev->name = "pata_at91";
  1142. #else
  1143. #warning "board requires AT91_CF_TRUE_IDE: enable pata_at91"
  1144. #endif
  1145. else
  1146. pdev->name = "at91_cf";
  1147. platform_device_register(pdev);
  1148. }
  1149. #else
  1150. void __init at91_add_device_cf(struct at91_cf_data * data) {}
  1151. #endif
  1152. /* --------------------------------------------------------------------
  1153. * ADCs
  1154. * -------------------------------------------------------------------- */
  1155. #if IS_ENABLED(CONFIG_AT91_ADC)
  1156. static struct at91_adc_data adc_data;
  1157. static struct resource adc_resources[] = {
  1158. [0] = {
  1159. .start = AT91SAM9260_BASE_ADC,
  1160. .end = AT91SAM9260_BASE_ADC + SZ_16K - 1,
  1161. .flags = IORESOURCE_MEM,
  1162. },
  1163. [1] = {
  1164. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1165. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1166. .flags = IORESOURCE_IRQ,
  1167. },
  1168. };
  1169. static struct platform_device at91_adc_device = {
  1170. .name = "at91_adc",
  1171. .id = -1,
  1172. .dev = {
  1173. .platform_data = &adc_data,
  1174. },
  1175. .resource = adc_resources,
  1176. .num_resources = ARRAY_SIZE(adc_resources),
  1177. };
  1178. static struct at91_adc_trigger at91_adc_triggers[] = {
  1179. [0] = {
  1180. .name = "timer-counter-0",
  1181. .value = AT91_ADC_TRGSEL_TC0 | AT91_ADC_TRGEN,
  1182. },
  1183. [1] = {
  1184. .name = "timer-counter-1",
  1185. .value = AT91_ADC_TRGSEL_TC1 | AT91_ADC_TRGEN,
  1186. },
  1187. [2] = {
  1188. .name = "timer-counter-2",
  1189. .value = AT91_ADC_TRGSEL_TC2 | AT91_ADC_TRGEN,
  1190. },
  1191. [3] = {
  1192. .name = "external",
  1193. .value = AT91_ADC_TRGSEL_EXTERNAL | AT91_ADC_TRGEN,
  1194. .is_external = true,
  1195. },
  1196. };
  1197. static struct at91_adc_reg_desc at91_adc_register_g20 = {
  1198. .channel_base = AT91_ADC_CHR(0),
  1199. .drdy_mask = AT91_ADC_DRDY,
  1200. .status_register = AT91_ADC_SR,
  1201. .trigger_register = AT91_ADC_MR,
  1202. };
  1203. void __init at91_add_device_adc(struct at91_adc_data *data)
  1204. {
  1205. if (!data)
  1206. return;
  1207. if (test_bit(0, &data->channels_used))
  1208. at91_set_A_periph(AT91_PIN_PC0, 0);
  1209. if (test_bit(1, &data->channels_used))
  1210. at91_set_A_periph(AT91_PIN_PC1, 0);
  1211. if (test_bit(2, &data->channels_used))
  1212. at91_set_A_periph(AT91_PIN_PC2, 0);
  1213. if (test_bit(3, &data->channels_used))
  1214. at91_set_A_periph(AT91_PIN_PC3, 0);
  1215. if (data->use_external_triggers)
  1216. at91_set_A_periph(AT91_PIN_PA22, 0);
  1217. data->num_channels = 4;
  1218. data->startup_time = 10;
  1219. data->registers = &at91_adc_register_g20;
  1220. data->trigger_number = 4;
  1221. data->trigger_list = at91_adc_triggers;
  1222. adc_data = *data;
  1223. platform_device_register(&at91_adc_device);
  1224. }
  1225. #else
  1226. void __init at91_add_device_adc(struct at91_adc_data *data) {}
  1227. #endif
  1228. /* -------------------------------------------------------------------- */
  1229. /*
  1230. * These devices are always present and don't need any board-specific
  1231. * setup.
  1232. */
  1233. static int __init at91_add_standard_devices(void)
  1234. {
  1235. if (of_have_populated_dt())
  1236. return 0;
  1237. at91_add_device_rtt();
  1238. at91_add_device_watchdog();
  1239. at91_add_device_tc();
  1240. return 0;
  1241. }
  1242. arch_initcall(at91_add_standard_devices);