diff options
Diffstat (limited to 'drivers/usb/gadget/legacy/audio.c')
-rw-r--r-- | drivers/usb/gadget/legacy/audio.c | 149 |
1 files changed, 139 insertions, 10 deletions
diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c index 6eb695e5e43a..f46a3956e43d 100644 --- a/drivers/usb/gadget/legacy/audio.c +++ b/drivers/usb/gadget/legacy/audio.c | |||
@@ -21,6 +21,66 @@ | |||
21 | 21 | ||
22 | USB_GADGET_COMPOSITE_OPTIONS(); | 22 | USB_GADGET_COMPOSITE_OPTIONS(); |
23 | 23 | ||
24 | #ifndef CONFIG_GADGET_UAC1 | ||
25 | #include "u_uac2.h" | ||
26 | |||
27 | /* Playback(USB-IN) Default Stereo - Fl/Fr */ | ||
28 | static int p_chmask = UAC2_DEF_PCHMASK; | ||
29 | module_param(p_chmask, uint, S_IRUGO); | ||
30 | MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); | ||
31 | |||
32 | /* Playback Default 48 KHz */ | ||
33 | static int p_srate = UAC2_DEF_PSRATE; | ||
34 | module_param(p_srate, uint, S_IRUGO); | ||
35 | MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); | ||
36 | |||
37 | /* Playback Default 16bits/sample */ | ||
38 | static int p_ssize = UAC2_DEF_PSSIZE; | ||
39 | module_param(p_ssize, uint, S_IRUGO); | ||
40 | MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)"); | ||
41 | |||
42 | /* Capture(USB-OUT) Default Stereo - Fl/Fr */ | ||
43 | static int c_chmask = UAC2_DEF_CCHMASK; | ||
44 | module_param(c_chmask, uint, S_IRUGO); | ||
45 | MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); | ||
46 | |||
47 | /* Capture Default 64 KHz */ | ||
48 | static int c_srate = UAC2_DEF_CSRATE; | ||
49 | module_param(c_srate, uint, S_IRUGO); | ||
50 | MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); | ||
51 | |||
52 | /* Capture Default 16bits/sample */ | ||
53 | static int c_ssize = UAC2_DEF_CSSIZE; | ||
54 | module_param(c_ssize, uint, S_IRUGO); | ||
55 | MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); | ||
56 | #else | ||
57 | #include "u_uac1.h" | ||
58 | |||
59 | static char *fn_play = FILE_PCM_PLAYBACK; | ||
60 | module_param(fn_play, charp, S_IRUGO); | ||
61 | MODULE_PARM_DESC(fn_play, "Playback PCM device file name"); | ||
62 | |||
63 | static char *fn_cap = FILE_PCM_CAPTURE; | ||
64 | module_param(fn_cap, charp, S_IRUGO); | ||
65 | MODULE_PARM_DESC(fn_cap, "Capture PCM device file name"); | ||
66 | |||
67 | static char *fn_cntl = FILE_CONTROL; | ||
68 | module_param(fn_cntl, charp, S_IRUGO); | ||
69 | MODULE_PARM_DESC(fn_cntl, "Control device file name"); | ||
70 | |||
71 | static int req_buf_size = UAC1_OUT_EP_MAX_PACKET_SIZE; | ||
72 | module_param(req_buf_size, int, S_IRUGO); | ||
73 | MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); | ||
74 | |||
75 | static int req_count = UAC1_REQ_COUNT; | ||
76 | module_param(req_count, int, S_IRUGO); | ||
77 | MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count"); | ||
78 | |||
79 | static int audio_buf_size = UAC1_AUDIO_BUF_SIZE; | ||
80 | module_param(audio_buf_size, int, S_IRUGO); | ||
81 | MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); | ||
82 | #endif | ||
83 | |||
24 | /* string IDs are assigned dynamically */ | 84 | /* string IDs are assigned dynamically */ |
25 | 85 | ||
26 | static struct usb_string strings_dev[] = { | 86 | static struct usb_string strings_dev[] = { |
@@ -40,12 +100,12 @@ static struct usb_gadget_strings *audio_strings[] = { | |||
40 | NULL, | 100 | NULL, |
41 | }; | 101 | }; |
42 | 102 | ||
43 | #ifdef CONFIG_GADGET_UAC1 | 103 | #ifndef CONFIG_GADGET_UAC1 |
44 | #include "u_uac1.h" | 104 | static struct usb_function_instance *fi_uac2; |
45 | #include "u_uac1.c" | 105 | static struct usb_function *f_uac2; |
46 | #include "f_uac1.c" | ||
47 | #else | 106 | #else |
48 | #include "f_uac2.c" | 107 | static struct usb_function_instance *fi_uac1; |
108 | static struct usb_function *f_uac1; | ||
49 | #endif | 109 | #endif |
50 | 110 | ||
51 | /*-------------------------------------------------------------------------*/ | 111 | /*-------------------------------------------------------------------------*/ |
@@ -109,6 +169,8 @@ static const struct usb_descriptor_header *otg_desc[] = { | |||
109 | 169 | ||
110 | static int __init audio_do_config(struct usb_configuration *c) | 170 | static int __init audio_do_config(struct usb_configuration *c) |
111 | { | 171 | { |
172 | int status; | ||
173 | |||
112 | /* FIXME alloc iConfiguration string, set it in c->strings */ | 174 | /* FIXME alloc iConfiguration string, set it in c->strings */ |
113 | 175 | ||
114 | if (gadget_is_otg(c->cdev->gadget)) { | 176 | if (gadget_is_otg(c->cdev->gadget)) { |
@@ -116,7 +178,31 @@ static int __init audio_do_config(struct usb_configuration *c) | |||
116 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; | 178 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
117 | } | 179 | } |
118 | 180 | ||
119 | audio_bind_config(c); | 181 | #ifdef CONFIG_GADGET_UAC1 |
182 | f_uac1 = usb_get_function(fi_uac1); | ||
183 | if (IS_ERR(f_uac1)) { | ||
184 | status = PTR_ERR(f_uac1); | ||
185 | return status; | ||
186 | } | ||
187 | |||
188 | status = usb_add_function(c, f_uac1); | ||
189 | if (status < 0) { | ||
190 | usb_put_function(f_uac1); | ||
191 | return status; | ||
192 | } | ||
193 | #else | ||
194 | f_uac2 = usb_get_function(fi_uac2); | ||
195 | if (IS_ERR(f_uac2)) { | ||
196 | status = PTR_ERR(f_uac2); | ||
197 | return status; | ||
198 | } | ||
199 | |||
200 | status = usb_add_function(c, f_uac2); | ||
201 | if (status < 0) { | ||
202 | usb_put_function(f_uac2); | ||
203 | return status; | ||
204 | } | ||
205 | #endif | ||
120 | 206 | ||
121 | return 0; | 207 | return 0; |
122 | } | 208 | } |
@@ -126,17 +212,47 @@ static struct usb_configuration audio_config_driver = { | |||
126 | .bConfigurationValue = 1, | 212 | .bConfigurationValue = 1, |
127 | /* .iConfiguration = DYNAMIC */ | 213 | /* .iConfiguration = DYNAMIC */ |
128 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, | 214 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
129 | #ifndef CONFIG_GADGET_UAC1 | ||
130 | .unbind = uac2_unbind_config, | ||
131 | #endif | ||
132 | }; | 215 | }; |
133 | 216 | ||
134 | /*-------------------------------------------------------------------------*/ | 217 | /*-------------------------------------------------------------------------*/ |
135 | 218 | ||
136 | static int __init audio_bind(struct usb_composite_dev *cdev) | 219 | static int __init audio_bind(struct usb_composite_dev *cdev) |
137 | { | 220 | { |
221 | #ifndef CONFIG_GADGET_UAC1 | ||
222 | struct f_uac2_opts *uac2_opts; | ||
223 | #else | ||
224 | struct f_uac1_opts *uac1_opts; | ||
225 | #endif | ||
138 | int status; | 226 | int status; |
139 | 227 | ||
228 | #ifndef CONFIG_GADGET_UAC1 | ||
229 | fi_uac2 = usb_get_function_instance("uac2"); | ||
230 | if (IS_ERR(fi_uac2)) | ||
231 | return PTR_ERR(fi_uac2); | ||
232 | #else | ||
233 | fi_uac1 = usb_get_function_instance("uac1"); | ||
234 | if (IS_ERR(fi_uac1)) | ||
235 | return PTR_ERR(fi_uac1); | ||
236 | #endif | ||
237 | |||
238 | #ifndef CONFIG_GADGET_UAC1 | ||
239 | uac2_opts = container_of(fi_uac2, struct f_uac2_opts, func_inst); | ||
240 | uac2_opts->p_chmask = p_chmask; | ||
241 | uac2_opts->p_srate = p_srate; | ||
242 | uac2_opts->p_ssize = p_ssize; | ||
243 | uac2_opts->c_chmask = c_chmask; | ||
244 | uac2_opts->c_srate = c_srate; | ||
245 | uac2_opts->c_ssize = c_ssize; | ||
246 | #else | ||
247 | uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst); | ||
248 | uac1_opts->fn_play = fn_play; | ||
249 | uac1_opts->fn_cap = fn_cap; | ||
250 | uac1_opts->fn_cntl = fn_cntl; | ||
251 | uac1_opts->req_buf_size = req_buf_size; | ||
252 | uac1_opts->req_count = req_count; | ||
253 | uac1_opts->audio_buf_size = audio_buf_size; | ||
254 | #endif | ||
255 | |||
140 | status = usb_string_ids_tab(cdev, strings_dev); | 256 | status = usb_string_ids_tab(cdev, strings_dev); |
141 | if (status < 0) | 257 | if (status < 0) |
142 | goto fail; | 258 | goto fail; |
@@ -152,13 +268,26 @@ static int __init audio_bind(struct usb_composite_dev *cdev) | |||
152 | return 0; | 268 | return 0; |
153 | 269 | ||
154 | fail: | 270 | fail: |
271 | #ifndef CONFIG_GADGET_UAC1 | ||
272 | usb_put_function_instance(fi_uac2); | ||
273 | #else | ||
274 | usb_put_function_instance(fi_uac1); | ||
275 | #endif | ||
155 | return status; | 276 | return status; |
156 | } | 277 | } |
157 | 278 | ||
158 | static int __exit audio_unbind(struct usb_composite_dev *cdev) | 279 | static int __exit audio_unbind(struct usb_composite_dev *cdev) |
159 | { | 280 | { |
160 | #ifdef CONFIG_GADGET_UAC1 | 281 | #ifdef CONFIG_GADGET_UAC1 |
161 | gaudio_cleanup(); | 282 | if (!IS_ERR_OR_NULL(f_uac1)) |
283 | usb_put_function(f_uac1); | ||
284 | if (!IS_ERR_OR_NULL(fi_uac1)) | ||
285 | usb_put_function_instance(fi_uac1); | ||
286 | #else | ||
287 | if (!IS_ERR_OR_NULL(f_uac2)) | ||
288 | usb_put_function(f_uac2); | ||
289 | if (!IS_ERR_OR_NULL(fi_uac2)) | ||
290 | usb_put_function_instance(fi_uac2); | ||
162 | #endif | 291 | #endif |
163 | return 0; | 292 | return 0; |
164 | } | 293 | } |