usb: gadget: nokia: use function framework for ACM
This patch converts the acm_ms gadget to make use of the function
framework to request the ACM function.
The "old" include interface for acm is now removed since nokia was the
last user of it (for ACM).
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 1deadde..e1d3e08 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -831,6 +831,7 @@
depends on PHONET
select USB_LIBCOMPOSITE
select USB_U_SERIAL
+ select USB_F_ACM
help
The Nokia composite gadget provides support for acm, obex
and phonet in only one composite gadget driver.
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 1ae180b..61b33d2 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -715,72 +715,6 @@
return status;
}
-static struct f_acm *acm_alloc_basic_func(void)
-{
- struct f_acm *acm;
-
- acm = kzalloc(sizeof(*acm), GFP_KERNEL);
- if (!acm)
- return NULL;
-
- spin_lock_init(&acm->lock);
-
- acm->port.connect = acm_connect;
- acm->port.disconnect = acm_disconnect;
- acm->port.send_break = acm_send_break;
-
- acm->port.func.name = "acm";
- /* descriptors are per-instance copies */
- acm->port.func.bind = acm_bind;
- acm->port.func.set_alt = acm_set_alt;
- acm->port.func.setup = acm_setup;
- acm->port.func.disable = acm_disable;
-
- return acm;
-}
-
-#ifdef USB_FACM_INCLUDED
-static void
-acm_old_unbind(struct usb_configuration *c, struct usb_function *f)
-{
- struct f_acm *acm = func_to_acm(f);
-
- usb_free_all_descriptors(f);
- if (acm->notify_req)
- gs_free_req(acm->notify, acm->notify_req);
- kfree(acm);
-}
-
-/**
- * acm_bind_config - add a CDC ACM function to a configuration
- * @c: the configuration to support the CDC ACM instance
- * @port_num: /dev/ttyGS* port this interface will use
- * Context: single threaded during gadget setup
- *
- * Returns zero on success, else negative errno.
- *
- */
-int acm_bind_config(struct usb_configuration *c, u8 port_num)
-{
- struct f_acm *acm;
- int status;
-
- /* allocate and initialize one new instance */
- acm = acm_alloc_basic_func();
- if (!acm)
- return -ENOMEM;
-
- acm->port_num = port_num;
- acm->port.func.unbind = acm_old_unbind;
-
- status = usb_add_function(c, &acm->port.func);
- if (status)
- kfree(acm);
- return status;
-}
-
-#else
-
static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
{
struct f_acm *acm = func_to_acm(f);
@@ -803,10 +737,24 @@
struct f_serial_opts *opts;
struct f_acm *acm;
- acm = acm_alloc_basic_func();
+ acm = kzalloc(sizeof(*acm), GFP_KERNEL);
if (!acm)
return ERR_PTR(-ENOMEM);
+ spin_lock_init(&acm->lock);
+
+ acm->port.connect = acm_connect;
+ acm->port.disconnect = acm_disconnect;
+ acm->port.send_break = acm_send_break;
+
+ acm->port.func.name = "acm";
+ acm->port.func.strings = acm_strings;
+ /* descriptors are per-instance copies */
+ acm->port.func.bind = acm_bind;
+ acm->port.func.set_alt = acm_set_alt;
+ acm->port.func.setup = acm_setup;
+ acm->port.func.disable = acm_disable;
+
opts = container_of(fi, struct f_serial_opts, func_inst);
acm->port_num = opts->port_num;
acm->port.func.unbind = acm_unbind;
@@ -835,4 +783,3 @@
}
DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func);
MODULE_LICENSE("GPL");
-#endif
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index def3740..c3ad777 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -37,8 +37,6 @@
* the runtime footprint, and giving us at least some parts of what
* a "gcc --combine ... part1.c part2.c part3.c ... " build would.
*/
-#define USB_FACM_INCLUDED
-#include "f_acm.c"
#include "f_ecm.c"
#include "f_obex.c"
#include "f_serial.c"
@@ -98,7 +96,8 @@
MODULE_LICENSE("GPL");
/*-------------------------------------------------------------------------*/
-
+static struct usb_function *f_acm_cfg1;
+static struct usb_function *f_acm_cfg2;
static u8 hostaddr[ETH_ALEN];
enum {
@@ -110,33 +109,6 @@
static unsigned char tty_lines[TTY_PORTS_MAX];
-static int __init nokia_bind_config(struct usb_configuration *c)
-{
- int status = 0;
-
- status = phonet_bind_config(c);
- if (status)
- printk(KERN_DEBUG "could not bind phonet config\n");
-
- status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX0]);
- if (status)
- printk(KERN_DEBUG "could not bind obex config %d\n", 0);
-
- status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX1]);
- if (status)
- printk(KERN_DEBUG "could not bind obex config %d\n", 0);
-
- status = acm_bind_config(c, tty_lines[TTY_PORT_ACM]);
- if (status)
- printk(KERN_DEBUG "could not bind acm config\n");
-
- status = ecm_bind_config(c, hostaddr);
- if (status)
- printk(KERN_DEBUG "could not bind ecm config\n");
-
- return status;
-}
-
static struct usb_configuration nokia_config_500ma_driver = {
.label = "Bus Powered",
.bConfigurationValue = 1,
@@ -153,9 +125,55 @@
.MaxPower = 100,
};
+static struct usb_function_instance *fi_acm;
+
+static int __init nokia_bind_config(struct usb_configuration *c)
+{
+ struct usb_function *f_acm;
+ int status = 0;
+
+ status = phonet_bind_config(c);
+ if (status)
+ printk(KERN_DEBUG "could not bind phonet config\n");
+
+ status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX0]);
+ if (status)
+ printk(KERN_DEBUG "could not bind obex config %d\n", 0);
+
+ status = obex_bind_config(c, tty_lines[TTY_PORT_OBEX1]);
+ if (status)
+ printk(KERN_DEBUG "could not bind obex config %d\n", 0);
+
+ f_acm = usb_get_function(fi_acm);
+ if (IS_ERR(f_acm))
+ return PTR_ERR(f_acm);
+
+ status = usb_add_function(c, f_acm);
+ if (status)
+ goto err_conf;
+
+ status = ecm_bind_config(c, hostaddr);
+ if (status) {
+ pr_debug("could not bind ecm config %d\n", status);
+ goto err_ecm;
+ }
+ if (c == &nokia_config_500ma_driver)
+ f_acm_cfg1 = f_acm;
+ else
+ f_acm_cfg2 = f_acm;
+
+ return status;
+err_ecm:
+ usb_remove_function(c, f_acm);
+err_conf:
+ usb_put_function(f_acm);
+ return status;
+}
+
static int __init nokia_bind(struct usb_composite_dev *cdev)
{
struct usb_gadget *gadget = cdev->gadget;
+ struct f_serial_opts *opts;
int status;
int cur_line;
@@ -185,22 +203,32 @@
if (!gadget_supports_altsettings(gadget))
goto err_usb;
+ fi_acm = usb_get_function_instance("acm");
+ if (IS_ERR(fi_acm))
+ goto err_usb;
+ opts = container_of(fi_acm, struct f_serial_opts, func_inst);
+ opts->port_num = tty_lines[TTY_PORT_ACM];
+
/* finally register the configuration */
status = usb_add_config(cdev, &nokia_config_500ma_driver,
nokia_bind_config);
if (status < 0)
- goto err_usb;
+ goto err_acm_inst;
status = usb_add_config(cdev, &nokia_config_100ma_driver,
nokia_bind_config);
if (status < 0)
- goto err_usb;
+ goto err_put_cfg1;
usb_composite_overwrite_options(cdev, &coverwrite);
dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
return 0;
+err_put_cfg1:
+ usb_put_function(f_acm_cfg1);
+err_acm_inst:
+ usb_put_function_instance(fi_acm);
err_usb:
gether_cleanup();
err_ether:
@@ -217,6 +245,9 @@
{
int i;
+ usb_put_function(f_acm_cfg1);
+ usb_put_function(f_acm_cfg2);
+ usb_put_function_instance(fi_acm);
gphonet_cleanup();
for (i = 0; i < TTY_PORTS_MAX; i++)
@@ -247,4 +278,3 @@
usb_composite_unregister(&nokia_driver);
}
module_exit(nokia_cleanup);
-
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h
index 66ce73a..c20210c 100644
--- a/drivers/usb/gadget/u_serial.h
+++ b/drivers/usb/gadget/u_serial.h
@@ -65,7 +65,6 @@
void gserial_disconnect(struct gserial *);
/* functions are bound to configurations by a config or gadget driver */
-int acm_bind_config(struct usb_configuration *c, u8 port_num);
int gser_bind_config(struct usb_configuration *c, u8 port_num);
int obex_bind_config(struct usb_configuration *c, u8 port_num);