Skip to content

Commit 6b164ea

Browse files
committed
Merge branch 'topic/midi20' into for-next
This is a small patch set to change the UMP core for the upcoming gadget driver support. Basically exporting a couple of helper functions and adding a flag to suppress the internal UMP handling. No functional changes by those alone. Link: https://lore.kernel.org/r/20230621110241.4751-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
2 parents 8d0cf15 + 4dce2f0 commit 6b164ea

2 files changed

Lines changed: 40 additions & 10 deletions

File tree

include/sound/ump.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct snd_ump_endpoint {
2828
u32 stream_wait_for; /* expected stream message status */
2929
bool stream_finished; /* set when message has been processed */
3030
bool parsed; /* UMP / FB parse finished? */
31+
bool no_process_stream; /* suppress UMP stream messages handling */
3132
wait_queue_head_t stream_wait;
3233
struct snd_rawmidi_file stream_rfile;
3334

@@ -108,6 +109,9 @@ static inline int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
108109
}
109110
#endif
110111

112+
int snd_ump_receive_ump_val(struct snd_ump_endpoint *ump, u32 val);
113+
int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol);
114+
111115
/*
112116
* Some definitions for UMP
113117
*/

sound/core/ump.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,16 @@ static unsigned char ump_packet_words[0x10] = {
263263
1, 1, 1, 2, 2, 4, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4
264264
};
265265

266-
/* parse the UMP packet data;
267-
* the data is copied onto ump->input_buf[].
266+
/**
267+
* snd_ump_receive_ump_val - parse the UMP packet data
268+
* @ump: UMP endpoint
269+
* @val: UMP packet data
270+
*
271+
* The data is copied onto ump->input_buf[].
268272
* When a full packet is completed, returns the number of words (from 1 to 4).
269273
* OTOH, if the packet is incomplete, returns 0.
270274
*/
271-
static int snd_ump_receive_ump_val(struct snd_ump_endpoint *ump, u32 val)
275+
int snd_ump_receive_ump_val(struct snd_ump_endpoint *ump, u32 val)
272276
{
273277
int words;
274278

@@ -284,6 +288,7 @@ static int snd_ump_receive_ump_val(struct snd_ump_endpoint *ump, u32 val)
284288
}
285289
return 0;
286290
}
291+
EXPORT_SYMBOL_GPL(snd_ump_receive_ump_val);
287292

288293
/**
289294
* snd_ump_receive - transfer UMP packets from the device
@@ -671,18 +676,35 @@ static void seq_notify_protocol(struct snd_ump_endpoint *ump)
671676
#endif /* CONFIG_SND_SEQUENCER */
672677
}
673678

679+
/**
680+
* snd_ump_switch_protocol - switch MIDI protocol
681+
* @ump: UMP endpoint
682+
* @protocol: protocol to switch to
683+
*
684+
* Returns 1 if the protocol is actually switched, 0 if unchanged
685+
*/
686+
int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol)
687+
{
688+
protocol &= ump->info.protocol_caps;
689+
if (protocol == ump->info.protocol)
690+
return 0;
691+
692+
ump->info.protocol = protocol;
693+
ump_dbg(ump, "New protocol = %x (caps = %x)\n",
694+
protocol, ump->info.protocol_caps);
695+
seq_notify_protocol(ump);
696+
return 1;
697+
}
698+
EXPORT_SYMBOL_GPL(snd_ump_switch_protocol);
699+
674700
/* handle EP stream config message; update the UMP protocol */
675701
static int ump_handle_stream_cfg_msg(struct snd_ump_endpoint *ump,
676702
const union snd_ump_stream_msg *buf)
677703
{
678-
unsigned int old_protocol = ump->info.protocol;
679-
680-
ump->info.protocol =
704+
unsigned int protocol =
681705
(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);
706+
707+
snd_ump_switch_protocol(ump, protocol);
686708
return 1; /* finished */
687709
}
688710

@@ -837,6 +859,10 @@ static void ump_handle_stream_msg(struct snd_ump_endpoint *ump,
837859
unsigned int status;
838860
int ret;
839861

862+
/* UMP stream message suppressed (for gadget UMP)? */
863+
if (ump->no_process_stream)
864+
return;
865+
840866
BUILD_BUG_ON(sizeof(*msg) != 16);
841867
ump_dbg(ump, "Stream msg: %08x %08x %08x %08x\n",
842868
buf[0], buf[1], buf[2], buf[3]);

0 commit comments

Comments
 (0)