at91sam9260_devices.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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 Slot for Atmel MCI Driver
  179. * -------------------------------------------------------------------- */
  180. #if IS_ENABLED(CONFIG_MMC_ATMELMCI)
  181. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  182. static struct mci_platform_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 = "atmel_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_mci(short mmc_id, struct mci_platform_data *data)
  207. {
  208. unsigned int i;
  209. unsigned int slot_count = 0;
  210. if (!data)
  211. return;
  212. for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
  213. if (data->slot[i].bus_width) {
  214. /* input/irq */
  215. if (gpio_is_valid(data->slot[i].detect_pin)) {
  216. at91_set_gpio_input(data->slot[i].detect_pin, 1);
  217. at91_set_deglitch(data->slot[i].detect_pin, 1);
  218. }
  219. if (gpio_is_valid(data->slot[i].wp_pin))
  220. at91_set_gpio_input(data->slot[i].wp_pin, 1);
  221. switch (i) {
  222. case 0:
  223. /* CMD */
  224. at91_set_A_periph(AT91_PIN_PA7, 1);
  225. /* DAT0, maybe DAT1..DAT3 */
  226. at91_set_A_periph(AT91_PIN_PA6, 1);
  227. if (data->slot[i].bus_width == 4) {
  228. at91_set_A_periph(AT91_PIN_PA9, 1);
  229. at91_set_A_periph(AT91_PIN_PA10, 1);
  230. at91_set_A_periph(AT91_PIN_PA11, 1);
  231. }
  232. slot_count++;
  233. break;
  234. case 1:
  235. /* CMD */
  236. at91_set_B_periph(AT91_PIN_PA1, 1);
  237. /* DAT0, maybe DAT1..DAT3 */
  238. at91_set_B_periph(AT91_PIN_PA0, 1);
  239. if (data->slot[i].bus_width == 4) {
  240. at91_set_B_periph(AT91_PIN_PA5, 1);
  241. at91_set_B_periph(AT91_PIN_PA4, 1);
  242. at91_set_B_periph(AT91_PIN_PA3, 1);
  243. }
  244. slot_count++;
  245. break;
  246. default:
  247. printk(KERN_ERR
  248. "AT91: SD/MMC slot %d not available\n", i);
  249. break;
  250. }
  251. }
  252. }
  253. if (slot_count) {
  254. /* CLK */
  255. at91_set_A_periph(AT91_PIN_PA8, 0);
  256. mmc_data = *data;
  257. platform_device_register(&at91sam9260_mmc_device);
  258. }
  259. }
  260. #else
  261. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
  262. #endif
  263. /* --------------------------------------------------------------------
  264. * NAND / SmartMedia
  265. * -------------------------------------------------------------------- */
  266. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  267. static struct atmel_nand_data nand_data;
  268. #define NAND_BASE AT91_CHIPSELECT_3
  269. static struct resource nand_resources[] = {
  270. [0] = {
  271. .start = NAND_BASE,
  272. .end = NAND_BASE + SZ_256M - 1,
  273. .flags = IORESOURCE_MEM,
  274. },
  275. [1] = {
  276. .start = AT91SAM9260_BASE_ECC,
  277. .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
  278. .flags = IORESOURCE_MEM,
  279. }
  280. };
  281. static struct platform_device at91sam9260_nand_device = {
  282. .name = "atmel_nand",
  283. .id = -1,
  284. .dev = {
  285. .platform_data = &nand_data,
  286. },
  287. .resource = nand_resources,
  288. .num_resources = ARRAY_SIZE(nand_resources),
  289. };
  290. void __init at91_add_device_nand(struct atmel_nand_data *data)
  291. {
  292. unsigned long csa;
  293. if (!data)
  294. return;
  295. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  296. at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  297. /* enable pin */
  298. if (gpio_is_valid(data->enable_pin))
  299. at91_set_gpio_output(data->enable_pin, 1);
  300. /* ready/busy pin */
  301. if (gpio_is_valid(data->rdy_pin))
  302. at91_set_gpio_input(data->rdy_pin, 1);
  303. /* card detect pin */
  304. if (gpio_is_valid(data->det_pin))
  305. at91_set_gpio_input(data->det_pin, 1);
  306. nand_data = *data;
  307. platform_device_register(&at91sam9260_nand_device);
  308. }
  309. #else
  310. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  311. #endif
  312. /* --------------------------------------------------------------------
  313. * TWI (i2c)
  314. * -------------------------------------------------------------------- */
  315. /*
  316. * Prefer the GPIO code since the TWI controller isn't robust
  317. * (gets overruns and underruns under load) and can only issue
  318. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  319. */
  320. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  321. static struct i2c_gpio_platform_data pdata = {
  322. .sda_pin = AT91_PIN_PA23,
  323. .sda_is_open_drain = 1,
  324. .scl_pin = AT91_PIN_PA24,
  325. .scl_is_open_drain = 1,
  326. .udelay = 2, /* ~100 kHz */
  327. };
  328. static struct platform_device at91sam9260_twi_device = {
  329. .name = "i2c-gpio",
  330. .id = 0,
  331. .dev.platform_data = &pdata,
  332. };
  333. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  334. {
  335. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  336. at91_set_multi_drive(AT91_PIN_PA23, 1);
  337. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  338. at91_set_multi_drive(AT91_PIN_PA24, 1);
  339. i2c_register_board_info(0, devices, nr_devices);
  340. platform_device_register(&at91sam9260_twi_device);
  341. }
  342. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  343. static struct resource twi_resources[] = {
  344. [0] = {
  345. .start = AT91SAM9260_BASE_TWI,
  346. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  347. .flags = IORESOURCE_MEM,
  348. },
  349. [1] = {
  350. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  351. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  352. .flags = IORESOURCE_IRQ,
  353. },
  354. };
  355. static struct platform_device at91sam9260_twi_device = {
  356. .id = 0,
  357. .resource = twi_resources,
  358. .num_resources = ARRAY_SIZE(twi_resources),
  359. };
  360. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  361. {
  362. /* IP version is not the same on 9260 and g20 */
  363. if (cpu_is_at91sam9g20()) {
  364. at91sam9260_twi_device.name = "i2c-at91sam9g20";
  365. } else {
  366. at91sam9260_twi_device.name = "i2c-at91sam9260";
  367. }
  368. /* pins used for TWI interface */
  369. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  370. at91_set_multi_drive(AT91_PIN_PA23, 1);
  371. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  372. at91_set_multi_drive(AT91_PIN_PA24, 1);
  373. i2c_register_board_info(0, devices, nr_devices);
  374. platform_device_register(&at91sam9260_twi_device);
  375. }
  376. #else
  377. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  378. #endif
  379. /* --------------------------------------------------------------------
  380. * SPI
  381. * -------------------------------------------------------------------- */
  382. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  383. static u64 spi_dmamask = DMA_BIT_MASK(32);
  384. static struct resource spi0_resources[] = {
  385. [0] = {
  386. .start = AT91SAM9260_BASE_SPI0,
  387. .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
  388. .flags = IORESOURCE_MEM,
  389. },
  390. [1] = {
  391. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  392. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
  393. .flags = IORESOURCE_IRQ,
  394. },
  395. };
  396. static struct platform_device at91sam9260_spi0_device = {
  397. .name = "atmel_spi",
  398. .id = 0,
  399. .dev = {
  400. .dma_mask = &spi_dmamask,
  401. .coherent_dma_mask = DMA_BIT_MASK(32),
  402. },
  403. .resource = spi0_resources,
  404. .num_resources = ARRAY_SIZE(spi0_resources),
  405. };
  406. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
  407. static struct resource spi1_resources[] = {
  408. [0] = {
  409. .start = AT91SAM9260_BASE_SPI1,
  410. .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
  411. .flags = IORESOURCE_MEM,
  412. },
  413. [1] = {
  414. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  415. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
  416. .flags = IORESOURCE_IRQ,
  417. },
  418. };
  419. static struct platform_device at91sam9260_spi1_device = {
  420. .name = "atmel_spi",
  421. .id = 1,
  422. .dev = {
  423. .dma_mask = &spi_dmamask,
  424. .coherent_dma_mask = DMA_BIT_MASK(32),
  425. },
  426. .resource = spi1_resources,
  427. .num_resources = ARRAY_SIZE(spi1_resources),
  428. };
  429. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
  430. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  431. {
  432. int i;
  433. unsigned long cs_pin;
  434. short enable_spi0 = 0;
  435. short enable_spi1 = 0;
  436. /* Choose SPI chip-selects */
  437. for (i = 0; i < nr_devices; i++) {
  438. if (devices[i].controller_data)
  439. cs_pin = (unsigned long) devices[i].controller_data;
  440. else if (devices[i].bus_num == 0)
  441. cs_pin = spi0_standard_cs[devices[i].chip_select];
  442. else
  443. cs_pin = spi1_standard_cs[devices[i].chip_select];
  444. if (!gpio_is_valid(cs_pin))
  445. continue;
  446. if (devices[i].bus_num == 0)
  447. enable_spi0 = 1;
  448. else
  449. enable_spi1 = 1;
  450. /* enable chip-select pin */
  451. at91_set_gpio_output(cs_pin, 1);
  452. /* pass chip-select pin to driver */
  453. devices[i].controller_data = (void *) cs_pin;
  454. }
  455. spi_register_board_info(devices, nr_devices);
  456. /* Configure SPI bus(es) */
  457. if (enable_spi0) {
  458. at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  459. at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  460. at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
  461. platform_device_register(&at91sam9260_spi0_device);
  462. }
  463. if (enable_spi1) {
  464. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
  465. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
  466. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
  467. platform_device_register(&at91sam9260_spi1_device);
  468. }
  469. }
  470. #else
  471. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  472. #endif
  473. /* --------------------------------------------------------------------
  474. * Timer/Counter blocks
  475. * -------------------------------------------------------------------- */
  476. #ifdef CONFIG_ATMEL_TCLIB
  477. static struct resource tcb0_resources[] = {
  478. [0] = {
  479. .start = AT91SAM9260_BASE_TCB0,
  480. .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
  481. .flags = IORESOURCE_MEM,
  482. },
  483. [1] = {
  484. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  485. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
  486. .flags = IORESOURCE_IRQ,
  487. },
  488. [2] = {
  489. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  490. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
  491. .flags = IORESOURCE_IRQ,
  492. },
  493. [3] = {
  494. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  495. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
  496. .flags = IORESOURCE_IRQ,
  497. },
  498. };
  499. static struct platform_device at91sam9260_tcb0_device = {
  500. .name = "atmel_tcb",
  501. .id = 0,
  502. .resource = tcb0_resources,
  503. .num_resources = ARRAY_SIZE(tcb0_resources),
  504. };
  505. static struct resource tcb1_resources[] = {
  506. [0] = {
  507. .start = AT91SAM9260_BASE_TCB1,
  508. .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
  509. .flags = IORESOURCE_MEM,
  510. },
  511. [1] = {
  512. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  513. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
  514. .flags = IORESOURCE_IRQ,
  515. },
  516. [2] = {
  517. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  518. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
  519. .flags = IORESOURCE_IRQ,
  520. },
  521. [3] = {
  522. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  523. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
  524. .flags = IORESOURCE_IRQ,
  525. },
  526. };
  527. static struct platform_device at91sam9260_tcb1_device = {
  528. .name = "atmel_tcb",
  529. .id = 1,
  530. .resource = tcb1_resources,
  531. .num_resources = ARRAY_SIZE(tcb1_resources),
  532. };
  533. static void __init at91_add_device_tc(void)
  534. {
  535. platform_device_register(&at91sam9260_tcb0_device);
  536. platform_device_register(&at91sam9260_tcb1_device);
  537. }
  538. #else
  539. static void __init at91_add_device_tc(void) { }
  540. #endif
  541. /* --------------------------------------------------------------------
  542. * RTT
  543. * -------------------------------------------------------------------- */
  544. static struct resource rtt_resources[] = {
  545. {
  546. .start = AT91SAM9260_BASE_RTT,
  547. .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
  548. .flags = IORESOURCE_MEM,
  549. }, {
  550. .flags = IORESOURCE_MEM,
  551. }, {
  552. .flags = IORESOURCE_IRQ,
  553. },
  554. };
  555. static struct platform_device at91sam9260_rtt_device = {
  556. .name = "at91_rtt",
  557. .id = 0,
  558. .resource = rtt_resources,
  559. };
  560. #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
  561. static void __init at91_add_device_rtt_rtc(void)
  562. {
  563. at91sam9260_rtt_device.name = "rtc-at91sam9";
  564. /*
  565. * The second resource is needed:
  566. * GPBR will serve as the storage for RTC time offset
  567. */
  568. at91sam9260_rtt_device.num_resources = 3;
  569. rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
  570. 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
  571. rtt_resources[1].end = rtt_resources[1].start + 3;
  572. rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
  573. rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
  574. }
  575. #else
  576. static void __init at91_add_device_rtt_rtc(void)
  577. {
  578. /* Only one resource is needed: RTT not used as RTC */
  579. at91sam9260_rtt_device.num_resources = 1;
  580. }
  581. #endif
  582. static void __init at91_add_device_rtt(void)
  583. {
  584. at91_add_device_rtt_rtc();
  585. platform_device_register(&at91sam9260_rtt_device);
  586. }
  587. /* --------------------------------------------------------------------
  588. * Watchdog
  589. * -------------------------------------------------------------------- */
  590. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  591. static struct resource wdt_resources[] = {
  592. {
  593. .start = AT91SAM9260_BASE_WDT,
  594. .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
  595. .flags = IORESOURCE_MEM,
  596. }
  597. };
  598. static struct platform_device at91sam9260_wdt_device = {
  599. .name = "at91_wdt",
  600. .id = -1,
  601. .resource = wdt_resources,
  602. .num_resources = ARRAY_SIZE(wdt_resources),
  603. };
  604. static void __init at91_add_device_watchdog(void)
  605. {
  606. platform_device_register(&at91sam9260_wdt_device);
  607. }
  608. #else
  609. static void __init at91_add_device_watchdog(void) {}
  610. #endif
  611. /* --------------------------------------------------------------------
  612. * SSC -- Synchronous Serial Controller
  613. * -------------------------------------------------------------------- */
  614. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  615. static u64 ssc_dmamask = DMA_BIT_MASK(32);
  616. static struct resource ssc_resources[] = {
  617. [0] = {
  618. .start = AT91SAM9260_BASE_SSC,
  619. .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
  620. .flags = IORESOURCE_MEM,
  621. },
  622. [1] = {
  623. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  624. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
  625. .flags = IORESOURCE_IRQ,
  626. },
  627. };
  628. static struct platform_device at91sam9260_ssc_device = {
  629. .name = "ssc",
  630. .id = 0,
  631. .dev = {
  632. .dma_mask = &ssc_dmamask,
  633. .coherent_dma_mask = DMA_BIT_MASK(32),
  634. },
  635. .resource = ssc_resources,
  636. .num_resources = ARRAY_SIZE(ssc_resources),
  637. };
  638. static inline void configure_ssc_pins(unsigned pins)
  639. {
  640. if (pins & ATMEL_SSC_TF)
  641. at91_set_A_periph(AT91_PIN_PB17, 1);
  642. if (pins & ATMEL_SSC_TK)
  643. at91_set_A_periph(AT91_PIN_PB16, 1);
  644. if (pins & ATMEL_SSC_TD)
  645. at91_set_A_periph(AT91_PIN_PB18, 1);
  646. if (pins & ATMEL_SSC_RD)
  647. at91_set_A_periph(AT91_PIN_PB19, 1);
  648. if (pins & ATMEL_SSC_RK)
  649. at91_set_A_periph(AT91_PIN_PB20, 1);
  650. if (pins & ATMEL_SSC_RF)
  651. at91_set_A_periph(AT91_PIN_PB21, 1);
  652. }
  653. static struct platform_device at91sam9260_ssc_dai_device = {
  654. .name = "atmel-ssc-dai",
  655. .id = 0,
  656. .dev = {
  657. .parent = &(at91sam9260_ssc_device.dev),
  658. },
  659. };
  660. /*
  661. * SSC controllers are accessed through library code, instead of any
  662. * kind of all-singing/all-dancing driver. For example one could be
  663. * used by a particular I2S audio codec's driver, while another one
  664. * on the same system might be used by a custom data capture driver.
  665. */
  666. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  667. {
  668. struct platform_device *pdev;
  669. /*
  670. * NOTE: caller is responsible for passing information matching
  671. * "pins" to whatever will be using each particular controller.
  672. */
  673. switch (id) {
  674. case AT91SAM9260_ID_SSC:
  675. pdev = &at91sam9260_ssc_device;
  676. configure_ssc_pins(pins);
  677. break;
  678. default:
  679. return;
  680. }
  681. platform_device_register(pdev);
  682. platform_device_register(&at91sam9260_ssc_dai_device);
  683. }
  684. #else
  685. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  686. #endif
  687. /* --------------------------------------------------------------------
  688. * UART
  689. * -------------------------------------------------------------------- */
  690. #if defined(CONFIG_SERIAL_ATMEL)
  691. static struct resource dbgu_resources[] = {
  692. [0] = {
  693. .start = AT91SAM9260_BASE_DBGU,
  694. .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
  695. .flags = IORESOURCE_MEM,
  696. },
  697. [1] = {
  698. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  699. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  700. .flags = IORESOURCE_IRQ,
  701. },
  702. };
  703. static struct atmel_uart_data dbgu_data = {
  704. .use_dma_tx = 0,
  705. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  706. };
  707. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  708. static struct platform_device at91sam9260_dbgu_device = {
  709. .name = "atmel_usart",
  710. .id = 0,
  711. .dev = {
  712. .dma_mask = &dbgu_dmamask,
  713. .coherent_dma_mask = DMA_BIT_MASK(32),
  714. .platform_data = &dbgu_data,
  715. },
  716. .resource = dbgu_resources,
  717. .num_resources = ARRAY_SIZE(dbgu_resources),
  718. };
  719. static inline void configure_dbgu_pins(void)
  720. {
  721. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  722. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  723. }
  724. static struct resource uart0_resources[] = {
  725. [0] = {
  726. .start = AT91SAM9260_BASE_US0,
  727. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  728. .flags = IORESOURCE_MEM,
  729. },
  730. [1] = {
  731. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  732. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  733. .flags = IORESOURCE_IRQ,
  734. },
  735. };
  736. static struct atmel_uart_data uart0_data = {
  737. .use_dma_tx = 1,
  738. .use_dma_rx = 1,
  739. };
  740. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  741. static struct platform_device at91sam9260_uart0_device = {
  742. .name = "atmel_usart",
  743. .id = 1,
  744. .dev = {
  745. .dma_mask = &uart0_dmamask,
  746. .coherent_dma_mask = DMA_BIT_MASK(32),
  747. .platform_data = &uart0_data,
  748. },
  749. .resource = uart0_resources,
  750. .num_resources = ARRAY_SIZE(uart0_resources),
  751. };
  752. static inline void configure_usart0_pins(unsigned pins)
  753. {
  754. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  755. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  756. if (pins & ATMEL_UART_RTS)
  757. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  758. if (pins & ATMEL_UART_CTS)
  759. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  760. if (pins & ATMEL_UART_DTR)
  761. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  762. if (pins & ATMEL_UART_DSR)
  763. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  764. if (pins & ATMEL_UART_DCD)
  765. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  766. if (pins & ATMEL_UART_RI)
  767. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  768. }
  769. static struct resource uart1_resources[] = {
  770. [0] = {
  771. .start = AT91SAM9260_BASE_US1,
  772. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  773. .flags = IORESOURCE_MEM,
  774. },
  775. [1] = {
  776. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  777. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  778. .flags = IORESOURCE_IRQ,
  779. },
  780. };
  781. static struct atmel_uart_data uart1_data = {
  782. .use_dma_tx = 1,
  783. .use_dma_rx = 1,
  784. };
  785. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  786. static struct platform_device at91sam9260_uart1_device = {
  787. .name = "atmel_usart",
  788. .id = 2,
  789. .dev = {
  790. .dma_mask = &uart1_dmamask,
  791. .coherent_dma_mask = DMA_BIT_MASK(32),
  792. .platform_data = &uart1_data,
  793. },
  794. .resource = uart1_resources,
  795. .num_resources = ARRAY_SIZE(uart1_resources),
  796. };
  797. static inline void configure_usart1_pins(unsigned pins)
  798. {
  799. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  800. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  801. if (pins & ATMEL_UART_RTS)
  802. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  803. if (pins & ATMEL_UART_CTS)
  804. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  805. }
  806. static struct resource uart2_resources[] = {
  807. [0] = {
  808. .start = AT91SAM9260_BASE_US2,
  809. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  810. .flags = IORESOURCE_MEM,
  811. },
  812. [1] = {
  813. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  814. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  815. .flags = IORESOURCE_IRQ,
  816. },
  817. };
  818. static struct atmel_uart_data uart2_data = {
  819. .use_dma_tx = 1,
  820. .use_dma_rx = 1,
  821. };
  822. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  823. static struct platform_device at91sam9260_uart2_device = {
  824. .name = "atmel_usart",
  825. .id = 3,
  826. .dev = {
  827. .dma_mask = &uart2_dmamask,
  828. .coherent_dma_mask = DMA_BIT_MASK(32),
  829. .platform_data = &uart2_data,
  830. },
  831. .resource = uart2_resources,
  832. .num_resources = ARRAY_SIZE(uart2_resources),
  833. };
  834. static inline void configure_usart2_pins(unsigned pins)
  835. {
  836. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  837. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  838. if (pins & ATMEL_UART_RTS)
  839. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  840. if (pins & ATMEL_UART_CTS)
  841. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  842. }
  843. static struct resource uart3_resources[] = {
  844. [0] = {
  845. .start = AT91SAM9260_BASE_US3,
  846. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  847. .flags = IORESOURCE_MEM,
  848. },
  849. [1] = {
  850. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  851. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  852. .flags = IORESOURCE_IRQ,
  853. },
  854. };
  855. static struct atmel_uart_data uart3_data = {
  856. .use_dma_tx = 1,
  857. .use_dma_rx = 1,
  858. };
  859. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  860. static struct platform_device at91sam9260_uart3_device = {
  861. .name = "atmel_usart",
  862. .id = 4,
  863. .dev = {
  864. .dma_mask = &uart3_dmamask,
  865. .coherent_dma_mask = DMA_BIT_MASK(32),
  866. .platform_data = &uart3_data,
  867. },
  868. .resource = uart3_resources,
  869. .num_resources = ARRAY_SIZE(uart3_resources),
  870. };
  871. static inline void configure_usart3_pins(unsigned pins)
  872. {
  873. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  874. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  875. if (pins & ATMEL_UART_RTS)
  876. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  877. if (pins & ATMEL_UART_CTS)
  878. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  879. }
  880. static struct resource uart4_resources[] = {
  881. [0] = {
  882. .start = AT91SAM9260_BASE_US4,
  883. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  884. .flags = IORESOURCE_MEM,
  885. },
  886. [1] = {
  887. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  888. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  889. .flags = IORESOURCE_IRQ,
  890. },
  891. };
  892. static struct atmel_uart_data uart4_data = {
  893. .use_dma_tx = 1,
  894. .use_dma_rx = 1,
  895. };
  896. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  897. static struct platform_device at91sam9260_uart4_device = {
  898. .name = "atmel_usart",
  899. .id = 5,
  900. .dev = {
  901. .dma_mask = &uart4_dmamask,
  902. .coherent_dma_mask = DMA_BIT_MASK(32),
  903. .platform_data = &uart4_data,
  904. },
  905. .resource = uart4_resources,
  906. .num_resources = ARRAY_SIZE(uart4_resources),
  907. };
  908. static inline void configure_usart4_pins(void)
  909. {
  910. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  911. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  912. }
  913. static struct resource uart5_resources[] = {
  914. [0] = {
  915. .start = AT91SAM9260_BASE_US5,
  916. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  917. .flags = IORESOURCE_MEM,
  918. },
  919. [1] = {
  920. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  921. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  922. .flags = IORESOURCE_IRQ,
  923. },
  924. };
  925. static struct atmel_uart_data uart5_data = {
  926. .use_dma_tx = 1,
  927. .use_dma_rx = 1,
  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 (data->flags & AT91_CF_TRUE_IDE)
  1082. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
  1083. pdev->name = "pata_at91";
  1084. #else
  1085. #warning "board requires AT91_CF_TRUE_IDE: enable pata_at91"
  1086. #endif
  1087. else
  1088. pdev->name = "at91_cf";
  1089. platform_device_register(pdev);
  1090. }
  1091. #else
  1092. void __init at91_add_device_cf(struct at91_cf_data * data) {}
  1093. #endif
  1094. /* --------------------------------------------------------------------
  1095. * ADCs
  1096. * -------------------------------------------------------------------- */
  1097. #if IS_ENABLED(CONFIG_AT91_ADC)
  1098. static struct at91_adc_data adc_data;
  1099. static struct resource adc_resources[] = {
  1100. [0] = {
  1101. .start = AT91SAM9260_BASE_ADC,
  1102. .end = AT91SAM9260_BASE_ADC + SZ_16K - 1,
  1103. .flags = IORESOURCE_MEM,
  1104. },
  1105. [1] = {
  1106. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1107. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1108. .flags = IORESOURCE_IRQ,
  1109. },
  1110. };
  1111. static struct platform_device at91_adc_device = {
  1112. .name = "at91_adc",
  1113. .id = -1,
  1114. .dev = {
  1115. .platform_data = &adc_data,
  1116. },
  1117. .resource = adc_resources,
  1118. .num_resources = ARRAY_SIZE(adc_resources),
  1119. };
  1120. static struct at91_adc_trigger at91_adc_triggers[] = {
  1121. [0] = {
  1122. .name = "timer-counter-0",
  1123. .value = AT91_ADC_TRGSEL_TC0 | AT91_ADC_TRGEN,
  1124. },
  1125. [1] = {
  1126. .name = "timer-counter-1",
  1127. .value = AT91_ADC_TRGSEL_TC1 | AT91_ADC_TRGEN,
  1128. },
  1129. [2] = {
  1130. .name = "timer-counter-2",
  1131. .value = AT91_ADC_TRGSEL_TC2 | AT91_ADC_TRGEN,
  1132. },
  1133. [3] = {
  1134. .name = "external",
  1135. .value = AT91_ADC_TRGSEL_EXTERNAL | AT91_ADC_TRGEN,
  1136. .is_external = true,
  1137. },
  1138. };
  1139. static struct at91_adc_reg_desc at91_adc_register_g20 = {
  1140. .channel_base = AT91_ADC_CHR(0),
  1141. .drdy_mask = AT91_ADC_DRDY,
  1142. .status_register = AT91_ADC_SR,
  1143. .trigger_register = AT91_ADC_MR,
  1144. };
  1145. void __init at91_add_device_adc(struct at91_adc_data *data)
  1146. {
  1147. if (!data)
  1148. return;
  1149. if (test_bit(0, &data->channels_used))
  1150. at91_set_A_periph(AT91_PIN_PC0, 0);
  1151. if (test_bit(1, &data->channels_used))
  1152. at91_set_A_periph(AT91_PIN_PC1, 0);
  1153. if (test_bit(2, &data->channels_used))
  1154. at91_set_A_periph(AT91_PIN_PC2, 0);
  1155. if (test_bit(3, &data->channels_used))
  1156. at91_set_A_periph(AT91_PIN_PC3, 0);
  1157. if (data->use_external_triggers)
  1158. at91_set_A_periph(AT91_PIN_PA22, 0);
  1159. data->num_channels = 4;
  1160. data->startup_time = 10;
  1161. data->registers = &at91_adc_register_g20;
  1162. data->trigger_number = 4;
  1163. data->trigger_list = at91_adc_triggers;
  1164. adc_data = *data;
  1165. platform_device_register(&at91_adc_device);
  1166. }
  1167. #else
  1168. void __init at91_add_device_adc(struct at91_adc_data *data) {}
  1169. #endif
  1170. /* -------------------------------------------------------------------- */
  1171. /*
  1172. * These devices are always present and don't need any board-specific
  1173. * setup.
  1174. */
  1175. static int __init at91_add_standard_devices(void)
  1176. {
  1177. if (of_have_populated_dt())
  1178. return 0;
  1179. at91_add_device_rtt();
  1180. at91_add_device_watchdog();
  1181. at91_add_device_tc();
  1182. return 0;
  1183. }
  1184. arch_initcall(at91_add_standard_devices);