Re: [PATCH v3 1/7] i2c: mux: add the ability to share mux address with child nodes

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

 



Le 11/06/2024 à 13:43, Farouk Bouabid a écrit :
Allow the mux (if it's an I2C device) to have the same address as a child
device. This is useful when the mux can only use an I2C address that is
used by a child device because no other addresses are free to use.
eg. the mux can only use address 0x18 which is used by amc6821 connected
to the mux.

Signed-off-by: Farouk Bouabid <farouk.bouabid@xxxxxxxxx>
---

Hi,

2 nitpicks below.

--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -334,7 +334,53 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
  	priv->adap.dev.parent = &parent->dev;
  	priv->adap.retries = parent->retries;
  	priv->adap.timeout = parent->timeout;
-	priv->adap.quirks = parent->quirks;
+
+	struct i2c_adapter_quirks *quirks;

Should this be at the beginning of the function?

+	/*
+	 * When creating the adapter, the node devices are checked for I2C address
+	 * match with other devices on the parent adapter, among which is the mux itself.
+	 * If a match is found the node device is not probed successfully.
+	 * Allow the mux to have the same address as a child device by skipping this check.
+	 */
+	if (muxc->share_addr_with_children) {
+		struct i2c_client *client = to_i2c_client(muxc->dev);
+
+		if (muxc->dev->type != &i2c_client_type)
+			dev_warn_once(muxc->dev, "Mux is not an I2C device\n");
+
+		quirks = devm_kzalloc(muxc->dev, sizeof(*quirks), GFP_KERNEL);
+		if (!quirks)
+			return -ENOMEM;
+
+		if (parent->quirks)
+			memcpy(quirks, parent->quirks, sizeof(*quirks));
+
+		quirks->flags |= I2C_AQ_SKIP_ADDR_CHECK;
+		quirks->skip_addr_in_parent = client->addr;
+		priv->adap.quirks = quirks;
+
+	} else if (parent->quirks &&
+		   parent->quirks->flags & I2C_AQ_SKIP_ADDR_CHECK) {
+		/*
+		 * Another I2C mux device can be a child of the Mule I2C mux.
+		 * The former could probably not allow address conflict between
+		 * its address and its own children addresses.
+		 *
+		 * For this purpose, do not propagate this flag unless
+		 * share_addr_with_children is set.
+		 */
+		quirks = devm_kzalloc(muxc->dev, sizeof(*quirks), GFP_KERNEL);

devm_kmemdup()? (not sure it is a win)

+		if (!quirks)
+			return -ENOMEM;
+
+		memcpy(quirks, parent->quirks, sizeof(*quirks));
+		quirks->flags &= ~I2C_AQ_SKIP_ADDR_CHECK;
+		priv->adap.quirks = quirks;
+
+	} else {
+		priv->adap.quirks = parent->quirks;
+	}
+
  	if (muxc->mux_locked)
  		priv->adap.lock_ops = &i2c_mux_lock_ops;
  	else

...

CJ




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux