mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] i2c: implement of_i2c_device_enable_and_register_by_alias()
Date: Mon,  5 Sep 2022 12:36:13 +0200	[thread overview]
Message-ID: <20220905103613.1750340-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220905103613.1750340-1-a.fatoum@pengutronix.de>

This new helper is the i2c equivalent of the existing
of_device_enable_and_register_by_alias(). That function isn't applicable
to i2c devices as it would create a platform device, but we need the
controller to create an i2c device instead.

This function was implemented for board code that uses an I2C EEPROM to
determine whether a specific I2C device is available on the same bus.
As reading the EEPROM requires the i2c controller be probed, there was
no way to reprobe the i2c controller children to create a device for the
previously disabled node. With of_i2c_register_devices_by_node(), this
is now possible and this helper makes it easier to use from board code.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/i2c/i2c.c | 13 +++++++++++++
 include/i2c/i2c.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index e70e51618850..40590b7d11be 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -597,6 +597,19 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
 	return to_i2c_client(dev);
 }
 
+int of_i2c_device_enable_and_register_by_alias(const char *alias)
+{
+	struct device_node *np;
+
+	np = of_find_node_by_alias(NULL, alias);
+	if (!np)
+		return -ENODEV;
+
+	of_device_enable(np);
+	return of_i2c_register_devices_by_node(np->parent);
+}
+
+
 static void i2c_parse_timing(struct device_d *dev, char *prop_name, u32 *cur_val_p,
 			    u32 def_val, bool use_def)
 {
diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index f5e2dc511ed1..e37a1770dc1e 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -297,6 +297,7 @@ struct i2c_adapter *i2c_get_adapter(int busnum);
 struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
 int of_i2c_register_devices_by_node(struct device_node *node);
 struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
+int of_i2c_device_enable_and_register_by_alias(const char *alias);
 
 void i2c_parse_fw_timings(struct device_d *dev, struct i2c_timings *t, bool use_defaults);
 
-- 
2.30.2




  reply	other threads:[~2022-09-05 17:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 10:36 [PATCH 1/2] i2c: implement of_i2c_register_devices_by_node() Ahmad Fatoum
2022-09-05 10:36 ` Ahmad Fatoum [this message]
2022-09-12  9:04 ` Sascha Hauer

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=20220905103613.1750340-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox