diff mbox series

[1/4] media: i2c: max9286: Initialize try formats

Message ID 20200817143540.247340-2-jacopo+renesas@jmondi.org (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series media: i2c: max9286: Use remote endpoint image format | expand

Commit Message

Jacopo Mondi Aug. 17, 2020, 2:35 p.m. UTC
Initialize try formats at device node open time by querying the
format from the remote subdevices instead of hard-coding it.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
---
 drivers/media/i2c/max9286.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

--
2.27.0

Comments

Sakari Ailus Aug. 18, 2020, 7:09 a.m. UTC | #1
Hi Jacopo,

On Mon, Aug 17, 2020 at 04:35:37PM +0200, Jacopo Mondi wrote:
> Initialize try formats at device node open time by querying the
> format from the remote subdevices instead of hard-coding it.

The try formats are expected to be device defaults and not dependent on
configuration.
Jacopo Mondi Aug. 18, 2020, 12:03 p.m. UTC | #2
Hi Sakari,

On Tue, Aug 18, 2020 at 10:09:10AM +0300, Sakari Ailus wrote:
> Hi Jacopo,
>
> On Mon, Aug 17, 2020 at 04:35:37PM +0200, Jacopo Mondi wrote:
> > Initialize try formats at device node open time by querying the
> > format from the remote subdevices instead of hard-coding it.
>
> The try formats are expected to be device defaults and not dependent on
> configuration.
>

The deserializer defaul depends on what is serialized on the other
end. I think getting it from the remote end makes sense in this case.

Thanks
   j

> --
> Sakari Ailus
diff mbox series

Patch

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 47f280518fdb..7c292f2e2704 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -794,12 +794,29 @@  static void max9286_init_format(struct v4l2_mbus_framefmt *fmt)

 static int max9286_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
 {
+	struct max9286_priv *priv = sd_to_max9286(subdev);
+	struct device *dev = &priv->client->dev;
 	struct v4l2_mbus_framefmt *format;
-	unsigned int i;
+	struct max9286_source *source;
+
+	for_each_source(priv, source) {
+		struct v4l2_subdev_pad_config remote_config = {};
+		unsigned int i = to_index(priv, source);
+		struct v4l2_subdev_format remote_fmt = {
+			.which = V4L2_SUBDEV_FORMAT_TRY,
+			.pad = 0,
+		};
+		int ret;

-	for (i = 0; i < MAX9286_N_SINKS; i++) {
 		format = v4l2_subdev_get_try_format(subdev, fh->pad, i);
-		max9286_init_format(format);
+		ret = v4l2_subdev_call(source->sd, pad, get_fmt, &remote_config,
+				       &remote_fmt);
+		if (ret) {
+			dev_err(dev, "Unable get format on source %u\n", i);
+			return ret;
+		}
+
+		*format = remote_fmt.format;
 	}

 	return 0;