All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
@ 2012-04-17 10:15 Marek Vasut
  2012-04-17 10:15 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
                   ` (10 more replies)
  0 siblings, 11 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
generic USB PHY infrastructure.

Marek Vasut (8):
  MXS: Make clk_disable return integer
  MXS: Add USB EHCI and USB PHY clock handling
  MXS: Fixup i.MX233 USB base address name
  MXS: Add platform registration hooks for USB EHCI
  MXS: Add USB PHY driver
  MXS: Add separate MXS EHCI HCD driver
  MXS: Enable USB on M28EVK
  MXS: Enable USB on MX28EVK

 arch/arm/mach-mxs/Kconfig                       |    4 +
 arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
 arch/arm/mach-mxs/devices-mx28.h                |    4 +
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   79 ++++++
 arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
 arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
 arch/arm/mach-mxs/mach-m28evk.c                 |   10 +
 arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
 drivers/usb/host/Kconfig                        |    7 +
 drivers/usb/host/ehci-hcd.c                     |    5 +
 drivers/usb/host/ehci-mxs.c                     |  309 +++++++++++++++++++++++
 drivers/usb/otg/Kconfig                         |    9 +
 drivers/usb/otg/Makefile                        |    1 +
 drivers/usb/otg/mxs-phy.c                       |  256 +++++++++++++++++++
 17 files changed, 736 insertions(+), 9 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
 create mode 100644 drivers/usb/host/ehci-mxs.c
 create mode 100644 drivers/usb/otg/mxs-phy.c

Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>

-- 
1.7.9.5

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

* [PATCH 1/8] MXS: Make clk_disable return integer
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 10:15 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

This allows subsequent USB clock patch to interchange enable() and disable()
calls without adding unnecessary switching cruft.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c         |    7 +++++--
 arch/arm/mach-mxs/include/mach/clock.h |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index cea29c9..43116ba 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -86,7 +86,7 @@ static int _raw_clk_enable(struct clk *clk)
 	return 0;
 }
 
-static void _raw_clk_disable(struct clk *clk)
+static int _raw_clk_disable(struct clk *clk)
 {
 	u32 reg;
 
@@ -95,6 +95,8 @@ static void _raw_clk_disable(struct clk *clk)
 		reg |= 1 << clk->enable_shift;
 		__raw_writel(reg, clk->enable_reg);
 	}
+
+	return 0;
 }
 
 /*
@@ -149,7 +151,7 @@ _CLK_ENABLE_PLL(pll1_clk, PLL1, EN_USB_CLKS)
 _CLK_ENABLE_PLL(pll2_clk, PLL2, CLKGATE)
 
 #define _CLK_DISABLE_PLL(name, r, g)					\
-static void name##_disable(struct clk *clk)				\
+static int name##_disable(struct clk *clk)				\
 {									\
 	__raw_writel(BM_CLKCTRL_##r##CTRL0_POWER,			\
 		     CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
@@ -161,6 +163,7 @@ static void name##_disable(struct clk *clk)				\
 		__raw_writel(BM_CLKCTRL_##r##CTRL0_##g,			\
 			CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
 									\
+	return 0;							\
 }
 
 _CLK_DISABLE_PLL(pll0_clk, PLL0, EN_USB_CLKS)
diff --git a/arch/arm/mach-mxs/include/mach/clock.h b/arch/arm/mach-mxs/include/mach/clock.h
index 592c9ab..21d1fad 100644
--- a/arch/arm/mach-mxs/include/mach/clock.h
+++ b/arch/arm/mach-mxs/include/mach/clock.h
@@ -50,7 +50,7 @@ struct clk {
 	int (*enable) (struct clk *);
 	/* Function ptr to disable the clock. Leave blank if clock can not
 	   be gated. */
-	void (*disable) (struct clk *);
+	int (*disable) (struct clk *);
 	/* Function ptr to set the parent clock of the clock. */
 	int (*set_parent) (struct clk *, struct clk *);
 };
-- 
1.7.9.5

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

* [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
  2012-04-17 10:15 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 18:01   ` Sascha Hauer
  2012-04-17 10:15 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index 43116ba..ae4f7b3 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -577,6 +577,21 @@ static struct clk usb1_clk = {
 	.parent = &pll1_clk,
 };
 
+static struct clk usb_phy_clk0 = {
+	.parent = &pll0_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL0CTRL0,
+	.enable_shift = 18,
+};
+
+static struct clk usb_phy_clk1 = {
+	.parent = &pll1_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL1CTRL0,
+	.enable_shift = 18,
+};
 #define _DEFINE_CLOCK(name, er, es, p)					\
 	static struct clk name = {					\
 		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
@@ -636,8 +651,10 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-mmc.3", NULL, ssp3_clk)
 	_REGISTER_CLOCK("flexcan.0", NULL, can0_clk)
 	_REGISTER_CLOCK("flexcan.1", NULL, can1_clk)
-	_REGISTER_CLOCK(NULL, "usb0", usb0_clk)
-	_REGISTER_CLOCK(NULL, "usb1", usb1_clk)
+	_REGISTER_CLOCK("mxs-ehci.0", "usb", usb0_clk)
+	_REGISTER_CLOCK("mxs-ehci.1", "usb", usb1_clk)
+	_REGISTER_CLOCK("mxs-phy.0", "usb0_phy", usb_phy_clk0)
+	_REGISTER_CLOCK("mxs-phy.1", "usb1_phy", usb_phy_clk1)
 	_REGISTER_CLOCK("mxs-pwm.0", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.1", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.2", NULL, pwm_clk)
-- 
1.7.9.5

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

* [PATCH 3/8] MXS: Fixup i.MX233 USB base address name
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
  2012-04-17 10:15 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
  2012-04-17 10:15 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 10:15 ` [PATCH 4/8] MXS: Add platform registration hooks for USB EHCI Marek Vasut
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

Modify USB EHCI and USB PHY base addresses on the i.MX233 to nicely fit into the
whole USB registration scheme.

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-mxs/include/mach/mx23.h b/arch/arm/mach-mxs/include/mach/mx23.h
index 599094b..7955b75 100644
--- a/arch/arm/mach-mxs/include/mach/mx23.h
+++ b/arch/arm/mach-mxs/include/mach/mx23.h
@@ -64,8 +64,8 @@
 #define MX23_AUART1_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06c000)
 #define MX23_AUART2_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06e000)
 #define MX23_DUART_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x070000)
-#define MX23_USBPHY_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
-#define MX23_USBCTRL_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
+#define MX23_USBPHY0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
+#define MX23_USBCTRL0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
 #define MX23_DRAM_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x0e0000)
 
 #define MX23_IO_P2V(x)			MXS_IO_P2V(x)
@@ -89,8 +89,8 @@
 #define MX23_INT_SPDIF_ERROR		10
 #define MX23_INT_SAIF1_IRQ		10
 #define MX23_INT_SAIF2_IRQ		10
-#define MX23_INT_USB_CTRL		11
-#define MX23_INT_USB_WAKEUP		12
+#define MX23_INT_USB0			11
+#define MX23_INT_USB0_WAKEUP		12
 #define MX23_INT_GPMI_DMA		13
 #define MX23_INT_SSP1_DMA		14
 #define MX23_INT_SSP1_ERROR		15
-- 
1.7.9.5

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

* [PATCH 4/8] MXS: Add platform registration hooks for USB EHCI
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (2 preceding siblings ...)
  2012-04-17 10:15 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 10:15 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/devices-mx28.h                |    4 ++
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   79 +++++++++++++++++++++++
 arch/arm/mach-mxs/include/mach/devices-common.h |    9 +++
 5 files changed, 96 insertions(+)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c

diff --git a/arch/arm/mach-mxs/devices-mx28.h b/arch/arm/mach-mxs/devices-mx28.h
index 5f71bb2..428b184 100644
--- a/arch/arm/mach-mxs/devices-mx28.h
+++ b/arch/arm/mach-mxs/devices-mx28.h
@@ -47,6 +47,10 @@ extern const struct mxs_mxs_mmc_data mx28_mxs_mmc_data[] __initconst;
 
 #define mx28_add_mxs_pwm(id)		mxs_add_mxs_pwm(MX28_PWM_BASE_ADDR, id)
 
+extern const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst;
+#define mx28_add_mxs_usbh(id) \
+	mxs_add_mxs_usbh(&mx28_mxs_usbh_data[id])
+
 struct platform_device *__init mx28_add_mxsfb(
 		const struct mxsfb_platform_data *pdata);
 
diff --git a/arch/arm/mach-mxs/devices/Kconfig b/arch/arm/mach-mxs/devices/Kconfig
index abad78d..a297d12 100644
--- a/arch/arm/mach-mxs/devices/Kconfig
+++ b/arch/arm/mach-mxs/devices/Kconfig
@@ -35,3 +35,6 @@ config MXS_HAVE_PLATFORM_MXS_SAIF
 
 config MXS_HAVE_PLATFORM_RTC_STMP3XXX
 	bool
+
+config MXS_HAVE_PLATFORM_USB
+	bool
diff --git a/arch/arm/mach-mxs/devices/Makefile b/arch/arm/mach-mxs/devices/Makefile
index 3e6fb12..2dbdf99 100644
--- a/arch/arm/mach-mxs/devices/Makefile
+++ b/arch/arm/mach-mxs/devices/Makefile
@@ -12,3 +12,4 @@ obj-y += platform-gpio-mxs.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXSFB) += platform-mxsfb.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXS_SAIF) += platform-mxs-saif.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_RTC_STMP3XXX) += platform-rtc-stmp3xxx.o
+obj-$(CONFIG_MXS_HAVE_PLATFORM_USB) += platform-usb.o
diff --git a/arch/arm/mach-mxs/devices/platform-usb.c b/arch/arm/mach-mxs/devices/platform-usb.c
new file mode 100644
index 0000000..0e2bdb6
--- /dev/null
+++ b/arch/arm/mach-mxs/devices/platform-usb.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+#include <linux/compiler.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/mx23.h>
+#include <mach/mx28.h>
+#include <mach/devices-common.h>
+
+#define mxs_usbh_data_entry_single(soc, _id, hwid)			\
+	{								\
+		.id = _id,						\
+		.usb_irq = soc ## _INT_USB ## hwid,			\
+		.usb_iobase = soc ## _USBCTRL ## hwid ## _BASE_ADDR,	\
+		.phy_iobase = soc ## _USBPHY ## hwid ## _BASE_ADDR,	\
+	}
+
+#define mxs_usbh_data_entry(soc, _id, hwid)				\
+	[_id] = mxs_usbh_data_entry_single(soc, _id, hwid)
+
+#ifdef CONFIG_SOC_IMX23
+const struct mxs_usbh_data mx23_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX23, 0, 0),
+};
+#endif
+
+#ifdef CONFIG_SOC_IMX28
+const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX28, 0, 0),
+	mxs_usbh_data_entry(MX28, 1, 1),
+};
+#endif
+
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data)
+{
+	struct platform_device *pdev;
+	struct resource usb_res[] = {
+		{
+			.start	= data->usb_iobase,
+			.end	= data->usb_iobase + SZ_64K - 1,
+			.flags	= IORESOURCE_MEM,
+		}, {
+			.start	= data->usb_irq,
+			.end	= data->usb_irq,
+			.flags	= IORESOURCE_IRQ,
+		},
+	};
+
+	struct resource phy_res[] = {
+		{
+			.start	= data->phy_iobase,
+			.end	= data->phy_iobase + SZ_256 - 1,
+			.flags	= IORESOURCE_MEM,
+		},
+	};
+
+	pdev = mxs_add_platform_device_dmamask("mxs-ehci", data->id,
+					usb_res, ARRAY_SIZE(usb_res),
+					NULL, 0,
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register EHCI USB controller!\n");
+
+	pdev = mxs_add_platform_device_dmamask("mxs-phy", data->id,
+					phy_res, ARRAY_SIZE(phy_res),
+					NULL, 0,
+					DMA_BIT_MASK(32));
+
+	if (!pdev)
+		pr_err("Failed to register EHCI USB PHY!\n");
+}
diff --git a/arch/arm/mach-mxs/include/mach/devices-common.h b/arch/arm/mach-mxs/include/mach/devices-common.h
index 3bffcd5..8fdd936 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
+++ b/arch/arm/mach-mxs/include/mach/devices-common.h
@@ -42,6 +42,15 @@ struct mxs_auart_data {
 struct platform_device *__init mxs_add_auart(
 		const struct mxs_auart_data *data);
 
+/* usb host */
+struct mxs_usbh_data {
+	int id;
+	resource_size_t usb_irq;
+	resource_size_t usb_iobase;
+	resource_size_t phy_iobase;
+};
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data);
+
 /* fec */
 #include <linux/fec.h>
 struct mxs_fec_data {
-- 
1.7.9.5

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (3 preceding siblings ...)
  2012-04-17 10:15 ` [PATCH 4/8] MXS: Add platform registration hooks for USB EHCI Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 17:51   ` Sascha Hauer
  2012-04-19 11:40   ` Arnd Bergmann
  2012-04-17 10:15 ` [PATCH 6/8] MXS: Add separate MXS EHCI HCD driver Marek Vasut
                   ` (5 subsequent siblings)
  10 siblings, 2 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
enables the PHY upon powerup and shuts it down on shutdown.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |    9 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  256 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 5c87db0..8689081 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -116,6 +116,15 @@ config FSL_USB2_OTG
 	help
 	  Enable this to support Freescale USB OTG transceiver.
 
+config USB_MXS_PHY
+	tristate "Freescale i.MX28 USB PHY support"
+	select USB_OTG_UTILS
+	help
+	  Say Y here if you want to build Freescale i.MX28 USB PHY
+	  driver in kernel.
+
+	  To compile this driver as a module, choose M here.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 41aa509..a844b8d 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
 obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
+obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
new file mode 100644
index 0000000..9963aa8
--- /dev/null
+++ b/drivers/usb/otg/mxs-phy.c
@@ -0,0 +1,256 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb/otg.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#define HW_USBPHY_PWD				0x00
+
+#define HW_USBPHY_CTRL				0x30
+#define HW_USBPHY_CTRL_SET			0x34
+#define HW_USBPHY_CTRL_CLR			0x38
+#define HW_USBPHY_CTRL_TOG			0x3c
+
+#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
+#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
+#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
+#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
+#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
+
+struct mxs_phy {
+	struct usb_phy	phy;
+	struct device	*dev;
+	struct clk	*clk;
+	struct resource	*res;
+	void __iomem	*reg;
+};
+
+static int phy_init(struct usb_phy *x)
+{
+	struct mxs_phy *phy = container_of(x, struct mxs_phy, phy);
+	uint32_t val;
+
+	/* Enable clock to the PHY. */
+	clk_enable(phy->clk);
+
+	/* Reset the PHY block. */
+	mxs_reset_block(phy->reg + HW_USBPHY_CTRL);
+
+	/* Power up the PHY. */
+	writel(0, phy->reg + HW_USBPHY_PWD);
+
+	/* Enable FS/LS compatibility and HS disconnection detector. */
+	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
+		BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
+	writel(val, phy->reg + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static void phy_shutdown(struct usb_phy *x)
+{
+	struct mxs_phy *phy = container_of(x, struct mxs_phy, phy);
+
+	/* Gate off the PHY. */
+	writel(BM_USBPHY_CTRL_CLKGATE, phy->reg + HW_USBPHY_CTRL_SET);
+
+	/* Disable clock to the PHY. */
+	clk_disable(phy->clk);
+}
+
+static int phy_set_vbus(struct usb_otg *otg, bool enabled)
+{
+	struct usb_phy *x = otg->phy;
+	struct mxs_phy *phy = container_of(x, struct mxs_phy, phy);
+
+	if (enabled)
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			phy->reg + HW_USBPHY_CTRL_CLR);
+	else
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			phy->reg + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static int __devinit mxs_phy_probe(struct platform_device *pdev)
+{
+	struct mxs_phy *phy;
+	struct resource *res;
+	int ret;
+
+	/* Allocate PHY driver's private date. */
+	phy = kzalloc(sizeof *phy, GFP_KERNEL);
+	if (!phy) {
+		ret = -ENOMEM;
+		goto err_alloc_phy;
+	}
+
+	/* Allocate OTG structure. */
+	phy->phy.otg = kzalloc(sizeof *phy->phy.otg, GFP_KERNEL);
+	if (!phy->phy.otg) {
+		ret = -ENOMEM;
+		goto err_alloc_otg;
+	}
+
+	/* Claim the PHY clock. */
+	phy->clk = clk_get(&pdev->dev, "usb_phy");
+	if (!phy->clk) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB PHY\n");
+		ret = -EINVAL;
+		goto err_claim_clock;
+	}
+
+	/* Get memory area where this controller resides from resources. */
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "Specify memory area for this controller!\n");
+		ret = -ENODEV;
+		goto err_get_resource;
+	}
+
+	/* Request the memory region for this driver. */
+	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
+		dev_dbg(&pdev->dev, "PHY memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_get_resource;
+	}
+
+	/* Map the memory region. */
+	phy->reg = ioremap(res->start, resource_size(res));
+	if (!phy->reg) {
+		dev_err(&pdev->dev, "Memory mapping failed!\n");
+		ret = -EFAULT;
+		goto err_ioremap;
+	}
+
+	/* Setup the PHY structures. */
+	phy->dev		= &pdev->dev;
+	phy->phy.dev		= phy->dev;
+	phy->phy.label		= "mxs-phy";
+	phy->phy.init		= phy_init;
+	phy->phy.shutdown	= phy_shutdown;
+	phy->phy.state		= OTG_STATE_A_HOST;
+
+	phy->res		= res;
+
+	phy->phy.otg->phy	= &phy->phy;
+	phy->phy.otg->set_vbus	= phy_set_vbus;
+
+	platform_set_drvdata(pdev, phy);
+
+	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
+
+	/* Enable the PHY clock. */
+	clk_prepare_enable(phy->clk);
+
+	/* Register the transceiver with kernel. */
+	ret = usb_set_transceiver(&phy->phy);
+	if (ret) {
+		dev_err(&pdev->dev, "Can't register transceiver, (%d)\n", ret);
+		goto err_set_transceiver;
+	}
+
+	return 0;
+
+err_set_transceiver:
+	clk_disable_unprepare(phy->clk);
+	iounmap(phy->reg);
+err_ioremap:
+	release_mem_region(res->start, resource_size(res));
+err_get_resource:
+	clk_put(phy->clk);
+err_claim_clock:
+	kfree(phy->phy.otg);
+err_alloc_otg:
+	kfree(phy);
+err_alloc_phy:
+
+	return ret;
+}
+
+static int __devexit mxs_phy_remove(struct platform_device *pdev)
+{
+	struct mxs_phy *phy = platform_get_drvdata(pdev);
+
+	/* Power down the PHY. */
+	phy_shutdown(&phy->phy);
+
+	/* Stop the PHY clock. */
+	clk_disable_unprepare(phy->clk);
+
+	/* Unmap and release the PHY memory region. */
+	iounmap(phy->reg);
+	release_mem_region(phy->res->start, resource_size(phy->res));
+
+	/* Reclaim the clock. */
+	clk_put(phy->clk);
+
+	/* Free the rest. */
+	usb_set_transceiver(NULL);
+	platform_set_drvdata(pdev, NULL);
+	kfree(phy->phy.otg);
+	kfree(phy);
+
+	return 0;
+}
+
+static struct platform_driver mxs_phy_driver = {
+	.probe		= mxs_phy_probe,
+	.remove		= __devexit_p(mxs_phy_remove),
+	.driver		= {
+		.name	= "mxs-phy",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mxs_phy_init(void)
+{
+	return platform_driver_register(&mxs_phy_driver);
+}
+
+static void __exit mxs_phy_exit(void)
+{
+	platform_driver_unregister(&mxs_phy_driver);
+}
+
+/*
+ * PHY must be registered via subsys_initcall to get it running before EHCI
+ * controller driver.
+ */
+subsys_initcall(mxs_phy_init);
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs_phy");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
-- 
1.7.9.5

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

* [PATCH 6/8] MXS: Add separate MXS EHCI HCD driver
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (4 preceding siblings ...)
  2012-04-17 10:15 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 10:15 ` [PATCH 7/8] MXS: Enable USB on M28EVK Marek Vasut
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to keep
this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
though eventually these two might be merged.

NOTE: I still haven't figured out how to enable/disable the disconnection
detector, it can't be enabled all the time, so I toggle PHY stuff from this
driver, which I doubt is correct.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/host/Kconfig    |    7 +
 drivers/usb/host/ehci-hcd.c |    5 +
 drivers/usb/host/ehci-mxs.c |  309 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 321 insertions(+)
 create mode 100644 drivers/usb/host/ehci-mxs.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f788eb8..85ed593 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -148,6 +148,13 @@ config USB_EHCI_MXC
 	---help---
 	  Variation of ARC USB block used in some Freescale chips.
 
+config USB_EHCI_MXS
+	bool "Support for Freescale i.MX28 on-chip EHCI USB controller"
+	depends on USB_EHCI_HCD && ARCH_MXS
+	select USB_EHCI_ROOT_HUB_TT
+	---help---
+	  Enable USB support for i.MX28.
+
 config USB_EHCI_HCD_OMAP
 	bool "EHCI support for OMAP3 and later chips"
 	depends on USB_EHCI_HCD && ARCH_OMAP
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 806cc95..d0df8be 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1263,6 +1263,11 @@ MODULE_LICENSE ("GPL");
 #define PLATFORM_DRIVER		ehci_mxc_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_MXS
+#include "ehci-mxs.c"
+#define PLATFORM_DRIVER		ehci_mxs_driver
+#endif
+
 #ifdef CONFIG_USB_EHCI_SH
 #include "ehci-sh.c"
 #define PLATFORM_DRIVER		ehci_hcd_sh_driver
diff --git a/drivers/usb/host/ehci-mxs.c b/drivers/usb/host/ehci-mxs.c
new file mode 100644
index 0000000..906738e
--- /dev/null
+++ b/drivers/usb/host/ehci-mxs.c
@@ -0,0 +1,309 @@
+/*
+ * Freescale i.MX28 EHCI driver
+ *
+ * Copyright (c) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * Based on MXC EHCI driver:
+ *
+ * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
+ * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, 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,
+ * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/slab.h>
+
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#include <asm/mach-types.h>
+
+#define MXC_EHCI_MODE_ULPI	(2 << 30)
+
+struct ehci_mxs_priv {
+	struct clk	*usbclk;
+	struct usb_hcd	*hcd;
+	struct usb_phy	*phy;
+	bool		discon;
+};
+
+/* Called during probe() after chip reset completes */
+static int ehci_mxs_setup(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	int retval;
+
+	dbg_hcs_params(ehci, "reset");
+	dbg_hcc_params(ehci, "reset");
+
+	/* Cache this readonly data; minimize chip reads. */
+	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
+
+	hcd->has_tt = 1;
+
+	retval = ehci_halt(ehci);
+	if (retval)
+		return retval;
+
+	/* Data structure init. */
+	retval = ehci_init(hcd);
+	if (retval)
+		return retval;
+
+	ehci->sbrn = 0x20;
+
+	ehci_reset(ehci);
+
+	ehci_port_power(ehci, 0);
+
+	return 0;
+}
+
+static irqreturn_t mxs_ehci_irq(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	struct device *dev = hcd->self.controller;
+	struct ehci_mxs_priv *ehci_mxs = dev_get_drvdata(dev);
+	struct usb_phy *phy = ehci_mxs->phy;
+	u32 status;
+
+	if (phy && phy->otg && phy->otg->set_vbus) {
+		status = ehci_readl(ehci, &ehci->regs->status);
+		status = !!(status & STS_PCD);
+		if (status != ehci_mxs->discon) {
+			ehci_mxs->discon = status;
+			phy->otg->set_vbus(phy->otg, status);
+		}
+	}
+
+	return ehci_irq(hcd);
+}
+
+static const struct hc_driver ehci_mxs_hc_driver = {
+	.description	= hcd_name,
+	.product_desc	= "Freescale i.MX28 On-Chip EHCI Host Controller",
+	.hcd_priv_size	= sizeof(struct ehci_hcd),
+
+	/*
+	 * Generic hardware linkage
+	 */
+	.irq		= mxs_ehci_irq,
+	.flags		= HCD_USB2 | HCD_MEMORY,
+
+	/*
+	 * Basic lifecycle operations
+	 */
+	.reset		= ehci_mxs_setup,
+	.start		= ehci_run,
+	.stop		= ehci_stop,
+	.shutdown	= ehci_shutdown,
+
+	/*
+	 * managing i/o requests and associated device resources
+	 */
+	.urb_enqueue		= ehci_urb_enqueue,
+	.urb_dequeue		= ehci_urb_dequeue,
+	.endpoint_disable	= ehci_endpoint_disable,
+	.endpoint_reset		= ehci_endpoint_reset,
+
+	/*
+	 * scheduling support
+	 */
+	.get_frame_number	= ehci_get_frame,
+
+	/*
+	 * root hub support
+	 */
+	.hub_status_data	= ehci_hub_status_data,
+	.hub_control		= ehci_hub_control,
+	.bus_suspend		= ehci_bus_suspend,
+	.bus_resume		= ehci_bus_resume,
+	.relinquish_port	= ehci_relinquish_port,
+	.port_handed_over	= ehci_port_handed_over,
+
+	.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
+};
+
+static int ehci_mxs_drv_probe(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd;
+	struct resource *res;
+	int irq, ret;
+	struct ehci_mxs_priv *priv;
+	struct device *dev = &pdev->dev;
+	struct ehci_hcd *ehci;
+
+	dev_info(&pdev->dev, "Initializing i.MX28 USB Controller\n");
+
+	/* Get IRQ from platform data via resources. */
+	irq = platform_get_irq(pdev, 0);
+
+	/* Create HCD controller instance. */
+	hcd = usb_create_hcd(&ehci_mxs_hc_driver, dev, dev_name(dev));
+	if (!hcd) {
+		dev_err(dev, "Failed to create HCD instance!\n");
+		return -ENOMEM;
+	}
+
+	/* Allocate private data for this instance. */
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	if (!priv) {
+		dev_err(dev, "Failed to allocate private data!\n");
+		ret = -ENOMEM;
+		goto err_alloc;
+	}
+
+	/* Get memory area where this controller resides from resources. */
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "Specify memory area for this controller!\n");
+		ret = -ENODEV;
+		goto err_get_resource;
+	}
+
+	hcd->rsrc_start = res->start;
+	hcd->rsrc_len = resource_size(res);
+
+	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
+		dev_dbg(dev, "controller already in use\n");
+		ret = -EBUSY;
+		goto err_request_mem;
+	}
+
+	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
+	if (!hcd->regs) {
+		dev_err(dev, "error mapping memory\n");
+		ret = -EFAULT;
+		goto err_ioremap;
+	}
+
+	/* enable clocks */
+	priv->usbclk = clk_get(dev, "usb");
+	if (IS_ERR(priv->usbclk)) {
+		ret = PTR_ERR(priv->usbclk);
+		goto err_clk;
+	}
+	clk_prepare_enable(priv->usbclk);
+
+	/* Wait for the controller to stabilize. */
+	mdelay(10);
+
+	/* Initialize the transceiver */
+#ifdef CONFIG_USB_OTG_UTILS
+	priv->phy = usb_get_transceiver();
+	if (!priv->phy) {
+		dev_err(&pdev->dev, "Unable to find transceiver.\n");
+		ret = -ENODEV;
+		goto err_add;
+	}
+
+	ret = usb_phy_init(priv->phy);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Unable init transceiver\n");
+		ret = -ENODEV;
+		goto err_put_tx;
+	}
+#else
+	dev_info(&pdev->dev,
+		"USB_MXS_PHY must have CONFIG_USB_OTG_UTILS enabled\n");
+	goto err_add;
+#endif
+
+	ehci = hcd_to_ehci(hcd);
+
+	/* EHCI registers start at offset 0x100 */
+	ehci->caps = hcd->regs + 0x100;
+	ehci->regs = hcd->regs + 0x100 +
+		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
+
+	/* Set up the PORTSCx register */
+	ehci_writel(ehci, MXC_EHCI_MODE_ULPI, &ehci->regs->port_status[0]);
+
+	priv->discon = false;
+	priv->hcd = hcd;
+	platform_set_drvdata(pdev, priv);
+
+	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+	if (ret)
+		goto err_add;
+
+	return 0;
+
+#ifdef CONFIG_USB_OTG_UTILS
+err_put_tx:
+	usb_put_transceiver(priv->phy);
+#endif
+err_add:
+	clk_disable_unprepare(priv->usbclk);
+	clk_put(priv->usbclk);
+err_clk:
+	iounmap(hcd->regs);
+err_ioremap:
+	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+err_request_mem:
+err_get_resource:
+	kfree(priv);
+err_alloc:
+	usb_put_hcd(hcd);
+	return ret;
+}
+
+static int __exit ehci_mxs_drv_remove(struct platform_device *pdev)
+{
+	struct ehci_mxs_priv *priv = platform_get_drvdata(pdev);
+	struct usb_hcd *hcd = priv->hcd;
+
+	if (priv->phy)
+		usb_phy_shutdown(priv->phy);
+
+	usb_remove_hcd(hcd);
+	iounmap(hcd->regs);
+	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+	usb_put_hcd(hcd);
+	platform_set_drvdata(pdev, NULL);
+
+	clk_disable_unprepare(priv->usbclk);
+	clk_put(priv->usbclk);
+	kfree(priv);
+
+	return 0;
+}
+
+static void ehci_mxs_drv_shutdown(struct platform_device *pdev)
+{
+	struct ehci_mxs_priv *priv = platform_get_drvdata(pdev);
+	struct usb_hcd *hcd = priv->hcd;
+
+	if (hcd->driver->shutdown)
+		hcd->driver->shutdown(hcd);
+}
+
+static struct platform_driver ehci_mxs_driver = {
+	.probe		= ehci_mxs_drv_probe,
+	.remove		= __exit_p(ehci_mxs_drv_remove),
+	.shutdown	= ehci_mxs_drv_shutdown,
+	.driver		= {
+		   .name	= "mxs-ehci",
+	},
+};
+
+MODULE_ALIAS("platform:mxs-ehci");
-- 
1.7.9.5

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

* [PATCH 7/8] MXS: Enable USB on M28EVK
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (5 preceding siblings ...)
  2012-04-17 10:15 ` [PATCH 6/8] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 17:40   ` Sergei Shtylyov
  2012-04-17 10:15 ` [PATCH 8/8] MXS: Enable USB on MX28EVK Marek Vasut
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

Enable the second USB port on M28EVK board.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig       |    2 ++
 arch/arm/mach-mxs/mach-m28evk.c |   10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index 9dbf29f..5b5566c 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -83,6 +83,8 @@ config MODULE_M28
 	select MXS_HAVE_PLATFORM_MXS_LRADC
 	select MXS_HAVE_PLATFORM_MXS_MMC
 	select MXS_HAVE_PLATFORM_MXSFB
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 
 config MODULE_APX4
diff --git a/arch/arm/mach-mxs/mach-m28evk.c b/arch/arm/mach-mxs/mach-m28evk.c
index f32fadb..a1850bc 100644
--- a/arch/arm/mach-mxs/mach-m28evk.c
+++ b/arch/arm/mach-mxs/mach-m28evk.c
@@ -212,6 +212,11 @@ static const iomux_cfg_t m28evk_pads[] __initconst = {
 
 	/* Backlight */
 	MX28_PAD_PWM3__GPIO_3_28 | MXS_PAD_CTRL,
+
+	/* USB */
+	MX28_PAD_SSP2_SS1__USB1_OVERCURRENT,
+	MX28_PAD_AUART3_TX__GPIO_3_13 |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
 };
 
 /* led */
@@ -377,6 +382,11 @@ static void __init m28evk_init(void)
 	mx28_add_ts(&touch_pdata);
 
 	mx28_add_gpmi_nand(&m28evk_gpmi_nand_data);
+
+	gpio_request(MXS_GPIO_NR(3, 13), "USB");
+	gpio_direction_output(MXS_GPIO_NR(3, 13), 0);
+
+	mx28_add_mxs_usbh(1);
 }
 
 static void __init m28evk_timer_init(void)
-- 
1.7.9.5

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

* [PATCH 8/8] MXS: Enable USB on MX28EVK
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (6 preceding siblings ...)
  2012-04-17 10:15 ` [PATCH 7/8] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-17 10:15 ` Marek Vasut
  2012-04-17 10:37 ` [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Dirk Behme
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 10:15 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig        |    2 ++
 arch/arm/mach-mxs/mach-mx28evk.c |   10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index 5b5566c..696e1d1 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -53,6 +53,8 @@ config MACH_MX28EVK
 	select MXS_HAVE_PLATFORM_MXS_SAIF
 	select MXS_HAVE_PLATFORM_MXS_I2C
 	select MXS_HAVE_PLATFORM_RTC_STMP3XXX
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 	help
 	  Include support for MX28EVK platform. This includes specific
diff --git a/arch/arm/mach-mxs/mach-mx28evk.c b/arch/arm/mach-mxs/mach-mx28evk.c
index e386c14..8bdd416 100644
--- a/arch/arm/mach-mxs/mach-mx28evk.c
+++ b/arch/arm/mach-mxs/mach-mx28evk.c
@@ -37,6 +37,7 @@
 #define MX28EVK_BL_ENABLE	MXS_GPIO_NR(3, 18)
 #define MX28EVK_LCD_ENABLE	MXS_GPIO_NR(3, 30)
 #define MX28EVK_FEC_PHY_RESET	MXS_GPIO_NR(4, 13)
+#define MX28EVK_USB1_PWR_EN	MXS_GPIO_NR(3, 8)
 
 #define MX28EVK_MMC0_WRITE_PROTECT	MXS_GPIO_NR(2, 12)
 #define MX28EVK_MMC1_WRITE_PROTECT	MXS_GPIO_NR(0, 28)
@@ -186,6 +187,8 @@ static const iomux_cfg_t mx28evk_pads[] __initconst = {
 
 	/* led */
 	MX28_PAD_AUART1_TX__GPIO_3_5 | MXS_PAD_CTRL,
+	/* usb1 */
+	MX28_PAD_AUART2_RX__GPIO_3_8 | MXS_PAD_CTRL,
 
 	/* I2C */
 	MX28_PAD_I2C0_SCL__I2C0_SCL |
@@ -451,6 +454,13 @@ static void __init mx28evk_init(void)
 	mx28_add_mxs_mmc(0, &mx28evk_mmc_pdata[0]);
 	mx28_add_mxs_mmc(1, &mx28evk_mmc_pdata[1]);
 
+	ret = gpio_request_one(MX28EVK_USB1_PWR_EN, GPIOF_OUT_INIT_HIGH,
+				"usb1-power-en");
+	if (ret)
+		pr_warn("failed to request gpio usb1-power-en %d\n", ret);
+
+	mx28_add_mxs_usbh(1);
+
 	mx28_add_rtc_stmp3xxx();
 
 	gpio_led_register_device(0, &mx28evk_led_data);
-- 
1.7.9.5

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (7 preceding siblings ...)
  2012-04-17 10:15 ` [PATCH 8/8] MXS: Enable USB on MX28EVK Marek Vasut
@ 2012-04-17 10:37 ` Dirk Behme
  2012-04-17 11:24   ` Marek Vasut
  2012-04-17 11:29 ` Sascha Hauer
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
  10 siblings, 1 reply; 149+ messages in thread
From: Dirk Behme @ 2012-04-17 10:37 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marek,

On 17.04.2012 12:15, Marek Vasut wrote:
> This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
> generic USB PHY infrastructure.

Great, many thanks!

Unfortunately, I lost the overview over the i.MXxx USB discussion ;)

Could this be used to add support for the mx53 and mx6, too? If yes, 
what do you think would be needed for this?

Best regards

Dirk

P.S.: What I read from the discussion:

-- cut --
All recent Freescale SoC's USB controller are the same, they are mx23, 
mx25, mx28, mx31, mx35, mx37, mx50, mx51, mx53, and mx6. But, the 
transceiver is different between them
* mx23, mx28, mx6 (Transceiver A)
* mx25 mx31, mx35,mx37, mx50, mx51, mx53 (Transceiver B)
-- cut --

> Marek Vasut (8):
>   MXS: Make clk_disable return integer
>   MXS: Add USB EHCI and USB PHY clock handling
>   MXS: Fixup i.MX233 USB base address name
>   MXS: Add platform registration hooks for USB EHCI
>   MXS: Add USB PHY driver
>   MXS: Add separate MXS EHCI HCD driver
>   MXS: Enable USB on M28EVK
>   MXS: Enable USB on MX28EVK
> 
>  arch/arm/mach-mxs/Kconfig                       |    4 +
>  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
>  arch/arm/mach-mxs/devices-mx28.h                |    4 +
>  arch/arm/mach-mxs/devices/Kconfig               |    3 +
>  arch/arm/mach-mxs/devices/Makefile              |    1 +
>  arch/arm/mach-mxs/devices/platform-usb.c        |   79 ++++++
>  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
>  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
>  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
>  arch/arm/mach-mxs/mach-m28evk.c                 |   10 +
>  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
>  drivers/usb/host/Kconfig                        |    7 +
>  drivers/usb/host/ehci-hcd.c                     |    5 +
>  drivers/usb/host/ehci-mxs.c                     |  309 +++++++++++++++++++++++
>  drivers/usb/otg/Kconfig                         |    9 +
>  drivers/usb/otg/Makefile                        |    1 +
>  drivers/usb/otg/mxs-phy.c                       |  256 +++++++++++++++++++
>  17 files changed, 736 insertions(+), 9 deletions(-)
>  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
>  create mode 100644 drivers/usb/host/ehci-mxs.c
>  create mode 100644 drivers/usb/otg/mxs-phy.c
> 
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 10:37 ` [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Dirk Behme
@ 2012-04-17 11:24   ` Marek Vasut
  2012-04-18  1:00     ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 11:24 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Dirk Behme,

> Hi Marek,
> 
> On 17.04.2012 12:15, Marek Vasut wrote:
> > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > the generic USB PHY infrastructure.
> 
> Great, many thanks!

Hey, this is still RFC and will need a great discussion.

> 
> Unfortunately, I lost the overview over the i.MXxx USB discussion ;)

Well I put parts together from the old patchset, did some coding on my own ... I 
still have a few places where I'm very uncertain about so please, review 
thoroughly.

> 
> Could this be used to add support for the mx53 and mx6, too? If yes,
> what do you think would be needed for this?

Yes, that's the plan actually. But, isn't mx53 supported by ehci-mxc? I thought 
the USB PHY core from mx28 was then reused only in mx6q.

You'd have to add support for some clock handling probably (enabling the USB 
clock on mx53 and maybe some other clock, I'm not quite sure now without the 
manual), but that should be about it. The MX6q PHY on the other hand looks quite 
similar to mx28 so it should be easy hacking.

> 
> Best regards
> 
> Dirk
> 
> P.S.: What I read from the discussion:
> 
> -- cut --
> All recent Freescale SoC's USB controller are the same, they are mx23,
> mx25, mx28, mx31, mx35, mx37, mx50, mx51, mx53, and mx6. But, the
> transceiver is different between them
> * mx23, mx28, mx6 (Transceiver A)
> * mx25 mx31, mx35,mx37, mx50, mx51, mx53 (Transceiver B)
> -- cut --
> 
> > Marek Vasut (8):
> >   MXS: Make clk_disable return integer
> >   MXS: Add USB EHCI and USB PHY clock handling
> >   MXS: Fixup i.MX233 USB base address name
> >   MXS: Add platform registration hooks for USB EHCI
> >   MXS: Add USB PHY driver
> >   MXS: Add separate MXS EHCI HCD driver
> >   MXS: Enable USB on M28EVK
> >   MXS: Enable USB on MX28EVK
> >  
> >  arch/arm/mach-mxs/Kconfig                       |    4 +
> >  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
> >  arch/arm/mach-mxs/devices-mx28.h                |    4 +
> >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> >  arch/arm/mach-mxs/devices/platform-usb.c        |   79 ++++++
> >  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> >  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
> >  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> >  arch/arm/mach-mxs/mach-m28evk.c                 |   10 +
> >  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
> >  drivers/usb/host/Kconfig                        |    7 +
> >  drivers/usb/host/ehci-hcd.c                     |    5 +
> >  drivers/usb/host/ehci-mxs.c                     |  309
> >  +++++++++++++++++++++++ drivers/usb/otg/Kconfig                        
> >  |    9 +
> >  drivers/usb/otg/Makefile                        |    1 +
> >  drivers/usb/otg/mxs-phy.c                       |  256
> >  +++++++++++++++++++ 17 files changed, 736 insertions(+), 9 deletions(-)
> >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> >  create mode 100644 drivers/usb/host/ehci-mxs.c
> >  create mode 100644 drivers/usb/otg/mxs-phy.c
> > 
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>

Best regards,
Marek Vasut

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (8 preceding siblings ...)
  2012-04-17 10:37 ` [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Dirk Behme
@ 2012-04-17 11:29 ` Sascha Hauer
  2012-04-17 11:45   ` Marek Vasut
                     ` (2 more replies)
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
  10 siblings, 3 replies; 149+ messages in thread
From: Sascha Hauer @ 2012-04-17 11:29 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marek,

On Tue, Apr 17, 2012 at 12:15:43PM +0200, Marek Vasut wrote:
> This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
> generic USB PHY infrastructure.
> 

Your patches won't work when more than one USB port is enabled because
of the singular usb transceiver present in the kernel. That of course is
not your fault. I think Heikki (Added to Cc) is working on this issue,
but I don't know the status here.

Another problem is that what you are doing does not integrate at all
with otg. I don't ask you to implement otg support because you are
likely not interested in this, but since you are adding a new ehci
glue driver anyway I suggest another approach:

Put a driver under drivers/usb/otg which:

- matches a 'imx-usb' device
- gets/enables all clocks needed for USB
- finds the transceiver
- registers a ehci device

Future additions would be:

- Put a USB_MODE_HOST/DEVICE flag into platform_data, and register a
  host or gadget driver depending on this flag
- Add a USB_MODE_OTG flag to platform_data and implement otg in this
  driver (or use whatever infrastructure present in the kernel then)

This is similar to what msm does. This way we have the clocks and phys
handled where they are needed. We may use this code on i.MX later.

We did this wrong on i.MX (and several other architectures) and getting
this right will be hard work. No need to introduce the same flaws again
with a new architecture.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 11:29 ` Sascha Hauer
@ 2012-04-17 11:45   ` Marek Vasut
  2012-04-17 12:18     ` Sascha Hauer
  2012-04-17 12:36   ` Heikki Krogerus
  2012-04-18  4:31   ` Chen Peter-B29397
  2 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 11:45 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> Hi Marek,
> 
> On Tue, Apr 17, 2012 at 12:15:43PM +0200, Marek Vasut wrote:
> > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > the generic USB PHY infrastructure.
> 
> Your patches won't work when more than one USB port is enabled because
> of the singular usb transceiver present in the kernel. That of course is
> not your fault. I think Heikki (Added to Cc) is working on this issue,
> but I don't know the status here.

All right, I'll let Heikki hack on that. I'm not sure if we have any mx28 based 
device with multiple USB ports in kernel. Do we ?

> Another problem is that what you are doing does not integrate at all
> with otg.

Well, how should this be done to integrate with OTG then?

> I don't ask you to implement otg support because you are
> likely not interested in this, but since you are adding a new ehci
> glue driver anyway I suggest another approach:
> 
> Put a driver under drivers/usb/otg which:
> 
> - matches a 'imx-usb' device
> - gets/enables all clocks needed for USB
> - finds the transceiver
> - registers a ehci device

So the PHY actually registers the EHCI driver (plat_bus->phy->ehci)? That's 
slightly weird, don't you think?

> 
> Future additions would be:
> 
> - Put a USB_MODE_HOST/DEVICE flag into platform_data, and register a
>   host or gadget driver depending on this flag
> - Add a USB_MODE_OTG flag to platform_data and implement otg in this
>   driver (or use whatever infrastructure present in the kernel then)

Ok, this sounds reasonable.

> This is similar to what msm does. This way we have the clocks and phys
> handled where they are needed. We may use this code on i.MX later.

Ok, I'll check the MSM stuff.

> We did this wrong on i.MX (and several other architectures) and getting
> this right will be hard work. No need to introduce the same flaws again
> with a new architecture.

Ack, thanks for pointers.

> Sascha

Best regards,
Marek Vasut

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 11:45   ` Marek Vasut
@ 2012-04-17 12:18     ` Sascha Hauer
  2012-04-17 20:29       ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-17 12:18 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Apr 17, 2012 at 01:45:07PM +0200, Marek Vasut wrote:
> Dear Sascha Hauer,
> 
> > Hi Marek,
> > 
> > On Tue, Apr 17, 2012 at 12:15:43PM +0200, Marek Vasut wrote:
> > > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > > the generic USB PHY infrastructure.
> > 
> > Your patches won't work when more than one USB port is enabled because
> > of the singular usb transceiver present in the kernel. That of course is
> > not your fault. I think Heikki (Added to Cc) is working on this issue,
> > but I don't know the status here.
> 
> All right, I'll let Heikki hack on that. I'm not sure if we have any mx28 based 
> device with multiple USB ports in kernel. Do we ?
> 
> > Another problem is that what you are doing does not integrate at all
> > with otg.
> 
> Well, how should this be done to integrate with OTG then?
> 
> > I don't ask you to implement otg support because you are
> > likely not interested in this, but since you are adding a new ehci
> > glue driver anyway I suggest another approach:
> > 
> > Put a driver under drivers/usb/otg which:
> > 
> > - matches a 'imx-usb' device
> > - gets/enables all clocks needed for USB
> > - finds the transceiver
> > - registers a ehci device
> 
> So the PHY actually registers the EHCI driver (plat_bus->phy->ehci)? That's 
> slightly weird, don't you think?

Your hardware device is a device consisting of a ehci core and a USB device
core. Currently we register the child devices independently which leads
to the mentioned problems. Instead we should register the USB core as a
whole and pass the resources to either the client or the host driver.

The phys are completely independent devices (from a bus topology point
of view). The USB core just happens to use the phys.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 11:29 ` Sascha Hauer
  2012-04-17 11:45   ` Marek Vasut
@ 2012-04-17 12:36   ` Heikki Krogerus
  2012-04-18  4:31   ` Chen Peter-B29397
  2 siblings, 0 replies; 149+ messages in thread
From: Heikki Krogerus @ 2012-04-17 12:36 UTC (permalink / raw)
  To: linux-arm-kernel

Hi guys,

On Tue, Apr 17, 2012 at 01:29:10PM +0200, Sascha Hauer wrote:
> Your patches won't work when more than one USB port is enabled because
> of the singular usb transceiver present in the kernel. That of course is
> not your fault. I think Heikki (Added to Cc) is working on this issue,
> but I don't know the status here.

No I'm not working on multi PHY support. At one point I was thinking
about introducing a very basic support for it but it would not have
been enough for USB3 and OMAP4. I believe Kishon has been working on
this. Kishon?

-- 
heikki

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

* [PATCH 7/8] MXS: Enable USB on M28EVK
  2012-04-17 10:15 ` [PATCH 7/8] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-17 17:40   ` Sergei Shtylyov
  0 siblings, 0 replies; 149+ messages in thread
From: Sergei Shtylyov @ 2012-04-17 17:40 UTC (permalink / raw)
  To: linux-arm-kernel

Hello.

On 04/17/2012 02:15 PM, Marek Vasut wrote:

> Enable the second USB port on M28EVK board.

> Signed-off-by: Marek Vasut<marex@denx.de>
> Cc: Chen Peter-B29397<B29397@freescale.com>
> Cc: Detlev Zundel<dzu@denx.de>
> Cc: Fabio Estevam<festevam@gmail.com>
> Cc: Li Frank-B20596<B20596@freescale.com>
> Cc: Lin Tony-B19295<B19295@freescale.com>
> Cc: Linux USB<linux-usb@vger.kernel.org>
> Cc: Sascha Hauer<s.hauer@pengutronix.de>
> Cc: Shawn Guo<shawn.guo@freescale.com>
> Cc: Shawn Guo<shawn.guo@linaro.org>
> Cc: Stefano Babic<sbabic@denx.de>
> Cc: Subodh Nijsure<snijsure@grid-net.com>
> Cc: Tony Lin<tony.lin@freescale.com>
> Cc: Wolfgang Denk<wd@denx.de>
[...]

> @@ -377,6 +382,11 @@ static void __init m28evk_init(void)
>   	mx28_add_ts(&touch_pdata);
>
>   	mx28_add_gpmi_nand(&m28evk_gpmi_nand_data);
> +
> +	gpio_request(MXS_GPIO_NR(3, 13), "USB");

    gpio_request() can fail and you don't handle it.

> +	gpio_direction_output(MXS_GPIO_NR(3, 13), 0);

    You can use gpio_request_one() instead of the above 2 calls.

WBR, Sergei

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-04-17 10:15 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-17 17:51   ` Sascha Hauer
  2012-04-19 11:40   ` Arnd Bergmann
  1 sibling, 0 replies; 149+ messages in thread
From: Sascha Hauer @ 2012-04-17 17:51 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Apr 17, 2012 at 12:15:48PM +0200, Marek Vasut wrote:
> Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
> enables the PHY upon powerup and shuts it down on shutdown.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  drivers/usb/otg/Kconfig   |    9 ++
>  drivers/usb/otg/Makefile  |    1 +
>  drivers/usb/otg/mxs-phy.c |  256 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 266 insertions(+)
>  create mode 100644 drivers/usb/otg/mxs-phy.c
> 
> diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> index 5c87db0..8689081 100644
> --- a/drivers/usb/otg/Kconfig
> +++ b/drivers/usb/otg/Kconfig
> @@ -116,6 +116,15 @@ config FSL_USB2_OTG
>  	help
>  	  Enable this to support Freescale USB OTG transceiver.
>  
> +config USB_MXS_PHY
> +	tristate "Freescale i.MX28 USB PHY support"
> +	select USB_OTG_UTILS
> +	help
> +	  Say Y here if you want to build Freescale i.MX28 USB PHY
> +	  driver in kernel.
> +
> +	  To compile this driver as a module, choose M here.
> +
>  config USB_MV_OTG
>  	tristate "Marvell USB OTG support"
>  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> index 41aa509..a844b8d 100644
> --- a/drivers/usb/otg/Makefile
> +++ b/drivers/usb/otg/Makefile
> @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
>  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
>  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
>  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> +obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
>  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
> new file mode 100644
> index 0000000..9963aa8
> --- /dev/null
> +++ b/drivers/usb/otg/mxs-phy.c
> @@ -0,0 +1,256 @@
> +/*
> + * drivers/usb/otg/mxs-phy.c
> + *
> + * Freescale i.MX28 USB PHY driver.
> + *
> + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> + * on behalf of DENX Software Engineering GmbH
> + *
> + * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/usb/otg.h>
> +#include <linux/slab.h>
> +#include <linux/delay.h>
> +
> +#include <mach/common.h>
> +#include <mach/hardware.h>
> +#include <mach/devices-common.h>
> +#include <mach/mx28.h>
> +
> +#define HW_USBPHY_PWD				0x00
> +
> +#define HW_USBPHY_CTRL				0x30
> +#define HW_USBPHY_CTRL_SET			0x34
> +#define HW_USBPHY_CTRL_CLR			0x38
> +#define HW_USBPHY_CTRL_TOG			0x3c
> +
> +#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
> +#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
> +#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
> +#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
> +#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
> +
> +struct mxs_phy {
> +	struct usb_phy	phy;
> +	struct device	*dev;
> +	struct clk	*clk;
> +	struct resource	*res;
> +	void __iomem	*reg;
> +};
> +
> +static int phy_init(struct usb_phy *x)
> +{
> +	struct mxs_phy *phy = container_of(x, struct mxs_phy, phy);
> +	uint32_t val;
> +
> +	/* Enable clock to the PHY. */
> +	clk_enable(phy->clk);
> +
> +	/* Reset the PHY block. */
> +	mxs_reset_block(phy->reg + HW_USBPHY_CTRL);
> +
> +	/* Power up the PHY. */
> +	writel(0, phy->reg + HW_USBPHY_PWD);
> +
> +	/* Enable FS/LS compatibility and HS disconnection detector. */
> +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
> +		BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
> +	writel(val, phy->reg + HW_USBPHY_CTRL_SET);
> +
> +	return 0;
> +}
> +
> +static void phy_shutdown(struct usb_phy *x)
> +{
> +	struct mxs_phy *phy = container_of(x, struct mxs_phy, phy);
> +
> +	/* Gate off the PHY. */
> +	writel(BM_USBPHY_CTRL_CLKGATE, phy->reg + HW_USBPHY_CTRL_SET);
> +
> +	/* Disable clock to the PHY. */
> +	clk_disable(phy->clk);
> +}
> +
> +static int phy_set_vbus(struct usb_otg *otg, bool enabled)
> +{
> +	struct usb_phy *x = otg->phy;
> +	struct mxs_phy *phy = container_of(x, struct mxs_phy, phy);
> +
> +	if (enabled)
> +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> +			phy->reg + HW_USBPHY_CTRL_CLR);
> +	else
> +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> +			phy->reg + HW_USBPHY_CTRL_SET);
> +
> +	return 0;
> +}
> +
> +static int __devinit mxs_phy_probe(struct platform_device *pdev)
> +{
> +	struct mxs_phy *phy;
> +	struct resource *res;
> +	int ret;
> +
> +	/* Allocate PHY driver's private date. */
> +	phy = kzalloc(sizeof *phy, GFP_KERNEL);
> +	if (!phy) {
> +		ret = -ENOMEM;
> +		goto err_alloc_phy;
> +	}

Use devm_* functions?


> +
> +	/* Enable the PHY clock. */
> +	clk_prepare_enable(phy->clk);

The clock is enabled in probe and then again in phy_init. Once is
enough.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-17 10:15 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-04-17 18:01   ` Sascha Hauer
  0 siblings, 0 replies; 149+ messages in thread
From: Sascha Hauer @ 2012-04-17 18:01 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Apr 17, 2012 at 12:15:45PM +0200, Marek Vasut wrote:
> Based on code by:
> Tony Lin <tony.lin@freescale.com>
> 
>  	static struct clk name = {					\
>  		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
> @@ -636,8 +651,10 @@ static struct clk_lookup lookups[] = {
>  	_REGISTER_CLOCK("mxs-mmc.3", NULL, ssp3_clk)
>  	_REGISTER_CLOCK("flexcan.0", NULL, can0_clk)
>  	_REGISTER_CLOCK("flexcan.1", NULL, can1_clk)
> -	_REGISTER_CLOCK(NULL, "usb0", usb0_clk)
> -	_REGISTER_CLOCK(NULL, "usb1", usb1_clk)
> +	_REGISTER_CLOCK("mxs-ehci.0", "usb", usb0_clk)
> +	_REGISTER_CLOCK("mxs-ehci.1", "usb", usb1_clk)
> +	_REGISTER_CLOCK("mxs-phy.0", "usb0_phy", usb_phy_clk0)
> +	_REGISTER_CLOCK("mxs-phy.1", "usb1_phy", usb_phy_clk1)

The phy device name should have 'usb' in it to make clear that it's a
USB phy and not a network phy. The connection should be simply 'phy'
because the device context already makes it clear for what kind of
device the clock is.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 12:18     ` Sascha Hauer
@ 2012-04-17 20:29       ` Marek Vasut
  2012-04-18  7:02         ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-17 20:29 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> On Tue, Apr 17, 2012 at 01:45:07PM +0200, Marek Vasut wrote:
> > Dear Sascha Hauer,
> > 
> > > Hi Marek,
> > > 
> > > On Tue, Apr 17, 2012 at 12:15:43PM +0200, Marek Vasut wrote:
> > > > This patchset introduces the USB Host driver for i.MX28 CPU,
> > > > utilising the generic USB PHY infrastructure.
> > > 
> > > Your patches won't work when more than one USB port is enabled because
> > > of the singular usb transceiver present in the kernel. That of course
> > > is not your fault. I think Heikki (Added to Cc) is working on this
> > > issue, but I don't know the status here.
> > 
> > All right, I'll let Heikki hack on that. I'm not sure if we have any mx28
> > based device with multiple USB ports in kernel. Do we ?
> > 
> > > Another problem is that what you are doing does not integrate at all
> > > with otg.
> > 
> > Well, how should this be done to integrate with OTG then?
> > 
> > > I don't ask you to implement otg support because you are
> > > likely not interested in this, but since you are adding a new ehci
> > > glue driver anyway I suggest another approach:
> > > 
> > > Put a driver under drivers/usb/otg which:
> > > 
> > > - matches a 'imx-usb' device
> > > - gets/enables all clocks needed for USB
> > > - finds the transceiver
> > > - registers a ehci device
> > 
> > So the PHY actually registers the EHCI driver (plat_bus->phy->ehci)?
> > That's slightly weird, don't you think?
> 
> Your hardware device is a device consisting of a ehci core and a USB device
> core. Currently we register the child devices independently which leads
> to the mentioned problems. Instead we should register the USB core as a
> whole and pass the resources to either the client or the host driver.

Ok, giving it a second thought -- you mean to create "stub" driver, which claims 
and toggles the clock _and_ registers both the EHCI host driver and PHY driver 
under itself in the hierarchy. Is that correct?

> The phys are completely independent devices (from a bus topology point
> of view). The USB core just happens to use the phys.

Correct.

> Sascha

Best regards,
Marek Vasut

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 11:24   ` Marek Vasut
@ 2012-04-18  1:00     ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-18  1:00 UTC (permalink / raw)
  To: linux-arm-kernel

 
> >
> > On 17.04.2012 12:15, Marek Vasut wrote:
> > > This patchset introduces the USB Host driver for i.MX28 CPU,
> utilising
> > > the generic USB PHY infrastructure.
> >
> > Great, many thanks!
> 
> Hey, this is still RFC and will need a great discussion.
> 
> >
> > Unfortunately, I lost the overview over the i.MXxx USB discussion ;)
> 
> Well I put parts together from the old patchset, did some coding on my
> own ... I
> still have a few places where I'm very uncertain about so please, review
> thoroughly.
> 
> >
> > Could this be used to add support for the mx53 and mx6, too? If yes,
> > what do you think would be needed for this?
> 
> Yes, that's the plan actually. But, isn't mx53 supported by ehci-mxc? I
> thought
> the USB PHY core from mx28 was then reused only in mx6q.
> 
mx53 is still not supported by ehci-mxc.
Yes, the mx28 and mx6q use the same PHY.

> You'd have to add support for some clock handling probably (enabling the
> USB
> clock on mx53 and maybe some other clock, I'm not quite sure now without
> the
> manual), but that should be about it. The MX6q PHY on the other hand
> looks quite
> similar to mx28 so it should be easy hacking.
> 
> >
> > Best regards
> >
> > Dirk
> >
> > P.S.: What I read from the discussion:
> >
> > -- cut --
> > All recent Freescale SoC's USB controller are the same, they are mx23,
> > mx25, mx28, mx31, mx35, mx37, mx50, mx51, mx53, and mx6. But, the
> > transceiver is different between them
> > * mx23, mx28, mx6 (Transceiver A)
> > * mx25 mx31, mx35,mx37, mx50, mx51, mx53 (Transceiver B)
> > -- cut --
> >
> > > Marek Vasut (8):
> > >   MXS: Make clk_disable return integer
> > >   MXS: Add USB EHCI and USB PHY clock handling
> > >   MXS: Fixup i.MX233 USB base address name
> > >   MXS: Add platform registration hooks for USB EHCI
> > >   MXS: Add USB PHY driver
> > >   MXS: Add separate MXS EHCI HCD driver
> > >   MXS: Enable USB on M28EVK
> > >   MXS: Enable USB on MX28EVK
> > >
> > >  arch/arm/mach-mxs/Kconfig                       |    4 +
> > >  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
> > >  arch/arm/mach-mxs/devices-mx28.h                |    4 +
> > >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> > >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> > >  arch/arm/mach-mxs/devices/platform-usb.c        |   79 ++++++
> > >  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> > >  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
> > >  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> > >  arch/arm/mach-mxs/mach-m28evk.c                 |   10 +
> > >  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
> > >  drivers/usb/host/Kconfig                        |    7 +
> > >  drivers/usb/host/ehci-hcd.c                     |    5 +
> > >  drivers/usb/host/ehci-mxs.c                     |  309
> > >  +++++++++++++++++++++++ drivers/usb/otg/Kconfig
> > >  |    9 +
> > >  drivers/usb/otg/Makefile                        |    1 +
> > >  drivers/usb/otg/mxs-phy.c                       |  256
> > >  +++++++++++++++++++ 17 files changed, 736 insertions(+), 9
> deletions(-)
> > >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> > >  create mode 100644 drivers/usb/host/ehci-mxs.c
> > >  create mode 100644 drivers/usb/otg/mxs-phy.c
> > >
> > > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > > Cc: Detlev Zundel <dzu@denx.de>
> > > Cc: Fabio Estevam <festevam@gmail.com>
> > > Cc: Li Frank-B20596 <B20596@freescale.com>
> > > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > > Cc: Linux USB <linux-usb@vger.kernel.org>
> > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > Cc: Shawn Guo <shawn.guo@freescale.com>
> > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > Cc: Stefano Babic <sbabic@denx.de>
> > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > Cc: Tony Lin <tony.lin@freescale.com>
> > > Cc: Wolfgang Denk <wd@denx.de>
> 
> Best regards,
> Marek Vasut

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

* [RFC PATCH 00/10 V2]  MXS: Add i.MX28 USB Host driver
  2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (9 preceding siblings ...)
  2012-04-17 11:29 ` Sascha Hauer
@ 2012-04-18  2:07 ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
                     ` (12 more replies)
  10 siblings, 13 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
generic USB PHY infrastructure.

V2: Introduce stub imx-usb driver that then registers the PHY and EHCI drivers.

Marek Vasut (10):
  MXS: Make clk_disable return integer
  MXS: Add USB EHCI and USB PHY clock handling
  MXS: Fixup i.MX233 USB base address name
  MXS: Add data shared between imx-usb, PHY and EHCI driver
  MXS: Add platform registration hooks for USB EHCI
  MXS: Add composite imx-usb driver
  MXS: Add USB PHY driver
  MXS: Add separate MXS EHCI HCD driver
  MXS: Enable USB on M28EVK
  MXS: Enable USB on MX28EVK

 arch/arm/mach-mxs/Kconfig                       |    4 +
 arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
 arch/arm/mach-mxs/devices-mx28.h                |    4 +
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   67 +++++
 arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
 arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
 arch/arm/mach-mxs/mach-m28evk.c                 |    9 +
 arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
 drivers/usb/host/Kconfig                        |    7 +
 drivers/usb/host/ehci-hcd.c                     |    5 +
 drivers/usb/host/ehci-mxs.c                     |  254 +++++++++++++++++++
 drivers/usb/otg/Kconfig                         |   16 ++
 drivers/usb/otg/Makefile                        |    2 +
 drivers/usb/otg/imx-usb.c                       |  303 +++++++++++++++++++++++
 drivers/usb/otg/mxs-phy.c                       |  201 +++++++++++++++
 include/linux/fsl_devices.h                     |   15 ++
 19 files changed, 939 insertions(+), 9 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
 create mode 100644 drivers/usb/host/ehci-mxs.c
 create mode 100644 drivers/usb/otg/imx-usb.c
 create mode 100644 drivers/usb/otg/mxs-phy.c

Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
-- 
1.7.9.5

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

* [PATCH 01/10] MXS: Make clk_disable return integer
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
                     ` (11 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

This allows subsequent USB clock patch to interchange enable() and disable()
calls without adding unnecessary switching cruft.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c         |    7 +++++--
 arch/arm/mach-mxs/include/mach/clock.h |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index cea29c9..43116ba 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -86,7 +86,7 @@ static int _raw_clk_enable(struct clk *clk)
 	return 0;
 }
 
-static void _raw_clk_disable(struct clk *clk)
+static int _raw_clk_disable(struct clk *clk)
 {
 	u32 reg;
 
@@ -95,6 +95,8 @@ static void _raw_clk_disable(struct clk *clk)
 		reg |= 1 << clk->enable_shift;
 		__raw_writel(reg, clk->enable_reg);
 	}
+
+	return 0;
 }
 
 /*
@@ -149,7 +151,7 @@ _CLK_ENABLE_PLL(pll1_clk, PLL1, EN_USB_CLKS)
 _CLK_ENABLE_PLL(pll2_clk, PLL2, CLKGATE)
 
 #define _CLK_DISABLE_PLL(name, r, g)					\
-static void name##_disable(struct clk *clk)				\
+static int name##_disable(struct clk *clk)				\
 {									\
 	__raw_writel(BM_CLKCTRL_##r##CTRL0_POWER,			\
 		     CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
@@ -161,6 +163,7 @@ static void name##_disable(struct clk *clk)				\
 		__raw_writel(BM_CLKCTRL_##r##CTRL0_##g,			\
 			CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
 									\
+	return 0;							\
 }
 
 _CLK_DISABLE_PLL(pll0_clk, PLL0, EN_USB_CLKS)
diff --git a/arch/arm/mach-mxs/include/mach/clock.h b/arch/arm/mach-mxs/include/mach/clock.h
index 592c9ab..21d1fad 100644
--- a/arch/arm/mach-mxs/include/mach/clock.h
+++ b/arch/arm/mach-mxs/include/mach/clock.h
@@ -50,7 +50,7 @@ struct clk {
 	int (*enable) (struct clk *);
 	/* Function ptr to disable the clock. Leave blank if clock can not
 	   be gated. */
-	void (*disable) (struct clk *);
+	int (*disable) (struct clk *);
 	/* Function ptr to set the parent clock of the clock. */
 	int (*set_parent) (struct clk *, struct clk *);
 };
-- 
1.7.9.5

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

* [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
  2012-04-18  2:07   ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
                     ` (10 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index 43116ba..15fed50 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -577,6 +577,21 @@ static struct clk usb1_clk = {
 	.parent = &pll1_clk,
 };
 
+static struct clk usb_phy_clk0 = {
+	.parent = &pll0_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL0CTRL0,
+	.enable_shift = 18,
+};
+
+static struct clk usb_phy_clk1 = {
+	.parent = &pll1_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL1CTRL0,
+	.enable_shift = 18,
+};
 #define _DEFINE_CLOCK(name, er, es, p)					\
 	static struct clk name = {					\
 		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
@@ -636,8 +651,10 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-mmc.3", NULL, ssp3_clk)
 	_REGISTER_CLOCK("flexcan.0", NULL, can0_clk)
 	_REGISTER_CLOCK("flexcan.1", NULL, can1_clk)
-	_REGISTER_CLOCK(NULL, "usb0", usb0_clk)
-	_REGISTER_CLOCK(NULL, "usb1", usb1_clk)
+	_REGISTER_CLOCK("imx-usb.0", "usb", usb0_clk)
+	_REGISTER_CLOCK("imx-usb.1", "usb", usb1_clk)
+	_REGISTER_CLOCK("imx-usb.0", "phy", usb_phy_clk0)
+	_REGISTER_CLOCK("imx-usb.1", "phy", usb_phy_clk1)
 	_REGISTER_CLOCK("mxs-pwm.0", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.1", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.2", NULL, pwm_clk)
-- 
1.7.9.5

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

* [PATCH 03/10] MXS: Fixup i.MX233 USB base address name
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
  2012-04-18  2:07   ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
  2012-04-18  2:07   ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 04/10] MXS: Add data shared between imx-usb, PHY and EHCI driver Marek Vasut
                     ` (9 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

Modify USB EHCI and USB PHY base addresses on the i.MX233 to nicely fit into the
whole USB registration scheme.

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-mxs/include/mach/mx23.h b/arch/arm/mach-mxs/include/mach/mx23.h
index 599094b..7955b75 100644
--- a/arch/arm/mach-mxs/include/mach/mx23.h
+++ b/arch/arm/mach-mxs/include/mach/mx23.h
@@ -64,8 +64,8 @@
 #define MX23_AUART1_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06c000)
 #define MX23_AUART2_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06e000)
 #define MX23_DUART_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x070000)
-#define MX23_USBPHY_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
-#define MX23_USBCTRL_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
+#define MX23_USBPHY0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
+#define MX23_USBCTRL0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
 #define MX23_DRAM_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x0e0000)
 
 #define MX23_IO_P2V(x)			MXS_IO_P2V(x)
@@ -89,8 +89,8 @@
 #define MX23_INT_SPDIF_ERROR		10
 #define MX23_INT_SAIF1_IRQ		10
 #define MX23_INT_SAIF2_IRQ		10
-#define MX23_INT_USB_CTRL		11
-#define MX23_INT_USB_WAKEUP		12
+#define MX23_INT_USB0			11
+#define MX23_INT_USB0_WAKEUP		12
 #define MX23_INT_GPMI_DMA		13
 #define MX23_INT_SSP1_DMA		14
 #define MX23_INT_SSP1_ERROR		15
-- 
1.7.9.5

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

* [PATCH 04/10] MXS: Add data shared between imx-usb, PHY and EHCI driver
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (2 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
                     ` (8 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds common data shared between the MXS USB PHY driver, the MXS EHCI
HCD driver and the imx-usb composite driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 include/linux/fsl_devices.h |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index fffdf00..20038c0 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -18,6 +18,7 @@
 #define _FSL_DEVICE_H_
 
 #include <linux/types.h>
+#include <linux/platform_device.h>
 
 /*
  * Some conventions on how we handle peripherals on Freescale chips
@@ -97,6 +98,20 @@ struct fsl_usb2_platform_data {
 	u32		pm_usbgenctrl;
 };
 
+struct imx_usb_data {
+	struct clk	*clk;
+	struct resource	*mem_res;
+	void __iomem	*mem;
+	int		irq;
+};
+
+struct imx_usb {
+	struct platform_device	*host_dev;
+	struct platform_device	*phy_dev;
+	struct imx_usb_data	host;
+	struct imx_usb_data	phy;
+};
+
 /* Flags in fsl_usb2_mph_platform_data */
 #define FSL_USB2_PORT0_ENABLED	0x00000001
 #define FSL_USB2_PORT1_ENABLED	0x00000002
-- 
1.7.9.5

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (3 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 04/10] MXS: Add data shared between imx-usb, PHY and EHCI driver Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 06/10] MXS: Add composite imx-usb driver Marek Vasut
                     ` (7 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/devices-mx28.h                |    4 ++
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   67 +++++++++++++++++++++++
 arch/arm/mach-mxs/include/mach/devices-common.h |    9 +++
 5 files changed, 84 insertions(+)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c

diff --git a/arch/arm/mach-mxs/devices-mx28.h b/arch/arm/mach-mxs/devices-mx28.h
index 5f71bb2..428b184 100644
--- a/arch/arm/mach-mxs/devices-mx28.h
+++ b/arch/arm/mach-mxs/devices-mx28.h
@@ -47,6 +47,10 @@ extern const struct mxs_mxs_mmc_data mx28_mxs_mmc_data[] __initconst;
 
 #define mx28_add_mxs_pwm(id)		mxs_add_mxs_pwm(MX28_PWM_BASE_ADDR, id)
 
+extern const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst;
+#define mx28_add_mxs_usbh(id) \
+	mxs_add_mxs_usbh(&mx28_mxs_usbh_data[id])
+
 struct platform_device *__init mx28_add_mxsfb(
 		const struct mxsfb_platform_data *pdata);
 
diff --git a/arch/arm/mach-mxs/devices/Kconfig b/arch/arm/mach-mxs/devices/Kconfig
index abad78d..a297d12 100644
--- a/arch/arm/mach-mxs/devices/Kconfig
+++ b/arch/arm/mach-mxs/devices/Kconfig
@@ -35,3 +35,6 @@ config MXS_HAVE_PLATFORM_MXS_SAIF
 
 config MXS_HAVE_PLATFORM_RTC_STMP3XXX
 	bool
+
+config MXS_HAVE_PLATFORM_USB
+	bool
diff --git a/arch/arm/mach-mxs/devices/Makefile b/arch/arm/mach-mxs/devices/Makefile
index 3e6fb12..2dbdf99 100644
--- a/arch/arm/mach-mxs/devices/Makefile
+++ b/arch/arm/mach-mxs/devices/Makefile
@@ -12,3 +12,4 @@ obj-y += platform-gpio-mxs.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXSFB) += platform-mxsfb.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXS_SAIF) += platform-mxs-saif.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_RTC_STMP3XXX) += platform-rtc-stmp3xxx.o
+obj-$(CONFIG_MXS_HAVE_PLATFORM_USB) += platform-usb.o
diff --git a/arch/arm/mach-mxs/devices/platform-usb.c b/arch/arm/mach-mxs/devices/platform-usb.c
new file mode 100644
index 0000000..479267d
--- /dev/null
+++ b/arch/arm/mach-mxs/devices/platform-usb.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+#include <linux/compiler.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/mx23.h>
+#include <mach/mx28.h>
+#include <mach/devices-common.h>
+
+#define mxs_usbh_data_entry_single(soc, _id, hwid)			\
+	{								\
+		.id = _id,						\
+		.usb_irq = soc ## _INT_USB ## hwid,			\
+		.usb_iobase = soc ## _USBCTRL ## hwid ## _BASE_ADDR,	\
+		.phy_iobase = soc ## _USBPHY ## hwid ## _BASE_ADDR,	\
+	}
+
+#define mxs_usbh_data_entry(soc, _id, hwid)				\
+	[_id] = mxs_usbh_data_entry_single(soc, _id, hwid)
+
+#ifdef CONFIG_SOC_IMX23
+const struct mxs_usbh_data mx23_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX23, 0, 0),
+};
+#endif
+
+#ifdef CONFIG_SOC_IMX28
+const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX28, 0, 0),
+	mxs_usbh_data_entry(MX28, 1, 1),
+};
+#endif
+
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data)
+{
+	struct platform_device *pdev;
+	struct resource usb_res[] = {
+		{
+			.start	= data->usb_iobase,
+			.end	= data->usb_iobase + SZ_64K - 1,
+			.flags	= IORESOURCE_MEM,
+		}, {
+			.start	= data->phy_iobase,
+			.end	= data->phy_iobase + SZ_256 - 1,
+			.flags	= IORESOURCE_MEM,
+		}, {
+			.start	= data->usb_irq,
+			.end	= data->usb_irq,
+			.flags	= IORESOURCE_IRQ,
+		},
+	};
+
+	pdev = mxs_add_platform_device_dmamask("imx-usb", data->id,
+					usb_res, ARRAY_SIZE(usb_res),
+					NULL, 0,
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register USB composite driver!\n");
+}
diff --git a/arch/arm/mach-mxs/include/mach/devices-common.h b/arch/arm/mach-mxs/include/mach/devices-common.h
index 3bffcd5..8fdd936 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
+++ b/arch/arm/mach-mxs/include/mach/devices-common.h
@@ -42,6 +42,15 @@ struct mxs_auart_data {
 struct platform_device *__init mxs_add_auart(
 		const struct mxs_auart_data *data);
 
+/* usb host */
+struct mxs_usbh_data {
+	int id;
+	resource_size_t usb_irq;
+	resource_size_t usb_iobase;
+	resource_size_t phy_iobase;
+};
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data);
+
 /* fec */
 #include <linux/fec.h>
 struct mxs_fec_data {
-- 
1.7.9.5

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

* [PATCH 06/10] MXS: Add composite imx-usb driver
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (4 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
                     ` (6 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

This driver handles claiming of clocks and memory areas. These are later
properly delegated to it's child devices, the USB PHY and USB Host.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |    6 +
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/imx-usb.c |  303 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 310 insertions(+)
 create mode 100644 drivers/usb/otg/imx-usb.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 5c87db0..e7c6325 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -116,6 +116,12 @@ config FSL_USB2_OTG
 	help
 	  Enable this to support Freescale USB OTG transceiver.
 
+config USB_IMX_COMPOSITE
+	bool
+	help
+	  Composite driver that handles clock and memory mapping for
+	  i.MX USB host and USB PHY.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 41aa509..e3feaca 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
 obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
+obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-usb.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/imx-usb.c b/drivers/usb/otg/imx-usb.c
new file mode 100644
index 0000000..8062dfa
--- /dev/null
+++ b/drivers/usb/otg/imx-usb.c
@@ -0,0 +1,303 @@
+/*
+ * drivers/usb/otg/imx-usb.c
+ *
+ * Freescale i.MX USB composite driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb/otg.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fsl_devices.h>
+#include <linux/io.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+
+/*
+ * Allocate platform device with the DMA mask, this is borrowed from
+ * arch/arm/mach-mxs/devices.c
+ */
+static struct platform_device *__devinit add_platform_device(
+		const char *name, int id,
+		const void *data, size_t size_data, u64 dmamask)
+{
+	int ret = -ENOMEM;
+	struct platform_device *pdev;
+
+	pdev = platform_device_alloc(name, id);
+	if (!pdev)
+		goto err;
+
+	if (dmamask) {
+		/*
+		 * This memory isn't freed when the device is put,
+		 * I don't have a nice idea for that though.  Conceptually
+		 * dma_mask in struct device should not be a pointer.
+		 * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
+		 */
+		pdev->dev.dma_mask =
+			kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
+		if (!pdev->dev.dma_mask)
+			/* ret is still -ENOMEM; */
+			goto err;
+
+		*pdev->dev.dma_mask = dmamask;
+		pdev->dev.coherent_dma_mask = dmamask;
+	}
+
+	if (data) {
+		ret = platform_device_add_data(pdev, data, size_data);
+		if (ret)
+			goto err;
+	}
+
+	ret = platform_device_add(pdev);
+	if (ret) {
+err:
+		if (dmamask)
+			kfree(pdev->dev.dma_mask);
+		platform_device_put(pdev);
+		return ERR_PTR(ret);
+	}
+
+	return pdev;
+}
+
+static int __devinit imx_usb_probe(struct platform_device *pdev)
+{
+	struct imx_usb *data;
+	struct imx_usb_data *host_data, *phy_data;
+	int ret;
+	void *retp = NULL;
+
+	/*
+	 * Until further notice, this claims all necessary resources.
+	 */
+
+	/* Allocate driver's private date. */
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		ret = -ENOMEM;
+		goto err_alloc_data;
+	}
+
+	host_data = &data->host;
+	phy_data = &data->phy;
+
+	/* Claim the Host clock. */
+	host_data->clk = clk_get(&pdev->dev, "usb");
+	if (IS_ERR(host_data->clk)) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB Host\n");
+		ret = PTR_ERR(host_data->clk);
+		goto err_claim_host_clock;
+	}
+
+	/* Claim the PHY clock. */
+	phy_data->clk = clk_get(&pdev->dev, "phy");
+	if (!phy_data->clk) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB PHY\n");
+		ret = PTR_ERR(host_data->clk);
+		goto err_claim_phy_clock;
+	}
+
+	/* Prepare Host clock. */
+	ret = clk_prepare(host_data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to prepare clock for USB Host.\n");
+		goto err_prepare_host_clock;
+	}
+
+	/* Prepare PHY clock. */
+	ret = clk_prepare(phy_data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to prepare clock for USB PHY.\n");
+		goto err_prepare_phy_clock;
+	}
+
+	/* Get memory area for EHCI host from resources. */
+	host_data->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!host_data->mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_resource;
+	}
+
+	/* Get memory area for PHY from resources. */
+	phy_data->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	if (!phy_data->mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB PHY!\n");
+		ret = -ENODEV;
+		goto err_get_phy_resource;
+	}
+
+	/* Request the memory region for this USB Host. */
+	retp = devm_request_mem_region(&pdev->dev, host_data->mem_res->start,
+			resource_size(host_data->mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB Host memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_get_host_mem;
+	}
+
+	/* Request the memory region for this USB PHY. */
+	retp = devm_request_mem_region(&pdev->dev, phy_data->mem_res->start,
+			resource_size(phy_data->mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB PHY memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_get_phy_mem;
+	}
+
+	/* Map the memory region for USB Host. */
+	host_data->mem = devm_ioremap(&pdev->dev, host_data->mem_res->start,
+				resource_size(host_data->mem_res));
+	if (!host_data->mem) {
+		dev_err(&pdev->dev, "Memory mapping of USB Host failed!\n");
+		ret = -EFAULT;
+		goto err_map_host_mem;
+	}
+
+	/* Map the memory region for USB PHY. */
+	phy_data->mem = devm_ioremap(&pdev->dev, phy_data->mem_res->start,
+				resource_size(phy_data->mem_res));
+	if (!phy_data->mem) {
+		dev_err(&pdev->dev, "Memory mapping of USB PHY failed!\n");
+		ret = -EFAULT;
+		goto err_map_phy_mem;
+	}
+
+	/* Get IRQ for EHCI host from resources. */
+	host_data->irq = platform_get_irq(pdev, 0);
+	if (host_data->irq < 0) {
+		dev_err(&pdev->dev, "Specify IRQ for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_irq;
+	}
+
+	/*
+	 * Now finally probe the Host and PHY drivers!
+	 */
+	data->phy_dev = add_platform_device("mxs-usb-phy", -1, &data->phy,
+					sizeof(data->phy), DMA_BIT_MASK(32));
+	if (!data->phy_dev) {
+		dev_err(&pdev->dev, "Failed registering PHY!\n");
+		ret = -ENODEV;
+		goto err_register_phy;
+	}
+
+	data->host_dev = add_platform_device("mxs-ehci", -1, &data->host,
+					sizeof(data->host), DMA_BIT_MASK(32));
+	if (!data->host_dev) {
+		dev_err(&pdev->dev, "Failed registering Host!\n");
+		ret = -ENODEV;
+		goto err_register_host;
+	}
+
+	return 0;
+
+err_register_host:
+err_register_phy:
+	platform_device_unregister(data->phy_dev);
+err_get_host_irq:
+	iounmap(phy_data->mem);
+err_map_phy_mem:
+	iounmap(host_data->mem);
+err_map_host_mem:
+	release_mem_region(phy_data->mem_res->start,
+			resource_size(phy_data->mem_res));
+err_get_phy_mem:
+	release_mem_region(host_data->mem_res->start,
+			resource_size(host_data->mem_res));
+err_get_host_mem:
+	phy_data->mem_res = NULL;
+err_get_phy_resource:
+	host_data->mem_res = NULL;
+err_get_host_resource:
+	clk_unprepare(phy_data->clk);
+err_prepare_phy_clock:
+	clk_unprepare(host_data->clk);
+err_prepare_host_clock:
+	clk_put(phy_data->clk);
+err_claim_phy_clock:
+	clk_put(host_data->clk);
+err_claim_host_clock:
+	kfree(data);
+err_alloc_data:
+	return ret;
+}
+
+static int __devexit imx_usb_remove(struct platform_device *pdev)
+{
+	struct imx_usb *data = platform_get_drvdata(pdev);
+	struct imx_usb_data *host_data, *phy_data;
+
+	host_data = &data->host;
+	phy_data = &data->phy;
+
+	platform_device_unregister(data->host_dev);
+	platform_device_unregister(data->phy_dev);
+
+	iounmap(host_data->mem);
+	iounmap(host_data->mem);
+	release_mem_region(phy_data->mem_res->start,
+			resource_size(phy_data->mem_res));
+	release_mem_region(host_data->mem_res->start,
+			resource_size(host_data->mem_res));
+	phy_data->mem_res = NULL;
+	host_data->mem_res = NULL;
+	clk_unprepare(phy_data->clk);
+	clk_unprepare(host_data->clk);
+	clk_put(phy_data->clk);
+	clk_put(host_data->clk);
+	kfree(data);
+
+	return 0;
+}
+
+static struct platform_driver imx_usb_driver = {
+	.probe		= imx_usb_probe,
+	.remove		= __devexit_p(imx_usb_remove),
+	.driver		= {
+		.name	= "imx-usb",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init imx_usb_init(void)
+{
+	return platform_driver_register(&imx_usb_driver);
+}
+
+static void __exit imx_usb_exit(void)
+{
+	platform_driver_unregister(&imx_usb_driver);
+}
+
+module_init(imx_usb_init);
+module_exit(imx_usb_exit);
+
+MODULE_ALIAS("platform:imx-usb");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX USB composite driver");
+MODULE_LICENSE("GPL");
-- 
1.7.9.5

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

* [PATCH 07/10] MXS: Add USB PHY driver
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (5 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 06/10] MXS: Add composite imx-usb driver Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:07   ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
                     ` (5 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
enables the PHY upon powerup and shuts it down on shutdown.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |   10 +++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  201 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 212 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index e7c6325..1de1495 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -122,6 +122,16 @@ config USB_IMX_COMPOSITE
 	  Composite driver that handles clock and memory mapping for
 	  i.MX USB host and USB PHY.
 
+config USB_MXS_PHY
+	tristate "Freescale i.MX28 USB PHY support"
+	select USB_OTG_UTILS
+	select USB_IMX_COMPOSITE
+	help
+	  Say Y here if you want to build Freescale i.MX28 USB PHY
+	  driver in kernel.
+
+	  To compile this driver as a module, choose M here.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index e3feaca..56700b3 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
 obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-usb.o
+obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
new file mode 100644
index 0000000..3c6c5a2
--- /dev/null
+++ b/drivers/usb/otg/mxs-phy.c
@@ -0,0 +1,201 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb/otg.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#define HW_USBPHY_PWD				0x00
+
+#define HW_USBPHY_CTRL				0x30
+#define HW_USBPHY_CTRL_SET			0x34
+#define HW_USBPHY_CTRL_CLR			0x38
+#define HW_USBPHY_CTRL_TOG			0x3c
+
+#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
+#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
+#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
+#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
+#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
+
+static int phy_init(struct usb_phy *x)
+{
+	struct imx_usb_data *data = x->dev->platform_data;
+	uint32_t val;
+
+	/* Enable clock to the PHY. */
+	clk_enable(data->clk);
+
+	/* Reset the PHY block. */
+	mxs_reset_block(data->mem + HW_USBPHY_CTRL);
+
+	/* Power up the PHY. */
+	writel(0, data->mem + HW_USBPHY_PWD);
+
+	/* Enable FS/LS compatibility and HS disconnection detector. */
+	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
+		BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
+	writel(val, data->mem + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static void phy_shutdown(struct usb_phy *x)
+{
+	struct imx_usb_data *data = x->dev->platform_data;
+
+	/* Gate off the PHY. */
+	writel(BM_USBPHY_CTRL_CLKGATE, data->mem + HW_USBPHY_CTRL_SET);
+
+	/* Disable clock to the PHY. */
+	clk_disable(data->clk);
+}
+
+static int phy_set_vbus(struct usb_otg *otg, bool enabled)
+{
+	struct usb_phy *x = otg->phy;
+	struct imx_usb_data *data = x->dev->platform_data;
+
+	if (enabled)
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			data->mem + HW_USBPHY_CTRL_CLR);
+	else
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			data->mem + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static int __devinit mxs_phy_probe(struct platform_device *pdev)
+{
+	struct imx_usb_data *data = pdev->dev.platform_data;
+	struct usb_phy *phy;
+	int ret;
+
+	if (!data) {
+		dev_err(&pdev->dev, "USB PHY platform data missing!\n");
+		return -ENODEV;
+	}
+
+	/* Allocate PHY driver's private date. */
+	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
+		ret = -ENOMEM;
+		goto err_alloc_phy;
+
+	}
+
+	phy->otg = kzalloc(sizeof(*phy->otg), GFP_KERNEL);
+	if (!phy->otg) {
+		dev_err(&pdev->dev, "Failed to allocate USB OTG structure!\n");
+		ret = -ENOMEM;
+		goto err_alloc_otg;
+	}
+
+	/* Setup the PHY structures. */
+	phy->dev		= &pdev->dev;
+	phy->label		= "mxs-usb-phy";
+	phy->init		= phy_init;
+	phy->shutdown		= phy_shutdown;
+	phy->state		= OTG_STATE_A_HOST;
+
+	phy->otg->phy		= phy;
+	phy->otg->set_vbus	= phy_set_vbus;
+
+	platform_set_drvdata(pdev, phy);
+
+	ATOMIC_INIT_NOTIFIER_HEAD(&phy->notifier);
+
+	/* Register the transceiver with kernel. */
+	ret = usb_set_transceiver(phy);
+	if (ret) {
+		dev_err(&pdev->dev, "Can't register transceiver, (%d)\n", ret);
+		goto err_set_transceiver;
+	}
+
+	return 0;
+
+err_set_transceiver:
+	platform_set_drvdata(pdev, NULL);
+	kfree(phy->otg);
+err_alloc_otg:
+	kfree(phy);
+err_alloc_phy:
+	return ret;
+}
+
+static int __devexit mxs_phy_remove(struct platform_device *pdev)
+{
+	struct imx_usb_data *data = pdev->dev.platform_data;
+	struct usb_phy *phy = platform_get_drvdata(pdev);
+
+	/* Power down the PHY. */
+	phy_shutdown(phy);
+
+	/* Stop the PHY clock. */
+	clk_disable(data->clk);
+
+	/* Free the rest. */
+	usb_set_transceiver(NULL);
+	platform_set_drvdata(pdev, NULL);
+	kfree(phy);
+
+	return 0;
+}
+
+static struct platform_driver mxs_phy_driver = {
+	.probe		= mxs_phy_probe,
+	.remove		= __devexit_p(mxs_phy_remove),
+	.driver		= {
+		.name	= "mxs-usb-phy",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mxs_phy_init(void)
+{
+	return platform_driver_register(&mxs_phy_driver);
+}
+
+static void __exit mxs_phy_exit(void)
+{
+	platform_driver_unregister(&mxs_phy_driver);
+}
+
+module_init(mxs_phy_init);
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
-- 
1.7.9.5

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (6 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  7:01     ` Chen Peter-B29397
  2012-04-18  2:07   ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
                     ` (4 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to keep
this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
though eventually these two might be merged.

NOTE: I still haven't figured out how to enable/disable the disconnection
detector, it can't be enabled all the time, so I toggle PHY stuff from this
driver, which I doubt is correct.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/host/Kconfig    |    7 ++
 drivers/usb/host/ehci-hcd.c |    5 +
 drivers/usb/host/ehci-mxs.c |  254 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+)
 create mode 100644 drivers/usb/host/ehci-mxs.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f788eb8..85ed593 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -148,6 +148,13 @@ config USB_EHCI_MXC
 	---help---
 	  Variation of ARC USB block used in some Freescale chips.
 
+config USB_EHCI_MXS
+	bool "Support for Freescale i.MX28 on-chip EHCI USB controller"
+	depends on USB_EHCI_HCD && ARCH_MXS
+	select USB_EHCI_ROOT_HUB_TT
+	---help---
+	  Enable USB support for i.MX28.
+
 config USB_EHCI_HCD_OMAP
 	bool "EHCI support for OMAP3 and later chips"
 	depends on USB_EHCI_HCD && ARCH_OMAP
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 806cc95..d0df8be 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1263,6 +1263,11 @@ MODULE_LICENSE ("GPL");
 #define PLATFORM_DRIVER		ehci_mxc_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_MXS
+#include "ehci-mxs.c"
+#define PLATFORM_DRIVER		ehci_mxs_driver
+#endif
+
 #ifdef CONFIG_USB_EHCI_SH
 #include "ehci-sh.c"
 #define PLATFORM_DRIVER		ehci_hcd_sh_driver
diff --git a/drivers/usb/host/ehci-mxs.c b/drivers/usb/host/ehci-mxs.c
new file mode 100644
index 0000000..47e6502
--- /dev/null
+++ b/drivers/usb/host/ehci-mxs.c
@@ -0,0 +1,254 @@
+/*
+ * Freescale i.MX28 EHCI driver
+ *
+ * Copyright (c) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * Based on MXC EHCI driver:
+ *
+ * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
+ * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, 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,
+ * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/slab.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#include <asm/mach-types.h>
+
+#define MXC_EHCI_MODE_ULPI	(2 << 30)
+
+/* Called during probe() after chip reset completes */
+static int ehci_mxs_setup(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	int retval;
+
+	dbg_hcs_params(ehci, "reset");
+	dbg_hcc_params(ehci, "reset");
+
+	/* Cache this readonly data; minimize chip reads. */
+	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
+
+	hcd->has_tt = 1;
+
+	retval = ehci_halt(ehci);
+	if (retval)
+		return retval;
+
+	/* Data structure init. */
+	retval = ehci_init(hcd);
+	if (retval)
+		return retval;
+
+	ehci->sbrn = 0x20;
+
+	ehci_reset(ehci);
+
+	ehci_port_power(ehci, 0);
+
+	return 0;
+}
+
+static irqreturn_t mxs_ehci_irq(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	struct usb_phy *phy = usb_get_transceiver();
+	uint32_t status;
+	static uint32_t discon;
+
+	if (phy && phy->otg && phy->otg->set_vbus) {
+		status = ehci_readl(ehci, &ehci->regs->status);
+		status = !!(status & STS_PCD);
+		if (status != discon) {
+			discon = status;
+			phy->otg->set_vbus(phy->otg, status);
+		}
+	}
+
+	return ehci_irq(hcd);
+}
+
+static const struct hc_driver ehci_mxs_hc_driver = {
+	.description	= hcd_name,
+	.product_desc	= "Freescale i.MX28 On-Chip EHCI Host Controller",
+	.hcd_priv_size	= sizeof(struct ehci_hcd),
+
+	/*
+	 * Generic hardware linkage
+	 */
+	.irq		= mxs_ehci_irq,
+	.flags		= HCD_USB2 | HCD_MEMORY,
+
+	/*
+	 * Basic lifecycle operations
+	 */
+	.reset		= ehci_mxs_setup,
+	.start		= ehci_run,
+	.stop		= ehci_stop,
+	.shutdown	= ehci_shutdown,
+
+	/*
+	 * managing i/o requests and associated device resources
+	 */
+	.urb_enqueue		= ehci_urb_enqueue,
+	.urb_dequeue		= ehci_urb_dequeue,
+	.endpoint_disable	= ehci_endpoint_disable,
+	.endpoint_reset		= ehci_endpoint_reset,
+
+	/*
+	 * scheduling support
+	 */
+	.get_frame_number	= ehci_get_frame,
+
+	/*
+	 * root hub support
+	 */
+	.hub_status_data	= ehci_hub_status_data,
+	.hub_control		= ehci_hub_control,
+	.bus_suspend		= ehci_bus_suspend,
+	.bus_resume		= ehci_bus_resume,
+	.relinquish_port	= ehci_relinquish_port,
+	.port_handed_over	= ehci_port_handed_over,
+
+	.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
+};
+
+static int ehci_mxs_drv_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct imx_usb_data *data = pdev->dev.platform_data;
+	struct usb_hcd *hcd;
+	struct ehci_hcd *ehci;
+	struct usb_phy *phy;
+	int ret;
+
+	dev_info(dev, "Initializing i.MX28 USB Controller\n");
+
+	if (!data) {
+		dev_err(dev, "USB Host platform data missing!\n");
+		return -ENODEV;
+	}
+
+	/* Create HCD controller instance. */
+	hcd = usb_create_hcd(&ehci_mxs_hc_driver, dev, dev_name(dev));
+	if (!hcd) {
+		dev_err(dev, "Failed to create HCD instance!\n");
+		return -ENOMEM;
+	}
+
+	hcd->rsrc_start = data->mem_res->start;
+	hcd->rsrc_len = resource_size(data->mem_res);
+	hcd->regs = data->mem;
+
+	clk_enable(data->clk);
+
+	/* Wait for the controller to stabilize. */
+	mdelay(10);
+
+	/* Initialize the transceiver */
+#ifdef CONFIG_USB_OTG_UTILS
+	phy = usb_get_transceiver();
+	if (!phy) {
+		dev_err(dev, "Unable to find transceiver.\n");
+		ret = -ENODEV;
+		goto err_phy;
+	}
+
+	ret = usb_phy_init(phy);
+	if (ret < 0) {
+		dev_err(dev, "Unable init transceiver\n");
+		ret = -ENODEV;
+		goto err_phy_init;
+	}
+#else
+	dev_info(dev, "USB_MXS_PHY must have CONFIG_USB_OTG_UTILS enabled\n");
+	goto err_phy;
+#endif
+
+	ehci = hcd_to_ehci(hcd);
+
+	/* EHCI registers start@offset 0x100 */
+	ehci->caps = hcd->regs + 0x100;
+	ehci->regs = hcd->regs + 0x100 +
+		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
+
+	/* Set up the PORTSCx register */
+	ehci_writel(ehci, MXC_EHCI_MODE_ULPI, &ehci->regs->port_status[0]);
+
+	platform_set_drvdata(pdev, hcd);
+
+	ret = usb_add_hcd(hcd, data->irq, IRQF_SHARED);
+	if (ret)
+		goto err_phy_init;
+
+	return 0;
+
+err_phy_init:
+#ifdef CONFIG_USB_OTG_UTILS
+	if (phy)
+		usb_put_transceiver(phy);
+#endif
+err_phy:
+	clk_disable(data->clk);
+	usb_put_hcd(hcd);
+	return ret;
+}
+
+static int __exit ehci_mxs_drv_remove(struct platform_device *pdev)
+{
+	struct imx_usb_data *data = pdev->dev.platform_data;
+	struct usb_hcd *hcd = platform_get_drvdata(pdev);
+	struct usb_phy *phy = usb_get_transceiver();
+
+	if (phy)
+		usb_phy_shutdown(phy);
+
+	usb_remove_hcd(hcd);
+	usb_put_hcd(hcd);
+	platform_set_drvdata(pdev, NULL);
+	clk_disable(data->clk);
+
+	return 0;
+}
+
+static void ehci_mxs_drv_shutdown(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd = platform_get_drvdata(pdev);
+
+	if (hcd->driver->shutdown)
+		hcd->driver->shutdown(hcd);
+}
+
+static struct platform_driver ehci_mxs_driver = {
+	.probe		= ehci_mxs_drv_probe,
+	.remove		= __exit_p(ehci_mxs_drv_remove),
+	.shutdown	= ehci_mxs_drv_shutdown,
+	.driver		= {
+		   .name	= "mxs-ehci",
+	},
+};
+
+MODULE_ALIAS("platform:mxs-ehci");
-- 
1.7.9.5

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

* [PATCH 09/10] MXS: Enable USB on M28EVK
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (7 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18 12:08     ` Sergei Shtylyov
  2012-04-18  2:07   ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
                     ` (3 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

Enable the second USB port on M28EVK board.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig       |    2 ++
 arch/arm/mach-mxs/mach-m28evk.c |    9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index 9dbf29f..5b5566c 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -83,6 +83,8 @@ config MODULE_M28
 	select MXS_HAVE_PLATFORM_MXS_LRADC
 	select MXS_HAVE_PLATFORM_MXS_MMC
 	select MXS_HAVE_PLATFORM_MXSFB
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 
 config MODULE_APX4
diff --git a/arch/arm/mach-mxs/mach-m28evk.c b/arch/arm/mach-mxs/mach-m28evk.c
index f32fadb..ecdb0ff 100644
--- a/arch/arm/mach-mxs/mach-m28evk.c
+++ b/arch/arm/mach-mxs/mach-m28evk.c
@@ -212,6 +212,11 @@ static const iomux_cfg_t m28evk_pads[] __initconst = {
 
 	/* Backlight */
 	MX28_PAD_PWM3__GPIO_3_28 | MXS_PAD_CTRL,
+
+	/* USB */
+	MX28_PAD_SSP2_SS1__USB1_OVERCURRENT,
+	MX28_PAD_AUART3_TX__GPIO_3_13 |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
 };
 
 /* led */
@@ -377,6 +382,10 @@ static void __init m28evk_init(void)
 	mx28_add_ts(&touch_pdata);
 
 	mx28_add_gpmi_nand(&m28evk_gpmi_nand_data);
+
+	gpio_request_one(MXS_GPIO_NR(3, 13), GPIOF_OUT_INIT_LOW, "USB Power");
+
+	mx28_add_mxs_usbh(1);
 }
 
 static void __init m28evk_timer_init(void)
-- 
1.7.9.5

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

* [PATCH 10/10] MXS: Enable USB on MX28EVK
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (8 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-18  2:07   ` Marek Vasut
  2012-04-18  2:09   ` [RFC PATCH 00/10 V2] MXS: Add i.MX28 USB Host driver Marek Vasut
                     ` (2 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:07 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig        |    2 ++
 arch/arm/mach-mxs/mach-mx28evk.c |   10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index 5b5566c..696e1d1 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -53,6 +53,8 @@ config MACH_MX28EVK
 	select MXS_HAVE_PLATFORM_MXS_SAIF
 	select MXS_HAVE_PLATFORM_MXS_I2C
 	select MXS_HAVE_PLATFORM_RTC_STMP3XXX
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 	help
 	  Include support for MX28EVK platform. This includes specific
diff --git a/arch/arm/mach-mxs/mach-mx28evk.c b/arch/arm/mach-mxs/mach-mx28evk.c
index e386c14..8bdd416 100644
--- a/arch/arm/mach-mxs/mach-mx28evk.c
+++ b/arch/arm/mach-mxs/mach-mx28evk.c
@@ -37,6 +37,7 @@
 #define MX28EVK_BL_ENABLE	MXS_GPIO_NR(3, 18)
 #define MX28EVK_LCD_ENABLE	MXS_GPIO_NR(3, 30)
 #define MX28EVK_FEC_PHY_RESET	MXS_GPIO_NR(4, 13)
+#define MX28EVK_USB1_PWR_EN	MXS_GPIO_NR(3, 8)
 
 #define MX28EVK_MMC0_WRITE_PROTECT	MXS_GPIO_NR(2, 12)
 #define MX28EVK_MMC1_WRITE_PROTECT	MXS_GPIO_NR(0, 28)
@@ -186,6 +187,8 @@ static const iomux_cfg_t mx28evk_pads[] __initconst = {
 
 	/* led */
 	MX28_PAD_AUART1_TX__GPIO_3_5 | MXS_PAD_CTRL,
+	/* usb1 */
+	MX28_PAD_AUART2_RX__GPIO_3_8 | MXS_PAD_CTRL,
 
 	/* I2C */
 	MX28_PAD_I2C0_SCL__I2C0_SCL |
@@ -451,6 +454,13 @@ static void __init mx28evk_init(void)
 	mx28_add_mxs_mmc(0, &mx28evk_mmc_pdata[0]);
 	mx28_add_mxs_mmc(1, &mx28evk_mmc_pdata[1]);
 
+	ret = gpio_request_one(MX28EVK_USB1_PWR_EN, GPIOF_OUT_INIT_HIGH,
+				"usb1-power-en");
+	if (ret)
+		pr_warn("failed to request gpio usb1-power-en %d\n", ret);
+
+	mx28_add_mxs_usbh(1);
+
 	mx28_add_rtc_stmp3xxx();
 
 	gpio_led_register_device(0, &mx28evk_led_data);
-- 
1.7.9.5

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

* [RFC PATCH 00/10 V2]  MXS: Add i.MX28 USB Host driver
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (9 preceding siblings ...)
  2012-04-18  2:07   ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
@ 2012-04-18  2:09   ` Marek Vasut
  2012-04-18  7:52   ` Chen Peter-B29397
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18  2:09 UTC (permalink / raw)
  To: linux-arm-kernel

> This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
> generic USB PHY infrastructure.
> 
> V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> drivers.
> 
> Marek Vasut (10):
>   MXS: Make clk_disable return integer
>   MXS: Add USB EHCI and USB PHY clock handling
>   MXS: Fixup i.MX233 USB base address name
>   MXS: Add data shared between imx-usb, PHY and EHCI driver
>   MXS: Add platform registration hooks for USB EHCI
>   MXS: Add composite imx-usb driver
>   MXS: Add USB PHY driver
>   MXS: Add separate MXS EHCI HCD driver
>   MXS: Enable USB on M28EVK
>   MXS: Enable USB on MX28EVK
> 
>  arch/arm/mach-mxs/Kconfig                       |    4 +
>  arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
>  arch/arm/mach-mxs/devices-mx28.h                |    4 +
>  arch/arm/mach-mxs/devices/Kconfig               |    3 +
>  arch/arm/mach-mxs/devices/Makefile              |    1 +
>  arch/arm/mach-mxs/devices/platform-usb.c        |   67 +++++
>  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
>  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
>  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
>  arch/arm/mach-mxs/mach-m28evk.c                 |    9 +
>  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
>  drivers/usb/host/Kconfig                        |    7 +
>  drivers/usb/host/ehci-hcd.c                     |    5 +
>  drivers/usb/host/ehci-mxs.c                     |  254 +++++++++++++++++++
>  drivers/usb/otg/Kconfig                         |   16 ++
>  drivers/usb/otg/Makefile                        |    2 +
>  drivers/usb/otg/imx-usb.c                       |  303
> +++++++++++++++++++++++ drivers/usb/otg/mxs-phy.c                       | 
> 201 +++++++++++++++ include/linux/fsl_devices.h                     |   15
> ++
>  19 files changed, 939 insertions(+), 9 deletions(-)
>  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
>  create mode 100644 drivers/usb/host/ehci-mxs.c
>  create mode 100644 drivers/usb/otg/imx-usb.c
>  create mode 100644 drivers/usb/otg/mxs-phy.c
> 
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>

Ok guys, you can tear me apart on this another round of patchset ... I'll be 
having some sleep while you do so ;-)

Best regards,
Marek Vasut

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 11:29 ` Sascha Hauer
  2012-04-17 11:45   ` Marek Vasut
  2012-04-17 12:36   ` Heikki Krogerus
@ 2012-04-18  4:31   ` Chen Peter-B29397
  2012-04-18  7:40     ` Sascha Hauer
  2 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-18  4:31 UTC (permalink / raw)
  To: linux-arm-kernel

 
> 
> Your patches won't work when more than one USB port is enabled because
> of the singular usb transceiver present in the kernel. That of course is
> not your fault. I think Heikki (Added to Cc) is working on this issue,
> but I don't know the status here.
> 
> Another problem is that what you are doing does not integrate at all
> with otg. I don't ask you to implement otg support because you are
> likely not interested in this, but since you are adding a new ehci
> glue driver anyway I suggest another approach:
> 
> Put a driver under drivers/usb/otg which:
> 
> - matches a 'imx-usb' device
> - gets/enables all clocks needed for USB
> - finds the transceiver
> - registers a ehci device
> 
> Future additions would be:
> 
> - Put a USB_MODE_HOST/DEVICE flag into platform_data, and register a
>   host or gadget driver depending on this flag
> - Add a USB_MODE_OTG flag to platform_data and implement otg in this
>   driver (or use whatever infrastructure present in the kernel then)
> 
> This is similar to what msm does. This way we have the clocks and phys
> handled where they are needed. We may use this code on i.MX later.
> 
> We did this wrong on i.MX (and several other architectures) and getting
> this right will be hard work. No need to introduce the same flaws again
> with a new architecture.
> 
Hi Sascha,

We have been discussing i.mx usb re-structure at freescale internal during
this periods, one side does not agree with otg driver manages PHY/clock
solution due to below reasons:

- May confuse the users who only use device or host function, the users may
double "why I need to include otg file to support device/host only function"?
 
- For some special cases, like device sends resume signal(remote wakeup)
after host suspend, but before otg suspend (system needs to refuse to suspend) .
It needs to add hcd flag to judge if there is a remote wakeup after host suspend, 
and if the port is sending resume signal now (when the port is sending resume signal, 
we can't put power to low power mode). Is it suitable to put some hcd stuffs at otg driver?

- Any disadvantages three individual drivers manage PHY/clock separately after the generic PHY
layer/FSL PHY driver have finished? It can define where to get/put PHY/clock operation at
individual drivers clearly. When OTG switch, for host mode, the hcd struct (includes interrupt)
will be free/created using usb_remove_hcd/usb_add_hcd, for device mode, 
we can deinit/init udc like current ci13xxx_udc.c at ci13xxx_vbus_session does. 

> Sascha
> 
> --
> Pengutronix e.K.                           |
> |
> Industrial Linux Solutions                 | http://www.pengutronix.de/
> |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0
> |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555
> |

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18  2:07   ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-18  7:01     ` Chen Peter-B29397
  2012-04-18  8:40       ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-18  7:01 UTC (permalink / raw)
  To: linux-arm-kernel



 
> 
> This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to
> keep
> this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
> though eventually these two might be merged.
> 
As mxc and mxs platforms use the same USB controller (chipidea's), I wonder if
you can use ehci-mxc, or change name from ehci-mxc to ehci-imx?
Sascha, what's your opinion?

> NOTE: I still haven't figured out how to enable/disable the disconnection
> detector, it can't be enabled all the time, so I toggle PHY stuff from
> this
> driver, which I doubt is correct.
For HS disconnect detector, please use like below:
- When there is no device at port, disable it
- When there is a device on the port, enable it
- When bus suspend occurs, disable it
- When bus resume has finishes, enable it.

 
> +	/* Set up the PORTSCx register */
> +	ehci_writel(ehci, MXC_EHCI_MODE_ULPI, &ehci->regs->port_status[0]);
It is UTMI PHY, why you use ULPI mode?

 

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-17 20:29       ` Marek Vasut
@ 2012-04-18  7:02         ` Sascha Hauer
  2012-04-18  8:05           ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18  7:02 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Apr 17, 2012 at 10:29:21PM +0200, Marek Vasut wrote:
> > > 
> > > So the PHY actually registers the EHCI driver (plat_bus->phy->ehci)?
> > > That's slightly weird, don't you think?
> > 
> > Your hardware device is a device consisting of a ehci core and a USB device
> > core. Currently we register the child devices independently which leads
> > to the mentioned problems. Instead we should register the USB core as a
> > whole and pass the resources to either the client or the host driver.
> 
> Ok, giving it a second thought -- you mean to create "stub" driver, which claims 
> and toggles the clock _and_ registers both the EHCI host driver and PHY driver 
> under itself in the hierarchy. Is that correct?

No, the registration of the phy is fine the way it is. The stub driver
should only register the ehci and the usb device. Maybe some pseudo code
helps describing what I mean:

arch/arm/mach-mxs:

	mx28_register_usbphy0();
	mx28_register_usb0();

drivers/usb/otg/mxs-otg.c:

	probe() {
		clk_get();
		clk_prepare_enable();

		usb_get_phy(&pdev->dev);

		if (pdata->mode == USB_OTG_MODE_HOST)
			usb_add_hcd(priv->host);
		else
			usb_gadget_vbus_connect(priv->gadget);
	}

	module_platform_driver(mxs_otg_driver);

drivers/usb/otg/mxs-otg-phy.c:

	probe() {
		clk_get();
		clk_prepare_enable();
		usb_register_phy(phy, "mxs-otg.0");
	}

	module_platform_driver(mxs_otg_phy_driver);


The mxs-otg part can be reused on i.MX aswell, whereas mxs-otg-phy is
mxs (and i.MX6 how we just learned) specific.
What currently is missing is a usb_get_phy() with a device argument to
get the phy specific to a device. That's a problem, but you currently
have it aswell with your current approach

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-18  4:31   ` Chen Peter-B29397
@ 2012-04-18  7:40     ` Sascha Hauer
  2012-04-20 13:10       ` 答复: " Liu JunJie-B08287
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18  7:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 18, 2012 at 04:31:50AM +0000, Chen Peter-B29397 wrote:
>  
> > 
> > Your patches won't work when more than one USB port is enabled because
> > of the singular usb transceiver present in the kernel. That of course is
> > not your fault. I think Heikki (Added to Cc) is working on this issue,
> > but I don't know the status here.
> > 
> > Another problem is that what you are doing does not integrate at all
> > with otg. I don't ask you to implement otg support because you are
> > likely not interested in this, but since you are adding a new ehci
> > glue driver anyway I suggest another approach:
> > 
> > Put a driver under drivers/usb/otg which:
> > 
> > - matches a 'imx-usb' device
> > - gets/enables all clocks needed for USB
> > - finds the transceiver
> > - registers a ehci device
> > 
> > Future additions would be:
> > 
> > - Put a USB_MODE_HOST/DEVICE flag into platform_data, and register a
> >   host or gadget driver depending on this flag
> > - Add a USB_MODE_OTG flag to platform_data and implement otg in this
> >   driver (or use whatever infrastructure present in the kernel then)
> > 
> > This is similar to what msm does. This way we have the clocks and phys
> > handled where they are needed. We may use this code on i.MX later.
> > 
> > We did this wrong on i.MX (and several other architectures) and getting
> > this right will be hard work. No need to introduce the same flaws again
> > with a new architecture.
> > 
> Hi Sascha,
> 
> We have been discussing i.mx usb re-structure at freescale internal during
> this periods, one side does not agree with otg driver manages PHY/clock
> solution due to below reasons:
> 
> - May confuse the users who only use device or host function, the users may
> double "why I need to include otg file to support device/host only function"?

I can't find anything confusing in this.

>  
> - For some special cases, like device sends resume signal(remote wakeup)
> after host suspend, but before otg suspend (system needs to refuse to suspend) .
> It needs to add hcd flag to judge if there is a remote wakeup after host suspend, 
> and if the port is sending resume signal now (when the port is sending resume signal, 
> we can't put power to low power mode). Is it suitable to put some hcd stuffs at otg driver?

I can't follow you here what the actual problem is, but since the otg
driver is the driver for host and gadget (which happens to pass control to
either the host or the gadget driver most of the time) it is ok to do
whatever it takes in the otg driver to make it work.

> 
> - Any disadvantages three individual drivers manage PHY/clock separately after the generic PHY
> layer/FSL PHY driver have finished? It can define where to get/put PHY/clock operation at
> individual drivers clearly. When OTG switch, for host mode, the hcd struct (includes interrupt)
> will be free/created using usb_remove_hcd/usb_add_hcd, for device mode, 
> we can deinit/init udc like current ci13xxx_udc.c at ci13xxx_vbus_session does. 

I once made a quick hack using the msm otg driver on i.MX. I had to
comment out some msm specifics but after that it worked quite well.

Sascga

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 00/10 V2]  MXS: Add i.MX28 USB Host driver
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (10 preceding siblings ...)
  2012-04-18  2:09   ` [RFC PATCH 00/10 V2] MXS: Add i.MX28 USB Host driver Marek Vasut
@ 2012-04-18  7:52   ` Chen Peter-B29397
  2012-04-18 17:49     ` Marek Vasut
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
  12 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-18  7:52 UTC (permalink / raw)
  To: linux-arm-kernel


 
> This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> the
> generic USB PHY infrastructure.
> 
> V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> drivers.
> 

- Currently, there is no generic PHY layer, so only one host/device can be supported.

- Now, the PHY and OTG is separated, it is better to put PHY driver to
drivers/usb/phy/

- mx23, mx28, mx6q uses the same PHY (FSL PHY), it is better to use the phy driver name
as imx-phy.c.

> Marek Vasut (10):
>   MXS: Make clk_disable return integer
>   MXS: Add USB EHCI and USB PHY clock handling
>   MXS: Fixup i.MX233 USB base address name
>   MXS: Add data shared between imx-usb, PHY and EHCI driver
>   MXS: Add platform registration hooks for USB EHCI
>   MXS: Add composite imx-usb driver
>   MXS: Add USB PHY driver
>   MXS: Add separate MXS EHCI HCD driver
>   MXS: Enable USB on M28EVK
>   MXS: Enable USB on MX28EVK
> 
>  arch/arm/mach-mxs/Kconfig                       |    4 +
>  arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
>  arch/arm/mach-mxs/devices-mx28.h                |    4 +
>  arch/arm/mach-mxs/devices/Kconfig               |    3 +
>  arch/arm/mach-mxs/devices/Makefile              |    1 +
>  arch/arm/mach-mxs/devices/platform-usb.c        |   67 +++++
>  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
>  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
>  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
>  arch/arm/mach-mxs/mach-m28evk.c                 |    9 +
>  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
>  drivers/usb/host/Kconfig                        |    7 +
>  drivers/usb/host/ehci-hcd.c                     |    5 +
>  drivers/usb/host/ehci-mxs.c                     |  254
> +++++++++++++++++++
>  drivers/usb/otg/Kconfig                         |   16 ++
>  drivers/usb/otg/Makefile                        |    2 +
>  drivers/usb/otg/imx-usb.c                       |  303
> +++++++++++++++++++++++
>  drivers/usb/otg/mxs-phy.c                       |  201 +++++++++++++++
>  include/linux/fsl_devices.h                     |   15 ++
>  19 files changed, 939 insertions(+), 9 deletions(-)
>  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
>  create mode 100644 drivers/usb/host/ehci-mxs.c
>  create mode 100644 drivers/usb/otg/imx-usb.c
>  create mode 100644 drivers/usb/otg/mxs-phy.c
> 
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> --
> 1.7.9.5
> 

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

* [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-18  7:02         ` Sascha Hauer
@ 2012-04-18  8:05           ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-18  8:05 UTC (permalink / raw)
  To: linux-arm-kernel

 
> 
> On Tue, Apr 17, 2012 at 10:29:21PM +0200, Marek Vasut wrote:
> > > >
> > > > So the PHY actually registers the EHCI driver (plat_bus->phy->ehci)?
> > > > That's slightly weird, don't you think?
> > >
> > > Your hardware device is a device consisting of a ehci core and a USB
> device
> > > core. Currently we register the child devices independently which
> leads
> > > to the mentioned problems. Instead we should register the USB core as
> a
> > > whole and pass the resources to either the client or the host driver.
> >
> > Ok, giving it a second thought -- you mean to create "stub" driver,
> which claims
> > and toggles the clock _and_ registers both the EHCI host driver and PHY
> driver
> > under itself in the hierarchy. Is that correct?
> 
> No, the registration of the phy is fine the way it is. The stub driver
> should only register the ehci and the usb device. Maybe some pseudo code
> helps describing what I mean:
> 
> arch/arm/mach-mxs:
> 
> 	mx28_register_usbphy0();
> 	mx28_register_usb0();
> 
> drivers/usb/otg/mxs-otg.c:
> 
> 	probe() {
> 		clk_get();
> 		clk_prepare_enable();
> 
> 		usb_get_phy(&pdev->dev);
> 
> 		if (pdata->mode == USB_OTG_MODE_HOST)
> 			usb_add_hcd(priv->host);
> 		else
> 			usb_gadget_vbus_connect(priv->gadget);
> 	}
> 
> 	module_platform_driver(mxs_otg_driver);
> 
> drivers/usb/otg/mxs-otg-phy.c:
> 
> 	probe() {
> 		clk_get();
> 		clk_prepare_enable();
> 		usb_register_phy(phy, "mxs-otg.0");
> 	}
> 
> 	module_platform_driver(mxs_otg_phy_driver);
> 
A similar file is drivers/usb/host/fsl-mph-dr-of.c.

> 
> The mxs-otg part can be reused on i.MX aswell, whereas mxs-otg-phy is
> mxs (and i.MX6 how we just learned) specific.
> What currently is missing is a usb_get_phy() with a device argument to
> get the phy specific to a device. That's a problem, but you currently
> have it aswell with your current approach
> 
As there are many things need to do, how about finish PHY layer first,
then the OTG driver part. After PHY layer and FSL PHY driver finish, the both
ports at i.mx28 can be used, and the operation mode (device or host) can
be decided by platform code.
 
> Sascha
> 
> --
> Pengutronix e.K.                           |
> |
> Industrial Linux Solutions                 | http://www.pengutronix.de/
> |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0
> |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555
> |

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18  7:01     ` Chen Peter-B29397
@ 2012-04-18  8:40       ` Sascha Hauer
  2012-04-18  9:18         ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18  8:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 18, 2012 at 07:01:07AM +0000, Chen Peter-B29397 wrote:
> 
> 
>  
> > 
> > This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to
> > keep
> > this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
> > though eventually these two might be merged.
> > 
> As mxc and mxs platforms use the same USB controller (chipidea's), I wonder if
> you can use ehci-mxc, or change name from ehci-mxc to ehci-imx?
> Sascha, what's your opinion?

Maybe better ehci-imx. I think it's a good idea to not use the ehci-mxc
glue code but instead write a mxs specific glue code with having in
mind that later we want to drop ehci-mxc and use ehci-imx for all imx
including mxs. This assumes the USB folks are ok with this, I don't
know.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18  8:40       ` Sascha Hauer
@ 2012-04-18  9:18         ` Chen Peter-B29397
  2012-04-18  9:45           ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-18  9:18 UTC (permalink / raw)
  To: linux-arm-kernel


 
> > >
> > > This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I
> tried to
> > > keep
> > > this separate from the MXC EHCI to avoid further polution of the MXC
> EHCI,
> > > though eventually these two might be merged.
> > >
> > As mxc and mxs platforms use the same USB controller (chipidea's), I
> wonder if
> > you can use ehci-mxc, or change name from ehci-mxc to ehci-imx?
> > Sascha, what's your opinion?
> 
> Maybe better ehci-imx. I think it's a good idea to not use the ehci-mxc
> glue code but instead write a mxs specific glue code with having in
> mind that later we want to drop ehci-mxc and use ehci-imx for all imx
> including mxs. This assumes the USB folks are ok with this, I don't
> know.
> 
How about create a patch changing name from ehci-mxc to ehci-imx first, then add
mx28/mx23/mx6q host ehci driver. I can do it.

> Sascha
> 
> --
> Pengutronix e.K.                           |
> |
> Industrial Linux Solutions                 | http://www.pengutronix.de/
> |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0
> |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555
> |

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18  9:18         ` Chen Peter-B29397
@ 2012-04-18  9:45           ` Sascha Hauer
  2012-04-19  2:54             ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18  9:45 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 18, 2012 at 09:18:23AM +0000, Chen Peter-B29397 wrote:
> 
>  
> > > >
> > > > This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I
> > tried to
> > > > keep
> > > > this separate from the MXC EHCI to avoid further polution of the MXC
> > EHCI,
> > > > though eventually these two might be merged.
> > > >
> > > As mxc and mxs platforms use the same USB controller (chipidea's), I
> > wonder if
> > > you can use ehci-mxc, or change name from ehci-mxc to ehci-imx?
> > > Sascha, what's your opinion?
> > 
> > Maybe better ehci-imx. I think it's a good idea to not use the ehci-mxc
> > glue code but instead write a mxs specific glue code with having in
> > mind that later we want to drop ehci-mxc and use ehci-imx for all imx
> > including mxs. This assumes the USB folks are ok with this, I don't
> > know.
> > 
> How about create a patch changing name from ehci-mxc to ehci-imx first, then add
> mx28/mx23/mx6q host ehci driver. I can do it.

ehci-imx won't need clock handling and it won't need phy handling. Also
the setup of the portsc register won't be in the new driver. The
clk_get(dev, "usb_phy1") part is horribly broken anyway. It's more than
just a rename.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 09/10] MXS: Enable USB on M28EVK
  2012-04-18  2:07   ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-18 12:08     ` Sergei Shtylyov
  2012-04-18 12:24       ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sergei Shtylyov @ 2012-04-18 12:08 UTC (permalink / raw)
  To: linux-arm-kernel

Hello.

On 18-04-2012 6:07, Marek Vasut wrote:

> Enable the second USB port on M28EVK board.

> Signed-off-by: Marek Vasut<marex@denx.de>
> Cc: Chen Peter-B29397<B29397@freescale.com>
> Cc: Detlev Zundel<dzu@denx.de>
> Cc: Fabio Estevam<festevam@gmail.com>
> Cc: Li Frank-B20596<B20596@freescale.com>
> Cc: Lin Tony-B19295<B19295@freescale.com>
> Cc: Linux USB<linux-usb@vger.kernel.org>
> Cc: Sascha Hauer<s.hauer@pengutronix.de>
> Cc: Shawn Guo<shawn.guo@freescale.com>
> Cc: Shawn Guo<shawn.guo@linaro.org>
> Cc: Stefano Babic<sbabic@denx.de>
> Cc: Subodh Nijsure<snijsure@grid-net.com>
> Cc: Tony Lin<tony.lin@freescale.com>
> Cc: Wolfgang Denk<wd@denx.de>
> ---
>   arch/arm/mach-mxs/Kconfig       |    2 ++
>   arch/arm/mach-mxs/mach-m28evk.c |    9 +++++++++
>   2 files changed, 11 insertions(+)

> diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
> index 9dbf29f..5b5566c 100644
> --- a/arch/arm/mach-mxs/Kconfig
> +++ b/arch/arm/mach-mxs/Kconfig
[...]
> @@ -377,6 +382,10 @@ static void __init m28evk_init(void)
>   	mx28_add_ts(&touch_pdata);
>
>   	mx28_add_gpmi_nand(&m28evk_gpmi_nand_data);
> +
> +	gpio_request_one(MXS_GPIO_NR(3, 13), GPIOF_OUT_INIT_LOW, "USB Power");

    Still can fail, and you don't handle it (unlike the next patch).

WBR, Sergei

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

* [PATCH 09/10] MXS: Enable USB on M28EVK
  2012-04-18 12:08     ` Sergei Shtylyov
@ 2012-04-18 12:24       ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 12:24 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sergei Shtylyov,

> Hello.
> 
> On 18-04-2012 6:07, Marek Vasut wrote:
> > Enable the second USB port on M28EVK board.
> > 
> > Signed-off-by: Marek Vasut<marex@denx.de>
> > Cc: Chen Peter-B29397<B29397@freescale.com>
> > Cc: Detlev Zundel<dzu@denx.de>
> > Cc: Fabio Estevam<festevam@gmail.com>
> > Cc: Li Frank-B20596<B20596@freescale.com>
> > Cc: Lin Tony-B19295<B19295@freescale.com>
> > Cc: Linux USB<linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer<s.hauer@pengutronix.de>
> > Cc: Shawn Guo<shawn.guo@freescale.com>
> > Cc: Shawn Guo<shawn.guo@linaro.org>
> > Cc: Stefano Babic<sbabic@denx.de>
> > Cc: Subodh Nijsure<snijsure@grid-net.com>
> > Cc: Tony Lin<tony.lin@freescale.com>
> > Cc: Wolfgang Denk<wd@denx.de>
> > ---
> > 
> >   arch/arm/mach-mxs/Kconfig       |    2 ++
> >   arch/arm/mach-mxs/mach-m28evk.c |    9 +++++++++
> >   2 files changed, 11 insertions(+)
> > 
> > diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
> > index 9dbf29f..5b5566c 100644
> > --- a/arch/arm/mach-mxs/Kconfig
> > +++ b/arch/arm/mach-mxs/Kconfig
> 
> [...]
> 
> > @@ -377,6 +382,10 @@ static void __init m28evk_init(void)
> > 
> >   	mx28_add_ts(&touch_pdata);
> >   	
> >   	mx28_add_gpmi_nand(&m28evk_gpmi_nand_data);
> > 
> > +
> > +	gpio_request_one(MXS_GPIO_NR(3, 13), GPIOF_OUT_INIT_LOW, "USB Power");
> 
>     Still can fail, and you don't handle it (unlike the next patch).

Hey, it was 4am in the morning when I was submitting this stuff, pardon my 
mistake ;-) Will be fixed in the new revision, thanks!

> 
> WBR, Sergei

Best regards,
Marek Vasut

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

* [RFC PATCH 00/10 V3]  MXS: Add i.MX28 USB Host driver
  2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
                     ` (11 preceding siblings ...)
  2012-04-18  7:52   ` Chen Peter-B29397
@ 2012-04-18 17:46   ` Marek Vasut
  2012-04-18 17:46     ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
                       ` (12 more replies)
  12 siblings, 13 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
generic USB PHY infrastructure.

V2: Introduce stub imx-usb driver that then registers the PHY and EHCI drivers.
V3: Add the HCD on demand based on the PHY's state (only add HCD if it's host).
    Currently, only the HOST mode is supported.

Marek Vasut (10):
  MXS: Make clk_disable return integer
  MXS: Add USB EHCI and USB PHY clock handling
  MXS: Fixup i.MX233 USB base address name
  MXS: Add data shared between imx-usb and EHCI driver
  MXS: Add platform registration hooks for USB EHCI
  MXS: Add imx-usb driver
  MXS: Add USB PHY driver
  MXS: Add separate MXS EHCI HCD driver
  MXS: Enable USB on M28EVK
  MXS: Enable USB on MX28EVK

 arch/arm/mach-mxs/Kconfig                       |    4 +
 arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
 arch/arm/mach-mxs/devices-mx28.h                |    4 +
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   78 ++++++
 arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
 arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
 arch/arm/mach-mxs/mach-m28evk.c                 |   15 ++
 arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
 drivers/usb/host/Kconfig                        |    7 +
 drivers/usb/host/ehci-hcd.c                     |    5 +
 drivers/usb/host/ehci-mxs.c                     |  228 +++++++++++++++++
 drivers/usb/otg/Kconfig                         |   16 ++
 drivers/usb/otg/Makefile                        |    2 +
 drivers/usb/otg/imx-usb.c                       |  226 +++++++++++++++++
 drivers/usb/otg/mxs-phy.c                       |  305 +++++++++++++++++++++++
 include/linux/fsl_devices.h                     |   10 +
 19 files changed, 952 insertions(+), 9 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
 create mode 100644 drivers/usb/host/ehci-mxs.c
 create mode 100644 drivers/usb/otg/imx-usb.c
 create mode 100644 drivers/usb/otg/mxs-phy.c

Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>

-- 
1.7.9.5

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

* [PATCH 01/10] MXS: Make clk_disable return integer
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 17:46     ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
                       ` (11 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

This allows subsequent USB clock patch to interchange enable() and disable()
calls without adding unnecessary switching cruft.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c         |    7 +++++--
 arch/arm/mach-mxs/include/mach/clock.h |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index cea29c9..43116ba 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -86,7 +86,7 @@ static int _raw_clk_enable(struct clk *clk)
 	return 0;
 }
 
-static void _raw_clk_disable(struct clk *clk)
+static int _raw_clk_disable(struct clk *clk)
 {
 	u32 reg;
 
@@ -95,6 +95,8 @@ static void _raw_clk_disable(struct clk *clk)
 		reg |= 1 << clk->enable_shift;
 		__raw_writel(reg, clk->enable_reg);
 	}
+
+	return 0;
 }
 
 /*
@@ -149,7 +151,7 @@ _CLK_ENABLE_PLL(pll1_clk, PLL1, EN_USB_CLKS)
 _CLK_ENABLE_PLL(pll2_clk, PLL2, CLKGATE)
 
 #define _CLK_DISABLE_PLL(name, r, g)					\
-static void name##_disable(struct clk *clk)				\
+static int name##_disable(struct clk *clk)				\
 {									\
 	__raw_writel(BM_CLKCTRL_##r##CTRL0_POWER,			\
 		     CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
@@ -161,6 +163,7 @@ static void name##_disable(struct clk *clk)				\
 		__raw_writel(BM_CLKCTRL_##r##CTRL0_##g,			\
 			CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
 									\
+	return 0;							\
 }
 
 _CLK_DISABLE_PLL(pll0_clk, PLL0, EN_USB_CLKS)
diff --git a/arch/arm/mach-mxs/include/mach/clock.h b/arch/arm/mach-mxs/include/mach/clock.h
index 592c9ab..21d1fad 100644
--- a/arch/arm/mach-mxs/include/mach/clock.h
+++ b/arch/arm/mach-mxs/include/mach/clock.h
@@ -50,7 +50,7 @@ struct clk {
 	int (*enable) (struct clk *);
 	/* Function ptr to disable the clock. Leave blank if clock can not
 	   be gated. */
-	void (*disable) (struct clk *);
+	int (*disable) (struct clk *);
 	/* Function ptr to set the parent clock of the clock. */
 	int (*set_parent) (struct clk *, struct clk *);
 };
-- 
1.7.9.5

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

* [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
  2012-04-18 17:46     ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 17:46     ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
                       ` (10 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index 43116ba..6136143 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -577,6 +577,21 @@ static struct clk usb1_clk = {
 	.parent = &pll1_clk,
 };
 
+static struct clk usb_phy_clk0 = {
+	.parent = &pll0_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL0CTRL0,
+	.enable_shift = 18,
+};
+
+static struct clk usb_phy_clk1 = {
+	.parent = &pll1_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL1CTRL0,
+	.enable_shift = 18,
+};
 #define _DEFINE_CLOCK(name, er, es, p)					\
 	static struct clk name = {					\
 		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
@@ -636,8 +651,10 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-mmc.3", NULL, ssp3_clk)
 	_REGISTER_CLOCK("flexcan.0", NULL, can0_clk)
 	_REGISTER_CLOCK("flexcan.1", NULL, can1_clk)
-	_REGISTER_CLOCK(NULL, "usb0", usb0_clk)
-	_REGISTER_CLOCK(NULL, "usb1", usb1_clk)
+	_REGISTER_CLOCK("imx-usb.0", "usb", usb0_clk)
+	_REGISTER_CLOCK("imx-usb.1", "usb", usb1_clk)
+	_REGISTER_CLOCK("mxs-usb-phy.0", "phy", usb_phy_clk0)
+	_REGISTER_CLOCK("mxs-usb-phy.1", "phy", usb_phy_clk1)
 	_REGISTER_CLOCK("mxs-pwm.0", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.1", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.2", NULL, pwm_clk)
-- 
1.7.9.5

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

* [PATCH 03/10] MXS: Fixup i.MX233 USB base address name
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
  2012-04-18 17:46     ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
  2012-04-18 17:46     ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 17:46     ` [PATCH 04/10] MXS: Add data shared between imx-usb and EHCI driver Marek Vasut
                       ` (9 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Modify USB EHCI and USB PHY base addresses on the i.MX233 to nicely fit into the
whole USB registration scheme.

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-mxs/include/mach/mx23.h b/arch/arm/mach-mxs/include/mach/mx23.h
index 599094b..7955b75 100644
--- a/arch/arm/mach-mxs/include/mach/mx23.h
+++ b/arch/arm/mach-mxs/include/mach/mx23.h
@@ -64,8 +64,8 @@
 #define MX23_AUART1_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06c000)
 #define MX23_AUART2_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06e000)
 #define MX23_DUART_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x070000)
-#define MX23_USBPHY_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
-#define MX23_USBCTRL_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
+#define MX23_USBPHY0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
+#define MX23_USBCTRL0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
 #define MX23_DRAM_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x0e0000)
 
 #define MX23_IO_P2V(x)			MXS_IO_P2V(x)
@@ -89,8 +89,8 @@
 #define MX23_INT_SPDIF_ERROR		10
 #define MX23_INT_SAIF1_IRQ		10
 #define MX23_INT_SAIF2_IRQ		10
-#define MX23_INT_USB_CTRL		11
-#define MX23_INT_USB_WAKEUP		12
+#define MX23_INT_USB0			11
+#define MX23_INT_USB0_WAKEUP		12
 #define MX23_INT_GPMI_DMA		13
 #define MX23_INT_SSP1_DMA		14
 #define MX23_INT_SSP1_ERROR		15
-- 
1.7.9.5

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

* [PATCH 04/10] MXS: Add data shared between imx-usb and EHCI driver
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (2 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 17:46     ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
                       ` (8 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds common data shared between the MXS EHCI HCD driver
and the imx-usb driver. These data allow passing clock and memory stuff
from imx-usb driver into the host driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 include/linux/fsl_devices.h |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index fffdf00..a1ed1a8 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -18,6 +18,7 @@
 #define _FSL_DEVICE_H_
 
 #include <linux/types.h>
+#include <linux/platform_device.h>
 
 /*
  * Some conventions on how we handle peripherals on Freescale chips
@@ -97,6 +98,15 @@ struct fsl_usb2_platform_data {
 	u32		pm_usbgenctrl;
 };
 
+struct imx_usb {
+	struct platform_device	*pdev;
+
+	struct clk		*clk;
+	struct resource		*mem_res;
+	void __iomem		*mem;
+	int			irq;
+};
+
 /* Flags in fsl_usb2_mph_platform_data */
 #define FSL_USB2_PORT0_ENABLED	0x00000001
 #define FSL_USB2_PORT1_ENABLED	0x00000002
-- 
1.7.9.5

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (3 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 04/10] MXS: Add data shared between imx-usb and EHCI driver Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-19 11:51       ` Arnd Bergmann
  2012-04-18 17:46     ` [PATCH 06/10] MXS: Add imx-usb driver Marek Vasut
                       ` (7 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/devices-mx28.h                |    4 ++
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   78 +++++++++++++++++++++++
 arch/arm/mach-mxs/include/mach/devices-common.h |    9 +++
 5 files changed, 95 insertions(+)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c

diff --git a/arch/arm/mach-mxs/devices-mx28.h b/arch/arm/mach-mxs/devices-mx28.h
index 9dbeae1..f1a76d7 100644
--- a/arch/arm/mach-mxs/devices-mx28.h
+++ b/arch/arm/mach-mxs/devices-mx28.h
@@ -47,6 +47,10 @@ extern const struct mxs_mxs_mmc_data mx28_mxs_mmc_data[] __initconst;
 
 #define mx28_add_mxs_pwm(id)		mxs_add_mxs_pwm(MX28_PWM_BASE_ADDR, id)
 
+extern const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst;
+#define mx28_add_mxs_usbh(id) \
+	mxs_add_mxs_usbh(&mx28_mxs_usbh_data[id])
+
 struct platform_device *__init mx28_add_mxsfb(
 		const struct mxsfb_platform_data *pdata);
 
diff --git a/arch/arm/mach-mxs/devices/Kconfig b/arch/arm/mach-mxs/devices/Kconfig
index b8913df..f6709bc 100644
--- a/arch/arm/mach-mxs/devices/Kconfig
+++ b/arch/arm/mach-mxs/devices/Kconfig
@@ -32,3 +32,6 @@ config MXS_HAVE_PLATFORM_MXS_SAIF
 
 config MXS_HAVE_PLATFORM_RTC_STMP3XXX
 	bool
+
+config MXS_HAVE_PLATFORM_USB
+	bool
diff --git a/arch/arm/mach-mxs/devices/Makefile b/arch/arm/mach-mxs/devices/Makefile
index c8f5c95..be4cc9e 100644
--- a/arch/arm/mach-mxs/devices/Makefile
+++ b/arch/arm/mach-mxs/devices/Makefile
@@ -11,3 +11,4 @@ obj-y += platform-gpio-mxs.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXSFB) += platform-mxsfb.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXS_SAIF) += platform-mxs-saif.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_RTC_STMP3XXX) += platform-rtc-stmp3xxx.o
+obj-$(CONFIG_MXS_HAVE_PLATFORM_USB) += platform-usb.o
diff --git a/arch/arm/mach-mxs/devices/platform-usb.c b/arch/arm/mach-mxs/devices/platform-usb.c
new file mode 100644
index 0000000..a76e015
--- /dev/null
+++ b/arch/arm/mach-mxs/devices/platform-usb.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+#include <linux/compiler.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/mx23.h>
+#include <mach/mx28.h>
+#include <mach/devices-common.h>
+
+#define mxs_usbh_data_entry_single(soc, _id, hwid)			\
+	{								\
+		.id = _id,						\
+		.usb_irq = soc ## _INT_USB ## hwid,			\
+		.usb_iobase = soc ## _USBCTRL ## hwid ## _BASE_ADDR,	\
+		.phy_iobase = soc ## _USBPHY ## hwid ## _BASE_ADDR,	\
+	}
+
+#define mxs_usbh_data_entry(soc, _id, hwid)				\
+	[_id] = mxs_usbh_data_entry_single(soc, _id, hwid)
+
+#ifdef CONFIG_SOC_IMX23
+const struct mxs_usbh_data mx23_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX23, 0, 0),
+};
+#endif
+
+#ifdef CONFIG_SOC_IMX28
+const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX28, 0, 0),
+	mxs_usbh_data_entry(MX28, 1, 1),
+};
+#endif
+
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data)
+{
+	struct platform_device *pdev;
+	struct resource phy_res[] = {
+		{
+			.start	= data->phy_iobase,
+			.end	= data->phy_iobase + SZ_256 - 1,
+			.flags	= IORESOURCE_MEM,
+		},
+	};
+
+	struct resource usb_res[] = {
+		{
+			.start	= data->usb_iobase,
+			.end	= data->usb_iobase + SZ_64K - 1,
+			.flags	= IORESOURCE_MEM,
+		}, {
+			.start	= data->usb_irq,
+			.end	= data->usb_irq,
+			.flags	= IORESOURCE_IRQ,
+		},
+	};
+
+	pdev = mxs_add_platform_device_dmamask("mxs-usb-phy", data->id,
+					phy_res, ARRAY_SIZE(phy_res),
+					NULL, 0,
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register USB PHY driver!\n");
+
+	pdev = mxs_add_platform_device_dmamask("imx-usb", data->id,
+					usb_res, ARRAY_SIZE(usb_res),
+					NULL, 0,
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register USB Host driver!\n");
+}
diff --git a/arch/arm/mach-mxs/include/mach/devices-common.h b/arch/arm/mach-mxs/include/mach/devices-common.h
index f2e3839..9f319b0 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
+++ b/arch/arm/mach-mxs/include/mach/devices-common.h
@@ -42,6 +42,15 @@ struct mxs_auart_data {
 struct platform_device *__init mxs_add_auart(
 		const struct mxs_auart_data *data);
 
+/* usb host */
+struct mxs_usbh_data {
+	int id;
+	resource_size_t usb_irq;
+	resource_size_t usb_iobase;
+	resource_size_t phy_iobase;
+};
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data);
+
 /* fec */
 #include <linux/fec.h>
 struct mxs_fec_data {
-- 
1.7.9.5

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

* [PATCH 06/10] MXS: Add imx-usb driver
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (4 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 17:46     ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
                       ` (6 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

This driver handles claiming of clocks and memory areas. These are later
properly delegated to it's child device, the USB Host.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |    6 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/imx-usb.c |  226 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 233 insertions(+)
 create mode 100644 drivers/usb/otg/imx-usb.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 5c87db0..e7c6325 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -116,6 +116,12 @@ config FSL_USB2_OTG
 	help
 	  Enable this to support Freescale USB OTG transceiver.
 
+config USB_IMX_COMPOSITE
+	bool
+	help
+	  Composite driver that handles clock and memory mapping for
+	  i.MX USB host and USB PHY.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 41aa509..e3feaca 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
 obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
+obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-usb.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/imx-usb.c b/drivers/usb/otg/imx-usb.c
new file mode 100644
index 0000000..8e8af95
--- /dev/null
+++ b/drivers/usb/otg/imx-usb.c
@@ -0,0 +1,226 @@
+/*
+ * drivers/usb/otg/imx-usb.c
+ *
+ * Freescale i.MX USB composite driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb/otg.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fsl_devices.h>
+#include <linux/io.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+
+/*
+ * Allocate platform device with the DMA mask, this is borrowed from
+ * arch/arm/mach-mxs/devices.c
+ */
+static struct platform_device *__devinit add_platform_device(
+		const char *name, int id,
+		const void *data, size_t size_data, u64 dmamask)
+{
+	int ret = -ENOMEM;
+	struct platform_device *pdev;
+
+	pdev = platform_device_alloc(name, id);
+	if (!pdev)
+		goto err;
+
+	if (dmamask) {
+		/*
+		 * This memory isn't freed when the device is put,
+		 * I don't have a nice idea for that though.  Conceptually
+		 * dma_mask in struct device should not be a pointer.
+		 * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
+		 */
+		pdev->dev.dma_mask =
+			kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
+		if (!pdev->dev.dma_mask)
+			/* ret is still -ENOMEM; */
+			goto err;
+
+		*pdev->dev.dma_mask = dmamask;
+		pdev->dev.coherent_dma_mask = dmamask;
+	}
+
+	if (data) {
+		ret = platform_device_add_data(pdev, data, size_data);
+		if (ret)
+			goto err;
+	}
+
+	ret = platform_device_add(pdev);
+	if (ret) {
+err:
+		if (dmamask)
+			kfree(pdev->dev.dma_mask);
+		platform_device_put(pdev);
+		return ERR_PTR(ret);
+	}
+
+	return pdev;
+}
+
+static int __devinit imx_usb_probe(struct platform_device *pdev)
+{
+	struct imx_usb *data;
+	int ret;
+	void *retp = NULL;
+
+	/*
+	 * Until further notice, this claims all necessary resources.
+	 */
+
+	/* Allocate driver's private date. */
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		ret = -ENOMEM;
+		goto err_alloc_data;
+	}
+
+	/* Claim the Host clock. */
+	data->clk = clk_get(&pdev->dev, "usb");
+	if (IS_ERR(data->clk)) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB Host\n");
+		ret = PTR_ERR(data->clk);
+		goto err_claim_host_clock;
+	}
+
+	/* Prepare Host clock. */
+	ret = clk_prepare(data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to prepare clock for USB Host.\n");
+		goto err_prepare_host_clock;
+	}
+
+	/* Get memory area for EHCI host from resources. */
+	data->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!data->mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_resource;
+	}
+
+	/* Request the memory region for this USB Host. */
+	retp = devm_request_mem_region(&pdev->dev, data->mem_res->start,
+			resource_size(data->mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB Host memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_get_host_mem;
+	}
+
+	/* Map the memory region for USB Host. */
+	data->mem = devm_ioremap(&pdev->dev, data->mem_res->start,
+				resource_size(data->mem_res));
+	if (!data->mem) {
+		dev_err(&pdev->dev, "Memory mapping of USB Host failed!\n");
+		ret = -EFAULT;
+		goto err_map_host_mem;
+	}
+
+	/* Get IRQ for EHCI host from resources. */
+	data->irq = platform_get_irq(pdev, 0);
+	if (data->irq < 0) {
+		dev_err(&pdev->dev, "Specify IRQ for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_irq;
+	}
+
+	/*
+	 * Now finally probe the Host driver!
+	 */
+	data->pdev = add_platform_device("mxs-ehci", -1, data, sizeof(*data),
+						DMA_BIT_MASK(32));
+	if (!data->pdev) {
+		dev_err(&pdev->dev, "Failed registering Host!\n");
+		ret = -ENODEV;
+		goto err_register_host;
+	}
+
+	return 0;
+
+err_register_host:
+err_get_host_irq:
+	iounmap(data->mem);
+err_map_host_mem:
+	release_mem_region(data->mem_res->start,
+			resource_size(data->mem_res));
+err_get_host_mem:
+	data->mem_res = NULL;
+err_get_host_resource:
+	clk_unprepare(data->clk);
+err_prepare_host_clock:
+	clk_put(data->clk);
+err_claim_host_clock:
+	kfree(data);
+err_alloc_data:
+	return ret;
+}
+
+static int __devexit imx_usb_remove(struct platform_device *pdev)
+{
+	struct imx_usb *data = platform_get_drvdata(pdev);
+
+	platform_device_unregister(data->pdev);
+
+	iounmap(data->mem);
+	release_mem_region(data->mem_res->start,
+			resource_size(data->mem_res));
+	data->mem_res = NULL;
+	clk_unprepare(data->clk);
+	clk_put(data->clk);
+	kfree(data);
+
+	return 0;
+}
+
+static struct platform_driver imx_usb_driver = {
+	.probe		= imx_usb_probe,
+	.remove		= __devexit_p(imx_usb_remove),
+	.driver		= {
+		.name	= "imx-usb",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init imx_usb_init(void)
+{
+	return platform_driver_register(&imx_usb_driver);
+}
+
+static void __exit imx_usb_exit(void)
+{
+	platform_driver_unregister(&imx_usb_driver);
+}
+
+module_init(imx_usb_init);
+module_exit(imx_usb_exit);
+
+MODULE_ALIAS("platform:imx-usb");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX USB composite driver");
+MODULE_LICENSE("GPL");
-- 
1.7.9.5

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

* [PATCH 07/10] MXS: Add USB PHY driver
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (5 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 06/10] MXS: Add imx-usb driver Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 19:36       ` Sascha Hauer
  2012-04-18 17:46     ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
                       ` (5 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
enables the PHY upon powerup and shuts it down on shutdown.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |   10 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  305 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 316 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index e7c6325..1de1495 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -122,6 +122,16 @@ config USB_IMX_COMPOSITE
 	  Composite driver that handles clock and memory mapping for
 	  i.MX USB host and USB PHY.
 
+config USB_MXS_PHY
+	tristate "Freescale i.MX28 USB PHY support"
+	select USB_OTG_UTILS
+	select USB_IMX_COMPOSITE
+	help
+	  Say Y here if you want to build Freescale i.MX28 USB PHY
+	  driver in kernel.
+
+	  To compile this driver as a module, choose M here.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index e3feaca..56700b3 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
 obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-usb.o
+obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
new file mode 100644
index 0000000..2ee1240
--- /dev/null
+++ b/drivers/usb/otg/mxs-phy.c
@@ -0,0 +1,305 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fsl_devices.h>
+
+#include <linux/usb.h>
+#include <linux/usb/ch9.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/hcd.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#define HW_USBPHY_PWD				0x00
+
+#define HW_USBPHY_CTRL				0x30
+#define HW_USBPHY_CTRL_SET			0x34
+#define HW_USBPHY_CTRL_CLR			0x38
+#define HW_USBPHY_CTRL_TOG			0x3c
+
+#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
+#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
+#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
+#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
+#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
+
+struct mxs_usb_phy {
+	struct usb_phy		phy;
+
+	struct work_struct	work;
+
+	struct clk		*clk;
+	struct resource		*mem_res;
+	void __iomem		*mem;
+	int			irq;
+};
+
+static int mxs_usb_set_vbus(struct usb_otg *otg, bool enabled)
+{
+	struct usb_phy *x = otg->phy;
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+
+	if (enabled)
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			phy->mem + HW_USBPHY_CTRL_CLR);
+	else
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			phy->mem + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static int mxs_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	struct usb_phy *x = otg->phy;
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+
+	/* So far, we support only host mode, so be quick here. */
+	otg->host = host;
+	schedule_work(&phy->work);
+
+	return 0;
+}
+
+static void mxs_usb_work(struct work_struct *w)
+{
+	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
+	struct usb_otg *otg = phy->phy.otg;
+	struct usb_hcd *hcd;
+
+	switch (otg->phy->state) {
+	case OTG_STATE_A_HOST:
+		if (otg->host) {
+			hcd = bus_to_hcd(otg->host);
+			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
+		}
+		break;
+	default:
+		break;
+	}
+}
+
+static int mxs_usb_phy_init(struct usb_phy *x)
+{
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+	uint32_t val;
+
+	/* Enable clock to the PHY. */
+	clk_enable(phy->clk);
+
+	/* Reset the PHY block. */
+	mxs_reset_block(phy->mem + HW_USBPHY_CTRL);
+
+	/* Power up the PHY. */
+	writel(0, phy->mem + HW_USBPHY_PWD);
+
+	/* Enable FS/LS compatibility and HS disconnection detector. */
+	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
+		BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
+	writel(val, phy->mem + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static void mxs_usb_phy_shutdown(struct usb_phy *x)
+{
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+
+	/* Gate off the PHY. */
+	writel(BM_USBPHY_CTRL_CLKGATE, phy->mem + HW_USBPHY_CTRL_SET);
+
+	/* Disable clock to the PHY. */
+	clk_disable(phy->clk);
+}
+
+static int __devinit mxs_phy_probe(struct platform_device *pdev)
+{
+	struct mxs_usb_phy *phy;
+	void *retp;
+	int ret;
+
+	/* Allocate PHY driver's private date. */
+	phy = kzalloc(sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
+		ret = -ENOMEM;
+		goto err_alloc_phy;
+	}
+
+	/* Allocate OTG structure. */
+	phy->phy.otg = kzalloc(sizeof(*phy->phy.otg), GFP_KERNEL);
+	if (!phy->phy.otg) {
+		dev_err(&pdev->dev, "Failed to allocate USB OTG structure!\n");
+		ret = -ENOMEM;
+		goto err_alloc_otg;
+	}
+
+	/* Claim the PHY clock. */
+	phy->clk = clk_get(&pdev->dev, "phy");
+	if (!phy->clk) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB PHY\n");
+		ret = PTR_ERR(phy->clk);
+		goto err_claim_phy_clock;
+	}
+
+	/* Prepare PHY clock. */
+	ret = clk_prepare(phy->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to prepare clock for USB PHY.\n");
+		goto err_prepare_phy_clock;
+	}
+
+	/* Get memory area for PHY from resources. */
+	phy->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!phy->mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB PHY!\n");
+		ret = -ENODEV;
+		goto err_get_phy_resource;
+	}
+
+	/* Request the memory region for this USB PHY. */
+	retp = devm_request_mem_region(&pdev->dev, phy->mem_res->start,
+			resource_size(phy->mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB PHY memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_get_phy_mem;
+	}
+
+	/* Map the memory region for USB PHY. */
+	phy->mem = devm_ioremap(&pdev->dev, phy->mem_res->start,
+				resource_size(phy->mem_res));
+	if (!phy->mem) {
+		dev_err(&pdev->dev, "Memory mapping of USB PHY failed!\n");
+		ret = -EFAULT;
+		goto err_map_phy_mem;
+	}
+
+	/* Setup the PHY structures. */
+	phy->phy.dev		= &pdev->dev;
+	phy->phy.label		= "mxs-usb-phy";
+	phy->phy.init		= mxs_usb_phy_init;
+	phy->phy.shutdown	= mxs_usb_phy_shutdown;
+	phy->phy.state		= OTG_STATE_A_HOST;
+
+	phy->phy.otg->phy	= &phy->phy;
+	phy->phy.otg->set_vbus	= mxs_usb_set_vbus;
+	phy->phy.otg->set_host	= mxs_usb_set_host;
+
+	platform_set_drvdata(pdev, phy);
+
+	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
+
+	INIT_WORK(&phy->work, mxs_usb_work);
+
+	/* Register the transceiver with kernel. */
+	ret = usb_set_transceiver(&phy->phy);
+	if (ret) {
+		dev_err(&pdev->dev, "Can't register transceiver, (%d)\n", ret);
+		goto err_set_transceiver;
+	}
+
+	return 0;
+
+err_set_transceiver:
+	iounmap(phy->mem);
+err_map_phy_mem:
+	release_mem_region(phy->mem_res->start, resource_size(phy->mem_res));
+err_get_phy_mem:
+	phy->mem_res = NULL;
+err_get_phy_resource:
+	clk_unprepare(phy->clk);
+err_prepare_phy_clock:
+	clk_put(phy->clk);
+err_claim_phy_clock:
+	kfree(phy->phy.otg);
+err_alloc_otg:
+	kfree(phy);
+err_alloc_phy:
+	return ret;
+}
+
+static int __devexit mxs_phy_remove(struct platform_device *pdev)
+{
+	struct mxs_usb_phy *phy = platform_get_drvdata(pdev);
+
+	/* Stop the PHY work. */
+	cancel_work_sync(&phy->work);
+
+	/* Power down the PHY. */
+	mxs_usb_phy_shutdown(&phy->phy);
+
+	/* Remove the transceiver. */
+	usb_set_transceiver(NULL);
+
+	/* Unmap the PHY's memory region. */
+	iounmap(phy->mem);
+	release_mem_region(phy->mem_res->start, resource_size(phy->mem_res));
+
+	/* Stop the PHY clock. */
+	clk_disable_unprepare(phy->clk);
+	clk_put(phy->clk);
+
+	/* Free the rest. */
+	platform_set_drvdata(pdev, NULL);
+	kfree(phy->phy.otg);
+	kfree(phy);
+
+	return 0;
+}
+
+static struct platform_driver mxs_phy_driver = {
+	.probe		= mxs_phy_probe,
+	.remove		= __devexit_p(mxs_phy_remove),
+	.driver		= {
+		.name	= "mxs-usb-phy",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mxs_phy_init(void)
+{
+	return platform_driver_register(&mxs_phy_driver);
+}
+
+static void __exit mxs_phy_exit(void)
+{
+	platform_driver_unregister(&mxs_phy_driver);
+}
+
+subsys_initcall(mxs_phy_init);
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
-- 
1.7.9.5

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (6 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 19:50       ` Sascha Hauer
  2012-04-18 17:46     ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
                       ` (4 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to keep
this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
though eventually these two might be merged.

NOTE: I still haven't figured out how to enable/disable the disconnection
detector, it can't be enabled all the time, so I toggle PHY stuff from this
driver, which I doubt is correct.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/host/Kconfig    |    7 ++
 drivers/usb/host/ehci-hcd.c |    5 +
 drivers/usb/host/ehci-mxs.c |  228 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 240 insertions(+)
 create mode 100644 drivers/usb/host/ehci-mxs.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f788eb8..85ed593 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -148,6 +148,13 @@ config USB_EHCI_MXC
 	---help---
 	  Variation of ARC USB block used in some Freescale chips.
 
+config USB_EHCI_MXS
+	bool "Support for Freescale i.MX28 on-chip EHCI USB controller"
+	depends on USB_EHCI_HCD && ARCH_MXS
+	select USB_EHCI_ROOT_HUB_TT
+	---help---
+	  Enable USB support for i.MX28.
+
 config USB_EHCI_HCD_OMAP
 	bool "EHCI support for OMAP3 and later chips"
 	depends on USB_EHCI_HCD && ARCH_OMAP
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 806cc95..d0df8be 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1263,6 +1263,11 @@ MODULE_LICENSE ("GPL");
 #define PLATFORM_DRIVER		ehci_mxc_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_MXS
+#include "ehci-mxs.c"
+#define PLATFORM_DRIVER		ehci_mxs_driver
+#endif
+
 #ifdef CONFIG_USB_EHCI_SH
 #include "ehci-sh.c"
 #define PLATFORM_DRIVER		ehci_hcd_sh_driver
diff --git a/drivers/usb/host/ehci-mxs.c b/drivers/usb/host/ehci-mxs.c
new file mode 100644
index 0000000..f3d23de
--- /dev/null
+++ b/drivers/usb/host/ehci-mxs.c
@@ -0,0 +1,228 @@
+/*
+ * Freescale i.MX28 EHCI driver
+ *
+ * Copyright (c) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * Based on MXC EHCI driver:
+ *
+ * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
+ * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, 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,
+ * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/slab.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#include <asm/mach-types.h>
+
+/* Called during probe() after chip reset completes */
+static int ehci_mxs_setup(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+
+	hcd->has_tt = 1;
+	ehci_setup(hcd);
+	ehci_port_power(ehci, 0);
+
+	return 0;
+}
+
+static irqreturn_t mxs_ehci_irq(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	struct usb_phy *phy = usb_get_transceiver();
+	uint32_t status;
+	static uint32_t discon;
+
+	if (phy && phy->otg && phy->otg->set_vbus) {
+		status = ehci_readl(ehci, &ehci->regs->status);
+		status = !!(status & STS_PCD);
+		if (status != discon) {
+			discon = status;
+			phy->otg->set_vbus(phy->otg, status);
+		}
+	}
+
+	return ehci_irq(hcd);
+}
+
+static const struct hc_driver ehci_mxs_hc_driver = {
+	.description	= hcd_name,
+	.product_desc	= "Freescale i.MX28 On-Chip EHCI Host Controller",
+	.hcd_priv_size	= sizeof(struct ehci_hcd),
+
+	/*
+	 * Generic hardware linkage
+	 */
+	.irq		= mxs_ehci_irq,
+	.flags		= HCD_USB2 | HCD_MEMORY,
+
+	/*
+	 * Basic lifecycle operations
+	 */
+	.reset		= ehci_mxs_setup,
+	.start		= ehci_run,
+	.stop		= ehci_stop,
+	.shutdown	= ehci_shutdown,
+
+	/*
+	 * managing i/o requests and associated device resources
+	 */
+	.urb_enqueue		= ehci_urb_enqueue,
+	.urb_dequeue		= ehci_urb_dequeue,
+	.endpoint_disable	= ehci_endpoint_disable,
+	.endpoint_reset		= ehci_endpoint_reset,
+
+	/*
+	 * scheduling support
+	 */
+	.get_frame_number	= ehci_get_frame,
+
+	/*
+	 * root hub support
+	 */
+	.hub_status_data	= ehci_hub_status_data,
+	.hub_control		= ehci_hub_control,
+	.bus_suspend		= ehci_bus_suspend,
+	.bus_resume		= ehci_bus_resume,
+	.relinquish_port	= ehci_relinquish_port,
+	.port_handed_over	= ehci_port_handed_over,
+
+	.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
+};
+
+static int ehci_mxs_drv_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct imx_usb *data = pdev->dev.platform_data;
+	struct usb_hcd *hcd;
+	struct ehci_hcd *ehci;
+	struct usb_phy *phy;
+	int ret;
+
+	dev_info(dev, "Initializing i.MX28 USB Controller\n");
+
+	if (!data) {
+		dev_err(dev, "USB Host platform data missing!\n");
+		return -ENODEV;
+	}
+
+	/* Create HCD controller instance. */
+	hcd = usb_create_hcd(&ehci_mxs_hc_driver, dev, dev_name(dev));
+	if (!hcd) {
+		dev_err(dev, "Failed to create HCD instance!\n");
+		return -ENOMEM;
+	}
+
+	hcd->rsrc_start = data->mem_res->start;
+	hcd->rsrc_len = resource_size(data->mem_res);
+	hcd->regs = data->mem;
+	hcd->irq = data->irq;
+
+	clk_enable(data->clk);
+
+	/* Wait for the controller to stabilize. */
+	mdelay(10);
+
+	ehci = hcd_to_ehci(hcd);
+
+	/* EHCI registers start at offset 0x100 */
+	ehci->caps = hcd->regs + 0x100;
+	ehci->regs = hcd->regs + 0x100 +
+		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
+
+	platform_set_drvdata(pdev, hcd);
+
+	/* Initialize the transceiver */
+#ifdef CONFIG_USB_OTG_UTILS
+	phy = usb_get_transceiver();
+	if (!phy) {
+		dev_err(dev, "Unable to find transceiver.\n");
+		ret = -ENODEV;
+		goto err_phy;
+	}
+
+	ret = otg_set_host(phy->otg, &hcd->self);
+	if (ret < 0) {
+		dev_err(dev, "Unable to set transceiver host\n");
+		ret = -ENODEV;
+		goto err_phy_set_host;
+	}
+
+	ret = usb_phy_init(phy);
+	if (ret < 0) {
+		dev_err(dev, "Unable init transceiver\n");
+		ret = -ENODEV;
+		goto err_phy_init;
+	}
+#else
+	dev_info(dev, "USB_MXS_PHY must have CONFIG_USB_OTG_UTILS enabled\n");
+	goto err_phy;
+#endif
+
+	/* Set up the PORTSCx register */
+	ehci_writel(ehci, 0, &ehci->regs->port_status[0]);
+
+	return 0;
+
+err_phy_init:
+err_phy_set_host:
+#ifdef CONFIG_USB_OTG_UTILS
+	if (phy)
+		usb_put_transceiver(phy);
+#endif
+err_phy:
+	clk_disable(data->clk);
+	usb_put_hcd(hcd);
+	return ret;
+}
+
+static int __exit ehci_mxs_drv_remove(struct platform_device *pdev)
+{
+	struct imx_usb *data = pdev->dev.platform_data;
+	struct usb_hcd *hcd = platform_get_drvdata(pdev);
+	struct usb_phy *phy = usb_get_transceiver();
+
+	if (phy)
+		usb_phy_shutdown(phy);
+
+	usb_remove_hcd(hcd);
+	usb_put_hcd(hcd);
+	platform_set_drvdata(pdev, NULL);
+	clk_disable(data->clk);
+
+	return 0;
+}
+
+static struct platform_driver ehci_mxs_driver = {
+	.probe		= ehci_mxs_drv_probe,
+	.remove		= __exit_p(ehci_mxs_drv_remove),
+	.driver		= {
+		   .name	= "mxs-ehci",
+	},
+};
+
+MODULE_ALIAS("platform:mxs-ehci");
-- 
1.7.9.5

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

* [PATCH 09/10] MXS: Enable USB on M28EVK
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (7 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-18 17:46     ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
                       ` (3 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Enable the second USB port on M28EVK board.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig       |    2 ++
 arch/arm/mach-mxs/mach-m28evk.c |   15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index c57f996..05f6e84 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -81,6 +81,8 @@ config MODULE_M28
 	select MXS_HAVE_PLATFORM_MXS_I2C
 	select MXS_HAVE_PLATFORM_MXS_MMC
 	select MXS_HAVE_PLATFORM_MXSFB
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 
 config MODULE_APX4
diff --git a/arch/arm/mach-mxs/mach-m28evk.c b/arch/arm/mach-mxs/mach-m28evk.c
index 06d7996..85c4f30 100644
--- a/arch/arm/mach-mxs/mach-m28evk.c
+++ b/arch/arm/mach-mxs/mach-m28evk.c
@@ -39,6 +39,7 @@
 
 #define MX28EVK_BL_ENABLE	MXS_GPIO_NR(3, 18)
 #define M28EVK_LCD_ENABLE	MXS_GPIO_NR(3, 28)
+#define M28EVK_USB_ENABLE	MXS_GPIO_NR(3, 13)
 
 #define MX28EVK_MMC0_WRITE_PROTECT	MXS_GPIO_NR(2, 12)
 #define MX28EVK_MMC1_WRITE_PROTECT	MXS_GPIO_NR(0, 28)
@@ -210,6 +211,11 @@ static const iomux_cfg_t m28evk_pads[] __initconst = {
 
 	/* Backlight */
 	MX28_PAD_PWM3__GPIO_3_28 | MXS_PAD_CTRL,
+
+	/* USB */
+	MX28_PAD_SSP2_SS1__USB1_OVERCURRENT,
+	MX28_PAD_AUART3_TX__GPIO_3_13 |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
 };
 
 /* led */
@@ -319,6 +325,8 @@ static struct mxs_mmc_platform_data m28evk_mmc_pdata[] __initdata = {
 
 static void __init m28evk_init(void)
 {
+	int ret;
+
 	mxs_iomux_setup_multiple_pads(m28evk_pads, ARRAY_SIZE(m28evk_pads));
 
 	mx28_add_duart();
@@ -344,6 +352,13 @@ static void __init m28evk_init(void)
 	mx28_add_mxs_i2c(0);
 	i2c_register_board_info(0, m28_stk5v3_i2c_boardinfo,
 			ARRAY_SIZE(m28_stk5v3_i2c_boardinfo));
+
+	ret = gpio_request_one(M28EVK_USB_ENABLE, GPIOF_OUT_INIT_LOW,
+				"USB Power");
+	if (ret)
+		pr_warn("Failed to request USB Power GPIO, %d\n", ret);
+
+	mx28_add_mxs_usbh(1);
 }
 
 static void __init m28evk_timer_init(void)
-- 
1.7.9.5

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

* [PATCH 10/10] MXS: Enable USB on MX28EVK
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (8 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-18 17:46     ` Marek Vasut
  2012-04-20  2:13     ` [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver Marek Vasut
                       ` (2 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:46 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig        |    2 ++
 arch/arm/mach-mxs/mach-mx28evk.c |   10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index 05f6e84..5083db3 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -53,6 +53,8 @@ config MACH_MX28EVK
 	select MXS_HAVE_PLATFORM_MXS_SAIF
 	select MXS_HAVE_PLATFORM_MXS_I2C
 	select MXS_HAVE_PLATFORM_RTC_STMP3XXX
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 	help
 	  Include support for MX28EVK platform. This includes specific
diff --git a/arch/arm/mach-mxs/mach-mx28evk.c b/arch/arm/mach-mxs/mach-mx28evk.c
index e386c14..8bdd416 100644
--- a/arch/arm/mach-mxs/mach-mx28evk.c
+++ b/arch/arm/mach-mxs/mach-mx28evk.c
@@ -37,6 +37,7 @@
 #define MX28EVK_BL_ENABLE	MXS_GPIO_NR(3, 18)
 #define MX28EVK_LCD_ENABLE	MXS_GPIO_NR(3, 30)
 #define MX28EVK_FEC_PHY_RESET	MXS_GPIO_NR(4, 13)
+#define MX28EVK_USB1_PWR_EN	MXS_GPIO_NR(3, 8)
 
 #define MX28EVK_MMC0_WRITE_PROTECT	MXS_GPIO_NR(2, 12)
 #define MX28EVK_MMC1_WRITE_PROTECT	MXS_GPIO_NR(0, 28)
@@ -186,6 +187,8 @@ static const iomux_cfg_t mx28evk_pads[] __initconst = {
 
 	/* led */
 	MX28_PAD_AUART1_TX__GPIO_3_5 | MXS_PAD_CTRL,
+	/* usb1 */
+	MX28_PAD_AUART2_RX__GPIO_3_8 | MXS_PAD_CTRL,
 
 	/* I2C */
 	MX28_PAD_I2C0_SCL__I2C0_SCL |
@@ -451,6 +454,13 @@ static void __init mx28evk_init(void)
 	mx28_add_mxs_mmc(0, &mx28evk_mmc_pdata[0]);
 	mx28_add_mxs_mmc(1, &mx28evk_mmc_pdata[1]);
 
+	ret = gpio_request_one(MX28EVK_USB1_PWR_EN, GPIOF_OUT_INIT_HIGH,
+				"usb1-power-en");
+	if (ret)
+		pr_warn("failed to request gpio usb1-power-en %d\n", ret);
+
+	mx28_add_mxs_usbh(1);
+
 	mx28_add_rtc_stmp3xxx();
 
 	gpio_led_register_device(0, &mx28evk_led_data);
-- 
1.7.9.5

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

* [RFC PATCH 00/10 V2]  MXS: Add i.MX28 USB Host driver
  2012-04-18  7:52   ` Chen Peter-B29397
@ 2012-04-18 17:49     ` Marek Vasut
  2012-04-19  2:37       ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 17:49 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > the
> > generic USB PHY infrastructure.
> > 
> > V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> > drivers.
> 
> - Currently, there is no generic PHY layer, so only one host/device can be
> supported.
> 
> - Now, the PHY and OTG is separated, it is better to put PHY driver to
> drivers/usb/phy/

There is no drivers/usb/phy ...

> 
> - mx23, mx28, mx6q uses the same PHY (FSL PHY), it is better to use the phy
> driver name as imx-phy.c.

Why? mxs == mx23,28,6q and mxc == the rest ... seems to me to be pretty well 
rooted terminology already.

> 
> > Marek Vasut (10):
> >   MXS: Make clk_disable return integer
> >   MXS: Add USB EHCI and USB PHY clock handling
> >   MXS: Fixup i.MX233 USB base address name
> >   MXS: Add data shared between imx-usb, PHY and EHCI driver
> >   MXS: Add platform registration hooks for USB EHCI
> >   MXS: Add composite imx-usb driver
> >   MXS: Add USB PHY driver
> >   MXS: Add separate MXS EHCI HCD driver
> >   MXS: Enable USB on M28EVK
> >   MXS: Enable USB on MX28EVK
> >  
> >  arch/arm/mach-mxs/Kconfig                       |    4 +
> >  arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
> >  arch/arm/mach-mxs/devices-mx28.h                |    4 +
> >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> >  arch/arm/mach-mxs/devices/platform-usb.c        |   67 +++++
> >  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> >  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
> >  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> >  arch/arm/mach-mxs/mach-m28evk.c                 |    9 +
> >  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
> >  drivers/usb/host/Kconfig                        |    7 +
> >  drivers/usb/host/ehci-hcd.c                     |    5 +
> >  drivers/usb/host/ehci-mxs.c                     |  254
> > 
> > +++++++++++++++++++
> > 
> >  drivers/usb/otg/Kconfig                         |   16 ++
> >  drivers/usb/otg/Makefile                        |    2 +
> >  drivers/usb/otg/imx-usb.c                       |  303
> > 
> > +++++++++++++++++++++++
> > 
> >  drivers/usb/otg/mxs-phy.c                       |  201 +++++++++++++++
> >  include/linux/fsl_devices.h                     |   15 ++
> >  19 files changed, 939 insertions(+), 9 deletions(-)
> >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> >  create mode 100644 drivers/usb/host/ehci-mxs.c
> >  create mode 100644 drivers/usb/otg/imx-usb.c
> >  create mode 100644 drivers/usb/otg/mxs-phy.c
> > 
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > --
> > 1.7.9.5

Best regards,
Marek Vasut

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

* [PATCH 07/10] MXS: Add USB PHY driver
  2012-04-18 17:46     ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-18 19:36       ` Sascha Hauer
  2012-04-18 20:02         ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18 19:36 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 18, 2012 at 07:46:31PM +0200, Marek Vasut wrote:
> Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
> enables the PHY upon powerup and shuts it down on shutdown.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  drivers/usb/otg/Kconfig   |   10 ++
>  drivers/usb/otg/Makefile  |    1 +
>  drivers/usb/otg/mxs-phy.c |  305 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 316 insertions(+)
>  create mode 100644 drivers/usb/otg/mxs-phy.c
> 
> diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> index e7c6325..1de1495 100644
> --- a/drivers/usb/otg/Kconfig
> +++ b/drivers/usb/otg/Kconfig
> @@ -122,6 +122,16 @@ config USB_IMX_COMPOSITE
>  	  Composite driver that handles clock and memory mapping for
>  	  i.MX USB host and USB PHY.
>  
> +config USB_MXS_PHY
> +	tristate "Freescale i.MX28 USB PHY support"
> +	select USB_OTG_UTILS
> +	select USB_IMX_COMPOSITE
> +	help
> +	  Say Y here if you want to build Freescale i.MX28 USB PHY
> +	  driver in kernel.
> +
> +	  To compile this driver as a module, choose M here.
> +
>  config USB_MV_OTG
>  	tristate "Marvell USB OTG support"
>  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> index e3feaca..56700b3 100644
> --- a/drivers/usb/otg/Makefile
> +++ b/drivers/usb/otg/Makefile
> @@ -21,4 +21,5 @@ obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
>  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
>  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
>  obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-usb.o
> +obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
>  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> +
> +struct mxs_usb_phy {
> +	struct usb_phy		phy;
> +
> +	struct work_struct	work;
> +
> +	struct clk		*clk;
> +	struct resource		*mem_res;
> +	void __iomem		*mem;
> +	int			irq;

irq is unused.

> +
> +static void mxs_usb_work(struct work_struct *w)
> +{
> +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
> +	struct usb_otg *otg = phy->phy.otg;
> +	struct usb_hcd *hcd;
> +
> +	switch (otg->phy->state) {
> +	case OTG_STATE_A_HOST:
> +		if (otg->host) {
> +			hcd = bus_to_hcd(otg->host);
> +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> +		}
> +		break;
> +	default:
> +		break;
> +	}
> +}

This function should be in imx-otg.

> +
> +static int __devinit mxs_phy_probe(struct platform_device *pdev)
> +{
> +	struct mxs_usb_phy *phy;
> +	void *retp;
> +	int ret;
> +
> +	/* Allocate PHY driver's private date. */
> +	phy = kzalloc(sizeof(*phy), GFP_KERNEL);

devm?

> +	if (!phy) {
> +		dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
> +		ret = -ENOMEM;
> +		goto err_alloc_phy;
> +	}
> +
> +	/* Allocate OTG structure. */
> +	phy->phy.otg = kzalloc(sizeof(*phy->phy.otg), GFP_KERNEL);

devm?

> +	if (!phy->phy.otg) {
> +		dev_err(&pdev->dev, "Failed to allocate USB OTG structure!\n");
> +		ret = -ENOMEM;
> +		goto err_alloc_otg;
> +	}
> +
> +	/* Claim the PHY clock. */
> +	phy->clk = clk_get(&pdev->dev, "phy");
> +	if (!phy->clk) {
> +		dev_err(&pdev->dev, "Failed to claim clock for USB PHY\n");
> +		ret = PTR_ERR(phy->clk);
> +		goto err_claim_phy_clock;
> +	}
> +
> +	/* Prepare PHY clock. */
> +	ret = clk_prepare(phy->clk);

It should be clear that a function named clk_prepare prepares the clock.
Please remove such comments.

> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to prepare clock for USB PHY.\n");
> +		goto err_prepare_phy_clock;
> +	}
> +
> +	/* Get memory area for PHY from resources. */
> +	phy->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!phy->mem_res) {
> +		dev_err(&pdev->dev, "Specify memory area for this USB PHY!\n");
> +		ret = -ENODEV;
> +		goto err_get_phy_resource;
> +	}
> +
> +	/* Request the memory region for this USB PHY. */
> +	retp = devm_request_mem_region(&pdev->dev, phy->mem_res->start,
> +			resource_size(phy->mem_res), pdev->name);

The 'm' in devm is for 'managed' which means that these resources are
automatically released on driver exit. You don't have to release them
manually. In fact you must not release them with the regular functions.
If you want to release them manually you have to use the devm variants.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18 17:46     ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-18 19:50       ` Sascha Hauer
  2012-04-18 20:07         ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18 19:50 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 18, 2012 at 07:46:32PM +0200, Marek Vasut wrote:
> This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to keep
> this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
> though eventually these two might be merged.
> 
> NOTE: I still haven't figured out how to enable/disable the disconnection
> detector, it can't be enabled all the time, so I toggle PHY stuff from this
> driver, which I doubt is correct.
> 

[...]

> +static int ehci_mxs_drv_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct imx_usb *data = pdev->dev.platform_data;
> +	struct usb_hcd *hcd;
> +	struct ehci_hcd *ehci;
> +	struct usb_phy *phy;
> +	int ret;
> +
> +	dev_info(dev, "Initializing i.MX28 USB Controller\n");

This is not (only) i.MX28

> +
> +	if (!data) {
> +		dev_err(dev, "USB Host platform data missing!\n");
> +		return -ENODEV;
> +	}
> +
> +	/* Create HCD controller instance. */
> +	hcd = usb_create_hcd(&ehci_mxs_hc_driver, dev, dev_name(dev));
> +	if (!hcd) {
> +		dev_err(dev, "Failed to create HCD instance!\n");
> +		return -ENOMEM;
> +	}
> +
> +	hcd->rsrc_start = data->mem_res->start;
> +	hcd->rsrc_len = resource_size(data->mem_res);
> +	hcd->regs = data->mem;
> +	hcd->irq = data->irq;
> +
> +	clk_enable(data->clk);

The clock shouldn't be here. move this to imx-otg.c

> +
> +	/* Wait for the controller to stabilize. */
> +	mdelay(10);
> +
> +	ehci = hcd_to_ehci(hcd);
> +
> +	/* EHCI registers start at offset 0x100 */
> +	ehci->caps = hcd->regs + 0x100;
> +	ehci->regs = hcd->regs + 0x100 +
> +		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
> +
> +	platform_set_drvdata(pdev, hcd);
> +
> +	/* Initialize the transceiver */
> +#ifdef CONFIG_USB_OTG_UTILS
> +	phy = usb_get_transceiver();
> +	if (!phy) {
> +		dev_err(dev, "Unable to find transceiver.\n");
> +		ret = -ENODEV;
> +		goto err_phy;
> +	}
> +
> +	ret = otg_set_host(phy->otg, &hcd->self);
> +	if (ret < 0) {
> +		dev_err(dev, "Unable to set transceiver host\n");
> +		ret = -ENODEV;
> +		goto err_phy_set_host;
> +	}
> +
> +	ret = usb_phy_init(phy);
> +	if (ret < 0) {
> +		dev_err(dev, "Unable init transceiver\n");
> +		ret = -ENODEV;
> +		goto err_phy_init;
> +	}
> +#else
> +	dev_info(dev, "USB_MXS_PHY must have CONFIG_USB_OTG_UTILS enabled\n");
> +	goto err_phy;
> +#endif

If your code does not work without CONFIG_USB_OTG_UTILS then why doesn't
the driver depend on this option?
It doesn't matter, all code inside these ifdefs should go to imx-otg.c.

> +
> +	/* Set up the PORTSCx register */
> +	ehci_writel(ehci, 0, &ehci->regs->port_status[0]);
> +

Should also be in imx-otg.c

> +err_phy_init:
> +err_phy_set_host:
> +#ifdef CONFIG_USB_OTG_UTILS
> +	if (phy)
> +		usb_put_transceiver(phy);
> +#endif
> +err_phy:
> +	clk_disable(data->clk);
> +	usb_put_hcd(hcd);
> +	return ret;
> +}
> +
> +static int __exit ehci_mxs_drv_remove(struct platform_device *pdev)
> +{
> +	struct imx_usb *data = pdev->dev.platform_data;
> +	struct usb_hcd *hcd = platform_get_drvdata(pdev);
> +	struct usb_phy *phy = usb_get_transceiver();
> +
> +	if (phy)
> +		usb_phy_shutdown(phy);
> +
> +	usb_remove_hcd(hcd);

usb_add_hcd is in imx-otg.c so usb_remove_hcd should be aswell.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 07/10] MXS: Add USB PHY driver
  2012-04-18 19:36       ` Sascha Hauer
@ 2012-04-18 20:02         ` Marek Vasut
  2012-04-18 20:16           ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 20:02 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> On Wed, Apr 18, 2012 at 07:46:31PM +0200, Marek Vasut wrote:
> > Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
> > enables the PHY upon powerup and shuts it down on shutdown.
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > ---
> > 
> >  drivers/usb/otg/Kconfig   |   10 ++
> >  drivers/usb/otg/Makefile  |    1 +
> >  drivers/usb/otg/mxs-phy.c |  305
> >  +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 316
> >  insertions(+)
> >  create mode 100644 drivers/usb/otg/mxs-phy.c
> > 
> > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > index e7c6325..1de1495 100644
> > --- a/drivers/usb/otg/Kconfig
> > +++ b/drivers/usb/otg/Kconfig
> > @@ -122,6 +122,16 @@ config USB_IMX_COMPOSITE
> > 
> >  	  Composite driver that handles clock and memory mapping for
> >  	  i.MX USB host and USB PHY.
> > 
> > +config USB_MXS_PHY
> > +	tristate "Freescale i.MX28 USB PHY support"
> > +	select USB_OTG_UTILS
> > +	select USB_IMX_COMPOSITE
> > +	help
> > +	  Say Y here if you want to build Freescale i.MX28 USB PHY
> > +	  driver in kernel.
> > +
> > +	  To compile this driver as a module, choose M here.
> > +
> > 
> >  config USB_MV_OTG
> >  
> >  	tristate "Marvell USB OTG support"
> >  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> > 
> > diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> > index e3feaca..56700b3 100644
> > --- a/drivers/usb/otg/Makefile
> > +++ b/drivers/usb/otg/Makefile
> > @@ -21,4 +21,5 @@ obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
> > 
> >  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
> >  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> >  obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-usb.o
> > 
> > +obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
> > 
> >  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> > 
> > +
> > +struct mxs_usb_phy {
> > +	struct usb_phy		phy;
> > +
> > +	struct work_struct	work;
> > +
> > +	struct clk		*clk;
> > +	struct resource		*mem_res;
> > +	void __iomem		*mem;
> > +	int			irq;
> 
> irq is unused.
> 
> > +
> > +static void mxs_usb_work(struct work_struct *w)
> > +{
> > +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
> > +	struct usb_otg *otg = phy->phy.otg;
> > +	struct usb_hcd *hcd;
> > +
> > +	switch (otg->phy->state) {
> > +	case OTG_STATE_A_HOST:
> > +		if (otg->host) {
> > +			hcd = bus_to_hcd(otg->host);
> > +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> > +		}
> > +		break;
> > +	default:
> > +		break;
> > +	}
> > +}
> 
> This function should be in imx-otg.

You mean imx-usb? What'd it do in there?

> > +
> > +static int __devinit mxs_phy_probe(struct platform_device *pdev)
> > +{
> > +	struct mxs_usb_phy *phy;
> > +	void *retp;
> > +	int ret;
> > +
> > +	/* Allocate PHY driver's private date. */
> > +	phy = kzalloc(sizeof(*phy), GFP_KERNEL);
> 
> devm?
> 
> > +	if (!phy) {
> > +		dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
> > +		ret = -ENOMEM;
> > +		goto err_alloc_phy;
> > +	}
> > +
> > +	/* Allocate OTG structure. */
> > +	phy->phy.otg = kzalloc(sizeof(*phy->phy.otg), GFP_KERNEL);
> 
> devm?
> 
> > +	if (!phy->phy.otg) {
> > +		dev_err(&pdev->dev, "Failed to allocate USB OTG structure!\n");
> > +		ret = -ENOMEM;
> > +		goto err_alloc_otg;
> > +	}
> > +
> > +	/* Claim the PHY clock. */
> > +	phy->clk = clk_get(&pdev->dev, "phy");
> > +	if (!phy->clk) {
> > +		dev_err(&pdev->dev, "Failed to claim clock for USB PHY\n");
> > +		ret = PTR_ERR(phy->clk);
> > +		goto err_claim_phy_clock;
> > +	}
> > +
> > +	/* Prepare PHY clock. */
> > +	ret = clk_prepare(phy->clk);
> 
> It should be clear that a function named clk_prepare prepares the clock.
> Please remove such comments.
> 
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "Failed to prepare clock for USB PHY.\n");
> > +		goto err_prepare_phy_clock;
> > +	}
> > +
> > +	/* Get memory area for PHY from resources. */
> > +	phy->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > +	if (!phy->mem_res) {
> > +		dev_err(&pdev->dev, "Specify memory area for this USB PHY!\n");
> > +		ret = -ENODEV;
> > +		goto err_get_phy_resource;
> > +	}
> > +
> > +	/* Request the memory region for this USB PHY. */
> > +	retp = devm_request_mem_region(&pdev->dev, phy->mem_res->start,
> > +			resource_size(phy->mem_res), pdev->name);
> 
> The 'm' in devm is for 'managed' which means that these resources are
> automatically released on driver exit. You don't have to release them
> manually. In fact you must not release them with the regular functions.
> If you want to release them manually you have to use the devm variants.
> 
> Sascha

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18 19:50       ` Sascha Hauer
@ 2012-04-18 20:07         ` Marek Vasut
  2012-04-18 20:43           ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-18 20:07 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> On Wed, Apr 18, 2012 at 07:46:32PM +0200, Marek Vasut wrote:
> > This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to
> > keep this separate from the MXC EHCI to avoid further polution of the
> > MXC EHCI, though eventually these two might be merged.
> > 
> > NOTE: I still haven't figured out how to enable/disable the disconnection
> > detector, it can't be enabled all the time, so I toggle PHY stuff from
> > this driver, which I doubt is correct.
> 
> [...]
> 
> > +static int ehci_mxs_drv_probe(struct platform_device *pdev)
> > +{
> > +	struct device *dev = &pdev->dev;
> > +	struct imx_usb *data = pdev->dev.platform_data;
> > +	struct usb_hcd *hcd;
> > +	struct ehci_hcd *ehci;
> > +	struct usb_phy *phy;
> > +	int ret;
> > +
> > +	dev_info(dev, "Initializing i.MX28 USB Controller\n");
> 
> This is not (only) i.MX28

Let's keep it like that until we get further testing on other platforms.

> 
> > +
> > +	if (!data) {
> > +		dev_err(dev, "USB Host platform data missing!\n");
> > +		return -ENODEV;
> > +	}
> > +
> > +	/* Create HCD controller instance. */
> > +	hcd = usb_create_hcd(&ehci_mxs_hc_driver, dev, dev_name(dev));
> > +	if (!hcd) {
> > +		dev_err(dev, "Failed to create HCD instance!\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	hcd->rsrc_start = data->mem_res->start;
> > +	hcd->rsrc_len = resource_size(data->mem_res);
> > +	hcd->regs = data->mem;
> > +	hcd->irq = data->irq;
> > +
> > +	clk_enable(data->clk);
> 
> The clock shouldn't be here. move this to imx-otg.c

I see.

> 
> > +
> > +	/* Wait for the controller to stabilize. */
> > +	mdelay(10);
> > +
> > +	ehci = hcd_to_ehci(hcd);
> > +
> > +	/* EHCI registers start at offset 0x100 */
> > +	ehci->caps = hcd->regs + 0x100;
> > +	ehci->regs = hcd->regs + 0x100 +
> > +		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
> > +
> > +	platform_set_drvdata(pdev, hcd);
> > +
> > +	/* Initialize the transceiver */
> > +#ifdef CONFIG_USB_OTG_UTILS
> > +	phy = usb_get_transceiver();
> > +	if (!phy) {
> > +		dev_err(dev, "Unable to find transceiver.\n");
> > +		ret = -ENODEV;
> > +		goto err_phy;
> > +	}
> > +
> > +	ret = otg_set_host(phy->otg, &hcd->self);
> > +	if (ret < 0) {
> > +		dev_err(dev, "Unable to set transceiver host\n");
> > +		ret = -ENODEV;
> > +		goto err_phy_set_host;
> > +	}
> > +
> > +	ret = usb_phy_init(phy);
> > +	if (ret < 0) {
> > +		dev_err(dev, "Unable init transceiver\n");
> > +		ret = -ENODEV;
> > +		goto err_phy_init;
> > +	}
> > +#else
> > +	dev_info(dev, "USB_MXS_PHY must have CONFIG_USB_OTG_UTILS enabled\n");
> > +	goto err_phy;
> > +#endif
> 
> If your code does not work without CONFIG_USB_OTG_UTILS then why doesn't
> the driver depend on this option?
> It doesn't matter, all code inside these ifdefs should go to imx-otg.c.

Again, you mean imx-usb (the driver registering ehci host) or mxs-usb-phy? 
Either way, why should it be moved there, why shouldn't it sit in this file? Can 
you elaborate?

> > +
> > +	/* Set up the PORTSCx register */
> > +	ehci_writel(ehci, 0, &ehci->regs->port_status[0]);
> > +
> 
> Should also be in imx-otg.c

This is clearly EHCI thing, why?

> > +err_phy_init:
> > +err_phy_set_host:
> > +#ifdef CONFIG_USB_OTG_UTILS
> > +	if (phy)
> > +		usb_put_transceiver(phy);
> > +#endif
> > +err_phy:
> > +	clk_disable(data->clk);
> > +	usb_put_hcd(hcd);
> > +	return ret;
> > +}
> > +
> > +static int __exit ehci_mxs_drv_remove(struct platform_device *pdev)
> > +{
> > +	struct imx_usb *data = pdev->dev.platform_data;
> > +	struct usb_hcd *hcd = platform_get_drvdata(pdev);
> > +	struct usb_phy *phy = usb_get_transceiver();
> > +
> > +	if (phy)
> > +		usb_phy_shutdown(phy);
> > +
> > +	usb_remove_hcd(hcd);
> 
> usb_add_hcd is in imx-otg.c so usb_remove_hcd should be aswell.

Why would that be?

> Sascha

Best regards,
Marek Vasut

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

* [PATCH 07/10] MXS: Add USB PHY driver
  2012-04-18 20:02         ` Marek Vasut
@ 2012-04-18 20:16           ` Sascha Hauer
  2012-04-19 22:06             ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 18, 2012 at 10:02:02PM +0200, Marek Vasut wrote:
> Dear Sascha Hauer,
> 
> > > +static void mxs_usb_work(struct work_struct *w)
> > > +{
> > > +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
> > > +	struct usb_otg *otg = phy->phy.otg;
> > > +	struct usb_hcd *hcd;
> > > +
> > > +	switch (otg->phy->state) {
> > > +	case OTG_STATE_A_HOST:
> > > +		if (otg->host) {
> > > +			hcd = bus_to_hcd(otg->host);
> > > +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> > > +		}
> > > +		break;
> > > +	default:
> > > +		break;
> > > +	}
> > > +}
> > 
> > This function should be in imx-otg.
> 
> You mean imx-usb? What'd it do in there?

otg/imx-usb.c, yes (though I would prefer imx-otg.c)

It should be there because it's the imx-otg.c driver which manages the
state. The phy driver is only a helper.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18 20:07         ` Marek Vasut
@ 2012-04-18 20:43           ` Sascha Hauer
  0 siblings, 0 replies; 149+ messages in thread
From: Sascha Hauer @ 2012-04-18 20:43 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 18, 2012 at 10:07:30PM +0200, Marek Vasut wrote:
> Dear Sascha Hauer,
> 
> > On Wed, Apr 18, 2012 at 07:46:32PM +0200, Marek Vasut wrote:
> > > This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to
> > > keep this separate from the MXC EHCI to avoid further polution of the
> > > MXC EHCI, though eventually these two might be merged.
> > > 
> > > NOTE: I still haven't figured out how to enable/disable the disconnection
> > > detector, it can't be enabled all the time, so I toggle PHY stuff from
> > > this driver, which I doubt is correct.
> > 
> > [...]
> > 
> > > +static int ehci_mxs_drv_probe(struct platform_device *pdev)
> > > +{
> > > +	struct device *dev = &pdev->dev;
> > > +	struct imx_usb *data = pdev->dev.platform_data;
> > > +	struct usb_hcd *hcd;
> > > +	struct ehci_hcd *ehci;
> > > +	struct usb_phy *phy;
> > > +	int ret;
> > > +
> > > +	dev_info(dev, "Initializing i.MX28 USB Controller\n");
> > 
> > This is not (only) i.MX28
> 
> Let's keep it like that until we get further testing on other platforms.

I see no reason for doing that. It does work on all i.MX for sure.

> > > +		ret = -ENODEV;
> > > +		goto err_phy_init;
> > > +	}
> > > +#else
> > > +	dev_info(dev, "USB_MXS_PHY must have CONFIG_USB_OTG_UTILS enabled\n");
> > > +	goto err_phy;
> > > +#endif
> > 
> > If your code does not work without CONFIG_USB_OTG_UTILS then why doesn't
> > the driver depend on this option?
> > It doesn't matter, all code inside these ifdefs should go to imx-otg.c.
> 
> Again, you mean imx-usb (the driver registering ehci host) or mxs-usb-phy? 

I mean otg/imx-usb.c (and I'll stick with the name imx-otg)

> Either way, why should it be moved there, why shouldn't it sit in this file? Can 
> you elaborate?

It's the imx-otg driver that manages the state. It's the imx-otg driver
which knows how to configure the phy

> 
> > > +
> > > +	/* Set up the PORTSCx register */
> > > +	ehci_writel(ehci, 0, &ehci->regs->port_status[0]);
> > > +
> > 
> > Should also be in imx-otg.c
> 
> This is clearly EHCI thing, why?

This is not ehci specific. This is specific to the whole USB controller.
You have to set it up for device mode aswell, grep -i for portsc in
drivers/usb/gadget.

> > > +	struct usb_phy *phy = usb_get_transceiver();
> > > +
> > > +	if (phy)
> > > +		usb_phy_shutdown(phy);
> > > +
> > > +	usb_remove_hcd(hcd);
> > 
> > usb_add_hcd is in imx-otg.c so usb_remove_hcd should be aswell.
> 
> Why would that be?

Let me try to rephrase my intention:

We have to deal with a 2-in-1 device here, a usb host and a usb device
controller. Both share some resources, namely:

- the io space
- the clocks
- the interrupt
- while being a seperate device they both share the phy

Everything that is shared should be handled by imx-otg.c. Whenever
imx-otg.c detects host mode it passes control to the ehci driver. When
imx-otg.c detects that the device is unplugged then it should remove the
host via usb_remove_hcd. device mode would be similar.
For now we don't implement device mode and do not automatically detect
host/device mode which makes things simpler. Still the calls have to be
in the right place.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 00/10 V2]  MXS: Add i.MX28 USB Host driver
  2012-04-18 17:49     ` Marek Vasut
@ 2012-04-19  2:37       ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-19  2:37 UTC (permalink / raw)
  To: linux-arm-kernel

 
> >
> > - Now, the PHY and OTG is separated, it is better to put PHY driver to
> > drivers/usb/phy/
> 
> There is no drivers/usb/phy ...
> 
You can discuss with Felipe Balbi <balbi@ti.com>, if it is ok to create
it to put PHY driver.

> >
> > - mx23, mx28, mx6q uses the same PHY (FSL PHY), it is better to use the
> phy
> > driver name as imx-phy.c.
> 
> Why? mxs == mx23,28,6q and mxc == the rest ... seems to me to be pretty
> well
> rooted terminology already.
mx23, 28, 6q uses Freescale itself PHY. 
mxc uses chipidea PHY.
Originally, I thought it should use IP vendor's name. After thinking it more,
it is ok use mxs for mx23,28,6q's PHY.

> 
> >
> > > Marek Vasut (10):
> > >   MXS: Make clk_disable return integer
> > >   MXS: Add USB EHCI and USB PHY clock handling
> > >   MXS: Fixup i.MX233 USB base address name
> > >   MXS: Add data shared between imx-usb, PHY and EHCI driver
> > >   MXS: Add platform registration hooks for USB EHCI
> > >   MXS: Add composite imx-usb driver
> > >   MXS: Add USB PHY driver
> > >   MXS: Add separate MXS EHCI HCD driver
> > >   MXS: Enable USB on M28EVK
> > >   MXS: Enable USB on MX28EVK
> > >
> > >  arch/arm/mach-mxs/Kconfig                       |    4 +
> > >  arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
> > >  arch/arm/mach-mxs/devices-mx28.h                |    4 +
> > >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> > >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> > >  arch/arm/mach-mxs/devices/platform-usb.c        |   67 +++++
> > >  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> > >  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
> > >  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> > >  arch/arm/mach-mxs/mach-m28evk.c                 |    9 +
> > >  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
> > >  drivers/usb/host/Kconfig                        |    7 +
> > >  drivers/usb/host/ehci-hcd.c                     |    5 +
> > >  drivers/usb/host/ehci-mxs.c                     |  254
> > >
> > > +++++++++++++++++++
> > >
> > >  drivers/usb/otg/Kconfig                         |   16 ++
> > >  drivers/usb/otg/Makefile                        |    2 +
> > >  drivers/usb/otg/imx-usb.c                       |  303
> > >
> > > +++++++++++++++++++++++
> > >
> > >  drivers/usb/otg/mxs-phy.c                       |  201
> +++++++++++++++
> > >  include/linux/fsl_devices.h                     |   15 ++
> > >  19 files changed, 939 insertions(+), 9 deletions(-)
> > >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> > >  create mode 100644 drivers/usb/host/ehci-mxs.c
> > >  create mode 100644 drivers/usb/otg/imx-usb.c
> > >  create mode 100644 drivers/usb/otg/mxs-phy.c
> > >
> > > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > > Cc: Detlev Zundel <dzu@denx.de>
> > > Cc: Fabio Estevam <festevam@gmail.com>
> > > Cc: Li Frank-B20596 <B20596@freescale.com>
> > > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > > Cc: Linux USB <linux-usb@vger.kernel.org>
> > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > Cc: Shawn Guo <shawn.guo@freescale.com>
> > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > Cc: Stefano Babic <sbabic@denx.de>
> > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > Cc: Tony Lin <tony.lin@freescale.com>
> > > Cc: Wolfgang Denk <wd@denx.de>
> > > --
> > > 1.7.9.5
> 
> Best regards,
> Marek Vasut

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-18  9:45           ` Sascha Hauer
@ 2012-04-19  2:54             ` Chen Peter-B29397
  2012-04-19  6:34               ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-19  2:54 UTC (permalink / raw)
  To: linux-arm-kernel



 
> >
> > > > >
> > > > > This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I
> > > tried to
> > > > > keep
> > > > > this separate from the MXC EHCI to avoid further polution of the
> MXC
> > > EHCI,
> > > > > though eventually these two might be merged.
> > > > >
> > > > As mxc and mxs platforms use the same USB controller (chipidea's),
> I
> > > wonder if
> > > > you can use ehci-mxc, or change name from ehci-mxc to ehci-imx?
> > > > Sascha, what's your opinion?
> > >
> > > Maybe better ehci-imx. I think it's a good idea to not use the ehci-
> mxc
> > > glue code but instead write a mxs specific glue code with having in
> > > mind that later we want to drop ehci-mxc and use ehci-imx for all imx
> > > including mxs. This assumes the USB folks are ok with this, I don't
> > > know.
> > >
> > How about create a patch changing name from ehci-mxc to ehci-imx first,
> then add
> > mx28/mx23/mx6q host ehci driver. I can do it.
> 
> ehci-imx won't need clock handling and it won't need phy handling. Also
> the setup of the portsc register won't be in the new driver. The
> clk_get(dev, "usb_phy1") part is horribly broken anyway. It's more than
> just a rename.
>
It depends on how you want things to go on, you can
- Create ehci-mxs first, then clean up clk/phy at ehci-mxs/ehci-mxc after 
generic phy driver and i.mx usb DT support is added, then merge ehci-mxs
and ehci-mxc to one ehci-imx. Not sure usb maintainers agree it or not.
- Or rename ehci-mxc to ehci-imx, add mx28 support to ehci-imx. Then, 
clean up clk/phy after phy driver and DT support are ready. This way
the driver ehci-mxs will not appear at drivers/usb/host all the time.

 
> Sascha
> 
> --
> Pengutronix e.K.                           |
> |
> Industrial Linux Solutions                 | http://www.pengutronix.de/
> |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0
> |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555
> |

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

* [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver
  2012-04-19  2:54             ` Chen Peter-B29397
@ 2012-04-19  6:34               ` Sascha Hauer
  0 siblings, 0 replies; 149+ messages in thread
From: Sascha Hauer @ 2012-04-19  6:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Apr 19, 2012 at 02:54:18AM +0000, Chen Peter-B29397 wrote:
> 
> 
> > > >
> > > How about create a patch changing name from ehci-mxc to ehci-imx first,
> > then add
> > > mx28/mx23/mx6q host ehci driver. I can do it.
> > 
> > ehci-imx won't need clock handling and it won't need phy handling. Also
> > the setup of the portsc register won't be in the new driver. The
> > clk_get(dev, "usb_phy1") part is horribly broken anyway. It's more than
> > just a rename.
> >
> It depends on how you want things to go on, you can
> - Create ehci-mxs first, then clean up clk/phy at ehci-mxs/ehci-mxc after 
> generic phy driver and i.mx usb DT support is added, then merge ehci-mxs
> and ehci-mxc to one ehci-imx. Not sure usb maintainers agree it or not.

My idea is more to create a ehci-mxs and instead of cleaning up ehci-mxc
we switch i.MX over to the new driver and remove ehci-mxc.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-04-17 10:15 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
  2012-04-17 17:51   ` Sascha Hauer
@ 2012-04-19 11:40   ` Arnd Bergmann
  1 sibling, 0 replies; 149+ messages in thread
From: Arnd Bergmann @ 2012-04-19 11:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 17 April 2012, Marek Vasut wrote:
> + * PHY must be registered via subsys_initcall to get it running before EHCI
> + * controller driver.
> + */
> +subsys_initcall(mxs_phy_init);
> +module_exit(mxs_phy_exit);

I think this can be a regular module_init() now, if you change the main
driver to call an exported function from here that checks if the phy
has been probed, so you can return -EPROBE_DEFER from the main
probe function to be called again later.

	Arnd

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-18 17:46     ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
@ 2012-04-19 11:51       ` Arnd Bergmann
  2012-04-19 14:24         ` Shawn Guo
  0 siblings, 1 reply; 149+ messages in thread
From: Arnd Bergmann @ 2012-04-19 11:51 UTC (permalink / raw)
  To: linux-arm-kernel

On Wednesday 18 April 2012, Marek Vasut wrote:
>  arch/arm/mach-mxs/devices-mx28.h                |    4 ++
>  arch/arm/mach-mxs/devices/Kconfig               |    3 +
>  arch/arm/mach-mxs/devices/Makefile              |    1 +
>  arch/arm/mach-mxs/devices/platform-usb.c        |   78 +++++++++++++++++++++++
>  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +++
>  5 files changed, 95 insertions(+)
>  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c

What's the state of the device tree support for mach-mxs now? Since we
allow booting at least the mx28evk with device tree now in -next, it
would be really nice if we didn't have to add this registration code
for non-DT platforms any more and just mandate that everyone who
wants to use USB on that board uses DT. Is that possible already
or are we missing too much other stuff?

	Arnd

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-19 11:51       ` Arnd Bergmann
@ 2012-04-19 14:24         ` Shawn Guo
  2012-04-19 21:32           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Shawn Guo @ 2012-04-19 14:24 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Apr 19, 2012 at 11:51:46AM +0000, Arnd Bergmann wrote:
> On Wednesday 18 April 2012, Marek Vasut wrote:
> >  arch/arm/mach-mxs/devices-mx28.h                |    4 ++
> >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> >  arch/arm/mach-mxs/devices/platform-usb.c        |   78 +++++++++++++++++++++++
> >  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +++
> >  5 files changed, 95 insertions(+)
> >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> 
> What's the state of the device tree support for mach-mxs now?

The pinctrl-mxs (DT only) was just posted today.  The gpio-mxs will
be the next one I will work on, and I think Dong Aisheng is adding
DT support for mxs-dma and mxs-mmc.  I believe we will reach a pretty
good state when in the v3.5 merge window.

> Since we
> allow booting at least the mx28evk with device tree now in -next, it
> would be really nice if we didn't have to add this registration code
> for non-DT platforms any more and just mandate that everyone who
> wants to use USB on that board uses DT.

I share the same view on this.

Regards,
Shawn

> Is that possible already
> or are we missing too much other stuff?
> 

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-19 14:24         ` Shawn Guo
@ 2012-04-19 21:32           ` Marek Vasut
  2012-04-20  0:40             ` Shawn Guo
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-19 21:32 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Shawn Guo,

> On Thu, Apr 19, 2012 at 11:51:46AM +0000, Arnd Bergmann wrote:
> > On Wednesday 18 April 2012, Marek Vasut wrote:
> > >  arch/arm/mach-mxs/devices-mx28.h                |    4 ++
> > >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> > >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> > >  arch/arm/mach-mxs/devices/platform-usb.c        |   78
> > >  +++++++++++++++++++++++
> > >  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +++
> > >  5 files changed, 95 insertions(+)
> > >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> > 
> > What's the state of the device tree support for mach-mxs now?
> 
> The pinctrl-mxs (DT only) was just posted today.  The gpio-mxs will
> be the next one I will work on, and I think Dong Aisheng is adding
> DT support for mxs-dma and mxs-mmc.  I believe we will reach a pretty
> good state when in the v3.5 merge window.

This is very good to hear, I'm really interested to see this development :)

> > Since we
> > allow booting at least the mx28evk with device tree now in -next, it
> > would be really nice if we didn't have to add this registration code
> > for non-DT platforms any more and just mandate that everyone who
> > wants to use USB on that board uses DT.
> 
> I share the same view on this.

The Device Tree code for MXS is not ripe yet. We still miss a lot in there. 
Flipping this usb stuff to DT should be easy, I see no point disallowing this 
(and that stands also for the MXS SPI actually) into kernel so more people can 
test it only because you'd like this to wait for who knows how long for the DT 
support to arrive. Don't take it personally, but I still believe it's too early 
to enforce DT on MXS.

> Regards,
> Shawn
> 
> > Is that possible already
> > or are we missing too much other stuff?

Best regards,
Marek Vasut

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

* [PATCH 07/10] MXS: Add USB PHY driver
  2012-04-18 20:16           ` Sascha Hauer
@ 2012-04-19 22:06             ` Marek Vasut
  2012-04-20  2:35               ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-19 22:06 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> On Wed, Apr 18, 2012 at 10:02:02PM +0200, Marek Vasut wrote:
> > Dear Sascha Hauer,
> > 
> > > > +static void mxs_usb_work(struct work_struct *w)
> > > > +{
> > > > +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy,
> > > > work); +	struct usb_otg *otg = phy->phy.otg;
> > > > +	struct usb_hcd *hcd;
> > > > +
> > > > +	switch (otg->phy->state) {
> > > > +	case OTG_STATE_A_HOST:
> > > > +		if (otg->host) {
> > > > +			hcd = bus_to_hcd(otg->host);
> > > > +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> > > > +		}
> > > > +		break;
> > > > +	default:
> > > > +		break;
> > > > +	}
> > > > +}
> > > 
> > > This function should be in imx-otg.
> > 
> > You mean imx-usb? What'd it do in there?
> 
> otg/imx-usb.c, yes (though I would prefer imx-otg.c)
> 
> It should be there because it's the imx-otg.c driver which manages the
> state. The phy driver is only a helper.

I believe the imx-otg should only call otg_set_host()/otg_set_peripheral() on 
the particular PHY, in this case mxs-usb-phy, correct? The mxs_usb_work() should 
stay in the PHY's driver, because it'll likely frob with the PHY's own registers 
once peripheral support is added.

> 
> Sascha

Best regards,
Marek Vasut

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-19 21:32           ` Marek Vasut
@ 2012-04-20  0:40             ` Shawn Guo
  2012-04-20  0:56               ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Shawn Guo @ 2012-04-20  0:40 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Apr 19, 2012 at 11:32:56PM +0200, Marek Vasut wrote:
> The Device Tree code for MXS is not ripe yet. We still miss a lot in there. 
> Flipping this usb stuff to DT should be easy, I see no point disallowing this 
> (and that stands also for the MXS SPI actually) into kernel so more people can 
> test it only because you'd like this to wait for who knows how long for the DT 
> support to arrive. Don't take it personally, but I still believe it's too early 
> to enforce DT on MXS.
> 
Let me put it another way.  When you have drivers/usb changes hit
mainline, while there is still something not ripe for mxs DT support
while stops you adding DT support for usb driver, you have good reason
to ask me take the arch/arm/mach-mxs changes in this series then.

-- 
Regards,
Shawn

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-20  0:40             ` Shawn Guo
@ 2012-04-20  0:56               ` Marek Vasut
  2012-04-20  1:34                 ` Shawn Guo
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-20  0:56 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Shawn Guo,

> On Thu, Apr 19, 2012 at 11:32:56PM +0200, Marek Vasut wrote:
> > The Device Tree code for MXS is not ripe yet. We still miss a lot in
> > there. Flipping this usb stuff to DT should be easy, I see no point
> > disallowing this (and that stands also for the MXS SPI actually) into
> > kernel so more people can test it only because you'd like this to wait
> > for who knows how long for the DT support to arrive. Don't take it
> > personally, but I still believe it's too early to enforce DT on MXS.
> 
> Let me put it another way.  When you have drivers/usb changes hit
> mainline, while there is still something not ripe for mxs DT support
> while stops you adding DT support for usb driver, you have good reason
> to ask me take the arch/arm/mach-mxs changes in this series then.

Yes, I'm quite aware this stuff might take a bit to get into mainline shape. I 
grouped this and MXS SPI together, maybe the MXS SPI stuff is a better 
representation of what I had in mind (about letting non-DT stuff for mxs slide 
in).

Best regards,
Marek Vasut

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-20  0:56               ` Marek Vasut
@ 2012-04-20  1:34                 ` Shawn Guo
  2012-04-20  1:40                   ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Shawn Guo @ 2012-04-20  1:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 20, 2012 at 02:56:50AM +0200, Marek Vasut wrote:
> Dear Shawn Guo,
> 
> > On Thu, Apr 19, 2012 at 11:32:56PM +0200, Marek Vasut wrote:
> > > The Device Tree code for MXS is not ripe yet. We still miss a lot in
> > > there. Flipping this usb stuff to DT should be easy, I see no point
> > > disallowing this (and that stands also for the MXS SPI actually) into
> > > kernel so more people can test it only because you'd like this to wait
> > > for who knows how long for the DT support to arrive. Don't take it
> > > personally, but I still believe it's too early to enforce DT on MXS.
> > 
> > Let me put it another way.  When you have drivers/usb changes hit
> > mainline, while there is still something not ripe for mxs DT support
> > while stops you adding DT support for usb driver, you have good reason
> > to ask me take the arch/arm/mach-mxs changes in this series then.
> 
> Yes, I'm quite aware this stuff might take a bit to get into mainline shape. I 
> grouped this and MXS SPI together, maybe the MXS SPI stuff is a better 
> representation of what I had in mind (about letting non-DT stuff for mxs slide 
> in).
> 
I gave Fabio the same comment on his SPI patch.

-- 
Regards,
Shawn

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

* [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI
  2012-04-20  1:34                 ` Shawn Guo
@ 2012-04-20  1:40                   ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-20  1:40 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Shawn Guo,

> On Fri, Apr 20, 2012 at 02:56:50AM +0200, Marek Vasut wrote:
> > Dear Shawn Guo,
> > 
> > > On Thu, Apr 19, 2012 at 11:32:56PM +0200, Marek Vasut wrote:
> > > > The Device Tree code for MXS is not ripe yet. We still miss a lot in
> > > > there. Flipping this usb stuff to DT should be easy, I see no point
> > > > disallowing this (and that stands also for the MXS SPI actually) into
> > > > kernel so more people can test it only because you'd like this to
> > > > wait for who knows how long for the DT support to arrive. Don't take
> > > > it personally, but I still believe it's too early to enforce DT on
> > > > MXS.
> > > 
> > > Let me put it another way.  When you have drivers/usb changes hit
> > > mainline, while there is still something not ripe for mxs DT support
> > > while stops you adding DT support for usb driver, you have good reason
> > > to ask me take the arch/arm/mach-mxs changes in this series then.
> > 
> > Yes, I'm quite aware this stuff might take a bit to get into mainline
> > shape. I grouped this and MXS SPI together, maybe the MXS SPI stuff is a
> > better representation of what I had in mind (about letting non-DT stuff
> > for mxs slide in).
> 
> I gave Fabio the same comment on his SPI patch.

Well, let's see how it turns out, I have some questions for Sascha and after I 
sort these out, I'll send V4 of these

Best regards,
Marek Vasut

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

* [RFC PATCH 00/10 V3]  MXS: Add i.MX28 USB Host driver
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (9 preceding siblings ...)
  2012-04-18 17:46     ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
@ 2012-04-20  2:13     ` Marek Vasut
  2012-04-20  9:48       ` Sascha Hauer
  2012-04-21 13:53     ` Subodh Nijsure
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-20  2:13 UTC (permalink / raw)
  To: linux-arm-kernel

> This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
> generic USB PHY infrastructure.
> 
> V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> drivers. V3: Add the HCD on demand based on the PHY's state (only add HCD
> if it's host). Currently, only the HOST mode is supported.
> 
> Marek Vasut (10):
>   MXS: Make clk_disable return integer
>   MXS: Add USB EHCI and USB PHY clock handling
>   MXS: Fixup i.MX233 USB base address name
>   MXS: Add data shared between imx-usb and EHCI driver
>   MXS: Add platform registration hooks for USB EHCI
>   MXS: Add imx-usb driver
>   MXS: Add USB PHY driver
>   MXS: Add separate MXS EHCI HCD driver
>   MXS: Enable USB on M28EVK
>   MXS: Enable USB on MX28EVK
> 
>  arch/arm/mach-mxs/Kconfig                       |    4 +
>  arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
>  arch/arm/mach-mxs/devices-mx28.h                |    4 +
>  arch/arm/mach-mxs/devices/Kconfig               |    3 +
>  arch/arm/mach-mxs/devices/Makefile              |    1 +
>  arch/arm/mach-mxs/devices/platform-usb.c        |   78 ++++++
>  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
>  arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
>  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
>  arch/arm/mach-mxs/mach-m28evk.c                 |   15 ++
>  arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
>  drivers/usb/host/Kconfig                        |    7 +
>  drivers/usb/host/ehci-hcd.c                     |    5 +
>  drivers/usb/host/ehci-mxs.c                     |  228 +++++++++++++++++
>  drivers/usb/otg/Kconfig                         |   16 ++
>  drivers/usb/otg/Makefile                        |    2 +
>  drivers/usb/otg/imx-usb.c                       |  226 +++++++++++++++++
>  drivers/usb/otg/mxs-phy.c                       |  305
> +++++++++++++++++++++++ include/linux/fsl_devices.h                     | 
>  10 +
>  19 files changed, 952 insertions(+), 9 deletions(-)
>  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
>  create mode 100644 drivers/usb/host/ehci-mxs.c
>  create mode 100644 drivers/usb/otg/imx-usb.c
>  create mode 100644 drivers/usb/otg/mxs-phy.c
> 
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>

btw /wrt USB Gadget etc -- how does the drivers/usb/gadget/fsl_udc_core.c and 
drivers/usb/gadget/ci13xxx_* fit into the big picture? We're gonna use the 
ci13xxx stuff for Gadget on mx28, correct? Then how does fsl_udc_core.c fit in?

Best regards,
Marek Vasut

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

* [PATCH 07/10] MXS: Add USB PHY driver
  2012-04-19 22:06             ` Marek Vasut
@ 2012-04-20  2:35               ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-20  2:35 UTC (permalink / raw)
  To: linux-arm-kernel


 
> > On Wed, Apr 18, 2012 at 10:02:02PM +0200, Marek Vasut wrote:
> > > Dear Sascha Hauer,
> > >
> > > > > +static void mxs_usb_work(struct work_struct *w)
> > > > > +{
> > > > > +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy,
> > > > > work); +	struct usb_otg *otg = phy->phy.otg;
> > > > > +	struct usb_hcd *hcd;
> > > > > +
> > > > > +	switch (otg->phy->state) {
> > > > > +	case OTG_STATE_A_HOST:
> > > > > +		if (otg->host) {
> > > > > +			hcd = bus_to_hcd(otg->host);
> > > > > +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> > > > > +		}
> > > > > +		break;
> > > > > +	default:
> > > > > +		break;
> > > > > +	}
> > > > > +}
> > > >
> > > > This function should be in imx-otg.
> > >
> > > You mean imx-usb? What'd it do in there?
> >
> > otg/imx-usb.c, yes (though I would prefer imx-otg.c)
> >
> > It should be there because it's the imx-otg.c driver which manages the
> > state. The phy driver is only a helper.
> 
> I believe the imx-otg should only call otg_set_host()/otg_set_peripheral()
> on
> the particular PHY, in this case mxs-usb-phy, correct? The mxs_usb_work()
> should
> stay in the PHY's driver, because it'll likely frob with the PHY's own
> registers
> once peripheral support is added.
> 
mxs_usb_work() manages host/device state switch due to id/vbus (at register otgsc) changing.
It is better to put it at otg driver.

> >
> > Sascha
> 
> Best regards,
> Marek Vasut

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

* [RFC PATCH 00/10 V3]  MXS: Add i.MX28 USB Host driver
  2012-04-20  2:13     ` [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver Marek Vasut
@ 2012-04-20  9:48       ` Sascha Hauer
  2012-04-20 12:26         ` Peter Chen
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-20  9:48 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 20, 2012 at 04:13:56AM +0200, Marek Vasut wrote:
> > 
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> 
> btw /wrt USB Gadget etc -- how does the drivers/usb/gadget/fsl_udc_core.c and 
> drivers/usb/gadget/ci13xxx_* fit into the big picture? We're gonna use the 
> ci13xxx stuff for Gadget on mx28, correct? Then how does fsl_udc_core.c fit in?

>From what I have been told by a collegue the ci13xxx driver works
better, and from what I have seen the code looks better. So I think mxs
should use it. i.MX can then use it later aswell. We won't need the
fsl_udc_core driver anymore then.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver
  2012-04-20  9:48       ` Sascha Hauer
@ 2012-04-20 12:26         ` Peter Chen
  2012-04-20 12:44           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Peter Chen @ 2012-04-20 12:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 20, 2012 at 5:48 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:

>>
>> btw /wrt USB Gadget etc -- how does the drivers/usb/gadget/fsl_udc_core.c and
>> drivers/usb/gadget/ci13xxx_* fit into the big picture? We're gonna use the
>> ci13xxx stuff for Gadget on mx28, correct? Then how does fsl_udc_core.c fit in?
>
> From what I have been told by a collegue the ci13xxx driver works
> better, and from what I have seen the code looks better. So I think mxs
> should use it. i.MX can then use it later aswell. We won't need the
> fsl_udc_core driver anymore then.
>
Oh, I find I lost many discussions using company email.
>From the function and quality level, fsl_udc_core.c is absolutely the
best one for all
i.mx SoCs, as both internal and upstream fsl code use it.

It discussed before:
http://marc.info/?l=linux-usb&m=129906859817430&w=2

I just wonder if ci13xxx_udc.c can support fsl's well as it has below
at comment.

/*
 * Description: MIPS USB IP core family device controller
 *              Currently it only supports IP part number CI13412
 */
I will check with IC guys to see if i.mx's controller is compatible
with CI13412.
If fsl's compatible with CI13412, then mxs can try to use ci13xxx_udc.c to see
if there are any problems, If no problems with kinds of testing,
we can switch all i.mx SoC to ci13xxx_udc.c.

> Sascha
>
> --
> Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
> Industrial Linux Solutions ? ? ? ? ? ? ? ? | http://www.pengutronix.de/ ?|
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 ? ?|
> Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? | Fax: ? +49-5121-206917-5555 |
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html



-- 
BR,
Peter Chen

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

* [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver
  2012-04-20 12:26         ` Peter Chen
@ 2012-04-20 12:44           ` Marek Vasut
  2012-04-20 13:00             ` Robert Schwebel
  2012-04-20 13:26             ` Sascha Hauer
  0 siblings, 2 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-20 12:44 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Peter Chen,

> On Fri, Apr 20, 2012 at 5:48 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> >> btw /wrt USB Gadget etc -- how does the
> >> drivers/usb/gadget/fsl_udc_core.c and drivers/usb/gadget/ci13xxx_* fit
> >> into the big picture? We're gonna use the ci13xxx stuff for Gadget on
> >> mx28, correct? Then how does fsl_udc_core.c fit in?
> > 
> > From what I have been told by a collegue the ci13xxx driver works
> > better, and from what I have seen the code looks better. So I think mxs
> > should use it. i.MX can then use it later aswell. We won't need the
> > fsl_udc_core driver anymore then.
> 
> Oh, I find I lost many discussions using company email.
> From the function and quality level, fsl_udc_core.c is absolutely the
> best one for all
> i.mx SoCs, as both internal and upstream fsl code use it.

Internally though, it looks like crap. Also, ci13xxx and fsl_usb_core is 
duplicated stuff, correct?

> 
> It discussed before:
> http://marc.info/?l=linux-usb&m=129906859817430&w=2
> 
> I just wonder if ci13xxx_udc.c can support fsl's well as it has below
> at comment.
> 
> /*
>  * Description: MIPS USB IP core family device controller
>  *              Currently it only supports IP part number CI13412
>  */

It doesn't matter if it's MIPS or whatever it is. Broadcom also managed to hack 
AMBA bus onto mips core ;-)

> I will check with IC guys to see if i.mx's controller is compatible
> with CI13412.
> If fsl's compatible with CI13412, then mxs can try to use ci13xxx_udc.c to
> see if there are any problems, If no problems with kinds of testing,
> we can switch all i.mx SoC to ci13xxx_udc.c.

Sascha, did you need to patch this ci13xxx somehow to get it running on MXS ? Or 
what was it that said he got it somehow running?

> 
> > Sascha
> > 
> > --
> > Pengutronix e.K.                           |                            
> > | Industrial Linux Solutions                 |
> > http://www.pengutronix.de/  | Peiner Str. 6-8, 31137 Hildesheim, Germany
> > | Phone: +49-5121-206917-0    | Amtsgericht Hildesheim, HRA 2686        
> >   | Fax:   +49-5121-206917-5555 | --
> > To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> > the body of a message to majordomo at vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html

Best regards,
Marek Vasut

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

* [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver
  2012-04-20 12:44           ` Marek Vasut
@ 2012-04-20 13:00             ` Robert Schwebel
  2012-04-20 13:26             ` Sascha Hauer
  1 sibling, 0 replies; 149+ messages in thread
From: Robert Schwebel @ 2012-04-20 13:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 20, 2012 at 02:44:48PM +0200, Marek Vasut wrote:
> > From the function and quality level, fsl_udc_core.c is absolutely
> > the best one for all i.mx SoCs, as both internal and upstream fsl
> > code use it.
>
> Internally though, it looks like crap. Also, ci13xxx and fsl_usb_core
> is duplicated stuff, correct?

As far as I know, this is a "Synopsys USB 2.0 High Speed Altantic
Controller". There are different drivers in mainline for this core:

- ci13xxx_udc
- fsl_usb_core
- langwell_udc

I think there even was a fourth, but I can't remember which one.

All with a different level of abstraction and features.

rsc
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* 答复: [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-18  7:40     ` Sascha Hauer
@ 2012-04-20 13:10       ` Liu JunJie-B08287
  2012-04-20 16:25         ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Liu JunJie-B08287 @ 2012-04-20 13:10 UTC (permalink / raw)
  To: linux-arm-kernel

hi Sascha,
   As the previous mail Peter post, we have two concerns about the new arch of USB drvier as followed:
   1. If the USB clock and the PHY are centralized managed by the OTG driver, it will introduce an unnecessary dependency between gadget/host function and OTG driver.
       That means even gadget/host function is the individual function that customer wanted, we need add OTG driver as well, otherwise, without the PHY and clock support provided by OTG driver, the gadget/host function can't work at all. But from the general viewpoint, the gadget/host function is independent of OTG function, this unnecessary dependency or limitation for customer is not reasonable.
       Furthermore, this dependency will face much difficulty in some extreme case that some customer only needs host function only but with the OTG ID floating, it was a real case we encounted before.

   2. If the USB clock and the PHY are centralized managed by the OTG driver, it will introduce an unavoidable remote wakup issue that:
       Since the USB suspend is separated into two parts: the USB host controller suspend (set portsc.suspend bit to 1)  part which is controlled by host driver and PHY suspend part (set portsc.phcd to 1) which is controlled by OTG driver, during the system suspend, these two parts will be executed in sequence, but the interval between these two parts is out of control.
       Refer to USB spec 2.0, the remote wakeup can happen anytime after 5ms later from bus entered suspended state(set portsc.suspend bit to 1), it means it can happen before, after, even during PHY suspend part executing. Taking the following case into accounted, PHY suspend process is executing, the pseudo code as below:
       {
            ...
            some checking for the remote wakeup;
                                      <------------------ remote wakeup happen here
            set portsc.phcd to 1;
            ...
        }
        At such situation, one issue will be generated that the USB controller is pulling up the resume signal (K), but at the same time, the SW may set PHY to low power mode(set PHCD to 1), it may cause unpredictable result.
        As in our i.MX platform the response to this remote wakeup(pulling up K signal) is out of SW control, and it can happen at anytime (5ms later after bus in suspended state), this issue is unavoidable.

        The safest solution for this issue is setting portsc.phcd within 5ms after bus in suspended state(set portsc.suspend bit to 1), it requires USB host controller suspend and PHY suspend must be executed uninterruptably, natively they can't be separated.

     The above is the shortcoming we thought about the new arch, and we want to know what are you thinking about the shortcoming of current arch, what makes you think the current arch had to be changed.

________________________________________
???: Sascha Hauer [s.hauer at pengutronix.de]
????: 2012?4?18? 15:40
?: Chen Peter-B29397
Cc: Marek Vasut; linux-arm-kernel at lists.infradead.org; Detlev Zundel; Fabio Estevam; Li Frank-B20596; Linux USB; Guo Shawn-R65073; Shawn Guo; Stefano Babic; Subodh Nijsure; Heikki Krogerus; Liu JunJie-B08287; Shi Make-B15407
??: Re: [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver

On Wed, Apr 18, 2012@04:31:50AM +0000, Chen Peter-B29397 wrote:
>
> >
> > Your patches won't work when more than one USB port is enabled because
> > of the singular usb transceiver present in the kernel. That of course is
> > not your fault. I think Heikki (Added to Cc) is working on this issue,
> > but I don't know the status here.
> >
> > Another problem is that what you are doing does not integrate at all
> > with otg. I don't ask you to implement otg support because you are
> > likely not interested in this, but since you are adding a new ehci
> > glue driver anyway I suggest another approach:
> >
> > Put a driver under drivers/usb/otg which:
> >
> > - matches a 'imx-usb' device
> > - gets/enables all clocks needed for USB
> > - finds the transceiver
> > - registers a ehci device
> >
> > Future additions would be:
> >
> > - Put a USB_MODE_HOST/DEVICE flag into platform_data, and register a
> >   host or gadget driver depending on this flag
> > - Add a USB_MODE_OTG flag to platform_data and implement otg in this
> >   driver (or use whatever infrastructure present in the kernel then)
> >
> > This is similar to what msm does. This way we have the clocks and phys
> > handled where they are needed. We may use this code on i.MX later.
> >
> > We did this wrong on i.MX (and several other architectures) and getting
> > this right will be hard work. No need to introduce the same flaws again
> > with a new architecture.
> >
> Hi Sascha,
>
> We have been discussing i.mx usb re-structure at freescale internal during
> this periods, one side does not agree with otg driver manages PHY/clock
> solution due to below reasons:
>
> - May confuse the users who only use device or host function, the users may
> double "why I need to include otg file to support device/host only function"?

I can't find anything confusing in this.

>
> - For some special cases, like device sends resume signal(remote wakeup)
> after host suspend, but before otg suspend (system needs to refuse to suspend) .
> It needs to add hcd flag to judge if there is a remote wakeup after host suspend,
> and if the port is sending resume signal now (when the port is sending resume signal,
> we can't put power to low power mode). Is it suitable to put some hcd stuffs at otg driver?

I can't follow you here what the actual problem is, but since the otg
driver is the driver for host and gadget (which happens to pass control to
either the host or the gadget driver most of the time) it is ok to do
whatever it takes in the otg driver to make it work.

>
> - Any disadvantages three individual drivers manage PHY/clock separately after the generic PHY
> layer/FSL PHY driver have finished? It can define where to get/put PHY/clock operation at
> individual drivers clearly. When OTG switch, for host mode, the hcd struct (includes interrupt)
> will be free/created using usb_remove_hcd/usb_add_hcd, for device mode,
> we can deinit/init udc like current ci13xxx_udc.c at ci13xxx_vbus_session does.

I once made a quick hack using the msm otg driver on i.MX. I had to
comment out some msm specifics but after that it worked quite well.

Sascga

--
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver
  2012-04-20 12:44           ` Marek Vasut
  2012-04-20 13:00             ` Robert Schwebel
@ 2012-04-20 13:26             ` Sascha Hauer
  2012-04-20 16:36               ` Michael Grzeschik
  1 sibling, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-20 13:26 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 20, 2012 at 02:44:48PM +0200, Marek Vasut wrote:
> Dear Peter Chen,
> 
> > On Fri, Apr 20, 2012 at 5:48 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > >> btw /wrt USB Gadget etc -- how does the
> > >> drivers/usb/gadget/fsl_udc_core.c and drivers/usb/gadget/ci13xxx_* fit
> > >> into the big picture? We're gonna use the ci13xxx stuff for Gadget on
> > >> mx28, correct? Then how does fsl_udc_core.c fit in?
> > > 
> > > From what I have been told by a collegue the ci13xxx driver works
> > > better, and from what I have seen the code looks better. So I think mxs
> > > should use it. i.MX can then use it later aswell. We won't need the
> > > fsl_udc_core driver anymore then.
> > 
> > Oh, I find I lost many discussions using company email.
> > From the function and quality level, fsl_udc_core.c is absolutely the
> > best one for all
> > i.mx SoCs, as both internal and upstream fsl code use it.
> 
> Internally though, it looks like crap.

+1 on this.

> Also, ci13xxx and fsl_usb_core is duplicated stuff, correct?

Yes.

> 
> > I will check with IC guys to see if i.mx's controller is compatible
> > with CI13412.
> > If fsl's compatible with CI13412, then mxs can try to use ci13xxx_udc.c to
> > see if there are any problems, If no problems with kinds of testing,
> > we can switch all i.mx SoC to ci13xxx_udc.c.
> 
> Sascha, did you need to patch this ci13xxx somehow to get it running on MXS ? Or 
> what was it that said he got it somehow running?

It basically works out of the box. I think we have some patches for this
driver, maybe michael can comment on this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* 答复: [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-20 13:10       ` 答复: " Liu JunJie-B08287
@ 2012-04-20 16:25         ` Marek Vasut
  2012-04-23  2:02           ` Liu JunJie-B08287
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-20 16:25 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Liu JunJie-B08287,

> hi Sascha,
>    As the previous mail Peter post, we have two concerns about the new arch
> of USB drvier as followed: 1. If the USB clock and the PHY are centralized
> managed by the OTG driver, it will introduce an unnecessary dependency
> between gadget/host function and OTG driver. That means even gadget/host
> function is the individual function that customer wanted, we need add OTG
> driver as well, otherwise, without the PHY and clock support provided by
> OTG driver, the gadget/host function can't work at all. But from the
> general viewpoint, the gadget/host function is independent of OTG
> function, this unnecessary dependency or limitation for customer is not
> reasonable. Furthermore, this dependency will face much difficulty in some
> extreme case that some customer only needs host function only but with the
> OTG ID floating, it was a real case we encounted before.

Can't this be fixed by passing of proper platform data to the imx-otg?

> 
>    2. If the USB clock and the PHY are centralized managed by the OTG
> driver, it will introduce an unavoidable remote wakup issue that: Since
> the USB suspend is separated into two parts: the USB host controller
> suspend (set portsc.suspend bit to 1)  part which is controlled by host
> driver and PHY suspend part (set portsc.phcd to 1) which is controlled by
> OTG driver, during the system suspend, these two parts will be executed in
> sequence, but the interval between these two parts is out of control.
> Refer to USB spec 2.0, the remote wakeup can happen anytime after 5ms
> later from bus entered suspended state(set portsc.suspend bit to 1), it
> means it can happen before, after, even during PHY suspend part executing.
> Taking the following case into accounted, PHY suspend process is
> executing, the pseudo code as below: {
>             ...
>             some checking for the remote wakeup;
>                                       <------------------ remote wakeup
> happen here set portsc.phcd to 1;
>             ...
>         }

Do we support this yet? Besides, you can make sure phy suspends before the 
controller ... and if the controller detects RW during suspend, it can fail to 
suspend and that brings the system back up.

>         At such situation, one issue will be generated that the USB
> controller is pulling up the resume signal (K), but at the same time, the
> SW may set PHY to low power mode(set PHCD to 1), it may cause
> unpredictable result. As in our i.MX platform the response to this remote
> wakeup(pulling up K signal) is out of SW control, and it can happen at
> anytime (5ms later after bus in suspended state), this issue is
> unavoidable.
> 
>         The safest solution for this issue is setting portsc.phcd within
> 5ms after bus in suspended state(set portsc.suspend bit to 1), it requires
> USB host controller suspend and PHY suspend must be executed
> uninterruptably, natively they can't be separated.
> 
>      The above is the shortcoming we thought about the new arch, and we
> want to know what are you thinking about the shortcoming of current arch,
> what makes you think the current arch had to be changed.
> 
> ________________________________________
> ???: Sascha Hauer [s.hauer at pengutronix.de]
> ????: 2012?4?18? 15:40
> ?: Chen Peter-B29397
> Cc: Marek Vasut; linux-arm-kernel at lists.infradead.org; Detlev Zundel; Fabio
> Estevam; Li Frank-B20596; Linux USB; Guo Shawn-R65073; Shawn Guo; Stefano
> Babic; Subodh Nijsure; Heikki Krogerus; Liu JunJie-B08287; Shi Make-B15407
> ??: Re: [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
> 
> On Wed, Apr 18, 2012 at 04:31:50AM +0000, Chen Peter-B29397 wrote:
> > > Your patches won't work when more than one USB port is enabled because
> > > of the singular usb transceiver present in the kernel. That of course
> > > is not your fault. I think Heikki (Added to Cc) is working on this
> > > issue, but I don't know the status here.
> > > 
> > > Another problem is that what you are doing does not integrate at all
> > > with otg. I don't ask you to implement otg support because you are
> > > likely not interested in this, but since you are adding a new ehci
> > > glue driver anyway I suggest another approach:
> > > 
> > > Put a driver under drivers/usb/otg which:
> > > 
> > > - matches a 'imx-usb' device
> > > - gets/enables all clocks needed for USB
> > > - finds the transceiver
> > > - registers a ehci device
> > > 
> > > Future additions would be:
> > > 
> > > - Put a USB_MODE_HOST/DEVICE flag into platform_data, and register a
> > > 
> > >   host or gadget driver depending on this flag
> > > 
> > > - Add a USB_MODE_OTG flag to platform_data and implement otg in this
> > > 
> > >   driver (or use whatever infrastructure present in the kernel then)
> > > 
> > > This is similar to what msm does. This way we have the clocks and phys
> > > handled where they are needed. We may use this code on i.MX later.
> > > 
> > > We did this wrong on i.MX (and several other architectures) and getting
> > > this right will be hard work. No need to introduce the same flaws again
> > > with a new architecture.
> > 
> > Hi Sascha,
> > 
> > We have been discussing i.mx usb re-structure at freescale internal
> > during this periods, one side does not agree with otg driver manages
> > PHY/clock solution due to below reasons:
> > 
> > - May confuse the users who only use device or host function, the users
> > may double "why I need to include otg file to support device/host only
> > function"?
> 
> I can't find anything confusing in this.
> 
> > - For some special cases, like device sends resume signal(remote wakeup)
> > after host suspend, but before otg suspend (system needs to refuse to
> > suspend) . It needs to add hcd flag to judge if there is a remote wakeup
> > after host suspend, and if the port is sending resume signal now (when
> > the port is sending resume signal, we can't put power to low power
> > mode). Is it suitable to put some hcd stuffs at otg driver?
> 
> I can't follow you here what the actual problem is, but since the otg
> driver is the driver for host and gadget (which happens to pass control to
> either the host or the gadget driver most of the time) it is ok to do
> whatever it takes in the otg driver to make it work.
> 
> > - Any disadvantages three individual drivers manage PHY/clock separately
> > after the generic PHY layer/FSL PHY driver have finished? It can define
> > where to get/put PHY/clock operation at individual drivers clearly. When
> > OTG switch, for host mode, the hcd struct (includes interrupt) will be
> > free/created using usb_remove_hcd/usb_add_hcd, for device mode, we can
> > deinit/init udc like current ci13xxx_udc.c at ci13xxx_vbus_session does.
> 
> I once made a quick hack using the msm otg driver on i.MX. I had to
> comment out some msm specifics but after that it worked quite well.
> 
> Sascga
> 
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Best regards,
Marek Vasut

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

* [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver
  2012-04-20 13:26             ` Sascha Hauer
@ 2012-04-20 16:36               ` Michael Grzeschik
  2012-04-21  7:42                 ` Peter Chen
  0 siblings, 1 reply; 149+ messages in thread
From: Michael Grzeschik @ 2012-04-20 16:36 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Apr 20, 2012 at 03:26:47PM +0200, Sascha Hauer wrote:
> On Fri, Apr 20, 2012 at 02:44:48PM +0200, Marek Vasut wrote:
> > Dear Peter Chen,
> > 
> > > On Fri, Apr 20, 2012 at 5:48 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > > >> btw /wrt USB Gadget etc -- how does the
> > > >> drivers/usb/gadget/fsl_udc_core.c and drivers/usb/gadget/ci13xxx_* fit
> > > >> into the big picture? We're gonna use the ci13xxx stuff for Gadget on
> > > >> mx28, correct? Then how does fsl_udc_core.c fit in?
> > > > 
> > > > From what I have been told by a collegue the ci13xxx driver works
> > > > better, and from what I have seen the code looks better. So I think mxs
> > > > should use it. i.MX can then use it later aswell. We won't need the
> > > > fsl_udc_core driver anymore then.
> > > 
> > > Oh, I find I lost many discussions using company email.
> > > From the function and quality level, fsl_udc_core.c is absolutely the
> > > best one for all
> > > i.mx SoCs, as both internal and upstream fsl code use it.
> > 
> > Internally though, it looks like crap.
> 
> +1 on this.

+1

We also made some tests with some gadget devices. IMHO we had troubles
with gadget_zero and testusb on the fsl_udc_core.c. I think the testusb
results should help to decide which is the most stable implementation.

> 
> > Also, ci13xxx and fsl_usb_core is duplicated stuff, correct?
> 
> Yes.
> 
> > 
> > > I will check with IC guys to see if i.mx's controller is compatible
> > > with CI13412.
> > > If fsl's compatible with CI13412, then mxs can try to use ci13xxx_udc.c to
> > > see if there are any problems, If no problems with kinds of testing,
> > > we can switch all i.mx SoC to ci13xxx_udc.c.
> > 
> > Sascha, did you need to patch this ci13xxx somehow to get it running on MXS ? Or 
> > what was it that said he got it somehow running?
> 
> It basically works out of the box. I think we have some patches for this
> driver, maybe michael can comment on this.

Yes, i have some smaller bugfix patches hanging around. I will send them
to the linux-usb mailinglist until the next week. Additionaly i have
some platform gluecode and a platform-support patch for the driver but you
probably have the same.

The ci13xxx_udc_driver has a flags element, which has to be set
appropriate to the used platform. On the mx23 for example we only were
able to get all testusb results correct, when the option
CI13XXX_DISABLE_STREAMING was set. In the OTG case the option
CI13XXX_REGS_SHARED is mandatory.

Regards,
Michael

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver
  2012-04-20 16:36               ` Michael Grzeschik
@ 2012-04-21  7:42                 ` Peter Chen
  2012-04-21  8:17                   ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Peter Chen @ 2012-04-21  7:42 UTC (permalink / raw)
  To: linux-arm-kernel

>
> > > Dear Peter Chen,
> > >
> > > > On Fri, Apr 20, 2012 at 5:48 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> > > > >> btw /wrt USB Gadget etc -- how does the
> > > > >> drivers/usb/gadget/fsl_udc_core.c and drivers/usb/gadget/ci13xxx_* fit
> > > > >> into the big picture? We're gonna use the ci13xxx stuff for Gadget on
> > > > >> mx28, correct? Then how does fsl_udc_core.c fit in?
> > > > >
> > > > > From what I have been told by a collegue the ci13xxx driver works
> > > > > better, and from what I have seen the code looks better. So I think mxs
> > > > > should use it. i.MX can then use it later aswell. We won't need the
> > > > > fsl_udc_core driver anymore then.
> > > >
> > > > Oh, I find I lost many discussions using company email.
> > > > From the function and quality level, fsl_udc_core.c is absolutely the
> > > > best one for all
> > > > i.mx SoCs, as both internal and upstream fsl code use it.
> > >
> > > Internally though, it looks like crap.
> >
> > +1 on this.
>
> +1
>
Your guys all consider ci13xxx is better than fsl_udc_core.c, can you
list some reasons?
Or just because it can compatible with your prefer OTG structure (like
msm_otg.c)?
>From my point, I also admit OTG structure like msm_otg.c is good one
and we can
follow it at i.mx USB structure.

>
> We also made some tests with some gadget devices. IMHO we had troubles
> with gadget_zero and testusb on the fsl_udc_core.c. I think the testusb
> results should help to decide which is the most stable implementation.
>
ci13xxx one is no problem? Have you checked why it failed at fsl_udc_core.c?

>
> >
> > > Also, ci13xxx and fsl_usb_core is duplicated stuff, correct?
> >
> > Yes.
> >
> > >
> > > > I will check with IC guys to see if i.mx's controller is compatible
> > > > with CI13412.
> > > > If fsl's compatible with CI13412, then mxs can try to use ci13xxx_udc.c to
> > > > see if there are any problems, If no problems with kinds of testing,
> > > > we can switch all i.mx SoC to ci13xxx_udc.c.
> > >
> > > Sascha, did you need to patch this ci13xxx somehow to get it running on MXS ? Or
> > > what was it that said he got it somehow running?
> >
> > It basically works out of the box. I think we have some patches for this
> > driver, maybe michael can comment on this.
>
> Yes, i have some smaller bugfix patches hanging around. I will send them
> to the linux-usb mailinglist until the next week. Additionaly i have
> some platform gluecode and a platform-support patch for the driver but you
> probably have the same.
>
> The ci13xxx_udc_driver has a flags element, which has to be set
> appropriate to the used platform. On the mx23 for example we only were
> able to get all testusb results correct, when the option
> CI13XXX_DISABLE_STREAMING was set. In the OTG case the option
> CI13XXX_REGS_SHARED is mandatory.

I have checked with IC guys, but they doesn't know something like
"CI13412" stands
for.
Yes, current many ARM SoC use chipidea SoC,  besides,
- ci13xxx_udc
- fsl_usb_core
- langwell_udc
marvell and Tegra are also use this. I have no maintain experiences on
abstract one IP driver
from kinds of SoC venders, if one SoC platform finds problem at
ci13xxx_udc core,
and submit the patch, it needs to verify at all SoC platforms, it may
increase difficulty
for review process and maintenance.
besides, in case this bug-fix is not compatible across kinds of SoC
vendors, how to do?
just add the fix at SoC vendor layer's code like ci13xxx_msm.c?


--
BR,
Peter Chen

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

* [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver
  2012-04-21  7:42                 ` Peter Chen
@ 2012-04-21  8:17                   ` Sascha Hauer
  0 siblings, 0 replies; 149+ messages in thread
From: Sascha Hauer @ 2012-04-21  8:17 UTC (permalink / raw)
  To: linux-arm-kernel

On Sat, Apr 21, 2012 at 03:42:46PM +0800, Peter Chen wrote:
> >
> Your guys all consider ci13xxx is better than fsl_udc_core.c, can you
> list some reasons?
> Or just because it can compatible with your prefer OTG structure (like
> msm_otg.c)?
> From my point, I also admit OTG structure like msm_otg.c is good one
> and we can
> follow it at i.mx USB structure.
> 
> >
> > We also made some tests with some gadget devices. IMHO we had troubles
> > with gadget_zero and testusb on the fsl_udc_core.c. I think the testusb
> > results should help to decide which is the most stable implementation.
> >
> ci13xxx one is no problem? Have you checked why it failed at fsl_udc_core.c?
> 
> >
> > >
> > > > Also, ci13xxx and fsl_usb_core is duplicated stuff, correct?
> > >
> > > Yes.
> > >
> > > >
> > > > > I will check with IC guys to see if i.mx's controller is compatible
> > > > > with CI13412.
> > > > > If fsl's compatible with CI13412, then mxs can try to use ci13xxx_udc.c to
> > > > > see if there are any problems, If no problems with kinds of testing,
> > > > > we can switch all i.mx SoC to ci13xxx_udc.c.
> > > >
> > > > Sascha, did you need to patch this ci13xxx somehow to get it running on MXS ? Or
> > > > what was it that said he got it somehow running?
> > >
> > > It basically works out of the box. I think we have some patches for this
> > > driver, maybe michael can comment on this.
> >
> > Yes, i have some smaller bugfix patches hanging around. I will send them
> > to the linux-usb mailinglist until the next week. Additionaly i have
> > some platform gluecode and a platform-support patch for the driver but you
> > probably have the same.
> >
> > The ci13xxx_udc_driver has a flags element, which has to be set
> > appropriate to the used platform. On the mx23 for example we only were
> > able to get all testusb results correct, when the option
> > CI13XXX_DISABLE_STREAMING was set. In the OTG case the option
> > CI13XXX_REGS_SHARED is mandatory.
> 
> I have checked with IC guys, but they doesn't know something like
> "CI13412" stands
> for.
> Yes, current many ARM SoC use chipidea SoC,  besides,
> - ci13xxx_udc
> - fsl_usb_core
> - langwell_udc
> marvell and Tegra are also use this. I have no maintain experiences on
> abstract one IP driver
> from kinds of SoC venders, if one SoC platform finds problem at
> ci13xxx_udc core,
> and submit the patch, it needs to verify at all SoC platforms, it may
> increase difficulty
> for review process and maintenance.

It's been some time since I last heard this argument...

Think about it, with this argument you could start writing your own
kernel, because how can you be sure that a change to the Linux Kernel
will work on your system?
You get much more maintainability from several SoCs sharing the same
code and more people fixing the bugs in your driver. Yes drivers do
occasionally break because a certain change is incompatible to a
particular SoC, but the advantages of sharing code outweigh this
multiple times.
(I didn't make this up myself, the Linux community *lives* this for many
years now)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [RFC PATCH 00/10 V3]  MXS: Add i.MX28 USB Host driver
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (10 preceding siblings ...)
  2012-04-20  2:13     ` [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver Marek Vasut
@ 2012-04-21 13:53     ` Subodh Nijsure
  2012-04-21 15:37       ` Marek Vasut
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
  12 siblings, 1 reply; 149+ messages in thread
From: Subodh Nijsure @ 2012-04-21 13:53 UTC (permalink / raw)
  To: linux-arm-kernel

On 04/18/2012 10:46 AM, Marek Vasut wrote:
> This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
> generic USB PHY infrastructure.
>
> V2: Introduce stub imx-usb driver that then registers the PHY and EHCI drivers.
> V3: Add the HCD on demand based on the PHY's state (only add HCD if it's host).
>      Currently, only the HOST mode is supported.
>
> Marek Vasut (10):
>    MXS: Make clk_disable return integer
>    MXS: Add USB EHCI and USB PHY clock handling
>    MXS: Fixup i.MX233 USB base address name
>    MXS: Add data shared between imx-usb and EHCI driver
>    MXS: Add platform registration hooks for USB EHCI
>    MXS: Add imx-usb driver
>    MXS: Add USB PHY driver
>    MXS: Add separate MXS EHCI HCD driver
>    MXS: Enable USB on M28EVK
>    MXS: Enable USB on MX28EVK
>
>   arch/arm/mach-mxs/Kconfig                       |    4 +
>   arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
>   arch/arm/mach-mxs/devices-mx28.h                |    4 +
>   arch/arm/mach-mxs/devices/Kconfig               |    3 +
>   arch/arm/mach-mxs/devices/Makefile              |    1 +
>   arch/arm/mach-mxs/devices/platform-usb.c        |   78 ++++++
>   arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
>   arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
>   arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
>   arch/arm/mach-mxs/mach-m28evk.c                 |   15 ++
>   arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
>   drivers/usb/host/Kconfig                        |    7 +
>   drivers/usb/host/ehci-hcd.c                     |    5 +
>   drivers/usb/host/ehci-mxs.c                     |  228 +++++++++++++++++
>   drivers/usb/otg/Kconfig                         |   16 ++
>   drivers/usb/otg/Makefile                        |    2 +
>   drivers/usb/otg/imx-usb.c                       |  226 +++++++++++++++++
>   drivers/usb/otg/mxs-phy.c                       |  305 +++++++++++++++++++++++
>   include/linux/fsl_devices.h                     |   10 +
>   19 files changed, 952 insertions(+), 9 deletions(-)
>   create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
>   create mode 100644 drivers/usb/host/ehci-mxs.c
>   create mode 100644 drivers/usb/otg/imx-usb.c
>   create mode 100644 drivers/usb/otg/mxs-phy.c
>
> Cc: Chen Peter-B29397<B29397@freescale.com>
> Cc: Detlev Zundel<dzu@denx.de>
> Cc: Fabio Estevam<festevam@gmail.com>
> Cc: Li Frank-B20596<B20596@freescale.com>
> Cc: Lin Tony-B19295<B19295@freescale.com>
> Cc: Linux USB<linux-usb@vger.kernel.org>
> Cc: Sascha Hauer<s.hauer@pengutronix.de>
> Cc: Shawn Guo<shawn.guo@freescale.com>
> Cc: Shawn Guo<shawn.guo@linaro.org>
> Cc: Stefano Babic<sbabic@denx.de>
> Cc: Subodh Nijsure<snijsure@grid-net.com>
> Cc: Tony Lin<tony.lin@freescale.com>
> Cc: Wolfgang Denk<wd@denx.de>
>

Tested this (v3) patch set on a MX28 based hardware that I have access 
to, and things worked as expected.

Tested-by:  Subodh Nijsure <snijsure@grid-net.com>

-Subodh

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

* [RFC PATCH 00/10 V3]  MXS: Add i.MX28 USB Host driver
  2012-04-21 13:53     ` Subodh Nijsure
@ 2012-04-21 15:37       ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-21 15:37 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Subodh Nijsure,

> On 04/18/2012 10:46 AM, Marek Vasut wrote:
> > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > the generic USB PHY infrastructure.
> > 
> > V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> > drivers. V3: Add the HCD on demand based on the PHY's state (only add
> > HCD if it's host).
> > 
> >      Currently, only the HOST mode is supported.
> > 
> > Marek Vasut (10):
> >    MXS: Make clk_disable return integer
> >    MXS: Add USB EHCI and USB PHY clock handling
> >    MXS: Fixup i.MX233 USB base address name
> >    MXS: Add data shared between imx-usb and EHCI driver
> >    MXS: Add platform registration hooks for USB EHCI
> >    MXS: Add imx-usb driver
> >    MXS: Add USB PHY driver
> >    MXS: Add separate MXS EHCI HCD driver
> >    MXS: Enable USB on M28EVK
> >    MXS: Enable USB on MX28EVK
> >   
> >   arch/arm/mach-mxs/Kconfig                       |    4 +
> >   arch/arm/mach-mxs/clock-mx28.c                  |   28 ++-
> >   arch/arm/mach-mxs/devices-mx28.h                |    4 +
> >   arch/arm/mach-mxs/devices/Kconfig               |    3 +
> >   arch/arm/mach-mxs/devices/Makefile              |    1 +
> >   arch/arm/mach-mxs/devices/platform-usb.c        |   78 ++++++
> >   arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> >   arch/arm/mach-mxs/include/mach/devices-common.h |    9 +
> >   arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> >   arch/arm/mach-mxs/mach-m28evk.c                 |   15 ++
> >   arch/arm/mach-mxs/mach-mx28evk.c                |   10 +
> >   drivers/usb/host/Kconfig                        |    7 +
> >   drivers/usb/host/ehci-hcd.c                     |    5 +
> >   drivers/usb/host/ehci-mxs.c                     |  228
> >   +++++++++++++++++ drivers/usb/otg/Kconfig                         |  
> >   16 ++
> >   drivers/usb/otg/Makefile                        |    2 +
> >   drivers/usb/otg/imx-usb.c                       |  226
> >   +++++++++++++++++ drivers/usb/otg/mxs-phy.c                       | 
> >   305 +++++++++++++++++++++++ include/linux/fsl_devices.h               
> >        |   10 +
> >   19 files changed, 952 insertions(+), 9 deletions(-)
> >   create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> >   create mode 100644 drivers/usb/host/ehci-mxs.c
> >   create mode 100644 drivers/usb/otg/imx-usb.c
> >   create mode 100644 drivers/usb/otg/mxs-phy.c
> > 
> > Cc: Chen Peter-B29397<B29397@freescale.com>
> > Cc: Detlev Zundel<dzu@denx.de>
> > Cc: Fabio Estevam<festevam@gmail.com>
> > Cc: Li Frank-B20596<B20596@freescale.com>
> > Cc: Lin Tony-B19295<B19295@freescale.com>
> > Cc: Linux USB<linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer<s.hauer@pengutronix.de>
> > Cc: Shawn Guo<shawn.guo@freescale.com>
> > Cc: Shawn Guo<shawn.guo@linaro.org>
> > Cc: Stefano Babic<sbabic@denx.de>
> > Cc: Subodh Nijsure<snijsure@grid-net.com>
> > Cc: Tony Lin<tony.lin@freescale.com>
> > Cc: Wolfgang Denk<wd@denx.de>
> 
> Tested this (v3) patch set on a MX28 based hardware that I have access
> to, and things worked as expected.
> 
> Tested-by:  Subodh Nijsure <snijsure@grid-net.com>

Thank you for your testing. Today, I was enlightened by some USB celestial being 
I guess ...  I finally got the UDC working and I see the whole big picture of 
how to implement this thing altogether :-) Expect V4 with some reworks, esp. 
about IRQ handling etc.

> 
> -Subodh

Best regards,
Marek Vasut

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
                       ` (11 preceding siblings ...)
  2012-04-21 13:53     ` Subodh Nijsure
@ 2012-04-22 12:59     ` Marek Vasut
  2012-04-22 12:59       ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
                         ` (12 more replies)
  12 siblings, 13 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
generic USB PHY infrastructure. Also added is glue code for CI13xxx driver, to
allow device mode. This patchset still does NOT support OTG mode, the
device/host mode is selected via platform data.

V2: Introduce stub imx-usb driver that then registers the PHY and EHCI drivers.
V3: Add the HCD on demand based on the PHY's state (only add HCD if it's host).
    Currently, only the HOST mode is supported.
V4: * Introduce ci13xxx gadget glue
    * Reorder patches in a more sensible order
    * Introduce platform data, containing VBUS GPIO and port mode (device/gadget)
    * Rename imx-usb to imx-otg
    * Drop mx28evk usb host patch
    * Use more devm_ function
    * Rework the mxs-phy to register the same interrupt as ehci-mxs (and
      effectivelly kill bogus otg_set_vbus() call from ehci-mxs ; use standard
      ehci irq handling in ehci-mxs)

Marek Vasut (11):
  MXS: Make clk_disable return integer
  MXS: Add USB EHCI and USB PHY clock handling
  MXS: Fixup i.MX233 USB base address name
  MXS: Add data shared between imx-otg and EHCI driver
  MXS: Modify the ci13xxx_udc to avoid adding UDC
  MXS: Add small registration glue for ci13xxx_udc
  MXS: Add separate MXS EHCI HCD driver
  MXS: Add imx-otg driver
  MXS: Add USB PHY driver
  MXS: Add platform registration hooks for USB EHCI
  MXS: Enable USB on M28EVK

 arch/arm/mach-mxs/Kconfig                       |    2 +
 arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
 arch/arm/mach-mxs/devices-mx28.h                |    5 +
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   84 +++++
 arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |   12 +
 arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
 arch/arm/mach-mxs/mach-m28evk.c                 |   20 ++
 drivers/usb/gadget/Kconfig                      |   17 +
 drivers/usb/gadget/Makefile                     |    1 +
 drivers/usb/gadget/ci13xxx_mxs.c                |   67 ++++
 drivers/usb/gadget/ci13xxx_udc.c                |   12 +-
 drivers/usb/gadget/ci13xxx_udc.h                |    1 +
 drivers/usb/host/Kconfig                        |    7 +
 drivers/usb/host/ehci-hcd.c                     |    5 +
 drivers/usb/host/ehci-mxs.c                     |  197 ++++++++++
 drivers/usb/otg/Kconfig                         |   16 +
 drivers/usb/otg/Makefile                        |    2 +
 drivers/usb/otg/imx-otg.c                       |  282 +++++++++++++++
 drivers/usb/otg/mxs-phy.c                       |  438 +++++++++++++++++++++++
 include/linux/fsl/mxs-usb.h                     |   46 +++
 23 files changed, 1243 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
 create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c
 create mode 100644 drivers/usb/host/ehci-mxs.c
 create mode 100644 drivers/usb/otg/imx-otg.c
 create mode 100644 drivers/usb/otg/mxs-phy.c
 create mode 100644 include/linux/fsl/mxs-usb.h

Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>

NOTE: Adding this ci13xxx-mxs driver was really helpful, it helped me to realise
      how this whole monster should look like in the end. Now the mxs-phy is
      also much more prepared for the OTG operation.

-- 
1.7.9.5

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

* [PATCH 01/11] MXS: Make clk_disable return integer
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-22 12:59       ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
                         ` (11 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

This allows subsequent USB clock patch to interchange enable() and disable()
calls without adding unnecessary switching cruft.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c         |    7 +++++--
 arch/arm/mach-mxs/include/mach/clock.h |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index cea29c9..43116ba 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -86,7 +86,7 @@ static int _raw_clk_enable(struct clk *clk)
 	return 0;
 }
 
-static void _raw_clk_disable(struct clk *clk)
+static int _raw_clk_disable(struct clk *clk)
 {
 	u32 reg;
 
@@ -95,6 +95,8 @@ static void _raw_clk_disable(struct clk *clk)
 		reg |= 1 << clk->enable_shift;
 		__raw_writel(reg, clk->enable_reg);
 	}
+
+	return 0;
 }
 
 /*
@@ -149,7 +151,7 @@ _CLK_ENABLE_PLL(pll1_clk, PLL1, EN_USB_CLKS)
 _CLK_ENABLE_PLL(pll2_clk, PLL2, CLKGATE)
 
 #define _CLK_DISABLE_PLL(name, r, g)					\
-static void name##_disable(struct clk *clk)				\
+static int name##_disable(struct clk *clk)				\
 {									\
 	__raw_writel(BM_CLKCTRL_##r##CTRL0_POWER,			\
 		     CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
@@ -161,6 +163,7 @@ static void name##_disable(struct clk *clk)				\
 		__raw_writel(BM_CLKCTRL_##r##CTRL0_##g,			\
 			CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
 									\
+	return 0;							\
 }
 
 _CLK_DISABLE_PLL(pll0_clk, PLL0, EN_USB_CLKS)
diff --git a/arch/arm/mach-mxs/include/mach/clock.h b/arch/arm/mach-mxs/include/mach/clock.h
index 592c9ab..21d1fad 100644
--- a/arch/arm/mach-mxs/include/mach/clock.h
+++ b/arch/arm/mach-mxs/include/mach/clock.h
@@ -50,7 +50,7 @@ struct clk {
 	int (*enable) (struct clk *);
 	/* Function ptr to disable the clock. Leave blank if clock can not
 	   be gated. */
-	void (*disable) (struct clk *);
+	int (*disable) (struct clk *);
 	/* Function ptr to set the parent clock of the clock. */
 	int (*set_parent) (struct clk *, struct clk *);
 };
-- 
1.7.9.5

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

* [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
  2012-04-22 12:59       ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-22 14:42         ` Shawn Guo
  2012-04-22 12:59       ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
                         ` (10 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index 43116ba..8784a72 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -577,6 +577,21 @@ static struct clk usb1_clk = {
 	.parent = &pll1_clk,
 };
 
+static struct clk usb_phy_clk0 = {
+	.parent = &pll0_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL0CTRL0,
+	.enable_shift = 18,
+};
+
+static struct clk usb_phy_clk1 = {
+	.parent = &pll1_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL1CTRL0,
+	.enable_shift = 18,
+};
 #define _DEFINE_CLOCK(name, er, es, p)					\
 	static struct clk name = {					\
 		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
@@ -636,8 +651,10 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-mmc.3", NULL, ssp3_clk)
 	_REGISTER_CLOCK("flexcan.0", NULL, can0_clk)
 	_REGISTER_CLOCK("flexcan.1", NULL, can1_clk)
-	_REGISTER_CLOCK(NULL, "usb0", usb0_clk)
-	_REGISTER_CLOCK(NULL, "usb1", usb1_clk)
+	_REGISTER_CLOCK("imx-otg.0", "usb", usb0_clk)
+	_REGISTER_CLOCK("imx-otg.1", "usb", usb1_clk)
+	_REGISTER_CLOCK("mxs-usb-phy.0", "phy", usb_phy_clk0)
+	_REGISTER_CLOCK("mxs-usb-phy.1", "phy", usb_phy_clk1)
 	_REGISTER_CLOCK("mxs-pwm.0", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.1", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.2", NULL, pwm_clk)
-- 
1.7.9.5

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

* [PATCH 03/11] MXS: Fixup i.MX233 USB base address name
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
  2012-04-22 12:59       ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
  2012-04-22 12:59       ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-22 12:59       ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
                         ` (9 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

Modify USB EHCI and USB PHY base addresses on the i.MX233 to nicely fit into the
whole USB registration scheme.

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-mxs/include/mach/mx23.h b/arch/arm/mach-mxs/include/mach/mx23.h
index 599094b..7955b75 100644
--- a/arch/arm/mach-mxs/include/mach/mx23.h
+++ b/arch/arm/mach-mxs/include/mach/mx23.h
@@ -64,8 +64,8 @@
 #define MX23_AUART1_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06c000)
 #define MX23_AUART2_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06e000)
 #define MX23_DUART_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x070000)
-#define MX23_USBPHY_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
-#define MX23_USBCTRL_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
+#define MX23_USBPHY0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
+#define MX23_USBCTRL0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
 #define MX23_DRAM_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x0e0000)
 
 #define MX23_IO_P2V(x)			MXS_IO_P2V(x)
@@ -89,8 +89,8 @@
 #define MX23_INT_SPDIF_ERROR		10
 #define MX23_INT_SAIF1_IRQ		10
 #define MX23_INT_SAIF2_IRQ		10
-#define MX23_INT_USB_CTRL		11
-#define MX23_INT_USB_WAKEUP		12
+#define MX23_INT_USB0			11
+#define MX23_INT_USB0_WAKEUP		12
 #define MX23_INT_GPMI_DMA		13
 #define MX23_INT_SSP1_DMA		14
 #define MX23_INT_SSP1_ERROR		15
-- 
1.7.9.5

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

* [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (2 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-22 14:39         ` Shawn Guo
  2012-04-22 12:59       ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
                         ` (8 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds common data shared between the MXS EHCI HCD driver,
the MXS USB Gadget driver and the imx-otg driver. These data allow
passing clock and memory stuff from imx-otg driver into the
host/gadget driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 include/linux/fsl/mxs-usb.h |   46 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 include/linux/fsl/mxs-usb.h

diff --git a/include/linux/fsl/mxs-usb.h b/include/linux/fsl/mxs-usb.h
new file mode 100644
index 0000000..8326a79
--- /dev/null
+++ b/include/linux/fsl/mxs-usb.h
@@ -0,0 +1,46 @@
+/*
+ * include/linux/fsl/mxs-usb.h
+ *
+ * Freescale i.MX USB driver shared data.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __INCLUDE_LINUX_FSL_MXS_USB_H__
+#define __INCLUDE_LINUX_FSL_MXS_USB_H__
+
+#include <linux/types.h>
+#include <linux/platform_device.h>
+
+struct imx_usb {
+	struct platform_device	*pdev_host;
+	struct platform_device	*pdev_gadget;
+
+	struct clk		*clk;
+	struct resource		*mem_res;
+	void __iomem		*mem;
+	int			irq;
+};
+
+struct imx_usb_platform_data {
+	uint32_t		gpio_vbus;
+	bool			gpio_vbus_inverted;
+	bool			host_mode;
+};
+
+#endif /* __INCLUDE_LINUX_FSL_MXS_USB_H__ */
-- 
1.7.9.5

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

* [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (3 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-22 12:59       ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
                         ` (7 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

On the i.MX platform, we are adding the UDC ourselves from the PHY driver. This
patch adds a flag into the ci13xxx_udc that avoids adding the UDC if set.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/gadget/ci13xxx_udc.c |   12 ++++++++----
 drivers/usb/gadget/ci13xxx_udc.h |    1 +
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index 243ef1a..94f8b19 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -2935,9 +2935,11 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
 			goto remove_dbg;
 	}
 
-	retval = usb_add_gadget_udc(dev, &udc->gadget);
-	if (retval)
-		goto remove_trans;
+	if (!(udc->udc_driver->flags & CI13XXX_DONT_REGISTER_GADGET)) {
+		retval = usb_add_gadget_udc(dev, &udc->gadget);
+		if (retval)
+			goto remove_trans;
+	}
 
 	pm_runtime_no_callbacks(&udc->gadget.dev);
 	pm_runtime_enable(&udc->gadget.dev);
@@ -2980,7 +2982,9 @@ static void udc_remove(void)
 		err("EINVAL");
 		return;
 	}
-	usb_del_gadget_udc(&udc->gadget);
+
+	if (!(udc->udc_driver->flags & CI13XXX_DONT_REGISTER_GADGET))
+		usb_del_gadget_udc(&udc->gadget);
 
 	if (udc->transceiver) {
 		otg_set_peripheral(udc->transceiver->otg, &udc->gadget);
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h
index 0d31af5..9f2efa2 100644
--- a/drivers/usb/gadget/ci13xxx_udc.h
+++ b/drivers/usb/gadget/ci13xxx_udc.h
@@ -108,6 +108,7 @@ struct ci13xxx_udc_driver {
 #define CI13XXX_REQUIRE_TRANSCEIVER	BIT(1)
 #define CI13XXX_PULLUP_ON_VBUS		BIT(2)
 #define CI13XXX_DISABLE_STREAMING	BIT(3)
+#define CI13XXX_DONT_REGISTER_GADGET	BIT(4)
 
 #define CI13XXX_CONTROLLER_RESET_EVENT		0
 #define CI13XXX_CONTROLLER_STOPPED_EVENT	1
-- 
1.7.9.5

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

* [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (4 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-23  1:46         ` Chen Peter-B29397
  2012-04-22 12:59       ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
                         ` (6 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds small registration glue for the ci13xxx_udc that is compatible
with the imx-otg driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/gadget/Kconfig       |   17 ++++++++++
 drivers/usb/gadget/Makefile      |    1 +
 drivers/usb/gadget/ci13xxx_mxs.c |   67 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 2633f75..d97abd8 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -494,6 +494,23 @@ config USB_CI13XXX_MSM
 	  dynamically linked module called "ci13xxx_msm" and force all
 	  gadget drivers to also be dynamically linked.
 
+config USB_CI13XXX_MXS
+	tristate "MIPS USB CI13xxx for i.MX23/28"
+	depends on ARCH_MXS
+	select USB_GADGET_DUALSPEED
+	select USB_IMX_COMPOSITE
+	help
+	  i.MX SoC has chipidea USB controller.  This driver uses
+	  ci13xxx_udc core.
+	  This driver depends on OTG driver for PHY initialization,
+	  clock management, powering up VBUS, and power management.
+	  This driver is not supported on boards like trout which
+	  has an external PHY.
+
+	  Say "y" to link the driver statically, or "m" to build a
+	  dynamically linked module called "ci13xxx_msm" and force all
+	  gadget drivers to also be dynamically linked.
+
 #
 # LAST -- dummy/emulated controller
 #
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index b7f6eef..1f159a9 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_USB_EG20T)		+= pch_udc.o
 obj-$(CONFIG_USB_MV_UDC)	+= mv_udc.o
 mv_udc-y			:= mv_udc_core.o
 obj-$(CONFIG_USB_CI13XXX_MSM)	+= ci13xxx_msm.o
+obj-$(CONFIG_USB_CI13XXX_MXS)	+= ci13xxx_mxs.o
 obj-$(CONFIG_USB_FUSB300)	+= fusb300_udc.o
 
 #
diff --git a/drivers/usb/gadget/ci13xxx_mxs.c b/drivers/usb/gadget/ci13xxx_mxs.c
new file mode 100644
index 0000000..35a3dd4
--- /dev/null
+++ b/drivers/usb/gadget/ci13xxx_mxs.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/usb/ulpi.h>
+#include <linux/fsl/mxs-usb.h>
+
+#include "ci13xxx_udc.c"
+
+#define MSM_USB_BASE	(udc->regs)
+
+static irqreturn_t mxs_udc_irq(int irq, void *data)
+{
+	return udc_irq();
+}
+
+static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
+	.name			= "ci13xxx-mxs",
+	.flags			= CI13XXX_REQUIRE_TRANSCEIVER |
+				  CI13XXX_DISABLE_STREAMING |
+				  CI13XXX_DONT_REGISTER_GADGET,
+};
+
+static int ci13xxx_mxs_probe(struct platform_device *pdev)
+{
+	struct imx_usb *data = pdev->dev.platform_data;
+	int ret;
+
+	ret = devm_request_irq(&pdev->dev, data->irq, mxs_udc_irq,
+				IRQF_SHARED, pdev->name, pdev);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to request IRQ!\n");
+		return ret;
+	}
+
+	ret = udc_probe(&ci13xxx_mxs_udc_driver, &pdev->dev, data->mem);
+	if (ret < 0)
+		dev_err(&pdev->dev, "Failed to probe CI13xxx-mxs!\n");
+
+	pm_runtime_no_callbacks(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
+	return ret;
+}
+
+static struct platform_driver ci13xxx_mxs_driver = {
+	.probe		= ci13xxx_mxs_probe,
+	.driver		= {
+		.name	= "ci13xxx-mxs",
+	},
+};
+
+static int __init ci13xxx_mxs_init(void)
+{
+	return platform_driver_register(&ci13xxx_mxs_driver);
+}
+
+module_init(ci13xxx_mxs_init);
+
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:ci13xxx-mxs");
-- 
1.7.9.5

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

* [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (5 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-23  1:44         ` Chen Peter-B29397
  2012-04-22 12:59       ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
                         ` (5 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to keep
this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
though eventually these two might be merged.

NOTE: I still haven't figured out how to enable/disable the disconnection
detector, it can't be enabled all the time, so I toggle PHY stuff from this
driver, which I doubt is correct.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/host/Kconfig    |    7 ++
 drivers/usb/host/ehci-hcd.c |    5 ++
 drivers/usb/host/ehci-mxs.c |  197 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 209 insertions(+)
 create mode 100644 drivers/usb/host/ehci-mxs.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f788eb8..85ed593 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -148,6 +148,13 @@ config USB_EHCI_MXC
 	---help---
 	  Variation of ARC USB block used in some Freescale chips.
 
+config USB_EHCI_MXS
+	bool "Support for Freescale i.MX28 on-chip EHCI USB controller"
+	depends on USB_EHCI_HCD && ARCH_MXS
+	select USB_EHCI_ROOT_HUB_TT
+	---help---
+	  Enable USB support for i.MX28.
+
 config USB_EHCI_HCD_OMAP
 	bool "EHCI support for OMAP3 and later chips"
 	depends on USB_EHCI_HCD && ARCH_OMAP
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 4a3bc5b..16e161c 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1268,6 +1268,11 @@ MODULE_LICENSE ("GPL");
 #define PLATFORM_DRIVER		ehci_mxc_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_MXS
+#include "ehci-mxs.c"
+#define PLATFORM_DRIVER		ehci_mxs_driver
+#endif
+
 #ifdef CONFIG_USB_EHCI_SH
 #include "ehci-sh.c"
 #define PLATFORM_DRIVER		ehci_hcd_sh_driver
diff --git a/drivers/usb/host/ehci-mxs.c b/drivers/usb/host/ehci-mxs.c
new file mode 100644
index 0000000..847cf9f
--- /dev/null
+++ b/drivers/usb/host/ehci-mxs.c
@@ -0,0 +1,197 @@
+/*
+ * Freescale i.MX28 EHCI driver
+ *
+ * Copyright (c) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * Based on MXC EHCI driver:
+ *
+ * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
+ * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, 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,
+ * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/slab.h>
+#include <linux/fsl/mxs-usb.h>
+
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#include <asm/mach-types.h>
+
+/* Called during probe() after chip reset completes */
+static int ehci_mxs_setup(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+
+	hcd->has_tt = 1;
+	ehci_setup(hcd);
+	ehci_port_power(ehci, 0);
+
+	return 0;
+}
+
+static irqreturn_t mxs_ehci_irq(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	struct usb_phy *phy = usb_get_transceiver();
+	uint32_t status;
+	static uint32_t discon;
+
+	if (phy && phy->otg && phy->otg->set_vbus) {
+		status = ehci_readl(ehci, &ehci->regs->status);
+		status = !!(status & STS_PCD);
+		if (status != discon) {
+			discon = status;
+			phy->otg->set_vbus(phy->otg, status);
+		}
+	}
+
+	return ehci_irq(hcd);
+}
+
+static const struct hc_driver ehci_mxs_hc_driver = {
+	.description	= hcd_name,
+	.product_desc	= "Freescale i.MX On-Chip EHCI Host Controller",
+	.hcd_priv_size	= sizeof(struct ehci_hcd),
+
+	/*
+	 * Generic hardware linkage
+	 */
+	.irq		= mxs_ehci_irq,
+	.flags		= HCD_USB2 | HCD_MEMORY,
+
+	/*
+	 * Basic lifecycle operations
+	 */
+	.reset		= ehci_mxs_setup,
+	.start		= ehci_run,
+	.stop		= ehci_stop,
+	.shutdown	= ehci_shutdown,
+
+	/*
+	 * managing i/o requests and associated device resources
+	 */
+	.urb_enqueue		= ehci_urb_enqueue,
+	.urb_dequeue		= ehci_urb_dequeue,
+	.endpoint_disable	= ehci_endpoint_disable,
+	.endpoint_reset		= ehci_endpoint_reset,
+
+	/*
+	 * scheduling support
+	 */
+	.get_frame_number	= ehci_get_frame,
+
+	/*
+	 * root hub support
+	 */
+	.hub_status_data	= ehci_hub_status_data,
+	.hub_control		= ehci_hub_control,
+	.bus_suspend		= ehci_bus_suspend,
+	.bus_resume		= ehci_bus_resume,
+	.relinquish_port	= ehci_relinquish_port,
+	.port_handed_over	= ehci_port_handed_over,
+
+	.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
+};
+
+static int ehci_mxs_drv_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct imx_usb *data = pdev->dev.platform_data;
+	struct usb_hcd *hcd;
+	struct ehci_hcd *ehci;
+	struct usb_phy *phy;
+	int ret;
+
+	dev_info(dev, "Initializing i.MX USB Controller\n");
+
+	if (!data) {
+		dev_err(dev, "USB Host platform data missing!\n");
+		return -ENODEV;
+	}
+
+	/* This should never fail. */
+	phy = usb_get_transceiver();
+	if (!phy) {
+		dev_err(&pdev->dev, "Unable to find transceiver.\n");
+		return -ENODEV;
+	}
+
+	/* Create HCD controller instance. */
+	hcd = usb_create_hcd(&ehci_mxs_hc_driver, dev, dev_name(dev));
+	if (!hcd) {
+		dev_err(dev, "Failed to create HCD instance!\n");
+		return -ENOMEM;
+	}
+
+	hcd->rsrc_start = data->mem_res->start;
+	hcd->rsrc_len = resource_size(data->mem_res);
+	hcd->regs = data->mem;
+	hcd->irq = data->irq;
+
+	/* Wait for the controller to stabilize. */
+	mdelay(10);
+
+	ehci = hcd_to_ehci(hcd);
+
+	/* EHCI registers start at offset 0x100 */
+	ehci->caps = hcd->regs + 0x100;
+	ehci->regs = hcd->regs + 0x100 +
+		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
+
+	platform_set_drvdata(pdev, hcd);
+
+	/* Connect this host to the PHY. */
+	ret = otg_set_host(phy->otg, &hcd->self);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Unable to set transceiver host\n");
+		usb_put_hcd(hcd);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int __exit ehci_mxs_drv_remove(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd = platform_get_drvdata(pdev);
+	struct usb_phy *phy = usb_get_transceiver();
+
+	if (phy)
+		usb_phy_shutdown(phy);
+
+	usb_remove_hcd(hcd);
+	usb_put_hcd(hcd);
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static struct platform_driver ehci_mxs_driver = {
+	.probe		= ehci_mxs_drv_probe,
+	.remove		= __exit_p(ehci_mxs_drv_remove),
+	.driver		= {
+		   .name	= "mxs-ehci",
+	},
+};
+
+MODULE_ALIAS("platform:mxs-ehci");
-- 
1.7.9.5

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (6 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-23  6:39         ` Sascha Hauer
  2012-04-22 12:59       ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
                         ` (4 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

This driver handles claiming of clocks and memory areas. These are later
properly delegated to it's child devices, the USB Host (ehci-mxs) and
USB Gadget (ci13xxx-mxs).

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |    6 +
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/imx-otg.c |  282 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 289 insertions(+)
 create mode 100644 drivers/usb/otg/imx-otg.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 5c87db0..e7c6325 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -116,6 +116,12 @@ config FSL_USB2_OTG
 	help
 	  Enable this to support Freescale USB OTG transceiver.
 
+config USB_IMX_COMPOSITE
+	bool
+	help
+	  Composite driver that handles clock and memory mapping for
+	  i.MX USB host and USB PHY.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 41aa509..7d2c631 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
 obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
+obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
new file mode 100644
index 0000000..249b6b5
--- /dev/null
+++ b/drivers/usb/otg/imx-otg.c
@@ -0,0 +1,282 @@
+/*
+ * drivers/usb/otg/imx-otg.c
+ *
+ * Freescale i.MX USB composite driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/usb.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/hcd.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fsl/mxs-usb.h>
+#include <linux/io.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+
+/*
+ * Allocate platform device with the DMA mask, this is borrowed from
+ * arch/arm/mach-mxs/devices.c
+ */
+static struct platform_device *__devinit add_platform_device(
+		const char *name, int id,
+		const void *data, size_t size_data, u64 dmamask)
+{
+	int ret = -ENOMEM;
+	struct platform_device *pdev;
+
+	pdev = platform_device_alloc(name, id);
+	if (!pdev)
+		goto err;
+
+	if (dmamask) {
+		/*
+		 * This memory isn't freed when the device is put,
+		 * I don't have a nice idea for that though.  Conceptually
+		 * dma_mask in struct device should not be a pointer.
+		 * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
+		 */
+		pdev->dev.dma_mask =
+			kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
+		if (!pdev->dev.dma_mask)
+			/* ret is still -ENOMEM; */
+			goto err;
+
+		*pdev->dev.dma_mask = dmamask;
+		pdev->dev.coherent_dma_mask = dmamask;
+	}
+
+	if (data) {
+		ret = platform_device_add_data(pdev, data, size_data);
+		if (ret)
+			goto err;
+	}
+
+	ret = platform_device_add(pdev);
+	if (ret) {
+err:
+		if (dmamask)
+			kfree(pdev->dev.dma_mask);
+		platform_device_put(pdev);
+		return ERR_PTR(ret);
+	}
+
+	return pdev;
+}
+
+static int __devinit imx_usb_probe(struct platform_device *pdev)
+{
+	struct imx_usb_platform_data *pdata = pdev->dev.platform_data;
+	struct imx_usb *data;
+	struct usb_phy *phy;
+	int ret;
+	void *retp = NULL;
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "No platform data supplied!\n");
+		return -ENODEV;
+	}
+
+	phy = usb_get_transceiver();
+	if (!phy)
+		return -EPROBE_DEFER;
+
+	/*
+	 * Until further notice, this claims all necessary resources.
+	 */
+
+	/* Allocate driver's private date. */
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		ret = -ENOMEM;
+		goto err_alloc_data;
+	}
+
+	/* Claim the Host clock. */
+	data->clk = clk_get(&pdev->dev, "usb");
+	if (IS_ERR(data->clk)) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB Host\n");
+		ret = PTR_ERR(data->clk);
+		goto err_claim_host_clock;
+	}
+
+	/* Prepare Host clock. */
+	ret = clk_prepare_enable(data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to enable clock for USB Host.\n");
+		goto err_prepare_host_clock;
+	}
+
+	/* Get memory area for EHCI host from resources. */
+	data->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!data->mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_resource;
+	}
+
+	/* Request the memory region for this USB Host. */
+	retp = devm_request_mem_region(&pdev->dev, data->mem_res->start,
+			resource_size(data->mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB Host memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_get_host_mem;
+	}
+
+	/* Map the memory region for USB Host. */
+	data->mem = devm_ioremap(&pdev->dev, data->mem_res->start,
+				resource_size(data->mem_res));
+	if (!data->mem) {
+		dev_err(&pdev->dev, "Memory mapping of USB Host failed!\n");
+		ret = -EFAULT;
+		goto err_map_host_mem;
+	}
+
+	/* Get IRQ for EHCI host from resources. */
+	data->irq = platform_get_irq(pdev, 0);
+	if (data->irq < 0) {
+		dev_err(&pdev->dev, "Specify IRQ for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_irq;
+	}
+
+	/*
+	 * Now finally probe the Host driver!
+	 */
+	if (pdata->host_mode) {
+		data->pdev_host = add_platform_device("mxs-ehci", -1,
+							data, sizeof(*data),
+							DMA_BIT_MASK(32));
+		if (!data->pdev_host) {
+			dev_err(&pdev->dev, "Failed registering Host!\n");
+			ret = -ENODEV;
+			goto err_register_host;
+		}
+	} else {
+		data->pdev_gadget = add_platform_device("ci13xxx-mxs", -1,
+							data, sizeof(*data),
+							DMA_BIT_MASK(32));
+		if (!data->pdev_gadget) {
+			dev_err(&pdev->dev, "Failed registering Host!\n");
+			ret = -ENODEV;
+			goto err_register_gadget;
+		}
+	}
+
+	/*
+	 * Initialize the transceiver
+	 */
+	phy = usb_get_transceiver();
+	if (!phy) {
+		dev_err(&pdev->dev, "Unable to find transceiver.\n");
+		ret = -ENODEV;
+		goto err_phy;
+	}
+
+	ret = usb_phy_init(phy);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Unable init transceiver\n");
+		ret = -ENODEV;
+		goto err_phy_init;
+	}
+
+	/* Set up the PORTSCx register */
+	writel(0, data->mem + 0x144);
+
+	return 0;
+
+err_phy_init:
+	if (phy)
+		usb_put_transceiver(phy);
+err_phy:
+	if (data->pdev_gadget)
+		platform_device_unregister(data->pdev_gadget);
+err_register_gadget:
+	if (data->pdev_host)
+		platform_device_unregister(data->pdev_host);
+err_register_host:
+err_get_host_irq:
+	iounmap(data->mem);
+err_map_host_mem:
+	release_mem_region(data->mem_res->start,
+			resource_size(data->mem_res));
+err_get_host_mem:
+	data->mem_res = NULL;
+err_get_host_resource:
+	clk_disable_unprepare(data->clk);
+err_prepare_host_clock:
+	clk_put(data->clk);
+err_claim_host_clock:
+err_alloc_data:
+	return ret;
+}
+
+static int __devexit imx_usb_remove(struct platform_device *pdev)
+{
+	struct imx_usb *data = platform_get_drvdata(pdev);
+
+	if (data->pdev_gadget)
+		platform_device_unregister(data->pdev_gadget);
+
+	if (data->pdev_host)
+		platform_device_unregister(data->pdev_host);
+
+	iounmap(data->mem);
+	release_mem_region(data->mem_res->start,
+			resource_size(data->mem_res));
+	data->mem_res = NULL;
+	clk_disable_unprepare(data->clk);
+	clk_put(data->clk);
+
+	return 0;
+}
+
+static struct platform_driver imx_usb_driver = {
+	.probe		= imx_usb_probe,
+	.remove		= __devexit_p(imx_usb_remove),
+	.driver		= {
+		.name	= "imx-otg",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init imx_usb_init(void)
+{
+	return platform_driver_register(&imx_usb_driver);
+}
+
+static void __exit imx_usb_exit(void)
+{
+	platform_driver_unregister(&imx_usb_driver);
+}
+
+module_init(imx_usb_init);
+module_exit(imx_usb_exit);
+
+MODULE_ALIAS("platform:imx-otg");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX USB composite driver");
+MODULE_LICENSE("GPL");
-- 
1.7.9.5

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

* [PATCH 09/11] MXS: Add USB PHY driver
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (7 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-23  1:42         ` Chen Peter-B29397
  2012-04-22 12:59       ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
                         ` (3 subsequent siblings)
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
enables the PHY upon powerup and shuts it down on shutdown.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |   10 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  438 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 449 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index e7c6325..1de1495 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -122,6 +122,16 @@ config USB_IMX_COMPOSITE
 	  Composite driver that handles clock and memory mapping for
 	  i.MX USB host and USB PHY.
 
+config USB_MXS_PHY
+	tristate "Freescale i.MX28 USB PHY support"
+	select USB_OTG_UTILS
+	select USB_IMX_COMPOSITE
+	help
+	  Say Y here if you want to build Freescale i.MX28 USB PHY
+	  driver in kernel.
+
+	  To compile this driver as a module, choose M here.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 7d2c631..b8d7d5c 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
 obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
+obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
new file mode 100644
index 0000000..4f03515
--- /dev/null
+++ b/drivers/usb/otg/mxs-phy.c
@@ -0,0 +1,438 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fsl/mxs-usb.h>
+#include <linux/gpio.h>
+
+#include <linux/usb.h>
+#include <linux/usb/ch9.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/hcd.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#define HW_USBPHY_PWD				0x00
+
+#define HW_USBPHY_CTRL				0x30
+#define HW_USBPHY_CTRL_SET			0x34
+#define HW_USBPHY_CTRL_CLR			0x38
+#define HW_USBPHY_CTRL_TOG			0x3c
+
+#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
+#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
+#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
+#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
+#define BM_USBPHY_CTRL_ENIRQDEVPLUGIN		(1 << 11)
+#define BM_USBPHY_CTRL_ENOTGIDDETECT		(1 << 7)
+#define BM_USBPHY_CTRL_ENDEVPLUGINDETECT	(1 << 4)
+#define BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ	(1 << 3)
+#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
+
+#define HW_USBPHY_STATUS			0x40
+
+#define BM_USBPHY_STATUS_OTGID_STATUS		(1 << 8)
+#define BM_USBPHY_STATUS_DEVPLUGIN_STATUS	(1 << 6)
+#define BM_USBPHY_STATUS_HOSTDISCON_STATUS	(1 << 3)
+
+/* FIXME */
+#define M28EVK_USBOTG_ENABLE	MXS_GPIO_NR(3, 12)
+
+struct mxs_usb_phy {
+	struct usb_phy		phy;
+
+	struct work_struct	work;
+
+	struct clk		*clk;
+	struct resource		*mem_res;
+	void __iomem		*mem;
+	int			irq;
+	int			gpio_vbus;
+	int			gpio_vbus_inverted;
+
+	enum usb_otg_state	new_state;
+
+	bool			host_mode;
+};
+
+static int mxs_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	struct usb_phy *x = otg->phy;
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+
+	/* If the host provided is what we already have, just return. */
+	if (otg->host && otg->host == host)
+		return 0;
+
+	/* Otherwise start the state machine. */
+	if (host)
+		otg->host = host;
+	else
+		phy->new_state = OTG_STATE_UNDEFINED;
+
+	schedule_work(&phy->work);
+
+	return 0;
+}
+
+static int mxs_usb_set_peripheral(struct usb_otg *otg, struct usb_gadget *gg)
+{
+	struct usb_phy *x = otg->phy;
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+
+	/* If the gadget provided is what we already have, just return. */
+	if (otg->gadget && otg->gadget == gg)
+		return 0;
+
+	/* Otherwise start the state machine. */
+	if (gg)
+		otg->gadget = gg;
+	else
+		phy->new_state = OTG_STATE_UNDEFINED;
+
+	schedule_work(&phy->work);
+
+	return 0;
+}
+
+static void mxs_usb_work(struct work_struct *w)
+{
+	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
+	struct usb_otg *otg = phy->phy.otg;
+	struct usb_hcd *hcd;
+
+	switch (otg->phy->state) {
+	case OTG_STATE_A_HOST:
+		if (phy->new_state == OTG_STATE_UNDEFINED) {
+			hcd = bus_to_hcd(otg->host);
+			usb_remove_hcd(hcd);
+			otg->phy->state = phy->new_state;
+			/* Turn off VBUS */
+			gpio_set_value(phy->gpio_vbus,
+				phy->gpio_vbus_inverted);
+		}
+		break;
+	case OTG_STATE_B_PERIPHERAL:
+		if (phy->new_state == OTG_STATE_UNDEFINED) {
+			usb_del_gadget_udc(otg->gadget);
+			otg->phy->state = phy->new_state;
+		}
+		break;
+	case OTG_STATE_UNDEFINED:
+		/* Check desired state. */
+		switch (phy->new_state) {
+		case OTG_STATE_A_HOST:
+			if (!otg->host)
+				break;
+			otg->phy->state = phy->new_state;
+
+			/* Turn on VBUS */
+			gpio_set_value(phy->gpio_vbus,
+				!phy->gpio_vbus_inverted);
+
+			hcd = bus_to_hcd(otg->host);
+			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
+			break;
+		case OTG_STATE_B_PERIPHERAL:
+			if (!otg->gadget)
+				break;
+			otg->phy->state = phy->new_state;
+			usb_add_gadget_udc(phy->phy.dev, otg->gadget);
+			break;
+		default:
+			break;
+		}
+		break;
+
+	default:
+		break;
+	}
+}
+
+static int mxs_usb_phy_init(struct usb_phy *x)
+{
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+	uint32_t val;
+
+	/* Enable clock to the PHY. */
+	clk_enable(phy->clk);
+
+	/* Reset the PHY block. */
+	mxs_reset_block(phy->mem + HW_USBPHY_CTRL);
+
+	/* Power up the PHY. */
+	writel(0, phy->mem + HW_USBPHY_PWD);
+
+	/* Enable FS/LS compatibility. */
+	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3;
+
+	if (phy->host_mode)
+		val |= BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
+	else
+		val |= BM_USBPHY_CTRL_ENIRQDEVPLUGIN |
+			BM_USBPHY_CTRL_ENOTGIDDETECT |
+			BM_USBPHY_CTRL_ENDEVPLUGINDETECT;
+
+	writel(val, phy->mem + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static void mxs_usb_phy_shutdown(struct usb_phy *x)
+{
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+
+	/* Gate off the PHY. */
+	writel(BM_USBPHY_CTRL_CLKGATE, phy->mem + HW_USBPHY_CTRL_SET);
+
+	/* Disable clock to the PHY. */
+	clk_disable(phy->clk);
+}
+
+static irqreturn_t mxs_phy_irq(int irq, void *data)
+{
+	struct mxs_usb_phy *phy = data;
+	uint32_t status = readl(phy->mem + HW_USBPHY_STATUS);
+
+	if (status & BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ)
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			phy->mem + HW_USBPHY_CTRL_CLR);
+	else
+		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+			phy->mem + HW_USBPHY_CTRL_SET);
+
+	return IRQ_NONE;
+}
+
+static int __devinit mxs_phy_probe(struct platform_device *pdev)
+{
+	struct imx_usb_platform_data *pdata = pdev->dev.platform_data;
+	struct mxs_usb_phy *phy;
+	void *retp;
+	int ret;
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "No platform data supplied!\n");
+		return -ENODEV;
+	}
+
+	/* Allocate PHY driver's private date. */
+	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
+		ret = -ENOMEM;
+		goto err_resources;
+	}
+
+	/* Allocate OTG structure. */
+	phy->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*phy->phy.otg),
+					GFP_KERNEL);
+	if (!phy->phy.otg) {
+		dev_err(&pdev->dev, "Failed to allocate USB OTG structure!\n");
+		ret = -ENOMEM;
+		goto err_resources;
+	}
+
+	/* Get memory area for PHY from resources. */
+	phy->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!phy->mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB PHY!\n");
+		ret = -ENODEV;
+		goto err_resources;
+	}
+
+	/* Request the memory region for this USB PHY. */
+	retp = devm_request_mem_region(&pdev->dev, phy->mem_res->start,
+			resource_size(phy->mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB PHY memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_resources;
+	}
+
+	/* Map the memory region for USB PHY. */
+	phy->mem = devm_ioremap(&pdev->dev, phy->mem_res->start,
+				resource_size(phy->mem_res));
+	if (!phy->mem) {
+		dev_err(&pdev->dev, "Memory mapping of USB PHY failed!\n");
+		ret = -EFAULT;
+		goto err_resources;
+	}
+
+	/* Claim the PHY clock. */
+	phy->clk = clk_get(&pdev->dev, "phy");
+	if (!phy->clk) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB PHY!\n");
+		ret = PTR_ERR(phy->clk);
+		goto err_resources;
+	}
+
+	/* Prepare PHY clock. */
+	ret = clk_prepare(phy->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to prepare clock for USB PHY!\n");
+		goto err_prepare_phy_clock;
+	}
+
+	/* Get IRQ for PHY from resources. */
+	phy->irq = platform_get_irq(pdev, 0);
+	if (phy->irq < 0) {
+		dev_err(&pdev->dev, "Specify IRQ for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_phy_irq;
+	}
+
+	/*
+	 * Request the PHY IRQ, this IRQ line is shared between the
+	 * USB Host, USB Gadget and the PHY!
+	 */
+	ret = request_irq(phy->irq, mxs_phy_irq, IRQF_SHARED,
+						pdev->name, phy);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to request IRQ!\n");
+		goto err_request_phy_irq;
+	}
+
+	ret = gpio_request_one(pdata->gpio_vbus, GPIOF_DIR_OUT, "USB Power");
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request USB Power GPIO!");
+		goto err_gpio;
+	}
+
+	/* Disable the VBUS. */
+	gpio_set_value(pdata->gpio_vbus, pdata->gpio_vbus_inverted);
+
+	/* Setup the PHY structures. */
+	phy->phy.dev		= &pdev->dev;
+	phy->phy.label		= "mxs-usb-phy";
+	phy->phy.init		= mxs_usb_phy_init;
+	phy->phy.shutdown	= mxs_usb_phy_shutdown;
+	phy->phy.state		= OTG_STATE_UNDEFINED;
+
+	if (pdata->host_mode)
+		phy->new_state	= OTG_STATE_A_HOST;
+	else
+		phy->new_state	= OTG_STATE_B_PERIPHERAL;
+
+	phy->phy.otg->phy	= &phy->phy;
+	phy->phy.otg->set_host	= mxs_usb_set_host;
+	phy->phy.otg->set_peripheral	= mxs_usb_set_peripheral;
+
+	phy->gpio_vbus		= pdata->gpio_vbus;
+	phy->gpio_vbus_inverted	= pdata->gpio_vbus_inverted;
+
+	platform_set_drvdata(pdev, phy);
+
+	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
+
+	INIT_WORK(&phy->work, mxs_usb_work);
+
+	/* Register the transceiver with kernel. */
+	ret = usb_set_transceiver(&phy->phy);
+	if (ret) {
+		dev_err(&pdev->dev, "Can't register transceiver, (%d)\n", ret);
+		goto err_set_transceiver;
+	}
+
+	return 0;
+
+err_set_transceiver:
+	gpio_free(pdata->gpio_vbus);
+err_gpio:
+	free_irq(phy->irq, phy);
+err_request_phy_irq:
+err_get_phy_irq:
+	clk_unprepare(phy->clk);
+err_prepare_phy_clock:
+	clk_put(phy->clk);
+err_resources:
+	return ret;
+}
+
+static int __devexit mxs_phy_remove(struct platform_device *pdev)
+{
+	struct mxs_usb_phy *phy = platform_get_drvdata(pdev);
+
+	/* Stop the PHY work. */
+	cancel_work_sync(&phy->work);
+
+	/* Power down the PHY. */
+	mxs_usb_phy_shutdown(&phy->phy);
+
+	/* Remove the transceiver. */
+	usb_set_transceiver(NULL);
+
+	/* Shut off VBUS. */
+	gpio_set_value(phy->gpio_vbus, phy->gpio_vbus_inverted);
+	gpio_free(phy->gpio_vbus);
+
+	/* Free the IRQ requested by this device. */
+	free_irq(phy->irq, phy);
+
+	/* Free the IRQ requested by this device. */
+	free_irq(phy->irq, phy);
+
+	/* Stop the PHY clock. */
+	clk_disable_unprepare(phy->clk);
+	clk_put(phy->clk);
+
+	/* Free the rest. */
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static struct platform_driver mxs_phy_driver = {
+	.probe		= mxs_phy_probe,
+	.remove		= __devexit_p(mxs_phy_remove),
+	.driver		= {
+		.name	= "mxs-usb-phy",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mxs_phy_init(void)
+{
+	return platform_driver_register(&mxs_phy_driver);
+}
+
+static void __exit mxs_phy_exit(void)
+{
+	platform_driver_unregister(&mxs_phy_driver);
+}
+
+arch_initcall(mxs_phy_init);
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
-- 
1.7.9.5

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

* [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (8 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-22 12:59       ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
                         ` (2 subsequent siblings)
  12 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/devices-mx28.h                |    5 ++
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   84 +++++++++++++++++++++++
 arch/arm/mach-mxs/include/mach/devices-common.h |   12 ++++
 5 files changed, 105 insertions(+)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c

diff --git a/arch/arm/mach-mxs/devices-mx28.h b/arch/arm/mach-mxs/devices-mx28.h
index 9dbeae1..f0e1d54 100644
--- a/arch/arm/mach-mxs/devices-mx28.h
+++ b/arch/arm/mach-mxs/devices-mx28.h
@@ -11,6 +11,7 @@
 #include <mach/mx28.h>
 #include <mach/devices-common.h>
 #include <mach/mxsfb.h>
+#include <linux/fsl/mxs-usb.h>
 
 extern const struct amba_device mx28_duart_device __initconst;
 #define mx28_add_duart() \
@@ -47,6 +48,10 @@ extern const struct mxs_mxs_mmc_data mx28_mxs_mmc_data[] __initconst;
 
 #define mx28_add_mxs_pwm(id)		mxs_add_mxs_pwm(MX28_PWM_BASE_ADDR, id)
 
+extern const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst;
+#define mx28_add_mxs_usbh(id, pdata) \
+	mxs_add_mxs_usbh(&mx28_mxs_usbh_data[id], pdata)
+
 struct platform_device *__init mx28_add_mxsfb(
 		const struct mxsfb_platform_data *pdata);
 
diff --git a/arch/arm/mach-mxs/devices/Kconfig b/arch/arm/mach-mxs/devices/Kconfig
index b8913df..f6709bc 100644
--- a/arch/arm/mach-mxs/devices/Kconfig
+++ b/arch/arm/mach-mxs/devices/Kconfig
@@ -32,3 +32,6 @@ config MXS_HAVE_PLATFORM_MXS_SAIF
 
 config MXS_HAVE_PLATFORM_RTC_STMP3XXX
 	bool
+
+config MXS_HAVE_PLATFORM_USB
+	bool
diff --git a/arch/arm/mach-mxs/devices/Makefile b/arch/arm/mach-mxs/devices/Makefile
index c8f5c95..be4cc9e 100644
--- a/arch/arm/mach-mxs/devices/Makefile
+++ b/arch/arm/mach-mxs/devices/Makefile
@@ -11,3 +11,4 @@ obj-y += platform-gpio-mxs.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXSFB) += platform-mxsfb.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXS_SAIF) += platform-mxs-saif.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_RTC_STMP3XXX) += platform-rtc-stmp3xxx.o
+obj-$(CONFIG_MXS_HAVE_PLATFORM_USB) += platform-usb.o
diff --git a/arch/arm/mach-mxs/devices/platform-usb.c b/arch/arm/mach-mxs/devices/platform-usb.c
new file mode 100644
index 0000000..5d71778
--- /dev/null
+++ b/arch/arm/mach-mxs/devices/platform-usb.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+#include <linux/compiler.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/fsl_devices.h>
+#include <linux/fsl/mxs-usb.h>
+
+#include <mach/mx23.h>
+#include <mach/mx28.h>
+#include <mach/devices-common.h>
+
+#define mxs_usbh_data_entry_single(soc, _id, hwid)			\
+	{								\
+		.id = _id,						\
+		.usb_irq = soc ## _INT_USB ## hwid,			\
+		.usb_iobase = soc ## _USBCTRL ## hwid ## _BASE_ADDR,	\
+		.phy_iobase = soc ## _USBPHY ## hwid ## _BASE_ADDR,	\
+	}
+
+#define mxs_usbh_data_entry(soc, _id, hwid)				\
+	[_id] = mxs_usbh_data_entry_single(soc, _id, hwid)
+
+#ifdef CONFIG_SOC_IMX23
+const struct mxs_usbh_data mx23_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX23, 0, 0),
+};
+#endif
+
+#ifdef CONFIG_SOC_IMX28
+const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX28, 0, 0),
+	mxs_usbh_data_entry(MX28, 1, 1),
+};
+#endif
+
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data,
+			const struct imx_usb_platform_data *pdata)
+{
+	struct platform_device *pdev;
+	struct resource phy_res[] = {
+		{
+			.start	= data->phy_iobase,
+			.end	= data->phy_iobase + SZ_256 - 1,
+			.flags	= IORESOURCE_MEM,
+		}, {
+			.start	= data->usb_irq,
+			.end	= data->usb_irq,
+			.flags	= IORESOURCE_IRQ,
+		},
+	};
+
+	struct resource usb_res[] = {
+		{
+			.start	= data->usb_iobase,
+			.end	= data->usb_iobase + SZ_64K - 1,
+			.flags	= IORESOURCE_MEM,
+		}, {
+			.start	= data->usb_irq,
+			.end	= data->usb_irq,
+			.flags	= IORESOURCE_IRQ,
+		},
+	};
+
+	pdev = mxs_add_platform_device_dmamask("mxs-usb-phy", data->id,
+					phy_res, ARRAY_SIZE(phy_res),
+					pdata, sizeof(*pdata),
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register USB PHY driver!\n");
+
+	pdev = mxs_add_platform_device_dmamask("imx-otg", data->id,
+					usb_res, ARRAY_SIZE(usb_res),
+					pdata, sizeof(*pdata),
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register USB Host driver!\n");
+}
diff --git a/arch/arm/mach-mxs/include/mach/devices-common.h b/arch/arm/mach-mxs/include/mach/devices-common.h
index f2e3839..3024428 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
+++ b/arch/arm/mach-mxs/include/mach/devices-common.h
@@ -10,6 +10,8 @@
 #include <linux/platform_device.h>
 #include <linux/init.h>
 #include <linux/amba/bus.h>
+#include <linux/fsl_devices.h>
+#include <linux/fsl/mxs-usb.h>
 
 extern struct device mxs_apbh_bus;
 
@@ -42,6 +44,16 @@ struct mxs_auart_data {
 struct platform_device *__init mxs_add_auart(
 		const struct mxs_auart_data *data);
 
+/* usb host */
+struct mxs_usbh_data {
+	int id;
+	resource_size_t usb_irq;
+	resource_size_t usb_iobase;
+	resource_size_t phy_iobase;
+};
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data,
+			const struct imx_usb_platform_data *pdata);
+
 /* fec */
 #include <linux/fec.h>
 struct mxs_fec_data {
-- 
1.7.9.5

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

* [PATCH 11/11] MXS: Enable USB on M28EVK
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (9 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
@ 2012-04-22 12:59       ` Marek Vasut
  2012-04-23  1:57         ` Chen Peter-B29397
  2012-04-23  2:01       ` [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver Chen Peter-B29397
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
  12 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

Enable the second USB port on M28EVK board.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig       |    2 ++
 arch/arm/mach-mxs/mach-m28evk.c |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index c57f996..05f6e84 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -81,6 +81,8 @@ config MODULE_M28
 	select MXS_HAVE_PLATFORM_MXS_I2C
 	select MXS_HAVE_PLATFORM_MXS_MMC
 	select MXS_HAVE_PLATFORM_MXSFB
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 
 config MODULE_APX4
diff --git a/arch/arm/mach-mxs/mach-m28evk.c b/arch/arm/mach-mxs/mach-m28evk.c
index 06d7996..96d523a 100644
--- a/arch/arm/mach-mxs/mach-m28evk.c
+++ b/arch/arm/mach-mxs/mach-m28evk.c
@@ -39,6 +39,8 @@
 
 #define MX28EVK_BL_ENABLE	MXS_GPIO_NR(3, 18)
 #define M28EVK_LCD_ENABLE	MXS_GPIO_NR(3, 28)
+#define M28EVK_USB_ENABLE	MXS_GPIO_NR(3, 13)
+#define M28EVK_USBOTG_ENABLE	MXS_GPIO_NR(3, 12)
 
 #define MX28EVK_MMC0_WRITE_PROTECT	MXS_GPIO_NR(2, 12)
 #define MX28EVK_MMC1_WRITE_PROTECT	MXS_GPIO_NR(0, 28)
@@ -210,6 +212,16 @@ static const iomux_cfg_t m28evk_pads[] __initconst = {
 
 	/* Backlight */
 	MX28_PAD_PWM3__GPIO_3_28 | MXS_PAD_CTRL,
+
+	/* USB */
+	MX28_PAD_SSP2_SS2__USB0_OVERCURRENT,
+	MX28_PAD_SSP2_SS1__USB1_OVERCURRENT,
+	MX28_PAD_PWM2__USB0_ID |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
+	MX28_PAD_AUART3_TX__GPIO_3_13 |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
+	MX28_PAD_AUART3_RX__GPIO_3_12 |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
 };
 
 /* led */
@@ -317,6 +329,12 @@ static struct mxs_mmc_platform_data m28evk_mmc_pdata[] __initdata = {
 	},
 };
 
+static struct imx_usb_platform_data m28_usb_data = {
+	.gpio_vbus		= M28EVK_USBOTG_ENABLE,
+	.gpio_vbus_inverted	= 1,
+	.host_mode		= 1,
+};
+
 static void __init m28evk_init(void)
 {
 	mxs_iomux_setup_multiple_pads(m28evk_pads, ARRAY_SIZE(m28evk_pads));
@@ -344,6 +362,8 @@ static void __init m28evk_init(void)
 	mx28_add_mxs_i2c(0);
 	i2c_register_board_info(0, m28_stk5v3_i2c_boardinfo,
 			ARRAY_SIZE(m28_stk5v3_i2c_boardinfo));
+
+	mx28_add_mxs_usbh(0, &m28_usb_data);
 }
 
 static void __init m28evk_timer_init(void)
-- 
1.7.9.5

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

* [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver
  2012-04-22 12:59       ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
@ 2012-04-22 14:39         ` Shawn Guo
  2012-04-22 15:42           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Shawn Guo @ 2012-04-22 14:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Apr 22, 2012 at 02:59:20PM +0200, Marek Vasut wrote:
> This patch adds common data shared between the MXS EHCI HCD driver,
> the MXS USB Gadget driver and the imx-otg driver. These data allow
> passing clock and memory stuff from imx-otg driver into the
> host/gadget driver.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  include/linux/fsl/mxs-usb.h |   46 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
>  create mode 100644 include/linux/fsl/mxs-usb.h

As what Wolfram and Arnd pointed out in thread [1], include/linux/fsl
is not a good choice. Instead, it should be include/linux/usb/mxs-usb.h.

Regards,
Shawn

[1] http://thread.gmane.org/gmane.linux.kernel/1271153/focus=163132

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

* [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-22 12:59       ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-04-22 14:42         ` Shawn Guo
  2012-04-22 15:42           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Shawn Guo @ 2012-04-22 14:42 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Apr 22, 2012 at 02:59:18PM +0200, Marek Vasut wrote:
> Based on code by:
> Tony Lin <tony.lin@freescale.com>
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
The first 2 patches in series are patching files to be removed.
We are switching mxs clock to common clk framework.

-- 
Regards,
Shawn

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

* [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-22 14:42         ` Shawn Guo
@ 2012-04-22 15:42           ` Marek Vasut
  2012-04-22 16:34             ` Shawn Guo
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 15:42 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Shawn Guo,

> On Sun, Apr 22, 2012 at 02:59:18PM +0200, Marek Vasut wrote:
> > Based on code by:
> > Tony Lin <tony.lin@freescale.com>
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > ---
> > 
> >  arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
> >  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> The first 2 patches in series are patching files to be removed.
> We are switching mxs clock to common clk framework.

When is this mxs clock framework scheduled to hit mainline? I obviously had to 
patch this stuff to work with mainline, once there's new framework, it should be 
easy to just change these patches.

Best regards,
Marek Vasut

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

* [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver
  2012-04-22 14:39         ` Shawn Guo
@ 2012-04-22 15:42           ` Marek Vasut
  2012-04-22 16:38             ` Shawn Guo
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-22 15:42 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Shawn Guo,

> On Sun, Apr 22, 2012 at 02:59:20PM +0200, Marek Vasut wrote:
> > This patch adds common data shared between the MXS EHCI HCD driver,
> > the MXS USB Gadget driver and the imx-otg driver. These data allow
> > passing clock and memory stuff from imx-otg driver into the
> > host/gadget driver.
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > ---
> > 
> >  include/linux/fsl/mxs-usb.h |   46
> >  +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46
> >  insertions(+)
> >  create mode 100644 include/linux/fsl/mxs-usb.h
> 
> As what Wolfram and Arnd pointed out in thread [1], include/linux/fsl
> is not a good choice. Instead, it should be include/linux/usb/mxs-usb.h.

Ok, noted. Will add in V5. What about the rest of these patches, I'd be 
interested to hear your opinion on these :-)

> 
> Regards,
> Shawn
> 
> [1] http://thread.gmane.org/gmane.linux.kernel/1271153/focus=163132

Best regards,
Marek Vasut

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

* [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-22 15:42           ` Marek Vasut
@ 2012-04-22 16:34             ` Shawn Guo
  0 siblings, 0 replies; 149+ messages in thread
From: Shawn Guo @ 2012-04-22 16:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Apr 22, 2012 at 05:42:05PM +0200, Marek Vasut wrote:
> Dear Shawn Guo,
> 
> > On Sun, Apr 22, 2012 at 02:59:18PM +0200, Marek Vasut wrote:
> > > Based on code by:
> > > Tony Lin <tony.lin@freescale.com>
> > > 
> > > Signed-off-by: Marek Vasut <marex@denx.de>
> > > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > > Cc: Detlev Zundel <dzu@denx.de>
> > > Cc: Fabio Estevam <festevam@gmail.com>
> > > Cc: Li Frank-B20596 <B20596@freescale.com>
> > > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > > Cc: Linux USB <linux-usb@vger.kernel.org>
> > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > Cc: Shawn Guo <shawn.guo@freescale.com>
> > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > Cc: Stefano Babic <sbabic@denx.de>
> > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > Cc: Tony Lin <tony.lin@freescale.com>
> > > Cc: Wolfgang Denk <wd@denx.de>
> > > ---
> > > 
> > >  arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
> > >  1 file changed, 19 insertions(+), 2 deletions(-)
> > 
> > The first 2 patches in series are patching files to be removed.
> > We are switching mxs clock to common clk framework.
> 
> When is this mxs clock framework scheduled to hit mainline?

v3.5 merge window.

-- 
Regards,
Shawn

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

* [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver
  2012-04-22 15:42           ` Marek Vasut
@ 2012-04-22 16:38             ` Shawn Guo
  0 siblings, 0 replies; 149+ messages in thread
From: Shawn Guo @ 2012-04-22 16:38 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Apr 22, 2012 at 05:42:53PM +0200, Marek Vasut wrote:
> Ok, noted. Will add in V5. What about the rest of these patches, I'd be 
> interested to hear your opinion on these :-)
> 
I have not looked into drivers/usb patches.  I doubt I have enough
knowledge about usb subsystem to give constructive comments.  Sorry.

For arch/arm/mach-mxs changes, I think you have known my position,
device tree.

-- 
Regards,
Shawn

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

* [PATCH 09/11] MXS: Add USB PHY driver
  2012-04-22 12:59       ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-23  1:42         ` Chen Peter-B29397
  2012-04-23  2:17           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23  1:42 UTC (permalink / raw)
  To: linux-arm-kernel

 
 
> +
> +#define HW_USBPHY_PWD				0x00
> +
> +#define HW_USBPHY_CTRL				0x30
> +#define HW_USBPHY_CTRL_SET			0x34
> +#define HW_USBPHY_CTRL_CLR			0x38
> +#define HW_USBPHY_CTRL_TOG			0x3c
> +
> +#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
> +#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
> +#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
> +#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
> +#define BM_USBPHY_CTRL_ENIRQDEVPLUGIN		(1 << 11)
> +#define BM_USBPHY_CTRL_ENOTGIDDETECT		(1 << 7)
> +#define BM_USBPHY_CTRL_ENDEVPLUGINDETECT	(1 << 4)
> +#define BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ	(1 << 3)
> +#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
> +
> +#define HW_USBPHY_STATUS			0x40
> +
> +#define BM_USBPHY_STATUS_OTGID_STATUS		(1 << 8)
> +#define BM_USBPHY_STATUS_DEVPLUGIN_STATUS	(1 << 6)
> +#define BM_USBPHY_STATUS_HOSTDISCON_STATUS	(1 << 3)
> +
> +/* FIXME */
> +#define M28EVK_USBOTG_ENABLE	MXS_GPIO_NR(3, 12)
> +
This is platform code, should not put at driver.



> +struct mxs_usb_phy {
> +	struct usb_phy		phy;
> +
> +	struct work_struct	work;
> +
> +	struct clk		*clk;
> +	struct resource		*mem_res;
> +	void __iomem		*mem;
> +	int			irq;
> +	int			gpio_vbus;
> +	int			gpio_vbus_inverted;
> +
> +	enum usb_otg_state	new_state;
> +
> +	bool			host_mode;
> +};
> +
> +static int mxs_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
should be at imx-otg.c

 
> +
> +static int mxs_usb_set_peripheral(struct usb_otg *otg, struct usb_gadget
> *gg)
gg may not a good name, how about just gadget?
should be at imx-otg.c
 
> +static void mxs_usb_work(struct work_struct *w)
It is OTG switch routine, and should be put imx-otg.c. Sascha also
suggested before. 

> +{
> +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
> +	struct usb_otg *otg = phy->phy.otg;
> +	struct usb_hcd *hcd;
> +
> +	switch (otg->phy->state) {
> +	case OTG_STATE_A_HOST:
> +		if (phy->new_state == OTG_STATE_UNDEFINED) {
> +			hcd = bus_to_hcd(otg->host);
> +			usb_remove_hcd(hcd);
> +			otg->phy->state = phy->new_state;
> +			/* Turn off VBUS */
> +			gpio_set_value(phy->gpio_vbus,
> +				phy->gpio_vbus_inverted);
> +		}
> +		break;
> +	case OTG_STATE_B_PERIPHERAL:
> +		if (phy->new_state == OTG_STATE_UNDEFINED) {
> +			usb_del_gadget_udc(otg->gadget);
> +			otg->phy->state = phy->new_state;
> +		}
> +		break;
> +	case OTG_STATE_UNDEFINED:
> +		/* Check desired state. */
> +		switch (phy->new_state) {
> +		case OTG_STATE_A_HOST:
> +			if (!otg->host)
> +				break;
> +			otg->phy->state = phy->new_state;
> +
> +			/* Turn on VBUS */
> +			gpio_set_value(phy->gpio_vbus,
> +				!phy->gpio_vbus_inverted);
> +
> +			hcd = bus_to_hcd(otg->host);
> +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> +			break;
> +		case OTG_STATE_B_PERIPHERAL:
> +			if (!otg->gadget)
> +				break;
> +			otg->phy->state = phy->new_state;
> +			usb_add_gadget_udc(phy->phy.dev, otg->gadget);
> +			break;
> +		default:
> +			break;
> +		}
> +		break;
> +
> +	default:
> +		break;
> +	}
> +}
> +
Seems you forget one otg state: OTG_STATE_B_IDLE.

at device mode: 
OTG_STATE_UNDEFINED -> OTG_STATE_B_IDLE (nothing on port)
OTG_STATE_B_PERIPHERAL -> OTG_STATE_B_IDLE (disconnect with host)
 
> +static int mxs_usb_phy_init(struct usb_phy *x)
> +{
> +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> +	uint32_t val;
> +
> +	/* Enable clock to the PHY. */
> +	clk_enable(phy->clk);
> +
> +	/* Reset the PHY block. */
> +	mxs_reset_block(phy->mem + HW_USBPHY_CTRL);
> +
> +	/* Power up the PHY. */
> +	writel(0, phy->mem + HW_USBPHY_PWD);
> +
> +	/* Enable FS/LS compatibility. */
> +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3;
> +
> +	if (phy->host_mode)
> +		val |= BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
> +	else
> +		val |= BM_USBPHY_CTRL_ENIRQDEVPLUGIN |
> +			BM_USBPHY_CTRL_ENOTGIDDETECT |
> +			BM_USBPHY_CTRL_ENDEVPLUGINDETECT;

Please explain the meaning of above code?


> +static void mxs_usb_phy_shutdown(struct usb_phy *x)
> +{
> +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> +
You need to set portsc.phcd=1 and power down phy using set 0xffffffff to HW_USBPHY_PWD.

> +	/* Gate off the PHY. */
> +	writel(BM_USBPHY_CTRL_CLKGATE, phy->mem + HW_USBPHY_CTRL_SET);
> +
> +	/* Disable clock to the PHY. */
> +	clk_disable(phy->clk);
> +}
> +
> +static irqreturn_t mxs_phy_irq(int irq, void *data)
> +{
> +	struct mxs_usb_phy *phy = data;
> +	uint32_t status = readl(phy->mem + HW_USBPHY_STATUS);
> +
> +	if (status & BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ)
> +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> +			phy->mem + HW_USBPHY_CTRL_CLR);
> +	else
> +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> +			phy->mem + HW_USBPHY_CTRL_SET);
> +

Have you tested several connect/disconnect operation with high speed device?
- where you clear BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ?
- This code will always run at every usb interrupt, in fact, high speed detector
only needs to be set/clear with connect/disconnect.

> +	return IRQ_NONE;
> +}
> +
 
 
> +
> +static int __devexit mxs_phy_remove(struct platform_device *pdev)
> +{
> +	struct mxs_usb_phy *phy = platform_get_drvdata(pdev);
> +
> +	/* Stop the PHY work. */
> +	cancel_work_sync(&phy->work);
> +
> +	/* Power down the PHY. */
> +	mxs_usb_phy_shutdown(&phy->phy);
> +
> +	/* Remove the transceiver. */
> +	usb_set_transceiver(NULL);
> +
> +	/* Shut off VBUS. */
> +	gpio_set_value(phy->gpio_vbus, phy->gpio_vbus_inverted);
> +	gpio_free(phy->gpio_vbus);
> +
> +	/* Free the IRQ requested by this device. */
> +	free_irq(phy->irq, phy);
> +
> +	/* Free the IRQ requested by this device. */
> +	free_irq(phy->irq, phy);
> +
Two free_irq???

> +	/* Stop the PHY clock. */
> +	clk_disable_unprepare(phy->clk);
> +	clk_put(phy->clk);
> +
> +	/* Free the rest. */
> +	platform_set_drvdata(pdev, NULL);
> +
> +	return 0;
> +}
> +
 

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

* [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver
  2012-04-22 12:59       ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-23  1:44         ` Chen Peter-B29397
  2012-04-23  2:11           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23  1:44 UTC (permalink / raw)
  To: linux-arm-kernel

 
> NOTE: I still haven't figured out how to enable/disable the disconnection
> detector, it can't be enabled all the time, so I toggle PHY stuff from
> this
> driver, which I doubt is correct.
> 
Hi Marek, I have already explain how to use high speed disconnect detector
in early email.

 
 
> +
> +static irqreturn_t mxs_ehci_irq(struct usb_hcd *hcd)
> +{
> +	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
> +	struct usb_phy *phy = usb_get_transceiver();
> +	uint32_t status;
> +	static uint32_t discon;
> +
> +	if (phy && phy->otg && phy->otg->set_vbus) {
> +		status = ehci_readl(ehci, &ehci->regs->status);
> +		status = !!(status & STS_PCD);
> +		if (status != discon) {
> +			discon = status;
> +			phy->otg->set_vbus(phy->otg, status);
> +		}
> +	}
Conflict with your phy interrupt code.

 
 

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

* [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc
  2012-04-22 12:59       ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
@ 2012-04-23  1:46         ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23  1:46 UTC (permalink / raw)
  To: linux-arm-kernel

 
> 
> +config USB_CI13XXX_MXS
> +	tristate "MIPS USB CI13xxx for i.MX23/28"
> +	depends on ARCH_MXS
> +	select USB_GADGET_DUALSPEED
> +	select USB_IMX_COMPOSITE
> +	help
> +	  i.MX SoC has chipidea USB controller.  This driver uses
> +	  ci13xxx_udc core.
> +	  This driver depends on OTG driver for PHY initialization,
> +	  clock management, powering up VBUS, and power management.
> +	  This driver is not supported on boards like trout which
> +	  has an external PHY.
> +
> +	  Say "y" to link the driver statically, or "m" to build a
> +	  dynamically linked module called "ci13xxx_msm" and force all
> +	  gadget drivers to also be dynamically linked.
> +
cil3xxx_msm????? should be cil3xxx_mxs?



>  #
>  # LAST -- dummy/emulated controller
>  #
> diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
> index b7f6eef..1f159a9 100644
> --- a/drivers/usb/gadget/Makefile
> +++ b/drivers/usb/gadget/Makefile
> @@ -30,6 +30,7 @@ obj-$(CONFIG_USB_EG20T)		+= pch_udc.o
>  obj-$(CONFIG_USB_MV_UDC)	+= mv_udc.o
>  mv_udc-y			:= mv_udc_core.o
>  obj-$(CONFIG_USB_CI13XXX_MSM)	+= ci13xxx_msm.o
> +obj-$(CONFIG_USB_CI13XXX_MXS)	+= ci13xxx_mxs.o
>  obj-$(CONFIG_USB_FUSB300)	+= fusb300_udc.o
> 
>  #
> diff --git a/drivers/usb/gadget/ci13xxx_mxs.c
> b/drivers/usb/gadget/ci13xxx_mxs.c
> new file mode 100644
> index 0000000..35a3dd4
> --- /dev/null
> +++ b/drivers/usb/gadget/ci13xxx_mxs.c
> @@ -0,0 +1,67 @@
> +/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/usb/ulpi.h>
> +#include <linux/fsl/mxs-usb.h>
> +
> +#include "ci13xxx_udc.c"
> +
> +#define MSM_USB_BASE	(udc->regs)
> +
> +static irqreturn_t mxs_udc_irq(int irq, void *data)
> +{
> +	return udc_irq();
> +}
> +
> +static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
> +	.name			= "ci13xxx-mxs",
> +	.flags			= CI13XXX_REQUIRE_TRANSCEIVER |
> +				  CI13XXX_DISABLE_STREAMING |
> +				  CI13XXX_DONT_REGISTER_GADGET,
> +};
> +
> +static int ci13xxx_mxs_probe(struct platform_device *pdev)
> +{
> +	struct imx_usb *data = pdev->dev.platform_data;
> +	int ret;
> +
> +	ret = devm_request_irq(&pdev->dev, data->irq, mxs_udc_irq,
> +				IRQF_SHARED, pdev->name, pdev);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Failed to request IRQ!\n");
> +		return ret;
> +	}
> +
> +	ret = udc_probe(&ci13xxx_mxs_udc_driver, &pdev->dev, data->mem);
> +	if (ret < 0)
> +		dev_err(&pdev->dev, "Failed to probe CI13xxx-mxs!\n");
> +
> +	pm_runtime_no_callbacks(&pdev->dev);
> +	pm_runtime_enable(&pdev->dev);
> +
> +	return ret;
> +}
> +
> +static struct platform_driver ci13xxx_mxs_driver = {
> +	.probe		= ci13xxx_mxs_probe,
> +	.driver		= {
> +		.name	= "ci13xxx-mxs",
> +	},
> +};
> +
> +static int __init ci13xxx_mxs_init(void)
> +{
> +	return platform_driver_register(&ci13xxx_mxs_driver);
> +}
> +
> +module_init(ci13xxx_mxs_init);
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_ALIAS("platform:ci13xxx-mxs");
> --
> 1.7.9.5
> 

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

* [PATCH 11/11] MXS: Enable USB on M28EVK
  2012-04-22 12:59       ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-23  1:57         ` Chen Peter-B29397
  2012-04-23  2:18           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23  1:57 UTC (permalink / raw)
  To: linux-arm-kernel



 
> Enable the second USB port on M28EVK board.
> 
 
> +
> +	mx28_add_mxs_usbh(0, &m28_usb_data);
>  }
> 
You have enabled second port at mx28evk, why it "0"? at your mx28_add_mxs_usbh(0, &m28_usb_data).


>  static void __init m28evk_timer_init(void)
> --
> 1.7.9.5
> 

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (10 preceding siblings ...)
  2012-04-22 12:59       ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-23  2:01       ` Chen Peter-B29397
  2012-04-23  2:18         ` Marek Vasut
  2012-04-23  2:37         ` Marek Vasut
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
  12 siblings, 2 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23  2:01 UTC (permalink / raw)
  To: linux-arm-kernel



 
> This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> the
> generic USB PHY infrastructure. Also added is glue code for CI13xxx
> driver, to
> allow device mode. This patchset still does NOT support OTG mode, the
> device/host mode is selected via platform data.
> 
Does the udc work at this patchset? If it is, you have enabled OTG port
and not host 1 port, correct?
 

> V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> drivers.
> V3: Add the HCD on demand based on the PHY's state (only add HCD if it's
> host).
>     Currently, only the HOST mode is supported.
> V4: * Introduce ci13xxx gadget glue
>     * Reorder patches in a more sensible order
>     * Introduce platform data, containing VBUS GPIO and port mode
> (device/gadget)
>     * Rename imx-usb to imx-otg
>     * Drop mx28evk usb host patch
>     * Use more devm_ function
>     * Rework the mxs-phy to register the same interrupt as ehci-mxs (and
>       effectivelly kill bogus otg_set_vbus() call from ehci-mxs ; use
> standard
>       ehci irq handling in ehci-mxs)
> 
> Marek Vasut (11):
>   MXS: Make clk_disable return integer
>   MXS: Add USB EHCI and USB PHY clock handling
>   MXS: Fixup i.MX233 USB base address name
>   MXS: Add data shared between imx-otg and EHCI driver
>   MXS: Modify the ci13xxx_udc to avoid adding UDC
>   MXS: Add small registration glue for ci13xxx_udc
>   MXS: Add separate MXS EHCI HCD driver
>   MXS: Add imx-otg driver
>   MXS: Add USB PHY driver
>   MXS: Add platform registration hooks for USB EHCI
>   MXS: Enable USB on M28EVK
> 
>  arch/arm/mach-mxs/Kconfig                       |    2 +
>  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
>  arch/arm/mach-mxs/devices-mx28.h                |    5 +
>  arch/arm/mach-mxs/devices/Kconfig               |    3 +
>  arch/arm/mach-mxs/devices/Makefile              |    1 +
>  arch/arm/mach-mxs/devices/platform-usb.c        |   84 +++++
>  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
>  arch/arm/mach-mxs/include/mach/devices-common.h |   12 +
>  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
>  arch/arm/mach-mxs/mach-m28evk.c                 |   20 ++
>  drivers/usb/gadget/Kconfig                      |   17 +
>  drivers/usb/gadget/Makefile                     |    1 +
>  drivers/usb/gadget/ci13xxx_mxs.c                |   67 ++++
>  drivers/usb/gadget/ci13xxx_udc.c                |   12 +-
>  drivers/usb/gadget/ci13xxx_udc.h                |    1 +
>  drivers/usb/host/Kconfig                        |    7 +
>  drivers/usb/host/ehci-hcd.c                     |    5 +
>  drivers/usb/host/ehci-mxs.c                     |  197 ++++++++++
>  drivers/usb/otg/Kconfig                         |   16 +
>  drivers/usb/otg/Makefile                        |    2 +
>  drivers/usb/otg/imx-otg.c                       |  282 +++++++++++++++
>  drivers/usb/otg/mxs-phy.c                       |  438
> +++++++++++++++++++++++
>  include/linux/fsl/mxs-usb.h                     |   46 +++
>  23 files changed, 1243 insertions(+), 13 deletions(-)
>  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
>  create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c
>  create mode 100644 drivers/usb/host/ehci-mxs.c
>  create mode 100644 drivers/usb/otg/imx-otg.c
>  create mode 100644 drivers/usb/otg/mxs-phy.c
>  create mode 100644 include/linux/fsl/mxs-usb.h
> 
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> 
> NOTE: Adding this ci13xxx-mxs driver was really helpful, it helped me to
> realise
>       how this whole monster should look like in the end. Now the mxs-phy
> is
>       also much more prepared for the OTG operation.
> 
> --
> 1.7.9.5
> 

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

* RE:  答复: [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
  2012-04-20 16:25         ` Marek Vasut
@ 2012-04-23  2:02           ` Liu JunJie-B08287
  0 siblings, 0 replies; 149+ messages in thread
From: Liu JunJie-B08287 @ 2012-04-23  2:02 UTC (permalink / raw)
  To: linux-arm-kernel

Call me Tony, :), and search [Tony] for the embedded comments.

-----Original Message-----
From: Marek Vasut [mailto:marex at denx.de] 
Sent: Saturday, April 21, 2012 00:26
To: Liu JunJie-B08287
Cc: Sascha Hauer; Chen Peter-B29397; linux-arm-kernel at lists.infradead.org; Detlev Zundel; Fabio Estevam; Li Frank-B20596; Linux USB; Guo Shawn-R65073; Shawn Guo; Stefano Babic; Subodh Nijsure; Heikki Krogerus; Shi Make-B15407
Subject: Re: ??: [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver

Dear Liu JunJie-B08287,

> hi Sascha,
>    As the previous mail Peter post, we have two concerns about the new 
> arch of USB drvier as followed: 1. If the USB clock and the PHY are 
> centralized managed by the OTG driver, it will introduce an 
> unnecessary dependency between gadget/host function and OTG driver. 
> That means even gadget/host function is the individual function that 
> customer wanted, we need add OTG driver as well, otherwise, without 
> the PHY and clock support provided by OTG driver, the gadget/host 
> function can't work at all. But from the general viewpoint, the 
> gadget/host function is independent of OTG function, this unnecessary 
> dependency or limitation for customer is not reasonable. Furthermore, 
> this dependency will face much difficulty in some extreme case that 
> some customer only needs host function only but with the OTG ID floating, it was a real case we encounted before.

Can't this be fixed by passing of proper platform data to the imx-otg?

[Tony] Yes, such special patch or say special parameter in the interface between OTG and gadget/host can resolve such issue. But I don't think it is a good way to design the arch, with more and more special parameter added into the interface will make the interface un-readable and hard to understand. 

> 
>    2. If the USB clock and the PHY are centralized managed by the OTG 
> driver, it will introduce an unavoidable remote wakup issue that: 
> Since the USB suspend is separated into two parts: the USB host 
> controller suspend (set portsc.suspend bit to 1)  part which is 
> controlled by host driver and PHY suspend part (set portsc.phcd to 1) 
> which is controlled by OTG driver, during the system suspend, these 
> two parts will be executed in sequence, but the interval between these two parts is out of control.
> Refer to USB spec 2.0, the remote wakeup can happen anytime after 5ms 
> later from bus entered suspended state(set portsc.suspend bit to 1), 
> it means it can happen before, after, even during PHY suspend part executing.
> Taking the following case into accounted, PHY suspend process is 
> executing, the pseudo code as below: {
>             ...
>             some checking for the remote wakeup;
>                                       <------------------ remote 
> wakeup happen here set portsc.phcd to 1;
>             ...
>         }

Do we support this yet? Besides, you can make sure phy suspends before the controller ... and if the controller detects RW during suspend, it can fail to suspend and that brings the system back up.
[Tony] 1. It is a requirement that we must support. If a modem connected to host, if no communication on modem, the host and modem will enter in suspend mode, and system may try to enter suspend mode too; but the modem may issue remote wake up signal at any time which comply with the usb spec 2.0, we must support this to make the modem wakeup system, and keep modem working well. 

       2. How could this happen that phy suspends before the controller? 
          The phy enter into suspend when the data line state is in J mode, or in 3 ms not receive sof. If suspend phy first but keep controller in running/active mode, means the line state is not J, and the sof will not stop, how could the phy retain in suspend mode.

       3. even phy suspends before the controller comes to be true, the issue still exist, the interval between the time stamp that controller finishes detecting RW during suspend, and the time stamp that controller really enter into suspend still exists, RW happens within this interval will have the same issue with before.  
    

>         At such situation, one issue will be generated that the USB 
> controller is pulling up the resume signal (K), but at the same time, 
> the SW may set PHY to low power mode(set PHCD to 1), it may cause 
> unpredictable result. As in our i.MX platform the response to this 
> remote wakeup(pulling up K signal) is out of SW control, and it can 
> happen at anytime (5ms later after bus in suspended state), this issue 
> is unavoidable.
> 
>         The safest solution for this issue is setting portsc.phcd 
> within 5ms after bus in suspended state(set portsc.suspend bit to 1), 
> it requires USB host controller suspend and PHY suspend must be 
> executed uninterruptably, natively they can't be separated.
> 
>      The above is the shortcoming we thought about the new arch, and 
> we want to know what are you thinking about the shortcoming of current 
> arch, what makes you think the current arch had to be changed.
> 
> ________________________________________
> ???: Sascha Hauer [s.hauer at pengutronix.de]
> ????: 2012?4?18? 15:40
> ?: Chen Peter-B29397
> Cc: Marek Vasut; linux-arm-kernel at lists.infradead.org; Detlev Zundel; 
> Fabio Estevam; Li Frank-B20596; Linux USB; Guo Shawn-R65073; Shawn 
> Guo; Stefano Babic; Subodh Nijsure; Heikki Krogerus; Liu 
> JunJie-B08287; Shi Make-B15407
> ??: Re: [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver
> 
> On Wed, Apr 18, 2012 at 04:31:50AM +0000, Chen Peter-B29397 wrote:
> > > Your patches won't work when more than one USB port is enabled 
> > > because of the singular usb transceiver present in the kernel. 
> > > That of course is not your fault. I think Heikki (Added to Cc) is 
> > > working on this issue, but I don't know the status here.
> > > 
> > > Another problem is that what you are doing does not integrate at 
> > > all with otg. I don't ask you to implement otg support because you 
> > > are likely not interested in this, but since you are adding a new 
> > > ehci glue driver anyway I suggest another approach:
> > > 
> > > Put a driver under drivers/usb/otg which:
> > > 
> > > - matches a 'imx-usb' device
> > > - gets/enables all clocks needed for USB
> > > - finds the transceiver
> > > - registers a ehci device
> > > 
> > > Future additions would be:
> > > 
> > > - Put a USB_MODE_HOST/DEVICE flag into platform_data, and register 
> > > a
> > > 
> > >   host or gadget driver depending on this flag
> > > 
> > > - Add a USB_MODE_OTG flag to platform_data and implement otg in 
> > > this
> > > 
> > >   driver (or use whatever infrastructure present in the kernel 
> > > then)
> > > 
> > > This is similar to what msm does. This way we have the clocks and 
> > > phys handled where they are needed. We may use this code on i.MX later.
> > > 
> > > We did this wrong on i.MX (and several other architectures) and 
> > > getting this right will be hard work. No need to introduce the 
> > > same flaws again with a new architecture.
> > 
> > Hi Sascha,
> > 
> > We have been discussing i.mx usb re-structure at freescale internal 
> > during this periods, one side does not agree with otg driver manages 
> > PHY/clock solution due to below reasons:
> > 
> > - May confuse the users who only use device or host function, the 
> > users may double "why I need to include otg file to support 
> > device/host only function"?
> 
> I can't find anything confusing in this.
> 
> > - For some special cases, like device sends resume signal(remote 
> > wakeup) after host suspend, but before otg suspend (system needs to 
> > refuse to
> > suspend) . It needs to add hcd flag to judge if there is a remote 
> > wakeup after host suspend, and if the port is sending resume signal 
> > now (when the port is sending resume signal, we can't put power to 
> > low power mode). Is it suitable to put some hcd stuffs at otg driver?
> 
> I can't follow you here what the actual problem is, but since the otg 
> driver is the driver for host and gadget (which happens to pass 
> control to either the host or the gadget driver most of the time) it 
> is ok to do whatever it takes in the otg driver to make it work.
> 
> > - Any disadvantages three individual drivers manage PHY/clock 
> > separately after the generic PHY layer/FSL PHY driver have finished? 
> > It can define where to get/put PHY/clock operation at individual 
> > drivers clearly. When OTG switch, for host mode, the hcd struct 
> > (includes interrupt) will be free/created using 
> > usb_remove_hcd/usb_add_hcd, for device mode, we can deinit/init udc like current ci13xxx_udc.c at ci13xxx_vbus_session does.
> 
> I once made a quick hack using the msm otg driver on i.MX. I had to 
> comment out some msm specifics but after that it worked quite well.
> 
> Sascga
> 
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Best regards,
Marek Vasut

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

* [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver
  2012-04-23  1:44         ` Chen Peter-B29397
@ 2012-04-23  2:11           ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-23  2:11 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > NOTE: I still haven't figured out how to enable/disable the disconnection
> > detector, it can't be enabled all the time, so I toggle PHY stuff from
> > this
> > driver, which I doubt is correct.
> 
> Hi Marek, I have already explain how to use high speed disconnect detector
> in early email.
> 
> > +
> > +static irqreturn_t mxs_ehci_irq(struct usb_hcd *hcd)
> > +{
> > +	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
> > +	struct usb_phy *phy = usb_get_transceiver();
> > +	uint32_t status;
> > +	static uint32_t discon;
> > +
> > +	if (phy && phy->otg && phy->otg->set_vbus) {
> > +		status = ehci_readl(ehci, &ehci->regs->status);
> > +		status = !!(status & STS_PCD);
> > +		if (status != discon) {
> > +			discon = status;
> > +			phy->otg->set_vbus(phy->otg, status);
> > +		}
> > +	}
> 
> Conflict with your phy interrupt code.

Yes, this should have been removed, rebase issue. Damn

Best regards,
Marek Vasut

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

* [PATCH 09/11] MXS: Add USB PHY driver
  2012-04-23  1:42         ` Chen Peter-B29397
@ 2012-04-23  2:17           ` Marek Vasut
  2012-04-23 12:20             ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-23  2:17 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > +
> > +#define HW_USBPHY_PWD				0x00
> > +
> > +#define HW_USBPHY_CTRL				0x30
> > +#define HW_USBPHY_CTRL_SET			0x34
> > +#define HW_USBPHY_CTRL_CLR			0x38
> > +#define HW_USBPHY_CTRL_TOG			0x3c
> > +
> > +#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
> > +#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
> > +#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
> > +#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
> > +#define BM_USBPHY_CTRL_ENIRQDEVPLUGIN		(1 << 11)
> > +#define BM_USBPHY_CTRL_ENOTGIDDETECT		(1 << 7)
> > +#define BM_USBPHY_CTRL_ENDEVPLUGINDETECT	(1 << 4)
> > +#define BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ	(1 << 3)
> > +#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
> > +
> > +#define HW_USBPHY_STATUS			0x40
> > +
> > +#define BM_USBPHY_STATUS_OTGID_STATUS		(1 << 8)
> > +#define BM_USBPHY_STATUS_DEVPLUGIN_STATUS	(1 << 6)
> > +#define BM_USBPHY_STATUS_HOSTDISCON_STATUS	(1 << 3)
> > +
> > +/* FIXME */
> > +#define M28EVK_USBOTG_ENABLE	MXS_GPIO_NR(3, 12)
> > +
> 
> This is platform code, should not put at driver.
> 
> > +struct mxs_usb_phy {
> > +	struct usb_phy		phy;
> > +
> > +	struct work_struct	work;
> > +
> > +	struct clk		*clk;
> > +	struct resource		*mem_res;
> > +	void __iomem		*mem;
> > +	int			irq;
> > +	int			gpio_vbus;
> > +	int			gpio_vbus_inverted;
> > +
> > +	enum usb_otg_state	new_state;
> > +
> > +	bool			host_mode;
> > +};
> > +
> > +static int mxs_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
> 
> should be at imx-otg.c

I don't understand why. This is clearly specific to this PHY driver.

> 
> > +
> > +static int mxs_usb_set_peripheral(struct usb_otg *otg, struct usb_gadget
> > *gg)
> 
> gg may not a good name, how about just gadget?
> should be at imx-otg.c

DTTO

> > +static void mxs_usb_work(struct work_struct *w)
> 
> It is OTG switch routine, and should be put imx-otg.c. Sascha also
> suggested before.

Fine by me, but until someone can clearly explain to me why PHY specific code 
should be in a shared file (even if it's completely unrelated to it), I see no 
point moving this.

> > +{
> > +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
> > +	struct usb_otg *otg = phy->phy.otg;
> > +	struct usb_hcd *hcd;
> > +
> > +	switch (otg->phy->state) {
> > +	case OTG_STATE_A_HOST:
> > +		if (phy->new_state == OTG_STATE_UNDEFINED) {
> > +			hcd = bus_to_hcd(otg->host);
> > +			usb_remove_hcd(hcd);
> > +			otg->phy->state = phy->new_state;
> > +			/* Turn off VBUS */
> > +			gpio_set_value(phy->gpio_vbus,
> > +				phy->gpio_vbus_inverted);
> > +		}
> > +		break;
> > +	case OTG_STATE_B_PERIPHERAL:
> > +		if (phy->new_state == OTG_STATE_UNDEFINED) {
> > +			usb_del_gadget_udc(otg->gadget);
> > +			otg->phy->state = phy->new_state;
> > +		}
> > +		break;
> > +	case OTG_STATE_UNDEFINED:
> > +		/* Check desired state. */
> > +		switch (phy->new_state) {
> > +		case OTG_STATE_A_HOST:
> > +			if (!otg->host)
> > +				break;
> > +			otg->phy->state = phy->new_state;
> > +
> > +			/* Turn on VBUS */
> > +			gpio_set_value(phy->gpio_vbus,
> > +				!phy->gpio_vbus_inverted);
> > +
> > +			hcd = bus_to_hcd(otg->host);
> > +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> > +			break;
> > +		case OTG_STATE_B_PERIPHERAL:
> > +			if (!otg->gadget)
> > +				break;
> > +			otg->phy->state = phy->new_state;
> > +			usb_add_gadget_udc(phy->phy.dev, otg->gadget);
> > +			break;
> > +		default:
> > +			break;
> > +		}
> > +		break;
> > +
> > +	default:
> > +		break;
> > +	}
> > +}
> > +
> 
> Seems you forget one otg state: OTG_STATE_B_IDLE.
> 
> at device mode:
> OTG_STATE_UNDEFINED -> OTG_STATE_B_IDLE (nothing on port)
> OTG_STATE_B_PERIPHERAL -> OTG_STATE_B_IDLE (disconnect with host)

This OTG biz really needs further work. So far, we only support Host/Device.

> 
> > +static int mxs_usb_phy_init(struct usb_phy *x)
> > +{
> > +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> > +	uint32_t val;
> > +
> > +	/* Enable clock to the PHY. */
> > +	clk_enable(phy->clk);
> > +
> > +	/* Reset the PHY block. */
> > +	mxs_reset_block(phy->mem + HW_USBPHY_CTRL);
> > +
> > +	/* Power up the PHY. */
> > +	writel(0, phy->mem + HW_USBPHY_PWD);
> > +
> > +	/* Enable FS/LS compatibility. */
> > +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3;
> > +
> > +	if (phy->host_mode)
> > +		val |= BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
> > +	else
> > +		val |= BM_USBPHY_CTRL_ENIRQDEVPLUGIN |
> > +			BM_USBPHY_CTRL_ENOTGIDDETECT |
> > +			BM_USBPHY_CTRL_ENDEVPLUGINDETECT;
> 
> Please explain the meaning of above code?
> 
> > +static void mxs_usb_phy_shutdown(struct usb_phy *x)
> > +{
> > +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> > +
> 
> You need to set portsc.phcd=1 and power down phy using set 0xffffffff to
> HW_USBPHY_PWD.
> 
> > +	/* Gate off the PHY. */
> > +	writel(BM_USBPHY_CTRL_CLKGATE, phy->mem + HW_USBPHY_CTRL_SET);
> > +
> > +	/* Disable clock to the PHY. */
> > +	clk_disable(phy->clk);
> > +}
> > +
> > +static irqreturn_t mxs_phy_irq(int irq, void *data)
> > +{
> > +	struct mxs_usb_phy *phy = data;
> > +	uint32_t status = readl(phy->mem + HW_USBPHY_STATUS);
> > +
> > +	if (status & BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ)
> > +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> > +			phy->mem + HW_USBPHY_CTRL_CLR);
> > +	else
> > +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> > +			phy->mem + HW_USBPHY_CTRL_SET);
> > +
> 
> Have you tested several connect/disconnect operation with high speed
> device? - where you clear BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ?
> - This code will always run at every usb interrupt, in fact, high speed
> detector only needs to be set/clear with connect/disconnect.

I have yet to figure out how to actually detect host connect/disconnect in OTG 
mode while also detect Device connect/disconnect. Can you elaborate on what 
needs to be set in the CTRL register to generate these interrupts?

> > +	return IRQ_NONE;
> > +}
> > +
> > 
> > 
> > +
> > +static int __devexit mxs_phy_remove(struct platform_device *pdev)
> > +{
> > +	struct mxs_usb_phy *phy = platform_get_drvdata(pdev);
> > +
> > +	/* Stop the PHY work. */
> > +	cancel_work_sync(&phy->work);
> > +
> > +	/* Power down the PHY. */
> > +	mxs_usb_phy_shutdown(&phy->phy);
> > +
> > +	/* Remove the transceiver. */
> > +	usb_set_transceiver(NULL);
> > +
> > +	/* Shut off VBUS. */
> > +	gpio_set_value(phy->gpio_vbus, phy->gpio_vbus_inverted);
> > +	gpio_free(phy->gpio_vbus);
> > +
> > +	/* Free the IRQ requested by this device. */
> > +	free_irq(phy->irq, phy);
> > +
> > +	/* Free the IRQ requested by this device. */
> > +	free_irq(phy->irq, phy);
> > +
> 
> Two free_irq???

Rebase issue

> 
> > +	/* Stop the PHY clock. */
> > +	clk_disable_unprepare(phy->clk);
> > +	clk_put(phy->clk);
> > +
> > +	/* Free the rest. */
> > +	platform_set_drvdata(pdev, NULL);
> > +
> > +	return 0;
> > +}
> > +

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

* [PATCH 11/11] MXS: Enable USB on M28EVK
  2012-04-23  1:57         ` Chen Peter-B29397
@ 2012-04-23  2:18           ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-23  2:18 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > Enable the second USB port on M28EVK board.
> > 
> > 
> > +
> > +	mx28_add_mxs_usbh(0, &m28_usb_data);
> > 
> >  }
> 
> You have enabled second port at mx28evk, why it "0"? at your
> mx28_add_mxs_usbh(0, &m28_usb_data).

Correct, I needed to test this with the gadget-capable port and this snuck in.

> 
> >  static void __init m28evk_timer_init(void)
> > 
> > --
> > 1.7.9.5

Best regards,
Marek Vasut

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-23  2:01       ` [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver Chen Peter-B29397
@ 2012-04-23  2:18         ` Marek Vasut
  2012-04-23 11:59           ` Chen Peter-B29397
  2012-04-23  2:37         ` Marek Vasut
  1 sibling, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-23  2:18 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > the
> > generic USB PHY infrastructure. Also added is glue code for CI13xxx
> > driver, to
> > allow device mode. This patchset still does NOT support OTG mode, the
> > device/host mode is selected via platform data.
> 
> Does the udc work at this patchset? If it is, you have enabled OTG port
> and not host 1 port, correct?

Wait for V5. Gadget mode should work, V5 should have some further rebase issues 
fixed.

> 
> > V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> > drivers.
> > V3: Add the HCD on demand based on the PHY's state (only add HCD if it's
> > host).
> > 
> >     Currently, only the HOST mode is supported.
> > 
> > V4: * Introduce ci13xxx gadget glue
> > 
> >     * Reorder patches in a more sensible order
> >     * Introduce platform data, containing VBUS GPIO and port mode
> > 
> > (device/gadget)
> > 
> >     * Rename imx-usb to imx-otg
> >     * Drop mx28evk usb host patch
> >     * Use more devm_ function
> >     * Rework the mxs-phy to register the same interrupt as ehci-mxs (and
> >     
> >       effectivelly kill bogus otg_set_vbus() call from ehci-mxs ; use
> > 
> > standard
> > 
> >       ehci irq handling in ehci-mxs)
> > 
> > Marek Vasut (11):
> >   MXS: Make clk_disable return integer
> >   MXS: Add USB EHCI and USB PHY clock handling
> >   MXS: Fixup i.MX233 USB base address name
> >   MXS: Add data shared between imx-otg and EHCI driver
> >   MXS: Modify the ci13xxx_udc to avoid adding UDC
> >   MXS: Add small registration glue for ci13xxx_udc
> >   MXS: Add separate MXS EHCI HCD driver
> >   MXS: Add imx-otg driver
> >   MXS: Add USB PHY driver
> >   MXS: Add platform registration hooks for USB EHCI
> >   MXS: Enable USB on M28EVK
> >  
> >  arch/arm/mach-mxs/Kconfig                       |    2 +
> >  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
> >  arch/arm/mach-mxs/devices-mx28.h                |    5 +
> >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> >  arch/arm/mach-mxs/devices/platform-usb.c        |   84 +++++
> >  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> >  arch/arm/mach-mxs/include/mach/devices-common.h |   12 +
> >  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> >  arch/arm/mach-mxs/mach-m28evk.c                 |   20 ++
> >  drivers/usb/gadget/Kconfig                      |   17 +
> >  drivers/usb/gadget/Makefile                     |    1 +
> >  drivers/usb/gadget/ci13xxx_mxs.c                |   67 ++++
> >  drivers/usb/gadget/ci13xxx_udc.c                |   12 +-
> >  drivers/usb/gadget/ci13xxx_udc.h                |    1 +
> >  drivers/usb/host/Kconfig                        |    7 +
> >  drivers/usb/host/ehci-hcd.c                     |    5 +
> >  drivers/usb/host/ehci-mxs.c                     |  197 ++++++++++
> >  drivers/usb/otg/Kconfig                         |   16 +
> >  drivers/usb/otg/Makefile                        |    2 +
> >  drivers/usb/otg/imx-otg.c                       |  282 +++++++++++++++
> >  drivers/usb/otg/mxs-phy.c                       |  438
> > 
> > +++++++++++++++++++++++
> > 
> >  include/linux/fsl/mxs-usb.h                     |   46 +++
> >  23 files changed, 1243 insertions(+), 13 deletions(-)
> >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> >  create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c
> >  create mode 100644 drivers/usb/host/ehci-mxs.c
> >  create mode 100644 drivers/usb/otg/imx-otg.c
> >  create mode 100644 drivers/usb/otg/mxs-phy.c
> >  create mode 100644 include/linux/fsl/mxs-usb.h
> > 
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > 
> > NOTE: Adding this ci13xxx-mxs driver was really helpful, it helped me to
> > realise
> > 
> >       how this whole monster should look like in the end. Now the mxs-phy
> > 
> > is
> > 
> >       also much more prepared for the OTG operation.
> > 
> > --
> > 1.7.9.5

Best regards,
Marek Vasut

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-23  2:01       ` [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver Chen Peter-B29397
  2012-04-23  2:18         ` Marek Vasut
@ 2012-04-23  2:37         ` Marek Vasut
  1 sibling, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-23  2:37 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > the
> > generic USB PHY infrastructure. Also added is glue code for CI13xxx
> > driver, to
> > allow device mode. This patchset still does NOT support OTG mode, the
> > device/host mode is selected via platform data.
> 
> Does the udc work at this patchset? If it is, you have enabled OTG port
> and not host 1 port, correct?

btw Peter, thanks for the review, you caught some pretty nasty problems.

> > V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> > drivers.
> > V3: Add the HCD on demand based on the PHY's state (only add HCD if it's
> > host).
> > 
> >     Currently, only the HOST mode is supported.
> > 
> > V4: * Introduce ci13xxx gadget glue
> > 
> >     * Reorder patches in a more sensible order
> >     * Introduce platform data, containing VBUS GPIO and port mode
> > 
> > (device/gadget)
> > 
> >     * Rename imx-usb to imx-otg
> >     * Drop mx28evk usb host patch
> >     * Use more devm_ function
> >     * Rework the mxs-phy to register the same interrupt as ehci-mxs (and
> >     
> >       effectivelly kill bogus otg_set_vbus() call from ehci-mxs ; use
> > 
> > standard
> > 
> >       ehci irq handling in ehci-mxs)
> > 
> > Marek Vasut (11):
> >   MXS: Make clk_disable return integer
> >   MXS: Add USB EHCI and USB PHY clock handling
> >   MXS: Fixup i.MX233 USB base address name
> >   MXS: Add data shared between imx-otg and EHCI driver
> >   MXS: Modify the ci13xxx_udc to avoid adding UDC
> >   MXS: Add small registration glue for ci13xxx_udc
> >   MXS: Add separate MXS EHCI HCD driver
> >   MXS: Add imx-otg driver
> >   MXS: Add USB PHY driver
> >   MXS: Add platform registration hooks for USB EHCI
> >   MXS: Enable USB on M28EVK
> >  
> >  arch/arm/mach-mxs/Kconfig                       |    2 +
> >  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
> >  arch/arm/mach-mxs/devices-mx28.h                |    5 +
> >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> >  arch/arm/mach-mxs/devices/platform-usb.c        |   84 +++++
> >  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> >  arch/arm/mach-mxs/include/mach/devices-common.h |   12 +
> >  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> >  arch/arm/mach-mxs/mach-m28evk.c                 |   20 ++
> >  drivers/usb/gadget/Kconfig                      |   17 +
> >  drivers/usb/gadget/Makefile                     |    1 +
> >  drivers/usb/gadget/ci13xxx_mxs.c                |   67 ++++
> >  drivers/usb/gadget/ci13xxx_udc.c                |   12 +-
> >  drivers/usb/gadget/ci13xxx_udc.h                |    1 +
> >  drivers/usb/host/Kconfig                        |    7 +
> >  drivers/usb/host/ehci-hcd.c                     |    5 +
> >  drivers/usb/host/ehci-mxs.c                     |  197 ++++++++++
> >  drivers/usb/otg/Kconfig                         |   16 +
> >  drivers/usb/otg/Makefile                        |    2 +
> >  drivers/usb/otg/imx-otg.c                       |  282 +++++++++++++++
> >  drivers/usb/otg/mxs-phy.c                       |  438
> > 
> > +++++++++++++++++++++++
> > 
> >  include/linux/fsl/mxs-usb.h                     |   46 +++
> >  23 files changed, 1243 insertions(+), 13 deletions(-)
> >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> >  create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c
> >  create mode 100644 drivers/usb/host/ehci-mxs.c
> >  create mode 100644 drivers/usb/otg/imx-otg.c
> >  create mode 100644 drivers/usb/otg/mxs-phy.c
> >  create mode 100644 include/linux/fsl/mxs-usb.h
> > 
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > 
> > NOTE: Adding this ci13xxx-mxs driver was really helpful, it helped me to
> > realise
> > 
> >       how this whole monster should look like in the end. Now the mxs-phy
> > 
> > is
> > 
> >       also much more prepared for the OTG operation.
> > 
> > --
> > 1.7.9.5

Best regards,
Marek Vasut

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-22 12:59       ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
@ 2012-04-23  6:39         ` Sascha Hauer
  2012-04-23  9:38           ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-23  6:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Apr 22, 2012 at 02:59:24PM +0200, Marek Vasut wrote:
> This driver handles claiming of clocks and memory areas. These are later
> properly delegated to it's child devices, the USB Host (ehci-mxs) and
> USB Gadget (ci13xxx-mxs).
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  drivers/usb/otg/Kconfig   |    6 +
>  drivers/usb/otg/Makefile  |    1 +
>  drivers/usb/otg/imx-otg.c |  282 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 289 insertions(+)
>  create mode 100644 drivers/usb/otg/imx-otg.c
> 
> diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> index 5c87db0..e7c6325 100644
> --- a/drivers/usb/otg/Kconfig
> +++ b/drivers/usb/otg/Kconfig
> @@ -116,6 +116,12 @@ config FSL_USB2_OTG
>  	help
>  	  Enable this to support Freescale USB OTG transceiver.
>  
> +config USB_IMX_COMPOSITE
> +	bool
> +	help
> +	  Composite driver that handles clock and memory mapping for
> +	  i.MX USB host and USB PHY.
> +
>  config USB_MV_OTG
>  	tristate "Marvell USB OTG support"
>  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> index 41aa509..7d2c631 100644
> --- a/drivers/usb/otg/Makefile
> +++ b/drivers/usb/otg/Makefile
> @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
>  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
>  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
>  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> +obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
>  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
> new file mode 100644
> index 0000000..249b6b5
> --- /dev/null
> +++ b/drivers/usb/otg/imx-otg.c
> @@ -0,0 +1,282 @@
> +/*
> + * drivers/usb/otg/imx-otg.c
> + *
> + * Freescale i.MX USB composite driver.
> + *
> + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> + * on behalf of DENX Software Engineering GmbH
> + *
> + * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/usb.h>
> +#include <linux/usb/otg.h>
> +#include <linux/usb/hcd.h>
> +#include <linux/slab.h>
> +#include <linux/delay.h>
> +#include <linux/fsl/mxs-usb.h>
> +#include <linux/io.h>
> +
> +#include <mach/common.h>
> +#include <mach/hardware.h>
> +#include <mach/devices-common.h>
> +
> +/*
> + * Allocate platform device with the DMA mask, this is borrowed from
> + * arch/arm/mach-mxs/devices.c
> + */
> +static struct platform_device *__devinit add_platform_device(
> +		const char *name, int id,
> +		const void *data, size_t size_data, u64 dmamask)
> +{
> +	int ret = -ENOMEM;
> +	struct platform_device *pdev;
> +
> +	pdev = platform_device_alloc(name, id);
> +	if (!pdev)
> +		goto err;
> +
> +	if (dmamask) {
> +		/*
> +		 * This memory isn't freed when the device is put,
> +		 * I don't have a nice idea for that though.  Conceptually
> +		 * dma_mask in struct device should not be a pointer.
> +		 * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
> +		 */
> +		pdev->dev.dma_mask =
> +			kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
> +		if (!pdev->dev.dma_mask)
> +			/* ret is still -ENOMEM; */
> +			goto err;
> +
> +		*pdev->dev.dma_mask = dmamask;
> +		pdev->dev.coherent_dma_mask = dmamask;
> +	}
> +
> +	if (data) {
> +		ret = platform_device_add_data(pdev, data, size_data);
> +		if (ret)
> +			goto err;
> +	}
> +
> +	ret = platform_device_add(pdev);
> +	if (ret) {
> +err:
> +		if (dmamask)
> +			kfree(pdev->dev.dma_mask);
> +		platform_device_put(pdev);
> +		return ERR_PTR(ret);
> +	}
> +
> +	return pdev;
> +}
> +
> +static int __devinit imx_usb_probe(struct platform_device *pdev)
> +{
> +	struct imx_usb_platform_data *pdata = pdev->dev.platform_data;
> +	struct imx_usb *data;
> +	struct usb_phy *phy;
> +	int ret;
> +	void *retp = NULL;
> +
> +	if (!pdata) {
> +		dev_err(&pdev->dev, "No platform data supplied!\n");
> +		return -ENODEV;
> +	}
> +
> +	phy = usb_get_transceiver();
> +	if (!phy)
> +		return -EPROBE_DEFER;
> +
> +	/*
> +	 * Until further notice, this claims all necessary resources.
> +	 */
> +
> +	/* Allocate driver's private date. */
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data) {
> +		ret = -ENOMEM;
> +		goto err_alloc_data;
> +	}
> +
> +	/* Claim the Host clock. */
> +	data->clk = clk_get(&pdev->dev, "usb");
> +	if (IS_ERR(data->clk)) {
> +		dev_err(&pdev->dev, "Failed to claim clock for USB Host\n");
> +		ret = PTR_ERR(data->clk);
> +		goto err_claim_host_clock;
> +	}
> +
> +	/* Prepare Host clock. */
> +	ret = clk_prepare_enable(data->clk);
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to enable clock for USB Host.\n");
> +		goto err_prepare_host_clock;
> +	}
> +
> +	/* Get memory area for EHCI host from resources. */
> +	data->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!data->mem_res) {
> +		dev_err(&pdev->dev, "Specify memory area for this USB Host!\n");
> +		ret = -ENODEV;
> +		goto err_get_host_resource;
> +	}
> +
> +	/* Request the memory region for this USB Host. */
> +	retp = devm_request_mem_region(&pdev->dev, data->mem_res->start,
> +			resource_size(data->mem_res), pdev->name);
> +	if (!retp) {
> +		dev_err(&pdev->dev, "USB Host memory area already in use!\n");
> +		ret = -EBUSY;
> +		goto err_get_host_mem;
> +	}
> +
> +	/* Map the memory region for USB Host. */
> +	data->mem = devm_ioremap(&pdev->dev, data->mem_res->start,
> +				resource_size(data->mem_res));
> +	if (!data->mem) {
> +		dev_err(&pdev->dev, "Memory mapping of USB Host failed!\n");
> +		ret = -EFAULT;
> +		goto err_map_host_mem;
> +	}
> +
> +	/* Get IRQ for EHCI host from resources. */
> +	data->irq = platform_get_irq(pdev, 0);
> +	if (data->irq < 0) {
> +		dev_err(&pdev->dev, "Specify IRQ for this USB Host!\n");
> +		ret = -ENODEV;
> +		goto err_get_host_irq;
> +	}
> +
> +	/*
> +	 * Now finally probe the Host driver!
> +	 */
> +	if (pdata->host_mode) {
> +		data->pdev_host = add_platform_device("mxs-ehci", -1,
> +							data, sizeof(*data),
> +							DMA_BIT_MASK(32));
> +		if (!data->pdev_host) {
> +			dev_err(&pdev->dev, "Failed registering Host!\n");
> +			ret = -ENODEV;
> +			goto err_register_host;
> +		}
> +	} else {
> +		data->pdev_gadget = add_platform_device("ci13xxx-mxs", -1,
> +							data, sizeof(*data),
> +							DMA_BIT_MASK(32));
> +		if (!data->pdev_gadget) {
> +			dev_err(&pdev->dev, "Failed registering Host!\n");
> +			ret = -ENODEV;
> +			goto err_register_gadget;
> +		}
> +	}
> +
> +	/*
> +	 * Initialize the transceiver
> +	 */
> +	phy = usb_get_transceiver();
> +	if (!phy) {
> +		dev_err(&pdev->dev, "Unable to find transceiver.\n");
> +		ret = -ENODEV;
> +		goto err_phy;
> +	}
> +
> +	ret = usb_phy_init(phy);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Unable init transceiver\n");
> +		ret = -ENODEV;
> +		goto err_phy_init;
> +	}
> +
> +	/* Set up the PORTSCx register */
> +	writel(0, data->mem + 0x144);
> +
> +	return 0;
> +
> +err_phy_init:
> +	if (phy)
> +		usb_put_transceiver(phy);
> +err_phy:
> +	if (data->pdev_gadget)
> +		platform_device_unregister(data->pdev_gadget);
> +err_register_gadget:
> +	if (data->pdev_host)
> +		platform_device_unregister(data->pdev_host);
> +err_register_host:
> +err_get_host_irq:
> +	iounmap(data->mem);
> +err_map_host_mem:
> +	release_mem_region(data->mem_res->start,
> +			resource_size(data->mem_res));
> +err_get_host_mem:
> +	data->mem_res = NULL;
> +err_get_host_resource:
> +	clk_disable_unprepare(data->clk);
> +err_prepare_host_clock:
> +	clk_put(data->clk);
> +err_claim_host_clock:
> +err_alloc_data:
> +	return ret;
> +}
> +
> +static int __devexit imx_usb_remove(struct platform_device *pdev)
> +{
> +	struct imx_usb *data = platform_get_drvdata(pdev);
> +
> +	if (data->pdev_gadget)
> +		platform_device_unregister(data->pdev_gadget);
> +
> +	if (data->pdev_host)
> +		platform_device_unregister(data->pdev_host);
> +
> +	iounmap(data->mem);
> +	release_mem_region(data->mem_res->start,
> +			resource_size(data->mem_res));

Again, you are using the managed versions of ioremap and
request_mem_region. The whole point of these functions is that these
resources are automatically released on driver exit (or failure at
probe).

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-23  6:39         ` Sascha Hauer
@ 2012-04-23  9:38           ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-23  9:38 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> On Sun, Apr 22, 2012 at 02:59:24PM +0200, Marek Vasut wrote:
> > This driver handles claiming of clocks and memory areas. These are later
> > properly delegated to it's child devices, the USB Host (ehci-mxs) and
> > USB Gadget (ci13xxx-mxs).
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > ---
> > 
> >  drivers/usb/otg/Kconfig   |    6 +
> >  drivers/usb/otg/Makefile  |    1 +
> >  drivers/usb/otg/imx-otg.c |  282
> >  +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 289
> >  insertions(+)
> >  create mode 100644 drivers/usb/otg/imx-otg.c
> > 
> > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > index 5c87db0..e7c6325 100644
> > --- a/drivers/usb/otg/Kconfig
> > +++ b/drivers/usb/otg/Kconfig
> > @@ -116,6 +116,12 @@ config FSL_USB2_OTG
> > 
> >  	help
> >  	
> >  	  Enable this to support Freescale USB OTG transceiver.
> > 
> > +config USB_IMX_COMPOSITE
> > +	bool
> > +	help
> > +	  Composite driver that handles clock and memory mapping for
> > +	  i.MX USB host and USB PHY.
> > +
> > 
> >  config USB_MV_OTG
> >  
> >  	tristate "Marvell USB OTG support"
> >  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> > 
> > diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> > index 41aa509..7d2c631 100644
> > --- a/drivers/usb/otg/Makefile
> > +++ b/drivers/usb/otg/Makefile
> > @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
> > 
> >  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
> >  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
> >  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> > 
> > +obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
> > 
> >  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> > 
> > diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
> > new file mode 100644
> > index 0000000..249b6b5
> > --- /dev/null
> > +++ b/drivers/usb/otg/imx-otg.c
> > @@ -0,0 +1,282 @@
> > +/*
> > + * drivers/usb/otg/imx-otg.c
> > + *
> > + * Freescale i.MX USB composite driver.
> > + *
> > + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> > + * on behalf of DENX Software Engineering GmbH
> > + *
> > + * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
> > + */
> > +
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/dma-mapping.h>
> > +#include <linux/usb.h>
> > +#include <linux/usb/otg.h>
> > +#include <linux/usb/hcd.h>
> > +#include <linux/slab.h>
> > +#include <linux/delay.h>
> > +#include <linux/fsl/mxs-usb.h>
> > +#include <linux/io.h>
> > +
> > +#include <mach/common.h>
> > +#include <mach/hardware.h>
> > +#include <mach/devices-common.h>
> > +
> > +/*
> > + * Allocate platform device with the DMA mask, this is borrowed from
> > + * arch/arm/mach-mxs/devices.c
> > + */
> > +static struct platform_device *__devinit add_platform_device(
> > +		const char *name, int id,
> > +		const void *data, size_t size_data, u64 dmamask)
> > +{
> > +	int ret = -ENOMEM;
> > +	struct platform_device *pdev;
> > +
> > +	pdev = platform_device_alloc(name, id);
> > +	if (!pdev)
> > +		goto err;
> > +
> > +	if (dmamask) {
> > +		/*
> > +		 * This memory isn't freed when the device is put,
> > +		 * I don't have a nice idea for that though.  Conceptually
> > +		 * dma_mask in struct device should not be a pointer.
> > +		 * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
> > +		 */
> > +		pdev->dev.dma_mask =
> > +			kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
> > +		if (!pdev->dev.dma_mask)
> > +			/* ret is still -ENOMEM; */
> > +			goto err;
> > +
> > +		*pdev->dev.dma_mask = dmamask;
> > +		pdev->dev.coherent_dma_mask = dmamask;
> > +	}
> > +
> > +	if (data) {
> > +		ret = platform_device_add_data(pdev, data, size_data);
> > +		if (ret)
> > +			goto err;
> > +	}
> > +
> > +	ret = platform_device_add(pdev);
> > +	if (ret) {
> > +err:
> > +		if (dmamask)
> > +			kfree(pdev->dev.dma_mask);
> > +		platform_device_put(pdev);
> > +		return ERR_PTR(ret);
> > +	}
> > +
> > +	return pdev;
> > +}
> > +
> > +static int __devinit imx_usb_probe(struct platform_device *pdev)
> > +{
> > +	struct imx_usb_platform_data *pdata = pdev->dev.platform_data;
> > +	struct imx_usb *data;
> > +	struct usb_phy *phy;
> > +	int ret;
> > +	void *retp = NULL;
> > +
> > +	if (!pdata) {
> > +		dev_err(&pdev->dev, "No platform data supplied!\n");
> > +		return -ENODEV;
> > +	}
> > +
> > +	phy = usb_get_transceiver();
> > +	if (!phy)
> > +		return -EPROBE_DEFER;
> > +
> > +	/*
> > +	 * Until further notice, this claims all necessary resources.
> > +	 */
> > +
> > +	/* Allocate driver's private date. */
> > +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > +	if (!data) {
> > +		ret = -ENOMEM;
> > +		goto err_alloc_data;
> > +	}
> > +
> > +	/* Claim the Host clock. */
> > +	data->clk = clk_get(&pdev->dev, "usb");
> > +	if (IS_ERR(data->clk)) {
> > +		dev_err(&pdev->dev, "Failed to claim clock for USB Host\n");
> > +		ret = PTR_ERR(data->clk);
> > +		goto err_claim_host_clock;
> > +	}
> > +
> > +	/* Prepare Host clock. */
> > +	ret = clk_prepare_enable(data->clk);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "Failed to enable clock for USB Host.\n");
> > +		goto err_prepare_host_clock;
> > +	}
> > +
> > +	/* Get memory area for EHCI host from resources. */
> > +	data->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > +	if (!data->mem_res) {
> > +		dev_err(&pdev->dev, "Specify memory area for this USB Host!\n");
> > +		ret = -ENODEV;
> > +		goto err_get_host_resource;
> > +	}
> > +
> > +	/* Request the memory region for this USB Host. */
> > +	retp = devm_request_mem_region(&pdev->dev, data->mem_res->start,
> > +			resource_size(data->mem_res), pdev->name);
> > +	if (!retp) {
> > +		dev_err(&pdev->dev, "USB Host memory area already in use!\n");
> > +		ret = -EBUSY;
> > +		goto err_get_host_mem;
> > +	}
> > +
> > +	/* Map the memory region for USB Host. */
> > +	data->mem = devm_ioremap(&pdev->dev, data->mem_res->start,
> > +				resource_size(data->mem_res));
> > +	if (!data->mem) {
> > +		dev_err(&pdev->dev, "Memory mapping of USB Host failed!\n");
> > +		ret = -EFAULT;
> > +		goto err_map_host_mem;
> > +	}
> > +
> > +	/* Get IRQ for EHCI host from resources. */
> > +	data->irq = platform_get_irq(pdev, 0);
> > +	if (data->irq < 0) {
> > +		dev_err(&pdev->dev, "Specify IRQ for this USB Host!\n");
> > +		ret = -ENODEV;
> > +		goto err_get_host_irq;
> > +	}
> > +
> > +	/*
> > +	 * Now finally probe the Host driver!
> > +	 */
> > +	if (pdata->host_mode) {
> > +		data->pdev_host = add_platform_device("mxs-ehci", -1,
> > +							data, sizeof(*data),
> > +							DMA_BIT_MASK(32));
> > +		if (!data->pdev_host) {
> > +			dev_err(&pdev->dev, "Failed registering Host!\n");
> > +			ret = -ENODEV;
> > +			goto err_register_host;
> > +		}
> > +	} else {
> > +		data->pdev_gadget = add_platform_device("ci13xxx-mxs", -1,
> > +							data, sizeof(*data),
> > +							DMA_BIT_MASK(32));
> > +		if (!data->pdev_gadget) {
> > +			dev_err(&pdev->dev, "Failed registering Host!\n");
> > +			ret = -ENODEV;
> > +			goto err_register_gadget;
> > +		}
> > +	}
> > +
> > +	/*
> > +	 * Initialize the transceiver
> > +	 */
> > +	phy = usb_get_transceiver();
> > +	if (!phy) {
> > +		dev_err(&pdev->dev, "Unable to find transceiver.\n");
> > +		ret = -ENODEV;
> > +		goto err_phy;
> > +	}
> > +
> > +	ret = usb_phy_init(phy);
> > +	if (ret < 0) {
> > +		dev_err(&pdev->dev, "Unable init transceiver\n");
> > +		ret = -ENODEV;
> > +		goto err_phy_init;
> > +	}
> > +
> > +	/* Set up the PORTSCx register */
> > +	writel(0, data->mem + 0x144);
> > +
> > +	return 0;
> > +
> > +err_phy_init:
> > +	if (phy)
> > +		usb_put_transceiver(phy);
> > +err_phy:
> > +	if (data->pdev_gadget)
> > +		platform_device_unregister(data->pdev_gadget);
> > +err_register_gadget:
> > +	if (data->pdev_host)
> > +		platform_device_unregister(data->pdev_host);
> > +err_register_host:
> > +err_get_host_irq:
> > +	iounmap(data->mem);
> > +err_map_host_mem:
> > +	release_mem_region(data->mem_res->start,
> > +			resource_size(data->mem_res));
> > +err_get_host_mem:
> > +	data->mem_res = NULL;
> > +err_get_host_resource:
> > +	clk_disable_unprepare(data->clk);
> > +err_prepare_host_clock:
> > +	clk_put(data->clk);
> > +err_claim_host_clock:
> > +err_alloc_data:
> > +	return ret;
> > +}
> > +
> > +static int __devexit imx_usb_remove(struct platform_device *pdev)
> > +{
> > +	struct imx_usb *data = platform_get_drvdata(pdev);
> > +
> > +	if (data->pdev_gadget)
> > +		platform_device_unregister(data->pdev_gadget);
> > +
> > +	if (data->pdev_host)
> > +		platform_device_unregister(data->pdev_host);
> > +
> > +	iounmap(data->mem);
> > +	release_mem_region(data->mem_res->start,
> > +			resource_size(data->mem_res));
> 
> Again, you are using the managed versions of ioremap and
> request_mem_region. The whole point of these functions is that these
> resources are automatically released on driver exit (or failure at
> probe).

Argh. Anyway, I'm more interested to hear your opinion on the general concept, 
esp. on Peter's comment on otg_set_host()/otg_set_peripheral() -- their 
implementation should be in the PHY driver and they should be called from EHCI 
host / ci13xxx gadget driver, correct?

> Sascha

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-23  2:18         ` Marek Vasut
@ 2012-04-23 11:59           ` Chen Peter-B29397
  2012-04-23 12:09             ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23 11:59 UTC (permalink / raw)
  To: linux-arm-kernel



 
> >
> > Does the udc work at this patchset? If it is, you have enabled OTG port
> > and not host 1 port, correct?
> 
> Wait for V5. Gadget mode should work, V5 should have some further rebase
> issues
> fixed.
> 
>From my point, you'd better step by step, first, mainline host and phy.
then, gadget. At last OTG if you have been interested in.

It can be easier for your mainline, as some of them have still not implemented
at your local. What's your opinion, Sascha?

 

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-23 11:59           ` Chen Peter-B29397
@ 2012-04-23 12:09             ` Marek Vasut
  2012-04-23 12:25               ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-23 12:09 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > > Does the udc work at this patchset? If it is, you have enabled OTG port
> > > and not host 1 port, correct?
> > 
> > Wait for V5. Gadget mode should work, V5 should have some further rebase
> > issues
> > fixed.
> 
> From my point, you'd better step by step, first, mainline host and phy.
> then, gadget. At last OTG if you have been interested in.

OTG is certainly going last, I still have to figure that out. I wanted to add 
gadget to see how this whole thing will work together to avoid design mistakes.

> It can be easier for your mainline, as some of them have still not
> implemented at your local. What's your opinion, Sascha?

I don't follow here, what do you mean?

Best regards,
Marek Vasut

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

* [PATCH 09/11] MXS: Add USB PHY driver
  2012-04-23  2:17           ` Marek Vasut
@ 2012-04-23 12:20             ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23 12:20 UTC (permalink / raw)
  To: linux-arm-kernel

 
> > > +
> > > +static int mxs_usb_set_host(struct usb_otg *otg, struct usb_bus
> *host)
> >
> > should be at imx-otg.c
> 
> I don't understand why. This is clearly specific to this PHY driver.
>
Please take a look the definition of struct usb_otg and struct usb_phy
at include/linux/usb/otg.h. You may need to implement individual
struct at individual driver (usb_otg->otg driver, usb_phy->phy driver)
 
 
> >
> > It is OTG switch routine, and should be put imx-otg.c. Sascha also
> > suggested before.
> 
> Fine by me, but until someone can clearly explain to me why PHY specific
> code
> should be in a shared file (even if it's completely unrelated to it), I
> see no
> point moving this.
>
Can you explain what kinds of things are PHY specific from your point?

 
 
> >
> > Have you tested several connect/disconnect operation with high speed
> > device? - where you clear BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ?
> > - This code will always run at every usb interrupt, in fact, high speed
> > detector only needs to be set/clear with connect/disconnect.
> 
> I have yet to figure out how to actually detect host connect/disconnect
> in OTG
> mode while also detect Device connect/disconnect. Can you elaborate on
> what
> needs to be set in the CTRL register to generate these interrupts?
At i.mx28, there are two USB related controller, one is USB core controller,
another is USB PHY controller. Each has individual interrupt line.
You only need to set USB_PHY_CTRL for wakeup interrupt case.
Host connect/disconnect: PCD interrupt at EHCI register
Device connect/disconnect: vbus (B_SESSION_VALID) interrupt at otgsc.

For register usage, you can refer freescale git:
http://git.freescale.com/git/cgit.cgi/imx/linux-2.6-imx.git/log/?h=imx_2.6.35_10.12.01
Although the code structure is not good, you can refer some hardware operation.

 

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-23 12:09             ` Marek Vasut
@ 2012-04-23 12:25               ` Chen Peter-B29397
  2012-04-23 12:40                 ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-23 12:25 UTC (permalink / raw)
  To: linux-arm-kernel

 
> >
> > From my point, you'd better step by step, first, mainline host and phy.
> > then, gadget. At last OTG if you have been interested in.
> 
> OTG is certainly going last, I still have to figure that out. I wanted to
> add
> gadget to see how this whole thing will work together to avoid design
> mistakes.
>
I agree. Current, it is lack of generic PHY layer, so only one PHY can
be supported at board if you want to use PHY driver. I would like to
submit some generic PHY layer code, but some many internal stuffs in hands
now.

> > It can be easier for your mainline, as some of them have still not
> > implemented at your local. What's your opinion, Sascha?
> 
> I don't follow here, what do you mean?
My original mind is step by step, but you want to implement the whole structure
to see if there is any design mistakes, it is also OK.

> 
> Best regards,
> Marek Vasut

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

* [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver
  2012-04-23 12:25               ` Chen Peter-B29397
@ 2012-04-23 12:40                 ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-23 12:40 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Chen Peter-B29397,

> > > From my point, you'd better step by step, first, mainline host and phy.
> > > then, gadget. At last OTG if you have been interested in.
> > 
> > OTG is certainly going last, I still have to figure that out. I wanted to
> > add
> > gadget to see how this whole thing will work together to avoid design
> > mistakes.
> 
> I agree. Current, it is lack of generic PHY layer, so only one PHY can
> be supported at board if you want to use PHY driver.

Yes, that's indeed a problem. Doesn't seem to be a hard one though.

> I would like to
> submit some generic PHY layer code, but some many internal stuffs in hands
> now.

Good :)
> 
> > > It can be easier for your mainline, as some of them have still not
> > > implemented at your local. What's your opinion, Sascha?
> > 
> > I don't follow here, what do you mean?
> 
> My original mind is step by step, but you want to implement the whole
> structure to see if there is any design mistakes, it is also OK.

Yes exactly ... I believe it's better this way to see how it works out. I'll try 
OTG tonight if nothing more important pops up.

> > Best regards,
> > Marek Vasut

Best regards,
Marek Vasut

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

* [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver
  2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
                         ` (11 preceding siblings ...)
  2012-04-23  2:01       ` [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver Chen Peter-B29397
@ 2012-04-24  3:18       ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
                           ` (11 more replies)
  12 siblings, 12 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

From: Marek Vasut <marek.vasut@gmail.com>

This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
generic USB PHY infrastructure. Also added is glue code for CI13xxx driver, to
allow device mode. This patchset still does NOT support OTG mode, the
device/host mode is selected via platform data.

V2: Introduce stub imx-usb driver that then registers the PHY and EHCI drivers.
V3: Add the HCD on demand based on the PHY's state (only add HCD if it's host).
    Currently, only the HOST mode is supported.
V4: * Introduce ci13xxx gadget glue
    * Reorder patches in a more sensible order
    * Introduce platform data, containing VBUS GPIO and port mode (device/gadget)
    * Rename imx-usb to imx-otg
    * Drop mx28evk usb host patch
    * Use more devm_ function
    * Rework the mxs-phy to register the same interrupt as ehci-mxs (and
      effectivelly kill bogus otg_set_vbus() call from ehci-mxs ; use standard
      ehci irq handling in ehci-mxs)
V5: * Finally move OTG IRQ handling into imx-otg
    * Move imx_otg_set_{host,peripheral}() into imx-otg
    * Move imx_otg_work() into imx-otg driver (now it all makes sense, yay!)

Marek Vasut (11):
  MXS: Make clk_disable return integer
  MXS: Add USB EHCI and USB PHY clock handling
  MXS: Fixup i.MX233 USB base address name
  MXS: Add data shared between imx-otg and EHCI driver
  MXS: Modify the ci13xxx_udc to avoid adding UDC
  MXS: Add small registration glue for ci13xxx_udc
  MXS: Add separate MXS EHCI HCD driver
  MXS: Add imx-otg driver
  MXS: Add USB PHY driver
  MXS: Add platform registration hooks for USB EHCI
  MXS: Enable USB on M28EVK

 arch/arm/mach-mxs/Kconfig                       |    2 +
 arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
 arch/arm/mach-mxs/devices-mx28.h                |    5 +
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   85 ++++
 arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
 arch/arm/mach-mxs/include/mach/devices-common.h |   13 +
 arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
 arch/arm/mach-mxs/mach-m28evk.c                 |   21 +
 drivers/usb/gadget/Kconfig                      |   17 +
 drivers/usb/gadget/Makefile                     |    1 +
 drivers/usb/gadget/ci13xxx_mxs.c                |   67 ++++
 drivers/usb/gadget/ci13xxx_udc.c                |   12 +-
 drivers/usb/gadget/ci13xxx_udc.h                |    1 +
 drivers/usb/host/Kconfig                        |    7 +
 drivers/usb/host/ehci-hcd.c                     |    5 +
 drivers/usb/host/ehci-mxs.c                     |  178 +++++++++
 drivers/usb/otg/Kconfig                         |   16 +
 drivers/usb/otg/Makefile                        |    2 +
 drivers/usb/otg/imx-otg.c                       |  473 +++++++++++++++++++++++
 drivers/usb/otg/mxs-phy.c                       |  237 ++++++++++++
 include/linux/usb/mxs-usb.h                     |   95 +++++
 23 files changed, 1266 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
 create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c
 create mode 100644 drivers/usb/host/ehci-mxs.c
 create mode 100644 drivers/usb/otg/imx-otg.c
 create mode 100644 drivers/usb/otg/mxs-phy.c
 create mode 100644 include/linux/usb/mxs-usb.h

Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>

-- 
1.7.10

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

* [PATCH 01/11] MXS: Make clk_disable return integer
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
                           ` (10 subsequent siblings)
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

This allows subsequent USB clock patch to interchange enable() and disable()
calls without adding unnecessary switching cruft.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c         |    7 +++++--
 arch/arm/mach-mxs/include/mach/clock.h |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index cea29c9..43116ba 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -86,7 +86,7 @@ static int _raw_clk_enable(struct clk *clk)
 	return 0;
 }
 
-static void _raw_clk_disable(struct clk *clk)
+static int _raw_clk_disable(struct clk *clk)
 {
 	u32 reg;
 
@@ -95,6 +95,8 @@ static void _raw_clk_disable(struct clk *clk)
 		reg |= 1 << clk->enable_shift;
 		__raw_writel(reg, clk->enable_reg);
 	}
+
+	return 0;
 }
 
 /*
@@ -149,7 +151,7 @@ _CLK_ENABLE_PLL(pll1_clk, PLL1, EN_USB_CLKS)
 _CLK_ENABLE_PLL(pll2_clk, PLL2, CLKGATE)
 
 #define _CLK_DISABLE_PLL(name, r, g)					\
-static void name##_disable(struct clk *clk)				\
+static int name##_disable(struct clk *clk)				\
 {									\
 	__raw_writel(BM_CLKCTRL_##r##CTRL0_POWER,			\
 		     CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
@@ -161,6 +163,7 @@ static void name##_disable(struct clk *clk)				\
 		__raw_writel(BM_CLKCTRL_##r##CTRL0_##g,			\
 			CLKCTRL_BASE_ADDR + HW_CLKCTRL_##r##CTRL0_CLR);	\
 									\
+	return 0;							\
 }
 
 _CLK_DISABLE_PLL(pll0_clk, PLL0, EN_USB_CLKS)
diff --git a/arch/arm/mach-mxs/include/mach/clock.h b/arch/arm/mach-mxs/include/mach/clock.h
index 592c9ab..21d1fad 100644
--- a/arch/arm/mach-mxs/include/mach/clock.h
+++ b/arch/arm/mach-mxs/include/mach/clock.h
@@ -50,7 +50,7 @@ struct clk {
 	int (*enable) (struct clk *);
 	/* Function ptr to disable the clock. Leave blank if clock can not
 	   be gated. */
-	void (*disable) (struct clk *);
+	int (*disable) (struct clk *);
 	/* Function ptr to set the parent clock of the clock. */
 	int (*set_parent) (struct clk *, struct clk *);
 };
-- 
1.7.10

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

* [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
  2012-04-24  3:18         ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
                           ` (9 subsequent siblings)
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mxs/clock-mx28.c b/arch/arm/mach-mxs/clock-mx28.c
index 43116ba..8784a72 100644
--- a/arch/arm/mach-mxs/clock-mx28.c
+++ b/arch/arm/mach-mxs/clock-mx28.c
@@ -577,6 +577,21 @@ static struct clk usb1_clk = {
 	.parent = &pll1_clk,
 };
 
+static struct clk usb_phy_clk0 = {
+	.parent = &pll0_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL0CTRL0,
+	.enable_shift = 18,
+};
+
+static struct clk usb_phy_clk1 = {
+	.parent = &pll1_clk,
+	.enable = _raw_clk_disable,
+	.disable = _raw_clk_enable,
+	.enable_reg = CLKCTRL_BASE_ADDR + HW_CLKCTRL_PLL1CTRL0,
+	.enable_shift = 18,
+};
 #define _DEFINE_CLOCK(name, er, es, p)					\
 	static struct clk name = {					\
 		.enable_reg	= CLKCTRL_BASE_ADDR + HW_CLKCTRL_##er,	\
@@ -636,8 +651,10 @@ static struct clk_lookup lookups[] = {
 	_REGISTER_CLOCK("mxs-mmc.3", NULL, ssp3_clk)
 	_REGISTER_CLOCK("flexcan.0", NULL, can0_clk)
 	_REGISTER_CLOCK("flexcan.1", NULL, can1_clk)
-	_REGISTER_CLOCK(NULL, "usb0", usb0_clk)
-	_REGISTER_CLOCK(NULL, "usb1", usb1_clk)
+	_REGISTER_CLOCK("imx-otg.0", "usb", usb0_clk)
+	_REGISTER_CLOCK("imx-otg.1", "usb", usb1_clk)
+	_REGISTER_CLOCK("mxs-usb-phy.0", "phy", usb_phy_clk0)
+	_REGISTER_CLOCK("mxs-usb-phy.1", "phy", usb_phy_clk1)
 	_REGISTER_CLOCK("mxs-pwm.0", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.1", NULL, pwm_clk)
 	_REGISTER_CLOCK("mxs-pwm.2", NULL, pwm_clk)
-- 
1.7.10

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

* [PATCH 03/11] MXS: Fixup i.MX233 USB base address name
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
  2012-04-24  3:18         ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
  2012-04-24  3:18         ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
                           ` (8 subsequent siblings)
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

Modify USB EHCI and USB PHY base addresses on the i.MX233 to nicely fit into the
whole USB registration scheme.

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-mxs/include/mach/mx23.h b/arch/arm/mach-mxs/include/mach/mx23.h
index 599094b..7955b75 100644
--- a/arch/arm/mach-mxs/include/mach/mx23.h
+++ b/arch/arm/mach-mxs/include/mach/mx23.h
@@ -64,8 +64,8 @@
 #define MX23_AUART1_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06c000)
 #define MX23_AUART2_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x06e000)
 #define MX23_DUART_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x070000)
-#define MX23_USBPHY_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
-#define MX23_USBCTRL_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
+#define MX23_USBPHY0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x07c000)
+#define MX23_USBCTRL0_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x080000)
 #define MX23_DRAM_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x0e0000)
 
 #define MX23_IO_P2V(x)			MXS_IO_P2V(x)
@@ -89,8 +89,8 @@
 #define MX23_INT_SPDIF_ERROR		10
 #define MX23_INT_SAIF1_IRQ		10
 #define MX23_INT_SAIF2_IRQ		10
-#define MX23_INT_USB_CTRL		11
-#define MX23_INT_USB_WAKEUP		12
+#define MX23_INT_USB0			11
+#define MX23_INT_USB0_WAKEUP		12
 #define MX23_INT_GPMI_DMA		13
 #define MX23_INT_SSP1_DMA		14
 #define MX23_INT_SSP1_ERROR		15
-- 
1.7.10

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

* [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (2 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
                           ` (7 subsequent siblings)
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds common data shared between the MXS EHCI HCD driver,
the MXS USB Gadget driver and the imx-otg driver. These data allow
passing clock and memory stuff from imx-otg driver into the
host/gadget driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 include/linux/usb/mxs-usb.h |   95 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644 include/linux/usb/mxs-usb.h

diff --git a/include/linux/usb/mxs-usb.h b/include/linux/usb/mxs-usb.h
new file mode 100644
index 0000000..a4de28e
--- /dev/null
+++ b/include/linux/usb/mxs-usb.h
@@ -0,0 +1,95 @@
+/*
+ * include/linux/usb/mxs-usb.h
+ *
+ * Freescale i.MX USB driver shared data.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __INCLUDE_LINUX_USB_MXS_USB_H__
+#define __INCLUDE_LINUX_USB_MXS_USB_H__
+
+#include <linux/types.h>
+#include <linux/platform_device.h>
+
+#include <linux/usb/otg.h>
+
+/* MXS USB PHY register definitions. */
+#define HW_USBPHY_PWD				0x00
+
+#define HW_USBPHY_CTRL				0x30
+#define HW_USBPHY_CTRL_SET			0x34
+#define HW_USBPHY_CTRL_CLR			0x38
+#define HW_USBPHY_CTRL_TOG			0x3c
+
+#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
+#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
+#define BM_USBPHY_CTRL_ENVBUSCHG_WKUP		(1 << 23)
+#define BM_USBPHY_CTRL_ENIDCHG_WKUP		(1 << 22)
+#define BM_USBPHY_CTRL_ENDPDMCHG_WKUP		(1 << 21)
+#define BM_USBPHY_CTRL_WAKEUP_IRQ		(1 << 17)
+#define BM_USBPHY_CTRL_ENIRQWAKEUP		(1 << 16)
+#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
+#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
+#define BM_USBPHY_CTRL_ENIRQDEVPLUGIN		(1 << 11)
+#define BM_USBPHY_CTRL_RESUME_IRQ		(1 << 10)
+#define BM_USBPHY_CTRL_ENIRQRESUMEDETECT	(1 << 9)
+#define BM_USBPHY_CTRL_ENOTGIDDETECT		(1 << 7)
+#define BM_USBPHY_CTRL_ENDEVPLUGINDETECT	(1 << 4)
+#define BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ	(1 << 3)
+#define BM_USBPHY_CTRL_ENIRQHOSTDISCON		(1 << 2)
+#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
+
+#define HW_USBPHY_STATUS			0x40
+
+#define BM_USBPHY_STATUS_OTGID_STATUS		(1 << 8)
+#define BM_USBPHY_STATUS_DEVPLUGIN_STATUS	(1 << 6)
+#define BM_USBPHY_STATUS_HOSTDISCON_STATUS	(1 << 3)
+
+struct imx_otg_priv {
+	uint32_t		gpio_vbus;
+	uint32_t		gpio_vbus_inverted;
+	enum usb_otg_state	new_state;
+	enum usb_otg_state	cur_state;
+	struct usb_otg		otg;
+	struct work_struct	work;
+	struct device		*dev;
+	uint32_t		status;
+};
+
+struct imx_otg {
+	struct platform_device	*pdev_host;
+	struct platform_device	*pdev_gadget;
+
+	struct clk		*clk;
+	struct resource		*mem_res;
+	void __iomem		*mem;
+	int			irq;
+	int			irq_wakeup;
+
+	struct imx_otg_priv	priv;
+};
+
+struct imx_usb_platform_data {
+	uint32_t		gpio_vbus;
+	bool			gpio_vbus_inverted;
+	bool			host_mode;
+	bool			gadget_mode;
+};
+
+#endif /* __INCLUDE_LINUX_USB_MXS_USB_H__ */
-- 
1.7.10

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

* [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (3 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-29  8:26           ` Chen Peter-B29397
  2012-04-24  3:18         ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
                           ` (6 subsequent siblings)
  11 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

On the i.MX platform, we are adding the UDC ourselves from the PHY driver. This
patch adds a flag into the ci13xxx_udc that avoids adding the UDC if set.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/gadget/ci13xxx_udc.c |   12 ++++++++----
 drivers/usb/gadget/ci13xxx_udc.h |    1 +
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index 243ef1a..94f8b19 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -2935,9 +2935,11 @@ static int udc_probe(struct ci13xxx_udc_driver *driver, struct device *dev,
 			goto remove_dbg;
 	}
 
-	retval = usb_add_gadget_udc(dev, &udc->gadget);
-	if (retval)
-		goto remove_trans;
+	if (!(udc->udc_driver->flags & CI13XXX_DONT_REGISTER_GADGET)) {
+		retval = usb_add_gadget_udc(dev, &udc->gadget);
+		if (retval)
+			goto remove_trans;
+	}
 
 	pm_runtime_no_callbacks(&udc->gadget.dev);
 	pm_runtime_enable(&udc->gadget.dev);
@@ -2980,7 +2982,9 @@ static void udc_remove(void)
 		err("EINVAL");
 		return;
 	}
-	usb_del_gadget_udc(&udc->gadget);
+
+	if (!(udc->udc_driver->flags & CI13XXX_DONT_REGISTER_GADGET))
+		usb_del_gadget_udc(&udc->gadget);
 
 	if (udc->transceiver) {
 		otg_set_peripheral(udc->transceiver->otg, &udc->gadget);
diff --git a/drivers/usb/gadget/ci13xxx_udc.h b/drivers/usb/gadget/ci13xxx_udc.h
index 0d31af5..9f2efa2 100644
--- a/drivers/usb/gadget/ci13xxx_udc.h
+++ b/drivers/usb/gadget/ci13xxx_udc.h
@@ -108,6 +108,7 @@ struct ci13xxx_udc_driver {
 #define CI13XXX_REQUIRE_TRANSCEIVER	BIT(1)
 #define CI13XXX_PULLUP_ON_VBUS		BIT(2)
 #define CI13XXX_DISABLE_STREAMING	BIT(3)
+#define CI13XXX_DONT_REGISTER_GADGET	BIT(4)
 
 #define CI13XXX_CONTROLLER_RESET_EVENT		0
 #define CI13XXX_CONTROLLER_STOPPED_EVENT	1
-- 
1.7.10

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

* [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (4 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
                           ` (5 subsequent siblings)
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

This patch adds small registration glue for the ci13xxx_udc that is compatible
with the imx-otg driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/gadget/Kconfig       |   17 ++++++++++
 drivers/usb/gadget/Makefile      |    1 +
 drivers/usb/gadget/ci13xxx_mxs.c |   67 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 2633f75..1fa6b0d 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -494,6 +494,23 @@ config USB_CI13XXX_MSM
 	  dynamically linked module called "ci13xxx_msm" and force all
 	  gadget drivers to also be dynamically linked.
 
+config USB_CI13XXX_MXS
+	tristate "MIPS USB CI13xxx for i.MX23/28"
+	depends on ARCH_MXS
+	select USB_GADGET_DUALSPEED
+	select USB_IMX_COMPOSITE
+	help
+	  i.MX SoC has chipidea USB controller.  This driver uses
+	  ci13xxx_udc core.
+	  This driver depends on OTG driver for PHY initialization,
+	  clock management, powering up VBUS, and power management.
+	  This driver is not supported on boards like trout which
+	  has an external PHY.
+
+	  Say "y" to link the driver statically, or "m" to build a
+	  dynamically linked module called "ci13xxx_mxs" and force all
+	  gadget drivers to also be dynamically linked.
+
 #
 # LAST -- dummy/emulated controller
 #
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index b7f6eef..1f159a9 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_USB_EG20T)		+= pch_udc.o
 obj-$(CONFIG_USB_MV_UDC)	+= mv_udc.o
 mv_udc-y			:= mv_udc_core.o
 obj-$(CONFIG_USB_CI13XXX_MSM)	+= ci13xxx_msm.o
+obj-$(CONFIG_USB_CI13XXX_MXS)	+= ci13xxx_mxs.o
 obj-$(CONFIG_USB_FUSB300)	+= fusb300_udc.o
 
 #
diff --git a/drivers/usb/gadget/ci13xxx_mxs.c b/drivers/usb/gadget/ci13xxx_mxs.c
new file mode 100644
index 0000000..2d99336
--- /dev/null
+++ b/drivers/usb/gadget/ci13xxx_mxs.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/usb/ulpi.h>
+#include <linux/usb/mxs-usb.h>
+
+#include "ci13xxx_udc.c"
+
+#define MSM_USB_BASE	(udc->regs)
+
+static irqreturn_t mxs_udc_irq(int irq, void *data)
+{
+	return udc_irq();
+}
+
+static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
+	.name			= "ci13xxx-mxs",
+	.flags			= CI13XXX_REQUIRE_TRANSCEIVER |
+				  CI13XXX_DISABLE_STREAMING |
+				  CI13XXX_DONT_REGISTER_GADGET,
+};
+
+static int ci13xxx_mxs_probe(struct platform_device *pdev)
+{
+	struct imx_otg *data = pdev->dev.platform_data;
+	int ret;
+
+	ret = devm_request_irq(&pdev->dev, data->irq, mxs_udc_irq,
+				IRQF_SHARED, pdev->name, pdev);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to request IRQ!\n");
+		return ret;
+	}
+
+	ret = udc_probe(&ci13xxx_mxs_udc_driver, &pdev->dev, data->mem);
+	if (ret < 0)
+		dev_err(&pdev->dev, "Failed to probe CI13xxx-mxs!\n");
+
+	pm_runtime_no_callbacks(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
+	return ret;
+}
+
+static struct platform_driver ci13xxx_mxs_driver = {
+	.probe		= ci13xxx_mxs_probe,
+	.driver		= {
+		.name	= "ci13xxx-mxs",
+	},
+};
+
+static int __init ci13xxx_mxs_init(void)
+{
+	return platform_driver_register(&ci13xxx_mxs_driver);
+}
+
+module_init(ci13xxx_mxs_init);
+
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:ci13xxx-mxs");
-- 
1.7.10

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

* [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (5 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-29  8:28           ` Chen Peter-B29397
  2012-04-24  3:18         ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
                           ` (4 subsequent siblings)
  11 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to keep
this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
though eventually these two might be merged.

NOTE: I still haven't figured out how to enable/disable the disconnection
detector, it can't be enabled all the time, so I toggle PHY stuff from this
driver, which I doubt is correct.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/host/Kconfig    |    7 ++
 drivers/usb/host/ehci-hcd.c |    5 ++
 drivers/usb/host/ehci-mxs.c |  178 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 190 insertions(+)
 create mode 100644 drivers/usb/host/ehci-mxs.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f788eb8..85ed593 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -148,6 +148,13 @@ config USB_EHCI_MXC
 	---help---
 	  Variation of ARC USB block used in some Freescale chips.
 
+config USB_EHCI_MXS
+	bool "Support for Freescale i.MX28 on-chip EHCI USB controller"
+	depends on USB_EHCI_HCD && ARCH_MXS
+	select USB_EHCI_ROOT_HUB_TT
+	---help---
+	  Enable USB support for i.MX28.
+
 config USB_EHCI_HCD_OMAP
 	bool "EHCI support for OMAP3 and later chips"
 	depends on USB_EHCI_HCD && ARCH_OMAP
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 4a3bc5b..16e161c 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1268,6 +1268,11 @@ MODULE_LICENSE ("GPL");
 #define PLATFORM_DRIVER		ehci_mxc_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_MXS
+#include "ehci-mxs.c"
+#define PLATFORM_DRIVER		ehci_mxs_driver
+#endif
+
 #ifdef CONFIG_USB_EHCI_SH
 #include "ehci-sh.c"
 #define PLATFORM_DRIVER		ehci_hcd_sh_driver
diff --git a/drivers/usb/host/ehci-mxs.c b/drivers/usb/host/ehci-mxs.c
new file mode 100644
index 0000000..4a696b4
--- /dev/null
+++ b/drivers/usb/host/ehci-mxs.c
@@ -0,0 +1,178 @@
+/*
+ * Freescale i.MX28 EHCI driver
+ *
+ * Copyright (c) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * Based on MXC EHCI driver:
+ *
+ * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
+ * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, 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,
+ * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/slab.h>
+#include <linux/usb/mxs-usb.h>
+
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+#include <asm/mach-types.h>
+
+/* Called during probe() after chip reset completes */
+static int ehci_mxs_setup(struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+
+	hcd->has_tt = 1;
+	ehci_setup(hcd);
+	ehci_port_power(ehci, 0);
+
+	return 0;
+}
+
+static const struct hc_driver ehci_mxs_hc_driver = {
+	.description	= hcd_name,
+	.product_desc	= "Freescale i.MX On-Chip EHCI Host Controller",
+	.hcd_priv_size	= sizeof(struct ehci_hcd),
+
+	/*
+	 * Generic hardware linkage
+	 */
+	.irq		= ehci_irq,
+	.flags		= HCD_USB2 | HCD_MEMORY,
+
+	/*
+	 * Basic lifecycle operations
+	 */
+	.reset		= ehci_mxs_setup,
+	.start		= ehci_run,
+	.stop		= ehci_stop,
+	.shutdown	= ehci_shutdown,
+
+	/*
+	 * managing i/o requests and associated device resources
+	 */
+	.urb_enqueue		= ehci_urb_enqueue,
+	.urb_dequeue		= ehci_urb_dequeue,
+	.endpoint_disable	= ehci_endpoint_disable,
+	.endpoint_reset		= ehci_endpoint_reset,
+
+	/*
+	 * scheduling support
+	 */
+	.get_frame_number	= ehci_get_frame,
+
+	/*
+	 * root hub support
+	 */
+	.hub_status_data	= ehci_hub_status_data,
+	.hub_control		= ehci_hub_control,
+	.bus_suspend		= ehci_bus_suspend,
+	.bus_resume		= ehci_bus_resume,
+	.relinquish_port	= ehci_relinquish_port,
+	.port_handed_over	= ehci_port_handed_over,
+
+	.clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
+};
+
+static int ehci_mxs_drv_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct imx_otg *data = pdev->dev.platform_data;
+	struct usb_hcd *hcd;
+	struct ehci_hcd *ehci;
+	struct usb_phy *phy;
+	int ret;
+
+	dev_info(dev, "Initializing i.MX USB Controller\n");
+
+	if (!data) {
+		dev_err(dev, "USB Host platform data missing!\n");
+		return -ENODEV;
+	}
+
+	/* This should never fail. */
+	phy = usb_get_transceiver();
+	if (!phy) {
+		dev_err(&pdev->dev, "Unable to find transceiver.\n");
+		return -ENODEV;
+	}
+
+	/* Create HCD controller instance. */
+	hcd = usb_create_hcd(&ehci_mxs_hc_driver, dev, dev_name(dev));
+	if (!hcd) {
+		dev_err(dev, "Failed to create HCD instance!\n");
+		return -ENOMEM;
+	}
+
+	hcd->rsrc_start = data->mem_res->start;
+	hcd->rsrc_len = resource_size(data->mem_res);
+	hcd->regs = data->mem;
+	hcd->irq = data->irq;
+
+	/* Wait for the controller to stabilize. */
+	mdelay(10);
+
+	ehci = hcd_to_ehci(hcd);
+
+	/* EHCI registers start at offset 0x100 */
+	ehci->caps = hcd->regs + 0x100;
+	ehci->regs = hcd->regs + 0x100 +
+		HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
+
+	platform_set_drvdata(pdev, hcd);
+
+	/* Connect this host to the PHY. */
+	ret = otg_set_host(phy->otg, &hcd->self);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Unable to set transceiver host\n");
+		usb_put_hcd(hcd);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+static int __exit ehci_mxs_drv_remove(struct platform_device *pdev)
+{
+	struct usb_hcd *hcd = platform_get_drvdata(pdev);
+	struct usb_phy *phy = usb_get_transceiver();
+
+	if (phy)
+		usb_phy_shutdown(phy);
+
+	usb_remove_hcd(hcd);
+	usb_put_hcd(hcd);
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static struct platform_driver ehci_mxs_driver = {
+	.probe		= ehci_mxs_drv_probe,
+	.remove		= __exit_p(ehci_mxs_drv_remove),
+	.driver		= {
+		   .name	= "mxs-ehci",
+	},
+};
+
+MODULE_ALIAS("platform:mxs-ehci");
-- 
1.7.10

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (6 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24 14:48           ` Lothar Waßmann
  2012-04-24  3:18         ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
                           ` (3 subsequent siblings)
  11 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

This driver handles claiming of clocks and memory areas. These are later
properly delegated to it's child devices, the USB Host (ehci-mxs) and
USB Gadget (ci13xxx-mxs).

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |    6 +
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/imx-otg.c |  473 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 480 insertions(+)
 create mode 100644 drivers/usb/otg/imx-otg.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 5c87db0..e7c6325 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -116,6 +116,12 @@ config FSL_USB2_OTG
 	help
 	  Enable this to support Freescale USB OTG transceiver.
 
+config USB_IMX_COMPOSITE
+	bool
+	help
+	  Composite driver that handles clock and memory mapping for
+	  i.MX USB host and USB PHY.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 41aa509..7d2c631 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
 obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
+obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
new file mode 100644
index 0000000..8440d909
--- /dev/null
+++ b/drivers/usb/otg/imx-otg.c
@@ -0,0 +1,473 @@
+/*
+ * drivers/usb/otg/imx-otg.c
+ *
+ * Freescale i.MX USB composite driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/usb/mxs-usb.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+
+#include <linux/usb.h>
+#include <linux/usb/ch9.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/hcd.h>
+#include <linux/usb/ehci_def.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+
+/*
+ * Allocate platform device with the DMA mask, this is borrowed from
+ * arch/arm/mach-mxs/devices.c
+ */
+static struct platform_device *__devinit add_platform_device(
+		const char *name, int id,
+		const void *data, size_t size_data, u64 dmamask)
+{
+	int ret = -ENOMEM;
+	struct platform_device *pdev;
+
+	pdev = platform_device_alloc(name, id);
+	if (!pdev)
+		goto err;
+
+	if (dmamask) {
+		/*
+		 * This memory isn't freed when the device is put,
+		 * I don't have a nice idea for that though.  Conceptually
+		 * dma_mask in struct device should not be a pointer.
+		 * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
+		 */
+		pdev->dev.dma_mask =
+			kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
+		if (!pdev->dev.dma_mask)
+			/* ret is still -ENOMEM; */
+			goto err;
+
+		*pdev->dev.dma_mask = dmamask;
+		pdev->dev.coherent_dma_mask = dmamask;
+	}
+
+	if (data) {
+		ret = platform_device_add_data(pdev, data, size_data);
+		if (ret)
+			goto err;
+	}
+
+	ret = platform_device_add(pdev);
+	if (ret) {
+err:
+		if (dmamask)
+			kfree(pdev->dev.dma_mask);
+		platform_device_put(pdev);
+		return ERR_PTR(ret);
+	}
+
+	return pdev;
+}
+
+static int imx_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	struct imx_otg_priv *priv = container_of(otg, struct imx_otg_priv, otg);
+	struct usb_phy *x = otg->phy;
+	const uint32_t wakeup =
+		BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP;
+
+	if (host) {
+		BUG_ON(otg->host);
+		otg->host = host;
+
+		/* Enable the Host connection detect IRQ. */
+		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_SET);
+	} else {
+		BUG_ON(!otg->host);
+
+		/* Disable the Host connection detect IRQ. */
+		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_CLR);
+	}
+
+	schedule_work(&priv->work);
+
+	return 0;
+}
+
+static int imx_otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *gg)
+{
+	struct imx_otg_priv *priv = container_of(otg, struct imx_otg_priv, otg);
+	struct usb_phy *x = otg->phy;
+	const uint32_t wakeup =
+		BM_USBPHY_CTRL_ENVBUSCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP;
+
+	if (gg) {
+		BUG_ON(otg->gadget);
+		otg->gadget = gg;
+
+		/* Enable the Host connection detect IRQ. */
+		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_SET);
+	} else {
+		BUG_ON(!otg->gadget);
+
+		/* Disable the Host connection detect IRQ. */
+		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_CLR);
+	}
+
+	schedule_work(&priv->work);
+
+	return 0;
+}
+
+static void imx_otg_work(struct work_struct *w)
+{
+	struct imx_otg_priv *priv = container_of(w, struct imx_otg_priv, work);
+	struct usb_hcd *hcd;
+
+	switch (priv->cur_state) {
+	case OTG_STATE_A_HOST:
+		if (priv->new_state == OTG_STATE_UNDEFINED) {
+			hcd = bus_to_hcd(priv->otg.host);
+			usb_remove_hcd(hcd);
+			priv->cur_state = priv->new_state;
+			/* Turn off VBUS */
+			gpio_set_value(priv->gpio_vbus,
+				priv->gpio_vbus_inverted);
+		}
+		break;
+	case OTG_STATE_B_PERIPHERAL:
+		if (priv->new_state == OTG_STATE_UNDEFINED) {
+			usb_del_gadget_udc(priv->otg.gadget);
+			priv->cur_state = priv->new_state;
+		}
+		break;
+	case OTG_STATE_UNDEFINED:
+		/* Check desired state. */
+		switch (priv->new_state) {
+		case OTG_STATE_A_HOST:
+			if (!priv->otg.host)
+				break;
+			priv->cur_state = priv->new_state;
+
+			/* Turn on VBUS */
+			gpio_set_value(priv->gpio_vbus,
+				!priv->gpio_vbus_inverted);
+
+			hcd = bus_to_hcd(priv->otg.host);
+			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
+			break;
+		case OTG_STATE_B_PERIPHERAL:
+			if (!priv->otg.gadget)
+				break;
+			priv->cur_state = priv->new_state;
+			usb_add_gadget_udc(priv->dev, priv->otg.gadget);
+			break;
+		default:
+			break;
+		}
+		break;
+
+	default:
+		break;
+	}
+}
+
+static irqreturn_t imx_otg_irq(int irq, void *irqdata)
+{
+	struct imx_otg *data = irqdata;
+	struct imx_otg_priv *priv = &data->priv;
+	struct usb_otg *otg = &data->priv.otg;
+	struct usb_phy *x = otg->phy;
+	uint32_t status;
+
+	if (otg->host) {
+		status = readl(data->mem + 0x144);
+		if (~(priv->status ^ status) & STS_PCD)
+			return IRQ_NONE;
+
+		priv->status = status;
+
+		if (priv->status & STS_PCD) {
+			writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+				x->io_priv + HW_USBPHY_CTRL_CLR);
+		} else {
+			writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
+				x->io_priv + HW_USBPHY_CTRL_SET);
+		}
+	}
+
+	return IRQ_NONE;
+}
+
+static int __devinit imx_usb_probe(struct platform_device *pdev)
+{
+	struct imx_usb_platform_data *pdata = pdev->dev.platform_data;
+	struct imx_otg_priv *priv;
+	struct imx_otg *data;
+	struct usb_phy *phy;
+	struct usb_otg *otg;
+	int ret;
+	void *retp = NULL;
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "No platform data supplied!\n");
+		return -ENODEV;
+	}
+
+	phy = usb_get_transceiver();
+	if (!phy)
+		return -EPROBE_DEFER;
+
+	/*
+	 * Until further notice, this claims all necessary resources.
+	 */
+
+	/* Claim the VBUS GPIO */
+	ret = gpio_request_one(pdata->gpio_vbus, GPIOF_DIR_OUT, "USB Power");
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request USB Power GPIO!");
+		ret = -EINVAL;
+		goto err_alloc_data;
+	}
+
+	/* Disable the VBUS. */
+	gpio_set_value(pdata->gpio_vbus, pdata->gpio_vbus_inverted);
+
+	/* Allocate driver's private date. */
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		dev_err(&pdev->dev, "Failed to allocate OTG nodes data!\n");
+		ret = -ENOMEM;
+		goto err_alloc_data;
+	}
+
+	priv = &data->priv;
+
+	/* Configure the OTG structure. */
+	otg				= &priv->otg;
+	otg->phy			= phy;
+	otg->set_host			= imx_otg_set_host;
+	otg->set_peripheral		= imx_otg_set_peripheral;
+	phy->otg			= otg;
+
+	priv->dev			= &pdev->dev;
+	priv->gpio_vbus			= pdata->gpio_vbus;
+	priv->gpio_vbus_inverted	= pdata->gpio_vbus_inverted;
+	priv->cur_state			= OTG_STATE_UNDEFINED;
+	priv->new_state			= OTG_STATE_UNDEFINED;
+
+	if (pdata->host_mode && !pdata->gadget_mode)
+		priv->new_state	= OTG_STATE_A_HOST;
+	else if (pdata->gadget_mode)
+		priv->new_state	= OTG_STATE_B_PERIPHERAL;
+
+	INIT_WORK(&priv->work, imx_otg_work);
+
+	/* Claim the Host clock. */
+	data->clk = clk_get(&pdev->dev, "usb");
+	if (IS_ERR(data->clk)) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB Host\n");
+		ret = PTR_ERR(data->clk);
+		goto err_alloc_data;
+	}
+
+	/* Prepare Host clock. */
+	ret = clk_prepare_enable(data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to enable clock for USB Host.\n");
+		goto err_prepare_host_clock;
+	}
+
+	/* Get memory area for EHCI host from resources. */
+	data->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!data->mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_resource;
+	}
+
+	/* Request the memory region for this USB Host. */
+	retp = devm_request_mem_region(&pdev->dev, data->mem_res->start,
+			resource_size(data->mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB Host memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_get_host_resource;
+	}
+
+	/* Map the memory region for USB Host. */
+	data->mem = devm_ioremap(&pdev->dev, data->mem_res->start,
+				resource_size(data->mem_res));
+	if (!data->mem) {
+		dev_err(&pdev->dev, "Memory mapping of USB Host failed!\n");
+		ret = -EFAULT;
+		goto err_get_host_resource;
+	}
+
+	/* Get IRQ for EHCI host from resources. */
+	data->irq = platform_get_irq(pdev, 0);
+	if (data->irq < 0) {
+		dev_err(&pdev->dev, "Specify IRQ for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_resource;
+	}
+
+	/* Get IRQ for PHY wakeup from resources. */
+	data->irq_wakeup = platform_get_irq(pdev, 1);
+	if (data->irq_wakeup < 0) {
+		dev_err(&pdev->dev, "Specify wakeup IRQ for this USB Host!\n");
+		ret = -ENODEV;
+		goto err_get_host_resource;
+	}
+
+	/* Request the EHCI IRQ. */
+	ret = devm_request_irq(&pdev->dev, data->irq, imx_otg_irq,
+				IRQF_SHARED, "imx-otg-usb-irq", data);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to request IRQ!\n");
+		goto err_get_host_resource;
+	}
+
+	/* Request the PHY IRQ. */
+	ret = devm_request_irq(&pdev->dev, data->irq_wakeup, imx_otg_irq,
+				IRQF_SHARED, "imx-otg-wakeup-irq", data);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to request IRQ!\n");
+		goto err_get_host_resource;
+	}
+
+	/*
+	 * Now finally probe the Host driver!
+	 */
+	if (pdata->gadget_mode) {
+		data->pdev_gadget = add_platform_device("ci13xxx-mxs", -1,
+							data, sizeof(*data),
+							DMA_BIT_MASK(32));
+		if (!data->pdev_gadget) {
+			dev_err(&pdev->dev, "Failed registering Host!\n");
+			ret = -ENODEV;
+			goto err_register_gadget;
+		}
+	}
+
+	if (pdata->host_mode) {
+		data->pdev_host = add_platform_device("mxs-ehci", -1,
+							data, sizeof(*data),
+							DMA_BIT_MASK(32));
+		if (!data->pdev_host) {
+			dev_err(&pdev->dev, "Failed registering Host!\n");
+			ret = -ENODEV;
+			goto err_get_host_resource;
+		}
+	}
+
+	/*
+	 * Initialize the transceiver
+	 */
+	phy = usb_get_transceiver();
+	if (!phy) {
+		dev_err(&pdev->dev, "Unable to find transceiver.\n");
+		ret = -ENODEV;
+		goto err_phy;
+	}
+
+	ret = usb_phy_init(phy);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Unable init transceiver\n");
+		ret = -ENODEV;
+		goto err_phy_init;
+	}
+
+	return 0;
+
+err_phy_init:
+	if (phy)
+		usb_put_transceiver(phy);
+err_phy:
+	if (data->pdev_gadget)
+		platform_device_unregister(data->pdev_gadget);
+err_register_gadget:
+	if (data->pdev_host)
+		platform_device_unregister(data->pdev_host);
+err_get_host_resource:
+	clk_disable_unprepare(data->clk);
+err_prepare_host_clock:
+	clk_put(data->clk);
+err_alloc_data:
+	return ret;
+}
+
+static int __devexit imx_usb_remove(struct platform_device *pdev)
+{
+	struct imx_otg *data = platform_get_drvdata(pdev);
+	struct imx_otg_priv *priv = &data->priv;
+
+	/* Stop the PHY work. */
+	cancel_work_sync(&priv->work);
+
+	/* Shut off VBUS. */
+	gpio_set_value(priv->gpio_vbus, priv->gpio_vbus_inverted);
+	gpio_free(priv->gpio_vbus);
+
+	/* Deregister both Gadget and Host driver. */
+	if (data->pdev_gadget)
+		platform_device_unregister(data->pdev_gadget);
+
+	if (data->pdev_host)
+		platform_device_unregister(data->pdev_host);
+
+	/* Stop the clock. */
+	clk_disable_unprepare(data->clk);
+	clk_put(data->clk);
+
+	return 0;
+}
+
+static struct platform_driver imx_usb_driver = {
+	.probe		= imx_usb_probe,
+	.remove		= __devexit_p(imx_usb_remove),
+	.driver		= {
+		.name	= "imx-otg",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init imx_usb_init(void)
+{
+	return platform_driver_register(&imx_usb_driver);
+}
+
+static void __exit imx_usb_exit(void)
+{
+	platform_driver_unregister(&imx_usb_driver);
+}
+
+module_init(imx_usb_init);
+module_exit(imx_usb_exit);
+
+MODULE_ALIAS("platform:imx-otg");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX USB composite driver");
+MODULE_LICENSE("GPL");
-- 
1.7.10

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

* [PATCH 09/11] MXS: Add USB PHY driver
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (7 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
                           ` (2 subsequent siblings)
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

Add driver that controls the built-in USB PHY in the i.MX233/i.MX28. This
enables the PHY upon powerup and shuts it down on shutdown.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |   10 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  237 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index e7c6325..1de1495 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -122,6 +122,16 @@ config USB_IMX_COMPOSITE
 	  Composite driver that handles clock and memory mapping for
 	  i.MX USB host and USB PHY.
 
+config USB_MXS_PHY
+	tristate "Freescale i.MX28 USB PHY support"
+	select USB_OTG_UTILS
+	select USB_IMX_COMPOSITE
+	help
+	  Say Y here if you want to build Freescale i.MX28 USB PHY
+	  driver in kernel.
+
+	  To compile this driver as a module, choose M here.
+
 config USB_MV_OTG
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 7d2c631..b8d7d5c 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -21,4 +21,5 @@ obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
 fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
 obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
 obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
+obj-$(CONFIG_USB_MXS_PHY)	+= mxs-phy.o
 obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/otg/mxs-phy.c
new file mode 100644
index 0000000..510c719
--- /dev/null
+++ b/drivers/usb/otg/mxs-phy.c
@@ -0,0 +1,237 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex@denx.de>
+ * on behalf of DENX Software Engineering GmbH
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/usb/mxs-usb.h>
+
+#include <linux/usb.h>
+#include <linux/usb/ch9.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/hcd.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/devices-common.h>
+#include <mach/mx28.h>
+
+struct mxs_usb_phy {
+	struct usb_phy		phy;
+	struct clk		*clk;
+};
+
+static int mxs_usb_phy_init(struct usb_phy *x)
+{
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+	uint32_t val;
+
+	/* Enable clock to the PHY. */
+	clk_enable(phy->clk);
+
+	/* Reset the PHY block. */
+	mxs_reset_block(x->io_priv + HW_USBPHY_CTRL);
+
+	/* Power up the PHY. */
+	writel(0, x->io_priv + HW_USBPHY_PWD);
+
+	/* Clear the wakeup IRQ before enabling them below. */
+	writel(BM_USBPHY_CTRL_RESUME_IRQ | BM_USBPHY_CTRL_WAKEUP_IRQ,
+		x->io_priv + HW_USBPHY_CTRL_CLR);
+
+	/* Enable FS/LS compatibility and wakeup IRQs. */
+	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
+		BM_USBPHY_CTRL_ENIRQWAKEUP;
+
+	writel(val, x->io_priv + HW_USBPHY_CTRL_SET);
+
+	return 0;
+}
+
+static void mxs_usb_phy_shutdown(struct usb_phy *x)
+{
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+	uint32_t val;
+
+	/* Clear the wakeup IRQ before disabling them below. */
+	writel(BM_USBPHY_CTRL_RESUME_IRQ | BM_USBPHY_CTRL_WAKEUP_IRQ,
+		x->io_priv + HW_USBPHY_CTRL_CLR);
+
+	/* Disable FS/LS compatibility and wakeup IRQs. */
+	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
+		BM_USBPHY_CTRL_ENIRQWAKEUP;
+	writel(val, x->io_priv + HW_USBPHY_CTRL_CLR);
+
+	/*
+	 * The interrupt must be disabled for at least 3 cycles of the
+	 * standby clock (32kHz), that is 0.094 ms.
+	 */
+	udelay(100);
+
+	/* Gate off the PHY. */
+	writel(BM_USBPHY_CTRL_CLKGATE, x->io_priv + HW_USBPHY_CTRL_SET);
+
+	/* Disable clock to the PHY. */
+	clk_disable(phy->clk);
+}
+
+static int __devinit mxs_phy_probe(struct platform_device *pdev)
+{
+	struct imx_usb_platform_data *pdata = pdev->dev.platform_data;
+	struct mxs_usb_phy *phy;
+	struct resource *mem_res;
+	void *retp;
+	int ret;
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "No platform data supplied!\n");
+		ret = -ENODEV;
+		goto err_pdata;
+	}
+
+	/* Allocate PHY driver's private data. */
+	phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		dev_err(&pdev->dev, "Failed to allocate USB PHY structure!\n");
+		ret = -ENOMEM;
+		goto err_pdata;
+	}
+
+	/* Get memory area for PHY from resources. */
+	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!mem_res) {
+		dev_err(&pdev->dev, "Specify memory area for this USB PHY!\n");
+		ret = -ENODEV;
+		goto err_pdata;
+	}
+
+	/* Request the memory region for this USB PHY. */
+	retp = devm_request_mem_region(&pdev->dev, mem_res->start,
+			resource_size(mem_res), pdev->name);
+	if (!retp) {
+		dev_err(&pdev->dev, "USB PHY memory area already in use!\n");
+		ret = -EBUSY;
+		goto err_pdata;
+	}
+
+	/* Map the memory region for USB PHY. */
+	phy->phy.io_priv = devm_ioremap(&pdev->dev, mem_res->start,
+				resource_size(mem_res));
+	if (!phy->phy.io_priv) {
+		dev_err(&pdev->dev, "Memory mapping of USB PHY failed!\n");
+		ret = -EFAULT;
+		goto err_pdata;
+	}
+
+	/* Claim the PHY clock. */
+	phy->clk = clk_get(&pdev->dev, "phy");
+	if (!phy->clk) {
+		dev_err(&pdev->dev, "Failed to claim clock for USB PHY!\n");
+		ret = PTR_ERR(phy->clk);
+		goto err_pdata;
+	}
+
+	/* Prepare PHY clock. */
+	ret = clk_prepare(phy->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to prepare clock for USB PHY!\n");
+		goto err_prepare_phy_clock;
+	}
+
+	/* Setup the PHY structures. */
+	phy->phy.dev		= &pdev->dev;
+	phy->phy.label		= "mxs-usb-phy";
+	phy->phy.init		= mxs_usb_phy_init;
+	phy->phy.shutdown	= mxs_usb_phy_shutdown;
+	phy->phy.state		= OTG_STATE_UNDEFINED;
+
+	platform_set_drvdata(pdev, phy);
+
+	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
+
+	/* Register the transceiver with kernel. */
+	ret = usb_set_transceiver(&phy->phy);
+	if (ret) {
+		dev_err(&pdev->dev, "Can't register transceiver, (%d)\n", ret);
+		goto err_set_transceiver;
+	}
+
+	return 0;
+
+err_set_transceiver:
+	clk_unprepare(phy->clk);
+err_prepare_phy_clock:
+	clk_put(phy->clk);
+err_pdata:
+	return ret;
+}
+
+static int __devexit mxs_phy_remove(struct platform_device *pdev)
+{
+	struct mxs_usb_phy *phy = platform_get_drvdata(pdev);
+
+	/* Power down the PHY. */
+	mxs_usb_phy_shutdown(&phy->phy);
+
+	/* Remove the transceiver. */
+	usb_set_transceiver(NULL);
+
+	/* Stop the PHY clock. */
+	clk_disable_unprepare(phy->clk);
+	clk_put(phy->clk);
+
+	/* Free the rest. */
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static struct platform_driver mxs_phy_driver = {
+	.probe		= mxs_phy_probe,
+	.remove		= __devexit_p(mxs_phy_remove),
+	.driver		= {
+		.name	= "mxs-usb-phy",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mxs_phy_init(void)
+{
+	return platform_driver_register(&mxs_phy_driver);
+}
+
+static void __exit mxs_phy_exit(void)
+{
+	platform_driver_unregister(&mxs_phy_driver);
+}
+
+arch_initcall(mxs_phy_init);
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
-- 
1.7.10

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

* [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (8 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24  3:18         ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
  2012-04-24 20:02         ` [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver Russell King - ARM Linux
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

Based on code by:
Tony Lin <tony.lin@freescale.com>

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/devices-mx28.h                |    5 ++
 arch/arm/mach-mxs/devices/Kconfig               |    3 +
 arch/arm/mach-mxs/devices/Makefile              |    1 +
 arch/arm/mach-mxs/devices/platform-usb.c        |   85 +++++++++++++++++++++++
 arch/arm/mach-mxs/include/mach/devices-common.h |   13 ++++
 5 files changed, 107 insertions(+)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c

diff --git a/arch/arm/mach-mxs/devices-mx28.h b/arch/arm/mach-mxs/devices-mx28.h
index 9dbeae1..04a9120 100644
--- a/arch/arm/mach-mxs/devices-mx28.h
+++ b/arch/arm/mach-mxs/devices-mx28.h
@@ -11,6 +11,7 @@
 #include <mach/mx28.h>
 #include <mach/devices-common.h>
 #include <mach/mxsfb.h>
+#include <linux/usb/mxs-usb.h>
 
 extern const struct amba_device mx28_duart_device __initconst;
 #define mx28_add_duart() \
@@ -47,6 +48,10 @@ extern const struct mxs_mxs_mmc_data mx28_mxs_mmc_data[] __initconst;
 
 #define mx28_add_mxs_pwm(id)		mxs_add_mxs_pwm(MX28_PWM_BASE_ADDR, id)
 
+extern const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst;
+#define mx28_add_mxs_usbh(id, pdata) \
+	mxs_add_mxs_usbh(&mx28_mxs_usbh_data[id], pdata)
+
 struct platform_device *__init mx28_add_mxsfb(
 		const struct mxsfb_platform_data *pdata);
 
diff --git a/arch/arm/mach-mxs/devices/Kconfig b/arch/arm/mach-mxs/devices/Kconfig
index b8913df..f6709bc 100644
--- a/arch/arm/mach-mxs/devices/Kconfig
+++ b/arch/arm/mach-mxs/devices/Kconfig
@@ -32,3 +32,6 @@ config MXS_HAVE_PLATFORM_MXS_SAIF
 
 config MXS_HAVE_PLATFORM_RTC_STMP3XXX
 	bool
+
+config MXS_HAVE_PLATFORM_USB
+	bool
diff --git a/arch/arm/mach-mxs/devices/Makefile b/arch/arm/mach-mxs/devices/Makefile
index c8f5c95..be4cc9e 100644
--- a/arch/arm/mach-mxs/devices/Makefile
+++ b/arch/arm/mach-mxs/devices/Makefile
@@ -11,3 +11,4 @@ obj-y += platform-gpio-mxs.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXSFB) += platform-mxsfb.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_MXS_SAIF) += platform-mxs-saif.o
 obj-$(CONFIG_MXS_HAVE_PLATFORM_RTC_STMP3XXX) += platform-rtc-stmp3xxx.o
+obj-$(CONFIG_MXS_HAVE_PLATFORM_USB) += platform-usb.o
diff --git a/arch/arm/mach-mxs/devices/platform-usb.c b/arch/arm/mach-mxs/devices/platform-usb.c
new file mode 100644
index 0000000..d3505a0
--- /dev/null
+++ b/arch/arm/mach-mxs/devices/platform-usb.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+#include <linux/compiler.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/fsl_devices.h>
+#include <linux/usb/mxs-usb.h>
+
+#include <mach/mx23.h>
+#include <mach/mx28.h>
+#include <mach/devices-common.h>
+
+#define mxs_usbh_data_entry_single(soc, _id, hwid)			\
+	{								\
+		.id = _id,						\
+		.usb_irq = soc ## _INT_USB ## hwid,			\
+		.phy_irq = soc ## _INT_USB ## hwid ## _WAKEUP,		\
+		.usb_iobase = soc ## _USBCTRL ## hwid ## _BASE_ADDR,	\
+		.phy_iobase = soc ## _USBPHY ## hwid ## _BASE_ADDR,	\
+	}
+
+#define mxs_usbh_data_entry(soc, _id, hwid)				\
+	[_id] = mxs_usbh_data_entry_single(soc, _id, hwid)
+
+#ifdef CONFIG_SOC_IMX23
+const struct mxs_usbh_data mx23_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX23, 0, 0),
+};
+#endif
+
+#ifdef CONFIG_SOC_IMX28
+const struct mxs_usbh_data mx28_mxs_usbh_data[] __initconst = {
+	mxs_usbh_data_entry(MX28, 0, 0),
+	mxs_usbh_data_entry(MX28, 1, 1),
+};
+#endif
+
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data,
+			const struct imx_usb_platform_data *pdata)
+{
+	struct platform_device *pdev;
+	struct resource phy_res[] = {
+		{
+			.start	= data->phy_iobase,
+			.end	= data->phy_iobase + SZ_256 - 1,
+			.flags	= IORESOURCE_MEM,
+		},
+	};
+
+	struct resource usb_res[] = {
+		{
+			.start	= data->usb_iobase,
+			.end	= data->usb_iobase + SZ_64K - 1,
+			.flags	= IORESOURCE_MEM,
+		}, {
+			.start	= data->usb_irq,
+			.end	= data->usb_irq,
+			.flags	= IORESOURCE_IRQ,
+		}, {
+			.start	= data->phy_irq,
+			.end	= data->phy_irq,
+			.flags	= IORESOURCE_IRQ,
+		},
+	};
+
+	pdev = mxs_add_platform_device_dmamask("mxs-usb-phy", data->id,
+					phy_res, ARRAY_SIZE(phy_res),
+					pdata, sizeof(*pdata),
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register USB PHY driver!\n");
+
+	pdev = mxs_add_platform_device_dmamask("imx-otg", data->id,
+					usb_res, ARRAY_SIZE(usb_res),
+					pdata, sizeof(*pdata),
+					DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register USB Host driver!\n");
+}
diff --git a/arch/arm/mach-mxs/include/mach/devices-common.h b/arch/arm/mach-mxs/include/mach/devices-common.h
index f2e3839..b4a65ab 100644
--- a/arch/arm/mach-mxs/include/mach/devices-common.h
+++ b/arch/arm/mach-mxs/include/mach/devices-common.h
@@ -10,6 +10,8 @@
 #include <linux/platform_device.h>
 #include <linux/init.h>
 #include <linux/amba/bus.h>
+#include <linux/fsl_devices.h>
+#include <linux/usb/mxs-usb.h>
 
 extern struct device mxs_apbh_bus;
 
@@ -42,6 +44,17 @@ struct mxs_auart_data {
 struct platform_device *__init mxs_add_auart(
 		const struct mxs_auart_data *data);
 
+/* usb host */
+struct mxs_usbh_data {
+	int id;
+	resource_size_t usb_irq;
+	resource_size_t phy_irq;
+	resource_size_t usb_iobase;
+	resource_size_t phy_iobase;
+};
+void __init mxs_add_mxs_usbh(const struct mxs_usbh_data *data,
+			const struct imx_usb_platform_data *pdata);
+
 /* fec */
 #include <linux/fec.h>
 struct mxs_fec_data {
-- 
1.7.10

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

* [PATCH 11/11] MXS: Enable USB on M28EVK
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (9 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
@ 2012-04-24  3:18         ` Marek Vasut
  2012-04-24 20:02         ` [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver Russell King - ARM Linux
  11 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-24  3:18 UTC (permalink / raw)
  To: linux-arm-kernel

Enable the second USB port on M28EVK board.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Chen Peter-B29397 <B29397@freescale.com>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Li Frank-B20596 <B20596@freescale.com>
Cc: Lin Tony-B19295 <B19295@freescale.com>
Cc: Linux USB <linux-usb@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@freescale.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Tony Lin <tony.lin@freescale.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig       |    2 ++
 arch/arm/mach-mxs/mach-m28evk.c |   21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig
index c57f996..05f6e84 100644
--- a/arch/arm/mach-mxs/Kconfig
+++ b/arch/arm/mach-mxs/Kconfig
@@ -81,6 +81,8 @@ config MODULE_M28
 	select MXS_HAVE_PLATFORM_MXS_I2C
 	select MXS_HAVE_PLATFORM_MXS_MMC
 	select MXS_HAVE_PLATFORM_MXSFB
+	select MXS_HAVE_PLATFORM_USB
+	select USB_ARCH_HAS_EHCI
 	select MXS_OCOTP
 
 config MODULE_APX4
diff --git a/arch/arm/mach-mxs/mach-m28evk.c b/arch/arm/mach-mxs/mach-m28evk.c
index 06d7996..fe00921 100644
--- a/arch/arm/mach-mxs/mach-m28evk.c
+++ b/arch/arm/mach-mxs/mach-m28evk.c
@@ -39,6 +39,8 @@
 
 #define MX28EVK_BL_ENABLE	MXS_GPIO_NR(3, 18)
 #define M28EVK_LCD_ENABLE	MXS_GPIO_NR(3, 28)
+#define M28EVK_USB_ENABLE	MXS_GPIO_NR(3, 13)
+#define M28EVK_USBOTG_ENABLE	MXS_GPIO_NR(3, 12)
 
 #define MX28EVK_MMC0_WRITE_PROTECT	MXS_GPIO_NR(2, 12)
 #define MX28EVK_MMC1_WRITE_PROTECT	MXS_GPIO_NR(0, 28)
@@ -210,6 +212,16 @@ static const iomux_cfg_t m28evk_pads[] __initconst = {
 
 	/* Backlight */
 	MX28_PAD_PWM3__GPIO_3_28 | MXS_PAD_CTRL,
+
+	/* USB */
+	MX28_PAD_SSP2_SS2__USB0_OVERCURRENT,
+	MX28_PAD_SSP2_SS1__USB1_OVERCURRENT,
+	MX28_PAD_PWM2__USB0_ID |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
+	MX28_PAD_AUART3_TX__GPIO_3_13 |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
+	MX28_PAD_AUART3_RX__GPIO_3_12 |
+		MXS_PAD_12MA | MXS_PAD_3V3 | MXS_PAD_PULLUP,
 };
 
 /* led */
@@ -317,6 +329,13 @@ static struct mxs_mmc_platform_data m28evk_mmc_pdata[] __initdata = {
 	},
 };
 
+static struct imx_usb_platform_data m28_usb_data = {
+	.gpio_vbus		= M28EVK_USBOTG_ENABLE,
+	.gpio_vbus_inverted	= 1,
+	.gadget_mode		= 0,
+	.host_mode		= 1,
+};
+
 static void __init m28evk_init(void)
 {
 	mxs_iomux_setup_multiple_pads(m28evk_pads, ARRAY_SIZE(m28evk_pads));
@@ -344,6 +363,8 @@ static void __init m28evk_init(void)
 	mx28_add_mxs_i2c(0);
 	i2c_register_board_info(0, m28_stk5v3_i2c_boardinfo,
 			ARRAY_SIZE(m28_stk5v3_i2c_boardinfo));
+
+	mx28_add_mxs_usbh(0, &m28_usb_data);
 }
 
 static void __init m28evk_timer_init(void)
-- 
1.7.10

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24  3:18         ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
@ 2012-04-24 14:48           ` Lothar Waßmann
  2012-04-24 14:50             ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Lothar Waßmann @ 2012-04-24 14:48 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

Marek Vasut writes:
> This driver handles claiming of clocks and memory areas. These are later
> properly delegated to it's child devices, the USB Host (ehci-mxs) and
> USB Gadget (ci13xxx-mxs).
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  drivers/usb/otg/Kconfig   |    6 +
>  drivers/usb/otg/Makefile  |    1 +
>  drivers/usb/otg/imx-otg.c |  473 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 480 insertions(+)
>  create mode 100644 drivers/usb/otg/imx-otg.c
> 
> diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> index 5c87db0..e7c6325 100644
> --- a/drivers/usb/otg/Kconfig
> +++ b/drivers/usb/otg/Kconfig
> @@ -116,6 +116,12 @@ config FSL_USB2_OTG
>  	help
>  	  Enable this to support Freescale USB OTG transceiver.
>  
> +config USB_IMX_COMPOSITE
> +	bool
> +	help
> +	  Composite driver that handles clock and memory mapping for
> +	  i.MX USB host and USB PHY.
> +
>  config USB_MV_OTG
>  	tristate "Marvell USB OTG support"
>  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> index 41aa509..7d2c631 100644
> --- a/drivers/usb/otg/Makefile
> +++ b/drivers/usb/otg/Makefile
> @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
>  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
>  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
>  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> +obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
>  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
> new file mode 100644
> index 0000000..8440d909
> --- /dev/null
> +++ b/drivers/usb/otg/imx-otg.c
> @@ -0,0 +1,473 @@
> +/*
> + * drivers/usb/otg/imx-otg.c
> + *
> + * Freescale i.MX USB composite driver.
> + *
> + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> + * on behalf of DENX Software Engineering GmbH
> + *
> + * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
> + */
> +
Why do you call this driver imx-otg when it is actually MXS specific?
How would you call a corresponding driver for the remaining i.MX
processors?


Lothar Wa?mann
-- 
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24 14:48           ` Lothar Waßmann
@ 2012-04-24 14:50             ` Sascha Hauer
  2012-04-24 16:13               ` Lothar Waßmann
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-24 14:50 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Apr 24, 2012 at 04:48:14PM +0200, Lothar Wa?mann wrote:
> Hi,
> 
> Marek Vasut writes:
> > This driver handles claiming of clocks and memory areas. These are later
> > properly delegated to it's child devices, the USB Host (ehci-mxs) and
> > USB Gadget (ci13xxx-mxs).
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > ---
> >  drivers/usb/otg/Kconfig   |    6 +
> >  drivers/usb/otg/Makefile  |    1 +
> >  drivers/usb/otg/imx-otg.c |  473 +++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 480 insertions(+)
> >  create mode 100644 drivers/usb/otg/imx-otg.c
> > 
> > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > index 5c87db0..e7c6325 100644
> > --- a/drivers/usb/otg/Kconfig
> > +++ b/drivers/usb/otg/Kconfig
> > @@ -116,6 +116,12 @@ config FSL_USB2_OTG
> >  	help
> >  	  Enable this to support Freescale USB OTG transceiver.
> >  
> > +config USB_IMX_COMPOSITE
> > +	bool
> > +	help
> > +	  Composite driver that handles clock and memory mapping for
> > +	  i.MX USB host and USB PHY.
> > +
> >  config USB_MV_OTG
> >  	tristate "Marvell USB OTG support"
> >  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> > diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> > index 41aa509..7d2c631 100644
> > --- a/drivers/usb/otg/Makefile
> > +++ b/drivers/usb/otg/Makefile
> > @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
> >  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
> >  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
> >  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> > +obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
> >  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> > diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
> > new file mode 100644
> > index 0000000..8440d909
> > --- /dev/null
> > +++ b/drivers/usb/otg/imx-otg.c
> > @@ -0,0 +1,473 @@
> > +/*
> > + * drivers/usb/otg/imx-otg.c
> > + *
> > + * Freescale i.MX USB composite driver.
> > + *
> > + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> > + * on behalf of DENX Software Engineering GmbH
> > + *
> > + * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
> > + */
> > +
> Why do you call this driver imx-otg when it is actually MXS specific?
> How would you call a corresponding driver for the remaining i.MX
> processors?

This is the driver for the all i.MX processors.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24 14:50             ` Sascha Hauer
@ 2012-04-24 16:13               ` Lothar Waßmann
  2012-04-24 16:47                 ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Lothar Waßmann @ 2012-04-24 16:13 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

Sascha Hauer writes:
> On Tue, Apr 24, 2012 at 04:48:14PM +0200, Lothar Wa?mann wrote:
> > Hi,
> > 
> > Marek Vasut writes:
> > > This driver handles claiming of clocks and memory areas. These are later
> > > properly delegated to it's child devices, the USB Host (ehci-mxs) and
> > > USB Gadget (ci13xxx-mxs).
> > > 
> > > Signed-off-by: Marek Vasut <marex@denx.de>
> > > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > > Cc: Detlev Zundel <dzu@denx.de>
> > > Cc: Fabio Estevam <festevam@gmail.com>
> > > Cc: Li Frank-B20596 <B20596@freescale.com>
> > > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > > Cc: Linux USB <linux-usb@vger.kernel.org>
> > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > Cc: Shawn Guo <shawn.guo@freescale.com>
> > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > Cc: Stefano Babic <sbabic@denx.de>
> > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > Cc: Tony Lin <tony.lin@freescale.com>
> > > Cc: Wolfgang Denk <wd@denx.de>
> > > ---
> > >  drivers/usb/otg/Kconfig   |    6 +
> > >  drivers/usb/otg/Makefile  |    1 +
> > >  drivers/usb/otg/imx-otg.c |  473 +++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 480 insertions(+)
> > >  create mode 100644 drivers/usb/otg/imx-otg.c
> > > 
> > > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > > index 5c87db0..e7c6325 100644
> > > --- a/drivers/usb/otg/Kconfig
> > > +++ b/drivers/usb/otg/Kconfig
> > > @@ -116,6 +116,12 @@ config FSL_USB2_OTG
> > >  	help
> > >  	  Enable this to support Freescale USB OTG transceiver.
> > >  
> > > +config USB_IMX_COMPOSITE
> > > +	bool
> > > +	help
> > > +	  Composite driver that handles clock and memory mapping for
> > > +	  i.MX USB host and USB PHY.
> > > +
> > >  config USB_MV_OTG
> > >  	tristate "Marvell USB OTG support"
> > >  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> > > diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> > > index 41aa509..7d2c631 100644
> > > --- a/drivers/usb/otg/Makefile
> > > +++ b/drivers/usb/otg/Makefile
> > > @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
> > >  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
> > >  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
> > >  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> > > +obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
> > >  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> > > diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
> > > new file mode 100644
> > > index 0000000..8440d909
> > > --- /dev/null
> > > +++ b/drivers/usb/otg/imx-otg.c
> > > @@ -0,0 +1,473 @@
> > > +/*
> > > + * drivers/usb/otg/imx-otg.c
> > > + *
> > > + * Freescale i.MX USB composite driver.
> > > + *
> > > + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> > > + * on behalf of DENX Software Engineering GmbH
> > > + *
> > > + * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
> > > + */
> > > +
> > Why do you call this driver imx-otg when it is actually MXS specific?
> > How would you call a corresponding driver for the remaining i.MX
> > processors?
> 
> This is the driver for the all i.MX processors.
> 
If it is for all i.MX processors, it shouldn't access MXS specific
registers, like:
+		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_SET);


Lothar Wa?mann
-- 
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstra?e 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Gesch?ftsf?hrer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | info at karo-electronics.de
___________________________________________________________

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24 16:13               ` Lothar Waßmann
@ 2012-04-24 16:47                 ` Sascha Hauer
  2012-04-24 17:49                   ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-24 16:47 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Apr 24, 2012 at 06:13:04PM +0200, Lothar Wa?mann wrote:
> Hi,
> 
> Sascha Hauer writes:
> > On Tue, Apr 24, 2012 at 04:48:14PM +0200, Lothar Wa?mann wrote:
> > > Hi,
> > > 
> > > Marek Vasut writes:
> > > > This driver handles claiming of clocks and memory areas. These are later
> > > > properly delegated to it's child devices, the USB Host (ehci-mxs) and
> > > > USB Gadget (ci13xxx-mxs).
> > > > 
> > > > Signed-off-by: Marek Vasut <marex@denx.de>
> > > > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > > > Cc: Detlev Zundel <dzu@denx.de>
> > > > Cc: Fabio Estevam <festevam@gmail.com>
> > > > Cc: Li Frank-B20596 <B20596@freescale.com>
> > > > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > > > Cc: Linux USB <linux-usb@vger.kernel.org>
> > > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > > Cc: Shawn Guo <shawn.guo@freescale.com>
> > > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > > Cc: Stefano Babic <sbabic@denx.de>
> > > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > > Cc: Tony Lin <tony.lin@freescale.com>
> > > > Cc: Wolfgang Denk <wd@denx.de>
> > > > ---
> > > >  drivers/usb/otg/Kconfig   |    6 +
> > > >  drivers/usb/otg/Makefile  |    1 +
> > > >  drivers/usb/otg/imx-otg.c |  473 +++++++++++++++++++++++++++++++++++++++++++++
> > > >  3 files changed, 480 insertions(+)
> > > >  create mode 100644 drivers/usb/otg/imx-otg.c
> > > > 
> > > > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > > > index 5c87db0..e7c6325 100644
> > > > --- a/drivers/usb/otg/Kconfig
> > > > +++ b/drivers/usb/otg/Kconfig
> > > > @@ -116,6 +116,12 @@ config FSL_USB2_OTG
> > > >  	help
> > > >  	  Enable this to support Freescale USB OTG transceiver.
> > > >  
> > > > +config USB_IMX_COMPOSITE
> > > > +	bool
> > > > +	help
> > > > +	  Composite driver that handles clock and memory mapping for
> > > > +	  i.MX USB host and USB PHY.
> > > > +
> > > >  config USB_MV_OTG
> > > >  	tristate "Marvell USB OTG support"
> > > >  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> > > > diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> > > > index 41aa509..7d2c631 100644
> > > > --- a/drivers/usb/otg/Makefile
> > > > +++ b/drivers/usb/otg/Makefile
> > > > @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
> > > >  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
> > > >  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
> > > >  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> > > > +obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
> > > >  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> > > > diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
> > > > new file mode 100644
> > > > index 0000000..8440d909
> > > > --- /dev/null
> > > > +++ b/drivers/usb/otg/imx-otg.c
> > > > @@ -0,0 +1,473 @@
> > > > +/*
> > > > + * drivers/usb/otg/imx-otg.c
> > > > + *
> > > > + * Freescale i.MX USB composite driver.
> > > > + *
> > > > + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> > > > + * on behalf of DENX Software Engineering GmbH
> > > > + *
> > > > + * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
> > > > + */
> > > > +
> > > Why do you call this driver imx-otg when it is actually MXS specific?
> > > How would you call a corresponding driver for the remaining i.MX
> > > processors?
> > 
> > This is the driver for the all i.MX processors.
> > 
> If it is for all i.MX processors, it shouldn't access MXS specific
> registers, like:
> +		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_SET);

Indeed not. This should be done in the phy driver.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24 16:47                 ` Sascha Hauer
@ 2012-04-24 17:49                   ` Marek Vasut
  2012-04-24 20:49                     ` Sascha Hauer
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-24 17:49 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> On Tue, Apr 24, 2012 at 06:13:04PM +0200, Lothar Wa?mann wrote:
> > Hi,
> > 
> > Sascha Hauer writes:
> > > On Tue, Apr 24, 2012 at 04:48:14PM +0200, Lothar Wa?mann wrote:
> > > > Hi,
> > > > 
> > > > Marek Vasut writes:
> > > > > This driver handles claiming of clocks and memory areas. These are
> > > > > later properly delegated to it's child devices, the USB Host
> > > > > (ehci-mxs) and USB Gadget (ci13xxx-mxs).
> > > > > 
> > > > > Signed-off-by: Marek Vasut <marex@denx.de>
> > > > > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > > > > Cc: Detlev Zundel <dzu@denx.de>
> > > > > Cc: Fabio Estevam <festevam@gmail.com>
> > > > > Cc: Li Frank-B20596 <B20596@freescale.com>
> > > > > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > > > > Cc: Linux USB <linux-usb@vger.kernel.org>
> > > > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > > > Cc: Shawn Guo <shawn.guo@freescale.com>
> > > > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > > > Cc: Stefano Babic <sbabic@denx.de>
> > > > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > > > Cc: Tony Lin <tony.lin@freescale.com>
> > > > > Cc: Wolfgang Denk <wd@denx.de>
> > > > > ---
> > > > > 
> > > > >  drivers/usb/otg/Kconfig   |    6 +
> > > > >  drivers/usb/otg/Makefile  |    1 +
> > > > >  drivers/usb/otg/imx-otg.c |  473
> > > > >  +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed,
> > > > >  480 insertions(+)
> > > > >  create mode 100644 drivers/usb/otg/imx-otg.c
> > > > > 
> > > > > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > > > > index 5c87db0..e7c6325 100644
> > > > > --- a/drivers/usb/otg/Kconfig
> > > > > +++ b/drivers/usb/otg/Kconfig
> > > > > @@ -116,6 +116,12 @@ config FSL_USB2_OTG
> > > > > 
> > > > >  	help
> > > > >  	
> > > > >  	  Enable this to support Freescale USB OTG transceiver.
> > > > > 
> > > > > +config USB_IMX_COMPOSITE
> > > > > +	bool
> > > > > +	help
> > > > > +	  Composite driver that handles clock and memory mapping for
> > > > > +	  i.MX USB host and USB PHY.
> > > > > +
> > > > > 
> > > > >  config USB_MV_OTG
> > > > >  
> > > > >  	tristate "Marvell USB OTG support"
> > > > >  	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
> > > > > 
> > > > > diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
> > > > > index 41aa509..7d2c631 100644
> > > > > --- a/drivers/usb/otg/Makefile
> > > > > +++ b/drivers/usb/otg/Makefile
> > > > > @@ -20,4 +20,5 @@ obj-$(CONFIG_USB_MSM_OTG)	+= msm_otg.o
> > > > > 
> > > > >  obj-$(CONFIG_AB8500_USB)	+= ab8500-usb.o
> > > > >  fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
> > > > >  obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
> > > > > 
> > > > > +obj-$(CONFIG_USB_IMX_COMPOSITE)	+= imx-otg.o
> > > > > 
> > > > >  obj-$(CONFIG_USB_MV_OTG)	+= mv_otg.o
> > > > > 
> > > > > diff --git a/drivers/usb/otg/imx-otg.c b/drivers/usb/otg/imx-otg.c
> > > > > new file mode 100644
> > > > > index 0000000..8440d909
> > > > > --- /dev/null
> > > > > +++ b/drivers/usb/otg/imx-otg.c
> > > > > @@ -0,0 +1,473 @@
> > > > > +/*
> > > > > + * drivers/usb/otg/imx-otg.c
> > > > > + *
> > > > > + * Freescale i.MX USB composite driver.
> > > > > + *
> > > > > + * Copyright (C) 2012 Marek Vasut <marex@denx.de>
> > > > > + * on behalf of DENX Software Engineering GmbH
> > > > > + *
> > > > > + * 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., 675 Mass Ave, Cambridge, MA 02139,
> > > > > USA. + */
> > > > > +
> > > > 
> > > > Why do you call this driver imx-otg when it is actually MXS specific?
> > > > How would you call a corresponding driver for the remaining i.MX
> > > > processors?
> > > 
> > > This is the driver for the all i.MX processors.
> > 
> > If it is for all i.MX processors, it shouldn't access MXS specific
> > registers, like:
> > +		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_SET);
> 
> Indeed not. This should be done in the phy driver.

Ok, so now you figured out that all these set_host() set_peripheral() work() 
calls should be back in the phy driver, not in the imx-otg? hm ... so back to 
the V4 of the patchset?

> 
> Sascha

Best regards,
Marek Vasut

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

* [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver
  2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
                           ` (10 preceding siblings ...)
  2012-04-24  3:18         ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
@ 2012-04-24 20:02         ` Russell King - ARM Linux
  2012-04-25 12:27           ` Marek Vasut
  11 siblings, 1 reply; 149+ messages in thread
From: Russell King - ARM Linux @ 2012-04-24 20:02 UTC (permalink / raw)
  To: linux-arm-kernel

Do you really need 138 messages (and counting) all threaded together
across the entire history of this patch set?  Please stop posting new
copies of your patch set as followups to the previous set.

Not only does it rob horizontal space for reading the subjects in the
index, but also it either buries your patches ages back or brings the
entire 138 messages to the front of mailboxes, depending on your sort
preferences.  Either way it makes threaded reading of the mailing list
really difficult.

Please stop this antisocial behaviour.  Thanks.

On Tue, Apr 24, 2012 at 05:18:32AM +0200, Marek Vasut wrote:
> From: Marek Vasut <marek.vasut@gmail.com>
> 
> This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
> generic USB PHY infrastructure. Also added is glue code for CI13xxx driver, to
> allow device mode. This patchset still does NOT support OTG mode, the
> device/host mode is selected via platform data.
> 
> V2: Introduce stub imx-usb driver that then registers the PHY and EHCI drivers.
> V3: Add the HCD on demand based on the PHY's state (only add HCD if it's host).
>     Currently, only the HOST mode is supported.
> V4: * Introduce ci13xxx gadget glue
>     * Reorder patches in a more sensible order
>     * Introduce platform data, containing VBUS GPIO and port mode (device/gadget)
>     * Rename imx-usb to imx-otg
>     * Drop mx28evk usb host patch
>     * Use more devm_ function
>     * Rework the mxs-phy to register the same interrupt as ehci-mxs (and
>       effectivelly kill bogus otg_set_vbus() call from ehci-mxs ; use standard
>       ehci irq handling in ehci-mxs)
> V5: * Finally move OTG IRQ handling into imx-otg
>     * Move imx_otg_set_{host,peripheral}() into imx-otg
>     * Move imx_otg_work() into imx-otg driver (now it all makes sense, yay!)
> 
> Marek Vasut (11):
>   MXS: Make clk_disable return integer
>   MXS: Add USB EHCI and USB PHY clock handling
>   MXS: Fixup i.MX233 USB base address name
>   MXS: Add data shared between imx-otg and EHCI driver
>   MXS: Modify the ci13xxx_udc to avoid adding UDC
>   MXS: Add small registration glue for ci13xxx_udc
>   MXS: Add separate MXS EHCI HCD driver
>   MXS: Add imx-otg driver
>   MXS: Add USB PHY driver
>   MXS: Add platform registration hooks for USB EHCI
>   MXS: Enable USB on M28EVK
> 
>  arch/arm/mach-mxs/Kconfig                       |    2 +
>  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
>  arch/arm/mach-mxs/devices-mx28.h                |    5 +
>  arch/arm/mach-mxs/devices/Kconfig               |    3 +
>  arch/arm/mach-mxs/devices/Makefile              |    1 +
>  arch/arm/mach-mxs/devices/platform-usb.c        |   85 ++++
>  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
>  arch/arm/mach-mxs/include/mach/devices-common.h |   13 +
>  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
>  arch/arm/mach-mxs/mach-m28evk.c                 |   21 +
>  drivers/usb/gadget/Kconfig                      |   17 +
>  drivers/usb/gadget/Makefile                     |    1 +
>  drivers/usb/gadget/ci13xxx_mxs.c                |   67 ++++
>  drivers/usb/gadget/ci13xxx_udc.c                |   12 +-
>  drivers/usb/gadget/ci13xxx_udc.h                |    1 +
>  drivers/usb/host/Kconfig                        |    7 +
>  drivers/usb/host/ehci-hcd.c                     |    5 +
>  drivers/usb/host/ehci-mxs.c                     |  178 +++++++++
>  drivers/usb/otg/Kconfig                         |   16 +
>  drivers/usb/otg/Makefile                        |    2 +
>  drivers/usb/otg/imx-otg.c                       |  473 +++++++++++++++++++++++
>  drivers/usb/otg/mxs-phy.c                       |  237 ++++++++++++
>  include/linux/usb/mxs-usb.h                     |   95 +++++
>  23 files changed, 1266 insertions(+), 13 deletions(-)
>  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
>  create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c
>  create mode 100644 drivers/usb/host/ehci-mxs.c
>  create mode 100644 drivers/usb/otg/imx-otg.c
>  create mode 100644 drivers/usb/otg/mxs-phy.c
>  create mode 100644 include/linux/usb/mxs-usb.h
> 
> Cc: Chen Peter-B29397 <B29397@freescale.com>
> Cc: Detlev Zundel <dzu@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Li Frank-B20596 <B20596@freescale.com>
> Cc: Lin Tony-B19295 <B19295@freescale.com>
> Cc: Linux USB <linux-usb@vger.kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@freescale.com>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Tony Lin <tony.lin@freescale.com>
> Cc: Wolfgang Denk <wd@denx.de>
> 
> -- 
> 1.7.10
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24 17:49                   ` Marek Vasut
@ 2012-04-24 20:49                     ` Sascha Hauer
  2012-04-24 20:58                       ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Sascha Hauer @ 2012-04-24 20:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Apr 24, 2012 at 07:49:37PM +0200, Marek Vasut wrote:
> > > > > 
> > > > > Why do you call this driver imx-otg when it is actually MXS specific?
> > > > > How would you call a corresponding driver for the remaining i.MX
> > > > > processors?
> > > > 
> > > > This is the driver for the all i.MX processors.
> > > 
> > > If it is for all i.MX processors, it shouldn't access MXS specific
> > > registers, like:
> > > +		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_SET);
> > 
> > Indeed not. This should be done in the phy driver.
> 
> Ok, so now you figured out that all these set_host() set_peripheral() work() 
> calls should be back in the phy driver, not in the imx-otg? hm ... so back to 
> the V4 of the patchset?

Not really, you are just not allowed to put phy code into imx-otg.c,
because the phy may be another one on a different SoC.

That said, I am a bit confused at the moment. There seems to be no
method to activate the interrupt in the phy.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24 20:49                     ` Sascha Hauer
@ 2012-04-24 20:58                       ` Marek Vasut
  2012-04-25  0:17                         ` Chen Peter-B29397
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-24 20:58 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Sascha Hauer,

> On Tue, Apr 24, 2012 at 07:49:37PM +0200, Marek Vasut wrote:
> > > > > > Why do you call this driver imx-otg when it is actually MXS
> > > > > > specific? How would you call a corresponding driver for the
> > > > > > remaining i.MX processors?
> > > > > 
> > > > > This is the driver for the all i.MX processors.
> > > > 
> > > > If it is for all i.MX processors, it shouldn't access MXS specific
> > > > registers, like:
> > > > +		writel(wakeup, x->io_priv + HW_USBPHY_CTRL_SET);
> > > 
> > > Indeed not. This should be done in the phy driver.
> > 
> > Ok, so now you figured out that all these set_host() set_peripheral()
> > work() calls should be back in the phy driver, not in the imx-otg? hm
> > ... so back to the V4 of the patchset?
> 
> Not really, you are just not allowed to put phy code into imx-otg.c,
> because the phy may be another one on a different SoC.
> 
> That said, I am a bit confused at the moment. There seems to be no
> method to activate the interrupt in the phy.

There is more to be confused about -- you don't get the host/device connection 
interrupt from the PHY, but you dig one of them from the EHCI host and the other 
from the EHCI host too -- which is pretty messed up already.

We can certainly use IRQF_SHARED to trap some of the interrupts in the PHY code, 
but that's still quite weird.

> Sascha

Best regards,
Marek Vasut

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

* [PATCH 08/11] MXS: Add imx-otg driver
  2012-04-24 20:58                       ` Marek Vasut
@ 2012-04-25  0:17                         ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-25  0:17 UTC (permalink / raw)
  To: linux-arm-kernel

 
> 
> There is more to be confused about -- you don't get the host/device
> connection
> interrupt from the PHY, but you dig one of them from the EHCI host and
> the other
> from the EHCI host too -- which is pretty messed up already.
> 
> We can certainly use IRQF_SHARED to trap some of the interrupts in the
> PHY code,
> but that's still quite weird.
> 
Below need to be implemented at phy driver:
- struct usb_phy;
- phy's interrupt which is only used for handle wakeup issue,
PHY's interrupt line is NOT the same with controller's, so you don't
need to use IRQF_SHARED, and request the same irq with controller's.

Below need to be implemented at otg driver:
- struct usb_otg;
- manage PHY through PHY interfaces which are implemented at phy driver.
- OTG interrupt, it only handles ID/vbus interrupt.
- OTG switch routine, it handles host and device's add/remove operation due to
id/vbus change and some operation_mode defined at platform_data or DT in fture.


> > Sascha
> 
> Best regards,
> Marek Vasut

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

* [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver
  2012-04-24 20:02         ` [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver Russell King - ARM Linux
@ 2012-04-25 12:27           ` Marek Vasut
  2012-04-25 12:41             ` Russell King - ARM Linux
  0 siblings, 1 reply; 149+ messages in thread
From: Marek Vasut @ 2012-04-25 12:27 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Russell King - ARM Linux,

> Do you really need 138 messages (and counting) all threaded together
> across the entire history of this patch set?  Please stop posting new
> copies of your patch set as followups to the previous set.

Well, it's usually to the point where the usb patches change, so instead of 
posting 8 patches, I post the whole set ot make it consistent.

> Not only does it rob horizontal space for reading the subjects in the
> index, but also it either buries your patches ages back or brings the
> entire 138 messages to the front of mailboxes, depending on your sort
> preferences.  Either way it makes threaded reading of the mailing list
> really difficult.
> 
> Please stop this antisocial behaviour.  Thanks.

Can you please suggest better solution? You mean post each new set as a separate 
thread ? Or post each patch as an in-reply-to previous one?

Thanks and sorry for that.

> On Tue, Apr 24, 2012 at 05:18:32AM +0200, Marek Vasut wrote:
> > From: Marek Vasut <marek.vasut@gmail.com>
> > 
> > This patchset introduces the USB Host driver for i.MX28 CPU, utilising
> > the generic USB PHY infrastructure. Also added is glue code for CI13xxx
> > driver, to allow device mode. This patchset still does NOT support OTG
> > mode, the device/host mode is selected via platform data.
> > 
> > V2: Introduce stub imx-usb driver that then registers the PHY and EHCI
> > drivers. V3: Add the HCD on demand based on the PHY's state (only add
> > HCD if it's host).
> > 
> >     Currently, only the HOST mode is supported.
> > 
> > V4: * Introduce ci13xxx gadget glue
> > 
> >     * Reorder patches in a more sensible order
> >     * Introduce platform data, containing VBUS GPIO and port mode
> >     (device/gadget) * Rename imx-usb to imx-otg
> >     * Drop mx28evk usb host patch
> >     * Use more devm_ function
> >     * Rework the mxs-phy to register the same interrupt as ehci-mxs (and
> >     
> >       effectivelly kill bogus otg_set_vbus() call from ehci-mxs ; use
> >       standard ehci irq handling in ehci-mxs)
> > 
> > V5: * Finally move OTG IRQ handling into imx-otg
> > 
> >     * Move imx_otg_set_{host,peripheral}() into imx-otg
> >     * Move imx_otg_work() into imx-otg driver (now it all makes sense,
> >     yay!)
> > 
> > Marek Vasut (11):
> >   MXS: Make clk_disable return integer
> >   MXS: Add USB EHCI and USB PHY clock handling
> >   MXS: Fixup i.MX233 USB base address name
> >   MXS: Add data shared between imx-otg and EHCI driver
> >   MXS: Modify the ci13xxx_udc to avoid adding UDC
> >   MXS: Add small registration glue for ci13xxx_udc
> >   MXS: Add separate MXS EHCI HCD driver
> >   MXS: Add imx-otg driver
> >   MXS: Add USB PHY driver
> >   MXS: Add platform registration hooks for USB EHCI
> >   MXS: Enable USB on M28EVK
> >  
> >  arch/arm/mach-mxs/Kconfig                       |    2 +
> >  arch/arm/mach-mxs/clock-mx28.c                  |   28 +-
> >  arch/arm/mach-mxs/devices-mx28.h                |    5 +
> >  arch/arm/mach-mxs/devices/Kconfig               |    3 +
> >  arch/arm/mach-mxs/devices/Makefile              |    1 +
> >  arch/arm/mach-mxs/devices/platform-usb.c        |   85 ++++
> >  arch/arm/mach-mxs/include/mach/clock.h          |    2 +-
> >  arch/arm/mach-mxs/include/mach/devices-common.h |   13 +
> >  arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
> >  arch/arm/mach-mxs/mach-m28evk.c                 |   21 +
> >  drivers/usb/gadget/Kconfig                      |   17 +
> >  drivers/usb/gadget/Makefile                     |    1 +
> >  drivers/usb/gadget/ci13xxx_mxs.c                |   67 ++++
> >  drivers/usb/gadget/ci13xxx_udc.c                |   12 +-
> >  drivers/usb/gadget/ci13xxx_udc.h                |    1 +
> >  drivers/usb/host/Kconfig                        |    7 +
> >  drivers/usb/host/ehci-hcd.c                     |    5 +
> >  drivers/usb/host/ehci-mxs.c                     |  178 +++++++++
> >  drivers/usb/otg/Kconfig                         |   16 +
> >  drivers/usb/otg/Makefile                        |    2 +
> >  drivers/usb/otg/imx-otg.c                       |  473
> >  +++++++++++++++++++++++ drivers/usb/otg/mxs-phy.c                      
> >  |  237 ++++++++++++ include/linux/usb/mxs-usb.h                     |  
> >  95 +++++
> >  23 files changed, 1266 insertions(+), 13 deletions(-)
> >  create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
> >  create mode 100644 drivers/usb/gadget/ci13xxx_mxs.c
> >  create mode 100644 drivers/usb/host/ehci-mxs.c
> >  create mode 100644 drivers/usb/otg/imx-otg.c
> >  create mode 100644 drivers/usb/otg/mxs-phy.c
> >  create mode 100644 include/linux/usb/mxs-usb.h
> > 
> > Cc: Chen Peter-B29397 <B29397@freescale.com>
> > Cc: Detlev Zundel <dzu@denx.de>
> > Cc: Fabio Estevam <festevam@gmail.com>
> > Cc: Li Frank-B20596 <B20596@freescale.com>
> > Cc: Lin Tony-B19295 <B19295@freescale.com>
> > Cc: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@freescale.com>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Tony Lin <tony.lin@freescale.com>
> > Cc: Wolfgang Denk <wd@denx.de>

Best regards,
Marek Vasut

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

* [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver
  2012-04-25 12:27           ` Marek Vasut
@ 2012-04-25 12:41             ` Russell King - ARM Linux
  2012-04-25 12:43               ` Marek Vasut
  0 siblings, 1 reply; 149+ messages in thread
From: Russell King - ARM Linux @ 2012-04-25 12:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Apr 25, 2012 at 02:27:58PM +0200, Marek Vasut wrote:
> Dear Russell King - ARM Linux,
> 
> > Do you really need 138 messages (and counting) all threaded together
> > across the entire history of this patch set?  Please stop posting new
> > copies of your patch set as followups to the previous set.
> 
> Well, it's usually to the point where the usb patches change, so instead of 
> posting 8 patches, I post the whole set ot make it consistent.

Sure, no problem with that.

> > Not only does it rob horizontal space for reading the subjects in the
> > index, but also it either buries your patches ages back or brings the
> > entire 138 messages to the front of mailboxes, depending on your sort
> > preferences.  Either way it makes threaded reading of the mailing list
> > really difficult.
> > 
> > Please stop this antisocial behaviour.  Thanks.
> 
> Can you please suggest better solution? You mean post each new set as a separate 
> thread ? Or post each patch as an in-reply-to previous one?

Please don't thread the posting of a new version of the patches to
the previous posting of the older version.  In other words, the
initial summary mail for V5 should not be threaded to the V4 series,
and the individual patches for V5 should only be threaded to the
initial summary mail for V5.

So, rather than this as one massive thread:
...[PATCH V3 0/N]
   +-[PATCH V3 1/N]
   | `-Replies
   +-[PATCH V3 2/N]
   | `-Replies
   +-[PATCH V3 3/N]
   | `-Replies
   `-[PATCH V4 0/N]
     +-[PATCH V4 1/N]
     | `-Replies
     +-[PATCH V4 2/N]
     | `-Replies
     +-[PATCH V4 3/N]
     | `-Replies
     `-[PATCH V5 0/N]
        +-[PATCH V5 1/N]
        | `-Replies
        +-[PATCH V5 2/N]
        | `-Replies
        `-[PATCH V5 3/N]
          `-Replies

It should be:
[PATCH V4 0/N]
+-[PATCH V4 1/N]
| `-Replies
+-[PATCH V4 2/N]
| `-Replies
`-[PATCH V4 3/N]
  `-Replies

<some time later>

[PATCH V5 0/N]
+-[PATCH V5 1/N]
| `-Replies
+-[PATCH V5 2/N]
| `-Replies
`-[PATCH V5 3/N]
  `-Replies

Where the 0/N patches have no parent message.  In other words, these
sumamry messages have no references or in-reply-to headers.

If you wish to provide a direct reference back to a previous thread,
please do so via URLs into archives, or providing the message id or
exact subject of the previous series in the new summary message body.
But please don't thread each version to the previous version!

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

* [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver
  2012-04-25 12:41             ` Russell King - ARM Linux
@ 2012-04-25 12:43               ` Marek Vasut
  0 siblings, 0 replies; 149+ messages in thread
From: Marek Vasut @ 2012-04-25 12:43 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Russell King - ARM Linux,

> On Wed, Apr 25, 2012 at 02:27:58PM +0200, Marek Vasut wrote:
> > Dear Russell King - ARM Linux,
> > 
> > > Do you really need 138 messages (and counting) all threaded together
> > > across the entire history of this patch set?  Please stop posting new
> > > copies of your patch set as followups to the previous set.
> > 
> > Well, it's usually to the point where the usb patches change, so instead
> > of posting 8 patches, I post the whole set ot make it consistent.
> 
> Sure, no problem with that.
> 
> > > Not only does it rob horizontal space for reading the subjects in the
> > > index, but also it either buries your patches ages back or brings the
> > > entire 138 messages to the front of mailboxes, depending on your sort
> > > preferences.  Either way it makes threaded reading of the mailing list
> > > really difficult.
> > > 
> > > Please stop this antisocial behaviour.  Thanks.
> > 
> > Can you please suggest better solution? You mean post each new set as a
> > separate thread ? Or post each patch as an in-reply-to previous one?
> 
> Please don't thread the posting of a new version of the patches to
> the previous posting of the older version.  In other words, the
> initial summary mail for V5 should not be threaded to the V4 series,
> and the individual patches for V5 should only be threaded to the
> initial summary mail for V5.
> 
> So, rather than this as one massive thread:
> ...[PATCH V3 0/N]
>    +-[PATCH V3 1/N]
> 
>    | `-Replies
> 
>    +-[PATCH V3 2/N]
> 
>    | `-Replies
> 
>    +-[PATCH V3 3/N]
> 
>    | `-Replies
> 
>    `-[PATCH V4 0/N]
>      +-[PATCH V4 1/N]
> 
>      | `-Replies
> 
>      +-[PATCH V4 2/N]
> 
>      | `-Replies
> 
>      +-[PATCH V4 3/N]
> 
>      | `-Replies
> 
>      `-[PATCH V5 0/N]
>         +-[PATCH V5 1/N]
> 
>         | `-Replies
> 
>         +-[PATCH V5 2/N]
> 
>         | `-Replies
> 
>         `-[PATCH V5 3/N]
>           `-Replies
> 
> It should be:
> [PATCH V4 0/N]
> +-[PATCH V4 1/N]
> 
> | `-Replies
> 
> +-[PATCH V4 2/N]
> 
> | `-Replies
> 
> `-[PATCH V4 3/N]
>   `-Replies
> 
> <some time later>
> 
> [PATCH V5 0/N]
> +-[PATCH V5 1/N]
> 
> | `-Replies
> 
> +-[PATCH V5 2/N]
> 
> | `-Replies
> 
> `-[PATCH V5 3/N]
>   `-Replies
> 
> Where the 0/N patches have no parent message.  In other words, these
> sumamry messages have no references or in-reply-to headers.

I see, roger that!

> If you wish to provide a direct reference back to a previous thread,
> please do so via URLs into archives, or providing the message id or
> exact subject of the previous series in the new summary message body.
> But please don't thread each version to the previous version!

Ack. Thanks for clearing this out, sorry for the mess.

Best regards,
Marek Vasut

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

* [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC
  2012-04-24  3:18         ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
@ 2012-04-29  8:26           ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-29  8:26 UTC (permalink / raw)
  To: linux-arm-kernel



> Subject: [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC
> 
> On the i.MX platform, we are adding the UDC ourselves from the PHY driver.
> This
> patch adds a flag into the ci13xxx_udc that avoids adding the UDC if set.
> 

You may need to add reviewers for is using cil3xxx_udc too.

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

* [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver
  2012-04-24  3:18         ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
@ 2012-04-29  8:28           ` Chen Peter-B29397
  0 siblings, 0 replies; 149+ messages in thread
From: Chen Peter-B29397 @ 2012-04-29  8:28 UTC (permalink / raw)
  To: linux-arm-kernel


 
> 
> This driver will handle i.MX233/i.MX28 and I hope soon i.MX6Q. I tried to
> keep
> this separate from the MXC EHCI to avoid further polution of the MXC EHCI,
> though eventually these two might be merged.
> 
> NOTE: I still haven't figured out how to enable/disable the disconnection
> detector, it can't be enabled all the time, so I toggle PHY stuff from
> this
> driver, which I doubt is correct.
> 
 
still not understand high speed disconnect detector?
I may explain it twice during reviewing. 

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

end of thread, other threads:[~2012-04-29  8:28 UTC | newest]

Thread overview: 149+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-04-17 10:15 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
2012-04-17 10:15 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-17 18:01   ` Sascha Hauer
2012-04-17 10:15 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-17 10:15 ` [PATCH 4/8] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-17 10:15 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
2012-04-17 17:51   ` Sascha Hauer
2012-04-19 11:40   ` Arnd Bergmann
2012-04-17 10:15 ` [PATCH 6/8] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-17 10:15 ` [PATCH 7/8] MXS: Enable USB on M28EVK Marek Vasut
2012-04-17 17:40   ` Sergei Shtylyov
2012-04-17 10:15 ` [PATCH 8/8] MXS: Enable USB on MX28EVK Marek Vasut
2012-04-17 10:37 ` [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Dirk Behme
2012-04-17 11:24   ` Marek Vasut
2012-04-18  1:00     ` Chen Peter-B29397
2012-04-17 11:29 ` Sascha Hauer
2012-04-17 11:45   ` Marek Vasut
2012-04-17 12:18     ` Sascha Hauer
2012-04-17 20:29       ` Marek Vasut
2012-04-18  7:02         ` Sascha Hauer
2012-04-18  8:05           ` Chen Peter-B29397
2012-04-17 12:36   ` Heikki Krogerus
2012-04-18  4:31   ` Chen Peter-B29397
2012-04-18  7:40     ` Sascha Hauer
2012-04-20 13:10       ` 答复: " Liu JunJie-B08287
2012-04-20 16:25         ` Marek Vasut
2012-04-23  2:02           ` Liu JunJie-B08287
2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
2012-04-18  2:07   ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
2012-04-18  2:07   ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-18  2:07   ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-18  2:07   ` [PATCH 04/10] MXS: Add data shared between imx-usb, PHY and EHCI driver Marek Vasut
2012-04-18  2:07   ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-18  2:07   ` [PATCH 06/10] MXS: Add composite imx-usb driver Marek Vasut
2012-04-18  2:07   ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
2012-04-18  2:07   ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-18  7:01     ` Chen Peter-B29397
2012-04-18  8:40       ` Sascha Hauer
2012-04-18  9:18         ` Chen Peter-B29397
2012-04-18  9:45           ` Sascha Hauer
2012-04-19  2:54             ` Chen Peter-B29397
2012-04-19  6:34               ` Sascha Hauer
2012-04-18  2:07   ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
2012-04-18 12:08     ` Sergei Shtylyov
2012-04-18 12:24       ` Marek Vasut
2012-04-18  2:07   ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
2012-04-18  2:09   ` [RFC PATCH 00/10 V2] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-04-18  7:52   ` Chen Peter-B29397
2012-04-18 17:49     ` Marek Vasut
2012-04-19  2:37       ` Chen Peter-B29397
2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
2012-04-18 17:46     ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
2012-04-18 17:46     ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-18 17:46     ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-18 17:46     ` [PATCH 04/10] MXS: Add data shared between imx-usb and EHCI driver Marek Vasut
2012-04-18 17:46     ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-19 11:51       ` Arnd Bergmann
2012-04-19 14:24         ` Shawn Guo
2012-04-19 21:32           ` Marek Vasut
2012-04-20  0:40             ` Shawn Guo
2012-04-20  0:56               ` Marek Vasut
2012-04-20  1:34                 ` Shawn Guo
2012-04-20  1:40                   ` Marek Vasut
2012-04-18 17:46     ` [PATCH 06/10] MXS: Add imx-usb driver Marek Vasut
2012-04-18 17:46     ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
2012-04-18 19:36       ` Sascha Hauer
2012-04-18 20:02         ` Marek Vasut
2012-04-18 20:16           ` Sascha Hauer
2012-04-19 22:06             ` Marek Vasut
2012-04-20  2:35               ` Chen Peter-B29397
2012-04-18 17:46     ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-18 19:50       ` Sascha Hauer
2012-04-18 20:07         ` Marek Vasut
2012-04-18 20:43           ` Sascha Hauer
2012-04-18 17:46     ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
2012-04-18 17:46     ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
2012-04-20  2:13     ` [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-04-20  9:48       ` Sascha Hauer
2012-04-20 12:26         ` Peter Chen
2012-04-20 12:44           ` Marek Vasut
2012-04-20 13:00             ` Robert Schwebel
2012-04-20 13:26             ` Sascha Hauer
2012-04-20 16:36               ` Michael Grzeschik
2012-04-21  7:42                 ` Peter Chen
2012-04-21  8:17                   ` Sascha Hauer
2012-04-21 13:53     ` Subodh Nijsure
2012-04-21 15:37       ` Marek Vasut
2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
2012-04-22 12:59       ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
2012-04-22 12:59       ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-22 14:42         ` Shawn Guo
2012-04-22 15:42           ` Marek Vasut
2012-04-22 16:34             ` Shawn Guo
2012-04-22 12:59       ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-22 12:59       ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
2012-04-22 14:39         ` Shawn Guo
2012-04-22 15:42           ` Marek Vasut
2012-04-22 16:38             ` Shawn Guo
2012-04-22 12:59       ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
2012-04-22 12:59       ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
2012-04-23  1:46         ` Chen Peter-B29397
2012-04-22 12:59       ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-23  1:44         ` Chen Peter-B29397
2012-04-23  2:11           ` Marek Vasut
2012-04-22 12:59       ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
2012-04-23  6:39         ` Sascha Hauer
2012-04-23  9:38           ` Marek Vasut
2012-04-22 12:59       ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
2012-04-23  1:42         ` Chen Peter-B29397
2012-04-23  2:17           ` Marek Vasut
2012-04-23 12:20             ` Chen Peter-B29397
2012-04-22 12:59       ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-22 12:59       ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
2012-04-23  1:57         ` Chen Peter-B29397
2012-04-23  2:18           ` Marek Vasut
2012-04-23  2:01       ` [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver Chen Peter-B29397
2012-04-23  2:18         ` Marek Vasut
2012-04-23 11:59           ` Chen Peter-B29397
2012-04-23 12:09             ` Marek Vasut
2012-04-23 12:25               ` Chen Peter-B29397
2012-04-23 12:40                 ` Marek Vasut
2012-04-23  2:37         ` Marek Vasut
2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
2012-04-24  3:18         ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
2012-04-24  3:18         ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-24  3:18         ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-24  3:18         ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
2012-04-24  3:18         ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
2012-04-29  8:26           ` Chen Peter-B29397
2012-04-24  3:18         ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
2012-04-24  3:18         ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-29  8:28           ` Chen Peter-B29397
2012-04-24  3:18         ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
2012-04-24 14:48           ` Lothar Waßmann
2012-04-24 14:50             ` Sascha Hauer
2012-04-24 16:13               ` Lothar Waßmann
2012-04-24 16:47                 ` Sascha Hauer
2012-04-24 17:49                   ` Marek Vasut
2012-04-24 20:49                     ` Sascha Hauer
2012-04-24 20:58                       ` Marek Vasut
2012-04-25  0:17                         ` Chen Peter-B29397
2012-04-24  3:18         ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
2012-04-24  3:18         ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-24  3:18         ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
2012-04-24 20:02         ` [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver Russell King - ARM Linux
2012-04-25 12:27           ` Marek Vasut
2012-04-25 12:41             ` Russell King - ARM Linux
2012-04-25 12:43               ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.