forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/sound/hda/hdac_stream.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * HD-audio stream operations
34 */
....@@ -11,6 +12,40 @@
1112 #include <sound/hdaudio.h>
1213 #include <sound/hda_register.h>
1314 #include "trace.h"
15
+
16
+/**
17
+ * snd_hdac_get_stream_stripe_ctl - get stripe control value
18
+ * @bus: HD-audio core bus
19
+ * @substream: PCM substream
20
+ */
21
+int snd_hdac_get_stream_stripe_ctl(struct hdac_bus *bus,
22
+ struct snd_pcm_substream *substream)
23
+{
24
+ struct snd_pcm_runtime *runtime = substream->runtime;
25
+ unsigned int channels = runtime->channels,
26
+ rate = runtime->rate,
27
+ bits_per_sample = runtime->sample_bits,
28
+ max_sdo_lines, value, sdo_line;
29
+
30
+ /* T_AZA_GCAP_NSDO is 1:2 bitfields in GCAP */
31
+ max_sdo_lines = snd_hdac_chip_readl(bus, GCAP) & AZX_GCAP_NSDO;
32
+
33
+ /* following is from HD audio spec */
34
+ for (sdo_line = max_sdo_lines; sdo_line > 0; sdo_line >>= 1) {
35
+ if (rate > 48000)
36
+ value = (channels * bits_per_sample *
37
+ (rate / 48000)) / sdo_line;
38
+ else
39
+ value = (channels * bits_per_sample) / sdo_line;
40
+
41
+ if (value >= bus->sdo_limit)
42
+ break;
43
+ }
44
+
45
+ /* stripe value: 0 for 1SDO, 1 for 2SDO, 2 for 4SDO lines */
46
+ return sdo_line >> 1;
47
+}
48
+EXPORT_SYMBOL_GPL(snd_hdac_get_stream_stripe_ctl);
1449
1550 /**
1651 * snd_hdac_stream_init - initialize each stream (aka device)
....@@ -48,6 +83,7 @@
4883 void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start)
4984 {
5085 struct hdac_bus *bus = azx_dev->bus;
86
+ int stripe_ctl;
5187
5288 trace_snd_hdac_stream_start(bus, azx_dev);
5389
....@@ -56,7 +92,18 @@
5692 azx_dev->start_wallclk -= azx_dev->period_wallclk;
5793
5894 /* enable SIE */
59
- snd_hdac_chip_updatel(bus, INTCTL, 0, 1 << azx_dev->index);
95
+ snd_hdac_chip_updatel(bus, INTCTL,
96
+ 1 << azx_dev->index,
97
+ 1 << azx_dev->index);
98
+ /* set stripe control */
99
+ if (azx_dev->stripe) {
100
+ if (azx_dev->substream)
101
+ stripe_ctl = snd_hdac_get_stream_stripe_ctl(bus, azx_dev->substream);
102
+ else
103
+ stripe_ctl = 0;
104
+ snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK,
105
+ stripe_ctl);
106
+ }
60107 /* set DMA start and interrupt mask */
61108 snd_hdac_stream_updateb(azx_dev, SD_CTL,
62109 0, SD_CTL_DMA_START | SD_INT_MASK);
....@@ -73,6 +120,8 @@
73120 snd_hdac_stream_updateb(azx_dev, SD_CTL,
74121 SD_CTL_DMA_START | SD_INT_MASK, 0);
75122 snd_hdac_stream_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
123
+ if (azx_dev->stripe)
124
+ snd_hdac_stream_updateb(azx_dev, SD_CTL_3B, SD_CTL_STRIPE_MASK, 0);
76125 azx_dev->running = false;
77126 }
78127 EXPORT_SYMBOL_GPL(snd_hdac_stream_clear);
....@@ -101,8 +150,11 @@
101150 {
102151 unsigned char val;
103152 int timeout;
153
+ int dma_run_state;
104154
105155 snd_hdac_stream_clear(azx_dev);
156
+
157
+ dma_run_state = snd_hdac_stream_readb(azx_dev, SD_CTL) & SD_CTL_DMA_START;
106158
107159 snd_hdac_stream_updateb(azx_dev, SD_CTL, 0, SD_CTL_STREAM_RESET);
108160 udelay(3);
....@@ -113,6 +165,10 @@
113165 if (val)
114166 break;
115167 } while (--timeout);
168
+
169
+ if (azx_dev->bus->dma_stop_delay && dma_run_state)
170
+ udelay(azx_dev->bus->dma_stop_delay);
171
+
116172 val &= ~SD_CTL_STREAM_RESET;
117173 snd_hdac_stream_writeb(azx_dev, SD_CTL, val);
118174 udelay(3);
....@@ -183,11 +239,7 @@
183239 /* set the interrupt enable bits in the descriptor control register */
184240 snd_hdac_stream_updatel(azx_dev, SD_CTL, 0, SD_INT_MASK);
185241
186
- if (azx_dev->direction == SNDRV_PCM_STREAM_PLAYBACK)
187
- azx_dev->fifo_size =
188
- snd_hdac_stream_readw(azx_dev, SD_FIFOSIZE) + 1;
189
- else
190
- azx_dev->fifo_size = 0;
242
+ azx_dev->fifo_size = snd_hdac_stream_readw(azx_dev, SD_FIFOSIZE) + 1;
191243
192244 /* when LPIB delay correction gives a small negative value,
193245 * we ignore it; currently set the threshold statically to
....@@ -244,6 +296,7 @@
244296 int key = (substream->pcm->device << 16) | (substream->number << 2) |
245297 (substream->stream + 1);
246298
299
+ spin_lock_irq(&bus->reg_lock);
247300 list_for_each_entry(azx_dev, &bus->stream_list, list) {
248301 if (azx_dev->direction != substream->stream)
249302 continue;
....@@ -257,13 +310,12 @@
257310 res = azx_dev;
258311 }
259312 if (res) {
260
- spin_lock_irq(&bus->reg_lock);
261313 res->opened = 1;
262314 res->running = 0;
263315 res->assigned_key = key;
264316 res->substream = substream;
265
- spin_unlock_irq(&bus->reg_lock);
266317 }
318
+ spin_unlock_irq(&bus->reg_lock);
267319 return res;
268320 }
269321 EXPORT_SYMBOL_GPL(snd_hdac_stream_assign);
....@@ -545,7 +597,9 @@
545597 /**
546598 * snd_hdac_stream_sync_trigger - turn on/off stream sync register
547599 * @azx_dev: HD-audio core stream (master stream)
600
+ * @set: true = set, false = clear
548601 * @streams: bit flags of streams to sync
602
+ * @reg: the stream sync register address
549603 */
550604 void snd_hdac_stream_sync_trigger(struct hdac_stream *azx_dev, bool set,
551605 unsigned int streams, unsigned int reg)
....@@ -584,20 +638,27 @@
584638 nwait = 0;
585639 i = 0;
586640 list_for_each_entry(s, &bus->stream_list, list) {
587
- if (streams & (1 << i)) {
588
- if (start) {
589
- /* check FIFO gets ready */
590
- if (!(snd_hdac_stream_readb(s, SD_STS) &
591
- SD_STS_FIFO_READY))
592
- nwait++;
593
- } else {
594
- /* check RUN bit is cleared */
595
- if (snd_hdac_stream_readb(s, SD_CTL) &
596
- SD_CTL_DMA_START)
597
- nwait++;
641
+ if (!(streams & (1 << i++)))
642
+ continue;
643
+
644
+ if (start) {
645
+ /* check FIFO gets ready */
646
+ if (!(snd_hdac_stream_readb(s, SD_STS) &
647
+ SD_STS_FIFO_READY))
648
+ nwait++;
649
+ } else {
650
+ /* check RUN bit is cleared */
651
+ if (snd_hdac_stream_readb(s, SD_CTL) &
652
+ SD_CTL_DMA_START) {
653
+ nwait++;
654
+ /*
655
+ * Perform stream reset if DMA RUN
656
+ * bit not cleared within given timeout
657
+ */
658
+ if (timeout == 1)
659
+ snd_hdac_stream_reset(s);
598660 }
599661 }
600
- i++;
601662 }
602663 if (!nwait)
603664 break;
....@@ -634,8 +695,8 @@
634695 azx_dev->locked = true;
635696 spin_unlock_irq(&bus->reg_lock);
636697
637
- err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV_SG,
638
- byte_size, bufp);
698
+ err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG, bus->dev,
699
+ byte_size, bufp);
639700 if (err < 0)
640701 goto err_alloc;
641702
....@@ -661,7 +722,7 @@
661722 return azx_dev->stream_tag;
662723
663724 error:
664
- bus->io_ops->dma_free_pages(bus, bufp);
725
+ snd_dma_free_pages(bufp);
665726 err_alloc:
666727 spin_lock_irq(&bus->reg_lock);
667728 azx_dev->locked = false;
....@@ -708,7 +769,7 @@
708769 azx_dev->period_bytes = 0;
709770 azx_dev->format_val = 0;
710771
711
- bus->io_ops->dma_free_pages(bus, dmab);
772
+ snd_dma_free_pages(dmab);
712773 dmab->area = NULL;
713774
714775 spin_lock_irq(&bus->reg_lock);