aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2014-10-31 06:00:23 -0400
committerTakashi Iwai <tiwai@suse.de>2014-11-04 09:09:08 -0500
commit4c8c3a4fcc021677c9a363b4e77f61dd09dbfd1a (patch)
treebc7a5211efe309850d6568c0dd19a689ec9dafdb /sound/usb
parent2603fe21b764eb7412598c8c6cd6199fb8b1d9c5 (diff)
ALSA: usb-audio: Flatten probe and disconnect functions
The usb-audio probe and disconnect functions have been split just for adapting the (new!) API at 2.5 kernel time. We left them until now, partly because we wanted to build with the pretty old kernels in the external alsa-driver tree. But the support of such old kernels has been longly stopped, so it's good time to clean up this mess. One good point by this cleanup is that now the probe function returns a proper error code instead of only -EIO. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/card.c75
1 files changed, 30 insertions, 45 deletions
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 7ecd0e8a5c51..be16bdc53c2a 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -112,7 +112,7 @@ static struct usb_driver usb_audio_driver;
112 112
113/* 113/*
114 * disconnect streams 114 * disconnect streams
115 * called from snd_usb_audio_disconnect() 115 * called from usb_audio_disconnect()
116 */ 116 */
117static void snd_usb_stream_disconnect(struct list_head *head) 117static void snd_usb_stream_disconnect(struct list_head *head)
118{ 118{
@@ -475,14 +475,14 @@ static int snd_usb_audio_create(struct usb_interface *intf,
475 * only at the first time. the successive calls of this function will 475 * only at the first time. the successive calls of this function will
476 * append the pcm interface to the corresponding card. 476 * append the pcm interface to the corresponding card.
477 */ 477 */
478static struct snd_usb_audio * 478static int usb_audio_probe(struct usb_interface *intf,
479snd_usb_audio_probe(struct usb_device *dev, 479 const struct usb_device_id *usb_id)
480 struct usb_interface *intf,
481 const struct usb_device_id *usb_id)
482{ 480{
483 const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info; 481 struct usb_device *dev = interface_to_usbdev(intf);
484 int i, err; 482 const struct snd_usb_audio_quirk *quirk =
483 (const struct snd_usb_audio_quirk *)usb_id->driver_info;
485 struct snd_usb_audio *chip; 484 struct snd_usb_audio *chip;
485 int i, err;
486 struct usb_host_interface *alts; 486 struct usb_host_interface *alts;
487 int ifnum; 487 int ifnum;
488 u32 id; 488 u32 id;
@@ -492,10 +492,11 @@ snd_usb_audio_probe(struct usb_device *dev,
492 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor), 492 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
493 le16_to_cpu(dev->descriptor.idProduct)); 493 le16_to_cpu(dev->descriptor.idProduct));
494 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum) 494 if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
495 goto __err_val; 495 return -ENXIO;
496 496
497 if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0) 497 err = snd_usb_apply_boot_quirk(dev, intf, quirk);
498 goto __err_val; 498 if (err < 0)
499 return err;
499 500
500 /* 501 /*
501 * found a config. now register to ALSA 502 * found a config. now register to ALSA
@@ -508,6 +509,7 @@ snd_usb_audio_probe(struct usb_device *dev,
508 if (usb_chip[i] && usb_chip[i]->dev == dev) { 509 if (usb_chip[i] && usb_chip[i]->dev == dev) {
509 if (usb_chip[i]->shutdown) { 510 if (usb_chip[i]->shutdown) {
510 dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n"); 511 dev_err(&dev->dev, "USB device is in the shutdown state, cannot create a card instance\n");
512 err = -EIO;
511 goto __error; 513 goto __error;
512 } 514 }
513 chip = usb_chip[i]; 515 chip = usb_chip[i];
@@ -523,15 +525,16 @@ snd_usb_audio_probe(struct usb_device *dev,
523 if (enable[i] && ! usb_chip[i] && 525 if (enable[i] && ! usb_chip[i] &&
524 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) && 526 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
525 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) { 527 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
526 if (snd_usb_audio_create(intf, dev, i, quirk, 528 err = snd_usb_audio_create(intf, dev, i, quirk,
527 &chip) < 0) { 529 &chip);
530 if (err < 0)
528 goto __error; 531 goto __error;
529 }
530 chip->pm_intf = intf; 532 chip->pm_intf = intf;
531 break; 533 break;
532 } 534 }
533 if (!chip) { 535 if (!chip) {
534 dev_err(&dev->dev, "no available usb audio device\n"); 536 dev_err(&dev->dev, "no available usb audio device\n");
537 err = -ENODEV;
535 goto __error; 538 goto __error;
536 } 539 }
537 } 540 }
@@ -548,28 +551,32 @@ snd_usb_audio_probe(struct usb_device *dev,
548 err = 1; /* continue */ 551 err = 1; /* continue */
549 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) { 552 if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
550 /* need some special handlings */ 553 /* need some special handlings */
551 if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0) 554 err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk);
555 if (err < 0)
552 goto __error; 556 goto __error;
553 } 557 }
554 558
555 if (err > 0) { 559 if (err > 0) {
556 /* create normal USB audio interfaces */ 560 /* create normal USB audio interfaces */
557 if (snd_usb_create_streams(chip, ifnum) < 0 || 561 err = snd_usb_create_streams(chip, ifnum);
558 snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) { 562 if (err < 0)
563 goto __error;
564 err = snd_usb_create_mixer(chip, ifnum, ignore_ctl_error);
565 if (err < 0)
559 goto __error; 566 goto __error;
560 }
561 } 567 }
562 568
563 /* we are allowed to call snd_card_register() many times */ 569 /* we are allowed to call snd_card_register() many times */
564 if (snd_card_register(chip->card) < 0) { 570 err = snd_card_register(chip->card);
571 if (err < 0)
565 goto __error; 572 goto __error;
566 }
567 573
568 usb_chip[chip->index] = chip; 574 usb_chip[chip->index] = chip;
569 chip->num_interfaces++; 575 chip->num_interfaces++;
570 chip->probing = 0; 576 chip->probing = 0;
577 usb_set_intfdata(intf, chip);
571 mutex_unlock(&register_mutex); 578 mutex_unlock(&register_mutex);
572 return chip; 579 return 0;
573 580
574 __error: 581 __error:
575 if (chip) { 582 if (chip) {
@@ -578,17 +585,16 @@ snd_usb_audio_probe(struct usb_device *dev,
578 chip->probing = 0; 585 chip->probing = 0;
579 } 586 }
580 mutex_unlock(&register_mutex); 587 mutex_unlock(&register_mutex);
581 __err_val: 588 return err;
582 return NULL;
583} 589}
584 590
585/* 591/*
586 * we need to take care of counter, since disconnection can be called also 592 * we need to take care of counter, since disconnection can be called also
587 * many times as well as usb_audio_probe(). 593 * many times as well as usb_audio_probe().
588 */ 594 */
589static void snd_usb_audio_disconnect(struct usb_device *dev, 595static void usb_audio_disconnect(struct usb_interface *intf)
590 struct snd_usb_audio *chip)
591{ 596{
597 struct snd_usb_audio *chip = usb_get_intfdata(intf);
592 struct snd_card *card; 598 struct snd_card *card;
593 struct list_head *p; 599 struct list_head *p;
594 600
@@ -630,27 +636,6 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
630 } 636 }
631} 637}
632 638
633/*
634 * new 2.5 USB kernel API
635 */
636static int usb_audio_probe(struct usb_interface *intf,
637 const struct usb_device_id *id)
638{
639 struct snd_usb_audio *chip;
640 chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
641 if (chip) {
642 usb_set_intfdata(intf, chip);
643 return 0;
644 } else
645 return -EIO;
646}
647
648static void usb_audio_disconnect(struct usb_interface *intf)
649{
650 snd_usb_audio_disconnect(interface_to_usbdev(intf),
651 usb_get_intfdata(intf));
652}
653
654#ifdef CONFIG_PM 639#ifdef CONFIG_PM
655 640
656int snd_usb_autoresume(struct snd_usb_audio *chip) 641int snd_usb_autoresume(struct snd_usb_audio *chip)