[RFC,v6,13/13] media: i2c: max9286: [Workaround] 'device is bound'
diff mbox series

Message ID 20191216102930.5867-14-kieran.bingham+renesas@ideasonboard.com
State New
Delegated to: Kieran Bingham
Headers show
Series
  • GMSL Renesas Platform Support
Related show

Commit Message

Kieran Bingham Dec. 16, 2019, 10:29 a.m. UTC
From: Kieran Bingham <kieran.bingham@ideasonboard.com>

This introduces a local workaround to support multiple MAX9286 devices
on the same I2C bus.

Not for upstream consumption due to device_is_bound being an in kernel
symbol, and requires the module to be a built-in only.

Not-signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
 drivers/media/i2c/max9286.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 090b6c0f81e9..07d4489183f4 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -942,7 +942,7 @@  static int max9286_gpio(struct max9286_priv *priv)
 	return ret;
 }
 
-static int max9286_init(struct device *dev)
+static int max9286_init(struct device *dev, void *data)
 {
 	struct max9286_priv *priv;
 	struct i2c_client *client;
@@ -1056,6 +1056,25 @@  static int max9286_init(struct device *dev)
 	return ret;
 }
 
+static int max9286_is_bound(struct device *dev, void *data)
+{
+	struct device *this = data;
+	int ret;
+
+	if (dev == this)
+		return 0;
+
+	/* Skip non-max9286 devices. */
+	if (!dev->of_node || !of_match_node(max9286_dt_ids, dev->of_node))
+		return 0;
+
+	ret = device_is_bound(dev);
+	if (!ret)
+		return -EPROBE_DEFER;
+
+	return 0;
+}
+
 static void max9286_cleanup_dt(struct max9286_priv *priv)
 {
 	struct max9286_source *source;
@@ -1281,10 +1300,21 @@  static int max9286_probe(struct i2c_client *client)
 	/* Add any userspace support before we return early. */
 	max9286_debugfs_init(priv);
 
-	ret = max9286_init(&client->dev);
+	ret = device_for_each_child(client->dev.parent, &client->dev,
+				    max9286_is_bound);
+	if (ret)
+		return 0;
+
+	dev_dbg(&client->dev,
+		"All max9286 probed: start initialization sequence\n");
+	ret = device_for_each_child(client->dev.parent, NULL,
+				    max9286_init);
 	if (ret < 0)
 		goto err_regulator;
 
+	/* Leave the mux channels disabled until they are selected. */
+	max9286_i2c_mux_close(priv);
+
 	return 0;
 
 err_regulator: