diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-09-05 12:36:13 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-09-12 11:03:59 +0200 |
commit | 2dc4f905ec49301d76a568697dd7e105fcf149be (patch) | |
tree | b7ef023a912a5a024304f67d318353e13fce6d8a /drivers | |
parent | 08be7406a4f6ff8be738ebb0c29c9da6519617cc (diff) | |
download | barebox-2dc4f905ec49301d76a568697dd7e105fcf149be.tar.gz barebox-2dc4f905ec49301d76a568697dd7e105fcf149be.tar.xz |
i2c: implement of_i2c_device_enable_and_register_by_alias()
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>
Link: https://lore.barebox.org/20220905103613.1750340-2-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/i2c.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index e70e516188..40590b7d11 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) { |