Skip to content

Commit bb1d2dd

Browse files
jernejskwens
authored andcommitted
drm/sun4i: layer: replace mixer with layer struct
This allows to almost completely decouple layer code from mixer. This is important for DE33. Reviewed-by: Chen-Yu Tsai <wens@kernel.org> Tested-by: Ryan Walklin <ryan@testtoast.com> Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com> Link: https://patch.msgid.link/20251104180942.61538-29-jernej.skrabec@gmail.com Signed-off-by: Chen-Yu Tsai <wens@kernel.org>
1 parent d1fe263 commit bb1d2dd

9 files changed

Lines changed: 66 additions & 67 deletions

File tree

drivers/gpu/drm/sun4i/sun8i_csc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ void sun8i_csc_config(struct sun8i_layer *layer,
233233
u32 mode = sun8i_csc_get_mode(state);
234234
u32 base;
235235

236-
if (layer->mixer->cfg->de_type == SUN8I_MIXER_DE3) {
236+
if (layer->cfg->de_type == SUN8I_MIXER_DE3) {
237237
sun8i_de3_ccsc_setup(layer->regs, layer->channel,
238238
mode, state->color_encoding,
239239
state->color_range);
240240
return;
241241
}
242242

243-
base = ccsc_base[layer->mixer->cfg->lay_cfg.ccsc][layer->channel];
243+
base = ccsc_base[layer->cfg->ccsc][layer->channel];
244244

245245
sun8i_csc_setup(layer->regs, base,
246246
mode, state->color_encoding,

drivers/gpu/drm/sun4i/sun8i_mixer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ static struct drm_plane **sun8i_layers_init(struct drm_device *drm,
339339

340340
layer = sun8i_vi_layer_init_one(drm, mixer, type,
341341
mixer->engine.regs, i,
342-
phy_index, plane_cnt);
342+
phy_index, plane_cnt,
343+
&mixer->cfg->lay_cfg);
343344
if (IS_ERR(layer)) {
344345
dev_err(drm->dev,
345346
"Couldn't initialize overlay plane\n");
@@ -364,7 +365,8 @@ static struct drm_plane **sun8i_layers_init(struct drm_device *drm,
364365

365366
layer = sun8i_ui_layer_init_one(drm, mixer, type,
366367
mixer->engine.regs, index,
367-
phy_index, plane_cnt);
368+
phy_index, plane_cnt,
369+
&mixer->cfg->lay_cfg);
368370
if (IS_ERR(layer)) {
369371
dev_err(drm->dev, "Couldn't initialize %s plane\n",
370372
i ? "overlay" : "primary");

drivers/gpu/drm/sun4i/sun8i_mixer.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,14 @@ enum {
225225
};
226226

227227
struct sun8i_layer {
228-
struct drm_plane plane;
229-
struct sun8i_mixer *mixer;
230-
int type;
231-
int index;
232-
int channel;
233-
int overlay;
234-
struct regmap *regs;
228+
struct drm_plane plane;
229+
struct sun8i_mixer *mixer;
230+
int type;
231+
int index;
232+
int channel;
233+
int overlay;
234+
struct regmap *regs;
235+
const struct sun8i_layer_cfg *cfg;
235236
};
236237

237238
static inline struct sun8i_layer *
@@ -260,14 +261,14 @@ sun8i_blender_regmap(struct sun8i_mixer *mixer)
260261
}
261262

262263
static inline u32
263-
sun8i_channel_base(struct sun8i_mixer *mixer, int channel)
264+
sun8i_channel_base(struct sun8i_layer *layer)
264265
{
265-
if (mixer->cfg->de_type == SUN8I_MIXER_DE33)
266-
return DE33_CH_BASE + channel * DE33_CH_SIZE;
267-
else if (mixer->cfg->de_type == SUN8I_MIXER_DE3)
268-
return DE3_CH_BASE + channel * DE3_CH_SIZE;
266+
if (layer->cfg->de_type == SUN8I_MIXER_DE33)
267+
return DE33_CH_BASE + layer->channel * DE33_CH_SIZE;
268+
else if (layer->cfg->de_type == SUN8I_MIXER_DE3)
269+
return DE3_CH_BASE + layer->channel * DE3_CH_SIZE;
269270
else
270-
return DE2_CH_BASE + channel * DE2_CH_SIZE;
271+
return DE2_CH_BASE + layer->channel * DE2_CH_SIZE;
271272
}
272273

273274
int sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format);

drivers/gpu/drm/sun4i/sun8i_ui_layer.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,20 @@
2828

2929
static void sun8i_ui_layer_disable(struct sun8i_layer *layer)
3030
{
31-
struct sun8i_mixer *mixer = layer->mixer;
32-
u32 ch_base = sun8i_channel_base(mixer, layer->channel);
31+
u32 ch_base = sun8i_channel_base(layer);
3332

34-
regmap_write(mixer->engine.regs,
33+
regmap_write(layer->regs,
3534
SUN8I_MIXER_CHAN_UI_LAYER_ATTR(ch_base, layer->overlay), 0);
3635
}
3736

3837
static void sun8i_ui_layer_update_attributes(struct sun8i_layer *layer,
3938
struct drm_plane *plane)
4039
{
4140
struct drm_plane_state *state = plane->state;
42-
struct sun8i_mixer *mixer = layer->mixer;
4341
const struct drm_format_info *fmt;
4442
u32 val, ch_base, hw_fmt;
4543

46-
ch_base = sun8i_channel_base(mixer, layer->channel);
44+
ch_base = sun8i_channel_base(layer);
4745
fmt = state->fb->format;
4846
sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt);
4947

@@ -62,7 +60,6 @@ static void sun8i_ui_layer_update_coord(struct sun8i_layer *layer,
6260
struct drm_plane *plane)
6361
{
6462
struct drm_plane_state *state = plane->state;
65-
struct sun8i_mixer *mixer = layer->mixer;
6663
u32 src_w, src_h, dst_w, dst_h;
6764
u32 outsize, insize;
6865
u32 hphase, vphase;
@@ -71,7 +68,7 @@ static void sun8i_ui_layer_update_coord(struct sun8i_layer *layer,
7168
DRM_DEBUG_DRIVER("Updating UI channel %d overlay %d\n",
7269
layer->channel, layer->overlay);
7370

74-
ch_base = sun8i_channel_base(mixer, layer->channel);
71+
ch_base = sun8i_channel_base(layer);
7572

7673
src_w = drm_rect_width(&state->src) >> 16;
7774
src_h = drm_rect_height(&state->src) >> 16;
@@ -103,7 +100,7 @@ static void sun8i_ui_layer_update_coord(struct sun8i_layer *layer,
103100
hscale = state->src_w / state->crtc_w;
104101
vscale = state->src_h / state->crtc_h;
105102

106-
if (mixer->cfg->de_type == SUN8I_MIXER_DE33) {
103+
if (layer->cfg->de_type == SUN8I_MIXER_DE33) {
107104
sun8i_vi_scaler_setup(layer, src_w, src_h, dst_w, dst_h,
108105
hscale, vscale, hphase, vphase,
109106
state->fb->format);
@@ -115,7 +112,7 @@ static void sun8i_ui_layer_update_coord(struct sun8i_layer *layer,
115112
}
116113
} else {
117114
DRM_DEBUG_DRIVER("HW scaling is not needed\n");
118-
if (mixer->cfg->de_type == SUN8I_MIXER_DE33)
115+
if (layer->cfg->de_type == SUN8I_MIXER_DE33)
119116
sun8i_vi_scaler_enable(layer, false);
120117
else
121118
sun8i_ui_scaler_enable(layer, false);
@@ -126,14 +123,13 @@ static void sun8i_ui_layer_update_buffer(struct sun8i_layer *layer,
126123
struct drm_plane *plane)
127124
{
128125
struct drm_plane_state *state = plane->state;
129-
struct sun8i_mixer *mixer = layer->mixer;
130126
struct drm_framebuffer *fb = state->fb;
131127
struct drm_gem_dma_object *gem;
132128
dma_addr_t dma_addr;
133129
u32 ch_base;
134130
int bpp;
135131

136-
ch_base = sun8i_channel_base(mixer, layer->channel);
132+
ch_base = sun8i_channel_base(layer);
137133

138134
/* Get the physical address of the buffer in memory */
139135
gem = drm_fb_dma_get_gem_obj(fb, 0);
@@ -190,7 +186,7 @@ static int sun8i_ui_layer_atomic_check(struct drm_plane *plane,
190186
min_scale = DRM_PLANE_NO_SCALING;
191187
max_scale = DRM_PLANE_NO_SCALING;
192188

193-
if (layer->mixer->cfg->lay_cfg.scaler_mask & BIT(layer->channel)) {
189+
if (layer->cfg->scaler_mask & BIT(layer->channel)) {
194190
min_scale = SUN8I_UI_SCALER_SCALE_MIN;
195191
max_scale = SUN8I_UI_SCALER_SCALE_MAX;
196192
}
@@ -266,7 +262,8 @@ struct sun8i_layer *sun8i_ui_layer_init_one(struct drm_device *drm,
266262
enum drm_plane_type type,
267263
struct regmap *regs,
268264
int index, int phy_index,
269-
int plane_cnt)
265+
int plane_cnt,
266+
const struct sun8i_layer_cfg *cfg)
270267
{
271268
struct sun8i_layer *layer;
272269
int ret;
@@ -281,6 +278,7 @@ struct sun8i_layer *sun8i_ui_layer_init_one(struct drm_device *drm,
281278
layer->channel = phy_index;
282279
layer->overlay = 0;
283280
layer->regs = regs;
281+
layer->cfg = cfg;
284282

285283
/* possible crtcs are set later */
286284
ret = drm_universal_plane_init(drm, &layer->plane, 0,

drivers/gpu/drm/sun4i/sun8i_ui_layer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ struct sun8i_layer *sun8i_ui_layer_init_one(struct drm_device *drm,
5454
enum drm_plane_type type,
5555
struct regmap *regs,
5656
int index, int phy_index,
57-
int plane_cnt);
57+
int plane_cnt,
58+
const struct sun8i_layer_cfg *cfg);
5859
#endif /* _SUN8I_UI_LAYER_H_ */

drivers/gpu/drm/sun4i/sun8i_ui_scaler.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ static const u32 lan2coefftab16[240] = {
8989
0x0b1c1603, 0x0d1c1502, 0x0e1d1401, 0x0f1d1301,
9090
};
9191

92-
static u32 sun8i_ui_scaler_base(struct sun8i_mixer *mixer, int channel)
92+
static u32 sun8i_ui_scaler_base(struct sun8i_layer *layer)
9393
{
94-
int offset = mixer->cfg->lay_cfg.vi_scaler_num;
94+
int offset = layer->cfg->vi_scaler_num;
9595

96-
if (mixer->cfg->de_type == SUN8I_MIXER_DE3)
96+
if (layer->cfg->de_type == SUN8I_MIXER_DE3)
9797
return DE3_VI_SCALER_UNIT_BASE +
9898
DE3_VI_SCALER_UNIT_SIZE * offset +
99-
DE3_UI_SCALER_UNIT_SIZE * (channel - offset);
99+
DE3_UI_SCALER_UNIT_SIZE * (layer->channel - offset);
100100
else
101101
return DE2_VI_SCALER_UNIT_BASE +
102102
DE2_VI_SCALER_UNIT_SIZE * offset +
103-
DE2_UI_SCALER_UNIT_SIZE * (channel - offset);
103+
DE2_UI_SCALER_UNIT_SIZE * (layer->channel - offset);
104104
}
105105

106106
static int sun8i_ui_scaler_coef_index(unsigned int step)
@@ -129,10 +129,9 @@ static int sun8i_ui_scaler_coef_index(unsigned int step)
129129

130130
void sun8i_ui_scaler_enable(struct sun8i_layer *layer, bool enable)
131131
{
132-
struct sun8i_mixer *mixer = layer->mixer;
133132
u32 val, base;
134133

135-
base = sun8i_ui_scaler_base(mixer, layer->channel);
134+
base = sun8i_ui_scaler_base(layer);
136135

137136
if (enable)
138137
val = SUN8I_SCALER_GSU_CTRL_EN |
@@ -147,12 +146,11 @@ void sun8i_ui_scaler_setup(struct sun8i_layer *layer,
147146
u32 src_w, u32 src_h, u32 dst_w, u32 dst_h,
148147
u32 hscale, u32 vscale, u32 hphase, u32 vphase)
149148
{
150-
struct sun8i_mixer *mixer = layer->mixer;
151149
u32 insize, outsize;
152150
int i, offset;
153151
u32 base;
154152

155-
base = sun8i_ui_scaler_base(mixer, layer->channel);
153+
base = sun8i_ui_scaler_base(layer);
156154

157155
hphase <<= SUN8I_UI_SCALER_PHASE_FRAC - 16;
158156
vphase <<= SUN8I_UI_SCALER_PHASE_FRAC - 16;

drivers/gpu/drm/sun4i/sun8i_vi_layer.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,28 @@
2121

2222
static void sun8i_vi_layer_disable(struct sun8i_layer *layer)
2323
{
24-
struct sun8i_mixer *mixer = layer->mixer;
25-
u32 ch_base = sun8i_channel_base(mixer, layer->channel);
24+
u32 ch_base = sun8i_channel_base(layer);
2625

27-
regmap_write(mixer->engine.regs,
26+
regmap_write(layer->regs,
2827
SUN8I_MIXER_CHAN_VI_LAYER_ATTR(ch_base, layer->overlay), 0);
2928
}
3029

3130
static void sun8i_vi_layer_update_attributes(struct sun8i_layer *layer,
3231
struct drm_plane *plane)
3332
{
3433
struct drm_plane_state *state = plane->state;
35-
struct sun8i_mixer *mixer = layer->mixer;
3634
const struct drm_format_info *fmt;
3735
u32 val, ch_base, hw_fmt;
3836

39-
ch_base = sun8i_channel_base(mixer, layer->channel);
37+
ch_base = sun8i_channel_base(layer);
4038
fmt = state->fb->format;
4139
sun8i_mixer_drm_format_to_hw(fmt->format, &hw_fmt);
4240

4341
val = hw_fmt << SUN8I_MIXER_CHAN_VI_LAYER_ATTR_FBFMT_OFFSET;
4442
if (!fmt->is_yuv)
4543
val |= SUN8I_MIXER_CHAN_VI_LAYER_ATTR_RGB_MODE;
4644
val |= SUN8I_MIXER_CHAN_VI_LAYER_ATTR_EN;
47-
if (mixer->cfg->de_type >= SUN8I_MIXER_DE3) {
45+
if (layer->cfg->de_type >= SUN8I_MIXER_DE3) {
4846
val |= SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA(state->alpha >> 8);
4947
val |= (state->alpha == DRM_BLEND_ALPHA_OPAQUE) ?
5048
SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MODE_PIXEL :
@@ -54,7 +52,7 @@ static void sun8i_vi_layer_update_attributes(struct sun8i_layer *layer,
5452
regmap_write(layer->regs,
5553
SUN8I_MIXER_CHAN_VI_LAYER_ATTR(ch_base, layer->overlay), val);
5654

57-
if (mixer->cfg->lay_cfg.de2_fcc_alpha) {
55+
if (layer->cfg->de2_fcc_alpha) {
5856
regmap_write(layer->regs,
5957
SUN8I_MIXER_FCC_GLOBAL_ALPHA_REG,
6058
SUN8I_MIXER_FCC_GLOBAL_ALPHA(state->alpha >> 8));
@@ -78,7 +76,7 @@ static void sun8i_vi_layer_update_coord(struct sun8i_layer *layer,
7876
DRM_DEBUG_DRIVER("Updating VI channel %d overlay %d\n",
7977
layer->channel, layer->overlay);
8078

81-
ch_base = sun8i_channel_base(mixer, layer->channel);
79+
ch_base = sun8i_channel_base(layer);
8280

8381
src_w = drm_rect_width(&state->src) >> 16;
8482
src_h = drm_rect_height(&state->src) >> 16;
@@ -153,7 +151,7 @@ static void sun8i_vi_layer_update_coord(struct sun8i_layer *layer,
153151
}
154152

155153
/* it seems that every RGB scaler has buffer for 2048 pixels */
156-
scanline = subsampled ? mixer->cfg->lay_cfg.scanline_yuv : 2048;
154+
scanline = subsampled ? layer->cfg->scanline_yuv : 2048;
157155

158156
if (src_w > scanline) {
159157
DRM_DEBUG_DRIVER("Using horizontal coarse scaling\n");
@@ -195,7 +193,6 @@ static void sun8i_vi_layer_update_buffer(struct sun8i_layer *layer,
195193
struct drm_plane *plane)
196194
{
197195
struct drm_plane_state *state = plane->state;
198-
struct sun8i_mixer *mixer = layer->mixer;
199196
struct drm_framebuffer *fb = state->fb;
200197
const struct drm_format_info *format = fb->format;
201198
struct drm_gem_dma_object *gem;
@@ -204,7 +201,7 @@ static void sun8i_vi_layer_update_buffer(struct sun8i_layer *layer,
204201
u32 ch_base;
205202
int i;
206203

207-
ch_base = sun8i_channel_base(mixer, layer->channel);
204+
ch_base = sun8i_channel_base(layer);
208205

209206
/* Adjust x and y to be dividable by subsampling factor */
210207
src_x = (state->src.x1 >> 16) & ~(format->hsub - 1);
@@ -278,7 +275,7 @@ static int sun8i_vi_layer_atomic_check(struct drm_plane *plane,
278275
min_scale = DRM_PLANE_NO_SCALING;
279276
max_scale = DRM_PLANE_NO_SCALING;
280277

281-
if (layer->mixer->cfg->lay_cfg.scaler_mask & BIT(layer->channel)) {
278+
if (layer->cfg->scaler_mask & BIT(layer->channel)) {
282279
min_scale = SUN8I_VI_SCALER_SCALE_MIN;
283280
max_scale = SUN8I_VI_SCALER_SCALE_MAX;
284281
}
@@ -414,7 +411,8 @@ struct sun8i_layer *sun8i_vi_layer_init_one(struct drm_device *drm,
414411
enum drm_plane_type type,
415412
struct regmap *regs,
416413
int index, int phy_index,
417-
int plane_cnt)
414+
int plane_cnt,
415+
const struct sun8i_layer_cfg *cfg)
418416
{
419417
u32 supported_encodings, supported_ranges;
420418
unsigned int format_count;
@@ -432,8 +430,9 @@ struct sun8i_layer *sun8i_vi_layer_init_one(struct drm_device *drm,
432430
layer->channel = phy_index;
433431
layer->overlay = 0;
434432
layer->regs = regs;
433+
layer->cfg = cfg;
435434

436-
if (mixer->cfg->de_type >= SUN8I_MIXER_DE3) {
435+
if (layer->cfg->de_type >= SUN8I_MIXER_DE3) {
437436
formats = sun8i_vi_layer_de3_formats;
438437
format_count = ARRAY_SIZE(sun8i_vi_layer_de3_formats);
439438
} else {
@@ -452,7 +451,7 @@ struct sun8i_layer *sun8i_vi_layer_init_one(struct drm_device *drm,
452451
return ERR_PTR(ret);
453452
}
454453

455-
if (mixer->cfg->lay_cfg.de2_fcc_alpha || mixer->cfg->de_type >= SUN8I_MIXER_DE3) {
454+
if (layer->cfg->de2_fcc_alpha || layer->cfg->de_type >= SUN8I_MIXER_DE3) {
456455
ret = drm_plane_create_alpha_property(&layer->plane);
457456
if (ret) {
458457
dev_err(drm->dev, "Couldn't add alpha property\n");
@@ -469,7 +468,7 @@ struct sun8i_layer *sun8i_vi_layer_init_one(struct drm_device *drm,
469468

470469
supported_encodings = BIT(DRM_COLOR_YCBCR_BT601) |
471470
BIT(DRM_COLOR_YCBCR_BT709);
472-
if (mixer->cfg->de_type >= SUN8I_MIXER_DE3)
471+
if (layer->cfg->de_type >= SUN8I_MIXER_DE3)
473472
supported_encodings |= BIT(DRM_COLOR_YCBCR_BT2020);
474473

475474
supported_ranges = BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |

drivers/gpu/drm/sun4i/sun8i_vi_layer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ struct sun8i_layer *sun8i_vi_layer_init_one(struct drm_device *drm,
5959
enum drm_plane_type type,
6060
struct regmap *regs,
6161
int index, int phy_index,
62-
int plane_cnt);
62+
int plane_cnt,
63+
const struct sun8i_layer_cfg *cfg);
6364
#endif /* _SUN8I_VI_LAYER_H_ */

0 commit comments

Comments
 (0)