at91sam9260_devices.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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 "board.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. /*
  654. * SSC controllers are accessed through library code, instead of any
  655. * kind of all-singing/all-dancing driver. For example one could be
  656. * used by a particular I2S audio codec's driver, while another one
  657. * on the same system might be used by a custom data capture driver.
  658. */
  659. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  660. {
  661. struct platform_device *pdev;
  662. /*
  663. * NOTE: caller is responsible for passing information matching
  664. * "pins" to whatever will be using each particular controller.
  665. */
  666. switch (id) {
  667. case AT91SAM9260_ID_SSC:
  668. pdev = &at91sam9260_ssc_device;
  669. configure_ssc_pins(pins);
  670. break;
  671. default:
  672. return;
  673. }
  674. platform_device_register(pdev);
  675. }
  676. #else
  677. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  678. #endif
  679. /* --------------------------------------------------------------------
  680. * UART
  681. * -------------------------------------------------------------------- */
  682. #if defined(CONFIG_SERIAL_ATMEL)
  683. static struct resource dbgu_resources[] = {
  684. [0] = {
  685. .start = AT91SAM9260_BASE_DBGU,
  686. .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
  687. .flags = IORESOURCE_MEM,
  688. },
  689. [1] = {
  690. .start = NR_IRQS_LEGACY + AT91_ID_SYS,
  691. .end = NR_IRQS_LEGACY + AT91_ID_SYS,
  692. .flags = IORESOURCE_IRQ,
  693. },
  694. };
  695. static struct atmel_uart_data dbgu_data = {
  696. .use_dma_tx = 0,
  697. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  698. };
  699. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  700. static struct platform_device at91sam9260_dbgu_device = {
  701. .name = "atmel_usart",
  702. .id = 0,
  703. .dev = {
  704. .dma_mask = &dbgu_dmamask,
  705. .coherent_dma_mask = DMA_BIT_MASK(32),
  706. .platform_data = &dbgu_data,
  707. },
  708. .resource = dbgu_resources,
  709. .num_resources = ARRAY_SIZE(dbgu_resources),
  710. };
  711. static inline void configure_dbgu_pins(void)
  712. {
  713. at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
  714. at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
  715. }
  716. static struct resource uart0_resources[] = {
  717. [0] = {
  718. .start = AT91SAM9260_BASE_US0,
  719. .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
  720. .flags = IORESOURCE_MEM,
  721. },
  722. [1] = {
  723. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  724. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
  725. .flags = IORESOURCE_IRQ,
  726. },
  727. };
  728. static struct atmel_uart_data uart0_data = {
  729. .use_dma_tx = 1,
  730. .use_dma_rx = 1,
  731. };
  732. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  733. static struct platform_device at91sam9260_uart0_device = {
  734. .name = "atmel_usart",
  735. .id = 1,
  736. .dev = {
  737. .dma_mask = &uart0_dmamask,
  738. .coherent_dma_mask = DMA_BIT_MASK(32),
  739. .platform_data = &uart0_data,
  740. },
  741. .resource = uart0_resources,
  742. .num_resources = ARRAY_SIZE(uart0_resources),
  743. };
  744. static inline void configure_usart0_pins(unsigned pins)
  745. {
  746. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
  747. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
  748. if (pins & ATMEL_UART_RTS)
  749. at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
  750. if (pins & ATMEL_UART_CTS)
  751. at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
  752. if (pins & ATMEL_UART_DTR)
  753. at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
  754. if (pins & ATMEL_UART_DSR)
  755. at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
  756. if (pins & ATMEL_UART_DCD)
  757. at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
  758. if (pins & ATMEL_UART_RI)
  759. at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
  760. }
  761. static struct resource uart1_resources[] = {
  762. [0] = {
  763. .start = AT91SAM9260_BASE_US1,
  764. .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
  765. .flags = IORESOURCE_MEM,
  766. },
  767. [1] = {
  768. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  769. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
  770. .flags = IORESOURCE_IRQ,
  771. },
  772. };
  773. static struct atmel_uart_data uart1_data = {
  774. .use_dma_tx = 1,
  775. .use_dma_rx = 1,
  776. };
  777. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  778. static struct platform_device at91sam9260_uart1_device = {
  779. .name = "atmel_usart",
  780. .id = 2,
  781. .dev = {
  782. .dma_mask = &uart1_dmamask,
  783. .coherent_dma_mask = DMA_BIT_MASK(32),
  784. .platform_data = &uart1_data,
  785. },
  786. .resource = uart1_resources,
  787. .num_resources = ARRAY_SIZE(uart1_resources),
  788. };
  789. static inline void configure_usart1_pins(unsigned pins)
  790. {
  791. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
  792. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
  793. if (pins & ATMEL_UART_RTS)
  794. at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
  795. if (pins & ATMEL_UART_CTS)
  796. at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
  797. }
  798. static struct resource uart2_resources[] = {
  799. [0] = {
  800. .start = AT91SAM9260_BASE_US2,
  801. .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
  802. .flags = IORESOURCE_MEM,
  803. },
  804. [1] = {
  805. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  806. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
  807. .flags = IORESOURCE_IRQ,
  808. },
  809. };
  810. static struct atmel_uart_data uart2_data = {
  811. .use_dma_tx = 1,
  812. .use_dma_rx = 1,
  813. };
  814. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  815. static struct platform_device at91sam9260_uart2_device = {
  816. .name = "atmel_usart",
  817. .id = 3,
  818. .dev = {
  819. .dma_mask = &uart2_dmamask,
  820. .coherent_dma_mask = DMA_BIT_MASK(32),
  821. .platform_data = &uart2_data,
  822. },
  823. .resource = uart2_resources,
  824. .num_resources = ARRAY_SIZE(uart2_resources),
  825. };
  826. static inline void configure_usart2_pins(unsigned pins)
  827. {
  828. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
  829. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
  830. if (pins & ATMEL_UART_RTS)
  831. at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
  832. if (pins & ATMEL_UART_CTS)
  833. at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
  834. }
  835. static struct resource uart3_resources[] = {
  836. [0] = {
  837. .start = AT91SAM9260_BASE_US3,
  838. .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
  839. .flags = IORESOURCE_MEM,
  840. },
  841. [1] = {
  842. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  843. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
  844. .flags = IORESOURCE_IRQ,
  845. },
  846. };
  847. static struct atmel_uart_data uart3_data = {
  848. .use_dma_tx = 1,
  849. .use_dma_rx = 1,
  850. };
  851. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  852. static struct platform_device at91sam9260_uart3_device = {
  853. .name = "atmel_usart",
  854. .id = 4,
  855. .dev = {
  856. .dma_mask = &uart3_dmamask,
  857. .coherent_dma_mask = DMA_BIT_MASK(32),
  858. .platform_data = &uart3_data,
  859. },
  860. .resource = uart3_resources,
  861. .num_resources = ARRAY_SIZE(uart3_resources),
  862. };
  863. static inline void configure_usart3_pins(unsigned pins)
  864. {
  865. at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
  866. at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
  867. if (pins & ATMEL_UART_RTS)
  868. at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
  869. if (pins & ATMEL_UART_CTS)
  870. at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
  871. }
  872. static struct resource uart4_resources[] = {
  873. [0] = {
  874. .start = AT91SAM9260_BASE_US4,
  875. .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
  876. .flags = IORESOURCE_MEM,
  877. },
  878. [1] = {
  879. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  880. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
  881. .flags = IORESOURCE_IRQ,
  882. },
  883. };
  884. static struct atmel_uart_data uart4_data = {
  885. .use_dma_tx = 1,
  886. .use_dma_rx = 1,
  887. };
  888. static u64 uart4_dmamask = DMA_BIT_MASK(32);
  889. static struct platform_device at91sam9260_uart4_device = {
  890. .name = "atmel_usart",
  891. .id = 5,
  892. .dev = {
  893. .dma_mask = &uart4_dmamask,
  894. .coherent_dma_mask = DMA_BIT_MASK(32),
  895. .platform_data = &uart4_data,
  896. },
  897. .resource = uart4_resources,
  898. .num_resources = ARRAY_SIZE(uart4_resources),
  899. };
  900. static inline void configure_usart4_pins(void)
  901. {
  902. at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
  903. at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
  904. }
  905. static struct resource uart5_resources[] = {
  906. [0] = {
  907. .start = AT91SAM9260_BASE_US5,
  908. .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
  909. .flags = IORESOURCE_MEM,
  910. },
  911. [1] = {
  912. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  913. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
  914. .flags = IORESOURCE_IRQ,
  915. },
  916. };
  917. static struct atmel_uart_data uart5_data = {
  918. .use_dma_tx = 1,
  919. .use_dma_rx = 1,
  920. };
  921. static u64 uart5_dmamask = DMA_BIT_MASK(32);
  922. static struct platform_device at91sam9260_uart5_device = {
  923. .name = "atmel_usart",
  924. .id = 6,
  925. .dev = {
  926. .dma_mask = &uart5_dmamask,
  927. .coherent_dma_mask = DMA_BIT_MASK(32),
  928. .platform_data = &uart5_data,
  929. },
  930. .resource = uart5_resources,
  931. .num_resources = ARRAY_SIZE(uart5_resources),
  932. };
  933. static inline void configure_usart5_pins(void)
  934. {
  935. at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
  936. at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
  937. }
  938. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  939. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  940. {
  941. struct platform_device *pdev;
  942. struct atmel_uart_data *pdata;
  943. switch (id) {
  944. case 0: /* DBGU */
  945. pdev = &at91sam9260_dbgu_device;
  946. configure_dbgu_pins();
  947. break;
  948. case AT91SAM9260_ID_US0:
  949. pdev = &at91sam9260_uart0_device;
  950. configure_usart0_pins(pins);
  951. break;
  952. case AT91SAM9260_ID_US1:
  953. pdev = &at91sam9260_uart1_device;
  954. configure_usart1_pins(pins);
  955. break;
  956. case AT91SAM9260_ID_US2:
  957. pdev = &at91sam9260_uart2_device;
  958. configure_usart2_pins(pins);
  959. break;
  960. case AT91SAM9260_ID_US3:
  961. pdev = &at91sam9260_uart3_device;
  962. configure_usart3_pins(pins);
  963. break;
  964. case AT91SAM9260_ID_US4:
  965. pdev = &at91sam9260_uart4_device;
  966. configure_usart4_pins();
  967. break;
  968. case AT91SAM9260_ID_US5:
  969. pdev = &at91sam9260_uart5_device;
  970. configure_usart5_pins();
  971. break;
  972. default:
  973. return;
  974. }
  975. pdata = pdev->dev.platform_data;
  976. pdata->num = portnr; /* update to mapped ID */
  977. if (portnr < ATMEL_MAX_UART)
  978. at91_uarts[portnr] = pdev;
  979. }
  980. void __init at91_add_device_serial(void)
  981. {
  982. int i;
  983. for (i = 0; i < ATMEL_MAX_UART; i++) {
  984. if (at91_uarts[i])
  985. platform_device_register(at91_uarts[i]);
  986. }
  987. }
  988. #else
  989. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  990. void __init at91_add_device_serial(void) {}
  991. #endif
  992. /* --------------------------------------------------------------------
  993. * CF/IDE
  994. * -------------------------------------------------------------------- */
  995. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
  996. defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  997. static struct at91_cf_data cf0_data;
  998. static struct resource cf0_resources[] = {
  999. [0] = {
  1000. .start = AT91_CHIPSELECT_4,
  1001. .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
  1002. .flags = IORESOURCE_MEM,
  1003. }
  1004. };
  1005. static struct platform_device cf0_device = {
  1006. .id = 0,
  1007. .dev = {
  1008. .platform_data = &cf0_data,
  1009. },
  1010. .resource = cf0_resources,
  1011. .num_resources = ARRAY_SIZE(cf0_resources),
  1012. };
  1013. static struct at91_cf_data cf1_data;
  1014. static struct resource cf1_resources[] = {
  1015. [0] = {
  1016. .start = AT91_CHIPSELECT_5,
  1017. .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
  1018. .flags = IORESOURCE_MEM,
  1019. }
  1020. };
  1021. static struct platform_device cf1_device = {
  1022. .id = 1,
  1023. .dev = {
  1024. .platform_data = &cf1_data,
  1025. },
  1026. .resource = cf1_resources,
  1027. .num_resources = ARRAY_SIZE(cf1_resources),
  1028. };
  1029. void __init at91_add_device_cf(struct at91_cf_data *data)
  1030. {
  1031. struct platform_device *pdev;
  1032. unsigned long csa;
  1033. if (!data)
  1034. return;
  1035. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  1036. switch (data->chipselect) {
  1037. case 4:
  1038. at91_set_multi_drive(AT91_PIN_PC8, 0);
  1039. at91_set_A_periph(AT91_PIN_PC8, 0);
  1040. csa |= AT91_MATRIX_CS4A_SMC_CF1;
  1041. cf0_data = *data;
  1042. pdev = &cf0_device;
  1043. break;
  1044. case 5:
  1045. at91_set_multi_drive(AT91_PIN_PC9, 0);
  1046. at91_set_A_periph(AT91_PIN_PC9, 0);
  1047. csa |= AT91_MATRIX_CS5A_SMC_CF2;
  1048. cf1_data = *data;
  1049. pdev = &cf1_device;
  1050. break;
  1051. default:
  1052. printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
  1053. data->chipselect);
  1054. return;
  1055. }
  1056. at91_matrix_write(AT91_MATRIX_EBICSA, csa);
  1057. if (gpio_is_valid(data->rst_pin)) {
  1058. at91_set_multi_drive(data->rst_pin, 0);
  1059. at91_set_gpio_output(data->rst_pin, 1);
  1060. }
  1061. if (gpio_is_valid(data->irq_pin)) {
  1062. at91_set_gpio_input(data->irq_pin, 0);
  1063. at91_set_deglitch(data->irq_pin, 1);
  1064. }
  1065. if (gpio_is_valid(data->det_pin)) {
  1066. at91_set_gpio_input(data->det_pin, 0);
  1067. at91_set_deglitch(data->det_pin, 1);
  1068. }
  1069. at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
  1070. at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
  1071. at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
  1072. at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
  1073. if (data->flags & AT91_CF_TRUE_IDE)
  1074. #if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE)
  1075. pdev->name = "pata_at91";
  1076. #else
  1077. #warning "board requires AT91_CF_TRUE_IDE: enable pata_at91"
  1078. #endif
  1079. else
  1080. pdev->name = "at91_cf";
  1081. platform_device_register(pdev);
  1082. }
  1083. #else
  1084. void __init at91_add_device_cf(struct at91_cf_data * data) {}
  1085. #endif
  1086. /* --------------------------------------------------------------------
  1087. * ADCs
  1088. * -------------------------------------------------------------------- */
  1089. #if IS_ENABLED(CONFIG_AT91_ADC)
  1090. static struct at91_adc_data adc_data;
  1091. static struct resource adc_resources[] = {
  1092. [0] = {
  1093. .start = AT91SAM9260_BASE_ADC,
  1094. .end = AT91SAM9260_BASE_ADC + SZ_16K - 1,
  1095. .flags = IORESOURCE_MEM,
  1096. },
  1097. [1] = {
  1098. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1099. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
  1100. .flags = IORESOURCE_IRQ,
  1101. },
  1102. };
  1103. static struct platform_device at91_adc_device = {
  1104. .name = "at91_adc",
  1105. .id = -1,
  1106. .dev = {
  1107. .platform_data = &adc_data,
  1108. },
  1109. .resource = adc_resources,
  1110. .num_resources = ARRAY_SIZE(adc_resources),
  1111. };
  1112. static struct at91_adc_trigger at91_adc_triggers[] = {
  1113. [0] = {
  1114. .name = "timer-counter-0",
  1115. .value = AT91_ADC_TRGSEL_TC0 | AT91_ADC_TRGEN,
  1116. },
  1117. [1] = {
  1118. .name = "timer-counter-1",
  1119. .value = AT91_ADC_TRGSEL_TC1 | AT91_ADC_TRGEN,
  1120. },
  1121. [2] = {
  1122. .name = "timer-counter-2",
  1123. .value = AT91_ADC_TRGSEL_TC2 | AT91_ADC_TRGEN,
  1124. },
  1125. [3] = {
  1126. .name = "external",
  1127. .value = AT91_ADC_TRGSEL_EXTERNAL | AT91_ADC_TRGEN,
  1128. .is_external = true,
  1129. },
  1130. };
  1131. static struct at91_adc_reg_desc at91_adc_register_g20 = {
  1132. .channel_base = AT91_ADC_CHR(0),
  1133. .drdy_mask = AT91_ADC_DRDY,
  1134. .status_register = AT91_ADC_SR,
  1135. .trigger_register = AT91_ADC_MR,
  1136. };
  1137. void __init at91_add_device_adc(struct at91_adc_data *data)
  1138. {
  1139. if (!data)
  1140. return;
  1141. if (test_bit(0, &data->channels_used))
  1142. at91_set_A_periph(AT91_PIN_PC0, 0);
  1143. if (test_bit(1, &data->channels_used))
  1144. at91_set_A_periph(AT91_PIN_PC1, 0);
  1145. if (test_bit(2, &data->channels_used))
  1146. at91_set_A_periph(AT91_PIN_PC2, 0);
  1147. if (test_bit(3, &data->channels_used))
  1148. at91_set_A_periph(AT91_PIN_PC3, 0);
  1149. if (data->use_external_triggers)
  1150. at91_set_A_periph(AT91_PIN_PA22, 0);
  1151. data->num_channels = 4;
  1152. data->startup_time = 10;
  1153. data->registers = &at91_adc_register_g20;
  1154. data->trigger_number = 4;
  1155. data->trigger_list = at91_adc_triggers;
  1156. adc_data = *data;
  1157. platform_device_register(&at91_adc_device);
  1158. }
  1159. #else
  1160. void __init at91_add_device_adc(struct at91_adc_data *data) {}
  1161. #endif
  1162. /* -------------------------------------------------------------------- */
  1163. /*
  1164. * These devices are always present and don't need any board-specific
  1165. * setup.
  1166. */
  1167. static int __init at91_add_standard_devices(void)
  1168. {
  1169. if (of_have_populated_dt())
  1170. return 0;
  1171. at91_add_device_rtt();
  1172. at91_add_device_watchdog();
  1173. at91_add_device_tc();
  1174. return 0;
  1175. }
  1176. arch_initcall(at91_add_standard_devices);