Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 1537
b: refs/heads/master
c: 27d10f5
h: refs/heads/master
i:
  1535: 4587caf
v: v3
  • Loading branch information
Clemens Ladisch authored and Jaroslav Kysela committed May 29, 2005
1 parent b92d297 commit 50fc2dc
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 146 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b259b10c420a59a2fdbcf5a3498253ebcbdffa1e
refs/heads/master: 27d10f5664c7650af3b2ffadfefaf19b36dc7bd8
104 changes: 50 additions & 54 deletions trunk/sound/usb/usbaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,17 +2184,15 @@ static int add_audio_endpoint(snd_usb_audio_t *chip, int stream, struct audiofor
/*
* check if the device uses big-endian samples
*/
static int is_big_endian_format(struct usb_device *dev, struct audioformat *fp)
static int is_big_endian_format(snd_usb_audio_t *chip, struct audioformat *fp)
{
/* M-Audio */
if (le16_to_cpu(dev->descriptor.idVendor) == 0x0763) {
/* Quattro: captured data only */
if (le16_to_cpu(dev->descriptor.idProduct) == 0x2001 &&
fp->endpoint & USB_DIR_IN)
return 1;
/* Audiophile USB */
if (le16_to_cpu(dev->descriptor.idProduct) == 0x2003)
switch (chip->usb_id) {
case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
if (fp->endpoint & USB_DIR_IN)
return 1;
break;
case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
return 1;
}
return 0;
}
Expand All @@ -2208,7 +2206,7 @@ static int is_big_endian_format(struct usb_device *dev, struct audioformat *fp)
* @format: the format tag (wFormatTag)
* @fmt: the format type descriptor
*/
static int parse_audio_format_i_type(struct usb_device *dev, struct audioformat *fp,
static int parse_audio_format_i_type(snd_usb_audio_t *chip, struct audioformat *fp,
int format, unsigned char *fmt)
{
int pcm_format;
Expand All @@ -2221,12 +2219,12 @@ static int parse_audio_format_i_type(struct usb_device *dev, struct audioformat
switch (format) {
case 0: /* some devices don't define this correctly... */
snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n",
dev->devnum, fp->iface, fp->altsetting);
chip->dev->devnum, fp->iface, fp->altsetting);
/* fall-through */
case USB_AUDIO_FORMAT_PCM:
if (sample_width > sample_bytes * 8) {
snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n",
dev->devnum, fp->iface, fp->altsetting,
chip->dev->devnum, fp->iface, fp->altsetting,
sample_width, sample_bytes);
}
/* check the format byte size */
Expand All @@ -2235,13 +2233,13 @@ static int parse_audio_format_i_type(struct usb_device *dev, struct audioformat
pcm_format = SNDRV_PCM_FORMAT_S8;
break;
case 2:
if (is_big_endian_format(dev, fp))
if (is_big_endian_format(chip, fp))
pcm_format = SNDRV_PCM_FORMAT_S16_BE; /* grrr, big endian!! */
else
pcm_format = SNDRV_PCM_FORMAT_S16_LE;
break;
case 3:
if (is_big_endian_format(dev, fp))
if (is_big_endian_format(chip, fp))
pcm_format = SNDRV_PCM_FORMAT_S24_3BE; /* grrr, big endian!! */
else
pcm_format = SNDRV_PCM_FORMAT_S24_3LE;
Expand All @@ -2251,14 +2249,14 @@ static int parse_audio_format_i_type(struct usb_device *dev, struct audioformat
break;
default:
snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n",
dev->devnum, fp->iface, fp->altsetting, sample_width, sample_bytes);
chip->dev->devnum, fp->iface,
fp->altsetting, sample_width, sample_bytes);
break;
}
break;
case USB_AUDIO_FORMAT_PCM8:
/* Dallas DS4201 workaround */
if (le16_to_cpu(dev->descriptor.idVendor) == 0x04fa &&
le16_to_cpu(dev->descriptor.idProduct) == 0x4201)
if (chip->usb_id == USB_ID(0x04fa, 0x4201))
pcm_format = SNDRV_PCM_FORMAT_S8;
else
pcm_format = SNDRV_PCM_FORMAT_U8;
Expand All @@ -2274,7 +2272,7 @@ static int parse_audio_format_i_type(struct usb_device *dev, struct audioformat
break;
default:
snd_printk(KERN_INFO "%d:%u:%d : unsupported format type %d\n",
dev->devnum, fp->iface, fp->altsetting, format);
chip->dev->devnum, fp->iface, fp->altsetting, format);
break;
}
return pcm_format;
Expand All @@ -2291,13 +2289,13 @@ static int parse_audio_format_i_type(struct usb_device *dev, struct audioformat
* @offset: the start offset of descriptor pointing the rate type
* (7 for type I and II, 8 for type II)
*/
static int parse_audio_format_rates(struct usb_device *dev, struct audioformat *fp,
static int parse_audio_format_rates(snd_usb_audio_t *chip, struct audioformat *fp,
unsigned char *fmt, int offset)
{
int nr_rates = fmt[offset];
if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
snd_printk(KERN_ERR "%d:%u:%d : invalid FORMAT_TYPE desc\n",
dev->devnum, fp->iface, fp->altsetting);
chip->dev->devnum, fp->iface, fp->altsetting);
return -1;
}

Expand Down Expand Up @@ -2344,7 +2342,7 @@ static int parse_audio_format_rates(struct usb_device *dev, struct audioformat *
/*
* parse the format type I and III descriptors
*/
static int parse_audio_format_i(struct usb_device *dev, struct audioformat *fp,
static int parse_audio_format_i(snd_usb_audio_t *chip, struct audioformat *fp,
int format, unsigned char *fmt)
{
int pcm_format;
Expand All @@ -2356,24 +2354,24 @@ static int parse_audio_format_i(struct usb_device *dev, struct audioformat *fp,
*/
pcm_format = SNDRV_PCM_FORMAT_S16_LE;
} else {
pcm_format = parse_audio_format_i_type(dev, fp, format, fmt);
pcm_format = parse_audio_format_i_type(chip, fp, format, fmt);
if (pcm_format < 0)
return -1;
}
fp->format = pcm_format;
fp->channels = fmt[4];
if (fp->channels < 1) {
snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n",
dev->devnum, fp->iface, fp->altsetting, fp->channels);
chip->dev->devnum, fp->iface, fp->altsetting, fp->channels);
return -1;
}
return parse_audio_format_rates(dev, fp, fmt, 7);
return parse_audio_format_rates(chip, fp, fmt, 7);
}

/*
* prase the format type II descriptor
*/
static int parse_audio_format_ii(struct usb_device *dev, struct audioformat *fp,
static int parse_audio_format_ii(snd_usb_audio_t *chip, struct audioformat *fp,
int format, unsigned char *fmt)
{
int brate, framesize;
Expand All @@ -2388,7 +2386,7 @@ static int parse_audio_format_ii(struct usb_device *dev, struct audioformat *fp,
break;
default:
snd_printd(KERN_INFO "%d:%u:%d : unknown format tag 0x%x is detected. processed as MPEG.\n",
dev->devnum, fp->iface, fp->altsetting, format);
chip->dev->devnum, fp->iface, fp->altsetting, format);
fp->format = SNDRV_PCM_FORMAT_MPEG;
break;
}
Expand All @@ -2397,25 +2395,25 @@ static int parse_audio_format_ii(struct usb_device *dev, struct audioformat *fp,
framesize = combine_word(&fmt[6]); /* fmt[6,7]: wSamplesPerFrame */
snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
fp->frame_size = framesize;
return parse_audio_format_rates(dev, fp, fmt, 8); /* fmt[8..] sample rates */
return parse_audio_format_rates(chip, fp, fmt, 8); /* fmt[8..] sample rates */
}

static int parse_audio_format(struct usb_device *dev, struct audioformat *fp,
static int parse_audio_format(snd_usb_audio_t *chip, struct audioformat *fp,
int format, unsigned char *fmt, int stream)
{
int err;

switch (fmt[3]) {
case USB_FORMAT_TYPE_I:
case USB_FORMAT_TYPE_III:
err = parse_audio_format_i(dev, fp, format, fmt);
err = parse_audio_format_i(chip, fp, format, fmt);
break;
case USB_FORMAT_TYPE_II:
err = parse_audio_format_ii(dev, fp, format, fmt);
err = parse_audio_format_ii(chip, fp, format, fmt);
break;
default:
snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",
dev->devnum, fp->iface, fp->altsetting, fmt[3]);
chip->dev->devnum, fp->iface, fp->altsetting, fmt[3]);
return -1;
}
fp->fmt_type = fmt[3];
Expand All @@ -2426,9 +2424,8 @@ static int parse_audio_format(struct usb_device *dev, struct audioformat *fp,
/* extigy apparently supports sample rates other than 48k
* but not in ordinary way. so we enable only 48k atm.
*/
if (le16_to_cpu(dev->descriptor.idVendor) == 0x041e &&
(le16_to_cpu(dev->descriptor.idProduct) == 0x3000 ||
le16_to_cpu(dev->descriptor.idProduct) == 0x3020)) {
if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
chip->usb_id == USB_ID(0x041e, 0x3020)) {
if (fmt[3] == USB_FORMAT_TYPE_I &&
stream == SNDRV_PCM_STREAM_PLAYBACK &&
fp->rates != SNDRV_PCM_RATE_48000 &&
Expand Down Expand Up @@ -2532,17 +2529,15 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
/* some quirks for attributes here */

/* workaround for AudioTrak Optoplay */
if (le16_to_cpu(dev->descriptor.idVendor) == 0x0a92 &&
le16_to_cpu(dev->descriptor.idProduct) == 0x0053) {
if (chip->usb_id == USB_ID(0x0a92, 0x0053)) {
/* Optoplay sets the sample rate attribute although
* it seems not supporting it in fact.
*/
fp->attributes &= ~EP_CS_ATTR_SAMPLE_RATE;
}

/* workaround for M-Audio Audiophile USB */
if (le16_to_cpu(dev->descriptor.idVendor) == 0x0763 &&
le16_to_cpu(dev->descriptor.idProduct) == 0x2003) {
if (chip->usb_id == USB_ID(0x0763, 0x2003)) {
/* doesn't set the sample rate attribute, but supports it */
fp->attributes |= EP_CS_ATTR_SAMPLE_RATE;
}
Expand All @@ -2551,11 +2546,9 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
* plantronics headset and Griffin iMic have set adaptive-in
* although it's really not...
*/
if ((le16_to_cpu(dev->descriptor.idVendor) == 0x047f &&
le16_to_cpu(dev->descriptor.idProduct) == 0x0ca1) ||
if (chip->usb_id == USB_ID(0x047f, 0x0ca1) ||
/* Griffin iMic (note that there is an older model 77d:223) */
(le16_to_cpu(dev->descriptor.idVendor) == 0x077d &&
le16_to_cpu(dev->descriptor.idProduct) == 0x07af)) {
chip->usb_id == USB_ID(0x077d, 0x07af)) {
fp->ep_attr &= ~EP_ATTR_MASK;
if (stream == SNDRV_PCM_STREAM_PLAYBACK)
fp->ep_attr |= EP_ATTR_ADAPTIVE;
Expand All @@ -2564,7 +2557,7 @@ static int parse_audio_endpoints(snd_usb_audio_t *chip, int iface_no)
}

/* ok, let's parse further... */
if (parse_audio_format(dev, fp, format, fmt, stream) < 0) {
if (parse_audio_format(chip, fp, format, fmt, stream) < 0) {
kfree(fp->rate_table);
kfree(fp);
continue;
Expand Down Expand Up @@ -2799,7 +2792,7 @@ static int create_ua700_ua25_quirk(snd_usb_audio_t *chip,
.type = QUIRK_MIDI_FIXED_ENDPOINT,
.data = &ua25_ep
};
if (le16_to_cpu(chip->dev->descriptor.idProduct) == 0x002b)
if (chip->usb_id == USB_ID(0x0582, 0x002b))
return snd_usb_create_midi_interface(chip, iface,
&ua700_quirk);
else
Expand Down Expand Up @@ -3018,8 +3011,8 @@ static void proc_audio_usbid_read(snd_info_entry_t *entry, snd_info_buffer_t *bu
snd_usb_audio_t *chip = entry->private_data;
if (! chip->shutdown)
snd_iprintf(buffer, "%04x:%04x\n",
le16_to_cpu(chip->dev->descriptor.idVendor),
le16_to_cpu(chip->dev->descriptor.idProduct));
USB_ID_VENDOR(chip->usb_id),
USB_ID_PRODUCT(chip->usb_id));
}

static void snd_usb_audio_create_proc(snd_usb_audio_t *chip)
Expand Down Expand Up @@ -3089,6 +3082,8 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
chip->index = idx;
chip->dev = dev;
chip->card = card;
chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
le16_to_cpu(dev->descriptor.idProduct));
INIT_LIST_HEAD(&chip->pcm_list);
INIT_LIST_HEAD(&chip->midi_list);
INIT_LIST_HEAD(&chip->mixer_list);
Expand All @@ -3101,8 +3096,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,

strcpy(card->driver, "USB-Audio");
sprintf(component, "USB%04x:%04x",
le16_to_cpu(dev->descriptor.idVendor),
le16_to_cpu(dev->descriptor.idProduct));
USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id));
snd_component_add(card, component);

/* retrieve the device string as shortname */
Expand All @@ -3114,8 +3108,8 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
card->shortname, sizeof(card->shortname)) <= 0) {
/* no name available from anywhere, so use ID */
sprintf(card->shortname, "USB Device %#04x:%#04x",
le16_to_cpu(dev->descriptor.idVendor),
le16_to_cpu(dev->descriptor.idProduct));
USB_ID_VENDOR(chip->usb_id),
USB_ID_PRODUCT(chip->usb_id));
}
}

Expand Down Expand Up @@ -3173,17 +3167,19 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
snd_usb_audio_t *chip;
struct usb_host_interface *alts;
int ifnum;
u32 id;

alts = &intf->altsetting[0];
ifnum = get_iface_desc(alts)->bInterfaceNumber;
id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
le16_to_cpu(dev->descriptor.idProduct));

if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
goto __err_val;

/* SB Extigy needs special boot-up sequence */
/* if more models come, this will go to the quirk list. */
if (le16_to_cpu(dev->descriptor.idVendor) == 0x041e &&
le16_to_cpu(dev->descriptor.idProduct) == 0x3000) {
if (id == USB_ID(0x041e, 0x3000)) {
if (snd_usb_extigy_boot_quirk(dev, intf) < 0)
goto __err_val;
config = dev->actconfig;
Expand Down Expand Up @@ -3217,8 +3213,8 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
}
for (i = 0; i < SNDRV_CARDS; i++)
if (enable[i] && ! usb_chip[i] &&
(vid[i] == -1 || vid[i] == le16_to_cpu(dev->descriptor.idVendor)) &&
(pid[i] == -1 || pid[i] == le16_to_cpu(dev->descriptor.idProduct))) {
(vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
(pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {
goto __error;
}
Expand Down
6 changes: 6 additions & 0 deletions trunk/sound/usb/usbaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
/* maximum number of endpoints per interface */
#define MIDI_MAX_ENDPOINTS 2

/* handling of USB vendor/product ID pairs as 32-bit numbers */
#define USB_ID(vendor, product) (((vendor) << 16) | (product))
#define USB_ID_VENDOR(id) ((id) >> 16)
#define USB_ID_PRODUCT(id) ((u16)(id))

/*
*/

Expand All @@ -127,6 +132,7 @@ struct snd_usb_audio {
int index;
struct usb_device *dev;
snd_card_t *card;
u32 usb_id;
int shutdown;
int num_interfaces;

Expand Down
Loading

0 comments on commit 50fc2dc

Please sign in to comment.