All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] audio: sgtl5000: Add MicBias resistor support in DT
@ 2014-10-12 21:39 Jean-Michel Hautbois
       [not found] ` <1413149951-2882-1-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Michel Hautbois @ 2014-10-12 21:39 UTC (permalink / raw)
  To: broonie-DgEjT+Ai2ygdnm+yROfE0A,
	fabio.estevam-KZfg59tc24xl57MIdRCFDg,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w, Jean-Michel Hautbois

Some systems may require a different resistor than the default one (4K).
This adds a property in sgtl5000 codec.
It keeps the default of 4K when nothing is specified so it does not break
existing code.

v2: modify the default case on DT parsing

Signed-off-by: Jean-Michel Hautbois <jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
---
 .../devicetree/bindings/sound/sgtl5000.txt         | 10 ++++
 sound/soc/codecs/sgtl5000.c                        | 60 ++++++++++++++++++++--
 2 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt
index 955df60..dd38f84 100644
--- a/Documentation/devicetree/bindings/sound/sgtl5000.txt
+++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt
@@ -7,10 +7,20 @@ Required properties:
 
 - clocks : the clock provider of SYS_MCLK
 
+- sgtl5000-micbias-resistor : the bias resistor to be used
+        1 or SGTL5000_MICBIAS_2K - MICBIAS resistor is set to 2K
+        2 or SGTL5000_MICBIAS_4K - MICBIAS resistor is set to 4K
+        3 or SGTL5000_MICBIAS_8K - MICBIAS resistor is set to 8K
+        0 or SGTL5000_MICBIAS_OFF - MICBIAS resistor is not used
+	If this node is not mentioned or if the value is unknown, then
+	micbias	resistor is set to 4K.
+
+
 Example:
 
 codec: sgtl5000@0a {
 	compatible = "fsl,sgtl5000";
 	reg = <0x0a>;
 	clocks = <&clks 150>;
+	sgtl5000-micbias-resistor = <1>;
 };
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 6bb77d7..a255754 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -121,6 +121,13 @@ struct ldo_regulator {
 	bool enabled;
 };
 
+enum sgtl5000_micbias_resistor {
+	SGTL5000_MICBIAS_OFF = 0,
+	SGTL5000_MICBIAS_2K = 1,
+	SGTL5000_MICBIAS_4K = 2,
+	SGTL5000_MICBIAS_8K = 3,
+};
+
 /* sgtl5000 private structure in codec */
 struct sgtl5000_priv {
 	int sysclk;	/* sysclk rate */
@@ -131,6 +138,7 @@ struct sgtl5000_priv {
 	struct regmap *regmap;
 	struct clk *mclk;
 	int revision;
+	enum sgtl5000_micbias_resistor micbias_resistor;
 };
 
 /*
@@ -145,12 +153,14 @@ struct sgtl5000_priv {
 static int mic_bias_event(struct snd_soc_dapm_widget *w,
 	struct snd_kcontrol *kcontrol, int event)
 {
+	struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(w->codec);
+
 	switch (event) {
 	case SND_SOC_DAPM_POST_PMU:
-		/* change mic bias resistor to 4Kohm */
+		/* change mic bias resistor */
 		snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL,
-				SGTL5000_BIAS_R_MASK,
-				SGTL5000_BIAS_R_4k << SGTL5000_BIAS_R_SHIFT);
+			SGTL5000_BIAS_R_MASK,
+			sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
 		break;
 
 	case SND_SOC_DAPM_PRE_PMD:
@@ -1326,7 +1336,16 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
 			SGTL5000_HP_ZCD_EN |
 			SGTL5000_ADC_ZCD_EN);
 
-	snd_soc_write(codec, SGTL5000_CHIP_MIC_CTRL, 2);
+	switch (sgtl5000->micbias_resistor) {
+	case SGTL5000_MICBIAS_2K:
+	case SGTL5000_MICBIAS_4K:
+	case SGTL5000_MICBIAS_8K:
+		snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
+			SGTL5000_BIAS_R_MASK,
+			sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
+	default:
+		break;
+	}
 
 	/*
 	 * disable DAP
@@ -1418,6 +1437,8 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
 	struct sgtl5000_priv *sgtl5000;
 	int ret, reg, rev;
 	unsigned int mclk;
+	struct device_node *np = client->dev.of_node;
+	u32 value;
 
 	sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv),
 								GFP_KERNEL);
@@ -1470,6 +1491,37 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
 	dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev);
 	sgtl5000->revision = rev;
 
+	if (np) {
+		if (!of_property_read_u32(np,
+			"sgtl5000-micbias-resistor", &value)) {
+			switch (value) {
+			case 0:
+				sgtl5000->micbias_resistor =
+					SGTL5000_MICBIAS_OFF;
+				break;
+			case 1:
+				sgtl5000->micbias_resistor =
+					SGTL5000_MICBIAS_2K;
+				break;
+			case 2:
+				sgtl5000->micbias_resistor =
+					SGTL5000_MICBIAS_4K;
+				break;
+			case 3:
+				sgtl5000->micbias_resistor =
+					SGTL5000_MICBIAS_8K;
+				break;
+			default:
+				sgtl5000->micbias_resistor =
+					SGTL5000_MICBIAS_4K;
+				dev_err(&client->dev,
+					"Unsuitable MicBias resistor\n");
+			}
+		} else {
+			sgtl5000->micbias_resistor = SGTL5000_MICBIAS_4K;
+		}
+	}
+
 	i2c_set_clientdata(client, sgtl5000);
 
 	/* Ensure sgtl5000 will start with sane register values */
-- 
2.1.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2] audio: sgtl5000: Add MicBias resistor support in DT
       [not found] ` <1413149951-2882-1-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
@ 2014-10-13 10:05   ` Mark Rutland
  2014-10-13 10:10     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2014-10-13 10:05 UTC (permalink / raw)
  To: Jean-Michel Hautbois
  Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

On Sun, Oct 12, 2014 at 10:39:11PM +0100, Jean-Michel Hautbois wrote:
> Some systems may require a different resistor than the default one (4K).
> This adds a property in sgtl5000 codec.
> It keeps the default of 4K when nothing is specified so it does not break
> existing code.
> 
> v2: modify the default case on DT parsing
> 
> Signed-off-by: Jean-Michel Hautbois <jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
> ---
>  .../devicetree/bindings/sound/sgtl5000.txt         | 10 ++++
>  sound/soc/codecs/sgtl5000.c                        | 60 ++++++++++++++++++++--
>  2 files changed, 66 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt
> index 955df60..dd38f84 100644
> --- a/Documentation/devicetree/bindings/sound/sgtl5000.txt
> +++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt
> @@ -7,10 +7,20 @@ Required properties:
>  
>  - clocks : the clock provider of SYS_MCLK
>  
> +- sgtl5000-micbias-resistor : the bias resistor to be used
> +        1 or SGTL5000_MICBIAS_2K - MICBIAS resistor is set to 2K
> +        2 or SGTL5000_MICBIAS_4K - MICBIAS resistor is set to 4K
> +        3 or SGTL5000_MICBIAS_8K - MICBIAS resistor is set to 8K
> +        0 or SGTL5000_MICBIAS_OFF - MICBIAS resistor is not used
> +	If this node is not mentioned or if the value is unknown, then
> +	micbias	resistor is set to 4K.

The SGTL5000_MICBIAS_* constants aren't in a DT header, so shouldn't be
referenced here.

Why not have mcbias-resistor-k-ohms as 2, 4, 8, or 0?

That would be much easier to read as a human.

Thanks,
Mark.

> +
> +
>  Example:
>  
>  codec: sgtl5000@0a {
>  	compatible = "fsl,sgtl5000";
>  	reg = <0x0a>;
>  	clocks = <&clks 150>;
> +	sgtl5000-micbias-resistor = <1>;
>  };
> diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
> index 6bb77d7..a255754 100644
> --- a/sound/soc/codecs/sgtl5000.c
> +++ b/sound/soc/codecs/sgtl5000.c
> @@ -121,6 +121,13 @@ struct ldo_regulator {
>  	bool enabled;
>  };
>  
> +enum sgtl5000_micbias_resistor {
> +	SGTL5000_MICBIAS_OFF = 0,
> +	SGTL5000_MICBIAS_2K = 1,
> +	SGTL5000_MICBIAS_4K = 2,
> +	SGTL5000_MICBIAS_8K = 3,
> +};
> +
>  /* sgtl5000 private structure in codec */
>  struct sgtl5000_priv {
>  	int sysclk;	/* sysclk rate */
> @@ -131,6 +138,7 @@ struct sgtl5000_priv {
>  	struct regmap *regmap;
>  	struct clk *mclk;
>  	int revision;
> +	enum sgtl5000_micbias_resistor micbias_resistor;
>  };
>  
>  /*
> @@ -145,12 +153,14 @@ struct sgtl5000_priv {
>  static int mic_bias_event(struct snd_soc_dapm_widget *w,
>  	struct snd_kcontrol *kcontrol, int event)
>  {
> +	struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(w->codec);
> +
>  	switch (event) {
>  	case SND_SOC_DAPM_POST_PMU:
> -		/* change mic bias resistor to 4Kohm */
> +		/* change mic bias resistor */
>  		snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL,
> -				SGTL5000_BIAS_R_MASK,
> -				SGTL5000_BIAS_R_4k << SGTL5000_BIAS_R_SHIFT);
> +			SGTL5000_BIAS_R_MASK,
> +			sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
>  		break;
>  
>  	case SND_SOC_DAPM_PRE_PMD:
> @@ -1326,7 +1336,16 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
>  			SGTL5000_HP_ZCD_EN |
>  			SGTL5000_ADC_ZCD_EN);
>  
> -	snd_soc_write(codec, SGTL5000_CHIP_MIC_CTRL, 2);
> +	switch (sgtl5000->micbias_resistor) {
> +	case SGTL5000_MICBIAS_2K:
> +	case SGTL5000_MICBIAS_4K:
> +	case SGTL5000_MICBIAS_8K:
> +		snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
> +			SGTL5000_BIAS_R_MASK,
> +			sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
> +	default:
> +		break;
> +	}
>  
>  	/*
>  	 * disable DAP
> @@ -1418,6 +1437,8 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
>  	struct sgtl5000_priv *sgtl5000;
>  	int ret, reg, rev;
>  	unsigned int mclk;
> +	struct device_node *np = client->dev.of_node;
> +	u32 value;
>  
>  	sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv),
>  								GFP_KERNEL);
> @@ -1470,6 +1491,37 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
>  	dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev);
>  	sgtl5000->revision = rev;
>  
> +	if (np) {
> +		if (!of_property_read_u32(np,
> +			"sgtl5000-micbias-resistor", &value)) {
> +			switch (value) {
> +			case 0:
> +				sgtl5000->micbias_resistor =
> +					SGTL5000_MICBIAS_OFF;
> +				break;
> +			case 1:
> +				sgtl5000->micbias_resistor =
> +					SGTL5000_MICBIAS_2K;
> +				break;
> +			case 2:
> +				sgtl5000->micbias_resistor =
> +					SGTL5000_MICBIAS_4K;
> +				break;
> +			case 3:
> +				sgtl5000->micbias_resistor =
> +					SGTL5000_MICBIAS_8K;
> +				break;
> +			default:
> +				sgtl5000->micbias_resistor =
> +					SGTL5000_MICBIAS_4K;
> +				dev_err(&client->dev,
> +					"Unsuitable MicBias resistor\n");
> +			}
> +		} else {
> +			sgtl5000->micbias_resistor = SGTL5000_MICBIAS_4K;
> +		}
> +	}
> +
>  	i2c_set_clientdata(client, sgtl5000);
>  
>  	/* Ensure sgtl5000 will start with sane register values */
> -- 
> 2.1.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2] audio: sgtl5000: Add MicBias resistor support in DT
  2014-10-13 10:05   ` Mark Rutland
@ 2014-10-13 10:10     ` Mark Brown
       [not found]       ` <20141013101008.GF27755-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2014-10-13 10:10 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Jean-Michel Hautbois,
	fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

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

On Mon, Oct 13, 2014 at 11:05:04AM +0100, Mark Rutland wrote:
> On Sun, Oct 12, 2014 at 10:39:11PM +0100, Jean-Michel Hautbois wrote:
> > Some systems may require a different resistor than the default one (4K).
> > This adds a property in sgtl5000 codec.
> > It keeps the default of 4K when nothing is specified so it does not break
> > existing code.
> > 
> > v2: modify the default case on DT parsing

Don't include noise like this in the changelog, add it after the --- as
covered in SubmittingPatches.

> > +- sgtl5000-micbias-resistor : the bias resistor to be used
> > +        1 or SGTL5000_MICBIAS_2K - MICBIAS resistor is set to 2K
> > +        2 or SGTL5000_MICBIAS_4K - MICBIAS resistor is set to 4K
> > +        3 or SGTL5000_MICBIAS_8K - MICBIAS resistor is set to 8K
> > +        0 or SGTL5000_MICBIAS_OFF - MICBIAS resistor is not used
> > +	If this node is not mentioned or if the value is unknown, then
> > +	micbias	resistor is set to 4K.

> The SGTL5000_MICBIAS_* constants aren't in a DT header, so shouldn't be
> referenced here.

Or the constants should be moved of course but...

> Why not have mcbias-resistor-k-ohms as 2, 4, 8, or 0?

> That would be much easier to read as a human.

...this is even better.

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

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

* Re: [PATCH v2] audio: sgtl5000: Add MicBias resistor support in DT
       [not found]       ` <20141013101008.GF27755-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2014-10-13 10:18         ` Jean-Michel Hautbois
  0 siblings, 0 replies; 4+ messages in thread
From: Jean-Michel Hautbois @ 2014-10-13 10:18 UTC (permalink / raw)
  To: Mark Brown
  Cc: Mark Rutland,
	fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

Hi Mark (x2 :))

2014-10-13 12:10 GMT+02:00 Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>:
> On Mon, Oct 13, 2014 at 11:05:04AM +0100, Mark Rutland wrote:
>> On Sun, Oct 12, 2014 at 10:39:11PM +0100, Jean-Michel Hautbois wrote:
>> > Some systems may require a different resistor than the default one (4K).
>> > This adds a property in sgtl5000 codec.
>> > It keeps the default of 4K when nothing is specified so it does not break
>> > existing code.
>> >
>> > v2: modify the default case on DT parsing
>
> Don't include noise like this in the changelog, add it after the --- as
> covered in SubmittingPatches.

Oups, not intended, too quick to commit sorry...

>> > +- sgtl5000-micbias-resistor : the bias resistor to be used
>> > +        1 or SGTL5000_MICBIAS_2K - MICBIAS resistor is set to 2K
>> > +        2 or SGTL5000_MICBIAS_4K - MICBIAS resistor is set to 4K
>> > +        3 or SGTL5000_MICBIAS_8K - MICBIAS resistor is set to 8K
>> > +        0 or SGTL5000_MICBIAS_OFF - MICBIAS resistor is not used
>> > +   If this node is not mentioned or if the value is unknown, then
>> > +   micbias resistor is set to 4K.
>
>> The SGTL5000_MICBIAS_* constants aren't in a DT header, so shouldn't be
>> referenced here.
>
> Or the constants should be moved of course but...
>
>> Why not have mcbias-resistor-k-ohms as 2, 4, 8, or 0?
>
>> That would be much easier to read as a human.
>
> ...this is even better.

Yes, I will do that ASAP, and base the micbias-voltage on the same principle.

Thanks,
JM
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2014-10-13 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-12 21:39 [PATCH v2] audio: sgtl5000: Add MicBias resistor support in DT Jean-Michel Hautbois
     [not found] ` <1413149951-2882-1-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
2014-10-13 10:05   ` Mark Rutland
2014-10-13 10:10     ` Mark Brown
     [not found]       ` <20141013101008.GF27755-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-10-13 10:18         ` Jean-Michel Hautbois

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.