1 From ddf6abc1c78072f8ccad59166be95f0ca5af8ca4 Mon Sep 17 00:00:00 2001
2 From: Maso Huang <maso.huang@mediatek.com>
3 Date: Thu, 17 Aug 2023 18:13:36 +0800
4 Subject: [PATCH 4/9] ASoC: mediatek: mt7986: add machine driver with wm8960
6 Add support for mt7986 board with wm8960.
8 Signed-off-by: Maso Huang <maso.huang@mediatek.com>
9 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
10 Link: https://lore.kernel.org/r/20230817101338.18782-5-maso.huang@mediatek.com
11 Signed-off-by: Mark Brown <broonie@kernel.org>
13 sound/soc/mediatek/Kconfig | 10 ++
14 sound/soc/mediatek/mt7986/Makefile | 1 +
15 sound/soc/mediatek/mt7986/mt7986-wm8960.c | 196 ++++++++++++++++++++++
16 3 files changed, 207 insertions(+)
17 create mode 100644 sound/soc/mediatek/mt7986/mt7986-wm8960.c
19 --- a/sound/soc/mediatek/Kconfig
20 +++ b/sound/soc/mediatek/Kconfig
21 @@ -64,6 +64,16 @@ config SND_SOC_MT7986
22 Select Y if you have such device.
25 +config SND_SOC_MT7986_WM8960
26 + tristate "ASoc Audio driver for MT7986 with WM8960 codec"
27 + depends on SND_SOC_MT7986 && I2C
28 + select SND_SOC_WM8960
30 + This adds support for ASoC machine driver for MediaTek MT7986
31 + boards with the WM8960 codecs.
32 + Select Y if you have such device.
33 + If unsure select "N".
36 tristate "ASoC support for Mediatek MT8173 chip"
37 depends on ARCH_MEDIATEK
38 --- a/sound/soc/mediatek/mt7986/Makefile
39 +++ b/sound/soc/mediatek/mt7986/Makefile
40 @@ -6,3 +6,4 @@ snd-soc-mt7986-afe-objs := \
43 obj-$(CONFIG_SND_SOC_MT7986) += snd-soc-mt7986-afe.o
44 +obj-$(CONFIG_SND_SOC_MT7986_WM8960) += mt7986-wm8960.o
46 +++ b/sound/soc/mediatek/mt7986/mt7986-wm8960.c
48 +// SPDX-License-Identifier: GPL-2.0
50 + * mt7986-wm8960.c -- MT7986-WM8960 ALSA SoC machine driver
52 + * Copyright (c) 2023 MediaTek Inc.
53 + * Authors: Vic Wu <vic.wu@mediatek.com>
54 + * Maso Huang <maso.huang@mediatek.com>
57 +#include <linux/module.h>
58 +#include <sound/soc.h>
60 +#include "mt7986-afe-common.h"
62 +struct mt7986_wm8960_priv {
63 + struct device_node *platform_node;
64 + struct device_node *codec_node;
67 +static const struct snd_soc_dapm_widget mt7986_wm8960_widgets[] = {
68 + SND_SOC_DAPM_HP("Headphone", NULL),
69 + SND_SOC_DAPM_MIC("AMIC", NULL),
72 +static const struct snd_kcontrol_new mt7986_wm8960_controls[] = {
73 + SOC_DAPM_PIN_SWITCH("Headphone"),
74 + SOC_DAPM_PIN_SWITCH("AMIC"),
77 +SND_SOC_DAILINK_DEFS(playback,
78 + DAILINK_COMP_ARRAY(COMP_CPU("DL1")),
79 + DAILINK_COMP_ARRAY(COMP_DUMMY()),
80 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
82 +SND_SOC_DAILINK_DEFS(capture,
83 + DAILINK_COMP_ARRAY(COMP_CPU("UL1")),
84 + DAILINK_COMP_ARRAY(COMP_DUMMY()),
85 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
87 +SND_SOC_DAILINK_DEFS(codec,
88 + DAILINK_COMP_ARRAY(COMP_CPU("ETDM")),
89 + DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8960-hifi")),
90 + DAILINK_COMP_ARRAY(COMP_EMPTY()));
92 +static struct snd_soc_dai_link mt7986_wm8960_dai_links[] = {
95 + .name = "wm8960-playback",
96 + .stream_name = "wm8960-playback",
97 + .trigger = {SND_SOC_DPCM_TRIGGER_POST,
98 + SND_SOC_DPCM_TRIGGER_POST},
100 + .dpcm_playback = 1,
101 + SND_SOC_DAILINK_REG(playback),
104 + .name = "wm8960-capture",
105 + .stream_name = "wm8960-capture",
106 + .trigger = {SND_SOC_DPCM_TRIGGER_POST,
107 + SND_SOC_DPCM_TRIGGER_POST},
110 + SND_SOC_DAILINK_REG(capture),
114 + .name = "wm8960-codec",
116 + .dai_fmt = SND_SOC_DAIFMT_I2S |
117 + SND_SOC_DAIFMT_NB_NF |
118 + SND_SOC_DAIFMT_CBS_CFS |
119 + SND_SOC_DAIFMT_GATED,
120 + .dpcm_playback = 1,
122 + SND_SOC_DAILINK_REG(codec),
126 +static struct snd_soc_card mt7986_wm8960_card = {
127 + .name = "mt7986-wm8960",
128 + .owner = THIS_MODULE,
129 + .dai_link = mt7986_wm8960_dai_links,
130 + .num_links = ARRAY_SIZE(mt7986_wm8960_dai_links),
131 + .controls = mt7986_wm8960_controls,
132 + .num_controls = ARRAY_SIZE(mt7986_wm8960_controls),
133 + .dapm_widgets = mt7986_wm8960_widgets,
134 + .num_dapm_widgets = ARRAY_SIZE(mt7986_wm8960_widgets),
137 +static int mt7986_wm8960_machine_probe(struct platform_device *pdev)
139 + struct snd_soc_card *card = &mt7986_wm8960_card;
140 + struct snd_soc_dai_link *dai_link;
141 + struct device_node *platform, *codec;
142 + struct mt7986_wm8960_priv *priv;
145 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
149 + platform = of_get_child_by_name(pdev->dev.of_node, "platform");
152 + priv->platform_node = of_parse_phandle(platform, "sound-dai", 0);
153 + of_node_put(platform);
155 + if (!priv->platform_node) {
156 + dev_err(&pdev->dev, "Failed to parse platform/sound-dai property\n");
160 + dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
164 + for_each_card_prelinks(card, i, dai_link) {
165 + if (dai_link->platforms->name)
167 + dai_link->platforms->of_node = priv->platform_node;
170 + card->dev = &pdev->dev;
172 + codec = of_get_child_by_name(pdev->dev.of_node, "codec");
175 + priv->codec_node = of_parse_phandle(codec, "sound-dai", 0);
176 + of_node_put(codec);
178 + if (!priv->codec_node) {
179 + of_node_put(priv->platform_node);
180 + dev_err(&pdev->dev, "Failed to parse codec/sound-dai property\n");
184 + of_node_put(priv->platform_node);
185 + dev_err(&pdev->dev, "Property 'codec' missing or invalid\n");
189 + for_each_card_prelinks(card, i, dai_link) {
190 + if (dai_link->codecs->name)
192 + dai_link->codecs->of_node = priv->codec_node;
195 + ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
197 + dev_err(&pdev->dev, "Failed to parse audio-routing: %d\n", ret);
198 + goto err_of_node_put;
201 + ret = devm_snd_soc_register_card(&pdev->dev, card);
203 + dev_err(&pdev->dev, "%s snd_soc_register_card fail: %d\n", __func__, ret);
204 + goto err_of_node_put;
208 + of_node_put(priv->codec_node);
209 + of_node_put(priv->platform_node);
213 +static void mt7986_wm8960_machine_remove(struct platform_device *pdev)
215 + struct snd_soc_card *card = platform_get_drvdata(pdev);
216 + struct mt7986_wm8960_priv *priv = snd_soc_card_get_drvdata(card);
218 + of_node_put(priv->codec_node);
219 + of_node_put(priv->platform_node);
222 +static const struct of_device_id mt7986_wm8960_machine_dt_match[] = {
223 + {.compatible = "mediatek,mt7986-wm8960-sound"},
226 +MODULE_DEVICE_TABLE(of, mt7986_wm8960_machine_dt_match);
228 +static struct platform_driver mt7986_wm8960_machine = {
230 + .name = "mt7986-wm8960",
231 + .of_match_table = mt7986_wm8960_machine_dt_match,
233 + .probe = mt7986_wm8960_machine_probe,
234 + .remove_new = mt7986_wm8960_machine_remove,
237 +module_platform_driver(mt7986_wm8960_machine);
239 +/* Module information */
240 +MODULE_DESCRIPTION("MT7986 WM8960 ALSA SoC machine driver");
241 +MODULE_AUTHOR("Vic Wu <vic.wu@mediatek.com>");
242 +MODULE_LICENSE("GPL");
243 +MODULE_ALIAS("mt7986 wm8960 soc card");