Commit 59835ad7 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Felipe Balbi

usb: gadget: multi: use function framework for ACM

This patch converts the acm_ms gadget to make use of the function
framework to request the ACM function.
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 29a6645f
...@@ -859,6 +859,7 @@ config USB_G_MULTI ...@@ -859,6 +859,7 @@ config USB_G_MULTI
select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
select USB_LIBCOMPOSITE select USB_LIBCOMPOSITE
select USB_U_SERIAL select USB_U_SERIAL
select USB_F_ACM
help help
The Multifunction Composite Gadget provides Ethernet (RNDIS The Multifunction Composite Gadget provides Ethernet (RNDIS
and/or CDC Ethernet), mass storage and ACM serial link and/or CDC Ethernet), mass storage and ACM serial link
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include "u_serial.h"
#if defined USB_ETH_RNDIS #if defined USB_ETH_RNDIS
# undef USB_ETH_RNDIS # undef USB_ETH_RNDIS
#endif #endif
...@@ -41,8 +42,6 @@ MODULE_LICENSE("GPL"); ...@@ -41,8 +42,6 @@ MODULE_LICENSE("GPL");
* a "gcc --combine ... part1.c part2.c part3.c ... " build would. * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
*/ */
#include "f_mass_storage.c" #include "f_mass_storage.c"
#define USB_FACM_INCLUDED
#include "f_acm.c"
#include "f_ecm.c" #include "f_ecm.c"
#include "f_subset.c" #include "f_subset.c"
...@@ -137,10 +136,12 @@ static struct fsg_common fsg_common; ...@@ -137,10 +136,12 @@ static struct fsg_common fsg_common;
static u8 hostaddr[ETH_ALEN]; static u8 hostaddr[ETH_ALEN];
static unsigned char tty_line; static unsigned char tty_line;
static struct usb_function_instance *fi_acm;
/********** RNDIS **********/ /********** RNDIS **********/
#ifdef USB_ETH_RNDIS #ifdef USB_ETH_RNDIS
static struct usb_function *f_acm_rndis;
static __init int rndis_do_config(struct usb_configuration *c) static __init int rndis_do_config(struct usb_configuration *c)
{ {
...@@ -155,15 +156,25 @@ static __init int rndis_do_config(struct usb_configuration *c) ...@@ -155,15 +156,25 @@ static __init int rndis_do_config(struct usb_configuration *c)
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = acm_bind_config(c, tty_line); f_acm_rndis = usb_get_function(fi_acm);
if (ret < 0) if (IS_ERR(f_acm_rndis))
return ret; goto err_func_acm;
ret = usb_add_function(c, f_acm_rndis);
if (ret)
goto err_conf;
ret = fsg_bind_config(c->cdev, c, &fsg_common); ret = fsg_bind_config(c->cdev, c, &fsg_common);
if (ret < 0) if (ret < 0)
return ret; goto err_fsg;
return 0; return 0;
err_fsg:
usb_remove_function(c, f_acm_rndis);
err_conf:
usb_put_function(f_acm_rndis);
err_func_acm:
return ret;
} }
static int rndis_config_register(struct usb_composite_dev *cdev) static int rndis_config_register(struct usb_composite_dev *cdev)
...@@ -192,6 +203,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev) ...@@ -192,6 +203,7 @@ static int rndis_config_register(struct usb_composite_dev *cdev)
/********** CDC ECM **********/ /********** CDC ECM **********/
#ifdef CONFIG_USB_G_MULTI_CDC #ifdef CONFIG_USB_G_MULTI_CDC
static struct usb_function *f_acm_multi;
static __init int cdc_do_config(struct usb_configuration *c) static __init int cdc_do_config(struct usb_configuration *c)
{ {
...@@ -206,15 +218,26 @@ static __init int cdc_do_config(struct usb_configuration *c) ...@@ -206,15 +218,26 @@ static __init int cdc_do_config(struct usb_configuration *c)
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = acm_bind_config(c, tty_line); /* implicit port_num is zero */
if (ret < 0) f_acm_multi = usb_get_function(fi_acm);
return ret; if (IS_ERR(f_acm_multi))
goto err_func_acm;
ret = usb_add_function(c, f_acm_multi);
if (ret)
goto err_conf;
ret = fsg_bind_config(c->cdev, c, &fsg_common); ret = fsg_bind_config(c->cdev, c, &fsg_common);
if (ret < 0) if (ret < 0)
return ret; goto err_fsg;
return 0; return 0;
err_fsg:
usb_remove_function(c, f_acm_multi);
err_conf:
usb_put_function(f_acm_multi);
err_func_acm:
return ret;
} }
static int cdc_config_register(struct usb_composite_dev *cdev) static int cdc_config_register(struct usb_composite_dev *cdev)
...@@ -246,6 +269,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev) ...@@ -246,6 +269,7 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
static int __ref multi_bind(struct usb_composite_dev *cdev) static int __ref multi_bind(struct usb_composite_dev *cdev)
{ {
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
struct f_serial_opts *opts;
int status; int status;
if (!can_support_ecm(cdev->gadget)) { if (!can_support_ecm(cdev->gadget)) {
...@@ -264,6 +288,15 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -264,6 +288,15 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
if (status < 0) if (status < 0)
goto fail0; goto fail0;
fi_acm = usb_get_function_instance("acm");
if (IS_ERR(fi_acm)) {
status = PTR_ERR(fi_acm);
goto fail0dot5;
}
opts = container_of(fi_acm, struct f_serial_opts, func_inst);
opts->port_num = tty_line;
/* set up mass storage function */ /* set up mass storage function */
{ {
void *retp; void *retp;
...@@ -300,6 +333,8 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -300,6 +333,8 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
fail2: fail2:
fsg_common_put(&fsg_common); fsg_common_put(&fsg_common);
fail1: fail1:
usb_put_function_instance(fi_acm);
fail0dot5:
gserial_free_line(tty_line); gserial_free_line(tty_line);
fail0: fail0:
gether_cleanup(); gether_cleanup();
...@@ -308,6 +343,13 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) ...@@ -308,6 +343,13 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
static int __exit multi_unbind(struct usb_composite_dev *cdev) static int __exit multi_unbind(struct usb_composite_dev *cdev)
{ {
#ifdef CONFIG_USB_G_MULTI_CDC
usb_put_function(f_acm_multi);
#endif
#ifdef USB_ETH_RNDIS
usb_put_function(f_acm_rndis);
#endif
usb_put_function_instance(fi_acm);
gserial_free_line(tty_line); gserial_free_line(tty_line);
gether_cleanup(); gether_cleanup();
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment