Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License as published by |
| 4 | * the Free Software Foundation; either version 2 of the License, or |
| 5 | * (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 15 | */ |
| 16 | |
| 17 | #include <linux/init.h> |
Stephen Rothwell | 36db045 | 2010-03-29 16:02:50 +1100 | [diff] [blame] | 18 | #include <linux/slab.h> |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 19 | #include <linux/usb.h> |
| 20 | #include <linux/usb/audio.h> |
| 21 | |
| 22 | #include <sound/core.h> |
| 23 | #include <sound/info.h> |
| 24 | #include <sound/pcm.h> |
| 25 | |
| 26 | #include "usbaudio.h" |
| 27 | #include "card.h" |
Daniel Mack | f0b5e63 | 2010-03-11 21:13:23 +0100 | [diff] [blame] | 28 | #include "mixer.h" |
Daniel Mack | 7b1eda2 | 2010-03-11 21:13:22 +0100 | [diff] [blame] | 29 | #include "mixer_quirks.h" |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 30 | #include "midi.h" |
| 31 | #include "quirks.h" |
| 32 | #include "helper.h" |
| 33 | #include "endpoint.h" |
| 34 | #include "pcm.h" |
Daniel Mack | 3d8d4dc | 2010-06-16 17:57:31 +0200 | [diff] [blame] | 35 | #include "clock.h" |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * handle the quirks for the contained interfaces |
| 39 | */ |
| 40 | static int create_composite_quirk(struct snd_usb_audio *chip, |
| 41 | struct usb_interface *iface, |
| 42 | struct usb_driver *driver, |
| 43 | const struct snd_usb_audio_quirk *quirk) |
| 44 | { |
| 45 | int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber; |
| 46 | int err; |
| 47 | |
| 48 | for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) { |
| 49 | iface = usb_ifnum_to_if(chip->dev, quirk->ifnum); |
| 50 | if (!iface) |
| 51 | continue; |
| 52 | if (quirk->ifnum != probed_ifnum && |
| 53 | usb_interface_claimed(iface)) |
| 54 | continue; |
| 55 | err = snd_usb_create_quirk(chip, iface, driver, quirk); |
| 56 | if (err < 0) |
| 57 | return err; |
| 58 | if (quirk->ifnum != probed_ifnum) |
| 59 | usb_driver_claim_interface(driver, iface, (void *)-1L); |
| 60 | } |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int ignore_interface_quirk(struct snd_usb_audio *chip, |
| 65 | struct usb_interface *iface, |
| 66 | struct usb_driver *driver, |
| 67 | const struct snd_usb_audio_quirk *quirk) |
| 68 | { |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /* |
| 74 | * Allow alignment on audio sub-slot (channel samples) rather than |
| 75 | * on audio slots (audio frames) |
| 76 | */ |
| 77 | static int create_align_transfer_quirk(struct snd_usb_audio *chip, |
| 78 | struct usb_interface *iface, |
| 79 | struct usb_driver *driver, |
| 80 | const struct snd_usb_audio_quirk *quirk) |
| 81 | { |
| 82 | chip->txfr_quirk = 1; |
| 83 | return 1; /* Continue with creating streams and mixer */ |
| 84 | } |
| 85 | |
| 86 | static int create_any_midi_quirk(struct snd_usb_audio *chip, |
| 87 | struct usb_interface *intf, |
| 88 | struct usb_driver *driver, |
| 89 | const struct snd_usb_audio_quirk *quirk) |
| 90 | { |
| 91 | return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk); |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * create a stream for an interface with proper descriptors |
| 96 | */ |
| 97 | static int create_standard_audio_quirk(struct snd_usb_audio *chip, |
| 98 | struct usb_interface *iface, |
| 99 | struct usb_driver *driver, |
| 100 | const struct snd_usb_audio_quirk *quirk) |
| 101 | { |
| 102 | struct usb_host_interface *alts; |
| 103 | struct usb_interface_descriptor *altsd; |
| 104 | int err; |
| 105 | |
| 106 | alts = &iface->altsetting[0]; |
| 107 | altsd = get_iface_desc(alts); |
| 108 | err = snd_usb_parse_audio_endpoints(chip, altsd->bInterfaceNumber); |
| 109 | if (err < 0) { |
| 110 | snd_printk(KERN_ERR "cannot setup if %d: error %d\n", |
| 111 | altsd->bInterfaceNumber, err); |
| 112 | return err; |
| 113 | } |
| 114 | /* reset the current interface */ |
| 115 | usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0); |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * create a stream for an endpoint/altsetting without proper descriptors |
| 121 | */ |
| 122 | static int create_fixed_stream_quirk(struct snd_usb_audio *chip, |
| 123 | struct usb_interface *iface, |
| 124 | struct usb_driver *driver, |
| 125 | const struct snd_usb_audio_quirk *quirk) |
| 126 | { |
| 127 | struct audioformat *fp; |
| 128 | struct usb_host_interface *alts; |
| 129 | int stream, err; |
| 130 | unsigned *rate_table = NULL; |
| 131 | |
| 132 | fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL); |
| 133 | if (! fp) { |
| 134 | snd_printk(KERN_ERR "cannot memdup\n"); |
| 135 | return -ENOMEM; |
| 136 | } |
| 137 | if (fp->nr_rates > 0) { |
| 138 | rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL); |
| 139 | if (!rate_table) { |
| 140 | kfree(fp); |
| 141 | return -ENOMEM; |
| 142 | } |
| 143 | memcpy(rate_table, fp->rate_table, sizeof(int) * fp->nr_rates); |
| 144 | fp->rate_table = rate_table; |
| 145 | } |
| 146 | |
| 147 | stream = (fp->endpoint & USB_DIR_IN) |
| 148 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; |
| 149 | err = snd_usb_add_audio_endpoint(chip, stream, fp); |
| 150 | if (err < 0) { |
| 151 | kfree(fp); |
| 152 | kfree(rate_table); |
| 153 | return err; |
| 154 | } |
| 155 | if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber || |
| 156 | fp->altset_idx >= iface->num_altsetting) { |
| 157 | kfree(fp); |
| 158 | kfree(rate_table); |
| 159 | return -EINVAL; |
| 160 | } |
| 161 | alts = &iface->altsetting[fp->altset_idx]; |
| 162 | fp->datainterval = snd_usb_parse_datainterval(chip, alts); |
| 163 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); |
| 164 | usb_set_interface(chip->dev, fp->iface, 0); |
Daniel Mack | 767d75a | 2010-03-04 19:46:17 +0100 | [diff] [blame] | 165 | snd_usb_init_pitch(chip, fp->iface, alts, fp); |
| 166 | snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max); |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface. |
| 172 | * The only way to detect the sample rate is by looking at wMaxPacketSize. |
| 173 | */ |
| 174 | static int create_uaxx_quirk(struct snd_usb_audio *chip, |
| 175 | struct usb_interface *iface, |
| 176 | struct usb_driver *driver, |
| 177 | const struct snd_usb_audio_quirk *quirk) |
| 178 | { |
| 179 | static const struct audioformat ua_format = { |
Clemens Ladisch | 015eb0b | 2010-03-04 19:46:15 +0100 | [diff] [blame] | 180 | .formats = SNDRV_PCM_FMTBIT_S24_3LE, |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 181 | .channels = 2, |
| 182 | .fmt_type = UAC_FORMAT_TYPE_I, |
| 183 | .altsetting = 1, |
| 184 | .altset_idx = 1, |
| 185 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 186 | }; |
| 187 | struct usb_host_interface *alts; |
| 188 | struct usb_interface_descriptor *altsd; |
| 189 | struct audioformat *fp; |
| 190 | int stream, err; |
| 191 | |
| 192 | /* both PCM and MIDI interfaces have 2 or more altsettings */ |
| 193 | if (iface->num_altsetting < 2) |
| 194 | return -ENXIO; |
| 195 | alts = &iface->altsetting[1]; |
| 196 | altsd = get_iface_desc(alts); |
| 197 | |
| 198 | if (altsd->bNumEndpoints == 2) { |
| 199 | static const struct snd_usb_midi_endpoint_info ua700_ep = { |
| 200 | .out_cables = 0x0003, |
| 201 | .in_cables = 0x0003 |
| 202 | }; |
| 203 | static const struct snd_usb_audio_quirk ua700_quirk = { |
| 204 | .type = QUIRK_MIDI_FIXED_ENDPOINT, |
| 205 | .data = &ua700_ep |
| 206 | }; |
| 207 | static const struct snd_usb_midi_endpoint_info uaxx_ep = { |
| 208 | .out_cables = 0x0001, |
| 209 | .in_cables = 0x0001 |
| 210 | }; |
| 211 | static const struct snd_usb_audio_quirk uaxx_quirk = { |
| 212 | .type = QUIRK_MIDI_FIXED_ENDPOINT, |
| 213 | .data = &uaxx_ep |
| 214 | }; |
| 215 | const struct snd_usb_audio_quirk *quirk = |
| 216 | chip->usb_id == USB_ID(0x0582, 0x002b) |
| 217 | ? &ua700_quirk : &uaxx_quirk; |
| 218 | return snd_usbmidi_create(chip->card, iface, |
| 219 | &chip->midi_list, quirk); |
| 220 | } |
| 221 | |
| 222 | if (altsd->bNumEndpoints != 1) |
| 223 | return -ENXIO; |
| 224 | |
| 225 | fp = kmalloc(sizeof(*fp), GFP_KERNEL); |
| 226 | if (!fp) |
| 227 | return -ENOMEM; |
| 228 | memcpy(fp, &ua_format, sizeof(*fp)); |
| 229 | |
| 230 | fp->iface = altsd->bInterfaceNumber; |
| 231 | fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; |
| 232 | fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; |
| 233 | fp->datainterval = 0; |
| 234 | fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); |
| 235 | |
| 236 | switch (fp->maxpacksize) { |
| 237 | case 0x120: |
| 238 | fp->rate_max = fp->rate_min = 44100; |
| 239 | break; |
| 240 | case 0x138: |
| 241 | case 0x140: |
| 242 | fp->rate_max = fp->rate_min = 48000; |
| 243 | break; |
| 244 | case 0x258: |
| 245 | case 0x260: |
| 246 | fp->rate_max = fp->rate_min = 96000; |
| 247 | break; |
| 248 | default: |
| 249 | snd_printk(KERN_ERR "unknown sample rate\n"); |
| 250 | kfree(fp); |
| 251 | return -ENXIO; |
| 252 | } |
| 253 | |
| 254 | stream = (fp->endpoint & USB_DIR_IN) |
| 255 | ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; |
| 256 | err = snd_usb_add_audio_endpoint(chip, stream, fp); |
| 257 | if (err < 0) { |
| 258 | kfree(fp); |
| 259 | return err; |
| 260 | } |
| 261 | usb_set_interface(chip->dev, fp->iface, 0); |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * audio-interface quirks |
| 267 | * |
| 268 | * returns zero if no standard audio/MIDI parsing is needed. |
| 269 | * returns a postive value if standard audio/midi interfaces are parsed |
| 270 | * after this. |
| 271 | * returns a negative value at error. |
| 272 | */ |
| 273 | int snd_usb_create_quirk(struct snd_usb_audio *chip, |
| 274 | struct usb_interface *iface, |
| 275 | struct usb_driver *driver, |
| 276 | const struct snd_usb_audio_quirk *quirk) |
| 277 | { |
| 278 | typedef int (*quirk_func_t)(struct snd_usb_audio *, |
| 279 | struct usb_interface *, |
| 280 | struct usb_driver *, |
| 281 | const struct snd_usb_audio_quirk *); |
| 282 | static const quirk_func_t quirk_funcs[] = { |
| 283 | [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk, |
| 284 | [QUIRK_COMPOSITE] = create_composite_quirk, |
| 285 | [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk, |
| 286 | [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk, |
| 287 | [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk, |
| 288 | [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk, |
| 289 | [QUIRK_MIDI_NOVATION] = create_any_midi_quirk, |
Clemens Ladisch | c7f5721 | 2010-10-22 18:20:48 +0200 | [diff] [blame] | 290 | [QUIRK_MIDI_RAW_BYTES] = create_any_midi_quirk, |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 291 | [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, |
| 292 | [QUIRK_MIDI_CME] = create_any_midi_quirk, |
Krzysztof Foltman | 4434ade | 2010-05-20 20:31:10 +0100 | [diff] [blame] | 293 | [QUIRK_MIDI_AKAI] = create_any_midi_quirk, |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 294 | [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, |
| 295 | [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, |
| 296 | [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, |
| 297 | [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk |
| 298 | }; |
| 299 | |
| 300 | if (quirk->type < QUIRK_TYPE_COUNT) { |
| 301 | return quirk_funcs[quirk->type](chip, iface, driver, quirk); |
| 302 | } else { |
| 303 | snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); |
| 304 | return -ENXIO; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * boot quirks |
| 310 | */ |
| 311 | |
| 312 | #define EXTIGY_FIRMWARE_SIZE_OLD 794 |
| 313 | #define EXTIGY_FIRMWARE_SIZE_NEW 483 |
| 314 | |
| 315 | static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf) |
| 316 | { |
| 317 | struct usb_host_config *config = dev->actconfig; |
| 318 | int err; |
| 319 | |
| 320 | if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD || |
| 321 | le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) { |
| 322 | snd_printdd("sending Extigy boot sequence...\n"); |
| 323 | /* Send message to force it to reconnect with full interface. */ |
| 324 | err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0), |
| 325 | 0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000); |
| 326 | if (err < 0) snd_printdd("error sending boot message: %d\n", err); |
| 327 | err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, |
| 328 | &dev->descriptor, sizeof(dev->descriptor)); |
| 329 | config = dev->actconfig; |
| 330 | if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err); |
| 331 | err = usb_reset_configuration(dev); |
| 332 | if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err); |
| 333 | snd_printdd("extigy_boot: new boot length = %d\n", |
| 334 | le16_to_cpu(get_cfg_desc(config)->wTotalLength)); |
| 335 | return -ENODEV; /* quit this anyway */ |
| 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev) |
| 341 | { |
| 342 | u8 buf = 1; |
| 343 | |
| 344 | snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, |
| 345 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 346 | 0, 0, &buf, 1, 1000); |
| 347 | if (buf == 0) { |
| 348 | snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29, |
| 349 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 350 | 1, 2000, NULL, 0, 1000); |
| 351 | return -ENODEV; |
| 352 | } |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely |
| 358 | * documented in the device's data sheet. |
| 359 | */ |
| 360 | static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value) |
| 361 | { |
| 362 | u8 buf[4]; |
| 363 | buf[0] = 0x20; |
| 364 | buf[1] = value & 0xff; |
| 365 | buf[2] = (value >> 8) & 0xff; |
| 366 | buf[3] = reg; |
| 367 | return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION, |
| 368 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, |
| 369 | 0, 0, &buf, 4, 1000); |
| 370 | } |
| 371 | |
| 372 | static int snd_usb_cm106_boot_quirk(struct usb_device *dev) |
| 373 | { |
| 374 | /* |
| 375 | * Enable line-out driver mode, set headphone source to front |
| 376 | * channels, enable stereo mic. |
| 377 | */ |
| 378 | return snd_usb_cm106_write_int_reg(dev, 2, 0x8004); |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * C-Media CM6206 is based on CM106 with two additional |
| 383 | * registers that are not documented in the data sheet. |
| 384 | * Values here are chosen based on sniffing USB traffic |
| 385 | * under Windows. |
| 386 | */ |
| 387 | static int snd_usb_cm6206_boot_quirk(struct usb_device *dev) |
| 388 | { |
| 389 | int err, reg; |
| 390 | int val[] = {0x200c, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000}; |
| 391 | |
| 392 | for (reg = 0; reg < ARRAY_SIZE(val); reg++) { |
| 393 | err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]); |
| 394 | if (err < 0) |
| 395 | return err; |
| 396 | } |
| 397 | |
| 398 | return err; |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * This call will put the synth in "USB send" mode, i.e it will send MIDI |
| 403 | * messages through USB (this is disabled at startup). The synth will |
| 404 | * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB |
| 405 | * sign on its LCD. Values here are chosen based on sniffing USB traffic |
| 406 | * under Windows. |
| 407 | */ |
| 408 | static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev) |
| 409 | { |
| 410 | int err, actual_length; |
| 411 | |
| 412 | /* "midi send" enable */ |
| 413 | static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 }; |
| 414 | |
| 415 | void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL); |
| 416 | if (!buf) |
| 417 | return -ENOMEM; |
| 418 | err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf, |
| 419 | ARRAY_SIZE(seq), &actual_length, 1000); |
| 420 | kfree(buf); |
| 421 | if (err < 0) |
| 422 | return err; |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | /* |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 428 | * Some sound cards from Native Instruments are in fact compliant to the USB |
| 429 | * audio standard of version 2 and other approved USB standards, even though |
| 430 | * they come up as vendor-specific device when first connected. |
| 431 | * |
| 432 | * However, they can be told to come up with a new set of descriptors |
| 433 | * upon their next enumeration, and the interfaces announced by the new |
| 434 | * descriptors will then be handled by the kernel's class drivers. As the |
| 435 | * product ID will also change, no further checks are required. |
| 436 | */ |
| 437 | |
| 438 | static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev) |
| 439 | { |
| 440 | int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), |
| 441 | 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 442 | cpu_to_le16(1), 0, NULL, 0, 1000); |
| 443 | |
| 444 | if (ret < 0) |
| 445 | return ret; |
| 446 | |
| 447 | usb_reset_device(dev); |
| 448 | |
| 449 | /* return -EAGAIN, so the creation of an audio interface for this |
| 450 | * temporary device is aborted. The device will reconnect with a |
| 451 | * new product ID */ |
| 452 | return -EAGAIN; |
| 453 | } |
| 454 | |
| 455 | /* |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 456 | * Setup quirks |
| 457 | */ |
| 458 | #define AUDIOPHILE_SET 0x01 /* if set, parse device_setup */ |
| 459 | #define AUDIOPHILE_SET_DTS 0x02 /* if set, enable DTS Digital Output */ |
| 460 | #define AUDIOPHILE_SET_96K 0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */ |
| 461 | #define AUDIOPHILE_SET_24B 0x08 /* 24bits sample if set, 16bits otherwise */ |
| 462 | #define AUDIOPHILE_SET_DI 0x10 /* if set, enable Digital Input */ |
| 463 | #define AUDIOPHILE_SET_MASK 0x1F /* bit mask for setup value */ |
| 464 | #define AUDIOPHILE_SET_24B_48K_DI 0x19 /* value for 24bits+48KHz+Digital Input */ |
| 465 | #define AUDIOPHILE_SET_24B_48K_NOTDI 0x09 /* value for 24bits+48KHz+No Digital Input */ |
| 466 | #define AUDIOPHILE_SET_16B_48K_DI 0x11 /* value for 16bits+48KHz+Digital Input */ |
| 467 | #define AUDIOPHILE_SET_16B_48K_NOTDI 0x01 /* value for 16bits+48KHz+No Digital Input */ |
| 468 | |
| 469 | static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip, |
| 470 | int iface, |
| 471 | int altno) |
| 472 | { |
| 473 | /* Reset ALL ifaces to 0 altsetting. |
| 474 | * Call it for every possible altsetting of every interface. |
| 475 | */ |
| 476 | usb_set_interface(chip->dev, iface, 0); |
| 477 | |
| 478 | if (chip->setup & AUDIOPHILE_SET) { |
| 479 | if ((chip->setup & AUDIOPHILE_SET_DTS) |
| 480 | && altno != 6) |
| 481 | return 1; /* skip this altsetting */ |
| 482 | if ((chip->setup & AUDIOPHILE_SET_96K) |
| 483 | && altno != 1) |
| 484 | return 1; /* skip this altsetting */ |
| 485 | if ((chip->setup & AUDIOPHILE_SET_MASK) == |
| 486 | AUDIOPHILE_SET_24B_48K_DI && altno != 2) |
| 487 | return 1; /* skip this altsetting */ |
| 488 | if ((chip->setup & AUDIOPHILE_SET_MASK) == |
| 489 | AUDIOPHILE_SET_24B_48K_NOTDI && altno != 3) |
| 490 | return 1; /* skip this altsetting */ |
| 491 | if ((chip->setup & AUDIOPHILE_SET_MASK) == |
| 492 | AUDIOPHILE_SET_16B_48K_DI && altno != 4) |
| 493 | return 1; /* skip this altsetting */ |
| 494 | if ((chip->setup & AUDIOPHILE_SET_MASK) == |
| 495 | AUDIOPHILE_SET_16B_48K_NOTDI && altno != 5) |
| 496 | return 1; /* skip this altsetting */ |
| 497 | } |
| 498 | |
| 499 | return 0; /* keep this altsetting */ |
| 500 | } |
| 501 | |
| 502 | int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip, |
| 503 | int iface, |
| 504 | int altno) |
| 505 | { |
| 506 | /* audiophile usb: skip altsets incompatible with device_setup */ |
| 507 | if (chip->usb_id == USB_ID(0x0763, 0x2003)) |
| 508 | return audiophile_skip_setting_quirk(chip, iface, altno); |
| 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | int snd_usb_apply_boot_quirk(struct usb_device *dev, |
| 514 | struct usb_interface *intf, |
| 515 | const struct snd_usb_audio_quirk *quirk) |
| 516 | { |
| 517 | u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), |
| 518 | le16_to_cpu(dev->descriptor.idProduct)); |
| 519 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 520 | switch (id) { |
| 521 | case USB_ID(0x041e, 0x3000): |
| 522 | /* SB Extigy needs special boot-up sequence */ |
| 523 | /* if more models come, this will go to the quirk list. */ |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 524 | return snd_usb_extigy_boot_quirk(dev, intf); |
| 525 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 526 | case USB_ID(0x041e, 0x3020): |
| 527 | /* SB Audigy 2 NX needs its own boot-up magic, too */ |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 528 | return snd_usb_audigy2nx_boot_quirk(dev); |
| 529 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 530 | case USB_ID(0x10f5, 0x0200): |
| 531 | /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */ |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 532 | return snd_usb_cm106_boot_quirk(dev); |
| 533 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 534 | case USB_ID(0x0d8c, 0x0102): |
| 535 | /* C-Media CM6206 / CM106-Like Sound Device */ |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 536 | return snd_usb_cm6206_boot_quirk(dev); |
| 537 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 538 | case USB_ID(0x133e, 0x0815): |
| 539 | /* Access Music VirusTI Desktop */ |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 540 | return snd_usb_accessmusic_boot_quirk(dev); |
| 541 | |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 542 | case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */ |
| 543 | case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */ |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 544 | return snd_usb_nativeinstruments_boot_quirk(dev); |
Daniel Mack | 3347b26 | 2011-02-11 11:34:12 +0000 | [diff] [blame] | 545 | } |
Daniel Mack | 54a8c50 | 2011-02-11 11:08:06 +0000 | [diff] [blame] | 546 | |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * check if the device uses big-endian samples |
| 552 | */ |
| 553 | int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp) |
| 554 | { |
| 555 | switch (chip->usb_id) { |
| 556 | case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */ |
| 557 | if (fp->endpoint & USB_DIR_IN) |
| 558 | return 1; |
| 559 | break; |
| 560 | case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */ |
| 561 | if (chip->setup == 0x00 || |
| 562 | fp->altsetting==1 || fp->altsetting==2 || fp->altsetting==3) |
| 563 | return 1; |
| 564 | } |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | /* |
Joseph Teichman | 1cdfa9f | 2011-02-08 01:22:36 -0500 | [diff] [blame] | 569 | * For E-Mu 0404USB/0202USB/TrackerPre/0204 sample rate should be set for device, |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 570 | * not for interface. |
| 571 | */ |
| 572 | |
| 573 | enum { |
| 574 | EMU_QUIRK_SR_44100HZ = 0, |
| 575 | EMU_QUIRK_SR_48000HZ, |
| 576 | EMU_QUIRK_SR_88200HZ, |
| 577 | EMU_QUIRK_SR_96000HZ, |
| 578 | EMU_QUIRK_SR_176400HZ, |
| 579 | EMU_QUIRK_SR_192000HZ |
| 580 | }; |
| 581 | |
| 582 | static void set_format_emu_quirk(struct snd_usb_substream *subs, |
| 583 | struct audioformat *fmt) |
| 584 | { |
| 585 | unsigned char emu_samplerate_id = 0; |
| 586 | |
| 587 | /* When capture is active |
| 588 | * sample rate shouldn't be changed |
| 589 | * by playback substream |
| 590 | */ |
| 591 | if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) { |
| 592 | if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1) |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | switch (fmt->rate_min) { |
| 597 | case 48000: |
| 598 | emu_samplerate_id = EMU_QUIRK_SR_48000HZ; |
| 599 | break; |
| 600 | case 88200: |
| 601 | emu_samplerate_id = EMU_QUIRK_SR_88200HZ; |
| 602 | break; |
| 603 | case 96000: |
| 604 | emu_samplerate_id = EMU_QUIRK_SR_96000HZ; |
| 605 | break; |
| 606 | case 176400: |
| 607 | emu_samplerate_id = EMU_QUIRK_SR_176400HZ; |
| 608 | break; |
| 609 | case 192000: |
| 610 | emu_samplerate_id = EMU_QUIRK_SR_192000HZ; |
| 611 | break; |
| 612 | default: |
| 613 | emu_samplerate_id = EMU_QUIRK_SR_44100HZ; |
| 614 | break; |
| 615 | } |
| 616 | snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id); |
| 617 | } |
| 618 | |
| 619 | void snd_usb_set_format_quirk(struct snd_usb_substream *subs, |
| 620 | struct audioformat *fmt) |
| 621 | { |
| 622 | switch (subs->stream->chip->usb_id) { |
| 623 | case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */ |
| 624 | case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */ |
| 625 | case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */ |
Joseph Teichman | 1cdfa9f | 2011-02-08 01:22:36 -0500 | [diff] [blame] | 626 | case USB_ID(0x041e, 0x3f19): /* E-Mu 0204 USB */ |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 627 | set_format_emu_quirk(subs, fmt); |
| 628 | break; |
| 629 | } |
| 630 | } |
| 631 | |