public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
	Gerlando Falauto
	<gerlando.falauto-SkAbAL50j+5BDgjK7y7TUQ@public.gmane.org>,
	Jean Delvare <jdelvare-l3A5Bk7waGM@public.gmane.org>,
	Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>,
	Martin Belanger
	<martin.belanger-Ir6+u9MVKBtBDgjK7y7TUQ@public.gmane.org>,
	Rodolfo Giometti
	<giometti-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>,
	Michael Lawnick <ml.lawnick-Mmb7MZpHnFY@public.gmane.org>,
	Jeroen De Wachter
	<jeroen.de.wachter-CNXmb7IdZIWZIoH1IeqzKA@public.gmane.org>
Subject: [PATCH] i2c: mux: create proper topology in sysfs
Date: Sun,  2 Nov 2014 21:40:09 +0100	[thread overview]
Message-ID: <1414960809-16860-1-git-send-email-wsa@the-dreams.de> (raw)

The current implementation creates muxed i2c-<n> busses as immediate
children of their i2c-<n> parent bus. In case of multiple muxes on one
bus, it is impossible to determine which muxed bus comes from which mux.

Change the topology so that they are created under the corresponding mux
device. This way, multiple muxes on the same segment can coexist and
children busses are grouped accordingly.

So for instance, by adding a pca9547 device with address 0x70 to
bus i2c-0, instead of:

/sys/class/i2c-dev/i2c-0/device/i2c-1
...
/sys/class/i2c-dev/i2c-0/device/i2c-8

we get:

/sys/class/i2c-dev/i2c-0/device/0-0070/i2c-1
...
/sys/class/i2c-dev/i2c-0/device/0-0070/i2c-8

Symlinks for backward compatibility are provided.

Signed-off-by: Gerlando Falauto <gerlando.falauto-SkAbAL50j+5BDgjK7y7TUQ@public.gmane.org>

[wsa: Ported to top-of-tree (1 line left :)) and added the compatibility
links.]
Signed-off-by: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Cc: Jean Delvare <jdelvare-l3A5Bk7waGM@public.gmane.org>
Cc: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
Cc: Martin Belanger <martin.belanger-Ir6+u9MVKBtBDgjK7y7TUQ@public.gmane.org>
Cc: Rodolfo Giometti <giometti-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org>
Cc: Michael Lawnick <ml.lawnick-Mmb7MZpHnFY@public.gmane.org>
Cc: Jeroen De Wachter <jeroen.de.wachter-CNXmb7IdZIWZIoH1IeqzKA@public.gmane.org>
---

So, this is what I came up with to fix the mux-topology problem. Since I don't
really use muxes, please review/comment/test. And give Acks/Tested-by tags if
this works for you.

 drivers/i2c/i2c-mux.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 2d0847b6be62..5b482ea32faf 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -138,7 +138,7 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
 	priv->adap.owner = THIS_MODULE;
 	priv->adap.algo = &priv->algo;
 	priv->adap.algo_data = priv;
-	priv->adap.dev.parent = &parent->dev;
+	priv->adap.dev.parent = mux_dev;
 	priv->adap.retries = parent->retries;
 	priv->adap.timeout = parent->timeout;
 
@@ -183,6 +183,9 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
 		return NULL;
 	}
 
+	WARN(sysfs_create_link(&parent->dev.kobj, &priv->adap.dev.kobj, priv->adap.dev.kobj.name),
+				"can't create compatibility link for old mux name scheme\n");
+
 	dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
 		 i2c_adapter_id(&priv->adap));
 
@@ -194,6 +197,7 @@ void i2c_del_mux_adapter(struct i2c_adapter *adap)
 {
 	struct i2c_mux_priv *priv = adap->algo_data;
 
+	sysfs_remove_link(&priv->parent->dev.kobj, adap->dev.kobj.name);
 	i2c_del_adapter(adap);
 	kfree(priv);
 }
-- 
2.1.1

             reply	other threads:[~2014-11-02 20:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02 20:40 Wolfram Sang [this message]
     [not found] ` <1414960809-16860-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2014-11-03 20:39   ` [PATCH] i2c: mux: create proper topology in sysfs Guenter Roeck
2014-11-03 20:55   ` Guenter Roeck
     [not found]     ` <20141103205534.GA18937-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2014-11-03 21:02       ` Wolfram Sang
2014-11-03 22:18         ` Guenter Roeck
     [not found]           ` <20141103221850.GA16026-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2014-11-04  7:33             ` Wolfram Sang
2014-11-04  9:07               ` Danielle Costantino
     [not found]                 ` <CAAVjN7dPet_nBHcQzPYknfiWnf1hD5d5NAJcrNEKKJHYHcBNkg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-10 20:57                   ` Jean Delvare
     [not found]                     ` <20141110215704.07d7ca1d-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2014-11-12 12:35                       ` Danielle Costantino
2014-11-04 14:16               ` Guenter Roeck
2014-11-03 22:49         ` Guenter Roeck
     [not found]           ` <20141103224908.GA18594-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2014-11-04 14:33             ` Wolfram Sang
2014-11-04 14:46               ` Guenter Roeck
2014-11-05 14:26               ` Guenter Roeck

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=1414960809-16860-1-git-send-email-wsa@the-dreams.de \
    --to=wsa-z923lk4zbo2bacvfa/9k2g@public.gmane.org \
    --cc=gerlando.falauto-SkAbAL50j+5BDgjK7y7TUQ@public.gmane.org \
    --cc=giometti-AVVDYK/kqiJWk0Htik3J/w@public.gmane.org \
    --cc=jdelvare-l3A5Bk7waGM@public.gmane.org \
    --cc=jeroen.de.wachter-CNXmb7IdZIWZIoH1IeqzKA@public.gmane.org \
    --cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=martin.belanger-Ir6+u9MVKBtBDgjK7y7TUQ@public.gmane.org \
    --cc=ml.lawnick-Mmb7MZpHnFY@public.gmane.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