forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/sound/soc/intel/atom/sst-mfld-platform-pcm.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * sst_mfld_platform.c - Intel MID Platform driver
34 *
....@@ -5,15 +6,6 @@
56 * Author: Vinod Koul <vinod.koul@intel.com>
67 * Author: Harsha Priya <priya.harsha@intel.com>
78 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; version 2 of the License.
12
- *
13
- * This program is distributed in the hope that it will be useful, but
14
- * WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- * General Public License for more details.
179 *
1810 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1911 */
....@@ -190,7 +182,7 @@
190182 map = ctx->pdata->pdev_strm_map;
191183 map_size = ctx->pdata->strm_map_size;
192184
193
- if (is_compress == true)
185
+ if (is_compress)
194186 cstream = (struct snd_compr_stream *)substream;
195187 else
196188 pstream = (struct snd_pcm_substream *)substream;
....@@ -281,7 +273,7 @@
281273 {
282274 struct sst_runtime_stream *stream =
283275 substream->runtime->private_data;
284
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
276
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
285277 int ret_val;
286278
287279 dev_dbg(rtd->dev, "setting buffer ptr param\n");
....@@ -340,6 +332,17 @@
340332 if (ret_val < 0)
341333 goto out_power_up;
342334
335
+ /*
336
+ * Make sure the period to be multiple of 1ms to align the
337
+ * design of firmware. Apply same rule to buffer size to make
338
+ * sure alsa could always find a value for period size
339
+ * regardless the buffer size given by user space.
340
+ */
341
+ snd_pcm_hw_constraint_step(substream->runtime, 0,
342
+ SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 48);
343
+ snd_pcm_hw_constraint_step(substream->runtime, 0,
344
+ SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 48);
345
+
343346 /* Make sure, that the period size is always even */
344347 snd_pcm_hw_constraint_step(substream->runtime, 0,
345348 SNDRV_PCM_HW_PARAM_PERIODS, 2);
....@@ -373,7 +376,7 @@
373376 struct snd_soc_dai *dai)
374377 {
375378 struct sst_runtime_stream *stream;
376
- int ret_val = 0, str_id;
379
+ int ret_val, str_id;
377380
378381 stream = substream->runtime->private_data;
379382 str_id = stream->stream_info.str_id;
....@@ -392,28 +395,7 @@
392395 if (ret_val)
393396 return ret_val;
394397 substream->runtime->hw.info = SNDRV_PCM_INFO_BLOCK_TRANSFER;
395
- return ret_val;
396
-}
397
-
398
-static int sst_media_hw_params(struct snd_pcm_substream *substream,
399
- struct snd_pcm_hw_params *params,
400
- struct snd_soc_dai *dai)
401
-{
402
- int ret;
403
-
404
- ret =
405
- snd_pcm_lib_malloc_pages(substream,
406
- params_buffer_bytes(params));
407
- if (ret)
408
- return ret;
409
- memset(substream->runtime->dma_area, 0, params_buffer_bytes(params));
410398 return 0;
411
-}
412
-
413
-static int sst_media_hw_free(struct snd_pcm_substream *substream,
414
- struct snd_soc_dai *dai)
415
-{
416
- return snd_pcm_lib_free_pages(substream);
417399 }
418400
419401 static int sst_enable_ssp(struct snd_pcm_substream *substream,
....@@ -421,7 +403,7 @@
421403 {
422404 int ret = 0;
423405
424
- if (!dai->active) {
406
+ if (!snd_soc_dai_active(dai)) {
425407 ret = sst_handle_vb_timer(dai, true);
426408 sst_fill_ssp_defaults(dai);
427409 }
....@@ -434,7 +416,7 @@
434416 {
435417 int ret = 0;
436418
437
- if (dai->active == 1)
419
+ if (snd_soc_dai_active(dai) == 1)
438420 ret = send_ssp_cmd(dai, dai->name, 1);
439421 return ret;
440422 }
....@@ -443,7 +425,7 @@
443425 {
444426 int ret = 0;
445427
446
- if (!dai->active)
428
+ if (!snd_soc_dai_active(dai))
447429 return 0;
448430
449431 ret = sst_fill_ssp_config(dai, fmt);
....@@ -458,7 +440,7 @@
458440 int slots, int slot_width) {
459441 int ret = 0;
460442
461
- if (!dai->active)
443
+ if (!snd_soc_dai_active(dai))
462444 return ret;
463445
464446 ret = sst_fill_ssp_slot(dai, tx_mask, rx_mask, slots, slot_width);
....@@ -471,7 +453,7 @@
471453 static void sst_disable_ssp(struct snd_pcm_substream *substream,
472454 struct snd_soc_dai *dai)
473455 {
474
- if (!dai->active) {
456
+ if (!snd_soc_dai_active(dai)) {
475457 send_ssp_cmd(dai, dai->name, 0);
476458 sst_handle_vb_timer(dai, false);
477459 }
....@@ -481,8 +463,6 @@
481463 .startup = sst_media_open,
482464 .shutdown = sst_media_close,
483465 .prepare = sst_media_prepare,
484
- .hw_params = sst_media_hw_params,
485
- .hw_free = sst_media_hw_free,
486466 .mute_stream = sst_media_digital_mute,
487467 };
488468
....@@ -594,7 +574,8 @@
594574 },
595575 };
596576
597
-static int sst_platform_open(struct snd_pcm_substream *substream)
577
+static int sst_soc_open(struct snd_soc_component *component,
578
+ struct snd_pcm_substream *substream)
598579 {
599580 struct snd_pcm_runtime *runtime;
600581
....@@ -606,15 +587,15 @@
606587 return 0;
607588 }
608589
609
-static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream,
610
- int cmd)
590
+static int sst_soc_trigger(struct snd_soc_component *component,
591
+ struct snd_pcm_substream *substream, int cmd)
611592 {
612593 int ret_val = 0, str_id;
613594 struct sst_runtime_stream *stream;
614595 int status;
615
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
596
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
616597
617
- dev_dbg(rtd->dev, "sst_platform_pcm_trigger called\n");
598
+ dev_dbg(rtd->dev, "%s called\n", __func__);
618599 if (substream->pcm->internal)
619600 return 0;
620601 stream = substream->runtime->private_data;
....@@ -654,13 +635,13 @@
654635 }
655636
656637
657
-static snd_pcm_uframes_t sst_platform_pcm_pointer
658
- (struct snd_pcm_substream *substream)
638
+static snd_pcm_uframes_t sst_soc_pointer(struct snd_soc_component *component,
639
+ struct snd_pcm_substream *substream)
659640 {
660641 struct sst_runtime_stream *stream;
661642 int ret_val, status;
662643 struct pcm_stream_info *str_info;
663
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
644
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
664645
665646 stream = substream->runtime->private_data;
666647 status = sst_get_stream_status(stream);
....@@ -676,31 +657,20 @@
676657 return str_info->buffer_ptr;
677658 }
678659
679
-static const struct snd_pcm_ops sst_platform_ops = {
680
- .open = sst_platform_open,
681
- .ioctl = snd_pcm_lib_ioctl,
682
- .trigger = sst_platform_pcm_trigger,
683
- .pointer = sst_platform_pcm_pointer,
684
-};
685
-
686
-static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
660
+static int sst_soc_pcm_new(struct snd_soc_component *component,
661
+ struct snd_soc_pcm_runtime *rtd)
687662 {
688
- struct snd_soc_dai *dai = rtd->cpu_dai;
663
+ struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0);
689664 struct snd_pcm *pcm = rtd->pcm;
690
- int retval = 0;
691665
692666 if (dai->driver->playback.channels_min ||
693667 dai->driver->capture.channels_min) {
694
- retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
668
+ snd_pcm_set_managed_buffer_all(pcm,
695669 SNDRV_DMA_TYPE_CONTINUOUS,
696670 snd_dma_continuous_data(GFP_DMA),
697671 SST_MIN_BUFFER, SST_MAX_BUFFER);
698
- if (retval) {
699
- dev_err(rtd->dev, "dma buffer allocation failure\n");
700
- return retval;
701
- }
702672 }
703
- return retval;
673
+ return 0;
704674 }
705675
706676 static int sst_soc_probe(struct snd_soc_component *component)
....@@ -722,9 +692,11 @@
722692 .name = DRV_NAME,
723693 .probe = sst_soc_probe,
724694 .remove = sst_soc_remove,
725
- .ops = &sst_platform_ops,
726
- .compr_ops = &sst_platform_compr_ops,
727
- .pcm_new = sst_pcm_new,
695
+ .open = sst_soc_open,
696
+ .trigger = sst_soc_trigger,
697
+ .pointer = sst_soc_pointer,
698
+ .compress_ops = &sst_platform_compress_ops,
699
+ .pcm_construct = sst_soc_pcm_new,
728700 };
729701
730702 static int sst_platform_probe(struct platform_device *pdev)
....@@ -779,10 +751,10 @@
779751 snd_soc_poweroff(drv->soc_card->dev);
780752
781753 /* set the SSPs to idle */
782
- list_for_each_entry(rtd, &drv->soc_card->rtd_list, list) {
783
- struct snd_soc_dai *dai = rtd->cpu_dai;
754
+ for_each_card_rtds(drv->soc_card, rtd) {
755
+ struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0);
784756
785
- if (dai->active) {
757
+ if (snd_soc_dai_active(dai)) {
786758 send_ssp_cmd(dai, dai->name, 0);
787759 sst_handle_vb_timer(dai, false);
788760 }
....@@ -800,10 +772,10 @@
800772 return;
801773
802774 /* restart SSPs */
803
- list_for_each_entry(rtd, &drv->soc_card->rtd_list, list) {
804
- struct snd_soc_dai *dai = rtd->cpu_dai;
775
+ for_each_card_rtds(drv->soc_card, rtd) {
776
+ struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0);
805777
806
- if (dai->active) {
778
+ if (snd_soc_dai_active(dai)) {
807779 sst_handle_vb_timer(dai, true);
808780 send_ssp_cmd(dai, dai->name, 1);
809781 }