This patch adds some ifdefs to make the ether gadget work
        as a usb_function module.

Signed-off-by: Felipe Balbi <[EMAIL PROTECTED]>
Signed-off-by: Ragner Magalhes <[EMAIL PROTECTED]>
---
Index: linux-2.6/drivers/usb/gadget/ether.c
===================================================================
--- linux-2.6.orig/drivers/usb/gadget/ether.c
+++ linux-2.6/drivers/usb/gadget/ether.c
@@ -51,2 +51,3 @@
 #include <linux/usb_gadget.h>
+#include <linux/usb/composite.h>
 
@@ -414,2 +415,8 @@ static inline int BITRATE(struct usb_gad
 
+#ifdef USB_COMPOSITE_DEVICE
+#define STRING_DATA                    1
+#define STRING_ETHADDR                 2
+#define STRING_CONTROL                 3
+#define STRING_RNDIS_CONTROL           4
+#else
 #define STRING_MANUFACTURER            1
@@ -424,2 +431,3 @@ static inline int BITRATE(struct usb_gad
 #define STRING_SERIALNUMBER            10
+#endif /* USB_COMPOSITE_DEVICE */
 
@@ -442,2 +450,4 @@ static inline int BITRATE(struct usb_gad
 
+#ifndef USB_COMPOSITE_DEVICE
+/* if defined composite, get the device descriptor from composite */
 static struct usb_device_descriptor
@@ -459,2 +469,3 @@ device_desc = {
 };
+#endif /* !USB_COMPOSITE_DEVICE */
 
@@ -468,2 +479,4 @@ otg_descriptor = {
 
+#ifndef USB_COMPOSITE_DEVICE
+/* if defined composite get the config descriptor from composite */
 static struct usb_config_descriptor
@@ -495,2 +508,4 @@ rndis_config = {
 #endif
+#endif /* !USB_COMPOSITE_DEVICE */
+
 
@@ -532,3 +547,3 @@ control_intf = {
 #ifdef CONFIG_USB_ETH_RNDIS
-static const struct usb_interface_descriptor
+static struct usb_interface_descriptor
 rndis_control_intf = {
@@ -556,3 +571,3 @@ static const struct usb_cdc_header_desc 
 
-static const struct usb_cdc_union_desc union_desc = {
+static struct usb_cdc_union_desc union_desc = {
        .bLength =              sizeof union_desc,
@@ -672,3 +687,3 @@ fs_status_desc = {
 
-static const struct usb_interface_descriptor
+static struct usb_interface_descriptor
 data_nop_intf = {
@@ -683,2 +698,3 @@ data_nop_intf = {
        .bInterfaceProtocol =   0,
+       .iInterface =           STRING_DATA,
 };
@@ -687,3 +703,3 @@ data_nop_intf = {
 
-static const struct usb_interface_descriptor
+static struct usb_interface_descriptor
 data_intf = {
@@ -707,3 +723,3 @@ data_intf = {
 
-static const struct usb_interface_descriptor
+static struct usb_interface_descriptor
 rndis_data_intf = {
@@ -733,3 +749,3 @@ rndis_data_intf = {
 
-static const struct usb_interface_descriptor
+static struct usb_interface_descriptor
 subset_data_intf = {
@@ -768,3 +784,3 @@ fs_sink_desc = {
 
-static const struct usb_descriptor_header *fs_eth_function [11] = {
+static struct usb_descriptor_header *fs_eth_function [11] = {
        (struct usb_descriptor_header *) &otg_descriptor,
@@ -805,3 +821,3 @@ static inline void __init fs_subset_desc
 #ifdef CONFIG_USB_ETH_RNDIS
-static const struct usb_descriptor_header *fs_rndis_function [] = {
+static struct usb_descriptor_header *fs_rndis_function [] = {
        (struct usb_descriptor_header *) &otg_descriptor,
@@ -859,2 +875,3 @@ hs_sink_desc = {
 
+#ifndef USB_COMPOSITE_DEVICE
 static struct usb_qualifier_descriptor
@@ -869,4 +886,5 @@ dev_qualifier = {
 };
+#endif /* !USB_COMPOSITE_DEVICE */
 
-static const struct usb_descriptor_header *hs_eth_function [11] = {
+static struct usb_descriptor_header *hs_eth_function [11] = {
        (struct usb_descriptor_header *) &otg_descriptor,
@@ -944,4 +962,6 @@ static inline void __init hs_subset_desc
 static char                            manufacturer [50];
+#ifndef USB_COMPOSITE_DEVICE
 static char                            product_desc [40] = DRIVER_DESC;
 static char                            serial_number [20];
+#endif /* !USB_COMPOSITE_DEVICE */
 
@@ -952,2 +972,13 @@ static char                                ethaddr [2 * 
ETH_ALEN + 1
 static struct usb_string               strings [] = {
+       /* ifdef composite */
+#ifdef USB_COMPOSITE_DEVICE
+       { STRING_DATA,          "Ethernet Data", },
+#ifdef DEV_CONFIG_CDC
+       { STRING_ETHADDR,       ethaddr, },
+       { STRING_CONTROL,       "CDC Communications Control", },
+#endif
+#ifdef CONFIG_USB_ETH_RNDIS
+       { STRING_RNDIS_CONTROL, "RNDIS Communications Control", },
+#endif
+#else /* USB_COMPOSITE_DEVICE */
        { STRING_MANUFACTURER,  manufacturer, },
@@ -968,2 +999,3 @@ static struct usb_string            strings [] = {
 #endif
+#endif /* USB_COMPOSITE_DEVICE */
        {  }            /* end of list */
@@ -976,2 +1008,7 @@ static struct usb_gadget_strings   stringt
 
+#ifdef USB_COMPOSITE_DEVICE
+static struct usb_function eth_usb_function;
+#endif
+
+#ifndef USB_COMPOSITE_DEVICE
 /*
@@ -987,3 +1024,3 @@ config_buf (enum usb_device_speed speed,
        const struct usb_config_descriptor      *config;
-       const struct usb_descriptor_header      **function;
+       struct usb_descriptor_header            **function;
 #ifdef CONFIG_USB_GADGET_DUALSPEED
@@ -1025,2 +1062,3 @@ config_buf (enum usb_device_speed speed,
 }
+#endif /* !USB_COMPOSITE_DEVICE */
 
@@ -1177,3 +1215,5 @@ eth_set_config (struct eth_dev *dev, uns
        int                     result = 0;
+#ifndef USB_COMPOSITE_DEVICE
        struct usb_gadget       *gadget = dev->gadget;
+#endif /* !USB_COMPOSITE_DEVICE */
 
@@ -1210,3 +1250,9 @@ eth_set_config (struct eth_dev *dev, uns
                                dev->gadget->is_otg ? 8 : 100);
-       } else {
+       }
+#ifdef USB_COMPOSITE_DEVICE
+         else {
+               dev->config = number;
+        }
+#else
+         else {
                char *speed;
@@ -1234,2 +1280,3 @@ eth_set_config (struct eth_dev *dev, uns
        }
+#endif /* !USB_COMPOSITE_DEVICE */
        return result;
@@ -1322,2 +1369,3 @@ static void issue_start_status (struct e
 
+#ifndef USB_COMPOSITE_DEVICE
 static void eth_setup_complete (struct usb_ep *ep, struct usb_request *req)
@@ -1329,2 +1377,3 @@ static void eth_setup_complete (struct u
 }
+#endif /* !USB_COMPOSITE_DEVICE */
 
@@ -1369,3 +1418,8 @@ eth_setup (struct usb_gadget *gadget, co
 {
+#ifdef USB_COMPOSITE_DEVICE
+       struct usb_composite_dev *cdev = get_gadget_data(gadget);
+       struct eth_dev          *dev = get_composite_data(cdev);
+#else
        struct eth_dev          *dev = get_gadget_data (gadget);
+#endif /* USB_COMPOSITE_DEVICE */
        struct usb_request      *req = dev->req;
@@ -1379,5 +1433,9 @@ eth_setup (struct usb_gadget *gadget, co
         */
+#ifndef USB_COMPOSITE_DEVICE
        req->complete = eth_setup_complete;
+#endif
        switch (ctrl->bRequest) {
 
+#ifndef USB_COMPOSITE_DEVICE
+/* if defined composite get the descriptors from composite. */
        case USB_REQ_GET_DESCRIPTOR:
@@ -1421,3 +1479,3 @@ eth_setup (struct usb_gadget *gadget, co
                break;
-
+#endif /* !USB_COMPOSITE_DEVICE */
        case USB_REQ_SET_CONFIGURATION:
@@ -1429,2 +1487,8 @@ eth_setup (struct usb_gadget *gadget, co
                        DEBUG (dev, "HNP needs a different root port\n");
+#ifdef USB_COMPOSITE_DEVICE
+               if (wValue == COMPOSITE_CONFIG_VALUE) {
+                       wValue = is_cdc(dev) ?
+                               DEV_CONFIG_VALUE : DEV_RNDIS_CONFIG_VALUE;
+               }
+#endif /* USB_COMPOSITE_DEVICE */
                spin_lock (&dev->lock);
@@ -1433,2 +1497,4 @@ eth_setup (struct usb_gadget *gadget, co
                break;
+#ifndef USB_COMPOSITE_DEVICE
+/* if defined composite, get the configuration from composite. */
        case USB_REQ_GET_CONFIGURATION:
@@ -1439,4 +1505,7 @@ eth_setup (struct usb_gadget *gadget, co
                break;
-
+#endif /* !USB_COMPOSITE_DEVICE */
        case USB_REQ_SET_INTERFACE:
+#ifdef USB_COMPOSITE_DEVICE
+               wIndex -= cdev->current_func->interface_shift;
+#endif /* USB_COMPOSITE_DEVICE */
                if (ctrl->bRequestType != USB_RECIP_INTERFACE
@@ -1511,2 +1580,5 @@ done_set_intf:
        case USB_REQ_GET_INTERFACE:
+#ifdef USB_COMPOSITE_DEVICE
+               wIndex -= cdev->current_func->interface_shift;
+#endif /* USB_COMPOSITE_DEVICE */
                if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)
@@ -1598,2 +1670,3 @@ done_set_intf:
 
+#ifndef USB_COMPOSITE_DEVICE
        /* respond with data transfer before status phase? */
@@ -1610,3 +1683,3 @@ done_set_intf:
        }
-
+#endif /* !USB_COMPOSITE_DEVICE */
        /* host either stalls (value < 0) or reports success */
@@ -1618,3 +1691,8 @@ eth_disconnect (struct usb_gadget *gadge
 {
+#ifdef USB_COMPOSITE_DEVICE
+       struct usb_composite_dev *cdev = get_gadget_data(gadget);
+       struct eth_dev          *dev = get_composite_data(cdev);
+#else
        struct eth_dev          *dev = get_gadget_data (gadget);
+#endif /* USB_COMPOSITE_DEVICE */
        unsigned long           flags;
@@ -2217,3 +2295,8 @@ eth_unbind (struct usb_gadget *gadget)
 {
+#ifdef USB_COMPOSITE_DEVICE
+       struct usb_composite_dev *cdev = get_gadget_data(gadget);
+       struct eth_dev          *dev = get_composite_data(cdev);
+#else
        struct eth_dev          *dev = get_gadget_data (gadget);
+#endif /* USB_COMPOSITE_DEVICE */
 
@@ -2222,3 +2305,5 @@ eth_unbind (struct usb_gadget *gadget)
        rndis_exit ();
-
+#ifdef USB_COMPOSITE_DEVICE
+       dev->req = NULL;
+#else
        /* we've already been disconnected ... no i/o is active */
@@ -2228,2 +2313,3 @@ eth_unbind (struct usb_gadget *gadget)
        }
+#endif /* USB_COMPOSITE_DEVICE */
        if (dev->stat_req) {
@@ -2233,8 +2319,18 @@ eth_unbind (struct usb_gadget *gadget)
 
+#ifdef USB_COMPOSITE_DEVICE
+       eth_reset_config(dev);
+       usb_composite_ep_reset(dev->status_ep);
+       usb_composite_ep_reset(dev->in_ep);
+       usb_composite_ep_reset(dev->out_ep);
+#endif /* USB_COMPOSITE_DEVICE */
+
        unregister_netdev (dev->net);
        free_netdev(dev->net);
-
        /* assuming we used keventd, it must quiesce too */
        flush_scheduled_work ();
+#ifdef USB_COMPOSITE_DEVICE
+       set_composite_data(cdev, NULL);
+#else
        set_gadget_data (gadget, NULL);
+#endif /* USB_COMPOSITE_DEVICE */
 }
@@ -2275,2 +2371,7 @@ eth_bind (struct usb_gadget *gadget)
 {
+#ifdef USB_COMPOSITE_DEVICE
+       struct usb_composite_dev *cdev = get_gadget_data(gadget);
+#else
+       int                     gcnum;
+#endif /* USB_COMPOSITE_DEVICE */
        struct eth_dev          *dev;
@@ -2280,3 +2381,2 @@ eth_bind (struct usb_gadget *gadget)
        int                     status = -ENOMEM;
-       int                     gcnum;
 
@@ -2312,3 +2412,22 @@ eth_bind (struct usb_gadget *gadget)
        }
+#ifdef USB_COMPOSITE_DEVICE
+       if (cdc) {
+               eth_usb_function.descriptors = fs_eth_function;
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+               eth_usb_function.hs_descriptors = hs_eth_function;
+#endif
+       }
+#ifdef CONFIG_USB_ETH_RNDIS
+         else { /* FIXME: How i could to use two descriptors type.
+                 * Composite has only one config.
+                 */
+                 eth_usb_function.descriptors = fs_rndis_function;
+#ifdef CONFIG_USB_GADGET_DUALSPEED
+                 eth_usb_function.hs_descriptors =  hs_rndis_function;
+#endif
+       }
 
+#endif /* CONFIG_USB_ETH_RNDIS */
+
+#else /* USB_COMPOSITE_DEVICE */
        gcnum = usb_gadget_controller_number (gadget);
@@ -2326,2 +2445,3 @@ eth_bind (struct usb_gadget *gadget)
        }
+#endif /* USB_COMPOSITE_DEVICE */
        snprintf (manufacturer, sizeof manufacturer, "%s %s/%s",
@@ -2336,2 +2456,3 @@ eth_bind (struct usb_gadget *gadget)
         */
+#ifndef USB_COMPOSITE_DEVICE
        if (rndis) {
@@ -2377,2 +2498,4 @@ eth_bind (struct usb_gadget *gadget)
        usb_ep_autoconfig_reset (gadget);
+#endif /* !USB_COMPOSITE_DEVICE */
+
        in_ep = usb_ep_autoconfig (gadget, &fs_source_desc);
@@ -2417,4 +2540,6 @@ autoconf_fail:
        if (!cdc) {
+#ifndef USB_COMPOSITE_DEVICE
                eth_config.bNumInterfaces = 1;
                eth_config.iConfiguration = STRING_SUBSET;
+#endif /* !USB_COMPOSITE_DEVICE */
 
@@ -2427,2 +2552,3 @@ autoconf_fail:
 
+#ifndef USB_COMPOSITE_DEVICE
        device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
@@ -2433,4 +2559,6 @@ autoconf_fail:
                device_desc.bNumConfigurations = 2;
+#endif /* !USB_COMPOSITE_DEVICE */
 
 #ifdef CONFIG_USB_GADGET_DUALSPEED
+#ifndef USB_COMPOSITE_DEVICE
        if (rndis)
@@ -2442,2 +2570,3 @@ autoconf_fail:
        dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
+#endif /* !USB_COMPOSITE_DEVICE */
 
@@ -2454,2 +2583,5 @@ autoconf_fail:
        if (gadget->is_otg) {
+#ifdef USB_COMPOSITE_DEVICE
+               otg_descriptor.bmAttributes |= USB_OTG_HNP;
+#else
                otg_descriptor.bmAttributes |= USB_OTG_HNP,
@@ -2461,2 +2593,3 @@ autoconf_fail:
 #endif
+#endif /* !USB_COMPOSITE_DEVICE */
        }
@@ -2520,2 +2653,5 @@ autoconf_fail:
        /* preallocate control message data and buffer */
+#ifdef USB_COMPOSITE_DEVICE
+       dev->req = cdev->req;
+#else
        dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ, GFP_KERNEL);
@@ -2524,3 +2660,3 @@ autoconf_fail:
        dev->req->complete = eth_setup_complete;
-
+#endif /* USB_COMPOSITE_DEVICE */
        /* ... and maybe likewise for status transfer */
@@ -2531,3 +2667,5 @@ autoconf_fail:
                if (!dev->stat_req) {
+#ifndef USB_COMPOSITE_DEVICE
                        eth_req_free (gadget->ep0, dev->req);
+#endif /* !USB_COMPOSITE_DEVICE */
                        goto fail;
@@ -2540,4 +2678,9 @@ autoconf_fail:
        dev->gadget = gadget;
+#ifdef USB_COMPOSITE_DEVICE
+       set_composite_data(cdev, dev);
+#else
        set_gadget_data (gadget, dev);
        gadget->ep0->driver_data = dev;
+#endif /* USB_COMPOSITE_DEVICE */
+
 
@@ -2614,3 +2757,8 @@ eth_suspend (struct usb_gadget *gadget)
 {
+#ifdef USB_COMPOSITE_DEVICE
+       struct usb_composite_dev *cdev = get_gadget_data(gadget);
+       struct eth_dev          *dev = get_composite_data(cdev);
+#else
        struct eth_dev          *dev = get_gadget_data (gadget);
+#endif /* USB_COMPOSITE_DEVICE */
 
@@ -2623,3 +2771,8 @@ eth_resume (struct usb_gadget *gadget)
 {
+#ifdef USB_COMPOSITE_DEVICE
+       struct usb_composite_dev *cdev = get_gadget_data(gadget);
+       struct eth_dev          *dev = get_composite_data(cdev);
+#else
        struct eth_dev          *dev = get_gadget_data (gadget);
+#endif /* USB_COMPOSITE_DEVICE */
 
@@ -2631,2 +2784,15 @@ eth_resume (struct usb_gadget *gadget)
 
+
+#ifdef USB_COMPOSITE_DEVICE
+static struct usb_function eth_usb_function = {
+       .name           = (char *) shortname,
+       .strings        = &stringtab,
+       .bind           = eth_bind,
+       .unbind         = eth_unbind,
+       .setup          = eth_setup,
+       .disconnect     = eth_disconnect,
+       .suspend        = eth_suspend,
+       .resume         = eth_resume,
+};
+#else
 static struct usb_gadget_driver eth_driver = {
@@ -2649,2 +2815,3 @@ static struct usb_gadget_driver eth_driv
 };
+#endif /* USB_COMPOSITE_DEVICE */
 
@@ -2657,3 +2824,7 @@ static int __init init (void)
 {
+#ifdef USB_COMPOSITE_DEVICE
+       return usb_function_register(&eth_usb_function);
+#else
        return usb_gadget_register_driver (&eth_driver);
+#endif /* USB_COMPOSITE_DEVICE */
 }
@@ -2663,3 +2834,7 @@ static void __exit cleanup (void)
 {
+#ifdef USB_COMPOSITE_DEVICE
+       usb_function_unregister (&eth_usb_function);
+#else
        usb_gadget_unregister_driver (&eth_driver);
+#endif /* USB_COMPOSITE_DEVICE */
 }

--
Best Regards,

Felipe Balbi
[EMAIL PROTECTED]

Nokia Institute of Technology - INdT
Kernel Developers Team

+55 92 2126 1003


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to