devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] sgtl5000: Add controls for MicBias in DT
@ 2014-10-14  6:43 Jean-Michel Hautbois
       [not found] ` <1413268992-15248-1-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Jean-Michel Hautbois @ 2014-10-14  6:43 UTC (permalink / raw)
  To: broonie-DgEjT+Ai2ygdnm+yROfE0A,
	fabio.estevam-KZfg59tc24xl57MIdRCFDg,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w, Jean-Michel Hautbois

This serie adds two simple controls on resistor and voltage for MicBias.

Jean-Michel Hautbois (2):
  audio: sgtl5000: Add MicBias resistor support in DT
  audio: sgtl5000: Add MicBias voltage support

 .../devicetree/bindings/sound/sgtl5000.txt         | 13 +++++
 sound/soc/codecs/sgtl5000.c                        | 68 ++++++++++++++++++++--
 2 files changed, 77 insertions(+), 4 deletions(-)

-- 
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	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] audio: sgtl5000: Add MicBias resistor support in DT
       [not found] ` <1413268992-15248-1-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
@ 2014-10-14  6:43   ` Jean-Michel Hautbois
  2014-10-14  8:03     ` Mark Brown
  2014-10-14  6:43   ` [PATCH v2 2/2] audio: sgtl5000: Add MicBias voltage support Jean-Michel Hautbois
  1 sibling, 1 reply; 5+ messages in thread
From: Jean-Michel Hautbois @ 2014-10-14  6:43 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.

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

diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt
index 955df60..d6ec927 100644
--- a/Documentation/devicetree/bindings/sound/sgtl5000.txt
+++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt
@@ -7,10 +7,18 @@ Required properties:
 
 - clocks : the clock provider of SYS_MCLK
 
+- micbias-resistor-k-ohms : the bias resistor to be used in kOmhs
+	The resistor can take values of 2k, 4k or 8k.
+	If set to 0 it will be off.
+	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..b2c2ed7 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -16,6 +16,7 @@
 #include <linux/pm.h>
 #include <linux/i2c.h>
 #include <linux/clk.h>
+#include <linux/log2.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
@@ -121,6 +122,13 @@ struct ldo_regulator {
 	bool enabled;
 };
 
+enum sgtl5000_micbias_resistor {
+	SGTL5000_MICBIAS_OFF = 0,
+	SGTL5000_MICBIAS_2K = 2,
+	SGTL5000_MICBIAS_4K = 4,
+	SGTL5000_MICBIAS_8K = 8,
+};
+
 /* sgtl5000 private structure in codec */
 struct sgtl5000_priv {
 	int sysclk;	/* sysclk rate */
@@ -131,6 +139,7 @@ struct sgtl5000_priv {
 	struct regmap *regmap;
 	struct clk *mclk;
 	int revision;
+	u8 micbias_resistor;
 };
 
 /*
@@ -145,12 +154,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 +1337,9 @@ 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);
+	snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
+			SGTL5000_BIAS_R_MASK,
+			sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
 
 	/*
 	 * disable DAP
@@ -1418,6 +1431,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 +1485,38 @@ 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,
+			"micbias-resistor-k-ohms", &value)) {
+			switch (value) {
+			case SGTL5000_MICBIAS_OFF:
+				sgtl5000->micbias_resistor = 0;
+				break;
+			case SGTL5000_MICBIAS_2K:
+				sgtl5000->micbias_resistor = 1;
+				break;
+			case SGTL5000_MICBIAS_4K:
+				sgtl5000->micbias_resistor = 2;
+				break;
+			case SGTL5000_MICBIAS_8K:
+				sgtl5000->micbias_resistor = 3;
+				break;
+			default:
+				sgtl5000->micbias_resistor = 2;
+				dev_err(&client->dev,
+					"Unsuitable MicBias resistor\n");
+			}
+		} else {
+			/* default is 4Kohms */
+			sgtl5000->micbias_resistor = 2;
+		}
+				dev_err(&client->dev,
+					"Unsuitable MicBias resistor\n");
+			}
+		} else {
+		}
+	}
+
 	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] 5+ messages in thread

* [PATCH v2 2/2] audio: sgtl5000: Add MicBias voltage support
       [not found] ` <1413268992-15248-1-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
  2014-10-14  6:43   ` [PATCH v2 1/2] audio: sgtl5000: Add MicBias resistor support " Jean-Michel Hautbois
@ 2014-10-14  6:43   ` Jean-Michel Hautbois
       [not found]     ` <1413268992-15248-3-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Jean-Michel Hautbois @ 2014-10-14  6:43 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 to specify a bias different than default (1.25V).
This adds a property in sgtl5000 codec.
The property is specified in milli-volts so that it is coherent with datasheet.

Signed-off-by: Jean-Michel Hautbois <jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
---
 Documentation/devicetree/bindings/sound/sgtl5000.txt |  7 ++++++-
 sound/soc/codecs/sgtl5000.c                          | 13 +++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt
index d6ec927..1aab403 100644
--- a/Documentation/devicetree/bindings/sound/sgtl5000.txt
+++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt
@@ -13,6 +13,10 @@ Required properties:
 	If this node is not mentioned or if the value is unknown, then
 	micbias	resistor is set to 4K.
 
+- micbias-voltage-m-volts : the bias voltage to be used in mVolts
+	The voltage can take values from 1.25V to 3V by 250mV steps
+	If this node is not mentionned or the value is unknown, then
+	the value is set to 1.25V.
 
 Example:
 
@@ -20,5 +24,6 @@ codec: sgtl5000@0a {
 	compatible = "fsl,sgtl5000";
 	reg = <0x0a>;
 	clocks = <&clks 150>;
-	sgtl5000-micbias-resistor = <1>;
+	micbias-resistor-k-ohms = <2>;
+	micbias-voltage-m-volts = <2250>;
 };
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index b2c2ed7..8611cfb 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -140,6 +140,7 @@ struct sgtl5000_priv {
 	struct clk *mclk;
 	int revision;
 	u8 micbias_resistor;
+	u8 micbias_voltage;
 };
 
 /*
@@ -1341,6 +1342,9 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
 			SGTL5000_BIAS_R_MASK,
 			sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
 
+	snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
+			SGTL5000_BIAS_R_MASK,
+			sgtl5000->micbias_voltage << SGTL5000_BIAS_R_SHIFT);
 	/*
 	 * disable DAP
 	 * TODO:
@@ -1510,10 +1514,19 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
 			/* default is 4Kohms */
 			sgtl5000->micbias_resistor = 2;
 		}
+		if (!of_property_read_u32(np,
+			"micbias-voltage-m-volts", &value)) {
+			/* 1250mV => 0 */
+			/* steps of 250mV */
+			if ((value >= 1250) && (value <= 3000))
+				sgtl5000->micbias_voltage = (value / 250) - 5;
+			else {
+				sgtl5000->micbias_voltage = 0;
 				dev_err(&client->dev,
 					"Unsuitable MicBias resistor\n");
 			}
 		} else {
+			sgtl5000->micbias_voltage = 0;
 		}
 	}
 
-- 
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] 5+ messages in thread

* Re: [PATCH v2 1/2] audio: sgtl5000: Add MicBias resistor support in DT
  2014-10-14  6:43   ` [PATCH v2 1/2] audio: sgtl5000: Add MicBias resistor support " Jean-Michel Hautbois
@ 2014-10-14  8:03     ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2014-10-14  8:03 UTC (permalink / raw)
  To: Jean-Michel Hautbois; +Cc: fabio.estevam, devicetree, alsa-devel, nicoleotsuka


[-- Attachment #1.1: Type: text/plain, Size: 298 bytes --]

On Tue, Oct 14, 2014 at 08:43:11AM +0200, 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.

Applied, thanks.

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

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

* Re: [PATCH v2 2/2] audio: sgtl5000: Add MicBias voltage support
       [not found]     ` <1413268992-15248-3-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
@ 2014-10-14  8:03       ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2014-10-14  8:03 UTC (permalink / raw)
  To: Jean-Michel Hautbois
  Cc: fabio.estevam-KZfg59tc24xl57MIdRCFDg,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	nicoleotsuka-Re5JQEeQqe8AvxtiuMwx3w

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

On Tue, Oct 14, 2014 at 08:43:12AM +0200, Jean-Michel Hautbois wrote:
> Some systems may require to specify a bias different than default (1.25V).
> This adds a property in sgtl5000 codec.
> The property is specified in milli-volts so that it is coherent with datasheet.

Applied, thanks.

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

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

end of thread, other threads:[~2014-10-14  8:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-14  6:43 [PATCH v2 0/2] sgtl5000: Add controls for MicBias in DT Jean-Michel Hautbois
     [not found] ` <1413268992-15248-1-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
2014-10-14  6:43   ` [PATCH v2 1/2] audio: sgtl5000: Add MicBias resistor support " Jean-Michel Hautbois
2014-10-14  8:03     ` Mark Brown
2014-10-14  6:43   ` [PATCH v2 2/2] audio: sgtl5000: Add MicBias voltage support Jean-Michel Hautbois
     [not found]     ` <1413268992-15248-3-git-send-email-jean-michel.hautbois-B+Q8N6RmIDZBDgjK7y7TUQ@public.gmane.org>
2014-10-14  8:03       ` Mark Brown

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