Skip to content

Commit 9afe52d

Browse files
paulkocialkowskimripard
authored andcommitted
drm/sun4i: frontend: Add support for semi-planar YUV input formats
Semi-planar YUV formats use two distinct planes, one for luminance and one for chrominance. To add support for them, we need to configure the second line stride and buffer address registers to setup the second YUV plane. New definitions are introduced to configure the input format register for the YUV420 and YUV422 semi-planar formats. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Link: https://patchwork.freedesktop.org/patch/msgid/20190118145133.21281-10-paul.kocialkowski@bootlin.com
1 parent 34d896e commit 9afe52d

3 files changed

Lines changed: 55 additions & 5 deletions

File tree

‎drivers/gpu/drm/sun4i/sun4i_frontend.c‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,23 @@ void sun4i_frontend_update_buffer(struct sun4i_frontend *frontend,
119119
regmap_write(frontend->regs, SUN4I_FRONTEND_LINESTRD0_REG,
120120
fb->pitches[0]);
121121

122+
if (fb->format->num_planes > 1)
123+
regmap_write(frontend->regs, SUN4I_FRONTEND_LINESTRD1_REG,
124+
fb->pitches[1]);
125+
122126
/* Set the physical address of the buffer in memory */
123127
paddr = drm_fb_cma_get_gem_addr(fb, state, 0);
124128
paddr -= PHYS_OFFSET;
125-
DRM_DEBUG_DRIVER("Setting buffer address to %pad\n", &paddr);
129+
DRM_DEBUG_DRIVER("Setting buffer #0 address to %pad\n", &paddr);
126130
regmap_write(frontend->regs, SUN4I_FRONTEND_BUF_ADDR0_REG, paddr);
131+
132+
if (fb->format->num_planes > 1) {
133+
paddr = drm_fb_cma_get_gem_addr(fb, state, 1);
134+
paddr -= PHYS_OFFSET;
135+
DRM_DEBUG_DRIVER("Setting buffer #1 address to %pad\n", &paddr);
136+
regmap_write(frontend->regs, SUN4I_FRONTEND_BUF_ADDR1_REG,
137+
paddr);
138+
}
127139
}
128140
EXPORT_SYMBOL(sun4i_frontend_update_buffer);
129141

@@ -133,6 +145,8 @@ sun4i_frontend_drm_format_to_input_fmt(const struct drm_format_info *format,
133145
{
134146
if (!format->is_yuv)
135147
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_RGB;
148+
else if (drm_format_info_is_yuv_sampling_420(format))
149+
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV420;
136150
else if (drm_format_info_is_yuv_sampling_422(format))
137151
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV422;
138152
else
@@ -145,12 +159,18 @@ static int
145159
sun4i_frontend_drm_format_to_input_mode(const struct drm_format_info *format,
146160
u32 *val)
147161
{
148-
if (format->num_planes == 1)
162+
switch (format->num_planes) {
163+
case 1:
149164
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_PACKED;
150-
else
151-
return -EINVAL;
165+
return 0;
152166

153-
return 0;
167+
case 2:
168+
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_SEMIPLANAR;
169+
return 0;
170+
171+
default:
172+
return -EINVAL;
173+
}
154174
}
155175

156176
static int
@@ -162,6 +182,22 @@ sun4i_frontend_drm_format_to_input_sequence(const struct drm_format_info *format
162182
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_PS_BGRX;
163183
return 0;
164184

185+
case DRM_FORMAT_NV12:
186+
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UV;
187+
return 0;
188+
189+
case DRM_FORMAT_NV16:
190+
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UV;
191+
return 0;
192+
193+
case DRM_FORMAT_NV21:
194+
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VU;
195+
return 0;
196+
197+
case DRM_FORMAT_NV61:
198+
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VU;
199+
return 0;
200+
165201
case DRM_FORMAT_UYVY:
166202
*val = SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UYVY;
167203
return 0;
@@ -205,6 +241,10 @@ static int sun4i_frontend_drm_format_to_output_fmt(uint32_t fmt, u32 *val)
205241

206242
static const uint32_t sun4i_frontend_formats[] = {
207243
DRM_FORMAT_BGRX8888,
244+
DRM_FORMAT_NV12,
245+
DRM_FORMAT_NV16,
246+
DRM_FORMAT_NV21,
247+
DRM_FORMAT_NV61,
208248
DRM_FORMAT_UYVY,
209249
DRM_FORMAT_VYUY,
210250
DRM_FORMAT_XRGB8888,

‎drivers/gpu/drm/sun4i/sun4i_frontend.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,23 @@
2222
#define SUN4I_FRONTEND_BYPASS_CSC_EN BIT(1)
2323

2424
#define SUN4I_FRONTEND_BUF_ADDR0_REG 0x020
25+
#define SUN4I_FRONTEND_BUF_ADDR1_REG 0x024
2526

2627
#define SUN4I_FRONTEND_LINESTRD0_REG 0x040
28+
#define SUN4I_FRONTEND_LINESTRD1_REG 0x044
2729

2830
#define SUN4I_FRONTEND_INPUT_FMT_REG 0x04c
2931
#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_PACKED (1 << 8)
32+
#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_SEMIPLANAR (2 << 8)
3033
#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV422 (1 << 4)
34+
#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV420 (2 << 4)
3135
#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_RGB (5 << 4)
3236
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UYVY 0
3337
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_YUYV 1
3438
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VYUY 2
3539
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_YVYU 3
40+
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UV 0
41+
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VU 1
3642
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_BGRX 0
3743
#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_XRGB 1
3844

‎drivers/gpu/drm/sun4i/sun4i_layer.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ static const uint32_t sun4i_layer_formats[] = {
138138
DRM_FORMAT_RGBA4444,
139139
DRM_FORMAT_RGB888,
140140
DRM_FORMAT_RGB565,
141+
DRM_FORMAT_NV12,
142+
DRM_FORMAT_NV16,
143+
DRM_FORMAT_NV21,
144+
DRM_FORMAT_NV61,
141145
DRM_FORMAT_UYVY,
142146
DRM_FORMAT_VYUY,
143147
DRM_FORMAT_XRGB8888,

0 commit comments

Comments
 (0)