Skip to content

Commit 5db5de6

Browse files
committed
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 <[email protected]>
1 parent 933bb6b commit 5db5de6

File tree

1 file changed

+71
-10
lines changed

1 file changed

+71
-10
lines changed

drivers/gpu/drm/vc4/vc4_hvs.c

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,9 +1845,69 @@ 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+
*/
1854+
struct vc6_d0_csc_coeff_entry {
1855+
u32 csc[3][4];
1856+
};
1857+
1858+
static const struct vc6_d0_csc_coeff_entry vc6_d0_csc_coeffs[2][3] = {
1859+
[DRM_COLOR_YCBCR_LIMITED_RANGE] = {
1860+
[DRM_COLOR_YCBCR_BT601] = {
1861+
.csc = {
1862+
{ 0x1f002543, 0x00003313, 0xfff00000, 0x1 },
1863+
{ 0x18002543, 0xf377e5fc, 0xfff00000, 0x0 },
1864+
{ 0x18002543, 0x408d0000, 0xfff00000, 0x0 }
1865+
}
1866+
},
1867+
[DRM_COLOR_YCBCR_BT709] = {
1868+
.csc = {
1869+
{ 0x1f002543, 0x0000395e, 0xfff00000, 0x1 },
1870+
{ 0x18002543, 0xf92deef2, 0xfff00000, 0x0 },
1871+
{ 0x18002543, 0x43990000, 0xfff00000, 0x0 }
1872+
}
1873+
},
1874+
[DRM_COLOR_YCBCR_BT2020] = {
1875+
.csc = {
1876+
{ 0x1f002543, 0x00003313, 0xfff00000, 0x1 },
1877+
{ 0x18002543, 0xf377e5fc, 0xfff00000, 0x0 },
1878+
{ 0x18002543, 0x408d0000, 0xfff00000, 0x0 }
1879+
}
1880+
}
1881+
},
1882+
[DRM_COLOR_YCBCR_FULL_RANGE] = {
1883+
[DRM_COLOR_YCBCR_BT601] = {
1884+
.csc = {
1885+
{ 0x00002000, 0x00002cdd, 0xfff00000, 0x1 },
1886+
{ 0x18002000, 0xf4fde926, 0xfff00000, 0x0 },
1887+
{ 0x18002000, 0x38b40000, 0xfff00000, 0x0 }
1888+
}
1889+
},
1890+
[DRM_COLOR_YCBCR_BT709] = {
1891+
.csc = {
1892+
{ 0x00002000, 0x00003265, 0xfff00000, 0x1 },
1893+
{ 0x18002000, 0xfa01f105, 0xfff00000, 0x0 },
1894+
{ 0x18002000, 0x3b610000, 0xfff00000, 0x0 }
1895+
}
1896+
},
1897+
[DRM_COLOR_YCBCR_BT2020] = {
1898+
.csc = {
1899+
{ 0x00002000, 0x00002f30, 0xfff00000, 0x1 },
1900+
{ 0x18002000, 0xfabcedb7, 0xfff00000, 0x0 },
1901+
{ 0x18002000, 0x3c340000, 0xfff00000, 0x0 }
1902+
}
1903+
}
1904+
}
1905+
};
1906+
18481907
static int vc6_hvs_hw_init(struct vc4_hvs *hvs)
18491908
{
18501909
const struct vc6_csc_coeff_entry *coeffs;
1910+
const struct vc6_d0_csc_coeff_entry *d0_coeffs;
18511911
unsigned int i;
18521912

18531913
HVS_WRITE(SCALER6_CONTROL,
@@ -1885,16 +1945,17 @@ static int vc6_hvs_hw_init(struct vc4_hvs *hvs)
18851945
}
18861946
} else {
18871947
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);
1890-
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);
1894-
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);
1897-
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE_CLAMP(i), 0xfff00000);
1948+
d0_coeffs = &vc6_d0_csc_coeffs[i / 3][i % 3];
1949+
HVS_WRITE(SCALER_PI_CMP_CSC_RED0(i), d0_coeffs->csc[0][0]);
1950+
HVS_WRITE(SCALER_PI_CMP_CSC_RED1(i), d0_coeffs->csc[0][1]);
1951+
HVS_WRITE(SCALER_PI_CMP_CSC_RED_CLAMP(i), d0_coeffs->csc[0][2]);
1952+
HVS_WRITE(SCALER_PI_CMP_CSC_CFG(i), d0_coeffs->csc[0][3]);
1953+
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN0(i), d0_coeffs->csc[1][0]);
1954+
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN1(i), d0_coeffs->csc[1][1]);
1955+
HVS_WRITE(SCALER_PI_CMP_CSC_GREEN_CLAMP(i), d0_coeffs->csc[1][2]);
1956+
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE0(i), d0_coeffs->csc[2][0]);
1957+
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE1(i), d0_coeffs->csc[2][1]);
1958+
HVS_WRITE(SCALER_PI_CMP_CSC_BLUE_CLAMP(i), d0_coeffs->csc[2][2]);
18981959
}
18991960
}
19001961

0 commit comments

Comments
 (0)