aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <m.chehab@samsung.com>2014-01-12 08:10:34 -0500
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-01-12 08:57:05 -0500
commit966f4163751b456f526a0b0dc8e6a9814df6abd9 (patch)
tree49f562029cba0fafb11e112fa45ffa03aaa1c49d /drivers/media
parent34906633faa69d523c032f37036b0bda6232268d (diff)
[media] em28xx-audio: split URB initialization code
The URB calculus code may eventually be moved to some other place, like at pcm open, if it ends by needing more setups, like working with different bit rates, or different audio latency. So, move it into a separate routine. That also makes the code more readable. No functional changes. Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/usb/em28xx/em28xx-audio.c145
1 files changed, 76 insertions, 69 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c
index f004680219e7..13ba631130cd 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -681,75 +681,14 @@ static int em28xx_audio_ep_packet_size(struct usb_device *udev,
681 return size & 0x7ff; 681 return size & 0x7ff;
682} 682}
683 683
684static int em28xx_audio_init(struct em28xx *dev) 684static int em28xx_audio_urb_init(struct em28xx *dev)
685{ 685{
686 struct em28xx_audio *adev = &dev->adev;
687 struct snd_pcm *pcm;
688 struct snd_card *card;
689 struct usb_interface *intf; 686 struct usb_interface *intf;
690 struct usb_endpoint_descriptor *e, *ep = NULL; 687 struct usb_endpoint_descriptor *e, *ep = NULL;
691 static int devnr; 688 int i, ep_size, interval, num_urb, npackets;
692 int err, i, ep_size, interval, num_urb, npackets;
693 int urb_size, bytes_per_transfer; 689 int urb_size, bytes_per_transfer;
694 u8 alt; 690 u8 alt;
695 691
696 if (!dev->has_alsa_audio || dev->audio_ifnum < 0) {
697 /* This device does not support the extension (in this case
698 the device is expecting the snd-usb-audio module or
699 doesn't have analog audio support at all) */
700 return 0;
701 }
702
703 em28xx_info("Binding audio extension\n");
704
705 printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
706 "Rechberger\n");
707 printk(KERN_INFO
708 "em28xx-audio.c: Copyright (C) 2007-2014 Mauro Carvalho Chehab\n");
709
710 err = snd_card_create(index[devnr], "Em28xx Audio", THIS_MODULE, 0,
711 &card);
712 if (err < 0)
713 return err;
714
715 spin_lock_init(&adev->slock);
716 adev->sndcard = card;
717 adev->udev = dev->udev;
718
719 err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
720 if (err < 0) {
721 snd_card_free(card);
722 return err;
723 }
724
725 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
726 pcm->info_flags = 0;
727 pcm->private_data = dev;
728 strcpy(pcm->name, "Empia 28xx Capture");
729
730 snd_card_set_dev(card, &dev->udev->dev);
731 strcpy(card->driver, "Em28xx-Audio");
732 strcpy(card->shortname, "Em28xx Audio");
733 strcpy(card->longname, "Empia Em28xx Audio");
734
735 INIT_WORK(&dev->wq_trigger, audio_trigger);
736
737 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
738 em28xx_cvol_new(card, dev, "Video", AC97_VIDEO);
739 em28xx_cvol_new(card, dev, "Line In", AC97_LINE);
740 em28xx_cvol_new(card, dev, "Phone", AC97_PHONE);
741 em28xx_cvol_new(card, dev, "Microphone", AC97_MIC);
742 em28xx_cvol_new(card, dev, "CD", AC97_CD);
743 em28xx_cvol_new(card, dev, "AUX", AC97_AUX);
744 em28xx_cvol_new(card, dev, "PCM", AC97_PCM);
745
746 em28xx_cvol_new(card, dev, "Master", AC97_MASTER);
747 em28xx_cvol_new(card, dev, "Line", AC97_HEADPHONE);
748 em28xx_cvol_new(card, dev, "Mono", AC97_MASTER_MONO);
749 em28xx_cvol_new(card, dev, "LFE", AC97_CENTER_LFE_MASTER);
750 em28xx_cvol_new(card, dev, "Surround", AC97_SURROUND_MASTER);
751 }
752
753 if (dev->audio_ifnum) 692 if (dev->audio_ifnum)
754 alt = 1; 693 alt = 1;
755 else 694 else
@@ -760,7 +699,6 @@ static int em28xx_audio_init(struct em28xx *dev)
760 if (intf->num_altsetting <= alt) { 699 if (intf->num_altsetting <= alt) {
761 em28xx_errdev("alt %d doesn't exist on interface %d\n", 700 em28xx_errdev("alt %d doesn't exist on interface %d\n",
762 dev->audio_ifnum, alt); 701 dev->audio_ifnum, alt);
763 snd_card_free(card);
764 return -ENODEV; 702 return -ENODEV;
765 } 703 }
766 704
@@ -776,7 +714,6 @@ static int em28xx_audio_init(struct em28xx *dev)
776 714
777 if (!ep) { 715 if (!ep) {
778 em28xx_errdev("Couldn't find an audio endpoint"); 716 em28xx_errdev("Couldn't find an audio endpoint");
779 snd_card_free(card);
780 return -ENODEV; 717 return -ENODEV;
781 } 718 }
782 719
@@ -833,13 +770,11 @@ static int em28xx_audio_init(struct em28xx *dev)
833 sizeof(*dev->adev.transfer_buffer), 770 sizeof(*dev->adev.transfer_buffer),
834 GFP_ATOMIC); 771 GFP_ATOMIC);
835 if (!dev->adev.transfer_buffer) { 772 if (!dev->adev.transfer_buffer) {
836 snd_card_free(card);
837 return -ENOMEM; 773 return -ENOMEM;
838 } 774 }
839 775
840 dev->adev.urb = kcalloc(num_urb, sizeof(*dev->adev.urb), GFP_ATOMIC); 776 dev->adev.urb = kcalloc(num_urb, sizeof(*dev->adev.urb), GFP_ATOMIC);
841 if (!dev->adev.urb) { 777 if (!dev->adev.urb) {
842 snd_card_free(card);
843 kfree(dev->adev.transfer_buffer); 778 kfree(dev->adev.transfer_buffer);
844 return -ENOMEM; 779 return -ENOMEM;
845 } 780 }
@@ -855,7 +790,6 @@ static int em28xx_audio_init(struct em28xx *dev)
855 if (!urb) { 790 if (!urb) {
856 em28xx_errdev("usb_alloc_urb failed!\n"); 791 em28xx_errdev("usb_alloc_urb failed!\n");
857 em28xx_audio_free_urb(dev); 792 em28xx_audio_free_urb(dev);
858 snd_card_free(card);
859 return -ENOMEM; 793 return -ENOMEM;
860 } 794 }
861 dev->adev.urb[i] = urb; 795 dev->adev.urb[i] = urb;
@@ -865,7 +799,6 @@ static int em28xx_audio_init(struct em28xx *dev)
865 if (!buf) { 799 if (!buf) {
866 em28xx_errdev("usb_alloc_coherent failed!\n"); 800 em28xx_errdev("usb_alloc_coherent failed!\n");
867 em28xx_audio_free_urb(dev); 801 em28xx_audio_free_urb(dev);
868 snd_card_free(card);
869 return -ENOMEM; 802 return -ENOMEM;
870 } 803 }
871 dev->adev.transfer_buffer[i] = buf; 804 dev->adev.transfer_buffer[i] = buf;
@@ -886,6 +819,80 @@ static int em28xx_audio_init(struct em28xx *dev)
886 } 819 }
887 } 820 }
888 821
822 return 0;
823}
824
825static int em28xx_audio_init(struct em28xx *dev)
826{
827 struct em28xx_audio *adev = &dev->adev;
828 struct snd_pcm *pcm;
829 struct snd_card *card;
830 static int devnr;
831 int err;
832
833 if (!dev->has_alsa_audio || dev->audio_ifnum < 0) {
834 /* This device does not support the extension (in this case
835 the device is expecting the snd-usb-audio module or
836 doesn't have analog audio support at all) */
837 return 0;
838 }
839
840 em28xx_info("Binding audio extension\n");
841
842 printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
843 "Rechberger\n");
844 printk(KERN_INFO
845 "em28xx-audio.c: Copyright (C) 2007-2014 Mauro Carvalho Chehab\n");
846
847 err = snd_card_create(index[devnr], "Em28xx Audio", THIS_MODULE, 0,
848 &card);
849 if (err < 0)
850 return err;
851
852 spin_lock_init(&adev->slock);
853 adev->sndcard = card;
854 adev->udev = dev->udev;
855
856 err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
857 if (err < 0) {
858 snd_card_free(card);
859 return err;
860 }
861
862 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_em28xx_pcm_capture);
863 pcm->info_flags = 0;
864 pcm->private_data = dev;
865 strcpy(pcm->name, "Empia 28xx Capture");
866
867 snd_card_set_dev(card, &dev->udev->dev);
868 strcpy(card->driver, "Em28xx-Audio");
869 strcpy(card->shortname, "Em28xx Audio");
870 strcpy(card->longname, "Empia Em28xx Audio");
871
872 INIT_WORK(&dev->wq_trigger, audio_trigger);
873
874 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
875 em28xx_cvol_new(card, dev, "Video", AC97_VIDEO);
876 em28xx_cvol_new(card, dev, "Line In", AC97_LINE);
877 em28xx_cvol_new(card, dev, "Phone", AC97_PHONE);
878 em28xx_cvol_new(card, dev, "Microphone", AC97_MIC);
879 em28xx_cvol_new(card, dev, "CD", AC97_CD);
880 em28xx_cvol_new(card, dev, "AUX", AC97_AUX);
881 em28xx_cvol_new(card, dev, "PCM", AC97_PCM);
882
883 em28xx_cvol_new(card, dev, "Master", AC97_MASTER);
884 em28xx_cvol_new(card, dev, "Line", AC97_HEADPHONE);
885 em28xx_cvol_new(card, dev, "Mono", AC97_MASTER_MONO);
886 em28xx_cvol_new(card, dev, "LFE", AC97_CENTER_LFE_MASTER);
887 em28xx_cvol_new(card, dev, "Surround", AC97_SURROUND_MASTER);
888 }
889
890 err = em28xx_audio_urb_init(dev);
891 if (err) {
892 snd_card_free(card);
893 return -ENODEV;
894 }
895
889 err = snd_card_register(card); 896 err = snd_card_register(card);
890 if (err < 0) { 897 if (err < 0) {
891 em28xx_audio_free_urb(dev); 898 em28xx_audio_free_urb(dev);