Lines Matching +full:mic +full:- +full:in +full:- +full:differential
1 // SPDX-License-Identifier: GPL-2.0-only
3 * es8316.c -- es8316 ALSA SoC audio driver
6 * Authors: David Yang <yangxiaohua@everest-semi.com>,
21 #include <sound/soc-dapm.h>
26 /* In slave mode at single speed, the codec is documented as accepting 5
51 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9600, 50, 1);
52 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9600, 50, 1);
53 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_max_gain_tlv, -650, 150, 0);
54 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_min_gain_tlv, -1200, 150, 0);
55 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_target_tlv, -1650, 150, 0);
57 0, 4, TLV_DB_SCALE_ITEM(-1200, 150, 0),
58 8, 11, TLV_DB_SCALE_ITEM(-450, 150, 0),
62 0, 0, TLV_DB_SCALE_ITEM(-350, 0, 0),
71 0, 0, TLV_DB_SCALE_ITEM(-4800, 0, 0),
72 1, 3, TLV_DB_SCALE_ITEM(-2400, 1200, 0),
105 SOC_SINGLE("Mic Boost Switch", ES8316_ADC_D2SEPGA, 0, 1, 0),
132 "lin1-rin1",
133 "lin2-rin2",
134 "lin1-rin1 with 20db Boost",
135 "lin2-rin2 with 20db Boost"
162 "lin1-rin1",
163 "lin2-rin2",
164 "lin-rin with Boost",
165 "lin-rin with Boost and PGA"
207 SND_SOC_DAPM_SUPPLY("Mic Bias", ES8316_SYS_PDN, 5, 1, NULL, 0),
214 SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM, 0, 0,
223 SND_SOC_DAPM_MUX("Digital Mic Mux", SND_SOC_NOPM, 0, 0,
229 SND_SOC_DAPM_AIF_IN("I2S IN", "I2S1 Playback", 0,
272 * be explicitly unset in order to enable HP output
285 {"MIC1", NULL, "Mic Bias"},
286 {"MIC2", NULL, "Mic Bias"},
292 {"Differential Mux", "lin1-rin1", "MIC1"},
293 {"Differential Mux", "lin2-rin2", "MIC2"},
294 {"Line input PGA", NULL, "Differential Mux"},
306 {"Digital Mic Mux", "dmic disable", "Mono ADC"},
308 {"I2S OUT", NULL, "Digital Mic Mux"},
311 {"DAC Source Mux", "LDATA TO LDAC, RDATA TO RDAC", "I2S IN"},
322 {"Left Headphone Mux", "lin-rin with Boost and PGA", "Line input PGA"},
323 {"Right Headphone Mux", "lin-rin with Boost and PGA", "Line input PGA"},
361 struct snd_soc_component *component = codec_dai->component; in es8316_set_dai_sysclk()
366 es8316->sysclk = freq; in es8316_set_dai_sysclk()
369 es8316->sysclk_constraints.list = NULL; in es8316_set_dai_sysclk()
370 es8316->sysclk_constraints.count = 0; in es8316_set_dai_sysclk()
375 ret = clk_set_rate(es8316->mclk, freq); in es8316_set_dai_sysclk()
380 * by the codec running in slave mode. in es8316_set_dai_sysclk()
386 es8316->allowed_rates[count++] = freq / ratio; in es8316_set_dai_sysclk()
389 es8316->sysclk_constraints.list = es8316->allowed_rates; in es8316_set_dai_sysclk()
390 es8316->sysclk_constraints.count = count; in es8316_set_dai_sysclk()
398 struct snd_soc_component *component = codec_dai->component; in es8316_set_dai_fmt()
408 dev_err(component->dev, "Codec driver only supports I2S format\n"); in es8316_set_dai_fmt()
409 return -EINVAL; in es8316_set_dai_fmt()
427 return -EINVAL; in es8316_set_dai_fmt()
437 /* Enable BCLK and MCLK inputs in slave mode */ in es8316_set_dai_fmt()
447 struct snd_soc_component *component = dai->component; in es8316_pcm_startup()
450 if (es8316->sysclk_constraints.list) in es8316_pcm_startup()
451 snd_pcm_hw_constraint_list(substream->runtime, 0, in es8316_pcm_startup()
453 &es8316->sysclk_constraints); in es8316_pcm_startup()
462 struct snd_soc_component *component = dai->component; in es8316_pcm_hw_params()
473 if (es8316->sysclk % ratio != 0) in es8316_pcm_hw_params()
475 if (es8316->sysclk / ratio == params_rate(params)) in es8316_pcm_hw_params()
479 return -EINVAL; in es8316_pcm_hw_params()
480 lrck_divider = es8316->sysclk / params_rate(params); in es8316_pcm_hw_params()
500 return -EINVAL; in es8316_pcm_hw_params()
517 snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, in es8316_mute()
562 snd_soc_dapm_force_enable_pin_unlocked(dapm, "Mic Bias"); in es8316_enable_micbias_for_mic_gnd_short_detect()
575 snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Bias"); in es8316_disable_micbias_for_mic_gnd_short_detect()
585 struct snd_soc_component *comp = es8316->component; in es8316_irq()
588 mutex_lock(&es8316->lock); in es8316_irq()
590 regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); in es8316_irq()
592 goto out; /* Powered-down / reset */ in es8316_irq()
595 if (!es8316->jack) in es8316_irq()
598 if (es8316->jd_inverted) in es8316_irq()
601 dev_dbg(comp->dev, "gpio flags %#04x\n", flags); in es8316_irq()
604 if (es8316->jack->status & SND_JACK_MICROPHONE) in es8316_irq()
607 if (es8316->jack->status & SND_JACK_HEADPHONE) { in es8316_irq()
608 snd_soc_jack_report(es8316->jack, 0, in es8316_irq()
610 dev_dbg(comp->dev, "jack unplugged\n"); in es8316_irq()
612 } else if (!(es8316->jack->status & SND_JACK_HEADPHONE)) { in es8316_irq()
615 regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); in es8316_irq()
616 if (es8316->jd_inverted) in es8316_irq()
618 dev_dbg(comp->dev, "gpio flags %#04x\n", flags); in es8316_irq()
624 snd_soc_jack_report(es8316->jack, in es8316_irq()
627 /* Keep mic-gnd-short detection on for button press */ in es8316_irq()
630 snd_soc_jack_report(es8316->jack, in es8316_irq()
633 /* No longer need mic-gnd-short detection */ in es8316_irq()
636 } else if (es8316->jack->status & SND_JACK_MICROPHONE) { in es8316_irq()
640 snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); in es8316_irq()
643 snd_soc_jack_report(es8316->jack, in es8316_irq()
650 mutex_unlock(&es8316->lock); in es8316_irq()
660 * Init es8316->jd_inverted here and not in the probe, as we cannot in es8316_enable_jack_detect()
661 * guarantee that the bytchr-es8316 driver, which might set this in es8316_enable_jack_detect()
664 es8316->jd_inverted = device_property_read_bool(component->dev, in es8316_enable_jack_detect()
665 "everest,jack-detect-inverted"); in es8316_enable_jack_detect()
667 mutex_lock(&es8316->lock); in es8316_enable_jack_detect()
669 es8316->jack = jack; in es8316_enable_jack_detect()
671 if (es8316->jack->status & SND_JACK_MICROPHONE) in es8316_enable_jack_detect()
678 mutex_unlock(&es8316->lock); in es8316_enable_jack_detect()
681 enable_irq(es8316->irq); in es8316_enable_jack_detect()
682 es8316_irq(es8316->irq, es8316); in es8316_enable_jack_detect()
689 if (!es8316->jack) in es8316_disable_jack_detect()
692 disable_irq(es8316->irq); in es8316_disable_jack_detect()
694 mutex_lock(&es8316->lock); in es8316_disable_jack_detect()
699 if (es8316->jack->status & SND_JACK_MICROPHONE) { in es8316_disable_jack_detect()
701 snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); in es8316_disable_jack_detect()
704 es8316->jack = NULL; in es8316_disable_jack_detect()
706 mutex_unlock(&es8316->lock); in es8316_disable_jack_detect()
725 es8316->component = component; in es8316_probe()
727 es8316->mclk = devm_clk_get_optional(component->dev, "mclk"); in es8316_probe()
728 if (IS_ERR(es8316->mclk)) { in es8316_probe()
729 dev_err(component->dev, "unable to get mclk\n"); in es8316_probe()
730 return PTR_ERR(es8316->mclk); in es8316_probe()
732 if (!es8316->mclk) in es8316_probe()
733 dev_warn(component->dev, "assuming static mclk\n"); in es8316_probe()
735 ret = clk_prepare_enable(es8316->mclk); in es8316_probe()
737 dev_err(component->dev, "unable to enable mclk\n"); in es8316_probe()
755 * but here is a vendor-provided value that improves volume in es8316_probe()
767 clk_disable_unprepare(es8316->mclk); in es8316_remove()
774 regcache_cache_only(es8316->regmap, false); in es8316_resume()
775 regcache_sync(es8316->regmap); in es8316_resume()
784 regcache_cache_only(es8316->regmap, true); in es8316_suspend()
785 regcache_mark_dirty(es8316->regmap); in es8316_suspend()
827 struct device *dev = &i2c_client->dev; in es8316_i2c_probe()
831 es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv), in es8316_i2c_probe()
834 return -ENOMEM; in es8316_i2c_probe()
838 es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap); in es8316_i2c_probe()
839 if (IS_ERR(es8316->regmap)) in es8316_i2c_probe()
840 return PTR_ERR(es8316->regmap); in es8316_i2c_probe()
842 es8316->irq = i2c_client->irq; in es8316_i2c_probe()
843 mutex_init(&es8316->lock); in es8316_i2c_probe()
845 ret = devm_request_threaded_irq(dev, es8316->irq, NULL, es8316_irq, in es8316_i2c_probe()
849 dev_warn(dev, "Failed to get IRQ %d: %d\n", es8316->irq, ret); in es8316_i2c_probe()
850 es8316->irq = -ENXIO; in es8316_i2c_probe()
853 return devm_snd_soc_register_component(&i2c_client->dev, in es8316_i2c_probe()
893 MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com>");