hdmi_wp.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * HDMI wrapper
  3. *
  4. * Copyright (C) 2013 Texas Instruments Incorporated
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #define DSS_SUBSYS_NAME "HDMIWP"
  11. #include <linux/kernel.h>
  12. #include <linux/err.h>
  13. #include <linux/io.h>
  14. #include <linux/platform_device.h>
  15. #include <video/omapdss.h>
  16. #include "dss.h"
  17. #include "hdmi.h"
  18. void hdmi_wp_dump(struct hdmi_wp_data *wp, struct seq_file *s)
  19. {
  20. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, hdmi_read_reg(wp->base, r))
  21. DUMPREG(HDMI_WP_REVISION);
  22. DUMPREG(HDMI_WP_SYSCONFIG);
  23. DUMPREG(HDMI_WP_IRQSTATUS_RAW);
  24. DUMPREG(HDMI_WP_IRQSTATUS);
  25. DUMPREG(HDMI_WP_IRQENABLE_SET);
  26. DUMPREG(HDMI_WP_IRQENABLE_CLR);
  27. DUMPREG(HDMI_WP_IRQWAKEEN);
  28. DUMPREG(HDMI_WP_PWR_CTRL);
  29. DUMPREG(HDMI_WP_DEBOUNCE);
  30. DUMPREG(HDMI_WP_VIDEO_CFG);
  31. DUMPREG(HDMI_WP_VIDEO_SIZE);
  32. DUMPREG(HDMI_WP_VIDEO_TIMING_H);
  33. DUMPREG(HDMI_WP_VIDEO_TIMING_V);
  34. DUMPREG(HDMI_WP_CLK);
  35. DUMPREG(HDMI_WP_AUDIO_CFG);
  36. DUMPREG(HDMI_WP_AUDIO_CFG2);
  37. DUMPREG(HDMI_WP_AUDIO_CTRL);
  38. DUMPREG(HDMI_WP_AUDIO_DATA);
  39. }
  40. u32 hdmi_wp_get_irqstatus(struct hdmi_wp_data *wp)
  41. {
  42. return hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS);
  43. }
  44. void hdmi_wp_set_irqstatus(struct hdmi_wp_data *wp, u32 irqstatus)
  45. {
  46. hdmi_write_reg(wp->base, HDMI_WP_IRQSTATUS, irqstatus);
  47. /* flush posted write */
  48. hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS);
  49. }
  50. void hdmi_wp_set_irqenable(struct hdmi_wp_data *wp, u32 mask)
  51. {
  52. hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_SET, mask);
  53. }
  54. void hdmi_wp_clear_irqenable(struct hdmi_wp_data *wp, u32 mask)
  55. {
  56. hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_CLR, mask);
  57. }
  58. /* PHY_PWR_CMD */
  59. int hdmi_wp_set_phy_pwr(struct hdmi_wp_data *wp, enum hdmi_phy_pwr val)
  60. {
  61. /* Return if already the state */
  62. if (REG_GET(wp->base, HDMI_WP_PWR_CTRL, 5, 4) == val)
  63. return 0;
  64. /* Command for power control of HDMI PHY */
  65. REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 7, 6);
  66. /* Status of the power control of HDMI PHY */
  67. if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 5, 4, val)
  68. != val) {
  69. DSSERR("Failed to set PHY power mode to %d\n", val);
  70. return -ETIMEDOUT;
  71. }
  72. return 0;
  73. }
  74. /* PLL_PWR_CMD */
  75. int hdmi_wp_set_pll_pwr(struct hdmi_wp_data *wp, enum hdmi_pll_pwr val)
  76. {
  77. /* Command for power control of HDMI PLL */
  78. REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 3, 2);
  79. /* wait till PHY_PWR_STATUS is set */
  80. if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 1, 0, val)
  81. != val) {
  82. DSSERR("Failed to set PLL_PWR_STATUS\n");
  83. return -ETIMEDOUT;
  84. }
  85. return 0;
  86. }
  87. int hdmi_wp_video_start(struct hdmi_wp_data *wp)
  88. {
  89. REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, true, 31, 31);
  90. return 0;
  91. }
  92. void hdmi_wp_video_stop(struct hdmi_wp_data *wp)
  93. {
  94. int i;
  95. hdmi_write_reg(wp->base, HDMI_WP_IRQSTATUS, HDMI_IRQ_VIDEO_FRAME_DONE);
  96. REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, false, 31, 31);
  97. for (i = 0; i < 50; ++i) {
  98. u32 v;
  99. msleep(20);
  100. v = hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS_RAW);
  101. if (v & HDMI_IRQ_VIDEO_FRAME_DONE)
  102. return;
  103. }
  104. DSSERR("no HDMI FRAMEDONE when disabling output\n");
  105. }
  106. void hdmi_wp_video_config_format(struct hdmi_wp_data *wp,
  107. struct hdmi_video_format *video_fmt)
  108. {
  109. u32 l = 0;
  110. REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, video_fmt->packing_mode,
  111. 10, 8);
  112. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  113. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  114. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_SIZE, l);
  115. }
  116. void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp,
  117. struct omap_video_timings *timings)
  118. {
  119. u32 r;
  120. bool vsync_pol, hsync_pol;
  121. DSSDBG("Enter hdmi_wp_video_config_interface\n");
  122. vsync_pol = timings->vsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
  123. hsync_pol = timings->hsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
  124. r = hdmi_read_reg(wp->base, HDMI_WP_VIDEO_CFG);
  125. r = FLD_MOD(r, vsync_pol, 7, 7);
  126. r = FLD_MOD(r, hsync_pol, 6, 6);
  127. r = FLD_MOD(r, timings->interlace, 3, 3);
  128. r = FLD_MOD(r, 1, 1, 0); /* HDMI_TIMING_MASTER_24BIT */
  129. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_CFG, r);
  130. }
  131. void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp,
  132. struct omap_video_timings *timings)
  133. {
  134. u32 timing_h = 0;
  135. u32 timing_v = 0;
  136. DSSDBG("Enter hdmi_wp_video_config_timing\n");
  137. timing_h |= FLD_VAL(timings->hbp, 31, 20);
  138. timing_h |= FLD_VAL(timings->hfp, 19, 8);
  139. timing_h |= FLD_VAL(timings->hsw, 7, 0);
  140. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_H, timing_h);
  141. timing_v |= FLD_VAL(timings->vbp, 31, 20);
  142. timing_v |= FLD_VAL(timings->vfp, 19, 8);
  143. timing_v |= FLD_VAL(timings->vsw, 7, 0);
  144. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_V, timing_v);
  145. }
  146. void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt,
  147. struct omap_video_timings *timings, struct hdmi_config *param)
  148. {
  149. DSSDBG("Enter hdmi_wp_video_init_format\n");
  150. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  151. video_fmt->y_res = param->timings.y_res;
  152. video_fmt->x_res = param->timings.x_res;
  153. if (param->timings.interlace)
  154. video_fmt->y_res /= 2;
  155. timings->hbp = param->timings.hbp;
  156. timings->hfp = param->timings.hfp;
  157. timings->hsw = param->timings.hsw;
  158. timings->vbp = param->timings.vbp;
  159. timings->vfp = param->timings.vfp;
  160. timings->vsw = param->timings.vsw;
  161. timings->vsync_level = param->timings.vsync_level;
  162. timings->hsync_level = param->timings.hsync_level;
  163. timings->interlace = param->timings.interlace;
  164. }
  165. void hdmi_wp_audio_config_format(struct hdmi_wp_data *wp,
  166. struct hdmi_audio_format *aud_fmt)
  167. {
  168. u32 r;
  169. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  170. r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG);
  171. if (omapdss_get_version() == OMAPDSS_VER_OMAP4430_ES1 ||
  172. omapdss_get_version() == OMAPDSS_VER_OMAP4430_ES2 ||
  173. omapdss_get_version() == OMAPDSS_VER_OMAP4) {
  174. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  175. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  176. }
  177. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  178. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  179. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  180. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  181. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  182. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  183. hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG, r);
  184. }
  185. void hdmi_wp_audio_config_dma(struct hdmi_wp_data *wp,
  186. struct hdmi_audio_dma *aud_dma)
  187. {
  188. u32 r;
  189. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  190. r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG2);
  191. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  192. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  193. hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG2, r);
  194. r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CTRL);
  195. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  196. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  197. hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CTRL, r);
  198. }
  199. int hdmi_wp_audio_enable(struct hdmi_wp_data *wp, bool enable)
  200. {
  201. REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 31, 31);
  202. return 0;
  203. }
  204. int hdmi_wp_audio_core_req_enable(struct hdmi_wp_data *wp, bool enable)
  205. {
  206. REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 30, 30);
  207. return 0;
  208. }
  209. int hdmi_wp_init(struct platform_device *pdev, struct hdmi_wp_data *wp)
  210. {
  211. struct resource *res;
  212. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wp");
  213. if (!res) {
  214. DSSERR("can't get WP mem resource\n");
  215. return -EINVAL;
  216. }
  217. wp->phys_base = res->start;
  218. wp->base = devm_ioremap_resource(&pdev->dev, res);
  219. if (IS_ERR(wp->base)) {
  220. DSSERR("can't ioremap HDMI WP\n");
  221. return PTR_ERR(wp->base);
  222. }
  223. return 0;
  224. }
  225. phys_addr_t hdmi_wp_get_audio_dma_addr(struct hdmi_wp_data *wp)
  226. {
  227. return wp->phys_base + HDMI_WP_AUDIO_DATA;
  228. }