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

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
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,
	switch (code->pad) {
	case PRP_SINK_PAD:
		ret = imx_media_enum_ipu_format(&code->code, code->index,
						CS_SEL_ANY);
						CS_SEL_YUV_RGB);
		break;
	case PRP_SRC_PAD_PRPENC:
	case PRP_SRC_PAD_PRPVF:
@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
				      MIN_H, MAX_H, H_ALIGN, S_ALIGN);

		cc = imx_media_find_ipu_format(sdformat->format.code,
					       CS_SEL_ANY);
					       CS_SEL_YUV_RGB);
		if (!cc) {
			imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY);
			cc = imx_media_find_ipu_format(code, CS_SEL_ANY);
			imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV_RGB);
			cc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB);
			sdformat->format.code = cc->codes[0];
		}

+5 −4
Original line number Diff line number Diff line
@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,
	if (code->pad >= PRPENCVF_NUM_PADS)
		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,
@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv,
{
	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) {
		u32 code;

		imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY);
		*cc = imx_media_find_ipu_format(code, CS_SEL_ANY);
		imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV_RGB);
		*cc = imx_media_find_ipu_format(code, CS_SEL_YUV_RGB);
		sdformat->format.code = (*cc)->codes[0];
	}

+11 −9
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh,
	};
	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)
		return -EINVAL;

@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh,
	};
	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)
		return -EINVAL;

@@ -167,7 +167,8 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
		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) {
		u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
			CS_SEL_YUV : CS_SEL_RGB;
@@ -177,7 +178,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
			return ret;
	} else {
		cc_src = imx_media_find_mbus_format(fmt_src.format.code,
						    CS_SEL_ANY, true);
						    CS_SEL_ANY);
		if (WARN_ON(!cc_src))
			return -EINVAL;

@@ -209,7 +210,8 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
{
	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) {
		u32 fourcc, cs_sel;

@@ -217,14 +219,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
			CS_SEL_YUV : CS_SEL_RGB;
		fourcc = f->fmt.pix.pixelformat;

		cc = imx_media_find_format(fourcc, cs_sel, false);
		cc = imx_media_find_format(fourcc, cs_sel);
		if (!cc) {
			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 {
		cc_src = imx_media_find_mbus_format(fmt_src->format.code,
						    CS_SEL_ANY, true);
						    CS_SEL_ANY);
		if (WARN_ON(!cc_src))
			return -EINVAL;

@@ -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.height = fmt_src.format.height;
	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,
		  video_device_node_name(vfd));
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,
	u32 fourcc;
	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)
		return ret;

+6 −9
Original line number Diff line number Diff line
@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
	mutex_lock(&priv->lock);

	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) {
	case CSI_SINK_PAD:
		ret = imx_media_enum_mbus_format(&code->code, code->index,
						 CS_SEL_ANY, true);
						 CS_SEL_ANY);
		break;
	case CSI_SRC_PAD_DIRECT:
	case CSI_SRC_PAD_IDMAC:
@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv,
	switch (sdformat->pad) {
	case CSI_SRC_PAD_DIRECT:
	case CSI_SRC_PAD_IDMAC:
		incc = imx_media_find_mbus_format(infmt->code,
						  CS_SEL_ANY, true);
		incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY);

		sdformat->format.width = compose->width;
		sdformat->format.height = compose->height;
@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv,
				      MIN_H, MAX_H, H_ALIGN, S_ALIGN);

		*cc = imx_media_find_mbus_format(sdformat->format.code,
						 CS_SEL_ANY, true);
						 CS_SEL_ANY);
		if (!*cc) {
			imx_media_enum_mbus_format(&code, 0,
						   CS_SEL_ANY, false);
			*cc = imx_media_find_mbus_format(code,
							 CS_SEL_ANY, false);
			imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV_RGB);
			*cc = imx_media_find_mbus_format(code, CS_SEL_YUV_RGB);
			sdformat->format.code = (*cc)->codes[0];
		}

Loading