at91sam9263_devices.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  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, mode;
  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. /* set the bus interface characteristics */
  334. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(1) | AT91_SMC_NCS_WRSETUP_(0)
  335. | AT91_SMC_NRDSETUP_(1) | AT91_SMC_NCS_RDSETUP_(0));
  336. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(3) | AT91_SMC_NCS_WRPULSE_(3)
  337. | AT91_SMC_NRDPULSE_(3) | AT91_SMC_NCS_RDPULSE_(3));
  338. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(5) | AT91_SMC_NRDCYCLE_(5));
  339. if (data->bus_width_16)
  340. mode = AT91_SMC_DBW_16;
  341. else
  342. mode = AT91_SMC_DBW_8;
  343. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(2));
  344. /* enable pin */
  345. if (data->enable_pin)
  346. at91_set_gpio_output(data->enable_pin, 1);
  347. /* ready/busy pin */
  348. if (data->rdy_pin)
  349. at91_set_gpio_input(data->rdy_pin, 1);
  350. /* card detect pin */
  351. if (data->det_pin)
  352. at91_set_gpio_input(data->det_pin, 1);
  353. nand_data = *data;
  354. platform_device_register(&at91sam9263_nand_device);
  355. }
  356. #else
  357. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  358. #endif
  359. /* --------------------------------------------------------------------
  360. * TWI (i2c)
  361. * -------------------------------------------------------------------- */
  362. /*
  363. * Prefer the GPIO code since the TWI controller isn't robust
  364. * (gets overruns and underruns under load) and can only issue
  365. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  366. */
  367. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  368. static struct i2c_gpio_platform_data pdata = {
  369. .sda_pin = AT91_PIN_PB4,
  370. .sda_is_open_drain = 1,
  371. .scl_pin = AT91_PIN_PB5,
  372. .scl_is_open_drain = 1,
  373. .udelay = 2, /* ~100 kHz */
  374. };
  375. static struct platform_device at91sam9263_twi_device = {
  376. .name = "i2c-gpio",
  377. .id = -1,
  378. .dev.platform_data = &pdata,
  379. };
  380. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  381. {
  382. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  383. at91_set_multi_drive(AT91_PIN_PB4, 1);
  384. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  385. at91_set_multi_drive(AT91_PIN_PB5, 1);
  386. i2c_register_board_info(0, devices, nr_devices);
  387. platform_device_register(&at91sam9263_twi_device);
  388. }
  389. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  390. static struct resource twi_resources[] = {
  391. [0] = {
  392. .start = AT91SAM9263_BASE_TWI,
  393. .end = AT91SAM9263_BASE_TWI + SZ_16K - 1,
  394. .flags = IORESOURCE_MEM,
  395. },
  396. [1] = {
  397. .start = AT91SAM9263_ID_TWI,
  398. .end = AT91SAM9263_ID_TWI,
  399. .flags = IORESOURCE_IRQ,
  400. },
  401. };
  402. static struct platform_device at91sam9263_twi_device = {
  403. .name = "at91_i2c",
  404. .id = -1,
  405. .resource = twi_resources,
  406. .num_resources = ARRAY_SIZE(twi_resources),
  407. };
  408. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  409. {
  410. /* pins used for TWI interface */
  411. at91_set_A_periph(AT91_PIN_PB4, 0); /* TWD */
  412. at91_set_multi_drive(AT91_PIN_PB4, 1);
  413. at91_set_A_periph(AT91_PIN_PB5, 0); /* TWCK */
  414. at91_set_multi_drive(AT91_PIN_PB5, 1);
  415. i2c_register_board_info(0, devices, nr_devices);
  416. platform_device_register(&at91sam9263_twi_device);
  417. }
  418. #else
  419. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  420. #endif
  421. /* --------------------------------------------------------------------
  422. * SPI
  423. * -------------------------------------------------------------------- */
  424. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  425. static u64 spi_dmamask = DMA_BIT_MASK(32);
  426. static struct resource spi0_resources[] = {
  427. [0] = {
  428. .start = AT91SAM9263_BASE_SPI0,
  429. .end = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
  430. .flags = IORESOURCE_MEM,
  431. },
  432. [1] = {
  433. .start = AT91SAM9263_ID_SPI0,
  434. .end = AT91SAM9263_ID_SPI0,
  435. .flags = IORESOURCE_IRQ,
  436. },
  437. };
  438. static struct platform_device at91sam9263_spi0_device = {
  439. .name = "atmel_spi",
  440. .id = 0,
  441. .dev = {
  442. .dma_mask = &spi_dmamask,
  443. .coherent_dma_mask = DMA_BIT_MASK(32),
  444. },
  445. .resource = spi0_resources,
  446. .num_resources = ARRAY_SIZE(spi0_resources),
  447. };
  448. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
  449. static struct resource spi1_resources[] = {
  450. [0] = {
  451. .start = AT91SAM9263_BASE_SPI1,
  452. .end = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
  453. .flags = IORESOURCE_MEM,
  454. },
  455. [1] = {
  456. .start = AT91SAM9263_ID_SPI1,
  457. .end = AT91SAM9263_ID_SPI1,
  458. .flags = IORESOURCE_IRQ,
  459. },
  460. };
  461. static struct platform_device at91sam9263_spi1_device = {
  462. .name = "atmel_spi",
  463. .id = 1,
  464. .dev = {
  465. .dma_mask = &spi_dmamask,
  466. .coherent_dma_mask = DMA_BIT_MASK(32),
  467. },
  468. .resource = spi1_resources,
  469. .num_resources = ARRAY_SIZE(spi1_resources),
  470. };
  471. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  472. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  473. {
  474. int i;
  475. unsigned long cs_pin;
  476. short enable_spi0 = 0;
  477. short enable_spi1 = 0;
  478. /* Choose SPI chip-selects */
  479. for (i = 0; i < nr_devices; i++) {
  480. if (devices[i].controller_data)
  481. cs_pin = (unsigned long) devices[i].controller_data;
  482. else if (devices[i].bus_num == 0)
  483. cs_pin = spi0_standard_cs[devices[i].chip_select];
  484. else
  485. cs_pin = spi1_standard_cs[devices[i].chip_select];
  486. if (devices[i].bus_num == 0)
  487. enable_spi0 = 1;
  488. else
  489. enable_spi1 = 1;
  490. /* enable chip-select pin */
  491. at91_set_gpio_output(cs_pin, 1);
  492. /* pass chip-select pin to driver */
  493. devices[i].controller_data = (void *) cs_pin;
  494. }
  495. spi_register_board_info(devices, nr_devices);
  496. /* Configure SPI bus(es) */
  497. if (enable_spi0) {
  498. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  499. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  500. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  501. at91_clock_associate("spi0_clk", &at91sam9263_spi0_device.dev, "spi_clk");
  502. platform_device_register(&at91sam9263_spi0_device);
  503. }
  504. if (enable_spi1) {
  505. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  506. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  507. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  508. at91_clock_associate("spi1_clk", &at91sam9263_spi1_device.dev, "spi_clk");
  509. platform_device_register(&at91sam9263_spi1_device);
  510. }
  511. }
  512. #else
  513. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  514. #endif
  515. /* --------------------------------------------------------------------
  516. * AC97
  517. * -------------------------------------------------------------------- */
  518. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  519. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  520. static struct atmel_ac97_data ac97_data;
  521. static struct resource ac97_resources[] = {
  522. [0] = {
  523. .start = AT91SAM9263_BASE_AC97C,
  524. .end = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
  525. .flags = IORESOURCE_MEM,
  526. },
  527. [1] = {
  528. .start = AT91SAM9263_ID_AC97C,
  529. .end = AT91SAM9263_ID_AC97C,
  530. .flags = IORESOURCE_IRQ,
  531. },
  532. };
  533. static struct platform_device at91sam9263_ac97_device = {
  534. .name = "ac97c",
  535. .id = 1,
  536. .dev = {
  537. .dma_mask = &ac97_dmamask,
  538. .coherent_dma_mask = DMA_BIT_MASK(32),
  539. .platform_data = &ac97_data,
  540. },
  541. .resource = ac97_resources,
  542. .num_resources = ARRAY_SIZE(ac97_resources),
  543. };
  544. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  545. {
  546. if (!data)
  547. return;
  548. at91_set_A_periph(AT91_PIN_PB0, 0); /* AC97FS */
  549. at91_set_A_periph(AT91_PIN_PB1, 0); /* AC97CK */
  550. at91_set_A_periph(AT91_PIN_PB2, 0); /* AC97TX */
  551. at91_set_A_periph(AT91_PIN_PB3, 0); /* AC97RX */
  552. /* reset */
  553. if (data->reset_pin)
  554. at91_set_gpio_output(data->reset_pin, 0);
  555. ac97_data = *ek_data;
  556. platform_device_register(&at91sam9263_ac97_device);
  557. }
  558. #else
  559. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  560. #endif
  561. /* --------------------------------------------------------------------
  562. * LCD Controller
  563. * -------------------------------------------------------------------- */
  564. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  565. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  566. static struct atmel_lcdfb_info lcdc_data;
  567. static struct resource lcdc_resources[] = {
  568. [0] = {
  569. .start = AT91SAM9263_LCDC_BASE,
  570. .end = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
  571. .flags = IORESOURCE_MEM,
  572. },
  573. [1] = {
  574. .start = AT91SAM9263_ID_LCDC,
  575. .end = AT91SAM9263_ID_LCDC,
  576. .flags = IORESOURCE_IRQ,
  577. },
  578. };
  579. static struct platform_device at91_lcdc_device = {
  580. .name = "atmel_lcdfb",
  581. .id = 0,
  582. .dev = {
  583. .dma_mask = &lcdc_dmamask,
  584. .coherent_dma_mask = DMA_BIT_MASK(32),
  585. .platform_data = &lcdc_data,
  586. },
  587. .resource = lcdc_resources,
  588. .num_resources = ARRAY_SIZE(lcdc_resources),
  589. };
  590. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  591. {
  592. if (!data)
  593. return;
  594. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  595. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  596. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  597. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  598. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  599. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  600. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  601. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  602. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  603. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  604. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  605. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  606. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  607. at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
  608. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  609. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  610. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  611. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  612. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  613. at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
  614. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  615. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  616. lcdc_data = *data;
  617. platform_device_register(&at91_lcdc_device);
  618. }
  619. #else
  620. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  621. #endif
  622. /* --------------------------------------------------------------------
  623. * Image Sensor Interface
  624. * -------------------------------------------------------------------- */
  625. #if defined(CONFIG_VIDEO_AT91_ISI) || defined(CONFIG_VIDEO_AT91_ISI_MODULE)
  626. struct resource isi_resources[] = {
  627. [0] = {
  628. .start = AT91SAM9263_BASE_ISI,
  629. .end = AT91SAM9263_BASE_ISI + SZ_16K - 1,
  630. .flags = IORESOURCE_MEM,
  631. },
  632. [1] = {
  633. .start = AT91SAM9263_ID_ISI,
  634. .end = AT91SAM9263_ID_ISI,
  635. .flags = IORESOURCE_IRQ,
  636. },
  637. };
  638. static struct platform_device at91sam9263_isi_device = {
  639. .name = "at91_isi",
  640. .id = -1,
  641. .resource = isi_resources,
  642. .num_resources = ARRAY_SIZE(isi_resources),
  643. };
  644. void __init at91_add_device_isi(void)
  645. {
  646. at91_set_A_periph(AT91_PIN_PE0, 0); /* ISI_D0 */
  647. at91_set_A_periph(AT91_PIN_PE1, 0); /* ISI_D1 */
  648. at91_set_A_periph(AT91_PIN_PE2, 0); /* ISI_D2 */
  649. at91_set_A_periph(AT91_PIN_PE3, 0); /* ISI_D3 */
  650. at91_set_A_periph(AT91_PIN_PE4, 0); /* ISI_D4 */
  651. at91_set_A_periph(AT91_PIN_PE5, 0); /* ISI_D5 */
  652. at91_set_A_periph(AT91_PIN_PE6, 0); /* ISI_D6 */
  653. at91_set_A_periph(AT91_PIN_PE7, 0); /* ISI_D7 */
  654. at91_set_A_periph(AT91_PIN_PE8, 0); /* ISI_PCK */
  655. at91_set_A_periph(AT91_PIN_PE9, 0); /* ISI_HSYNC */
  656. at91_set_A_periph(AT91_PIN_PE10, 0); /* ISI_VSYNC */
  657. at91_set_B_periph(AT91_PIN_PE11, 0); /* ISI_MCK (PCK3) */
  658. at91_set_B_periph(AT91_PIN_PE12, 0); /* ISI_PD8 */
  659. at91_set_B_periph(AT91_PIN_PE13, 0); /* ISI_PD9 */
  660. at91_set_B_periph(AT91_PIN_PE14, 0); /* ISI_PD10 */
  661. at91_set_B_periph(AT91_PIN_PE15, 0); /* ISI_PD11 */
  662. }
  663. #else
  664. void __init at91_add_device_isi(void) {}
  665. #endif
  666. /* --------------------------------------------------------------------
  667. * Timer/Counter block
  668. * -------------------------------------------------------------------- */
  669. #ifdef CONFIG_ATMEL_TCLIB
  670. static struct resource tcb_resources[] = {
  671. [0] = {
  672. .start = AT91SAM9263_BASE_TCB0,
  673. .end = AT91SAM9263_BASE_TCB0 + SZ_16K - 1,
  674. .flags = IORESOURCE_MEM,
  675. },
  676. [1] = {
  677. .start = AT91SAM9263_ID_TCB,
  678. .end = AT91SAM9263_ID_TCB,
  679. .flags = IORESOURCE_IRQ,
  680. },
  681. };
  682. static struct platform_device at91sam9263_tcb_device = {
  683. .name = "atmel_tcb",
  684. .id = 0,
  685. .resource = tcb_resources,
  686. .num_resources = ARRAY_SIZE(tcb_resources),
  687. };
  688. static void __init at91_add_device_tc(void)
  689. {
  690. /* this chip has one clock and irq for all three TC channels */
  691. at91_clock_associate("tcb_clk", &at91sam9263_tcb_device.dev, "t0_clk");
  692. platform_device_register(&at91sam9263_tcb_device);
  693. }
  694. #else
  695. static void __init at91_add_device_tc(void) { }
  696. #endif
  697. /* --------------------------------------------------------------------
  698. * RTT
  699. * -------------------------------------------------------------------- */
  700. static struct resource rtt0_resources[] = {
  701. {
  702. .start = AT91_BASE_SYS + AT91_RTT0,
  703. .end = AT91_BASE_SYS + AT91_RTT0 + SZ_16 - 1,
  704. .flags = IORESOURCE_MEM,
  705. }
  706. };
  707. static struct platform_device at91sam9263_rtt0_device = {
  708. .name = "at91_rtt",
  709. .id = 0,
  710. .resource = rtt0_resources,
  711. .num_resources = ARRAY_SIZE(rtt0_resources),
  712. };
  713. static struct resource rtt1_resources[] = {
  714. {
  715. .start = AT91_BASE_SYS + AT91_RTT1,
  716. .end = AT91_BASE_SYS + AT91_RTT1 + SZ_16 - 1,
  717. .flags = IORESOURCE_MEM,
  718. }
  719. };
  720. static struct platform_device at91sam9263_rtt1_device = {
  721. .name = "at91_rtt",
  722. .id = 1,
  723. .resource = rtt1_resources,
  724. .num_resources = ARRAY_SIZE(rtt1_resources),
  725. };
  726. static void __init at91_add_device_rtt(void)
  727. {
  728. platform_device_register(&at91sam9263_rtt0_device);
  729. platform_device_register(&at91sam9263_rtt1_device);
  730. }
  731. /* --------------------------------------------------------------------
  732. * Watchdog
  733. * -------------------------------------------------------------------- */
  734. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  735. static struct platform_device at91sam9263_wdt_device = {
  736. .name = "at91_wdt",
  737. .id = -1,
  738. .num_resources = 0,
  739. };
  740. static void __init at91_add_device_watchdog(void)
  741. {
  742. platform_device_register(&at91sam9263_wdt_device);
  743. }
  744. #else
  745. static void __init at91_add_device_watchdog(void) {}
  746. #endif
  747. /* --------------------------------------------------------------------
  748. * PWM
  749. * --------------------------------------------------------------------*/
  750. #if defined(CONFIG_ATMEL_PWM)
  751. static u32 pwm_mask;
  752. static struct resource pwm_resources[] = {
  753. [0] = {
  754. .start = AT91SAM9263_BASE_PWMC,
  755. .end = AT91SAM9263_BASE_PWMC + SZ_16K - 1,
  756. .flags = IORESOURCE_MEM,
  757. },
  758. [1] = {
  759. .start = AT91SAM9263_ID_PWMC,
  760. .end = AT91SAM9263_ID_PWMC,
  761. .flags = IORESOURCE_IRQ,
  762. },
  763. };
  764. static struct platform_device at91sam9263_pwm0_device = {
  765. .name = "atmel_pwm",
  766. .id = -1,
  767. .dev = {
  768. .platform_data = &pwm_mask,
  769. },
  770. .resource = pwm_resources,
  771. .num_resources = ARRAY_SIZE(pwm_resources),
  772. };
  773. void __init at91_add_device_pwm(u32 mask)
  774. {
  775. if (mask & (1 << AT91_PWM0))
  776. at91_set_B_periph(AT91_PIN_PB7, 1); /* enable PWM0 */
  777. if (mask & (1 << AT91_PWM1))
  778. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
  779. if (mask & (1 << AT91_PWM2))
  780. at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
  781. if (mask & (1 << AT91_PWM3))
  782. at91_set_B_periph(AT91_PIN_PB29, 1); /* enable PWM3 */
  783. pwm_mask = mask;
  784. platform_device_register(&at91sam9263_pwm0_device);
  785. }
  786. #else
  787. void __init at91_add_device_pwm(u32 mask) {}
  788. #endif
  789. /* --------------------------------------------------------------------
  790. * SSC -- Synchronous Serial Controller
  791. * -------------------------------------------------------------------- */
  792. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  793. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  794. static struct resource ssc0_resources[] = {
  795. [0] = {
  796. .start = AT91SAM9263_BASE_SSC0,
  797. .end = AT91SAM9263_BASE_SSC0 + SZ_16K - 1,
  798. .flags = IORESOURCE_MEM,
  799. },
  800. [1] = {
  801. .start = AT91SAM9263_ID_SSC0,
  802. .end = AT91SAM9263_ID_SSC0,
  803. .flags = IORESOURCE_IRQ,
  804. },
  805. };
  806. static struct platform_device at91sam9263_ssc0_device = {
  807. .name = "ssc",
  808. .id = 0,
  809. .dev = {
  810. .dma_mask = &ssc0_dmamask,
  811. .coherent_dma_mask = DMA_BIT_MASK(32),
  812. },
  813. .resource = ssc0_resources,
  814. .num_resources = ARRAY_SIZE(ssc0_resources),
  815. };
  816. static inline void configure_ssc0_pins(unsigned pins)
  817. {
  818. if (pins & ATMEL_SSC_TF)
  819. at91_set_B_periph(AT91_PIN_PB0, 1);
  820. if (pins & ATMEL_SSC_TK)
  821. at91_set_B_periph(AT91_PIN_PB1, 1);
  822. if (pins & ATMEL_SSC_TD)
  823. at91_set_B_periph(AT91_PIN_PB2, 1);
  824. if (pins & ATMEL_SSC_RD)
  825. at91_set_B_periph(AT91_PIN_PB3, 1);
  826. if (pins & ATMEL_SSC_RK)
  827. at91_set_B_periph(AT91_PIN_PB4, 1);
  828. if (pins & ATMEL_SSC_RF)
  829. at91_set_B_periph(AT91_PIN_PB5, 1);
  830. }
  831. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  832. static struct resource ssc1_resources[] = {
  833. [0] = {
  834. .start = AT91SAM9263_BASE_SSC1,
  835. .end = AT91SAM9263_BASE_SSC1 + SZ_16K - 1,
  836. .flags = IORESOURCE_MEM,
  837. },
  838. [1] = {
  839. .start = AT91SAM9263_ID_SSC1,
  840. .end = AT91SAM9263_ID_SSC1,
  841. .flags = IORESOURCE_IRQ,
  842. },
  843. };
  844. static struct platform_device at91sam9263_ssc1_device = {
  845. .name = "ssc",
  846. .id = 1,
  847. .dev = {
  848. .dma_mask = &ssc1_dmamask,
  849. .coherent_dma_mask = DMA_BIT_MASK(32),
  850. },
  851. .resource = ssc1_resources,
  852. .num_resources = ARRAY_SIZE(ssc1_resources),
  853. };
  854. static inline void configure_ssc1_pins(unsigned pins)
  855. {
  856. if (pins & ATMEL_SSC_TF)
  857. at91_set_A_periph(AT91_PIN_PB6, 1);
  858. if (pins & ATMEL_SSC_TK)
  859. at91_set_A_periph(AT91_PIN_PB7, 1);
  860. if (pins & ATMEL_SSC_TD)
  861. at91_set_A_periph(AT91_PIN_PB8, 1);
  862. if (pins & ATMEL_SSC_RD)
  863. at91_set_A_periph(AT91_PIN_PB9, 1);
  864. if (pins & ATMEL_SSC_RK)
  865. at91_set_A_periph(AT91_PIN_PB10, 1);
  866. if (pins & ATMEL_SSC_RF)
  867. at91_set_A_periph(AT91_PIN_PB11, 1);
  868. }
  869. /*
  870. * SSC controllers are accessed through library code, instead of any
  871. * kind of all-singing/all-dancing driver. For example one could be
  872. * used by a particular I2S audio codec's driver, while another one
  873. * on the same system might be used by a custom data capture driver.
  874. */
  875. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  876. {
  877. struct platform_device *pdev;
  878. /*
  879. * NOTE: caller is responsible for passing information matching
  880. * "pins" to whatever will be using each particular controller.
  881. */
  882. switch (id) {
  883. case AT91SAM9263_ID_SSC0:
  884. pdev = &at91sam9263_ssc0_device;
  885. configure_ssc0_pins(pins);
  886. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  887. break;
  888. case AT91SAM9263_ID_SSC1:
  889. pdev = &at91sam9263_ssc1_device;
  890. configure_ssc1_pins(pins);
  891. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  892. break;
  893. default:
  894. return;
  895. }
  896. platform_device_register(pdev);
  897. }
  898. #else
  899. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  900. #endif
  901. /* --------------------------------------------------------------------
  902. * UART
  903. * -------------------------------------------------------------------- */
  904. #if defined(CONFIG_SERIAL_ATMEL)
  905. static struct resource dbgu_resources[] = {
  906. [0] = {
  907. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  908. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  909. .flags = IORESOURCE_MEM,
  910. },
  911. [1] = {
  912. .start = AT91_ID_SYS,
  913. .end = AT91_ID_SYS,
  914. .flags = IORESOURCE_IRQ,
  915. },
  916. };
  917. static struct atmel_uart_data dbgu_data = {
  918. .use_dma_tx = 0,
  919. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  920. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  921. };
  922. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  923. static struct platform_device at91sam9263_dbgu_device = {
  924. .name = "atmel_usart",
  925. .id = 0,
  926. .dev = {
  927. .dma_mask = &dbgu_dmamask,
  928. .coherent_dma_mask = DMA_BIT_MASK(32),
  929. .platform_data = &dbgu_data,
  930. },
  931. .resource = dbgu_resources,
  932. .num_resources = ARRAY_SIZE(dbgu_resources),
  933. };
  934. static inline void configure_dbgu_pins(void)
  935. {
  936. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  937. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  938. }
  939. static struct resource uart0_resources[] = {
  940. [0] = {
  941. .start = AT91SAM9263_BASE_US0,
  942. .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
  943. .flags = IORESOURCE_MEM,
  944. },
  945. [1] = {
  946. .start = AT91SAM9263_ID_US0,
  947. .end = AT91SAM9263_ID_US0,
  948. .flags = IORESOURCE_IRQ,
  949. },
  950. };
  951. static struct atmel_uart_data uart0_data = {
  952. .use_dma_tx = 1,
  953. .use_dma_rx = 1,
  954. };
  955. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  956. static struct platform_device at91sam9263_uart0_device = {
  957. .name = "atmel_usart",
  958. .id = 1,
  959. .dev = {
  960. .dma_mask = &uart0_dmamask,
  961. .coherent_dma_mask = DMA_BIT_MASK(32),
  962. .platform_data = &uart0_data,
  963. },
  964. .resource = uart0_resources,
  965. .num_resources = ARRAY_SIZE(uart0_resources),
  966. };
  967. static inline void configure_usart0_pins(unsigned pins)
  968. {
  969. at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
  970. at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
  971. if (pins & ATMEL_UART_RTS)
  972. at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
  973. if (pins & ATMEL_UART_CTS)
  974. at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
  975. }
  976. static struct resource uart1_resources[] = {
  977. [0] = {
  978. .start = AT91SAM9263_BASE_US1,
  979. .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
  980. .flags = IORESOURCE_MEM,
  981. },
  982. [1] = {
  983. .start = AT91SAM9263_ID_US1,
  984. .end = AT91SAM9263_ID_US1,
  985. .flags = IORESOURCE_IRQ,
  986. },
  987. };
  988. static struct atmel_uart_data uart1_data = {
  989. .use_dma_tx = 1,
  990. .use_dma_rx = 1,
  991. };
  992. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  993. static struct platform_device at91sam9263_uart1_device = {
  994. .name = "atmel_usart",
  995. .id = 2,
  996. .dev = {
  997. .dma_mask = &uart1_dmamask,
  998. .coherent_dma_mask = DMA_BIT_MASK(32),
  999. .platform_data = &uart1_data,
  1000. },
  1001. .resource = uart1_resources,
  1002. .num_resources = ARRAY_SIZE(uart1_resources),
  1003. };
  1004. static inline void configure_usart1_pins(unsigned pins)
  1005. {
  1006. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  1007. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  1008. if (pins & ATMEL_UART_RTS)
  1009. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  1010. if (pins & ATMEL_UART_CTS)
  1011. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  1012. }
  1013. static struct resource uart2_resources[] = {
  1014. [0] = {
  1015. .start = AT91SAM9263_BASE_US2,
  1016. .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
  1017. .flags = IORESOURCE_MEM,
  1018. },
  1019. [1] = {
  1020. .start = AT91SAM9263_ID_US2,
  1021. .end = AT91SAM9263_ID_US2,
  1022. .flags = IORESOURCE_IRQ,
  1023. },
  1024. };
  1025. static struct atmel_uart_data uart2_data = {
  1026. .use_dma_tx = 1,
  1027. .use_dma_rx = 1,
  1028. };
  1029. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  1030. static struct platform_device at91sam9263_uart2_device = {
  1031. .name = "atmel_usart",
  1032. .id = 3,
  1033. .dev = {
  1034. .dma_mask = &uart2_dmamask,
  1035. .coherent_dma_mask = DMA_BIT_MASK(32),
  1036. .platform_data = &uart2_data,
  1037. },
  1038. .resource = uart2_resources,
  1039. .num_resources = ARRAY_SIZE(uart2_resources),
  1040. };
  1041. static inline void configure_usart2_pins(unsigned pins)
  1042. {
  1043. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  1044. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  1045. if (pins & ATMEL_UART_RTS)
  1046. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  1047. if (pins & ATMEL_UART_CTS)
  1048. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  1049. }
  1050. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1051. struct platform_device *atmel_default_console_device; /* the serial console device */
  1052. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1053. {
  1054. struct platform_device *pdev;
  1055. switch (id) {
  1056. case 0: /* DBGU */
  1057. pdev = &at91sam9263_dbgu_device;
  1058. configure_dbgu_pins();
  1059. at91_clock_associate("mck", &pdev->dev, "usart");
  1060. break;
  1061. case AT91SAM9263_ID_US0:
  1062. pdev = &at91sam9263_uart0_device;
  1063. configure_usart0_pins(pins);
  1064. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  1065. break;
  1066. case AT91SAM9263_ID_US1:
  1067. pdev = &at91sam9263_uart1_device;
  1068. configure_usart1_pins(pins);
  1069. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  1070. break;
  1071. case AT91SAM9263_ID_US2:
  1072. pdev = &at91sam9263_uart2_device;
  1073. configure_usart2_pins(pins);
  1074. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  1075. break;
  1076. default:
  1077. return;
  1078. }
  1079. pdev->id = portnr; /* update to mapped ID */
  1080. if (portnr < ATMEL_MAX_UART)
  1081. at91_uarts[portnr] = pdev;
  1082. }
  1083. void __init at91_set_serial_console(unsigned portnr)
  1084. {
  1085. if (portnr < ATMEL_MAX_UART)
  1086. atmel_default_console_device = at91_uarts[portnr];
  1087. }
  1088. void __init at91_add_device_serial(void)
  1089. {
  1090. int i;
  1091. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1092. if (at91_uarts[i])
  1093. platform_device_register(at91_uarts[i]);
  1094. }
  1095. if (!atmel_default_console_device)
  1096. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1097. }
  1098. #else
  1099. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1100. void __init at91_set_serial_console(unsigned portnr) {}
  1101. void __init at91_add_device_serial(void) {}
  1102. #endif
  1103. /* -------------------------------------------------------------------- */
  1104. /*
  1105. * These devices are always present and don't need any board-specific
  1106. * setup.
  1107. */
  1108. static int __init at91_add_standard_devices(void)
  1109. {
  1110. at91_add_device_rtt();
  1111. at91_add_device_watchdog();
  1112. at91_add_device_tc();
  1113. return 0;
  1114. }
  1115. arch_initcall(at91_add_standard_devices);