at91cap9_devices.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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 <linux/dma-mapping.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/i2c-gpio.h>
  19. #include <video/atmel_lcdc.h>
  20. #include <mach/board.h>
  21. #include <mach/gpio.h>
  22. #include <mach/at91cap9.h>
  23. #include <mach/at91cap9_matrix.h>
  24. #include <mach/at91sam9_smc.h>
  25. #include "generic.h"
  26. /* --------------------------------------------------------------------
  27. * USB Host
  28. * -------------------------------------------------------------------- */
  29. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  30. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  31. static struct at91_usbh_data usbh_data;
  32. static struct resource usbh_resources[] = {
  33. [0] = {
  34. .start = AT91CAP9_UHP_BASE,
  35. .end = AT91CAP9_UHP_BASE + SZ_1M - 1,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. [1] = {
  39. .start = AT91CAP9_ID_UHP,
  40. .end = AT91CAP9_ID_UHP,
  41. .flags = IORESOURCE_IRQ,
  42. },
  43. };
  44. static struct platform_device at91_usbh_device = {
  45. .name = "at91_ohci",
  46. .id = -1,
  47. .dev = {
  48. .dma_mask = &ohci_dmamask,
  49. .coherent_dma_mask = DMA_BIT_MASK(32),
  50. .platform_data = &usbh_data,
  51. },
  52. .resource = usbh_resources,
  53. .num_resources = ARRAY_SIZE(usbh_resources),
  54. };
  55. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  56. {
  57. int i;
  58. if (!data)
  59. return;
  60. /* Enable VBus control for UHP ports */
  61. for (i = 0; i < data->ports; i++) {
  62. if (data->vbus_pin[i])
  63. at91_set_gpio_output(data->vbus_pin[i], 0);
  64. }
  65. usbh_data = *data;
  66. platform_device_register(&at91_usbh_device);
  67. }
  68. #else
  69. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  70. #endif
  71. /* --------------------------------------------------------------------
  72. * USB HS Device (Gadget)
  73. * -------------------------------------------------------------------- */
  74. #if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  75. static struct resource usba_udc_resources[] = {
  76. [0] = {
  77. .start = AT91CAP9_UDPHS_FIFO,
  78. .end = AT91CAP9_UDPHS_FIFO + SZ_512K - 1,
  79. .flags = IORESOURCE_MEM,
  80. },
  81. [1] = {
  82. .start = AT91CAP9_BASE_UDPHS,
  83. .end = AT91CAP9_BASE_UDPHS + SZ_1K - 1,
  84. .flags = IORESOURCE_MEM,
  85. },
  86. [2] = {
  87. .start = AT91CAP9_ID_UDPHS,
  88. .end = AT91CAP9_ID_UDPHS,
  89. .flags = IORESOURCE_IRQ,
  90. },
  91. };
  92. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  93. [idx] = { \
  94. .name = nam, \
  95. .index = idx, \
  96. .fifo_size = maxpkt, \
  97. .nr_banks = maxbk, \
  98. .can_dma = dma, \
  99. .can_isoc = isoc, \
  100. }
  101. static struct usba_ep_data usba_udc_ep[] = {
  102. EP("ep0", 0, 64, 1, 0, 0),
  103. EP("ep1", 1, 1024, 3, 1, 1),
  104. EP("ep2", 2, 1024, 3, 1, 1),
  105. EP("ep3", 3, 1024, 2, 1, 1),
  106. EP("ep4", 4, 1024, 2, 1, 1),
  107. EP("ep5", 5, 1024, 2, 1, 0),
  108. EP("ep6", 6, 1024, 2, 1, 0),
  109. EP("ep7", 7, 1024, 2, 0, 0),
  110. };
  111. #undef EP
  112. /*
  113. * pdata doesn't have room for any endpoints, so we need to
  114. * append room for the ones we need right after it.
  115. */
  116. static struct {
  117. struct usba_platform_data pdata;
  118. struct usba_ep_data ep[8];
  119. } usba_udc_data;
  120. static struct platform_device at91_usba_udc_device = {
  121. .name = "atmel_usba_udc",
  122. .id = -1,
  123. .dev = {
  124. .platform_data = &usba_udc_data.pdata,
  125. },
  126. .resource = usba_udc_resources,
  127. .num_resources = ARRAY_SIZE(usba_udc_resources),
  128. };
  129. void __init at91_add_device_usba(struct usba_platform_data *data)
  130. {
  131. at91_sys_write(AT91_MATRIX_UDPHS, AT91_MATRIX_SELECT_UDPHS |
  132. AT91_MATRIX_UDPHS_BYPASS_LOCK);
  133. /*
  134. * Invalid pins are 0 on AT91, but the usba driver is shared
  135. * with AVR32, which use negative values instead. Once/if
  136. * gpio_is_valid() is ported to AT91, revisit this code.
  137. */
  138. usba_udc_data.pdata.vbus_pin = -EINVAL;
  139. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  140. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));;
  141. if (data && data->vbus_pin > 0) {
  142. at91_set_gpio_input(data->vbus_pin, 0);
  143. at91_set_deglitch(data->vbus_pin, 1);
  144. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  145. }
  146. /* Pullup pin is handled internally by USB device peripheral */
  147. /* Clocks */
  148. at91_clock_associate("utmi_clk", &at91_usba_udc_device.dev, "hclk");
  149. at91_clock_associate("udphs_clk", &at91_usba_udc_device.dev, "pclk");
  150. platform_device_register(&at91_usba_udc_device);
  151. }
  152. #else
  153. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  154. #endif
  155. /* --------------------------------------------------------------------
  156. * Ethernet
  157. * -------------------------------------------------------------------- */
  158. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  159. static u64 eth_dmamask = DMA_BIT_MASK(32);
  160. static struct at91_eth_data eth_data;
  161. static struct resource eth_resources[] = {
  162. [0] = {
  163. .start = AT91CAP9_BASE_EMAC,
  164. .end = AT91CAP9_BASE_EMAC + SZ_16K - 1,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. [1] = {
  168. .start = AT91CAP9_ID_EMAC,
  169. .end = AT91CAP9_ID_EMAC,
  170. .flags = IORESOURCE_IRQ,
  171. },
  172. };
  173. static struct platform_device at91cap9_eth_device = {
  174. .name = "macb",
  175. .id = -1,
  176. .dev = {
  177. .dma_mask = &eth_dmamask,
  178. .coherent_dma_mask = DMA_BIT_MASK(32),
  179. .platform_data = &eth_data,
  180. },
  181. .resource = eth_resources,
  182. .num_resources = ARRAY_SIZE(eth_resources),
  183. };
  184. void __init at91_add_device_eth(struct at91_eth_data *data)
  185. {
  186. if (!data)
  187. return;
  188. if (data->phy_irq_pin) {
  189. at91_set_gpio_input(data->phy_irq_pin, 0);
  190. at91_set_deglitch(data->phy_irq_pin, 1);
  191. }
  192. /* Pins used for MII and RMII */
  193. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  194. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  195. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  196. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  197. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  198. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  199. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  200. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  201. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  202. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  203. if (!data->is_rmii) {
  204. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  205. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  206. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  207. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  208. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  209. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  210. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  211. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  212. }
  213. eth_data = *data;
  214. platform_device_register(&at91cap9_eth_device);
  215. }
  216. #else
  217. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  218. #endif
  219. /* --------------------------------------------------------------------
  220. * MMC / SD
  221. * -------------------------------------------------------------------- */
  222. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  223. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  224. static struct at91_mmc_data mmc0_data, mmc1_data;
  225. static struct resource mmc0_resources[] = {
  226. [0] = {
  227. .start = AT91CAP9_BASE_MCI0,
  228. .end = AT91CAP9_BASE_MCI0 + SZ_16K - 1,
  229. .flags = IORESOURCE_MEM,
  230. },
  231. [1] = {
  232. .start = AT91CAP9_ID_MCI0,
  233. .end = AT91CAP9_ID_MCI0,
  234. .flags = IORESOURCE_IRQ,
  235. },
  236. };
  237. static struct platform_device at91cap9_mmc0_device = {
  238. .name = "at91_mci",
  239. .id = 0,
  240. .dev = {
  241. .dma_mask = &mmc_dmamask,
  242. .coherent_dma_mask = DMA_BIT_MASK(32),
  243. .platform_data = &mmc0_data,
  244. },
  245. .resource = mmc0_resources,
  246. .num_resources = ARRAY_SIZE(mmc0_resources),
  247. };
  248. static struct resource mmc1_resources[] = {
  249. [0] = {
  250. .start = AT91CAP9_BASE_MCI1,
  251. .end = AT91CAP9_BASE_MCI1 + SZ_16K - 1,
  252. .flags = IORESOURCE_MEM,
  253. },
  254. [1] = {
  255. .start = AT91CAP9_ID_MCI1,
  256. .end = AT91CAP9_ID_MCI1,
  257. .flags = IORESOURCE_IRQ,
  258. },
  259. };
  260. static struct platform_device at91cap9_mmc1_device = {
  261. .name = "at91_mci",
  262. .id = 1,
  263. .dev = {
  264. .dma_mask = &mmc_dmamask,
  265. .coherent_dma_mask = DMA_BIT_MASK(32),
  266. .platform_data = &mmc1_data,
  267. },
  268. .resource = mmc1_resources,
  269. .num_resources = ARRAY_SIZE(mmc1_resources),
  270. };
  271. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  272. {
  273. if (!data)
  274. return;
  275. /* input/irq */
  276. if (data->det_pin) {
  277. at91_set_gpio_input(data->det_pin, 1);
  278. at91_set_deglitch(data->det_pin, 1);
  279. }
  280. if (data->wp_pin)
  281. at91_set_gpio_input(data->wp_pin, 1);
  282. if (data->vcc_pin)
  283. at91_set_gpio_output(data->vcc_pin, 0);
  284. if (mmc_id == 0) { /* MCI0 */
  285. /* CLK */
  286. at91_set_A_periph(AT91_PIN_PA2, 0);
  287. /* CMD */
  288. at91_set_A_periph(AT91_PIN_PA1, 1);
  289. /* DAT0, maybe DAT1..DAT3 */
  290. at91_set_A_periph(AT91_PIN_PA0, 1);
  291. if (data->wire4) {
  292. at91_set_A_periph(AT91_PIN_PA3, 1);
  293. at91_set_A_periph(AT91_PIN_PA4, 1);
  294. at91_set_A_periph(AT91_PIN_PA5, 1);
  295. }
  296. mmc0_data = *data;
  297. at91_clock_associate("mci0_clk", &at91cap9_mmc0_device.dev, "mci_clk");
  298. platform_device_register(&at91cap9_mmc0_device);
  299. } else { /* MCI1 */
  300. /* CLK */
  301. at91_set_A_periph(AT91_PIN_PA16, 0);
  302. /* CMD */
  303. at91_set_A_periph(AT91_PIN_PA17, 1);
  304. /* DAT0, maybe DAT1..DAT3 */
  305. at91_set_A_periph(AT91_PIN_PA18, 1);
  306. if (data->wire4) {
  307. at91_set_A_periph(AT91_PIN_PA19, 1);
  308. at91_set_A_periph(AT91_PIN_PA20, 1);
  309. at91_set_A_periph(AT91_PIN_PA21, 1);
  310. }
  311. mmc1_data = *data;
  312. at91_clock_associate("mci1_clk", &at91cap9_mmc1_device.dev, "mci_clk");
  313. platform_device_register(&at91cap9_mmc1_device);
  314. }
  315. }
  316. #else
  317. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  318. #endif
  319. /* --------------------------------------------------------------------
  320. * NAND / SmartMedia
  321. * -------------------------------------------------------------------- */
  322. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  323. static struct atmel_nand_data nand_data;
  324. #define NAND_BASE AT91_CHIPSELECT_3
  325. static struct resource nand_resources[] = {
  326. [0] = {
  327. .start = NAND_BASE,
  328. .end = NAND_BASE + SZ_256M - 1,
  329. .flags = IORESOURCE_MEM,
  330. },
  331. [1] = {
  332. .start = AT91_BASE_SYS + AT91_ECC,
  333. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  334. .flags = IORESOURCE_MEM,
  335. }
  336. };
  337. static struct platform_device at91cap9_nand_device = {
  338. .name = "atmel_nand",
  339. .id = -1,
  340. .dev = {
  341. .platform_data = &nand_data,
  342. },
  343. .resource = nand_resources,
  344. .num_resources = ARRAY_SIZE(nand_resources),
  345. };
  346. void __init at91_add_device_nand(struct atmel_nand_data *data)
  347. {
  348. unsigned long csa, mode;
  349. if (!data)
  350. return;
  351. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  352. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  353. /* set the bus interface characteristics */
  354. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1)
  355. | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
  356. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6)
  357. | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
  358. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  359. if (data->bus_width_16)
  360. mode = AT91_SMC_DBW_16;
  361. else
  362. mode = AT91_SMC_DBW_8;
  363. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
  364. /* enable pin */
  365. if (data->enable_pin)
  366. at91_set_gpio_output(data->enable_pin, 1);
  367. /* ready/busy pin */
  368. if (data->rdy_pin)
  369. at91_set_gpio_input(data->rdy_pin, 1);
  370. /* card detect pin */
  371. if (data->det_pin)
  372. at91_set_gpio_input(data->det_pin, 1);
  373. nand_data = *data;
  374. platform_device_register(&at91cap9_nand_device);
  375. }
  376. #else
  377. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  378. #endif
  379. /* --------------------------------------------------------------------
  380. * TWI (i2c)
  381. * -------------------------------------------------------------------- */
  382. /*
  383. * Prefer the GPIO code since the TWI controller isn't robust
  384. * (gets overruns and underruns under load) and can only issue
  385. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  386. */
  387. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  388. static struct i2c_gpio_platform_data pdata = {
  389. .sda_pin = AT91_PIN_PB4,
  390. .sda_is_open_drain = 1,
  391. .scl_pin = AT91_PIN_PB5,
  392. .scl_is_open_drain = 1,
  393. .udelay = 2, /* ~100 kHz */
  394. };
  395. static struct platform_device at91cap9_twi_device = {
  396. .name = "i2c-gpio",
  397. .id = -1,
  398. .dev.platform_data = &pdata,
  399. };
  400. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  401. {
  402. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  403. at91_set_multi_drive(AT91_PIN_PB4, 1);
  404. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  405. at91_set_multi_drive(AT91_PIN_PB5, 1);
  406. i2c_register_board_info(0, devices, nr_devices);
  407. platform_device_register(&at91cap9_twi_device);
  408. }
  409. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  410. static struct resource twi_resources[] = {
  411. [0] = {
  412. .start = AT91CAP9_BASE_TWI,
  413. .end = AT91CAP9_BASE_TWI + SZ_16K - 1,
  414. .flags = IORESOURCE_MEM,
  415. },
  416. [1] = {
  417. .start = AT91CAP9_ID_TWI,
  418. .end = AT91CAP9_ID_TWI,
  419. .flags = IORESOURCE_IRQ,
  420. },
  421. };
  422. static struct platform_device at91cap9_twi_device = {
  423. .name = "at91_i2c",
  424. .id = -1,
  425. .resource = twi_resources,
  426. .num_resources = ARRAY_SIZE(twi_resources),
  427. };
  428. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  429. {
  430. /* pins used for TWI interface */
  431. at91_set_B_periph(AT91_PIN_PB4, 0); /* TWD */
  432. at91_set_multi_drive(AT91_PIN_PB4, 1);
  433. at91_set_B_periph(AT91_PIN_PB5, 0); /* TWCK */
  434. at91_set_multi_drive(AT91_PIN_PB5, 1);
  435. i2c_register_board_info(0, devices, nr_devices);
  436. platform_device_register(&at91cap9_twi_device);
  437. }
  438. #else
  439. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  440. #endif
  441. /* --------------------------------------------------------------------
  442. * SPI
  443. * -------------------------------------------------------------------- */
  444. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  445. static u64 spi_dmamask = DMA_BIT_MASK(32);
  446. static struct resource spi0_resources[] = {
  447. [0] = {
  448. .start = AT91CAP9_BASE_SPI0,
  449. .end = AT91CAP9_BASE_SPI0 + SZ_16K - 1,
  450. .flags = IORESOURCE_MEM,
  451. },
  452. [1] = {
  453. .start = AT91CAP9_ID_SPI0,
  454. .end = AT91CAP9_ID_SPI0,
  455. .flags = IORESOURCE_IRQ,
  456. },
  457. };
  458. static struct platform_device at91cap9_spi0_device = {
  459. .name = "atmel_spi",
  460. .id = 0,
  461. .dev = {
  462. .dma_mask = &spi_dmamask,
  463. .coherent_dma_mask = DMA_BIT_MASK(32),
  464. },
  465. .resource = spi0_resources,
  466. .num_resources = ARRAY_SIZE(spi0_resources),
  467. };
  468. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PD0, AT91_PIN_PD1 };
  469. static struct resource spi1_resources[] = {
  470. [0] = {
  471. .start = AT91CAP9_BASE_SPI1,
  472. .end = AT91CAP9_BASE_SPI1 + SZ_16K - 1,
  473. .flags = IORESOURCE_MEM,
  474. },
  475. [1] = {
  476. .start = AT91CAP9_ID_SPI1,
  477. .end = AT91CAP9_ID_SPI1,
  478. .flags = IORESOURCE_IRQ,
  479. },
  480. };
  481. static struct platform_device at91cap9_spi1_device = {
  482. .name = "atmel_spi",
  483. .id = 1,
  484. .dev = {
  485. .dma_mask = &spi_dmamask,
  486. .coherent_dma_mask = DMA_BIT_MASK(32),
  487. },
  488. .resource = spi1_resources,
  489. .num_resources = ARRAY_SIZE(spi1_resources),
  490. };
  491. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  492. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  493. {
  494. int i;
  495. unsigned long cs_pin;
  496. short enable_spi0 = 0;
  497. short enable_spi1 = 0;
  498. /* Choose SPI chip-selects */
  499. for (i = 0; i < nr_devices; i++) {
  500. if (devices[i].controller_data)
  501. cs_pin = (unsigned long) devices[i].controller_data;
  502. else if (devices[i].bus_num == 0)
  503. cs_pin = spi0_standard_cs[devices[i].chip_select];
  504. else
  505. cs_pin = spi1_standard_cs[devices[i].chip_select];
  506. if (devices[i].bus_num == 0)
  507. enable_spi0 = 1;
  508. else
  509. enable_spi1 = 1;
  510. /* enable chip-select pin */
  511. at91_set_gpio_output(cs_pin, 1);
  512. /* pass chip-select pin to driver */
  513. devices[i].controller_data = (void *) cs_pin;
  514. }
  515. spi_register_board_info(devices, nr_devices);
  516. /* Configure SPI bus(es) */
  517. if (enable_spi0) {
  518. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  519. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  520. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  521. at91_clock_associate("spi0_clk", &at91cap9_spi0_device.dev, "spi_clk");
  522. platform_device_register(&at91cap9_spi0_device);
  523. }
  524. if (enable_spi1) {
  525. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  526. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  527. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  528. at91_clock_associate("spi1_clk", &at91cap9_spi1_device.dev, "spi_clk");
  529. platform_device_register(&at91cap9_spi1_device);
  530. }
  531. }
  532. #else
  533. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  534. #endif
  535. /* --------------------------------------------------------------------
  536. * Timer/Counter block
  537. * -------------------------------------------------------------------- */
  538. #ifdef CONFIG_ATMEL_TCLIB
  539. static struct resource tcb_resources[] = {
  540. [0] = {
  541. .start = AT91CAP9_BASE_TCB0,
  542. .end = AT91CAP9_BASE_TCB0 + SZ_16K - 1,
  543. .flags = IORESOURCE_MEM,
  544. },
  545. [1] = {
  546. .start = AT91CAP9_ID_TCB,
  547. .end = AT91CAP9_ID_TCB,
  548. .flags = IORESOURCE_IRQ,
  549. },
  550. };
  551. static struct platform_device at91cap9_tcb_device = {
  552. .name = "atmel_tcb",
  553. .id = 0,
  554. .resource = tcb_resources,
  555. .num_resources = ARRAY_SIZE(tcb_resources),
  556. };
  557. static void __init at91_add_device_tc(void)
  558. {
  559. /* this chip has one clock and irq for all three TC channels */
  560. at91_clock_associate("tcb_clk", &at91cap9_tcb_device.dev, "t0_clk");
  561. platform_device_register(&at91cap9_tcb_device);
  562. }
  563. #else
  564. static void __init at91_add_device_tc(void) { }
  565. #endif
  566. /* --------------------------------------------------------------------
  567. * RTT
  568. * -------------------------------------------------------------------- */
  569. static struct resource rtt_resources[] = {
  570. {
  571. .start = AT91_BASE_SYS + AT91_RTT,
  572. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  573. .flags = IORESOURCE_MEM,
  574. }
  575. };
  576. static struct platform_device at91cap9_rtt_device = {
  577. .name = "at91_rtt",
  578. .id = 0,
  579. .resource = rtt_resources,
  580. .num_resources = ARRAY_SIZE(rtt_resources),
  581. };
  582. static void __init at91_add_device_rtt(void)
  583. {
  584. platform_device_register(&at91cap9_rtt_device);
  585. }
  586. /* --------------------------------------------------------------------
  587. * Watchdog
  588. * -------------------------------------------------------------------- */
  589. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  590. static struct platform_device at91cap9_wdt_device = {
  591. .name = "at91_wdt",
  592. .id = -1,
  593. .num_resources = 0,
  594. };
  595. static void __init at91_add_device_watchdog(void)
  596. {
  597. platform_device_register(&at91cap9_wdt_device);
  598. }
  599. #else
  600. static void __init at91_add_device_watchdog(void) {}
  601. #endif
  602. /* --------------------------------------------------------------------
  603. * PWM
  604. * --------------------------------------------------------------------*/
  605. #if defined(CONFIG_ATMEL_PWM)
  606. static u32 pwm_mask;
  607. static struct resource pwm_resources[] = {
  608. [0] = {
  609. .start = AT91CAP9_BASE_PWMC,
  610. .end = AT91CAP9_BASE_PWMC + SZ_16K - 1,
  611. .flags = IORESOURCE_MEM,
  612. },
  613. [1] = {
  614. .start = AT91CAP9_ID_PWMC,
  615. .end = AT91CAP9_ID_PWMC,
  616. .flags = IORESOURCE_IRQ,
  617. },
  618. };
  619. static struct platform_device at91cap9_pwm0_device = {
  620. .name = "atmel_pwm",
  621. .id = -1,
  622. .dev = {
  623. .platform_data = &pwm_mask,
  624. },
  625. .resource = pwm_resources,
  626. .num_resources = ARRAY_SIZE(pwm_resources),
  627. };
  628. void __init at91_add_device_pwm(u32 mask)
  629. {
  630. if (mask & (1 << AT91_PWM0))
  631. at91_set_A_periph(AT91_PIN_PB19, 1); /* enable PWM0 */
  632. if (mask & (1 << AT91_PWM1))
  633. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
  634. if (mask & (1 << AT91_PWM2))
  635. at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
  636. if (mask & (1 << AT91_PWM3))
  637. at91_set_B_periph(AT91_PIN_PA11, 1); /* enable PWM3 */
  638. pwm_mask = mask;
  639. platform_device_register(&at91cap9_pwm0_device);
  640. }
  641. #else
  642. void __init at91_add_device_pwm(u32 mask) {}
  643. #endif
  644. /* --------------------------------------------------------------------
  645. * AC97
  646. * -------------------------------------------------------------------- */
  647. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  648. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  649. static struct atmel_ac97_data ac97_data;
  650. static struct resource ac97_resources[] = {
  651. [0] = {
  652. .start = AT91CAP9_BASE_AC97C,
  653. .end = AT91CAP9_BASE_AC97C + SZ_16K - 1,
  654. .flags = IORESOURCE_MEM,
  655. },
  656. [1] = {
  657. .start = AT91CAP9_ID_AC97C,
  658. .end = AT91CAP9_ID_AC97C,
  659. .flags = IORESOURCE_IRQ,
  660. },
  661. };
  662. static struct platform_device at91cap9_ac97_device = {
  663. .name = "ac97c",
  664. .id = 1,
  665. .dev = {
  666. .dma_mask = &ac97_dmamask,
  667. .coherent_dma_mask = DMA_BIT_MASK(32),
  668. .platform_data = &ac97_data,
  669. },
  670. .resource = ac97_resources,
  671. .num_resources = ARRAY_SIZE(ac97_resources),
  672. };
  673. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  674. {
  675. if (!data)
  676. return;
  677. at91_set_A_periph(AT91_PIN_PA6, 0); /* AC97FS */
  678. at91_set_A_periph(AT91_PIN_PA7, 0); /* AC97CK */
  679. at91_set_A_periph(AT91_PIN_PA8, 0); /* AC97TX */
  680. at91_set_A_periph(AT91_PIN_PA9, 0); /* AC97RX */
  681. /* reset */
  682. if (data->reset_pin)
  683. at91_set_gpio_output(data->reset_pin, 0);
  684. ac97_data = *data;
  685. platform_device_register(&at91cap9_ac97_device);
  686. }
  687. #else
  688. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  689. #endif
  690. /* --------------------------------------------------------------------
  691. * LCD Controller
  692. * -------------------------------------------------------------------- */
  693. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  694. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  695. static struct atmel_lcdfb_info lcdc_data;
  696. static struct resource lcdc_resources[] = {
  697. [0] = {
  698. .start = AT91CAP9_LCDC_BASE,
  699. .end = AT91CAP9_LCDC_BASE + SZ_4K - 1,
  700. .flags = IORESOURCE_MEM,
  701. },
  702. [1] = {
  703. .start = AT91CAP9_ID_LCDC,
  704. .end = AT91CAP9_ID_LCDC,
  705. .flags = IORESOURCE_IRQ,
  706. },
  707. };
  708. static struct platform_device at91_lcdc_device = {
  709. .name = "atmel_lcdfb",
  710. .id = 0,
  711. .dev = {
  712. .dma_mask = &lcdc_dmamask,
  713. .coherent_dma_mask = DMA_BIT_MASK(32),
  714. .platform_data = &lcdc_data,
  715. },
  716. .resource = lcdc_resources,
  717. .num_resources = ARRAY_SIZE(lcdc_resources),
  718. };
  719. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  720. {
  721. if (!data)
  722. return;
  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);