Skip to content

Commit 3c12863

Browse files
Kalyan Thotarobclark
authored andcommitted
drm/msm/dpu: add support for dither block in display
This change enables dither block for primary interface in display. Enabled for 6bpc in the current version. Changes in v1: - Remove redundant error checks (Rob). Signed-off-by: Kalyan Thota <[email protected]> Tested-by: Douglas Anderson <[email protected]> Tested-by: Kristian H. Kristensen <[email protected]> Signed-off-by: Rob Clark <[email protected]>
1 parent 520c651 commit 3c12863

File tree

3 files changed

+121
-9
lines changed

3 files changed

+121
-9
lines changed

drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,36 @@ struct dpu_encoder_virt {
208208

209209
#define to_dpu_encoder_virt(x) container_of(x, struct dpu_encoder_virt, base)
210210

211+
static u32 dither_matrix[DITHER_MATRIX_SZ] = {
212+
15, 7, 13, 5, 3, 11, 1, 9, 12, 4, 14, 6, 0, 8, 2, 10
213+
};
214+
215+
static void _dpu_encoder_setup_dither(struct dpu_encoder_phys *phys)
216+
{
217+
struct dpu_hw_dither_cfg dither_cfg = { 0 };
218+
219+
if (!phys->hw_pp || !phys->hw_pp->ops.setup_dither)
220+
return;
221+
222+
switch (phys->connector->display_info.bpc) {
223+
case 6:
224+
dither_cfg.c0_bitdepth = 6;
225+
dither_cfg.c1_bitdepth = 6;
226+
dither_cfg.c2_bitdepth = 6;
227+
dither_cfg.c3_bitdepth = 6;
228+
dither_cfg.temporal_en = 0;
229+
break;
230+
default:
231+
phys->hw_pp->ops.setup_dither(phys->hw_pp, NULL);
232+
return;
233+
}
234+
235+
memcpy(&dither_cfg.matrix, dither_matrix,
236+
sizeof(u32) * DITHER_MATRIX_SZ);
237+
238+
phys->hw_pp->ops.setup_dither(phys->hw_pp, &dither_cfg);
239+
}
240+
211241
void dpu_encoder_helper_report_irq_timeout(struct dpu_encoder_phys *phys_enc,
212242
enum dpu_intr_idx intr_idx)
213243
{
@@ -1059,6 +1089,7 @@ static void _dpu_encoder_virt_enable_helper(struct drm_encoder *drm_enc)
10591089
struct dpu_encoder_virt *dpu_enc = NULL;
10601090
struct msm_drm_private *priv;
10611091
struct dpu_kms *dpu_kms;
1092+
int i;
10621093

10631094
if (!drm_enc || !drm_enc->dev) {
10641095
DPU_ERROR("invalid parameters\n");
@@ -1081,6 +1112,14 @@ static void _dpu_encoder_virt_enable_helper(struct drm_encoder *drm_enc)
10811112
dpu_kms->catalog);
10821113

10831114
_dpu_encoder_update_vsync_source(dpu_enc, &dpu_enc->disp_info);
1115+
1116+
if (dpu_enc->disp_info.intf_type == DRM_MODE_ENCODER_DSI) {
1117+
for (i = 0; i < dpu_enc->num_phys_encs; i++) {
1118+
struct dpu_encoder_phys *phys = dpu_enc->phys_encs[i];
1119+
1120+
_dpu_encoder_setup_dither(phys);
1121+
}
1122+
}
10841123
}
10851124

10861125
void dpu_encoder_virt_runtime_resume(struct drm_encoder *drm_enc)

drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
#define PP_FBC_BUDGET_CTL 0x038
2929
#define PP_FBC_LOSSY_MODE 0x03C
3030

31+
#define PP_DITHER_EN 0x000
32+
#define PP_DITHER_BITDEPTH 0x004
33+
#define PP_DITHER_MATRIX 0x008
34+
35+
#define DITHER_DEPTH_MAP_INDEX 9
36+
37+
static u32 dither_depth_map[DITHER_DEPTH_MAP_INDEX] = {
38+
0, 0, 0, 0, 0, 0, 0, 1, 2
39+
};
40+
3141
static const struct dpu_pingpong_cfg *_pingpong_offset(enum dpu_pingpong pp,
3242
const struct dpu_mdss_cfg *m,
3343
void __iomem *addr,
@@ -49,6 +59,37 @@ static const struct dpu_pingpong_cfg *_pingpong_offset(enum dpu_pingpong pp,
4959
return ERR_PTR(-EINVAL);
5060
}
5161

62+
static void dpu_hw_pp_setup_dither(struct dpu_hw_pingpong *pp,
63+
struct dpu_hw_dither_cfg *cfg)
64+
{
65+
struct dpu_hw_blk_reg_map *c;
66+
u32 i, base, data = 0;
67+
68+
c = &pp->hw;
69+
base = pp->caps->sblk->dither.base;
70+
if (!cfg) {
71+
DPU_REG_WRITE(c, base + PP_DITHER_EN, 0);
72+
return;
73+
}
74+
75+
data = dither_depth_map[cfg->c0_bitdepth] & REG_MASK(2);
76+
data |= (dither_depth_map[cfg->c1_bitdepth] & REG_MASK(2)) << 2;
77+
data |= (dither_depth_map[cfg->c2_bitdepth] & REG_MASK(2)) << 4;
78+
data |= (dither_depth_map[cfg->c3_bitdepth] & REG_MASK(2)) << 6;
79+
data |= (cfg->temporal_en) ? (1 << 8) : 0;
80+
81+
DPU_REG_WRITE(c, base + PP_DITHER_BITDEPTH, data);
82+
83+
for (i = 0; i < DITHER_MATRIX_SZ - 3; i += 4) {
84+
data = (cfg->matrix[i] & REG_MASK(4)) |
85+
((cfg->matrix[i + 1] & REG_MASK(4)) << 4) |
86+
((cfg->matrix[i + 2] & REG_MASK(4)) << 8) |
87+
((cfg->matrix[i + 3] & REG_MASK(4)) << 12);
88+
DPU_REG_WRITE(c, base + PP_DITHER_MATRIX + i, data);
89+
}
90+
DPU_REG_WRITE(c, base + PP_DITHER_EN, 1);
91+
}
92+
5293
static int dpu_hw_pp_setup_te_config(struct dpu_hw_pingpong *pp,
5394
struct dpu_hw_tear_check *te)
5495
{
@@ -180,15 +221,19 @@ static u32 dpu_hw_pp_get_line_count(struct dpu_hw_pingpong *pp)
180221
return line;
181222
}
182223

183-
static void _setup_pingpong_ops(struct dpu_hw_pingpong_ops *ops,
184-
const struct dpu_pingpong_cfg *hw_cap)
224+
static void _setup_pingpong_ops(struct dpu_hw_pingpong *c,
225+
unsigned long features)
185226
{
186-
ops->setup_tearcheck = dpu_hw_pp_setup_te_config;
187-
ops->enable_tearcheck = dpu_hw_pp_enable_te;
188-
ops->connect_external_te = dpu_hw_pp_connect_external_te;
189-
ops->get_vsync_info = dpu_hw_pp_get_vsync_info;
190-
ops->poll_timeout_wr_ptr = dpu_hw_pp_poll_timeout_wr_ptr;
191-
ops->get_line_count = dpu_hw_pp_get_line_count;
227+
c->ops.setup_tearcheck = dpu_hw_pp_setup_te_config;
228+
c->ops.enable_tearcheck = dpu_hw_pp_enable_te;
229+
c->ops.connect_external_te = dpu_hw_pp_connect_external_te;
230+
c->ops.get_vsync_info = dpu_hw_pp_get_vsync_info;
231+
c->ops.poll_timeout_wr_ptr = dpu_hw_pp_poll_timeout_wr_ptr;
232+
c->ops.get_line_count = dpu_hw_pp_get_line_count;
233+
234+
if (test_bit(DPU_PINGPONG_DITHER, &features) &&
235+
IS_SC7180_TARGET(c->hw.hwversion))
236+
c->ops.setup_dither = dpu_hw_pp_setup_dither;
192237
};
193238

194239
static struct dpu_hw_blk_ops dpu_hw_ops;
@@ -212,7 +257,7 @@ struct dpu_hw_pingpong *dpu_hw_pingpong_init(enum dpu_pingpong idx,
212257

213258
c->idx = idx;
214259
c->caps = cfg;
215-
_setup_pingpong_ops(&c->ops, c->caps);
260+
_setup_pingpong_ops(c, c->caps->features);
216261

217262
dpu_hw_blk_init(&c->base, DPU_HW_BLK_PINGPONG, idx, &dpu_hw_ops);
218263

drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "dpu_hw_util.h"
1111
#include "dpu_hw_blk.h"
1212

13+
#define DITHER_MATRIX_SZ 16
14+
1315
struct dpu_hw_pingpong;
1416

1517
struct dpu_hw_tear_check {
@@ -34,6 +36,26 @@ struct dpu_hw_pp_vsync_info {
3436
u32 wr_ptr_line_count; /* current line within pp fifo (wr ptr) */
3537
};
3638

39+
/**
40+
* struct dpu_hw_dither_cfg - dither feature structure
41+
* @flags: for customizing operations
42+
* @temporal_en: temperal dither enable
43+
* @c0_bitdepth: c0 component bit depth
44+
* @c1_bitdepth: c1 component bit depth
45+
* @c2_bitdepth: c2 component bit depth
46+
* @c3_bitdepth: c2 component bit depth
47+
* @matrix: dither strength matrix
48+
*/
49+
struct dpu_hw_dither_cfg {
50+
u64 flags;
51+
u32 temporal_en;
52+
u32 c0_bitdepth;
53+
u32 c1_bitdepth;
54+
u32 c2_bitdepth;
55+
u32 c3_bitdepth;
56+
u32 matrix[DITHER_MATRIX_SZ];
57+
};
58+
3759
/**
3860
*
3961
* struct dpu_hw_pingpong_ops : Interface to the pingpong Hw driver functions
@@ -82,6 +104,12 @@ struct dpu_hw_pingpong_ops {
82104
* Obtain current vertical line counter
83105
*/
84106
u32 (*get_line_count)(struct dpu_hw_pingpong *pp);
107+
108+
/**
109+
* Setup dither matix for pingpong block
110+
*/
111+
void (*setup_dither)(struct dpu_hw_pingpong *pp,
112+
struct dpu_hw_dither_cfg *cfg);
85113
};
86114

87115
struct dpu_hw_pingpong {

0 commit comments

Comments
 (0)