.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* Atmel PDMIC driver |
---|
2 | 3 | * |
---|
3 | 4 | * Copyright (C) 2015 Atmel |
---|
4 | 5 | * |
---|
5 | 6 | * Author: Songjun Wu <songjun.wu@atmel.com> |
---|
6 | | - * |
---|
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 or later |
---|
9 | | - * as published by the Free Software Foundation. |
---|
10 | 7 | */ |
---|
11 | 8 | |
---|
12 | 9 | #include <linux/of.h> |
---|
.. | .. |
---|
107 | 104 | static int atmel_pdmic_cpu_dai_startup(struct snd_pcm_substream *substream, |
---|
108 | 105 | struct snd_soc_dai *cpu_dai) |
---|
109 | 106 | { |
---|
110 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
| 107 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
111 | 108 | struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); |
---|
112 | 109 | int ret; |
---|
113 | 110 | |
---|
.. | .. |
---|
135 | 132 | static void atmel_pdmic_cpu_dai_shutdown(struct snd_pcm_substream *substream, |
---|
136 | 133 | struct snd_soc_dai *cpu_dai) |
---|
137 | 134 | { |
---|
138 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
| 135 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
139 | 136 | struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); |
---|
140 | 137 | |
---|
141 | 138 | /* Disable the overrun error interrupt */ |
---|
.. | .. |
---|
148 | 145 | static int atmel_pdmic_cpu_dai_prepare(struct snd_pcm_substream *substream, |
---|
149 | 146 | struct snd_soc_dai *cpu_dai) |
---|
150 | 147 | { |
---|
151 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
| 148 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
152 | 149 | struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); |
---|
| 150 | + struct snd_soc_component *component = cpu_dai->component; |
---|
153 | 151 | u32 val; |
---|
| 152 | + int ret; |
---|
154 | 153 | |
---|
155 | 154 | /* Clean the PDMIC Converted Data Register */ |
---|
156 | | - return regmap_read(dd->regmap, PDMIC_CDR, &val); |
---|
| 155 | + ret = regmap_read(dd->regmap, PDMIC_CDR, &val); |
---|
| 156 | + if (ret < 0) |
---|
| 157 | + return 0; |
---|
| 158 | + |
---|
| 159 | + ret = snd_soc_component_update_bits(component, PDMIC_CR, |
---|
| 160 | + PDMIC_CR_ENPDM_MASK, |
---|
| 161 | + PDMIC_CR_ENPDM_DIS << |
---|
| 162 | + PDMIC_CR_ENPDM_SHIFT); |
---|
| 163 | + if (ret < 0) |
---|
| 164 | + return ret; |
---|
| 165 | + |
---|
| 166 | + return 0; |
---|
157 | 167 | } |
---|
158 | 168 | |
---|
159 | | -static const struct snd_soc_dai_ops atmel_pdmic_cpu_dai_ops = { |
---|
160 | | - .startup = atmel_pdmic_cpu_dai_startup, |
---|
161 | | - .shutdown = atmel_pdmic_cpu_dai_shutdown, |
---|
162 | | - .prepare = atmel_pdmic_cpu_dai_prepare, |
---|
163 | | -}; |
---|
164 | | - |
---|
165 | 169 | #define ATMEL_PDMIC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) |
---|
166 | | - |
---|
167 | | -static struct snd_soc_dai_driver atmel_pdmic_cpu_dai = { |
---|
168 | | - .capture = { |
---|
169 | | - .channels_min = 1, |
---|
170 | | - .channels_max = 1, |
---|
171 | | - .rates = SNDRV_PCM_RATE_KNOT, |
---|
172 | | - .formats = ATMEL_PDMIC_FORMATS,}, |
---|
173 | | - .ops = &atmel_pdmic_cpu_dai_ops, |
---|
174 | | -}; |
---|
175 | | - |
---|
176 | | -static const struct snd_soc_component_driver atmel_pdmic_cpu_dai_component = { |
---|
177 | | - .name = "atmel-pdmic", |
---|
178 | | -}; |
---|
179 | 170 | |
---|
180 | 171 | /* platform */ |
---|
181 | 172 | #define ATMEL_PDMIC_MAX_BUF_SIZE (64 * 1024) |
---|
.. | .. |
---|
200 | 191 | struct snd_pcm_hw_params *params, |
---|
201 | 192 | struct dma_slave_config *slave_config) |
---|
202 | 193 | { |
---|
203 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
| 194 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
204 | 195 | struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); |
---|
205 | 196 | int ret; |
---|
206 | 197 | |
---|
.. | .. |
---|
293 | 284 | unsigned int dgain_val, scale_val; |
---|
294 | 285 | int i; |
---|
295 | 286 | |
---|
296 | | - dgain_val = (snd_soc_component_read32(component, PDMIC_DSPR1) & PDMIC_DSPR1_DGAIN_MASK) |
---|
| 287 | + dgain_val = (snd_soc_component_read(component, PDMIC_DSPR1) & PDMIC_DSPR1_DGAIN_MASK) |
---|
297 | 288 | >> PDMIC_DSPR1_DGAIN_SHIFT; |
---|
298 | 289 | |
---|
299 | | - scale_val = (snd_soc_component_read32(component, PDMIC_DSPR0) & PDMIC_DSPR0_SCALE_MASK) |
---|
| 290 | + scale_val = (snd_soc_component_read(component, PDMIC_DSPR0) & PDMIC_DSPR0_SCALE_MASK) |
---|
300 | 291 | >> PDMIC_DSPR0_SCALE_SHIFT; |
---|
301 | 292 | |
---|
302 | 293 | for (i = 0; i < ARRAY_SIZE(mic_gain_table); i++) { |
---|
.. | .. |
---|
358 | 349 | return 0; |
---|
359 | 350 | } |
---|
360 | 351 | |
---|
361 | | -static struct snd_soc_component_driver soc_component_dev_pdmic = { |
---|
362 | | - .probe = atmel_pdmic_component_probe, |
---|
363 | | - .controls = atmel_pdmic_snd_controls, |
---|
364 | | - .num_controls = ARRAY_SIZE(atmel_pdmic_snd_controls), |
---|
365 | | - .idle_bias_on = 1, |
---|
366 | | - .use_pmdown_time = 1, |
---|
367 | | - .endianness = 1, |
---|
368 | | - .non_legacy_dai_naming = 1, |
---|
369 | | -}; |
---|
370 | | - |
---|
371 | | -/* codec dai component */ |
---|
372 | 352 | #define PDMIC_MR_PRESCAL_MAX_VAL 127 |
---|
373 | 353 | |
---|
374 | 354 | static int |
---|
375 | | -atmel_pdmic_codec_dai_hw_params(struct snd_pcm_substream *substream, |
---|
376 | | - struct snd_pcm_hw_params *params, |
---|
377 | | - struct snd_soc_dai *codec_dai) |
---|
| 355 | +atmel_pdmic_cpu_dai_hw_params(struct snd_pcm_substream *substream, |
---|
| 356 | + struct snd_pcm_hw_params *params, |
---|
| 357 | + struct snd_soc_dai *cpu_dai) |
---|
378 | 358 | { |
---|
379 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
---|
| 359 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
---|
380 | 360 | struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card); |
---|
381 | | - struct snd_soc_component *component = codec_dai->component; |
---|
| 361 | + struct snd_soc_component *component = cpu_dai->component; |
---|
382 | 362 | unsigned int rate_min = substream->runtime->hw.rate_min; |
---|
383 | 363 | unsigned int rate_max = substream->runtime->hw.rate_max; |
---|
384 | 364 | int fs = params_rate(params); |
---|
.. | .. |
---|
448 | 428 | return 0; |
---|
449 | 429 | } |
---|
450 | 430 | |
---|
451 | | -static int atmel_pdmic_codec_dai_prepare(struct snd_pcm_substream *substream, |
---|
452 | | - struct snd_soc_dai *codec_dai) |
---|
| 431 | +static int atmel_pdmic_cpu_dai_trigger(struct snd_pcm_substream *substream, |
---|
| 432 | + int cmd, struct snd_soc_dai *cpu_dai) |
---|
453 | 433 | { |
---|
454 | | - struct snd_soc_component *component = codec_dai->component; |
---|
455 | | - |
---|
456 | | - snd_soc_component_update_bits(component, PDMIC_CR, PDMIC_CR_ENPDM_MASK, |
---|
457 | | - PDMIC_CR_ENPDM_DIS << PDMIC_CR_ENPDM_SHIFT); |
---|
458 | | - |
---|
459 | | - return 0; |
---|
460 | | -} |
---|
461 | | - |
---|
462 | | -static int atmel_pdmic_codec_dai_trigger(struct snd_pcm_substream *substream, |
---|
463 | | - int cmd, struct snd_soc_dai *codec_dai) |
---|
464 | | -{ |
---|
465 | | - struct snd_soc_component *component = codec_dai->component; |
---|
| 434 | + struct snd_soc_component *component = cpu_dai->component; |
---|
466 | 435 | u32 val; |
---|
467 | 436 | |
---|
468 | 437 | switch (cmd) { |
---|
.. | .. |
---|
485 | 454 | return 0; |
---|
486 | 455 | } |
---|
487 | 456 | |
---|
488 | | -static const struct snd_soc_dai_ops atmel_pdmic_codec_dai_ops = { |
---|
489 | | - .hw_params = atmel_pdmic_codec_dai_hw_params, |
---|
490 | | - .prepare = atmel_pdmic_codec_dai_prepare, |
---|
491 | | - .trigger = atmel_pdmic_codec_dai_trigger, |
---|
| 457 | +static const struct snd_soc_dai_ops atmel_pdmic_cpu_dai_ops = { |
---|
| 458 | + .startup = atmel_pdmic_cpu_dai_startup, |
---|
| 459 | + .shutdown = atmel_pdmic_cpu_dai_shutdown, |
---|
| 460 | + .prepare = atmel_pdmic_cpu_dai_prepare, |
---|
| 461 | + .hw_params = atmel_pdmic_cpu_dai_hw_params, |
---|
| 462 | + .trigger = atmel_pdmic_cpu_dai_trigger, |
---|
492 | 463 | }; |
---|
493 | 464 | |
---|
494 | | -#define ATMEL_PDMIC_CODEC_DAI_NAME "atmel-pdmic-hifi" |
---|
495 | 465 | |
---|
496 | | -static struct snd_soc_dai_driver atmel_pdmic_codec_dai = { |
---|
497 | | - .name = ATMEL_PDMIC_CODEC_DAI_NAME, |
---|
| 466 | +static struct snd_soc_dai_driver atmel_pdmic_cpu_dai = { |
---|
498 | 467 | .capture = { |
---|
499 | 468 | .stream_name = "Capture", |
---|
500 | 469 | .channels_min = 1, |
---|
.. | .. |
---|
502 | 471 | .rates = SNDRV_PCM_RATE_KNOT, |
---|
503 | 472 | .formats = ATMEL_PDMIC_FORMATS, |
---|
504 | 473 | }, |
---|
505 | | - .ops = &atmel_pdmic_codec_dai_ops, |
---|
| 474 | + .ops = &atmel_pdmic_cpu_dai_ops, |
---|
| 475 | +}; |
---|
| 476 | + |
---|
| 477 | +static const struct snd_soc_component_driver atmel_pdmic_cpu_dai_component = { |
---|
| 478 | + .name = "atmel-pdmic", |
---|
| 479 | + .probe = atmel_pdmic_component_probe, |
---|
| 480 | + .controls = atmel_pdmic_snd_controls, |
---|
| 481 | + .num_controls = ARRAY_SIZE(atmel_pdmic_snd_controls), |
---|
| 482 | + .idle_bias_on = 1, |
---|
| 483 | + .use_pmdown_time = 1, |
---|
506 | 484 | }; |
---|
507 | 485 | |
---|
508 | 486 | /* ASoC sound card */ |
---|
.. | .. |
---|
511 | 489 | { |
---|
512 | 490 | struct snd_soc_dai_link *dai_link; |
---|
513 | 491 | struct atmel_pdmic *dd = snd_soc_card_get_drvdata(card); |
---|
| 492 | + struct snd_soc_dai_link_component *comp; |
---|
514 | 493 | |
---|
515 | 494 | dai_link = devm_kzalloc(dev, sizeof(*dai_link), GFP_KERNEL); |
---|
516 | 495 | if (!dai_link) |
---|
517 | 496 | return -ENOMEM; |
---|
518 | 497 | |
---|
| 498 | + comp = devm_kzalloc(dev, 3 * sizeof(*comp), GFP_KERNEL); |
---|
| 499 | + if (!comp) |
---|
| 500 | + return -ENOMEM; |
---|
| 501 | + |
---|
| 502 | + dai_link->cpus = &comp[0]; |
---|
| 503 | + dai_link->codecs = &comp[1]; |
---|
| 504 | + dai_link->platforms = &comp[2]; |
---|
| 505 | + |
---|
| 506 | + dai_link->num_cpus = 1; |
---|
| 507 | + dai_link->num_codecs = 1; |
---|
| 508 | + dai_link->num_platforms = 1; |
---|
| 509 | + |
---|
519 | 510 | dai_link->name = "PDMIC"; |
---|
520 | 511 | dai_link->stream_name = "PDMIC PCM"; |
---|
521 | | - dai_link->codec_dai_name = ATMEL_PDMIC_CODEC_DAI_NAME; |
---|
522 | | - dai_link->cpu_dai_name = dev_name(dev); |
---|
523 | | - dai_link->codec_name = dev_name(dev); |
---|
524 | | - dai_link->platform_name = dev_name(dev); |
---|
| 512 | + dai_link->codecs->dai_name = "snd-soc-dummy-dai"; |
---|
| 513 | + dai_link->cpus->dai_name = dev_name(dev); |
---|
| 514 | + dai_link->codecs->name = "snd-soc-dummy"; |
---|
| 515 | + dai_link->platforms->name = dev_name(dev); |
---|
525 | 516 | |
---|
526 | 517 | card->dai_link = dai_link; |
---|
527 | 518 | card->num_links = 1; |
---|
.. | .. |
---|
602 | 593 | dd->dev = dev; |
---|
603 | 594 | |
---|
604 | 595 | dd->irq = platform_get_irq(pdev, 0); |
---|
605 | | - if (dd->irq < 0) { |
---|
606 | | - ret = dd->irq; |
---|
607 | | - dev_err(dev, "failed to get irq: %d\n", ret); |
---|
608 | | - return ret; |
---|
609 | | - } |
---|
| 596 | + if (dd->irq < 0) |
---|
| 597 | + return dd->irq; |
---|
610 | 598 | |
---|
611 | 599 | dd->pclk = devm_clk_get(dev, "pclk"); |
---|
612 | 600 | if (IS_ERR(dd->pclk)) { |
---|
.. | .. |
---|
674 | 662 | 0); |
---|
675 | 663 | if (ret) { |
---|
676 | 664 | dev_err(dev, "could not register platform: %d\n", ret); |
---|
677 | | - return ret; |
---|
678 | | - } |
---|
679 | | - |
---|
680 | | - /* register codec and codec dai */ |
---|
681 | | - atmel_pdmic_codec_dai.capture.rate_min = rate_min; |
---|
682 | | - atmel_pdmic_codec_dai.capture.rate_max = rate_max; |
---|
683 | | - ret = devm_snd_soc_register_component(dev, &soc_component_dev_pdmic, |
---|
684 | | - &atmel_pdmic_codec_dai, 1); |
---|
685 | | - if (ret) { |
---|
686 | | - dev_err(dev, "could not register component: %d\n", ret); |
---|
687 | 665 | return ret; |
---|
688 | 666 | } |
---|
689 | 667 | |
---|