Commit a7d5003c authored by Steve Longerbeam's avatar Steve Longerbeam Committed by Mauro Carvalho Chehab

media: imx: utils: Rename pixel format selection enumeration

After the introduction of the CS_SEL_BAYER flag, the "codespace"
pixel format selection enumeration wording no longer makes sense
(and even before, when selecting between YUV or RGB formats,
"codespace" was a misuse of the term).

Rename

- 'enum codespace_sel' to 'enum imx_pixfmt_sel'
- CS_SEL_* to PIXFMT_SEL_*
- local vars named cs_sel to fmt_sel or just sel

No functional changes.
Signed-off-by: default avatarSteve Longerbeam <slongerbeam@gmail.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 3130c45c
...@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,
switch (code->pad) { switch (code->pad) {
case PRP_SINK_PAD: case PRP_SINK_PAD:
ret = imx_media_enum_ipu_format(&code->code, code->index, ret = imx_media_enum_ipu_format(&code->code, code->index,
CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
break; break;
case PRP_SRC_PAD_PRPENC: case PRP_SRC_PAD_PRPENC:
case PRP_SRC_PAD_PRPVF: case PRP_SRC_PAD_PRPVF:
...@@ -180,10 +180,12 @@ static int prp_set_fmt(struct v4l2_subdev *sd, ...@@ -180,10 +180,12 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
MIN_H, MAX_H, H_ALIGN, S_ALIGN); MIN_H, MAX_H, H_ALIGN, S_ALIGN);
cc = imx_media_find_ipu_format(sdformat->format.code, cc = imx_media_find_ipu_format(sdformat->format.code,
CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
if (!cc) { if (!cc) {
imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV_RGB); imx_media_enum_ipu_format(&code, 0,
cc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
cc = imx_media_find_ipu_format(code,
PIXFMT_SEL_YUV_RGB);
sdformat->format.code = cc->codes[0]; sdformat->format.code = cc->codes[0];
} }
...@@ -438,7 +440,7 @@ static int prp_registered(struct v4l2_subdev *sd) ...@@ -438,7 +440,7 @@ static int prp_registered(struct v4l2_subdev *sd)
priv->frame_interval.denominator = 30; priv->frame_interval.denominator = 30;
/* set a default mbus format */ /* set a default mbus format */
imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV);
return imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code, return imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code,
V4L2_FIELD_NONE, NULL); V4L2_FIELD_NONE, NULL);
} }
......
...@@ -851,7 +851,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -851,7 +851,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,
return -EINVAL; return -EINVAL;
return imx_media_enum_ipu_format(&code->code, code->index, return imx_media_enum_ipu_format(&code->code, code->index,
CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
} }
static int prp_get_fmt(struct v4l2_subdev *sd, static int prp_get_fmt(struct v4l2_subdev *sd,
...@@ -886,12 +886,14 @@ static void prp_try_fmt(struct prp_priv *priv, ...@@ -886,12 +886,14 @@ static void prp_try_fmt(struct prp_priv *priv,
{ {
struct v4l2_mbus_framefmt *infmt; struct v4l2_mbus_framefmt *infmt;
*cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_YUV_RGB); *cc = imx_media_find_ipu_format(sdformat->format.code,
PIXFMT_SEL_YUV_RGB);
if (!*cc) { if (!*cc) {
u32 code; u32 code;
imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV_RGB); imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV_RGB);
*cc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB); *cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV_RGB);
sdformat->format.code = (*cc)->codes[0]; sdformat->format.code = (*cc)->codes[0];
} }
...@@ -1249,7 +1251,7 @@ static int prp_registered(struct v4l2_subdev *sd) ...@@ -1249,7 +1251,7 @@ static int prp_registered(struct v4l2_subdev *sd)
u32 code; u32 code;
/* set a default mbus format */ /* set a default mbus format */
imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV);
for (i = 0; i < PRPENCVF_NUM_PADS; i++) { for (i = 0; i < PRPENCVF_NUM_PADS; i++) {
ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
640, 480, code, V4L2_FIELD_NONE, 640, 480, code, V4L2_FIELD_NONE,
......
...@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, ...@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh,
}; };
int ret; int ret;
cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY); cc = imx_media_find_format(fsize->pixel_format, PIXFMT_SEL_ANY);
if (!cc) if (!cc)
return -EINVAL; return -EINVAL;
...@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, ...@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh,
}; };
int ret; int ret;
cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY); cc = imx_media_find_format(fival->pixel_format, PIXFMT_SEL_ANY);
if (!cc) if (!cc)
return -EINVAL; return -EINVAL;
...@@ -168,17 +168,18 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, ...@@ -168,17 +168,18 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
} }
cc_src = imx_media_find_ipu_format(fmt_src.format.code, cc_src = imx_media_find_ipu_format(fmt_src.format.code,
CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
if (cc_src) { if (cc_src) {
u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ? enum imx_pixfmt_sel fmt_sel =
CS_SEL_YUV : CS_SEL_RGB; (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
ret = imx_media_enum_format(&fourcc, f->index, cs_sel); ret = imx_media_enum_format(&fourcc, f->index, fmt_sel);
if (ret) if (ret)
return ret; return ret;
} else { } else {
cc_src = imx_media_find_mbus_format(fmt_src.format.code, cc_src = imx_media_find_mbus_format(fmt_src.format.code,
CS_SEL_ANY); PIXFMT_SEL_ANY);
if (WARN_ON(!cc_src)) if (WARN_ON(!cc_src))
return -EINVAL; return -EINVAL;
...@@ -211,22 +212,23 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, ...@@ -211,22 +212,23 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
const struct imx_media_pixfmt *cc, *cc_src; const struct imx_media_pixfmt *cc, *cc_src;
cc_src = imx_media_find_ipu_format(fmt_src->format.code, cc_src = imx_media_find_ipu_format(fmt_src->format.code,
CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
if (cc_src) { if (cc_src) {
u32 fourcc, cs_sel; enum imx_pixfmt_sel fmt_sel;
u32 fourcc;
cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ? fmt_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB; PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
fourcc = f->fmt.pix.pixelformat; fourcc = f->fmt.pix.pixelformat;
cc = imx_media_find_format(fourcc, cs_sel); cc = imx_media_find_format(fourcc, fmt_sel);
if (!cc) { if (!cc) {
imx_media_enum_format(&fourcc, 0, cs_sel); imx_media_enum_format(&fourcc, 0, fmt_sel);
cc = imx_media_find_format(fourcc, cs_sel); cc = imx_media_find_format(fourcc, fmt_sel);
} }
} else { } else {
cc_src = imx_media_find_mbus_format(fmt_src->format.code, cc_src = imx_media_find_mbus_format(fmt_src->format.code,
CS_SEL_ANY); PIXFMT_SEL_ANY);
if (WARN_ON(!cc_src)) if (WARN_ON(!cc_src))
return -EINVAL; return -EINVAL;
...@@ -792,7 +794,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) ...@@ -792,7 +794,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev)
vdev->compose.width = fmt_src.format.width; vdev->compose.width = fmt_src.format.width;
vdev->compose.height = fmt_src.format.height; vdev->compose.height = fmt_src.format.height;
vdev->cc = imx_media_find_format(vdev->fmt.fmt.pix.pixelformat, vdev->cc = imx_media_find_format(vdev->fmt.fmt.pix.pixelformat,
CS_SEL_ANY); PIXFMT_SEL_ANY);
v4l2_info(sd, "Registered %s as /dev/%s\n", vfd->name, v4l2_info(sd, "Registered %s as /dev/%s\n", vfd->name,
video_device_node_name(vfd)); video_device_node_name(vfd));
......
...@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh, ...@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,
u32 fourcc; u32 fourcc;
int ret; int ret;
ret = imx_media_enum_format(&fourcc, f->index, CS_SEL_YUV_RGB); ret = imx_media_enum_format(&fourcc, f->index, PIXFMT_SEL_YUV_RGB);
if (ret) if (ret)
return ret; return ret;
......
...@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
mutex_lock(&priv->lock); mutex_lock(&priv->lock);
infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, code->which); infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, code->which);
incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY); incc = imx_media_find_mbus_format(infmt->code, PIXFMT_SEL_ANY);
switch (code->pad) { switch (code->pad) {
case CSI_SINK_PAD: case CSI_SINK_PAD:
ret = imx_media_enum_mbus_format(&code->code, code->index, ret = imx_media_enum_mbus_format(&code->code, code->index,
CS_SEL_ANY); PIXFMT_SEL_ANY);
break; break;
case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_DIRECT:
case CSI_SRC_PAD_IDMAC: case CSI_SRC_PAD_IDMAC:
...@@ -1256,11 +1256,13 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -1256,11 +1256,13 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
} }
code->code = infmt->code; code->code = infmt->code;
} else { } else {
u32 cs_sel = (incc->cs == IPUV3_COLORSPACE_YUV) ? enum imx_pixfmt_sel fmt_sel =
CS_SEL_YUV : CS_SEL_RGB; (incc->cs == IPUV3_COLORSPACE_YUV) ?
PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
ret = imx_media_enum_ipu_format(&code->code, ret = imx_media_enum_ipu_format(&code->code,
code->index, code->index,
cs_sel); fmt_sel);
} }
break; break;
default: default:
...@@ -1433,7 +1435,7 @@ static void csi_try_fmt(struct csi_priv *priv, ...@@ -1433,7 +1435,7 @@ static void csi_try_fmt(struct csi_priv *priv,
switch (sdformat->pad) { switch (sdformat->pad) {
case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_DIRECT:
case CSI_SRC_PAD_IDMAC: case CSI_SRC_PAD_IDMAC:
incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY); incc = imx_media_find_mbus_format(infmt->code, PIXFMT_SEL_ANY);
sdformat->format.width = compose->width; sdformat->format.width = compose->width;
sdformat->format.height = compose->height; sdformat->format.height = compose->height;
...@@ -1442,14 +1444,15 @@ static void csi_try_fmt(struct csi_priv *priv, ...@@ -1442,14 +1444,15 @@ static void csi_try_fmt(struct csi_priv *priv,
sdformat->format.code = infmt->code; sdformat->format.code = infmt->code;
*cc = incc; *cc = incc;
} else { } else {
u32 cs_sel = (incc->cs == IPUV3_COLORSPACE_YUV) ? enum imx_pixfmt_sel fmt_sel =
CS_SEL_YUV : CS_SEL_RGB; (incc->cs == IPUV3_COLORSPACE_YUV) ?
PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
*cc = imx_media_find_ipu_format(sdformat->format.code, *cc = imx_media_find_ipu_format(sdformat->format.code,
cs_sel); fmt_sel);
if (!*cc) { if (!*cc) {
imx_media_enum_ipu_format(&code, 0, cs_sel); imx_media_enum_ipu_format(&code, 0, fmt_sel);
*cc = imx_media_find_ipu_format(code, cs_sel); *cc = imx_media_find_ipu_format(code, fmt_sel);
sdformat->format.code = (*cc)->codes[0]; sdformat->format.code = (*cc)->codes[0];
} }
} }
...@@ -1469,10 +1472,12 @@ static void csi_try_fmt(struct csi_priv *priv, ...@@ -1469,10 +1472,12 @@ static void csi_try_fmt(struct csi_priv *priv,
MIN_H, MAX_H, H_ALIGN, S_ALIGN); MIN_H, MAX_H, H_ALIGN, S_ALIGN);
*cc = imx_media_find_mbus_format(sdformat->format.code, *cc = imx_media_find_mbus_format(sdformat->format.code,
CS_SEL_ANY); PIXFMT_SEL_ANY);
if (!*cc) { if (!*cc) {
imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV_RGB); imx_media_enum_mbus_format(&code, 0,
*cc = imx_media_find_mbus_format(code, CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
*cc = imx_media_find_mbus_format(code,
PIXFMT_SEL_YUV_RGB);
sdformat->format.code = (*cc)->codes[0]; sdformat->format.code = (*cc)->codes[0];
} }
...@@ -1758,7 +1763,7 @@ static int csi_registered(struct v4l2_subdev *sd) ...@@ -1758,7 +1763,7 @@ static int csi_registered(struct v4l2_subdev *sd)
for (i = 0; i < CSI_NUM_PADS; i++) { for (i = 0; i < CSI_NUM_PADS; i++) {
code = 0; code = 0;
if (i != CSI_SINK_PAD) if (i != CSI_SINK_PAD)
imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV);
/* set a default mbus format */ /* set a default mbus format */
ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
......
...@@ -212,21 +212,21 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = { ...@@ -212,21 +212,21 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = {
static const struct imx_media_pixfmt *find_format(u32 fourcc, static const struct imx_media_pixfmt *find_format(u32 fourcc,
u32 code, u32 code,
enum codespace_sel cs_sel, enum imx_pixfmt_sel fmt_sel,
bool allow_non_mbus) bool allow_non_mbus)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
const struct imx_media_pixfmt *fmt = &pixel_formats[i]; const struct imx_media_pixfmt *fmt = &pixel_formats[i];
enum codespace_sel fmt_cs_sel; enum imx_pixfmt_sel sel;
unsigned int j; unsigned int j;
fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : sel = fmt->bayer ? PIXFMT_SEL_BAYER :
((fmt->cs == IPUV3_COLORSPACE_YUV) ? ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB); PIXFMT_SEL_YUV : PIXFMT_SEL_RGB);
if (!(fmt_cs_sel & cs_sel) || if (!(fmt_sel & sel) ||
(!allow_non_mbus && !fmt->codes[0])) (!allow_non_mbus && !fmt->codes[0]))
continue; continue;
...@@ -246,21 +246,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ...@@ -246,21 +246,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,
} }
static int enum_format(u32 *fourcc, u32 *code, u32 index, static int enum_format(u32 *fourcc, u32 *code, u32 index,
enum codespace_sel cs_sel, enum imx_pixfmt_sel fmt_sel,
bool allow_non_mbus) bool allow_non_mbus)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
const struct imx_media_pixfmt *fmt = &pixel_formats[i]; const struct imx_media_pixfmt *fmt = &pixel_formats[i];
enum codespace_sel fmt_cs_sel; enum imx_pixfmt_sel sel;
unsigned int j; unsigned int j;
fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : sel = fmt->bayer ? PIXFMT_SEL_BAYER :
((fmt->cs == IPUV3_COLORSPACE_YUV) ? ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB); PIXFMT_SEL_YUV : PIXFMT_SEL_RGB);
if (!(fmt_cs_sel & cs_sel) || if (!(fmt_sel & sel) ||
(!allow_non_mbus && !fmt->codes[0])) (!allow_non_mbus && !fmt->codes[0]))
continue; continue;
...@@ -288,50 +288,51 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ...@@ -288,50 +288,51 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
} }
const struct imx_media_pixfmt * const struct imx_media_pixfmt *
imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel) imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel)
{ {
return find_format(fourcc, 0, cs_sel, true); return find_format(fourcc, 0, fmt_sel, true);
} }
EXPORT_SYMBOL_GPL(imx_media_find_format); EXPORT_SYMBOL_GPL(imx_media_find_format);
int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel) int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel fmt_sel)
{ {
return enum_format(fourcc, NULL, index, cs_sel, true); return enum_format(fourcc, NULL, index, fmt_sel, true);
} }
EXPORT_SYMBOL_GPL(imx_media_enum_format); EXPORT_SYMBOL_GPL(imx_media_enum_format);
const struct imx_media_pixfmt * const struct imx_media_pixfmt *
imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel fmt_sel)
{ {
return find_format(0, code, cs_sel, false); return find_format(0, code, fmt_sel, false);
} }
EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); EXPORT_SYMBOL_GPL(imx_media_find_mbus_format);
int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel) int imx_media_enum_mbus_format(u32 *code, u32 index,
enum imx_pixfmt_sel fmt_sel)
{ {
return enum_format(NULL, code, index, cs_sel, false); return enum_format(NULL, code, index, fmt_sel, false);
} }
EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format);
const struct imx_media_pixfmt * const struct imx_media_pixfmt *
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel)
{ {
const struct imx_media_pixfmt *array, *fmt, *ret = NULL; const struct imx_media_pixfmt *array, *fmt, *ret = NULL;
u32 array_size; u32 array_size;
int i, j; int i, j;
cs_sel &= ~CS_SEL_BAYER; fmt_sel &= ~PIXFMT_SEL_BAYER;
switch (cs_sel) { switch (fmt_sel) {
case CS_SEL_YUV: case PIXFMT_SEL_YUV:
array_size = NUM_IPU_YUV_FORMATS; array_size = NUM_IPU_YUV_FORMATS;
array = ipu_yuv_formats; array = ipu_yuv_formats;
break; break;
case CS_SEL_RGB: case PIXFMT_SEL_RGB:
array_size = NUM_IPU_RGB_FORMATS; array_size = NUM_IPU_RGB_FORMATS;
array = ipu_rgb_formats; array = ipu_rgb_formats;
break; break;
case CS_SEL_YUV_RGB: case PIXFMT_SEL_YUV_RGB:
array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS; array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS;
array = ipu_yuv_formats; array = ipu_yuv_formats;
break; break;
...@@ -340,7 +341,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) ...@@ -340,7 +341,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)
} }
for (i = 0; i < array_size; i++) { for (i = 0; i < array_size; i++) {
if (cs_sel == CS_SEL_YUV_RGB && i >= NUM_IPU_YUV_FORMATS) if (fmt_sel == PIXFMT_SEL_YUV_RGB && i >= NUM_IPU_YUV_FORMATS)
fmt = &ipu_rgb_formats[i - NUM_IPU_YUV_FORMATS]; fmt = &ipu_rgb_formats[i - NUM_IPU_YUV_FORMATS];
else else
fmt = &array[i]; fmt = &array[i];
...@@ -358,22 +359,23 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) ...@@ -358,22 +359,23 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)
} }
EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); EXPORT_SYMBOL_GPL(imx_media_find_ipu_format);
int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) int imx_media_enum_ipu_format(u32 *code, u32 index,
enum imx_pixfmt_sel fmt_sel)
{ {
cs_sel &= ~CS_SEL_BAYER; fmt_sel &= ~PIXFMT_SEL_BAYER;
switch (cs_sel) { switch (fmt_sel) {
case CS_SEL_YUV: case PIXFMT_SEL_YUV:
if (index >= NUM_IPU_YUV_FORMATS) if (index >= NUM_IPU_YUV_FORMATS)
return -EINVAL; return -EINVAL;
*code = ipu_yuv_formats[index].codes[0]; *code = ipu_yuv_formats[index].codes[0];
break; break;
case CS_SEL_RGB: case PIXFMT_SEL_RGB:
if (index >= NUM_IPU_RGB_FORMATS) if (index >= NUM_IPU_RGB_FORMATS)
return -EINVAL; return -EINVAL;
*code = ipu_rgb_formats[index].codes[0]; *code = ipu_rgb_formats[index].codes[0];
break; break;
case CS_SEL_YUV_RGB: case PIXFMT_SEL_YUV_RGB:
if (index >= NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS) if (index >= NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS)
return -EINVAL; return -EINVAL;
if (index >= NUM_IPU_YUV_FORMATS) { if (index >= NUM_IPU_YUV_FORMATS) {
...@@ -401,10 +403,10 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, ...@@ -401,10 +403,10 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
mbus->height = height; mbus->height = height;
mbus->field = field; mbus->field = field;
if (code == 0) if (code == 0)
imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_YUV);
lcc = imx_media_find_mbus_format(code, CS_SEL_ANY); lcc = imx_media_find_mbus_format(code, PIXFMT_SEL_ANY);
if (!lcc) { if (!lcc) {
lcc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB); lcc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV_RGB);
if (!lcc) if (!lcc)
return -EINVAL; return -EINVAL;
} }
...@@ -473,9 +475,11 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, ...@@ -473,9 +475,11 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,
const struct imx_media_pixfmt *cc; const struct imx_media_pixfmt *cc;
bool is_rgb = false; bool is_rgb = false;
cc = imx_media_find_mbus_format(tryfmt->code, CS_SEL_ANY); cc = imx_media_find_mbus_format(tryfmt->code, PIXFMT_SEL_ANY);
if (!cc) if (!cc)
cc = imx_media_find_ipu_format(tryfmt->code, CS_SEL_YUV_RGB); cc = imx_media_find_ipu_format(tryfmt->code,
PIXFMT_SEL_YUV_RGB);
if (cc && cc->cs == IPUV3_COLORSPACE_RGB) if (cc && cc->cs == IPUV3_COLORSPACE_RGB)
is_rgb = true; is_rgb = true;
...@@ -525,10 +529,11 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, ...@@ -525,10 +529,11 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
u32 stride; u32 stride;
if (!cc) { if (!cc) {
cc = imx_media_find_ipu_format(mbus->code, CS_SEL_YUV_RGB); cc = imx_media_find_ipu_format(mbus->code,
PIXFMT_SEL_YUV_RGB);
if (!cc) if (!cc)
cc = imx_media_find_mbus_format(mbus->code, cc = imx_media_find_mbus_format(mbus->code,
CS_SEL_ANY); PIXFMT_SEL_ANY);
if (!cc) if (!cc)
return -EINVAL; return -EINVAL;
} }
...@@ -540,8 +545,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, ...@@ -540,8 +545,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
if (cc->ipufmt && cc->cs == IPUV3_COLORSPACE_YUV) { if (cc->ipufmt && cc->cs == IPUV3_COLORSPACE_YUV) {
u32 code; u32 code;
imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_YUV);
cc = imx_media_find_mbus_format(code, CS_SEL_YUV); cc = imx_media_find_mbus_format(code, PIXFMT_SEL_YUV);
} }
/* Round up width for minimum burst size */ /* Round up width for minimum burst size */
...@@ -592,7 +597,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, ...@@ -592,7 +597,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
{ {
const struct imx_media_pixfmt *fmt; const struct imx_media_pixfmt *fmt;
fmt = imx_media_find_format(image->pix.pixelformat, CS_SEL_ANY); fmt = imx_media_find_format(image->pix.pixelformat, PIXFMT_SEL_ANY);
if (!fmt) if (!fmt)
return -EINVAL; return -EINVAL;
......
...@@ -548,7 +548,8 @@ static int vdic_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -548,7 +548,8 @@ static int vdic_enum_mbus_code(struct v4l2_subdev *sd,
if (code->pad >= VDIC_NUM_PADS) if (code->pad >= VDIC_NUM_PADS)
return -EINVAL; return -EINVAL;
return imx_media_enum_ipu_format(&code->code, code->index, CS_SEL_YUV); return imx_media_enum_ipu_format(&code->code, code->index,
PIXFMT_SEL_YUV);
} }
static int vdic_get_fmt(struct v4l2_subdev *sd, static int vdic_get_fmt(struct v4l2_subdev *sd,
...@@ -583,12 +584,13 @@ static void vdic_try_fmt(struct vdic_priv *priv, ...@@ -583,12 +584,13 @@ static void vdic_try_fmt(struct vdic_priv *priv,
{ {
struct v4l2_mbus_framefmt *infmt; struct v4l2_mbus_framefmt *infmt;
*cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_YUV); *cc = imx_media_find_ipu_format(sdformat->format.code,
PIXFMT_SEL_YUV);
if (!*cc) { if (!*cc) {
u32 code; u32 code;
imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV);
*cc = imx_media_find_ipu_format(code, CS_SEL_YUV); *cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV);
sdformat->format.code = (*cc)->codes[0]; sdformat->format.code = (*cc)->codes[0];
} }
...@@ -850,7 +852,7 @@ static int vdic_registered(struct v4l2_subdev *sd) ...@@ -850,7 +852,7 @@ static int vdic_registered(struct v4l2_subdev *sd)
for (i = 0; i < VDIC_NUM_PADS; i++) { for (i = 0; i < VDIC_NUM_PADS; i++) {
code = 0; code = 0;
if (i != VDIC_SINK_PAD_IDMAC) if (i != VDIC_SINK_PAD_IDMAC)
imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV);
/* set a default mbus format */ /* set a default mbus format */
ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
......
...@@ -79,6 +79,14 @@ struct imx_media_pixfmt { ...@@ -79,6 +79,14 @@ struct imx_media_pixfmt {
bool ipufmt; /* is one of the IPU internal formats */ bool ipufmt; /* is one of the IPU internal formats */
}; };
enum imx_pixfmt_sel {
PIXFMT_SEL_YUV = BIT(0), /* select YUV formats */
PIXFMT_SEL_RGB = BIT(1), /* select RGB formats */
PIXFMT_SEL_BAYER = BIT(2), /* select BAYER formats */
PIXFMT_SEL_YUV_RGB = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB,
PIXFMT_SEL_ANY = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB | PIXFMT_SEL_BAYER,
};
struct imx_media_buffer { struct imx_media_buffer {
struct vb2_v4l2_buffer vbuf; /* v4l buffer must be first */ struct vb2_v4l2_buffer vbuf; /* v4l buffer must be first */
struct list_head list; struct list_head list;
...@@ -149,24 +157,16 @@ struct imx_media_dev { ...@@ -149,24 +157,16 @@ struct imx_media_dev {
struct v4l2_subdev *sync_sd[2][NUM_IPU_SUBDEVS]; struct v4l2_subdev *sync_sd[2][NUM_IPU_SUBDEVS];
}; };
enum codespace_sel {
CS_SEL_YUV = BIT(0),
CS_SEL_RGB = BIT(1),
CS_SEL_BAYER = BIT(2),
CS_SEL_YUV_RGB = CS_SEL_YUV | CS_SEL_RGB,
CS_SEL_ANY = CS_SEL_YUV | CS_SEL_RGB | CS_SEL_BAYER,
};
/* imx-media-utils.c */ /* imx-media-utils.c */
const struct imx_media_pixfmt * const struct imx_media_pixfmt *
imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel); imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel sel);
int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel); int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel sel);
const struct imx_media_pixfmt * const struct imx_media_pixfmt *
imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel); imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel sel);
int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel); int imx_media_enum_mbus_format(u32 *code, u32 index, enum imx_pixfmt_sel sel);
const struct imx_media_pixfmt * const struct imx_media_pixfmt *
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel); imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel sel);
int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel); int imx_media_enum_ipu_format(u32 *code, u32 index, enum imx_pixfmt_sel sel);
int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
u32 width, u32 height, u32 code, u32 field, u32 width, u32 height, u32 code, u32 field,
const struct imx_media_pixfmt **cc); const struct imx_media_pixfmt **cc);
......
...@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,
switch (code->pad) { switch (code->pad) {
case IMX7_CSI_PAD_SINK: case IMX7_CSI_PAD_SINK:
ret = imx_media_enum_mbus_format(&code->code, code->index, ret = imx_media_enum_mbus_format(&code->code, code->index,
CS_SEL_ANY); PIXFMT_SEL_ANY);
break; break;
case IMX7_CSI_PAD_SRC: case IMX7_CSI_PAD_SRC:
if (code->index != 0) { if (code->index != 0) {
...@@ -1019,7 +1019,8 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, ...@@ -1019,7 +1019,8 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
switch (sdformat->pad) { switch (sdformat->pad) {
case IMX7_CSI_PAD_SRC: case IMX7_CSI_PAD_SRC:
in_cc = imx_media_find_mbus_format(in_fmt->code, CS_SEL_ANY); in_cc = imx_media_find_mbus_format(in_fmt->code,
PIXFMT_SEL_ANY);
sdformat->format.width = in_fmt->width; sdformat->format.width = in_fmt->width;
sdformat->format.height = in_fmt->height; sdformat->format.height = in_fmt->height;
...@@ -1034,10 +1035,12 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, ...@@ -1034,10 +1035,12 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,
break; break;
case IMX7_CSI_PAD_SINK: case IMX7_CSI_PAD_SINK:
*cc = imx_media_find_mbus_format(sdformat->format.code, *cc = imx_media_find_mbus_format(sdformat->format.code,
CS_SEL_ANY); PIXFMT_SEL_ANY);
if (!*cc) { if (!*cc) {
imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV_RGB); imx_media_enum_mbus_format(&code, 0,
*cc = imx_media_find_mbus_format(code, CS_SEL_YUV_RGB); PIXFMT_SEL_YUV_RGB);
*cc = imx_media_find_mbus_format(code,
PIXFMT_SEL_YUV_RGB);
sdformat->format.code = (*cc)->codes[0]; sdformat->format.code = (*cc)->codes[0];
} }
......
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