mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/3] i2c: i2c: fix getting adapter.nr for I2C muxes
Date: Sun, 15 Dec 2024 10:54:11 +0100	[thread overview]
Message-ID: <20241215095412.3756337-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241215095412.3756337-1-a.fatoum@pengutronix.de>

When probed from device tree, "real" I2C controllers are virtual
devices that have the OF device as parent.

For those the current logic of using the alias of the parent
device's of_node works.

I2C muxes are different, because their parent device is the virtual
device of their controller. Using that controller's alias is often
destined to result in an -EBUSY:

  pca9450-i2c pca9450b0: PMIC Chip ID: 0x3
  ERROR: i2c1: failed to add mux-adapter (error=-16)
  ERROR: pca954x pca95450: failed to register multiplexed adapter0

As a single I2C mux can have multiple channels, there may also be just
one OF device for multiple virtual adapters. As all I2C adapters being
registered in barebox also have the of_node of the virtual device
populated, let's just consult that.

Fixes: b4746725454c ("i2c: get adapter.nr from device tree")
Reported-by: Alexander Shiyan <eagle.alexander923@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/i2c/i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index d19506af2627..017842f026dd 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -705,8 +705,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
 	struct device *hw_dev;
 	int ret;
 
-	if (adapter->nr < 0 && adapter->dev.parent && adapter->dev.parent->of_node)
-		adapter->nr = of_alias_get_id(adapter->dev.parent->of_node, "i2c");
+	if (adapter->nr < 0 && dev_of_node(&adapter->dev))
+		adapter->nr = of_alias_get_id(adapter->dev.of_node, "i2c");
 
 	if (adapter->nr < 0) {
 		int nr;
-- 
2.39.5




  reply	other threads:[~2024-12-15  9:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-15  9:54 [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Ahmad Fatoum
2024-12-15  9:54 ` Ahmad Fatoum [this message]
2024-12-15  9:54 ` [PATCH master 3/3] i2c: order dynamically numbered adapter after highest alias id Ahmad Fatoum
2024-12-16  7:16 ` [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Sascha Hauer
2024-12-17 13:04 ` Alexander Shiyan

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=20241215095412.3756337-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=eagle.alexander923@gmail.com \
    /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