at91sam9g45_devices.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  1. /*
  2. * On-Chip devices setup code for the AT91SAM9G45 family
  3. *
  4. * Copyright (C) 2009 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/at91sam9g45.h>
  22. #include <mach/at91sam9g45_matrix.h>
  23. #include <mach/at91sam9_smc.h>
  24. #include <mach/at_hdmac.h>
  25. #include "generic.h"
  26. /* --------------------------------------------------------------------
  27. * HDMAC - AHB DMA Controller
  28. * -------------------------------------------------------------------- */
  29. #if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
  30. static u64 hdmac_dmamask = DMA_BIT_MASK(32);
  31. static struct at_dma_platform_data atdma_pdata = {
  32. .nr_channels = 8,
  33. };
  34. static struct resource hdmac_resources[] = {
  35. [0] = {
  36. .start = AT91_BASE_SYS + AT91_DMA,
  37. .end = AT91_BASE_SYS + AT91_DMA + SZ_512 - 1,
  38. .flags = IORESOURCE_MEM,
  39. },
  40. [2] = {
  41. .start = AT91SAM9G45_ID_DMA,
  42. .end = AT91SAM9G45_ID_DMA,
  43. .flags = IORESOURCE_IRQ,
  44. },
  45. };
  46. static struct platform_device at_hdmac_device = {
  47. .name = "at_hdmac",
  48. .id = -1,
  49. .dev = {
  50. .dma_mask = &hdmac_dmamask,
  51. .coherent_dma_mask = DMA_BIT_MASK(32),
  52. .platform_data = &atdma_pdata,
  53. },
  54. .resource = hdmac_resources,
  55. .num_resources = ARRAY_SIZE(hdmac_resources),
  56. };
  57. void __init at91_add_device_hdmac(void)
  58. {
  59. dma_cap_set(DMA_MEMCPY, atdma_pdata.cap_mask);
  60. dma_cap_set(DMA_SLAVE, atdma_pdata.cap_mask);
  61. platform_device_register(&at_hdmac_device);
  62. }
  63. #else
  64. void __init at91_add_device_hdmac(void) {}
  65. #endif
  66. /* --------------------------------------------------------------------
  67. * USB Host (OHCI)
  68. * -------------------------------------------------------------------- */
  69. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  70. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  71. static struct at91_usbh_data usbh_ohci_data;
  72. static struct resource usbh_ohci_resources[] = {
  73. [0] = {
  74. .start = AT91SAM9G45_OHCI_BASE,
  75. .end = AT91SAM9G45_OHCI_BASE + SZ_1M - 1,
  76. .flags = IORESOURCE_MEM,
  77. },
  78. [1] = {
  79. .start = AT91SAM9G45_ID_UHPHS,
  80. .end = AT91SAM9G45_ID_UHPHS,
  81. .flags = IORESOURCE_IRQ,
  82. },
  83. };
  84. static struct platform_device at91_usbh_ohci_device = {
  85. .name = "at91_ohci",
  86. .id = -1,
  87. .dev = {
  88. .dma_mask = &ohci_dmamask,
  89. .coherent_dma_mask = DMA_BIT_MASK(32),
  90. .platform_data = &usbh_ohci_data,
  91. },
  92. .resource = usbh_ohci_resources,
  93. .num_resources = ARRAY_SIZE(usbh_ohci_resources),
  94. };
  95. void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data)
  96. {
  97. int i;
  98. if (!data)
  99. return;
  100. /* Enable VBus control for UHP ports */
  101. for (i = 0; i < data->ports; i++) {
  102. if (data->vbus_pin[i])
  103. at91_set_gpio_output(data->vbus_pin[i], 0);
  104. }
  105. usbh_ohci_data = *data;
  106. platform_device_register(&at91_usbh_ohci_device);
  107. }
  108. #else
  109. void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data) {}
  110. #endif
  111. /* --------------------------------------------------------------------
  112. * USB HS Device (Gadget)
  113. * -------------------------------------------------------------------- */
  114. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  115. static struct resource usba_udc_resources[] = {
  116. [0] = {
  117. .start = AT91SAM9G45_UDPHS_FIFO,
  118. .end = AT91SAM9G45_UDPHS_FIFO + SZ_512K - 1,
  119. .flags = IORESOURCE_MEM,
  120. },
  121. [1] = {
  122. .start = AT91SAM9G45_BASE_UDPHS,
  123. .end = AT91SAM9G45_BASE_UDPHS + SZ_1K - 1,
  124. .flags = IORESOURCE_MEM,
  125. },
  126. [2] = {
  127. .start = AT91SAM9G45_ID_UDPHS,
  128. .end = AT91SAM9G45_ID_UDPHS,
  129. .flags = IORESOURCE_IRQ,
  130. },
  131. };
  132. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  133. [idx] = { \
  134. .name = nam, \
  135. .index = idx, \
  136. .fifo_size = maxpkt, \
  137. .nr_banks = maxbk, \
  138. .can_dma = dma, \
  139. .can_isoc = isoc, \
  140. }
  141. static struct usba_ep_data usba_udc_ep[] __initdata = {
  142. EP("ep0", 0, 64, 1, 0, 0),
  143. EP("ep1", 1, 1024, 2, 1, 1),
  144. EP("ep2", 2, 1024, 2, 1, 1),
  145. EP("ep3", 3, 1024, 3, 1, 0),
  146. EP("ep4", 4, 1024, 3, 1, 0),
  147. EP("ep5", 5, 1024, 3, 1, 1),
  148. EP("ep6", 6, 1024, 3, 1, 1),
  149. };
  150. #undef EP
  151. /*
  152. * pdata doesn't have room for any endpoints, so we need to
  153. * append room for the ones we need right after it.
  154. */
  155. static struct {
  156. struct usba_platform_data pdata;
  157. struct usba_ep_data ep[7];
  158. } usba_udc_data;
  159. static struct platform_device at91_usba_udc_device = {
  160. .name = "atmel_usba_udc",
  161. .id = -1,
  162. .dev = {
  163. .platform_data = &usba_udc_data.pdata,
  164. },
  165. .resource = usba_udc_resources,
  166. .num_resources = ARRAY_SIZE(usba_udc_resources),
  167. };
  168. void __init at91_add_device_usba(struct usba_platform_data *data)
  169. {
  170. usba_udc_data.pdata.vbus_pin = -EINVAL;
  171. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  172. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  173. if (data && data->vbus_pin > 0) {
  174. at91_set_gpio_input(data->vbus_pin, 0);
  175. at91_set_deglitch(data->vbus_pin, 1);
  176. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  177. }
  178. /* Pullup pin is handled internally by USB device peripheral */
  179. /* Clocks */
  180. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  181. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  182. platform_device_register(&at91_usba_udc_device);
  183. }
  184. #else
  185. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  186. #endif
  187. /* --------------------------------------------------------------------
  188. * Ethernet
  189. * -------------------------------------------------------------------- */
  190. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  191. static u64 eth_dmamask = DMA_BIT_MASK(32);
  192. static struct at91_eth_data eth_data;
  193. static struct resource eth_resources[] = {
  194. [0] = {
  195. .start = AT91SAM9G45_BASE_EMAC,
  196. .end = AT91SAM9G45_BASE_EMAC + SZ_16K - 1,
  197. .flags = IORESOURCE_MEM,
  198. },
  199. [1] = {
  200. .start = AT91SAM9G45_ID_EMAC,
  201. .end = AT91SAM9G45_ID_EMAC,
  202. .flags = IORESOURCE_IRQ,
  203. },
  204. };
  205. static struct platform_device at91sam9g45_eth_device = {
  206. .name = "macb",
  207. .id = -1,
  208. .dev = {
  209. .dma_mask = &eth_dmamask,
  210. .coherent_dma_mask = DMA_BIT_MASK(32),
  211. .platform_data = &eth_data,
  212. },
  213. .resource = eth_resources,
  214. .num_resources = ARRAY_SIZE(eth_resources),
  215. };
  216. void __init at91_add_device_eth(struct at91_eth_data *data)
  217. {
  218. if (!data)
  219. return;
  220. if (data->phy_irq_pin) {
  221. at91_set_gpio_input(data->phy_irq_pin, 0);
  222. at91_set_deglitch(data->phy_irq_pin, 1);
  223. }
  224. /* Pins used for MII and RMII */
  225. at91_set_A_periph(AT91_PIN_PA17, 0); /* ETXCK_EREFCK */
  226. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERXDV */
  227. at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
  228. at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
  229. at91_set_A_periph(AT91_PIN_PA16, 0); /* ERXER */
  230. at91_set_A_periph(AT91_PIN_PA14, 0); /* ETXEN */
  231. at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX0 */
  232. at91_set_A_periph(AT91_PIN_PA11, 0); /* ETX1 */
  233. at91_set_A_periph(AT91_PIN_PA19, 0); /* EMDIO */
  234. at91_set_A_periph(AT91_PIN_PA18, 0); /* EMDC */
  235. if (!data->is_rmii) {
  236. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECRS */
  237. at91_set_B_periph(AT91_PIN_PA30, 0); /* ECOL */
  238. at91_set_B_periph(AT91_PIN_PA8, 0); /* ERX2 */
  239. at91_set_B_periph(AT91_PIN_PA9, 0); /* ERX3 */
  240. at91_set_B_periph(AT91_PIN_PA28, 0); /* ERXCK */
  241. at91_set_B_periph(AT91_PIN_PA6, 0); /* ETX2 */
  242. at91_set_B_periph(AT91_PIN_PA7, 0); /* ETX3 */
  243. at91_set_B_periph(AT91_PIN_PA27, 0); /* ETXER */
  244. }
  245. eth_data = *data;
  246. platform_device_register(&at91sam9g45_eth_device);
  247. }
  248. #else
  249. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  250. #endif
  251. /* --------------------------------------------------------------------
  252. * NAND / SmartMedia
  253. * -------------------------------------------------------------------- */
  254. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  255. static struct atmel_nand_data nand_data;
  256. #define NAND_BASE AT91_CHIPSELECT_3
  257. static struct resource nand_resources[] = {
  258. [0] = {
  259. .start = NAND_BASE,
  260. .end = NAND_BASE + SZ_256M - 1,
  261. .flags = IORESOURCE_MEM,
  262. },
  263. [1] = {
  264. .start = AT91_BASE_SYS + AT91_ECC,
  265. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  266. .flags = IORESOURCE_MEM,
  267. }
  268. };
  269. static struct platform_device at91sam9g45_nand_device = {
  270. .name = "atmel_nand",
  271. .id = -1,
  272. .dev = {
  273. .platform_data = &nand_data,
  274. },
  275. .resource = nand_resources,
  276. .num_resources = ARRAY_SIZE(nand_resources),
  277. };
  278. void __init at91_add_device_nand(struct atmel_nand_data *data)
  279. {
  280. unsigned long csa;
  281. if (!data)
  282. return;
  283. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  284. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
  285. /* enable pin */
  286. if (data->enable_pin)
  287. at91_set_gpio_output(data->enable_pin, 1);
  288. /* ready/busy pin */
  289. if (data->rdy_pin)
  290. at91_set_gpio_input(data->rdy_pin, 1);
  291. /* card detect pin */
  292. if (data->det_pin)
  293. at91_set_gpio_input(data->det_pin, 1);
  294. nand_data = *data;
  295. platform_device_register(&at91sam9g45_nand_device);
  296. }
  297. #else
  298. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  299. #endif
  300. /* --------------------------------------------------------------------
  301. * TWI (i2c)
  302. * -------------------------------------------------------------------- */
  303. /*
  304. * Prefer the GPIO code since the TWI controller isn't robust
  305. * (gets overruns and underruns under load) and can only issue
  306. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  307. */
  308. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  309. static struct i2c_gpio_platform_data pdata_i2c0 = {
  310. .sda_pin = AT91_PIN_PA20,
  311. .sda_is_open_drain = 1,
  312. .scl_pin = AT91_PIN_PA21,
  313. .scl_is_open_drain = 1,
  314. .udelay = 2, /* ~100 kHz */
  315. };
  316. static struct platform_device at91sam9g45_twi0_device = {
  317. .name = "i2c-gpio",
  318. .id = 0,
  319. .dev.platform_data = &pdata_i2c0,
  320. };
  321. static struct i2c_gpio_platform_data pdata_i2c1 = {
  322. .sda_pin = AT91_PIN_PB10,
  323. .sda_is_open_drain = 1,
  324. .scl_pin = AT91_PIN_PB11,
  325. .scl_is_open_drain = 1,
  326. .udelay = 2, /* ~100 kHz */
  327. };
  328. static struct platform_device at91sam9g45_twi1_device = {
  329. .name = "i2c-gpio",
  330. .id = 1,
  331. .dev.platform_data = &pdata_i2c1,
  332. };
  333. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  334. {
  335. i2c_register_board_info(i2c_id, devices, nr_devices);
  336. if (i2c_id == 0) {
  337. at91_set_GPIO_periph(AT91_PIN_PA20, 1); /* TWD (SDA) */
  338. at91_set_multi_drive(AT91_PIN_PA20, 1);
  339. at91_set_GPIO_periph(AT91_PIN_PA21, 1); /* TWCK (SCL) */
  340. at91_set_multi_drive(AT91_PIN_PA21, 1);
  341. platform_device_register(&at91sam9g45_twi0_device);
  342. } else {
  343. at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* TWD (SDA) */
  344. at91_set_multi_drive(AT91_PIN_PB10, 1);
  345. at91_set_GPIO_periph(AT91_PIN_PB11, 1); /* TWCK (SCL) */
  346. at91_set_multi_drive(AT91_PIN_PB11, 1);
  347. platform_device_register(&at91sam9g45_twi1_device);
  348. }
  349. }
  350. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  351. static struct resource twi0_resources[] = {
  352. [0] = {
  353. .start = AT91SAM9G45_BASE_TWI0,
  354. .end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1,
  355. .flags = IORESOURCE_MEM,
  356. },
  357. [1] = {
  358. .start = AT91SAM9G45_ID_TWI0,
  359. .end = AT91SAM9G45_ID_TWI0,
  360. .flags = IORESOURCE_IRQ,
  361. },
  362. };
  363. static struct platform_device at91sam9g45_twi0_device = {
  364. .name = "at91_i2c",
  365. .id = 0,
  366. .resource = twi0_resources,
  367. .num_resources = ARRAY_SIZE(twi0_resources),
  368. };
  369. static struct resource twi1_resources[] = {
  370. [0] = {
  371. .start = AT91SAM9G45_BASE_TWI1,
  372. .end = AT91SAM9G45_BASE_TWI1 + SZ_16K - 1,
  373. .flags = IORESOURCE_MEM,
  374. },
  375. [1] = {
  376. .start = AT91SAM9G45_ID_TWI1,
  377. .end = AT91SAM9G45_ID_TWI1,
  378. .flags = IORESOURCE_IRQ,
  379. },
  380. };
  381. static struct platform_device at91sam9g45_twi1_device = {
  382. .name = "at91_i2c",
  383. .id = 1,
  384. .resource = twi1_resources,
  385. .num_resources = ARRAY_SIZE(twi1_resources),
  386. };
  387. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
  388. {
  389. i2c_register_board_info(i2c_id, devices, nr_devices);
  390. /* pins used for TWI interface */
  391. if (i2c_id == 0) {
  392. at91_set_A_periph(AT91_PIN_PA20, 0); /* TWD */
  393. at91_set_multi_drive(AT91_PIN_PA20, 1);
  394. at91_set_A_periph(AT91_PIN_PA21, 0); /* TWCK */
  395. at91_set_multi_drive(AT91_PIN_PA21, 1);
  396. platform_device_register(&at91sam9g45_twi0_device);
  397. } else {
  398. at91_set_A_periph(AT91_PIN_PB10, 0); /* TWD */
  399. at91_set_multi_drive(AT91_PIN_PB10, 1);
  400. at91_set_A_periph(AT91_PIN_PB11, 0); /* TWCK */
  401. at91_set_multi_drive(AT91_PIN_PB11, 1);
  402. platform_device_register(&at91sam9g45_twi1_device);
  403. }
  404. }
  405. #else
  406. void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {}
  407. #endif
  408. /* --------------------------------------------------------------------
  409. * SPI
  410. * -------------------------------------------------------------------- */
  411. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  412. static u64 spi_dmamask = DMA_BIT_MASK(32);
  413. static struct resource spi0_resources[] = {
  414. [0] = {
  415. .start = AT91SAM9G45_BASE_SPI0,
  416. .end = AT91SAM9G45_BASE_SPI0 + SZ_16K - 1,
  417. .flags = IORESOURCE_MEM,
  418. },
  419. [1] = {
  420. .start = AT91SAM9G45_ID_SPI0,
  421. .end = AT91SAM9G45_ID_SPI0,
  422. .flags = IORESOURCE_IRQ,
  423. },
  424. };
  425. static struct platform_device at91sam9g45_spi0_device = {
  426. .name = "atmel_spi",
  427. .id = 0,
  428. .dev = {
  429. .dma_mask = &spi_dmamask,
  430. .coherent_dma_mask = DMA_BIT_MASK(32),
  431. },
  432. .resource = spi0_resources,
  433. .num_resources = ARRAY_SIZE(spi0_resources),
  434. };
  435. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PB18, AT91_PIN_PB19, AT91_PIN_PD27 };
  436. static struct resource spi1_resources[] = {
  437. [0] = {
  438. .start = AT91SAM9G45_BASE_SPI1,
  439. .end = AT91SAM9G45_BASE_SPI1 + SZ_16K - 1,
  440. .flags = IORESOURCE_MEM,
  441. },
  442. [1] = {
  443. .start = AT91SAM9G45_ID_SPI1,
  444. .end = AT91SAM9G45_ID_SPI1,
  445. .flags = IORESOURCE_IRQ,
  446. },
  447. };
  448. static struct platform_device at91sam9g45_spi1_device = {
  449. .name = "atmel_spi",
  450. .id = 1,
  451. .dev = {
  452. .dma_mask = &spi_dmamask,
  453. .coherent_dma_mask = DMA_BIT_MASK(32),
  454. },
  455. .resource = spi1_resources,
  456. .num_resources = ARRAY_SIZE(spi1_resources),
  457. };
  458. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB17, AT91_PIN_PD28, AT91_PIN_PD18, AT91_PIN_PD19 };
  459. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  460. {
  461. int i;
  462. unsigned long cs_pin;
  463. short enable_spi0 = 0;
  464. short enable_spi1 = 0;
  465. /* Choose SPI chip-selects */
  466. for (i = 0; i < nr_devices; i++) {
  467. if (devices[i].controller_data)
  468. cs_pin = (unsigned long) devices[i].controller_data;
  469. else if (devices[i].bus_num == 0)
  470. cs_pin = spi0_standard_cs[devices[i].chip_select];
  471. else
  472. cs_pin = spi1_standard_cs[devices[i].chip_select];
  473. if (devices[i].bus_num == 0)
  474. enable_spi0 = 1;
  475. else
  476. enable_spi1 = 1;
  477. /* enable chip-select pin */
  478. at91_set_gpio_output(cs_pin, 1);
  479. /* pass chip-select pin to driver */
  480. devices[i].controller_data = (void *) cs_pin;
  481. }
  482. spi_register_board_info(devices, nr_devices);
  483. /* Configure SPI bus(es) */
  484. if (enable_spi0) {
  485. at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI0_MISO */
  486. at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI0_MOSI */
  487. at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI0_SPCK */
  488. at91_clock_associate("spi0_clk", &at91sam9g45_spi0_device.dev, "spi_clk");
  489. platform_device_register(&at91sam9g45_spi0_device);
  490. }
  491. if (enable_spi1) {
  492. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_MISO */
  493. at91_set_A_periph(AT91_PIN_PB15, 0); /* SPI1_MOSI */
  494. at91_set_A_periph(AT91_PIN_PB16, 0); /* SPI1_SPCK */
  495. at91_clock_associate("spi1_clk", &at91sam9g45_spi1_device.dev, "spi_clk");
  496. platform_device_register(&at91sam9g45_spi1_device);
  497. }
  498. }
  499. #else
  500. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  501. #endif
  502. /* --------------------------------------------------------------------
  503. * AC97
  504. * -------------------------------------------------------------------- */
  505. #if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
  506. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  507. static struct ac97c_platform_data ac97_data;
  508. static struct resource ac97_resources[] = {
  509. [0] = {
  510. .start = AT91SAM9G45_BASE_AC97C,
  511. .end = AT91SAM9G45_BASE_AC97C + SZ_16K - 1,
  512. .flags = IORESOURCE_MEM,
  513. },
  514. [1] = {
  515. .start = AT91SAM9G45_ID_AC97C,
  516. .end = AT91SAM9G45_ID_AC97C,
  517. .flags = IORESOURCE_IRQ,
  518. },
  519. };
  520. static struct platform_device at91sam9g45_ac97_device = {
  521. .name = "atmel_ac97c",
  522. .id = 0,
  523. .dev = {
  524. .dma_mask = &ac97_dmamask,
  525. .coherent_dma_mask = DMA_BIT_MASK(32),
  526. .platform_data = &ac97_data,
  527. },
  528. .resource = ac97_resources,
  529. .num_resources = ARRAY_SIZE(ac97_resources),
  530. };
  531. void __init at91_add_device_ac97(struct ac97c_platform_data *data)
  532. {
  533. if (!data)
  534. return;
  535. at91_set_A_periph(AT91_PIN_PD8, 0); /* AC97FS */
  536. at91_set_A_periph(AT91_PIN_PD9, 0); /* AC97CK */
  537. at91_set_A_periph(AT91_PIN_PD7, 0); /* AC97TX */
  538. at91_set_A_periph(AT91_PIN_PD6, 0); /* AC97RX */
  539. /* reset */
  540. if (data->reset_pin)
  541. at91_set_gpio_output(data->reset_pin, 0);
  542. ac97_data = *data;
  543. platform_device_register(&at91sam9g45_ac97_device);
  544. }
  545. #else
  546. void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
  547. #endif
  548. /* --------------------------------------------------------------------
  549. * LCD Controller
  550. * -------------------------------------------------------------------- */
  551. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  552. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  553. static struct atmel_lcdfb_info lcdc_data;
  554. static struct resource lcdc_resources[] = {
  555. [0] = {
  556. .start = AT91SAM9G45_LCDC_BASE,
  557. .end = AT91SAM9G45_LCDC_BASE + SZ_4K - 1,
  558. .flags = IORESOURCE_MEM,
  559. },
  560. [1] = {
  561. .start = AT91SAM9G45_ID_LCDC,
  562. .end = AT91SAM9G45_ID_LCDC,
  563. .flags = IORESOURCE_IRQ,
  564. },
  565. };
  566. static struct platform_device at91_lcdc_device = {
  567. .name = "atmel_lcdfb",
  568. .id = 0,
  569. .dev = {
  570. .dma_mask = &lcdc_dmamask,
  571. .coherent_dma_mask = DMA_BIT_MASK(32),
  572. .platform_data = &lcdc_data,
  573. },
  574. .resource = lcdc_resources,
  575. .num_resources = ARRAY_SIZE(lcdc_resources),
  576. };
  577. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  578. {
  579. if (!data)
  580. return;
  581. at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
  582. at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
  583. at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
  584. at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
  585. at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
  586. at91_set_A_periph(AT91_PIN_PE6, 0); /* LCDDEN */
  587. at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
  588. at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
  589. at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
  590. at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
  591. at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
  592. at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
  593. at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
  594. at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
  595. at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
  596. at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
  597. at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
  598. at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
  599. at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
  600. at91_set_A_periph(AT91_PIN_PE20, 0); /* LCDD13 */
  601. at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
  602. at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
  603. at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
  604. at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
  605. at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
  606. at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
  607. at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
  608. at91_set_A_periph(AT91_PIN_PE28, 0); /* LCDD21 */
  609. at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
  610. at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
  611. lcdc_data = *data;
  612. platform_device_register(&at91_lcdc_device);
  613. }
  614. #else
  615. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  616. #endif
  617. /* --------------------------------------------------------------------
  618. * Timer/Counter block
  619. * -------------------------------------------------------------------- */
  620. #ifdef CONFIG_ATMEL_TCLIB
  621. static struct resource tcb0_resources[] = {
  622. [0] = {
  623. .start = AT91SAM9G45_BASE_TCB0,
  624. .end = AT91SAM9G45_BASE_TCB0 + SZ_16K - 1,
  625. .flags = IORESOURCE_MEM,
  626. },
  627. [1] = {
  628. .start = AT91SAM9G45_ID_TCB,
  629. .end = AT91SAM9G45_ID_TCB,
  630. .flags = IORESOURCE_IRQ,
  631. },
  632. };
  633. static struct platform_device at91sam9g45_tcb0_device = {
  634. .name = "atmel_tcb",
  635. .id = 0,
  636. .resource = tcb0_resources,
  637. .num_resources = ARRAY_SIZE(tcb0_resources),
  638. };
  639. /* TCB1 begins with TC3 */
  640. static struct resource tcb1_resources[] = {
  641. [0] = {
  642. .start = AT91SAM9G45_BASE_TCB1,
  643. .end = AT91SAM9G45_BASE_TCB1 + SZ_16K - 1,
  644. .flags = IORESOURCE_MEM,
  645. },
  646. [1] = {
  647. .start = AT91SAM9G45_ID_TCB,
  648. .end = AT91SAM9G45_ID_TCB,
  649. .flags = IORESOURCE_IRQ,
  650. },
  651. };
  652. static struct platform_device at91sam9g45_tcb1_device = {
  653. .name = "atmel_tcb",
  654. .id = 1,
  655. .resource = tcb1_resources,
  656. .num_resources = ARRAY_SIZE(tcb1_resources),
  657. };
  658. static void __init at91_add_device_tc(void)
  659. {
  660. /* this chip has one clock and irq for all six TC channels */
  661. at91_clock_associate("tcb_clk", &at91sam9g45_tcb0_device.dev, "t0_clk");
  662. platform_device_register(&at91sam9g45_tcb0_device);
  663. at91_clock_associate("tcb_clk", &at91sam9g45_tcb1_device.dev, "t0_clk");
  664. platform_device_register(&at91sam9g45_tcb1_device);
  665. }
  666. #else
  667. static void __init at91_add_device_tc(void) { }
  668. #endif
  669. /* --------------------------------------------------------------------
  670. * RTC
  671. * -------------------------------------------------------------------- */
  672. #if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
  673. static struct platform_device at91sam9g45_rtc_device = {
  674. .name = "at91_rtc",
  675. .id = -1,
  676. .num_resources = 0,
  677. };
  678. static void __init at91_add_device_rtc(void)
  679. {
  680. platform_device_register(&at91sam9g45_rtc_device);
  681. }
  682. #else
  683. static void __init at91_add_device_rtc(void) {}
  684. #endif
  685. /* --------------------------------------------------------------------
  686. * RTT
  687. * -------------------------------------------------------------------- */
  688. static struct resource rtt_resources[] = {
  689. {
  690. .start = AT91_BASE_SYS + AT91_RTT,
  691. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  692. .flags = IORESOURCE_MEM,
  693. }
  694. };
  695. static struct platform_device at91sam9g45_rtt_device = {
  696. .name = "at91_rtt",
  697. .id = 0,
  698. .resource = rtt_resources,
  699. .num_resources = ARRAY_SIZE(rtt_resources),
  700. };
  701. static void __init at91_add_device_rtt(void)
  702. {
  703. platform_device_register(&at91sam9g45_rtt_device);
  704. }
  705. /* --------------------------------------------------------------------
  706. * Watchdog
  707. * -------------------------------------------------------------------- */
  708. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  709. static struct platform_device at91sam9g45_wdt_device = {
  710. .name = "at91_wdt",
  711. .id = -1,
  712. .num_resources = 0,
  713. };
  714. static void __init at91_add_device_watchdog(void)
  715. {
  716. platform_device_register(&at91sam9g45_wdt_device);
  717. }
  718. #else
  719. static void __init at91_add_device_watchdog(void) {}
  720. #endif
  721. /* --------------------------------------------------------------------
  722. * PWM
  723. * --------------------------------------------------------------------*/
  724. #if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE)
  725. static u32 pwm_mask;
  726. static struct resource pwm_resources[] = {
  727. [0] = {
  728. .start = AT91SAM9G45_BASE_PWMC,
  729. .end = AT91SAM9G45_BASE_PWMC + SZ_16K - 1,
  730. .flags = IORESOURCE_MEM,
  731. },
  732. [1] = {
  733. .start = AT91SAM9G45_ID_PWMC,
  734. .end = AT91SAM9G45_ID_PWMC,
  735. .flags = IORESOURCE_IRQ,
  736. },
  737. };
  738. static struct platform_device at91sam9g45_pwm0_device = {
  739. .name = "atmel_pwm",
  740. .id = -1,
  741. .dev = {
  742. .platform_data = &pwm_mask,
  743. },
  744. .resource = pwm_resources,
  745. .num_resources = ARRAY_SIZE(pwm_resources),
  746. };
  747. void __init at91_add_device_pwm(u32 mask)
  748. {
  749. if (mask & (1 << AT91_PWM0))
  750. at91_set_B_periph(AT91_PIN_PD24, 1); /* enable PWM0 */
  751. if (mask & (1 << AT91_PWM1))
  752. at91_set_B_periph(AT91_PIN_PD31, 1); /* enable PWM1 */
  753. if (mask & (1 << AT91_PWM2))
  754. at91_set_B_periph(AT91_PIN_PD26, 1); /* enable PWM2 */
  755. if (mask & (1 << AT91_PWM3))
  756. at91_set_B_periph(AT91_PIN_PD0, 1); /* enable PWM3 */
  757. pwm_mask = mask;
  758. platform_device_register(&at91sam9g45_pwm0_device);
  759. }
  760. #else
  761. void __init at91_add_device_pwm(u32 mask) {}
  762. #endif
  763. /* --------------------------------------------------------------------
  764. * SSC -- Synchronous Serial Controller
  765. * -------------------------------------------------------------------- */
  766. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  767. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  768. static struct resource ssc0_resources[] = {
  769. [0] = {
  770. .start = AT91SAM9G45_BASE_SSC0,
  771. .end = AT91SAM9G45_BASE_SSC0 + SZ_16K - 1,
  772. .flags = IORESOURCE_MEM,
  773. },
  774. [1] = {
  775. .start = AT91SAM9G45_ID_SSC0,
  776. .end = AT91SAM9G45_ID_SSC0,
  777. .flags = IORESOURCE_IRQ,
  778. },
  779. };
  780. static struct platform_device at91sam9g45_ssc0_device = {
  781. .name = "ssc",
  782. .id = 0,
  783. .dev = {
  784. .dma_mask = &ssc0_dmamask,
  785. .coherent_dma_mask = DMA_BIT_MASK(32),
  786. },
  787. .resource = ssc0_resources,
  788. .num_resources = ARRAY_SIZE(ssc0_resources),
  789. };
  790. static inline void configure_ssc0_pins(unsigned pins)
  791. {
  792. if (pins & ATMEL_SSC_TF)
  793. at91_set_A_periph(AT91_PIN_PD1, 1);
  794. if (pins & ATMEL_SSC_TK)
  795. at91_set_A_periph(AT91_PIN_PD0, 1);
  796. if (pins & ATMEL_SSC_TD)
  797. at91_set_A_periph(AT91_PIN_PD2, 1);
  798. if (pins & ATMEL_SSC_RD)
  799. at91_set_A_periph(AT91_PIN_PD3, 1);
  800. if (pins & ATMEL_SSC_RK)
  801. at91_set_A_periph(AT91_PIN_PD4, 1);
  802. if (pins & ATMEL_SSC_RF)
  803. at91_set_A_periph(AT91_PIN_PD5, 1);
  804. }
  805. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  806. static struct resource ssc1_resources[] = {
  807. [0] = {
  808. .start = AT91SAM9G45_BASE_SSC1,
  809. .end = AT91SAM9G45_BASE_SSC1 + SZ_16K - 1,
  810. .flags = IORESOURCE_MEM,
  811. },
  812. [1] = {
  813. .start = AT91SAM9G45_ID_SSC1,
  814. .end = AT91SAM9G45_ID_SSC1,
  815. .flags = IORESOURCE_IRQ,
  816. },
  817. };
  818. static struct platform_device at91sam9g45_ssc1_device = {
  819. .name = "ssc",
  820. .id = 1,
  821. .dev = {
  822. .dma_mask = &ssc1_dmamask,
  823. .coherent_dma_mask = DMA_BIT_MASK(32),
  824. },
  825. .resource = ssc1_resources,
  826. .num_resources = ARRAY_SIZE(ssc1_resources),
  827. };
  828. static inline void configure_ssc1_pins(unsigned pins)
  829. {
  830. if (pins & ATMEL_SSC_TF)
  831. at91_set_A_periph(AT91_PIN_PD14, 1);
  832. if (pins & ATMEL_SSC_TK)
  833. at91_set_A_periph(AT91_PIN_PD12, 1);
  834. if (pins & ATMEL_SSC_TD)
  835. at91_set_A_periph(AT91_PIN_PD10, 1);
  836. if (pins & ATMEL_SSC_RD)
  837. at91_set_A_periph(AT91_PIN_PD11, 1);
  838. if (pins & ATMEL_SSC_RK)
  839. at91_set_A_periph(AT91_PIN_PD13, 1);
  840. if (pins & ATMEL_SSC_RF)
  841. at91_set_A_periph(AT91_PIN_PD15, 1);
  842. }
  843. /*
  844. * SSC controllers are accessed through library code, instead of any
  845. * kind of all-singing/all-dancing driver. For example one could be
  846. * used by a particular I2S audio codec's driver, while another one
  847. * on the same system might be used by a custom data capture driver.
  848. */
  849. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  850. {
  851. struct platform_device *pdev;
  852. /*
  853. * NOTE: caller is responsible for passing information matching
  854. * "pins" to whatever will be using each particular controller.
  855. */
  856. switch (id) {
  857. case AT91SAM9G45_ID_SSC0:
  858. pdev = &at91sam9g45_ssc0_device;
  859. configure_ssc0_pins(pins);
  860. at91_clock_associate("ssc0_clk", &pdev->dev, "pclk");
  861. break;
  862. case AT91SAM9G45_ID_SSC1:
  863. pdev = &at91sam9g45_ssc1_device;
  864. configure_ssc1_pins(pins);
  865. at91_clock_associate("ssc1_clk", &pdev->dev, "pclk");
  866. break;
  867. default:
  868. return;
  869. }
  870. platform_device_register(pdev);
  871. }
  872. #else
  873. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  874. #endif
  875. /* --------------------------------------------------------------------
  876. * UART
  877. * -------------------------------------------------------------------- */
  878. #if defined(CONFIG_SERIAL_ATMEL)
  879. static struct resource dbgu_resources[] = {
  880. [0] = {
  881. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  882. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  883. .flags = IORESOURCE_MEM,
  884. },
  885. [1] = {
  886. .start = AT91_ID_SYS,
  887. .end = AT91_ID_SYS,
  888. .flags = IORESOURCE_IRQ,
  889. },
  890. };
  891. static struct atmel_uart_data dbgu_data = {
  892. .use_dma_tx = 0,
  893. .use_dma_rx = 0,
  894. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  895. };
  896. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  897. static struct platform_device at91sam9g45_dbgu_device = {
  898. .name = "atmel_usart",
  899. .id = 0,
  900. .dev = {
  901. .dma_mask = &dbgu_dmamask,
  902. .coherent_dma_mask = DMA_BIT_MASK(32),
  903. .platform_data = &dbgu_data,
  904. },
  905. .resource = dbgu_resources,
  906. .num_resources = ARRAY_SIZE(dbgu_resources),
  907. };
  908. static inline void configure_dbgu_pins(void)
  909. {
  910. at91_set_A_periph(AT91_PIN_PB12, 0); /* DRXD */
  911. at91_set_A_periph(AT91_PIN_PB13, 1); /* DTXD */
  912. }
  913. static struct resource uart0_resources[] = {
  914. [0] = {
  915. .start = AT91SAM9G45_BASE_US0,
  916. .end = AT91SAM9G45_BASE_US0 + SZ_16K - 1,
  917. .flags = IORESOURCE_MEM,
  918. },
  919. [1] = {
  920. .start = AT91SAM9G45_ID_US0,
  921. .end = AT91SAM9G45_ID_US0,
  922. .flags = IORESOURCE_IRQ,
  923. },
  924. };
  925. static struct atmel_uart_data uart0_data = {
  926. .use_dma_tx = 1,
  927. .use_dma_rx = 1,
  928. };
  929. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  930. static struct platform_device at91sam9g45_uart0_device = {
  931. .name = "atmel_usart",
  932. .id = 1,
  933. .dev = {
  934. .dma_mask = &uart0_dmamask,
  935. .coherent_dma_mask = DMA_BIT_MASK(32),
  936. .platform_data = &uart0_data,
  937. },
  938. .resource = uart0_resources,
  939. .num_resources = ARRAY_SIZE(uart0_resources),
  940. };
  941. static inline void configure_usart0_pins(unsigned pins)
  942. {
  943. at91_set_A_periph(AT91_PIN_PB19, 1); /* TXD0 */
  944. at91_set_A_periph(AT91_PIN_PB18, 0); /* RXD0 */
  945. if (pins & ATMEL_UART_RTS)
  946. at91_set_B_periph(AT91_PIN_PB17, 0); /* RTS0 */
  947. if (pins & ATMEL_UART_CTS)
  948. at91_set_B_periph(AT91_PIN_PB15, 0); /* CTS0 */
  949. }
  950. static struct resource uart1_resources[] = {
  951. [0] = {
  952. .start = AT91SAM9G45_BASE_US1,
  953. .end = AT91SAM9G45_BASE_US1 + SZ_16K - 1,
  954. .flags = IORESOURCE_MEM,
  955. },
  956. [1] = {
  957. .start = AT91SAM9G45_ID_US1,
  958. .end = AT91SAM9G45_ID_US1,
  959. .flags = IORESOURCE_IRQ,
  960. },
  961. };
  962. static struct atmel_uart_data uart1_data = {
  963. .use_dma_tx = 1,
  964. .use_dma_rx = 1,
  965. };
  966. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  967. static struct platform_device at91sam9g45_uart1_device = {
  968. .name = "atmel_usart",
  969. .id = 2,
  970. .dev = {
  971. .dma_mask = &uart1_dmamask,
  972. .coherent_dma_mask = DMA_BIT_MASK(32),
  973. .platform_data = &uart1_data,
  974. },
  975. .resource = uart1_resources,
  976. .num_resources = ARRAY_SIZE(uart1_resources),
  977. };
  978. static inline void configure_usart1_pins(unsigned pins)
  979. {
  980. at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD1 */
  981. at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD1 */
  982. if (pins & ATMEL_UART_RTS)
  983. at91_set_A_periph(AT91_PIN_PD16, 0); /* RTS1 */
  984. if (pins & ATMEL_UART_CTS)
  985. at91_set_A_periph(AT91_PIN_PD17, 0); /* CTS1 */
  986. }
  987. static struct resource uart2_resources[] = {
  988. [0] = {
  989. .start = AT91SAM9G45_BASE_US2,
  990. .end = AT91SAM9G45_BASE_US2 + SZ_16K - 1,
  991. .flags = IORESOURCE_MEM,
  992. },
  993. [1] = {
  994. .start = AT91SAM9G45_ID_US2,
  995. .end = AT91SAM9G45_ID_US2,
  996. .flags = IORESOURCE_IRQ,
  997. },
  998. };
  999. static struct atmel_uart_data uart2_data = {
  1000. .use_dma_tx = 1,
  1001. .use_dma_rx = 1,
  1002. };
  1003. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  1004. static struct platform_device at91sam9g45_uart2_device = {
  1005. .name = "atmel_usart",
  1006. .id = 3,
  1007. .dev = {
  1008. .dma_mask = &uart2_dmamask,
  1009. .coherent_dma_mask = DMA_BIT_MASK(32),
  1010. .platform_data = &uart2_data,
  1011. },
  1012. .resource = uart2_resources,
  1013. .num_resources = ARRAY_SIZE(uart2_resources),
  1014. };
  1015. static inline void configure_usart2_pins(unsigned pins)
  1016. {
  1017. at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD2 */
  1018. at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD2 */
  1019. if (pins & ATMEL_UART_RTS)
  1020. at91_set_B_periph(AT91_PIN_PC9, 0); /* RTS2 */
  1021. if (pins & ATMEL_UART_CTS)
  1022. at91_set_B_periph(AT91_PIN_PC11, 0); /* CTS2 */
  1023. }
  1024. static struct resource uart3_resources[] = {
  1025. [0] = {
  1026. .start = AT91SAM9G45_BASE_US3,
  1027. .end = AT91SAM9G45_BASE_US3 + SZ_16K - 1,
  1028. .flags = IORESOURCE_MEM,
  1029. },
  1030. [1] = {
  1031. .start = AT91SAM9G45_ID_US3,
  1032. .end = AT91SAM9G45_ID_US3,
  1033. .flags = IORESOURCE_IRQ,
  1034. },
  1035. };
  1036. static struct atmel_uart_data uart3_data = {
  1037. .use_dma_tx = 1,
  1038. .use_dma_rx = 1,
  1039. };
  1040. static u64 uart3_dmamask = DMA_BIT_MASK(32);
  1041. static struct platform_device at91sam9g45_uart3_device = {
  1042. .name = "atmel_usart",
  1043. .id = 4,
  1044. .dev = {
  1045. .dma_mask = &uart3_dmamask,
  1046. .coherent_dma_mask = DMA_BIT_MASK(32),
  1047. .platform_data = &uart3_data,
  1048. },
  1049. .resource = uart3_resources,
  1050. .num_resources = ARRAY_SIZE(uart3_resources),
  1051. };
  1052. static inline void configure_usart3_pins(unsigned pins)
  1053. {
  1054. at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD3 */
  1055. at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD3 */
  1056. if (pins & ATMEL_UART_RTS)
  1057. at91_set_B_periph(AT91_PIN_PA23, 0); /* RTS3 */
  1058. if (pins & ATMEL_UART_CTS)
  1059. at91_set_B_periph(AT91_PIN_PA24, 0); /* CTS3 */
  1060. }
  1061. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1062. struct platform_device *atmel_default_console_device; /* the serial console device */
  1063. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1064. {
  1065. struct platform_device *pdev;
  1066. switch (id) {
  1067. case 0: /* DBGU */
  1068. pdev = &at91sam9g45_dbgu_device;
  1069. configure_dbgu_pins();
  1070. at91_clock_associate("mck", &pdev->dev, "usart");
  1071. break;
  1072. case AT91SAM9G45_ID_US0:
  1073. pdev = &at91sam9g45_uart0_device;
  1074. configure_usart0_pins(pins);
  1075. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  1076. break;
  1077. case AT91SAM9G45_ID_US1:
  1078. pdev = &at91sam9g45_uart1_device;
  1079. configure_usart1_pins(pins);
  1080. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  1081. break;
  1082. case AT91SAM9G45_ID_US2:
  1083. pdev = &at91sam9g45_uart2_device;
  1084. configure_usart2_pins(pins);
  1085. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  1086. break;
  1087. case AT91SAM9G45_ID_US3:
  1088. pdev = &at91sam9g45_uart3_device;
  1089. configure_usart3_pins(pins);
  1090. at91_clock_associate("usart3_clk", &pdev->dev, "usart");
  1091. break;
  1092. default:
  1093. return;
  1094. }
  1095. pdev->id = portnr; /* update to mapped ID */
  1096. if (portnr < ATMEL_MAX_UART)
  1097. at91_uarts[portnr] = pdev;
  1098. }
  1099. void __init at91_set_serial_console(unsigned portnr)
  1100. {
  1101. if (portnr < ATMEL_MAX_UART)
  1102. atmel_default_console_device = at91_uarts[portnr];
  1103. }
  1104. void __init at91_add_device_serial(void)
  1105. {
  1106. int i;
  1107. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1108. if (at91_uarts[i])
  1109. platform_device_register(at91_uarts[i]);
  1110. }
  1111. if (!atmel_default_console_device)
  1112. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1113. }
  1114. #else
  1115. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1116. void __init at91_set_serial_console(unsigned portnr) {}
  1117. void __init at91_add_device_serial(void) {}
  1118. #endif
  1119. /* -------------------------------------------------------------------- */
  1120. /*
  1121. * These devices are always present and don't need any board-specific
  1122. * setup.
  1123. */
  1124. static int __init at91_add_standard_devices(void)
  1125. {
  1126. at91_add_device_hdmac();
  1127. at91_add_device_rtc();
  1128. at91_add_device_rtt();
  1129. at91_add_device_watchdog();
  1130. at91_add_device_tc();
  1131. return 0;
  1132. }
  1133. arch_initcall(at91_add_standard_devices);