An f_midi instance will have a corresponding native
device in /dev/snd/midiC%dD%d where the first number
is the number of the sound card and the second is the
number of the device. Expose both of these through
configfs so the user can find the correct sound device.

The configfs attrs are read only and will return the
appropriate value, or -1 if it is not available.

Signed-off-by: Jerry Zhang <zhangje...@google.com>
---
 drivers/usb/gadget/function/f_midi.c | 38 ++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index a89908eb035f..5d4a444ff073 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -1179,6 +1179,42 @@ static ssize_t f_midi_opts_id_store(struct config_item 
*item,
 
 CONFIGFS_ATTR(f_midi_opts_, id);
 
+static ssize_t f_midi_opts_card_show(struct config_item *item, char *page)
+{
+       struct f_midi_opts *opts = to_f_midi_opts(item);
+       int card = -1;
+       struct f_midi *midi;
+
+       if (opts->func_inst.f) {
+               midi = func_to_midi(opts->func_inst.f);
+               if (midi->rmidi && midi->rmidi->card) {
+                       card = midi->rmidi->card->number;
+               }
+       }
+
+       return sprintf(page, "%d\n", card);
+}
+
+CONFIGFS_ATTR_RO(f_midi_opts_, card);
+
+static ssize_t f_midi_opts_device_show(struct config_item *item, char *page)
+{
+       struct f_midi_opts *opts = to_f_midi_opts(item);
+       int device = -1;
+       struct f_midi *midi;
+
+       if (opts->func_inst.f) {
+               midi = func_to_midi(opts->func_inst.f);
+               if (midi->rmidi) {
+                       device = midi->rmidi->device;
+               }
+       }
+
+       return sprintf(page, "%d\n", device);
+}
+
+CONFIGFS_ATTR_RO(f_midi_opts_, device);
+
 static struct configfs_attribute *midi_attrs[] = {
        &f_midi_opts_attr_index,
        &f_midi_opts_attr_buflen,
@@ -1186,6 +1222,8 @@ static struct configfs_attribute *midi_attrs[] = {
        &f_midi_opts_attr_in_ports,
        &f_midi_opts_attr_out_ports,
        &f_midi_opts_attr_id,
+       &f_midi_opts_attr_card,
+       &f_midi_opts_attr_device,
        NULL,
 };
 
-- 
2.17.0.484.g0c8726318c-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to