]> git.karo-electronics.de Git - linux-beck.git/commitdiff
usb: gadget: push tty port allocation from gadget into f_acm
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Sun, 23 Dec 2012 20:10:18 +0000 (21:10 +0100)
committerFelipe Balbi <balbi@ti.com>
Wed, 3 Apr 2013 11:43:31 +0000 (14:43 +0300)
It possible to allocate the tty port number within the "instance"
structure of the function and there is no need to expose this
information within the gadget and therefore it is removed here.
This patch converts only f_acm and all its users. The other gadgets will
follow once the function is converted to the function interface.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/acm_ms.c
drivers/usb/gadget/cdc2.c
drivers/usb/gadget/f_acm.c
drivers/usb/gadget/multi.c
drivers/usb/gadget/nokia.c
drivers/usb/gadget/serial.c

index 8f2b0e391534f251a576fca2bbc1e18b511e1db2..4b947bb50f62acdd17bebee987b5b14faa26e253 100644 (file)
@@ -109,7 +109,6 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 static struct fsg_common fsg_common;
 
 /*-------------------------------------------------------------------------*/
-static unsigned char tty_line;
 static struct usb_function *f_acm;
 static struct usb_function_instance *f_acm_inst;
 /*
@@ -117,7 +116,6 @@ static struct usb_function_instance *f_acm_inst;
  */
 static int __init acm_ms_do_config(struct usb_configuration *c)
 {
-       struct f_serial_opts *opts;
        int     status;
 
        if (gadget_is_otg(c->cdev->gadget)) {
@@ -129,9 +127,6 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
        if (IS_ERR(f_acm_inst))
                return PTR_ERR(f_acm_inst);
 
-       opts = container_of(f_acm_inst, struct f_serial_opts, func_inst);
-       opts->port_num = tty_line;
-
        f_acm = usb_get_function(f_acm_inst);
        if (IS_ERR(f_acm)) {
                status = PTR_ERR(f_acm);
@@ -171,16 +166,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
        int                     status;
        void                    *retp;
 
-       /* set up serial link layer */
-       status = gserial_alloc_line(&tty_line);
-       if (status < 0)
-               return status;
-
        /* set up mass storage function */
        retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
        if (IS_ERR(retp)) {
                status = PTR_ERR(retp);
-               goto fail0;
+               return PTR_ERR(retp);
        }
 
        /*
@@ -207,8 +197,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
        /* error recovery */
 fail1:
        fsg_common_put(&fsg_common);
-fail0:
-       gserial_free_line(tty_line);
        return status;
 }
 
@@ -216,7 +204,6 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
 {
        usb_put_function(f_acm);
        usb_put_function_instance(f_acm_inst);
-       gserial_free_line(tty_line);
        return 0;
 }
 
index 61023aae98653c80a758cb39fd824e3426a5253a..c6ee6f1558c390454e13a0a2008e2a0836f407e2 100644 (file)
@@ -108,13 +108,11 @@ static struct eth_dev *the_dev;
 static struct usb_function *f_acm;
 static struct usb_function_instance *fi_serial;
 
-static unsigned char tty_line;
 /*
  * We _always_ have both CDC ECM and CDC ACM functions.
  */
 static int __init cdc_do_config(struct usb_configuration *c)
 {
-       struct f_serial_opts *opts;
        int     status;
 
        if (gadget_is_otg(c->cdev->gadget)) {
@@ -130,9 +128,6 @@ static int __init cdc_do_config(struct usb_configuration *c)
        if (IS_ERR(fi_serial))
                return PTR_ERR(fi_serial);
 
-       opts = container_of(fi_serial, struct f_serial_opts, func_inst);
-       opts->port_num = tty_line;
-
        f_acm = usb_get_function(fi_serial);
        if (IS_ERR(f_acm))
                goto err_func_acm;
@@ -173,11 +168,6 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
        if (IS_ERR(the_dev))
                return PTR_ERR(the_dev);
 
-       /* set up serial link layer */
-       status = gserial_alloc_line(&tty_line);
-       if (status < 0)
-               goto fail0;
-
        /* Allocate string descriptor numbers ... note that string
         * contents can be overridden by the composite_dev glue.
         */
@@ -200,8 +190,6 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
        return 0;
 
 fail1:
-       gserial_free_line(tty_line);
-fail0:
        gether_cleanup(the_dev);
        return status;
 }
@@ -210,7 +198,6 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
 {
        usb_put_function(f_acm);
        usb_put_function_instance(fi_serial);
-       gserial_free_line(tty_line);
        gether_cleanup(the_dev);
        return 0;
 }
index 61b33d23be72aac0359b9403baf7a661fd1cc6fe..ba7daaaad1480a3d2bf98b6d00b99dfc14278181 100644 (file)
@@ -768,17 +768,24 @@ static void acm_free_instance(struct usb_function_instance *fi)
        struct f_serial_opts *opts;
 
        opts = container_of(fi, struct f_serial_opts, func_inst);
+       gserial_free_line(opts->port_num);
        kfree(opts);
 }
 
 static struct usb_function_instance *acm_alloc_instance(void)
 {
        struct f_serial_opts *opts;
+       int ret;
 
        opts = kzalloc(sizeof(*opts), GFP_KERNEL);
        if (!opts)
                return ERR_PTR(-ENOMEM);
        opts->func_inst.free_func_inst = acm_free_instance;
+       ret = gserial_alloc_line(&opts->port_num);
+       if (ret) {
+               kfree(opts);
+               return ERR_PTR(ret);
+       }
        return &opts->func_inst;
 }
 DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func);
index 34427553271e9aea12807044c9ee72917c262c45..a74ebefc7682c7fe71ae4ec0153bdd7933c237b6 100644 (file)
@@ -135,7 +135,6 @@ static struct fsg_common fsg_common;
 
 static u8 hostaddr[ETH_ALEN];
 
-static unsigned char tty_line;
 static struct usb_function_instance *fi_acm;
 static struct eth_dev *the_dev;
 
@@ -270,7 +269,6 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
 static int __ref multi_bind(struct usb_composite_dev *cdev)
 {
        struct usb_gadget *gadget = cdev->gadget;
-       struct f_serial_opts *opts;
        int status;
 
        if (!can_support_ecm(cdev->gadget)) {
@@ -285,19 +283,12 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
                return PTR_ERR(the_dev);
 
        /* set up serial link layer */
-       status = gserial_alloc_line(&tty_line);
-       if (status < 0)
-               goto fail0;
-
        fi_acm = usb_get_function_instance("acm");
        if (IS_ERR(fi_acm)) {
                status = PTR_ERR(fi_acm);
-               goto fail0dot5;
+               goto fail0;
        }
 
-       opts = container_of(fi_acm, struct f_serial_opts, func_inst);
-       opts->port_num = tty_line;
-
        /* set up mass storage function */
        {
                void *retp;
@@ -335,8 +326,6 @@ fail2:
        fsg_common_put(&fsg_common);
 fail1:
        usb_put_function_instance(fi_acm);
-fail0dot5:
-       gserial_free_line(tty_line);
 fail0:
        gether_cleanup(the_dev);
        return status;
@@ -351,7 +340,6 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
        usb_put_function(f_acm_rndis);
 #endif
        usb_put_function_instance(fi_acm);
-       gserial_free_line(tty_line);
        gether_cleanup(the_dev);
        return 0;
 }
index 0c13ddd78bef8a833b7ba4d87c71d17b59f83f37..b5fbf1a1cb3c94ccb7a436da4a8e29f90a80171a 100644 (file)
@@ -104,7 +104,6 @@ static struct eth_dev *the_dev;
 enum {
        TTY_PORT_OBEX0,
        TTY_PORT_OBEX1,
-       TTY_PORT_ACM,
        TTY_PORTS_MAX,
 };
 
@@ -174,7 +173,6 @@ err_conf:
 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;
 
@@ -209,8 +207,6 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
        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,
index 68d7bb06ebcb83245658bbe6473892a529eb05b2..c48ca1eb5442a77ad106469eef622aae5c2b67b1 100644 (file)
@@ -169,15 +169,12 @@ static int serial_register_ports(struct usb_composite_dev *cdev,
                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])) {
@@ -212,12 +209,14 @@ out:
 static int __init gs_bind(struct usb_composite_dev *cdev)
 {
        int                     status;
-       int                     cur_line;
+       int                     cur_line = 0;
 
-       for (cur_line = 0; cur_line < n_ports; cur_line++) {
-               status = gserial_alloc_line(&tty_lines[cur_line]);
-               if (status)
-                       goto fail;
+       if (!use_acm) {
+               for (cur_line = 0; cur_line < n_ports; cur_line++) {
+                       status = gserial_alloc_line(&tty_lines[cur_line]);
+                       if (status)
+                               goto fail;
+               }
        }
 
        /* Allocate string descriptor numbers ... note that string
@@ -258,7 +257,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
 
 fail:
        cur_line--;
-       while (cur_line >= 0)
+       while (cur_line >= 0 && !use_acm)
                gserial_free_line(tty_lines[cur_line--]);
        return status;
 }
@@ -270,7 +269,8 @@ static int gs_unbind(struct usb_composite_dev *cdev)
        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]);
+               if (!use_acm)
+                       gserial_free_line(tty_lines[i]);
        }
        return 0;
 }