USB: Add support for designware UDC
v2 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.
V2:
- Configure the gadget in HS only if CONFIG_USBD_HS is defined
- Made local functions static in a separate commit
- In "Fix memory nonalignment issue" used memcpy instead of copying byte-by-byte
- Define the HS_PACKET_SIZE unconditionally
V1:
- Added support for designware UDC in a more generic way
Amit Virdi (1):
USB:gadget:designware Make locally used functions static
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} | 7 +-
5 files changed, 97 insertions(+), 58 deletions(-)
rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (89%)
rename include/usb/{spr_udc.h => designware_udc.h} (98%)Signature · 1 line
1.7.2.2
PATCH v2 1/5 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 2/5 USB:gadget:designware Device controller bugfixes
In reply to Amit VirdiFrom: 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
@@ -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
PATCH v2 3/5 USB:gadget:designware Support high speed
In reply to Amit VirdiFrom: Vipin KUMAR <[email protected]>
This patch adds the support for usb device high speed for designware peripheral.
--- drivers/usb/gadget/designware_udc.c | 10 ++++++++++ include/usb/designware_udc.h | 1 + 2 files changed, 11 insertions(+), 0 deletions(-)
drivers/usb/gadget/designware_udc.c +10 -0
@@ -566,8 +566,13 @@ int udc_init(void)writel (~0x0 , &udc_regs_p->dev_int_mask);writel (~0x0 , &udc_regs_p->endp_int_mask); +#ifndef CONFIG_USBD_HS writel (DEV_CONF_FS_SPEED |DEV_CONF_REMWAKEUP |DEV_CONF_SELFPOW |DEV_CONF_PHYINT_16 , &udc_regs_p->dev_conf); +#else +writel (DEV_CONF_HS_SPEED |DEV_CONF_REMWAKEUP |DEV_CONF_SELFPOW | +DEV_CONF_PHYINT_16 , &udc_regs_p->dev_conf); +#endif writel (DEV_CNTL_SOFTDISCONNECT , &udc_regs_p->dev_cntl);
@@ -577,6 +582,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
include/usb/designware_udc.h +1 -0
@@ -197,6 +197,7 @@ struct udcfifo_regs {#define UDC_INT_PACKET_SIZE 64#define UDC_OUT_ENDPOINT 2#define UDC_BULK_PACKET_SIZE 64 +#define UDC_BULK_HS_PACKET_SIZE 512#define UDC_IN_ENDPOINT 3#define UDC_OUT_PACKET_SIZE 64#define UDC_IN_PACKET_SIZE 64
Signature · 1 line
1.7.2.2
PATCH v2 4/5 USB:gadget:designware Make locally used functions static
In reply to Amit Virdi--- drivers/usb/gadget/designware_udc.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/designware_udc.c +3 -3
@@ -802,7 +802,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 ) {/*
@@ -826,7 +826,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);
@@ -896,7 +896,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 ) {
Signature · 1 line
1.7.2.2
PATCH v2 5/5 USB:gadget:designware Fix memory nonalignment issue
In reply to Amit VirdiFrom: 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 | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
drivers/usb/gadget/designware_udc.c +11 -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,10 @@ 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 ) +memcpy (bufp, tmp, len); +return 0 ; }
Signature · 1 line
1.7.2.2
v2 cover USB: Add support for designware UDC
In reply to Amit VirdiQuoted 31 lines · On Wed, 07 Mar 2012 15:09:36 +0530 Amit Virdi <[email protected]> wrote:
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.
V2:
- Configure the gadget in HS only ifCONFIG_USBD_HSis defined
- Made local functions static in a separate commit
- In "Fix memory nonalignment issue" used memcpy instead of copying byte-by-byte
- Define theHS_PACKET_SIZEunconditionallyV1:
- Added support for designware UDC in a more generic wayAmit Virdi (1):
USB:gadget:designware Make locally used functions staticShiraz Hashim (1):
USB:gadget:designware Fix memory nonalignment issueVipin KUMAR (3):
USB:gadget:designware USB device controller (UDC) implementation USB:gadget:designware Device controller bugfixes USB:gadget:designware Support high speeddrivers/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} | 7 +- 5 files
Quoted 4 lines
changed, 97 insertions(+), 58 deletions(-) rename
drivers/usb/gadget/{spr_udc.c=>designware_udc.c} (89%) renameinclude/usb/{spr_udc.h=>designware_udc.h} (98%)
Hi Amit,
Is this driver a Synopsis DWC2 or DWC3 UDC controller?
Signature · 6 lines
Best regards, Lukasz Majewski Samsung Poland R&D Center Platform Group
v2 cover USB: Add support for designware UDC
Hi Lukasz,
Quoted 1 line · On Wednesday 07 March 2012 12:19:11 Lukasz Majewski wrote:
Is this driver a Synopsis DWC2 or DWC3 UDC controller?
DWC2! Is there already such a driver in mainline U-Boot? Are you working on something here (I know that you are working on the Linux driver generalization)?
Thanks,
Stefan
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de
v2 cover USB: Add support for designware UDC
In reply to Amit VirdiDear Amit Virdi,
Quoted 25 lines
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.
V2:
- Configure the gadget in HS only ifCONFIG_USBD_HSis defined
- Made local functions static in a separate commit
- In "Fix memory nonalignment issue" used memcpy instead of copying byte-by-byte
- Define theHS_PACKET_SIZEunconditionallyV1:
- Added support for designware UDC in a more generic wayAmit Virdi (1):
USB:gadget:designware Make locally used functions staticShiraz Hashim (1):
USB:gadget:designware Fix memory nonalignment issueVipin KUMAR (3):
USB:gadget:designware USB device controller (UDC) implementation USB:gadget:designware Device controller bugfixes USB:gadget:designware Support high speed
Quoted 9 lines
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} | 7 +-
5 files changed, 97 insertions(+), 58 deletions(-)
rename drivers/usb/gadget/{spr_udc.c => designware_udc.c} (89%)
rename include/usb/{spr_udc.h => designware_udc.h} (98%)Thank you for your efforts, I'll apply these.
Best regards,
Marek Vasut
v2 cover USB: Add support for designware UDC
Dear Marek,
Quoted 37 lines · Marek Vasut
Dear Amit Virdi,
Quoted 28 lines
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.
V2:
?- Configure the gadget in HS only ifCONFIG_USBD_HSis defined ?- Made local functions static in a separate commit
?- In "Fix memory nonalignment issue" used memcpy instead of copying ? ?byte-by-byte
?- Define theHS_PACKET_SIZEunconditionallyV1:
?- Added support for designware UDC in a more generic wayAmit Virdi (1):
? USB:gadget:designware Make locally used functions staticShiraz Hashim (1):
? USB:gadget:designware Fix memory nonalignment issueVipin 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} | ?138Quoted 6 lines
++++++++++++-------
include/configs/spear-common.h? ? ? ? ? ? ? ? ? ? | ?4 +-
?include/usb/{spr_udc.h =>designware_udc.h} ? ? ? ?| ? ?7 +- ?5 files changed, 97 insertions(+), 58 deletions(-)
?renamedrivers/usb/gadget/{spr_udc.c=>designware_udc.c} (89%) ?renameinclude/usb/{spr_udc.h=>designware_udc.h} (98%)
Quoted 1 line
Thank you for your efforts, I'll apply these.
Thanks.
Regards
Amit Virdi