[RFC PATCH 5/5] media: ov6650: Add .init_cfg() pad operation callback

From: Janusz Krzysztofik
Date: Sun May 26 2019 - 16:52:02 EST


The driver now supports V4L2_SUBDEV_FORMAT_TRY operation mode only in
.get/set_fmt() pad operation callbacks. That means only .try_format
member of pad config is maintained. As a consequence, active crop
rectangle is used as a referece while V4L2_SUBDEV_FORMAT_TRY requests
are processed. In order to fix that, a method for initialization of
.try_crop pad config member is needed.

Implement .init_cfg() pad operation callback which initializes the pad
config from current active format and selection settings. From now on,
and before the driver V4L2_SUBDEV_FORMAT_TRY support is further
modified, host interface drivers should call .init_cfg() on a pad
config before passing it to V4L2_SUBDEV_FORMAT_TRY operations.

Signed-off-by: Janusz Krzysztofik <jmkrzyszt@xxxxxxxxx>
---
drivers/media/i2c/ov6650.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c
index cc70d8952999..c3d4c1f598b2 100644
--- a/drivers/media/i2c/ov6650.c
+++ b/drivers/media/i2c/ov6650.c
@@ -447,6 +447,26 @@ static int ov6650_s_power(struct v4l2_subdev *sd, int on)
return ret;
}

+static int ov6650_init_cfg(struct v4l2_subdev *sd,
+ struct v4l2_subdev_pad_config *cfg)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct ov6650 *priv = to_ov6650(client);
+ struct v4l2_mbus_framefmt *mf;
+ struct v4l2_rect *rect;
+
+ mf = &cfg->try_fmt;
+ *mf = ov6650_def_fmt;
+ mf->width = priv->rect.width >> priv->half_scale;
+ mf->height = priv->rect.height >> priv->half_scale;
+ mf->code = priv->code;
+
+ rect = &cfg->try_crop;
+ *rect = priv->rect;
+
+ return 0;
+}
+
static int ov6650_get_selection(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_selection *sel)
@@ -959,6 +979,7 @@ static const struct v4l2_subdev_video_ops ov6650_video_ops = {
};

static const struct v4l2_subdev_pad_ops ov6650_pad_ops = {
+ .init_cfg = ov6650_init_cfg,
.enum_mbus_code = ov6650_enum_mbus_code,
.get_selection = ov6650_get_selection,
.set_selection = ov6650_set_selection,
--
2.21.0