Skip to content

Commit 4d1cd9d

Browse files
mripardpelwell
authored andcommitted
drm/vc4: hdmi: Define colorspace matrices
The current CSC setup code for the BCM2711 uses a sequence of register writes to configure the CSC depending on whether we output using a full or limited range. However, with the upcoming introduction of the YUV output, we're going to add new matrices to perform the conversions, so we should switch to something a bit more flexible that takes the matrix as an argument and programs the CSC accordingly. Acked-by: Thomas Zimmermann <tzimmermann@suse.de> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
1 parent dfbbcaf commit 4d1cd9d

1 file changed

Lines changed: 50 additions & 29 deletions

File tree

‎drivers/gpu/drm/vc4/vc4_hdmi.c‎

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,52 @@ static void vc4_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi,
791791
spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
792792
}
793793

794+
795+
/*
796+
* If we need to output Full Range RGB, then use the unity matrix
797+
*
798+
* [ 1 0 0 0]
799+
* [ 0 1 0 0]
800+
* [ 0 0 1 0]
801+
*
802+
* Matrix is signed 2p13 fixed point, with signed 9p6 offsets
803+
*/
804+
static const u16 vc5_hdmi_csc_full_rgb_unity[3][4] = {
805+
{ 0x2000, 0x0000, 0x0000, 0x0000 },
806+
{ 0x0000, 0x2000, 0x0000, 0x0000 },
807+
{ 0x0000, 0x0000, 0x2000, 0x0000 },
808+
};
809+
810+
/*
811+
* CEA VICs other than #1 require limited range RGB output unless
812+
* overridden by an AVI infoframe. Apply a colorspace conversion to
813+
* squash 0-255 down to 16-235. The matrix here is:
814+
*
815+
* [ 0.8594 0 0 16]
816+
* [ 0 0.8594 0 16]
817+
* [ 0 0 0.8594 16]
818+
*
819+
* Matrix is signed 2p13 fixed point, with signed 9p6 offsets
820+
*/
821+
static const u16 vc5_hdmi_csc_full_rgb_to_limited_rgb[3][4] = {
822+
{ 0x1b80, 0x0000, 0x0000, 0x0400 },
823+
{ 0x0000, 0x1b80, 0x0000, 0x0400 },
824+
{ 0x0000, 0x0000, 0x1b80, 0x0400 },
825+
};
826+
827+
static void vc5_hdmi_set_csc_coeffs(struct vc4_hdmi *vc4_hdmi,
828+
const u16 coeffs[3][4])
829+
{
830+
lockdep_assert_held(&vc4_hdmi->hw_lock);
831+
832+
HDMI_WRITE(HDMI_CSC_12_11, (coeffs[0][1] << 16) | coeffs[0][0]);
833+
HDMI_WRITE(HDMI_CSC_14_13, (coeffs[0][3] << 16) | coeffs[0][2]);
834+
HDMI_WRITE(HDMI_CSC_22_21, (coeffs[1][1] << 16) | coeffs[1][0]);
835+
HDMI_WRITE(HDMI_CSC_24_23, (coeffs[1][3] << 16) | coeffs[1][2]);
836+
HDMI_WRITE(HDMI_CSC_32_31, (coeffs[2][1] << 16) | coeffs[2][0]);
837+
HDMI_WRITE(HDMI_CSC_34_33, (coeffs[2][3] << 16) | coeffs[2][2]);
838+
}
839+
794840
static void vc5_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi,
795841
const struct drm_display_mode *mode)
796842
{
@@ -802,35 +848,10 @@ static void vc5_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi,
802848

803849
HDMI_WRITE(HDMI_VEC_INTERFACE_XBAR, 0x354021);
804850

805-
if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode)) {
806-
/* CEA VICs other than #1 requre limited range RGB
807-
* output unless overridden by an AVI infoframe.
808-
* Apply a colorspace conversion to squash 0-255 down
809-
* to 16-235. The matrix here is:
810-
*
811-
* [ 0.8594 0 0 16]
812-
* [ 0 0.8594 0 16]
813-
* [ 0 0 0.8594 16]
814-
* [ 0 0 0 1]
815-
* Matrix is signed 2p13 fixed point, with signed 9p6 offsets
816-
*/
817-
HDMI_WRITE(HDMI_CSC_12_11, (0x0000 << 16) | 0x1b80);
818-
HDMI_WRITE(HDMI_CSC_14_13, (0x0400 << 16) | 0x0000);
819-
HDMI_WRITE(HDMI_CSC_22_21, (0x1b80 << 16) | 0x0000);
820-
HDMI_WRITE(HDMI_CSC_24_23, (0x0400 << 16) | 0x0000);
821-
HDMI_WRITE(HDMI_CSC_32_31, (0x0000 << 16) | 0x0000);
822-
HDMI_WRITE(HDMI_CSC_34_33, (0x0400 << 16) | 0x1b80);
823-
} else {
824-
/* Still use the matrix for full range, but make it unity.
825-
* Matrix is signed 2p13 fixed point, with signed 9p6 offsets
826-
*/
827-
HDMI_WRITE(HDMI_CSC_12_11, (0x0000 << 16) | 0x2000);
828-
HDMI_WRITE(HDMI_CSC_14_13, (0x0000 << 16) | 0x0000);
829-
HDMI_WRITE(HDMI_CSC_22_21, (0x2000 << 16) | 0x0000);
830-
HDMI_WRITE(HDMI_CSC_24_23, (0x0000 << 16) | 0x0000);
831-
HDMI_WRITE(HDMI_CSC_32_31, (0x0000 << 16) | 0x0000);
832-
HDMI_WRITE(HDMI_CSC_34_33, (0x0000 << 16) | 0x2000);
833-
}
851+
if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode))
852+
vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_to_limited_rgb);
853+
else
854+
vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_unity);
834855

835856
HDMI_WRITE(HDMI_CSC_CTL, csc_ctl);
836857

0 commit comments

Comments
 (0)