forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/soc/bcm/cygnus-pcm.c
....@@ -207,9 +207,9 @@
207207 static struct cygnus_aio_port *cygnus_dai_get_dma_data(
208208 struct snd_pcm_substream *substream)
209209 {
210
- struct snd_soc_pcm_runtime *soc_runtime = substream->private_data;
210
+ struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
211211
212
- return snd_soc_dai_get_dma_data(soc_runtime->cpu_dai, substream);
212
+ return snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(soc_runtime, 0), substream);
213213 }
214214
215215 static void ringbuf_set_initial(void __iomem *audio_io,
....@@ -353,13 +353,13 @@
353353
354354 static void disable_intr(struct snd_pcm_substream *substream)
355355 {
356
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
356
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
357357 struct cygnus_aio_port *aio;
358358 u32 set_mask;
359359
360360 aio = cygnus_dai_get_dma_data(substream);
361361
362
- dev_dbg(rtd->cpu_dai->dev, "%s on port %d\n", __func__, aio->portnum);
362
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s on port %d\n", __func__, aio->portnum);
363363
364364 /* The port number maps to the bit position to be set */
365365 set_mask = BIT(aio->portnum);
....@@ -376,7 +376,8 @@
376376
377377 }
378378
379
-static int cygnus_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
379
+static int cygnus_pcm_trigger(struct snd_soc_component *component,
380
+ struct snd_pcm_substream *substream, int cmd)
380381 {
381382 int ret = 0;
382383
....@@ -577,9 +578,10 @@
577578 return IRQ_HANDLED;
578579 }
579580
580
-static int cygnus_pcm_open(struct snd_pcm_substream *substream)
581
+static int cygnus_pcm_open(struct snd_soc_component *component,
582
+ struct snd_pcm_substream *substream)
581583 {
582
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
584
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
583585 struct snd_pcm_runtime *runtime = substream->runtime;
584586 struct cygnus_aio_port *aio;
585587 int ret;
....@@ -588,7 +590,7 @@
588590 if (!aio)
589591 return -ENODEV;
590592
591
- dev_dbg(rtd->cpu_dai->dev, "%s port %d\n", __func__, aio->portnum);
593
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s port %d\n", __func__, aio->portnum);
592594
593595 snd_soc_set_runtime_hwparams(substream, &cygnus_pcm_hw);
594596
....@@ -613,14 +615,15 @@
613615 return 0;
614616 }
615617
616
-static int cygnus_pcm_close(struct snd_pcm_substream *substream)
618
+static int cygnus_pcm_close(struct snd_soc_component *component,
619
+ struct snd_pcm_substream *substream)
617620 {
618
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
621
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
619622 struct cygnus_aio_port *aio;
620623
621624 aio = cygnus_dai_get_dma_data(substream);
622625
623
- dev_dbg(rtd->cpu_dai->dev, "%s port %d\n", __func__, aio->portnum);
626
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s port %d\n", __func__, aio->portnum);
624627
625628 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
626629 aio->play_stream = NULL;
....@@ -628,58 +631,59 @@
628631 aio->capture_stream = NULL;
629632
630633 if (!aio->play_stream && !aio->capture_stream)
631
- dev_dbg(rtd->cpu_dai->dev, "freed port %d\n", aio->portnum);
634
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "freed port %d\n", aio->portnum);
632635
633636 return 0;
634637 }
635638
636
-static int cygnus_pcm_hw_params(struct snd_pcm_substream *substream,
637
- struct snd_pcm_hw_params *params)
639
+static int cygnus_pcm_hw_params(struct snd_soc_component *component,
640
+ struct snd_pcm_substream *substream,
641
+ struct snd_pcm_hw_params *params)
638642 {
639
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
643
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
640644 struct snd_pcm_runtime *runtime = substream->runtime;
641645 struct cygnus_aio_port *aio;
642
- int ret = 0;
643646
644647 aio = cygnus_dai_get_dma_data(substream);
645
- dev_dbg(rtd->cpu_dai->dev, "%s port %d\n", __func__, aio->portnum);
648
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s port %d\n", __func__, aio->portnum);
646649
647650 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
648651 runtime->dma_bytes = params_buffer_bytes(params);
649652
650
- return ret;
653
+ return 0;
651654 }
652655
653
-static int cygnus_pcm_hw_free(struct snd_pcm_substream *substream)
656
+static int cygnus_pcm_hw_free(struct snd_soc_component *component,
657
+ struct snd_pcm_substream *substream)
654658 {
655
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
659
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
656660 struct cygnus_aio_port *aio;
657661
658662 aio = cygnus_dai_get_dma_data(substream);
659
- dev_dbg(rtd->cpu_dai->dev, "%s port %d\n", __func__, aio->portnum);
663
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s port %d\n", __func__, aio->portnum);
660664
661665 snd_pcm_set_runtime_buffer(substream, NULL);
662666 return 0;
663667 }
664668
665
-static int cygnus_pcm_prepare(struct snd_pcm_substream *substream)
669
+static int cygnus_pcm_prepare(struct snd_soc_component *component,
670
+ struct snd_pcm_substream *substream)
666671 {
667
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
672
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
668673 struct snd_pcm_runtime *runtime = substream->runtime;
669674 struct cygnus_aio_port *aio;
670675 unsigned long bufsize, periodsize;
671
- int ret = 0;
672676 bool is_play;
673677 u32 start;
674678 struct ringbuf_regs *p_rbuf = NULL;
675679
676680 aio = cygnus_dai_get_dma_data(substream);
677
- dev_dbg(rtd->cpu_dai->dev, "%s port %d\n", __func__, aio->portnum);
681
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s port %d\n", __func__, aio->portnum);
678682
679683 bufsize = snd_pcm_lib_buffer_bytes(substream);
680684 periodsize = snd_pcm_lib_period_bytes(substream);
681685
682
- dev_dbg(rtd->cpu_dai->dev, "%s (buf_size %lu) (period_size %lu)\n",
686
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s (buf_size %lu) (period_size %lu)\n",
683687 __func__, bufsize, periodsize);
684688
685689 configure_ringbuf_regs(substream);
....@@ -693,10 +697,11 @@
693697 ringbuf_set_initial(aio->cygaud->audio, p_rbuf, is_play, start,
694698 periodsize, bufsize);
695699
696
- return ret;
700
+ return 0;
697701 }
698702
699
-static snd_pcm_uframes_t cygnus_pcm_pointer(struct snd_pcm_substream *substream)
703
+static snd_pcm_uframes_t cygnus_pcm_pointer(struct snd_soc_component *component,
704
+ struct snd_pcm_substream *substream)
700705 {
701706 struct cygnus_aio_port *aio;
702707 unsigned int res = 0, cur = 0, base = 0;
....@@ -728,7 +733,7 @@
728733 static int cygnus_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
729734 {
730735 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
731
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
736
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
732737 struct snd_dma_buffer *buf = &substream->dma_buffer;
733738 size_t size;
734739
....@@ -740,11 +745,11 @@
740745 buf->area = dma_alloc_coherent(pcm->card->dev, size,
741746 &buf->addr, GFP_KERNEL);
742747
743
- dev_dbg(rtd->cpu_dai->dev, "%s: size 0x%zx @ %pK\n",
748
+ dev_dbg(asoc_rtd_to_cpu(rtd, 0)->dev, "%s: size 0x%zx @ %pK\n",
744749 __func__, size, buf->area);
745750
746751 if (!buf->area) {
747
- dev_err(rtd->cpu_dai->dev, "%s: dma_alloc failed\n", __func__);
752
+ dev_err(asoc_rtd_to_cpu(rtd, 0)->dev, "%s: dma_alloc failed\n", __func__);
748753 return -ENOMEM;
749754 }
750755 buf->bytes = size;
....@@ -752,19 +757,8 @@
752757 return 0;
753758 }
754759
755
-
756
-static const struct snd_pcm_ops cygnus_pcm_ops = {
757
- .open = cygnus_pcm_open,
758
- .close = cygnus_pcm_close,
759
- .ioctl = snd_pcm_lib_ioctl,
760
- .hw_params = cygnus_pcm_hw_params,
761
- .hw_free = cygnus_pcm_hw_free,
762
- .prepare = cygnus_pcm_prepare,
763
- .trigger = cygnus_pcm_trigger,
764
- .pointer = cygnus_pcm_pointer,
765
-};
766
-
767
-static void cygnus_dma_free_dma_buffers(struct snd_pcm *pcm)
760
+static void cygnus_dma_free_dma_buffers(struct snd_soc_component *component,
761
+ struct snd_pcm *pcm)
768762 {
769763 struct snd_pcm_substream *substream;
770764 struct snd_dma_buffer *buf;
....@@ -790,7 +784,8 @@
790784 }
791785 }
792786
793
-static int cygnus_dma_new(struct snd_soc_pcm_runtime *rtd)
787
+static int cygnus_dma_new(struct snd_soc_component *component,
788
+ struct snd_soc_pcm_runtime *rtd)
794789 {
795790 struct snd_card *card = rtd->card->snd_card;
796791 struct snd_pcm *pcm = rtd->pcm;
....@@ -812,7 +807,7 @@
812807 ret = cygnus_pcm_preallocate_dma_buffer(pcm,
813808 SNDRV_PCM_STREAM_CAPTURE);
814809 if (ret) {
815
- cygnus_dma_free_dma_buffers(pcm);
810
+ cygnus_dma_free_dma_buffers(component, pcm);
816811 return ret;
817812 }
818813 }
....@@ -821,9 +816,15 @@
821816 }
822817
823818 static struct snd_soc_component_driver cygnus_soc_platform = {
824
- .ops = &cygnus_pcm_ops,
825
- .pcm_new = cygnus_dma_new,
826
- .pcm_free = cygnus_dma_free_dma_buffers,
819
+ .open = cygnus_pcm_open,
820
+ .close = cygnus_pcm_close,
821
+ .hw_params = cygnus_pcm_hw_params,
822
+ .hw_free = cygnus_pcm_hw_free,
823
+ .prepare = cygnus_pcm_prepare,
824
+ .trigger = cygnus_pcm_trigger,
825
+ .pointer = cygnus_pcm_pointer,
826
+ .pcm_construct = cygnus_dma_new,
827
+ .pcm_destruct = cygnus_dma_free_dma_buffers,
827828 };
828829
829830 int cygnus_soc_platform_register(struct device *dev,