hdmi_wp.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 <linux/seq_file.h>
  16. #include "omapdss.h"
  17. #include "dss.h"
  18. #include "hdmi.h"
  19. void hdmi_wp_dump(struct hdmi_wp_data *wp, struct seq_file *s)
  20. {
  21. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, hdmi_read_reg(wp->base, r))
  22. DUMPREG(HDMI_WP_REVISION);
  23. DUMPREG(HDMI_WP_SYSCONFIG);
  24. DUMPREG(HDMI_WP_IRQSTATUS_RAW);
  25. DUMPREG(HDMI_WP_IRQSTATUS);
  26. DUMPREG(HDMI_WP_IRQENABLE_SET);
  27. DUMPREG(HDMI_WP_IRQENABLE_CLR);
  28. DUMPREG(HDMI_WP_IRQWAKEEN);
  29. DUMPREG(HDMI_WP_PWR_CTRL);
  30. DUMPREG(HDMI_WP_DEBOUNCE);
  31. DUMPREG(HDMI_WP_VIDEO_CFG);
  32. DUMPREG(HDMI_WP_VIDEO_SIZE);
  33. DUMPREG(HDMI_WP_VIDEO_TIMING_H);
  34. DUMPREG(HDMI_WP_VIDEO_TIMING_V);
  35. DUMPREG(HDMI_WP_CLK);
  36. DUMPREG(HDMI_WP_AUDIO_CFG);
  37. DUMPREG(HDMI_WP_AUDIO_CFG2);
  38. DUMPREG(HDMI_WP_AUDIO_CTRL);
  39. DUMPREG(HDMI_WP_AUDIO_DATA);
  40. }
  41. u32 hdmi_wp_get_irqstatus(struct hdmi_wp_data *wp)
  42. {
  43. return hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS);
  44. }
  45. void hdmi_wp_set_irqstatus(struct hdmi_wp_data *wp, u32 irqstatus)
  46. {
  47. hdmi_write_reg(wp->base, HDMI_WP_IRQSTATUS, irqstatus);
  48. /* flush posted write */
  49. hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS);
  50. }
  51. void hdmi_wp_set_irqenable(struct hdmi_wp_data *wp, u32 mask)
  52. {
  53. hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_SET, mask);
  54. }
  55. void hdmi_wp_clear_irqenable(struct hdmi_wp_data *wp, u32 mask)
  56. {
  57. hdmi_write_reg(wp->base, HDMI_WP_IRQENABLE_CLR, mask);
  58. }
  59. /* PHY_PWR_CMD */
  60. int hdmi_wp_set_phy_pwr(struct hdmi_wp_data *wp, enum hdmi_phy_pwr val)
  61. {
  62. /* Return if already the state */
  63. if (REG_GET(wp->base, HDMI_WP_PWR_CTRL, 5, 4) == val)
  64. return 0;
  65. /* Command for power control of HDMI PHY */
  66. REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 7, 6);
  67. /* Status of the power control of HDMI PHY */
  68. if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 5, 4, val)
  69. != val) {
  70. DSSERR("Failed to set PHY power mode to %d\n", val);
  71. return -ETIMEDOUT;
  72. }
  73. return 0;
  74. }
  75. /* PLL_PWR_CMD */
  76. int hdmi_wp_set_pll_pwr(struct hdmi_wp_data *wp, enum hdmi_pll_pwr val)
  77. {
  78. /* Command for power control of HDMI PLL */
  79. REG_FLD_MOD(wp->base, HDMI_WP_PWR_CTRL, val, 3, 2);
  80. /* wait till PHY_PWR_STATUS is set */
  81. if (hdmi_wait_for_bit_change(wp->base, HDMI_WP_PWR_CTRL, 1, 0, val)
  82. != val) {
  83. DSSERR("Failed to set PLL_PWR_STATUS\n");
  84. return -ETIMEDOUT;
  85. }
  86. return 0;
  87. }
  88. int hdmi_wp_video_start(struct hdmi_wp_data *wp)
  89. {
  90. REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, true, 31, 31);
  91. return 0;
  92. }
  93. void hdmi_wp_video_stop(struct hdmi_wp_data *wp)
  94. {
  95. int i;
  96. hdmi_write_reg(wp->base, HDMI_WP_IRQSTATUS, HDMI_IRQ_VIDEO_FRAME_DONE);
  97. REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, false, 31, 31);
  98. for (i = 0; i < 50; ++i) {
  99. u32 v;
  100. msleep(20);
  101. v = hdmi_read_reg(wp->base, HDMI_WP_IRQSTATUS_RAW);
  102. if (v & HDMI_IRQ_VIDEO_FRAME_DONE)
  103. return;
  104. }
  105. DSSERR("no HDMI FRAMEDONE when disabling output\n");
  106. }
  107. void hdmi_wp_video_config_format(struct hdmi_wp_data *wp,
  108. struct hdmi_video_format *video_fmt)
  109. {
  110. u32 l = 0;
  111. REG_FLD_MOD(wp->base, HDMI_WP_VIDEO_CFG, video_fmt->packing_mode,
  112. 10, 8);
  113. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  114. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  115. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_SIZE, l);
  116. }
  117. void hdmi_wp_video_config_interface(struct hdmi_wp_data *wp,
  118. struct videomode *vm)
  119. {
  120. u32 r;
  121. bool vsync_pol, hsync_pol;
  122. DSSDBG("Enter hdmi_wp_video_config_interface\n");
  123. vsync_pol = !!(vm->flags & DISPLAY_FLAGS_VSYNC_HIGH);
  124. hsync_pol = !!(vm->flags & DISPLAY_FLAGS_HSYNC_HIGH);
  125. r = hdmi_read_reg(wp->base, HDMI_WP_VIDEO_CFG);
  126. r = FLD_MOD(r, vsync_pol, 7, 7);
  127. r = FLD_MOD(r, hsync_pol, 6, 6);
  128. r = FLD_MOD(r, !!(vm->flags & DISPLAY_FLAGS_INTERLACED), 3, 3);
  129. r = FLD_MOD(r, 1, 1, 0); /* HDMI_TIMING_MASTER_24BIT */
  130. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_CFG, r);
  131. }
  132. void hdmi_wp_video_config_timing(struct hdmi_wp_data *wp,
  133. struct videomode *vm)
  134. {
  135. u32 timing_h = 0;
  136. u32 timing_v = 0;
  137. unsigned hsync_len_offset = 1;
  138. DSSDBG("Enter hdmi_wp_video_config_timing\n");
  139. /*
  140. * On OMAP4 and OMAP5 ES1 the HSW field is programmed as is. On OMAP5
  141. * ES2+ (including DRA7/AM5 SoCs) HSW field is programmed to hsync_len-1.
  142. * However, we don't support OMAP5 ES1 at all, so we can just check for
  143. * OMAP4 here.
  144. */
  145. if (omapdss_get_version() == OMAPDSS_VER_OMAP4430_ES1 ||
  146. omapdss_get_version() == OMAPDSS_VER_OMAP4430_ES2 ||
  147. omapdss_get_version() == OMAPDSS_VER_OMAP4)
  148. hsync_len_offset = 0;
  149. timing_h |= FLD_VAL(vm->hback_porch, 31, 20);
  150. timing_h |= FLD_VAL(vm->hfront_porch, 19, 8);
  151. timing_h |= FLD_VAL(vm->hsync_len - hsync_len_offset, 7, 0);
  152. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_H, timing_h);
  153. timing_v |= FLD_VAL(vm->vback_porch, 31, 20);
  154. timing_v |= FLD_VAL(vm->vfront_porch, 19, 8);
  155. timing_v |= FLD_VAL(vm->vsync_len, 7, 0);
  156. hdmi_write_reg(wp->base, HDMI_WP_VIDEO_TIMING_V, timing_v);
  157. }
  158. void hdmi_wp_init_vid_fmt_timings(struct hdmi_video_format *video_fmt,
  159. struct videomode *vm, struct hdmi_config *param)
  160. {
  161. DSSDBG("Enter hdmi_wp_video_init_format\n");
  162. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  163. video_fmt->y_res = param->vm.vactive;
  164. video_fmt->x_res = param->vm.hactive;
  165. vm->hback_porch = param->vm.hback_porch;
  166. vm->hfront_porch = param->vm.hfront_porch;
  167. vm->hsync_len = param->vm.hsync_len;
  168. vm->vback_porch = param->vm.vback_porch;
  169. vm->vfront_porch = param->vm.vfront_porch;
  170. vm->vsync_len = param->vm.vsync_len;
  171. vm->flags = param->vm.flags;
  172. if (param->vm.flags & DISPLAY_FLAGS_INTERLACED) {
  173. video_fmt->y_res /= 2;
  174. vm->vback_porch /= 2;
  175. vm->vfront_porch /= 2;
  176. vm->vsync_len /= 2;
  177. }
  178. if (param->vm.flags & DISPLAY_FLAGS_DOUBLECLK) {
  179. video_fmt->x_res *= 2;
  180. vm->hfront_porch *= 2;
  181. vm->hsync_len *= 2;
  182. vm->hback_porch *= 2;
  183. }
  184. }
  185. void hdmi_wp_audio_config_format(struct hdmi_wp_data *wp,
  186. struct hdmi_audio_format *aud_fmt)
  187. {
  188. u32 r;
  189. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  190. r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG);
  191. if (omapdss_get_version() == OMAPDSS_VER_OMAP4430_ES1 ||
  192. omapdss_get_version() == OMAPDSS_VER_OMAP4430_ES2 ||
  193. omapdss_get_version() == OMAPDSS_VER_OMAP4) {
  194. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  195. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  196. }
  197. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  198. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  199. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  200. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  201. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  202. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  203. hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG, r);
  204. }
  205. void hdmi_wp_audio_config_dma(struct hdmi_wp_data *wp,
  206. struct hdmi_audio_dma *aud_dma)
  207. {
  208. u32 r;
  209. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  210. r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CFG2);
  211. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  212. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  213. hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CFG2, r);
  214. r = hdmi_read_reg(wp->base, HDMI_WP_AUDIO_CTRL);
  215. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  216. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  217. hdmi_write_reg(wp->base, HDMI_WP_AUDIO_CTRL, r);
  218. }
  219. int hdmi_wp_audio_enable(struct hdmi_wp_data *wp, bool enable)
  220. {
  221. REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 31, 31);
  222. return 0;
  223. }
  224. int hdmi_wp_audio_core_req_enable(struct hdmi_wp_data *wp, bool enable)
  225. {
  226. REG_FLD_MOD(wp->base, HDMI_WP_AUDIO_CTRL, enable, 30, 30);
  227. return 0;
  228. }
  229. int hdmi_wp_init(struct platform_device *pdev, struct hdmi_wp_data *wp)
  230. {
  231. struct resource *res;
  232. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wp");
  233. if (!res) {
  234. DSSERR("can't get WP mem resource\n");
  235. return -EINVAL;
  236. }
  237. wp->phys_base = res->start;
  238. wp->base = devm_ioremap_resource(&pdev->dev, res);
  239. if (IS_ERR(wp->base)) {
  240. DSSERR("can't ioremap HDMI WP\n");
  241. return PTR_ERR(wp->base);
  242. }
  243. return 0;
  244. }
  245. phys_addr_t hdmi_wp_get_audio_dma_addr(struct hdmi_wp_data *wp)
  246. {
  247. return wp->phys_base + HDMI_WP_AUDIO_DATA;
  248. }