On Wed, Aug 14, 2019 at 10:47:40AM +, Mihail Atanassov wrote:
> On Wednesday, 14 August 2019 08:52:18 BST james qian wang (Arm Technology
> China) wrote:
> > On Tue, Aug 13, 2019 at 09:51:08AM +, Mihail Atanassov wrote:
> > > Hi James,
> > >
> > > On Tuesday, 13 August 2019 05:56:07 BST james qian wang (Arm Technology
> > > China) wrote:
> > > > Many komeda component support color management like layer and IPS, so
> > > > komeda_color_manager/state are introduced to manager gamma, csc and
> > > > degamma
> > > > together for easily share it to multiple componpent.
> > > >
> > > > And for komeda_color_manager which:
> > > > - convert drm 3d gamma lut to komeda specific gamma coeffs
> > > > - gamma table management and hide the HW difference for komeda-CORE
> > > >
> > > > Signed-off-by: James Qian Wang (Arm Technology China)
> > > >
> > > > ---
> > > > .../arm/display/komeda/komeda_color_mgmt.c| 126 ++
> > > > .../arm/display/komeda/komeda_color_mgmt.h| 32 -
> > > > 2 files changed, 156 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
> > > > b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
> > > > index 9d14a92dbb17..bf2388d641b9 100644
> > > > --- a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
> > > > +++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c
> > > > @@ -4,7 +4,9 @@
> > > > * Author: James.Qian.Wang
> > > > *
> > > > */
> > > > +#include
> > > >
> > > > +#include "malidp_utils.h"
> > > > #include "komeda_color_mgmt.h"
> > > >
> > > > /* 10bit precision YUV2RGB matrix */
> > > > @@ -65,3 +67,127 @@ const s32 *komeda_select_yuv2rgb_coeffs(u32
> > > > color_encoding, u32 color_range)
> > > >
> > > > return coeffs;
> > > > }
> > > > +
> > > > +struct gamma_curve_sector {
> > > > + u32 boundary_start;
> > > > + u32 num_of_segments;
> > > > + u32 segment_width;
> > > > +};
> > > > +
> > > > +struct gamma_curve_segment {
> > > > + u32 start;
> > > > + u32 end;
> > > > +};
> > > > +
> > > > +static struct gamma_curve_sector sector_tbl[] = {
> > > > + { 0,4, 4 },
> Max LUT precision (see full response below) is determined by your
> smallest segment, which is 4.
> > > > + { 16, 4, 4 },
> > > > + { 32, 4, 8 },
> > > > + { 64, 4, 16 },
> > > > + { 128, 4, 32 },
> > > > + { 256, 4, 64 },
> > > > + { 512, 16, 32 },
> > > > + { 1024, 24, 128 },
> > > > +};
> > > > +
> > > > +static struct gamma_curve_sector igamma_sector_tbl[] = {
> > > > + {0, 64, 64},
> > > > +};
> > > > +
> > > > +static void
> > > > +drm_lut_to_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs,
> > > > + struct gamma_curve_sector *sector_tbl, u32
> > > > num_sectors)
> > > > +{
> > > > + struct drm_color_lut *lut;
> > > > + u32 i, j, in, num = 0;
> > > > +
> > > > + if (!lut_blob)
> > > > + return;
> > > > +
> > > > + lut = lut_blob->data;
> > > > +
> > > > + for (i = 0; i < num_sectors; i++) {
> > > > + for (j = 0; j < sector_tbl[i].num_of_segments; j++) {
> > > > + in = sector_tbl[i].boundary_start +
> > > > +j * sector_tbl[i].segment_width;
> > > > +
> > > > + coeffs[num++] =
> > > > drm_color_lut_extract(lut[in].red,
> > > > + KOMEDA_COLOR_PRECISION);
> > > > + }
> > > > + }
> > > > +
> > > > + coeffs[num] = BIT(KOMEDA_COLOR_PRECISION);
> > > > +}
> > > > +
> > > > +void drm_lut_to_igamma_coeffs(struct drm_property_blob *lut_blob, u32
> > > > *coeffs)
> > > > +{
> > > > + drm_lut_to_coeffs(lut_blob, coeffs,
> > > > + igamma_sector_tbl,
> > > > ARRAY_SIZE(igamma_sector_tbl));
> > > > +}
> > > > +
> > > > +void drm_lut_to_fgamma_coeffs(struct drm_property_blob *lut_blob, u32
> > > > *coeffs)
> > > > +{
> > > > + drm_lut_to_coeffs(lut_blob, coeffs,
> > > > + sector_tbl, ARRAY_SIZE(sector_tbl));
> > > > +}
> > > > +
> > > > +void drm_ctm_to_coeffs(struct drm_property_blob *ctm_blob, u32 *coeffs)
> > > > +{
> > > > + struct drm_color_ctm *ctm;
> > > > + u32 i;
> > > > +
> > > > + if (!ctm_blob)
> > > > + return;
> > > > +
> > > > + ctm = ctm_blob->data;
> > > > +
> > > > + for (i = 0; i < KOMEDA_N_CTM_COEFFS; ++i) {
> > > > + /* Convert from S31.32 to Q3.12. */
> > > > + s64 v = ctm->matrix[i];
> > > > +
> > > > + coeffs[i] = clamp_val(v, 1 - (1LL << 34), (1LL << 34) -
> > > > 1) >> 20;
> > > CTM matrix values are S31.32, i.e. sign-magnitude, so clamp_val won't
> > > give you the right result for negative coeffs. See
> > > malidp_crtc_atomic_check_ctm for the sign-mag -> 2's complement
> > >