mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-11 12:44:49 -04:00
ASoC: mediatek: mt8188-mt6359: commonize headset codec init/exit api
Reduce code duplication, unify the headset codec init/exit api. Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Rui Zhou <zhourui@huaqin.corp-partner.google.com> Link: https://msgid.link/r/20231212123050.4080083-3-zhourui@huaqin.corp-partner.google.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
@@ -726,7 +726,7 @@ static int mt8188_max98390_codec_init(struct snd_soc_pcm_runtime *rtd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mt8188_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
|
||||
static int mt8188_headset_codec_init(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
struct snd_soc_card *card = rtd->card;
|
||||
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card);
|
||||
@@ -775,68 +775,13 @@ static int mt8188_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
|
||||
return 0;
|
||||
};
|
||||
|
||||
static int mt8188_rt5682s_codec_init(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
struct snd_soc_card *card = rtd->card;
|
||||
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card);
|
||||
struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv;
|
||||
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
|
||||
struct snd_soc_jack *jack = &priv->headset_jack;
|
||||
int ret;
|
||||
|
||||
ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets,
|
||||
ARRAY_SIZE(mt8188_nau8825_widgets));
|
||||
if (ret) {
|
||||
dev_err(rtd->dev, "unable to add rt5682s card widget, ret %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = snd_soc_add_card_controls(card, mt8188_nau8825_controls,
|
||||
ARRAY_SIZE(mt8188_nau8825_controls));
|
||||
if (ret) {
|
||||
dev_err(rtd->dev, "unable to add rt5682s card controls, ret %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
|
||||
SND_JACK_HEADSET | SND_JACK_BTN_0 |
|
||||
SND_JACK_BTN_1 | SND_JACK_BTN_2 |
|
||||
SND_JACK_BTN_3,
|
||||
jack,
|
||||
nau8825_jack_pins,
|
||||
ARRAY_SIZE(nau8825_jack_pins));
|
||||
if (ret) {
|
||||
dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
|
||||
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
|
||||
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
|
||||
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
|
||||
ret = snd_soc_component_set_jack(component, jack, NULL);
|
||||
|
||||
if (ret) {
|
||||
dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
static void mt8188_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd)
|
||||
static void mt8188_headset_codec_exit(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
|
||||
|
||||
snd_soc_component_set_jack(component, NULL, NULL);
|
||||
}
|
||||
|
||||
static void mt8188_rt5682s_codec_exit(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
|
||||
|
||||
snd_soc_component_set_jack(component, NULL, NULL);
|
||||
}
|
||||
|
||||
static int mt8188_nau8825_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params)
|
||||
@@ -1407,15 +1352,15 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
|
||||
} else if (!strcmp(dai_link->codecs->dai_name, NAU8825_CODEC_DAI)) {
|
||||
dai_link->ops = &mt8188_nau8825_ops;
|
||||
if (!init_nau8825) {
|
||||
dai_link->init = mt8188_nau8825_codec_init;
|
||||
dai_link->exit = mt8188_nau8825_codec_exit;
|
||||
dai_link->init = mt8188_headset_codec_init;
|
||||
dai_link->exit = mt8188_headset_codec_exit;
|
||||
init_nau8825 = true;
|
||||
}
|
||||
} else if (!strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) {
|
||||
dai_link->ops = &mt8188_rt5682s_i2s_ops;
|
||||
if (!init_rt5682s) {
|
||||
dai_link->init = mt8188_rt5682s_codec_init;
|
||||
dai_link->exit = mt8188_rt5682s_codec_exit;
|
||||
dai_link->init = mt8188_headset_codec_init;
|
||||
dai_link->exit = mt8188_headset_codec_exit;
|
||||
init_rt5682s = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user