Skip to contentSkip to conversation

Add reset-gpios handling for max98927

PATCH Superseded Alejandro 4 participants 11 messages Sep 3, 2021

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Alejandro

author
#0 lore raw

v3 cover Add reset-gpios handling for max98927

The max98927 codec on some devices (i.e. Xiaomi Mi A2 Lite phone) require hardware-resetting the codec by driving a reset-gpio. This series add support for it through an optional reset-gpios property.

Alejandro Tafalla (2):
ASoC: max98927: Handle reset gpio when probing i2c
dt-bindings: sound: max98927: Add reset-gpios optional property

 .../devicetree/bindings/sound/max9892x.txt         |  3 +++
 sound/soc/codecs/max98927.c                        | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
Signature · 1 line
2.33.0
author
#1 lore raw

PATCH v3 1/2 ASoC: max98927: Handle reset gpio when probing i2c

From: Alejandro Tafalla <[email protected]>

Drive the reset gpio if defined in the DTS node.

---
 sound/soc/codecs/max98927.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
sound/soc/codecs/max98927.c +14 -0
index 8b206ee77709..daf06b503433 100644
@@ -868,6 +868,7 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
 	int ret = 0, value;
 	int reg = 0;
 	struct max98927_priv *max98927 = NULL;
+	struct gpio_desc *reset_gpio;
 
 	max98927 = devm_kzalloc(&i2c->dev,
 		sizeof(*max98927), GFP_KERNEL);
@@ -898,6 +899,19 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
+	reset_gpio
+		= devm_gpiod_get_optional(&i2c->dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR(reset_gpio)) {
+		ret = PTR_ERR(reset_gpio);
+		return dev_err_probe(&i2c->dev, ret, "failed to request GPIO reset pin");
+	}
+
+	if (reset_gpio) {
+		usleep_range(8000, 10000);
+		gpiod_set_value_cansleep(reset_gpio, 1);
+		usleep_range(1000, 5000);
+	}
+
 	/* Check Revision ID */
 	ret = regmap_read(max98927->regmap,
 		MAX98927_R01FF_REV_ID, &reg);
Signature · 1 line
2.33.0
author
#6 lore raw

PATCH v3 2/2 dt-bindings: sound: max98927: Add reset-gpios optional property

In reply to Alejandro

From: Alejandro Tafalla <[email protected]>

Add the reset-gpios as an optional property because some devices might not need it to work properly.

---
 Documentation/devicetree/bindings/sound/max9892x.txt | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/sound/max9892x.txt +3 -0
index f6171591ddc6..98cb9ba5b328 100644
@@ -30,6 +30,9 @@ Required properties:
 
   - reg : the I2C address of the device for I2C
 
+Optional properties:
+  - reset-gpios : GPIO to reset the device
+
 Example:
 
 codec: max98927@3a {
Signature · 1 line
2.33.0
#9 lore raw
In reply to Alejandro
Quoted 2 lines · Alejandro

The max98927 codec on some devices (i.e. Xiaomi Mi A2 Lite phone) require

requires

Quoted 1 line

hardware-resetting the codec by driving a reset-gpio. This series add

adds

Quoted 1 line

support for it through an optional reset-gpios property.

Where is the changelog?

Quoted 12 lines

Alejandro Tafalla (2):
ASoC: max98927: Handle reset gpio when probing i2c
dt-bindings: sound: max98927: Add reset-gpios optional property

 .../devicetree/bindings/sound/max9892x.txt         |  3 +++
 sound/soc/codecs/max98927.c                        | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

--
2.33.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c

In reply to Alejandro
Quoted 4 lines · Alejandro

From: Alejandro Tafalla <[email protected]>

Drive the reset gpio if defined in the DTS node.

...

sound/soc/codecs/max98927.c static int max98927_i2c_probe(struct i2c_client *i2c, · line 906

Quoted 5 lines
sound/soc/codecs/max98927.c +5 -0
+       reset_gpio
+               = devm_gpiod_get_optional(&i2c->dev, "reset", GPIOD_OUT_LOW);
+       if (IS_ERR(reset_gpio)) {
+               ret = PTR_ERR(reset_gpio);
+               return dev_err_probe(&i2c->dev, ret, "failed to request GPIO reset pin");

Not sure why my comments have been ignored here.

Quoted 1 line

+ }

--
With Best Regards,
Andy Shevchenko

#4 lore raw

Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c

In reply to Alejandro
Quoted 22 lines · Alejandro

From: Alejandro Tafalla <[email protected]>

Drive the reset gpio if defined in the DTS node.

---
 sound/soc/codecs/max98927.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
sound/soc/codecs/max98927.c +1 -0
index 8b206ee77709..daf06b503433 100644
@@ -868,6 +868,7 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
 	int ret = 0, value;
 	int reg = 0;
 	struct max98927_priv *max98927 = NULL;
+	struct gpio_desc *reset_gpio;
 
 	max98927 = devm_kzalloc(&i2c->dev,
 		sizeof(*max98927), GFP_KERNEL);

sound/soc/codecs/max98927.c static int max98927_i2c_probe(struct i2c_client *i2c, · line 903

Quoted 5 lines
sound/soc/codecs/max98927.c +2 -0
@@ -898,6 +899,19 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
+	reset_gpio
+		= devm_gpiod_get_optional(&i2c->dev, "reset", GPIOD_OUT_LOW);

If this is a 'reset' pin then it's ACTIVE state is when it places the device to _reset_.
GPIOD_OUT_LOW == Deasserted state of the GPIO line.

If the reset pin should be pulled low for reset (GPIO_ACTIVE_LOW) and you want the device initially in reset then you need GPIOD_OUT_HIGH, because:
GPIOD_OUT_HIGH == Asserted state of the GPIO line.

Same goes for the gpiod_set_value_cansleep():
0 - deasserted
1 = asserted

and this all depends on how the gpio is defined in DT (GPIO_ACTIVE_LOW/HIGH), which depends on how the documentation refers to the pin...

reset pin:
low to keep the device in reset, high to release it from reset:
GPIO_ACTIVE_LOW
gpiod_set_value_cansleep(0) to enable gpiod_set_value_cansleep(1) to disable

enable pin:
high to enable the part, low to disable
GPIO_ACTIVE_HIGH
gpiod_set_value_cansleep(1) to enable
gpiod_set_value_cansleep(0) to disable

In both cases
electrical 0: reset/disable
electrical 1: enable

sound/soc/codecs/max98927.c static int max98927_i2c_probe(struct i2c_client *i2c, · line 914

Quoted 11 lines
sound/soc/codecs/max98927.c +11 -0
+	if (IS_ERR(reset_gpio)) {
+		ret = PTR_ERR(reset_gpio);
+		return dev_err_probe(&i2c->dev, ret, "failed to request GPIO reset pin");
+	}
+
+	if (reset_gpio) {
+		usleep_range(8000, 10000);
+		gpiod_set_value_cansleep(reset_gpio, 1);
+		usleep_range(1000, 5000);
+	}
+

You might want to put the device to reset on remove at minimum.

Quoted 4 lines
sound/soc/codecs/max98927.c +0 -0
 	/* Check Revision ID */
 	ret = regmap_read(max98927->regmap,
 		MAX98927_R01FF_REV_ID, &reg);
Signature · 1 line
Péter
#3 lore raw

Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c

In reply to Andy Shevchenko
Quoted 13 lines · On viernes, 3 de septiembre de 2021 10:18:14 (CEST) Andy Shevchenko wrote:
Quoted 3 lines · Alejandro

From: Alejandro Tafalla <[email protected]>

Drive the reset gpio if defined in the DTS node.

...

Quoted 6 lines
(quoted diff) +2 -0
+       reset_gpio
+               = devm_gpiod_get_optional(&i2c->dev, "reset",

GPIOD_OUT_LOW); + if (IS_ERR(reset_gpio)) {

(quoted diff) +2 -0
+               ret = PTR_ERR(reset_gpio);
+               return dev_err_probe(&i2c->dev, ret, "failed to request

GPIO reset pin");

Quoted 7 lines

Not sure why my comments have been ignored here.

Quoted 1 line

+ }

--
With Best Regards,
Andy Shevchenko

Sorry, I misread your suggestion and didn't notice PTR_ERR was also in the same line.

#10 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · On 3/9/21 10:16 Andy Shevchenko wrote:
Quoted 1 line · Alejandro

The max98927 codec on some devices (i.e. Xiaomi Mi A2 Lite phone) require

requires

Quoted 7 lines
Quoted 1 line

hardware-resetting the codec by driving a reset-gpio. This series add

adds

Quoted 1 line

support for it through an optional reset-gpios property.

Where is the changelog?

I'll fix the typos and add previous changelogs in the next version. Thank you.

Signature · 1 line
Alejandro Tafalla
maintainer
#7 lore raw

Re: [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property

In reply to Alejandro
Quoted 10 lines · Alejandro

From: Alejandro Tafalla <[email protected]>

Add the reset-gpios as an optional property because some devices might not need it to work properly.

---
 Documentation/devicetree/bindings/sound/max9892x.txt | 3 +++
 1 file changed, 3 insertions(+)

Please add Acked-by/Reviewed-by tags when posting new versions. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.

If a tag was not added on purpose, please state why and what changed.

#8 lore raw

Re: [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property

Quoted 9 lines · On 3/9/21 19:41 Rob Herring wrote:
Quoted 8 lines · Alejandro

From: Alejandro Tafalla <[email protected]>

Add the reset-gpios as an optional property because some devices might not need it to work properly.

---

Quoted 8 lines
Quoted 2 lines
 Documentation/devicetree/bindings/sound/max9892x.txt | 3 +++
 1 file changed, 3 insertions(+)

Please add Acked-by/Reviewed-by tags when posting new versions. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for acks received on the version they apply.

If a tag was not added on purpose, please state why and what changed.

Okay. I was gonna send another version so I'll add it there.

Signature · 1 line
Alejandro Tafalla
#5 lore raw

Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c

In reply to Péter Ujfalusi
Quoted 31 lines · On 3/9/21 11:20 Péter Ujfalusi wrote:

If this is a 'reset' pin then it's ACTIVE state is when it places the device to _reset_.
GPIOD_OUT_LOW == Deasserted state of the GPIO line.

If the reset pin should be pulled low for reset (GPIO_ACTIVE_LOW) and you want the device initially in reset then you need GPIOD_OUT_HIGH, because:
GPIOD_OUT_HIGH == Asserted state of the GPIO line.

Same goes for the gpiod_set_value_cansleep():
0 - deasserted
1 = asserted

and this all depends on how the gpio is defined in DT (GPIO_ACTIVE_LOW/HIGH), which depends on how the documentation refers to the pin...

reset pin:
low to keep the device in reset, high to release it from reset:
GPIO_ACTIVE_LOW
gpiod_set_value_cansleep(0) to enable gpiod_set_value_cansleep(1) to disable

enable pin:
high to enable the part, low to disable
GPIO_ACTIVE_HIGH
gpiod_set_value_cansleep(1) to enable
gpiod_set_value_cansleep(0) to disable

Quoted 3 lines

In both cases
electrical 0: reset/disable
electrical 1: enable

I'll change it to be consistent in the next version. Thank you for the explanation.

Quoted 3 lines

sound/soc/codecs/max98927.c static int max98927_i2c_probe(struct i2c_client *i2c,

Quoted 3 lines
sound/soc/codecs/max98927.c +3 -0
+	if (IS_ERR(reset_gpio)) {
+		ret = PTR_ERR(reset_gpio);
+		return dev_err_probe(&i2c->dev, ret, "failed to request 

GPIO reset

Quoted 10 lines

sound/soc/codecs/max98927.c static int max98927_i2c_probe(struct i2c_client *i2c, · line 914

Quoted 8 lines

pin"); + }

sound/soc/codecs/max98927.c +7 -0
+
+	if (reset_gpio) {
+		usleep_range(8000, 10000);
+		gpiod_set_value_cansleep(reset_gpio, 1);
+		usleep_range(1000, 5000);
+	}
+

You might want to put the device to reset on remove at minimum.

Okay, thanks.

Signature · 1 line
Alejandro Tafalla