Skip to content

Commit 4c9eda8

Browse files
takaswietiwai
authored andcommitted
ALSA: firewire-motu: queue event for parameter change in register DSP model
This commit is a preparation to notify parameter change of register DSP to userspace application. A simple queue is added to store encoded data for the change as long as ALSA hwdep character device is opened by application. Signed-off-by: Takashi Sakamoto <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent ca15a09 commit 4c9eda8

File tree

3 files changed

+82
-14
lines changed

3 files changed

+82
-14
lines changed

sound/firewire/motu/motu-hwdep.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,7 @@ int snd_motu_create_hwdep_device(struct snd_motu *motu)
258258
hwdep->private_data = motu;
259259
hwdep->exclusive = true;
260260

261+
motu->hwdep = hwdep;
262+
261263
return 0;
262264
}

sound/firewire/motu/motu-register-dsp-message-parser.c

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ enum register_dsp_msg_type {
7878
METER = 0x1f,
7979
};
8080

81+
#define EVENT_QUEUE_SIZE 16
82+
8183
struct msg_parser {
8284
spinlock_t lock;
8385
struct snd_firewire_motu_register_dsp_meter meter;
@@ -90,6 +92,9 @@ struct msg_parser {
9092

9193
u8 input_ch;
9294
u8 prev_msg_type;
95+
96+
u32 event_queue[EVENT_QUEUE_SIZE];
97+
unsigned int push_pos;
9398
};
9499

95100
int snd_motu_register_dsp_message_parser_new(struct snd_motu *motu)
@@ -117,6 +122,24 @@ int snd_motu_register_dsp_message_parser_init(struct snd_motu *motu)
117122
return 0;
118123
}
119124

125+
static void queue_event(struct snd_motu *motu, u8 msg_type, u8 identifier0, u8 identifier1, u8 val)
126+
{
127+
struct msg_parser *parser = motu->message_parser;
128+
unsigned int pos = parser->push_pos;
129+
u32 entry;
130+
131+
if (!motu->hwdep || motu->hwdep->used == 0)
132+
return;
133+
134+
entry = (msg_type << 24) | (identifier0 << 16) | (identifier1 << 8) | val;
135+
parser->event_queue[pos] = entry;
136+
137+
++pos;
138+
if (pos >= EVENT_QUEUE_SIZE)
139+
pos = 0;
140+
parser->push_pos = pos;
141+
}
142+
120143
void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const struct pkt_desc *descs,
121144
unsigned int desc_count, unsigned int data_block_quadlets)
122145
{
@@ -172,19 +195,34 @@ void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const str
172195

173196
switch (msg_type) {
174197
case MIXER_SRC_GAIN:
175-
param->mixer.source[mixer_ch].gain[mixer_src_ch] = val;
198+
if (param->mixer.source[mixer_ch].gain[mixer_src_ch] != val) {
199+
queue_event(motu, msg_type, mixer_ch, mixer_src_ch, val);
200+
param->mixer.source[mixer_ch].gain[mixer_src_ch] = val;
201+
}
176202
break;
177203
case MIXER_SRC_PAN:
178-
param->mixer.source[mixer_ch].pan[mixer_src_ch] = val;
204+
if (param->mixer.source[mixer_ch].pan[mixer_src_ch] != val) {
205+
queue_event(motu, msg_type, mixer_ch, mixer_src_ch, val);
206+
param->mixer.source[mixer_ch].pan[mixer_src_ch] = val;
207+
}
179208
break;
180209
case MIXER_SRC_FLAG:
181-
param->mixer.source[mixer_ch].flag[mixer_src_ch] = val;
210+
if (param->mixer.source[mixer_ch].flag[mixer_src_ch] != val) {
211+
queue_event(motu, msg_type, mixer_ch, mixer_src_ch, val);
212+
param->mixer.source[mixer_ch].flag[mixer_src_ch] = val;
213+
}
182214
break;
183215
case MIXER_SRC_PAIRED_BALANCE:
184-
param->mixer.source[mixer_ch].paired_balance[mixer_src_ch] = val;
216+
if (param->mixer.source[mixer_ch].paired_balance[mixer_src_ch] != val) {
217+
queue_event(motu, msg_type, mixer_ch, mixer_src_ch, val);
218+
param->mixer.source[mixer_ch].paired_balance[mixer_src_ch] = val;
219+
}
185220
break;
186221
case MIXER_SRC_PAIRED_WIDTH:
187-
param->mixer.source[mixer_ch].paired_width[mixer_src_ch] = val;
222+
if (param->mixer.source[mixer_ch].paired_width[mixer_src_ch] != val) {
223+
queue_event(motu, msg_type, mixer_ch, mixer_src_ch, val);
224+
param->mixer.source[mixer_ch].paired_width[mixer_src_ch] = val;
225+
}
188226
break;
189227
default:
190228
break;
@@ -203,10 +241,16 @@ void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const str
203241
if (mixer_ch < SNDRV_FIREWIRE_MOTU_REGISTER_DSP_MIXER_COUNT) {
204242
switch (msg_type) {
205243
case MIXER_OUTPUT_PAIRED_VOLUME:
206-
param->mixer.output.paired_volume[mixer_ch] = val;
244+
if (param->mixer.output.paired_volume[mixer_ch] != val) {
245+
queue_event(motu, msg_type, mixer_ch, 0, val);
246+
param->mixer.output.paired_volume[mixer_ch] = val;
247+
}
207248
break;
208249
case MIXER_OUTPUT_PAIRED_FLAG:
209-
param->mixer.output.paired_flag[mixer_ch] = val;
250+
if (param->mixer.output.paired_flag[mixer_ch] != val) {
251+
queue_event(motu, msg_type, mixer_ch, 0, val);
252+
param->mixer.output.paired_flag[mixer_ch] = val;
253+
}
210254
break;
211255
default:
212256
break;
@@ -215,19 +259,34 @@ void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const str
215259
break;
216260
}
217261
case MAIN_OUTPUT_PAIRED_VOLUME:
218-
parser->param.output.main_paired_volume = val;
262+
if (parser->param.output.main_paired_volume != val) {
263+
queue_event(motu, msg_type, 0, 0, val);
264+
parser->param.output.main_paired_volume = val;
265+
}
219266
break;
220267
case HP_OUTPUT_PAIRED_VOLUME:
221-
parser->param.output.hp_paired_volume = val;
268+
if (parser->param.output.hp_paired_volume != val) {
269+
queue_event(motu, msg_type, 0, 0, val);
270+
parser->param.output.hp_paired_volume = val;
271+
}
222272
break;
223273
case HP_OUTPUT_PAIRED_ASSIGNMENT:
224-
parser->param.output.hp_paired_assignment = val;
274+
if (parser->param.output.hp_paired_assignment != val) {
275+
queue_event(motu, msg_type, 0, 0, val);
276+
parser->param.output.hp_paired_assignment = val;
277+
}
225278
break;
226279
case LINE_INPUT_BOOST:
227-
parser->param.line_input.boost_flag = val;
280+
if (parser->param.line_input.boost_flag != val) {
281+
queue_event(motu, msg_type, 0, 0, val);
282+
parser->param.line_input.boost_flag = val;
283+
}
228284
break;
229285
case LINE_INPUT_NOMINAL_LEVEL:
230-
parser->param.line_input.nominal_level_flag = val;
286+
if (parser->param.line_input.nominal_level_flag != val) {
287+
queue_event(motu, msg_type, 0, 0, val);
288+
parser->param.line_input.nominal_level_flag = val;
289+
}
231290
break;
232291
case INPUT_GAIN_AND_INVERT:
233292
case INPUT_FLAG:
@@ -243,10 +302,16 @@ void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const str
243302
if (input_ch < SNDRV_FIREWIRE_MOTU_REGISTER_DSP_INPUT_COUNT) {
244303
switch (msg_type) {
245304
case INPUT_GAIN_AND_INVERT:
246-
param->input.gain_and_invert[input_ch] = val;
305+
if (param->input.gain_and_invert[input_ch] != val) {
306+
queue_event(motu, msg_type, input_ch, 0, val);
307+
param->input.gain_and_invert[input_ch] = val;
308+
}
247309
break;
248310
case INPUT_FLAG:
249-
param->input.flag[input_ch] = val;
311+
if (param->input.flag[input_ch] != val) {
312+
queue_event(motu, msg_type, input_ch, 0, val);
313+
param->input.flag[input_ch] = val;
314+
}
250315
break;
251316
default:
252317
break;

sound/firewire/motu/motu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct snd_motu {
7474
int dev_lock_count;
7575
bool dev_lock_changed;
7676
wait_queue_head_t hwdep_wait;
77+
struct snd_hwdep *hwdep;
7778

7879
struct amdtp_domain domain;
7980

0 commit comments

Comments
 (0)