hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/sound/soc/tegra/tegra_wm8903.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec.
34 *
....@@ -11,21 +12,6 @@
1112 * Copyright 2007 Wolfson Microelectronics PLC.
1213 * Author: Graeme Gregory
1314 * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
14
- *
15
- * This program is free software; you can redistribute it and/or
16
- * modify it under the terms of the GNU General Public License
17
- * version 2 as published by the Free Software Foundation.
18
- *
19
- * This program is distributed in the hope that it will be useful, but
20
- * WITHOUT ANY WARRANTY; without even the implied warranty of
21
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
- * General Public License for more details.
23
- *
24
- * You should have received a copy of the GNU General Public License
25
- * along with this program; if not, write to the Free Software
26
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27
- * 02110-1301 USA
28
- *
2915 */
3016
3117 #include <linux/module.h>
....@@ -58,8 +44,8 @@
5844 static int tegra_wm8903_hw_params(struct snd_pcm_substream *substream,
5945 struct snd_pcm_hw_params *params)
6046 {
61
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
62
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
47
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
48
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
6349 struct snd_soc_card *card = rtd->card;
6450 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
6551 int srate, mclk;
....@@ -157,19 +143,37 @@
157143 return 0;
158144 }
159145
146
+static int tegra_wm8903_event_int_mic(struct snd_soc_dapm_widget *w,
147
+ struct snd_kcontrol *k, int event)
148
+{
149
+ struct snd_soc_dapm_context *dapm = w->dapm;
150
+ struct snd_soc_card *card = dapm->card;
151
+ struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
152
+
153
+ if (!gpio_is_valid(machine->gpio_int_mic_en))
154
+ return 0;
155
+
156
+ gpio_set_value_cansleep(machine->gpio_int_mic_en,
157
+ SND_SOC_DAPM_EVENT_ON(event));
158
+
159
+ return 0;
160
+}
161
+
160162 static const struct snd_soc_dapm_widget tegra_wm8903_dapm_widgets[] = {
161163 SND_SOC_DAPM_SPK("Int Spk", tegra_wm8903_event_int_spk),
162164 SND_SOC_DAPM_HP("Headphone Jack", tegra_wm8903_event_hp),
163165 SND_SOC_DAPM_MIC("Mic Jack", NULL),
166
+ SND_SOC_DAPM_MIC("Int Mic", tegra_wm8903_event_int_mic),
164167 };
165168
166169 static const struct snd_kcontrol_new tegra_wm8903_controls[] = {
167170 SOC_DAPM_PIN_SWITCH("Int Spk"),
171
+ SOC_DAPM_PIN_SWITCH("Int Mic"),
168172 };
169173
170174 static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd)
171175 {
172
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
176
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
173177 struct snd_soc_component *component = codec_dai->component;
174178 struct snd_soc_card *card = rtd->card;
175179 struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
....@@ -204,8 +208,8 @@
204208 static int tegra_wm8903_remove(struct snd_soc_card *card)
205209 {
206210 struct snd_soc_pcm_runtime *rtd =
207
- snd_soc_get_pcm_runtime(card, card->dai_link[0].name);
208
- struct snd_soc_dai *codec_dai = rtd->codec_dai;
211
+ snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
212
+ struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
209213 struct snd_soc_component *component = codec_dai->component;
210214
211215 wm8903_mic_detect(component, NULL, 0, 0);
....@@ -213,15 +217,20 @@
213217 return 0;
214218 }
215219
220
+SND_SOC_DAILINK_DEFS(hifi,
221
+ DAILINK_COMP_ARRAY(COMP_EMPTY()),
222
+ DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8903-hifi")),
223
+ DAILINK_COMP_ARRAY(COMP_EMPTY()));
224
+
216225 static struct snd_soc_dai_link tegra_wm8903_dai = {
217226 .name = "WM8903",
218227 .stream_name = "WM8903 PCM",
219
- .codec_dai_name = "wm8903-hifi",
220228 .init = tegra_wm8903_init,
221229 .ops = &tegra_wm8903_ops,
222230 .dai_fmt = SND_SOC_DAIFMT_I2S |
223231 SND_SOC_DAIFMT_NB_NF |
224232 SND_SOC_DAIFMT_CBS_CFS,
233
+ SND_SOC_DAILINK_REG(hifi),
225234 };
226235
227236 static struct snd_soc_card snd_soc_tegra_wm8903 = {
....@@ -315,59 +324,40 @@
315324
316325 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
317326 if (ret)
318
- goto err;
327
+ return ret;
319328
320329 ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
321330 if (ret)
322
- goto err;
331
+ return ret;
323332
324
- tegra_wm8903_dai.codec_of_node = of_parse_phandle(np,
333
+ tegra_wm8903_dai.codecs->of_node = of_parse_phandle(np,
325334 "nvidia,audio-codec", 0);
326
- if (!tegra_wm8903_dai.codec_of_node) {
335
+ if (!tegra_wm8903_dai.codecs->of_node) {
327336 dev_err(&pdev->dev,
328337 "Property 'nvidia,audio-codec' missing or invalid\n");
329
- ret = -EINVAL;
330
- goto err;
338
+ return -EINVAL;
331339 }
332340
333
- tegra_wm8903_dai.cpu_of_node = of_parse_phandle(np,
341
+ tegra_wm8903_dai.cpus->of_node = of_parse_phandle(np,
334342 "nvidia,i2s-controller", 0);
335
- if (!tegra_wm8903_dai.cpu_of_node) {
343
+ if (!tegra_wm8903_dai.cpus->of_node) {
336344 dev_err(&pdev->dev,
337345 "Property 'nvidia,i2s-controller' missing or invalid\n");
338
- ret = -EINVAL;
339
- goto err;
346
+ return -EINVAL;
340347 }
341348
342
- tegra_wm8903_dai.platform_of_node = tegra_wm8903_dai.cpu_of_node;
349
+ tegra_wm8903_dai.platforms->of_node = tegra_wm8903_dai.cpus->of_node;
343350
344351 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
345352 if (ret)
346
- goto err;
353
+ return ret;
347354
348
- ret = snd_soc_register_card(card);
355
+ ret = devm_snd_soc_register_card(&pdev->dev, card);
349356 if (ret) {
350
- dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
357
+ dev_err(&pdev->dev, "devm_snd_soc_register_card failed (%d)\n",
351358 ret);
352
- goto err_fini_utils;
359
+ return ret;
353360 }
354
-
355
- return 0;
356
-
357
-err_fini_utils:
358
- tegra_asoc_utils_fini(&machine->util_data);
359
-err:
360
- return ret;
361
-}
362
-
363
-static int tegra_wm8903_driver_remove(struct platform_device *pdev)
364
-{
365
- struct snd_soc_card *card = platform_get_drvdata(pdev);
366
- struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card);
367
-
368
- snd_soc_unregister_card(card);
369
-
370
- tegra_asoc_utils_fini(&machine->util_data);
371361
372362 return 0;
373363 }
....@@ -384,7 +374,6 @@
384374 .of_match_table = tegra_wm8903_of_match,
385375 },
386376 .probe = tegra_wm8903_driver_probe,
387
- .remove = tegra_wm8903_driver_remove,
388377 };
389378 module_platform_driver(tegra_wm8903_driver);
390379