diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2012-12-23 15:10:01 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2013-01-21 13:52:40 -0500 |
commit | cf9a08ae5aece88987bbeee8eb0dd0ebb5015815 (patch) | |
tree | bbc7e204bd532b6ff84586653f57bc7ec6bf6380 /drivers/usb/gadget/f_loopback.c | |
parent | de53c25447117eae6b3f8952f663f08a09e0dbb7 (diff) |
usb: gadget: convert source sink and loopback to new function interface
This patch converts the f_sourcesink and f_loopback file to the USB-function
module. Both functions shares a few common utility functions which are
currently implemented in g_zero.c itself. This patch moves the common
code into the sourcesink file and creates one module out of the the two
functions (source sink and loop back).
The g_zero gadget is function specific to source sink and loop back to
set a few options. This Symbol dependency enforces a modul load right
now.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/f_loopback.c')
-rw-r--r-- | drivers/usb/gadget/f_loopback.c | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c index 3d103a2f998f..4a3873a0f2d0 100644 --- a/drivers/usb/gadget/f_loopback.c +++ b/drivers/usb/gadget/f_loopback.c | |||
@@ -15,10 +15,11 @@ | |||
15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
17 | #include <linux/device.h> | 17 | #include <linux/device.h> |
18 | #include <linux/module.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/usb/composite.h> | ||
18 | 21 | ||
19 | #include "g_zero.h" | 22 | #include "g_zero.h" |
20 | #include "gadget_chips.h" | ||
21 | |||
22 | 23 | ||
23 | /* | 24 | /* |
24 | * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, | 25 | * LOOPBACK FUNCTION ... a testing vehicle for USB peripherals, |
@@ -44,9 +45,8 @@ static inline struct f_loopback *func_to_loop(struct usb_function *f) | |||
44 | return container_of(f, struct f_loopback, function); | 45 | return container_of(f, struct f_loopback, function); |
45 | } | 46 | } |
46 | 47 | ||
47 | static unsigned qlen = 32; | 48 | static unsigned qlen; |
48 | module_param(qlen, uint, 0); | 49 | static unsigned buflen; |
49 | MODULE_PARM_DESC(qlenn, "depth of loopback queue"); | ||
50 | 50 | ||
51 | /*-------------------------------------------------------------------------*/ | 51 | /*-------------------------------------------------------------------------*/ |
52 | 52 | ||
@@ -171,8 +171,7 @@ static struct usb_gadget_strings *loopback_strings[] = { | |||
171 | 171 | ||
172 | /*-------------------------------------------------------------------------*/ | 172 | /*-------------------------------------------------------------------------*/ |
173 | 173 | ||
174 | static int __init | 174 | static int loopback_bind(struct usb_configuration *c, struct usb_function *f) |
175 | loopback_bind(struct usb_configuration *c, struct usb_function *f) | ||
176 | { | 175 | { |
177 | struct usb_composite_dev *cdev = c->cdev; | 176 | struct usb_composite_dev *cdev = c->cdev; |
178 | struct f_loopback *loop = func_to_loop(f); | 177 | struct f_loopback *loop = func_to_loop(f); |
@@ -229,8 +228,7 @@ autoconf_fail: | |||
229 | return 0; | 228 | return 0; |
230 | } | 229 | } |
231 | 230 | ||
232 | static void | 231 | static void lb_free_func(struct usb_function *f) |
233 | loopback_unbind(struct usb_configuration *c, struct usb_function *f) | ||
234 | { | 232 | { |
235 | usb_free_all_descriptors(f); | 233 | usb_free_all_descriptors(f); |
236 | kfree(func_to_loop(f)); | 234 | kfree(func_to_loop(f)); |
@@ -372,25 +370,64 @@ static void loopback_disable(struct usb_function *f) | |||
372 | disable_loopback(loop); | 370 | disable_loopback(loop); |
373 | } | 371 | } |
374 | 372 | ||
375 | /*-------------------------------------------------------------------------*/ | 373 | static struct usb_function *loopback_alloc(struct usb_function_instance *fi) |
376 | |||
377 | static int __init loopback_bind_config(struct usb_configuration *c) | ||
378 | { | 374 | { |
379 | struct f_loopback *loop; | 375 | struct f_loopback *loop; |
380 | int status; | 376 | struct f_lb_opts *lb_opts; |
381 | 377 | ||
382 | loop = kzalloc(sizeof *loop, GFP_KERNEL); | 378 | loop = kzalloc(sizeof *loop, GFP_KERNEL); |
383 | if (!loop) | 379 | if (!loop) |
384 | return -ENOMEM; | 380 | return ERR_PTR(-ENOMEM); |
381 | |||
382 | lb_opts = container_of(fi, struct f_lb_opts, func_inst); | ||
383 | buflen = lb_opts->bulk_buflen; | ||
384 | qlen = lb_opts->qlen; | ||
385 | if (!qlen) | ||
386 | qlen = 32; | ||
385 | 387 | ||
386 | loop->function.name = "loopback"; | 388 | loop->function.name = "loopback"; |
387 | loop->function.bind = loopback_bind; | 389 | loop->function.bind = loopback_bind; |
388 | loop->function.unbind = loopback_unbind; | ||
389 | loop->function.set_alt = loopback_set_alt; | 390 | loop->function.set_alt = loopback_set_alt; |
390 | loop->function.disable = loopback_disable; | 391 | loop->function.disable = loopback_disable; |
392 | loop->function.strings = loopback_strings; | ||
393 | |||
394 | loop->function.free_func = lb_free_func; | ||
395 | |||
396 | return &loop->function; | ||
397 | } | ||
398 | |||
399 | static void lb_free_instance(struct usb_function_instance *fi) | ||
400 | { | ||
401 | struct f_lb_opts *lb_opts; | ||
391 | 402 | ||
392 | status = usb_add_function(c, &loop->function); | 403 | lb_opts = container_of(fi, struct f_lb_opts, func_inst); |
393 | if (status) | 404 | kfree(lb_opts); |
394 | kfree(loop); | ||
395 | return status; | ||
396 | } | 405 | } |
406 | |||
407 | static struct usb_function_instance *loopback_alloc_instance(void) | ||
408 | { | ||
409 | struct f_lb_opts *lb_opts; | ||
410 | |||
411 | lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); | ||
412 | if (!lb_opts) | ||
413 | return ERR_PTR(-ENOMEM); | ||
414 | lb_opts->func_inst.free_func_inst = lb_free_instance; | ||
415 | return &lb_opts->func_inst; | ||
416 | } | ||
417 | DECLARE_USB_FUNCTION(Loopback, loopback_alloc_instance, loopback_alloc); | ||
418 | |||
419 | int __init lb_modinit(void) | ||
420 | { | ||
421 | int ret; | ||
422 | |||
423 | ret = usb_function_register(&Loopbackusb_func); | ||
424 | if (ret) | ||
425 | return ret; | ||
426 | return ret; | ||
427 | } | ||
428 | void __exit lb_modexit(void) | ||
429 | { | ||
430 | usb_function_unregister(&Loopbackusb_func); | ||
431 | } | ||
432 | |||
433 | MODULE_LICENSE("GPL"); | ||