All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vipin KUMAR <vipin.kumar@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 17/28] SPEAr : USB device controller bugfixes
Date: Wed, 14 Jul 2010 10:39:53 +0530	[thread overview]
Message-ID: <1279084204-3263-18-git-send-email-vipin.kumar@st.com> (raw)
In-Reply-To: <1279084204-3263-17-git-send-email-vipin.kumar@st.com>

From: Vipin KUMAR <vipin.kumar@st.com>

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

Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
---
 drivers/usb/gadget/designware_udc.c |   59 ++++++++++++++++++++++------------
 1 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/gadget/designware_udc.c b/drivers/usb/gadget/designware_udc.c
index aee44aa..3c20f3d 100644
--- a/drivers/usb/gadget/designware_udc.c
+++ b/drivers/usb/gadget/designware_udc.c
@@ -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;
-- 
1.6.0.2

  reply	other threads:[~2010-07-14  5:09 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-14  5:09 [U-Boot] [PATCH 00/28] Support for SPEAr13xx boards added Vipin KUMAR
2010-07-14  5:09 ` [U-Boot] [PATCH 01/28] change_bit routine defined Vipin KUMAR
2010-07-14  5:09   ` [U-Boot] [PATCH 02/28] SPEAr : SMI erase and write timeouts increased Vipin KUMAR
2010-07-14  5:09     ` [U-Boot] [PATCH 03/28] SPEAr : Placing ethaddr write and read within CONFIG_CMD_NET Vipin KUMAR
2010-07-14  5:09       ` [U-Boot] [PATCH 04/28] SPEAr : Reducing the max RAM size to 128MB Vipin KUMAR
2010-07-14  5:09         ` [U-Boot] [PATCH 05/28] SPEAr : Basic arch related support added for SPEAr SoCs Vipin KUMAR
2010-07-14  5:09           ` [U-Boot] [PATCH 06/28] SPEAr : Network support configured for spear SoCs Vipin KUMAR
2010-07-14  5:09             ` [U-Boot] [PATCH 07/28] SPEAr : macb driver support added for spear310 and spear320 Vipin KUMAR
2010-07-14  5:09               ` [U-Boot] [PATCH 08/28] SPEAr : FSMC driver support added Vipin KUMAR
2010-07-14  5:09                 ` [U-Boot] [PATCH 09/28] SPEAr : Configuring FSMC driver for NAND interface Vipin KUMAR
2010-07-14  5:09                   ` [U-Boot] [PATCH 10/28] SPEAr : i2c driver moved completely into drivers/i2c Vipin KUMAR
2010-07-14  5:09                     ` [U-Boot] [PATCH 11/28] SPEAr : smi driver moved completely into drivers/mtd Vipin KUMAR
2010-07-14  5:09                       ` [U-Boot] [PATCH 12/28] SPEAr : USB Device Controller driver support added Vipin KUMAR
2010-07-14  5:09                         ` [U-Boot] [PATCH 13/28] SPEAr : Supporting various configurations for spear3xx and spear6xx boards Vipin KUMAR
2010-07-14  5:09                           ` [U-Boot] [PATCH 14/28] SPEAr : Basic spear1300 architecture support added Vipin KUMAR
2010-07-14  5:09                             ` [U-Boot] [PATCH 15/28] SPEAr : spear1300 SoC " Vipin KUMAR
2010-07-14  5:09                               ` [U-Boot] [PATCH 16/28] SPEAr : Removing extraneous code Vipin KUMAR
2010-07-14  5:09                                 ` Vipin KUMAR [this message]
2010-07-14  5:09                                   ` [U-Boot] [PATCH 18/28] SPEAr : Network driver fixes Vipin KUMAR
2010-07-14  5:09                                     ` [U-Boot] [PATCH 19/28] SPEAr : Changing the default environment variable bootargs Vipin KUMAR
2010-07-14  5:09                                       ` [U-Boot] [PATCH 20/28] SPEAr1300: Workaround the UHC problem (issue #101435) Vipin KUMAR
2010-07-14  5:09                                         ` [U-Boot] [PATCH 21/28] Enable high speed support for usb device framework and usbtty Vipin KUMAR
2010-07-14  5:09                                           ` [U-Boot] [PATCH 22/28] SPEAr : High speed support for designware peripheral Vipin KUMAR
2010-07-14  5:09                                             ` [U-Boot] [PATCH 23/28] SPEAr : Enable usb device high speed support Vipin KUMAR
2010-07-14  5:10                                               ` [U-Boot] [PATCH 24/28] SPEAr : Network support configuration Vipin KUMAR
2010-07-14  5:10                                                 ` [U-Boot] [PATCH 25/28] SPEAr : Enabling GPT clock explicitly Vipin KUMAR
2010-07-14  5:10                                                   ` [U-Boot] [PATCH 26/28] SPEAr : smi_init moved to board_init Vipin KUMAR
2010-07-14  5:10                                                     ` [U-Boot] [PATCH 27/28] SPEAr : Ethernet issue workaround is not needed when uboot is acting as flashing Vipin KUMAR
2010-07-14  5:10                                                       ` [U-Boot] [PATCH 28/28] SPEAr1310 : spear1310 support added Vipin KUMAR
2010-07-15 22:14                                                         ` Wolfgang Denk
2010-07-15 22:12                                                       ` [U-Boot] [PATCH 27/28] SPEAr : Ethernet issue workaround is not needed when uboot is acting as flashing Wolfgang Denk
2010-07-15 22:10                                                   ` [U-Boot] [PATCH 25/28] SPEAr : Enabling GPT clock explicitly Wolfgang Denk
2010-07-15 22:09                                                 ` [U-Boot] [PATCH 24/28] SPEAr : Network support configuration Wolfgang Denk
2010-08-01 11:06                                             ` [U-Boot] [PATCH 22/28] SPEAr : High speed support for designware peripheral Remy Bohmer
2010-07-15 22:08                                           ` [U-Boot] [PATCH 21/28] Enable high speed support for usb device framework and usbtty Wolfgang Denk
2010-08-01 11:11                                   ` [U-Boot] [PATCH 17/28] SPEAr : USB device controller bugfixes Remy Bohmer
2010-07-15 22:04                               ` [U-Boot] [PATCH 15/28] SPEAr : spear1300 SoC support added Wolfgang Denk
2010-07-16  4:45                                 ` Vipin KUMAR
2010-07-15 22:01                             ` [U-Boot] [PATCH 14/28] SPEAr : Basic spear1300 architecture " Wolfgang Denk
2010-07-15 21:55                           ` [U-Boot] [PATCH 13/28] SPEAr : Supporting various configurations for spear3xx and spear6xx boards Wolfgang Denk
2010-07-16 11:24                             ` Wolfgang Denk
2010-07-16 11:41                               ` Reinhard Meyer
2010-07-19  3:41                               ` Vipin KUMAR
2010-08-01 11:08                         ` [U-Boot] [PATCH 12/28] SPEAr : USB Device Controller driver support added Remy Bohmer
2010-07-15 21:41                 ` [U-Boot] [PATCH 08/28] SPEAr : FSMC " Wolfgang Denk
2010-07-15 21:38               ` [U-Boot] [PATCH 07/28] SPEAr : macb driver support added for spear310 and spear320 Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1279084204-3263-18-git-send-email-vipin.kumar@st.com \
    --to=vipin.kumar@st.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.