Lines Matching +full:mclk +full:- +full:div
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2011-2014 Analog Devices Inc.
6 * Author: Lars-Peter Clausen <lars@metafoo.de>
26 #include "adau-utils.h"
48 static const DECLARE_TLV_DB_MINMAX(adau17x1_digital_tlv, -9563, 0);
60 SOC_SINGLE("Playback De-emphasis Switch", ADAU17X1_DAC_CONTROL0,
74 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in adau17x1_pll_event()
78 adau->pll_regs[5] = 1; in adau17x1_pll_event()
80 adau->pll_regs[5] = 0; in adau17x1_pll_event()
83 regmap_update_bits(adau->regmap, ADAU17X1_CLOCK_CONTROL, in adau17x1_pll_event()
88 regmap_raw_write(adau->regmap, ADAU17X1_PLL_CONTROL, in adau17x1_pll_event()
89 adau->pll_regs, ARRAY_SIZE(adau->pll_regs)); in adau17x1_pll_event()
93 regmap_update_bits(adau->regmap, ADAU17X1_CLOCK_CONTROL, in adau17x1_pll_event()
104 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in adau17x1_adc_fixup()
114 regmap_update_bits(adau->regmap, ADAU17X1_CONVERTER0, in adau17x1_adc_fixup()
116 regmap_update_bits(adau->regmap, ADAU17X1_CONVERTER0, in adau17x1_adc_fixup()
133 SOC_DAPM_ENUM("DAC Mono-Stereo-Mode", adau17x1_dac_mode_enum);
191 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in adau17x1_dsp_mux_enum_put()
193 unsigned int stream = e->shift_l; in adau17x1_dsp_mux_enum_put()
197 if (ucontrol->value.enumerated.item[0] >= e->items) in adau17x1_dsp_mux_enum_put()
198 return -EINVAL; in adau17x1_dsp_mux_enum_put()
200 switch (ucontrol->value.enumerated.item[0]) { in adau17x1_dsp_mux_enum_put()
203 adau->dsp_bypass[stream] = false; in adau17x1_dsp_mux_enum_put()
206 val = (adau->tdm_slot[stream] * 2) + 1; in adau17x1_dsp_mux_enum_put()
207 adau->dsp_bypass[stream] = true; in adau17x1_dsp_mux_enum_put()
224 ucontrol->value.enumerated.item[0], e, &update); in adau17x1_dsp_mux_enum_put()
235 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in adau17x1_dsp_mux_enum_get()
236 unsigned int stream = e->shift_l; in adau17x1_dsp_mux_enum_get()
245 ret = regmap_read(adau->regmap, reg, &val); in adau17x1_dsp_mux_enum_get()
251 ucontrol->value.enumerated.item[0] = val; in adau17x1_dsp_mux_enum_get()
326 switch (adau->type) { in adau17x1_has_dsp()
339 switch (adau->type) { in adau17x1_has_disused_dsp()
349 switch (adau->type) { in adau17x1_has_safeload()
361 struct snd_soc_component *component = dai->component; in adau17x1_set_dai_pll()
366 return -EINVAL; in adau17x1_set_dai_pll()
368 ret = adau_calc_pll_cfg(freq_in, freq_out, adau->pll_regs); in adau17x1_set_dai_pll()
373 ret = regmap_raw_write(adau->regmap, ADAU17X1_PLL_CONTROL, in adau17x1_set_dai_pll()
374 adau->pll_regs, ARRAY_SIZE(adau->pll_regs)); in adau17x1_set_dai_pll()
378 adau->pll_freq = freq_out; in adau17x1_set_dai_pll()
386 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(dai->component); in adau17x1_set_dai_sysclk()
387 struct adau *adau = snd_soc_component_get_drvdata(dai->component); in adau17x1_set_dai_sysclk()
396 if (!adau->mclk) in adau17x1_set_dai_sysclk()
397 return -EINVAL; in adau17x1_set_dai_sysclk()
403 return -EINVAL; in adau17x1_set_dai_sysclk()
406 switch (adau->clk_src) { in adau17x1_set_dai_sysclk()
415 return -EINVAL; in adau17x1_set_dai_sysclk()
418 adau->sysclk = freq; in adau17x1_set_dai_sysclk()
430 adau->clk_src = clk_id; in adau17x1_set_dai_sysclk()
461 return -EINVAL; in adau17x1_auto_pll()
465 clk_get_rate(adau->mclk), pll_rate); in adau17x1_auto_pll()
471 struct snd_soc_component *component = dai->component; in adau17x1_hw_params()
473 unsigned int val, div, dsp_div; in adau17x1_hw_params() local
477 switch (adau->clk_src) { in adau17x1_hw_params()
484 freq = adau->pll_freq; in adau17x1_hw_params()
487 freq = adau->sysclk; in adau17x1_hw_params()
492 return -EINVAL; in adau17x1_hw_params()
496 div = 0; in adau17x1_hw_params()
500 div = 1; in adau17x1_hw_params()
504 div = 2; in adau17x1_hw_params()
508 div = 3; in adau17x1_hw_params()
512 div = 4; in adau17x1_hw_params()
516 div = 5; in adau17x1_hw_params()
520 div = 6; in adau17x1_hw_params()
524 return -EINVAL; in adau17x1_hw_params()
527 regmap_update_bits(adau->regmap, ADAU17X1_CONVERTER0, in adau17x1_hw_params()
528 ADAU17X1_CONVERTER0_CONVSR_MASK, div); in adau17x1_hw_params()
531 regmap_write(adau->regmap, ADAU17X1_SERIAL_SAMPLING_RATE, div); in adau17x1_hw_params()
533 regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, dsp_div); in adau17x1_hw_params()
535 if (adau->sigmadsp) { in adau17x1_hw_params()
541 if (adau->dai_fmt != SND_SOC_DAIFMT_RIGHT_J) in adau17x1_hw_params()
555 return -EINVAL; in adau17x1_hw_params()
558 return regmap_update_bits(adau->regmap, ADAU17X1_SERIAL_PORT1, in adau17x1_hw_params()
565 struct adau *adau = snd_soc_component_get_drvdata(dai->component); in adau17x1_set_dai_fmt()
573 adau->master = true; in adau17x1_set_dai_fmt()
577 adau->master = false; in adau17x1_set_dai_fmt()
580 return -EINVAL; in adau17x1_set_dai_fmt()
604 return -EINVAL; in adau17x1_set_dai_fmt()
621 return -EINVAL; in adau17x1_set_dai_fmt()
633 regmap_update_bits(adau->regmap, ADAU17X1_SERIAL_PORT0, ctrl0_mask, in adau17x1_set_dai_fmt()
635 regmap_update_bits(adau->regmap, ADAU17X1_SERIAL_PORT1, in adau17x1_set_dai_fmt()
638 adau->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK; in adau17x1_set_dai_fmt()
646 struct adau *adau = snd_soc_component_get_drvdata(dai->component); in adau17x1_set_dai_tdm_slot()
666 if (adau->type == ADAU1361) in adau17x1_set_dai_tdm_slot()
667 return -EINVAL; in adau17x1_set_dai_tdm_slot()
672 return -EINVAL; in adau17x1_set_dai_tdm_slot()
677 if (adau->type == ADAU1761 || adau->type == ADAU1761_AS_1361) in adau17x1_set_dai_tdm_slot()
678 return -EINVAL; in adau17x1_set_dai_tdm_slot()
692 if (adau->type == ADAU1361) in adau17x1_set_dai_tdm_slot()
693 return -EINVAL; in adau17x1_set_dai_tdm_slot()
698 return -EINVAL; in adau17x1_set_dai_tdm_slot()
704 adau->tdm_slot[SNDRV_PCM_STREAM_CAPTURE] = 0; in adau17x1_set_dai_tdm_slot()
708 adau->tdm_slot[SNDRV_PCM_STREAM_CAPTURE] = 1; in adau17x1_set_dai_tdm_slot()
712 adau->tdm_slot[SNDRV_PCM_STREAM_CAPTURE] = 2; in adau17x1_set_dai_tdm_slot()
716 adau->tdm_slot[SNDRV_PCM_STREAM_CAPTURE] = 3; in adau17x1_set_dai_tdm_slot()
719 return -EINVAL; in adau17x1_set_dai_tdm_slot()
725 adau->tdm_slot[SNDRV_PCM_STREAM_PLAYBACK] = 0; in adau17x1_set_dai_tdm_slot()
729 adau->tdm_slot[SNDRV_PCM_STREAM_PLAYBACK] = 1; in adau17x1_set_dai_tdm_slot()
733 adau->tdm_slot[SNDRV_PCM_STREAM_PLAYBACK] = 2; in adau17x1_set_dai_tdm_slot()
737 adau->tdm_slot[SNDRV_PCM_STREAM_PLAYBACK] = 3; in adau17x1_set_dai_tdm_slot()
740 return -EINVAL; in adau17x1_set_dai_tdm_slot()
743 regmap_update_bits(adau->regmap, ADAU17X1_CONVERTER0, in adau17x1_set_dai_tdm_slot()
745 regmap_update_bits(adau->regmap, ADAU17X1_CONVERTER1, in adau17x1_set_dai_tdm_slot()
747 regmap_update_bits(adau->regmap, ADAU17X1_SERIAL_PORT0, in adau17x1_set_dai_tdm_slot()
749 regmap_update_bits(adau->regmap, ADAU17X1_SERIAL_PORT1, in adau17x1_set_dai_tdm_slot()
755 if (adau->dsp_bypass[SNDRV_PCM_STREAM_PLAYBACK]) { in adau17x1_set_dai_tdm_slot()
756 regmap_write(adau->regmap, ADAU17X1_SERIAL_INPUT_ROUTE, in adau17x1_set_dai_tdm_slot()
757 (adau->tdm_slot[SNDRV_PCM_STREAM_PLAYBACK] * 2) + 1); in adau17x1_set_dai_tdm_slot()
760 if (adau->dsp_bypass[SNDRV_PCM_STREAM_CAPTURE]) { in adau17x1_set_dai_tdm_slot()
761 regmap_write(adau->regmap, ADAU17X1_SERIAL_OUTPUT_ROUTE, in adau17x1_set_dai_tdm_slot()
762 (adau->tdm_slot[SNDRV_PCM_STREAM_CAPTURE] * 2) + 1); in adau17x1_set_dai_tdm_slot()
771 struct adau *adau = snd_soc_component_get_drvdata(dai->component); in adau17x1_startup()
773 if (adau->sigmadsp) in adau17x1_startup()
774 return sigmadsp_restrict_params(adau->sigmadsp, substream); in adau17x1_startup()
799 return -EINVAL; in adau17x1_set_micbias_voltage()
802 return regmap_write(adau->regmap, ADAU17X1_MICBIAS, micbias << 2); in adau17x1_set_micbias_voltage()
892 if (adau->sigmadsp->current_samplerate == rate) in adau17x1_setup_firmware()
897 ret = regmap_read(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, &dspsr); in adau17x1_setup_firmware()
901 ret = regmap_read(adau->regmap, ADAU17X1_DSP_RUN, &dsp_run); in adau17x1_setup_firmware()
905 regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 1); in adau17x1_setup_firmware()
906 regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, 0xf); in adau17x1_setup_firmware()
907 regmap_write(adau->regmap, ADAU17X1_DSP_RUN, 0); in adau17x1_setup_firmware()
909 ret = sigmadsp_setup(adau->sigmadsp, rate); in adau17x1_setup_firmware()
911 regmap_write(adau->regmap, ADAU17X1_DSP_ENABLE, 0); in adau17x1_setup_firmware()
914 regmap_write(adau->regmap, ADAU17X1_DSP_SAMPLING_RATE, dspsr); in adau17x1_setup_firmware()
915 regmap_write(adau->regmap, ADAU17X1_DSP_RUN, dsp_run); in adau17x1_setup_firmware()
944 if (!adau->sigmadsp) in adau17x1_add_widgets()
947 ret = sigmadsp_attach(adau->sigmadsp, component); in adau17x1_add_widgets()
949 dev_err(component->dev, "Failed to attach firmware: %d\n", in adau17x1_add_widgets()
978 if (adau->clk_src != ADAU17X1_CLK_SRC_MCLK) in adau17x1_add_routes()
989 if (adau->switch_mode) in adau17x1_resume()
990 adau->switch_mode(component->dev); in adau17x1_resume()
992 regcache_sync(adau->regmap); in adau17x1_resume()
1011 if ((len - nbr_words * ADAU17X1_WORD_SIZE) == 0) { in adau17x1_safeload()
1012 ret = regmap_raw_write(sigmadsp->control_data, in adau17x1_safeload()
1018 ret = regmap_raw_write(sigmadsp->control_data, in adau17x1_safeload()
1027 addr_offset = addr - 1; in adau17x1_safeload()
1029 ret = regmap_raw_write(sigmadsp->control_data, in adau17x1_safeload()
1036 ret = regmap_raw_write(sigmadsp->control_data, in adau17x1_safeload()
1060 return -ENOMEM; in adau17x1_probe()
1063 adau->mclk = devm_clk_get_optional(dev, "mclk"); in adau17x1_probe()
1064 if (IS_ERR(adau->mclk)) in adau17x1_probe()
1065 return PTR_ERR(adau->mclk); in adau17x1_probe()
1067 if (adau->mclk) { in adau17x1_probe()
1068 adau->clk_src = ADAU17X1_CLK_SRC_PLL_AUTO; in adau17x1_probe()
1075 ret = adau_calc_pll_cfg(clk_get_rate(adau->mclk), 48000 * 1024, in adau17x1_probe()
1076 adau->pll_regs); in adau17x1_probe()
1080 ret = clk_prepare_enable(adau->mclk); in adau17x1_probe()
1085 adau->regmap = regmap; in adau17x1_probe()
1086 adau->switch_mode = switch_mode; in adau17x1_probe()
1087 adau->type = type; in adau17x1_probe()
1093 adau->sigmadsp = devm_sigmadsp_init_regmap(dev, regmap, in adau17x1_probe()
1096 adau->sigmadsp = devm_sigmadsp_init_regmap(dev, regmap, in adau17x1_probe()
1099 if (IS_ERR(adau->sigmadsp)) { in adau17x1_probe()
1101 PTR_ERR(adau->sigmadsp)); in adau17x1_probe()
1102 adau->sigmadsp = NULL; in adau17x1_probe()
1117 clk_disable_unprepare(adau->mclk); in adau17x1_remove()
1122 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");