at91sam9260_devices.c 33 KB

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