1 /*
2 * probe the active usb device3 *4 * note that this can be called multiple times per a device, when it5 * includes multiple audio control interfaces.6 *7 * thus we check the usb device pointer and creates the card instance8 * only at the first time. the successive calls of this function will9 * append the pcm interface to the corresponding card.10 */
11 static struct snd_usb_audio *
12 snd_usb_audio_probe(struct usb_device *dev,13 struct usb_interface *intf,14 const struct usb_device_id *usb_id)15 {16 const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info;17 inti, err;18 struct snd_usb_audio *chip;19 struct usb_host_interface *alts;20 intifnum;21 u32 id;22
23 alts = &intf->altsetting[0];24 ifnum = get_iface_desc(alts)->bInterfaceNumber;25 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),26 le16_to_cpu(dev->descriptor.idProduct));27 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)28 goto__err_val;29
30 if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0)31 goto__err_val;32
33 /*
34 * found a config. now register to ALSA35 */
36
37 /*check whether it‘s already registered*/
38 chip =NULL;39 mutex_lock(®ister_mutex);40 for (i = 0; i < SNDRV_CARDS; i++) {41 if (usb_chip[i] && usb_chip[i]->dev ==dev) {42 if (usb_chip[i]->shutdown) {43 snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");44 goto__error;45 }46 chip =usb_chip[i];47 chip->probing = 1;48 break;49 }50 }51 if (!chip) {52 /*it‘s a fresh one.53 * now look for an empty slot and create a new card instance54 */
55 for (i = 0; i < SNDRV_CARDS; i++)56 if (enable[i] && ! usb_chip[i] &&
57 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
58 (pid[i] == -1 || pid[i] ==USB_ID_PRODUCT(id))) {59 if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {60 goto__error;61 }62 snd_card_set_dev(chip->card, &intf->dev);63 chip->pm_intf =intf;64 break;65 }66 if (!chip) {67 printk(KERN_ERR "no available usb audio device\n");68 goto__error;69 }70 }71
72 /*
73 * For devices with more than one control interface, we assume the74 * first contains the audio controls. We might need a more specific75 * check here in the future.76 */
77 if (!chip->ctrl_intf)78 chip->ctrl_intf =alts;79
80 chip->txfr_quirk = 0;81 err = 1; /*continue*/
82 if (quirk && quirk->ifnum !=QUIRK_NO_INTERFACE) {83 /*need some special handlings*/
84 if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0)85 goto__error;86 }87
88 if (err > 0) {89 /*create normal USB audio interfaces*/
90 if (snd_usb_create_streams(chip, ifnum) < 0 ||
91 snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) {92 goto__error;93 }94 }95
96 /*we are allowed to call snd_card_register() many times*/
97 if (snd_card_register(chip->card) < 0) {98 goto__error;99 }100
101 usb_chip[chip->index] =chip;102 chip->num_interfaces++;103 chip->probing = 0;104 mutex_unlock(®ister_mutex);105 returnchip;106
107 __error:108 if(chip) {109 if (!chip->num_interfaces)110 snd_card_free(chip->card);111 chip->probing = 0;112 }113 mutex_unlock(®ister_mutex);114 __err_val:115 returnNULL;116 }