提交 bd0593f5 编写于 作者: J Jean-Michel Hautbois 提交者: Mark Brown

ASoC: sgtl5000: Add MicBias resistor support in DT

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: NJean-Michel Hautbois <jean-michel.hautbois@vodalys.com>
Signed-off-by: NMark Brown <broonie@kernel.org>
上级 7f6d75d7
...@@ -7,10 +7,18 @@ Required properties: ...@@ -7,10 +7,18 @@ Required properties:
- clocks : the clock provider of SYS_MCLK - 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: Example:
codec: sgtl5000@0a { codec: sgtl5000@0a {
compatible = "fsl,sgtl5000"; compatible = "fsl,sgtl5000";
reg = <0x0a>; reg = <0x0a>;
clocks = <&clks 150>; clocks = <&clks 150>;
sgtl5000-micbias-resistor = <1>;
}; };
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/log2.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/regulator/driver.h> #include <linux/regulator/driver.h>
#include <linux/regulator/machine.h> #include <linux/regulator/machine.h>
...@@ -121,6 +122,13 @@ struct ldo_regulator { ...@@ -121,6 +122,13 @@ struct ldo_regulator {
bool enabled; 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 */ /* sgtl5000 private structure in codec */
struct sgtl5000_priv { struct sgtl5000_priv {
int sysclk; /* sysclk rate */ int sysclk; /* sysclk rate */
...@@ -131,6 +139,7 @@ struct sgtl5000_priv { ...@@ -131,6 +139,7 @@ struct sgtl5000_priv {
struct regmap *regmap; struct regmap *regmap;
struct clk *mclk; struct clk *mclk;
int revision; int revision;
u8 micbias_resistor;
}; };
/* /*
...@@ -145,12 +154,14 @@ struct sgtl5000_priv { ...@@ -145,12 +154,14 @@ struct sgtl5000_priv {
static int mic_bias_event(struct snd_soc_dapm_widget *w, static int mic_bias_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event) struct snd_kcontrol *kcontrol, int event)
{ {
struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(w->codec);
switch (event) { switch (event) {
case SND_SOC_DAPM_POST_PMU: 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, snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL,
SGTL5000_BIAS_R_MASK, SGTL5000_BIAS_R_MASK,
SGTL5000_BIAS_R_4k << SGTL5000_BIAS_R_SHIFT); sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
break; break;
case SND_SOC_DAPM_PRE_PMD: case SND_SOC_DAPM_PRE_PMD:
...@@ -1327,7 +1338,9 @@ static int sgtl5000_probe(struct snd_soc_codec *codec) ...@@ -1327,7 +1338,9 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
SGTL5000_HP_ZCD_EN | SGTL5000_HP_ZCD_EN |
SGTL5000_ADC_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 * disable DAP
...@@ -1419,6 +1432,8 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, ...@@ -1419,6 +1432,8 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
struct sgtl5000_priv *sgtl5000; struct sgtl5000_priv *sgtl5000;
int ret, reg, rev; int ret, reg, rev;
unsigned int mclk; unsigned int mclk;
struct device_node *np = client->dev.of_node;
u32 value;
sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv), sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv),
GFP_KERNEL); GFP_KERNEL);
...@@ -1471,6 +1486,38 @@ static int sgtl5000_i2c_probe(struct i2c_client *client, ...@@ -1471,6 +1486,38 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev); dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev);
sgtl5000->revision = 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); i2c_set_clientdata(client, sgtl5000);
/* Ensure sgtl5000 will start with sane register values */ /* Ensure sgtl5000 will start with sane register values */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册