From: Sascha Hauer <s.hauer@pengutronix.de>
To: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 05/23] i2c: Port of_find_i2c_device_by_node() from Linux
Date: Wed, 1 Apr 2020 07:46:57 +0200 [thread overview]
Message-ID: <20200401054657.GV27288@pengutronix.de> (raw)
In-Reply-To: <20200401052947.GU27288@pengutronix.de>
On Wed, Apr 01, 2020 at 07:29:47AM +0200, Sascha Hauer wrote:
> 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@gmail.com>
> > ---
> > 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.
This should do it:
--------------------------------8<--------------------------------
From 1437676f8cdf8fafd3269e364fc06f996acc0aad Mon Sep 17 00:00:00 2001
From: Andrey Smirnov <andrew.smirnov@gmail.com>
Date: Tue, 31 Mar 2020 11:47:04 -0700
Subject: [PATCH] i2c: Port of_find_i2c_device_by_node() from Linux
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@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@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 9df5ee70c7..2fed624d69 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -556,6 +556,19 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
return NULL;
}
+struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
+{
+ struct device_d *dev = of_find_device_by_node(node);
+
+ if (!dev)
+ return NULL;
+
+ if (dev->bus != &i2c_bus)
+ return NULL;
+
+ return to_i2c_client(dev);
+}
+
/**
* i2c_parse_fw_timings - get I2C related timing parameters from firmware
* @dev: The device to scan for I2C timing properties
diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index a694e4ab2f..56a887a13a 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -281,6 +281,7 @@ 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);
+struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
void i2c_parse_fw_timings(struct device_d *dev, struct i2c_timings *t, bool use_defaults);
--
2.26.0.rc2
--
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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-04-01 5:47 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-31 18:46 [PATCH 00/23] A number of ZII related fixes Andrey Smirnov
2020-03-31 18:47 ` [PATCH 01/23] ARM: zii-common: Gate rdu_i210_invm() call with CONFIG_PCI_IMX6 Andrey Smirnov
2020-04-01 5:20 ` Sascha Hauer
2020-04-01 19:47 ` Andrey Smirnov
2020-04-02 6:46 ` Sascha Hauer
2020-03-31 18:47 ` [PATCH 02/23] ARM: imx7d-zii-rpu2: Drop redundant chosen node Andrey Smirnov
2020-03-31 18:47 ` [PATCH 03/23] ARM: zii-imx7d-dev: Fix compatible name Andrey Smirnov
2020-03-31 18:47 ` [PATCH 04/23] ARM: zii-common: Check for I2C errors in do_rdu2_switch_reset() Andrey Smirnov
2020-04-01 5:23 ` Sascha Hauer
2020-03-31 18:47 ` [PATCH 05/23] i2c: Port of_find_i2c_device_by_node() from Linux Andrey Smirnov
2020-04-01 5:29 ` Sascha Hauer
2020-04-01 5:46 ` Sascha Hauer [this message]
2020-03-31 18:47 ` [PATCH 06/23] ARM: zii-common: Find switch watchdog via DT Andrey Smirnov
2020-03-31 18:47 ` [PATCH 07/23] ARM: zii-common: Support rave_switch_reset on ZII Ultra Andrey Smirnov
2020-03-31 18:47 ` [PATCH 08/23] ARM: zii-imx6q-rdu2: Differentiate between RDU2 and RDU2+ Andrey Smirnov
2020-03-31 18:47 ` [PATCH 09/23] ARM: zii-imx7d-dev: Differentiate between RPU2 and RMU2 Andrey Smirnov
2020-03-31 18:47 ` [PATCH 10/23] ARM: zii-imx8mq-dev: Differentiate between Zest and RMB3 Andrey Smirnov
2020-03-31 18:47 ` [PATCH 11/23] ARM: zii-common: Add common environment directory Andrey Smirnov
2020-04-02 6:49 ` Sascha Hauer
2020-04-02 22:27 ` Andrey Smirnov
2020-04-03 7:58 ` Sascha Hauer
2020-03-31 18:47 ` [PATCH 12/23] ARM: zii-imx6q-rdu2: Register SD card slot with BBU Andrey Smirnov
2020-03-31 18:47 ` [PATCH 13/23] ARM: zii-vf610-dev: " Andrey Smirnov
2020-03-31 18:47 ` [PATCH 14/23] ARM: zii-imx8mq-dev: " Andrey Smirnov
2020-03-31 18:47 ` [PATCH 15/23] ARM: zii-vf610-dev: Add newline to end of board.c Andrey Smirnov
2020-03-31 18:47 ` [PATCH 16/23] ARM: rdu2: Drop redundant USB GPIO hog nodes Andrey Smirnov
2020-03-31 18:47 ` [PATCH 17/23] ARM: imx8mq: Drop trailing whitespace Andrey Smirnov
2020-03-31 18:47 ` [PATCH 18/23] ARM: imx8mq: Drop redundant DT nodes Andrey Smirnov
2020-03-31 18:47 ` [PATCH 19/23] ARM: zii-imx8mq-dev: Add boot source info Andrey Smirnov
2020-03-31 18:47 ` [PATCH 20/23] ARM: zii-imx8mq-dev: Drop redundant "stdout-path" Andrey Smirnov
2020-03-31 18:47 ` [PATCH 21/23] ARM: zii-imx7d-dev: Drop redundant RMU2 .dtsi Andrey Smirnov
2020-03-31 18:47 ` [PATCH 22/23] ARM: zii-imx7d-rmu2: Add SPI NOR partition info Andrey Smirnov
2020-03-31 18:47 ` [PATCH 23/23] ARM: zii-imx7d-rmu2: Add boot source info Andrey Smirnov
2020-04-01 6:10 ` [PATCH 00/23] A number of ZII related fixes 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=20200401054657.GV27288@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=andrew.smirnov@gmail.com \
--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