at91cap9_devices.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  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 <asm/arch/board.h>
  21. #include <asm/arch/gpio.h>
  22. #include <asm/arch/at91cap9.h>
  23. #include <asm/arch/at91cap9_matrix.h>
  24. #include <asm/arch/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. * Ethernet
  73. * -------------------------------------------------------------------- */
  74. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  75. static u64 eth_dmamask = DMA_BIT_MASK(32);
  76. static struct at91_eth_data eth_data;
  77. static struct resource eth_resources[] = {
  78. [0] = {
  79. .start = AT91CAP9_BASE_EMAC,
  80. .end = AT91CAP9_BASE_EMAC + SZ_16K - 1,
  81. .flags = IORESOURCE_MEM,
  82. },
  83. [1] = {
  84. .start = AT91CAP9_ID_EMAC,
  85. .end = AT91CAP9_ID_EMAC,
  86. .flags = IORESOURCE_IRQ,
  87. },
  88. };
  89. static struct platform_device at91cap9_eth_device = {
  90. .name = "macb",
  91. .id = -1,
  92. .dev = {
  93. .dma_mask = &eth_dmamask,
  94. .coherent_dma_mask = DMA_BIT_MASK(32),
  95. .platform_data = &eth_data,
  96. },
  97. .resource = eth_resources,
  98. .num_resources = ARRAY_SIZE(eth_resources),
  99. };
  100. void __init at91_add_device_eth(struct at91_eth_data *data)
  101. {
  102. if (!data)
  103. return;
  104. if (data->phy_irq_pin) {
  105. at91_set_gpio_input(data->phy_irq_pin, 0);
  106. at91_set_deglitch(data->phy_irq_pin, 1);
  107. }
  108. /* Pins used for MII and RMII */
  109. at91_set_A_periph(AT91_PIN_PB21, 0); /* ETXCK_EREFCK */
  110. at91_set_A_periph(AT91_PIN_PB22, 0); /* ERXDV */
  111. at91_set_A_periph(AT91_PIN_PB25, 0); /* ERX0 */
  112. at91_set_A_periph(AT91_PIN_PB26, 0); /* ERX1 */
  113. at91_set_A_periph(AT91_PIN_PB27, 0); /* ERXER */
  114. at91_set_A_periph(AT91_PIN_PB28, 0); /* ETXEN */
  115. at91_set_A_periph(AT91_PIN_PB23, 0); /* ETX0 */
  116. at91_set_A_periph(AT91_PIN_PB24, 0); /* ETX1 */
  117. at91_set_A_periph(AT91_PIN_PB30, 0); /* EMDIO */
  118. at91_set_A_periph(AT91_PIN_PB29, 0); /* EMDC */
  119. if (!data->is_rmii) {
  120. at91_set_B_periph(AT91_PIN_PC25, 0); /* ECRS */
  121. at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
  122. at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
  123. at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
  124. at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
  125. at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
  126. at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
  127. at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
  128. }
  129. eth_data = *data;
  130. platform_device_register(&at91cap9_eth_device);
  131. }
  132. #else
  133. void __init at91_add_device_eth(struct at91_eth_data *data) {}
  134. #endif
  135. /* --------------------------------------------------------------------
  136. * MMC / SD
  137. * -------------------------------------------------------------------- */
  138. #if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
  139. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  140. static struct at91_mmc_data mmc0_data, mmc1_data;
  141. static struct resource mmc0_resources[] = {
  142. [0] = {
  143. .start = AT91CAP9_BASE_MCI0,
  144. .end = AT91CAP9_BASE_MCI0 + SZ_16K - 1,
  145. .flags = IORESOURCE_MEM,
  146. },
  147. [1] = {
  148. .start = AT91CAP9_ID_MCI0,
  149. .end = AT91CAP9_ID_MCI0,
  150. .flags = IORESOURCE_IRQ,
  151. },
  152. };
  153. static struct platform_device at91cap9_mmc0_device = {
  154. .name = "at91_mci",
  155. .id = 0,
  156. .dev = {
  157. .dma_mask = &mmc_dmamask,
  158. .coherent_dma_mask = DMA_BIT_MASK(32),
  159. .platform_data = &mmc0_data,
  160. },
  161. .resource = mmc0_resources,
  162. .num_resources = ARRAY_SIZE(mmc0_resources),
  163. };
  164. static struct resource mmc1_resources[] = {
  165. [0] = {
  166. .start = AT91CAP9_BASE_MCI1,
  167. .end = AT91CAP9_BASE_MCI1 + SZ_16K - 1,
  168. .flags = IORESOURCE_MEM,
  169. },
  170. [1] = {
  171. .start = AT91CAP9_ID_MCI1,
  172. .end = AT91CAP9_ID_MCI1,
  173. .flags = IORESOURCE_IRQ,
  174. },
  175. };
  176. static struct platform_device at91cap9_mmc1_device = {
  177. .name = "at91_mci",
  178. .id = 1,
  179. .dev = {
  180. .dma_mask = &mmc_dmamask,
  181. .coherent_dma_mask = DMA_BIT_MASK(32),
  182. .platform_data = &mmc1_data,
  183. },
  184. .resource = mmc1_resources,
  185. .num_resources = ARRAY_SIZE(mmc1_resources),
  186. };
  187. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
  188. {
  189. if (!data)
  190. return;
  191. /* input/irq */
  192. if (data->det_pin) {
  193. at91_set_gpio_input(data->det_pin, 1);
  194. at91_set_deglitch(data->det_pin, 1);
  195. }
  196. if (data->wp_pin)
  197. at91_set_gpio_input(data->wp_pin, 1);
  198. if (data->vcc_pin)
  199. at91_set_gpio_output(data->vcc_pin, 0);
  200. if (mmc_id == 0) { /* MCI0 */
  201. /* CLK */
  202. at91_set_A_periph(AT91_PIN_PA2, 0);
  203. /* CMD */
  204. at91_set_A_periph(AT91_PIN_PA1, 1);
  205. /* DAT0, maybe DAT1..DAT3 */
  206. at91_set_A_periph(AT91_PIN_PA0, 1);
  207. if (data->wire4) {
  208. at91_set_A_periph(AT91_PIN_PA3, 1);
  209. at91_set_A_periph(AT91_PIN_PA4, 1);
  210. at91_set_A_periph(AT91_PIN_PA5, 1);
  211. }
  212. mmc0_data = *data;
  213. at91_clock_associate("mci0_clk", &at91cap9_mmc1_device.dev, "mci_clk");
  214. platform_device_register(&at91cap9_mmc0_device);
  215. } else { /* MCI1 */
  216. /* CLK */
  217. at91_set_A_periph(AT91_PIN_PA16, 0);
  218. /* CMD */
  219. at91_set_A_periph(AT91_PIN_PA17, 1);
  220. /* DAT0, maybe DAT1..DAT3 */
  221. at91_set_A_periph(AT91_PIN_PA18, 1);
  222. if (data->wire4) {
  223. at91_set_A_periph(AT91_PIN_PA19, 1);
  224. at91_set_A_periph(AT91_PIN_PA20, 1);
  225. at91_set_A_periph(AT91_PIN_PA21, 1);
  226. }
  227. mmc1_data = *data;
  228. at91_clock_associate("mci1_clk", &at91cap9_mmc1_device.dev, "mci_clk");
  229. platform_device_register(&at91cap9_mmc1_device);
  230. }
  231. }
  232. #else
  233. void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
  234. #endif
  235. /* --------------------------------------------------------------------
  236. * NAND / SmartMedia
  237. * -------------------------------------------------------------------- */
  238. #if defined(CONFIG_MTD_NAND_AT91) || defined(CONFIG_MTD_NAND_AT91_MODULE)
  239. static struct at91_nand_data nand_data;
  240. #define NAND_BASE AT91_CHIPSELECT_3
  241. static struct resource nand_resources[] = {
  242. [0] = {
  243. .start = NAND_BASE,
  244. .end = NAND_BASE + SZ_256M - 1,
  245. .flags = IORESOURCE_MEM,
  246. },
  247. [1] = {
  248. .start = AT91_BASE_SYS + AT91_ECC,
  249. .end = AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
  250. .flags = IORESOURCE_MEM,
  251. }
  252. };
  253. static struct platform_device at91cap9_nand_device = {
  254. .name = "at91_nand",
  255. .id = -1,
  256. .dev = {
  257. .platform_data = &nand_data,
  258. },
  259. .resource = nand_resources,
  260. .num_resources = ARRAY_SIZE(nand_resources),
  261. };
  262. void __init at91_add_device_nand(struct at91_nand_data *data)
  263. {
  264. unsigned long csa, mode;
  265. if (!data)
  266. return;
  267. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  268. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  269. /* set the bus interface characteristics */
  270. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1)
  271. | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
  272. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6)
  273. | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
  274. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  275. if (data->bus_width_16)
  276. mode = AT91_SMC_DBW_16;
  277. else
  278. mode = AT91_SMC_DBW_8;
  279. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
  280. /* enable pin */
  281. if (data->enable_pin)
  282. at91_set_gpio_output(data->enable_pin, 1);
  283. /* ready/busy pin */
  284. if (data->rdy_pin)
  285. at91_set_gpio_input(data->rdy_pin, 1);
  286. /* card detect pin */
  287. if (data->det_pin)
  288. at91_set_gpio_input(data->det_pin, 1);
  289. nand_data = *data;
  290. platform_device_register(&at91cap9_nand_device);
  291. }
  292. #else
  293. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  294. #endif
  295. /* --------------------------------------------------------------------
  296. * TWI (i2c)
  297. * -------------------------------------------------------------------- */
  298. /*
  299. * Prefer the GPIO code since the TWI controller isn't robust
  300. * (gets overruns and underruns under load) and can only issue
  301. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  302. */
  303. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  304. static struct i2c_gpio_platform_data pdata = {
  305. .sda_pin = AT91_PIN_PB4,
  306. .sda_is_open_drain = 1,
  307. .scl_pin = AT91_PIN_PB5,
  308. .scl_is_open_drain = 1,
  309. .udelay = 2, /* ~100 kHz */
  310. };
  311. static struct platform_device at91cap9_twi_device = {
  312. .name = "i2c-gpio",
  313. .id = -1,
  314. .dev.platform_data = &pdata,
  315. };
  316. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  317. {
  318. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  319. at91_set_multi_drive(AT91_PIN_PB4, 1);
  320. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  321. at91_set_multi_drive(AT91_PIN_PB5, 1);
  322. i2c_register_board_info(0, devices, nr_devices);
  323. platform_device_register(&at91cap9_twi_device);
  324. }
  325. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  326. static struct resource twi_resources[] = {
  327. [0] = {
  328. .start = AT91CAP9_BASE_TWI,
  329. .end = AT91CAP9_BASE_TWI + SZ_16K - 1,
  330. .flags = IORESOURCE_MEM,
  331. },
  332. [1] = {
  333. .start = AT91CAP9_ID_TWI,
  334. .end = AT91CAP9_ID_TWI,
  335. .flags = IORESOURCE_IRQ,
  336. },
  337. };
  338. static struct platform_device at91cap9_twi_device = {
  339. .name = "at91_i2c",
  340. .id = -1,
  341. .resource = twi_resources,
  342. .num_resources = ARRAY_SIZE(twi_resources),
  343. };
  344. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  345. {
  346. /* pins used for TWI interface */
  347. at91_set_B_periph(AT91_PIN_PB4, 0); /* TWD */
  348. at91_set_multi_drive(AT91_PIN_PB4, 1);
  349. at91_set_B_periph(AT91_PIN_PB5, 0); /* TWCK */
  350. at91_set_multi_drive(AT91_PIN_PB5, 1);
  351. i2c_register_board_info(0, devices, nr_devices);
  352. platform_device_register(&at91cap9_twi_device);
  353. }
  354. #else
  355. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  356. #endif
  357. /* --------------------------------------------------------------------
  358. * SPI
  359. * -------------------------------------------------------------------- */
  360. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  361. static u64 spi_dmamask = DMA_BIT_MASK(32);
  362. static struct resource spi0_resources[] = {
  363. [0] = {
  364. .start = AT91CAP9_BASE_SPI0,
  365. .end = AT91CAP9_BASE_SPI0 + SZ_16K - 1,
  366. .flags = IORESOURCE_MEM,
  367. },
  368. [1] = {
  369. .start = AT91CAP9_ID_SPI0,
  370. .end = AT91CAP9_ID_SPI0,
  371. .flags = IORESOURCE_IRQ,
  372. },
  373. };
  374. static struct platform_device at91cap9_spi0_device = {
  375. .name = "atmel_spi",
  376. .id = 0,
  377. .dev = {
  378. .dma_mask = &spi_dmamask,
  379. .coherent_dma_mask = DMA_BIT_MASK(32),
  380. },
  381. .resource = spi0_resources,
  382. .num_resources = ARRAY_SIZE(spi0_resources),
  383. };
  384. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PD0, AT91_PIN_PD1 };
  385. static struct resource spi1_resources[] = {
  386. [0] = {
  387. .start = AT91CAP9_BASE_SPI1,
  388. .end = AT91CAP9_BASE_SPI1 + SZ_16K - 1,
  389. .flags = IORESOURCE_MEM,
  390. },
  391. [1] = {
  392. .start = AT91CAP9_ID_SPI1,
  393. .end = AT91CAP9_ID_SPI1,
  394. .flags = IORESOURCE_IRQ,
  395. },
  396. };
  397. static struct platform_device at91cap9_spi1_device = {
  398. .name = "atmel_spi",
  399. .id = 1,
  400. .dev = {
  401. .dma_mask = &spi_dmamask,
  402. .coherent_dma_mask = DMA_BIT_MASK(32),
  403. },
  404. .resource = spi1_resources,
  405. .num_resources = ARRAY_SIZE(spi1_resources),
  406. };
  407. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  408. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  409. {
  410. int i;
  411. unsigned long cs_pin;
  412. short enable_spi0 = 0;
  413. short enable_spi1 = 0;
  414. /* Choose SPI chip-selects */
  415. for (i = 0; i < nr_devices; i++) {
  416. if (devices[i].controller_data)
  417. cs_pin = (unsigned long) devices[i].controller_data;
  418. else if (devices[i].bus_num == 0)
  419. cs_pin = spi0_standard_cs[devices[i].chip_select];
  420. else
  421. cs_pin = spi1_standard_cs[devices[i].chip_select];
  422. if (devices[i].bus_num == 0)
  423. enable_spi0 = 1;
  424. else
  425. enable_spi1 = 1;
  426. /* enable chip-select pin */
  427. at91_set_gpio_output(cs_pin, 1);
  428. /* pass chip-select pin to driver */
  429. devices[i].controller_data = (void *) cs_pin;
  430. }
  431. spi_register_board_info(devices, nr_devices);
  432. /* Configure SPI bus(es) */
  433. if (enable_spi0) {
  434. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  435. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  436. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  437. at91_clock_associate("spi0_clk", &at91cap9_spi0_device.dev, "spi_clk");
  438. platform_device_register(&at91cap9_spi0_device);
  439. }
  440. if (enable_spi1) {
  441. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  442. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  443. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  444. at91_clock_associate("spi1_clk", &at91cap9_spi1_device.dev, "spi_clk");
  445. platform_device_register(&at91cap9_spi1_device);
  446. }
  447. }
  448. #else
  449. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  450. #endif
  451. /* --------------------------------------------------------------------
  452. * Timer/Counter block
  453. * -------------------------------------------------------------------- */
  454. #ifdef CONFIG_ATMEL_TCLIB
  455. static struct resource tcb_resources[] = {
  456. [0] = {
  457. .start = AT91CAP9_BASE_TCB0,
  458. .end = AT91CAP9_BASE_TCB0 + SZ_16K - 1,
  459. .flags = IORESOURCE_MEM,
  460. },
  461. [1] = {
  462. .start = AT91CAP9_ID_TCB,
  463. .end = AT91CAP9_ID_TCB,
  464. .flags = IORESOURCE_IRQ,
  465. },
  466. };
  467. static struct platform_device at91cap9_tcb_device = {
  468. .name = "atmel_tcb",
  469. .id = 0,
  470. .resource = tcb_resources,
  471. .num_resources = ARRAY_SIZE(tcb_resources),
  472. };
  473. static void __init at91_add_device_tc(void)
  474. {
  475. /* this chip has one clock and irq for all three TC channels */
  476. at91_clock_associate("tcb_clk", &at91cap9_tcb_device.dev, "t0_clk");
  477. platform_device_register(&at91cap9_tcb_device);
  478. }
  479. #else
  480. static void __init at91_add_device_tc(void) { }
  481. #endif
  482. /* --------------------------------------------------------------------
  483. * RTT
  484. * -------------------------------------------------------------------- */
  485. static struct resource rtt_resources[] = {
  486. {
  487. .start = AT91_BASE_SYS + AT91_RTT,
  488. .end = AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
  489. .flags = IORESOURCE_MEM,
  490. }
  491. };
  492. static struct platform_device at91cap9_rtt_device = {
  493. .name = "at91_rtt",
  494. .id = 0,
  495. .resource = rtt_resources,
  496. .num_resources = ARRAY_SIZE(rtt_resources),
  497. };
  498. static void __init at91_add_device_rtt(void)
  499. {
  500. platform_device_register(&at91cap9_rtt_device);
  501. }
  502. /* --------------------------------------------------------------------
  503. * Watchdog
  504. * -------------------------------------------------------------------- */
  505. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  506. static struct platform_device at91cap9_wdt_device = {
  507. .name = "at91_wdt",
  508. .id = -1,
  509. .num_resources = 0,
  510. };
  511. static void __init at91_add_device_watchdog(void)
  512. {
  513. platform_device_register(&at91cap9_wdt_device);
  514. }
  515. #else
  516. static void __init at91_add_device_watchdog(void) {}
  517. #endif
  518. /* --------------------------------------------------------------------
  519. * AC97
  520. * -------------------------------------------------------------------- */
  521. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  522. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  523. static struct atmel_ac97_data ac97_data;
  524. static struct resource ac97_resources[] = {
  525. [0] = {
  526. .start = AT91CAP9_BASE_AC97C,
  527. .end = AT91CAP9_BASE_AC97C + SZ_16K - 1,
  528. .flags = IORESOURCE_MEM,
  529. },
  530. [1] = {
  531. .start = AT91CAP9_ID_AC97C,
  532. .end = AT91CAP9_ID_AC97C,
  533. .flags = IORESOURCE_IRQ,
  534. },
  535. };
  536. static struct platform_device at91cap9_ac97_device = {
  537. .name = "ac97c",
  538. .id = 1,
  539. .dev = {
  540. .dma_mask = &ac97_dmamask,
  541. .coherent_dma_mask = DMA_BIT_MASK(32),
  542. .platform_data = &ac97_data,
  543. },
  544. .resource = ac97_resources,
  545. .num_resources = ARRAY_SIZE(ac97_resources),
  546. };
  547. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  548. {
  549. if (!data)
  550. return;
  551. at91_set_A_periph(AT91_PIN_PA6, 0); /* AC97FS */
  552. at91_set_A_periph(AT91_PIN_PA7, 0); /* AC97CK */
  553. at91_set_A_periph(AT91_PIN_PA8, 0); /* AC97TX */
  554. at91_set_A_periph(AT91_PIN_PA9, 0); /* AC97RX */
  555. /* reset */
  556. if (data->reset_pin)
  557. at91_set_gpio_output(data->reset_pin, 0);
  558. ac97_data = *data;
  559. platform_device_register(&at91cap9_ac97_device);
  560. }
  561. #else
  562. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  563. #endif
  564. /* --------------------------------------------------------------------
  565. * LCD Controller
  566. * -------------------------------------------------------------------- */
  567. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  568. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  569. static struct atmel_lcdfb_info lcdc_data;
  570. static struct resource lcdc_resources[] = {
  571. [0] = {
  572. .start = AT91CAP9_LCDC_BASE,
  573. .end = AT91CAP9_LCDC_BASE + SZ_4K - 1,
  574. .flags = IORESOURCE_MEM,
  575. },
  576. [1] = {
  577. .start = AT91CAP9_ID_LCDC,
  578. .end = AT91CAP9_ID_LCDC,
  579. .flags = IORESOURCE_IRQ,
  580. },
  581. };
  582. static struct platform_device at91_lcdc_device = {
  583. .name = "atmel_lcdfb",
  584. .id = 0,
  585. .dev = {
  586. .dma_mask = &lcdc_dmamask,
  587. .coherent_dma_mask = DMA_BIT_MASK(32),
  588. .platform_data = &lcdc_data,
  589. },
  590. .resource = lcdc_resources,
  591. .num_resources = ARRAY_SIZE(lcdc_resources),
  592. };
  593. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  594. {
  595. if (!data)
  596. return;
  597. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  598. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  599. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  600. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  601. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  602. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  603. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  604. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  605. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  606. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  607. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  608. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  609. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  610. at91_set_A_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  611. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  612. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  613. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  614. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  615. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  616. at91_set_A_periph(AT91_PIN_PC25, 0); /* LCDD21 */
  617. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  618. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  619. lcdc_data = *data;
  620. platform_device_register(&at91_lcdc_device);
  621. }
  622. #else
  623. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  624. #endif
  625. /* --------------------------------------------------------------------
  626. * SSC -- Synchronous Serial Controller
  627. * -------------------------------------------------------------------- */
  628. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  629. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  630. static struct resource ssc0_resources[] = {
  631. [0] = {
  632. .start = AT91CAP9_BASE_SSC0,
  633. .end = AT91CAP9_BASE_SSC0 + SZ_16K - 1,
  634. .flags = IORESOURCE_MEM,
  635. },
  636. [1] = {
  637. .start = AT91CAP9_ID_SSC0,
  638. .end = AT91CAP9_ID_SSC0,
  639. .flags = IORESOURCE_IRQ,
  640. },
  641. };
  642. static struct platform_device at91cap9_ssc0_device = {
  643. .name = "ssc",
  644. .id = 0,
  645. .dev = {
  646. .dma_mask = &ssc0_dmamask,
  647. .coherent_dma_mask = DMA_BIT_MASK(32),
  648. },
  649. .resource = ssc0_resources,
  650. .num_resources = ARRAY_SIZE(ssc0_resources),
  651. };
  652. static inline void configure_ssc0_pins(unsigned pins)
  653. {
  654. if (pins & ATMEL_SSC_TF)
  655. at91_set_A_periph(AT91_PIN_PB0, 1);
  656. if (pins & ATMEL_SSC_TK)
  657. at91_set_A_periph(AT91_PIN_PB1, 1);
  658. if (pins & ATMEL_SSC_TD)
  659. at91_set_A_periph(AT91_PIN_PB2, 1);
  660. if (pins & ATMEL_SSC_RD)
  661. at91_set_A_periph(AT91_PIN_PB3, 1);
  662. if (pins & ATMEL_SSC_RK)
  663. at91_set_A_periph(AT91_PIN_PB4, 1);
  664. if (pins & ATMEL_SSC_RF)
  665. at91_set_A_periph(AT91_PIN_PB5, 1);
  666. }
  667. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  668. static struct resource ssc1_resources[] = {
  669. [0] = {
  670. .start = AT91CAP9_BASE_SSC1,
  671. .end = AT91CAP9_BASE_SSC1 + SZ_16K - 1,
  672. .flags = IORESOURCE_MEM,
  673. },
  674. [1] = {
  675. .start = AT91CAP9_ID_SSC1,
  676. .end = AT91CAP9_ID_SSC1,
  677. .flags = IORESOURCE_IRQ,
  678. },
  679. };
  680. static struct platform_device at91cap9_ssc1_device = {
  681. .name = "ssc",
  682. .id = 1,
  683. .dev = {
  684. .dma_mask = &ssc1_dmamask,
  685. .coherent_dma_mask = DMA_BIT_MASK(32),
  686. },
  687. .resource = ssc1_resources,
  688. .num_resources = ARRAY_SIZE(ssc1_resources),
  689. };
  690. static inline void configure_ssc1_pins(unsigned pins)
  691. {
  692. if (pins & ATMEL_SSC_TF)
  693. at91_set_A_periph(AT91_PIN_PB6, 1);
  694. if (pins & ATMEL_SSC_TK)
  695. at91_set_A_periph(AT91_PIN_PB7, 1);
  696. if (pins & ATMEL_SSC_TD)
  697. at91_set_A_periph(AT91_PIN_PB8, 1);
  698. if (pins & ATMEL_SSC_RD)
  699. at91_set_A_periph(AT91_PIN_PB9, 1);
  700. if (pins & ATMEL_SSC_RK)
  701. at91_set_A_periph(AT91_PIN_PB10, 1);
  702. if (pins & ATMEL_SSC_RF)
  703. at91_set_A_periph(AT91_PIN_PB11, 1);
  704. }
  705. /*
  706. * SSC controllers are accessed through library code, instead of any
  707. * kind of all-singing/all-dancing driver. For example one could be
  708. * used by a particular I2S audio codec's driver, while another one
  709. * on the same system might be used by a custom data capture driver.
  710. */
  711. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  712. {
  713. struct platform_device *pdev;
  714. /*
  715. * NOTE: caller is responsible for passing information matching
  716. * "pins" to whatever will be using each particular controller.
  717. */
  718. switch (id) {
  719. case AT91CAP9_ID_SSC0:
  720. pdev = &at91cap9_ssc0_device;
  721. configure_ssc0_pins(pins);
  722. at91_clock_associate("ssc0_clk", &pdev->dev, "ssc");
  723. break;
  724. case AT91CAP9_ID_SSC1:
  725. pdev = &at91cap9_ssc1_device;
  726. configure_ssc1_pins(pins);
  727. at91_clock_associate("ssc1_clk", &pdev->dev, "ssc");
  728. break;
  729. default:
  730. return;
  731. }
  732. platform_device_register(pdev);
  733. }
  734. #else
  735. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  736. #endif
  737. /* --------------------------------------------------------------------
  738. * UART
  739. * -------------------------------------------------------------------- */
  740. #if defined(CONFIG_SERIAL_ATMEL)
  741. static struct resource dbgu_resources[] = {
  742. [0] = {
  743. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  744. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  745. .flags = IORESOURCE_MEM,
  746. },
  747. [1] = {
  748. .start = AT91_ID_SYS,
  749. .end = AT91_ID_SYS,
  750. .flags = IORESOURCE_IRQ,
  751. },
  752. };
  753. static struct atmel_uart_data dbgu_data = {
  754. .use_dma_tx = 0,
  755. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  756. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  757. };
  758. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  759. static struct platform_device at91cap9_dbgu_device = {
  760. .name = "atmel_usart",
  761. .id = 0,
  762. .dev = {
  763. .dma_mask = &dbgu_dmamask,
  764. .coherent_dma_mask = DMA_BIT_MASK(32),
  765. .platform_data = &dbgu_data,
  766. },
  767. .resource = dbgu_resources,
  768. .num_resources = ARRAY_SIZE(dbgu_resources),
  769. };
  770. static inline void configure_dbgu_pins(void)
  771. {
  772. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  773. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  774. }
  775. static struct resource uart0_resources[] = {
  776. [0] = {
  777. .start = AT91CAP9_BASE_US0,
  778. .end = AT91CAP9_BASE_US0 + SZ_16K - 1,
  779. .flags = IORESOURCE_MEM,
  780. },
  781. [1] = {
  782. .start = AT91CAP9_ID_US0,
  783. .end = AT91CAP9_ID_US0,
  784. .flags = IORESOURCE_IRQ,
  785. },
  786. };
  787. static struct atmel_uart_data uart0_data = {
  788. .use_dma_tx = 1,
  789. .use_dma_rx = 1,
  790. };
  791. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  792. static struct platform_device at91cap9_uart0_device = {
  793. .name = "atmel_usart",
  794. .id = 1,
  795. .dev = {
  796. .dma_mask = &uart0_dmamask,
  797. .coherent_dma_mask = DMA_BIT_MASK(32),
  798. .platform_data = &uart0_data,
  799. },
  800. .resource = uart0_resources,
  801. .num_resources = ARRAY_SIZE(uart0_resources),
  802. };
  803. static inline void configure_usart0_pins(unsigned pins)
  804. {
  805. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  806. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  807. if (pins & ATMEL_UART_RTS)
  808. at91_set_A_periph(AT91_PIN_PA24, 0); /* RTS0 */
  809. if (pins & ATMEL_UART_CTS)
  810. at91_set_A_periph(AT91_PIN_PA25, 0); /* CTS0 */
  811. }
  812. static struct resource uart1_resources[] = {
  813. [0] = {
  814. .start = AT91CAP9_BASE_US1,
  815. .end = AT91CAP9_BASE_US1 + SZ_16K - 1,
  816. .flags = IORESOURCE_MEM,
  817. },
  818. [1] = {
  819. .start = AT91CAP9_ID_US1,
  820. .end = AT91CAP9_ID_US1,
  821. .flags = IORESOURCE_IRQ,
  822. },
  823. };
  824. static struct atmel_uart_data uart1_data = {
  825. .use_dma_tx = 1,
  826. .use_dma_rx = 1,
  827. };
  828. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  829. static struct platform_device at91cap9_uart1_device = {
  830. .name = "atmel_usart",
  831. .id = 2,
  832. .dev = {
  833. .dma_mask = &uart1_dmamask,
  834. .coherent_dma_mask = DMA_BIT_MASK(32),
  835. .platform_data = &uart1_data,
  836. },
  837. .resource = uart1_resources,
  838. .num_resources = ARRAY_SIZE(uart1_resources),
  839. };
  840. static inline void configure_usart1_pins(unsigned pins)
  841. {
  842. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  843. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  844. if (pins & ATMEL_UART_RTS)
  845. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  846. if (pins & ATMEL_UART_CTS)
  847. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  848. }
  849. static struct resource uart2_resources[] = {
  850. [0] = {
  851. .start = AT91CAP9_BASE_US2,
  852. .end = AT91CAP9_BASE_US2 + SZ_16K - 1,
  853. .flags = IORESOURCE_MEM,
  854. },
  855. [1] = {
  856. .start = AT91CAP9_ID_US2,
  857. .end = AT91CAP9_ID_US2,
  858. .flags = IORESOURCE_IRQ,
  859. },
  860. };
  861. static struct atmel_uart_data uart2_data = {
  862. .use_dma_tx = 1,
  863. .use_dma_rx = 1,
  864. };
  865. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  866. static struct platform_device at91cap9_uart2_device = {
  867. .name = "atmel_usart",
  868. .id = 3,
  869. .dev = {
  870. .dma_mask = &uart2_dmamask,
  871. .coherent_dma_mask = DMA_BIT_MASK(32),
  872. .platform_data = &uart2_data,
  873. },
  874. .resource = uart2_resources,
  875. .num_resources = ARRAY_SIZE(uart2_resources),
  876. };
  877. static inline void configure_usart2_pins(unsigned pins)
  878. {
  879. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  880. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  881. if (pins & ATMEL_UART_RTS)
  882. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  883. if (pins & ATMEL_UART_CTS)
  884. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  885. }
  886. static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  887. struct platform_device *atmel_default_console_device; /* the serial console device */
  888. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  889. {
  890. struct platform_device *pdev;
  891. switch (id) {
  892. case 0: /* DBGU */
  893. pdev = &at91cap9_dbgu_device;
  894. configure_dbgu_pins();
  895. at91_clock_associate("mck", &pdev->dev, "usart");
  896. break;
  897. case AT91CAP9_ID_US0:
  898. pdev = &at91cap9_uart0_device;
  899. configure_usart0_pins(pins);
  900. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  901. break;
  902. case AT91CAP9_ID_US1:
  903. pdev = &at91cap9_uart1_device;
  904. configure_usart1_pins(pins);
  905. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  906. break;
  907. case AT91CAP9_ID_US2:
  908. pdev = &at91cap9_uart2_device;
  909. configure_usart2_pins(pins);
  910. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  911. break;
  912. default:
  913. return;
  914. }
  915. pdev->id = portnr; /* update to mapped ID */
  916. if (portnr < ATMEL_MAX_UART)
  917. at91_uarts[portnr] = pdev;
  918. }
  919. void __init at91_set_serial_console(unsigned portnr)
  920. {
  921. if (portnr < ATMEL_MAX_UART)
  922. atmel_default_console_device = at91_uarts[portnr];
  923. }
  924. void __init at91_add_device_serial(void)
  925. {
  926. int i;
  927. for (i = 0; i < ATMEL_MAX_UART; i++) {
  928. if (at91_uarts[i])
  929. platform_device_register(at91_uarts[i]);
  930. }
  931. if (!atmel_default_console_device)
  932. printk(KERN_INFO "AT91: No default serial console defined.\n");
  933. }
  934. #else
  935. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  936. void __init at91_set_serial_console(unsigned portnr) {}
  937. void __init at91_add_device_serial(void) {}
  938. #endif
  939. /* -------------------------------------------------------------------- */
  940. /*
  941. * These devices are always present and don't need any board-specific
  942. * setup.
  943. */
  944. static int __init at91_add_standard_devices(void)
  945. {
  946. at91_add_device_rtt();
  947. at91_add_device_watchdog();
  948. at91_add_device_tc();
  949. return 0;
  950. }
  951. arch_initcall(at91_add_standard_devices);