at91sam9260_devices.c 34 KB

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