diff options
author | Andrzej Pietrasiewicz <andrzej.p@samsung.com> | 2014-07-22 13:58:38 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2014-08-20 15:04:54 -0400 |
commit | f3a3406b3f562f8d15b89979c0ca9e184b269084 (patch) | |
tree | 0cf9bc197f84683c8162a0005a6379738ddd9bb7 | |
parent | af1a58ca00b3735275c453ebd0b811a71a377470 (diff) |
usb: gadget: f_uac1: convert to new function interface with backward compatibility
Converting uac1 to the new function interface requires converting
the USB uac1's function code and its users.
This patch converts the f_uac1.c to the new function interface.
The file is now compiled into a separate usb_f_uac1.ko module.
The old function interface is provided by means of a preprocessor
conditional directives. After all users are converted, the old interface
can be removed.
Tested-by: Sebastian Reimers <sebastian.reimers@googlemail.com>
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r-- | drivers/usb/gadget/Kconfig | 3 | ||||
-rw-r--r-- | drivers/usb/gadget/function/Makefile | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/function/f_uac1.c | 169 | ||||
-rw-r--r-- | drivers/usb/gadget/function/u_uac1.c | 31 | ||||
-rw-r--r-- | drivers/usb/gadget/function/u_uac1.h | 20 | ||||
-rw-r--r-- | drivers/usb/gadget/legacy/audio.c | 1 |
6 files changed, 195 insertions, 31 deletions
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index ea8ebce60d8f..68302aa604be 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -181,6 +181,9 @@ config USB_F_MASS_STORAGE | |||
181 | config USB_F_FS | 181 | config USB_F_FS |
182 | tristate | 182 | tristate |
183 | 183 | ||
184 | config USB_F_UAC1 | ||
185 | tristate | ||
186 | |||
184 | config USB_F_UAC2 | 187 | config USB_F_UAC2 |
185 | tristate | 188 | tristate |
186 | 189 | ||
diff --git a/drivers/usb/gadget/function/Makefile b/drivers/usb/gadget/function/Makefile index 20775a87e51a..edb6dfa91932 100644 --- a/drivers/usb/gadget/function/Makefile +++ b/drivers/usb/gadget/function/Makefile | |||
@@ -32,5 +32,7 @@ usb_f_mass_storage-y := f_mass_storage.o storage_common.o | |||
32 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o | 32 | obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o |
33 | usb_f_fs-y := f_fs.o | 33 | usb_f_fs-y := f_fs.o |
34 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o | 34 | obj-$(CONFIG_USB_F_FS) += usb_f_fs.o |
35 | usb_f_uac1-y := f_uac1.o u_uac1.o | ||
36 | obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o | ||
35 | usb_f_uac2-y := f_uac2.o | 37 | usb_f_uac2-y := f_uac2.o |
36 | obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o | 38 | obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o |
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 9cfaf1de7b90..787ed2bc4dd4 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c | |||
@@ -11,13 +11,17 @@ | |||
11 | 11 | ||
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/module.h> | ||
14 | #include <linux/device.h> | 15 | #include <linux/device.h> |
15 | #include <linux/atomic.h> | 16 | #include <linux/atomic.h> |
16 | 17 | ||
17 | #include "u_uac1.h" | 18 | #include "u_uac1.h" |
19 | #ifdef USBF_UAC1_INCLUDED | ||
18 | #include "u_uac1.c" | 20 | #include "u_uac1.c" |
21 | #endif | ||
19 | 22 | ||
20 | #define OUT_EP_MAX_PACKET_SIZE 200 | 23 | #define OUT_EP_MAX_PACKET_SIZE 200 |
24 | #ifdef USBF_UAC1_INCLUDED | ||
21 | static int req_buf_size = OUT_EP_MAX_PACKET_SIZE; | 25 | static int req_buf_size = OUT_EP_MAX_PACKET_SIZE; |
22 | module_param(req_buf_size, int, S_IRUGO); | 26 | module_param(req_buf_size, int, S_IRUGO); |
23 | MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); | 27 | MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); |
@@ -29,6 +33,7 @@ MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count"); | |||
29 | static int audio_buf_size = 48000; | 33 | static int audio_buf_size = 48000; |
30 | module_param(audio_buf_size, int, S_IRUGO); | 34 | module_param(audio_buf_size, int, S_IRUGO); |
31 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); | 35 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); |
36 | #endif | ||
32 | 37 | ||
33 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); | 38 | static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); |
34 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); | 39 | static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); |
@@ -47,7 +52,7 @@ static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); | |||
47 | #define F_AUDIO_NUM_INTERFACES 2 | 52 | #define F_AUDIO_NUM_INTERFACES 2 |
48 | 53 | ||
49 | /* B.3.1 Standard AC Interface Descriptor */ | 54 | /* B.3.1 Standard AC Interface Descriptor */ |
50 | static struct usb_interface_descriptor ac_interface_desc __initdata = { | 55 | static struct usb_interface_descriptor ac_interface_desc = { |
51 | .bLength = USB_DT_INTERFACE_SIZE, | 56 | .bLength = USB_DT_INTERFACE_SIZE, |
52 | .bDescriptorType = USB_DT_INTERFACE, | 57 | .bDescriptorType = USB_DT_INTERFACE, |
53 | .bNumEndpoints = 0, | 58 | .bNumEndpoints = 0, |
@@ -189,7 +194,7 @@ static struct usb_endpoint_descriptor as_out_ep_desc = { | |||
189 | }; | 194 | }; |
190 | 195 | ||
191 | /* Class-specific AS ISO OUT Endpoint Descriptor */ | 196 | /* Class-specific AS ISO OUT Endpoint Descriptor */ |
192 | static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = { | 197 | static struct uac_iso_endpoint_descriptor as_iso_out_desc = { |
193 | .bLength = UAC_ISO_ENDPOINT_DESC_SIZE, | 198 | .bLength = UAC_ISO_ENDPOINT_DESC_SIZE, |
194 | .bDescriptorType = USB_DT_CS_ENDPOINT, | 199 | .bDescriptorType = USB_DT_CS_ENDPOINT, |
195 | .bDescriptorSubtype = UAC_EP_GENERAL, | 200 | .bDescriptorSubtype = UAC_EP_GENERAL, |
@@ -198,7 +203,7 @@ static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = { | |||
198 | .wLockDelay = __constant_cpu_to_le16(1), | 203 | .wLockDelay = __constant_cpu_to_le16(1), |
199 | }; | 204 | }; |
200 | 205 | ||
201 | static struct usb_descriptor_header *f_audio_desc[] __initdata = { | 206 | static struct usb_descriptor_header *f_audio_desc[] = { |
202 | (struct usb_descriptor_header *)&ac_interface_desc, | 207 | (struct usb_descriptor_header *)&ac_interface_desc, |
203 | (struct usb_descriptor_header *)&ac_header_desc, | 208 | (struct usb_descriptor_header *)&ac_header_desc, |
204 | 209 | ||
@@ -332,8 +337,17 @@ static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req) | |||
332 | struct f_audio *audio = req->context; | 337 | struct f_audio *audio = req->context; |
333 | struct usb_composite_dev *cdev = audio->card.func.config->cdev; | 338 | struct usb_composite_dev *cdev = audio->card.func.config->cdev; |
334 | struct f_audio_buf *copy_buf = audio->copy_buf; | 339 | struct f_audio_buf *copy_buf = audio->copy_buf; |
340 | #ifndef USBF_UAC1_INCLUDED | ||
341 | struct f_uac1_opts *opts; | ||
342 | int audio_buf_size; | ||
343 | #endif | ||
335 | int err; | 344 | int err; |
336 | 345 | ||
346 | #ifndef USBF_UAC1_INCLUDED | ||
347 | opts = container_of(audio->card.func.fi, struct f_uac1_opts, | ||
348 | func_inst); | ||
349 | audio_buf_size = opts->audio_buf_size; | ||
350 | #endif | ||
337 | if (!copy_buf) | 351 | if (!copy_buf) |
338 | return -EINVAL; | 352 | return -EINVAL; |
339 | 353 | ||
@@ -578,10 +592,21 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | |||
578 | struct usb_composite_dev *cdev = f->config->cdev; | 592 | struct usb_composite_dev *cdev = f->config->cdev; |
579 | struct usb_ep *out_ep = audio->out_ep; | 593 | struct usb_ep *out_ep = audio->out_ep; |
580 | struct usb_request *req; | 594 | struct usb_request *req; |
595 | #ifndef USBF_UAC1_INCLUDED | ||
596 | struct f_uac1_opts *opts; | ||
597 | int req_buf_size, req_count, audio_buf_size; | ||
598 | #endif | ||
581 | int i = 0, err = 0; | 599 | int i = 0, err = 0; |
582 | 600 | ||
583 | DBG(cdev, "intf %d, alt %d\n", intf, alt); | 601 | DBG(cdev, "intf %d, alt %d\n", intf, alt); |
584 | 602 | ||
603 | #ifndef USBF_UAC1_INCLUDED | ||
604 | opts = container_of(f->fi, struct f_uac1_opts, func_inst); | ||
605 | req_buf_size = opts->req_buf_size; | ||
606 | req_count = opts->req_count; | ||
607 | audio_buf_size = opts->audio_buf_size; | ||
608 | |||
609 | #endif | ||
585 | if (intf == 1) { | 610 | if (intf == 1) { |
586 | if (alt == 1) { | 611 | if (alt == 1) { |
587 | usb_ep_enable(out_ep); | 612 | usb_ep_enable(out_ep); |
@@ -657,13 +682,50 @@ static void f_audio_build_desc(struct f_audio *audio) | |||
657 | } | 682 | } |
658 | 683 | ||
659 | /* audio function driver setup/binding */ | 684 | /* audio function driver setup/binding */ |
660 | static int __init | 685 | static int |
661 | f_audio_bind(struct usb_configuration *c, struct usb_function *f) | 686 | f_audio_bind(struct usb_configuration *c, struct usb_function *f) |
662 | { | 687 | { |
663 | struct usb_composite_dev *cdev = c->cdev; | 688 | struct usb_composite_dev *cdev = c->cdev; |
664 | struct f_audio *audio = func_to_audio(f); | 689 | struct f_audio *audio = func_to_audio(f); |
665 | int status; | 690 | int status; |
666 | struct usb_ep *ep = NULL; | 691 | struct usb_ep *ep = NULL; |
692 | #ifndef USBF_UAC1_INCLUDED | ||
693 | struct f_uac1_opts *audio_opts; | ||
694 | |||
695 | audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst); | ||
696 | audio->card.gadget = c->cdev->gadget; | ||
697 | audio_opts->card = &audio->card; | ||
698 | /* set up ASLA audio devices */ | ||
699 | if (!audio_opts->bound) { | ||
700 | status = gaudio_setup(&audio->card); | ||
701 | if (status < 0) | ||
702 | return status; | ||
703 | audio_opts->bound = true; | ||
704 | } | ||
705 | #else | ||
706 | audio->card.gadget = c->cdev->gadget; | ||
707 | #endif | ||
708 | if (strings_uac1[0].id == 0) { | ||
709 | status = usb_string_ids_tab(c->cdev, strings_uac1); | ||
710 | if (status < 0) | ||
711 | #ifdef USBF_UAC1_INCLUDED | ||
712 | return status; | ||
713 | #else | ||
714 | goto fail; | ||
715 | #endif | ||
716 | ac_interface_desc.iInterface = strings_uac1[STR_AC_IF].id; | ||
717 | input_terminal_desc.iTerminal = | ||
718 | strings_uac1[STR_INPUT_TERMINAL].id; | ||
719 | input_terminal_desc.iChannelNames = | ||
720 | strings_uac1[STR_INPUT_TERMINAL_CH_NAMES].id; | ||
721 | feature_unit_desc.iFeature = strings_uac1[STR_FEAT_DESC_0].id; | ||
722 | output_terminal_desc.iTerminal = | ||
723 | strings_uac1[STR_OUTPUT_TERMINAL].id; | ||
724 | as_interface_alt_0_desc.iInterface = | ||
725 | strings_uac1[STR_AS_IF_ALT0].id; | ||
726 | as_interface_alt_1_desc.iInterface = | ||
727 | strings_uac1[STR_AS_IF_ALT1].id; | ||
728 | } | ||
667 | 729 | ||
668 | f_audio_build_desc(audio); | 730 | f_audio_build_desc(audio); |
669 | 731 | ||
@@ -698,19 +760,24 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f) | |||
698 | return 0; | 760 | return 0; |
699 | 761 | ||
700 | fail: | 762 | fail: |
763 | #ifndef USBF_UAC1_INCLUDED | ||
764 | gaudio_cleanup(&audio->card); | ||
765 | #endif | ||
701 | if (ep) | 766 | if (ep) |
702 | ep->driver_data = NULL; | 767 | ep->driver_data = NULL; |
703 | return status; | 768 | return status; |
704 | } | 769 | } |
705 | 770 | ||
771 | #ifdef USBF_UAC1_INCLUDED | ||
706 | static void | 772 | static void |
707 | f_audio_unbind(struct usb_configuration *c, struct usb_function *f) | 773 | old_f_audio_unbind(struct usb_configuration *c, struct usb_function *f) |
708 | { | 774 | { |
709 | struct f_audio *audio = func_to_audio(f); | 775 | struct f_audio *audio = func_to_audio(f); |
710 | 776 | ||
711 | usb_free_all_descriptors(f); | 777 | usb_free_all_descriptors(f); |
712 | kfree(audio); | 778 | kfree(audio); |
713 | } | 779 | } |
780 | #endif | ||
714 | 781 | ||
715 | /*-------------------------------------------------------------------------*/ | 782 | /*-------------------------------------------------------------------------*/ |
716 | 783 | ||
@@ -727,7 +794,7 @@ static int generic_get_cmd(struct usb_audio_control *con, u8 cmd) | |||
727 | } | 794 | } |
728 | 795 | ||
729 | /* Todo: add more control selecotor dynamically */ | 796 | /* Todo: add more control selecotor dynamically */ |
730 | static int __init control_selector_init(struct f_audio *audio) | 797 | static int control_selector_init(struct f_audio *audio) |
731 | { | 798 | { |
732 | INIT_LIST_HEAD(&audio->cs); | 799 | INIT_LIST_HEAD(&audio->cs); |
733 | list_add(&feature_unit.list, &audio->cs); | 800 | list_add(&feature_unit.list, &audio->cs); |
@@ -744,6 +811,7 @@ static int __init control_selector_init(struct f_audio *audio) | |||
744 | return 0; | 811 | return 0; |
745 | } | 812 | } |
746 | 813 | ||
814 | #ifdef USBF_UAC1_INCLUDED | ||
747 | /** | 815 | /** |
748 | * audio_bind_config - add USB audio function to a configuration | 816 | * audio_bind_config - add USB audio function to a configuration |
749 | * @c: the configuration to supcard the USB audio function | 817 | * @c: the configuration to supcard the USB audio function |
@@ -756,24 +824,6 @@ static int __init audio_bind_config(struct usb_configuration *c) | |||
756 | struct f_audio *audio; | 824 | struct f_audio *audio; |
757 | int status; | 825 | int status; |
758 | 826 | ||
759 | if (strings_uac1[0].id == 0) { | ||
760 | status = usb_string_ids_tab(c->cdev, strings_uac1); | ||
761 | if (status < 0) | ||
762 | return status; | ||
763 | ac_interface_desc.iInterface = strings_uac1[STR_AC_IF].id; | ||
764 | input_terminal_desc.iTerminal = | ||
765 | strings_uac1[STR_INPUT_TERMINAL].id; | ||
766 | input_terminal_desc.iChannelNames = | ||
767 | strings_uac1[STR_INPUT_TERMINAL_CH_NAMES].id; | ||
768 | feature_unit_desc.iFeature = strings_uac1[STR_FEAT_DESC_0].id; | ||
769 | output_terminal_desc.iTerminal = | ||
770 | strings_uac1[STR_OUTPUT_TERMINAL].id; | ||
771 | as_interface_alt_0_desc.iInterface = | ||
772 | strings_uac1[STR_AS_IF_ALT0].id; | ||
773 | as_interface_alt_1_desc.iInterface = | ||
774 | strings_uac1[STR_AS_IF_ALT1].id; | ||
775 | } | ||
776 | |||
777 | /* allocate and initialize one new instance */ | 827 | /* allocate and initialize one new instance */ |
778 | audio = kzalloc(sizeof *audio, GFP_KERNEL); | 828 | audio = kzalloc(sizeof *audio, GFP_KERNEL); |
779 | if (!audio) | 829 | if (!audio) |
@@ -789,10 +839,9 @@ static int __init audio_bind_config(struct usb_configuration *c) | |||
789 | status = gaudio_setup(&audio->card); | 839 | status = gaudio_setup(&audio->card); |
790 | if (status < 0) | 840 | if (status < 0) |
791 | goto setup_fail; | 841 | goto setup_fail; |
792 | |||
793 | audio->card.func.strings = uac1_strings; | 842 | audio->card.func.strings = uac1_strings; |
794 | audio->card.func.bind = f_audio_bind; | 843 | audio->card.func.bind = f_audio_bind; |
795 | audio->card.func.unbind = f_audio_unbind; | 844 | audio->card.func.unbind = old_f_audio_unbind; |
796 | audio->card.func.set_alt = f_audio_set_alt; | 845 | audio->card.func.set_alt = f_audio_set_alt; |
797 | audio->card.func.setup = f_audio_setup; | 846 | audio->card.func.setup = f_audio_setup; |
798 | audio->card.func.disable = f_audio_disable; | 847 | audio->card.func.disable = f_audio_disable; |
@@ -816,3 +865,71 @@ setup_fail: | |||
816 | kfree(audio); | 865 | kfree(audio); |
817 | return status; | 866 | return status; |
818 | } | 867 | } |
868 | #else | ||
869 | static void f_audio_free_inst(struct usb_function_instance *f) | ||
870 | { | ||
871 | struct f_uac1_opts *opts; | ||
872 | |||
873 | opts = container_of(f, struct f_uac1_opts, func_inst); | ||
874 | gaudio_cleanup(opts->card); | ||
875 | kfree(opts); | ||
876 | } | ||
877 | |||
878 | static struct usb_function_instance *f_audio_alloc_inst(void) | ||
879 | { | ||
880 | struct f_uac1_opts *opts; | ||
881 | |||
882 | opts = kzalloc(sizeof(*opts), GFP_KERNEL); | ||
883 | if (!opts) | ||
884 | return ERR_PTR(-ENOMEM); | ||
885 | |||
886 | opts->func_inst.free_func_inst = f_audio_free_inst; | ||
887 | |||
888 | return &opts->func_inst; | ||
889 | } | ||
890 | |||
891 | static void f_audio_free(struct usb_function *f) | ||
892 | { | ||
893 | struct f_audio *audio = func_to_audio(f); | ||
894 | |||
895 | kfree(audio); | ||
896 | } | ||
897 | |||
898 | static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f) | ||
899 | { | ||
900 | usb_free_all_descriptors(f); | ||
901 | } | ||
902 | |||
903 | static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) | ||
904 | { | ||
905 | struct f_audio *audio; | ||
906 | |||
907 | /* allocate and initialize one new instance */ | ||
908 | audio = kzalloc(sizeof(*audio), GFP_KERNEL); | ||
909 | if (!audio) | ||
910 | return ERR_PTR(-ENOMEM); | ||
911 | |||
912 | audio->card.func.name = "g_audio"; | ||
913 | |||
914 | INIT_LIST_HEAD(&audio->play_queue); | ||
915 | spin_lock_init(&audio->lock); | ||
916 | |||
917 | audio->card.func.strings = uac1_strings; | ||
918 | audio->card.func.bind = f_audio_bind; | ||
919 | audio->card.func.unbind = f_audio_unbind; | ||
920 | audio->card.func.set_alt = f_audio_set_alt; | ||
921 | audio->card.func.setup = f_audio_setup; | ||
922 | audio->card.func.disable = f_audio_disable; | ||
923 | audio->card.func.free_func = f_audio_free; | ||
924 | |||
925 | control_selector_init(audio); | ||
926 | |||
927 | INIT_WORK(&audio->playback_work, f_audio_playback_work); | ||
928 | |||
929 | return &audio->card.func; | ||
930 | } | ||
931 | |||
932 | DECLARE_USB_FUNCTION_INIT(uac1, f_audio_alloc_inst, f_audio_alloc); | ||
933 | MODULE_LICENSE("GPL"); | ||
934 | MODULE_AUTHOR("Bryan Wu"); | ||
935 | #endif | ||
diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c index 7a55fea43430..9a55e5cf4cd8 100644 --- a/drivers/usb/gadget/function/u_uac1.c +++ b/drivers/usb/gadget/function/u_uac1.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/module.h> | ||
13 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
14 | #include <linux/device.h> | 15 | #include <linux/device.h> |
15 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
@@ -23,6 +24,7 @@ | |||
23 | * This component encapsulates the ALSA devices for USB audio gadget | 24 | * This component encapsulates the ALSA devices for USB audio gadget |
24 | */ | 25 | */ |
25 | 26 | ||
27 | #ifdef USBF_UAC1_INCLUDED | ||
26 | #define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p" | 28 | #define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p" |
27 | #define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c" | 29 | #define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c" |
28 | #define FILE_CONTROL "/dev/snd/controlC0" | 30 | #define FILE_CONTROL "/dev/snd/controlC0" |
@@ -38,7 +40,7 @@ MODULE_PARM_DESC(fn_cap, "Capture PCM device file name"); | |||
38 | static char *fn_cntl = FILE_CONTROL; | 40 | static char *fn_cntl = FILE_CONTROL; |
39 | module_param(fn_cntl, charp, S_IRUGO); | 41 | module_param(fn_cntl, charp, S_IRUGO); |
40 | MODULE_PARM_DESC(fn_cntl, "Control device file name"); | 42 | MODULE_PARM_DESC(fn_cntl, "Control device file name"); |
41 | 43 | #endif | |
42 | /*-------------------------------------------------------------------------*/ | 44 | /*-------------------------------------------------------------------------*/ |
43 | 45 | ||
44 | /** | 46 | /** |
@@ -167,7 +169,7 @@ static int playback_default_hw_params(struct gaudio_snd_dev *snd) | |||
167 | /** | 169 | /** |
168 | * Playback audio buffer data by ALSA PCM device | 170 | * Playback audio buffer data by ALSA PCM device |
169 | */ | 171 | */ |
170 | static size_t u_audio_playback(struct gaudio *card, void *buf, size_t count) | 172 | size_t u_audio_playback(struct gaudio *card, void *buf, size_t count) |
171 | { | 173 | { |
172 | struct gaudio_snd_dev *snd = &card->playback; | 174 | struct gaudio_snd_dev *snd = &card->playback; |
173 | struct snd_pcm_substream *substream = snd->substream; | 175 | struct snd_pcm_substream *substream = snd->substream; |
@@ -202,12 +204,12 @@ try_again: | |||
202 | return 0; | 204 | return 0; |
203 | } | 205 | } |
204 | 206 | ||
205 | static int u_audio_get_playback_channels(struct gaudio *card) | 207 | int u_audio_get_playback_channels(struct gaudio *card) |
206 | { | 208 | { |
207 | return card->playback.channels; | 209 | return card->playback.channels; |
208 | } | 210 | } |
209 | 211 | ||
210 | static int u_audio_get_playback_rate(struct gaudio *card) | 212 | int u_audio_get_playback_rate(struct gaudio *card) |
211 | { | 213 | { |
212 | return card->playback.rate; | 214 | return card->playback.rate; |
213 | } | 215 | } |
@@ -220,6 +222,15 @@ static int gaudio_open_snd_dev(struct gaudio *card) | |||
220 | { | 222 | { |
221 | struct snd_pcm_file *pcm_file; | 223 | struct snd_pcm_file *pcm_file; |
222 | struct gaudio_snd_dev *snd; | 224 | struct gaudio_snd_dev *snd; |
225 | #ifndef USBF_UAC1_INCLUDED | ||
226 | struct f_uac1_opts *opts; | ||
227 | char *fn_play, *fn_cap, *fn_cntl; | ||
228 | |||
229 | opts = container_of(card->func.fi, struct f_uac1_opts, func_inst); | ||
230 | fn_play = opts->fn_play; | ||
231 | fn_cap = opts->fn_cap; | ||
232 | fn_cntl = opts->fn_cntl; | ||
233 | #endif | ||
223 | 234 | ||
224 | if (!card) | 235 | if (!card) |
225 | return -ENODEV; | 236 | return -ENODEV; |
@@ -293,7 +304,9 @@ static int gaudio_close_snd_dev(struct gaudio *gau) | |||
293 | return 0; | 304 | return 0; |
294 | } | 305 | } |
295 | 306 | ||
307 | #ifdef USBF_UAC1_INCLUDED | ||
296 | static struct gaudio *the_card; | 308 | static struct gaudio *the_card; |
309 | #endif | ||
297 | /** | 310 | /** |
298 | * gaudio_setup - setup ALSA interface and preparing for USB transfer | 311 | * gaudio_setup - setup ALSA interface and preparing for USB transfer |
299 | * | 312 | * |
@@ -301,15 +314,17 @@ static struct gaudio *the_card; | |||
301 | * | 314 | * |
302 | * Returns negative errno, or zero on success | 315 | * Returns negative errno, or zero on success |
303 | */ | 316 | */ |
304 | int __init gaudio_setup(struct gaudio *card) | 317 | int gaudio_setup(struct gaudio *card) |
305 | { | 318 | { |
306 | int ret; | 319 | int ret; |
307 | 320 | ||
308 | ret = gaudio_open_snd_dev(card); | 321 | ret = gaudio_open_snd_dev(card); |
309 | if (ret) | 322 | if (ret) |
310 | ERROR(card, "we need at least one control device\n"); | 323 | ERROR(card, "we need at least one control device\n"); |
324 | #ifdef USBF_UAC1_INCLUDED | ||
311 | else if (!the_card) | 325 | else if (!the_card) |
312 | the_card = card; | 326 | the_card = card; |
327 | #endif | ||
313 | 328 | ||
314 | return ret; | 329 | return ret; |
315 | 330 | ||
@@ -320,11 +335,17 @@ int __init gaudio_setup(struct gaudio *card) | |||
320 | * | 335 | * |
321 | * This is called to free all resources allocated by @gaudio_setup(). | 336 | * This is called to free all resources allocated by @gaudio_setup(). |
322 | */ | 337 | */ |
338 | #ifdef USBF_UAC1_INCLUDED | ||
323 | void gaudio_cleanup(void) | 339 | void gaudio_cleanup(void) |
340 | #else | ||
341 | void gaudio_cleanup(struct gaudio *the_card) | ||
342 | #endif | ||
324 | { | 343 | { |
325 | if (the_card) { | 344 | if (the_card) { |
326 | gaudio_close_snd_dev(the_card); | 345 | gaudio_close_snd_dev(the_card); |
346 | #ifdef USBF_UAC1_INCLUDED | ||
327 | the_card = NULL; | 347 | the_card = NULL; |
348 | #endif | ||
328 | } | 349 | } |
329 | } | 350 | } |
330 | 351 | ||
diff --git a/drivers/usb/gadget/function/u_uac1.h b/drivers/usb/gadget/function/u_uac1.h index 18c2e729faf6..5b4fe9efb8f1 100644 --- a/drivers/usb/gadget/function/u_uac1.h +++ b/drivers/usb/gadget/function/u_uac1.h | |||
@@ -50,7 +50,27 @@ struct gaudio { | |||
50 | /* TODO */ | 50 | /* TODO */ |
51 | }; | 51 | }; |
52 | 52 | ||
53 | struct f_uac1_opts { | ||
54 | struct usb_function_instance func_inst; | ||
55 | int req_buf_size; | ||
56 | int req_count; | ||
57 | int audio_buf_size; | ||
58 | char *fn_play; | ||
59 | char *fn_cap; | ||
60 | char *fn_cntl; | ||
61 | bool bound; | ||
62 | struct gaudio *card; | ||
63 | }; | ||
64 | |||
53 | int gaudio_setup(struct gaudio *card); | 65 | int gaudio_setup(struct gaudio *card); |
66 | #ifdef USBF_UAC1_INCLUDED | ||
54 | void gaudio_cleanup(void); | 67 | void gaudio_cleanup(void); |
68 | #else | ||
69 | void gaudio_cleanup(struct gaudio *the_card); | ||
70 | #endif | ||
71 | |||
72 | size_t u_audio_playback(struct gaudio *card, void *buf, size_t count); | ||
73 | int u_audio_get_playback_channels(struct gaudio *card); | ||
74 | int u_audio_get_playback_rate(struct gaudio *card); | ||
55 | 75 | ||
56 | #endif /* __U_AUDIO_H */ | 76 | #endif /* __U_AUDIO_H */ |
diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c index 47a7de71f7fb..cf1a5434feaf 100644 --- a/drivers/usb/gadget/legacy/audio.c +++ b/drivers/usb/gadget/legacy/audio.c | |||
@@ -80,6 +80,7 @@ static struct usb_function *f_uac2; | |||
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | #ifdef CONFIG_GADGET_UAC1 | 82 | #ifdef CONFIG_GADGET_UAC1 |
83 | #define USBF_UAC1_INCLUDED | ||
83 | #include "u_uac1.h" | 84 | #include "u_uac1.h" |
84 | #include "f_uac1.c" | 85 | #include "f_uac1.c" |
85 | #endif | 86 | #endif |