From 2721551a11e64ac639547211dae027eea476af4c Mon Sep 17 00:00:00 2001 From: Vipin KUMAR Date: Tue, 6 Mar 2012 23:39:37 +0000 Subject: [PATCH] USB:gadget:designware USB device controller (UDC) implementation 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. Signed-off-by: Vipin Kumar Signed-off-by: Amit Virdi Acked-by: Marek Vasut --- 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%) diff --git a/drivers/serial/usbtty.h b/drivers/serial/usbtty.h index e449cd7..60347d7 100644 --- a/drivers/serial/usbtty.h +++ b/drivers/serial/usbtty.h @@ -33,8 +33,8 @@ #include #elif defined(CONFIG_CPU_PXA27X) #include -#elif defined(CONFIG_SPEAR3XX) || defined(CONFIG_SPEAR600) -#include +#elif defined(CONFIG_DW_UDC) +#include #endif #include diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 64b091f..87d1918 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile @@ -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 diff --git a/drivers/usb/gadget/spr_udc.c b/drivers/usb/gadget/designware_udc.c similarity index 94% rename from drivers/usb/gadget/spr_udc.c rename to drivers/usb/gadget/designware_udc.c index f2b06d6..aee44aa 100644 --- a/drivers/usb/gadget/spr_udc.c +++ b/drivers/usb/gadget/designware_udc.c @@ -29,14 +29,13 @@ #include #include "ep0.h" -#include +#include #include -#include #define UDC_INIT_MDELAY 80 /* Device settle delay */ /* Some kind of debugging output... */ -#ifndef DEBUG_SPRUSBTTY +#ifndef DEBUG_DWUSBTTY #define UDCDBG(str) #define UDCDBGA(fmt, args...) #else @@ -251,7 +250,7 @@ static void usbputpcktofifo(int epNum, u8 *bufp, u32 len) } /* - * spear_write_noniso_tx_fifo - Write the next packet to TxFIFO. + * dw_write_noniso_tx_fifo - Write the next packet to TxFIFO. * @endpoint: Endpoint pointer. * * If the endpoint has an active tx_urb, then the next packet of data from the @@ -263,7 +262,7 @@ static void usbputpcktofifo(int epNum, u8 *bufp, u32 len) * transmitted in this packet. * */ -static void spear_write_noniso_tx_fifo(struct usb_endpoint_instance +static void dw_write_noniso_tx_fifo(struct usb_endpoint_instance *endpoint) { struct urb *urb = endpoint->tx_urb; @@ -307,7 +306,7 @@ static void spear_write_noniso_tx_fifo(struct usb_endpoint_instance * Handle SETUP USB interrupt. * This function implements TRM Figure 14-14. */ -static void spear_udc_setup(struct usb_endpoint_instance *endpoint) +static void dw_udc_setup(struct usb_endpoint_instance *endpoint) { u8 *datap = (u8 *)&ep0_urb->device_request; int ep_addr = endpoint->endpoint_address; @@ -344,11 +343,11 @@ static void spear_udc_setup(struct usb_endpoint_instance *endpoint) endpoint->tx_urb = ep0_urb; endpoint->sent = 0; /* - * Write packet data to the FIFO. spear_write_noniso_tx_fifo + * Write packet data to the FIFO. dw_write_noniso_tx_fifo * will update endpoint->last with the number of bytes written * to the FIFO. */ - spear_write_noniso_tx_fifo(endpoint); + dw_write_noniso_tx_fifo(endpoint); writel(0x0, &inep_regs_p[ep_addr].write_done); } @@ -361,7 +360,7 @@ static void spear_udc_setup(struct usb_endpoint_instance *endpoint) /* * Handle endpoint 0 RX interrupt */ -static void spear_udc_ep0_rx(struct usb_endpoint_instance *endpoint) +static void dw_udc_ep0_rx(struct usb_endpoint_instance *endpoint) { u8 dummy[64]; @@ -395,7 +394,7 @@ static void spear_udc_ep0_rx(struct usb_endpoint_instance *endpoint) /* * Handle endpoint 0 TX interrupt */ -static void spear_udc_ep0_tx(struct usb_endpoint_instance *endpoint) +static void dw_udc_ep0_tx(struct usb_endpoint_instance *endpoint) { struct usb_device_request *request = &ep0_urb->device_request; int ep_addr; @@ -444,7 +443,7 @@ static void spear_udc_ep0_tx(struct usb_endpoint_instance *endpoint) * need a zero-length terminating packet. */ UDCDBG("ACK control read data stage packet"); - spear_write_noniso_tx_fifo(endpoint); + dw_write_noniso_tx_fifo(endpoint); ep_addr = endpoint->endpoint_address; writel(0x0, &inep_regs_p[ep_addr].write_done); @@ -452,7 +451,7 @@ static void spear_udc_ep0_tx(struct usb_endpoint_instance *endpoint) } } -static struct usb_endpoint_instance *spear_find_ep(int ep) +static struct usb_endpoint_instance *dw_find_ep(int ep) { int i; @@ -469,11 +468,11 @@ static struct usb_endpoint_instance *spear_find_ep(int ep) * The ep argument is a physical endpoint number for a non-ISO IN endpoint * in the range 1 to 15. */ -static void spear_udc_epn_rx(int ep) +static void dw_udc_epn_rx(int ep) { int nbytes = 0; struct urb *urb; - struct usb_endpoint_instance *endpoint = spear_find_ep(ep); + struct usb_endpoint_instance *endpoint = dw_find_ep(ep); if (endpoint) { urb = endpoint->rcv_urb; @@ -494,9 +493,9 @@ static void spear_udc_epn_rx(int ep) * The ep argument is a physical endpoint number for a non-ISO IN endpoint * in the range 16 to 30. */ -static void spear_udc_epn_tx(int ep) +static void dw_udc_epn_tx(int ep) { - struct usb_endpoint_instance *endpoint = spear_find_ep(ep); + struct usb_endpoint_instance *endpoint = dw_find_ep(ep); /* * We need to transmit a terminating zero-length packet now if @@ -516,7 +515,7 @@ static void spear_udc_epn_tx(int ep) */ if (endpoint->tx_urb && endpoint->tx_urb->actual_length) { /* write data to FIFO */ - spear_write_noniso_tx_fifo(endpoint); + dw_write_noniso_tx_fifo(endpoint); writel(0x0, &inep_regs_p[ep].write_done); } else if (endpoint->tx_urb @@ -765,7 +764,7 @@ void udc_startup_events(struct usb_device_instance *device) * DEVICE_HUB_CONFIGURED and DEVICE_RESET events here. * DEVICE_HUB_CONFIGURED causes a transition to the state STATE_POWERED, * and DEVICE_RESET causes a transition to the state STATE_DEFAULT. - * The SPEAr USB client controller has the capability to detect when the + * The DW USB client controller has the capability to detect when the * USB cable is connected to a powered USB bus, so we will defer the * DEVICE_HUB_CONFIGURED and DEVICE_RESET events until later. */ @@ -776,7 +775,7 @@ void udc_startup_events(struct usb_device_instance *device) /* * Plug detection interrupt handling */ -void spear_udc_plug_irq(void) +void dw_udc_plug_irq(void) { if (readl(&plug_regs_p->plug_state) & PLUG_STATUS_ATTACHED) { /* @@ -805,7 +804,7 @@ void spear_udc_plug_irq(void) /* * Device interrupt handling */ -void spear_udc_dev_irq(void) +void dw_udc_dev_irq(void) { if (readl(&udc_regs_p->dev_int) & DEV_INT_USBRESET) { writel(~0x0, &udc_regs_p->endp_int_mask); @@ -870,7 +869,7 @@ void spear_udc_dev_irq(void) /* * Endpoint interrupt handling */ -void spear_udc_endpoint_irq(void) +void dw_udc_endpoint_irq(void) { while (readl(&udc_regs_p->endp_int) & ENDP0_INT_CTRLOUT) { @@ -878,13 +877,13 @@ void spear_udc_endpoint_irq(void) if ((readl(&outep_regs_p[0].endp_status) & ENDP_STATUS_OUTMSK) == ENDP_STATUS_OUT_SETUP) { - spear_udc_setup(udc_device->bus->endpoint_array + 0); + dw_udc_setup(udc_device->bus->endpoint_array + 0); writel(ENDP_STATUS_OUT_SETUP, &outep_regs_p[0].endp_status); } else if ((readl(&outep_regs_p[0].endp_status) & ENDP_STATUS_OUTMSK) == ENDP_STATUS_OUT_DATA) { - spear_udc_ep0_rx(udc_device->bus->endpoint_array + 0); + dw_udc_ep0_rx(udc_device->bus->endpoint_array + 0); writel(ENDP_STATUS_OUT_DATA, &outep_regs_p[0].endp_status); @@ -897,7 +896,7 @@ void spear_udc_endpoint_irq(void) } if (readl(&udc_regs_p->endp_int) & ENDP0_INT_CTRLIN) { - spear_udc_ep0_tx(udc_device->bus->endpoint_array + 0); + dw_udc_ep0_tx(udc_device->bus->endpoint_array + 0); writel(ENDP_STATUS_IN, &inep_regs_p[0].endp_status); writel(ENDP0_INT_CTRLIN, &udc_regs_p->endp_int); @@ -919,7 +918,7 @@ void spear_udc_endpoint_irq(void) if ((readl(&outep_regs_p[epnum].endp_status) & ENDP_STATUS_OUTMSK) == ENDP_STATUS_OUT_DATA) { - spear_udc_epn_rx(epnum); + dw_udc_epn_rx(epnum); writel(ENDP_STATUS_OUT_DATA, &outep_regs_p[epnum].endp_status); } else if ((readl(&outep_regs_p[epnum].endp_status) & @@ -941,7 +940,7 @@ void spear_udc_endpoint_irq(void) if (readl(&inep_regs_p[epnum].endp_status) & ENDP_STATUS_IN) { writel(ENDP_STATUS_IN, &outep_regs_p[epnum].endp_status); - spear_udc_epn_tx(epnum); + dw_udc_epn_tx(epnum); writel(ENDP_STATUS_IN, &outep_regs_p[epnum].endp_status); @@ -963,13 +962,13 @@ void udc_irq(void) * host requests. */ while (readl(&plug_regs_p->plug_pending)) - spear_udc_plug_irq(); + dw_udc_plug_irq(); while (readl(&udc_regs_p->dev_int)) - spear_udc_dev_irq(); + dw_udc_dev_irq(); if (readl(&udc_regs_p->endp_int)) - spear_udc_endpoint_irq(); + dw_udc_endpoint_irq(); } /* Flow control */ diff --git a/include/configs/spear-common.h b/include/configs/spear-common.h index 55d19b5..5fef8cc 100644 --- a/include/configs/spear-common.h +++ b/include/configs/spear-common.h @@ -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 diff --git a/include/usb/spr_udc.h b/include/usb/designware_udc.h similarity index 98% rename from include/usb/spr_udc.h rename to include/usb/designware_udc.h index 2c332d5..ae98e8c 100644 --- a/include/usb/spr_udc.h +++ b/include/usb/designware_udc.h @@ -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 */ -- 2.7.4