All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
	"Jacopo Mondi" <jacopo.mondi@ideasonboard.com>,
	"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
	"Thomas Nizan" <tnizan@witekio.com>
Subject: [PATCH v3 10/12] media: i2c: max9286: Configure bus width from device tree
Date: Thu, 15 Dec 2022 01:38:23 +0200	[thread overview]
Message-ID: <20221214233825.13050-11-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <20221214233825.13050-1-laurent.pinchart+renesas@ideasonboard.com>

The GMSL serial data bus width is normally selected through the BWS pin.
On some systems, the pin may not be wired to the correct value. Support
overriding the bus width by software, using the value specified in the
device tree.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
---
Changes since v1:

- Add comment about the bus_width == 0 case
---
 drivers/media/i2c/max9286.c | 40 +++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index fffb0d2da416..125b4d434f57 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -91,6 +91,11 @@
 /* Register 0x1b */
 #define MAX9286_SWITCHIN(n)		(1 << ((n) + 4))
 #define MAX9286_ENEQ(n)			(1 << (n))
+/* Register 0x1c */
+#define MAX9286_HIGHIMM(n)		BIT((n) + 4)
+#define MAX9286_I2CSEL			BIT(2)
+#define MAX9286_HIBW			BIT(1)
+#define MAX9286_BWS			BIT(0)
 /* Register 0x27 */
 #define MAX9286_LOCKED			BIT(7)
 /* Register 0x31 */
@@ -183,6 +188,7 @@ struct max9286_priv {
 	u32 init_rev_chan_mv;
 	u32 rev_chan_mv;
 	u8 i2c_mstbt;
+	u32 bus_width;
 
 	bool use_gpio_poc;
 	u32 gpio_poc[2];
@@ -1168,6 +1174,23 @@ static int max9286_setup(struct max9286_priv *priv)
 	max9286_set_video_format(priv, &max9286_default_format);
 	max9286_set_fsync_period(priv);
 
+	if (priv->bus_width) {
+		int val;
+
+		val = max9286_read(priv, 0x1c);
+		if (val < 0)
+			return val;
+
+		val &= ~(MAX9286_HIBW | MAX9286_BWS);
+
+		if (priv->bus_width == 27)
+			val |= MAX9286_HIBW;
+		else if (priv->bus_width == 32)
+			val |= MAX9286_BWS;
+
+		max9286_write(priv, 0x1c, val);
+	}
+
 	/*
 	 * The overlap window seems to provide additional validation by tracking
 	 * the delay between vsync and frame sync, generating an error if the
@@ -1496,6 +1519,23 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 	}
 	of_node_put(node);
 
+	of_property_read_u32(dev->of_node, "maxim,bus-width", &priv->bus_width);
+	switch (priv->bus_width) {
+	case 0:
+		/*
+		 * The property isn't specified in the device tree, the driver
+		 * will keep the default value selected by the BWS pin.
+		 */
+	case 24:
+	case 27:
+	case 32:
+		break;
+	default:
+		dev_err(dev, "Invalid %s value %u\n", "maxim,bus-width",
+			priv->bus_width);
+		return -EINVAL;
+	}
+
 	of_property_read_u32(dev->of_node, "maxim,i2c-remote-bus-hz",
 			     &i2c_clk_freq);
 	for (i = 0; i < ARRAY_SIZE(max9286_i2c_speeds); ++i) {
-- 
Regards,

Laurent Pinchart


  parent reply	other threads:[~2022-12-14 23:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 23:38 [PATCH v3 00/12] media: i2c: max9286: Small new features Laurent Pinchart
2022-12-14 23:38 ` [PATCH v3 01/12] dt-bindings: media: i2c: max9286: Add support for per-port supplies Laurent Pinchart
2022-12-14 23:38 ` [PATCH v3 02/12] dt-bindings: media: i2c: max9286: Add property to select I2C speed Laurent Pinchart
2022-12-15 13:24   ` Rob Herring
2022-12-15 13:43     ` Laurent Pinchart
2022-12-15 16:22       ` Rob Herring
2022-12-15 16:46         ` Laurent Pinchart
2022-12-16  0:45   ` [PATCH v3.1 " Laurent Pinchart
2022-12-16 10:05     ` Jacopo Mondi
2022-12-14 23:38 ` [PATCH v3 03/12] dt-bindings: media: i2c: max9286: Add property to select bus width Laurent Pinchart
2022-12-14 23:38 ` [PATCH v3 04/12] media: i2c: max9286: Add support for port regulators Laurent Pinchart
2022-12-16  9:52   ` Jacopo Mondi
2022-12-19  2:03     ` Laurent Pinchart
2022-12-19  2:18   ` [PATCH v3.1 " Laurent Pinchart
2022-12-19  7:40     ` Jacopo Mondi
2022-12-14 23:38 ` [PATCH v3 05/12] media: i2c: max9286: Support manual framesync operation Laurent Pinchart
2022-12-14 23:38 ` [PATCH v3 06/12] media: i2c: max9286: Rename MAX9286_DATATYPE_RAW11 to RAW12 Laurent Pinchart
2022-12-14 23:38 ` [PATCH v3 07/12] media: i2c: max9286: Support 12-bit raw bayer formats Laurent Pinchart
2022-12-16  9:58   ` Jacopo Mondi
2022-12-14 23:38 ` [PATCH v3 08/12] media: i2c: max9286: Define macros for all bits of register 0x15 Laurent Pinchart
2022-12-14 23:38 ` [PATCH v3 09/12] media: i2c: max9286: Configure remote I2C speed from device tree Laurent Pinchart
2022-12-16 10:03   ` Jacopo Mondi
2022-12-14 23:38 ` Laurent Pinchart [this message]
2022-12-14 23:38 ` [PATCH v3 11/12] media: i2c: max9286: Select HS as data enable signal Laurent Pinchart
2022-12-14 23:38 ` [PATCH v3 12/12] media: i2c: max9286: Print power-up GMSL link configuration Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221214233825.13050-11-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas@ideasonboard.com \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=tnizan@witekio.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.