Skip to content

Commit

Permalink
ALSA: usb-audio: Manage number of rawmidis globally
Browse files Browse the repository at this point in the history
We're going to create rawmidi objects for MIDI 2.0 in a different code
from the current code for USB-MIDI 1.0.  As a preliminary work, this
patch adds the number of rawmidi objects to keep globally in a
USB-audio card instance, so that it can be referred from both MIDI 1.0
and 2.0 code.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20230523075358.9672-8-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed May 23, 2023
1 parent fa030f6 commit bb1bf4f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions sound/usb/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
int err = __snd_usbmidi_create(chip->card, iface,
&chip->midi_list, NULL,
chip->usb_id);
&chip->midi_list, NULL,
chip->usb_id,
&chip->num_rawmidis);
if (err < 0) {
dev_err(&dev->dev,
"%u:%d: cannot create sequencer device\n",
Expand Down
7 changes: 6 additions & 1 deletion sound/usb/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,8 @@ int __snd_usbmidi_create(struct snd_card *card,
struct usb_interface *iface,
struct list_head *midi_list,
const struct snd_usb_audio_quirk *quirk,
unsigned int usb_id)
unsigned int usb_id,
unsigned int *num_rawmidis)
{
struct snd_usb_midi *umidi;
struct snd_usb_midi_endpoint_info endpoints[MIDI_MAX_ENDPOINTS];
Expand All @@ -2476,6 +2477,8 @@ int __snd_usbmidi_create(struct snd_card *card,
umidi->iface = iface;
umidi->quirk = quirk;
umidi->usb_protocol_ops = &snd_usbmidi_standard_ops;
if (num_rawmidis)
umidi->next_midi_device = *num_rawmidis;
spin_lock_init(&umidi->disc_lock);
init_rwsem(&umidi->disc_rwsem);
mutex_init(&umidi->mutex);
Expand Down Expand Up @@ -2595,6 +2598,8 @@ int __snd_usbmidi_create(struct snd_card *card,
usb_autopm_get_interface_no_resume(umidi->iface);

list_add_tail(&umidi->list, midi_list);
if (num_rawmidis)
*num_rawmidis = umidi->next_midi_device;
return 0;

free_midi:
Expand Down
5 changes: 3 additions & 2 deletions sound/usb/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ int __snd_usbmidi_create(struct snd_card *card,
struct usb_interface *iface,
struct list_head *midi_list,
const struct snd_usb_audio_quirk *quirk,
unsigned int usb_id);
unsigned int usb_id,
unsigned int *num_rawmidis);

static inline int snd_usbmidi_create(struct snd_card *card,
struct usb_interface *iface,
struct list_head *midi_list,
const struct snd_usb_audio_quirk *quirk)
{
return __snd_usbmidi_create(card, iface, midi_list, quirk, 0);
return __snd_usbmidi_create(card, iface, midi_list, quirk, 0, NULL);
}

void snd_usbmidi_input_stop(struct list_head *p);
Expand Down
5 changes: 3 additions & 2 deletions sound/usb/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,9 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
chip->usb_id == USB_ID(0x0582, 0x002b)
? &ua700_quirk : &uaxx_quirk;
return __snd_usbmidi_create(chip->card, iface,
&chip->midi_list, quirk,
chip->usb_id);
&chip->midi_list, quirk,
chip->usb_id,
&chip->num_rawmidis);
}

if (altsd->bNumEndpoints != 1)
Expand Down
1 change: 1 addition & 0 deletions sound/usb/usbaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct snd_usb_audio {
struct list_head clock_ref_list; /* list of clock refcounts */
int pcm_devs;

unsigned int num_rawmidis; /* number of created rawmidi devices */
struct list_head midi_list; /* list of midi interfaces */

struct list_head mixer_list; /* list of mixer interfaces */
Expand Down

0 comments on commit bb1bf4f

Please sign in to comment.