Skip to contentSkip to conversation

MXS: Add i.MX28 USB Host driver

RFC PATCH New Marek Vasut 4 participants 26 messages May 15, 2012 – May 18, 2012

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v8 cover MXS: Add i.MX28 USB Host driver

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 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
Signature · 1 line
1.7.10
#1 lore raw

PATCH v8 1/8 MXS: Make clk_disable return integer

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

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/arm/mach-mxs/clock-mx28.c         |    7 +++++--
 arch/arm/mach-mxs/include/mach/clock.h |    2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +5 -2
index cea29c9..43116ba 100644
@@ -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)
arch/arm/mach-mxs/include/mach/clock.h +1 -1
index 592c9ab..21d1fad 100644
@@ -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 *);
 };
Signature · 1 line
1.7.10
#2 lore raw

PATCH 1/8 MXS: Make clk_disable return integer

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

Thanks
Richard

#3 lore raw

PATCH v8 1/8 MXS: Make clk_disable return integer

Dear Richard Zhao,

Quoted 1 line

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

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

Quoted 3 lines

Thanks
Richard

Best regards,
Marek Vasut

#4 lore raw

PATCH v8 2/8 MXS: Add USB EHCI and USB PHY clock handling

In reply to Marek Vasut

Based on code by:
Tony Lin <[email protected]>

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/arm/mach-mxs/clock-mx28.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
arch/arm/mach-mxs/clock-mx28.c +19 -2
index 43116ba..60ebe99 100644
@@ -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)
Signature · 1 line
1.7.10
#5 lore raw

PATCH 2/8 MXS: Add USB EHCI and USB PHY clock handling

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

Thanks
Richard

#6 lore raw

PATCH v8 3/8 MXS: Fixup i.MX233 USB base address name

In reply to Marek Vasut

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 <[email protected]>

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm/mach-mxs/include/mach/mx23.h +4 -4
index 599094b..7955b75 100644
@@ -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
Signature · 1 line
1.7.10
#7 lore raw

PATCH 3/8 MXS: Fixup i.MX233 USB base address name

Quoted 28 lines · Marek Vasut

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 <[email protected]>

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm/mach-mxs/include/mach/mx23.h +0 -0
index 599094b..7955b75 100644

arch/arm/mach-mxs/include/mach/mx23.h line 68

Quoted 7 lines
arch/arm/mach-mxs/include/mach/mx23.h +2 -2
@@ -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

Quoted 22 lines
arch/arm/mach-mxs/include/mach/mx23.h +2 -2
 #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
Signature · 6 lines
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
#8 lore raw

PATCH v8 3/8 MXS: Fixup i.MX233 USB base address name

Dear Richard Zhao,

Quoted 35 lines · Marek Vasut
Quoted 34 lines

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 <[email protected]>

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

 arch/arm/mach-mxs/include/mach/mx23.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-mxs/include/mach/mx23.h index 599094b..7955b75 100644

arch/arm/mach-mxs/include/mach/mx23.h +0 -0
@@ -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)
 
Quoted 6 lines

arch/arm/mach-mxs/include/mach/mx23.h line 68

Quoted 4 lines
arch/arm/mach-mxs/include/mach/mx23.h +2 -2
-#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.

Quoted 14 lines

Thanks
Richard

Quoted 10 lines
arch/arm/mach-mxs/include/mach/mx23.h +0 -0
 #define MX23_DRAM_BASE_ADDR		(MX23_IO_BASE_ADDR + 0x0e0000)

#define MX23_IO_P2V(x) MXS_IO_P2V(x)

arch/arm/mach-mxs/include/mach/mx23.h +0 -0
@@ -89,8 +89,8 @@
 
 #define MX23_INT_SPDIF_ERROR		10
 #define MX23_INT_SAIF1_IRQ		10
 #define MX23_INT_SAIF2_IRQ		10
 
Quoted 8 lines
Quoted 8 lines
arch/arm/mach-mxs/include/mach/mx23.h +2 -2
-#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

#9 lore raw

PATCH v8 4/8 MXS: Add data shared between imx-otg and EHCI driver

In reply to Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/linux/usb/mxs-usb.h |   39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 include/linux/usb/mxs-usb.h
include/linux/usb/mxs-usb.h new file +39 -0
new file mode 100644
index 0000000..2678700
@@ -0,0 +1,39 @@
+/*
+ * include/linux/usb/mxs-usb.h
+ *
+ * Freescale i.MX USB driver shared data.
+ *
+ * Copyright (C) 2012 Marek Vasut <[email protected]>
+ * 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__ */
Signature · 1 line
1.7.10
#10 lore raw

PATCH 4/8 MXS: Add data shared between imx-otg and EHCI driver

Quoted 52 lines · Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 include/linux/usb/mxs-usb.h |   39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 include/linux/usb/mxs-usb.h
include/linux/usb/mxs-usb.h new file +23 -0
new file mode 100644
index 0000000..2678700
@@ -0,0 +1,39 @@
+/*
+ * include/linux/usb/mxs-usb.h
+ *
+ * Freescale i.MX USB driver shared data.
+ *
+ * Copyright (C) 2012 Marek Vasut <[email protected]>
+ * 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/usb/mxs-usb.h line 33

Quoted 10 lines
include/linux/usb/mxs-usb.h new file +10 -0
+#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

Quoted 14 lines
include/linux/usb/mxs-usb.h new file +6 -0
+
+struct mxs_ci13xxx_phy_notify {
+	bool			discon;
+};
+
+#endif /* __INCLUDE_LINUX_USB_MXS_USB_H__ */
Signature · 6 lines
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
#11 lore raw

PATCH v8 5/8 MXS: Add USB PHY driver

In reply to Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 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
drivers/usb/otg/Kconfig +10 -0
index 5c87db0..bc7625e 100644
@@ -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
drivers/usb/otg/Makefile +1 -0
index 41aa509..a844b8d 100644
@@ -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
drivers/usb/otg/mxs-phy.c new file +313 -0

313 lines not on this page · raw message

Signature · 1 line
1.7.10
#12 lore raw

PATCH 5/8 MXS: Add USB PHY driver

Hi Marek,

Quoted 16 lines · Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
Quoted 4 lines
---
 drivers/usb/otg/Kconfig   |   10 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  313 +++++++++++++++++++++++++++++++++++++++++++++

imx is more common.

Quoted 120 lines
 3 files changed, 324 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c
drivers/usb/otg/Kconfig +10 -0
index 5c87db0..bc7625e 100644
@@ -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
drivers/usb/otg/Makefile +1 -0
index 41aa509..a844b8d 100644
@@ -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
drivers/usb/otg/mxs-phy.c new file +80 -0
new file mode 100644
index 0000000..eb658ca
@@ -0,0 +1,313 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <[email protected]>
+ * 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;
+};
+

drivers/usb/otg/mxs-phy.c line 90

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -0
+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.

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+
+	/* Power up the PHY. */
+	writel(0, x->io_priv + HW_USBPHY_PWD);
+
+	/* Clear the wakeup IRQ before enabling them below. */

drivers/usb/otg/mxs-phy.c line 105

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -0
+	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?

Quoted 60 lines
drivers/usb/otg/mxs-phy.c new file +60 -0
+
+	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;

drivers/usb/otg/mxs-phy.c line 175

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -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.

Quoted 27 lines
drivers/usb/otg/mxs-phy.c new file +27 -0
+
+	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. */

drivers/usb/otg/mxs-phy.c line 212

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -0
+	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 ?

drivers/usb/otg/mxs-phy.c line 219

Quoted 7 lines
drivers/usb/otg/mxs-phy.c new file +7 -0
+	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 ?

drivers/usb/otg/mxs-phy.c line 226

Quoted 7 lines
drivers/usb/otg/mxs-phy.c new file +7 -0
+	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?

Quoted 17 lines
drivers/usb/otg/mxs-phy.c new file +17 -0
+	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;

drivers/usb/otg/mxs-phy.c line 253

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -0
+	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.

Quoted 44 lines
drivers/usb/otg/mxs-phy.c new file +44 -0
+	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)

drivers/usb/otg/mxs-phy.c line 307

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -0
+{
+	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

Quoted 14 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
Signature · 6 lines
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
#13 lore raw

PATCH v8 5/8 MXS: Add USB PHY driver

Dear Richard Zhao,

Quoted 21 lines

Hi Marek,

Quoted 18 lines · Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

Quoted 6 lines
Quoted 4 lines
 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 ?

Quoted 134 lines
Quoted 134 lines
 3 files changed, 324 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c
drivers/usb/otg/Kconfig +10 -0
index 5c87db0..bc7625e 100644
@@ -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

drivers/usb/otg/Kconfig +0 -0
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
drivers/usb/otg/Makefile +1 -0
index 41aa509..a844b8d 100644
@@ -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
drivers/usb/otg/mxs-phy.c new file +85 -0
new file mode 100644
index 0000000..eb658ca
@@ -0,0 +1,313 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <[email protected]>
+ * 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;
+
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 90

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+	/* 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.

Quoted 11 lines
Quoted 11 lines
drivers/usb/otg/mxs-phy.c new file +10 -0
+
+	/* 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 |
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 105

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+		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.

Quoted 66 lines
Quoted 66 lines
drivers/usb/otg/mxs-phy.c new file +44 -0
+
+	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) +{

drivers/usb/otg/mxs-phy.c new file +21 -0
+	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);
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 175

Quoted 4 lines
drivers/usb/otg/mxs-phy.c new file +4 -0
+	} 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)

Quoted 31 lines
Quoted 31 lines
drivers/usb/otg/mxs-phy.c new file +31 -0
+
+	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");
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 212

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+		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.

Quoted 9 lines

drivers/usb/otg/mxs-phy.c line 219

Quoted 7 lines
drivers/usb/otg/mxs-phy.c new file +7 -0
+	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!

Quoted 9 lines

drivers/usb/otg/mxs-phy.c line 226

Quoted 7 lines
drivers/usb/otg/mxs-phy.c new file +7 -0
+	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.

Quoted 22 lines
Quoted 22 lines
drivers/usb/otg/mxs-phy.c new file +22 -0
+	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);
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 253

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+
+	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.

Quoted 48 lines
Quoted 48 lines
drivers/usb/otg/mxs-phy.c new file +48 -0
+	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);
+}
+
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 307

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+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.

Quoted 9 lines

Thanks
Richard

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
#14 lore raw

PATCH 5/8 MXS: Add USB PHY driver

Quoted 28 lines · Marek Vasut

Dear Richard Zhao,

Quoted 26 lines

Hi Marek,

Quoted 22 lines · Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

 drivers/usb/otg/Kconfig   |   10 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  313

+++++++++++++++++++++++++++++++++++++++++++++

Quoted 4 lines
Quoted 1 line

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.

Quoted 166 lines
Quoted 135 lines
Quoted 135 lines
 3 files changed, 324 insertions(+)
 create mode 100644 drivers/usb/otg/mxs-phy.c
drivers/usb/otg/Kconfig +10 -0
index 5c87db0..bc7625e 100644
@@ -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

drivers/usb/otg/Kconfig +0 -0
 	tristate "Marvell USB OTG support"
 	depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
drivers/usb/otg/Makefile +1 -0
index 41aa509..a844b8d 100644
@@ -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
drivers/usb/otg/mxs-phy.c new file +85 -0
new file mode 100644
index 0000000..eb658ca
@@ -0,0 +1,313 @@
+/*
+ * drivers/usb/otg/mxs-phy.c
+ *
+ * Freescale i.MX28 USB PHY driver.
+ *
+ * Copyright (C) 2012 Marek Vasut <[email protected]>
+ * 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;
+
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 90

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+	/* 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.

Quoted 11 lines
Quoted 11 lines
drivers/usb/otg/mxs-phy.c new file +10 -0
+
+	/* 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 |
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 105

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+		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?

Quoted 1 line

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

I didn't consider or test wakeup yet.

Quoted 118 lines
Quoted 67 lines
Quoted 67 lines
drivers/usb/otg/mxs-phy.c new file +44 -0
+
+	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) +{

drivers/usb/otg/mxs-phy.c new file +21 -0
+	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);
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 175

Quoted 4 lines
drivers/usb/otg/mxs-phy.c new file +4 -0
+	} 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)

Quoted 31 lines
Quoted 31 lines
drivers/usb/otg/mxs-phy.c new file +31 -0
+
+	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");
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 212

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+		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 ?

Quoted 2 lines

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.

Quoted 56 lines
Quoted 10 lines

drivers/usb/otg/mxs-phy.c line 219

Quoted 8 lines
drivers/usb/otg/mxs-phy.c new file +7 -0
+	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!

Quoted 9 lines

drivers/usb/otg/mxs-phy.c line 226

Quoted 7 lines
drivers/usb/otg/mxs-phy.c new file +7 -0
+	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.

Quoted 22 lines
Quoted 22 lines
drivers/usb/otg/mxs-phy.c new file +22 -0
+	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);
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 253

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+
+	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.

Quoted 2 lines

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?

Quoted 58 lines
Quoted 49 lines
Quoted 49 lines
drivers/usb/otg/mxs-phy.c new file +48 -0
+	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);
+}
+
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 307

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+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.

Quoted 4 lines

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.

Quoted 2 lines

Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,

I explained it above.

Quoted 3 lines

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?

Quoted 4 lines

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

Quoted 11 lines
Quoted 10 lines

Thanks
Richard

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
#15 lore raw

PATCH 5/8 MXS: Add USB PHY driver

Quoted 4 lines
Quoted 2 lines

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

Quoted 32 lines
Quoted 2 lines

Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,

I explained it above.

Quoted 3 lines

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?

Quoted 4 lines

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

Quoted 11 lines
Quoted 10 lines

Thanks
Richard

drivers/usb/otg/mxs-phy.c line 313

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+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

#16 lore raw

PATCH v8 5/8 MXS: Add USB PHY driver

Dear Richard Zhao,

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

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 :)

Quoted 37 lines

Thanks
Richard

Quoted 34 lines
Quoted 1 line

Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,

I explained it above.

Quoted 3 lines

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?

Quoted 4 lines

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

Quoted 9 lines
Quoted 9 lines

Thanks
Richard

drivers/usb/otg/mxs-phy.c line 313

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+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

#17 lore raw

PATCH v8 5/8 MXS: Add USB PHY driver

In reply to Richard Zhao

Dear Richard Zhao,

Quoted 29 lines · Marek Vasut
Quoted 28 lines

Dear Richard Zhao,

Quoted 26 lines

Hi Marek,

Quoted 22 lines · Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

 drivers/usb/otg/Kconfig   |   10 ++
 drivers/usb/otg/Makefile  |    1 +
 drivers/usb/otg/mxs-phy.c |  313

+++++++++++++++++++++++++++++++++++++++++++++

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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.

[...]

Quoted 18 lines
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+	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);
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 253

Quoted 5 lines
drivers/usb/otg/mxs-phy.c new file +5 -0
+
+	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.

Quoted 2 lines

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.

Quoted 7 lines

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.

[...]

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 307

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+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.

Quoted 8 lines
Quoted 5 lines

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?

Quoted 9 lines
Quoted 1 line

Alas, I'd prefer for the PHY to stay separate in drivers/usb/otg,

I explained it above.

Quoted 3 lines

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.

Quoted 6 lines
Quoted 4 lines

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.

Quoted 12 lines

Thanks
Richard

Quoted 9 lines
Quoted 9 lines

Thanks
Richard

Quoted 6 lines
drivers/usb/otg/mxs-phy.c new file +6 -0
+module_exit(mxs_phy_exit);
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");
+MODULE_LICENSE("GPL");
#18 lore raw

PATCH 5/8 MXS: Add USB PHY driver

In reply to Marek Vasut
Quoted 2 lines · Marek Vasut

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 .

drivers/usb/otg/Kconfig config FSL_USB2_OTG · line 122

Quoted 5 lines
drivers/usb/otg/Kconfig +4 -0
+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.

Quoted 2 lines

+ *
+ * Freescale i.MX28 USB PHY driver.

use mxs

drivers/usb/otg/mxs-phy.c line 105

Quoted 9 lines

+ *

drivers/usb/otg/mxs-phy.c new file +8 -0
+
+	/* 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.

Quoted 4 lines
drivers/usb/otg/mxs-phy.c new file +4 -0
+
+	writel(val, x->io_priv + HW_USBPHY_CTRL_SET);
+
+	return 0;

drivers/usb/otg/mxs-phy.c line 128

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -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

drivers/usb/otg/mxs-phy.c line 312

Quoted 4 lines
drivers/usb/otg/mxs-phy.c new file +4 -0
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");

mxs

Quoted 5 lines

+MODULE_LICENSE("GPL");

Signature · 1 line
1.7.10
Signature · 2 lines
Best Regards,
Peter Chen
#19 lore raw

PATCH v8 5/8 MXS: Add USB PHY driver

Dear Peter Chen,

Quoted 12 lines · Marek Vasut
Quoted 2 lines

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 .

drivers/usb/otg/Kconfig config FSL_USB2_OTG · line 122

Quoted 4 lines
drivers/usb/otg/Kconfig +4 -0
+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 :)

Quoted 5 lines
Quoted 3 lines

+ *
+ * Freescale i.MX28 USB PHY driver.

use mxs

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

Quoted 30 lines

drivers/usb/otg/mxs-phy.c line 105

Quoted 9 lines

+ *

drivers/usb/otg/mxs-phy.c new file +8 -0
+
+	/* 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.

Quoted 4 lines
drivers/usb/otg/mxs-phy.c new file +4 -0
+
+	writel(val, x->io_priv + HW_USBPHY_CTRL_SET);
+
+	return 0;

drivers/usb/otg/mxs-phy.c line 128

Quoted 10 lines
drivers/usb/otg/mxs-phy.c new file +10 -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

Quoted 8 lines

drivers/usb/otg/mxs-phy.c line 312

Quoted 4 lines
drivers/usb/otg/mxs-phy.c new file +4 -0
+
+MODULE_ALIAS("platform:mxs-usb-phy");
+MODULE_AUTHOR("Marek Vasut <[email protected]>");
+MODULE_DESCRIPTION("Freescale i.MX28 USB PHY driver");

mxs

Quoted 1 line

+MODULE_LICENSE("GPL");

Best regards,
Marek Vasut

#20 lore raw

PATCH v8 6/8 CI13xxx: Add i.MX233/i.MX28 binding code

In reply to Marek Vasut

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

Cc Alan Stern <[email protected]>
Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>
---
 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
drivers/usb/chipidea/Makefile +4 -0
index cc34937..266d57d 100644
@@ -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
drivers/usb/chipidea/ci13xxx_mxs.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
1.7.10
#21 lore raw

PATCH 6/8 CI13xxx: Add i.MX233/i.MX28 binding code

Quoted 29 lines · Marek Vasut

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

Cc Alan Stern <[email protected]>
Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>
---
 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
drivers/usb/chipidea/Makefile +0 -0
index cc34937..266d57d 100644

drivers/usb/chipidea/Makefile endif · line 18

Quoted 7 lines
drivers/usb/chipidea/Makefile +4 -0
@@ -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.

Quoted 113 lines
drivers/usb/chipidea/ci13xxx_mxs.c new file +107 -0
new file mode 100644
index 0000000..fcca90b
@@ -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 <[email protected]>
+ * 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 */

drivers/usb/chipidea/ci13xxx_mxs.c line 117

Quoted 10 lines
drivers/usb/chipidea/ci13xxx_mxs.c new file +10 -0
+	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 ?

Signature · 8 lines
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>
#22 lore raw

PATCH v8 6/8 CI13xxx: Add i.MX233/i.MX28 binding code

Dear Felipe Balbi,

Quoted 36 lines · Marek Vasut
Quoted 35 lines

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

Cc Alan Stern <[email protected]>
Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>

---

 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
(quoted diff) +0 -0

b/drivers/usb/chipidea/Makefile index cc34937..266d57d 100644

drivers/usb/chipidea/Makefile +0 -0
@@ -12,3 +12,7 @@ endif
 
 ifneq ($(CONFIG_ARCH_MSM),)
 
 	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
Quoted 8 lines

drivers/usb/chipidea/Makefile endif · line 18

Quoted 6 lines

endif

drivers/usb/chipidea/Makefile +4 -0
+
+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.

Quoted 117 lines
Quoted 117 lines
(quoted diff) +0 -0

b/drivers/usb/chipidea/ci13xxx_mxs.c new file mode 100644 index 0000000..fcca90b

drivers/usb/chipidea/ci13xxx_mxs.c new file +111 -0
@@ -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 <[email protected]>
+ * 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) {
Quoted 8 lines

drivers/usb/chipidea/ci13xxx_mxs.c line 117

Quoted 6 lines
drivers/usb/chipidea/ci13xxx_mxs.c new file +6 -0
+		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 :)

#23 lore raw

PATCH 6/8 CI13xxx: Add i.MX233/i.MX28 binding code

Quoted 47 lines · Marek Vasut

Dear Felipe Balbi,

Quoted 36 lines · Marek Vasut
Quoted 35 lines

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

Cc Alan Stern <[email protected]>
Cc Detlev Zundel <[email protected]>
CC Dong Aisheng <[email protected]>
CC Fabio Estevam <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Linux ARM kernel <[email protected]>
Cc linux-i2c at vger.kernel.org
CC Sascha Hauer <[email protected]>
CC Shawn Guo <[email protected]>
Cc Stefano Babic <[email protected]>
CC Uwe Kleine-K?nig <[email protected]>
Cc Wolfgang Denk <[email protected]>
Cc Wolfram Sang <[email protected]>

---

 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
(quoted diff) +0 -0

b/drivers/usb/chipidea/Makefile index cc34937..266d57d 100644

drivers/usb/chipidea/Makefile +0 -0
@@ -12,3 +12,7 @@ endif
 
 ifneq ($(CONFIG_ARCH_MSM),)
 
 	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_msm.o
Quoted 8 lines

drivers/usb/chipidea/Makefile endif · line 18

Quoted 6 lines

endif

drivers/usb/chipidea/Makefile +4 -0
+
+ifneq ($(CONFIG_ARCH_MXS),)
+	obj-$(CONFIG_USB_CHIPIDEA)	+= ci13xxx_mxs.o
+endif

NAK... let it compile everywhere.

Quoted 2 lines

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.

Quoted 6 lines
Quoted 4 lines

drivers/usb/chipidea/Makefile

Quoted 2 lines
drivers/usb/chipidea/Makefile +2 -0
+	*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 ;-)

Signature · 8 lines
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>
#24 lore raw

PATCH v8 7/8 MXS: Add platform registration hooks for USB EHCI

In reply to Marek Vasut

Based on code by:
Tony Lin <[email protected]>

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 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
arch/arm/mach-mxs/devices-mx28.h +5 -0
index 9dbeae1..04a9120 100644
@@ -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);
 
arch/arm/mach-mxs/devices/Kconfig +3 -0
index b8913df..f6709bc 100644
@@ -32,3 +32,6 @@ config MXS_HAVE_PLATFORM_MXS_SAIF
 
 config MXS_HAVE_PLATFORM_RTC_STMP3XXX
 	bool
+
+config MXS_HAVE_PLATFORM_USB
+	bool
arch/arm/mach-mxs/devices/Makefile +1 -0
index c8f5c95..be4cc9e 100644
@@ -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
arch/arm/mach-mxs/devices/platform-usb.c new file +84 -0

84 lines not on this page · raw message

arch/arm/mach-mxs/include/mach/devices-common.h +13 -0
index f2e3839..e1339ed 100644
@@ -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 {
Signature · 1 line
1.7.10
#25 lore raw

PATCH v8 8/8 MXS: Enable USB on M28EVK

In reply to Marek Vasut

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.

Cc Chen Peter-B29397 <[email protected]>
Cc Detlev Zundel <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Li Frank-B20596 <[email protected]>
Cc Linux USB <[email protected]>
Cc Liu JunJie-B08287 <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Shi Make-B15407 <[email protected]>
Cc Stefano Babic <[email protected]>
Cc Subodh Nijsure <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/arm/mach-mxs/Kconfig       |    2 ++
 arch/arm/mach-mxs/mach-m28evk.c |   19 +++++++++++++++++++
 2 files changed, 21 insertions(+)
arch/arm/mach-mxs/Kconfig +2 -0
index c57f996..05f6e84 100644
@@ -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
arch/arm/mach-mxs/mach-m28evk.c +19 -0
index 06d7996..fc2dd2d 100644
@@ -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)
Signature · 1 line
1.7.10