All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND v6,1/3] dt-bindings: i2c: support property idle-state
@ 2019-12-25 10:36 Biwen Li
  2019-12-25 10:36 ` [RESEND v6,2/3] i2c: mux: pca954x: " Biwen Li
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Biwen Li @ 2019-12-25 10:36 UTC (permalink / raw)
  To: peda, leoyang.li, robh+dt, mark.rutland
  Cc: linux-i2c, linux-kernel, devicetree, Biwen Li

This supports property idle-state

Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Biwen Li <biwen.li@nxp.com>
---
Change in v6:
	- add reviewed-by

Change in v5:
	- none

Change in v4:
	- none

Change in v3:
	- update subject and description
	- add some information for
  	  property idle-state

Change in v2:
	- update subject and description
	- add property idle-state

 Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt
index 30ac6a60f041..7abda506b828 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.txt
@@ -25,6 +25,8 @@ Required Properties:
 Optional Properties:
 
   - reset-gpios: Reference to the GPIO connected to the reset input.
+  - idle-state: if present, overrides i2c-mux-idle-disconnect,
+    Please refer to Documentation/devicetree/bindings/mux/mux-controller.txt
   - i2c-mux-idle-disconnect: Boolean; if defined, forces mux to disconnect all
     children in idle state. This is necessary for example, if there are several
     multiplexers on the bus and the devices behind them use same I2C addresses.
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RESEND v6,2/3] i2c: mux: pca954x: support property idle-state
  2019-12-25 10:36 [RESEND v6,1/3] dt-bindings: i2c: support property idle-state Biwen Li
@ 2019-12-25 10:36 ` Biwen Li
  2020-01-03 14:06   ` Peter Rosin
  2019-12-25 10:36 ` [RESEND v6,3/3] arm64: dts: fsl-ls208xa-rdb: fix an errata E-00013 Biwen Li
  2020-01-03 14:05 ` [RESEND v6,1/3] dt-bindings: i2c: support property idle-state Peter Rosin
  2 siblings, 1 reply; 6+ messages in thread
From: Biwen Li @ 2019-12-25 10:36 UTC (permalink / raw)
  To: peda, leoyang.li, robh+dt, mark.rutland
  Cc: linux-i2c, linux-kernel, devicetree, Biwen Li

This supports property idle-state,if present,
overrides i2c-mux-idle-disconnect.

My use cases:
	- Use the property idle-state to fix
	  an errata on LS2085ARDB and LS2088ARDB.
	- Errata id: E-00013(board LS2085ARDB and
	  LS2088ARDB revision on Rev.B, Rev.C and Rev.D).
	- About E-00013:
	  - Description: I2C1 and I2C3 buses
	    are missing pull-up.
	  - Impact: When the PCA954x device is tri-stated, the I2C bus
	    will float. This makes the I2C bus and its associated
	    downstream devices inaccessible.
	  - Hardware fix: Populate resistors R189 and R190 for I2C1
	    and resistors R228 and R229 for I2C3.
	  - Software fix: Remove the tri-state option from the PCA954x
	    driver(PCA954x always on enable status, specify a
	    channel zero in dts to fix the errata E-00013).

Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: Biwen Li <biwen.li@nxp.com>
---
Change in v6:
	- adjust log

Change in v5:
	- add extra precaution for pca954x_init 	

Change in v4:
	- rename function
	  pca954x_calculate_chan -> pca954x_regval

Change in v3:
	- update subject and description
	- add a helper function pca954x_calculate_chan()

Change in v2:
	- update subject and description
	- add property idle-state

 drivers/i2c/muxes/i2c-mux-pca954x.c | 69 +++++++++++++++++++----------
 1 file changed, 46 insertions(+), 23 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index cd8753b29a63..6577ec873f59 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -87,7 +87,7 @@ struct pca954x {
 
 	u8 last_chan;		/* last register value */
 	/* MUX_IDLE_AS_IS, MUX_IDLE_DISCONNECT or >= 0 for channel */
-	s8 idle_state;
+	s32 idle_state;
 
 	struct i2c_client *client;
 
@@ -237,20 +237,23 @@ static int pca954x_reg_write(struct i2c_adapter *adap,
 				I2C_SMBUS_BYTE, &dummy);
 }
 
+static u8 pca954x_regval(struct pca954x *data, u8 chan)
+{
+	/* We make switches look like muxes, not sure how to be smarter. */
+	if (data->chip->muxtype == pca954x_ismux)
+		return chan | data->chip->enable;
+	else
+		return 1 << chan;
+}
+
 static int pca954x_select_chan(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct pca954x *data = i2c_mux_priv(muxc);
 	struct i2c_client *client = data->client;
-	const struct chip_desc *chip = data->chip;
 	u8 regval;
 	int ret = 0;
 
-	/* we make switches look like muxes, not sure how to be smarter */
-	if (chip->muxtype == pca954x_ismux)
-		regval = chan | chip->enable;
-	else
-		regval = 1 << chan;
-
+	regval = pca954x_regval(data, chan);
 	/* Only select the channel if its different from the last channel */
 	if (data->last_chan != regval) {
 		ret = pca954x_reg_write(muxc->parent, client, regval);
@@ -264,7 +267,7 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
 {
 	struct pca954x *data = i2c_mux_priv(muxc);
 	struct i2c_client *client = data->client;
-	s8 idle_state;
+	s32 idle_state;
 
 	idle_state = READ_ONCE(data->idle_state);
 	if (idle_state >= 0)
@@ -410,6 +413,22 @@ static void pca954x_cleanup(struct i2c_mux_core *muxc)
 	i2c_mux_del_adapters(muxc);
 }
 
+static int pca954x_init(struct i2c_client *client, struct pca954x *data)
+{
+	int ret;
+	if (data->idle_state >= 0) {
+		data->last_chan = pca954x_regval(data, data->idle_state);
+	} else {
+		/* Disconnect multiplexer */
+		data->last_chan = 0;
+	}
+	ret = i2c_smbus_write_byte(client, data->last_chan);
+	if (ret < 0)
+		data->last_chan = 0;
+
+	return ret;
+}
+
 /*
  * I2C init/probing/exit functions
  */
@@ -419,7 +438,6 @@ static int pca954x_probe(struct i2c_client *client,
 	struct i2c_adapter *adap = client->adapter;
 	struct device *dev = &client->dev;
 	struct device_node *np = dev->of_node;
-	bool idle_disconnect_dt;
 	struct gpio_desc *gpio;
 	struct i2c_mux_core *muxc;
 	struct pca954x *data;
@@ -470,23 +488,24 @@ static int pca954x_probe(struct i2c_client *client,
 		}
 	}
 
-	/* Write the mux register at addr to verify
+	data->idle_state = MUX_IDLE_AS_IS;
+	if (of_property_read_u32(np, "idle-state", &data->idle_state)) {
+		if (np && of_property_read_bool(np, "i2c-mux-idle-disconnect"))
+			data->idle_state = MUX_IDLE_DISCONNECT;
+	}
+
+	/*
+	 * Write the mux register at addr to verify
 	 * that the mux is in fact present. This also
-	 * initializes the mux to disconnected state.
+	 * initializes the mux to a channel
+	 * or disconnected state.
 	 */
-	if (i2c_smbus_write_byte(client, 0) < 0) {
+	ret = pca954x_init(client, data);
+	if (ret < 0) {
 		dev_warn(dev, "probe failed\n");
 		return -ENODEV;
 	}
 
-	data->last_chan = 0;		   /* force the first selection */
-	data->idle_state = MUX_IDLE_AS_IS;
-
-	idle_disconnect_dt = np &&
-		of_property_read_bool(np, "i2c-mux-idle-disconnect");
-	if (idle_disconnect_dt)
-		data->idle_state = MUX_IDLE_DISCONNECT;
-
 	ret = pca954x_irq_setup(muxc);
 	if (ret)
 		goto fail_cleanup;
@@ -538,9 +557,13 @@ static int pca954x_resume(struct device *dev)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct i2c_mux_core *muxc = i2c_get_clientdata(client);
 	struct pca954x *data = i2c_mux_priv(muxc);
+	int ret;
 
-	data->last_chan = 0;
-	return i2c_smbus_write_byte(client, 0);
+	ret = pca954x_init(client, data);
+	if (ret < 0)
+		dev_err(&client->dev, "failed to verify the mux, the mux maybe not present in fact\n");
+
+	return ret;
 }
 #endif
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RESEND v6,3/3] arm64: dts: fsl-ls208xa-rdb: fix an errata E-00013
  2019-12-25 10:36 [RESEND v6,1/3] dt-bindings: i2c: support property idle-state Biwen Li
  2019-12-25 10:36 ` [RESEND v6,2/3] i2c: mux: pca954x: " Biwen Li
@ 2019-12-25 10:36 ` Biwen Li
  2020-01-03 14:09   ` Peter Rosin
  2020-01-03 14:05 ` [RESEND v6,1/3] dt-bindings: i2c: support property idle-state Peter Rosin
  2 siblings, 1 reply; 6+ messages in thread
From: Biwen Li @ 2019-12-25 10:36 UTC (permalink / raw)
  To: peda, leoyang.li, robh+dt, mark.rutland
  Cc: linux-i2c, linux-kernel, devicetree, Biwen Li

Specify a channel zero in idle state to
avoid enterring tri-stated state for PCA9547.
About E-00013:
	- Description: I2C1 and I2C3 buses
	  are missing pull-up.
	- Impact: When the PCA954x device is tri-stated, the I2C bus
	  will float. This makes the I2C bus and its associated
	  downstream devices inaccessible.
	- Hardware fix: Populate resistors R189 and R190 for I2C1
	  and resistors R228 and R229 for I2C3.
	- Software fix: Remove the tri-state option from the PCA954x
	  driver(PCA954x always on enable status, specify a
	  channel zero in dts to fix the errata E-00013).

Signed-off-by: Biwen Li <biwen.li@nxp.com>
---
Change in v6:
	- none

Change in v5:
	- specify a channel zero when pca9547 in idle state.

 arch/arm64/boot/dts/freescale/fsl-ls208xa-rdb.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls208xa-rdb.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls208xa-rdb.dtsi
index 6fd7f63085c9..412f1bc0db5f 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls208xa-rdb.dtsi
+++ b/arch/arm64/boot/dts/freescale/fsl-ls208xa-rdb.dtsi
@@ -49,6 +49,7 @@
 		reg = <0x75>;
 		#address-cells = <1>;
 		#size-cells = <0>;
+		idle-state = <0>;
 		i2c@1 {
 			#address-cells = <1>;
 			#size-cells = <0>;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RESEND v6,1/3] dt-bindings: i2c: support property idle-state
  2019-12-25 10:36 [RESEND v6,1/3] dt-bindings: i2c: support property idle-state Biwen Li
  2019-12-25 10:36 ` [RESEND v6,2/3] i2c: mux: pca954x: " Biwen Li
  2019-12-25 10:36 ` [RESEND v6,3/3] arm64: dts: fsl-ls208xa-rdb: fix an errata E-00013 Biwen Li
@ 2020-01-03 14:05 ` Peter Rosin
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Rosin @ 2020-01-03 14:05 UTC (permalink / raw)
  To: Biwen Li, leoyang.li, robh+dt, mark.rutland
  Cc: linux-i2c, linux-kernel, devicetree

On 2019-12-25 11:36, Biwen Li wrote:
> This supports property idle-state
> 
> Reviewed-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Biwen Li <biwen.li@nxp.com>

Pushed to i2c-mux/for-next

Cheers,
Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RESEND v6,2/3] i2c: mux: pca954x: support property idle-state
  2019-12-25 10:36 ` [RESEND v6,2/3] i2c: mux: pca954x: " Biwen Li
@ 2020-01-03 14:06   ` Peter Rosin
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Rosin @ 2020-01-03 14:06 UTC (permalink / raw)
  To: Biwen Li, leoyang.li, robh+dt, mark.rutland
  Cc: linux-i2c, linux-kernel, devicetree

On 2019-12-25 11:36, Biwen Li wrote:
> This supports property idle-state,if present,
> overrides i2c-mux-idle-disconnect.
> 
> My use cases:
> 	- Use the property idle-state to fix
> 	  an errata on LS2085ARDB and LS2088ARDB.
> 	- Errata id: E-00013(board LS2085ARDB and
> 	  LS2088ARDB revision on Rev.B, Rev.C and Rev.D).
> 	- About E-00013:
> 	  - Description: I2C1 and I2C3 buses
> 	    are missing pull-up.
> 	  - Impact: When the PCA954x device is tri-stated, the I2C bus
> 	    will float. This makes the I2C bus and its associated
> 	    downstream devices inaccessible.
> 	  - Hardware fix: Populate resistors R189 and R190 for I2C1
> 	    and resistors R228 and R229 for I2C3.
> 	  - Software fix: Remove the tri-state option from the PCA954x
> 	    driver(PCA954x always on enable status, specify a
> 	    channel zero in dts to fix the errata E-00013).
> 
> Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> Signed-off-by: Biwen Li <biwen.li@nxp.com>

Pushed to i2c-mux/for-next with some minor language tweaks.

Cheers,
Peter



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RESEND v6,3/3] arm64: dts: fsl-ls208xa-rdb: fix an errata E-00013
  2019-12-25 10:36 ` [RESEND v6,3/3] arm64: dts: fsl-ls208xa-rdb: fix an errata E-00013 Biwen Li
@ 2020-01-03 14:09   ` Peter Rosin
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Rosin @ 2020-01-03 14:09 UTC (permalink / raw)
  To: Biwen Li, leoyang.li, robh+dt, mark.rutland
  Cc: linux-i2c, linux-kernel, devicetree

On 2019-12-25 11:36, Biwen Li wrote:
> Specify a channel zero in idle state to
> avoid enterring tri-stated state for PCA9547.
> About E-00013:
> 	- Description: I2C1 and I2C3 buses
> 	  are missing pull-up.
> 	- Impact: When the PCA954x device is tri-stated, the I2C bus
> 	  will float. This makes the I2C bus and its associated
> 	  downstream devices inaccessible.
> 	- Hardware fix: Populate resistors R189 and R190 for I2C1
> 	  and resistors R228 and R229 for I2C3.
> 	- Software fix: Remove the tri-state option from the PCA954x
> 	  driver(PCA954x always on enable status, specify a
> 	  channel zero in dts to fix the errata E-00013).
> 
> Signed-off-by: Biwen Li <biwen.li@nxp.com>

For this patch, get_maintainer.pl suggests a few more recipients that
you need to seek reviews/acks from.

Cheers,
Peter

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-03 14:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-25 10:36 [RESEND v6,1/3] dt-bindings: i2c: support property idle-state Biwen Li
2019-12-25 10:36 ` [RESEND v6,2/3] i2c: mux: pca954x: " Biwen Li
2020-01-03 14:06   ` Peter Rosin
2019-12-25 10:36 ` [RESEND v6,3/3] arm64: dts: fsl-ls208xa-rdb: fix an errata E-00013 Biwen Li
2020-01-03 14:09   ` Peter Rosin
2020-01-03 14:05 ` [RESEND v6,1/3] dt-bindings: i2c: support property idle-state Peter Rosin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.