hdmi_wp.c 7.7 KB

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