connectionSignalSlot.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * KZM-A9-GT board support
  3. *
  4. * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  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; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/gpio.h>
  21. #include <linux/gpio_keys.h>
  22. #include <linux/io.h>
  23. #include <linux/irq.h>
  24. #include <linux/i2c.h>
  25. #include <linux/i2c/pcf857x.h>
  26. #include <linux/input.h>
  27. #include <linux/mmc/host.h>
  28. #include <linux/mmc/sh_mmcif.h>
  29. #include <linux/mmc/sh_mobile_sdhi.h>
  30. #include <linux/mfd/tmio.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/regulator/fixed.h>
  33. #include <linux/regulator/machine.h>
  34. #include <linux/smsc911x.h>
  35. #include <linux/usb/r8a66597.h>
  36. #include <linux/usb/renesas_usbhs.h>
  37. #include <linux/videodev2.h>
  38. #include <sound/sh_fsi.h>
  39. #include <sound/simple_card.h>
  40. #include <mach/irqs.h>
  41. #include <mach/sh73a0.h>
  42. #include <mach/common.h>
  43. #include <asm/hardware/cache-l2x0.h>
  44. #include <asm/hardware/gic.h>
  45. #include <asm/mach-types.h>
  46. #include <asm/mach/arch.h>
  47. #include <video/sh_mobile_lcdc.h>
  48. /*
  49. * external GPIO
  50. */
  51. #define GPIO_PCF8575_BASE (GPIO_NR)
  52. #define GPIO_PCF8575_PORT10 (GPIO_NR + 8)
  53. #define GPIO_PCF8575_PORT11 (GPIO_NR + 9)
  54. #define GPIO_PCF8575_PORT12 (GPIO_NR + 10)
  55. #define GPIO_PCF8575_PORT13 (GPIO_NR + 11)
  56. #define GPIO_PCF8575_PORT14 (GPIO_NR + 12)
  57. #define GPIO_PCF8575_PORT15 (GPIO_NR + 13)
  58. #define GPIO_PCF8575_PORT16 (GPIO_NR + 14)
  59. /* Dummy supplies, where voltage doesn't matter */
  60. static struct regulator_consumer_supply dummy_supplies[] = {
  61. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  62. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  63. };
  64. /*
  65. * FSI-AK4648
  66. *
  67. * this command is required when playback.
  68. *
  69. * # amixer set "LINEOUT Mixer DACL" on
  70. */
  71. /* SMSC 9221 */
  72. static struct resource smsc9221_resources[] = {
  73. [0] = {
  74. .start = 0x10000000, /* CS4 */
  75. .end = 0x100000ff,
  76. .flags = IORESOURCE_MEM,
  77. },
  78. [1] = {
  79. .start = intcs_evt2irq(0x260), /* IRQ3 */
  80. .flags = IORESOURCE_IRQ,
  81. },
  82. };
  83. static struct smsc911x_platform_config smsc9221_platdata = {
  84. .flags = SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS,
  85. .phy_interface = PHY_INTERFACE_MODE_MII,
  86. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  87. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  88. };
  89. static struct platform_device smsc_device = {
  90. .name = "smsc911x",
  91. .dev = {
  92. .platform_data = &smsc9221_platdata,
  93. },
  94. .resource = smsc9221_resources,
  95. .num_resources = ARRAY_SIZE(smsc9221_resources),
  96. };
  97. /* USB external chip */
  98. static struct r8a66597_platdata usb_host_data = {
  99. .on_chip = 0,
  100. .xtal = R8A66597_PLATDATA_XTAL_48MHZ,
  101. };
  102. static struct resource usb_resources[] = {
  103. [0] = {
  104. .start = 0x10010000,
  105. .end = 0x1001ffff - 1,
  106. .flags = IORESOURCE_MEM,
  107. },
  108. [1] = {
  109. .start = intcs_evt2irq(0x220), /* IRQ1 */
  110. .flags = IORESOURCE_IRQ,
  111. },
  112. };
  113. static struct platform_device usb_host_device = {
  114. .name = "r8a66597_hcd",
  115. .dev = {
  116. .platform_data = &usb_host_data,
  117. .dma_mask = NULL,
  118. .coherent_dma_mask = 0xffffffff,
  119. },
  120. .num_resources = ARRAY_SIZE(usb_resources),
  121. .resource = usb_resources,
  122. };
  123. /* USB Func CN17 */
  124. struct usbhs_private {
  125. void __iomem *phy;
  126. void __iomem *cr2;
  127. struct renesas_usbhs_platform_info info;
  128. };
  129. #define IRQ15 intcs_evt2irq(0x03e0)
  130. #define USB_PHY_MODE (1 << 4)
  131. #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
  132. #define USB_PHY_ON (1 << 1)
  133. #define USB_PHY_OFF (1 << 0)
  134. #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
  135. #define usbhs_get_priv(pdev) \
  136. container_of(renesas_usbhs_get_info(pdev), struct usbhs_private, info)
  137. static int usbhs_get_vbus(struct platform_device *pdev)
  138. {
  139. struct usbhs_private *priv = usbhs_get_priv(pdev);
  140. return !((1 << 7) & __raw_readw(priv->cr2));
  141. }
  142. static void usbhs_phy_reset(struct platform_device *pdev)
  143. {
  144. struct usbhs_private *priv = usbhs_get_priv(pdev);
  145. /* init phy */
  146. __raw_writew(0x8a0a, priv->cr2);
  147. }
  148. static int usbhs_get_id(struct platform_device *pdev)
  149. {
  150. return USBHS_GADGET;
  151. }
  152. static irqreturn_t usbhs_interrupt(int irq, void *data)
  153. {
  154. struct platform_device *pdev = data;
  155. struct usbhs_private *priv = usbhs_get_priv(pdev);
  156. renesas_usbhs_call_notify_hotplug(pdev);
  157. /* clear status */
  158. __raw_writew(__raw_readw(priv->phy) | USB_PHY_INT_CLR, priv->phy);
  159. return IRQ_HANDLED;
  160. }
  161. static int usbhs_hardware_init(struct platform_device *pdev)
  162. {
  163. struct usbhs_private *priv = usbhs_get_priv(pdev);
  164. int ret;
  165. /* clear interrupt status */
  166. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->phy);
  167. ret = request_irq(IRQ15, usbhs_interrupt, IRQF_TRIGGER_HIGH,
  168. dev_name(&pdev->dev), pdev);
  169. if (ret) {
  170. dev_err(&pdev->dev, "request_irq err\n");
  171. return ret;
  172. }
  173. /* enable USB phy interrupt */
  174. __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->phy);
  175. return 0;
  176. }
  177. static void usbhs_hardware_exit(struct platform_device *pdev)
  178. {
  179. struct usbhs_private *priv = usbhs_get_priv(pdev);
  180. /* clear interrupt status */
  181. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->phy);
  182. free_irq(IRQ15, pdev);
  183. }
  184. static u32 usbhs_pipe_cfg[] = {
  185. USB_ENDPOINT_XFER_CONTROL,
  186. USB_ENDPOINT_XFER_ISOC,
  187. USB_ENDPOINT_XFER_ISOC,
  188. USB_ENDPOINT_XFER_BULK,
  189. USB_ENDPOINT_XFER_BULK,
  190. USB_ENDPOINT_XFER_BULK,
  191. USB_ENDPOINT_XFER_INT,
  192. USB_ENDPOINT_XFER_INT,
  193. USB_ENDPOINT_XFER_INT,
  194. USB_ENDPOINT_XFER_BULK,
  195. USB_ENDPOINT_XFER_BULK,
  196. USB_ENDPOINT_XFER_BULK,
  197. USB_ENDPOINT_XFER_BULK,
  198. USB_ENDPOINT_XFER_BULK,
  199. USB_ENDPOINT_XFER_BULK,
  200. USB_ENDPOINT_XFER_BULK,
  201. };
  202. static struct usbhs_private usbhs_private = {
  203. .phy = IOMEM(0xe60781e0), /* USBPHYINT */
  204. .cr2 = IOMEM(0xe605810c), /* USBCR2 */
  205. .info = {
  206. .platform_callback = {
  207. .hardware_init = usbhs_hardware_init,
  208. .hardware_exit = usbhs_hardware_exit,
  209. .get_id = usbhs_get_id,
  210. .phy_reset = usbhs_phy_reset,
  211. .get_vbus = usbhs_get_vbus,
  212. },
  213. .driver_param = {
  214. .buswait_bwait = 4,
  215. .has_otg = 1,
  216. .pipe_type = usbhs_pipe_cfg,
  217. .pipe_size = ARRAY_SIZE(usbhs_pipe_cfg),
  218. },
  219. },
  220. };
  221. static struct resource usbhs_resources[] = {
  222. [0] = {
  223. .start = 0xE6890000,
  224. .end = 0xE68900e6 - 1,
  225. .flags = IORESOURCE_MEM,
  226. },
  227. [1] = {
  228. .start = gic_spi(62),
  229. .end = gic_spi(62),
  230. .flags = IORESOURCE_IRQ,
  231. },
  232. };
  233. static struct platform_device usbhs_device = {
  234. .name = "renesas_usbhs",
  235. .id = -1,
  236. .dev = {
  237. .dma_mask = NULL,
  238. .coherent_dma_mask = 0xffffffff,
  239. .platform_data = &usbhs_private.info,
  240. },
  241. .num_resources = ARRAY_SIZE(usbhs_resources),
  242. .resource = usbhs_resources,
  243. };
  244. /* LCDC */
  245. static struct fb_videomode kzm_lcdc_mode = {
  246. .name = "WVGA Panel",
  247. .xres = 800,
  248. .yres = 480,
  249. .left_margin = 220,
  250. .right_margin = 110,
  251. .hsync_len = 70,
  252. .upper_margin = 20,
  253. .lower_margin = 5,
  254. .vsync_len = 5,
  255. .sync = 0,
  256. };
  257. static struct sh_mobile_lcdc_info lcdc_info = {
  258. .clock_source = LCDC_CLK_BUS,
  259. .ch[0] = {
  260. .chan = LCDC_CHAN_MAINLCD,
  261. .fourcc = V4L2_PIX_FMT_RGB565,
  262. .interface_type = RGB24,
  263. .lcd_modes = &kzm_lcdc_mode,
  264. .num_modes = 1,
  265. .clock_divider = 5,
  266. .flags = 0,
  267. .panel_cfg = {
  268. .width = 152,
  269. .height = 91,
  270. },
  271. }
  272. };
  273. static struct resource lcdc_resources[] = {
  274. [0] = {
  275. .name = "LCDC",
  276. .start = 0xfe940000,
  277. .end = 0xfe943fff,
  278. .flags = IORESOURCE_MEM,
  279. },
  280. [1] = {
  281. .start = intcs_evt2irq(0x580),
  282. .flags = IORESOURCE_IRQ,
  283. },
  284. };
  285. static struct platform_device lcdc_device = {
  286. .name = "sh_mobile_lcdc_fb",
  287. .num_resources = ARRAY_SIZE(lcdc_resources),
  288. .resource = lcdc_resources,
  289. .dev = {
  290. .platform_data = &lcdc_info,
  291. .coherent_dma_mask = ~0,
  292. },
  293. };
  294. /* Fixed 1.8V regulator to be used by MMCIF */
  295. static struct regulator_consumer_supply fixed1v8_power_consumers[] =
  296. {
  297. REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
  298. REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
  299. };
  300. /* MMCIF */
  301. static struct resource sh_mmcif_resources[] = {
  302. [0] = {
  303. .name = "MMCIF",
  304. .start = 0xe6bd0000,
  305. .end = 0xe6bd00ff,
  306. .flags = IORESOURCE_MEM,
  307. },
  308. [1] = {
  309. .start = gic_spi(140),
  310. .flags = IORESOURCE_IRQ,
  311. },
  312. [2] = {
  313. .start = gic_spi(141),
  314. .flags = IORESOURCE_IRQ,
  315. },
  316. };
  317. static struct sh_mmcif_plat_data sh_mmcif_platdata = {
  318. .ocr = MMC_VDD_165_195,
  319. .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE,
  320. .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
  321. .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
  322. };
  323. static struct platform_device mmc_device = {
  324. .name = "sh_mmcif",
  325. .dev = {
  326. .dma_mask = NULL,
  327. .coherent_dma_mask = 0xffffffff,
  328. .platform_data = &sh_mmcif_platdata,
  329. },
  330. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  331. .resource = sh_mmcif_resources,
  332. };
  333. /* Fixed 2.8V regulators to be used by SDHI0 and SDHI2 */
  334. static struct regulator_consumer_supply fixed2v8_power_consumers[] =
  335. {
  336. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
  337. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
  338. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
  339. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
  340. };
  341. /* SDHI */
  342. static struct sh_mobile_sdhi_info sdhi0_info = {
  343. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  344. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  345. .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
  346. .tmio_caps = MMC_CAP_SD_HIGHSPEED,
  347. .tmio_ocr_mask = MMC_VDD_27_28 | MMC_VDD_28_29,
  348. };
  349. static struct resource sdhi0_resources[] = {
  350. [0] = {
  351. .name = "SDHI0",
  352. .start = 0xee100000,
  353. .end = 0xee1000ff,
  354. .flags = IORESOURCE_MEM,
  355. },
  356. [1] = {
  357. .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
  358. .start = gic_spi(83),
  359. .flags = IORESOURCE_IRQ,
  360. },
  361. [2] = {
  362. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  363. .start = gic_spi(84),