Lines Matching +full:tdm +full:- +full:sync +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
3 // MediaTek ALSA SoC Audio DAI TDM Control
11 #include "mt8186-afe-clk.h"
12 #include "mt8186-afe-common.h"
13 #include "mt8186-afe-gpio.h"
14 #include "mt8186-interconnection.h"
60 unsigned int mode) in get_tdm_lrck_width() argument
62 if (mode == TDM_IN_DSP_A || mode == TDM_IN_DSP_B) in get_tdm_lrck_width()
65 return snd_pcm_format_physical_width(format) - 1; in get_tdm_lrck_width()
78 static unsigned int get_tdm_ch_per_sdata(unsigned int mode, in get_tdm_ch_per_sdata() argument
81 if (mode == TDM_IN_DSP_A || mode == TDM_IN_DSP_B) in get_tdm_ch_per_sdata()
103 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_tdm_en_event()
105 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_tdm_en_event()
106 int dai_id = get_tdm_id_by_name(w->name); in mtk_tdm_en_event()
107 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mtk_tdm_en_event()
109 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n", in mtk_tdm_en_event()
110 __func__, w->name, event); in mtk_tdm_en_event()
114 mt8186_afe_gpio_request(afe->dev, true, tdm_priv->id, 0); in mtk_tdm_en_event()
117 mt8186_afe_gpio_request(afe->dev, false, tdm_priv->id, 0); in mtk_tdm_en_event()
130 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_tdm_mck_en_event()
132 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_tdm_mck_en_event()
133 int dai_id = get_tdm_id_by_name(w->name); in mtk_tdm_mck_en_event()
134 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mtk_tdm_mck_en_event()
136 dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x, dai_id %d\n", in mtk_tdm_mck_en_event()
137 __func__, w->name, event, dai_id); in mtk_tdm_mck_en_event()
141 mt8186_mck_enable(afe, tdm_priv->mclk_id, tdm_priv->mclk_rate); in mtk_tdm_mck_en_event()
144 tdm_priv->mclk_rate = 0; in mtk_tdm_mck_en_event()
145 mt8186_mck_disable(afe, tdm_priv->mclk_id); in mtk_tdm_mck_en_event()
155 /* tdm virtual mux to output widget */
172 SOC_DAPM_ENUM("TDM In Select", tdm_mux_map_enum);
181 /* tdm hd en */
202 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_tdm_mclk_connect()
204 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_afe_tdm_mclk_connect()
205 int dai_id = get_tdm_id_by_name(w->name); in mtk_afe_tdm_mclk_connect()
206 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mtk_afe_tdm_mclk_connect()
208 return (tdm_priv->mclk_rate > 0) ? 1 : 0; in mtk_afe_tdm_mclk_connect()
215 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_tdm_mclk_apll_connect()
217 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_afe_tdm_mclk_apll_connect()
218 int dai_id = get_tdm_id_by_name(w->name); in mtk_afe_tdm_mclk_apll_connect()
219 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mtk_afe_tdm_mclk_apll_connect()
223 cur_apll = mt8186_get_apll_by_name(afe, source->name); in mtk_afe_tdm_mclk_apll_connect()
225 return (tdm_priv->mclk_apll == cur_apll) ? 1 : 0; in mtk_afe_tdm_mclk_apll_connect()
232 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_tdm_hd_connect()
234 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_afe_tdm_hd_connect()
235 int dai_id = get_tdm_id_by_name(w->name); in mtk_afe_tdm_hd_connect()
236 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mtk_afe_tdm_hd_connect()
238 return tdm_priv->low_jitter_en; in mtk_afe_tdm_hd_connect()
245 struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); in mtk_afe_tdm_apll_connect()
247 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_afe_tdm_apll_connect()
248 int dai_id = get_tdm_id_by_name(w->name); in mtk_afe_tdm_apll_connect()
249 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mtk_afe_tdm_apll_connect()
254 cur_apll = mt8186_get_apll_by_name(afe, source->name); in mtk_afe_tdm_apll_connect()
256 /* choose APLL from tdm rate */ in mtk_afe_tdm_apll_connect()
257 tdm_need_apll = mt8186_get_apll_by_rate(afe, tdm_priv->rate); in mtk_afe_tdm_apll_connect()
277 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mt8186_tdm_hd_get()
278 int dai_id = get_tdm_id_by_name(kcontrol->id.name); in mt8186_tdm_hd_get()
279 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mt8186_tdm_hd_get()
281 ucontrol->value.integer.value[0] = tdm_priv->low_jitter_en; in mt8186_tdm_hd_get()
291 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mt8186_tdm_hd_set()
292 int dai_id = get_tdm_id_by_name(kcontrol->id.name); in mt8186_tdm_hd_set()
293 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id]; in mt8186_tdm_hd_set()
294 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in mt8186_tdm_hd_set()
297 if (ucontrol->value.enumerated.item[0] >= e->items) in mt8186_tdm_hd_set()
298 return -EINVAL; in mt8186_tdm_hd_set()
300 hd_en = ucontrol->value.integer.value[0]; in mt8186_tdm_hd_set()
302 dev_dbg(afe->dev, "%s(), kcontrol name %s, hd_en %d\n", in mt8186_tdm_hd_set()
303 __func__, kcontrol->id.name, hd_en); in mt8186_tdm_hd_set()
305 if (tdm_priv->low_jitter_en == hd_en) in mt8186_tdm_hd_set()
308 tdm_priv->low_jitter_en = hd_en; in mt8186_tdm_hd_set()
319 {"TDM IN", NULL, "aud_tdm_clk"},
320 {"TDM IN", NULL, "TDM_EN"},
321 {"TDM IN", NULL, TDM_HD_EN_W_NAME, mtk_afe_tdm_hd_connect},
325 {"TDM IN", NULL, TDM_MCLK_EN_W_NAME, mtk_afe_tdm_mclk_connect},
329 /* allow tdm on without codec on */
330 {"TDM IN", NULL, "TDM_In_Mux"},
346 dev_err(afe->dev, in mtk_dai_tdm_cal_mclk()
348 return -EINVAL; in mtk_dai_tdm_cal_mclk()
352 dev_err(afe->dev, in mtk_dai_tdm_cal_mclk()
354 return -EINVAL; in mtk_dai_tdm_cal_mclk()
357 tdm_priv->mclk_rate = freq; in mtk_dai_tdm_cal_mclk()
358 tdm_priv->mclk_apll = apll; in mtk_dai_tdm_cal_mclk()
368 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_dai_tdm_hw_params()
369 int tdm_id = dai->id; in mtk_dai_tdm_hw_params()
370 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[tdm_id]; in mtk_dai_tdm_hw_params()
371 unsigned int tdm_mode = tdm_priv->tdm_mode; in mtk_dai_tdm_hw_params()
372 unsigned int data_mode = tdm_priv->data_mode; in mtk_dai_tdm_hw_params()
383 bool slave_mode = tdm_priv->slave_mode; in mtk_dai_tdm_hw_params()
384 bool lrck_inv = tdm_priv->lck_invert; in mtk_dai_tdm_hw_params()
385 bool bck_inv = tdm_priv->bck_invert; in mtk_dai_tdm_hw_params()
389 tdm_priv->rate = rate; in mtk_dai_tdm_hw_params()
390 tran_rate = mt8186_rate_transform(afe->dev, rate, dai->id); in mtk_dai_tdm_hw_params()
391 tran_relatch_rate = mt8186_tdm_relatch_rate_transform(afe->dev, rate); in mtk_dai_tdm_hw_params()
394 if (!tdm_priv->mclk_rate) { in mtk_dai_tdm_hw_params()
395 tdm_priv->mclk_rate = rate * tdm_priv->mclk_multiple; in mtk_dai_tdm_hw_params()
396 mtk_dai_tdm_cal_mclk(afe, tdm_priv, tdm_priv->mclk_rate); in mtk_dai_tdm_hw_params()
402 tdm_con |= (bit_width - 1) << ETDM_IN1_CON0_REG_BIT_LENGTH_SFT; in mtk_dai_tdm_hw_params()
403 tdm_con |= (bit_width - 1) << ETDM_IN1_CON0_REG_WORD_LENGTH_SFT; in mtk_dai_tdm_hw_params()
404 tdm_con |= (tdm_channels - 1) << ETDM_IN1_CON0_REG_CH_NUM_SFT; in mtk_dai_tdm_hw_params()
405 /* need to disable sync mode otherwise this may cause latch data error */ in mtk_dai_tdm_hw_params()
409 regmap_update_bits(afe->regmap, ETDM_IN1_CON0, ETDM_IN_CON0_CTRL_MASK, tdm_con); in mtk_dai_tdm_hw_params()
415 tdm_con |= (lrck_width - 1) << ETDM_IN1_CON1_REG_LRCK_WIDTH_SFT; in mtk_dai_tdm_hw_params()
416 regmap_update_bits(afe->regmap, ETDM_IN1_CON1, ETDM_IN_CON1_CTRL_MASK, tdm_con); in mtk_dai_tdm_hw_params()
420 regmap_update_bits(afe->regmap, ETDM_IN1_CON3, ETDM_IN_CON3_CTRL_MASK, tdm_con); in mtk_dai_tdm_hw_params()
435 regmap_update_bits(afe->regmap, ETDM_IN1_CON4, ETDM_IN_CON4_CTRL_MASK, tdm_con); in mtk_dai_tdm_hw_params()
443 regmap_update_bits(afe->regmap, ETDM_IN1_CON2, ETDM_IN_CON2_CTRL_MASK, tdm_con); in mtk_dai_tdm_hw_params()
454 regmap_update_bits(afe->regmap, ETDM_IN1_CON8, ETDM_IN_CON8_CTRL_MASK, tdm_con); in mtk_dai_tdm_hw_params()
462 struct mtk_base_afe *afe = dev_get_drvdata(dai->dev); in mtk_dai_tdm_set_sysclk()
463 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_dai_tdm_set_sysclk()
464 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai->id]; in mtk_dai_tdm_set_sysclk()
467 dev_err(afe->dev, "%s(), dir != SND_SOC_CLOCK_OUT", __func__); in mtk_dai_tdm_set_sysclk()
468 return -EINVAL; in mtk_dai_tdm_set_sysclk()
471 dev_dbg(afe->dev, "%s(), freq %d\n", __func__, freq); in mtk_dai_tdm_set_sysclk()
478 struct mtk_base_afe *afe = dev_get_drvdata(dai->dev); in mtk_dai_tdm_set_fmt()
479 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_dai_tdm_set_fmt()
480 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai->id]; in mtk_dai_tdm_set_fmt()
482 /* DAI mode*/ in mtk_dai_tdm_set_fmt()
485 tdm_priv->tdm_mode = TDM_IN_I2S; in mtk_dai_tdm_set_fmt()
486 tdm_priv->data_mode = TDM_DATA_MULTI_PIN; in mtk_dai_tdm_set_fmt()
489 tdm_priv->tdm_mode = TDM_IN_LJ; in mtk_dai_tdm_set_fmt()
490 tdm_priv->data_mode = TDM_DATA_MULTI_PIN; in mtk_dai_tdm_set_fmt()
493 tdm_priv->tdm_mode = TDM_IN_RJ; in mtk_dai_tdm_set_fmt()
494 tdm_priv->data_mode = TDM_DATA_MULTI_PIN; in mtk_dai_tdm_set_fmt()
497 tdm_priv->tdm_mode = TDM_IN_DSP_A; in mtk_dai_tdm_set_fmt()
498 tdm_priv->data_mode = TDM_DATA_ONE_PIN; in mtk_dai_tdm_set_fmt()
501 tdm_priv->tdm_mode = TDM_IN_DSP_B; in mtk_dai_tdm_set_fmt()
502 tdm_priv->data_mode = TDM_DATA_ONE_PIN; in mtk_dai_tdm_set_fmt()
505 dev_err(afe->dev, "%s(), invalid DAIFMT_FORMAT_MASK", __func__); in mtk_dai_tdm_set_fmt()
506 return -EINVAL; in mtk_dai_tdm_set_fmt()
512 tdm_priv->bck_invert = TDM_BCK_NON_INV; in mtk_dai_tdm_set_fmt()
513 tdm_priv->lck_invert = TDM_LCK_NON_INV; in mtk_dai_tdm_set_fmt()
516 tdm_priv->bck_invert = TDM_BCK_NON_INV; in mtk_dai_tdm_set_fmt()
517 tdm_priv->lck_invert = TDM_LCK_INV; in mtk_dai_tdm_set_fmt()
520 tdm_priv->bck_invert = TDM_BCK_INV; in mtk_dai_tdm_set_fmt()
521 tdm_priv->lck_invert = TDM_LCK_NON_INV; in mtk_dai_tdm_set_fmt()
524 tdm_priv->bck_invert = TDM_BCK_INV; in mtk_dai_tdm_set_fmt()
525 tdm_priv->lck_invert = TDM_LCK_INV; in mtk_dai_tdm_set_fmt()
528 dev_err(afe->dev, "%s(), invalid DAIFMT_INV_MASK", __func__); in mtk_dai_tdm_set_fmt()
529 return -EINVAL; in mtk_dai_tdm_set_fmt()
534 tdm_priv->slave_mode = false; in mtk_dai_tdm_set_fmt()
537 tdm_priv->slave_mode = true; in mtk_dai_tdm_set_fmt()
540 dev_err(afe->dev, "%s(), invalid DAIFMT_CLOCK_PROVIDER_MASK", in mtk_dai_tdm_set_fmt()
542 return -EINVAL; in mtk_dai_tdm_set_fmt()
554 struct mtk_base_afe *afe = dev_get_drvdata(dai->dev); in mtk_dai_tdm_set_tdm_slot()
555 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mtk_dai_tdm_set_tdm_slot()
556 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai->id]; in mtk_dai_tdm_set_tdm_slot()
558 dev_dbg(dai->dev, "%s %d slot_width %d\n", __func__, dai->id, slot_width); in mtk_dai_tdm_set_tdm_slot()
560 tdm_priv->lrck_width = slot_width; in mtk_dai_tdm_set_tdm_slot()
585 .name = "TDM IN",
588 .stream_name = "TDM IN",
602 tdm_priv = devm_kzalloc(afe->dev, sizeof(struct mtk_afe_tdm_priv), in init_tdm_priv_data()
607 tdm_priv->mclk_multiple = 512; in init_tdm_priv_data()
608 tdm_priv->mclk_id = MT8186_TDM_MCK; in init_tdm_priv_data()
609 tdm_priv->id = MT8186_DAI_TDM_IN; in init_tdm_priv_data()
616 struct mt8186_afe_private *afe_priv = afe->platform_priv; in mt8186_dai_tdm_register()
620 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8186_dai_tdm_register()
622 return -ENOMEM; in mt8186_dai_tdm_register()
624 list_add(&dai->list, &afe->sub_dais); in mt8186_dai_tdm_register()
626 dai->dai_drivers = mtk_dai_tdm_driver; in mt8186_dai_tdm_register()
627 dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_tdm_driver); in mt8186_dai_tdm_register()
629 dai->controls = mtk_dai_tdm_controls; in mt8186_dai_tdm_register()
630 dai->num_controls = ARRAY_SIZE(mtk_dai_tdm_controls); in mt8186_dai_tdm_register()
631 dai->dapm_widgets = mtk_dai_tdm_widgets; in mt8186_dai_tdm_register()
632 dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_tdm_widgets); in mt8186_dai_tdm_register()
633 dai->dapm_routes = mtk_dai_tdm_routes; in mt8186_dai_tdm_register()
634 dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_tdm_routes); in mt8186_dai_tdm_register()
638 return -ENOMEM; in mt8186_dai_tdm_register()
640 afe_priv->dai_priv[MT8186_DAI_TDM_IN] = tdm_priv; in mt8186_dai_tdm_register()