Skip to contentSkip to conversation

Add USB Host and OTG support for MPC5121 SoC

PATCH In review Anatolij Gustschin 4 participants 12 messages Apr 27, 2010 – Jun 11, 2010 2 messages not in the archive

Subsystems (5)
lore
Share & tools
lore

Anatolij Gustschin

author maintainer
#0 lore raw

cover Add USB Host and OTG support for MPC5121 SoC

Anatolij Gustschin (4):
powerpc/fsl_soc.c: prepare for addition of mpc5121 USB code powerpc/mpc5121: add USB host support
USB: add USB OTG support for MPC5121 SoC powerpc/mpc5121: select options for USB OTG support

 Documentation/powerpc/dts-bindings/fsl/usb.txt |   22 +
 arch/powerpc/include/asm/fsl_usb_io.h          |  106 +++
 arch/powerpc/platforms/512x/Kconfig            |   11 +
 arch/powerpc/platforms/512x/Makefile           |    2 +-
 arch/powerpc/platforms/512x/mpc5121_usb.c      |  131 +++
 arch/powerpc/platforms/512x/mpc512x.h          |    1 +
 arch/powerpc/platforms/512x/mpc512x_shared.c   |    1 +
 arch/powerpc/sysdev/fsl_soc.c                  |  249 +++---
 arch/powerpc/sysdev/fsl_soc.h                  |    9 +
 drivers/usb/gadget/fsl_udc_core.c              |  357 ++++++--
 drivers/usb/gadget/fsl_usb2_udc.h              |   14 +
 drivers/usb/host/ehci-fsl.c                    |  372 ++++++--
 drivers/usb/host/ehci-fsl.h                    |   22 +-
 drivers/usb/host/ehci-hub.c                    |   39 +
 drivers/usb/host/ehci-mem.c                    |    2 +-
 drivers/usb/host/ehci.h                        |    5 +
 drivers/usb/otg/Kconfig                        |    8 +
 drivers/usb/otg/Makefile                       |    2 +
 drivers/usb/otg/fsl_otg.c                      | 1199 ++++++++++++++++++++++++
 drivers/usb/otg/fsl_otg.h                      |  418 +++++++++
 drivers/usb/otg/otg.c                          |   17 +
 drivers/usb/otg/otg_fsm.c                      |  368 ++++++++
 drivers/usb/otg/otg_fsm.h                      |  154 +++
 include/linux/fsl_devices.h                    |   28 +
 24 files changed, 3285 insertions(+), 252 deletions(-)
 create mode 100644 arch/powerpc/include/asm/fsl_usb_io.h
 create mode 100644 arch/powerpc/platforms/512x/mpc5121_usb.c
 create mode 100644 drivers/usb/otg/fsl_otg.c
 create mode 100644 drivers/usb/otg/fsl_otg.h
 create mode 100644 drivers/usb/otg/otg_fsm.c
 create mode 100644 drivers/usb/otg/otg_fsm.h

A message that is not in the archive (sent off-list or not yet received): 1272384698-4359-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org

#2 lore raw

PATCH 2/4 powerpc/mpc5121: add USB host support

Platform specific code for MPC5121 USB Host support.

The patch also contains changes to FSL EHCI platform driver needed to support MPC5121 USB controllers. MPC5121 Rev 2.0 silicon EHCI registers are in big endian format. The appropriate flags are set using the information in the platform data structure. 83xx system interface registers are not available on 512x, so the access to these registers is isolated for 512x. Furthermore the USB controller clock must be enabled before 512x register access which is done by providing platform specific init callback.

The 512x internal USB PHY doesn't provide supply voltage. For boards using different power switches allow specifying DRVVBUS and PWR_FAULT signal polarity of the MPC5121 internal PHY using "fsl,invert-drvvbus" and "fsl,invert-pwr-fault" properties in the device tree USB node.

Cc David Brownell <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Kumar Gala <[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]
---
 Documentation/powerpc/dts-bindings/fsl/usb.txt |   22 ++++
 arch/powerpc/platforms/512x/Kconfig            |    3 +
 arch/powerpc/platforms/512x/Makefile           |    2 +-
 arch/powerpc/platforms/512x/mpc5121_usb.c      |  131 ++++++++++++++++++++++++
 arch/powerpc/platforms/512x/mpc512x.h          |    1 +
 arch/powerpc/platforms/512x/mpc512x_shared.c   |    1 +
 arch/powerpc/sysdev/fsl_soc.c                  |   20 ++++
 arch/powerpc/sysdev/fsl_soc.h                  |    9 ++
 drivers/usb/host/ehci-fsl.c                    |  111 +++++++++++++++------
 drivers/usb/host/ehci-fsl.h                    |   19 ++++-
 drivers/usb/host/ehci-mem.c                    |    2 +-
 include/linux/fsl_devices.h                    |   13 +++
 12 files changed, 301 insertions(+), 33 deletions(-)
 create mode 100644 arch/powerpc/platforms/512x/mpc5121_usb.c
Documentation/powerpc/dts-bindings/fsl/usb.txt +22 -0
index b001524..bd5723f 100644
@@ -8,6 +8,7 @@ and additions :
 Required properties :
  - compatible : Should be "fsl-usb2-mph" for multi port host USB
    controllers, or "fsl-usb2-dr" for dual role USB controllers
+   or "fsl,mpc5121-usb2-dr" for dual role USB controllers of MPC5121
  - phy_type : For multi port host USB controllers, should be one of
    "ulpi", or "serial". For dual role USB controllers, should be
    one of "ulpi", "utmi", "utmi_wide", or "serial".
@@ -33,6 +34,12 @@ Recommended properties :
  - interrupt-parent : the phandle for the interrupt controller that
    services interrupts for this device.
 
+Optional properties :
+ - fsl,invert-drvvbus : boolean; for MPC5121 USB0 only. Indicates the
+   port power polarity of internal PHY signal DRVVBUS is inverted.
+ - fsl,invert-pwr-fault : boolean; for MPC5121 USB0 only. Indicates
+   the PWR_FAULT signal polarity is inverted.
+
 Example multi port host USB controller device node :
 	usb@22000 {
 		compatible = "fsl-usb2-mph";
@@ -57,3 +64,18 @@ Example dual role USB controller device node :
 		dr_mode = "otg";
 		phy = "ulpi";
 	};
+
+Example dual role USB controller device node for MPC5121ADS:
+
+	usb@4000 {
+		compatible = "fsl,mpc5121-usb2-dr";
+		reg = <0x4000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		interrupt-parent = < &ipic >;
+		interrupts = <44 0x8>;
+		dr_mode = "otg";
+		phy_type = "utmi_wide";
+		fsl,invert-drvvbus;
+		fsl,invert-pwr-fault;
+	};
arch/powerpc/platforms/512x/Kconfig +3 -0
index 4dac9b0..fed7b5d 100644
@@ -9,6 +9,9 @@ config PPC_MPC512x
 config PPC_MPC5121
 	bool
 	select PPC_MPC512x
+	select USB_ARCH_HAS_EHCI
+	select USB_EHCI_BIG_ENDIAN_DESC
+	select USB_EHCI_BIG_ENDIAN_MMIO
 
 config MPC5121_ADS
 	bool "Freescale MPC5121E ADS"
arch/powerpc/platforms/512x/Makefile +1 -1
index 90be2f5..49adabc 100644
@@ -1,6 +1,6 @@
 #
 # Makefile for the Freescale PowerPC 512x linux kernel.
 #
-obj-y				+= clock.o mpc512x_shared.o
+obj-y				+= clock.o mpc512x_shared.o mpc5121_usb.o
 obj-$(CONFIG_MPC5121_ADS)	+= mpc5121_ads.o mpc5121_ads_cpld.o
 obj-$(CONFIG_MPC5121_GENERIC)	+= mpc5121_generic.o
arch/powerpc/platforms/512x/mpc5121_usb.c new file +131 -0

131 lines not on this page · raw message

arch/powerpc/platforms/512x/mpc512x.h +1 -0
index b2daca0..fd6462f 100644
@@ -16,4 +16,5 @@ extern void __init mpc512x_init(void);
 extern int __init mpc5121_clk_init(void);
 void __init mpc512x_declare_of_platform_devices(void);
 extern void mpc512x_restart(char *cmd);
+extern void mpc5121_usb_init(void);
 #endif				/* __MPC512X_H__ */
arch/powerpc/platforms/512x/mpc512x_shared.c +1 -0
index b7f518a..fbdf65f 100644
@@ -100,4 +100,5 @@ void __init mpc512x_init(void)
 	mpc512x_declare_of_platform_devices();
 	mpc5121_clk_init();
 	mpc512x_restart_init();
+	mpc5121_usb_init();
 }
arch/powerpc/sysdev/fsl_soc.c +20 -0
index 976218c..67fc801 100644
@@ -209,6 +209,9 @@ static int __init of_add_fixed_phys(void)
 arch_initcall(of_add_fixed_phys);
 #endif /* CONFIG_FIXED_PHY */
 
+struct fsl_platform_usb_ops fsl_platform_usb_ops;
+EXPORT_SYMBOL(fsl_platform_usb_ops);
+
 struct fsl_usb2_dev_data {
 	char *dr_mode;		/* controller mode */
 	char *drivers[3];	/* drivers to instantiate for this mode */
@@ -357,6 +360,23 @@ static int __init fsl_usb_of_init(void)
 			return ret;
 	}
 
+	for_each_compatible_node(np, NULL, "fsl,mpc5121-usb2-dr") {
+		memset(&pdata, 0, sizeof(pdata));
+		pdata.platform_init = fsl_platform_usb_ops.init;
+		pdata.platform_uninit = fsl_platform_usb_ops.uninit;
+
+		if (of_get_property(np, "fsl,invert-drvvbus", NULL))
+			pdata.invert_drvvbus = 1;
+
+		if (of_get_property(np, "fsl,invert-pwr-fault", NULL))
+			pdata.invert_pwr_fault = 1;
+
+		ret = fsl_usb2_register_device(np, get_dr_data(np),
+						&pdata, idx++);
+		if (ret)
+			return ret;
+	}
+
 	return 0;
 }
 arch_initcall(fsl_usb_of_init);
arch/powerpc/sysdev/fsl_soc.h +9 -0
index 42381bb..19754be 100644
@@ -35,5 +35,14 @@ struct platform_diu_data_ops {
 extern struct platform_diu_data_ops diu_ops;
 #endif
 
+struct platform_device;
+
+struct fsl_platform_usb_ops {
+	int (*init)(struct platform_device *);
+	void (*uninit)(struct platform_device *);
+};
+
+extern struct fsl_platform_usb_ops fsl_platform_usb_ops;
+
 #endif
 #endif
drivers/usb/host/ehci-fsl.c +81 -30

191 lines not on this page · raw message

drivers/usb/host/ehci-fsl.h +18 -1
index b5e59db..faeaea5 100644
@@ -1,4 +1,4 @@
-/* Copyright (c) 2005 freescale semiconductor
+/* Copyright (C) 2005-2009 Freescale Semiconductor, Inc. All rights reserved.
  * Copyright (c) 2005 MontaVista Software
  *
  * This program is free software; you can redistribute  it and/or modify it
@@ -19,6 +19,11 @@
 #define _EHCI_FSL_H
 
 /* offsets for the non-ehci registers in the FSL SOC USB controller */
+#define FSL_SOC_USB_ID		0x0
+#define ID_MSK			0x3f
+#define NID_MSK			0x3f00
+#define FSL_SOC_USB_SBUSCFG	0x90
+#define FSL_SOC_USB_BURSTSIZE	0x160
 #define FSL_SOC_USB_ULPIVP	0x170
 #define FSL_SOC_USB_PORTSC1	0x184
 #define PORT_PTS_MSK		(3<<30)
@@ -26,8 +31,20 @@
 #define PORT_PTS_ULPI		(2<<30)
 #define	PORT_PTS_SERIAL		(3<<30)
 #define PORT_PTS_PTW		(1<<28)
+#define PORT_PTS_PHCD		(1<<23)
 #define FSL_SOC_USB_PORTSC2	0x188
 #define FSL_SOC_USB_USBMODE	0x1a8
+#define USBMODE_CM_MASK		(3 << 0)	/* controller mode mask */
+#define USBMODE_CM_HOST		(3 << 0)	/* controller mode: host */
+#define USBMODE_ES		(1 << 2)	/* (Big) Endian Select */
+
+#define FSL_SOC_USB_USBGENCTRL	0x200
+#define USBGENCTRL_PPP		(1 << 3)
+#define USBGENCTRL_PFP		(1 << 2)
+#define FSL_SOC_USB_ISIPHYCTRL	0x204
+#define ISIPHYCTRL_PXE		(1)
+#define ISIPHYCTRL_PHYE		(1 << 4)
+
 #define FSL_SOC_USB_SNOOP1	0x400	/* NOTE: big-endian */
 #define FSL_SOC_USB_SNOOP2	0x404	/* NOTE: big-endian */
 #define FSL_SOC_USB_AGECNTTHRSH	0x408	/* NOTE: big-endian */
drivers/usb/host/ehci-mem.c +1 -1
index 1f3f01e..d36e4e7 100644
@@ -40,7 +40,7 @@ static inline void ehci_qtd_init(struct ehci_hcd *ehci, struct ehci_qtd *qtd,
 {
 	memset (qtd, 0, sizeof *qtd);
 	qtd->qtd_dma = dma;
-	qtd->hw_token = cpu_to_le32 (QTD_STS_HALT);
+	qtd->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
 	qtd->hw_next = EHCI_LIST_END(ehci);
 	qtd->hw_alt_next = EHCI_LIST_END(ehci);
 	INIT_LIST_HEAD (&qtd->qtd_list);
include/linux/fsl_devices.h +13 -0
index 28e33fe..7e64112 100644
@@ -58,11 +58,24 @@ enum fsl_usb2_phy_modes {
 	FSL_USB2_PHY_SERIAL,
 };
 
+struct platform_device;
 struct fsl_usb2_platform_data {
 	/* board specific information */
 	enum fsl_usb2_operating_modes	operating_mode;
 	enum fsl_usb2_phy_modes		phy_mode;
 	unsigned int			port_enables;
+
+	char				*name;		/* pretty print */
+	int (*platform_init) (struct platform_device *);
+	void (*platform_uninit) (struct platform_device *);
+	void __iomem			*regs;	/* ioremap'd register base */
+	unsigned			big_endian_mmio:1;
+	unsigned			big_endian_desc:1;
+	unsigned			es:1;		/* need USBMODE:ES */
+	unsigned			have_sysif_regs:1;
+	unsigned			invert_drvvbus:1;
+	unsigned			invert_pwr_fault:1;
+	unsigned			le_setup_buf:1;
 };
 
 /* Flags in fsl_usb2_mph_platform_data */
Signature · 6 lines
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1272384698-4359-3-git-send-email-agust-ynQEQJNshbs@public.gmane.org

#4 lore raw

Re: [PATCH 2/4] powerpc/mpc5121: add USB host support

Quoted 75 lines · Anatolij Gustschin

Platform specific code for MPC5121 USB Host support.

The patch also contains changes to FSL EHCI platform driver needed to support MPC5121 USB controllers. MPC5121 Rev 2.0 silicon EHCI registers are in big endian format. The appropriate flags are set using the information in the platform data structure. 83xx system interface registers are not available on 512x, so the access to these registers is isolated for 512x. Furthermore the USB controller clock must be enabled before 512x register access which is done by providing platform specific init callback.

The 512x internal USB PHY doesn't provide supply voltage. For boards using different power switches allow specifying DRVVBUS and PWR_FAULT signal polarity of the MPC5121 internal PHY using "fsl,invert-drvvbus" and "fsl,invert-pwr-fault" properties in the device tree USB node.

Cc David Brownell <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Kumar Gala <[email protected]>
Cc devicetree-discuss-uLR06cmDAlY/[email protected]

---
 Documentation/powerpc/dts-bindings/fsl/usb.txt |   22 ++++ arch/powerpc/platforms/512x/Kconfig            |    3 + arch/powerpc/platforms/512x/Makefile           |    2 +- arch/powerpc/platforms/512x/mpc5121_usb.c      |  131 ++++++++++++++++++++++++ arch/powerpc/platforms/512x/mpc512x.h          |    1 + arch/powerpc/platforms/512x/mpc512x_shared.c   |    1 + arch/powerpc/sysdev/fsl_soc.c                  |   20 ++++ arch/powerpc/sysdev/fsl_soc.h                  |    9 ++

 drivers/usb/host/ehci-fsl.c                    |  111 +++++++++++++++------
 drivers/usb/host/ehci-fsl.h                    |   19 ++++-
 drivers/usb/host/ehci-mem.c                    |    2 +-
 include/linux/fsl_devices.h                    |   13 +++
 12 files changed, 301 insertions(+), 33 deletions(-)

 create mode 100644 arch/powerpc/platforms/512x/mpc5121_usb.c

Documentation/powerpc/dts-bindings/fsl/usb.txt +0 -0
index b001524..bd5723f 100644
@@ -8,6 +8,7 @@ and additions :

 Required properties :
 - compatible : Should be "fsl-usb2-mph" for multi port host USB controllers, or "fsl-usb2-dr" for dual role USB controllers
+   or "fsl,mpc5121-usb2-dr" for dual role USB controllers of MPC5121
 - phy_type : For multi port host USB controllers, should be one of "ulpi", or "serial". For dual role USB controllers, should be one of "ulpi", "utmi", "utmi_wide", or "serial".

Documentation/powerpc/dts-bindings/fsl/usb.txt +0 -0
@@ -33,6 +34,12 @@ Recommended properties :

 - interrupt-parent : the phandle for the interrupt controller that services interrupts for this device.

Documentation/powerpc/dts-bindings/fsl/usb.txt +6 -0
+Optional properties :
+ - fsl,invert-drvvbus : boolean; for MPC5121 USB0 only. Indicates the
+   port power polarity of internal PHY signal DRVVBUS is inverted.
+ - fsl,invert-pwr-fault : boolean; for MPC5121 USB0 only. Indicates
+   the PWR_FAULT signal polarity is inverted.
+

 Example multi port host USB controller device node :
       usb@22000 {
               compatible = "fsl-usb2-mph";

Documentation/powerpc/dts-bindings/fsl/usb.txt +5 -0
@@ -57,3 +64,18 @@ Example dual role USB controller device node :
                dr_mode = "otg";
                phy = "ulpi";
        };
+
+Example dual role USB controller device node for MPC5121ADS:
+
+       usb@4000 {
+               compatible = "fsl,mpc5121-usb2-dr";

Documentation/powerpc/dts-bindings/fsl/usb.txt Example dual role USB controller device node : · line 81

Quoted 10 lines
Documentation/powerpc/dts-bindings/fsl/usb.txt +10 -0
+               reg = <0x4000 0x1000>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+               interrupt-parent = < &ipic >;
+               interrupts = <44 0x8>;
+               dr_mode = "otg";
+               phy_type = "utmi_wide";
+               fsl,invert-drvvbus;
+               fsl,invert-pwr-fault;
+       };

This modification to the device binding looks fine to me.

Cheers,
g.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#5 lore raw

PATCH 1/4 powerpc/fsl_soc.c: prepare for addition of mpc5121 USB code

In reply to Anatolij Gustschin

Factor out common code for registering a FSL EHCI platform device into new fsl_usb2_register_device() function. This is done to avoid code duplication while adding code for instantiating of MPC5121 dual role USB platform devices. Then, the subsequent patch can use

for_each_compatible_node(np, NULL, "fsl,mpc5121-usb2-dr") {
        ...
        fsl_usb2_register_device();
}
---
 arch/powerpc/sysdev/fsl_soc.c |  231 +++++++++++++++++++---------------------
 1 files changed, 110 insertions(+), 121 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +110 -121
index b91f7ac..976218c 100644
@@ -209,6 +209,49 @@ static int __init of_add_fixed_phys(void)
 arch_initcall(of_add_fixed_phys);
 #endif /* CONFIG_FIXED_PHY */
 
+struct fsl_usb2_dev_data {
+	char *dr_mode;		/* controller mode */
+	char *drivers[3];	/* drivers to instantiate for this mode */
+	enum fsl_usb2_operating_modes op_mode;	/* operating mode */
+};
+
+struct fsl_usb2_dev_data dr_data[] __initdata = {
+	{
+		"host",
+		{ "fsl-ehci", NULL, NULL, },
+		FSL_USB2_DR_HOST,
+	},
+	{
+		"otg",
+		{ "fsl-ehci", "fsl-usb2-udc", "fsl-usb2-otg", },
+		FSL_USB2_DR_OTG,
+	},
+	{
+		"periferal",
+		{ "fsl-usb2-udc", NULL, NULL, },
+		FSL_USB2_DR_DEVICE,
+	},
+};
+
+struct fsl_usb2_dev_data mph_data[] __initdata = {
+	{ NULL,		{ "fsl-ehci",	NULL,		}, FSL_USB2_MPH_HOST, },
+};
+
+struct fsl_usb2_dev_data * __init get_dr_data(struct device_node *np)
+{
+	const unsigned char *prop;
+	int i;
+
+	prop = of_get_property(np, "dr_mode", NULL);
+	if (prop) {
+		for (i = 0; i < ARRAY_SIZE(dr_data); i++) {
+			if (!strcmp(prop, dr_data[i].dr_mode))
+				return &dr_data[i];
+		}
+	}
+	return &dr_data[0]; /* mode not specified, use host */
+}
+
 static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
 {
 	if (!phy_type)
@@ -225,151 +268,97 @@ static enum fsl_usb2_phy_modes determine_usb_phy(const char *phy_type)
 	return FSL_USB2_PHY_NONE;
 }
 
-static int __init fsl_usb_of_init(void)
+int __init fsl_usb2_register_device(struct device_node *np,
+			struct fsl_usb2_dev_data *dev_data,
+			struct fsl_usb2_platform_data *pdata,
+			unsigned int idx)
 {
-	struct device_node *np;
-	unsigned int i = 0;
-	struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
-		*usb_dev_dr_client = NULL;
+	struct platform_device *usb_dev;
+	const unsigned char *prop;
+	struct resource r[2];
+	int registered = 0;
 	int ret;
+	int i;
+
+	if (!(dev_data && pdata))
+		return -EINVAL;
+
+	memset(&r, 0, sizeof(r));
+	ret = of_address_to_resource(np, 0, &r[0]);
+	if (ret)
+		return -ENODEV;
+
+	ret = of_irq_to_resource(np, 0, &r[1]);
+	if (ret == NO_IRQ)
+		return -ENODEV;
+
+	pdata->operating_mode = dev_data->op_mode;
+
+	prop = of_get_property(np, "phy_type", NULL);
+	pdata->phy_mode = determine_usb_phy(prop);
+	ret = 0;
+	for (i = 0; i < ARRAY_SIZE(dev_data->drivers); i++) {
+		if (!dev_data->drivers[i])
+			break;
+		usb_dev = platform_device_register_simple(
+					dev_data->drivers[i], idx, r, 2);
+		if (IS_ERR(usb_dev)) {
+			ret = PTR_ERR(usb_dev);
+			goto out;
+		}
 
-	for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
-		struct resource r[2];
-		struct fsl_usb2_platform_data usb_data;
-		const unsigned char *prop = NULL;
-
-		memset(&r, 0, sizeof(r));
-		memset(&usb_data, 0, sizeof(usb_data));
-
-		ret = of_address_to_resource(np, 0, &r[0]);
+		usb_dev->dev.coherent_dma_mask = 0xffffffffUL;
+		usb_dev->dev.dma_mask = &usb_dev->dev.coherent_dma_mask;
+		ret = platform_device_add_data(usb_dev, pdata,
+				sizeof(struct fsl_usb2_platform_data));
 		if (ret)
-			goto err;
-
-		of_irq_to_resource(np, 0, &r[1]);
-
-		usb_dev_mph =
-		    platform_device_register_simple("fsl-ehci", i, r, 2);
-		if (IS_ERR(usb_dev_mph)) {
-			ret = PTR_ERR(usb_dev_mph);
-			goto err;
-		}
+			platform_device_unregister(usb_dev);
+		else
+			registered++;
+	}
+out:
+	if (!registered)
+		irq_dispose_mapping(r[1].end);
 
-		usb_dev_mph->dev.coherent_dma_mask = 0xffffffffUL;
-		usb_dev_mph->dev.dma_mask = &usb_dev_mph->dev.coherent_dma_mask;
+	return ret;
+}
 
-		usb_data.operating_mode = FSL_USB2_MPH_HOST;
+static int __init fsl_usb_of_init(void)
+{
+	struct device_node *np;
+	const unsigned char *prop;
+	struct fsl_usb2_platform_data pdata;
+	unsigned int idx = 0;
+	int ret;
 
+	for_each_compatible_node(np, NULL, "fsl-usb2-mph") {
+		memset(&pdata, 0, sizeof(pdata));
 		prop = of_get_property(np, "port0", NULL);
 		if (prop)
-			usb_data.port_enables |= FSL_USB2_PORT0_ENABLED;
+			pdata.port_enables |= FSL_USB2_PORT0_ENABLED;
 
 		prop = of_get_property(np, "port1", NULL);
 		if (prop)
-			usb_data.port_enables |= FSL_USB2_PORT1_ENABLED;
+			pdata.port_enables |= FSL_USB2_PORT1_ENABLED;
 
-		prop = of_get_property(np, "phy_type", NULL);
-		usb_data.phy_mode = determine_usb_phy(prop);
-
-		ret =
-		    platform_device_add_data(usb_dev_mph, &usb_data,
-					     sizeof(struct
-						    fsl_usb2_platform_data));
+		ret = fsl_usb2_register_device(np, mph_data, &pdata, idx++);
 		if (ret)
-			goto unreg_mph;
-		i++;
+			return ret;
 	}
 
 	for_each_compatible_node(np, NULL, "fsl-usb2-dr") {
-		struct resource r[2];
-		struct fsl_usb2_platform_data usb_data;
-		const unsigned char *prop = NULL;
-
 		if (!of_device_is_available(np))
 			continue;
 
-		memset(&r, 0, sizeof(r));
-		memset(&usb_data, 0, sizeof(usb_data));
-
-		ret = of_address_to_resource(np, 0, &r[0]);
+		memset(&pdata, 0, sizeof(pdata));
+		ret = fsl_usb2_register_device(np, get_dr_data(np),
+						&pdata, idx++);
 		if (ret)
-			goto unreg_mph;
-
-		of_irq_to_resource(np, 0, &r[1]);
-
-		prop = of_get_property(np, "dr_mode", NULL);
-
-		if (!prop || !strcmp(prop, "host")) {
-			usb_data.operating_mode = FSL_USB2_DR_HOST;
-			usb_dev_dr_host = platform_device_register_simple(
-					"fsl-ehci", i, r, 2);
-			if (IS_ERR(usb_dev_dr_host)) {
-				ret = PTR_ERR(usb_dev_dr_host);
-				goto err;
-			}
-		} else if (prop && !strcmp(prop, "peripheral")) {
-			usb_data.operating_mode = FSL_USB2_DR_DEVICE;
-			usb_dev_dr_client = platform_device_register_simple(
-					"fsl-usb2-udc", i, r, 2);
-			if (IS_ERR(usb_dev_dr_client)) {
-				ret = PTR_ERR(usb_dev_dr_client);
-				goto err;
-			}
-		} else if (prop && !strcmp(prop, "otg")) {
-			usb_data.operating_mode = FSL_USB2_DR_OTG;
-			usb_dev_dr_host = platform_device_register_simple(
-					"fsl-ehci", i, r, 2);
-			if (IS_ERR(usb_dev_dr_host)) {
-				ret = PTR_ERR(usb_dev_dr_host);
-				goto err;
-			}
-			usb_dev_dr_client = platform_device_register_simple(
-					"fsl-usb2-udc", i, r, 2);
-			if (IS_ERR(usb_dev_dr_client)) {
-				ret = PTR_ERR(usb_dev_dr_client);
-				goto err;
-			}
-		} else {
-			ret = -EINVAL;
-			goto err;
-		}
-
-		prop = of_get_property(np, "phy_type", NULL);
-		usb_data.phy_mode = determine_usb_phy(prop);
-
-		if (usb_dev_dr_host) {
-			usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
-			usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
-				dev.coherent_dma_mask;
-			if ((ret = platform_device_add_data(usb_dev_dr_host,
-						&usb_data, sizeof(struct
-						fsl_usb2_platform_data))))
-				goto unreg_dr;
-		}
-		if (usb_dev_dr_client) {
-			usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
-			usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
-				dev.coherent_dma_mask;
-			if ((ret = platform_device_add_data(usb_dev_dr_client,
-						&usb_data, sizeof(struct
-						fsl_usb2_platform_data))))
-				goto unreg_dr;
-		}
-		i++;
+			return ret;
 	}
-	return 0;
 
-unreg_dr:
-	if (usb_dev_dr_host)
-		platform_device_unregister(usb_dev_dr_host);
-	if (usb_dev_dr_client)
-		platform_device_unregister(usb_dev_dr_client);
-unreg_mph:
-	if (usb_dev_mph)
-		platform_device_unregister(usb_dev_mph);
-err:
-	return ret;
+	return 0;
 }
-
 arch_initcall(fsl_usb_of_init);
 
 #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
Signature · 1 line
1.6.3.3
#6 lore raw

Re: [PATCH 1/4] powerpc/fsl_soc.c: prepare for addition of mpc5121 USB code

Quoted 10 lines · Anatolij Gustschin

Factor out common code for registering a FSL EHCI platform device into new fsl_usb2_register_device() function. This is done to avoid code duplication while adding code for instantiating of MPC5121 dual role USB platform devices. Then, the subsequent patch can use for_each_compatible_node(np, NULL, "fsl,mpc5121-usb2-dr") { =A0 =A0 =A0 =A0...
=A0 =A0 =A0 =A0fsl_usb2_register_device();
}

Quoted 5 lines

---
=A0arch/powerpc/sysdev/fsl_soc.c | =A0231 +++++++++++++++++++------------=

---------

Hi Anatolij,

Thanks for this work. However, I've got concerns.

Forgive me for ragging on code that you didn't write, but this fsl_soc.c code for registering the USB device really doesn't belong here anymore. It should be part of the drivers/usb/host/ehci-fsl.c and the driver should do of-style binding (Which should be a lot easier if I manage to get the merge of platform bus and of_platform bus into 2.6.35).

This patch series makes the fsl_soc.c code even more complicated, and scatters what is essentially driver code over even more places in the arch/powerpc tree. I'm really not keen on it being merged in this form.

g.

author maintainer
#7 lore raw

Re: [PATCH 1/4] powerpc/fsl_soc.c: prepare for addition of mpc5121 USB code

Hi Grant,

Quoted 1 line · On Tue, 27 Apr 2010 10:51:21 -0600 Grant Likely <[email protected]>…

On Tue, Apr 27, 2010 at 10:11 AM, Anatolij Gustschin <[email protected]> wrot=

e:

Quoted 10 lines
Quoted 10 lines

Factor out common code for registering a FSL EHCI platform device into new fsl_usb2_register_device() function. This is done to avoid code duplication while adding code for instantiating of MPC5121 dual role USB platform devices. Then, the subsequent patch can use for_each_compatible_node(np, NULL, "fsl,mpc5121-usb2-dr") { =A0 =A0 =A0 =A0...
=A0 =A0 =A0 =A0fsl_usb2_register_device();
}

Quoted 5 lines
Quoted 5 lines

---
=A0arch/powerpc/sysdev/fsl_soc.c | =A0231 +++++++++++++++++++----------=

-----------

Quoted 11 lines

=20
Hi Anatolij,
=20
Thanks for this work. However, I've got concerns.
=20
Forgive me for ragging on code that you didn't write, but this fsl_soc.c code for registering the USB device really doesn't belong here anymore. It should be part of the drivers/usb/host/ehci-fsl.c and the driver should do of-style binding (Which should be a lot easier if I manage to get the merge of platform bus and of_platform bus into 2.6.35).

Now I moved the USB devices registration code to drivers/usb/host/ehci-fsl.c and added of-style binding there. It works for one platform driver based on your test-devicetree branch. It seems I can't bind more than one driver to the device described in the tree. But I need to bind at least 2 drivers, ehci-hcd and fsl-usb2-udc. For USB OTG support I need additional one to be bound to the same USB dual role device (also tree different drivers simultaneously).
I also can't register UDC device in the ehci-fsl.c since registering of the UDC device should also be possible independent of the EHCI-HDC driver (for USB device support we do not need host controller driver). Is it possible to bind more than one driver to the same device simultaneously? If so, how can I implement this?

Quoted 4 lines

This patch series makes the fsl_soc.c code even more complicated, and scatters what is essentially driver code over even more places in the arch/powerpc tree. I'm really not keen on it being merged in this form.

Now I see one reason why it has been originally implemented this way.

Thanks,
Anatolij

#8 lore raw

Re: [PATCH 1/4] powerpc/fsl_soc.c: prepare for addition of mpc5121 USB code

Quoted 6 lines · Anatolij Gustschin

Hi Grant,

Quoted 1 line · On Tue, 27 Apr 2010 10:51:21 -0600 Grant Likely <[email protected]>…

On Tue, Apr 27, 2010 at 10:11 AM, Anatolij Gustschin <[email protected]> wro=

te:

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Factor out common code for registering a FSL EHCI platform device into new fsl_usb2_register_device() function. This is done to avoid code duplication while adding code for instantiating of MPC5121 dual role USB platform devices. Then, the subsequent patch can use for_each_compatible_node(np, NULL, "fsl,mpc5121-usb2-dr") { =A0 =A0 =A0 =A0...
=A0 =A0 =A0 =A0fsl_usb2_register_device();
}

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

---
=A0arch/powerpc/sysdev/fsl_soc.c | =A0231 +++++++++++++++++++---------=

------------

Quoted 12 lines
Quoted 11 lines

Hi Anatolij,

Thanks for this work. =A0However, I've got concerns.

Forgive me for ragging on code that you didn't write, but this fsl_soc.c code for registering the USB device really doesn't belong here anymore. =A0It should be part of the drivers/usb/host/ehci-fsl.c and the driver should do of-style binding (Which should be a lot easier if I manage to get the merge of platform bus and of_platform bus into 2.6.35).

Quoted 13 lines

Now I moved the USB devices registration code to drivers/usb/host/ehci-fsl.c and added of-style binding there. It works for one platform driver based on your test-devicetree branch. It seems I can't bind more than one driver to the device described in the tree. But I need to bind at least 2 drivers, ehci-hcd and fsl-usb2-udc. For USB OTG support I need additional one to be bound to the same USB dual role device (also tree different drivers simultaneously).
I also can't register UDC device in the ehci-fsl.c since registering of the UDC device should also be possible independent of the EHCI-HDC driver (for USB device support we do not need host controller driver). Is it possible to bind more than one driver to the same device simultaneously? If so, how can I implement this?

No, the linux driver model can bind exactly one driver to a struct device. However, that doesn't mean you can't have multiple struct devices (in whatever form they come) to tell the Linux kernel about all the details of a single hardware device.

Quoted 7 lines
Quoted 4 lines

This patch series makes the fsl_soc.c code even more complicated, and scatters what is essentially driver code over even more places in the arch/powerpc tree. =A0I'm really not keen on it being merged in this form.

Now I see one reason why it has been originally implemented this way.

Should be a solvable problem. The fsl_soc.c stuff was originally written simply because the infrastructure wasn't there for doing it any other way. We're long past that point now. I don't have time to dig into the details now (merge window and all), but ping me in a few weeks and I'll take another look to see if I can help you.

g.

author maintainer
#9 lore raw

Re: [PATCH 1/4] powerpc/fsl_soc.c: prepare for addition of mpc5121 USB code

Quoted 7 lines · On Wed, 19 May 2010 14:47:47 -0600 Grant Likely <[email protected]>…
Quoted 6 lines · Anatolij Gustschin

Hi Grant,

Quoted 1 line · On Tue, 27 Apr 2010 10:51:21 -0600 Grant Likely <[email protected]>…

On Tue, Apr 27, 2010 at 10:11 AM, Anatolij Gustschin <[email protected]> w=

rote:

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Factor out common code for registering a FSL EHCI platform device into new fsl_usb2_register_device() function. This is done to avoid code duplication while adding code for instantiating of MPC5121 dual role USB platform devices. Then, the subsequent patch can use for_each_compatible_node(np, NULL, "fsl,mpc5121-usb2-dr") { =C2=A0 =C2=A0 =C2=A0 =C2=A0...
=C2=A0 =C2=A0 =C2=A0 =C2=A0fsl_usb2_register_device(); }

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

---
=C2=A0arch/powerpc/sysdev/fsl_soc.c | =C2=A0231 +++++++++++++++++++-=

--------------------

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Hi Anatolij,

Thanks for this work. =C2=A0However, I've got concerns.

Forgive me for ragging on code that you didn't write, but this fsl_soc.c code for registering the USB device really doesn't belong here anymore. =C2=A0It should be part of the drivers/usb/host/ehci-fsl=

.c

Quoted 28 lines
Quoted 4 lines
Quoted 3 lines

and the driver should do of-style binding (Which should be a lot easier if I manage to get the merge of platform bus and of_platform bus into 2.6.35).

Quoted 13 lines

Now I moved the USB devices registration code to drivers/usb/host/ehci-fsl.c and added of-style binding there. It works for one platform driver based on your test-devicetree branch. It seems I can't bind more than one driver to the device described in the tree. But I need to bind at least 2 drivers, ehci-hcd and fsl-usb2-udc. For USB OTG support I need additional one to be bound to the same USB dual role device (also tree different drivers simultaneously).
I also can't register UDC device in the ehci-fsl.c since registering of the UDC device should also be possible independent of the EHCI-HDC driver (for USB device support we do not need host controller driver). Is it possible to bind more than one driver to the same device simultaneously? If so, how can I implement this?

=20
No, the linux driver model can bind exactly one driver to a struct device. However, that doesn't mean you can't have multiple struct devices (in whatever form they come) to tell the Linux kernel about all the details of a single hardware device.
=20

Quoted 5 lines
Quoted 4 lines

This patch series makes the fsl_soc.c code even more complicated, and scatters what is essentially driver code over even more places in the arch/powerpc tree. =C2=A0I'm really not keen on it being merged in this form.

Quoted 8 lines
Quoted 2 lines

Now I see one reason why it has been originally implemented this way.

=20
Should be a solvable problem. The fsl_soc.c stuff was originally written simply because the infrastructure wasn't there for doing it any other way. We're long past that point now. I don't have time to dig into the details now (merge window and all), but ping me in a few weeks and I'll take another look to see if I can help you.

Hi Grant,

Ping. Do you have any suggestions how to realize this using current infrastructure? Thanks!

Anatolij

#10 lore raw

Re: [PATCH 1/4] powerpc/fsl_soc.c: prepare for addition of mpc5121 USB code

Quoted 4 lines · Anatolij Gustschin
Quoted 1 line · On Wed, 19 May 2010 14:47:47 -0600 Grant Likely <[email protected]>…

On Thu, May 6, 2010 at 1:18 PM, Anatolij Gustschin <[email protected]> wrote=

:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Hi Grant,

Quoted 1 line · On Tue, 27 Apr 2010 10:51:21 -0600 Grant Likely <[email protected]>…

On Tue, Apr 27, 2010 at 10:11 AM, Anatolij Gustschin <[email protected]> =

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Factor out common code for registering a FSL EHCI platform device into new fsl_usb2_register_device() function. This is done to avoid code duplication while adding code for instantiating of MPC5121 dual role USB platform devices. Then, the subsequent patch can use for_each_compatible_node(np, NULL, "fsl,mpc5121-usb2-dr") { =A0 =A0 =A0 =A0...
=A0 =A0 =A0 =A0fsl_usb2_register_device();
}

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

---
=A0arch/powerpc/sysdev/fsl_soc.c | =A0231 +++++++++++++++++++------=

---------------

Quoted 36 lines
Quoted 36 lines
Quoted 12 lines
Quoted 11 lines

Hi Anatolij,

Thanks for this work. =A0However, I've got concerns.

Forgive me for ragging on code that you didn't write, but this fsl_soc.c code for registering the USB device really doesn't belong here anymore. =A0It should be part of the drivers/usb/host/ehci-fsl.c and the driver should do of-style binding (Which should be a lot easier if I manage to get the merge of platform bus and of_platform bus into 2.6.35).

Quoted 13 lines

Now I moved the USB devices registration code to drivers/usb/host/ehci-fsl.c and added of-style binding there. It works for one platform driver based on your test-devicetree branch. It seems I can't bind more than one driver to the device described in the tree. But I need to bind at least 2 drivers, ehci-hcd and fsl-usb2-udc. For USB OTG support I need additional one to be bound to the same USB dual role device (also tree different drivers simultaneously).
I also can't register UDC device in the ehci-fsl.c since registering of the UDC device should also be possible independent of the EHCI-HDC driver (for USB device support we do not need host controller driver). Is it possible to bind more than one driver to the same device simultaneously? If so, how can I implement this?

No, the linux driver model can bind exactly one driver to a struct device. =A0However, that doesn't mean you can't have multiple struct devices (in whatever form they come) to tell the Linux kernel about all the details of a single hardware device.

Quoted 5 lines
Quoted 4 lines

This patch series makes the fsl_soc.c code even more complicated, and scatters what is essentially driver code over even more places in the arch/powerpc tree. =A0I'm really not keen on it being merged in this form.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Now I see one reason why it has been originally implemented this way.

Should be a solvable problem. =A0The fsl_soc.c stuff was originally written simply because the infrastructure wasn't there for doing it any other way. =A0We're long past that point now. =A0I don't have time t=

o

Quoted 7 lines
Quoted 2 lines

dig into the details now (merge window and all), but ping me in a few weeks and I'll take another look to see if I can help you.

Hi Grant,

Ping. Do you have any suggestions how to realize this using current infrastructure? Thanks!

It sounds like the USB OTG controller is effectively a compound device with one host controller and one device controller plus some logic to switch between the two. I'm not a USB expert, so correct me if I'm wrong here.

You've got 2 choices for implementing this:
A) create a 'master' of_driver which registers 2 platform devices it it's probe routine.
B) Rework the drivers so that both fsl-ehci and fsl-usb2-udc bits are called directly (essentially one driver handles both modes)

Option A probably makes the most sense as it has the least amount of impact on current code. Essentially, you create an of_driver and put into it's probe hook the code that is currently in fsl_soc.c. Then it will bind in the normal of_platform_bus_type manner and can register the appropriate platform devices for each platform.

Some important points though; when you create the platform devices, make sure you set the parent pointer correctly so the new devices are registered as children of the of_device.

Second, you can eliminate the call to platform_device_add_data() by setting the of_node pointer in the platform device (the of_node is now part of struct device). Make the driver look up its own data from the device tree instead of passing it in an anonymous data structure.

On that note, the current code looks racy anyway because it registers the device before attaching the platform_data. It's probably okay because of how early it is run and no drivers are registered yet, but it is still wrong. It should be: allocate; add data; then register. But I digress. Eliminating the platform data makes this problem go away.

I hope this helps.

g.

author maintainer
#11 lore raw

PATCH 3/4 USB: add USB OTG support for MPC5121 SoC

In reply to Anatolij Gustschin

Adds Freescale USB OTG driver and extends Freescale USB SoC Device Controller driver and FSL EHCI driver to support OTG operation on MPC5121.

Cc Greg Kroah-Hartman <[email protected]>
Cc David Brownell <[email protected]>
Cc Grant Likely <[email protected]>
---
 arch/powerpc/include/asm/fsl_usb_io.h |  106 +++
 drivers/usb/gadget/fsl_udc_core.c     |  357 ++++++++--
 drivers/usb/gadget/fsl_usb2_udc.h     |   14 +
 drivers/usb/host/ehci-fsl.c           |  261 +++++++-
 drivers/usb/host/ehci-fsl.h           |    3 +
 drivers/usb/host/ehci-hub.c           |   39 ++
 drivers/usb/host/ehci.h               |    5 +
 drivers/usb/otg/Kconfig               |    8 +
 drivers/usb/otg/Makefile              |    2 +
 drivers/usb/otg/fsl_otg.c             | 1199 +++++++++++++++++++++++++++++++++
 drivers/usb/otg/fsl_otg.h             |  418 ++++++++++++
 drivers/usb/otg/otg.c                 |   17 +
 drivers/usb/otg/otg_fsm.c             |  368 ++++++++++
 drivers/usb/otg/otg_fsm.h             |  154 +++++
 include/linux/fsl_devices.h           |   15 +
 15 files changed, 2867 insertions(+), 99 deletions(-)
 create mode 100644 arch/powerpc/include/asm/fsl_usb_io.h
 create mode 100644 drivers/usb/otg/fsl_otg.c
 create mode 100644 drivers/usb/otg/fsl_otg.h
 create mode 100644 drivers/usb/otg/otg_fsm.c
 create mode 100644 drivers/usb/otg/otg_fsm.h
arch/powerpc/include/asm/fsl_usb_io.h new file +106 -0
new file mode 100644
index 0000000..20c42ef
@@ -0,0 +1,106 @@
+/* Copyright (c) 2008 Freescale Semiconductor Inc.
+ *
+ * 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 _FSL_USB_IO_H
+#define _FSL_USB_IO_H
+
+/*
+ * On some SoCs, the USB controller registers can be big or little endian,
+ * depending on the version of the chip.  For these SoCs, the kernel
+ * should be configured with CONFIG_USB_FSL_BIG_ENDIAN_MMIO enabled.
+ *
+ * Platform code for SoCs that have BE USB registers should set
+ * pdata->big_endian_mmio flag.
+ *
+ * In order to be able to run the same kernel binary on 2 different
+ * versions of an SoC, the BE/LE decision must be made at run time.
+ * _fsl_readl and fsl_writel are pointers to the BE or LE readl()
+ * and writel() functions, and fsl_readl() and fsl_writel() call through
+ * those pointers.
+ *
+ * For SoCs with the usual LE USB registers, don't enable
+ * CONFIG_USB_FSL_BIG_ENDIAN_MMIO, and then fsl_readl() and fsl_writel()
+ * are just macro wrappers for in_le32() and out_le32().
+ *
+ * In either (LE or mixed) case, the function fsl_set_usb_accessors()
+ * should be called at probe time, to either set up the readl/writel
+ * function pointers (mixed case), or do nothing (LE case).
+ *
+ * The host USB drivers already have a mechanism to handle BE/LE
+ * registers.  The functionality here is intended to be used by the
+ * gadget and OTG transceiver drivers.
+ *
+ * This file also contains controller-to-cpu accessors for the
+ * USB descriptors, since their endianess is also SoC dependant.
+ * The kernel option CONFIG_USB_FSL_BIG_ENDIAN_DESC configures
+ * which way to go.
+ */
+
+#ifdef CONFIG_USB_FSL_BIG_ENDIAN_MMIO
+static u32 __maybe_unused _fsl_readl_be(const unsigned __iomem *p)
+{
+	return in_be32(p);
+}
+static u32 __maybe_unused _fsl_readl_le(const unsigned __iomem *p)
+{
+	return in_le32(p);
+}
+
+static void __maybe_unused _fsl_writel_be(u32 v, unsigned __iomem *p)
+{
+	out_be32(p, v);
+}
+static void __maybe_unused _fsl_writel_le(u32 v, unsigned __iomem *p)
+{
+	out_le32(p, v);
+}
+
+static u32 (*_fsl_readl)(const unsigned __iomem *p);
+static void (*_fsl_writel)(u32 v, unsigned __iomem *p);
+
+#define fsl_readl(p)		(*_fsl_readl)((p))
+#define fsl_writel(v, p)	(*_fsl_writel)((v), (p))
+
+static inline void fsl_set_usb_accessors(struct fsl_usb2_platform_data *pdata)
+{
+	if (pdata->big_endian_mmio) {
+		_fsl_readl = _fsl_readl_be;
+		_fsl_writel = _fsl_writel_be;
+	} else {
+		_fsl_readl = _fsl_readl_le;
+		_fsl_writel = _fsl_writel_le;
+	}
+}
+
+#else /* CONFIG_USB_FSL_BIG_ENDIAN_MMIO */
+
+#define fsl_readl(addr)		in_le32((addr))
+#define fsl_writel(val32, addr) out_le32((addr), (val32))
+
+static inline void fsl_set_usb_accessors(struct fsl_usb2_platform_data *pdata)
+{
+}
+#endif /* CONFIG_USB_FSL_BIG_ENDIAN_MMIO */
+
+#ifdef CONFIG_USB_FSL_BIG_ENDIAN_DESC
+#define cpu_to_hc32(x)	(x)
+#define hc32_to_cpu(x)	(x)
+#else
+#define cpu_to_hc32(x)	cpu_to_le32((x))
+#define hc32_to_cpu(x)	le32_to_cpu((x))
+#endif
+
+#endif /* _FSL_USB_IO_H */
drivers/usb/gadget/fsl_udc_core.c +290 -67

649 lines not on this page · raw message

drivers/usb/gadget/fsl_usb2_udc.h +14 -0
index 20aecee..fe901f4 100644
@@ -275,7 +275,9 @@ struct usb_sys_interface {
 #define  USB_MODE_CTRL_MODE_IDLE              0x00000000
 #define  USB_MODE_CTRL_MODE_DEVICE            0x00000002
 #define  USB_MODE_CTRL_MODE_HOST              0x00000003
+#define  USB_MODE_CTRL_MODE_MASK              0x00000003
 #define  USB_MODE_CTRL_MODE_RSV               0x00000001
+#define  USB_MODE_ES                          0x00000004 /* Endian Select */
 #define  USB_MODE_SETUP_LOCK_OFF              0x00000008
 #define  USB_MODE_STREAM_DISABLE              0x00000010
 /* Endpoint Flush Register */
@@ -461,6 +463,7 @@ struct fsl_ep {
 struct fsl_udc {
 	struct usb_gadget gadget;
 	struct usb_gadget_driver *driver;
+	struct fsl_usb2_platform_data *pdata;
 	struct completion *done;	/* to make sure release() is done */
 	struct fsl_ep *eps;
 	unsigned int max_ep;
@@ -473,6 +476,7 @@ struct fsl_udc {
 	unsigned vbus_active:1;
 	unsigned stopped:1;
 	unsigned remote_wakeup:1;
+	unsigned already_stopped:1;
 
 	struct ep_queue_head *ep_qh;	/* Endpoints Queue-Head */
 	struct fsl_req *status_req;	/* ep0 status request */
@@ -483,6 +487,7 @@ struct fsl_udc {
 	dma_addr_t ep_qh_dma;		/* dma address of QH */
 
 	u32 max_pipes;          /* Device max pipes */
+	u32 bus_reset;		/* Device is bus reseting */
 	u32 resume_state;	/* USB state to resume */
 	u32 usb_state;		/* USB current state */
 	u32 ep0_state;		/* Endpoint zero state */
@@ -581,4 +586,13 @@ static inline void fsl_udc_clk_release(void)
 }
 #endif
 
+#ifdef CONFIG_USB_OTG
+/* Get platform resource from OTG driver */
+extern struct resource *otg_get_resources(void);
+#endif
+
+#ifdef CONFIG_PPC32
+#include <asm/fsl_usb_io.h>
+#endif
+
 #endif
drivers/usb/host/ehci-fsl.c +229 -32

330 lines not on this page · raw message

drivers/usb/host/ehci-fsl.h +3 -0
index faeaea5..652888e 100644
@@ -52,4 +52,7 @@
 #define FSL_SOC_USB_SICTRL	0x410	/* NOTE: big-endian */
 #define FSL_SOC_USB_CTRL	0x500	/* NOTE: big-endian */
 #define SNOOP_SIZE_2GB		0x1e
+
+extern struct resource *otg_get_resources(void);
+
 #endif				/* _EHCI_FSL_H */
drivers/usb/host/ehci-hub.c +39 -0
index c7178bc..30fb3d4 100644
@@ -27,6 +27,7 @@
  */
 
 /*-------------------------------------------------------------------------*/
+#include <linux/usb/otg.h>
 
 #define	PORT_WAKE_BITS	(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
 
@@ -607,6 +608,37 @@ ehci_hub_descriptor (
 	desc->wHubCharacteristics = cpu_to_le16(temp);
 }
 
+#ifdef CONFIG_USB_OTG
+static int ehci_start_port_reset(struct usb_hcd *hcd, unsigned port)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	u32 status;
+
+	if (!port)
+		return -EINVAL;
+	port--;
+
+	/* start port reset before HNP protocol time out */
+	status = readl(&ehci->regs->port_status[port]);
+	if (!(status & PORT_CONNECT))
+		return -ENODEV;
+
+	/* khubd will finish the reset later */
+	if (ehci_is_TDI(ehci))
+		writel(PORT_RESET | (status & ~(PORT_CSC | PORT_PEC
+				| PORT_OCC)), &ehci->regs->port_status[port]);
+	else
+		writel(PORT_RESET, &ehci->regs->port_status[port]);
+
+	return 0;
+}
+#else
+static int ehci_start_port_reset(struct usb_hcd *hcd, unsigned port)
+{
+	return 0;
+}
+#endif /* CONFIG_USB_OTG */
+
 /*-------------------------------------------------------------------------*/
 
 static int ehci_hub_control (
@@ -675,6 +707,13 @@ static int ehci_hub_control (
 				goto error;
 			if (ehci->no_selective_suspend)
 				break;
+#if defined CONFIG_USB_OTG
+			if ((hcd->self.otg_port == (wIndex + 1))
+					&& hcd->self.b_hnp_enable) {
+				otg_start_hnp(ehci->transceiver);
+				break;
+			}
+#endif
 			if (temp & PORT_SUSPEND) {
 				if ((temp & PORT_PE) == 0)
 					goto error;
drivers/usb/host/ehci.h +5 -0
index 556c0b4..12432cb 100644
@@ -158,6 +158,11 @@ struct ehci_hcd {			/* one per controller */
 	struct dentry		*debug_periodic;
 	struct dentry		*debug_registers;
 #endif
+	/*
+	 * OTG controllers and transceivers need software interaction
+	 */
+	struct otg_transceiver	*transceiver;
+	u32			power_budget;
 };
 
 /* convert between an HCD pointer and the corresponding EHCI_HCD */
drivers/usb/otg/Kconfig +8 -0
index 3d2d3e5..ff22db4 100644
@@ -69,4 +69,12 @@ config NOP_USB_XCEIV
 	 built-in with usb ip or which are autonomous and doesn't require any
 	 phy programming such as ISP1x04 etc.
 
+config FSL_USB2_OTG
+	bool "Freescale USB OTG Transceiver Driver"
+	depends on USB_EHCI_FSL
+	select USB_OTG
+	select USB_OTG_UTILS
+	help
+	  Enable this to support Freescale USB OTG transceiver.
+
 endif # USB || OTG
drivers/usb/otg/Makefile +2 -0
index aeb49a8..d66e2c3 100644
@@ -11,6 +11,8 @@ obj-$(CONFIG_ISP1301_OMAP)	+= isp1301_omap.o
 obj-$(CONFIG_TWL4030_USB)	+= twl4030-usb.o
 obj-$(CONFIG_NOP_USB_XCEIV)	+= nop-usb-xceiv.o
 obj-$(CONFIG_USB_ULPI)		+= ulpi.o
+fsl_usb2_otg-objs		:= fsl_otg.o otg_fsm.o
+obj-$(CONFIG_FSL_USB2_OTG)	+= fsl_usb2_otg.o
 
 ccflags-$(CONFIG_USB_DEBUG)	+= -DDEBUG
 ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG
drivers/usb/otg/fsl_otg.c new file +1199 -0

1,199 lines not on this page · raw message

drivers/usb/otg/fsl_otg.h new file +418 -0

418 lines not on this page · raw message

drivers/usb/otg/otg.c +17 -0
index 0a43a7d..a694b67 100644
@@ -64,3 +64,20 @@ int otg_set_transceiver(struct otg_transceiver *x)
 	return 0;
 }
 EXPORT_SYMBOL(otg_set_transceiver);
+
+#ifdef CONFIG_FSL_USB2_OTG
+static struct resource *otg_resources;
+
+struct resource *otg_get_resources(void)
+{
+	return otg_resources;
+}
+EXPORT_SYMBOL(otg_get_resources);
+
+int otg_set_resources(struct resource *resources)
+{
+	otg_resources = resources;
+	return 0;
+}
+EXPORT_SYMBOL(otg_set_resources);
+#endif
drivers/usb/otg/otg_fsm.c new file +368 -0

140 lines not on this page · raw message

drivers/usb/otg/otg_fsm.h new file +154 -0

154 lines not on this page · raw message

include/linux/fsl_devices.h +15 -0
index 7e64112..db06a6c 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.6.3.3

Part of the diff is not shown here. View the raw message.

#12 lore raw

Re: [PATCH 3/4] USB: add USB OTG support for MPC5121 SoC

Hi Anatolij,

I haven't looked deeply, but I've written a couple of minor comments below.

g.

Quoted 14 lines · Anatolij Gustschin

Adds Freescale USB OTG driver and extends Freescale USB SoC Device Controller driver and FSL EHCI driver to support OTG operation on MPC5121.

Cc Greg Kroah-Hartman <[email protected]>
Cc David Brownell <[email protected]>
Cc Grant Likely <[email protected]>

---
=A0arch/powerpc/include/asm/fsl_usb_io.h | =A0106 +++ =A0drivers/usb/gadget/fsl_udc_core.c =A0 =A0 | =A0357 ++++++++-- =A0drivers/usb/gadget/fsl_usb2_udc.h =A0 =A0 | =A0 14 +

Quoted 7 lines
=A0drivers/usb/host/ehci-fsl.c =A0 =A0 =A0 =A0 =A0 | =A0261 +++++++-
=A0drivers/usb/host/ehci-fsl.h =A0 =A0 =A0 =A0 =A0 | =A0 =A03 +
=A0drivers/usb/host/ehci-hub.c =A0 =A0 =A0 =A0 =A0 | =A0 39 ++
=A0drivers/usb/host/ehci.h =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A05 +
=A0drivers/usb/otg/Kconfig =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 =A08 +
=A0drivers/usb/otg/Makefile =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A02 +

=A0drivers/usb/otg/fsl_otg.c =A0 =A0 =A0 =A0 =A0 =A0 | 1199 +++++++++++++=

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

Quoted 1 line

=A0drivers/usb/otg/fsl_otg.h =A0 =A0 =A0 =A0 =A0 =A0 | =A0418 +++++++++++=

+

arch/powerpc/include=

Quoted 12 lines

=A0drivers/usb/otg/otg.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | =A0 17 + =A0drivers/usb/otg/otg_fsm.c =A0 =A0 =A0 =A0 =A0 =A0 | =A0368 ++++++++++ =A0drivers/usb/otg/otg_fsm.h =A0 =A0 =A0 =A0 =A0 =A0 | =A0154 +++++ =A0include/linux/fsl_devices.h =A0 =A0 =A0 =A0 =A0 | =A0 15 + =A015 files changed, 2867 insertions(+), 99 deletions(-) =A0create mode 100644 arch/powerpc/include/asm/fsl_usb_io.h =A0create mode 100644 drivers/usb/otg/fsl_otg.c
=A0create mode 100644 drivers/usb/otg/fsl_otg.h
=A0create mode 100644 drivers/usb/otg/otg_fsm.c
=A0create mode 100644 drivers/usb/otg/otg_fsm.h

arch/powerpc/include= renamed from arch/powerpc/include/asm/fsl_usb_io.h +0 -0

/asm/fsl_usb_io.h

arch/powerpc/include/asm/fsl_usb_io.h line 3

Quoted 8 lines

new file mode 100644
index 0000000..20c42ef

arch/powerpc/include/asm/fsl_usb_io.h new file +3 -0
@@ -0,0 +1,106 @@
+/* Copyright (c) 2008 Freescale Semiconductor Inc.
+ *
+ * This program is free software; you can redistribute =A0it and/or modi=

fy it

arch/powerpc/include/asm/fsl_usb_io.h line 4

Quoted 1 line
arch/powerpc/include/asm/fsl_usb_io.h new file +1 -0
+ * under =A0the terms of =A0the GNU General =A0Public License as publish=

ed by the

arch/powerpc/include/asm/fsl_usb_io.h line 5

Quoted 1 line
arch/powerpc/include/asm/fsl_usb_io.h new file +1 -0
+ * Free Software Foundation; =A0either version 2 of the =A0License, or (=

at your

arch/powerpc/include/asm/fsl_usb_io.h

Quoted 8 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +8 -0
+ * 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. =A0See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the =A0GNU General Public License =

along

arch/powerpc/include/asm/fsl_usb_io.h line 14

Quoted 1 line
arch/powerpc/include/asm/fsl_usb_io.h new file +1 -0
+ * with this program; if not, write =A0to the Free Software Foundation, =

Inc.,

arch/powerpc/include/asm/fsl_usb_io.h

Quoted 7 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +7 -0
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+#ifndef _FSL_USB_IO_H
+#define _FSL_USB_IO_H
+
+/*
+ * On some SoCs, the USB controller registers can be big or little endia=

n,

Quoted 41 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +41 -0
+ * depending on the version of the chip. =A0For these SoCs, the kernel
+ * should be configured with CONFIG_USB_FSL_BIG_ENDIAN_MMIO enabled.
+ *
+ * Platform code for SoCs that have BE USB registers should set
+ * pdata->big_endian_mmio flag.
+ *
+ * In order to be able to run the same kernel binary on 2 different
+ * versions of an SoC, the BE/LE decision must be made at run time.
+ * _fsl_readl and fsl_writel are pointers to the BE or LE readl()
+ * and writel() functions, and fsl_readl() and fsl_writel() call through
+ * those pointers.
+ *
+ * For SoCs with the usual LE USB registers, don't enable
+ * CONFIG_USB_FSL_BIG_ENDIAN_MMIO, and then fsl_readl() and fsl_writel()
+ * are just macro wrappers for in_le32() and out_le32().
+ *
+ * In either (LE or mixed) case, the function fsl_set_usb_accessors()
+ * should be called at probe time, to either set up the readl/writel
+ * function pointers (mixed case), or do nothing (LE case).
+ *
+ * The host USB drivers already have a mechanism to handle BE/LE
+ * registers. =A0The functionality here is intended to be used by the
+ * gadget and OTG transceiver drivers.
+ *
+ * This file also contains controller-to-cpu accessors for the
+ * USB descriptors, since their endianess is also SoC dependant.
+ * The kernel option CONFIG_USB_FSL_BIG_ENDIAN_DESC configures
+ * which way to go.
+ */
+
+#ifdef CONFIG_USB_FSL_BIG_ENDIAN_MMIO
+static u32 __maybe_unused _fsl_readl_be(const unsigned __iomem *p)
+{
+ =A0 =A0 =A0 return in_be32(p);
+}
+static u32 __maybe_unused _fsl_readl_le(const unsigned __iomem *p)
+{
+ =A0 =A0 =A0 return in_le32(p);
+}
+
+static void __maybe_unused _fsl_writel_be(u32 v, unsigned __iomem *p)

arch/powerpc/include/asm/fsl_usb_io.h line 72

Quoted 10 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +10 -0
+{
+ =A0 =A0 =A0 out_be32(p, v);
+}
+static void __maybe_unused _fsl_writel_le(u32 v, unsigned __iomem *p)
+{
+ =A0 =A0 =A0 out_le32(p, v);
+}
+
+static u32 (*_fsl_readl)(const unsigned __iomem *p);
+static void (*_fsl_writel)(u32 v, unsigned __iomem *p);

statics defined in a header file? That doesn't look right. These dynamic accessors probably need to be defined in a .c file and linked to the rest of the driver code.

It is also better practise to put ops like these into the drivers private instance data structure, but I understand that there is a large driver impact associated with making that change.

arch/powerpc/include/asm/fsl_usb_io.h line 77

Quoted 5 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +5 -0
+
+#define fsl_readl(p) =A0 =A0 =A0 =A0 =A0 (*_fsl_readl)((p))
+#define fsl_writel(v, p) =A0 =A0 =A0 (*_fsl_writel)((v), (p))
+
+static inline void fsl_set_usb_accessors(struct fsl_usb2_platform_data *=

pdata)

Quoted 6 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +6 -0
+{
+ =A0 =A0 =A0 if (pdata->big_endian_mmio) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 _fsl_readl =3D _fsl_readl_be;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 _fsl_writel =3D _fsl_writel_be;
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 _fsl_readl =3D _fsl_readl_le;

arch/powerpc/include/asm/fsl_usb_io.h line 93

Quoted 10 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +10 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 _fsl_writel =3D _fsl_writel_le;
+ =A0 =A0 =A0 }
+}
+
+#else /* CONFIG_USB_FSL_BIG_ENDIAN_MMIO */
+
+#define fsl_readl(addr) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0in_le32((addr))
+#define fsl_writel(val32, addr) out_le32((addr), (val32))
+
+static inline void fsl_set_usb_accessors(struct fsl_usb2_platform_data *=

pdata)

drivers/usb/gadget/fsl_u=

Quoted 14 lines
arch/powerpc/include/asm/fsl_usb_io.h new file +13 -0
+{
+}
+#endif /* CONFIG_USB_FSL_BIG_ENDIAN_MMIO */
+
+#ifdef CONFIG_USB_FSL_BIG_ENDIAN_DESC
+#define cpu_to_hc32(x) (x)
+#define hc32_to_cpu(x) (x)
+#else
+#define cpu_to_hc32(x) cpu_to_le32((x))
+#define hc32_to_cpu(x) le32_to_cpu((x))
+#endif
+
+#endif /* _FSL_USB_IO_H */
drivers/usb/gadget/fsl_u= renamed from drivers/usb/gadget/fsl_udc_core.c +0 -0

dc_core.c

Quoted 22 lines

index fa3d142..b5361a8 100644

drivers/usb/gadget/fsl_udc_core.c +0 -0
@@ -45,6 +45,7 @@

=A0#include <asm/system.h>
=A0#include <asm/unaligned.h>
=A0#include <asm/dma.h>
+#include <asm/cacheflush.h>

=A0#include "fsl_usb2_udc.h"

drivers/usb/gadget/fsl_udc_core.c +1 -4
@@ -76,10 +77,7 @@ fsl_ep0_desc =3D {
 
 =A0static void fsl_ep_fifo_flush(struct usb_ep *_ep);
 
-#ifdef CONFIG_PPC32
-#define fsl_readl(addr) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0in_le32(addr)
-#define fsl_writel(val32, addr) out_le32(addr, val32)
-#else
+#ifndef CONFIG_PPC32
 =A0#define fsl_readl(addr) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0readl(addr)
 =A0#define fsl_writel(val32, addr) writel(val32, addr)
Quoted 1 line

=A0#endif

I would think these !CONFIG_PPC32 defines should also move into the header file just so everything is defined in the same place.

Cheers,
g.

author maintainer
#13 lore raw

PATCH 4/4 powerpc/mpc5121: select options for USB OTG support

In reply to Anatolij Gustschin

USB Device Controller driver and OTG driver allow configuration of controller register accessors. Enable default big-endian register accessors for Rev.2 SoC.

---
 arch/powerpc/platforms/512x/Kconfig |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
arch/powerpc/platforms/512x/Kconfig +8 -0
index fed7b5d..0c42537 100644
@@ -12,6 +12,14 @@ config PPC_MPC5121
 	select USB_ARCH_HAS_EHCI
 	select USB_EHCI_BIG_ENDIAN_DESC
 	select USB_EHCI_BIG_ENDIAN_MMIO
+	select USB_FSL_BIG_ENDIAN_DESC
+	select USB_FSL_BIG_ENDIAN_MMIO
+
+config USB_FSL_BIG_ENDIAN_MMIO
+	bool
+
+config USB_FSL_BIG_ENDIAN_DESC
+	bool
 
 config MPC5121_ADS
 	bool "Freescale MPC5121E ADS"
Signature · 1 line
1.6.3.3