Skip to content

Commit d8b07cb

Browse files
6by9popcornmix
authored andcommitted
drm/vc4: crtc: Add support for a custom background color
Since a previous patch introduced the BACKGROUND_COLOR CRTC property, which defaults to solid black, take it into account when programming the hardware. The exact registers used varies between the hardware generations, but is supported by all of them. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
1 parent bf57dee commit d8b07cb

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

drivers/gpu/drm/vc4/vc4_crtc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <drm/drm_atomic.h>
3939
#include <drm/drm_atomic_helper.h>
4040
#include <drm/drm_atomic_uapi.h>
41+
#include <drm/drm_blend.h>
4142
#include <drm/drm_fb_dma_helper.h>
4243
#include <drm/drm_framebuffer.h>
4344
#include <drm/drm_drv.h>
@@ -1434,6 +1435,8 @@ int __vc4_crtc_init(struct drm_device *drm,
14341435
if (ret)
14351436
return ret;
14361437

1438+
drm_crtc_attach_background_color_property(crtc);
1439+
14371440
drm_crtc_helper_add(crtc, crtc_helper_funcs);
14381441

14391442
if (vc4->gen == VC4_GEN_4) {

drivers/gpu/drm/vc4/vc4_hvs.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
12561256
struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
12571257
struct vc4_crtc_state *vc4_state = to_vc4_crtc_state(crtc->state);
12581258
unsigned int channel = vc4_state->assigned_channel;
1259+
u64 bgcolor = crtc->state->background_color;
12591260
struct drm_plane *plane;
12601261
struct vc4_plane_state *vc4_plane_state;
12611262
bool debug_dump_regs = false;
@@ -1320,16 +1321,46 @@ void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
13201321
WARN_ON_ONCE(dlist_next - dlist_start != vc4_state->mm->mm_node.size);
13211322

13221323
if (vc4->gen >= VC4_GEN_6_C) {
1323-
/* This sets a black background color fill, as is the case
1324+
/* This sets the background color fill, as is the case
13241325
* with other DRM drivers.
13251326
*/
1327+
if (vc4->gen == VC4_GEN_6_C) {
1328+
HVS_WRITE(SCALER6_DISPX_BGND(channel),
1329+
VC4_SET_FIELD(DRM_ARGB64_GETR_BPCS(bgcolor, 8),
1330+
SCALER6_DISPX_BGND_FILL_RED) |
1331+
VC4_SET_FIELD(DRM_ARGB64_GETG_BPCS(bgcolor, 8),
1332+
SCALER6_DISPX_BGND_FILL_GREEN) |
1333+
VC4_SET_FIELD(DRM_ARGB64_GETB_BPCS(bgcolor, 8),
1334+
SCALER6_DISPX_BGND_FILL_BLUE) |
1335+
VC4_SET_FIELD(DRM_ARGB64_GETA_BPCS(bgcolor, 8),
1336+
SCALER6_DISPX_BGND_FILL_ALPHA));
1337+
} else {
1338+
/* GEN_6_D takes a 12bit background colour */
1339+
HVS_WRITE(SCALER6D_DISPX_BGND0(channel),
1340+
VC4_SET_FIELD(DRM_ARGB64_GETG_BPCS(bgcolor, 12),
1341+
SCALER6D_DISPX_BGND0_FILL_GREEN) |
1342+
VC4_SET_FIELD(DRM_ARGB64_GETB_BPCS(bgcolor, 12),
1343+
SCALER6D_DISPX_BGND0_FILL_BLUE));
1344+
HVS_WRITE(SCALER6D_DISPX_BGND1(channel),
1345+
VC4_SET_FIELD(DRM_ARGB64_GETR_BPCS(bgcolor, 12),
1346+
SCALER6D_DISPX_BGND1_FILL_RED) |
1347+
VC4_SET_FIELD(DRM_ARGB64_GETA_BPCS(bgcolor, 12),
1348+
SCALER6D_DISPX_BGND1_FILL_ALPHA));
1349+
}
13261350
hvs->bg_fill[channel] = enable_bg_fill;
13271351
} else {
13281352
/* we can actually run with a lower core clock when background
13291353
* fill is enabled on VC4_GEN_5 so leave it enabled always.
13301354
*/
13311355
HVS_WRITE(SCALER_DISPBKGNDX(channel),
1332-
HVS_READ(SCALER_DISPBKGNDX(channel)) |
1356+
(HVS_READ(SCALER_DISPBKGNDX(channel)) &
1357+
~SCALER_DISPBKGND_FILL_MASK) |
1358+
VC4_SET_FIELD(DRM_ARGB64_GETR_BPCS(bgcolor, 8),
1359+
SCALER_DISPBKGND_FILL_RED) |
1360+
VC4_SET_FIELD(DRM_ARGB64_GETG_BPCS(bgcolor, 8),
1361+
SCALER_DISPBKGND_FILL_GREEN) |
1362+
VC4_SET_FIELD(DRM_ARGB64_GETB_BPCS(bgcolor, 8),
1363+
SCALER_DISPBKGND_FILL_BLUE) |
13331364
SCALER_DISPBKGND_FILL);
13341365
}
13351366

drivers/gpu/drm/vc4/vc4_regs.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@
402402
* opaque display planes will cover everything.
403403
*/
404404
# define SCALER_DISPBKGND_FILL BIT(24)
405+
# define SCALER_DISPBKGND_FILL_RED_MASK VC4_MASK(23, 16)
406+
# define SCALER_DISPBKGND_FILL_RED_SHIFT 16
407+
# define SCALER_DISPBKGND_FILL_GREEN_MASK VC4_MASK(15, 8)
408+
# define SCALER_DISPBKGND_FILL_GREEN_SHIFT 8
409+
# define SCALER_DISPBKGND_FILL_BLUE_MASK VC4_MASK(7, 0)
410+
# define SCALER_DISPBKGND_FILL_BLUE_SHIFT 0
411+
# define SCALER_DISPBKGND_FILL_MASK (SCALER_DISPBKGND_FILL_RED_MASK | \
412+
SCALER_DISPBKGND_FILL_GREEN_MASK | \
413+
SCALER_DISPBKGND_FILL_BLUE_MASK)
405414

406415
#define SCALER_DISPSTAT0 0x00000048
407416
# define SCALER_DISPSTATX_MODE_MASK VC4_MASK(31, 30)
@@ -580,9 +589,16 @@
580589
# define SCALER6_DISPX_CTRL1_INTLACE BIT(0)
581590

582591
#define SCALER6_DISP0_BGND 0x00000038
583-
#define SCALER6_DISPX_BGND(x) ((hvs->vc4->gen == VC4_GEN_6_C) ? \
584-
(SCALER6_DISP0_BGND + ((x) * (SCALER6_DISP1_BGND - SCALER6_DISP0_BGND))) : \
585-
(SCALER6D_DISP0_BGND + ((x) * (SCALER6D_DISP1_BGND - SCALER6D_DISP0_BGND))))
592+
#define SCALER6_DISPX_BGND(x) \
593+
(SCALER6_DISP0_BGND + ((x) * (SCALER6_DISP1_BGND - SCALER6_DISP0_BGND)))
594+
# define SCALER6_DISPX_BGND_FILL_ALPHA_MASK VC4_MASK(31, 24)
595+
# define SCALER6_DISPX_BGND_FILL_ALPHA_SHIFT 24
596+
# define SCALER6_DISPX_BGND_FILL_RED_MASK VC4_MASK(23, 16)
597+
# define SCALER6_DISPX_BGND_FILL_RED_SHIFT 16
598+
# define SCALER6_DISPX_BGND_FILL_GREEN_MASK VC4_MASK(15, 8)
599+
# define SCALER6_DISPX_BGND_FILL_GREEN_SHIFT 8
600+
# define SCALER6_DISPX_BGND_FILL_BLUE_MASK VC4_MASK(7, 0)
601+
# define SCALER6_DISPX_BGND_FILL_BLUE_SHIFT 0
586602

587603
#define SCALER6_DISP0_LPTRS 0x0000003c
588604
#define SCALER6_DISPX_LPTRS(x) ((hvs->vc4->gen == VC4_GEN_6_C) ? \
@@ -701,7 +717,19 @@
701717
#define SCALER6D_DISP0_CTRL0 0x00000100
702718
#define SCALER6D_DISP0_CTRL1 0x00000104
703719
#define SCALER6D_DISP0_BGND0 0x00000108
720+
#define SCALER6D_DISPX_BGND0(x) \
721+
(SCALER6D_DISP0_BGND0 + ((x) * (SCALER6D_DISP1_BGND0 - SCALER6D_DISP0_BGND0)))
722+
# define SCALER6D_DISPX_BGND0_FILL_GREEN_MASK VC4_MASK(31, 20)
723+
# define SCALER6D_DISPX_BGND0_FILL_GREEN_SHIFT 20
724+
# define SCALER6D_DISPX_BGND0_FILL_BLUE_MASK VC4_MASK(15, 4)
725+
# define SCALER6D_DISPX_BGND0_FILL_BLUE_SHIFT 4
704726
#define SCALER6D_DISP0_BGND1 0x0000010c
727+
#define SCALER6D_DISPX_BGND1(x) \
728+
(SCALER6D_DISP0_BGND1 + ((x) * (SCALER6D_DISP1_BGND1 - SCALER6D_DISP0_BGND1)))
729+
# define SCALER6D_DISPX_BGND1_FILL_ALPHA_MASK VC4_MASK(31, 20)
730+
# define SCALER6D_DISPX_BGND1_FILL_ALPHA_SHIFT 20
731+
# define SCALER6D_DISPX_BGND1_FILL_RED_MASK VC4_MASK(15, 4)
732+
# define SCALER6D_DISPX_BGND1_FILL_RED_SHIFT 4
705733
#define SCALER6D_DISP0_LPTRS 0x00000110
706734
#define SCALER6D_DISP0_COB 0x00000114
707735
#define SCALER6D_DISP0_STATUS 0x00000118

0 commit comments

Comments
 (0)