Skip to contentSkip to conversation

integrate snd-usb-midi into snd-usb-audio

PATCH In review Clemens Ladisch 4 participants 5 messages Aug 26, 2002 – Sep 3, 2002 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 integrate snd-usb-midi into snd-usb-audio

Index: acore/seq/Makefile
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/acore/seq/Makefile,v retrieving revision 1.2

seq/Makefile +3 -1
diff -u -r1.2 Makefile
@@ -3,7 +3,9 @@
 include $(TOPDIR)/toplevel.config
 include $(TOPDIR)/Makefile.conf
 
-obj-$(CONFIG_SND_USB_MIDI) += snd-seq-virmidi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
+ifeq ($(subst m,y,$(CONFIG_SND_SEQUENCER)),y)
+obj-$(CONFIG_SND_USB_AUDIO) += snd-seq-virmidi.o snd-seq.o snd-seq-device.o snd-seq-midi-event.o
+endif
 
 TOPDIR = $(MAINSRCDIR)
 include $(TOPDIR)/alsa-kernel/core/seq/Makefile

Index: include/sndmagic.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/include/sndmagic.h,v retrieving revision 1.10

sndmagic.h +3 -3
diff -u -r1.10 sndmagic.h
@@ -140,9 +140,9 @@
 #define snd_usb_audio_t_magic			0xa15a3e01
 #define usb_mixer_elem_info_t_magic		0xa15a3e02
 #define snd_usb_stream_t_magic			0xa15a3e03
-#define usbmidi_t_magic				0xa15a3f01
-#define usbmidi_out_endpoint_t_magic		0xa15a3f02
-#define usbmidi_in_endpoint_t_magic		0xa15a3f03
+#define snd_usb_midi_t_magic			0xa15a3f01
+#define snd_usb_midi_out_endpoint_t_magic	0xa15a3f02
+#define snd_usb_midi_in_endpoint_t_magic	0xa15a3f03
 
 
 #else

Index: scripts/Modules.dep
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/scripts/Modules.dep,v retrieving revision 1.16

Modules.dep +1 -1
diff -u -r1.16 Modules.dep
@@ -203,4 +203,4 @@
 
 %dir linux/sound/usb
 |snd-usb-audio snd-pcm
-|snd-usb-midi @if_sequencer snd-seq-device snd-seq-midi-event
+snd-usb-midi @if_sequencer snd-seq-device snd-seq-midi-event

Index: usb/Config.help
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/Config.help,v retrieving revision 1.1

Config.help +0 -3
diff -u -r1.1 Config.help
@@ -1,5 +1,2 @@
 CONFIG_SND_USB_AUDIO
   Say 'Y' or 'M' to include support for USB audio devices.
-
-CONFIG_SND_USB_MIDI
-  Say 'Y' or 'M' to include support for MIDI devices connected via USB.

Index: usb/Config.in
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/Config.in,v retrieving revision 1.1

Config.in +0 -1
diff -u -r1.1 Config.in
@@ -4,6 +4,5 @@
 comment 'ALSA USB devices'
 
 dep_tristate 'USB Audio driver' CONFIG_SND_USB_AUDIO $CONFIG_SND
-dep_tristate 'USB MIDI driver' CONFIG_SND_USB_MIDI $CONFIG_SND $CONFIG_SND_SEQUENCER
 
 endmenu

Index: usb/Makefile
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/Makefile,v retrieving revision 1.1

Makefile +5 -1
diff -u -r1.1 Makefile
@@ -3,10 +3,14 @@
 #
 
 snd-usb-audio-objs := usbaudio.o usbmixer.o
+ifeq ($(subst m,y,$(CONFIG_SND_SEQUENCER)),y)
 snd-usb-midi-objs := usbmidi.o
+endif
 
 # Toplevel Module Dependency
 obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o
-obj-$(CONFIG_SND_USB_MIDI) += snd-usb-midi.o
+ifeq ($(subst m,y,$(CONFIG_SND_SEQUENCER)),y)
+obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-midi.o
+endif
 
 include $(TOPDIR)/Rules.make

Index: usb/usbaudio.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbaudio.c,v retrieving revision 1.2

usbaudio.c +17 -3
diff -u -r1.2 usbaudio.c
@@ -36,6 +36,7 @@
 #include <sound/core.h>
 #include <sound/info.h>
 #include <sound/pcm.h>
+#include <sound/seq_device.h>
 #define SNDRV_GET_ID
 #include <sound/initval.h>
 
@@ -1234,6 +1235,7 @@
 static void usb_audio_disconnect(struct usb_device *dev, void *ptr);
 
 static struct usb_device_id usb_audio_ids [] = {
+#include "usbquirks.h"
     { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
       .bInterfaceClass = USB_CLASS_AUDIO,
       .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL },
@@ -1716,11 +1718,14 @@
 
 
 /*
- * parse audio control descriptor and create pcm streams
+ * parse audio control descriptor and create pcm/midi streams
  */
 
-static int snd_usb_create_pcm(snd_usb_audio_t *chip, int ctrlif,
-			      unsigned char *buffer, int buflen)
+static int snd_usb_create_midi_interface(snd_usb_audio_t *chip, int ifnum,
+					 const snd_usb_audio_quirk_t *quirk);
+
+static int snd_usb_create_streams(snd_usb_audio_t *chip, int ctrlif,
+				  unsigned char *buffer, int buflen)
 {
 	struct usb_device *dev = chip->dev;
 	struct usb_config_descriptor *config;
@@ -1752,6 +1757,15 @@
 			continue;
 		}
 		iface = &config->interface[j];
+		if (iface->altsetting[0].bInterfaceClass == USB_CLASS_AUDIO &&
+		    iface->altsetting[0].bInterfaceSubClass == USB_SUBCLASS_MIDI_STREAMING) {
+			if (snd_usb_create_midi_interface(chip, j, NULL) < 0) {
+				snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n", dev->devnum, ctrlif, j);
+				continue;
+			}
+			usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1);
+			continue;
+		}
 		if (iface->altsetting[0].bInterfaceClass != USB_CLASS_AUDIO ||
 		    iface->altsetting[0].bInterfaceSubClass != USB_SUBCLASS_AUDIO_STREAMING) {
 			snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n", dev->devnum, ctrlif, j,

iface->altsetting[0].bInterfaceClass);
@@ -1808,6 +1822,37 @@
return 0;
}

+static int snd_usb_create_midi_interface(snd_usb_audio_t *chip, int ifnum,
+ const snd_usb_audio_quirk_t *quirk)
+{
+#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
+ snd_seq_device_t *seq_device;
+ snd_usb_midi_t *umidi;
+ int err;
+
+ err = snd_seq_device_new(chip->card, chip->next_seq_device,
+ SNDRV_SEQ_DEV_ID_USBMIDI,
+ sizeof(snd_usb_midi_t), &seq_device);
+ if (err < 0)
+ return err;
+ chip->next_seq_device++;
+ strcpy(seq_device->name, chip->card->shortname);
+ umidi = (snd_usb_midi_t *)SNDRV_SEQ_DEVICE_ARGPTR(seq_device);
+ umidi->chip = chip;
+ umidi->ifnum = ifnum;
+ umidi->quirk = quirk;
+ umidi->seq_client = -1;
+#endif
+ return 0;
+}
+
+static inline int snd_usb_create_quirk(snd_usb_audio_t *chip, int ifnum,
+ const snd_usb_audio_quirk_t *quirk)
+{
+ /* in the future, there may be quirks for PCM devices */
+ return snd_usb_create_midi_interface(chip, ifnum, quirk);
+}
+

/*
* free the chip instance
@@ -1835,7 +1880,9 @@
/*
* create a chip instance and set its names.
*/
-static int snd_usb_audio_create(snd_card_t *card, struct usb_device *dev, snd_usb_audio_t **rchip) +static int snd_usb_audio_create(snd_card_t *card, struct usb_device *dev,
+ const snd_usb_audio_quirk_t *quirk,
+ snd_usb_audio_t **rchip)
{
snd_usb_audio_t *chip;
int err, len;
@@ -1858,18 +1905,50 @@
}

strcpy(card->driver, "USB-Audio");
- strcpy(card->shortname, "USB Audio Driver");
+
+ /* retrieve the device string as shortname */
+ if (dev->descriptor.iProduct)
+ len = usb_string(dev, dev->descriptor.iProduct,
+ card->shortname, sizeof(card->shortname));
+ else
+ len = 0;
+ if (len <= 0) {
+ if (quirk && quirk->product_name) {
+ strncpy(card->shortname, quirk->product_name, sizeof(card->shortname) - 1);
+ card->shortname[sizeof(card->shortname) - 1] = '\0';
+ } else {
+ sprintf(card->shortname, "USB Device %#04x:%#04x",
+ dev->descriptor.idVendor, dev->descriptor.idProduct);
+ }
+ }

/* retrieve the vendor and device strings as longname */
- len = usb_string(dev, 1, card->longname, sizeof(card->longname) - 1);
- if (len <= 0)
+ if (dev->descriptor.iManufacturer)
+ len = usb_string(dev, dev->descriptor.iManufacturer,
+ card->longname, sizeof(card->longname) - 1);
+ else
len = 0;
- else {
+ if (len <= 0) {
+ if (quirk && quirk->vendor_name) {
+ strncpy(card->longname, quirk->vendor_name, sizeof(card->longname) - 2);
+ card->longname[sizeof(card->longname) - 2] = '\0';
+ len = strlen(card->longname);
+ } else {
+ len = 0;
+ }
+ }
+ if (len > 0) {
card->longname[len] = ' ';
len++;
}
- card->longname[len] = 0;
- usb_string(dev, 2, card->longname + len, sizeof(card->longname) - len);
+ card->longname[len] = '\0';
+ if ((!dev->descriptor.iProduct
+ || usb_string(dev, dev->descriptor.iProduct,
+ card->longname + len, sizeof(card->longname) - len) <= 0)
+ && quirk && quirk->product_name) {
+ strncpy(card->longname + len, quirk->product_name, sizeof(card->longname) - len - 1);
+ card->longname[sizeof(card->longname) - 1] = '\0';
+ }

*rchip = chip;
return 0;
@@ -1926,12 +2005,16 @@
const struct usb_device_id *id)
{
struct usb_config_descriptor *config = dev->actconfig;
+ const snd_usb_audio_quirk_t *quirk = (const snd_usb_audio_quirk_t *)id->driver_info;
unsigned char *buffer;
unsigned int index;
int i, buflen;
snd_card_t *card;
snd_usb_audio_t *chip;

+ if (quirk && ifnum != quirk->ifnum)
+ return NULL;
+
if (usb_set_configuration(dev, config->bConfigurationValue) < 0) {
snd_printk(KERN_ERR "cannot set configuration (value 0x%x)\n", config->bConfigurationValue); return NULL;
@@ -1966,7 +2049,7 @@
snd_printk(KERN_ERR "cannot create a card instance %d\n", i); goto __error;
}
- if (snd_usb_audio_create(card, dev, &chip) < 0) {
+ if (snd_usb_audio_create(card, dev, quirk, &chip) < 0) {
snd_card_free(card);
goto __error;
}
@@ -1980,10 +2063,15 @@
}
}

- if (snd_usb_create_pcm(chip, ifnum, buffer, buflen) < 0)
- goto __error;
- if (snd_usb_create_mixer(chip, ifnum, buffer, buflen) < 0)
- goto __error;
+ if (!quirk) {
+ if (snd_usb_create_streams(chip, ifnum, buffer, buflen) < 0)
+ goto __error;
+ if (snd_usb_create_mixer(chip, ifnum, buffer, buflen) < 0)
+ goto __error;
+ } else {
+ if (snd_usb_create_quirk(chip, ifnum, quirk) < 0)
+ goto __error;
+ }

/* we are allowed to call snd_card_register() many times */ if (snd_card_register(chip->card) < 0) {
Index: usb/usbaudio.h
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbaudio.h,v retrieving revision 1.1

usbaudio.h +53 -0

78 lines not on this page · raw message

Index: usb/usbmidi.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbmidi.c,v retrieving revision 1.3

usbmidi.c +189 -646

1,146 lines not on this page · raw message

usbquirks.h new file +337 -0

337 lines not on this page · raw message

-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390

#1 lore raw

Hi,

thanks. the patch is applied now to cvs.
could you check whether it works for you?

Karsten, can you rewrite the patch for your tascam driver based on this new mechanism? if any other changes are needed, please let us know.

Takashi

-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390

#2 lore raw
Quoted 3 lines · Takashi Iwai

could you check whether it works for you?

My Evolution MK-249C works perfect! Both driver parts are loaded, only one card is listed and sound is there. Wonderful.

Thanks!
martin

-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390

#3 lore raw

At Mon, 26 Aug 2002 19:03:17 +0200,

Quoted 8 lines · Martin Langer
Quoted 3 lines · Takashi Iwai

could you check whether it works for you?

My Evolution MK-249C works perfect! Both driver parts are loaded, only one card is listed and sound is there. Wonderful.

ok, then great kudo to Clemens!

Takashi

-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390

#4 lore raw
In reply to Takashi Iwai

--- Takashi Iwai <[email protected]> schrieb: > Hi,

Quoted 11 lines

thanks. the patch is applied now to cvs.
could you check whether it works for you?

Karsten, can you rewrite the patch for your tascam driver based on
this new mechanism? if any other changes are needed, please let us
know.

no changes needed. works well as it is now. changed tascam driver available via email. Tascam did not answer yet our calls to allow us the use of their firmware.

proposal for autoloading snd-usb-midi from
snd-usb-audio if needed:

	request_module( "snd-usb-midi");

this way the tascam driver releaves the user from
taking care that snd-usb-midi is present.

Karsten

__________________________________________________________________

Gesendet von Yahoo! Mail - http://mail.yahoo.de
Möchten Sie mit einem Gruß antworten? http://grusskarten.yahoo.de

-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390