[PATCH 2/2] i2c-mux: create "channel-n" symlinks for child segments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For instance, by adding a pca9547 device with address 0x70 to
bus i2c-0, you get

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

Signed-off-by: Gerlando Falauto <gerlando.falauto@xxxxxxxxxxx>
---
 drivers/i2c/i2c-mux.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 01b8f8e..c984862 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -96,6 +96,7 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
 {
 	struct i2c_mux_priv *priv;
 	int ret;
+	char symlink_name[12];
 
 	priv = kzalloc(sizeof(struct i2c_mux_priv), GFP_KERNEL);
 	if (!priv)
@@ -142,6 +143,17 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
 	dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
 		 i2c_adapter_id(&priv->adap));
 
+	snprintf(symlink_name, sizeof(symlink_name), "channel-%d", chan_id);
+	ret = sysfs_create_link(&parent_device->kobj,
+				&priv->adap.dev.kobj,
+				symlink_name);
+	if (ret)
+		dev_err(parent_device, "Failed creating symlink %s\n",
+			symlink_name);
+	else
+		dev_info(parent_device, "Created symlink %s\n",
+			symlink_name);
+
 	return &priv->adap;
 }
 EXPORT_SYMBOL_GPL(i2c_add_mux_adapter);
@@ -150,6 +162,11 @@ int i2c_del_mux_adapter(struct i2c_adapter *adap)
 {
 	struct i2c_mux_priv *priv = adap->algo_data;
 	int ret;
+	char symlink_name[12];
+
+	snprintf(symlink_name, sizeof(symlink_name), "channel-%d", priv->chan_id);
+
+	sysfs_delete_link(&adap->dev.parent->kobj, &priv->adap.dev.kobj, symlink_name);
 
 	ret = i2c_del_adapter(adap);
 	if (ret < 0)
-- 
1.7.10.1

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux