Skip to content

Commit a798076

Browse files
committed
ALSA: ump: Add helper to change MIDI protocol
This is a preliminary patch for MIDI 2.0 USB gadget driver. Export a new helper to allow changing the current MIDI protocol from the outside. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent febdfa0 commit a798076

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

include/sound/ump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ static inline int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
108108
}
109109
#endif
110110

111+
int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol);
112+
111113
/*
112114
* Some definitions for UMP
113115
*/

sound/core/ump.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,18 +671,35 @@ static void seq_notify_protocol(struct snd_ump_endpoint *ump)
671671
#endif /* CONFIG_SND_SEQUENCER */
672672
}
673673

674+
/**
675+
* snd_ump_switch_protocol - switch MIDI protocol
676+
* @ump: UMP endpoint
677+
* @protocol: protocol to switch to
678+
*
679+
* Returns 1 if the protocol is actually switched, 0 if unchanged
680+
*/
681+
int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol)
682+
{
683+
protocol &= ump->info.protocol_caps;
684+
if (protocol == ump->info.protocol)
685+
return 0;
686+
687+
ump->info.protocol = protocol;
688+
ump_dbg(ump, "New protocol = %x (caps = %x)\n",
689+
protocol, ump->info.protocol_caps);
690+
seq_notify_protocol(ump);
691+
return 1;
692+
}
693+
EXPORT_SYMBOL_GPL(snd_ump_switch_protocol);
694+
674695
/* handle EP stream config message; update the UMP protocol */
675696
static int ump_handle_stream_cfg_msg(struct snd_ump_endpoint *ump,
676697
const union snd_ump_stream_msg *buf)
677698
{
678-
unsigned int old_protocol = ump->info.protocol;
679-
680-
ump->info.protocol =
699+
unsigned int protocol =
681700
(buf->stream_cfg.protocol << 8) | buf->stream_cfg.jrts;
682-
ump_dbg(ump, "Current protocol = %x (caps = %x)\n",
683-
ump->info.protocol, ump->info.protocol_caps);
684-
if (ump->parsed && ump->info.protocol != old_protocol)
685-
seq_notify_protocol(ump);
701+
702+
snd_ump_switch_protocol(ump, protocol);
686703
return 1; /* finished */
687704
}
688705

0 commit comments

Comments
 (0)