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

This patchset introduces the USB Host driver for i.MX28 CPU, utilising the
generic USB PHY infrastructure. This version of patchset is now based on
ci13xxx rework by Alexander Shishkin.

This patchset now depends on the following four patches:
	http://www.spinics.net/lists/linux-usb/msg63787.html

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!)
V6: Do PHY-specific job inside the PHY driver
V7: * Pass only necessary data to the drivers registered by imx-otg
      (memory, irq, pointer to imx-otg device). This should fix issue pointed
      out by Lothar Wassmann.
    * Have single IRQ handler in imx-otg, which then calls host/gadget IRQ
      handlers only if they're registered via imx_otg_set_irq_handler() call,
      depending on the current state of the OTG.
V8: Rework on top of ci13xxx changes by Alex Shishkin

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 data shared between imx-otg and EHCI driver
  MXS: Add USB PHY driver
  CI13xxx: Add i.MX233/i.MX28 binding code
  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 |   13 +
 arch/arm/mach-mxs/include/mach/mx23.h           |    8 +-
 arch/arm/mach-mxs/mach-m28evk.c                 |   19 ++
 drivers/usb/chipidea/Makefile                   |    4 +
 drivers/usb/chipidea/ci13xxx_mxs.c              |  201 +++++++++++++++
 drivers/usb/otg/Kconfig                         |   10 +
 drivers/usb/otg/Makefile                        |    1 +
 drivers/usb/otg/mxs-phy.c                       |  313 +++++++++++++++++++++++
 include/linux/usb/mxs-usb.h                     |   39 +++
 16 files changed, 724 insertions(+), 9 deletions(-)
 create mode 100644 arch/arm/mach-mxs/devices/platform-usb.c
 create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Wolfgang Denk <wd@denx.de>

-- 
1.7.10

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

* [PATCH 1/8] MXS: Make clk_disable return integer
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
@ 2012-05-15  8:23 ` Marek Vasut
  2012-05-16  0:55   ` Richard Zhao
  2012-05-15  8:23 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.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] 30+ messages in thread

* [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
  2012-05-15  8:23 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
@ 2012-05-15  8:23 ` Marek Vasut
  2012-05-16  0:56   ` Richard Zhao
  2012-05-15  8:23 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.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..60ebe99 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-usb.0", "usb", usb0_clk)
+	_REGISTER_CLOCK("mxs-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.10

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

* [PATCH 3/8] MXS: Fixup i.MX233 USB base address name
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
  2012-05-15  8:23 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
  2012-05-15  8:23 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-05-15  8:23 ` Marek Vasut
  2012-05-16  0:58   ` Richard Zhao
  2012-05-15  8:23 ` [PATCH 4/8] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.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] 30+ messages in thread

* [PATCH 4/8] MXS: Add data shared between imx-otg and EHCI driver
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (2 preceding siblings ...)
  2012-05-15  8:23 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
@ 2012-05-15  8:23 ` Marek Vasut
  2012-05-16  1:00   ` Richard Zhao
  2012-05-15  8:23 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 include/linux/usb/mxs-usb.h |   39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 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..2678700
--- /dev/null
+++ b/include/linux/usb/mxs-usb.h
@@ -0,0 +1,39 @@
+/*
+ * 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/usb/otg.h>
+
+struct mxs_usb_platform_data {
+	uint32_t		gpio_vbus;
+	bool			gpio_vbus_inverted;
+};
+
+struct mxs_ci13xxx_phy_notify {
+	bool			discon;
+};
+
+#endif /* __INCLUDE_LINUX_USB_MXS_USB_H__ */
-- 
1.7.10

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (3 preceding siblings ...)
  2012-05-15  8:23 ` [PATCH 4/8] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
@ 2012-05-15  8:23 ` Marek Vasut
  2012-05-16  3:33   ` Richard Zhao
  2012-05-16 10:35   ` Peter Chen
       [not found] ` <1337070219-3630-1-git-send-email-marex-ynQEQJNshbs@public.gmane.org>
                   ` (2 subsequent siblings)
  7 siblings, 2 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/usb/otg/Kconfig   |   10 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  313 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 324 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c

diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 5c87db0..bc7625e 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -116,6 +116,16 @@ 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
+	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 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..eb658ca
--- /dev/null
+++ b/drivers/usb/otg/mxs-phy.c
@@ -0,0 +1,313 @@
+/*
+ * 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.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>
+#include <mach/mx28.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 mxs_usb_phy {
+	struct usb_phy		phy;
+	struct usb_otg		otg;
+	struct clk		*clk;
+	bool			discon;
+};
+
+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;
+
+	/* Enable IRQ sources. */
+	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
+		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
+
+	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;
+
+	/* Disable IRQ sources. */
+	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
+		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
+
+	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 mxs_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
+{
+	return 0;
+}
+
+static int mxs_otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *gg)
+{
+	return 0;
+}
+
+static int mxs_otg_set_vbus(struct usb_otg *otg, bool enabled)
+{
+	return 0;
+}
+
+static int mxs_usb_phy_notify(struct usb_phy *x, void *data)
+{
+	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
+	struct mxs_ci13xxx_phy_notify *notify = data;
+
+	if (notify->discon == phy->discon)
+		return 0;
+
+	phy->discon = notify->discon;
+
+	if (notify->discon) {
+		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 0;
+}
+
+static int __devinit mxs_phy_probe(struct platform_device *pdev)
+{
+	struct mxs_usb_phy *phy;
+	struct resource *mem_res;
+	void *retp;
+	int ret;
+	struct usb_otg *otg;
+
+	/* 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");
+		return -ENOMEM;
+	}
+
+	/* 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");
+		return -ENODEV;
+	}
+
+	/* 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");
+		return -EBUSY;
+	}
+
+	/* 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");
+		return -EFAULT;
+	}
+
+	/* 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");
+		return PTR_ERR(phy->clk);
+	}
+
+	/* 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.notify		= mxs_usb_phy_notify;
+	phy->phy.state		= OTG_STATE_UNDEFINED;
+
+	otg			= &phy->otg;
+	phy->phy.otg		= otg;
+
+	otg->phy		= &phy->phy;
+	otg->set_vbus		= mxs_otg_set_vbus;
+	otg->set_host		= mxs_otg_set_host;
+	otg->set_peripheral	= mxs_otg_set_peripheral;
+
+	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);
+	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] 30+ messages in thread

* [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
@ 2012-05-15  8:23     ` Marek Vasut
  2012-05-15  8:23 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
                       ` (6 subsequent siblings)
  7 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Marek Vasut, Alan Stern, Detlev Zundel, Dong Aisheng,
	Fabio Estevam, Felipe Balbi, Greg Kroah-Hartman,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA, Sascha Hauer, Shawn Guo,
	Stefano Babic, Uwe Kleine-König, Wolfgang Denk,
	Wolfram Sang

This codes connects the CI13xxx driver with the core found inside of
the Freescale i.MX244/i.MX28 CPU.

Signed-off-by: Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
Cc: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
Cc: Detlev Zundel <dzu-ynQEQJNshbs@public.gmane.org>
CC: Dong Aisheng <b29396-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
CC: Fabio Estevam <fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Cc: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
Cc: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
Cc: Linux ARM kernel <linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
CC: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
CC: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: Stefano Babic <sbabic-ynQEQJNshbs@public.gmane.org>
CC: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: Wolfgang Denk <wd-ynQEQJNshbs@public.gmane.org>
Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
---
 drivers/usb/chipidea/Makefile      |    4 +
 drivers/usb/chipidea/ci13xxx_mxs.c |  201 ++++++++++++++++++++++++++++++++++++
 2 files changed, 205 insertions(+)
 create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c

diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index cc34937..266d57d 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -12,3 +12,7 @@ endif
 ifneq ($(CONFIG_ARCH_MSM),)
 	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
 endif
+
+ifneq ($(CONFIG_ARCH_MXS),)
+	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
+endif
diff --git a/drivers/usb/chipidea/ci13xxx_mxs.c b/drivers/usb/chipidea/ci13xxx_mxs.c
new file mode 100644
index 0000000..fcca90b
--- /dev/null
+++ b/drivers/usb/chipidea/ci13xxx_mxs.c
@@ -0,0 +1,201 @@
+/*
+ * drivers/usb/chipidea/ci13xxx_mxs.c
+ *
+ * Freescale i.MX233/i.MX28 USB glue driver to CI13xxx core.
+ *
+ * Copyright (C) 2012 Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
+ * 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/pm_runtime.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+
+#include <linux/usb.h>
+#include <linux/usb/chipidea.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 <linux/usb/mxs-usb.h>
+
+#include "ci.h"
+
+static void ci13xxx_mxs_notify(struct ci13xxx *ci, unsigned event)
+{
+	uint32_t status;
+	struct usb_phy *phy;
+	struct mxs_ci13xxx_phy_notify notify;
+
+	phy = usb_get_transceiver();
+	if (!phy)
+		return;
+
+	if (event != CI13XXX_CONTROLLER_HOST_IRQ_EVENT)
+		return;
+
+	status = hw_read(ci, OP_USBSTS, ~0);
+
+	notify.discon = status & STS_PCD;
+
+	usb_phy_notify(phy, &notify);
+}
+
+static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
+	.name			= "ci13xxx_mxs",
+	.flags			= /*CI13XXX_REGS_SHARED |*/
+				  CI13XXX_REQUIRE_TRANSCEIVER |
+				  CI13XXX_PULLUP_ON_VBUS |
+				  CI13XXX_DISABLE_STREAMING,
+	.capoffset		= 0x100,
+	.notify_event		= ci13xxx_mxs_notify,
+};
+
+struct ci13xxx_mxs_data {
+	struct clk		*clk;
+	struct platform_device	*pdev;
+};
+
+static int __devinit ci13xxx_mxs_probe(struct platform_device *pdev)
+{
+	struct ci13xxx_mxs_data *data;
+	int ret;
+	struct usb_phy *phy;
+
+	phy = usb_get_transceiver();
+	if (!phy)
+		return -EPROBE_DEFER;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		dev_err(&pdev->dev, "Failed to allocate CI13xxx-MXS data!\n");
+		return -ENOMEM;
+	}
+
+	ret = usb_phy_init(phy);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to initialize PHY!\n");
+		return -EINVAL;
+	}
+
+	data->pdev = platform_device_alloc("ci_hdrc", -1);
+	if (!data->pdev) {
+		dev_err(&pdev->dev,
+			"Failed to allocate ci_hdrc platform device!\n");
+		ret = -ENOMEM;
+		goto put_phy;
+	}
+
+	/* Add DMA mask */
+	data->pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
+					sizeof(*data->pdev->dev.dma_mask),
+					GFP_KERNEL);
+	if (!data->pdev->dev.dma_mask) {
+		ret = -ENOMEM;
+		goto put_platform;
+	}
+
+	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
+	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+
+	ret = platform_device_add_resources(data->pdev, pdev->resource,
+					    pdev->num_resources);
+	if (ret) {
+		dev_err(&pdev->dev,
+			"Failed to add resources to platform device!\n");
+		goto put_platform;
+	}
+
+	ret = platform_device_add_data(data->pdev, &ci13xxx_mxs_udc_driver,
+				       sizeof(ci13xxx_mxs_udc_driver));
+	if (ret) {
+		dev_err(&pdev->dev,
+			"Failed to add platform data to platform device!\n");
+		goto put_platform;
+	}
+
+	/* 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 put_platform;
+	}
+
+	/* Prepare Host clock. */
+	ret = clk_prepare_enable(data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to enable clock for USB Host.\n");
+		goto put_clk;
+	}
+
+	ret = platform_device_add(data->pdev);
+	if (ret)
+		goto put_clk;
+
+	dev_set_drvdata(&pdev->dev, data);
+
+	pm_runtime_no_callbacks(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
+	return 0;
+
+put_clk:
+	clk_put(data->clk);
+put_platform:
+	platform_device_put(data->pdev);
+put_phy:
+	usb_phy_shutdown(phy);
+	return ret;
+}
+
+static int __devexit ci13xxx_mxs_remove(struct platform_device *pdev)
+{
+	struct ci13xxx_mxs_data *data = dev_get_drvdata(&pdev->dev);
+	struct usb_phy *phy = usb_get_transceiver();
+
+	clk_disable_unprepare(data->clk);
+	clk_put(data->clk);
+
+	if (phy)
+		usb_phy_shutdown(phy);
+
+	platform_device_del(data->pdev);
+	platform_device_put(data->pdev);
+
+	return 0;
+}
+
+static struct platform_driver ci13xxx_mxs_driver = {
+	.probe		= ci13xxx_mxs_probe,
+	.remove		= __devexit_p(ci13xxx_mxs_remove),
+	.driver		= {
+		.name	= "mxs-usb",
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(ci13xxx_mxs_driver);
+
+MODULE_ALIAS("platform:mxs-usb");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("CI13xxx MXS USB binding");
+MODULE_AUTHOR("Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>");
-- 
1.7.10

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

* [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
@ 2012-05-15  8:23     ` Marek Vasut
  0 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 UTC (permalink / raw)
  To: linux-arm-kernel

This codes connects the CI13xxx driver with the core found inside of
the Freescale i.MX244/i.MX28 CPU.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Detlev Zundel <dzu@denx.de>
CC: Dong Aisheng <b29396@freescale.com>
CC: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linux ARM kernel <linux-arm-kernel@lists.infradead.org>
Cc: linux-i2c at vger.kernel.org
CC: Sascha Hauer <s.hauer@pengutronix.de>
CC: Shawn Guo <shawn.guo@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
CC: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Wolfram Sang <w.sang@pengutronix.de>
---
 drivers/usb/chipidea/Makefile      |    4 +
 drivers/usb/chipidea/ci13xxx_mxs.c |  201 ++++++++++++++++++++++++++++++++++++
 2 files changed, 205 insertions(+)
 create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c

diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index cc34937..266d57d 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -12,3 +12,7 @@ endif
 ifneq ($(CONFIG_ARCH_MSM),)
 	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
 endif
+
+ifneq ($(CONFIG_ARCH_MXS),)
+	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
+endif
diff --git a/drivers/usb/chipidea/ci13xxx_mxs.c b/drivers/usb/chipidea/ci13xxx_mxs.c
new file mode 100644
index 0000000..fcca90b
--- /dev/null
+++ b/drivers/usb/chipidea/ci13xxx_mxs.c
@@ -0,0 +1,201 @@
+/*
+ * drivers/usb/chipidea/ci13xxx_mxs.c
+ *
+ * Freescale i.MX233/i.MX28 USB glue driver to CI13xxx core.
+ *
+ * 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/pm_runtime.h>
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+
+#include <linux/usb.h>
+#include <linux/usb/chipidea.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 <linux/usb/mxs-usb.h>
+
+#include "ci.h"
+
+static void ci13xxx_mxs_notify(struct ci13xxx *ci, unsigned event)
+{
+	uint32_t status;
+	struct usb_phy *phy;
+	struct mxs_ci13xxx_phy_notify notify;
+
+	phy = usb_get_transceiver();
+	if (!phy)
+		return;
+
+	if (event != CI13XXX_CONTROLLER_HOST_IRQ_EVENT)
+		return;
+
+	status = hw_read(ci, OP_USBSTS, ~0);
+
+	notify.discon = status & STS_PCD;
+
+	usb_phy_notify(phy, &notify);
+}
+
+static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
+	.name			= "ci13xxx_mxs",
+	.flags			= /*CI13XXX_REGS_SHARED |*/
+				  CI13XXX_REQUIRE_TRANSCEIVER |
+				  CI13XXX_PULLUP_ON_VBUS |
+				  CI13XXX_DISABLE_STREAMING,
+	.capoffset		= 0x100,
+	.notify_event		= ci13xxx_mxs_notify,
+};
+
+struct ci13xxx_mxs_data {
+	struct clk		*clk;
+	struct platform_device	*pdev;
+};
+
+static int __devinit ci13xxx_mxs_probe(struct platform_device *pdev)
+{
+	struct ci13xxx_mxs_data *data;
+	int ret;
+	struct usb_phy *phy;
+
+	phy = usb_get_transceiver();
+	if (!phy)
+		return -EPROBE_DEFER;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		dev_err(&pdev->dev, "Failed to allocate CI13xxx-MXS data!\n");
+		return -ENOMEM;
+	}
+
+	ret = usb_phy_init(phy);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to initialize PHY!\n");
+		return -EINVAL;
+	}
+
+	data->pdev = platform_device_alloc("ci_hdrc", -1);
+	if (!data->pdev) {
+		dev_err(&pdev->dev,
+			"Failed to allocate ci_hdrc platform device!\n");
+		ret = -ENOMEM;
+		goto put_phy;
+	}
+
+	/* Add DMA mask */
+	data->pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
+					sizeof(*data->pdev->dev.dma_mask),
+					GFP_KERNEL);
+	if (!data->pdev->dev.dma_mask) {
+		ret = -ENOMEM;
+		goto put_platform;
+	}
+
+	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
+	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+
+	ret = platform_device_add_resources(data->pdev, pdev->resource,
+					    pdev->num_resources);
+	if (ret) {
+		dev_err(&pdev->dev,
+			"Failed to add resources to platform device!\n");
+		goto put_platform;
+	}
+
+	ret = platform_device_add_data(data->pdev, &ci13xxx_mxs_udc_driver,
+				       sizeof(ci13xxx_mxs_udc_driver));
+	if (ret) {
+		dev_err(&pdev->dev,
+			"Failed to add platform data to platform device!\n");
+		goto put_platform;
+	}
+
+	/* 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 put_platform;
+	}
+
+	/* Prepare Host clock. */
+	ret = clk_prepare_enable(data->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to enable clock for USB Host.\n");
+		goto put_clk;
+	}
+
+	ret = platform_device_add(data->pdev);
+	if (ret)
+		goto put_clk;
+
+	dev_set_drvdata(&pdev->dev, data);
+
+	pm_runtime_no_callbacks(&pdev->dev);
+	pm_runtime_enable(&pdev->dev);
+
+	return 0;
+
+put_clk:
+	clk_put(data->clk);
+put_platform:
+	platform_device_put(data->pdev);
+put_phy:
+	usb_phy_shutdown(phy);
+	return ret;
+}
+
+static int __devexit ci13xxx_mxs_remove(struct platform_device *pdev)
+{
+	struct ci13xxx_mxs_data *data = dev_get_drvdata(&pdev->dev);
+	struct usb_phy *phy = usb_get_transceiver();
+
+	clk_disable_unprepare(data->clk);
+	clk_put(data->clk);
+
+	if (phy)
+		usb_phy_shutdown(phy);
+
+	platform_device_del(data->pdev);
+	platform_device_put(data->pdev);
+
+	return 0;
+}
+
+static struct platform_driver ci13xxx_mxs_driver = {
+	.probe		= ci13xxx_mxs_probe,
+	.remove		= __devexit_p(ci13xxx_mxs_remove),
+	.driver		= {
+		.name	= "mxs-usb",
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(ci13xxx_mxs_driver);
+
+MODULE_ALIAS("platform:mxs-usb");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("CI13xxx MXS USB binding");
+MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
-- 
1.7.10

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

* [PATCH 7/8] MXS: Add platform registration hooks for USB EHCI
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (5 preceding siblings ...)
       [not found] ` <1337070219-3630-1-git-send-email-marex-ynQEQJNshbs@public.gmane.org>
@ 2012-05-15  8:23 ` Marek Vasut
  2012-05-15  8:23 ` [PATCH 8/8] MXS: Enable USB on M28EVK Marek Vasut
  7 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.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 |   13 ++++
 5 files changed, 106 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..2477d56
--- /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/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 mxs_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("mxs-usb", data->id,
+					usb_res, ARRAY_SIZE(usb_res),
+					NULL, 0, DMA_BIT_MASK(32));
+	if (!pdev)
+		pr_err("Failed to register CI13xxx 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..e1339ed 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 mxs_usb_platform_data *pdata);
+
 /* fec */
 #include <linux/fec.h>
 struct mxs_fec_data {
-- 
1.7.10

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

* [PATCH 8/8] MXS: Enable USB on M28EVK
  2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
                   ` (6 preceding siblings ...)
  2012-05-15  8:23 ` [PATCH 7/8] MXS: Add platform registration hooks for USB EHCI Marek Vasut
@ 2012-05-15  8:23 ` Marek Vasut
  7 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-15  8:23 UTC (permalink / raw)
  To: linux-arm-kernel

Enable the first USB port on M28EVK board.

NOTE: The platform data here are not used, they should be replaced when the phy
      driver evolves.

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: Linux USB <linux-usb@vger.kernel.org>
Cc: Liu JunJie-B08287 <B08287@freescale.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shi Make-B15407 <B15407@freescale.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Subodh Nijsure <snijsure@grid-net.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 arch/arm/mach-mxs/Kconfig       |    2 ++
 arch/arm/mach-mxs/mach-m28evk.c |   19 +++++++++++++++++++
 2 files changed, 21 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..fc2dd2d 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 */
@@ -292,6 +304,11 @@ static const struct mxsfb_platform_data m28evk_mxsfb_pdata __initconst = {
 	.ld_intf_width	= STMLCDIF_18BIT,
 };
 
+static struct mxs_usb_platform_data m28_usb_data = {
+	.gpio_vbus		= M28EVK_USBOTG_ENABLE,
+	.gpio_vbus_inverted	= 1,
+};
+
 static struct at24_platform_data m28evk_eeprom = {
 	.byte_len = 16384,
 	.page_size = 32,
@@ -344,6 +361,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] 30+ messages in thread

* [PATCH 1/8] MXS: Make clk_disable return integer
  2012-05-15  8:23 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
@ 2012-05-16  0:55   ` Richard Zhao
  2012-05-16  1:01     ` Marek Vasut
  0 siblings, 1 reply; 30+ messages in thread
From: Richard Zhao @ 2012-05-16  0:55 UTC (permalink / raw)
  To: linux-arm-kernel

clk code has been re-worked to adopt common clk framework.

Thanks
Richard 

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

* [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling
  2012-05-15  8:23 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
@ 2012-05-16  0:56   ` Richard Zhao
  0 siblings, 0 replies; 30+ messages in thread
From: Richard Zhao @ 2012-05-16  0:56 UTC (permalink / raw)
  To: linux-arm-kernel

Same. It need to migrate to the new clk code?

Thanks
Richard 

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

* [PATCH 3/8] MXS: Fixup i.MX233 USB base address name
  2012-05-15  8:23 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
@ 2012-05-16  0:58   ` Richard Zhao
  2012-05-16  1:02     ` Marek Vasut
  0 siblings, 1 reply; 30+ messages in thread
From: Richard Zhao @ 2012-05-16  0:58 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, May 15, 2012 at 10:23:34AM +0200, Marek Vasut wrote:
> 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: Linux USB <linux-usb@vger.kernel.org>
> Cc: Liu JunJie-B08287 <B08287@freescale.com>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Shi Make-B15407 <B15407@freescale.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.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)
Why not migrate to DT?

Thanks
Richard
>  #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
> 
> --
> 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
> 

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

* [PATCH 4/8] MXS: Add data shared between imx-otg and EHCI driver
  2012-05-15  8:23 ` [PATCH 4/8] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
@ 2012-05-16  1:00   ` Richard Zhao
  0 siblings, 0 replies; 30+ messages in thread
From: Richard Zhao @ 2012-05-16  1:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, May 15, 2012 at 10:23:35AM +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: Linux USB <linux-usb@vger.kernel.org>
> Cc: Liu JunJie-B08287 <B08287@freescale.com>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Shi Make-B15407 <B15407@freescale.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  include/linux/usb/mxs-usb.h |   39 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 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..2678700
> --- /dev/null
> +++ b/include/linux/usb/mxs-usb.h
> @@ -0,0 +1,39 @@
> +/*
> + * 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/usb/otg.h>
> +
> +struct mxs_usb_platform_data {
> +	uint32_t		gpio_vbus;
> +	bool			gpio_vbus_inverted;
> +};
hmm..., people don't like platform data. DT?

Thanks
Richard
> +
> +struct mxs_ci13xxx_phy_notify {
> +	bool			discon;
> +};
> +
> +#endif /* __INCLUDE_LINUX_USB_MXS_USB_H__ */
> -- 
> 1.7.10
> 
> --
> 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
> 

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

* [PATCH 1/8] MXS: Make clk_disable return integer
  2012-05-16  0:55   ` Richard Zhao
@ 2012-05-16  1:01     ` Marek Vasut
  0 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-16  1:01 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Richard Zhao,

> clk code has been re-worked to adopt common clk framework.

I know, posted just for completeness (since it's not mainline yet).

> 
> Thanks
> Richard

Best regards,
Marek Vasut

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

* [PATCH 3/8] MXS: Fixup i.MX233 USB base address name
  2012-05-16  0:58   ` Richard Zhao
@ 2012-05-16  1:02     ` Marek Vasut
  0 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-16  1:02 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Richard Zhao,

> On Tue, May 15, 2012 at 10:23:34AM +0200, Marek Vasut wrote:
> > 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: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Liu JunJie-B08287 <B08287@freescale.com>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Shi Make-B15407 <B15407@freescale.com>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.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)
> 
> Why not migrate to DT?

When it's mainline, sure ... right now, I wanted to make sure these patches can 
be tested without much problems.

> 
> Thanks
> Richard
> 
> >  #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

Best regards,
Marek Vasut

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-15  8:23 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
@ 2012-05-16  3:33   ` Richard Zhao
  2012-05-16  4:30     ` Marek Vasut
  2012-05-16 10:35   ` Peter Chen
  1 sibling, 1 reply; 30+ messages in thread
From: Richard Zhao @ 2012-05-16  3:33 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Marek,

On Tue, May 15, 2012 at 10:23:36AM +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: Linux USB <linux-usb@vger.kernel.org>
> Cc: Liu JunJie-B08287 <B08287@freescale.com>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Shi Make-B15407 <B15407@freescale.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Subodh Nijsure <snijsure@grid-net.com>
> Cc: Wolfgang Denk <wd@denx.de>
> ---
>  drivers/usb/otg/Kconfig   |   10 ++
>  drivers/usb/otg/Makefile  |    1 +
>  drivers/usb/otg/mxs-phy.c |  313 +++++++++++++++++++++++++++++++++++++++++++++
imx is more common.

>  3 files changed, 324 insertions(+)
>  create mode 100644 drivers/usb/otg/mxs-phy.c
> 
> diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> index 5c87db0..bc7625e 100644
> --- a/drivers/usb/otg/Kconfig
> +++ b/drivers/usb/otg/Kconfig
> @@ -116,6 +116,16 @@ 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
> +	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 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..eb658ca
> --- /dev/null
> +++ b/drivers/usb/otg/mxs-phy.c
> @@ -0,0 +1,313 @@
> +/*
> + * 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.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>
> +#include <mach/mx28.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 mxs_usb_phy {
> +	struct usb_phy		phy;
> +	struct usb_otg		otg;
> +	struct clk		*clk;
> +	bool			discon;
> +};
> +
> +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);
I find mxs_reset_block is defined in platform code. It breaks multi-soc
in one image.
> +
> +	/* 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;
> +
> +	/* Enable IRQ sources. */
> +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
It's a little different from my steps. I copied it from fsl kernel.
Peter, maybe you can comment?
> +
> +	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;
> +
> +	/* Disable IRQ sources. */
> +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> +
> +	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 mxs_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
> +{
> +	return 0;
> +}
> +
> +static int mxs_otg_set_peripheral(struct usb_otg *otg, struct usb_gadget *gg)
> +{
> +	return 0;
> +}
> +
> +static int mxs_otg_set_vbus(struct usb_otg *otg, bool enabled)
> +{
> +	return 0;
> +}
> +
> +static int mxs_usb_phy_notify(struct usb_phy *x, void *data)
> +{
> +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> +	struct mxs_ci13xxx_phy_notify *notify = data;
> +
> +	if (notify->discon == phy->discon)
> +		return 0;
> +
> +	phy->discon = notify->discon;
> +
> +	if (notify->discon) {
> +		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);
> +	}
I'm also thinking how to add the hack. Great work.
and, maybe it can be PHY_EVENT_CONNECT and PHY_EVENT_DISCONNECT rather
not void* ? It makes loose binding of phy and usb driver.
> +
> +	return 0;
> +}
> +
> +static int __devinit mxs_phy_probe(struct platform_device *pdev)
> +{
> +	struct mxs_usb_phy *phy;
> +	struct resource *mem_res;
> +	void *retp;
> +	int ret;
> +	struct usb_otg *otg;
> +
> +	/* 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");
> +		return -ENOMEM;
> +	}
> +
> +	/* 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");
> +		return -ENODEV;
> +	}
> +
> +	/* 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");
> +		return -EBUSY;
> +	}
> +
> +	/* Map the memory region for USB PHY. */
> +	phy->phy.io_priv = devm_ioremap(&pdev->dev, mem_res->start,
> +				resource_size(mem_res));
devm_request_and_ioremap ?

> +	if (!phy->phy.io_priv) {
> +		dev_err(&pdev->dev, "Memory mapping of USB PHY failed!\n");
> +		return -EFAULT;
> +	}
> +
> +	/* Claim the PHY clock. */
> +	phy->clk = clk_get(&pdev->dev, "phy");
devm_clk_get ?
> +	if (!phy->clk) {
> +		dev_err(&pdev->dev, "Failed to claim clock for USB PHY!\n");
> +		return PTR_ERR(phy->clk);
> +	}
> +
> +	/* Prepare PHY clock. */
> +	ret = clk_prepare(phy->clk);
Why not put it in phy init? phy init has to be atomic?
> +	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.notify		= mxs_usb_phy_notify;
> +	phy->phy.state		= OTG_STATE_UNDEFINED;
> +
> +	otg			= &phy->otg;
> +	phy->phy.otg		= otg;
> +
> +	otg->phy		= &phy->phy;
> +	otg->set_vbus		= mxs_otg_set_vbus;
> +	otg->set_host		= mxs_otg_set_host;
> +	otg->set_peripheral	= mxs_otg_set_peripheral;
> +
> +	platform_set_drvdata(pdev, phy);
> +
> +	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
> +
> +	/* Register the transceiver with kernel. */
> +	ret = usb_set_transceiver(&phy->phy);
In my code, I don't plan to call it for host phy, to achieve multi-phy
support.

> +	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);
> +	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);
postcor_initcall? It make possible hack in machine init code.

Thanks
Richard
> +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
> 
> --
> 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
> 

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-16  3:33   ` Richard Zhao
@ 2012-05-16  4:30     ` Marek Vasut
  2012-05-16  5:06       ` Richard Zhao
  0 siblings, 1 reply; 30+ messages in thread
From: Marek Vasut @ 2012-05-16  4:30 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Richard Zhao,

> Hi Marek,
> 
> On Tue, May 15, 2012 at 10:23:36AM +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: Linux USB <linux-usb@vger.kernel.org>
> > Cc: Liu JunJie-B08287 <B08287@freescale.com>
> > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > Cc: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Shi Make-B15407 <B15407@freescale.com>
> > Cc: Stefano Babic <sbabic@denx.de>
> > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > Cc: Wolfgang Denk <wd@denx.de>
> > ---
> > 
> >  drivers/usb/otg/Kconfig   |   10 ++
> >  drivers/usb/otg/Makefile  |    1 +
> >  drivers/usb/otg/mxs-phy.c |  313
> >  +++++++++++++++++++++++++++++++++++++++++++++
> 
> imx is more common.

But is this really present also in the mx3/mx5 chips ? Or is this only 
mx233/mx28/mx6q specific ?

> >  3 files changed, 324 insertions(+)
> >  create mode 100644 drivers/usb/otg/mxs-phy.c
> > 
> > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > index 5c87db0..bc7625e 100644
> > --- a/drivers/usb/otg/Kconfig
> > +++ b/drivers/usb/otg/Kconfig
> > @@ -116,6 +116,16 @@ 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
> > +	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 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..eb658ca
> > --- /dev/null
> > +++ b/drivers/usb/otg/mxs-phy.c
> > @@ -0,0 +1,313 @@
> > +/*
> > + * 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.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>
> > +#include <mach/mx28.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 mxs_usb_phy {
> > +	struct usb_phy		phy;
> > +	struct usb_otg		otg;
> > +	struct clk		*clk;
> > +	bool			discon;
> > +};
> > +
> > +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);
> 
> I find mxs_reset_block is defined in platform code. It breaks multi-soc
> in one image.

This is a matter to change I believe ... with the SMTP-device stuff from 
Wolfram. Check my comment on your PHY patch.
> 
> > +
> > +	/* 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;
> > +
> > +	/* Enable IRQ sources. */
> > +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> > +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> 
> It's a little different from my steps. I copied it from fsl kernel.
> Peter, maybe you can comment?

You need to enable these to get wakeup interrupts from the PHY.

> > +
> > +	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;
> > +
> > +	/* Disable IRQ sources. */
> > +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> > +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> > +
> > +	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 mxs_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
> > +{
> > +	return 0;
> > +}
> > +
> > +static int mxs_otg_set_peripheral(struct usb_otg *otg, struct usb_gadget
> > *gg) +{
> > +	return 0;
> > +}
> > +
> > +static int mxs_otg_set_vbus(struct usb_otg *otg, bool enabled)
> > +{
> > +	return 0;
> > +}
> > +
> > +static int mxs_usb_phy_notify(struct usb_phy *x, void *data)
> > +{
> > +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> > +	struct mxs_ci13xxx_phy_notify *notify = data;
> > +
> > +	if (notify->discon == phy->discon)
> > +		return 0;
> > +
> > +	phy->discon = notify->discon;
> > +
> > +	if (notify->discon) {
> > +		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);
> > +	}
> 
> I'm also thinking how to add the hack. Great work.
> and, maybe it can be PHY_EVENT_CONNECT and PHY_EVENT_DISCONNECT rather
> not void* ? It makes loose binding of phy and usb driver.

Correct, we discussed this with Greg and Alan (CCed)

> > +
> > +	return 0;
> > +}
> > +
> > +static int __devinit mxs_phy_probe(struct platform_device *pdev)
> > +{
> > +	struct mxs_usb_phy *phy;
> > +	struct resource *mem_res;
> > +	void *retp;
> > +	int ret;
> > +	struct usb_otg *otg;
> > +
> > +	/* 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");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	/* 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");
> > +		return -ENODEV;
> > +	}
> > +
> > +	/* 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");
> > +		return -EBUSY;
> > +	}
> > +
> > +	/* Map the memory region for USB PHY. */
> > +	phy->phy.io_priv = devm_ioremap(&pdev->dev, mem_res->start,
> > +				resource_size(mem_res));
> 
> devm_request_and_ioremap ?

Yes, should be like that. But now, we need to figure out what driver to use and 
how to compose the final thingie from your and mine code.

> > +	if (!phy->phy.io_priv) {
> > +		dev_err(&pdev->dev, "Memory mapping of USB PHY failed!\n");
> > +		return -EFAULT;
> > +	}
> > +
> > +	/* Claim the PHY clock. */
> > +	phy->clk = clk_get(&pdev->dev, "phy");
> 
> devm_clk_get ?

yes, thanks!

> > +	if (!phy->clk) {
> > +		dev_err(&pdev->dev, "Failed to claim clock for USB PHY!\n");
> > +		return PTR_ERR(phy->clk);
> > +	}
> > +
> > +	/* Prepare PHY clock. */
> > +	ret = clk_prepare(phy->clk);
> 
> Why not put it in phy init? phy init has to be atomic?

I think moving this to phy init would be OK, yes.

> > +	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.notify		= mxs_usb_phy_notify;
> > +	phy->phy.state		= OTG_STATE_UNDEFINED;
> > +
> > +	otg			= &phy->otg;
> > +	phy->phy.otg		= otg;
> > +
> > +	otg->phy		= &phy->phy;
> > +	otg->set_vbus		= mxs_otg_set_vbus;
> > +	otg->set_host		= mxs_otg_set_host;
> > +	otg->set_peripheral	= mxs_otg_set_peripheral;
> > +
> > +	platform_set_drvdata(pdev, phy);
> > +
> > +	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
> > +
> > +	/* Register the transceiver with kernel. */
> > +	ret = usb_set_transceiver(&phy->phy);
> 
> In my code, I don't plan to call it for host phy, to achieve multi-phy
> support.

We're not sure how the multi-phy support will look like at all yet. I think 
Peter and Filipe are in a tough dispute on that.

> > +	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);
> > +	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);
> 
> postcor_initcall? It make possible hack in machine init code.

Good idea.

Thanks for the review, now how should we put these codes of ours together? Will 
you integrate my code into yours or shall I do it the other way around?

Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg, maybe we can 
also recycle some my mxs binding code for ci13xxx in some way or another, as it 
has MXS specific hacks in it. I think the ci13xxx binding for the rest of i.MX 
(aka mxc) will looks different, won't it? But either way, my mxs/ci13xxx binding 
glue will have to wait until we finish negotiating the phy_notify stuff with 
Greg.

> Thanks
> Richard
> 
> > +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");

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-16  4:30     ` Marek Vasut
@ 2012-05-16  5:06       ` Richard Zhao
  2012-05-16  7:18         ` Richard Zhao
  2012-05-16 13:35         ` Marek Vasut
  0 siblings, 2 replies; 30+ messages in thread
From: Richard Zhao @ 2012-05-16  5:06 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, May 16, 2012 at 06:30:14AM +0200, Marek Vasut wrote:
> Dear Richard Zhao,
> 
> > Hi Marek,
> > 
> > On Tue, May 15, 2012 at 10:23:36AM +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: Linux USB <linux-usb@vger.kernel.org>
> > > Cc: Liu JunJie-B08287 <B08287@freescale.com>
> > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > Cc: Shi Make-B15407 <B15407@freescale.com>
> > > Cc: Stefano Babic <sbabic@denx.de>
> > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > Cc: Wolfgang Denk <wd@denx.de>
> > > ---
> > > 
> > >  drivers/usb/otg/Kconfig   |   10 ++
> > >  drivers/usb/otg/Makefile  |    1 +
> > >  drivers/usb/otg/mxs-phy.c |  313
> > >  +++++++++++++++++++++++++++++++++++++++++++++
> > 
> > imx is more common.
> 
> But is this really present also in the mx3/mx5 chips ? Or is this only 
> mx233/mx28/mx6q specific ?
I don't mean phy only, but all naming in the series. mx23/28 (mxs) are
still imx.
> 
> > >  3 files changed, 324 insertions(+)
> > >  create mode 100644 drivers/usb/otg/mxs-phy.c
> > > 
> > > diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
> > > index 5c87db0..bc7625e 100644
> > > --- a/drivers/usb/otg/Kconfig
> > > +++ b/drivers/usb/otg/Kconfig
> > > @@ -116,6 +116,16 @@ 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
> > > +	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 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..eb658ca
> > > --- /dev/null
> > > +++ b/drivers/usb/otg/mxs-phy.c
> > > @@ -0,0 +1,313 @@
> > > +/*
> > > + * 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.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>
> > > +#include <mach/mx28.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 mxs_usb_phy {
> > > +	struct usb_phy		phy;
> > > +	struct usb_otg		otg;
> > > +	struct clk		*clk;
> > > +	bool			discon;
> > > +};
> > > +
> > > +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);
> > 
> > I find mxs_reset_block is defined in platform code. It breaks multi-soc
> > in one image.
> 
> This is a matter to change I believe ... with the SMTP-device stuff from 
> Wolfram. Check my comment on your PHY patch.
> > 
> > > +
> > > +	/* 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;
> > > +
> > > +	/* Enable IRQ sources. */
> > > +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> > > +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> > 
> > It's a little different from my steps. I copied it from fsl kernel.
> > Peter, maybe you can comment?
> 
> You need to enable these to get wakeup interrupts from the PHY.
I didn't consider or test wakeup yet.
> 
> > > +
> > > +	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;
> > > +
> > > +	/* Disable IRQ sources. */
> > > +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> > > +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> > > +
> > > +	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 mxs_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
> > > +{
> > > +	return 0;
> > > +}
> > > +
> > > +static int mxs_otg_set_peripheral(struct usb_otg *otg, struct usb_gadget
> > > *gg) +{
> > > +	return 0;
> > > +}
> > > +
> > > +static int mxs_otg_set_vbus(struct usb_otg *otg, bool enabled)
> > > +{
> > > +	return 0;
> > > +}
> > > +
> > > +static int mxs_usb_phy_notify(struct usb_phy *x, void *data)
> > > +{
> > > +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> > > +	struct mxs_ci13xxx_phy_notify *notify = data;
> > > +
> > > +	if (notify->discon == phy->discon)
> > > +		return 0;
> > > +
> > > +	phy->discon = notify->discon;
> > > +
> > > +	if (notify->discon) {
> > > +		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);
> > > +	}
> > 
> > I'm also thinking how to add the hack. Great work.
> > and, maybe it can be PHY_EVENT_CONNECT and PHY_EVENT_DISCONNECT rather
> > not void* ? It makes loose binding of phy and usb driver.
> 
> Correct, we discussed this with Greg and Alan (CCed)
> 
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static int __devinit mxs_phy_probe(struct platform_device *pdev)
> > > +{
> > > +	struct mxs_usb_phy *phy;
> > > +	struct resource *mem_res;
> > > +	void *retp;
> > > +	int ret;
> > > +	struct usb_otg *otg;
> > > +
> > > +	/* 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");
> > > +		return -ENOMEM;
> > > +	}
> > > +
> > > +	/* 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");
> > > +		return -ENODEV;
> > > +	}
> > > +
> > > +	/* 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");
> > > +		return -EBUSY;
> > > +	}
> > > +
> > > +	/* Map the memory region for USB PHY. */
> > > +	phy->phy.io_priv = devm_ioremap(&pdev->dev, mem_res->start,
> > > +				resource_size(mem_res));
> > 
> > devm_request_and_ioremap ?
> 
> Yes, should be like that. But now, we need to figure out what driver to use and 
> how to compose the final thingie from your and mine code.
It looks like, for ci13xxx driver binding or phy driver, we don't have
much difference. It's how co-work with platform code.
> 
> > > +	if (!phy->phy.io_priv) {
> > > +		dev_err(&pdev->dev, "Memory mapping of USB PHY failed!\n");
> > > +		return -EFAULT;
> > > +	}
> > > +
> > > +	/* Claim the PHY clock. */
> > > +	phy->clk = clk_get(&pdev->dev, "phy");
> > 
> > devm_clk_get ?
> 
> yes, thanks!
> 
> > > +	if (!phy->clk) {
> > > +		dev_err(&pdev->dev, "Failed to claim clock for USB PHY!\n");
> > > +		return PTR_ERR(phy->clk);
> > > +	}
> > > +
> > > +	/* Prepare PHY clock. */
> > > +	ret = clk_prepare(phy->clk);
> > 
> > Why not put it in phy init? phy init has to be atomic?
> 
> I think moving this to phy init would be OK, yes.
> 
> > > +	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.notify		= mxs_usb_phy_notify;
> > > +	phy->phy.state		= OTG_STATE_UNDEFINED;
> > > +
> > > +	otg			= &phy->otg;
> > > +	phy->phy.otg		= otg;
> > > +
> > > +	otg->phy		= &phy->phy;
> > > +	otg->set_vbus		= mxs_otg_set_vbus;
> > > +	otg->set_host		= mxs_otg_set_host;
> > > +	otg->set_peripheral	= mxs_otg_set_peripheral;
> > > +
> > > +	platform_set_drvdata(pdev, phy);
> > > +
> > > +	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
> > > +
> > > +	/* Register the transceiver with kernel. */
> > > +	ret = usb_set_transceiver(&phy->phy);
> > 
> > In my code, I don't plan to call it for host phy, to achieve multi-phy
> > support.
> 
> We're not sure how the multi-phy support will look like at all yet. I think 
> Peter and Filipe are in a tough dispute on that.
Using DT phandler, my code can connect phy and usb drivers. We might
not have to pend on phy lib.
Sure, somehow it cause dependency between phy driver and ci13xxx_imx
driver. phy driver must set usb_phy as  drv data and ci13xxx_imx use
it. It's one reason why I didn't put it to otg folder. The other reason
is, otg folder may not be a good place to hold phy. Maybe drivers/usb/phy
will be better?
> 
> > > +	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);
> > > +	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);
> > 
> > postcor_initcall? It make possible hack in machine init code.
> 
> Good idea.
> 
> Thanks for the review, now how should we put these codes of ours together? Will 
> you integrate my code into yours or shall I do it the other way around?
either way works for me. but I hope it support imx6 and use DT bindings
and other things maybe in next branch.
> 
> Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,
I explained it above.
> maybe we can 
> also recycle some my mxs binding code for ci13xxx in some way or another, as it 
> has MXS specific hacks in it.
what hack do you mean?
> I think the ci13xxx binding for the rest of i.MX 
> (aka mxc) will looks different, won't it? But either way, my mxs/ci13xxx binding 
> glue will have to wait until we finish negotiating the phy_notify stuff with 
> Greg.
Sure. At the same time, we may create new version patch and see response.

Thanks
Richard
> 
> > Thanks
> > Richard
> > 
> > > +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");
> 

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-16  5:06       ` Richard Zhao
@ 2012-05-16  7:18         ` Richard Zhao
  2012-05-16 13:36           ` Marek Vasut
  2012-05-16 13:35         ` Marek Vasut
  1 sibling, 1 reply; 30+ messages in thread
From: Richard Zhao @ 2012-05-16  7:18 UTC (permalink / raw)
  To: linux-arm-kernel

> > Thanks for the review, now how should we put these codes of ours together? Will 
> > you integrate my code into yours or shall I do it the other way around?
> either way works for me. but I hope it support imx6 and use DT bindings
> and other things maybe in next branch.
Since, anyway we have to use DT, do you mind if I pick your patch and
add mx28 DT too, and send you for further tuning?

Thanks
Richard
> > 
> > Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,
> I explained it above.
> > maybe we can 
> > also recycle some my mxs binding code for ci13xxx in some way or another, as it 
> > has MXS specific hacks in it.
> what hack do you mean?
> > I think the ci13xxx binding for the rest of i.MX 
> > (aka mxc) will looks different, won't it? But either way, my mxs/ci13xxx binding 
> > glue will have to wait until we finish negotiating the phy_notify stuff with 
> > Greg.
> Sure. At the same time, we may create new version patch and see response.
> 
> Thanks
> Richard
> > 
> > > Thanks
> > > Richard
> > > 
> > > > +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");
> > 
> 
> --
> 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
> 

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

* Re: [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
  2012-05-15  8:23     ` Marek Vasut
@ 2012-05-16  8:36         ` Felipe Balbi
  -1 siblings, 0 replies; 30+ messages in thread
From: Felipe Balbi @ 2012-05-16  8:36 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Alan Stern,
	Detlev Zundel, Dong Aisheng, Fabio Estevam, Felipe Balbi,
	Greg Kroah-Hartman, linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	Sascha Hauer, Shawn Guo, Stefano Babic, Uwe Kleine-König,
	Wolfgang Denk, Wolfram Sang

[-- Attachment #1: Type: text/plain, Size: 5679 bytes --]

On Tue, May 15, 2012 at 10:23:37AM +0200, Marek Vasut wrote:
> This codes connects the CI13xxx driver with the core found inside of
> the Freescale i.MX244/i.MX28 CPU.
> 
> Signed-off-by: Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
> Cc: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
> Cc: Detlev Zundel <dzu-ynQEQJNshbs@public.gmane.org>
> CC: Dong Aisheng <b29396-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> CC: Fabio Estevam <fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> Cc: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
> Cc: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
> Cc: Linux ARM kernel <linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
> Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> CC: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> CC: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> Cc: Stefano Babic <sbabic-ynQEQJNshbs@public.gmane.org>
> CC: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> Cc: Wolfgang Denk <wd-ynQEQJNshbs@public.gmane.org>
> Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> ---
>  drivers/usb/chipidea/Makefile      |    4 +
>  drivers/usb/chipidea/ci13xxx_mxs.c |  201 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 205 insertions(+)
>  create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c
> 
> diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
> index cc34937..266d57d 100644
> --- a/drivers/usb/chipidea/Makefile
> +++ b/drivers/usb/chipidea/Makefile
> @@ -12,3 +12,7 @@ endif
>  ifneq ($(CONFIG_ARCH_MSM),)
>  	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
>  endif
> +
> +ifneq ($(CONFIG_ARCH_MXS),)
> +	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
> +endif

NAK... let it compile everywhere.

> diff --git a/drivers/usb/chipidea/ci13xxx_mxs.c b/drivers/usb/chipidea/ci13xxx_mxs.c
> new file mode 100644
> index 0000000..fcca90b
> --- /dev/null
> +++ b/drivers/usb/chipidea/ci13xxx_mxs.c
> @@ -0,0 +1,201 @@
> +/*
> + * drivers/usb/chipidea/ci13xxx_mxs.c
> + *
> + * Freescale i.MX233/i.MX28 USB glue driver to CI13xxx core.
> + *
> + * Copyright (C) 2012 Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
> + * 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/pm_runtime.h>
> +#include <linux/clk.h>
> +#include <linux/dma-mapping.h>
> +
> +#include <linux/usb.h>
> +#include <linux/usb/chipidea.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 <linux/usb/mxs-usb.h>
> +
> +#include "ci.h"
> +
> +static void ci13xxx_mxs_notify(struct ci13xxx *ci, unsigned event)
> +{
> +	uint32_t status;
> +	struct usb_phy *phy;
> +	struct mxs_ci13xxx_phy_notify notify;
> +
> +	phy = usb_get_transceiver();
> +	if (!phy)
> +		return;
> +
> +	if (event != CI13XXX_CONTROLLER_HOST_IRQ_EVENT)
> +		return;
> +
> +	status = hw_read(ci, OP_USBSTS, ~0);
> +
> +	notify.discon = status & STS_PCD;
> +
> +	usb_phy_notify(phy, &notify);
> +}
> +
> +static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
> +	.name			= "ci13xxx_mxs",
> +	.flags			= /*CI13XXX_REGS_SHARED |*/
> +				  CI13XXX_REQUIRE_TRANSCEIVER |
> +				  CI13XXX_PULLUP_ON_VBUS |
> +				  CI13XXX_DISABLE_STREAMING,
> +	.capoffset		= 0x100,
> +	.notify_event		= ci13xxx_mxs_notify,
> +};
> +
> +struct ci13xxx_mxs_data {
> +	struct clk		*clk;
> +	struct platform_device	*pdev;
> +};
> +
> +static int __devinit ci13xxx_mxs_probe(struct platform_device *pdev)
> +{
> +	struct ci13xxx_mxs_data *data;
> +	int ret;
> +	struct usb_phy *phy;
> +
> +	phy = usb_get_transceiver();
> +	if (!phy)
> +		return -EPROBE_DEFER;
> +
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data) {
> +		dev_err(&pdev->dev, "Failed to allocate CI13xxx-MXS data!\n");
> +		return -ENOMEM;
> +	}
> +
> +	ret = usb_phy_init(phy);
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to initialize PHY!\n");
> +		return -EINVAL;
> +	}
> +
> +	data->pdev = platform_device_alloc("ci_hdrc", -1);
> +	if (!data->pdev) {
> +		dev_err(&pdev->dev,
> +			"Failed to allocate ci_hdrc platform device!\n");
> +		ret = -ENOMEM;
> +		goto put_phy;
> +	}
> +
> +	/* Add DMA mask */
> +	data->pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
> +					sizeof(*data->pdev->dev.dma_mask),
> +					GFP_KERNEL);
> +	if (!data->pdev->dev.dma_mask) {
> +		ret = -ENOMEM;
> +		goto put_platform;
> +	}
> +
> +	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
> +	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);

why don't you just point to the parent's ?

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
@ 2012-05-16  8:36         ` Felipe Balbi
  0 siblings, 0 replies; 30+ messages in thread
From: Felipe Balbi @ 2012-05-16  8:36 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, May 15, 2012 at 10:23:37AM +0200, Marek Vasut wrote:
> This codes connects the CI13xxx driver with the core found inside of
> the Freescale i.MX244/i.MX28 CPU.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Alan Stern <stern@rowland.harvard.edu>
> Cc: Detlev Zundel <dzu@denx.de>
> CC: Dong Aisheng <b29396@freescale.com>
> CC: Fabio Estevam <fabio.estevam@freescale.com>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Linux ARM kernel <linux-arm-kernel@lists.infradead.org>
> Cc: linux-i2c at vger.kernel.org
> CC: Sascha Hauer <s.hauer@pengutronix.de>
> CC: Shawn Guo <shawn.guo@linaro.org>
> Cc: Stefano Babic <sbabic@denx.de>
> CC: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> Cc: Wolfgang Denk <wd@denx.de>
> Cc: Wolfram Sang <w.sang@pengutronix.de>
> ---
>  drivers/usb/chipidea/Makefile      |    4 +
>  drivers/usb/chipidea/ci13xxx_mxs.c |  201 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 205 insertions(+)
>  create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c
> 
> diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
> index cc34937..266d57d 100644
> --- a/drivers/usb/chipidea/Makefile
> +++ b/drivers/usb/chipidea/Makefile
> @@ -12,3 +12,7 @@ endif
>  ifneq ($(CONFIG_ARCH_MSM),)
>  	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
>  endif
> +
> +ifneq ($(CONFIG_ARCH_MXS),)
> +	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
> +endif

NAK... let it compile everywhere.

> diff --git a/drivers/usb/chipidea/ci13xxx_mxs.c b/drivers/usb/chipidea/ci13xxx_mxs.c
> new file mode 100644
> index 0000000..fcca90b
> --- /dev/null
> +++ b/drivers/usb/chipidea/ci13xxx_mxs.c
> @@ -0,0 +1,201 @@
> +/*
> + * drivers/usb/chipidea/ci13xxx_mxs.c
> + *
> + * Freescale i.MX233/i.MX28 USB glue driver to CI13xxx core.
> + *
> + * 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/pm_runtime.h>
> +#include <linux/clk.h>
> +#include <linux/dma-mapping.h>
> +
> +#include <linux/usb.h>
> +#include <linux/usb/chipidea.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 <linux/usb/mxs-usb.h>
> +
> +#include "ci.h"
> +
> +static void ci13xxx_mxs_notify(struct ci13xxx *ci, unsigned event)
> +{
> +	uint32_t status;
> +	struct usb_phy *phy;
> +	struct mxs_ci13xxx_phy_notify notify;
> +
> +	phy = usb_get_transceiver();
> +	if (!phy)
> +		return;
> +
> +	if (event != CI13XXX_CONTROLLER_HOST_IRQ_EVENT)
> +		return;
> +
> +	status = hw_read(ci, OP_USBSTS, ~0);
> +
> +	notify.discon = status & STS_PCD;
> +
> +	usb_phy_notify(phy, &notify);
> +}
> +
> +static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
> +	.name			= "ci13xxx_mxs",
> +	.flags			= /*CI13XXX_REGS_SHARED |*/
> +				  CI13XXX_REQUIRE_TRANSCEIVER |
> +				  CI13XXX_PULLUP_ON_VBUS |
> +				  CI13XXX_DISABLE_STREAMING,
> +	.capoffset		= 0x100,
> +	.notify_event		= ci13xxx_mxs_notify,
> +};
> +
> +struct ci13xxx_mxs_data {
> +	struct clk		*clk;
> +	struct platform_device	*pdev;
> +};
> +
> +static int __devinit ci13xxx_mxs_probe(struct platform_device *pdev)
> +{
> +	struct ci13xxx_mxs_data *data;
> +	int ret;
> +	struct usb_phy *phy;
> +
> +	phy = usb_get_transceiver();
> +	if (!phy)
> +		return -EPROBE_DEFER;
> +
> +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> +	if (!data) {
> +		dev_err(&pdev->dev, "Failed to allocate CI13xxx-MXS data!\n");
> +		return -ENOMEM;
> +	}
> +
> +	ret = usb_phy_init(phy);
> +	if (ret) {
> +		dev_err(&pdev->dev, "Failed to initialize PHY!\n");
> +		return -EINVAL;
> +	}
> +
> +	data->pdev = platform_device_alloc("ci_hdrc", -1);
> +	if (!data->pdev) {
> +		dev_err(&pdev->dev,
> +			"Failed to allocate ci_hdrc platform device!\n");
> +		ret = -ENOMEM;
> +		goto put_phy;
> +	}
> +
> +	/* Add DMA mask */
> +	data->pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
> +					sizeof(*data->pdev->dev.dma_mask),
> +					GFP_KERNEL);
> +	if (!data->pdev->dev.dma_mask) {
> +		ret = -ENOMEM;
> +		goto put_platform;
> +	}
> +
> +	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
> +	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);

why don't you just point to the parent's ?

-- 
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120516/22ab45e7/attachment.sig>

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-15  8:23 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
  2012-05-16  3:33   ` Richard Zhao
@ 2012-05-16 10:35   ` Peter Chen
  2012-05-16 13:37     ` Marek Vasut
  1 sibling, 1 reply; 30+ messages in thread
From: Peter Chen @ 2012-05-16 10:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, May 15, 2012 at 10:23:36AM +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.
Please add i.mx6q .
> 
> +config USB_MXS_PHY
> +	tristate "Freescale i.MX28 USB PHY support"
> +	select USB_OTG_UTILS
> +	select USB_IMX_COMPOSITE
Seems you will not use imx_otg.c with chipidea framework.
> + *
> + * Freescale i.MX28 USB PHY driver.
use mxs
> + *
> +
> +	/* Enable FS/LS compatibility and wakeup IRQs. */
> +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
> +		BM_USBPHY_CTRL_ENIRQWAKEUP;
> +
> +	/* Enable IRQ sources. */
> +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
Please forget wakeup function currently, as it will make things more
complicated.
> +
> +	writel(val, x->io_priv + HW_USBPHY_CTRL_SET);
> +
> +	return 0;
> +}
> +
> +	/* Disable FS/LS compatibility and wakeup IRQs. */
> +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
> +		BM_USBPHY_CTRL_ENIRQWAKEUP;
> +
> +	/* Disable IRQ sources. */
> +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> +
The same with above
> +
> +MODULE_ALIAS("platform:mxs-usb-phy");
> +MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
> +MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
mxs
> +MODULE_LICENSE("GPL");
> -- 
> 1.7.10
> 
> 

-- 

Best Regards,
Peter Chen

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-16  5:06       ` Richard Zhao
  2012-05-16  7:18         ` Richard Zhao
@ 2012-05-16 13:35         ` Marek Vasut
  1 sibling, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-16 13:35 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Richard Zhao,

> On Wed, May 16, 2012 at 06:30:14AM +0200, Marek Vasut wrote:
> > Dear Richard Zhao,
> > 
> > > Hi Marek,
> > > 
> > > On Tue, May 15, 2012 at 10:23:36AM +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: Linux USB <linux-usb@vger.kernel.org>
> > > > Cc: Liu JunJie-B08287 <B08287@freescale.com>
> > > > Cc: Sascha Hauer <s.hauer@pengutronix.de>
> > > > Cc: Shawn Guo <shawn.guo@linaro.org>
> > > > Cc: Shi Make-B15407 <B15407@freescale.com>
> > > > Cc: Stefano Babic <sbabic@denx.de>
> > > > Cc: Subodh Nijsure <snijsure@grid-net.com>
> > > > Cc: Wolfgang Denk <wd@denx.de>
> > > > ---
> > > > 
> > > >  drivers/usb/otg/Kconfig   |   10 ++
> > > >  drivers/usb/otg/Makefile  |    1 +
> > > >  drivers/usb/otg/mxs-phy.c |  313
> > > >  +++++++++++++++++++++++++++++++++++++++++++++
> > > 
> > > imx is more common.
> > 
> > But is this really present also in the mx3/mx5 chips ? Or is this only
> > mx233/mx28/mx6q specific ?
> 
> I don't mean phy only, but all naming in the series. mx23/28 (mxs) are
> still imx.

Sure, but mixing sigmatel stuff with mxc stuff is quite confusing.

[...]

> > > > +	otg->phy		= &phy->phy;
> > > > +	otg->set_vbus		= mxs_otg_set_vbus;
> > > > +	otg->set_host		= mxs_otg_set_host;
> > > > +	otg->set_peripheral	= mxs_otg_set_peripheral;
> > > > +
> > > > +	platform_set_drvdata(pdev, phy);
> > > > +
> > > > +	ATOMIC_INIT_NOTIFIER_HEAD(&phy->phy.notifier);
> > > > +
> > > > +	/* Register the transceiver with kernel. */
> > > > +	ret = usb_set_transceiver(&phy->phy);
> > > 
> > > In my code, I don't plan to call it for host phy, to achieve multi-phy
> > > support.
> > 
> > We're not sure how the multi-phy support will look like at all yet. I
> > think Peter and Filipe are in a tough dispute on that.
> 
> Using DT phandler, my code can connect phy and usb drivers. We might
> not have to pend on phy lib.
> Sure, somehow it cause dependency between phy driver and ci13xxx_imx
> driver. phy driver must set usb_phy as  drv data and ci13xxx_imx use
> it. It's one reason why I didn't put it to otg folder. The other reason
> is, otg folder may not be a good place to hold phy. Maybe drivers/usb/phy
> will be better?

That's exactly where I'd like to know Felipe's opinion. I don't think it's a 
good idea to create the dependency between this driver any PHY in any way. It 
kind-of defies the purpose of phy lib.

[...]

> > > > +static void __exit mxs_phy_exit(void)
> > > > +{
> > > > +	platform_driver_unregister(&mxs_phy_driver);
> > > > +}
> > > > +
> > > > +arch_initcall(mxs_phy_init);
> > > 
> > > postcor_initcall? It make possible hack in machine init code.
> > 
> > Good idea.
> > 
> > Thanks for the review, now how should we put these codes of ours
> > together? Will you integrate my code into yours or shall I do it the
> > other way around?
> 
> either way works for me. but I hope it support imx6 and use DT bindings
> and other things maybe in next branch.

Fine with me, I asked in the other patch where I can get the mx28 DT-enabled 
tree please?

> > Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,
> 
> I explained it above.
> 
> > maybe we can
> > also recycle some my mxs binding code for ci13xxx in some way or another,
> > as it has MXS specific hacks in it.
> 
> what hack do you mean?

The .notify_event stuff in my ci13xxx_mxs, where it reads the PCD bit.

> > I think the ci13xxx binding for the rest of i.MX
> > (aka mxc) will looks different, won't it? But either way, my mxs/ci13xxx
> > binding glue will have to wait until we finish negotiating the
> > phy_notify stuff with Greg.
> 
> Sure. At the same time, we may create new version patch and see response.

But if this ci13xxx_imx will only support mxs at first, it is kinda confusing.

> Thanks
> Richard
> 
> > > Thanks
> > > Richard
> > > 
> > > > +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");

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

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-16  7:18         ` Richard Zhao
@ 2012-05-16 13:36           ` Marek Vasut
  0 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-16 13:36 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Richard Zhao,

> > > Thanks for the review, now how should we put these codes of ours
> > > together? Will you integrate my code into yours or shall I do it the
> > > other way around?
> > 
> > either way works for me. but I hope it support imx6 and use DT bindings
> > and other things maybe in next branch.
> 
> Since, anyway we have to use DT, do you mind if I pick your patch and
> add mx28 DT too, and send you for further tuning?

I don't mind at all, go ahead. Thanks for that :)

> Thanks
> Richard
> 
> > > Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,
> > 
> > I explained it above.
> > 
> > > maybe we can
> > > also recycle some my mxs binding code for ci13xxx in some way or
> > > another, as it has MXS specific hacks in it.
> > 
> > what hack do you mean?
> > 
> > > I think the ci13xxx binding for the rest of i.MX
> > > (aka mxc) will looks different, won't it? But either way, my
> > > mxs/ci13xxx binding glue will have to wait until we finish negotiating
> > > the phy_notify stuff with Greg.
> > 
> > Sure. At the same time, we may create new version patch and see response.
> > 
> > Thanks
> > Richard
> > 
> > > > Thanks
> > > > Richard
> > > > 
> > > > > +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");
> > 
> > --
> > 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] 30+ messages in thread

* [PATCH 5/8] MXS: Add USB PHY driver
  2012-05-16 10:35   ` Peter Chen
@ 2012-05-16 13:37     ` Marek Vasut
  0 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-16 13:37 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Peter Chen,

> On Tue, May 15, 2012 at 10:23:36AM +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.
> 
> Please add i.mx6q .
> 
> > +config USB_MXS_PHY
> > +	tristate "Freescale i.MX28 USB PHY support"
> > +	select USB_OTG_UTILS
> > +	select USB_IMX_COMPOSITE
> 
> Seems you will not use imx_otg.c with chipidea framework.

Good catch :)

> 
> > + *
> > + * Freescale i.MX28 USB PHY driver.
> 
> use mxs

Now ... I think we have two waring opinions in here :)

> > + *
> > +
> > +	/* Enable FS/LS compatibility and wakeup IRQs. */
> > +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
> > +		BM_USBPHY_CTRL_ENIRQWAKEUP;
> > +
> > +	/* Enable IRQ sources. */
> > +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> > +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> 
> Please forget wakeup function currently, as it will make things more
> complicated.
> 
> > +
> > +	writel(val, x->io_priv + HW_USBPHY_CTRL_SET);
> > +
> > +	return 0;
> > +}
> > +
> > +	/* Disable FS/LS compatibility and wakeup IRQs. */
> > +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3 |
> > +		BM_USBPHY_CTRL_ENIRQWAKEUP;
> > +
> > +	/* Disable IRQ sources. */
> > +	val |= BM_USBPHY_CTRL_ENIDCHG_WKUP | BM_USBPHY_CTRL_ENDPDMCHG_WKUP |
> > +		BM_USBPHY_CTRL_ENVBUSCHG_WKUP;
> > +
> 
> The same with above
> 
> > +
> > +MODULE_ALIAS("platform:mxs-usb-phy");
> > +MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
> > +MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
> 
> mxs
> 
> > +MODULE_LICENSE("GPL");

Best regards,
Marek Vasut

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

* Re: [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
  2012-05-16  8:36         ` Felipe Balbi
@ 2012-05-16 13:41             ` Marek Vasut
  -1 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-16 13:41 UTC (permalink / raw)
  To: balbi-l0cyMroinI0
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Alan Stern,
	Detlev Zundel, Dong Aisheng, Fabio Estevam, Greg Kroah-Hartman,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA, Sascha Hauer, Shawn Guo,
	Stefano Babic, Uwe Kleine-König, Wolfgang Denk,
	Wolfram Sang

Dear Felipe Balbi,

> On Tue, May 15, 2012 at 10:23:37AM +0200, Marek Vasut wrote:
> > This codes connects the CI13xxx driver with the core found inside of
> > the Freescale i.MX244/i.MX28 CPU.
> > 
> > Signed-off-by: Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
> > Cc: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
> > Cc: Detlev Zundel <dzu-ynQEQJNshbs@public.gmane.org>
> > CC: Dong Aisheng <b29396-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > CC: Fabio Estevam <fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > Cc: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
> > Cc: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
> > Cc: Linux ARM kernel <linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
> > Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> > CC: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > CC: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> > Cc: Stefano Babic <sbabic-ynQEQJNshbs@public.gmane.org>
> > CC: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > Cc: Wolfgang Denk <wd-ynQEQJNshbs@public.gmane.org>
> > Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > ---
> > 
> >  drivers/usb/chipidea/Makefile      |    4 +
> >  drivers/usb/chipidea/ci13xxx_mxs.c |  201
> >  ++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+)
> >  create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c
> > 
> > diff --git a/drivers/usb/chipidea/Makefile
> > b/drivers/usb/chipidea/Makefile index cc34937..266d57d 100644
> > --- a/drivers/usb/chipidea/Makefile
> > +++ b/drivers/usb/chipidea/Makefile
> > @@ -12,3 +12,7 @@ endif
> > 
> >  ifneq ($(CONFIG_ARCH_MSM),)
> >  
> >  	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
> >  
> >  endif
> > 
> > +
> > +ifneq ($(CONFIG_ARCH_MXS),)
> > +	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
> > +endif
> 
> NAK... let it compile everywhere.

I just followed the pattern here, honestly I think this is quite OK so far. 
Further improvements can be made indeed.

> > diff --git a/drivers/usb/chipidea/ci13xxx_mxs.c
> > b/drivers/usb/chipidea/ci13xxx_mxs.c new file mode 100644
> > index 0000000..fcca90b
> > --- /dev/null
> > +++ b/drivers/usb/chipidea/ci13xxx_mxs.c
> > @@ -0,0 +1,201 @@
> > +/*
> > + * drivers/usb/chipidea/ci13xxx_mxs.c
> > + *
> > + * Freescale i.MX233/i.MX28 USB glue driver to CI13xxx core.
> > + *
> > + * Copyright (C) 2012 Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
> > + * 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/pm_runtime.h>
> > +#include <linux/clk.h>
> > +#include <linux/dma-mapping.h>
> > +
> > +#include <linux/usb.h>
> > +#include <linux/usb/chipidea.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 <linux/usb/mxs-usb.h>
> > +
> > +#include "ci.h"
> > +
> > +static void ci13xxx_mxs_notify(struct ci13xxx *ci, unsigned event)
> > +{
> > +	uint32_t status;
> > +	struct usb_phy *phy;
> > +	struct mxs_ci13xxx_phy_notify notify;
> > +
> > +	phy = usb_get_transceiver();
> > +	if (!phy)
> > +		return;
> > +
> > +	if (event != CI13XXX_CONTROLLER_HOST_IRQ_EVENT)
> > +		return;
> > +
> > +	status = hw_read(ci, OP_USBSTS, ~0);
> > +
> > +	notify.discon = status & STS_PCD;
> > +
> > +	usb_phy_notify(phy, &notify);
> > +}
> > +
> > +static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
> > +	.name			= "ci13xxx_mxs",
> > +	.flags			= /*CI13XXX_REGS_SHARED |*/
> > +				  CI13XXX_REQUIRE_TRANSCEIVER |
> > +				  CI13XXX_PULLUP_ON_VBUS |
> > +				  CI13XXX_DISABLE_STREAMING,
> > +	.capoffset		= 0x100,
> > +	.notify_event		= ci13xxx_mxs_notify,
> > +};
> > +
> > +struct ci13xxx_mxs_data {
> > +	struct clk		*clk;
> > +	struct platform_device	*pdev;
> > +};
> > +
> > +static int __devinit ci13xxx_mxs_probe(struct platform_device *pdev)
> > +{
> > +	struct ci13xxx_mxs_data *data;
> > +	int ret;
> > +	struct usb_phy *phy;
> > +
> > +	phy = usb_get_transceiver();
> > +	if (!phy)
> > +		return -EPROBE_DEFER;
> > +
> > +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > +	if (!data) {
> > +		dev_err(&pdev->dev, "Failed to allocate CI13xxx-MXS data!\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	ret = usb_phy_init(phy);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "Failed to initialize PHY!\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	data->pdev = platform_device_alloc("ci_hdrc", -1);
> > +	if (!data->pdev) {
> > +		dev_err(&pdev->dev,
> > +			"Failed to allocate ci_hdrc platform device!\n");
> > +		ret = -ENOMEM;
> > +		goto put_phy;
> > +	}
> > +
> > +	/* Add DMA mask */
> > +	data->pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
> > +					sizeof(*data->pdev->dev.dma_mask),
> > +					GFP_KERNEL);
> > +	if (!data->pdev->dev.dma_mask) {
> > +		ret = -ENOMEM;
> > +		goto put_platform;
> > +	}
> > +
> > +	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
> > +	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
> 
> why don't you just point to the parent's ?

Good idea, thanks :)

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

* [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
@ 2012-05-16 13:41             ` Marek Vasut
  0 siblings, 0 replies; 30+ messages in thread
From: Marek Vasut @ 2012-05-16 13:41 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Felipe Balbi,

> On Tue, May 15, 2012 at 10:23:37AM +0200, Marek Vasut wrote:
> > This codes connects the CI13xxx driver with the core found inside of
> > the Freescale i.MX244/i.MX28 CPU.
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Alan Stern <stern@rowland.harvard.edu>
> > Cc: Detlev Zundel <dzu@denx.de>
> > CC: Dong Aisheng <b29396@freescale.com>
> > CC: Fabio Estevam <fabio.estevam@freescale.com>
> > Cc: Felipe Balbi <balbi@ti.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: Linux ARM kernel <linux-arm-kernel@lists.infradead.org>
> > Cc: linux-i2c at vger.kernel.org
> > CC: Sascha Hauer <s.hauer@pengutronix.de>
> > CC: Shawn Guo <shawn.guo@linaro.org>
> > Cc: Stefano Babic <sbabic@denx.de>
> > CC: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> > Cc: Wolfgang Denk <wd@denx.de>
> > Cc: Wolfram Sang <w.sang@pengutronix.de>
> > ---
> > 
> >  drivers/usb/chipidea/Makefile      |    4 +
> >  drivers/usb/chipidea/ci13xxx_mxs.c |  201
> >  ++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+)
> >  create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c
> > 
> > diff --git a/drivers/usb/chipidea/Makefile
> > b/drivers/usb/chipidea/Makefile index cc34937..266d57d 100644
> > --- a/drivers/usb/chipidea/Makefile
> > +++ b/drivers/usb/chipidea/Makefile
> > @@ -12,3 +12,7 @@ endif
> > 
> >  ifneq ($(CONFIG_ARCH_MSM),)
> >  
> >  	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
> >  
> >  endif
> > 
> > +
> > +ifneq ($(CONFIG_ARCH_MXS),)
> > +	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
> > +endif
> 
> NAK... let it compile everywhere.

I just followed the pattern here, honestly I think this is quite OK so far. 
Further improvements can be made indeed.

> > diff --git a/drivers/usb/chipidea/ci13xxx_mxs.c
> > b/drivers/usb/chipidea/ci13xxx_mxs.c new file mode 100644
> > index 0000000..fcca90b
> > --- /dev/null
> > +++ b/drivers/usb/chipidea/ci13xxx_mxs.c
> > @@ -0,0 +1,201 @@
> > +/*
> > + * drivers/usb/chipidea/ci13xxx_mxs.c
> > + *
> > + * Freescale i.MX233/i.MX28 USB glue driver to CI13xxx core.
> > + *
> > + * 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/pm_runtime.h>
> > +#include <linux/clk.h>
> > +#include <linux/dma-mapping.h>
> > +
> > +#include <linux/usb.h>
> > +#include <linux/usb/chipidea.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 <linux/usb/mxs-usb.h>
> > +
> > +#include "ci.h"
> > +
> > +static void ci13xxx_mxs_notify(struct ci13xxx *ci, unsigned event)
> > +{
> > +	uint32_t status;
> > +	struct usb_phy *phy;
> > +	struct mxs_ci13xxx_phy_notify notify;
> > +
> > +	phy = usb_get_transceiver();
> > +	if (!phy)
> > +		return;
> > +
> > +	if (event != CI13XXX_CONTROLLER_HOST_IRQ_EVENT)
> > +		return;
> > +
> > +	status = hw_read(ci, OP_USBSTS, ~0);
> > +
> > +	notify.discon = status & STS_PCD;
> > +
> > +	usb_phy_notify(phy, &notify);
> > +}
> > +
> > +static struct ci13xxx_udc_driver ci13xxx_mxs_udc_driver = {
> > +	.name			= "ci13xxx_mxs",
> > +	.flags			= /*CI13XXX_REGS_SHARED |*/
> > +				  CI13XXX_REQUIRE_TRANSCEIVER |
> > +				  CI13XXX_PULLUP_ON_VBUS |
> > +				  CI13XXX_DISABLE_STREAMING,
> > +	.capoffset		= 0x100,
> > +	.notify_event		= ci13xxx_mxs_notify,
> > +};
> > +
> > +struct ci13xxx_mxs_data {
> > +	struct clk		*clk;
> > +	struct platform_device	*pdev;
> > +};
> > +
> > +static int __devinit ci13xxx_mxs_probe(struct platform_device *pdev)
> > +{
> > +	struct ci13xxx_mxs_data *data;
> > +	int ret;
> > +	struct usb_phy *phy;
> > +
> > +	phy = usb_get_transceiver();
> > +	if (!phy)
> > +		return -EPROBE_DEFER;
> > +
> > +	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > +	if (!data) {
> > +		dev_err(&pdev->dev, "Failed to allocate CI13xxx-MXS data!\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	ret = usb_phy_init(phy);
> > +	if (ret) {
> > +		dev_err(&pdev->dev, "Failed to initialize PHY!\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	data->pdev = platform_device_alloc("ci_hdrc", -1);
> > +	if (!data->pdev) {
> > +		dev_err(&pdev->dev,
> > +			"Failed to allocate ci_hdrc platform device!\n");
> > +		ret = -ENOMEM;
> > +		goto put_phy;
> > +	}
> > +
> > +	/* Add DMA mask */
> > +	data->pdev->dev.dma_mask = devm_kzalloc(&pdev->dev,
> > +					sizeof(*data->pdev->dev.dma_mask),
> > +					GFP_KERNEL);
> > +	if (!data->pdev->dev.dma_mask) {
> > +		ret = -ENOMEM;
> > +		goto put_platform;
> > +	}
> > +
> > +	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
> > +	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
> 
> why don't you just point to the parent's ?

Good idea, thanks :)

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

* Re: [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
  2012-05-16 13:41             ` Marek Vasut
@ 2012-05-18 11:34                 ` Felipe Balbi
  -1 siblings, 0 replies; 30+ messages in thread
From: Felipe Balbi @ 2012-05-18 11:34 UTC (permalink / raw)
  To: Marek Vasut
  Cc: balbi-l0cyMroinI0,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r, Alan Stern,
	Detlev Zundel, Dong Aisheng, Fabio Estevam, Greg Kroah-Hartman,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA, Sascha Hauer, Shawn Guo,
	Stefano Babic, Uwe Kleine-König, Wolfgang Denk,
	Wolfram Sang

[-- Attachment #1: Type: text/plain, Size: 2687 bytes --]

On Wed, May 16, 2012 at 03:41:17PM +0200, Marek Vasut wrote:
> Dear Felipe Balbi,
> 
> > On Tue, May 15, 2012 at 10:23:37AM +0200, Marek Vasut wrote:
> > > This codes connects the CI13xxx driver with the core found inside of
> > > the Freescale i.MX244/i.MX28 CPU.
> > > 
> > > Signed-off-by: Marek Vasut <marex-ynQEQJNshbs@public.gmane.org>
> > > Cc: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
> > > Cc: Detlev Zundel <dzu-ynQEQJNshbs@public.gmane.org>
> > > CC: Dong Aisheng <b29396-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > > CC: Fabio Estevam <fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > > Cc: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
> > > Cc: Greg Kroah-Hartman <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>
> > > Cc: Linux ARM kernel <linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
> > > Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> > > CC: Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > > CC: Shawn Guo <shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> > > Cc: Stefano Babic <sbabic-ynQEQJNshbs@public.gmane.org>
> > > CC: Uwe Kleine-König <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > > Cc: Wolfgang Denk <wd-ynQEQJNshbs@public.gmane.org>
> > > Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > > ---
> > > 
> > >  drivers/usb/chipidea/Makefile      |    4 +
> > >  drivers/usb/chipidea/ci13xxx_mxs.c |  201
> > >  ++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+)
> > >  create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c
> > > 
> > > diff --git a/drivers/usb/chipidea/Makefile
> > > b/drivers/usb/chipidea/Makefile index cc34937..266d57d 100644
> > > --- a/drivers/usb/chipidea/Makefile
> > > +++ b/drivers/usb/chipidea/Makefile
> > > @@ -12,3 +12,7 @@ endif
> > > 
> > >  ifneq ($(CONFIG_ARCH_MSM),)
> > >  
> > >  	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
> > >  
> > >  endif
> > > 
> > > +
> > > +ifneq ($(CONFIG_ARCH_MXS),)
> > > +	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
> > > +endif
> > 
> > NAK... let it compile everywhere.
> 
> I just followed the pattern here, honestly I think this is quite OK so far. 
> Further improvements can be made indeed.

why introduce something we know will change ? Just make sure your code
compiles everywhere. What's already there can be changed afterwards.

> > > +	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
> > > +	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
> > 
> > why don't you just point to the parent's ?
> 
> Good idea, thanks :)

no problem ;-)

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code
@ 2012-05-18 11:34                 ` Felipe Balbi
  0 siblings, 0 replies; 30+ messages in thread
From: Felipe Balbi @ 2012-05-18 11:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, May 16, 2012 at 03:41:17PM +0200, Marek Vasut wrote:
> Dear Felipe Balbi,
> 
> > On Tue, May 15, 2012 at 10:23:37AM +0200, Marek Vasut wrote:
> > > This codes connects the CI13xxx driver with the core found inside of
> > > the Freescale i.MX244/i.MX28 CPU.
> > > 
> > > Signed-off-by: Marek Vasut <marex@denx.de>
> > > Cc: Alan Stern <stern@rowland.harvard.edu>
> > > Cc: Detlev Zundel <dzu@denx.de>
> > > CC: Dong Aisheng <b29396@freescale.com>
> > > CC: Fabio Estevam <fabio.estevam@freescale.com>
> > > Cc: Felipe Balbi <balbi@ti.com>
> > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Cc: Linux ARM kernel <linux-arm-kernel@lists.infradead.org>
> > > Cc: linux-i2c at vger.kernel.org
> > > CC: Sascha Hauer <s.hauer@pengutronix.de>
> > > CC: Shawn Guo <shawn.guo@linaro.org>
> > > Cc: Stefano Babic <sbabic@denx.de>
> > > CC: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> > > Cc: Wolfgang Denk <wd@denx.de>
> > > Cc: Wolfram Sang <w.sang@pengutronix.de>
> > > ---
> > > 
> > >  drivers/usb/chipidea/Makefile      |    4 +
> > >  drivers/usb/chipidea/ci13xxx_mxs.c |  201
> > >  ++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+)
> > >  create mode 100644 drivers/usb/chipidea/ci13xxx_mxs.c
> > > 
> > > diff --git a/drivers/usb/chipidea/Makefile
> > > b/drivers/usb/chipidea/Makefile index cc34937..266d57d 100644
> > > --- a/drivers/usb/chipidea/Makefile
> > > +++ b/drivers/usb/chipidea/Makefile
> > > @@ -12,3 +12,7 @@ endif
> > > 
> > >  ifneq ($(CONFIG_ARCH_MSM),)
> > >  
> > >  	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
> > >  
> > >  endif
> > > 
> > > +
> > > +ifneq ($(CONFIG_ARCH_MXS),)
> > > +	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
> > > +endif
> > 
> > NAK... let it compile everywhere.
> 
> I just followed the pattern here, honestly I think this is quite OK so far. 
> Further improvements can be made indeed.

why introduce something we know will change ? Just make sure your code
compiles everywhere. What's already there can be changed afterwards.

> > > +	*data->pdev->dev.dma_mask = DMA_BIT_MASK(32);
> > > +	data->pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
> > 
> > why don't you just point to the parent's ?
> 
> Good idea, thanks :)

no problem ;-)

-- 
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120518/7a2cd354/attachment.sig>

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

end of thread, other threads:[~2012-05-18 11:34 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-15  8:23 [RFC PATCH 0/8 V8] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-05-15  8:23 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
2012-05-16  0:55   ` Richard Zhao
2012-05-16  1:01     ` Marek Vasut
2012-05-15  8:23 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-05-16  0:56   ` Richard Zhao
2012-05-15  8:23 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-05-16  0:58   ` Richard Zhao
2012-05-16  1:02     ` Marek Vasut
2012-05-15  8:23 ` [PATCH 4/8] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
2012-05-16  1:00   ` Richard Zhao
2012-05-15  8:23 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
2012-05-16  3:33   ` Richard Zhao
2012-05-16  4:30     ` Marek Vasut
2012-05-16  5:06       ` Richard Zhao
2012-05-16  7:18         ` Richard Zhao
2012-05-16 13:36           ` Marek Vasut
2012-05-16 13:35         ` Marek Vasut
2012-05-16 10:35   ` Peter Chen
2012-05-16 13:37     ` Marek Vasut
     [not found] ` <1337070219-3630-1-git-send-email-marex-ynQEQJNshbs@public.gmane.org>
2012-05-15  8:23   ` [PATCH 6/8] CI13xxx: Add i.MX233/i.MX28 binding code Marek Vasut
2012-05-15  8:23     ` Marek Vasut
     [not found]     ` <1337070219-3630-7-git-send-email-marex-ynQEQJNshbs@public.gmane.org>
2012-05-16  8:36       ` Felipe Balbi
2012-05-16  8:36         ` Felipe Balbi
     [not found]         ` <20120516083613.GG17359-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-05-16 13:41           ` Marek Vasut
2012-05-16 13:41             ` Marek Vasut
     [not found]             ` <201205161541.17508.marex-ynQEQJNshbs@public.gmane.org>
2012-05-18 11:34               ` Felipe Balbi
2012-05-18 11:34                 ` Felipe Balbi
2012-05-15  8:23 ` [PATCH 7/8] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-05-15  8:23 ` [PATCH 8/8] MXS: Enable USB on M28EVK 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.