1 // SPDX-License-Identifier: GPL-2.0
3 * mt8173-max98090.c -- MT8173 MAX98090 ALSA SoC machine driver
5 * Copyright (c) 2015 MediaTek Inc.
6 * Author: Koro Chen <koro.chen@mediatek.com>
9 #include <linux/module.h>
10 #include <sound/soc.h>
11 #include <sound/jack.h>
12 #include <linux/gpio.h>
13 #include "../../codecs/max98090.h"
15 static struct snd_soc_jack mt8173_max98090_jack;
17 static struct snd_soc_jack_pin mt8173_max98090_jack_pins[] = {
20 .mask = SND_JACK_HEADPHONE,
24 .mask = SND_JACK_MICROPHONE,
28 static const struct snd_soc_dapm_widget mt8173_max98090_widgets[] = {
29 SND_SOC_DAPM_SPK("Speaker", NULL),
30 SND_SOC_DAPM_MIC("Int Mic", NULL),
31 SND_SOC_DAPM_HP("Headphone", NULL),
32 SND_SOC_DAPM_MIC("Headset Mic", NULL),
35 static const struct snd_soc_dapm_route mt8173_max98090_routes[] = {
36 {"Speaker", NULL, "SPKL"},
37 {"Speaker", NULL, "SPKR"},
38 {"DMICL", NULL, "Int Mic"},
39 {"Headphone", NULL, "HPL"},
40 {"Headphone", NULL, "HPR"},
41 {"Headset Mic", NULL, "MICBIAS"},
42 {"IN34", NULL, "Headset Mic"},
45 static const struct snd_kcontrol_new mt8173_max98090_controls[] = {
46 SOC_DAPM_PIN_SWITCH("Speaker"),
47 SOC_DAPM_PIN_SWITCH("Int Mic"),
48 SOC_DAPM_PIN_SWITCH("Headphone"),
49 SOC_DAPM_PIN_SWITCH("Headset Mic"),
52 static int mt8173_max98090_hw_params(struct snd_pcm_substream *substream,
53 struct snd_pcm_hw_params *params)
55 struct snd_soc_pcm_runtime *rtd = substream->private_data;
56 struct snd_soc_dai *codec_dai = rtd->codec_dai;
58 return snd_soc_dai_set_sysclk(codec_dai, 0, params_rate(params) * 256,
62 static const struct snd_soc_ops mt8173_max98090_ops = {
63 .hw_params = mt8173_max98090_hw_params,
66 static int mt8173_max98090_init(struct snd_soc_pcm_runtime *runtime)
69 struct snd_soc_card *card = runtime->card;
70 struct snd_soc_component *component = runtime->codec_dai->component;
72 /* enable jack detection */
73 ret = snd_soc_card_jack_new(card, "Headphone", SND_JACK_HEADPHONE,
74 &mt8173_max98090_jack,
75 mt8173_max98090_jack_pins,
76 ARRAY_SIZE(mt8173_max98090_jack_pins));
78 dev_err(card->dev, "Can't create a new Jack %d\n", ret);
82 return max98090_mic_detect(component, &mt8173_max98090_jack);
85 /* Digital audio interface glue - connects codec <---> CPU */
86 static struct snd_soc_dai_link mt8173_max98090_dais[] = {
87 /* Front End DAI links */
89 .name = "MAX98090 Playback",
90 .stream_name = "MAX98090 Playback",
91 .cpu_dai_name = "DL1",
92 .codec_name = "snd-soc-dummy",
93 .codec_dai_name = "snd-soc-dummy-dai",
94 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
99 .name = "MAX98090 Capture",
100 .stream_name = "MAX98090 Capture",
101 .cpu_dai_name = "VUL",
102 .codec_name = "snd-soc-dummy",
103 .codec_dai_name = "snd-soc-dummy-dai",
104 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
108 /* Back End DAI links */
111 .cpu_dai_name = "I2S",
113 .codec_dai_name = "HiFi",
114 .init = mt8173_max98090_init,
115 .ops = &mt8173_max98090_ops,
116 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
117 SND_SOC_DAIFMT_CBS_CFS,
123 static struct snd_soc_card mt8173_max98090_card = {
124 .name = "mt8173-max98090",
125 .owner = THIS_MODULE,
126 .dai_link = mt8173_max98090_dais,
127 .num_links = ARRAY_SIZE(mt8173_max98090_dais),
128 .controls = mt8173_max98090_controls,
129 .num_controls = ARRAY_SIZE(mt8173_max98090_controls),
130 .dapm_widgets = mt8173_max98090_widgets,
131 .num_dapm_widgets = ARRAY_SIZE(mt8173_max98090_widgets),
132 .dapm_routes = mt8173_max98090_routes,
133 .num_dapm_routes = ARRAY_SIZE(mt8173_max98090_routes),
136 static int mt8173_max98090_dev_probe(struct platform_device *pdev)
138 struct snd_soc_card *card = &mt8173_max98090_card;
139 struct device_node *codec_node, *platform_node;
142 platform_node = of_parse_phandle(pdev->dev.of_node,
143 "mediatek,platform", 0);
144 if (!platform_node) {
145 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
148 for (i = 0; i < card->num_links; i++) {
149 if (mt8173_max98090_dais[i].platform_name)
151 mt8173_max98090_dais[i].platform_of_node = platform_node;
154 codec_node = of_parse_phandle(pdev->dev.of_node,
155 "mediatek,audio-codec", 0);
158 "Property 'audio-codec' missing or invalid\n");
160 goto put_platform_node;
162 for (i = 0; i < card->num_links; i++) {
163 if (mt8173_max98090_dais[i].codec_name)
165 mt8173_max98090_dais[i].codec_of_node = codec_node;
167 card->dev = &pdev->dev;
169 ret = devm_snd_soc_register_card(&pdev->dev, card);
171 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
174 of_node_put(codec_node);
177 of_node_put(platform_node);
181 static const struct of_device_id mt8173_max98090_dt_match[] = {
182 { .compatible = "mediatek,mt8173-max98090", },
185 MODULE_DEVICE_TABLE(of, mt8173_max98090_dt_match);
187 static struct platform_driver mt8173_max98090_driver = {
189 .name = "mt8173-max98090",
190 .of_match_table = mt8173_max98090_dt_match,
192 .pm = &snd_soc_pm_ops,
195 .probe = mt8173_max98090_dev_probe,
198 module_platform_driver(mt8173_max98090_driver);
200 /* Module information */
201 MODULE_DESCRIPTION("MT8173 MAX98090 ALSA SoC machine driver");
202 MODULE_AUTHOR("Koro Chen <koro.chen@mediatek.com>");
203 MODULE_LICENSE("GPL v2");
204 MODULE_ALIAS("platform:mt8173-max98090");