Lines Matching +full:codec +full:- +full:aif1 +full:- +full:lrclk

1 // SPDX-License-Identifier: GPL-2.0-only
3 * es8311.c -- es8311 ALSA SoC audio driver
38 static const DECLARE_TLV_DB_SCALE(es8311_adc_vol_tlv, -9550, 50, 0);
68 0, 1, TLV_DB_SCALE_ITEM(-3010, 600, 0),
69 2, 3, TLV_DB_SCALE_ITEM(-2060, 250, 0),
70 4, 5, TLV_DB_SCALE_ITEM(-1610, 160, 0),
71 6, 7, TLV_DB_SCALE_ITEM(-1320, 120, 0),
72 8, 9, TLV_DB_SCALE_ITEM(-1100, 90, 0),
73 10, 11, TLV_DB_SCALE_ITEM(-930, 80, 0),
74 12, 15, TLV_DB_SCALE_ITEM(-780, 60, 0),
107 0, 7, TLV_DB_SCALE_ITEM(-9600, 600, 0),
108 8, 15, TLV_DB_SCALE_ITEM(-5100, 300, 0),
110 static const DECLARE_TLV_DB_SCALE(es8311_automute_vol_tlv, -2800, 400, 0);
112 static const DECLARE_TLV_DB_SCALE(es8311_dac_vol_tlv, -9550, 50, 0);
187 "MIC1P-MIC1N",
259 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, ES8311_SDP_OUT,
263 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, ES8311_SDP_IN,
283 { "Differential Mux", "MIC1P-MIC1N", "MIC1" },
315 * from 1 to 20: the register takes the div value - 1
335 * documentation. Limited to have a ratio of adc (or dac) clock to lrclk equal
373 * Return -EINVAL otherwise.
380 return -EINVAL; in es8311_cmp_adj_mclk_coeff()
382 unsigned int div = coeff->div; in es8311_cmp_adj_mclk_coeff()
383 unsigned int mult = coeff->mult; in es8311_cmp_adj_mclk_coeff()
386 if (coeff->mclk == mclk_freq) { in es8311_cmp_adj_mclk_coeff()
388 } else if (mclk_freq % coeff->mclk == 0) { in es8311_cmp_adj_mclk_coeff()
389 div = mclk_freq / coeff->mclk; in es8311_cmp_adj_mclk_coeff()
390 div *= coeff->div; in es8311_cmp_adj_mclk_coeff()
393 } else if (coeff->mclk % mclk_freq == 0) { in es8311_cmp_adj_mclk_coeff()
394 mult = coeff->mclk / mclk_freq; in es8311_cmp_adj_mclk_coeff()
396 mult *= coeff->mult; in es8311_cmp_adj_mclk_coeff()
402 return -EINVAL; in es8311_cmp_adj_mclk_coeff()
405 out_coeff->div = div; in es8311_cmp_adj_mclk_coeff()
406 out_coeff->mult = mult; in es8311_cmp_adj_mclk_coeff()
417 if (coeff->rate != rate) in es8311_get_mclk_coeff()
425 return -EINVAL; in es8311_get_mclk_coeff()
434 count < ARRAY_SIZE(es8311->rates); i++) { in es8311_set_sysclk_constraints()
437 if (count > 0 && coeff->rate == es8311->rates[count - 1]) in es8311_set_sysclk_constraints()
442 es8311->rates[count++] = coeff->rate; in es8311_set_sysclk_constraints()
445 es8311->constraints.list = es8311->rates; in es8311_set_sysclk_constraints()
446 es8311->constraints.count = count; in es8311_set_sysclk_constraints()
452 struct snd_soc_component *component = dai->component; in es8311_mute()
460 regmap_update_bits(es8311->regmap, ES8311_DAC1, mask, val); in es8311_mute()
469 struct snd_soc_component *component = dai->component; in es8311_startup()
472 if (es8311->constraints.list) { in es8311_startup()
473 snd_pcm_hw_constraint_list(substream->runtime, 0, in es8311_startup()
475 &es8311->constraints); in es8311_startup()
485 struct snd_soc_component *component = dai->component; in es8311_hw_params()
507 return -EINVAL; in es8311_hw_params()
511 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in es8311_hw_params()
521 if (es8311->mclk_freq > ES8311_MCLK_MAX_FREQ) { in es8311_hw_params()
522 dev_err(component->dev, "mclk frequency %lu too high\n", in es8311_hw_params()
523 es8311->mclk_freq); in es8311_hw_params()
524 return -EINVAL; in es8311_hw_params()
527 unsigned int mclk_freq = es8311->mclk_freq; in es8311_hw_params()
532 if (es8311->provider) { in es8311_hw_params()
533 dev_err(component->dev, in es8311_hw_params()
535 return -EINVAL; in es8311_hw_params()
537 dev_dbg(component->dev, in es8311_hw_params()
548 dev_err(component->dev, "unable to find mclk coefficient\n"); in es8311_hw_params()
560 return -EINVAL; in es8311_hw_params()
579 return -EINVAL; in es8311_hw_params()
583 clkmgr = (coeff.div - 1) << ES8311_CLKMGR2_DIV_PRE_SHIFT | in es8311_hw_params()
588 clkmgr = (coeff.div_adc_dac - 1) << ES8311_CLKMGR5_ADC_DIV_SHIFT | in es8311_hw_params()
589 (coeff.div_adc_dac - 1) << ES8311_CLKMGR5_DAC_DIV_SHIFT; in es8311_hw_params()
592 if (es8311->provider) { in es8311_hw_params()
597 return -EINVAL; in es8311_hw_params()
600 clkmgr = (div_lrclk - 1) >> 8; in es8311_hw_params()
603 clkmgr = (div_lrclk - 1) & 0xFF; in es8311_hw_params()
607 dev_err(component->dev, in es8311_hw_params()
610 return -EINVAL; in es8311_hw_params()
617 clkmgr = div_bclk - 1; in es8311_hw_params()
626 dev_err(component->dev, in es8311_hw_params()
629 return -EINVAL; in es8311_hw_params()
644 struct snd_soc_component *component = codec_dai->component; in es8311_set_sysclk()
648 dev_err(component->dev, "invalid frequency %u: too high\n", in es8311_set_sysclk()
650 return -EINVAL; in es8311_set_sysclk()
653 if (es8311->mclk_freq == freq) in es8311_set_sysclk()
656 es8311->mclk_freq = freq; in es8311_set_sysclk()
657 es8311->constraints.list = NULL; in es8311_set_sysclk()
658 es8311->constraints.count = 0; in es8311_set_sysclk()
663 int ret = clk_set_rate(es8311->mclk, freq); in es8311_set_sysclk()
665 dev_err(component->dev, "unable to set mclk rate\n"); in es8311_set_sysclk()
676 struct snd_soc_component *component = codec_dai->component; in es8311_set_dai_fmt()
682 es8311->provider = true; in es8311_set_dai_fmt()
690 es8311->provider = false; in es8311_set_dai_fmt()
695 return -EINVAL; in es8311_set_dai_fmt()
708 dev_err(component->dev, "right justified mode not supported\n"); in es8311_set_dai_fmt()
709 return -EINVAL; in es8311_set_dai_fmt()
720 dev_err(component->dev, in es8311_set_dai_fmt()
722 return -EINVAL; in es8311_set_dai_fmt()
726 return -EINVAL; in es8311_set_dai_fmt()
745 return -EINVAL; in es8311_set_dai_fmt()
771 int ret = clk_prepare_enable(es8311->mclk); in es8311_set_bias_level()
773 dev_err(component->dev, in es8311_set_bias_level()
786 clk_disable_unprepare(es8311->mclk); in es8311_set_bias_level()
809 .stream_name = "AIF1 Playback",
816 .stream_name = "AIF1 Capture",
829 * (1) power down state machine and reset codec blocks then, in es8311_reset()
855 regcache_cache_only(es8311->regmap, true); in es8311_suspend()
856 regcache_mark_dirty(es8311->regmap); in es8311_suspend()
869 regcache_cache_only(es8311->regmap, false); in es8311_resume()
870 regcache_sync(es8311->regmap); in es8311_resume()
881 es8311->mclk = devm_clk_get_optional(component->dev, "mclk"); in es8311_component_probe()
882 if (IS_ERR(es8311->mclk)) { in es8311_component_probe()
883 dev_err(component->dev, "invalid mclk\n"); in es8311_component_probe()
884 return PTR_ERR(es8311->mclk); in es8311_component_probe()
887 es8311->mclk_freq = clk_get_rate(es8311->mclk); in es8311_component_probe()
888 if (es8311->mclk_freq > 0 && es8311->mclk_freq < ES8311_MCLK_MAX_FREQ) in es8311_component_probe()
889 es8311_set_sysclk_constraints(es8311->mclk_freq, es8311); in es8311_component_probe()
929 struct device *dev = &i2c_client->dev; in es8311_i2c_probe()
933 return -ENOMEM; in es8311_i2c_probe()
935 es8311->regmap = in es8311_i2c_probe()
937 if (IS_ERR(es8311->regmap)) in es8311_i2c_probe()
938 return PTR_ERR(es8311->regmap); in es8311_i2c_probe()