12babb477STrevor Wu // SPDX-License-Identifier: GPL-2.0
22babb477STrevor Wu /*
32babb477STrevor Wu * MediaTek ALSA SoC Audio DAI eTDM Control
42babb477STrevor Wu *
52babb477STrevor Wu * Copyright (c) 2022 MediaTek Inc.
62babb477STrevor Wu * Author: Bicycle Tsai <bicycle.tsai@mediatek.com>
72babb477STrevor Wu * Trevor Wu <trevor.wu@mediatek.com>
82babb477STrevor Wu * Chun-Chia Chiu <chun-chia.chiu@mediatek.com>
92babb477STrevor Wu */
102babb477STrevor Wu
112babb477STrevor Wu #include <linux/bitfield.h>
122babb477STrevor Wu #include <linux/pm_runtime.h>
132babb477STrevor Wu #include <linux/regmap.h>
142babb477STrevor Wu #include <sound/pcm_params.h>
152babb477STrevor Wu #include "mt8188-afe-clk.h"
162babb477STrevor Wu #include "mt8188-afe-common.h"
172babb477STrevor Wu #include "mt8188-reg.h"
182babb477STrevor Wu
192babb477STrevor Wu #define MT8188_ETDM_MAX_CHANNELS 16
202babb477STrevor Wu #define MT8188_ETDM_NORMAL_MAX_BCK_RATE 24576000
212babb477STrevor Wu #define ETDM_TO_DAI_ID(x) ((x) + MT8188_AFE_IO_ETDM_START)
222babb477STrevor Wu #define ENUM_TO_STR(x) #x
232babb477STrevor Wu
242babb477STrevor Wu enum {
259be0213aSTrevor Wu SUPPLY_SEQ_APLL,
26e5d2bd41STrevor Wu SUPPLY_SEQ_ETDM_MCLK,
27e5d2bd41STrevor Wu SUPPLY_SEQ_ETDM_CG,
28e5d2bd41STrevor Wu SUPPLY_SEQ_DPTX_EN,
29e5d2bd41STrevor Wu SUPPLY_SEQ_ETDM_EN,
30e5d2bd41STrevor Wu };
31e5d2bd41STrevor Wu
32e5d2bd41STrevor Wu enum {
332babb477STrevor Wu MTK_DAI_ETDM_FORMAT_I2S = 0,
342babb477STrevor Wu MTK_DAI_ETDM_FORMAT_LJ,
352babb477STrevor Wu MTK_DAI_ETDM_FORMAT_RJ,
362babb477STrevor Wu MTK_DAI_ETDM_FORMAT_EIAJ,
372babb477STrevor Wu MTK_DAI_ETDM_FORMAT_DSPA,
382babb477STrevor Wu MTK_DAI_ETDM_FORMAT_DSPB,
392babb477STrevor Wu };
402babb477STrevor Wu
412babb477STrevor Wu enum {
422babb477STrevor Wu MTK_DAI_ETDM_DATA_ONE_PIN = 0,
432babb477STrevor Wu MTK_DAI_ETDM_DATA_MULTI_PIN,
442babb477STrevor Wu };
452babb477STrevor Wu
462babb477STrevor Wu enum {
472babb477STrevor Wu ETDM_IN,
482babb477STrevor Wu ETDM_OUT,
492babb477STrevor Wu };
502babb477STrevor Wu
512babb477STrevor Wu enum {
522babb477STrevor Wu COWORK_ETDM_NONE = 0,
532babb477STrevor Wu COWORK_ETDM_IN1_M = 2,
542babb477STrevor Wu COWORK_ETDM_IN1_S = 3,
552babb477STrevor Wu COWORK_ETDM_IN2_M = 4,
562babb477STrevor Wu COWORK_ETDM_IN2_S = 5,
572babb477STrevor Wu COWORK_ETDM_OUT1_M = 10,
582babb477STrevor Wu COWORK_ETDM_OUT1_S = 11,
592babb477STrevor Wu COWORK_ETDM_OUT2_M = 12,
602babb477STrevor Wu COWORK_ETDM_OUT2_S = 13,
612babb477STrevor Wu COWORK_ETDM_OUT3_M = 14,
622babb477STrevor Wu COWORK_ETDM_OUT3_S = 15,
632babb477STrevor Wu };
642babb477STrevor Wu
652babb477STrevor Wu enum {
662babb477STrevor Wu ETDM_RELATCH_TIMING_A1A2SYS,
672babb477STrevor Wu ETDM_RELATCH_TIMING_A3SYS,
682babb477STrevor Wu ETDM_RELATCH_TIMING_A4SYS,
692babb477STrevor Wu };
702babb477STrevor Wu
712babb477STrevor Wu enum {
722babb477STrevor Wu ETDM_SYNC_NONE,
732babb477STrevor Wu ETDM_SYNC_FROM_IN1 = 2,
742babb477STrevor Wu ETDM_SYNC_FROM_IN2 = 4,
752babb477STrevor Wu ETDM_SYNC_FROM_OUT1 = 10,
762babb477STrevor Wu ETDM_SYNC_FROM_OUT2 = 12,
772babb477STrevor Wu ETDM_SYNC_FROM_OUT3 = 14,
782babb477STrevor Wu };
792babb477STrevor Wu
802babb477STrevor Wu struct etdm_con_reg {
812babb477STrevor Wu unsigned int con0;
822babb477STrevor Wu unsigned int con1;
832babb477STrevor Wu unsigned int con2;
842babb477STrevor Wu unsigned int con3;
852babb477STrevor Wu unsigned int con4;
862babb477STrevor Wu unsigned int con5;
872babb477STrevor Wu };
882babb477STrevor Wu
892babb477STrevor Wu struct mtk_dai_etdm_rate {
902babb477STrevor Wu unsigned int rate;
912babb477STrevor Wu unsigned int reg_value;
922babb477STrevor Wu };
932babb477STrevor Wu
942babb477STrevor Wu struct mtk_dai_etdm_priv {
952babb477STrevor Wu unsigned int data_mode;
962babb477STrevor Wu bool slave_mode;
972babb477STrevor Wu bool lrck_inv;
982babb477STrevor Wu bool bck_inv;
999be0213aSTrevor Wu unsigned int rate;
1002babb477STrevor Wu unsigned int format;
1012babb477STrevor Wu unsigned int slots;
1022babb477STrevor Wu unsigned int lrck_width;
1032babb477STrevor Wu unsigned int mclk_freq;
1042babb477STrevor Wu unsigned int mclk_fixed_apll;
1052babb477STrevor Wu unsigned int mclk_apll;
1062babb477STrevor Wu unsigned int mclk_dir;
1072babb477STrevor Wu int cowork_source_id; //dai id
1082babb477STrevor Wu unsigned int cowork_slv_count;
1092babb477STrevor Wu int cowork_slv_id[MT8188_AFE_IO_ETDM_NUM - 1]; //dai_id
1102babb477STrevor Wu bool in_disable_ch[MT8188_ETDM_MAX_CHANNELS];
1112babb477STrevor Wu };
1122babb477STrevor Wu
1132babb477STrevor Wu static const struct mtk_dai_etdm_rate mt8188_etdm_rates[] = {
1142babb477STrevor Wu { .rate = 8000, .reg_value = 0, },
1152babb477STrevor Wu { .rate = 12000, .reg_value = 1, },
1162babb477STrevor Wu { .rate = 16000, .reg_value = 2, },
1172babb477STrevor Wu { .rate = 24000, .reg_value = 3, },
1182babb477STrevor Wu { .rate = 32000, .reg_value = 4, },
1192babb477STrevor Wu { .rate = 48000, .reg_value = 5, },
1202babb477STrevor Wu { .rate = 96000, .reg_value = 7, },
1212babb477STrevor Wu { .rate = 192000, .reg_value = 9, },
1222babb477STrevor Wu { .rate = 384000, .reg_value = 11, },
1232babb477STrevor Wu { .rate = 11025, .reg_value = 16, },
1242babb477STrevor Wu { .rate = 22050, .reg_value = 17, },
1252babb477STrevor Wu { .rate = 44100, .reg_value = 18, },
1262babb477STrevor Wu { .rate = 88200, .reg_value = 19, },
1272babb477STrevor Wu { .rate = 176400, .reg_value = 20, },
1282babb477STrevor Wu { .rate = 352800, .reg_value = 21, },
1292babb477STrevor Wu };
1302babb477STrevor Wu
get_etdm_fs_timing(unsigned int rate)1312babb477STrevor Wu static int get_etdm_fs_timing(unsigned int rate)
1322babb477STrevor Wu {
1332babb477STrevor Wu int i;
1342babb477STrevor Wu
1352babb477STrevor Wu for (i = 0; i < ARRAY_SIZE(mt8188_etdm_rates); i++)
1362babb477STrevor Wu if (mt8188_etdm_rates[i].rate == rate)
1372babb477STrevor Wu return mt8188_etdm_rates[i].reg_value;
1382babb477STrevor Wu
1392babb477STrevor Wu return -EINVAL;
1402babb477STrevor Wu }
1412babb477STrevor Wu
get_etdm_ch_fixup(unsigned int channels)1422babb477STrevor Wu static unsigned int get_etdm_ch_fixup(unsigned int channels)
1432babb477STrevor Wu {
1442babb477STrevor Wu if (channels > 16)
1452babb477STrevor Wu return 24;
1462babb477STrevor Wu else if (channels > 8)
1472babb477STrevor Wu return 16;
1482babb477STrevor Wu else if (channels > 4)
1492babb477STrevor Wu return 8;
1502babb477STrevor Wu else if (channels > 2)
1512babb477STrevor Wu return 4;
1522babb477STrevor Wu else
1532babb477STrevor Wu return 2;
1542babb477STrevor Wu }
1552babb477STrevor Wu
get_etdm_reg(unsigned int dai_id,struct etdm_con_reg * etdm_reg)1562babb477STrevor Wu static int get_etdm_reg(unsigned int dai_id, struct etdm_con_reg *etdm_reg)
1572babb477STrevor Wu {
1582babb477STrevor Wu switch (dai_id) {
1592babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
1602babb477STrevor Wu etdm_reg->con0 = ETDM_IN1_CON0;
1612babb477STrevor Wu etdm_reg->con1 = ETDM_IN1_CON1;
1622babb477STrevor Wu etdm_reg->con2 = ETDM_IN1_CON2;
1632babb477STrevor Wu etdm_reg->con3 = ETDM_IN1_CON3;
1642babb477STrevor Wu etdm_reg->con4 = ETDM_IN1_CON4;
1652babb477STrevor Wu etdm_reg->con5 = ETDM_IN1_CON5;
1662babb477STrevor Wu break;
1672babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
1682babb477STrevor Wu etdm_reg->con0 = ETDM_IN2_CON0;
1692babb477STrevor Wu etdm_reg->con1 = ETDM_IN2_CON1;
1702babb477STrevor Wu etdm_reg->con2 = ETDM_IN2_CON2;
1712babb477STrevor Wu etdm_reg->con3 = ETDM_IN2_CON3;
1722babb477STrevor Wu etdm_reg->con4 = ETDM_IN2_CON4;
1732babb477STrevor Wu etdm_reg->con5 = ETDM_IN2_CON5;
1742babb477STrevor Wu break;
1752babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
1762babb477STrevor Wu etdm_reg->con0 = ETDM_OUT1_CON0;
1772babb477STrevor Wu etdm_reg->con1 = ETDM_OUT1_CON1;
1782babb477STrevor Wu etdm_reg->con2 = ETDM_OUT1_CON2;
1792babb477STrevor Wu etdm_reg->con3 = ETDM_OUT1_CON3;
1802babb477STrevor Wu etdm_reg->con4 = ETDM_OUT1_CON4;
1812babb477STrevor Wu etdm_reg->con5 = ETDM_OUT1_CON5;
1822babb477STrevor Wu break;
1832babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
1842babb477STrevor Wu etdm_reg->con0 = ETDM_OUT2_CON0;
1852babb477STrevor Wu etdm_reg->con1 = ETDM_OUT2_CON1;
1862babb477STrevor Wu etdm_reg->con2 = ETDM_OUT2_CON2;
1872babb477STrevor Wu etdm_reg->con3 = ETDM_OUT2_CON3;
1882babb477STrevor Wu etdm_reg->con4 = ETDM_OUT2_CON4;
1892babb477STrevor Wu etdm_reg->con5 = ETDM_OUT2_CON5;
1902babb477STrevor Wu break;
1912babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
1922babb477STrevor Wu case MT8188_AFE_IO_DPTX:
1932babb477STrevor Wu etdm_reg->con0 = ETDM_OUT3_CON0;
1942babb477STrevor Wu etdm_reg->con1 = ETDM_OUT3_CON1;
1952babb477STrevor Wu etdm_reg->con2 = ETDM_OUT3_CON2;
1962babb477STrevor Wu etdm_reg->con3 = ETDM_OUT3_CON3;
1972babb477STrevor Wu etdm_reg->con4 = ETDM_OUT3_CON4;
1982babb477STrevor Wu etdm_reg->con5 = ETDM_OUT3_CON5;
1992babb477STrevor Wu break;
2002babb477STrevor Wu default:
2012babb477STrevor Wu return -EINVAL;
2022babb477STrevor Wu }
2032babb477STrevor Wu return 0;
2042babb477STrevor Wu }
2052babb477STrevor Wu
get_etdm_dir(unsigned int dai_id)2062babb477STrevor Wu static int get_etdm_dir(unsigned int dai_id)
2072babb477STrevor Wu {
2082babb477STrevor Wu switch (dai_id) {
2092babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
2102babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
2112babb477STrevor Wu return ETDM_IN;
2122babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
2132babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
2142babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
2152babb477STrevor Wu return ETDM_OUT;
2162babb477STrevor Wu default:
2172babb477STrevor Wu return -EINVAL;
2182babb477STrevor Wu }
2192babb477STrevor Wu }
2202babb477STrevor Wu
get_etdm_wlen(unsigned int bitwidth)2212babb477STrevor Wu static int get_etdm_wlen(unsigned int bitwidth)
2222babb477STrevor Wu {
2232babb477STrevor Wu return bitwidth <= 16 ? 16 : 32;
2242babb477STrevor Wu }
2252babb477STrevor Wu
is_valid_etdm_dai(int dai_id)2262babb477STrevor Wu static bool is_valid_etdm_dai(int dai_id)
2272babb477STrevor Wu {
2282babb477STrevor Wu switch (dai_id) {
2292babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
2302babb477STrevor Wu fallthrough;
2312babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
2322babb477STrevor Wu fallthrough;
2332babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
2342babb477STrevor Wu fallthrough;
2352babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
2362babb477STrevor Wu fallthrough;
2372babb477STrevor Wu case MT8188_AFE_IO_DPTX:
2382babb477STrevor Wu fallthrough;
2392babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
2402babb477STrevor Wu return true;
2412babb477STrevor Wu default:
2422babb477STrevor Wu return false;
2432babb477STrevor Wu }
2442babb477STrevor Wu }
2452babb477STrevor Wu
is_cowork_mode(struct snd_soc_dai * dai)2462babb477STrevor Wu static int is_cowork_mode(struct snd_soc_dai *dai)
2472babb477STrevor Wu {
2482babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
2492babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
2502babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
2512babb477STrevor Wu
2522babb477STrevor Wu if (!is_valid_etdm_dai(dai->id))
2532babb477STrevor Wu return -EINVAL;
2542babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai->id];
2552babb477STrevor Wu
2562babb477STrevor Wu return (etdm_data->cowork_slv_count > 0 ||
2572babb477STrevor Wu etdm_data->cowork_source_id != COWORK_ETDM_NONE);
2582babb477STrevor Wu }
2592babb477STrevor Wu
sync_to_dai_id(int source_sel)2602babb477STrevor Wu static int sync_to_dai_id(int source_sel)
2612babb477STrevor Wu {
2622babb477STrevor Wu switch (source_sel) {
2632babb477STrevor Wu case ETDM_SYNC_FROM_IN1:
2642babb477STrevor Wu return MT8188_AFE_IO_ETDM1_IN;
2652babb477STrevor Wu case ETDM_SYNC_FROM_IN2:
2662babb477STrevor Wu return MT8188_AFE_IO_ETDM2_IN;
2672babb477STrevor Wu case ETDM_SYNC_FROM_OUT1:
2682babb477STrevor Wu return MT8188_AFE_IO_ETDM1_OUT;
2692babb477STrevor Wu case ETDM_SYNC_FROM_OUT2:
2702babb477STrevor Wu return MT8188_AFE_IO_ETDM2_OUT;
2712babb477STrevor Wu case ETDM_SYNC_FROM_OUT3:
2722babb477STrevor Wu return MT8188_AFE_IO_ETDM3_OUT;
2732babb477STrevor Wu default:
2742babb477STrevor Wu return 0;
2752babb477STrevor Wu }
2762babb477STrevor Wu }
2772babb477STrevor Wu
get_etdm_cowork_master_id(struct snd_soc_dai * dai)2782babb477STrevor Wu static int get_etdm_cowork_master_id(struct snd_soc_dai *dai)
2792babb477STrevor Wu {
2802babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
2812babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
2822babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
2832babb477STrevor Wu int dai_id;
2842babb477STrevor Wu
2852babb477STrevor Wu if (!is_valid_etdm_dai(dai->id))
2862babb477STrevor Wu return -EINVAL;
2872babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai->id];
2882babb477STrevor Wu dai_id = etdm_data->cowork_source_id;
2892babb477STrevor Wu
2902babb477STrevor Wu if (dai_id == COWORK_ETDM_NONE)
2912babb477STrevor Wu dai_id = dai->id;
2922babb477STrevor Wu
2932babb477STrevor Wu return dai_id;
2942babb477STrevor Wu }
2952babb477STrevor Wu
mtk_dai_etdm_get_cg_id_by_dai_id(int dai_id)2962babb477STrevor Wu static int mtk_dai_etdm_get_cg_id_by_dai_id(int dai_id)
2972babb477STrevor Wu {
2982babb477STrevor Wu switch (dai_id) {
2992babb477STrevor Wu case MT8188_AFE_IO_DPTX:
3002babb477STrevor Wu return MT8188_CLK_AUD_HDMI_OUT;
3012babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
3022babb477STrevor Wu return MT8188_CLK_AUD_TDM_IN;
3032babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
3042babb477STrevor Wu return MT8188_CLK_AUD_I2SIN;
3052babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
3062babb477STrevor Wu return MT8188_CLK_AUD_TDM_OUT;
3072babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
3082babb477STrevor Wu return MT8188_CLK_AUD_I2S_OUT;
3092babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
3102babb477STrevor Wu return MT8188_CLK_AUD_HDMI_OUT;
3112babb477STrevor Wu default:
3122babb477STrevor Wu return -EINVAL;
3132babb477STrevor Wu }
3142babb477STrevor Wu }
3152babb477STrevor Wu
mtk_dai_etdm_get_clk_id_by_dai_id(int dai_id)3162babb477STrevor Wu static int mtk_dai_etdm_get_clk_id_by_dai_id(int dai_id)
3172babb477STrevor Wu {
3182babb477STrevor Wu switch (dai_id) {
3192babb477STrevor Wu case MT8188_AFE_IO_DPTX:
3202babb477STrevor Wu return MT8188_CLK_TOP_DPTX_M_SEL;
3212babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
3222babb477STrevor Wu return MT8188_CLK_TOP_I2SI1_M_SEL;
3232babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
3242babb477STrevor Wu return MT8188_CLK_TOP_I2SI2_M_SEL;
3252babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
3262babb477STrevor Wu return MT8188_CLK_TOP_I2SO1_M_SEL;
3272babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
3282babb477STrevor Wu return MT8188_CLK_TOP_I2SO2_M_SEL;
3292babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
3302babb477STrevor Wu default:
3312babb477STrevor Wu return -EINVAL;
3322babb477STrevor Wu }
3332babb477STrevor Wu }
3342babb477STrevor Wu
mtk_dai_etdm_get_clkdiv_id_by_dai_id(int dai_id)3352babb477STrevor Wu static int mtk_dai_etdm_get_clkdiv_id_by_dai_id(int dai_id)
3362babb477STrevor Wu {
3372babb477STrevor Wu switch (dai_id) {
3382babb477STrevor Wu case MT8188_AFE_IO_DPTX:
3392babb477STrevor Wu return MT8188_CLK_TOP_APLL12_DIV9;
3402babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
3412babb477STrevor Wu return MT8188_CLK_TOP_APLL12_DIV0;
3422babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
3432babb477STrevor Wu return MT8188_CLK_TOP_APLL12_DIV1;
3442babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
3452babb477STrevor Wu return MT8188_CLK_TOP_APLL12_DIV2;
3462babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
3472babb477STrevor Wu return MT8188_CLK_TOP_APLL12_DIV3;
3482babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
3492babb477STrevor Wu default:
3502babb477STrevor Wu return -EINVAL;
3512babb477STrevor Wu }
3522babb477STrevor Wu }
3532babb477STrevor Wu
get_etdm_id_by_name(struct mtk_base_afe * afe,const char * name)354e5d2bd41STrevor Wu static int get_etdm_id_by_name(struct mtk_base_afe *afe,
355e5d2bd41STrevor Wu const char *name)
356e5d2bd41STrevor Wu {
357e5d2bd41STrevor Wu if (!strncmp(name, "ETDM1_IN", strlen("ETDM1_IN")))
358e5d2bd41STrevor Wu return MT8188_AFE_IO_ETDM1_IN;
359e5d2bd41STrevor Wu else if (!strncmp(name, "ETDM2_IN", strlen("ETDM2_IN")))
360e5d2bd41STrevor Wu return MT8188_AFE_IO_ETDM2_IN;
361e5d2bd41STrevor Wu else if (!strncmp(name, "ETDM1_OUT", strlen("ETDM1_OUT")))
362e5d2bd41STrevor Wu return MT8188_AFE_IO_ETDM1_OUT;
363e5d2bd41STrevor Wu else if (!strncmp(name, "ETDM2_OUT", strlen("ETDM2_OUT")))
364e5d2bd41STrevor Wu return MT8188_AFE_IO_ETDM2_OUT;
3659be0213aSTrevor Wu else if (!strncmp(name, "ETDM3_OUT", strlen("ETDM3_OUT")))
3669be0213aSTrevor Wu return MT8188_AFE_IO_ETDM3_OUT;
3679be0213aSTrevor Wu else if (!strncmp(name, "DPTX", strlen("DPTX")))
3689be0213aSTrevor Wu return MT8188_AFE_IO_ETDM3_OUT;
369e5d2bd41STrevor Wu else
370e5d2bd41STrevor Wu return -EINVAL;
371e5d2bd41STrevor Wu }
372e5d2bd41STrevor Wu
get_etdm_priv_by_name(struct mtk_base_afe * afe,const char * name)373e5d2bd41STrevor Wu static struct mtk_dai_etdm_priv *get_etdm_priv_by_name(struct mtk_base_afe *afe,
374e5d2bd41STrevor Wu const char *name)
375e5d2bd41STrevor Wu {
376e5d2bd41STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
377e5d2bd41STrevor Wu int dai_id = get_etdm_id_by_name(afe, name);
378e5d2bd41STrevor Wu
379e5d2bd41STrevor Wu if (dai_id < MT8188_AFE_IO_ETDM_START ||
380e5d2bd41STrevor Wu dai_id >= MT8188_AFE_IO_ETDM_END)
381e5d2bd41STrevor Wu return NULL;
382e5d2bd41STrevor Wu
383e5d2bd41STrevor Wu return afe_priv->dai_priv[dai_id];
384e5d2bd41STrevor Wu }
385e5d2bd41STrevor Wu
mtk_dai_etdm_enable_mclk(struct mtk_base_afe * afe,int dai_id)3862babb477STrevor Wu static int mtk_dai_etdm_enable_mclk(struct mtk_base_afe *afe, int dai_id)
3872babb477STrevor Wu {
3882babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
389e5d2bd41STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
390e5d2bd41STrevor Wu struct etdm_con_reg etdm_reg;
391e5d2bd41STrevor Wu unsigned int val = 0;
392e5d2bd41STrevor Wu unsigned int mask;
393e5d2bd41STrevor Wu int clkmux_id = mtk_dai_etdm_get_clk_id_by_dai_id(dai_id);
3942babb477STrevor Wu int clkdiv_id = mtk_dai_etdm_get_clkdiv_id_by_dai_id(dai_id);
395e5d2bd41STrevor Wu int apll_clk_id;
396e5d2bd41STrevor Wu int apll;
397e5d2bd41STrevor Wu int ret;
3982babb477STrevor Wu
399e5d2bd41STrevor Wu if (!is_valid_etdm_dai(dai_id))
4002babb477STrevor Wu return -EINVAL;
401e5d2bd41STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
402e5d2bd41STrevor Wu
403e5d2bd41STrevor Wu apll = etdm_data->mclk_apll;
404e5d2bd41STrevor Wu apll_clk_id = mt8188_afe_get_mclk_source_clk_id(apll);
405e5d2bd41STrevor Wu
406e5d2bd41STrevor Wu if (clkmux_id < 0 || clkdiv_id < 0)
407e5d2bd41STrevor Wu return -EINVAL;
408e5d2bd41STrevor Wu
409e5d2bd41STrevor Wu if (apll_clk_id < 0)
410e5d2bd41STrevor Wu return apll_clk_id;
411e5d2bd41STrevor Wu
412e5d2bd41STrevor Wu ret = get_etdm_reg(dai_id, &etdm_reg);
413e5d2bd41STrevor Wu if (ret < 0)
414e5d2bd41STrevor Wu return ret;
415e5d2bd41STrevor Wu
416e5d2bd41STrevor Wu mask = ETDM_CON1_MCLK_OUTPUT;
417e5d2bd41STrevor Wu if (etdm_data->mclk_dir == SND_SOC_CLOCK_OUT)
418e5d2bd41STrevor Wu val = ETDM_CON1_MCLK_OUTPUT;
419e5d2bd41STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val);
420e5d2bd41STrevor Wu
421e5d2bd41STrevor Wu /* enable parent clock before select apll*/
422e5d2bd41STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[clkmux_id]);
423e5d2bd41STrevor Wu
424e5d2bd41STrevor Wu /* select apll */
425e5d2bd41STrevor Wu ret = mt8188_afe_set_clk_parent(afe, afe_priv->clk[clkmux_id],
426e5d2bd41STrevor Wu afe_priv->clk[apll_clk_id]);
427e5d2bd41STrevor Wu if (ret)
428e5d2bd41STrevor Wu return ret;
429e5d2bd41STrevor Wu
430e5d2bd41STrevor Wu /* set rate */
431e5d2bd41STrevor Wu ret = mt8188_afe_set_clk_rate(afe, afe_priv->clk[clkdiv_id],
432e5d2bd41STrevor Wu etdm_data->mclk_freq);
4332babb477STrevor Wu
4342babb477STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[clkdiv_id]);
4352babb477STrevor Wu
4362babb477STrevor Wu return 0;
4372babb477STrevor Wu }
4382babb477STrevor Wu
mtk_dai_etdm_disable_mclk(struct mtk_base_afe * afe,int dai_id)4392babb477STrevor Wu static int mtk_dai_etdm_disable_mclk(struct mtk_base_afe *afe, int dai_id)
4402babb477STrevor Wu {
4412babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
442e5d2bd41STrevor Wu int clkmux_id = mtk_dai_etdm_get_clk_id_by_dai_id(dai_id);
4432babb477STrevor Wu int clkdiv_id = mtk_dai_etdm_get_clkdiv_id_by_dai_id(dai_id);
4442babb477STrevor Wu
445e5d2bd41STrevor Wu if (clkmux_id < 0 || clkdiv_id < 0)
4462babb477STrevor Wu return -EINVAL;
4472babb477STrevor Wu
4482babb477STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[clkdiv_id]);
449e5d2bd41STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[clkmux_id]);
450e5d2bd41STrevor Wu
451e5d2bd41STrevor Wu return 0;
452e5d2bd41STrevor Wu }
453e5d2bd41STrevor Wu
mtk_afe_etdm_apll_connect(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)4549be0213aSTrevor Wu static int mtk_afe_etdm_apll_connect(struct snd_soc_dapm_widget *source,
4559be0213aSTrevor Wu struct snd_soc_dapm_widget *sink)
4569be0213aSTrevor Wu {
4579be0213aSTrevor Wu struct snd_soc_dapm_widget *w = sink;
4589be0213aSTrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
4599be0213aSTrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
4609be0213aSTrevor Wu struct mtk_dai_etdm_priv *etdm_priv;
4619be0213aSTrevor Wu int cur_apll;
4629be0213aSTrevor Wu int need_apll;
4639be0213aSTrevor Wu
4649be0213aSTrevor Wu etdm_priv = get_etdm_priv_by_name(afe, w->name);
4659be0213aSTrevor Wu if (!etdm_priv) {
4669be0213aSTrevor Wu dev_dbg(afe->dev, "etdm_priv == NULL\n");
4679be0213aSTrevor Wu return 0;
4689be0213aSTrevor Wu }
4699be0213aSTrevor Wu
4709be0213aSTrevor Wu cur_apll = mt8188_get_apll_by_name(afe, source->name);
4719be0213aSTrevor Wu need_apll = mt8188_get_apll_by_rate(afe, etdm_priv->rate);
4729be0213aSTrevor Wu
4739be0213aSTrevor Wu return (need_apll == cur_apll) ? 1 : 0;
4749be0213aSTrevor Wu }
4759be0213aSTrevor Wu
mtk_afe_mclk_apll_connect(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)4769be0213aSTrevor Wu static int mtk_afe_mclk_apll_connect(struct snd_soc_dapm_widget *source,
4779be0213aSTrevor Wu struct snd_soc_dapm_widget *sink)
4789be0213aSTrevor Wu {
4799be0213aSTrevor Wu struct snd_soc_dapm_widget *w = sink;
4809be0213aSTrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
4819be0213aSTrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
4829be0213aSTrevor Wu struct mtk_dai_etdm_priv *etdm_priv;
4839be0213aSTrevor Wu int cur_apll;
4849be0213aSTrevor Wu
4859be0213aSTrevor Wu etdm_priv = get_etdm_priv_by_name(afe, w->name);
4869be0213aSTrevor Wu
4879be0213aSTrevor Wu cur_apll = mt8188_get_apll_by_name(afe, source->name);
4889be0213aSTrevor Wu
4899be0213aSTrevor Wu return (etdm_priv->mclk_apll == cur_apll) ? 1 : 0;
4909be0213aSTrevor Wu }
4919be0213aSTrevor Wu
mtk_etdm_mclk_connect(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)492e5d2bd41STrevor Wu static int mtk_etdm_mclk_connect(struct snd_soc_dapm_widget *source,
493e5d2bd41STrevor Wu struct snd_soc_dapm_widget *sink)
494e5d2bd41STrevor Wu {
495e5d2bd41STrevor Wu struct snd_soc_dapm_widget *w = sink;
496e5d2bd41STrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
497e5d2bd41STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
498e5d2bd41STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
499e5d2bd41STrevor Wu struct mtk_dai_etdm_priv *etdm_priv;
500e5d2bd41STrevor Wu int mclk_id;
501e5d2bd41STrevor Wu
502e5d2bd41STrevor Wu mclk_id = get_etdm_id_by_name(afe, source->name);
503e5d2bd41STrevor Wu if (mclk_id < 0) {
504e5d2bd41STrevor Wu dev_dbg(afe->dev, "mclk_id < 0\n");
505e5d2bd41STrevor Wu return 0;
506e5d2bd41STrevor Wu }
507e5d2bd41STrevor Wu
508e5d2bd41STrevor Wu etdm_priv = get_etdm_priv_by_name(afe, w->name);
509e5d2bd41STrevor Wu if (!etdm_priv) {
510e5d2bd41STrevor Wu dev_dbg(afe->dev, "etdm_priv == NULL\n");
511e5d2bd41STrevor Wu return 0;
512e5d2bd41STrevor Wu }
513e5d2bd41STrevor Wu
514e5d2bd41STrevor Wu if (get_etdm_id_by_name(afe, sink->name) == mclk_id)
515e5d2bd41STrevor Wu return !!(etdm_priv->mclk_freq > 0);
516e5d2bd41STrevor Wu
517e5d2bd41STrevor Wu if (etdm_priv->cowork_source_id == mclk_id) {
518e5d2bd41STrevor Wu etdm_priv = afe_priv->dai_priv[mclk_id];
519e5d2bd41STrevor Wu return !!(etdm_priv->mclk_freq > 0);
520e5d2bd41STrevor Wu }
521e5d2bd41STrevor Wu
522e5d2bd41STrevor Wu return 0;
523e5d2bd41STrevor Wu }
524e5d2bd41STrevor Wu
mtk_etdm_cowork_connect(struct snd_soc_dapm_widget * source,struct snd_soc_dapm_widget * sink)525e5d2bd41STrevor Wu static int mtk_etdm_cowork_connect(struct snd_soc_dapm_widget *source,
526e5d2bd41STrevor Wu struct snd_soc_dapm_widget *sink)
527e5d2bd41STrevor Wu {
528e5d2bd41STrevor Wu struct snd_soc_dapm_widget *w = sink;
529e5d2bd41STrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
530e5d2bd41STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
531e5d2bd41STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
532e5d2bd41STrevor Wu struct mtk_dai_etdm_priv *etdm_priv;
533e5d2bd41STrevor Wu int source_id;
534e5d2bd41STrevor Wu int i;
535e5d2bd41STrevor Wu
536e5d2bd41STrevor Wu source_id = get_etdm_id_by_name(afe, source->name);
537e5d2bd41STrevor Wu if (source_id < 0) {
538e5d2bd41STrevor Wu dev_dbg(afe->dev, "%s() source_id < 0\n", __func__);
539e5d2bd41STrevor Wu return 0;
540e5d2bd41STrevor Wu }
541e5d2bd41STrevor Wu
542e5d2bd41STrevor Wu etdm_priv = get_etdm_priv_by_name(afe, w->name);
543e5d2bd41STrevor Wu if (!etdm_priv) {
544e5d2bd41STrevor Wu dev_dbg(afe->dev, "%s() etdm_priv == NULL\n", __func__);
545e5d2bd41STrevor Wu return 0;
546e5d2bd41STrevor Wu }
547e5d2bd41STrevor Wu
548e5d2bd41STrevor Wu if (etdm_priv->cowork_source_id != COWORK_ETDM_NONE) {
549e5d2bd41STrevor Wu if (etdm_priv->cowork_source_id == source_id)
550e5d2bd41STrevor Wu return 1;
551e5d2bd41STrevor Wu
552e5d2bd41STrevor Wu etdm_priv = afe_priv->dai_priv[etdm_priv->cowork_source_id];
553e5d2bd41STrevor Wu for (i = 0; i < etdm_priv->cowork_slv_count; i++) {
554e5d2bd41STrevor Wu if (etdm_priv->cowork_slv_id[i] == source_id)
555e5d2bd41STrevor Wu return 1;
556e5d2bd41STrevor Wu }
557e5d2bd41STrevor Wu } else {
558e5d2bd41STrevor Wu for (i = 0; i < etdm_priv->cowork_slv_count; i++) {
559e5d2bd41STrevor Wu if (etdm_priv->cowork_slv_id[i] == source_id)
560e5d2bd41STrevor Wu return 1;
561e5d2bd41STrevor Wu }
562e5d2bd41STrevor Wu }
563e5d2bd41STrevor Wu
564e5d2bd41STrevor Wu return 0;
565e5d2bd41STrevor Wu }
566e5d2bd41STrevor Wu
mtk_apll_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)5679be0213aSTrevor Wu static int mtk_apll_event(struct snd_soc_dapm_widget *w,
5689be0213aSTrevor Wu struct snd_kcontrol *kcontrol,
5699be0213aSTrevor Wu int event)
5709be0213aSTrevor Wu {
5719be0213aSTrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
5729be0213aSTrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
5739be0213aSTrevor Wu
5749be0213aSTrevor Wu dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n",
5759be0213aSTrevor Wu __func__, w->name, event);
5769be0213aSTrevor Wu
5779be0213aSTrevor Wu switch (event) {
5789be0213aSTrevor Wu case SND_SOC_DAPM_PRE_PMU:
579*d1ecaabeSKrzysztof Kozlowski if (snd_soc_dapm_widget_name_cmp(w, APLL1_W_NAME) == 0)
5809be0213aSTrevor Wu mt8188_apll1_enable(afe);
5819be0213aSTrevor Wu else
5829be0213aSTrevor Wu mt8188_apll2_enable(afe);
5839be0213aSTrevor Wu break;
5849be0213aSTrevor Wu case SND_SOC_DAPM_POST_PMD:
585*d1ecaabeSKrzysztof Kozlowski if (snd_soc_dapm_widget_name_cmp(w, APLL1_W_NAME) == 0)
5869be0213aSTrevor Wu mt8188_apll1_disable(afe);
5879be0213aSTrevor Wu else
5889be0213aSTrevor Wu mt8188_apll2_disable(afe);
5899be0213aSTrevor Wu break;
5909be0213aSTrevor Wu default:
5919be0213aSTrevor Wu break;
5929be0213aSTrevor Wu }
5939be0213aSTrevor Wu
5949be0213aSTrevor Wu return 0;
5959be0213aSTrevor Wu }
5969be0213aSTrevor Wu
mtk_etdm_mclk_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)597e5d2bd41STrevor Wu static int mtk_etdm_mclk_event(struct snd_soc_dapm_widget *w,
598e5d2bd41STrevor Wu struct snd_kcontrol *kcontrol,
599e5d2bd41STrevor Wu int event)
600e5d2bd41STrevor Wu {
601e5d2bd41STrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
602e5d2bd41STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
603e5d2bd41STrevor Wu int mclk_id = get_etdm_id_by_name(afe, w->name);
604e5d2bd41STrevor Wu
605e5d2bd41STrevor Wu if (mclk_id < 0) {
606e5d2bd41STrevor Wu dev_dbg(afe->dev, "%s() mclk_id < 0\n", __func__);
607e5d2bd41STrevor Wu return 0;
608e5d2bd41STrevor Wu }
609e5d2bd41STrevor Wu
610e5d2bd41STrevor Wu dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n",
611e5d2bd41STrevor Wu __func__, w->name, event);
612e5d2bd41STrevor Wu
613e5d2bd41STrevor Wu switch (event) {
614e5d2bd41STrevor Wu case SND_SOC_DAPM_PRE_PMU:
615e5d2bd41STrevor Wu mtk_dai_etdm_enable_mclk(afe, mclk_id);
616e5d2bd41STrevor Wu break;
617e5d2bd41STrevor Wu case SND_SOC_DAPM_POST_PMD:
618e5d2bd41STrevor Wu mtk_dai_etdm_disable_mclk(afe, mclk_id);
619e5d2bd41STrevor Wu break;
620e5d2bd41STrevor Wu default:
621e5d2bd41STrevor Wu break;
622e5d2bd41STrevor Wu }
623e5d2bd41STrevor Wu
624e5d2bd41STrevor Wu return 0;
625e5d2bd41STrevor Wu }
626e5d2bd41STrevor Wu
mtk_dptx_mclk_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)627e5d2bd41STrevor Wu static int mtk_dptx_mclk_event(struct snd_soc_dapm_widget *w,
628e5d2bd41STrevor Wu struct snd_kcontrol *kcontrol,
629e5d2bd41STrevor Wu int event)
630e5d2bd41STrevor Wu {
631e5d2bd41STrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
632e5d2bd41STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
633e5d2bd41STrevor Wu
634e5d2bd41STrevor Wu dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n",
635e5d2bd41STrevor Wu __func__, w->name, event);
636e5d2bd41STrevor Wu
637e5d2bd41STrevor Wu switch (event) {
638e5d2bd41STrevor Wu case SND_SOC_DAPM_PRE_PMU:
639e5d2bd41STrevor Wu mtk_dai_etdm_enable_mclk(afe, MT8188_AFE_IO_DPTX);
640e5d2bd41STrevor Wu break;
641e5d2bd41STrevor Wu case SND_SOC_DAPM_POST_PMD:
642e5d2bd41STrevor Wu mtk_dai_etdm_disable_mclk(afe, MT8188_AFE_IO_DPTX);
643e5d2bd41STrevor Wu break;
644e5d2bd41STrevor Wu default:
645e5d2bd41STrevor Wu break;
646e5d2bd41STrevor Wu }
647e5d2bd41STrevor Wu
648e5d2bd41STrevor Wu return 0;
649e5d2bd41STrevor Wu }
650e5d2bd41STrevor Wu
mtk_etdm_cg_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)651e5d2bd41STrevor Wu static int mtk_etdm_cg_event(struct snd_soc_dapm_widget *w,
652e5d2bd41STrevor Wu struct snd_kcontrol *kcontrol,
653e5d2bd41STrevor Wu int event)
654e5d2bd41STrevor Wu {
655e5d2bd41STrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
656e5d2bd41STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
657e5d2bd41STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
658e5d2bd41STrevor Wu int etdm_id;
659e5d2bd41STrevor Wu int cg_id;
660e5d2bd41STrevor Wu
661e5d2bd41STrevor Wu etdm_id = get_etdm_id_by_name(afe, w->name);
662e5d2bd41STrevor Wu if (etdm_id < 0) {
663e5d2bd41STrevor Wu dev_dbg(afe->dev, "%s() etdm_id < 0\n", __func__);
664e5d2bd41STrevor Wu return 0;
665e5d2bd41STrevor Wu }
666e5d2bd41STrevor Wu
667e5d2bd41STrevor Wu cg_id = mtk_dai_etdm_get_cg_id_by_dai_id(etdm_id);
668e5d2bd41STrevor Wu if (cg_id < 0) {
669e5d2bd41STrevor Wu dev_dbg(afe->dev, "%s() cg_id < 0\n", __func__);
670e5d2bd41STrevor Wu return 0;
671e5d2bd41STrevor Wu }
672e5d2bd41STrevor Wu
673e5d2bd41STrevor Wu dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n",
674e5d2bd41STrevor Wu __func__, w->name, event);
675e5d2bd41STrevor Wu
676e5d2bd41STrevor Wu switch (event) {
677e5d2bd41STrevor Wu case SND_SOC_DAPM_PRE_PMU:
678e5d2bd41STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[cg_id]);
679e5d2bd41STrevor Wu break;
680e5d2bd41STrevor Wu case SND_SOC_DAPM_POST_PMD:
681e5d2bd41STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[cg_id]);
682e5d2bd41STrevor Wu break;
683e5d2bd41STrevor Wu default:
684e5d2bd41STrevor Wu break;
685e5d2bd41STrevor Wu }
686e5d2bd41STrevor Wu
687e5d2bd41STrevor Wu return 0;
688e5d2bd41STrevor Wu }
689e5d2bd41STrevor Wu
mtk_etdm3_cg_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)690e5d2bd41STrevor Wu static int mtk_etdm3_cg_event(struct snd_soc_dapm_widget *w,
691e5d2bd41STrevor Wu struct snd_kcontrol *kcontrol,
692e5d2bd41STrevor Wu int event)
693e5d2bd41STrevor Wu {
694e5d2bd41STrevor Wu struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm);
695e5d2bd41STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt);
696e5d2bd41STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
697e5d2bd41STrevor Wu
698e5d2bd41STrevor Wu dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n",
699e5d2bd41STrevor Wu __func__, w->name, event);
700e5d2bd41STrevor Wu
701e5d2bd41STrevor Wu switch (event) {
702e5d2bd41STrevor Wu case SND_SOC_DAPM_PRE_PMU:
703e5d2bd41STrevor Wu mt8188_afe_enable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_HDMI_OUT]);
704e5d2bd41STrevor Wu break;
705e5d2bd41STrevor Wu case SND_SOC_DAPM_POST_PMD:
706e5d2bd41STrevor Wu mt8188_afe_disable_clk(afe, afe_priv->clk[MT8188_CLK_AUD_HDMI_OUT]);
707e5d2bd41STrevor Wu break;
708e5d2bd41STrevor Wu default:
709e5d2bd41STrevor Wu break;
710e5d2bd41STrevor Wu }
7112babb477STrevor Wu
7122babb477STrevor Wu return 0;
7132babb477STrevor Wu }
7142babb477STrevor Wu
7152babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o048_mix[] = {
7162babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I020 Switch", AFE_CONN48, 20, 1, 0),
7172babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I022 Switch", AFE_CONN48, 22, 1, 0),
7182babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I046 Switch", AFE_CONN48_1, 14, 1, 0),
7192babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I070 Switch", AFE_CONN48_2, 6, 1, 0),
7202babb477STrevor Wu };
7212babb477STrevor Wu
7222babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o049_mix[] = {
7232babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I021 Switch", AFE_CONN49, 21, 1, 0),
7242babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I023 Switch", AFE_CONN49, 23, 1, 0),
7252babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I047 Switch", AFE_CONN49_1, 15, 1, 0),
7262babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I071 Switch", AFE_CONN49_2, 7, 1, 0),
7272babb477STrevor Wu };
7282babb477STrevor Wu
7292babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o050_mix[] = {
7302babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I024 Switch", AFE_CONN50, 24, 1, 0),
7312babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I048 Switch", AFE_CONN50_1, 16, 1, 0),
7322babb477STrevor Wu };
7332babb477STrevor Wu
7342babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o051_mix[] = {
7352babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I025 Switch", AFE_CONN51, 25, 1, 0),
7362babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I049 Switch", AFE_CONN51_1, 17, 1, 0),
7372babb477STrevor Wu };
7382babb477STrevor Wu
7392babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o052_mix[] = {
7402babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I026 Switch", AFE_CONN52, 26, 1, 0),
7412babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I050 Switch", AFE_CONN52_1, 18, 1, 0),
7422babb477STrevor Wu };
7432babb477STrevor Wu
7442babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o053_mix[] = {
7452babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I027 Switch", AFE_CONN53, 27, 1, 0),
7462babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I051 Switch", AFE_CONN53_1, 19, 1, 0),
7472babb477STrevor Wu };
7482babb477STrevor Wu
7492babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o054_mix[] = {
7502babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I028 Switch", AFE_CONN54, 28, 1, 0),
7512babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I052 Switch", AFE_CONN54_1, 20, 1, 0),
7522babb477STrevor Wu };
7532babb477STrevor Wu
7542babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o055_mix[] = {
7552babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I029 Switch", AFE_CONN55, 29, 1, 0),
7562babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I053 Switch", AFE_CONN55_1, 21, 1, 0),
7572babb477STrevor Wu };
7582babb477STrevor Wu
7592babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o056_mix[] = {
7602babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I030 Switch", AFE_CONN56, 30, 1, 0),
7612babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I054 Switch", AFE_CONN56_1, 22, 1, 0),
7622babb477STrevor Wu };
7632babb477STrevor Wu
7642babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o057_mix[] = {
7652babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I031 Switch", AFE_CONN57, 31, 1, 0),
7662babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I055 Switch", AFE_CONN57_1, 23, 1, 0),
7672babb477STrevor Wu };
7682babb477STrevor Wu
7692babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o058_mix[] = {
7702babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I032 Switch", AFE_CONN58_1, 0, 1, 0),
7712babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I056 Switch", AFE_CONN58_1, 24, 1, 0),
7722babb477STrevor Wu };
7732babb477STrevor Wu
7742babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o059_mix[] = {
7752babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I033 Switch", AFE_CONN59_1, 1, 1, 0),
7762babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I057 Switch", AFE_CONN59_1, 25, 1, 0),
7772babb477STrevor Wu };
7782babb477STrevor Wu
7792babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o060_mix[] = {
7802babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I034 Switch", AFE_CONN60_1, 2, 1, 0),
7812babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I058 Switch", AFE_CONN60_1, 26, 1, 0),
7822babb477STrevor Wu };
7832babb477STrevor Wu
7842babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o061_mix[] = {
7852babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I035 Switch", AFE_CONN61_1, 3, 1, 0),
7862babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I059 Switch", AFE_CONN61_1, 27, 1, 0),
7872babb477STrevor Wu };
7882babb477STrevor Wu
7892babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o062_mix[] = {
7902babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I036 Switch", AFE_CONN62_1, 4, 1, 0),
7912babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I060 Switch", AFE_CONN62_1, 28, 1, 0),
7922babb477STrevor Wu };
7932babb477STrevor Wu
7942babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o063_mix[] = {
7952babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I037 Switch", AFE_CONN63_1, 5, 1, 0),
7962babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I061 Switch", AFE_CONN63_1, 29, 1, 0),
7972babb477STrevor Wu };
7982babb477STrevor Wu
7992babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o072_mix[] = {
8002babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I020 Switch", AFE_CONN72, 20, 1, 0),
8012babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I022 Switch", AFE_CONN72, 22, 1, 0),
8022babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I046 Switch", AFE_CONN72_1, 14, 1, 0),
8032babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I070 Switch", AFE_CONN72_2, 6, 1, 0),
8042babb477STrevor Wu };
8052babb477STrevor Wu
8062babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o073_mix[] = {
8072babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I021 Switch", AFE_CONN73, 21, 1, 0),
8082babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I023 Switch", AFE_CONN73, 23, 1, 0),
8092babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I047 Switch", AFE_CONN73_1, 15, 1, 0),
8102babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I071 Switch", AFE_CONN73_2, 7, 1, 0),
8112babb477STrevor Wu };
8122babb477STrevor Wu
8132babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o074_mix[] = {
8142babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I024 Switch", AFE_CONN74, 24, 1, 0),
8152babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I048 Switch", AFE_CONN74_1, 16, 1, 0),
8162babb477STrevor Wu };
8172babb477STrevor Wu
8182babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o075_mix[] = {
8192babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I025 Switch", AFE_CONN75, 25, 1, 0),
8202babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I049 Switch", AFE_CONN75_1, 17, 1, 0),
8212babb477STrevor Wu };
8222babb477STrevor Wu
8232babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o076_mix[] = {
8242babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I026 Switch", AFE_CONN76, 26, 1, 0),
8252babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I050 Switch", AFE_CONN76_1, 18, 1, 0),
8262babb477STrevor Wu };
8272babb477STrevor Wu
8282babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o077_mix[] = {
8292babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I027 Switch", AFE_CONN77, 27, 1, 0),
8302babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I051 Switch", AFE_CONN77_1, 19, 1, 0),
8312babb477STrevor Wu };
8322babb477STrevor Wu
8332babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o078_mix[] = {
8342babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I028 Switch", AFE_CONN78, 28, 1, 0),
8352babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I052 Switch", AFE_CONN78_1, 20, 1, 0),
8362babb477STrevor Wu };
8372babb477STrevor Wu
8382babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o079_mix[] = {
8392babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I029 Switch", AFE_CONN79, 29, 1, 0),
8402babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I053 Switch", AFE_CONN79_1, 21, 1, 0),
8412babb477STrevor Wu };
8422babb477STrevor Wu
8432babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o080_mix[] = {
8442babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I030 Switch", AFE_CONN80, 30, 1, 0),
8452babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I054 Switch", AFE_CONN80_1, 22, 1, 0),
8462babb477STrevor Wu };
8472babb477STrevor Wu
8482babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o081_mix[] = {
8492babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I031 Switch", AFE_CONN81, 31, 1, 0),
8502babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I055 Switch", AFE_CONN81_1, 23, 1, 0),
8512babb477STrevor Wu };
8522babb477STrevor Wu
8532babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o082_mix[] = {
8542babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I032 Switch", AFE_CONN82_1, 0, 1, 0),
8552babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I056 Switch", AFE_CONN82_1, 24, 1, 0),
8562babb477STrevor Wu };
8572babb477STrevor Wu
8582babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o083_mix[] = {
8592babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I033 Switch", AFE_CONN83_1, 1, 1, 0),
8602babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I057 Switch", AFE_CONN83_1, 25, 1, 0),
8612babb477STrevor Wu };
8622babb477STrevor Wu
8632babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o084_mix[] = {
8642babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I034 Switch", AFE_CONN84_1, 2, 1, 0),
8652babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I058 Switch", AFE_CONN84_1, 26, 1, 0),
8662babb477STrevor Wu };
8672babb477STrevor Wu
8682babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o085_mix[] = {
8692babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I035 Switch", AFE_CONN85_1, 3, 1, 0),
8702babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I059 Switch", AFE_CONN85_1, 27, 1, 0),
8712babb477STrevor Wu };
8722babb477STrevor Wu
8732babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o086_mix[] = {
8742babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I036 Switch", AFE_CONN86_1, 4, 1, 0),
8752babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I060 Switch", AFE_CONN86_1, 28, 1, 0),
8762babb477STrevor Wu };
8772babb477STrevor Wu
8782babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_o087_mix[] = {
8792babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I037 Switch", AFE_CONN87_1, 5, 1, 0),
8802babb477STrevor Wu SOC_DAPM_SINGLE_AUTODISABLE("I061 Switch", AFE_CONN87_1, 29, 1, 0),
8812babb477STrevor Wu };
8822babb477STrevor Wu
8832babb477STrevor Wu static const char * const mt8188_etdm_clk_src_sel_text[] = {
8842babb477STrevor Wu "26m",
8852babb477STrevor Wu "a1sys_a2sys",
8862babb477STrevor Wu "a3sys",
8872babb477STrevor Wu "a4sys",
8882babb477STrevor Wu };
8892babb477STrevor Wu
8902babb477STrevor Wu static SOC_ENUM_SINGLE_EXT_DECL(etdmout_clk_src_enum,
8912babb477STrevor Wu mt8188_etdm_clk_src_sel_text);
8922babb477STrevor Wu
8932babb477STrevor Wu static const char * const hdmitx_dptx_mux_map[] = {
8942babb477STrevor Wu "Disconnect", "Connect",
8952babb477STrevor Wu };
8962babb477STrevor Wu
8972babb477STrevor Wu static int hdmitx_dptx_mux_map_value[] = {
8982babb477STrevor Wu 0, 1,
8992babb477STrevor Wu };
9002babb477STrevor Wu
9012babb477STrevor Wu /* HDMI_OUT_MUX */
9022babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(hdmi_out_mux_map_enum,
9032babb477STrevor Wu SND_SOC_NOPM,
9042babb477STrevor Wu 0,
9052babb477STrevor Wu 1,
9062babb477STrevor Wu hdmitx_dptx_mux_map,
9072babb477STrevor Wu hdmitx_dptx_mux_map_value);
9082babb477STrevor Wu
9092babb477STrevor Wu static const struct snd_kcontrol_new hdmi_out_mux_control =
9102babb477STrevor Wu SOC_DAPM_ENUM("HDMI_OUT_MUX", hdmi_out_mux_map_enum);
9112babb477STrevor Wu
9122babb477STrevor Wu /* DPTX_OUT_MUX */
9132babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(dptx_out_mux_map_enum,
9142babb477STrevor Wu SND_SOC_NOPM,
9152babb477STrevor Wu 0,
9162babb477STrevor Wu 1,
9172babb477STrevor Wu hdmitx_dptx_mux_map,
9182babb477STrevor Wu hdmitx_dptx_mux_map_value);
9192babb477STrevor Wu
9202babb477STrevor Wu static const struct snd_kcontrol_new dptx_out_mux_control =
9212babb477STrevor Wu SOC_DAPM_ENUM("DPTX_OUT_MUX", dptx_out_mux_map_enum);
9222babb477STrevor Wu
9232babb477STrevor Wu /* HDMI_CH0_MUX ~ HDMI_CH7_MUX */
9242babb477STrevor Wu static const char *const afe_conn_hdmi_mux_map[] = {
9252babb477STrevor Wu "CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7",
9262babb477STrevor Wu };
9272babb477STrevor Wu
9282babb477STrevor Wu static int afe_conn_hdmi_mux_map_value[] = {
9292babb477STrevor Wu 0, 1, 2, 3, 4, 5, 6, 7,
9302babb477STrevor Wu };
9312babb477STrevor Wu
9322babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch0_mux_map_enum,
9332babb477STrevor Wu AFE_TDMOUT_CONN0,
9342babb477STrevor Wu 0,
9352babb477STrevor Wu 0xf,
9362babb477STrevor Wu afe_conn_hdmi_mux_map,
9372babb477STrevor Wu afe_conn_hdmi_mux_map_value);
9382babb477STrevor Wu
9392babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch0_mux_control =
9402babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH0_MUX", hdmi_ch0_mux_map_enum);
9412babb477STrevor Wu
9422babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch1_mux_map_enum,
9432babb477STrevor Wu AFE_TDMOUT_CONN0,
9442babb477STrevor Wu 4,
9452babb477STrevor Wu 0xf,
9462babb477STrevor Wu afe_conn_hdmi_mux_map,
9472babb477STrevor Wu afe_conn_hdmi_mux_map_value);
9482babb477STrevor Wu
9492babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch1_mux_control =
9502babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH1_MUX", hdmi_ch1_mux_map_enum);
9512babb477STrevor Wu
9522babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch2_mux_map_enum,
9532babb477STrevor Wu AFE_TDMOUT_CONN0,
9542babb477STrevor Wu 8,
9552babb477STrevor Wu 0xf,
9562babb477STrevor Wu afe_conn_hdmi_mux_map,
9572babb477STrevor Wu afe_conn_hdmi_mux_map_value);
9582babb477STrevor Wu
9592babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch2_mux_control =
9602babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH2_MUX", hdmi_ch2_mux_map_enum);
9612babb477STrevor Wu
9622babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch3_mux_map_enum,
9632babb477STrevor Wu AFE_TDMOUT_CONN0,
9642babb477STrevor Wu 12,
9652babb477STrevor Wu 0xf,
9662babb477STrevor Wu afe_conn_hdmi_mux_map,
9672babb477STrevor Wu afe_conn_hdmi_mux_map_value);
9682babb477STrevor Wu
9692babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch3_mux_control =
9702babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH3_MUX", hdmi_ch3_mux_map_enum);
9712babb477STrevor Wu
9722babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch4_mux_map_enum,
9732babb477STrevor Wu AFE_TDMOUT_CONN0,
9742babb477STrevor Wu 16,
9752babb477STrevor Wu 0xf,
9762babb477STrevor Wu afe_conn_hdmi_mux_map,
9772babb477STrevor Wu afe_conn_hdmi_mux_map_value);
9782babb477STrevor Wu
9792babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch4_mux_control =
9802babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH4_MUX", hdmi_ch4_mux_map_enum);
9812babb477STrevor Wu
9822babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch5_mux_map_enum,
9832babb477STrevor Wu AFE_TDMOUT_CONN0,
9842babb477STrevor Wu 20,
9852babb477STrevor Wu 0xf,
9862babb477STrevor Wu afe_conn_hdmi_mux_map,
9872babb477STrevor Wu afe_conn_hdmi_mux_map_value);
9882babb477STrevor Wu
9892babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch5_mux_control =
9902babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH5_MUX", hdmi_ch5_mux_map_enum);
9912babb477STrevor Wu
9922babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch6_mux_map_enum,
9932babb477STrevor Wu AFE_TDMOUT_CONN0,
9942babb477STrevor Wu 24,
9952babb477STrevor Wu 0xf,
9962babb477STrevor Wu afe_conn_hdmi_mux_map,
9972babb477STrevor Wu afe_conn_hdmi_mux_map_value);
9982babb477STrevor Wu
9992babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch6_mux_control =
10002babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH6_MUX", hdmi_ch6_mux_map_enum);
10012babb477STrevor Wu
10022babb477STrevor Wu static SOC_VALUE_ENUM_SINGLE_DECL(hdmi_ch7_mux_map_enum,
10032babb477STrevor Wu AFE_TDMOUT_CONN0,
10042babb477STrevor Wu 28,
10052babb477STrevor Wu 0xf,
10062babb477STrevor Wu afe_conn_hdmi_mux_map,
10072babb477STrevor Wu afe_conn_hdmi_mux_map_value);
10082babb477STrevor Wu
10092babb477STrevor Wu static const struct snd_kcontrol_new hdmi_ch7_mux_control =
10102babb477STrevor Wu SOC_DAPM_ENUM("HDMI_CH7_MUX", hdmi_ch7_mux_map_enum);
10112babb477STrevor Wu
mt8188_etdm_clk_src_sel_put(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)10122babb477STrevor Wu static int mt8188_etdm_clk_src_sel_put(struct snd_kcontrol *kcontrol,
10132babb477STrevor Wu struct snd_ctl_elem_value *ucontrol)
10142babb477STrevor Wu {
10152babb477STrevor Wu struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
10162babb477STrevor Wu struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
10172babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
10182babb477STrevor Wu unsigned int source = ucontrol->value.enumerated.item[0];
10192babb477STrevor Wu unsigned int val;
10202babb477STrevor Wu unsigned int old_val;
10212babb477STrevor Wu unsigned int mask;
10222babb477STrevor Wu unsigned int reg;
10232babb477STrevor Wu
10242babb477STrevor Wu if (source >= e->items)
10252babb477STrevor Wu return -EINVAL;
10262babb477STrevor Wu
10272babb477STrevor Wu if (!strcmp(kcontrol->id.name, "ETDM_OUT1_Clock_Source")) {
10282babb477STrevor Wu reg = ETDM_OUT1_CON4;
10292babb477STrevor Wu mask = ETDM_OUT_CON4_CLOCK_MASK;
10302babb477STrevor Wu val = FIELD_PREP(ETDM_OUT_CON4_CLOCK_MASK, source);
10312babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_OUT2_Clock_Source")) {
10322babb477STrevor Wu reg = ETDM_OUT2_CON4;
10332babb477STrevor Wu mask = ETDM_OUT_CON4_CLOCK_MASK;
10342babb477STrevor Wu val = FIELD_PREP(ETDM_OUT_CON4_CLOCK_MASK, source);
10352babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_OUT3_Clock_Source")) {
10362babb477STrevor Wu reg = ETDM_OUT3_CON4;
10372babb477STrevor Wu mask = ETDM_OUT_CON4_CLOCK_MASK;
10382babb477STrevor Wu val = FIELD_PREP(ETDM_OUT_CON4_CLOCK_MASK, source);
10392babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_IN1_Clock_Source")) {
10402babb477STrevor Wu reg = ETDM_IN1_CON2;
10412babb477STrevor Wu mask = ETDM_IN_CON2_CLOCK_MASK;
10422babb477STrevor Wu val = FIELD_PREP(ETDM_IN_CON2_CLOCK_MASK, source);
10432babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_IN2_Clock_Source")) {
10442babb477STrevor Wu reg = ETDM_IN2_CON2;
10452babb477STrevor Wu mask = ETDM_IN_CON2_CLOCK_MASK;
10462babb477STrevor Wu val = FIELD_PREP(ETDM_IN_CON2_CLOCK_MASK, source);
10472babb477STrevor Wu } else {
10482babb477STrevor Wu return -EINVAL;
10492babb477STrevor Wu }
10502babb477STrevor Wu
10512babb477STrevor Wu regmap_read(afe->regmap, reg, &old_val);
10522babb477STrevor Wu old_val &= mask;
10532babb477STrevor Wu if (old_val == val)
10542babb477STrevor Wu return 0;
10552babb477STrevor Wu
10562babb477STrevor Wu regmap_update_bits(afe->regmap, reg, mask, val);
10572babb477STrevor Wu
10582babb477STrevor Wu return 1;
10592babb477STrevor Wu }
10602babb477STrevor Wu
mt8188_etdm_clk_src_sel_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)10612babb477STrevor Wu static int mt8188_etdm_clk_src_sel_get(struct snd_kcontrol *kcontrol,
10622babb477STrevor Wu struct snd_ctl_elem_value *ucontrol)
10632babb477STrevor Wu {
10642babb477STrevor Wu struct snd_soc_component *component =
10652babb477STrevor Wu snd_soc_kcontrol_component(kcontrol);
10662babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
10672babb477STrevor Wu unsigned int value;
10682babb477STrevor Wu unsigned int reg;
10692babb477STrevor Wu unsigned int mask;
10702babb477STrevor Wu unsigned int shift;
10712babb477STrevor Wu
10722babb477STrevor Wu if (!strcmp(kcontrol->id.name, "ETDM_OUT1_Clock_Source")) {
10732babb477STrevor Wu reg = ETDM_OUT1_CON4;
10742babb477STrevor Wu mask = ETDM_OUT_CON4_CLOCK_MASK;
10752babb477STrevor Wu shift = ETDM_OUT_CON4_CLOCK_SHIFT;
10762babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_OUT2_Clock_Source")) {
10772babb477STrevor Wu reg = ETDM_OUT2_CON4;
10782babb477STrevor Wu mask = ETDM_OUT_CON4_CLOCK_MASK;
10792babb477STrevor Wu shift = ETDM_OUT_CON4_CLOCK_SHIFT;
10802babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_OUT3_Clock_Source")) {
10812babb477STrevor Wu reg = ETDM_OUT3_CON4;
10822babb477STrevor Wu mask = ETDM_OUT_CON4_CLOCK_MASK;
10832babb477STrevor Wu shift = ETDM_OUT_CON4_CLOCK_SHIFT;
10842babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_IN1_Clock_Source")) {
10852babb477STrevor Wu reg = ETDM_IN1_CON2;
10862babb477STrevor Wu mask = ETDM_IN_CON2_CLOCK_MASK;
10872babb477STrevor Wu shift = ETDM_IN_CON2_CLOCK_SHIFT;
10882babb477STrevor Wu } else if (!strcmp(kcontrol->id.name, "ETDM_IN2_Clock_Source")) {
10892babb477STrevor Wu reg = ETDM_IN2_CON2;
10902babb477STrevor Wu mask = ETDM_IN_CON2_CLOCK_MASK;
10912babb477STrevor Wu shift = ETDM_IN_CON2_CLOCK_SHIFT;
10922babb477STrevor Wu } else {
10932babb477STrevor Wu return -EINVAL;
10942babb477STrevor Wu }
10952babb477STrevor Wu
10962babb477STrevor Wu regmap_read(afe->regmap, reg, &value);
10972babb477STrevor Wu
10982babb477STrevor Wu value &= mask;
10992babb477STrevor Wu value >>= shift;
11002babb477STrevor Wu ucontrol->value.enumerated.item[0] = value;
11012babb477STrevor Wu return 0;
11022babb477STrevor Wu }
11032babb477STrevor Wu
11042babb477STrevor Wu static const struct snd_kcontrol_new mtk_dai_etdm_controls[] = {
11052babb477STrevor Wu SOC_ENUM_EXT("ETDM_OUT1_Clock_Source", etdmout_clk_src_enum,
11062babb477STrevor Wu mt8188_etdm_clk_src_sel_get,
11072babb477STrevor Wu mt8188_etdm_clk_src_sel_put),
11082babb477STrevor Wu SOC_ENUM_EXT("ETDM_OUT2_Clock_Source", etdmout_clk_src_enum,
11092babb477STrevor Wu mt8188_etdm_clk_src_sel_get,
11102babb477STrevor Wu mt8188_etdm_clk_src_sel_put),
11112babb477STrevor Wu SOC_ENUM_EXT("ETDM_OUT3_Clock_Source", etdmout_clk_src_enum,
11122babb477STrevor Wu mt8188_etdm_clk_src_sel_get,
11132babb477STrevor Wu mt8188_etdm_clk_src_sel_put),
11142babb477STrevor Wu SOC_ENUM_EXT("ETDM_IN1_Clock_Source", etdmout_clk_src_enum,
11152babb477STrevor Wu mt8188_etdm_clk_src_sel_get,
11162babb477STrevor Wu mt8188_etdm_clk_src_sel_put),
11172babb477STrevor Wu SOC_ENUM_EXT("ETDM_IN2_Clock_Source", etdmout_clk_src_enum,
11182babb477STrevor Wu mt8188_etdm_clk_src_sel_get,
11192babb477STrevor Wu mt8188_etdm_clk_src_sel_put),
11202babb477STrevor Wu };
11212babb477STrevor Wu
11222babb477STrevor Wu static const struct snd_soc_dapm_widget mtk_dai_etdm_widgets[] = {
11232babb477STrevor Wu /* eTDM_IN2 */
11242babb477STrevor Wu SND_SOC_DAPM_MIXER("I012", SND_SOC_NOPM, 0, 0, NULL, 0),
11252babb477STrevor Wu SND_SOC_DAPM_MIXER("I013", SND_SOC_NOPM, 0, 0, NULL, 0),
11262babb477STrevor Wu SND_SOC_DAPM_MIXER("I014", SND_SOC_NOPM, 0, 0, NULL, 0),
11272babb477STrevor Wu SND_SOC_DAPM_MIXER("I015", SND_SOC_NOPM, 0, 0, NULL, 0),
11282babb477STrevor Wu SND_SOC_DAPM_MIXER("I016", SND_SOC_NOPM, 0, 0, NULL, 0),
11292babb477STrevor Wu SND_SOC_DAPM_MIXER("I017", SND_SOC_NOPM, 0, 0, NULL, 0),
11302babb477STrevor Wu SND_SOC_DAPM_MIXER("I018", SND_SOC_NOPM, 0, 0, NULL, 0),
11312babb477STrevor Wu SND_SOC_DAPM_MIXER("I019", SND_SOC_NOPM, 0, 0, NULL, 0),
11322babb477STrevor Wu SND_SOC_DAPM_MIXER("I188", SND_SOC_NOPM, 0, 0, NULL, 0),
11332babb477STrevor Wu SND_SOC_DAPM_MIXER("I189", SND_SOC_NOPM, 0, 0, NULL, 0),
11342babb477STrevor Wu SND_SOC_DAPM_MIXER("I190", SND_SOC_NOPM, 0, 0, NULL, 0),
11352babb477STrevor Wu SND_SOC_DAPM_MIXER("I191", SND_SOC_NOPM, 0, 0, NULL, 0),
11362babb477STrevor Wu SND_SOC_DAPM_MIXER("I192", SND_SOC_NOPM, 0, 0, NULL, 0),
11372babb477STrevor Wu SND_SOC_DAPM_MIXER("I193", SND_SOC_NOPM, 0, 0, NULL, 0),
11382babb477STrevor Wu SND_SOC_DAPM_MIXER("I194", SND_SOC_NOPM, 0, 0, NULL, 0),
11392babb477STrevor Wu SND_SOC_DAPM_MIXER("I195", SND_SOC_NOPM, 0, 0, NULL, 0),
11402babb477STrevor Wu
11412babb477STrevor Wu /* eTDM_IN1 */
11422babb477STrevor Wu SND_SOC_DAPM_MIXER("I072", SND_SOC_NOPM, 0, 0, NULL, 0),
11432babb477STrevor Wu SND_SOC_DAPM_MIXER("I073", SND_SOC_NOPM, 0, 0, NULL, 0),
11442babb477STrevor Wu SND_SOC_DAPM_MIXER("I074", SND_SOC_NOPM, 0, 0, NULL, 0),
11452babb477STrevor Wu SND_SOC_DAPM_MIXER("I075", SND_SOC_NOPM, 0, 0, NULL, 0),
11462babb477STrevor Wu SND_SOC_DAPM_MIXER("I076", SND_SOC_NOPM, 0, 0, NULL, 0),
11472babb477STrevor Wu SND_SOC_DAPM_MIXER("I077", SND_SOC_NOPM, 0, 0, NULL, 0),
11482babb477STrevor Wu SND_SOC_DAPM_MIXER("I078", SND_SOC_NOPM, 0, 0, NULL, 0),
11492babb477STrevor Wu SND_SOC_DAPM_MIXER("I079", SND_SOC_NOPM, 0, 0, NULL, 0),
11502babb477STrevor Wu SND_SOC_DAPM_MIXER("I080", SND_SOC_NOPM, 0, 0, NULL, 0),
11512babb477STrevor Wu SND_SOC_DAPM_MIXER("I081", SND_SOC_NOPM, 0, 0, NULL, 0),
11522babb477STrevor Wu SND_SOC_DAPM_MIXER("I082", SND_SOC_NOPM, 0, 0, NULL, 0),
11532babb477STrevor Wu SND_SOC_DAPM_MIXER("I083", SND_SOC_NOPM, 0, 0, NULL, 0),
11542babb477STrevor Wu SND_SOC_DAPM_MIXER("I084", SND_SOC_NOPM, 0, 0, NULL, 0),
11552babb477STrevor Wu SND_SOC_DAPM_MIXER("I085", SND_SOC_NOPM, 0, 0, NULL, 0),
11562babb477STrevor Wu SND_SOC_DAPM_MIXER("I086", SND_SOC_NOPM, 0, 0, NULL, 0),
11572babb477STrevor Wu SND_SOC_DAPM_MIXER("I087", SND_SOC_NOPM, 0, 0, NULL, 0),
11582babb477STrevor Wu
11592babb477STrevor Wu /* eTDM_OUT2 */
11602babb477STrevor Wu SND_SOC_DAPM_MIXER("O048", SND_SOC_NOPM, 0, 0,
11612babb477STrevor Wu mtk_dai_etdm_o048_mix, ARRAY_SIZE(mtk_dai_etdm_o048_mix)),
11622babb477STrevor Wu SND_SOC_DAPM_MIXER("O049", SND_SOC_NOPM, 0, 0,
11632babb477STrevor Wu mtk_dai_etdm_o049_mix, ARRAY_SIZE(mtk_dai_etdm_o049_mix)),
11642babb477STrevor Wu SND_SOC_DAPM_MIXER("O050", SND_SOC_NOPM, 0, 0,
11652babb477STrevor Wu mtk_dai_etdm_o050_mix, ARRAY_SIZE(mtk_dai_etdm_o050_mix)),
11662babb477STrevor Wu SND_SOC_DAPM_MIXER("O051", SND_SOC_NOPM, 0, 0,
11672babb477STrevor Wu mtk_dai_etdm_o051_mix, ARRAY_SIZE(mtk_dai_etdm_o051_mix)),
11682babb477STrevor Wu SND_SOC_DAPM_MIXER("O052", SND_SOC_NOPM, 0, 0,
11692babb477STrevor Wu mtk_dai_etdm_o052_mix, ARRAY_SIZE(mtk_dai_etdm_o052_mix)),
11702babb477STrevor Wu SND_SOC_DAPM_MIXER("O053", SND_SOC_NOPM, 0, 0,
11712babb477STrevor Wu mtk_dai_etdm_o053_mix, ARRAY_SIZE(mtk_dai_etdm_o053_mix)),
11722babb477STrevor Wu SND_SOC_DAPM_MIXER("O054", SND_SOC_NOPM, 0, 0,
11732babb477STrevor Wu mtk_dai_etdm_o054_mix, ARRAY_SIZE(mtk_dai_etdm_o054_mix)),
11742babb477STrevor Wu SND_SOC_DAPM_MIXER("O055", SND_SOC_NOPM, 0, 0,
11752babb477STrevor Wu mtk_dai_etdm_o055_mix, ARRAY_SIZE(mtk_dai_etdm_o055_mix)),
11762babb477STrevor Wu SND_SOC_DAPM_MIXER("O056", SND_SOC_NOPM, 0, 0,
11772babb477STrevor Wu mtk_dai_etdm_o056_mix, ARRAY_SIZE(mtk_dai_etdm_o056_mix)),
11782babb477STrevor Wu SND_SOC_DAPM_MIXER("O057", SND_SOC_NOPM, 0, 0,
11792babb477STrevor Wu mtk_dai_etdm_o057_mix, ARRAY_SIZE(mtk_dai_etdm_o057_mix)),
11802babb477STrevor Wu SND_SOC_DAPM_MIXER("O058", SND_SOC_NOPM, 0, 0,
11812babb477STrevor Wu mtk_dai_etdm_o058_mix, ARRAY_SIZE(mtk_dai_etdm_o058_mix)),
11822babb477STrevor Wu SND_SOC_DAPM_MIXER("O059", SND_SOC_NOPM, 0, 0,
11832babb477STrevor Wu mtk_dai_etdm_o059_mix, ARRAY_SIZE(mtk_dai_etdm_o059_mix)),
11842babb477STrevor Wu SND_SOC_DAPM_MIXER("O060", SND_SOC_NOPM, 0, 0,
11852babb477STrevor Wu mtk_dai_etdm_o060_mix, ARRAY_SIZE(mtk_dai_etdm_o060_mix)),
11862babb477STrevor Wu SND_SOC_DAPM_MIXER("O061", SND_SOC_NOPM, 0, 0,
11872babb477STrevor Wu mtk_dai_etdm_o061_mix, ARRAY_SIZE(mtk_dai_etdm_o061_mix)),
11882babb477STrevor Wu SND_SOC_DAPM_MIXER("O062", SND_SOC_NOPM, 0, 0,
11892babb477STrevor Wu mtk_dai_etdm_o062_mix, ARRAY_SIZE(mtk_dai_etdm_o062_mix)),
11902babb477STrevor Wu SND_SOC_DAPM_MIXER("O063", SND_SOC_NOPM, 0, 0,
11912babb477STrevor Wu mtk_dai_etdm_o063_mix, ARRAY_SIZE(mtk_dai_etdm_o063_mix)),
11922babb477STrevor Wu
11932babb477STrevor Wu /* eTDM_OUT1 */
11942babb477STrevor Wu SND_SOC_DAPM_MIXER("O072", SND_SOC_NOPM, 0, 0,
11952babb477STrevor Wu mtk_dai_etdm_o072_mix, ARRAY_SIZE(mtk_dai_etdm_o072_mix)),
11962babb477STrevor Wu SND_SOC_DAPM_MIXER("O073", SND_SOC_NOPM, 0, 0,
11972babb477STrevor Wu mtk_dai_etdm_o073_mix, ARRAY_SIZE(mtk_dai_etdm_o073_mix)),
11982babb477STrevor Wu SND_SOC_DAPM_MIXER("O074", SND_SOC_NOPM, 0, 0,
11992babb477STrevor Wu mtk_dai_etdm_o074_mix, ARRAY_SIZE(mtk_dai_etdm_o074_mix)),
12002babb477STrevor Wu SND_SOC_DAPM_MIXER("O075", SND_SOC_NOPM, 0, 0,
12012babb477STrevor Wu mtk_dai_etdm_o075_mix, ARRAY_SIZE(mtk_dai_etdm_o075_mix)),
12022babb477STrevor Wu SND_SOC_DAPM_MIXER("O076", SND_SOC_NOPM, 0, 0,
12032babb477STrevor Wu mtk_dai_etdm_o076_mix, ARRAY_SIZE(mtk_dai_etdm_o076_mix)),
12042babb477STrevor Wu SND_SOC_DAPM_MIXER("O077", SND_SOC_NOPM, 0, 0,
12052babb477STrevor Wu mtk_dai_etdm_o077_mix, ARRAY_SIZE(mtk_dai_etdm_o077_mix)),
12062babb477STrevor Wu SND_SOC_DAPM_MIXER("O078", SND_SOC_NOPM, 0, 0,
12072babb477STrevor Wu mtk_dai_etdm_o078_mix, ARRAY_SIZE(mtk_dai_etdm_o078_mix)),
12082babb477STrevor Wu SND_SOC_DAPM_MIXER("O079", SND_SOC_NOPM, 0, 0,
12092babb477STrevor Wu mtk_dai_etdm_o079_mix, ARRAY_SIZE(mtk_dai_etdm_o079_mix)),
12102babb477STrevor Wu SND_SOC_DAPM_MIXER("O080", SND_SOC_NOPM, 0, 0,
12112babb477STrevor Wu mtk_dai_etdm_o080_mix, ARRAY_SIZE(mtk_dai_etdm_o080_mix)),
12122babb477STrevor Wu SND_SOC_DAPM_MIXER("O081", SND_SOC_NOPM, 0, 0,
12132babb477STrevor Wu mtk_dai_etdm_o081_mix, ARRAY_SIZE(mtk_dai_etdm_o081_mix)),
12142babb477STrevor Wu SND_SOC_DAPM_MIXER("O082", SND_SOC_NOPM, 0, 0,
12152babb477STrevor Wu mtk_dai_etdm_o082_mix, ARRAY_SIZE(mtk_dai_etdm_o082_mix)),
12162babb477STrevor Wu SND_SOC_DAPM_MIXER("O083", SND_SOC_NOPM, 0, 0,
12172babb477STrevor Wu mtk_dai_etdm_o083_mix, ARRAY_SIZE(mtk_dai_etdm_o083_mix)),
12182babb477STrevor Wu SND_SOC_DAPM_MIXER("O084", SND_SOC_NOPM, 0, 0,
12192babb477STrevor Wu mtk_dai_etdm_o084_mix, ARRAY_SIZE(mtk_dai_etdm_o084_mix)),
12202babb477STrevor Wu SND_SOC_DAPM_MIXER("O085", SND_SOC_NOPM, 0, 0,
12212babb477STrevor Wu mtk_dai_etdm_o085_mix, ARRAY_SIZE(mtk_dai_etdm_o085_mix)),
12222babb477STrevor Wu SND_SOC_DAPM_MIXER("O086", SND_SOC_NOPM, 0, 0,
12232babb477STrevor Wu mtk_dai_etdm_o086_mix, ARRAY_SIZE(mtk_dai_etdm_o086_mix)),
12242babb477STrevor Wu SND_SOC_DAPM_MIXER("O087", SND_SOC_NOPM, 0, 0,
12252babb477STrevor Wu mtk_dai_etdm_o087_mix, ARRAY_SIZE(mtk_dai_etdm_o087_mix)),
12262babb477STrevor Wu
12272babb477STrevor Wu /* eTDM_OUT3 */
12282babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_OUT_MUX", SND_SOC_NOPM, 0, 0,
12292babb477STrevor Wu &hdmi_out_mux_control),
12302babb477STrevor Wu SND_SOC_DAPM_MUX("DPTX_OUT_MUX", SND_SOC_NOPM, 0, 0,
12312babb477STrevor Wu &dptx_out_mux_control),
12322babb477STrevor Wu
12332babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH0_MUX", SND_SOC_NOPM, 0, 0,
12342babb477STrevor Wu &hdmi_ch0_mux_control),
12352babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH1_MUX", SND_SOC_NOPM, 0, 0,
12362babb477STrevor Wu &hdmi_ch1_mux_control),
12372babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH2_MUX", SND_SOC_NOPM, 0, 0,
12382babb477STrevor Wu &hdmi_ch2_mux_control),
12392babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH3_MUX", SND_SOC_NOPM, 0, 0,
12402babb477STrevor Wu &hdmi_ch3_mux_control),
12412babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH4_MUX", SND_SOC_NOPM, 0, 0,
12422babb477STrevor Wu &hdmi_ch4_mux_control),
12432babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH5_MUX", SND_SOC_NOPM, 0, 0,
12442babb477STrevor Wu &hdmi_ch5_mux_control),
12452babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH6_MUX", SND_SOC_NOPM, 0, 0,
12462babb477STrevor Wu &hdmi_ch6_mux_control),
12472babb477STrevor Wu SND_SOC_DAPM_MUX("HDMI_CH7_MUX", SND_SOC_NOPM, 0, 0,
12482babb477STrevor Wu &hdmi_ch7_mux_control),
12492babb477STrevor Wu
1250e5d2bd41STrevor Wu /* mclk en */
1251e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM1_IN_MCLK", SUPPLY_SEQ_ETDM_MCLK,
1252e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1253e5d2bd41STrevor Wu mtk_etdm_mclk_event,
1254e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1255e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM2_IN_MCLK", SUPPLY_SEQ_ETDM_MCLK,
1256e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1257e5d2bd41STrevor Wu mtk_etdm_mclk_event,
1258e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1259e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM1_OUT_MCLK", SUPPLY_SEQ_ETDM_MCLK,
1260e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1261e5d2bd41STrevor Wu mtk_etdm_mclk_event,
1262e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1263e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM2_OUT_MCLK", SUPPLY_SEQ_ETDM_MCLK,
1264e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1265e5d2bd41STrevor Wu mtk_etdm_mclk_event,
1266e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1267e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("DPTX_MCLK", SUPPLY_SEQ_ETDM_MCLK,
1268e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1269e5d2bd41STrevor Wu mtk_dptx_mclk_event,
1270e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1271e5d2bd41STrevor Wu
1272e5d2bd41STrevor Wu /* cg */
1273e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM1_IN_CG", SUPPLY_SEQ_ETDM_CG,
1274e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1275e5d2bd41STrevor Wu mtk_etdm_cg_event,
1276e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1277e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM2_IN_CG", SUPPLY_SEQ_ETDM_CG,
1278e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1279e5d2bd41STrevor Wu mtk_etdm_cg_event,
1280e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1281e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM1_OUT_CG", SUPPLY_SEQ_ETDM_CG,
1282e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1283e5d2bd41STrevor Wu mtk_etdm_cg_event,
1284e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1285e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM2_OUT_CG", SUPPLY_SEQ_ETDM_CG,
1286e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1287e5d2bd41STrevor Wu mtk_etdm_cg_event,
1288e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1289e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM3_OUT_CG", SUPPLY_SEQ_ETDM_CG,
1290e5d2bd41STrevor Wu SND_SOC_NOPM, 0, 0,
1291e5d2bd41STrevor Wu mtk_etdm3_cg_event,
1292e5d2bd41STrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1293e5d2bd41STrevor Wu
1294e5d2bd41STrevor Wu /* en */
1295e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM1_IN_EN", SUPPLY_SEQ_ETDM_EN,
1296e5d2bd41STrevor Wu ETDM_IN1_CON0, ETDM_CON0_EN_SHIFT, 0, NULL, 0),
1297e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM2_IN_EN", SUPPLY_SEQ_ETDM_EN,
1298e5d2bd41STrevor Wu ETDM_IN2_CON0, ETDM_CON0_EN_SHIFT, 0, NULL, 0),
1299e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM1_OUT_EN", SUPPLY_SEQ_ETDM_EN,
1300e5d2bd41STrevor Wu ETDM_OUT1_CON0, ETDM_CON0_EN_SHIFT, 0, NULL, 0),
1301e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM2_OUT_EN", SUPPLY_SEQ_ETDM_EN,
1302e5d2bd41STrevor Wu ETDM_OUT2_CON0, ETDM_CON0_EN_SHIFT, 0, NULL, 0),
1303e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("ETDM3_OUT_EN", SUPPLY_SEQ_ETDM_EN,
1304e5d2bd41STrevor Wu ETDM_OUT3_CON0, ETDM_CON0_EN_SHIFT, 0, NULL, 0),
1305e5d2bd41STrevor Wu SND_SOC_DAPM_SUPPLY_S("DPTX_EN", SUPPLY_SEQ_DPTX_EN,
1306e5d2bd41STrevor Wu AFE_DPTX_CON, AFE_DPTX_CON_ON_SHIFT, 0, NULL, 0),
1307e5d2bd41STrevor Wu
13089be0213aSTrevor Wu /* apll */
13099be0213aSTrevor Wu SND_SOC_DAPM_SUPPLY_S(APLL1_W_NAME, SUPPLY_SEQ_APLL,
13109be0213aSTrevor Wu SND_SOC_NOPM, 0, 0,
13119be0213aSTrevor Wu mtk_apll_event,
13129be0213aSTrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
13139be0213aSTrevor Wu SND_SOC_DAPM_SUPPLY_S(APLL2_W_NAME, SUPPLY_SEQ_APLL,
13149be0213aSTrevor Wu SND_SOC_NOPM, 0, 0,
13159be0213aSTrevor Wu mtk_apll_event,
13169be0213aSTrevor Wu SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
13179be0213aSTrevor Wu
13182babb477STrevor Wu SND_SOC_DAPM_INPUT("ETDM_INPUT"),
13192babb477STrevor Wu SND_SOC_DAPM_OUTPUT("ETDM_OUTPUT"),
13202babb477STrevor Wu };
13212babb477STrevor Wu
13222babb477STrevor Wu static const struct snd_soc_dapm_route mtk_dai_etdm_routes[] = {
1323e5d2bd41STrevor Wu /* mclk */
1324e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM1_IN_MCLK", mtk_etdm_mclk_connect},
1325e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM2_IN_MCLK", mtk_etdm_mclk_connect},
1326e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM1_OUT_MCLK", mtk_etdm_mclk_connect},
1327e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM2_OUT_MCLK", mtk_etdm_mclk_connect},
1328e5d2bd41STrevor Wu
1329e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM1_IN_MCLK", mtk_etdm_mclk_connect},
1330e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM2_IN_MCLK", mtk_etdm_mclk_connect},
1331e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM1_OUT_MCLK", mtk_etdm_mclk_connect},
1332e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM2_OUT_MCLK", mtk_etdm_mclk_connect},
1333e5d2bd41STrevor Wu
1334e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM1_IN_MCLK", mtk_etdm_mclk_connect},
1335e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM2_IN_MCLK", mtk_etdm_mclk_connect},
1336e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM1_OUT_MCLK", mtk_etdm_mclk_connect},
1337e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM2_OUT_MCLK", mtk_etdm_mclk_connect},
1338e5d2bd41STrevor Wu
1339e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM1_IN_MCLK", mtk_etdm_mclk_connect},
1340e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM2_IN_MCLK", mtk_etdm_mclk_connect},
1341e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM1_OUT_MCLK", mtk_etdm_mclk_connect},
1342e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM2_OUT_MCLK", mtk_etdm_mclk_connect},
1343e5d2bd41STrevor Wu
1344e5d2bd41STrevor Wu {"DPTX", NULL, "DPTX_MCLK"},
1345e5d2bd41STrevor Wu
13469be0213aSTrevor Wu {"ETDM1_IN_MCLK", NULL, APLL1_W_NAME, mtk_afe_mclk_apll_connect},
13479be0213aSTrevor Wu {"ETDM1_IN_MCLK", NULL, APLL2_W_NAME, mtk_afe_mclk_apll_connect},
13489be0213aSTrevor Wu
13499be0213aSTrevor Wu {"ETDM2_IN_MCLK", NULL, APLL1_W_NAME, mtk_afe_mclk_apll_connect},
13509be0213aSTrevor Wu {"ETDM2_IN_MCLK", NULL, APLL2_W_NAME, mtk_afe_mclk_apll_connect},
13519be0213aSTrevor Wu
13529be0213aSTrevor Wu {"ETDM1_OUT_MCLK", NULL, APLL1_W_NAME, mtk_afe_mclk_apll_connect},
13539be0213aSTrevor Wu {"ETDM1_OUT_MCLK", NULL, APLL2_W_NAME, mtk_afe_mclk_apll_connect},
13549be0213aSTrevor Wu
13559be0213aSTrevor Wu {"ETDM2_OUT_MCLK", NULL, APLL1_W_NAME, mtk_afe_mclk_apll_connect},
13569be0213aSTrevor Wu {"ETDM2_OUT_MCLK", NULL, APLL2_W_NAME, mtk_afe_mclk_apll_connect},
13579be0213aSTrevor Wu
13589be0213aSTrevor Wu {"DPTX_MCLK", NULL, APLL1_W_NAME, mtk_afe_mclk_apll_connect},
13599be0213aSTrevor Wu {"DPTX_MCLK", NULL, APLL2_W_NAME, mtk_afe_mclk_apll_connect},
13609be0213aSTrevor Wu
1361e5d2bd41STrevor Wu /* cg */
1362e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM1_IN_CG"},
1363e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM2_IN_CG", mtk_etdm_cowork_connect},
1364e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM1_OUT_CG", mtk_etdm_cowork_connect},
1365e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM2_OUT_CG", mtk_etdm_cowork_connect},
1366e5d2bd41STrevor Wu
1367e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM1_IN_CG", mtk_etdm_cowork_connect},
1368e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM2_IN_CG"},
1369e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM1_OUT_CG", mtk_etdm_cowork_connect},
1370e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM2_OUT_CG", mtk_etdm_cowork_connect},
1371e5d2bd41STrevor Wu
1372e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM1_IN_CG", mtk_etdm_cowork_connect},
1373e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM2_IN_CG", mtk_etdm_cowork_connect},
1374e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM1_OUT_CG"},
1375e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM2_OUT_CG", mtk_etdm_cowork_connect},
1376e5d2bd41STrevor Wu
1377e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM1_IN_CG", mtk_etdm_cowork_connect},
1378e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM2_IN_CG", mtk_etdm_cowork_connect},
1379e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM1_OUT_CG", mtk_etdm_cowork_connect},
1380e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM2_OUT_CG"},
1381e5d2bd41STrevor Wu
1382e5d2bd41STrevor Wu {"ETDM3_OUT", NULL, "ETDM3_OUT_CG"},
1383e5d2bd41STrevor Wu {"DPTX", NULL, "ETDM3_OUT_CG"},
1384e5d2bd41STrevor Wu
1385e5d2bd41STrevor Wu /* en */
1386e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM1_IN_EN"},
1387e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM2_IN_EN", mtk_etdm_cowork_connect},
1388e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM1_OUT_EN", mtk_etdm_cowork_connect},
1389e5d2bd41STrevor Wu {"ETDM1_IN", NULL, "ETDM2_OUT_EN", mtk_etdm_cowork_connect},
1390e5d2bd41STrevor Wu
1391e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM1_IN_EN", mtk_etdm_cowork_connect},
1392e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM2_IN_EN"},
1393e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM1_OUT_EN", mtk_etdm_cowork_connect},
1394e5d2bd41STrevor Wu {"ETDM2_IN", NULL, "ETDM2_OUT_EN", mtk_etdm_cowork_connect},
1395e5d2bd41STrevor Wu
1396e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM1_IN_EN", mtk_etdm_cowork_connect},
1397e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM2_IN_EN", mtk_etdm_cowork_connect},
1398e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM1_OUT_EN"},
1399e5d2bd41STrevor Wu {"ETDM1_OUT", NULL, "ETDM2_OUT_EN", mtk_etdm_cowork_connect},
1400e5d2bd41STrevor Wu
1401e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM1_IN_EN", mtk_etdm_cowork_connect},
1402e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM2_IN_EN", mtk_etdm_cowork_connect},
1403e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM1_OUT_EN", mtk_etdm_cowork_connect},
1404e5d2bd41STrevor Wu {"ETDM2_OUT", NULL, "ETDM2_OUT_EN"},
1405e5d2bd41STrevor Wu
1406e5d2bd41STrevor Wu {"ETDM3_OUT", NULL, "ETDM3_OUT_EN"},
1407e5d2bd41STrevor Wu {"DPTX", NULL, "ETDM3_OUT_EN"},
1408e5d2bd41STrevor Wu {"DPTX", NULL, "DPTX_EN"},
1409e5d2bd41STrevor Wu
14109be0213aSTrevor Wu {"ETDM1_IN_EN", NULL, APLL1_W_NAME, mtk_afe_etdm_apll_connect},
14119be0213aSTrevor Wu {"ETDM1_IN_EN", NULL, APLL2_W_NAME, mtk_afe_etdm_apll_connect},
14129be0213aSTrevor Wu
14139be0213aSTrevor Wu {"ETDM2_IN_EN", NULL, APLL1_W_NAME, mtk_afe_etdm_apll_connect},
14149be0213aSTrevor Wu {"ETDM2_IN_EN", NULL, APLL2_W_NAME, mtk_afe_etdm_apll_connect},
14159be0213aSTrevor Wu
14169be0213aSTrevor Wu {"ETDM1_OUT_EN", NULL, APLL1_W_NAME, mtk_afe_etdm_apll_connect},
14179be0213aSTrevor Wu {"ETDM1_OUT_EN", NULL, APLL2_W_NAME, mtk_afe_etdm_apll_connect},
14189be0213aSTrevor Wu
14199be0213aSTrevor Wu {"ETDM2_OUT_EN", NULL, APLL1_W_NAME, mtk_afe_etdm_apll_connect},
14209be0213aSTrevor Wu {"ETDM2_OUT_EN", NULL, APLL2_W_NAME, mtk_afe_etdm_apll_connect},
14219be0213aSTrevor Wu
14229be0213aSTrevor Wu {"ETDM3_OUT_EN", NULL, APLL1_W_NAME, mtk_afe_etdm_apll_connect},
14239be0213aSTrevor Wu {"ETDM3_OUT_EN", NULL, APLL2_W_NAME, mtk_afe_etdm_apll_connect},
14249be0213aSTrevor Wu
14252babb477STrevor Wu {"I012", NULL, "ETDM2_IN"},
14262babb477STrevor Wu {"I013", NULL, "ETDM2_IN"},
14272babb477STrevor Wu {"I014", NULL, "ETDM2_IN"},
14282babb477STrevor Wu {"I015", NULL, "ETDM2_IN"},
14292babb477STrevor Wu {"I016", NULL, "ETDM2_IN"},
14302babb477STrevor Wu {"I017", NULL, "ETDM2_IN"},
14312babb477STrevor Wu {"I018", NULL, "ETDM2_IN"},
14322babb477STrevor Wu {"I019", NULL, "ETDM2_IN"},
14332babb477STrevor Wu {"I188", NULL, "ETDM2_IN"},
14342babb477STrevor Wu {"I189", NULL, "ETDM2_IN"},
14352babb477STrevor Wu {"I190", NULL, "ETDM2_IN"},
14362babb477STrevor Wu {"I191", NULL, "ETDM2_IN"},
14372babb477STrevor Wu {"I192", NULL, "ETDM2_IN"},
14382babb477STrevor Wu {"I193", NULL, "ETDM2_IN"},
14392babb477STrevor Wu {"I194", NULL, "ETDM2_IN"},
14402babb477STrevor Wu {"I195", NULL, "ETDM2_IN"},
14412babb477STrevor Wu
14422babb477STrevor Wu {"I072", NULL, "ETDM1_IN"},
14432babb477STrevor Wu {"I073", NULL, "ETDM1_IN"},
14442babb477STrevor Wu {"I074", NULL, "ETDM1_IN"},
14452babb477STrevor Wu {"I075", NULL, "ETDM1_IN"},
14462babb477STrevor Wu {"I076", NULL, "ETDM1_IN"},
14472babb477STrevor Wu {"I077", NULL, "ETDM1_IN"},
14482babb477STrevor Wu {"I078", NULL, "ETDM1_IN"},
14492babb477STrevor Wu {"I079", NULL, "ETDM1_IN"},
14502babb477STrevor Wu {"I080", NULL, "ETDM1_IN"},
14512babb477STrevor Wu {"I081", NULL, "ETDM1_IN"},
14522babb477STrevor Wu {"I082", NULL, "ETDM1_IN"},
14532babb477STrevor Wu {"I083", NULL, "ETDM1_IN"},
14542babb477STrevor Wu {"I084", NULL, "ETDM1_IN"},
14552babb477STrevor Wu {"I085", NULL, "ETDM1_IN"},
14562babb477STrevor Wu {"I086", NULL, "ETDM1_IN"},
14572babb477STrevor Wu {"I087", NULL, "ETDM1_IN"},
14582babb477STrevor Wu
14592babb477STrevor Wu {"UL8", NULL, "ETDM1_IN"},
14602babb477STrevor Wu {"UL3", NULL, "ETDM2_IN"},
14612babb477STrevor Wu
14622babb477STrevor Wu {"ETDM2_OUT", NULL, "O048"},
14632babb477STrevor Wu {"ETDM2_OUT", NULL, "O049"},
14642babb477STrevor Wu {"ETDM2_OUT", NULL, "O050"},
14652babb477STrevor Wu {"ETDM2_OUT", NULL, "O051"},
14662babb477STrevor Wu {"ETDM2_OUT", NULL, "O052"},
14672babb477STrevor Wu {"ETDM2_OUT", NULL, "O053"},
14682babb477STrevor Wu {"ETDM2_OUT", NULL, "O054"},
14692babb477STrevor Wu {"ETDM2_OUT", NULL, "O055"},
14702babb477STrevor Wu {"ETDM2_OUT", NULL, "O056"},
14712babb477STrevor Wu {"ETDM2_OUT", NULL, "O057"},
14722babb477STrevor Wu {"ETDM2_OUT", NULL, "O058"},
14732babb477STrevor Wu {"ETDM2_OUT", NULL, "O059"},
14742babb477STrevor Wu {"ETDM2_OUT", NULL, "O060"},
14752babb477STrevor Wu {"ETDM2_OUT", NULL, "O061"},
14762babb477STrevor Wu {"ETDM2_OUT", NULL, "O062"},
14772babb477STrevor Wu {"ETDM2_OUT", NULL, "O063"},
14782babb477STrevor Wu
14792babb477STrevor Wu {"ETDM1_OUT", NULL, "O072"},
14802babb477STrevor Wu {"ETDM1_OUT", NULL, "O073"},
14812babb477STrevor Wu {"ETDM1_OUT", NULL, "O074"},
14822babb477STrevor Wu {"ETDM1_OUT", NULL, "O075"},
14832babb477STrevor Wu {"ETDM1_OUT", NULL, "O076"},
14842babb477STrevor Wu {"ETDM1_OUT", NULL, "O077"},
14852babb477STrevor Wu {"ETDM1_OUT", NULL, "O078"},
14862babb477STrevor Wu {"ETDM1_OUT", NULL, "O079"},
14872babb477STrevor Wu {"ETDM1_OUT", NULL, "O080"},
14882babb477STrevor Wu {"ETDM1_OUT", NULL, "O081"},
14892babb477STrevor Wu {"ETDM1_OUT", NULL, "O082"},
14902babb477STrevor Wu {"ETDM1_OUT", NULL, "O083"},
14912babb477STrevor Wu {"ETDM1_OUT", NULL, "O084"},
14922babb477STrevor Wu {"ETDM1_OUT", NULL, "O085"},
14932babb477STrevor Wu {"ETDM1_OUT", NULL, "O086"},
14942babb477STrevor Wu {"ETDM1_OUT", NULL, "O087"},
14952babb477STrevor Wu
14962babb477STrevor Wu {"O048", "I020 Switch", "I020"},
14972babb477STrevor Wu {"O049", "I021 Switch", "I021"},
14982babb477STrevor Wu
14992babb477STrevor Wu {"O048", "I022 Switch", "I022"},
15002babb477STrevor Wu {"O049", "I023 Switch", "I023"},
15012babb477STrevor Wu {"O050", "I024 Switch", "I024"},
15022babb477STrevor Wu {"O051", "I025 Switch", "I025"},
15032babb477STrevor Wu {"O052", "I026 Switch", "I026"},
15042babb477STrevor Wu {"O053", "I027 Switch", "I027"},
15052babb477STrevor Wu {"O054", "I028 Switch", "I028"},
15062babb477STrevor Wu {"O055", "I029 Switch", "I029"},
15072babb477STrevor Wu {"O056", "I030 Switch", "I030"},
15082babb477STrevor Wu {"O057", "I031 Switch", "I031"},
15092babb477STrevor Wu {"O058", "I032 Switch", "I032"},
15102babb477STrevor Wu {"O059", "I033 Switch", "I033"},
15112babb477STrevor Wu {"O060", "I034 Switch", "I034"},
15122babb477STrevor Wu {"O061", "I035 Switch", "I035"},
15132babb477STrevor Wu {"O062", "I036 Switch", "I036"},
15142babb477STrevor Wu {"O063", "I037 Switch", "I037"},
15152babb477STrevor Wu
15162babb477STrevor Wu {"O048", "I046 Switch", "I046"},
15172babb477STrevor Wu {"O049", "I047 Switch", "I047"},
15182babb477STrevor Wu {"O050", "I048 Switch", "I048"},
15192babb477STrevor Wu {"O051", "I049 Switch", "I049"},
15202babb477STrevor Wu {"O052", "I050 Switch", "I050"},
15212babb477STrevor Wu {"O053", "I051 Switch", "I051"},
15222babb477STrevor Wu {"O054", "I052 Switch", "I052"},
15232babb477STrevor Wu {"O055", "I053 Switch", "I053"},
15242babb477STrevor Wu {"O056", "I054 Switch", "I054"},
15252babb477STrevor Wu {"O057", "I055 Switch", "I055"},
15262babb477STrevor Wu {"O058", "I056 Switch", "I056"},
15272babb477STrevor Wu {"O059", "I057 Switch", "I057"},
15282babb477STrevor Wu {"O060", "I058 Switch", "I058"},
15292babb477STrevor Wu {"O061", "I059 Switch", "I059"},
15302babb477STrevor Wu {"O062", "I060 Switch", "I060"},
15312babb477STrevor Wu {"O063", "I061 Switch", "I061"},
15322babb477STrevor Wu
15332babb477STrevor Wu {"O048", "I070 Switch", "I070"},
15342babb477STrevor Wu {"O049", "I071 Switch", "I071"},
15352babb477STrevor Wu
15362babb477STrevor Wu {"O072", "I020 Switch", "I020"},
15372babb477STrevor Wu {"O073", "I021 Switch", "I021"},
15382babb477STrevor Wu
15392babb477STrevor Wu {"O072", "I022 Switch", "I022"},
15402babb477STrevor Wu {"O073", "I023 Switch", "I023"},
15412babb477STrevor Wu {"O074", "I024 Switch", "I024"},
15422babb477STrevor Wu {"O075", "I025 Switch", "I025"},
15432babb477STrevor Wu {"O076", "I026 Switch", "I026"},
15442babb477STrevor Wu {"O077", "I027 Switch", "I027"},
15452babb477STrevor Wu {"O078", "I028 Switch", "I028"},
15462babb477STrevor Wu {"O079", "I029 Switch", "I029"},
15472babb477STrevor Wu {"O080", "I030 Switch", "I030"},
15482babb477STrevor Wu {"O081", "I031 Switch", "I031"},
15492babb477STrevor Wu {"O082", "I032 Switch", "I032"},
15502babb477STrevor Wu {"O083", "I033 Switch", "I033"},
15512babb477STrevor Wu {"O084", "I034 Switch", "I034"},
15522babb477STrevor Wu {"O085", "I035 Switch", "I035"},
15532babb477STrevor Wu {"O086", "I036 Switch", "I036"},
15542babb477STrevor Wu {"O087", "I037 Switch", "I037"},
15552babb477STrevor Wu
15562babb477STrevor Wu {"O072", "I046 Switch", "I046"},
15572babb477STrevor Wu {"O073", "I047 Switch", "I047"},
15582babb477STrevor Wu {"O074", "I048 Switch", "I048"},
15592babb477STrevor Wu {"O075", "I049 Switch", "I049"},
15602babb477STrevor Wu {"O076", "I050 Switch", "I050"},
15612babb477STrevor Wu {"O077", "I051 Switch", "I051"},
15622babb477STrevor Wu {"O078", "I052 Switch", "I052"},
15632babb477STrevor Wu {"O079", "I053 Switch", "I053"},
15642babb477STrevor Wu {"O080", "I054 Switch", "I054"},
15652babb477STrevor Wu {"O081", "I055 Switch", "I055"},
15662babb477STrevor Wu {"O082", "I056 Switch", "I056"},
15672babb477STrevor Wu {"O083", "I057 Switch", "I057"},
15682babb477STrevor Wu {"O084", "I058 Switch", "I058"},
15692babb477STrevor Wu {"O085", "I059 Switch", "I059"},
15702babb477STrevor Wu {"O086", "I060 Switch", "I060"},
15712babb477STrevor Wu {"O087", "I061 Switch", "I061"},
15722babb477STrevor Wu
15732babb477STrevor Wu {"O072", "I070 Switch", "I070"},
15742babb477STrevor Wu {"O073", "I071 Switch", "I071"},
15752babb477STrevor Wu
15762babb477STrevor Wu {"HDMI_CH0_MUX", "CH0", "DL10"},
15772babb477STrevor Wu {"HDMI_CH0_MUX", "CH1", "DL10"},
15782babb477STrevor Wu {"HDMI_CH0_MUX", "CH2", "DL10"},
15792babb477STrevor Wu {"HDMI_CH0_MUX", "CH3", "DL10"},
15802babb477STrevor Wu {"HDMI_CH0_MUX", "CH4", "DL10"},
15812babb477STrevor Wu {"HDMI_CH0_MUX", "CH5", "DL10"},
15822babb477STrevor Wu {"HDMI_CH0_MUX", "CH6", "DL10"},
15832babb477STrevor Wu {"HDMI_CH0_MUX", "CH7", "DL10"},
15842babb477STrevor Wu
15852babb477STrevor Wu {"HDMI_CH1_MUX", "CH0", "DL10"},
15862babb477STrevor Wu {"HDMI_CH1_MUX", "CH1", "DL10"},
15872babb477STrevor Wu {"HDMI_CH1_MUX", "CH2", "DL10"},
15882babb477STrevor Wu {"HDMI_CH1_MUX", "CH3", "DL10"},
15892babb477STrevor Wu {"HDMI_CH1_MUX", "CH4", "DL10"},
15902babb477STrevor Wu {"HDMI_CH1_MUX", "CH5", "DL10"},
15912babb477STrevor Wu {"HDMI_CH1_MUX", "CH6", "DL10"},
15922babb477STrevor Wu {"HDMI_CH1_MUX", "CH7", "DL10"},
15932babb477STrevor Wu
15942babb477STrevor Wu {"HDMI_CH2_MUX", "CH0", "DL10"},
15952babb477STrevor Wu {"HDMI_CH2_MUX", "CH1", "DL10"},
15962babb477STrevor Wu {"HDMI_CH2_MUX", "CH2", "DL10"},
15972babb477STrevor Wu {"HDMI_CH2_MUX", "CH3", "DL10"},
15982babb477STrevor Wu {"HDMI_CH2_MUX", "CH4", "DL10"},
15992babb477STrevor Wu {"HDMI_CH2_MUX", "CH5", "DL10"},
16002babb477STrevor Wu {"HDMI_CH2_MUX", "CH6", "DL10"},
16012babb477STrevor Wu {"HDMI_CH2_MUX", "CH7", "DL10"},
16022babb477STrevor Wu
16032babb477STrevor Wu {"HDMI_CH3_MUX", "CH0", "DL10"},
16042babb477STrevor Wu {"HDMI_CH3_MUX", "CH1", "DL10"},
16052babb477STrevor Wu {"HDMI_CH3_MUX", "CH2", "DL10"},
16062babb477STrevor Wu {"HDMI_CH3_MUX", "CH3", "DL10"},
16072babb477STrevor Wu {"HDMI_CH3_MUX", "CH4", "DL10"},
16082babb477STrevor Wu {"HDMI_CH3_MUX", "CH5", "DL10"},
16092babb477STrevor Wu {"HDMI_CH3_MUX", "CH6", "DL10"},
16102babb477STrevor Wu {"HDMI_CH3_MUX", "CH7", "DL10"},
16112babb477STrevor Wu
16122babb477STrevor Wu {"HDMI_CH4_MUX", "CH0", "DL10"},
16132babb477STrevor Wu {"HDMI_CH4_MUX", "CH1", "DL10"},
16142babb477STrevor Wu {"HDMI_CH4_MUX", "CH2", "DL10"},
16152babb477STrevor Wu {"HDMI_CH4_MUX", "CH3", "DL10"},
16162babb477STrevor Wu {"HDMI_CH4_MUX", "CH4", "DL10"},
16172babb477STrevor Wu {"HDMI_CH4_MUX", "CH5", "DL10"},
16182babb477STrevor Wu {"HDMI_CH4_MUX", "CH6", "DL10"},
16192babb477STrevor Wu {"HDMI_CH4_MUX", "CH7", "DL10"},
16202babb477STrevor Wu
16212babb477STrevor Wu {"HDMI_CH5_MUX", "CH0", "DL10"},
16222babb477STrevor Wu {"HDMI_CH5_MUX", "CH1", "DL10"},
16232babb477STrevor Wu {"HDMI_CH5_MUX", "CH2", "DL10"},
16242babb477STrevor Wu {"HDMI_CH5_MUX", "CH3", "DL10"},
16252babb477STrevor Wu {"HDMI_CH5_MUX", "CH4", "DL10"},
16262babb477STrevor Wu {"HDMI_CH5_MUX", "CH5", "DL10"},
16272babb477STrevor Wu {"HDMI_CH5_MUX", "CH6", "DL10"},
16282babb477STrevor Wu {"HDMI_CH5_MUX", "CH7", "DL10"},
16292babb477STrevor Wu
16302babb477STrevor Wu {"HDMI_CH6_MUX", "CH0", "DL10"},
16312babb477STrevor Wu {"HDMI_CH6_MUX", "CH1", "DL10"},
16322babb477STrevor Wu {"HDMI_CH6_MUX", "CH2", "DL10"},
16332babb477STrevor Wu {"HDMI_CH6_MUX", "CH3", "DL10"},
16342babb477STrevor Wu {"HDMI_CH6_MUX", "CH4", "DL10"},
16352babb477STrevor Wu {"HDMI_CH6_MUX", "CH5", "DL10"},
16362babb477STrevor Wu {"HDMI_CH6_MUX", "CH6", "DL10"},
16372babb477STrevor Wu {"HDMI_CH6_MUX", "CH7", "DL10"},
16382babb477STrevor Wu
16392babb477STrevor Wu {"HDMI_CH7_MUX", "CH0", "DL10"},
16402babb477STrevor Wu {"HDMI_CH7_MUX", "CH1", "DL10"},
16412babb477STrevor Wu {"HDMI_CH7_MUX", "CH2", "DL10"},
16422babb477STrevor Wu {"HDMI_CH7_MUX", "CH3", "DL10"},
16432babb477STrevor Wu {"HDMI_CH7_MUX", "CH4", "DL10"},
16442babb477STrevor Wu {"HDMI_CH7_MUX", "CH5", "DL10"},
16452babb477STrevor Wu {"HDMI_CH7_MUX", "CH6", "DL10"},
16462babb477STrevor Wu {"HDMI_CH7_MUX", "CH7", "DL10"},
16472babb477STrevor Wu
16482babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH0_MUX"},
16492babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH1_MUX"},
16502babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH2_MUX"},
16512babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH3_MUX"},
16522babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH4_MUX"},
16532babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH5_MUX"},
16542babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH6_MUX"},
16552babb477STrevor Wu {"HDMI_OUT_MUX", "Connect", "HDMI_CH7_MUX"},
16562babb477STrevor Wu
16572babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH0_MUX"},
16582babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH1_MUX"},
16592babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH2_MUX"},
16602babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH3_MUX"},
16612babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH4_MUX"},
16622babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH5_MUX"},
16632babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH6_MUX"},
16642babb477STrevor Wu {"DPTX_OUT_MUX", "Connect", "HDMI_CH7_MUX"},
16652babb477STrevor Wu
16662babb477STrevor Wu {"ETDM3_OUT", NULL, "HDMI_OUT_MUX"},
16672babb477STrevor Wu {"DPTX", NULL, "DPTX_OUT_MUX"},
16682babb477STrevor Wu
16692babb477STrevor Wu {"ETDM_OUTPUT", NULL, "DPTX"},
16702babb477STrevor Wu {"ETDM_OUTPUT", NULL, "ETDM1_OUT"},
16712babb477STrevor Wu {"ETDM_OUTPUT", NULL, "ETDM2_OUT"},
16722babb477STrevor Wu {"ETDM_OUTPUT", NULL, "ETDM3_OUT"},
16732babb477STrevor Wu {"ETDM1_IN", NULL, "ETDM_INPUT"},
16742babb477STrevor Wu {"ETDM2_IN", NULL, "ETDM_INPUT"},
16752babb477STrevor Wu };
16762babb477STrevor Wu
etdm_cowork_slv_sel(int id,int slave_mode)16772babb477STrevor Wu static int etdm_cowork_slv_sel(int id, int slave_mode)
16782babb477STrevor Wu {
16792babb477STrevor Wu if (slave_mode) {
16802babb477STrevor Wu switch (id) {
16812babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
16822babb477STrevor Wu return COWORK_ETDM_IN1_S;
16832babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
16842babb477STrevor Wu return COWORK_ETDM_IN2_S;
16852babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
16862babb477STrevor Wu return COWORK_ETDM_OUT1_S;
16872babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
16882babb477STrevor Wu return COWORK_ETDM_OUT2_S;
16892babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
16902babb477STrevor Wu return COWORK_ETDM_OUT3_S;
16912babb477STrevor Wu default:
16922babb477STrevor Wu return -EINVAL;
16932babb477STrevor Wu }
16942babb477STrevor Wu } else {
16952babb477STrevor Wu switch (id) {
16962babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
16972babb477STrevor Wu return COWORK_ETDM_IN1_M;
16982babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
16992babb477STrevor Wu return COWORK_ETDM_IN2_M;
17002babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
17012babb477STrevor Wu return COWORK_ETDM_OUT1_M;
17022babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
17032babb477STrevor Wu return COWORK_ETDM_OUT2_M;
17042babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
17052babb477STrevor Wu return COWORK_ETDM_OUT3_M;
17062babb477STrevor Wu default:
17072babb477STrevor Wu return -EINVAL;
17082babb477STrevor Wu }
17092babb477STrevor Wu }
17102babb477STrevor Wu }
17112babb477STrevor Wu
etdm_cowork_sync_sel(int id)17122babb477STrevor Wu static int etdm_cowork_sync_sel(int id)
17132babb477STrevor Wu {
17142babb477STrevor Wu switch (id) {
17152babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
17162babb477STrevor Wu return ETDM_SYNC_FROM_IN1;
17172babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
17182babb477STrevor Wu return ETDM_SYNC_FROM_IN2;
17192babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
17202babb477STrevor Wu return ETDM_SYNC_FROM_OUT1;
17212babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
17222babb477STrevor Wu return ETDM_SYNC_FROM_OUT2;
17232babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
17242babb477STrevor Wu return ETDM_SYNC_FROM_OUT3;
17252babb477STrevor Wu default:
17262babb477STrevor Wu return -EINVAL;
17272babb477STrevor Wu }
17282babb477STrevor Wu }
17292babb477STrevor Wu
mt8188_etdm_sync_mode_slv(struct mtk_base_afe * afe,int dai_id)17302babb477STrevor Wu static int mt8188_etdm_sync_mode_slv(struct mtk_base_afe *afe, int dai_id)
17312babb477STrevor Wu {
17322babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
17332babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
17342babb477STrevor Wu unsigned int reg = 0;
17352babb477STrevor Wu unsigned int mask;
17362babb477STrevor Wu unsigned int val;
17372babb477STrevor Wu int cowork_source_sel;
17382babb477STrevor Wu
17392babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
17402babb477STrevor Wu return -EINVAL;
17412babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
17422babb477STrevor Wu
17432babb477STrevor Wu cowork_source_sel = etdm_cowork_slv_sel(etdm_data->cowork_source_id,
17442babb477STrevor Wu true);
17452babb477STrevor Wu if (cowork_source_sel < 0)
17462babb477STrevor Wu return cowork_source_sel;
17472babb477STrevor Wu
17482babb477STrevor Wu switch (dai_id) {
17492babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
17502babb477STrevor Wu reg = ETDM_COWORK_CON1;
17512babb477STrevor Wu mask = ETDM_IN1_SLAVE_SEL_MASK;
17522babb477STrevor Wu val = FIELD_PREP(ETDM_IN1_SLAVE_SEL_MASK, cowork_source_sel);
17532babb477STrevor Wu break;
17542babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
17552babb477STrevor Wu reg = ETDM_COWORK_CON2;
17562babb477STrevor Wu mask = ETDM_IN2_SLAVE_SEL_MASK;
17572babb477STrevor Wu val = FIELD_PREP(ETDM_IN2_SLAVE_SEL_MASK, cowork_source_sel);
17582babb477STrevor Wu break;
17592babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
17602babb477STrevor Wu reg = ETDM_COWORK_CON0;
17612babb477STrevor Wu mask = ETDM_OUT1_SLAVE_SEL_MASK;
17622babb477STrevor Wu val = FIELD_PREP(ETDM_OUT1_SLAVE_SEL_MASK, cowork_source_sel);
17632babb477STrevor Wu break;
17642babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
17652babb477STrevor Wu reg = ETDM_COWORK_CON2;
17662babb477STrevor Wu mask = ETDM_OUT2_SLAVE_SEL_MASK;
17672babb477STrevor Wu val = FIELD_PREP(ETDM_OUT2_SLAVE_SEL_MASK, cowork_source_sel);
17682babb477STrevor Wu break;
17692babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
17702babb477STrevor Wu reg = ETDM_COWORK_CON2;
17712babb477STrevor Wu mask = ETDM_OUT3_SLAVE_SEL_MASK;
17722babb477STrevor Wu val = FIELD_PREP(ETDM_OUT3_SLAVE_SEL_MASK, cowork_source_sel);
17732babb477STrevor Wu break;
17742babb477STrevor Wu default:
17752babb477STrevor Wu return 0;
17762babb477STrevor Wu }
17772babb477STrevor Wu
17782babb477STrevor Wu regmap_update_bits(afe->regmap, reg, mask, val);
17792babb477STrevor Wu
17802babb477STrevor Wu return 0;
17812babb477STrevor Wu }
17822babb477STrevor Wu
mt8188_etdm_sync_mode_mst(struct mtk_base_afe * afe,int dai_id)17832babb477STrevor Wu static int mt8188_etdm_sync_mode_mst(struct mtk_base_afe *afe, int dai_id)
17842babb477STrevor Wu {
17852babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
17862babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
17872babb477STrevor Wu struct etdm_con_reg etdm_reg;
17882babb477STrevor Wu unsigned int reg = 0;
17892babb477STrevor Wu unsigned int mask;
17902babb477STrevor Wu unsigned int val;
17912babb477STrevor Wu int cowork_source_sel;
17922babb477STrevor Wu int ret;
17932babb477STrevor Wu
17942babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
17952babb477STrevor Wu return -EINVAL;
17962babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
17972babb477STrevor Wu
17982babb477STrevor Wu cowork_source_sel = etdm_cowork_sync_sel(etdm_data->cowork_source_id);
17992babb477STrevor Wu if (cowork_source_sel < 0)
18002babb477STrevor Wu return cowork_source_sel;
18012babb477STrevor Wu
18022babb477STrevor Wu switch (dai_id) {
18032babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
18042babb477STrevor Wu reg = ETDM_COWORK_CON1;
18052babb477STrevor Wu mask = ETDM_IN1_SYNC_SEL_MASK;
18062babb477STrevor Wu val = FIELD_PREP(ETDM_IN1_SYNC_SEL_MASK, cowork_source_sel);
18072babb477STrevor Wu break;
18082babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
18092babb477STrevor Wu reg = ETDM_COWORK_CON2;
18102babb477STrevor Wu mask = ETDM_IN2_SYNC_SEL_MASK;
18112babb477STrevor Wu val = FIELD_PREP(ETDM_IN2_SYNC_SEL_MASK, cowork_source_sel);
18122babb477STrevor Wu break;
18132babb477STrevor Wu case MT8188_AFE_IO_ETDM1_OUT:
18142babb477STrevor Wu reg = ETDM_COWORK_CON0;
18152babb477STrevor Wu mask = ETDM_OUT1_SYNC_SEL_MASK;
18162babb477STrevor Wu val = FIELD_PREP(ETDM_OUT1_SYNC_SEL_MASK, cowork_source_sel);
18172babb477STrevor Wu break;
18182babb477STrevor Wu case MT8188_AFE_IO_ETDM2_OUT:
18192babb477STrevor Wu reg = ETDM_COWORK_CON2;
18202babb477STrevor Wu mask = ETDM_OUT2_SYNC_SEL_MASK;
18212babb477STrevor Wu val = FIELD_PREP(ETDM_OUT2_SYNC_SEL_MASK, cowork_source_sel);
18222babb477STrevor Wu break;
18232babb477STrevor Wu case MT8188_AFE_IO_ETDM3_OUT:
18242babb477STrevor Wu reg = ETDM_COWORK_CON2;
18252babb477STrevor Wu mask = ETDM_OUT3_SYNC_SEL_MASK;
18262babb477STrevor Wu val = FIELD_PREP(ETDM_OUT3_SYNC_SEL_MASK, cowork_source_sel);
18272babb477STrevor Wu break;
18282babb477STrevor Wu default:
18292babb477STrevor Wu return 0;
18302babb477STrevor Wu }
18312babb477STrevor Wu
18322babb477STrevor Wu ret = get_etdm_reg(dai_id, &etdm_reg);
18332babb477STrevor Wu if (ret < 0)
18342babb477STrevor Wu return ret;
18352babb477STrevor Wu
18362babb477STrevor Wu regmap_update_bits(afe->regmap, reg, mask, val);
18372babb477STrevor Wu
18382babb477STrevor Wu regmap_set_bits(afe->regmap, etdm_reg.con0, ETDM_CON0_SYNC_MODE);
18392babb477STrevor Wu
18402babb477STrevor Wu return 0;
18412babb477STrevor Wu }
18422babb477STrevor Wu
mt8188_etdm_sync_mode_configure(struct mtk_base_afe * afe,int dai_id)18432babb477STrevor Wu static int mt8188_etdm_sync_mode_configure(struct mtk_base_afe *afe, int dai_id)
18442babb477STrevor Wu {
18452babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
18462babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
18472babb477STrevor Wu
18482babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
18492babb477STrevor Wu return -EINVAL;
18502babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
18512babb477STrevor Wu
18522babb477STrevor Wu if (etdm_data->cowork_source_id == COWORK_ETDM_NONE)
18532babb477STrevor Wu return 0;
18542babb477STrevor Wu
18552babb477STrevor Wu if (etdm_data->slave_mode)
18562babb477STrevor Wu mt8188_etdm_sync_mode_slv(afe, dai_id);
18572babb477STrevor Wu else
18582babb477STrevor Wu mt8188_etdm_sync_mode_mst(afe, dai_id);
18592babb477STrevor Wu
18602babb477STrevor Wu return 0;
18612babb477STrevor Wu }
18622babb477STrevor Wu
18632babb477STrevor Wu /* dai ops */
mtk_dai_etdm_fifo_mode(struct mtk_base_afe * afe,int dai_id,unsigned int rate)18642babb477STrevor Wu static int mtk_dai_etdm_fifo_mode(struct mtk_base_afe *afe,
18652babb477STrevor Wu int dai_id, unsigned int rate)
18662babb477STrevor Wu {
18672babb477STrevor Wu unsigned int mode = 0;
18682babb477STrevor Wu unsigned int reg = 0;
18692babb477STrevor Wu unsigned int val = 0;
18702babb477STrevor Wu unsigned int mask = (ETDM_IN_AFIFO_MODE_MASK | ETDM_IN_USE_AFIFO);
18712babb477STrevor Wu
18722babb477STrevor Wu if (rate != 0)
18732babb477STrevor Wu mode = mt8188_afe_fs_timing(rate);
18742babb477STrevor Wu
18752babb477STrevor Wu switch (dai_id) {
18762babb477STrevor Wu case MT8188_AFE_IO_ETDM1_IN:
18772babb477STrevor Wu reg = ETDM_IN1_AFIFO_CON;
18782babb477STrevor Wu if (rate == 0)
18792babb477STrevor Wu mode = MT8188_ETDM_IN1_1X_EN;
18802babb477STrevor Wu break;
18812babb477STrevor Wu case MT8188_AFE_IO_ETDM2_IN:
18822babb477STrevor Wu reg = ETDM_IN2_AFIFO_CON;
18832babb477STrevor Wu if (rate == 0)
18842babb477STrevor Wu mode = MT8188_ETDM_IN2_1X_EN;
18852babb477STrevor Wu break;
18862babb477STrevor Wu default:
18872babb477STrevor Wu return -EINVAL;
18882babb477STrevor Wu }
18892babb477STrevor Wu
18902babb477STrevor Wu val = (mode | ETDM_IN_USE_AFIFO);
18912babb477STrevor Wu
18922babb477STrevor Wu regmap_update_bits(afe->regmap, reg, mask, val);
18932babb477STrevor Wu return 0;
18942babb477STrevor Wu }
18952babb477STrevor Wu
mtk_dai_etdm_in_configure(struct mtk_base_afe * afe,unsigned int rate,unsigned int channels,int dai_id)18962babb477STrevor Wu static int mtk_dai_etdm_in_configure(struct mtk_base_afe *afe,
18972babb477STrevor Wu unsigned int rate,
18982babb477STrevor Wu unsigned int channels,
18992babb477STrevor Wu int dai_id)
19002babb477STrevor Wu {
19012babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
19022babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
19032babb477STrevor Wu struct etdm_con_reg etdm_reg;
19042babb477STrevor Wu bool slave_mode;
19052babb477STrevor Wu unsigned int data_mode;
19062babb477STrevor Wu unsigned int lrck_width;
19072babb477STrevor Wu unsigned int val = 0;
19082babb477STrevor Wu unsigned int mask = 0;
19092babb477STrevor Wu int ret;
19102babb477STrevor Wu int i;
19112babb477STrevor Wu
19122babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
19132babb477STrevor Wu return -EINVAL;
19142babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
19152babb477STrevor Wu slave_mode = etdm_data->slave_mode;
19162babb477STrevor Wu data_mode = etdm_data->data_mode;
19172babb477STrevor Wu lrck_width = etdm_data->lrck_width;
19182babb477STrevor Wu
19192babb477STrevor Wu dev_dbg(afe->dev, "%s rate %u channels %u, id %d\n",
19202babb477STrevor Wu __func__, rate, channels, dai_id);
19212babb477STrevor Wu
19222babb477STrevor Wu ret = get_etdm_reg(dai_id, &etdm_reg);
19232babb477STrevor Wu if (ret < 0)
19242babb477STrevor Wu return ret;
19252babb477STrevor Wu
19262babb477STrevor Wu /* afifo */
19272babb477STrevor Wu if (slave_mode)
19282babb477STrevor Wu mtk_dai_etdm_fifo_mode(afe, dai_id, 0);
19292babb477STrevor Wu else
19302babb477STrevor Wu mtk_dai_etdm_fifo_mode(afe, dai_id, rate);
19312babb477STrevor Wu
19322babb477STrevor Wu /* con1 */
19332babb477STrevor Wu if (lrck_width > 0) {
19342babb477STrevor Wu mask |= (ETDM_IN_CON1_LRCK_AUTO_MODE |
19352babb477STrevor Wu ETDM_IN_CON1_LRCK_WIDTH_MASK);
19362babb477STrevor Wu val |= FIELD_PREP(ETDM_IN_CON1_LRCK_WIDTH_MASK, lrck_width - 1);
19372babb477STrevor Wu }
19382babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val);
19392babb477STrevor Wu
19402babb477STrevor Wu mask = 0;
19412babb477STrevor Wu val = 0;
19422babb477STrevor Wu
19432babb477STrevor Wu /* con2 */
19442babb477STrevor Wu if (!slave_mode) {
19452babb477STrevor Wu mask |= ETDM_IN_CON2_UPDATE_GAP_MASK;
19462babb477STrevor Wu if (rate == 352800 || rate == 384000)
19472babb477STrevor Wu val |= FIELD_PREP(ETDM_IN_CON2_UPDATE_GAP_MASK, 4);
19482babb477STrevor Wu else
19492babb477STrevor Wu val |= FIELD_PREP(ETDM_IN_CON2_UPDATE_GAP_MASK, 3);
19502babb477STrevor Wu }
19512babb477STrevor Wu mask |= (ETDM_IN_CON2_MULTI_IP_2CH_MODE |
19522babb477STrevor Wu ETDM_IN_CON2_MULTI_IP_TOTAL_CH_MASK);
19532babb477STrevor Wu if (data_mode == MTK_DAI_ETDM_DATA_MULTI_PIN) {
19542babb477STrevor Wu val |= ETDM_IN_CON2_MULTI_IP_2CH_MODE |
19552babb477STrevor Wu FIELD_PREP(ETDM_IN_CON2_MULTI_IP_TOTAL_CH_MASK, channels - 1);
19562babb477STrevor Wu }
19572babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con2, mask, val);
19582babb477STrevor Wu
19592babb477STrevor Wu mask = 0;
19602babb477STrevor Wu val = 0;
19612babb477STrevor Wu
19622babb477STrevor Wu /* con3 */
19632babb477STrevor Wu mask |= ETDM_IN_CON3_DISABLE_OUT_MASK;
19642babb477STrevor Wu for (i = 0; i < channels; i += 2) {
19652babb477STrevor Wu if (etdm_data->in_disable_ch[i] &&
19662babb477STrevor Wu etdm_data->in_disable_ch[i + 1])
19672babb477STrevor Wu val |= ETDM_IN_CON3_DISABLE_OUT(i >> 1);
19682babb477STrevor Wu }
19692babb477STrevor Wu if (!slave_mode) {
19702babb477STrevor Wu mask |= ETDM_IN_CON3_FS_MASK;
19712babb477STrevor Wu val |= FIELD_PREP(ETDM_IN_CON3_FS_MASK, get_etdm_fs_timing(rate));
19722babb477STrevor Wu }
19732babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con3, mask, val);
19742babb477STrevor Wu
19752babb477STrevor Wu mask = 0;
19762babb477STrevor Wu val = 0;
19772babb477STrevor Wu
19782babb477STrevor Wu /* con4 */
19792babb477STrevor Wu mask |= (ETDM_IN_CON4_MASTER_LRCK_INV | ETDM_IN_CON4_MASTER_BCK_INV |
19802babb477STrevor Wu ETDM_IN_CON4_SLAVE_LRCK_INV | ETDM_IN_CON4_SLAVE_BCK_INV);
19812babb477STrevor Wu if (slave_mode) {
19822babb477STrevor Wu if (etdm_data->lrck_inv)
19832babb477STrevor Wu val |= ETDM_IN_CON4_SLAVE_LRCK_INV;
19842babb477STrevor Wu if (etdm_data->bck_inv)
19852babb477STrevor Wu val |= ETDM_IN_CON4_SLAVE_BCK_INV;
19862babb477STrevor Wu } else {
19872babb477STrevor Wu if (etdm_data->lrck_inv)
19882babb477STrevor Wu val |= ETDM_IN_CON4_MASTER_LRCK_INV;
19892babb477STrevor Wu if (etdm_data->bck_inv)
19902babb477STrevor Wu val |= ETDM_IN_CON4_MASTER_BCK_INV;
19912babb477STrevor Wu }
19922babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con4, mask, val);
19932babb477STrevor Wu
19942babb477STrevor Wu mask = 0;
19952babb477STrevor Wu val = 0;
19962babb477STrevor Wu
19972babb477STrevor Wu /* con5 */
19982babb477STrevor Wu mask |= ETDM_IN_CON5_LR_SWAP_MASK;
19992babb477STrevor Wu mask |= ETDM_IN_CON5_ENABLE_ODD_MASK;
20002babb477STrevor Wu for (i = 0; i < channels; i += 2) {
20012babb477STrevor Wu if (etdm_data->in_disable_ch[i] &&
20022babb477STrevor Wu !etdm_data->in_disable_ch[i + 1]) {
20032babb477STrevor Wu val |= ETDM_IN_CON5_LR_SWAP(i >> 1);
20042babb477STrevor Wu val |= ETDM_IN_CON5_ENABLE_ODD(i >> 1);
20052babb477STrevor Wu } else if (!etdm_data->in_disable_ch[i] &&
20062babb477STrevor Wu etdm_data->in_disable_ch[i + 1]) {
20072babb477STrevor Wu val |= ETDM_IN_CON5_ENABLE_ODD(i >> 1);
20082babb477STrevor Wu }
20092babb477STrevor Wu }
20102babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con5, mask, val);
20112babb477STrevor Wu return 0;
20122babb477STrevor Wu }
20132babb477STrevor Wu
mtk_dai_etdm_out_configure(struct mtk_base_afe * afe,unsigned int rate,unsigned int channels,int dai_id)20142babb477STrevor Wu static int mtk_dai_etdm_out_configure(struct mtk_base_afe *afe,
20152babb477STrevor Wu unsigned int rate,
20162babb477STrevor Wu unsigned int channels,
20172babb477STrevor Wu int dai_id)
20182babb477STrevor Wu {
20192babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
20202babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
20212babb477STrevor Wu struct etdm_con_reg etdm_reg;
20222babb477STrevor Wu bool slave_mode;
20232babb477STrevor Wu unsigned int lrck_width;
20242babb477STrevor Wu unsigned int val = 0;
20252babb477STrevor Wu unsigned int mask = 0;
20262babb477STrevor Wu int fs = 0;
20272babb477STrevor Wu int ret;
20282babb477STrevor Wu
20292babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
20302babb477STrevor Wu return -EINVAL;
20312babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
20322babb477STrevor Wu slave_mode = etdm_data->slave_mode;
20332babb477STrevor Wu lrck_width = etdm_data->lrck_width;
20342babb477STrevor Wu
20352babb477STrevor Wu dev_dbg(afe->dev, "%s rate %u channels %u, id %d\n",
20362babb477STrevor Wu __func__, rate, channels, dai_id);
20372babb477STrevor Wu
20382babb477STrevor Wu ret = get_etdm_reg(dai_id, &etdm_reg);
20392babb477STrevor Wu if (ret < 0)
20402babb477STrevor Wu return ret;
20412babb477STrevor Wu
20422babb477STrevor Wu /* con0 */
20432babb477STrevor Wu mask = ETDM_OUT_CON0_RELATCH_DOMAIN_MASK;
20442babb477STrevor Wu val = FIELD_PREP(ETDM_OUT_CON0_RELATCH_DOMAIN_MASK,
20452babb477STrevor Wu ETDM_RELATCH_TIMING_A1A2SYS);
20462babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con0, mask, val);
20472babb477STrevor Wu
20482babb477STrevor Wu mask = 0;
20492babb477STrevor Wu val = 0;
20502babb477STrevor Wu
20512babb477STrevor Wu /* con1 */
20522babb477STrevor Wu if (lrck_width > 0) {
20532babb477STrevor Wu mask |= (ETDM_OUT_CON1_LRCK_AUTO_MODE |
20542babb477STrevor Wu ETDM_OUT_CON1_LRCK_WIDTH_MASK);
20552babb477STrevor Wu val |= FIELD_PREP(ETDM_OUT_CON1_LRCK_WIDTH_MASK, lrck_width - 1);
20562babb477STrevor Wu }
20572babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con1, mask, val);
20582babb477STrevor Wu
20592babb477STrevor Wu mask = 0;
20602babb477STrevor Wu val = 0;
20612babb477STrevor Wu
20622babb477STrevor Wu if (!slave_mode) {
20632babb477STrevor Wu /* con4 */
20642babb477STrevor Wu mask |= ETDM_OUT_CON4_FS_MASK;
20652babb477STrevor Wu val |= FIELD_PREP(ETDM_OUT_CON4_FS_MASK, get_etdm_fs_timing(rate));
20662babb477STrevor Wu }
20672babb477STrevor Wu
20682babb477STrevor Wu mask |= ETDM_OUT_CON4_RELATCH_EN_MASK;
20692babb477STrevor Wu if (dai_id == MT8188_AFE_IO_ETDM1_OUT)
20702babb477STrevor Wu fs = MT8188_ETDM_OUT1_1X_EN;
20712babb477STrevor Wu else if (dai_id == MT8188_AFE_IO_ETDM2_OUT)
20722babb477STrevor Wu fs = MT8188_ETDM_OUT2_1X_EN;
20732babb477STrevor Wu
20742babb477STrevor Wu val |= FIELD_PREP(ETDM_OUT_CON4_RELATCH_EN_MASK, fs);
20752babb477STrevor Wu
20762babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con4, mask, val);
20772babb477STrevor Wu
20782babb477STrevor Wu mask = 0;
20792babb477STrevor Wu val = 0;
20802babb477STrevor Wu
20812babb477STrevor Wu /* con5 */
20822babb477STrevor Wu mask |= (ETDM_OUT_CON5_MASTER_LRCK_INV | ETDM_OUT_CON5_MASTER_BCK_INV |
20832babb477STrevor Wu ETDM_OUT_CON5_SLAVE_LRCK_INV | ETDM_OUT_CON5_SLAVE_BCK_INV);
20842babb477STrevor Wu if (slave_mode) {
20852babb477STrevor Wu if (etdm_data->lrck_inv)
20862babb477STrevor Wu val |= ETDM_OUT_CON5_SLAVE_LRCK_INV;
20872babb477STrevor Wu if (etdm_data->bck_inv)
20882babb477STrevor Wu val |= ETDM_OUT_CON5_SLAVE_BCK_INV;
20892babb477STrevor Wu } else {
20902babb477STrevor Wu if (etdm_data->lrck_inv)
20912babb477STrevor Wu val |= ETDM_OUT_CON5_MASTER_LRCK_INV;
20922babb477STrevor Wu if (etdm_data->bck_inv)
20932babb477STrevor Wu val |= ETDM_OUT_CON5_MASTER_BCK_INV;
20942babb477STrevor Wu }
20952babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con5, mask, val);
20962babb477STrevor Wu
20972babb477STrevor Wu return 0;
20982babb477STrevor Wu }
20992babb477STrevor Wu
mtk_dai_etdm_configure(struct mtk_base_afe * afe,unsigned int rate,unsigned int channels,unsigned int bit_width,int dai_id)21002babb477STrevor Wu static int mtk_dai_etdm_configure(struct mtk_base_afe *afe,
21012babb477STrevor Wu unsigned int rate,
21022babb477STrevor Wu unsigned int channels,
21032babb477STrevor Wu unsigned int bit_width,
21042babb477STrevor Wu int dai_id)
21052babb477STrevor Wu {
21062babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
21072babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
21082babb477STrevor Wu struct etdm_con_reg etdm_reg;
21092babb477STrevor Wu bool slave_mode;
21102babb477STrevor Wu unsigned int etdm_channels;
21112babb477STrevor Wu unsigned int val = 0;
21122babb477STrevor Wu unsigned int mask = 0;
21132babb477STrevor Wu unsigned int bck;
21142babb477STrevor Wu unsigned int wlen = get_etdm_wlen(bit_width);
21152babb477STrevor Wu int ret;
21162babb477STrevor Wu
21172babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
21182babb477STrevor Wu return -EINVAL;
21192babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
21202babb477STrevor Wu slave_mode = etdm_data->slave_mode;
21219be0213aSTrevor Wu etdm_data->rate = rate;
21222babb477STrevor Wu
21232babb477STrevor Wu ret = get_etdm_reg(dai_id, &etdm_reg);
21242babb477STrevor Wu if (ret < 0)
21252babb477STrevor Wu return ret;
21262babb477STrevor Wu
2127e5d2bd41STrevor Wu dev_dbg(afe->dev, "%s fmt %u data %u lrck %d-%u bck %d, slv %u\n",
21282babb477STrevor Wu __func__, etdm_data->format, etdm_data->data_mode,
21292babb477STrevor Wu etdm_data->lrck_inv, etdm_data->lrck_width, etdm_data->bck_inv,
2130e5d2bd41STrevor Wu etdm_data->slave_mode);
21312babb477STrevor Wu dev_dbg(afe->dev, "%s rate %u channels %u bitwidth %u, id %d\n",
21322babb477STrevor Wu __func__, rate, channels, bit_width, dai_id);
21332babb477STrevor Wu
21342babb477STrevor Wu etdm_channels = (etdm_data->data_mode == MTK_DAI_ETDM_DATA_ONE_PIN) ?
21352babb477STrevor Wu get_etdm_ch_fixup(channels) : 2;
21362babb477STrevor Wu
21372babb477STrevor Wu bck = rate * etdm_channels * wlen;
21382babb477STrevor Wu if (bck > MT8188_ETDM_NORMAL_MAX_BCK_RATE) {
21392babb477STrevor Wu dev_err(afe->dev, "%s bck rate %u not support\n",
21402babb477STrevor Wu __func__, bck);
21412babb477STrevor Wu return -EINVAL;
21422babb477STrevor Wu }
21432babb477STrevor Wu
21442babb477STrevor Wu /* con0 */
21452babb477STrevor Wu mask |= ETDM_CON0_BIT_LEN_MASK;
21462babb477STrevor Wu val |= FIELD_PREP(ETDM_CON0_BIT_LEN_MASK, bit_width - 1);
21472babb477STrevor Wu mask |= ETDM_CON0_WORD_LEN_MASK;
21482babb477STrevor Wu val |= FIELD_PREP(ETDM_CON0_WORD_LEN_MASK, wlen - 1);
21492babb477STrevor Wu mask |= ETDM_CON0_FORMAT_MASK;
21502babb477STrevor Wu val |= FIELD_PREP(ETDM_CON0_FORMAT_MASK, etdm_data->format);
21512babb477STrevor Wu mask |= ETDM_CON0_CH_NUM_MASK;
21522babb477STrevor Wu val |= FIELD_PREP(ETDM_CON0_CH_NUM_MASK, etdm_channels - 1);
21532babb477STrevor Wu
21542babb477STrevor Wu mask |= ETDM_CON0_SLAVE_MODE;
21552babb477STrevor Wu if (slave_mode) {
21562babb477STrevor Wu if (dai_id == MT8188_AFE_IO_ETDM1_OUT) {
21572babb477STrevor Wu dev_err(afe->dev, "%s id %d only support master mode\n",
21582babb477STrevor Wu __func__, dai_id);
21592babb477STrevor Wu return -EINVAL;
21602babb477STrevor Wu }
21612babb477STrevor Wu val |= ETDM_CON0_SLAVE_MODE;
21622babb477STrevor Wu }
21632babb477STrevor Wu regmap_update_bits(afe->regmap, etdm_reg.con0, mask, val);
21642babb477STrevor Wu
21652babb477STrevor Wu if (get_etdm_dir(dai_id) == ETDM_IN)
21662babb477STrevor Wu mtk_dai_etdm_in_configure(afe, rate, channels, dai_id);
21672babb477STrevor Wu else
21682babb477STrevor Wu mtk_dai_etdm_out_configure(afe, rate, channels, dai_id);
21692babb477STrevor Wu
21702babb477STrevor Wu return 0;
21712babb477STrevor Wu }
21722babb477STrevor Wu
mtk_dai_etdm_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)21732babb477STrevor Wu static int mtk_dai_etdm_hw_params(struct snd_pcm_substream *substream,
21742babb477STrevor Wu struct snd_pcm_hw_params *params,
21752babb477STrevor Wu struct snd_soc_dai *dai)
21762babb477STrevor Wu {
21772babb477STrevor Wu unsigned int rate = params_rate(params);
21782babb477STrevor Wu unsigned int bit_width = params_width(params);
21792babb477STrevor Wu unsigned int channels = params_channels(params);
21802babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
21812babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
21822babb477STrevor Wu struct mtk_dai_etdm_priv *mst_etdm_data;
21832babb477STrevor Wu int mst_dai_id;
21842babb477STrevor Wu int slv_dai_id;
21852babb477STrevor Wu int ret;
21862babb477STrevor Wu int i;
21872babb477STrevor Wu
21882babb477STrevor Wu dev_dbg(afe->dev, "%s '%s' period %u-%u\n",
21892babb477STrevor Wu __func__, snd_pcm_stream_str(substream),
21902babb477STrevor Wu params_period_size(params), params_periods(params));
21912babb477STrevor Wu
21922babb477STrevor Wu if (is_cowork_mode(dai)) {
21932babb477STrevor Wu mst_dai_id = get_etdm_cowork_master_id(dai);
21942babb477STrevor Wu if (!is_valid_etdm_dai(mst_dai_id))
21952babb477STrevor Wu return -EINVAL;
21962babb477STrevor Wu
21972664c879STrevor Wu mst_etdm_data = afe_priv->dai_priv[mst_dai_id];
21982664c879STrevor Wu if (mst_etdm_data->slots)
21992664c879STrevor Wu channels = mst_etdm_data->slots;
22002664c879STrevor Wu
22012babb477STrevor Wu ret = mtk_dai_etdm_configure(afe, rate, channels,
22022babb477STrevor Wu bit_width, mst_dai_id);
22032babb477STrevor Wu if (ret)
22042babb477STrevor Wu return ret;
22052babb477STrevor Wu
22062babb477STrevor Wu for (i = 0; i < mst_etdm_data->cowork_slv_count; i++) {
22072babb477STrevor Wu slv_dai_id = mst_etdm_data->cowork_slv_id[i];
22082babb477STrevor Wu ret = mtk_dai_etdm_configure(afe, rate, channels,
22092babb477STrevor Wu bit_width, slv_dai_id);
22102babb477STrevor Wu if (ret)
22112babb477STrevor Wu return ret;
22122babb477STrevor Wu
22132babb477STrevor Wu ret = mt8188_etdm_sync_mode_configure(afe, slv_dai_id);
22142babb477STrevor Wu if (ret)
22152babb477STrevor Wu return ret;
22162babb477STrevor Wu }
22172babb477STrevor Wu } else {
22182664c879STrevor Wu if (!is_valid_etdm_dai(dai->id))
22192664c879STrevor Wu return -EINVAL;
22202664c879STrevor Wu mst_etdm_data = afe_priv->dai_priv[dai->id];
22212664c879STrevor Wu if (mst_etdm_data->slots)
22222664c879STrevor Wu channels = mst_etdm_data->slots;
22232664c879STrevor Wu
22242babb477STrevor Wu ret = mtk_dai_etdm_configure(afe, rate, channels,
22252babb477STrevor Wu bit_width, dai->id);
22262babb477STrevor Wu if (ret)
22272babb477STrevor Wu return ret;
22282babb477STrevor Wu }
22292babb477STrevor Wu
22302babb477STrevor Wu return 0;
22312babb477STrevor Wu }
22322babb477STrevor Wu
mtk_dai_etdm_cal_mclk(struct mtk_base_afe * afe,int freq,int dai_id)22332babb477STrevor Wu static int mtk_dai_etdm_cal_mclk(struct mtk_base_afe *afe, int freq, int dai_id)
22342babb477STrevor Wu {
22352babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
22362babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
22372babb477STrevor Wu int apll_rate;
22382babb477STrevor Wu int apll;
22392babb477STrevor Wu
22402babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
22412babb477STrevor Wu return -EINVAL;
22422babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
22432babb477STrevor Wu
22442babb477STrevor Wu if (freq == 0) {
22452babb477STrevor Wu etdm_data->mclk_freq = freq;
22462babb477STrevor Wu return 0;
22472babb477STrevor Wu }
22482babb477STrevor Wu
22492babb477STrevor Wu if (etdm_data->mclk_fixed_apll == 0)
22502babb477STrevor Wu apll = mt8188_afe_get_default_mclk_source_by_rate(freq);
22512babb477STrevor Wu else
22522babb477STrevor Wu apll = etdm_data->mclk_apll;
22532babb477STrevor Wu
22542babb477STrevor Wu apll_rate = mt8188_afe_get_mclk_source_rate(afe, apll);
22552babb477STrevor Wu
22562babb477STrevor Wu if (freq > apll_rate) {
22572babb477STrevor Wu dev_err(afe->dev, "freq %d > apll rate %d\n", freq, apll_rate);
22582babb477STrevor Wu return -EINVAL;
22592babb477STrevor Wu }
22602babb477STrevor Wu
22612babb477STrevor Wu if (apll_rate % freq != 0) {
22622babb477STrevor Wu dev_err(afe->dev, "APLL%d cannot generate freq Hz\n", apll);
22632babb477STrevor Wu return -EINVAL;
22642babb477STrevor Wu }
22652babb477STrevor Wu
22662babb477STrevor Wu if (etdm_data->mclk_fixed_apll == 0)
22672babb477STrevor Wu etdm_data->mclk_apll = apll;
22682babb477STrevor Wu etdm_data->mclk_freq = freq;
22692babb477STrevor Wu
22702babb477STrevor Wu return 0;
22712babb477STrevor Wu }
22722babb477STrevor Wu
mtk_dai_etdm_set_sysclk(struct snd_soc_dai * dai,int clk_id,unsigned int freq,int dir)22732babb477STrevor Wu static int mtk_dai_etdm_set_sysclk(struct snd_soc_dai *dai,
22742babb477STrevor Wu int clk_id, unsigned int freq, int dir)
22752babb477STrevor Wu {
22762babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
22772babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
22782babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
22792babb477STrevor Wu int dai_id;
22802babb477STrevor Wu
22812babb477STrevor Wu dev_dbg(dai->dev, "%s id %d freq %u, dir %d\n",
22822babb477STrevor Wu __func__, dai->id, freq, dir);
22832babb477STrevor Wu if (is_cowork_mode(dai))
22842babb477STrevor Wu dai_id = get_etdm_cowork_master_id(dai);
22852babb477STrevor Wu else
22862babb477STrevor Wu dai_id = dai->id;
22872babb477STrevor Wu
22882babb477STrevor Wu if (!is_valid_etdm_dai(dai_id))
22892babb477STrevor Wu return -EINVAL;
22902babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
22912babb477STrevor Wu etdm_data->mclk_dir = dir;
22922babb477STrevor Wu return mtk_dai_etdm_cal_mclk(afe, freq, dai_id);
22932babb477STrevor Wu }
22942babb477STrevor Wu
mtk_dai_etdm_set_tdm_slot(struct snd_soc_dai * dai,unsigned int tx_mask,unsigned int rx_mask,int slots,int slot_width)22952babb477STrevor Wu static int mtk_dai_etdm_set_tdm_slot(struct snd_soc_dai *dai,
22962babb477STrevor Wu unsigned int tx_mask, unsigned int rx_mask,
22972babb477STrevor Wu int slots, int slot_width)
22982babb477STrevor Wu {
22992babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
23002babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
23012babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
23022664c879STrevor Wu int dai_id;
23032babb477STrevor Wu
23042664c879STrevor Wu if (is_cowork_mode(dai))
23052664c879STrevor Wu dai_id = get_etdm_cowork_master_id(dai);
23062664c879STrevor Wu else
23072664c879STrevor Wu dai_id = dai->id;
23082664c879STrevor Wu
23092664c879STrevor Wu if (!is_valid_etdm_dai(dai_id))
23102babb477STrevor Wu return -EINVAL;
23112664c879STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
23122babb477STrevor Wu
23132babb477STrevor Wu dev_dbg(dai->dev, "%s id %d slot_width %d\n",
23142babb477STrevor Wu __func__, dai->id, slot_width);
23152babb477STrevor Wu
23162babb477STrevor Wu etdm_data->slots = slots;
23172babb477STrevor Wu etdm_data->lrck_width = slot_width;
23182babb477STrevor Wu return 0;
23192babb477STrevor Wu }
23202babb477STrevor Wu
mtk_dai_etdm_set_fmt(struct snd_soc_dai * dai,unsigned int fmt)23212babb477STrevor Wu static int mtk_dai_etdm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
23222babb477STrevor Wu {
23232babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
23242babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
23252babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
23262babb477STrevor Wu
23272babb477STrevor Wu if (!is_valid_etdm_dai(dai->id))
23282babb477STrevor Wu return -EINVAL;
23292babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai->id];
23302babb477STrevor Wu
23312babb477STrevor Wu switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
23322babb477STrevor Wu case SND_SOC_DAIFMT_I2S:
23332babb477STrevor Wu etdm_data->format = MTK_DAI_ETDM_FORMAT_I2S;
23342babb477STrevor Wu break;
23352babb477STrevor Wu case SND_SOC_DAIFMT_LEFT_J:
23362babb477STrevor Wu etdm_data->format = MTK_DAI_ETDM_FORMAT_LJ;
23372babb477STrevor Wu break;
23382babb477STrevor Wu case SND_SOC_DAIFMT_RIGHT_J:
23392babb477STrevor Wu etdm_data->format = MTK_DAI_ETDM_FORMAT_RJ;
23402babb477STrevor Wu break;
23412babb477STrevor Wu case SND_SOC_DAIFMT_DSP_A:
23422babb477STrevor Wu etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPA;
23432babb477STrevor Wu break;
23442babb477STrevor Wu case SND_SOC_DAIFMT_DSP_B:
23452babb477STrevor Wu etdm_data->format = MTK_DAI_ETDM_FORMAT_DSPB;
23462babb477STrevor Wu break;
23472babb477STrevor Wu default:
23482babb477STrevor Wu return -EINVAL;
23492babb477STrevor Wu }
23502babb477STrevor Wu
23512babb477STrevor Wu switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
23522babb477STrevor Wu case SND_SOC_DAIFMT_NB_NF:
23532babb477STrevor Wu etdm_data->bck_inv = false;
23542babb477STrevor Wu etdm_data->lrck_inv = false;
23552babb477STrevor Wu break;
23562babb477STrevor Wu case SND_SOC_DAIFMT_NB_IF:
23572babb477STrevor Wu etdm_data->bck_inv = false;
23582babb477STrevor Wu etdm_data->lrck_inv = true;
23592babb477STrevor Wu break;
23602babb477STrevor Wu case SND_SOC_DAIFMT_IB_NF:
23612babb477STrevor Wu etdm_data->bck_inv = true;
23622babb477STrevor Wu etdm_data->lrck_inv = false;
23632babb477STrevor Wu break;
23642babb477STrevor Wu case SND_SOC_DAIFMT_IB_IF:
23652babb477STrevor Wu etdm_data->bck_inv = true;
23662babb477STrevor Wu etdm_data->lrck_inv = true;
23672babb477STrevor Wu break;
23682babb477STrevor Wu default:
23692babb477STrevor Wu return -EINVAL;
23702babb477STrevor Wu }
23712babb477STrevor Wu
23722babb477STrevor Wu switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
23732babb477STrevor Wu case SND_SOC_DAIFMT_BC_FC:
23742babb477STrevor Wu etdm_data->slave_mode = true;
23752babb477STrevor Wu break;
23762babb477STrevor Wu case SND_SOC_DAIFMT_BP_FP:
23772babb477STrevor Wu etdm_data->slave_mode = false;
23782babb477STrevor Wu break;
23792babb477STrevor Wu default:
23802babb477STrevor Wu return -EINVAL;
23812babb477STrevor Wu }
23822babb477STrevor Wu
23832babb477STrevor Wu return 0;
23842babb477STrevor Wu }
23852babb477STrevor Wu
mtk_dai_get_dptx_ch_en(unsigned int channel)23862babb477STrevor Wu static unsigned int mtk_dai_get_dptx_ch_en(unsigned int channel)
23872babb477STrevor Wu {
23882babb477STrevor Wu switch (channel) {
23892babb477STrevor Wu case 1 ... 2:
23902babb477STrevor Wu return AFE_DPTX_CON_CH_EN_2CH;
23912babb477STrevor Wu case 3 ... 4:
23922babb477STrevor Wu return AFE_DPTX_CON_CH_EN_4CH;
23932babb477STrevor Wu case 5 ... 6:
23942babb477STrevor Wu return AFE_DPTX_CON_CH_EN_6CH;
23952babb477STrevor Wu case 7 ... 8:
23962babb477STrevor Wu return AFE_DPTX_CON_CH_EN_8CH;
23972babb477STrevor Wu default:
23982babb477STrevor Wu return AFE_DPTX_CON_CH_EN_2CH;
23992babb477STrevor Wu }
24002babb477STrevor Wu }
24012babb477STrevor Wu
mtk_dai_get_dptx_ch(unsigned int ch)24022babb477STrevor Wu static unsigned int mtk_dai_get_dptx_ch(unsigned int ch)
24032babb477STrevor Wu {
24042babb477STrevor Wu return (ch > 2) ?
24052babb477STrevor Wu AFE_DPTX_CON_CH_NUM_8CH : AFE_DPTX_CON_CH_NUM_2CH;
24062babb477STrevor Wu }
24072babb477STrevor Wu
mtk_dai_get_dptx_wlen(snd_pcm_format_t format)24082babb477STrevor Wu static unsigned int mtk_dai_get_dptx_wlen(snd_pcm_format_t format)
24092babb477STrevor Wu {
24102babb477STrevor Wu return snd_pcm_format_physical_width(format) <= 16 ?
24112babb477STrevor Wu AFE_DPTX_CON_16BIT : AFE_DPTX_CON_24BIT;
24122babb477STrevor Wu }
24132babb477STrevor Wu
mtk_dai_hdmitx_dptx_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)24142babb477STrevor Wu static int mtk_dai_hdmitx_dptx_hw_params(struct snd_pcm_substream *substream,
24152babb477STrevor Wu struct snd_pcm_hw_params *params,
24162babb477STrevor Wu struct snd_soc_dai *dai)
24172babb477STrevor Wu {
24182babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
24192babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
24202babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
24212babb477STrevor Wu unsigned int rate = params_rate(params);
24222babb477STrevor Wu unsigned int channels = params_channels(params);
24232babb477STrevor Wu snd_pcm_format_t format = params_format(params);
24242babb477STrevor Wu int width = snd_pcm_format_physical_width(format);
24252babb477STrevor Wu int ret;
24262babb477STrevor Wu
24272babb477STrevor Wu if (!is_valid_etdm_dai(dai->id))
24282babb477STrevor Wu return -EINVAL;
24292babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai->id];
24302babb477STrevor Wu
24312babb477STrevor Wu /* dptx configure */
24322babb477STrevor Wu if (dai->id == MT8188_AFE_IO_DPTX) {
24332babb477STrevor Wu regmap_update_bits(afe->regmap, AFE_DPTX_CON,
24342babb477STrevor Wu AFE_DPTX_CON_CH_EN_MASK,
24352babb477STrevor Wu mtk_dai_get_dptx_ch_en(channels));
24362babb477STrevor Wu regmap_update_bits(afe->regmap, AFE_DPTX_CON,
24372babb477STrevor Wu AFE_DPTX_CON_CH_NUM_MASK,
24382babb477STrevor Wu mtk_dai_get_dptx_ch(channels));
24392babb477STrevor Wu regmap_update_bits(afe->regmap, AFE_DPTX_CON,
24402babb477STrevor Wu AFE_DPTX_CON_16BIT_MASK,
24412babb477STrevor Wu mtk_dai_get_dptx_wlen(format));
24422babb477STrevor Wu
24432babb477STrevor Wu if (mtk_dai_get_dptx_ch(channels) == AFE_DPTX_CON_CH_NUM_8CH) {
24442babb477STrevor Wu etdm_data->data_mode = MTK_DAI_ETDM_DATA_ONE_PIN;
24452babb477STrevor Wu channels = 8;
24462babb477STrevor Wu } else {
24472babb477STrevor Wu channels = 2;
24482babb477STrevor Wu }
24492babb477STrevor Wu } else {
24502babb477STrevor Wu etdm_data->data_mode = MTK_DAI_ETDM_DATA_MULTI_PIN;
24512babb477STrevor Wu }
24522babb477STrevor Wu
24532babb477STrevor Wu ret = mtk_dai_etdm_configure(afe, rate, channels, width, dai->id);
24542babb477STrevor Wu
24552babb477STrevor Wu return ret;
24562babb477STrevor Wu }
24572babb477STrevor Wu
mtk_dai_hdmitx_dptx_set_sysclk(struct snd_soc_dai * dai,int clk_id,unsigned int freq,int dir)24582babb477STrevor Wu static int mtk_dai_hdmitx_dptx_set_sysclk(struct snd_soc_dai *dai,
24592babb477STrevor Wu int clk_id,
24602babb477STrevor Wu unsigned int freq,
24612babb477STrevor Wu int dir)
24622babb477STrevor Wu {
24632babb477STrevor Wu struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
24642babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
24652babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
24662babb477STrevor Wu
24672babb477STrevor Wu if (!is_valid_etdm_dai(dai->id))
24682babb477STrevor Wu return -EINVAL;
24692babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai->id];
24702babb477STrevor Wu
24712babb477STrevor Wu dev_dbg(dai->dev, "%s id %d freq %u, dir %d\n",
24722babb477STrevor Wu __func__, dai->id, freq, dir);
24732babb477STrevor Wu
24742babb477STrevor Wu etdm_data->mclk_dir = dir;
24752babb477STrevor Wu return mtk_dai_etdm_cal_mclk(afe, freq, dai->id);
24762babb477STrevor Wu }
24772babb477STrevor Wu
24782babb477STrevor Wu static const struct snd_soc_dai_ops mtk_dai_etdm_ops = {
24792babb477STrevor Wu .hw_params = mtk_dai_etdm_hw_params,
24802babb477STrevor Wu .set_sysclk = mtk_dai_etdm_set_sysclk,
24812babb477STrevor Wu .set_fmt = mtk_dai_etdm_set_fmt,
24822babb477STrevor Wu .set_tdm_slot = mtk_dai_etdm_set_tdm_slot,
24832babb477STrevor Wu };
24842babb477STrevor Wu
24852babb477STrevor Wu static const struct snd_soc_dai_ops mtk_dai_hdmitx_dptx_ops = {
24862babb477STrevor Wu .hw_params = mtk_dai_hdmitx_dptx_hw_params,
24872babb477STrevor Wu .set_sysclk = mtk_dai_hdmitx_dptx_set_sysclk,
24882babb477STrevor Wu .set_fmt = mtk_dai_etdm_set_fmt,
24892babb477STrevor Wu };
24902babb477STrevor Wu
24912babb477STrevor Wu /* dai driver */
24922babb477STrevor Wu #define MTK_ETDM_RATES (SNDRV_PCM_RATE_8000_192000)
24932babb477STrevor Wu
24942babb477STrevor Wu #define MTK_ETDM_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
24952babb477STrevor Wu SNDRV_PCM_FMTBIT_S24_LE |\
24962babb477STrevor Wu SNDRV_PCM_FMTBIT_S32_LE)
24972babb477STrevor Wu
24982babb477STrevor Wu static struct snd_soc_dai_driver mtk_dai_etdm_driver[] = {
24992babb477STrevor Wu {
25002babb477STrevor Wu .name = "DPTX",
25012babb477STrevor Wu .id = MT8188_AFE_IO_DPTX,
25022babb477STrevor Wu .playback = {
25032babb477STrevor Wu .stream_name = "DPTX",
25042babb477STrevor Wu .channels_min = 1,
25052babb477STrevor Wu .channels_max = 8,
25062babb477STrevor Wu .rates = MTK_ETDM_RATES,
25072babb477STrevor Wu .formats = MTK_ETDM_FORMATS,
25082babb477STrevor Wu },
25092babb477STrevor Wu .ops = &mtk_dai_hdmitx_dptx_ops,
25102babb477STrevor Wu },
25112babb477STrevor Wu {
25122babb477STrevor Wu .name = "ETDM1_IN",
25132babb477STrevor Wu .id = MT8188_AFE_IO_ETDM1_IN,
25142babb477STrevor Wu .capture = {
25152babb477STrevor Wu .stream_name = "ETDM1_IN",
25162babb477STrevor Wu .channels_min = 1,
25172babb477STrevor Wu .channels_max = 16,
25182babb477STrevor Wu .rates = MTK_ETDM_RATES,
25192babb477STrevor Wu .formats = MTK_ETDM_FORMATS,
25202babb477STrevor Wu },
25212babb477STrevor Wu .ops = &mtk_dai_etdm_ops,
25222babb477STrevor Wu },
25232babb477STrevor Wu {
25242babb477STrevor Wu .name = "ETDM2_IN",
25252babb477STrevor Wu .id = MT8188_AFE_IO_ETDM2_IN,
25262babb477STrevor Wu .capture = {
25272babb477STrevor Wu .stream_name = "ETDM2_IN",
25282babb477STrevor Wu .channels_min = 1,
25292babb477STrevor Wu .channels_max = 16,
25302babb477STrevor Wu .rates = MTK_ETDM_RATES,
25312babb477STrevor Wu .formats = MTK_ETDM_FORMATS,
25322babb477STrevor Wu },
25332babb477STrevor Wu .ops = &mtk_dai_etdm_ops,
25342babb477STrevor Wu },
25352babb477STrevor Wu {
25362babb477STrevor Wu .name = "ETDM1_OUT",
25372babb477STrevor Wu .id = MT8188_AFE_IO_ETDM1_OUT,
25382babb477STrevor Wu .playback = {
25392babb477STrevor Wu .stream_name = "ETDM1_OUT",
25402babb477STrevor Wu .channels_min = 1,
25412babb477STrevor Wu .channels_max = 16,
25422babb477STrevor Wu .rates = MTK_ETDM_RATES,
25432babb477STrevor Wu .formats = MTK_ETDM_FORMATS,
25442babb477STrevor Wu },
25452babb477STrevor Wu .ops = &mtk_dai_etdm_ops,
25462babb477STrevor Wu },
25472babb477STrevor Wu {
25482babb477STrevor Wu .name = "ETDM2_OUT",
25492babb477STrevor Wu .id = MT8188_AFE_IO_ETDM2_OUT,
25502babb477STrevor Wu .playback = {
25512babb477STrevor Wu .stream_name = "ETDM2_OUT",
25522babb477STrevor Wu .channels_min = 1,
25532babb477STrevor Wu .channels_max = 16,
25542babb477STrevor Wu .rates = MTK_ETDM_RATES,
25552babb477STrevor Wu .formats = MTK_ETDM_FORMATS,
25562babb477STrevor Wu },
25572babb477STrevor Wu .ops = &mtk_dai_etdm_ops,
25582babb477STrevor Wu },
25592babb477STrevor Wu {
25602babb477STrevor Wu .name = "ETDM3_OUT",
25612babb477STrevor Wu .id = MT8188_AFE_IO_ETDM3_OUT,
25622babb477STrevor Wu .playback = {
25632babb477STrevor Wu .stream_name = "ETDM3_OUT",
25642babb477STrevor Wu .channels_min = 1,
25652babb477STrevor Wu .channels_max = 8,
25662babb477STrevor Wu .rates = MTK_ETDM_RATES,
25672babb477STrevor Wu .formats = MTK_ETDM_FORMATS,
25682babb477STrevor Wu },
25692babb477STrevor Wu .ops = &mtk_dai_hdmitx_dptx_ops,
25702babb477STrevor Wu },
25712babb477STrevor Wu };
25722babb477STrevor Wu
mt8188_etdm_update_sync_info(struct mtk_base_afe * afe)25732babb477STrevor Wu static void mt8188_etdm_update_sync_info(struct mtk_base_afe *afe)
25742babb477STrevor Wu {
25752babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
25762babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
25772babb477STrevor Wu struct mtk_dai_etdm_priv *mst_data;
25782babb477STrevor Wu int mst_dai_id;
25792babb477STrevor Wu int i;
25802babb477STrevor Wu
25812babb477STrevor Wu for (i = MT8188_AFE_IO_ETDM_START; i < MT8188_AFE_IO_ETDM_END; i++) {
25822babb477STrevor Wu etdm_data = afe_priv->dai_priv[i];
25832babb477STrevor Wu if (etdm_data->cowork_source_id != COWORK_ETDM_NONE) {
25842babb477STrevor Wu mst_dai_id = etdm_data->cowork_source_id;
25852babb477STrevor Wu mst_data = afe_priv->dai_priv[mst_dai_id];
25862babb477STrevor Wu if (mst_data->cowork_source_id != COWORK_ETDM_NONE)
25872babb477STrevor Wu dev_err(afe->dev, "%s [%d] wrong sync source\n",
25882babb477STrevor Wu __func__, i);
25892babb477STrevor Wu mst_data->cowork_slv_id[mst_data->cowork_slv_count] = i;
25902babb477STrevor Wu mst_data->cowork_slv_count++;
25912babb477STrevor Wu }
25922babb477STrevor Wu }
25932babb477STrevor Wu }
25942babb477STrevor Wu
mt8188_dai_etdm_parse_of(struct mtk_base_afe * afe)25952babb477STrevor Wu static void mt8188_dai_etdm_parse_of(struct mtk_base_afe *afe)
25962babb477STrevor Wu {
25972babb477STrevor Wu const struct device_node *of_node = afe->dev->of_node;
25982babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
25992babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_data;
26002babb477STrevor Wu char prop[48];
26012babb477STrevor Wu u8 disable_chn[MT8188_ETDM_MAX_CHANNELS];
26022babb477STrevor Wu int max_chn = MT8188_ETDM_MAX_CHANNELS;
26032babb477STrevor Wu unsigned int sync_id;
26042babb477STrevor Wu u32 sel;
26052babb477STrevor Wu int ret;
26062babb477STrevor Wu int dai_id;
26072babb477STrevor Wu int i, j;
26082babb477STrevor Wu struct {
26092babb477STrevor Wu const char *name;
26102babb477STrevor Wu const unsigned int sync_id;
26112babb477STrevor Wu } of_afe_etdms[MT8188_AFE_IO_ETDM_NUM] = {
26122babb477STrevor Wu {"etdm-in1", ETDM_SYNC_FROM_IN1},
26132babb477STrevor Wu {"etdm-in2", ETDM_SYNC_FROM_IN2},
26142babb477STrevor Wu {"etdm-out1", ETDM_SYNC_FROM_OUT1},
26152babb477STrevor Wu {"etdm-out2", ETDM_SYNC_FROM_OUT2},
26162babb477STrevor Wu {"etdm-out3", ETDM_SYNC_FROM_OUT3},
26172babb477STrevor Wu };
26182babb477STrevor Wu
26192babb477STrevor Wu for (i = 0; i < MT8188_AFE_IO_ETDM_NUM; i++) {
26202babb477STrevor Wu dai_id = ETDM_TO_DAI_ID(i);
26212babb477STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
26222babb477STrevor Wu
262366b9e94cSTrevor Wu snprintf(prop, sizeof(prop), "mediatek,%s-multi-pin-mode",
26242babb477STrevor Wu of_afe_etdms[i].name);
262566b9e94cSTrevor Wu
26262babb477STrevor Wu etdm_data->data_mode = of_property_read_bool(of_node, prop);
26272babb477STrevor Wu
262866b9e94cSTrevor Wu snprintf(prop, sizeof(prop), "mediatek,%s-cowork-source",
26292babb477STrevor Wu of_afe_etdms[i].name);
263066b9e94cSTrevor Wu
26312babb477STrevor Wu ret = of_property_read_u32(of_node, prop, &sel);
26322babb477STrevor Wu if (ret == 0) {
26332babb477STrevor Wu if (sel >= MT8188_AFE_IO_ETDM_NUM) {
26342babb477STrevor Wu dev_err(afe->dev, "%s invalid id=%d\n",
26352babb477STrevor Wu __func__, sel);
26362babb477STrevor Wu etdm_data->cowork_source_id = COWORK_ETDM_NONE;
26372babb477STrevor Wu } else {
26382babb477STrevor Wu sync_id = of_afe_etdms[sel].sync_id;
26392babb477STrevor Wu etdm_data->cowork_source_id =
26402babb477STrevor Wu sync_to_dai_id(sync_id);
26412babb477STrevor Wu }
26422babb477STrevor Wu } else {
26432babb477STrevor Wu etdm_data->cowork_source_id = COWORK_ETDM_NONE;
26442babb477STrevor Wu }
26452babb477STrevor Wu }
26462babb477STrevor Wu
26472babb477STrevor Wu /* etdm in only */
26482babb477STrevor Wu for (i = 0; i < 2; i++) {
264923badca4STrevor Wu dai_id = ETDM_TO_DAI_ID(i);
265023badca4STrevor Wu etdm_data = afe_priv->dai_priv[dai_id];
265123badca4STrevor Wu
265266b9e94cSTrevor Wu snprintf(prop, sizeof(prop), "mediatek,%s-chn-disabled",
26532babb477STrevor Wu of_afe_etdms[i].name);
265466b9e94cSTrevor Wu
26552babb477STrevor Wu ret = of_property_read_variable_u8_array(of_node, prop,
26562babb477STrevor Wu disable_chn,
26572babb477STrevor Wu 1, max_chn);
26582babb477STrevor Wu if (ret < 0)
26592babb477STrevor Wu continue;
26602babb477STrevor Wu
26612babb477STrevor Wu for (j = 0; j < ret; j++) {
26622babb477STrevor Wu if (disable_chn[j] >= MT8188_ETDM_MAX_CHANNELS)
26632babb477STrevor Wu dev_err(afe->dev, "%s [%d] invalid chn %u\n",
26642babb477STrevor Wu __func__, j, disable_chn[j]);
26652babb477STrevor Wu else
26662babb477STrevor Wu etdm_data->in_disable_ch[disable_chn[j]] = true;
26672babb477STrevor Wu }
26682babb477STrevor Wu }
26692babb477STrevor Wu mt8188_etdm_update_sync_info(afe);
26702babb477STrevor Wu }
26712babb477STrevor Wu
init_etdm_priv_data(struct mtk_base_afe * afe)26722babb477STrevor Wu static int init_etdm_priv_data(struct mtk_base_afe *afe)
26732babb477STrevor Wu {
26742babb477STrevor Wu struct mt8188_afe_private *afe_priv = afe->platform_priv;
26752babb477STrevor Wu struct mtk_dai_etdm_priv *etdm_priv;
26762babb477STrevor Wu int i;
26772babb477STrevor Wu
26782babb477STrevor Wu for (i = MT8188_AFE_IO_ETDM_START; i < MT8188_AFE_IO_ETDM_END; i++) {
26792babb477STrevor Wu etdm_priv = devm_kzalloc(afe->dev,
26802babb477STrevor Wu sizeof(struct mtk_dai_etdm_priv),
26812babb477STrevor Wu GFP_KERNEL);
26822babb477STrevor Wu if (!etdm_priv)
26832babb477STrevor Wu return -ENOMEM;
26842babb477STrevor Wu
26852babb477STrevor Wu afe_priv->dai_priv[i] = etdm_priv;
26862babb477STrevor Wu }
26872babb477STrevor Wu
26882babb477STrevor Wu afe_priv->dai_priv[MT8188_AFE_IO_DPTX] =
26892babb477STrevor Wu afe_priv->dai_priv[MT8188_AFE_IO_ETDM3_OUT];
26902babb477STrevor Wu
26912babb477STrevor Wu mt8188_dai_etdm_parse_of(afe);
26922babb477STrevor Wu return 0;
26932babb477STrevor Wu }
26942babb477STrevor Wu
mt8188_dai_etdm_register(struct mtk_base_afe * afe)26952babb477STrevor Wu int mt8188_dai_etdm_register(struct mtk_base_afe *afe)
26962babb477STrevor Wu {
26972babb477STrevor Wu struct mtk_base_afe_dai *dai;
26982babb477STrevor Wu
26992babb477STrevor Wu dai = devm_kzalloc(afe->dev, sizeof(*dai), GFP_KERNEL);
27002babb477STrevor Wu if (!dai)
27012babb477STrevor Wu return -ENOMEM;
27022babb477STrevor Wu
27032babb477STrevor Wu list_add(&dai->list, &afe->sub_dais);
27042babb477STrevor Wu
27052babb477STrevor Wu dai->dai_drivers = mtk_dai_etdm_driver;
27062babb477STrevor Wu dai->num_dai_drivers = ARRAY_SIZE(mtk_dai_etdm_driver);
27072babb477STrevor Wu
27082babb477STrevor Wu dai->dapm_widgets = mtk_dai_etdm_widgets;
27092babb477STrevor Wu dai->num_dapm_widgets = ARRAY_SIZE(mtk_dai_etdm_widgets);
27102babb477STrevor Wu dai->dapm_routes = mtk_dai_etdm_routes;
27112babb477STrevor Wu dai->num_dapm_routes = ARRAY_SIZE(mtk_dai_etdm_routes);
27122babb477STrevor Wu dai->controls = mtk_dai_etdm_controls;
27132babb477STrevor Wu dai->num_controls = ARRAY_SIZE(mtk_dai_etdm_controls);
27142babb477STrevor Wu
27152babb477STrevor Wu return init_etdm_priv_data(afe);
27162babb477STrevor Wu }
2717