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 <asm/mach/irq.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/gpio.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/i2c-gpio.h>
  21. #include <video/atmel_lcdc.h>
  22. #include <mach/board.h>
  23. #include <mach/cpu.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. irq_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 (gpio_is_valid(data->vbus_pin[i]))
  67. at91_set_gpio_output(data->vbus_pin[i], 0);
  68. }
  69. /* Enable overcurrent notification */
  70. for (i = 0; i < data->ports; i++) {
  71. if (data->overcurrent_pin[i])
  72. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  73. }
  74. usbh_data = *data;
  75. platform_device_register(&at91_usbh_device);
  76. }
  77. #else
  78. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  79. #endif
  80. /* --------------------------------------------------------------------
  81. * USB HS Device (Gadget)
  82. * -------------------------------------------------------------------- */
  83. #if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE)
  84. static struct resource usba_udc_resources[] = {
  85. [0] = {
  86. .start = AT91CAP9_UDPHS_FIFO,
  87. .end = AT91CAP9_UDPHS_FIFO + SZ_512K - 1,
  88. .flags = IORESOURCE_MEM,
  89. },
  90. [1] = {
  91. .start = AT91CAP9_BASE_UDPHS,
  92. .end = AT91CAP9_BASE_UDPHS + SZ_1K - 1,
  93. .flags = IORESOURCE_MEM,
  94. },
  95. [2] = {
  96. .start = AT91CAP9_ID_UDPHS,
  97. .end = AT91CAP9_ID_UDPHS,
  98. .flags = IORESOURCE_IRQ,
  99. },
  100. };
  101. #define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
  102. [idx] = { \
  103. .name = nam, \
  104. .index = idx, \
  105. .fifo_size = maxpkt, \
  106. .nr_banks = maxbk, \
  107. .can_dma = dma, \
  108. .can_isoc = isoc, \
  109. }
  110. static struct usba_ep_data usba_udc_ep[] = {
  111. EP("ep0", 0, 64, 1, 0, 0),
  112. EP("ep1", 1, 1024, 3, 1, 1),
  113. EP("ep2", 2, 1024, 3, 1, 1),
  114. EP("ep3", 3, 1024, 2, 1, 1),
  115. EP("ep4", 4, 1024, 2, 1, 1),
  116. EP("ep5", 5, 1024, 2, 1, 0),
  117. EP("ep6", 6, 1024, 2, 1, 0),
  118. EP("ep7", 7, 1024, 2, 0, 0),
  119. };
  120. #undef EP
  121. /*
  122. * pdata doesn't have room for any endpoints, so we need to
  123. * append room for the ones we need right after it.
  124. */
  125. static struct {
  126. struct usba_platform_data pdata;
  127. struct usba_ep_data ep[8];
  128. } usba_udc_data;
  129. static struct platform_device at91_usba_udc_device = {
  130. .name = "atmel_usba_udc",
  131. .id = -1,
  132. .dev = {
  133. .platform_data = &usba_udc_data.pdata,
  134. },
  135. .resource = usba_udc_resources,
  136. .num_resources = ARRAY_SIZE(usba_udc_resources),
  137. };
  138. void __init at91_add_device_usba(struct usba_platform_data *data)
  139. {
  140. if (cpu_is_at91cap9_revB()) {
  141. irq_set_irq_type(AT91CAP9_ID_UDPHS, IRQ_TYPE_LEVEL_HIGH);
  142. at91_sys_write(AT91_MATRIX_UDPHS, AT91_MATRIX_SELECT_UDPHS |
  143. AT91_MATRIX_UDPHS_BYPASS_LOCK);
  144. }
  145. else
  146. at91_sys_write(AT91_MATRIX_UDPHS, AT91_MATRIX_SELECT_UDPHS);
  147. /*
  148. * Invalid pins are 0 on AT91, but the usba driver is shared
  149. * with AVR32, which use negative values instead. Once/if
  150. * gpio_is_valid() is ported to AT91, revisit this code.
  151. */
  152. usba_udc_data.pdata.vbus_pin = -EINVAL;
  153. usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
  154. memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));
  155. if (data && gpio_is_valid(data->vbus_pin)) {
  156. at91_set_gpio_input(data->vbus_pin, 0);
  157. at91_set_deglitch(data->vbus_pin, 1);
  158. usba_udc_data.pdata.vbus_pin = data->vbus_pin;
  159. }
  160. /* Pullup pin is handled internally by USB device peripheral */
  161. platform_device_register(&at91_usba_udc_device);
  162. }
  163. #else
  164. void __init at91_add_device_usba(struct usba_platform_data *data) {}
  165. #endif
  166. /* --------------------------------------------------------------------
  167. * Ethernet
  168. * -------------------------------------------------------------------- */
  169. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  170. static u64 eth_dmamask = DMA_BIT_MASK(32);
  171. static struct macb_platform_data eth_data;
  172. static struct resource eth_resources[] = {
  173. [0] = {
  174. .start = AT91CAP9_BASE_EMAC,
  175. .end = AT91CAP9_BASE_EMAC + SZ_16K - 1,
  176. .flags = IORESOURCE_MEM,
  177. },
  178. [1] = {
  179. .start = AT91CAP9_ID_EMAC,
  180. .end = AT91CAP9_ID_EMAC,
  181. .flags = IORESOURCE_IRQ,
  182. },
  183. };
  184. static struct platform_device at91cap9_eth_device = {
  185. .name = "macb",
  186. .id = -1,
  187. .dev = {
  188. .dma_mask = &eth_dmamask,
  189. .coherent_dma_mask = DMA_BIT_MASK(32),
  190. .platform_data = &eth_data,
  191. },
  192. .resource = eth_resources,
  193. .num_resources = ARRAY_SIZE(eth_resources),
  194. };
  195. void __init at91_add_device_eth(struct macb_platform_data *data)
  196. {
  197. if (!data)
  198. return;
  199. if (gpio_is_valid(data->phy_irq_pin)) {
  200. at91_set_gpio_input(data->phy_irq_pin, 0);
  201. at91_set_deglitch(data->phy_irq_pin, 1);
  202. }
  203. /* Pins used for MII and RMII */
  204. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  205. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  206. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  207. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  208. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  209. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  210. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  211. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  212. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  213. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  214. if (!data->is_rmii) {
  215. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  216. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  217. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  218. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  219. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  220. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  221. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  222. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  223. }
  224. eth_data = *data;
  225. platform_device_register(&at91cap9_eth_device);
  226. }
  227. #else
  228. void __init at91_add_device_eth(struct macb_platform_data *data) {}
  229. #endif
  230. /* --------------------------------------------------------------------
  231. * MMC / SD
  232. * -------------------------------------------------------------------- */
  233. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  234. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  235. static struct at91_mmc_data mmc0_data, mmc1_data;
  236. static struct resource mmc0_resources[] = {
  237. [0] = {
  238. .start = AT91CAP9_BASE_MCI0,
  239. .end = AT91CAP9_BASE_MCI0 + SZ_16K - 1,
  240. .flags = IORESOURCE_MEM,
  241. },
  242. [1] = {
  243. .start = AT91CAP9_ID_MCI0,
  244. .end = AT91CAP9_ID_MCI0,
  245. .flags = IORESOURCE_IRQ,
  246. },
  247. };
  248. static struct platform_device at91cap9_mmc0_device = {
  249. .name = "at91_mci",
  250. .id = 0,
  251. .dev = {
  252. .dma_mask = &mmc_dmamask,
  253. .coherent_dma_mask = DMA_BIT_MASK(32),
  254. .platform_data = &mmc0_data,
  255. },
  256. .resource = mmc0_resources,
  257. .num_resources = ARRAY_SIZE(mmc0_resources),
  258. };
  259. static struct resource mmc1_resources[] = {
  260. [0] = {
  261. .start = AT91CAP9_BASE_MCI1,
  262. .end = AT91CAP9_BASE_MCI1 + SZ_16K - 1,
  263. .flags = IORESOURCE_MEM,
  264. },
  265. [1] = {
  266. .start = AT91CAP9_ID_MCI1,
  267. .end = AT91CAP9_ID_MCI1,
  268. .flags = IORESOURCE_IRQ,
  269. },
  270. };
  271. static struct platform_device at91cap9_mmc1_device = {
  272. .name = "at91_mci",
  273. .id = 1,
  274. .dev = {
  275. .dma_mask = &mmc_dmamask,
  276. .coherent_dma_mask = DMA_BIT_MASK(32),
  277. .platform_data = &mmc1_data,
  278. },
  279. .resource = mmc1_resources,
  280. .num_resources = ARRAY_SIZE(mmc1_resources),
  281. };
  282. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  283. {
  284. if (!data)
  285. return;
  286. /* input/irq */
  287. if (gpio_is_valid(data->det_pin)) {
  288. at91_set_gpio_input(data->det_pin, 1);
  289. at91_set_deglitch(data->det_pin, 1);
  290. }
  291. if (gpio_is_valid(data->wp_pin))
  292. at91_set_gpio_input(data->wp_pin, 1);
  293. if (gpio_is_valid(data->vcc_pin))
  294. at91_set_gpio_output(data->vcc_pin, 0);
  295. if (mmc_id == 0) { /* MCI0 */
  296. /* CLK */
  297. at91_set_A_periph(AT91_PIN_PA2, 0);
  298. /* CMD */
  299. at91_set_A_periph(AT91_PIN_PA1, 1);
  300. /* DAT0, maybe DAT1..DAT3 */
  301. at91_set_A_periph(AT91_PIN_PA0, 1);
  302. if (data->wire4) {
  303. at91_set_A_periph(AT91_PIN_PA3, 1);
  304. at91_set_A_periph(AT91_PIN_PA4, 1);
  305. at91_set_A_periph(AT91_PIN_PA5, 1);
  306. }
  307. mmc0_data = *data;
  308. platform_device_register(&at91cap9_mmc0_device);
  309. } else { /* MCI1 */
  310. /* CLK */
  311. at91_set_A_periph(AT91_PIN_PA16, 0);
  312. /* CMD */
  313. at91_set_A_periph(AT91_PIN_PA17, 1);
  314. /* DAT0, maybe DAT1..DAT3 */
  315. at91_set_A_periph(AT91_PIN_PA18, 1);
  316. if (data->wire4) {
  317. at91_set_A_periph(AT91_PIN_PA19, 1);
  318. at91_set_A_periph(AT91_PIN_PA20, 1);
  319. at91_set_A_periph(AT91_PIN_PA21, 1);
  320. }
  321. mmc1_data = *data;
  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 = AT91CAP9_BASE_ECC,
  342. .end = AT91CAP9_BASE_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 (gpio_is_valid(data->enable_pin))
  364. at91_set_gpio_output(data->enable_pin, 1);
  365. /* ready/busy pin */
  366. if (gpio_is_valid(data->rdy_pin))
  367. at91_set_gpio_input(data->rdy_pin, 1);
  368. /* card detect pin */
  369. if (gpio_is_valid(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. platform_device_register(&at91cap9_spi0_device);
  520. }
  521. if (enable_spi1) {
  522. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  523. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  524. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  525. platform_device_register(&at91cap9_spi1_device);
  526. }
  527. }
  528. #else
  529. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  530. #endif
  531. /* --------------------------------------------------------------------
  532. * Timer/Counter block
  533. * -------------------------------------------------------------------- */
  534. #ifdef CONFIG_ATMEL_TCLIB
  535. static struct resource tcb_resources[] = {
  536. [0] = {
  537. .start = AT91CAP9_BASE_TCB0,
  538. .end = AT91CAP9_BASE_TCB0 + SZ_16K - 1,
  539. .flags = IORESOURCE_MEM,
  540. },
  541. [1] = {
  542. .start = AT91CAP9_ID_TCB,
  543. .end = AT91CAP9_ID_TCB,
  544. .flags = IORESOURCE_IRQ,
  545. },
  546. };
  547. static struct platform_device at91cap9_tcb_device = {
  548. .name = "atmel_tcb",
  549. .id = 0,
  550. .resource = tcb_resources,
  551. .num_resources = ARRAY_SIZE(tcb_resources),
  552. };
  553. static void __init at91_add_device_tc(void)
  554. {
  555. platform_device_register(&at91cap9_tcb_device);
  556. }
  557. #else
  558. static void __init at91_add_device_tc(void) { }
  559. #endif
  560. /* --------------------------------------------------------------------
  561. * RTT
  562. * -------------------------------------------------------------------- */
  563. static struct resource rtt_resources[] = {
  564. {
  565. .start = AT91CAP9_BASE_RTT,
  566. .end = AT91CAP9_BASE_RTT + SZ_16 - 1,
  567. .flags = IORESOURCE_MEM,
  568. }
  569. };
  570. static struct platform_device at91cap9_rtt_device = {
  571. .name = "at91_rtt",
  572. .id = 0,
  573. .resource = rtt_resources,
  574. .num_resources = ARRAY_SIZE(rtt_resources),
  575. };
  576. static void __init at91_add_device_rtt(void)
  577. {
  578. platform_device_register(&at91cap9_rtt_device);
  579. }
  580. /* --------------------------------------------------------------------
  581. * Watchdog
  582. * -------------------------------------------------------------------- */
  583. #if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
  584. static struct resource wdt_resources[] = {
  585. {
  586. .start = AT91CAP9_BASE_WDT,
  587. .end = AT91CAP9_BASE_WDT + SZ_16 - 1,
  588. .flags = IORESOURCE_MEM,
  589. }
  590. };
  591. static struct platform_device at91cap9_wdt_device = {
  592. .name = "at91_wdt",
  593. .id = -1,
  594. .resource = wdt_resources,
  595. .num_resources = ARRAY_SIZE(wdt_resources),
  596. };
  597. static void __init at91_add_device_watchdog(void)
  598. {
  599. platform_device_register(&at91cap9_wdt_device);
  600. }
  601. #else
  602. static void __init at91_add_device_watchdog(void) {}
  603. #endif
  604. /* --------------------------------------------------------------------
  605. * PWM
  606. * --------------------------------------------------------------------*/
  607. #if defined(CONFIG_ATMEL_PWM)
  608. static u32 pwm_mask;
  609. static struct resource pwm_resources[] = {
  610. [0] = {
  611. .start = AT91CAP9_BASE_PWMC,
  612. .end = AT91CAP9_BASE_PWMC + SZ_16K - 1,
  613. .flags = IORESOURCE_MEM,
  614. },
  615. [1] = {
  616. .start = AT91CAP9_ID_PWMC,
  617. .end = AT91CAP9_ID_PWMC,
  618. .flags = IORESOURCE_IRQ,
  619. },
  620. };
  621. static struct platform_device at91cap9_pwm0_device = {
  622. .name = "atmel_pwm",
  623. .id = -1,
  624. .dev = {
  625. .platform_data = &pwm_mask,
  626. },
  627. .resource = pwm_resources,
  628. .num_resources = ARRAY_SIZE(pwm_resources),
  629. };
  630. void __init at91_add_device_pwm(u32 mask)
  631. {
  632. if (mask & (1 << AT91_PWM0))
  633. at91_set_A_periph(AT91_PIN_PB19, 1); /* enable PWM0 */
  634. if (mask & (1 << AT91_PWM1))
  635. at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
  636. if (mask & (1 << AT91_PWM2))
  637. at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
  638. if (mask & (1 << AT91_PWM3))
  639. at91_set_B_periph(AT91_PIN_PA11, 1); /* enable PWM3 */
  640. pwm_mask = mask;
  641. platform_device_register(&at91cap9_pwm0_device);
  642. }
  643. #else
  644. void __init at91_add_device_pwm(u32 mask) {}
  645. #endif
  646. /* --------------------------------------------------------------------
  647. * AC97
  648. * -------------------------------------------------------------------- */
  649. #if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
  650. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  651. static struct ac97c_platform_data ac97_data;
  652. static struct resource ac97_resources[] = {
  653. [0] = {
  654. .start = AT91CAP9_BASE_AC97C,
  655. .end = AT91CAP9_BASE_AC97C + SZ_16K - 1,
  656. .flags = IORESOURCE_MEM,
  657. },
  658. [1] = {
  659. .start = AT91CAP9_ID_AC97C,
  660. .end = AT91CAP9_ID_AC97C,
  661. .flags = IORESOURCE_IRQ,
  662. },
  663. };
  664. static struct platform_device at91cap9_ac97_device = {
  665. .name = "atmel_ac97c",
  666. .id = 1,
  667. .dev = {
  668. .dma_mask = &ac97_dmamask,
  669. .coherent_dma_mask = DMA_BIT_MASK(32),
  670. .platform_data = &ac97_data,
  671. },
  672. .resource = ac97_resources,
  673. .num_resources = ARRAY_SIZE(ac97_resources),
  674. };
  675. void __init at91_add_device_ac97(struct ac97c_platform_data *data)
  676. {
  677. if (!data)
  678. return;
  679. at91_set_A_periph(AT91_PIN_PA6, 0); /* AC97FS */
  680. at91_set_A_periph(AT91_PIN_PA7, 0); /* AC97CK */
  681. at91_set_A_periph(AT91_PIN_PA8, 0); /* AC97TX */
  682. at91_set_A_periph(AT91_PIN_PA9, 0); /* AC97RX */
  683. /* reset */
  684. if (gpio_is_valid(data->reset_pin))
  685. at91_set_gpio_output(data->reset_pin, 0);
  686. ac97_data = *data;
  687. platform_device_register(&at91cap9_ac97_device);
  688. }
  689. #else
  690. void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
  691. #endif
  692. /* --------------------------------------------------------------------
  693. * LCD Controller
  694. * -------------------------------------------------------------------- */
  695. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  696. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  697. static struct atmel_lcdfb_info lcdc_data;
  698. static struct resource lcdc_resources[] = {
  699. [0] = {
  700. .start = AT91CAP9_LCDC_BASE,
  701. .end = AT91CAP9_LCDC_BASE + SZ_4K - 1,
  702. .flags = IORESOURCE_MEM,
  703. },
  704. [1] = {
  705. .start = AT91CAP9_ID_LCDC,
  706. .end = AT91CAP9_ID_LCDC,
  707. .flags = IORESOURCE_IRQ,
  708. },
  709. };
  710. static struct platform_device at91_lcdc_device = {
  711. .name = "atmel_lcdfb",
  712. .id = 0,
  713. .dev = {
  714. .dma_mask = &lcdc_dmamask,
  715. .coherent_dma_mask = DMA_BIT_MASK(32),
  716. .platform_data = &lcdc_data,
  717. },
  718. .resource = lcdc_resources,
  719. .num_resources = ARRAY_SIZE(lcdc_resources),
  720. };
  721. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  722. {
  723. if (!data)
  724. return;
  725. if (cpu_is_at91cap9_revB())
  726. irq_set_irq_type(AT91CAP9_ID_LCDC, IRQ_TYPE_LEVEL_HIGH);
  727. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  728. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  729. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  730. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  731. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  732. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  733. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  734. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  735. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  736. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  737. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  738. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  739. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  740. at91_set_A_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  741. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  742. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  743. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  744. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  745. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  746. at91_set_A_periph(AT91_PIN_PC25, 0); /* LCDD21 */
  747. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  748. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  749. lcdc_data = *data;
  750. platform_device_register(&at91_lcdc_device);
  751. }
  752. #else
  753. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  754. #endif
  755. /* --------------------------------------------------------------------
  756. * SSC -- Synchronous Serial Controller
  757. * -------------------------------------------------------------------- */
  758. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  759. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  760. static struct resource ssc0_resources[] = {
  761. [0] = {
  762. .start = AT91CAP9_BASE_SSC0,
  763. .end = AT91CAP9_BASE_SSC0 + SZ_16K - 1,
  764. .flags = IORESOURCE_MEM,
  765. },
  766. [1] = {
  767. .start = AT91CAP9_ID_SSC0,
  768. .end = AT91CAP9_ID_SSC0,
  769. .flags = IORESOURCE_IRQ,
  770. },
  771. };
  772. static struct platform_device at91cap9_ssc0_device = {
  773. .name = "ssc",
  774. .id = 0,
  775. .dev = {
  776. .dma_mask = &ssc0_dmamask,
  777. .coherent_dma_mask = DMA_BIT_MASK(32),
  778. },
  779. .resource = ssc0_resources,
  780. .num_resources = ARRAY_SIZE(ssc0_resources),
  781. };
  782. static inline void configure_ssc0_pins(unsigned pins)
  783. {
  784. if (pins & ATMEL_SSC_TF)
  785. at91_set_A_periph(AT91_PIN_PB0, 1);
  786. if (pins & ATMEL_SSC_TK)
  787. at91_set_A_periph(AT91_PIN_PB1, 1);
  788. if (pins & ATMEL_SSC_TD)
  789. at91_set_A_periph(AT91_PIN_PB2, 1);
  790. if (pins & ATMEL_SSC_RD)
  791. at91_set_A_periph(AT91_PIN_PB3, 1);
  792. if (pins & ATMEL_SSC_RK)
  793. at91_set_A_periph(AT91_PIN_PB4, 1);
  794. if (pins & ATMEL_SSC_RF)
  795. at91_set_A_periph(AT91_PIN_PB5, 1);
  796. }
  797. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  798. static struct resource ssc1_resources[] = {
  799. [0] = {
  800. .start = AT91CAP9_BASE_SSC1,
  801. .end = AT91CAP9_BASE_SSC1 + SZ_16K - 1,
  802. .flags = IORESOURCE_MEM,
  803. },
  804. [1] = {
  805. .start = AT91CAP9_ID_SSC1,
  806. .end = AT91CAP9_ID_SSC1,
  807. .flags = IORESOURCE_IRQ,
  808. },
  809. };
  810. static struct platform_device at91cap9_ssc1_device = {
  811. .name = "ssc",
  812. .id = 1,
  813. .dev = {
  814. .dma_mask = &ssc1_dmamask,
  815. .coherent_dma_mask = DMA_BIT_MASK(32),
  816. },
  817. .resource = ssc1_resources,
  818. .num_resources = ARRAY_SIZE(ssc1_resources),
  819. };
  820. static inline void configure_ssc1_pins(unsigned pins)
  821. {
  822. if (pins & ATMEL_SSC_TF)
  823. at91_set_A_periph(AT91_PIN_PB6, 1);
  824. if (pins & ATMEL_SSC_TK)
  825. at91_set_A_periph(AT91_PIN_PB7, 1);
  826. if (pins & ATMEL_SSC_TD)
  827. at91_set_A_periph(AT91_PIN_PB8, 1);
  828. if (pins & ATMEL_SSC_RD)
  829. at91_set_A_periph(AT91_PIN_PB9, 1);
  830. if (pins & ATMEL_SSC_RK)
  831. at91_set_A_periph(AT91_PIN_PB10, 1);
  832. if (pins & ATMEL_SSC_RF)
  833. at91_set_A_periph(AT91_PIN_PB11, 1);
  834. }
  835. /*
  836. * SSC controllers are accessed through library code, instead of any
  837. * kind of all-singing/all-dancing driver. For example one could be
  838. * used by a particular I2S audio codec's driver, while another one
  839. * on the same system might be used by a custom data capture driver.
  840. */
  841. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  842. {
  843. struct platform_device *pdev;
  844. /*
  845. * NOTE: caller is responsible for passing information matching
  846. * "pins" to whatever will be using each particular controller.
  847. */
  848. switch (id) {
  849. case AT91CAP9_ID_SSC0:
  850. pdev = &at91cap9_ssc0_device;
  851. configure_ssc0_pins(pins);
  852. break;
  853. case AT91CAP9_ID_SSC1:
  854. pdev = &at91cap9_ssc1_device;
  855. configure_ssc1_pins(pins);
  856. break;
  857. default:
  858. return;
  859. }
  860. platform_device_register(pdev);
  861. }
  862. #else
  863. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  864. #endif
  865. /* --------------------------------------------------------------------
  866. * UART
  867. * -------------------------------------------------------------------- */
  868. #if defined(CONFIG_SERIAL_ATMEL)
  869. static struct resource dbgu_resources[] = {
  870. [0] = {
  871. .start = AT91CAP9_BASE_DBGU,
  872. .end = AT91CAP9_BASE_DBGU + SZ_512 - 1,
  873. .flags = IORESOURCE_MEM,
  874. },
  875. [1] = {
  876. .start = AT91_ID_SYS,
  877. .end = AT91_ID_SYS,
  878. .flags = IORESOURCE_IRQ,
  879. },
  880. };
  881. static struct atmel_uart_data dbgu_data = {
  882. .use_dma_tx = 0,
  883. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  884. };
  885. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  886. static struct platform_device at91cap9_dbgu_device = {
  887. .name = "atmel_usart",
  888. .id = 0,
  889. .dev = {
  890. .dma_mask = &dbgu_dmamask,
  891. .coherent_dma_mask = DMA_BIT_MASK(32),
  892. .platform_data = &dbgu_data,
  893. },
  894. .resource = dbgu_resources,
  895. .num_resources = ARRAY_SIZE(dbgu_resources),
  896. };
  897. static inline void configure_dbgu_pins(void)
  898. {
  899. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  900. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  901. }
  902. static struct resource uart0_resources[] = {
  903. [0] = {
  904. .start = AT91CAP9_BASE_US0,
  905. .end = AT91CAP9_BASE_US0 + SZ_16K - 1,
  906. .flags = IORESOURCE_MEM,
  907. },
  908. [1] = {
  909. .start = AT91CAP9_ID_US0,
  910. .end = AT91CAP9_ID_US0,
  911. .flags = IORESOURCE_IRQ,
  912. },
  913. };
  914. static struct atmel_uart_data uart0_data = {
  915. .use_dma_tx = 1,
  916. .use_dma_rx = 1,
  917. };
  918. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  919. static struct platform_device at91cap9_uart0_device = {
  920. .name = "atmel_usart",
  921. .id = 1,
  922. .dev = {
  923. .dma_mask = &uart0_dmamask,
  924. .coherent_dma_mask = DMA_BIT_MASK(32),
  925. .platform_data = &uart0_data,
  926. },
  927. .resource = uart0_resources,
  928. .num_resources = ARRAY_SIZE(uart0_resources),
  929. };
  930. static inline void configure_usart0_pins(unsigned pins)
  931. {
  932. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  933. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  934. if (pins & ATMEL_UART_RTS)
  935. at91_set_A_periph(AT91_PIN_PA24, 0); /* RTS0 */
  936. if (pins & ATMEL_UART_CTS)
  937. at91_set_A_periph(AT91_PIN_PA25, 0); /* CTS0 */
  938. }
  939. static struct resource uart1_resources[] = {
  940. [0] = {
  941. .start = AT91CAP9_BASE_US1,
  942. .end = AT91CAP9_BASE_US1 + SZ_16K - 1,
  943. .flags = IORESOURCE_MEM,
  944. },
  945. [1] = {
  946. .start = AT91CAP9_ID_US1,
  947. .end = AT91CAP9_ID_US1,
  948. .flags = IORESOURCE_IRQ,
  949. },
  950. };
  951. static struct atmel_uart_data uart1_data = {
  952. .use_dma_tx = 1,
  953. .use_dma_rx = 1,
  954. };
  955. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  956. static struct platform_device at91cap9_uart1_device = {
  957. .name = "atmel_usart",
  958. .id = 2,
  959. .dev = {
  960. .dma_mask = &uart1_dmamask,
  961. .coherent_dma_mask = DMA_BIT_MASK(32),
  962. .platform_data = &uart1_data,
  963. },
  964. .resource = uart1_resources,
  965. .num_resources = ARRAY_SIZE(uart1_resources),
  966. };
  967. static inline void configure_usart1_pins(unsigned pins)
  968. {
  969. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  970. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  971. if (pins & ATMEL_UART_RTS)
  972. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  973. if (pins & ATMEL_UART_CTS)
  974. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  975. }
  976. static struct resource uart2_resources[] = {
  977. [0] = {
  978. .start = AT91CAP9_BASE_US2,
  979. .end = AT91CAP9_BASE_US2 + SZ_16K - 1,
  980. .flags = IORESOURCE_MEM,
  981. },
  982. [1] = {
  983. .start = AT91CAP9_ID_US2,
  984. .end = AT91CAP9_ID_US2,
  985. .flags = IORESOURCE_IRQ,
  986. },
  987. };
  988. static struct atmel_uart_data uart2_data = {
  989. .use_dma_tx = 1,
  990. .use_dma_rx = 1,
  991. };
  992. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  993. static struct platform_device at91cap9_uart2_device = {
  994. .name = "atmel_usart",
  995. .id = 3,
  996. .dev = {
  997. .dma_mask = &uart2_dmamask,
  998. .coherent_dma_mask = DMA_BIT_MASK(32),
  999. .platform_data = &uart2_data,
  1000. },
  1001. .resource = uart2_resources,
  1002. .num_resources = ARRAY_SIZE(uart2_resources),
  1003. };
  1004. static inline void configure_usart2_pins(unsigned pins)
  1005. {
  1006. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  1007. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  1008. if (pins & ATMEL_UART_RTS)
  1009. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  1010. if (pins & ATMEL_UART_CTS)
  1011. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  1012. }
  1013. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  1014. struct platform_device *atmel_default_console_device; /* the serial console device */
  1015. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  1016. {
  1017. struct platform_device *pdev;
  1018. struct atmel_uart_data *pdata;
  1019. switch (id) {
  1020. case 0: /* DBGU */
  1021. pdev = &at91cap9_dbgu_device;
  1022. configure_dbgu_pins();
  1023. break;
  1024. case AT91CAP9_ID_US0:
  1025. pdev = &at91cap9_uart0_device;
  1026. configure_usart0_pins(pins);
  1027. break;
  1028. case AT91CAP9_ID_US1:
  1029. pdev = &at91cap9_uart1_device;
  1030. configure_usart1_pins(pins);
  1031. break;
  1032. case AT91CAP9_ID_US2:
  1033. pdev = &at91cap9_uart2_device;
  1034. configure_usart2_pins(pins);
  1035. break;
  1036. default:
  1037. return;
  1038. }
  1039. pdata = pdev->dev.platform_data;
  1040. pdata->num = portnr; /* update to mapped ID */
  1041. if (portnr < ATMEL_MAX_UART)
  1042. at91_uarts[portnr] = pdev;
  1043. }
  1044. void __init at91_set_serial_console(unsigned portnr)
  1045. {
  1046. if (portnr < ATMEL_MAX_UART) {
  1047. atmel_default_console_device = at91_uarts[portnr];
  1048. at91cap9_set_console_clock(at91_uarts[portnr]->id);
  1049. }
  1050. }
  1051. void __init at91_add_device_serial(void)
  1052. {
  1053. int i;
  1054. for (i = 0; i < ATMEL_MAX_UART; i++) {
  1055. if (at91_uarts[i])
  1056. platform_device_register(at91_uarts[i]);
  1057. }
  1058. if (!atmel_default_console_device)
  1059. printk(KERN_INFO "AT91: No default serial console defined.\n");
  1060. }
  1061. #else
  1062. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  1063. void __init at91_set_serial_console(unsigned portnr) {}
  1064. void __init at91_add_device_serial(void) {}
  1065. #endif
  1066. /* -------------------------------------------------------------------- */
  1067. /*
  1068. * These devices are always present and don't need any board-specific
  1069. * setup.
  1070. */
  1071. static int __init at91_add_standard_devices(void)
  1072. {
  1073. at91_add_device_rtt();
  1074. at91_add_device_watchdog();
  1075. at91_add_device_tc();
  1076. return 0;
  1077. }
  1078. arch_initcall(at91_add_standard_devices);