diff mbox series

[1/3] ALSA: ump: Add helper to change MIDI protocol

Message ID 20230621110241.4751-2-tiwai@suse.de (mailing list archive)
State Accepted
Commit a79807683781d3f215e9d958494e52ed70f4ad27
Headers show
Series ALSA: ump: Preliminary changes for gadget driver | expand

Commit Message

Takashi Iwai June 21, 2023, 11:02 a.m. UTC
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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/ump.h |  2 ++
 sound/core/ump.c    | 31 ++++++++++++++++++++++++-------
 2 files changed, 26 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/include/sound/ump.h b/include/sound/ump.h
index 68478e7be3b4..3c7e67475676 100644
--- a/include/sound/ump.h
+++ b/include/sound/ump.h
@@ -108,6 +108,8 @@  static inline int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
 }
 #endif
 
+int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol);
+
 /*
  * Some definitions for UMP
  */
diff --git a/sound/core/ump.c b/sound/core/ump.c
index a64dc2d8a129..4150b9c0b35b 100644
--- a/sound/core/ump.c
+++ b/sound/core/ump.c
@@ -671,18 +671,35 @@  static void seq_notify_protocol(struct snd_ump_endpoint *ump)
 #endif /* CONFIG_SND_SEQUENCER */
 }
 
+/**
+ * snd_ump_switch_protocol - switch MIDI protocol
+ * @ump: UMP endpoint
+ * @protocol: protocol to switch to
+ *
+ * Returns 1 if the protocol is actually switched, 0 if unchanged
+ */
+int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol)
+{
+	protocol &= ump->info.protocol_caps;
+	if (protocol == ump->info.protocol)
+		return 0;
+
+	ump->info.protocol = protocol;
+	ump_dbg(ump, "New protocol = %x (caps = %x)\n",
+		protocol, ump->info.protocol_caps);
+	seq_notify_protocol(ump);
+	return 1;
+}
+EXPORT_SYMBOL_GPL(snd_ump_switch_protocol);
+
 /* handle EP stream config message; update the UMP protocol */
 static int ump_handle_stream_cfg_msg(struct snd_ump_endpoint *ump,
 				     const union snd_ump_stream_msg *buf)
 {
-	unsigned int old_protocol = ump->info.protocol;
-
-	ump->info.protocol =
+	unsigned int protocol =
 		(buf->stream_cfg.protocol << 8) | buf->stream_cfg.jrts;
-	ump_dbg(ump, "Current protocol = %x (caps = %x)\n",
-		ump->info.protocol, ump->info.protocol_caps);
-	if (ump->parsed && ump->info.protocol != old_protocol)
-		seq_notify_protocol(ump);
+
+	snd_ump_switch_protocol(ump, protocol);
 	return 1; /* finished */
 }