at91cap9_devices.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. /*
  2. * arch/arm/mach-at91/at91cap9_devices.c
  3. *
  4. * Copyright (C) 2007 Stelian Pop <stelian.pop@leadtechdesign.com>
  5. * Copyright (C) 2007 Lead Tech Design <www.leadtechdesign.com>
  6. * Copyright (C) 2007 Atmel Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #include <asm/mach/arch.h>
  15. #include <asm/mach/map.h>
  16. #include <asm/mach/irq.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/i2c-gpio.h>
  20. #include <video/atmel_lcdc.h>
  21. #include <mach/board.h>
  22. #include <mach/cpu.h>
  23. #include <mach/gpio.h>
  24. #include <mach/at91cap9.h>
  25. #include <mach/at91cap9_matrix.h>
  26. #include <mach/at91sam9_smc.h>
  27. #include "generic.h"
  28. /* --------------------------------------------------------------------
  29. * USB Host
  30. * -------------------------------------------------------------------- */
  31. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  32. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  33. static struct at91_usbh_data usbh_data;
  34. static struct resource usbh_resources[] = {
  35. [0] = {
  36. .start = AT91CAP9_UHP_BASE,
  37. .end = AT91CAP9_UHP_BASE + SZ_1M - 1,
  38. .flags = IORESOURCE_MEM,
  39. },
  40. [1] = {
  41. .start = AT91CAP9_ID_UHP,
  42. .end = AT91CAP9_ID_UHP,
  43. .flags = IORESOURCE_IRQ,
  44. },
  45. };
  46. static struct platform_device at91_usbh_device = {
  47. .name = "at91_ohci",
  48. .id = -1,
  49. .dev = {
  50. .dma_mask = &ohci_dmamask,
  51. .coherent_dma_mask = DMA_BIT_MASK(32),
  52. .platform_data = &usbh_data,
  53. },
  54. .resource = usbh_resources,
  55. .num_resources = ARRAY_SIZE(usbh_resources),
  56. };
  57. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  58. {
  59. int i;
  60. if (!data)
  61. return;
  62. if (cpu_is_at91cap9_revB())
  63. set_irq_type(AT91CAP9_ID_UHP, IRQ_TYPE_LEVEL_HIGH);
  64. /* Enable VBus control for UHP ports */
  65. for (i = 0; i < data->ports; i++) {
  66. if (data->vbus_pin[i])
  67. at91_set_gpio_output(data->vbus_pin[i], 0);
  68. }
  69. usbh_data = *data;
  70. platform_device_register(&at91_usbh_device);
  71. }
  72. #else
  73. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  74. #endif
  75. /* --------------------------------------------------------------------
  76. * USB HS Device (Gadget)
  77. * -------------------------------------------------------------------- */
  78. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  79. static struct resource usba_udc_resources[] = {
  80. [0] = {
  81. .start = AT91CAP9_UDPHS_FIFO,
  82. .end = AT91CAP9_UDPHS_FIFO + SZ_512K - 1,
  83. .flags = IORESOURCE_MEM,
  84. },
  85. [1] = {
  86. .start = AT91CAP9_BASE_UDPHS,
  87. .end = AT91CAP9_BASE_UDPHS + SZ_1K - 1,
  88. .flags = IORESOURCE_MEM,
  89. },
  90. [2] = {
  91. .start = AT91CAP9_ID_UDPHS,
  92. .end = AT91CAP9_ID_UDPHS,
  93. .flags = IORESOURCE_IRQ,
  94. },
  95. };
  96. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  97. [idx] = { \
  98. .name = nam, \
  99. .index = idx, \
  100. .fifo_size = maxpkt, \
  101. .nr_banks = maxbk, \
  102. .can_dma = dma, \
  103. .can_isoc = isoc, \
  104. }
  105. static struct usba_ep_data usba_udc_ep[] = {
  106. EP("ep0", 0, 64, 1, 0, 0),
  107. EP("ep1", 1, 1024, 3, 1, 1),
  108. EP("ep2", 2, 1024, 3, 1, 1),
  109. EP("ep3", 3, 1024, 2, 1, 1),
  110. EP("ep4", 4, 1024, 2, 1, 1),
  111. EP("ep5", 5, 1024, 2, 1, 0),
  112. EP("ep6", 6, 1024, 2, 1, 0),
  113. EP("ep7", 7, 1024, 2, 0, 0),
  114. };
  115. #undef EP
  116. /*
  117. * pdata doesn't have room for any endpoints, so we need to
  118. * append room for the ones we need right after it.
  119. */
  120. static struct {
  121. struct usba_platform_data pdata;
  122. struct usba_ep_data ep[8];
  123. } usba_udc_data;
  124. static struct platform_device at91_usba_udc_device = {
  125. .name = "atmel_usba_udc",
  126. .id = -1,
  127. .dev = {
  128. .platform_data = &usba_udc_data.pdata,
  129. },
  130. .resource = usba_udc_resources,
  131. .num_resources = ARRAY_SIZE(usba_udc_resources),
  132. };
  133. void __init at91_add_device_usba(struct usba_platform_data *data)
  134. {
  135. if (cpu_is_at91cap9_revB()) {
  136. set_irq_type(AT91CAP9_ID_UDPHS, IRQ_TYPE_LEVEL_HIGH);
  137. at91_sys_write(AT91_MATRIX_UDPHS, AT91_MATRIX_SELECT_UDPHS |
  138. AT91_MATRIX_UDPHS_BYPASS_LOCK);
  139. }
  140. else
  141. at91_sys_write(AT91_MATRIX_UDPHS, AT91_MATRIX_SELECT_UDPHS);
  142. /*
  143. * Invalid pins are 0 on AT91, but the usba driver is shared
  144. * with AVR32, which use negative values instead. Once/if
  145. * gpio_is_valid() is ported to AT91, revisit this code.
  146. */
  147. usba_udc_data.pdata.vbus_pin = -EINVAL;
  148. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  149. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  150. if (data && data->vbus_pin > 0) {
  151. at91_set_gpio_input(data->vbus_pin, 0);
  152. at91_set_deglitch(data->vbus_pin, 1);
  153. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  154. }
  155. /* Pullup pin is handled internally by USB device peripheral */
  156. /* Clocks */
  157. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  158. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  159. platform_device_register(&at91_usba_udc_device);
  160. }
  161. #else
  162. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  163. #endif
  164. /* --------------------------------------------------------------------
  165. * Ethernet
  166. * -------------------------------------------------------------------- */
  167. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  168. static u64 eth_dmamask = DMA_BIT_MASK(32);
  169. static struct at91_eth_data eth_data;
  170. static struct resource eth_resources[] = {
  171. [0] = {
  172. .start = AT91CAP9_BASE_EMAC,
  173. .end = AT91CAP9_BASE_EMAC + SZ_16K - 1,
  174. .flags = IORESOURCE_MEM,
  175. },
  176. [1] = {
  177. .start = AT91CAP9_ID_EMAC,
  178. .end = AT91CAP9_ID_EMAC,
  179. .flags = IORESOURCE_IRQ,
  180. },
  181. };
  182. static struct platform_device at91cap9_eth_device = {
  183. .name = "macb",
  184. .id = -1,
  185. .dev = {
  186. .dma_mask = &eth_dmamask,
  187. .coherent_dma_mask = DMA_BIT_MASK(32),
  188. .platform_data = &eth_data,
  189. },
  190. .resource = eth_resources,
  191. .num_resources = ARRAY_SIZE(eth_resources),
  192. };
  193. void __init at91_add_device_eth(struct at91_eth_data *data)
  194. {
  195. if (!data)
  196. return;
  197. if (data->phy_irq_pin) {
  198. at91_set_gpio_input(data->phy_irq_pin, 0);
  199. at91_set_deglitch(data->phy_irq_pin, 1);
  200. }
  201. /* Pins used for MII and RMII */
  202. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  203. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  204. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  205. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  206. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  207. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  208. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  209. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  210. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  211. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  212. if (!data->is_rmii) {
  213. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  214. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  215. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  216. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  217. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  218. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  219. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  220. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  221. }
  222. eth_data = *data;
  223. platform_device_register(&at91cap9_eth_device);
  224. }
  225. #else
  226. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  227. #endif
  228. /* --------------------------------------------------------------------
  229. * MMC / SD
  230. * -------------------------------------------------------------------- */
  231. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  232. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  233. static struct at91_mmc_data mmc0_data, mmc1_data;
  234. static struct resource mmc0_resources[] = {
  235. [0] = {
  236. .start = AT91CAP9_BASE_MCI0,
  237. .end = AT91CAP9_BASE_MCI0 + SZ_16K - 1,
  238. .flags = IORESOURCE_MEM,
  239. },
  240. [1] = {
  241. .start = AT91CAP9_ID_MCI0,
  242. .end = AT91CAP9_ID_MCI0,
  243. .flags = IORESOURCE_IRQ,
  244. },
  245. };
  246. static struct platform_device at91cap9_mmc0_device = {
  247. .name = "at91_mci",
  248. .id = 0,
  249. .dev = {
  250. .dma_mask = &mmc_dmamask,
  251. .coherent_dma_mask = DMA_BIT_MASK(32),
  252. .platform_data = &mmc0_data,
  253. },
  254. .resource = mmc0_resources,
  255. .num_resources = ARRAY_SIZE(mmc0_resources),
  256. };
  257. static struct resource mmc1_resources[] = {
  258. [0] = {
  259. .start = AT91CAP9_BASE_MCI1,
  260. .end = AT91CAP9_BASE_MCI1 + SZ_16K - 1,
  261. .flags = IORESOURCE_MEM,
  262. },
  263. [1] = {
  264. .start = AT91CAP9_ID_MCI1,
  265. .end = AT91CAP9_ID_MCI1,
  266. .flags = IORESOURCE_IRQ,
  267. },
  268. };
  269. static struct platform_device at91cap9_mmc1_device = {
  270. .name = "at91_mci",
  271. .id = 1,
  272. .dev = {
  273. .dma_mask = &mmc_dmamask,
  274. .coherent_dma_mask = DMA_BIT_MASK(32),
  275. .platform_data = &mmc1_data,
  276. },
  277. .resource = mmc1_resources,
  278. .num_resources = ARRAY_SIZE(mmc1_resources),
  279. };
  280. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  281. {
  282. if (!data)
  283. return;
  284. /* input/irq */
  285. if (data->det_pin) {
  286. at91_set_gpio_input(data->det_pin, 1);
  287. at91_set_deglitch(data->det_pin, 1);
  288. }
  289. if (data->wp_pin)
  290. at91_set_gpio_input(data->wp_pin, 1);
  291. if (data->vcc_pin)
  292. at91_set_gpio_output(data->vcc_pin, 0);
  293. if (mmc_id == 0) { /* MCI0 */
  294. /* CLK */
  295. at91_set_A_periph(AT91_PIN_PA2, 0);
  296. /* CMD */
  297. at91_set_A_periph(AT91_PIN_PA1, 1);
  298. /* DAT0, maybe DAT1..DAT3 */
  299. at91_set_A_periph(AT91_PIN_PA0, 1);
  300. if (data->wire4) {
  301. at91_set_A_periph(AT91_PIN_PA3, 1);
  302. at91_set_A_periph(AT91_PIN_PA4, 1);
  303. at91_set_A_periph(AT91_PIN_PA5, 1);
  304. }
  305. mmc0_data = *data;
  306. at91_clock_associate("mci0_clk", &at91cap9_mmc0_device.dev, "mci_clk");
  307. platform_device_register(&at91cap9_mmc0_device);
  308. } else { /* MCI1 */
  309. /* CLK */
  310. at91_set_A_periph(AT91_PIN_PA16, 0);
  311. /* CMD */
  312. at91_set_A_periph(AT91_PIN_PA17, 1);
  313. /* DAT0, maybe DAT1..DAT3 */
  314. at91_set_A_periph(AT91_PIN_PA18, 1);
  315. if (data->wire4) {
  316. at91_set_A_periph(AT91_PIN_PA19, 1);
  317. at91_set_A_periph(AT91_PIN_PA20, 1);
  318. at91_set_A_periph(AT91_PIN_PA21, 1);
  319. }
  320. mmc1_data = *data;
  321. at91_clock_associate("mci1_clk", &at91cap9_mmc1_device.dev, "mci_clk");
  322. platform_device_register(&at91cap9_mmc1_device);
  323. }
  324. }
  325. #else
  326. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  327. #endif
  328. /* --------------------------------------------------------------------
  329. * NAND / SmartMedia
  330. * -------------------------------------------------------------------- */
  331. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  332. static struct atmel_nand_data nand_data;
  333. #define NAND_BASE AT91_CHIPSELECT_3
  334. static struct resource nand_resources[] = {
  335. [0] = {
  336. .start = NAND_BASE,
  337. .end = NAND_BASE + SZ_256M - 1,
  338. .flags = IORESOURCE_MEM,
  339. },
  340. [1] = {
  341. .start = AT91_BASE_SYS + AT91_ECC,
  342. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  343. .flags = IORESOURCE_MEM,
  344. }
  345. };
  346. static struct platform_device at91cap9_nand_device = {
  347. .name = "atmel_nand",
  348. .id = -1,
  349. .dev = {
  350. .platform_data = &nand_data,
  351. },
  352. .resource = nand_resources,
  353. .num_resources = ARRAY_SIZE(nand_resources),
  354. };
  355. void __init at91_add_device_nand(struct atmel_nand_data *data)
  356. {
  357. unsigned long csa;
  358. if (!data)
  359. return;
  360. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  361. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
  362. /* enable pin */
  363. if (data->enable_pin)
  364. at91_set_gpio_output(data->enable_pin, 1);
  365. /* ready/busy pin */
  366. if (data->rdy_pin)
  367. at91_set_gpio_input(data->rdy_pin, 1);
  368. /* card detect pin */
  369. if (data->det_pin)
  370. at91_set_gpio_input(data->det_pin, 1);
  371. nand_data = *data;
  372. platform_device_register(&at91cap9_nand_device);
  373. }
  374. #else
  375. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  376. #endif
  377. /* --------------------------------------------------------------------
  378. * TWI (i2c)
  379. * -------------------------------------------------------------------- */
  380. /*
  381. * Prefer the GPIO code since the TWI controller isn't robust
  382. * (gets overruns and underruns under load) and can only issue
  383. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  384. */
  385. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  386. static struct i2c_gpio_platform_data pdata = {
  387. .sda_pin = AT91_PIN_PB4,
  388. .sda_is_open_drain = 1,
  389. .scl_pin = AT91_PIN_PB5,
  390. .scl_is_open_drain = 1,
  391. .udelay = 2, /* ~100 kHz */
  392. };
  393. static struct platform_device at91cap9_twi_device = {
  394. .name = "i2c-gpio",
  395. .id = -1,
  396. .dev.platform_data = &pdata,
  397. };
  398. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  399. {
  400. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  401. at91_set_multi_drive(AT91_PIN_PB4, 1);
  402. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  403. at91_set_multi_drive(AT91_PIN_PB5, 1);
  404. i2c_register_board_info(0, devices, nr_devices);
  405. platform_device_register(&at91cap9_twi_device);
  406. }
  407. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  408. static struct resource twi_resources[] = {
  409. [0] = {
  410. .start = AT91CAP9_BASE_TWI,
  411. .end = AT91CAP9_BASE_TWI + SZ_16K - 1,
  412. .flags = IORESOURCE_MEM,
  413. },
  414. [1] = {
  415. .start = AT91CAP9_ID_TWI,
  416. .end = AT91CAP9_ID_TWI,
  417. .flags = IORESOURCE_IRQ,
  418. },
  419. };
  420. static struct platform_device at91cap9_twi_device = {
  421. .name = "at91_i2c",
  422. .id = -1,
  423. .resource = twi_resources,
  424. .num_resources = ARRAY_SIZE(twi_resources),
  425. };
  426. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  427. {
  428. /* pins used for TWI interface */
  429. at91_set_B_periph(AT91_PIN_PB4, 0); /* TWD */
  430. at91_set_multi_drive(AT91_PIN_PB4, 1);
  431. at91_set_B_periph(AT91_PIN_PB5, 0); /* TWCK */
  432. at91_set_multi_drive(AT91_PIN_PB5, 1);
  433. i2c_register_board_info(0, devices, nr_devices);
  434. platform_device_register(&at91cap9_twi_device);
  435. }
  436. #else
  437. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  438. #endif
  439. /* --------------------------------------------------------------------
  440. * SPI
  441. * -------------------------------------------------------------------- */
  442. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  443. static u64 spi_dmamask = DMA_BIT_MASK(32);
  444. static struct resource spi0_resources[] = {
  445. [0] = {
  446. .start = AT91CAP9_BASE_SPI0,
  447. .end = AT91CAP9_BASE_SPI0 + SZ_16K - 1,
  448. .flags = IORESOURCE_MEM,
  449. },
  450. [1] = {
  451. .start = AT91CAP9_ID_SPI0,
  452. .end = AT91CAP9_ID_SPI0,
  453. .flags = IORESOURCE_IRQ,
  454. },
  455. };
  456. static struct platform_device at91cap9_spi0_device = {
  457. .name = "atmel_spi",
  458. .id = 0,
  459. .dev = {
  460. .dma_mask = &spi_dmamask,
  461. .coherent_dma_mask = DMA_BIT_MASK(32),
  462. },
  463. .resource = spi0_resources,
  464. .num_resources = ARRAY_SIZE(spi0_resources),
  465. };
  466. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PD0, AT91_PIN_PD1 };
  467. static struct resource spi1_resources[] = {
  468. [0] = {
  469. .start = AT91CAP9_BASE_SPI1,
  470. .end = AT91CAP9_BASE_SPI1 + SZ_16K - 1,
  471. .flags = IORESOURCE_MEM,
  472. },
  473. [1] = {
  474. .start = AT91CAP9_ID_SPI1,
  475. .end = AT91CAP9_ID_SPI1,
  476. .flags = IORESOURCE_IRQ,
  477. },
  478. };
  479. static struct platform_device at91cap9_spi1_device = {
  480. .name = "atmel_spi",
  481. .id = 1,
  482. .dev = {
  483. .dma_mask = &spi_dmamask,
  484. .coherent_dma_mask = DMA_BIT_MASK(32),
  485. },
  486. .resource = spi1_resources,
  487. .num_resources = ARRAY_SIZE(spi1_resources),
  488. };
  489. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  490. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  491. {
  492. int i;
  493. unsigned long cs_pin;
  494. short enable_spi0 = 0;
  495. short enable_spi1 = 0;
  496. /* Choose SPI chip-selects */
  497. for (i = 0; i < nr_devices; i++) {
  498. if (devices[i].controller_data)
  499. cs_pin = (unsigned long) devices[i].controller_data;
  500. else if (devices[i].bus_num == 0)
  501. cs_pin = spi0_standard_cs[devices[i].chip_select];
  502. else
  503. cs_pin = spi1_standard_cs[devices[i].chip_select];
  504. if (devices[i].bus_num == 0)
  505. enable_spi0 = 1;
  506. else
  507. enable_spi1 = 1;
  508. /* enable chip-select pin */
  509. at91_set_gpio_output(cs_pin, 1);
  510. /* pass chip-select pin to driver */
  511. devices[i].controller_data = (void *) cs_pin;
  512. }
  513. spi_register_board_info(devices, nr_devices);
  514. /* Configure SPI bus(es) */
  515. if (enable_spi0) {
  516. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  517. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  518. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  519. at91_clock_associate("spi0_clk", &at91cap9_spi0_device.dev, "spi_clk");
  520. platform_device_register(&at91cap9_spi0_device);
  521. }
  522. if (enable_spi1) {
  523. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  524. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  525. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  526. at91_clock_associate("spi1_clk", &at91cap9_spi1_device.dev, "spi_clk");
  527. platform_device_register(&at91cap9_spi1_device);
  528. }
  529. }
  530. #else
  531. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  532. #endif
  533. /* --------------------------------------------------------------------
  534. * Timer/Counter block
  535. * -------------------------------------------------------------------- */
  536. #ifdef CONFIG_ATMEL_TCLIB
  537. static struct resource tcb_resources[] = {
  538. [0] = {
  539. .start = AT91CAP9_BASE_TCB0,
  540. .end = AT91CAP9_BASE_TCB0 + SZ_16K - 1,
  541. .flags = IORESOURCE_MEM,
  542. },
  543. [1] = {
  544. .start = AT91CAP9_ID_TCB,
  545. .end = AT91CAP9_ID_TCB,
  546. .flags = IORESOURCE_IRQ,
  547. },
  548. };
  549. static struct platform_device at91cap9_tcb_device = {
  550. .name = "atmel_tcb",
  551. .id = 0,
  552. .resource = tcb_resources,
  553. .num_resources = ARRAY_SIZE(tcb_resources),
  554. };
  555. static void __init at91_add_device_tc(void)
  556. {
  557. /* this chip has one clock and irq for all three TC channels */
  558. at91_clock_associate("tcb_clk", &at91cap9_tcb_device.dev, "t0_clk");
  559. platform_device_register(&at91cap9_tcb_device);
  560. }
  561. #else
  562. static void __init at91_add_device_tc(void) { }
  563. #endif
  564. /* --------------------------------------------------------------------
  565. * RTT
  566. * -------------------------------------------------------------------- */
  567. static struct resource rtt_resources[] = {
  568. {
  569. .start = AT91_BASE_SYS + AT91_RTT,
  570. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  571. .flags = IORESOURCE_MEM,
  572. }
  573. };
  574. static struct platform_device at91cap9_rtt_device = {
  575. .name = "at91_rtt",
  576. .id = 0,
  577. .resource = rtt_resources,
  578. .num_resources = ARRAY_SIZE(rtt_resources),
  579. };
  580. static void __init at91_add_device_rtt(void)
  581. {
  582. platform_device_register(&at91cap9_rtt_device);
  583. }
  584. /* --------------------------------------------------------------------
  585. * Watchdog
  586. * -------------------------------------------------------------------- */
  587. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  588. static struct platform_device at91cap9_wdt_device = {
  589. .name = "at91_wdt",
  590. .id = -1,
  591. .num_resources = 0,
  592. };
  593. static void __init at91_add_device_watchdog(void)
  594. {
  595. platform_device_register(&at91cap9_wdt_device);
  596. }
  597. #else
  598. static void __init at91_add_device_watchdog(void) {}
  599. #endif
  600. /* --------------------------------------------------------------------
  601. * PWM
  602. * --------------------------------------------------------------------*/
  603. #if defined(CONFIG_ATMEL_PWM)
  604. static u32 pwm_mask;
  605. static struct resource pwm_resources[] = {
  606. [0] = {
  607. .start = AT91CAP9_BASE_PWMC,
  608. .end = AT91CAP9_BASE_PWMC + SZ_16K - 1,
  609. .flags = IORESOURCE_MEM,
  610. },
  611. [1] = {
  612. .start = AT91CAP9_ID_PWMC,
  613. .end = AT91CAP9_ID_PWMC,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. };
  617. static struct platform_device at91cap9_pwm0_device = {
  618. .name = "atmel_pwm",
  619. .id = -1,
  620. .dev = {
  621. .platform_data = &pwm_mask,
  622. },
  623. .resource = pwm_resources,
  624. .num_resources = ARRAY_SIZE(pwm_resources),
  625. };
  626. void __init at91_add_device_pwm(u32 mask)
  627. {
  628. if (mask & (1 << AT91_PWM0))
  629. at91_set_A_periph(AT91_PIN_PB19, 1); /* enable PWM0 */
  630. if (mask & (1 << AT91_PWM1))
  631. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
  632. if (mask & (1 << AT91_PWM2))
  633. at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
  634. if (mask & (1 << AT91_PWM3))
  635. at91_set_B_periph(AT91_PIN_PA11, 1); /* enable PWM3 */
  636. pwm_mask = mask;
  637. platform_device_register(&at91cap9_pwm0_device);
  638. }
  639. #else
  640. void __init at91_add_device_pwm(u32 mask) {}
  641. #endif
  642. /* --------------------------------------------------------------------
  643. * AC97
  644. * -------------------------------------------------------------------- */
  645. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  646. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  647. static struct atmel_ac97_data ac97_data;
  648. static struct resource ac97_resources[] = {
  649. [0] = {
  650. .start = AT91CAP9_BASE_AC97C,
  651. .end = AT91CAP9_BASE_AC97C + SZ_16K - 1,
  652. .flags = IORESOURCE_MEM,
  653. },
  654. [1] = {
  655. .start = AT91CAP9_ID_AC97C,
  656. .end = AT91CAP9_ID_AC97C,
  657. .flags = IORESOURCE_IRQ,
  658. },
  659. };
  660. static struct platform_device at91cap9_ac97_device = {
  661. .name = "ac97c",
  662. .id = 1,
  663. .dev = {
  664. .dma_mask = &ac97_dmamask,
  665. .coherent_dma_mask = DMA_BIT_MASK(32),
  666. .platform_data = &ac97_data,
  667. },
  668. .resource = ac97_resources,
  669. .num_resources = ARRAY_SIZE(ac97_resources),
  670. };
  671. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  672. {
  673. if (!data)
  674. return;
  675. at91_set_A_periph(AT91_PIN_PA6, 0); /* AC97FS */
  676. at91_set_A_periph(AT91_PIN_PA7, 0); /* AC97CK */
  677. at91_set_A_periph(AT91_PIN_PA8, 0); /* AC97TX */
  678. at91_set_A_periph(AT91_PIN_PA9, 0); /* AC97RX */
  679. /* reset */
  680. if (data->reset_pin)
  681. at91_set_gpio_output(data->reset_pin, 0);
  682. ac97_data = *data;
  683. platform_device_register(&at91cap9_ac97_device);
  684. }
  685. #else
  686. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  687. #endif
  688. /* --------------------------------------------------------------------
  689. * LCD Controller
  690. * -------------------------------------------------------------------- */
  691. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  692. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  693. static struct atmel_lcdfb_info lcdc_data;
  694. static struct resource lcdc_resources[] = {
  695. [0] = {
  696. .start = AT91CAP9_LCDC_BASE,
  697. .end = AT91CAP9_LCDC_BASE + SZ_4K - 1,
  698. .flags = IORESOURCE_MEM,
  699. },
  700. [1] = {
  701. .start = AT91CAP9_ID_LCDC,
  702. .end = AT91CAP9_ID_LCDC,
  703. .flags = IORESOURCE_IRQ,
  704. },
  705. };
  706. static struct platform_device at91_lcdc_device = {
  707. .name = "atmel_lcdfb",
  708. .id = 0,
  709. .dev = {
  710. .dma_mask = &lcdc_dmamask,
  711. .coherent_dma_mask = DMA_BIT_MASK(32),
  712. .platform_data = &lcdc_data,
  713. },
  714. .resource = lcdc_resources,
  715. .num_resources = ARRAY_SIZE(lcdc_resources),
  716. };
  717. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  718. {
  719. if (!data)
  720. return;
  721. if (cpu_is_at91cap9_revB())
  722. set_irq_type(AT91CAP9_ID_LCDC, IRQ_TYPE_LEVEL_HIGH);
  723. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  724. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  725. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  726. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  727. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  728. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  729. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  730. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  731. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  732. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  733. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  734. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  735. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  736. at91_set_A_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  737. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  738. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  739. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  740. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  741. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  742. at91_set_A_periph(AT91_PIN_PC25, 0); /* LCDD21 */
  743. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  744. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  745. lcdc_data = *data;
  746. platform_device_register(&at91_lcdc_device);
  747. }
  748. #else
  749. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  750. #endif
  751. /* --------------------------------------------------------------------
  752. * SSC -- Synchronous Serial Controller
  753. * -------------------------------------------------------------------- */
  754. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  755. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  756. static struct resource ssc0_resources[] = {
  757. [0] = {
  758. .start = AT91CAP9_BASE_SSC0,
  759. .end = AT91CAP9_BASE_SSC0 + SZ_16K - 1,
  760. .flags = IORESOURCE_MEM,
  761. },
  762. [1] = {
  763. .start = AT91CAP9_ID_SSC0,
  764. .end = AT91CAP9_ID_SSC0,
  765. .flags = IORESOURCE_IRQ,
  766. },
  767. };
  768. static struct platform_device at91cap9_ssc0_device = {
  769. .name = "ssc",
  770. .id = 0,
  771. .dev = {
  772. .dma_mask = &ssc0_dmamask,
  773. .coherent_dma_mask = DMA_BIT_MASK(32),
  774. },
  775. .resource = ssc0_resources,
  776. .num_resources = ARRAY_SIZE(ssc0_resources),
  777. };
  778. static inline void configure_ssc0_pins(unsigned pins)
  779. {
  780. if (pins & ATMEL_SSC_TF)
  781. at91_set_A_periph(AT91_PIN_PB0, 1);
  782. if (pins & ATMEL_SSC_TK)
  783. at91_set_A_periph(AT91_PIN_PB1, 1);
  784. if (pins & ATMEL_SSC_TD)
  785. at91_set_A_periph(AT91_PIN_PB2, 1);
  786. if (pins & ATMEL_SSC_RD)
  787. at91_set_A_periph(AT91_PIN_PB3, 1);
  788. if (pins & ATMEL_SSC_RK)
  789. at91_set_A_periph(AT91_PIN_PB4, 1);
  790. if (pins & ATMEL_SSC_RF)
  791. at91_set_A_periph(AT91_PIN_PB5, 1);
  792. }
  793. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  794. static struct resource ssc1_resources[] = {
  795. [0] = {
  796. .start = AT91CAP9_BASE_SSC1,
  797. .end = AT91CAP9_BASE_SSC1 + SZ_16K - 1,
  798. .flags = IORESOURCE_MEM,
  799. },
  800. [1] = {
  801. .start = AT91CAP9_ID_SSC1,
  802. .end = AT91CAP9_ID_SSC1,
  803. .flags = IORESOURCE_IRQ,
  804. },
  805. };
  806. static struct platform_device at91cap9_ssc1_device = {
  807. .name = "ssc",
  808. .id = 1,
  809. .dev = {
  810. .dma_mask = &ssc1_dmamask,
  811. .coherent_dma_mask = DMA_BIT_MASK(32),
  812. },
  813. .resource = ssc1_resources,
  814. .num_resources = ARRAY_SIZE(ssc1_resources),
  815. };
  816. static inline void configure_ssc1_pins(unsigned pins)
  817. {
  818. if (pins & ATMEL_SSC_TF)
  819. at91_set_A_periph(AT91_PIN_PB6, 1);
  820. if (pins & ATMEL_SSC_TK)
  821. at91_set_A_periph(AT91_PIN_PB7, 1);
  822. if (pins & ATMEL_SSC_TD)
  823. at91_set_A_periph(AT91_PIN_PB8, 1);
  824. if (pins & ATMEL_SSC_RD)
  825. at91_set_A_periph(AT91_PIN_PB9, 1);
  826. if (pins & ATMEL_SSC_RK)
  827. at91_set_A_periph(AT91_PIN_PB10, 1);
  828. if (pins & ATMEL_SSC_RF)
  829. at91_set_A_periph(AT91_PIN_PB11, 1);
  830. }
  831. /*
  832. * SSC controllers are accessed through library code, instead of any
  833. * kind of all-singing/all-dancing driver. For example one could be
  834. * used by a particular I2S audio codec's driver, while another one
  835. * on the same system might be used by a custom data capture driver.
  836. */
  837. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  838. {
  839. struct platform_device *pdev;
  840. /*
  841. * NOTE: caller is responsible for passing information matching
  842. * "pins" to whatever will be using each particular controller.
  843. */
  844. switch (id) {
  845. case AT91CAP9_ID_SSC0:
  846. pdev = &at91cap9_ssc0_device;
  847. configure_ssc0_pins(pins);
  848. at91_clock_associate("ssc0_clk", &pdev->dev, "ssc");
  849. break;
  850. case AT91CAP9_ID_SSC1:
  851. pdev = &at91cap9_ssc1_device;
  852. configure_ssc1_pins(pins);
  853. at91_clock_associate("ssc1_clk", &pdev->dev, "ssc");
  854. break;
  855. default:
  856. return;
  857. }
  858. platform_device_register(pdev);
  859. }
  860. #else
  861. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  862. #endif
  863. /* --------------------------------------------------------------------
  864. * UART
  865. * -------------------------------------------------------------------- */
  866. #if defined(CONFIG_SERIAL_ATMEL)
  867. static struct resource dbgu_resources[] = {
  868. [0] = {
  869. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  870. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  871. .flags = IORESOURCE_MEM,
  872. },
  873. [1] = {
  874. .start = AT91_ID_SYS,
  875. .end = AT91_ID_SYS,
  876. .flags = IORESOURCE_IRQ,
  877. },
  878. };
  879. static struct atmel_uart_data dbgu_data = {
  880. .use_dma_tx = 0,
  881. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  882. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  883. };
  884. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  885. static struct platform_device at91cap9_dbgu_device = {
  886. .name = "atmel_usart",
  887. .id = 0,
  888. .dev = {
  889. .dma_mask = &dbgu_dmamask,
  890. .coherent_dma_mask = DMA_BIT_MASK(32),
  891. .platform_data = &dbgu_data,
  892. },
  893. .resource = dbgu_resources,
  894. .num_resources = ARRAY_SIZE(dbgu_resources),
  895. };
  896. static inline void configure_dbgu_pins(void)
  897. {
  898. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  899. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  900. }
  901. static struct resource uart0_resources[] = {
  902. [0] = {
  903. .start = AT91CAP9_BASE_US0,
  904. .end = AT91CAP9_BASE_US0 + SZ_16K - 1,
  905. .flags = IORESOURCE_MEM,
  906. },
  907. [1] = {
  908. .start = AT91CAP9_ID_US0,
  909. .end = AT91CAP9_ID_US0,
  910. .flags = IORESOURCE_IRQ,
  911. },
  912. };
  913. static struct atmel_uart_data uart0_data = {
  914. .use_dma_tx = 1,
  915. .use_dma_rx = 1,
  916. };
  917. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  918. static struct platform_device at91cap9_uart0_device = {
  919. .name = "atmel_usart",
  920. .id = 1,
  921. .dev = {
  922. .dma_mask = &uart0_dmamask,
  923. .coherent_dma_mask = DMA_BIT_MASK(32),
  924. .platform_data = &uart0_data,
  925. },
  926. .resource = uart0_resources,
  927. .num_resources = ARRAY_SIZE(uart0_resources),
  928. };
  929. static inline void configure_usart0_pins(unsigned pins)
  930. {
  931. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  932. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  933. if (pins & ATMEL_UART_RTS)
  934. at91_set_A_periph(AT91_PIN_PA24, 0); /* RTS0 */
  935. if (pins & ATMEL_UART_CTS)
  936. at91_set_A_periph(AT91_PIN_PA25, 0); /* CTS0 */
  937. }
  938. static struct resource uart1_resources[] = {
  939. [0] = {
  940. .start = AT91CAP9_BASE_US1,
  941. .end = AT91CAP9_BASE_US1 + SZ_16K - 1,
  942. .flags = IORESOURCE_MEM,
  943. },
  944. [1] = {
  945. .start = AT91CAP9_ID_US1,
  946. .end = AT91CAP9_ID_US1,
  947. .flags = IORESOURCE_IRQ,
  948. },
  949. };
  950. static struct atmel_uart_data uart1_data = {
  951. .use_dma_tx = 1,
  952. .use_dma_rx = 1,
  953. };
  954. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  955. static struct platform_device at91cap9_uart1_device = {
  956. .name = "atmel_usart",
  957. .id = 2,
  958. .dev = {
  959. .dma_mask = &uart1_dmamask,
  960. .coherent_dma_mask = DMA_BIT_MASK(32),
  961. .platform_data = &uart1_data,
  962. },
  963. .resource = uart1_resources,
  964. .num_resources = ARRAY_SIZE(uart1_resources),
  965. };
  966. static inline void configure_usart1_pins(unsigned pins)
  967. {
  968. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  969. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  970. if (pins & ATMEL_UART_RTS)
  971. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  972. if (pins & ATMEL_UART_CTS)
  973. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  974. }
  975. static struct resource uart2_resources[] = {
  976. [0] = {
  977. .start = AT91CAP9_BASE_US2,
  978. .end = AT91CAP9_BASE_US2 + SZ_16K - 1,
  979. .flags = IORESOURCE_MEM,
  980. },
  981. [1] = {
  982. .start = AT91CAP9_ID_US2,
  983. .end = AT91CAP9_ID_US2,
  984. .flags = IORESOURCE_IRQ,
  985. },
  986. };
  987. static struct atmel_uart_data uart2_data = {
  988. .use_dma_tx = 1,
  989. .use_dma_rx = 1,
  990. };
  991. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  992. static struct platform_device at91cap9_uart2_device = {
  993. .name = "atmel_usart",
  994. .id = 3,
  995. .dev = {
  996. .dma_mask = &uart2_dmamask,
  997. .coherent_dma_mask = DMA_BIT_MASK(32),
  998. .platform_data = &uart2_data,
  999. },
  1000. .resource = uart2_resources,
  1001. .num_resources = ARRAY_SIZE(uart2_resources),
  1002. };
  1003. static inline void configure_usart2_pins(unsigned pins)
  1004. {
  1005. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  1006. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  1007. if (pins & ATMEL_UART_RTS)
  1008. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  1009. if (pins & ATMEL_UART_CTS)
  1010. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  1011. }
  1012. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1013. struct platform_device *atmel_default_console_device; /* the serial console device */
  1014. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1015. {
  1016. struct platform_device *pdev;
  1017. switch (id) {
  1018. case 0: /* DBGU */
  1019. pdev = &at91cap9_dbgu_device;
  1020. configure_dbgu_pins();
  1021. at91_clock_associate("mck", &pdev->dev, "usart");
  1022. break;
  1023. case AT91CAP9_ID_US0:
  1024. pdev = &at91cap9_uart0_device;
  1025. configure_usart0_pins(pins);
  1026. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  1027. break;
  1028. case AT91CAP9_ID_US1:
  1029. pdev = &at91cap9_uart1_device;
  1030. configure_usart1_pins(pins);
  1031. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  1032. break;
  1033. case AT91CAP9_ID_US2:
  1034. pdev = &at91cap9_uart2_device;
  1035. configure_usart2_pins(pins);
  1036. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  1037. break;
  1038. default:
  1039. return;
  1040. }
  1041. pdev->id = portnr; /* update to mapped ID */
  1042. if (portnr < ATMEL_MAX_UART)
  1043. at91_uarts[portnr] = pdev;
  1044. }
  1045. void __init at91_set_serial_console(unsigned portnr)
  1046. {
  1047. if (portnr < ATMEL_MAX_UART)
  1048. atmel_default_console_device = at91_uarts[portnr];
  1049. }
  1050. void __init at91_add_device_serial(void)
  1051. {
  1052. int i;
  1053. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1054. if (at91_uarts[i])
  1055. platform_device_register(at91_uarts[i]);
  1056. }
  1057. if (!atmel_default_console_device)
  1058. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1059. }
  1060. #else
  1061. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1062. void __init at91_set_serial_console(unsigned portnr) {}
  1063. void __init at91_add_device_serial(void) {}
  1064. #endif
  1065. /* -------------------------------------------------------------------- */
  1066. /*
  1067. * These devices are always present and don't need any board-specific
  1068. * setup.
  1069. */
  1070. static int __init at91_add_standard_devices(void)
  1071. {
  1072. at91_add_device_rtt();
  1073. at91_add_device_watchdog();
  1074. at91_add_device_tc();
  1075. return 0;
  1076. }
  1077. arch_initcall(at91_add_standard_devices);