From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH v2 3/7] i2c: implement rescan
Date: Thu, 9 Mar 2023 16:54:21 +0100 [thread overview]
Message-ID: <20230309155421.GA15008@pengutronix.de> (raw)
In-Reply-To: <6968fd72-b0e4-dc92-9053-404086315a83@pengutronix.de>
On Thu, Mar 09, 2023 at 02:02:09PM +0100, Ahmad Fatoum wrote:
> On 09.03.23 12:52, Sascha Hauer wrote:
> > struct device::rescan is called by the core to let the subsystem rescan
> > the controllers device node. Implement that for I2C. Ahmad recently
> > implemented the struct device::detect hook for the very same purpose.
> > The downside of that approach was that device_detect() had to be called
> > manually and that either needs knowledge which device actually has
> > updated device nodes, or all devices were detected, like unrelated USB
> > or MMC/SD devices. The rescan hook doesn't need that manual detect call,
> > so just drop the I2C detect implementation in favour for implementing
> > rescan.
> >
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> > drivers/i2c/i2c.c | 20 +++++---------------
> > 1 file changed, 5 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> > index efcad29342..df89b8fb65 100644
> > --- a/drivers/i2c/i2c.c
> > +++ b/drivers/i2c/i2c.c
> > @@ -471,15 +471,7 @@ int of_i2c_register_devices_by_node(struct device_node *node)
> > return 0;
> > }
> >
> > -static int i2c_bus_detect(struct device *dev)
> > -{
> > - struct i2c_adapter *adap = container_of(dev, struct i2c_adapter, dev);
> > -
> > - of_i2c_register_devices(adap);
> > - return 0;
> > -}
> > -
> > -static int i2c_hw_detect(struct device *dev)
> > +static void i2c_hw_rescan(struct device *dev)
> > {
> > struct i2c_adapter *adap;
> >
> > @@ -489,8 +481,6 @@ static int i2c_hw_detect(struct device *dev)
> > of_i2c_register_devices(adap);
> > break;
> > }
> > -
> > - return 0;
> > }
> >
> > /**
> > @@ -720,7 +710,6 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
> > }
> >
> > adapter->dev.id = adapter->nr;
> > - adapter->dev.detect = i2c_bus_detect;
> > dev_set_name(&adapter->dev, "i2c");
> >
> > ret = register_device(&adapter->dev);
> > @@ -732,11 +721,12 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
> > /* populate children from any i2c device tables */
> > scan_boardinfo(adapter);
> >
> > + of_i2c_register_devices(adapter);
>
> I think this would fail for a non-OF I2C contoller on a CONFIG_OFTREE=y system,
> because the function doesn't guard against !CONFIG_OFTREE. Just move it into
> the if clause below.
This is not equivalent as of_i2c_register_devices() uses
adap->dev.of_node whereas the if clause below uses adapter->dev.parent->of_node.
Ideally this should be the same, but for now I think I'll just
revert to what has been done before the i2c_hw_detect patches
which adding a check in of_i2c_register_devices().
Sascha
>
> > +
> > hw_dev = adapter->dev.parent;
> > if (hw_dev && dev_of_node(hw_dev)) {
> > - if (!hw_dev->detect)
> > - hw_dev->detect = i2c_hw_detect;
> > - i2c_hw_detect(hw_dev);
> > + if (!hw_dev->rescan)
> > + hw_dev->rescan = i2c_hw_rescan;
> > }
> >
> > return 0;
>
> --
> 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 |
>
>
--
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 |
next prev parent reply other threads:[~2023-03-09 16:02 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-09 11:52 [PATCH v2 0/7] support overlays to the barebox live tree Sascha Hauer
2023-03-09 11:52 ` [PATCH v2 1/7] kbuild: Add target to build dtb overlay files Sascha Hauer
2023-03-09 13:24 ` Ahmad Fatoum
2023-03-09 15:28 ` Sascha Hauer
2023-03-09 15:33 ` Ahmad Fatoum
2023-03-09 15:35 ` Sascha Hauer
2023-03-09 11:52 ` [PATCH v2 2/7] driver: Add rescan hook to struct device Sascha Hauer
2023-03-09 12:54 ` Ahmad Fatoum
2023-03-09 13:39 ` Ahmad Fatoum
2023-03-09 13:08 ` Ahmad Fatoum
2023-03-09 15:41 ` Sascha Hauer
2023-03-10 8:37 ` Sascha Hauer
2023-03-09 11:52 ` [PATCH v2 3/7] i2c: implement rescan Sascha Hauer
2023-03-09 13:02 ` Ahmad Fatoum
2023-03-09 15:54 ` Sascha Hauer [this message]
2023-03-09 11:52 ` [PATCH v2 4/7] spi: Directly register SPI device Sascha Hauer
2023-03-09 11:52 ` [PATCH v2 5/7] spi: reduce scope of 'chip' Sascha Hauer
2023-03-09 11:52 ` [PATCH v2 6/7] spi: implement rescan Sascha Hauer
2023-03-09 13:03 ` Ahmad Fatoum
2023-03-09 11:52 ` [PATCH v2 7/7] of_overlay: Add option to apply overlay to live tree 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=20230309155421.GA15008@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=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