Lines Matching +full:dmic +full:- +full:sample +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0-only
3 * wm8995.c -- WM8995 ALSA SoC Audio driver
26 #include <sound/soc-dapm.h>
400 regcache_mark_dirty(wm8995->regmap); \
414 static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
415 static const DECLARE_TLV_DB_SCALE(in1lr_pga_tlv, -1650, 150, 0);
417 static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 150, 0);
420 "Differential", "Single-ended IN1LN", "Single-ended IN1LP"
427 "Differential", "Single-ended IN1RN", "Single-ended IN1RP"
495 dev_dbg(component->dev, "Class W source AIF2DAC\n");
499 dev_dbg(component->dev, "Class W source AIF1DAC2\n");
503 dev_dbg(component->dev, "Class W source AIF1DAC1\n");
507 dev_dbg(component->dev, "DAC mixer setting: %x\n", reg);
514 dev_dbg(component->dev, "Left and right DAC mixers different\n");
519 dev_dbg(component->dev, "Class W enabled\n");
525 dev_dbg(component->dev, "Class W disabled\n");
534 struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
561 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
593 dev_dbg(component->dev, "%s: reg = %#x, val = %#x, mask = %#x\n",
597 while (timeout--) {
604 dev_err(component->dev, "Timed out waiting for DC Servo\n");
610 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
672 int rate;
683 switch (wm8995->sysclk[aif]) {
685 rate = wm8995->mclk[0];
689 rate = wm8995->mclk[1];
693 rate = wm8995->fll[0].out;
697 rate = wm8995->fll[1].out;
700 return -EINVAL;
703 if (rate >= 13500000) {
704 rate /= 2;
707 dev_dbg(component->dev, "Dividing AIF%d clock to %dHz\n",
708 aif + 1, rate);
711 wm8995->aifclk[aif] = rate;
739 if (wm8995->aifclk[0] == wm8995->aifclk[1])
742 if (wm8995->aifclk[0] < wm8995->aifclk[1])
760 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
789 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_LEFT_MIXER_ROUTING,
796 SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8995_AIF1_ADC1_RIGHT_MIXER_ROUTING,
803 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_LEFT_MIXER_ROUTING,
810 SOC_DAPM_SINGLE("DMIC Switch", WM8995_AIF1_ADC2_RIGHT_MIXER_ROUTING,
876 "DMIC",
1066 { "ADCL Mux", "DMIC", "DMIC1L" },
1068 { "ADCR Mux", "DMIC", "DMIC1R" },
1072 { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
1075 { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
1078 { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
1081 { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
1422 struct snd_soc_component *component = dai->component;
1425 switch (dai->id) {
1433 return -EINVAL;
1447 component = dai->component;
1457 dev_err(dai->dev, "Unknown master/slave configuration\n");
1458 return -EINVAL;
1478 dev_err(dai->dev, "Unknown dai format\n");
1479 return -EINVAL;
1493 return -EINVAL;
1513 return -EINVAL;
1517 return -EINVAL;
1535 -1 /* reserved */,
1558 component = dai->component;
1561 switch (dai->id) {
1566 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
1567 wm8995->lrclk_shared[0] */) {
1571 dev_dbg(component->dev, "AIF1 using split LRCLK\n");
1578 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK /* ||
1579 wm8995->lrclk_shared[1] */) {
1583 dev_dbg(component->dev, "AIF2 using split LRCLK\n");
1587 return -EINVAL;
1608 dev_err(dai->dev, "Unsupported word length %u\n",
1610 return -EINVAL;
1613 /* try to find a suitable sample rate */
1618 dev_err(dai->dev, "Sample rate %d is not supported\n",
1620 return -EINVAL;
1624 dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i]);
1625 dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
1626 dai->id + 1, wm8995->aifclk[dai->id], bclk_rate);
1631 - wm8995->aifclk[dai->id]);
1634 - wm8995->aifclk[dai->id]);
1642 dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
1643 dai->id + 1, fs_ratios[best]);
1654 cur_val = (wm8995->aifclk[dai->id] * 10 / bclk_divs[i]) - bclk_rate;
1661 bclk_rate = wm8995->aifclk[dai->id] * 10 / bclk_divs[best];
1662 dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
1666 dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
1683 struct snd_soc_component *component = codec_dai->component;
1686 switch (codec_dai->id) {
1700 return -EINVAL;
1732 fll->clk_ref_div = 0;
1734 fll->clk_ref_div++;
1737 if (fll->clk_ref_div > 3)
1738 return -EINVAL;
1740 pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
1743 fll->outdiv = 3;
1744 while (freq_out * (fll->outdiv + 1) < 90000000) {
1745 fll->outdiv++;
1746 if (fll->outdiv > 63)
1747 return -EINVAL;
1749 freq_out *= fll->outdiv + 1;
1750 pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
1753 fll->fll_fratio = 0;
1755 fll->fll_fratio = 1;
1758 fll->fll_fratio = 2;
1761 fll->fll_fratio = 3;
1764 fll->fll_fratio = 4;
1767 pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
1772 fll->n = Ndiv;
1776 /* Calculate fractional part - scale up so we can round. */
1787 fll->k = K / 10;
1789 pr_debug("N=%x K=%x\n", fll->n, fll->k);
1804 component = dai->component;
1823 return -EINVAL;
1830 return -EINVAL;
1838 return -EINVAL;
1842 if (wm8995->fll[id].src == src &&
1843 wm8995->fll[id].in == freq_in && wm8995->fll[id].out == freq_out)
1846 /* If we're stopping the FLL redo the old config - no
1853 ret = wm8995_get_fll_config(&fll, wm8995->fll[id].in,
1854 wm8995->fll[id].out);
1884 (src - 1));
1890 wm8995->fll[id].in = freq_in;
1891 wm8995->fll[id].out = freq_out;
1892 wm8995->fll[id].src = src;
1911 component = dai->component;
1914 switch (dai->id) {
1920 return -EINVAL;
1925 wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK1;
1926 wm8995->mclk[0] = freq;
1927 dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
1928 dai->id + 1, freq);
1931 wm8995->sysclk[dai->id] = WM8995_SYSCLK_MCLK2;
1932 wm8995->mclk[1] = freq;
1933 dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
1934 dai->id + 1, freq);
1937 wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL1;
1938 dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id + 1);
1941 wm8995->sysclk[dai->id] = WM8995_SYSCLK_FLL2;
1942 dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id + 1);
1946 dev_err(dai->dev, "Unknown clock source %d\n", clk_id);
1947 return -EINVAL;
1968 ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies),
1969 wm8995->supplies);
1973 ret = regcache_sync(wm8995->regmap);
1975 dev_err(component->dev,
1987 regulator_bulk_disable(ARRAY_SIZE(wm8995->supplies),
1988 wm8995->supplies);
2002 wm8995->component = component;
2004 for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++)
2005 wm8995->supplies[i].supply = wm8995_supply_names[i];
2007 ret = devm_regulator_bulk_get(component->dev,
2008 ARRAY_SIZE(wm8995->supplies),
2009 wm8995->supplies);
2011 dev_err(component->dev, "Failed to request supplies: %d\n", ret);
2015 wm8995->disable_nb[0].notifier_call = wm8995_regulator_event_0;
2016 wm8995->disable_nb[1].notifier_call = wm8995_regulator_event_1;
2017 wm8995->disable_nb[2].notifier_call = wm8995_regulator_event_2;
2018 wm8995->disable_nb[3].notifier_call = wm8995_regulator_event_3;
2019 wm8995->disable_nb[4].notifier_call = wm8995_regulator_event_4;
2020 wm8995->disable_nb[5].notifier_call = wm8995_regulator_event_5;
2021 wm8995->disable_nb[6].notifier_call = wm8995_regulator_event_6;
2022 wm8995->disable_nb[7].notifier_call = wm8995_regulator_event_7;
2025 for (i = 0; i < ARRAY_SIZE(wm8995->supplies); i++) {
2027 wm8995->supplies[i].consumer,
2028 &wm8995->disable_nb[i]);
2030 dev_err(component->dev,
2036 ret = regulator_bulk_enable(ARRAY_SIZE(wm8995->supplies),
2037 wm8995->supplies);
2039 dev_err(component->dev, "Failed to enable supplies: %d\n", ret);
2045 dev_err(component->dev, "Failed to read device ID: %d\n", ret);
2050 dev_err(component->dev, "Invalid device ID: %#x\n", ret);
2051 ret = -EINVAL;
2057 dev_err(component->dev, "Failed to issue reset: %d\n", ret);
2086 regulator_bulk_disable(ARRAY_SIZE(wm8995->supplies), wm8995->supplies);
2119 .name = "wm8995-aif1",
2137 .name = "wm8995-aif2",
2155 .name = "wm8995-aif3",
2205 wm8995 = devm_kzalloc(&spi->dev, sizeof(*wm8995), GFP_KERNEL);
2207 return -ENOMEM;
2211 wm8995->regmap = devm_regmap_init_spi(spi, &wm8995_regmap);
2212 if (IS_ERR(wm8995->regmap)) {
2213 ret = PTR_ERR(wm8995->regmap);
2214 dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
2218 ret = devm_snd_soc_register_component(&spi->dev,
2238 wm8995 = devm_kzalloc(&i2c->dev, sizeof(*wm8995), GFP_KERNEL);
2240 return -ENOMEM;
2244 wm8995->regmap = devm_regmap_init_i2c(i2c, &wm8995_regmap);
2245 if (IS_ERR(wm8995->regmap)) {
2246 ret = PTR_ERR(wm8995->regmap);
2247 dev_err(&i2c->dev, "Failed to register regmap: %d\n", ret);
2251 ret = devm_snd_soc_register_component(&i2c->dev,
2255 dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);