Skip to content

Commit 84abcf1

Browse files
Yongqiang Niuckhu-mediatek
authored andcommitted
drm/mediatek: Add ctm property support
Add ctm property support Signed-off-by: Yongqiang Niu <[email protected]> Signed-off-by: Hsin-Yi Wang <[email protected]> Signed-off-by: CK Hu <[email protected]>
1 parent 4cebc1d commit 84abcf1

File tree

3 files changed

+82
-5
lines changed

3 files changed

+82
-5
lines changed

drivers/gpu/drm/mediatek/mtk_drm_crtc.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,10 @@ static void mtk_drm_crtc_atomic_flush(struct drm_crtc *crtc,
606606
if (mtk_crtc->event)
607607
mtk_crtc->pending_needs_vblank = true;
608608
if (crtc->state->color_mgmt_changed)
609-
for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
609+
for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
610610
mtk_ddp_gamma_set(mtk_crtc->ddp_comp[i], crtc->state);
611+
mtk_ddp_ctm_set(mtk_crtc->ddp_comp[i], crtc->state);
612+
}
611613
mtk_drm_crtc_hw_config(mtk_crtc);
612614
}
613615

@@ -730,6 +732,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
730732
int pipe = priv->num_pipes;
731733
int ret;
732734
int i;
735+
bool has_ctm = false;
733736
uint gamma_lut_size = 0;
734737

735738
if (!path)
@@ -782,8 +785,13 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
782785

783786
mtk_crtc->ddp_comp[i] = comp;
784787

785-
if (comp->funcs && comp->funcs->gamma_set)
786-
gamma_lut_size = MTK_LUT_SIZE;
788+
if (comp->funcs) {
789+
if (comp->funcs->gamma_set)
790+
gamma_lut_size = MTK_LUT_SIZE;
791+
792+
if (comp->funcs->ctm_set)
793+
has_ctm = true;
794+
}
787795
}
788796

789797
for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
@@ -807,7 +815,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
807815

808816
if (gamma_lut_size)
809817
drm_mode_crtc_set_gamma_size(&mtk_crtc->base, gamma_lut_size);
810-
drm_crtc_enable_color_mgmt(&mtk_crtc->base, 0, false, gamma_lut_size);
818+
drm_crtc_enable_color_mgmt(&mtk_crtc->base, 0, has_ctm, gamma_lut_size);
811819
priv->num_pipes++;
812820
mutex_init(&mtk_crtc->hw_lock);
813821

drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@
3737
#define CCORR_EN BIT(0)
3838
#define DISP_CCORR_CFG 0x0020
3939
#define CCORR_RELAY_MODE BIT(0)
40+
#define CCORR_ENGINE_EN BIT(1)
41+
#define CCORR_GAMMA_OFF BIT(2)
42+
#define CCORR_WGAMUT_SRC_CLIP BIT(3)
4043
#define DISP_CCORR_SIZE 0x0030
44+
#define DISP_CCORR_COEF_0 0x0080
45+
#define DISP_CCORR_COEF_1 0x0084
46+
#define DISP_CCORR_COEF_2 0x0088
47+
#define DISP_CCORR_COEF_3 0x008C
48+
#define DISP_CCORR_COEF_4 0x0090
4149

4250
#define DISP_DITHER_EN 0x0000
4351
#define DITHER_EN BIT(0)
@@ -188,7 +196,7 @@ static void mtk_ccorr_config(struct mtk_ddp_comp *comp, unsigned int w,
188196
unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
189197
{
190198
mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_CCORR_SIZE);
191-
mtk_ddp_write(cmdq_pkt, CCORR_RELAY_MODE, comp, DISP_CCORR_CFG);
199+
mtk_ddp_write(cmdq_pkt, CCORR_ENGINE_EN, comp, DISP_CCORR_CFG);
192200
}
193201

194202
static void mtk_ccorr_start(struct mtk_ddp_comp *comp)
@@ -201,6 +209,57 @@ static void mtk_ccorr_stop(struct mtk_ddp_comp *comp)
201209
writel_relaxed(0x0, comp->regs + DISP_CCORR_EN);
202210
}
203211

212+
/* Converts a DRM S31.32 value to the HW S1.10 format. */
213+
static u16 mtk_ctm_s31_32_to_s1_10(u64 in)
214+
{
215+
u16 r;
216+
217+
/* Sign bit. */
218+
r = in & BIT_ULL(63) ? BIT(11) : 0;
219+
220+
if ((in & GENMASK_ULL(62, 33)) > 0) {
221+
/* identity value 0x100000000 -> 0x400, */
222+
/* if bigger this, set it to max 0x7ff. */
223+
r |= GENMASK(10, 0);
224+
} else {
225+
/* take the 11 most important bits. */
226+
r |= (in >> 22) & GENMASK(10, 0);
227+
}
228+
229+
return r;
230+
}
231+
232+
static void mtk_ccorr_ctm_set(struct mtk_ddp_comp *comp,
233+
struct drm_crtc_state *state)
234+
{
235+
struct drm_property_blob *blob = state->ctm;
236+
struct drm_color_ctm *ctm;
237+
const u64 *input;
238+
uint16_t coeffs[9] = { 0 };
239+
int i;
240+
struct cmdq_pkt *cmdq_pkt = NULL;
241+
242+
if (!blob)
243+
return;
244+
245+
ctm = (struct drm_color_ctm *)blob->data;
246+
input = ctm->matrix;
247+
248+
for (i = 0; i < ARRAY_SIZE(coeffs); i++)
249+
coeffs[i] = mtk_ctm_s31_32_to_s1_10(input[i]);
250+
251+
mtk_ddp_write(cmdq_pkt, coeffs[0] << 16 | coeffs[1],
252+
comp, DISP_CCORR_COEF_0);
253+
mtk_ddp_write(cmdq_pkt, coeffs[2] << 16 | coeffs[3],
254+
comp, DISP_CCORR_COEF_1);
255+
mtk_ddp_write(cmdq_pkt, coeffs[4] << 16 | coeffs[5],
256+
comp, DISP_CCORR_COEF_2);
257+
mtk_ddp_write(cmdq_pkt, coeffs[6] << 16 | coeffs[7],
258+
comp, DISP_CCORR_COEF_3);
259+
mtk_ddp_write(cmdq_pkt, coeffs[8] << 16,
260+
comp, DISP_CCORR_COEF_4);
261+
}
262+
204263
static void mtk_dither_config(struct mtk_ddp_comp *comp, unsigned int w,
205264
unsigned int h, unsigned int vrefresh,
206265
unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
@@ -271,6 +330,7 @@ static const struct mtk_ddp_comp_funcs ddp_ccorr = {
271330
.config = mtk_ccorr_config,
272331
.start = mtk_ccorr_start,
273332
.stop = mtk_ccorr_stop,
333+
.ctm_set = mtk_ccorr_ctm_set,
274334
};
275335

276336
static const struct mtk_ddp_comp_funcs ddp_dither = {

drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ struct mtk_ddp_comp_funcs {
9090
struct drm_crtc_state *state);
9191
void (*bgclr_in_on)(struct mtk_ddp_comp *comp);
9292
void (*bgclr_in_off)(struct mtk_ddp_comp *comp);
93+
void (*ctm_set)(struct mtk_ddp_comp *comp,
94+
struct drm_crtc_state *state);
9395
};
9496

9597
struct mtk_ddp_comp {
@@ -191,6 +193,13 @@ static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
191193
comp->funcs->bgclr_in_off(comp);
192194
}
193195

196+
static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
197+
struct drm_crtc_state *state)
198+
{
199+
if (comp->funcs && comp->funcs->ctm_set)
200+
comp->funcs->ctm_set(comp, state);
201+
}
202+
194203
int mtk_ddp_comp_get_id(struct device_node *node,
195204
enum mtk_ddp_comp_type comp_type);
196205
int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,

0 commit comments

Comments
 (0)