Skip to content

Commit

Permalink
ALSA: rawmidi: Show substream activity in info ioctl
Browse files Browse the repository at this point in the history
The UMP legacy rawmidi may turn on/off the substream dynamically
depending on the UMP Function Block information.  So far, there was no
direct way to know whether the substream is disabled (inactive) or
not; at most one can take a look at the substream name string or try
to open and get -ENODEV.

This patch extends the rawmidi info ioctl to show the current inactive
state of the given substream.  When the selected substream is
inactive, info flags field contains the new bit flag
SNDRV_RAWMIDI_INFO_STREAM_INACTIVE.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250110155943.31578-3-tiwai@suse.de
  • Loading branch information
Takashi Iwai committed Jan 12, 2025
1 parent bdf4644 commit b8fefed
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Documentation/sound/designs/midi-2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ Rawmidi API Extensions
On the other hand, the UMP rawmidi device number is found in
`tied_device` field of the legacy rawmidi info, too.

* Each substream of the legacy rawmidi may be enabled / disabled
dynamically depending on the UMP FB state.
When the selected substream is inactive, it's indicated by the bit
0x10 (`SNDRV_RAWMIDI_INFO_STREAM_INACTIVE`) in the `flags` field of
the legacy rawmidi info.


Control API Extensions
======================
Expand Down
1 change: 1 addition & 0 deletions include/sound/rawmidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct snd_rawmidi_substream {
unsigned int framing; /* whether to frame input data */
unsigned int clock_type; /* clock source to use for input framing */
int use_count; /* use counter (for output) */
bool inactive; /* inactive substream (for UMP legacy) */
size_t bytes;
spinlock_t lock;
struct snd_rawmidi *rmidi;
Expand Down
1 change: 1 addition & 0 deletions include/uapi/sound/asound.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ enum {
#define SNDRV_RAWMIDI_INFO_INPUT 0x00000002
#define SNDRV_RAWMIDI_INFO_DUPLEX 0x00000004
#define SNDRV_RAWMIDI_INFO_UMP 0x00000008
#define SNDRV_RAWMIDI_INFO_STREAM_INACTIVE 0x00000010

#define SNDRV_RAWMIDI_DEVICE_UNKNOWN -1

Expand Down
2 changes: 2 additions & 0 deletions sound/core/rawmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ static int snd_rawmidi_info(struct snd_rawmidi_substream *substream,
info->subdevice = substream->number;
info->stream = substream->stream;
info->flags = rmidi->info_flags;
if (substream->inactive)
info->flags |= SNDRV_RAWMIDI_INFO_STREAM_INACTIVE;
strcpy(info->id, rmidi->id);
strcpy(info->name, rmidi->name);
strcpy(info->subname, substream->name);
Expand Down
9 changes: 5 additions & 4 deletions sound/core/ump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,8 +1250,8 @@ static int fill_legacy_mapping(struct snd_ump_endpoint *ump)
return num;
}

static void fill_substream_names(struct snd_ump_endpoint *ump,
struct snd_rawmidi *rmidi, int dir)
static void update_legacy_substreams(struct snd_ump_endpoint *ump,
struct snd_rawmidi *rmidi, int dir)
{
struct snd_rawmidi_substream *s;
const char *name;
Expand All @@ -1265,15 +1265,16 @@ static void fill_substream_names(struct snd_ump_endpoint *ump,
scnprintf(s->name, sizeof(s->name), "Group %d (%.16s)%s",
idx + 1, name,
ump->groups[idx].active ? "" : " [Inactive]");
s->inactive = !ump->groups[idx].active;
}
}

static void update_legacy_names(struct snd_ump_endpoint *ump)
{
struct snd_rawmidi *rmidi = ump->legacy_rmidi;

fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_INPUT);
fill_substream_names(ump, rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT);
update_legacy_substreams(ump, rmidi, SNDRV_RAWMIDI_STREAM_INPUT);
update_legacy_substreams(ump, rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT);
}

int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
Expand Down

0 comments on commit b8fefed

Please sign in to comment.