Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 717fd5b4 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab
Browse files

[media] v4l2: replace try_mbus_fmt by set_fmt



The try_mbus_fmt video op is a duplicate of the pad op. Replace all uses
in sub-devices by the set_fmt() pad op.

Since try_mbus_fmt and s_mbus_fmt both map to the set_fmt pad op (but
with a different 'which' argument), this patch will replace both
try_mbus_fmt and s_mbus_fmt by set_fmt.

Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kamil Debski <k.debski@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent da298c6d
Loading
Loading
Loading
Loading
+18 −18
Original line number Diff line number Diff line
@@ -431,10 +431,15 @@ static int adv7183_enum_mbus_code(struct v4l2_subdev *sd,
	return 0;
}

static int adv7183_try_mbus_fmt(struct v4l2_subdev *sd,
				struct v4l2_mbus_framefmt *fmt)
static int adv7183_set_fmt(struct v4l2_subdev *sd,
		struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *format)
{
	struct adv7183 *decoder = to_adv7183(sd);
	struct v4l2_mbus_framefmt *fmt = &format->format;

	if (format->pad)
		return -EINVAL;

	fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
	fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -447,16 +452,10 @@ static int adv7183_try_mbus_fmt(struct v4l2_subdev *sd,
		fmt->width = 720;
		fmt->height = 576;
	}
	return 0;
}

static int adv7183_s_mbus_fmt(struct v4l2_subdev *sd,
				struct v4l2_mbus_framefmt *fmt)
{
	struct adv7183 *decoder = to_adv7183(sd);

	adv7183_try_mbus_fmt(sd, fmt);
	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
		decoder->fmt = *fmt;
	else
		cfg->try_fmt = *fmt;
	return 0;
}

@@ -519,14 +518,13 @@ static const struct v4l2_subdev_video_ops adv7183_video_ops = {
	.s_routing = adv7183_s_routing,
	.querystd = adv7183_querystd,
	.g_input_status = adv7183_g_input_status,
	.try_mbus_fmt = adv7183_try_mbus_fmt,
	.s_mbus_fmt = adv7183_s_mbus_fmt,
	.s_stream = adv7183_s_stream,
};

static const struct v4l2_subdev_pad_ops adv7183_pad_ops = {
	.enum_mbus_code = adv7183_enum_mbus_code,
	.get_fmt = adv7183_get_fmt,
	.set_fmt = adv7183_set_fmt,
};

static const struct v4l2_subdev_ops adv7183_ops = {
@@ -542,7 +540,9 @@ static int adv7183_probe(struct i2c_client *client,
	struct v4l2_subdev *sd;
	struct v4l2_ctrl_handler *hdl;
	int ret;
	struct v4l2_mbus_framefmt fmt;
	struct v4l2_subdev_format fmt = {
		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
	};
	const unsigned *pin_array;

	/* Check if the adapter supports the needed features */
@@ -612,9 +612,9 @@ static int adv7183_probe(struct i2c_client *client,

	adv7183_writeregs(sd, adv7183_init_regs, ARRAY_SIZE(adv7183_init_regs));
	adv7183_s_std(sd, decoder->std);
	fmt.width = 720;
	fmt.height = 576;
	adv7183_s_mbus_fmt(sd, &fmt);
	fmt.format.width = 720;
	fmt.format.height = 576;
	adv7183_set_fmt(sd, NULL, &fmt);

	/* initialize the hardware to the default control values */
	ret = v4l2_ctrl_handler_setup(hdl);
+17 −21
Original line number Diff line number Diff line
@@ -335,9 +335,14 @@ static int mt9v011_enum_mbus_code(struct v4l2_subdev *sd,
	return 0;
}

static int mt9v011_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt)
static int mt9v011_set_fmt(struct v4l2_subdev *sd,
		struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *format)
{
	if (fmt->code != MEDIA_BUS_FMT_SGRBG8_1X8)
	struct v4l2_mbus_framefmt *fmt = &format->format;
	struct mt9v011 *core = to_mt9v011(sd);

	if (format->pad || fmt->code != MEDIA_BUS_FMT_SGRBG8_1X8)
		return -EINVAL;

	v4l_bound_align_image(&fmt->width, 48, 639, 1,
@@ -345,6 +350,15 @@ static int mt9v011_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
	fmt->field = V4L2_FIELD_NONE;
	fmt->colorspace = V4L2_COLORSPACE_SRGB;

	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
		core->width = fmt->width;
		core->height = fmt->height;

		set_res(sd);
	} else {
		cfg->try_fmt = *fmt;
	}

	return 0;
}

@@ -386,23 +400,6 @@ static int mt9v011_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
	return 0;
}

static int mt9v011_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *fmt)
{
	struct mt9v011 *core = to_mt9v011(sd);
	int rc;

	rc = mt9v011_try_mbus_fmt(sd, fmt);
	if (rc < 0)
		return -EINVAL;

	core->width = fmt->width;
	core->height = fmt->height;

	set_res(sd);

	return 0;
}

#ifdef CONFIG_VIDEO_ADV_DEBUG
static int mt9v011_g_register(struct v4l2_subdev *sd,
			      struct v4l2_dbg_register *reg)
@@ -470,14 +467,13 @@ static const struct v4l2_subdev_core_ops mt9v011_core_ops = {
};

static const struct v4l2_subdev_video_ops mt9v011_video_ops = {
	.try_mbus_fmt = mt9v011_try_mbus_fmt,
	.s_mbus_fmt = mt9v011_s_mbus_fmt,
	.g_parm = mt9v011_g_parm,
	.s_parm = mt9v011_s_parm,
};

static const struct v4l2_subdev_pad_ops mt9v011_pad_ops = {
	.enum_mbus_code = mt9v011_enum_mbus_code,
	.set_fmt = mt9v011_set_fmt,
};

static const struct v4l2_subdev_ops mt9v011_ops = {
+16 −11
Original line number Diff line number Diff line
@@ -971,17 +971,12 @@ static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
	return 0;
}

static int ov7670_try_mbus_fmt(struct v4l2_subdev *sd,
			    struct v4l2_mbus_framefmt *fmt)
{
	return ov7670_try_fmt_internal(sd, fmt, NULL, NULL);
}

/*
 * Set a format.
 */
static int ov7670_s_mbus_fmt(struct v4l2_subdev *sd,
			  struct v4l2_mbus_framefmt *fmt)
static int ov7670_set_fmt(struct v4l2_subdev *sd,
		struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *format)
{
	struct ov7670_format_struct *ovfmt;
	struct ov7670_win_size *wsize;
@@ -989,7 +984,18 @@ static int ov7670_s_mbus_fmt(struct v4l2_subdev *sd,
	unsigned char com7;
	int ret;

	ret = ov7670_try_fmt_internal(sd, fmt, &ovfmt, &wsize);
	if (format->pad)
		return -EINVAL;

	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
		ret = ov7670_try_fmt_internal(sd, &format->format, NULL, NULL);
		if (ret)
			return ret;
		cfg->try_fmt = format->format;
		return 0;
	}

	ret = ov7670_try_fmt_internal(sd, &format->format, &ovfmt, &wsize);

	if (ret)
		return ret;
@@ -1509,8 +1515,6 @@ static const struct v4l2_subdev_core_ops ov7670_core_ops = {
};

static const struct v4l2_subdev_video_ops ov7670_video_ops = {
	.try_mbus_fmt = ov7670_try_mbus_fmt,
	.s_mbus_fmt = ov7670_s_mbus_fmt,
	.s_parm = ov7670_s_parm,
	.g_parm = ov7670_g_parm,
};
@@ -1519,6 +1523,7 @@ static const struct v4l2_subdev_pad_ops ov7670_pad_ops = {
	.enum_frame_interval = ov7670_enum_frame_interval,
	.enum_frame_size = ov7670_enum_frame_size,
	.enum_mbus_code = ov7670_enum_mbus_code,
	.set_fmt = ov7670_set_fmt,
};

static const struct v4l2_subdev_ops ov7670_ops = {
+16 −12
Original line number Diff line number Diff line
@@ -574,10 +574,17 @@ static int saa6752hs_get_fmt(struct v4l2_subdev *sd,
	return 0;
}

static int saa6752hs_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
static int saa6752hs_set_fmt(struct v4l2_subdev *sd,
		struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *format)
{
	struct v4l2_mbus_framefmt *f = &format->format;
	struct saa6752hs_state *h = to_state(sd);
	int dist_352, dist_480, dist_720;

	if (format->pad)
		return -EINVAL;

	f->code = MEDIA_BUS_FMT_FIXED;

	dist_352 = abs(f->width - 352);
@@ -598,16 +605,12 @@ static int saa6752hs_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_frame
	}
	f->field = V4L2_FIELD_INTERLACED;
	f->colorspace = V4L2_COLORSPACE_SMPTE170M;

	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
		cfg->try_fmt = *f;
		return 0;
	}

static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
{
	struct saa6752hs_state *h = to_state(sd);

	if (f->code != MEDIA_BUS_FMT_FIXED)
		return -EINVAL;

	/*
	  FIXME: translate and round width/height into EMPRESS
	  subsample type:
@@ -620,7 +623,9 @@ static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
	  D1     | 720x576 | 720x480
	*/

	saa6752hs_try_mbus_fmt(sd, f);
	if (f->code != MEDIA_BUS_FMT_FIXED)
		return -EINVAL;

	if (f->width == 720)
		h->video_format = SAA6752HS_VF_D1;
	else if (f->width == 480)
@@ -653,12 +658,11 @@ static const struct v4l2_subdev_core_ops saa6752hs_core_ops = {

static const struct v4l2_subdev_video_ops saa6752hs_video_ops = {
	.s_std = saa6752hs_s_std,
	.s_mbus_fmt = saa6752hs_s_mbus_fmt,
	.try_mbus_fmt = saa6752hs_try_mbus_fmt,
};

static const struct v4l2_subdev_pad_ops saa6752hs_pad_ops = {
	.get_fmt = saa6752hs_get_fmt,
	.set_fmt = saa6752hs_set_fmt,
};

static const struct v4l2_subdev_ops saa6752hs_ops = {
+17 −22
Original line number Diff line number Diff line
@@ -153,14 +153,24 @@ static int reg_read(struct i2c_client *client, const u16 addr)
	return buf[0] & 0xff; /* no sign-extension */
}

static int imx074_try_fmt(struct v4l2_subdev *sd,
			  struct v4l2_mbus_framefmt *mf)
static int imx074_set_fmt(struct v4l2_subdev *sd,
		struct v4l2_subdev_pad_config *cfg,
		struct v4l2_subdev_format *format)
{
	struct v4l2_mbus_framefmt *mf = &format->format;
	const struct imx074_datafmt *fmt = imx074_find_datafmt(mf->code);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct imx074 *priv = to_imx074(client);

	if (format->pad)
		return -EINVAL;

	dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);

	if (!fmt) {
		/* MIPI CSI could have changed the format, double-check */
		if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
			return -EINVAL;
		mf->code	= imx074_colour_fmts[0].code;
		mf->colorspace	= imx074_colour_fmts[0].colorspace;
	}
@@ -169,24 +179,10 @@ static int imx074_try_fmt(struct v4l2_subdev *sd,
	mf->height	= IMX074_HEIGHT;
	mf->field	= V4L2_FIELD_NONE;

	return 0;
}

static int imx074_s_fmt(struct v4l2_subdev *sd,
			struct v4l2_mbus_framefmt *mf)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct imx074 *priv = to_imx074(client);

	dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);

	/* MIPI CSI could have changed the format, double-check */
	if (!imx074_find_datafmt(mf->code))
		return -EINVAL;

	imx074_try_fmt(sd, mf);

	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE)
		priv->fmt = imx074_find_datafmt(mf->code);
	else
		cfg->try_fmt = *mf;

	return 0;
}
@@ -282,8 +278,6 @@ static int imx074_g_mbus_config(struct v4l2_subdev *sd,

static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
	.s_stream	= imx074_s_stream,
	.s_mbus_fmt	= imx074_s_fmt,
	.try_mbus_fmt	= imx074_try_fmt,
	.g_crop		= imx074_g_crop,
	.cropcap	= imx074_cropcap,
	.g_mbus_config	= imx074_g_mbus_config,
@@ -296,6 +290,7 @@ static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
static const struct v4l2_subdev_pad_ops imx074_subdev_pad_ops = {
	.enum_mbus_code = imx074_enum_mbus_code,
	.get_fmt	= imx074_get_fmt,
	.set_fmt	= imx074_set_fmt,
};

static struct v4l2_subdev_ops imx074_subdev_ops = {
Loading