at91sam9260_devices.c 34 KB

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