18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * mt2701-cs42448.c -- MT2701 CS42448 ALSA SoC machine driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2016 MediaTek Inc. 68c2ecf20Sopenharmony_ci * Author: Ir Lian <ir.lian@mediatek.com> 78c2ecf20Sopenharmony_ci * Garlic Tseng <garlic.tseng@mediatek.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/module.h> 118c2ecf20Sopenharmony_ci#include <sound/soc.h> 128c2ecf20Sopenharmony_ci#include <linux/delay.h> 138c2ecf20Sopenharmony_ci#include <linux/gpio.h> 148c2ecf20Sopenharmony_ci#include <linux/pinctrl/consumer.h> 158c2ecf20Sopenharmony_ci#include <linux/of_gpio.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include "mt2701-afe-common.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistruct mt2701_cs42448_private { 208c2ecf20Sopenharmony_ci int i2s1_in_mux; 218c2ecf20Sopenharmony_ci int i2s1_in_mux_gpio_sel_1; 228c2ecf20Sopenharmony_ci int i2s1_in_mux_gpio_sel_2; 238c2ecf20Sopenharmony_ci}; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistatic const char * const i2sin_mux_switch_text[] = { 268c2ecf20Sopenharmony_ci "ADC_SDOUT2", 278c2ecf20Sopenharmony_ci "ADC_SDOUT3", 288c2ecf20Sopenharmony_ci "I2S_IN_1", 298c2ecf20Sopenharmony_ci "I2S_IN_2", 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistatic const struct soc_enum i2sin_mux_enum = 338c2ecf20Sopenharmony_ci SOC_ENUM_SINGLE_EXT(4, i2sin_mux_switch_text); 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic int mt2701_cs42448_i2sin1_mux_get(struct snd_kcontrol *kcontrol, 368c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); 398c2ecf20Sopenharmony_ci struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci ucontrol->value.integer.value[0] = priv->i2s1_in_mux; 428c2ecf20Sopenharmony_ci return 0; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic int mt2701_cs42448_i2sin1_mux_set(struct snd_kcontrol *kcontrol, 468c2ecf20Sopenharmony_ci struct snd_ctl_elem_value *ucontrol) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); 498c2ecf20Sopenharmony_ci struct mt2701_cs42448_private *priv = snd_soc_card_get_drvdata(card); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci if (ucontrol->value.integer.value[0] == priv->i2s1_in_mux) 528c2ecf20Sopenharmony_ci return 0; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci switch (ucontrol->value.integer.value[0]) { 558c2ecf20Sopenharmony_ci case 0: 568c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_1, 0); 578c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_2, 0); 588c2ecf20Sopenharmony_ci break; 598c2ecf20Sopenharmony_ci case 1: 608c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_1, 1); 618c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_2, 0); 628c2ecf20Sopenharmony_ci break; 638c2ecf20Sopenharmony_ci case 2: 648c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_1, 0); 658c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_2, 1); 668c2ecf20Sopenharmony_ci break; 678c2ecf20Sopenharmony_ci case 3: 688c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_1, 1); 698c2ecf20Sopenharmony_ci gpio_set_value(priv->i2s1_in_mux_gpio_sel_2, 1); 708c2ecf20Sopenharmony_ci break; 718c2ecf20Sopenharmony_ci default: 728c2ecf20Sopenharmony_ci dev_warn(card->dev, "%s invalid setting\n", __func__); 738c2ecf20Sopenharmony_ci } 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci priv->i2s1_in_mux = ucontrol->value.integer.value[0]; 768c2ecf20Sopenharmony_ci return 0; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget 808c2ecf20Sopenharmony_ci mt2701_cs42448_asoc_card_dapm_widgets[] = { 818c2ecf20Sopenharmony_ci SND_SOC_DAPM_LINE("Line Out Jack", NULL), 828c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIC("AMIC", NULL), 838c2ecf20Sopenharmony_ci SND_SOC_DAPM_LINE("Tuner In", NULL), 848c2ecf20Sopenharmony_ci SND_SOC_DAPM_LINE("Satellite Tuner In", NULL), 858c2ecf20Sopenharmony_ci SND_SOC_DAPM_LINE("AUX In", NULL), 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new mt2701_cs42448_controls[] = { 898c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Line Out Jack"), 908c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("AMIC"), 918c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Tuner In"), 928c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("Satellite Tuner In"), 938c2ecf20Sopenharmony_ci SOC_DAPM_PIN_SWITCH("AUX In"), 948c2ecf20Sopenharmony_ci SOC_ENUM_EXT("I2SIN1_MUX_Switch", i2sin_mux_enum, 958c2ecf20Sopenharmony_ci mt2701_cs42448_i2sin1_mux_get, 968c2ecf20Sopenharmony_ci mt2701_cs42448_i2sin1_mux_set), 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistatic const unsigned int mt2701_cs42448_sampling_rates[] = {48000}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistatic const struct snd_pcm_hw_constraint_list mt2701_cs42448_constraints_rates = { 1028c2ecf20Sopenharmony_ci .count = ARRAY_SIZE(mt2701_cs42448_sampling_rates), 1038c2ecf20Sopenharmony_ci .list = mt2701_cs42448_sampling_rates, 1048c2ecf20Sopenharmony_ci .mask = 0, 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistatic int mt2701_cs42448_fe_ops_startup(struct snd_pcm_substream *substream) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci int err; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci err = snd_pcm_hw_constraint_list(substream->runtime, 0, 1128c2ecf20Sopenharmony_ci SNDRV_PCM_HW_PARAM_RATE, 1138c2ecf20Sopenharmony_ci &mt2701_cs42448_constraints_rates); 1148c2ecf20Sopenharmony_ci if (err < 0) { 1158c2ecf20Sopenharmony_ci dev_err(substream->pcm->card->dev, 1168c2ecf20Sopenharmony_ci "%s snd_pcm_hw_constraint_list failed: 0x%x\n", 1178c2ecf20Sopenharmony_ci __func__, err); 1188c2ecf20Sopenharmony_ci return err; 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci return 0; 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic const struct snd_soc_ops mt2701_cs42448_48k_fe_ops = { 1248c2ecf20Sopenharmony_ci .startup = mt2701_cs42448_fe_ops_startup, 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic int mt2701_cs42448_be_ops_hw_params(struct snd_pcm_substream *substream, 1288c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 1318c2ecf20Sopenharmony_ci struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 1328c2ecf20Sopenharmony_ci struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 1338c2ecf20Sopenharmony_ci unsigned int mclk_rate; 1348c2ecf20Sopenharmony_ci unsigned int rate = params_rate(params); 1358c2ecf20Sopenharmony_ci unsigned int div_mclk_over_bck = rate > 192000 ? 2 : 4; 1368c2ecf20Sopenharmony_ci unsigned int div_bck_over_lrck = 64; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci mclk_rate = rate * div_bck_over_lrck * div_mclk_over_bck; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* mt2701 mclk */ 1418c2ecf20Sopenharmony_ci snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate, SND_SOC_CLOCK_OUT); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci /* codec mclk */ 1448c2ecf20Sopenharmony_ci snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate, SND_SOC_CLOCK_IN); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci return 0; 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic struct snd_soc_ops mt2701_cs42448_be_ops = { 1508c2ecf20Sopenharmony_ci .hw_params = mt2701_cs42448_be_ops_hw_params 1518c2ecf20Sopenharmony_ci}; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cienum { 1548c2ecf20Sopenharmony_ci DAI_LINK_FE_MULTI_CH_OUT, 1558c2ecf20Sopenharmony_ci DAI_LINK_FE_PCM0_IN, 1568c2ecf20Sopenharmony_ci DAI_LINK_FE_PCM1_IN, 1578c2ecf20Sopenharmony_ci DAI_LINK_FE_BT_OUT, 1588c2ecf20Sopenharmony_ci DAI_LINK_FE_BT_IN, 1598c2ecf20Sopenharmony_ci DAI_LINK_BE_I2S0, 1608c2ecf20Sopenharmony_ci DAI_LINK_BE_I2S1, 1618c2ecf20Sopenharmony_ci DAI_LINK_BE_I2S2, 1628c2ecf20Sopenharmony_ci DAI_LINK_BE_I2S3, 1638c2ecf20Sopenharmony_ci DAI_LINK_BE_MRG_BT, 1648c2ecf20Sopenharmony_ci}; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(fe_multi_ch_out, 1678c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("PCM_multi")), 1688c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_DUMMY()), 1698c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(fe_pcm0_in, 1728c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("PCM0")), 1738c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_DUMMY()), 1748c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(fe_pcm1_in, 1778c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("PCM1")), 1788c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_DUMMY()), 1798c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(fe_bt_out, 1828c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("PCM_BT_DL")), 1838c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_DUMMY()), 1848c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(fe_bt_in, 1878c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("PCM_BT_UL")), 1888c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_DUMMY()), 1898c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(be_i2s0, 1928c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("I2S0")), 1938c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")), 1948c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(be_i2s1, 1978c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("I2S1")), 1988c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")), 1998c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(be_i2s2, 2028c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("I2S2")), 2038c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")), 2048c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(be_i2s3, 2078c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("I2S3")), 2088c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "cs42448")), 2098c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(be_mrg_bt, 2128c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("MRG BT")), 2138c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "bt-sco-pcm-wb")), 2148c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_EMPTY())); 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_cistatic struct snd_soc_dai_link mt2701_cs42448_dai_links[] = { 2178c2ecf20Sopenharmony_ci /* FE */ 2188c2ecf20Sopenharmony_ci [DAI_LINK_FE_MULTI_CH_OUT] = { 2198c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-multi-ch-out", 2208c2ecf20Sopenharmony_ci .stream_name = "mt2701-cs42448-multi-ch-out", 2218c2ecf20Sopenharmony_ci .trigger = {SND_SOC_DPCM_TRIGGER_POST, 2228c2ecf20Sopenharmony_ci SND_SOC_DPCM_TRIGGER_POST}, 2238c2ecf20Sopenharmony_ci .ops = &mt2701_cs42448_48k_fe_ops, 2248c2ecf20Sopenharmony_ci .dynamic = 1, 2258c2ecf20Sopenharmony_ci .dpcm_playback = 1, 2268c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(fe_multi_ch_out), 2278c2ecf20Sopenharmony_ci }, 2288c2ecf20Sopenharmony_ci [DAI_LINK_FE_PCM0_IN] = { 2298c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-pcm0", 2308c2ecf20Sopenharmony_ci .stream_name = "mt2701-cs42448-pcm0-data-UL", 2318c2ecf20Sopenharmony_ci .trigger = {SND_SOC_DPCM_TRIGGER_POST, 2328c2ecf20Sopenharmony_ci SND_SOC_DPCM_TRIGGER_POST}, 2338c2ecf20Sopenharmony_ci .ops = &mt2701_cs42448_48k_fe_ops, 2348c2ecf20Sopenharmony_ci .dynamic = 1, 2358c2ecf20Sopenharmony_ci .dpcm_capture = 1, 2368c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(fe_pcm0_in), 2378c2ecf20Sopenharmony_ci }, 2388c2ecf20Sopenharmony_ci [DAI_LINK_FE_PCM1_IN] = { 2398c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-pcm1-data-UL", 2408c2ecf20Sopenharmony_ci .stream_name = "mt2701-cs42448-pcm1-data-UL", 2418c2ecf20Sopenharmony_ci .trigger = {SND_SOC_DPCM_TRIGGER_POST, 2428c2ecf20Sopenharmony_ci SND_SOC_DPCM_TRIGGER_POST}, 2438c2ecf20Sopenharmony_ci .ops = &mt2701_cs42448_48k_fe_ops, 2448c2ecf20Sopenharmony_ci .dynamic = 1, 2458c2ecf20Sopenharmony_ci .dpcm_capture = 1, 2468c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(fe_pcm1_in), 2478c2ecf20Sopenharmony_ci }, 2488c2ecf20Sopenharmony_ci [DAI_LINK_FE_BT_OUT] = { 2498c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-pcm-BT-out", 2508c2ecf20Sopenharmony_ci .stream_name = "mt2701-cs42448-pcm-BT", 2518c2ecf20Sopenharmony_ci .trigger = {SND_SOC_DPCM_TRIGGER_POST, 2528c2ecf20Sopenharmony_ci SND_SOC_DPCM_TRIGGER_POST}, 2538c2ecf20Sopenharmony_ci .dynamic = 1, 2548c2ecf20Sopenharmony_ci .dpcm_playback = 1, 2558c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(fe_bt_out), 2568c2ecf20Sopenharmony_ci }, 2578c2ecf20Sopenharmony_ci [DAI_LINK_FE_BT_IN] = { 2588c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-pcm-BT-in", 2598c2ecf20Sopenharmony_ci .stream_name = "mt2701-cs42448-pcm-BT", 2608c2ecf20Sopenharmony_ci .trigger = {SND_SOC_DPCM_TRIGGER_POST, 2618c2ecf20Sopenharmony_ci SND_SOC_DPCM_TRIGGER_POST}, 2628c2ecf20Sopenharmony_ci .dynamic = 1, 2638c2ecf20Sopenharmony_ci .dpcm_capture = 1, 2648c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(fe_bt_in), 2658c2ecf20Sopenharmony_ci }, 2668c2ecf20Sopenharmony_ci /* BE */ 2678c2ecf20Sopenharmony_ci [DAI_LINK_BE_I2S0] = { 2688c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-I2S0", 2698c2ecf20Sopenharmony_ci .no_pcm = 1, 2708c2ecf20Sopenharmony_ci .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS 2718c2ecf20Sopenharmony_ci | SND_SOC_DAIFMT_GATED, 2728c2ecf20Sopenharmony_ci .ops = &mt2701_cs42448_be_ops, 2738c2ecf20Sopenharmony_ci .dpcm_playback = 1, 2748c2ecf20Sopenharmony_ci .dpcm_capture = 1, 2758c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(be_i2s0), 2768c2ecf20Sopenharmony_ci }, 2778c2ecf20Sopenharmony_ci [DAI_LINK_BE_I2S1] = { 2788c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-I2S1", 2798c2ecf20Sopenharmony_ci .no_pcm = 1, 2808c2ecf20Sopenharmony_ci .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS 2818c2ecf20Sopenharmony_ci | SND_SOC_DAIFMT_GATED, 2828c2ecf20Sopenharmony_ci .ops = &mt2701_cs42448_be_ops, 2838c2ecf20Sopenharmony_ci .dpcm_playback = 1, 2848c2ecf20Sopenharmony_ci .dpcm_capture = 1, 2858c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(be_i2s1), 2868c2ecf20Sopenharmony_ci }, 2878c2ecf20Sopenharmony_ci [DAI_LINK_BE_I2S2] = { 2888c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-I2S2", 2898c2ecf20Sopenharmony_ci .no_pcm = 1, 2908c2ecf20Sopenharmony_ci .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS 2918c2ecf20Sopenharmony_ci | SND_SOC_DAIFMT_GATED, 2928c2ecf20Sopenharmony_ci .ops = &mt2701_cs42448_be_ops, 2938c2ecf20Sopenharmony_ci .dpcm_playback = 1, 2948c2ecf20Sopenharmony_ci .dpcm_capture = 1, 2958c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(be_i2s2), 2968c2ecf20Sopenharmony_ci }, 2978c2ecf20Sopenharmony_ci [DAI_LINK_BE_I2S3] = { 2988c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-I2S3", 2998c2ecf20Sopenharmony_ci .no_pcm = 1, 3008c2ecf20Sopenharmony_ci .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS 3018c2ecf20Sopenharmony_ci | SND_SOC_DAIFMT_GATED, 3028c2ecf20Sopenharmony_ci .ops = &mt2701_cs42448_be_ops, 3038c2ecf20Sopenharmony_ci .dpcm_playback = 1, 3048c2ecf20Sopenharmony_ci .dpcm_capture = 1, 3058c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(be_i2s3), 3068c2ecf20Sopenharmony_ci }, 3078c2ecf20Sopenharmony_ci [DAI_LINK_BE_MRG_BT] = { 3088c2ecf20Sopenharmony_ci .name = "mt2701-cs42448-MRG-BT", 3098c2ecf20Sopenharmony_ci .no_pcm = 1, 3108c2ecf20Sopenharmony_ci .dpcm_playback = 1, 3118c2ecf20Sopenharmony_ci .dpcm_capture = 1, 3128c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(be_mrg_bt), 3138c2ecf20Sopenharmony_ci }, 3148c2ecf20Sopenharmony_ci}; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_cistatic struct snd_soc_card mt2701_cs42448_soc_card = { 3178c2ecf20Sopenharmony_ci .name = "mt2701-cs42448", 3188c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 3198c2ecf20Sopenharmony_ci .dai_link = mt2701_cs42448_dai_links, 3208c2ecf20Sopenharmony_ci .num_links = ARRAY_SIZE(mt2701_cs42448_dai_links), 3218c2ecf20Sopenharmony_ci .controls = mt2701_cs42448_controls, 3228c2ecf20Sopenharmony_ci .num_controls = ARRAY_SIZE(mt2701_cs42448_controls), 3238c2ecf20Sopenharmony_ci .dapm_widgets = mt2701_cs42448_asoc_card_dapm_widgets, 3248c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(mt2701_cs42448_asoc_card_dapm_widgets), 3258c2ecf20Sopenharmony_ci}; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_cistatic int mt2701_cs42448_machine_probe(struct platform_device *pdev) 3288c2ecf20Sopenharmony_ci{ 3298c2ecf20Sopenharmony_ci struct snd_soc_card *card = &mt2701_cs42448_soc_card; 3308c2ecf20Sopenharmony_ci int ret; 3318c2ecf20Sopenharmony_ci int i; 3328c2ecf20Sopenharmony_ci struct device_node *platform_node, *codec_node, *codec_node_bt_mrg; 3338c2ecf20Sopenharmony_ci struct mt2701_cs42448_private *priv = 3348c2ecf20Sopenharmony_ci devm_kzalloc(&pdev->dev, sizeof(struct mt2701_cs42448_private), 3358c2ecf20Sopenharmony_ci GFP_KERNEL); 3368c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 3378c2ecf20Sopenharmony_ci struct snd_soc_dai_link *dai_link; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci if (!priv) 3408c2ecf20Sopenharmony_ci return -ENOMEM; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci platform_node = of_parse_phandle(pdev->dev.of_node, 3438c2ecf20Sopenharmony_ci "mediatek,platform", 0); 3448c2ecf20Sopenharmony_ci if (!platform_node) { 3458c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "Property 'platform' missing or invalid\n"); 3468c2ecf20Sopenharmony_ci return -EINVAL; 3478c2ecf20Sopenharmony_ci } 3488c2ecf20Sopenharmony_ci for_each_card_prelinks(card, i, dai_link) { 3498c2ecf20Sopenharmony_ci if (dai_link->platforms->name) 3508c2ecf20Sopenharmony_ci continue; 3518c2ecf20Sopenharmony_ci dai_link->platforms->of_node = platform_node; 3528c2ecf20Sopenharmony_ci } 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci card->dev = dev; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci codec_node = of_parse_phandle(pdev->dev.of_node, 3578c2ecf20Sopenharmony_ci "mediatek,audio-codec", 0); 3588c2ecf20Sopenharmony_ci if (!codec_node) { 3598c2ecf20Sopenharmony_ci dev_err(&pdev->dev, 3608c2ecf20Sopenharmony_ci "Property 'audio-codec' missing or invalid\n"); 3618c2ecf20Sopenharmony_ci return -EINVAL; 3628c2ecf20Sopenharmony_ci } 3638c2ecf20Sopenharmony_ci for_each_card_prelinks(card, i, dai_link) { 3648c2ecf20Sopenharmony_ci if (dai_link->codecs->name) 3658c2ecf20Sopenharmony_ci continue; 3668c2ecf20Sopenharmony_ci dai_link->codecs->of_node = codec_node; 3678c2ecf20Sopenharmony_ci } 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci codec_node_bt_mrg = of_parse_phandle(pdev->dev.of_node, 3708c2ecf20Sopenharmony_ci "mediatek,audio-codec-bt-mrg", 0); 3718c2ecf20Sopenharmony_ci if (!codec_node_bt_mrg) { 3728c2ecf20Sopenharmony_ci dev_err(&pdev->dev, 3738c2ecf20Sopenharmony_ci "Property 'audio-codec-bt-mrg' missing or invalid\n"); 3748c2ecf20Sopenharmony_ci return -EINVAL; 3758c2ecf20Sopenharmony_ci } 3768c2ecf20Sopenharmony_ci mt2701_cs42448_dai_links[DAI_LINK_BE_MRG_BT].codecs->of_node 3778c2ecf20Sopenharmony_ci = codec_node_bt_mrg; 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci ret = snd_soc_of_parse_audio_routing(card, "audio-routing"); 3808c2ecf20Sopenharmony_ci if (ret) { 3818c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret); 3828c2ecf20Sopenharmony_ci return ret; 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci priv->i2s1_in_mux_gpio_sel_1 = 3868c2ecf20Sopenharmony_ci of_get_named_gpio(dev->of_node, "i2s1-in-sel-gpio1", 0); 3878c2ecf20Sopenharmony_ci if (gpio_is_valid(priv->i2s1_in_mux_gpio_sel_1)) { 3888c2ecf20Sopenharmony_ci ret = devm_gpio_request(dev, priv->i2s1_in_mux_gpio_sel_1, 3898c2ecf20Sopenharmony_ci "i2s1_in_mux_gpio_sel_1"); 3908c2ecf20Sopenharmony_ci if (ret) 3918c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "%s devm_gpio_request fail %d\n", 3928c2ecf20Sopenharmony_ci __func__, ret); 3938c2ecf20Sopenharmony_ci gpio_direction_output(priv->i2s1_in_mux_gpio_sel_1, 0); 3948c2ecf20Sopenharmony_ci } 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci priv->i2s1_in_mux_gpio_sel_2 = 3978c2ecf20Sopenharmony_ci of_get_named_gpio(dev->of_node, "i2s1-in-sel-gpio2", 0); 3988c2ecf20Sopenharmony_ci if (gpio_is_valid(priv->i2s1_in_mux_gpio_sel_2)) { 3998c2ecf20Sopenharmony_ci ret = devm_gpio_request(dev, priv->i2s1_in_mux_gpio_sel_2, 4008c2ecf20Sopenharmony_ci "i2s1_in_mux_gpio_sel_2"); 4018c2ecf20Sopenharmony_ci if (ret) 4028c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "%s devm_gpio_request fail2 %d\n", 4038c2ecf20Sopenharmony_ci __func__, ret); 4048c2ecf20Sopenharmony_ci gpio_direction_output(priv->i2s1_in_mux_gpio_sel_2, 0); 4058c2ecf20Sopenharmony_ci } 4068c2ecf20Sopenharmony_ci snd_soc_card_set_drvdata(card, priv); 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci ret = devm_snd_soc_register_card(&pdev->dev, card); 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci if (ret) 4118c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n", 4128c2ecf20Sopenharmony_ci __func__, ret); 4138c2ecf20Sopenharmony_ci return ret; 4148c2ecf20Sopenharmony_ci} 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci#ifdef CONFIG_OF 4178c2ecf20Sopenharmony_cistatic const struct of_device_id mt2701_cs42448_machine_dt_match[] = { 4188c2ecf20Sopenharmony_ci {.compatible = "mediatek,mt2701-cs42448-machine",}, 4198c2ecf20Sopenharmony_ci {} 4208c2ecf20Sopenharmony_ci}; 4218c2ecf20Sopenharmony_ci#endif 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_cistatic struct platform_driver mt2701_cs42448_machine = { 4248c2ecf20Sopenharmony_ci .driver = { 4258c2ecf20Sopenharmony_ci .name = "mt2701-cs42448", 4268c2ecf20Sopenharmony_ci #ifdef CONFIG_OF 4278c2ecf20Sopenharmony_ci .of_match_table = mt2701_cs42448_machine_dt_match, 4288c2ecf20Sopenharmony_ci #endif 4298c2ecf20Sopenharmony_ci }, 4308c2ecf20Sopenharmony_ci .probe = mt2701_cs42448_machine_probe, 4318c2ecf20Sopenharmony_ci}; 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_cimodule_platform_driver(mt2701_cs42448_machine); 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci/* Module information */ 4368c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("MT2701 CS42448 ALSA SoC machine driver"); 4378c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ir Lian <ir.lian@mediatek.com>"); 4388c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 4398c2ecf20Sopenharmony_ciMODULE_ALIAS("mt2701 cs42448 soc card"); 440