hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/sound/soc/atmel/atmel-pdmic.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* Atmel PDMIC driver
23 *
34 * Copyright (C) 2015 Atmel
45 *
56 * 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.
107 */
118
129 #include <linux/of.h>
....@@ -107,7 +104,7 @@
107104 static int atmel_pdmic_cpu_dai_startup(struct snd_pcm_substream *substream,
108105 struct snd_soc_dai *cpu_dai)
109106 {
110
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
107
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
111108 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card);
112109 int ret;
113110
....@@ -135,7 +132,7 @@
135132 static void atmel_pdmic_cpu_dai_shutdown(struct snd_pcm_substream *substream,
136133 struct snd_soc_dai *cpu_dai)
137134 {
138
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
135
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
139136 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card);
140137
141138 /* Disable the overrun error interrupt */
....@@ -148,34 +145,28 @@
148145 static int atmel_pdmic_cpu_dai_prepare(struct snd_pcm_substream *substream,
149146 struct snd_soc_dai *cpu_dai)
150147 {
151
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
148
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
152149 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card);
150
+ struct snd_soc_component *component = cpu_dai->component;
153151 u32 val;
152
+ int ret;
154153
155154 /* 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;
157167 }
158168
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
-
165169 #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
-};
179170
180171 /* platform */
181172 #define ATMEL_PDMIC_MAX_BUF_SIZE (64 * 1024)
....@@ -200,7 +191,7 @@
200191 struct snd_pcm_hw_params *params,
201192 struct dma_slave_config *slave_config)
202193 {
203
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
194
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
204195 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(rtd->card);
205196 int ret;
206197
....@@ -293,10 +284,10 @@
293284 unsigned int dgain_val, scale_val;
294285 int i;
295286
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)
297288 >> PDMIC_DSPR1_DGAIN_SHIFT;
298289
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)
300291 >> PDMIC_DSPR0_SCALE_SHIFT;
301292
302293 for (i = 0; i < ARRAY_SIZE(mic_gain_table); i++) {
....@@ -358,27 +349,16 @@
358349 return 0;
359350 }
360351
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 */
372352 #define PDMIC_MR_PRESCAL_MAX_VAL 127
373353
374354 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)
378358 {
379
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
359
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
380360 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;
382362 unsigned int rate_min = substream->runtime->hw.rate_min;
383363 unsigned int rate_max = substream->runtime->hw.rate_max;
384364 int fs = params_rate(params);
....@@ -448,21 +428,10 @@
448428 return 0;
449429 }
450430
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)
453433 {
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;
466435 u32 val;
467436
468437 switch (cmd) {
....@@ -485,16 +454,16 @@
485454 return 0;
486455 }
487456
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,
492463 };
493464
494
-#define ATMEL_PDMIC_CODEC_DAI_NAME "atmel-pdmic-hifi"
495465
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 = {
498467 .capture = {
499468 .stream_name = "Capture",
500469 .channels_min = 1,
....@@ -502,7 +471,16 @@
502471 .rates = SNDRV_PCM_RATE_KNOT,
503472 .formats = ATMEL_PDMIC_FORMATS,
504473 },
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,
506484 };
507485
508486 /* ASoC sound card */
....@@ -511,17 +489,30 @@
511489 {
512490 struct snd_soc_dai_link *dai_link;
513491 struct atmel_pdmic *dd = snd_soc_card_get_drvdata(card);
492
+ struct snd_soc_dai_link_component *comp;
514493
515494 dai_link = devm_kzalloc(dev, sizeof(*dai_link), GFP_KERNEL);
516495 if (!dai_link)
517496 return -ENOMEM;
518497
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
+
519510 dai_link->name = "PDMIC";
520511 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);
525516
526517 card->dai_link = dai_link;
527518 card->num_links = 1;
....@@ -602,11 +593,8 @@
602593 dd->dev = dev;
603594
604595 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;
610598
611599 dd->pclk = devm_clk_get(dev, "pclk");
612600 if (IS_ERR(dd->pclk)) {
....@@ -674,16 +662,6 @@
674662 0);
675663 if (ret) {
676664 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);
687665 return ret;
688666 }
689667