Commit 0cd5d896 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

media: imx: utils: Handle Bayer format lookup through a selection flag

The format lookup (and enumeration) functions take a boolean flag to
tell if Bayer formats should be considered. This leads to hard to read
lines such as

	return enum_format(fourcc, NULL, index, cs_sel, true, false);

where the boolean parameters can easily be mixed. To make the code
clearer, add a CS_SEL_BAYER flag that can be passed through the
codespace_sel parameter of the lookup functions to replace the bool
parameter.

[slongerbeam@gmail.com: Instead of declaring CS_SEL_ANY as a bitfield
 containing only CS_SEL_YUV | CS_SEL_RGB, declare CS_SEL_ANY as all of
 the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB
 selection as CS_SEL_YUV_RGB, and that is used by sub-devices that
 don't support BAYER and only allow selecting and enumerating YUV or RGB
 encodings. CS_SEL_ANY is now only used by the CSI sub-devices and the
 attached capture interfaces, since only those devices support BAYER
 formats.]
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarSteve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent c25ab5ca
...@@ -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_ANY); CS_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,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, ...@@ -180,10 +180,10 @@ 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_ANY); CS_SEL_YUV_RGB);
if (!cc) { if (!cc) {
imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV_RGB);
cc = imx_media_find_ipu_format(code, CS_SEL_ANY); cc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB);
sdformat->format.code = cc->codes[0]; sdformat->format.code = cc->codes[0];
} }
......
...@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,
if (code->pad >= PRPENCVF_NUM_PADS) if (code->pad >= PRPENCVF_NUM_PADS)
return -EINVAL; return -EINVAL;
return imx_media_enum_ipu_format(&code->code, code->index, CS_SEL_ANY); return imx_media_enum_ipu_format(&code->code, code->index,
CS_SEL_YUV_RGB);
} }
static int prp_get_fmt(struct v4l2_subdev *sd, static int prp_get_fmt(struct v4l2_subdev *sd,
...@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, ...@@ -885,12 +886,12 @@ 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_ANY); *cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_YUV_RGB);
if (!*cc) { if (!*cc) {
u32 code; u32 code;
imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV_RGB);
*cc = imx_media_find_ipu_format(code, CS_SEL_ANY); *cc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB);
sdformat->format.code = (*cc)->codes[0]; sdformat->format.code = (*cc)->codes[0];
} }
......
...@@ -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, true); cc = imx_media_find_format(fsize->pixel_format, CS_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, true); cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY);
if (!cc) if (!cc)
return -EINVAL; return -EINVAL;
...@@ -167,7 +167,8 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, ...@@ -167,7 +167,8 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
return ret; return ret;
} }
cc_src = imx_media_find_ipu_format(fmt_src.format.code, CS_SEL_ANY); cc_src = imx_media_find_ipu_format(fmt_src.format.code,
CS_SEL_YUV_RGB);
if (cc_src) { if (cc_src) {
u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ? u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB; CS_SEL_YUV : CS_SEL_RGB;
...@@ -177,7 +178,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, ...@@ -177,7 +178,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
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, true); CS_SEL_ANY);
if (WARN_ON(!cc_src)) if (WARN_ON(!cc_src))
return -EINVAL; return -EINVAL;
...@@ -209,7 +210,8 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, ...@@ -209,7 +210,8 @@ 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, CS_SEL_ANY); cc_src = imx_media_find_ipu_format(fmt_src->format.code,
CS_SEL_YUV_RGB);
if (cc_src) { if (cc_src) {
u32 fourcc, cs_sel; u32 fourcc, cs_sel;
...@@ -217,14 +219,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, ...@@ -217,14 +219,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
CS_SEL_YUV : CS_SEL_RGB; CS_SEL_YUV : CS_SEL_RGB;
fourcc = f->fmt.pix.pixelformat; fourcc = f->fmt.pix.pixelformat;
cc = imx_media_find_format(fourcc, cs_sel, false); cc = imx_media_find_format(fourcc, cs_sel);
if (!cc) { if (!cc) {
imx_media_enum_format(&fourcc, 0, cs_sel); imx_media_enum_format(&fourcc, 0, cs_sel);
cc = imx_media_find_format(fourcc, cs_sel, false); cc = imx_media_find_format(fourcc, cs_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, true); CS_SEL_ANY);
if (WARN_ON(!cc_src)) if (WARN_ON(!cc_src))
return -EINVAL; return -EINVAL;
...@@ -790,7 +792,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) ...@@ -790,7 +792,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, false); CS_SEL_YUV_RGB);
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_ANY); ret = imx_media_enum_format(&fourcc, f->index, CS_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, true); incc = imx_media_find_mbus_format(infmt->code, CS_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, true); CS_SEL_ANY);
break; break;
case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_DIRECT:
case CSI_SRC_PAD_IDMAC: case CSI_SRC_PAD_IDMAC:
...@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv, ...@@ -1433,8 +1433,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, incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY);
CS_SEL_ANY, true);
sdformat->format.width = compose->width; sdformat->format.width = compose->width;
sdformat->format.height = compose->height; sdformat->format.height = compose->height;
...@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, ...@@ -1470,12 +1469,10 @@ 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, true); CS_SEL_ANY);
if (!*cc) { if (!*cc) {
imx_media_enum_mbus_format(&code, 0, imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV_RGB);
CS_SEL_ANY, false); *cc = imx_media_find_mbus_format(code, CS_SEL_YUV_RGB);
*cc = imx_media_find_mbus_format(code,
CS_SEL_ANY, false);
sdformat->format.code = (*cc)->codes[0]; sdformat->format.code = (*cc)->codes[0];
} }
......
...@@ -213,8 +213,7 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = { ...@@ -213,8 +213,7 @@ 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 codespace_sel cs_sel,
bool allow_non_mbus, bool allow_non_mbus)
bool allow_bayer)
{ {
unsigned int i; unsigned int i;
...@@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ...@@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,
enum codespace_sel fmt_cs_sel; enum codespace_sel fmt_cs_sel;
unsigned int j; unsigned int j;
fmt_cs_sel = (fmt->cs == IPUV3_COLORSPACE_YUV) ? fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER :
CS_SEL_YUV : CS_SEL_RGB; ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB);
if ((cs_sel != CS_SEL_ANY && fmt_cs_sel != cs_sel) || if (!(fmt_cs_sel & cs_sel) ||
(!allow_non_mbus && !fmt->codes[0]) || (!allow_non_mbus && !fmt->codes[0]))
(!allow_bayer && fmt->bayer))
continue; continue;
if (fourcc && fmt->fourcc == fourcc) if (fourcc && fmt->fourcc == fourcc)
...@@ -248,8 +247,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ...@@ -248,8 +247,7 @@ 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 codespace_sel cs_sel,
bool allow_non_mbus, bool allow_non_mbus)
bool allow_bayer)
{ {
unsigned int i; unsigned int i;
...@@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ...@@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
enum codespace_sel fmt_cs_sel; enum codespace_sel fmt_cs_sel;
unsigned int j; unsigned int j;
fmt_cs_sel = (fmt->cs == IPUV3_COLORSPACE_YUV) ? fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER :
CS_SEL_YUV : CS_SEL_RGB; ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB);
if ((cs_sel != CS_SEL_ANY && fmt_cs_sel != cs_sel) || if (!(fmt_cs_sel & cs_sel) ||
(!allow_non_mbus && !fmt->codes[0]) || (!allow_non_mbus && !fmt->codes[0]))
(!allow_bayer && fmt->bayer))
continue; continue;
if (fourcc && index == 0) { if (fourcc && index == 0) {
...@@ -290,30 +288,28 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ...@@ -290,30 +288,28 @@ 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, bool allow_bayer) imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel)
{ {
return find_format(fourcc, 0, cs_sel, true, allow_bayer); return find_format(fourcc, 0, cs_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 codespace_sel cs_sel)
{ {
return enum_format(fourcc, NULL, index, cs_sel, true, false); return enum_format(fourcc, NULL, index, cs_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 codespace_sel cs_sel)
bool allow_bayer)
{ {
return find_format(0, code, cs_sel, false, allow_bayer); return find_format(0, code, cs_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 codespace_sel cs_sel)
bool allow_bayer)
{ {
return enum_format(NULL, code, index, cs_sel, false, allow_bayer); return enum_format(NULL, code, index, cs_sel, false);
} }
EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format);
...@@ -324,6 +320,8 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) ...@@ -324,6 +320,8 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)
u32 array_size; u32 array_size;
int i, j; int i, j;
cs_sel &= ~CS_SEL_BAYER;
switch (cs_sel) { switch (cs_sel) {
case CS_SEL_YUV: case CS_SEL_YUV:
array_size = NUM_IPU_YUV_FORMATS; array_size = NUM_IPU_YUV_FORMATS;
...@@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) ...@@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)
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_ANY: case CS_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;
...@@ -342,7 +340,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) ...@@ -342,7 +340,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_ANY && i >= NUM_IPU_YUV_FORMATS) if (cs_sel == CS_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];
...@@ -362,6 +360,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); ...@@ -362,6 +360,8 @@ 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 codespace_sel cs_sel)
{ {
cs_sel &= ~CS_SEL_BAYER;
switch (cs_sel) { switch (cs_sel) {
case CS_SEL_YUV: case CS_SEL_YUV:
if (index >= NUM_IPU_YUV_FORMATS) if (index >= NUM_IPU_YUV_FORMATS)
...@@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) ...@@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel)
return -EINVAL; return -EINVAL;
*code = ipu_rgb_formats[index].codes[0]; *code = ipu_rgb_formats[index].codes[0];
break; break;
case CS_SEL_ANY: case CS_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 +401,10 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, ...@@ -401,10 +401,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, false); imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV);
lcc = imx_media_find_mbus_format(code, CS_SEL_ANY, false); lcc = imx_media_find_mbus_format(code, CS_SEL_YUV_RGB);
if (!lcc) { if (!lcc) {
lcc = imx_media_find_ipu_format(code, CS_SEL_ANY); lcc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB);
if (!lcc) if (!lcc)
return -EINVAL; return -EINVAL;
} }
...@@ -473,9 +473,9 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, ...@@ -473,9 +473,9 @@ 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, true); cc = imx_media_find_mbus_format(tryfmt->code, CS_SEL_ANY);
if (!cc) if (!cc)
cc = imx_media_find_ipu_format(tryfmt->code, CS_SEL_ANY); cc = imx_media_find_ipu_format(tryfmt->code, CS_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 +525,10 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, ...@@ -525,10 +525,10 @@ 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_ANY); cc = imx_media_find_ipu_format(mbus->code, CS_SEL_YUV_RGB);
if (!cc) if (!cc)
cc = imx_media_find_mbus_format(mbus->code, CS_SEL_ANY, cc = imx_media_find_mbus_format(mbus->code,
true); CS_SEL_ANY);
if (!cc) if (!cc)
return -EINVAL; return -EINVAL;
} }
...@@ -540,8 +540,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, ...@@ -540,8 +540,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, false); imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV);
cc = imx_media_find_mbus_format(code, CS_SEL_YUV, false); cc = imx_media_find_mbus_format(code, CS_SEL_YUV);
} }
/* Round up width for minimum burst size */ /* Round up width for minimum burst size */
...@@ -592,7 +592,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, ...@@ -592,7 +592,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, true); fmt = imx_media_find_format(image->pix.pixelformat, CS_SEL_ANY);
if (!fmt) if (!fmt)
return -EINVAL; return -EINVAL;
......
...@@ -150,20 +150,20 @@ struct imx_media_dev { ...@@ -150,20 +150,20 @@ struct imx_media_dev {
}; };
enum codespace_sel { enum codespace_sel {
CS_SEL_YUV = 0, CS_SEL_YUV = BIT(0),
CS_SEL_RGB, CS_SEL_RGB = BIT(1),
CS_SEL_ANY, 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, bool allow_bayer); imx_media_find_format(u32 fourcc, enum codespace_sel cs_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 codespace_sel cs_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 codespace_sel cs_sel);
bool allow_bayer); 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 codespace_sel cs_sel,
bool allow_bayer);
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 codespace_sel cs_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 codespace_sel cs_sel);
......
...@@ -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, true); CS_SEL_ANY);
break; break;
case IMX7_CSI_PAD_SRC: case IMX7_CSI_PAD_SRC:
if (code->index != 0) { if (code->index != 0) {
...@@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, ...@@ -1019,8 +1019,7 @@ 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, CS_SEL_ANY);
true);
sdformat->format.width = in_fmt->width; sdformat->format.width = in_fmt->width;
sdformat->format.height = in_fmt->height; sdformat->format.height = in_fmt->height;
...@@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, ...@@ -1035,11 +1034,10 @@ 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, true); CS_SEL_ANY);
if (!*cc) { if (!*cc) {
imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY, false); imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV_RGB);
*cc = imx_media_find_mbus_format(code, CS_SEL_ANY, *cc = imx_media_find_mbus_format(code, CS_SEL_YUV_RGB);
false);
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