at91sam9260_devices.c 34 KB

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