devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa@the-dreams.de>
To: linux-i2c@vger.kernel.org
Cc: Wolfram Sang <wsa@the-dreams.de>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Bob Feretich <bob.feretich@rafresearch.com>,
	Jean Delvare <jdelvare@suse.de>,
	devicetree@vger.kernel.org
Subject: [PATCH 2/2] i2c: busses with dynamic ids should start after fixed ids for DT
Date: Thu, 12 Mar 2015 17:17:59 +0100	[thread overview]
Message-ID: <1426177093-26820-3-git-send-email-wsa@the-dreams.de> (raw)
In-Reply-To: <1426177093-26820-1-git-send-email-wsa@the-dreams.de>

Make sure dynamic ids do not interfere with fixed ones and let them
start after the highest fixed id. This patch might cause different
bus-numbers for dynamic ids, however it fixes a bug. Assume:

- fixed id0 defers probe
- fixed id1 succeeds and registers a muxed bus with dynamic id
- muxed bus gets id0
- fixed id0 wants to probe again, but its fixed id is gone now
- fixed id0 probe fails

With this patch, the fixed ids are always reserved in the DT case.
For legacy board init, we already have a mechanism like this in
i2c_register_board_info().

Reported-by: Bob Feretich <bob.feretich@rafresearch.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
---
 drivers/i2c/i2c-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 210cf4874cb7ea..4dda9a529f4464 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1878,6 +1878,14 @@ static int __init i2c_init(void)
 {
 	int retval;
 
+	retval = of_alias_get_highest_id("i2c");
+
+	down_write(&__i2c_board_lock);
+	if (retval >= __i2c_first_dynamic_bus_num) {
+		__i2c_first_dynamic_bus_num = retval + 1;
+	}
+	up_write(&__i2c_board_lock);
+
 	retval = bus_register(&i2c_bus_type);
 	if (retval)
 		return retval;
-- 
2.1.4

  parent reply	other threads:[~2015-03-12 16:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-12 16:17 [PATCH 0/2] i2c: prevent id collisions in the DT case Wolfram Sang
     [not found] ` <1426177093-26820-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2015-03-12 16:17   ` [PATCH 1/2] of: base: add function to get highest id of an alias stem Wolfram Sang
2015-03-12 21:35     ` Rob Herring
     [not found]     ` <1426177093-26820-2-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2015-03-18 12:46       ` Wolfram Sang
2015-03-28 13:20         ` Grant Likely
2015-03-12 16:17 ` Wolfram Sang [this message]
     [not found]   ` <1426177093-26820-3-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2015-03-18 12:46     ` [PATCH 2/2] i2c: busses with dynamic ids should start after fixed ids for DT Wolfram Sang

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=1426177093-26820-3-git-send-email-wsa@the-dreams.de \
    --to=wsa@the-dreams.de \
    --cc=bob.feretich@rafresearch.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).