diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2012-12-23 21:10:07 +0100 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2013-01-21 20:52:43 +0200 |
commit | ff47f59467388104d369a441aa6996d257343775 (patch) | |
tree | 895601c59ad3b136817f0c1c944a2272fbd7a4a8 /drivers/usb/gadget/serial.c | |
parent | 19b10a8828a6cdd5a4e7e37babd5084d35641f87 (diff) |
usb: gadget: f_acm: convert to new function interface with backwards compatibility
This patch converts f_acm into a module which uses the new function
interface. It also converts one of its users that is g_serial to make
use of it. The other users of it (g_nokia for instance) are still using
the old include file system and should not notice the change at all. So
they can be converter later independently.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget/serial.c')
-rw-r--r-- | drivers/usb/gadget/serial.c | 83 |
1 files changed, 65 insertions, 18 deletions
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index a883562f6a8..68d7bb06ebc 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c @@ -36,7 +36,6 @@ * the runtime footprint, and giving us at least some parts of what * a "gcc --combine ... part1.c part2.c part3.c ... " build would. */ -#include "f_acm.c" #include "f_obex.c" #include "f_serial.c" @@ -129,16 +128,6 @@ MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); /*-------------------------------------------------------------------------*/ static unsigned char tty_lines[MAX_U_SERIAL_PORTS]; -static int __init serial_bind_acm_config(struct usb_configuration *c) -{ - unsigned i; - int status = 0; - - for (i = 0; i < n_ports && status == 0; i++) - status = acm_bind_config(c, tty_lines[i]); - return status; -} - static int __init serial_bind_obex_config(struct usb_configuration *c) { unsigned i; @@ -166,13 +155,58 @@ static struct usb_configuration serial_config_driver = { .bmAttributes = USB_CONFIG_ATT_SELFPOWER, }; -static int gs_unbind(struct usb_composite_dev *cdev) +static struct usb_function_instance *fi_serial[MAX_U_SERIAL_PORTS]; +static struct usb_function *f_serial[MAX_U_SERIAL_PORTS]; + +static int serial_register_ports(struct usb_composite_dev *cdev, + struct usb_configuration *c, const char *f_name) { int i; + int ret; + + ret = usb_add_config_only(cdev, c); + if (ret) + goto out; + + for (i = 0; i < n_ports; i++) { + struct f_serial_opts *opts; + + fi_serial[i] = usb_get_function_instance(f_name); + if (IS_ERR(fi_serial[i])) { + ret = PTR_ERR(fi_serial[i]); + goto fail; + } + opts = container_of(fi_serial[i], struct f_serial_opts, func_inst); + opts->port_num = tty_lines[i]; + + f_serial[i] = usb_get_function(fi_serial[i]); + if (IS_ERR(f_serial[i])) { + ret = PTR_ERR(f_serial[i]); + goto err_get_func; + } + + ret = usb_add_function(c, f_serial[i]); + if (ret) + goto err_add_func; + } - for (i = 0; i < n_ports; i++) - gserial_free_line(tty_lines[i]); return 0; + +err_add_func: + usb_put_function(f_serial[i]); +err_get_func: + usb_put_function_instance(fi_serial[i]); + +fail: + i--; + while (i >= 0) { + usb_remove_function(c, f_serial[i]); + usb_put_function(f_serial[i]); + usb_put_function_instance(fi_serial[i]); + i--; + } +out: + return ret; } static int __init gs_bind(struct usb_composite_dev *cdev) @@ -204,10 +238,11 @@ static int __init gs_bind(struct usb_composite_dev *cdev) } /* register our configuration */ - if (use_acm) - status = usb_add_config(cdev, &serial_config_driver, - serial_bind_acm_config); - else if (use_obex) + if (use_acm) { + status = serial_register_ports(cdev, &serial_config_driver, + "acm"); + usb_ep_autoconfig_reset(cdev->gadget); + } else if (use_obex) status = usb_add_config(cdev, &serial_config_driver, serial_bind_obex_config); else @@ -228,6 +263,18 @@ fail: return status; } +static int gs_unbind(struct usb_composite_dev *cdev) +{ + int i; + + for (i = 0; i < n_ports; i++) { + usb_put_function(f_serial[i]); + usb_put_function_instance(fi_serial[i]); + gserial_free_line(tty_lines[i]); + } + return 0; +} + static __refdata struct usb_composite_driver gserial_driver = { .name = "g_serial", .dev = &device_desc, |