at91sam9263_devices.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. /*
  2. * arch/arm/mach-at91/at91sam9263_devices.c
  3. *
  4. * Copyright (C) 2007 Atmel Corporation.
  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 <linux/fb.h>
  18. #include <video/atmel_lcdc.h>
  19. #include <mach/board.h>
  20. #include <mach/gpio.h>
  21. #include <mach/at91sam9263.h>
  22. #include <mach/at91sam9263_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 = AT91SAM9263_UHP_BASE,
  34. .end = AT91SAM9263_UHP_BASE + SZ_1M - 1,
  35. .flags = IORESOURCE_MEM,
  36. },
  37. [1] = {
  38. .start = AT91SAM9263_ID_UHP,
  39. .end = AT91SAM9263_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 VBus control for UHP ports */
  60. for (i = 0; i < data->ports; i++) {
  61. if (data->vbus_pin[i])
  62. at91_set_gpio_output(data->vbus_pin[i], 0);
  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. #ifdef CONFIG_USB_GADGET_AT91
  74. static struct at91_udc_data udc_data;
  75. static struct resource udc_resources[] = {
  76. [0] = {
  77. .start = AT91SAM9263_BASE_UDP,
  78. .end = AT91SAM9263_BASE_UDP + SZ_16K - 1,
  79. .flags = IORESOURCE_MEM,
  80. },
  81. [1] = {
  82. .start = AT91SAM9263_ID_UDP,
  83. .end = AT91SAM9263_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 (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 at91_eth_data eth_data;
  117. static struct resource eth_resources[] = {
  118. [0] = {
  119. .start = AT91SAM9263_BASE_EMAC,
  120. .end = AT91SAM9263_BASE_EMAC + SZ_16K - 1,
  121. .flags = IORESOURCE_MEM,
  122. },
  123. [1] = {
  124. .start = AT91SAM9263_ID_EMAC,
  125. .end = AT91SAM9263_ID_EMAC,
  126. .flags = IORESOURCE_IRQ,
  127. },
  128. };
  129. static struct platform_device at91sam9263_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 at91_eth_data *data)
  141. {
  142. if (!data)
  143. return;
  144. if (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_PE21, 0); /* ETXCK_EREFCK */
  150. at91_set_B_periph(AT91_PIN_PC25, 0); /* ERXDV */
  151. at91_set_A_periph(AT91_PIN_PE25, 0); /* ERX0 */
  152. at91_set_A_periph(AT91_PIN_PE26, 0); /* ERX1 */
  153. at91_set_A_periph(AT91_PIN_PE27, 0); /* ERXER */
  154. at91_set_A_periph(AT91_PIN_PE28, 0); /* ETXEN */
  155. at91_set_A_periph(AT91_PIN_PE23, 0); /* ETX0 */
  156. at91_set_A_periph(AT91_PIN_PE24, 0); /* ETX1 */
  157. at91_set_A_periph(AT91_PIN_PE30, 0); /* EMDIO */
  158. at91_set_A_periph(AT91_PIN_PE29, 0); /* EMDC */
  159. if (!data->is_rmii) {
  160. at91_set_A_periph(AT91_PIN_PE22, 0); /* ECRS */
  161. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  162. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  163. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  164. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  165. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  166. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  167. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  168. }
  169. eth_data = *data;
  170. platform_device_register(&at91sam9263_eth_device);
  171. }
  172. #else
  173. void __init at91_add_device_eth(struct at91_eth_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 mmc0_data, mmc1_data;
  181. static struct resource mmc0_resources[] = {
  182. [0] = {
  183. .start = AT91SAM9263_BASE_MCI0,
  184. .end = AT91SAM9263_BASE_MCI0 + SZ_16K - 1,
  185. .flags = IORESOURCE_MEM,
  186. },
  187. [1] = {
  188. .start = AT91SAM9263_ID_MCI0,
  189. .end = AT91SAM9263_ID_MCI0,
  190. .flags = IORESOURCE_IRQ,
  191. },
  192. };
  193. static struct platform_device at91sam9263_mmc0_device = {
  194. .name = "at91_mci",
  195. .id = 0,
  196. .dev = {
  197. .dma_mask = &mmc_dmamask,
  198. .coherent_dma_mask = DMA_BIT_MASK(32),
  199. .platform_data = &mmc0_data,
  200. },
  201. .resource = mmc0_resources,
  202. .num_resources = ARRAY_SIZE(mmc0_resources),
  203. };
  204. static struct resource mmc1_resources[] = {
  205. [0] = {
  206. .start = AT91SAM9263_BASE_MCI1,
  207. .end = AT91SAM9263_BASE_MCI1 + SZ_16K - 1,
  208. .flags = IORESOURCE_MEM,
  209. },
  210. [1] = {
  211. .start = AT91SAM9263_ID_MCI1,
  212. .end = AT91SAM9263_ID_MCI1,
  213. .flags = IORESOURCE_IRQ,
  214. },
  215. };
  216. static struct platform_device at91sam9263_mmc1_device = {
  217. .name = "at91_mci",
  218. .id = 1,
  219. .dev = {
  220. .dma_mask = &mmc_dmamask,
  221. .coherent_dma_mask = DMA_BIT_MASK(32),
  222. .platform_data = &mmc1_data,
  223. },
  224. .resource = mmc1_resources,
  225. .num_resources = ARRAY_SIZE(mmc1_resources),
  226. };
  227. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  228. {
  229. if (!data)
  230. return;
  231. /* input/irq */
  232. if (data->det_pin) {
  233. at91_set_gpio_input(data->det_pin, 1);
  234. at91_set_deglitch(data->det_pin, 1);
  235. }
  236. if (data->wp_pin)
  237. at91_set_gpio_input(data->wp_pin, 1);
  238. if (data->vcc_pin)
  239. at91_set_gpio_output(data->vcc_pin, 0);
  240. if (mmc_id == 0) { /* MCI0 */
  241. /* CLK */
  242. at91_set_A_periph(AT91_PIN_PA12, 0);
  243. if (data->slot_b) {
  244. /* CMD */
  245. at91_set_A_periph(AT91_PIN_PA16, 1);
  246. /* DAT0, maybe DAT1..DAT3 */
  247. at91_set_A_periph(AT91_PIN_PA17, 1);
  248. if (data->wire4) {
  249. at91_set_A_periph(AT91_PIN_PA18, 1);
  250. at91_set_A_periph(AT91_PIN_PA19, 1);
  251. at91_set_A_periph(AT91_PIN_PA20, 1);
  252. }
  253. } else {
  254. /* CMD */
  255. at91_set_A_periph(AT91_PIN_PA1, 1);
  256. /* DAT0, maybe DAT1..DAT3 */
  257. at91_set_A_periph(AT91_PIN_PA0, 1);
  258. if (data->wire4) {
  259. at91_set_A_periph(AT91_PIN_PA3, 1);
  260. at91_set_A_periph(AT91_PIN_PA4, 1);
  261. at91_set_A_periph(AT91_PIN_PA5, 1);
  262. }
  263. }
  264. mmc0_data = *data;
  265. at91_clock_associate("mci0_clk", &at91sam9263_mmc0_device.dev, "mci_clk");
  266. platform_device_register(&at91sam9263_mmc0_device);
  267. } else { /* MCI1 */
  268. /* CLK */
  269. at91_set_A_periph(AT91_PIN_PA6, 0);
  270. if (data->slot_b) {
  271. /* CMD */
  272. at91_set_A_periph(AT91_PIN_PA21, 1);
  273. /* DAT0, maybe DAT1..DAT3 */
  274. at91_set_A_periph(AT91_PIN_PA22, 1);
  275. if (data->wire4) {
  276. at91_set_A_periph(AT91_PIN_PA23, 1);
  277. at91_set_A_periph(AT91_PIN_PA24, 1);
  278. at91_set_A_periph(AT91_PIN_PA25, 1);
  279. }
  280. } else {
  281. /* CMD */
  282. at91_set_A_periph(AT91_PIN_PA7, 1);
  283. /* DAT0, maybe DAT1..DAT3 */
  284. at91_set_A_periph(AT91_PIN_PA8, 1);
  285. if (data->wire4) {
  286. at91_set_A_periph(AT91_PIN_PA9, 1);
  287. at91_set_A_periph(AT91_PIN_PA10, 1);
  288. at91_set_A_periph(AT91_PIN_PA11, 1);
  289. }
  290. }
  291. mmc1_data = *data;
  292. at91_clock_associate("mci1_clk", &at91sam9263_mmc1_device.dev, "mci_clk");
  293. platform_device_register(&at91sam9263_mmc1_device);
  294. }
  295. }
  296. #else
  297. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  298. #endif
  299. /* --------------------------------------------------------------------
  300. * NAND / SmartMedia
  301. * -------------------------------------------------------------------- */
  302. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  303. static struct atmel_nand_data nand_data;
  304. #define NAND_BASE AT91_CHIPSELECT_3
  305. static struct resource nand_resources[] = {
  306. [0] = {
  307. .start = NAND_BASE,
  308. .end = NAND_BASE + SZ_256M - 1,
  309. .flags = IORESOURCE_MEM,
  310. },
  311. [1] = {
  312. .start = AT91_BASE_SYS + AT91_ECC0,
  313. .end = AT91_BASE_SYS + AT91_ECC0 + SZ_512 - 1,
  314. .flags = IORESOURCE_MEM,
  315. }
  316. };
  317. static struct platform_device at91sam9263_nand_device = {
  318. .name = "atmel_nand",
  319. .id = -1,
  320. .dev = {
  321. .platform_data = &nand_data,
  322. },
  323. .resource = nand_resources,
  324. .num_resources = ARRAY_SIZE(nand_resources),
  325. };
  326. void __init at91_add_device_nand(struct atmel_nand_data *data)
  327. {
  328. unsigned long csa;
  329. if (!data)
  330. return;
  331. csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
  332. at91_sys_write(AT91_MATRIX_EBI0CSA, csa | AT91_MATRIX_EBI0_CS3A_SMC_SMARTMEDIA);
  333. /* enable pin */
  334. if (data->enable_pin)
  335. at91_set_gpio_output(data->enable_pin, 1);
  336. /* ready/busy pin */
  337. if (data->rdy_pin)
  338. at91_set_gpio_input(data->rdy_pin, 1);
  339. /* card detect pin */
  340. if (data->det_pin)
  341. at91_set_gpio_input(data->det_pin, 1);
  342. nand_data = *data;
  343. platform_device_register(&at91sam9263_nand_device);
  344. }
  345. #else
  346. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  347. #endif
  348. /* --------------------------------------------------------------------
  349. * TWI (i2c)
  350. * -------------------------------------------------------------------- */
  351. /*
  352. * Prefer the GPIO code since the TWI controller isn't robust
  353. * (gets overruns and underruns under load) and can only issue
  354. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  355. */
  356. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  357. static struct i2c_gpio_platform_data pdata = {
  358. .sda_pin = AT91_PIN_PB4,
  359. .sda_is_open_drain = 1,
  360. .scl_pin = AT91_PIN_PB5,
  361. .scl_is_open_drain = 1,
  362. .udelay = 2, /* ~100 kHz */
  363. };
  364. static struct platform_device at91sam9263_twi_device = {
  365. .name = "i2c-gpio",
  366. .id = -1,
  367. .dev.platform_data = &pdata,
  368. };
  369. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  370. {
  371. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  372. at91_set_multi_drive(AT91_PIN_PB4, 1);
  373. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  374. at91_set_multi_drive(AT91_PIN_PB5, 1);
  375. i2c_register_board_info(0, devices, nr_devices);
  376. platform_device_register(&at91sam9263_twi_device);
  377. }
  378. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  379. static struct resource twi_resources[] = {
  380. [0] = {
  381. .start = AT91SAM9263_BASE_TWI,
  382. .end = AT91SAM9263_BASE_TWI + SZ_16K - 1,
  383. .flags = IORESOURCE_MEM,
  384. },
  385. [1] = {
  386. .start = AT91SAM9263_ID_TWI,
  387. .end = AT91SAM9263_ID_TWI,
  388. .flags = IORESOURCE_IRQ,
  389. },
  390. };
  391. static struct platform_device at91sam9263_twi_device = {
  392. .name = "at91_i2c",
  393. .id = -1,
  394. .resource = twi_resources,
  395. .num_resources = ARRAY_SIZE(twi_resources),
  396. };
  397. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  398. {
  399. /* pins used for TWI interface */
  400. at91_set_A_periph(AT91_PIN_PB4, 0); /* TWD */
  401. at91_set_multi_drive(AT91_PIN_PB4, 1);
  402. at91_set_A_periph(AT91_PIN_PB5, 0); /* TWCK */
  403. at91_set_multi_drive(AT91_PIN_PB5, 1);
  404. i2c_register_board_info(0, devices, nr_devices);
  405. platform_device_register(&at91sam9263_twi_device);
  406. }
  407. #else
  408. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  409. #endif
  410. /* --------------------------------------------------------------------
  411. * SPI
  412. * -------------------------------------------------------------------- */
  413. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  414. static u64 spi_dmamask = DMA_BIT_MASK(32);
  415. static struct resource spi0_resources[] = {
  416. [0] = {
  417. .start = AT91SAM9263_BASE_SPI0,
  418. .end = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
  419. .flags = IORESOURCE_MEM,
  420. },
  421. [1] = {
  422. .start = AT91SAM9263_ID_SPI0,
  423. .end = AT91SAM9263_ID_SPI0,
  424. .flags = IORESOURCE_IRQ,
  425. },
  426. };
  427. static struct platform_device at91sam9263_spi0_device = {
  428. .name = "atmel_spi",
  429. .id = 0,
  430. .dev = {
  431. .dma_mask = &spi_dmamask,
  432. .coherent_dma_mask = DMA_BIT_MASK(32),
  433. },
  434. .resource = spi0_resources,
  435. .num_resources = ARRAY_SIZE(spi0_resources),
  436. };
  437. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
  438. static struct resource spi1_resources[] = {
  439. [0] = {
  440. .start = AT91SAM9263_BASE_SPI1,
  441. .end = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
  442. .flags = IORESOURCE_MEM,
  443. },
  444. [1] = {
  445. .start = AT91SAM9263_ID_SPI1,
  446. .end = AT91SAM9263_ID_SPI1,
  447. .flags = IORESOURCE_IRQ,
  448. },
  449. };
  450. static struct platform_device at91sam9263_spi1_device = {
  451. .name = "atmel_spi",
  452. .id = 1,
  453. .dev = {
  454. .dma_mask = &spi_dmamask,
  455. .coherent_dma_mask = DMA_BIT_MASK(32),
  456. },
  457. .resource = spi1_resources,
  458. .num_resources = ARRAY_SIZE(spi1_resources),
  459. };
  460. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  461. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  462. {
  463. int i;
  464. unsigned long cs_pin;
  465. short enable_spi0 = 0;
  466. short enable_spi1 = 0;
  467. /* Choose SPI chip-selects */
  468. for (i = 0; i < nr_devices; i++) {
  469. if (devices[i].controller_data)
  470. cs_pin = (unsigned long) devices[i].controller_data;
  471. else if (devices[i].bus_num == 0)
  472. cs_pin = spi0_standard_cs[devices[i].chip_select];
  473. else
  474. cs_pin = spi1_standard_cs[devices[i].chip_select];
  475. if (devices[i].bus_num == 0)
  476. enable_spi0 = 1;
  477. else
  478. enable_spi1 = 1;
  479. /* enable chip-select pin */
  480. at91_set_gpio_output(cs_pin, 1);
  481. /* pass chip-select pin to driver */
  482. devices[i].controller_data = (void *) cs_pin;
  483. }
  484. spi_register_board_info(devices, nr_devices);
  485. /* Configure SPI bus(es) */
  486. if (enable_spi0) {
  487. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  488. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  489. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  490. at91_clock_associate("spi0_clk", &at91sam9263_spi0_device.dev, "spi_clk");
  491. platform_device_register(&at91sam9263_spi0_device);
  492. }
  493. if (enable_spi1) {
  494. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  495. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  496. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  497. at91_clock_associate("spi1_clk", &at91sam9263_spi1_device.dev, "spi_clk");
  498. platform_device_register(&at91sam9263_spi1_device);
  499. }
  500. }
  501. #else
  502. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  503. #endif
  504. /* --------------------------------------------------------------------
  505. * AC97
  506. * -------------------------------------------------------------------- */
  507. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  508. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  509. static struct atmel_ac97_data ac97_data;
  510. static struct resource ac97_resources[] = {
  511. [0] = {
  512. .start = AT91SAM9263_BASE_AC97C,
  513. .end = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
  514. .flags = IORESOURCE_MEM,
  515. },
  516. [1] = {
  517. .start = AT91SAM9263_ID_AC97C,
  518. .end = AT91SAM9263_ID_AC97C,
  519. .flags = IORESOURCE_IRQ,
  520. },
  521. };
  522. static struct platform_device at91sam9263_ac97_device = {
  523. .name = "ac97c",
  524. .id = 1,
  525. .dev = {
  526. .dma_mask = &ac97_dmamask,
  527. .coherent_dma_mask = DMA_BIT_MASK(32),
  528. .platform_data = &ac97_data,
  529. },
  530. .resource = ac97_resources,
  531. .num_resources = ARRAY_SIZE(ac97_resources),
  532. };
  533. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  534. {
  535. if (!data)
  536. return;
  537. at91_set_A_periph(AT91_PIN_PB0, 0); /* AC97FS */
  538. at91_set_A_periph(AT91_PIN_PB1, 0); /* AC97CK */
  539. at91_set_A_periph(AT91_PIN_PB2, 0); /* AC97TX */
  540. at91_set_A_periph(AT91_PIN_PB3, 0); /* AC97RX */
  541. /* reset */
  542. if (data->reset_pin)
  543. at91_set_gpio_output(data->reset_pin, 0);
  544. ac97_data = *ek_data;
  545. platform_device_register(&at91sam9263_ac97_device);
  546. }
  547. #else
  548. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  549. #endif
  550. /* --------------------------------------------------------------------
  551. * LCD Controller
  552. * -------------------------------------------------------------------- */
  553. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  554. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  555. static struct atmel_lcdfb_info lcdc_data;
  556. static struct resource lcdc_resources[] = {
  557. [0] = {
  558. .start = AT91SAM9263_LCDC_BASE,
  559. .end = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
  560. .flags = IORESOURCE_MEM,
  561. },
  562. [1] = {
  563. .start = AT91SAM9263_ID_LCDC,
  564. .end = AT91SAM9263_ID_LCDC,
  565. .flags = IORESOURCE_IRQ,
  566. },
  567. };
  568. static struct platform_device at91_lcdc_device = {
  569. .name = "atmel_lcdfb",
  570. .id = 0,
  571. .dev = {
  572. .dma_mask = &lcdc_dmamask,
  573. .coherent_dma_mask = DMA_BIT_MASK(32),
  574. .platform_data = &lcdc_data,
  575. },
  576. .resource = lcdc_resources,
  577. .num_resources = ARRAY_SIZE(lcdc_resources),
  578. };
  579. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  580. {
  581. if (!data)
  582. return;
  583. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  584. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  585. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  586. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  587. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  588. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  589. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  590. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  591. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  592. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  593. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  594. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  595. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  596. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
  597. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  598. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  599. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  600. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  601. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  602. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
  603. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  604. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  605. lcdc_data = *data;
  606. platform_device_register(&at91_lcdc_device);
  607. }
  608. #else
  609. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  610. #endif
  611. /* --------------------------------------------------------------------
  612. * Image Sensor Interface
  613. * -------------------------------------------------------------------- */
  614. #if defined(CONFIG_VIDEO_AT91_ISI) || defined(CONFIG_VIDEO_AT91_ISI_MODULE)
  615. struct resource isi_resources[] = {
  616. [0] = {
  617. .start = AT91SAM9263_BASE_ISI,
  618. .end = AT91SAM9263_BASE_ISI + SZ_16K - 1,
  619. .flags = IORESOURCE_MEM,
  620. },
  621. [1] = {
  622. .start = AT91SAM9263_ID_ISI,
  623. .end = AT91SAM9263_ID_ISI,
  624. .flags = IORESOURCE_IRQ,
  625. },
  626. };
  627. static struct platform_device at91sam9263_isi_device = {
  628. .name = "at91_isi",
  629. .id = -1,
  630. .resource = isi_resources,
  631. .num_resources = ARRAY_SIZE(isi_resources),
  632. };
  633. void __init at91_add_device_isi(void)
  634. {
  635. at91_set_A_periph(AT91_PIN_PE0, 0); /* ISI_D0 */
  636. at91_set_A_periph(AT91_PIN_PE1, 0); /* ISI_D1 */
  637. at91_set_A_periph(AT91_PIN_PE2, 0); /* ISI_D2 */
  638. at91_set_A_periph(AT91_PIN_PE3, 0); /* ISI_D3 */
  639. at91_set_A_periph(AT91_PIN_PE4, 0); /* ISI_D4 */
  640. at91_set_A_periph(AT91_PIN_PE5, 0); /* ISI_D5 */
  641. at91_set_A_periph(AT91_PIN_PE6, 0); /* ISI_D6 */
  642. at91_set_A_periph(AT91_PIN_PE7, 0); /* ISI_D7 */
  643. at91_set_A_periph(AT91_PIN_PE8, 0); /* ISI_PCK */
  644. at91_set_A_periph(AT91_PIN_PE9, 0); /* ISI_HSYNC */
  645. at91_set_A_periph(AT91_PIN_PE10, 0); /* ISI_VSYNC */
  646. at91_set_B_periph(AT91_PIN_PE11, 0); /* ISI_MCK (PCK3) */
  647. at91_set_B_periph(AT91_PIN_PE12, 0); /* ISI_PD8 */
  648. at91_set_B_periph(AT91_PIN_PE13, 0); /* ISI_PD9 */
  649. at91_set_B_periph(AT91_PIN_PE14, 0); /* ISI_PD10 */
  650. at91_set_B_periph(AT91_PIN_PE15, 0); /* ISI_PD11 */
  651. }
  652. #else
  653. void __init at91_add_device_isi(void) {}
  654. #endif
  655. /* --------------------------------------------------------------------
  656. * Timer/Counter block
  657. * -------------------------------------------------------------------- */
  658. #ifdef CONFIG_ATMEL_TCLIB
  659. static struct resource tcb_resources[] = {
  660. [0] = {
  661. .start = AT91SAM9263_BASE_TCB0,
  662. .end = AT91SAM9263_BASE_TCB0 + SZ_16K - 1,
  663. .flags = IORESOURCE_MEM,
  664. },
  665. [1] = {
  666. .start = AT91SAM9263_ID_TCB,
  667. .end = AT91SAM9263_ID_TCB,
  668. .flags = IORESOURCE_IRQ,
  669. },
  670. };
  671. static struct platform_device at91sam9263_tcb_device = {
  672. .name = "atmel_tcb",
  673. .id = 0,
  674. .resource = tcb_resources,
  675. .num_resources = ARRAY_SIZE(tcb_resources),
  676. };
  677. static void __init at91_add_device_tc(void)
  678. {
  679. /* this chip has one clock and irq for all three TC channels */
  680. at91_clock_associate("tcb_clk", &at91sam9263_tcb_device.dev, "t0_clk");
  681. platform_device_register(&at91sam9263_tcb_device);
  682. }
  683. #else
  684. static void __init at91_add_device_tc(void) { }
  685. #endif
  686. /* --------------------------------------------------------------------
  687. * RTT
  688. * -------------------------------------------------------------------- */
  689. static struct resource rtt0_resources[] = {
  690. {
  691. .start = AT91_BASE_SYS + AT91_RTT0,
  692. .end = AT91_BASE_SYS + AT91_RTT0 + SZ_16 - 1,
  693. .flags = IORESOURCE_MEM,
  694. }
  695. };
  696. static struct platform_device at91sam9263_rtt0_device = {
  697. .name = "at91_rtt",
  698. .id = 0,
  699. .resource = rtt0_resources,
  700. .num_resources = ARRAY_SIZE(rtt0_resources),
  701. };
  702. static struct resource rtt1_resources[] = {
  703. {
  704. .start = AT91_BASE_SYS + AT91_RTT1,
  705. .end = AT91_BASE_SYS + AT91_RTT1 + SZ_16 - 1,
  706. .flags = IORESOURCE_MEM,
  707. }
  708. };
  709. static struct platform_device at91sam9263_rtt1_device = {
  710. .name = "at91_rtt",
  711. .id = 1,
  712. .resource = rtt1_resources,
  713. .num_resources = ARRAY_SIZE(rtt1_resources),
  714. };
  715. static void __init at91_add_device_rtt(void)
  716. {
  717. platform_device_register(&at91sam9263_rtt0_device);
  718. platform_device_register(&at91sam9263_rtt1_device);
  719. }
  720. /* --------------------------------------------------------------------
  721. * Watchdog
  722. * -------------------------------------------------------------------- */
  723. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  724. static struct platform_device at91sam9263_wdt_device = {
  725. .name = "at91_wdt",
  726. .id = -1,
  727. .num_resources = 0,
  728. };
  729. static void __init at91_add_device_watchdog(void)
  730. {
  731. platform_device_register(&at91sam9263_wdt_device);
  732. }
  733. #else
  734. static void __init at91_add_device_watchdog(void) {}
  735. #endif
  736. /* --------------------------------------------------------------------
  737. * PWM
  738. * --------------------------------------------------------------------*/
  739. #if defined(CONFIG_ATMEL_PWM)
  740. static u32 pwm_mask;
  741. static struct resource pwm_resources[] = {
  742. [0] = {
  743. .start = AT91SAM9263_BASE_PWMC,
  744. .end = AT91SAM9263_BASE_PWMC + SZ_16K - 1,
  745. .flags = IORESOURCE_MEM,
  746. },
  747. [1] = {
  748. .start = AT91SAM9263_ID_PWMC,
  749. .end = AT91SAM9263_ID_PWMC,
  750. .flags = IORESOURCE_IRQ,
  751. },
  752. };
  753. static struct platform_device at91sam9263_pwm0_device = {
  754. .name = "atmel_pwm",
  755. .id = -1,
  756. .dev = {
  757. .platform_data = &pwm_mask,
  758. },
  759. .resource = pwm_resources,
  760. .num_resources = ARRAY_SIZE(pwm_resources),
  761. };
  762. void __init at91_add_device_pwm(u32 mask)
  763. {
  764. if (mask & (1 << AT91_PWM0))
  765. at91_set_B_periph(AT91_PIN_PB7, 1); /* enable PWM0 */
  766. if (mask & (1 << AT91_PWM1))
  767. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
  768. if (mask & (1 << AT91_PWM2))
  769. at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
  770. if (mask & (1 << AT91_PWM3))
  771. at91_set_B_periph(AT91_PIN_PB29, 1); /* enable PWM3 */
  772. pwm_mask = mask;
  773. platform_device_register(&at91sam9263_pwm0_device);
  774. }
  775. #else
  776. void __init at91_add_device_pwm(u32 mask) {}
  777. #endif
  778. /* --------------------------------------------------------------------
  779. * SSC -- Synchronous Serial Controller
  780. * -------------------------------------------------------------------- */
  781. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  782. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  783. static struct resource ssc0_resources[] = {
  784. [0] = {
  785. .start = AT91SAM9263_BASE_SSC0,
  786. .end = AT91SAM9263_BASE_SSC0 + SZ_16K - 1,
  787. .flags = IORESOURCE_MEM,
  788. },
  789. [1] = {
  790. .start = AT91SAM9263_ID_SSC0,
  791. .end = AT91SAM9263_ID_SSC0,
  792. .flags = IORESOURCE_IRQ,
  793. },
  794. };
  795. static struct platform_device at91sam9263_ssc0_device = {
  796. .name = "ssc",
  797. .id = 0,
  798. .dev = {
  799. .dma_mask = &ssc0_dmamask,
  800. .coherent_dma_mask = DMA_BIT_MASK(32),
  801. },
  802. .resource = ssc0_resources,
  803. .num_resources = ARRAY_SIZE(ssc0_resources),
  804. };
  805. static inline void configure_ssc0_pins(unsigned pins)
  806. {
  807. if (pins & ATMEL_SSC_TF)
  808. at91_set_B_periph(AT91_PIN_PB0, 1);
  809. if (pins & ATMEL_SSC_TK)
  810. at91_set_B_periph(AT91_PIN_PB1, 1);
  811. if (pins & ATMEL_SSC_TD)
  812. at91_set_B_periph(AT91_PIN_PB2, 1);
  813. if (pins & ATMEL_SSC_RD)
  814. at91_set_B_periph(AT91_PIN_PB3, 1);
  815. if (pins & ATMEL_SSC_RK)
  816. at91_set_B_periph(AT91_PIN_PB4, 1);
  817. if (pins & ATMEL_SSC_RF)
  818. at91_set_B_periph(AT91_PIN_PB5, 1);
  819. }
  820. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  821. static struct resource ssc1_resources[] = {
  822. [0] = {
  823. .start = AT91SAM9263_BASE_SSC1,
  824. .end = AT91SAM9263_BASE_SSC1 + SZ_16K - 1,
  825. .flags = IORESOURCE_MEM,
  826. },
  827. [1] = {
  828. .start = AT91SAM9263_ID_SSC1,
  829. .end = AT91SAM9263_ID_SSC1,
  830. .flags = IORESOURCE_IRQ,
  831. },
  832. };
  833. static struct platform_device at91sam9263_ssc1_device = {
  834. .name = "ssc",
  835. .id = 1,
  836. .dev = {
  837. .dma_mask = &ssc1_dmamask,
  838. .coherent_dma_mask = DMA_BIT_MASK(32),
  839. },
  840. .resource = ssc1_resources,
  841. .num_resources = ARRAY_SIZE(ssc1_resources),
  842. };
  843. static inline void configure_ssc1_pins(unsigned pins)
  844. {
  845. if (pins & ATMEL_SSC_TF)
  846. at91_set_A_periph(AT91_PIN_PB6, 1);
  847. if (pins & ATMEL_SSC_TK)
  848. at91_set_A_periph(AT91_PIN_PB7, 1);
  849. if (pins & ATMEL_SSC_TD)
  850. at91_set_A_periph(AT91_PIN_PB8, 1);
  851. if (pins & ATMEL_SSC_RD)
  852. at91_set_A_periph(AT91_PIN_PB9, 1);
  853. if (pins & ATMEL_SSC_RK)
  854. at91_set_A_periph(AT91_PIN_PB10, 1);
  855. if (pins & ATMEL_SSC_RF)
  856. at91_set_A_periph(AT91_PIN_PB11, 1);
  857. }
  858. /*
  859. * SSC controllers are accessed through library code, instead of any
  860. * kind of all-singing/all-dancing driver. For example one could be
  861. * used by a particular I2S audio codec's driver, while another one
  862. * on the same system might be used by a custom data capture driver.
  863. */
  864. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  865. {
  866. struct platform_device *pdev;
  867. /*
  868. * NOTE: caller is responsible for passing information matching
  869. * "pins" to whatever will be using each particular controller.
  870. */
  871. switch (id) {
  872. case AT91SAM9263_ID_SSC0:
  873. pdev = &at91sam9263_ssc0_device;
  874. configure_ssc0_pins(pins);
  875. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  876. break;
  877. case AT91SAM9263_ID_SSC1:
  878. pdev = &at91sam9263_ssc1_device;
  879. configure_ssc1_pins(pins);
  880. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  881. break;
  882. default:
  883. return;
  884. }
  885. platform_device_register(pdev);
  886. }
  887. #else
  888. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  889. #endif
  890. /* --------------------------------------------------------------------
  891. * UART
  892. * -------------------------------------------------------------------- */
  893. #if defined(CONFIG_SERIAL_ATMEL)
  894. static struct resource dbgu_resources[] = {
  895. [0] = {
  896. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  897. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  898. .flags = IORESOURCE_MEM,
  899. },
  900. [1] = {
  901. .start = AT91_ID_SYS,
  902. .end = AT91_ID_SYS,
  903. .flags = IORESOURCE_IRQ,
  904. },
  905. };
  906. static struct atmel_uart_data dbgu_data = {
  907. .use_dma_tx = 0,
  908. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  909. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  910. };
  911. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  912. static struct platform_device at91sam9263_dbgu_device = {
  913. .name = "atmel_usart",
  914. .id = 0,
  915. .dev = {
  916. .dma_mask = &dbgu_dmamask,
  917. .coherent_dma_mask = DMA_BIT_MASK(32),
  918. .platform_data = &dbgu_data,
  919. },
  920. .resource = dbgu_resources,
  921. .num_resources = ARRAY_SIZE(dbgu_resources),
  922. };
  923. static inline void configure_dbgu_pins(void)
  924. {
  925. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  926. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  927. }
  928. static struct resource uart0_resources[] = {
  929. [0] = {
  930. .start = AT91SAM9263_BASE_US0,
  931. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  932. .flags = IORESOURCE_MEM,
  933. },
  934. [1] = {
  935. .start = AT91SAM9263_ID_US0,
  936. .end = AT91SAM9263_ID_US0,
  937. .flags = IORESOURCE_IRQ,
  938. },
  939. };
  940. static struct atmel_uart_data uart0_data = {
  941. .use_dma_tx = 1,
  942. .use_dma_rx = 1,
  943. };
  944. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  945. static struct platform_device at91sam9263_uart0_device = {
  946. .name = "atmel_usart",
  947. .id = 1,
  948. .dev = {
  949. .dma_mask = &uart0_dmamask,
  950. .coherent_dma_mask = DMA_BIT_MASK(32),
  951. .platform_data = &uart0_data,
  952. },
  953. .resource = uart0_resources,
  954. .num_resources = ARRAY_SIZE(uart0_resources),
  955. };
  956. static inline void configure_usart0_pins(unsigned pins)
  957. {
  958. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  959. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  960. if (pins & ATMEL_UART_RTS)
  961. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  962. if (pins & ATMEL_UART_CTS)
  963. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  964. }
  965. static struct resource uart1_resources[] = {
  966. [0] = {
  967. .start = AT91SAM9263_BASE_US1,
  968. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  969. .flags = IORESOURCE_MEM,
  970. },
  971. [1] = {
  972. .start = AT91SAM9263_ID_US1,
  973. .end = AT91SAM9263_ID_US1,
  974. .flags = IORESOURCE_IRQ,
  975. },
  976. };
  977. static struct atmel_uart_data uart1_data = {
  978. .use_dma_tx = 1,
  979. .use_dma_rx = 1,
  980. };
  981. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  982. static struct platform_device at91sam9263_uart1_device = {
  983. .name = "atmel_usart",
  984. .id = 2,
  985. .dev = {
  986. .dma_mask = &uart1_dmamask,
  987. .coherent_dma_mask = DMA_BIT_MASK(32),
  988. .platform_data = &uart1_data,
  989. },
  990. .resource = uart1_resources,
  991. .num_resources = ARRAY_SIZE(uart1_resources),
  992. };
  993. static inline void configure_usart1_pins(unsigned pins)
  994. {
  995. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  996. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  997. if (pins & ATMEL_UART_RTS)
  998. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  999. if (pins & ATMEL_UART_CTS)
  1000. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  1001. }
  1002. static struct resource uart2_resources[] = {
  1003. [0] = {
  1004. .start = AT91SAM9263_BASE_US2,
  1005. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  1006. .flags = IORESOURCE_MEM,
  1007. },
  1008. [1] = {
  1009. .start = AT91SAM9263_ID_US2,
  1010. .end = AT91SAM9263_ID_US2,
  1011. .flags = IORESOURCE_IRQ,
  1012. },
  1013. };
  1014. static struct atmel_uart_data uart2_data = {
  1015. .use_dma_tx = 1,
  1016. .use_dma_rx = 1,
  1017. };
  1018. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  1019. static struct platform_device at91sam9263_uart2_device = {
  1020. .name = "atmel_usart",
  1021. .id = 3,
  1022. .dev = {
  1023. .dma_mask = &uart2_dmamask,
  1024. .coherent_dma_mask = DMA_BIT_MASK(32),
  1025. .platform_data = &uart2_data,
  1026. },
  1027. .resource = uart2_resources,
  1028. .num_resources = ARRAY_SIZE(uart2_resources),
  1029. };
  1030. static inline void configure_usart2_pins(unsigned pins)
  1031. {
  1032. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  1033. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  1034. if (pins & ATMEL_UART_RTS)
  1035. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  1036. if (pins & ATMEL_UART_CTS)
  1037. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  1038. }
  1039. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1040. struct platform_device *atmel_default_console_device; /* the serial console device */
  1041. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1042. {
  1043. struct platform_device *pdev;
  1044. switch (id) {
  1045. case 0: /* DBGU */
  1046. pdev = &at91sam9263_dbgu_device;
  1047. configure_dbgu_pins();
  1048. at91_clock_associate("mck", &pdev->dev, "usart");
  1049. break;
  1050. case AT91SAM9263_ID_US0:
  1051. pdev = &at91sam9263_uart0_device;
  1052. configure_usart0_pins(pins);
  1053. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  1054. break;
  1055. case AT91SAM9263_ID_US1:
  1056. pdev = &at91sam9263_uart1_device;
  1057. configure_usart1_pins(pins);
  1058. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  1059. break;
  1060. case AT91SAM9263_ID_US2:
  1061. pdev = &at91sam9263_uart2_device;
  1062. configure_usart2_pins(pins);
  1063. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  1064. break;
  1065. default:
  1066. return;
  1067. }
  1068. pdev->id = portnr; /* update to mapped ID */
  1069. if (portnr < ATMEL_MAX_UART)
  1070. at91_uarts[portnr] = pdev;
  1071. }
  1072. void __init at91_set_serial_console(unsigned portnr)
  1073. {
  1074. if (portnr < ATMEL_MAX_UART)
  1075. atmel_default_console_device = at91_uarts[portnr];
  1076. }
  1077. void __init at91_add_device_serial(void)
  1078. {
  1079. int i;
  1080. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1081. if (at91_uarts[i])
  1082. platform_device_register(at91_uarts[i]);
  1083. }
  1084. if (!atmel_default_console_device)
  1085. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1086. }
  1087. #else
  1088. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1089. void __init at91_set_serial_console(unsigned portnr) {}
  1090. void __init at91_add_device_serial(void) {}
  1091. #endif
  1092. /* -------------------------------------------------------------------- */
  1093. /*
  1094. * These devices are always present and don't need any board-specific
  1095. * setup.
  1096. */
  1097. static int __init at91_add_standard_devices(void)
  1098. {
  1099. at91_add_device_rtt();
  1100. at91_add_device_watchdog();
  1101. at91_add_device_tc();
  1102. return 0;
  1103. }
  1104. arch_initcall(at91_add_standard_devices);