Lines Matching +full:- +full:chn +full:- +full:disabled
1 // SPDX-License-Identifier: GPL-2.0
8 * Chun-Chia Chiu <chun-chia.chiu@mediatek.com>
15 #include "mt8188-afe-clk.h"
16 #include "mt8188-afe-common.h"
17 #include "mt8188-reg.h"
109 int cowork_slv_id[MT8188_AFE_IO_ETDM_NUM - 1]; //dai_id
139 return -EINVAL; in get_etdm_fs_timing()
160 etdm_reg->con0 = ETDM_IN1_CON0; in get_etdm_reg()
161 etdm_reg->con1 = ETDM_IN1_CON1; in get_etdm_reg()
162 etdm_reg->con2 = ETDM_IN1_CON2; in get_etdm_reg()
163 etdm_reg->con3 = ETDM_IN1_CON3; in get_etdm_reg()
164 etdm_reg->con4 = ETDM_IN1_CON4; in get_etdm_reg()
165 etdm_reg->con5 = ETDM_IN1_CON5; in get_etdm_reg()
168 etdm_reg->con0 = ETDM_IN2_CON0; in get_etdm_reg()
169 etdm_reg->con1 = ETDM_IN2_CON1; in get_etdm_reg()
170 etdm_reg->con2 = ETDM_IN2_CON2; in get_etdm_reg()
171 etdm_reg->con3 = ETDM_IN2_CON3; in get_etdm_reg()
172 etdm_reg->con4 = ETDM_IN2_CON4; in get_etdm_reg()
173 etdm_reg->con5 = ETDM_IN2_CON5; in get_etdm_reg()
176 etdm_reg->con0 = ETDM_OUT1_CON0; in get_etdm_reg()
177 etdm_reg->con1 = ETDM_OUT1_CON1; in get_etdm_reg()
178 etdm_reg->con2 = ETDM_OUT1_CON2; in get_etdm_reg()
179 etdm_reg->con3 = ETDM_OUT1_CON3; in get_etdm_reg()
180 etdm_reg->con4 = ETDM_OUT1_CON4; in get_etdm_reg()
181 etdm_reg->con5 = ETDM_OUT1_CON5; in get_etdm_reg()
184 etdm_reg->con0 = ETDM_OUT2_CON0; in get_etdm_reg()
185 etdm_reg->con1 = ETDM_OUT2_CON1; in get_etdm_reg()
186 etdm_reg->con2 = ETDM_OUT2_CON2; in get_etdm_reg()
187 etdm_reg->con3 = ETDM_OUT2_CON3; in get_etdm_reg()
188 etdm_reg->con4 = ETDM_OUT2_CON4; in get_etdm_reg()
189 etdm_reg->con5 = ETDM_OUT2_CON5; in get_etdm_reg()
193 etdm_reg->con0 = ETDM_OUT3_CON0; in get_etdm_reg()
194 etdm_reg->con1 = ETDM_OUT3_CON1; in get_etdm_reg()
195 etdm_reg->con2 = ETDM_OUT3_CON2; in get_etdm_reg()
196 etdm_reg->con3 = ETDM_OUT3_CON3; in get_etdm_reg()
197 etdm_reg->con4 = ETDM_OUT3_CON4; in get_etdm_reg()
198 etdm_reg->con5 = ETDM_OUT3_CON5; in get_etdm_reg()
201 return -EINVAL; in get_etdm_reg()
217 return -EINVAL; in get_etdm_dir()
249 struct mt8188_afe_private *afe_priv = afe->platform_priv; in is_cowork_mode()
252 if (!is_valid_etdm_dai(dai->id)) in is_cowork_mode()
253 return -EINVAL; in is_cowork_mode()
254 etdm_data = afe_priv->dai_priv[dai->id]; in is_cowork_mode()
256 return (etdm_data->cowork_slv_count > 0 || in is_cowork_mode()
257 etdm_data->cowork_source_id != COWORK_ETDM_NONE); in is_cowork_mode()
281 struct mt8188_afe_private *afe_priv = afe->platform_priv; in get_etdm_cowork_master_id()
285 if (!is_valid_etdm_dai(dai->id)) in get_etdm_cowork_master_id()
286 return -EINVAL; in get_etdm_cowork_master_id()
287 etdm_data = afe_priv->dai_priv[dai->id]; in get_etdm_cowork_master_id()
288 dai_id = etdm_data->cowork_source_id; in get_etdm_cowork_master_id()
291 dai_id = dai->id; in get_etdm_cowork_master_id()
312 return -EINVAL; in mtk_dai_etdm_get_cg_id_by_dai_id()
331 return -EINVAL; in mtk_dai_etdm_get_clk_id_by_dai_id()
350 return -EINVAL; in mtk_dai_etdm_get_clkdiv_id_by_dai_id()
370 return -EINVAL; in get_etdm_id_by_name()
376 struct mt8188_afe_private *afe_priv = afe->platform_priv; in get_etdm_priv_by_name()
383 return afe_priv->dai_priv[dai_id]; in get_etdm_priv_by_name()
388 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_enable_mclk()
400 return -EINVAL; in mtk_dai_etdm_enable_mclk()
401 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_enable_mclk()
403 apll = etdm_data->mclk_apll; in mtk_dai_etdm_enable_mclk()
407 return -EINVAL; in mtk_dai_etdm_enable_mclk()
417 if (etdm_data->mclk_dir == SND_SOC_CLOCK_OUT) in mtk_dai_etdm_enable_mclk()
419 regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val); in mtk_dai_etdm_enable_mclk()
422 mt8188_afe_enable_clk(afe, afe_priv->clk[clkmux_id]); in mtk_dai_etdm_enable_mclk()
425 ret = mt8188_afe_set_clk_parent(afe, afe_priv->clk[clkmux_id], in mtk_dai_etdm_enable_mclk()
426 afe_priv->clk[apll_clk_id]); in mtk_dai_etdm_enable_mclk()
431 ret = mt8188_afe_set_clk_rate(afe, afe_priv->clk[clkdiv_id], in mtk_dai_etdm_enable_mclk()
432 etdm_data->mclk_freq); in mtk_dai_etdm_enable_mclk()
434 mt8188_afe_enable_clk(afe, afe_priv->clk[clkdiv_id]); in mtk_dai_etdm_enable_mclk()
441 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_disable_mclk()
446 return -EINVAL; in mtk_dai_etdm_disable_mclk()
448 mt8188_afe_disable_clk(afe, afe_priv->clk[clkdiv_id]); in mtk_dai_etdm_disable_mclk()
449 mt8188_afe_disable_clk(afe, afe_priv->clk[clkmux_id]); in mtk_dai_etdm_disable_mclk()
458 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_etdm_apll_connect()
464 etdm_priv = get_etdm_priv_by_name(afe, w->name); in mtk_afe_etdm_apll_connect()
466 dev_dbg(afe->dev, "etdm_priv == NULL\n"); in mtk_afe_etdm_apll_connect()
470 cur_apll = mt8188_get_apll_by_name(afe, source->name); in mtk_afe_etdm_apll_connect()
471 need_apll = mt8188_get_apll_by_rate(afe, etdm_priv->rate); in mtk_afe_etdm_apll_connect()
480 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_mclk_apll_connect()
485 etdm_priv = get_etdm_priv_by_name(afe, w->name); in mtk_afe_mclk_apll_connect()
487 cur_apll = mt8188_get_apll_by_name(afe, source->name); in mtk_afe_mclk_apll_connect()
489 return (etdm_priv->mclk_apll == cur_apll) ? 1 : 0; in mtk_afe_mclk_apll_connect()
496 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_etdm_mclk_connect()
498 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_etdm_mclk_connect()
502 mclk_id = get_etdm_id_by_name(afe, source->name); in mtk_etdm_mclk_connect()
504 dev_dbg(afe->dev, "mclk_id < 0\n"); in mtk_etdm_mclk_connect()
508 etdm_priv = get_etdm_priv_by_name(afe, w->name); in mtk_etdm_mclk_connect()
510 dev_dbg(afe->dev, "etdm_priv == NULL\n"); in mtk_etdm_mclk_connect()
514 if (get_etdm_id_by_name(afe, sink->name) == mclk_id) in mtk_etdm_mclk_connect()
515 return !!(etdm_priv->mclk_freq > 0); in mtk_etdm_mclk_connect()
517 if (etdm_priv->cowork_source_id == mclk_id) { in mtk_etdm_mclk_connect()
518 etdm_priv = afe_priv->dai_priv[mclk_id]; in mtk_etdm_mclk_connect()
519 return !!(etdm_priv->mclk_freq > 0); in mtk_etdm_mclk_connect()
529 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_etdm_cowork_connect()
531 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_etdm_cowork_connect()
536 source_id = get_etdm_id_by_name(afe, source->name); in mtk_etdm_cowork_connect()
538 dev_dbg(afe->dev, "%s() source_id < 0\n", __func__); in mtk_etdm_cowork_connect()
542 etdm_priv = get_etdm_priv_by_name(afe, w->name); in mtk_etdm_cowork_connect()
544 dev_dbg(afe->dev, "%s() etdm_priv == NULL\n", __func__); in mtk_etdm_cowork_connect()
548 if (etdm_priv->cowork_source_id != COWORK_ETDM_NONE) { in mtk_etdm_cowork_connect()
549 if (etdm_priv->cowork_source_id == source_id) in mtk_etdm_cowork_connect()
552 etdm_priv = afe_priv->dai_priv[etdm_priv->cowork_source_id]; in mtk_etdm_cowork_connect()
553 for (i = 0; i < etdm_priv->cowork_slv_count; i++) { in mtk_etdm_cowork_connect()
554 if (etdm_priv->cowork_slv_id[i] == source_id) in mtk_etdm_cowork_connect()
558 for (i = 0; i < etdm_priv->cowork_slv_count; i++) { in mtk_etdm_cowork_connect()
559 if (etdm_priv->cowork_slv_id[i] == source_id) in mtk_etdm_cowork_connect()
571 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_apll_event()
574 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_apll_event()
575 __func__, w->name, event); in mtk_apll_event()
601 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_etdm_mclk_event()
603 int mclk_id = get_etdm_id_by_name(afe, w->name); in mtk_etdm_mclk_event()
606 dev_dbg(afe->dev, "%s() mclk_id < 0\n", __func__); in mtk_etdm_mclk_event()
610 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_etdm_mclk_event()
611 __func__, w->name, event); in mtk_etdm_mclk_event()
631 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_dptx_mclk_event()
634 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_dptx_mclk_event()
635 __func__, w->name, event); in mtk_dptx_mclk_event()
655 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_etdm_cg_event()
657 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_etdm_cg_event()
661 etdm_id = get_etdm_id_by_name(afe, w->name); in mtk_etdm_cg_event()
663 dev_dbg(afe->dev, "%s() etdm_id < 0\n", __func__); in mtk_etdm_cg_event()
669 dev_dbg(afe->dev, "%s() cg_id < 0\n", __func__); in mtk_etdm_cg_event()
673 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_etdm_cg_event()
674 __func__, w->name, event); in mtk_etdm_cg_event()
678 mt8188_afe_enable_clk(afe, afe_priv->clk[cg_id]); in mtk_etdm_cg_event()
681 mt8188_afe_disable_clk(afe, afe_priv->clk[cg_id]); in mtk_etdm_cg_event()
694 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_etdm3_cg_event()
696 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_etdm3_cg_event()
698 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_etdm3_cg_event()
699 __func__, w->name, event); in mtk_etdm3_cg_event()
703 mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_HDMI_OUT]); in mtk_etdm3_cg_event()
706 mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_HDMI_OUT]); in mtk_etdm3_cg_event()
1016 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in mt8188_etdm_clk_src_sel_put()
1018 unsigned int source = ucontrol->value.enumerated.item[0]; in mt8188_etdm_clk_src_sel_put()
1024 if (source >= e->items) in mt8188_etdm_clk_src_sel_put()
1025 return -EINVAL; in mt8188_etdm_clk_src_sel_put()
1027 if (!strcmp(kcontrol->id.name, "ETDM_OUT1_Clock_Source")) { in mt8188_etdm_clk_src_sel_put()
1031 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT2_Clock_Source")) { in mt8188_etdm_clk_src_sel_put()
1035 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT3_Clock_Source")) { in mt8188_etdm_clk_src_sel_put()
1039 } else if (!strcmp(kcontrol->id.name, "ETDM_IN1_Clock_Source")) { in mt8188_etdm_clk_src_sel_put()
1043 } else if (!strcmp(kcontrol->id.name, "ETDM_IN2_Clock_Source")) { in mt8188_etdm_clk_src_sel_put()
1048 return -EINVAL; in mt8188_etdm_clk_src_sel_put()
1051 regmap_read(afe->regmap, reg, &old_val); in mt8188_etdm_clk_src_sel_put()
1056 regmap_update_bits(afe->regmap, reg, mask, val); in mt8188_etdm_clk_src_sel_put()
1072 if (!strcmp(kcontrol->id.name, "ETDM_OUT1_Clock_Source")) { in mt8188_etdm_clk_src_sel_get()
1076 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT2_Clock_Source")) { in mt8188_etdm_clk_src_sel_get()
1080 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT3_Clock_Source")) { in mt8188_etdm_clk_src_sel_get()
1084 } else if (!strcmp(kcontrol->id.name, "ETDM_IN1_Clock_Source")) { in mt8188_etdm_clk_src_sel_get()
1088 } else if (!strcmp(kcontrol->id.name, "ETDM_IN2_Clock_Source")) { in mt8188_etdm_clk_src_sel_get()
1093 return -EINVAL; in mt8188_etdm_clk_src_sel_get()
1096 regmap_read(afe->regmap, reg, &value); in mt8188_etdm_clk_src_sel_get()
1100 ucontrol->value.enumerated.item[0] = value; in mt8188_etdm_clk_src_sel_get()
1692 return -EINVAL; in etdm_cowork_slv_sel()
1707 return -EINVAL; in etdm_cowork_slv_sel()
1726 return -EINVAL; in etdm_cowork_sync_sel()
1732 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_etdm_sync_mode_slv()
1740 return -EINVAL; in mt8188_etdm_sync_mode_slv()
1741 etdm_data = afe_priv->dai_priv[dai_id]; in mt8188_etdm_sync_mode_slv()
1743 cowork_source_sel = etdm_cowork_slv_sel(etdm_data->cowork_source_id, in mt8188_etdm_sync_mode_slv()
1778 regmap_update_bits(afe->regmap, reg, mask, val); in mt8188_etdm_sync_mode_slv()
1785 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_etdm_sync_mode_mst()
1795 return -EINVAL; in mt8188_etdm_sync_mode_mst()
1796 etdm_data = afe_priv->dai_priv[dai_id]; in mt8188_etdm_sync_mode_mst()
1798 cowork_source_sel = etdm_cowork_sync_sel(etdm_data->cowork_source_id); in mt8188_etdm_sync_mode_mst()
1836 regmap_update_bits(afe->regmap, reg, mask, val); in mt8188_etdm_sync_mode_mst()
1838 regmap_set_bits(afe->regmap, etdm_reg.con0, ETDM_CON0_SYNC_MODE); in mt8188_etdm_sync_mode_mst()
1845 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_etdm_sync_mode_configure()
1849 return -EINVAL; in mt8188_etdm_sync_mode_configure()
1850 etdm_data = afe_priv->dai_priv[dai_id]; in mt8188_etdm_sync_mode_configure()
1852 if (etdm_data->cowork_source_id == COWORK_ETDM_NONE) in mt8188_etdm_sync_mode_configure()
1855 if (etdm_data->slave_mode) in mt8188_etdm_sync_mode_configure()
1887 return -EINVAL; in mtk_dai_etdm_fifo_mode()
1892 regmap_update_bits(afe->regmap, reg, mask, val); in mtk_dai_etdm_fifo_mode()
1901 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_in_configure()
1913 return -EINVAL; in mtk_dai_etdm_in_configure()
1914 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_in_configure()
1915 slave_mode = etdm_data->slave_mode; in mtk_dai_etdm_in_configure()
1916 data_mode = etdm_data->data_mode; in mtk_dai_etdm_in_configure()
1917 lrck_width = etdm_data->lrck_width; in mtk_dai_etdm_in_configure()
1919 dev_dbg(afe->dev, "%s rate %u channels %u, id %d\n", in mtk_dai_etdm_in_configure()
1936 val |= FIELD_PREP(ETDM_IN_CON1_LRCK_WIDTH_MASK, lrck_width - 1); in mtk_dai_etdm_in_configure()
1938 regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val); in mtk_dai_etdm_in_configure()
1955 FIELD_PREP(ETDM_IN_CON2_MULTI_IP_TOTAL_CH_MASK, channels - 1); in mtk_dai_etdm_in_configure()
1957 regmap_update_bits(afe->regmap, etdm_reg.con2, mask, val); in mtk_dai_etdm_in_configure()
1965 if (etdm_data->in_disable_ch[i] && in mtk_dai_etdm_in_configure()
1966 etdm_data->in_disable_ch[i + 1]) in mtk_dai_etdm_in_configure()
1973 regmap_update_bits(afe->regmap, etdm_reg.con3, mask, val); in mtk_dai_etdm_in_configure()
1982 if (etdm_data->lrck_inv) in mtk_dai_etdm_in_configure()
1984 if (etdm_data->bck_inv) in mtk_dai_etdm_in_configure()
1987 if (etdm_data->lrck_inv) in mtk_dai_etdm_in_configure()
1989 if (etdm_data->bck_inv) in mtk_dai_etdm_in_configure()
1992 regmap_update_bits(afe->regmap, etdm_reg.con4, mask, val); in mtk_dai_etdm_in_configure()
2001 if (etdm_data->in_disable_ch[i] && in mtk_dai_etdm_in_configure()
2002 !etdm_data->in_disable_ch[i + 1]) { in mtk_dai_etdm_in_configure()
2005 } else if (!etdm_data->in_disable_ch[i] && in mtk_dai_etdm_in_configure()
2006 etdm_data->in_disable_ch[i + 1]) { in mtk_dai_etdm_in_configure()
2010 regmap_update_bits(afe->regmap, etdm_reg.con5, mask, val); in mtk_dai_etdm_in_configure()
2019 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_out_configure()
2030 return -EINVAL; in mtk_dai_etdm_out_configure()
2031 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_out_configure()
2032 slave_mode = etdm_data->slave_mode; in mtk_dai_etdm_out_configure()
2033 lrck_width = etdm_data->lrck_width; in mtk_dai_etdm_out_configure()
2035 dev_dbg(afe->dev, "%s rate %u channels %u, id %d\n", in mtk_dai_etdm_out_configure()
2046 regmap_update_bits(afe->regmap, etdm_reg.con0, mask, val); in mtk_dai_etdm_out_configure()
2055 val |= FIELD_PREP(ETDM_OUT_CON1_LRCK_WIDTH_MASK, lrck_width - 1); in mtk_dai_etdm_out_configure()
2057 regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val); in mtk_dai_etdm_out_configure()
2076 regmap_update_bits(afe->regmap, etdm_reg.con4, mask, val); in mtk_dai_etdm_out_configure()
2085 if (etdm_data->lrck_inv) in mtk_dai_etdm_out_configure()
2087 if (etdm_data->bck_inv) in mtk_dai_etdm_out_configure()
2090 if (etdm_data->lrck_inv) in mtk_dai_etdm_out_configure()
2092 if (etdm_data->bck_inv) in mtk_dai_etdm_out_configure()
2095 regmap_update_bits(afe->regmap, etdm_reg.con5, mask, val); in mtk_dai_etdm_out_configure()
2106 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_configure()
2118 return -EINVAL; in mtk_dai_etdm_configure()
2119 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_configure()
2120 slave_mode = etdm_data->slave_mode; in mtk_dai_etdm_configure()
2121 etdm_data->rate = rate; in mtk_dai_etdm_configure()
2127 dev_dbg(afe->dev, "%s fmt %u data %u lrck %d-%u bck %d, slv %u\n", in mtk_dai_etdm_configure()
2128 __func__, etdm_data->format, etdm_data->data_mode, in mtk_dai_etdm_configure()
2129 etdm_data->lrck_inv, etdm_data->lrck_width, etdm_data->bck_inv, in mtk_dai_etdm_configure()
2130 etdm_data->slave_mode); in mtk_dai_etdm_configure()
2131 dev_dbg(afe->dev, "%s rate %u channels %u bitwidth %u, id %d\n", in mtk_dai_etdm_configure()
2134 etdm_channels = (etdm_data->data_mode == MTK_DAI_ETDM_DATA_ONE_PIN) ? in mtk_dai_etdm_configure()
2139 dev_err(afe->dev, "%s bck rate %u not support\n", in mtk_dai_etdm_configure()
2141 return -EINVAL; in mtk_dai_etdm_configure()
2146 val |= FIELD_PREP(ETDM_CON0_BIT_LEN_MASK, bit_width - 1); in mtk_dai_etdm_configure()
2148 val |= FIELD_PREP(ETDM_CON0_WORD_LEN_MASK, wlen - 1); in mtk_dai_etdm_configure()
2150 val |= FIELD_PREP(ETDM_CON0_FORMAT_MASK, etdm_data->format); in mtk_dai_etdm_configure()
2152 val |= FIELD_PREP(ETDM_CON0_CH_NUM_MASK, etdm_channels - 1); in mtk_dai_etdm_configure()
2157 dev_err(afe->dev, "%s id %d only support master mode\n", in mtk_dai_etdm_configure()
2159 return -EINVAL; in mtk_dai_etdm_configure()
2163 regmap_update_bits(afe->regmap, etdm_reg.con0, mask, val); in mtk_dai_etdm_configure()
2181 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_hw_params()
2188 dev_dbg(afe->dev, "%s '%s' period %u-%u\n", in mtk_dai_etdm_hw_params()
2195 return -EINVAL; in mtk_dai_etdm_hw_params()
2197 mst_etdm_data = afe_priv->dai_priv[mst_dai_id]; in mtk_dai_etdm_hw_params()
2198 if (mst_etdm_data->slots) in mtk_dai_etdm_hw_params()
2199 channels = mst_etdm_data->slots; in mtk_dai_etdm_hw_params()
2206 for (i = 0; i < mst_etdm_data->cowork_slv_count; i++) { in mtk_dai_etdm_hw_params()
2207 slv_dai_id = mst_etdm_data->cowork_slv_id[i]; in mtk_dai_etdm_hw_params()
2218 if (!is_valid_etdm_dai(dai->id)) in mtk_dai_etdm_hw_params()
2219 return -EINVAL; in mtk_dai_etdm_hw_params()
2220 mst_etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_etdm_hw_params()
2221 if (mst_etdm_data->slots) in mtk_dai_etdm_hw_params()
2222 channels = mst_etdm_data->slots; in mtk_dai_etdm_hw_params()
2225 bit_width, dai->id); in mtk_dai_etdm_hw_params()
2235 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_cal_mclk()
2241 return -EINVAL; in mtk_dai_etdm_cal_mclk()
2242 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_cal_mclk()
2245 etdm_data->mclk_freq = freq; in mtk_dai_etdm_cal_mclk()
2249 if (etdm_data->mclk_fixed_apll == 0) in mtk_dai_etdm_cal_mclk()
2252 apll = etdm_data->mclk_apll; in mtk_dai_etdm_cal_mclk()
2257 dev_err(afe->dev, "freq %d > apll rate %d\n", freq, apll_rate); in mtk_dai_etdm_cal_mclk()
2258 return -EINVAL; in mtk_dai_etdm_cal_mclk()
2262 dev_err(afe->dev, "APLL%d cannot generate freq Hz\n", apll); in mtk_dai_etdm_cal_mclk()
2263 return -EINVAL; in mtk_dai_etdm_cal_mclk()
2266 if (etdm_data->mclk_fixed_apll == 0) in mtk_dai_etdm_cal_mclk()
2267 etdm_data->mclk_apll = apll; in mtk_dai_etdm_cal_mclk()
2268 etdm_data->mclk_freq = freq; in mtk_dai_etdm_cal_mclk()
2277 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_set_sysclk()
2281 dev_dbg(dai->dev, "%s id %d freq %u, dir %d\n", in mtk_dai_etdm_set_sysclk()
2282 __func__, dai->id, freq, dir); in mtk_dai_etdm_set_sysclk()
2286 dai_id = dai->id; in mtk_dai_etdm_set_sysclk()
2289 return -EINVAL; in mtk_dai_etdm_set_sysclk()
2290 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_set_sysclk()
2291 etdm_data->mclk_dir = dir; in mtk_dai_etdm_set_sysclk()
2300 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_set_tdm_slot()
2307 dai_id = dai->id; in mtk_dai_etdm_set_tdm_slot()
2310 return -EINVAL; in mtk_dai_etdm_set_tdm_slot()
2311 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_set_tdm_slot()
2313 dev_dbg(dai->dev, "%s id %d slot_width %d\n", in mtk_dai_etdm_set_tdm_slot()
2314 __func__, dai->id, slot_width); in mtk_dai_etdm_set_tdm_slot()
2316 etdm_data->slots = slots; in mtk_dai_etdm_set_tdm_slot()
2317 etdm_data->lrck_width = slot_width; in mtk_dai_etdm_set_tdm_slot()
2324 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_set_fmt()
2327 if (!is_valid_etdm_dai(dai->id)) in mtk_dai_etdm_set_fmt()
2328 return -EINVAL; in mtk_dai_etdm_set_fmt()
2329 etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_etdm_set_fmt()
2333 etdm_data->format = MTK_DAI_ETDM_FORMAT_I2S; in mtk_dai_etdm_set_fmt()
2336 etdm_data->format = MTK_DAI_ETDM_FORMAT_LJ; in mtk_dai_etdm_set_fmt()
2339 etdm_data->format = MTK_DAI_ETDM_FORMAT_RJ; in mtk_dai_etdm_set_fmt()
2342 etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPA; in mtk_dai_etdm_set_fmt()
2345 etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPB; in mtk_dai_etdm_set_fmt()
2348 return -EINVAL; in mtk_dai_etdm_set_fmt()
2353 etdm_data->bck_inv = false; in mtk_dai_etdm_set_fmt()
2354 etdm_data->lrck_inv = false; in mtk_dai_etdm_set_fmt()
2357 etdm_data->bck_inv = false; in mtk_dai_etdm_set_fmt()
2358 etdm_data->lrck_inv = true; in mtk_dai_etdm_set_fmt()
2361 etdm_data->bck_inv = true; in mtk_dai_etdm_set_fmt()
2362 etdm_data->lrck_inv = false; in mtk_dai_etdm_set_fmt()
2365 etdm_data->bck_inv = true; in mtk_dai_etdm_set_fmt()
2366 etdm_data->lrck_inv = true; in mtk_dai_etdm_set_fmt()
2369 return -EINVAL; in mtk_dai_etdm_set_fmt()
2374 etdm_data->slave_mode = true; in mtk_dai_etdm_set_fmt()
2377 etdm_data->slave_mode = false; in mtk_dai_etdm_set_fmt()
2380 return -EINVAL; in mtk_dai_etdm_set_fmt()
2419 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_hdmitx_dptx_hw_params()
2427 if (!is_valid_etdm_dai(dai->id)) in mtk_dai_hdmitx_dptx_hw_params()
2428 return -EINVAL; in mtk_dai_hdmitx_dptx_hw_params()
2429 etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_hdmitx_dptx_hw_params()
2432 if (dai->id == MT8188_AFE_IO_DPTX) { in mtk_dai_hdmitx_dptx_hw_params()
2433 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_hw_params()
2436 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_hw_params()
2439 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_hw_params()
2444 etdm_data->data_mode = MTK_DAI_ETDM_DATA_ONE_PIN; in mtk_dai_hdmitx_dptx_hw_params()
2450 etdm_data->data_mode = MTK_DAI_ETDM_DATA_MULTI_PIN; in mtk_dai_hdmitx_dptx_hw_params()
2453 ret = mtk_dai_etdm_configure(afe, rate, channels, width, dai->id); in mtk_dai_hdmitx_dptx_hw_params()
2464 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mtk_dai_hdmitx_dptx_set_sysclk()
2467 if (!is_valid_etdm_dai(dai->id)) in mtk_dai_hdmitx_dptx_set_sysclk()
2468 return -EINVAL; in mtk_dai_hdmitx_dptx_set_sysclk()
2469 etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_hdmitx_dptx_set_sysclk()
2471 dev_dbg(dai->dev, "%s id %d freq %u, dir %d\n", in mtk_dai_hdmitx_dptx_set_sysclk()
2472 __func__, dai->id, freq, dir); in mtk_dai_hdmitx_dptx_set_sysclk()
2474 etdm_data->mclk_dir = dir; in mtk_dai_hdmitx_dptx_set_sysclk()
2475 return mtk_dai_etdm_cal_mclk(afe, freq, dai->id); in mtk_dai_hdmitx_dptx_set_sysclk()
2575 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_etdm_update_sync_info()
2582 etdm_data = afe_priv->dai_priv[i]; in mt8188_etdm_update_sync_info()
2583 if (etdm_data->cowork_source_id != COWORK_ETDM_NONE) { in mt8188_etdm_update_sync_info()
2584 mst_dai_id = etdm_data->cowork_source_id; in mt8188_etdm_update_sync_info()
2585 mst_data = afe_priv->dai_priv[mst_dai_id]; in mt8188_etdm_update_sync_info()
2586 if (mst_data->cowork_source_id != COWORK_ETDM_NONE) in mt8188_etdm_update_sync_info()
2587 dev_err(afe->dev, "%s [%d] wrong sync source\n", in mt8188_etdm_update_sync_info()
2589 mst_data->cowork_slv_id[mst_data->cowork_slv_count] = i; in mt8188_etdm_update_sync_info()
2590 mst_data->cowork_slv_count++; in mt8188_etdm_update_sync_info()
2597 const struct device_node *of_node = afe->dev->of_node; in mt8188_dai_etdm_parse_of()
2598 struct mt8188_afe_private *afe_priv = afe->platform_priv; in mt8188_dai_etdm_parse_of()
2612 {"etdm-in1", ETDM_SYNC_FROM_IN1}, in mt8188_dai_etdm_parse_of()
2613 {"etdm-in2", ETDM_SYNC_FROM_IN2}, in mt8188_dai_etdm_parse_of()
2614 {"etdm-out1", ETDM_SYNC_FROM_OUT1}, in mt8188_dai_etdm_parse_of()
2615 {"etdm-out2", ETDM_SYNC_FROM_OUT2}, in mt8188_dai_etdm_parse_of()
2616 {"etdm-out3", ETDM_SYNC_FROM_OUT3}, in mt8188_dai_etdm_parse_of()
2621 etdm_data = afe_priv->dai_priv[dai_id]; in mt8188_dai_etdm_parse_of()
2623 snprintf(prop, sizeof(prop), "mediatek,%s-multi-pin-mode", in mt8188_dai_etdm_parse_of()
2626 etdm_data->data_mode = of_property_read_bool(of_node, prop); in mt8188_dai_etdm_parse_of()
2628 snprintf(prop, sizeof(prop), "mediatek,%s-cowork-source", in mt8188_dai_etdm_parse_of()
2634 dev_err(afe->dev, "%s invalid id=%d\n", in mt8188_dai_etdm_parse_of()
2636 etdm_data->cowork_source_id = COWORK_ETDM_NONE; in mt8188_dai_etdm_parse_of()
2639 etdm_data->cowork_source_id = in mt8188_dai_etdm_parse_of()
2643 etdm_data->cowork_source_id = COWORK_ETDM_NONE; in mt8188_dai_etdm_parse_of()
2650 etdm_data = afe_priv->dai_priv[dai_id]; in mt8188_dai_etdm_parse_of()
2652 snprintf(prop, sizeof(prop), "mediatek,%s-chn-disabled", in mt8188_dai_etdm_parse_of()
2663 dev_err(afe->dev, "%s [%d] invalid chn %u\n", in mt8188_dai_etdm_parse_of()
2666 etdm_data->in_disable_ch[disable_chn[j]] = true; in mt8188_dai_etdm_parse_of()
2674 struct mt8188_afe_private *afe_priv = afe->platform_priv; in init_etdm_priv_data()
2679 etdm_priv = devm_kzalloc(afe->dev, in init_etdm_priv_data()
2683 return -ENOMEM; in init_etdm_priv_data()
2685 afe_priv->dai_priv[i] = etdm_priv; in init_etdm_priv_data()
2688 afe_priv->dai_priv[MT8188_AFE_IO_DPTX] = in init_etdm_priv_data()
2689 afe_priv->dai_priv[MT8188_AFE_IO_ETDM3_OUT]; in init_etdm_priv_data()
2699 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8188_dai_etdm_register()
2701 return -ENOMEM; in mt8188_dai_etdm_register()
2703 list_add(&dai->list, &afe->sub_dais); in mt8188_dai_etdm_register()
2705 dai->dai_drivers = mtk_dai_etdm_driver; in mt8188_dai_etdm_register()
2706 dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_etdm_driver); in mt8188_dai_etdm_register()
2708 dai->dapm_widgets = mtk_dai_etdm_widgets; in mt8188_dai_etdm_register()
2709 dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_etdm_widgets); in mt8188_dai_etdm_register()
2710 dai->dapm_routes = mtk_dai_etdm_routes; in mt8188_dai_etdm_register()
2711 dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_etdm_routes); in mt8188_dai_etdm_register()
2712 dai->controls = mtk_dai_etdm_controls; in mt8188_dai_etdm_register()
2713 dai->num_controls = ARRAY_SIZE(mtk_dai_etdm_controls); in mt8188_dai_etdm_register()