Skip to content

Commit a7febbd

Browse files
jernejskwens
authored andcommitted
drm/sun4i: csc: Simplify arguments with taking plane state
Taking plane state directly reduces number of arguments, avoids copying values and allows making additional decisions. For example, when plane is disabled, CSC should be turned off. This is also cleanup for later patches which will move call to another place. 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-13-jernej.skrabec@gmail.com Signed-off-by: Chen-Yu Tsai <wens@kernel.org>
1 parent 870e3cf commit a7febbd

3 files changed

Lines changed: 40 additions & 46 deletions

File tree

drivers/gpu/drm/sun4i/sun8i_csc.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
* Copyright (C) Jernej Skrabec <jernej.skrabec@siol.net>
44
*/
55

6+
#include <drm/drm_fourcc.h>
7+
#include <drm/drm_framebuffer.h>
8+
#include <drm/drm_plane.h>
69
#include <drm/drm_print.h>
710

811
#include "sun8i_csc.h"
912
#include "sun8i_mixer.h"
1013

14+
enum sun8i_csc_mode {
15+
SUN8I_CSC_MODE_OFF,
16+
SUN8I_CSC_MODE_YUV2RGB,
17+
SUN8I_CSC_MODE_YVU2RGB,
18+
};
19+
1120
static const u32 ccsc_base[][2] = {
1221
[CCSC_MIXER0_LAYOUT] = {CCSC00_OFFSET, CCSC01_OFFSET},
1322
[CCSC_MIXER1_LAYOUT] = {CCSC10_OFFSET, CCSC11_OFFSET},
@@ -196,21 +205,44 @@ static void sun8i_de3_ccsc_setup(struct regmap *map, int layer,
196205
mask, val);
197206
}
198207

208+
static u32 sun8i_csc_get_mode(struct drm_plane_state *state)
209+
{
210+
const struct drm_format_info *format;
211+
212+
if (!state->crtc || !state->visible)
213+
return SUN8I_CSC_MODE_OFF;
214+
215+
format = state->fb->format;
216+
if (!format->is_yuv)
217+
return SUN8I_CSC_MODE_OFF;
218+
219+
switch (format->format) {
220+
case DRM_FORMAT_YVU411:
221+
case DRM_FORMAT_YVU420:
222+
case DRM_FORMAT_YVU422:
223+
case DRM_FORMAT_YVU444:
224+
return SUN8I_CSC_MODE_YVU2RGB;
225+
default:
226+
return SUN8I_CSC_MODE_YUV2RGB;
227+
}
228+
}
229+
199230
void sun8i_csc_config(struct sun8i_mixer *mixer, int layer,
200-
enum sun8i_csc_mode mode,
201-
enum drm_color_encoding encoding,
202-
enum drm_color_range range)
231+
struct drm_plane_state *state)
203232
{
233+
u32 mode = sun8i_csc_get_mode(state);
204234
u32 base;
205235

206236
if (mixer->cfg->de_type == SUN8I_MIXER_DE3) {
207237
sun8i_de3_ccsc_setup(mixer->engine.regs, layer,
208-
mode, encoding, range);
238+
mode, state->color_encoding,
239+
state->color_range);
209240
return;
210241
}
211242

212243
base = ccsc_base[mixer->cfg->ccsc][layer];
213244

214245
sun8i_csc_setup(mixer->engine.regs, base,
215-
mode, encoding, range);
246+
mode, state->color_encoding,
247+
state->color_range);
216248
}

drivers/gpu/drm/sun4i/sun8i_csc.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <drm/drm_color_mgmt.h>
1010

11+
struct drm_plane_state;
1112
struct sun8i_mixer;
1213

1314
/* VI channel CSC units offsets */
@@ -22,15 +23,7 @@ struct sun8i_mixer;
2223

2324
#define SUN8I_CSC_CTRL_EN BIT(0)
2425

25-
enum sun8i_csc_mode {
26-
SUN8I_CSC_MODE_OFF,
27-
SUN8I_CSC_MODE_YUV2RGB,
28-
SUN8I_CSC_MODE_YVU2RGB,
29-
};
30-
3126
void sun8i_csc_config(struct sun8i_mixer *mixer, int layer,
32-
enum sun8i_csc_mode mode,
33-
enum drm_color_encoding encoding,
34-
enum drm_color_range range);
27+
struct drm_plane_state *state);
3528

3629
#endif

drivers/gpu/drm/sun4i/sun8i_vi_layer.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -189,36 +189,6 @@ static void sun8i_vi_layer_update_coord(struct sun8i_mixer *mixer, int channel,
189189
SUN8I_MIXER_CHAN_VI_DS_M(vm));
190190
}
191191

192-
static u32 sun8i_vi_layer_get_csc_mode(const struct drm_format_info *format)
193-
{
194-
if (!format->is_yuv)
195-
return SUN8I_CSC_MODE_OFF;
196-
197-
switch (format->format) {
198-
case DRM_FORMAT_YVU411:
199-
case DRM_FORMAT_YVU420:
200-
case DRM_FORMAT_YVU422:
201-
case DRM_FORMAT_YVU444:
202-
return SUN8I_CSC_MODE_YVU2RGB;
203-
default:
204-
return SUN8I_CSC_MODE_YUV2RGB;
205-
}
206-
}
207-
208-
static void sun8i_vi_layer_update_colors(struct sun8i_mixer *mixer, int channel,
209-
int overlay, struct drm_plane *plane)
210-
{
211-
struct drm_plane_state *state = plane->state;
212-
const struct drm_format_info *fmt;
213-
u32 csc_mode;
214-
215-
fmt = state->fb->format;
216-
csc_mode = sun8i_vi_layer_get_csc_mode(fmt);
217-
sun8i_csc_config(mixer, channel, csc_mode,
218-
state->color_encoding,
219-
state->color_range);
220-
}
221-
222192
static void sun8i_vi_layer_update_buffer(struct sun8i_mixer *mixer, int channel,
223193
int overlay, struct drm_plane *plane)
224194
{
@@ -333,8 +303,7 @@ static void sun8i_vi_layer_atomic_update(struct drm_plane *plane,
333303
layer->overlay, plane);
334304
sun8i_vi_layer_update_coord(mixer, layer->channel,
335305
layer->overlay, plane);
336-
sun8i_vi_layer_update_colors(mixer, layer->channel,
337-
layer->overlay, plane);
306+
sun8i_csc_config(mixer, layer->channel, new_state);
338307
sun8i_vi_layer_update_buffer(mixer, layer->channel,
339308
layer->overlay, plane);
340309
}

0 commit comments

Comments
 (0)