Commit b8fefed7 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: rawmidi: Show substream activity in info ioctl



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: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250110155943.31578-3-tiwai@suse.de
parent bdf46443
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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
======================
+1 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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

+2 −0
Original line number Diff line number Diff line
@@ -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);
+5 −4
Original line number Diff line number Diff line
@@ -1250,7 +1250,7 @@ static int fill_legacy_mapping(struct snd_ump_endpoint *ump)
	return num;
}

static void fill_substream_names(struct snd_ump_endpoint *ump,
static void update_legacy_substreams(struct snd_ump_endpoint *ump,
				     struct snd_rawmidi *rmidi, int dir)
{
	struct snd_rawmidi_substream *s;
@@ -1265,6 +1265,7 @@ 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;
	}
}

@@ -1272,8 +1273,8 @@ 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,