Lines Matching +full:refclk +full:- +full:mux
1 // SPDX-License-Identifier: GPL-2.0-only
5 // Copyright (C) 2015-2019 Cirrus Logic, Inc. and
18 #include <linux/irqchip/irq-madera.h>
22 #include <sound/madera-pdata.h>
24 #include <dt-bindings/sound/madera.h>
143 dev_err(_fll->madera->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
145 dev_warn(_fll->madera->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
147 dev_dbg(_fll->madera->dev, "FLL%d: " fmt, _fll->id, ##__VA_ARGS__)
150 dev_err(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
152 dev_warn(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
154 dev_dbg(_dai->dev, "AIF%d: " fmt, _dai->id, ##__VA_ARGS__)
169 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_clk_ev()
171 struct madera *madera = priv->madera; in madera_clk_ev()
176 ret = regmap_read(madera->regmap, w->reg, &val); in madera_clk_ev()
178 dev_err(madera->dev, "Failed to check clock source: %d\n", ret); in madera_clk_ev()
198 return clk_prepare_enable(madera->mclk[clk_idx].clk); in madera_clk_ev()
200 clk_disable_unprepare(madera->mclk[clk_idx].clk); in madera_clk_ev()
210 struct madera *madera = priv->madera; in madera_spin_sysclk()
215 if (pm_runtime_suspended(madera->dev)) in madera_spin_sysclk()
223 ret = regmap_read(madera->regmap, MADERA_SOFTWARE_RESET, &val); in madera_spin_sysclk()
225 dev_err(madera->dev, in madera_spin_sysclk()
235 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_sysclk_ev()
257 ret = regmap_read(madera->regmap, MADERA_IRQ1_RAW_STATUS_15, &val); in madera_check_speaker_overheat()
259 dev_err(madera->dev, "Failed to read thermal status: %d\n", in madera_check_speaker_overheat()
273 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_spk_ev()
275 struct madera *madera = priv->madera; in madera_spk_ev()
286 dev_crit(madera->dev, in madera_spk_ev()
288 return -EBUSY; in madera_spk_ev()
291 regmap_update_bits(madera->regmap, MADERA_OUTPUT_ENABLES_1, in madera_spk_ev()
292 1 << w->shift, 1 << w->shift); in madera_spk_ev()
295 regmap_update_bits(madera->regmap, MADERA_OUTPUT_ENABLES_1, in madera_spk_ev()
296 1 << w->shift, 0); in madera_spk_ev()
314 dev_crit(madera->dev, "Thermal shutdown\n"); in madera_thermal_warn()
315 ret = regmap_update_bits(madera->regmap, in madera_thermal_warn()
320 dev_crit(madera->dev, in madera_thermal_warn()
324 dev_alert(madera->dev, "Thermal warning\n"); in madera_thermal_warn()
326 dev_info(madera->dev, "Spurious thermal warning\n"); in madera_thermal_warn()
335 struct madera *madera = priv->madera; in madera_init_overheat()
336 struct device *dev = madera->dev; in madera_init_overheat()
357 struct madera *madera = priv->madera; in madera_free_overheat()
375 if (n == -EINVAL) in madera_get_variable_u32_array()
385 return -EINVAL; in madera_get_variable_u32_array()
400 struct madera *madera = priv->madera; in madera_prop_get_inmode()
401 struct madera_codec_pdata *pdata = &madera->pdata.codec; in madera_prop_get_inmode()
405 BUILD_BUG_ON(ARRAY_SIZE(pdata->inmode) != MADERA_MAX_INPUT); in madera_prop_get_inmode()
406 BUILD_BUG_ON(ARRAY_SIZE(pdata->inmode[0]) != MADERA_MAX_MUXED_CHANNELS); in madera_prop_get_inmode()
408 n = madera_get_variable_u32_array(madera->dev, "cirrus,inmode", in madera_prop_get_inmode()
417 pdata->inmode[in_idx][ch_idx] = tmp[i]; in madera_prop_get_inmode()
428 struct madera *madera = priv->madera; in madera_prop_get_pdata()
429 struct madera_codec_pdata *pdata = &madera->pdata.codec; in madera_prop_get_pdata()
430 u32 out_mono[ARRAY_SIZE(pdata->out_mono)]; in madera_prop_get_pdata()
435 n = madera_get_variable_u32_array(madera->dev, "cirrus,out-mono", in madera_prop_get_pdata()
439 pdata->out_mono[i] = !!out_mono[i]; in madera_prop_get_pdata()
441 madera_get_variable_u32_array(madera->dev, in madera_prop_get_pdata()
442 "cirrus,max-channels-clocked", in madera_prop_get_pdata()
443 pdata->max_channels_clocked, in madera_prop_get_pdata()
444 ARRAY_SIZE(pdata->max_channels_clocked), in madera_prop_get_pdata()
447 madera_get_variable_u32_array(madera->dev, "cirrus,pdm-fmt", in madera_prop_get_pdata()
448 pdata->pdm_fmt, in madera_prop_get_pdata()
449 ARRAY_SIZE(pdata->pdm_fmt), 1); in madera_prop_get_pdata()
451 madera_get_variable_u32_array(madera->dev, "cirrus,pdm-mute", in madera_prop_get_pdata()
452 pdata->pdm_mute, in madera_prop_get_pdata()
453 ARRAY_SIZE(pdata->pdm_mute), 1); in madera_prop_get_pdata()
455 madera_get_variable_u32_array(madera->dev, "cirrus,dmic-ref", in madera_prop_get_pdata()
456 pdata->dmic_ref, in madera_prop_get_pdata()
457 ARRAY_SIZE(pdata->dmic_ref), 1); in madera_prop_get_pdata()
465 BUILD_BUG_ON(!madera_mixer_texts[MADERA_NUM_MIXER_INPUTS - 1]); in madera_core_init()
466 BUILD_BUG_ON(!madera_mixer_values[MADERA_NUM_MIXER_INPUTS - 1]); in madera_core_init()
468 if (!dev_get_platdata(priv->madera->dev)) in madera_core_init()
471 mutex_init(&priv->rate_lock); in madera_core_init()
474 priv->madera->out_clamp[i] = true; in madera_core_init()
482 mutex_destroy(&priv->rate_lock); in madera_core_free()
490 struct madera *madera = priv->madera; in madera_debug_dump_domain_groups()
493 for (i = 0; i < ARRAY_SIZE(priv->domain_group_ref); ++i) in madera_debug_dump_domain_groups()
494 dev_dbg(madera->dev, "domain_grp_ref[%d]=%d\n", i, in madera_debug_dump_domain_groups()
495 priv->domain_group_ref[i]); in madera_debug_dump_domain_groups()
502 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_domain_clk_ev()
504 int dom_grp = w->shift; in madera_domain_clk_ev()
506 if (dom_grp >= ARRAY_SIZE(priv->domain_group_ref)) { in madera_domain_clk_ev()
508 return -EINVAL; in madera_domain_clk_ev()
515 mutex_lock(&priv->rate_lock); in madera_domain_clk_ev()
519 dev_dbg(priv->madera->dev, "Inc ref on domain group %d\n", in madera_domain_clk_ev()
521 ++priv->domain_group_ref[dom_grp]; in madera_domain_clk_ev()
524 dev_dbg(priv->madera->dev, "Dec ref on domain group %d\n", in madera_domain_clk_ev()
526 --priv->domain_group_ref[dom_grp]; in madera_domain_clk_ev()
534 mutex_unlock(&priv->rate_lock); in madera_domain_clk_ev()
548 struct madera *madera = priv->madera; in madera_out1_demux_put()
549 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_out1_demux_put()
550 unsigned int ep_sel, mux, change; in madera_out1_demux_put() local
554 if (ucontrol->value.enumerated.item[0] > e->items - 1) in madera_out1_demux_put()
555 return -EINVAL; in madera_out1_demux_put()
557 mux = ucontrol->value.enumerated.item[0]; in madera_out1_demux_put()
561 ep_sel = mux << MADERA_EP_SEL_SHIFT; in madera_out1_demux_put()
570 ret = regmap_update_bits(madera->regmap, MADERA_OUTPUT_ENABLES_1, in madera_out1_demux_put()
573 dev_warn(madera->dev, "Failed to disable outputs: %d\n", ret); in madera_out1_demux_put()
579 if (madera->out_clamp[0]) in madera_out1_demux_put()
580 ret = regmap_update_bits(madera->regmap, in madera_out1_demux_put()
584 dev_err(madera->dev, "Failed to set OUT1 demux: %d\n", ret); in madera_out1_demux_put()
587 if (!ep_sel && !madera->pdata.codec.out_mono[0]) in madera_out1_demux_put()
594 dev_warn(madera->dev, in madera_out1_demux_put()
603 (madera->out_clamp[0] && !madera->out_shorted[0])) { in madera_out1_demux_put()
604 ret = regmap_update_bits(madera->regmap, in madera_out1_demux_put()
607 madera->hp_ena); in madera_out1_demux_put()
609 dev_warn(madera->dev, in madera_out1_demux_put()
612 else if (madera->hp_ena) in madera_out1_demux_put()
621 return snd_soc_dapm_mux_update_power(dapm, kcontrol, mux, e, NULL); in madera_out1_demux_put()
635 ucontrol->value.enumerated.item[0] = val; in madera_out1_demux_get()
649 struct madera *madera = priv->madera; in madera_inmux_put()
650 struct regmap *regmap = madera->regmap; in madera_inmux_put()
651 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_inmux_put()
652 unsigned int mux, val, mask; in madera_inmux_put() local
657 mux = ucontrol->value.enumerated.item[0]; in madera_inmux_put()
658 if (mux > 1) in madera_inmux_put()
659 return -EINVAL; in madera_inmux_put()
661 val = mux << e->shift_l; in madera_inmux_put()
662 mask = (e->mask << e->shift_l) | MADERA_IN1L_SRC_SE_MASK; in madera_inmux_put()
664 switch (e->reg) { in madera_inmux_put()
666 inmode = madera->pdata.codec.inmode[0][2 * mux]; in madera_inmux_put()
669 inmode = madera->pdata.codec.inmode[0][1 + (2 * mux)]; in madera_inmux_put()
672 inmode = madera->pdata.codec.inmode[1][2 * mux]; in madera_inmux_put()
675 inmode = madera->pdata.codec.inmode[1][1 + (2 * mux)]; in madera_inmux_put()
678 return -EINVAL; in madera_inmux_put()
684 dev_dbg(madera->dev, "mux=%u reg=0x%x inmode=0x%x mask=0x%x val=0x%x\n", in madera_inmux_put()
685 mux, e->reg, inmode, mask, val); in madera_inmux_put()
687 ret = regmap_update_bits_check(regmap, e->reg, mask, val, &changed); in madera_inmux_put()
693 mux, e, NULL); in madera_inmux_put()
724 SOC_DAPM_ENUM_EXT("IN1L Mux", madera_in1muxl_enum,
726 SOC_DAPM_ENUM_EXT("IN1R Mux", madera_in1muxr_enum,
728 SOC_DAPM_ENUM_EXT("IN2L Mux", madera_in2muxl_enum,
730 SOC_DAPM_ENUM_EXT("IN2R Mux", madera_in2muxr_enum,
769 count = priv->domain_group_ref[MADERA_DOM_GRP_FX]; in madera_can_change_grp_rate()
773 count = priv->domain_group_ref[MADERA_DOM_GRP_ASRC1]; in madera_can_change_grp_rate()
777 count = priv->domain_group_ref[MADERA_DOM_GRP_ASRC2]; in madera_can_change_grp_rate()
781 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC1]; in madera_can_change_grp_rate()
785 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC2]; in madera_can_change_grp_rate()
789 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC3]; in madera_can_change_grp_rate()
793 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC4]; in madera_can_change_grp_rate()
796 count = priv->domain_group_ref[MADERA_DOM_GRP_OUT]; in madera_can_change_grp_rate()
799 count = priv->domain_group_ref[MADERA_DOM_GRP_SPD]; in madera_can_change_grp_rate()
803 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP1]; in madera_can_change_grp_rate()
807 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP2]; in madera_can_change_grp_rate()
811 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP3]; in madera_can_change_grp_rate()
815 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP4]; in madera_can_change_grp_rate()
819 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP5]; in madera_can_change_grp_rate()
823 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP6]; in madera_can_change_grp_rate()
827 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP7]; in madera_can_change_grp_rate()
830 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF1]; in madera_can_change_grp_rate()
833 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF2]; in madera_can_change_grp_rate()
836 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF3]; in madera_can_change_grp_rate()
839 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF4]; in madera_can_change_grp_rate()
849 count = priv->domain_group_ref[MADERA_DOM_GRP_SLIMBUS]; in madera_can_change_grp_rate()
852 count = priv->domain_group_ref[MADERA_DOM_GRP_PWM]; in madera_can_change_grp_rate()
858 dev_dbg(priv->madera->dev, "Rate reg 0x%x group ref %d\n", reg, count); in madera_can_change_grp_rate()
872 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_adsp_rate_get()
874 const int adsp_num = e->shift_l; in madera_adsp_rate_get()
877 mutex_lock(&priv->rate_lock); in madera_adsp_rate_get()
878 cached_rate = priv->adsp_rate_cache[adsp_num]; in madera_adsp_rate_get()
879 mutex_unlock(&priv->rate_lock); in madera_adsp_rate_get()
882 ucontrol->value.enumerated.item[0] = item; in madera_adsp_rate_get()
893 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_adsp_rate_put()
894 const int adsp_num = e->shift_l; in madera_adsp_rate_put()
895 const unsigned int item = ucontrol->value.enumerated.item[0]; in madera_adsp_rate_put()
898 if (item >= e->items) in madera_adsp_rate_put()
899 return -EINVAL; in madera_adsp_rate_put()
906 mutex_lock(&priv->rate_lock); in madera_adsp_rate_put()
908 if (!madera_can_change_grp_rate(priv, priv->adsp[adsp_num].base)) { in madera_adsp_rate_put()
909 dev_warn(priv->madera->dev, in madera_adsp_rate_put()
911 kcontrol->id.name); in madera_adsp_rate_put()
912 ret = -EBUSY; in madera_adsp_rate_put()
915 priv->adsp_rate_cache[adsp_num] = e->values[item]; in madera_adsp_rate_put()
919 mutex_unlock(&priv->rate_lock); in madera_adsp_rate_put()
967 val = priv->adsp_rate_cache[dsp->num - 1] << MADERA_DSP_RATE_SHIFT; in madera_write_adsp_clk_setting()
969 switch (priv->madera->type) { in madera_write_adsp_clk_setting()
979 dev_dbg(priv->madera->dev, "Set DSP frequency to 0x%x\n", freq); in madera_write_adsp_clk_setting()
981 ret = regmap_write(dsp->regmap, in madera_write_adsp_clk_setting()
982 dsp->base + MADERA_DSP_CONFIG_2_OFFS, freq); in madera_write_adsp_clk_setting()
988 ret = regmap_update_bits(dsp->regmap, in madera_write_adsp_clk_setting()
989 dsp->base + MADERA_DSP_CONFIG_1_OFFS, in madera_write_adsp_clk_setting()
994 dev_dbg(priv->madera->dev, "Set DSP clocking to 0x%x\n", val); in madera_write_adsp_clk_setting()
999 dev_err(dsp->dev, "Failed to set DSP%d clock: %d\n", dsp->num, ret); in madera_write_adsp_clk_setting()
1007 struct wm_adsp *dsp = &priv->adsp[dsp_num]; in madera_set_adsp_clk()
1008 struct madera *madera = priv->madera; in madera_set_adsp_clk()
1013 * This is called at a higher DAPM priority than the mux widgets so in madera_set_adsp_clk()
1021 ret = regmap_read(dsp->regmap, dsp->base, &cur); in madera_set_adsp_clk()
1023 dev_err(madera->dev, in madera_set_adsp_clk()
1030 new = priv->adsp_rate_cache[dsp->num - 1] << MADERA_DSP_RATE_SHIFT; in madera_set_adsp_clk()
1033 dev_dbg(madera->dev, "DSP rate not changed\n"); in madera_set_adsp_clk()
1036 dev_dbg(madera->dev, "DSP rate changed\n"); in madera_set_adsp_clk()
1053 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_rate_put()
1054 unsigned int item = ucontrol->value.enumerated.item[0]; in madera_rate_put()
1058 if (item >= e->items) in madera_rate_put()
1059 return -EINVAL; in madera_rate_put()
1065 mutex_lock(&priv->rate_lock); in madera_rate_put()
1067 val = snd_soc_component_read(component, e->reg); in madera_rate_put()
1068 val >>= e->shift_l; in madera_rate_put()
1069 val &= e->mask; in madera_rate_put()
1075 if (!madera_can_change_grp_rate(priv, e->reg)) { in madera_rate_put()
1076 dev_warn(priv->madera->dev, in madera_rate_put()
1078 kcontrol->id.name); in madera_rate_put()
1079 ret = -EBUSY; in madera_rate_put()
1087 mutex_unlock(&priv->rate_lock); in madera_rate_put()
1098 switch (madera->type) { in madera_configure_input_mode()
1125 * B settings will be applied if the mux is changed in madera_configure_input_mode()
1128 dev_dbg(madera->dev, "IN%d mode %u:%u:%u:%u\n", i + 1, in madera_configure_input_mode()
1129 madera->pdata.codec.inmode[i][0], in madera_configure_input_mode()
1130 madera->pdata.codec.inmode[i][1], in madera_configure_input_mode()
1131 madera->pdata.codec.inmode[i][2], in madera_configure_input_mode()
1132 madera->pdata.codec.inmode[i][3]); in madera_configure_input_mode()
1134 dig_mode = madera->pdata.codec.dmic_ref[i] << in madera_configure_input_mode()
1137 switch (madera->pdata.codec.inmode[i][0]) { in madera_configure_input_mode()
1145 dev_warn(madera->dev, in madera_configure_input_mode()
1147 i + 1, madera->pdata.codec.inmode[i][0]); in madera_configure_input_mode()
1151 switch (madera->pdata.codec.inmode[i][1]) { in madera_configure_input_mode()
1159 dev_warn(madera->dev, in madera_configure_input_mode()
1161 i + 1, madera->pdata.codec.inmode[i][1]); in madera_configure_input_mode()
1165 dev_dbg(madera->dev, in madera_configure_input_mode()
1169 regmap_update_bits(madera->regmap, in madera_configure_input_mode()
1176 regmap_update_bits(madera->regmap, in madera_configure_input_mode()
1180 regmap_update_bits(madera->regmap, in madera_configure_input_mode()
1189 struct madera *madera = priv->madera; in madera_init_inputs()
1213 struct madera *madera = priv->madera; in madera_init_outputs()
1214 const struct madera_codec_pdata *pdata = &madera->pdata.codec; in madera_init_outputs()
1219 dev_warn(madera->dev, in madera_init_outputs()
1230 if (pdata->out_mono[i]) { in madera_init_outputs()
1240 regmap_update_bits(madera->regmap, in madera_init_outputs()
1244 dev_dbg(madera->dev, "OUT%d mono=0x%x\n", i + 1, val); in madera_init_outputs()
1248 dev_dbg(madera->dev, "PDM%d fmt=0x%x mute=0x%x\n", i + 1, in madera_init_outputs()
1249 pdata->pdm_fmt[i], pdata->pdm_mute[i]); in madera_init_outputs()
1251 if (pdata->pdm_mute[i]) in madera_init_outputs()
1252 regmap_update_bits(madera->regmap, in madera_init_outputs()
1256 pdata->pdm_mute[i]); in madera_init_outputs()
1258 if (pdata->pdm_fmt[i]) in madera_init_outputs()
1259 regmap_update_bits(madera->regmap, in madera_init_outputs()
1262 pdata->pdm_fmt[i]); in madera_init_outputs()
1272 struct madera *madera = priv->madera; in madera_init_bus_error_irq()
1279 &priv->adsp[dsp_num]); in madera_init_bus_error_irq()
1281 dev_err(madera->dev, in madera_init_bus_error_irq()
1290 struct madera *madera = priv->madera; in madera_free_bus_error_irq()
1294 &priv->adsp[dsp_num]); in madera_free_bus_error_irq()
1605 const DECLARE_TLV_DB_SCALE(madera_eq_tlv, -1200, 100, 0);
1608 const DECLARE_TLV_DB_SCALE(madera_digital_tlv, -6400, 50, 0);
1611 const DECLARE_TLV_DB_SCALE(madera_noise_tlv, -13200, 600, 0);
1614 const DECLARE_TLV_DB_SCALE(madera_ng_tlv, -12000, 600, 0);
1617 const DECLARE_TLV_DB_SCALE(madera_mixer_tlv, -3200, 100, 0);
1988 "Low-pass", "High-pass"
2163 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_dfc_put()
2164 unsigned int reg = e->reg; in madera_dfc_put()
2168 reg = ((reg / 6) * 6) - 2; in madera_dfc_put()
2174 ret = -EBUSY; in madera_dfc_put()
2175 dev_err(component->dev, "Can't change mode on an active DFC\n"); in madera_dfc_put()
2191 (struct soc_mixer_control *)kcontrol->private_value; in madera_lp_mode_put()
2203 mask = (mc->reg - MADERA_ADC_DIGITAL_VOLUME_1L) / 4; in madera_lp_mode_put()
2207 ret = -EBUSY; in madera_lp_mode_put()
2208 dev_err(component->dev, in madera_lp_mode_put()
2249 for (i = 0; i < priv->num_inputs; i++) { in madera_in_set_vu()
2250 ret = regmap_update_bits(priv->madera->regmap, in madera_in_set_vu()
2254 dev_warn(priv->madera->dev, in madera_in_set_vu()
2262 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_in_ev()
2266 if (w->shift % 2) in madera_in_ev()
2267 reg = MADERA_ADC_DIGITAL_VOLUME_1L + ((w->shift / 2) * 8); in madera_in_ev()
2269 reg = MADERA_ADC_DIGITAL_VOLUME_1R + ((w->shift / 2) * 8); in madera_in_ev()
2273 priv->in_pending++; in madera_in_ev()
2276 priv->in_pending--; in madera_in_ev()
2281 if (priv->in_pending == 0) { in madera_in_ev()
2308 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_out_ev()
2310 struct madera *madera = priv->madera; in madera_out_ev()
2313 switch (madera->type) { in madera_out_ev()
2328 switch (w->shift) { in madera_out_ev()
2335 priv->out_up_pending++; in madera_out_ev()
2336 priv->out_up_delay += out_up_delay; in madera_out_ev()
2344 switch (w->shift) { in madera_out_ev()
2351 priv->out_up_pending--; in madera_out_ev()
2352 if (!priv->out_up_pending) { in madera_out_ev()
2353 msleep(priv->out_up_delay); in madera_out_ev()
2354 priv->out_up_delay = 0; in madera_out_ev()
2364 switch (w->shift) { in madera_out_ev()
2371 priv->out_down_pending++; in madera_out_ev()
2372 priv->out_down_delay++; in madera_out_ev()
2380 switch (w->shift) { in madera_out_ev()
2387 priv->out_down_pending--; in madera_out_ev()
2388 if (!priv->out_down_pending) { in madera_out_ev()
2389 msleep(priv->out_down_delay); in madera_out_ev()
2390 priv->out_down_delay = 0; in madera_out_ev()
2408 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_hp_ev()
2410 struct madera *madera = priv->madera; in madera_hp_ev()
2411 unsigned int mask = 1 << w->shift; in madera_hp_ev()
2412 unsigned int out_num = w->shift / 2; in madera_hp_ev()
2431 madera->hp_ena &= ~mask; in madera_hp_ev()
2432 madera->hp_ena |= val; in madera_hp_ev()
2434 switch (madera->type) { in madera_hp_ev()
2441 regmap_read(madera->regmap, MADERA_OUTPUT_ENABLES_1, &ep_sel); in madera_hp_ev()
2448 (!madera->out_clamp[out_num] || madera->out_shorted[out_num])) in madera_hp_ev()
2451 regmap_update_bits(madera->regmap, MADERA_OUTPUT_ENABLES_1, mask, val); in madera_hp_ev()
2460 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_anc_ev()
2465 val = 1 << w->shift; in madera_anc_ev()
2468 val = 1 << (w->shift + 1); in madera_anc_ev()
2501 int ref, div, refclk; in madera_set_opclk() local
2509 refclk = priv->sysclk; in madera_set_opclk()
2513 refclk = priv->asyncclk; in madera_set_opclk()
2516 return -EINVAL; in madera_set_opclk()
2519 if (refclk % 4000) in madera_set_opclk()
2525 if (rates[ref] > refclk) in madera_set_opclk()
2531 dev_dbg(component->dev, "Configured %dHz OPCLK\n", in madera_set_opclk()
2544 dev_err(component->dev, "Unable to generate %dHz OPCLK\n", freq); in madera_set_opclk()
2546 return -EINVAL; in madera_set_opclk()
2569 return -EINVAL; in madera_get_sysclk_setting()
2581 switch (madera->type) { in madera_get_legacy_dspclk_setting()
2584 if (madera->rev < 3) in madera_get_legacy_dspclk_setting()
2585 return -EINVAL; in madera_get_legacy_dspclk_setting()
2590 return -EINVAL; in madera_get_legacy_dspclk_setting()
2596 return -EINVAL; in madera_get_legacy_dspclk_setting()
2604 switch (madera->type) { in madera_get_dspclk_setting()
2612 return -EINVAL; in madera_get_dspclk_setting()
2627 dev_dbg(component->dev, "Configured OUTCLK to SYSCLK\n"); in madera_set_outclk()
2632 dev_dbg(component->dev, "Configured OUTCLK to ASYNCCLK\n"); in madera_set_outclk()
2641 return -EINVAL; in madera_set_outclk()
2653 dev_dbg(component->dev, "Configured %dHz OUTCLK\n", rate); in madera_set_outclk()
2666 dev_err(component->dev, in madera_set_outclk()
2669 return -EINVAL; in madera_set_outclk()
2676 struct madera *madera = priv->madera; in madera_set_sysclk()
2688 clk = &priv->sysclk; in madera_set_sysclk()
2695 clk = &priv->asyncclk; in madera_set_sysclk()
2701 clk = &priv->dspclk; in madera_set_sysclk()
2711 return -EINVAL; in madera_set_sysclk()
2715 dev_err(madera->dev, in madera_set_sysclk()
2723 dev_dbg(madera->dev, "%s cleared\n", name); in madera_set_sysclk()
2730 ret = regmap_write(madera->regmap, MADERA_DSP_CLOCK_2, in madera_set_sysclk()
2733 dev_err(madera->dev, in madera_set_sysclk()
2748 dev_dbg(madera->dev, "%s set to %uHz\n", name, freq); in madera_set_sysclk()
2750 return regmap_update_bits(madera->regmap, reg, mask, val); in madera_set_sysclk()
2756 struct snd_soc_component *component = dai->component; in madera_set_fmt()
2758 struct madera *madera = priv->madera; in madera_set_fmt()
2761 base = dai->driver->base; in madera_set_fmt()
2774 return -EINVAL; in madera_set_fmt()
2785 return -EINVAL; in madera_set_fmt()
2792 return -EINVAL; in madera_set_fmt()
2811 return -EINVAL; in madera_set_fmt()
2830 return -EINVAL; in madera_set_fmt()
2833 regmap_update_bits(madera->regmap, base + MADERA_AIF_BCLK_CTRL, in madera_set_fmt()
2836 regmap_update_bits(madera->regmap, base + MADERA_AIF_TX_PIN_CTRL, in madera_set_fmt()
2839 regmap_update_bits(madera->regmap, base + MADERA_AIF_RX_PIN_CTRL, in madera_set_fmt()
2842 regmap_update_bits(madera->regmap, base + MADERA_AIF_FORMAT, in madera_set_fmt()
2849 -1,
2871 -1,
2936 struct snd_soc_component *component = dai->component; in madera_startup()
2938 struct madera_dai_priv *dai_priv = &priv->dai[dai->id - 1]; in madera_startup()
2939 struct madera *madera = priv->madera; in madera_startup()
2942 if (!substream->runtime) in madera_startup()
2945 switch (dai_priv->clk) { in madera_startup()
2949 base_rate = priv->sysclk; in madera_startup()
2953 base_rate = priv->asyncclk; in madera_startup()
2959 switch (madera->type) { in madera_startup()
2964 dai_priv->constraint.mask = MADERA_384K_RATE_MASK; in madera_startup()
2966 dai_priv->constraint.mask = MADERA_384K_44K1_RATE_MASK; in madera_startup()
2968 dai_priv->constraint.mask = MADERA_384K_48K_RATE_MASK; in madera_startup()
2972 dai_priv->constraint.mask = MADERA_192K_RATE_MASK; in madera_startup()
2974 dai_priv->constraint.mask = MADERA_192K_44K1_RATE_MASK; in madera_startup()
2976 dai_priv->constraint.mask = MADERA_192K_48K_RATE_MASK; in madera_startup()
2980 return snd_pcm_hw_constraint_list(substream->runtime, 0, in madera_startup()
2982 &dai_priv->constraint); in madera_startup()
2989 struct snd_soc_component *component = dai->component; in madera_hw_params_rate()
2991 struct madera_dai_priv *dai_priv = &priv->dai[dai->id - 1]; in madera_hw_params_rate()
2992 int base = dai->driver->base; in madera_hw_params_rate()
3004 return -EINVAL; in madera_hw_params_rate()
3008 switch (dai_priv->clk) { in madera_hw_params_rate()
3030 madera_aif_err(dai, "Invalid clock %d\n", dai_priv->clk); in madera_hw_params_rate()
3031 return -EINVAL; in madera_hw_params_rate()
3040 ret = regmap_read(priv->madera->regmap, in madera_hw_params_rate()
3050 mutex_lock(&priv->rate_lock); in madera_hw_params_rate()
3054 ret = -EBUSY; in madera_hw_params_rate()
3065 mutex_unlock(&priv->rate_lock); in madera_hw_params_rate()
3095 struct snd_soc_component *component = dai->component; in madera_hw_params()
3097 struct madera *madera = priv->madera; in madera_hw_params()
3098 int base = dai->driver->base; in madera_hw_params()
3105 madera->pdata.codec.max_channels_clocked[dai->id - 1]; in madera_hw_params()
3106 int tdm_width = priv->tdm_width[dai->id - 1]; in madera_hw_params()
3107 int tdm_slots = priv->tdm_slots[dai->id - 1]; in madera_hw_params()
3156 return -EINVAL; in madera_hw_params()
3172 regmap_read(madera->regmap, base + MADERA_AIF_TX_ENABLES, in madera_hw_params()
3174 regmap_read(madera->regmap, base + MADERA_AIF_RX_ENABLES, in madera_hw_params()
3177 regmap_update_bits(madera->regmap, in madera_hw_params()
3179 regmap_update_bits(madera->regmap, in madera_hw_params()
3188 regmap_update_bits(madera->regmap, in madera_hw_params()
3191 regmap_update_bits(madera->regmap, in madera_hw_params()
3194 regmap_update_bits(madera->regmap, in madera_hw_params()
3198 regmap_update_bits(madera->regmap, in madera_hw_params()
3207 regmap_update_bits(madera->regmap, in madera_hw_params()
3210 regmap_update_bits(madera->regmap, in madera_hw_params()
3229 return -EINVAL; in madera_is_syncclk()
3236 struct snd_soc_component *component = dai->component; in madera_dai_set_sysclk()
3240 struct madera_dai_priv *dai_priv = &priv->dai[dai->id - 1]; in madera_dai_set_sysclk()
3246 dev_err(component->dev, "Illegal DAI clock id %d\n", clk_id); in madera_dai_set_sysclk()
3250 if (is_sync == madera_is_syncclk(dai_priv->clk)) in madera_dai_set_sysclk()
3254 dev_err(component->dev, "Can't change clock on active DAI %d\n", in madera_dai_set_sysclk()
3255 dai->id); in madera_dai_set_sysclk()
3256 return -EBUSY; in madera_dai_set_sysclk()
3259 dev_dbg(component->dev, "Setting AIF%d to %s\n", dai->id, in madera_dai_set_sysclk()
3267 routes[0].sink = dai->driver->capture.stream_name; in madera_dai_set_sysclk()
3268 routes[1].sink = dai->driver->playback.stream_name; in madera_dai_set_sysclk()
3277 dai_priv->clk = clk_id; in madera_dai_set_sysclk()
3284 struct snd_soc_component *component = dai->component; in madera_set_tristate()
3285 int base = dai->driver->base; in madera_set_tristate()
3307 struct snd_soc_component *component = dai->component; in madera_set_channels_to_mask()
3309 struct madera *madera = priv->madera; in madera_set_channels_to_mask()
3313 slot = ffs(mask) - 1; in madera_set_channels_to_mask()
3317 regmap_write(madera->regmap, base + i, slot); in madera_set_channels_to_mask()
3329 struct snd_soc_component *component = dai->component; in madera_set_tdm_slot()
3331 int base = dai->driver->base; in madera_set_tdm_slot()
3332 int rx_max_chan = dai->driver->playback.channels_max; in madera_set_tdm_slot()
3333 int tx_max_chan = dai->driver->capture.channels_max; in madera_set_tdm_slot()
3336 if (dai->id > MADERA_MAX_AIF) in madera_set_tdm_slot()
3337 return -ENOTSUPP; in madera_set_tdm_slot()
3340 tx_mask = (1 << tx_max_chan) - 1; in madera_set_tdm_slot()
3341 rx_mask = (1 << rx_max_chan) - 1; in madera_set_tdm_slot()
3349 priv->tdm_width[dai->id - 1] = slot_width; in madera_set_tdm_slot()
3350 priv->tdm_slots[dai->id - 1] = slots; in madera_set_tdm_slot()
3374 struct madera_dai_priv *dai_priv = &priv->dai[id]; in madera_init_dai()
3376 dai_priv->clk = MADERA_CLK_SYSCLK_1; in madera_init_dai()
3377 dai_priv->constraint = madera_constraint; in madera_init_dai()
3423 { 0, 256000, 0, -1 },
3424 { 256000, 1000000, 2, -1 },
3425 { 1000000, 13500000, 4, -1 },
3451 return -EINVAL; in madera_find_sync_fratio()
3463 *fratio = ratio - 1; in madera_find_main_fratio()
3471 switch (fll->madera->type) { in madera_find_fratio()
3473 switch (fll->madera->rev) { in madera_find_fratio()
3482 fll->fout, in madera_find_fratio()
3494 return madera_find_main_fratio(fref, fll->fout, fratio); in madera_find_fratio()
3507 cfg->refdiv = 0; in madera_calc_fratio()
3511 cfg->refdiv++; in madera_calc_fratio()
3514 return -EINVAL; in madera_calc_fratio()
3518 init_ratio = madera_find_fratio(fll, fref, sync, &cfg->fratio); in madera_calc_fratio()
3526 cfg->fratio = init_ratio - 1; in madera_calc_fratio()
3528 switch (fll->madera->type) { in madera_calc_fratio()
3530 switch (fll->madera->rev) { in madera_calc_fratio()
3552 refdiv = cfg->refdiv; in madera_calc_fratio()
3559 for (ratio = init_ratio; ratio > 0; ratio--) { in madera_calc_fratio()
3560 if (fll->fout % (ratio * fref)) { in madera_calc_fratio()
3561 cfg->refdiv = refdiv; in madera_calc_fratio()
3562 cfg->fratio = ratio - 1; in madera_calc_fratio()
3573 if (fref > pseudo_fref_max[ratio - 1]) in madera_calc_fratio()
3576 if (fll->fout % (ratio * fref)) { in madera_calc_fratio()
3577 cfg->refdiv = refdiv; in madera_calc_fratio()
3578 cfg->fratio = ratio - 1; in madera_calc_fratio()
3591 return cfg->fratio + 1; in madera_calc_fratio()
3604 cfg->gain = gains[i].gain; in madera_find_fll_gain()
3605 cfg->alt_gain = gains[i].alt_gain; in madera_find_fll_gain()
3612 return -EINVAL; in madera_find_fll_gain()
3625 fref, fll->fout, fll->fout * MADERA_FLL_VCO_MULT); in madera_calc_fll()
3633 fref = fref / (1 << cfg->refdiv); in madera_calc_fll()
3635 cfg->n = fll->fout / (ratio * fref); in madera_calc_fll()
3637 if (fll->fout % (ratio * fref)) { in madera_calc_fll()
3638 gcd_fll = gcd(fll->fout, ratio * fref); in madera_calc_fll()
3641 cfg->theta = (fll->fout - (cfg->n * ratio * fref)) in madera_calc_fll()
3643 cfg->lambda = (ratio * fref) / gcd_fll; in madera_calc_fll()
3645 cfg->theta = 0; in madera_calc_fll()
3646 cfg->lambda = 0; in madera_calc_fll()
3654 while (cfg->lambda >= (1 << 16)) { in madera_calc_fll()
3655 cfg->theta >>= 1; in madera_calc_fll()
3656 cfg->lambda >>= 1; in madera_calc_fll()
3659 switch (fll->madera->type) { in madera_calc_fll()
3661 switch (fll->madera->rev) { in madera_calc_fll()
3700 cfg->n, cfg->theta, cfg->lambda); in madera_calc_fll()
3702 cfg->fratio, ratio, cfg->refdiv, 1 << cfg->refdiv); in madera_calc_fll()
3703 madera_fll_dbg(fll, "GAIN=0x%x(%d)\n", cfg->gain, 1 << cfg->gain); in madera_calc_fll()
3715 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3718 cfg->theta, &change); in madera_write_fll()
3720 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3723 cfg->lambda, &change); in madera_write_fll()
3725 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3728 cfg->fratio << MADERA_FLL1_FRATIO_SHIFT, in madera_write_fll()
3731 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3735 cfg->refdiv << MADERA_FLL1_REFCLK_DIV_SHIFT | in madera_write_fll()
3741 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3748 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3756 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3759 MADERA_FLL1_CTRL_UPD | cfg->n, &change); in madera_write_fll()
3767 struct madera *madera = fll->madera; in madera_is_enabled_fll()
3771 ret = regmap_read(madera->regmap, in madera_is_enabled_fll()
3783 struct madera *madera = fll->madera; in madera_wait_for_fll()
3791 regmap_read(madera->regmap, MADERA_IRQ1_RAW_STATUS_2, &val); in madera_wait_for_fll()
3792 status = val & (MADERA_FLL1_LOCK_STS1 << (fll->id - 1)); in madera_wait_for_fll()
3811 return -ETIMEDOUT; in madera_wait_for_fll()
3821 if (!sync && ref_cfg->theta == 0) in madera_set_fll_phase_integrator()
3827 regmap_update_bits_check(fll->madera->regmap, in madera_set_fll_phase_integrator()
3828 fll->base + MADERA_FLL_EFS_2_OFFS, in madera_set_fll_phase_integrator()
3840 struct madera *madera = fll->madera; in madera_set_fll_clks_reg()
3845 ret = regmap_read(madera->regmap, reg, &src); in madera_set_fll_clks_reg()
3856 clk = madera->mclk[MADERA_MCLK1].clk; in madera_set_fll_clks_reg()
3859 clk = madera->mclk[MADERA_MCLK2].clk; in madera_set_fll_clks_reg()
3862 clk = madera->mclk[MADERA_MCLK3].clk; in madera_set_fll_clks_reg()
3902 struct madera *madera = fll->madera; in madera_disable_fll()
3906 switch (madera->type) { in madera_disable_fll()
3908 sync_base = fll->base + CS47L35_FLL_SYNCHRONISER_OFFS; in madera_disable_fll()
3911 sync_base = fll->base + MADERA_FLL_SYNCHRONISER_OFFS; in madera_disable_fll()
3917 regmap_update_bits(madera->regmap, in madera_disable_fll()
3918 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_disable_fll()
3920 regmap_update_bits_check(madera->regmap, in madera_disable_fll()
3921 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_disable_fll()
3923 regmap_update_bits_check(madera->regmap, in madera_disable_fll()
3926 regmap_update_bits(madera->regmap, in madera_disable_fll()
3927 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_disable_fll()
3936 madera_set_fll_clks(fll, fll->base, false); in madera_disable_fll()
3937 pm_runtime_put_autosuspend(madera->dev); in madera_disable_fll()
3943 struct madera *madera = fll->madera; in madera_enable_fll()
3945 int already_enabled = madera_is_enabled_fll(fll, fll->base); in madera_enable_fll()
3955 if (fll->ref_src < 0 || fll->ref_freq == 0) { in madera_enable_fll()
3956 madera_fll_err(fll, "No REFCLK\n"); in madera_enable_fll()
3957 ret = -EINVAL; in madera_enable_fll()
3964 if (fll->fout < MADERA_FLL_MIN_FOUT || in madera_enable_fll()
3965 fll->fout > MADERA_FLL_MAX_FOUT) { in madera_enable_fll()
3966 madera_fll_err(fll, "invalid fout %uHz\n", fll->fout); in madera_enable_fll()
3967 ret = -EINVAL; in madera_enable_fll()
3971 switch (madera->type) { in madera_enable_fll()
3973 sync_base = fll->base + CS47L35_FLL_SYNCHRONISER_OFFS; in madera_enable_fll()
3976 sync_base = fll->base + MADERA_FLL_SYNCHRONISER_OFFS; in madera_enable_fll()
3985 /* Facilitate smooth refclk across the transition */ in madera_enable_fll()
3986 regmap_update_bits(fll->madera->regmap, in madera_enable_fll()
3987 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_enable_fll()
3991 regmap_update_bits(fll->madera->regmap, in madera_enable_fll()
3992 fll->base + MADERA_FLL_CONTROL_7_OFFS, in madera_enable_fll()
3997 madera_set_fll_clks(fll, fll->base, false); in madera_enable_fll()
4001 if (fll->sync_src >= 0) { in madera_enable_fll()
4002 ret = madera_calc_fll(fll, &cfg, fll->sync_freq, true); in madera_enable_fll()
4007 &cfg, fll->sync_src, in madera_enable_fll()
4015 /* Apply REFCLK setting */ in madera_enable_fll()
4016 ret = madera_calc_fll(fll, &cfg, fll->ref_freq, false); in madera_enable_fll()
4024 switch (fll->madera->type) { in madera_enable_fll()
4026 switch (fll->madera->rev) { in madera_enable_fll()
4055 fll_change |= madera_write_fll(madera, fll->base, in madera_enable_fll()
4056 &cfg, fll->ref_src, in madera_enable_fll()
4063 if (have_sync && fll->sync_freq > 100000) in madera_enable_fll()
4064 regmap_update_bits(madera->regmap, in madera_enable_fll()
4068 regmap_update_bits(madera->regmap, in madera_enable_fll()
4074 pm_runtime_get_sync(madera->dev); in madera_enable_fll()
4078 regmap_update_bits(madera->regmap, in madera_enable_fll()
4084 madera_set_fll_clks(fll, fll->base, true); in madera_enable_fll()
4085 regmap_update_bits(madera->regmap, in madera_enable_fll()
4086 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_enable_fll()
4090 regmap_update_bits(madera->regmap, in madera_enable_fll()
4091 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_enable_fll()
4108 if (fll->fout) { in madera_apply_fll()
4121 * constraint on the Fout generated from REFCLK, so the Fout is in madera_set_fll_syncclk()
4122 * set when configuring REFCLK in madera_set_fll_syncclk()
4125 if (fll->sync_src == source && fll->sync_freq == fref) in madera_set_fll_syncclk()
4128 fll->sync_src = source; in madera_set_fll_syncclk()
4129 fll->sync_freq = fref; in madera_set_fll_syncclk()
4140 if (fll->ref_src == source && in madera_set_fll_refclk()
4141 fll->ref_freq == fref && fll->fout == fout) in madera_set_fll_refclk()
4148 if (fout && fout != fll->fout) { in madera_set_fll_refclk()
4149 ret = madera_is_enabled_fll(fll, fll->base); in madera_set_fll_refclk()
4155 return -EBUSY; in madera_set_fll_refclk()
4159 fll->ref_src = source; in madera_set_fll_refclk()
4160 fll->ref_freq = fref; in madera_set_fll_refclk()
4161 fll->fout = fout; in madera_set_fll_refclk()
4170 fll->id = id; in madera_init_fll()
4171 fll->base = base; in madera_init_fll()
4172 fll->madera = madera; in madera_init_fll()
4173 fll->ref_src = MADERA_FLL_SRC_NONE; in madera_init_fll()
4174 fll->sync_src = MADERA_FLL_SRC_NONE; in madera_init_fll()
4176 regmap_update_bits(madera->regmap, in madera_init_fll()
4177 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_init_fll()
4237 struct madera *madera = fll->madera; in madera_enable_fll_ao()
4238 int already_enabled = madera_is_enabled_fll(fll, fll->base); in madera_enable_fll_ao()
4246 pm_runtime_get_sync(madera->dev); in madera_enable_fll_ao()
4252 regmap_update_bits(fll->madera->regmap, in madera_enable_fll_ao()
4253 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_enable_fll_ao()
4257 madera_set_fllao_clks(fll, fll->base, false); in madera_enable_fll_ao()
4262 /* modify the patch to apply fll->ref_src as input clock */ in madera_enable_fll_ao()
4265 val |= (fll->ref_src << MADERA_FLL_AO_REFCLK_SRC_SHIFT) in madera_enable_fll_ao()
4269 regmap_write(madera->regmap, patch[i].reg, val); in madera_enable_fll_ao()
4272 madera_set_fllao_clks(fll, fll->base, true); in madera_enable_fll_ao()
4274 regmap_update_bits(madera->regmap, in madera_enable_fll_ao()
4275 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_enable_fll_ao()
4279 regmap_update_bits(madera->regmap, in madera_enable_fll_ao()
4280 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_enable_fll_ao()
4291 struct madera *madera = fll->madera; in madera_disable_fll_ao()
4296 regmap_update_bits(madera->regmap, in madera_disable_fll_ao()
4297 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_disable_fll_ao()
4299 regmap_update_bits_check(madera->regmap, in madera_disable_fll_ao()
4300 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_disable_fll_ao()
4313 regmap_update_bits(madera->regmap, in madera_disable_fll_ao()
4314 fll->base + MADERA_FLLAO_CONTROL_2_OFFS, in madera_disable_fll_ao()
4318 madera_set_fllao_clks(fll, fll->base, false); in madera_disable_fll_ao()
4319 pm_runtime_put_autosuspend(madera->dev); in madera_disable_fll_ao()
4333 if (fll->ref_src == source && in madera_set_fll_ao_refclk()
4334 fll->ref_freq == fin && fll->fout == fout) in madera_set_fll_ao_refclk()
4337 madera_fll_dbg(fll, "Change FLL_AO refclk to fin=%u fout=%u source=%d\n", in madera_set_fll_ao_refclk()
4340 if (fout && (fll->ref_freq != fin || fll->fout != fout)) { in madera_set_fll_ao_refclk()
4350 return -EINVAL; in madera_set_fll_ao_refclk()
4357 fll->ref_src = source; in madera_set_fll_ao_refclk()
4358 fll->ref_freq = fin; in madera_set_fll_ao_refclk()
4359 fll->fout = fout; in madera_set_fll_ao_refclk()
4372 struct madera *madera = fll->madera; in madera_fllhj_disable()
4379 * again due to a control clock being required, the lock won't re-assert in madera_fllhj_disable()
4383 regmap_update_bits(madera->regmap, in madera_fllhj_disable()
4384 fll->base + MADERA_FLL_CONTROL_11_OFFS, in madera_fllhj_disable()
4386 regmap_update_bits(madera->regmap, in madera_fllhj_disable()
4387 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_disable()
4389 regmap_update_bits_check(madera->regmap, in madera_fllhj_disable()
4390 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_disable()
4402 regmap_update_bits(madera->regmap, in madera_fllhj_disable()
4403 fll->base + MADERA_FLL_CONTROL_2_OFFS, in madera_fllhj_disable()
4407 madera_set_fllhj_clks(fll, fll->base, false); in madera_fllhj_disable()
4408 pm_runtime_put_autosuspend(madera->dev); in madera_fllhj_disable()
4416 struct madera *madera = fll->madera; in madera_fllhj_apply()
4422 madera_fll_dbg(fll, "fin=%d, fout=%d\n", fin, fll->fout); in madera_fllhj_apply()
4434 fout = fll->fout; in madera_fllhj_apply()
4457 fout = fll->fout * 6; in madera_fllhj_apply()
4480 return -EINVAL; in madera_fllhj_apply()
4487 return -EINVAL; in madera_fllhj_apply()
4506 madera_fll_err(fll, "N not in valid %s mode range %d-%d: %d\n", in madera_fllhj_apply()
4509 return -EINVAL; in madera_fllhj_apply()
4514 return -EINVAL; in madera_fllhj_apply()
4518 regmap_write(madera->regmap, in madera_fllhj_apply()
4519 fll->base + MADERA_FLL_CONTROL_2_OFFS, in madera_fllhj_apply()
4521 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4522 fll->base + MADERA_FLL_CONTROL_3_OFFS, in madera_fllhj_apply()
4525 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4526 fll->base + MADERA_FLL_CONTROL_4_OFFS, in madera_fllhj_apply()
4529 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4530 fll->base + MADERA_FLL_CONTROL_5_OFFS, in madera_fllhj_apply()
4533 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4534 fll->base + MADERA_FLL_CONTROL_6_OFFS, in madera_fllhj_apply()
4537 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4538 fll->base + MADERA_FLL_GAIN_OFFS, in madera_fllhj_apply()
4543 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4544 fll->base + MADERA_FLL_CONTROL_10_OFFS, in madera_fllhj_apply()
4547 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4548 fll->base + MADERA_FLL_CONTROL_11_OFFS, in madera_fllhj_apply()
4551 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4552 fll->base + MADERA_FLL1_DIGITAL_TEST_1_OFFS, in madera_fllhj_apply()
4562 struct madera *madera = fll->madera; in madera_fllhj_enable()
4563 int already_enabled = madera_is_enabled_fll(fll, fll->base); in madera_fllhj_enable()
4570 pm_runtime_get_sync(madera->dev); in madera_fllhj_enable()
4576 regmap_update_bits(fll->madera->regmap, in madera_fllhj_enable()
4577 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4582 madera_set_fllhj_clks(fll, fll->base, false); in madera_fllhj_enable()
4584 /* Apply refclk */ in madera_fllhj_enable()
4585 ret = madera_fllhj_apply(fll, fll->ref_freq); in madera_fllhj_enable()
4590 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4591 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4593 fll->ref_src << CS47L92_FLL1_REFCLK_SRC_SHIFT); in madera_fllhj_enable()
4595 madera_set_fllhj_clks(fll, fll->base, true); in madera_fllhj_enable()
4597 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4598 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4603 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4604 fll->base + MADERA_FLL_CONTROL_11_OFFS, in madera_fllhj_enable()
4608 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4609 fll->base + MADERA_FLL_CONTROL_2_OFFS, in madera_fllhj_enable()
4614 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4615 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4631 return -EINVAL; in madera_fllhj_validate()
4634 if (fll->fout && fout != fll->fout) { in madera_fllhj_validate()
4636 return -EINVAL; in madera_fllhj_validate()
4641 return -EINVAL; in madera_fllhj_validate()
4659 if (fll->ref_src == source && fll->ref_freq == fin && in madera_fllhj_set_refclk()
4660 fll->fout == fout) in madera_fllhj_set_refclk()
4664 return -EINVAL; in madera_fllhj_set_refclk()
4666 fll->ref_src = source; in madera_fllhj_set_refclk()
4667 fll->ref_freq = fin; in madera_fllhj_set_refclk()
4668 fll->fout = fout; in madera_fllhj_set_refclk()
4680 * madera_set_output_mode - Set the mode of the specified output
4702 return -EINVAL; in madera_set_output_mode()
4704 reg = MADERA_OUTPUT_PATH_CONFIG_1L + (output - 1) * 8; in madera_set_output_mode()
4731 return (abs((a << 16) / (4096 - b)) >= 4096 << 4); in madera_eq_filter_unstable()
4741 struct madera *madera = priv->madera; in madera_eq_coeff_put()
4742 struct soc_bytes *params = (void *)kcontrol->private_value; in madera_eq_coeff_put()
4748 len = params->num_regs * regmap_get_val_bytes(madera->regmap); in madera_eq_coeff_put()
4750 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); in madera_eq_coeff_put()
4752 return -ENOMEM; in madera_eq_coeff_put()
4761 dev_err(madera->dev, "Rejecting unstable EQ coefficients\n"); in madera_eq_coeff_put()
4762 ret = -EINVAL; in madera_eq_coeff_put()
4766 ret = regmap_read(madera->regmap, params->base, &val); in madera_eq_coeff_put()
4773 ret = regmap_raw_write(madera->regmap, params->base, data, len); in madera_eq_coeff_put()
4788 struct madera *madera = priv->madera; in madera_lhpf_coeff_put()
4789 __be16 *data = (__be16 *)ucontrol->value.bytes.data; in madera_lhpf_coeff_put()
4793 dev_err(madera->dev, "Rejecting unstable LHPF coefficients\n"); in madera_lhpf_coeff_put()
4794 return -EINVAL; in madera_lhpf_coeff_put()