preliminaryDataProcessing.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * arch/arm/mach-at91/at91rm9200_devices.c
  3. *
  4. * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
  5. * Copyright (C) 2005 David Brownell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. */
  13. #include <asm/mach/arch.h>
  14. #include <asm/mach/map.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/gpio.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/i2c-gpio.h>
  19. #include <mach/at91rm9200.h>
  20. #include <mach/at91rm9200_mc.h>
  21. #include <mach/at91_ramc.h>
  22. #include "board.h"
  23. #include "generic.h"
  24. /* --------------------------------------------------------------------
  25. * USB Host
  26. * -------------------------------------------------------------------- */
  27. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  28. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  29. static struct at91_usbh_data usbh_data;
  30. static struct resource usbh_resources[] = {
  31. [0] = {
  32. .start = AT91RM9200_UHP_BASE,
  33. .end = AT91RM9200_UHP_BASE + SZ_1M - 1,
  34. .flags = IORESOURCE_MEM,
  35. },
  36. [1] = {
  37. .start = NR_IRQS_LEGACY + AT91RM9200_ID_UHP,
  38. .end = NR_IRQS_LEGACY + AT91RM9200_ID_UHP,
  39. .flags = IORESOURCE_IRQ,
  40. },
  41. };
  42. static struct platform_device at91rm9200_usbh_device = {
  43. .name = "at91_ohci",
  44. .id = -1,
  45. .dev = {
  46. .dma_mask = &ohci_dmamask,
  47. .coherent_dma_mask = DMA_BIT_MASK(32),
  48. .platform_data = &usbh_data,
  49. },
  50. .resource = usbh_resources,
  51. .num_resources = ARRAY_SIZE(usbh_resources),
  52. };
  53. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  54. {
  55. int i;
  56. if (!data)
  57. return;
  58. /* Enable overcurrent notification */
  59. for (i = 0; i < data->ports; i++) {
  60. if (gpio_is_valid(data->overcurrent_pin[i]))
  61. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  62. }
  63. usbh_data = *data;
  64. platform_device_register(&at91rm9200_usbh_device);
  65. }
  66. #else
  67. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  68. #endif
  69. /* --------------------------------------------------------------------
  70. * USB Device (Gadget)
  71. * -------------------------------------------------------------------- */
  72. #if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
  73. static struct at91_udc_data udc_data;
  74. static struct resource udc_resources[] = {
  75. [0] = {
  76. .start = AT91RM9200_BASE_UDP,
  77. .end = AT91RM9200_BASE_UDP + SZ_16K - 1,
  78. .flags = IORESOURCE_MEM,
  79. },
  80. [1] = {
  81. .start = NR_IRQS_LEGACY + AT91RM9200_ID_UDP,
  82. .end = NR_IRQS_LEGACY + AT91RM9200_ID_UDP,
  83. .flags = IORESOURCE_IRQ,
  84. },
  85. };
  86. static struct platform_device at91rm9200_udc_device = {
  87. .name = "at91_udc",
  88. .id = -1,
  89. .dev = {
  90. .platform_data = &udc_data,
  91. },
  92. .resource = udc_resources,
  93. .num_resources = ARRAY_SIZE(udc_resources),
  94. };
  95. void __init at91_add_device_udc(struct at91_udc_data *data)
  96. {
  97. if (!data)
  98. return;
  99. if (gpio_is_valid(data->vbus_pin)) {
  100. at91_set_gpio_input(data->vbus_pin, 0);
  101. at91_set_deglitch(data->vbus_pin, 1);
  102. }
  103. if (gpio_is_valid(data->pullup_pin))
  104. at91_set_gpio_output(data->pullup_pin, 0);
  105. udc_data = *data;
  106. platform_device_register(&at91rm9200_udc_device);
  107. }
  108. #else
  109. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  110. #endif
  111. /* --------------------------------------------------------------------
  112. * Ethernet
  113. * -------------------------------------------------------------------- */
  114. #if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
  115. static u64 eth_dmamask = DMA_BIT_MASK(32);
  116. static struct macb_platform_data eth_data;
  117. static struct resource eth_resources[] = {
  118. [0] = {
  119. .start = AT91RM9200_BASE_EMAC,
  120. .end = AT91RM9200_BASE_EMAC + SZ_16K - 1,
  121. .flags = IORESOURCE_MEM,
  122. },
  123. [1] = {
  124. .start = NR_IRQS_LEGACY + AT91RM9200_ID_EMAC,
  125. .end = NR_IRQS_LEGACY + AT91RM9200_ID_EMAC,
  126. .flags = IORESOURCE_IRQ,
  127. },
  128. };
  129. static struct platform_device at91rm9200_eth_device = {
  130. .name = "at91_ether",
  131. .id = -1,
  132. .dev = {
  133. .dma_mask = &eth_dmamask,
  134. .coherent_dma_mask = DMA_BIT_MASK(32),
  135. .platform_data = &eth_data,
  136. },
  137. .resource = eth_resources,
  138. .num_resources = ARRAY_SIZE(eth_resources),
  139. };
  140. void __init at91_add_device_eth(struct macb_platform_data *data)
  141. {
  142. if (!data)
  143. return;
  144. if (gpio_is_valid(data->phy_irq_pin)) {
  145. at91_set_gpio_input(data->phy_irq_pin, 0);
  146. at91_set_deglitch(data->phy_irq_pin, 1);
  147. }
  148. /* Pins used for MII and RMII */
  149. at91_set_A_periph(AT91_PIN_PA16, 0); /* EMDIO */
  150. at91_set_A_periph(AT91_PIN_PA15, 0); /* EMDC */
  151. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERXER */
  152. at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
  153. at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
  154. at91_set_A_periph(AT91_PIN_PA11, 0); /* ECRS_ECRSDV */
  155. at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX1 */
  156. at91_set_A_periph(AT91_PIN_PA9, 0); /* ETX0 */
  157. at91_set_A_periph(AT91_PIN_PA8, 0); /* ETXEN */
  158. at91_set_A_periph(AT91_PIN_PA7, 0); /* ETXCK_EREFCK */
  159. if (!data->is_rmii) {
  160. at91_set_B_periph(AT91_PIN_PB19, 0); /* ERXCK */
  161. at91_set_B_periph(AT91_PIN_PB18, 0); /* ECOL */
  162. at91_set_B_periph(AT91_PIN_PB17, 0); /* ERXDV */
  163. at91_set_B_periph(AT91_PIN_PB16, 0); /* ERX3 */
  164. at91_set_B_periph(AT91_PIN_PB15, 0); /* ERX2 */
  165. at91_set_B_periph(AT91_PIN_PB14, 0); /* ETXER */
  166. at91_set_B_periph(AT91_PIN_PB13, 0); /* ETX3 */
  167. at91_set_B_periph(AT91_PIN_PB12, 0); /* ETX2 */
  168. }
  169. eth_data = *data;
  170. platform_device_register(&at91rm9200_eth_device);
  171. }
  172. #else
  173. void __init at91_add_device_eth(struct macb_platform_data *data) {}
  174. #endif
  175. /* --------------------------------------------------------------------
  176. * Compact Flash / PCMCIA
  177. * -------------------------------------------------------------------- */
  178. #if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
  179. static struct at91_cf_data cf_data;
  180. #define CF_BASE AT91_CHIPSELECT_4
  181. static struct resource cf_resources[] = {
  182. [0] = {
  183. .start = CF_BASE,
  184. /* ties up CS4, CS5 and CS6 */
  185. .end = CF_BASE + (0x30000000 - 1),
  186. .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
  187. },
  188. };
  189. static struct platform_device at91rm9200_cf_device = {
  190. .name = "at91_cf",
  191. .id = -1,
  192. .dev = {
  193. .platform_data = &cf_data,
  194. },
  195. .resource = cf_resources,
  196. .num_resources = ARRAY_SIZE(cf_resources),
  197. };
  198. void __init at91_add_device_cf(struct at91_cf_data *data)
  199. {
  200. unsigned int csa;
  201. if (!data)
  202. return;
  203. data->chipselect = 4; /* can only use EBI ChipSelect 4 */
  204. /* CF takes over CS4, CS5, CS6 */
  205. csa = at91_ramc_read(0, AT91_EBI_CSA);
  206. at91_ramc_write(0, AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
  207. /*
  208. * Static memory controller timing adjustments.
  209. * REVISIT: these timings are in terms of MCK cycles, so
  210. * when MCK changes (cpufreq etc) so must these values...
  211. */
  212. at91_ramc_write(0, AT91_SMC_CSR(4),
  213. AT91_SMC_ACSS_STD
  214. | AT91_SMC_DBW_16
  215. | AT91_SMC_BAT
  216. | AT91_SMC_WSEN
  217. | AT91_SMC_NWS_(32) /* wait states */
  218. | AT91_SMC_RWSETUP_(6) /* setup time */
  219. | AT91_SMC_RWHOLD_(4) /* hold time */
  220. );
  221. /* input/irq */
  222. if (gpio_is_valid(data->irq_pin)) {
  223. at91_set_gpio_input(data->irq_pin, 1);
  224. at91_set_deglitch(data->irq_pin, 1);
  225. }
  226. at91_set_gpio_input(data->det_pin, 1);
  227. at91_set_deglitch(data->det_pin, 1);
  228. /* outputs, initially off */
  229. if (gpio_is_valid(data->vcc_pin))
  230. at91_set_gpio_output(data->vcc_pin, 0);
  231. at91_set_gpio_output(data->rst_pin, 0);
  232. /* force poweron defaults for these pins ... */
  233. at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
  234. at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
  235. at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
  236. at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
  237. /* nWAIT is _not_ a default setting */
  238. at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
  239. cf_data = *data;
  240. platform_device_register(&at91rm9200_cf_device);
  241. }
  242. #else
  243. void __init at91_add_device_cf(struct at91_cf_data *data) {}
  244. #endif
  245. /* --------------------------------------------------------------------
  246. * MMC / SD
  247. * -------------------------------------------------------------------- */
  248. #if IS_ENABLED(CONFIG_MMC_ATMELMCI)
  249. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  250. static struct mci_platform_data mmc_data;
  251. static struct resource mmc_resources[] = {
  252. [0] = {
  253. .start = AT91RM9200_BASE_MCI,
  254. .end = AT91RM9200_BASE_MCI + SZ_16K - 1,
  255. .flags = IORESOURCE_MEM,
  256. },
  257. [1] = {
  258. .start = NR_IRQS_LEGACY + AT91RM9200_ID_MCI,
  259. .end = NR_IRQS_LEGACY + AT91RM9200_ID_MCI,
  260. .flags = IORESOURCE_IRQ,
  261. },
  262. };
  263. static struct platform_device at91rm9200_mmc_device = {
  264. .name = "atmel_mci",
  265. .id = -1,
  266. .dev = {
  267. .dma_mask = &mmc_dmamask,
  268. .coherent_dma_mask = DMA_BIT_MASK(32),
  269. .platform_data = &mmc_data,
  270. },
  271. .resource = mmc_resources,
  272. .num_resources = ARRAY_SIZE(mmc_resources),
  273. };
  274. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
  275. {
  276. unsigned int i;
  277. unsigned int slot_count = 0;
  278. if (!data)
  279. return;
  280. for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
  281. if (!data->slot[i].bus_width)
  282. continue;
  283. /* input/irq */
  284. if (gpio_is_valid(data->slot[i].detect_pin)) {
  285. at91_set_gpio_input(data->slot[i].detect_pin, 1);
  286. at91_set_deglitch(data->slot[i].detect_pin, 1);
  287. }
  288. if (gpio_is_valid(data->slot[i].wp_pin))
  289. at91_set_gpio_input(data->slot[i].wp_pin, 1);
  290. switch (i) {
  291. case 0: /* slot A */
  292. /* CMD */
  293. at91_set_A_periph(AT91_PIN_PA28, 1);
  294. /* DAT0, maybe DAT1..DAT3 */
  295. at91_set_A_periph(AT91_PIN_PA29, 1);
  296. if (data->slot[i].bus_width == 4) {
  297. at91_set_B_periph(AT91_PIN_PB3, 1);
  298. at91_set_B_periph(AT91_PIN_PB4, 1);
  299. at91_set_B_periph(AT91_PIN_PB5, 1);
  300. }
  301. slot_count++;
  302. break;
  303. case 1: /* slot B */
  304. /* CMD */
  305. at91_set_B_periph(AT91_PIN_PA8, 1);
  306. /* DAT0, maybe DAT1..DAT3 */
  307. at91_set_B_periph(AT91_PIN_PA9, 1);
  308. if (data->slot[i].bus_width == 4) {
  309. at91_set_B_periph(AT91_PIN_PA10, 1);
  310. at91_set_B_periph(AT91_PIN_PA11, 1);
  311. at91_set_B_periph(AT91_PIN_PA12, 1);
  312. }
  313. slot_count++;
  314. break;
  315. default:
  316. printk(KERN_ERR
  317. "AT91: SD/MMC slot %d not available\n", i);
  318. break;
  319. }
  320. if (slot_count) {
  321. /* CLK */
  322. at91_set_A_periph(AT91_PIN_PA27, 0);
  323. mmc_data = *data;
  324. platform_device_register(&at91rm9200_mmc_device);
  325. }
  326. }
  327. }
  328. #else
  329. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
  330. #endif
  331. /* --------------------------------------------------------------------
  332. * NAND / SmartMedia
  333. * -------------------------------------------------------------------- */
  334. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  335. static struct atmel_nand_data nand_data;
  336. #define NAND_BASE AT91_CHIPSELECT_3
  337. static struct resource nand_resources[] = {