linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Add reset-gpios handling for max98927
@ 2021-09-03  1:49 Alejandro
  2021-09-03  1:49 ` [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c Alejandro
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Alejandro @ 2021-09-03  1:49 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Andy Shevchenko
  Cc: Alejandro, Rob Herring, Jaroslav Kysela, Takashi Iwai,
	alsa-devel, devicetree, linux-kernel

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(+)

-- 
2.33.0


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

* [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c
  2021-09-03  1:49 [PATCH v3 0/2] Add reset-gpios handling for max98927 Alejandro
@ 2021-09-03  1:49 ` Alejandro
  2021-09-03  8:18   ` Andy Shevchenko
  2021-09-03  9:20   ` Péter Ujfalusi
  2021-09-03  1:49 ` [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property Alejandro
  2021-09-03  8:16 ` [PATCH v3 0/2] Add reset-gpios handling for max98927 Andy Shevchenko
  2 siblings, 2 replies; 11+ messages in thread
From: Alejandro @ 2021-09-03  1:49 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Andy Shevchenko
  Cc: Alejandro Tafalla, Rob Herring, Jaroslav Kysela, Takashi Iwai,
	alsa-devel, devicetree, linux-kernel

From: Alejandro Tafalla <atafalla@dnyon.com>

Drive the reset gpio if defined in the DTS node.

Signed-off-by: Alejandro Tafalla <atafalla@dnyon.com>
---
 sound/soc/codecs/max98927.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index 8b206ee77709..daf06b503433 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -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);
-- 
2.33.0


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

* [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property
  2021-09-03  1:49 [PATCH v3 0/2] Add reset-gpios handling for max98927 Alejandro
  2021-09-03  1:49 ` [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c Alejandro
@ 2021-09-03  1:49 ` Alejandro
  2021-09-03 17:41   ` Rob Herring
  2021-09-03  8:16 ` [PATCH v3 0/2] Add reset-gpios handling for max98927 Andy Shevchenko
  2 siblings, 1 reply; 11+ messages in thread
From: Alejandro @ 2021-09-03  1:49 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Andy Shevchenko
  Cc: Alejandro Tafalla, Rob Herring, Jaroslav Kysela, Takashi Iwai,
	alsa-devel, devicetree, linux-kernel

From: Alejandro Tafalla <atafalla@dnyon.com>

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

Signed-off-by: Alejandro Tafalla <atafalla@dnyon.com>
---
 Documentation/devicetree/bindings/sound/max9892x.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/max9892x.txt b/Documentation/devicetree/bindings/sound/max9892x.txt
index f6171591ddc6..98cb9ba5b328 100644
--- a/Documentation/devicetree/bindings/sound/max9892x.txt
+++ b/Documentation/devicetree/bindings/sound/max9892x.txt
@@ -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 {
-- 
2.33.0


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

* Re: [PATCH v3 0/2] Add reset-gpios handling for max98927
  2021-09-03  1:49 [PATCH v3 0/2] Add reset-gpios handling for max98927 Alejandro
  2021-09-03  1:49 ` [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c Alejandro
  2021-09-03  1:49 ` [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property Alejandro
@ 2021-09-03  8:16 ` Andy Shevchenko
  2021-09-03 16:02   ` Alejandro Tafalla
  2 siblings, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2021-09-03  8:16 UTC (permalink / raw)
  To: Alejandro
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Jaroslav Kysela,
	Takashi Iwai, ALSA Development Mailing List, devicetree,
	Linux Kernel Mailing List

On Fri, Sep 3, 2021 at 4:51 AM Alejandro <atafalla@dnyon.com> wrote:
>
> The max98927 codec on some devices (i.e. Xiaomi Mi A2 Lite phone) require

requires

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

adds

> support for it through an optional reset-gpios property.

Where is the  changelog?

>
> 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
>


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c
  2021-09-03  1:49 ` [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c Alejandro
@ 2021-09-03  8:18   ` Andy Shevchenko
  2021-09-03 15:52     ` Alejandro Tafalla
  2021-09-03  9:20   ` Péter Ujfalusi
  1 sibling, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2021-09-03  8:18 UTC (permalink / raw)
  To: Alejandro
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Jaroslav Kysela,
	Takashi Iwai, ALSA Development Mailing List, devicetree,
	Linux Kernel Mailing List

On Fri, Sep 3, 2021 at 4:51 AM Alejandro <atafalla@dnyon.com> wrote:
>
> From: Alejandro Tafalla <atafalla@dnyon.com>
>
> Drive the reset gpio if defined in the DTS node.

...

> +       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.

> +       }

--
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c
  2021-09-03  1:49 ` [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c Alejandro
  2021-09-03  8:18   ` Andy Shevchenko
@ 2021-09-03  9:20   ` Péter Ujfalusi
  2021-09-03 23:22     ` Alejandro Tafalla
  1 sibling, 1 reply; 11+ messages in thread
From: Péter Ujfalusi @ 2021-09-03  9:20 UTC (permalink / raw)
  To: Alejandro, Liam Girdwood, Mark Brown, Andy Shevchenko
  Cc: devicetree, alsa-devel, linux-kernel, Takashi Iwai, Rob Herring



On 03/09/2021 04:49, Alejandro wrote:
> From: Alejandro Tafalla <atafalla@dnyon.com>
> 
> Drive the reset gpio if defined in the DTS node.
> 
> Signed-off-by: Alejandro Tafalla <atafalla@dnyon.com>
> ---
>  sound/soc/codecs/max98927.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
> index 8b206ee77709..daf06b503433 100644
> --- a/sound/soc/codecs/max98927.c
> +++ b/sound/soc/codecs/max98927.c
> @@ -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 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

> +	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.

>  	/* Check Revision ID */
>  	ret = regmap_read(max98927->regmap,
>  		MAX98927_R01FF_REV_ID, &reg);
> 

-- 
Péter

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

* Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c
  2021-09-03  8:18   ` Andy Shevchenko
@ 2021-09-03 15:52     ` Alejandro Tafalla
  0 siblings, 0 replies; 11+ messages in thread
From: Alejandro Tafalla @ 2021-09-03 15:52 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Jaroslav Kysela,
	Takashi Iwai, ALSA Development Mailing List, devicetree,
	Linux Kernel Mailing List

On viernes, 3 de septiembre de 2021 10:18:14 (CEST) Andy Shevchenko wrote:
> On Fri, Sep 3, 2021 at 4:51 AM Alejandro <atafalla@dnyon.com> wrote:
> > From: Alejandro Tafalla <atafalla@dnyon.com>
> > 
> > Drive the reset gpio if defined in the DTS node.
> 
> ...
> 
> > +       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.
> 
> > +       }
> 
> --
> With Best Regards,
> Andy Shevchenko
Sorry, I misread your suggestion and didn't notice PTR_ERR was also in the 
same line.




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

* Re: [PATCH v3 0/2] Add reset-gpios handling for max98927
  2021-09-03  8:16 ` [PATCH v3 0/2] Add reset-gpios handling for max98927 Andy Shevchenko
@ 2021-09-03 16:02   ` Alejandro Tafalla
  0 siblings, 0 replies; 11+ messages in thread
From: Alejandro Tafalla @ 2021-09-03 16:02 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Liam Girdwood, Mark Brown, Rob Herring, Jaroslav Kysela,
	Takashi Iwai, ALSA Development Mailing List, devicetree,
	Linux Kernel Mailing List

On 3/9/21 10:16 Andy Shevchenko wrote:
> On Fri, Sep 3, 2021 at 4:51 AM Alejandro <atafalla@dnyon.com> wrote:
> > The max98927 codec on some devices (i.e. Xiaomi Mi A2 Lite phone) require
> 
> requires
> 
> > hardware-resetting the codec by driving a reset-gpio. This series add
> 
> adds
> 
> > 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.

-- 
Alejandro Tafalla



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

* Re: [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property
  2021-09-03  1:49 ` [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property Alejandro
@ 2021-09-03 17:41   ` Rob Herring
  2021-09-03 17:58     ` Alejandro Tafalla
  0 siblings, 1 reply; 11+ messages in thread
From: Rob Herring @ 2021-09-03 17:41 UTC (permalink / raw)
  To: Alejandro
  Cc: Jaroslav Kysela, alsa-devel, linux-kernel, Mark Brown,
	devicetree, Rob Herring, Liam Girdwood, Takashi Iwai,
	Andy Shevchenko

On Fri, 03 Sep 2021 03:49:51 +0200, Alejandro wrote:
> From: Alejandro Tafalla <atafalla@dnyon.com>
> 
> Add the reset-gpios as an optional property because some devices might
> not need it to work properly.
> 
> Signed-off-by: Alejandro Tafalla <atafalla@dnyon.com>
> ---
>  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.


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

* Re: [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property
  2021-09-03 17:41   ` Rob Herring
@ 2021-09-03 17:58     ` Alejandro Tafalla
  0 siblings, 0 replies; 11+ messages in thread
From: Alejandro Tafalla @ 2021-09-03 17:58 UTC (permalink / raw)
  To: Rob Herring
  Cc: Jaroslav Kysela, alsa-devel, linux-kernel, Mark Brown,
	devicetree, Rob Herring, Liam Girdwood, Takashi Iwai,
	Andy Shevchenko

On 3/9/21 19:41 Rob Herring wrote:
> On Fri, 03 Sep 2021 03:49:51 +0200, Alejandro wrote:
> > From: Alejandro Tafalla <atafalla@dnyon.com>
> > 
> > Add the reset-gpios as an optional property because some devices might
> > not need it to work properly.
> > 
> > Signed-off-by: Alejandro Tafalla <atafalla@dnyon.com>
> > ---
> > 
> >  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.

-- 
Alejandro Tafalla



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

* Re: [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c
  2021-09-03  9:20   ` Péter Ujfalusi
@ 2021-09-03 23:22     ` Alejandro Tafalla
  0 siblings, 0 replies; 11+ messages in thread
From: Alejandro Tafalla @ 2021-09-03 23:22 UTC (permalink / raw)
  To: Péter Ujfalusi
  Cc: Liam Girdwood, Mark Brown, Andy Shevchenko, devicetree,
	alsa-devel, linux-kernel, Takashi Iwai, Rob Herring

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
> 
> 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.
 
> > +	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.
Okay, thanks.

-- 
Alejandro Tafalla



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

end of thread, other threads:[~2021-09-03 23:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03  1:49 [PATCH v3 0/2] Add reset-gpios handling for max98927 Alejandro
2021-09-03  1:49 ` [PATCH v3 1/2] ASoC: max98927: Handle reset gpio when probing i2c Alejandro
2021-09-03  8:18   ` Andy Shevchenko
2021-09-03 15:52     ` Alejandro Tafalla
2021-09-03  9:20   ` Péter Ujfalusi
2021-09-03 23:22     ` Alejandro Tafalla
2021-09-03  1:49 ` [PATCH v3 2/2] dt-bindings: sound: max98927: Add reset-gpios optional property Alejandro
2021-09-03 17:41   ` Rob Herring
2021-09-03 17:58     ` Alejandro Tafalla
2021-09-03  8:16 ` [PATCH v3 0/2] Add reset-gpios handling for max98927 Andy Shevchenko
2021-09-03 16:02   ` Alejandro Tafalla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).