.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * tegra_wm8903.c - Tegra machine ASoC driver for boards using WM8903 codec. |
---|
3 | 4 | * |
---|
.. | .. |
---|
11 | 12 | * Copyright 2007 Wolfson Microelectronics PLC. |
---|
12 | 13 | * Author: Graeme Gregory |
---|
13 | 14 | * 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 | | - * |
---|
29 | 15 | */ |
---|
30 | 16 | |
---|
31 | 17 | #include <linux/module.h> |
---|
.. | .. |
---|
58 | 44 | static int tegra_wm8903_hw_params(struct snd_pcm_substream *substream, |
---|
59 | 45 | struct snd_pcm_hw_params *params) |
---|
60 | 46 | { |
---|
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); |
---|
63 | 49 | struct snd_soc_card *card = rtd->card; |
---|
64 | 50 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
---|
65 | 51 | int srate, mclk; |
---|
.. | .. |
---|
157 | 143 | return 0; |
---|
158 | 144 | } |
---|
159 | 145 | |
---|
| 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 | + |
---|
160 | 162 | static const struct snd_soc_dapm_widget tegra_wm8903_dapm_widgets[] = { |
---|
161 | 163 | SND_SOC_DAPM_SPK("Int Spk", tegra_wm8903_event_int_spk), |
---|
162 | 164 | SND_SOC_DAPM_HP("Headphone Jack", tegra_wm8903_event_hp), |
---|
163 | 165 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
---|
| 166 | + SND_SOC_DAPM_MIC("Int Mic", tegra_wm8903_event_int_mic), |
---|
164 | 167 | }; |
---|
165 | 168 | |
---|
166 | 169 | static const struct snd_kcontrol_new tegra_wm8903_controls[] = { |
---|
167 | 170 | SOC_DAPM_PIN_SWITCH("Int Spk"), |
---|
| 171 | + SOC_DAPM_PIN_SWITCH("Int Mic"), |
---|
168 | 172 | }; |
---|
169 | 173 | |
---|
170 | 174 | static int tegra_wm8903_init(struct snd_soc_pcm_runtime *rtd) |
---|
171 | 175 | { |
---|
172 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
---|
| 176 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
---|
173 | 177 | struct snd_soc_component *component = codec_dai->component; |
---|
174 | 178 | struct snd_soc_card *card = rtd->card; |
---|
175 | 179 | struct tegra_wm8903 *machine = snd_soc_card_get_drvdata(card); |
---|
.. | .. |
---|
204 | 208 | static int tegra_wm8903_remove(struct snd_soc_card *card) |
---|
205 | 209 | { |
---|
206 | 210 | 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); |
---|
209 | 213 | struct snd_soc_component *component = codec_dai->component; |
---|
210 | 214 | |
---|
211 | 215 | wm8903_mic_detect(component, NULL, 0, 0); |
---|
.. | .. |
---|
213 | 217 | return 0; |
---|
214 | 218 | } |
---|
215 | 219 | |
---|
| 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 | + |
---|
216 | 225 | static struct snd_soc_dai_link tegra_wm8903_dai = { |
---|
217 | 226 | .name = "WM8903", |
---|
218 | 227 | .stream_name = "WM8903 PCM", |
---|
219 | | - .codec_dai_name = "wm8903-hifi", |
---|
220 | 228 | .init = tegra_wm8903_init, |
---|
221 | 229 | .ops = &tegra_wm8903_ops, |
---|
222 | 230 | .dai_fmt = SND_SOC_DAIFMT_I2S | |
---|
223 | 231 | SND_SOC_DAIFMT_NB_NF | |
---|
224 | 232 | SND_SOC_DAIFMT_CBS_CFS, |
---|
| 233 | + SND_SOC_DAILINK_REG(hifi), |
---|
225 | 234 | }; |
---|
226 | 235 | |
---|
227 | 236 | static struct snd_soc_card snd_soc_tegra_wm8903 = { |
---|
.. | .. |
---|
315 | 324 | |
---|
316 | 325 | ret = snd_soc_of_parse_card_name(card, "nvidia,model"); |
---|
317 | 326 | if (ret) |
---|
318 | | - goto err; |
---|
| 327 | + return ret; |
---|
319 | 328 | |
---|
320 | 329 | ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing"); |
---|
321 | 330 | if (ret) |
---|
322 | | - goto err; |
---|
| 331 | + return ret; |
---|
323 | 332 | |
---|
324 | | - tegra_wm8903_dai.codec_of_node = of_parse_phandle(np, |
---|
| 333 | + tegra_wm8903_dai.codecs->of_node = of_parse_phandle(np, |
---|
325 | 334 | "nvidia,audio-codec", 0); |
---|
326 | | - if (!tegra_wm8903_dai.codec_of_node) { |
---|
| 335 | + if (!tegra_wm8903_dai.codecs->of_node) { |
---|
327 | 336 | dev_err(&pdev->dev, |
---|
328 | 337 | "Property 'nvidia,audio-codec' missing or invalid\n"); |
---|
329 | | - ret = -EINVAL; |
---|
330 | | - goto err; |
---|
| 338 | + return -EINVAL; |
---|
331 | 339 | } |
---|
332 | 340 | |
---|
333 | | - tegra_wm8903_dai.cpu_of_node = of_parse_phandle(np, |
---|
| 341 | + tegra_wm8903_dai.cpus->of_node = of_parse_phandle(np, |
---|
334 | 342 | "nvidia,i2s-controller", 0); |
---|
335 | | - if (!tegra_wm8903_dai.cpu_of_node) { |
---|
| 343 | + if (!tegra_wm8903_dai.cpus->of_node) { |
---|
336 | 344 | dev_err(&pdev->dev, |
---|
337 | 345 | "Property 'nvidia,i2s-controller' missing or invalid\n"); |
---|
338 | | - ret = -EINVAL; |
---|
339 | | - goto err; |
---|
| 346 | + return -EINVAL; |
---|
340 | 347 | } |
---|
341 | 348 | |
---|
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; |
---|
343 | 350 | |
---|
344 | 351 | ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev); |
---|
345 | 352 | if (ret) |
---|
346 | | - goto err; |
---|
| 353 | + return ret; |
---|
347 | 354 | |
---|
348 | | - ret = snd_soc_register_card(card); |
---|
| 355 | + ret = devm_snd_soc_register_card(&pdev->dev, card); |
---|
349 | 356 | 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", |
---|
351 | 358 | ret); |
---|
352 | | - goto err_fini_utils; |
---|
| 359 | + return ret; |
---|
353 | 360 | } |
---|
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); |
---|
371 | 361 | |
---|
372 | 362 | return 0; |
---|
373 | 363 | } |
---|
.. | .. |
---|
384 | 374 | .of_match_table = tegra_wm8903_of_match, |
---|
385 | 375 | }, |
---|
386 | 376 | .probe = tegra_wm8903_driver_probe, |
---|
387 | | - .remove = tegra_wm8903_driver_remove, |
---|
388 | 377 | }; |
---|
389 | 378 | module_platform_driver(tegra_wm8903_driver); |
---|
390 | 379 | |
---|