diff options
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r-- | sound/soc/codecs/lm4857.c | 112 | ||||
-rw-r--r-- | sound/soc/codecs/max98090.c | 13 | ||||
-rw-r--r-- | sound/soc/codecs/max98357a.c | 3 | ||||
-rw-r--r-- | sound/soc/codecs/sta32x.c | 14 |
4 files changed, 46 insertions, 96 deletions
diff --git a/sound/soc/codecs/lm4857.c b/sound/soc/codecs/lm4857.c index 79ad4cbdcdd4..99ffc49aa779 100644 --- a/sound/soc/codecs/lm4857.c +++ b/sound/soc/codecs/lm4857.c @@ -23,11 +23,6 @@ #include <sound/soc.h> #include <sound/tlv.h> -struct lm4857 { - struct regmap *regmap; - uint8_t mode; -}; - static const struct reg_default lm4857_default_regs[] = { { 0x0, 0x00 }, { 0x1, 0x00 }, @@ -46,64 +41,33 @@ static const struct reg_default lm4857_default_regs[] = { #define LM4857_WAKEUP 5 #define LM4857_EPGAIN 4 -static int lm4857_get_mode(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct lm4857 *lm4857 = snd_soc_codec_get_drvdata(codec); - - ucontrol->value.integer.value[0] = lm4857->mode; - - return 0; -} - -static int lm4857_set_mode(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); - struct lm4857 *lm4857 = snd_soc_codec_get_drvdata(codec); - uint8_t value = ucontrol->value.integer.value[0]; - - lm4857->mode = value; - - if (codec->dapm.bias_level == SND_SOC_BIAS_ON) - regmap_update_bits(lm4857->regmap, LM4857_CTRL, 0x0F, value + 6); - - return 1; -} - -static int lm4857_set_bias_level(struct snd_soc_codec *codec, - enum snd_soc_bias_level level) -{ - struct lm4857 *lm4857 = snd_soc_codec_get_drvdata(codec); - - switch (level) { - case SND_SOC_BIAS_ON: - regmap_update_bits(lm4857->regmap, LM4857_CTRL, 0x0F, - lm4857->mode + 6); - break; - case SND_SOC_BIAS_STANDBY: - regmap_update_bits(lm4857->regmap, LM4857_CTRL, 0x0F, 0); - break; - default: - break; - } - - return 0; -} +static const unsigned int lm4857_mode_values[] = { + 0, + 6, + 7, + 8, + 9, +}; -static const char *lm4857_mode[] = { +static const char * const lm4857_mode_texts[] = { + "Off", "Earpiece", "Loudspeaker", "Loudspeaker + Headphone", "Headphone", }; -static SOC_ENUM_SINGLE_EXT_DECL(lm4857_mode_enum, lm4857_mode); +static SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(lm4857_mode_enum, + LM4857_CTRL, 0, 0xf, lm4857_mode_texts, lm4857_mode_values); + +static const struct snd_kcontrol_new lm4857_mode_ctrl = + SOC_DAPM_ENUM("Mode", lm4857_mode_enum); static const struct snd_soc_dapm_widget lm4857_dapm_widgets[] = { SND_SOC_DAPM_INPUT("IN"), + SND_SOC_DAPM_DEMUX("Mode", SND_SOC_NOPM, 0, 0, &lm4857_mode_ctrl), + SND_SOC_DAPM_OUTPUT("LS"), SND_SOC_DAPM_OUTPUT("HP"), SND_SOC_DAPM_OUTPUT("EP"), @@ -125,24 +89,18 @@ static const struct snd_kcontrol_new lm4857_controls[] = { LM4857_WAKEUP, 1, 0), SOC_SINGLE("Earpiece 6dB Playback Switch", LM4857_CTRL, LM4857_EPGAIN, 1, 0), - - SOC_ENUM_EXT("Mode", lm4857_mode_enum, - lm4857_get_mode, lm4857_set_mode), }; -/* There is a demux between the input signal and the output signals. - * Currently there is no easy way to model it in ASoC and since it does not make - * much of a difference in practice simply connect the input direclty to the - * outputs. */ static const struct snd_soc_dapm_route lm4857_routes[] = { - {"LS", NULL, "IN"}, - {"HP", NULL, "IN"}, - {"EP", NULL, "IN"}, + { "Mode", NULL, "IN" }, + { "LS", "Loudspeaker", "Mode" }, + { "LS", "Loudspeaker + Headphone", "Mode" }, + { "HP", "Headphone", "Mode" }, + { "HP", "Loudspeaker + Headphone", "Mode" }, + { "EP", "Earpiece", "Mode" }, }; -static struct snd_soc_codec_driver soc_codec_dev_lm4857 = { - .set_bias_level = lm4857_set_bias_level, - +static struct snd_soc_component_driver lm4857_component_driver = { .controls = lm4857_controls, .num_controls = ARRAY_SIZE(lm4857_controls), .dapm_widgets = lm4857_dapm_widgets, @@ -165,25 +123,14 @@ static const struct regmap_config lm4857_regmap_config = { static int lm4857_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { - struct lm4857 *lm4857; - - lm4857 = devm_kzalloc(&i2c->dev, sizeof(*lm4857), GFP_KERNEL); - if (!lm4857) - return -ENOMEM; - - i2c_set_clientdata(i2c, lm4857); - - lm4857->regmap = devm_regmap_init_i2c(i2c, &lm4857_regmap_config); - if (IS_ERR(lm4857->regmap)) - return PTR_ERR(lm4857->regmap); + struct regmap *regmap; - return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_lm4857, NULL, 0); -} + regmap = devm_regmap_init_i2c(i2c, &lm4857_regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); -static int lm4857_i2c_remove(struct i2c_client *i2c) -{ - snd_soc_unregister_codec(&i2c->dev); - return 0; + return devm_snd_soc_register_component(&i2c->dev, + &lm4857_component_driver, NULL, 0); } static const struct i2c_device_id lm4857_i2c_id[] = { @@ -198,7 +145,6 @@ static struct i2c_driver lm4857_i2c_driver = { .owner = THIS_MODULE, }, .probe = lm4857_i2c_probe, - .remove = lm4857_i2c_remove, .id_table = lm4857_i2c_id, }; diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index c2306268cab8..679f0a0f7039 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c @@ -2419,6 +2419,8 @@ static int max98090_probe(struct snd_soc_codec *codec) struct max98090_cdata *cdata; enum max98090_type devtype; int ret = 0; + int err; + unsigned int micbias; dev_dbg(codec->dev, "max98090_probe\n"); @@ -2503,8 +2505,17 @@ static int max98090_probe(struct snd_soc_codec *codec) snd_soc_write(codec, M98090_REG_BIAS_CONTROL, M98090_VCM_MODE_MASK); + err = device_property_read_u32(codec->dev, "maxim,micbias", &micbias); + if (err) { + micbias = M98090_MBVSEL_2V8; + dev_info(codec->dev, "use default 2.8v micbias\n"); + } else if (micbias < M98090_MBVSEL_2V2 || micbias > M98090_MBVSEL_2V8) { + dev_err(codec->dev, "micbias out of range 0x%x\n", micbias); + micbias = M98090_MBVSEL_2V8; + } + snd_soc_update_bits(codec, M98090_REG_MIC_BIAS_VOLTAGE, - M98090_MBVSEL_MASK, M98090_MBVSEL_2V8); + M98090_MBVSEL_MASK, micbias); max98090_add_widgets(codec); diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c index bf3e933ee895..3a2fda08a893 100644 --- a/sound/soc/codecs/max98357a.c +++ b/sound/soc/codecs/max98357a.c @@ -60,13 +60,12 @@ static int max98357a_codec_probe(struct snd_soc_codec *codec) { struct gpio_desc *sdmode; - sdmode = devm_gpiod_get(codec->dev, "sdmode"); + sdmode = devm_gpiod_get(codec->dev, "sdmode", GPIOD_OUT_LOW); if (IS_ERR(sdmode)) { dev_err(codec->dev, "%s() unable to get sdmode GPIO: %ld\n", __func__, PTR_ERR(sdmode)); return PTR_ERR(sdmode); } - gpiod_direction_output(sdmode, 0); snd_soc_codec_set_drvdata(codec, sdmode); return 0; diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c index ffe6187dce85..60eff36260cb 100644 --- a/sound/soc/codecs/sta32x.c +++ b/sound/soc/codecs/sta32x.c @@ -1095,16 +1095,10 @@ static int sta32x_i2c_probe(struct i2c_client *i2c, #endif /* GPIOs */ - sta32x->gpiod_nreset = devm_gpiod_get(dev, "reset"); - if (IS_ERR(sta32x->gpiod_nreset)) { - ret = PTR_ERR(sta32x->gpiod_nreset); - if (ret != -ENOENT && ret != -ENOSYS) - return ret; - - sta32x->gpiod_nreset = NULL; - } else { - gpiod_direction_output(sta32x->gpiod_nreset, 0); - } + sta32x->gpiod_nreset = devm_gpiod_get_optional(dev, "reset", + GPIOD_OUT_LOW); + if (IS_ERR(sta32x->gpiod_nreset)) + return PTR_ERR(sta32x->gpiod_nreset); /* regulators */ for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) |