Lines Matching +full:dmic +full:- +full:freq

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>
50 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(dac_vol_tlv, -9600, 50, 1);
51 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(adc_vol_tlv, -9600, 50, 1);
52 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_max_gain_tlv, -650, 150, 0);
53 static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(alc_min_gain_tlv, -1200, 150, 0);
56 0, 10, TLV_DB_SCALE_ITEM(-1650, 150, 0),
57 11, 11, TLV_DB_SCALE_ITEM(-150, 0, 0),
61 0, 4, TLV_DB_SCALE_ITEM(-1200, 150, 0),
62 8, 11, TLV_DB_SCALE_ITEM(-450, 150, 0),
66 0, 0, TLV_DB_SCALE_ITEM(-350, 0, 0),
75 0, 0, TLV_DB_SCALE_ITEM(-4800, 0, 0),
76 1, 3, TLV_DB_SCALE_ITEM(-2400, 1200, 0),
136 "lin1-rin1",
137 "lin2-rin2",
138 "lin1-rin1 with 20db Boost",
139 "lin2-rin2 with 20db Boost"
151 "dmic disable",
152 "dmic data at high level",
153 "dmic data at low level",
166 "lin1-rin1",
167 "lin2-rin2",
168 "lin-rin with Boost",
169 "lin-rin with Boost and PGA"
213 SND_SOC_DAPM_INPUT("DMIC"),
296 {"Differential Mux", "lin1-rin1", "MIC1"},
297 {"Differential Mux", "lin2-rin2", "MIC2"},
310 {"Digital Mic Mux", "dmic disable", "Mono ADC"},
326 {"Left Headphone Mux", "lin-rin with Boost and PGA", "Line input PGA"},
327 {"Right Headphone Mux", "lin-rin with Boost and PGA", "Line input PGA"},
363 int clk_id, unsigned int freq, int dir) in es8316_set_dai_sysclk() argument
365 struct snd_soc_component *component = codec_dai->component; in es8316_set_dai_sysclk()
370 es8316->sysclk = freq; in es8316_set_dai_sysclk()
371 es8316->sysclk_constraints.list = NULL; in es8316_set_dai_sysclk()
372 es8316->sysclk_constraints.count = 0; in es8316_set_dai_sysclk()
374 if (freq == 0) in es8316_set_dai_sysclk()
377 ret = clk_set_rate(es8316->mclk, freq); in es8316_set_dai_sysclk()
387 if (freq % ratio == 0) in es8316_set_dai_sysclk()
388 es8316->allowed_rates[count++] = freq / ratio; in es8316_set_dai_sysclk()
392 es8316->sysclk_constraints.list = es8316->allowed_rates; in es8316_set_dai_sysclk()
393 es8316->sysclk_constraints.count = count; in es8316_set_dai_sysclk()
402 struct snd_soc_component *component = codec_dai->component; in es8316_set_dai_fmt()
412 dev_err(component->dev, "Codec driver only supports I2S format\n"); in es8316_set_dai_fmt()
413 return -EINVAL; in es8316_set_dai_fmt()
431 return -EINVAL; in es8316_set_dai_fmt()
451 struct snd_soc_component *component = dai->component; in es8316_pcm_startup()
454 if (es8316->sysclk_constraints.list) in es8316_pcm_startup()
455 snd_pcm_hw_constraint_list(substream->runtime, 0, in es8316_pcm_startup()
457 &es8316->sysclk_constraints); in es8316_pcm_startup()
466 struct snd_soc_component *component = dai->component; in es8316_pcm_hw_params()
472 unsigned int clk = es8316->sysclk / 2; in es8316_pcm_hw_params()
493 if (clk == es8316->sysclk) in es8316_pcm_hw_params()
494 return -EINVAL; in es8316_pcm_hw_params()
495 clk = es8316->sysclk; in es8316_pcm_hw_params()
501 if (clk != es8316->sysclk) { in es8316_pcm_hw_params()
528 return -EINVAL; in es8316_pcm_hw_params()
545 snd_soc_component_update_bits(dai->component, ES8316_DAC_SET1, 0x20, in es8316_mute()
613 struct snd_soc_component *comp = es8316->component; in es8316_irq()
616 mutex_lock(&es8316->lock); in es8316_irq()
618 regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); in es8316_irq()
620 goto out; /* Powered-down / reset */ in es8316_irq()
623 if (!es8316->jack) in es8316_irq()
626 if (es8316->jd_inverted) in es8316_irq()
629 dev_dbg(comp->dev, "gpio flags %#04x\n", flags); in es8316_irq()
632 if (es8316->jack->status & SND_JACK_MICROPHONE) in es8316_irq()
635 if (es8316->jack->status & SND_JACK_HEADPHONE) { in es8316_irq()
636 snd_soc_jack_report(es8316->jack, 0, in es8316_irq()
638 dev_dbg(comp->dev, "jack unplugged\n"); in es8316_irq()
640 } else if (!(es8316->jack->status & SND_JACK_HEADPHONE)) { in es8316_irq()
643 regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags); in es8316_irq()
644 if (es8316->jd_inverted) in es8316_irq()
646 dev_dbg(comp->dev, "gpio flags %#04x\n", flags); in es8316_irq()
652 snd_soc_jack_report(es8316->jack, in es8316_irq()
655 /* Keep mic-gnd-short detection on for button press */ in es8316_irq()
658 snd_soc_jack_report(es8316->jack, in es8316_irq()
661 /* No longer need mic-gnd-short detection */ in es8316_irq()
664 } else if (es8316->jack->status & SND_JACK_MICROPHONE) { in es8316_irq()
668 snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); in es8316_irq()
671 snd_soc_jack_report(es8316->jack, in es8316_irq()
678 mutex_unlock(&es8316->lock); in es8316_irq()
688 * Init es8316->jd_inverted here and not in the probe, as we cannot in es8316_enable_jack_detect()
689 * guarantee that the bytchr-es8316 driver, which might set this in es8316_enable_jack_detect()
692 es8316->jd_inverted = device_property_read_bool(component->dev, in es8316_enable_jack_detect()
693 "everest,jack-detect-inverted"); in es8316_enable_jack_detect()
695 mutex_lock(&es8316->lock); in es8316_enable_jack_detect()
697 es8316->jack = jack; in es8316_enable_jack_detect()
699 if (es8316->jack->status & SND_JACK_MICROPHONE) in es8316_enable_jack_detect()
706 mutex_unlock(&es8316->lock); in es8316_enable_jack_detect()
709 enable_irq(es8316->irq); in es8316_enable_jack_detect()
710 es8316_irq(es8316->irq, es8316); in es8316_enable_jack_detect()
717 if (!es8316->jack) in es8316_disable_jack_detect()
720 disable_irq(es8316->irq); in es8316_disable_jack_detect()
722 mutex_lock(&es8316->lock); in es8316_disable_jack_detect()
727 if (es8316->jack->status & SND_JACK_MICROPHONE) { in es8316_disable_jack_detect()
729 snd_soc_jack_report(es8316->jack, 0, SND_JACK_BTN_0); in es8316_disable_jack_detect()
732 es8316->jack = NULL; in es8316_disable_jack_detect()
734 mutex_unlock(&es8316->lock); in es8316_disable_jack_detect()
753 es8316->component = component; in es8316_probe()
755 es8316->mclk = devm_clk_get_optional(component->dev, "mclk"); in es8316_probe()
756 if (IS_ERR(es8316->mclk)) { in es8316_probe()
757 dev_err(component->dev, "unable to get mclk\n"); in es8316_probe()
758 return PTR_ERR(es8316->mclk); in es8316_probe()
760 if (!es8316->mclk) in es8316_probe()
761 dev_warn(component->dev, "assuming static mclk\n"); in es8316_probe()
763 ret = clk_prepare_enable(es8316->mclk); in es8316_probe()
765 dev_err(component->dev, "unable to enable mclk\n"); in es8316_probe()
783 * but here is a vendor-provided value that improves volume in es8316_probe()
795 clk_disable_unprepare(es8316->mclk); in es8316_remove()
802 regcache_cache_only(es8316->regmap, false); in es8316_resume()
803 regcache_sync(es8316->regmap); in es8316_resume()
812 regcache_cache_only(es8316->regmap, true); in es8316_suspend()
813 regcache_mark_dirty(es8316->regmap); in es8316_suspend()
856 struct device *dev = &i2c_client->dev; in es8316_i2c_probe()
860 es8316 = devm_kzalloc(&i2c_client->dev, sizeof(struct es8316_priv), in es8316_i2c_probe()
863 return -ENOMEM; in es8316_i2c_probe()
867 es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap); in es8316_i2c_probe()
868 if (IS_ERR(es8316->regmap)) in es8316_i2c_probe()
869 return PTR_ERR(es8316->regmap); in es8316_i2c_probe()
871 es8316->irq = i2c_client->irq; in es8316_i2c_probe()
872 mutex_init(&es8316->lock); in es8316_i2c_probe()
874 if (es8316->irq > 0) { in es8316_i2c_probe()
875 ret = devm_request_threaded_irq(dev, es8316->irq, NULL, es8316_irq, in es8316_i2c_probe()
879 dev_warn(dev, "Failed to get IRQ %d: %d\n", es8316->irq, ret); in es8316_i2c_probe()
880 es8316->irq = -ENXIO; in es8316_i2c_probe()
884 return devm_snd_soc_register_component(&i2c_client->dev, in es8316_i2c_probe()
924 MODULE_AUTHOR("David Yang <yangxiaohua@everest-semi.com>");