CONFIG_NO_HZ added too much idle time in /proc/stat during throughput test.

2011-12-13 Thread Fushen Chen
On APM82181,  vmstat (/proc/stat)  doesn't show correct idle percent, if
kernel enables CONFIG_NO_HZ (Tickless System / Dynamic Tick).

When I run wireless throughput test with heavy traffic, vmstat shows very
high idle percent while oprofile shows very low idle percent. During the
test, the system is idle, but network traffic uses a lot of hard IRQ and
soft-irq time. vmstat would have the correct stats if
account_idle_ticks(ticks) in kernel/time/tick-sched.c doesn't add more idle
time in vmstat. In the same test, if I disable CONFIG_NO_HZ in kernel,
idle percent in vmstat and oprofile would match.

My APM82181 kernel configuration is CONFIG_NO_HZ, CONFIG_HZ_250=y,
CONFIG_HZ=250, and CONFIG_HIGH_RES_TIMERS.

My question is that if kernel enables CONFIG_NO_HZ, how would kernel
report correct stats.

Thanks,
Fushen
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: CONFIG_NO_HZ added too much idle time in /proc/stat during throughput test.

2011-12-13 Thread Fushen Chen
This is 2.6.32, but I think 2.6.36 is the same.
Thanks,
Fushen

On Tue, Dec 13, 2011 at 3:34 PM, Benjamin Herrenschmidt 
b...@kernel.crashing.org wrote:

 On Wed, 2011-12-14 at 00:28 +0100, Thomas Gleixner wrote:
  On Wed, 14 Dec 2011, Benjamin Herrenschmidt wrote:
 
   On Tue, 2011-12-13 at 12:42 -0800, Fushen Chen wrote:
On APM82181,  vmstat (/proc/stat)  doesn't show correct idle
percent, if kernel enables CONFIG_NO_HZ (Tickless System / Dynamic
Tick).
   
When I run wireless throughput test with heavy traffic, vmstat
 shows
very high idle percent while oprofile shows very low idle percent.
During the test, the system is idle, but network traffic uses a lot
 of
hard IRQ and soft-irq time. vmstat would have the correct stats if
account_idle_ticks(ticks) in kernel/time/tick-sched.c doesn't add
 more
idle time in vmstat. In the same test, if I disable CONFIG_NO_HZ
in kernel, idle percent in vmstat and oprofile would match.
   
My APM82181 kernel configuration is CONFIG_NO_HZ,
 CONFIG_HZ_250=y,
CONFIG_HZ=250, and CONFIG_HIGH_RES_TIMERS.
   
My question is that if kernel enables CONFIG_NO_HZ, how would
 kernel
report correct stats.
  
   Hi Thomas ! Any idea what we're doing wrong ? :-)
 
  Not really, that had been an issue before and had been fixed. Peter 

 Fusen, what kernel version is this ?

 Cheers,
 Ben.



___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH V5 0/9] Add Synopsys DesignWare HS USB OTG driver

2010-10-21 Thread fushen chen
On Wed, 2010-10-20 at 21:03 -0700, Greg KH wrote:
 On Wed, Oct 20, 2010 at 06:06:34PM -0700, Fushen Chen wrote:
  This patch series add Synopsys DesignWare HS USB OTG driver support.
 
 Unfortunatly this is right at the start of the merge window for me,
 which means it is past the window for anything new to go into .37.  Can
 you resend this after .37-rc1 comes out and I can review it at that
 point in time?
Sure, I'll make another patch submit.

Thanks,
Fushen

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH V5 0/9] *** Add Synopsys DesignWare HS USB OTG driver ***

2010-10-20 Thread Fushen Chen
This patch series add Synopsys DesignWare HS USB OTG driver support.

PATCH V5 has a new license header from Synopsys and APM 
Previous versions:
  1. Addressed comment from Wolfgang Denk to sync with
 git://git.denx.de/linux-2.6-denx.git.
  2. Added bug fixes and features from Stefan Roese and Chuck Meade.
  3. Removed dts file from this pathch per Sergei Shtylyov suggestion.
 We'll submit a separate patch to PowerPC tree.
  4. Modified driver to use generic USB OTG enumeration state.
  5. Move Makefiles to the last patch per David Daney suggestion.

Fushen Chen (9):
  Add Synopsys DesignWare HS USB OTG Control and Status Register (CSR).
  Add Synopsys DesignWare HS USB OTG driver framework.
  Add Synopsys DesignWare HS USB OTG Core Interface Layer (CIL).
  Add Synopsys DesignWare HS USB OTG HCD function.
  Add Synopsys DesignWare HS USB OTG HCD interrupt function.
  Add Synopsys DesignWare HS USB OTG HCD queue function.
  Add Synopsys DesignWare HS USB OTG PCD function.
  Add Synopsys DesignWare HS USB OTG PCD interrupt function.
  Add Synopsys DesignWare HS USB OTG driver kernel configuration and
Makefile.

 drivers/Makefile|1 +
 drivers/usb/Kconfig |2 +
 drivers/usb/dwc_otg/Kconfig |   99 +
 drivers/usb/dwc_otg/Makefile|   19 +
 drivers/usb/dwc_otg/dwc_otg_apmppc.c|  394 
 drivers/usb/dwc_otg/dwc_otg_cil.c   |  892 +
 drivers/usb/dwc_otg/dwc_otg_cil.h   | 1181 +++
 drivers/usb/dwc_otg/dwc_otg_cil_intr.c  |  618 ++
 drivers/usb/dwc_otg/dwc_otg_driver.h|   78 +
 drivers/usb/dwc_otg/dwc_otg_hcd.c   | 2400 +++
 drivers/usb/dwc_otg/dwc_otg_hcd.h   |  413 
 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c  | 1465 ++
 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c |  697 +++
 drivers/usb/dwc_otg/dwc_otg_param.c |  730 +++
 drivers/usb/dwc_otg/dwc_otg_pcd.c   | 1733 
 drivers/usb/dwc_otg/dwc_otg_pcd.h   |  137 ++
 drivers/usb/dwc_otg/dwc_otg_pcd_intr.c  | 2262 +
 drivers/usb/dwc_otg/dwc_otg_regs.h  | 3269 +++
 18 files changed, 16390 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/Kconfig
 create mode 100644 drivers/usb/dwc_otg/Makefile
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_apmppc.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil_intr.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_param.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd_intr.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_regs.h

-- 
1.7.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH V5 9/9] Add Synopsys DesignWare HS USB OTG driver kernel configuration and Makefile.

2010-10-20 Thread Fushen Chen

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/Makefile |1 +
 drivers/usb/Kconfig  |2 +
 drivers/usb/dwc_otg/Kconfig  |   99 ++
 drivers/usb/dwc_otg/Makefile |   19 
 4 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/Kconfig
 create mode 100644 drivers/usb/dwc_otg/Makefile

diff --git a/drivers/Makefile b/drivers/Makefile
index a2aea53..36cb201 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_UWB) += uwb/
 obj-$(CONFIG_USB_OTG_UTILS)+= usb/otg/
 obj-$(CONFIG_USB)  += usb/
 obj-$(CONFIG_USB_MUSB_HDRC)+= usb/musb/
+obj-$(CONFIG_USB_DWC_OTG)  += usb/dwc_otg/
 obj-$(CONFIG_PCI)  += usb/
 obj-$(CONFIG_USB_GADGET)   += usb/gadget/
 obj-$(CONFIG_SERIO)+= input/serio/
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 4aa00e6..bbb8b2c 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -114,6 +114,8 @@ source drivers/usb/host/Kconfig
 
 source drivers/usb/musb/Kconfig
 
+source drivers/usb/dwc_otg/Kconfig
+
 source drivers/usb/class/Kconfig
 
 source drivers/usb/storage/Kconfig
diff --git a/drivers/usb/dwc_otg/Kconfig b/drivers/usb/dwc_otg/Kconfig
new file mode 100644
index 000..174141d
--- /dev/null
+++ b/drivers/usb/dwc_otg/Kconfig
@@ -0,0 +1,99 @@
+#
+# USB Dual Role (OTG-ready) Controller Drivers
+# for silicon based on Synopsys DesignWare IP
+#
+
+comment Enable Host or Gadget support for DesignWare OTG controller
+   depends on !USB  USB_GADGET=n
+
+config USB_DWC_OTG
+   depends on (USB || USB_GADGET)
+   depends on 405EZ || 405EX || 460EX
+   select NOP_USB_XCEIV
+   select USB_OTG_UTILS
+   tristate Synopsys DWC OTG Controller
+   default USB_GADGET
+   help
+ This driver provides USB Device Controller support for the
+ Synopsys DesignWare USB OTG Core used on the AppliedMicro PowerPC SoC.
+
+config DWC_DEBUG
+   bool Enable DWC Debugging
+   depends on USB_DWC_OTG
+   default n
+   help
+ Enable DWC driver debugging
+
+choice
+   prompt DWC Mode Selection
+   depends on USB_DWC_OTG
+   default DWC_HOST_ONLY
+   help
+ Select the DWC Core in OTG, Host only, or Device only mode.
+
+config DWC_HOST_ONLY
+   bool DWC Host Only Mode if 405EX || 460EX
+
+config DWC_OTG_MODE
+   bool DWC OTG Mode if 405EX || 460EX
+   select USB_GADGET_SELECTED
+
+config DWC_DEVICE_ONLY
+   bool DWC Device Only Mode
+   select USB_GADGET_SELECTED
+
+endchoice
+
+# enable peripheral support (including with OTG)
+config USB_GADGET_DWC_HDRC
+   bool
+   depends on USB_DWC_OTG  (DWC_DEVICE_ONLY || USB_DWC_OTG)
+
+choice
+   prompt DWC DMA/SlaveMode Selection
+   depends on USB_DWC_OTG
+   default DWC_DMA_MODE
+   help
+ Select the DWC DMA or Slave Mode.
+ DMA mode uses the DWC core internal DMA engines.
+ Slave mode uses the processor PIO to tranfer data.
+ In Slave mode, processor's DMA channels can be used if available.
+
+config DWC_SLAVE
+   bool DWC Slave Mode if 405EX || 460EX
+
+config DWC_DMA_MODE
+   bool DWC DMA Mode if 405EX || (460EX  \
+   (!USB_EHCI_HCD  || !USB_OHCI_HCD))
+
+endchoice
+
+config USB_OTG_WHITELIST
+   bool Rely on OTG Targeted Peripherals List
+   depends on !USB_SUSPEND  USB_DWC_OTG
+   default n
+   help
+ This is the same flag as in ../core/Kconfig.
+ It is here for easy deselect.
+
+config DWC_OTG_REG_LE
+   depends on USB_DWC_OTG
+   bool DWC Little Endian Register if 405EX || 460EX
+   default y
+   help
+ OTG core register access is Little-Endian.
+
+config DWC_OTG_FIFO_LE
+   depends on USB_DWC_OTG
+   bool DWC FIFO Little Endian if 405EZ
+   default n
+   help
+ OTG core FIFO access is Little-Endian.
+
+config DWC_LIMITED_XFER_SIZE
+   depends on USB_GADGET_DWC_HDRC
+   bool DWC Endpoint Limited Xfer Size if 405EZ || 405EX || 460EX
+   default n if 460EX || 405EX
+   default y if 405EZ
+   help
+ Bit fields in the Device EP Transfer Size Register is 11 bits.
diff --git a/drivers/usb/dwc_otg/Makefile b/drivers/usb/dwc_otg/Makefile
new file mode 100644
index 000..31dd5e8
--- /dev/null
+++ b/drivers/usb/dwc_otg/Makefile
@@ -0,0 +1,19 @@
+#
+# OTG infrastructure and transceiver drivers
+#
+obj-$(CONFIG_USB_DWC_OTG)  += dwc_otg.o
+
+dwc_otg-objs := dwc_otg_cil.o dwc_otg_cil_intr.o dwc_otg_param.o
+
+ifeq ($(CONFIG_4xx_SOC),y)
+dwc_otg-objs += dwc_otg_apmppc.o
+endif
+
+ifneq ($(CONFIG_DWC_DEVICE_ONLY),y)
+dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_intr.o \
+   dwc_otg_hcd_queue.o
+endif
+
+ifneq ($(CONFIG_DWC_HOST_ONLY),y)
+dwc_otg-objs += dwc_otg_pcd.o dwc_otg_pcd_intr.o
+endif
-- 
1.7.3

[PATCH V5 6/9] Add Synopsys DesignWare HS USB OTG HCD queue function.

2010-10-20 Thread Fushen Chen
Implements functions to manage Queue Heads and Queue
Transfer Descriptors of DWC USB OTG Controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c |  697 +++
 1 files changed, 697 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c

diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c 
b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
new file mode 100644
index 000..b1d67fe
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
@@ -0,0 +1,697 @@
+/*
+ * DesignWare HS OTG controller driver
+ * Copyright (C) 2006 Synopsys, Inc.
+ * Portions Copyright (C) 2010 Applied Micro Circuits Corporation.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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 version 2 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see http://www.gnu.org/licenses
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Suite 500, Boston, MA 02110-1335 USA.
+ *
+ * Based on Synopsys driver version 2.60a
+ * Modified by Mark Miesfeld mmiesf...@apm.com
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ * Modified by Chuck Meade ch...@theptrgroup.com
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL SYNOPSYS, INC. BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * This file contains the functions to manage Queue Heads and Queue
+ * Transfer Descriptors.
+ */
+
+#include dwc_otg_hcd.h
+
+static inline int is_fs_ls(enum usb_device_speed speed)
+{
+   return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
+}
+
+/* Allocates memory for a QH structure. */
+static inline struct dwc_qh *dwc_otg_hcd_qh_alloc(void)
+{
+   return kmalloc(sizeof(struct dwc_qh), GFP_ATOMIC);
+}
+
+/**
+ * Initializes a QH structure to initialize the QH.
+ */
+#define SCHEDULE_SLOP 10
+static void dwc_otg_hcd_qh_init(struct dwc_hcd *hcd, struct dwc_qh *qh,
+   struct urb *urb)
+{
+   memset(qh, 0, sizeof(struct dwc_qh));
+
+   /* Initialize QH */
+   switch (usb_pipetype(urb-pipe)) {
+   case PIPE_CONTROL:
+   qh-ep_type = USB_ENDPOINT_XFER_CONTROL;
+   break;
+   case PIPE_BULK:
+   qh-ep_type = USB_ENDPOINT_XFER_BULK;
+   break;
+   case PIPE_ISOCHRONOUS:
+   qh-ep_type = USB_ENDPOINT_XFER_ISOC;
+   break;
+   case PIPE_INTERRUPT:
+   qh-ep_type = USB_ENDPOINT_XFER_INT;
+   break;
+   }
+
+   qh-ep_is_in = usb_pipein(urb-pipe) ? 1 : 0;
+   qh-data_toggle = DWC_OTG_HC_PID_DATA0;
+   qh-maxp = usb_maxpacket(urb-dev, urb-pipe, !(usb_pipein(urb-pipe)));
+
+   INIT_LIST_HEAD(qh-qtd_list);
+   INIT_LIST_HEAD(qh-qh_list_entry);
+
+   qh-channel = NULL;
+   qh-speed = urb-dev-speed;
+
+   /*
+* FS/LS Enpoint on HS Hub NOT virtual root hub
+*/
+   qh-do_split = 0;
+   if (is_fs_ls(urb-dev-speed)  urb-dev-tt  urb-dev-tt-hub 
+   urb-dev-tt-hub-devnum != 1)
+   qh-do_split = 1;
+
+   if (qh-ep_type == USB_ENDPOINT_XFER_INT ||
+   qh-ep_type == USB_ENDPOINT_XFER_ISOC) {
+   /* Compute scheduling parameters once and save them. */
+   union hprt0_data hprt;
+   int bytecount = dwc_hb_mult(qh-maxp) *
+   dwc_max_packet(qh-maxp);
+
+   qh-usecs = NS_TO_US(usb_calc_bus_time(urb-dev-speed,
+   usb_pipein(urb-pipe),
+   (qh-ep_type == USB_ENDPOINT_XFER_ISOC),
+   bytecount));
+
+   /* Start in a slightly future (micro)frame. */
+   qh-sched_frame = dwc_frame_num_inc(hcd-frame_number,
+   SCHEDULE_SLOP);
+   qh

[PATCH V5 2/9] Add Synopsys DesignWare HS USB OTG driver framework.

2010-10-20 Thread Fushen Chen
Platform probing is in dwc_otg_apmppc.c.
Driver parameter and parameter checking are in dwc_otg_param.c.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_apmppc.c |  394 ++
 drivers/usb/dwc_otg/dwc_otg_driver.h |   78 
 drivers/usb/dwc_otg/dwc_otg_param.c  |  730 ++
 3 files changed, 1202 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_apmppc.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_param.c

diff --git a/drivers/usb/dwc_otg/dwc_otg_apmppc.c 
b/drivers/usb/dwc_otg/dwc_otg_apmppc.c
new file mode 100644
index 000..a5c75c4
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_apmppc.c
@@ -0,0 +1,394 @@
+/*
+ * DesignWare HS OTG controller driver
+ * Copyright (C) 2006 Synopsys, Inc.
+ * Portions Copyright (C) 2010 Applied Micro Circuits Corporation.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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 version 2 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see http://www.gnu.org/licenses
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Suite 500, Boston, MA 02110-1335 USA.
+ *
+ * Based on Synopsys driver version 2.60a
+ * Modified by Mark Miesfeld mmiesf...@apm.com
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL SYNOPSYS, INC. BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * The dwc_otg module provides the initialization and cleanup entry
+ * points for the dwcotg driver. This module will be dynamically installed
+ * after Linux is booted using the insmod command. When the module is
+ * installed, the dwc_otg_driver_init function is called. When the module is
+ * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
+ *
+ * This module also defines a data structure for the dwc_otg driver, which is
+ * used in conjunction with the standard device structure. These
+ * structures allow the OTG driver to comply with the standard Linux driver
+ * model in which devices and drivers are registered with a bus driver. This
+ * has the benefit that Linux can expose attributes of the driver and device
+ * in its special sysfs file system. Users can then read or write files in
+ * this file system to perform diagnostics on the driver components or the
+ * device.
+ */
+
+#include linux/of_platform.h
+
+#include dwc_otg_driver.h
+
+#define DWC_DRIVER_VERSION 1.05
+#define DWC_DRIVER_DESCHS OTG USB Controller driver
+static const char dwc_driver_name[] = dwc_otg;
+
+/**
+ * This function is the top level interrupt handler for the Common
+ * (Device and host modes) interrupts.
+ */
+static irqreturn_t dwc_otg_common_irq(int _irq, void *dev)
+{
+   struct dwc_otg_device *dwc_dev = dev;
+   int retval = IRQ_NONE;
+
+   retval = dwc_otg_handle_common_intr(dwc_dev-core_if);
+   return IRQ_RETVAL(retval);
+}
+
+/**
+ * This function is the interrupt handler for the OverCurrent condition
+ * from the external charge pump (if enabled)
+ */
+static irqreturn_t dwc_otg_externalchgpump_irq(int _irq, void *dev)
+{
+   struct dwc_otg_device *dwc_dev = dev;
+
+   if (dwc_otg_is_host_mode(dwc_dev-core_if)) {
+   struct dwc_hcd *dwc_hcd;
+   union hprt0_data hprt0 = {.d32 = 0};
+
+   dwc_hcd = dwc_dev-hcd;
+   spin_lock(dwc_hcd-lock);
+   dwc_hcd-flags.b.port_over_current_change = 1;
+
+   hprt0.b.prtpwr = 0;
+   dwc_write_reg32(dwc_dev-core_if-host_if-hprt0,
+   hprt0.d32);
+   spin_unlock(dwc_hcd-lock);
+   } else {
+   /* Device mode - This int is n/a for device mode */
+   printk

[PATCH V5 5/9] Add Synopsys DesignWare HS USB OTG HCD interrupt function.

2010-10-20 Thread Fushen Chen
Implements DWC OTG USB HCD interrupt service routine.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c | 1465 
 1 files changed, 1465 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c

diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c 
b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
new file mode 100644
index 000..c4c8e10
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
@@ -0,0 +1,1465 @@
+/*
+ * DesignWare HS OTG controller driver
+ * Copyright (C) 2006 Synopsys, Inc.
+ * Portions Copyright (C) 2010 Applied Micro Circuits Corporation.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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 version 2 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see http://www.gnu.org/licenses
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Suite 500, Boston, MA 02110-1335 USA.
+ *
+ * Based on Synopsys driver version 2.60a
+ * Modified by Mark Miesfeld mmiesf...@apm.com
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ * Modified by Chuck Meade ch...@theptrgroup.com
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL SYNOPSYS, INC. BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include dwc_otg_hcd.h
+
+/* This file contains the implementation of the HCD Interrupt handlers.
*/
+static const int erratum_usb09_patched;
+static const int deferral_on = 1;
+static const int nak_deferral_delay = 8;
+static const int nyet_deferral_delay = 1;
+
+/**
+ * Handles the start-of-frame interrupt in host mode. Non-periodic
+ * transactions may be queued to the DWC_otg controller for the current
+ * (micro)frame. Periodic transactions may be queued to the controller for the
+ * next (micro)frame.
+ */
+static int dwc_otg_hcd_handle_sof_intr(struct dwc_hcd *hcd)
+{
+   union hfnum_data hfnum;
+   struct list_head *qh_entry;
+   struct dwc_qh *qh;
+   enum dwc_transaction_type tr_type;
+   union gintsts_data gintsts = {.d32 = 0};
+
+   hfnum.d32 =
+   dwc_read_reg32(hcd-core_if-host_if-host_global_regs-hfnum);
+
+   hcd-frame_number = hfnum.b.frnum;
+
+   /* Determine whether any periodic QHs should be executed. */
+   qh_entry = hcd-periodic_sched_inactive.next;
+   while (qh_entry != hcd-periodic_sched_inactive) {
+   qh = list_entry(qh_entry, struct dwc_qh, qh_list_entry);
+   qh_entry = qh_entry-next;
+
+   /*
+* If needed, move QH to the ready list to be executed next
+* (micro)frame.
+*/
+   if (dwc_frame_num_le(qh-sched_frame, hcd-frame_number))
+   list_move(qh-qh_list_entry,
+   hcd-periodic_sched_ready);
+   }
+
+   tr_type = dwc_otg_hcd_select_transactions(hcd);
+   if (tr_type != DWC_OTG_TRANSACTION_NONE)
+   dwc_otg_hcd_queue_transactions(hcd, tr_type);
+
+   /* Clear interrupt */
+   gintsts.b.sofintr = 1;
+   dwc_write_reg32(gintsts_reg(hcd), gintsts.d32);
+   return 1;
+}
+
+/**
+ * Handles the Rx Status Queue Level Interrupt, which indicates that there is 
at
+ * least one packet in the Rx FIFO.  The packets are moved from the FIFO to
+ * memory if the DWC_otg controller is operating in Slave mode.
+ */
+static int dwc_otg_hcd_handle_rx_status_q_level_intr(struct dwc_hcd *hcd)
+{
+   union host_grxsts_data grxsts;
+   struct dwc_hc *hc = NULL;
+
+   grxsts.d32 = dwc_read_reg32(hcd-core_if-core_global_regs-grxstsp);
+   hc = hcd-hc_ptr_array[grxsts.b.chnum];
+
+   /* Packet Status */
+   switch (grxsts.b.pktsts) {
+   case DWC_GRXSTS_PKTSTS_IN:
+   /* Read the data into the host buffer. */
+   if (grxsts.b.bcnt  0

[PATCH V5 7/9] Add Synopsys DesignWare HS USB OTG PCD function.

2010-10-20 Thread Fushen Chen
The PCD is responsible for translating requests from the gadget driver
to appropriate actions on the DWC OTG controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_pcd.c | 1733 +
 drivers/usb/dwc_otg/dwc_otg_pcd.h |  137 +++
 2 files changed, 1870 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.h

diff --git a/drivers/usb/dwc_otg/dwc_otg_pcd.c 
b/drivers/usb/dwc_otg/dwc_otg_pcd.c
new file mode 100644
index 000..9e226d7
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_pcd.c
@@ -0,0 +1,1733 @@
+/*
+ * DesignWare HS OTG controller driver
+ * Copyright (C) 2006 Synopsys, Inc.
+ * Portions Copyright (C) 2010 Applied Micro Circuits Corporation.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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 version 2 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see http://www.gnu.org/licenses
+ * or write to the Free Software Foundation, Inc., 51 Franklin Street,
+ * Suite 500, Boston, MA 02110-1335 USA.
+ *
+ * Based on Synopsys driver version 2.60a
+ * Modified by Mark Miesfeld mmiesf...@apm.com
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL SYNOPSYS, INC. BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * This file implements the Peripheral Controller Driver.
+ *
+ * The Peripheral Controller Driver (PCD) is responsible for
+ * translating requests from the Function Driver into the appropriate
+ * actions on the DWC_otg controller. It isolates the Function Driver
+ * from the specifics of the controller by providing an API to the
+ * Function Driver.
+ *
+ * The Peripheral Controller Driver for Linux will implement the
+ * Gadget API, so that the existing Gadget drivers can be used.
+ * (Gadget Driver is the Linux terminology for a Function Driver.)
+ *
+ * The Linux Gadget API is defined in the header file linux/usb/gadget.h. The
+ * USB EP operations API is defined in the structure usb_ep_ops and the USB
+ * Controller API is defined in the structure usb_gadget_ops
+ *
+ * An important function of the PCD is managing interrupts generated
+ * by the DWC_otg controller. The implementation of the DWC_otg device
+ * mode interrupt service routines is in dwc_otg_pcd_intr.c.
+ */
+
+#include linux/dma-mapping.h
+#include linux/delay.h
+
+#include dwc_otg_pcd.h
+
+/*
+ * Static PCD pointer for use in usb_gadget_register_driver and
+ * usb_gadget_unregister_driver.  Initialized in dwc_otg_pcd_init.
+ */
+static struct dwc_pcd *s_pcd;
+
+static inline int need_stop_srp_timer(struct core_if *core_if)
+{
+   if (core_if-core_params-phy_type != DWC_PHY_TYPE_PARAM_FS ||
+   !core_if-core_params-i2c_enable)
+   return core_if-srp_timer_started ? 1 : 0;
+   return 0;
+}
+
+/**
+ * Tests if the module is set to FS or if the PHY_TYPE is FS. If so, then the
+ * gadget should not report as dual-speed capable.
+ */
+static inline int check_is_dual_speed(struct core_if *core_if)
+{
+   if (core_if-core_params-speed == DWC_SPEED_PARAM_FULL ||
+   (core_if-hwcfg2.b.hs_phy_type == 2 
+   core_if-hwcfg2.b.fs_phy_type == 1 
+   core_if-core_params-ulpi_fs_ls))
+   return 0;
+   return 1;
+}
+
+/**
+ * Tests if driver is OTG capable.
+ */
+static inline int check_is_otg(struct core_if *core_if)
+{
+   if (core_if-hwcfg2.b.op_mode ==
+   DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE ||
+   core_if-hwcfg2.b.op_mode ==
+   DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST ||
+   core_if-hwcfg2.b.op_mode ==
+   DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE

[PATCH V5 0/9] Add Synopsys DesignWare HS USB OTG driver

2010-10-20 Thread Fushen Chen
This patch series add Synopsys DesignWare HS USB OTG driver support.

PATCH V5 has a new license header from Synopsys and APM 
Previous versions:
  1. Addressed comment from Wolfgang Denk to sync with
 git://git.denx.de/linux-2.6-denx.git.
  2. Added bug fixes and features from Stefan Roese and Chuck Meade.
  3. Removed dts file from this pathch per Sergei Shtylyov suggestion.
 We'll submit a separate patch to PowerPC tree.
  4. Modified driver to use generic USB OTG enumeration state.
  5. Move Makefiles to the last patch per David Daney suggestion.

Fushen Chen (9):
  Add Synopsys DesignWare HS USB OTG Control and Status Register (CSR).
  Add Synopsys DesignWare HS USB OTG driver framework.
  Add Synopsys DesignWare HS USB OTG Core Interface Layer (CIL).
  Add Synopsys DesignWare HS USB OTG HCD function.
  Add Synopsys DesignWare HS USB OTG HCD interrupt function.
  Add Synopsys DesignWare HS USB OTG HCD queue function.
  Add Synopsys DesignWare HS USB OTG PCD function.
  Add Synopsys DesignWare HS USB OTG PCD interrupt function.
  Add Synopsys DesignWare HS USB OTG driver kernel configuration and
Makefile.

 drivers/Makefile|1 +
 drivers/usb/Kconfig |2 +
 drivers/usb/dwc_otg/Kconfig |   99 +
 drivers/usb/dwc_otg/Makefile|   19 +
 drivers/usb/dwc_otg/dwc_otg_apmppc.c|  394 
 drivers/usb/dwc_otg/dwc_otg_cil.c   |  892 +
 drivers/usb/dwc_otg/dwc_otg_cil.h   | 1181 +++
 drivers/usb/dwc_otg/dwc_otg_cil_intr.c  |  618 ++
 drivers/usb/dwc_otg/dwc_otg_driver.h|   78 +
 drivers/usb/dwc_otg/dwc_otg_hcd.c   | 2400 +++
 drivers/usb/dwc_otg/dwc_otg_hcd.h   |  413 
 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c  | 1465 ++
 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c |  697 +++
 drivers/usb/dwc_otg/dwc_otg_param.c |  730 +++
 drivers/usb/dwc_otg/dwc_otg_pcd.c   | 1733 
 drivers/usb/dwc_otg/dwc_otg_pcd.h   |  137 ++
 drivers/usb/dwc_otg/dwc_otg_pcd_intr.c  | 2262 +
 drivers/usb/dwc_otg/dwc_otg_regs.h  | 3269 +++
 18 files changed, 16390 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/Kconfig
 create mode 100644 drivers/usb/dwc_otg/Makefile
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_apmppc.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil_intr.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_param.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.h
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd_intr.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_regs.h

-- 
1.7.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Question about dma_direct_ops in PowerPC.

2010-08-12 Thread Fushen Chen
We have a board with PCI device driver that calls for
pci_dma_sync_single_for_device.
This driver used to work for Linux kernel 2.6.25.

We ported to the driver to Linux kernel 2.6.32. The PCI device driver
doesn't work anymore.
The following call trace shows why the PCI driver won't work in kernel
2.6.32.
1. In pci_include/asm-generic/pci-dma-compat.h
pci_dma_sync_single_for_device calls for dma_sync_single_for_cpu
2. In include/asm-generic/dma-mapping-common.h
dma_sync_single_for_cpu calls for ops-sync_single_for_cpu
3. In arch/powerpc/kernel/dma.c
struct dma_map_ops dma_direct_ops = {
.alloc_coherent = dma_direct_alloc_coherent,
.free_coherent  = dma_direct_free_coherent,
.map_sg = dma_direct_map_sg,
.unmap_sg   = dma_direct_unmap_sg,
.dma_supported  = dma_direct_dma_supported,
.map_page   = dma_direct_map_page,
.unmap_page = dma_direct_unmap_page,
#ifdef CONFIG_NOT_COHERENT_CACHE
.sync_single_range_for_cpu  = dma_direct_sync_single_range,
.sync_single_range_for_device   = dma_direct_sync_single_range,
.sync_sg_for_cpu= dma_direct_sync_sg,
.sync_sg_for_device = dma_direct_sync_sg,
#endif
};
There is no ops defined for sync_single_for_cpu.
The pci_dma_sync_single_for_device is a no-op.

However Linux kernel 2.6.35.1 from kernel.org has the  .sync_single_for_cpu
for dma_direct_ops.
in arch/powerpc/kernel/dma.c
#ifdef CONFIG_NOT_COHERENT_CACHE
.sync_single_for_cpu= dma_direct_sync_single,
.sync_single_for_device = dma_direct_sync_single,
.sync_sg_for_cpu= dma_direct_sync_sg,
.sync_sg_for_device = dma_direct_sync_sg,
#endif


We won't move to Linux kernel 2.6.35 anytime soon.
My questions:
1. Is there any side effect for adding .sync_single_for_cpu to
dma_direct_ops in 2.6.32?
2. What will be the future development here?


Best regards  Thanks,
Fushen
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 0/2 v1.04] Add support for DWC OTG driver.

2010-07-29 Thread Fushen Chen
 [PATCH 1/2 v1.04]
 1. License information is under clarification.

I meant that APM is still working with Synopys to resolve the GPL License.
There is no result yet.
I'll change this line to License issue is resolved. if that happens.
I modified other part of the patch according to other reviewer's comment.

Thanks,
Fushen

On Wed, Jul 28, 2010 at 8:05 PM, Greg KH gre...@suse.de wrote:

 On Wed, Jul 28, 2010 at 05:28:41PM -0700, Fushen Chen wrote:
  [PATCH 1/2 v1.04]
  1. License information is under clarification.

 What do you mean by this?  I fail to see a change here, why just repost
 the same code again?

 What is being done to resolve the issues I outlined previously?

 greg k-h

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 0/2 v1.04] Add support for DWC OTG driver.

2010-07-28 Thread Fushen Chen
[PATCH 1/2 v1.04]
1. License information is under clarification.
2. Difference in v1.04 patch.
Added drivers/usb/dwc_otg/dwc_otg_param.c to [PATCH 1/2 v1.03] patch.
Coding style:
Added space line after declaration.
drivers/usb/dwc_otg/Kconfig:
Set dwc_otg driver to host mode in [PATCH 1/2 v1.04].
DWC_LIMITED_XFER_SIZE is selectable.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 5/9 v1.02] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-22 Thread Fushen Chen
Implements DWC OTG USB Host Controller Driver (HCD) interrupt
service routine.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c | 1477 
 1 files changed, 1477 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_intr.c

diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c 
b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
new file mode 100644
index 000..a6c93a1
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_hcd_intr.c
@@ -0,0 +1,1477 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by APM and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ * Modified by Chuck Meade ch...@theptrgroup.com
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+#include dwc_otg_driver.h
+#include dwc_otg_hcd.h
+#include dwc_otg_regs.h
+
+/* This file contains the implementation of the HCD Interrupt handlers.
*/
+static const int erratum_usb09_patched;
+static const int deferral_on = 1;
+static const int nak_deferral_delay = 8;
+static const int nyet_deferral_delay = 1;
+
+/**
+ * Handles the start-of-frame interrupt in host mode. Non-periodic
+ * transactions may be queued to the DWC_otg controller for the current
+ * (micro)frame. Periodic transactions may be queued to the controller for the
+ * next (micro)frame.
+ */
+static int dwc_otg_hcd_handle_sof_intr(struct dwc_hcd *hcd)
+{
+   union hfnum_data hfnum;
+   struct list_head *qh_entry;
+   struct dwc_qh *qh;
+   enum dwc_transaction_type tr_type;
+   union gintsts_data gintsts = {.d32 = 0};
+
+   hfnum.d32 =
+   dwc_read_reg32(hcd-core_if-host_if-host_global_regs-hfnum);
+
+   hcd-frame_number = hfnum.b.frnum;
+
+   /* Determine whether any periodic QHs should be executed. */
+   qh_entry = hcd-periodic_sched_inactive.next;
+   while (qh_entry != hcd-periodic_sched_inactive) {
+   qh = list_entry(qh_entry, struct dwc_qh, qh_list_entry);
+   qh_entry = qh_entry-next;
+
+   /*
+* If needed, move QH to the ready list to be executed next
+* (micro)frame.
+*/
+   if (dwc_frame_num_le(qh-sched_frame, hcd-frame_number))
+   list_move(qh-qh_list_entry,
+   hcd-periodic_sched_ready);
+   }
+
+   tr_type = dwc_otg_hcd_select_transactions(hcd);
+   if (tr_type != DWC_OTG_TRANSACTION_NONE

[PATCH 7/9 v1.02] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-22 Thread Fushen Chen
The Peripheral Controller Driver (PCD) is responsible for translating
requests from the Function Driver into the appropriate actions on the
DWC OTG controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_pcd.c | 1758 +
 drivers/usb/dwc_otg/dwc_otg_pcd.h |  160 
 2 files changed, 1918 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_pcd.h

diff --git a/drivers/usb/dwc_otg/dwc_otg_pcd.c 
b/drivers/usb/dwc_otg/dwc_otg_pcd.c
new file mode 100644
index 000..9bf663b
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_pcd.c
@@ -0,0 +1,1758 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by APM and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * This file implements the Peripheral Controller Driver.
+ *
+ * The Peripheral Controller Driver (PCD) is responsible for
+ * translating requests from the Function Driver into the appropriate
+ * actions on the DWC_otg controller. It isolates the Function Driver
+ * from the specifics of the controller by providing an API to the
+ * Function Driver.
+ *
+ * The Peripheral Controller Driver for Linux will implement the
+ * Gadget API, so that the existing Gadget drivers can be used.
+ * (Gadget Driver is the Linux terminology for a Function Driver.)
+ *
+ * The Linux Gadget API is defined in the header file linux/usb/gadget.h. The
+ * USB EP operations API is defined in the structure usb_ep_ops and the USB
+ * Controller API is defined in the structure usb_gadget_ops
+ *
+ * An important function of the PCD is managing interrupts generated
+ * by the DWC_otg controller. The implementation of the DWC_otg device
+ * mode interrupt service routines is in dwc_otg_pcd_intr.c.
+ */
+
+#include linux/kernel.h
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/list.h
+#include linux/interrupt.h
+#include linux/string.h
+#include linux/dma-mapping.h
+#include linux/delay.h
+#include linux/usb/ch9.h
+#include linux/usb/gadget.h
+
+#include dwc_otg_driver.h
+#include dwc_otg_pcd.h
+
+/*
+ * Static PCD pointer for use in usb_gadget_register_driver and
+ * usb_gadget_unregister_driver.  Initialized in dwc_otg_pcd_init.
+ */
+static struct dwc_pcd *s_pcd;
+
+static inline int need_stop_srp_timer(struct core_if *core_if

[PATCH 3/9 v1.02] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-22 Thread Fushen Chen
Core Interface Layer Common Interrupt handlers provides common interrupt
handler for both host controller and peripheral controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_cil_intr.c |  631 
 1 files changed, 631 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_cil_intr.c

diff --git a/drivers/usb/dwc_otg/dwc_otg_cil_intr.c 
b/drivers/usb/dwc_otg/dwc_otg_cil_intr.c
new file mode 100644
index 000..e25ea37
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_cil_intr.c
@@ -0,0 +1,631 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by APM and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * The Core Interface Layer provides basic services for accessing and
+ * managing the DWC_otg hardware. These services are used by both the
+ * Host Controller Driver and the Peripheral Controller Driver.
+ *
+ * This file contains the Common Interrupt handlers.
+ */
+#include linux/types.h
+#include linux/delay.h
+
+#include dwc_otg_regs.h
+#include dwc_otg_cil.h
+
+/**
+ *  This function will log a debug message
+ */
+static int dwc_otg_handle_mode_mismatch_intr(struct core_if *core_if)
+{
+   union gintsts_data gintsts;
+
+   printk(KERN_WARNING Mode Mismatch Interrupt: currently in %s mode\n,
+   dwc_otg_mode(core_if) ? Host : Device);
+
+   /* Clear interrupt */
+   gintsts.d32 = 0;
+   gintsts.b.modemismatch = 1;
+   dwc_write_reg32(core_if-core_global_regs-gintsts, gintsts.d32);
+
+   return 1;
+}
+
+/**
+ *  Start the HCD.  Helper function for using the HCD callbacks.
+ */
+static inline void hcd_start(struct core_if *core_if)
+{
+   if (core_if-hcd_cb  core_if-hcd_cb-start)
+   core_if-hcd_cb-start(core_if-hcd_cb-p);
+}
+
+/**
+ *  Stop the HCD.  Helper function for using the HCD callbacks.
+ */
+static inline void hcd_stop(struct core_if *core_if)
+{
+   if (core_if-hcd_cb  core_if-hcd_cb-stop)
+   core_if-hcd_cb-stop(core_if-hcd_cb-p);
+}
+
+/**
+ *  Disconnect the HCD.  Helper function for using the HCD callbacks.
+ */
+static inline void hcd_disconnect(struct core_if *core_if)
+{
+   if (core_if-hcd_cb  core_if-hcd_cb-disconnect)
+   core_if-hcd_cb-disconnect(core_if-hcd_cb-p);
+}
+
+/**
+ *  Inform the HCD the a New Session has begun.  Helper function for using the
+ *  HCD callbacks.
+ */
+static inline

[PATCH 1/9 v1.02] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-22 Thread Fushen Chen
The DWC OTG driver module provides the initialization and cleanup
entry points for the DWC OTG USB driver.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/Makefile |1 +
 drivers/usb/Kconfig  |2 +
 drivers/usb/dwc_otg/Kconfig  |   96 +++
 drivers/usb/dwc_otg/Makefile |   13 +
 drivers/usb/dwc_otg/dwc_otg_driver.c | 1246 ++
 drivers/usb/dwc_otg/dwc_otg_driver.h |   97 +++
 drivers/usb/gadget/Kconfig   |   21 +
 drivers/usb/gadget/gadget_chips.h|7 +
 8 files changed, 1483 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/Kconfig
 create mode 100644 drivers/usb/dwc_otg/Makefile
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.c
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_driver.h

diff --git a/drivers/Makefile b/drivers/Makefile
index 20dcced..f3fc7c7 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_UWB) += uwb/
 obj-$(CONFIG_USB_OTG_UTILS)+= usb/otg/
 obj-$(CONFIG_USB)  += usb/
 obj-$(CONFIG_USB_MUSB_HDRC)+= usb/musb/
+obj-$(CONFIG_USB_DWC_OTG)  += usb/dwc_otg/
 obj-$(CONFIG_PCI)  += usb/
 obj-$(CONFIG_USB_GADGET)   += usb/gadget/
 obj-$(CONFIG_SERIO)+= input/serio/
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 6a58cb1..f48920b 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -113,6 +113,8 @@ source drivers/usb/host/Kconfig
 
 source drivers/usb/musb/Kconfig
 
+source drivers/usb/dwc_otg/Kconfig
+
 source drivers/usb/class/Kconfig
 
 source drivers/usb/storage/Kconfig
diff --git a/drivers/usb/dwc_otg/Kconfig b/drivers/usb/dwc_otg/Kconfig
new file mode 100644
index 000..27ae0d5
--- /dev/null
+++ b/drivers/usb/dwc_otg/Kconfig
@@ -0,0 +1,96 @@
+#
+# USB Dual Role (OTG-ready) Controller Drivers
+# for silicon based on Synopsys DesignWare IP
+#
+
+comment Enable Host or Gadget support for DesignWare OTG controller
+   depends on !USB  USB_GADGET=n
+
+config USB_DWC_OTG
+   depends on (USB || USB_GADGET)
+   depends on 405EZ || 405EX || 460EX
+   select NOP_USB_XCEIV
+   select USB_OTG_UTILS
+   tristate Synopsys DWC OTG Controller
+   default USB_GADGET
+   help
+ This driver provides USB Device Controller support for the
+ Synopsys DesignWare USB OTG Core used on the AppliedMicro PowerPC SoC.
+
+config DWC_DEBUG
+   bool Enable DWC Debugging
+   depends on USB_DWC_OTG
+   default n
+   help
+ Enable DWC driver debugging
+
+choice
+   prompt DWC Mode Selection
+   depends on USB_DWC_OTG
+   default DWC_OTG_MODE
+   help
+ Select the DWC Core in OTG, Host only, or Device only mode.
+
+config DWC_OTG_MODE
+   bool DWC OTG Mode if 405EX || 460EX
+   select USB_GADGET_SELECTED
+
+config DWC_HOST_ONLY
+   bool DWC Host Only Mode if 405EX || 460EX
+
+config DWC_DEVICE_ONLY
+   bool DWC Device Only Mode
+   select USB_GADGET_SELECTED
+
+endchoice
+
+# enable peripheral support (including with OTG)
+config USB_GADGET_DWC_HDRC
+bool
+depends on USB_DWC_OTG  (DWC_DEVICE_ONLY || USB_DWC_OTG)
+
+choice
+   prompt DWC DMA/SlaveMode Selection
+   depends on USB_DWC_OTG
+   default DWC_DMA_MODE
+   help
+ Select the DWC DMA or Slave Mode.
+ DMA mode uses the DWC core internal DMA engines.
+ Slave mode uses the processor PIO to tranfer data.
+ In Slave mode, processor's DMA channels can be used if available.
+
+config DWC_SLAVE
+   bool DWC Slave Mode if 405EX || 460EX
+
+config DWC_DMA_MODE
+   bool DWC DMA Mode if 405EX || (460EX  \
+   (!USB_EHCI_HCD  || !USB_OHCI_HCD))
+
+endchoice
+
+config USB_OTG_WHITELIST
+   bool Rely on OTG Targeted Peripherals List
+   depends on !USB_SUSPEND
+   default n
+   help
+This is the same flag as in ../core/Kconfig.
+It is here for easy deselect.
+
+config DWC_OTG_REG_LE
+   depends on USB_DWC_OTG
+   bool DWC Little Endian Register if 405EX || 460EX
+   default y
+   help
+OTG core register access is Little-Endian.
+
+config DWC_OTG_FIFO_LE
+   depends on USB_DWC_OTG
+   bool DWC FIFO Little Endian if 405EZ
+   default n
+   help
+OTG core FIFO access is Little-Endian.
+
+config DWC_LIMITED_XFER_SIZE
+   depends on USB_DWC_OTG
+   bool DWC Endpoint Limited Xfer Size if 405EZ
+   default n
diff --git a/drivers/usb/dwc_otg/Makefile b/drivers/usb/dwc_otg/Makefile
new file mode 100644
index 000..337ff81
--- /dev/null
+++ b/drivers/usb/dwc_otg/Makefile
@@ -0,0 +1,13 @@
+#
+# OTG infrastructure and transceiver drivers
+#
+obj-$(CONFIG_USB_DWC_OTG)  += dwc_otg.o
+
+dwc_otg-objs := dwc_otg_driver.o dwc_otg_cil.o dwc_otg_cil_intr.o
+ifneq ($(CONFIG_DWC_DEVICE_ONLY),y)
+dwc_otg-objs

[PATCH 6/9 v1.02] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-22 Thread Fushen Chen
Implements functions to manage Queue Heads and Queue
Transfer Descriptors of DWC USB OTG Controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c |  719 +++
 1 files changed, 719 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc_otg/dwc_otg_hcd_queue.c

diff --git a/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c 
b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
new file mode 100644
index 000..97a7867
--- /dev/null
+++ b/drivers/usb/dwc_otg/dwc_otg_hcd_queue.c
@@ -0,0 +1,719 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by APM and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ * Modified by Chuck Meade ch...@theptrgroup.com
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * This file contains the functions to manage Queue Heads and Queue
+ * Transfer Descriptors.
+ */
+#include linux/kernel.h
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/list.h
+#include linux/interrupt.h
+#include linux/string.h
+
+#include dwc_otg_driver.h
+#include dwc_otg_hcd.h
+#include dwc_otg_regs.h
+
+static inline int is_fs_ls(enum usb_device_speed speed)
+{
+   return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
+}
+
+/* Allocates memory for a QH structure. */
+static inline struct dwc_qh *dwc_otg_hcd_qh_alloc(void)
+{
+   return kmalloc(sizeof(struct dwc_qh), GFP_ATOMIC);
+}
+
+/**
+ * Initializes a QH structure to initialize the QH.
+ */
+#define SCHEDULE_SLOP 10
+static void dwc_otg_hcd_qh_init(struct dwc_hcd *hcd, struct dwc_qh *qh,
+   struct urb *urb)
+{
+   memset(qh, 0, sizeof(struct dwc_qh));
+
+   /* Initialize QH */
+   switch (usb_pipetype(urb-pipe)) {
+   case PIPE_CONTROL:
+   qh-ep_type = USB_ENDPOINT_XFER_CONTROL;
+   break;
+   case PIPE_BULK:
+   qh-ep_type = USB_ENDPOINT_XFER_BULK;
+   break;
+   case PIPE_ISOCHRONOUS:
+   qh-ep_type = USB_ENDPOINT_XFER_ISOC;
+   break;
+   case PIPE_INTERRUPT:
+   qh-ep_type = USB_ENDPOINT_XFER_INT;
+   break;
+   }
+
+   qh-ep_is_in = usb_pipein(urb-pipe) ? 1 : 0;
+   qh-data_toggle = DWC_OTG_HC_PID_DATA0;
+   qh-maxp = usb_maxpacket(urb-dev, urb-pipe, !(usb_pipein(urb-pipe)));
+
+   INIT_LIST_HEAD(qh-qtd_list);
+   INIT_LIST_HEAD(qh-qh_list_entry);
+
+   qh

Re: [PATCH 1/9 v1.01] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-13 Thread fushen chen
On Mon, 2010-07-12 at 16:55 -0700, David Brownell wrote:
 Please remove all the changes not related to
 this Synopsis IP ... 
Could you clarify what is not Synopsis IP related in the patch?
 
 and make the OTG functionality
 key on the generic OTG symbol, not a DW-specific one.
 
 
Use drivers/usb/otg/otg.c and include/linux/usb/otg.h?

Thanks,
Fushen 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 3/9 v1.01] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-12 Thread Fushen Chen
Core Interface Layer Common Interrupt handlers provides common interrupt
handler for both host controller and peripheral controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_cil_intr.c |  642 
 1 files changed, 642 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_cil_intr.c

diff --git a/drivers/usb/otg/dwc_otg_cil_intr.c 
b/drivers/usb/otg/dwc_otg_cil_intr.c
new file mode 100644
index 000..9aa7807
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_cil_intr.c
@@ -0,0 +1,642 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * The Core Interface Layer provides basic services for accessing and
+ * managing the DWC_otg hardware. These services are used by both the
+ * Host Controller Driver and the Peripheral Controller Driver.
+ *
+ * This file contains the Common Interrupt handlers.
+ */
+#include linux/types.h
+#include linux/delay.h
+
+#include dwc_otg_regs.h
+#include dwc_otg_cil.h
+
+inline const char *op_state_str(struct core_if *core_if)
+{
+   return (core_if-op_state == A_HOST ? a_host :
+   (core_if-op_state == A_SUSPEND ? a_suspend :
+   (core_if-op_state == A_PERIPHERAL ? a_peripheral :
+   (core_if-op_state == B_PERIPHERAL ? b_peripheral :
+   (core_if-op_state == B_HOST ? b_host : unknown);
+}
+
+/**
+ *  This function will log a debug message
+ */
+static int dwc_otg_handle_mode_mismatch_intr(struct core_if *core_if)
+{
+   union gintsts_data gintsts;
+
+   printk(KERN_WARNING Mode Mismatch Interrupt: currently in %s mode\n,
+   dwc_otg_mode(core_if) ? Host : Device);
+
+   /* Clear interrupt */
+   gintsts.d32 = 0;
+   gintsts.b.modemismatch = 1;
+   dwc_write_reg32(core_if-core_global_regs-gintsts, gintsts.d32);
+
+   return 1;
+}
+
+/**
+ *  Start the HCD.  Helper function for using the HCD callbacks.
+ */
+static inline void hcd_start(struct core_if *core_if)
+{
+   if (core_if-hcd_cb  core_if-hcd_cb-start)
+   core_if-hcd_cb-start(core_if-hcd_cb-p);
+}
+
+/**
+ *  Stop the HCD.  Helper function for using the HCD callbacks.
+ */
+static inline void hcd_stop(struct core_if *core_if)
+{
+   if (core_if-hcd_cb  core_if-hcd_cb-stop)
+   core_if-hcd_cb-stop(core_if-hcd_cb-p);
+}
+
+/**
+ *  Disconnect

[PATCH 1/9 v1.01] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-12 Thread Fushen Chen
The DWC OTG driver module provides the initialization and cleanup
entry points for the DWC OTG USB driver.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/gadget/Kconfig|   32 +-
 drivers/usb/gadget/gadget_chips.h |7 +
 drivers/usb/otg/Kconfig   |   87 +++
 drivers/usb/otg/Makefile  |   10 +
 drivers/usb/otg/dwc_otg_driver.c  | 1238 +
 drivers/usb/otg/dwc_otg_driver.h  |   97 +++
 6 files changed, 1455 insertions(+), 16 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_driver.c
 create mode 100644 drivers/usb/otg/dwc_otg_driver.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index dd3b251..130626a 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -109,8 +109,8 @@ config  USB_GADGET_SELECTED
 #   - discrete ones (including all PCI-only controllers)
 #   - debug/dummy gadget+hcd is last.
 #
-choice
-   prompt USB Peripheral Controller
+menuconfig USB_PERIPHERAL_CONTROLLER
+   bool USB Peripheral Controller
depends on USB_GADGET
help
   A USB device uses a controller to talk to its host.
@@ -122,6 +122,8 @@ choice
 # Integrated controllers
 #
 
+if USB_PERIPHERAL_CONTROLLER
+
 config USB_GADGET_AT91
boolean Atmel AT91 USB Device Port
depends on ARCH_AT91  !ARCH_AT91SAM9RL  !ARCH_AT91CAP9  
!ARCH_AT91SAM9G45
@@ -542,7 +544,7 @@ config USB_DUMMY_HCD
 # NOTE:  Please keep dummy_hcd LAST so that real hardware appears
 # first and will be selected by default.
 
-endchoice
+endif # USB_PERIPHERAL_CONTROLLER
 
 config USB_GADGET_DUALSPEED
bool
@@ -714,7 +716,6 @@ config USB_GADGETFS
 config USB_FUNCTIONFS
tristate Function Filesystem (EXPERIMENTAL)
depends on EXPERIMENTAL
-   select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || 
USB_FUNCTIONFS_RNDIS)
help
  The Function Filesystem (FunctioFS) lets one create USB
  composite functions in user space in the same way as GadgetFS
@@ -723,31 +724,31 @@ config USB_FUNCTIONFS
  implemented in kernel space (for instance Ethernet, serial or
  mass storage) and other are implemented in user space.
 
- If you say y or m here you will be able what kind of
- configurations the gadget will provide.
-
  Say y to link the driver statically, or m to build
  a dynamically linked module called g_ffs.
 
 config USB_FUNCTIONFS_ETH
-   bool Include configuration with CDC ECM (Ethernet)
+   bool Include CDC ECM (Ethernet) function
depends on USB_FUNCTIONFS  NET
help
- Include a configuration with CDC ECM funcion (Ethernet) and the
- Funcion Filesystem.
+ Include an CDC ECM (Ethernet) funcion in the CDC ECM (Funcion)
+ Filesystem.  If you also say y to the RNDIS query below the
+ gadget will have two configurations.
 
 config USB_FUNCTIONFS_RNDIS
-   bool Include configuration with RNDIS (Ethernet)
+   bool Include RNDIS (Ethernet) function
depends on USB_FUNCTIONFS  NET
help
- Include a configuration with RNDIS funcion (Ethernet) and the 
Filesystem.
+ Include an RNDIS (Ethernet) funcion in the Funcion Filesystem.
+ If you also say y to the CDC ECM query above the gadget will
+ have two configurations.
 
 config USB_FUNCTIONFS_GENERIC
bool Include 'pure' configuration
-   depends on USB_FUNCTIONFS
+   depends on USB_FUNCTIONFS  (USB_FUNCTIONFS_ETH || 
USB_FUNCTIONFS_RNDIS)
help
- Include a configuration with the Function Filesystem alone with
- no Ethernet interface.
+ Include a configuration with FunctionFS and no Ethernet
+ configuration.
 
 config USB_FILE_STORAGE
tristate File-backed Storage Gadget
@@ -864,7 +865,6 @@ config USB_G_NOKIA
 config USB_G_MULTI
tristate Multifunction Composite Gadget (EXPERIMENTAL)
depends on BLOCK  NET
-   select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
help
  The Multifunction Composite Gadget provides Ethernet (RNDIS
  and/or CDC Ethernet), mass storage and ACM serial link
diff --git a/drivers/usb/gadget/gadget_chips.h 
b/drivers/usb/gadget/gadget_chips.h
index e511fec..c0dec12 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -142,6 +142,11 @@
 #define gadget_is_s3c_hsotg(g)0
 #endif
 
+#if defined(CONFIG_DWC_OTG_MODE) || defined(CONFIG_DWC_DEVICE_ONLY)
+#definegadget_is_dwc_otg_pcd(g)(!strcmp(dwc_otg_pcd, 
(g)-name))
+#else
+#definegadget_is_dwc_otg_pcd(g)0
+#endif
 
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
@@ -200,6 +205,8 @@ static inline int usb_gadget_controller_number(struct 
usb_gadget *gadget)
return 0x25;
else if (gadget_is_s3c_hsotg(gadget))
return

[PATCH 6/9 v1.01] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-12 Thread Fushen Chen
Implements functions to manage Queue Heads and Queue
Transfer Descriptors of DWC USB OTG Controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_hcd_queue.c |  719 +++
 1 files changed, 719 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_hcd_queue.c

diff --git a/drivers/usb/otg/dwc_otg_hcd_queue.c 
b/drivers/usb/otg/dwc_otg_hcd_queue.c
new file mode 100644
index 000..88f614c
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_hcd_queue.c
@@ -0,0 +1,719 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ * Modified by Chuck Meade ch...@theptrgroup.com
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * This file contains the functions to manage Queue Heads and Queue
+ * Transfer Descriptors.
+ */
+#include linux/kernel.h
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/list.h
+#include linux/interrupt.h
+#include linux/string.h
+
+#include dwc_otg_driver.h
+#include dwc_otg_hcd.h
+#include dwc_otg_regs.h
+
+static inline int is_fs_ls(enum usb_device_speed speed)
+{
+   return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
+}
+
+/* Allocates memory for a QH structure. */
+static inline struct dwc_qh *dwc_otg_hcd_qh_alloc(void)
+{
+   return kmalloc(sizeof(struct dwc_qh), GFP_ATOMIC);
+}
+
+/**
+ * Initializes a QH structure to initialize the QH.
+ */
+#define SCHEDULE_SLOP 10
+static void dwc_otg_hcd_qh_init(struct dwc_hcd *hcd, struct dwc_qh *qh,
+   struct urb *urb)
+{
+   memset(qh, 0, sizeof(struct dwc_qh));
+
+   /* Initialize QH */
+   switch (usb_pipetype(urb-pipe)) {
+   case PIPE_CONTROL:
+   qh-ep_type = USB_ENDPOINT_XFER_CONTROL;
+   break;
+   case PIPE_BULK:
+   qh-ep_type = USB_ENDPOINT_XFER_BULK;
+   break;
+   case PIPE_ISOCHRONOUS:
+   qh-ep_type = USB_ENDPOINT_XFER_ISOC;
+   break;
+   case PIPE_INTERRUPT:
+   qh-ep_type = USB_ENDPOINT_XFER_INT;
+   break;
+   }
+
+   qh-ep_is_in = usb_pipein(urb-pipe) ? 1 : 0;
+   qh-data_toggle = DWC_OTG_HC_PID_DATA0;
+   qh-maxp = usb_maxpacket(urb-dev, urb-pipe, !(usb_pipein(urb-pipe)));
+
+   INIT_LIST_HEAD(qh-qtd_list);
+   INIT_LIST_HEAD(qh-qh_list_entry);
+
+   qh-channel = NULL

[PATCH 5/9 v1.01] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-12 Thread Fushen Chen
Implements DWC OTG USB Host Controller Driver (HCD) interrupt
service routine.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_hcd_intr.c | 1473 
 1 files changed, 1473 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_hcd_intr.c

diff --git a/drivers/usb/otg/dwc_otg_hcd_intr.c 
b/drivers/usb/otg/dwc_otg_hcd_intr.c
new file mode 100644
index 000..5919002
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_hcd_intr.c
@@ -0,0 +1,1473 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ * Modified by Chuck Meade ch...@theptrgroup.com
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+#include dwc_otg_driver.h
+#include dwc_otg_hcd.h
+#include dwc_otg_regs.h
+
+/* This file contains the implementation of the HCD Interrupt handlers.
*/
+static const int erratum_usb09_patched;
+static const int deferral_on = 1;
+static const int nak_deferral_delay = 8;
+static const int nyet_deferral_delay = 1;
+
+/**
+ * Handles the start-of-frame interrupt in host mode. Non-periodic
+ * transactions may be queued to the DWC_otg controller for the current
+ * (micro)frame. Periodic transactions may be queued to the controller for the
+ * next (micro)frame.
+ */
+static int dwc_otg_hcd_handle_sof_intr(struct dwc_hcd *hcd)
+{
+   union hfnum_data hfnum;
+   struct list_head *qh_entry;
+   struct dwc_qh *qh;
+   enum dwc_transaction_type tr_type;
+   union gintsts_data gintsts = {.d32 = 0};
+
+   hfnum.d32 =
+   dwc_read_reg32(hcd-core_if-host_if-host_global_regs-hfnum);
+
+   hcd-frame_number = hfnum.b.frnum;
+
+   /* Determine whether any periodic QHs should be executed. */
+   qh_entry = hcd-periodic_sched_inactive.next;
+   while (qh_entry != hcd-periodic_sched_inactive) {
+   qh = list_entry(qh_entry, struct dwc_qh, qh_list_entry);
+   qh_entry = qh_entry-next;
+
+   /*
+* If needed, move QH to the ready list to be executed next
+* (micro)frame.
+*/
+   if (dwc_frame_num_le(qh-sched_frame, hcd-frame_number))
+   list_move(qh-qh_list_entry,
+   hcd-periodic_sched_ready);
+   }
+
+   tr_type = dwc_otg_hcd_select_transactions(hcd);
+   if (tr_type != DWC_OTG_TRANSACTION_NONE

[PATCH 7/9 v1.01] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-07-12 Thread Fushen Chen
The Peripheral Controller Driver (PCD) is responsible for translating
requests from the Function Driver into the appropriate actions on the
DWC OTG controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_pcd.c | 1749 +
 drivers/usb/otg/dwc_otg_pcd.h |  160 
 2 files changed, 1909 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_pcd.c
 create mode 100644 drivers/usb/otg/dwc_otg_pcd.h

diff --git a/drivers/usb/otg/dwc_otg_pcd.c b/drivers/usb/otg/dwc_otg_pcd.c
new file mode 100644
index 000..f0c3b04
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_pcd.c
@@ -0,0 +1,1749 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ * Modified by Stefan Roese s...@denx.de, DENX Software Engineering
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * This file implements the Peripheral Controller Driver.
+ *
+ * The Peripheral Controller Driver (PCD) is responsible for
+ * translating requests from the Function Driver into the appropriate
+ * actions on the DWC_otg controller. It isolates the Function Driver
+ * from the specifics of the controller by providing an API to the
+ * Function Driver.
+ *
+ * The Peripheral Controller Driver for Linux will implement the
+ * Gadget API, so that the existing Gadget drivers can be used.
+ * (Gadget Driver is the Linux terminology for a Function Driver.)
+ *
+ * The Linux Gadget API is defined in the header file linux/usb/gadget.h. The
+ * USB EP operations API is defined in the structure usb_ep_ops and the USB
+ * Controller API is defined in the structure usb_gadget_ops
+ *
+ * An important function of the PCD is managing interrupts generated
+ * by the DWC_otg controller. The implementation of the DWC_otg device
+ * mode interrupt service routines is in dwc_otg_pcd_intr.c.
+ */
+
+#include linux/kernel.h
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/list.h
+#include linux/interrupt.h
+#include linux/string.h
+#include linux/dma-mapping.h
+#include linux/delay.h
+#include linux/usb/ch9.h
+#include linux/usb/gadget.h
+
+#include dwc_otg_driver.h
+#include dwc_otg_pcd.h
+
+/*
+ * Static PCD pointer for use in usb_gadget_register_driver and
+ * usb_gadget_unregister_driver.  Initialized in dwc_otg_pcd_init.
+ */
+static struct dwc_pcd *s_pcd;
+
+static inline int need_stop_srp_timer(struct core_if *core_if)
+{
+   if (core_if

Re: [PATCH 1/9] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-06-30 Thread fushen chen
Stefan,

The driver is based on Synopsys driver 2.60a.

We started to prepare open source submission based on our internal
version. We sync this version to linux-2.6-denx repository from time to
time. I'll sync the driver to the latest linux-2.6-denx as Wolfgang
pointed out, and re-submit patch to open source.

We modified the driver mostly to follow Linux kernel coding style.  
Both USB host and device modes are tested. 

Thanks,
Fushen
 1. 

On Wed, 2010-06-30 at 11:27 +0200, Stefan Roese wrote:
 Hi Fushen, Hi Mark,
 
 On Tuesday 29 June 2010 23:26:54 Fushen Chen wrote:
  The DWC OTG driver module provides the initialization and cleanup
  entry points for the DWC OTG USB driver.
  
  Signed-off-by: Fushen Chen fc...@apm.com
  Signed-off-by: Mark Miesfeld mmiesf...@apm.com
 
 I tried to compare this driver with the version that's currently available in 
 the linux-2.6-denx repository. But the differences are quite big. Could you 
 please list the history of this DWC driver? Things like:
 
 - Which Synopsis version is it based upon?
 - What changes/enhancements/fixups where made from APM?
 - How was this driver tested (USB host and device mode)?
 
 As Wolfgang already pointed out, the driver in our git repository has 
 undergone multiple changes/fixes. Did you take a look at them and try to 
 integrate them?
 
 Thanks.
 
 Cheers,
 Stefan

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH 1/9] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-06-30 Thread fushen chen
David,

AppliedMicro has PPC-405EX and PPC-460EX SOC using this controller.
There will be another arch/powerpc/boot/dts/canyonlands.dts for
PPC-460EX board.

Thanks,
Fushen

 
 
On Tue, 2010-06-29 at 15:41 -0700, David Brownell wrote:
 Good -- MUSB won't be the only one.  ;)
 
 Could you mention a few Linux-enabled chips which
 include this controller?
 
 
   arch/powerpc/boot/dts/kilauea.dts |   15 +
 
 Also, please provide a clean patch that only
 includes the driver, and split PPC hooks into
 a separate patch.
 
 
 

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH 6/9] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-06-29 Thread Fushen Chen
Implements functions to manage Queue Heads and Queue
Transfer Descriptors of DWC USB OTG Controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_hcd_queue.c |  584 +++
 1 files changed, 584 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_hcd_queue.c

diff --git a/drivers/usb/otg/dwc_otg_hcd_queue.c 
b/drivers/usb/otg/dwc_otg_hcd_queue.c
new file mode 100644
index 000..a33c0da
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_hcd_queue.c
@@ -0,0 +1,584 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * This file contains the functions to manage Queue Heads and Queue
+ * Transfer Descriptors.
+ */
+#include linux/kernel.h
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/list.h
+#include linux/interrupt.h
+#include linux/string.h
+
+#include dwc_otg_driver.h
+#include dwc_otg_hcd.h
+#include dwc_otg_regs.h
+
+static inline int is_fs_ls(enum usb_device_speed speed)
+{
+   return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
+}
+
+/* Allocates memory for a QH structure. */
+static inline struct dwc_qh *dwc_otg_hcd_qh_alloc(void)
+{
+   return kmalloc(sizeof(struct dwc_qh), GFP_ATOMIC);
+}
+
+/**
+ * Initializes a QH structure to initialize the QH.
+ */
+#define SCHEDULE_SLOP 10
+static void dwc_otg_hcd_qh_init(struct dwc_hcd *hcd, struct dwc_qh *qh,
+   struct urb *urb)
+{
+   memset(qh, 0, sizeof(struct dwc_qh));
+
+   /* Initialize QH */
+   switch (usb_pipetype(urb-pipe)) {
+   case PIPE_CONTROL:
+   qh-ep_type = USB_ENDPOINT_XFER_CONTROL;
+   break;
+   case PIPE_BULK:
+   qh-ep_type = USB_ENDPOINT_XFER_BULK;
+   break;
+   case PIPE_ISOCHRONOUS:
+   qh-ep_type = USB_ENDPOINT_XFER_ISOC;
+   break;
+   case PIPE_INTERRUPT:
+   qh-ep_type = USB_ENDPOINT_XFER_INT;
+   break;
+   }
+
+   qh-ep_is_in = usb_pipein(urb-pipe) ? 1 : 0;
+   qh-data_toggle = DWC_OTG_HC_PID_DATA0;
+   qh-maxp = usb_maxpacket(urb-dev, urb-pipe, !(usb_pipein(urb-pipe)));
+
+   INIT_LIST_HEAD(qh-qtd_list);
+   INIT_LIST_HEAD(qh-qh_list_entry);
+
+   qh-channel = NULL;
+
+   /*
+* FS/LS Enpoint on HS Hub NOT virtual root hub
+*/
+   qh-do_split = 0

[PATCH 3/9] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-06-29 Thread Fushen Chen
Core Interface Layer Common Interrupt handlers provides common interrupt
handler for both host controller and peripheral controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_cil_intr.c |  625 
 1 files changed, 625 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_cil_intr.c

diff --git a/drivers/usb/otg/dwc_otg_cil_intr.c 
b/drivers/usb/otg/dwc_otg_cil_intr.c
new file mode 100644
index 000..2e5be88
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_cil_intr.c
@@ -0,0 +1,625 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * The Core Interface Layer provides basic services for accessing and
+ * managing the DWC_otg hardware. These services are used by both the
+ * Host Controller Driver and the Peripheral Controller Driver.
+ *
+ * This file contains the Common Interrupt handlers.
+ */
+
+#include dwc_otg_regs.h
+#include dwc_otg_cil.h
+
+#include linux/types.h
+#include linux/delay.h
+
+inline const char *op_state_str(struct core_if *core_if)
+{
+   return (core_if-op_state == A_HOST ? a_host :
+   (core_if-op_state == A_SUSPEND ? a_suspend :
+   (core_if-op_state == A_PERIPHERAL ? a_peripheral :
+   (core_if-op_state == B_PERIPHERAL ? b_peripheral :
+   (core_if-op_state == B_HOST ? b_host : unknown);
+}
+
+/**
+ *  This function will log a debug message
+ */
+static int dwc_otg_handle_mode_mismatch_intr(struct core_if *core_if)
+{
+   union gintsts_data gintsts;
+
+   printk(KERN_WARNING Mode Mismatch Interrupt: currently in %s mode\n,
+   dwc_otg_mode(core_if) ? Host : Device);
+
+   /* Clear interrupt */
+   gintsts.d32 = 0;
+   gintsts.b.modemismatch = 1;
+   dwc_write_reg32(core_if-core_global_regs-gintsts, gintsts.d32);
+
+   return 1;
+}
+
+/**
+ *  Start the HCD.  Helper function for using the HCD callbacks.
+ */
+static inline void hcd_start(struct core_if *core_if)
+{
+   if (core_if-hcd_cb  core_if-hcd_cb-start)
+   core_if-hcd_cb-start(core_if-hcd_cb-p);
+}
+
+/**
+ *  Stop the HCD.  Helper function for using the HCD callbacks.
+ */
+static inline void hcd_stop(struct core_if *core_if)
+{
+   if (core_if-hcd_cb  core_if-hcd_cb-stop)
+   core_if-hcd_cb-stop(core_if-hcd_cb-p);
+}
+
+/**
+ *  Disconnect the HCD.  Helper function for using the HCD callbacks

[PATCH 5/9] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-06-29 Thread Fushen Chen
Implements DWC OTG USB Host Controller Driver (HCD) interrupt
service routine.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_hcd_intr.c | 1446 
 1 files changed, 1446 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_hcd_intr.c

diff --git a/drivers/usb/otg/dwc_otg_hcd_intr.c 
b/drivers/usb/otg/dwc_otg_hcd_intr.c
new file mode 100644
index 000..dc00184
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_hcd_intr.c
@@ -0,0 +1,1446 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include dwc_otg_driver.h
+#include dwc_otg_hcd.h
+#include dwc_otg_regs.h
+
+/* This file contains the implementation of the HCD Interrupt handlers.
*/
+
+
+
+/**
+ * Handles the start-of-frame interrupt in host mode. Non-periodic
+ * transactions may be queued to the DWC_otg controller for the current
+ * (micro)frame. Periodic transactions may be queued to the controller for the
+ * next (micro)frame.
+ */
+static int dwc_otg_hcd_handle_sof_intr(struct dwc_hcd *hcd)
+{
+   union hfnum_data hfnum;
+   struct list_head *qh_entry;
+   struct dwc_qh *qh;
+   enum dwc_transaction_type tr_type;
+   union gintsts_data gintsts = {.d32 = 0};
+
+   hfnum.d32 =
+   dwc_read_reg32(hcd-core_if-host_if-host_global_regs-hfnum);
+
+   hcd-frame_number = hfnum.b.frnum;
+
+   /* Determine whether any periodic QHs should be executed. */
+   qh_entry = hcd-periodic_sched_inactive.next;
+   while (qh_entry != hcd-periodic_sched_inactive) {
+   qh = list_entry(qh_entry, struct dwc_qh, qh_list_entry);
+   qh_entry = qh_entry-next;
+
+   /*
+* If needed, move QH to the ready list to be executed next
+* (micro)frame.
+*/
+   if (dwc_frame_num_le(qh-sched_frame, hcd-frame_number))
+   list_move(qh-qh_list_entry,
+   hcd-periodic_sched_ready);
+   }
+
+   tr_type = dwc_otg_hcd_select_transactions(hcd);
+   if (tr_type != DWC_OTG_TRANSACTION_NONE)
+   dwc_otg_hcd_queue_transactions(hcd, tr_type);
+
+   /* Clear interrupt */
+   gintsts.b.sofintr = 1;
+   dwc_write_reg32(gintsts_reg(hcd), gintsts.d32);
+   return 1;
+}
+
+/**
+ * Handles the Rx Status Queue Level Interrupt, which indicates that there is 
at
+ * least one packet

[PATCH 1/9] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-06-29 Thread Fushen Chen
The DWC OTG driver module provides the initialization and cleanup
entry points for the DWC OTG USB driver.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 arch/powerpc/boot/dts/kilauea.dts |   15 +
 drivers/usb/gadget/Kconfig|8 +-
 drivers/usb/gadget/gadget_chips.h |7 +
 drivers/usb/otg/Kconfig   |   87 +++
 drivers/usb/otg/Makefile  |   10 +
 drivers/usb/otg/dwc_otg_driver.c  | 1236 +
 drivers/usb/otg/dwc_otg_driver.h  |   97 +++
 7 files changed, 1457 insertions(+), 3 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_driver.c
 create mode 100644 drivers/usb/otg/dwc_otg_driver.h

diff --git a/arch/powerpc/boot/dts/kilauea.dts 
b/arch/powerpc/boot/dts/kilauea.dts
index 083e68e..1a141b8 100644
--- a/arch/powerpc/boot/dts/kilauea.dts
+++ b/arch/powerpc/boot/dts/kilauea.dts
@@ -394,5 +394,20 @@
0x0 0x0 0x0 0x3 UIC2 0xd 0x4 /* swizzled int C 
*/
0x0 0x0 0x0 0x4 UIC2 0xe 0x4 /* swizzled int D 
*/;
};
+
+   USBOTG0: usb...@ef6c {
+   compatible = amcc,dwc-otg;
+   reg = 0xef6c 0x1;
+   interrupt-parent = USBOTG0;
+   interrupts = 0x0 0x1 0x2;
+   #interrupt-cells = 0x1;
+   #address-cells = 0x0;
+   #size-cells = 0x0;
+   interrupt-map = 
+   0x0 UIC2 0x1e 0x4 /* USB-OTG */
+   0x1 UIC1 0x1a 0x8 /* HIGH-POWER */
+   0x2 UIC0 0xc 0x4  /* DMA */ ;
+   interrupt-map-mask = 0x;
+   };
};
 };
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 591ae9f..130626a 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -109,8 +109,8 @@ config  USB_GADGET_SELECTED
 #   - discrete ones (including all PCI-only controllers)
 #   - debug/dummy gadget+hcd is last.
 #
-choice
-   prompt USB Peripheral Controller
+menuconfig USB_PERIPHERAL_CONTROLLER
+   bool USB Peripheral Controller
depends on USB_GADGET
help
   A USB device uses a controller to talk to its host.
@@ -122,6 +122,8 @@ choice
 # Integrated controllers
 #
 
+if USB_PERIPHERAL_CONTROLLER
+
 config USB_GADGET_AT91
boolean Atmel AT91 USB Device Port
depends on ARCH_AT91  !ARCH_AT91SAM9RL  !ARCH_AT91CAP9  
!ARCH_AT91SAM9G45
@@ -542,7 +544,7 @@ config USB_DUMMY_HCD
 # NOTE:  Please keep dummy_hcd LAST so that real hardware appears
 # first and will be selected by default.
 
-endchoice
+endif # USB_PERIPHERAL_CONTROLLER
 
 config USB_GADGET_DUALSPEED
bool
diff --git a/drivers/usb/gadget/gadget_chips.h 
b/drivers/usb/gadget/gadget_chips.h
index e511fec..3d5c136 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -142,6 +142,11 @@
 #define gadget_is_s3c_hsotg(g)0
 #endif
 
+#if defined(CONFIG_USB_DWC_OTG) || defined(CONFIG_DWC_DEVICE_ONLY)
+#definegadget_is_dwc_otg_pcd(g)(!strcmp(dwc_otg_pcd, 
(g)-name))
+#else
+#definegadget_is_dwc_otg_pcd(g)0
+#endif
 
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
@@ -200,6 +205,8 @@ static inline int usb_gadget_controller_number(struct 
usb_gadget *gadget)
return 0x25;
else if (gadget_is_s3c_hsotg(gadget))
return 0x26;
+   else if (gadget_is_dwc_otg_pcd(gadget))
+   return 0x27;
return -ENOENT;
 }
 
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 3d2d3e5..745bac2 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -69,4 +69,91 @@ config NOP_USB_XCEIV
 built-in with usb ip or which are autonomous and doesn't require any
 phy programming such as ISP1x04 etc.
 
+config USB_DWC_OTG
+   depends on (USB || USB_GADGET)
+   depends on 405EZ || 405EX || 460EX
+   select USB_OTG_UTILS
+   tristate Synopsys DWC OTG Controller
+   default USB_GADGET
+   help
+ This driver provides USB Device Controller support for the
+ Synopsys DesignWare USB OTG Core used on the AMCC 405EZ/405EX/
+ 460EX.
+
+ Note that on the 405EZ, this Core provides USB Device Controller
+ function only.  It does not act as a true OTG device, and the
+ 'OTG' is slightly misleading.
+
+config DWC_LEGACY_405EX
+   bool Enable 405EX Legacy Support (lower performance)
+   default n
+   depends on USB_DWC_OTG  405EX
+   select DWC_SLAVE
+   help
+ Enable Legacy 405EX Chip support (Rev 1.0) where DWC DMA is broken
+ Selecting this option will cause lower performance
+ Don't select this unless you want to support Rev 1.0 405EX chips 
(obsolete

[PATCH 7/9] Add Synopsys DesignWare HS USB OTG Controller driver.

2010-06-29 Thread Fushen Chen
The Peripheral Controller Driver (PCD) is responsible for translating
requests from the Function Driver into the appropriate actions on the
DWC OTG controller.

Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/otg/dwc_otg_pcd.c | 1749 +
 drivers/usb/otg/dwc_otg_pcd.h |  159 
 2 files changed, 1908 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/otg/dwc_otg_pcd.c
 create mode 100644 drivers/usb/otg/dwc_otg_pcd.h

diff --git a/drivers/usb/otg/dwc_otg_pcd.c b/drivers/usb/otg/dwc_otg_pcd.c
new file mode 100644
index 000..152c0a6
--- /dev/null
+++ b/drivers/usb/otg/dwc_otg_pcd.c
@@ -0,0 +1,1749 @@
+/*
+ * DesignWare HS OTG controller driver
+ *
+ * Author: Mark Miesfeld mmiesf...@apm.com
+ *
+ * Based on versions provided by AMCC and Synopsis which are:
+ * Copyright (C) 2009-2010 AppliedMicro(www.apm.com)
+ *
+ * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
+ * Software) is an Unsupported proprietary work of Synopsys, Inc. unless
+ * otherwise expressly agreed to in writing between Synopsys and you.
+ *
+ * The Software IS NOT an item of Licensed Software or Licensed Product under
+ * any End User Software License Agreement or Agreement for Licensed Product
+ * with Synopsys or any supplement thereto. You are permitted to use and
+ * redistribute this Software in source and binary forms, with or without
+ * modification, provided that redistributions of source code must retain this
+ * notice. You may not view, use, disclose, copy or distribute this file or
+ * any information contained herein except pursuant to this license grant from
+ * Synopsys. If you do not agree with this notice, including the disclaimer
+ * below, then you are not authorized to use the Software.
+ *
+ * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN AS IS BASIS
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/*
+ * This file implements the Peripheral Controller Driver.
+ *
+ * The Peripheral Controller Driver (PCD) is responsible for
+ * translating requests from the Function Driver into the appropriate
+ * actions on the DWC_otg controller. It isolates the Function Driver
+ * from the specifics of the controller by providing an API to the
+ * Function Driver.
+ *
+ * The Peripheral Controller Driver for Linux will implement the
+ * Gadget API, so that the existing Gadget drivers can be used.
+ * (Gadget Driver is the Linux terminology for a Function Driver.)
+ *
+ * The Linux Gadget API is defined in the header file linux/usb/gadget.h. The
+ * USB EP operations API is defined in the structure usb_ep_ops and the USB
+ * Controller API is defined in the structure usb_gadget_ops
+ *
+ * An important function of the PCD is managing interrupts generated
+ * by the DWC_otg controller. The implementation of the DWC_otg device
+ * mode interrupt service routines is in dwc_otg_pcd_intr.c.
+ */
+
+#include linux/kernel.h
+#include linux/module.h
+#include linux/moduleparam.h
+#include linux/init.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/list.h
+#include linux/interrupt.h
+#include linux/string.h
+#include linux/dma-mapping.h
+#include linux/delay.h
+#include linux/usb/ch9.h
+#include linux/usb/gadget.h
+
+#include dwc_otg_driver.h
+#include dwc_otg_pcd.h
+
+/*
+ * Static PCD pointer for use in usb_gadget_register_driver and
+ * usb_gadget_unregister_driver.  Initialized in dwc_otg_pcd_init.
+ */
+static struct dwc_pcd *s_pcd;
+
+static inline int need_stop_srp_timer(struct core_if *core_if)
+{
+   if (core_if-core_params-phy_type != DWC_PHY_TYPE_PARAM_FS