public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] some USB cleanup on EfikaMX
@ 2011-09-08 21:06 Jana Rapava
  2011-09-08 22:32 ` Wolfgang Denk
                   ` (2 more replies)
  0 siblings, 3 replies; 105+ messages in thread
From: Jana Rapava @ 2011-09-08 21:06 UTC (permalink / raw)
  To: u-boot

--- a/board/efikamx/efikamx-usb.c
+++ b/board/efikamx/efikamx-usb.c
@@ -154,6 +154,7 @@ void efika_usb_phy_reset(void)
        gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_D27), 1);
 }

+
 /*
  * Configure control registers of the USB controller
  */
@@ -161,56 +162,56 @@ void control_regs_setup(void)
 {
        uint32_t tmp;

-       tmp = readl(OTG_BASE_ADDR + 0x800);
-       tmp &= ~((1 << 27) | (1 << 24) | (1 << 12) | (1 << 11));
-       tmp |= 1 << 8;
-       writel(tmp, OTG_BASE_ADDR + 0x800);
+       tmp = readl(OTG_BASE_ADDR + MX51_USB_CTRL_OFFSET);
+       tmp &= ~(MX51_OTG_WUE_BIT | MX51_OTG_PM_BIT | MX51_H1_ULPI_IE_BIT |
MX51_H1_WUE_BIT);
+       tmp |= MX51_H1_PM_BIT;
+       writel(tmp, OTG_BASE_ADDR + MX51_USB_CTRL_OFFSET);

-       tmp = readl(OTG_BASE_ADDR + 0x808);
-       tmp &= ~(1 << 8);
-       tmp |= 1 << 5;
-       writel(tmp, OTG_BASE_ADDR + 0x808);
+       tmp = readl(OTG_BASE_ADDR + MX51_PHY_CTRL0_OFFSET);
+       tmp &= ~MX51_OTG_OVERCURD_BIT;
+       tmp |= MX51_EHCI_POWERPINSE_BIT;
+       writel(tmp, OTG_BASE_ADDR + MX51_PHY_CTRL0_OFFSET);

-       tmp = readl(OTG_BASE_ADDR + 0x80c);
-       tmp &= ~0x3;
-       tmp |= 0x1;
-       writel(tmp, OTG_BASE_ADDR + 0x80c);
+       tmp = readl(OTG_BASE_ADDR + MX51_PHY_CTRL1_OFFSET);
+       tmp &= ~0x3; /* make sure bits 0 and 1 are set to zero */
+       tmp |= MX51_SYSCLOCK_24_MHZ_BIT;
+       writel(tmp, OTG_BASE_ADDR + MX51_PHY_CTRL1_OFFSET);

-       tmp = readl(OTG_BASE_ADDR + 0x810);
-       tmp |= 1 << 25;
-       writel(tmp, OTG_BASE_ADDR + 0x810);
+       tmp = readl(OTG_BASE_ADDR + MX51_USB_CTRL1_OFFSET);
+       tmp |= MX51_H1_EXTCLKE_BIT;
+       writel(tmp, OTG_BASE_ADDR + MX51_USB_CTRL1_OFFSET);

-       tmp = readl(OTG_BASE_ADDR + 0x814);
-       tmp &= ~((1 << 8) | (1 << 7));
-       tmp |= 1 << 4;
-       writel(tmp, OTG_BASE_ADDR + 0x814);
+       tmp = readl(OTG_BASE_ADDR + MX51_UH2_CTRL_OFFSET);
+       tmp &= ~(MX51_H2_ULPI_IE_BIT | MX51_H2_WUE_BIT);
+       //Host 2 VBUS enable controlled by Host 2 controller
+       tmp |= MX51_H2_PM_BIT;
+       writel(tmp, OTG_BASE_ADDR + MX51_UH2_CTRL_OFFSET);

        udelay(10000);
 }

-#define        ULPI_VIEWPORT(base)     (base + 0x170)

 void ulpi_write(u32 base, u32 reg, u32 value)
 {
-       if (!(readl(ULPI_VIEWPORT(base)) & (1 << 27))) {
-               writel(1 << 31, ULPI_VIEWPORT(base));
-               while (readl(ULPI_VIEWPORT(base)) & (1 << 31));
+       if (!(readl(ULPI_VIEWPORT(base)) & MX51_ULPI_SS_BIT)) {
+               writel(MX51_ULPI_WU_BIT, ULPI_VIEWPORT(base));
+               while (readl(ULPI_VIEWPORT(base)) & MX51_ULPI_WU_BIT);
        }
-       writel((1 << 30) | (1 << 29) | (reg << 16) | (value & 0xff),
ULPI_VIEWPORT(base));
-       while (readl(ULPI_VIEWPORT(base)) & (1 << 30));
+       writel(MX51_ULPI_RWRUN | MX51_ULPI_RWCTRL | (reg << 16) | (value &
0xff), ULPI_VIEWPORT(base));
+       while (readl(ULPI_VIEWPORT(base)) & MX51_ULPI_RWRUN);
 }

 u32 ulpi_read(u32 base, u32 reg)
 {
        u32 tmp;
-       if (!(readl(ULPI_VIEWPORT(base)) & (1 << 27))) {
-               writel(1 << 31, ULPI_VIEWPORT(base));
-               while (readl(ULPI_VIEWPORT(base)) & (1 << 31));
+       if (!(readl(ULPI_VIEWPORT(base)) & MX51_ULPI_SS_BIT)) {
+               writel(MX51_ULPI_WU_BIT, ULPI_VIEWPORT(base));
+               while (readl(ULPI_VIEWPORT(base)) & MX51_ULPI_WU_BIT);
        }
-       writel((1 << 30) | (reg << 16), ULPI_VIEWPORT(base));
+       writel(MX51_ULPI_RWRUN | (reg << 16), ULPI_VIEWPORT(base));
        do {
                tmp = readl(ULPI_VIEWPORT(base));
-       } while (tmp & (1 << 30));
+       } while (tmp & MX51_ULPI_RWRUN);
        return (tmp >> 8) & 0xff;
 }

diff --git a/include/usb/ehci-fsl.h b/include/usb/ehci-fsl.h
index 67600ed..3af7928 100644
--- a/include/usb/ehci-fsl.h
+++ b/include/usb/ehci-fsl.h
@@ -169,9 +169,46 @@
 #define CONFIG_SYS_FSL_USB_ADDR CONFIG_SYS_MPC512x_USB_ADDR
 #endif

+/* Register offsets for MX51 */
+#define MX51_USB_CTRL_OFFSET   0x800
+#define MX51_PHY_CTRL0_OFFSET  0x808
+#define MX51_PHY_CTRL1_OFFSET  0x80c
+#define MX51_USB_CTRL1_OFFSET  0x810
+#define MX51_UH2_CTRL_OFFSET   0x814
+
+/* Some USB_CTRL register bits*/
+#define MX51_OTG_WUE_BIT       (1 << 27)
+#define MX51_OTG_PM_BIT                (1 << 24)
+#define MX51_H1_ULPI_IE_BIT    (1 << 12)
+#define MX51_H1_WUE_BIT                (1 << 11)
+#define MX51_H1_PM_BIT         (1 << 8)
+
+/* Some PHY_CTRL_0 register bits */
+#define MX51_OTG_OVERCURD_BIT  (1 << 8)
+#define MX51_EHCI_POWERPINSE_BIT       (1 << 5)
+
+/* Some PHY_CTRL_1 register bits */
+#define MX51_SYSCLOCK_24_MHZ_BIT       (1 << 0)
+
+/* Some USB_CTRL_1 register bits*/
+#define MX51_H1_EXTCLKE_BIT    (1 << 25)
+
+/* Some USB Host 2 CTRL register bits*/
+#define MX51_H2_ULPI_IE_BIT    (1 << 8)
+#define MX51_H2_WUE_BIT                (1 << 7)
+#define MX51_H2_PM_BIT         (1 << 4)
+
+#define        ULPI_VIEWPORT(base)     (base + 0x170)
+/* ULPI viewport control bits */
+#define MX51_ULPI_WU_BIT       (1 << 31)
+#define MX51_ULPI_SS_BIT       (1 << 27)
+#define MX51_ULPI_RWRUN                (1 << 30)
+#define MX51_ULPI_RWCTRL       (1 << 29)
+
 /*
  * USB Registers
  */
+
 struct usb_ehci {
        u32     id;             /* 0x000 - Identification register */
        u32     hwgeneral;      /* 0x004 - General hardware parameters */
@@ -241,5 +278,4 @@ struct usb_ehci {
        u32     control;        /* 0x500 - Control */
        u8      res13[0xafc];
 };
-
 #endif /* _EHCI_FSL_H */

^ permalink raw reply related	[flat|nested] 105+ messages in thread
* [U-Boot] [PATCH v4 4/4] usb: add USB support for Efika
@ 2011-09-29 10:30 Jana Rapava
  2011-09-29 11:09 ` [U-Boot] [PATCH v5 4/4] Add " Jana Rapava
  0 siblings, 1 reply; 105+ messages in thread
From: Jana Rapava @ 2011-09-29 10:30 UTC (permalink / raw)
  To: u-boot

This commit adds USB support for EfikaMX and EfikaSB.

Signed-off-by: Jana Rapava <fermata7@gmail.com>
Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Cc: Remy Bohmer <linux@bohmer.net>
Cc: Stefano Babic <sbabic@denx.de>
---
Changes for v2:
      - introduce temporary variable in ulpi_write
      - whitespace changes
Changes for v3:
       - add protection against multiple inclusion of efika.h
Changes for v4:
	- rename multiple inclusion protection macro in efika.h

 board/efikamx/Makefile      |    3 +
 board/efikamx/efika.h       |   33 ++++
 board/efikamx/efikamx-usb.c |  423 +++++++++++++++++++++++++++++++++++++++++++
 board/efikamx/efikamx.c     |    3 +
 include/configs/efikamx.h   |   16 ++
 5 files changed, 478 insertions(+), 0 deletions(-)
 create mode 100644 board/efikamx/efika.h
 create mode 100644 board/efikamx/efikamx-usb.c

diff --git a/board/efikamx/Makefile b/board/efikamx/Makefile
index ee4a16e..860e4d2 100644
--- a/board/efikamx/Makefile
+++ b/board/efikamx/Makefile
@@ -28,6 +28,9 @@ include $(TOPDIR)/config.mk
 LIB	= $(obj)lib$(BOARD).o
 
 COBJS	:= efikamx.o
+ifdef	CONFIG_CMD_USB
+COBJS	+= efikamx-usb.o
+endif
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS))
diff --git a/board/efikamx/efika.h b/board/efikamx/efika.h
new file mode 100644
index 0000000..f5a09e3
--- /dev/null
+++ b/board/efikamx/efika.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __BOARD_EFIKAMX_EFIKA_H__
+#define __BOARD_EFIKAMX_EFIKA_H__
+
+/*
+ * EHCI USB
+ */
+#ifdef	CONFIG_CMD_USB
+void setup_iomux_usb(void);
+#else
+static inline void setup_iomux_usb(void) { }
+#endif
diff --git a/board/efikamx/efikamx-usb.c b/board/efikamx/efikamx-usb.c
new file mode 100644
index 0000000..b169ea7
--- /dev/null
+++ b/board/efikamx/efikamx-usb.c
@@ -0,0 +1,423 @@
+/*
+ * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
+ * Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <usb.h>
+#include <asm/io.h>
+#include <asm/arch/imx-regs.h>
+#include <asm/arch/mx5x_pins.h>
+#include <asm/arch/iomux.h>
+#include <asm/gpio.h>
+#include <usb/ehci-fsl.h>
+#include <errno.h>
+#include <watchdog.h>
+
+#include <usb/ehci.h>
+#include <usb/ehci-core.h>
+
+/*
+ * Configure the USB H1 and USB H2 IOMUX.
+ */
+#define USB_PAD_CONFIG	(PAD_CTL_PKE_ENABLE | PAD_CTL_SRE_FAST | \
+			PAD_CTL_DRV_HIGH | PAD_CTL_100K_PU | \
+			PAD_CTL_HYS_ENABLE | PAD_CTL_PUE_PULL)
+void setup_iomux_usb(void)
+{
+	/*
+	 * Configure USBH1 pads
+	 */
+	mxc_request_iomux(MX51_PIN_USBH1_STP, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_STP, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_CLK, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_CLK, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DIR, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DIR, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_NXT, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_NXT, USB_PAD_CONFIG);
+
+	mxc_request_iomux(MX51_PIN_USBH1_DATA0, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA0, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DATA1, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA1, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DATA2, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA2, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DATA3, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA3, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DATA4, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA4, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DATA5, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA5, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DATA6, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA6, USB_PAD_CONFIG);
+	mxc_request_iomux(MX51_PIN_USBH1_DATA7, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_DATA7, USB_PAD_CONFIG);
+
+	/*
+	 * Configure USBH1 control pads
+	 */
+
+	/* USB PHY reset */
+	mxc_request_iomux(MX51_PIN_EIM_D27, IOMUX_CONFIG_ALT1);
+	mxc_iomux_set_pad(MX51_PIN_EIM_D27, PAD_CTL_PKE_ENABLE |
+			PAD_CTL_SRE_FAST | PAD_CTL_DRV_HIGH);
+
+	/* USB HUB reset */
+	mxc_request_iomux(MX51_PIN_GPIO1_5, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_GPIO1_5, PAD_CTL_PKE_ENABLE |
+			PAD_CTL_SRE_FAST | PAD_CTL_DRV_HIGH);
+
+
+	if (machine_is_efikasb()) {
+		/*
+		 * Configure USBH2 pads (used on EfikaSB)
+		 */
+		/* USBH2_DATA */
+		mxc_request_iomux(MX51_PIN_EIM_D16, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D16, USB_PAD_CONFIG);
+		mxc_request_iomux(MX51_PIN_EIM_D17, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D17, USB_PAD_CONFIG);
+		mxc_request_iomux(MX51_PIN_EIM_D18, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D18, USB_PAD_CONFIG);
+		mxc_request_iomux(MX51_PIN_EIM_D19, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D19, USB_PAD_CONFIG);
+		mxc_request_iomux(MX51_PIN_EIM_D20, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D20, USB_PAD_CONFIG);
+		mxc_request_iomux(MX51_PIN_EIM_D21, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D21, USB_PAD_CONFIG);
+		mxc_request_iomux(MX51_PIN_EIM_D22, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D22, USB_PAD_CONFIG);
+		mxc_request_iomux(MX51_PIN_EIM_D23, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_D23, USB_PAD_CONFIG);
+
+		/* USBH2_CLK */
+		mxc_request_iomux(MX51_PIN_EIM_A24, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_A24, USB_PAD_CONFIG);
+		/* USBH2_DIR */
+		mxc_request_iomux(MX51_PIN_EIM_A25, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_A25, USB_PAD_CONFIG);
+		/* USBH2_STP */
+		mxc_request_iomux(MX51_PIN_EIM_A26, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_A26, USB_PAD_CONFIG);
+		/* USBH2_NXT */
+		mxc_request_iomux(MX51_PIN_EIM_A27, IOMUX_CONFIG_ALT2);
+		mxc_iomux_set_pad(MX51_PIN_EIM_A27, USB_PAD_CONFIG);
+	}
+
+	/* WIFI EN (act low) */
+	mxc_request_iomux(MX51_PIN_EIM_A22, IOMUX_CONFIG_GPIO);
+	mxc_iomux_set_pad(MX51_PIN_EIM_A22, 0);
+	/* WIFI RESET */
+	mxc_request_iomux(MX51_PIN_EIM_A16, IOMUX_CONFIG_GPIO);
+	mxc_iomux_set_pad(MX51_PIN_EIM_A16, 0);
+	/* BT EN (act low) */
+	mxc_request_iomux(MX51_PIN_EIM_A17, IOMUX_CONFIG_GPIO);
+	mxc_iomux_set_pad(MX51_PIN_EIM_A17, 0);
+}
+
+/*
+ * Enable devices connected to USB buses.
+ */
+void efika_usb_enable_devices(void)
+{
+	/* Enable Bluetooth */
+	gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_A17), 0);
+	udelay(10000);
+	gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_A17), 1);
+
+	/* Enable WiFi */
+	gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_A22), 1);
+	udelay(10000);
+
+	/* Reset the WiFi chip */
+	gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_A16), 0);
+	udelay(10000);
+	gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_A16), 1);
+}
+
+/*
+ * Reset USB HUB (or HUBs on EfikaSB).
+ */
+void efika_usb_hub_reset(void)
+{
+	/* HUB reset */
+	gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_GPIO1_5), 1);
+	udelay(1000);
+	gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_GPIO1_5), 0);
+	udelay(1000);
+	gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_GPIO1_5), 1);
+}
+
+/*
+ * Reset USB PHY (or PHYs on EfikaSB).
+ */
+void efika_usb_phy_reset(void)
+{
+	/* SMSC 3317 PHY reset */
+	gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_D27), 0);
+	udelay(1000);
+	gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_D27), 1);
+}
+
+/*
+ * Configure control registers of the USB controller.
+ */
+void control_regs_setup(struct mx5_usb_control_regs *control)
+{
+	clrsetbits_le32(&control->usbctrl,
+		(MXC_OTG_WUE | MXC_OTG_PM | MX51_H1_ULPI_IE | MX51_H1_WUE),
+		MX51_H1_PM);
+
+	clrsetbits_le32(&control->phyctrl0,
+			MX51_OTG_OVERCURD,
+			MX51_EHCI_POWERPINSE);
+
+	clrsetbits_le32(&control->phyctrl1,
+			MX51_SYSCLOCK_MASK,
+			MX51_SYSCLOCK_24_MHZ);
+
+	setbits_le32(&control->usbctrl1, MX51_H1_EXTCLKE);
+
+	clrsetbits_le32(&control->uh2ctrl,
+			(MX51_H2_ULPI_IE | MX51_H2_WUE),
+			MX51_H2_PM);
+
+	udelay(10000);
+}
+
+#define ULPI_ADDR_SHIFT		16
+#define ulpi_write_mask(value)	((value) & 0xff)
+#define ulpi_read_mask(value)	(((value) >> 8) & 0xff)
+
+int ulpi_wait(struct usb_ehci *ehci, u32 ulpi_value, u32 ulpi_mask)
+{
+	int timeout = ULPI_TIMEOUT;
+	u32 tmp;
+
+	writel(ulpi_value, &ehci->ulpi_viewpoint);
+
+	/* Wait for the bits in ulpi_mask to become zero. */
+	while (--timeout) {
+		tmp = readl(&ehci->ulpi_viewpoint);
+		if (!(tmp & ulpi_mask))
+			break;
+		WATCHDOG_RESET();
+	}
+
+	return !timeout;
+}
+
+int ulpi_wakeup(struct usb_ehci *ehci)
+{
+	if (readl(&ehci->ulpi_viewpoint) & ULPI_SS)
+		return 0; /* already awake */
+	return ulpi_wait(ehci, ULPI_WU, ULPI_WU);
+}
+
+void ulpi_write(struct usb_ehci *ehci, u32 reg, u32 value)
+{
+	u32 tmp;
+	if (ulpi_wakeup(ehci)) {
+		printf("ULPI wakeup timed out\n");
+		return;
+	}
+
+	tmp = ulpi_wait(ehci, ULPI_RWRUN | ULPI_RWCTRL |
+		reg << ULPI_ADDR_SHIFT | ulpi_write_mask(value), ULPI_RWRUN);
+	if (tmp)
+		printf("ULPI write timed out\n");
+}
+
+u32 ulpi_read(struct usb_ehci *ehci, u32 reg)
+{
+	if (ulpi_wakeup(ehci)) {
+		printf("ULPI wakeup timed out\n");
+		return 0;
+	}
+
+	if (ulpi_wait(ehci, ULPI_RWRUN | reg << ULPI_ADDR_SHIFT, ULPI_RWRUN)) {
+		printf("ULPI read timed out\n");
+		return 0;
+	}
+
+	return ulpi_read_mask(readl(&ehci->ulpi_viewpoint));
+}
+
+void ulpi_init(struct usb_ehci *ehci, struct mxc_ulpi_regs *ulpi)
+{
+	u32 tmp = 0;
+	int reg, i;
+
+	/* Assemble ID from four ULPI ID registers (8 bits each). */
+	for (reg = ULPI_ID_REGS_COUNT - 1; reg >= 0; reg--)
+		tmp |= ulpi_read(ehci, reg) << (reg * 8);
+
+	/* Split ID into vendor and product ID. */
+	debug("Found ULPI TX, ID %04x:%04x\n", tmp >> 16, tmp & 0xffff);
+
+	/* ULPI integrity check */
+	for (i = 0; i < 2; i++) {
+		ulpi_write(ehci, (u32)&ulpi->scratch_write,
+			ULPI_TEST_VALUE << i);
+		tmp = ulpi_read(ehci, (u32)&ulpi->scratch_write);
+
+		if (tmp != (ULPI_TEST_VALUE << i)) {
+			printf("ULPI integrity check failed\n");
+			return;
+		}
+	}
+
+	/* Set ULPI flags. */
+	ulpi_write(ehci, (u32)&ulpi->otg_ctrl_write,
+		ULPI_OTG_EXT_VBUS_IND |
+		ULPI_OTG_DM_PULLDOWN | ULPI_OTG_DP_PULLDOWN);
+	ulpi_write(ehci, (u32)&ulpi->function_ctrl_write,
+		ULPI_FC_XCVR_SELECT | ULPI_FC_OPMODE_NORMAL |
+		ULPI_FC_SUSPENDM_PWRED);
+	ulpi_write(ehci, (u32)&ulpi->iface_ctrl_write, 0);
+	ulpi_write(ehci, (u32)&ulpi->otg_ctrl_set,
+		ULPI_OTG_DRV_VBUS | ULPI_OTG_DRV_VBUS_EXT);
+
+	/*
+	 * NOTE: This violates USB specification, but otherwise, USB on Efika
+	 * doesn't charge VBUS and as a result, USB doesn't work.
+	 */
+	ulpi_write(ehci, (u32)&ulpi->otg_ctrl_set, ULPI_OTG_CHRG_VBUS);
+}
+
+/*
+ * Solve the VBUS reset problem on Efika
+ * by setting the CHRG_VBUS bit in the reset.
+ */
+void ehci_fixup(uint32_t *status_reg, uint32_t *reg_ref)
+{
+	struct usb_ehci *ehci = (struct usb_ehci *)(OTG_BASE_ADDR +
+		MX51_REGISTER_LAYOUT_LENGTH);
+	struct mxc_ulpi_regs *ulpi = (struct mxc_ulpi_regs *)0;
+
+	u32 tmp = ulpi_read(ehci, (u32)&ulpi->otg_ctrl_write);
+	tmp |= ULPI_OTG_CHRG_VBUS;
+	ulpi_write(ehci, (u32)&ulpi->otg_ctrl_write, tmp);
+
+	/* USB 2.0 specification say 50 ms resets on root. */
+	wait_ms(50);
+
+	/* Now terminate the reset. */
+	*reg_ref = ehci_readl(status_reg);
+	*reg_ref |= EHCI_PS_PE;
+}
+
+void ehci0_init(struct usb_ehci *ehci)
+{
+	writel(MX51_16BIT_UTMI, &ehci->portsc);
+}
+
+void ehci1_init(struct usb_ehci *ehci, struct mxc_ulpi_regs *ulpi)
+{
+	mxc_request_iomux(MX51_PIN_USBH1_STP, IOMUX_CONFIG_ALT2);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_STP, PAD_CTL_DRV_HIGH |
+				PAD_CTL_PKE_ENABLE | PAD_CTL_SRE_FAST);
+	gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_USBH1_STP), 0);
+	udelay(1000);
+	gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_USBH1_STP), 1);
+	udelay(1000);
+
+	mxc_request_iomux(MX51_PIN_USBH1_STP, IOMUX_CONFIG_ALT0);
+	mxc_iomux_set_pad(MX51_PIN_USBH1_STP, USB_PAD_CONFIG);
+	udelay(10000);
+
+	clrbits_le32(&ehci->usbcmd, MX51_ITC_IMMEDIATE_MASK);
+	udelay(10000);
+
+	writel(MX51_ULPI_MODE_MASK, &ehci->portsc);
+	udelay(10000);
+
+	ulpi_init(ehci, ulpi);
+}
+
+void ehci2_init(struct usb_ehci *ehci, struct mxc_ulpi_regs *ulpi)
+{
+	mxc_request_iomux(MX51_PIN_EIM_A26, IOMUX_CONFIG_ALT1);
+	mxc_iomux_set_pad(MX51_PIN_EIM_A26, PAD_CTL_DRV_HIGH |
+				PAD_CTL_PKE_ENABLE | PAD_CTL_SRE_FAST);
+	gpio_direction_output(IOMUX_TO_GPIO(MX51_PIN_EIM_A26), 0);
+	udelay(1000);
+	gpio_set_value(IOMUX_TO_GPIO(MX51_PIN_EIM_A26), 1);
+	udelay(1000);
+
+	mxc_request_iomux(MX51_PIN_EIM_A26, IOMUX_CONFIG_ALT2);
+	mxc_iomux_set_pad(MX51_PIN_EIM_A26, USB_PAD_CONFIG);
+
+	writel(MX51_ULPI_MODE_MASK, &ehci->portsc);
+	udelay(10000);
+
+	ulpi_init(ehci, ulpi);
+}
+
+int ehci_hcd_init(void)
+{
+	struct usb_ehci *ehci;
+	struct mx5_usb_control_regs *mx5_usb_control_regs;
+	struct mxc_ulpi_regs *ulpi;
+
+	mx5_usb_control_regs = (struct mx5_usb_control_regs *)(OTG_BASE_ADDR +
+		 MX5_CTRL_REGS_OFFSET);
+	control_regs_setup(mx5_usb_control_regs);
+	ulpi = (struct mxc_ulpi_regs *)0;
+
+	/* Init EHCI core */
+	ehci = (struct usb_ehci *)(OTG_BASE_ADDR +
+		(MX51_REGISTER_LAYOUT_LENGTH * CONFIG_MXC_USB_PORT));
+	hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
+	hcor = (struct ehci_hcor *)((uint32_t) hccr +
+			HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
+	setbits_le32(&ehci->usbmode, CM_HOST);
+	setbits_le32(&ehci->control, USB_EN);
+
+	/* Init iMX51 EHCI */
+	efika_usb_phy_reset();
+	efika_usb_hub_reset();
+	efika_usb_enable_devices();
+
+	switch (CONFIG_MXC_USB_PORT) {
+	case 0:
+		ehci0_init(ehci);
+		break;
+	case 1:
+		ehci1_init(ehci, ulpi);
+		break;
+	case 2:
+		if (machine_is_efikasb())
+			ehci2_init(ehci, ulpi);
+		break;
+	};
+
+	/* EfikaMX USB has issues ... */
+	udelay(10000);
+
+	return 0;
+}
+
+int ehci_hcd_stop(void)
+{
+	return 0;
+}
diff --git a/board/efikamx/efikamx.c b/board/efikamx/efikamx.c
index 0c4e24b..8e9b42b 100644
--- a/board/efikamx/efikamx.c
+++ b/board/efikamx/efikamx.c
@@ -37,6 +37,8 @@
 #include <fsl_pmic.h>
 #include <mc13892.h>
 
+#include "efika.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /*
@@ -678,6 +680,7 @@ int board_late_init(void)
 
 	setup_iomux_led();
 	setup_iomux_ata();
+	setup_iomux_usb();
 
 	efikamx_toggle_led(EFIKAMX_LED_BLUE);
 
diff --git a/include/configs/efikamx.h b/include/configs/efikamx.h
index 54f48e4..010a16a 100644
--- a/include/configs/efikamx.h
+++ b/include/configs/efikamx.h
@@ -44,6 +44,10 @@
 
 #define CONFIG_SYS_TEXT_BASE		0x97800000
 
+#define	CONFIG_L2_OFF
+#define	CONFIG_SYS_ICACHE_OFF
+#define	CONFIG_SYS_DCACHE_OFF
+
 /*
  * Bootloader Components Configuration
  */
@@ -172,6 +176,18 @@
 #endif
 
 /*
+ * USB
+ */
+#define CONFIG_CMD_USB
+#ifdef CONFIG_CMD_USB
+#define CONFIG_USB_EHCI			/* Enable EHCI USB support */
+#define CONFIG_MXC_USB_PORT	1
+#define CONFIG_EHCI_IS_TDI
+#define CONFIG_USB_STORAGE
+#define CONFIG_USB_KEYBOARD
+#endif /* CONFIG_CMD_USB */
+
+/*
  * Filesystems
  */
 #ifdef CONFIG_CMD_FAT
-- 
1.7.6.3

^ permalink raw reply related	[flat|nested] 105+ messages in thread

end of thread, other threads:[~2011-10-14 16:07 UTC | newest]

Thread overview: 105+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-08 21:06 [U-Boot] some USB cleanup on EfikaMX Jana Rapava
2011-09-08 22:32 ` Wolfgang Denk
2011-09-09 10:18 ` Stefano Babic
2011-09-12 17:20 ` [U-Boot] [PATCH 1/2 v2] USB cleanup for EfikaMX Jana Rapava
2011-09-12 19:25   ` Marek Vasut
2011-09-18  2:19   ` [U-Boot] [PATCH v3] Add USB support for Efika Jana Rapava
2011-09-18  2:33     ` Marek Vasut
2011-09-19  8:43     ` Stefano Babic
2011-09-19 10:30       ` Marek Vasut
2011-09-24 15:57       ` Remy Bohmer
2011-09-24 19:07         ` Fabio Estevam
2011-09-24 19:19           ` Marek Vasut
2011-09-24 21:22             ` Fabio Estevam
2011-09-22  5:18     ` Marek Vasut
2011-09-25 11:55     ` [U-Boot] [PATCH v4 1/5] EHCI: add callback ehci_fixup Jana Rapava
2011-09-25 11:55       ` [U-Boot] [PATCH v4 2/5] Add USB support for Efika Jana Rapava
2011-09-25 11:55       ` [U-Boot] [PATCH v4 3/5] /drivers/usb/host/ehci-mxc.c: naming cleanup Jana Rapava
2011-09-25 11:55       ` [U-Boot] [PATCH v4 4/5] USB: Add usb_event_poll() to get keyboards working with EHCI Jana Rapava
2011-09-25 12:02         ` Marek Vasut
2011-09-25 11:55       ` [U-Boot] [PATCH v4 5/5] USB: move ehci.h and ehci-core.h into /include/usb/ Jana Rapava
2011-09-27 10:45         ` [U-Boot] [PATCH v5 1/4] usb: Move ehci.h and ehci-core.h to include/usb directory Jana Rapava
2011-09-27 10:57           ` Fabio Estevam
2011-09-27 11:01           ` [U-Boot] [PATCH v5 2/4] EHCI: add callback ehci_fixup Jana Rapava
2011-09-27 11:01             ` [U-Boot] [PATCH v5 3/4] EHCI: adjust for mx5 Jana Rapava
2011-09-27 11:01             ` [U-Boot] [PATCH v5 4/4] Add USB support for Efika Jana Rapava
2011-09-27 11:50               ` Marek Vasut
2011-09-27 14:12                 ` Jana Rapava
2011-09-27 14:55                   ` Marek Vasut
2011-09-27 18:17                 ` Jana Rapava
2011-09-27 18:20                   ` Marek Vasut
2011-09-28 10:26                   ` Stefano Babic
2011-09-28 12:12                     ` Jana Rapava
2011-09-27 11:23             ` [U-Boot] [PATCH v5 2/4] EHCI: add callback ehci_fixup Marek Vasut
2011-09-27 11:42               ` Jana Rapava
2011-09-27 19:24                 ` [U-Boot] [PATCH v6 " Jana Rapava
2011-09-27 19:24                   ` [U-Boot] [PATCH v6 3/4] EHCI: adjust for mx5 Jana Rapava
2011-09-27 19:41                     ` Marek Vasut
2011-09-27 20:19                       ` Jana Rapava
2011-09-27 20:47                         ` Marek Vasut
2011-09-27 19:24                   ` [U-Boot] [PATCH v6 4/4] Add USB support for Efika Jana Rapava
2011-09-27 19:47                     ` Marek Vasut
2011-09-27 20:40                       ` Jana Rapava
2011-09-27 20:50                         ` Marek Vasut
2011-09-27 19:40                   ` [U-Boot] [PATCH v6 2/4] EHCI: add callback ehci_fixup Marek Vasut
2011-09-27 22:21                   ` [U-Boot] [PATCH v7 " Jana Rapava
2011-09-27 22:21                     ` [U-Boot] [PATCH v7 3/4] EHCI: adjust for mx5 Jana Rapava
2011-09-27 22:21                     ` [U-Boot] [PATCH v7 4/4] Add USB support for Efika Jana Rapava
2011-09-28  0:43                       ` Marek Vasut
2011-09-28 12:25                         ` Jana Rapava
2011-09-28 12:28                           ` Marek Vasut
2011-09-28  0:46                     ` [U-Boot] [PATCH v7 2/4] EHCI: add callback ehci_fixup Marek Vasut
2011-09-28 10:54                     ` Marek Vasut
2011-09-28 11:52                       ` Jana Rapava
2011-09-28 12:13                         ` Marek Vasut
2011-09-28 15:02                     ` [U-Boot] [PATCH v8 " Jana Rapava
2011-09-28 15:05                       ` [U-Boot] [PATCH v8 3/4] EHCI: adjust for mx5 Jana Rapava
2011-09-28 15:07                         ` [U-Boot] [PATCH v8 4/4] Add USB support for Efika Jana Rapava
2011-09-28 15:20                           ` Marek Vasut
2011-09-28 18:12                             ` Jana Rapava
2011-09-28 18:26                               ` Marek Vasut
2011-10-06 21:18                           ` Wolfgang Denk
2011-10-07 17:16                             ` Jana Rapava
2011-09-28 15:21                       ` [U-Boot] [PATCH v8 2/4] EHCI: add callback ehci_fixup Marek Vasut
2011-09-27 11:07           ` [U-Boot] [PATCH v5 1/4] usb: Move ehci.h and ehci-core.h to include/usb directory Fabio Estevam
2011-09-27 11:09             ` Fabio Estevam
2011-09-27 11:27               ` Jana Rapava
2011-09-27 18:44           ` [U-Boot] [PATCH v6 " Jana Rapava
2011-09-27 22:06             ` [U-Boot] [PATCH v7 " Jana Rapava
2011-09-28 14:59               ` [U-Boot] [PATCH v8 " Jana Rapava
2011-09-28 19:49                 ` [U-Boot] [PATCH v9 " Jana Rapava
2011-09-28 20:36                   ` Marek Vasut
2011-09-28 21:10                     ` Jana Rapava
2011-09-28 21:43                       ` Marek Vasut
2011-09-28 23:04                         ` Jana Rapava
2011-09-28 23:05                           ` Marek Vasut
2011-09-28 23:22                             ` Jana Rapava
2011-09-28 19:51                 ` [U-Boot] [PATCH v9 2/4] EHCI: add callback ehci_fixup Jana Rapava
2011-09-28 19:52                   ` [U-Boot] [PATCH v9 3/4] EHCI: adjust for mx5 Jana Rapava
2011-09-28 19:54                     ` [U-Boot] [PATCH v9 4/4] Add USB support for Efika Jana Rapava
2011-09-28 20:44                       ` Marek Vasut
2011-09-28 20:36                   ` [U-Boot] [PATCH v9 2/4] EHCI: add callback ehci_fixup Marek Vasut
2011-09-28 21:14                     ` Jana Rapava
2011-09-28 21:26                       ` Marek Vasut
2011-09-25 12:02       ` [U-Boot] [PATCH v4 1/5] " Marek Vasut
2011-09-25 17:25     ` [U-Boot] [PATCH v4 1/4] USB: move ehci.h and ehci-core.h into /include/usb/ Jana Rapava
2011-09-25 17:25       ` [U-Boot] [PATCH v4 2/4] EHCI: add callback ehci_fixup Jana Rapava
2011-09-25 17:41         ` Marek Vasut
2011-09-25 17:25       ` [U-Boot] [PATCH v4 3/4] EHCI: adjust for mx5 Jana Rapava
2011-09-25 17:38         ` Marek Vasut
2011-09-25 17:25       ` [U-Boot] [PATCH v4 4/4] Add USB support for Efika Jana Rapava
2011-09-25 17:34         ` Marek Vasut
2011-09-26 20:28           ` Jana Rapava
2011-09-26 20:42             ` Marek Vasut
2011-09-26 20:51             ` Marek Vasut
2011-09-27 11:00               ` Jana Rapava
2011-09-25 19:01       ` [U-Boot] [PATCH v4 1/4] USB: move ehci.h and ehci-core.h into /include/usb/ Fabio Estevam
2011-09-26  8:32         ` Jana Rapava
2011-10-09 18:42       ` Marek Vasut
2011-10-09 20:22         ` Jana Rapava
2011-10-14 15:49           ` Fabio Estevam
2011-10-14 16:07             ` Marek Vasut
2011-10-14 15:50           ` Marek Vasut
2011-10-06 21:33   ` [U-Boot] [PATCH 1/2 v2] USB cleanup for EfikaMX Wolfgang Denk
  -- strict thread matches above, loose matches on Subject: below --
2011-09-29 10:30 [U-Boot] [PATCH v4 4/4] usb: add USB support for Efika Jana Rapava
2011-09-29 11:09 ` [U-Boot] [PATCH v5 4/4] Add " Jana Rapava
2011-09-29 14:37   ` Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox