1 From 1246d16c393a2f5790e5492053f26e6b0b62cec8 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Tue, 17 Sep 2019 18:36:32 +0100
4 Subject: [PATCH] drm/vc4: Add support for H & V flips
6 The HVS supports horizontal and vertical flips whilst composing.
8 Expose these through the standard DRM rotation property.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
12 drivers/gpu/drm/vc4/vc4_plane.c | 54 +++++++++++++++++++++++++++------
13 1 file changed, 45 insertions(+), 9 deletions(-)
15 --- a/drivers/gpu/drm/vc4/vc4_plane.c
16 +++ b/drivers/gpu/drm/vc4/vc4_plane.c
17 @@ -560,7 +560,9 @@ static int vc4_plane_mode_set(struct drm
18 const struct hvs_format *format = vc4_get_hvs_format(fb->format->format);
19 u64 base_format_mod = fourcc_mod_broadcom_mod(fb->modifier);
20 int num_planes = drm_format_num_planes(format->drm);
21 + bool hflip = false, vflip = false;
22 u32 h_subsample, v_subsample;
23 + unsigned int rotation;
26 u32 scl0, scl1, pitch0;
27 @@ -568,11 +570,26 @@ static int vc4_plane_mode_set(struct drm
28 unsigned long irqflags;
29 u32 hvs_format = format->hvs;
33 ret = vc4_plane_setup_clipping_and_scaling(state);
37 + rotation = drm_rotation_simplify(state->rotation,
39 + DRM_MODE_REFLECT_X |
40 + DRM_MODE_REFLECT_Y);
42 + if ((rotation & DRM_MODE_ROTATE_MASK) == DRM_MODE_ROTATE_180) {
46 + if (rotation & DRM_MODE_REFLECT_X)
48 + if (rotation & DRM_MODE_REFLECT_Y)
51 /* Allocate the LBM memory that the HVS will use for temporary
52 * storage due to our scaling/format conversion.
54 @@ -609,6 +626,16 @@ static int vc4_plane_mode_set(struct drm
55 h_subsample = drm_format_horz_chroma_subsampling(format->drm);
56 v_subsample = drm_format_vert_chroma_subsampling(format->drm);
59 + src_y = vc4_state->src_y;
61 + /* When vflipped the image offset needs to be
62 + * the start of the last line of the image, and
63 + * the pitch will be subtracted from the offset.
65 + src_y = vc4_state->src_y +
66 + vc4_state->src_h[0] - 1;
68 switch (base_format_mod) {
69 case DRM_FORMAT_MOD_LINEAR:
70 tiling = SCALER_CTL0_TILING_LINEAR;
71 @@ -618,12 +645,13 @@ static int vc4_plane_mode_set(struct drm
74 for (i = 0; i < num_planes; i++) {
75 - vc4_state->offsets[i] += vc4_state->src_y /
76 + vc4_state->offsets[i] += src_y /
77 (i ? v_subsample : 1) *
80 vc4_state->offsets[i] += vc4_state->src_x /
81 - (i ? h_subsample : 1) *
83 + (i ? h_subsample : 1) *
88 @@ -651,11 +679,11 @@ static int vc4_plane_mode_set(struct drm
89 * SCALER_PITCH0_TILE_Y_OFFSET tells HVS how to walk from that
92 - u32 tile_y = (vc4_state->src_y >> 4) & 1;
93 - u32 subtile_y = (vc4_state->src_y >> 2) & 3;
94 - u32 utile_y = vc4_state->src_y & 3;
95 + u32 tile_y = (src_y >> 4) & 1;
96 + u32 subtile_y = (src_y >> 2) & 3;
97 + u32 utile_y = src_y & 3;
98 u32 x_off = vc4_state->src_x & tile_w_mask;
99 - u32 y_off = vc4_state->src_y & tile_h_mask;
100 + u32 y_off = src_y & tile_h_mask;
102 tiling = SCALER_CTL0_TILING_256B_OR_T;
103 pitch0 = (VC4_SET_FIELD(x_off, SCALER_PITCH0_SINK_PIX) |
104 @@ -732,7 +760,7 @@ static int vc4_plane_mode_set(struct drm
106 for (i = 0; i < num_planes; i++) {
107 vc4_state->offsets[i] += param * tile_w * tile;
108 - vc4_state->offsets[i] += vc4_state->src_y /
109 + vc4_state->offsets[i] += src_y /
110 (i ? v_subsample : 1) *
112 vc4_state->offsets[i] += x_off /
113 @@ -759,7 +787,9 @@ static int vc4_plane_mode_set(struct drm
114 VC4_SET_FIELD(tiling, SCALER_CTL0_TILING) |
115 (vc4_state->is_unity ? SCALER_CTL0_UNITY : 0) |
116 VC4_SET_FIELD(scl0, SCALER_CTL0_SCL0) |
117 - VC4_SET_FIELD(scl1, SCALER_CTL0_SCL1));
118 + VC4_SET_FIELD(scl1, SCALER_CTL0_SCL1) |
119 + (vflip ? SCALER_CTL0_VFLIP : 0) |
120 + (hflip ? SCALER_CTL0_HFLIP : 0));
122 /* Position Word 0: Image Positions and Alpha Value */
123 vc4_state->pos0_offset = vc4_state->dlist_count;
124 @@ -1203,5 +1233,11 @@ struct drm_plane *vc4_plane_init(struct
125 DRM_COLOR_YCBCR_BT709,
126 DRM_COLOR_YCBCR_LIMITED_RANGE);
128 + drm_plane_create_rotation_property(plane, DRM_MODE_ROTATE_0,
129 + DRM_MODE_ROTATE_0 |
130 + DRM_MODE_ROTATE_180 |
131 + DRM_MODE_REFLECT_X |
132 + DRM_MODE_REFLECT_Y);