forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/firewire/fireface/amdtp-ff.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * amdtp-ff.c - a part of driver for RME Fireface series
34 *
45 * Copyright (c) 2015-2017 Takashi Sakamoto
5
- *
6
- * Licensed under the terms of the GNU General Public License, version 2.
76 */
87
98 #include <sound/pcm.h>
....@@ -28,19 +27,24 @@
2827 return amdtp_stream_set_parameters(s, rate, data_channels);
2928 }
3029
31
-static void write_pcm_s32(struct amdtp_stream *s,
32
- struct snd_pcm_substream *pcm,
33
- __le32 *buffer, unsigned int frames)
30
+static void write_pcm_s32(struct amdtp_stream *s, struct snd_pcm_substream *pcm,
31
+ __le32 *buffer, unsigned int frames,
32
+ unsigned int pcm_frames)
3433 {
3534 struct amdtp_ff *p = s->protocol;
35
+ unsigned int channels = p->pcm_channels;
3636 struct snd_pcm_runtime *runtime = pcm->runtime;
37
- unsigned int channels, remaining_frames, i, c;
37
+ unsigned int pcm_buffer_pointer;
38
+ int remaining_frames;
3839 const u32 *src;
40
+ int i, c;
3941
40
- channels = p->pcm_channels;
42
+ pcm_buffer_pointer = s->pcm_buffer_pointer + pcm_frames;
43
+ pcm_buffer_pointer %= runtime->buffer_size;
44
+
4145 src = (void *)runtime->dma_area +
42
- frames_to_bytes(runtime, s->pcm_buffer_pointer);
43
- remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
46
+ frames_to_bytes(runtime, pcm_buffer_pointer);
47
+ remaining_frames = runtime->buffer_size - pcm_buffer_pointer;
4448
4549 for (i = 0; i < frames; ++i) {
4650 for (c = 0; c < channels; ++c) {
....@@ -53,19 +57,24 @@
5357 }
5458 }
5559
56
-static void read_pcm_s32(struct amdtp_stream *s,
57
- struct snd_pcm_substream *pcm,
58
- __le32 *buffer, unsigned int frames)
60
+static void read_pcm_s32(struct amdtp_stream *s, struct snd_pcm_substream *pcm,
61
+ __le32 *buffer, unsigned int frames,
62
+ unsigned int pcm_frames)
5963 {
6064 struct amdtp_ff *p = s->protocol;
65
+ unsigned int channels = p->pcm_channels;
6166 struct snd_pcm_runtime *runtime = pcm->runtime;
62
- unsigned int channels, remaining_frames, i, c;
67
+ unsigned int pcm_buffer_pointer;
68
+ int remaining_frames;
6369 u32 *dst;
70
+ int i, c;
6471
65
- channels = p->pcm_channels;
72
+ pcm_buffer_pointer = s->pcm_buffer_pointer + pcm_frames;
73
+ pcm_buffer_pointer %= runtime->buffer_size;
74
+
6675 dst = (void *)runtime->dma_area +
67
- frames_to_bytes(runtime, s->pcm_buffer_pointer);
68
- remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;
76
+ frames_to_bytes(runtime, pcm_buffer_pointer);
77
+ remaining_frames = runtime->buffer_size - pcm_buffer_pointer;
6978
7079 for (i = 0; i < frames; ++i) {
7180 for (c = 0; c < channels; ++c) {
....@@ -103,38 +112,47 @@
103112 return amdtp_stream_add_pcm_hw_constraints(s, runtime);
104113 }
105114
106
-static unsigned int process_rx_data_blocks(struct amdtp_stream *s,
107
- __be32 *buffer,
108
- unsigned int data_blocks,
109
- unsigned int *syt)
115
+static unsigned int process_it_ctx_payloads(struct amdtp_stream *s,
116
+ const struct pkt_desc *descs,
117
+ unsigned int packets,
118
+ struct snd_pcm_substream *pcm)
110119 {
111
- struct snd_pcm_substream *pcm = READ_ONCE(s->pcm);
112
- unsigned int pcm_frames;
120
+ unsigned int pcm_frames = 0;
121
+ int i;
113122
114
- if (pcm) {
115
- write_pcm_s32(s, pcm, (__le32 *)buffer, data_blocks);
116
- pcm_frames = data_blocks;
117
- } else {
118
- write_pcm_silence(s, (__le32 *)buffer, data_blocks);
119
- pcm_frames = 0;
123
+ for (i = 0; i < packets; ++i) {
124
+ const struct pkt_desc *desc = descs + i;
125
+ __le32 *buf = (__le32 *)desc->ctx_payload;
126
+ unsigned int data_blocks = desc->data_blocks;
127
+
128
+ if (pcm) {
129
+ write_pcm_s32(s, pcm, buf, data_blocks, pcm_frames);
130
+ pcm_frames += data_blocks;
131
+ } else {
132
+ write_pcm_silence(s, buf, data_blocks);
133
+ }
120134 }
121135
122136 return pcm_frames;
123137 }
124138
125
-static unsigned int process_tx_data_blocks(struct amdtp_stream *s,
126
- __be32 *buffer,
127
- unsigned int data_blocks,
128
- unsigned int *syt)
139
+static unsigned int process_ir_ctx_payloads(struct amdtp_stream *s,
140
+ const struct pkt_desc *descs,
141
+ unsigned int packets,
142
+ struct snd_pcm_substream *pcm)
129143 {
130
- struct snd_pcm_substream *pcm = READ_ONCE(s->pcm);
131
- unsigned int pcm_frames;
144
+ unsigned int pcm_frames = 0;
145
+ int i;
132146
133
- if (pcm) {
134
- read_pcm_s32(s, pcm, (__le32 *)buffer, data_blocks);
135
- pcm_frames = data_blocks;
136
- } else {
137
- pcm_frames = 0;
147
+ for (i = 0; i < packets; ++i) {
148
+ const struct pkt_desc *desc = descs + i;
149
+ __le32 *buf = (__le32 *)desc->ctx_payload;
150
+ unsigned int data_blocks = desc->data_blocks;
151
+
152
+ if (pcm) {
153
+ read_pcm_s32(s, pcm, buf, data_blocks, pcm_frames);
154
+ pcm_frames += data_blocks;
155
+ }
138156 }
139157
140158 return pcm_frames;
....@@ -143,13 +161,13 @@
143161 int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
144162 enum amdtp_stream_direction dir)
145163 {
146
- amdtp_stream_process_data_blocks_t process_data_blocks;
164
+ amdtp_stream_process_ctx_payloads_t process_ctx_payloads;
147165
148166 if (dir == AMDTP_IN_STREAM)
149
- process_data_blocks = process_tx_data_blocks;
167
+ process_ctx_payloads = process_ir_ctx_payloads;
150168 else
151
- process_data_blocks = process_rx_data_blocks;
169
+ process_ctx_payloads = process_it_ctx_payloads;
152170
153171 return amdtp_stream_init(s, unit, dir, CIP_NO_HEADER, 0,
154
- process_data_blocks, sizeof(struct amdtp_ff));
172
+ process_ctx_payloads, sizeof(struct amdtp_ff));
155173 }