Received: from mail.onstor.com (66.201.51.107) by exch1.onstor.net
 (10.0.0.225) with Microsoft SMTP Server id 8.1.311.2; Fri, 6 Mar 2009
 08:24:03 -0800
Received: from ausesmta2-2.messageone.com ([64.20.241.45]) by mail.onstor.com
 with Microsoft SMTPSVC(6.0.3790.3959);	 Fri, 6 Mar 2009 08:24:01 -0800
Received: from ftp.linux-mips.org (ftp.linux-mips.org [213.58.128.207])	by
 ausesmta2-2.messageone.com (8.13.8/8.13.8) with ESMTP id n26GO0r3002434	for
 <andy.sharp@onstor.com>; Fri, 6 Mar 2009 10:24:02 -0600
Received: from localhost.localdomain ([127.0.0.1]:12777 "EHLO
	ftp.linux-mips.org") by ftp.linux-mips.org with ESMTP	id S20808295AbZCFQWp
 (ORCPT <rfc822;andy.sharp@onstor.com>);	Fri, 6 Mar 2009 16:22:45 +0000
Received: with ECARTIS (v1.0.0; list linux-mips); Fri, 06 Mar 2009 16:22:27
 +0000 (GMT)
Received: from mx1.rmicorp.com ([63.111.213.197]:35445 "EHLO mx1.rmicorp.com")
	by ftp.linux-mips.org with ESMTP id S21366481AbZCFQUU (ORCPT
	<rfc822;linux-mips@linux-mips.org>); Fri, 6 Mar 2009 16:20:20 +0000
Received: from sark.razamicroelectronics.com ([10.8.0.254]) by mx1.rmicorp.com
 with Microsoft SMTPSVC(6.0.3790.3959);	 Fri, 6 Mar 2009 08:20:09 -0800
Received: from localhost.localdomain (unknown [10.8.0.23])	by
 sark.razamicroelectronics.com (Postfix) with ESMTP id D70F6EE76AB;	Fri,  6
 Mar 2009 09:42:10 -0600 (CST)
From: Kevin Hickey <khickey@rmicorp.com>
To: "ralf@linux-mips.org" <ralf@linux-mips.org>, "linux-mips@linux-mips.org"
	<linux-mips@linux-mips.org>
CC: Kevin Hickey <khickey@rmicorp.com>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Fri, 6 Mar 2009 08:20:05 -0800
Subject: [PATCH 06/10] Alchemy: Au1300 USB support
Thread-Topic: [PATCH 06/10] Alchemy: Au1300 USB support
Thread-Index: Acmed/a8mDWLYrOXST6sq5A4L3h95w==
Message-ID:
 <7e632686ab9b29a94eefeb2e5dca8b091a956b95.1236354153.git.khickey@rmicorp.com>
References:
 <788248524efc28ba2608ed79bfb7080ee476b12d.1236354153.git.khickey@rmicorp.com>
In-Reply-To:
 <788248524efc28ba2608ed79bfb7080ee476b12d.1236354153.git.khickey@rmicorp.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 0b
X-MS-Exchange-Organization-AuthSource: exch1.onstor.net
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-originalarrivaltime: 06 Mar 2009 16:20:09.0887 (UTC)
 FILETIME=[6B83DAF0:01C99E77]
errors-to: linux-mips-bounce@linux-mips.org
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
x-ems-stamp: SRefh8OpaD2MXYhMMTxxjw==
x-messageone-virus-version: vendor=fsecure
 engine=4.65.7400:2.4.4,1.2.40,4.0.164
 definitions=2009-02-22_03:2009-02-10,2009-02-22,2009-02-22 signatures=0
x-messageone-virus-scanned: Clean
x-messageone-envelope-sender: linux-mips-bounce@linux-mips.org
x-messageone-spam-details: rule=m773emszm_notspam policy=m773emszm score=0
 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam
 adjust=0 reason=mlx engine=3.1.0-0810130000 definitions=main-0902220252
x-messageone-spam-score: 0
x-messageone-spam-bar:
x-list: linux-mips
x-archive-position: 22022
x-ecartis-version: Ecartis v1.0.0
x-original-sender: khickey@rmicorp.com
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Adds support for USB 2.0 on the Au1300 SOC.

Signed-off-by: Kevin Hickey <khickey@rmicorp.com>
---
 drivers/usb/Kconfig            |    1 +
 drivers/usb/host/ehci-au13xx.c |  213 ++++++++++++++++++++++++++++++++++++=
++++
 drivers/usb/host/ehci-hcd.c    |    5 +
 3 files changed, 219 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-au13xx.c

diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 83babb0..a50d053 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -55,6 +55,7 @@ config USB_ARCH_HAS_EHCI
 	boolean
 	default y if PPC_83xx
 	default y if SOC_AU1200
+	default y if SOC_AU13XX
 	default y if ARCH_IXP4XX
 	default PCI

diff --git a/drivers/usb/host/ehci-au13xx.c b/drivers/usb/host/ehci-au13xx.=
c
new file mode 100644
index 0000000..fe03667
--- /dev/null
+++ b/drivers/usb/host/ehci-au13xx.c
@@ -0,0 +1,213 @@
+/*
+ * Copyright 2008 RMI Corporation
+ * Author: Kevin Hickey <khickey@rmicorp.com>
+ *
+ *  This program is free software; you can redistribute  it and/or modify =
it
+ *  under  the terms of  the GNU General  Public License as published by t=
he
+ *  Free Software Foundation;  either version 2 of the  License, or (at yo=
ur
+ *  option) any later version.
+ *
+ *  THIS  SOFTWARE  IS PROVIDED   ``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   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT=
,
+ *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, B=
UT
+ *  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 TO=
RT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE =
OF
+ *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  You should have received a copy of the  GNU General Public License alo=
ng
+ *  with this program; if not, write  to the Free Software Foundation, Inc=
.,
+ *  675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  Based on ehci-au1xxx.c.
+ */
+
+#include <linux/platform_device.h>
+#include <asm/mach-au1x00/au1000.h>
+
+
+extern int usb_disabled(void);
+
+static void au13xx_start_ehc(void)
+{
+	AU13XX_USB* au13xx_usb =3D (AU13XX_USB*)(KSEG1 | USB_BASE_PHYS_ADDR);
+	/*
+	 * Enable clocks.
+	 */
+	AU_SET_BITS_32(USB_DWC_CTRL3_EHC_CLKEN, &au13xx_usb->dwc_ctrl3);
+
+	/*
+	 * Take the host controller block out of reset
+	 */
+	AU_SET_BITS_32(USB_DWC_CTRL1_HSTRS, &au13xx_usb->dwc_ctrl1);
+
+	/*
+	 * Enable all of the PHYs
+	 */
+	AU_SET_BITS_32(USB_DWC_CTRL2_PHYRS | USB_DWC_CTRL2_PHY0RS | USB_DWC_CTRL2=
_PH1RS,
+		       &au13xx_usb->dwc_ctrl2);
+
+	/*
+	 * Enable interrupts
+	 */
+	AU_SET_BITS_32(USB_INTR_EHCI, &au13xx_usb->intr_enable);
+
+	/*
+	 * This bit enables coherent DMA.
+	 */
+	AU_SET_BITS_32(USB_SBUS_CTRL_SBCA, &au13xx_usb->sbus_ctrl);
+	asm("sync");
+}
+
+static void au13xx_stop_ehc(void)
+{
+	AU13XX_USB* au13xx_usb =3D (AU13XX_USB*)(KSEG1 | USB_BASE_PHYS_ADDR);
+	/*
+	 * Disable the EHCI interrupt
+	 */
+	AU_CLEAR_BITS_32(USB_INTR_EHCI, &au13xx_usb->intr_enable);
+
+	/*
+	 * Disable the clock to the EHCI block
+	 */
+	AU_CLEAR_BITS_32(USB_DWC_CTRL3_EHC_CLKEN, &au13xx_usb->dwc_ctrl3);
+
+	/*
+	 * Note: we're not disabling the PHY here because the OHCI and EHCI
+	 * drivers share a PHY and the OHCI driver may still be active.
+	 */
+}
+
+static const struct hc_driver ehci_au13xx_hc_driver =3D {
+	.description		=3D hcd_name,
+	.product_desc		=3D "Au13xx EHCI",
+	.hcd_priv_size		=3D sizeof(struct ehci_hcd),
+
+	/*
+	 * generic hardware linkage
+	 */
+	.irq			=3D ehci_irq,
+	.flags			=3D HCD_MEMORY | HCD_USB2,
+
+	/*
+	 * basic lifecycle operations
+	 */
+	.reset			=3D ehci_init,
+	.start			=3D ehci_run,
+	.stop			=3D ehci_stop,
+	.shutdown		=3D ehci_shutdown,
+
+	/*
+	 * managing i/o requests and associated device resources
+	 */
+	.urb_enqueue		=3D ehci_urb_enqueue,
+	.urb_dequeue		=3D ehci_urb_dequeue,
+	.endpoint_disable	=3D ehci_endpoint_disable,
+
+	/*
+	 * scheduling support
+	 */
+	.get_frame_number	=3D ehci_get_frame,
+
+	/*
+	 * root hub support
+	 */
+	.hub_status_data	=3D ehci_hub_status_data,
+	.hub_control		=3D ehci_hub_control,
+	.bus_suspend		=3D ehci_bus_suspend,
+	.bus_resume		=3D ehci_bus_resume,
+	.relinquish_port	=3D ehci_relinquish_port,
+	.port_handed_over	=3D ehci_port_handed_over,
+};
+
+static int ehci_hcd_au13xx_drv_probe(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd;
+	struct ehci_hcd *ehci;
+	int ret;
+
+	if (usb_disabled())
+		return -ENODEV;
+
+	if (pdev->resource[1].flags !=3D IORESOURCE_IRQ) {
+		pr_debug("resource[1] is not IORESOURCE_IRQ");
+		return -ENOMEM;
+	}
+	hcd =3D usb_create_hcd(&ehci_au13xx_hc_driver, &pdev->dev,
+			     dev_name(&pdev->dev));
+
+	if (!hcd)
+		return -ENOMEM;
+
+	hcd->rsrc_start =3D pdev->resource[0].start;
+	hcd->rsrc_len =3D pdev->resource[0].end - pdev->resource[0].start + 1;
+
+	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
+		pr_debug("request_mem_region failed");
+		ret =3D -EBUSY;
+		goto err1;
+	}
+
+	hcd->regs =3D ioremap(hcd->rsrc_start, hcd->rsrc_len);
+	if (!hcd->regs) {
+		pr_debug("ioremap failed");
+		ret =3D -ENOMEM;
+		goto err2;
+	}
+
+	au13xx_start_ehc();
+
+	ehci =3D hcd_to_ehci(hcd);
+	ehci->caps =3D hcd->regs;
+	ehci->regs =3D hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase));
+	printk("ehci->regs =3D %p\n", ehci->regs);
+
+	/* cache this readonly data; minimize chip reads */
+	ehci->hcs_params =3D readl(&ehci->caps->hcs_params);
+
+	ret =3D usb_add_hcd(hcd, pdev->resource[1].start,
+			  IRQF_DISABLED | IRQF_SHARED);
+	if (ret =3D=3D 0) {
+		platform_set_drvdata(pdev, hcd);
+		return ret;
+	}
+
+	au13xx_stop_ehc();
+	iounmap(hcd->regs);
+err2:
+	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+err1:
+	usb_put_hcd(hcd);
+	return ret;
+}
+
+static int ehci_hcd_au13xx_drv_remove(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd =3D platform_get_drvdata(pdev);
+
+	usb_remove_hcd(hcd);
+	iounmap(hcd->regs);
+	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+	usb_put_hcd(hcd);
+	au13xx_stop_ehc();
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static struct platform_driver ehci_hcd_au13xx_driver =3D {
+	.probe		=3D ehci_hcd_au13xx_drv_probe,
+	.remove		=3D ehci_hcd_au13xx_drv_remove,
+	.shutdown	=3D usb_hcd_platform_shutdown,
+	.suspend	=3D NULL,
+	.resume		=3D NULL,
+	.driver =3D {
+		.name	=3D "au13xx-ehci",
+		.owner	=3D THIS_MODULE,
+	}
+};
+
+MODULE_ALIAS("platform:au13xx-ehci");
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index e551bb3..1e4ca7e 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1016,6 +1016,11 @@ MODULE_LICENSE ("GPL");
 #define	PLATFORM_DRIVER		ehci_hcd_au1xxx_driver
 #endif

+#ifdef CONFIG_SOC_AU13XX
+#include "ehci-au13xx.c"
+#define	PLATFORM_DRIVER		ehci_hcd_au13xx_driver
+#endif
+
 #ifdef CONFIG_PPC_PS3
 #include "ehci-ps3.c"
 #define	PS3_SYSTEM_BUS_DRIVER	ps3_ehci_driver
--
1.5.4.3


