[U-Boot] [PATCH 2/4] usb:gadget:composite: Linux composite.{h/c} code adjustement for u-boot

Lukasz Majewski l.majewski at samsung.com
Thu Apr 12 09:15:29 CEST 2012


This commit fixes Linux kernel's composite.{h/c} code to work with u-boot.

Signed-off-by: Lukasz Majewski <l.majewski at samsung.com>
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p at samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
Cc: Marek Vasut <marex at denx.de>
---
 drivers/usb/gadget/composite.c |   58 ++++++++++++++++++++++++++--------------
 include/linux/usb/composite.h  |   52 +++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 1160c55..6a20278 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -18,13 +18,14 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-/* #define VERBOSE_DEBUG */
+#define VERBOSE_DEBUG
 
-#include <linux/kallsyms.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/device.h>
+/* #include <linux/kallsyms.h> */
+/* #include <linux/kernel.h> */
+/* #include <linux/slab.h> */
+/* #include <linux/device.h> */
 
+#include <linux/bitops.h>
 #include <linux/usb/composite.h>
 
 
@@ -36,7 +37,7 @@
  */
 
 /* big enough to hold our biggest descriptor */
-#define USB_BUFSIZ	1024
+#define USB_BUFSIZ	4096
 
 static struct usb_composite_driver *composite;
 
@@ -404,13 +405,23 @@ static int set_config(struct usb_composite_dev *cdev,
 		result = 0;
 
 	INFO(cdev, "%s speed config #%d: %s\n",
-		({ char *speed;
-		switch (gadget->speed) {
-		case USB_SPEED_LOW:	speed = "low"; break;
-		case USB_SPEED_FULL:	speed = "full"; break;
-		case USB_SPEED_HIGH:	speed = "high"; break;
-		default:		speed = "?"; break;
-		} ; speed; }), number, c ? c->label : "unconfigured");
+	     ({ char *speed;
+		     switch (gadget->speed) {
+		     case USB_SPEED_LOW:
+			     speed = "low";
+			     break;
+		     case USB_SPEED_FULL:
+			     speed = "full";
+			     break;
+		     case USB_SPEED_HIGH:
+			     speed = "high";
+			     break;
+		     default:
+			     speed = "?";
+			     break;
+		     };
+		     speed;
+	     }), number, c ? c->label : "unconfigured");
 
 	if (!c)
 		goto done;
@@ -779,6 +790,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 	u16				w_length = le16_to_cpu(ctrl->wLength);
 	struct usb_function		*f = NULL;
 	u8				endp;
+	bool				standard;
 
 	/* partial re-init of the response message; the function or the
 	 * gadget might need to intercept e.g. a control-OUT completion
@@ -788,6 +800,10 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 	req->complete = composite_setup_complete;
 	req->length = USB_BUFSIZ;
 	gadget->ep0->driver_data = cdev;
+	standard = (ctrl->bRequestType & USB_TYPE_MASK)
+						== USB_TYPE_STANDARD;
+	if (!standard)
+		goto unknown;
 
 	switch (ctrl->bRequest) {
 
@@ -825,6 +841,8 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 			if (value >= 0)
 				value = min(w_length, (u16) value);
 			break;
+		default:
+			goto unknown;
 		}
 		break;
 
@@ -963,7 +981,7 @@ static void composite_disconnect(struct usb_gadget *gadget)
 
 /*-------------------------------------------------------------------------*/
 
-static ssize_t composite_show_suspended(struct device *dev,
+/* static ssize_t composite_show_suspended(struct device *dev,
 					struct device_attribute *attr,
 					char *buf)
 {
@@ -973,7 +991,7 @@ static ssize_t composite_show_suspended(struct device *dev,
 	return sprintf(buf, "%d\n", cdev->suspended);
 }
 
-static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
+static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL); */
 
 static void
 composite_unbind(struct usb_gadget *gadget)
@@ -985,7 +1003,7 @@ composite_unbind(struct usb_gadget *gadget)
 	 * so there's no i/o concurrency that could affect the
 	 * state protected by cdev->lock.
 	 */
-	WARN_ON(cdev->config);
+	BUG_ON(cdev->config);
 
 	while (!list_empty(&cdev->configs)) {
 		struct usb_configuration	*c;
@@ -1186,9 +1204,9 @@ static struct usb_gadget_driver composite_driver = {
 	.suspend	= composite_suspend,
 	.resume		= composite_resume,
 
-	.driver	= {
+	/* .driver	= {
 		.owner		= THIS_MODULE,
-	},
+	}, */
 };
 
 /**
@@ -1213,8 +1231,8 @@ int usb_composite_register(struct usb_composite_driver *driver)
 
 	if (!driver->name)
 		driver->name = "composite";
-	composite_driver.function =  (char *) driver->name;
-	composite_driver.driver.name = driver->name;
+	/* composite_driver.function =  (char *) driver->name; */
+	/* composite_driver.driver.name = driver->name; */
 	composite = driver;
 
 	return usb_gadget_register_driver(&composite_driver);
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 6170681..0c50a26 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -22,6 +22,58 @@
 #define	__LINUX_USB_COMPOSITE_H
 
 /*
+ * Linux kernel compatibility layer
+ */
+#define true					1
+#define false					0
+#define GFP_ATOMIC				((gfp_t) 0)
+#define GFP_KERNEL				((gfp_t) 0)
+#define BITS_PER_BYTE				8
+#define BITS_TO_LONGS(nr) \
+	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+#define DECLARE_BITMAP(name, bits) \
+	unsigned long name[BITS_TO_LONGS(bits)]
+#define min_t(type, x, y) \
+	({ type __x = (x); type __y = (y); __x < __y ? __x : __y; })
+#define dev_dbg(...)				do {} while (0)
+#define dev_vdbg(...)				do {} while (0)
+#define dev_err(...)				do {} while (0)
+#define dev_warn(...)				do {} while (0)
+#define dev_info(...)				do {} while (0)
+#define pr_warning(...)				do {} while (0)
+#define spin_lock_init(lock)			do {} while (0)
+#define spin_lock(lock)				do {} while (0)
+#define spin_unlock(lock)			do {} while (0)
+#define spin_lock_irqsave(lock, flags)		do {flags = 1; } while (0)
+#define spin_unlock_irqrestore(lock, flags)	do {flags = 0; } while (0)
+#define kmalloc(x, y)				malloc(x)
+#define kfree(x)				free(x)
+#define kzalloc(size, flags)			calloc((size), 1)
+#define module_param(...)
+#define MODULE_PARM_DESC(...)
+#define WARN_ON(x)				x
+#define device_remove_file(...)
+#define device_create_file(...)			0
+#define set_bit					__set_bit
+typedef int spinlock_t;
+typedef int bool;
+#define small_const_nbits(nbits) \
+	(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
+
+static inline void bitmap_zero(unsigned long *dst, int nbits)
+{
+	if (small_const_nbits(nbits))
+		*dst = 0UL;
+	else {
+		int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+		memset(dst, 0, len);
+	}
+}
+/*
+ * end compatibility layer
+ */
+
+/*
  * This framework is an optional layer on top of the USB Gadget interface,
  * making it easier to build (a) Composite devices, supporting multiple
  * functions within any single configuration, and (b) Multi-configuration
-- 
1.7.2.3



More information about the U-Boot mailing list