From: Abdurrahman Hussain <abdurrahman@nexthop.ai>
Use i2c_add_numbered_adapter() to allow platform devices to specify
fixed bus numbers when needed.
Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
---
drivers/i2c/busses/i2c-xiic.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index eeb8ba8e131e..2c0470452221 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -1450,6 +1450,7 @@ static int xiic_i2c_probe(struct platform_device *pdev)
/* hook up driver to tree */
platform_set_drvdata(pdev, i2c);
i2c->adap = xiic_adapter;
+ i2c->adap.nr = pdev->id;
i2c_set_adapdata(&i2c->adap, i2c);
i2c->adap.dev.parent = dev;
device_set_node(&i2c->adap.dev, dev_fwnode(dev));
@@ -1506,7 +1507,7 @@ static int xiic_i2c_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret, "Cannot xiic_reinit\n");
/* add i2c adapter to i2c tree */
- ret = i2c_add_adapter(&i2c->adap);
+ ret = i2c_add_numbered_adapter(&i2c->adap);
if (ret) {
xiic_deinit(i2c);
return ret;
--
2.52.0
On Mon, Feb 02, 2026 at 08:37:23PM +0000, Abdurrahman Hussain via B4 Relay wrote: > Use i2c_add_numbered_adapter() to allow platform devices to specify > fixed bus numbers when needed. Not sure about this. Doesn't it break the current approach? Please, double check that. -- With Best Regards, Andy Shevchenko
> On Feb 3, 2026, at 7:45 AM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote: > > On Mon, Feb 02, 2026 at 08:37:23PM +0000, Abdurrahman Hussain via B4 Relay wrote: > >> Use i2c_add_numbered_adapter() to allow platform devices to specify >> fixed bus numbers when needed. > > Not sure about this. Doesn't it break the current approach? Please, double > check that. > > -- > With Best Regards, > Andy Shevchenko > > If pdev->id is PLATFORM_DEVID_NONE(-1) then i2c_add_numbered_adapter() falls back to dynamic allocation and calls i2c_add_adapter(). Many existing i2c drivers use the same approach, see i2c-pxa.c and i2c-pnx.c etc.
On Tue, Feb 03, 2026 at 10:14:49AM -0800, Abdurrahman Hussain wrote:
>
>
> > On Feb 3, 2026, at 7:45 AM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> >
> > On Mon, Feb 02, 2026 at 08:37:23PM +0000, Abdurrahman Hussain via B4 Relay wrote:
> >
> >> Use i2c_add_numbered_adapter() to allow platform devices to specify
> >> fixed bus numbers when needed.
> >
> > Not sure about this. Doesn't it break the current approach? Please, double
> > check that.
> >
> > --
> > With Best Regards,
> > Andy Shevchenko
> >
> >
>
> If pdev->id is PLATFORM_DEVID_NONE(-1) then i2c_add_numbered_adapter()
> falls back to dynamic allocation and calls i2c_add_adapter().
>
> Many existing i2c drivers use the same approach, see i2c-pxa.c and
> i2c-pnx.c etc.
It is not about if other drivers do this. Its about does this change
the behaviour of this driver, so that I2C busses get different IDs
then before, and so cause regressions?
You need to explain in the commit message why you think this is safe.
Andrew
> On Feb 3, 2026, at 10:31 AM, Andrew Lunn <andrew@lunn.ch> wrote: > > On Tue, Feb 03, 2026 at 10:14:49AM -0800, Abdurrahman Hussain wrote: >> >> >>> On Feb 3, 2026, at 7:45 AM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote: >>> >>> On Mon, Feb 02, 2026 at 08:37:23PM +0000, Abdurrahman Hussain via B4 Relay wrote: >>> >>>> Use i2c_add_numbered_adapter() to allow platform devices to specify >>>> fixed bus numbers when needed. >>> >>> Not sure about this. Doesn't it break the current approach? Please, double >>> check that. >>> >>> -- >>> With Best Regards, >>> Andy Shevchenko >>> >>> >> >> If pdev->id is PLATFORM_DEVID_NONE(-1) then i2c_add_numbered_adapter() >> falls back to dynamic allocation and calls i2c_add_adapter(). >> >> Many existing i2c drivers use the same approach, see i2c-pxa.c and >> i2c-pnx.c etc. > > It is not about if other drivers do this. Its about does this change > the behaviour of this driver, so that I2C busses get different IDs > then before, and so cause regressions? > > You need to explain in the commit message why you think this is safe. > > Andrew Before, the driver was always doing the dynamic allocation due to i2c_add_adapter(). So there could not have been a system that relied on consistent i2c bus numbering. Even between reboots bus numbering could change. The systems that did set pdev->id and were expecting a consistent i2c bus numbering were broken to begin with. This patch won’t break any existing systems or cause regressions.
> On Feb 3, 2026, at 10:50 AM, Abdurrahman Hussain <abdurrahman@nexthop.ai> wrote: > > > >> On Feb 3, 2026, at 10:31 AM, Andrew Lunn <andrew@lunn.ch> wrote: >> >> On Tue, Feb 03, 2026 at 10:14:49AM -0800, Abdurrahman Hussain wrote: >>> >>> >>>> On Feb 3, 2026, at 7:45 AM, Andy Shevchenko <andriy.shevchenko@intel.com> wrote: >>>> >>>> On Mon, Feb 02, 2026 at 08:37:23PM +0000, Abdurrahman Hussain via B4 Relay wrote: >>>> >>>>> Use i2c_add_numbered_adapter() to allow platform devices to specify >>>>> fixed bus numbers when needed. >>>> >>>> Not sure about this. Doesn't it break the current approach? Please, double >>>> check that. >>>> >>>> -- >>>> With Best Regards, >>>> Andy Shevchenko >>>> >>>> >>> >>> If pdev->id is PLATFORM_DEVID_NONE(-1) then i2c_add_numbered_adapter() >>> falls back to dynamic allocation and calls i2c_add_adapter(). >>> >>> Many existing i2c drivers use the same approach, see i2c-pxa.c and >>> i2c-pnx.c etc. >> >> It is not about if other drivers do this. Its about does this change >> the behaviour of this driver, so that I2C busses get different IDs >> then before, and so cause regressions? >> >> You need to explain in the commit message why you think this is safe. >> >> Andrew > > Before, the driver was always doing the dynamic allocation due to > i2c_add_adapter(). So there could not have been a system that relied on > consistent i2c bus numbering. Even between reboots bus numbering could change. > > The systems that did set pdev->id and were expecting a consistent i2c bus > numbering were broken to begin with. > > This patch won’t break any existing systems or cause regressions. > I can add the following to the commit if you find the wording acceptable: Previously, the i2c bus numbers were dynamically allocated because of the use of the i2c_add_adapter() call. This meant there were no guarantees about consistent bus numbering. However, with this change, on systems that don’t set their platform device ID and leave it at the default PLATFORM_DEVID_NONE, the bus numbers will still be dynamically allocated because of the check in i2c_add_numbered_adapter(). Therefore there won’t be any change in behavior.
> Before, the driver was always doing the dynamic allocation due to
> i2c_add_adapter(). So there could not have been a system that relied on
> consistent i2c bus numbering. Even between reboots bus numbering could change.
>
> The systems that did set pdev->id and were expecting a consistent i2c bus
> numbering were broken to begin with.
>
> This patch won’t break any existing systems or cause regressions.
Great, now please add that to the commit message. These are the sort
of things reviewers want to know, is a change going to cause
regressions. If you have done your homework, mentioning it in the
commit message will help avoid the questions being asked.
Andrew
© 2016 - 2026 Red Hat, Inc.