basicAlgorithmEncapsulation.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /*
  2. * arch/arm/mach-at91/at91sam9260_devices.c
  3. *
  4. * Copyright (C) 2006 Atmel
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <asm/mach/arch.h>
  13. #include <asm/mach/map.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/gpio.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/i2c-gpio.h>
  18. #include <linux/platform_data/at91_adc.h>
  19. #include <mach/cpu.h>
  20. #include <mach/at91sam9260.h>
  21. #include <mach/at91sam9260_matrix.h>
  22. #include <mach/at91_matrix.h>
  23. #include <mach/at91sam9_smc.h>
  24. #include <mach/at91_adc.h>
  25. #include "board.h"
  26. #include "generic.h"
  27. /* --------------------------------------------------------------------
  28. * USB Host
  29. * -------------------------------------------------------------------- */
  30. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  31. static u64 ohci_dmamask = DMA_BIT_MASK(32);
  32. static struct at91_usbh_data usbh_data;
  33. static struct resource usbh_resources[] = {
  34. [0] = {
  35. .start = AT91SAM9260_UHP_BASE,
  36. .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
  37. .flags = IORESOURCE_MEM,
  38. },
  39. [1] = {
  40. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
  41. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
  42. .flags = IORESOURCE_IRQ,
  43. },
  44. };
  45. static struct platform_device at91_usbh_device = {
  46. .name = "at91_ohci",
  47. .id = -1,
  48. .dev = {
  49. .dma_mask = &ohci_dmamask,
  50. .coherent_dma_mask = DMA_BIT_MASK(32),
  51. .platform_data = &usbh_data,
  52. },
  53. .resource = usbh_resources,
  54. .num_resources = ARRAY_SIZE(usbh_resources),
  55. };
  56. void __init at91_add_device_usbh(struct at91_usbh_data *data)
  57. {
  58. int i;
  59. if (!data)
  60. return;
  61. /* Enable overcurrent notification */
  62. for (i = 0; i < data->ports; i++) {
  63. if (gpio_is_valid(data->overcurrent_pin[i]))
  64. at91_set_gpio_input(data->overcurrent_pin[i], 1);
  65. }
  66. usbh_data = *data;
  67. platform_device_register(&at91_usbh_device);
  68. }
  69. #else
  70. void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
  71. #endif
  72. /* --------------------------------------------------------------------
  73. * USB Device (Gadget)
  74. * -------------------------------------------------------------------- */
  75. #if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
  76. static struct at91_udc_data udc_data;
  77. static struct resource udc_resources[] = {
  78. [0] = {
  79. .start = AT91SAM9260_BASE_UDP,
  80. .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
  81. .flags = IORESOURCE_MEM,
  82. },
  83. [1] = {
  84. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
  85. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
  86. .flags = IORESOURCE_IRQ,
  87. },
  88. };
  89. static struct platform_device at91_udc_device = {
  90. .name = "at91_udc",
  91. .id = -1,
  92. .dev = {
  93. .platform_data = &udc_data,
  94. },
  95. .resource = udc_resources,
  96. .num_resources = ARRAY_SIZE(udc_resources),
  97. };
  98. void __init at91_add_device_udc(struct at91_udc_data *data)
  99. {
  100. if (!data)
  101. return;
  102. if (gpio_is_valid(data->vbus_pin)) {
  103. at91_set_gpio_input(data->vbus_pin, 0);
  104. at91_set_deglitch(data->vbus_pin, 1);
  105. }
  106. /* Pullup pin is handled internally by USB device peripheral */
  107. udc_data = *data;
  108. platform_device_register(&at91_udc_device);
  109. }
  110. #else
  111. void __init at91_add_device_udc(struct at91_udc_data *data) {}
  112. #endif
  113. /* --------------------------------------------------------------------
  114. * Ethernet
  115. * -------------------------------------------------------------------- */
  116. #if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
  117. static u64 eth_dmamask = DMA_BIT_MASK(32);
  118. static struct macb_platform_data eth_data;
  119. static struct resource eth_resources[] = {
  120. [0] = {
  121. .start = AT91SAM9260_BASE_EMAC,
  122. .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. [1] = {
  126. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
  127. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
  128. .flags = IORESOURCE_IRQ,
  129. },
  130. };
  131. static struct platform_device at91sam9260_eth_device = {
  132. .name = "macb",
  133. .id = -1,
  134. .dev = {
  135. .dma_mask = &eth_dmamask,
  136. .coherent_dma_mask = DMA_BIT_MASK(32),
  137. .platform_data = &eth_data,
  138. },
  139. .resource = eth_resources,
  140. .num_resources = ARRAY_SIZE(eth_resources),
  141. };
  142. void __init at91_add_device_eth(struct macb_platform_data *data)
  143. {
  144. if (!data)
  145. return;
  146. if (gpio_is_valid(data->phy_irq_pin)) {
  147. at91_set_gpio_input(data->phy_irq_pin, 0);
  148. at91_set_deglitch(data->phy_irq_pin, 1);
  149. }
  150. /* Pins used for MII and RMII */
  151. at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
  152. at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
  153. at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
  154. at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
  155. at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
  156. at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
  157. at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
  158. at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
  159. at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
  160. at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
  161. if (!data->is_rmii) {
  162. at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
  163. at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
  164. at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
  165. at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
  166. at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
  167. at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
  168. at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
  169. at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
  170. }
  171. eth_data = *data;
  172. platform_device_register(&at91sam9260_eth_device);
  173. }
  174. #else
  175. void __init at91_add_device_eth(struct macb_platform_data *data) {}
  176. #endif
  177. /* --------------------------------------------------------------------
  178. * MMC / SD Slot for Atmel MCI Driver
  179. * -------------------------------------------------------------------- */
  180. #if IS_ENABLED(CONFIG_MMC_ATMELMCI)
  181. static u64 mmc_dmamask = DMA_BIT_MASK(32);
  182. static struct mci_platform_data mmc_data;
  183. static struct resource mmc_resources[] = {
  184. [0] = {
  185. .start = AT91SAM9260_BASE_MCI,
  186. .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
  187. .flags = IORESOURCE_MEM,
  188. },
  189. [1] = {
  190. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  191. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
  192. .flags = IORESOURCE_IRQ,
  193. },
  194. };
  195. static struct platform_device at91sam9260_mmc_device = {
  196. .name = "atmel_mci",
  197. .id = -1,
  198. .dev = {
  199. .dma_mask = &mmc_dmamask,
  200. .coherent_dma_mask = DMA_BIT_MASK(32),
  201. .platform_data = &mmc_data,
  202. },
  203. .resource = mmc_resources,
  204. .num_resources = ARRAY_SIZE(mmc_resources),
  205. };
  206. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
  207. {
  208. unsigned int i;
  209. unsigned int slot_count = 0;
  210. if (!data)
  211. return;
  212. for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
  213. if (data->slot[i].bus_width) {
  214. /* input/irq */
  215. if (gpio_is_valid(data->slot[i].detect_pin)) {
  216. at91_set_gpio_input(data->slot[i].detect_pin, 1);
  217. at91_set_deglitch(data->slot[i].detect_pin, 1);
  218. }
  219. if (gpio_is_valid(data->slot[i].wp_pin))
  220. at91_set_gpio_input(data->slot[i].wp_pin, 1);
  221. switch (i) {
  222. case 0:
  223. /* CMD */
  224. at91_set_A_periph(AT91_PIN_PA7, 1);
  225. /* DAT0, maybe DAT1..DAT3 */
  226. at91_set_A_periph(AT91_PIN_PA6, 1);
  227. if (data->slot[i].bus_width == 4) {
  228. at91_set_A_periph(AT91_PIN_PA9, 1);
  229. at91_set_A_periph(AT91_PIN_PA10, 1);
  230. at91_set_A_periph(AT91_PIN_PA11, 1);
  231. }
  232. slot_count++;
  233. break;
  234. case 1:
  235. /* CMD */
  236. at91_set_B_periph(AT91_PIN_PA1, 1);
  237. /* DAT0, maybe DAT1..DAT3 */
  238. at91_set_B_periph(AT91_PIN_PA0, 1);
  239. if (data->slot[i].bus_width == 4) {
  240. at91_set_B_periph(AT91_PIN_PA5, 1);
  241. at91_set_B_periph(AT91_PIN_PA4, 1);
  242. at91_set_B_periph(AT91_PIN_PA3, 1);
  243. }
  244. slot_count++;
  245. break;
  246. default:
  247. printk(KERN_ERR
  248. "AT91: SD/MMC slot %d not available\n", i);
  249. break;
  250. }
  251. }
  252. }
  253. if (slot_count) {
  254. /* CLK */
  255. at91_set_A_periph(AT91_PIN_PA8, 0);
  256. mmc_data = *data;
  257. platform_device_register(&at91sam9260_mmc_device);
  258. }
  259. }
  260. #else
  261. void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
  262. #endif
  263. /* --------------------------------------------------------------------
  264. * NAND / SmartMedia
  265. * -------------------------------------------------------------------- */
  266. #if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
  267. static struct atmel_nand_data nand_data;
  268. #define NAND_BASE AT91_CHIPSELECT_3
  269. static struct resource nand_resources[] = {
  270. [0] = {
  271. .start = NAND_BASE,
  272. .end = NAND_BASE + SZ_256M - 1,
  273. .flags = IORESOURCE_MEM,
  274. },
  275. [1] = {
  276. .start = AT91SAM9260_BASE_ECC,
  277. .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
  278. .flags = IORESOURCE_MEM,
  279. }
  280. };
  281. static struct platform_device at91sam9260_nand_device = {
  282. .name = "atmel_nand",
  283. .id = -1,
  284. .dev = {
  285. .platform_data = &nand_data,
  286. },
  287. .resource = nand_resources,
  288. .num_resources = ARRAY_SIZE(nand_resources),
  289. };
  290. void __init at91_add_device_nand(struct atmel_nand_data *data)
  291. {
  292. unsigned long csa;
  293. if (!data)
  294. return;
  295. csa = at91_matrix_read(AT91_MATRIX_EBICSA);
  296. at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
  297. /* enable pin */
  298. if (gpio_is_valid(data->enable_pin))
  299. at91_set_gpio_output(data->enable_pin, 1);
  300. /* ready/busy pin */
  301. if (gpio_is_valid(data->rdy_pin))
  302. at91_set_gpio_input(data->rdy_pin, 1);
  303. /* card detect pin */
  304. if (gpio_is_valid(data->det_pin))
  305. at91_set_gpio_input(data->det_pin, 1);
  306. nand_data = *data;
  307. platform_device_register(&at91sam9260_nand_device);
  308. }
  309. #else
  310. void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  311. #endif
  312. /* --------------------------------------------------------------------
  313. * TWI (i2c)
  314. * -------------------------------------------------------------------- */
  315. /*
  316. * Prefer the GPIO code since the TWI controller isn't robust
  317. * (gets overruns and underruns under load) and can only issue
  318. * repeated STARTs in one scenario (the driver doesn't yet handle them).
  319. */
  320. #if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
  321. static struct i2c_gpio_platform_data pdata = {
  322. .sda_pin = AT91_PIN_PA23,
  323. .sda_is_open_drain = 1,
  324. .scl_pin = AT91_PIN_PA24,
  325. .scl_is_open_drain = 1,
  326. .udelay = 2, /* ~100 kHz */
  327. };
  328. static struct platform_device at91sam9260_twi_device = {
  329. .name = "i2c-gpio",
  330. .id = 0,
  331. .dev.platform_data = &pdata,
  332. };
  333. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  334. {
  335. at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
  336. at91_set_multi_drive(AT91_PIN_PA23, 1);
  337. at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
  338. at91_set_multi_drive(AT91_PIN_PA24, 1);
  339. i2c_register_board_info(0, devices, nr_devices);
  340. platform_device_register(&at91sam9260_twi_device);
  341. }
  342. #elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
  343. static struct resource twi_resources[] = {
  344. [0] = {
  345. .start = AT91SAM9260_BASE_TWI,
  346. .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
  347. .flags = IORESOURCE_MEM,
  348. },
  349. [1] = {
  350. .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  351. .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
  352. .flags = IORESOURCE_IRQ,
  353. },
  354. };
  355. static struct platform_device at91sam9260_twi_device = {
  356. .id = 0,
  357. .resource = twi_resources,
  358. .num_resources = ARRAY_SIZE(twi_resources),
  359. };
  360. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
  361. {
  362. /* IP version is not the same on 9260 and g20 */
  363. if (cpu_is_at91sam9g20()) {
  364. at91sam9260_twi_device.name = "i2c-at91sam9g20";
  365. } else {
  366. at91sam9260_twi_device.name = "i2c-at91sam9260";
  367. }
  368. /* pins used for TWI interface */
  369. at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
  370. at91_set_multi_drive(AT91_PIN_PA23, 1);
  371. at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
  372. at91_set_multi_drive(AT91_PIN_PA24, 1);
  373. i2c_register_board_info(0, devices, nr_devices);
  374. platform_device_register(&at91sam9260_twi_device);
  375. }
  376. #else
  377. void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
  378. #endif
  379. /* --------------------------------------------------------------------
  380. * SPI
  381. * -------------------------------------------------------------------- */
  382. #if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
  383. static u64 spi_dmamask = DMA_BIT_MASK(32);
  384. static struct resource spi0_resources[] = {