0510-drm-vc4-Enable-limited-range-RGB-output-with-CEA-mod.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From 330916bb64ca043ad03993aa4041edc99f68cf8f Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Thu, 15 Sep 2016 17:52:17 +0100
  4. Subject: [PATCH] drm/vc4: Enable limited range RGB output with CEA modes.
  5. ---
  6. drivers/gpu/drm/vc4/vc4_hdmi.c | 28 ++++++++++++++++++++++++++--
  7. drivers/gpu/drm/vc4/vc4_regs.h | 9 ++++++++-
  8. 2 files changed, 34 insertions(+), 3 deletions(-)
  9. --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
  10. +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
  11. @@ -285,6 +285,7 @@ static void vc4_hdmi_encoder_mode_set(st
  12. struct drm_display_mode *unadjusted_mode,
  13. struct drm_display_mode *mode)
  14. {
  15. + struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
  16. struct drm_device *dev = encoder->dev;
  17. struct vc4_dev *vc4 = to_vc4_dev(dev);
  18. bool debug_dump_regs = false;
  19. @@ -300,6 +301,7 @@ static void vc4_hdmi_encoder_mode_set(st
  20. u32 vertb = (VC4_SET_FIELD(0, VC4_HDMI_VERTB_VSPO) |
  21. VC4_SET_FIELD(mode->vtotal - mode->vsync_end,
  22. VC4_HDMI_VERTB_VBP));
  23. + u32 csc_ctl;
  24. if (debug_dump_regs) {
  25. DRM_INFO("HDMI regs before:\n");
  26. @@ -338,9 +340,31 @@ static void vc4_hdmi_encoder_mode_set(st
  27. (vsync_pos ? 0 : VC4_HD_VID_CTL_VSYNC_LOW) |
  28. (hsync_pos ? 0 : VC4_HD_VID_CTL_HSYNC_LOW));
  29. + csc_ctl = VC4_SET_FIELD(VC4_HD_CSC_CTL_ORDER_BGR,
  30. + VC4_HD_CSC_CTL_ORDER);
  31. +
  32. + if (vc4_encoder->hdmi_monitor && drm_match_cea_mode(mode) != 0) {
  33. + /* Enable limited range RGB output. This matrix is:
  34. + * [ 0 0 0.8594 16]
  35. + * [ 0 0.8594 0 16]
  36. + * [ 0.8594 0 0 16]
  37. + * [ 0 0 0 1]
  38. + */
  39. + csc_ctl |= VC4_HD_CSC_CTL_ENABLE;
  40. + csc_ctl |= VC4_HD_CSC_CTL_RGB2YCC;
  41. + csc_ctl |= VC4_SET_FIELD(VC4_HD_CSC_CTL_MODE_CUSTOM,
  42. + VC4_HD_CSC_CTL_MODE);
  43. +
  44. + HD_WRITE(VC4_HD_CSC_12_11, (0x000 << 16) | 0x000);
  45. + HD_WRITE(VC4_HD_CSC_14_13, (0x100 << 16) | 0x6e0);
  46. + HD_WRITE(VC4_HD_CSC_22_21, (0x6e0 << 16) | 0x000);
  47. + HD_WRITE(VC4_HD_CSC_24_23, (0x100 << 16) | 0x000);
  48. + HD_WRITE(VC4_HD_CSC_32_31, (0x000 << 16) | 0x6e0);
  49. + HD_WRITE(VC4_HD_CSC_34_33, (0x100 << 16) | 0x000);
  50. + }
  51. +
  52. /* The RGB order applies even when CSC is disabled. */
  53. - HD_WRITE(VC4_HD_CSC_CTL, VC4_SET_FIELD(VC4_HD_CSC_CTL_ORDER_BGR,
  54. - VC4_HD_CSC_CTL_ORDER));
  55. + HD_WRITE(VC4_HD_CSC_CTL, csc_ctl);
  56. HDMI_WRITE(VC4_HDMI_FIFO_CTL, VC4_HDMI_FIFO_CTL_MASTER_SLAVE_N);
  57. --- a/drivers/gpu/drm/vc4/vc4_regs.h
  58. +++ b/drivers/gpu/drm/vc4/vc4_regs.h
  59. @@ -530,10 +530,17 @@
  60. # define VC4_HD_CSC_CTL_MODE_SHIFT 2
  61. # define VC4_HD_CSC_CTL_MODE_RGB_TO_SD_YPRPB 0
  62. # define VC4_HD_CSC_CTL_MODE_RGB_TO_HD_YPRPB 1
  63. -# define VC4_HD_CSC_CTL_MODE_CUSTOM 2
  64. +# define VC4_HD_CSC_CTL_MODE_CUSTOM 3
  65. # define VC4_HD_CSC_CTL_RGB2YCC BIT(1)
  66. # define VC4_HD_CSC_CTL_ENABLE BIT(0)
  67. +#define VC4_HD_CSC_12_11 0x044
  68. +#define VC4_HD_CSC_14_13 0x048
  69. +#define VC4_HD_CSC_22_21 0x04c
  70. +#define VC4_HD_CSC_24_23 0x050
  71. +#define VC4_HD_CSC_32_31 0x054
  72. +#define VC4_HD_CSC_34_33 0x058
  73. +
  74. #define VC4_HD_FRAME_COUNT 0x068
  75. /* HVS display list information. */