0520-drm-vc4-Fix-support-for-interlaced-modes-on-HDMI.patch 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. From 6e6624aeedaa97f1b81636e0be4a7478ccb22d69 Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Wed, 28 Sep 2016 17:30:25 -0700
  4. Subject: [PATCH] drm/vc4: Fix support for interlaced modes on HDMI.
  5. We really do need to be using the halved V fields. I had been
  6. confused by the code I was using as a reference because it stored
  7. halved vsync fields but not halved vdisplay, so it looked like I only
  8. needed to divide vdisplay by 2.
  9. This reverts part of Mario's timestamping fixes that prevented
  10. CRTC_HALVE_V from applying, and instead adjusts the timestamping code
  11. to not use the crtc field in that case.
  12. Fixes locking of 1920x1080x60i on my Dell 2408WFP. There are black
  13. bars on the top and bottom, but I suspect that might be an
  14. under/overscan flags problem as opposed to video timings.
  15. Signed-off-by: Eric Anholt <eric@anholt.net>
  16. ---
  17. drivers/gpu/drm/vc4/vc4_crtc.c | 54 +++++++++++++++++++++++-------------------
  18. drivers/gpu/drm/vc4/vc4_hdmi.c | 45 ++++++++++-------------------------
  19. drivers/gpu/drm/vc4/vc4_regs.h | 3 +++
  20. 3 files changed, 44 insertions(+), 58 deletions(-)
  21. --- a/drivers/gpu/drm/vc4/vc4_crtc.c
  22. +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
  23. @@ -220,7 +220,7 @@ int vc4_crtc_get_scanoutpos(struct drm_d
  24. * and need to make things up in a approximative but consistent way.
  25. */
  26. ret |= DRM_SCANOUTPOS_IN_VBLANK;
  27. - vblank_lines = mode->crtc_vtotal - mode->crtc_vdisplay;
  28. + vblank_lines = mode->vtotal - mode->vdisplay;
  29. if (flags & DRM_CALLED_FROM_VBLIRQ) {
  30. /*
  31. @@ -368,7 +368,6 @@ static void vc4_crtc_mode_set_nofb(struc
  32. struct drm_crtc_state *state = crtc->state;
  33. struct drm_display_mode *mode = &state->adjusted_mode;
  34. bool interlace = mode->flags & DRM_MODE_FLAG_INTERLACE;
  35. - u32 vactive = (mode->vdisplay >> (interlace ? 1 : 0));
  36. bool is_dsi = (vc4_encoder->type == VC4_ENCODER_TYPE_DSI0 ||
  37. vc4_encoder->type == VC4_ENCODER_TYPE_DSI1);
  38. u32 format = is_dsi ? PV_CONTROL_FORMAT_DSIV_24 : PV_CONTROL_FORMAT_24;
  39. @@ -395,34 +394,49 @@ static void vc4_crtc_mode_set_nofb(struc
  40. VC4_SET_FIELD(mode->hdisplay, PV_HORZB_HACTIVE));
  41. CRTC_WRITE(PV_VERTA,
  42. - VC4_SET_FIELD(mode->vtotal - mode->vsync_end,
  43. + VC4_SET_FIELD(mode->crtc_vtotal - mode->crtc_vsync_end,
  44. PV_VERTA_VBP) |
  45. - VC4_SET_FIELD(mode->vsync_end - mode->vsync_start,
  46. + VC4_SET_FIELD(mode->crtc_vsync_end - mode->crtc_vsync_start,
  47. PV_VERTA_VSYNC));
  48. CRTC_WRITE(PV_VERTB,
  49. - VC4_SET_FIELD(mode->vsync_start - mode->vdisplay,
  50. + VC4_SET_FIELD(mode->crtc_vsync_start - mode->crtc_vdisplay,
  51. PV_VERTB_VFP) |
  52. - VC4_SET_FIELD(vactive, PV_VERTB_VACTIVE));
  53. + VC4_SET_FIELD(mode->crtc_vdisplay, PV_VERTB_VACTIVE));
  54. if (interlace) {
  55. CRTC_WRITE(PV_VERTA_EVEN,
  56. - VC4_SET_FIELD(mode->vtotal - mode->vsync_end - 1,
  57. + VC4_SET_FIELD(mode->crtc_vtotal -
  58. + mode->crtc_vsync_end - 1,
  59. PV_VERTA_VBP) |
  60. - VC4_SET_FIELD(mode->vsync_end - mode->vsync_start,
  61. + VC4_SET_FIELD(mode->crtc_vsync_end -
  62. + mode->crtc_vsync_start,
  63. PV_VERTA_VSYNC));
  64. CRTC_WRITE(PV_VERTB_EVEN,
  65. - VC4_SET_FIELD(mode->vsync_start - mode->vdisplay,
  66. + VC4_SET_FIELD(mode->crtc_vsync_start -
  67. + mode->crtc_vdisplay,
  68. PV_VERTB_VFP) |
  69. - VC4_SET_FIELD(vactive, PV_VERTB_VACTIVE));
  70. + VC4_SET_FIELD(mode->crtc_vdisplay, PV_VERTB_VACTIVE));
  71. +
  72. + /* We set up first field even mode for HDMI. VEC's
  73. + * NTSC mode would want first field odd instead, once
  74. + * we support it (to do so, set ODD_FIRST and put the
  75. + * delay in VSYNCD_EVEN instead).
  76. + */
  77. + CRTC_WRITE(PV_V_CONTROL,
  78. + PV_VCONTROL_CONTINUOUS |
  79. + (is_dsi ? PV_VCONTROL_DSI : 0) |
  80. + PV_VCONTROL_INTERLACE |
  81. + VC4_SET_FIELD(mode->htotal / 2,
  82. + PV_VCONTROL_ODD_DELAY));
  83. + CRTC_WRITE(PV_VSYNCD_EVEN, 0);
  84. + } else {
  85. + CRTC_WRITE(PV_V_CONTROL,
  86. + PV_VCONTROL_CONTINUOUS |
  87. + (is_dsi ? PV_VCONTROL_DSI : 0));
  88. }
  89. CRTC_WRITE(PV_HACT_ACT, mode->hdisplay);
  90. - CRTC_WRITE(PV_V_CONTROL,
  91. - PV_VCONTROL_CONTINUOUS |
  92. - (is_dsi ? PV_VCONTROL_DSI : 0) |
  93. - (interlace ? PV_VCONTROL_INTERLACE : 0));
  94. -
  95. CRTC_WRITE(PV_CONTROL,
  96. VC4_SET_FIELD(format, PV_CONTROL_FORMAT) |
  97. VC4_SET_FIELD(vc4_get_fifo_full_level(format),
  98. @@ -550,16 +564,6 @@ static bool vc4_crtc_mode_fixup(struct d
  99. return false;
  100. }
  101. - /*
  102. - * Interlaced video modes got CRTC_INTERLACE_HALVE_V applied when
  103. - * coming from user space. We don't want this, as it screws up
  104. - * vblank timestamping, so fix it up.
  105. - */
  106. - drm_mode_set_crtcinfo(adjusted_mode, 0);
  107. -
  108. - DRM_DEBUG_KMS("[CRTC:%d] adjusted_mode :\n", crtc->base.id);
  109. - drm_mode_debug_printmodeline(adjusted_mode);
  110. -
  111. return true;
  112. }
  113. --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
  114. +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
  115. @@ -219,35 +219,10 @@ vc4_hdmi_connector_best_encoder(struct d
  116. return hdmi_connector->encoder;
  117. }
  118. -/*
  119. - * drm_helper_probe_single_connector_modes() applies drm_mode_set_crtcinfo to
  120. - * all modes with flag CRTC_INTERLACE_HALVE_V. We don't want this, as it
  121. - * screws up vblank timestamping for interlaced modes, so fix it up.
  122. - */
  123. -static int vc4_hdmi_connector_probe_modes(struct drm_connector *connector,
  124. - uint32_t maxX, uint32_t maxY)
  125. -{
  126. - struct drm_display_mode *mode;
  127. - int count;
  128. -
  129. - count = drm_helper_probe_single_connector_modes(connector, maxX, maxY);
  130. - if (count == 0)
  131. - return 0;
  132. -
  133. - DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed adapted modes :\n",
  134. - connector->base.id, connector->name);
  135. - list_for_each_entry(mode, &connector->modes, head) {
  136. - drm_mode_set_crtcinfo(mode, 0);
  137. - drm_mode_debug_printmodeline(mode);
  138. - }
  139. -
  140. - return count;
  141. -}
  142. -
  143. static const struct drm_connector_funcs vc4_hdmi_connector_funcs = {
  144. .dpms = drm_atomic_helper_connector_dpms,
  145. .detect = vc4_hdmi_connector_detect,
  146. - .fill_modes = vc4_hdmi_connector_probe_modes,
  147. + .fill_modes = drm_helper_probe_single_connector_modes,
  148. .destroy = vc4_hdmi_connector_destroy,
  149. .reset = drm_atomic_helper_connector_reset,
  150. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  151. @@ -316,16 +291,20 @@ static void vc4_hdmi_encoder_mode_set(st
  152. bool debug_dump_regs = false;
  153. bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC;
  154. bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC;
  155. - u32 vactive = (mode->vdisplay >>
  156. - ((mode->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0));
  157. - u32 verta = (VC4_SET_FIELD(mode->vsync_end - mode->vsync_start,
  158. + bool interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
  159. + u32 verta = (VC4_SET_FIELD(mode->crtc_vsync_end - mode->crtc_vsync_start,
  160. VC4_HDMI_VERTA_VSP) |
  161. - VC4_SET_FIELD(mode->vsync_start - mode->vdisplay,
  162. + VC4_SET_FIELD(mode->crtc_vsync_start - mode->crtc_vdisplay,
  163. VC4_HDMI_VERTA_VFP) |
  164. - VC4_SET_FIELD(vactive, VC4_HDMI_VERTA_VAL));
  165. + VC4_SET_FIELD(mode->crtc_vdisplay, VC4_HDMI_VERTA_VAL));
  166. u32 vertb = (VC4_SET_FIELD(0, VC4_HDMI_VERTB_VSPO) |
  167. - VC4_SET_FIELD(mode->vtotal - mode->vsync_end,
  168. + VC4_SET_FIELD(mode->crtc_vtotal - mode->crtc_vsync_end,
  169. VC4_HDMI_VERTB_VBP));
  170. + u32 vertb_even = (VC4_SET_FIELD(0, VC4_HDMI_VERTB_VSPO) |
  171. + VC4_SET_FIELD(mode->crtc_vtotal -
  172. + mode->crtc_vsync_end -
  173. + interlaced,
  174. + VC4_HDMI_VERTB_VBP));
  175. u32 csc_ctl;
  176. if (debug_dump_regs) {
  177. @@ -358,7 +337,7 @@ static void vc4_hdmi_encoder_mode_set(st
  178. HDMI_WRITE(VC4_HDMI_VERTA0, verta);
  179. HDMI_WRITE(VC4_HDMI_VERTA1, verta);
  180. - HDMI_WRITE(VC4_HDMI_VERTB0, vertb);
  181. + HDMI_WRITE(VC4_HDMI_VERTB0, vertb_even);
  182. HDMI_WRITE(VC4_HDMI_VERTB1, vertb);
  183. HD_WRITE(VC4_HD_VID_CTL,
  184. --- a/drivers/gpu/drm/vc4/vc4_regs.h
  185. +++ b/drivers/gpu/drm/vc4/vc4_regs.h
  186. @@ -183,6 +183,9 @@
  187. # define PV_CONTROL_EN BIT(0)
  188. #define PV_V_CONTROL 0x04
  189. +# define PV_VCONTROL_ODD_DELAY_MASK VC4_MASK(22, 6)
  190. +# define PV_VCONTROL_ODD_DELAY_SHIFT 6
  191. +# define PV_VCONTROL_ODD_FIRST BIT(5)
  192. # define PV_VCONTROL_INTERLACE BIT(4)
  193. # define PV_VCONTROL_DSI BIT(3)
  194. # define PV_VCONTROL_COMMAND BIT(2)