Lines Matching +full:capture +full:- +full:channels
1 // SPDX-License-Identifier: GPL-2.0
14 #include "mt8195-afe-clk.h"
15 #include "mt8195-afe-common.h"
16 #include "mt8195-reg.h"
117 int cowork_slv_id[MT8195_AFE_IO_ETDM_NUM - 1]; //dai_id
148 return -EINVAL; in get_etdm_fs_timing()
151 static unsigned int get_etdm_ch_fixup(unsigned int channels) in get_etdm_ch_fixup() argument
153 if (channels > 16) in get_etdm_ch_fixup()
155 else if (channels > 8) in get_etdm_ch_fixup()
157 else if (channels > 4) in get_etdm_ch_fixup()
159 else if (channels > 2) in get_etdm_ch_fixup()
169 etdm_reg->con0 = ETDM_IN1_CON0; in get_etdm_reg()
170 etdm_reg->con1 = ETDM_IN1_CON1; in get_etdm_reg()
171 etdm_reg->con2 = ETDM_IN1_CON2; in get_etdm_reg()
172 etdm_reg->con3 = ETDM_IN1_CON3; in get_etdm_reg()
173 etdm_reg->con4 = ETDM_IN1_CON4; in get_etdm_reg()
174 etdm_reg->con5 = ETDM_IN1_CON5; in get_etdm_reg()
177 etdm_reg->con0 = ETDM_IN2_CON0; in get_etdm_reg()
178 etdm_reg->con1 = ETDM_IN2_CON1; in get_etdm_reg()
179 etdm_reg->con2 = ETDM_IN2_CON2; in get_etdm_reg()
180 etdm_reg->con3 = ETDM_IN2_CON3; in get_etdm_reg()
181 etdm_reg->con4 = ETDM_IN2_CON4; in get_etdm_reg()
182 etdm_reg->con5 = ETDM_IN2_CON5; in get_etdm_reg()
185 etdm_reg->con0 = ETDM_OUT1_CON0; in get_etdm_reg()
186 etdm_reg->con1 = ETDM_OUT1_CON1; in get_etdm_reg()
187 etdm_reg->con2 = ETDM_OUT1_CON2; in get_etdm_reg()
188 etdm_reg->con3 = ETDM_OUT1_CON3; in get_etdm_reg()
189 etdm_reg->con4 = ETDM_OUT1_CON4; in get_etdm_reg()
190 etdm_reg->con5 = ETDM_OUT1_CON5; in get_etdm_reg()
193 etdm_reg->con0 = ETDM_OUT2_CON0; in get_etdm_reg()
194 etdm_reg->con1 = ETDM_OUT2_CON1; in get_etdm_reg()
195 etdm_reg->con2 = ETDM_OUT2_CON2; in get_etdm_reg()
196 etdm_reg->con3 = ETDM_OUT2_CON3; in get_etdm_reg()
197 etdm_reg->con4 = ETDM_OUT2_CON4; in get_etdm_reg()
198 etdm_reg->con5 = ETDM_OUT2_CON5; in get_etdm_reg()
202 etdm_reg->con0 = ETDM_OUT3_CON0; in get_etdm_reg()
203 etdm_reg->con1 = ETDM_OUT3_CON1; in get_etdm_reg()
204 etdm_reg->con2 = ETDM_OUT3_CON2; in get_etdm_reg()
205 etdm_reg->con3 = ETDM_OUT3_CON3; in get_etdm_reg()
206 etdm_reg->con4 = ETDM_OUT3_CON4; in get_etdm_reg()
207 etdm_reg->con5 = ETDM_OUT3_CON5; in get_etdm_reg()
210 return -EINVAL; in get_etdm_reg()
226 return -EINVAL; in get_etdm_dir()
238 struct mt8195_afe_private *afe_priv = afe->platform_priv; in is_cowork_mode()
239 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; in is_cowork_mode()
241 return (etdm_data->cowork_slv_count > 0 || in is_cowork_mode()
242 etdm_data->cowork_source_id != COWORK_ETDM_NONE); in is_cowork_mode()
266 struct mt8195_afe_private *afe_priv = afe->platform_priv; in get_etdm_cowork_master_id()
267 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; in get_etdm_cowork_master_id()
268 int dai_id = etdm_data->cowork_source_id; in get_etdm_cowork_master_id()
271 dai_id = dai->id; in get_etdm_cowork_master_id()
657 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in mt8195_etdm_clk_src_sel_put()
659 unsigned int source = ucontrol->value.enumerated.item[0]; in mt8195_etdm_clk_src_sel_put()
664 if (source >= e->items) in mt8195_etdm_clk_src_sel_put()
665 return -EINVAL; in mt8195_etdm_clk_src_sel_put()
668 if (!strcmp(kcontrol->id.name, "ETDM_OUT1_Clock_Source")) { in mt8195_etdm_clk_src_sel_put()
672 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT2_Clock_Source")) { in mt8195_etdm_clk_src_sel_put()
676 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT3_Clock_Source")) { in mt8195_etdm_clk_src_sel_put()
680 } else if (!strcmp(kcontrol->id.name, "ETDM_IN1_Clock_Source")) { in mt8195_etdm_clk_src_sel_put()
684 } else if (!strcmp(kcontrol->id.name, "ETDM_IN2_Clock_Source")) { in mt8195_etdm_clk_src_sel_put()
691 regmap_update_bits(afe->regmap, reg, mask, val); in mt8195_etdm_clk_src_sel_put()
707 if (!strcmp(kcontrol->id.name, "ETDM_OUT1_Clock_Source")) { in mt8195_etdm_clk_src_sel_get()
711 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT2_Clock_Source")) { in mt8195_etdm_clk_src_sel_get()
715 } else if (!strcmp(kcontrol->id.name, "ETDM_OUT3_Clock_Source")) { in mt8195_etdm_clk_src_sel_get()
719 } else if (!strcmp(kcontrol->id.name, "ETDM_IN1_Clock_Source")) { in mt8195_etdm_clk_src_sel_get()
723 } else if (!strcmp(kcontrol->id.name, "ETDM_IN2_Clock_Source")) { in mt8195_etdm_clk_src_sel_get()
730 regmap_read(afe->regmap, reg, &value); in mt8195_etdm_clk_src_sel_get()
734 ucontrol->value.enumerated.item[0] = value; in mt8195_etdm_clk_src_sel_get()
974 {"I012", NULL, "ETDM2 Capture"},
975 {"I013", NULL, "ETDM2 Capture"},
976 {"I014", NULL, "ETDM2 Capture"},
977 {"I015", NULL, "ETDM2 Capture"},
978 {"I016", NULL, "ETDM2 Capture"},
979 {"I017", NULL, "ETDM2 Capture"},
980 {"I018", NULL, "ETDM2 Capture"},
981 {"I019", NULL, "ETDM2 Capture"},
983 {"I072", NULL, "ETDM1 Capture"},
984 {"I073", NULL, "ETDM1 Capture"},
985 {"I074", NULL, "ETDM1 Capture"},
986 {"I075", NULL, "ETDM1 Capture"},
987 {"I076", NULL, "ETDM1 Capture"},
988 {"I077", NULL, "ETDM1 Capture"},
989 {"I078", NULL, "ETDM1 Capture"},
990 {"I079", NULL, "ETDM1 Capture"},
991 {"I080", NULL, "ETDM1 Capture"},
992 {"I081", NULL, "ETDM1 Capture"},
993 {"I082", NULL, "ETDM1 Capture"},
994 {"I083", NULL, "ETDM1 Capture"},
995 {"I084", NULL, "ETDM1 Capture"},
996 {"I085", NULL, "ETDM1 Capture"},
997 {"I086", NULL, "ETDM1 Capture"},
998 {"I087", NULL, "ETDM1 Capture"},
999 {"I088", NULL, "ETDM1 Capture"},
1000 {"I089", NULL, "ETDM1 Capture"},
1001 {"I090", NULL, "ETDM1 Capture"},
1002 {"I091", NULL, "ETDM1 Capture"},
1003 {"I092", NULL, "ETDM1 Capture"},
1004 {"I093", NULL, "ETDM1 Capture"},
1005 {"I094", NULL, "ETDM1 Capture"},
1006 {"I095", NULL, "ETDM1 Capture"},
1008 {"UL8", NULL, "ETDM1 Capture"},
1009 {"UL3", NULL, "ETDM2 Capture"},
1270 {"ETDM1 Capture", NULL, "ETDM_INPUT"},
1271 {"ETDM2 Capture", NULL, "ETDM_INPUT"},
1278 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_afe_enable_etdm()
1279 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mt8195_afe_enable_etdm()
1282 spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags); in mt8195_afe_enable_etdm()
1283 etdm_data->en_ref_cnt++; in mt8195_afe_enable_etdm()
1284 if (etdm_data->en_ref_cnt == 1) { in mt8195_afe_enable_etdm()
1289 regmap_update_bits(afe->regmap, etdm_reg.con0, in mt8195_afe_enable_etdm()
1293 spin_unlock_irqrestore(&afe_priv->afe_ctrl_lock, flags); in mt8195_afe_enable_etdm()
1301 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_afe_disable_etdm()
1302 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mt8195_afe_disable_etdm()
1305 spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags); in mt8195_afe_disable_etdm()
1306 if (etdm_data->en_ref_cnt > 0) { in mt8195_afe_disable_etdm()
1307 etdm_data->en_ref_cnt--; in mt8195_afe_disable_etdm()
1308 if (etdm_data->en_ref_cnt == 0) { in mt8195_afe_disable_etdm()
1313 regmap_update_bits(afe->regmap, etdm_reg.con0, in mt8195_afe_disable_etdm()
1318 spin_unlock_irqrestore(&afe_priv->afe_ctrl_lock, flags); in mt8195_afe_disable_etdm()
1337 return -EINVAL; in etdm_cowork_slv_sel()
1352 return -EINVAL; in etdm_cowork_slv_sel()
1359 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_etdm_sync_mode_configure()
1360 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mt8195_etdm_sync_mode_configure()
1366 if (etdm_data->cowork_source_id == COWORK_ETDM_NONE) in mt8195_etdm_sync_mode_configure()
1369 cowork_source_sel = etdm_cowork_slv_sel(etdm_data->cowork_source_id, in mt8195_etdm_sync_mode_configure()
1370 etdm_data->slave_mode); in mt8195_etdm_sync_mode_configure()
1404 regmap_update_bits(afe->regmap, reg, mask, val); in mt8195_etdm_sync_mode_configure()
1411 int cg_id = -1; in mtk_dai_etdm_get_cg_id_by_dai_id()
1441 int clk_id = -1; in mtk_dai_etdm_get_clk_id_by_dai_id()
1469 int clk_id = -1; in mtk_dai_etdm_get_clkdiv_id_by_dai_id()
1497 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_enable_mclk()
1501 return -EINVAL; in mtk_dai_etdm_enable_mclk()
1503 mt8195_afe_enable_clk(afe, afe_priv->clk[clkdiv_id]); in mtk_dai_etdm_enable_mclk()
1510 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_disable_mclk()
1514 return -EINVAL; in mtk_dai_etdm_disable_mclk()
1516 mt8195_afe_disable_clk(afe, afe_priv->clk[clkdiv_id]); in mtk_dai_etdm_disable_mclk()
1526 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_startup()
1539 mt8195_afe_enable_clk(afe, afe_priv->clk[cg_id]); in mtk_dai_etdm_startup()
1541 mst_etdm_data = afe_priv->dai_priv[mst_dai_id]; in mtk_dai_etdm_startup()
1543 for (i = 0; i < mst_etdm_data->cowork_slv_count; i++) { in mtk_dai_etdm_startup()
1544 slv_dai_id = mst_etdm_data->cowork_slv_id[i]; in mtk_dai_etdm_startup()
1548 afe_priv->clk[cg_id]); in mtk_dai_etdm_startup()
1551 mtk_dai_etdm_enable_mclk(afe, dai->id); in mtk_dai_etdm_startup()
1553 cg_id = mtk_dai_etdm_get_cg_id_by_dai_id(dai->id); in mtk_dai_etdm_startup()
1555 mt8195_afe_enable_clk(afe, afe_priv->clk[cg_id]); in mtk_dai_etdm_startup()
1565 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_shutdown()
1576 mt8195_afe_disable_clk(afe, afe_priv->clk[cg_id]); in mtk_dai_etdm_shutdown()
1578 mst_etdm_data = afe_priv->dai_priv[mst_dai_id]; in mtk_dai_etdm_shutdown()
1579 for (i = 0; i < mst_etdm_data->cowork_slv_count; i++) { in mtk_dai_etdm_shutdown()
1580 slv_dai_id = mst_etdm_data->cowork_slv_id[i]; in mtk_dai_etdm_shutdown()
1584 afe_priv->clk[cg_id]); in mtk_dai_etdm_shutdown()
1588 cg_id = mtk_dai_etdm_get_cg_id_by_dai_id(dai->id); in mtk_dai_etdm_shutdown()
1590 mt8195_afe_disable_clk(afe, afe_priv->clk[cg_id]); in mtk_dai_etdm_shutdown()
1592 mtk_dai_etdm_disable_mclk(afe, dai->id); in mtk_dai_etdm_shutdown()
1619 return -EINVAL; in mtk_dai_etdm_fifo_mode()
1624 regmap_update_bits(afe->regmap, reg, mask, val); in mtk_dai_etdm_fifo_mode()
1630 unsigned int channels, in mtk_dai_etdm_in_configure() argument
1633 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_in_configure()
1634 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_in_configure()
1636 bool slave_mode = etdm_data->slave_mode; in mtk_dai_etdm_in_configure()
1637 unsigned int data_mode = etdm_data->data_mode; in mtk_dai_etdm_in_configure()
1638 unsigned int lrck_width = etdm_data->lrck_width; in mtk_dai_etdm_in_configure()
1644 dev_dbg(afe->dev, "%s rate %u channels %u, id %d\n", in mtk_dai_etdm_in_configure()
1645 __func__, rate, channels, dai_id); in mtk_dai_etdm_in_configure()
1651 if (etdm_data->cowork_source_id != COWORK_ETDM_NONE) in mtk_dai_etdm_in_configure()
1666 regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val); in mtk_dai_etdm_in_configure()
1683 ETDM_IN_CON2_MULTI_IP_TOTAL_CH(channels); in mtk_dai_etdm_in_configure()
1685 regmap_update_bits(afe->regmap, etdm_reg.con2, mask, val); in mtk_dai_etdm_in_configure()
1692 for (i = 0; i < channels; i += 2) { in mtk_dai_etdm_in_configure()
1693 if (etdm_data->in_disable_ch[i] && in mtk_dai_etdm_in_configure()
1694 etdm_data->in_disable_ch[i + 1]) in mtk_dai_etdm_in_configure()
1701 regmap_update_bits(afe->regmap, etdm_reg.con3, mask, val); in mtk_dai_etdm_in_configure()
1710 if (etdm_data->lrck_inv) in mtk_dai_etdm_in_configure()
1712 if (etdm_data->bck_inv) in mtk_dai_etdm_in_configure()
1715 if (etdm_data->lrck_inv) in mtk_dai_etdm_in_configure()
1717 if (etdm_data->bck_inv) in mtk_dai_etdm_in_configure()
1720 regmap_update_bits(afe->regmap, etdm_reg.con4, mask, val); in mtk_dai_etdm_in_configure()
1728 for (i = 0; i < channels; i += 2) { in mtk_dai_etdm_in_configure()
1729 if (etdm_data->in_disable_ch[i] && in mtk_dai_etdm_in_configure()
1730 !etdm_data->in_disable_ch[i + 1]) { in mtk_dai_etdm_in_configure()
1731 if (i == (channels - 2)) in mtk_dai_etdm_in_configure()
1736 } else if (!etdm_data->in_disable_ch[i] && in mtk_dai_etdm_in_configure()
1737 etdm_data->in_disable_ch[i + 1]) { in mtk_dai_etdm_in_configure()
1741 regmap_update_bits(afe->regmap, etdm_reg.con5, mask, val); in mtk_dai_etdm_in_configure()
1747 unsigned int channels, in mtk_dai_etdm_out_configure() argument
1750 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_out_configure()
1751 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_out_configure()
1753 bool slave_mode = etdm_data->slave_mode; in mtk_dai_etdm_out_configure()
1754 unsigned int lrck_width = etdm_data->lrck_width; in mtk_dai_etdm_out_configure()
1760 dev_dbg(afe->dev, "%s rate %u channels %u, id %d\n", in mtk_dai_etdm_out_configure()
1761 __func__, rate, channels, dai_id); in mtk_dai_etdm_out_configure()
1767 if (etdm_data->cowork_source_id != COWORK_ETDM_NONE) in mtk_dai_etdm_out_configure()
1773 regmap_update_bits(afe->regmap, etdm_reg.con0, mask, val); in mtk_dai_etdm_out_configure()
1784 regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val); in mtk_dai_etdm_out_configure()
1795 regmap_update_bits(afe->regmap, etdm_reg.con2, in mtk_dai_etdm_out_configure()
1813 regmap_update_bits(afe->regmap, etdm_reg.con4, mask, val); in mtk_dai_etdm_out_configure()
1822 if (etdm_data->lrck_inv) in mtk_dai_etdm_out_configure()
1824 if (etdm_data->bck_inv) in mtk_dai_etdm_out_configure()
1827 if (etdm_data->lrck_inv) in mtk_dai_etdm_out_configure()
1829 if (etdm_data->bck_inv) in mtk_dai_etdm_out_configure()
1832 regmap_update_bits(afe->regmap, etdm_reg.con5, mask, val); in mtk_dai_etdm_out_configure()
1839 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_mclk_configure()
1840 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_mclk_configure()
1858 if (etdm_data->mclk_dir == SND_SOC_CLOCK_OUT) in mtk_dai_etdm_mclk_configure()
1860 regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val); in mtk_dai_etdm_mclk_configure()
1862 if (etdm_data->mclk_freq) { in mtk_dai_etdm_mclk_configure()
1863 apll = etdm_data->mclk_apll; in mtk_dai_etdm_mclk_configure()
1869 ret = mt8195_afe_set_clk_parent(afe, afe_priv->clk[clk_id], in mtk_dai_etdm_mclk_configure()
1870 afe_priv->clk[apll_clk_id]); in mtk_dai_etdm_mclk_configure()
1875 ret = mt8195_afe_set_clk_rate(afe, afe_priv->clk[clkdiv_id], in mtk_dai_etdm_mclk_configure()
1876 etdm_data->mclk_freq); in mtk_dai_etdm_mclk_configure()
1878 if (etdm_data->mclk_dir == SND_SOC_CLOCK_OUT) in mtk_dai_etdm_mclk_configure()
1879 dev_dbg(afe->dev, "%s mclk freq = 0\n", __func__); in mtk_dai_etdm_mclk_configure()
1886 unsigned int channels, in mtk_dai_etdm_configure() argument
1890 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_configure()
1891 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_configure()
1893 bool slave_mode = etdm_data->slave_mode; in mtk_dai_etdm_configure()
1905 if (etdm_data->cowork_source_id != COWORK_ETDM_NONE) in mtk_dai_etdm_configure()
1908 dev_dbg(afe->dev, "%s fmt %u data %u lrck %d-%u bck %d, clock %u slv %u\n", in mtk_dai_etdm_configure()
1909 __func__, etdm_data->format, etdm_data->data_mode, in mtk_dai_etdm_configure()
1910 etdm_data->lrck_inv, etdm_data->lrck_width, etdm_data->bck_inv, in mtk_dai_etdm_configure()
1911 etdm_data->clock_mode, etdm_data->slave_mode); in mtk_dai_etdm_configure()
1912 dev_dbg(afe->dev, "%s rate %u channels %u bitwidth %u, id %d\n", in mtk_dai_etdm_configure()
1913 __func__, rate, channels, bit_width, dai_id); in mtk_dai_etdm_configure()
1915 etdm_channels = (etdm_data->data_mode == MTK_DAI_ETDM_DATA_ONE_PIN) ? in mtk_dai_etdm_configure()
1916 get_etdm_ch_fixup(channels) : 2; in mtk_dai_etdm_configure()
1920 dev_info(afe->dev, "%s bck rate %u not support\n", in mtk_dai_etdm_configure()
1922 return -EINVAL; in mtk_dai_etdm_configure()
1931 val |= ETDM_CON0_FORMAT(etdm_data->format); in mtk_dai_etdm_configure()
1938 etdm_data->cowork_source_id == COWORK_ETDM_NONE) { in mtk_dai_etdm_configure()
1939 dev_info(afe->dev, "%s id %d only support master mode\n", in mtk_dai_etdm_configure()
1941 return -EINVAL; in mtk_dai_etdm_configure()
1945 regmap_update_bits(afe->regmap, etdm_reg.con0, mask, val); in mtk_dai_etdm_configure()
1948 mtk_dai_etdm_in_configure(afe, rate, channels, dai_id); in mtk_dai_etdm_configure()
1950 mtk_dai_etdm_out_configure(afe, rate, channels, dai_id); in mtk_dai_etdm_configure()
1962 unsigned int channels = params_channels(params); in mtk_dai_etdm_hw_params() local
1964 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_hw_params()
1970 dev_dbg(afe->dev, "%s '%s' period %u-%u\n", in mtk_dai_etdm_hw_params()
1981 ret = mtk_dai_etdm_configure(afe, rate, channels, in mtk_dai_etdm_hw_params()
1986 mst_etdm_data = afe_priv->dai_priv[mst_dai_id]; in mtk_dai_etdm_hw_params()
1987 for (i = 0; i < mst_etdm_data->cowork_slv_count; i++) { in mtk_dai_etdm_hw_params()
1988 slv_dai_id = mst_etdm_data->cowork_slv_id[i]; in mtk_dai_etdm_hw_params()
1989 ret = mtk_dai_etdm_configure(afe, rate, channels, in mtk_dai_etdm_hw_params()
1999 ret = mtk_dai_etdm_mclk_configure(afe, dai->id); in mtk_dai_etdm_hw_params()
2003 ret = mtk_dai_etdm_configure(afe, rate, channels, in mtk_dai_etdm_hw_params()
2004 bit_width, dai->id); in mtk_dai_etdm_hw_params()
2015 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_trigger()
2021 dev_dbg(afe->dev, "%s(), cmd %d, dai id %d\n", __func__, cmd, dai->id); in mtk_dai_etdm_trigger()
2027 mst_etdm_data = afe_priv->dai_priv[mst_dai_id]; in mtk_dai_etdm_trigger()
2031 for (i = 0; i < mst_etdm_data->cowork_slv_count; i++) { in mtk_dai_etdm_trigger()
2032 slv_dai_id = mst_etdm_data->cowork_slv_id[i]; in mtk_dai_etdm_trigger()
2036 ret = mt8195_afe_enable_etdm(afe, dai->id); in mtk_dai_etdm_trigger()
2043 mst_etdm_data = afe_priv->dai_priv[mst_dai_id]; in mtk_dai_etdm_trigger()
2045 for (i = 0; i < mst_etdm_data->cowork_slv_count; i++) { in mtk_dai_etdm_trigger()
2046 slv_dai_id = mst_etdm_data->cowork_slv_id[i]; in mtk_dai_etdm_trigger()
2052 ret = mt8195_afe_disable_etdm(afe, dai->id); in mtk_dai_etdm_trigger()
2063 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_cal_mclk()
2064 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_cal_mclk()
2069 etdm_data->mclk_freq = freq; in mtk_dai_etdm_cal_mclk()
2077 dev_info(afe->dev, "freq %d > apll rate %d\n", freq, apll_rate); in mtk_dai_etdm_cal_mclk()
2078 return -EINVAL; in mtk_dai_etdm_cal_mclk()
2082 dev_info(afe->dev, "APLL%d cannot generate freq Hz\n", apll); in mtk_dai_etdm_cal_mclk()
2083 return -EINVAL; in mtk_dai_etdm_cal_mclk()
2086 etdm_data->mclk_apll = apll; in mtk_dai_etdm_cal_mclk()
2087 etdm_data->mclk_freq = freq; in mtk_dai_etdm_cal_mclk()
2096 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_set_sysclk()
2100 dev_dbg(dai->dev, "%s id %d freq %u, dir %d\n", in mtk_dai_etdm_set_sysclk()
2101 __func__, dai->id, freq, dir); in mtk_dai_etdm_set_sysclk()
2105 dai_id = dai->id; in mtk_dai_etdm_set_sysclk()
2107 etdm_data = afe_priv->dai_priv[dai_id]; in mtk_dai_etdm_set_sysclk()
2108 etdm_data->mclk_dir = dir; in mtk_dai_etdm_set_sysclk()
2117 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_set_tdm_slot()
2118 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_etdm_set_tdm_slot()
2120 dev_dbg(dai->dev, "%s id %d slot_width %d\n", in mtk_dai_etdm_set_tdm_slot()
2121 __func__, dai->id, slot_width); in mtk_dai_etdm_set_tdm_slot()
2123 etdm_data->slots = slots; in mtk_dai_etdm_set_tdm_slot()
2124 etdm_data->lrck_width = slot_width; in mtk_dai_etdm_set_tdm_slot()
2131 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_set_fmt()
2132 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_etdm_set_fmt()
2136 etdm_data->format = MTK_DAI_ETDM_FORMAT_I2S; in mtk_dai_etdm_set_fmt()
2139 etdm_data->format = MTK_DAI_ETDM_FORMAT_LJ; in mtk_dai_etdm_set_fmt()
2142 etdm_data->format = MTK_DAI_ETDM_FORMAT_RJ; in mtk_dai_etdm_set_fmt()
2145 etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPA; in mtk_dai_etdm_set_fmt()
2148 etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPB; in mtk_dai_etdm_set_fmt()
2151 return -EINVAL; in mtk_dai_etdm_set_fmt()
2156 etdm_data->bck_inv = false; in mtk_dai_etdm_set_fmt()
2157 etdm_data->lrck_inv = false; in mtk_dai_etdm_set_fmt()
2160 etdm_data->bck_inv = false; in mtk_dai_etdm_set_fmt()
2161 etdm_data->lrck_inv = true; in mtk_dai_etdm_set_fmt()
2164 etdm_data->bck_inv = true; in mtk_dai_etdm_set_fmt()
2165 etdm_data->lrck_inv = false; in mtk_dai_etdm_set_fmt()
2168 etdm_data->bck_inv = true; in mtk_dai_etdm_set_fmt()
2169 etdm_data->lrck_inv = true; in mtk_dai_etdm_set_fmt()
2172 return -EINVAL; in mtk_dai_etdm_set_fmt()
2177 etdm_data->slave_mode = true; in mtk_dai_etdm_set_fmt()
2180 etdm_data->slave_mode = false; in mtk_dai_etdm_set_fmt()
2183 return -EINVAL; in mtk_dai_etdm_set_fmt()
2193 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_hdmitx_dptx_startup()
2194 int cg_id = mtk_dai_etdm_get_cg_id_by_dai_id(dai->id); in mtk_dai_hdmitx_dptx_startup()
2197 mt8195_afe_enable_clk(afe, afe_priv->clk[cg_id]); in mtk_dai_hdmitx_dptx_startup()
2199 mtk_dai_etdm_enable_mclk(afe, dai->id); in mtk_dai_hdmitx_dptx_startup()
2208 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_hdmitx_dptx_shutdown()
2209 int cg_id = mtk_dai_etdm_get_cg_id_by_dai_id(dai->id); in mtk_dai_hdmitx_dptx_shutdown()
2211 mtk_dai_etdm_disable_mclk(afe, dai->id); in mtk_dai_hdmitx_dptx_shutdown()
2214 mt8195_afe_disable_clk(afe, afe_priv->clk[cg_id]); in mtk_dai_hdmitx_dptx_shutdown()
2250 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_hdmitx_dptx_hw_params()
2251 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_hdmitx_dptx_hw_params()
2253 unsigned int channels = params_channels(params); in mtk_dai_hdmitx_dptx_hw_params() local
2259 if (dai->id == MT8195_AFE_IO_DPTX) { in mtk_dai_hdmitx_dptx_hw_params()
2260 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_hw_params()
2262 mtk_dai_get_dptx_ch_en(channels)); in mtk_dai_hdmitx_dptx_hw_params()
2263 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_hw_params()
2265 mtk_dai_get_dptx_ch(channels)); in mtk_dai_hdmitx_dptx_hw_params()
2266 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_hw_params()
2270 if (mtk_dai_get_dptx_ch(channels) == AFE_DPTX_CON_CH_NUM_8CH) { in mtk_dai_hdmitx_dptx_hw_params()
2271 etdm_data->data_mode = MTK_DAI_ETDM_DATA_ONE_PIN; in mtk_dai_hdmitx_dptx_hw_params()
2272 channels = 8; in mtk_dai_hdmitx_dptx_hw_params()
2274 channels = 2; in mtk_dai_hdmitx_dptx_hw_params()
2277 etdm_data->data_mode = MTK_DAI_ETDM_DATA_MULTI_PIN; in mtk_dai_hdmitx_dptx_hw_params()
2280 ret = mtk_dai_etdm_mclk_configure(afe, dai->id); in mtk_dai_hdmitx_dptx_hw_params()
2284 ret = mtk_dai_etdm_configure(afe, rate, channels, width, dai->id); in mtk_dai_hdmitx_dptx_hw_params()
2296 dev_dbg(afe->dev, "%s(), cmd %d, dai id %d\n", __func__, cmd, dai->id); in mtk_dai_hdmitx_dptx_trigger()
2302 if (dai->id == MT8195_AFE_IO_DPTX) in mtk_dai_hdmitx_dptx_trigger()
2303 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_trigger()
2308 ret = mt8195_afe_enable_etdm(afe, dai->id); in mtk_dai_hdmitx_dptx_trigger()
2313 ret = mt8195_afe_disable_etdm(afe, dai->id); in mtk_dai_hdmitx_dptx_trigger()
2316 if (dai->id == MT8195_AFE_IO_DPTX) in mtk_dai_hdmitx_dptx_trigger()
2317 regmap_update_bits(afe->regmap, AFE_DPTX_CON, in mtk_dai_hdmitx_dptx_trigger()
2321 return -EINVAL; in mtk_dai_hdmitx_dptx_trigger()
2333 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_hdmitx_dptx_set_sysclk()
2334 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_hdmitx_dptx_set_sysclk()
2336 dev_dbg(dai->dev, "%s id %d freq %u, dir %d\n", in mtk_dai_hdmitx_dptx_set_sysclk()
2337 __func__, dai->id, freq, dir); in mtk_dai_hdmitx_dptx_set_sysclk()
2339 etdm_data->mclk_dir = dir; in mtk_dai_hdmitx_dptx_set_sysclk()
2340 return mtk_dai_etdm_cal_mclk(afe, freq, dai->id); in mtk_dai_hdmitx_dptx_set_sysclk()
2372 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mtk_dai_etdm_probe()
2373 struct mtk_dai_etdm_priv *etdm_data = afe_priv->dai_priv[dai->id]; in mtk_dai_etdm_probe()
2375 dev_dbg(dai->dev, "%s id %d\n", __func__, dai->id); in mtk_dai_etdm_probe()
2377 if (etdm_data->mclk_freq) { in mtk_dai_etdm_probe()
2378 dev_dbg(afe->dev, "MCLK always on, rate %d\n", in mtk_dai_etdm_probe()
2379 etdm_data->mclk_freq); in mtk_dai_etdm_probe()
2380 pm_runtime_get_sync(afe->dev); in mtk_dai_etdm_probe()
2381 mtk_dai_etdm_mclk_configure(afe, dai->id); in mtk_dai_etdm_probe()
2382 mtk_dai_etdm_enable_mclk(afe, dai->id); in mtk_dai_etdm_probe()
2383 pm_runtime_put_sync(afe->dev); in mtk_dai_etdm_probe()
2404 .capture = {
2405 .stream_name = "ETDM1 Capture",
2417 .capture = {
2418 .stream_name = "ETDM2 Capture",
2470 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_etdm_update_sync_info()
2477 etdm_data = afe_priv->dai_priv[i]; in mt8195_etdm_update_sync_info()
2478 if (etdm_data->cowork_source_id != COWORK_ETDM_NONE) { in mt8195_etdm_update_sync_info()
2479 mst_dai_id = etdm_data->cowork_source_id; in mt8195_etdm_update_sync_info()
2480 mst_data = afe_priv->dai_priv[mst_dai_id]; in mt8195_etdm_update_sync_info()
2481 if (mst_data->cowork_source_id != COWORK_ETDM_NONE) in mt8195_etdm_update_sync_info()
2482 dev_info(afe->dev, "%s [%d] wrong sync source\n" in mt8195_etdm_update_sync_info()
2484 mst_data->cowork_slv_id[mst_data->cowork_slv_count] = i; in mt8195_etdm_update_sync_info()
2485 mst_data->cowork_slv_count++; in mt8195_etdm_update_sync_info()
2492 const struct device_node *of_node = afe->dev->of_node; in mt8195_dai_etdm_parse_of()
2493 struct mt8195_afe_private *afe_priv = afe->platform_priv; in mt8195_dai_etdm_parse_of()
2507 {"etdm-in1", ETDM_SYNC_FROM_IN1}, in mt8195_dai_etdm_parse_of()
2508 {"etdm-in2", ETDM_SYNC_FROM_IN2}, in mt8195_dai_etdm_parse_of()
2509 {"etdm-out1", ETDM_SYNC_FROM_OUT1}, in mt8195_dai_etdm_parse_of()
2510 {"etdm-out2", ETDM_SYNC_FROM_OUT2}, in mt8195_dai_etdm_parse_of()
2511 {"etdm-out3", ETDM_SYNC_FROM_OUT3}, in mt8195_dai_etdm_parse_of()
2516 etdm_data = afe_priv->dai_priv[dai_id]; in mt8195_dai_etdm_parse_of()
2519 "mediatek,%s-mclk-always-on-rate", in mt8195_dai_etdm_parse_of()
2522 dev_info(afe->dev, "%s snprintf err=%d\n", in mt8195_dai_etdm_parse_of()
2528 etdm_data->mclk_dir = SND_SOC_CLOCK_OUT; in mt8195_dai_etdm_parse_of()
2530 dev_info(afe->dev, "%s unsupported mclk %uHz\n", in mt8195_dai_etdm_parse_of()
2535 "mediatek,%s-multi-pin-mode", in mt8195_dai_etdm_parse_of()
2538 dev_info(afe->dev, "%s snprintf err=%d\n", in mt8195_dai_etdm_parse_of()
2542 etdm_data->data_mode = of_property_read_bool(of_node, prop); in mt8195_dai_etdm_parse_of()
2545 "mediatek,%s-cowork-source", in mt8195_dai_etdm_parse_of()
2548 dev_info(afe->dev, "%s snprintf err=%d\n", in mt8195_dai_etdm_parse_of()
2555 dev_info(afe->dev, "%s invalid id=%d\n", in mt8195_dai_etdm_parse_of()
2557 etdm_data->cowork_source_id = COWORK_ETDM_NONE; in mt8195_dai_etdm_parse_of()
2560 etdm_data->cowork_source_id = in mt8195_dai_etdm_parse_of()
2564 etdm_data->cowork_source_id = COWORK_ETDM_NONE; in mt8195_dai_etdm_parse_of()
2571 "mediatek,%s-chn-disabled", in mt8195_dai_etdm_parse_of()
2574 dev_info(afe->dev, "%s snprintf err=%d\n", in mt8195_dai_etdm_parse_of()
2586 dev_info(afe->dev, "%s [%d] invalid chn %u\n", in mt8195_dai_etdm_parse_of()
2589 etdm_data->in_disable_ch[disable_chn[j]] = true; in mt8195_dai_etdm_parse_of()
2597 struct mt8195_afe_private *afe_priv = afe->platform_priv; in init_etdm_priv_data()
2602 etdm_priv = devm_kzalloc(afe->dev, in init_etdm_priv_data()
2606 return -ENOMEM; in init_etdm_priv_data()
2608 afe_priv->dai_priv[i] = etdm_priv; in init_etdm_priv_data()
2611 afe_priv->dai_priv[MT8195_AFE_IO_DPTX] = in init_etdm_priv_data()
2612 afe_priv->dai_priv[MT8195_AFE_IO_ETDM3_OUT]; in init_etdm_priv_data()
2622 dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL); in mt8195_dai_etdm_register()
2624 return -ENOMEM; in mt8195_dai_etdm_register()
2626 list_add(&dai->list, &afe->sub_dais); in mt8195_dai_etdm_register()
2628 dai->dai_drivers = mtk_dai_etdm_driver; in mt8195_dai_etdm_register()
2629 dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_etdm_driver); in mt8195_dai_etdm_register()
2631 dai->dapm_widgets = mtk_dai_etdm_widgets; in mt8195_dai_etdm_register()
2632 dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_etdm_widgets); in mt8195_dai_etdm_register()
2633 dai->dapm_routes = mtk_dai_etdm_routes; in mt8195_dai_etdm_register()
2634 dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_etdm_routes); in mt8195_dai_etdm_register()
2635 dai->controls = mtk_dai_etdm_controls; in mt8195_dai_etdm_register()
2636 dai->num_controls = ARRAY_SIZE(mtk_dai_etdm_controls); in mt8195_dai_etdm_register()