Re: [PATCH v13 02/10] USB/ppc4xx: Add Synopsys DWC OTG driver framework

2011-04-04 Thread Felipe Balbi
On Sun, Apr 03, 2011 at 04:16:50PM -0700, tma...@apm.com wrote:
 From: Tirumala Marri tma...@apm.com
 
 Platform probing is in dwc_otg_apmppc.c.
 Driver parameter and parameter checking are in dwc_otg_param.c.
 
 Signed-off-by: Tirumala R Marri tma...@apm.com
 Signed-off-by: Fushen Chen fc...@apm.com
 Signed-off-by: Mark Miesfeld mmiesf...@apm.com
 ---
  drivers/usb/dwc/apmppc.c |  414 
 ++
  drivers/usb/dwc/driver.h |   76 +
  drivers/usb/dwc/param.c  |  180 
  3 files changed, 670 insertions(+), 0 deletions(-)
  create mode 100644 drivers/usb/dwc/apmppc.c
  create mode 100644 drivers/usb/dwc/driver.h
  create mode 100644 drivers/usb/dwc/param.c
 
 diff --git a/drivers/usb/dwc/apmppc.c b/drivers/usb/dwc/apmppc.c
 new file mode 100644
 index 000..ffbe6dd
 --- /dev/null
 +++ b/drivers/usb/dwc/apmppc.c
 @@ -0,0 +1,414 @@
 +/*
 + * 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 driver.h
 +
 +#define DWC_DRIVER_VERSION   1.05
 +#define DWC_DRIVER_DESC  HS 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;
 +
 + retval = dwc_otg_handle_common_intr(dwc_dev-core_if);

no lock needed ? What if you get another IRQ while you're calling
dwc_otg_handle_common_intr() ??

 + return IRQ_RETVAL(retval);
 +}
 +
 +/**
 + * This function is the interrupt handler for the OverCurrent condition
 + * from the external charge pump (if enabled)
 + */

this comment is completely unnecessary. Same goes for most all other
functions. The ones which would be nice to keep, should be converted to
kerneldoc so we can extract documentation from source code if we
need/want.

 +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;
 + u32 hprt0 = 0;
 +
 +

[PATCH v13 02/10] USB/ppc4xx: Add Synopsys DWC OTG driver framework

2011-04-03 Thread tmarri
From: Tirumala Marri tma...@apm.com

Platform probing is in dwc_otg_apmppc.c.
Driver parameter and parameter checking are in dwc_otg_param.c.

Signed-off-by: Tirumala R Marri tma...@apm.com
Signed-off-by: Fushen Chen fc...@apm.com
Signed-off-by: Mark Miesfeld mmiesf...@apm.com
---
 drivers/usb/dwc/apmppc.c |  414 ++
 drivers/usb/dwc/driver.h |   76 +
 drivers/usb/dwc/param.c  |  180 
 3 files changed, 670 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/dwc/apmppc.c
 create mode 100644 drivers/usb/dwc/driver.h
 create mode 100644 drivers/usb/dwc/param.c

diff --git a/drivers/usb/dwc/apmppc.c b/drivers/usb/dwc/apmppc.c
new file mode 100644
index 000..ffbe6dd
--- /dev/null
+++ b/drivers/usb/dwc/apmppc.c
@@ -0,0 +1,414 @@
+/*
+ * 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 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;
+
+   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;
+   u32 hprt0 = 0;
+
+   dwc_hcd = dwc_dev-hcd;
+   spin_lock(dwc_hcd-lock);
+   dwc_hcd-flags.b.port_over_current_change = 1;
+
+   hprt0 = DWC_HPRT0_PRT_PWR_RW(hprt0, 0);
+   dwc_write32(dwc_dev-core_if-host_if-hprt0, hprt0);
+   spin_unlock(dwc_hcd-lock);
+   } else {
+   /* Device mode - This int is n/a for device mode */
+   dev_dbg(dev, DeviceMode: OTG OverCurrent Detected\n);
+   }
+
+   return