at91cap9_devices.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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/mtd/physmap.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/at91sam926x_mc.h>
  24. #include <asm/arch/at91cap9_matrix.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. {
  243. .start = NAND_BASE,
  244. .end = NAND_BASE + SZ_256M - 1,
  245. .flags = IORESOURCE_MEM,
  246. }
  247. };
  248. static struct platform_device at91cap9_nand_device = {
  249. .name = "at91_nand",
  250. .id = -1,
  251. .dev = {
  252. .platform_data = &nand_data,
  253. },
  254. .resource = nand_resources,
  255. .num_resources = ARRAY_SIZE(nand_resources),
  256. };
  257. void __init at91_add_device_nand(struct at91_nand_data *data)
  258. {
  259. unsigned long csa, mode;
  260. if (!data)
  261. return;
  262. csa = at91_sys_read(AT91_MATRIX_EBICSA);
  263. at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA | AT91_MATRIX_EBI_VDDIOMSEL_3_3V);
  264. /* set the bus interface characteristics */
  265. at91_sys_write(AT91_SMC_SETUP(3), AT91_SMC_NWESETUP_(2) | AT91_SMC_NCS_WRSETUP_(1)
  266. | AT91_SMC_NRDSETUP_(2) | AT91_SMC_NCS_RDSETUP_(1));
  267. at91_sys_write(AT91_SMC_PULSE(3), AT91_SMC_NWEPULSE_(4) | AT91_SMC_NCS_WRPULSE_(6)
  268. | AT91_SMC_NRDPULSE_(4) | AT91_SMC_NCS_RDPULSE_(6));
  269. at91_sys_write(AT91_SMC_CYCLE(3), AT91_SMC_NWECYCLE_(8) | AT91_SMC_NRDCYCLE_(8));
  270. if (data->bus_width_16)
  271. mode = AT91_SMC_DBW_16;
  272. else
  273. mode = AT91_SMC_DBW_8;
  274. at91_sys_write(AT91_SMC_MODE(3), mode | AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_TDF_(1));
  275. /* enable pin */
  276. if (data->enable_pin)
  277. at91_set_gpio_output(data->enable_pin, 1);
  278. /* ready/busy pin */
  279. if (data->rdy_pin)
  280. at91_set_gpio_input(data->rdy_pin, 1);
  281. /* card detect pin */
  282. if (data->det_pin)
  283. at91_set_gpio_input(data->det_pin, 1);
  284. nand_data = *data;
  285. platform_device_register(&at91cap9_nand_device);
  286. }
  287. #else
  288. void __init at91_add_device_nand(struct at91_nand_data *data) {}
  289. #endif
  290. /* --------------------------------------------------------------------
  291. * TWI (i2c)
  292. * -------------------------------------------------------------------- */
  293. /*
  294. * Prefer the GPIO code since the TWI controller isn't robust
  295. * (gets overruns and underruns under load) and can only issue
  296. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  297. */
  298. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  299. static struct i2c_gpio_platform_data pdata = {
  300. .sda_pin = AT91_PIN_PB4,
  301. .sda_is_open_drain = 1,
  302. .scl_pin = AT91_PIN_PB5,
  303. .scl_is_open_drain = 1,
  304. .udelay = 2, /* ~100 kHz */
  305. };
  306. static struct platform_device at91cap9_twi_device = {
  307. .name = "i2c-gpio",
  308. .id = -1,
  309. .dev.platform_data = &pdata,
  310. };
  311. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  312. {
  313. at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
  314. at91_set_multi_drive(AT91_PIN_PB4, 1);
  315. at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
  316. at91_set_multi_drive(AT91_PIN_PB5, 1);
  317. i2c_register_board_info(0, devices, nr_devices);
  318. platform_device_register(&at91cap9_twi_device);
  319. }
  320. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  321. static struct resource twi_resources[] = {
  322. [0] = {
  323. .start = AT91CAP9_BASE_TWI,
  324. .end = AT91CAP9_BASE_TWI + SZ_16K - 1,
  325. .flags = IORESOURCE_MEM,
  326. },
  327. [1] = {
  328. .start = AT91CAP9_ID_TWI,
  329. .end = AT91CAP9_ID_TWI,
  330. .flags = IORESOURCE_IRQ,
  331. },
  332. };
  333. static struct platform_device at91cap9_twi_device = {
  334. .name = "at91_i2c",
  335. .id = -1,
  336. .resource = twi_resources,
  337. .num_resources = ARRAY_SIZE(twi_resources),
  338. };
  339. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  340. {
  341. /* pins used for TWI interface */
  342. at91_set_B_periph(AT91_PIN_PB4, 0); /* TWD */
  343. at91_set_multi_drive(AT91_PIN_PB4, 1);
  344. at91_set_B_periph(AT91_PIN_PB5, 0); /* TWCK */
  345. at91_set_multi_drive(AT91_PIN_PB5, 1);
  346. i2c_register_board_info(0, devices, nr_devices);
  347. platform_device_register(&at91cap9_twi_device);
  348. }
  349. #else
  350. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  351. #endif
  352. /* --------------------------------------------------------------------
  353. * SPI
  354. * -------------------------------------------------------------------- */
  355. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  356. static u64 spi_dmamask = DMA_BIT_MASK(32);
  357. static struct resource spi0_resources[] = {
  358. [0] = {
  359. .start = AT91CAP9_BASE_SPI0,
  360. .end = AT91CAP9_BASE_SPI0 + SZ_16K - 1,
  361. .flags = IORESOURCE_MEM,
  362. },
  363. [1] = {
  364. .start = AT91CAP9_ID_SPI0,
  365. .end = AT91CAP9_ID_SPI0,
  366. .flags = IORESOURCE_IRQ,
  367. },
  368. };
  369. static struct platform_device at91cap9_spi0_device = {
  370. .name = "atmel_spi",
  371. .id = 0,
  372. .dev = {
  373. .dma_mask = &spi_dmamask,
  374. .coherent_dma_mask = DMA_BIT_MASK(32),
  375. },
  376. .resource = spi0_resources,
  377. .num_resources = ARRAY_SIZE(spi0_resources),
  378. };
  379. static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PD0, AT91_PIN_PD1 };
  380. static struct resource spi1_resources[] = {
  381. [0] = {
  382. .start = AT91CAP9_BASE_SPI1,
  383. .end = AT91CAP9_BASE_SPI1 + SZ_16K - 1,
  384. .flags = IORESOURCE_MEM,
  385. },
  386. [1] = {
  387. .start = AT91CAP9_ID_SPI1,
  388. .end = AT91CAP9_ID_SPI1,
  389. .flags = IORESOURCE_IRQ,
  390. },
  391. };
  392. static struct platform_device at91cap9_spi1_device = {
  393. .name = "atmel_spi",
  394. .id = 1,
  395. .dev = {
  396. .dma_mask = &spi_dmamask,
  397. .coherent_dma_mask = DMA_BIT_MASK(32),
  398. },
  399. .resource = spi1_resources,
  400. .num_resources = ARRAY_SIZE(spi1_resources),
  401. };
  402. static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
  403. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
  404. {
  405. int i;
  406. unsigned long cs_pin;
  407. short enable_spi0 = 0;
  408. short enable_spi1 = 0;
  409. /* Choose SPI chip-selects */
  410. for (i = 0; i < nr_devices; i++) {
  411. if (devices[i].controller_data)
  412. cs_pin = (unsigned long) devices[i].controller_data;
  413. else if (devices[i].bus_num == 0)
  414. cs_pin = spi0_standard_cs[devices[i].chip_select];
  415. else
  416. cs_pin = spi1_standard_cs[devices[i].chip_select];
  417. if (devices[i].bus_num == 0)
  418. enable_spi0 = 1;
  419. else
  420. enable_spi1 = 1;
  421. /* enable chip-select pin */
  422. at91_set_gpio_output(cs_pin, 1);
  423. /* pass chip-select pin to driver */
  424. devices[i].controller_data = (void *) cs_pin;
  425. }
  426. spi_register_board_info(devices, nr_devices);
  427. /* Configure SPI bus(es) */
  428. if (enable_spi0) {
  429. at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
  430. at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
  431. at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
  432. at91_clock_associate("spi0_clk", &at91cap9_spi0_device.dev, "spi_clk");
  433. platform_device_register(&at91cap9_spi0_device);
  434. }
  435. if (enable_spi1) {
  436. at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
  437. at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
  438. at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
  439. at91_clock_associate("spi1_clk", &at91cap9_spi1_device.dev, "spi_clk");
  440. platform_device_register(&at91cap9_spi1_device);
  441. }
  442. }
  443. #else
  444. void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
  445. #endif
  446. /* --------------------------------------------------------------------
  447. * RTT
  448. * -------------------------------------------------------------------- */
  449. static struct platform_device at91cap9_rtt_device = {
  450. .name = "at91_rtt",
  451. .id = -1,
  452. .num_resources = 0,
  453. };
  454. static void __init at91_add_device_rtt(void)
  455. {
  456. platform_device_register(&at91cap9_rtt_device);
  457. }
  458. /* --------------------------------------------------------------------
  459. * Watchdog
  460. * -------------------------------------------------------------------- */
  461. #if defined(CONFIG_AT91SAM9_WATCHDOG) || defined(CONFIG_AT91SAM9_WATCHDOG_MODULE)
  462. static struct platform_device at91cap9_wdt_device = {
  463. .name = "at91_wdt",
  464. .id = -1,
  465. .num_resources = 0,
  466. };
  467. static void __init at91_add_device_watchdog(void)
  468. {
  469. platform_device_register(&at91cap9_wdt_device);
  470. }
  471. #else
  472. static void __init at91_add_device_watchdog(void) {}
  473. #endif
  474. /* --------------------------------------------------------------------
  475. * AC97
  476. * -------------------------------------------------------------------- */
  477. #if defined(CONFIG_SND_AT91_AC97) || defined(CONFIG_SND_AT91_AC97_MODULE)
  478. static u64 ac97_dmamask = DMA_BIT_MASK(32);
  479. static struct atmel_ac97_data ac97_data;
  480. static struct resource ac97_resources[] = {
  481. [0] = {
  482. .start = AT91CAP9_BASE_AC97C,
  483. .end = AT91CAP9_BASE_AC97C + SZ_16K - 1,
  484. .flags = IORESOURCE_MEM,
  485. },
  486. [1] = {
  487. .start = AT91CAP9_ID_AC97C,
  488. .end = AT91CAP9_ID_AC97C,
  489. .flags = IORESOURCE_IRQ,
  490. },
  491. };
  492. static struct platform_device at91cap9_ac97_device = {
  493. .name = "ac97c",
  494. .id = 1,
  495. .dev = {
  496. .dma_mask = &ac97_dmamask,
  497. .coherent_dma_mask = DMA_BIT_MASK(32),
  498. .platform_data = &ac97_data,
  499. },
  500. .resource = ac97_resources,
  501. .num_resources = ARRAY_SIZE(ac97_resources),
  502. };
  503. void __init at91_add_device_ac97(struct atmel_ac97_data *data)
  504. {
  505. if (!data)
  506. return;
  507. at91_set_A_periph(AT91_PIN_PA6, 0); /* AC97FS */
  508. at91_set_A_periph(AT91_PIN_PA7, 0); /* AC97CK */
  509. at91_set_A_periph(AT91_PIN_PA8, 0); /* AC97TX */
  510. at91_set_A_periph(AT91_PIN_PA9, 0); /* AC97RX */
  511. /* reset */
  512. if (data->reset_pin)
  513. at91_set_gpio_output(data->reset_pin, 0);
  514. ac97_data = *data;
  515. platform_device_register(&at91cap9_ac97_device);
  516. }
  517. #else
  518. void __init at91_add_device_ac97(struct atmel_ac97_data *data) {}
  519. #endif
  520. /* --------------------------------------------------------------------
  521. * LCD Controller
  522. * -------------------------------------------------------------------- */
  523. #if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
  524. static u64 lcdc_dmamask = DMA_BIT_MASK(32);
  525. static struct atmel_lcdfb_info lcdc_data;
  526. static struct resource lcdc_resources[] = {
  527. [0] = {
  528. .start = AT91CAP9_LCDC_BASE,
  529. .end = AT91CAP9_LCDC_BASE + SZ_4K - 1,
  530. .flags = IORESOURCE_MEM,
  531. },
  532. [1] = {
  533. .start = AT91CAP9_ID_LCDC,
  534. .end = AT91CAP9_ID_LCDC,
  535. .flags = IORESOURCE_IRQ,
  536. },
  537. };
  538. static struct platform_device at91_lcdc_device = {
  539. .name = "atmel_lcdfb",
  540. .id = 0,
  541. .dev = {
  542. .dma_mask = &lcdc_dmamask,
  543. .coherent_dma_mask = DMA_BIT_MASK(32),
  544. .platform_data = &lcdc_data,
  545. },
  546. .resource = lcdc_resources,
  547. .num_resources = ARRAY_SIZE(lcdc_resources),
  548. };
  549. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
  550. {
  551. if (!data)
  552. return;
  553. at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
  554. at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
  555. at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
  556. at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
  557. at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
  558. at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
  559. at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
  560. at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
  561. at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
  562. at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
  563. at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
  564. at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
  565. at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
  566. at91_set_A_periph(AT91_PIN_PC17, 0); /* LCDD13 */
  567. at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
  568. at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
  569. at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
  570. at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
  571. at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
  572. at91_set_A_periph(AT91_PIN_PC25, 0); /* LCDD21 */
  573. at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
  574. at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
  575. lcdc_data = *data;
  576. platform_device_register(&at91_lcdc_device);
  577. }
  578. #else
  579. void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
  580. #endif
  581. /* --------------------------------------------------------------------
  582. * SSC -- Synchronous Serial Controller
  583. * -------------------------------------------------------------------- */
  584. #if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
  585. static u64 ssc0_dmamask = DMA_BIT_MASK(32);
  586. static struct resource ssc0_resources[] = {
  587. [0] = {
  588. .start = AT91CAP9_BASE_SSC0,
  589. .end = AT91CAP9_BASE_SSC0 + SZ_16K - 1,
  590. .flags = IORESOURCE_MEM,
  591. },
  592. [1] = {
  593. .start = AT91CAP9_ID_SSC0,
  594. .end = AT91CAP9_ID_SSC0,
  595. .flags = IORESOURCE_IRQ,
  596. },
  597. };
  598. static struct platform_device at91cap9_ssc0_device = {
  599. .name = "ssc",
  600. .id = 0,
  601. .dev = {
  602. .dma_mask = &ssc0_dmamask,
  603. .coherent_dma_mask = DMA_BIT_MASK(32),
  604. },
  605. .resource = ssc0_resources,
  606. .num_resources = ARRAY_SIZE(ssc0_resources),
  607. };
  608. static inline void configure_ssc0_pins(unsigned pins)
  609. {
  610. if (pins & ATMEL_SSC_TF)
  611. at91_set_A_periph(AT91_PIN_PB0, 1);
  612. if (pins & ATMEL_SSC_TK)
  613. at91_set_A_periph(AT91_PIN_PB1, 1);
  614. if (pins & ATMEL_SSC_TD)
  615. at91_set_A_periph(AT91_PIN_PB2, 1);
  616. if (pins & ATMEL_SSC_RD)
  617. at91_set_A_periph(AT91_PIN_PB3, 1);
  618. if (pins & ATMEL_SSC_RK)
  619. at91_set_A_periph(AT91_PIN_PB4, 1);
  620. if (pins & ATMEL_SSC_RF)
  621. at91_set_A_periph(AT91_PIN_PB5, 1);
  622. }
  623. static u64 ssc1_dmamask = DMA_BIT_MASK(32);
  624. static struct resource ssc1_resources[] = {
  625. [0] = {
  626. .start = AT91CAP9_BASE_SSC1,
  627. .end = AT91CAP9_BASE_SSC1 + SZ_16K - 1,
  628. .flags = IORESOURCE_MEM,
  629. },
  630. [1] = {
  631. .start = AT91CAP9_ID_SSC1,
  632. .end = AT91CAP9_ID_SSC1,
  633. .flags = IORESOURCE_IRQ,
  634. },
  635. };
  636. static struct platform_device at91cap9_ssc1_device = {
  637. .name = "ssc",
  638. .id = 1,
  639. .dev = {
  640. .dma_mask = &ssc1_dmamask,
  641. .coherent_dma_mask = DMA_BIT_MASK(32),
  642. },
  643. .resource = ssc1_resources,
  644. .num_resources = ARRAY_SIZE(ssc1_resources),
  645. };
  646. static inline void configure_ssc1_pins(unsigned pins)
  647. {
  648. if (pins & ATMEL_SSC_TF)
  649. at91_set_A_periph(AT91_PIN_PB6, 1);
  650. if (pins & ATMEL_SSC_TK)
  651. at91_set_A_periph(AT91_PIN_PB7, 1);
  652. if (pins & ATMEL_SSC_TD)
  653. at91_set_A_periph(AT91_PIN_PB8, 1);
  654. if (pins & ATMEL_SSC_RD)
  655. at91_set_A_periph(AT91_PIN_PB9, 1);
  656. if (pins & ATMEL_SSC_RK)
  657. at91_set_A_periph(AT91_PIN_PB10, 1);
  658. if (pins & ATMEL_SSC_RF)
  659. at91_set_A_periph(AT91_PIN_PB11, 1);
  660. }
  661. /*
  662. * SSC controllers are accessed through library code, instead of any
  663. * kind of all-singing/all-dancing driver. For example one could be
  664. * used by a particular I2S audio codec's driver, while another one
  665. * on the same system might be used by a custom data capture driver.
  666. */
  667. void __init at91_add_device_ssc(unsigned id, unsigned pins)
  668. {
  669. struct platform_device *pdev;
  670. /*
  671. * NOTE: caller is responsible for passing information matching
  672. * "pins" to whatever will be using each particular controller.
  673. */
  674. switch (id) {
  675. case AT91CAP9_ID_SSC0:
  676. pdev = &at91cap9_ssc0_device;
  677. configure_ssc0_pins(pins);
  678. at91_clock_associate("ssc0_clk", &pdev->dev, "ssc");
  679. break;
  680. case AT91CAP9_ID_SSC1:
  681. pdev = &at91cap9_ssc1_device;
  682. configure_ssc1_pins(pins);
  683. at91_clock_associate("ssc1_clk", &pdev->dev, "ssc");
  684. break;
  685. default:
  686. return;
  687. }
  688. platform_device_register(pdev);
  689. }
  690. #else
  691. void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
  692. #endif
  693. /* --------------------------------------------------------------------
  694. * UART
  695. * -------------------------------------------------------------------- */
  696. #if defined(CONFIG_SERIAL_ATMEL)
  697. static struct resource dbgu_resources[] = {
  698. [0] = {
  699. .start = AT91_VA_BASE_SYS + AT91_DBGU,
  700. .end = AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
  701. .flags = IORESOURCE_MEM,
  702. },
  703. [1] = {
  704. .start = AT91_ID_SYS,
  705. .end = AT91_ID_SYS,
  706. .flags = IORESOURCE_IRQ,
  707. },
  708. };
  709. static struct atmel_uart_data dbgu_data = {
  710. .use_dma_tx = 0,
  711. .use_dma_rx = 0, /* DBGU not capable of receive DMA */
  712. .regs = (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
  713. };
  714. static u64 dbgu_dmamask = DMA_BIT_MASK(32);
  715. static struct platform_device at91cap9_dbgu_device = {
  716. .name = "atmel_usart",
  717. .id = 0,
  718. .dev = {
  719. .dma_mask = &dbgu_dmamask,
  720. .coherent_dma_mask = DMA_BIT_MASK(32),
  721. .platform_data = &dbgu_data,
  722. },
  723. .resource = dbgu_resources,
  724. .num_resources = ARRAY_SIZE(dbgu_resources),
  725. };
  726. static inline void configure_dbgu_pins(void)
  727. {
  728. at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
  729. at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
  730. }
  731. static struct resource uart0_resources[] = {
  732. [0] = {
  733. .start = AT91CAP9_BASE_US0,
  734. .end = AT91CAP9_BASE_US0 + SZ_16K - 1,
  735. .flags = IORESOURCE_MEM,
  736. },
  737. [1] = {
  738. .start = AT91CAP9_ID_US0,
  739. .end = AT91CAP9_ID_US0,
  740. .flags = IORESOURCE_IRQ,
  741. },
  742. };
  743. static struct atmel_uart_data uart0_data = {
  744. .use_dma_tx = 1,
  745. .use_dma_rx = 1,
  746. };
  747. static u64 uart0_dmamask = DMA_BIT_MASK(32);
  748. static struct platform_device at91cap9_uart0_device = {
  749. .name = "atmel_usart",
  750. .id = 1,
  751. .dev = {
  752. .dma_mask = &uart0_dmamask,
  753. .coherent_dma_mask = DMA_BIT_MASK(32),
  754. .platform_data = &uart0_data,
  755. },
  756. .resource = uart0_resources,
  757. .num_resources = ARRAY_SIZE(uart0_resources),
  758. };
  759. static inline void configure_usart0_pins(unsigned pins)
  760. {
  761. at91_set_A_periph(AT91_PIN_PA22, 1); /* TXD0 */
  762. at91_set_A_periph(AT91_PIN_PA23, 0); /* RXD0 */
  763. if (pins & ATMEL_UART_RTS)
  764. at91_set_A_periph(AT91_PIN_PA24, 0); /* RTS0 */
  765. if (pins & ATMEL_UART_CTS)
  766. at91_set_A_periph(AT91_PIN_PA25, 0); /* CTS0 */
  767. }
  768. static struct resource uart1_resources[] = {
  769. [0] = {
  770. .start = AT91CAP9_BASE_US1,
  771. .end = AT91CAP9_BASE_US1 + SZ_16K - 1,
  772. .flags = IORESOURCE_MEM,
  773. },
  774. [1] = {
  775. .start = AT91CAP9_ID_US1,
  776. .end = AT91CAP9_ID_US1,
  777. .flags = IORESOURCE_IRQ,
  778. },
  779. };
  780. static struct atmel_uart_data uart1_data = {
  781. .use_dma_tx = 1,
  782. .use_dma_rx = 1,
  783. };
  784. static u64 uart1_dmamask = DMA_BIT_MASK(32);
  785. static struct platform_device at91cap9_uart1_device = {
  786. .name = "atmel_usart",
  787. .id = 2,
  788. .dev = {
  789. .dma_mask = &uart1_dmamask,
  790. .coherent_dma_mask = DMA_BIT_MASK(32),
  791. .platform_data = &uart1_data,
  792. },
  793. .resource = uart1_resources,
  794. .num_resources = ARRAY_SIZE(uart1_resources),
  795. };
  796. static inline void configure_usart1_pins(unsigned pins)
  797. {
  798. at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
  799. at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
  800. if (pins & ATMEL_UART_RTS)
  801. at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
  802. if (pins & ATMEL_UART_CTS)
  803. at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
  804. }
  805. static struct resource uart2_resources[] = {
  806. [0] = {
  807. .start = AT91CAP9_BASE_US2,
  808. .end = AT91CAP9_BASE_US2 + SZ_16K - 1,
  809. .flags = IORESOURCE_MEM,
  810. },
  811. [1] = {
  812. .start = AT91CAP9_ID_US2,
  813. .end = AT91CAP9_ID_US2,
  814. .flags = IORESOURCE_IRQ,
  815. },
  816. };
  817. static struct atmel_uart_data uart2_data = {
  818. .use_dma_tx = 1,
  819. .use_dma_rx = 1,
  820. };
  821. static u64 uart2_dmamask = DMA_BIT_MASK(32);
  822. static struct platform_device at91cap9_uart2_device = {
  823. .name = "atmel_usart",
  824. .id = 3,
  825. .dev = {
  826. .dma_mask = &uart2_dmamask,
  827. .coherent_dma_mask = DMA_BIT_MASK(32),
  828. .platform_data = &uart2_data,
  829. },
  830. .resource = uart2_resources,
  831. .num_resources = ARRAY_SIZE(uart2_resources),
  832. };
  833. static inline void configure_usart2_pins(unsigned pins)
  834. {
  835. at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
  836. at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
  837. if (pins & ATMEL_UART_RTS)
  838. at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
  839. if (pins & ATMEL_UART_CTS)
  840. at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
  841. }
  842. static struct platform_device *at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
  843. struct platform_device *atmel_default_console_device; /* the serial console device */
  844. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
  845. {
  846. struct platform_device *pdev;
  847. switch (id) {
  848. case 0: /* DBGU */
  849. pdev = &at91cap9_dbgu_device;
  850. configure_dbgu_pins();
  851. at91_clock_associate("mck", &pdev->dev, "usart");
  852. break;
  853. case AT91CAP9_ID_US0:
  854. pdev = &at91cap9_uart0_device;
  855. configure_usart0_pins(pins);
  856. at91_clock_associate("usart0_clk", &pdev->dev, "usart");
  857. break;
  858. case AT91CAP9_ID_US1:
  859. pdev = &at91cap9_uart1_device;
  860. configure_usart1_pins(pins);
  861. at91_clock_associate("usart1_clk", &pdev->dev, "usart");
  862. break;
  863. case AT91CAP9_ID_US2:
  864. pdev = &at91cap9_uart2_device;
  865. configure_usart2_pins(pins);
  866. at91_clock_associate("usart2_clk", &pdev->dev, "usart");
  867. break;
  868. default:
  869. return;
  870. }
  871. pdev->id = portnr; /* update to mapped ID */
  872. if (portnr < ATMEL_MAX_UART)
  873. at91_uarts[portnr] = pdev;
  874. }
  875. void __init at91_set_serial_console(unsigned portnr)
  876. {
  877. if (portnr < ATMEL_MAX_UART)
  878. atmel_default_console_device = at91_uarts[portnr];
  879. if (!atmel_default_console_device)
  880. printk(KERN_INFO "AT91: No default serial console defined.\n");
  881. }
  882. void __init at91_add_device_serial(void)
  883. {
  884. int i;
  885. for (i = 0; i < ATMEL_MAX_UART; i++) {
  886. if (at91_uarts[i])
  887. platform_device_register(at91_uarts[i]);
  888. }
  889. }
  890. #else
  891. void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
  892. void __init at91_set_serial_console(unsigned portnr) {}
  893. void __init at91_add_device_serial(void) {}
  894. #endif
  895. /* -------------------------------------------------------------------- */
  896. /*
  897. * These devices are always present and don't need any board-specific
  898. * setup.
  899. */
  900. static int __init at91_add_standard_devices(void)
  901. {
  902. at91_add_device_rtt();
  903. at91_add_device_watchdog();
  904. return 0;
  905. }
  906. arch_initcall(at91_add_standard_devices);