mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: [PATCH 2/3] ARM i.MX6: enable usbphy1
Date: Thu, 30 Aug 2012 14:30:49 +0200	[thread overview]
Message-ID: <1346329850-3866-3-git-send-email-s.trumtrar@pengutronix.de> (raw)
In-Reply-To: <1346329850-3866-1-git-send-email-s.trumtrar@pengutronix.de>

Add a function to take the usbphy1 through its initialization procedure.
The imx6_usb_phy1_disable_oc function is needed at least on the sabrelite,
as the power design is faulty. The state on other imx6 boards is unknown,
therefore it is an extra function call at the moment.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 arch/arm/mach-imx/Makefile   |    2 +-
 arch/arm/mach-imx/usb-imx6.c |  111 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-imx/usb-imx6.c

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 2ff537a..7b872f6 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -8,7 +8,7 @@ obj-$(CONFIG_ARCH_IMX31) += speed-imx31.o imx31.o iomux-v2.o
 obj-$(CONFIG_ARCH_IMX35) += speed-imx35.o imx35.o iomux-v3.o
 obj-$(CONFIG_ARCH_IMX51) += speed-imx51.o imx51.o iomux-v3.o imx5.o
 obj-$(CONFIG_ARCH_IMX53) += speed-imx53.o imx53.o iomux-v3.o imx5.o
-obj-$(CONFIG_ARCH_IMX6) += speed-imx6.o imx6.o iomux-v3.o
+obj-$(CONFIG_ARCH_IMX6) += speed-imx6.o imx6.o iomux-v3.o usb-imx6.o
 obj-$(CONFIG_IMX_CLKO)	+= clko.o
 obj-$(CONFIG_IMX_IIM)	+= iim.o
 obj-$(CONFIG_NAND_IMX) += nand.o
diff --git a/arch/arm/mach-imx/usb-imx6.c b/arch/arm/mach-imx/usb-imx6.c
new file mode 100644
index 0000000..cd234d2
--- /dev/null
+++ b/arch/arm/mach-imx/usb-imx6.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2012 Steffen Trumtrar, Pengutronix
+ *
+ * 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.
+ *
+ */
+
+#include <common.h>
+#include <io.h>
+#include <mach/imx6-regs.h>
+
+#define SET				0x4
+#define CLR				0x8
+
+#define USBPHY_CTRL			0x30
+#define USB_OTG_CTRL			0x800
+#define USB_UH1_CTRL			0x804
+#define USB_UH2_CTRL			0x808
+#define USB_UH3_CTRL			0x80c
+
+#define USB_UH1_USBCMD			0x340
+
+#define USB_CMD_RUNSTOP			(1 <<  0)
+#define USB_CMD_RESET			(1 <<  1)
+
+#define USB_OVER_CUR_DIS		(1 <<  7)
+#define USBPHY_CTRL_SFTRST		(1 << 31)
+#define USBPHY_CTRL_CLKGATE		(1 << 30)
+#define USBPHY_CTRL_ENUTMILEVEL3	(1 << 15)
+#define USBPHY_CTRL_ENUTMILEVEL2	(1 << 14)
+
+#define USBPHY1_PLL_480_CTRL_EN		(1 << 13)
+#define USBPHY1_PLL_480_CTRL_POWER	(1 << 12)
+#define USBPHY1_PLL_480_CTRL_EN_USB_CLK	(1 <<  6)
+#define USBPHY1_PLL_480_CTRL_BYPASS	(1 << 16)
+
+int imx6_usb_phy1_disable_oc(void)
+{
+	int val;
+
+	/* disable over current detection */
+	val = readl(MX6_USBOH3_USB_BASE_ADDR + USB_UH1_CTRL);
+	val |= USB_OVER_CUR_DIS;
+	writel(val, MX6_USBOH3_USB_BASE_ADDR + USB_UH1_CTRL);
+	val = readl(MX6_USBOH3_USB_BASE_ADDR + USB_UH2_CTRL);
+	val |= USB_OVER_CUR_DIS;
+	writel(val, MX6_USBOH3_USB_BASE_ADDR + USB_UH2_CTRL);
+	val = readl(MX6_USBOH3_USB_BASE_ADDR + USB_UH3_CTRL);
+	val |= USB_OVER_CUR_DIS;
+	writel(val, MX6_USBOH3_USB_BASE_ADDR + USB_UH3_CTRL);
+
+	return 0;
+}
+
+int imx6_usb_phy1_enable(void)
+{
+	int val;
+
+	/* disable external charger detector or DP will be poor */
+	writel(0x00180000, MX6_ANATOP_BASE_ADDR + 0x1b0);
+	writel(0x00180000, MX6_ANATOP_BASE_ADDR + 0x210);
+
+	/* enable usb pll */
+	writel(USBPHY1_PLL_480_CTRL_EN |
+	       USBPHY1_PLL_480_CTRL_POWER |
+	       USBPHY1_PLL_480_CTRL_EN_USB_CLK, MX6_ANATOP_BASE_ADDR + 0x24);
+
+	/* turn OFF clk bypass */
+	/* at least on imx6 v1.0 this essential for usb to work */
+	/* FIXME: test on v1.1. Datasheet declares bit as reserved */
+	writel(USBPHY1_PLL_480_CTRL_BYPASS, MX6_ANATOP_BASE_ADDR + 0x28);
+
+	/* stop then reset */
+	val = readl(MX6_USBOH3_USB_BASE_ADDR + USB_UH1_USBCMD);
+	val &= ~USB_CMD_RUNSTOP;
+	writel(val, MX6_USBOH3_USB_BASE_ADDR + USB_UH1_USBCMD);
+	while (readl(MX6_USBOH3_USB_BASE_ADDR + USB_UH1_USBCMD) & USB_CMD_RUNSTOP);
+
+	val = readl(MX6_USBOH3_USB_BASE_ADDR + USB_UH1_USBCMD);
+	val |= USB_CMD_RESET;
+	writel(val, MX6_USBOH3_USB_BASE_ADDR + USB_UH1_USBCMD);
+	while (readl(MX6_USBOH3_USB_BASE_ADDR + USB_UH1_USBCMD) & USB_CMD_RESET);
+
+	/* reset usbphy */
+	writel(USBPHY_CTRL_SFTRST, MX6_USBPHY1_BASE_ADDR + USBPHY_CTRL + SET);
+	udelay(10);
+	/* clr reset and clkgate */
+	writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE, MX6_USBPHY1_BASE_ADDR + USBPHY_CTRL + CLR);
+
+	/* clr all pwd bits => power up phy */
+	writel(0xffffffff, MX6_USBPHY1_BASE_ADDR + CLR);
+
+	/* set utmilvl2/3 */
+	val = readl(MX6_USBPHY1_BASE_ADDR + USBPHY_CTRL);
+	val |= USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2;
+	writel(val, MX6_USBPHY1_BASE_ADDR + USBPHY_CTRL + SET);
+
+	return 0;
+}
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-08-30 12:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-30 12:30 [PATCH 0/3] ARM i.MX6: basic USB H1 support Steffen Trumtrar
2012-08-30 12:30 ` [PATCH 1/3] ARM i.MX6: add the usbphy1 base addr Steffen Trumtrar
2012-08-30 12:30 ` Steffen Trumtrar [this message]
2012-08-30 12:30 ` [PATCH 3/3] usb: use ep-specific pwrgood delay Steffen Trumtrar
2012-08-30 13:03   ` Eric Bénard
2012-08-30 13:26     ` Steffen Trumtrar
2012-08-30 13:59       ` Eric Bénard
2012-08-30 14:12         ` Steffen Trumtrar
2012-08-30 14:18           ` Eric Bénard
2012-08-31  7:33 ` [PATCH 0/3] ARM i.MX6: basic USB H1 support Sascha Hauer
2012-08-31  7:43   ` Eric Bénard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1346329850-3866-3-git-send-email-s.trumtrar@pengutronix.de \
    --to=s.trumtrar@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox