linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers
@ 2013-11-26  9:55 Xiubo Li
  2013-11-26 10:59 ` Lothar Waßmann
  2013-11-26 13:44 ` Mark Brown
  0 siblings, 2 replies; 7+ messages in thread
From: Xiubo Li @ 2013-11-26  9:55 UTC (permalink / raw)
  To: lgirdwood, broonie, perex, tiwai, fabio.estevam, LW, oskar
  Cc: alsa-devel, linux-kernel

SGTL5000 codec allows to use the internal LDO instead of VDDD, if the
internal LDO is used, this caused the following kernel failed while trying
to get the external VDDD regulator consumer.

Adding sgtl5000_external_vddd_used() to fix it. And this has been tested on
VF610-TWR board.

sgtl5000 0-000a: Failed to get supply 'VDDD': -19

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---

 sound/soc/codecs/sgtl5000.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 1f4093f..1a2d35a 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -1298,6 +1298,20 @@ static int sgtl5000_replace_vddd_with_ldo(struct snd_soc_codec *codec)
 	return 0;
 }
 
+static int sgtl5000_external_vddd_used(struct snd_soc_codec *codec)
+{
+	struct regulator *consumer;
+	struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
+
+	consumer = regulator_get(codec->dev, sgtl5000->supplies[VDDD].supply);
+	if (IS_ERR(consumer)) {
+		return 0;
+	}
+	regulator_put(consumer);
+
+	return 1;
+}
+
 static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
 {
 	int reg;
@@ -1310,9 +1324,7 @@ static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
 	for (i = 0; i < ARRAY_SIZE(sgtl5000->supplies); i++)
 		sgtl5000->supplies[i].supply = supply_names[i];
 
-	ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(sgtl5000->supplies),
-				sgtl5000->supplies);
-	if (!ret)
+	if (sgtl5000_external_vddd_used(codec))
 		external_vddd = 1;
 	else {
 		ret = sgtl5000_replace_vddd_with_ldo(codec);
-- 
1.8.4



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

* Re: [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers
  2013-11-26  9:55 [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers Xiubo Li
@ 2013-11-26 10:59 ` Lothar Waßmann
  2013-11-27  4:16   ` Li Xiubo
  2013-11-26 13:44 ` Mark Brown
  1 sibling, 1 reply; 7+ messages in thread
From: Lothar Waßmann @ 2013-11-26 10:59 UTC (permalink / raw)
  To: Xiubo Li
  Cc: lgirdwood, broonie, perex, tiwai, fabio.estevam, oskar,
	alsa-devel, linux-kernel

Hi,

Xiubo Li wrote:
> SGTL5000 codec allows to use the internal LDO instead of VDDD, if the
> internal LDO is used, this caused the following kernel failed while trying
> to get the external VDDD regulator consumer.
> 
> Adding sgtl5000_external_vddd_used() to fix it. And this has been tested on
> VF610-TWR board.
> 
> sgtl5000 0-000a: Failed to get supply 'VDDD': -19
> 
> Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
> ---
> 
>  sound/soc/codecs/sgtl5000.c | 18 +++++++++++++++---
>  1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
> index 1f4093f..1a2d35a 100644
> --- a/sound/soc/codecs/sgtl5000.c
> +++ b/sound/soc/codecs/sgtl5000.c
> @@ -1298,6 +1298,20 @@ static int sgtl5000_replace_vddd_with_ldo(struct snd_soc_codec *codec)
>  	return 0;
>  }
>  
> +static int sgtl5000_external_vddd_used(struct snd_soc_codec *codec)
> +{
> +	struct regulator *consumer;
> +	struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
> +
> +	consumer = regulator_get(codec->dev, sgtl5000->supplies[VDDD].supply);
> +	if (IS_ERR(consumer)) {
> +		return 0;
> +	}
> +	regulator_put(consumer);
> +
> +	return 1;
> +}
> +
>  static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
>  {
>  	int reg;
> @@ -1310,9 +1324,7 @@ static int sgtl5000_enable_regulators(struct snd_soc_codec *codec)
>  	for (i = 0; i < ARRAY_SIZE(sgtl5000->supplies); i++)
>  		sgtl5000->supplies[i].supply = supply_names[i];
>  
> -	ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(sgtl5000->supplies),
> -				sgtl5000->supplies);
> -	if (!ret)
> +	if (sgtl5000_external_vddd_used(codec))
>  		external_vddd = 1;
>  	else {
>  		ret = sgtl5000_replace_vddd_with_ldo(codec);
>
You could fix the coding style issue (braces on both branches
of the if clause) here too.


Lothar Waßmann
-- 
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info@karo-electronics.de
___________________________________________________________

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

* Re: [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers
  2013-11-26  9:55 [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers Xiubo Li
  2013-11-26 10:59 ` Lothar Waßmann
@ 2013-11-26 13:44 ` Mark Brown
  2013-11-27  8:13   ` Li Xiubo
  1 sibling, 1 reply; 7+ messages in thread
From: Mark Brown @ 2013-11-26 13:44 UTC (permalink / raw)
  To: Xiubo Li
  Cc: lgirdwood, perex, tiwai, fabio.estevam, LW, oskar, alsa-devel,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1654 bytes --]

On Tue, Nov 26, 2013 at 05:55:13PM +0800, Xiubo Li wrote:

> +static int sgtl5000_external_vddd_used(struct snd_soc_codec *codec)
> +{
> +	struct regulator *consumer;
> +	struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
> +
> +	consumer = regulator_get(codec->dev, sgtl5000->supplies[VDDD].supply);
> +	if (IS_ERR(consumer)) {
> +		return 0;
> +	}
> +	regulator_put(consumer);
> +
> +	return 1;
> +}

This is going to fail to do what you expect if a dummy regulator is
substituted which it will almost all of the time when the supply is
genuinely absent.  It's also going to interact poorly with probe
deferral.

> -	ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(sgtl5000->supplies),
> -				sgtl5000->supplies);
> -	if (!ret)
> +	if (sgtl5000_external_vddd_used(codec))
>  		external_vddd = 1;
>  	else {
>  		ret = sgtl5000_replace_vddd_with_ldo(codec);

This looks buggy, it removes the regulator_get() for most of the
supplies for the device.

I think the driver may want to use regulator_get_optional(), though
looking at the fact that there's an external_vdd flag there already it
seems like there's already some attempt to handle these configuratins in
the driver that isn't working so perhaps that just needs to be fixed.
Or possibly DTs need to be changed to describe the supply.  

I'd expect to see a commit description that describes how the driver
currently tries to handle this, why it doesn't work and how the patch
fixes it.  Right now it seems like the change is jumping to a solution
without understanding the problem and making some already problematic
code more confused.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* RE: [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers
  2013-11-26 10:59 ` Lothar Waßmann
@ 2013-11-27  4:16   ` Li Xiubo
  0 siblings, 0 replies; 7+ messages in thread
From: Li Xiubo @ 2013-11-27  4:16 UTC (permalink / raw)
  To: Lothar Waßmann
  Cc: lgirdwood, broonie, perex, tiwai, Fabio Estevam, oskar,
	alsa-devel, linux-kernel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 354 bytes --]


> >  	else {
> >  		ret = sgtl5000_replace_vddd_with_ldo(codec);
> >
> You could fix the coding style issue (braces on both branches of the if
> clause) here too.
> 
> 
Yes, I will.

Thanks.


ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* RE: [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers
  2013-11-26 13:44 ` Mark Brown
@ 2013-11-27  8:13   ` Li Xiubo
  2013-11-27 11:27     ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Li Xiubo @ 2013-11-27  8:13 UTC (permalink / raw)
  To: Mark Brown
  Cc: lgirdwood, perex, tiwai, Fabio Estevam, LW, oskar, alsa-devel,
	linux-kernel

> > +static int sgtl5000_external_vddd_used(struct snd_soc_codec *codec)
> > +{
> > +	struct regulator *consumer;
> > +	struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
> > +
> > +	consumer = regulator_get(codec->dev, sgtl5000-
> >supplies[VDDD].supply);
> > +	if (IS_ERR(consumer)) {
> > +		return 0;
> > +	}
> > +	regulator_put(consumer);
> > +
> > +	return 1;
> > +}
> 
> This is going to fail to do what you expect if a dummy regulator is
> substituted which it will almost all of the time when the supply is
> genuinely absent.  It's also going to interact poorly with probe
> deferral.
> 

There is one dependency patch: "regulator: core: Provide a dummy regulator with full constraints".

>From the dependency patch, we can see that using regulator_get_optional() instead can resovle the problem you descripted above.

When or will this dependency patch be merged into the -next tree ?



> I'd expect to see a commit description that describes how the driver
> currently tries to handle this, why it doesn't work and how the patch
> fixes it.  

The SGTL5000 requires 2 external power supplies: VDDA and VDDIO. An optional third external power supply VDDD may be provided externally to achieve lower power.If an external supply is not used for VDDD, the SGTL5000 driver will register it's own non-DT regulator device, and then provides the VDDD supply consumer, and now there will be two register devices exist, non-DT regulator for VDDD and DT regulator for VDDIO, VDDA.   


		
+++++++++++++++++++
+			+------------|3.3V VDDIO
+			+
+  SGTL5000	codec	+---X   VDDD
+			+
+			+------------|3.3V VDDA
+++++++++++++++++++
		


If an external supply is not used for VDDD, in the DT file, only "VDDA-supply" and "VDDIO-supply" properties will be presented. This caused the following kernel failed while trying to get the external VDDD regulator consumer before trying to register it's own regulator device. 

sgtl5000 0-000a: Failed to get supply 'VDDD': -19

While if an external supply is used for VDDD, in the DT file, all the three "VDDA-supply", "VDDIO-supply" and "VDDD-supply" properties can absent, by just using the dummy regulator. 

IMO, the failed log will confuse most people(especially for those not familiar with the SGTL5000 driver) that why getting the 'VDDD' supply failed but it still works? or is there something wrong with it ? ,etc.


Yes, this is a buggy patch, and I will revise it later.


--
Best Regards,





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

* Re: [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers
  2013-11-27  8:13   ` Li Xiubo
@ 2013-11-27 11:27     ` Mark Brown
  2013-11-28  3:31       ` Li Xiubo
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2013-11-27 11:27 UTC (permalink / raw)
  To: Li Xiubo
  Cc: lgirdwood, perex, tiwai, Fabio Estevam, LW, oskar, alsa-devel,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

On Wed, Nov 27, 2013 at 08:13:03AM +0000, Li Xiubo wrote:

Please fix your mailer to word wrap within paragraphs, it makes your
mail much more legible.

> There is one dependency patch: "regulator: core: Provide a dummy regulator with full constraints".

> From the dependency patch, we can see that using regulator_get_optional() instead can resovle the problem you descripted above.

> When or will this dependency patch be merged into the -next tree ?

That patch is already in mainline.

> > I'd expect to see a commit description that describes how the driver
> > currently tries to handle this, why it doesn't work and how the patch
> > fixes it.  

> The SGTL5000 requires 2 external power supplies: VDDA and VDDIO. An
> optional third external power supply VDDD may be provided externally

You need to put your working through of this stuff in the commit
message.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* RE: [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers
  2013-11-27 11:27     ` Mark Brown
@ 2013-11-28  3:31       ` Li Xiubo
  0 siblings, 0 replies; 7+ messages in thread
From: Li Xiubo @ 2013-11-28  3:31 UTC (permalink / raw)
  To: Mark Brown
  Cc: lgirdwood, perex, tiwai, Fabio Estevam, LW, oskar, alsa-devel,
	linux-kernel


> Subject: Re: [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting
> regulator consumers
> 
> On Wed, Nov 27, 2013 at 08:13:03AM +0000, Li Xiubo wrote:
> 
> Please fix your mailer to word wrap within paragraphs, it makes your mail
> much more legible.
> 

Yes, I will.


> > There is one dependency patch: "regulator: core: Provide a dummy
> regulator with full constraints".
> 
> > From the dependency patch, we can see that using regulator_get_optional()
> instead can resovle the problem you descripted above.
> 
> > When or will this dependency patch be merged into the -next tree ?
> 
> That patch is already in mainline.
> 

Okey.

> > > I'd expect to see a commit description that describes how the driver
> > > currently tries to handle this, why it doesn't work and how the
> > > patch fixes it.
> 
> > The SGTL5000 requires 2 external power supplies: VDDA and VDDIO. An
> > optional third external power supply VDDD may be provided externally
> 
> You need to put your working through of this stuff in the commit message.

I did it already, please see the next version.

--
Best Regards,



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

end of thread, other threads:[~2013-11-28  3:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-26  9:55 [PATCHv1] ASoC: SGTL5000: Fix kernel failed while getting regulator consumers Xiubo Li
2013-11-26 10:59 ` Lothar Waßmann
2013-11-27  4:16   ` Li Xiubo
2013-11-26 13:44 ` Mark Brown
2013-11-27  8:13   ` Li Xiubo
2013-11-27 11:27     ` Mark Brown
2013-11-28  3:31       ` Li Xiubo

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