at91sam9260_devices.c 36 KB

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