public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] dt-binding: Add custom property for MAX7357
@ 2023-08-30 11:57 Naresh Solanki
  2023-08-30 11:57 ` [PATCH 2/2] i2c: muxes: Enable features on MAX7357 Naresh Solanki
  2023-08-30 14:38 ` [PATCH 1/2] dt-binding: Add custom property for MAX7357 Krzysztof Kozlowski
  0 siblings, 2 replies; 7+ messages in thread
From: Naresh Solanki @ 2023-08-30 11:57 UTC (permalink / raw)
  To: Peter Rosin, Andi Shyti, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Laurent Pinchart
  Cc: Patrick Rudolph, Naresh Solanki, linux-i2c, devicetree,
	linux-kernel

From: Patrick Rudolph <patrick.rudolph@9elements.com>

Add a custom property "maxim,bus-lockup-fix" to enable proprietary
features on MAX7357. The driver configures MAX7357 to isolate the
failing channel and trigger a flush-out sequence for bus lock-up
resolution.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
 .../devicetree/bindings/i2c/i2c-mux-pca954x.yaml  | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
index 2d7bb998b0e9..984d4614a270 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
+++ b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
@@ -71,6 +71,11 @@ properties:
     description: A voltage regulator supplying power to the chip. On PCA9846
       the regulator supplies power to VDD2 (core logic) and optionally to VDD1.
 
+  maxim,bus-lockup-fix:
+    type: boolean
+    description: Isolates only the stuck channel and generates a flush-out sequence
+      to attempt to clear the bus lock-up.
+
 required:
   - compatible
   - reg
@@ -95,6 +100,16 @@ allOf:
         "#interrupt-cells": false
         interrupt-controller: false
 
+  - if:
+      not:
+        properties:
+          compatible:
+            contains:
+              const: maxim,max7357
+    then:
+      properties:
+        maxim,bus-lockup-fix: false
+
 unevaluatedProperties: false
 
 examples:

base-commit: f9ea75e087b81081f33e34c4e1ba8b4abe841d9f
-- 
2.41.0


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

* [PATCH 2/2] i2c: muxes: Enable features on MAX7357
  2023-08-30 11:57 [PATCH 1/2] dt-binding: Add custom property for MAX7357 Naresh Solanki
@ 2023-08-30 11:57 ` Naresh Solanki
  2023-09-02 18:42   ` Andi Shyti
  2023-08-30 14:38 ` [PATCH 1/2] dt-binding: Add custom property for MAX7357 Krzysztof Kozlowski
  1 sibling, 1 reply; 7+ messages in thread
From: Naresh Solanki @ 2023-08-30 11:57 UTC (permalink / raw)
  To: Peter Rosin; +Cc: Patrick Rudolph, Naresh Solanki, linux-i2c, linux-kernel

From: Patrick Rudolph <patrick.rudolph@9elements.com>

Detect that max7357 is being used and run custom init sequence.

By default MAX7357 disconnects all channels on a bus lock-up and
signals	this condition to the bus master using an interrupt.

Disable the interrupt as it's not useful within the kernel and
it might conflict with the reset functionality that shares the same
pin.

Use the introduced 'maxim,bus-lockup-fix' property to enable
faulty channel isolation and flush-out sequence generation.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
 drivers/i2c/muxes/i2c-mux-pca954x.c | 56 ++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 2219062104fb..0c1ff1438e7c 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -57,6 +57,21 @@
 
 #define PCA954X_IRQ_OFFSET 4
 
+/*
+ * MAX7357 exposes 7 registers on POR which allow to configure additional
+ * features. The configuration register holds the following settings:
+ */
+#define MAX7357_CONF_INT_ENABLE			BIT(0)
+#define MAX7357_CONF_FLUSH_OUT			BIT(1)
+#define MAX7357_CONF_RELEASE_INT		BIT(2)
+#define MAX7357_CONF_LOCK_UP_CLEAR		BIT(3)
+#define MAX7357_CONF_DISCON_SINGLE_CHAN		BIT(4)
+#define MAX7357_CONF_BUS_LOCKUP_DETECT_DIS	BIT(5)
+#define MAX7357_CONF_ENABLE_BASIC_MODE		BIT(6)
+#define MAX7357_CONF_PRECONNECT_TEST		BIT(7)
+
+#define MAX7357_POR_DEFAULT_CONF		BIT(0)
+
 enum pca_type {
 	max_7356,
 	max_7357,
@@ -477,6 +492,41 @@ static int pca954x_init(struct i2c_client *client, struct pca954x *data)
 	return ret;
 }
 
+static int max7357_init(struct i2c_client *client, struct pca954x *data)
+{
+	struct i2c_adapter *adap = client->adapter;
+	u8 conf = MAX7357_POR_DEFAULT_CONF;
+	int ret;
+
+	if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
+		return pca954x_init(client, data);
+
+	if (data->idle_state >= 0)
+		data->last_chan = pca954x_regval(data, data->idle_state);
+	else
+		data->last_chan = 0; /* Disconnect multiplexer */
+
+	/*
+	 * The interrupt signals downstream channels that are stuck, but
+	 * there's nothing to do and it prevents using the shared pin as reset.
+	 */
+	conf &= MAX7357_CONF_INT_ENABLE;
+
+	/*
+	 * On bus lock-up isolate the failing channel and try to clear the
+	 * fault by sending the flush-out sequence.
+	 */
+	if (device_property_read_bool(&client->dev, "maxim,bus-lockup-fix"))
+		conf |= MAX7357_CONF_DISCON_SINGLE_CHAN |
+			MAX7357_CONF_FLUSH_OUT;
+
+	ret = i2c_smbus_write_byte_data(client, data->last_chan, conf);
+	if (ret < 0)
+		data->last_chan = 0;
+
+	return ret;
+}
+
 /*
  * I2C init/probing/exit functions
  */
@@ -560,7 +610,11 @@ static int pca954x_probe(struct i2c_client *client)
 	 * initializes the mux to a channel
 	 * or disconnected state.
 	 */
-	ret = pca954x_init(client, data);
+	if ((dev->of_node && of_device_is_compatible(dev->of_node, "maxim,max7357")) ||
+	    id->driver_data == max_7357)
+		ret = max7357_init(client, data);
+	else
+		ret = pca954x_init(client, data);
 	if (ret < 0) {
 		dev_warn(dev, "probe failed\n");
 		ret = -ENODEV;
-- 
2.41.0


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

* Re: [PATCH 1/2] dt-binding: Add custom property for MAX7357
  2023-08-30 11:57 [PATCH 1/2] dt-binding: Add custom property for MAX7357 Naresh Solanki
  2023-08-30 11:57 ` [PATCH 2/2] i2c: muxes: Enable features on MAX7357 Naresh Solanki
@ 2023-08-30 14:38 ` Krzysztof Kozlowski
  2023-08-31  9:45   ` Naresh Solanki
  1 sibling, 1 reply; 7+ messages in thread
From: Krzysztof Kozlowski @ 2023-08-30 14:38 UTC (permalink / raw)
  To: Naresh Solanki, Peter Rosin, Andi Shyti, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Laurent Pinchart
  Cc: Patrick Rudolph, linux-i2c, devicetree, linux-kernel

On 30/08/2023 13:57, Naresh Solanki wrote:
> From: Patrick Rudolph <patrick.rudolph@9elements.com>
> 
> Add a custom property "maxim,bus-lockup-fix" to enable proprietary
> features on MAX7357. The driver configures MAX7357 to isolate the
> failing channel and trigger a flush-out sequence for bus lock-up
> resolution.

Please use subject prefixes matching the subsystem. You can get them for
example with `git log --oneline -- DIRECTORY_OR_FILE` on the directory
your patch is touching.

It is "dt-bindings" not binding and several other fields are needed.

Also "add custom property" is quite generic. When you add next custom
property you are going to have two commits with the same subject. Just
make it descriptive - "Add foobar for MAX7357"



> 
> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
> Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
> ---
>  .../devicetree/bindings/i2c/i2c-mux-pca954x.yaml  | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
> index 2d7bb998b0e9..984d4614a270 100644
> --- a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
> +++ b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
> @@ -71,6 +71,11 @@ properties:
>      description: A voltage regulator supplying power to the chip. On PCA9846
>        the regulator supplies power to VDD2 (core logic) and optionally to VDD1.
>  
> +  maxim,bus-lockup-fix:
> +    type: boolean
> +    description: Isolates only the stuck channel and generates a flush-out sequence
> +      to attempt to clear the bus lock-up.

Why wouldn't you want it to be enabled all the time? Why should it be
configurable per-board?

Best regards,
Krzysztof


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

* Re: [PATCH 1/2] dt-binding: Add custom property for MAX7357
  2023-08-30 14:38 ` [PATCH 1/2] dt-binding: Add custom property for MAX7357 Krzysztof Kozlowski
@ 2023-08-31  9:45   ` Naresh Solanki
  2023-08-31 12:01     ` Krzysztof Kozlowski
  0 siblings, 1 reply; 7+ messages in thread
From: Naresh Solanki @ 2023-08-31  9:45 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Peter Rosin, Andi Shyti, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Laurent Pinchart, Patrick Rudolph, linux-i2c,
	devicetree, linux-kernel

Hi

On Wed, 30 Aug 2023 at 20:08, Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 30/08/2023 13:57, Naresh Solanki wrote:
> > From: Patrick Rudolph <patrick.rudolph@9elements.com>
> >
> > Add a custom property "maxim,bus-lockup-fix" to enable proprietary
> > features on MAX7357. The driver configures MAX7357 to isolate the
> > failing channel and trigger a flush-out sequence for bus lock-up
> > resolution.
>
> Please use subject prefixes matching the subsystem. You can get them for
> example with `git log --oneline -- DIRECTORY_OR_FILE` on the directory
> your patch is touching.
Ack
>
> It is "dt-bindings" not binding and several other fields are needed.
Ack
>
> Also "add custom property" is quite generic. When you add next custom
> property you are going to have two commits with the same subject. Just
> make it descriptive - "Add foobar for MAX7357"
Missed Properties in this Patch Series, Will Be Addressed in V2.
So in that case I guess the below title should be fine?
dt-bindings: i2c: Add custom properties for MAX7357/MAX7358

>
>
>
> >
> > Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
> > Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
> > ---
> >  .../devicetree/bindings/i2c/i2c-mux-pca954x.yaml  | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
> > index 2d7bb998b0e9..984d4614a270 100644
> > --- a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
> > +++ b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
> > @@ -71,6 +71,11 @@ properties:
> >      description: A voltage regulator supplying power to the chip. On PCA9846
> >        the regulator supplies power to VDD2 (core logic) and optionally to VDD1.
> >
> > +  maxim,bus-lockup-fix:
> > +    type: boolean
> > +    description: Isolates only the stuck channel and generates a flush-out sequence
> > +      to attempt to clear the bus lock-up.
>
> Why wouldn't you want it to be enabled all the time? Why should it be
> configurable per-board?
The chip doesn't enable these features by default & it is left to
discretion of board designer to enable the same.

Regards,
Naresh
>
> Best regards,
> Krzysztof
>

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

* Re: [PATCH 1/2] dt-binding: Add custom property for MAX7357
  2023-08-31  9:45   ` Naresh Solanki
@ 2023-08-31 12:01     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2023-08-31 12:01 UTC (permalink / raw)
  To: Naresh Solanki
  Cc: Peter Rosin, Andi Shyti, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Laurent Pinchart, Patrick Rudolph, linux-i2c,
	devicetree, linux-kernel

On 31/08/2023 11:45, Naresh Solanki wrote:
> Hi
> 
> On Wed, 30 Aug 2023 at 20:08, Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>>
>> On 30/08/2023 13:57, Naresh Solanki wrote:
>>> From: Patrick Rudolph <patrick.rudolph@9elements.com>
>>>
>>> Add a custom property "maxim,bus-lockup-fix" to enable proprietary
>>> features on MAX7357. The driver configures MAX7357 to isolate the
>>> failing channel and trigger a flush-out sequence for bus lock-up
>>> resolution.
>>
>> Please use subject prefixes matching the subsystem. You can get them for
>> example with `git log --oneline -- DIRECTORY_OR_FILE` on the directory
>> your patch is touching.
> Ack
>>
>> It is "dt-bindings" not binding and several other fields are needed.
> Ack
>>
>> Also "add custom property" is quite generic. When you add next custom
>> property you are going to have two commits with the same subject. Just
>> make it descriptive - "Add foobar for MAX7357"
> Missed Properties in this Patch Series, Will Be Addressed in V2.
> So in that case I guess the below title should be fine?
> dt-bindings: i2c: Add custom properties for MAX7357/MAX7358

No, because you do not solve that part of my feedback:

>> Also "add custom property" is quite generic. When you add next custom
>> property you are going to have two commits with the same subject.

I said, everything will be now "add custom properties", right?

The prefix is dt-bindings: i2c: pca954x:



> 
>>
>>
>>
>>>
>>> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
>>> Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
>>> ---
>>>  .../devicetree/bindings/i2c/i2c-mux-pca954x.yaml  | 15 +++++++++++++++
>>>  1 file changed, 15 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
>>> index 2d7bb998b0e9..984d4614a270 100644
>>> --- a/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
>>> +++ b/Documentation/devicetree/bindings/i2c/i2c-mux-pca954x.yaml
>>> @@ -71,6 +71,11 @@ properties:
>>>      description: A voltage regulator supplying power to the chip. On PCA9846
>>>        the regulator supplies power to VDD2 (core logic) and optionally to VDD1.
>>>
>>> +  maxim,bus-lockup-fix:
>>> +    type: boolean
>>> +    description: Isolates only the stuck channel and generates a flush-out sequence
>>> +      to attempt to clear the bus lock-up.
>>
>> Why wouldn't you want it to be enabled all the time? Why should it be
>> configurable per-board?
> The chip doesn't enable these features by default & it is left to
> discretion of board designer to enable the same.


That does not explain anything. Enable them by default in such case or
come with some argument.

Best regards,
Krzysztof


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

* Re: [PATCH 2/2] i2c: muxes: Enable features on MAX7357
  2023-08-30 11:57 ` [PATCH 2/2] i2c: muxes: Enable features on MAX7357 Naresh Solanki
@ 2023-09-02 18:42   ` Andi Shyti
  2023-09-11  9:07     ` Naresh Solanki
  0 siblings, 1 reply; 7+ messages in thread
From: Andi Shyti @ 2023-09-02 18:42 UTC (permalink / raw)
  To: Naresh Solanki; +Cc: Peter Rosin, Patrick Rudolph, linux-i2c, linux-kernel

Hi Naresh,

On Wed, Aug 30, 2023 at 01:57:43PM +0200, Naresh Solanki wrote:
> From: Patrick Rudolph <patrick.rudolph@9elements.com>
> 
> Detect that max7357 is being used and run custom init sequence.
> 
> By default MAX7357 disconnects all channels on a bus lock-up and
> signals	this condition to the bus master using an interrupt.

please replace this tab with a space.

> Disable the interrupt as it's not useful within the kernel and
> it might conflict with the reset functionality that shares the same
> pin.
> 
> Use the introduced 'maxim,bus-lockup-fix' property to enable
> faulty channel isolation and flush-out sequence generation.
> 
> Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
> Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
> ---
>  drivers/i2c/muxes/i2c-mux-pca954x.c | 56 ++++++++++++++++++++++++++++-
>  1 file changed, 55 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
> index 2219062104fb..0c1ff1438e7c 100644
> --- a/drivers/i2c/muxes/i2c-mux-pca954x.c
> +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
> @@ -57,6 +57,21 @@
>  
>  #define PCA954X_IRQ_OFFSET 4
>  
> +/*
> + * MAX7357 exposes 7 registers on POR which allow to configure additional
> + * features. The configuration register holds the following settings:
> + */
> +#define MAX7357_CONF_INT_ENABLE			BIT(0)
> +#define MAX7357_CONF_FLUSH_OUT			BIT(1)
> +#define MAX7357_CONF_RELEASE_INT		BIT(2)
> +#define MAX7357_CONF_LOCK_UP_CLEAR		BIT(3)
> +#define MAX7357_CONF_DISCON_SINGLE_CHAN		BIT(4)
> +#define MAX7357_CONF_BUS_LOCKUP_DETECT_DIS	BIT(5)
> +#define MAX7357_CONF_ENABLE_BASIC_MODE		BIT(6)
> +#define MAX7357_CONF_PRECONNECT_TEST		BIT(7)

Not all these defines are are used, can we remove those that we
don't need?

> +#define MAX7357_POR_DEFAULT_CONF		BIT(0)

I think:

   #define MAX7357_POR_DEFAULT_CONF	MAX7357_CONF_INT_ENABLE

has a better meaning... but overall, do we need it?

> +
>  enum pca_type {
>  	max_7356,
>  	max_7357,
> @@ -477,6 +492,41 @@ static int pca954x_init(struct i2c_client *client, struct pca954x *data)
>  	return ret;
>  }
>  
> +static int max7357_init(struct i2c_client *client, struct pca954x *data)
> +{
> +	struct i2c_adapter *adap = client->adapter;
> +	u8 conf = MAX7357_POR_DEFAULT_CONF;
> +	int ret;
> +
> +	if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
> +		return pca954x_init(client, data);
> +
> +	if (data->idle_state >= 0)
> +		data->last_chan = pca954x_regval(data, data->idle_state);
> +	else
> +		data->last_chan = 0; /* Disconnect multiplexer */
> +
> +	/*
> +	 * The interrupt signals downstream channels that are stuck, but
> +	 * there's nothing to do and it prevents using the shared pin as reset.
> +	 */
> +	conf &= MAX7357_CONF_INT_ENABLE;
> +
> +	/*
> +	 * On bus lock-up isolate the failing channel and try to clear the
> +	 * fault by sending the flush-out sequence.
> +	 */
> +	if (device_property_read_bool(&client->dev, "maxim,bus-lockup-fix"))
> +		conf |= MAX7357_CONF_DISCON_SINGLE_CHAN |
> +			MAX7357_CONF_FLUSH_OUT;

this function is identical to pca954x_init() except for the
conf.

If you:

	u8 conf = 0;

	...

	if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
		conf &= MAX7357_CONF_INT_ENABLE;

		if (device_property_read_bool(&client->dev,
					      "maxim,bus-lockup-fix"))
			conf |= MAX7357_CONF_DISCON_SINGLE_CHAN |
				MAX7357_CONF_FLUSH_OUT;
	}

	ret = i2c_smbus_write_byte_data(client, data->last_chan, conf);
	...


You basically should obtain the same thing, I guess and we make
things easier.


> +	ret = i2c_smbus_write_byte_data(client, data->last_chan, conf);
> +	if (ret < 0)
> +		data->last_chan = 0;
> +	return ret;
> +}
> +
>  /*
>   * I2C init/probing/exit functions
>   */
> @@ -560,7 +610,11 @@ static int pca954x_probe(struct i2c_client *client)
>  	 * initializes the mux to a channel
>  	 * or disconnected state.
>  	 */
> -	ret = pca954x_init(client, data);
> +	if ((dev->of_node && of_device_is_compatible(dev->of_node, "maxim,max7357")) ||
> +	    id->driver_data == max_7357)
> +		ret = max7357_init(client, data);

what happens if this is true and in max7357_init(); the i2c
functionality check fails?

Which of the two if's is redundant? Should they be merged?

Andi

> +	else
> +		ret = pca954x_init(client, data);
>  	if (ret < 0) {
>  		dev_warn(dev, "probe failed\n");
>  		ret = -ENODEV;
> -- 
> 2.41.0
> 

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

* Re: [PATCH 2/2] i2c: muxes: Enable features on MAX7357
  2023-09-02 18:42   ` Andi Shyti
@ 2023-09-11  9:07     ` Naresh Solanki
  0 siblings, 0 replies; 7+ messages in thread
From: Naresh Solanki @ 2023-09-11  9:07 UTC (permalink / raw)
  To: Andi Shyti; +Cc: Peter Rosin, Patrick Rudolph, linux-i2c, linux-kernel

Hi Andy,


On Sun, 3 Sept 2023 at 00:13, Andi Shyti <andi.shyti@kernel.org> wrote:
>
> Hi Naresh,
>
> On Wed, Aug 30, 2023 at 01:57:43PM +0200, Naresh Solanki wrote:
> > From: Patrick Rudolph <patrick.rudolph@9elements.com>
> >
> > Detect that max7357 is being used and run custom init sequence.
> >
> > By default MAX7357 disconnects all channels on a bus lock-up and
> > signals       this condition to the bus master using an interrupt.
>
> please replace this tab with a space.
Ack
>
> > Disable the interrupt as it's not useful within the kernel and
> > it might conflict with the reset functionality that shares the same
> > pin.
> >
> > Use the introduced 'maxim,bus-lockup-fix' property to enable
> > faulty channel isolation and flush-out sequence generation.
> >
> > Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
> > Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
> > ---
> >  drivers/i2c/muxes/i2c-mux-pca954x.c | 56 ++++++++++++++++++++++++++++-
> >  1 file changed, 55 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
> > index 2219062104fb..0c1ff1438e7c 100644
> > --- a/drivers/i2c/muxes/i2c-mux-pca954x.c
> > +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
> > @@ -57,6 +57,21 @@
> >
> >  #define PCA954X_IRQ_OFFSET 4
> >
> > +/*
> > + * MAX7357 exposes 7 registers on POR which allow to configure additional
> > + * features. The configuration register holds the following settings:
> > + */
> > +#define MAX7357_CONF_INT_ENABLE                      BIT(0)
> > +#define MAX7357_CONF_FLUSH_OUT                       BIT(1)
> > +#define MAX7357_CONF_RELEASE_INT             BIT(2)
> > +#define MAX7357_CONF_LOCK_UP_CLEAR           BIT(3)
> > +#define MAX7357_CONF_DISCON_SINGLE_CHAN              BIT(4)
> > +#define MAX7357_CONF_BUS_LOCKUP_DETECT_DIS   BIT(5)
> > +#define MAX7357_CONF_ENABLE_BASIC_MODE               BIT(6)
> > +#define MAX7357_CONF_PRECONNECT_TEST         BIT(7)
>
> Not all these defines are are used, can we remove those that we
> don't need?
Ack. Will keep the ones that are used.
>
> > +#define MAX7357_POR_DEFAULT_CONF             BIT(0)
>
> I think:
>
>    #define MAX7357_POR_DEFAULT_CONF     MAX7357_CONF_INT_ENABLE
>
> has a better meaning... but overall, do we need it?
Ack. Will keep the ones that are in use.
>
> > +
> >  enum pca_type {
> >       max_7356,
> >       max_7357,
> > @@ -477,6 +492,41 @@ static int pca954x_init(struct i2c_client *client, struct pca954x *data)
> >       return ret;
> >  }
> >
> > +static int max7357_init(struct i2c_client *client, struct pca954x *data)
> > +{
> > +     struct i2c_adapter *adap = client->adapter;
> > +     u8 conf = MAX7357_POR_DEFAULT_CONF;
> > +     int ret;
> > +
> > +     if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
> > +             return pca954x_init(client, data);
> > +
> > +     if (data->idle_state >= 0)
> > +             data->last_chan = pca954x_regval(data, data->idle_state);
> > +     else
> > +             data->last_chan = 0; /* Disconnect multiplexer */
> > +
> > +     /*
> > +      * The interrupt signals downstream channels that are stuck, but
> > +      * there's nothing to do and it prevents using the shared pin as reset.
> > +      */
> > +     conf &= MAX7357_CONF_INT_ENABLE;
> > +
> > +     /*
> > +      * On bus lock-up isolate the failing channel and try to clear the
> > +      * fault by sending the flush-out sequence.
> > +      */
> > +     if (device_property_read_bool(&client->dev, "maxim,bus-lockup-fix"))
> > +             conf |= MAX7357_CONF_DISCON_SINGLE_CHAN |
> > +                     MAX7357_CONF_FLUSH_OUT;
>
> this function is identical to pca954x_init() except for the
> conf.
>
> If you:
>
>         u8 conf = 0;
>
>         ...
>
>         if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
>                 conf &= MAX7357_CONF_INT_ENABLE;
>
>                 if (device_property_read_bool(&client->dev,
>                                               "maxim,bus-lockup-fix"))
>                         conf |= MAX7357_CONF_DISCON_SINGLE_CHAN |
>                                 MAX7357_CONF_FLUSH_OUT;
>         }
>
>         ret = i2c_smbus_write_byte_data(client, data->last_chan, conf);
>         ...
>
>
> You basically should obtain the same thing, I guess and we make
> things easier.
Ack. Will do the changes as suggested.
Also based on feedback from Krzysztof, it was suggested that the dt
property might
not be needed & the settings can be configured/enabled by default. So
will remove
the DT property check ?

Ref: https://lore.kernel.org/lkml/9100e41b-291e-9723-4188-b4d3e5adb6f8@linaro.org/#t

Regards,
Naresh
>
>
> > +     ret = i2c_smbus_write_byte_data(client, data->last_chan, conf);
> > +     if (ret < 0)
> > +             data->last_chan = 0;
> > +     return ret;
> > +}
> > +
> >  /*
> >   * I2C init/probing/exit functions
> >   */
> > @@ -560,7 +610,11 @@ static int pca954x_probe(struct i2c_client *client)
> >        * initializes the mux to a channel
> >        * or disconnected state.
> >        */
> > -     ret = pca954x_init(client, data);
> > +     if ((dev->of_node && of_device_is_compatible(dev->of_node, "maxim,max7357")) ||
> > +         id->driver_data == max_7357)
> > +             ret = max7357_init(client, data);
>
> what happens if this is true and in max7357_init(); the i2c
> functionality check fails?
>
> Which of the two if's is redundant? Should they be merged?
>
> Andi
>
> > +     else
> > +             ret = pca954x_init(client, data);
> >       if (ret < 0) {
> >               dev_warn(dev, "probe failed\n");
> >               ret = -ENODEV;
> > --
> > 2.41.0
> >

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

end of thread, other threads:[~2023-09-11 20:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-30 11:57 [PATCH 1/2] dt-binding: Add custom property for MAX7357 Naresh Solanki
2023-08-30 11:57 ` [PATCH 2/2] i2c: muxes: Enable features on MAX7357 Naresh Solanki
2023-09-02 18:42   ` Andi Shyti
2023-09-11  9:07     ` Naresh Solanki
2023-08-30 14:38 ` [PATCH 1/2] dt-binding: Add custom property for MAX7357 Krzysztof Kozlowski
2023-08-31  9:45   ` Naresh Solanki
2023-08-31 12:01     ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox