forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/firewire/fireface/ff-transaction.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ff-transaction.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 "ff.h"
....@@ -51,23 +50,17 @@
5150 finish_transmit_midi_msg(ff, 1, rcode);
5251 }
5352
54
-static inline void fill_midi_buf(struct snd_ff *ff, unsigned int port,
55
- unsigned int index, u8 byte)
56
-{
57
- ff->msg_buf[port][index] = cpu_to_le32(byte);
58
-}
59
-
6053 static void transmit_midi_msg(struct snd_ff *ff, unsigned int port)
6154 {
6255 struct snd_rawmidi_substream *substream =
6356 READ_ONCE(ff->rx_midi_substreams[port]);
64
- u8 *buf = (u8 *)ff->msg_buf[port];
65
- int i, len;
57
+ int quad_count;
6658
6759 struct fw_device *fw_dev = fw_parent_device(ff->unit);
6860 unsigned long long addr;
6961 int generation;
7062 fw_transaction_callback_t callback;
63
+ int tcode;
7164
7265 if (substream == NULL || snd_rawmidi_transmit_empty(substream))
7366 return;
....@@ -81,26 +74,26 @@
8174 return;
8275 }
8376
84
- len = snd_rawmidi_transmit_peek(substream, buf,
85
- SND_FF_MAXIMIM_MIDI_QUADS);
86
- if (len <= 0)
77
+ quad_count = ff->spec->protocol->fill_midi_msg(ff, substream, port);
78
+ if (quad_count <= 0)
8779 return;
8880
89
- for (i = len - 1; i >= 0; i--)
90
- fill_midi_buf(ff, port, i, buf[i]);
91
-
9281 if (port == 0) {
93
- addr = ff->spec->protocol->midi_rx_port_0_reg;
82
+ addr = ff->spec->midi_rx_addrs[0];
9483 callback = finish_transmit_midi0_msg;
9584 } else {
96
- addr = ff->spec->protocol->midi_rx_port_1_reg;
85
+ addr = ff->spec->midi_rx_addrs[1];
9786 callback = finish_transmit_midi1_msg;
9887 }
9988
10089 /* Set interval to next transaction. */
10190 ff->next_ktime[port] = ktime_add_ns(ktime_get(),
102
- len * 8 * (NSEC_PER_SEC / 31250));
103
- ff->rx_bytes[port] = len;
91
+ ff->rx_bytes[port] * 8 * (NSEC_PER_SEC / 31250));
92
+
93
+ if (quad_count == 1)
94
+ tcode = TCODE_WRITE_QUADLET_REQUEST;
95
+ else
96
+ tcode = TCODE_WRITE_BLOCK_REQUEST;
10497
10598 /*
10699 * In Linux FireWire core, when generation is updated with memory
....@@ -112,10 +105,9 @@
112105 */
113106 generation = fw_dev->generation;
114107 smp_rmb();
115
- fw_send_request(fw_dev->card, &ff->transactions[port],
116
- TCODE_WRITE_BLOCK_REQUEST,
108
+ fw_send_request(fw_dev->card, &ff->transactions[port], tcode,
117109 fw_dev->node_id, generation, fw_dev->max_speed,
118
- addr, &ff->msg_buf[port], len * 4,
110
+ addr, &ff->msg_buf[port], quad_count * 4,
119111 callback, &ff->transactions[port]);
120112 }
121113
....@@ -140,42 +132,12 @@
140132 {
141133 struct snd_ff *ff = callback_data;
142134 __le32 *buf = data;
143
- u32 quad;
144
- u8 byte;
145
- unsigned int index;
146
- struct snd_rawmidi_substream *substream;
147
- int i;
148135
149136 fw_send_response(card, request, RCODE_COMPLETE);
150137
151
- for (i = 0; i < length / 4; i++) {
152
- quad = le32_to_cpu(buf[i]);
153
-
154
- /* Message in first port. */
155
- /*
156
- * This value may represent the index of this unit when the same
157
- * units are on the same IEEE 1394 bus. This driver doesn't use
158
- * it.
159
- */
160
- index = (quad >> 8) & 0xff;
161
- if (index > 0) {
162
- substream = READ_ONCE(ff->tx_midi_substreams[0]);
163
- if (substream != NULL) {
164
- byte = quad & 0xff;
165
- snd_rawmidi_receive(substream, &byte, 1);
166
- }
167
- }
168
-
169
- /* Message in second port. */
170
- index = (quad >> 24) & 0xff;
171
- if (index > 0) {
172
- substream = READ_ONCE(ff->tx_midi_substreams[1]);
173
- if (substream != NULL) {
174
- byte = (quad >> 16) & 0xff;
175
- snd_rawmidi_receive(substream, &byte, 1);
176
- }
177
- }
178
- }
138
+ offset -= ff->async_handler.offset;
139
+ ff->spec->protocol->handle_midi_msg(ff, (unsigned int)offset, buf,
140
+ length);
179141 }
180142
181143 static int allocate_own_address(struct snd_ff *ff, int i)
....@@ -183,7 +145,7 @@
183145 struct fw_address_region midi_msg_region;
184146 int err;
185147
186
- ff->async_handler.length = SND_FF_MAXIMIM_MIDI_QUADS * 4;
148
+ ff->async_handler.length = ff->spec->midi_addr_range;
187149 ff->async_handler.address_callback = handle_midi_msg;
188150 ff->async_handler.callback_data = ff;
189151
....@@ -202,38 +164,13 @@
202164 return err;
203165 }
204166
205
-/*
206
- * The configuration to start asynchronous transactions for MIDI messages is in
207
- * 0x'0000'8010'051c. This register includes the other options, thus this driver
208
- * doesn't touch it and leaves the decision to userspace. The userspace MUST add
209
- * 0x04000000 to write transactions to the register to receive any MIDI
210
- * messages.
211
- *
212
- * Here, I just describe MIDI-related offsets of the register, in little-endian
213
- * order.
214
- *
215
- * Controllers are allowed to register higher 4 bytes of address to receive
216
- * the transactions. The register is 0x'0000'8010'03f4. On the other hand, the
217
- * controllers are not allowed to register lower 4 bytes of the address. They
218
- * are forced to select from 4 options by writing corresponding bits to
219
- * 0x'0000'8010'051c.
220
- *
221
- * The 3rd-6th bits in MSB of this register are used to indicate lower 4 bytes
222
- * of address to which the device transferrs the transactions.
223
- * - 6th: 0x'....'....'0000'0180
224
- * - 5th: 0x'....'....'0000'0100
225
- * - 4th: 0x'....'....'0000'0080
226
- * - 3rd: 0x'....'....'0000'0000
227
- *
228
- * This driver configure 0x'....'....'0000'0000 for units to receive MIDI
229
- * messages. 3rd bit of the register should be configured, however this driver
230
- * deligates this task to user space applications due to a restriction that
231
- * this register is write-only and the other bits have own effects.
232
- *
233
- * The 1st and 2nd bits in LSB of this register are used to cancel transferring
234
- * asynchronous transactions. These two bits have the same effect.
235
- * - 1st/2nd: cancel transferring
236
- */
167
+// Controllers are allowed to register higher 4 bytes of destination address to
168
+// receive asynchronous transactions for MIDI messages, while the way to
169
+// register lower 4 bytes of address is different depending on protocols. For
170
+// details, please refer to comments in protocol implementations.
171
+//
172
+// This driver expects userspace applications to configure registers for the
173
+// lower address because in most cases such registers has the other settings.
237174 int snd_ff_transaction_reregister(struct snd_ff *ff)
238175 {
239176 struct fw_card *fw_card = fw_parent_device(ff->unit)->card;
....@@ -247,7 +184,7 @@
247184 addr = (fw_card->node_id << 16) | (ff->async_handler.offset >> 32);
248185 reg = cpu_to_le32(addr);
249186 return snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST,
250
- ff->spec->protocol->midi_high_addr_reg,
187
+ ff->spec->midi_high_addr,
251188 &reg, sizeof(reg), 0);
252189 }
253190
....@@ -288,7 +225,7 @@
288225 /* Release higher 4 bytes of address. */
289226 reg = cpu_to_le32(0x00000000);
290227 snd_fw_transaction(ff->unit, TCODE_WRITE_QUADLET_REQUEST,
291
- ff->spec->protocol->midi_high_addr_reg,
228
+ ff->spec->midi_high_addr,
292229 &reg, sizeof(reg), 0);
293230
294231 fw_core_remove_address_handler(&ff->async_handler);