at91sam9260_devices.c 32 KB

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