[PATCH v3 20/42] usb/gadget: cdc2: convert to new interface of f_ecm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
 drivers/usb/gadget/Kconfig |    1 +
 drivers/usb/gadget/cdc2.c  |   57 +++++++++++++++++++++++++++++++------------
 2 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index eb53344..4d97a72 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -896,6 +896,7 @@ config USB_CDC_COMPOSITE
 	select USB_U_SERIAL
 	select USB_U_ETHER
 	select USB_F_ACM
+	select USB_F_ECM
 	help
 	  This driver provides two functions in one configuration:
 	  a CDC Ethernet (ECM) link, and a CDC ACM (serial port) link.
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 17e30df..92c2d58 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -15,6 +15,7 @@
 
 #include "u_ether.h"
 #include "u_serial.h"
+#include "u_ecm.h"
 
 
 #define DRIVER_DESC		"CDC Composite Gadget"
@@ -32,19 +33,8 @@
 #define CDC_VENDOR_NUM		0x0525	/* NetChip */
 #define CDC_PRODUCT_NUM		0xa4aa	/* CDC Composite: ECM + ACM */
 
-/*-------------------------------------------------------------------------*/
 USB_GADGET_COMPOSITE_OPTIONS();
 
-/*
- * Kbuild is not very cooperative with respect to linking separately
- * compiled library objects into one module.  So for now we won't use
- * separate compilation ... ensuring init/exit sections work to shrink
- * 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_FECM_INCLUDED
-#include "f_ecm.c"
-
 /*-------------------------------------------------------------------------*/
 
 static struct usb_device_descriptor device_desc = {
@@ -108,11 +98,15 @@ static struct eth_dev *the_dev;
 static struct usb_function *f_acm;
 static struct usb_function_instance *fi_serial;
 
+static struct usb_function_instance *f_ecm_inst;
+static struct usb_function *f_ecm;
+
 /*
  * We _always_ have both CDC ECM and CDC ACM functions.
  */
 static int __init cdc_do_config(struct usb_configuration *c)
 {
+	struct f_ecm_opts *ecm_opts;
 	int	status;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
@@ -120,26 +114,53 @@ static int __init cdc_do_config(struct usb_configuration *c)
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
 
-	status = ecm_bind_config(c, hostaddr, the_dev);
+	f_ecm_inst = usb_get_function_instance("ecm");
+	if (IS_ERR(f_ecm_inst))
+		return PTR_ERR(f_ecm_inst);
+
+	ecm_opts = container_of(f_ecm_inst, struct f_ecm_opts, func_inst);
+	ecm_opts->ethaddr = hostaddr;
+	ecm_opts->dev = the_dev;
+
+	f_ecm = usb_get_function(f_ecm_inst);
+	if (IS_ERR(f_ecm)) {
+		status = PTR_ERR(f_ecm);
+
+		goto err_get_ecm;
+	}
+	status = usb_add_function(c, f_ecm);
 	if (status < 0)
-		return status;
+		goto err_add_ecm;
 
 	fi_serial = usb_get_function_instance("acm");
-	if (IS_ERR(fi_serial))
-		return PTR_ERR(fi_serial);
+	if (IS_ERR(fi_serial)) {
+		status = PTR_ERR(fi_serial);
+
+		goto err_get_acm;
+	}
 
 	f_acm = usb_get_function(fi_serial);
-	if (IS_ERR(f_acm))
+	if (IS_ERR(f_acm)) {
+		status = PTR_ERR(f_acm);
+
 		goto err_func_acm;
+	}
 
 	status = usb_add_function(c, f_acm);
 	if (status)
 		goto err_conf;
 	return 0;
+
 err_conf:
 	usb_put_function(f_acm);
 err_func_acm:
 	usb_put_function_instance(fi_serial);
+err_get_acm:
+	usb_remove_function(c, f_ecm);
+err_add_ecm:
+	usb_put_function(f_ecm);
+err_get_ecm:
+	usb_put_function_instance(f_ecm_inst);
 	return status;
 }
 
@@ -198,6 +219,10 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
 {
 	usb_put_function(f_acm);
 	usb_put_function_instance(fi_serial);
+	if (!IS_ERR_OR_NULL(f_ecm))
+		usb_put_function(f_ecm);
+	if (!IS_ERR_OR_NULL(f_ecm_inst))
+		usb_put_function_instance(f_ecm_inst);
 	gether_cleanup(the_dev);
 	return 0;
 }
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux