mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: barebox@lists.infradead.org
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH 1/2] i2c: Added feature to get bus number from alias
Date: Fri, 14 Jul 2023 08:15:08 +0300	[thread overview]
Message-ID: <20230714051510.2304-2-eagle.alexander923@gmail.com> (raw)
In-Reply-To: <20230714051510.2304-1-eagle.alexander923@gmail.com>

For the correct assignment of the I2C bus number, let's use an alias
from the devicetree.

Signed-off-by: Alexander Shiyan <eagle.alexander923@gmail.com>
---
 drivers/i2c/i2c.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 300365bd1f..df3b968a4b 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -701,17 +701,21 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
 	int ret;
 
 	if (adapter->nr < 0) {
-		int nr;
+		if (!adapter->dev.of_node) {
+			int nr = adapter->dev.id;
 
-		for (nr = 0;; nr++)
-			if (!i2c_get_adapter(nr))
-				break;
-		adapter->nr = nr;
-	} else {
-		if (i2c_get_adapter(adapter->nr))
-			return -EBUSY;
+			for (nr = 0;; nr++)
+				if (!i2c_get_adapter(nr))
+					break;
+			adapter->nr = nr;
+		} else
+			adapter->nr =
+				of_alias_get_id(adapter->dev.of_node, "i2c");
 	}
 
+	if (i2c_get_adapter(adapter->nr))
+		return -EBUSY;
+
 	adapter->dev.id = adapter->nr;
 	dev_set_name(&adapter->dev, "i2c");
 
-- 
2.38.2




  reply	other threads:[~2023-07-14  5:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-14  5:15 [PATCH] .gitignore: Add generated scripts/rkimage to .gitignore Alexander Shiyan
2023-07-14  5:15 ` Alexander Shiyan [this message]
2023-07-26 11:55   ` [PATCH 1/2] i2c: Added feature to get bus number from alias Sascha Hauer
2023-07-14  5:15 ` [PATCH] mfd: rk808: Add missing RK809 chip ID to poweroff handler Alexander Shiyan
2023-07-14  5:15 ` [PATCH 2/2] i2c: rockchip: Get I2C bus number from devicetree alias 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=20230714051510.2304-2-eagle.alexander923@gmail.com \
    --to=eagle.alexander923@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