diff mbox

[v3,1/2] i2c: mux: create symlink to actual mux device

Message ID 1415885996-14770-1-git-send-email-wsa@the-dreams.de
State Accepted
Headers show

Commit Message

Wolfram Sang Nov. 13, 2014, 1:39 p.m. UTC
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.

It could be argued that the parent device should be changed from the
parent adapter to the mux device. This has pros and cons. To improve the
topology, simply add a "muxed_device" symlink pointing to the actual
muxing device, so we can distinguish muxed busses. Doing it this way, we
don't break the ABI.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Cc: Jean Delvare <jdelvare@suse.de>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Martin Belanger <martin.belanger@cyaninc.com>
Cc: Rodolfo Giometti <giometti@enneenne.com>
Cc: Michael Lawnick <ml.lawnick@gmx.de>
Cc: Jeroen De Wachter <jeroen.de.wachter@telenet.be>
Cc: Gerlando Falauto <gerlando.falauto@keymile.com>
---
 drivers/i2c/i2c-mux.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Guenter Roeck Nov. 14, 2014, 3:55 a.m. UTC | #1
On 11/13/2014 05:39 AM, Wolfram Sang wrote:
> 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.
>
> It could be argued that the parent device should be changed from the
> parent adapter to the mux device. This has pros and cons. To improve the
> topology, simply add a "muxed_device" symlink pointing to the actual
> muxing device, so we can distinguish muxed busses. Doing it this way, we
> don't break the ABI.
>
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
> Cc: Jean Delvare <jdelvare@suse.de>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: Martin Belanger <martin.belanger@cyaninc.com>
> Cc: Rodolfo Giometti <giometti@enneenne.com>
> Cc: Michael Lawnick <ml.lawnick@gmx.de>
> Cc: Jeroen De Wachter <jeroen.de.wachter@telenet.be>
> Cc: Gerlando Falauto <gerlando.falauto@keymile.com>

This version works for me and passes testing with our application code.

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/i2c/i2c-mux.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index 2d0847b6be62..f246a9f7dd22 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -183,6 +183,9 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
>   		return NULL;
>   	}
>
> +	WARN(sysfs_create_link(&priv->adap.dev.kobj, &mux_dev->kobj, "mux_device"),
> +			       "can't create symlink to mux device\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->adap.dev.kobj, "mux_device");
>   	i2c_del_adapter(adap);
>   	kfree(priv);
>   }
>

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
jeroen.de.wachter@telenet.be Nov. 14, 2014, 10:01 a.m. UTC | #2
Hey guys,

It's been a while since I contacted you about this issue and I know I haven't been helping to solve it (because there were/are more pressing issues, as usual).

We're working with an older kernel here and have found a way of working around this issue (there's only one application adding muxes, so I'm scanning the i2c busses before and after adding the mux to figure out which busses were added by the new mux). Our solution works for the moment (although it's not as clean, obviously), so I don't think we'll be backporting the changes, but it's nice to know it's being solved. If we ever switch to a kernel that has these changes, we can do a better job with our application :-)

I justed wanted to say thank you for keeping me in the loop :-)

Regards,
Jeroen


----- Original Message -----
From: "Guenter Roeck" <linux@roeck-us.net>
To: "Wolfram Sang" <wsa@the-dreams.de>, linux-i2c@vger.kernel.org
Cc: "Jean Delvare" <jdelvare@suse.de>, "Martin Belanger" <martin.belanger@cyaninc.com>, "Rodolfo Giometti" <giometti@enneenne.com>, "Michael Lawnick" <ml.lawnick@gmx.de>, "Jeroen De Wachter" <jeroen.de.wachter@telenet.be>, "Gerlando Falauto" <gerlando.falauto@keymile.com>
Sent: Friday, November 14, 2014 4:55:45 AM
Subject: Re: [PATCH v3 1/2] i2c: mux: create symlink to actual mux device

On 11/13/2014 05:39 AM, Wolfram Sang wrote:
> 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.
>
> It could be argued that the parent device should be changed from the
> parent adapter to the mux device. This has pros and cons. To improve the
> topology, simply add a "muxed_device" symlink pointing to the actual
> muxing device, so we can distinguish muxed busses. Doing it this way, we
> don't break the ABI.
>
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
> Cc: Jean Delvare <jdelvare@suse.de>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: Martin Belanger <martin.belanger@cyaninc.com>
> Cc: Rodolfo Giometti <giometti@enneenne.com>
> Cc: Michael Lawnick <ml.lawnick@gmx.de>
> Cc: Jeroen De Wachter <jeroen.de.wachter@telenet.be>
> Cc: Gerlando Falauto <gerlando.falauto@keymile.com>

This version works for me and passes testing with our application code.

Tested-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/i2c/i2c-mux.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index 2d0847b6be62..f246a9f7dd22 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -183,6 +183,9 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
>   		return NULL;
>   	}
>
> +	WARN(sysfs_create_link(&priv->adap.dev.kobj, &mux_dev->kobj, "mux_device"),
> +			       "can't create symlink to mux device\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->adap.dev.kobj, "mux_device");
>   	i2c_del_adapter(adap);
>   	kfree(priv);
>   }
>

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang Nov. 14, 2014, 11:32 a.m. UTC | #3
> I justed wanted to say thank you for keeping me in the loop :-)

You are welcome. And even if you don't test/backport the changes, you
can still donate an Acked-by: if you think the patches are useful and
going to the right direction. If not, then not :)

Thanks,

   Wolfram
Wolfram Sang Nov. 18, 2014, 3:11 p.m. UTC | #4
On Thu, Nov 13, 2014 at 02:39:55PM +0100, Wolfram Sang wrote:
> 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.
> 
> It could be argued that the parent device should be changed from the
> parent adapter to the mux device. This has pros and cons. To improve the
> topology, simply add a "muxed_device" symlink pointing to the actual
> muxing device, so we can distinguish muxed busses. Doing it this way, we
> don't break the ABI.
> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
> Cc: Jean Delvare <jdelvare@suse.de>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: Martin Belanger <martin.belanger@cyaninc.com>
> Cc: Rodolfo Giometti <giometti@enneenne.com>
> Cc: Michael Lawnick <ml.lawnick@gmx.de>
> Cc: Jeroen De Wachter <jeroen.de.wachter@telenet.be>
> Cc: Gerlando Falauto <gerlando.falauto@keymile.com>

Applied to for-next, thanks!
diff mbox

Patch

diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 2d0847b6be62..f246a9f7dd22 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -183,6 +183,9 @@  struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
 		return NULL;
 	}
 
+	WARN(sysfs_create_link(&priv->adap.dev.kobj, &mux_dev->kobj, "mux_device"),
+			       "can't create symlink to mux device\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->adap.dev.kobj, "mux_device");
 	i2c_del_adapter(adap);
 	kfree(priv);
 }