Commit 3ff3a712 authored by Benoit Parrot's avatar Benoit Parrot Committed by Mauro Carvalho Chehab

media: ti-vpe: vpe: don't rely on colorspace member for conversion

Up to now VPE was relying on the colorspace value of struct v4l2_format
as an indication to perform color space conversion from YUV to RGB or
not.

Instead we should used the source/destination fourcc codes as a more
reliable indication to perform color space conversion or not.

To do so, we rework the csc module to use "struct v4l2_format *" as
parameters, and reorganize the coefficients tables in a more logical
way.
Signed-off-by: default avatarBenoit Parrot <bparrot@ti.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent b373f84d
...@@ -15,76 +15,96 @@ ...@@ -15,76 +15,96 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/v4l2-common.h>
#include "csc.h" #include "csc.h"
/* /*
* 16 coefficients in the order: * 12 coefficients in the order:
* a0, b0, c0, a1, b1, c1, a2, b2, c2, d0, d1, d2 * a0, b0, c0, a1, b1, c1, a2, b2, c2, d0, d1, d2
* (we may need to pass non-default values from user space later on, we might
* need to make the coefficient struct more easy to populate)
*/ */
struct colorspace_coeffs { struct quantization {
u16 sd[12]; u16 coeff[12];
u16 hd[12];
}; };
/* VIDEO_RANGE: limited range, GRAPHICS_RANGE: full range */ struct colorspace {
#define CSC_COEFFS_VIDEO_RANGE_Y2R 0 struct quantization limited;
#define CSC_COEFFS_GRAPHICS_RANGE_Y2R 1 struct quantization full;
#define CSC_COEFFS_VIDEO_RANGE_R2Y 2 };
#define CSC_COEFFS_GRAPHICS_RANGE_R2Y 3
struct encoding_direction {
struct colorspace r601;
struct colorspace r709;
};
struct csc_coeffs {
struct encoding_direction y2r;
struct encoding_direction r2y;
};
/* default colorspace coefficients */ /* default colorspace coefficients */
static struct colorspace_coeffs colorspace_coeffs[4] = { static struct csc_coeffs csc_coeffs = {
[CSC_COEFFS_VIDEO_RANGE_Y2R] = { .y2r = {
{ .r601 = {
/* SDTV */ .limited = {
0x0400, 0x0000, 0x057D, 0x0400, 0x1EA7, 0x1D35, { /* SDTV */
0x0400, 0x06EF, 0x1FFE, 0x0D40, 0x0210, 0x0C88, 0x0400, 0x0000, 0x057D, 0x0400, 0x1EA7, 0x1D35,
0x0400, 0x06EF, 0x1FFE, 0x0D40, 0x0210, 0x0C88,
}
},
.full = {
{ /* SDTV */
0x04A8, 0x1FFE, 0x0662, 0x04A8, 0x1E6F, 0x1CBF,
0x04A8, 0x0812, 0x1FFF, 0x0C84, 0x0220, 0x0BAC,
}
},
}, },
{ .r709 = {
/* HDTV */ .limited = {
0x0400, 0x0000, 0x0629, 0x0400, 0x1F45, 0x1E2B, { /* HDTV */
0x0400, 0x0742, 0x0000, 0x0CEC, 0x0148, 0x0C60, 0x0400, 0x0000, 0x0629, 0x0400, 0x1F45, 0x1E2B,
0x0400, 0x0742, 0x0000, 0x0CEC, 0x0148, 0x0C60,
}
},
.full = {
{ /* HDTV */
0x04A8, 0x0000, 0x072C, 0x04A8, 0x1F26, 0x1DDE,
0x04A8, 0x0873, 0x0000, 0x0C20, 0x0134, 0x0B7C,
}
},
}, },
}, },
[CSC_COEFFS_GRAPHICS_RANGE_Y2R] = { .r2y = {
{ .r601 = {
/* SDTV */ .limited = {
0x04A8, 0x1FFE, 0x0662, 0x04A8, 0x1E6F, 0x1CBF, { /* SDTV */
0x04A8, 0x0812, 0x1FFF, 0x0C84, 0x0220, 0x0BAC, 0x0132, 0x0259, 0x0075, 0x1F50, 0x1EA5, 0x020B,
0x020B, 0x1E4A, 0x1FAB, 0x0000, 0x0200, 0x0200,
}
},
.full = {
{ /* SDTV */
0x0107, 0x0204, 0x0064, 0x1F68, 0x1ED6, 0x01C2,
0x01C2, 0x1E87, 0x1FB7, 0x0040, 0x0200, 0x0200,
}
},
}, },
{ .r709 = {
/* HDTV */ .limited = {
0x04A8, 0x0000, 0x072C, 0x04A8, 0x1F26, 0x1DDE, { /* HDTV */
0x04A8, 0x0873, 0x0000, 0x0C20, 0x0134, 0x0B7C, 0x00DA, 0x02DC, 0x004A, 0x1F88, 0x1E6C, 0x020C,
}, 0x020C, 0x1E24, 0x1FD0, 0x0000, 0x0200, 0x0200,
}, }
[CSC_COEFFS_VIDEO_RANGE_R2Y] = { },
{ .full = {
/* SDTV */ { /* HDTV */
0x0132, 0x0259, 0x0075, 0x1F50, 0x1EA5, 0x020B, 0x00bb, 0x0275, 0x003f, 0x1f99, 0x1ea5, 0x01c2,
0x020B, 0x1E4A, 0x1FAB, 0x0000, 0x0200, 0x0200, 0x01c2, 0x1e67, 0x1fd7, 0x0040, 0x0200, 0x0200,
}, }
{ },
/* HDTV */
0x00DA, 0x02DC, 0x004A, 0x1F88, 0x1E6C, 0x020C,
0x020C, 0x1E24, 0x1FD0, 0x0000, 0x0200, 0x0200,
},
},
[CSC_COEFFS_GRAPHICS_RANGE_R2Y] = {
{
/* SDTV */
0x0107, 0x0204, 0x0064, 0x1F68, 0x1ED6, 0x01C2,
0x01C2, 0x1E87, 0x1FB7, 0x0040, 0x0200, 0x0200,
},
{
/* HDTV */
0x00bb, 0x0275, 0x003f, 0x1f99, 0x1ea5, 0x01c2,
0x01c2, 0x1e67, 0x1fd7, 0x0040, 0x0200, 0x0200,
}, },
}, },
}; };
void csc_dump_regs(struct csc_data *csc) void csc_dump_regs(struct csc_data *csc)
...@@ -117,46 +137,114 @@ EXPORT_SYMBOL(csc_set_coeff_bypass); ...@@ -117,46 +137,114 @@ EXPORT_SYMBOL(csc_set_coeff_bypass);
* set the color space converter coefficient shadow register values * set the color space converter coefficient shadow register values
*/ */
void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0, void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0,
enum v4l2_colorspace src_colorspace, struct v4l2_format *src_fmt, struct v4l2_format *dst_fmt)
enum v4l2_colorspace dst_colorspace)
{ {
u32 *csc_reg5 = csc_reg0 + 5; u32 *csc_reg5 = csc_reg0 + 5;
u32 *shadow_csc = csc_reg0; u32 *shadow_csc = csc_reg0;
struct colorspace_coeffs *sd_hd_coeffs;
u16 *coeff, *end_coeff; u16 *coeff, *end_coeff;
enum v4l2_colorspace yuv_colorspace; const struct v4l2_pix_format *pix;
int sel = 0; const struct v4l2_pix_format_mplane *mp;
const struct v4l2_format_info *src_finfo, *dst_finfo;
/* enum v4l2_ycbcr_encoding src_ycbcr_enc, dst_ycbcr_enc;
* support only graphics data range(full range) for now, a control ioctl enum v4l2_quantization src_quantization, dst_quantization;
* would be nice here u32 src_pixelformat, dst_pixelformat;
*/
/* Y2R */ switch (src_fmt->type) {
if (dst_colorspace == V4L2_COLORSPACE_SRGB && case V4L2_BUF_TYPE_VIDEO_OUTPUT:
(src_colorspace == V4L2_COLORSPACE_SMPTE170M || pix = &src_fmt->fmt.pix;
src_colorspace == V4L2_COLORSPACE_REC709)) { src_pixelformat = pix->pixelformat;
src_ycbcr_enc = pix->ycbcr_enc;
src_quantization = pix->quantization;
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
default:
mp = &src_fmt->fmt.pix_mp;
src_pixelformat = mp->pixelformat;
src_ycbcr_enc = mp->ycbcr_enc;
src_quantization = mp->quantization;
break;
}
switch (dst_fmt->type) {
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
pix = &dst_fmt->fmt.pix;
dst_pixelformat = pix->pixelformat;
dst_ycbcr_enc = pix->ycbcr_enc;
dst_quantization = pix->quantization;
break;
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
default:
mp = &dst_fmt->fmt.pix_mp;
dst_pixelformat = mp->pixelformat;
dst_ycbcr_enc = mp->ycbcr_enc;
dst_quantization = mp->quantization;
break;
}
src_finfo = v4l2_format_info(src_pixelformat);
dst_finfo = v4l2_format_info(dst_pixelformat);
if (v4l2_is_format_yuv(src_finfo) &&
v4l2_is_format_rgb(dst_finfo)) {
/* Y2R */ /* Y2R */
sel = 1;
yuv_colorspace = src_colorspace; /*
} else if ((dst_colorspace == V4L2_COLORSPACE_SMPTE170M || * These are not the standard default values but are
dst_colorspace == V4L2_COLORSPACE_REC709) && * set this way for historical compatibility
src_colorspace == V4L2_COLORSPACE_SRGB) { */
if (src_ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
src_ycbcr_enc = V4L2_YCBCR_ENC_601;
if (src_quantization == V4L2_QUANTIZATION_DEFAULT)
src_quantization = V4L2_QUANTIZATION_FULL_RANGE;
if (src_ycbcr_enc == V4L2_YCBCR_ENC_601) {
if (src_quantization == V4L2_QUANTIZATION_FULL_RANGE)
coeff = csc_coeffs.y2r.r601.full.coeff;
else
coeff = csc_coeffs.y2r.r601.limited.coeff;
} else if (src_ycbcr_enc == V4L2_YCBCR_ENC_709) {
if (src_quantization == V4L2_QUANTIZATION_FULL_RANGE)
coeff = csc_coeffs.y2r.r709.full.coeff;
else
coeff = csc_coeffs.y2r.r709.limited.coeff;
} else {
/* Should never reach this, but it keeps gcc happy */
coeff = csc_coeffs.y2r.r601.full.coeff;
}
} else if (v4l2_is_format_rgb(src_finfo) &&
v4l2_is_format_yuv(dst_finfo)) {
/* R2Y */ /* R2Y */
sel = 3;
yuv_colorspace = dst_colorspace; /*
* These are not the standard default values but are
* set this way for historical compatibility
*/
if (dst_ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
dst_ycbcr_enc = V4L2_YCBCR_ENC_601;
if (dst_quantization == V4L2_QUANTIZATION_DEFAULT)
dst_quantization = V4L2_QUANTIZATION_FULL_RANGE;
if (dst_ycbcr_enc == V4L2_YCBCR_ENC_601) {
if (dst_quantization == V4L2_QUANTIZATION_FULL_RANGE)
coeff = csc_coeffs.r2y.r601.full.coeff;
else
coeff = csc_coeffs.r2y.r601.limited.coeff;
} else if (dst_ycbcr_enc == V4L2_YCBCR_ENC_709) {
if (dst_quantization == V4L2_QUANTIZATION_FULL_RANGE)
coeff = csc_coeffs.r2y.r709.full.coeff;
else
coeff = csc_coeffs.r2y.r709.limited.coeff;
} else {
/* Should never reach this, but it keeps gcc happy */
coeff = csc_coeffs.y2r.r601.full.coeff;
}
} else { } else {
*csc_reg5 |= CSC_BYPASS; *csc_reg5 |= CSC_BYPASS;
return; return;
} }
sd_hd_coeffs = &colorspace_coeffs[sel];
/* select between SD or HD coefficients */
if (yuv_colorspace == V4L2_COLORSPACE_SMPTE170M)
coeff = sd_hd_coeffs->sd;
else
coeff = sd_hd_coeffs->hd;
end_coeff = coeff + 12; end_coeff = coeff + 12;
for (; coeff < end_coeff; coeff += 2) for (; coeff < end_coeff; coeff += 2)
......
...@@ -58,8 +58,8 @@ struct csc_data { ...@@ -58,8 +58,8 @@ struct csc_data {
void csc_dump_regs(struct csc_data *csc); void csc_dump_regs(struct csc_data *csc);
void csc_set_coeff_bypass(struct csc_data *csc, u32 *csc_reg5); void csc_set_coeff_bypass(struct csc_data *csc, u32 *csc_reg5);
void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0, void csc_set_coeff(struct csc_data *csc, u32 *csc_reg0,
enum v4l2_colorspace src_colorspace, struct v4l2_format *src_fmt, struct v4l2_format *dst_fmt);
enum v4l2_colorspace dst_colorspace);
struct csc_data *csc_create(struct platform_device *pdev, const char *res_name); struct csc_data *csc_create(struct platform_device *pdev, const char *res_name);
#endif #endif
...@@ -756,12 +756,12 @@ static void set_src_registers(struct vpe_ctx *ctx) ...@@ -756,12 +756,12 @@ static void set_src_registers(struct vpe_ctx *ctx)
static void set_dst_registers(struct vpe_ctx *ctx) static void set_dst_registers(struct vpe_ctx *ctx)
{ {
struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr; struct vpe_mmr_adb *mmr_adb = ctx->mmr_adb.addr;
struct v4l2_pix_format_mplane *pix;
struct vpe_fmt *fmt = ctx->q_data[Q_DATA_DST].fmt; struct vpe_fmt *fmt = ctx->q_data[Q_DATA_DST].fmt;
const struct v4l2_format_info *finfo;
u32 val = 0; u32 val = 0;
pix = &ctx->q_data[Q_DATA_DST].format.fmt.pix_mp; finfo = v4l2_format_info(fmt->fourcc);
if (pix->colorspace == V4L2_COLORSPACE_SRGB) { if (v4l2_is_format_rgb(finfo)) {
val |= VPE_RGB_OUT_SELECT; val |= VPE_RGB_OUT_SELECT;
vpdma_set_bg_color(ctx->dev->vpdma, vpdma_set_bg_color(ctx->dev->vpdma,
(struct vpdma_data_format *)fmt->vpdma_fmt[0], 0xff); (struct vpdma_data_format *)fmt->vpdma_fmt[0], 0xff);
...@@ -865,14 +865,12 @@ static int set_srcdst_params(struct vpe_ctx *ctx) ...@@ -865,14 +865,12 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
unsigned int dst_w = d_q_data->c_rect.width; unsigned int dst_w = d_q_data->c_rect.width;
unsigned int dst_h = d_q_data->c_rect.height; unsigned int dst_h = d_q_data->c_rect.height;
struct v4l2_pix_format_mplane *spix; struct v4l2_pix_format_mplane *spix;
struct v4l2_pix_format_mplane *dpix;
size_t mv_buf_size; size_t mv_buf_size;
int ret; int ret;
ctx->sequence = 0; ctx->sequence = 0;
ctx->field = V4L2_FIELD_TOP; ctx->field = V4L2_FIELD_TOP;
spix = &s_q_data->format.fmt.pix_mp; spix = &s_q_data->format.fmt.pix_mp;
dpix = &d_q_data->format.fmt.pix_mp;
if ((s_q_data->flags & Q_IS_INTERLACED) && if ((s_q_data->flags & Q_IS_INTERLACED) &&
!(d_q_data->flags & Q_IS_INTERLACED)) { !(d_q_data->flags & Q_IS_INTERLACED)) {
...@@ -909,7 +907,7 @@ static int set_srcdst_params(struct vpe_ctx *ctx) ...@@ -909,7 +907,7 @@ static int set_srcdst_params(struct vpe_ctx *ctx)
set_dei_regs(ctx); set_dei_regs(ctx);
csc_set_coeff(ctx->dev->csc, &mmr_adb->csc_regs[0], csc_set_coeff(ctx->dev->csc, &mmr_adb->csc_regs[0],
spix->colorspace, dpix->colorspace); &s_q_data->format, &d_q_data->format);
sc_set_hs_coeffs(ctx->dev->sc, ctx->sc_coeff_h.addr, src_w, dst_w); sc_set_hs_coeffs(ctx->dev->sc, ctx->sc_coeff_h.addr, src_w, dst_w);
sc_set_vs_coeffs(ctx->dev->sc, ctx->sc_coeff_v.addr, src_h, dst_h); sc_set_vs_coeffs(ctx->dev->sc, ctx->sc_coeff_v.addr, src_h, dst_h);
...@@ -1215,9 +1213,9 @@ static void device_run(void *priv) ...@@ -1215,9 +1213,9 @@ static void device_run(void *priv)
struct sc_data *sc = ctx->dev->sc; struct sc_data *sc = ctx->dev->sc;
struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST]; struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST];
struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC]; struct vpe_q_data *s_q_data = &ctx->q_data[Q_DATA_SRC];
struct v4l2_pix_format_mplane *dpix; const struct v4l2_format_info *d_finfo;
dpix = &d_q_data->format.fmt.pix_mp; d_finfo = v4l2_format_info(d_q_data->fmt->fourcc);
if (ctx->deinterlacing && s_q_data->flags & Q_IS_SEQ_XX && if (ctx->deinterlacing && s_q_data->flags & Q_IS_SEQ_XX &&
ctx->sequence % 2 == 0) { ctx->sequence % 2 == 0) {
...@@ -1290,7 +1288,7 @@ static void device_run(void *priv) ...@@ -1290,7 +1288,7 @@ static void device_run(void *priv)
if (ctx->deinterlacing) if (ctx->deinterlacing)
add_out_dtd(ctx, VPE_PORT_MV_OUT); add_out_dtd(ctx, VPE_PORT_MV_OUT);
if (dpix->colorspace == V4L2_COLORSPACE_SRGB) { if (v4l2_is_format_rgb(d_finfo)) {
add_out_dtd(ctx, VPE_PORT_RGB_OUT); add_out_dtd(ctx, VPE_PORT_RGB_OUT);
} else { } else {
add_out_dtd(ctx, VPE_PORT_LUMA_OUT); add_out_dtd(ctx, VPE_PORT_LUMA_OUT);
...@@ -1332,7 +1330,7 @@ static void device_run(void *priv) ...@@ -1332,7 +1330,7 @@ static void device_run(void *priv)
} }
/* sync on channel control descriptors for output ports */ /* sync on channel control descriptors for output ports */
if (dpix->colorspace == V4L2_COLORSPACE_SRGB) { if (v4l2_is_format_rgb(d_finfo)) {
vpdma_add_sync_on_channel_ctd(&ctx->desc_list, vpdma_add_sync_on_channel_ctd(&ctx->desc_list,
VPE_CHAN_RGB_OUT); VPE_CHAN_RGB_OUT);
} else { } else {
...@@ -1603,6 +1601,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f, ...@@ -1603,6 +1601,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
unsigned int w_align; unsigned int w_align;
int i, depth, depth_bytes, height; int i, depth, depth_bytes, height;
unsigned int stride = 0; unsigned int stride = 0;
const struct v4l2_format_info *finfo;
if (!fmt || !(fmt->types & type)) { if (!fmt || !(fmt->types & type)) {
vpe_dbg(ctx->dev, "Fourcc format (0x%08x) invalid.\n", vpe_dbg(ctx->dev, "Fourcc format (0x%08x) invalid.\n",
...@@ -1662,6 +1661,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f, ...@@ -1662,6 +1661,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
pix->num_planes = 1; pix->num_planes = 1;
pix->pixelformat = fmt->fourcc; pix->pixelformat = fmt->fourcc;
finfo = v4l2_format_info(fmt->fourcc);
/* /*
* For the actual image parameters, we need to consider the field * For the actual image parameters, we need to consider the field
...@@ -1673,10 +1673,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f, ...@@ -1673,10 +1673,7 @@ static int __vpe_try_fmt(struct vpe_ctx *ctx, struct v4l2_format *f,
height = pix->height; height = pix->height;
if (!pix->colorspace) { if (!pix->colorspace) {
if (fmt->fourcc == V4L2_PIX_FMT_RGB24 || if (v4l2_is_format_rgb(finfo)) {
fmt->fourcc == V4L2_PIX_FMT_BGR24 ||
fmt->fourcc == V4L2_PIX_FMT_RGB32 ||
fmt->fourcc == V4L2_PIX_FMT_BGR32) {
pix->colorspace = V4L2_COLORSPACE_SRGB; pix->colorspace = V4L2_COLORSPACE_SRGB;
} else { } else {
if (height > 1280) /* HD */ if (height > 1280) /* HD */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment