2 * mt8173-max98090.c -- MT8173 MAX98090 ALSA SoC machine driver
4 * Copyright (c) 2015 MediaTek Inc.
5 * Author: Koro Chen <koro.chen@mediatek.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 and
9 * only version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <sound/soc.h>
19 #include <sound/jack.h>
20 #include <linux/gpio.h>
21 #include "../codecs/max98090.h"
23 static struct snd_soc_jack mt8173_max98090_jack;
25 static struct snd_soc_jack_pin mt8173_max98090_jack_pins[] = {
28 .mask = SND_JACK_HEADPHONE,
32 .mask = SND_JACK_MICROPHONE,
36 static const struct snd_soc_dapm_widget mt8173_max98090_widgets[] = {
37 SND_SOC_DAPM_SPK("Speaker", NULL),
38 SND_SOC_DAPM_MIC("Int Mic", NULL),
39 SND_SOC_DAPM_HP("Headphone", NULL),
40 SND_SOC_DAPM_MIC("Headset Mic", NULL),
43 static const struct snd_soc_dapm_route mt8173_max98090_routes[] = {
44 {"Speaker", NULL, "SPKL"},
45 {"Speaker", NULL, "SPKR"},
46 {"DMICL", NULL, "Int Mic"},
47 {"Headphone", NULL, "HPL"},
48 {"Headphone", NULL, "HPR"},
49 {"Headset Mic", NULL, "MICBIAS"},
50 {"IN34", NULL, "Headset Mic"},
53 static const struct snd_kcontrol_new mt8173_max98090_controls[] = {
54 SOC_DAPM_PIN_SWITCH("Speaker"),
55 SOC_DAPM_PIN_SWITCH("Int Mic"),
56 SOC_DAPM_PIN_SWITCH("Headphone"),
57 SOC_DAPM_PIN_SWITCH("Headset Mic"),
60 static int mt8173_max98090_hw_params(struct snd_pcm_substream *substream,
61 struct snd_pcm_hw_params *params)
63 struct snd_soc_pcm_runtime *rtd = substream->private_data;
64 struct snd_soc_dai *codec_dai = rtd->codec_dai;
66 return snd_soc_dai_set_sysclk(codec_dai, 0, params_rate(params) * 256,
70 static struct snd_soc_ops mt8173_max98090_ops = {
71 .hw_params = mt8173_max98090_hw_params,
74 static int mt8173_max98090_init(struct snd_soc_pcm_runtime *runtime)
77 struct snd_soc_card *card = runtime->card;
78 struct snd_soc_codec *codec = runtime->codec;
80 /* enable jack detection */
81 ret = snd_soc_card_jack_new(card, "Headphone", SND_JACK_HEADPHONE,
82 &mt8173_max98090_jack, NULL, 0);
84 dev_err(card->dev, "Can't snd_soc_jack_new %d\n", ret);
88 ret = snd_soc_jack_add_pins(&mt8173_max98090_jack,
89 ARRAY_SIZE(mt8173_max98090_jack_pins),
90 mt8173_max98090_jack_pins);
92 dev_err(card->dev, "Can't snd_soc_jack_add_pins %d\n", ret);
96 return max98090_mic_detect(codec, &mt8173_max98090_jack);
99 /* Digital audio interface glue - connects codec <---> CPU */
100 static struct snd_soc_dai_link mt8173_max98090_dais[] = {
101 /* Front End DAI links */
103 .name = "MAX98090 Playback",
104 .stream_name = "MAX98090 Playback",
105 .cpu_dai_name = "DL1",
106 .platform_name = "11220000.mt8173-afe-pcm",
107 .codec_name = "snd-soc-dummy",
108 .codec_dai_name = "snd-soc-dummy-dai",
109 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
114 .name = "MAX98090 Capture",
115 .stream_name = "MAX98090 Capture",
116 .cpu_dai_name = "VUL",
117 .platform_name = "11220000.mt8173-afe-pcm",
118 .codec_name = "snd-soc-dummy",
119 .codec_dai_name = "snd-soc-dummy-dai",
120 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
124 /* Back End DAI links */
127 .cpu_dai_name = "I2S",
128 .platform_name = "11220000.mt8173-afe-pcm",
130 .codec_dai_name = "HiFi",
131 .init = mt8173_max98090_init,
132 .ops = &mt8173_max98090_ops,
133 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
134 SND_SOC_DAIFMT_CBS_CFS,
140 static struct snd_soc_card mt8173_max98090_card = {
141 .name = "mt8173-max98090",
142 .dai_link = mt8173_max98090_dais,
143 .num_links = ARRAY_SIZE(mt8173_max98090_dais),
144 .controls = mt8173_max98090_controls,
145 .num_controls = ARRAY_SIZE(mt8173_max98090_controls),
146 .dapm_widgets = mt8173_max98090_widgets,
147 .num_dapm_widgets = ARRAY_SIZE(mt8173_max98090_widgets),
148 .dapm_routes = mt8173_max98090_routes,
149 .num_dapm_routes = ARRAY_SIZE(mt8173_max98090_routes),
152 static int mt8173_max98090_dev_probe(struct platform_device *pdev)
154 struct snd_soc_card *card = &mt8173_max98090_card;
155 struct device_node *codec_node;
158 codec_node = of_parse_phandle(pdev->dev.of_node,
159 "mediatek,audio-codec", 0);
162 "Property 'audio-codec' missing or invalid\n");
165 for (i = 0; i < card->num_links; i++) {
166 if (mt8173_max98090_dais[i].codec_name)
168 mt8173_max98090_dais[i].codec_of_node = codec_node;
170 card->dev = &pdev->dev;
172 ret = snd_soc_register_card(card);
174 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n",
179 static int mt8173_max98090_dev_remove(struct platform_device *pdev)
181 struct snd_soc_card *card = platform_get_drvdata(pdev);
183 snd_soc_unregister_card(card);
187 static const struct of_device_id mt8173_max98090_dt_match[] = {
188 { .compatible = "mediatek,mt8173-max98090", },
191 MODULE_DEVICE_TABLE(of, mt8173_max98090_dt_match);
193 static struct platform_driver mt8173_max98090_driver = {
195 .name = "mt8173-max98090",
196 .owner = THIS_MODULE,
197 .of_match_table = mt8173_max98090_dt_match,
199 .pm = &snd_soc_pm_ops,
202 .probe = mt8173_max98090_dev_probe,
203 .remove = mt8173_max98090_dev_remove,
206 module_platform_driver(mt8173_max98090_driver);
208 /* Module information */
209 MODULE_DESCRIPTION("MT8173 MAX98090 ALSA SoC machine driver");
210 MODULE_AUTHOR("Koro Chen <koro.chen@mediatek.com>");
211 MODULE_LICENSE("GPL v2");
212 MODULE_ALIAS("platform:mt8173-max98090");