Lines Matching +full:fllao +full:- +full:lock
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()
512 * We can't rely on the DAPM mutex for locking because we need a lock 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()
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()
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()
623 dev_err(madera->dev, "Failed to update demux power state: %d\n", ret); in madera_out1_demux_put()
641 ucontrol->value.enumerated.item[0] = val; in madera_out1_demux_get()
655 struct madera *madera = priv->madera; in madera_inmux_put()
656 struct regmap *regmap = madera->regmap; in madera_inmux_put()
657 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_inmux_put()
663 mux = ucontrol->value.enumerated.item[0]; in madera_inmux_put()
665 return -EINVAL; in madera_inmux_put()
667 val = mux << e->shift_l; in madera_inmux_put()
668 mask = (e->mask << e->shift_l) | MADERA_IN1L_SRC_SE_MASK; in madera_inmux_put()
670 switch (e->reg) { in madera_inmux_put()
672 inmode = madera->pdata.codec.inmode[0][2 * mux]; in madera_inmux_put()
675 inmode = madera->pdata.codec.inmode[0][1 + (2 * mux)]; in madera_inmux_put()
678 inmode = madera->pdata.codec.inmode[1][2 * mux]; in madera_inmux_put()
681 inmode = madera->pdata.codec.inmode[1][1 + (2 * mux)]; in madera_inmux_put()
684 return -EINVAL; in madera_inmux_put()
690 dev_dbg(madera->dev, "mux=%u reg=0x%x inmode=0x%x mask=0x%x val=0x%x\n", in madera_inmux_put()
691 mux, e->reg, inmode, mask, val); in madera_inmux_put()
693 ret = regmap_update_bits_check(regmap, e->reg, mask, val, &changed); in madera_inmux_put()
775 count = priv->domain_group_ref[MADERA_DOM_GRP_FX]; in madera_can_change_grp_rate()
779 count = priv->domain_group_ref[MADERA_DOM_GRP_ASRC1]; in madera_can_change_grp_rate()
783 count = priv->domain_group_ref[MADERA_DOM_GRP_ASRC2]; in madera_can_change_grp_rate()
787 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC1]; in madera_can_change_grp_rate()
791 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC2]; in madera_can_change_grp_rate()
795 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC3]; in madera_can_change_grp_rate()
799 count = priv->domain_group_ref[MADERA_DOM_GRP_ISRC4]; in madera_can_change_grp_rate()
802 count = priv->domain_group_ref[MADERA_DOM_GRP_OUT]; in madera_can_change_grp_rate()
805 count = priv->domain_group_ref[MADERA_DOM_GRP_SPD]; in madera_can_change_grp_rate()
809 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP1]; in madera_can_change_grp_rate()
813 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP2]; in madera_can_change_grp_rate()
817 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP3]; in madera_can_change_grp_rate()
821 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP4]; in madera_can_change_grp_rate()
825 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP5]; in madera_can_change_grp_rate()
829 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP6]; in madera_can_change_grp_rate()
833 count = priv->domain_group_ref[MADERA_DOM_GRP_DSP7]; in madera_can_change_grp_rate()
836 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF1]; in madera_can_change_grp_rate()
839 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF2]; in madera_can_change_grp_rate()
842 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF3]; in madera_can_change_grp_rate()
845 count = priv->domain_group_ref[MADERA_DOM_GRP_AIF4]; in madera_can_change_grp_rate()
855 count = priv->domain_group_ref[MADERA_DOM_GRP_SLIMBUS]; in madera_can_change_grp_rate()
858 count = priv->domain_group_ref[MADERA_DOM_GRP_PWM]; in madera_can_change_grp_rate()
864 dev_dbg(priv->madera->dev, "Rate reg 0x%x group ref %d\n", reg, count); in madera_can_change_grp_rate()
878 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_adsp_rate_get()
880 const int adsp_num = e->shift_l; in madera_adsp_rate_get()
883 mutex_lock(&priv->rate_lock); in madera_adsp_rate_get()
884 cached_rate = priv->adsp_rate_cache[adsp_num]; in madera_adsp_rate_get()
885 mutex_unlock(&priv->rate_lock); in madera_adsp_rate_get()
888 ucontrol->value.enumerated.item[0] = item; in madera_adsp_rate_get()
899 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_adsp_rate_put()
900 const int adsp_num = e->shift_l; in madera_adsp_rate_put()
901 const unsigned int item = ucontrol->value.enumerated.item[0]; in madera_adsp_rate_put()
904 if (item >= e->items) in madera_adsp_rate_put()
905 return -EINVAL; in madera_adsp_rate_put()
912 mutex_lock(&priv->rate_lock); in madera_adsp_rate_put()
914 if (!madera_can_change_grp_rate(priv, priv->adsp[adsp_num].cs_dsp.base)) { in madera_adsp_rate_put()
915 dev_warn(priv->madera->dev, in madera_adsp_rate_put()
917 kcontrol->id.name); in madera_adsp_rate_put()
918 ret = -EBUSY; in madera_adsp_rate_put()
919 } else if (priv->adsp_rate_cache[adsp_num] != e->values[item]) { in madera_adsp_rate_put()
921 priv->adsp_rate_cache[adsp_num] = e->values[item]; in madera_adsp_rate_put()
925 mutex_unlock(&priv->rate_lock); in madera_adsp_rate_put()
973 val = priv->adsp_rate_cache[dsp->cs_dsp.num - 1] << MADERA_DSP_RATE_SHIFT; in madera_write_adsp_clk_setting()
975 switch (priv->madera->type) { in madera_write_adsp_clk_setting()
985 dev_dbg(priv->madera->dev, "Set DSP frequency to 0x%x\n", freq); in madera_write_adsp_clk_setting()
987 ret = regmap_write(dsp->cs_dsp.regmap, in madera_write_adsp_clk_setting()
988 dsp->cs_dsp.base + MADERA_DSP_CONFIG_2_OFFS, freq); in madera_write_adsp_clk_setting()
994 ret = regmap_update_bits(dsp->cs_dsp.regmap, in madera_write_adsp_clk_setting()
995 dsp->cs_dsp.base + MADERA_DSP_CONFIG_1_OFFS, in madera_write_adsp_clk_setting()
1000 dev_dbg(priv->madera->dev, "Set DSP clocking to 0x%x\n", val); in madera_write_adsp_clk_setting()
1005 dev_err(dsp->cs_dsp.dev, "Failed to set DSP%d clock: %d\n", dsp->cs_dsp.num, ret); in madera_write_adsp_clk_setting()
1013 struct wm_adsp *dsp = &priv->adsp[dsp_num]; in madera_set_adsp_clk()
1014 struct madera *madera = priv->madera; in madera_set_adsp_clk()
1027 ret = regmap_read(dsp->cs_dsp.regmap, dsp->cs_dsp.base, &cur); in madera_set_adsp_clk()
1029 dev_err(madera->dev, in madera_set_adsp_clk()
1036 new = priv->adsp_rate_cache[dsp->cs_dsp.num - 1] << MADERA_DSP_RATE_SHIFT; in madera_set_adsp_clk()
1039 dev_dbg(madera->dev, "DSP rate not changed\n"); in madera_set_adsp_clk()
1042 dev_dbg(madera->dev, "DSP rate changed\n"); in madera_set_adsp_clk()
1059 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_rate_put()
1060 unsigned int item = ucontrol->value.enumerated.item[0]; in madera_rate_put()
1064 if (item >= e->items) in madera_rate_put()
1065 return -EINVAL; in madera_rate_put()
1071 mutex_lock(&priv->rate_lock); in madera_rate_put()
1073 val = snd_soc_component_read(component, e->reg); in madera_rate_put()
1074 val >>= e->shift_l; in madera_rate_put()
1075 val &= e->mask; in madera_rate_put()
1081 if (!madera_can_change_grp_rate(priv, e->reg)) { in madera_rate_put()
1082 dev_warn(priv->madera->dev, in madera_rate_put()
1084 kcontrol->id.name); in madera_rate_put()
1085 ret = -EBUSY; in madera_rate_put()
1093 mutex_unlock(&priv->rate_lock); in madera_rate_put()
1104 switch (madera->type) { in madera_configure_input_mode()
1134 dev_dbg(madera->dev, "IN%d mode %u:%u:%u:%u\n", i + 1, in madera_configure_input_mode()
1135 madera->pdata.codec.inmode[i][0], in madera_configure_input_mode()
1136 madera->pdata.codec.inmode[i][1], in madera_configure_input_mode()
1137 madera->pdata.codec.inmode[i][2], in madera_configure_input_mode()
1138 madera->pdata.codec.inmode[i][3]); in madera_configure_input_mode()
1140 dig_mode = madera->pdata.codec.dmic_ref[i] << in madera_configure_input_mode()
1143 switch (madera->pdata.codec.inmode[i][0]) { in madera_configure_input_mode()
1151 dev_warn(madera->dev, in madera_configure_input_mode()
1153 i + 1, madera->pdata.codec.inmode[i][0]); in madera_configure_input_mode()
1157 switch (madera->pdata.codec.inmode[i][1]) { in madera_configure_input_mode()
1165 dev_warn(madera->dev, in madera_configure_input_mode()
1167 i + 1, madera->pdata.codec.inmode[i][1]); in madera_configure_input_mode()
1171 dev_dbg(madera->dev, in madera_configure_input_mode()
1175 regmap_update_bits(madera->regmap, in madera_configure_input_mode()
1182 regmap_update_bits(madera->regmap, in madera_configure_input_mode()
1186 regmap_update_bits(madera->regmap, in madera_configure_input_mode()
1195 struct madera *madera = priv->madera; in madera_init_inputs()
1219 struct madera *madera = priv->madera; in madera_init_outputs()
1220 const struct madera_codec_pdata *pdata = &madera->pdata.codec; in madera_init_outputs()
1225 dev_warn(madera->dev, in madera_init_outputs()
1236 if (pdata->out_mono[i]) { in madera_init_outputs()
1246 regmap_update_bits(madera->regmap, in madera_init_outputs()
1250 dev_dbg(madera->dev, "OUT%d mono=0x%x\n", i + 1, val); in madera_init_outputs()
1254 dev_dbg(madera->dev, "PDM%d fmt=0x%x mute=0x%x\n", i + 1, in madera_init_outputs()
1255 pdata->pdm_fmt[i], pdata->pdm_mute[i]); in madera_init_outputs()
1257 if (pdata->pdm_mute[i]) in madera_init_outputs()
1258 regmap_update_bits(madera->regmap, in madera_init_outputs()
1262 pdata->pdm_mute[i]); in madera_init_outputs()
1264 if (pdata->pdm_fmt[i]) in madera_init_outputs()
1265 regmap_update_bits(madera->regmap, in madera_init_outputs()
1268 pdata->pdm_fmt[i]); in madera_init_outputs()
1278 struct madera *madera = priv->madera; in madera_init_bus_error_irq()
1285 &priv->adsp[dsp_num]); in madera_init_bus_error_irq()
1287 dev_err(madera->dev, in madera_init_bus_error_irq()
1288 "Failed to request DSP Lock region IRQ: %d\n", ret); in madera_init_bus_error_irq()
1296 struct madera *madera = priv->madera; in madera_free_bus_error_irq()
1300 &priv->adsp[dsp_num]); in madera_free_bus_error_irq()
1611 const DECLARE_TLV_DB_SCALE(madera_eq_tlv, -1200, 100, 0);
1614 const DECLARE_TLV_DB_SCALE(madera_digital_tlv, -6400, 50, 0);
1617 const DECLARE_TLV_DB_SCALE(madera_noise_tlv, -13200, 600, 0);
1620 const DECLARE_TLV_DB_SCALE(madera_ng_tlv, -12000, 600, 0);
1623 const DECLARE_TLV_DB_SCALE(madera_mixer_tlv, -3200, 100, 0);
1994 "Low-pass", "High-pass"
2169 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in madera_dfc_put()
2170 unsigned int reg = e->reg; in madera_dfc_put()
2174 reg = ((reg / 6) * 6) - 2; in madera_dfc_put()
2180 ret = -EBUSY; in madera_dfc_put()
2181 dev_err(component->dev, "Can't change mode on an active DFC\n"); in madera_dfc_put()
2197 (struct soc_mixer_control *)kcontrol->private_value; in madera_lp_mode_put()
2209 mask = (mc->reg - MADERA_ADC_DIGITAL_VOLUME_1L) / 4; in madera_lp_mode_put()
2213 ret = -EBUSY; in madera_lp_mode_put()
2214 dev_err(component->dev, in madera_lp_mode_put()
2255 for (i = 0; i < priv->num_inputs; i++) { in madera_in_set_vu()
2256 ret = regmap_update_bits(priv->madera->regmap, in madera_in_set_vu()
2260 dev_warn(priv->madera->dev, in madera_in_set_vu()
2268 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_in_ev()
2272 if (w->shift % 2) in madera_in_ev()
2273 reg = MADERA_ADC_DIGITAL_VOLUME_1L + ((w->shift / 2) * 8); in madera_in_ev()
2275 reg = MADERA_ADC_DIGITAL_VOLUME_1R + ((w->shift / 2) * 8); in madera_in_ev()
2279 priv->in_pending++; in madera_in_ev()
2282 priv->in_pending--; in madera_in_ev()
2287 if (priv->in_pending == 0) { in madera_in_ev()
2314 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_out_ev()
2316 struct madera *madera = priv->madera; in madera_out_ev()
2319 switch (madera->type) { in madera_out_ev()
2334 switch (w->shift) { in madera_out_ev()
2341 priv->out_up_pending++; in madera_out_ev()
2342 priv->out_up_delay += out_up_delay; in madera_out_ev()
2350 switch (w->shift) { in madera_out_ev()
2357 priv->out_up_pending--; in madera_out_ev()
2358 if (!priv->out_up_pending) { in madera_out_ev()
2359 msleep(priv->out_up_delay); in madera_out_ev()
2360 priv->out_up_delay = 0; in madera_out_ev()
2370 switch (w->shift) { in madera_out_ev()
2377 priv->out_down_pending++; in madera_out_ev()
2378 priv->out_down_delay++; in madera_out_ev()
2386 switch (w->shift) { in madera_out_ev()
2393 priv->out_down_pending--; in madera_out_ev()
2394 if (!priv->out_down_pending) { in madera_out_ev()
2395 msleep(priv->out_down_delay); in madera_out_ev()
2396 priv->out_down_delay = 0; in madera_out_ev()
2414 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_hp_ev()
2416 struct madera *madera = priv->madera; in madera_hp_ev()
2417 unsigned int mask = 1 << w->shift; in madera_hp_ev()
2418 unsigned int out_num = w->shift / 2; in madera_hp_ev()
2437 madera->hp_ena &= ~mask; in madera_hp_ev()
2438 madera->hp_ena |= val; in madera_hp_ev()
2440 switch (madera->type) { in madera_hp_ev()
2447 regmap_read(madera->regmap, MADERA_OUTPUT_ENABLES_1, &ep_sel); in madera_hp_ev()
2454 (!madera->out_clamp[out_num] || madera->out_shorted[out_num])) in madera_hp_ev()
2457 regmap_update_bits(madera->regmap, MADERA_OUTPUT_ENABLES_1, mask, val); in madera_hp_ev()
2466 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in madera_anc_ev()
2471 val = 1 << w->shift; in madera_anc_ev()
2474 val = 1 << (w->shift + 1); in madera_anc_ev()
2515 refclk = priv->sysclk; in madera_set_opclk()
2519 refclk = priv->asyncclk; in madera_set_opclk()
2522 return -EINVAL; in madera_set_opclk()
2537 dev_dbg(component->dev, "Configured %dHz OPCLK\n", in madera_set_opclk()
2550 dev_err(component->dev, "Unable to generate %dHz OPCLK\n", freq); in madera_set_opclk()
2552 return -EINVAL; in madera_set_opclk()
2575 return -EINVAL; in madera_get_sysclk_setting()
2587 switch (madera->type) { in madera_get_legacy_dspclk_setting()
2590 if (madera->rev < 3) in madera_get_legacy_dspclk_setting()
2591 return -EINVAL; in madera_get_legacy_dspclk_setting()
2596 return -EINVAL; in madera_get_legacy_dspclk_setting()
2602 return -EINVAL; in madera_get_legacy_dspclk_setting()
2610 switch (madera->type) { in madera_get_dspclk_setting()
2618 return -EINVAL; in madera_get_dspclk_setting()
2633 dev_dbg(component->dev, "Configured OUTCLK to SYSCLK\n"); in madera_set_outclk()
2638 dev_dbg(component->dev, "Configured OUTCLK to ASYNCCLK\n"); in madera_set_outclk()
2647 return -EINVAL; in madera_set_outclk()
2659 dev_dbg(component->dev, "Configured %dHz OUTCLK\n", rate); in madera_set_outclk()
2672 dev_err(component->dev, in madera_set_outclk()
2675 return -EINVAL; in madera_set_outclk()
2682 struct madera *madera = priv->madera; in madera_set_sysclk()
2694 clk = &priv->sysclk; in madera_set_sysclk()
2701 clk = &priv->asyncclk; in madera_set_sysclk()
2707 clk = &priv->dspclk; in madera_set_sysclk()
2717 return -EINVAL; in madera_set_sysclk()
2721 dev_err(madera->dev, in madera_set_sysclk()
2729 dev_dbg(madera->dev, "%s cleared\n", name); in madera_set_sysclk()
2736 ret = regmap_write(madera->regmap, MADERA_DSP_CLOCK_2, in madera_set_sysclk()
2739 dev_err(madera->dev, in madera_set_sysclk()
2754 dev_dbg(madera->dev, "%s set to %uHz\n", name, freq); in madera_set_sysclk()
2756 return regmap_update_bits(madera->regmap, reg, mask, val); in madera_set_sysclk()
2762 struct snd_soc_component *component = dai->component; in madera_set_fmt()
2764 struct madera *madera = priv->madera; in madera_set_fmt()
2767 base = dai->driver->base; in madera_set_fmt()
2780 return -EINVAL; in madera_set_fmt()
2791 return -EINVAL; in madera_set_fmt()
2798 return -EINVAL; in madera_set_fmt()
2817 return -EINVAL; in madera_set_fmt()
2836 return -EINVAL; in madera_set_fmt()
2839 regmap_update_bits(madera->regmap, base + MADERA_AIF_BCLK_CTRL, in madera_set_fmt()
2842 regmap_update_bits(madera->regmap, base + MADERA_AIF_TX_PIN_CTRL, in madera_set_fmt()
2845 regmap_update_bits(madera->regmap, base + MADERA_AIF_RX_PIN_CTRL, in madera_set_fmt()
2848 regmap_update_bits(madera->regmap, base + MADERA_AIF_FORMAT, in madera_set_fmt()
2855 -1,
2877 -1,
2942 struct snd_soc_component *component = dai->component; in madera_startup()
2944 struct madera_dai_priv *dai_priv = &priv->dai[dai->id - 1]; in madera_startup()
2945 struct madera *madera = priv->madera; in madera_startup()
2948 if (!substream->runtime) in madera_startup()
2951 switch (dai_priv->clk) { in madera_startup()
2955 base_rate = priv->sysclk; in madera_startup()
2959 base_rate = priv->asyncclk; in madera_startup()
2965 switch (madera->type) { in madera_startup()
2970 dai_priv->constraint.mask = MADERA_384K_RATE_MASK; in madera_startup()
2972 dai_priv->constraint.mask = MADERA_384K_44K1_RATE_MASK; in madera_startup()
2974 dai_priv->constraint.mask = MADERA_384K_48K_RATE_MASK; in madera_startup()
2978 dai_priv->constraint.mask = MADERA_192K_RATE_MASK; in madera_startup()
2980 dai_priv->constraint.mask = MADERA_192K_44K1_RATE_MASK; in madera_startup()
2982 dai_priv->constraint.mask = MADERA_192K_48K_RATE_MASK; in madera_startup()
2986 return snd_pcm_hw_constraint_list(substream->runtime, 0, in madera_startup()
2988 &dai_priv->constraint); in madera_startup()
2995 struct snd_soc_component *component = dai->component; in madera_hw_params_rate()
2997 struct madera_dai_priv *dai_priv = &priv->dai[dai->id - 1]; in madera_hw_params_rate()
2998 int base = dai->driver->base; in madera_hw_params_rate()
3010 return -EINVAL; in madera_hw_params_rate()
3014 switch (dai_priv->clk) { in madera_hw_params_rate()
3036 madera_aif_err(dai, "Invalid clock %d\n", dai_priv->clk); in madera_hw_params_rate()
3037 return -EINVAL; in madera_hw_params_rate()
3046 ret = regmap_read(priv->madera->regmap, in madera_hw_params_rate()
3056 mutex_lock(&priv->rate_lock); in madera_hw_params_rate()
3060 ret = -EBUSY; in madera_hw_params_rate()
3071 mutex_unlock(&priv->rate_lock); in madera_hw_params_rate()
3101 struct snd_soc_component *component = dai->component; in madera_hw_params()
3103 struct madera *madera = priv->madera; in madera_hw_params()
3104 int base = dai->driver->base; in madera_hw_params()
3111 madera->pdata.codec.max_channels_clocked[dai->id - 1]; in madera_hw_params()
3112 int tdm_width = priv->tdm_width[dai->id - 1]; in madera_hw_params()
3113 int tdm_slots = priv->tdm_slots[dai->id - 1]; in madera_hw_params()
3162 return -EINVAL; in madera_hw_params()
3178 regmap_read(madera->regmap, base + MADERA_AIF_TX_ENABLES, in madera_hw_params()
3180 regmap_read(madera->regmap, base + MADERA_AIF_RX_ENABLES, in madera_hw_params()
3183 regmap_update_bits(madera->regmap, in madera_hw_params()
3185 regmap_update_bits(madera->regmap, in madera_hw_params()
3194 regmap_update_bits(madera->regmap, in madera_hw_params()
3197 regmap_update_bits(madera->regmap, in madera_hw_params()
3200 regmap_update_bits(madera->regmap, in madera_hw_params()
3204 regmap_update_bits(madera->regmap, in madera_hw_params()
3213 regmap_update_bits(madera->regmap, in madera_hw_params()
3216 regmap_update_bits(madera->regmap, in madera_hw_params()
3235 return -EINVAL; in madera_is_syncclk()
3242 struct snd_soc_component *component = dai->component; in madera_dai_set_sysclk()
3246 struct madera_dai_priv *dai_priv = &priv->dai[dai->id - 1]; in madera_dai_set_sysclk()
3252 dev_err(component->dev, "Illegal DAI clock id %d\n", clk_id); in madera_dai_set_sysclk()
3256 if (is_sync == madera_is_syncclk(dai_priv->clk)) in madera_dai_set_sysclk()
3260 dev_err(component->dev, "Can't change clock on active DAI %d\n", in madera_dai_set_sysclk()
3261 dai->id); in madera_dai_set_sysclk()
3262 return -EBUSY; in madera_dai_set_sysclk()
3265 dev_dbg(component->dev, "Setting AIF%d to %s\n", dai->id, in madera_dai_set_sysclk()
3273 routes[0].sink = dai->driver->capture.stream_name; in madera_dai_set_sysclk()
3274 routes[1].sink = dai->driver->playback.stream_name; in madera_dai_set_sysclk()
3283 dai_priv->clk = clk_id; in madera_dai_set_sysclk()
3290 struct snd_soc_component *component = dai->component; in madera_set_tristate()
3291 int base = dai->driver->base; in madera_set_tristate()
3313 struct snd_soc_component *component = dai->component; in madera_set_channels_to_mask()
3315 struct madera *madera = priv->madera; in madera_set_channels_to_mask()
3319 slot = ffs(mask) - 1; in madera_set_channels_to_mask()
3323 regmap_write(madera->regmap, base + i, slot); in madera_set_channels_to_mask()
3335 struct snd_soc_component *component = dai->component; in madera_set_tdm_slot()
3337 int base = dai->driver->base; in madera_set_tdm_slot()
3338 int rx_max_chan = dai->driver->playback.channels_max; in madera_set_tdm_slot()
3339 int tx_max_chan = dai->driver->capture.channels_max; in madera_set_tdm_slot()
3342 if (dai->id > MADERA_MAX_AIF) in madera_set_tdm_slot()
3343 return -ENOTSUPP; in madera_set_tdm_slot()
3346 tx_mask = (1 << tx_max_chan) - 1; in madera_set_tdm_slot()
3347 rx_mask = (1 << rx_max_chan) - 1; in madera_set_tdm_slot()
3355 priv->tdm_width[dai->id - 1] = slot_width; in madera_set_tdm_slot()
3356 priv->tdm_slots[dai->id - 1] = slots; in madera_set_tdm_slot()
3380 struct madera_dai_priv *dai_priv = &priv->dai[id]; in madera_init_dai()
3382 dai_priv->clk = MADERA_CLK_SYSCLK_1; in madera_init_dai()
3383 dai_priv->constraint = madera_constraint; in madera_init_dai()
3429 { 0, 256000, 0, -1 },
3430 { 256000, 1000000, 2, -1 },
3431 { 1000000, 13500000, 4, -1 },
3457 return -EINVAL; in madera_find_sync_fratio()
3469 *fratio = ratio - 1; in madera_find_main_fratio()
3477 switch (fll->madera->type) { in madera_find_fratio()
3479 switch (fll->madera->rev) { in madera_find_fratio()
3488 fll->fout, in madera_find_fratio()
3500 return madera_find_main_fratio(fref, fll->fout, fratio); in madera_find_fratio()
3513 cfg->refdiv = 0; in madera_calc_fratio()
3517 cfg->refdiv++; in madera_calc_fratio()
3520 return -EINVAL; in madera_calc_fratio()
3524 init_ratio = madera_find_fratio(fll, fref, sync, &cfg->fratio); in madera_calc_fratio()
3532 cfg->fratio = init_ratio - 1; in madera_calc_fratio()
3534 switch (fll->madera->type) { in madera_calc_fratio()
3536 switch (fll->madera->rev) { in madera_calc_fratio()
3558 refdiv = cfg->refdiv; in madera_calc_fratio()
3565 for (ratio = init_ratio; ratio > 0; ratio--) { in madera_calc_fratio()
3566 if (fll->fout % (ratio * fref)) { in madera_calc_fratio()
3567 cfg->refdiv = refdiv; in madera_calc_fratio()
3568 cfg->fratio = ratio - 1; in madera_calc_fratio()
3579 if (fref > pseudo_fref_max[ratio - 1]) in madera_calc_fratio()
3582 if (fll->fout % (ratio * fref)) { in madera_calc_fratio()
3583 cfg->refdiv = refdiv; in madera_calc_fratio()
3584 cfg->fratio = ratio - 1; in madera_calc_fratio()
3597 return cfg->fratio + 1; in madera_calc_fratio()
3610 cfg->gain = gains[i].gain; in madera_find_fll_gain()
3611 cfg->alt_gain = gains[i].alt_gain; in madera_find_fll_gain()
3618 return -EINVAL; in madera_find_fll_gain()
3631 fref, fll->fout, fll->fout * MADERA_FLL_VCO_MULT); in madera_calc_fll()
3639 fref = fref / (1 << cfg->refdiv); in madera_calc_fll()
3641 cfg->n = fll->fout / (ratio * fref); in madera_calc_fll()
3643 if (fll->fout % (ratio * fref)) { in madera_calc_fll()
3644 gcd_fll = gcd(fll->fout, ratio * fref); in madera_calc_fll()
3647 cfg->theta = (fll->fout - (cfg->n * ratio * fref)) in madera_calc_fll()
3649 cfg->lambda = (ratio * fref) / gcd_fll; in madera_calc_fll()
3651 cfg->theta = 0; in madera_calc_fll()
3652 cfg->lambda = 0; in madera_calc_fll()
3660 while (cfg->lambda >= (1 << 16)) { in madera_calc_fll()
3661 cfg->theta >>= 1; in madera_calc_fll()
3662 cfg->lambda >>= 1; in madera_calc_fll()
3665 switch (fll->madera->type) { in madera_calc_fll()
3667 switch (fll->madera->rev) { in madera_calc_fll()
3706 cfg->n, cfg->theta, cfg->lambda); in madera_calc_fll()
3708 cfg->fratio, ratio, cfg->refdiv, 1 << cfg->refdiv); in madera_calc_fll()
3709 madera_fll_dbg(fll, "GAIN=0x%x(%d)\n", cfg->gain, 1 << cfg->gain); in madera_calc_fll()
3721 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3724 cfg->theta, &change); in madera_write_fll()
3726 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3729 cfg->lambda, &change); in madera_write_fll()
3731 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3734 cfg->fratio << MADERA_FLL1_FRATIO_SHIFT, in madera_write_fll()
3737 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3741 cfg->refdiv << MADERA_FLL1_REFCLK_DIV_SHIFT | in madera_write_fll()
3747 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3754 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3762 regmap_update_bits_check(madera->regmap, in madera_write_fll()
3765 MADERA_FLL1_CTRL_UPD | cfg->n, &change); in madera_write_fll()
3773 struct madera *madera = fll->madera; in madera_is_enabled_fll()
3777 ret = regmap_read(madera->regmap, in madera_is_enabled_fll()
3789 struct madera *madera = fll->madera; in madera_wait_for_fll()
3797 regmap_read(madera->regmap, MADERA_IRQ1_RAW_STATUS_2, &val); in madera_wait_for_fll()
3798 status = val & (MADERA_FLL1_LOCK_STS1 << (fll->id - 1)); in madera_wait_for_fll()
3815 madera_fll_warn(fll, "Timed out waiting for lock\n"); in madera_wait_for_fll()
3817 return -ETIMEDOUT; in madera_wait_for_fll()
3827 if (!sync && ref_cfg->theta == 0) in madera_set_fll_phase_integrator()
3833 regmap_update_bits_check(fll->madera->regmap, in madera_set_fll_phase_integrator()
3834 fll->base + MADERA_FLL_EFS_2_OFFS, in madera_set_fll_phase_integrator()
3846 struct madera *madera = fll->madera; in madera_set_fll_clks_reg()
3851 ret = regmap_read(madera->regmap, reg, &src); in madera_set_fll_clks_reg()
3862 clk = madera->mclk[MADERA_MCLK1].clk; in madera_set_fll_clks_reg()
3865 clk = madera->mclk[MADERA_MCLK2].clk; in madera_set_fll_clks_reg()
3868 clk = madera->mclk[MADERA_MCLK3].clk; in madera_set_fll_clks_reg()
3908 struct madera *madera = fll->madera; in madera_disable_fll()
3912 switch (madera->type) { in madera_disable_fll()
3914 sync_base = fll->base + CS47L35_FLL_SYNCHRONISER_OFFS; in madera_disable_fll()
3917 sync_base = fll->base + MADERA_FLL_SYNCHRONISER_OFFS; in madera_disable_fll()
3923 regmap_update_bits(madera->regmap, in madera_disable_fll()
3924 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_disable_fll()
3926 regmap_update_bits_check(madera->regmap, in madera_disable_fll()
3927 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_disable_fll()
3929 regmap_update_bits_check(madera->regmap, in madera_disable_fll()
3932 regmap_update_bits(madera->regmap, in madera_disable_fll()
3933 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_disable_fll()
3942 madera_set_fll_clks(fll, fll->base, false); in madera_disable_fll()
3943 pm_runtime_put_autosuspend(madera->dev); in madera_disable_fll()
3949 struct madera *madera = fll->madera; in madera_enable_fll()
3951 int already_enabled = madera_is_enabled_fll(fll, fll->base); in madera_enable_fll()
3961 if (fll->ref_src < 0 || fll->ref_freq == 0) { in madera_enable_fll()
3963 ret = -EINVAL; in madera_enable_fll()
3970 if (fll->fout < MADERA_FLL_MIN_FOUT || in madera_enable_fll()
3971 fll->fout > MADERA_FLL_MAX_FOUT) { in madera_enable_fll()
3972 madera_fll_err(fll, "invalid fout %uHz\n", fll->fout); in madera_enable_fll()
3973 ret = -EINVAL; in madera_enable_fll()
3977 switch (madera->type) { in madera_enable_fll()
3979 sync_base = fll->base + CS47L35_FLL_SYNCHRONISER_OFFS; in madera_enable_fll()
3982 sync_base = fll->base + MADERA_FLL_SYNCHRONISER_OFFS; in madera_enable_fll()
3992 regmap_update_bits(fll->madera->regmap, in madera_enable_fll()
3993 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_enable_fll()
3997 regmap_update_bits(fll->madera->regmap, in madera_enable_fll()
3998 fll->base + MADERA_FLL_CONTROL_7_OFFS, in madera_enable_fll()
4003 madera_set_fll_clks(fll, fll->base, false); in madera_enable_fll()
4007 if (fll->sync_src >= 0) { in madera_enable_fll()
4008 ret = madera_calc_fll(fll, &cfg, fll->sync_freq, true); in madera_enable_fll()
4013 &cfg, fll->sync_src, in madera_enable_fll()
4022 ret = madera_calc_fll(fll, &cfg, fll->ref_freq, false); in madera_enable_fll()
4030 switch (fll->madera->type) { in madera_enable_fll()
4032 switch (fll->madera->rev) { in madera_enable_fll()
4061 fll_change |= madera_write_fll(madera, fll->base, in madera_enable_fll()
4062 &cfg, fll->ref_src, in madera_enable_fll()
4069 if (have_sync && fll->sync_freq > 100000) in madera_enable_fll()
4070 regmap_update_bits(madera->regmap, in madera_enable_fll()
4074 regmap_update_bits(madera->regmap, in madera_enable_fll()
4080 pm_runtime_get_sync(madera->dev); in madera_enable_fll()
4084 regmap_update_bits(madera->regmap, in madera_enable_fll()
4090 madera_set_fll_clks(fll, fll->base, true); in madera_enable_fll()
4091 regmap_update_bits(madera->regmap, in madera_enable_fll()
4092 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_enable_fll()
4096 regmap_update_bits(madera->regmap, in madera_enable_fll()
4097 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_enable_fll()
4114 if (fll->fout) { in madera_apply_fll()
4131 if (fll->sync_src == source && fll->sync_freq == fref) in madera_set_fll_syncclk()
4134 fll->sync_src = source; in madera_set_fll_syncclk()
4135 fll->sync_freq = fref; in madera_set_fll_syncclk()
4146 if (fll->ref_src == source && in madera_set_fll_refclk()
4147 fll->ref_freq == fref && fll->fout == fout) in madera_set_fll_refclk()
4154 if (fout && fout != fll->fout) { in madera_set_fll_refclk()
4155 ret = madera_is_enabled_fll(fll, fll->base); in madera_set_fll_refclk()
4161 return -EBUSY; in madera_set_fll_refclk()
4165 fll->ref_src = source; in madera_set_fll_refclk()
4166 fll->ref_freq = fref; in madera_set_fll_refclk()
4167 fll->fout = fout; in madera_set_fll_refclk()
4176 fll->id = id; in madera_init_fll()
4177 fll->base = base; in madera_init_fll()
4178 fll->madera = madera; in madera_init_fll()
4179 fll->ref_src = MADERA_FLL_SRC_NONE; in madera_init_fll()
4180 fll->sync_src = MADERA_FLL_SRC_NONE; in madera_init_fll()
4182 regmap_update_bits(madera->regmap, in madera_init_fll()
4183 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_init_fll()
4243 struct madera *madera = fll->madera; in madera_enable_fll_ao()
4244 int already_enabled = madera_is_enabled_fll(fll, fll->base); in madera_enable_fll_ao()
4252 pm_runtime_get_sync(madera->dev); in madera_enable_fll_ao()
4258 regmap_update_bits(fll->madera->regmap, in madera_enable_fll_ao()
4259 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_enable_fll_ao()
4263 madera_set_fllao_clks(fll, fll->base, false); in madera_enable_fll_ao()
4268 /* modify the patch to apply fll->ref_src as input clock */ in madera_enable_fll_ao()
4271 val |= (fll->ref_src << MADERA_FLL_AO_REFCLK_SRC_SHIFT) in madera_enable_fll_ao()
4275 regmap_write(madera->regmap, patch[i].reg, val); in madera_enable_fll_ao()
4278 madera_set_fllao_clks(fll, fll->base, true); in madera_enable_fll_ao()
4280 regmap_update_bits(madera->regmap, in madera_enable_fll_ao()
4281 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_enable_fll_ao()
4285 regmap_update_bits(madera->regmap, in madera_enable_fll_ao()
4286 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_enable_fll_ao()
4297 struct madera *madera = fll->madera; in madera_disable_fll_ao()
4302 regmap_update_bits(madera->regmap, in madera_disable_fll_ao()
4303 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_disable_fll_ao()
4305 regmap_update_bits_check(madera->regmap, in madera_disable_fll_ao()
4306 fll->base + MADERA_FLLAO_CONTROL_1_OFFS, in madera_disable_fll_ao()
4314 * enables the fllao then ctrl_up is the last bit that is configured in madera_disable_fll_ao()
4315 * by the fllao enable code rather than the cache sync operation which in madera_disable_fll_ao()
4316 * would have updated it much earlier before writing out all fllao in madera_disable_fll_ao()
4319 regmap_update_bits(madera->regmap, in madera_disable_fll_ao()
4320 fll->base + MADERA_FLLAO_CONTROL_2_OFFS, in madera_disable_fll_ao()
4324 madera_set_fllao_clks(fll, fll->base, false); in madera_disable_fll_ao()
4325 pm_runtime_put_autosuspend(madera->dev); in madera_disable_fll_ao()
4339 if (fll->ref_src == source && in madera_set_fll_ao_refclk()
4340 fll->ref_freq == fin && fll->fout == fout) in madera_set_fll_ao_refclk()
4346 if (fout && (fll->ref_freq != fin || fll->fout != fout)) { in madera_set_fll_ao_refclk()
4356 return -EINVAL; in madera_set_fll_ao_refclk()
4363 fll->ref_src = source; in madera_set_fll_ao_refclk()
4364 fll->ref_freq = fin; in madera_set_fll_ao_refclk()
4365 fll->fout = fout; in madera_set_fll_ao_refclk()
4378 struct madera *madera = fll->madera; in madera_fllhj_disable()
4384 * lock status bit to clear as normal, but should the FLL be enabled in madera_fllhj_disable()
4385 * again due to a control clock being required, the lock won't re-assert in madera_fllhj_disable()
4389 regmap_update_bits(madera->regmap, in madera_fllhj_disable()
4390 fll->base + MADERA_FLL_CONTROL_11_OFFS, in madera_fllhj_disable()
4392 regmap_update_bits(madera->regmap, in madera_fllhj_disable()
4393 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_disable()
4395 regmap_update_bits_check(madera->regmap, in madera_fllhj_disable()
4396 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_disable()
4408 regmap_update_bits(madera->regmap, in madera_fllhj_disable()
4409 fll->base + MADERA_FLL_CONTROL_2_OFFS, in madera_fllhj_disable()
4413 madera_set_fllhj_clks(fll, fll->base, false); in madera_fllhj_disable()
4414 pm_runtime_put_autosuspend(madera->dev); in madera_fllhj_disable()
4422 struct madera *madera = fll->madera; in madera_fllhj_apply()
4428 madera_fll_dbg(fll, "fin=%d, fout=%d\n", fin, fll->fout); in madera_fllhj_apply()
4440 fout = fll->fout; in madera_fllhj_apply()
4463 fout = fll->fout * 6; in madera_fllhj_apply()
4486 return -EINVAL; in madera_fllhj_apply()
4493 return -EINVAL; in madera_fllhj_apply()
4512 madera_fll_err(fll, "N not in valid %s mode range %d-%d: %d\n", in madera_fllhj_apply()
4515 return -EINVAL; in madera_fllhj_apply()
4520 return -EINVAL; in madera_fllhj_apply()
4524 regmap_write(madera->regmap, in madera_fllhj_apply()
4525 fll->base + MADERA_FLL_CONTROL_2_OFFS, in madera_fllhj_apply()
4527 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4528 fll->base + MADERA_FLL_CONTROL_3_OFFS, in madera_fllhj_apply()
4531 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4532 fll->base + MADERA_FLL_CONTROL_4_OFFS, in madera_fllhj_apply()
4535 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4536 fll->base + MADERA_FLL_CONTROL_5_OFFS, in madera_fllhj_apply()
4539 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4540 fll->base + MADERA_FLL_CONTROL_6_OFFS, in madera_fllhj_apply()
4543 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4544 fll->base + MADERA_FLL_GAIN_OFFS, in madera_fllhj_apply()
4549 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4550 fll->base + MADERA_FLL_CONTROL_10_OFFS, in madera_fllhj_apply()
4553 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4554 fll->base + MADERA_FLL_CONTROL_11_OFFS, in madera_fllhj_apply()
4557 regmap_update_bits(madera->regmap, in madera_fllhj_apply()
4558 fll->base + MADERA_FLL1_DIGITAL_TEST_1_OFFS, in madera_fllhj_apply()
4568 struct madera *madera = fll->madera; in madera_fllhj_enable()
4569 int already_enabled = madera_is_enabled_fll(fll, fll->base); in madera_fllhj_enable()
4576 pm_runtime_get_sync(madera->dev); in madera_fllhj_enable()
4582 regmap_update_bits(fll->madera->regmap, in madera_fllhj_enable()
4583 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4588 madera_set_fllhj_clks(fll, fll->base, false); in madera_fllhj_enable()
4591 ret = madera_fllhj_apply(fll, fll->ref_freq); in madera_fllhj_enable()
4596 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4597 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4599 fll->ref_src << CS47L92_FLL1_REFCLK_SRC_SHIFT); in madera_fllhj_enable()
4601 madera_set_fllhj_clks(fll, fll->base, true); in madera_fllhj_enable()
4603 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4604 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4609 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4610 fll->base + MADERA_FLL_CONTROL_11_OFFS, in madera_fllhj_enable()
4614 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4615 fll->base + MADERA_FLL_CONTROL_2_OFFS, in madera_fllhj_enable()
4620 regmap_update_bits(madera->regmap, in madera_fllhj_enable()
4621 fll->base + MADERA_FLL_CONTROL_1_OFFS, in madera_fllhj_enable()
4637 return -EINVAL; in madera_fllhj_validate()
4640 if (fll->fout && fout != fll->fout) { in madera_fllhj_validate()
4642 return -EINVAL; in madera_fllhj_validate()
4647 return -EINVAL; in madera_fllhj_validate()
4665 if (fll->ref_src == source && fll->ref_freq == fin && in madera_fllhj_set_refclk()
4666 fll->fout == fout) in madera_fllhj_set_refclk()
4670 return -EINVAL; in madera_fllhj_set_refclk()
4672 fll->ref_src = source; in madera_fllhj_set_refclk()
4673 fll->ref_freq = fin; in madera_fllhj_set_refclk()
4674 fll->fout = fout; in madera_fllhj_set_refclk()
4686 * madera_set_output_mode - Set the mode of the specified output
4708 return -EINVAL; in madera_set_output_mode()
4710 reg = MADERA_OUTPUT_PATH_CONFIG_1L + (output - 1) * 8; in madera_set_output_mode()
4737 return (abs((a << 16) / (4096 - b)) >= 4096 << 4); in madera_eq_filter_unstable()
4747 struct madera *madera = priv->madera; in madera_eq_coeff_put()
4748 struct soc_bytes *params = (void *)kcontrol->private_value; in madera_eq_coeff_put()
4754 len = params->num_regs * regmap_get_val_bytes(madera->regmap); in madera_eq_coeff_put()
4756 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA); in madera_eq_coeff_put()
4758 return -ENOMEM; in madera_eq_coeff_put()
4767 dev_err(madera->dev, "Rejecting unstable EQ coefficients\n"); in madera_eq_coeff_put()
4768 ret = -EINVAL; in madera_eq_coeff_put()
4772 ret = regmap_read(madera->regmap, params->base, &val); in madera_eq_coeff_put()
4779 ret = regmap_raw_write(madera->regmap, params->base, data, len); in madera_eq_coeff_put()
4794 struct madera *madera = priv->madera; in madera_lhpf_coeff_put()
4795 __be16 *data = (__be16 *)ucontrol->value.bytes.data; in madera_lhpf_coeff_put()
4799 dev_err(madera->dev, "Rejecting unstable LHPF coefficients\n"); in madera_lhpf_coeff_put()
4800 return -EINVAL; in madera_lhpf_coeff_put()