Re: [PATCH 05/23] i2c: Port of_find_i2c_device_by_node() from Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 31, 2020 at 11:47:04AM -0700, Andrey Smirnov wrote:
> Port of_find_i2c_device_by_node() from Linux in order to allow looking
> i2c_client up by corresponding DT node. Useful for interacting with
> identical raw/driverless I2C devices that are not found on the same
> bus between board variants.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
> ---
>  include/i2c/i2c.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
> index a694e4ab2..7eaa97dde 100644
> --- a/include/i2c/i2c.h
> +++ b/include/i2c/i2c.h
> @@ -281,6 +281,14 @@ static inline int i2c_register_board_info(int busnum,
>  extern int i2c_add_numbered_adapter(struct i2c_adapter *adapter);
>  struct i2c_adapter *i2c_get_adapter(int busnum);
>  struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
> +static inline struct i2c_client *
> +of_find_i2c_device_by_node(struct device_node *node)
> +{
> +	struct device_d *dev = of_find_device_by_node(node);
> +
> +	return dev ? to_i2c_client(dev) : NULL;
> +}

Can we have a sanity check if this is actually a I2C device? At least
a test for dev->bus == &i2c_bus would be nice.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux