Skip to contentSkip to conversation

USB: Add support for designware UDC

PATCH Superseded Amit Virdi 4 participants 20 messages Feb 16, 2012 – Mar 7, 2012 USB

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Amit Virdi

author
#0 lore raw

cover USB: Add support for designware UDC

Support for designware USB device controller (UDC) exists in the u-boot for SPEAr platform. This patchset makes the driver more generic so that it can be used across multiple platforms.

Shiraz Hashim (1):
USB:gadget:designware Fix memory nonalignment issue

Vipin KUMAR (3):
USB:gadget:designware USB device controller (UDC) implementation USB:gadget:designware Device controller bugfixes USB:gadget:designware Support high speed

 drivers/serial/usbtty.h                            |    4 +-
 drivers/usb/gadget/Makefile                        |    2 +-
 drivers/usb/gadget/{spr_udc.c => designware_udc.c} |  138 ++++++++++++--------
 include/configs/spear-common.h                     |    4 +-
 include/usb/{spr_udc.h => designware_udc.h}        |    9 +-
 5 files changed, 98 insertions(+), 59 deletions(-)
 rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (89%)
 rename include/usb/{spr_udc.h => designware_udc.h} (97%)
Signature · 1 line
1.7.2.2
author
#1 lore raw

PATCH 1/4 USB:gadget:designware USB device controller (UDC) implementation

From: Vipin KUMAR <[email protected]>

The earlier usb device controller driver was specific to spear platforms. This patch implements the usb device controller driver as a generic controller which can be reused by other platforms using this peripheral.

---
 drivers/serial/usbtty.h                            |    4 +-
 drivers/usb/gadget/Makefile                        |    2 +-
 drivers/usb/gadget/{spr_udc.c => designware_udc.c} |   57 ++++++++++----------
 include/configs/spear-common.h                     |    4 +-
 include/usb/{spr_udc.h => designware_udc.h}        |    6 +-
 5 files changed, 37 insertions(+), 36 deletions(-)
 rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (94%)
 rename include/usb/{spr_udc.h => designware_udc.h} (98%)
drivers/serial/usbtty.h +2 -2
index e449cd7..60347d7 100644
@@ -33,8 +33,8 @@
 #include <usb/musb_udc.h>
 #elif defined(CONFIG_CPU_PXA27X)
 #include <usb/pxa27x_udc.h>
-#elif defined(CONFIG_SPEAR3XX) || defined(CONFIG_SPEAR600)
-#include <usb/spr_udc.h>
+#elif defined(CONFIG_DW_UDC)
+#include <usb/designware_udc.h>
 #endif
 
 #include <version.h>
drivers/usb/gadget/Makefile +1 -1
index 64b091f..87d1918 100644
@@ -39,11 +39,11 @@ else
 ifdef CONFIG_USB_DEVICE
 COBJS-y += core.o
 COBJS-y += ep0.o
+COBJS-$(CONFIG_DW_UDC) += designware_udc.o
 COBJS-$(CONFIG_OMAP1510) += omap1510_udc.o
 COBJS-$(CONFIG_OMAP1610) += omap1510_udc.o
 COBJS-$(CONFIG_MPC885_FAMILY) += mpc8xx_udc.o
 COBJS-$(CONFIG_CPU_PXA27X) += pxa27x_udc.o
-COBJS-$(CONFIG_SPEARUDC) += spr_udc.o
 endif
 endif
 
drivers/usb/gadget/designware_udc.c renamed from drivers/usb/gadget/spr_udc.c +28 -29

204 lines not on this page · raw message

include/configs/spear-common.h +3 -1
index 258574f..3dd6b57 100644
@@ -28,14 +28,16 @@
  */
 
 /* USBD driver configuration */
-#define CONFIG_SPEARUDC
+#define CONFIG_DW_UDC
 #define CONFIG_USB_DEVICE
 #define CONFIG_USB_TTY
 
 #define CONFIG_USBD_PRODUCT_NAME		"SPEAr SoC"
 #define CONFIG_USBD_MANUFACTURER		"ST Microelectronics"
 
+#if defined(CONFIG_USB_TTY)
 #define CONFIG_EXTRA_ENV_USBTTY			"usbtty=cdc_acm\0"
+#endif
 
 /* I2C driver configuration */
 #define CONFIG_HARD_I2C
include/usb/designware_udc.h renamed from include/usb/spr_udc.h +3 -3
similarity index 98%
rename from include/usb/spr_udc.h
rename to include/usb/designware_udc.h
index 2c332d5..ae98e8c 100644
@@ -21,8 +21,8 @@
  * MA 02111-1307 USA
  */
 
-#ifndef __SPR_UDC_H
-#define __SPR_UDC_H
+#ifndef __DW_UDC_H
+#define __DW_UDC_H
 
 /*
  * Defines for  USBD
@@ -227,4 +227,4 @@ void udc_startup_events(struct usb_device_instance *device);
 void udc_setup_ep(struct usb_device_instance *device, unsigned int ep,
 		  struct usb_endpoint_instance *endpoint);
 
-#endif /* __SPR_UDC_H */
+#endif /* __DW_UDC_H */
Signature · 1 line
1.7.2.2
#2 lore raw

PATCH 1/4 USB:gadget:designware USB device controller (UDC) implementation

Dear Amit Virdi,

Quoted 8 lines

From: Vipin KUMAR <[email protected]>

The earlier usb device controller driver was specific to spear platforms. This patch implements the usb device controller driver as a generic controller which can be reused by other platforms using this peripheral.

Quoted 11 lines
---
 drivers/serial/usbtty.h                            |    4 +-
 drivers/usb/gadget/Makefile                        |    2 +-
 drivers/usb/gadget/{spr_udc.c => designware_udc.c} |   57
++++++++++---------- include/configs/spear-common.h                     | 
  4 +-
 include/usb/{spr_udc.h => designware_udc.h}        |    6 +-
 5 files changed, 37 insertions(+), 36 deletions(-)
 rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (94%)
 rename include/usb/{spr_udc.h => designware_udc.h} (98%)

This patch is just a rename, right?

Best regards,
Marek Vasut

author
#3 lore raw

PATCH 1/4 USB:gadget:designware USB device controller (UDC) implementation

Hello Marek,

Quoted 22 lines · Marek Vasut

Dear Amit Virdi,

Quoted 16 lines

From: Vipin KUMAR<[email protected]>

The earlier usb device controller driver was specific to spear platforms. This patch implements the usb device controller driver as a generic controller which can be reused by other platforms using this peripheral.

---
  drivers/serial/usbtty.h                            |    4 +-
  drivers/usb/gadget/Makefile                        |    2 +-
  drivers/usb/gadget/{spr_udc.c =>  designware_udc.c} |   57
++++++++++---------- include/configs/spear-common.h                     |
   4 +-
  include/usb/{spr_udc.h =>  designware_udc.h}        |    6 +-
  5 files changed, 37 insertions(+), 36 deletions(-)
Quoted 3 lines

rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (94%) rename include/usb/{spr_udc.h => designware_udc.h} (98%)

Quoted 2 lines

This patch is just a rename, right?

Yes.

Quoted 2 lines

Thanks n Regards
Amit Virdi

author
#4 lore raw

PATCH 2/4 USB:gadget:designware Device controller bugfixes

In reply to Amit Virdi

From: Vipin KUMAR <[email protected]>

This patch fixes a few bugs in USB device controller driver. The fixes are as follows
1. Adding error condition checks eg. NULL return
2. Endpoint other than endpoint 0 (control endpoint) are initialized only if usb state machine reaches STATE_ADDRESSED or above
3. Zero length packet handling corrected
4. Dead code removed
5. Bulk out endpoint returns after servicing 1 interrupt and returns back to service if more interrupts are pending

---
 drivers/usb/gadget/designware_udc.c |   59 ++++++++++++++++++++++------------
 1 files changed, 38 insertions(+), 21 deletions(-)
drivers/usb/gadget/designware_udc.c +38 -21
index aee44aa..3c20f3d 100644
@@ -497,16 +497,24 @@ static void dw_udc_epn_tx(int ep)
 {
 	struct usb_endpoint_instance *endpoint = dw_find_ep(ep);
 
+	if (!endpoint)
+		return;
+
 	/*
 	 * We need to transmit a terminating zero-length packet now if
 	 * we have sent all of the data in this URB and the transfer
 	 * size was an exact multiple of the packet size.
 	 */
-	if (endpoint && endpoint->tx_urb && endpoint->tx_urb->actual_length) {
-		if (endpoint->last == endpoint->tx_packetSize) {
-			/* handle zero length packet here */
-			writel(0x0, &inep_regs_p[ep].write_done);
-		}
+	if (endpoint->tx_urb &&
+	    (endpoint->last == endpoint->tx_packetSize) &&
+	    (endpoint->tx_urb->actual_length - endpoint->sent -
+	     endpoint->last == 0)) {
+		/* handle zero length packet here */
+		writel(0x0, &inep_regs_p[ep].write_done);
+
+	}
+
+	if (endpoint->tx_urb && endpoint->tx_urb->actual_length) {
 		/* retire the data that was just sent */
 		usbd_tx_complete(endpoint);
 		/*
@@ -548,8 +556,6 @@ int udc_init(void)
 
 	readl(&plug_regs_p->plug_pending);
 
-	udc_disconnect();
-
 	for (i = 0; i < UDC_INIT_MDELAY; i++)
 		udelay(1000);
 
@@ -561,10 +567,9 @@ int udc_init(void)
 	writel(~0x0, &udc_regs_p->endp_int_mask);
 
 	writel(DEV_CONF_FS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
-	       /* Dev_Conf_SYNCFRAME | */
 	       DEV_CONF_PHYINT_16, &udc_regs_p->dev_conf);
 
-	writel(0x0, &udc_regs_p->dev_cntl);
+	writel(DEV_CNTL_SOFTDISCONNECT, &udc_regs_p->dev_cntl);
 
 	/* Clear all interrupts pending */
 	writel(DEV_INT_MSK, &udc_regs_p->dev_int);
@@ -588,6 +593,9 @@ void udc_setup_ep(struct usb_device_instance *device,
 	char *tt;
 	u32 endp_intmask;
 
+	if ((ep != 0) && (udc_device->device_state < STATE_ADDRESSED))
+		return;
+
 	tt = getenv("usbtty");
 	if (!tt)
 		tt = "generic";
@@ -647,9 +655,6 @@ void udc_setup_ep(struct usb_device_instance *device,
 		writel(packet_size | ((buffer_size / sizeof(int)) << 16),
 		       &out_p->endp_maxpacksize);
 
-		writel((packet_size << 19) | ENDP_EPTYPE_CNTL,
-		       &udc_regs_p->udc_endp_reg[ep_num]);
-
 	} else if ((ep_addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) {
 		/* Setup the IN endpoint */
 		writel(0x0, &in_p->endp_status);
@@ -708,7 +713,17 @@ void udc_setup_ep(struct usb_device_instance *device,
 /* Turn on the USB connection by enabling the pullup resistor */
 void udc_connect(void)
 {
-	u32 plug_st;
+	u32 plug_st, dev_cntl;
+
+	dev_cntl = readl(&udc_regs_p->dev_cntl);
+	dev_cntl |= DEV_CNTL_SOFTDISCONNECT;
+	writel(dev_cntl, &udc_regs_p->dev_cntl);
+
+	udelay(1000);
+
+	dev_cntl = readl(&udc_regs_p->dev_cntl);
+	dev_cntl &= ~DEV_CNTL_SOFTDISCONNECT;
+	writel(dev_cntl, &udc_regs_p->dev_cntl);
 
 	plug_st = readl(&plug_regs_p->plug_state);
 	plug_st &= ~(PLUG_STATUS_PHY_RESET | PLUG_STATUS_PHY_MODE);
@@ -720,6 +735,8 @@ void udc_disconnect(void)
 {
 	u32 plug_st;
 
+	writel(DEV_CNTL_SOFTDISCONNECT, &udc_regs_p->dev_cntl);
+
 	plug_st = readl(&plug_regs_p->plug_state);
 	plug_st |= (PLUG_STATUS_PHY_RESET | PLUG_STATUS_PHY_MODE);
 	writel(plug_st, &plug_regs_p->plug_state);
@@ -789,11 +806,6 @@ void dw_udc_plug_irq(void)
 		UDCDBG("device attached and powered");
 		udc_state_transition(udc_device->device_state, STATE_POWERED);
 	} else {
-		/*
-		 * USB cable detached
-		 * Reset the PHY and switch the mode.
-		 */
-		udc_disconnect();
 		writel(~0x0, &udc_regs_p->dev_int_mask);
 
 		UDCDBG("device detached or unpowered");
@@ -809,13 +821,18 @@ void dw_udc_dev_irq(void)
 	if (readl(&udc_regs_p->dev_int) & DEV_INT_USBRESET) {
 		writel(~0x0, &udc_regs_p->endp_int_mask);
 
-		udc_connect();
-
 		writel(readl(&inep_regs_p[0].endp_cntl) | ENDP_CNTL_FLUSH,
 		       &inep_regs_p[0].endp_cntl);
 
 		writel(DEV_INT_USBRESET, &udc_regs_p->dev_int);
 
+		/*
+		 * This endpoint0 specific register can be programmed only
+		 * after the phy clock is initialized
+		 */
+		writel((EP0_MAX_PACKET_SIZE << 19) | ENDP_EPTYPE_CNTL,
+				&udc_regs_p->udc_endp_reg[0]);
+
 		UDCDBG("device reset in progess");
 		udc_state_transition(udc_device->device_state, STATE_DEFAULT);
 	}
@@ -902,7 +919,7 @@ void dw_udc_endpoint_irq(void)
 		writel(ENDP0_INT_CTRLIN, &udc_regs_p->endp_int);
 	}
 
-	while (readl(&udc_regs_p->endp_int) & ENDP_INT_NONISOOUT_MSK) {
+	if (readl(&udc_regs_p->endp_int) & ENDP_INT_NONISOOUT_MSK) {
 		u32 epnum = 0;
 		u32 ep_int = readl(&udc_regs_p->endp_int) &
 		    ENDP_INT_NONISOOUT_MSK;
Signature · 1 line
1.7.2.2
#5 lore raw

PATCH 2/4 USB:gadget:designware Device controller bugfixes

Dear Amit Virdi,

Quoted 12 lines

From: Vipin KUMAR <[email protected]>

This patch fixes a few bugs in USB device controller driver. The fixes are as follows
1. Adding error condition checks eg. NULL return
2. Endpoint other than endpoint 0 (control endpoint) are initialized only if usb state machine reaches STATE_ADDRESSED or above
3. Zero length packet handling corrected
4. Dead code removed
5. Bulk out endpoint returns after servicing 1 interrupt and returns back to service if more interrupts are pending

Quoted 2 lines

Ok, I take it you know what you're doing here:

Best regards,
Marek Vasut

author
#6 lore raw

PATCH 2/4 USB:gadget:designware Device controller bugfixes

Dear Marek,

Quoted 14 lines · Marek Vasut

Dear Amit Virdi,

Quoted 12 lines

From: Vipin KUMAR<[email protected]>

This patch fixes a few bugs in USB device controller driver. The fixes are as follows
1. Adding error condition checks eg. NULL return
2. Endpoint other than endpoint 0 (control endpoint) are initialized only if usb state machine reaches STATE_ADDRESSED or above
3. Zero length packet handling corrected
4. Dead code removed
5. Bulk out endpoint returns after servicing 1 interrupt and returns back to service if more interrupts are pending

Quoted 7 lines
Quoted 2 lines

Ok, I take it you know what you're doing here:

Thanks.

Best Regards
Amit Virdi

author
#7 lore raw

PATCH 3/4 USB:gadget:designware Support high speed

In reply to Amit Virdi

From: Vipin KUMAR <[email protected]>

This patch adds the support for usb device high speed for designware peripheral.

---
 drivers/usb/gadget/designware_udc.c |   13 +++++++++----
 include/usb/designware_udc.h        |    3 +++
 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/usb/gadget/designware_udc.c +9 -4
index 3c20f3d..d4b53a2 100644
@@ -566,7 +566,7 @@ int udc_init(void)
 	writel(~0x0, &udc_regs_p->dev_int_mask);
 	writel(~0x0, &udc_regs_p->endp_int_mask);
 
-	writel(DEV_CONF_FS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
+	writel(DEV_CONF_HS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
 	       DEV_CONF_PHYINT_16, &udc_regs_p->dev_conf);
 
 	writel(DEV_CNTL_SOFTDISCONNECT, &udc_regs_p->dev_cntl);
@@ -577,6 +577,11 @@ int udc_init(void)
 	return 0;
 }
 
+int is_usbd_high_speed(void)
+{
+	return (readl(&udc_regs_p->dev_stat) & DEV_STAT_ENUM) ? 0 : 1;
+}
+
 /*
  * udc_setup_ep - setup endpoint
  * Associate a physical endpoint with endpoint_instance
@@ -792,7 +797,7 @@ void udc_startup_events(struct usb_device_instance *device)
 /*
  * Plug detection interrupt handling
  */
-void dw_udc_plug_irq(void)
+static void dw_udc_plug_irq(void)
 {
 	if (readl(&plug_regs_p->plug_state) & PLUG_STATUS_ATTACHED) {
 		/*
@@ -816,7 +821,7 @@ void dw_udc_plug_irq(void)
 /*
  * Device interrupt handling
  */
-void dw_udc_dev_irq(void)
+static void dw_udc_dev_irq(void)
 {
 	if (readl(&udc_regs_p->dev_int) & DEV_INT_USBRESET) {
 		writel(~0x0, &udc_regs_p->endp_int_mask);
@@ -886,7 +891,7 @@ void dw_udc_dev_irq(void)
 /*
  * Endpoint interrupt handling
  */
-void dw_udc_endpoint_irq(void)
+static void dw_udc_endpoint_irq(void)
 {
 	while (readl(&udc_regs_p->endp_int) & ENDP0_INT_CTRLOUT) {
 
include/usb/designware_udc.h +3 -0
index ae98e8c..8d48ae9 100644
@@ -197,6 +197,9 @@ struct udcfifo_regs {
 #define  UDC_INT_PACKET_SIZE		64
 #define  UDC_OUT_ENDPOINT		2
 #define  UDC_BULK_PACKET_SIZE		64
+#if defined(CONFIG_USBD_HS)
+#define  UDC_BULK_HS_PACKET_SIZE	512
+#endif
 #define  UDC_IN_ENDPOINT		3
 #define  UDC_OUT_PACKET_SIZE		64
 #define  UDC_IN_PACKET_SIZE		64
Signature · 1 line
1.7.2.2
#8 lore raw

PATCH 3/4 USB:gadget:designware Support high speed

Dear Amit Virdi,

Quoted 17 lines

From: Vipin KUMAR <[email protected]>

This patch adds the support for usb device high speed for designware peripheral.

---
 drivers/usb/gadget/designware_udc.c |   13 +++++++++----
 include/usb/designware_udc.h        |    3 +++
 2 files changed, 12 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/gadget/designware_udc.c index 3c20f3d..d4b53a2 100644

drivers/usb/gadget/designware_udc.c int udc_init(void) · line 570

Quoted 6 lines
drivers/usb/gadget/designware_udc.c +1 -1
@@ -566,7 +566,7 @@ int udc_init(void)
 	writel(~0x0, &udc_regs_p->dev_int_mask);
 	writel(~0x0, &udc_regs_p->endp_int_mask);
 
-	writel(DEV_CONF_FS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
+	writel(DEV_CONF_HS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
 	       DEV_CONF_PHYINT_16, &udc_regs_p->dev_conf);

Won't this break anything?

Quoted 15 lines
drivers/usb/gadget/designware_udc.c +5 -0
 	writel(DEV_CNTL_SOFTDISCONNECT, &udc_regs_p->dev_cntl);
@@ -577,6 +577,11 @@ int udc_init(void)
 	return 0;
 }
 
+int is_usbd_high_speed(void)
+{
+	return (readl(&udc_regs_p->dev_stat) & DEV_STAT_ENUM) ? 0 : 1;
+}
+
 /*
  * udc_setup_ep - setup endpoint
  * Associate a physical endpoint with endpoint_instance

drivers/usb/gadget/designware_udc.c void udc_startup_events(struct usb_device_instance · line 800

Quoted 5 lines
drivers/usb/gadget/designware_udc.c +1 -1
@@ -792,7 +797,7 @@ void udc_startup_events(struct usb_device_instance
 *device) /*
  * Plug detection interrupt handling
  */
-void dw_udc_plug_irq(void)
+static void dw_udc_plug_irq(void)

This staticisation stuff should go in a separate patch please.

Quoted 26 lines
drivers/usb/gadget/designware_udc.c +2 -2
 {
 	if (readl(&plug_regs_p->plug_state) & PLUG_STATUS_ATTACHED) {
 		/*
@@ -816,7 +821,7 @@ void dw_udc_plug_irq(void)
 /*
  * Device interrupt handling
  */
-void dw_udc_dev_irq(void)
+static void dw_udc_dev_irq(void)
 {
 	if (readl(&udc_regs_p->dev_int) & DEV_INT_USBRESET) {
 		writel(~0x0, &udc_regs_p->endp_int_mask);
@@ -886,7 +891,7 @@ void dw_udc_dev_irq(void)
 /*
  * Endpoint interrupt handling
  */
-void dw_udc_endpoint_irq(void)
+static void dw_udc_endpoint_irq(void)
 {
 	while (readl(&udc_regs_p->endp_int) & ENDP0_INT_CTRLOUT) {
 
include/usb/designware_udc.h +0 -0
index ae98e8c..8d48ae9 100644

include/usb/designware_udc.h struct udcfifo_regs { · line 202

Quoted 6 lines
include/usb/designware_udc.h +3 -0
@@ -197,6 +197,9 @@ struct udcfifo_regs {
 #define  UDC_INT_PACKET_SIZE		64
 #define  UDC_OUT_ENDPOINT		2
 #define  UDC_BULK_PACKET_SIZE		64
+#if defined(CONFIG_USBD_HS)
+#define  UDC_BULK_HS_PACKET_SIZE	512
+#endif

You can define this without the ifdef

include/usb/designware_udc.h struct udcfifo_regs { · line 205

Quoted 3 lines
include/usb/designware_udc.h +0 -0
 #define  UDC_IN_ENDPOINT		3
 #define  UDC_OUT_PACKET_SIZE		64
 #define  UDC_IN_PACKET_SIZE		64

Best regards,
Marek Vasut

author
#9 lore raw

PATCH 3/4 USB:gadget:designware Support high speed

Dear Marek,

Quoted 22 lines · Marek Vasut

Dear Amit Virdi,

Quoted 20 lines

From: Vipin KUMAR<[email protected]>

This patch adds the support for usb device high speed for designware peripheral.

---
  drivers/usb/gadget/designware_udc.c |   13 +++++++++----
  include/usb/designware_udc.h        |    3 +++
  2 files changed, 12 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/gadget/designware_udc.c index 3c20f3d..d4b53a2 100644

drivers/usb/gadget/designware_udc.c +0 -0
@@ -566,7 +566,7 @@ int udc_init(void)
  	writel(~0x0,&udc_regs_p->dev_int_mask);
  	writel(~0x0,&udc_regs_p->endp_int_mask);
 
Quoted 5 lines

drivers/usb/gadget/designware_udc.c int udc_init(void)

Quoted 3 lines
drivers/usb/gadget/designware_udc.c +1 -1
-	writel(DEV_CONF_FS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
+	writel(DEV_CONF_HS_SPEED | DEV_CONF_REMWAKEUP | DEV_CONF_SELFPOW |
  	       DEV_CONF_PHYINT_16,&udc_regs_p->dev_conf);

Won't this break anything?

You're right. Perhaps, it's better to configure FS only if the FS is configured. I'll amend this part.

Quoted 6 lines
Quoted 6 lines
drivers/usb/gadget/designware_udc.c +0 -0
  	writel(DEV_CNTL_SOFTDISCONNECT,&udc_regs_p->dev_cntl);
@@ -577,6 +577,11 @@ int udc_init(void)
  	return 0;
  }
 
Quoted 17 lines
Quoted 9 lines
drivers/usb/gadget/designware_udc.c +5 -0
+int is_usbd_high_speed(void)
+{
+	return (readl(&udc_regs_p->dev_stat)&  DEV_STAT_ENUM) ? 0 : 1;
+}
+
  /*
   * udc_setup_ep - setup endpoint
   * Associate a physical endpoint with endpoint_instance

drivers/usb/gadget/designware_udc.c void udc_startup_events(struct usb_device_instance · line 800

Quoted 5 lines
drivers/usb/gadget/designware_udc.c +1 -1
@@ -792,7 +797,7 @@ void udc_startup_events(struct usb_device_instance
 *device) /*
   * Plug detection interrupt handling
   */
-void dw_udc_plug_irq(void)
+static void dw_udc_plug_irq(void)

This staticisation stuff should go in a separate patch please.

Ok.

Quoted 21 lines
Quoted 21 lines
drivers/usb/gadget/designware_udc.c +2 -2
  {
  	if (readl(&plug_regs_p->plug_state)&  PLUG_STATUS_ATTACHED) {
  		/*
@@ -816,7 +821,7 @@ void dw_udc_plug_irq(void)
  /*
   * Device interrupt handling
   */
-void dw_udc_dev_irq(void)
+static void dw_udc_dev_irq(void)
  {
  	if (readl(&udc_regs_p->dev_int)&  DEV_INT_USBRESET) {
  		writel(~0x0,&udc_regs_p->endp_int_mask);
@@ -886,7 +891,7 @@ void dw_udc_dev_irq(void)
  /*
   * Endpoint interrupt handling
   */
-void dw_udc_endpoint_irq(void)
+static void dw_udc_endpoint_irq(void)
  {
  	while (readl(&udc_regs_p->endp_int)&  ENDP0_INT_CTRLOUT) {
 
Quoted 14 lines

include/usb/designware_udc.h struct udcfifo_regs { · line 202

Quoted 11 lines
include/usb/designware_udc.h +3 -0
index ae98e8c..8d48ae9 100644
@@ -197,6 +197,9 @@ struct udcfifo_regs {
  #define  UDC_INT_PACKET_SIZE		64
  #define  UDC_OUT_ENDPOINT		2
  #define  UDC_BULK_PACKET_SIZE		64
+#if defined(CONFIG_USBD_HS)
+#define  UDC_BULK_HS_PACKET_SIZE	512
+#endif

You can define this without the ifdef

Ok.

Quoted 4 lines

include/usb/designware_udc.h struct udcfifo_regs { · line 205

Quoted 3 lines
include/usb/designware_udc.h +0 -0
  #define  UDC_IN_ENDPOINT		3
  #define  UDC_OUT_PACKET_SIZE		64
  #define  UDC_IN_PACKET_SIZE		64

Thanks for reviewing.

Best Regards
Amit Virdi

author
#10 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

In reply to Amit Virdi

From: Shiraz Hashim <[email protected]>

While receiving packets from FIFO sometimes the buffer provided was nonaligned. Fix this by taking a temporary aligned buffer and then copying the content to nonaligned buffer.

---
 drivers/usb/gadget/designware_udc.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
drivers/usb/gadget/designware_udc.c +14 -1
index d4b53a2..878123c 100644
@@ -202,6 +202,7 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len)
 	u32 i, nw, nb;
 	u32 *wrdp;
 	u8 *bytp;
+	u32 tmp[128];
 
 	if (readl(&udc_regs_p->dev_stat) & DEV_STAT_RXFIFO_EMPTY)
 		return -1;
@@ -209,7 +210,12 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len)
 	nw = len / sizeof(u32);
 	nb = len % sizeof(u32);
 
-	wrdp = (u32 *)bufp;
+	/* use tmp buf if bufp is not word aligned */
+	if ((int)bufp & 0x3)
+		wrdp = (u32 *)&tmp[0];
+	else
+		wrdp = (u32 *)bufp;
+
 	for (i = 0; i < nw; i++) {
 		writel(readl(fifo_ptr), wrdp);
 		wrdp++;
@@ -223,6 +229,13 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len)
 	}
 	readl(&outep_regs_p[epNum].write_done);
 
+	/* copy back tmp buffer to bufp if bufp is not word aligned */
+	if ((int)bufp & 0x3) {
+		bytp = (u8 *)&tmp[0];
+		for (i = 0; i < len; i++)
+			bufp[i] = bytp[i];
+	}
+
 	return 0;
 }
 
Signature · 1 line
1.7.2.2
#11 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

Dear Amit Virdi,

Quoted 41 lines

From: Shiraz Hashim <[email protected]>

While receiving packets from FIFO sometimes the buffer provided was nonaligned. Fix this by taking a temporary aligned buffer and then copying the content to nonaligned buffer.

---
 drivers/usb/gadget/designware_udc.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/gadget/designware_udc.c index d4b53a2..878123c 100644

drivers/usb/gadget/designware_udc.c +7 -1
@@ -202,6 +202,7 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32
 len) u32 i, nw, nb;
 	u32 *wrdp;
 	u8 *bytp;
+	u32 tmp[128];
 
 	if (readl(&udc_regs_p->dev_stat) & DEV_STAT_RXFIFO_EMPTY)
 		return -1;
@@ -209,7 +210,12 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32
 len) nw = len / sizeof(u32);
 	nb = len % sizeof(u32);
 
-	wrdp = (u32 *)bufp;
+	/* use tmp buf if bufp is not word aligned */
+	if ((int)bufp & 0x3)
+		wrdp = (u32 *)&tmp[0];
+	else
+		wrdp = (u32 *)bufp;
+
 	for (i = 0; i < nw; i++) {
 		writel(readl(fifo_ptr), wrdp);
 		wrdp++;
@@ -223,6 +229,13 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32
 len) }
 	readl(&outep_regs_p[epNum].write_done);

drivers/usb/gadget/designware_udc.c static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 · line 240

Quoted 10 lines
drivers/usb/gadget/designware_udc.c +7 -0
 
+	/* copy back tmp buffer to bufp if bufp is not word aligned */
+	if ((int)bufp & 0x3) {
+		bytp = (u8 *)&tmp[0];
+		for (i = 0; i < len; i++)
+			bufp[i] = bytp[i];
+	}
+
 	return 0;
 }

This addresses EHCI cache problem, that's why you need bounce buffer, right?

This is the patch from Puneet, can you give it a go and tell me if EHCI works for you without 4/4 patch from your series or do you still see issues?

http://permalink.gmane.org/gmane.comp.boot-loaders.u-boot/126447

Thanks in advance!

Best regards,
Marek Vasut

author
#12 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

Dear Marek,

Quoted 44 lines · Marek Vasut

Dear Amit Virdi,

Quoted 42 lines

From: Shiraz Hashim<[email protected]>

While receiving packets from FIFO sometimes the buffer provided was nonaligned. Fix this by taking a temporary aligned buffer and then copying the content to nonaligned buffer.

---
  drivers/usb/gadget/designware_udc.c |   15 ++++++++++++++-
  1 files changed, 14 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/gadget/designware_udc.c index d4b53a2..878123c 100644

drivers/usb/gadget/designware_udc.c +7 -1
@@ -202,6 +202,7 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32
 len) u32 i, nw, nb;
  	u32 *wrdp;
  	u8 *bytp;
+	u32 tmp[128];
 
  	if (readl(&udc_regs_p->dev_stat)&  DEV_STAT_RXFIFO_EMPTY)
  		return -1;
@@ -209,7 +210,12 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32
 len) nw = len / sizeof(u32);
  	nb = len % sizeof(u32);
 
-	wrdp = (u32 *)bufp;
+	/* use tmp buf if bufp is not word aligned */
+	if ((int)bufp&  0x3)
+		wrdp = (u32 *)&tmp[0];
+	else
+		wrdp = (u32 *)bufp;
+
  	for (i = 0; i<  nw; i++) {
  		writel(readl(fifo_ptr), wrdp);
  		wrdp++;
@@ -223,6 +229,13 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp, u32
 len) }
  	readl(&outep_regs_p[epNum].write_done);
 
Quoted 12 lines

drivers/usb/gadget/designware_udc.c static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len) · line 240

Quoted 9 lines
drivers/usb/gadget/designware_udc.c +7 -0
+	/* copy back tmp buffer to bufp if bufp is not word aligned */
+	if ((int)bufp&  0x3) {
+		bytp = (u8 *)&tmp[0];
+		for (i = 0; i<  len; i++)
+			bufp[i] = bytp[i];
+	}
+
  	return 0;
  }

This addresses EHCI cache problem, that's why you need bounce buffer, right?

No. The problem was we were copying data word-by-word to a non-word aligned memory in the USB gadget. So, this is different from the USB host controller issue.

Thanks n Regards
Amit Virdi

Quoted 11 lines

This is the patch from Puneet, can you give it a go and tell me if EHCI works for you without 4/4 patch from your series or do you still see issues?

http://permalink.gmane.org/gmane.comp.boot-loaders.u-boot/126447

Thanks in advance!

Best regards,
Marek Vasut
.

#13 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

Dear Amit Virdi,

Quoted 67 lines

Dear Marek,

Quoted 64 lines · Marek Vasut

Dear Amit Virdi,

Quoted 62 lines

From: Shiraz Hashim<[email protected]>

While receiving packets from FIFO sometimes the buffer provided was nonaligned. Fix this by taking a temporary aligned buffer and then copying the content to nonaligned buffer.

---

  drivers/usb/gadget/designware_udc.c |   15 ++++++++++++++-
  1 files changed, 14 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/gadget/designware_udc.c index d4b53a2..878123c 100644

drivers/usb/gadget/designware_udc.c +1 -0
@@ -202,6 +202,7 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
 u32 len) u32 i, nw, nb;
 
  	u32 *wrdp;
  	u8 *bytp;
 
+	u32 tmp[128];
 

if (readl(&udc_regs_p->dev_stat)& DEV_STAT_RXFIFO_EMPTY)

return -1;

drivers/usb/gadget/designware_udc.c +6 -1
@@ -209,7 +210,12 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
 u32 len) nw = len / sizeof(u32);
 
  	nb = len % sizeof(u32);
 
-	wrdp = (u32 *)bufp;
+	/* use tmp buf if bufp is not word aligned */
+	if ((int)bufp&  0x3)
+		wrdp = (u32 *)&tmp[0];
+	else
+		wrdp = (u32 *)bufp;
+
 
  	for (i = 0; i<  nw; i++) {
  	
  		writel(readl(fifo_ptr), wrdp);
  		wrdp++;
drivers/usb/gadget/designware_udc.c +7 -0
@@ -223,6 +229,13 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
 u32 len) }
 
  	readl(&outep_regs_p[epNum].write_done);
 
+	/* copy back tmp buffer to bufp if bufp is not word aligned */
+	if ((int)bufp&  0x3) {
+		bytp = (u8 *)&tmp[0];
+		for (i = 0; i<  len; i++)
+			bufp[i] = bytp[i];
+	}
+
 
  	return 0;
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
  }

This addresses EHCI cache problem, that's why you need bounce buffer, right?

No. The problem was we were copying data word-by-word to a non-word aligned memory in the USB gadget. So, this is different from the USB host controller issue.

I see ... why isn't buffer aligned by the usb stack then?

Thanks!

Quoted 15 lines

Thanks n Regards
Amit Virdi

Quoted 11 lines

This is the patch from Puneet, can you give it a go and tell me if EHCI works for you without 4/4 patch from your series or do you still see issues?

http://permalink.gmane.org/gmane.comp.boot-loaders.u-boot/126447

Thanks in advance!

Best regards,
Marek Vasut
.

#14 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

Quoted 58 lines · On Tuesday 06 March 2012 04:51:57 Marek Vasut wrote:
Quoted 58 lines · Marek Vasut
Quoted 56 lines
Quoted 51 lines · Amit Virdi

While receiving packets from FIFO sometimes the buffer provided was nonaligned. Fix this by taking a temporary aligned buffer and then copying the content to nonaligned buffer.

drivers/usb/gadget/designware_udc.c +1 -0
@@ -202,6 +202,7 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
 u32 len) u32 i, nw, nb;
 
  	u32 *wrdp;
  	u8 *bytp;
 
+	u32 tmp[128];
 

if (readl(&udc_regs_p->dev_stat)& DEV_STAT_RXFIFO_EMPTY)

return -1;

drivers/usb/gadget/designware_udc.c +6 -1
@@ -209,7 +210,12 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
 u32 len) nw = len / sizeof(u32);
 
  	nb = len % sizeof(u32);
 
-	wrdp = (u32 *)bufp;
+	/* use tmp buf if bufp is not word aligned */
+	if ((int)bufp&  0x3)
+		wrdp = (u32 *)&tmp[0];
+	else
+		wrdp = (u32 *)bufp;
+
 
  	for (i = 0; i<  nw; i++) {
  	
  		writel(readl(fifo_ptr), wrdp);
  		wrdp++;
drivers/usb/gadget/designware_udc.c +7 -0
@@ -223,6 +229,13 @@ static int usbgetpckfromfifo(int epNum, u8 *bufp,
 u32 len) }
 
  	readl(&outep_regs_p[epNum].write_done);
 
+	/* copy back tmp buffer to bufp if bufp is not word aligned */
+	if ((int)bufp&  0x3) {
+		bytp = (u8 *)&tmp[0];
+		for (i = 0; i<  len; i++)
+			bufp[i] = bytp[i];
+	}
+
 
  	return 0;
Quoted 1 line
  }

This addresses EHCI cache problem, that's why you need bounce buffer, right?

Quoted 5 lines
Quoted 3 lines

No. The problem was we were copying data word-by-word to a non-word aligned memory in the USB gadget. So, this is different from the USB host controller issue.

I see ... why isn't buffer aligned by the usb stack then?

because it might not be a requirement higher up. i.e. it's dealing with a data byte stream. forcing all higher layers to use 32bit alignment because this host controller requires 32bit alignment in its FIFOs is incorrect. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120306/3e706ea1/attachment.pgp>

author
#15 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

Dear Marek,

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
   }

This addresses EHCI cache problem, that's why you need bounce buffer, right?

No. The problem was we were copying data word-by-word to a non-word aligned memory in the USB gadget. So, this is different from the USB host controller issue.

Quoted 5 lines
Quoted 1 line

I see ... why isn't buffer aligned by the usb stack then?

because it might not be a requirement higher up. i.e. it's dealing with a data byte stream. forcing all higher layers to use 32bit alignment because this host controller requires 32bit alignment in its FIFOs is incorrect.

The usb gadget is used by the usbtty so we can receive any number of bytes and, as Mike explains, we cannot force 32-bit alignment.

Thanks
Amit Virdi

#16 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

In reply to Amit Virdi

drivers/usb/gadget/designware_udc.c static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len) · line 237

Quoted 9 lines · On Thursday 16 February 2012 07:03:38 Amit Virdi wrote:
drivers/usb/gadget/designware_udc.c +6 -0
 
+	/* copy back tmp buffer to bufp if bufp is not word aligned */
+	if ((int)bufp & 0x3) {
+		bytp = (u8 *)&tmp[0];
+		for (i = 0; i < len; i++)
+			bufp[i] = bytp[i];
+	}

memcpy(bufp, tmp, len) ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120306/ee72f671/attachment.pgp>

author
#17 lore raw

PATCH 4/4 USB:gadget:designware Fix memory nonalignment issue

Hey Mike,

Quoted 4 lines · Mike Frysinger
Quoted 3 lines · On Thursday 16 February 2012 07:03:38 Amit Virdi wrote:
drivers/usb/gadget/designware_udc.c +0 -0
Quoted 8 lines

drivers/usb/gadget/designware_udc.c static int usbgetpckfromfifo(int epNum, u8 *bufp, u32 len) · line 237

Quoted 6 lines
drivers/usb/gadget/designware_udc.c +6 -0
+	/* copy back tmp buffer to bufp if bufp is not word aligned */
+	if ((int)bufp&  0x3) {
+		bytp = (u8 *)&tmp[0];
+		for (i = 0; i<  len; i++)
+			bufp[i] = bytp[i];
+	}

memcpy(bufp, tmp, len) ?

Yes, memcpy can be used. I'll amend the code.

Thanks
Amit Virdi

#18 lore raw

cover USB: Add support for designware UDC

In reply to Amit Virdi

Hello Remy,

Quoted 17 lines · Amit Virdi

Support for designware USB device controller (UDC) exists in the u-boot for SPEAr platform. This patchset makes the driver more generic so that it can be used across multiple platforms.

Shiraz Hashim (1):
?USB:gadget:designware Fix memory nonalignment issue

Vipin KUMAR (3):
?USB:gadget:designware USB device controller (UDC) implementation ?USB:gadget:designware Device controller bugfixes ?USB:gadget:designware Support high speed

?drivers/serial/usbtty.h ? ? ? ? ? ? ? ? ? ? ? ? ? ?| ? ?4 +-
?drivers/usb/gadget/Makefile ? ? ? ? ? ? ? ? ? ? ? ?| ? ?2 +-
?drivers/usb/gadget/{spr_udc.c => designware_udc.c} | ?138 ++++++++++++--------
?include/configs/spear-common.h ? ? ? ? ? ? ? ? ? ? | ? ?4 +-
?include/usb/{spr_udc.h => designware_udc.h} ? ? ? ?| ? ?9 +-
Quoted 7 lines

?5 files changed, 98 insertions(+), 59 deletions(-) ?rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (89%) ?rename include/usb/{spr_udc.h => designware_udc.h} (97%)

--
1.7.2.2

Any comment on this patchset?

Thanks
Amit Virdi

#19 lore raw

cover USB: Add support for designware UDC

Dear Amit Virdi,

Quoted 25 lines

Hello Remy,

Quoted 22 lines · Amit Virdi

Support for designware USB device controller (UDC) exists in the u-boot for SPEAr platform. This patchset makes the driver more generic so that it can be used across multiple platforms.

Shiraz Hashim (1):
USB:gadget:designware Fix memory nonalignment issue

Vipin KUMAR (3):
USB:gadget:designware USB device controller (UDC) implementation USB:gadget:designware Device controller bugfixes USB:gadget:designware Support high speed

 drivers/serial/usbtty.h                            |    4 +-
 drivers/usb/gadget/Makefile                        |    2 +-
 drivers/usb/gadget/{spr_udc.c => designware_udc.c} |  138
++++++++++++-------- include/configs/spear-common.h                    
|    4 +-
 include/usb/{spr_udc.h => designware_udc.h}        |    9 +-
 5 files changed, 98 insertions(+), 59 deletions(-)
 rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (89%)
 rename include/usb/{spr_udc.h => designware_udc.h} (97%)
Quoted 7 lines
Quoted 2 lines

--
1.7.2.2

Any comment on this patchset?

Thanks
Amit Virdi

I took over after Remy, let's sort this out.

Best regards,
Marek Vasut