Skip to content

Commit ee724ea

Browse files
cristicc6by9
authored andcommitted
drm/rockchip: vop2: Support setting custom background color
Commit bec7cbfa7d4f upstream. The Rockchip VOP2 display controller allows configuring the background color of each video output port. Since a previous patch introduced the BACKGROUND_COLOR CRTC property, which defaults to solid black, make use of it when programming the hardware. Note the maximum precision allowed by the display controller is 10bpc, while the alpha component is not supported, hence ignored. Tested-by: Diederik de Haas <diederik@cknow-tech.com> Reviewed-by: Andy Yan <andyshrk@163.com> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com> Link: https://patch.msgid.link/20260303-rk3588-bgcolor-v8-4-fee377037ad1@collabora.com Signed-off-by: Daniel Stone <daniels@collabora.com>
1 parent 0d6abe4 commit ee724ea

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

drivers/gpu/drm/rockchip/rockchip_drm_vop2.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,13 @@ static int vop2_plane_atomic_check(struct drm_plane *plane,
10581058
return -EINVAL;
10591059
}
10601060

1061+
if ((cstate->background_color << 16) &&
1062+
(fb->format->has_alpha || pstate->alpha != 0xffff)) {
1063+
drm_dbg_kms(vop2->drm,
1064+
"Alpha-blending with background color is unsupported\n");
1065+
return -EINVAL;
1066+
}
1067+
10611068
return 0;
10621069
}
10631070

@@ -1548,6 +1555,7 @@ static void vop2_post_config(struct drm_crtc *crtc)
15481555
struct vop2_video_port *vp = to_vop2_video_port(crtc);
15491556
struct vop2 *vop2 = vp->vop2;
15501557
struct drm_display_mode *mode = &crtc->state->adjusted_mode;
1558+
u64 bgcolor = crtc->state->background_color;
15511559
u16 vtotal = mode->crtc_vtotal;
15521560
u16 hdisplay = mode->crtc_hdisplay;
15531561
u16 hact_st = mode->crtc_htotal - mode->crtc_hsync_start;
@@ -1593,7 +1601,15 @@ static void vop2_post_config(struct drm_crtc *crtc)
15931601
vop2_vp_write(vp, RK3568_VP_POST_DSP_VACT_INFO_F1, val);
15941602
}
15951603

1596-
vop2_vp_write(vp, RK3568_VP_DSP_BG, 0);
1604+
/*
1605+
* Background color is programmed with 10 bits of precision.
1606+
* Since performance is more important than accuracy here,
1607+
* make use of the DRM_ARGB64_GET*_BPCS() helpers.
1608+
*/
1609+
val = FIELD_PREP(RK3568_VP_DSP_BG__DSP_BG_RED, DRM_ARGB64_GETR_BPCS(bgcolor, 10));
1610+
FIELD_MODIFY(RK3568_VP_DSP_BG__DSP_BG_GREEN, &val, DRM_ARGB64_GETG_BPCS(bgcolor, 10));
1611+
FIELD_MODIFY(RK3568_VP_DSP_BG__DSP_BG_BLUE, &val, DRM_ARGB64_GETB_BPCS(bgcolor, 10));
1612+
vop2_vp_write(vp, RK3568_VP_DSP_BG, val);
15971613
}
15981614

15991615
static int us_to_vertical_line(struct drm_display_mode *mode, int us)
@@ -1972,6 +1988,10 @@ static int vop2_crtc_state_dump(struct drm_crtc *crtc, struct seq_file *s)
19721988
drm_get_bus_format_name(vcstate->bus_format));
19731989
seq_printf(s, "\toutput_mode[%x]", vcstate->output_mode);
19741990
seq_printf(s, " color_space[%d]\n", vcstate->color_space);
1991+
seq_printf(s, "\tbackground color (10bpc): r=0x%x g=0x%x b=0x%x\n",
1992+
DRM_ARGB64_GETR_BPCS(cstate->background_color, 10),
1993+
DRM_ARGB64_GETG_BPCS(cstate->background_color, 10),
1994+
DRM_ARGB64_GETB_BPCS(cstate->background_color, 10));
19751995
seq_printf(s, " Display mode: %dx%d%s%d\n",
19761996
mode->hdisplay, mode->vdisplay, interlaced ? "i" : "p",
19771997
drm_mode_vrefresh(mode));
@@ -2461,6 +2481,8 @@ static int vop2_create_crtcs(struct vop2 *vop2)
24612481
return dev_err_probe(drm->dev, ret,
24622482
"crtc init for video_port%d failed\n", i);
24632483

2484+
drm_crtc_attach_background_color_property(&vp->crtc);
2485+
24642486
drm_crtc_helper_add(&vp->crtc, &vop2_crtc_helper_funcs);
24652487
if (vop2->lut_regs) {
24662488
const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];

drivers/gpu/drm/rockchip/rockchip_drm_vop2.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ enum dst_factor_mode {
658658
#define RK3588_VP_CLK_CTRL__DCLK_OUT_DIV GENMASK(3, 2)
659659
#define RK3588_VP_CLK_CTRL__DCLK_CORE_DIV GENMASK(1, 0)
660660

661+
#define RK3568_VP_DSP_BG__DSP_BG_RED GENMASK(29, 20)
662+
#define RK3568_VP_DSP_BG__DSP_BG_GREEN GENMASK(19, 10)
663+
#define RK3568_VP_DSP_BG__DSP_BG_BLUE GENMASK(9, 0)
664+
661665
#define RK3568_VP_POST_SCL_CTRL__VSCALEDOWN BIT(1)
662666
#define RK3568_VP_POST_SCL_CTRL__HSCALEDOWN BIT(0)
663667

0 commit comments

Comments
 (0)