Hi all,
I have generated a patch against sound-2.6 git for the Digidesign Mbox 2. I did a git commit -a and then git diff HEAD^1 to generate this patch. Unfortunately I am sending this email from gmail, so I'm not sure about line formatting, yikes.
Damien
diff --git a/sound/usb/midi.c b/sound/usb/midi.c index 25bce7e..5dace7e 100644 --- a/sound/usb/midi.c +++ b/sound/usb/midi.c @@ -2122,6 +2122,18 @@ int snd_usbmidi_create(struct snd_card *card, umidi->usb_protocol_ops = &snd_usbmidi_novation_ops; err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints); break; + case QUIRK_MIDI_MBOX2: + /* Digidesign Mbox 2 uses MIDIMAN MIDI protocol */ + umidi->usb_protocol_ops = &snd_usbmidi_midiman_ops; + /* + * We have to make sure that the USB core looks + * again at interface 6 by calling usb_set_interface() on it. + */ + usb_set_interface(umidi->dev, 6, 0); + memcpy(&endpoints[0], quirk->data, + sizeof(struct snd_usb_midi_endpoint_info)); + err = 0; + break; case QUIRK_MIDI_RAW_BYTES: umidi->usb_protocol_ops = &snd_usbmidi_raw_ops; /* diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index ad7079d..f0b6520 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h @@ -2477,6 +2477,60 @@ YAMAHA_DEVICE(0x7010, "UB99"), } },
+/* DIGIDESIGN MBOX 2 */ +{ + /* Damien Zammit damien.zammit@gmail.com */ + + USB_DEVICE(0x0dba, 0x3000), + .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { + .vendor_name = "Digidesign", + .product_name = "Mbox 2", + .ifnum = QUIRK_ANY_INTERFACE, + .type = QUIRK_COMPOSITE, + .data = (const struct snd_usb_audio_quirk[]) { + { + .ifnum = 0, + .type = QUIRK_IGNORE_INTERFACE + }, + { + .ifnum = 1, + .type = QUIRK_AUDIO_STANDARD_INTERFACE + }, + { + .ifnum = 2, + .type = QUIRK_AUDIO_STANDARD_INTERFACE + }, + { + .ifnum = 3, + .type = QUIRK_AUDIO_STANDARD_INTERFACE + }, + { + .ifnum = 4, + .type = QUIRK_AUDIO_STANDARD_INTERFACE + }, + { + .ifnum = 5, + .type = QUIRK_AUDIO_STANDARD_INTERFACE + }, + { + .ifnum = 6, + .type = QUIRK_MIDI_MBOX2, + .data = & (const struct snd_usb_midi_endpoint_info) { + .out_ep = 0x02, + .out_cables = 0x0001, + .in_ep = 0x81, + .in_interval = 0x01, + .in_cables = 0x0001 + } + + }, + { + .ifnum = -1 + } + } + } +}, + { /* * Some USB MIDI devices don't have an audio control interface, diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index cf8bf08..d66a638 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -287,6 +287,7 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip, [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk, [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk, [QUIRK_MIDI_NOVATION] = create_any_midi_quirk, + [QUIRK_MIDI_MBOX2] = create_any_midi_quirk, [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk, [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, [QUIRK_MIDI_CME] = create_any_midi_quirk, @@ -479,6 +480,9 @@ int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip, if (chip->usb_id == USB_ID(0x0763, 0x2003)) return audiophile_skip_setting_quirk(chip, iface, altno);
+ if (chip->usb_id == USB_ID(0x0dba, 0x3000)) + return mbox2_skip_setting_quirk(chip, iface, altno); + return 0; }
@@ -510,6 +514,10 @@ int snd_usb_apply_boot_quirk(struct usb_device *dev, if (id == USB_ID(0x133e, 0x0815)) return snd_usb_accessmusic_boot_quirk(dev);
+ /* Digidesign Mbox 2 */ + if (id == USB_ID(0x0dba, 0x3000)) + return snd_usb_mbox2_boot_quirk(dev); + return 0; }
@@ -527,6 +535,9 @@ int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat if (chip->setup == 0x00 || fp->altsetting==1 || fp->altsetting==2 || fp->altsetting==3) return 1; + break; + case USB_ID(0x0dba, 0x3000): /* Digidesign Mbox 2 */ + return 1; } return 0; } @@ -594,3 +605,170 @@ void snd_usb_set_format_quirk(struct snd_usb_substream *subs, } }
+#define MBOX2_FIRMWARE_SIZE 646 +#define MBOX2_BOOT_LOADING 0x01 /* Hard coded into the device */ +#define MBOX2_BOOT_READY 0x02 /* Hard coded into the device */ + +static int snd_usb_mbox2_boot_quirk(struct usb_device *dev) +{ + struct usb_host_config *config = dev->actconfig; + int err; + u8 enablemagic[3]; + u8 bootresponse; + int fwsize; + + if ((fwsize = le16_to_cpu(get_cfg_desc(config)->wTotalLength)) == MBOX2_FIRMWARE_SIZE) { + snd_printdd("Sending Digidesign Mbox 2 boot sequence...\n"); + + /* From USB Snoop, + * + * SetupPacket = RT RQ VHVL INDX SIZE + * RT = 0xRT Request Type + * RQ = 0xRQ Request + * VHVL = 0xVLVH Value in reverse byte order + * INDX = 0xDXIN Index in reverse byte order + * SIZE = 0xZESI Size in reverse byte order + * + * Magic boot code setup packet: c0 85 01 00 00 00 12 00 + * RQ RT VLVH DXIN ZESI + * becomes 0x85, 0xc0, 0x0001, 0x0000, &RETURNDATA, 0x0012, TIMEOUT + * for snd_usb_ctl_msg() + */ + +mbox2_reboot: + snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), + 0x85, 0xc0, 0x0001, 0x0000, &bootresponse, 0x0012, 1000); + + if (bootresponse == MBOX2_BOOT_LOADING) { + snd_printdd("device not ready, resending boot sequence...\n"); + goto mbox2_reboot; + } + + if (bootresponse == MBOX2_BOOT_READY) { + snd_printdd("device initialised!\n"); + + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, + &dev->descriptor, sizeof(dev->descriptor)); + config = dev->actconfig; + if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err); + err = usb_reset_configuration(dev); + if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err); + snd_printdd("mbox2_boot: new boot length = %d\n", + le16_to_cpu(get_cfg_desc(config)->wTotalLength)); + + /* Successful boot, (should reset all altsettings to 0 like windows does, but works without it) + * but now we will try sending capture/playback enable magic + * + * 80 bb 00 = 24bit mode - S24_3BE + * 44 ac 00 = 16bit mode? + * + */ + //enablemagic[0]=0x44; + //enablemagic[1]=0xac; + //enablemagic[2]=0x00; + + /* We want 48 kHz mode for now */ + enablemagic[0]=0x80; + enablemagic[1]=0xbb; + enablemagic[2]=0x00; + + /* Send the magic! */ + snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), + 0x01, 0x22, 0x0100, 0x0085, &enablemagic, 0x0003, 1000); + + snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), + 0x81, 0xa2, 0x0100, 0x0085, &enablemagic, 0x0003, 1000); + + snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), + 0x81, 0xa2, 0x0100, 0x0086, &enablemagic, 0x0003, 1000); + + snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), + 0x81, 0xa2, 0x0100, 0x0003, &enablemagic, 0x0003, 1000); + + return 0; /* Succesful boot */ + } + + snd_printdd("unknown bootresponse, ignoring device: %d\n",bootresponse); + return -ENODEV; + } + snd_printk("Invalid firmware size: %d\n",fwsize); + return -ENODEV; +} + +#define MBOX2_SET_48K_SPDIF 0 +#define MBOX2_SET_44K_SPDIF 1 +#define MBOX2_SET_48K_ANALOG 2 +#define MBOX2_SET_44K_ANALOG 3 + +static int mbox2_skip_setting_quirk(struct snd_usb_audio *chip, + int iface, int altno) +{ + u8 srate[3]; + /* Reset ifaces 2-5 to 0 altsetting. */ + usb_set_interface(chip->dev, iface, 0); + + if (chip->setup == MBOX2_SET_48K_SPDIF || + chip->setup == MBOX2_SET_48K_ANALOG) { + //setup 48k + srate[0]=0x80; + srate[1]=0xbb; + srate[2]=0x00; + + /* Send the magic! */ + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x01, 0x22, 0x0100, 0x0085, &srate, 0x0003, 1000); + + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003, 1000); + + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003, 1000); + + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003, 1000); + snd_printk(KERN_INFO "Digidesign Mbox 2: 24 Bit 48000Hz"); + if (chip->setup == MBOX2_SET_48K_SPDIF) { + //setup spdif + snd_printk(KERN_INFO ", SPDIF\n"); + if (altno != 2) return 1; + } else { + //setup analog + snd_printk(KERN_INFO ", ANALOGUE\n"); + if (altno != 3) return 1; + } + } else { + //setup 44k + srate[0]=0x44; + srate[1]=0xac; + srate[2]=0x00; + + /* Send the magic! */ + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x01, 0x22, 0x0100, 0x0085, &srate, 0x0003, 1000); + + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x81, 0xa2, 0x0100, 0x0085, &srate, 0x0003, 1000); + + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x81, 0xa2, 0x0100, 0x0086, &srate, 0x0003, 1000); + + snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), + 0x81, 0xa2, 0x0100, 0x0003, &srate, 0x0003, 1000); + + snd_printk(KERN_INFO "Digidesign Mbox 2: 24 Bit 44100Hz"); + if (chip->setup == MBOX2_SET_44K_SPDIF || + chip->setup == MBOX2_SET_44K_ANALOG) { + + //setup spdif + snd_printk(KERN_INFO ", SPDIF\n"); + if (altno != 2) return 1; + } else { + //setup analog + snd_printk(KERN_INFO ", ANALOGUE\n"); + if (altno != 3) return 1; + } + } + return 0; +} + + diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h index 03e5e94..13fd3ad 100644 --- a/sound/usb/quirks.h +++ b/sound/usb/quirks.h @@ -20,4 +20,9 @@ void snd_usb_set_format_quirk(struct snd_usb_substream *subs, int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp);
+static int mbox2_skip_setting_quirk(struct snd_usb_audio *chip, + int iface, int altno); + +static int snd_usb_mbox2_boot_quirk(struct usb_device *dev); + #endif /* __USBAUDIO_QUIRKS_H */ diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index db3eb21..128c3f4 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -70,6 +70,7 @@ enum quirk_type { QUIRK_MIDI_YAMAHA, QUIRK_MIDI_MIDIMAN, QUIRK_MIDI_NOVATION, + QUIRK_MIDI_MBOX2, QUIRK_MIDI_RAW_BYTES, QUIRK_MIDI_EMAGIC, QUIRK_MIDI_CME,
On Tue, Nov 30, 2010 at 1:50 AM, Takashi Iwai tiwai@suse.de wrote:
At Tue, 30 Nov 2010 00:03:26 +1100, Damien Zammit wrote:
Hi Daniel,
I am confused by the git repository of alsa. There seems to be two copies of it, one in alsa-kernel and one in alsa-driver. alsa-driver seems to "patch" the alsa-kernel and then build it. I have taken one of the latest snapshots of alsa-driver and modified the alsa-kernel directory and it now compiles and the device works. What do I generate the patch against?
You can use sound git repo below. git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git
Base on topic/misc branch or master branch.
Takashi