diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/serial/usbtty.c | 2 | ||||
-rw-r--r-- | drivers/serial/usbtty.h | 10 | ||||
-rw-r--r-- | drivers/usb/gadget/Makefile | 53 | ||||
-rw-r--r-- | drivers/usb/gadget/core.c (renamed from drivers/usb/usbdcore.c) | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/ep0.c (renamed from drivers/usb/usbdcore_ep0.c) | 2 | ||||
-rw-r--r-- | drivers/usb/gadget/ep0.h | 39 | ||||
-rw-r--r-- | drivers/usb/gadget/mpc8xx_udc.c (renamed from drivers/usb/usbdcore_mpc8xx.c) | 9 | ||||
-rw-r--r-- | drivers/usb/gadget/omap1510_udc.c (renamed from drivers/usb/usbdcore_omap1510.c) | 6 | ||||
-rw-r--r-- | drivers/usb/gadget/pxa27x_udc.c | 702 | ||||
-rw-r--r-- | drivers/usb/host/Makefile (renamed from drivers/usb/Makefile) | 37 | ||||
-rw-r--r-- | drivers/usb/host/ehci-core.h (renamed from drivers/usb/usb_ehci_core.h) | 0 | ||||
-rw-r--r-- | drivers/usb/host/ehci-fsl.c (renamed from drivers/usb/usb_ehci_fsl.c) | 6 | ||||
-rw-r--r-- | drivers/usb/host/ehci-fsl.h (renamed from drivers/usb/usb_ehci_fsl.h) | 0 | ||||
-rw-r--r-- | drivers/usb/host/ehci-hcd.c (renamed from drivers/usb/usb_ehci_core.c) | 3 | ||||
-rw-r--r-- | drivers/usb/host/ehci-ixp4xx.c (renamed from drivers/usb/usb_ehci_ixp.c) | 5 | ||||
-rw-r--r-- | drivers/usb/host/ehci-pci.c (renamed from drivers/usb/usb_ehci_pci.c) | 5 | ||||
-rw-r--r-- | drivers/usb/host/ehci-vct.c (renamed from drivers/usb/usb_ehci_vct.c) | 4 | ||||
-rw-r--r-- | drivers/usb/host/ehci.h (renamed from drivers/usb/usb_ehci.h) | 0 | ||||
-rw-r--r-- | drivers/usb/host/isp116x-hcd.c (renamed from drivers/usb/isp116x-hcd.c) | 0 | ||||
-rw-r--r-- | drivers/usb/host/isp116x.h (renamed from drivers/usb/isp116x.h) | 0 | ||||
-rw-r--r-- | drivers/usb/host/ohci-at91.c (renamed from drivers/usb/atmel_usb.c) | 0 | ||||
-rw-r--r-- | drivers/usb/host/ohci-hcd.c (renamed from drivers/usb/usb_ohci.c) | 3 | ||||
-rw-r--r-- | drivers/usb/host/ohci.h (renamed from drivers/usb/usb_ohci.h) | 0 | ||||
-rw-r--r-- | drivers/usb/host/r8a66597-hcd.c (renamed from drivers/usb/r8a66597-hcd.c) | 0 | ||||
-rw-r--r-- | drivers/usb/host/r8a66597.h (renamed from drivers/usb/r8a66597.h) | 0 | ||||
-rw-r--r-- | drivers/usb/host/s3c64xx-hcd.c (renamed from drivers/usb/s3c64xx_usb.c) | 0 | ||||
-rw-r--r-- | drivers/usb/host/sl811-hcd.c (renamed from drivers/usb/sl811_usb.c) | 2 | ||||
-rw-r--r-- | drivers/usb/host/sl811.h (renamed from drivers/usb/sl811.h) | 0 | ||||
-rw-r--r-- | drivers/usb/musb/Makefile | 47 | ||||
-rw-r--r-- | drivers/usb/musb/davinci.c (renamed from drivers/usb/davinci_usb.c) | 2 | ||||
-rw-r--r-- | drivers/usb/musb/davinci.h (renamed from drivers/usb/davinci_usb.h) | 0 | ||||
-rw-r--r-- | drivers/usb/musb/musb_core.c (renamed from drivers/usb/musb_core.c) | 0 | ||||
-rw-r--r-- | drivers/usb/musb/musb_core.h (renamed from drivers/usb/musb_core.h) | 0 | ||||
-rw-r--r-- | drivers/usb/musb/musb_hcd.c (renamed from drivers/usb/musb_hcd.c) | 0 | ||||
-rw-r--r-- | drivers/usb/musb/musb_hcd.h (renamed from drivers/usb/musb_hcd.h) | 0 |
35 files changed, 888 insertions, 51 deletions
diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c index d8b1387..f711d0b 100644 --- a/drivers/serial/usbtty.c +++ b/drivers/serial/usbtty.c @@ -94,7 +94,7 @@ static char serial_number[16]; * Descriptors, Strings, Local variables. */ -/* defined and used by usbdcore_ep0.c */ +/* defined and used by gadget/ep0.c */ extern struct usb_string_descriptor **usb_strings; /* Indicies, References */ diff --git a/drivers/serial/usbtty.h b/drivers/serial/usbtty.h index ecefde5..f746d63 100644 --- a/drivers/serial/usbtty.h +++ b/drivers/serial/usbtty.h @@ -24,11 +24,13 @@ #ifndef __USB_TTY_H__ #define __USB_TTY_H__ -#include <usbdcore.h> +#include <usbdevice.h> #if defined(CONFIG_PPC) -#include <usbdcore_mpc8xx.h> -#elif defined(CONFIG_ARM) -#include <usbdcore_omap1510.h> +#include <usb/mpc8xx_udc.h> +#elif defined(CONFIG_OMAP1510) +#include <usb/omap1510_udc.h> +#elif defined(CONFIG_PXA27X) +#include <usb/pxa27x_udc.h> #endif #include <version_autogenerated.h> diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile new file mode 100644 index 0000000..2a19b1e --- /dev/null +++ b/drivers/usb/gadget/Makefile @@ -0,0 +1,53 @@ +# +# (C) Copyright 2000-2007 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libusb_gadget.a + +ifdef CONFIG_USB_DEVICE +COBJS-y += core.o +COBJS-y += ep0.o +COBJS-$(CONFIG_OMAP1510) += omap1510_udc.o +COBJS-$(CONFIG_OMAP1610) += omap1510_udc.o +COBJS-$(CONFIG_MPC885_FAMILY) += mpc8xx_udc.o +COBJS-$(CONFIG_PXA27X) += pxa27x_udc.o +endif + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/drivers/usb/usbdcore.c b/drivers/usb/gadget/core.c index 53ed669..67b6681 100644 --- a/drivers/usb/usbdcore.c +++ b/drivers/usb/gadget/core.c @@ -30,7 +30,7 @@ */ #include <malloc.h> -#include "usbdcore.h" +#include <usbdevice.h> #define MAX_INTERFACES 2 diff --git a/drivers/usb/usbdcore_ep0.c b/drivers/usb/gadget/ep0.c index f6e017d..2b4ec44 100644 --- a/drivers/usb/usbdcore_ep0.c +++ b/drivers/usb/gadget/ep0.c @@ -51,7 +51,7 @@ */ #include <common.h> -#include "usbdcore.h" +#include <usbdevice.h> #if 0 #define dbg_ep0(lvl,fmt,args...) serial_printf("[%s] %s:%d: "fmt"\n",__FILE__,__FUNCTION__,__LINE__,##args) diff --git a/drivers/usb/gadget/ep0.h b/drivers/usb/gadget/ep0.h new file mode 100644 index 0000000..3bec106 --- /dev/null +++ b/drivers/usb/gadget/ep0.h @@ -0,0 +1,39 @@ +/* + * (C) Copyright 2003 + * Gerry Hamel, geh@ti.com, Texas Instruments + * + * Based on + * linux/drivers/usbd/ep0.c + * + * Copyright (c) 2000, 2001, 2002 Lineo + * Copyright (c) 2001 Hewlett Packard + * + * By: + * Stuart Lynne <sl@lineo.com>, + * Tom Rushworth <tbr@lineo.com>, + * Bruce Balden <balden@lineo.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __USBDCORE_EP0_H__ +#define __USBDCORE_EP0_H__ + + +int ep0_recv_setup (struct urb *urb); + + +#endif diff --git a/drivers/usb/usbdcore_mpc8xx.c b/drivers/usb/gadget/mpc8xx_udc.c index 0e311ad..da3fbba 100644 --- a/drivers/usb/usbdcore_mpc8xx.c +++ b/drivers/usb/gadget/mpc8xx_udc.c @@ -3,7 +3,7 @@ * bodonoghue@CodeHermit.ie * * References - * DasUBoot/drivers/usb/usbdcore_omap1510.c, for design and implementation + * DasUBoot/drivers/usb/gadget/omap1510_udc.c, for design and implementation * ideas. * * This program is free software; you can redistribute it and/or modify @@ -59,9 +59,10 @@ #include <common.h> #include <config.h> #include <commproc.h> -#include "usbdcore.h" -#include "usbdcore_mpc8xx.h" -#include "usbdcore_ep0.h" +#include <usbdevice.h> +#include <usb/mpc8xx_udc.h> + +#include "ep0.h" DECLARE_GLOBAL_DATA_PTR; diff --git a/drivers/usb/usbdcore_omap1510.c b/drivers/usb/gadget/omap1510_udc.c index 6b7b61b..90f7907 100644 --- a/drivers/usb/usbdcore_omap1510.c +++ b/drivers/usb/gadget/omap1510_udc.c @@ -31,10 +31,10 @@ #ifdef CONFIG_OMAP_SX1 #include <i2c.h> #endif +#include <usbdevice.h> +#include <usb/omap1510_udc.h> -#include "usbdcore.h" -#include "usbdcore_omap1510.h" -#include "usbdcore_ep0.h" +#include "ep0.h" #define UDC_INIT_MDELAY 80 /* Device settle delay */ diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c new file mode 100644 index 0000000..e6ccd49 --- /dev/null +++ b/drivers/usb/gadget/pxa27x_udc.c @@ -0,0 +1,702 @@ +/* + * PXA27x USB device driver for u-boot. + * + * Copyright (C) 2007 Rodolfo Giometti <giometti@linux.it> + * Copyright (C) 2007 Eurotech S.p.A. <info@eurotech.it> + * Copyright (C) 2008 Vivek Kutal <vivek.kutal@azingo.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + + +#include <common.h> +#include <config.h> +#include <asm/byteorder.h> +#include <usbdcore.h> +#include <usbdcore_ep0.h> +#include <asm/arch/hardware.h> +#include <usb/pxa27x_udc.h> + +/* number of endpoints on this UDC */ +#define UDC_MAX_ENDPOINTS 24 + +static struct urb *ep0_urb; +static struct usb_device_instance *udc_device; +static int ep0state = EP0_IDLE; + +#ifdef USBDDBG +static void udc_dump_buffer(char *name, u8 *buf, int len) +{ + usbdbg("%s - buf %p, len %d", name, buf, len); + print_buffer(0, buf, 1, len, 0); +} +#else +#define udc_dump_buffer(name, buf, len) /* void */ +#endif + +static inline void udc_ack_int_UDCCR(int mask) +{ + USIR1 = mask | USIR1; +} + +/* + * If the endpoint has an active tx_urb, then the next packet of data from the + * URB is written to the tx FIFO. + * The total amount of data in the urb is given by urb->actual_length. + * The maximum amount of data that can be sent in any one packet is given by + * endpoint->tx_packetSize. + * The number of data bytes from this URB that have already been transmitted + * is given by endpoint->sent. + * endpoint->last is updated by this routine with the number of data bytes + * transmitted in this packet. + */ +static int udc_write_urb(struct usb_endpoint_instance *endpoint) +{ + struct urb *urb = endpoint->tx_urb; + int ep_num = endpoint->endpoint_address & USB_ENDPOINT_NUMBER_MASK; + u32 *addr32 = (u32 *) &UDCDN(ep_num); + u32 *data32 = (u32 *) urb->buffer; + u8 *addr8 = (u8 *) &UDCDN(ep_num); + u8 *data8 = (u8 *) urb->buffer; + unsigned int i, n, w, b, is_short; + int timeout = 2000; /* 2ms */ + + if (!urb || !urb->actual_length) + return -1; + + n = MIN(urb->actual_length - endpoint->sent, endpoint->tx_packetSize); + if (n <= 0) + return -1; + + usbdbg("write urb on ep %d", ep_num); +#if defined(USBDDBG) && defined(USBDPARANOIA) + usbdbg("urb: buf %p, buf_len %d, actual_len %d", + urb->buffer, urb->buffer_length, urb->actual_length); + usbdbg("endpoint: sent %d, tx_packetSize %d, last %d", + endpoint->sent, endpoint->tx_packetSize, endpoint->last); +#endif + + is_short = n != endpoint->tx_packetSize; + w = n / 4; + b = n % 4; + usbdbg("n %d%s w %d b %d", n, is_short ? "-s" : "", w, b); + udc_dump_buffer("urb write", data8 + endpoint->sent, n); + + /* Prepare for data send */ + if (ep_num) + UDCCSN(ep_num) = UDCCSR_PC; + + for (i = 0; i < w; i++) + *addr32 = data32[endpoint->sent/4 + i]; + for (i = 0; i < b; i++) + *addr8 = data8[endpoint->sent + w*4 + i]; + + /* Set "Packet Complete" if less data then tx_packetSize */ + if (is_short) + UDCCSN(ep_num) = ep_num ? UDCCSR_SP : UDCCSR0_IPR; + + /* Wait for data sent */ + while (!(UDCCSN(ep_num) & (ep_num ? UDCCSR_PC : UDCCSR0_IPR))) { + if (ep_num) { + if (timeout-- == 0) + return -1; + else + udelay(1); + }; + } + endpoint->last = n; + + if (ep_num) { + usbd_tx_complete(endpoint); + } else { + endpoint->sent += n; + endpoint->last -= n; + } + + if ((endpoint->tx_urb->actual_length - endpoint->sent) <= 0) { + urb->actual_length = 0; + endpoint->sent = 0; + endpoint->last = 0; + } + + if ((endpoint->sent >= urb->actual_length) && (!ep_num)) { + usbdbg("ep0 IN stage done"); + if (is_short) + ep0state = EP0_IDLE; + else + ep0state = EP0_XFER_COMPLETE; + } + + return 0; +} + +static int udc_read_urb(struct usb_endpoint_instance *endpoint) +{ + struct urb *urb = endpoint->rcv_urb; + int ep_num = endpoint->endpoint_address & USB_ENDPOINT_NUMBER_MASK; + u32 *addr32 = (u32 *) &UDCDN(ep_num); + u32 *data32 = (u32 *) urb->buffer; + unsigned int i, n, is_short ; + + usbdbg("read urb on ep %d", ep_num); +#if defined(USBDDBG) && defined(USBDPARANOIA) + usbdbg("urb: buf %p, buf_len %d, actual_len %d", + urb->buffer, urb->buffer_length, urb->actual_length); + usbdbg("endpoint: rcv_packetSize %d", + endpoint->rcv_packetSize); +#endif + + if (UDCCSN(ep_num) & UDCCSR_BNE) + n = UDCBCN(ep_num) & 0x3ff; + else /* zlp */ + n = 0; + is_short = n != endpoint->rcv_packetSize; + + usbdbg("n %d%s", n, is_short ? "-s" : ""); + for (i = 0; i < n; i += 4) + data32[urb->actual_length/4 + i/4] = *addr32; + + udc_dump_buffer("urb read", (u8 *) data32, urb->actual_length + n); + usbd_rcv_complete(endpoint, n, 0); + + return 0; +} + +static int udc_read_urb_ep0(void) +{ + u32 *addr32 = (u32 *) &UDCDN(0); + u32 *data32 = (u32 *) ep0_urb->buffer; + u8 *addr8 = (u8 *) &UDCDN(0); + u8 *data8 = (u8 *) ep0_urb->buffer; + unsigned int i, n, w, b; + + n = UDCBCR0; + w = n / 4; + b = n % 4; + + for (i = 0; i < w; i++) { + data32[ep0_urb->actual_length/4 + i] = *addr32; + ep0_urb->actual_length += 4; + } + + for (i = 0; i < b; i++) { + data8[ep0_urb->actual_length + w*4 + i] = *addr8; + ep0_urb->actual_length++; + } + + UDCCSR0 = UDCCSR0_OPC | UDCCSR0_IPR; + if (ep0_urb->actual_length == ep0_urb->device_request.wLength) + return 1; + + return 0; +} + +static void udc_handle_ep0(struct usb_endpoint_instance *endpoint) +{ + u32 udccsr0 = UDCCSR0; + u32 *data = (u32 *) &ep0_urb->device_request; + int i; + + usbdbg("udccsr0 %x", udccsr0); + + /* Clear stall status */ + if (udccsr0 & UDCCSR0_SST) { + usberr("clear stall status"); + UDCCSR0 = UDCCSR0_SST; + ep0state = EP0_IDLE; + } + + /* previous request unfinished? non-error iff back-to-back ... */ + if ((udccsr0 & UDCCSR0_SA) != 0 && ep0state != EP0_IDLE) + ep0state = EP0_IDLE; + + switch (ep0state) { + + case EP0_IDLE: + + udccsr0 = UDCCSR0; + /* Start control request? */ + if ((udccsr0 & (UDCCSR0_OPC | UDCCSR0_SA | UDCCSR0_RNE)) + == (UDCCSR0_OPC | UDCCSR0_SA | UDCCSR0_RNE)) { + + /* Read SETUP packet. + * SETUP packet size is 8 bytes (aka 2 words) + */ + usbdbg("try reading SETUP packet"); + for (i = 0; i < 2; i++) { + if ((UDCCSR0 & UDCCSR0_RNE) == 0) { + usberr("setup packet too short:%d", i); + goto stall; + } + data[i] = UDCDR0; + } + + UDCCSR0 |= (UDCCSR0_OPC | UDCCSR0_SA); + if ((UDCCSR0 & UDCCSR0_RNE) != 0) { + usberr("setup packet too long"); + goto stall; + } + + udc_dump_buffer("ep0 setup read", (u8 *) data, 8); + + if (ep0_urb->device_request.wLength == 0) { + usbdbg("Zero Data control Packet\n"); + if (ep0_recv_setup(ep0_urb)) { + usberr("Invalid Setup Packet\n"); + udc_dump_buffer("ep0 setup read", + (u8 *)data, 8); + goto stall; + } + UDCCSR0 = UDCCSR0_IPR; + ep0state = EP0_IDLE; + } else { + /* Check direction */ + if ((ep0_urb->device_request.bmRequestType & + USB_REQ_DIRECTION_MASK) + == USB_REQ_HOST2DEVICE) { + ep0state = EP0_OUT_DATA; + ep0_urb->buffer = + (u8 *)ep0_urb->buffer_data; + ep0_urb->buffer_length = + sizeof(ep0_urb->buffer_data); + ep0_urb->actual_length = 0; + UDCCSR0 = UDCCSR0_IPR; + } else { + /* The ep0_recv_setup function has + * already placed our response packet + * data in ep0_urb->buffer and the + * packet length in + * ep0_urb->actual_length. + */ + if (ep0_recv_setup(ep0_urb)) { +stall: + usberr("Invalid setup packet"); + udc_dump_buffer("ep0 setup read" + , (u8 *) data, 8); + ep0state = EP0_IDLE; + + UDCCSR0 = UDCCSR0_SA | + UDCCSR0_OPC | UDCCSR0_FST | + UDCCS0_FTF; + + return; + } + + endpoint->tx_urb = ep0_urb; + endpoint->sent = 0; + usbdbg("EP0_IN_DATA"); + ep0state = EP0_IN_DATA; + if (udc_write_urb(endpoint) < 0) + goto stall; + + } + } + return; + } else if ((udccsr0 & (UDCCSR0_OPC | UDCCSR0_SA)) + == (UDCCSR0_OPC|UDCCSR0_SA)) { + usberr("Setup Active but no data. Stalling ....\n"); + goto stall; + } else { + usbdbg("random early IRQs"); + /* Some random early IRQs: + * - we acked FST + * - IPR cleared + * - OPC got set, without SA (likely status stage) + */ + UDCCSR0 = udccsr0 & (UDCCSR0_SA | UDCCSR0_OPC); + } + break; + + case EP0_OUT_DATA: + + if ((udccsr0 & UDCCSR0_OPC) && !(udccsr0 & UDCCSR0_SA)) { + if (udc_read_urb_ep0()) { +read_complete: + ep0state = EP0_IDLE; + if (ep0_recv_setup(ep0_urb)) { + /* Not a setup packet, stall next + * EP0 transaction + */ + udc_dump_buffer("ep0 setup read", + (u8 *) data, 8); + usberr("can't parse setup packet\n"); + goto stall; + } + } + } else if (!(udccsr0 & UDCCSR0_OPC) && + !(udccsr0 & UDCCSR0_IPR)) { + if (ep0_urb->device_request.wLength == + ep0_urb->actual_length) + goto read_complete; + + usberr("Premature Status\n"); + ep0state = EP0_IDLE; + } + break; + + case EP0_IN_DATA: + /* GET_DESCRIPTOR etc */ + if (udccsr0 & UDCCSR0_OPC) { + UDCCSR0 = UDCCSR0_OPC | UDCCSR0_FTF; + usberr("ep0in premature status"); + ep0state = EP0_IDLE; + } else { + /* irq was IPR clearing */ + if (udc_write_urb(endpoint) < 0) { + usberr("ep0_write_error\n"); + goto stall; + } + } + break; + + case EP0_XFER_COMPLETE: + UDCCSR0 = UDCCSR0_IPR; + ep0state = EP0_IDLE; + break; + + default: + usbdbg("Default\n"); + } + USIR0 = USIR0_IR0; +} + +static void udc_handle_ep(struct usb_endpoint_instance *endpoint) +{ + int ep_addr = endpoint->endpoint_address; + int ep_num = ep_addr & USB_ENDPOINT_NUMBER_MASK; + int ep_isout = (ep_addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT; + + u32 flags = UDCCSN(ep_num) & (UDCCSR_SST | UDCCSR_TRN); + if (flags) + UDCCSN(ep_num) = flags; + + if (ep_isout) + udc_read_urb(endpoint); + else + udc_write_urb(endpoint); + + UDCCSN(ep_num) = UDCCSR_PC; +} + +static void udc_state_changed(void) +{ + int config, interface, alternate; + + UDCCR |= UDCCR_SMAC; + + config = (UDCCR & UDCCR_ACN) >> UDCCR_ACN_S; + interface = (UDCCR & UDCCR_AIN) >> UDCCR_AIN_S; + alternate = (UDCCR & UDCCR_AAISN) >> UDCCR_AAISN_S; + + usbdbg("New UDC settings are: conf %d - inter %d - alter %d", + config, interface, alternate); + + usbd_device_event_irq(udc_device, DEVICE_CONFIGURED, 0); + UDCISR1 = UDCISR1_IRCC; +} + +void udc_irq(void) +{ + int handled; + struct usb_endpoint_instance *endpoint; + int ep_num, i; + u32 udcisr0; + + do { + handled = 0; + /* Suspend Interrupt Request */ + if (USIR1 & UDCCR_SUSIR) { + usbdbg("Suspend\n"); + udc_ack_int_UDCCR(UDCCR_SUSIR); + handled = 1; + ep0state = EP0_IDLE; + } + + /* Resume Interrupt Request */ + if (USIR1 & UDCCR_RESIR) { + udc_ack_int_UDCCR(UDCCR_RESIR); + handled = 1; + usbdbg("USB resume\n"); + } + + if (USIR1 & (1<<31)) { + handled = 1; + udc_state_changed(); + } + + /* Reset Interrupt Request */ + if (USIR1 & UDCCR_RSTIR) { + udc_ack_int_UDCCR(UDCCR_RSTIR); + handled = 1; + usbdbg("Reset\n"); + usbd_device_event_irq(udc_device, DEVICE_RESET, 0); + } else { + if (USIR0) + usbdbg("UISR0: %x \n", USIR0); + + if (USIR0 & 0x2) + USIR0 = 0x2; + + /* Control traffic */ + if (USIR0 & USIR0_IR0) { + handled = 1; + udc_handle_ep0(udc_device->bus->endpoint_array); + USIR0 = USIR0_IR0; + } + + endpoint = udc_device->bus->endpoint_array; + for (i = 0; i < udc_device->bus->max_endpoints; i++) { + ep_num = (endpoint[i].endpoint_address) & + USB_ENDPOINT_NUMBER_MASK; + if (!ep_num) + continue; + udcisr0 = UDCISR0; + if (udcisr0 & + UDCISR_INT(ep_num, UDC_INT_PACKETCMP)) { + UDCISR0 = UDCISR_INT(ep_num, + UDC_INT_PACKETCMP); + udc_handle_ep(&endpoint[i]); + } + } + } + + } while (handled); +} + +/* The UDCCR reg contains mask and interrupt status bits, + * so using '|=' isn't safe as it may ack an interrupt. + */ +#define UDCCR_OEN (1 << 31) /* On-the-Go Enable */ +#define UDCCR_MASK_BITS (UDCCR_OEN | UDCCR_UDE) + +static inline void udc_set_mask_UDCCR(int mask) +{ + UDCCR = (UDCCR & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS); +} + +static inline void udc_clear_mask_UDCCR(int mask) +{ + UDCCR = (UDCCR & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS); +} + +static void pio_irq_enable(int ep_num) +{ + if (ep_num < 16) + UDCICR0 |= 3 << (ep_num * 2); + else { + ep_num -= 16; + UDCICR1 |= 3 << (ep_num * 2); + } +} + +/* + * udc_set_nak + * + * Allow upper layers to signal lower layers should not accept more RX data + */ +void udc_set_nak(int ep_num) +{ + /* TODO */ +} + +/* + * udc_unset_nak + * + * Suspend sending of NAK tokens for DATA OUT tokens on a given endpoint. + * Switch off NAKing on this endpoint to accept more data output from host. + */ +void udc_unset_nak(int ep_num) +{ + /* TODO */ +} + +int udc_endpoint_write(struct usb_endpoint_instance *endpoint) +{ + return udc_write_urb(endpoint); +} + +/* Associate a physical endpoint with endpoint instance */ +void udc_setup_ep(struct usb_device_instance *device, unsigned int id, + struct usb_endpoint_instance *endpoint) +{ + int ep_num, ep_addr, ep_isout, ep_type, ep_size; + int config, interface, alternate; + u32 tmp; + + usbdbg("setting up endpoint id %d", id); + + if (!endpoint) { + usberr("endpoint void!"); + return; + } + + ep_num = endpoint->endpoint_address & USB_ENDPOINT_NUMBER_MASK; + if (ep_num >= UDC_MAX_ENDPOINTS) { + usberr("unable to setup ep %d!", ep_num); + return; + } + + pio_irq_enable(ep_num); + if (ep_num == 0) { + /* Done for ep0 */ + return; + } + + config = 1; + interface = 0; + alternate = 0; + + usbdbg("config %d - interface %d - alternate %d", + config, interface, alternate); + + ep_addr = endpoint->endpoint_address; + ep_num = ep_addr & USB_ENDPOINT_NUMBER_MASK; + ep_isout = (ep_addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT; + ep_type = ep_isout ? endpoint->rcv_attributes : endpoint->tx_attributes; + ep_size = ep_isout ? endpoint->rcv_packetSize : endpoint->tx_packetSize; + + usbdbg("addr %x, num %d, dir %s, type %s, packet size %d", + ep_addr, ep_num, + ep_isout ? "out" : "in", + ep_type == USB_ENDPOINT_XFER_ISOC ? "isoc" : + ep_type == USB_ENDPOINT_XFER_BULK ? "bulk" : + ep_type == USB_ENDPOINT_XFER_INT ? "int" : "???", + ep_size + ); + + /* Configure UDCCRx */ + tmp = 0; + tmp |= (config << UDCCONR_CN_S) & UDCCONR_CN; + tmp |= (interface << UDCCONR_IN_S) & UDCCONR_IN; + tmp |= (alternate << UDCCONR_AISN_S) & UDCCONR_AISN; + tmp |= (ep_num << UDCCONR_EN_S) & UDCCONR_EN; + tmp |= (ep_type << UDCCONR_ET_S) & UDCCONR_ET; + tmp |= ep_isout ? 0 : UDCCONR_ED; + tmp |= (ep_size << UDCCONR_MPS_S) & UDCCONR_MPS; + tmp |= UDCCONR_EE; + + UDCCN(ep_num) = tmp; + + usbdbg("UDCCR%c = %x", 'A' + ep_num-1, UDCCN(ep_num)); + usbdbg("UDCCSR%c = %x", 'A' + ep_num-1, UDCCSN(ep_num)); +} + +#define CONFIG_USB_DEV_PULLUP_GPIO 87 + +/* Connect the USB device to the bus */ +void udc_connect(void) +{ + usbdbg("UDC connect"); + + /* Turn on the USB connection by enabling the pullup resistor */ + set_GPIO_mode(CONFIG_USB_DEV_PULLUP_GPIO | GPIO_OUT); + GPSR(CONFIG_USB_DEV_PULLUP_GPIO) = GPIO_bit(CONFIG_USB_DEV_PULLUP_GPIO); +} + +/* Disconnect the USB device to the bus */ +void udc_disconnect(void) +{ + usbdbg("UDC disconnect"); + + /* Turn off the USB connection by disabling the pullup resistor */ + GPCR(CONFIG_USB_DEV_PULLUP_GPIO) = GPIO_bit(CONFIG_USB_DEV_PULLUP_GPIO); +} + +/* Switch on the UDC */ +void udc_enable(struct usb_device_instance *device) +{ + + ep0state = EP0_IDLE; + CKEN |= CKEN11_USB; + + /* enable endpoint 0, A, B's Packet Complete Interrupt. */ + UDCICR0 = 0x0000003f; + UDCICR1 = 0xa8000000; + + /* clear the interrupt status/control registers */ + UDCISR0 = 0xffffffff; + UDCISR1 = 0xffffffff; + + /* set UDC-enable */ + udc_set_mask_UDCCR(UDCCR_UDE); + + udc_device = device; + if (!ep0_urb) + ep0_urb = usbd_alloc_urb(udc_device, + udc_device->bus->endpoint_array); + else + usbinfo("ep0_urb %p already allocated", ep0_urb); + + usbdbg("UDC Enabled\n"); +} + +/* Need to check this again */ +void udc_disable(void) +{ + usbdbg("disable UDC"); + + udc_clear_mask_UDCCR(UDCCR_UDE); + + /* Disable clock for USB device */ + CKEN &= ~CKEN11_USB; + + /* Free ep0 URB */ + if (ep0_urb) { + usbd_dealloc_urb(ep0_urb); + ep0_urb = NULL; + } + + /* Reset device pointer */ + udc_device = NULL; +} + +/* Allow udc code to do any additional startup */ +void udc_startup_events(struct usb_device_instance *device) +{ + /* The DEVICE_INIT event puts the USB device in the state STATE_INIT */ + usbd_device_event_irq(device, DEVICE_INIT, 0); + + /* The DEVICE_CREATE event puts the USB device in the state + * STATE_ATTACHED */ + usbd_device_event_irq(device, DEVICE_CREATE, 0); + + /* Some USB controller driver implementations signal + * 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. + */ + udc_enable(device); +} + +/* Initialize h/w stuff */ +int udc_init(void) +{ + udc_device = NULL; + usbdbg("PXA27x usbd start"); + + /* Disable the UDC */ + udc_clear_mask_UDCCR(UDCCR_UDE); + + /* Disable clock for USB device */ + CKEN &= ~CKEN11_USB; + + /* Disable IRQs: we don't use them */ + UDCICR0 = UDCICR1 = 0; + + return 0; +} diff --git a/drivers/usb/Makefile b/drivers/usb/host/Makefile index 5523cbd..ec1d689 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/host/Makefile @@ -23,33 +23,22 @@ include $(TOPDIR)/config.mk -LIB := $(obj)libusb.a +LIB := $(obj)libusb_host.a -# core -COBJS-y += usbdcore.o -COBJS-$(CONFIG_USB_OHCI_NEW) += usb_ohci.o -COBJS-$(CONFIG_USB_EHCI) += usb_ehci_core.o - -# host -COBJS-$(CONFIG_USB_ATMEL) += atmel_usb.o +# ohci +COBJS-$(CONFIG_USB_OHCI_NEW) += ohci-hcd.o +COBJS-$(CONFIG_USB_ATMEL) += ohci-at91.o COBJS-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o COBJS-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o -COBJS-$(CONFIG_USB_S3C64XX) += s3c64xx_usb.o -COBJS-$(CONFIG_USB_SL811HS) += sl811_usb.o -COBJS-$(CONFIG_USB_EHCI_FSL) += usb_ehci_fsl.o -COBJS-$(CONFIG_USB_EHCI_PCI) += usb_ehci_pci.o -COBJS-$(CONFIG_USB_EHCI_IXP4XX) += usb_ehci_ixp.o -COBJS-$(CONFIG_MUSB_HCD) += musb_hcd.o musb_core.o -COBJS-$(CONFIG_USB_DAVINCI) += davinci_usb.o -COBJS-$(CONFIG_USB_EHCI_VCT) += usb_ehci_vct.o - -# device -ifdef CONFIG_USB_DEVICE -COBJS-y += usbdcore_ep0.o -COBJS-$(CONFIG_OMAP1510) += usbdcore_omap1510.o -COBJS-$(CONFIG_OMAP1610) += usbdcore_omap1510.o -COBJS-$(CONFIG_MPC885_FAMILY) += usbdcore_mpc8xx.o -endif +COBJS-$(CONFIG_USB_S3C64XX) += s3c64xx-hcd.o +COBJS-$(CONFIG_USB_SL811HS) += sl811-hcd.o + +# echi +COBJS-$(CONFIG_USB_EHCI) += ehci-hcd.o +COBJS-$(CONFIG_USB_EHCI_FSL) += ehci-fsl.o +COBJS-$(CONFIG_USB_EHCI_IXP4XX) += ehci-ixp.o +COBJS-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o +COBJS-$(CONFIG_USB_EHCI_VCT) += ehci-vct.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/usb/usb_ehci_core.h b/drivers/usb/host/ehci-core.h index 39e5c5e..39e5c5e 100644 --- a/drivers/usb/usb_ehci_core.h +++ b/drivers/usb/host/ehci-core.h diff --git a/drivers/usb/usb_ehci_fsl.c b/drivers/usb/host/ehci-fsl.c index 81d5d21..86ee1d5 100644 --- a/drivers/usb/usb_ehci_fsl.c +++ b/drivers/usb/host/ehci-fsl.c @@ -26,9 +26,9 @@ #include <asm/io.h> #include <asm/bitops.h> -#include "usb_ehci.h" -#include "usb_ehci_fsl.h" -#include "usb_ehci_core.h" +#include "ehci.h" +#include "ehci-fsl.h" +#include "ehci-core.h" /* * Create the appropriate control structures to manage diff --git a/drivers/usb/usb_ehci_fsl.h b/drivers/usb/host/ehci-fsl.h index c429af1..c429af1 100644 --- a/drivers/usb/usb_ehci_fsl.h +++ b/drivers/usb/host/ehci-fsl.h diff --git a/drivers/usb/usb_ehci_core.c b/drivers/usb/host/ehci-hcd.c index 4dbfb66..bbd547b 100644 --- a/drivers/usb/usb_ehci_core.c +++ b/drivers/usb/host/ehci-hcd.c @@ -25,7 +25,8 @@ #include <usb.h> #include <asm/io.h> #include <malloc.h> -#include "usb_ehci.h" + +#include "ehci.h" int rootdev; struct ehci_hccr *hccr; /* R/O registers, not need for volatile */ diff --git a/drivers/usb/usb_ehci_ixp.c b/drivers/usb/host/ehci-ixp4xx.c index 25c18c1..b8f15ae 100644 --- a/drivers/usb/usb_ehci_ixp.c +++ b/drivers/usb/host/ehci-ixp4xx.c @@ -21,8 +21,9 @@ */ #include <common.h> #include <usb.h> -#include "usb_ehci.h" -#include "usb_ehci_core.h" + +#include "ehci.h" +#include "ehci-core.h" /* * Create the appropriate control structures to manage * a new EHCI host controller. diff --git a/drivers/usb/usb_ehci_pci.c b/drivers/usb/host/ehci-pci.c index 3e7143c..441b1a2 100644 --- a/drivers/usb/usb_ehci_pci.c +++ b/drivers/usb/host/ehci-pci.c @@ -21,8 +21,9 @@ #include <common.h> #include <pci.h> #include <usb.h> -#include "usb_ehci.h" -#include "usb_ehci_core.h" + +#include "ehci.h" +#include "ehci-core.h" #ifdef CONFIG_PCI_EHCI_DEVICE static struct pci_device_id ehci_pci_ids[] = { diff --git a/drivers/usb/usb_ehci_vct.c b/drivers/usb/host/ehci-vct.c index 89daaaf..3063dd1 100644 --- a/drivers/usb/usb_ehci_vct.c +++ b/drivers/usb/host/ehci-vct.c @@ -20,8 +20,8 @@ #include <common.h> #include <usb.h> -#include "usb_ehci.h" -#include "usb_ehci_core.h" +#include "ehci.h" +#include "ehci-core.h" int vct_ehci_hcd_init(u32 *hccr, u32 *hcor); diff --git a/drivers/usb/usb_ehci.h b/drivers/usb/host/ehci.h index b3c1d5d..b3c1d5d 100644 --- a/drivers/usb/usb_ehci.h +++ b/drivers/usb/host/ehci.h diff --git a/drivers/usb/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index 348e404..348e404 100644 --- a/drivers/usb/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c diff --git a/drivers/usb/isp116x.h b/drivers/usb/host/isp116x.h index a3ce3b5..a3ce3b5 100644 --- a/drivers/usb/isp116x.h +++ b/drivers/usb/host/isp116x.h diff --git a/drivers/usb/atmel_usb.c b/drivers/usb/host/ohci-at91.c index 7c44ad0..7c44ad0 100644 --- a/drivers/usb/atmel_usb.c +++ b/drivers/usb/host/ohci-at91.c diff --git a/drivers/usb/usb_ohci.c b/drivers/usb/host/ohci-hcd.c index 0bbee0f..e2f289e 100644 --- a/drivers/usb/usb_ohci.c +++ b/drivers/usb/host/ohci-hcd.c @@ -57,7 +57,8 @@ #include <malloc.h> #include <usb.h> -#include "usb_ohci.h" + +#include "ohci.h" #ifdef CONFIG_AT91RM9200 #include <asm/arch/hardware.h> /* needed for AT91_USB_HOST_BASE */ diff --git a/drivers/usb/usb_ohci.h b/drivers/usb/host/ohci.h index a547337..a547337 100644 --- a/drivers/usb/usb_ohci.h +++ b/drivers/usb/host/ohci.h diff --git a/drivers/usb/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index db611b6..db611b6 100644 --- a/drivers/usb/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c diff --git a/drivers/usb/r8a66597.h b/drivers/usb/host/r8a66597.h index 9af6446..9af6446 100644 --- a/drivers/usb/r8a66597.h +++ b/drivers/usb/host/r8a66597.h diff --git a/drivers/usb/s3c64xx_usb.c b/drivers/usb/host/s3c64xx-hcd.c index 274a4ed..274a4ed 100644 --- a/drivers/usb/s3c64xx_usb.c +++ b/drivers/usb/host/s3c64xx-hcd.c diff --git a/drivers/usb/sl811_usb.c b/drivers/usb/host/sl811-hcd.c index a03e469..82a8b36 100644 --- a/drivers/usb/sl811_usb.c +++ b/drivers/usb/host/sl811-hcd.c @@ -40,7 +40,7 @@ #include <usb.h> #include "sl811.h" -#include "../../board/kup/common/kup.h" +#include "../../../board/kup/common/kup.h" #ifdef __PPC__ # define EIEIO __asm__ volatile ("eieio") diff --git a/drivers/usb/sl811.h b/drivers/usb/host/sl811.h index c1f9f01..c1f9f01 100644 --- a/drivers/usb/sl811.h +++ b/drivers/usb/host/sl811.h diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile new file mode 100644 index 0000000..09e0a5f --- /dev/null +++ b/drivers/usb/musb/Makefile @@ -0,0 +1,47 @@ +# +# (C) Copyright 2000-2007 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libusb_musb.a + +COBJS-$(CONFIG_MUSB_HCD) += musb_hcd.o musb_core.o +COBJS-$(CONFIG_USB_DAVINCI) += davinci.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/drivers/usb/davinci_usb.c b/drivers/usb/musb/davinci.c index e66f660..a7648fc 100644 --- a/drivers/usb/davinci_usb.c +++ b/drivers/usb/musb/davinci.c @@ -23,7 +23,7 @@ #include <common.h> #include <asm/io.h> -#include "davinci_usb.h" +#include "davinci.h" /* MUSB platform configuration */ struct musb_config musb_cfg = { diff --git a/drivers/usb/davinci_usb.h b/drivers/usb/musb/davinci.h index f6751bf..f6751bf 100644 --- a/drivers/usb/davinci_usb.h +++ b/drivers/usb/musb/davinci.h diff --git a/drivers/usb/musb_core.c b/drivers/usb/musb/musb_core.c index ec57fc8..ec57fc8 100644 --- a/drivers/usb/musb_core.c +++ b/drivers/usb/musb/musb_core.c diff --git a/drivers/usb/musb_core.h b/drivers/usb/musb/musb_core.h index 2597c5f..2597c5f 100644 --- a/drivers/usb/musb_core.h +++ b/drivers/usb/musb/musb_core.h diff --git a/drivers/usb/musb_hcd.c b/drivers/usb/musb/musb_hcd.c index 352a0d4..352a0d4 100644 --- a/drivers/usb/musb_hcd.c +++ b/drivers/usb/musb/musb_hcd.c diff --git a/drivers/usb/musb_hcd.h b/drivers/usb/musb/musb_hcd.h index bb83311..bb83311 100644 --- a/drivers/usb/musb_hcd.h +++ b/drivers/usb/musb/musb_hcd.h |