Skip to content

Commit 8d376f1

Browse files
6by9pelwell
authored andcommitted
drm/vc4: hvs: Populate YUV to RGB matrices for GEN_6D
All the matrix entries for the YUV to RGB conversion matrices were being filled with the same coefficients. Compute the values for the BT601, BT709, and BT2020 matrices in both full and limited range, and program those into the hardware. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
1 parent a23cf5f commit 8d376f1

File tree

1 file changed

+71
-8
lines changed

1 file changed

+71
-8
lines changed

drivers/gpu/drm/vc4/vc4_hvs.c

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,9 +1845,71 @@ static const struct vc6_csc_coeff_entry csc_coeffs[2][3] = {
18451845
}
18461846
};
18471847

1848+
/*
1849+
* GEN_6D has a 3x3 matrix of signed 3p12 fixed point values, signed 13bit
1850+
* offset, and high and low clamp values. The offset can be applied before or
1851+
* after the multiply - for use here for YUV to RGB conversion it is easier to
1852+
* put it before.
1853+
* Clamp values are always set to max 0xfff and min 0, and the conversion always
1854+
* has the offset before the multiply.
1855+
*/
1856+
struct vc6_d0_csc_coeff_entry {
1857+
u32 csc[3][2];
1858+
};
1859+
1860+
static const struct vc6_d0_csc_coeff_entry vc6_d0_csc_coeffs[2][3] = {
1861+
[DRM_COLOR_YCBCR_LIMITED_RANGE] = {
1862+
[DRM_COLOR_YCBCR_BT601] = {
1863+
.csc = {
1864+
{ 0x1f002543, 0x00003313 },
1865+
{ 0x18002543, 0xf377e5fc },
1866+
{ 0x18002543, 0x408d0000 }
1867+
}
1868+
},
1869+
[DRM_COLOR_YCBCR_BT709] = {
1870+
.csc = {
1871+
{ 0x1f002543, 0x0000395e },
1872+
{ 0x18002543, 0xf92deef2 },
1873+
{ 0x18002543, 0x43990000 }
1874+
}
1875+
},
1876+
[DRM_COLOR_YCBCR_BT2020] = {
1877+
.csc = {
1878+
{ 0x1f002543, 0x000035a0 },
1879+
{ 0x18002543, 0xfa00eb20 },
1880+
{ 0x18002543, 0x44800000 }
1881+
}
1882+
}
1883+
},
1884+
[DRM_COLOR_YCBCR_FULL_RANGE] = {
1885+
[DRM_COLOR_YCBCR_BT601] = {
1886+
.csc = {
1887+
{ 0x00002000, 0x00002cdd },
1888+
{ 0x18002000, 0xf4fde926 },
1889+
{ 0x18002000, 0x38b40000 }
1890+
}
1891+
},
1892+
[DRM_COLOR_YCBCR_BT709] = {
1893+
.csc = {
1894+
{ 0x00002000, 0x00003265 },
1895+
{ 0x18002000, 0xfa01f105 },
1896+
{ 0x18002000, 0x3b610000 }
1897+
}
1898+
},
1899+
[DRM_COLOR_YCBCR_BT2020] = {
1900+
.csc = {
1901+
{ 0x00002000, 0x00002f30 },
1902+
{ 0x18002000, 0xfabcedb7 },
1903+
{ 0x18002000, 0x3c340000 }
1904+
}
1905+
}
1906+
}
1907+
};
1908+
18481909
static int vc6_hvs_hw_init(struct vc4_hvs *hvs)
18491910
{
18501911
const struct vc6_csc_coeff_entry *coeffs;
1912+
const struct vc6_d0_csc_coeff_entry *d0_coeffs;
18511913
unsigned int i;
18521914

18531915
HVS_WRITE(SCALER6_CONTROL,
@@ -1884,16 +1946,17 @@ static int vc6_hvs_hw_init(struct vc4_hvs *hvs)
18841946
HVS_WRITE(CFC1_N_NL_CSC_CTRL(i), BIT(15));
18851947
}
18861948
} else {
1887-
for (i = 0; i < 8; i++) {
1888-
HVS_WRITE(SCALER_PI_CMP_CSC_RED0(i), 0x1f002566);
1889-
HVS_WRITE(SCALER_PI_CMP_CSC_RED1(i), 0x3994);
1949+
for (i = 0; i < 6; i++) {
1950+
d0_coeffs = &vc6_d0_csc_coeffs[i / 3][i % 3];
1951+
HVS_WRITE(SCALER_PI_CMP_CSC_RED0(i), d0_coeffs->csc[0][0]);
1952+
HVS_WRITE(SCALER_PI_CMP_CSC_RED1(i), d0_coeffs->csc[0][1]);
18901953
HVS_WRITE(SCALER_PI_CMP_CSC_RED_CLAMP(i), 0xfff00000);
1891-
HVS_WRITE(SCALER_PI_CMP_CSC_CFG(i), 0x1);
1892-
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN0(i), 0x18002566);
1893-
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN1(i), 0xf927eee2);
1954+
HVS_WRITE(SCALER_PI_CMP_CSC_CFG(i), 1);
1955+
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN0(i), d0_coeffs->csc[1][0]);
1956+
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN1(i), d0_coeffs->csc[1][1]);
18941957
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN_CLAMP(i), 0xfff00000);
1895-
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE0(i), 0x18002566);
1896-
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE1(i), 0x43d80000);
1958+
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE0(i), d0_coeffs->csc[2][0]);
1959+
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE1(i), d0_coeffs->csc[2][1]);
18971960
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE_CLAMP(i), 0xfff00000);
18981961
}
18991962
}

0 commit comments

Comments
 (0)