vision_ep9307.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * arch/arm/mach-ep93xx/vision_ep9307.c
  3. * Vision Engraving Systems EP9307 SoM support.
  4. *
  5. * Copyright (C) 2008-2011 Vision Engraving Systems
  6. * H Hartley Sweeten <hsweeten@visionengravers.com>
  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 (at
  11. * your option) any later version.
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/irq.h>
  18. #include <linux/gpio.h>
  19. #include <linux/fb.h>
  20. #include <linux/io.h>
  21. #include <linux/mtd/partitions.h>
  22. #include <linux/i2c.h>
  23. #include <linux/i2c-gpio.h>
  24. #include <linux/platform_data/pca953x.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/spi/flash.h>
  27. #include <linux/spi/mmc_spi.h>
  28. #include <linux/mmc/host.h>
  29. #include <sound/cs4271.h>
  30. #include <mach/hardware.h>
  31. #include <linux/platform_data/video-ep93xx.h>
  32. #include <linux/platform_data/spi-ep93xx.h>
  33. #include <mach/gpio-ep93xx.h>
  34. #include <asm/mach-types.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/mach/arch.h>
  37. #include "soc.h"
  38. /*************************************************************************
  39. * Static I/O mappings for the FPGA
  40. *************************************************************************/
  41. #define VISION_PHYS_BASE EP93XX_CS7_PHYS_BASE
  42. #define VISION_VIRT_BASE 0xfebff000
  43. static struct map_desc vision_io_desc[] __initdata = {
  44. {
  45. .virtual = VISION_VIRT_BASE,
  46. .pfn = __phys_to_pfn(VISION_PHYS_BASE),
  47. .length = SZ_4K,
  48. .type = MT_DEVICE,
  49. },
  50. };
  51. static void __init vision_map_io(void)
  52. {
  53. ep93xx_map_io();
  54. iotable_init(vision_io_desc, ARRAY_SIZE(vision_io_desc));
  55. }
  56. /*************************************************************************
  57. * Ethernet
  58. *************************************************************************/
  59. static struct ep93xx_eth_data vision_eth_data __initdata = {
  60. .phy_id = 1,
  61. };
  62. /*************************************************************************
  63. * Framebuffer
  64. *************************************************************************/
  65. #define VISION_LCD_ENABLE EP93XX_GPIO_LINE_EGPIO1
  66. static int vision_lcd_setup(struct platform_device *pdev)
  67. {
  68. int err;
  69. err = gpio_request_one(VISION_LCD_ENABLE, GPIOF_INIT_HIGH,
  70. dev_name(&pdev->dev));
  71. if (err)
  72. return err;
  73. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_RAS |
  74. EP93XX_SYSCON_DEVCFG_RASONP3 |
  75. EP93XX_SYSCON_DEVCFG_EXVC);
  76. return 0;
  77. }
  78. static void vision_lcd_teardown(struct platform_device *pdev)
  79. {
  80. gpio_free(VISION_LCD_ENABLE);
  81. }
  82. static void vision_lcd_blank(int blank_mode, struct fb_info *info)
  83. {
  84. if (blank_mode)
  85. gpio_set_value(VISION_LCD_ENABLE, 0);
  86. else
  87. gpio_set_value(VISION_LCD_ENABLE, 1);
  88. }
  89. static struct ep93xxfb_mach_info ep93xxfb_info __initdata = {
  90. .flags = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING,
  91. .setup = vision_lcd_setup,
  92. .teardown = vision_lcd_teardown,
  93. .blank = vision_lcd_blank,
  94. };
  95. /*************************************************************************
  96. * GPIO Expanders
  97. *************************************************************************/
  98. #define PCA9539_74_GPIO_BASE (EP93XX_GPIO_LINE_MAX + 1)
  99. #define PCA9539_75_GPIO_BASE (PCA9539_74_GPIO_BASE + 16)
  100. #define PCA9539_76_GPIO_BASE (PCA9539_75_GPIO_BASE + 16)
  101. #define PCA9539_77_GPIO_BASE (PCA9539_76_GPIO_BASE + 16)
  102. static struct pca953x_platform_data pca953x_74_gpio_data = {
  103. .gpio_base = PCA9539_74_GPIO_BASE,
  104. .irq_base = EP93XX_BOARD_IRQ(0),
  105. };
  106. static struct pca953x_platform_data pca953x_75_gpio_data = {
  107. .gpio_base = PCA9539_75_GPIO_BASE,
  108. .irq_base = -1,
  109. };
  110. static struct pca953x_platform_data pca953x_76_gpio_data = {
  111. .gpio_base = PCA9539_76_GPIO_BASE,
  112. .irq_base = -1,
  113. };
  114. static struct pca953x_platform_data pca953x_77_gpio_data = {
  115. .gpio_base = PCA9539_77_GPIO_BASE,
  116. .irq_base = -1,
  117. };
  118. /*************************************************************************
  119. * I2C Bus
  120. *************************************************************************/
  121. static struct i2c_gpio_platform_data vision_i2c_gpio_data __initdata = {
  122. .sda_pin = EP93XX_GPIO_LINE_EEDAT,
  123. .scl_pin = EP93XX_GPIO_LINE_EECLK,
  124. };
  125. static struct i2c_board_info vision_i2c_info[] __initdata = {
  126. {
  127. I2C_BOARD_INFO("isl1208", 0x6f),
  128. .irq = IRQ_EP93XX_EXT1,
  129. }, {
  130. I2C_BOARD_INFO("pca9539", 0x74),
  131. .platform_data = &pca953x_74_gpio_data,
  132. }, {
  133. I2C_BOARD_INFO("pca9539", 0x75),
  134. .platform_data = &pca953x_75_gpio_data,
  135. }, {
  136. I2C_BOARD_INFO("pca9539", 0x76),
  137. .platform_data = &pca953x_76_gpio_data,
  138. }, {
  139. I2C_BOARD_INFO("pca9539", 0x77),
  140. .platform_data = &pca953x_77_gpio_data,
  141. },
  142. };
  143. /*************************************************************************
  144. * SPI CS4271 Audio Codec
  145. *************************************************************************/
  146. static struct cs4271_platform_data vision_cs4271_data = {
  147. .gpio_nreset = EP93XX_GPIO_LINE_H(2),
  148. };
  149. static int vision_cs4271_hw_setup(struct spi_device *spi)
  150. {
  151. return gpio_request_one(EP93XX_GPIO_LINE_EGPIO6,
  152. GPIOF_OUT_INIT_HIGH, spi->modalias);
  153. }
  154. static void vision_cs4271_hw_cleanup(struct spi_device *spi)
  155. {
  156. gpio_free(EP93XX_GPIO_LINE_EGPIO6);
  157. }
  158. static void vision_cs4271_hw_cs_control(struct spi_device *spi, int value)
  159. {
  160. gpio_set_value(EP93XX_GPIO_LINE_EGPIO6, value);
  161. }
  162. static struct ep93xx_spi_chip_ops vision_cs4271_hw = {
  163. .setup = vision_cs4271_hw_setup,
  164. .cleanup = vision_cs4271_hw_cleanup,
  165. .cs_control = vision_cs4271_hw_cs_control,
  166. };
  167. /*************************************************************************
  168. * SPI Flash
  169. *************************************************************************/
  170. #define VISION_SPI_FLASH_CS EP93XX_GPIO_LINE_EGPIO7
  171. static struct mtd_partition vision_spi_flash_partitions[] = {
  172. {
  173. .name = "SPI bootstrap",
  174. .offset = 0,
  175. .size = SZ_4K,
  176. }, {
  177. .name = "Bootstrap config",
  178. .offset = MTDPART_OFS_APPEND,
  179. .size = SZ_4K,
  180. }, {
  181. .name = "System config",
  182. .offset = MTDPART_OFS_APPEND,
  183. .size = MTDPART_SIZ_FULL,
  184. },
  185. };
  186. static struct flash_platform_data vision_spi_flash_data = {
  187. .name = "SPI Flash",
  188. .parts = vision_spi_flash_partitions,
  189. .nr_parts = ARRAY_SIZE(vision_spi_flash_partitions),
  190. };
  191. static int vision_spi_flash_hw_setup(struct spi_device *spi)
  192. {
  193. return gpio_request_one(VISION_SPI_FLASH_CS, GPIOF_INIT_HIGH,
  194. spi->modalias);
  195. }
  196. static void vision_spi_flash_hw_cleanup(struct spi_device *spi)
  197. {
  198. gpio_free(VISION_SPI_FLASH_CS);
  199. }
  200. static void vision_spi_flash_hw_cs_control(struct spi_device *spi, int value)
  201. {
  202. gpio_set_value(VISION_SPI_FLASH_CS, value);
  203. }
  204. static struct ep93xx_spi_chip_ops vision_spi_flash_hw = {
  205. .setup = vision_spi_flash_hw_setup,
  206. .cleanup = vision_spi_flash_hw_cleanup,
  207. .cs_control = vision_spi_flash_hw_cs_control,
  208. };
  209. /*************************************************************************
  210. * SPI SD/MMC host
  211. *************************************************************************/
  212. #define VISION_SPI_MMC_CS EP93XX_GPIO_LINE_G(2)
  213. #define VISION_SPI_MMC_WP EP93XX_GPIO_LINE_F(0)
  214. #define VISION_SPI_MMC_CD EP93XX_GPIO_LINE_EGPIO15
  215. static struct mmc_spi_platform_data vision_spi_mmc_data = {
  216. .detect_delay = 100,
  217. .powerup_msecs = 100,
  218. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  219. .flags = MMC_SPI_USE_CD_GPIO | MMC_SPI_USE_RO_GPIO,
  220. .cd_gpio = VISION_SPI_MMC_CD,
  221. .cd_debounce = 1,
  222. .ro_gpio = VISION_SPI_MMC_WP,
  223. .caps2 = MMC_CAP2_RO_ACTIVE_HIGH,
  224. };
  225. static int vision_spi_mmc_hw_setup(struct spi_device *spi)
  226. {
  227. return gpio_request_one(VISION_SPI_MMC_CS, GPIOF_INIT_HIGH,
  228. spi->modalias);
  229. }
  230. static void vision_spi_mmc_hw_cleanup(struct spi_device *spi)
  231. {
  232. gpio_free(VISION_SPI_MMC_CS);
  233. }
  234. static void vision_spi_mmc_hw_cs_control(struct spi_device *spi, int value)
  235. {
  236. gpio_set_value(VISION_SPI_MMC_CS, value);
  237. }
  238. static struct ep93xx_spi_chip_ops vision_spi_mmc_hw = {
  239. .setup = vision_spi_mmc_hw_setup,
  240. .cleanup = vision_spi_mmc_hw_cleanup,
  241. .cs_control = vision_spi_mmc_hw_cs_control,
  242. };
  243. /*************************************************************************
  244. * SPI Bus
  245. *************************************************************************/
  246. static struct spi_board_info vision_spi_board_info[] __initdata = {
  247. {
  248. .modalias = "cs4271",
  249. .platform_data = &vision_cs4271_data,
  250. .controller_data = &vision_cs4271_hw,
  251. .max_speed_hz = 6000000,
  252. .bus_num = 0,
  253. .chip_select = 0,
  254. .mode = SPI_MODE_3,
  255. }, {
  256. .modalias = "sst25l",
  257. .platform_data = &vision_spi_flash_data,
  258. .controller_data = &vision_spi_flash_hw,
  259. .max_speed_hz = 20000000,
  260. .bus_num = 0,
  261. .chip_select = 1,
  262. .mode = SPI_MODE_3,
  263. }, {
  264. .modalias = "mmc_spi",
  265. .platform_data = &vision_spi_mmc_data,
  266. .controller_data = &vision_spi_mmc_hw,
  267. .max_speed_hz = 20000000,
  268. .bus_num = 0,
  269. .chip_select = 2,
  270. .mode = SPI_MODE_3,
  271. },
  272. };
  273. static struct ep93xx_spi_info vision_spi_master __initdata = {
  274. .num_chipselect = ARRAY_SIZE(vision_spi_board_info),
  275. .use_dma = 1,
  276. };
  277. /*************************************************************************
  278. * I2S Audio
  279. *************************************************************************/
  280. static struct platform_device vision_audio_device = {
  281. .name = "edb93xx-audio",
  282. .id = -1,
  283. };
  284. static void __init vision_register_i2s(void)
  285. {
  286. ep93xx_register_i2s();
  287. platform_device_register(&vision_audio_device);
  288. }
  289. /*************************************************************************
  290. * Machine Initialization
  291. *************************************************************************/
  292. static void __init vision_init_machine(void)
  293. {
  294. ep93xx_init_devices();
  295. ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_64M);
  296. ep93xx_register_eth(&vision_eth_data, 1);
  297. ep93xx_register_fb(&ep93xxfb_info);
  298. ep93xx_register_pwm(1, 0);
  299. /*
  300. * Request the gpio expander's interrupt gpio line now to prevent
  301. * the kernel from doing a WARN in gpiolib:gpio_ensure_requested().
  302. */
  303. if (gpio_request_one(EP93XX_GPIO_LINE_F(7), GPIOF_DIR_IN,
  304. "pca9539:74"))
  305. pr_warn("cannot request interrupt gpio for pca9539:74\n");
  306. vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7));
  307. ep93xx_register_i2c(&vision_i2c_gpio_data, vision_i2c_info,
  308. ARRAY_SIZE(vision_i2c_info));
  309. ep93xx_register_spi(&vision_spi_master, vision_spi_board_info,
  310. ARRAY_SIZE(vision_spi_board_info));
  311. vision_register_i2s();
  312. }
  313. MACHINE_START(VISION_EP9307, "Vision Engraving Systems EP9307")
  314. /* Maintainer: H Hartley Sweeten <hsweeten@visionengravers.com> */
  315. .atag_offset = 0x100,
  316. .map_io = vision_map_io,
  317. .init_irq = ep93xx_init_irq,
  318. .init_time = ep93xx_timer_init,
  319. .init_machine = vision_init_machine,
  320. .init_late = ep93xx_init_late,
  321. .restart = ep93xx_restart,
  322. MACHINE_END