Il 13/04/23 12:47, Trevor Wu ha scritto:
Replace register controls in snd_soc_dai_ops with snd_soc_dapm_widgets. startup, shutdown and trigger ops are removed, and create DAPM_SUPPLY to handle mclk, clock gating and etdm enabling. Additionally, mclk setup sequence is also updated because of new supply enabling sequence.
Signed-off-by: Trevor Wu trevor.wu@mediatek.com
sound/soc/mediatek/mt8188/mt8188-dai-etdm.c | 790 ++++++++++---------- sound/soc/mediatek/mt8188/mt8188-reg.h | 2 + 2 files changed, 406 insertions(+), 386 deletions(-)
diff --git a/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c b/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c index fddecf5bf7c6..c276687630ee 100644 --- a/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c +++ b/sound/soc/mediatek/mt8188/mt8188-dai-etdm.c @@ -21,6 +21,13 @@ #define ETDM_TO_DAI_ID(x) ((x) + MT8188_AFE_IO_ETDM_START) #define ENUM_TO_STR(x) #x
+enum {
- SUPPLY_SEQ_ETDM_MCLK,
- SUPPLY_SEQ_ETDM_CG,
- SUPPLY_SEQ_DPTX_EN,
- SUPPLY_SEQ_ETDM_EN,
+};
- enum { MTK_DAI_ETDM_FORMAT_I2S = 0, MTK_DAI_ETDM_FORMAT_LJ,
@@ -84,7 +91,6 @@ struct mtk_dai_etdm_rate { };
struct mtk_dai_etdm_priv {
- unsigned int clock_mode; unsigned int data_mode; bool slave_mode; bool lrck_inv;
@@ -100,8 +106,6 @@ struct mtk_dai_etdm_priv { unsigned int cowork_slv_count; int cowork_slv_id[MT8188_AFE_IO_ETDM_NUM - 1]; //dai_id bool in_disable_ch[MT8188_ETDM_MAX_CHANNELS];
unsigned int en_ref_cnt;
bool is_prepared; };
static const struct mtk_dai_etdm_rate mt8188_etdm_rates[] = {
@@ -345,14 +349,82 @@ static int mtk_dai_etdm_get_clkdiv_id_by_dai_id(int dai_id) } }
+static int get_etdm_id_by_name(struct mtk_base_afe *afe,
const char *name)
+{
- if (!strncmp(name, "ETDM1_IN", strlen("ETDM1_IN")))
return MT8188_AFE_IO_ETDM1_IN;
- else if (!strncmp(name, "ETDM2_IN", strlen("ETDM2_IN")))
return MT8188_AFE_IO_ETDM2_IN;
- else if (!strncmp(name, "ETDM1_OUT", strlen("ETDM1_OUT")))
return MT8188_AFE_IO_ETDM1_OUT;
- else if (!strncmp(name, "ETDM2_OUT", strlen("ETDM2_OUT")))
return MT8188_AFE_IO_ETDM2_OUT;
- else
return -EINVAL;
+}
+static struct mtk_dai_etdm_priv *get_etdm_priv_by_name(struct mtk_base_afe *afe,
const char *name)
+{
- struct mt8188_afe_private *afe_priv = afe->platform_priv;
- int dai_id = get_etdm_id_by_name(afe, name);
- if (dai_id < MT8188_AFE_IO_ETDM_START ||
dai_id >= MT8188_AFE_IO_ETDM_END)
return NULL;
- return afe_priv->dai_priv[dai_id];
+}
- static int mtk_dai_etdm_enable_mclk(struct mtk_base_afe *afe, int dai_id) { struct mt8188_afe_private *afe_priv = afe->platform_priv;
- struct mtk_dai_etdm_priv *etdm_data;
- struct etdm_con_reg etdm_reg;
- unsigned int val = 0;
- unsigned int mask;
- int clkmux_id = mtk_dai_etdm_get_clk_id_by_dai_id(dai_id); int clkdiv_id = mtk_dai_etdm_get_clkdiv_id_by_dai_id(dai_id);
- int apll_clk_id;
- int apll;
- int ret;
- if (!is_valid_etdm_dai(dai_id))
return -EINVAL;
- etdm_data = afe_priv->dai_priv[dai_id];
- if (clkdiv_id < 0)
apll = etdm_data->mclk_apll;
apll_clk_id = mt8188_afe_get_mclk_source_clk_id(apll);
if (clkmux_id < 0 || clkdiv_id < 0) return -EINVAL;
if (apll_clk_id < 0)
return apll_clk_id;
ret = get_etdm_reg(dai_id, &etdm_reg);
if (ret < 0)
return ret;
mask = ETDM_CON1_MCLK_OUTPUT;
if (etdm_data->mclk_dir == SND_SOC_CLOCK_OUT)
val = ETDM_CON1_MCLK_OUTPUT;
regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val);
/* enable parent clock before select apll*/
mt8188_afe_enable_clk(afe, afe_priv->clk[clkmux_id]);
/* select apll */
ret = mt8188_afe_set_clk_parent(afe, afe_priv->clk[clkmux_id],
afe_priv->clk[apll_clk_id]);
if (ret)
return ret;
/* set rate */
ret = mt8188_afe_set_clk_rate(afe, afe_priv->clk[clkdiv_id],
etdm_data->mclk_freq);
mt8188_afe_enable_clk(afe, afe_priv->clk[clkdiv_id]);
return 0;
@@ -361,12 +433,207 @@ static int mtk_dai_etdm_enable_mclk(struct mtk_base_afe *afe, int dai_id) static int mtk_dai_etdm_disable_mclk(struct mtk_base_afe *afe, int dai_id) { struct mt8188_afe_private *afe_priv = afe->platform_priv;
- int clkmux_id = mtk_dai_etdm_get_clk_id_by_dai_id(dai_id); int clkdiv_id = mtk_dai_etdm_get_clkdiv_id_by_dai_id(dai_id);
- if (clkdiv_id < 0)
if (clkmux_id < 0 || clkdiv_id < 0) return -EINVAL;
mt8188_afe_disable_clk(afe, afe_priv->clk[clkdiv_id]);
mt8188_afe_disable_clk(afe, afe_priv->clk[clkmux_id]);
return 0;
+}
+static int mtk_etdm_mclk_connect(struct snd_soc_dapm_widget *source,
struct snd_soc_dapm_widget *sink)
+{
- struct snd_soc_dapm_widget *w = sink;
- struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
- struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
- struct mt8188_afe_private *afe_priv = afe->platform_priv;
- struct mtk_dai_etdm_priv *etdm_priv;
- int mclk_id;
- mclk_id = get_etdm_id_by_name(afe, source->name);
- if (mclk_id < 0) {
dev_info(afe->dev, "mclk_id < 0");
Since you're returning 0, this doesn't appear to be an error and this print is useless unless it is used for debugging purposes.
Please change it to dev_dbg().
return 0;
- }
- etdm_priv = get_etdm_priv_by_name(afe, w->name);
- if (!etdm_priv) {
dev_info(afe->dev, "etdm_priv == NULL");
dev_dbg()
return 0;
- }
- if (get_etdm_id_by_name(afe, sink->name) == mclk_id)
return !!(etdm_priv->mclk_freq > 0);
- if (etdm_priv->cowork_source_id == mclk_id) {
etdm_priv = afe_priv->dai_priv[mclk_id];
return !!(etdm_priv->mclk_freq > 0);
- }
- return 0;
+}
+static int mtk_etdm_cowork_connect(struct snd_soc_dapm_widget *source,
struct snd_soc_dapm_widget *sink)
+{
- struct snd_soc_dapm_widget *w = sink;
- struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
- struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
- struct mt8188_afe_private *afe_priv = afe->platform_priv;
- struct mtk_dai_etdm_priv *etdm_priv;
- int source_id;
- int i;
- source_id = get_etdm_id_by_name(afe, source->name);
- if (source_id < 0) {
dev_info(afe->dev, "%s() source_id < 0\n", __func__);
dev_dbg() please
return 0;
- }
- etdm_priv = get_etdm_priv_by_name(afe, w->name);
- if (!etdm_priv) {
dev_info(afe->dev, "%s() etdm_priv == NULL\n", __func__);
...again... and everywhere else.
return 0;
- }
Regards, Angelo