Skip to content

Commit bea36af

Browse files
takaswietiwai
authored andcommitted
ALSA: firewire-motu: add message parser to gather meter information in register DSP model
Some of MOTU models allows software to configure their DSP parameters by accessing to their registers. The models multiplex messages for status of DSP into isochronous packet as well as PCM frames. The message includes information of hardware metering, MIDI message, current parameters of DSP. For my convenience, I call them as 'register DSP' model. This patch adds message parser for them to gather hardware meter information. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Link: https://lore.kernel.org/r/20211015080826.34847-2-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent c18c496 commit bea36af

9 files changed

Lines changed: 219 additions & 7 deletions

File tree

‎include/uapi/sound/firewire.h‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,39 @@ struct snd_firewire_tascam_state {
108108
__be32 data[SNDRV_FIREWIRE_TASCAM_STATE_COUNT];
109109
};
110110

111+
// In below MOTU models, software is allowed to control their DSP by accessing to registers.
112+
// - 828mk2
113+
// - 896hd
114+
// - Traveler
115+
// - 8 pre
116+
// - Ultralite
117+
// - 4 pre
118+
// - Audio Express
119+
//
120+
// On the other hand, the status of DSP is split into specific messages included in the sequence of
121+
// isochronous packet. ALSA firewire-motu driver gathers the messages and allow userspace applications
122+
// to read it via ioctl. In 828mk2, 896hd, and Traveler, hardware meter for all of physical inputs
123+
// are put into the message, while one pair of physical outputs is selected. The selection is done by
124+
// LSB one byte in asynchronous write quadlet transaction to 0x'ffff'f000'0b2c.
125+
//
126+
// I note that V3HD/V4HD uses asynchronous transaction for the purpose. The destination address is
127+
// registered to 0x'ffff'f000'0b38 and '0b3c by asynchronous write quadlet request. The size of
128+
// message differs between 23 and 51 quadlets. For the case, the number of mixer bus can be extended
129+
// up to 12.
130+
131+
#define SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_COUNT 40
132+
133+
/**
134+
* struct snd_firewire_motu_register_dsp_meter - the container for meter information in DSP
135+
* controlled by register access
136+
* @data: Signal level meters. The mapping between position and input/output channel is
137+
* model-dependent.
138+
*
139+
* The structure expresses the part of DSP status for hardware meter. The u8 storage includes linear
140+
* value for audio signal level between 0x00 and 0x7f.
141+
*/
142+
struct snd_firewire_motu_register_dsp_meter {
143+
__u8 data[SNDRV_FIREWIRE_MOTU_REGISTER_DSP_METER_COUNT];
144+
};
145+
111146
#endif /* _UAPI_SOUND_FIREWIRE_H_INCLUDED */

‎sound/firewire/motu/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ CFLAGS_amdtp-motu.o := -I$(src)
44
snd-firewire-motu-objs := motu.o amdtp-motu.o motu-transaction.o motu-stream.o \
55
motu-proc.o motu-pcm.o motu-midi.o motu-hwdep.o \
66
motu-protocol-v2.o motu-protocol-v3.o \
7-
motu-protocol-v1.o
7+
motu-protocol-v1.o motu-register-dsp-message-parser.o
88
obj-$(CONFIG_SND_FIREWIRE_MOTU) += snd-firewire-motu.o

‎sound/firewire/motu/amdtp-motu.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ static unsigned int process_ir_ctx_payloads(struct amdtp_stream *s,
333333
unsigned int packets,
334334
struct snd_pcm_substream *pcm)
335335
{
336+
struct snd_motu *motu = container_of(s, struct snd_motu, tx_stream);
336337
struct amdtp_motu *p = s->protocol;
337338
unsigned int pcm_frames = 0;
338339
int i;
@@ -357,6 +358,11 @@ static unsigned int process_ir_ctx_payloads(struct amdtp_stream *s,
357358
read_midi_messages(s, buf, data_blocks);
358359
}
359360

361+
if (motu->spec->flags & SND_MOTU_SPEC_REGISTER_DSP) {
362+
snd_motu_register_dsp_message_parser_parse(motu, descs, packets,
363+
s->data_block_quadlets);
364+
}
365+
360366
// For tracepoints.
361367
if (trace_data_block_sph_enabled() ||
362368
trace_data_block_message_enabled())

‎sound/firewire/motu/motu-protocol-v2.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,16 @@ const struct snd_motu_spec snd_motu_spec_828mk2 = {
275275
.name = "828mk2",
276276
.protocol_version = SND_MOTU_PROTOCOL_V2,
277277
.flags = SND_MOTU_SPEC_RX_MIDI_2ND_Q |
278-
SND_MOTU_SPEC_TX_MIDI_2ND_Q,
278+
SND_MOTU_SPEC_TX_MIDI_2ND_Q |
279+
SND_MOTU_SPEC_REGISTER_DSP,
279280
.tx_fixed_pcm_chunks = {14, 14, 0},
280281
.rx_fixed_pcm_chunks = {14, 14, 0},
281282
};
282283

283284
const struct snd_motu_spec snd_motu_spec_896hd = {
284285
.name = "896HD",
285286
.protocol_version = SND_MOTU_PROTOCOL_V2,
286-
// No support for MIDI.
287+
.flags = SND_MOTU_SPEC_REGISTER_DSP,
287288
.tx_fixed_pcm_chunks = {14, 14, 8},
288289
.rx_fixed_pcm_chunks = {14, 14, 8},
289290
};
@@ -292,7 +293,8 @@ const struct snd_motu_spec snd_motu_spec_traveler = {
292293
.name = "Traveler",
293294
.protocol_version = SND_MOTU_PROTOCOL_V2,
294295
.flags = SND_MOTU_SPEC_RX_MIDI_2ND_Q |
295-
SND_MOTU_SPEC_TX_MIDI_2ND_Q,
296+
SND_MOTU_SPEC_TX_MIDI_2ND_Q |
297+
SND_MOTU_SPEC_REGISTER_DSP,
296298
.tx_fixed_pcm_chunks = {14, 14, 8},
297299
.rx_fixed_pcm_chunks = {14, 14, 8},
298300
};
@@ -301,7 +303,8 @@ const struct snd_motu_spec snd_motu_spec_ultralite = {
301303
.name = "UltraLite",
302304
.protocol_version = SND_MOTU_PROTOCOL_V2,
303305
.flags = SND_MOTU_SPEC_RX_MIDI_2ND_Q |
304-
SND_MOTU_SPEC_TX_MIDI_2ND_Q,
306+
SND_MOTU_SPEC_TX_MIDI_2ND_Q |
307+
SND_MOTU_SPEC_REGISTER_DSP,
305308
.tx_fixed_pcm_chunks = {14, 14, 0},
306309
.rx_fixed_pcm_chunks = {14, 14, 0},
307310
};
@@ -310,7 +313,8 @@ const struct snd_motu_spec snd_motu_spec_8pre = {
310313
.name = "8pre",
311314
.protocol_version = SND_MOTU_PROTOCOL_V2,
312315
.flags = SND_MOTU_SPEC_RX_MIDI_2ND_Q |
313-
SND_MOTU_SPEC_TX_MIDI_2ND_Q,
316+
SND_MOTU_SPEC_TX_MIDI_2ND_Q |
317+
SND_MOTU_SPEC_REGISTER_DSP,
314318
// Two dummy chunks always in the end of data block.
315319
.tx_fixed_pcm_chunks = {10, 10, 0},
316320
.rx_fixed_pcm_chunks = {6, 6, 0},

‎sound/firewire/motu/motu-protocol-v3.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,16 @@ const struct snd_motu_spec snd_motu_spec_audio_express = {
293293
.name = "AudioExpress",
294294
.protocol_version = SND_MOTU_PROTOCOL_V3,
295295
.flags = SND_MOTU_SPEC_RX_MIDI_2ND_Q |
296-
SND_MOTU_SPEC_TX_MIDI_3RD_Q,
296+
SND_MOTU_SPEC_TX_MIDI_3RD_Q |
297+
SND_MOTU_SPEC_REGISTER_DSP,
297298
.tx_fixed_pcm_chunks = {10, 10, 0},
298299
.rx_fixed_pcm_chunks = {10, 10, 0},
299300
};
300301

301302
const struct snd_motu_spec snd_motu_spec_4pre = {
302303
.name = "4pre",
303304
.protocol_version = SND_MOTU_PROTOCOL_V3,
305+
.flags = SND_MOTU_SPEC_REGISTER_DSP,
304306
.tx_fixed_pcm_chunks = {10, 10, 0},
305307
.rx_fixed_pcm_chunks = {10, 10, 0},
306308
};
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
//
3+
// motu-register-dsp-message-parser.c - a part of driver for MOTU FireWire series
4+
//
5+
// Copyright (c) 2021 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6+
7+
// Below models allow software to configure their DSP functions by asynchronous transaction
8+
// to access their internal registers.
9+
// * 828 mk2
10+
// * 896hd
11+
// * Traveler
12+
// * 8 pre
13+
// * Ultralite
14+
// * 4 pre
15+
// * Audio Express
16+
//
17+
// Additionally, isochronous packets from the above models include messages to notify state of
18+
// DSP. The messages are two set of 3 byte data in 2nd and 3rd quadlet of data block. When user
19+
// operates hardware components such as dial and switch, corresponding messages are transferred.
20+
// The messages include Hardware metering and MIDI messages as well.
21+
22+
#include "motu.h"
23+
24+
#define MSG_FLAG_POS 4
25+
#define MSG_FLAG_TYPE_MASK 0xf8
26+
#define MSG_FLAG_MIDI_MASK 0x01
27+
#define MSG_FLAG_MODEL_SPECIFIC_MASK 0x06
28+
#define MSG_FLAG_8PRE 0x00
29+
#define MSG_FLAG_ULTRALITE 0x04
30+
#define MSG_FLAG_TRAVELER 0x04
31+
#define MSG_FLAG_828MK2 0x04
32+
#define MSG_FLAG_896HD 0x04
33+
#define MSG_FLAG_4PRE 0x05 // MIDI mask is in 8th byte.
34+
#define MSG_FLAG_AUDIOEXPRESS 0x05 // MIDI mask is in 8th byte.
35+
#define MSG_FLAG_TYPE_SHIFT 3
36+
#define MSG_VALUE_POS 5
37+
#define MSG_MIDI_BYTE_POS 6
38+
#define MSG_METER_IDX_POS 7
39+
40+
// In 4 pre and Audio express, meter index is in 6th byte. MIDI flag is in 8th byte and MIDI byte
41+
// is in 7th byte.
42+
#define MSG_METER_IDX_POS_4PRE_AE 6
43+
#define MSG_MIDI_BYTE_POS_4PRE_AE 7
44+
#define MSG_FLAG_MIDI_POS_4PRE_AE 8
45+
46+
enum register_dsp_msg_type {
47+
// Used for messages with no information.
48+
INVALID = 0x00,
49+
MIXER_SELECT = 0x01,
50+
MIXER_SRC_GAIN = 0x02,
51+
MIXER_SRC_PAN = 0x03,
52+
MIXER_SRC_FLAG = 0x04,
53+
MIXER_OUTPUT_PAIRED_VOLUME = 0x05,
54+
MIXER_OUTPUT_PAIRED_FLAG = 0x06,
55+
MAIN_OUTPUT_PAIRED_VOLUME = 0x07,
56+
HP_OUTPUT_PAIRED_VOLUME = 0x08,
57+
HP_OUTPUT_ASSIGN = 0x09,
58+
// Transferred by all models but the purpose is still unknown.
59+
UNKNOWN_0 = 0x0a,
60+
// Specific to 828mk2, 896hd, Traveler.
61+
UNKNOWN_2 = 0x0c,
62+
// Specific to 828mk2, Traveler, and 896hd (not functional).
63+
LINE_INPUT_BOOST = 0x0d,
64+
// Specific to 828mk2, Traveler, and 896hd (not functional).
65+
LINE_INPUT_NOMINAL_LEVEL = 0x0e,
66+
// Specific to Ultralite, 4 pre, Audio express, and 8 pre (not functional).
67+
INPUT_GAIN_AND_INVERT = 0x15,
68+
// Specific to 4 pre, and Audio express.
69+
INPUT_FLAG = 0x16,
70+
// Specific to 4 pre, and Audio express.
71+
MIXER_SRC_PAIRED_BALANCE = 0x17,
72+
// Specific to 4 pre, and Audio express.
73+
MIXER_SRC_PAIRED_WIDTH = 0x18,
74+
// Transferred by all models. This type of message interposes the series of the other
75+
// messages. The message delivers signal level up to 96.0 kHz. In 828mk2, 896hd, and
76+
// Traveler, one of physical outputs is selected for the message. The selection is done
77+
// by LSB one byte in asynchronous write quadlet transaction to 0x'ffff'f000'0b2c.
78+
METER = 0x1f,
79+
};
80+
81+
struct msg_parser {
82+
struct snd_firewire_motu_register_dsp_meter meter;
83+
bool meter_pos_quirk;
84+
};
85+
86+
int snd_motu_register_dsp_message_parser_new(struct snd_motu *motu)
87+
{
88+
struct msg_parser *parser;
89+
parser = devm_kzalloc(&motu->card->card_dev, sizeof(*parser), GFP_KERNEL);
90+
if (!parser)
91+
return -ENOMEM;
92+
if (motu->spec == &snd_motu_spec_4pre || motu->spec == &snd_motu_spec_audio_express)
93+
parser->meter_pos_quirk = true;
94+
motu->message_parser = parser;
95+
return 0;
96+
}
97+
98+
int snd_motu_register_dsp_message_parser_init(struct snd_motu *motu)
99+
{
100+
return 0;
101+
}
102+
103+
void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const struct pkt_desc *descs,
104+
unsigned int desc_count, unsigned int data_block_quadlets)
105+
{
106+
struct msg_parser *parser = motu->message_parser;
107+
bool meter_pos_quirk = parser->meter_pos_quirk;
108+
int i;
109+
110+
for (i = 0; i < desc_count; ++i) {
111+
const struct pkt_desc *desc = descs + i;
112+
__be32 *buffer = desc->ctx_payload;
113+
unsigned int data_blocks = desc->data_blocks;
114+
int j;
115+
116+
for (j = 0; j < data_blocks; ++j) {
117+
u8 *b = (u8 *)buffer;
118+
u8 msg_type = (b[MSG_FLAG_POS] & MSG_FLAG_TYPE_MASK) >> MSG_FLAG_TYPE_SHIFT;
119+
u8 val = b[MSG_VALUE_POS];
120+
121+
buffer += data_block_quadlets;
122+
123+
switch (msg_type) {
124+
case METER:
125+
{
126+
u8 pos;
127+
128+
if (!meter_pos_quirk)
129+
pos = b[MSG_METER_IDX_POS];
130+
else
131+
pos = b[MSG_METER_IDX_POS_4PRE_AE];
132+
133+
if (pos < 0x80)
134+
pos &= 0x1f;
135+
else
136+
pos = (pos & 0x1f) + 20;
137+
parser->meter.data[pos] = val;
138+
break;
139+
}
140+
default:
141+
break;
142+
}
143+
}
144+
}
145+
}

‎sound/firewire/motu/motu-stream.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ int snd_motu_stream_start_duplex(struct snd_motu *motu)
255255
if (err < 0)
256256
return err;
257257

258+
if (motu->spec->flags & SND_MOTU_SPEC_REGISTER_DSP) {
259+
err = snd_motu_register_dsp_message_parser_init(motu);
260+
if (err < 0)
261+
return err;
262+
}
263+
258264
err = begin_session(motu);
259265
if (err < 0) {
260266
dev_err(&motu->unit->device,

‎sound/firewire/motu/motu.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ static int motu_probe(struct fw_unit *unit, const struct ieee1394_device_id *ent
112112
if (err < 0)
113113
goto error;
114114

115+
if (motu->spec->flags & SND_MOTU_SPEC_REGISTER_DSP) {
116+
err = snd_motu_register_dsp_message_parser_new(motu);
117+
if (err < 0)
118+
goto error;
119+
}
120+
115121
err = snd_card_register(card);
116122
if (err < 0)
117123
goto error;

‎sound/firewire/motu/motu.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ struct snd_motu {
7878
struct amdtp_domain domain;
7979

8080
struct amdtp_motu_cache cache;
81+
82+
void *message_parser;
8183
};
8284

8385
enum snd_motu_spec_flags {
8486
SND_MOTU_SPEC_RX_MIDI_2ND_Q = 0x0001,
8587
SND_MOTU_SPEC_RX_MIDI_3RD_Q = 0x0002,
8688
SND_MOTU_SPEC_TX_MIDI_2ND_Q = 0x0004,
8789
SND_MOTU_SPEC_TX_MIDI_3RD_Q = 0x0008,
90+
SND_MOTU_SPEC_REGISTER_DSP = 0x0010,
8891
};
8992

9093
#define SND_MOTU_CLOCK_RATE_COUNT 6
@@ -270,4 +273,9 @@ static inline int snd_motu_protocol_cache_packet_formats(struct snd_motu *motu)
270273
return -ENXIO;
271274
}
272275

276+
int snd_motu_register_dsp_message_parser_new(struct snd_motu *motu);
277+
int snd_motu_register_dsp_message_parser_init(struct snd_motu *motu);
278+
void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const struct pkt_desc *descs,
279+
unsigned int desc_count, unsigned int data_block_quadlets);
280+
273281
#endif

0 commit comments

Comments
 (0)