Skip to content

Commit 06cf3bf

Browse files
committed
ALSA: usb-audio: Get UMP EP name string from USB interface
USB descriptor may provide a nicer name for USB interface, and we may take it as the UMP Endpoint name. The UMP EP name is copied as the rawmidi name, too. Also, fill the UMP block product_id field from the iSerialNumber string of the USB device descriptor as a recommended unique id, too. Reviewed-by: Jaroslav Kysela <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent ff49d1d commit 06cf3bf

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

sound/usb/midi2.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,15 +892,39 @@ static int set_altset(struct snd_usb_midi2_interface *umidi)
892892
umidi->hostif->desc.bAlternateSetting);
893893
}
894894

895+
/* fill UMP Endpoint name string from USB descriptor */
896+
static void fill_ump_ep_name(struct snd_ump_endpoint *ump,
897+
struct usb_device *dev, int id)
898+
{
899+
usb_string(dev, id, ump->info.name, sizeof(ump->info.name));
900+
}
901+
895902
/* fill the fallback name string for each rawmidi instance */
896903
static void set_fallback_rawmidi_names(struct snd_usb_midi2_interface *umidi)
897904
{
905+
struct usb_device *dev = umidi->chip->dev;
898906
struct snd_usb_midi2_ump *rmidi;
907+
struct snd_ump_endpoint *ump;
899908

900909
list_for_each_entry(rmidi, &umidi->rawmidi_list, list) {
901-
if (!*rmidi->ump->core.name)
902-
sprintf(rmidi->ump->core.name, "USB MIDI %d",
903-
rmidi->index);
910+
ump = rmidi->ump;
911+
/* fill UMP EP name from USB descriptors */
912+
if (!*ump->info.name && umidi->hostif->desc.iInterface)
913+
fill_ump_ep_name(ump, dev, umidi->hostif->desc.iInterface);
914+
else if (!*ump->info.name && dev->descriptor.iProduct)
915+
fill_ump_ep_name(ump, dev, dev->descriptor.iProduct);
916+
/* fill fallback name */
917+
if (!*ump->info.name)
918+
sprintf(ump->info.name, "USB MIDI %d", rmidi->index);
919+
/* copy as rawmidi name if not set */
920+
if (!*ump->core.name)
921+
strscpy(ump->core.name, ump->info.name,
922+
sizeof(ump->core.name));
923+
/* use serial number string as unique UMP product id */
924+
if (!*ump->info.product_id && dev->descriptor.iSerialNumber)
925+
usb_string(dev, dev->descriptor.iSerialNumber,
926+
ump->info.product_id,
927+
sizeof(ump->info.product_id));
904928
}
905929
}
906930

0 commit comments

Comments
 (0)