Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: midi2: Add "Operation Mode" control

Add a new ALSA control element to watch the current operation mode
(MIDI 1.0 or MIDI 2.0). It's a read-only control that reflects the
current value of altsetting, and 0 means unused, 1 for MIDI 1.0
(altset 0) and 2 for MIDI 2.0 (altset 1).

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20230725062206.9674-7-tiwai@suse.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Takashi Iwai and committed by
Greg Kroah-Hartman
1b437d2f 8559caa9

+46
+11
Documentation/usb/gadget-testing.rst
··· 1106 1106 The access to MIDI 1.0 on altset 0 on the host is supported, and it's 1107 1107 translated from/to UMP packets on the gadget. It's bound to only 1108 1108 Function Block 0. 1109 + 1110 + The current operation mode can be observed in ALSA control element 1111 + "Operation Mode" for SND_CTL_IFACE_RAWMIDI. For example:: 1112 + 1113 + $ amixer -c1 contents 1114 + numid=1,iface=RAWMIDI,name='Operation Mode' 1115 + ; type=INTEGER,access=r--v----,values=1,min=0,max=2,step=0 1116 + : values=2 1117 + 1118 + where 0 = unused, 1 = MIDI 1.0 (altset 0), 2 = MIDI 2.0 (altset 1). 1119 + The example above shows it's running in 2, i.e. MIDI 2.0.
+35
drivers/usb/gadget/function/f_midi2.c
··· 9 9 #include <linux/slab.h> 10 10 11 11 #include <sound/core.h> 12 + #include <sound/control.h> 12 13 #include <sound/ump.h> 13 14 #include <sound/ump_msg.h> 14 15 #include <sound/ump_convert.h> ··· 1452 1451 }; 1453 1452 1454 1453 /* 1454 + * "Operation Mode" control element 1455 + */ 1456 + static int f_midi2_operation_mode_info(struct snd_kcontrol *kcontrol, 1457 + struct snd_ctl_elem_info *uinfo) 1458 + { 1459 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1460 + uinfo->count = 1; 1461 + uinfo->value.integer.min = MIDI_OP_MODE_UNSET; 1462 + uinfo->value.integer.max = MIDI_OP_MODE_MIDI2; 1463 + return 0; 1464 + } 1465 + 1466 + static int f_midi2_operation_mode_get(struct snd_kcontrol *kcontrol, 1467 + struct snd_ctl_elem_value *ucontrol) 1468 + { 1469 + struct f_midi2 *midi2 = snd_kcontrol_chip(kcontrol); 1470 + 1471 + ucontrol->value.integer.value[0] = midi2->operation_mode; 1472 + return 0; 1473 + } 1474 + 1475 + static const struct snd_kcontrol_new operation_mode_ctl = { 1476 + .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI, 1477 + .name = "Operation Mode", 1478 + .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 1479 + .info = f_midi2_operation_mode_info, 1480 + .get = f_midi2_operation_mode_get, 1481 + }; 1482 + 1483 + /* 1455 1484 * ALSA UMP instance creation / deletion 1456 1485 */ 1457 1486 static void f_midi2_free_card(struct f_midi2 *midi2) ··· 1577 1546 goto error; 1578 1547 id++; 1579 1548 } 1549 + 1550 + err = snd_ctl_add(card, snd_ctl_new1(&operation_mode_ctl, midi2)); 1551 + if (err < 0) 1552 + goto error; 1580 1553 1581 1554 err = snd_card_register(card); 1582 1555 if (err < 0)