All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu
@ 2015-02-06  8:47 Kishon Vijay Abraham I
  2015-02-06  8:47 ` [U-Boot] [u-boot 01/40] ARM: DRA7: Enable clocks for USB OTGSS and USB PHY Kishon Vijay Abraham I
                   ` (40 more replies)
  0 siblings, 41 replies; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

This patch series ports dwc3 gadget driver from linux kernel (3.19-rc1)
to u-boot.

Changes from RFC:
*) A patch has been added to copy the driver from linux kernel to u-boot and then
   it's modfied to make it work in u-boot. This will help to understand the changes
   that's been done to make it work in u-boot and will also be easier to review.
*) Implemented chained TRB support in dwc3 ep0 so that we need not increase the size
   of bounce buffer

Testing:
*) tested DFU RAM and DFU MMC in dra7xx and am43xx

TODO:
*) Add Kconfig support
*) Adapt dwc3 driver to use the driver model.
*) Make composite driver similar to the one in linux kernel.

Pushed these patches to
git://git.ti.com/~kishon/ti-u-boot/kishons-ti-u-boot.git dwc3_upstream_v1

Kishon Vijay Abraham I (40):
  ARM: DRA7: Enable clocks for USB OTGSS and USB PHY
  ARM: AM43xx: Enable clocks for USB OTGSS and USB PHY
  usb: gadget: udc: add udc-core from linux kernel to u-boot
  include: usb: modify gadget.h to include udc support
  usb: gadget: udc: make udc-core compile in u-boot build
  include: asm: dma-mapping: get rid of the compilation warning in
    udc-core
  usb: dwc3: add dwc3 folder from linux kernel to u-boot
  usb: dwc3: remove un-used files from dwc3 folder
  usb: dwc3: Modify the file headers to u-boot format
  usb: dwc3: remove trace_* APIs from dwc3 driver
  usb: dwc3: fix dwc3 header files
  usb: dwc3: remove pm related operations from dwc3 driver
  arm: asm: dma-mapping: added dma_free_coherent API
  usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  usb: dwc3: gadget: make dwc3 gadget build in uboot
  include: asm: types: add resource_size_t type
  usb: dwc3: ep0: make dwc3 ep0 build in uboot
  include: usb: composite: add USB_GADGET_DELAYED_STATUS to avoid
    compilation error
  usb: dwc3: core: make dwc3 core build in uboot
  include: dwc3-uboot: add a structure for populating platform data
  dwc3: core: change probe and remove to uboot init and uboot exit code
  dwc3: core: add support for multiple dwc3 controllers
  dwc3: core: added an API to invoke irq handlers
  usb: dwc3: dwc3-omap: make dwc3-omap build in uboot
  include: dwc3-omap-uboot: add a structure for populating dwc3-omap
    platform data
  usb: dwc3: dwc3-omap: change probe and remove to uboot init and uboot
    exit code
  dwc3: dwc3-omap: add support for multiple dwc3-omap controllers
  usb: dwc3: dwc3-omap: add interrupt status API to check for
    interrupts
  usb: dwc3: TI PHY: PHY driver for dwc3 in TI platforms
  dwc3: flush the buffers before using it
  usb: dwc3: ep0: preparation for implementing chained TRB
  usb: dwc3: Add chained TRB support for ep0
  usb: dwc3: Makefile: Make dwc3 driver compile in u-boot
  usb: gadget: defer setting maxpacket till ->setup()
  common: cmd_dfu: invoke board_usb_cleanup() for cleaning up
  board: ti: DRA7: added USB initializtion code
  include: configs: Enable DWC3 and DFU in DRA7xx
  board: ti: AM43xx: added USB initializtion code
  include: configs: Enable DWC3 and DFU in AM43xx
  usb: modify usb_gadget_handle_interrupts to take controller index

 Makefile                                           |    2 +
 arch/arm/cpu/armv7/am33xx/clock_am43xx.c           |   12 +
 arch/arm/cpu/armv7/omap5/hw_data.c                 |   14 +
 arch/arm/cpu/armv7/omap5/prcm-regs.c               |   10 +-
 arch/arm/include/asm/arch-am33xx/cpu.h             |   22 +-
 arch/arm/include/asm/arch-am33xx/hardware_am43xx.h |   13 +
 arch/arm/include/asm/arch-omap5/omap.h             |   12 +
 arch/arm/include/asm/dma-mapping.h                 |    9 +-
 arch/arm/include/asm/omap_common.h                 |    4 +-
 arch/arm/include/asm/types.h                       |    1 +
 board/ti/am43xx/board.c                            |  108 +
 board/ti/dra7xx/evm.c                              |  109 +
 common/cmd_dfu.c                                   |    3 +-
 common/cmd_fastboot.c                              |    2 +-
 common/cmd_usb_mass_storage.c                      |    2 +-
 common/usb.c                                       |    7 +
 drivers/usb/dwc3/Makefile                          |    8 +
 drivers/usb/dwc3/core.c                            |  792 ++++++
 drivers/usb/dwc3/core.h                            | 1033 ++++++++
 drivers/usb/dwc3/dwc3-omap.c                       |  441 ++++
 drivers/usb/dwc3/ep0.c                             | 1112 ++++++++
 drivers/usb/dwc3/gadget.c                          | 2679 ++++++++++++++++++++
 drivers/usb/dwc3/gadget.h                          |  108 +
 drivers/usb/dwc3/io.h                              |   56 +
 drivers/usb/dwc3/linux-compat.h                    |   38 +
 drivers/usb/dwc3/ti_usb_phy.c                      |  309 +++
 drivers/usb/gadget/atmel_usba_udc.c                |    2 +-
 drivers/usb/gadget/ci_udc.c                        |    2 +-
 drivers/usb/gadget/composite.c                     |    4 +-
 drivers/usb/gadget/ether.c                         |   12 +-
 drivers/usb/gadget/f_mass_storage.c                |    2 +-
 drivers/usb/gadget/f_thor.c                        |    6 +-
 drivers/usb/gadget/fotg210.c                       |    2 +-
 drivers/usb/gadget/pxa25x_udc.c                    |    2 +-
 drivers/usb/gadget/s3c_udc_otg.c                   |    2 +-
 drivers/usb/gadget/udc/Makefile                    |    4 +
 drivers/usb/gadget/udc/udc-core.c                  |  354 +++
 drivers/usb/musb-new/musb_uboot.c                  |    2 +-
 include/configs/am43xx_evm.h                       |   61 +-
 include/configs/dra7xx_evm.h                       |   63 +
 include/configs/ti_omap5_common.h                  |    5 +
 include/dwc3-omap-uboot.h                          |   32 +
 include/dwc3-uboot.h                               |   42 +
 include/linux/compat.h                             |    1 +
 include/linux/usb/composite.h                      |    9 +
 include/linux/usb/dwc3-omap.h                      |   19 +
 include/linux/usb/gadget.h                         |   84 +-
 include/linux/usb/otg.h                            |   20 +
 include/ti-usb-phy-uboot.h                         |   22 +
 49 files changed, 7622 insertions(+), 36 deletions(-)
 create mode 100644 drivers/usb/dwc3/Makefile
 create mode 100644 drivers/usb/dwc3/core.c
 create mode 100644 drivers/usb/dwc3/core.h
 create mode 100644 drivers/usb/dwc3/dwc3-omap.c
 create mode 100644 drivers/usb/dwc3/ep0.c
 create mode 100644 drivers/usb/dwc3/gadget.c
 create mode 100644 drivers/usb/dwc3/gadget.h
 create mode 100644 drivers/usb/dwc3/io.h
 create mode 100644 drivers/usb/dwc3/linux-compat.h
 create mode 100644 drivers/usb/dwc3/ti_usb_phy.c
 create mode 100644 drivers/usb/gadget/udc/Makefile
 create mode 100644 drivers/usb/gadget/udc/udc-core.c
 create mode 100644 include/dwc3-omap-uboot.h
 create mode 100644 include/dwc3-uboot.h
 create mode 100644 include/linux/usb/dwc3-omap.h
 create mode 100644 include/linux/usb/otg.h
 create mode 100644 include/ti-usb-phy-uboot.h

-- 
1.7.9.5

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

* [U-Boot] [u-boot 01/40] ARM: DRA7: Enable clocks for USB OTGSS and USB PHY
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:04   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 02/40] ARM: AM43xx: " Kishon Vijay Abraham I
                   ` (39 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Enabled clocks for dwc3 controller and USB PHY present in DRA7.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/cpu/armv7/omap5/hw_data.c   |   14 ++++++++++++++
 arch/arm/cpu/armv7/omap5/prcm-regs.c |   10 +++++-----
 arch/arm/include/asm/omap_common.h   |    4 ++--
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/arch/arm/cpu/armv7/omap5/hw_data.c b/arch/arm/cpu/armv7/omap5/hw_data.c
index 95f1686..9315bce 100644
--- a/arch/arm/cpu/armv7/omap5/hw_data.c
+++ b/arch/arm/cpu/armv7/omap5/hw_data.c
@@ -455,6 +455,10 @@ void enable_basic_clocks(void)
 		(*prcm)->cm_l4per_gpio6_clkctrl,
 		(*prcm)->cm_l4per_gpio7_clkctrl,
 		(*prcm)->cm_l4per_gpio8_clkctrl,
+#ifdef CONFIG_USB_DWC3
+		(*prcm)->cm_l3init_ocp2scp1_clkctrl,
+		(*prcm)->cm_l3init_usb_otg_ss1_clkctrl,
+#endif
 		0
 	};
 
@@ -486,6 +490,16 @@ void enable_basic_clocks(void)
 	setbits_le32((*prcm)->cm_l3init_hsmmc2_clkctrl,
 			HSMMC_CLKCTRL_CLKSEL_MASK);
 
+#ifdef CONFIG_USB_DWC3
+	/* Enable 960 MHz clock for dwc3 */
+	setbits_le32((*prcm)->cm_l3init_usb_otg_ss1_clkctrl,
+		     OPTFCLKEN_REFCLK960M);
+
+	/* Enable 32 KHz clock for dwc3 */
+	setbits_le32((*prcm)->cm_coreaon_usb_phy1_core_clkctrl,
+		     USBPHY_CORE_CLKCTRL_OPTFCLKEN_CLK32K);
+#endif
+
 	/* Set the correct clock dividers for mmc */
 	setbits_le32((*prcm)->cm_l3init_hsmmc1_clkctrl,
 			HSMMC_CLKCTRL_CLKSEL_DIV_MASK);
diff --git a/arch/arm/cpu/armv7/omap5/prcm-regs.c b/arch/arm/cpu/armv7/omap5/prcm-regs.c
index 0745d42..440bb40 100644
--- a/arch/arm/cpu/armv7/omap5/prcm-regs.c
+++ b/arch/arm/cpu/armv7/omap5/prcm-regs.c
@@ -575,7 +575,7 @@ struct prcm_regs const omap5_es2_prcm = {
 	.cm_div_m2_dpll_unipro = 0x4a0081d0,
 	.cm_ssc_deltamstep_dpll_unipro = 0x4a0081e8,
 	.cm_ssc_modfreqdiv_dpll_unipro = 0x4a0081ec,
-	.cm_coreaon_usb_phy_core_clkctrl = 0x4A008640,
+	.cm_coreaon_usb_phy1_core_clkctrl = 0x4A008640,
 	.cm_coreaon_bandgap_clkctrl = 0x4a008648,
 	.cm_coreaon_io_srcomp_clkctrl = 0x4a008650,
 
@@ -709,7 +709,7 @@ struct prcm_regs const omap5_es2_prcm = {
 	.cm_l3init_fsusb_clkctrl = 0x4a0096d0,
 	.cm_l3init_ocp2scp1_clkctrl = 0x4a0096e0,
 	.cm_l3init_ocp2scp3_clkctrl = 0x4a0096e8,
-	.cm_l3init_usb_otg_ss_clkctrl = 0x4a0096f0,
+	.cm_l3init_usb_otg_ss1_clkctrl = 0x4a0096f0,
 
 	/* prm irqstatus regs */
 	.prm_irqstatus_mpu_2 = 0x4ae06014,
@@ -801,8 +801,8 @@ struct prcm_regs const dra7xx_prcm = {
 	.cm_clkmode_dpll_dsp			= 0x4a005234,
 	.cm_shadow_freq_config1			= 0x4a005260,
 	.cm_clkmode_dpll_gmac			= 0x4a0052a8,
-	.cm_coreaon_usb_phy_core_clkctrl	= 0x4a008640,
-	.cm_coreaon_usb_phy2_core_clkctrl = 0x4a008688,
+	.cm_coreaon_usb_phy1_core_clkctrl	= 0x4a008640,
+	.cm_coreaon_usb_phy2_core_clkctrl	= 0x4a008688,
 
 	/* cm1.mpu */
 	.cm_mpu_mpu_clkctrl			= 0x4a005320,
@@ -908,7 +908,7 @@ struct prcm_regs const dra7xx_prcm = {
 	.cm_gmac_gmac_clkctrl			= 0x4a0093d0,
 	.cm_l3init_ocp2scp1_clkctrl		= 0x4a0093e0,
 	.cm_l3init_ocp2scp3_clkctrl		= 0x4a0093e8,
-	.cm_l3init_usb_otg_ss_clkctrl		= 0x4a0093f0,
+	.cm_l3init_usb_otg_ss1_clkctrl		= 0x4a0093f0,
 
 	/* cm2.l4per */
 	.cm_l4per_clkstctrl			= 0x4a009700,
diff --git a/arch/arm/include/asm/omap_common.h b/arch/arm/include/asm/omap_common.h
index 323952f..bd43099 100644
--- a/arch/arm/include/asm/omap_common.h
+++ b/arch/arm/include/asm/omap_common.h
@@ -143,7 +143,7 @@ struct prcm_regs {
 	u32 cm_div_m2_dpll_unipro;
 	u32 cm_ssc_deltamstep_dpll_unipro;
 	u32 cm_ssc_modfreqdiv_dpll_unipro;
-	u32 cm_coreaon_usb_phy_core_clkctrl;
+	u32 cm_coreaon_usb_phy1_core_clkctrl;
 	u32 cm_coreaon_usb_phy2_core_clkctrl;
 
 	/* cm2.core */
@@ -230,7 +230,7 @@ struct prcm_regs {
 	u32 cm_l3init_fsusb_clkctrl;
 	u32 cm_l3init_ocp2scp1_clkctrl;
 	u32 cm_l3init_ocp2scp3_clkctrl;
-	u32 cm_l3init_usb_otg_ss_clkctrl;
+	u32 cm_l3init_usb_otg_ss1_clkctrl;
 
 	u32 prm_irqstatus_mpu_2;
 
-- 
1.7.9.5

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

* [U-Boot] [u-boot 02/40] ARM: AM43xx: Enable clocks for USB OTGSS and USB PHY
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
  2015-02-06  8:47 ` [U-Boot] [u-boot 01/40] ARM: DRA7: Enable clocks for USB OTGSS and USB PHY Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:07   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot Kishon Vijay Abraham I
                   ` (38 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Enabled clocks for dwc3 controller and USB PHY present in AM43xx.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/cpu/armv7/am33xx/clock_am43xx.c           |   12 +++++++++++
 arch/arm/include/asm/arch-am33xx/cpu.h             |   22 ++++++++++++++------
 arch/arm/include/asm/arch-am33xx/hardware_am43xx.h |    4 ++++
 3 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
index 31188c8..252135d 100644
--- a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
+++ b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
@@ -111,9 +111,21 @@ void enable_basic_clocks(void)
 		&cmper->emifclkctrl,
 		&cmper->otfaemifclkctrl,
 		&cmper->qspiclkctrl,
+		&cmper->usb0clkctrl,
+		&cmper->usbphyocp2scp0clkctrl,
+		&cmper->usb1clkctrl,
+		&cmper->usbphyocp2scp1clkctrl,
 		0
 	};
 
+	setbits_le32(&cmper->usb0clkctrl,
+		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
+	setbits_le32(&cmwkup->usbphy0clkctrl,
+		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
+	setbits_le32(&cmper->usb1clkctrl,
+		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
+	setbits_le32(&cmwkup->usbphy1clkctrl,
+		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
 	do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
 
 	/* Select the Master osc clk as Timer2 clock source */
diff --git a/arch/arm/include/asm/arch-am33xx/cpu.h b/arch/arm/include/asm/arch-am33xx/cpu.h
index 8dd69b3..1caa24e 100644
--- a/arch/arm/include/asm/arch-am33xx/cpu.h
+++ b/arch/arm/include/asm/arch-am33xx/cpu.h
@@ -224,7 +224,11 @@ struct cm_dpll {
 struct cm_wkuppll {
 	unsigned int resv0[136];
 	unsigned int wkl4wkclkctrl;	/* offset 0x220 */
-	unsigned int resv1[55];
+	unsigned int resv1[7];
+	unsigned int usbphy0clkctrl;	/* offset 0x240 */
+	unsigned int resv112;
+	unsigned int usbphy1clkctrl;	/* offset 0x248 */
+	unsigned int resv113[45];
 	unsigned int wkclkstctrl;	/* offset 0x300 */
 	unsigned int resv2[15];
 	unsigned int wkup_i2c0ctrl;	/* offset 0x340 */
@@ -275,7 +279,7 @@ struct cm_wkuppll {
 	unsigned int divm2dplldisp;	/* offset 0x630 */
 };
 
-/*
+/*get_sys_clk_freq
  * Encapsulating peripheral functional clocks
  * pll registers
  */
@@ -283,7 +287,7 @@ struct cm_perpll {
 	unsigned int l3clkstctrl;	/* offset 0x00 */
 	unsigned int resv0[7];
 	unsigned int l3clkctrl;		/* Offset 0x20 */
-	unsigned int resv1[7];
+	unsigned int resv112[7];
 	unsigned int l3instrclkctrl;	/* offset 0x40 */
 	unsigned int resv2[3];
 	unsigned int ocmcramclkctrl;	/* offset 0x50 */
@@ -310,7 +314,9 @@ struct cm_perpll {
 	unsigned int qspiclkctrl;       /* offset 0x258 */
 	unsigned int resv121;
 	unsigned int usb0clkctrl;	/* offset 0x260 */
-	unsigned int resv13[103];
+	unsigned int resv122;
+	unsigned int usb1clkctrl;	/* offset 0x268 */
+	unsigned int resv13[101];
 	unsigned int l4lsclkstctrl;	/* offset 0x400 */
 	unsigned int resv14[7];
 	unsigned int l4lsclkctrl;	/* offset 0x420 */
@@ -364,10 +370,14 @@ struct cm_perpll {
 	unsigned int uart4clkctrl;	/* offset 0x598 */
 	unsigned int resv35;
 	unsigned int uart5clkctrl;	/* offset 0x5A0 */
-	unsigned int resv36[87];
+	unsigned int resv36[5];
+	unsigned int usbphyocp2scp0clkctrl;	/* offset 0x5B8 */
+	unsigned int resv361;
+	unsigned int usbphyocp2scp1clkctrl;	/* offset 0x5C0 */
+	unsigned int resv3611[79];
 
 	unsigned int emifclkstctrl;	/* offset 0x700 */
-	unsigned int resv361[7];
+	unsigned int resv362[7];
 	unsigned int emifclkctrl;	/* offset 0x720 */
 	unsigned int resv37[3];
 	unsigned int emiffwclkctrl;	/* offset 0x730 */
diff --git a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
index efdecf4..5f259da 100644
--- a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
+++ b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
@@ -72,6 +72,10 @@
 #define USBPHYOCPSCP_MODULE_EN	(1 << 1)
 #define CM_DEVICE_INST			0x44df4100
 
+#define	USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960	(1 << 8)
+#define	USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K	(1 << 8)
+
+
 /* Control status register */
 #define CTRL_CRYSTAL_FREQ_SRC_MASK		(1 << 31)
 #define CTRL_CRYSTAL_FREQ_SRC_SHIFT		31
-- 
1.7.9.5

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

* [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
  2015-02-06  8:47 ` [U-Boot] [u-boot 01/40] ARM: DRA7: Enable clocks for USB OTGSS and USB PHY Kishon Vijay Abraham I
  2015-02-06  8:47 ` [U-Boot] [u-boot 02/40] ARM: AM43xx: " Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-07 13:27   ` Marek Vasut
  2015-02-16 10:11   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 04/40] include: usb: modify gadget.h to include udc support Kishon Vijay Abraham I
                   ` (37 subsequent siblings)
  40 siblings, 2 replies; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added udc-core.c from linux kernel 3.19-rc1 (97bf6af1f9) to u-boot.
This will be adapted to work with u-boot in the
following patches.
Adding support for udc will help to seamlessly port dwc3 driver from
linux kernel to u-boot (since dwc3 uses udc-core) and it'll also help
to add support for multiple gadget controllers to be functional at the
same time.
All other gadget drivers can also be adapted to use udc-core.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/gadget/udc/Makefile   |    4 +
 drivers/usb/gadget/udc/udc-core.c |  637 +++++++++++++++++++++++++++++++++++++
 2 files changed, 641 insertions(+)
 create mode 100644 drivers/usb/gadget/udc/Makefile
 create mode 100644 drivers/usb/gadget/udc/udc-core.c

diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
new file mode 100644
index 0000000..be265aa
--- /dev/null
+++ b/drivers/usb/gadget/udc/Makefile
@@ -0,0 +1,4 @@
+#
+# USB peripheral controller drivers
+#
+obj-$(CONFIG_USB_GADGET)	+= udc-core.o
diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
new file mode 100644
index 0000000..e31d574
--- /dev/null
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -0,0 +1,637 @@
+/**
+ * udc.c - Core UDC Framework
+ *
+ * Copyright (C) 2010 Texas Instruments
+ * Author: Felipe Balbi <balbi@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/err.h>
+#include <linux/dma-mapping.h>
+#include <linux/workqueue.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb.h>
+
+/**
+ * struct usb_udc - describes one usb device controller
+ * @driver - the gadget driver pointer. For use by the class code
+ * @dev - the child device to the actual controller
+ * @gadget - the gadget. For use by the class code
+ * @list - for use by the udc class driver
+ *
+ * This represents the internal data structure which is used by the UDC-class
+ * to hold information about udc driver and gadget together.
+ */
+struct usb_udc {
+	struct usb_gadget_driver	*driver;
+	struct usb_gadget		*gadget;
+	struct device			dev;
+	struct list_head		list;
+};
+
+static struct class *udc_class;
+static LIST_HEAD(udc_list);
+static DEFINE_MUTEX(udc_lock);
+
+/* ------------------------------------------------------------------------- */
+
+#ifdef	CONFIG_HAS_DMA
+
+int usb_gadget_map_request(struct usb_gadget *gadget,
+		struct usb_request *req, int is_in)
+{
+	if (req->length == 0)
+		return 0;
+
+	if (req->num_sgs) {
+		int     mapped;
+
+		mapped = dma_map_sg(&gadget->dev, req->sg, req->num_sgs,
+				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
+		if (mapped == 0) {
+			dev_err(&gadget->dev, "failed to map SGs\n");
+			return -EFAULT;
+		}
+
+		req->num_mapped_sgs = mapped;
+	} else {
+		req->dma = dma_map_single(&gadget->dev, req->buf, req->length,
+				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
+
+		if (dma_mapping_error(&gadget->dev, req->dma)) {
+			dev_err(&gadget->dev, "failed to map buffer\n");
+			return -EFAULT;
+		}
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_map_request);
+
+void usb_gadget_unmap_request(struct usb_gadget *gadget,
+		struct usb_request *req, int is_in)
+{
+	if (req->length == 0)
+		return;
+
+	if (req->num_mapped_sgs) {
+		dma_unmap_sg(&gadget->dev, req->sg, req->num_mapped_sgs,
+				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
+
+		req->num_mapped_sgs = 0;
+	} else {
+		dma_unmap_single(&gadget->dev, req->dma, req->length,
+				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
+	}
+}
+EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
+
+#endif	/* CONFIG_HAS_DMA */
+
+/* ------------------------------------------------------------------------- */
+
+/**
+ * usb_gadget_giveback_request - give the request back to the gadget layer
+ * Context: in_interrupt()
+ *
+ * This is called by device controller drivers in order to return the
+ * completed request back to the gadget layer.
+ */
+void usb_gadget_giveback_request(struct usb_ep *ep,
+		struct usb_request *req)
+{
+	if (likely(req->status == 0))
+		usb_led_activity(USB_LED_EVENT_GADGET);
+
+	req->complete(ep, req);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
+
+/* ------------------------------------------------------------------------- */
+
+static void usb_gadget_state_work(struct work_struct *work)
+{
+	struct usb_gadget	*gadget = work_to_gadget(work);
+	struct usb_udc		*udc = NULL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+	mutex_unlock(&udc_lock);
+
+	return;
+
+found:
+	mutex_unlock(&udc_lock);
+
+	sysfs_notify(&udc->dev.kobj, NULL, "state");
+}
+
+void usb_gadget_set_state(struct usb_gadget *gadget,
+		enum usb_device_state state)
+{
+	gadget->state = state;
+	schedule_work(&gadget->work);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_set_state);
+
+/* ------------------------------------------------------------------------- */
+
+/**
+ * usb_gadget_udc_reset - notifies the udc core that bus reset occurs
+ * @gadget: The gadget which bus reset occurs
+ * @driver: The gadget driver we want to notify
+ *
+ * If the udc driver has bus reset handler, it needs to call this when the bus
+ * reset occurs, it notifies the gadget driver that the bus reset occurs as
+ * well as updates gadget state.
+ */
+void usb_gadget_udc_reset(struct usb_gadget *gadget,
+		struct usb_gadget_driver *driver)
+{
+	driver->reset(gadget);
+	usb_gadget_set_state(gadget, USB_STATE_DEFAULT);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
+
+/**
+ * usb_gadget_udc_start - tells usb device controller to start up
+ * @udc: The UDC to be started
+ *
+ * This call is issued by the UDC Class driver when it's about
+ * to register a gadget driver to the device controller, before
+ * calling gadget driver's bind() method.
+ *
+ * It allows the controller to be powered off until strictly
+ * necessary to have it powered on.
+ *
+ * Returns zero on success, else negative errno.
+ */
+static inline int usb_gadget_udc_start(struct usb_udc *udc)
+{
+	return udc->gadget->ops->udc_start(udc->gadget, udc->driver);
+}
+
+/**
+ * usb_gadget_udc_stop - tells usb device controller we don't need it anymore
+ * @gadget: The device we want to stop activity
+ * @driver: The driver to unbind from @gadget
+ *
+ * This call is issued by the UDC Class driver after calling
+ * gadget driver's unbind() method.
+ *
+ * The details are implementation specific, but it can go as
+ * far as powering off UDC completely and disable its data
+ * line pullups.
+ */
+static inline void usb_gadget_udc_stop(struct usb_udc *udc)
+{
+	udc->gadget->ops->udc_stop(udc->gadget);
+}
+
+/**
+ * usb_udc_release - release the usb_udc struct
+ * @dev: the dev member within usb_udc
+ *
+ * This is called by driver's core in order to free memory once the last
+ * reference is released.
+ */
+static void usb_udc_release(struct device *dev)
+{
+	struct usb_udc *udc;
+
+	udc = container_of(dev, struct usb_udc, dev);
+	dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
+	kfree(udc);
+}
+
+static const struct attribute_group *usb_udc_attr_groups[];
+
+static void usb_udc_nop_release(struct device *dev)
+{
+	dev_vdbg(dev, "%s\n", __func__);
+}
+
+/**
+ * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
+ * @parent: the parent device to this udc. Usually the controller driver's
+ * device.
+ * @gadget: the gadget to be added to the list.
+ * @release: a gadget release function.
+ *
+ * Returns zero on success, negative errno otherwise.
+ */
+int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
+		void (*release)(struct device *dev))
+{
+	struct usb_udc		*udc;
+	int			ret = -ENOMEM;
+
+	udc = kzalloc(sizeof(*udc), GFP_KERNEL);
+	if (!udc)
+		goto err1;
+
+	dev_set_name(&gadget->dev, "gadget");
+	INIT_WORK(&gadget->work, usb_gadget_state_work);
+	gadget->dev.parent = parent;
+
+#ifdef	CONFIG_HAS_DMA
+	dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask);
+	gadget->dev.dma_parms = parent->dma_parms;
+	gadget->dev.dma_mask = parent->dma_mask;
+#endif
+
+	if (release)
+		gadget->dev.release = release;
+	else
+		gadget->dev.release = usb_udc_nop_release;
+
+	ret = device_register(&gadget->dev);
+	if (ret)
+		goto err2;
+
+	device_initialize(&udc->dev);
+	udc->dev.release = usb_udc_release;
+	udc->dev.class = udc_class;
+	udc->dev.groups = usb_udc_attr_groups;
+	udc->dev.parent = parent;
+	ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
+	if (ret)
+		goto err3;
+
+	udc->gadget = gadget;
+
+	mutex_lock(&udc_lock);
+	list_add_tail(&udc->list, &udc_list);
+
+	ret = device_add(&udc->dev);
+	if (ret)
+		goto err4;
+
+	usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
+
+	mutex_unlock(&udc_lock);
+
+	return 0;
+
+err4:
+	list_del(&udc->list);
+	mutex_unlock(&udc_lock);
+
+err3:
+	put_device(&udc->dev);
+
+err2:
+	put_device(&gadget->dev);
+	kfree(udc);
+
+err1:
+	return ret;
+}
+EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
+
+/**
+ * usb_add_gadget_udc - adds a new gadget to the udc class driver list
+ * @parent: the parent device to this udc. Usually the controller
+ * driver's device.
+ * @gadget: the gadget to be added to the list
+ *
+ * Returns zero on success, negative errno otherwise.
+ */
+int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
+{
+	return usb_add_gadget_udc_release(parent, gadget, NULL);
+}
+EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
+
+static void usb_gadget_remove_driver(struct usb_udc *udc)
+{
+	dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
+			udc->driver->function);
+
+	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
+
+	usb_gadget_disconnect(udc->gadget);
+	udc->driver->disconnect(udc->gadget);
+	udc->driver->unbind(udc->gadget);
+	usb_gadget_udc_stop(udc);
+
+	udc->driver = NULL;
+	udc->dev.driver = NULL;
+	udc->gadget->dev.driver = NULL;
+}
+
+/**
+ * usb_del_gadget_udc - deletes @udc from udc_list
+ * @gadget: the gadget to be removed.
+ *
+ * This, will call usb_gadget_unregister_driver() if
+ * the @udc is still busy.
+ */
+void usb_del_gadget_udc(struct usb_gadget *gadget)
+{
+	struct usb_udc		*udc = NULL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->gadget == gadget)
+			goto found;
+
+	dev_err(gadget->dev.parent, "gadget not registered.\n");
+	mutex_unlock(&udc_lock);
+
+	return;
+
+found:
+	dev_vdbg(gadget->dev.parent, "unregistering gadget\n");
+
+	list_del(&udc->list);
+	mutex_unlock(&udc_lock);
+
+	if (udc->driver)
+		usb_gadget_remove_driver(udc);
+
+	kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
+	flush_work(&gadget->work);
+	device_unregister(&udc->dev);
+	device_unregister(&gadget->dev);
+}
+EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
+
+/* ------------------------------------------------------------------------- */
+
+static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
+{
+	int ret;
+
+	dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
+			driver->function);
+
+	udc->driver = driver;
+	udc->dev.driver = &driver->driver;
+	udc->gadget->dev.driver = &driver->driver;
+
+	ret = driver->bind(udc->gadget, driver);
+	if (ret)
+		goto err1;
+	ret = usb_gadget_udc_start(udc);
+	if (ret) {
+		driver->unbind(udc->gadget);
+		goto err1;
+	}
+	usb_gadget_connect(udc->gadget);
+
+	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
+	return 0;
+err1:
+	if (ret != -EISNAM)
+		dev_err(&udc->dev, "failed to start %s: %d\n",
+			udc->driver->function, ret);
+	udc->driver = NULL;
+	udc->dev.driver = NULL;
+	udc->gadget->dev.driver = NULL;
+	return ret;
+}
+
+int usb_udc_attach_driver(const char *name, struct usb_gadget_driver *driver)
+{
+	struct usb_udc *udc = NULL;
+	int ret = -ENODEV;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list) {
+		ret = strcmp(name, dev_name(&udc->dev));
+		if (!ret)
+			break;
+	}
+	if (ret) {
+		ret = -ENODEV;
+		goto out;
+	}
+	if (udc->driver) {
+		ret = -EBUSY;
+		goto out;
+	}
+	ret = udc_bind_to_driver(udc, driver);
+out:
+	mutex_unlock(&udc_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(usb_udc_attach_driver);
+
+int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
+{
+	struct usb_udc		*udc = NULL;
+	int			ret;
+
+	if (!driver || !driver->bind || !driver->setup)
+		return -EINVAL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list) {
+		/* For now we take the first one */
+		if (!udc->driver)
+			goto found;
+	}
+
+	pr_debug("couldn't find an available UDC\n");
+	mutex_unlock(&udc_lock);
+	return -ENODEV;
+found:
+	ret = udc_bind_to_driver(udc, driver);
+	mutex_unlock(&udc_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
+
+int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
+{
+	struct usb_udc		*udc = NULL;
+	int			ret = -ENODEV;
+
+	if (!driver || !driver->unbind)
+		return -EINVAL;
+
+	mutex_lock(&udc_lock);
+	list_for_each_entry(udc, &udc_list, list)
+		if (udc->driver == driver) {
+			usb_gadget_remove_driver(udc);
+			usb_gadget_set_state(udc->gadget,
+					USB_STATE_NOTATTACHED);
+			ret = 0;
+			break;
+		}
+
+	mutex_unlock(&udc_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
+
+/* ------------------------------------------------------------------------- */
+
+static ssize_t usb_udc_srp_store(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t n)
+{
+	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
+
+	if (sysfs_streq(buf, "1"))
+		usb_gadget_wakeup(udc->gadget);
+
+	return n;
+}
+static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
+
+static ssize_t usb_udc_softconn_store(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t n)
+{
+	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
+
+	if (!udc->driver) {
+		dev_err(dev, "soft-connect without a gadget driver\n");
+		return -EOPNOTSUPP;
+	}
+
+	if (sysfs_streq(buf, "connect")) {
+		usb_gadget_udc_start(udc);
+		usb_gadget_connect(udc->gadget);
+	} else if (sysfs_streq(buf, "disconnect")) {
+		usb_gadget_disconnect(udc->gadget);
+		udc->driver->disconnect(udc->gadget);
+		usb_gadget_udc_stop(udc);
+	} else {
+		dev_err(dev, "unsupported command '%s'\n", buf);
+		return -EINVAL;
+	}
+
+	return n;
+}
+static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
+
+static ssize_t state_show(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
+	struct usb_gadget	*gadget = udc->gadget;
+
+	return sprintf(buf, "%s\n", usb_state_string(gadget->state));
+}
+static DEVICE_ATTR_RO(state);
+
+#define USB_UDC_SPEED_ATTR(name, param)					\
+ssize_t name##_show(struct device *dev,					\
+		struct device_attribute *attr, char *buf)		\
+{									\
+	struct usb_udc *udc = container_of(dev, struct usb_udc, dev);	\
+	return snprintf(buf, PAGE_SIZE, "%s\n",				\
+			usb_speed_string(udc->gadget->param));		\
+}									\
+static DEVICE_ATTR_RO(name)
+
+static USB_UDC_SPEED_ATTR(current_speed, speed);
+static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
+
+#define USB_UDC_ATTR(name)					\
+ssize_t name##_show(struct device *dev,				\
+		struct device_attribute *attr, char *buf)	\
+{								\
+	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev); \
+	struct usb_gadget	*gadget = udc->gadget;		\
+								\
+	return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name);	\
+}								\
+static DEVICE_ATTR_RO(name)
+
+static USB_UDC_ATTR(is_otg);
+static USB_UDC_ATTR(is_a_peripheral);
+static USB_UDC_ATTR(b_hnp_enable);
+static USB_UDC_ATTR(a_hnp_support);
+static USB_UDC_ATTR(a_alt_hnp_support);
+
+static struct attribute *usb_udc_attrs[] = {
+	&dev_attr_srp.attr,
+	&dev_attr_soft_connect.attr,
+	&dev_attr_state.attr,
+	&dev_attr_current_speed.attr,
+	&dev_attr_maximum_speed.attr,
+
+	&dev_attr_is_otg.attr,
+	&dev_attr_is_a_peripheral.attr,
+	&dev_attr_b_hnp_enable.attr,
+	&dev_attr_a_hnp_support.attr,
+	&dev_attr_a_alt_hnp_support.attr,
+	NULL,
+};
+
+static const struct attribute_group usb_udc_attr_group = {
+	.attrs = usb_udc_attrs,
+};
+
+static const struct attribute_group *usb_udc_attr_groups[] = {
+	&usb_udc_attr_group,
+	NULL,
+};
+
+static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
+	int			ret;
+
+	ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name);
+	if (ret) {
+		dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
+		return ret;
+	}
+
+	if (udc->driver) {
+		ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
+				udc->driver->function);
+		if (ret) {
+			dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int __init usb_udc_init(void)
+{
+	udc_class = class_create(THIS_MODULE, "udc");
+	if (IS_ERR(udc_class)) {
+		pr_err("failed to create udc class --> %ld\n",
+				PTR_ERR(udc_class));
+		return PTR_ERR(udc_class);
+	}
+
+	udc_class->dev_uevent = usb_udc_uevent;
+	return 0;
+}
+subsys_initcall(usb_udc_init);
+
+static void __exit usb_udc_exit(void)
+{
+	class_destroy(udc_class);
+}
+module_exit(usb_udc_exit);
+
+MODULE_DESCRIPTION("UDC Framework");
+MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
+MODULE_LICENSE("GPL v2");
-- 
1.7.9.5

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

* [U-Boot] [u-boot 04/40] include: usb: modify gadget.h to include udc support
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (2 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:12   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 05/40] usb: gadget: udc: make udc-core compile in u-boot build Kishon Vijay Abraham I
                   ` (36 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Made changes in gadget.h that is required after adding udc-core.c
except changes that might break other platforms.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 include/linux/usb/gadget.h |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 9bccd45..1960958 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -396,6 +396,7 @@ static inline void usb_ep_fifo_flush(struct usb_ep *ep)
 /*-------------------------------------------------------------------------*/
 
 struct usb_gadget;
+struct usb_gadget_driver;
 
 /* the rest of the api to the controller hardware: device operations,
  * which don't involve endpoints (or i/o).
@@ -409,6 +410,9 @@ struct usb_gadget_ops {
 	int	(*pullup) (struct usb_gadget *, int is_on);
 	int	(*ioctl)(struct usb_gadget *,
 				unsigned code, unsigned long param);
+	int	(*udc_start)(struct usb_gadget *,
+			     struct usb_gadget_driver *);
+	int	(*udc_stop)(struct usb_gadget *);
 };
 
 /**
@@ -459,6 +463,7 @@ struct usb_gadget {
 	struct usb_ep			*ep0;
 	struct list_head		ep_list;	/* of usb_ep */
 	enum usb_device_speed		speed;
+	enum usb_device_state		state;
 	unsigned			is_dualspeed:1;
 	unsigned			is_otg:1;
 	unsigned			is_a_peripheral:1;
@@ -686,6 +691,7 @@ static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
 
 /**
  * struct usb_gadget_driver - driver for usb 'slave' devices
+ * @function: String describing the gadget's function
  * @speed: Highest speed the driver handles.
  * @bind: Invoked when the driver is bound to a gadget, usually
  *	after registering the driver.
@@ -707,6 +713,8 @@ static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
  *	Called in a context that permits sleeping.
  * @suspend: Invoked on USB suspend.  May be called in_interrupt.
  * @resume: Invoked on USB resume.  May be called in_interrupt.
+ * @reset: Invoked on USB bus reset. It is mandatory for all gadget drivers
+ *	and should be called in_interrupt.
  *
  * Devices are disabled till a gadget driver successfully bind()s, which
  * means the driver will handle setup() requests needed to enumerate (and
@@ -753,6 +761,7 @@ static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
  * power is maintained.
  */
 struct usb_gadget_driver {
+	char			*function;
 	enum usb_device_speed	speed;
 	int			(*bind)(struct usb_gadget *);
 	void			(*unbind)(struct usb_gadget *);
@@ -761,6 +770,7 @@ struct usb_gadget_driver {
 	void			(*disconnect)(struct usb_gadget *);
 	void			(*suspend)(struct usb_gadget *);
 	void			(*resume)(struct usb_gadget *);
+	void			(*reset)(struct usb_gadget *);
 };
 
 
@@ -801,6 +811,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver);
  */
 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
 
+int usb_add_gadget_udc_release(struct device *parent,
+		struct usb_gadget *gadget, void (*release)(struct device *dev));
+int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
+void usb_del_gadget_udc(struct usb_gadget *gadget);
 /*-------------------------------------------------------------------------*/
 
 /* utility to simplify dealing with string descriptors */
@@ -847,6 +861,35 @@ int usb_gadget_config_buf(const struct usb_config_descriptor *config,
 	void *buf, unsigned buflen, const struct usb_descriptor_header **desc);
 
 /*-------------------------------------------------------------------------*/
+/* utility to simplify map/unmap of usb_requests to/from DMA */
+
+extern int usb_gadget_map_request(struct usb_gadget *gadget,
+				  struct usb_request *req, int is_in);
+
+extern void usb_gadget_unmap_request(struct usb_gadget *gadget,
+				     struct usb_request *req, int is_in);
+
+/*-------------------------------------------------------------------------*/
+
+/* utility to set gadget state properly */
+
+extern void usb_gadget_set_state(struct usb_gadget *gadget,
+				 enum usb_device_state state);
+
+/*-------------------------------------------------------------------------*/
+
+/* utility to tell udc core that the bus reset occurs */
+extern void usb_gadget_udc_reset(struct usb_gadget *gadget,
+				 struct usb_gadget_driver *driver);
+
+/*-------------------------------------------------------------------------*/
+
+/* utility to give requests back to the gadget layer */
+
+extern void usb_gadget_giveback_request(struct usb_ep *ep,
+					struct usb_request *req);
+
+/*-------------------------------------------------------------------------*/
 
 /* utility wrapping a simple endpoint selection policy */
 
-- 
1.7.9.5

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

* [U-Boot] [u-boot 05/40] usb: gadget: udc: make udc-core compile in u-boot build
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (3 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 04/40] include: usb: modify gadget.h to include udc support Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:18   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 06/40] include: asm: dma-mapping: get rid of the compilation warning in udc-core Kishon Vijay Abraham I
                   ` (35 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Make udc-core compile in u-boot by removing all linux specific
stuff and having only the bare minimal udc-core required for
usb gadget drivers. Also modified the file header to a format that is
generally being used in u-boot.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/gadget/udc/udc-core.c |  335 +++----------------------------------
 1 file changed, 26 insertions(+), 309 deletions(-)

diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index e31d574..875e998 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -1,33 +1,27 @@
 /**
- * udc.c - Core UDC Framework
+ * udc-core.c - Core UDC Framework
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  *
- * Copyright (C) 2010 Texas Instruments
  * Author: Felipe Balbi <balbi@ti.com>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/gadget/udc-core.c) and ported
+ * to uboot.
  *
- * 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.
+ * commit 02e8c96627 : usb: gadget: udc: core: prepend udc_attach_driver with
+ *		       usb_
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier:     GPL-2.0
  */
 
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/device.h>
-#include <linux/list.h>
-#include <linux/err.h>
-#include <linux/dma-mapping.h>
-#include <linux/workqueue.h>
+#include <linux/compat.h>
+#include <malloc.h>
+#include <asm/cache.h>
+#include <asm/dma-mapping.h>
+#include <common.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
-#include <linux/usb.h>
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -48,38 +42,18 @@ struct usb_udc {
 
 static struct class *udc_class;
 static LIST_HEAD(udc_list);
-static DEFINE_MUTEX(udc_lock);
+DEFINE_MUTEX(udc_lock);
 
 /* ------------------------------------------------------------------------- */
 
-#ifdef	CONFIG_HAS_DMA
-
 int usb_gadget_map_request(struct usb_gadget *gadget,
 		struct usb_request *req, int is_in)
 {
 	if (req->length == 0)
 		return 0;
 
-	if (req->num_sgs) {
-		int     mapped;
-
-		mapped = dma_map_sg(&gadget->dev, req->sg, req->num_sgs,
-				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
-		if (mapped == 0) {
-			dev_err(&gadget->dev, "failed to map SGs\n");
-			return -EFAULT;
-		}
-
-		req->num_mapped_sgs = mapped;
-	} else {
-		req->dma = dma_map_single(&gadget->dev, req->buf, req->length,
-				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
-
-		if (dma_mapping_error(&gadget->dev, req->dma)) {
-			dev_err(&gadget->dev, "failed to map buffer\n");
-			return -EFAULT;
-		}
-	}
+	req->dma = dma_map_single(req->buf, req->length,
+				  is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
 
 	return 0;
 }
@@ -91,20 +65,11 @@ void usb_gadget_unmap_request(struct usb_gadget *gadget,
 	if (req->length == 0)
 		return;
 
-	if (req->num_mapped_sgs) {
-		dma_unmap_sg(&gadget->dev, req->sg, req->num_mapped_sgs,
-				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
-
-		req->num_mapped_sgs = 0;
-	} else {
-		dma_unmap_single(&gadget->dev, req->dma, req->length,
-				is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
-	}
+	dma_unmap_single((void *)req->dma, req->length,
+			 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
 }
 EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 
-#endif	/* CONFIG_HAS_DMA */
-
 /* ------------------------------------------------------------------------- */
 
 /**
@@ -117,39 +82,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
 void usb_gadget_giveback_request(struct usb_ep *ep,
 		struct usb_request *req)
 {
-	if (likely(req->status == 0))
-		usb_led_activity(USB_LED_EVENT_GADGET);
-
 	req->complete(ep, req);
 }
 EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
 /* ------------------------------------------------------------------------- */
 
-static void usb_gadget_state_work(struct work_struct *work)
-{
-	struct usb_gadget	*gadget = work_to_gadget(work);
-	struct usb_udc		*udc = NULL;
-
-	mutex_lock(&udc_lock);
-	list_for_each_entry(udc, &udc_list, list)
-		if (udc->gadget == gadget)
-			goto found;
-	mutex_unlock(&udc_lock);
-
-	return;
-
-found:
-	mutex_unlock(&udc_lock);
-
-	sysfs_notify(&udc->dev.kobj, NULL, "state");
-}
-
 void usb_gadget_set_state(struct usb_gadget *gadget,
 		enum usb_device_state state)
 {
 	gadget->state = state;
-	schedule_work(&gadget->work);
 }
 EXPORT_SYMBOL_GPL(usb_gadget_set_state);
 
@@ -219,17 +161,9 @@ static void usb_udc_release(struct device *dev)
 	struct usb_udc *udc;
 
 	udc = container_of(dev, struct usb_udc, dev);
-	dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
 	kfree(udc);
 }
 
-static const struct attribute_group *usb_udc_attr_groups[];
-
-static void usb_udc_nop_release(struct device *dev)
-{
-	dev_vdbg(dev, "%s\n", __func__);
-}
-
 /**
  * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
  * @parent: the parent device to this udc. Usually the controller driver's
@@ -250,59 +184,23 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
 		goto err1;
 
 	dev_set_name(&gadget->dev, "gadget");
-	INIT_WORK(&gadget->work, usb_gadget_state_work);
 	gadget->dev.parent = parent;
 
-#ifdef	CONFIG_HAS_DMA
-	dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask);
-	gadget->dev.dma_parms = parent->dma_parms;
-	gadget->dev.dma_mask = parent->dma_mask;
-#endif
-
-	if (release)
-		gadget->dev.release = release;
-	else
-		gadget->dev.release = usb_udc_nop_release;
-
-	ret = device_register(&gadget->dev);
-	if (ret)
-		goto err2;
-
-	device_initialize(&udc->dev);
 	udc->dev.release = usb_udc_release;
 	udc->dev.class = udc_class;
-	udc->dev.groups = usb_udc_attr_groups;
 	udc->dev.parent = parent;
-	ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
-	if (ret)
-		goto err3;
 
 	udc->gadget = gadget;
 
 	mutex_lock(&udc_lock);
 	list_add_tail(&udc->list, &udc_list);
 
-	ret = device_add(&udc->dev);
-	if (ret)
-		goto err4;
-
 	usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
 
 	mutex_unlock(&udc_lock);
 
 	return 0;
 
-err4:
-	list_del(&udc->list);
-	mutex_unlock(&udc_lock);
-
-err3:
-	put_device(&udc->dev);
-
-err2:
-	put_device(&gadget->dev);
-	kfree(udc);
-
 err1:
 	return ret;
 }
@@ -327,16 +225,12 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
 	dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
 			udc->driver->function);
 
-	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
-
 	usb_gadget_disconnect(udc->gadget);
 	udc->driver->disconnect(udc->gadget);
 	udc->driver->unbind(udc->gadget);
 	usb_gadget_udc_stop(udc);
 
 	udc->driver = NULL;
-	udc->dev.driver = NULL;
-	udc->gadget->dev.driver = NULL;
 }
 
 /**
@@ -368,11 +262,6 @@ found:
 
 	if (udc->driver)
 		usb_gadget_remove_driver(udc);
-
-	kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
-	flush_work(&gadget->work);
-	device_unregister(&udc->dev);
-	device_unregister(&gadget->dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
@@ -386,10 +275,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
 			driver->function);
 
 	udc->driver = driver;
-	udc->dev.driver = &driver->driver;
-	udc->gadget->dev.driver = &driver->driver;
 
-	ret = driver->bind(udc->gadget, driver);
+	ret = driver->bind(udc->gadget);
 	if (ret)
 		goto err1;
 	ret = usb_gadget_udc_start(udc);
@@ -399,43 +286,14 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
 	}
 	usb_gadget_connect(udc->gadget);
 
-	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
 	return 0;
 err1:
 	if (ret != -EISNAM)
 		dev_err(&udc->dev, "failed to start %s: %d\n",
 			udc->driver->function, ret);
 	udc->driver = NULL;
-	udc->dev.driver = NULL;
-	udc->gadget->dev.driver = NULL;
-	return ret;
-}
-
-int usb_udc_attach_driver(const char *name, struct usb_gadget_driver *driver)
-{
-	struct usb_udc *udc = NULL;
-	int ret = -ENODEV;
-
-	mutex_lock(&udc_lock);
-	list_for_each_entry(udc, &udc_list, list) {
-		ret = strcmp(name, dev_name(&udc->dev));
-		if (!ret)
-			break;
-	}
-	if (ret) {
-		ret = -ENODEV;
-		goto out;
-	}
-	if (udc->driver) {
-		ret = -EBUSY;
-		goto out;
-	}
-	ret = udc_bind_to_driver(udc, driver);
-out:
-	mutex_unlock(&udc_lock);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(usb_udc_attach_driver);
 
 int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
 {
@@ -452,7 +310,7 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
 			goto found;
 	}
 
-	pr_debug("couldn't find an available UDC\n");
+	printf("couldn't find an available UDC\n");
 	mutex_unlock(&udc_lock);
 	return -ENODEV;
 found:
@@ -462,6 +320,12 @@ found:
 }
 EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
 
+int usb_gadget_register_driver(struct usb_gadget_driver *driver)
+{
+	return usb_gadget_probe_driver(driver);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_register_driver);
+
 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 {
 	struct usb_udc		*udc = NULL;
@@ -485,153 +349,6 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 }
 EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
 
-/* ------------------------------------------------------------------------- */
-
-static ssize_t usb_udc_srp_store(struct device *dev,
-		struct device_attribute *attr, const char *buf, size_t n)
-{
-	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
-
-	if (sysfs_streq(buf, "1"))
-		usb_gadget_wakeup(udc->gadget);
-
-	return n;
-}
-static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
-
-static ssize_t usb_udc_softconn_store(struct device *dev,
-		struct device_attribute *attr, const char *buf, size_t n)
-{
-	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
-
-	if (!udc->driver) {
-		dev_err(dev, "soft-connect without a gadget driver\n");
-		return -EOPNOTSUPP;
-	}
-
-	if (sysfs_streq(buf, "connect")) {
-		usb_gadget_udc_start(udc);
-		usb_gadget_connect(udc->gadget);
-	} else if (sysfs_streq(buf, "disconnect")) {
-		usb_gadget_disconnect(udc->gadget);
-		udc->driver->disconnect(udc->gadget);
-		usb_gadget_udc_stop(udc);
-	} else {
-		dev_err(dev, "unsupported command '%s'\n", buf);
-		return -EINVAL;
-	}
-
-	return n;
-}
-static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
-
-static ssize_t state_show(struct device *dev, struct device_attribute *attr,
-			  char *buf)
-{
-	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
-	struct usb_gadget	*gadget = udc->gadget;
-
-	return sprintf(buf, "%s\n", usb_state_string(gadget->state));
-}
-static DEVICE_ATTR_RO(state);
-
-#define USB_UDC_SPEED_ATTR(name, param)					\
-ssize_t name##_show(struct device *dev,					\
-		struct device_attribute *attr, char *buf)		\
-{									\
-	struct usb_udc *udc = container_of(dev, struct usb_udc, dev);	\
-	return snprintf(buf, PAGE_SIZE, "%s\n",				\
-			usb_speed_string(udc->gadget->param));		\
-}									\
-static DEVICE_ATTR_RO(name)
-
-static USB_UDC_SPEED_ATTR(current_speed, speed);
-static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
-
-#define USB_UDC_ATTR(name)					\
-ssize_t name##_show(struct device *dev,				\
-		struct device_attribute *attr, char *buf)	\
-{								\
-	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev); \
-	struct usb_gadget	*gadget = udc->gadget;		\
-								\
-	return snprintf(buf, PAGE_SIZE, "%d\n", gadget->name);	\
-}								\
-static DEVICE_ATTR_RO(name)
-
-static USB_UDC_ATTR(is_otg);
-static USB_UDC_ATTR(is_a_peripheral);
-static USB_UDC_ATTR(b_hnp_enable);
-static USB_UDC_ATTR(a_hnp_support);
-static USB_UDC_ATTR(a_alt_hnp_support);
-
-static struct attribute *usb_udc_attrs[] = {
-	&dev_attr_srp.attr,
-	&dev_attr_soft_connect.attr,
-	&dev_attr_state.attr,
-	&dev_attr_current_speed.attr,
-	&dev_attr_maximum_speed.attr,
-
-	&dev_attr_is_otg.attr,
-	&dev_attr_is_a_peripheral.attr,
-	&dev_attr_b_hnp_enable.attr,
-	&dev_attr_a_hnp_support.attr,
-	&dev_attr_a_alt_hnp_support.attr,
-	NULL,
-};
-
-static const struct attribute_group usb_udc_attr_group = {
-	.attrs = usb_udc_attrs,
-};
-
-static const struct attribute_group *usb_udc_attr_groups[] = {
-	&usb_udc_attr_group,
-	NULL,
-};
-
-static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env *env)
-{
-	struct usb_udc		*udc = container_of(dev, struct usb_udc, dev);
-	int			ret;
-
-	ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name);
-	if (ret) {
-		dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
-		return ret;
-	}
-
-	if (udc->driver) {
-		ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
-				udc->driver->function);
-		if (ret) {
-			dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
-			return ret;
-		}
-	}
-
-	return 0;
-}
-
-static int __init usb_udc_init(void)
-{
-	udc_class = class_create(THIS_MODULE, "udc");
-	if (IS_ERR(udc_class)) {
-		pr_err("failed to create udc class --> %ld\n",
-				PTR_ERR(udc_class));
-		return PTR_ERR(udc_class);
-	}
-
-	udc_class->dev_uevent = usb_udc_uevent;
-	return 0;
-}
-subsys_initcall(usb_udc_init);
-
-static void __exit usb_udc_exit(void)
-{
-	class_destroy(udc_class);
-}
-module_exit(usb_udc_exit);
-
 MODULE_DESCRIPTION("UDC Framework");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("GPL v2");
-- 
1.7.9.5

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

* [U-Boot] [u-boot 06/40] include: asm: dma-mapping: get rid of the compilation warning in udc-core
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (4 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 05/40] usb: gadget: udc: make udc-core compile in u-boot build Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:19   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 07/40] usb: dwc3: add dwc3 folder from linux kernel to u-boot Kishon Vijay Abraham I
                   ` (34 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Fixed the following warning here.
"warning: ?dma_alloc_coherent? defined but not used" while compiling
udc-core

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/include/asm/dma-mapping.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 55a4e26..14f00efd2 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -14,7 +14,7 @@ enum dma_data_direction {
 	DMA_FROM_DEVICE		= 2,
 };
 
-static void *dma_alloc_coherent(size_t len, unsigned long *handle)
+static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
 {
 	*handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len);
 	return (void *)*handle;
-- 
1.7.9.5

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

* [U-Boot] [u-boot 07/40] usb: dwc3: add dwc3 folder from linux kernel to u-boot
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (5 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 06/40] include: asm: dma-mapping: get rid of the compilation warning in udc-core Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:20   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 08/40] usb: dwc3: remove un-used files from dwc3 folder Kishon Vijay Abraham I
                   ` (33 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added dwc3 folder from linux kernel 3.19-rc1 (97bf6af1f9)
to u-boot. This will be adapted to work with u-boot in the
following patches.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/Kconfig         |  120 ++
 drivers/usb/dwc3/Makefile        |   40 +
 drivers/usb/dwc3/core.c          | 1119 +++++++++++++++
 drivers/usb/dwc3/core.h          | 1041 ++++++++++++++
 drivers/usb/dwc3/debug.c         |   32 +
 drivers/usb/dwc3/debug.h         |  228 +++
 drivers/usb/dwc3/debugfs.c       |  690 ++++++++++
 drivers/usb/dwc3/dwc3-exynos.c   |  301 ++++
 drivers/usb/dwc3/dwc3-keystone.c |  197 +++
 drivers/usb/dwc3/dwc3-omap.c     |  645 +++++++++
 drivers/usb/dwc3/dwc3-pci.c      |  272 ++++
 drivers/usb/dwc3/dwc3-qcom.c     |  130 ++
 drivers/usb/dwc3/dwc3-st.c       |  367 +++++
 drivers/usb/dwc3/ep0.c           | 1092 +++++++++++++++
 drivers/usb/dwc3/gadget.c        | 2824 ++++++++++++++++++++++++++++++++++++++
 drivers/usb/dwc3/gadget.h        |  107 ++
 drivers/usb/dwc3/host.c          |   91 ++
 drivers/usb/dwc3/io.h            |   70 +
 drivers/usb/dwc3/platform_data.h |   47 +
 drivers/usb/dwc3/trace.c         |   19 +
 drivers/usb/dwc3/trace.h         |  247 ++++
 21 files changed, 9679 insertions(+)
 create mode 100644 drivers/usb/dwc3/Kconfig
 create mode 100644 drivers/usb/dwc3/Makefile
 create mode 100644 drivers/usb/dwc3/core.c
 create mode 100644 drivers/usb/dwc3/core.h
 create mode 100644 drivers/usb/dwc3/debug.c
 create mode 100644 drivers/usb/dwc3/debug.h
 create mode 100644 drivers/usb/dwc3/debugfs.c
 create mode 100644 drivers/usb/dwc3/dwc3-exynos.c
 create mode 100644 drivers/usb/dwc3/dwc3-keystone.c
 create mode 100644 drivers/usb/dwc3/dwc3-omap.c
 create mode 100644 drivers/usb/dwc3/dwc3-pci.c
 create mode 100644 drivers/usb/dwc3/dwc3-qcom.c
 create mode 100644 drivers/usb/dwc3/dwc3-st.c
 create mode 100644 drivers/usb/dwc3/ep0.c
 create mode 100644 drivers/usb/dwc3/gadget.c
 create mode 100644 drivers/usb/dwc3/gadget.h
 create mode 100644 drivers/usb/dwc3/host.c
 create mode 100644 drivers/usb/dwc3/io.h
 create mode 100644 drivers/usb/dwc3/platform_data.h
 create mode 100644 drivers/usb/dwc3/trace.c
 create mode 100644 drivers/usb/dwc3/trace.h

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
new file mode 100644
index 0000000..58b5b2c
--- /dev/null
+++ b/drivers/usb/dwc3/Kconfig
@@ -0,0 +1,120 @@
+config USB_DWC3
+	tristate "DesignWare USB3 DRD Core Support"
+	depends on (USB || USB_GADGET) && HAS_DMA
+	select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD
+	help
+	  Say Y or M here if your system has a Dual Role SuperSpeed
+	  USB controller based on the DesignWare USB3 IP Core.
+
+	  If you choose to build this driver is a dynamically linked
+	  module, the module will be called dwc3.ko.
+
+if USB_DWC3
+
+choice
+	bool "DWC3 Mode Selection"
+	default USB_DWC3_DUAL_ROLE if (USB && USB_GADGET)
+	default USB_DWC3_HOST if (USB && !USB_GADGET)
+	default USB_DWC3_GADGET if (!USB && USB_GADGET)
+
+config USB_DWC3_HOST
+	bool "Host only mode"
+	depends on USB=y || USB=USB_DWC3
+	help
+	  Select this when you want to use DWC3 in host mode only,
+	  thereby the gadget feature will be regressed.
+
+config USB_DWC3_GADGET
+	bool "Gadget only mode"
+	depends on USB_GADGET=y || USB_GADGET=USB_DWC3
+	help
+	  Select this when you want to use DWC3 in gadget mode only,
+	  thereby the host feature will be regressed.
+
+config USB_DWC3_DUAL_ROLE
+	bool "Dual Role mode"
+	depends on ((USB=y || USB=USB_DWC3) && (USB_GADGET=y || USB_GADGET=USB_DWC3))
+	help
+	  This is the default mode of working of DWC3 controller where
+	  both host and gadget features are enabled.
+
+endchoice
+
+comment "Platform Glue Driver Support"
+
+config USB_DWC3_OMAP
+	tristate "Texas Instruments OMAP5 and similar Platforms"
+	depends on EXTCON && (ARCH_OMAP2PLUS || COMPILE_TEST)
+	depends on OF
+	default USB_DWC3
+	help
+	  Some platforms from Texas Instruments like OMAP5, DRA7xxx and
+	  AM437x use this IP for USB2/3 functionality.
+
+	  Say 'Y' or 'M' here if you have one such device
+
+config USB_DWC3_EXYNOS
+	tristate "Samsung Exynos Platform"
+	depends on ARCH_EXYNOS && OF || COMPILE_TEST
+	default USB_DWC3
+	help
+	  Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside,
+	  say 'Y' or 'M' if you have one such device.
+
+config USB_DWC3_PCI
+	tristate "PCIe-based Platforms"
+	depends on PCI
+	default USB_DWC3
+	help
+	  If you're using the DesignWare Core IP with a PCIe, please say
+	  'Y' or 'M' here.
+
+	  One such PCIe-based platform is Synopsys' PCIe HAPS model of
+	  this IP.
+
+config USB_DWC3_KEYSTONE
+	tristate "Texas Instruments Keystone2 Platforms"
+	depends on ARCH_KEYSTONE || COMPILE_TEST
+	default USB_DWC3
+	help
+	  Support of USB2/3 functionality in TI Keystone2 platforms.
+	  Say 'Y' or 'M' here if you have one such device
+
+config USB_DWC3_ST
+	tristate "STMicroelectronics Platforms"
+	depends on ARCH_STI && OF
+	default USB_DWC3
+	help
+	  STMicroelectronics SoCs with one DesignWare Core USB3 IP
+	  inside (i.e. STiH407).
+	  Say 'Y' or 'M' if you have one such device.
+
+config USB_DWC3_QCOM
+	tristate "Qualcomm Platforms"
+	depends on ARCH_QCOM || COMPILE_TEST
+	default USB_DWC3
+	help
+	  Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside,
+	  say 'Y' or 'M' if you have one such device.
+
+comment "Debugging features"
+
+config USB_DWC3_DEBUG
+	bool "Enable Debugging Messages"
+	help
+	  Say Y here to enable debugging messages on DWC3 Driver.
+
+config USB_DWC3_VERBOSE
+	bool "Enable Verbose Debugging Messages"
+	depends on USB_DWC3_DEBUG
+	help
+	  Say Y here to enable verbose debugging messages on DWC3 Driver.
+
+config DWC3_HOST_USB3_LPM_ENABLE
+	bool "Enable USB3 LPM Capability"
+	depends on USB_DWC3_HOST=y || USB_DWC3_DUAL_ROLE=y
+	default n
+	help
+	  Select this when you want to enable USB3 LPM with dwc3 xhci host.
+
+endif
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
new file mode 100644
index 0000000..bb34fbc
--- /dev/null
+++ b/drivers/usb/dwc3/Makefile
@@ -0,0 +1,40 @@
+# define_trace.h needs to know how to find our header
+CFLAGS_trace.o				:= -I$(src)
+
+ccflags-$(CONFIG_USB_DWC3_DEBUG)	:= -DDEBUG
+ccflags-$(CONFIG_USB_DWC3_VERBOSE)	+= -DVERBOSE_DEBUG
+
+obj-$(CONFIG_USB_DWC3)			+= dwc3.o
+
+dwc3-y					:= core.o debug.o trace.o
+
+ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
+	dwc3-y				+= host.o
+endif
+
+ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
+	dwc3-y				+= gadget.o ep0.o
+endif
+
+ifneq ($(CONFIG_DEBUG_FS),)
+	dwc3-y				+= debugfs.o
+endif
+
+##
+# Platform-specific glue layers go here
+#
+# NOTICE: Make sure your glue layer doesn't depend on anything
+# which is arch-specific and that it compiles on all situations.
+#
+# We want to keep this requirement in order to be able to compile
+# the entire driver (with all its glue layers) on several architectures
+# and make sure it compiles fine. This will also help with allmodconfig
+# and allyesconfig builds.
+##
+
+obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
+obj-$(CONFIG_USB_DWC3_EXYNOS)		+= dwc3-exynos.o
+obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
+obj-$(CONFIG_USB_DWC3_KEYSTONE)		+= dwc3-keystone.o
+obj-$(CONFIG_USB_DWC3_QCOM)		+= dwc3-qcom.o
+obj-$(CONFIG_USB_DWC3_ST)		+= dwc3-st.o
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
new file mode 100644
index 0000000..25ddc39
--- /dev/null
+++ b/drivers/usb/dwc3/core.c
@@ -0,0 +1,1119 @@
+/**
+ * core.c - DesignWare USB3 DRD Controller Core file
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/of.h>
+#include <linux/acpi.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/of.h>
+#include <linux/usb/otg.h>
+
+#include "platform_data.h"
+#include "core.h"
+#include "gadget.h"
+#include "io.h"
+
+#include "debug.h"
+
+/* -------------------------------------------------------------------------- */
+
+void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
+{
+	u32 reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
+	reg |= DWC3_GCTL_PRTCAPDIR(mode);
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+}
+
+/**
+ * dwc3_core_soft_reset - Issues core soft reset and PHY reset
+ * @dwc: pointer to our context structure
+ */
+static int dwc3_core_soft_reset(struct dwc3 *dwc)
+{
+	u32		reg;
+	int		ret;
+
+	/* Before Resetting PHY, put Core in Reset */
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg |= DWC3_GCTL_CORESOFTRESET;
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+
+	/* Assert USB3 PHY reset */
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
+	reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
+	dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
+
+	/* Assert USB2 PHY reset */
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
+	reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
+	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
+
+	usb_phy_init(dwc->usb2_phy);
+	usb_phy_init(dwc->usb3_phy);
+	ret = phy_init(dwc->usb2_generic_phy);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_init(dwc->usb3_generic_phy);
+	if (ret < 0) {
+		phy_exit(dwc->usb2_generic_phy);
+		return ret;
+	}
+	mdelay(100);
+
+	/* Clear USB3 PHY reset */
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
+	reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
+	dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
+
+	/* Clear USB2 PHY reset */
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
+	reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
+	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
+
+	mdelay(100);
+
+	/* After PHYs are stable we can take Core out of reset state */
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg &= ~DWC3_GCTL_CORESOFTRESET;
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+
+	return 0;
+}
+
+/**
+ * dwc3_free_one_event_buffer - Frees one event buffer
+ * @dwc: Pointer to our controller context structure
+ * @evt: Pointer to event buffer to be freed
+ */
+static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
+		struct dwc3_event_buffer *evt)
+{
+	dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
+}
+
+/**
+ * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
+ * @dwc: Pointer to our controller context structure
+ * @length: size of the event buffer
+ *
+ * Returns a pointer to the allocated event buffer structure on success
+ * otherwise ERR_PTR(errno).
+ */
+static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
+		unsigned length)
+{
+	struct dwc3_event_buffer	*evt;
+
+	evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
+	if (!evt)
+		return ERR_PTR(-ENOMEM);
+
+	evt->dwc	= dwc;
+	evt->length	= length;
+	evt->buf	= dma_alloc_coherent(dwc->dev, length,
+			&evt->dma, GFP_KERNEL);
+	if (!evt->buf)
+		return ERR_PTR(-ENOMEM);
+
+	return evt;
+}
+
+/**
+ * dwc3_free_event_buffers - frees all allocated event buffers
+ * @dwc: Pointer to our controller context structure
+ */
+static void dwc3_free_event_buffers(struct dwc3 *dwc)
+{
+	struct dwc3_event_buffer	*evt;
+	int i;
+
+	for (i = 0; i < dwc->num_event_buffers; i++) {
+		evt = dwc->ev_buffs[i];
+		if (evt)
+			dwc3_free_one_event_buffer(dwc, evt);
+	}
+}
+
+/**
+ * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
+ * @dwc: pointer to our controller context structure
+ * @length: size of event buffer
+ *
+ * Returns 0 on success otherwise negative errno. In the error case, dwc
+ * may contain some buffers allocated but not all which were requested.
+ */
+static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
+{
+	int			num;
+	int			i;
+
+	num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
+	dwc->num_event_buffers = num;
+
+	dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
+			GFP_KERNEL);
+	if (!dwc->ev_buffs)
+		return -ENOMEM;
+
+	for (i = 0; i < num; i++) {
+		struct dwc3_event_buffer	*evt;
+
+		evt = dwc3_alloc_one_event_buffer(dwc, length);
+		if (IS_ERR(evt)) {
+			dev_err(dwc->dev, "can't allocate event buffer\n");
+			return PTR_ERR(evt);
+		}
+		dwc->ev_buffs[i] = evt;
+	}
+
+	return 0;
+}
+
+/**
+ * dwc3_event_buffers_setup - setup our allocated event buffers
+ * @dwc: pointer to our controller context structure
+ *
+ * Returns 0 on success otherwise negative errno.
+ */
+static int dwc3_event_buffers_setup(struct dwc3 *dwc)
+{
+	struct dwc3_event_buffer	*evt;
+	int				n;
+
+	for (n = 0; n < dwc->num_event_buffers; n++) {
+		evt = dwc->ev_buffs[n];
+		dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n",
+				evt->buf, (unsigned long long) evt->dma,
+				evt->length);
+
+		evt->lpos = 0;
+
+		dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
+				lower_32_bits(evt->dma));
+		dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
+				upper_32_bits(evt->dma));
+		dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
+				DWC3_GEVNTSIZ_SIZE(evt->length));
+		dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
+	}
+
+	return 0;
+}
+
+static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
+{
+	struct dwc3_event_buffer	*evt;
+	int				n;
+
+	for (n = 0; n < dwc->num_event_buffers; n++) {
+		evt = dwc->ev_buffs[n];
+
+		evt->lpos = 0;
+
+		dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
+		dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
+		dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
+				| DWC3_GEVNTSIZ_SIZE(0));
+		dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
+	}
+}
+
+static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
+{
+	if (!dwc->has_hibernation)
+		return 0;
+
+	if (!dwc->nr_scratch)
+		return 0;
+
+	dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
+			DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
+	if (!dwc->scratchbuf)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
+{
+	dma_addr_t scratch_addr;
+	u32 param;
+	int ret;
+
+	if (!dwc->has_hibernation)
+		return 0;
+
+	if (!dwc->nr_scratch)
+		return 0;
+
+	 /* should never fall here */
+	if (!WARN_ON(dwc->scratchbuf))
+		return 0;
+
+	scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
+			dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
+			DMA_BIDIRECTIONAL);
+	if (dma_mapping_error(dwc->dev, scratch_addr)) {
+		dev_err(dwc->dev, "failed to map scratch buffer\n");
+		ret = -EFAULT;
+		goto err0;
+	}
+
+	dwc->scratch_addr = scratch_addr;
+
+	param = lower_32_bits(scratch_addr);
+
+	ret = dwc3_send_gadget_generic_command(dwc,
+			DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
+	if (ret < 0)
+		goto err1;
+
+	param = upper_32_bits(scratch_addr);
+
+	ret = dwc3_send_gadget_generic_command(dwc,
+			DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
+	if (ret < 0)
+		goto err1;
+
+	return 0;
+
+err1:
+	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+
+err0:
+	return ret;
+}
+
+static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
+{
+	if (!dwc->has_hibernation)
+		return;
+
+	if (!dwc->nr_scratch)
+		return;
+
+	 /* should never fall here */
+	if (!WARN_ON(dwc->scratchbuf))
+		return;
+
+	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+	kfree(dwc->scratchbuf);
+}
+
+static void dwc3_core_num_eps(struct dwc3 *dwc)
+{
+	struct dwc3_hwparams	*parms = &dwc->hwparams;
+
+	dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
+	dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
+
+	dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n",
+			dwc->num_in_eps, dwc->num_out_eps);
+}
+
+static void dwc3_cache_hwparams(struct dwc3 *dwc)
+{
+	struct dwc3_hwparams	*parms = &dwc->hwparams;
+
+	parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
+	parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
+	parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
+	parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
+	parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
+	parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
+	parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
+	parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
+	parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
+}
+
+/**
+ * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
+ * @dwc: Pointer to our controller context structure
+ */
+static void dwc3_phy_setup(struct dwc3 *dwc)
+{
+	u32 reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
+
+	/*
+	 * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
+	 * to '0' during coreConsultant configuration. So default value
+	 * will be '0' when the core is reset. Application needs to set it
+	 * to '1' after the core initialization is completed.
+	 */
+	if (dwc->revision > DWC3_REVISION_194A)
+		reg |= DWC3_GUSB3PIPECTL_SUSPHY;
+
+	if (dwc->u2ss_inp3_quirk)
+		reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
+
+	if (dwc->req_p1p2p3_quirk)
+		reg |= DWC3_GUSB3PIPECTL_REQP1P2P3;
+
+	if (dwc->del_p1p2p3_quirk)
+		reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN;
+
+	if (dwc->del_phy_power_chg_quirk)
+		reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE;
+
+	if (dwc->lfps_filter_quirk)
+		reg |= DWC3_GUSB3PIPECTL_LFPSFILT;
+
+	if (dwc->rx_detect_poll_quirk)
+		reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL;
+
+	if (dwc->tx_de_emphasis_quirk)
+		reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis);
+
+	if (dwc->dis_u3_susphy_quirk)
+		reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
+
+	dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
+
+	mdelay(100);
+
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
+
+	/*
+	 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
+	 * '0' during coreConsultant configuration. So default value will
+	 * be '0' when the core is reset. Application needs to set it to
+	 * '1' after the core initialization is completed.
+	 */
+	if (dwc->revision > DWC3_REVISION_194A)
+		reg |= DWC3_GUSB2PHYCFG_SUSPHY;
+
+	if (dwc->dis_u2_susphy_quirk)
+		reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
+
+	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
+
+	mdelay(100);
+}
+
+/**
+ * dwc3_core_init - Low-level initialization of DWC3 Core
+ * @dwc: Pointer to our controller context structure
+ *
+ * Returns 0 on success otherwise negative errno.
+ */
+static int dwc3_core_init(struct dwc3 *dwc)
+{
+	unsigned long		timeout;
+	u32			hwparams4 = dwc->hwparams.hwparams4;
+	u32			reg;
+	int			ret;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
+	/* This should read as U3 followed by revision number */
+	if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) {
+		dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
+		ret = -ENODEV;
+		goto err0;
+	}
+	dwc->revision = reg;
+
+	/*
+	 * Write Linux Version Code to our GUID register so it's easy to figure
+	 * out which kernel version a bug was found.
+	 */
+	dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
+
+	/* Handle USB2.0-only core configuration */
+	if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
+			DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
+		if (dwc->maximum_speed == USB_SPEED_SUPER)
+			dwc->maximum_speed = USB_SPEED_HIGH;
+	}
+
+	/* issue device SoftReset too */
+	timeout = jiffies + msecs_to_jiffies(500);
+	dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
+	do {
+		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+		if (!(reg & DWC3_DCTL_CSFTRST))
+			break;
+
+		if (time_after(jiffies, timeout)) {
+			dev_err(dwc->dev, "Reset Timed Out\n");
+			ret = -ETIMEDOUT;
+			goto err0;
+		}
+
+		cpu_relax();
+	} while (true);
+
+	ret = dwc3_core_soft_reset(dwc);
+	if (ret)
+		goto err0;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
+
+	switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
+	case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
+		/**
+		 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
+		 * issue which would cause xHCI compliance tests to fail.
+		 *
+		 * Because of that we cannot enable clock gating on such
+		 * configurations.
+		 *
+		 * Refers to:
+		 *
+		 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
+		 * SOF/ITP Mode Used
+		 */
+		if ((dwc->dr_mode == USB_DR_MODE_HOST ||
+				dwc->dr_mode == USB_DR_MODE_OTG) &&
+				(dwc->revision >= DWC3_REVISION_210A &&
+				dwc->revision <= DWC3_REVISION_250A))
+			reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
+		else
+			reg &= ~DWC3_GCTL_DSBLCLKGTNG;
+		break;
+	case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
+		/* enable hibernation here */
+		dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
+
+		/*
+		 * REVISIT Enabling this bit so that host-mode hibernation
+		 * will work. Device-mode hibernation is not yet implemented.
+		 */
+		reg |= DWC3_GCTL_GBLHIBERNATIONEN;
+		break;
+	default:
+		dev_dbg(dwc->dev, "No power optimization available\n");
+	}
+
+	/* check if current dwc3 is on simulation board */
+	if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
+		dev_dbg(dwc->dev, "it is on FPGA board\n");
+		dwc->is_fpga = true;
+	}
+
+	WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
+			"disable_scramble cannot be used on non-FPGA builds\n");
+
+	if (dwc->disable_scramble_quirk && dwc->is_fpga)
+		reg |= DWC3_GCTL_DISSCRAMBLE;
+	else
+		reg &= ~DWC3_GCTL_DISSCRAMBLE;
+
+	if (dwc->u2exit_lfps_quirk)
+		reg |= DWC3_GCTL_U2EXIT_LFPS;
+
+	/*
+	 * WORKAROUND: DWC3 revisions <1.90a have a bug
+	 * where the device can fail to connect@SuperSpeed
+	 * and falls back to high-speed mode which causes
+	 * the device to enter a Connect/Disconnect loop
+	 */
+	if (dwc->revision < DWC3_REVISION_190A)
+		reg |= DWC3_GCTL_U2RSTECN;
+
+	dwc3_core_num_eps(dwc);
+
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+
+	dwc3_phy_setup(dwc);
+
+	ret = dwc3_alloc_scratch_buffers(dwc);
+	if (ret)
+		goto err1;
+
+	ret = dwc3_setup_scratch_buffers(dwc);
+	if (ret)
+		goto err2;
+
+	return 0;
+
+err2:
+	dwc3_free_scratch_buffers(dwc);
+
+err1:
+	usb_phy_shutdown(dwc->usb2_phy);
+	usb_phy_shutdown(dwc->usb3_phy);
+	phy_exit(dwc->usb2_generic_phy);
+	phy_exit(dwc->usb3_generic_phy);
+
+err0:
+	return ret;
+}
+
+static void dwc3_core_exit(struct dwc3 *dwc)
+{
+	dwc3_free_scratch_buffers(dwc);
+	usb_phy_shutdown(dwc->usb2_phy);
+	usb_phy_shutdown(dwc->usb3_phy);
+	phy_exit(dwc->usb2_generic_phy);
+	phy_exit(dwc->usb3_generic_phy);
+}
+
+static int dwc3_core_get_phy(struct dwc3 *dwc)
+{
+	struct device		*dev = dwc->dev;
+	struct device_node	*node = dev->of_node;
+	int ret;
+
+	if (node) {
+		dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
+		dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
+	} else {
+		dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
+		dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
+	}
+
+	if (IS_ERR(dwc->usb2_phy)) {
+		ret = PTR_ERR(dwc->usb2_phy);
+		if (ret == -ENXIO || ret == -ENODEV) {
+			dwc->usb2_phy = NULL;
+		} else if (ret == -EPROBE_DEFER) {
+			return ret;
+		} else {
+			dev_err(dev, "no usb2 phy configured\n");
+			return ret;
+		}
+	}
+
+	if (IS_ERR(dwc->usb3_phy)) {
+		ret = PTR_ERR(dwc->usb3_phy);
+		if (ret == -ENXIO || ret == -ENODEV) {
+			dwc->usb3_phy = NULL;
+		} else if (ret == -EPROBE_DEFER) {
+			return ret;
+		} else {
+			dev_err(dev, "no usb3 phy configured\n");
+			return ret;
+		}
+	}
+
+	dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
+	if (IS_ERR(dwc->usb2_generic_phy)) {
+		ret = PTR_ERR(dwc->usb2_generic_phy);
+		if (ret == -ENOSYS || ret == -ENODEV) {
+			dwc->usb2_generic_phy = NULL;
+		} else if (ret == -EPROBE_DEFER) {
+			return ret;
+		} else {
+			dev_err(dev, "no usb2 phy configured\n");
+			return ret;
+		}
+	}
+
+	dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
+	if (IS_ERR(dwc->usb3_generic_phy)) {
+		ret = PTR_ERR(dwc->usb3_generic_phy);
+		if (ret == -ENOSYS || ret == -ENODEV) {
+			dwc->usb3_generic_phy = NULL;
+		} else if (ret == -EPROBE_DEFER) {
+			return ret;
+		} else {
+			dev_err(dev, "no usb3 phy configured\n");
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int dwc3_core_init_mode(struct dwc3 *dwc)
+{
+	struct device *dev = dwc->dev;
+	int ret;
+
+	switch (dwc->dr_mode) {
+	case USB_DR_MODE_PERIPHERAL:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
+		ret = dwc3_gadget_init(dwc);
+		if (ret) {
+			dev_err(dev, "failed to initialize gadget\n");
+			return ret;
+		}
+		break;
+	case USB_DR_MODE_HOST:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
+		ret = dwc3_host_init(dwc);
+		if (ret) {
+			dev_err(dev, "failed to initialize host\n");
+			return ret;
+		}
+		break;
+	case USB_DR_MODE_OTG:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
+		ret = dwc3_host_init(dwc);
+		if (ret) {
+			dev_err(dev, "failed to initialize host\n");
+			return ret;
+		}
+
+		ret = dwc3_gadget_init(dwc);
+		if (ret) {
+			dev_err(dev, "failed to initialize gadget\n");
+			return ret;
+		}
+		break;
+	default:
+		dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static void dwc3_core_exit_mode(struct dwc3 *dwc)
+{
+	switch (dwc->dr_mode) {
+	case USB_DR_MODE_PERIPHERAL:
+		dwc3_gadget_exit(dwc);
+		break;
+	case USB_DR_MODE_HOST:
+		dwc3_host_exit(dwc);
+		break;
+	case USB_DR_MODE_OTG:
+		dwc3_host_exit(dwc);
+		dwc3_gadget_exit(dwc);
+		break;
+	default:
+		/* do nothing */
+		break;
+	}
+}
+
+#define DWC3_ALIGN_MASK		(16 - 1)
+
+static int dwc3_probe(struct platform_device *pdev)
+{
+	struct device		*dev = &pdev->dev;
+	struct dwc3_platform_data *pdata = dev_get_platdata(dev);
+	struct device_node	*node = dev->of_node;
+	struct resource		*res;
+	struct dwc3		*dwc;
+	u8			lpm_nyet_threshold;
+	u8			tx_de_emphasis;
+	u8			hird_threshold;
+
+	int			ret;
+
+	void __iomem		*regs;
+	void			*mem;
+
+	mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
+	if (!mem)
+		return -ENOMEM;
+
+	dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
+	dwc->mem = mem;
+	dwc->dev = dev;
+
+	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (!res) {
+		dev_err(dev, "missing IRQ\n");
+		return -ENODEV;
+	}
+	dwc->xhci_resources[1].start = res->start;
+	dwc->xhci_resources[1].end = res->end;
+	dwc->xhci_resources[1].flags = res->flags;
+	dwc->xhci_resources[1].name = res->name;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "missing memory resource\n");
+		return -ENODEV;
+	}
+
+	dwc->xhci_resources[0].start = res->start;
+	dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
+					DWC3_XHCI_REGS_END;
+	dwc->xhci_resources[0].flags = res->flags;
+	dwc->xhci_resources[0].name = res->name;
+
+	res->start += DWC3_GLOBALS_REGS_START;
+
+	/*
+	 * Request memory region but exclude xHCI regs,
+	 * since it will be requested by the xhci-plat driver.
+	 */
+	regs = devm_ioremap_resource(dev, res);
+	if (IS_ERR(regs))
+		return PTR_ERR(regs);
+
+	dwc->regs	= regs;
+	dwc->regs_size	= resource_size(res);
+	/*
+	 * restore res->start back to its original value so that,
+	 * in case the probe is deferred, we don't end up getting error in
+	 * request the memory region the next time probe is called.
+	 */
+	res->start -= DWC3_GLOBALS_REGS_START;
+
+	/* default to highest possible threshold */
+	lpm_nyet_threshold = 0xff;
+
+	/* default to -3.5dB de-emphasis */
+	tx_de_emphasis = 1;
+
+	/*
+	 * default to assert utmi_sleep_n and use maximum allowed HIRD
+	 * threshold value of 0b1100
+	 */
+	hird_threshold = 12;
+
+	if (node) {
+		dwc->maximum_speed = of_usb_get_maximum_speed(node);
+		dwc->has_lpm_erratum = of_property_read_bool(node,
+				"snps,has-lpm-erratum");
+		of_property_read_u8(node, "snps,lpm-nyet-threshold",
+				&lpm_nyet_threshold);
+		dwc->is_utmi_l1_suspend = of_property_read_bool(node,
+				"snps,is-utmi-l1-suspend");
+		of_property_read_u8(node, "snps,hird-threshold",
+				&hird_threshold);
+
+		dwc->needs_fifo_resize = of_property_read_bool(node,
+				"tx-fifo-resize");
+		dwc->dr_mode = of_usb_get_dr_mode(node);
+
+		dwc->disable_scramble_quirk = of_property_read_bool(node,
+				"snps,disable_scramble_quirk");
+		dwc->u2exit_lfps_quirk = of_property_read_bool(node,
+				"snps,u2exit_lfps_quirk");
+		dwc->u2ss_inp3_quirk = of_property_read_bool(node,
+				"snps,u2ss_inp3_quirk");
+		dwc->req_p1p2p3_quirk = of_property_read_bool(node,
+				"snps,req_p1p2p3_quirk");
+		dwc->del_p1p2p3_quirk = of_property_read_bool(node,
+				"snps,del_p1p2p3_quirk");
+		dwc->del_phy_power_chg_quirk = of_property_read_bool(node,
+				"snps,del_phy_power_chg_quirk");
+		dwc->lfps_filter_quirk = of_property_read_bool(node,
+				"snps,lfps_filter_quirk");
+		dwc->rx_detect_poll_quirk = of_property_read_bool(node,
+				"snps,rx_detect_poll_quirk");
+		dwc->dis_u3_susphy_quirk = of_property_read_bool(node,
+				"snps,dis_u3_susphy_quirk");
+		dwc->dis_u2_susphy_quirk = of_property_read_bool(node,
+				"snps,dis_u2_susphy_quirk");
+
+		dwc->tx_de_emphasis_quirk = of_property_read_bool(node,
+				"snps,tx_de_emphasis_quirk");
+		of_property_read_u8(node, "snps,tx_de_emphasis",
+				&tx_de_emphasis);
+	} else if (pdata) {
+		dwc->maximum_speed = pdata->maximum_speed;
+		dwc->has_lpm_erratum = pdata->has_lpm_erratum;
+		if (pdata->lpm_nyet_threshold)
+			lpm_nyet_threshold = pdata->lpm_nyet_threshold;
+		dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend;
+		if (pdata->hird_threshold)
+			hird_threshold = pdata->hird_threshold;
+
+		dwc->needs_fifo_resize = pdata->tx_fifo_resize;
+		dwc->dr_mode = pdata->dr_mode;
+
+		dwc->disable_scramble_quirk = pdata->disable_scramble_quirk;
+		dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk;
+		dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk;
+		dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk;
+		dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk;
+		dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk;
+		dwc->lfps_filter_quirk = pdata->lfps_filter_quirk;
+		dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk;
+		dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk;
+		dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk;
+
+		dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk;
+		if (pdata->tx_de_emphasis)
+			tx_de_emphasis = pdata->tx_de_emphasis;
+	}
+
+	/* default to superspeed if no maximum_speed passed */
+	if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
+		dwc->maximum_speed = USB_SPEED_SUPER;
+
+	dwc->lpm_nyet_threshold = lpm_nyet_threshold;
+	dwc->tx_de_emphasis = tx_de_emphasis;
+
+	dwc->hird_threshold = hird_threshold
+		| (dwc->is_utmi_l1_suspend << 4);
+
+	ret = dwc3_core_get_phy(dwc);
+	if (ret)
+		return ret;
+
+	spin_lock_init(&dwc->lock);
+	platform_set_drvdata(pdev, dwc);
+
+	if (!dev->dma_mask) {
+		dev->dma_mask = dev->parent->dma_mask;
+		dev->dma_parms = dev->parent->dma_parms;
+		dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
+	}
+
+	pm_runtime_enable(dev);
+	pm_runtime_get_sync(dev);
+	pm_runtime_forbid(dev);
+
+	dwc3_cache_hwparams(dwc);
+
+	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
+	if (ret) {
+		dev_err(dwc->dev, "failed to allocate event buffers\n");
+		ret = -ENOMEM;
+		goto err0;
+	}
+
+	if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
+		dwc->dr_mode = USB_DR_MODE_HOST;
+	else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
+		dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
+
+	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
+		dwc->dr_mode = USB_DR_MODE_OTG;
+
+	ret = dwc3_core_init(dwc);
+	if (ret) {
+		dev_err(dev, "failed to initialize core\n");
+		goto err0;
+	}
+
+	usb_phy_set_suspend(dwc->usb2_phy, 0);
+	usb_phy_set_suspend(dwc->usb3_phy, 0);
+	ret = phy_power_on(dwc->usb2_generic_phy);
+	if (ret < 0)
+		goto err1;
+
+	ret = phy_power_on(dwc->usb3_generic_phy);
+	if (ret < 0)
+		goto err_usb2phy_power;
+
+	ret = dwc3_event_buffers_setup(dwc);
+	if (ret) {
+		dev_err(dwc->dev, "failed to setup event buffers\n");
+		goto err_usb3phy_power;
+	}
+
+	ret = dwc3_core_init_mode(dwc);
+	if (ret)
+		goto err2;
+
+	ret = dwc3_debugfs_init(dwc);
+	if (ret) {
+		dev_err(dev, "failed to initialize debugfs\n");
+		goto err3;
+	}
+
+	pm_runtime_allow(dev);
+
+	return 0;
+
+err3:
+	dwc3_core_exit_mode(dwc);
+
+err2:
+	dwc3_event_buffers_cleanup(dwc);
+
+err_usb3phy_power:
+	phy_power_off(dwc->usb3_generic_phy);
+
+err_usb2phy_power:
+	phy_power_off(dwc->usb2_generic_phy);
+
+err1:
+	usb_phy_set_suspend(dwc->usb2_phy, 1);
+	usb_phy_set_suspend(dwc->usb3_phy, 1);
+	dwc3_core_exit(dwc);
+
+err0:
+	dwc3_free_event_buffers(dwc);
+
+	return ret;
+}
+
+static int dwc3_remove(struct platform_device *pdev)
+{
+	struct dwc3	*dwc = platform_get_drvdata(pdev);
+
+	dwc3_debugfs_exit(dwc);
+	dwc3_core_exit_mode(dwc);
+	dwc3_event_buffers_cleanup(dwc);
+	dwc3_free_event_buffers(dwc);
+
+	usb_phy_set_suspend(dwc->usb2_phy, 1);
+	usb_phy_set_suspend(dwc->usb3_phy, 1);
+	phy_power_off(dwc->usb2_generic_phy);
+	phy_power_off(dwc->usb3_generic_phy);
+
+	dwc3_core_exit(dwc);
+
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int dwc3_suspend(struct device *dev)
+{
+	struct dwc3	*dwc = dev_get_drvdata(dev);
+	unsigned long	flags;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+
+	switch (dwc->dr_mode) {
+	case USB_DR_MODE_PERIPHERAL:
+	case USB_DR_MODE_OTG:
+		dwc3_gadget_suspend(dwc);
+		/* FALLTHROUGH */
+	case USB_DR_MODE_HOST:
+	default:
+		dwc3_event_buffers_cleanup(dwc);
+		break;
+	}
+
+	dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	usb_phy_shutdown(dwc->usb3_phy);
+	usb_phy_shutdown(dwc->usb2_phy);
+	phy_exit(dwc->usb2_generic_phy);
+	phy_exit(dwc->usb3_generic_phy);
+
+	return 0;
+}
+
+static int dwc3_resume(struct device *dev)
+{
+	struct dwc3	*dwc = dev_get_drvdata(dev);
+	unsigned long	flags;
+	int		ret;
+
+	usb_phy_init(dwc->usb3_phy);
+	usb_phy_init(dwc->usb2_phy);
+	ret = phy_init(dwc->usb2_generic_phy);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_init(dwc->usb3_generic_phy);
+	if (ret < 0)
+		goto err_usb2phy_init;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+
+	dwc3_event_buffers_setup(dwc);
+	dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
+
+	switch (dwc->dr_mode) {
+	case USB_DR_MODE_PERIPHERAL:
+	case USB_DR_MODE_OTG:
+		dwc3_gadget_resume(dwc);
+		/* FALLTHROUGH */
+	case USB_DR_MODE_HOST:
+	default:
+		/* do nothing */
+		break;
+	}
+
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	return 0;
+
+err_usb2phy_init:
+	phy_exit(dwc->usb2_generic_phy);
+
+	return ret;
+}
+
+static const struct dev_pm_ops dwc3_dev_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
+};
+
+#define DWC3_PM_OPS	&(dwc3_dev_pm_ops)
+#else
+#define DWC3_PM_OPS	NULL
+#endif
+
+#ifdef CONFIG_OF
+static const struct of_device_id of_dwc3_match[] = {
+	{
+		.compatible = "snps,dwc3"
+	},
+	{
+		.compatible = "synopsys,dwc3"
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, of_dwc3_match);
+#endif
+
+#ifdef CONFIG_ACPI
+
+#define ACPI_ID_INTEL_BSW	"808622B7"
+
+static const struct acpi_device_id dwc3_acpi_match[] = {
+	{ ACPI_ID_INTEL_BSW, 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
+#endif
+
+static struct platform_driver dwc3_driver = {
+	.probe		= dwc3_probe,
+	.remove		= dwc3_remove,
+	.driver		= {
+		.name	= "dwc3",
+		.of_match_table	= of_match_ptr(of_dwc3_match),
+		.acpi_match_table = ACPI_PTR(dwc3_acpi_match),
+		.pm	= DWC3_PM_OPS,
+	},
+};
+
+module_platform_driver(dwc3_driver);
+
+MODULE_ALIAS("platform:dwc3");
+MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
new file mode 100644
index 0000000..4bb9aa6
--- /dev/null
+++ b/drivers/usb/dwc3/core.h
@@ -0,0 +1,1041 @@
+/**
+ * core.h - DesignWare USB3 DRD Core Header
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#ifndef __DRIVERS_USB_DWC3_CORE_H
+#define __DRIVERS_USB_DWC3_CORE_H
+
+#include <linux/device.h>
+#include <linux/spinlock.h>
+#include <linux/ioport.h>
+#include <linux/list.h>
+#include <linux/dma-mapping.h>
+#include <linux/mm.h>
+#include <linux/debugfs.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/otg.h>
+
+#include <linux/phy/phy.h>
+
+#define DWC3_MSG_MAX	500
+
+/* Global constants */
+#define DWC3_EP0_BOUNCE_SIZE	512
+#define DWC3_ENDPOINTS_NUM	32
+#define DWC3_XHCI_RESOURCES_NUM	2
+
+#define DWC3_SCRATCHBUF_SIZE	4096	/* each buffer is assumed to be 4KiB */
+#define DWC3_EVENT_SIZE		4	/* bytes */
+#define DWC3_EVENT_MAX_NUM	64	/* 2 events/endpoint */
+#define DWC3_EVENT_BUFFERS_SIZE	(DWC3_EVENT_SIZE * DWC3_EVENT_MAX_NUM)
+#define DWC3_EVENT_TYPE_MASK	0xfe
+
+#define DWC3_EVENT_TYPE_DEV	0
+#define DWC3_EVENT_TYPE_CARKIT	3
+#define DWC3_EVENT_TYPE_I2C	4
+
+#define DWC3_DEVICE_EVENT_DISCONNECT		0
+#define DWC3_DEVICE_EVENT_RESET			1
+#define DWC3_DEVICE_EVENT_CONNECT_DONE		2
+#define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE	3
+#define DWC3_DEVICE_EVENT_WAKEUP		4
+#define DWC3_DEVICE_EVENT_HIBER_REQ		5
+#define DWC3_DEVICE_EVENT_EOPF			6
+#define DWC3_DEVICE_EVENT_SOF			7
+#define DWC3_DEVICE_EVENT_ERRATIC_ERROR		9
+#define DWC3_DEVICE_EVENT_CMD_CMPL		10
+#define DWC3_DEVICE_EVENT_OVERFLOW		11
+
+#define DWC3_GEVNTCOUNT_MASK	0xfffc
+#define DWC3_GSNPSID_MASK	0xffff0000
+#define DWC3_GSNPSREV_MASK	0xffff
+
+/* DWC3 registers memory space boundries */
+#define DWC3_XHCI_REGS_START		0x0
+#define DWC3_XHCI_REGS_END		0x7fff
+#define DWC3_GLOBALS_REGS_START		0xc100
+#define DWC3_GLOBALS_REGS_END		0xc6ff
+#define DWC3_DEVICE_REGS_START		0xc700
+#define DWC3_DEVICE_REGS_END		0xcbff
+#define DWC3_OTG_REGS_START		0xcc00
+#define DWC3_OTG_REGS_END		0xccff
+
+/* Global Registers */
+#define DWC3_GSBUSCFG0		0xc100
+#define DWC3_GSBUSCFG1		0xc104
+#define DWC3_GTXTHRCFG		0xc108
+#define DWC3_GRXTHRCFG		0xc10c
+#define DWC3_GCTL		0xc110
+#define DWC3_GEVTEN		0xc114
+#define DWC3_GSTS		0xc118
+#define DWC3_GSNPSID		0xc120
+#define DWC3_GGPIO		0xc124
+#define DWC3_GUID		0xc128
+#define DWC3_GUCTL		0xc12c
+#define DWC3_GBUSERRADDR0	0xc130
+#define DWC3_GBUSERRADDR1	0xc134
+#define DWC3_GPRTBIMAP0		0xc138
+#define DWC3_GPRTBIMAP1		0xc13c
+#define DWC3_GHWPARAMS0		0xc140
+#define DWC3_GHWPARAMS1		0xc144
+#define DWC3_GHWPARAMS2		0xc148
+#define DWC3_GHWPARAMS3		0xc14c
+#define DWC3_GHWPARAMS4		0xc150
+#define DWC3_GHWPARAMS5		0xc154
+#define DWC3_GHWPARAMS6		0xc158
+#define DWC3_GHWPARAMS7		0xc15c
+#define DWC3_GDBGFIFOSPACE	0xc160
+#define DWC3_GDBGLTSSM		0xc164
+#define DWC3_GPRTBIMAP_HS0	0xc180
+#define DWC3_GPRTBIMAP_HS1	0xc184
+#define DWC3_GPRTBIMAP_FS0	0xc188
+#define DWC3_GPRTBIMAP_FS1	0xc18c
+
+#define DWC3_GUSB2PHYCFG(n)	(0xc200 + (n * 0x04))
+#define DWC3_GUSB2I2CCTL(n)	(0xc240 + (n * 0x04))
+
+#define DWC3_GUSB2PHYACC(n)	(0xc280 + (n * 0x04))
+
+#define DWC3_GUSB3PIPECTL(n)	(0xc2c0 + (n * 0x04))
+
+#define DWC3_GTXFIFOSIZ(n)	(0xc300 + (n * 0x04))
+#define DWC3_GRXFIFOSIZ(n)	(0xc380 + (n * 0x04))
+
+#define DWC3_GEVNTADRLO(n)	(0xc400 + (n * 0x10))
+#define DWC3_GEVNTADRHI(n)	(0xc404 + (n * 0x10))
+#define DWC3_GEVNTSIZ(n)	(0xc408 + (n * 0x10))
+#define DWC3_GEVNTCOUNT(n)	(0xc40c + (n * 0x10))
+
+#define DWC3_GHWPARAMS8		0xc600
+
+/* Device Registers */
+#define DWC3_DCFG		0xc700
+#define DWC3_DCTL		0xc704
+#define DWC3_DEVTEN		0xc708
+#define DWC3_DSTS		0xc70c
+#define DWC3_DGCMDPAR		0xc710
+#define DWC3_DGCMD		0xc714
+#define DWC3_DALEPENA		0xc720
+#define DWC3_DEPCMDPAR2(n)	(0xc800 + (n * 0x10))
+#define DWC3_DEPCMDPAR1(n)	(0xc804 + (n * 0x10))
+#define DWC3_DEPCMDPAR0(n)	(0xc808 + (n * 0x10))
+#define DWC3_DEPCMD(n)		(0xc80c + (n * 0x10))
+
+/* OTG Registers */
+#define DWC3_OCFG		0xcc00
+#define DWC3_OCTL		0xcc04
+#define DWC3_OEVT		0xcc08
+#define DWC3_OEVTEN		0xcc0C
+#define DWC3_OSTS		0xcc10
+
+/* Bit fields */
+
+/* Global Configuration Register */
+#define DWC3_GCTL_PWRDNSCALE(n)	((n) << 19)
+#define DWC3_GCTL_U2RSTECN	(1 << 16)
+#define DWC3_GCTL_RAMCLKSEL(x)	(((x) & DWC3_GCTL_CLK_MASK) << 6)
+#define DWC3_GCTL_CLK_BUS	(0)
+#define DWC3_GCTL_CLK_PIPE	(1)
+#define DWC3_GCTL_CLK_PIPEHALF	(2)
+#define DWC3_GCTL_CLK_MASK	(3)
+
+#define DWC3_GCTL_PRTCAP(n)	(((n) & (3 << 12)) >> 12)
+#define DWC3_GCTL_PRTCAPDIR(n)	((n) << 12)
+#define DWC3_GCTL_PRTCAP_HOST	1
+#define DWC3_GCTL_PRTCAP_DEVICE	2
+#define DWC3_GCTL_PRTCAP_OTG	3
+
+#define DWC3_GCTL_CORESOFTRESET		(1 << 11)
+#define DWC3_GCTL_SOFITPSYNC		(1 << 10)
+#define DWC3_GCTL_SCALEDOWN(n)		((n) << 4)
+#define DWC3_GCTL_SCALEDOWN_MASK	DWC3_GCTL_SCALEDOWN(3)
+#define DWC3_GCTL_DISSCRAMBLE		(1 << 3)
+#define DWC3_GCTL_U2EXIT_LFPS		(1 << 2)
+#define DWC3_GCTL_GBLHIBERNATIONEN	(1 << 1)
+#define DWC3_GCTL_DSBLCLKGTNG		(1 << 0)
+
+/* Global USB2 PHY Configuration Register */
+#define DWC3_GUSB2PHYCFG_PHYSOFTRST	(1 << 31)
+#define DWC3_GUSB2PHYCFG_SUSPHY		(1 << 6)
+
+/* Global USB3 PIPE Control Register */
+#define DWC3_GUSB3PIPECTL_PHYSOFTRST	(1 << 31)
+#define DWC3_GUSB3PIPECTL_U2SSINP3OK	(1 << 29)
+#define DWC3_GUSB3PIPECTL_REQP1P2P3	(1 << 24)
+#define DWC3_GUSB3PIPECTL_DEP1P2P3(n)	((n) << 19)
+#define DWC3_GUSB3PIPECTL_DEP1P2P3_MASK	DWC3_GUSB3PIPECTL_DEP1P2P3(7)
+#define DWC3_GUSB3PIPECTL_DEP1P2P3_EN	DWC3_GUSB3PIPECTL_DEP1P2P3(1)
+#define DWC3_GUSB3PIPECTL_DEPOCHANGE	(1 << 18)
+#define DWC3_GUSB3PIPECTL_SUSPHY	(1 << 17)
+#define DWC3_GUSB3PIPECTL_LFPSFILT	(1 << 9)
+#define DWC3_GUSB3PIPECTL_RX_DETOPOLL	(1 << 8)
+#define DWC3_GUSB3PIPECTL_TX_DEEPH_MASK	DWC3_GUSB3PIPECTL_TX_DEEPH(3)
+#define DWC3_GUSB3PIPECTL_TX_DEEPH(n)	((n) << 1)
+
+/* Global TX Fifo Size Register */
+#define DWC3_GTXFIFOSIZ_TXFDEF(n)	((n) & 0xffff)
+#define DWC3_GTXFIFOSIZ_TXFSTADDR(n)	((n) & 0xffff0000)
+
+/* Global Event Size Registers */
+#define DWC3_GEVNTSIZ_INTMASK		(1 << 31)
+#define DWC3_GEVNTSIZ_SIZE(n)		((n) & 0xffff)
+
+/* Global HWPARAMS1 Register */
+#define DWC3_GHWPARAMS1_EN_PWROPT(n)	(((n) & (3 << 24)) >> 24)
+#define DWC3_GHWPARAMS1_EN_PWROPT_NO	0
+#define DWC3_GHWPARAMS1_EN_PWROPT_CLK	1
+#define DWC3_GHWPARAMS1_EN_PWROPT_HIB	2
+#define DWC3_GHWPARAMS1_PWROPT(n)	((n) << 24)
+#define DWC3_GHWPARAMS1_PWROPT_MASK	DWC3_GHWPARAMS1_PWROPT(3)
+
+/* Global HWPARAMS3 Register */
+#define DWC3_GHWPARAMS3_SSPHY_IFC(n)		((n) & 3)
+#define DWC3_GHWPARAMS3_SSPHY_IFC_DIS		0
+#define DWC3_GHWPARAMS3_SSPHY_IFC_ENA		1
+#define DWC3_GHWPARAMS3_HSPHY_IFC(n)		(((n) & (3 << 2)) >> 2)
+#define DWC3_GHWPARAMS3_HSPHY_IFC_DIS		0
+#define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI		1
+#define DWC3_GHWPARAMS3_HSPHY_IFC_ULPI		2
+#define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI	3
+#define DWC3_GHWPARAMS3_FSPHY_IFC(n)		(((n) & (3 << 4)) >> 4)
+#define DWC3_GHWPARAMS3_FSPHY_IFC_DIS		0
+#define DWC3_GHWPARAMS3_FSPHY_IFC_ENA		1
+
+/* Global HWPARAMS4 Register */
+#define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n)	(((n) & (0x0f << 13)) >> 13)
+#define DWC3_MAX_HIBER_SCRATCHBUFS		15
+
+/* Global HWPARAMS6 Register */
+#define DWC3_GHWPARAMS6_EN_FPGA			(1 << 7)
+
+/* Device Configuration Register */
+#define DWC3_DCFG_DEVADDR(addr)	((addr) << 3)
+#define DWC3_DCFG_DEVADDR_MASK	DWC3_DCFG_DEVADDR(0x7f)
+
+#define DWC3_DCFG_SPEED_MASK	(7 << 0)
+#define DWC3_DCFG_SUPERSPEED	(4 << 0)
+#define DWC3_DCFG_HIGHSPEED	(0 << 0)
+#define DWC3_DCFG_FULLSPEED2	(1 << 0)
+#define DWC3_DCFG_LOWSPEED	(2 << 0)
+#define DWC3_DCFG_FULLSPEED1	(3 << 0)
+
+#define DWC3_DCFG_LPM_CAP	(1 << 22)
+
+/* Device Control Register */
+#define DWC3_DCTL_RUN_STOP	(1 << 31)
+#define DWC3_DCTL_CSFTRST	(1 << 30)
+#define DWC3_DCTL_LSFTRST	(1 << 29)
+
+#define DWC3_DCTL_HIRD_THRES_MASK	(0x1f << 24)
+#define DWC3_DCTL_HIRD_THRES(n)	((n) << 24)
+
+#define DWC3_DCTL_APPL1RES	(1 << 23)
+
+/* These apply for core versions 1.87a and earlier */
+#define DWC3_DCTL_TRGTULST_MASK		(0x0f << 17)
+#define DWC3_DCTL_TRGTULST(n)		((n) << 17)
+#define DWC3_DCTL_TRGTULST_U2		(DWC3_DCTL_TRGTULST(2))
+#define DWC3_DCTL_TRGTULST_U3		(DWC3_DCTL_TRGTULST(3))
+#define DWC3_DCTL_TRGTULST_SS_DIS	(DWC3_DCTL_TRGTULST(4))
+#define DWC3_DCTL_TRGTULST_RX_DET	(DWC3_DCTL_TRGTULST(5))
+#define DWC3_DCTL_TRGTULST_SS_INACT	(DWC3_DCTL_TRGTULST(6))
+
+/* These apply for core versions 1.94a and later */
+#define DWC3_DCTL_LPM_ERRATA_MASK	DWC3_DCTL_LPM_ERRATA(0xf)
+#define DWC3_DCTL_LPM_ERRATA(n)		((n) << 20)
+
+#define DWC3_DCTL_KEEP_CONNECT		(1 << 19)
+#define DWC3_DCTL_L1_HIBER_EN		(1 << 18)
+#define DWC3_DCTL_CRS			(1 << 17)
+#define DWC3_DCTL_CSS			(1 << 16)
+
+#define DWC3_DCTL_INITU2ENA		(1 << 12)
+#define DWC3_DCTL_ACCEPTU2ENA		(1 << 11)
+#define DWC3_DCTL_INITU1ENA		(1 << 10)
+#define DWC3_DCTL_ACCEPTU1ENA		(1 << 9)
+#define DWC3_DCTL_TSTCTRL_MASK		(0xf << 1)
+
+#define DWC3_DCTL_ULSTCHNGREQ_MASK	(0x0f << 5)
+#define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK)
+
+#define DWC3_DCTL_ULSTCHNG_NO_ACTION	(DWC3_DCTL_ULSTCHNGREQ(0))
+#define DWC3_DCTL_ULSTCHNG_SS_DISABLED	(DWC3_DCTL_ULSTCHNGREQ(4))
+#define DWC3_DCTL_ULSTCHNG_RX_DETECT	(DWC3_DCTL_ULSTCHNGREQ(5))
+#define DWC3_DCTL_ULSTCHNG_SS_INACTIVE	(DWC3_DCTL_ULSTCHNGREQ(6))
+#define DWC3_DCTL_ULSTCHNG_RECOVERY	(DWC3_DCTL_ULSTCHNGREQ(8))
+#define DWC3_DCTL_ULSTCHNG_COMPLIANCE	(DWC3_DCTL_ULSTCHNGREQ(10))
+#define DWC3_DCTL_ULSTCHNG_LOOPBACK	(DWC3_DCTL_ULSTCHNGREQ(11))
+
+/* Device Event Enable Register */
+#define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN	(1 << 12)
+#define DWC3_DEVTEN_EVNTOVERFLOWEN	(1 << 11)
+#define DWC3_DEVTEN_CMDCMPLTEN		(1 << 10)
+#define DWC3_DEVTEN_ERRTICERREN		(1 << 9)
+#define DWC3_DEVTEN_SOFEN		(1 << 7)
+#define DWC3_DEVTEN_EOPFEN		(1 << 6)
+#define DWC3_DEVTEN_HIBERNATIONREQEVTEN	(1 << 5)
+#define DWC3_DEVTEN_WKUPEVTEN		(1 << 4)
+#define DWC3_DEVTEN_ULSTCNGEN		(1 << 3)
+#define DWC3_DEVTEN_CONNECTDONEEN	(1 << 2)
+#define DWC3_DEVTEN_USBRSTEN		(1 << 1)
+#define DWC3_DEVTEN_DISCONNEVTEN	(1 << 0)
+
+/* Device Status Register */
+#define DWC3_DSTS_DCNRD			(1 << 29)
+
+/* This applies for core versions 1.87a and earlier */
+#define DWC3_DSTS_PWRUPREQ		(1 << 24)
+
+/* These apply for core versions 1.94a and later */
+#define DWC3_DSTS_RSS			(1 << 25)
+#define DWC3_DSTS_SSS			(1 << 24)
+
+#define DWC3_DSTS_COREIDLE		(1 << 23)
+#define DWC3_DSTS_DEVCTRLHLT		(1 << 22)
+
+#define DWC3_DSTS_USBLNKST_MASK		(0x0f << 18)
+#define DWC3_DSTS_USBLNKST(n)		(((n) & DWC3_DSTS_USBLNKST_MASK) >> 18)
+
+#define DWC3_DSTS_RXFIFOEMPTY		(1 << 17)
+
+#define DWC3_DSTS_SOFFN_MASK		(0x3fff << 3)
+#define DWC3_DSTS_SOFFN(n)		(((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
+
+#define DWC3_DSTS_CONNECTSPD		(7 << 0)
+
+#define DWC3_DSTS_SUPERSPEED		(4 << 0)
+#define DWC3_DSTS_HIGHSPEED		(0 << 0)
+#define DWC3_DSTS_FULLSPEED2		(1 << 0)
+#define DWC3_DSTS_LOWSPEED		(2 << 0)
+#define DWC3_DSTS_FULLSPEED1		(3 << 0)
+
+/* Device Generic Command Register */
+#define DWC3_DGCMD_SET_LMP		0x01
+#define DWC3_DGCMD_SET_PERIODIC_PAR	0x02
+#define DWC3_DGCMD_XMIT_FUNCTION	0x03
+
+/* These apply for core versions 1.94a and later */
+#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO	0x04
+#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI	0x05
+
+#define DWC3_DGCMD_SELECTED_FIFO_FLUSH	0x09
+#define DWC3_DGCMD_ALL_FIFO_FLUSH	0x0a
+#define DWC3_DGCMD_SET_ENDPOINT_NRDY	0x0c
+#define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK	0x10
+
+#define DWC3_DGCMD_STATUS(n)		(((n) >> 15) & 1)
+#define DWC3_DGCMD_CMDACT		(1 << 10)
+#define DWC3_DGCMD_CMDIOC		(1 << 8)
+
+/* Device Generic Command Parameter Register */
+#define DWC3_DGCMDPAR_FORCE_LINKPM_ACCEPT	(1 << 0)
+#define DWC3_DGCMDPAR_FIFO_NUM(n)		((n) << 0)
+#define DWC3_DGCMDPAR_RX_FIFO			(0 << 5)
+#define DWC3_DGCMDPAR_TX_FIFO			(1 << 5)
+#define DWC3_DGCMDPAR_LOOPBACK_DIS		(0 << 0)
+#define DWC3_DGCMDPAR_LOOPBACK_ENA		(1 << 0)
+
+/* Device Endpoint Command Register */
+#define DWC3_DEPCMD_PARAM_SHIFT		16
+#define DWC3_DEPCMD_PARAM(x)		((x) << DWC3_DEPCMD_PARAM_SHIFT)
+#define DWC3_DEPCMD_GET_RSC_IDX(x)	(((x) >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f)
+#define DWC3_DEPCMD_STATUS(x)		(((x) >> 15) & 1)
+#define DWC3_DEPCMD_HIPRI_FORCERM	(1 << 11)
+#define DWC3_DEPCMD_CMDACT		(1 << 10)
+#define DWC3_DEPCMD_CMDIOC		(1 << 8)
+
+#define DWC3_DEPCMD_DEPSTARTCFG		(0x09 << 0)
+#define DWC3_DEPCMD_ENDTRANSFER		(0x08 << 0)
+#define DWC3_DEPCMD_UPDATETRANSFER	(0x07 << 0)
+#define DWC3_DEPCMD_STARTTRANSFER	(0x06 << 0)
+#define DWC3_DEPCMD_CLEARSTALL		(0x05 << 0)
+#define DWC3_DEPCMD_SETSTALL		(0x04 << 0)
+/* This applies for core versions 1.90a and earlier */
+#define DWC3_DEPCMD_GETSEQNUMBER	(0x03 << 0)
+/* This applies for core versions 1.94a and later */
+#define DWC3_DEPCMD_GETEPSTATE		(0x03 << 0)
+#define DWC3_DEPCMD_SETTRANSFRESOURCE	(0x02 << 0)
+#define DWC3_DEPCMD_SETEPCONFIG		(0x01 << 0)
+
+/* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
+#define DWC3_DALEPENA_EP(n)		(1 << n)
+
+#define DWC3_DEPCMD_TYPE_CONTROL	0
+#define DWC3_DEPCMD_TYPE_ISOC		1
+#define DWC3_DEPCMD_TYPE_BULK		2
+#define DWC3_DEPCMD_TYPE_INTR		3
+
+/* Structures */
+
+struct dwc3_trb;
+
+/**
+ * struct dwc3_event_buffer - Software event buffer representation
+ * @buf: _THE_ buffer
+ * @length: size of this buffer
+ * @lpos: event offset
+ * @count: cache of last read event count register
+ * @flags: flags related to this event buffer
+ * @dma: dma_addr_t
+ * @dwc: pointer to DWC controller
+ */
+struct dwc3_event_buffer {
+	void			*buf;
+	unsigned		length;
+	unsigned int		lpos;
+	unsigned int		count;
+	unsigned int		flags;
+
+#define DWC3_EVENT_PENDING	BIT(0)
+
+	dma_addr_t		dma;
+
+	struct dwc3		*dwc;
+};
+
+#define DWC3_EP_FLAG_STALLED	(1 << 0)
+#define DWC3_EP_FLAG_WEDGED	(1 << 1)
+
+#define DWC3_EP_DIRECTION_TX	true
+#define DWC3_EP_DIRECTION_RX	false
+
+#define DWC3_TRB_NUM		32
+#define DWC3_TRB_MASK		(DWC3_TRB_NUM - 1)
+
+/**
+ * struct dwc3_ep - device side endpoint representation
+ * @endpoint: usb endpoint
+ * @request_list: list of requests for this endpoint
+ * @req_queued: list of requests on this ep which have TRBs setup
+ * @trb_pool: array of transaction buffers
+ * @trb_pool_dma: dma address of @trb_pool
+ * @free_slot: next slot which is going to be used
+ * @busy_slot: first slot which is owned by HW
+ * @desc: usb_endpoint_descriptor pointer
+ * @dwc: pointer to DWC controller
+ * @saved_state: ep state saved during hibernation
+ * @flags: endpoint flags (wedged, stalled, ...)
+ * @current_trb: index of current used trb
+ * @number: endpoint number (1 - 15)
+ * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
+ * @resource_index: Resource transfer index
+ * @interval: the interval on which the ISOC transfer is started
+ * @name: a human readable name e.g. ep1out-bulk
+ * @direction: true for TX, false for RX
+ * @stream_capable: true when streams are enabled
+ */
+struct dwc3_ep {
+	struct usb_ep		endpoint;
+	struct list_head	request_list;
+	struct list_head	req_queued;
+
+	struct dwc3_trb		*trb_pool;
+	dma_addr_t		trb_pool_dma;
+	u32			free_slot;
+	u32			busy_slot;
+	const struct usb_ss_ep_comp_descriptor *comp_desc;
+	struct dwc3		*dwc;
+
+	u32			saved_state;
+	unsigned		flags;
+#define DWC3_EP_ENABLED		(1 << 0)
+#define DWC3_EP_STALL		(1 << 1)
+#define DWC3_EP_WEDGE		(1 << 2)
+#define DWC3_EP_BUSY		(1 << 4)
+#define DWC3_EP_PENDING_REQUEST	(1 << 5)
+#define DWC3_EP_MISSED_ISOC	(1 << 6)
+
+	/* This last one is specific to EP0 */
+#define DWC3_EP0_DIR_IN		(1 << 31)
+
+	unsigned		current_trb;
+
+	u8			number;
+	u8			type;
+	u8			resource_index;
+	u32			interval;
+
+	char			name[20];
+
+	unsigned		direction:1;
+	unsigned		stream_capable:1;
+};
+
+enum dwc3_phy {
+	DWC3_PHY_UNKNOWN = 0,
+	DWC3_PHY_USB3,
+	DWC3_PHY_USB2,
+};
+
+enum dwc3_ep0_next {
+	DWC3_EP0_UNKNOWN = 0,
+	DWC3_EP0_COMPLETE,
+	DWC3_EP0_NRDY_DATA,
+	DWC3_EP0_NRDY_STATUS,
+};
+
+enum dwc3_ep0_state {
+	EP0_UNCONNECTED		= 0,
+	EP0_SETUP_PHASE,
+	EP0_DATA_PHASE,
+	EP0_STATUS_PHASE,
+};
+
+enum dwc3_link_state {
+	/* In SuperSpeed */
+	DWC3_LINK_STATE_U0		= 0x00, /* in HS, means ON */
+	DWC3_LINK_STATE_U1		= 0x01,
+	DWC3_LINK_STATE_U2		= 0x02, /* in HS, means SLEEP */
+	DWC3_LINK_STATE_U3		= 0x03, /* in HS, means SUSPEND */
+	DWC3_LINK_STATE_SS_DIS		= 0x04,
+	DWC3_LINK_STATE_RX_DET		= 0x05, /* in HS, means Early Suspend */
+	DWC3_LINK_STATE_SS_INACT	= 0x06,
+	DWC3_LINK_STATE_POLL		= 0x07,
+	DWC3_LINK_STATE_RECOV		= 0x08,
+	DWC3_LINK_STATE_HRESET		= 0x09,
+	DWC3_LINK_STATE_CMPLY		= 0x0a,
+	DWC3_LINK_STATE_LPBK		= 0x0b,
+	DWC3_LINK_STATE_RESET		= 0x0e,
+	DWC3_LINK_STATE_RESUME		= 0x0f,
+	DWC3_LINK_STATE_MASK		= 0x0f,
+};
+
+/* TRB Length, PCM and Status */
+#define DWC3_TRB_SIZE_MASK	(0x00ffffff)
+#define DWC3_TRB_SIZE_LENGTH(n)	((n) & DWC3_TRB_SIZE_MASK)
+#define DWC3_TRB_SIZE_PCM1(n)	(((n) & 0x03) << 24)
+#define DWC3_TRB_SIZE_TRBSTS(n)	(((n) & (0x0f << 28)) >> 28)
+
+#define DWC3_TRBSTS_OK			0
+#define DWC3_TRBSTS_MISSED_ISOC		1
+#define DWC3_TRBSTS_SETUP_PENDING	2
+#define DWC3_TRB_STS_XFER_IN_PROG	4
+
+/* TRB Control */
+#define DWC3_TRB_CTRL_HWO		(1 << 0)
+#define DWC3_TRB_CTRL_LST		(1 << 1)
+#define DWC3_TRB_CTRL_CHN		(1 << 2)
+#define DWC3_TRB_CTRL_CSP		(1 << 3)
+#define DWC3_TRB_CTRL_TRBCTL(n)		(((n) & 0x3f) << 4)
+#define DWC3_TRB_CTRL_ISP_IMI		(1 << 10)
+#define DWC3_TRB_CTRL_IOC		(1 << 11)
+#define DWC3_TRB_CTRL_SID_SOFN(n)	(((n) & 0xffff) << 14)
+
+#define DWC3_TRBCTL_NORMAL		DWC3_TRB_CTRL_TRBCTL(1)
+#define DWC3_TRBCTL_CONTROL_SETUP	DWC3_TRB_CTRL_TRBCTL(2)
+#define DWC3_TRBCTL_CONTROL_STATUS2	DWC3_TRB_CTRL_TRBCTL(3)
+#define DWC3_TRBCTL_CONTROL_STATUS3	DWC3_TRB_CTRL_TRBCTL(4)
+#define DWC3_TRBCTL_CONTROL_DATA	DWC3_TRB_CTRL_TRBCTL(5)
+#define DWC3_TRBCTL_ISOCHRONOUS_FIRST	DWC3_TRB_CTRL_TRBCTL(6)
+#define DWC3_TRBCTL_ISOCHRONOUS		DWC3_TRB_CTRL_TRBCTL(7)
+#define DWC3_TRBCTL_LINK_TRB		DWC3_TRB_CTRL_TRBCTL(8)
+
+/**
+ * struct dwc3_trb - transfer request block (hw format)
+ * @bpl: DW0-3
+ * @bph: DW4-7
+ * @size: DW8-B
+ * @trl: DWC-F
+ */
+struct dwc3_trb {
+	u32		bpl;
+	u32		bph;
+	u32		size;
+	u32		ctrl;
+} __packed;
+
+/**
+ * dwc3_hwparams - copy of HWPARAMS registers
+ * @hwparams0 - GHWPARAMS0
+ * @hwparams1 - GHWPARAMS1
+ * @hwparams2 - GHWPARAMS2
+ * @hwparams3 - GHWPARAMS3
+ * @hwparams4 - GHWPARAMS4
+ * @hwparams5 - GHWPARAMS5
+ * @hwparams6 - GHWPARAMS6
+ * @hwparams7 - GHWPARAMS7
+ * @hwparams8 - GHWPARAMS8
+ */
+struct dwc3_hwparams {
+	u32	hwparams0;
+	u32	hwparams1;
+	u32	hwparams2;
+	u32	hwparams3;
+	u32	hwparams4;
+	u32	hwparams5;
+	u32	hwparams6;
+	u32	hwparams7;
+	u32	hwparams8;
+};
+
+/* HWPARAMS0 */
+#define DWC3_MODE(n)		((n) & 0x7)
+
+#define DWC3_MDWIDTH(n)		(((n) & 0xff00) >> 8)
+
+/* HWPARAMS1 */
+#define DWC3_NUM_INT(n)		(((n) & (0x3f << 15)) >> 15)
+
+/* HWPARAMS3 */
+#define DWC3_NUM_IN_EPS_MASK	(0x1f << 18)
+#define DWC3_NUM_EPS_MASK	(0x3f << 12)
+#define DWC3_NUM_EPS(p)		(((p)->hwparams3 &		\
+			(DWC3_NUM_EPS_MASK)) >> 12)
+#define DWC3_NUM_IN_EPS(p)	(((p)->hwparams3 &		\
+			(DWC3_NUM_IN_EPS_MASK)) >> 18)
+
+/* HWPARAMS7 */
+#define DWC3_RAM1_DEPTH(n)	((n) & 0xffff)
+
+struct dwc3_request {
+	struct usb_request	request;
+	struct list_head	list;
+	struct dwc3_ep		*dep;
+	u32			start_slot;
+
+	u8			epnum;
+	struct dwc3_trb		*trb;
+	dma_addr_t		trb_dma;
+
+	unsigned		direction:1;
+	unsigned		mapped:1;
+	unsigned		queued:1;
+};
+
+/*
+ * struct dwc3_scratchpad_array - hibernation scratchpad array
+ * (format defined by hw)
+ */
+struct dwc3_scratchpad_array {
+	__le64	dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
+};
+
+/**
+ * struct dwc3 - representation of our controller
+ * @ctrl_req: usb control request which is used for ep0
+ * @ep0_trb: trb which is used for the ctrl_req
+ * @ep0_bounce: bounce buffer for ep0
+ * @setup_buf: used while precessing STD USB requests
+ * @ctrl_req_addr: dma address of ctrl_req
+ * @ep0_trb: dma address of ep0_trb
+ * @ep0_usb_req: dummy req used while handling STD USB requests
+ * @ep0_bounce_addr: dma address of ep0_bounce
+ * @scratch_addr: dma address of scratchbuf
+ * @lock: for synchronizing
+ * @dev: pointer to our struct device
+ * @xhci: pointer to our xHCI child
+ * @event_buffer_list: a list of event buffers
+ * @gadget: device side representation of the peripheral controller
+ * @gadget_driver: pointer to the gadget driver
+ * @regs: base address for our registers
+ * @regs_size: address space size
+ * @nr_scratch: number of scratch buffers
+ * @num_event_buffers: calculated number of event buffers
+ * @u1u2: only used on revisions <1.83a for workaround
+ * @maximum_speed: maximum speed requested (mainly for testing purposes)
+ * @revision: revision register contents
+ * @dr_mode: requested mode of operation
+ * @usb2_phy: pointer to USB2 PHY
+ * @usb3_phy: pointer to USB3 PHY
+ * @usb2_generic_phy: pointer to USB2 PHY
+ * @usb3_generic_phy: pointer to USB3 PHY
+ * @dcfg: saved contents of DCFG register
+ * @gctl: saved contents of GCTL register
+ * @isoch_delay: wValue from Set Isochronous Delay request;
+ * @u2sel: parameter from Set SEL request.
+ * @u2pel: parameter from Set SEL request.
+ * @u1sel: parameter from Set SEL request.
+ * @u1pel: parameter from Set SEL request.
+ * @num_out_eps: number of out endpoints
+ * @num_in_eps: number of in endpoints
+ * @ep0_next_event: hold the next expected event
+ * @ep0state: state of endpoint zero
+ * @link_state: link state
+ * @speed: device speed (super, high, full, low)
+ * @mem: points to start of memory which is used for this struct.
+ * @hwparams: copy of hwparams registers
+ * @root: debugfs root folder pointer
+ * @regset: debugfs pointer to regdump file
+ * @test_mode: true when we're entering a USB test mode
+ * @test_mode_nr: test feature selector
+ * @lpm_nyet_threshold: LPM NYET response threshold
+ * @hird_threshold: HIRD threshold
+ * @delayed_status: true when gadget driver asks for delayed status
+ * @ep0_bounced: true when we used bounce buffer
+ * @ep0_expect_in: true when we expect a DATA IN transfer
+ * @has_hibernation: true when dwc3 was configured with Hibernation
+ * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that
+ *			there's now way for software to detect this in runtime.
+ * @is_utmi_l1_suspend: the core asserts output signal
+ * 	0	- utmi_sleep_n
+ * 	1	- utmi_l1_suspend_n
+ * @is_selfpowered: true when we are selfpowered
+ * @is_fpga: true when we are using the FPGA board
+ * @needs_fifo_resize: not all users might want fifo resizing, flag it
+ * @pullups_connected: true when Run/Stop bit is set
+ * @resize_fifos: tells us it's ok to reconfigure our TxFIFO sizes.
+ * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
+ * @start_config_issued: true when StartConfig command has been issued
+ * @three_stage_setup: set if we perform a three phase setup
+ * @disable_scramble_quirk: set if we enable the disable scramble quirk
+ * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
+ * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
+ * @req_p1p2p3_quirk: set if we enable request p1p2p3 quirk
+ * @del_p1p2p3_quirk: set if we enable delay p1p2p3 quirk
+ * @del_phy_power_chg_quirk: set if we enable delay phy power change quirk
+ * @lfps_filter_quirk: set if we enable LFPS filter quirk
+ * @rx_detect_poll_quirk: set if we enable rx_detect to polling lfps quirk
+ * @dis_u3_susphy_quirk: set if we disable usb3 suspend phy
+ * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy
+ * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
+ * @tx_de_emphasis: Tx de-emphasis value
+ * 	0	- -6dB de-emphasis
+ * 	1	- -3.5dB de-emphasis
+ * 	2	- No de-emphasis
+ * 	3	- Reserved
+ */
+struct dwc3 {
+	struct usb_ctrlrequest	*ctrl_req;
+	struct dwc3_trb		*ep0_trb;
+	void			*ep0_bounce;
+	void			*scratchbuf;
+	u8			*setup_buf;
+	dma_addr_t		ctrl_req_addr;
+	dma_addr_t		ep0_trb_addr;
+	dma_addr_t		ep0_bounce_addr;
+	dma_addr_t		scratch_addr;
+	struct dwc3_request	ep0_usb_req;
+
+	/* device lock */
+	spinlock_t		lock;
+
+	struct device		*dev;
+
+	struct platform_device	*xhci;
+	struct resource		xhci_resources[DWC3_XHCI_RESOURCES_NUM];
+
+	struct dwc3_event_buffer **ev_buffs;
+	struct dwc3_ep		*eps[DWC3_ENDPOINTS_NUM];
+
+	struct usb_gadget	gadget;
+	struct usb_gadget_driver *gadget_driver;
+
+	struct usb_phy		*usb2_phy;
+	struct usb_phy		*usb3_phy;
+
+	struct phy		*usb2_generic_phy;
+	struct phy		*usb3_generic_phy;
+
+	void __iomem		*regs;
+	size_t			regs_size;
+
+	enum usb_dr_mode	dr_mode;
+
+	/* used for suspend/resume */
+	u32			dcfg;
+	u32			gctl;
+
+	u32			nr_scratch;
+	u32			num_event_buffers;
+	u32			u1u2;
+	u32			maximum_speed;
+	u32			revision;
+
+#define DWC3_REVISION_173A	0x5533173a
+#define DWC3_REVISION_175A	0x5533175a
+#define DWC3_REVISION_180A	0x5533180a
+#define DWC3_REVISION_183A	0x5533183a
+#define DWC3_REVISION_185A	0x5533185a
+#define DWC3_REVISION_187A	0x5533187a
+#define DWC3_REVISION_188A	0x5533188a
+#define DWC3_REVISION_190A	0x5533190a
+#define DWC3_REVISION_194A	0x5533194a
+#define DWC3_REVISION_200A	0x5533200a
+#define DWC3_REVISION_202A	0x5533202a
+#define DWC3_REVISION_210A	0x5533210a
+#define DWC3_REVISION_220A	0x5533220a
+#define DWC3_REVISION_230A	0x5533230a
+#define DWC3_REVISION_240A	0x5533240a
+#define DWC3_REVISION_250A	0x5533250a
+#define DWC3_REVISION_260A	0x5533260a
+#define DWC3_REVISION_270A	0x5533270a
+#define DWC3_REVISION_280A	0x5533280a
+
+	enum dwc3_ep0_next	ep0_next_event;
+	enum dwc3_ep0_state	ep0state;
+	enum dwc3_link_state	link_state;
+
+	u16			isoch_delay;
+	u16			u2sel;
+	u16			u2pel;
+	u8			u1sel;
+	u8			u1pel;
+
+	u8			speed;
+
+	u8			num_out_eps;
+	u8			num_in_eps;
+
+	void			*mem;
+
+	struct dwc3_hwparams	hwparams;
+	struct dentry		*root;
+	struct debugfs_regset32	*regset;
+
+	u8			test_mode;
+	u8			test_mode_nr;
+	u8			lpm_nyet_threshold;
+	u8			hird_threshold;
+
+	unsigned		delayed_status:1;
+	unsigned		ep0_bounced:1;
+	unsigned		ep0_expect_in:1;
+	unsigned		has_hibernation:1;
+	unsigned		has_lpm_erratum:1;
+	unsigned		is_utmi_l1_suspend:1;
+	unsigned		is_selfpowered:1;
+	unsigned		is_fpga:1;
+	unsigned		needs_fifo_resize:1;
+	unsigned		pullups_connected:1;
+	unsigned		resize_fifos:1;
+	unsigned		setup_packet_pending:1;
+	unsigned		start_config_issued:1;
+	unsigned		three_stage_setup:1;
+
+	unsigned		disable_scramble_quirk:1;
+	unsigned		u2exit_lfps_quirk:1;
+	unsigned		u2ss_inp3_quirk:1;
+	unsigned		req_p1p2p3_quirk:1;
+	unsigned                del_p1p2p3_quirk:1;
+	unsigned		del_phy_power_chg_quirk:1;
+	unsigned		lfps_filter_quirk:1;
+	unsigned		rx_detect_poll_quirk:1;
+	unsigned		dis_u3_susphy_quirk:1;
+	unsigned		dis_u2_susphy_quirk:1;
+
+	unsigned		tx_de_emphasis_quirk:1;
+	unsigned		tx_de_emphasis:2;
+};
+
+/* -------------------------------------------------------------------------- */
+
+/* -------------------------------------------------------------------------- */
+
+struct dwc3_event_type {
+	u32	is_devspec:1;
+	u32	type:7;
+	u32	reserved8_31:24;
+} __packed;
+
+#define DWC3_DEPEVT_XFERCOMPLETE	0x01
+#define DWC3_DEPEVT_XFERINPROGRESS	0x02
+#define DWC3_DEPEVT_XFERNOTREADY	0x03
+#define DWC3_DEPEVT_RXTXFIFOEVT		0x04
+#define DWC3_DEPEVT_STREAMEVT		0x06
+#define DWC3_DEPEVT_EPCMDCMPLT		0x07
+
+/**
+ * struct dwc3_event_depvt - Device Endpoint Events
+ * @one_bit: indicates this is an endpoint event (not used)
+ * @endpoint_number: number of the endpoint
+ * @endpoint_event: The event we have:
+ *	0x00	- Reserved
+ *	0x01	- XferComplete
+ *	0x02	- XferInProgress
+ *	0x03	- XferNotReady
+ *	0x04	- RxTxFifoEvt (IN->Underrun, OUT->Overrun)
+ *	0x05	- Reserved
+ *	0x06	- StreamEvt
+ *	0x07	- EPCmdCmplt
+ * @reserved11_10: Reserved, don't use.
+ * @status: Indicates the status of the event. Refer to databook for
+ *	more information.
+ * @parameters: Parameters of the current event. Refer to databook for
+ *	more information.
+ */
+struct dwc3_event_depevt {
+	u32	one_bit:1;
+	u32	endpoint_number:5;
+	u32	endpoint_event:4;
+	u32	reserved11_10:2;
+	u32	status:4;
+
+/* Within XferNotReady */
+#define DEPEVT_STATUS_TRANSFER_ACTIVE	(1 << 3)
+
+/* Within XferComplete */
+#define DEPEVT_STATUS_BUSERR	(1 << 0)
+#define DEPEVT_STATUS_SHORT	(1 << 1)
+#define DEPEVT_STATUS_IOC	(1 << 2)
+#define DEPEVT_STATUS_LST	(1 << 3)
+
+/* Stream event only */
+#define DEPEVT_STREAMEVT_FOUND		1
+#define DEPEVT_STREAMEVT_NOTFOUND	2
+
+/* Control-only Status */
+#define DEPEVT_STATUS_CONTROL_DATA	1
+#define DEPEVT_STATUS_CONTROL_STATUS	2
+
+	u32	parameters:16;
+} __packed;
+
+/**
+ * struct dwc3_event_devt - Device Events
+ * @one_bit: indicates this is a non-endpoint event (not used)
+ * @device_event: indicates it's a device event. Should read as 0x00
+ * @type: indicates the type of device event.
+ *	0	- DisconnEvt
+ *	1	- USBRst
+ *	2	- ConnectDone
+ *	3	- ULStChng
+ *	4	- WkUpEvt
+ *	5	- Reserved
+ *	6	- EOPF
+ *	7	- SOF
+ *	8	- Reserved
+ *	9	- ErrticErr
+ *	10	- CmdCmplt
+ *	11	- EvntOverflow
+ *	12	- VndrDevTstRcved
+ * @reserved15_12: Reserved, not used
+ * @event_info: Information about this event
+ * @reserved31_25: Reserved, not used
+ */
+struct dwc3_event_devt {
+	u32	one_bit:1;
+	u32	device_event:7;
+	u32	type:4;
+	u32	reserved15_12:4;
+	u32	event_info:9;
+	u32	reserved31_25:7;
+} __packed;
+
+/**
+ * struct dwc3_event_gevt - Other Core Events
+ * @one_bit: indicates this is a non-endpoint event (not used)
+ * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
+ * @phy_port_number: self-explanatory
+ * @reserved31_12: Reserved, not used.
+ */
+struct dwc3_event_gevt {
+	u32	one_bit:1;
+	u32	device_event:7;
+	u32	phy_port_number:4;
+	u32	reserved31_12:20;
+} __packed;
+
+/**
+ * union dwc3_event - representation of Event Buffer contents
+ * @raw: raw 32-bit event
+ * @type: the type of the event
+ * @depevt: Device Endpoint Event
+ * @devt: Device Event
+ * @gevt: Global Event
+ */
+union dwc3_event {
+	u32				raw;
+	struct dwc3_event_type		type;
+	struct dwc3_event_depevt	depevt;
+	struct dwc3_event_devt		devt;
+	struct dwc3_event_gevt		gevt;
+};
+
+/**
+ * struct dwc3_gadget_ep_cmd_params - representation of endpoint command
+ * parameters
+ * @param2: third parameter
+ * @param1: second parameter
+ * @param0: first parameter
+ */
+struct dwc3_gadget_ep_cmd_params {
+	u32	param2;
+	u32	param1;
+	u32	param0;
+};
+
+/*
+ * DWC3 Features to be used as Driver Data
+ */
+
+#define DWC3_HAS_PERIPHERAL		BIT(0)
+#define DWC3_HAS_XHCI			BIT(1)
+#define DWC3_HAS_OTG			BIT(3)
+
+/* prototypes */
+void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
+int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
+
+#if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
+int dwc3_host_init(struct dwc3 *dwc);
+void dwc3_host_exit(struct dwc3 *dwc);
+#else
+static inline int dwc3_host_init(struct dwc3 *dwc)
+{ return 0; }
+static inline void dwc3_host_exit(struct dwc3 *dwc)
+{ }
+#endif
+
+#if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
+int dwc3_gadget_init(struct dwc3 *dwc);
+void dwc3_gadget_exit(struct dwc3 *dwc);
+int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
+int dwc3_gadget_get_link_state(struct dwc3 *dwc);
+int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
+int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
+		unsigned cmd, struct dwc3_gadget_ep_cmd_params *params);
+int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
+#else
+static inline int dwc3_gadget_init(struct dwc3 *dwc)
+{ return 0; }
+static inline void dwc3_gadget_exit(struct dwc3 *dwc)
+{ }
+static inline int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)
+{ return 0; }
+static inline int dwc3_gadget_get_link_state(struct dwc3 *dwc)
+{ return 0; }
+static inline int dwc3_gadget_set_link_state(struct dwc3 *dwc,
+		enum dwc3_link_state state)
+{ return 0; }
+
+static inline int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
+		unsigned cmd, struct dwc3_gadget_ep_cmd_params *params)
+{ return 0; }
+static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
+		int cmd, u32 param)
+{ return 0; }
+#endif
+
+/* power management interface */
+#if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
+int dwc3_gadget_suspend(struct dwc3 *dwc);
+int dwc3_gadget_resume(struct dwc3 *dwc);
+#else
+static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
+{
+	return 0;
+}
+
+static inline int dwc3_gadget_resume(struct dwc3 *dwc)
+{
+	return 0;
+}
+#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
+
+#endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/debug.c b/drivers/usb/dwc3/debug.c
new file mode 100644
index 0000000..0be6885
--- /dev/null
+++ b/drivers/usb/dwc3/debug.c
@@ -0,0 +1,32 @@
+/**
+ * debug.c - DesignWare USB3 DRD Controller Debug/Trace Support
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author: Felipe Balbi <balbi@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include "debug.h"
+
+void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...)
+{
+	struct va_format vaf;
+	va_list args;
+
+	va_start(args, fmt);
+	vaf.fmt = fmt;
+	vaf.va = &args;
+
+	trace(&vaf);
+
+	va_end(args);
+}
diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
new file mode 100644
index 0000000..07fbc2d
--- /dev/null
+++ b/drivers/usb/dwc3/debug.h
@@ -0,0 +1,228 @@
+/**
+ * debug.h - DesignWare USB3 DRD Controller Debug Header
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#ifndef __DWC3_DEBUG_H
+#define __DWC3_DEBUG_H
+
+#include "core.h"
+
+/**
+ * dwc3_gadget_ep_cmd_string - returns endpoint command string
+ * @cmd: command code
+ */
+static inline const char *
+dwc3_gadget_ep_cmd_string(u8 cmd)
+{
+	switch (cmd) {
+	case DWC3_DEPCMD_DEPSTARTCFG:
+		return "Start New Configuration";
+	case DWC3_DEPCMD_ENDTRANSFER:
+		return "End Transfer";
+	case DWC3_DEPCMD_UPDATETRANSFER:
+		return "Update Transfer";
+	case DWC3_DEPCMD_STARTTRANSFER:
+		return "Start Transfer";
+	case DWC3_DEPCMD_CLEARSTALL:
+		return "Clear Stall";
+	case DWC3_DEPCMD_SETSTALL:
+		return "Set Stall";
+	case DWC3_DEPCMD_GETEPSTATE:
+		return "Get Endpoint State";
+	case DWC3_DEPCMD_SETTRANSFRESOURCE:
+		return "Set Endpoint Transfer Resource";
+	case DWC3_DEPCMD_SETEPCONFIG:
+		return "Set Endpoint Configuration";
+	default:
+		return "UNKNOWN command";
+	}
+}
+
+/**
+ * dwc3_gadget_generic_cmd_string - returns generic command string
+ * @cmd: command code
+ */
+static inline const char *
+dwc3_gadget_generic_cmd_string(u8 cmd)
+{
+	switch (cmd) {
+	case DWC3_DGCMD_SET_LMP:
+		return "Set LMP";
+	case DWC3_DGCMD_SET_PERIODIC_PAR:
+		return "Set Periodic Parameters";
+	case DWC3_DGCMD_XMIT_FUNCTION:
+		return "Transmit Function Wake Device Notification";
+	case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
+		return "Set Scratchpad Buffer Array Address Lo";
+	case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
+		return "Set Scratchpad Buffer Array Address Hi";
+	case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
+		return "Selected FIFO Flush";
+	case DWC3_DGCMD_ALL_FIFO_FLUSH:
+		return "All FIFO Flush";
+	case DWC3_DGCMD_SET_ENDPOINT_NRDY:
+		return "Set Endpoint NRDY";
+	case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
+		return "Run SoC Bus Loopback Test";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+/**
+ * dwc3_gadget_link_string - returns link name
+ * @link_state: link state code
+ */
+static inline const char *
+dwc3_gadget_link_string(enum dwc3_link_state link_state)
+{
+	switch (link_state) {
+	case DWC3_LINK_STATE_U0:
+		return "U0";
+	case DWC3_LINK_STATE_U1:
+		return "U1";
+	case DWC3_LINK_STATE_U2:
+		return "U2";
+	case DWC3_LINK_STATE_U3:
+		return "U3";
+	case DWC3_LINK_STATE_SS_DIS:
+		return "SS.Disabled";
+	case DWC3_LINK_STATE_RX_DET:
+		return "RX.Detect";
+	case DWC3_LINK_STATE_SS_INACT:
+		return "SS.Inactive";
+	case DWC3_LINK_STATE_POLL:
+		return "Polling";
+	case DWC3_LINK_STATE_RECOV:
+		return "Recovery";
+	case DWC3_LINK_STATE_HRESET:
+		return "Hot Reset";
+	case DWC3_LINK_STATE_CMPLY:
+		return "Compliance";
+	case DWC3_LINK_STATE_LPBK:
+		return "Loopback";
+	case DWC3_LINK_STATE_RESET:
+		return "Reset";
+	case DWC3_LINK_STATE_RESUME:
+		return "Resume";
+	default:
+		return "UNKNOWN link state\n";
+	}
+}
+
+/**
+ * dwc3_gadget_event_string - returns event name
+ * @event: the event code
+ */
+static inline const char *dwc3_gadget_event_string(u8 event)
+{
+	switch (event) {
+	case DWC3_DEVICE_EVENT_DISCONNECT:
+		return "Disconnect";
+	case DWC3_DEVICE_EVENT_RESET:
+		return "Reset";
+	case DWC3_DEVICE_EVENT_CONNECT_DONE:
+		return "Connection Done";
+	case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
+		return "Link Status Change";
+	case DWC3_DEVICE_EVENT_WAKEUP:
+		return "WakeUp";
+	case DWC3_DEVICE_EVENT_EOPF:
+		return "End-Of-Frame";
+	case DWC3_DEVICE_EVENT_SOF:
+		return "Start-Of-Frame";
+	case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
+		return "Erratic Error";
+	case DWC3_DEVICE_EVENT_CMD_CMPL:
+		return "Command Complete";
+	case DWC3_DEVICE_EVENT_OVERFLOW:
+		return "Overflow";
+	}
+
+	return "UNKNOWN";
+}
+
+/**
+ * dwc3_ep_event_string - returns event name
+ * @event: then event code
+ */
+static inline const char *dwc3_ep_event_string(u8 event)
+{
+	switch (event) {
+	case DWC3_DEPEVT_XFERCOMPLETE:
+		return "Transfer Complete";
+	case DWC3_DEPEVT_XFERINPROGRESS:
+		return "Transfer In-Progress";
+	case DWC3_DEPEVT_XFERNOTREADY:
+		return "Transfer Not Ready";
+	case DWC3_DEPEVT_RXTXFIFOEVT:
+		return "FIFO";
+	case DWC3_DEPEVT_STREAMEVT:
+		return "Stream";
+	case DWC3_DEPEVT_EPCMDCMPLT:
+		return "Endpoint Command Complete";
+	}
+
+	return "UNKNOWN";
+}
+
+/**
+ * dwc3_gadget_event_type_string - return event name
+ * @event: the event code
+ */
+static inline const char *dwc3_gadget_event_type_string(u8 event)
+{
+	switch (event) {
+	case DWC3_DEVICE_EVENT_DISCONNECT:
+		return "Disconnect";
+	case DWC3_DEVICE_EVENT_RESET:
+		return "Reset";
+	case DWC3_DEVICE_EVENT_CONNECT_DONE:
+		return "Connect Done";
+	case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
+		return "Link Status Change";
+	case DWC3_DEVICE_EVENT_WAKEUP:
+		return "Wake-Up";
+	case DWC3_DEVICE_EVENT_HIBER_REQ:
+		return "Hibernation";
+	case DWC3_DEVICE_EVENT_EOPF:
+		return "End of Periodic Frame";
+	case DWC3_DEVICE_EVENT_SOF:
+		return "Start of Frame";
+	case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
+		return "Erratic Error";
+	case DWC3_DEVICE_EVENT_CMD_CMPL:
+		return "Command Complete";
+	case DWC3_DEVICE_EVENT_OVERFLOW:
+		return "Overflow";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
+
+#ifdef CONFIG_DEBUG_FS
+extern int dwc3_debugfs_init(struct dwc3 *);
+extern void dwc3_debugfs_exit(struct dwc3 *);
+#else
+static inline int dwc3_debugfs_init(struct dwc3 *d)
+{  return 0;  }
+static inline void dwc3_debugfs_exit(struct dwc3 *d)
+{  }
+#endif
+#endif /* __DWC3_DEBUG_H */
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
new file mode 100644
index 0000000..9ac37fe
--- /dev/null
+++ b/drivers/usb/dwc3/debugfs.c
@@ -0,0 +1,690 @@
+/**
+ * debugfs.c - DesignWare USB3 DRD Controller DebugFS file
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/ptrace.h>
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+#include <linux/delay.h>
+#include <linux/uaccess.h>
+
+#include <linux/usb/ch9.h>
+
+#include "core.h"
+#include "gadget.h"
+#include "io.h"
+#include "debug.h"
+
+#define dump_register(nm)				\
+{							\
+	.name	= __stringify(nm),			\
+	.offset	= DWC3_ ##nm - DWC3_GLOBALS_REGS_START,	\
+}
+
+static const struct debugfs_reg32 dwc3_regs[] = {
+	dump_register(GSBUSCFG0),
+	dump_register(GSBUSCFG1),
+	dump_register(GTXTHRCFG),
+	dump_register(GRXTHRCFG),
+	dump_register(GCTL),
+	dump_register(GEVTEN),
+	dump_register(GSTS),
+	dump_register(GSNPSID),
+	dump_register(GGPIO),
+	dump_register(GUID),
+	dump_register(GUCTL),
+	dump_register(GBUSERRADDR0),
+	dump_register(GBUSERRADDR1),
+	dump_register(GPRTBIMAP0),
+	dump_register(GPRTBIMAP1),
+	dump_register(GHWPARAMS0),
+	dump_register(GHWPARAMS1),
+	dump_register(GHWPARAMS2),
+	dump_register(GHWPARAMS3),
+	dump_register(GHWPARAMS4),
+	dump_register(GHWPARAMS5),
+	dump_register(GHWPARAMS6),
+	dump_register(GHWPARAMS7),
+	dump_register(GDBGFIFOSPACE),
+	dump_register(GDBGLTSSM),
+	dump_register(GPRTBIMAP_HS0),
+	dump_register(GPRTBIMAP_HS1),
+	dump_register(GPRTBIMAP_FS0),
+	dump_register(GPRTBIMAP_FS1),
+
+	dump_register(GUSB2PHYCFG(0)),
+	dump_register(GUSB2PHYCFG(1)),
+	dump_register(GUSB2PHYCFG(2)),
+	dump_register(GUSB2PHYCFG(3)),
+	dump_register(GUSB2PHYCFG(4)),
+	dump_register(GUSB2PHYCFG(5)),
+	dump_register(GUSB2PHYCFG(6)),
+	dump_register(GUSB2PHYCFG(7)),
+	dump_register(GUSB2PHYCFG(8)),
+	dump_register(GUSB2PHYCFG(9)),
+	dump_register(GUSB2PHYCFG(10)),
+	dump_register(GUSB2PHYCFG(11)),
+	dump_register(GUSB2PHYCFG(12)),
+	dump_register(GUSB2PHYCFG(13)),
+	dump_register(GUSB2PHYCFG(14)),
+	dump_register(GUSB2PHYCFG(15)),
+
+	dump_register(GUSB2I2CCTL(0)),
+	dump_register(GUSB2I2CCTL(1)),
+	dump_register(GUSB2I2CCTL(2)),
+	dump_register(GUSB2I2CCTL(3)),
+	dump_register(GUSB2I2CCTL(4)),
+	dump_register(GUSB2I2CCTL(5)),
+	dump_register(GUSB2I2CCTL(6)),
+	dump_register(GUSB2I2CCTL(7)),
+	dump_register(GUSB2I2CCTL(8)),
+	dump_register(GUSB2I2CCTL(9)),
+	dump_register(GUSB2I2CCTL(10)),
+	dump_register(GUSB2I2CCTL(11)),
+	dump_register(GUSB2I2CCTL(12)),
+	dump_register(GUSB2I2CCTL(13)),
+	dump_register(GUSB2I2CCTL(14)),
+	dump_register(GUSB2I2CCTL(15)),
+
+	dump_register(GUSB2PHYACC(0)),
+	dump_register(GUSB2PHYACC(1)),
+	dump_register(GUSB2PHYACC(2)),
+	dump_register(GUSB2PHYACC(3)),
+	dump_register(GUSB2PHYACC(4)),
+	dump_register(GUSB2PHYACC(5)),
+	dump_register(GUSB2PHYACC(6)),
+	dump_register(GUSB2PHYACC(7)),
+	dump_register(GUSB2PHYACC(8)),
+	dump_register(GUSB2PHYACC(9)),
+	dump_register(GUSB2PHYACC(10)),
+	dump_register(GUSB2PHYACC(11)),
+	dump_register(GUSB2PHYACC(12)),
+	dump_register(GUSB2PHYACC(13)),
+	dump_register(GUSB2PHYACC(14)),
+	dump_register(GUSB2PHYACC(15)),
+
+	dump_register(GUSB3PIPECTL(0)),
+	dump_register(GUSB3PIPECTL(1)),
+	dump_register(GUSB3PIPECTL(2)),
+	dump_register(GUSB3PIPECTL(3)),
+	dump_register(GUSB3PIPECTL(4)),
+	dump_register(GUSB3PIPECTL(5)),
+	dump_register(GUSB3PIPECTL(6)),
+	dump_register(GUSB3PIPECTL(7)),
+	dump_register(GUSB3PIPECTL(8)),
+	dump_register(GUSB3PIPECTL(9)),
+	dump_register(GUSB3PIPECTL(10)),
+	dump_register(GUSB3PIPECTL(11)),
+	dump_register(GUSB3PIPECTL(12)),
+	dump_register(GUSB3PIPECTL(13)),
+	dump_register(GUSB3PIPECTL(14)),
+	dump_register(GUSB3PIPECTL(15)),
+
+	dump_register(GTXFIFOSIZ(0)),
+	dump_register(GTXFIFOSIZ(1)),
+	dump_register(GTXFIFOSIZ(2)),
+	dump_register(GTXFIFOSIZ(3)),
+	dump_register(GTXFIFOSIZ(4)),
+	dump_register(GTXFIFOSIZ(5)),
+	dump_register(GTXFIFOSIZ(6)),
+	dump_register(GTXFIFOSIZ(7)),
+	dump_register(GTXFIFOSIZ(8)),
+	dump_register(GTXFIFOSIZ(9)),
+	dump_register(GTXFIFOSIZ(10)),
+	dump_register(GTXFIFOSIZ(11)),
+	dump_register(GTXFIFOSIZ(12)),
+	dump_register(GTXFIFOSIZ(13)),
+	dump_register(GTXFIFOSIZ(14)),
+	dump_register(GTXFIFOSIZ(15)),
+	dump_register(GTXFIFOSIZ(16)),
+	dump_register(GTXFIFOSIZ(17)),
+	dump_register(GTXFIFOSIZ(18)),
+	dump_register(GTXFIFOSIZ(19)),
+	dump_register(GTXFIFOSIZ(20)),
+	dump_register(GTXFIFOSIZ(21)),
+	dump_register(GTXFIFOSIZ(22)),
+	dump_register(GTXFIFOSIZ(23)),
+	dump_register(GTXFIFOSIZ(24)),
+	dump_register(GTXFIFOSIZ(25)),
+	dump_register(GTXFIFOSIZ(26)),
+	dump_register(GTXFIFOSIZ(27)),
+	dump_register(GTXFIFOSIZ(28)),
+	dump_register(GTXFIFOSIZ(29)),
+	dump_register(GTXFIFOSIZ(30)),
+	dump_register(GTXFIFOSIZ(31)),
+
+	dump_register(GRXFIFOSIZ(0)),
+	dump_register(GRXFIFOSIZ(1)),
+	dump_register(GRXFIFOSIZ(2)),
+	dump_register(GRXFIFOSIZ(3)),
+	dump_register(GRXFIFOSIZ(4)),
+	dump_register(GRXFIFOSIZ(5)),
+	dump_register(GRXFIFOSIZ(6)),
+	dump_register(GRXFIFOSIZ(7)),
+	dump_register(GRXFIFOSIZ(8)),
+	dump_register(GRXFIFOSIZ(9)),
+	dump_register(GRXFIFOSIZ(10)),
+	dump_register(GRXFIFOSIZ(11)),
+	dump_register(GRXFIFOSIZ(12)),
+	dump_register(GRXFIFOSIZ(13)),
+	dump_register(GRXFIFOSIZ(14)),
+	dump_register(GRXFIFOSIZ(15)),
+	dump_register(GRXFIFOSIZ(16)),
+	dump_register(GRXFIFOSIZ(17)),
+	dump_register(GRXFIFOSIZ(18)),
+	dump_register(GRXFIFOSIZ(19)),
+	dump_register(GRXFIFOSIZ(20)),
+	dump_register(GRXFIFOSIZ(21)),
+	dump_register(GRXFIFOSIZ(22)),
+	dump_register(GRXFIFOSIZ(23)),
+	dump_register(GRXFIFOSIZ(24)),
+	dump_register(GRXFIFOSIZ(25)),
+	dump_register(GRXFIFOSIZ(26)),
+	dump_register(GRXFIFOSIZ(27)),
+	dump_register(GRXFIFOSIZ(28)),
+	dump_register(GRXFIFOSIZ(29)),
+	dump_register(GRXFIFOSIZ(30)),
+	dump_register(GRXFIFOSIZ(31)),
+
+	dump_register(GEVNTADRLO(0)),
+	dump_register(GEVNTADRHI(0)),
+	dump_register(GEVNTSIZ(0)),
+	dump_register(GEVNTCOUNT(0)),
+
+	dump_register(GHWPARAMS8),
+	dump_register(DCFG),
+	dump_register(DCTL),
+	dump_register(DEVTEN),
+	dump_register(DSTS),
+	dump_register(DGCMDPAR),
+	dump_register(DGCMD),
+	dump_register(DALEPENA),
+
+	dump_register(DEPCMDPAR2(0)),
+	dump_register(DEPCMDPAR2(1)),
+	dump_register(DEPCMDPAR2(2)),
+	dump_register(DEPCMDPAR2(3)),
+	dump_register(DEPCMDPAR2(4)),
+	dump_register(DEPCMDPAR2(5)),
+	dump_register(DEPCMDPAR2(6)),
+	dump_register(DEPCMDPAR2(7)),
+	dump_register(DEPCMDPAR2(8)),
+	dump_register(DEPCMDPAR2(9)),
+	dump_register(DEPCMDPAR2(10)),
+	dump_register(DEPCMDPAR2(11)),
+	dump_register(DEPCMDPAR2(12)),
+	dump_register(DEPCMDPAR2(13)),
+	dump_register(DEPCMDPAR2(14)),
+	dump_register(DEPCMDPAR2(15)),
+	dump_register(DEPCMDPAR2(16)),
+	dump_register(DEPCMDPAR2(17)),
+	dump_register(DEPCMDPAR2(18)),
+	dump_register(DEPCMDPAR2(19)),
+	dump_register(DEPCMDPAR2(20)),
+	dump_register(DEPCMDPAR2(21)),
+	dump_register(DEPCMDPAR2(22)),
+	dump_register(DEPCMDPAR2(23)),
+	dump_register(DEPCMDPAR2(24)),
+	dump_register(DEPCMDPAR2(25)),
+	dump_register(DEPCMDPAR2(26)),
+	dump_register(DEPCMDPAR2(27)),
+	dump_register(DEPCMDPAR2(28)),
+	dump_register(DEPCMDPAR2(29)),
+	dump_register(DEPCMDPAR2(30)),
+	dump_register(DEPCMDPAR2(31)),
+
+	dump_register(DEPCMDPAR1(0)),
+	dump_register(DEPCMDPAR1(1)),
+	dump_register(DEPCMDPAR1(2)),
+	dump_register(DEPCMDPAR1(3)),
+	dump_register(DEPCMDPAR1(4)),
+	dump_register(DEPCMDPAR1(5)),
+	dump_register(DEPCMDPAR1(6)),
+	dump_register(DEPCMDPAR1(7)),
+	dump_register(DEPCMDPAR1(8)),
+	dump_register(DEPCMDPAR1(9)),
+	dump_register(DEPCMDPAR1(10)),
+	dump_register(DEPCMDPAR1(11)),
+	dump_register(DEPCMDPAR1(12)),
+	dump_register(DEPCMDPAR1(13)),
+	dump_register(DEPCMDPAR1(14)),
+	dump_register(DEPCMDPAR1(15)),
+	dump_register(DEPCMDPAR1(16)),
+	dump_register(DEPCMDPAR1(17)),
+	dump_register(DEPCMDPAR1(18)),
+	dump_register(DEPCMDPAR1(19)),
+	dump_register(DEPCMDPAR1(20)),
+	dump_register(DEPCMDPAR1(21)),
+	dump_register(DEPCMDPAR1(22)),
+	dump_register(DEPCMDPAR1(23)),
+	dump_register(DEPCMDPAR1(24)),
+	dump_register(DEPCMDPAR1(25)),
+	dump_register(DEPCMDPAR1(26)),
+	dump_register(DEPCMDPAR1(27)),
+	dump_register(DEPCMDPAR1(28)),
+	dump_register(DEPCMDPAR1(29)),
+	dump_register(DEPCMDPAR1(30)),
+	dump_register(DEPCMDPAR1(31)),
+
+	dump_register(DEPCMDPAR0(0)),
+	dump_register(DEPCMDPAR0(1)),
+	dump_register(DEPCMDPAR0(2)),
+	dump_register(DEPCMDPAR0(3)),
+	dump_register(DEPCMDPAR0(4)),
+	dump_register(DEPCMDPAR0(5)),
+	dump_register(DEPCMDPAR0(6)),
+	dump_register(DEPCMDPAR0(7)),
+	dump_register(DEPCMDPAR0(8)),
+	dump_register(DEPCMDPAR0(9)),
+	dump_register(DEPCMDPAR0(10)),
+	dump_register(DEPCMDPAR0(11)),
+	dump_register(DEPCMDPAR0(12)),
+	dump_register(DEPCMDPAR0(13)),
+	dump_register(DEPCMDPAR0(14)),
+	dump_register(DEPCMDPAR0(15)),
+	dump_register(DEPCMDPAR0(16)),
+	dump_register(DEPCMDPAR0(17)),
+	dump_register(DEPCMDPAR0(18)),
+	dump_register(DEPCMDPAR0(19)),
+	dump_register(DEPCMDPAR0(20)),
+	dump_register(DEPCMDPAR0(21)),
+	dump_register(DEPCMDPAR0(22)),
+	dump_register(DEPCMDPAR0(23)),
+	dump_register(DEPCMDPAR0(24)),
+	dump_register(DEPCMDPAR0(25)),
+	dump_register(DEPCMDPAR0(26)),
+	dump_register(DEPCMDPAR0(27)),
+	dump_register(DEPCMDPAR0(28)),
+	dump_register(DEPCMDPAR0(29)),
+	dump_register(DEPCMDPAR0(30)),
+	dump_register(DEPCMDPAR0(31)),
+
+	dump_register(DEPCMD(0)),
+	dump_register(DEPCMD(1)),
+	dump_register(DEPCMD(2)),
+	dump_register(DEPCMD(3)),
+	dump_register(DEPCMD(4)),
+	dump_register(DEPCMD(5)),
+	dump_register(DEPCMD(6)),
+	dump_register(DEPCMD(7)),
+	dump_register(DEPCMD(8)),
+	dump_register(DEPCMD(9)),
+	dump_register(DEPCMD(10)),
+	dump_register(DEPCMD(11)),
+	dump_register(DEPCMD(12)),
+	dump_register(DEPCMD(13)),
+	dump_register(DEPCMD(14)),
+	dump_register(DEPCMD(15)),
+	dump_register(DEPCMD(16)),
+	dump_register(DEPCMD(17)),
+	dump_register(DEPCMD(18)),
+	dump_register(DEPCMD(19)),
+	dump_register(DEPCMD(20)),
+	dump_register(DEPCMD(21)),
+	dump_register(DEPCMD(22)),
+	dump_register(DEPCMD(23)),
+	dump_register(DEPCMD(24)),
+	dump_register(DEPCMD(25)),
+	dump_register(DEPCMD(26)),
+	dump_register(DEPCMD(27)),
+	dump_register(DEPCMD(28)),
+	dump_register(DEPCMD(29)),
+	dump_register(DEPCMD(30)),
+	dump_register(DEPCMD(31)),
+
+	dump_register(OCFG),
+	dump_register(OCTL),
+	dump_register(OEVT),
+	dump_register(OEVTEN),
+	dump_register(OSTS),
+};
+
+static int dwc3_mode_show(struct seq_file *s, void *unused)
+{
+	struct dwc3		*dwc = s->private;
+	unsigned long		flags;
+	u32			reg;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	switch (DWC3_GCTL_PRTCAP(reg)) {
+	case DWC3_GCTL_PRTCAP_HOST:
+		seq_printf(s, "host\n");
+		break;
+	case DWC3_GCTL_PRTCAP_DEVICE:
+		seq_printf(s, "device\n");
+		break;
+	case DWC3_GCTL_PRTCAP_OTG:
+		seq_printf(s, "OTG\n");
+		break;
+	default:
+		seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
+	}
+
+	return 0;
+}
+
+static int dwc3_mode_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, dwc3_mode_show, inode->i_private);
+}
+
+static ssize_t dwc3_mode_write(struct file *file,
+		const char __user *ubuf, size_t count, loff_t *ppos)
+{
+	struct seq_file		*s = file->private_data;
+	struct dwc3		*dwc = s->private;
+	unsigned long		flags;
+	u32			mode = 0;
+	char			buf[32];
+
+	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+		return -EFAULT;
+
+	if (!strncmp(buf, "host", 4))
+		mode |= DWC3_GCTL_PRTCAP_HOST;
+
+	if (!strncmp(buf, "device", 6))
+		mode |= DWC3_GCTL_PRTCAP_DEVICE;
+
+	if (!strncmp(buf, "otg", 3))
+		mode |= DWC3_GCTL_PRTCAP_OTG;
+
+	if (mode) {
+		spin_lock_irqsave(&dwc->lock, flags);
+		dwc3_set_mode(dwc, mode);
+		spin_unlock_irqrestore(&dwc->lock, flags);
+	}
+	return count;
+}
+
+static const struct file_operations dwc3_mode_fops = {
+	.open			= dwc3_mode_open,
+	.write			= dwc3_mode_write,
+	.read			= seq_read,
+	.llseek			= seq_lseek,
+	.release		= single_release,
+};
+
+static int dwc3_testmode_show(struct seq_file *s, void *unused)
+{
+	struct dwc3		*dwc = s->private;
+	unsigned long		flags;
+	u32			reg;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+	reg &= DWC3_DCTL_TSTCTRL_MASK;
+	reg >>= 1;
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	switch (reg) {
+	case 0:
+		seq_printf(s, "no test\n");
+		break;
+	case TEST_J:
+		seq_printf(s, "test_j\n");
+		break;
+	case TEST_K:
+		seq_printf(s, "test_k\n");
+		break;
+	case TEST_SE0_NAK:
+		seq_printf(s, "test_se0_nak\n");
+		break;
+	case TEST_PACKET:
+		seq_printf(s, "test_packet\n");
+		break;
+	case TEST_FORCE_EN:
+		seq_printf(s, "test_force_enable\n");
+		break;
+	default:
+		seq_printf(s, "UNKNOWN %d\n", reg);
+	}
+
+	return 0;
+}
+
+static int dwc3_testmode_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, dwc3_testmode_show, inode->i_private);
+}
+
+static ssize_t dwc3_testmode_write(struct file *file,
+		const char __user *ubuf, size_t count, loff_t *ppos)
+{
+	struct seq_file		*s = file->private_data;
+	struct dwc3		*dwc = s->private;
+	unsigned long		flags;
+	u32			testmode = 0;
+	char			buf[32];
+
+	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+		return -EFAULT;
+
+	if (!strncmp(buf, "test_j", 6))
+		testmode = TEST_J;
+	else if (!strncmp(buf, "test_k", 6))
+		testmode = TEST_K;
+	else if (!strncmp(buf, "test_se0_nak", 12))
+		testmode = TEST_SE0_NAK;
+	else if (!strncmp(buf, "test_packet", 11))
+		testmode = TEST_PACKET;
+	else if (!strncmp(buf, "test_force_enable", 17))
+		testmode = TEST_FORCE_EN;
+	else
+		testmode = 0;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	dwc3_gadget_set_test_mode(dwc, testmode);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return count;
+}
+
+static const struct file_operations dwc3_testmode_fops = {
+	.open			= dwc3_testmode_open,
+	.write			= dwc3_testmode_write,
+	.read			= seq_read,
+	.llseek			= seq_lseek,
+	.release		= single_release,
+};
+
+static int dwc3_link_state_show(struct seq_file *s, void *unused)
+{
+	struct dwc3		*dwc = s->private;
+	unsigned long		flags;
+	enum dwc3_link_state	state;
+	u32			reg;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+	state = DWC3_DSTS_USBLNKST(reg);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	switch (state) {
+	case DWC3_LINK_STATE_U0:
+		seq_printf(s, "U0\n");
+		break;
+	case DWC3_LINK_STATE_U1:
+		seq_printf(s, "U1\n");
+		break;
+	case DWC3_LINK_STATE_U2:
+		seq_printf(s, "U2\n");
+		break;
+	case DWC3_LINK_STATE_U3:
+		seq_printf(s, "U3\n");
+		break;
+	case DWC3_LINK_STATE_SS_DIS:
+		seq_printf(s, "SS.Disabled\n");
+		break;
+	case DWC3_LINK_STATE_RX_DET:
+		seq_printf(s, "Rx.Detect\n");
+		break;
+	case DWC3_LINK_STATE_SS_INACT:
+		seq_printf(s, "SS.Inactive\n");
+		break;
+	case DWC3_LINK_STATE_POLL:
+		seq_printf(s, "Poll\n");
+		break;
+	case DWC3_LINK_STATE_RECOV:
+		seq_printf(s, "Recovery\n");
+		break;
+	case DWC3_LINK_STATE_HRESET:
+		seq_printf(s, "HRESET\n");
+		break;
+	case DWC3_LINK_STATE_CMPLY:
+		seq_printf(s, "Compliance\n");
+		break;
+	case DWC3_LINK_STATE_LPBK:
+		seq_printf(s, "Loopback\n");
+		break;
+	case DWC3_LINK_STATE_RESET:
+		seq_printf(s, "Reset\n");
+		break;
+	case DWC3_LINK_STATE_RESUME:
+		seq_printf(s, "Resume\n");
+		break;
+	default:
+		seq_printf(s, "UNKNOWN %d\n", state);
+	}
+
+	return 0;
+}
+
+static int dwc3_link_state_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, dwc3_link_state_show, inode->i_private);
+}
+
+static ssize_t dwc3_link_state_write(struct file *file,
+		const char __user *ubuf, size_t count, loff_t *ppos)
+{
+	struct seq_file		*s = file->private_data;
+	struct dwc3		*dwc = s->private;
+	unsigned long		flags;
+	enum dwc3_link_state	state = 0;
+	char			buf[32];
+
+	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+		return -EFAULT;
+
+	if (!strncmp(buf, "SS.Disabled", 11))
+		state = DWC3_LINK_STATE_SS_DIS;
+	else if (!strncmp(buf, "Rx.Detect", 9))
+		state = DWC3_LINK_STATE_RX_DET;
+	else if (!strncmp(buf, "SS.Inactive", 11))
+		state = DWC3_LINK_STATE_SS_INACT;
+	else if (!strncmp(buf, "Recovery", 8))
+		state = DWC3_LINK_STATE_RECOV;
+	else if (!strncmp(buf, "Compliance", 10))
+		state = DWC3_LINK_STATE_CMPLY;
+	else if (!strncmp(buf, "Loopback", 8))
+		state = DWC3_LINK_STATE_LPBK;
+	else
+		return -EINVAL;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	dwc3_gadget_set_link_state(dwc, state);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return count;
+}
+
+static const struct file_operations dwc3_link_state_fops = {
+	.open			= dwc3_link_state_open,
+	.write			= dwc3_link_state_write,
+	.read			= seq_read,
+	.llseek			= seq_lseek,
+	.release		= single_release,
+};
+
+int dwc3_debugfs_init(struct dwc3 *dwc)
+{
+	struct dentry		*root;
+	struct dentry		*file;
+	int			ret;
+
+	root = debugfs_create_dir(dev_name(dwc->dev), NULL);
+	if (!root) {
+		ret = -ENOMEM;
+		goto err0;
+	}
+
+	dwc->root = root;
+
+	dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
+	if (!dwc->regset) {
+		ret = -ENOMEM;
+		goto err1;
+	}
+
+	dwc->regset->regs = dwc3_regs;
+	dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
+	dwc->regset->base = dwc->regs;
+
+	file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
+	if (!file) {
+		ret = -ENOMEM;
+		goto err1;
+	}
+
+	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
+		file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
+				dwc, &dwc3_mode_fops);
+		if (!file) {
+			ret = -ENOMEM;
+			goto err1;
+		}
+	}
+
+	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
+			IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
+		file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
+				dwc, &dwc3_testmode_fops);
+		if (!file) {
+			ret = -ENOMEM;
+			goto err1;
+		}
+
+		file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
+				dwc, &dwc3_link_state_fops);
+		if (!file) {
+			ret = -ENOMEM;
+			goto err1;
+		}
+	}
+
+	return 0;
+
+err1:
+	debugfs_remove_recursive(root);
+
+err0:
+	return ret;
+}
+
+void dwc3_debugfs_exit(struct dwc3 *dwc)
+{
+	debugfs_remove_recursive(dwc->root);
+	dwc->root = NULL;
+}
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
new file mode 100644
index 0000000..7bd0a95
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -0,0 +1,301 @@
+/**
+ * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+ *		http://www.samsung.com
+ *
+ * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/clk.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/usb_phy_generic.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/regulator/consumer.h>
+
+struct dwc3_exynos {
+	struct platform_device	*usb2_phy;
+	struct platform_device	*usb3_phy;
+	struct device		*dev;
+
+	struct clk		*clk;
+	struct clk		*susp_clk;
+	struct clk		*axius_clk;
+
+	struct regulator	*vdd33;
+	struct regulator	*vdd10;
+};
+
+static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
+{
+	struct usb_phy_generic_platform_data pdata;
+	struct platform_device	*pdev;
+	int			ret;
+
+	memset(&pdata, 0x00, sizeof(pdata));
+
+	pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
+	if (!pdev)
+		return -ENOMEM;
+
+	exynos->usb2_phy = pdev;
+	pdata.type = USB_PHY_TYPE_USB2;
+	pdata.gpio_reset = -1;
+
+	ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
+	if (ret)
+		goto err1;
+
+	pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
+	if (!pdev) {
+		ret = -ENOMEM;
+		goto err1;
+	}
+
+	exynos->usb3_phy = pdev;
+	pdata.type = USB_PHY_TYPE_USB3;
+
+	ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
+	if (ret)
+		goto err2;
+
+	ret = platform_device_add(exynos->usb2_phy);
+	if (ret)
+		goto err2;
+
+	ret = platform_device_add(exynos->usb3_phy);
+	if (ret)
+		goto err3;
+
+	return 0;
+
+err3:
+	platform_device_del(exynos->usb2_phy);
+
+err2:
+	platform_device_put(exynos->usb3_phy);
+
+err1:
+	platform_device_put(exynos->usb2_phy);
+
+	return ret;
+}
+
+static int dwc3_exynos_remove_child(struct device *dev, void *unused)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	platform_device_unregister(pdev);
+
+	return 0;
+}
+
+static int dwc3_exynos_probe(struct platform_device *pdev)
+{
+	struct dwc3_exynos	*exynos;
+	struct device		*dev = &pdev->dev;
+	struct device_node	*node = dev->of_node;
+
+	int			ret;
+
+	exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
+	if (!exynos)
+		return -ENOMEM;
+
+	/*
+	 * Right now device-tree probed devices don't get dma_mask set.
+	 * Since shared usb code relies on it, set it here for now.
+	 * Once we move to full device tree support this will vanish off.
+	 */
+	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
+	if (ret)
+		return ret;
+
+	platform_set_drvdata(pdev, exynos);
+
+	ret = dwc3_exynos_register_phys(exynos);
+	if (ret) {
+		dev_err(dev, "couldn't register PHYs\n");
+		return ret;
+	}
+
+	exynos->dev	= dev;
+
+	exynos->clk = devm_clk_get(dev, "usbdrd30");
+	if (IS_ERR(exynos->clk)) {
+		dev_err(dev, "couldn't get clock\n");
+		return -EINVAL;
+	}
+	clk_prepare_enable(exynos->clk);
+
+	exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk");
+	if (IS_ERR(exynos->susp_clk)) {
+		dev_dbg(dev, "no suspend clk specified\n");
+		exynos->susp_clk = NULL;
+	}
+	clk_prepare_enable(exynos->susp_clk);
+
+	if (of_device_is_compatible(node, "samsung,exynos7-dwusb3")) {
+		exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk");
+		if (IS_ERR(exynos->axius_clk)) {
+			dev_err(dev, "no AXI UpScaler clk specified\n");
+			return -ENODEV;
+		}
+		clk_prepare_enable(exynos->axius_clk);
+	} else {
+		exynos->axius_clk = NULL;
+	}
+
+	exynos->vdd33 = devm_regulator_get(dev, "vdd33");
+	if (IS_ERR(exynos->vdd33)) {
+		ret = PTR_ERR(exynos->vdd33);
+		goto err2;
+	}
+	ret = regulator_enable(exynos->vdd33);
+	if (ret) {
+		dev_err(dev, "Failed to enable VDD33 supply\n");
+		goto err2;
+	}
+
+	exynos->vdd10 = devm_regulator_get(dev, "vdd10");
+	if (IS_ERR(exynos->vdd10)) {
+		ret = PTR_ERR(exynos->vdd10);
+		goto err3;
+	}
+	ret = regulator_enable(exynos->vdd10);
+	if (ret) {
+		dev_err(dev, "Failed to enable VDD10 supply\n");
+		goto err3;
+	}
+
+	if (node) {
+		ret = of_platform_populate(node, NULL, NULL, dev);
+		if (ret) {
+			dev_err(dev, "failed to add dwc3 core\n");
+			goto err4;
+		}
+	} else {
+		dev_err(dev, "no device node, failed to add dwc3 core\n");
+		ret = -ENODEV;
+		goto err4;
+	}
+
+	return 0;
+
+err4:
+	regulator_disable(exynos->vdd10);
+err3:
+	regulator_disable(exynos->vdd33);
+err2:
+	clk_disable_unprepare(exynos->axius_clk);
+	clk_disable_unprepare(exynos->susp_clk);
+	clk_disable_unprepare(exynos->clk);
+	return ret;
+}
+
+static int dwc3_exynos_remove(struct platform_device *pdev)
+{
+	struct dwc3_exynos	*exynos = platform_get_drvdata(pdev);
+
+	device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
+	platform_device_unregister(exynos->usb2_phy);
+	platform_device_unregister(exynos->usb3_phy);
+
+	clk_disable_unprepare(exynos->axius_clk);
+	clk_disable_unprepare(exynos->susp_clk);
+	clk_disable_unprepare(exynos->clk);
+
+	regulator_disable(exynos->vdd33);
+	regulator_disable(exynos->vdd10);
+
+	return 0;
+}
+
+static const struct of_device_id exynos_dwc3_match[] = {
+	{ .compatible = "samsung,exynos5250-dwusb3" },
+	{ .compatible = "samsung,exynos7-dwusb3" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
+
+#ifdef CONFIG_PM_SLEEP
+static int dwc3_exynos_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	clk_disable(exynos->axius_clk);
+	clk_disable(exynos->clk);
+
+	regulator_disable(exynos->vdd33);
+	regulator_disable(exynos->vdd10);
+
+	return 0;
+}
+
+static int dwc3_exynos_resume(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+	int ret;
+
+	ret = regulator_enable(exynos->vdd33);
+	if (ret) {
+		dev_err(dev, "Failed to enable VDD33 supply\n");
+		return ret;
+	}
+	ret = regulator_enable(exynos->vdd10);
+	if (ret) {
+		dev_err(dev, "Failed to enable VDD10 supply\n");
+		return ret;
+	}
+
+	clk_enable(exynos->clk);
+	clk_enable(exynos->axius_clk);
+
+	/* runtime set active to reflect active state. */
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	return 0;
+}
+
+static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
+};
+
+#define DEV_PM_OPS	(&dwc3_exynos_dev_pm_ops)
+#else
+#define DEV_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
+static struct platform_driver dwc3_exynos_driver = {
+	.probe		= dwc3_exynos_probe,
+	.remove		= dwc3_exynos_remove,
+	.driver		= {
+		.name	= "exynos-dwc3",
+		.of_match_table = exynos_dwc3_match,
+		.pm	= DEV_PM_OPS,
+	},
+};
+
+module_platform_driver(dwc3_exynos_driver);
+
+MODULE_ALIAS("platform:exynos-dwc3");
+MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
new file mode 100644
index 0000000..fe3b933
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -0,0 +1,197 @@
+/**
+ * dwc3-keystone.c - Keystone Specific Glue layer
+ *
+ * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author: WingMan Kwok <w-kwok2@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/of_platform.h>
+
+/* USBSS register offsets */
+#define USBSS_REVISION		0x0000
+#define USBSS_SYSCONFIG		0x0010
+#define USBSS_IRQ_EOI		0x0018
+#define USBSS_IRQSTATUS_RAW_0	0x0020
+#define USBSS_IRQSTATUS_0	0x0024
+#define USBSS_IRQENABLE_SET_0	0x0028
+#define USBSS_IRQENABLE_CLR_0	0x002c
+
+/* IRQ register bits */
+#define USBSS_IRQ_EOI_LINE(n)	BIT(n)
+#define USBSS_IRQ_EVENT_ST	BIT(0)
+#define USBSS_IRQ_COREIRQ_EN	BIT(0)
+#define USBSS_IRQ_COREIRQ_CLR	BIT(0)
+
+static u64 kdwc3_dma_mask;
+
+struct dwc3_keystone {
+	struct device			*dev;
+	struct clk			*clk;
+	void __iomem			*usbss;
+};
+
+static inline u32 kdwc3_readl(void __iomem *base, u32 offset)
+{
+	return readl(base + offset);
+}
+
+static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value)
+{
+	writel(value, base + offset);
+}
+
+static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc)
+{
+	u32 val;
+
+	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
+	val |= USBSS_IRQ_COREIRQ_EN;
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
+}
+
+static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc)
+{
+	u32 val;
+
+	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
+	val &= ~USBSS_IRQ_COREIRQ_EN;
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
+}
+
+static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
+{
+	struct dwc3_keystone	*kdwc = _kdwc;
+
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR);
+	kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST);
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN);
+	kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0));
+
+	return IRQ_HANDLED;
+}
+
+static int kdwc3_probe(struct platform_device *pdev)
+{
+	struct device		*dev = &pdev->dev;
+	struct device_node	*node = pdev->dev.of_node;
+	struct dwc3_keystone	*kdwc;
+	struct resource		*res;
+	int			error, irq;
+
+	kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL);
+	if (!kdwc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, kdwc);
+
+	kdwc->dev = dev;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	kdwc->usbss = devm_ioremap_resource(dev, res);
+	if (IS_ERR(kdwc->usbss))
+		return PTR_ERR(kdwc->usbss);
+
+	kdwc3_dma_mask = dma_get_mask(dev);
+	dev->dma_mask = &kdwc3_dma_mask;
+
+	kdwc->clk = devm_clk_get(kdwc->dev, "usb");
+
+	error = clk_prepare_enable(kdwc->clk);
+	if (error < 0) {
+		dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
+			error);
+		return error;
+	}
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "missing irq\n");
+		error = irq;
+		goto err_irq;
+	}
+
+	error = devm_request_irq(dev, irq, dwc3_keystone_interrupt, IRQF_SHARED,
+			dev_name(dev), kdwc);
+	if (error) {
+		dev_err(dev, "failed to request IRQ #%d --> %d\n",
+				irq, error);
+		goto err_irq;
+	}
+
+	kdwc3_enable_irqs(kdwc);
+
+	error = of_platform_populate(node, NULL, NULL, dev);
+	if (error) {
+		dev_err(&pdev->dev, "failed to create dwc3 core\n");
+		goto err_core;
+	}
+
+	return 0;
+
+err_core:
+	kdwc3_disable_irqs(kdwc);
+err_irq:
+	clk_disable_unprepare(kdwc->clk);
+
+	return error;
+}
+
+static int kdwc3_remove_core(struct device *dev, void *c)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	platform_device_unregister(pdev);
+
+	return 0;
+}
+
+static int kdwc3_remove(struct platform_device *pdev)
+{
+	struct dwc3_keystone *kdwc = platform_get_drvdata(pdev);
+
+	kdwc3_disable_irqs(kdwc);
+	device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
+	clk_disable_unprepare(kdwc->clk);
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static const struct of_device_id kdwc3_of_match[] = {
+	{ .compatible = "ti,keystone-dwc3", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, kdwc3_of_match);
+
+static struct platform_driver kdwc3_driver = {
+	.probe		= kdwc3_probe,
+	.remove		= kdwc3_remove,
+	.driver		= {
+		.name	= "keystone-dwc3",
+		.of_match_table	= kdwc3_of_match,
+	},
+};
+
+module_platform_driver(kdwc3_driver);
+
+MODULE_ALIAS("platform:keystone-dwc3");
+MODULE_AUTHOR("WingMan Kwok <w-kwok2@ti.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("DesignWare USB3 KEYSTONE Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
new file mode 100644
index 0000000..172d64e
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -0,0 +1,645 @@
+/**
+ * dwc3-omap.c - OMAP Specific Glue layer
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/platform_data/dwc3-omap.h>
+#include <linux/pm_runtime.h>
+#include <linux/dma-mapping.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/extcon.h>
+#include <linux/regulator/consumer.h>
+
+#include <linux/usb/otg.h>
+
+/*
+ * All these registers belong to OMAP's Wrapper around the
+ * DesignWare USB3 Core.
+ */
+
+#define USBOTGSS_REVISION			0x0000
+#define USBOTGSS_SYSCONFIG			0x0010
+#define USBOTGSS_IRQ_EOI			0x0020
+#define USBOTGSS_EOI_OFFSET			0x0008
+#define USBOTGSS_IRQSTATUS_RAW_0		0x0024
+#define USBOTGSS_IRQSTATUS_0			0x0028
+#define USBOTGSS_IRQENABLE_SET_0		0x002c
+#define USBOTGSS_IRQENABLE_CLR_0		0x0030
+#define USBOTGSS_IRQ0_OFFSET			0x0004
+#define USBOTGSS_IRQSTATUS_RAW_1		0x0030
+#define USBOTGSS_IRQSTATUS_1			0x0034
+#define USBOTGSS_IRQENABLE_SET_1		0x0038
+#define USBOTGSS_IRQENABLE_CLR_1		0x003c
+#define USBOTGSS_IRQSTATUS_RAW_2		0x0040
+#define USBOTGSS_IRQSTATUS_2			0x0044
+#define USBOTGSS_IRQENABLE_SET_2		0x0048
+#define USBOTGSS_IRQENABLE_CLR_2		0x004c
+#define USBOTGSS_IRQSTATUS_RAW_3		0x0050
+#define USBOTGSS_IRQSTATUS_3			0x0054
+#define USBOTGSS_IRQENABLE_SET_3		0x0058
+#define USBOTGSS_IRQENABLE_CLR_3		0x005c
+#define USBOTGSS_IRQSTATUS_EOI_MISC		0x0030
+#define USBOTGSS_IRQSTATUS_RAW_MISC		0x0034
+#define USBOTGSS_IRQSTATUS_MISC			0x0038
+#define USBOTGSS_IRQENABLE_SET_MISC		0x003c
+#define USBOTGSS_IRQENABLE_CLR_MISC		0x0040
+#define USBOTGSS_IRQMISC_OFFSET			0x03fc
+#define USBOTGSS_UTMI_OTG_CTRL			0x0080
+#define USBOTGSS_UTMI_OTG_STATUS		0x0084
+#define USBOTGSS_UTMI_OTG_OFFSET		0x0480
+#define USBOTGSS_TXFIFO_DEPTH			0x0508
+#define USBOTGSS_RXFIFO_DEPTH			0x050c
+#define USBOTGSS_MMRAM_OFFSET			0x0100
+#define USBOTGSS_FLADJ				0x0104
+#define USBOTGSS_DEBUG_CFG			0x0108
+#define USBOTGSS_DEBUG_DATA			0x010c
+#define USBOTGSS_DEV_EBC_EN			0x0110
+#define USBOTGSS_DEBUG_OFFSET			0x0600
+
+/* SYSCONFIG REGISTER */
+#define USBOTGSS_SYSCONFIG_DMADISABLE		(1 << 16)
+
+/* IRQ_EOI REGISTER */
+#define USBOTGSS_IRQ_EOI_LINE_NUMBER		(1 << 0)
+
+/* IRQS0 BITS */
+#define USBOTGSS_IRQO_COREIRQ_ST		(1 << 0)
+
+/* IRQMISC BITS */
+#define USBOTGSS_IRQMISC_DMADISABLECLR		(1 << 17)
+#define USBOTGSS_IRQMISC_OEVT			(1 << 16)
+#define USBOTGSS_IRQMISC_DRVVBUS_RISE		(1 << 13)
+#define USBOTGSS_IRQMISC_CHRGVBUS_RISE		(1 << 12)
+#define USBOTGSS_IRQMISC_DISCHRGVBUS_RISE	(1 << 11)
+#define USBOTGSS_IRQMISC_IDPULLUP_RISE		(1 << 8)
+#define USBOTGSS_IRQMISC_DRVVBUS_FALL		(1 << 5)
+#define USBOTGSS_IRQMISC_CHRGVBUS_FALL		(1 << 4)
+#define USBOTGSS_IRQMISC_DISCHRGVBUS_FALL		(1 << 3)
+#define USBOTGSS_IRQMISC_IDPULLUP_FALL		(1 << 0)
+
+/* UTMI_OTG_CTRL REGISTER */
+#define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS		(1 << 5)
+#define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS		(1 << 4)
+#define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS	(1 << 3)
+#define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP		(1 << 0)
+
+/* UTMI_OTG_STATUS REGISTER */
+#define USBOTGSS_UTMI_OTG_STATUS_SW_MODE	(1 << 31)
+#define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT	(1 << 9)
+#define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8)
+#define USBOTGSS_UTMI_OTG_STATUS_IDDIG		(1 << 4)
+#define USBOTGSS_UTMI_OTG_STATUS_SESSEND	(1 << 3)
+#define USBOTGSS_UTMI_OTG_STATUS_SESSVALID	(1 << 2)
+#define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID	(1 << 1)
+
+struct dwc3_omap {
+	struct device		*dev;
+
+	int			irq;
+	void __iomem		*base;
+
+	u32			utmi_otg_status;
+	u32			utmi_otg_offset;
+	u32			irqmisc_offset;
+	u32			irq_eoi_offset;
+	u32			debug_offset;
+	u32			irq0_offset;
+
+	u32			dma_status:1;
+
+	struct extcon_specific_cable_nb extcon_vbus_dev;
+	struct extcon_specific_cable_nb extcon_id_dev;
+	struct notifier_block	vbus_nb;
+	struct notifier_block	id_nb;
+
+	struct regulator	*vbus_reg;
+};
+
+enum omap_dwc3_vbus_id_status {
+	OMAP_DWC3_ID_FLOAT,
+	OMAP_DWC3_ID_GROUND,
+	OMAP_DWC3_VBUS_OFF,
+	OMAP_DWC3_VBUS_VALID,
+};
+
+static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
+{
+	return readl(base + offset);
+}
+
+static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
+{
+	writel(value, base + offset);
+}
+
+static u32 dwc3_omap_read_utmi_status(struct dwc3_omap *omap)
+{
+	return dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS +
+							omap->utmi_otg_offset);
+}
+
+static void dwc3_omap_write_utmi_status(struct dwc3_omap *omap, u32 value)
+{
+	dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS +
+					omap->utmi_otg_offset, value);
+
+}
+
+static u32 dwc3_omap_read_irq0_status(struct dwc3_omap *omap)
+{
+	return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0 -
+						omap->irq0_offset);
+}
+
+static void dwc3_omap_write_irq0_status(struct dwc3_omap *omap, u32 value)
+{
+	dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0 -
+						omap->irq0_offset, value);
+
+}
+
+static u32 dwc3_omap_read_irqmisc_status(struct dwc3_omap *omap)
+{
+	return dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_MISC +
+						omap->irqmisc_offset);
+}
+
+static void dwc3_omap_write_irqmisc_status(struct dwc3_omap *omap, u32 value)
+{
+	dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_MISC +
+					omap->irqmisc_offset, value);
+
+}
+
+static void dwc3_omap_write_irqmisc_set(struct dwc3_omap *omap, u32 value)
+{
+	dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_MISC +
+						omap->irqmisc_offset, value);
+
+}
+
+static void dwc3_omap_write_irq0_set(struct dwc3_omap *omap, u32 value)
+{
+	dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0 -
+						omap->irq0_offset, value);
+}
+
+static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
+	enum omap_dwc3_vbus_id_status status)
+{
+	int	ret;
+	u32	val;
+
+	switch (status) {
+	case OMAP_DWC3_ID_GROUND:
+		dev_dbg(omap->dev, "ID GND\n");
+
+		if (omap->vbus_reg) {
+			ret = regulator_enable(omap->vbus_reg);
+			if (ret) {
+				dev_dbg(omap->dev, "regulator enable failed\n");
+				return;
+			}
+		}
+
+		val = dwc3_omap_read_utmi_status(omap);
+		val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
+				| USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
+				| USBOTGSS_UTMI_OTG_STATUS_SESSEND);
+		val |= USBOTGSS_UTMI_OTG_STATUS_SESSVALID
+				| USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
+		dwc3_omap_write_utmi_status(omap, val);
+		break;
+
+	case OMAP_DWC3_VBUS_VALID:
+		dev_dbg(omap->dev, "VBUS Connect\n");
+
+		val = dwc3_omap_read_utmi_status(omap);
+		val &= ~USBOTGSS_UTMI_OTG_STATUS_SESSEND;
+		val |= USBOTGSS_UTMI_OTG_STATUS_IDDIG
+				| USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
+				| USBOTGSS_UTMI_OTG_STATUS_SESSVALID
+				| USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT;
+		dwc3_omap_write_utmi_status(omap, val);
+		break;
+
+	case OMAP_DWC3_ID_FLOAT:
+		if (omap->vbus_reg)
+			regulator_disable(omap->vbus_reg);
+
+	case OMAP_DWC3_VBUS_OFF:
+		dev_dbg(omap->dev, "VBUS Disconnect\n");
+
+		val = dwc3_omap_read_utmi_status(omap);
+		val &= ~(USBOTGSS_UTMI_OTG_STATUS_SESSVALID
+				| USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
+				| USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT);
+		val |= USBOTGSS_UTMI_OTG_STATUS_SESSEND
+				| USBOTGSS_UTMI_OTG_STATUS_IDDIG;
+		dwc3_omap_write_utmi_status(omap, val);
+		break;
+
+	default:
+		dev_dbg(omap->dev, "invalid state\n");
+	}
+}
+
+static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
+{
+	struct dwc3_omap	*omap = _omap;
+	u32			reg;
+
+	reg = dwc3_omap_read_irqmisc_status(omap);
+
+	if (reg & USBOTGSS_IRQMISC_DMADISABLECLR) {
+		dev_dbg(omap->dev, "DMA Disable was Cleared\n");
+		omap->dma_status = false;
+	}
+
+	if (reg & USBOTGSS_IRQMISC_OEVT)
+		dev_dbg(omap->dev, "OTG Event\n");
+
+	if (reg & USBOTGSS_IRQMISC_DRVVBUS_RISE)
+		dev_dbg(omap->dev, "DRVVBUS Rise\n");
+
+	if (reg & USBOTGSS_IRQMISC_CHRGVBUS_RISE)
+		dev_dbg(omap->dev, "CHRGVBUS Rise\n");
+
+	if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_RISE)
+		dev_dbg(omap->dev, "DISCHRGVBUS Rise\n");
+
+	if (reg & USBOTGSS_IRQMISC_IDPULLUP_RISE)
+		dev_dbg(omap->dev, "IDPULLUP Rise\n");
+
+	if (reg & USBOTGSS_IRQMISC_DRVVBUS_FALL)
+		dev_dbg(omap->dev, "DRVVBUS Fall\n");
+
+	if (reg & USBOTGSS_IRQMISC_CHRGVBUS_FALL)
+		dev_dbg(omap->dev, "CHRGVBUS Fall\n");
+
+	if (reg & USBOTGSS_IRQMISC_DISCHRGVBUS_FALL)
+		dev_dbg(omap->dev, "DISCHRGVBUS Fall\n");
+
+	if (reg & USBOTGSS_IRQMISC_IDPULLUP_FALL)
+		dev_dbg(omap->dev, "IDPULLUP Fall\n");
+
+	dwc3_omap_write_irqmisc_status(omap, reg);
+
+	reg = dwc3_omap_read_irq0_status(omap);
+
+	dwc3_omap_write_irq0_status(omap, reg);
+
+	return IRQ_HANDLED;
+}
+
+static int dwc3_omap_remove_core(struct device *dev, void *c)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	of_device_unregister(pdev);
+
+	return 0;
+}
+
+static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
+{
+	u32			reg;
+
+	/* enable all IRQs */
+	reg = USBOTGSS_IRQO_COREIRQ_ST;
+	dwc3_omap_write_irq0_set(omap, reg);
+
+	reg = (USBOTGSS_IRQMISC_OEVT |
+			USBOTGSS_IRQMISC_DRVVBUS_RISE |
+			USBOTGSS_IRQMISC_CHRGVBUS_RISE |
+			USBOTGSS_IRQMISC_DISCHRGVBUS_RISE |
+			USBOTGSS_IRQMISC_IDPULLUP_RISE |
+			USBOTGSS_IRQMISC_DRVVBUS_FALL |
+			USBOTGSS_IRQMISC_CHRGVBUS_FALL |
+			USBOTGSS_IRQMISC_DISCHRGVBUS_FALL |
+			USBOTGSS_IRQMISC_IDPULLUP_FALL);
+
+	dwc3_omap_write_irqmisc_set(omap, reg);
+}
+
+static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
+{
+	/* disable all IRQs */
+	dwc3_omap_write_irqmisc_set(omap, 0x00);
+	dwc3_omap_write_irq0_set(omap, 0x00);
+}
+
+static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
+
+static int dwc3_omap_id_notifier(struct notifier_block *nb,
+	unsigned long event, void *ptr)
+{
+	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb);
+
+	if (event)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
+	else
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
+
+	return NOTIFY_DONE;
+}
+
+static int dwc3_omap_vbus_notifier(struct notifier_block *nb,
+	unsigned long event, void *ptr)
+{
+	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb);
+
+	if (event)
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+	else
+		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
+
+	return NOTIFY_DONE;
+}
+
+static void dwc3_omap_map_offset(struct dwc3_omap *omap)
+{
+	struct device_node	*node = omap->dev->of_node;
+
+	/*
+	 * Differentiate between OMAP5 and AM437x.
+	 *
+	 * For OMAP5(ES2.0) and AM437x wrapper revision is same, even
+	 * though there are changes in wrapper register offsets.
+	 *
+	 * Using dt compatible to differentiate AM437x.
+	 */
+	if (of_device_is_compatible(node, "ti,am437x-dwc3")) {
+		omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
+		omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
+		omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
+		omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
+		omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
+	}
+}
+
+static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
+{
+	u32			reg;
+	struct device_node	*node = omap->dev->of_node;
+	int			utmi_mode = 0;
+
+	reg = dwc3_omap_read_utmi_status(omap);
+
+	of_property_read_u32(node, "utmi-mode", &utmi_mode);
+
+	switch (utmi_mode) {
+	case DWC3_OMAP_UTMI_MODE_SW:
+		reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
+		break;
+	case DWC3_OMAP_UTMI_MODE_HW:
+		reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
+		break;
+	default:
+		dev_dbg(omap->dev, "UNKNOWN utmi mode %d\n", utmi_mode);
+	}
+
+	dwc3_omap_write_utmi_status(omap, reg);
+}
+
+static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
+{
+	int			ret;
+	struct device_node	*node = omap->dev->of_node;
+	struct extcon_dev	*edev;
+
+	if (of_property_read_bool(node, "extcon")) {
+		edev = extcon_get_edev_by_phandle(omap->dev, 0);
+		if (IS_ERR(edev)) {
+			dev_vdbg(omap->dev, "couldn't get extcon device\n");
+			return -EPROBE_DEFER;
+		}
+
+		omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
+		ret = extcon_register_interest(&omap->extcon_vbus_dev,
+					       edev->name, "USB",
+					       &omap->vbus_nb);
+		if (ret < 0)
+			dev_vdbg(omap->dev, "failed to register notifier for USB\n");
+
+		omap->id_nb.notifier_call = dwc3_omap_id_notifier;
+		ret = extcon_register_interest(&omap->extcon_id_dev,
+					       edev->name, "USB-HOST",
+					       &omap->id_nb);
+		if (ret < 0)
+			dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n");
+
+		if (extcon_get_cable_state(edev, "USB") == true)
+			dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+		if (extcon_get_cable_state(edev, "USB-HOST") == true)
+			dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
+	}
+
+	return 0;
+}
+
+static int dwc3_omap_probe(struct platform_device *pdev)
+{
+	struct device_node	*node = pdev->dev.of_node;
+
+	struct dwc3_omap	*omap;
+	struct resource		*res;
+	struct device		*dev = &pdev->dev;
+	struct regulator	*vbus_reg = NULL;
+
+	int			ret;
+	int			irq;
+
+	u32			reg;
+
+	void __iomem		*base;
+
+	if (!node) {
+		dev_err(dev, "device node not found\n");
+		return -EINVAL;
+	}
+
+	omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
+	if (!omap)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, omap);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(dev, "missing IRQ resource\n");
+		return -EINVAL;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	if (of_property_read_bool(node, "vbus-supply")) {
+		vbus_reg = devm_regulator_get(dev, "vbus");
+		if (IS_ERR(vbus_reg)) {
+			dev_err(dev, "vbus init failed\n");
+			return PTR_ERR(vbus_reg);
+		}
+	}
+
+	omap->dev	= dev;
+	omap->irq	= irq;
+	omap->base	= base;
+	omap->vbus_reg	= vbus_reg;
+	dev->dma_mask	= &dwc3_omap_dma_mask;
+
+	pm_runtime_enable(dev);
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0) {
+		dev_err(dev, "get_sync failed with err %d\n", ret);
+		goto err0;
+	}
+
+	dwc3_omap_map_offset(omap);
+	dwc3_omap_set_utmi_mode(omap);
+
+	/* check the DMA Status */
+	reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
+	omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
+
+	ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0,
+			"dwc3-omap", omap);
+	if (ret) {
+		dev_err(dev, "failed to request IRQ #%d --> %d\n",
+				omap->irq, ret);
+		goto err1;
+	}
+
+	dwc3_omap_enable_irqs(omap);
+
+	ret = dwc3_omap_extcon_register(omap);
+	if (ret < 0)
+		goto err2;
+
+	ret = of_platform_populate(node, NULL, NULL, dev);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to create dwc3 core\n");
+		goto err3;
+	}
+
+	return 0;
+
+err3:
+	if (omap->extcon_vbus_dev.edev)
+		extcon_unregister_interest(&omap->extcon_vbus_dev);
+	if (omap->extcon_id_dev.edev)
+		extcon_unregister_interest(&omap->extcon_id_dev);
+
+err2:
+	dwc3_omap_disable_irqs(omap);
+
+err1:
+	pm_runtime_put_sync(dev);
+
+err0:
+	pm_runtime_disable(dev);
+
+	return ret;
+}
+
+static int dwc3_omap_remove(struct platform_device *pdev)
+{
+	struct dwc3_omap	*omap = platform_get_drvdata(pdev);
+
+	if (omap->extcon_vbus_dev.edev)
+		extcon_unregister_interest(&omap->extcon_vbus_dev);
+	if (omap->extcon_id_dev.edev)
+		extcon_unregister_interest(&omap->extcon_id_dev);
+	dwc3_omap_disable_irqs(omap);
+	device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+
+	return 0;
+}
+
+static const struct of_device_id of_dwc3_match[] = {
+	{
+		.compatible =	"ti,dwc3"
+	},
+	{
+		.compatible =	"ti,am437x-dwc3"
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, of_dwc3_match);
+
+#ifdef CONFIG_PM_SLEEP
+static int dwc3_omap_suspend(struct device *dev)
+{
+	struct dwc3_omap	*omap = dev_get_drvdata(dev);
+
+	omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap);
+	dwc3_omap_disable_irqs(omap);
+
+	return 0;
+}
+
+static int dwc3_omap_resume(struct device *dev)
+{
+	struct dwc3_omap	*omap = dev_get_drvdata(dev);
+
+	dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status);
+	dwc3_omap_enable_irqs(omap);
+
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	return 0;
+}
+
+static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
+
+	SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
+};
+
+#define DEV_PM_OPS	(&dwc3_omap_dev_pm_ops)
+#else
+#define DEV_PM_OPS	NULL
+#endif /* CONFIG_PM_SLEEP */
+
+static struct platform_driver dwc3_omap_driver = {
+	.probe		= dwc3_omap_probe,
+	.remove		= dwc3_omap_remove,
+	.driver		= {
+		.name	= "omap-dwc3",
+		.of_match_table	= of_dwc3_match,
+		.pm	= DEV_PM_OPS,
+	},
+};
+
+module_platform_driver(dwc3_omap_driver);
+
+MODULE_ALIAS("platform:omap-dwc3");
+MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
new file mode 100644
index 0000000..7c4faf7
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -0,0 +1,272 @@
+/**
+ * dwc3-pci.c - PCI Specific glue layer
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+
+#include <linux/usb/otg.h>
+#include <linux/usb/usb_phy_generic.h>
+
+#include "platform_data.h"
+
+/* FIXME define these in <linux/pci_ids.h> */
+#define PCI_VENDOR_ID_SYNOPSYS		0x16c3
+#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3	0xabcd
+#define PCI_DEVICE_ID_INTEL_BYT		0x0f37
+#define PCI_DEVICE_ID_INTEL_MRFLD	0x119e
+#define PCI_DEVICE_ID_INTEL_BSW		0x22B7
+
+struct dwc3_pci {
+	struct device		*dev;
+	struct platform_device	*dwc3;
+	struct platform_device	*usb2_phy;
+	struct platform_device	*usb3_phy;
+};
+
+static int dwc3_pci_register_phys(struct dwc3_pci *glue)
+{
+	struct usb_phy_generic_platform_data pdata;
+	struct platform_device	*pdev;
+	int			ret;
+
+	memset(&pdata, 0x00, sizeof(pdata));
+
+	pdev = platform_device_alloc("usb_phy_generic", 0);
+	if (!pdev)
+		return -ENOMEM;
+
+	glue->usb2_phy = pdev;
+	pdata.type = USB_PHY_TYPE_USB2;
+	pdata.gpio_reset = -1;
+
+	ret = platform_device_add_data(glue->usb2_phy, &pdata, sizeof(pdata));
+	if (ret)
+		goto err1;
+
+	pdev = platform_device_alloc("usb_phy_generic", 1);
+	if (!pdev) {
+		ret = -ENOMEM;
+		goto err1;
+	}
+
+	glue->usb3_phy = pdev;
+	pdata.type = USB_PHY_TYPE_USB3;
+
+	ret = platform_device_add_data(glue->usb3_phy, &pdata, sizeof(pdata));
+	if (ret)
+		goto err2;
+
+	ret = platform_device_add(glue->usb2_phy);
+	if (ret)
+		goto err2;
+
+	ret = platform_device_add(glue->usb3_phy);
+	if (ret)
+		goto err3;
+
+	return 0;
+
+err3:
+	platform_device_del(glue->usb2_phy);
+
+err2:
+	platform_device_put(glue->usb3_phy);
+
+err1:
+	platform_device_put(glue->usb2_phy);
+
+	return ret;
+}
+
+static int dwc3_pci_probe(struct pci_dev *pci,
+		const struct pci_device_id *id)
+{
+	struct resource		res[2];
+	struct platform_device	*dwc3;
+	struct dwc3_pci		*glue;
+	int			ret;
+	struct device		*dev = &pci->dev;
+	struct dwc3_platform_data dwc3_pdata;
+
+	memset(&dwc3_pdata, 0x00, sizeof(dwc3_pdata));
+
+	glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
+	if (!glue)
+		return -ENOMEM;
+
+	glue->dev = dev;
+
+	ret = pcim_enable_device(pci);
+	if (ret) {
+		dev_err(dev, "failed to enable pci device\n");
+		return -ENODEV;
+	}
+
+	pci_set_master(pci);
+
+	ret = dwc3_pci_register_phys(glue);
+	if (ret) {
+		dev_err(dev, "couldn't register PHYs\n");
+		return ret;
+	}
+
+	dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
+	if (!dwc3) {
+		dev_err(dev, "couldn't allocate dwc3 device\n");
+		return -ENOMEM;
+	}
+
+	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
+
+	res[0].start	= pci_resource_start(pci, 0);
+	res[0].end	= pci_resource_end(pci, 0);
+	res[0].name	= "dwc_usb3";
+	res[0].flags	= IORESOURCE_MEM;
+
+	res[1].start	= pci->irq;
+	res[1].name	= "dwc_usb3";
+	res[1].flags	= IORESOURCE_IRQ;
+
+	if (pci->vendor == PCI_VENDOR_ID_AMD &&
+			pci->device == PCI_DEVICE_ID_AMD_NL_USB) {
+		dwc3_pdata.has_lpm_erratum = true;
+		dwc3_pdata.lpm_nyet_threshold = 0xf;
+
+		dwc3_pdata.u2exit_lfps_quirk = true;
+		dwc3_pdata.u2ss_inp3_quirk = true;
+		dwc3_pdata.req_p1p2p3_quirk = true;
+		dwc3_pdata.del_p1p2p3_quirk = true;
+		dwc3_pdata.del_phy_power_chg_quirk = true;
+		dwc3_pdata.lfps_filter_quirk = true;
+		dwc3_pdata.rx_detect_poll_quirk = true;
+
+		dwc3_pdata.tx_de_emphasis_quirk = true;
+		dwc3_pdata.tx_de_emphasis = 1;
+
+		/*
+		 * FIXME these quirks should be removed when AMD NL
+		 * taps out
+		 */
+		dwc3_pdata.disable_scramble_quirk = true;
+		dwc3_pdata.dis_u3_susphy_quirk = true;
+		dwc3_pdata.dis_u2_susphy_quirk = true;
+	}
+
+	ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
+	if (ret) {
+		dev_err(dev, "couldn't add resources to dwc3 device\n");
+		return ret;
+	}
+
+	pci_set_drvdata(pci, glue);
+
+	ret = platform_device_add_data(dwc3, &dwc3_pdata, sizeof(dwc3_pdata));
+	if (ret)
+		goto err3;
+
+	dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
+
+	dwc3->dev.dma_mask = dev->dma_mask;
+	dwc3->dev.dma_parms = dev->dma_parms;
+	dwc3->dev.parent = dev;
+	glue->dwc3 = dwc3;
+
+	ret = platform_device_add(dwc3);
+	if (ret) {
+		dev_err(dev, "failed to register dwc3 device\n");
+		goto err3;
+	}
+
+	return 0;
+
+err3:
+	platform_device_put(dwc3);
+	return ret;
+}
+
+static void dwc3_pci_remove(struct pci_dev *pci)
+{
+	struct dwc3_pci	*glue = pci_get_drvdata(pci);
+
+	platform_device_unregister(glue->dwc3);
+	platform_device_unregister(glue->usb2_phy);
+	platform_device_unregister(glue->usb3_phy);
+}
+
+static const struct pci_device_id dwc3_pci_id_table[] = {
+	{
+		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
+				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
+	},
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
+	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
+	{  }	/* Terminating Entry */
+};
+MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
+
+#ifdef CONFIG_PM_SLEEP
+static int dwc3_pci_suspend(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+
+	pci_disable_device(pci);
+
+	return 0;
+}
+
+static int dwc3_pci_resume(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+	int		ret;
+
+	ret = pci_enable_device(pci);
+	if (ret) {
+		dev_err(dev, "can't re-enable device --> %d\n", ret);
+		return ret;
+	}
+
+	pci_set_master(pci);
+
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
+};
+
+static struct pci_driver dwc3_pci_driver = {
+	.name		= "dwc3-pci",
+	.id_table	= dwc3_pci_id_table,
+	.probe		= dwc3_pci_probe,
+	.remove		= dwc3_pci_remove,
+	.driver		= {
+		.pm	= &dwc3_pci_dev_pm_ops,
+	},
+};
+
+MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
+
+module_pci_driver(dwc3_pci_driver);
diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
new file mode 100644
index 0000000..8c2e8ee
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -0,0 +1,130 @@
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+
+struct dwc3_qcom {
+	struct device		*dev;
+
+	struct clk		*core_clk;
+	struct clk		*iface_clk;
+	struct clk		*sleep_clk;
+};
+
+static int dwc3_qcom_probe(struct platform_device *pdev)
+{
+	struct device_node *node = pdev->dev.of_node;
+	struct dwc3_qcom *qdwc;
+	int ret;
+
+	qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
+	if (!qdwc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, qdwc);
+
+	qdwc->dev = &pdev->dev;
+
+	qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
+	if (IS_ERR(qdwc->core_clk)) {
+		dev_err(qdwc->dev, "failed to get core clock\n");
+		return PTR_ERR(qdwc->core_clk);
+	}
+
+	qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
+	if (IS_ERR(qdwc->iface_clk)) {
+		dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
+		qdwc->iface_clk = NULL;
+	}
+
+	qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
+	if (IS_ERR(qdwc->sleep_clk)) {
+		dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");
+		qdwc->sleep_clk = NULL;
+	}
+
+	ret = clk_prepare_enable(qdwc->core_clk);
+	if (ret) {
+		dev_err(qdwc->dev, "failed to enable core clock\n");
+		goto err_core;
+	}
+
+	ret = clk_prepare_enable(qdwc->iface_clk);
+	if (ret) {
+		dev_err(qdwc->dev, "failed to enable optional iface clock\n");
+		goto err_iface;
+	}
+
+	ret = clk_prepare_enable(qdwc->sleep_clk);
+	if (ret) {
+		dev_err(qdwc->dev, "failed to enable optional sleep clock\n");
+		goto err_sleep;
+	}
+
+	ret = of_platform_populate(node, NULL, NULL, qdwc->dev);
+	if (ret) {
+		dev_err(qdwc->dev, "failed to register core - %d\n", ret);
+		goto err_clks;
+	}
+
+	return 0;
+
+err_clks:
+	clk_disable_unprepare(qdwc->sleep_clk);
+err_sleep:
+	clk_disable_unprepare(qdwc->iface_clk);
+err_iface:
+	clk_disable_unprepare(qdwc->core_clk);
+err_core:
+	return ret;
+}
+
+static int dwc3_qcom_remove(struct platform_device *pdev)
+{
+	struct dwc3_qcom *qdwc = platform_get_drvdata(pdev);
+
+	of_platform_depopulate(&pdev->dev);
+
+	clk_disable_unprepare(qdwc->sleep_clk);
+	clk_disable_unprepare(qdwc->iface_clk);
+	clk_disable_unprepare(qdwc->core_clk);
+
+	return 0;
+}
+
+static const struct of_device_id of_dwc3_match[] = {
+	{ .compatible = "qcom,dwc3" },
+	{ /* Sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, of_dwc3_match);
+
+static struct platform_driver dwc3_qcom_driver = {
+	.probe		= dwc3_qcom_probe,
+	.remove		= dwc3_qcom_remove,
+	.driver		= {
+		.name	= "qcom-dwc3",
+		.of_match_table	= of_dwc3_match,
+	},
+};
+
+module_platform_driver(dwc3_qcom_driver);
+
+MODULE_ALIAS("platform:qcom-dwc3");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer");
+MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
new file mode 100644
index 0000000..4a1a543
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-st.c
@@ -0,0 +1,367 @@
+/**
+ * dwc3-st.c Support for dwc3 platform devices on ST Microelectronics platforms
+ *
+ * This is a small driver for the dwc3 to provide the glue logic
+ * to configure the controller. Tested on STi platforms.
+ *
+ * Copyright (C) 2014 Stmicroelectronics
+ *
+ * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
+ * Contributors: Aymen Bouattay <aymen.bouattay@st.com>
+ *               Peter Griffin <peter.griffin@linaro.org>
+ *
+ * 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.
+ *
+ * Inspired by dwc3-omap.c and dwc3-exynos.c.
+ */
+
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/usb/of.h>
+
+#include "core.h"
+#include "io.h"
+
+/* glue registers */
+#define CLKRST_CTRL		0x00
+#define AUX_CLK_EN		BIT(0)
+#define SW_PIPEW_RESET_N	BIT(4)
+#define EXT_CFG_RESET_N		BIT(8)
+/*
+ * 1'b0 : The host controller complies with the xHCI revision 0.96
+ * 1'b1 : The host controller complies with the xHCI revision 1.0
+ */
+#define XHCI_REVISION		BIT(12)
+
+#define USB2_VBUS_MNGMNT_SEL1	0x2C
+/*
+ * For all fields in USB2_VBUS_MNGMNT_SEL1
+ * 2?b00 : Override value from Reg 0x30 is selected
+ * 2?b01 : utmiotg_<signal_name> from usb3_top is selected
+ * 2?b10 : pipew_<signal_name> from PIPEW instance is selected
+ * 2?b11 : value is 1'b0
+ */
+#define USB2_VBUS_REG30		0x0
+#define USB2_VBUS_UTMIOTG	0x1
+#define USB2_VBUS_PIPEW		0x2
+#define USB2_VBUS_ZERO		0x3
+
+#define SEL_OVERRIDE_VBUSVALID(n)	(n << 0)
+#define SEL_OVERRIDE_POWERPRESENT(n)	(n << 4)
+#define SEL_OVERRIDE_BVALID(n)		(n << 8)
+
+/* Static DRD configuration */
+#define USB3_CONTROL_MASK		0xf77
+
+#define USB3_DEVICE_NOT_HOST		BIT(0)
+#define USB3_FORCE_VBUSVALID		BIT(1)
+#define USB3_DELAY_VBUSVALID		BIT(2)
+#define USB3_SEL_FORCE_OPMODE		BIT(4)
+#define USB3_FORCE_OPMODE(n)		(n << 5)
+#define USB3_SEL_FORCE_DPPULLDOWN2	BIT(8)
+#define USB3_FORCE_DPPULLDOWN2		BIT(9)
+#define USB3_SEL_FORCE_DMPULLDOWN2	BIT(10)
+#define USB3_FORCE_DMPULLDOWN2		BIT(11)
+
+/**
+ * struct st_dwc3 - dwc3-st driver private structure
+ * @dev:		device pointer
+ * @glue_base:		ioaddr for the glue registers
+ * @regmap:		regmap pointer for getting syscfg
+ * @syscfg_reg_off:	usb syscfg control offset
+ * @dr_mode:		drd static host/device config
+ * @rstc_pwrdn:		rest controller for powerdown signal
+ * @rstc_rst:		reset controller for softreset signal
+ */
+
+struct st_dwc3 {
+	struct device *dev;
+	void __iomem *glue_base;
+	struct regmap *regmap;
+	int syscfg_reg_off;
+	enum usb_dr_mode dr_mode;
+	struct reset_control *rstc_pwrdn;
+	struct reset_control *rstc_rst;
+};
+
+static inline u32 st_dwc3_readl(void __iomem *base, u32 offset)
+{
+	return readl_relaxed(base + offset);
+}
+
+static inline void st_dwc3_writel(void __iomem *base, u32 offset, u32 value)
+{
+	writel_relaxed(value, base + offset);
+}
+
+/**
+ * st_dwc3_drd_init: program the port
+ * @dwc3_data: driver private structure
+ * Description: this function is to program the port as either host or device
+ * according to the static configuration passed from devicetree.
+ * OTG and dual role are not yet supported!
+ */
+static int st_dwc3_drd_init(struct st_dwc3 *dwc3_data)
+{
+	u32 val;
+	int err;
+
+	err = regmap_read(dwc3_data->regmap, dwc3_data->syscfg_reg_off, &val);
+	if (err)
+		return err;
+
+	val &= USB3_CONTROL_MASK;
+
+	switch (dwc3_data->dr_mode) {
+	case USB_DR_MODE_PERIPHERAL:
+
+		val &= ~(USB3_FORCE_VBUSVALID | USB3_DELAY_VBUSVALID
+			| USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3)
+			| USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
+			| USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
+
+		val |= USB3_DEVICE_NOT_HOST;
+
+		dev_dbg(dwc3_data->dev, "Configuring as Device\n");
+		break;
+
+	case USB_DR_MODE_HOST:
+
+		val &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID
+			| USB3_SEL_FORCE_OPMODE	| USB3_FORCE_OPMODE(0x3)
+			| USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
+			| USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
+
+		/*
+		 * USB3_DELAY_VBUSVALID is ANDed with USB_C_VBUSVALID. Thus,
+		 * when set to ?0?, it can delay the arrival of VBUSVALID
+		 * information to VBUSVLDEXT2 input of the pico PHY.
+		 * We don't want to do that so we set the bit to '1'.
+		 */
+
+		val |= USB3_DELAY_VBUSVALID;
+
+		dev_dbg(dwc3_data->dev, "Configuring as Host\n");
+		break;
+
+	default:
+		dev_err(dwc3_data->dev, "Unsupported mode of operation %d\n",
+			dwc3_data->dr_mode);
+		return -EINVAL;
+	}
+
+	return regmap_write(dwc3_data->regmap, dwc3_data->syscfg_reg_off, val);
+}
+
+/**
+ * st_dwc3_init: init the controller via glue logic
+ * @dwc3_data: driver private structure
+ */
+static void st_dwc3_init(struct st_dwc3 *dwc3_data)
+{
+	u32 reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
+
+	reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION;
+	reg &= ~SW_PIPEW_RESET_N;
+	st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
+
+	/* configure mux for vbus, powerpresent and bvalid signals */
+	reg = st_dwc3_readl(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1);
+
+	reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) |
+		SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) |
+		SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG);
+
+	st_dwc3_writel(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1, reg);
+
+	reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
+	reg |= SW_PIPEW_RESET_N;
+	st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
+}
+
+static int st_dwc3_probe(struct platform_device *pdev)
+{
+	struct st_dwc3 *dwc3_data;
+	struct resource *res;
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node, *child;
+	struct regmap *regmap;
+	int ret;
+
+	dwc3_data = devm_kzalloc(dev, sizeof(*dwc3_data), GFP_KERNEL);
+	if (!dwc3_data)
+		return -ENOMEM;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "reg-glue");
+	dwc3_data->glue_base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(dwc3_data->glue_base))
+		return PTR_ERR(dwc3_data->glue_base);
+
+	regmap = syscon_regmap_lookup_by_phandle(node, "st,syscfg");
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	dma_set_coherent_mask(dev, dev->coherent_dma_mask);
+	dwc3_data->dev = dev;
+	dwc3_data->regmap = regmap;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg");
+	if (!res) {
+		ret = -ENXIO;
+		goto undo_platform_dev_alloc;
+	}
+
+	dwc3_data->syscfg_reg_off = res->start;
+
+	dev_vdbg(&pdev->dev, "glue-logic addr 0x%p, syscfg-reg offset 0x%x\n",
+		 dwc3_data->glue_base, dwc3_data->syscfg_reg_off);
+
+	dwc3_data->rstc_pwrdn = devm_reset_control_get(dev, "powerdown");
+	if (IS_ERR(dwc3_data->rstc_pwrdn)) {
+		dev_err(&pdev->dev, "could not get power controller\n");
+		ret = PTR_ERR(dwc3_data->rstc_pwrdn);
+		goto undo_platform_dev_alloc;
+	}
+
+	/* Manage PowerDown */
+	reset_control_deassert(dwc3_data->rstc_pwrdn);
+
+	dwc3_data->rstc_rst = devm_reset_control_get(dev, "softreset");
+	if (IS_ERR(dwc3_data->rstc_rst)) {
+		dev_err(&pdev->dev, "could not get reset controller\n");
+		ret = PTR_ERR(dwc3_data->rstc_rst);
+		goto undo_powerdown;
+	}
+
+	/* Manage SoftReset */
+	reset_control_deassert(dwc3_data->rstc_rst);
+
+	child = of_get_child_by_name(node, "dwc3");
+	if (!child) {
+		dev_err(&pdev->dev, "failed to find dwc3 core node\n");
+		ret = -ENODEV;
+		goto undo_softreset;
+	}
+
+	dwc3_data->dr_mode = of_usb_get_dr_mode(child);
+
+	/* Allocate and initialize the core */
+	ret = of_platform_populate(node, NULL, NULL, dev);
+	if (ret) {
+		dev_err(dev, "failed to add dwc3 core\n");
+		goto undo_softreset;
+	}
+
+	/*
+	 * Configure the USB port as device or host according to the static
+	 * configuration passed from DT.
+	 * DRD is the only mode currently supported so this will be enhanced
+	 * as soon as OTG is available.
+	 */
+	ret = st_dwc3_drd_init(dwc3_data);
+	if (ret) {
+		dev_err(dev, "drd initialisation failed\n");
+		goto undo_softreset;
+	}
+
+	/* ST glue logic init */
+	st_dwc3_init(dwc3_data);
+
+	platform_set_drvdata(pdev, dwc3_data);
+	return 0;
+
+undo_softreset:
+	reset_control_assert(dwc3_data->rstc_rst);
+undo_powerdown:
+	reset_control_assert(dwc3_data->rstc_pwrdn);
+undo_platform_dev_alloc:
+	platform_device_put(pdev);
+	return ret;
+}
+
+static int st_dwc3_remove(struct platform_device *pdev)
+{
+	struct st_dwc3 *dwc3_data = platform_get_drvdata(pdev);
+
+	of_platform_depopulate(&pdev->dev);
+
+	reset_control_assert(dwc3_data->rstc_pwrdn);
+	reset_control_assert(dwc3_data->rstc_rst);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int st_dwc3_suspend(struct device *dev)
+{
+	struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
+
+	reset_control_assert(dwc3_data->rstc_pwrdn);
+	reset_control_assert(dwc3_data->rstc_rst);
+
+	pinctrl_pm_select_sleep_state(dev);
+
+	return 0;
+}
+
+static int st_dwc3_resume(struct device *dev)
+{
+	struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
+	int ret;
+
+	pinctrl_pm_select_default_state(dev);
+
+	reset_control_deassert(dwc3_data->rstc_pwrdn);
+	reset_control_deassert(dwc3_data->rstc_rst);
+
+	ret = st_dwc3_drd_init(dwc3_data);
+	if (ret) {
+		dev_err(dev, "drd initialisation failed\n");
+		return ret;
+	}
+
+	/* ST glue logic init */
+	st_dwc3_init(dwc3_data);
+
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume);
+
+static const struct of_device_id st_dwc3_match[] = {
+	{ .compatible = "st,stih407-dwc3" },
+	{ /* sentinel */ },
+};
+
+MODULE_DEVICE_TABLE(of, st_dwc3_match);
+
+static struct platform_driver st_dwc3_driver = {
+	.probe = st_dwc3_probe,
+	.remove = st_dwc3_remove,
+	.driver = {
+		.name = "usb-st-dwc3",
+		.of_match_table = st_dwc3_match,
+		.pm = &st_dwc3_dev_pm_ops,
+	},
+};
+
+module_platform_driver(st_dwc3_driver);
+
+MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
+MODULE_DESCRIPTION("DesignWare USB3 STi Glue Layer");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
new file mode 100644
index 0000000..1bc77a3
--- /dev/null
+++ b/drivers/usb/dwc3/ep0.c
@@ -0,0 +1,1092 @@
+/**
+ * ep0.c - DesignWare USB3 DRD Controller Endpoint 0 Handling
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/dma-mapping.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/composite.h>
+
+#include "core.h"
+#include "debug.h"
+#include "gadget.h"
+#include "io.h"
+
+static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep);
+static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
+		struct dwc3_ep *dep, struct dwc3_request *req);
+
+static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
+{
+	switch (state) {
+	case EP0_UNCONNECTED:
+		return "Unconnected";
+	case EP0_SETUP_PHASE:
+		return "Setup Phase";
+	case EP0_DATA_PHASE:
+		return "Data Phase";
+	case EP0_STATUS_PHASE:
+		return "Status Phase";
+	default:
+		return "UNKNOWN";
+	}
+}
+
+static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
+		u32 len, u32 type)
+{
+	struct dwc3_gadget_ep_cmd_params params;
+	struct dwc3_trb			*trb;
+	struct dwc3_ep			*dep;
+
+	int				ret;
+
+	dep = dwc->eps[epnum];
+	if (dep->flags & DWC3_EP_BUSY) {
+		dwc3_trace(trace_dwc3_ep0, "%s still busy", dep->name);
+		return 0;
+	}
+
+	trb = dwc->ep0_trb;
+
+	trb->bpl = lower_32_bits(buf_dma);
+	trb->bph = upper_32_bits(buf_dma);
+	trb->size = len;
+	trb->ctrl = type;
+
+	trb->ctrl |= (DWC3_TRB_CTRL_HWO
+			| DWC3_TRB_CTRL_LST
+			| DWC3_TRB_CTRL_IOC
+			| DWC3_TRB_CTRL_ISP_IMI);
+
+	memset(&params, 0, sizeof(params));
+	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
+	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
+
+	trace_dwc3_prepare_trb(dep, trb);
+
+	ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
+			DWC3_DEPCMD_STARTTRANSFER, &params);
+	if (ret < 0) {
+		dwc3_trace(trace_dwc3_ep0, "%s STARTTRANSFER failed",
+				dep->name);
+		return ret;
+	}
+
+	dep->flags |= DWC3_EP_BUSY;
+	dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc,
+			dep->number);
+
+	dwc->ep0_next_event = DWC3_EP0_COMPLETE;
+
+	return 0;
+}
+
+static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
+		struct dwc3_request *req)
+{
+	struct dwc3		*dwc = dep->dwc;
+
+	req->request.actual	= 0;
+	req->request.status	= -EINPROGRESS;
+	req->epnum		= dep->number;
+
+	list_add_tail(&req->list, &dep->request_list);
+
+	/*
+	 * Gadget driver might not be quick enough to queue a request
+	 * before we get a Transfer Not Ready event on this endpoint.
+	 *
+	 * In that case, we will set DWC3_EP_PENDING_REQUEST. When that
+	 * flag is set, it's telling us that as soon as Gadget queues the
+	 * required request, we should kick the transfer here because the
+	 * IRQ we were waiting for is long gone.
+	 */
+	if (dep->flags & DWC3_EP_PENDING_REQUEST) {
+		unsigned	direction;
+
+		direction = !!(dep->flags & DWC3_EP0_DIR_IN);
+
+		if (dwc->ep0state != EP0_DATA_PHASE) {
+			dev_WARN(dwc->dev, "Unexpected pending request\n");
+			return 0;
+		}
+
+		__dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req);
+
+		dep->flags &= ~(DWC3_EP_PENDING_REQUEST |
+				DWC3_EP0_DIR_IN);
+
+		return 0;
+	}
+
+	/*
+	 * In case gadget driver asked us to delay the STATUS phase,
+	 * handle it here.
+	 */
+	if (dwc->delayed_status) {
+		unsigned	direction;
+
+		direction = !dwc->ep0_expect_in;
+		dwc->delayed_status = false;
+		usb_gadget_set_state(&dwc->gadget, USB_STATE_CONFIGURED);
+
+		if (dwc->ep0state == EP0_STATUS_PHASE)
+			__dwc3_ep0_do_control_status(dwc, dwc->eps[direction]);
+		else
+			dwc3_trace(trace_dwc3_ep0,
+					"too early for delayed status");
+
+		return 0;
+	}
+
+	/*
+	 * Unfortunately we have uncovered a limitation wrt the Data Phase.
+	 *
+	 * Section 9.4 says we can wait for the XferNotReady(DATA) event to
+	 * come before issueing Start Transfer command, but if we do, we will
+	 * miss situations where the host starts another SETUP phase instead of
+	 * the DATA phase.  Such cases happen at least on TD.7.6 of the Link
+	 * Layer Compliance Suite.
+	 *
+	 * The problem surfaces due to the fact that in case of back-to-back
+	 * SETUP packets there will be no XferNotReady(DATA) generated and we
+	 * will be stuck waiting for XferNotReady(DATA) forever.
+	 *
+	 * By looking at tables 9-13 and 9-14 of the Databook, we can see that
+	 * it tells us to start Data Phase right away. It also mentions that if
+	 * we receive a SETUP phase instead of the DATA phase, core will issue
+	 * XferComplete for the DATA phase, before actually initiating it in
+	 * the wire, with the TRB's status set to "SETUP_PENDING". Such status
+	 * can only be used to print some debugging logs, as the core expects
+	 * us to go through to the STATUS phase and start a CONTROL_STATUS TRB,
+	 * just so it completes right away, without transferring anything and,
+	 * only then, we can go back to the SETUP phase.
+	 *
+	 * Because of this scenario, SNPS decided to change the programming
+	 * model of control transfers and support on-demand transfers only for
+	 * the STATUS phase. To fix the issue we have now, we will always wait
+	 * for gadget driver to queue the DATA phase's struct usb_request, then
+	 * start it right away.
+	 *
+	 * If we're actually in a 2-stage transfer, we will wait for
+	 * XferNotReady(STATUS).
+	 */
+	if (dwc->three_stage_setup) {
+		unsigned        direction;
+
+		direction = dwc->ep0_expect_in;
+		dwc->ep0state = EP0_DATA_PHASE;
+
+		__dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req);
+
+		dep->flags &= ~DWC3_EP0_DIR_IN;
+	}
+
+	return 0;
+}
+
+int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
+		gfp_t gfp_flags)
+{
+	struct dwc3_request		*req = to_dwc3_request(request);
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+	struct dwc3			*dwc = dep->dwc;
+
+	unsigned long			flags;
+
+	int				ret;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	if (!dep->endpoint.desc) {
+		dwc3_trace(trace_dwc3_ep0,
+				"trying to queue request %p to disabled %s",
+				request, dep->name);
+		ret = -ESHUTDOWN;
+		goto out;
+	}
+
+	/* we share one TRB for ep0/1 */
+	if (!list_empty(&dep->request_list)) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	dwc3_trace(trace_dwc3_ep0,
+			"queueing request %p to %s length %d state '%s'",
+			request, dep->name, request->length,
+			dwc3_ep0_state_string(dwc->ep0state));
+
+	ret = __dwc3_gadget_ep0_queue(dep, req);
+
+out:
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)
+{
+	struct dwc3_ep		*dep;
+
+	/* reinitialize physical ep1 */
+	dep = dwc->eps[1];
+	dep->flags = DWC3_EP_ENABLED;
+
+	/* stall is always issued on EP0 */
+	dep = dwc->eps[0];
+	__dwc3_gadget_ep_set_halt(dep, 1, false);
+	dep->flags = DWC3_EP_ENABLED;
+	dwc->delayed_status = false;
+
+	if (!list_empty(&dep->request_list)) {
+		struct dwc3_request	*req;
+
+		req = next_request(&dep->request_list);
+		dwc3_gadget_giveback(dep, req, -ECONNRESET);
+	}
+
+	dwc->ep0state = EP0_SETUP_PHASE;
+	dwc3_ep0_out_start(dwc);
+}
+
+int __dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value)
+{
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+	struct dwc3			*dwc = dep->dwc;
+
+	dwc3_ep0_stall_and_restart(dwc);
+
+	return 0;
+}
+
+int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value)
+{
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+	struct dwc3			*dwc = dep->dwc;
+	unsigned long			flags;
+	int				ret;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	ret = __dwc3_gadget_ep0_set_halt(ep, value);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+void dwc3_ep0_out_start(struct dwc3 *dwc)
+{
+	int				ret;
+
+	ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
+			DWC3_TRBCTL_CONTROL_SETUP);
+	WARN_ON(ret < 0);
+}
+
+static struct dwc3_ep *dwc3_wIndex_to_dep(struct dwc3 *dwc, __le16 wIndex_le)
+{
+	struct dwc3_ep		*dep;
+	u32			windex = le16_to_cpu(wIndex_le);
+	u32			epnum;
+
+	epnum = (windex & USB_ENDPOINT_NUMBER_MASK) << 1;
+	if ((windex & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)
+		epnum |= 1;
+
+	dep = dwc->eps[epnum];
+	if (dep->flags & DWC3_EP_ENABLED)
+		return dep;
+
+	return NULL;
+}
+
+static void dwc3_ep0_status_cmpl(struct usb_ep *ep, struct usb_request *req)
+{
+}
+/*
+ * ch 9.4.5
+ */
+static int dwc3_ep0_handle_status(struct dwc3 *dwc,
+		struct usb_ctrlrequest *ctrl)
+{
+	struct dwc3_ep		*dep;
+	u32			recip;
+	u32			reg;
+	u16			usb_status = 0;
+	__le16			*response_pkt;
+
+	recip = ctrl->bRequestType & USB_RECIP_MASK;
+	switch (recip) {
+	case USB_RECIP_DEVICE:
+		/*
+		 * LTM will be set once we know how to set this in HW.
+		 */
+		usb_status |= dwc->is_selfpowered << USB_DEVICE_SELF_POWERED;
+
+		if (dwc->speed == DWC3_DSTS_SUPERSPEED) {
+			reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+			if (reg & DWC3_DCTL_INITU1ENA)
+				usb_status |= 1 << USB_DEV_STAT_U1_ENABLED;
+			if (reg & DWC3_DCTL_INITU2ENA)
+				usb_status |= 1 << USB_DEV_STAT_U2_ENABLED;
+		}
+
+		break;
+
+	case USB_RECIP_INTERFACE:
+		/*
+		 * Function Remote Wake Capable	D0
+		 * Function Remote Wakeup	D1
+		 */
+		break;
+
+	case USB_RECIP_ENDPOINT:
+		dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex);
+		if (!dep)
+			return -EINVAL;
+
+		if (dep->flags & DWC3_EP_STALL)
+			usb_status = 1 << USB_ENDPOINT_HALT;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	response_pkt = (__le16 *) dwc->setup_buf;
+	*response_pkt = cpu_to_le16(usb_status);
+
+	dep = dwc->eps[0];
+	dwc->ep0_usb_req.dep = dep;
+	dwc->ep0_usb_req.request.length = sizeof(*response_pkt);
+	dwc->ep0_usb_req.request.buf = dwc->setup_buf;
+	dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl;
+
+	return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
+}
+
+static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
+		struct usb_ctrlrequest *ctrl, int set)
+{
+	struct dwc3_ep		*dep;
+	u32			recip;
+	u32			wValue;
+	u32			wIndex;
+	u32			reg;
+	int			ret;
+	enum usb_device_state	state;
+
+	wValue = le16_to_cpu(ctrl->wValue);
+	wIndex = le16_to_cpu(ctrl->wIndex);
+	recip = ctrl->bRequestType & USB_RECIP_MASK;
+	state = dwc->gadget.state;
+
+	switch (recip) {
+	case USB_RECIP_DEVICE:
+
+		switch (wValue) {
+		case USB_DEVICE_REMOTE_WAKEUP:
+			break;
+		/*
+		 * 9.4.1 says only only for SS, in AddressState only for
+		 * default control pipe
+		 */
+		case USB_DEVICE_U1_ENABLE:
+			if (state != USB_STATE_CONFIGURED)
+				return -EINVAL;
+			if (dwc->speed != DWC3_DSTS_SUPERSPEED)
+				return -EINVAL;
+
+			reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+			if (set)
+				reg |= DWC3_DCTL_INITU1ENA;
+			else
+				reg &= ~DWC3_DCTL_INITU1ENA;
+			dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+			break;
+
+		case USB_DEVICE_U2_ENABLE:
+			if (state != USB_STATE_CONFIGURED)
+				return -EINVAL;
+			if (dwc->speed != DWC3_DSTS_SUPERSPEED)
+				return -EINVAL;
+
+			reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+			if (set)
+				reg |= DWC3_DCTL_INITU2ENA;
+			else
+				reg &= ~DWC3_DCTL_INITU2ENA;
+			dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+			break;
+
+		case USB_DEVICE_LTM_ENABLE:
+			return -EINVAL;
+
+		case USB_DEVICE_TEST_MODE:
+			if ((wIndex & 0xff) != 0)
+				return -EINVAL;
+			if (!set)
+				return -EINVAL;
+
+			dwc->test_mode_nr = wIndex >> 8;
+			dwc->test_mode = true;
+			break;
+		default:
+			return -EINVAL;
+		}
+		break;
+
+	case USB_RECIP_INTERFACE:
+		switch (wValue) {
+		case USB_INTRF_FUNC_SUSPEND:
+			if (wIndex & USB_INTRF_FUNC_SUSPEND_LP)
+				/* XXX enable Low power suspend */
+				;
+			if (wIndex & USB_INTRF_FUNC_SUSPEND_RW)
+				/* XXX enable remote wakeup */
+				;
+			break;
+		default:
+			return -EINVAL;
+		}
+		break;
+
+	case USB_RECIP_ENDPOINT:
+		switch (wValue) {
+		case USB_ENDPOINT_HALT:
+			dep = dwc3_wIndex_to_dep(dwc, wIndex);
+			if (!dep)
+				return -EINVAL;
+			if (set == 0 && (dep->flags & DWC3_EP_WEDGE))
+				break;
+			ret = __dwc3_gadget_ep_set_halt(dep, set, true);
+			if (ret)
+				return -EINVAL;
+			break;
+		default:
+			return -EINVAL;
+		}
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
+{
+	enum usb_device_state state = dwc->gadget.state;
+	u32 addr;
+	u32 reg;
+
+	addr = le16_to_cpu(ctrl->wValue);
+	if (addr > 127) {
+		dwc3_trace(trace_dwc3_ep0, "invalid device address %d", addr);
+		return -EINVAL;
+	}
+
+	if (state == USB_STATE_CONFIGURED) {
+		dwc3_trace(trace_dwc3_ep0,
+				"trying to set address when configured");
+		return -EINVAL;
+	}
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
+	reg &= ~(DWC3_DCFG_DEVADDR_MASK);
+	reg |= DWC3_DCFG_DEVADDR(addr);
+	dwc3_writel(dwc->regs, DWC3_DCFG, reg);
+
+	if (addr)
+		usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS);
+	else
+		usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
+
+	return 0;
+}
+
+static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
+{
+	int ret;
+
+	spin_unlock(&dwc->lock);
+	ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl);
+	spin_lock(&dwc->lock);
+	return ret;
+}
+
+static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
+{
+	enum usb_device_state state = dwc->gadget.state;
+	u32 cfg;
+	int ret;
+	u32 reg;
+
+	dwc->start_config_issued = false;
+	cfg = le16_to_cpu(ctrl->wValue);
+
+	switch (state) {
+	case USB_STATE_DEFAULT:
+		return -EINVAL;
+
+	case USB_STATE_ADDRESS:
+		ret = dwc3_ep0_delegate_req(dwc, ctrl);
+		/* if the cfg matches and the cfg is non zero */
+		if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
+
+			/*
+			 * only change state if set_config has already
+			 * been processed. If gadget driver returns
+			 * USB_GADGET_DELAYED_STATUS, we will wait
+			 * to change the state on the next usb_ep_queue()
+			 */
+			if (ret == 0)
+				usb_gadget_set_state(&dwc->gadget,
+						USB_STATE_CONFIGURED);
+
+			/*
+			 * Enable transition to U1/U2 state when
+			 * nothing is pending from application.
+			 */
+			reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+			reg |= (DWC3_DCTL_ACCEPTU1ENA | DWC3_DCTL_ACCEPTU2ENA);
+			dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+			dwc->resize_fifos = true;
+			dwc3_trace(trace_dwc3_ep0, "resize FIFOs flag SET");
+		}
+		break;
+
+	case USB_STATE_CONFIGURED:
+		ret = dwc3_ep0_delegate_req(dwc, ctrl);
+		if (!cfg && !ret)
+			usb_gadget_set_state(&dwc->gadget,
+					USB_STATE_ADDRESS);
+		break;
+	default:
+		ret = -EINVAL;
+	}
+	return ret;
+}
+
+static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)
+{
+	struct dwc3_ep	*dep = to_dwc3_ep(ep);
+	struct dwc3	*dwc = dep->dwc;
+
+	u32		param = 0;
+	u32		reg;
+
+	struct timing {
+		u8	u1sel;
+		u8	u1pel;
+		u16	u2sel;
+		u16	u2pel;
+	} __packed timing;
+
+	int		ret;
+
+	memcpy(&timing, req->buf, sizeof(timing));
+
+	dwc->u1sel = timing.u1sel;
+	dwc->u1pel = timing.u1pel;
+	dwc->u2sel = le16_to_cpu(timing.u2sel);
+	dwc->u2pel = le16_to_cpu(timing.u2pel);
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+	if (reg & DWC3_DCTL_INITU2ENA)
+		param = dwc->u2pel;
+	if (reg & DWC3_DCTL_INITU1ENA)
+		param = dwc->u1pel;
+
+	/*
+	 * According to Synopsys Databook, if parameter is
+	 * greater than 125, a value of zero should be
+	 * programmed in the register.
+	 */
+	if (param > 125)
+		param = 0;
+
+	/* now that we have the time, issue DGCMD Set Sel */
+	ret = dwc3_send_gadget_generic_command(dwc,
+			DWC3_DGCMD_SET_PERIODIC_PAR, param);
+	WARN_ON(ret < 0);
+}
+
+static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
+{
+	struct dwc3_ep	*dep;
+	enum usb_device_state state = dwc->gadget.state;
+	u16		wLength;
+	u16		wValue;
+
+	if (state == USB_STATE_DEFAULT)
+		return -EINVAL;
+
+	wValue = le16_to_cpu(ctrl->wValue);
+	wLength = le16_to_cpu(ctrl->wLength);
+
+	if (wLength != 6) {
+		dev_err(dwc->dev, "Set SEL should be 6 bytes, got %d\n",
+				wLength);
+		return -EINVAL;
+	}
+
+	/*
+	 * To handle Set SEL we need to receive 6 bytes from Host. So let's
+	 * queue a usb_request for 6 bytes.
+	 *
+	 * Remember, though, this controller can't handle non-wMaxPacketSize
+	 * aligned transfers on the OUT direction, so we queue a request for
+	 * wMaxPacketSize instead.
+	 */
+	dep = dwc->eps[0];
+	dwc->ep0_usb_req.dep = dep;
+	dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket;
+	dwc->ep0_usb_req.request.buf = dwc->setup_buf;
+	dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl;
+
+	return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
+}
+
+static int dwc3_ep0_set_isoch_delay(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
+{
+	u16		wLength;
+	u16		wValue;
+	u16		wIndex;
+
+	wValue = le16_to_cpu(ctrl->wValue);
+	wLength = le16_to_cpu(ctrl->wLength);
+	wIndex = le16_to_cpu(ctrl->wIndex);
+
+	if (wIndex || wLength)
+		return -EINVAL;
+
+	/*
+	 * REVISIT It's unclear from Databook what to do with this
+	 * value. For now, just cache it.
+	 */
+	dwc->isoch_delay = wValue;
+
+	return 0;
+}
+
+static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
+{
+	int ret;
+
+	switch (ctrl->bRequest) {
+	case USB_REQ_GET_STATUS:
+		dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS");
+		ret = dwc3_ep0_handle_status(dwc, ctrl);
+		break;
+	case USB_REQ_CLEAR_FEATURE:
+		dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE");
+		ret = dwc3_ep0_handle_feature(dwc, ctrl, 0);
+		break;
+	case USB_REQ_SET_FEATURE:
+		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE");
+		ret = dwc3_ep0_handle_feature(dwc, ctrl, 1);
+		break;
+	case USB_REQ_SET_ADDRESS:
+		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS");
+		ret = dwc3_ep0_set_address(dwc, ctrl);
+		break;
+	case USB_REQ_SET_CONFIGURATION:
+		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_CONFIGURATION");
+		ret = dwc3_ep0_set_config(dwc, ctrl);
+		break;
+	case USB_REQ_SET_SEL:
+		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL");
+		ret = dwc3_ep0_set_sel(dwc, ctrl);
+		break;
+	case USB_REQ_SET_ISOCH_DELAY:
+		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ISOCH_DELAY");
+		ret = dwc3_ep0_set_isoch_delay(dwc, ctrl);
+		break;
+	default:
+		dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget driver");
+		ret = dwc3_ep0_delegate_req(dwc, ctrl);
+		break;
+	}
+
+	return ret;
+}
+
+static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event)
+{
+	struct usb_ctrlrequest *ctrl = dwc->ctrl_req;
+	int ret = -EINVAL;
+	u32 len;
+
+	if (!dwc->gadget_driver)
+		goto out;
+
+	trace_dwc3_ctrl_req(ctrl);
+
+	len = le16_to_cpu(ctrl->wLength);
+	if (!len) {
+		dwc->three_stage_setup = false;
+		dwc->ep0_expect_in = false;
+		dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS;
+	} else {
+		dwc->three_stage_setup = true;
+		dwc->ep0_expect_in = !!(ctrl->bRequestType & USB_DIR_IN);
+		dwc->ep0_next_event = DWC3_EP0_NRDY_DATA;
+	}
+
+	if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD)
+		ret = dwc3_ep0_std_request(dwc, ctrl);
+	else
+		ret = dwc3_ep0_delegate_req(dwc, ctrl);
+
+	if (ret == USB_GADGET_DELAYED_STATUS)
+		dwc->delayed_status = true;
+
+out:
+	if (ret < 0)
+		dwc3_ep0_stall_and_restart(dwc);
+}
+
+static void dwc3_ep0_complete_data(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event)
+{
+	struct dwc3_request	*r = NULL;
+	struct usb_request	*ur;
+	struct dwc3_trb		*trb;
+	struct dwc3_ep		*ep0;
+	u32			transferred;
+	u32			status;
+	u32			length;
+	u8			epnum;
+
+	epnum = event->endpoint_number;
+	ep0 = dwc->eps[0];
+
+	dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS;
+
+	trb = dwc->ep0_trb;
+
+	trace_dwc3_complete_trb(ep0, trb);
+
+	r = next_request(&ep0->request_list);
+	if (!r)
+		return;
+
+	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
+	if (status == DWC3_TRBSTS_SETUP_PENDING) {
+		dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
+
+		if (r)
+			dwc3_gadget_giveback(ep0, r, -ECONNRESET);
+
+		return;
+	}
+
+	ur = &r->request;
+
+	length = trb->size & DWC3_TRB_SIZE_MASK;
+
+	if (dwc->ep0_bounced) {
+		unsigned transfer_size = ur->length;
+		unsigned maxp = ep0->endpoint.maxpacket;
+
+		transfer_size += (maxp - (transfer_size % maxp));
+		transferred = min_t(u32, ur->length,
+				transfer_size - length);
+		memcpy(ur->buf, dwc->ep0_bounce, transferred);
+	} else {
+		transferred = ur->length - length;
+	}
+
+	ur->actual += transferred;
+
+	if ((epnum & 1) && ur->actual < ur->length) {
+		/* for some reason we did not get everything out */
+
+		dwc3_ep0_stall_and_restart(dwc);
+	} else {
+		dwc3_gadget_giveback(ep0, r, 0);
+
+		if (IS_ALIGNED(ur->length, ep0->endpoint.maxpacket) &&
+				ur->length && ur->zero) {
+			int ret;
+
+			dwc->ep0_next_event = DWC3_EP0_COMPLETE;
+
+			ret = dwc3_ep0_start_trans(dwc, epnum,
+					dwc->ctrl_req_addr, 0,
+					DWC3_TRBCTL_CONTROL_DATA);
+			WARN_ON(ret < 0);
+		}
+	}
+}
+
+static void dwc3_ep0_complete_status(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event)
+{
+	struct dwc3_request	*r;
+	struct dwc3_ep		*dep;
+	struct dwc3_trb		*trb;
+	u32			status;
+
+	dep = dwc->eps[0];
+	trb = dwc->ep0_trb;
+
+	trace_dwc3_complete_trb(dep, trb);
+
+	if (!list_empty(&dep->request_list)) {
+		r = next_request(&dep->request_list);
+
+		dwc3_gadget_giveback(dep, r, 0);
+	}
+
+	if (dwc->test_mode) {
+		int ret;
+
+		ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr);
+		if (ret < 0) {
+			dwc3_trace(trace_dwc3_ep0, "Invalid Test #%d",
+					dwc->test_mode_nr);
+			dwc3_ep0_stall_and_restart(dwc);
+			return;
+		}
+	}
+
+	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
+	if (status == DWC3_TRBSTS_SETUP_PENDING)
+		dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
+
+	dwc->ep0state = EP0_SETUP_PHASE;
+	dwc3_ep0_out_start(dwc);
+}
+
+static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
+			const struct dwc3_event_depevt *event)
+{
+	struct dwc3_ep		*dep = dwc->eps[event->endpoint_number];
+
+	dep->flags &= ~DWC3_EP_BUSY;
+	dep->resource_index = 0;
+	dwc->setup_packet_pending = false;
+
+	switch (dwc->ep0state) {
+	case EP0_SETUP_PHASE:
+		dwc3_trace(trace_dwc3_ep0, "Setup Phase");
+		dwc3_ep0_inspect_setup(dwc, event);
+		break;
+
+	case EP0_DATA_PHASE:
+		dwc3_trace(trace_dwc3_ep0, "Data Phase");
+		dwc3_ep0_complete_data(dwc, event);
+		break;
+
+	case EP0_STATUS_PHASE:
+		dwc3_trace(trace_dwc3_ep0, "Status Phase");
+		dwc3_ep0_complete_status(dwc, event);
+		break;
+	default:
+		WARN(true, "UNKNOWN ep0state %d\n", dwc->ep0state);
+	}
+}
+
+static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
+		struct dwc3_ep *dep, struct dwc3_request *req)
+{
+	int			ret;
+
+	req->direction = !!dep->number;
+
+	if (req->request.length == 0) {
+		ret = dwc3_ep0_start_trans(dwc, dep->number,
+				dwc->ctrl_req_addr, 0,
+				DWC3_TRBCTL_CONTROL_DATA);
+	} else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket)
+			&& (dep->number == 0)) {
+		u32	transfer_size;
+		u32	maxpacket;
+
+		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
+				dep->number);
+		if (ret) {
+			dev_dbg(dwc->dev, "failed to map request\n");
+			return;
+		}
+
+		WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
+
+		maxpacket = dep->endpoint.maxpacket;
+		transfer_size = roundup(req->request.length, maxpacket);
+
+		dwc->ep0_bounced = true;
+
+		/*
+		 * REVISIT in case request length is bigger than
+		 * DWC3_EP0_BOUNCE_SIZE we will need two chained
+		 * TRBs to handle the transfer.
+		 */
+		ret = dwc3_ep0_start_trans(dwc, dep->number,
+				dwc->ep0_bounce_addr, transfer_size,
+				DWC3_TRBCTL_CONTROL_DATA);
+	} else {
+		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
+				dep->number);
+		if (ret) {
+			dev_dbg(dwc->dev, "failed to map request\n");
+			return;
+		}
+
+		ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma,
+				req->request.length, DWC3_TRBCTL_CONTROL_DATA);
+	}
+
+	WARN_ON(ret < 0);
+}
+
+static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
+{
+	struct dwc3		*dwc = dep->dwc;
+	u32			type;
+
+	type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3
+		: DWC3_TRBCTL_CONTROL_STATUS2;
+
+	return dwc3_ep0_start_trans(dwc, dep->number,
+			dwc->ctrl_req_addr, 0, type);
+}
+
+static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
+{
+	if (dwc->resize_fifos) {
+		dwc3_trace(trace_dwc3_ep0, "Resizing FIFOs");
+		dwc3_gadget_resize_tx_fifos(dwc);
+		dwc->resize_fifos = 0;
+	}
+
+	WARN_ON(dwc3_ep0_start_control_status(dep));
+}
+
+static void dwc3_ep0_do_control_status(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event)
+{
+	struct dwc3_ep		*dep = dwc->eps[event->endpoint_number];
+
+	__dwc3_ep0_do_control_status(dwc, dep);
+}
+
+static void dwc3_ep0_end_control_data(struct dwc3 *dwc, struct dwc3_ep *dep)
+{
+	struct dwc3_gadget_ep_cmd_params params;
+	u32			cmd;
+	int			ret;
+
+	if (!dep->resource_index)
+		return;
+
+	cmd = DWC3_DEPCMD_ENDTRANSFER;
+	cmd |= DWC3_DEPCMD_CMDIOC;
+	cmd |= DWC3_DEPCMD_PARAM(dep->resource_index);
+	memset(&params, 0, sizeof(params));
+	ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params);
+	WARN_ON_ONCE(ret);
+	dep->resource_index = 0;
+}
+
+static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event)
+{
+	dwc->setup_packet_pending = true;
+
+	switch (event->status) {
+	case DEPEVT_STATUS_CONTROL_DATA:
+		dwc3_trace(trace_dwc3_ep0, "Control Data");
+
+		/*
+		 * We already have a DATA transfer in the controller's cache,
+		 * if we receive a XferNotReady(DATA) we will ignore it, unless
+		 * it's for the wrong direction.
+		 *
+		 * In that case, we must issue END_TRANSFER command to the Data
+		 * Phase we already have started and issue SetStall on the
+		 * control endpoint.
+		 */
+		if (dwc->ep0_expect_in != event->endpoint_number) {
+			struct dwc3_ep	*dep = dwc->eps[dwc->ep0_expect_in];
+
+			dwc3_trace(trace_dwc3_ep0,
+					"Wrong direction for Data phase");
+			dwc3_ep0_end_control_data(dwc, dep);
+			dwc3_ep0_stall_and_restart(dwc);
+			return;
+		}
+
+		break;
+
+	case DEPEVT_STATUS_CONTROL_STATUS:
+		if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS)
+			return;
+
+		dwc3_trace(trace_dwc3_ep0, "Control Status");
+
+		dwc->ep0state = EP0_STATUS_PHASE;
+
+		if (dwc->delayed_status) {
+			WARN_ON_ONCE(event->endpoint_number != 1);
+			dwc3_trace(trace_dwc3_ep0, "Delayed Status");
+			return;
+		}
+
+		dwc3_ep0_do_control_status(dwc, event);
+	}
+}
+
+void dwc3_ep0_interrupt(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event)
+{
+	u8			epnum = event->endpoint_number;
+
+	dwc3_trace(trace_dwc3_ep0, "%s while ep%d%s in state '%s'",
+			dwc3_ep_event_string(event->endpoint_event),
+			epnum >> 1, (epnum & 1) ? "in" : "out",
+			dwc3_ep0_state_string(dwc->ep0state));
+
+	switch (event->endpoint_event) {
+	case DWC3_DEPEVT_XFERCOMPLETE:
+		dwc3_ep0_xfer_complete(dwc, event);
+		break;
+
+	case DWC3_DEPEVT_XFERNOTREADY:
+		dwc3_ep0_xfernotready(dwc, event);
+		break;
+
+	case DWC3_DEPEVT_XFERINPROGRESS:
+	case DWC3_DEPEVT_RXTXFIFOEVT:
+	case DWC3_DEPEVT_STREAMEVT:
+	case DWC3_DEPEVT_EPCMDCMPLT:
+		break;
+	}
+}
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
new file mode 100644
index 0000000..f03b136
--- /dev/null
+++ b/drivers/usb/dwc3/gadget.c
@@ -0,0 +1,2824 @@
+/**
+ * gadget.c - DesignWare USB3 DRD Controller Gadget Framework Link
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/dma-mapping.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+
+#include "debug.h"
+#include "core.h"
+#include "gadget.h"
+#include "io.h"
+
+/**
+ * dwc3_gadget_set_test_mode - Enables USB2 Test Modes
+ * @dwc: pointer to our context structure
+ * @mode: the mode to set (J, K SE0 NAK, Force Enable)
+ *
+ * Caller should take care of locking. This function will
+ * return 0 on success or -EINVAL if wrong Test Selector
+ * is passed
+ */
+int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)
+{
+	u32		reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+	reg &= ~DWC3_DCTL_TSTCTRL_MASK;
+
+	switch (mode) {
+	case TEST_J:
+	case TEST_K:
+	case TEST_SE0_NAK:
+	case TEST_PACKET:
+	case TEST_FORCE_EN:
+		reg |= mode << 1;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+	return 0;
+}
+
+/**
+ * dwc3_gadget_get_link_state - Gets current state of USB Link
+ * @dwc: pointer to our context structure
+ *
+ * Caller should take care of locking. This function will
+ * return the link state on success (>= 0) or -ETIMEDOUT.
+ */
+int dwc3_gadget_get_link_state(struct dwc3 *dwc)
+{
+	u32		reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+
+	return DWC3_DSTS_USBLNKST(reg);
+}
+
+/**
+ * dwc3_gadget_set_link_state - Sets USB Link to a particular State
+ * @dwc: pointer to our context structure
+ * @state: the state to put link into
+ *
+ * Caller should take care of locking. This function will
+ * return 0 on success or -ETIMEDOUT.
+ */
+int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
+{
+	int		retries = 10000;
+	u32		reg;
+
+	/*
+	 * Wait until device controller is ready. Only applies to 1.94a and
+	 * later RTL.
+	 */
+	if (dwc->revision >= DWC3_REVISION_194A) {
+		while (--retries) {
+			reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+			if (reg & DWC3_DSTS_DCNRD)
+				udelay(5);
+			else
+				break;
+		}
+
+		if (retries <= 0)
+			return -ETIMEDOUT;
+	}
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+	reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK;
+
+	/* set requested state */
+	reg |= DWC3_DCTL_ULSTCHNGREQ(state);
+	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+	/*
+	 * The following code is racy when called from dwc3_gadget_wakeup,
+	 * and is not needed, at least on newer versions
+	 */
+	if (dwc->revision >= DWC3_REVISION_194A)
+		return 0;
+
+	/* wait for a change in DSTS */
+	retries = 10000;
+	while (--retries) {
+		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+
+		if (DWC3_DSTS_USBLNKST(reg) == state)
+			return 0;
+
+		udelay(5);
+	}
+
+	dev_vdbg(dwc->dev, "link state change request timed out\n");
+
+	return -ETIMEDOUT;
+}
+
+/**
+ * dwc3_gadget_resize_tx_fifos - reallocate fifo spaces for current use-case
+ * @dwc: pointer to our context structure
+ *
+ * This function will a best effort FIFO allocation in order
+ * to improve FIFO usage and throughput, while still allowing
+ * us to enable as many endpoints as possible.
+ *
+ * Keep in mind that this operation will be highly dependent
+ * on the configured size for RAM1 - which contains TxFifo -,
+ * the amount of endpoints enabled on coreConsultant tool, and
+ * the width of the Master Bus.
+ *
+ * In the ideal world, we would always be able to satisfy the
+ * following equation:
+ *
+ * ((512 + 2 * MDWIDTH-Bytes) + (Number of IN Endpoints - 1) * \
+ * (3 * (1024 + MDWIDTH-Bytes) + MDWIDTH-Bytes)) / MDWIDTH-Bytes
+ *
+ * Unfortunately, due to many variables that's not always the case.
+ */
+int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
+{
+	int		last_fifo_depth = 0;
+	int		ram1_depth;
+	int		fifo_size;
+	int		mdwidth;
+	int		num;
+
+	if (!dwc->needs_fifo_resize)
+		return 0;
+
+	ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7);
+	mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
+
+	/* MDWIDTH is represented in bits, we need it in bytes */
+	mdwidth >>= 3;
+
+	/*
+	 * FIXME For now we will only allocate 1 wMaxPacketSize space
+	 * for each enabled endpoint, later patches will come to
+	 * improve this algorithm so that we better use the internal
+	 * FIFO space
+	 */
+	for (num = 0; num < dwc->num_in_eps; num++) {
+		/* bit0 indicates direction; 1 means IN ep */
+		struct dwc3_ep	*dep = dwc->eps[(num << 1) | 1];
+		int		mult = 1;
+		int		tmp;
+
+		if (!(dep->flags & DWC3_EP_ENABLED))
+			continue;
+
+		if (usb_endpoint_xfer_bulk(dep->endpoint.desc)
+				|| usb_endpoint_xfer_isoc(dep->endpoint.desc))
+			mult = 3;
+
+		/*
+		 * REVISIT: the following assumes we will always have enough
+		 * space available on the FIFO RAM for all possible use cases.
+		 * Make sure that's true somehow and change FIFO allocation
+		 * accordingly.
+		 *
+		 * If we have Bulk or Isochronous endpoints, we want
+		 * them to be able to be very, very fast. So we're giving
+		 * those endpoints a fifo_size which is enough for 3 full
+		 * packets
+		 */
+		tmp = mult * (dep->endpoint.maxpacket + mdwidth);
+		tmp += mdwidth;
+
+		fifo_size = DIV_ROUND_UP(tmp, mdwidth);
+
+		fifo_size |= (last_fifo_depth << 16);
+
+		dev_vdbg(dwc->dev, "%s: Fifo Addr %04x Size %d\n",
+				dep->name, last_fifo_depth, fifo_size & 0xffff);
+
+		dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num), fifo_size);
+
+		last_fifo_depth += (fifo_size & 0xffff);
+	}
+
+	return 0;
+}
+
+void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
+		int status)
+{
+	struct dwc3			*dwc = dep->dwc;
+	int				i;
+
+	if (req->queued) {
+		i = 0;
+		do {
+			dep->busy_slot++;
+			/*
+			 * Skip LINK TRB. We can't use req->trb and check for
+			 * DWC3_TRBCTL_LINK_TRB because it points the TRB we
+			 * just completed (not the LINK TRB).
+			 */
+			if (((dep->busy_slot & DWC3_TRB_MASK) ==
+				DWC3_TRB_NUM- 1) &&
+				usb_endpoint_xfer_isoc(dep->endpoint.desc))
+				dep->busy_slot++;
+		} while(++i < req->request.num_mapped_sgs);
+		req->queued = false;
+	}
+	list_del(&req->list);
+	req->trb = NULL;
+
+	if (req->request.status == -EINPROGRESS)
+		req->request.status = status;
+
+	if (dwc->ep0_bounced && dep->number == 0)
+		dwc->ep0_bounced = false;
+	else
+		usb_gadget_unmap_request(&dwc->gadget, &req->request,
+				req->direction);
+
+	dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n",
+			req, dep->name, req->request.actual,
+			req->request.length, status);
+	trace_dwc3_gadget_giveback(req);
+
+	spin_unlock(&dwc->lock);
+	usb_gadget_giveback_request(&dep->endpoint, &req->request);
+	spin_lock(&dwc->lock);
+}
+
+int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param)
+{
+	u32		timeout = 500;
+	u32		reg;
+
+	trace_dwc3_gadget_generic_cmd(cmd, param);
+
+	dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param);
+	dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT);
+
+	do {
+		reg = dwc3_readl(dwc->regs, DWC3_DGCMD);
+		if (!(reg & DWC3_DGCMD_CMDACT)) {
+			dev_vdbg(dwc->dev, "Command Complete --> %d\n",
+					DWC3_DGCMD_STATUS(reg));
+			return 0;
+		}
+
+		/*
+		 * We can't sleep here, because it's also called from
+		 * interrupt context.
+		 */
+		timeout--;
+		if (!timeout)
+			return -ETIMEDOUT;
+		udelay(1);
+	} while (1);
+}
+
+int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
+		unsigned cmd, struct dwc3_gadget_ep_cmd_params *params)
+{
+	struct dwc3_ep		*dep = dwc->eps[ep];
+	u32			timeout = 500;
+	u32			reg;
+
+	trace_dwc3_gadget_ep_cmd(dep, cmd, params);
+
+	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0);
+	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1);
+	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR2(ep), params->param2);
+
+	dwc3_writel(dwc->regs, DWC3_DEPCMD(ep), cmd | DWC3_DEPCMD_CMDACT);
+	do {
+		reg = dwc3_readl(dwc->regs, DWC3_DEPCMD(ep));
+		if (!(reg & DWC3_DEPCMD_CMDACT)) {
+			dev_vdbg(dwc->dev, "Command Complete --> %d\n",
+					DWC3_DEPCMD_STATUS(reg));
+			return 0;
+		}
+
+		/*
+		 * We can't sleep here, because it is also called from
+		 * interrupt context.
+		 */
+		timeout--;
+		if (!timeout)
+			return -ETIMEDOUT;
+
+		udelay(1);
+	} while (1);
+}
+
+static dma_addr_t dwc3_trb_dma_offset(struct dwc3_ep *dep,
+		struct dwc3_trb *trb)
+{
+	u32		offset = (char *) trb - (char *) dep->trb_pool;
+
+	return dep->trb_pool_dma + offset;
+}
+
+static int dwc3_alloc_trb_pool(struct dwc3_ep *dep)
+{
+	struct dwc3		*dwc = dep->dwc;
+
+	if (dep->trb_pool)
+		return 0;
+
+	if (dep->number == 0 || dep->number == 1)
+		return 0;
+
+	dep->trb_pool = dma_alloc_coherent(dwc->dev,
+			sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
+			&dep->trb_pool_dma, GFP_KERNEL);
+	if (!dep->trb_pool) {
+		dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n",
+				dep->name);
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+static void dwc3_free_trb_pool(struct dwc3_ep *dep)
+{
+	struct dwc3		*dwc = dep->dwc;
+
+	dma_free_coherent(dwc->dev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
+			dep->trb_pool, dep->trb_pool_dma);
+
+	dep->trb_pool = NULL;
+	dep->trb_pool_dma = 0;
+}
+
+static int dwc3_gadget_start_config(struct dwc3 *dwc, struct dwc3_ep *dep)
+{
+	struct dwc3_gadget_ep_cmd_params params;
+	u32			cmd;
+
+	memset(&params, 0x00, sizeof(params));
+
+	if (dep->number != 1) {
+		cmd = DWC3_DEPCMD_DEPSTARTCFG;
+		/* XferRscIdx == 0 for ep0 and 2 for the remaining */
+		if (dep->number > 1) {
+			if (dwc->start_config_issued)
+				return 0;
+			dwc->start_config_issued = true;
+			cmd |= DWC3_DEPCMD_PARAM(2);
+		}
+
+		return dwc3_send_gadget_ep_cmd(dwc, 0, cmd, &params);
+	}
+
+	return 0;
+}
+
+static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep,
+		const struct usb_endpoint_descriptor *desc,
+		const struct usb_ss_ep_comp_descriptor *comp_desc,
+		bool ignore, bool restore)
+{
+	struct dwc3_gadget_ep_cmd_params params;
+
+	memset(&params, 0x00, sizeof(params));
+
+	params.param0 = DWC3_DEPCFG_EP_TYPE(usb_endpoint_type(desc))
+		| DWC3_DEPCFG_MAX_PACKET_SIZE(usb_endpoint_maxp(desc));
+
+	/* Burst size is only needed in SuperSpeed mode */
+	if (dwc->gadget.speed == USB_SPEED_SUPER) {
+		u32 burst = dep->endpoint.maxburst - 1;
+
+		params.param0 |= DWC3_DEPCFG_BURST_SIZE(burst);
+	}
+
+	if (ignore)
+		params.param0 |= DWC3_DEPCFG_IGN_SEQ_NUM;
+
+	if (restore) {
+		params.param0 |= DWC3_DEPCFG_ACTION_RESTORE;
+		params.param2 |= dep->saved_state;
+	}
+
+	params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN
+		| DWC3_DEPCFG_XFER_NOT_READY_EN;
+
+	if (usb_ss_max_streams(comp_desc) && usb_endpoint_xfer_bulk(desc)) {
+		params.param1 |= DWC3_DEPCFG_STREAM_CAPABLE
+			| DWC3_DEPCFG_STREAM_EVENT_EN;
+		dep->stream_capable = true;
+	}
+
+	if (!usb_endpoint_xfer_control(desc))
+		params.param1 |= DWC3_DEPCFG_XFER_IN_PROGRESS_EN;
+
+	/*
+	 * We are doing 1:1 mapping for endpoints, meaning
+	 * Physical Endpoints 2 maps to Logical Endpoint 2 and
+	 * so on. We consider the direction bit as part of the physical
+	 * endpoint number. So USB endpoint 0x81 is 0x03.
+	 */
+	params.param1 |= DWC3_DEPCFG_EP_NUMBER(dep->number);
+
+	/*
+	 * We must use the lower 16 TX FIFOs even though
+	 * HW might have more
+	 */
+	if (dep->direction)
+		params.param0 |= DWC3_DEPCFG_FIFO_NUMBER(dep->number >> 1);
+
+	if (desc->bInterval) {
+		params.param1 |= DWC3_DEPCFG_BINTERVAL_M1(desc->bInterval - 1);
+		dep->interval = 1 << (desc->bInterval - 1);
+	}
+
+	return dwc3_send_gadget_ep_cmd(dwc, dep->number,
+			DWC3_DEPCMD_SETEPCONFIG, &params);
+}
+
+static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, struct dwc3_ep *dep)
+{
+	struct dwc3_gadget_ep_cmd_params params;
+
+	memset(&params, 0x00, sizeof(params));
+
+	params.param0 = DWC3_DEPXFERCFG_NUM_XFER_RES(1);
+
+	return dwc3_send_gadget_ep_cmd(dwc, dep->number,
+			DWC3_DEPCMD_SETTRANSFRESOURCE, &params);
+}
+
+/**
+ * __dwc3_gadget_ep_enable - Initializes a HW endpoint
+ * @dep: endpoint to be initialized
+ * @desc: USB Endpoint Descriptor
+ *
+ * Caller should take care of locking
+ */
+static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
+		const struct usb_endpoint_descriptor *desc,
+		const struct usb_ss_ep_comp_descriptor *comp_desc,
+		bool ignore, bool restore)
+{
+	struct dwc3		*dwc = dep->dwc;
+	u32			reg;
+	int			ret;
+
+	dev_vdbg(dwc->dev, "Enabling %s\n", dep->name);
+
+	if (!(dep->flags & DWC3_EP_ENABLED)) {
+		ret = dwc3_gadget_start_config(dwc, dep);
+		if (ret)
+			return ret;
+	}
+
+	ret = dwc3_gadget_set_ep_config(dwc, dep, desc, comp_desc, ignore,
+			restore);
+	if (ret)
+		return ret;
+
+	if (!(dep->flags & DWC3_EP_ENABLED)) {
+		struct dwc3_trb	*trb_st_hw;
+		struct dwc3_trb	*trb_link;
+
+		ret = dwc3_gadget_set_xfer_resource(dwc, dep);
+		if (ret)
+			return ret;
+
+		dep->endpoint.desc = desc;
+		dep->comp_desc = comp_desc;
+		dep->type = usb_endpoint_type(desc);
+		dep->flags |= DWC3_EP_ENABLED;
+
+		reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
+		reg |= DWC3_DALEPENA_EP(dep->number);
+		dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
+
+		if (!usb_endpoint_xfer_isoc(desc))
+			return 0;
+
+		/* Link TRB for ISOC. The HWO bit is never reset */
+		trb_st_hw = &dep->trb_pool[0];
+
+		trb_link = &dep->trb_pool[DWC3_TRB_NUM - 1];
+		memset(trb_link, 0, sizeof(*trb_link));
+
+		trb_link->bpl = lower_32_bits(dwc3_trb_dma_offset(dep, trb_st_hw));
+		trb_link->bph = upper_32_bits(dwc3_trb_dma_offset(dep, trb_st_hw));
+		trb_link->ctrl |= DWC3_TRBCTL_LINK_TRB;
+		trb_link->ctrl |= DWC3_TRB_CTRL_HWO;
+	}
+
+	return 0;
+}
+
+static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum, bool force);
+static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep)
+{
+	struct dwc3_request		*req;
+
+	if (!list_empty(&dep->req_queued)) {
+		dwc3_stop_active_transfer(dwc, dep->number, true);
+
+		/* - giveback all requests to gadget driver */
+		while (!list_empty(&dep->req_queued)) {
+			req = next_request(&dep->req_queued);
+
+			dwc3_gadget_giveback(dep, req, -ESHUTDOWN);
+		}
+	}
+
+	while (!list_empty(&dep->request_list)) {
+		req = next_request(&dep->request_list);
+
+		dwc3_gadget_giveback(dep, req, -ESHUTDOWN);
+	}
+}
+
+/**
+ * __dwc3_gadget_ep_disable - Disables a HW endpoint
+ * @dep: the endpoint to disable
+ *
+ * This function also removes requests which are currently processed ny the
+ * hardware and those which are not yet scheduled.
+ * Caller should take care of locking.
+ */
+static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
+{
+	struct dwc3		*dwc = dep->dwc;
+	u32			reg;
+
+	dwc3_remove_requests(dwc, dep);
+
+	/* make sure HW endpoint isn't stalled */
+	if (dep->flags & DWC3_EP_STALL)
+		__dwc3_gadget_ep_set_halt(dep, 0, false);
+
+	reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
+	reg &= ~DWC3_DALEPENA_EP(dep->number);
+	dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
+
+	dep->stream_capable = false;
+	dep->endpoint.desc = NULL;
+	dep->comp_desc = NULL;
+	dep->type = 0;
+	dep->flags = 0;
+
+	return 0;
+}
+
+/* -------------------------------------------------------------------------- */
+
+static int dwc3_gadget_ep0_enable(struct usb_ep *ep,
+		const struct usb_endpoint_descriptor *desc)
+{
+	return -EINVAL;
+}
+
+static int dwc3_gadget_ep0_disable(struct usb_ep *ep)
+{
+	return -EINVAL;
+}
+
+/* -------------------------------------------------------------------------- */
+
+static int dwc3_gadget_ep_enable(struct usb_ep *ep,
+		const struct usb_endpoint_descriptor *desc)
+{
+	struct dwc3_ep			*dep;
+	struct dwc3			*dwc;
+	unsigned long			flags;
+	int				ret;
+
+	if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) {
+		pr_debug("dwc3: invalid parameters\n");
+		return -EINVAL;
+	}
+
+	if (!desc->wMaxPacketSize) {
+		pr_debug("dwc3: missing wMaxPacketSize\n");
+		return -EINVAL;
+	}
+
+	dep = to_dwc3_ep(ep);
+	dwc = dep->dwc;
+
+	if (dep->flags & DWC3_EP_ENABLED) {
+		dev_WARN_ONCE(dwc->dev, true, "%s is already enabled\n",
+				dep->name);
+		return 0;
+	}
+
+	switch (usb_endpoint_type(desc)) {
+	case USB_ENDPOINT_XFER_CONTROL:
+		strlcat(dep->name, "-control", sizeof(dep->name));
+		break;
+	case USB_ENDPOINT_XFER_ISOC:
+		strlcat(dep->name, "-isoc", sizeof(dep->name));
+		break;
+	case USB_ENDPOINT_XFER_BULK:
+		strlcat(dep->name, "-bulk", sizeof(dep->name));
+		break;
+	case USB_ENDPOINT_XFER_INT:
+		strlcat(dep->name, "-int", sizeof(dep->name));
+		break;
+	default:
+		dev_err(dwc->dev, "invalid endpoint transfer type\n");
+	}
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	ret = __dwc3_gadget_ep_enable(dep, desc, ep->comp_desc, false, false);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static int dwc3_gadget_ep_disable(struct usb_ep *ep)
+{
+	struct dwc3_ep			*dep;
+	struct dwc3			*dwc;
+	unsigned long			flags;
+	int				ret;
+
+	if (!ep) {
+		pr_debug("dwc3: invalid parameters\n");
+		return -EINVAL;
+	}
+
+	dep = to_dwc3_ep(ep);
+	dwc = dep->dwc;
+
+	if (!(dep->flags & DWC3_EP_ENABLED)) {
+		dev_WARN_ONCE(dwc->dev, true, "%s is already disabled\n",
+				dep->name);
+		return 0;
+	}
+
+	snprintf(dep->name, sizeof(dep->name), "ep%d%s",
+			dep->number >> 1,
+			(dep->number & 1) ? "in" : "out");
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	ret = __dwc3_gadget_ep_disable(dep);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static struct usb_request *dwc3_gadget_ep_alloc_request(struct usb_ep *ep,
+	gfp_t gfp_flags)
+{
+	struct dwc3_request		*req;
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+
+	req = kzalloc(sizeof(*req), gfp_flags);
+	if (!req)
+		return NULL;
+
+	req->epnum	= dep->number;
+	req->dep	= dep;
+
+	trace_dwc3_alloc_request(req);
+
+	return &req->request;
+}
+
+static void dwc3_gadget_ep_free_request(struct usb_ep *ep,
+		struct usb_request *request)
+{
+	struct dwc3_request		*req = to_dwc3_request(request);
+
+	trace_dwc3_free_request(req);
+	kfree(req);
+}
+
+/**
+ * dwc3_prepare_one_trb - setup one TRB from one request
+ * @dep: endpoint for which this request is prepared
+ * @req: dwc3_request pointer
+ */
+static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
+		struct dwc3_request *req, dma_addr_t dma,
+		unsigned length, unsigned last, unsigned chain, unsigned node)
+{
+	struct dwc3		*dwc = dep->dwc;
+	struct dwc3_trb		*trb;
+
+	dev_vdbg(dwc->dev, "%s: req %p dma %08llx length %d%s%s\n",
+			dep->name, req, (unsigned long long) dma,
+			length, last ? " last" : "",
+			chain ? " chain" : "");
+
+
+	trb = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK];
+
+	if (!req->trb) {
+		dwc3_gadget_move_request_queued(req);
+		req->trb = trb;
+		req->trb_dma = dwc3_trb_dma_offset(dep, trb);
+		req->start_slot = dep->free_slot & DWC3_TRB_MASK;
+	}
+
+	dep->free_slot++;
+	/* Skip the LINK-TRB on ISOC */
+	if (((dep->free_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) &&
+			usb_endpoint_xfer_isoc(dep->endpoint.desc))
+		dep->free_slot++;
+
+	trb->size = DWC3_TRB_SIZE_LENGTH(length);
+	trb->bpl = lower_32_bits(dma);
+	trb->bph = upper_32_bits(dma);
+
+	switch (usb_endpoint_type(dep->endpoint.desc)) {
+	case USB_ENDPOINT_XFER_CONTROL:
+		trb->ctrl = DWC3_TRBCTL_CONTROL_SETUP;
+		break;
+
+	case USB_ENDPOINT_XFER_ISOC:
+		if (!node)
+			trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS_FIRST;
+		else
+			trb->ctrl = DWC3_TRBCTL_ISOCHRONOUS;
+		break;
+
+	case USB_ENDPOINT_XFER_BULK:
+	case USB_ENDPOINT_XFER_INT:
+		trb->ctrl = DWC3_TRBCTL_NORMAL;
+		break;
+	default:
+		/*
+		 * This is only possible with faulty memory because we
+		 * checked it already :)
+		 */
+		BUG();
+	}
+
+	if (!req->request.no_interrupt && !chain)
+		trb->ctrl |= DWC3_TRB_CTRL_IOC;
+
+	if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+		trb->ctrl |= DWC3_TRB_CTRL_ISP_IMI;
+		trb->ctrl |= DWC3_TRB_CTRL_CSP;
+	} else if (last) {
+		trb->ctrl |= DWC3_TRB_CTRL_LST;
+	}
+
+	if (chain)
+		trb->ctrl |= DWC3_TRB_CTRL_CHN;
+
+	if (usb_endpoint_xfer_bulk(dep->endpoint.desc) && dep->stream_capable)
+		trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id);
+
+	trb->ctrl |= DWC3_TRB_CTRL_HWO;
+
+	trace_dwc3_prepare_trb(dep, trb);
+}
+
+/*
+ * dwc3_prepare_trbs - setup TRBs from requests
+ * @dep: endpoint for which requests are being prepared
+ * @starting: true if the endpoint is idle and no requests are queued.
+ *
+ * The function goes through the requests list and sets up TRBs for the
+ * transfers. The function returns once there are no more TRBs available or
+ * it runs out of requests.
+ */
+static void dwc3_prepare_trbs(struct dwc3_ep *dep, bool starting)
+{
+	struct dwc3_request	*req, *n;
+	u32			trbs_left;
+	u32			max;
+	unsigned int		last_one = 0;
+
+	BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM);
+
+	/* the first request must not be queued */
+	trbs_left = (dep->busy_slot - dep->free_slot) & DWC3_TRB_MASK;
+
+	/* Can't wrap around on a non-isoc EP since there's no link TRB */
+	if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+		max = DWC3_TRB_NUM - (dep->free_slot & DWC3_TRB_MASK);
+		if (trbs_left > max)
+			trbs_left = max;
+	}
+
+	/*
+	 * If busy & slot are equal than it is either full or empty. If we are
+	 * starting to process requests then we are empty. Otherwise we are
+	 * full and don't do anything
+	 */
+	if (!trbs_left) {
+		if (!starting)
+			return;
+		trbs_left = DWC3_TRB_NUM;
+		/*
+		 * In case we start from scratch, we queue the ISOC requests
+		 * starting from slot 1. This is done because we use ring
+		 * buffer and have no LST bit to stop us. Instead, we place
+		 * IOC bit every TRB_NUM/4. We try to avoid having an interrupt
+		 * after the first request so we start at slot 1 and have
+		 * 7 requests proceed before we hit the first IOC.
+		 * Other transfer types don't use the ring buffer and are
+		 * processed from the first TRB until the last one. Since we
+		 * don't wrap around we have to start at the beginning.
+		 */
+		if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+			dep->busy_slot = 1;
+			dep->free_slot = 1;
+		} else {
+			dep->busy_slot = 0;
+			dep->free_slot = 0;
+		}
+	}
+
+	/* The last TRB is a link TRB, not used for xfer */
+	if ((trbs_left <= 1) && usb_endpoint_xfer_isoc(dep->endpoint.desc))
+		return;
+
+	list_for_each_entry_safe(req, n, &dep->request_list, list) {
+		unsigned	length;
+		dma_addr_t	dma;
+		last_one = false;
+
+		if (req->request.num_mapped_sgs > 0) {
+			struct usb_request *request = &req->request;
+			struct scatterlist *sg = request->sg;
+			struct scatterlist *s;
+			int		i;
+
+			for_each_sg(sg, s, request->num_mapped_sgs, i) {
+				unsigned chain = true;
+
+				length = sg_dma_len(s);
+				dma = sg_dma_address(s);
+
+				if (i == (request->num_mapped_sgs - 1) ||
+						sg_is_last(s)) {
+					if (list_is_last(&req->list,
+							&dep->request_list))
+						last_one = true;
+					chain = false;
+				}
+
+				trbs_left--;
+				if (!trbs_left)
+					last_one = true;
+
+				if (last_one)
+					chain = false;
+
+				dwc3_prepare_one_trb(dep, req, dma, length,
+						last_one, chain, i);
+
+				if (last_one)
+					break;
+			}
+		} else {
+			dma = req->request.dma;
+			length = req->request.length;
+			trbs_left--;
+
+			if (!trbs_left)
+				last_one = 1;
+
+			/* Is this the last request? */
+			if (list_is_last(&req->list, &dep->request_list))
+				last_one = 1;
+
+			dwc3_prepare_one_trb(dep, req, dma, length,
+					last_one, false, 0);
+
+			if (last_one)
+				break;
+		}
+	}
+}
+
+static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param,
+		int start_new)
+{
+	struct dwc3_gadget_ep_cmd_params params;
+	struct dwc3_request		*req;
+	struct dwc3			*dwc = dep->dwc;
+	int				ret;
+	u32				cmd;
+
+	if (start_new && (dep->flags & DWC3_EP_BUSY)) {
+		dev_vdbg(dwc->dev, "%s: endpoint busy\n", dep->name);
+		return -EBUSY;
+	}
+	dep->flags &= ~DWC3_EP_PENDING_REQUEST;
+
+	/*
+	 * If we are getting here after a short-out-packet we don't enqueue any
+	 * new requests as we try to set the IOC bit only on the last request.
+	 */
+	if (start_new) {
+		if (list_empty(&dep->req_queued))
+			dwc3_prepare_trbs(dep, start_new);
+
+		/* req points to the first request which will be sent */
+		req = next_request(&dep->req_queued);
+	} else {
+		dwc3_prepare_trbs(dep, start_new);
+
+		/*
+		 * req points to the first request where HWO changed from 0 to 1
+		 */
+		req = next_request(&dep->req_queued);
+	}
+	if (!req) {
+		dep->flags |= DWC3_EP_PENDING_REQUEST;
+		return 0;
+	}
+
+	memset(&params, 0, sizeof(params));
+
+	if (start_new) {
+		params.param0 = upper_32_bits(req->trb_dma);
+		params.param1 = lower_32_bits(req->trb_dma);
+		cmd = DWC3_DEPCMD_STARTTRANSFER;
+	} else {
+		cmd = DWC3_DEPCMD_UPDATETRANSFER;
+	}
+
+	cmd |= DWC3_DEPCMD_PARAM(cmd_param);
+	ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params);
+	if (ret < 0) {
+		dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n");
+
+		/*
+		 * FIXME we need to iterate over the list of requests
+		 * here and stop, unmap, free and del each of the linked
+		 * requests instead of what we do now.
+		 */
+		usb_gadget_unmap_request(&dwc->gadget, &req->request,
+				req->direction);
+		list_del(&req->list);
+		return ret;
+	}
+
+	dep->flags |= DWC3_EP_BUSY;
+
+	if (start_new) {
+		dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc,
+				dep->number);
+		WARN_ON_ONCE(!dep->resource_index);
+	}
+
+	return 0;
+}
+
+static void __dwc3_gadget_start_isoc(struct dwc3 *dwc,
+		struct dwc3_ep *dep, u32 cur_uf)
+{
+	u32 uf;
+
+	if (list_empty(&dep->request_list)) {
+		dev_vdbg(dwc->dev, "ISOC ep %s run out for requests.\n",
+			dep->name);
+		dep->flags |= DWC3_EP_PENDING_REQUEST;
+		return;
+	}
+
+	/* 4 micro frames in the future */
+	uf = cur_uf + dep->interval * 4;
+
+	__dwc3_gadget_kick_transfer(dep, uf, 1);
+}
+
+static void dwc3_gadget_start_isoc(struct dwc3 *dwc,
+		struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
+{
+	u32 cur_uf, mask;
+
+	mask = ~(dep->interval - 1);
+	cur_uf = event->parameters & mask;
+
+	__dwc3_gadget_start_isoc(dwc, dep, cur_uf);
+}
+
+static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
+{
+	struct dwc3		*dwc = dep->dwc;
+	int			ret;
+
+	req->request.actual	= 0;
+	req->request.status	= -EINPROGRESS;
+	req->direction		= dep->direction;
+	req->epnum		= dep->number;
+
+	/*
+	 * We only add to our list of requests now and
+	 * start consuming the list once we get XferNotReady
+	 * IRQ.
+	 *
+	 * That way, we avoid doing anything that we don't need
+	 * to do now and defer it until the point we receive a
+	 * particular token from the Host side.
+	 *
+	 * This will also avoid Host cancelling URBs due to too
+	 * many NAKs.
+	 */
+	ret = usb_gadget_map_request(&dwc->gadget, &req->request,
+			dep->direction);
+	if (ret)
+		return ret;
+
+	list_add_tail(&req->list, &dep->request_list);
+
+	/*
+	 * There are a few special cases:
+	 *
+	 * 1. XferNotReady with empty list of requests. We need to kick the
+	 *    transfer here in that situation, otherwise we will be NAKing
+	 *    forever. If we get XferNotReady before gadget driver has a
+	 *    chance to queue a request, we will ACK the IRQ but won't be
+	 *    able to receive the data until the next request is queued.
+	 *    The following code is handling exactly that.
+	 *
+	 */
+	if (dep->flags & DWC3_EP_PENDING_REQUEST) {
+		/*
+		 * If xfernotready is already elapsed and it is a case
+		 * of isoc transfer, then issue END TRANSFER, so that
+		 * you can receive xfernotready again and can have
+		 * notion of current microframe.
+		 */
+		if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+			if (list_empty(&dep->req_queued)) {
+				dwc3_stop_active_transfer(dwc, dep->number, true);
+				dep->flags = DWC3_EP_ENABLED;
+			}
+			return 0;
+		}
+
+		ret = __dwc3_gadget_kick_transfer(dep, 0, true);
+		if (ret && ret != -EBUSY)
+			dev_dbg(dwc->dev, "%s: failed to kick transfers\n",
+					dep->name);
+		return ret;
+	}
+
+	/*
+	 * 2. XferInProgress on Isoc EP with an active transfer. We need to
+	 *    kick the transfer here after queuing a request, otherwise the
+	 *    core may not see the modified TRB(s).
+	 */
+	if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
+			(dep->flags & DWC3_EP_BUSY) &&
+			!(dep->flags & DWC3_EP_MISSED_ISOC)) {
+		WARN_ON_ONCE(!dep->resource_index);
+		ret = __dwc3_gadget_kick_transfer(dep, dep->resource_index,
+				false);
+		if (ret && ret != -EBUSY)
+			dev_dbg(dwc->dev, "%s: failed to kick transfers\n",
+					dep->name);
+		return ret;
+	}
+
+	/*
+	 * 4. Stream Capable Bulk Endpoints. We need to start the transfer
+	 * right away, otherwise host will not know we have streams to be
+	 * handled.
+	 */
+	if (dep->stream_capable) {
+		int	ret;
+
+		ret = __dwc3_gadget_kick_transfer(dep, 0, true);
+		if (ret && ret != -EBUSY) {
+			struct dwc3	*dwc = dep->dwc;
+
+			dev_dbg(dwc->dev, "%s: failed to kick transfers\n",
+					dep->name);
+		}
+	}
+
+	return 0;
+}
+
+static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
+	gfp_t gfp_flags)
+{
+	struct dwc3_request		*req = to_dwc3_request(request);
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+	struct dwc3			*dwc = dep->dwc;
+
+	unsigned long			flags;
+
+	int				ret;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	if (!dep->endpoint.desc) {
+		dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n",
+				request, ep->name);
+		ret = -ESHUTDOWN;
+		goto out;
+	}
+
+	if (WARN(req->dep != dep, "request %p belongs to '%s'\n",
+				request, req->dep->name)) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	dev_vdbg(dwc->dev, "queing request %p to %s length %d\n",
+			request, ep->name, request->length);
+	trace_dwc3_ep_queue(req);
+
+	ret = __dwc3_gadget_ep_queue(dep, req);
+
+out:
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
+		struct usb_request *request)
+{
+	struct dwc3_request		*req = to_dwc3_request(request);
+	struct dwc3_request		*r = NULL;
+
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+	struct dwc3			*dwc = dep->dwc;
+
+	unsigned long			flags;
+	int				ret = 0;
+
+	trace_dwc3_ep_dequeue(req);
+
+	spin_lock_irqsave(&dwc->lock, flags);
+
+	list_for_each_entry(r, &dep->request_list, list) {
+		if (r == req)
+			break;
+	}
+
+	if (r != req) {
+		list_for_each_entry(r, &dep->req_queued, list) {
+			if (r == req)
+				break;
+		}
+		if (r == req) {
+			/* wait until it is processed */
+			dwc3_stop_active_transfer(dwc, dep->number, true);
+			goto out1;
+		}
+		dev_err(dwc->dev, "request %p was not queued to %s\n",
+				request, ep->name);
+		ret = -EINVAL;
+		goto out0;
+	}
+
+out1:
+	/* giveback the request */
+	dwc3_gadget_giveback(dep, req, -ECONNRESET);
+
+out0:
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol)
+{
+	struct dwc3_gadget_ep_cmd_params	params;
+	struct dwc3				*dwc = dep->dwc;
+	int					ret;
+
+	if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+		dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name);
+		return -EINVAL;
+	}
+
+	memset(&params, 0x00, sizeof(params));
+
+	if (value) {
+		if (!protocol && ((dep->direction && dep->flags & DWC3_EP_BUSY) ||
+				(!list_empty(&dep->req_queued) ||
+				 !list_empty(&dep->request_list)))) {
+			dev_dbg(dwc->dev, "%s: pending request, cannot halt\n",
+					dep->name);
+			return -EAGAIN;
+		}
+
+		ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
+			DWC3_DEPCMD_SETSTALL, &params);
+		if (ret)
+			dev_err(dwc->dev, "failed to set STALL on %s\n",
+					dep->name);
+		else
+			dep->flags |= DWC3_EP_STALL;
+	} else {
+		ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
+			DWC3_DEPCMD_CLEARSTALL, &params);
+		if (ret)
+			dev_err(dwc->dev, "failed to clear STALL on %s\n",
+					dep->name);
+		else
+			dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE);
+	}
+
+	return ret;
+}
+
+static int dwc3_gadget_ep_set_halt(struct usb_ep *ep, int value)
+{
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+	struct dwc3			*dwc = dep->dwc;
+
+	unsigned long			flags;
+
+	int				ret;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	ret = __dwc3_gadget_ep_set_halt(dep, value, false);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static int dwc3_gadget_ep_set_wedge(struct usb_ep *ep)
+{
+	struct dwc3_ep			*dep = to_dwc3_ep(ep);
+	struct dwc3			*dwc = dep->dwc;
+	unsigned long			flags;
+	int				ret;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	dep->flags |= DWC3_EP_WEDGE;
+
+	if (dep->number == 0 || dep->number == 1)
+		ret = __dwc3_gadget_ep0_set_halt(ep, 1);
+	else
+		ret = __dwc3_gadget_ep_set_halt(dep, 1, false);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+/* -------------------------------------------------------------------------- */
+
+static struct usb_endpoint_descriptor dwc3_gadget_ep0_desc = {
+	.bLength	= USB_DT_ENDPOINT_SIZE,
+	.bDescriptorType = USB_DT_ENDPOINT,
+	.bmAttributes	= USB_ENDPOINT_XFER_CONTROL,
+};
+
+static const struct usb_ep_ops dwc3_gadget_ep0_ops = {
+	.enable		= dwc3_gadget_ep0_enable,
+	.disable	= dwc3_gadget_ep0_disable,
+	.alloc_request	= dwc3_gadget_ep_alloc_request,
+	.free_request	= dwc3_gadget_ep_free_request,
+	.queue		= dwc3_gadget_ep0_queue,
+	.dequeue	= dwc3_gadget_ep_dequeue,
+	.set_halt	= dwc3_gadget_ep0_set_halt,
+	.set_wedge	= dwc3_gadget_ep_set_wedge,
+};
+
+static const struct usb_ep_ops dwc3_gadget_ep_ops = {
+	.enable		= dwc3_gadget_ep_enable,
+	.disable	= dwc3_gadget_ep_disable,
+	.alloc_request	= dwc3_gadget_ep_alloc_request,
+	.free_request	= dwc3_gadget_ep_free_request,
+	.queue		= dwc3_gadget_ep_queue,
+	.dequeue	= dwc3_gadget_ep_dequeue,
+	.set_halt	= dwc3_gadget_ep_set_halt,
+	.set_wedge	= dwc3_gadget_ep_set_wedge,
+};
+
+/* -------------------------------------------------------------------------- */
+
+static int dwc3_gadget_get_frame(struct usb_gadget *g)
+{
+	struct dwc3		*dwc = gadget_to_dwc(g);
+	u32			reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+	return DWC3_DSTS_SOFFN(reg);
+}
+
+static int dwc3_gadget_wakeup(struct usb_gadget *g)
+{
+	struct dwc3		*dwc = gadget_to_dwc(g);
+
+	unsigned long		timeout;
+	unsigned long		flags;
+
+	u32			reg;
+
+	int			ret = 0;
+
+	u8			link_state;
+	u8			speed;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+
+	/*
+	 * According to the Databook Remote wakeup request should
+	 * be issued only when the device is in early suspend state.
+	 *
+	 * We can check that via USB Link State bits in DSTS register.
+	 */
+	reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+
+	speed = reg & DWC3_DSTS_CONNECTSPD;
+	if (speed == DWC3_DSTS_SUPERSPEED) {
+		dev_dbg(dwc->dev, "no wakeup on SuperSpeed\n");
+		ret = -EINVAL;
+		goto out;
+	}
+
+	link_state = DWC3_DSTS_USBLNKST(reg);
+
+	switch (link_state) {
+	case DWC3_LINK_STATE_RX_DET:	/* in HS, means Early Suspend */
+	case DWC3_LINK_STATE_U3:	/* in HS, means SUSPEND */
+		break;
+	default:
+		dev_dbg(dwc->dev, "can't wakeup from link state %d\n",
+				link_state);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	ret = dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RECOV);
+	if (ret < 0) {
+		dev_err(dwc->dev, "failed to put link in Recovery\n");
+		goto out;
+	}
+
+	/* Recent versions do this automatically */
+	if (dwc->revision < DWC3_REVISION_194A) {
+		/* write zeroes to Link Change Request */
+		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+		reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK;
+		dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	}
+
+	/* poll until Link State changes to ON */
+	timeout = jiffies + msecs_to_jiffies(100);
+
+	while (!time_after(jiffies, timeout)) {
+		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+
+		/* in HS, means ON */
+		if (DWC3_DSTS_USBLNKST(reg) == DWC3_LINK_STATE_U0)
+			break;
+	}
+
+	if (DWC3_DSTS_USBLNKST(reg) != DWC3_LINK_STATE_U0) {
+		dev_err(dwc->dev, "failed to send remote wakeup\n");
+		ret = -EINVAL;
+	}
+
+out:
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static int dwc3_gadget_set_selfpowered(struct usb_gadget *g,
+		int is_selfpowered)
+{
+	struct dwc3		*dwc = gadget_to_dwc(g);
+	unsigned long		flags;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	dwc->is_selfpowered = !!is_selfpowered;
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return 0;
+}
+
+static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
+{
+	u32			reg;
+	u32			timeout = 500;
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+	if (is_on) {
+		if (dwc->revision <= DWC3_REVISION_187A) {
+			reg &= ~DWC3_DCTL_TRGTULST_MASK;
+			reg |= DWC3_DCTL_TRGTULST_RX_DET;
+		}
+
+		if (dwc->revision >= DWC3_REVISION_194A)
+			reg &= ~DWC3_DCTL_KEEP_CONNECT;
+		reg |= DWC3_DCTL_RUN_STOP;
+
+		if (dwc->has_hibernation)
+			reg |= DWC3_DCTL_KEEP_CONNECT;
+
+		dwc->pullups_connected = true;
+	} else {
+		reg &= ~DWC3_DCTL_RUN_STOP;
+
+		if (dwc->has_hibernation && !suspend)
+			reg &= ~DWC3_DCTL_KEEP_CONNECT;
+
+		dwc->pullups_connected = false;
+	}
+
+	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+	do {
+		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+		if (is_on) {
+			if (!(reg & DWC3_DSTS_DEVCTRLHLT))
+				break;
+		} else {
+			if (reg & DWC3_DSTS_DEVCTRLHLT)
+				break;
+		}
+		timeout--;
+		if (!timeout)
+			return -ETIMEDOUT;
+		udelay(1);
+	} while (1);
+
+	dev_vdbg(dwc->dev, "gadget %s data soft-%s\n",
+			dwc->gadget_driver
+			? dwc->gadget_driver->function : "no-function",
+			is_on ? "connect" : "disconnect");
+
+	return 0;
+}
+
+static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
+{
+	struct dwc3		*dwc = gadget_to_dwc(g);
+	unsigned long		flags;
+	int			ret;
+
+	is_on = !!is_on;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+	ret = dwc3_gadget_run_stop(dwc, is_on, false);
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static void dwc3_gadget_enable_irq(struct dwc3 *dwc)
+{
+	u32			reg;
+
+	/* Enable all but Start and End of Frame IRQs */
+	reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN |
+			DWC3_DEVTEN_EVNTOVERFLOWEN |
+			DWC3_DEVTEN_CMDCMPLTEN |
+			DWC3_DEVTEN_ERRTICERREN |
+			DWC3_DEVTEN_WKUPEVTEN |
+			DWC3_DEVTEN_ULSTCNGEN |
+			DWC3_DEVTEN_CONNECTDONEEN |
+			DWC3_DEVTEN_USBRSTEN |
+			DWC3_DEVTEN_DISCONNEVTEN);
+
+	dwc3_writel(dwc->regs, DWC3_DEVTEN, reg);
+}
+
+static void dwc3_gadget_disable_irq(struct dwc3 *dwc)
+{
+	/* mask all interrupts */
+	dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
+}
+
+static irqreturn_t dwc3_interrupt(int irq, void *_dwc);
+static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc);
+
+static int dwc3_gadget_start(struct usb_gadget *g,
+		struct usb_gadget_driver *driver)
+{
+	struct dwc3		*dwc = gadget_to_dwc(g);
+	struct dwc3_ep		*dep;
+	unsigned long		flags;
+	int			ret = 0;
+	int			irq;
+	u32			reg;
+
+	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
+	ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
+			IRQF_SHARED, "dwc3", dwc);
+	if (ret) {
+		dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
+				irq, ret);
+		goto err0;
+	}
+
+	spin_lock_irqsave(&dwc->lock, flags);
+
+	if (dwc->gadget_driver) {
+		dev_err(dwc->dev, "%s is already bound to %s\n",
+				dwc->gadget.name,
+				dwc->gadget_driver->driver.name);
+		ret = -EBUSY;
+		goto err1;
+	}
+
+	dwc->gadget_driver	= driver;
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
+	reg &= ~(DWC3_DCFG_SPEED_MASK);
+
+	/**
+	 * WORKAROUND: DWC3 revision < 2.20a have an issue
+	 * which would cause metastability state on Run/Stop
+	 * bit if we try to force the IP to USB2-only mode.
+	 *
+	 * Because of that, we cannot configure the IP to any
+	 * speed other than the SuperSpeed
+	 *
+	 * Refers to:
+	 *
+	 * STAR#9000525659: Clock Domain Crossing on DCTL in
+	 * USB 2.0 Mode
+	 */
+	if (dwc->revision < DWC3_REVISION_220A) {
+		reg |= DWC3_DCFG_SUPERSPEED;
+	} else {
+		switch (dwc->maximum_speed) {
+		case USB_SPEED_LOW:
+			reg |= DWC3_DSTS_LOWSPEED;
+			break;
+		case USB_SPEED_FULL:
+			reg |= DWC3_DSTS_FULLSPEED1;
+			break;
+		case USB_SPEED_HIGH:
+			reg |= DWC3_DSTS_HIGHSPEED;
+			break;
+		case USB_SPEED_SUPER:	/* FALLTHROUGH */
+		case USB_SPEED_UNKNOWN:	/* FALTHROUGH */
+		default:
+			reg |= DWC3_DSTS_SUPERSPEED;
+		}
+	}
+	dwc3_writel(dwc->regs, DWC3_DCFG, reg);
+
+	dwc->start_config_issued = false;
+
+	/* Start with SuperSpeed Default */
+	dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
+
+	dep = dwc->eps[0];
+	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
+			false);
+	if (ret) {
+		dev_err(dwc->dev, "failed to enable %s\n", dep->name);
+		goto err2;
+	}
+
+	dep = dwc->eps[1];
+	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
+			false);
+	if (ret) {
+		dev_err(dwc->dev, "failed to enable %s\n", dep->name);
+		goto err3;
+	}
+
+	/* begin to receive SETUP packets */
+	dwc->ep0state = EP0_SETUP_PHASE;
+	dwc3_ep0_out_start(dwc);
+
+	dwc3_gadget_enable_irq(dwc);
+
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return 0;
+
+err3:
+	__dwc3_gadget_ep_disable(dwc->eps[0]);
+
+err2:
+	dwc->gadget_driver = NULL;
+
+err1:
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	free_irq(irq, dwc);
+
+err0:
+	return ret;
+}
+
+static int dwc3_gadget_stop(struct usb_gadget *g)
+{
+	struct dwc3		*dwc = gadget_to_dwc(g);
+	unsigned long		flags;
+	int			irq;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+
+	dwc3_gadget_disable_irq(dwc);
+	__dwc3_gadget_ep_disable(dwc->eps[0]);
+	__dwc3_gadget_ep_disable(dwc->eps[1]);
+
+	dwc->gadget_driver	= NULL;
+
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
+	free_irq(irq, dwc);
+
+	return 0;
+}
+
+static const struct usb_gadget_ops dwc3_gadget_ops = {
+	.get_frame		= dwc3_gadget_get_frame,
+	.wakeup			= dwc3_gadget_wakeup,
+	.set_selfpowered	= dwc3_gadget_set_selfpowered,
+	.pullup			= dwc3_gadget_pullup,
+	.udc_start		= dwc3_gadget_start,
+	.udc_stop		= dwc3_gadget_stop,
+};
+
+/* -------------------------------------------------------------------------- */
+
+static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
+		u8 num, u32 direction)
+{
+	struct dwc3_ep			*dep;
+	u8				i;
+
+	for (i = 0; i < num; i++) {
+		u8 epnum = (i << 1) | (!!direction);
+
+		dep = kzalloc(sizeof(*dep), GFP_KERNEL);
+		if (!dep)
+			return -ENOMEM;
+
+		dep->dwc = dwc;
+		dep->number = epnum;
+		dep->direction = !!direction;
+		dwc->eps[epnum] = dep;
+
+		snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1,
+				(epnum & 1) ? "in" : "out");
+
+		dep->endpoint.name = dep->name;
+
+		dev_vdbg(dwc->dev, "initializing %s\n", dep->name);
+
+		if (epnum == 0 || epnum == 1) {
+			usb_ep_set_maxpacket_limit(&dep->endpoint, 512);
+			dep->endpoint.maxburst = 1;
+			dep->endpoint.ops = &dwc3_gadget_ep0_ops;
+			if (!epnum)
+				dwc->gadget.ep0 = &dep->endpoint;
+		} else {
+			int		ret;
+
+			usb_ep_set_maxpacket_limit(&dep->endpoint, 1024);
+			dep->endpoint.max_streams = 15;
+			dep->endpoint.ops = &dwc3_gadget_ep_ops;
+			list_add_tail(&dep->endpoint.ep_list,
+					&dwc->gadget.ep_list);
+
+			ret = dwc3_alloc_trb_pool(dep);
+			if (ret)
+				return ret;
+		}
+
+		INIT_LIST_HEAD(&dep->request_list);
+		INIT_LIST_HEAD(&dep->req_queued);
+	}
+
+	return 0;
+}
+
+static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
+{
+	int				ret;
+
+	INIT_LIST_HEAD(&dwc->gadget.ep_list);
+
+	ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_out_eps, 0);
+	if (ret < 0) {
+		dev_vdbg(dwc->dev, "failed to allocate OUT endpoints\n");
+		return ret;
+	}
+
+	ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_in_eps, 1);
+	if (ret < 0) {
+		dev_vdbg(dwc->dev, "failed to allocate IN endpoints\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
+{
+	struct dwc3_ep			*dep;
+	u8				epnum;
+
+	for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
+		dep = dwc->eps[epnum];
+		if (!dep)
+			continue;
+		/*
+		 * Physical endpoints 0 and 1 are special; they form the
+		 * bi-directional USB endpoint 0.
+		 *
+		 * For those two physical endpoints, we don't allocate a TRB
+		 * pool nor do we add them the endpoints list. Due to that, we
+		 * shouldn't do these two operations otherwise we would end up
+		 * with all sorts of bugs when removing dwc3.ko.
+		 */
+		if (epnum != 0 && epnum != 1) {
+			dwc3_free_trb_pool(dep);
+			list_del(&dep->endpoint.ep_list);
+		}
+
+		kfree(dep);
+	}
+}
+
+/* -------------------------------------------------------------------------- */
+
+static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
+		struct dwc3_request *req, struct dwc3_trb *trb,
+		const struct dwc3_event_depevt *event, int status)
+{
+	unsigned int		count;
+	unsigned int		s_pkt = 0;
+	unsigned int		trb_status;
+
+	trace_dwc3_complete_trb(dep, trb);
+
+	if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN)
+		/*
+		 * We continue despite the error. There is not much we
+		 * can do. If we don't clean it up we loop forever. If
+		 * we skip the TRB then it gets overwritten after a
+		 * while since we use them in a ring buffer. A BUG()
+		 * would help. Lets hope that if this occurs, someone
+		 * fixes the root cause instead of looking away :)
+		 */
+		dev_err(dwc->dev, "%s's TRB (%p) still owned by HW\n",
+				dep->name, trb);
+	count = trb->size & DWC3_TRB_SIZE_MASK;
+
+	if (dep->direction) {
+		if (count) {
+			trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size);
+			if (trb_status == DWC3_TRBSTS_MISSED_ISOC) {
+				dev_dbg(dwc->dev, "incomplete IN transfer %s\n",
+						dep->name);
+				/*
+				 * If missed isoc occurred and there is
+				 * no request queued then issue END
+				 * TRANSFER, so that core generates
+				 * next xfernotready and we will issue
+				 * a fresh START TRANSFER.
+				 * If there are still queued request
+				 * then wait, do not issue either END
+				 * or UPDATE TRANSFER, just attach next
+				 * request in request_list during
+				 * giveback.If any future queued request
+				 * is successfully transferred then we
+				 * will issue UPDATE TRANSFER for all
+				 * request in the request_list.
+				 */
+				dep->flags |= DWC3_EP_MISSED_ISOC;
+			} else {
+				dev_err(dwc->dev, "incomplete IN transfer %s\n",
+						dep->name);
+				status = -ECONNRESET;
+			}
+		} else {
+			dep->flags &= ~DWC3_EP_MISSED_ISOC;
+		}
+	} else {
+		if (count && (event->status & DEPEVT_STATUS_SHORT))
+			s_pkt = 1;
+	}
+
+	/*
+	 * We assume here we will always receive the entire data block
+	 * which we should receive. Meaning, if we program RX to
+	 * receive 4K but we receive only 2K, we assume that's all we
+	 * should receive and we simply bounce the request back to the
+	 * gadget driver for further processing.
+	 */
+	req->request.actual += req->request.length - count;
+	if (s_pkt)
+		return 1;
+	if ((event->status & DEPEVT_STATUS_LST) &&
+			(trb->ctrl & (DWC3_TRB_CTRL_LST |
+				DWC3_TRB_CTRL_HWO)))
+		return 1;
+	if ((event->status & DEPEVT_STATUS_IOC) &&
+			(trb->ctrl & DWC3_TRB_CTRL_IOC))
+		return 1;
+	return 0;
+}
+
+static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
+		const struct dwc3_event_depevt *event, int status)
+{
+	struct dwc3_request	*req;
+	struct dwc3_trb		*trb;
+	unsigned int		slot;
+	unsigned int		i;
+	int			ret;
+
+	do {
+		req = next_request(&dep->req_queued);
+		if (!req) {
+			WARN_ON_ONCE(1);
+			return 1;
+		}
+		i = 0;
+		do {
+			slot = req->start_slot + i;
+			if ((slot == DWC3_TRB_NUM - 1) &&
+				usb_endpoint_xfer_isoc(dep->endpoint.desc))
+				slot++;
+			slot %= DWC3_TRB_NUM;
+			trb = &dep->trb_pool[slot];
+
+			ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
+					event, status);
+			if (ret)
+				break;
+		}while (++i < req->request.num_mapped_sgs);
+
+		dwc3_gadget_giveback(dep, req, status);
+
+		if (ret)
+			break;
+	} while (1);
+
+	if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
+			list_empty(&dep->req_queued)) {
+		if (list_empty(&dep->request_list)) {
+			/*
+			 * If there is no entry in request list then do
+			 * not issue END TRANSFER now. Just set PENDING
+			 * flag, so that END TRANSFER is issued when an
+			 * entry is added into request list.
+			 */
+			dep->flags = DWC3_EP_PENDING_REQUEST;
+		} else {
+			dwc3_stop_active_transfer(dwc, dep->number, true);
+			dep->flags = DWC3_EP_ENABLED;
+		}
+		return 1;
+	}
+
+	return 1;
+}
+
+static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc,
+		struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
+{
+	unsigned		status = 0;
+	int			clean_busy;
+
+	if (event->status & DEPEVT_STATUS_BUSERR)
+		status = -ECONNRESET;
+
+	clean_busy = dwc3_cleanup_done_reqs(dwc, dep, event, status);
+	if (clean_busy)
+		dep->flags &= ~DWC3_EP_BUSY;
+
+	/*
+	 * WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround.
+	 * See dwc3_gadget_linksts_change_interrupt() for 1st half.
+	 */
+	if (dwc->revision < DWC3_REVISION_183A) {
+		u32		reg;
+		int		i;
+
+		for (i = 0; i < DWC3_ENDPOINTS_NUM; i++) {
+			dep = dwc->eps[i];
+
+			if (!(dep->flags & DWC3_EP_ENABLED))
+				continue;
+
+			if (!list_empty(&dep->req_queued))
+				return;
+		}
+
+		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+		reg |= dwc->u1u2;
+		dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+		dwc->u1u2 = 0;
+	}
+}
+
+static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event)
+{
+	struct dwc3_ep		*dep;
+	u8			epnum = event->endpoint_number;
+
+	dep = dwc->eps[epnum];
+
+	if (!(dep->flags & DWC3_EP_ENABLED))
+		return;
+
+	if (epnum == 0 || epnum == 1) {
+		dwc3_ep0_interrupt(dwc, event);
+		return;
+	}
+
+	switch (event->endpoint_event) {
+	case DWC3_DEPEVT_XFERCOMPLETE:
+		dep->resource_index = 0;
+
+		if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+			dev_dbg(dwc->dev, "%s is an Isochronous endpoint\n",
+					dep->name);
+			return;
+		}
+
+		dwc3_endpoint_transfer_complete(dwc, dep, event);
+		break;
+	case DWC3_DEPEVT_XFERINPROGRESS:
+		dwc3_endpoint_transfer_complete(dwc, dep, event);
+		break;
+	case DWC3_DEPEVT_XFERNOTREADY:
+		if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+			dwc3_gadget_start_isoc(dwc, dep, event);
+		} else {
+			int ret;
+
+			dev_vdbg(dwc->dev, "%s: reason %s\n",
+					dep->name, event->status &
+					DEPEVT_STATUS_TRANSFER_ACTIVE
+					? "Transfer Active"
+					: "Transfer Not Active");
+
+			ret = __dwc3_gadget_kick_transfer(dep, 0, 1);
+			if (!ret || ret == -EBUSY)
+				return;
+
+			dev_dbg(dwc->dev, "%s: failed to kick transfers\n",
+					dep->name);
+		}
+
+		break;
+	case DWC3_DEPEVT_STREAMEVT:
+		if (!usb_endpoint_xfer_bulk(dep->endpoint.desc)) {
+			dev_err(dwc->dev, "Stream event for non-Bulk %s\n",
+					dep->name);
+			return;
+		}
+
+		switch (event->status) {
+		case DEPEVT_STREAMEVT_FOUND:
+			dev_vdbg(dwc->dev, "Stream %d found and started\n",
+					event->parameters);
+
+			break;
+		case DEPEVT_STREAMEVT_NOTFOUND:
+			/* FALLTHROUGH */
+		default:
+			dev_dbg(dwc->dev, "Couldn't find suitable stream\n");
+		}
+		break;
+	case DWC3_DEPEVT_RXTXFIFOEVT:
+		dev_dbg(dwc->dev, "%s FIFO Overrun\n", dep->name);
+		break;
+	case DWC3_DEPEVT_EPCMDCMPLT:
+		dev_vdbg(dwc->dev, "Endpoint Command Complete\n");
+		break;
+	}
+}
+
+static void dwc3_disconnect_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->disconnect) {
+		spin_unlock(&dwc->lock);
+		dwc->gadget_driver->disconnect(&dwc->gadget);
+		spin_lock(&dwc->lock);
+	}
+}
+
+static void dwc3_suspend_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->suspend) {
+		spin_unlock(&dwc->lock);
+		dwc->gadget_driver->suspend(&dwc->gadget);
+		spin_lock(&dwc->lock);
+	}
+}
+
+static void dwc3_resume_gadget(struct dwc3 *dwc)
+{
+	if (dwc->gadget_driver && dwc->gadget_driver->resume) {
+		spin_unlock(&dwc->lock);
+		dwc->gadget_driver->resume(&dwc->gadget);
+	}
+}
+
+static void dwc3_reset_gadget(struct dwc3 *dwc)
+{
+	if (!dwc->gadget_driver)
+		return;
+
+	if (dwc->gadget.speed != USB_SPEED_UNKNOWN) {
+		spin_unlock(&dwc->lock);
+		usb_gadget_udc_reset(&dwc->gadget, dwc->gadget_driver);
+		spin_lock(&dwc->lock);
+	}
+}
+
+static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum, bool force)
+{
+	struct dwc3_ep *dep;
+	struct dwc3_gadget_ep_cmd_params params;
+	u32 cmd;
+	int ret;
+
+	dep = dwc->eps[epnum];
+
+	if (!dep->resource_index)
+		return;
+
+	/*
+	 * NOTICE: We are violating what the Databook says about the
+	 * EndTransfer command. Ideally we would _always_ wait for the
+	 * EndTransfer Command Completion IRQ, but that's causing too
+	 * much trouble synchronizing between us and gadget driver.
+	 *
+	 * We have discussed this with the IP Provider and it was
+	 * suggested to giveback all requests here, but give HW some
+	 * extra time to synchronize with the interconnect. We're using
+	 * an arbitraty 100us delay for that.
+	 *
+	 * Note also that a similar handling was tested by Synopsys
+	 * (thanks a lot Paul) and nothing bad has come out of it.
+	 * In short, what we're doing is:
+	 *
+	 * - Issue EndTransfer WITH CMDIOC bit set
+	 * - Wait 100us
+	 */
+
+	cmd = DWC3_DEPCMD_ENDTRANSFER;
+	cmd |= force ? DWC3_DEPCMD_HIPRI_FORCERM : 0;
+	cmd |= DWC3_DEPCMD_CMDIOC;
+	cmd |= DWC3_DEPCMD_PARAM(dep->resource_index);
+	memset(&params, 0, sizeof(params));
+	ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params);
+	WARN_ON_ONCE(ret);
+	dep->resource_index = 0;
+	dep->flags &= ~DWC3_EP_BUSY;
+	udelay(100);
+}
+
+static void dwc3_stop_active_transfers(struct dwc3 *dwc)
+{
+	u32 epnum;
+
+	for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
+		struct dwc3_ep *dep;
+
+		dep = dwc->eps[epnum];
+		if (!dep)
+			continue;
+
+		if (!(dep->flags & DWC3_EP_ENABLED))
+			continue;
+
+		dwc3_remove_requests(dwc, dep);
+	}
+}
+
+static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)
+{
+	u32 epnum;
+
+	for (epnum = 1; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
+		struct dwc3_ep *dep;
+		struct dwc3_gadget_ep_cmd_params params;
+		int ret;
+
+		dep = dwc->eps[epnum];
+		if (!dep)
+			continue;
+
+		if (!(dep->flags & DWC3_EP_STALL))
+			continue;
+
+		dep->flags &= ~DWC3_EP_STALL;
+
+		memset(&params, 0, sizeof(params));
+		ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
+				DWC3_DEPCMD_CLEARSTALL, &params);
+		WARN_ON_ONCE(ret);
+	}
+}
+
+static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
+{
+	int			reg;
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+	reg &= ~DWC3_DCTL_INITU1ENA;
+	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+	reg &= ~DWC3_DCTL_INITU2ENA;
+	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+	dwc3_disconnect_gadget(dwc);
+	dwc->start_config_issued = false;
+
+	dwc->gadget.speed = USB_SPEED_UNKNOWN;
+	dwc->setup_packet_pending = false;
+	usb_gadget_set_state(&dwc->gadget, USB_STATE_NOTATTACHED);
+}
+
+static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
+{
+	u32			reg;
+
+	/*
+	 * WORKAROUND: DWC3 revisions <1.88a have an issue which
+	 * would cause a missing Disconnect Event if there's a
+	 * pending Setup Packet in the FIFO.
+	 *
+	 * There's no suggested workaround on the official Bug
+	 * report, which states that "unless the driver/application
+	 * is doing any special handling of a disconnect event,
+	 * there is no functional issue".
+	 *
+	 * Unfortunately, it turns out that we _do_ some special
+	 * handling of a disconnect event, namely complete all
+	 * pending transfers, notify gadget driver of the
+	 * disconnection, and so on.
+	 *
+	 * Our suggested workaround is to follow the Disconnect
+	 * Event steps here, instead, based on a setup_packet_pending
+	 * flag. Such flag gets set whenever we have a XferNotReady
+	 * event on EP0 and gets cleared on XferComplete for the
+	 * same endpoint.
+	 *
+	 * Refers to:
+	 *
+	 * STAR#9000466709: RTL: Device : Disconnect event not
+	 * generated if setup packet pending in FIFO
+	 */
+	if (dwc->revision < DWC3_REVISION_188A) {
+		if (dwc->setup_packet_pending)
+			dwc3_gadget_disconnect_interrupt(dwc);
+	}
+
+	dwc3_reset_gadget(dwc);
+
+	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+	reg &= ~DWC3_DCTL_TSTCTRL_MASK;
+	dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	dwc->test_mode = false;
+
+	dwc3_stop_active_transfers(dwc);
+	dwc3_clear_stall_all_ep(dwc);
+	dwc->start_config_issued = false;
+
+	/* Reset device address to zero */
+	reg = dwc3_readl(dwc->regs, DWC3_DCFG);
+	reg &= ~(DWC3_DCFG_DEVADDR_MASK);
+	dwc3_writel(dwc->regs, DWC3_DCFG, reg);
+}
+
+static void dwc3_update_ram_clk_sel(struct dwc3 *dwc, u32 speed)
+{
+	u32 reg;
+	u32 usb30_clock = DWC3_GCTL_CLK_BUS;
+
+	/*
+	 * We change the clock only at SS but I dunno why I would want to do
+	 * this. Maybe it becomes part of the power saving plan.
+	 */
+
+	if (speed != DWC3_DSTS_SUPERSPEED)
+		return;
+
+	/*
+	 * RAMClkSel is reset to 0 after USB reset, so it must be reprogrammed
+	 * each time on Connect Done.
+	 */
+	if (!usb30_clock)
+		return;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+	reg |= DWC3_GCTL_RAMCLKSEL(usb30_clock);
+	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+}
+
+static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
+{
+	struct dwc3_ep		*dep;
+	int			ret;
+	u32			reg;
+	u8			speed;
+
+	reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+	speed = reg & DWC3_DSTS_CONNECTSPD;
+	dwc->speed = speed;
+
+	dwc3_update_ram_clk_sel(dwc, speed);
+
+	switch (speed) {
+	case DWC3_DCFG_SUPERSPEED:
+		/*
+		 * WORKAROUND: DWC3 revisions <1.90a have an issue which
+		 * would cause a missing USB3 Reset event.
+		 *
+		 * In such situations, we should force a USB3 Reset
+		 * event by calling our dwc3_gadget_reset_interrupt()
+		 * routine.
+		 *
+		 * Refers to:
+		 *
+		 * STAR#9000483510: RTL: SS : USB3 reset event may
+		 * not be generated always when the link enters poll
+		 */
+		if (dwc->revision < DWC3_REVISION_190A)
+			dwc3_gadget_reset_interrupt(dwc);
+
+		dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
+		dwc->gadget.ep0->maxpacket = 512;
+		dwc->gadget.speed = USB_SPEED_SUPER;
+		break;
+	case DWC3_DCFG_HIGHSPEED:
+		dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64);
+		dwc->gadget.ep0->maxpacket = 64;
+		dwc->gadget.speed = USB_SPEED_HIGH;
+		break;
+	case DWC3_DCFG_FULLSPEED2:
+	case DWC3_DCFG_FULLSPEED1:
+		dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64);
+		dwc->gadget.ep0->maxpacket = 64;
+		dwc->gadget.speed = USB_SPEED_FULL;
+		break;
+	case DWC3_DCFG_LOWSPEED:
+		dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(8);
+		dwc->gadget.ep0->maxpacket = 8;
+		dwc->gadget.speed = USB_SPEED_LOW;
+		break;
+	}
+
+	/* Enable USB2 LPM Capability */
+
+	if ((dwc->revision > DWC3_REVISION_194A)
+			&& (speed != DWC3_DCFG_SUPERSPEED)) {
+		reg = dwc3_readl(dwc->regs, DWC3_DCFG);
+		reg |= DWC3_DCFG_LPM_CAP;
+		dwc3_writel(dwc->regs, DWC3_DCFG, reg);
+
+		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+		reg &= ~(DWC3_DCTL_HIRD_THRES_MASK | DWC3_DCTL_L1_HIBER_EN);
+
+		reg |= DWC3_DCTL_HIRD_THRES(dwc->hird_threshold);
+
+		/*
+		 * When dwc3 revisions >= 2.40a, LPM Erratum is enabled and
+		 * DCFG.LPMCap is set, core responses with an ACK and the
+		 * BESL value in the LPM token is less than or equal to LPM
+		 * NYET threshold.
+		 */
+		WARN_ONCE(dwc->revision < DWC3_REVISION_240A
+				&& dwc->has_lpm_erratum,
+				"LPM Erratum not available on dwc3 revisisions < 2.40a\n");
+
+		if (dwc->has_lpm_erratum && dwc->revision >= DWC3_REVISION_240A)
+			reg |= DWC3_DCTL_LPM_ERRATA(dwc->lpm_nyet_threshold);
+
+		dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	} else {
+		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+		reg &= ~DWC3_DCTL_HIRD_THRES_MASK;
+		dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+	}
+
+	dep = dwc->eps[0];
+	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, true,
+			false);
+	if (ret) {
+		dev_err(dwc->dev, "failed to enable %s\n", dep->name);
+		return;
+	}
+
+	dep = dwc->eps[1];
+	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, true,
+			false);
+	if (ret) {
+		dev_err(dwc->dev, "failed to enable %s\n", dep->name);
+		return;
+	}
+
+	/*
+	 * Configure PHY via GUSB3PIPECTLn if required.
+	 *
+	 * Update GTXFIFOSIZn
+	 *
+	 * In both cases reset values should be sufficient.
+	 */
+}
+
+static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc)
+{
+	/*
+	 * TODO take core out of low power mode when that's
+	 * implemented.
+	 */
+
+	dwc->gadget_driver->resume(&dwc->gadget);
+}
+
+static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
+		unsigned int evtinfo)
+{
+	enum dwc3_link_state	next = evtinfo & DWC3_LINK_STATE_MASK;
+	unsigned int		pwropt;
+
+	/*
+	 * WORKAROUND: DWC3 < 2.50a have an issue when configured without
+	 * Hibernation mode enabled which would show up when device detects
+	 * host-initiated U3 exit.
+	 *
+	 * In that case, device will generate a Link State Change Interrupt
+	 * from U3 to RESUME which is only necessary if Hibernation is
+	 * configured in.
+	 *
+	 * There are no functional changes due to such spurious event and we
+	 * just need to ignore it.
+	 *
+	 * Refers to:
+	 *
+	 * STAR#9000570034 RTL: SS Resume event generated in non-Hibernation
+	 * operational mode
+	 */
+	pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1);
+	if ((dwc->revision < DWC3_REVISION_250A) &&
+			(pwropt != DWC3_GHWPARAMS1_EN_PWROPT_HIB)) {
+		if ((dwc->link_state == DWC3_LINK_STATE_U3) &&
+				(next == DWC3_LINK_STATE_RESUME)) {
+			dev_vdbg(dwc->dev, "ignoring transition U3 -> Resume\n");
+			return;
+		}
+	}
+
+	/*
+	 * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending
+	 * on the link partner, the USB session might do multiple entry/exit
+	 * of low power states before a transfer takes place.
+	 *
+	 * Due to this problem, we might experience lower throughput. The
+	 * suggested workaround is to disable DCTL[12:9] bits if we're
+	 * transitioning from U1/U2 to U0 and enable those bits again
+	 * after a transfer completes and there are no pending transfers
+	 * on any of the enabled endpoints.
+	 *
+	 * This is the first half of that workaround.
+	 *
+	 * Refers to:
+	 *
+	 * STAR#9000446952: RTL: Device SS : if U1/U2 ->U0 takes >128us
+	 * core send LGO_Ux entering U0
+	 */
+	if (dwc->revision < DWC3_REVISION_183A) {
+		if (next == DWC3_LINK_STATE_U0) {
+			u32	u1u2;
+			u32	reg;
+
+			switch (dwc->link_state) {
+			case DWC3_LINK_STATE_U1:
+			case DWC3_LINK_STATE_U2:
+				reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+				u1u2 = reg & (DWC3_DCTL_INITU2ENA
+						| DWC3_DCTL_ACCEPTU2ENA
+						| DWC3_DCTL_INITU1ENA
+						| DWC3_DCTL_ACCEPTU1ENA);
+
+				if (!dwc->u1u2)
+					dwc->u1u2 = reg & u1u2;
+
+				reg &= ~u1u2;
+
+				dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+				break;
+			default:
+				/* do nothing */
+				break;
+			}
+		}
+	}
+
+	switch (next) {
+	case DWC3_LINK_STATE_U1:
+		if (dwc->speed == USB_SPEED_SUPER)
+			dwc3_suspend_gadget(dwc);
+		break;
+	case DWC3_LINK_STATE_U2:
+	case DWC3_LINK_STATE_U3:
+		dwc3_suspend_gadget(dwc);
+		break;
+	case DWC3_LINK_STATE_RESUME:
+		dwc3_resume_gadget(dwc);
+		break;
+	default:
+		/* do nothing */
+		break;
+	}
+
+	dwc->link_state = next;
+}
+
+static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc,
+		unsigned int evtinfo)
+{
+	unsigned int is_ss = evtinfo & BIT(4);
+
+	/**
+	 * WORKAROUND: DWC3 revison 2.20a with hibernation support
+	 * have a known issue which can cause USB CV TD.9.23 to fail
+	 * randomly.
+	 *
+	 * Because of this issue, core could generate bogus hibernation
+	 * events which SW needs to ignore.
+	 *
+	 * Refers to:
+	 *
+	 * STAR#9000546576: Device Mode Hibernation: Issue in USB 2.0
+	 * Device Fallback from SuperSpeed
+	 */
+	if (is_ss ^ (dwc->speed == USB_SPEED_SUPER))
+		return;
+
+	/* enter hibernation here */
+}
+
+static void dwc3_gadget_interrupt(struct dwc3 *dwc,
+		const struct dwc3_event_devt *event)
+{
+	switch (event->type) {
+	case DWC3_DEVICE_EVENT_DISCONNECT:
+		dwc3_gadget_disconnect_interrupt(dwc);
+		break;
+	case DWC3_DEVICE_EVENT_RESET:
+		dwc3_gadget_reset_interrupt(dwc);
+		break;
+	case DWC3_DEVICE_EVENT_CONNECT_DONE:
+		dwc3_gadget_conndone_interrupt(dwc);
+		break;
+	case DWC3_DEVICE_EVENT_WAKEUP:
+		dwc3_gadget_wakeup_interrupt(dwc);
+		break;
+	case DWC3_DEVICE_EVENT_HIBER_REQ:
+		if (dev_WARN_ONCE(dwc->dev, !dwc->has_hibernation,
+					"unexpected hibernation event\n"))
+			break;
+
+		dwc3_gadget_hibernation_interrupt(dwc, event->event_info);
+		break;
+	case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
+		dwc3_gadget_linksts_change_interrupt(dwc, event->event_info);
+		break;
+	case DWC3_DEVICE_EVENT_EOPF:
+		dev_vdbg(dwc->dev, "End of Periodic Frame\n");
+		break;
+	case DWC3_DEVICE_EVENT_SOF:
+		dev_vdbg(dwc->dev, "Start of Periodic Frame\n");
+		break;
+	case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
+		dev_vdbg(dwc->dev, "Erratic Error\n");
+		break;
+	case DWC3_DEVICE_EVENT_CMD_CMPL:
+		dev_vdbg(dwc->dev, "Command Complete\n");
+		break;
+	case DWC3_DEVICE_EVENT_OVERFLOW:
+		dev_vdbg(dwc->dev, "Overflow\n");
+		break;
+	default:
+		dev_dbg(dwc->dev, "UNKNOWN IRQ %d\n", event->type);
+	}
+}
+
+static void dwc3_process_event_entry(struct dwc3 *dwc,
+		const union dwc3_event *event)
+{
+	trace_dwc3_event(event->raw);
+
+	/* Endpoint IRQ, handle it and return early */
+	if (event->type.is_devspec == 0) {
+		/* depevt */
+		return dwc3_endpoint_interrupt(dwc, &event->depevt);
+	}
+
+	switch (event->type.type) {
+	case DWC3_EVENT_TYPE_DEV:
+		dwc3_gadget_interrupt(dwc, &event->devt);
+		break;
+	/* REVISIT what to do with Carkit and I2C events ? */
+	default:
+		dev_err(dwc->dev, "UNKNOWN IRQ type %d\n", event->raw);
+	}
+}
+
+static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
+{
+	struct dwc3_event_buffer *evt;
+	irqreturn_t ret = IRQ_NONE;
+	int left;
+	u32 reg;
+
+	evt = dwc->ev_buffs[buf];
+	left = evt->count;
+
+	if (!(evt->flags & DWC3_EVENT_PENDING))
+		return IRQ_NONE;
+
+	while (left > 0) {
+		union dwc3_event event;
+
+		event.raw = *(u32 *) (evt->buf + evt->lpos);
+
+		dwc3_process_event_entry(dwc, &event);
+
+		/*
+		 * FIXME we wrap around correctly to the next entry as
+		 * almost all entries are 4 bytes in size. There is one
+		 * entry which has 12 bytes which is a regular entry
+		 * followed by 8 bytes data. ATM I don't know how
+		 * things are organized if we get next to the a
+		 * boundary so I worry about that once we try to handle
+		 * that.
+		 */
+		evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
+		left -= 4;
+
+		dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4);
+	}
+
+	evt->count = 0;
+	evt->flags &= ~DWC3_EVENT_PENDING;
+	ret = IRQ_HANDLED;
+
+	/* Unmask interrupt */
+	reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
+	reg &= ~DWC3_GEVNTSIZ_INTMASK;
+	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
+
+	return ret;
+}
+
+static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc)
+{
+	struct dwc3 *dwc = _dwc;
+	unsigned long flags;
+	irqreturn_t ret = IRQ_NONE;
+	int i;
+
+	spin_lock_irqsave(&dwc->lock, flags);
+
+	for (i = 0; i < dwc->num_event_buffers; i++)
+		ret |= dwc3_process_event_buf(dwc, i);
+
+	spin_unlock_irqrestore(&dwc->lock, flags);
+
+	return ret;
+}
+
+static irqreturn_t dwc3_check_event_buf(struct dwc3 *dwc, u32 buf)
+{
+	struct dwc3_event_buffer *evt;
+	u32 count;
+	u32 reg;
+
+	evt = dwc->ev_buffs[buf];
+
+	count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf));
+	count &= DWC3_GEVNTCOUNT_MASK;
+	if (!count)
+		return IRQ_NONE;
+
+	evt->count = count;
+	evt->flags |= DWC3_EVENT_PENDING;
+
+	/* Mask interrupt */
+	reg = dwc3_readl(dwc->regs, DWC3_GEVNTSIZ(buf));
+	reg |= DWC3_GEVNTSIZ_INTMASK;
+	dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(buf), reg);
+
+	return IRQ_WAKE_THREAD;
+}
+
+static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
+{
+	struct dwc3			*dwc = _dwc;
+	int				i;
+	irqreturn_t			ret = IRQ_NONE;
+
+	spin_lock(&dwc->lock);
+
+	for (i = 0; i < dwc->num_event_buffers; i++) {
+		irqreturn_t status;
+
+		status = dwc3_check_event_buf(dwc, i);
+		if (status == IRQ_WAKE_THREAD)
+			ret = status;
+	}
+
+	spin_unlock(&dwc->lock);
+
+	return ret;
+}
+
+/**
+ * dwc3_gadget_init - Initializes gadget related registers
+ * @dwc: pointer to our controller context structure
+ *
+ * Returns 0 on success otherwise negative errno.
+ */
+int dwc3_gadget_init(struct dwc3 *dwc)
+{
+	int					ret;
+
+	dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+			&dwc->ctrl_req_addr, GFP_KERNEL);
+	if (!dwc->ctrl_req) {
+		dev_err(dwc->dev, "failed to allocate ctrl request\n");
+		ret = -ENOMEM;
+		goto err0;
+	}
+
+	dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
+			&dwc->ep0_trb_addr, GFP_KERNEL);
+	if (!dwc->ep0_trb) {
+		dev_err(dwc->dev, "failed to allocate ep0 trb\n");
+		ret = -ENOMEM;
+		goto err1;
+	}
+
+	dwc->setup_buf = kzalloc(DWC3_EP0_BOUNCE_SIZE, GFP_KERNEL);
+	if (!dwc->setup_buf) {
+		ret = -ENOMEM;
+		goto err2;
+	}
+
+	dwc->ep0_bounce = dma_alloc_coherent(dwc->dev,
+			DWC3_EP0_BOUNCE_SIZE, &dwc->ep0_bounce_addr,
+			GFP_KERNEL);
+	if (!dwc->ep0_bounce) {
+		dev_err(dwc->dev, "failed to allocate ep0 bounce buffer\n");
+		ret = -ENOMEM;
+		goto err3;
+	}
+
+	dwc->gadget.ops			= &dwc3_gadget_ops;
+	dwc->gadget.max_speed		= USB_SPEED_SUPER;
+	dwc->gadget.speed		= USB_SPEED_UNKNOWN;
+	dwc->gadget.sg_supported	= true;
+	dwc->gadget.name		= "dwc3-gadget";
+
+	/*
+	 * Per databook, DWC3 needs buffer size to be aligned to MaxPacketSize
+	 * on ep out.
+	 */
+	dwc->gadget.quirk_ep_out_aligned_size = true;
+
+	/*
+	 * REVISIT: Here we should clear all pending IRQs to be
+	 * sure we're starting from a well known location.
+	 */
+
+	ret = dwc3_gadget_init_endpoints(dwc);
+	if (ret)
+		goto err4;
+
+	ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
+	if (ret) {
+		dev_err(dwc->dev, "failed to register udc\n");
+		goto err4;
+	}
+
+	return 0;
+
+err4:
+	dwc3_gadget_free_endpoints(dwc);
+	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
+			dwc->ep0_bounce, dwc->ep0_bounce_addr);
+
+err3:
+	kfree(dwc->setup_buf);
+
+err2:
+	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
+			dwc->ep0_trb, dwc->ep0_trb_addr);
+
+err1:
+	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+			dwc->ctrl_req, dwc->ctrl_req_addr);
+
+err0:
+	return ret;
+}
+
+/* -------------------------------------------------------------------------- */
+
+void dwc3_gadget_exit(struct dwc3 *dwc)
+{
+	usb_del_gadget_udc(&dwc->gadget);
+
+	dwc3_gadget_free_endpoints(dwc);
+
+	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
+			dwc->ep0_bounce, dwc->ep0_bounce_addr);
+
+	kfree(dwc->setup_buf);
+
+	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
+			dwc->ep0_trb, dwc->ep0_trb_addr);
+
+	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
+			dwc->ctrl_req, dwc->ctrl_req_addr);
+}
+
+int dwc3_gadget_suspend(struct dwc3 *dwc)
+{
+	if (dwc->pullups_connected) {
+		dwc3_gadget_disable_irq(dwc);
+		dwc3_gadget_run_stop(dwc, true, true);
+	}
+
+	__dwc3_gadget_ep_disable(dwc->eps[0]);
+	__dwc3_gadget_ep_disable(dwc->eps[1]);
+
+	dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG);
+
+	return 0;
+}
+
+int dwc3_gadget_resume(struct dwc3 *dwc)
+{
+	struct dwc3_ep		*dep;
+	int			ret;
+
+	/* Start with SuperSpeed Default */
+	dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
+
+	dep = dwc->eps[0];
+	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
+			false);
+	if (ret)
+		goto err0;
+
+	dep = dwc->eps[1];
+	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
+			false);
+	if (ret)
+		goto err1;
+
+	/* begin to receive SETUP packets */
+	dwc->ep0state = EP0_SETUP_PHASE;
+	dwc3_ep0_out_start(dwc);
+
+	dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg);
+
+	if (dwc->pullups_connected) {
+		dwc3_gadget_enable_irq(dwc);
+		dwc3_gadget_run_stop(dwc, true, false);
+	}
+
+	return 0;
+
+err1:
+	__dwc3_gadget_ep_disable(dwc->eps[0]);
+
+err0:
+	return ret;
+}
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
new file mode 100644
index 0000000..18ae3ea
--- /dev/null
+++ b/drivers/usb/dwc3/gadget.h
@@ -0,0 +1,107 @@
+/**
+ * gadget.h - DesignWare USB3 DRD Gadget Header
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#ifndef __DRIVERS_USB_DWC3_GADGET_H
+#define __DRIVERS_USB_DWC3_GADGET_H
+
+#include <linux/list.h>
+#include <linux/usb/gadget.h>
+#include "io.h"
+
+struct dwc3;
+#define to_dwc3_ep(ep)		(container_of(ep, struct dwc3_ep, endpoint))
+#define gadget_to_dwc(g)	(container_of(g, struct dwc3, gadget))
+
+/* DEPCFG parameter 1 */
+#define DWC3_DEPCFG_INT_NUM(n)		((n) << 0)
+#define DWC3_DEPCFG_XFER_COMPLETE_EN	(1 << 8)
+#define DWC3_DEPCFG_XFER_IN_PROGRESS_EN	(1 << 9)
+#define DWC3_DEPCFG_XFER_NOT_READY_EN	(1 << 10)
+#define DWC3_DEPCFG_FIFO_ERROR_EN	(1 << 11)
+#define DWC3_DEPCFG_STREAM_EVENT_EN	(1 << 13)
+#define DWC3_DEPCFG_BINTERVAL_M1(n)	((n) << 16)
+#define DWC3_DEPCFG_STREAM_CAPABLE	(1 << 24)
+#define DWC3_DEPCFG_EP_NUMBER(n)	((n) << 25)
+#define DWC3_DEPCFG_BULK_BASED		(1 << 30)
+#define DWC3_DEPCFG_FIFO_BASED		(1 << 31)
+
+/* DEPCFG parameter 0 */
+#define DWC3_DEPCFG_EP_TYPE(n)		((n) << 1)
+#define DWC3_DEPCFG_MAX_PACKET_SIZE(n)	((n) << 3)
+#define DWC3_DEPCFG_FIFO_NUMBER(n)	((n) << 17)
+#define DWC3_DEPCFG_BURST_SIZE(n)	((n) << 22)
+#define DWC3_DEPCFG_DATA_SEQ_NUM(n)	((n) << 26)
+/* This applies for core versions earlier than 1.94a */
+#define DWC3_DEPCFG_IGN_SEQ_NUM		(1 << 31)
+/* These apply for core versions 1.94a and later */
+#define DWC3_DEPCFG_ACTION_INIT		(0 << 30)
+#define DWC3_DEPCFG_ACTION_RESTORE	(1 << 30)
+#define DWC3_DEPCFG_ACTION_MODIFY	(2 << 30)
+
+/* DEPXFERCFG parameter 0 */
+#define DWC3_DEPXFERCFG_NUM_XFER_RES(n)	((n) & 0xffff)
+
+/* -------------------------------------------------------------------------- */
+
+#define to_dwc3_request(r)	(container_of(r, struct dwc3_request, request))
+
+static inline struct dwc3_request *next_request(struct list_head *list)
+{
+	if (list_empty(list))
+		return NULL;
+
+	return list_first_entry(list, struct dwc3_request, list);
+}
+
+static inline void dwc3_gadget_move_request_queued(struct dwc3_request *req)
+{
+	struct dwc3_ep		*dep = req->dep;
+
+	req->queued = true;
+	list_move_tail(&req->list, &dep->req_queued);
+}
+
+void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
+		int status);
+
+void dwc3_ep0_interrupt(struct dwc3 *dwc,
+		const struct dwc3_event_depevt *event);
+void dwc3_ep0_out_start(struct dwc3 *dwc);
+int __dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value);
+int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value);
+int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
+		gfp_t gfp_flags);
+int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol);
+
+/**
+ * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
+ * @dwc: DesignWare USB3 Pointer
+ * @number: DWC endpoint number
+ *
+ * Caller should take care of locking
+ */
+static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number)
+{
+	u32			res_id;
+
+	res_id = dwc3_readl(dwc->regs, DWC3_DEPCMD(number));
+
+	return DWC3_DEPCMD_GET_RSC_IDX(res_id);
+}
+
+#endif /* __DRIVERS_USB_DWC3_GADGET_H */
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
new file mode 100644
index 0000000..12bfd3c
--- /dev/null
+++ b/drivers/usb/dwc3/host.c
@@ -0,0 +1,91 @@
+/**
+ * host.c - DesignWare USB3 DRD Controller Host Glue
+ *
+ * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/usb/xhci_pdriver.h>
+
+#include "core.h"
+
+int dwc3_host_init(struct dwc3 *dwc)
+{
+	struct platform_device	*xhci;
+	struct usb_xhci_pdata	pdata;
+	int			ret;
+
+	xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
+	if (!xhci) {
+		dev_err(dwc->dev, "couldn't allocate xHCI device\n");
+		return -ENOMEM;
+	}
+
+	dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
+
+	xhci->dev.parent	= dwc->dev;
+	xhci->dev.dma_mask	= dwc->dev->dma_mask;
+	xhci->dev.dma_parms	= dwc->dev->dma_parms;
+
+	dwc->xhci = xhci;
+
+	ret = platform_device_add_resources(xhci, dwc->xhci_resources,
+						DWC3_XHCI_RESOURCES_NUM);
+	if (ret) {
+		dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
+		goto err1;
+	}
+
+	memset(&pdata, 0, sizeof(pdata));
+
+#ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE
+	pdata.usb3_lpm_capable = 1;
+#endif
+
+	ret = platform_device_add_data(xhci, &pdata, sizeof(pdata));
+	if (ret) {
+		dev_err(dwc->dev, "couldn't add platform data to xHCI device\n");
+		goto err1;
+	}
+
+	phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
+			  dev_name(&xhci->dev));
+	phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
+			  dev_name(&xhci->dev));
+
+	ret = platform_device_add(xhci);
+	if (ret) {
+		dev_err(dwc->dev, "failed to register xHCI device\n");
+		goto err2;
+	}
+
+	return 0;
+err2:
+	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
+			  dev_name(&xhci->dev));
+	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
+			  dev_name(&xhci->dev));
+err1:
+	platform_device_put(xhci);
+	return ret;
+}
+
+void dwc3_host_exit(struct dwc3 *dwc)
+{
+	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
+			  dev_name(&dwc->xhci->dev));
+	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
+			  dev_name(&dwc->xhci->dev));
+	platform_device_unregister(dwc->xhci);
+}
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
new file mode 100644
index 0000000..6a79c8e
--- /dev/null
+++ b/drivers/usb/dwc3/io.h
@@ -0,0 +1,70 @@
+/**
+ * io.h - DesignWare USB3 DRD IO Header
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Felipe Balbi <balbi@ti.com>,
+ *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#ifndef __DRIVERS_USB_DWC3_IO_H
+#define __DRIVERS_USB_DWC3_IO_H
+
+#include <linux/io.h>
+#include "trace.h"
+#include "debug.h"
+#include "core.h"
+
+static inline u32 dwc3_readl(void __iomem *base, u32 offset)
+{
+	u32 offs = offset - DWC3_GLOBALS_REGS_START;
+	u32 value;
+
+	/*
+	 * We requested the mem region starting from the Globals address
+	 * space, see dwc3_probe in core.c.
+	 * However, the offsets are given starting from xHCI address space.
+	 */
+	value = readl(base + offs);
+
+	/*
+	 * When tracing we want to make it easy to find the correct address on
+	 * documentation, so we revert it back to the proper addresses, the
+	 * same way they are described on SNPS documentation
+	 */
+	dwc3_trace(trace_dwc3_readl, "addr %p value %08x",
+			base - DWC3_GLOBALS_REGS_START + offset, value);
+
+	return value;
+}
+
+static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
+{
+	u32 offs = offset - DWC3_GLOBALS_REGS_START;
+
+	/*
+	 * We requested the mem region starting from the Globals address
+	 * space, see dwc3_probe in core.c.
+	 * However, the offsets are given starting from xHCI address space.
+	 */
+	writel(value, base + offs);
+
+	/*
+	 * When tracing we want to make it easy to find the correct address on
+	 * documentation, so we revert it back to the proper addresses, the
+	 * same way they are described on SNPS documentation
+	 */
+	dwc3_trace(trace_dwc3_writel, "addr %p value %08x",
+			base - DWC3_GLOBALS_REGS_START + offset, value);
+}
+
+#endif /* __DRIVERS_USB_DWC3_IO_H */
diff --git a/drivers/usb/dwc3/platform_data.h b/drivers/usb/dwc3/platform_data.h
new file mode 100644
index 0000000..a3a3b6d
--- /dev/null
+++ b/drivers/usb/dwc3/platform_data.h
@@ -0,0 +1,47 @@
+/**
+ * platform_data.h - USB DWC3 Platform Data Support
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Felipe Balbi <balbi@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/otg.h>
+
+struct dwc3_platform_data {
+	enum usb_device_speed maximum_speed;
+	enum usb_dr_mode dr_mode;
+	bool tx_fifo_resize;
+
+	unsigned is_utmi_l1_suspend:1;
+	u8 hird_threshold;
+
+	u8 lpm_nyet_threshold;
+
+	unsigned disable_scramble_quirk:1;
+	unsigned has_lpm_erratum:1;
+	unsigned u2exit_lfps_quirk:1;
+	unsigned u2ss_inp3_quirk:1;
+	unsigned req_p1p2p3_quirk:1;
+	unsigned del_p1p2p3_quirk:1;
+	unsigned del_phy_power_chg_quirk:1;
+	unsigned lfps_filter_quirk:1;
+	unsigned rx_detect_poll_quirk:1;
+	unsigned dis_u3_susphy_quirk:1;
+	unsigned dis_u2_susphy_quirk:1;
+
+	unsigned tx_de_emphasis_quirk:1;
+	unsigned tx_de_emphasis:2;
+};
diff --git a/drivers/usb/dwc3/trace.c b/drivers/usb/dwc3/trace.c
new file mode 100644
index 0000000..6cd1664
--- /dev/null
+++ b/drivers/usb/dwc3/trace.c
@@ -0,0 +1,19 @@
+/**
+ * trace.c - DesignWare USB3 DRD Controller Trace Support
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author: Felipe Balbi <balbi@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#define CREATE_TRACE_POINTS
+#include "trace.h"
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
new file mode 100644
index 0000000..9fc20b3
--- /dev/null
+++ b/drivers/usb/dwc3/trace.h
@@ -0,0 +1,247 @@
+/**
+ * trace.h - DesignWare USB3 DRD Controller Trace Support
+ *
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author: Felipe Balbi <balbi@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM dwc3
+
+#if !defined(__DWC3_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
+#define __DWC3_TRACE_H
+
+#include <linux/types.h>
+#include <linux/tracepoint.h>
+#include <asm/byteorder.h>
+#include "core.h"
+#include "debug.h"
+
+DECLARE_EVENT_CLASS(dwc3_log_msg,
+	TP_PROTO(struct va_format *vaf),
+	TP_ARGS(vaf),
+	TP_STRUCT__entry(__dynamic_array(char, msg, DWC3_MSG_MAX)),
+	TP_fast_assign(
+		vsnprintf(__get_str(msg), DWC3_MSG_MAX, vaf->fmt, *vaf->va);
+	),
+	TP_printk("%s", __get_str(msg))
+);
+
+DEFINE_EVENT(dwc3_log_msg, dwc3_readl,
+	TP_PROTO(struct va_format *vaf),
+	TP_ARGS(vaf)
+);
+
+DEFINE_EVENT(dwc3_log_msg, dwc3_writel,
+	TP_PROTO(struct va_format *vaf),
+	TP_ARGS(vaf)
+);
+
+DEFINE_EVENT(dwc3_log_msg, dwc3_ep0,
+	TP_PROTO(struct va_format *vaf),
+	TP_ARGS(vaf)
+);
+
+DECLARE_EVENT_CLASS(dwc3_log_event,
+	TP_PROTO(u32 event),
+	TP_ARGS(event),
+	TP_STRUCT__entry(
+		__field(u32, event)
+	),
+	TP_fast_assign(
+		__entry->event = event;
+	),
+	TP_printk("event %08x", __entry->event)
+);
+
+DEFINE_EVENT(dwc3_log_event, dwc3_event,
+	TP_PROTO(u32 event),
+	TP_ARGS(event)
+);
+
+DECLARE_EVENT_CLASS(dwc3_log_ctrl,
+	TP_PROTO(struct usb_ctrlrequest *ctrl),
+	TP_ARGS(ctrl),
+	TP_STRUCT__entry(
+		__field(__u8, bRequestType)
+		__field(__u8, bRequest)
+		__field(__le16, wValue)
+		__field(__le16, wIndex)
+		__field(__le16, wLength)
+	),
+	TP_fast_assign(
+		__entry->bRequestType = ctrl->bRequestType;
+		__entry->bRequest = ctrl->bRequest;
+		__entry->wValue = ctrl->wValue;
+		__entry->wIndex = ctrl->wIndex;
+		__entry->wLength = ctrl->wLength;
+	),
+	TP_printk("bRequestType %02x bRequest %02x wValue %04x wIndex %04x wLength %d",
+		__entry->bRequestType, __entry->bRequest,
+		le16_to_cpu(__entry->wValue), le16_to_cpu(__entry->wIndex),
+		le16_to_cpu(__entry->wLength)
+	)
+);
+
+DEFINE_EVENT(dwc3_log_ctrl, dwc3_ctrl_req,
+	TP_PROTO(struct usb_ctrlrequest *ctrl),
+	TP_ARGS(ctrl)
+);
+
+DECLARE_EVENT_CLASS(dwc3_log_request,
+	TP_PROTO(struct dwc3_request *req),
+	TP_ARGS(req),
+	TP_STRUCT__entry(
+		__dynamic_array(char, name, DWC3_MSG_MAX)
+		__field(struct dwc3_request *, req)
+		__field(unsigned, actual)
+		__field(unsigned, length)
+		__field(int, status)
+	),
+	TP_fast_assign(
+		snprintf(__get_str(name), DWC3_MSG_MAX, "%s", req->dep->name);
+		__entry->req = req;
+		__entry->actual = req->request.actual;
+		__entry->length = req->request.length;
+		__entry->status = req->request.status;
+	),
+	TP_printk("%s: req %p length %u/%u ==> %d",
+		__get_str(name), __entry->req, __entry->actual, __entry->length,
+		__entry->status
+	)
+);
+
+DEFINE_EVENT(dwc3_log_request, dwc3_alloc_request,
+	TP_PROTO(struct dwc3_request *req),
+	TP_ARGS(req)
+);
+
+DEFINE_EVENT(dwc3_log_request, dwc3_free_request,
+	TP_PROTO(struct dwc3_request *req),
+	TP_ARGS(req)
+);
+
+DEFINE_EVENT(dwc3_log_request, dwc3_ep_queue,
+	TP_PROTO(struct dwc3_request *req),
+	TP_ARGS(req)
+);
+
+DEFINE_EVENT(dwc3_log_request, dwc3_ep_dequeue,
+	TP_PROTO(struct dwc3_request *req),
+	TP_ARGS(req)
+);
+
+DEFINE_EVENT(dwc3_log_request, dwc3_gadget_giveback,
+	TP_PROTO(struct dwc3_request *req),
+	TP_ARGS(req)
+);
+
+DECLARE_EVENT_CLASS(dwc3_log_generic_cmd,
+	TP_PROTO(unsigned int cmd, u32 param),
+	TP_ARGS(cmd, param),
+	TP_STRUCT__entry(
+		__field(unsigned int, cmd)
+		__field(u32, param)
+	),
+	TP_fast_assign(
+		__entry->cmd = cmd;
+		__entry->param = param;
+	),
+	TP_printk("cmd '%s' [%d] param %08x",
+		dwc3_gadget_generic_cmd_string(__entry->cmd),
+		__entry->cmd, __entry->param
+	)
+);
+
+DEFINE_EVENT(dwc3_log_generic_cmd, dwc3_gadget_generic_cmd,
+	TP_PROTO(unsigned int cmd, u32 param),
+	TP_ARGS(cmd, param)
+);
+
+DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd,
+	TP_PROTO(struct dwc3_ep *dep, unsigned int cmd,
+		struct dwc3_gadget_ep_cmd_params *params),
+	TP_ARGS(dep, cmd, params),
+	TP_STRUCT__entry(
+		__dynamic_array(char, name, DWC3_MSG_MAX)
+		__field(unsigned int, cmd)
+		__field(u32, param0)
+		__field(u32, param1)
+		__field(u32, param2)
+	),
+	TP_fast_assign(
+		snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name);
+		__entry->cmd = cmd;
+		__entry->param0 = params->param0;
+		__entry->param1 = params->param1;
+		__entry->param2 = params->param2;
+	),
+	TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x",
+		__get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd),
+		__entry->cmd, __entry->param0,
+		__entry->param1, __entry->param2
+	)
+);
+
+DEFINE_EVENT(dwc3_log_gadget_ep_cmd, dwc3_gadget_ep_cmd,
+	TP_PROTO(struct dwc3_ep *dep, unsigned int cmd,
+		struct dwc3_gadget_ep_cmd_params *params),
+	TP_ARGS(dep, cmd, params)
+);
+
+DECLARE_EVENT_CLASS(dwc3_log_trb,
+	TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
+	TP_ARGS(dep, trb),
+	TP_STRUCT__entry(
+		__dynamic_array(char, name, DWC3_MSG_MAX)
+		__field(struct dwc3_trb *, trb)
+		__field(u32, bpl)
+		__field(u32, bph)
+		__field(u32, size)
+		__field(u32, ctrl)
+	),
+	TP_fast_assign(
+		snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name);
+		__entry->trb = trb;
+		__entry->bpl = trb->bpl;
+		__entry->bph = trb->bph;
+		__entry->size = trb->size;
+		__entry->ctrl = trb->ctrl;
+	),
+	TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x",
+		__get_str(name), __entry->trb, __entry->bph, __entry->bpl,
+		__entry->size, __entry->ctrl
+	)
+);
+
+DEFINE_EVENT(dwc3_log_trb, dwc3_prepare_trb,
+	TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
+	TP_ARGS(dep, trb)
+);
+
+DEFINE_EVENT(dwc3_log_trb, dwc3_complete_trb,
+	TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
+	TP_ARGS(dep, trb)
+);
+
+#endif /* __DWC3_TRACE_H */
+
+/* this part has to be here */
+
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE trace
+
+#include <trace/define_trace.h>
-- 
1.7.9.5

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

* [U-Boot] [u-boot 08/40] usb: dwc3: remove un-used files from dwc3 folder
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (6 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 07/40] usb: dwc3: add dwc3 folder from linux kernel to u-boot Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:21   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 09/40] usb: dwc3: Modify the file headers to u-boot format Kishon Vijay Abraham I
                   ` (32 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

removed un-used/un-supported files from dwc3. These files can be added
later as and when the support is added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/Kconfig         |  120 -------
 drivers/usb/dwc3/debug.c         |   32 --
 drivers/usb/dwc3/debug.h         |  228 -------------
 drivers/usb/dwc3/debugfs.c       |  690 --------------------------------------
 drivers/usb/dwc3/dwc3-exynos.c   |  301 -----------------
 drivers/usb/dwc3/dwc3-keystone.c |  197 -----------
 drivers/usb/dwc3/dwc3-pci.c      |  272 ---------------
 drivers/usb/dwc3/dwc3-qcom.c     |  130 -------
 drivers/usb/dwc3/dwc3-st.c       |  367 --------------------
 drivers/usb/dwc3/host.c          |   91 -----
 drivers/usb/dwc3/platform_data.h |   47 ---
 drivers/usb/dwc3/trace.c         |   19 --
 drivers/usb/dwc3/trace.h         |  247 --------------
 13 files changed, 2741 deletions(-)
 delete mode 100644 drivers/usb/dwc3/Kconfig
 delete mode 100644 drivers/usb/dwc3/debug.c
 delete mode 100644 drivers/usb/dwc3/debug.h
 delete mode 100644 drivers/usb/dwc3/debugfs.c
 delete mode 100644 drivers/usb/dwc3/dwc3-exynos.c
 delete mode 100644 drivers/usb/dwc3/dwc3-keystone.c
 delete mode 100644 drivers/usb/dwc3/dwc3-pci.c
 delete mode 100644 drivers/usb/dwc3/dwc3-qcom.c
 delete mode 100644 drivers/usb/dwc3/dwc3-st.c
 delete mode 100644 drivers/usb/dwc3/host.c
 delete mode 100644 drivers/usb/dwc3/platform_data.h
 delete mode 100644 drivers/usb/dwc3/trace.c
 delete mode 100644 drivers/usb/dwc3/trace.h

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
deleted file mode 100644
index 58b5b2c..0000000
--- a/drivers/usb/dwc3/Kconfig
+++ /dev/null
@@ -1,120 +0,0 @@
-config USB_DWC3
-	tristate "DesignWare USB3 DRD Core Support"
-	depends on (USB || USB_GADGET) && HAS_DMA
-	select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD
-	help
-	  Say Y or M here if your system has a Dual Role SuperSpeed
-	  USB controller based on the DesignWare USB3 IP Core.
-
-	  If you choose to build this driver is a dynamically linked
-	  module, the module will be called dwc3.ko.
-
-if USB_DWC3
-
-choice
-	bool "DWC3 Mode Selection"
-	default USB_DWC3_DUAL_ROLE if (USB && USB_GADGET)
-	default USB_DWC3_HOST if (USB && !USB_GADGET)
-	default USB_DWC3_GADGET if (!USB && USB_GADGET)
-
-config USB_DWC3_HOST
-	bool "Host only mode"
-	depends on USB=y || USB=USB_DWC3
-	help
-	  Select this when you want to use DWC3 in host mode only,
-	  thereby the gadget feature will be regressed.
-
-config USB_DWC3_GADGET
-	bool "Gadget only mode"
-	depends on USB_GADGET=y || USB_GADGET=USB_DWC3
-	help
-	  Select this when you want to use DWC3 in gadget mode only,
-	  thereby the host feature will be regressed.
-
-config USB_DWC3_DUAL_ROLE
-	bool "Dual Role mode"
-	depends on ((USB=y || USB=USB_DWC3) && (USB_GADGET=y || USB_GADGET=USB_DWC3))
-	help
-	  This is the default mode of working of DWC3 controller where
-	  both host and gadget features are enabled.
-
-endchoice
-
-comment "Platform Glue Driver Support"
-
-config USB_DWC3_OMAP
-	tristate "Texas Instruments OMAP5 and similar Platforms"
-	depends on EXTCON && (ARCH_OMAP2PLUS || COMPILE_TEST)
-	depends on OF
-	default USB_DWC3
-	help
-	  Some platforms from Texas Instruments like OMAP5, DRA7xxx and
-	  AM437x use this IP for USB2/3 functionality.
-
-	  Say 'Y' or 'M' here if you have one such device
-
-config USB_DWC3_EXYNOS
-	tristate "Samsung Exynos Platform"
-	depends on ARCH_EXYNOS && OF || COMPILE_TEST
-	default USB_DWC3
-	help
-	  Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside,
-	  say 'Y' or 'M' if you have one such device.
-
-config USB_DWC3_PCI
-	tristate "PCIe-based Platforms"
-	depends on PCI
-	default USB_DWC3
-	help
-	  If you're using the DesignWare Core IP with a PCIe, please say
-	  'Y' or 'M' here.
-
-	  One such PCIe-based platform is Synopsys' PCIe HAPS model of
-	  this IP.
-
-config USB_DWC3_KEYSTONE
-	tristate "Texas Instruments Keystone2 Platforms"
-	depends on ARCH_KEYSTONE || COMPILE_TEST
-	default USB_DWC3
-	help
-	  Support of USB2/3 functionality in TI Keystone2 platforms.
-	  Say 'Y' or 'M' here if you have one such device
-
-config USB_DWC3_ST
-	tristate "STMicroelectronics Platforms"
-	depends on ARCH_STI && OF
-	default USB_DWC3
-	help
-	  STMicroelectronics SoCs with one DesignWare Core USB3 IP
-	  inside (i.e. STiH407).
-	  Say 'Y' or 'M' if you have one such device.
-
-config USB_DWC3_QCOM
-	tristate "Qualcomm Platforms"
-	depends on ARCH_QCOM || COMPILE_TEST
-	default USB_DWC3
-	help
-	  Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside,
-	  say 'Y' or 'M' if you have one such device.
-
-comment "Debugging features"
-
-config USB_DWC3_DEBUG
-	bool "Enable Debugging Messages"
-	help
-	  Say Y here to enable debugging messages on DWC3 Driver.
-
-config USB_DWC3_VERBOSE
-	bool "Enable Verbose Debugging Messages"
-	depends on USB_DWC3_DEBUG
-	help
-	  Say Y here to enable verbose debugging messages on DWC3 Driver.
-
-config DWC3_HOST_USB3_LPM_ENABLE
-	bool "Enable USB3 LPM Capability"
-	depends on USB_DWC3_HOST=y || USB_DWC3_DUAL_ROLE=y
-	default n
-	help
-	  Select this when you want to enable USB3 LPM with dwc3 xhci host.
-
-endif
diff --git a/drivers/usb/dwc3/debug.c b/drivers/usb/dwc3/debug.c
deleted file mode 100644
index 0be6885..0000000
--- a/drivers/usb/dwc3/debug.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * debug.c - DesignWare USB3 DRD Controller Debug/Trace Support
- *
- * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
- *
- * Author: Felipe Balbi <balbi@ti.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#include "debug.h"
-
-void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...)
-{
-	struct va_format vaf;
-	va_list args;
-
-	va_start(args, fmt);
-	vaf.fmt = fmt;
-	vaf.va = &args;
-
-	trace(&vaf);
-
-	va_end(args);
-}
diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
deleted file mode 100644
index 07fbc2d..0000000
--- a/drivers/usb/dwc3/debug.h
+++ /dev/null
@@ -1,228 +0,0 @@
-/**
- * debug.h - DesignWare USB3 DRD Controller Debug Header
- *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
- *
- * Authors: Felipe Balbi <balbi@ti.com>,
- *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#ifndef __DWC3_DEBUG_H
-#define __DWC3_DEBUG_H
-
-#include "core.h"
-
-/**
- * dwc3_gadget_ep_cmd_string - returns endpoint command string
- * @cmd: command code
- */
-static inline const char *
-dwc3_gadget_ep_cmd_string(u8 cmd)
-{
-	switch (cmd) {
-	case DWC3_DEPCMD_DEPSTARTCFG:
-		return "Start New Configuration";
-	case DWC3_DEPCMD_ENDTRANSFER:
-		return "End Transfer";
-	case DWC3_DEPCMD_UPDATETRANSFER:
-		return "Update Transfer";
-	case DWC3_DEPCMD_STARTTRANSFER:
-		return "Start Transfer";
-	case DWC3_DEPCMD_CLEARSTALL:
-		return "Clear Stall";
-	case DWC3_DEPCMD_SETSTALL:
-		return "Set Stall";
-	case DWC3_DEPCMD_GETEPSTATE:
-		return "Get Endpoint State";
-	case DWC3_DEPCMD_SETTRANSFRESOURCE:
-		return "Set Endpoint Transfer Resource";
-	case DWC3_DEPCMD_SETEPCONFIG:
-		return "Set Endpoint Configuration";
-	default:
-		return "UNKNOWN command";
-	}
-}
-
-/**
- * dwc3_gadget_generic_cmd_string - returns generic command string
- * @cmd: command code
- */
-static inline const char *
-dwc3_gadget_generic_cmd_string(u8 cmd)
-{
-	switch (cmd) {
-	case DWC3_DGCMD_SET_LMP:
-		return "Set LMP";
-	case DWC3_DGCMD_SET_PERIODIC_PAR:
-		return "Set Periodic Parameters";
-	case DWC3_DGCMD_XMIT_FUNCTION:
-		return "Transmit Function Wake Device Notification";
-	case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
-		return "Set Scratchpad Buffer Array Address Lo";
-	case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
-		return "Set Scratchpad Buffer Array Address Hi";
-	case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
-		return "Selected FIFO Flush";
-	case DWC3_DGCMD_ALL_FIFO_FLUSH:
-		return "All FIFO Flush";
-	case DWC3_DGCMD_SET_ENDPOINT_NRDY:
-		return "Set Endpoint NRDY";
-	case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
-		return "Run SoC Bus Loopback Test";
-	default:
-		return "UNKNOWN";
-	}
-}
-
-/**
- * dwc3_gadget_link_string - returns link name
- * @link_state: link state code
- */
-static inline const char *
-dwc3_gadget_link_string(enum dwc3_link_state link_state)
-{
-	switch (link_state) {
-	case DWC3_LINK_STATE_U0:
-		return "U0";
-	case DWC3_LINK_STATE_U1:
-		return "U1";
-	case DWC3_LINK_STATE_U2:
-		return "U2";
-	case DWC3_LINK_STATE_U3:
-		return "U3";
-	case DWC3_LINK_STATE_SS_DIS:
-		return "SS.Disabled";
-	case DWC3_LINK_STATE_RX_DET:
-		return "RX.Detect";
-	case DWC3_LINK_STATE_SS_INACT:
-		return "SS.Inactive";
-	case DWC3_LINK_STATE_POLL:
-		return "Polling";
-	case DWC3_LINK_STATE_RECOV:
-		return "Recovery";
-	case DWC3_LINK_STATE_HRESET:
-		return "Hot Reset";
-	case DWC3_LINK_STATE_CMPLY:
-		return "Compliance";
-	case DWC3_LINK_STATE_LPBK:
-		return "Loopback";
-	case DWC3_LINK_STATE_RESET:
-		return "Reset";
-	case DWC3_LINK_STATE_RESUME:
-		return "Resume";
-	default:
-		return "UNKNOWN link state\n";
-	}
-}
-
-/**
- * dwc3_gadget_event_string - returns event name
- * @event: the event code
- */
-static inline const char *dwc3_gadget_event_string(u8 event)
-{
-	switch (event) {
-	case DWC3_DEVICE_EVENT_DISCONNECT:
-		return "Disconnect";
-	case DWC3_DEVICE_EVENT_RESET:
-		return "Reset";
-	case DWC3_DEVICE_EVENT_CONNECT_DONE:
-		return "Connection Done";
-	case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
-		return "Link Status Change";
-	case DWC3_DEVICE_EVENT_WAKEUP:
-		return "WakeUp";
-	case DWC3_DEVICE_EVENT_EOPF:
-		return "End-Of-Frame";
-	case DWC3_DEVICE_EVENT_SOF:
-		return "Start-Of-Frame";
-	case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
-		return "Erratic Error";
-	case DWC3_DEVICE_EVENT_CMD_CMPL:
-		return "Command Complete";
-	case DWC3_DEVICE_EVENT_OVERFLOW:
-		return "Overflow";
-	}
-
-	return "UNKNOWN";
-}
-
-/**
- * dwc3_ep_event_string - returns event name
- * @event: then event code
- */
-static inline const char *dwc3_ep_event_string(u8 event)
-{
-	switch (event) {
-	case DWC3_DEPEVT_XFERCOMPLETE:
-		return "Transfer Complete";
-	case DWC3_DEPEVT_XFERINPROGRESS:
-		return "Transfer In-Progress";
-	case DWC3_DEPEVT_XFERNOTREADY:
-		return "Transfer Not Ready";
-	case DWC3_DEPEVT_RXTXFIFOEVT:
-		return "FIFO";
-	case DWC3_DEPEVT_STREAMEVT:
-		return "Stream";
-	case DWC3_DEPEVT_EPCMDCMPLT:
-		return "Endpoint Command Complete";
-	}
-
-	return "UNKNOWN";
-}
-
-/**
- * dwc3_gadget_event_type_string - return event name
- * @event: the event code
- */
-static inline const char *dwc3_gadget_event_type_string(u8 event)
-{
-	switch (event) {
-	case DWC3_DEVICE_EVENT_DISCONNECT:
-		return "Disconnect";
-	case DWC3_DEVICE_EVENT_RESET:
-		return "Reset";
-	case DWC3_DEVICE_EVENT_CONNECT_DONE:
-		return "Connect Done";
-	case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
-		return "Link Status Change";
-	case DWC3_DEVICE_EVENT_WAKEUP:
-		return "Wake-Up";
-	case DWC3_DEVICE_EVENT_HIBER_REQ:
-		return "Hibernation";
-	case DWC3_DEVICE_EVENT_EOPF:
-		return "End of Periodic Frame";
-	case DWC3_DEVICE_EVENT_SOF:
-		return "Start of Frame";
-	case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
-		return "Erratic Error";
-	case DWC3_DEVICE_EVENT_CMD_CMPL:
-		return "Command Complete";
-	case DWC3_DEVICE_EVENT_OVERFLOW:
-		return "Overflow";
-	default:
-		return "UNKNOWN";
-	}
-}
-
-void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
-
-#ifdef CONFIG_DEBUG_FS
-extern int dwc3_debugfs_init(struct dwc3 *);
-extern void dwc3_debugfs_exit(struct dwc3 *);
-#else
-static inline int dwc3_debugfs_init(struct dwc3 *d)
-{  return 0;  }
-static inline void dwc3_debugfs_exit(struct dwc3 *d)
-{  }
-#endif
-#endif /* __DWC3_DEBUG_H */
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
deleted file mode 100644
index 9ac37fe..0000000
--- a/drivers/usb/dwc3/debugfs.c
+++ /dev/null
@@ -1,690 +0,0 @@
-/**
- * debugfs.c - DesignWare USB3 DRD Controller DebugFS file
- *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
- *
- * Authors: Felipe Balbi <balbi@ti.com>,
- *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/ptrace.h>
-#include <linux/types.h>
-#include <linux/spinlock.h>
-#include <linux/debugfs.h>
-#include <linux/seq_file.h>
-#include <linux/delay.h>
-#include <linux/uaccess.h>
-
-#include <linux/usb/ch9.h>
-
-#include "core.h"
-#include "gadget.h"
-#include "io.h"
-#include "debug.h"
-
-#define dump_register(nm)				\
-{							\
-	.name	= __stringify(nm),			\
-	.offset	= DWC3_ ##nm - DWC3_GLOBALS_REGS_START,	\
-}
-
-static const struct debugfs_reg32 dwc3_regs[] = {
-	dump_register(GSBUSCFG0),
-	dump_register(GSBUSCFG1),
-	dump_register(GTXTHRCFG),
-	dump_register(GRXTHRCFG),
-	dump_register(GCTL),
-	dump_register(GEVTEN),
-	dump_register(GSTS),
-	dump_register(GSNPSID),
-	dump_register(GGPIO),
-	dump_register(GUID),
-	dump_register(GUCTL),
-	dump_register(GBUSERRADDR0),
-	dump_register(GBUSERRADDR1),
-	dump_register(GPRTBIMAP0),
-	dump_register(GPRTBIMAP1),
-	dump_register(GHWPARAMS0),
-	dump_register(GHWPARAMS1),
-	dump_register(GHWPARAMS2),
-	dump_register(GHWPARAMS3),
-	dump_register(GHWPARAMS4),
-	dump_register(GHWPARAMS5),
-	dump_register(GHWPARAMS6),
-	dump_register(GHWPARAMS7),
-	dump_register(GDBGFIFOSPACE),
-	dump_register(GDBGLTSSM),
-	dump_register(GPRTBIMAP_HS0),
-	dump_register(GPRTBIMAP_HS1),
-	dump_register(GPRTBIMAP_FS0),
-	dump_register(GPRTBIMAP_FS1),
-
-	dump_register(GUSB2PHYCFG(0)),
-	dump_register(GUSB2PHYCFG(1)),
-	dump_register(GUSB2PHYCFG(2)),
-	dump_register(GUSB2PHYCFG(3)),
-	dump_register(GUSB2PHYCFG(4)),
-	dump_register(GUSB2PHYCFG(5)),
-	dump_register(GUSB2PHYCFG(6)),
-	dump_register(GUSB2PHYCFG(7)),
-	dump_register(GUSB2PHYCFG(8)),
-	dump_register(GUSB2PHYCFG(9)),
-	dump_register(GUSB2PHYCFG(10)),
-	dump_register(GUSB2PHYCFG(11)),
-	dump_register(GUSB2PHYCFG(12)),
-	dump_register(GUSB2PHYCFG(13)),
-	dump_register(GUSB2PHYCFG(14)),
-	dump_register(GUSB2PHYCFG(15)),
-
-	dump_register(GUSB2I2CCTL(0)),
-	dump_register(GUSB2I2CCTL(1)),
-	dump_register(GUSB2I2CCTL(2)),
-	dump_register(GUSB2I2CCTL(3)),
-	dump_register(GUSB2I2CCTL(4)),
-	dump_register(GUSB2I2CCTL(5)),
-	dump_register(GUSB2I2CCTL(6)),
-	dump_register(GUSB2I2CCTL(7)),
-	dump_register(GUSB2I2CCTL(8)),
-	dump_register(GUSB2I2CCTL(9)),
-	dump_register(GUSB2I2CCTL(10)),
-	dump_register(GUSB2I2CCTL(11)),
-	dump_register(GUSB2I2CCTL(12)),
-	dump_register(GUSB2I2CCTL(13)),
-	dump_register(GUSB2I2CCTL(14)),
-	dump_register(GUSB2I2CCTL(15)),
-
-	dump_register(GUSB2PHYACC(0)),
-	dump_register(GUSB2PHYACC(1)),
-	dump_register(GUSB2PHYACC(2)),
-	dump_register(GUSB2PHYACC(3)),
-	dump_register(GUSB2PHYACC(4)),
-	dump_register(GUSB2PHYACC(5)),
-	dump_register(GUSB2PHYACC(6)),
-	dump_register(GUSB2PHYACC(7)),
-	dump_register(GUSB2PHYACC(8)),
-	dump_register(GUSB2PHYACC(9)),
-	dump_register(GUSB2PHYACC(10)),
-	dump_register(GUSB2PHYACC(11)),
-	dump_register(GUSB2PHYACC(12)),
-	dump_register(GUSB2PHYACC(13)),
-	dump_register(GUSB2PHYACC(14)),
-	dump_register(GUSB2PHYACC(15)),
-
-	dump_register(GUSB3PIPECTL(0)),
-	dump_register(GUSB3PIPECTL(1)),
-	dump_register(GUSB3PIPECTL(2)),
-	dump_register(GUSB3PIPECTL(3)),
-	dump_register(GUSB3PIPECTL(4)),
-	dump_register(GUSB3PIPECTL(5)),
-	dump_register(GUSB3PIPECTL(6)),
-	dump_register(GUSB3PIPECTL(7)),
-	dump_register(GUSB3PIPECTL(8)),
-	dump_register(GUSB3PIPECTL(9)),
-	dump_register(GUSB3PIPECTL(10)),
-	dump_register(GUSB3PIPECTL(11)),
-	dump_register(GUSB3PIPECTL(12)),
-	dump_register(GUSB3PIPECTL(13)),
-	dump_register(GUSB3PIPECTL(14)),
-	dump_register(GUSB3PIPECTL(15)),
-
-	dump_register(GTXFIFOSIZ(0)),
-	dump_register(GTXFIFOSIZ(1)),
-	dump_register(GTXFIFOSIZ(2)),
-	dump_register(GTXFIFOSIZ(3)),
-	dump_register(GTXFIFOSIZ(4)),
-	dump_register(GTXFIFOSIZ(5)),
-	dump_register(GTXFIFOSIZ(6)),
-	dump_register(GTXFIFOSIZ(7)),
-	dump_register(GTXFIFOSIZ(8)),
-	dump_register(GTXFIFOSIZ(9)),
-	dump_register(GTXFIFOSIZ(10)),
-	dump_register(GTXFIFOSIZ(11)),
-	dump_register(GTXFIFOSIZ(12)),
-	dump_register(GTXFIFOSIZ(13)),
-	dump_register(GTXFIFOSIZ(14)),
-	dump_register(GTXFIFOSIZ(15)),
-	dump_register(GTXFIFOSIZ(16)),
-	dump_register(GTXFIFOSIZ(17)),
-	dump_register(GTXFIFOSIZ(18)),
-	dump_register(GTXFIFOSIZ(19)),
-	dump_register(GTXFIFOSIZ(20)),
-	dump_register(GTXFIFOSIZ(21)),
-	dump_register(GTXFIFOSIZ(22)),
-	dump_register(GTXFIFOSIZ(23)),
-	dump_register(GTXFIFOSIZ(24)),
-	dump_register(GTXFIFOSIZ(25)),
-	dump_register(GTXFIFOSIZ(26)),
-	dump_register(GTXFIFOSIZ(27)),
-	dump_register(GTXFIFOSIZ(28)),
-	dump_register(GTXFIFOSIZ(29)),
-	dump_register(GTXFIFOSIZ(30)),
-	dump_register(GTXFIFOSIZ(31)),
-
-	dump_register(GRXFIFOSIZ(0)),
-	dump_register(GRXFIFOSIZ(1)),
-	dump_register(GRXFIFOSIZ(2)),
-	dump_register(GRXFIFOSIZ(3)),
-	dump_register(GRXFIFOSIZ(4)),
-	dump_register(GRXFIFOSIZ(5)),
-	dump_register(GRXFIFOSIZ(6)),
-	dump_register(GRXFIFOSIZ(7)),
-	dump_register(GRXFIFOSIZ(8)),
-	dump_register(GRXFIFOSIZ(9)),
-	dump_register(GRXFIFOSIZ(10)),
-	dump_register(GRXFIFOSIZ(11)),
-	dump_register(GRXFIFOSIZ(12)),
-	dump_register(GRXFIFOSIZ(13)),
-	dump_register(GRXFIFOSIZ(14)),
-	dump_register(GRXFIFOSIZ(15)),
-	dump_register(GRXFIFOSIZ(16)),
-	dump_register(GRXFIFOSIZ(17)),
-	dump_register(GRXFIFOSIZ(18)),
-	dump_register(GRXFIFOSIZ(19)),
-	dump_register(GRXFIFOSIZ(20)),
-	dump_register(GRXFIFOSIZ(21)),
-	dump_register(GRXFIFOSIZ(22)),
-	dump_register(GRXFIFOSIZ(23)),
-	dump_register(GRXFIFOSIZ(24)),
-	dump_register(GRXFIFOSIZ(25)),
-	dump_register(GRXFIFOSIZ(26)),
-	dump_register(GRXFIFOSIZ(27)),
-	dump_register(GRXFIFOSIZ(28)),
-	dump_register(GRXFIFOSIZ(29)),
-	dump_register(GRXFIFOSIZ(30)),
-	dump_register(GRXFIFOSIZ(31)),
-
-	dump_register(GEVNTADRLO(0)),
-	dump_register(GEVNTADRHI(0)),
-	dump_register(GEVNTSIZ(0)),
-	dump_register(GEVNTCOUNT(0)),
-
-	dump_register(GHWPARAMS8),
-	dump_register(DCFG),
-	dump_register(DCTL),
-	dump_register(DEVTEN),
-	dump_register(DSTS),
-	dump_register(DGCMDPAR),
-	dump_register(DGCMD),
-	dump_register(DALEPENA),
-
-	dump_register(DEPCMDPAR2(0)),
-	dump_register(DEPCMDPAR2(1)),
-	dump_register(DEPCMDPAR2(2)),
-	dump_register(DEPCMDPAR2(3)),
-	dump_register(DEPCMDPAR2(4)),
-	dump_register(DEPCMDPAR2(5)),
-	dump_register(DEPCMDPAR2(6)),
-	dump_register(DEPCMDPAR2(7)),
-	dump_register(DEPCMDPAR2(8)),
-	dump_register(DEPCMDPAR2(9)),
-	dump_register(DEPCMDPAR2(10)),
-	dump_register(DEPCMDPAR2(11)),
-	dump_register(DEPCMDPAR2(12)),
-	dump_register(DEPCMDPAR2(13)),
-	dump_register(DEPCMDPAR2(14)),
-	dump_register(DEPCMDPAR2(15)),
-	dump_register(DEPCMDPAR2(16)),
-	dump_register(DEPCMDPAR2(17)),
-	dump_register(DEPCMDPAR2(18)),
-	dump_register(DEPCMDPAR2(19)),
-	dump_register(DEPCMDPAR2(20)),
-	dump_register(DEPCMDPAR2(21)),
-	dump_register(DEPCMDPAR2(22)),
-	dump_register(DEPCMDPAR2(23)),
-	dump_register(DEPCMDPAR2(24)),
-	dump_register(DEPCMDPAR2(25)),
-	dump_register(DEPCMDPAR2(26)),
-	dump_register(DEPCMDPAR2(27)),
-	dump_register(DEPCMDPAR2(28)),
-	dump_register(DEPCMDPAR2(29)),
-	dump_register(DEPCMDPAR2(30)),
-	dump_register(DEPCMDPAR2(31)),
-
-	dump_register(DEPCMDPAR1(0)),
-	dump_register(DEPCMDPAR1(1)),
-	dump_register(DEPCMDPAR1(2)),
-	dump_register(DEPCMDPAR1(3)),
-	dump_register(DEPCMDPAR1(4)),
-	dump_register(DEPCMDPAR1(5)),
-	dump_register(DEPCMDPAR1(6)),
-	dump_register(DEPCMDPAR1(7)),
-	dump_register(DEPCMDPAR1(8)),
-	dump_register(DEPCMDPAR1(9)),
-	dump_register(DEPCMDPAR1(10)),
-	dump_register(DEPCMDPAR1(11)),
-	dump_register(DEPCMDPAR1(12)),
-	dump_register(DEPCMDPAR1(13)),
-	dump_register(DEPCMDPAR1(14)),
-	dump_register(DEPCMDPAR1(15)),
-	dump_register(DEPCMDPAR1(16)),
-	dump_register(DEPCMDPAR1(17)),
-	dump_register(DEPCMDPAR1(18)),
-	dump_register(DEPCMDPAR1(19)),
-	dump_register(DEPCMDPAR1(20)),
-	dump_register(DEPCMDPAR1(21)),
-	dump_register(DEPCMDPAR1(22)),
-	dump_register(DEPCMDPAR1(23)),
-	dump_register(DEPCMDPAR1(24)),
-	dump_register(DEPCMDPAR1(25)),
-	dump_register(DEPCMDPAR1(26)),
-	dump_register(DEPCMDPAR1(27)),
-	dump_register(DEPCMDPAR1(28)),
-	dump_register(DEPCMDPAR1(29)),
-	dump_register(DEPCMDPAR1(30)),
-	dump_register(DEPCMDPAR1(31)),
-
-	dump_register(DEPCMDPAR0(0)),
-	dump_register(DEPCMDPAR0(1)),
-	dump_register(DEPCMDPAR0(2)),
-	dump_register(DEPCMDPAR0(3)),
-	dump_register(DEPCMDPAR0(4)),
-	dump_register(DEPCMDPAR0(5)),
-	dump_register(DEPCMDPAR0(6)),
-	dump_register(DEPCMDPAR0(7)),
-	dump_register(DEPCMDPAR0(8)),
-	dump_register(DEPCMDPAR0(9)),
-	dump_register(DEPCMDPAR0(10)),
-	dump_register(DEPCMDPAR0(11)),
-	dump_register(DEPCMDPAR0(12)),
-	dump_register(DEPCMDPAR0(13)),
-	dump_register(DEPCMDPAR0(14)),
-	dump_register(DEPCMDPAR0(15)),
-	dump_register(DEPCMDPAR0(16)),
-	dump_register(DEPCMDPAR0(17)),
-	dump_register(DEPCMDPAR0(18)),
-	dump_register(DEPCMDPAR0(19)),
-	dump_register(DEPCMDPAR0(20)),
-	dump_register(DEPCMDPAR0(21)),
-	dump_register(DEPCMDPAR0(22)),
-	dump_register(DEPCMDPAR0(23)),
-	dump_register(DEPCMDPAR0(24)),
-	dump_register(DEPCMDPAR0(25)),
-	dump_register(DEPCMDPAR0(26)),
-	dump_register(DEPCMDPAR0(27)),
-	dump_register(DEPCMDPAR0(28)),
-	dump_register(DEPCMDPAR0(29)),
-	dump_register(DEPCMDPAR0(30)),
-	dump_register(DEPCMDPAR0(31)),
-
-	dump_register(DEPCMD(0)),
-	dump_register(DEPCMD(1)),
-	dump_register(DEPCMD(2)),
-	dump_register(DEPCMD(3)),
-	dump_register(DEPCMD(4)),
-	dump_register(DEPCMD(5)),
-	dump_register(DEPCMD(6)),
-	dump_register(DEPCMD(7)),
-	dump_register(DEPCMD(8)),
-	dump_register(DEPCMD(9)),
-	dump_register(DEPCMD(10)),
-	dump_register(DEPCMD(11)),
-	dump_register(DEPCMD(12)),
-	dump_register(DEPCMD(13)),
-	dump_register(DEPCMD(14)),
-	dump_register(DEPCMD(15)),
-	dump_register(DEPCMD(16)),
-	dump_register(DEPCMD(17)),
-	dump_register(DEPCMD(18)),
-	dump_register(DEPCMD(19)),
-	dump_register(DEPCMD(20)),
-	dump_register(DEPCMD(21)),
-	dump_register(DEPCMD(22)),
-	dump_register(DEPCMD(23)),
-	dump_register(DEPCMD(24)),
-	dump_register(DEPCMD(25)),
-	dump_register(DEPCMD(26)),
-	dump_register(DEPCMD(27)),
-	dump_register(DEPCMD(28)),
-	dump_register(DEPCMD(29)),
-	dump_register(DEPCMD(30)),
-	dump_register(DEPCMD(31)),
-
-	dump_register(OCFG),
-	dump_register(OCTL),
-	dump_register(OEVT),
-	dump_register(OEVTEN),
-	dump_register(OSTS),
-};
-
-static int dwc3_mode_show(struct seq_file *s, void *unused)
-{
-	struct dwc3		*dwc = s->private;
-	unsigned long		flags;
-	u32			reg;
-
-	spin_lock_irqsave(&dwc->lock, flags);
-	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
-	spin_unlock_irqrestore(&dwc->lock, flags);
-
-	switch (DWC3_GCTL_PRTCAP(reg)) {
-	case DWC3_GCTL_PRTCAP_HOST:
-		seq_printf(s, "host\n");
-		break;
-	case DWC3_GCTL_PRTCAP_DEVICE:
-		seq_printf(s, "device\n");
-		break;
-	case DWC3_GCTL_PRTCAP_OTG:
-		seq_printf(s, "OTG\n");
-		break;
-	default:
-		seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
-	}
-
-	return 0;
-}
-
-static int dwc3_mode_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, dwc3_mode_show, inode->i_private);
-}
-
-static ssize_t dwc3_mode_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
-{
-	struct seq_file		*s = file->private_data;
-	struct dwc3		*dwc = s->private;
-	unsigned long		flags;
-	u32			mode = 0;
-	char			buf[32];
-
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
-		return -EFAULT;
-
-	if (!strncmp(buf, "host", 4))
-		mode |= DWC3_GCTL_PRTCAP_HOST;
-
-	if (!strncmp(buf, "device", 6))
-		mode |= DWC3_GCTL_PRTCAP_DEVICE;
-
-	if (!strncmp(buf, "otg", 3))
-		mode |= DWC3_GCTL_PRTCAP_OTG;
-
-	if (mode) {
-		spin_lock_irqsave(&dwc->lock, flags);
-		dwc3_set_mode(dwc, mode);
-		spin_unlock_irqrestore(&dwc->lock, flags);
-	}
-	return count;
-}
-
-static const struct file_operations dwc3_mode_fops = {
-	.open			= dwc3_mode_open,
-	.write			= dwc3_mode_write,
-	.read			= seq_read,
-	.llseek			= seq_lseek,
-	.release		= single_release,
-};
-
-static int dwc3_testmode_show(struct seq_file *s, void *unused)
-{
-	struct dwc3		*dwc = s->private;
-	unsigned long		flags;
-	u32			reg;
-
-	spin_lock_irqsave(&dwc->lock, flags);
-	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
-	reg &= DWC3_DCTL_TSTCTRL_MASK;
-	reg >>= 1;
-	spin_unlock_irqrestore(&dwc->lock, flags);
-
-	switch (reg) {
-	case 0:
-		seq_printf(s, "no test\n");
-		break;
-	case TEST_J:
-		seq_printf(s, "test_j\n");
-		break;
-	case TEST_K:
-		seq_printf(s, "test_k\n");
-		break;
-	case TEST_SE0_NAK:
-		seq_printf(s, "test_se0_nak\n");
-		break;
-	case TEST_PACKET:
-		seq_printf(s, "test_packet\n");
-		break;
-	case TEST_FORCE_EN:
-		seq_printf(s, "test_force_enable\n");
-		break;
-	default:
-		seq_printf(s, "UNKNOWN %d\n", reg);
-	}
-
-	return 0;
-}
-
-static int dwc3_testmode_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, dwc3_testmode_show, inode->i_private);
-}
-
-static ssize_t dwc3_testmode_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
-{
-	struct seq_file		*s = file->private_data;
-	struct dwc3		*dwc = s->private;
-	unsigned long		flags;
-	u32			testmode = 0;
-	char			buf[32];
-
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
-		return -EFAULT;
-
-	if (!strncmp(buf, "test_j", 6))
-		testmode = TEST_J;
-	else if (!strncmp(buf, "test_k", 6))
-		testmode = TEST_K;
-	else if (!strncmp(buf, "test_se0_nak", 12))
-		testmode = TEST_SE0_NAK;
-	else if (!strncmp(buf, "test_packet", 11))
-		testmode = TEST_PACKET;
-	else if (!strncmp(buf, "test_force_enable", 17))
-		testmode = TEST_FORCE_EN;
-	else
-		testmode = 0;
-
-	spin_lock_irqsave(&dwc->lock, flags);
-	dwc3_gadget_set_test_mode(dwc, testmode);
-	spin_unlock_irqrestore(&dwc->lock, flags);
-
-	return count;
-}
-
-static const struct file_operations dwc3_testmode_fops = {
-	.open			= dwc3_testmode_open,
-	.write			= dwc3_testmode_write,
-	.read			= seq_read,
-	.llseek			= seq_lseek,
-	.release		= single_release,
-};
-
-static int dwc3_link_state_show(struct seq_file *s, void *unused)
-{
-	struct dwc3		*dwc = s->private;
-	unsigned long		flags;
-	enum dwc3_link_state	state;
-	u32			reg;
-
-	spin_lock_irqsave(&dwc->lock, flags);
-	reg = dwc3_readl(dwc->regs, DWC3_DSTS);
-	state = DWC3_DSTS_USBLNKST(reg);
-	spin_unlock_irqrestore(&dwc->lock, flags);
-
-	switch (state) {
-	case DWC3_LINK_STATE_U0:
-		seq_printf(s, "U0\n");
-		break;
-	case DWC3_LINK_STATE_U1:
-		seq_printf(s, "U1\n");
-		break;
-	case DWC3_LINK_STATE_U2:
-		seq_printf(s, "U2\n");
-		break;
-	case DWC3_LINK_STATE_U3:
-		seq_printf(s, "U3\n");
-		break;
-	case DWC3_LINK_STATE_SS_DIS:
-		seq_printf(s, "SS.Disabled\n");
-		break;
-	case DWC3_LINK_STATE_RX_DET:
-		seq_printf(s, "Rx.Detect\n");
-		break;
-	case DWC3_LINK_STATE_SS_INACT:
-		seq_printf(s, "SS.Inactive\n");
-		break;
-	case DWC3_LINK_STATE_POLL:
-		seq_printf(s, "Poll\n");
-		break;
-	case DWC3_LINK_STATE_RECOV:
-		seq_printf(s, "Recovery\n");
-		break;
-	case DWC3_LINK_STATE_HRESET:
-		seq_printf(s, "HRESET\n");
-		break;
-	case DWC3_LINK_STATE_CMPLY:
-		seq_printf(s, "Compliance\n");
-		break;
-	case DWC3_LINK_STATE_LPBK:
-		seq_printf(s, "Loopback\n");
-		break;
-	case DWC3_LINK_STATE_RESET:
-		seq_printf(s, "Reset\n");
-		break;
-	case DWC3_LINK_STATE_RESUME:
-		seq_printf(s, "Resume\n");
-		break;
-	default:
-		seq_printf(s, "UNKNOWN %d\n", state);
-	}
-
-	return 0;
-}
-
-static int dwc3_link_state_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, dwc3_link_state_show, inode->i_private);
-}
-
-static ssize_t dwc3_link_state_write(struct file *file,
-		const char __user *ubuf, size_t count, loff_t *ppos)
-{
-	struct seq_file		*s = file->private_data;
-	struct dwc3		*dwc = s->private;
-	unsigned long		flags;
-	enum dwc3_link_state	state = 0;
-	char			buf[32];
-
-	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
-		return -EFAULT;
-
-	if (!strncmp(buf, "SS.Disabled", 11))
-		state = DWC3_LINK_STATE_SS_DIS;
-	else if (!strncmp(buf, "Rx.Detect", 9))
-		state = DWC3_LINK_STATE_RX_DET;
-	else if (!strncmp(buf, "SS.Inactive", 11))
-		state = DWC3_LINK_STATE_SS_INACT;
-	else if (!strncmp(buf, "Recovery", 8))
-		state = DWC3_LINK_STATE_RECOV;
-	else if (!strncmp(buf, "Compliance", 10))
-		state = DWC3_LINK_STATE_CMPLY;
-	else if (!strncmp(buf, "Loopback", 8))
-		state = DWC3_LINK_STATE_LPBK;
-	else
-		return -EINVAL;
-
-	spin_lock_irqsave(&dwc->lock, flags);
-	dwc3_gadget_set_link_state(dwc, state);
-	spin_unlock_irqrestore(&dwc->lock, flags);
-
-	return count;
-}
-
-static const struct file_operations dwc3_link_state_fops = {
-	.open			= dwc3_link_state_open,
-	.write			= dwc3_link_state_write,
-	.read			= seq_read,
-	.llseek			= seq_lseek,
-	.release		= single_release,
-};
-
-int dwc3_debugfs_init(struct dwc3 *dwc)
-{
-	struct dentry		*root;
-	struct dentry		*file;
-	int			ret;
-
-	root = debugfs_create_dir(dev_name(dwc->dev), NULL);
-	if (!root) {
-		ret = -ENOMEM;
-		goto err0;
-	}
-
-	dwc->root = root;
-
-	dwc->regset = kzalloc(sizeof(*dwc->regset), GFP_KERNEL);
-	if (!dwc->regset) {
-		ret = -ENOMEM;
-		goto err1;
-	}
-
-	dwc->regset->regs = dwc3_regs;
-	dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
-	dwc->regset->base = dwc->regs;
-
-	file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
-	if (!file) {
-		ret = -ENOMEM;
-		goto err1;
-	}
-
-	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
-		file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
-				dwc, &dwc3_mode_fops);
-		if (!file) {
-			ret = -ENOMEM;
-			goto err1;
-		}
-	}
-
-	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
-			IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
-		file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
-				dwc, &dwc3_testmode_fops);
-		if (!file) {
-			ret = -ENOMEM;
-			goto err1;
-		}
-
-		file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
-				dwc, &dwc3_link_state_fops);
-		if (!file) {
-			ret = -ENOMEM;
-			goto err1;
-		}
-	}
-
-	return 0;
-
-err1:
-	debugfs_remove_recursive(root);
-
-err0:
-	return ret;
-}
-
-void dwc3_debugfs_exit(struct dwc3 *dwc)
-{
-	debugfs_remove_recursive(dwc->root);
-	dwc->root = NULL;
-}
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
deleted file mode 100644
index 7bd0a95..0000000
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ /dev/null
@@ -1,301 +0,0 @@
-/**
- * dwc3-exynos.c - Samsung EXYNOS DWC3 Specific Glue layer
- *
- * Copyright (c) 2012 Samsung Electronics Co., Ltd.
- *		http://www.samsung.com
- *
- * Author: Anton Tikhomirov <av.tikhomirov@samsung.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/platform_device.h>
-#include <linux/dma-mapping.h>
-#include <linux/clk.h>
-#include <linux/usb/otg.h>
-#include <linux/usb/usb_phy_generic.h>
-#include <linux/of.h>
-#include <linux/of_platform.h>
-#include <linux/regulator/consumer.h>
-
-struct dwc3_exynos {
-	struct platform_device	*usb2_phy;
-	struct platform_device	*usb3_phy;
-	struct device		*dev;
-
-	struct clk		*clk;
-	struct clk		*susp_clk;
-	struct clk		*axius_clk;
-
-	struct regulator	*vdd33;
-	struct regulator	*vdd10;
-};
-
-static int dwc3_exynos_register_phys(struct dwc3_exynos *exynos)
-{
-	struct usb_phy_generic_platform_data pdata;
-	struct platform_device	*pdev;
-	int			ret;
-
-	memset(&pdata, 0x00, sizeof(pdata));
-
-	pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
-	if (!pdev)
-		return -ENOMEM;
-
-	exynos->usb2_phy = pdev;
-	pdata.type = USB_PHY_TYPE_USB2;
-	pdata.gpio_reset = -1;
-
-	ret = platform_device_add_data(exynos->usb2_phy, &pdata, sizeof(pdata));
-	if (ret)
-		goto err1;
-
-	pdev = platform_device_alloc("usb_phy_generic", PLATFORM_DEVID_AUTO);
-	if (!pdev) {
-		ret = -ENOMEM;
-		goto err1;
-	}
-
-	exynos->usb3_phy = pdev;
-	pdata.type = USB_PHY_TYPE_USB3;
-
-	ret = platform_device_add_data(exynos->usb3_phy, &pdata, sizeof(pdata));
-	if (ret)
-		goto err2;
-
-	ret = platform_device_add(exynos->usb2_phy);
-	if (ret)
-		goto err2;
-
-	ret = platform_device_add(exynos->usb3_phy);
-	if (ret)
-		goto err3;
-
-	return 0;
-
-err3:
-	platform_device_del(exynos->usb2_phy);
-
-err2:
-	platform_device_put(exynos->usb3_phy);
-
-err1:
-	platform_device_put(exynos->usb2_phy);
-
-	return ret;
-}
-
-static int dwc3_exynos_remove_child(struct device *dev, void *unused)
-{
-	struct platform_device *pdev = to_platform_device(dev);
-
-	platform_device_unregister(pdev);
-
-	return 0;
-}
-
-static int dwc3_exynos_probe(struct platform_device *pdev)
-{
-	struct dwc3_exynos	*exynos;
-	struct device		*dev = &pdev->dev;
-	struct device_node	*node = dev->of_node;
-
-	int			ret;
-
-	exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
-	if (!exynos)
-		return -ENOMEM;
-
-	/*
-	 * Right now device-tree probed devices don't get dma_mask set.
-	 * Since shared usb code relies on it, set it here for now.
-	 * Once we move to full device tree support this will vanish off.
-	 */
-	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
-	if (ret)
-		return ret;
-
-	platform_set_drvdata(pdev, exynos);
-
-	ret = dwc3_exynos_register_phys(exynos);
-	if (ret) {
-		dev_err(dev, "couldn't register PHYs\n");
-		return ret;
-	}
-
-	exynos->dev	= dev;
-
-	exynos->clk = devm_clk_get(dev, "usbdrd30");
-	if (IS_ERR(exynos->clk)) {
-		dev_err(dev, "couldn't get clock\n");
-		return -EINVAL;
-	}
-	clk_prepare_enable(exynos->clk);
-
-	exynos->susp_clk = devm_clk_get(dev, "usbdrd30_susp_clk");
-	if (IS_ERR(exynos->susp_clk)) {
-		dev_dbg(dev, "no suspend clk specified\n");
-		exynos->susp_clk = NULL;
-	}
-	clk_prepare_enable(exynos->susp_clk);
-
-	if (of_device_is_compatible(node, "samsung,exynos7-dwusb3")) {
-		exynos->axius_clk = devm_clk_get(dev, "usbdrd30_axius_clk");
-		if (IS_ERR(exynos->axius_clk)) {
-			dev_err(dev, "no AXI UpScaler clk specified\n");
-			return -ENODEV;
-		}
-		clk_prepare_enable(exynos->axius_clk);
-	} else {
-		exynos->axius_clk = NULL;
-	}
-
-	exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-	if (IS_ERR(exynos->vdd33)) {
-		ret = PTR_ERR(exynos->vdd33);
-		goto err2;
-	}
-	ret = regulator_enable(exynos->vdd33);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD33 supply\n");
-		goto err2;
-	}
-
-	exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-	if (IS_ERR(exynos->vdd10)) {
-		ret = PTR_ERR(exynos->vdd10);
-		goto err3;
-	}
-	ret = regulator_enable(exynos->vdd10);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD10 supply\n");
-		goto err3;
-	}
-
-	if (node) {
-		ret = of_platform_populate(node, NULL, NULL, dev);
-		if (ret) {
-			dev_err(dev, "failed to add dwc3 core\n");
-			goto err4;
-		}
-	} else {
-		dev_err(dev, "no device node, failed to add dwc3 core\n");
-		ret = -ENODEV;
-		goto err4;
-	}
-
-	return 0;
-
-err4:
-	regulator_disable(exynos->vdd10);
-err3:
-	regulator_disable(exynos->vdd33);
-err2:
-	clk_disable_unprepare(exynos->axius_clk);
-	clk_disable_unprepare(exynos->susp_clk);
-	clk_disable_unprepare(exynos->clk);
-	return ret;
-}
-
-static int dwc3_exynos_remove(struct platform_device *pdev)
-{
-	struct dwc3_exynos	*exynos = platform_get_drvdata(pdev);
-
-	device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
-	platform_device_unregister(exynos->usb2_phy);
-	platform_device_unregister(exynos->usb3_phy);
-
-	clk_disable_unprepare(exynos->axius_clk);
-	clk_disable_unprepare(exynos->susp_clk);
-	clk_disable_unprepare(exynos->clk);
-
-	regulator_disable(exynos->vdd33);
-	regulator_disable(exynos->vdd10);
-
-	return 0;
-}
-
-static const struct of_device_id exynos_dwc3_match[] = {
-	{ .compatible = "samsung,exynos5250-dwusb3" },
-	{ .compatible = "samsung,exynos7-dwusb3" },
-	{},
-};
-MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
-
-#ifdef CONFIG_PM_SLEEP
-static int dwc3_exynos_suspend(struct device *dev)
-{
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-
-	clk_disable(exynos->axius_clk);
-	clk_disable(exynos->clk);
-
-	regulator_disable(exynos->vdd33);
-	regulator_disable(exynos->vdd10);
-
-	return 0;
-}
-
-static int dwc3_exynos_resume(struct device *dev)
-{
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-	int ret;
-
-	ret = regulator_enable(exynos->vdd33);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD33 supply\n");
-		return ret;
-	}
-	ret = regulator_enable(exynos->vdd10);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD10 supply\n");
-		return ret;
-	}
-
-	clk_enable(exynos->clk);
-	clk_enable(exynos->axius_clk);
-
-	/* runtime set active to reflect active state. */
-	pm_runtime_disable(dev);
-	pm_runtime_set_active(dev);
-	pm_runtime_enable(dev);
-
-	return 0;
-}
-
-static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
-};
-
-#define DEV_PM_OPS	(&dwc3_exynos_dev_pm_ops)
-#else
-#define DEV_PM_OPS	NULL
-#endif /* CONFIG_PM_SLEEP */
-
-static struct platform_driver dwc3_exynos_driver = {
-	.probe		= dwc3_exynos_probe,
-	.remove		= dwc3_exynos_remove,
-	.driver		= {
-		.name	= "exynos-dwc3",
-		.of_match_table = exynos_dwc3_match,
-		.pm	= DEV_PM_OPS,
-	},
-};
-
-module_platform_driver(dwc3_exynos_driver);
-
-MODULE_ALIAS("platform:exynos-dwc3");
-MODULE_AUTHOR("Anton Tikhomirov <av.tikhomirov@samsung.com>");
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("DesignWare USB3 EXYNOS Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
deleted file mode 100644
index fe3b933..0000000
--- a/drivers/usb/dwc3/dwc3-keystone.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/**
- * dwc3-keystone.c - Keystone Specific Glue layer
- *
- * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com
- *
- * Author: WingMan Kwok <w-kwok2@ti.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#include <linux/clk.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/interrupt.h>
-#include <linux/platform_device.h>
-#include <linux/dma-mapping.h>
-#include <linux/io.h>
-#include <linux/of_platform.h>
-
-/* USBSS register offsets */
-#define USBSS_REVISION		0x0000
-#define USBSS_SYSCONFIG		0x0010
-#define USBSS_IRQ_EOI		0x0018
-#define USBSS_IRQSTATUS_RAW_0	0x0020
-#define USBSS_IRQSTATUS_0	0x0024
-#define USBSS_IRQENABLE_SET_0	0x0028
-#define USBSS_IRQENABLE_CLR_0	0x002c
-
-/* IRQ register bits */
-#define USBSS_IRQ_EOI_LINE(n)	BIT(n)
-#define USBSS_IRQ_EVENT_ST	BIT(0)
-#define USBSS_IRQ_COREIRQ_EN	BIT(0)
-#define USBSS_IRQ_COREIRQ_CLR	BIT(0)
-
-static u64 kdwc3_dma_mask;
-
-struct dwc3_keystone {
-	struct device			*dev;
-	struct clk			*clk;
-	void __iomem			*usbss;
-};
-
-static inline u32 kdwc3_readl(void __iomem *base, u32 offset)
-{
-	return readl(base + offset);
-}
-
-static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value)
-{
-	writel(value, base + offset);
-}
-
-static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc)
-{
-	u32 val;
-
-	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
-	val |= USBSS_IRQ_COREIRQ_EN;
-	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
-}
-
-static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc)
-{
-	u32 val;
-
-	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
-	val &= ~USBSS_IRQ_COREIRQ_EN;
-	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
-}
-
-static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
-{
-	struct dwc3_keystone	*kdwc = _kdwc;
-
-	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR);
-	kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST);
-	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN);
-	kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0));
-
-	return IRQ_HANDLED;
-}
-
-static int kdwc3_probe(struct platform_device *pdev)
-{
-	struct device		*dev = &pdev->dev;
-	struct device_node	*node = pdev->dev.of_node;
-	struct dwc3_keystone	*kdwc;
-	struct resource		*res;
-	int			error, irq;
-
-	kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL);
-	if (!kdwc)
-		return -ENOMEM;
-
-	platform_set_drvdata(pdev, kdwc);
-
-	kdwc->dev = dev;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	kdwc->usbss = devm_ioremap_resource(dev, res);
-	if (IS_ERR(kdwc->usbss))
-		return PTR_ERR(kdwc->usbss);
-
-	kdwc3_dma_mask = dma_get_mask(dev);
-	dev->dma_mask = &kdwc3_dma_mask;
-
-	kdwc->clk = devm_clk_get(kdwc->dev, "usb");
-
-	error = clk_prepare_enable(kdwc->clk);
-	if (error < 0) {
-		dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
-			error);
-		return error;
-	}
-
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		dev_err(&pdev->dev, "missing irq\n");
-		error = irq;
-		goto err_irq;
-	}
-
-	error = devm_request_irq(dev, irq, dwc3_keystone_interrupt, IRQF_SHARED,
-			dev_name(dev), kdwc);
-	if (error) {
-		dev_err(dev, "failed to request IRQ #%d --> %d\n",
-				irq, error);
-		goto err_irq;
-	}
-
-	kdwc3_enable_irqs(kdwc);
-
-	error = of_platform_populate(node, NULL, NULL, dev);
-	if (error) {
-		dev_err(&pdev->dev, "failed to create dwc3 core\n");
-		goto err_core;
-	}
-
-	return 0;
-
-err_core:
-	kdwc3_disable_irqs(kdwc);
-err_irq:
-	clk_disable_unprepare(kdwc->clk);
-
-	return error;
-}
-
-static int kdwc3_remove_core(struct device *dev, void *c)
-{
-	struct platform_device *pdev = to_platform_device(dev);
-
-	platform_device_unregister(pdev);
-
-	return 0;
-}
-
-static int kdwc3_remove(struct platform_device *pdev)
-{
-	struct dwc3_keystone *kdwc = platform_get_drvdata(pdev);
-
-	kdwc3_disable_irqs(kdwc);
-	device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
-	clk_disable_unprepare(kdwc->clk);
-	platform_set_drvdata(pdev, NULL);
-
-	return 0;
-}
-
-static const struct of_device_id kdwc3_of_match[] = {
-	{ .compatible = "ti,keystone-dwc3", },
-	{},
-};
-MODULE_DEVICE_TABLE(of, kdwc3_of_match);
-
-static struct platform_driver kdwc3_driver = {
-	.probe		= kdwc3_probe,
-	.remove		= kdwc3_remove,
-	.driver		= {
-		.name	= "keystone-dwc3",
-		.of_match_table	= kdwc3_of_match,
-	},
-};
-
-module_platform_driver(kdwc3_driver);
-
-MODULE_ALIAS("platform:keystone-dwc3");
-MODULE_AUTHOR("WingMan Kwok <w-kwok2@ti.com>");
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("DesignWare USB3 KEYSTONE Glue Layer");
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
deleted file mode 100644
index 7c4faf7..0000000
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/**
- * dwc3-pci.c - PCI Specific glue layer
- *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
- *
- * Authors: Felipe Balbi <balbi@ti.com>,
- *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/pci.h>
-#include <linux/platform_device.h>
-
-#include <linux/usb/otg.h>
-#include <linux/usb/usb_phy_generic.h>
-
-#include "platform_data.h"
-
-/* FIXME define these in <linux/pci_ids.h> */
-#define PCI_VENDOR_ID_SYNOPSYS		0x16c3
-#define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3	0xabcd
-#define PCI_DEVICE_ID_INTEL_BYT		0x0f37
-#define PCI_DEVICE_ID_INTEL_MRFLD	0x119e
-#define PCI_DEVICE_ID_INTEL_BSW		0x22B7
-
-struct dwc3_pci {
-	struct device		*dev;
-	struct platform_device	*dwc3;
-	struct platform_device	*usb2_phy;
-	struct platform_device	*usb3_phy;
-};
-
-static int dwc3_pci_register_phys(struct dwc3_pci *glue)
-{
-	struct usb_phy_generic_platform_data pdata;
-	struct platform_device	*pdev;
-	int			ret;
-
-	memset(&pdata, 0x00, sizeof(pdata));
-
-	pdev = platform_device_alloc("usb_phy_generic", 0);
-	if (!pdev)
-		return -ENOMEM;
-
-	glue->usb2_phy = pdev;
-	pdata.type = USB_PHY_TYPE_USB2;
-	pdata.gpio_reset = -1;
-
-	ret = platform_device_add_data(glue->usb2_phy, &pdata, sizeof(pdata));
-	if (ret)
-		goto err1;
-
-	pdev = platform_device_alloc("usb_phy_generic", 1);
-	if (!pdev) {
-		ret = -ENOMEM;
-		goto err1;
-	}
-
-	glue->usb3_phy = pdev;
-	pdata.type = USB_PHY_TYPE_USB3;
-
-	ret = platform_device_add_data(glue->usb3_phy, &pdata, sizeof(pdata));
-	if (ret)
-		goto err2;
-
-	ret = platform_device_add(glue->usb2_phy);
-	if (ret)
-		goto err2;
-
-	ret = platform_device_add(glue->usb3_phy);
-	if (ret)
-		goto err3;
-
-	return 0;
-
-err3:
-	platform_device_del(glue->usb2_phy);
-
-err2:
-	platform_device_put(glue->usb3_phy);
-
-err1:
-	platform_device_put(glue->usb2_phy);
-
-	return ret;
-}
-
-static int dwc3_pci_probe(struct pci_dev *pci,
-		const struct pci_device_id *id)
-{
-	struct resource		res[2];
-	struct platform_device	*dwc3;
-	struct dwc3_pci		*glue;
-	int			ret;
-	struct device		*dev = &pci->dev;
-	struct dwc3_platform_data dwc3_pdata;
-
-	memset(&dwc3_pdata, 0x00, sizeof(dwc3_pdata));
-
-	glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
-	if (!glue)
-		return -ENOMEM;
-
-	glue->dev = dev;
-
-	ret = pcim_enable_device(pci);
-	if (ret) {
-		dev_err(dev, "failed to enable pci device\n");
-		return -ENODEV;
-	}
-
-	pci_set_master(pci);
-
-	ret = dwc3_pci_register_phys(glue);
-	if (ret) {
-		dev_err(dev, "couldn't register PHYs\n");
-		return ret;
-	}
-
-	dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
-	if (!dwc3) {
-		dev_err(dev, "couldn't allocate dwc3 device\n");
-		return -ENOMEM;
-	}
-
-	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
-
-	res[0].start	= pci_resource_start(pci, 0);
-	res[0].end	= pci_resource_end(pci, 0);
-	res[0].name	= "dwc_usb3";
-	res[0].flags	= IORESOURCE_MEM;
-
-	res[1].start	= pci->irq;
-	res[1].name	= "dwc_usb3";
-	res[1].flags	= IORESOURCE_IRQ;
-
-	if (pci->vendor == PCI_VENDOR_ID_AMD &&
-			pci->device == PCI_DEVICE_ID_AMD_NL_USB) {
-		dwc3_pdata.has_lpm_erratum = true;
-		dwc3_pdata.lpm_nyet_threshold = 0xf;
-
-		dwc3_pdata.u2exit_lfps_quirk = true;
-		dwc3_pdata.u2ss_inp3_quirk = true;
-		dwc3_pdata.req_p1p2p3_quirk = true;
-		dwc3_pdata.del_p1p2p3_quirk = true;
-		dwc3_pdata.del_phy_power_chg_quirk = true;
-		dwc3_pdata.lfps_filter_quirk = true;
-		dwc3_pdata.rx_detect_poll_quirk = true;
-
-		dwc3_pdata.tx_de_emphasis_quirk = true;
-		dwc3_pdata.tx_de_emphasis = 1;
-
-		/*
-		 * FIXME these quirks should be removed when AMD NL
-		 * taps out
-		 */
-		dwc3_pdata.disable_scramble_quirk = true;
-		dwc3_pdata.dis_u3_susphy_quirk = true;
-		dwc3_pdata.dis_u2_susphy_quirk = true;
-	}
-
-	ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
-	if (ret) {
-		dev_err(dev, "couldn't add resources to dwc3 device\n");
-		return ret;
-	}
-
-	pci_set_drvdata(pci, glue);
-
-	ret = platform_device_add_data(dwc3, &dwc3_pdata, sizeof(dwc3_pdata));
-	if (ret)
-		goto err3;
-
-	dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
-
-	dwc3->dev.dma_mask = dev->dma_mask;
-	dwc3->dev.dma_parms = dev->dma_parms;
-	dwc3->dev.parent = dev;
-	glue->dwc3 = dwc3;
-
-	ret = platform_device_add(dwc3);
-	if (ret) {
-		dev_err(dev, "failed to register dwc3 device\n");
-		goto err3;
-	}
-
-	return 0;
-
-err3:
-	platform_device_put(dwc3);
-	return ret;
-}
-
-static void dwc3_pci_remove(struct pci_dev *pci)
-{
-	struct dwc3_pci	*glue = pci_get_drvdata(pci);
-
-	platform_device_unregister(glue->dwc3);
-	platform_device_unregister(glue->usb2_phy);
-	platform_device_unregister(glue->usb3_phy);
-}
-
-static const struct pci_device_id dwc3_pci_id_table[] = {
-	{
-		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
-				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
-	},
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
-	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
-	{  }	/* Terminating Entry */
-};
-MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
-
-#ifdef CONFIG_PM_SLEEP
-static int dwc3_pci_suspend(struct device *dev)
-{
-	struct pci_dev	*pci = to_pci_dev(dev);
-
-	pci_disable_device(pci);
-
-	return 0;
-}
-
-static int dwc3_pci_resume(struct device *dev)
-{
-	struct pci_dev	*pci = to_pci_dev(dev);
-	int		ret;
-
-	ret = pci_enable_device(pci);
-	if (ret) {
-		dev_err(dev, "can't re-enable device --> %d\n", ret);
-		return ret;
-	}
-
-	pci_set_master(pci);
-
-	return 0;
-}
-#endif /* CONFIG_PM_SLEEP */
-
-static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
-};
-
-static struct pci_driver dwc3_pci_driver = {
-	.name		= "dwc3-pci",
-	.id_table	= dwc3_pci_id_table,
-	.probe		= dwc3_pci_probe,
-	.remove		= dwc3_pci_remove,
-	.driver		= {
-		.pm	= &dwc3_pci_dev_pm_ops,
-	},
-};
-
-MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
-
-module_pci_driver(dwc3_pci_driver);
diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
deleted file mode 100644
index 8c2e8ee..0000000
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#include <linux/clk.h>
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/module.h>
-#include <linux/of.h>
-#include <linux/of_platform.h>
-#include <linux/platform_device.h>
-
-struct dwc3_qcom {
-	struct device		*dev;
-
-	struct clk		*core_clk;
-	struct clk		*iface_clk;
-	struct clk		*sleep_clk;
-};
-
-static int dwc3_qcom_probe(struct platform_device *pdev)
-{
-	struct device_node *node = pdev->dev.of_node;
-	struct dwc3_qcom *qdwc;
-	int ret;
-
-	qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
-	if (!qdwc)
-		return -ENOMEM;
-
-	platform_set_drvdata(pdev, qdwc);
-
-	qdwc->dev = &pdev->dev;
-
-	qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
-	if (IS_ERR(qdwc->core_clk)) {
-		dev_err(qdwc->dev, "failed to get core clock\n");
-		return PTR_ERR(qdwc->core_clk);
-	}
-
-	qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
-	if (IS_ERR(qdwc->iface_clk)) {
-		dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
-		qdwc->iface_clk = NULL;
-	}
-
-	qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
-	if (IS_ERR(qdwc->sleep_clk)) {
-		dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");
-		qdwc->sleep_clk = NULL;
-	}
-
-	ret = clk_prepare_enable(qdwc->core_clk);
-	if (ret) {
-		dev_err(qdwc->dev, "failed to enable core clock\n");
-		goto err_core;
-	}
-
-	ret = clk_prepare_enable(qdwc->iface_clk);
-	if (ret) {
-		dev_err(qdwc->dev, "failed to enable optional iface clock\n");
-		goto err_iface;
-	}
-
-	ret = clk_prepare_enable(qdwc->sleep_clk);
-	if (ret) {
-		dev_err(qdwc->dev, "failed to enable optional sleep clock\n");
-		goto err_sleep;
-	}
-
-	ret = of_platform_populate(node, NULL, NULL, qdwc->dev);
-	if (ret) {
-		dev_err(qdwc->dev, "failed to register core - %d\n", ret);
-		goto err_clks;
-	}
-
-	return 0;
-
-err_clks:
-	clk_disable_unprepare(qdwc->sleep_clk);
-err_sleep:
-	clk_disable_unprepare(qdwc->iface_clk);
-err_iface:
-	clk_disable_unprepare(qdwc->core_clk);
-err_core:
-	return ret;
-}
-
-static int dwc3_qcom_remove(struct platform_device *pdev)
-{
-	struct dwc3_qcom *qdwc = platform_get_drvdata(pdev);
-
-	of_platform_depopulate(&pdev->dev);
-
-	clk_disable_unprepare(qdwc->sleep_clk);
-	clk_disable_unprepare(qdwc->iface_clk);
-	clk_disable_unprepare(qdwc->core_clk);
-
-	return 0;
-}
-
-static const struct of_device_id of_dwc3_match[] = {
-	{ .compatible = "qcom,dwc3" },
-	{ /* Sentinel */ }
-};
-MODULE_DEVICE_TABLE(of, of_dwc3_match);
-
-static struct platform_driver dwc3_qcom_driver = {
-	.probe		= dwc3_qcom_probe,
-	.remove		= dwc3_qcom_remove,
-	.driver		= {
-		.name	= "qcom-dwc3",
-		.of_match_table	= of_dwc3_match,
-	},
-};
-
-module_platform_driver(dwc3_qcom_driver);
-
-MODULE_ALIAS("platform:qcom-dwc3");
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer");
-MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
deleted file mode 100644
index 4a1a543..0000000
--- a/drivers/usb/dwc3/dwc3-st.c
+++ /dev/null
@@ -1,367 +0,0 @@
-/**
- * dwc3-st.c Support for dwc3 platform devices on ST Microelectronics platforms
- *
- * This is a small driver for the dwc3 to provide the glue logic
- * to configure the controller. Tested on STi platforms.
- *
- * Copyright (C) 2014 Stmicroelectronics
- *
- * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
- * Contributors: Aymen Bouattay <aymen.bouattay@st.com>
- *               Peter Griffin <peter.griffin@linaro.org>
- *
- * 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.
- *
- * Inspired by dwc3-omap.c and dwc3-exynos.c.
- */
-
-#include <linux/delay.h>
-#include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/ioport.h>
-#include <linux/kernel.h>
-#include <linux/mfd/syscon.h>
-#include <linux/module.h>
-#include <linux/of.h>
-#include <linux/of_platform.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-#include <linux/regmap.h>
-#include <linux/reset.h>
-#include <linux/usb/of.h>
-
-#include "core.h"
-#include "io.h"
-
-/* glue registers */
-#define CLKRST_CTRL		0x00
-#define AUX_CLK_EN		BIT(0)
-#define SW_PIPEW_RESET_N	BIT(4)
-#define EXT_CFG_RESET_N		BIT(8)
-/*
- * 1'b0 : The host controller complies with the xHCI revision 0.96
- * 1'b1 : The host controller complies with the xHCI revision 1.0
- */
-#define XHCI_REVISION		BIT(12)
-
-#define USB2_VBUS_MNGMNT_SEL1	0x2C
-/*
- * For all fields in USB2_VBUS_MNGMNT_SEL1
- * 2?b00 : Override value from Reg 0x30 is selected
- * 2?b01 : utmiotg_<signal_name> from usb3_top is selected
- * 2?b10 : pipew_<signal_name> from PIPEW instance is selected
- * 2?b11 : value is 1'b0
- */
-#define USB2_VBUS_REG30		0x0
-#define USB2_VBUS_UTMIOTG	0x1
-#define USB2_VBUS_PIPEW		0x2
-#define USB2_VBUS_ZERO		0x3
-
-#define SEL_OVERRIDE_VBUSVALID(n)	(n << 0)
-#define SEL_OVERRIDE_POWERPRESENT(n)	(n << 4)
-#define SEL_OVERRIDE_BVALID(n)		(n << 8)
-
-/* Static DRD configuration */
-#define USB3_CONTROL_MASK		0xf77
-
-#define USB3_DEVICE_NOT_HOST		BIT(0)
-#define USB3_FORCE_VBUSVALID		BIT(1)
-#define USB3_DELAY_VBUSVALID		BIT(2)
-#define USB3_SEL_FORCE_OPMODE		BIT(4)
-#define USB3_FORCE_OPMODE(n)		(n << 5)
-#define USB3_SEL_FORCE_DPPULLDOWN2	BIT(8)
-#define USB3_FORCE_DPPULLDOWN2		BIT(9)
-#define USB3_SEL_FORCE_DMPULLDOWN2	BIT(10)
-#define USB3_FORCE_DMPULLDOWN2		BIT(11)
-
-/**
- * struct st_dwc3 - dwc3-st driver private structure
- * @dev:		device pointer
- * @glue_base:		ioaddr for the glue registers
- * @regmap:		regmap pointer for getting syscfg
- * @syscfg_reg_off:	usb syscfg control offset
- * @dr_mode:		drd static host/device config
- * @rstc_pwrdn:		rest controller for powerdown signal
- * @rstc_rst:		reset controller for softreset signal
- */
-
-struct st_dwc3 {
-	struct device *dev;
-	void __iomem *glue_base;
-	struct regmap *regmap;
-	int syscfg_reg_off;
-	enum usb_dr_mode dr_mode;
-	struct reset_control *rstc_pwrdn;
-	struct reset_control *rstc_rst;
-};
-
-static inline u32 st_dwc3_readl(void __iomem *base, u32 offset)
-{
-	return readl_relaxed(base + offset);
-}
-
-static inline void st_dwc3_writel(void __iomem *base, u32 offset, u32 value)
-{
-	writel_relaxed(value, base + offset);
-}
-
-/**
- * st_dwc3_drd_init: program the port
- * @dwc3_data: driver private structure
- * Description: this function is to program the port as either host or device
- * according to the static configuration passed from devicetree.
- * OTG and dual role are not yet supported!
- */
-static int st_dwc3_drd_init(struct st_dwc3 *dwc3_data)
-{
-	u32 val;
-	int err;
-
-	err = regmap_read(dwc3_data->regmap, dwc3_data->syscfg_reg_off, &val);
-	if (err)
-		return err;
-
-	val &= USB3_CONTROL_MASK;
-
-	switch (dwc3_data->dr_mode) {
-	case USB_DR_MODE_PERIPHERAL:
-
-		val &= ~(USB3_FORCE_VBUSVALID | USB3_DELAY_VBUSVALID
-			| USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3)
-			| USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
-			| USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
-
-		val |= USB3_DEVICE_NOT_HOST;
-
-		dev_dbg(dwc3_data->dev, "Configuring as Device\n");
-		break;
-
-	case USB_DR_MODE_HOST:
-
-		val &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID
-			| USB3_SEL_FORCE_OPMODE	| USB3_FORCE_OPMODE(0x3)
-			| USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
-			| USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
-
-		/*
-		 * USB3_DELAY_VBUSVALID is ANDed with USB_C_VBUSVALID. Thus,
-		 * when set to ?0?, it can delay the arrival of VBUSVALID
-		 * information to VBUSVLDEXT2 input of the pico PHY.
-		 * We don't want to do that so we set the bit to '1'.
-		 */
-
-		val |= USB3_DELAY_VBUSVALID;
-
-		dev_dbg(dwc3_data->dev, "Configuring as Host\n");
-		break;
-
-	default:
-		dev_err(dwc3_data->dev, "Unsupported mode of operation %d\n",
-			dwc3_data->dr_mode);
-		return -EINVAL;
-	}
-
-	return regmap_write(dwc3_data->regmap, dwc3_data->syscfg_reg_off, val);
-}
-
-/**
- * st_dwc3_init: init the controller via glue logic
- * @dwc3_data: driver private structure
- */
-static void st_dwc3_init(struct st_dwc3 *dwc3_data)
-{
-	u32 reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
-
-	reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION;
-	reg &= ~SW_PIPEW_RESET_N;
-	st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
-
-	/* configure mux for vbus, powerpresent and bvalid signals */
-	reg = st_dwc3_readl(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1);
-
-	reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) |
-		SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) |
-		SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG);
-
-	st_dwc3_writel(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1, reg);
-
-	reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
-	reg |= SW_PIPEW_RESET_N;
-	st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
-}
-
-static int st_dwc3_probe(struct platform_device *pdev)
-{
-	struct st_dwc3 *dwc3_data;
-	struct resource *res;
-	struct device *dev = &pdev->dev;
-	struct device_node *node = dev->of_node, *child;
-	struct regmap *regmap;
-	int ret;
-
-	dwc3_data = devm_kzalloc(dev, sizeof(*dwc3_data), GFP_KERNEL);
-	if (!dwc3_data)
-		return -ENOMEM;
-
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "reg-glue");
-	dwc3_data->glue_base = devm_ioremap_resource(dev, res);
-	if (IS_ERR(dwc3_data->glue_base))
-		return PTR_ERR(dwc3_data->glue_base);
-
-	regmap = syscon_regmap_lookup_by_phandle(node, "st,syscfg");
-	if (IS_ERR(regmap))
-		return PTR_ERR(regmap);
-
-	dma_set_coherent_mask(dev, dev->coherent_dma_mask);
-	dwc3_data->dev = dev;
-	dwc3_data->regmap = regmap;
-
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg");
-	if (!res) {
-		ret = -ENXIO;
-		goto undo_platform_dev_alloc;
-	}
-
-	dwc3_data->syscfg_reg_off = res->start;
-
-	dev_vdbg(&pdev->dev, "glue-logic addr 0x%p, syscfg-reg offset 0x%x\n",
-		 dwc3_data->glue_base, dwc3_data->syscfg_reg_off);
-
-	dwc3_data->rstc_pwrdn = devm_reset_control_get(dev, "powerdown");
-	if (IS_ERR(dwc3_data->rstc_pwrdn)) {
-		dev_err(&pdev->dev, "could not get power controller\n");
-		ret = PTR_ERR(dwc3_data->rstc_pwrdn);
-		goto undo_platform_dev_alloc;
-	}
-
-	/* Manage PowerDown */
-	reset_control_deassert(dwc3_data->rstc_pwrdn);
-
-	dwc3_data->rstc_rst = devm_reset_control_get(dev, "softreset");
-	if (IS_ERR(dwc3_data->rstc_rst)) {
-		dev_err(&pdev->dev, "could not get reset controller\n");
-		ret = PTR_ERR(dwc3_data->rstc_rst);
-		goto undo_powerdown;
-	}
-
-	/* Manage SoftReset */
-	reset_control_deassert(dwc3_data->rstc_rst);
-
-	child = of_get_child_by_name(node, "dwc3");
-	if (!child) {
-		dev_err(&pdev->dev, "failed to find dwc3 core node\n");
-		ret = -ENODEV;
-		goto undo_softreset;
-	}
-
-	dwc3_data->dr_mode = of_usb_get_dr_mode(child);
-
-	/* Allocate and initialize the core */
-	ret = of_platform_populate(node, NULL, NULL, dev);
-	if (ret) {
-		dev_err(dev, "failed to add dwc3 core\n");
-		goto undo_softreset;
-	}
-
-	/*
-	 * Configure the USB port as device or host according to the static
-	 * configuration passed from DT.
-	 * DRD is the only mode currently supported so this will be enhanced
-	 * as soon as OTG is available.
-	 */
-	ret = st_dwc3_drd_init(dwc3_data);
-	if (ret) {
-		dev_err(dev, "drd initialisation failed\n");
-		goto undo_softreset;
-	}
-
-	/* ST glue logic init */
-	st_dwc3_init(dwc3_data);
-
-	platform_set_drvdata(pdev, dwc3_data);
-	return 0;
-
-undo_softreset:
-	reset_control_assert(dwc3_data->rstc_rst);
-undo_powerdown:
-	reset_control_assert(dwc3_data->rstc_pwrdn);
-undo_platform_dev_alloc:
-	platform_device_put(pdev);
-	return ret;
-}
-
-static int st_dwc3_remove(struct platform_device *pdev)
-{
-	struct st_dwc3 *dwc3_data = platform_get_drvdata(pdev);
-
-	of_platform_depopulate(&pdev->dev);
-
-	reset_control_assert(dwc3_data->rstc_pwrdn);
-	reset_control_assert(dwc3_data->rstc_rst);
-
-	return 0;
-}
-
-#ifdef CONFIG_PM_SLEEP
-static int st_dwc3_suspend(struct device *dev)
-{
-	struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
-
-	reset_control_assert(dwc3_data->rstc_pwrdn);
-	reset_control_assert(dwc3_data->rstc_rst);
-
-	pinctrl_pm_select_sleep_state(dev);
-
-	return 0;
-}
-
-static int st_dwc3_resume(struct device *dev)
-{
-	struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
-	int ret;
-
-	pinctrl_pm_select_default_state(dev);
-
-	reset_control_deassert(dwc3_data->rstc_pwrdn);
-	reset_control_deassert(dwc3_data->rstc_rst);
-
-	ret = st_dwc3_drd_init(dwc3_data);
-	if (ret) {
-		dev_err(dev, "drd initialisation failed\n");
-		return ret;
-	}
-
-	/* ST glue logic init */
-	st_dwc3_init(dwc3_data);
-
-	return 0;
-}
-#endif /* CONFIG_PM_SLEEP */
-
-static SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume);
-
-static const struct of_device_id st_dwc3_match[] = {
-	{ .compatible = "st,stih407-dwc3" },
-	{ /* sentinel */ },
-};
-
-MODULE_DEVICE_TABLE(of, st_dwc3_match);
-
-static struct platform_driver st_dwc3_driver = {
-	.probe = st_dwc3_probe,
-	.remove = st_dwc3_remove,
-	.driver = {
-		.name = "usb-st-dwc3",
-		.of_match_table = st_dwc3_match,
-		.pm = &st_dwc3_dev_pm_ops,
-	},
-};
-
-module_platform_driver(st_dwc3_driver);
-
-MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
-MODULE_DESCRIPTION("DesignWare USB3 STi Glue Layer");
-MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
deleted file mode 100644
index 12bfd3c..0000000
--- a/drivers/usb/dwc3/host.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * host.c - DesignWare USB3 DRD Controller Host Glue
- *
- * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
- *
- * Authors: Felipe Balbi <balbi@ti.com>,
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#include <linux/platform_device.h>
-#include <linux/usb/xhci_pdriver.h>
-
-#include "core.h"
-
-int dwc3_host_init(struct dwc3 *dwc)
-{
-	struct platform_device	*xhci;
-	struct usb_xhci_pdata	pdata;
-	int			ret;
-
-	xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
-	if (!xhci) {
-		dev_err(dwc->dev, "couldn't allocate xHCI device\n");
-		return -ENOMEM;
-	}
-
-	dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
-
-	xhci->dev.parent	= dwc->dev;
-	xhci->dev.dma_mask	= dwc->dev->dma_mask;
-	xhci->dev.dma_parms	= dwc->dev->dma_parms;
-
-	dwc->xhci = xhci;
-
-	ret = platform_device_add_resources(xhci, dwc->xhci_resources,
-						DWC3_XHCI_RESOURCES_NUM);
-	if (ret) {
-		dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
-		goto err1;
-	}
-
-	memset(&pdata, 0, sizeof(pdata));
-
-#ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE
-	pdata.usb3_lpm_capable = 1;
-#endif
-
-	ret = platform_device_add_data(xhci, &pdata, sizeof(pdata));
-	if (ret) {
-		dev_err(dwc->dev, "couldn't add platform data to xHCI device\n");
-		goto err1;
-	}
-
-	phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&xhci->dev));
-	phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&xhci->dev));
-
-	ret = platform_device_add(xhci);
-	if (ret) {
-		dev_err(dwc->dev, "failed to register xHCI device\n");
-		goto err2;
-	}
-
-	return 0;
-err2:
-	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&xhci->dev));
-	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&xhci->dev));
-err1:
-	platform_device_put(xhci);
-	return ret;
-}
-
-void dwc3_host_exit(struct dwc3 *dwc)
-{
-	phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
-			  dev_name(&dwc->xhci->dev));
-	phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
-			  dev_name(&dwc->xhci->dev));
-	platform_device_unregister(dwc->xhci);
-}
diff --git a/drivers/usb/dwc3/platform_data.h b/drivers/usb/dwc3/platform_data.h
deleted file mode 100644
index a3a3b6d..0000000
--- a/drivers/usb/dwc3/platform_data.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * platform_data.h - USB DWC3 Platform Data Support
- *
- * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
- * Author: Felipe Balbi <balbi@ti.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include <linux/usb/ch9.h>
-#include <linux/usb/otg.h>
-
-struct dwc3_platform_data {
-	enum usb_device_speed maximum_speed;
-	enum usb_dr_mode dr_mode;
-	bool tx_fifo_resize;
-
-	unsigned is_utmi_l1_suspend:1;
-	u8 hird_threshold;
-
-	u8 lpm_nyet_threshold;
-
-	unsigned disable_scramble_quirk:1;
-	unsigned has_lpm_erratum:1;
-	unsigned u2exit_lfps_quirk:1;
-	unsigned u2ss_inp3_quirk:1;
-	unsigned req_p1p2p3_quirk:1;
-	unsigned del_p1p2p3_quirk:1;
-	unsigned del_phy_power_chg_quirk:1;
-	unsigned lfps_filter_quirk:1;
-	unsigned rx_detect_poll_quirk:1;
-	unsigned dis_u3_susphy_quirk:1;
-	unsigned dis_u2_susphy_quirk:1;
-
-	unsigned tx_de_emphasis_quirk:1;
-	unsigned tx_de_emphasis:2;
-};
diff --git a/drivers/usb/dwc3/trace.c b/drivers/usb/dwc3/trace.c
deleted file mode 100644
index 6cd1664..0000000
--- a/drivers/usb/dwc3/trace.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * trace.c - DesignWare USB3 DRD Controller Trace Support
- *
- * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
- *
- * Author: Felipe Balbi <balbi@ti.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#define CREATE_TRACE_POINTS
-#include "trace.h"
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
deleted file mode 100644
index 9fc20b3..0000000
--- a/drivers/usb/dwc3/trace.h
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- * trace.h - DesignWare USB3 DRD Controller Trace Support
- *
- * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
- *
- * Author: Felipe Balbi <balbi@ti.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
- *
- * 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.
- */
-
-#undef TRACE_SYSTEM
-#define TRACE_SYSTEM dwc3
-
-#if !defined(__DWC3_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
-#define __DWC3_TRACE_H
-
-#include <linux/types.h>
-#include <linux/tracepoint.h>
-#include <asm/byteorder.h>
-#include "core.h"
-#include "debug.h"
-
-DECLARE_EVENT_CLASS(dwc3_log_msg,
-	TP_PROTO(struct va_format *vaf),
-	TP_ARGS(vaf),
-	TP_STRUCT__entry(__dynamic_array(char, msg, DWC3_MSG_MAX)),
-	TP_fast_assign(
-		vsnprintf(__get_str(msg), DWC3_MSG_MAX, vaf->fmt, *vaf->va);
-	),
-	TP_printk("%s", __get_str(msg))
-);
-
-DEFINE_EVENT(dwc3_log_msg, dwc3_readl,
-	TP_PROTO(struct va_format *vaf),
-	TP_ARGS(vaf)
-);
-
-DEFINE_EVENT(dwc3_log_msg, dwc3_writel,
-	TP_PROTO(struct va_format *vaf),
-	TP_ARGS(vaf)
-);
-
-DEFINE_EVENT(dwc3_log_msg, dwc3_ep0,
-	TP_PROTO(struct va_format *vaf),
-	TP_ARGS(vaf)
-);
-
-DECLARE_EVENT_CLASS(dwc3_log_event,
-	TP_PROTO(u32 event),
-	TP_ARGS(event),
-	TP_STRUCT__entry(
-		__field(u32, event)
-	),
-	TP_fast_assign(
-		__entry->event = event;
-	),
-	TP_printk("event %08x", __entry->event)
-);
-
-DEFINE_EVENT(dwc3_log_event, dwc3_event,
-	TP_PROTO(u32 event),
-	TP_ARGS(event)
-);
-
-DECLARE_EVENT_CLASS(dwc3_log_ctrl,
-	TP_PROTO(struct usb_ctrlrequest *ctrl),
-	TP_ARGS(ctrl),
-	TP_STRUCT__entry(
-		__field(__u8, bRequestType)
-		__field(__u8, bRequest)
-		__field(__le16, wValue)
-		__field(__le16, wIndex)
-		__field(__le16, wLength)
-	),
-	TP_fast_assign(
-		__entry->bRequestType = ctrl->bRequestType;
-		__entry->bRequest = ctrl->bRequest;
-		__entry->wValue = ctrl->wValue;
-		__entry->wIndex = ctrl->wIndex;
-		__entry->wLength = ctrl->wLength;
-	),
-	TP_printk("bRequestType %02x bRequest %02x wValue %04x wIndex %04x wLength %d",
-		__entry->bRequestType, __entry->bRequest,
-		le16_to_cpu(__entry->wValue), le16_to_cpu(__entry->wIndex),
-		le16_to_cpu(__entry->wLength)
-	)
-);
-
-DEFINE_EVENT(dwc3_log_ctrl, dwc3_ctrl_req,
-	TP_PROTO(struct usb_ctrlrequest *ctrl),
-	TP_ARGS(ctrl)
-);
-
-DECLARE_EVENT_CLASS(dwc3_log_request,
-	TP_PROTO(struct dwc3_request *req),
-	TP_ARGS(req),
-	TP_STRUCT__entry(
-		__dynamic_array(char, name, DWC3_MSG_MAX)
-		__field(struct dwc3_request *, req)
-		__field(unsigned, actual)
-		__field(unsigned, length)
-		__field(int, status)
-	),
-	TP_fast_assign(
-		snprintf(__get_str(name), DWC3_MSG_MAX, "%s", req->dep->name);
-		__entry->req = req;
-		__entry->actual = req->request.actual;
-		__entry->length = req->request.length;
-		__entry->status = req->request.status;
-	),
-	TP_printk("%s: req %p length %u/%u ==> %d",
-		__get_str(name), __entry->req, __entry->actual, __entry->length,
-		__entry->status
-	)
-);
-
-DEFINE_EVENT(dwc3_log_request, dwc3_alloc_request,
-	TP_PROTO(struct dwc3_request *req),
-	TP_ARGS(req)
-);
-
-DEFINE_EVENT(dwc3_log_request, dwc3_free_request,
-	TP_PROTO(struct dwc3_request *req),
-	TP_ARGS(req)
-);
-
-DEFINE_EVENT(dwc3_log_request, dwc3_ep_queue,
-	TP_PROTO(struct dwc3_request *req),
-	TP_ARGS(req)
-);
-
-DEFINE_EVENT(dwc3_log_request, dwc3_ep_dequeue,
-	TP_PROTO(struct dwc3_request *req),
-	TP_ARGS(req)
-);
-
-DEFINE_EVENT(dwc3_log_request, dwc3_gadget_giveback,
-	TP_PROTO(struct dwc3_request *req),
-	TP_ARGS(req)
-);
-
-DECLARE_EVENT_CLASS(dwc3_log_generic_cmd,
-	TP_PROTO(unsigned int cmd, u32 param),
-	TP_ARGS(cmd, param),
-	TP_STRUCT__entry(
-		__field(unsigned int, cmd)
-		__field(u32, param)
-	),
-	TP_fast_assign(
-		__entry->cmd = cmd;
-		__entry->param = param;
-	),
-	TP_printk("cmd '%s' [%d] param %08x",
-		dwc3_gadget_generic_cmd_string(__entry->cmd),
-		__entry->cmd, __entry->param
-	)
-);
-
-DEFINE_EVENT(dwc3_log_generic_cmd, dwc3_gadget_generic_cmd,
-	TP_PROTO(unsigned int cmd, u32 param),
-	TP_ARGS(cmd, param)
-);
-
-DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd,
-	TP_PROTO(struct dwc3_ep *dep, unsigned int cmd,
-		struct dwc3_gadget_ep_cmd_params *params),
-	TP_ARGS(dep, cmd, params),
-	TP_STRUCT__entry(
-		__dynamic_array(char, name, DWC3_MSG_MAX)
-		__field(unsigned int, cmd)
-		__field(u32, param0)
-		__field(u32, param1)
-		__field(u32, param2)
-	),
-	TP_fast_assign(
-		snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name);
-		__entry->cmd = cmd;
-		__entry->param0 = params->param0;
-		__entry->param1 = params->param1;
-		__entry->param2 = params->param2;
-	),
-	TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x",
-		__get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd),
-		__entry->cmd, __entry->param0,
-		__entry->param1, __entry->param2
-	)
-);
-
-DEFINE_EVENT(dwc3_log_gadget_ep_cmd, dwc3_gadget_ep_cmd,
-	TP_PROTO(struct dwc3_ep *dep, unsigned int cmd,
-		struct dwc3_gadget_ep_cmd_params *params),
-	TP_ARGS(dep, cmd, params)
-);
-
-DECLARE_EVENT_CLASS(dwc3_log_trb,
-	TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
-	TP_ARGS(dep, trb),
-	TP_STRUCT__entry(
-		__dynamic_array(char, name, DWC3_MSG_MAX)
-		__field(struct dwc3_trb *, trb)
-		__field(u32, bpl)
-		__field(u32, bph)
-		__field(u32, size)
-		__field(u32, ctrl)
-	),
-	TP_fast_assign(
-		snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name);
-		__entry->trb = trb;
-		__entry->bpl = trb->bpl;
-		__entry->bph = trb->bph;
-		__entry->size = trb->size;
-		__entry->ctrl = trb->ctrl;
-	),
-	TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x",
-		__get_str(name), __entry->trb, __entry->bph, __entry->bpl,
-		__entry->size, __entry->ctrl
-	)
-);
-
-DEFINE_EVENT(dwc3_log_trb, dwc3_prepare_trb,
-	TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
-	TP_ARGS(dep, trb)
-);
-
-DEFINE_EVENT(dwc3_log_trb, dwc3_complete_trb,
-	TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
-	TP_ARGS(dep, trb)
-);
-
-#endif /* __DWC3_TRACE_H */
-
-/* this part has to be here */
-
-#undef TRACE_INCLUDE_PATH
-#define TRACE_INCLUDE_PATH .
-
-#undef TRACE_INCLUDE_FILE
-#define TRACE_INCLUDE_FILE trace
-
-#include <trace/define_trace.h>
-- 
1.7.9.5

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

* [U-Boot] [u-boot 09/40] usb: dwc3: Modify the file headers to u-boot format
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (7 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 08/40] usb: dwc3: remove un-used files from dwc3 folder Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:21   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 10/40] usb: dwc3: remove trace_* APIs from dwc3 driver Kishon Vijay Abraham I
                   ` (31 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Modified the file header to the format that is used in u-boot. Also
included in the header, the commit in linux kernel from which each of
these files are added.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.c      |   15 +++++----------
 drivers/usb/dwc3/core.h      |   15 +++++++--------
 drivers/usb/dwc3/dwc3-omap.c |   14 ++++++--------
 drivers/usb/dwc3/ep0.c       |   14 ++++++--------
 drivers/usb/dwc3/gadget.c    |   14 ++++++--------
 drivers/usb/dwc3/gadget.h    |   16 ++++++++--------
 drivers/usb/dwc3/io.h        |   15 +++++++--------
 7 files changed, 45 insertions(+), 58 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 25ddc39..b79a8b3 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1,22 +1,17 @@
 /**
  * core.c - DesignWare USB3 DRD Controller Core file
  *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/core.c) and ported
+ * to uboot.
  *
- * 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.
+ * commit cd72f890d2 : usb: dwc3: core: enable phy suspend quirk on non-FPGA
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier:     GPL-2.0
  */
 
 #include <linux/version.h>
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 4bb9aa6..09cec53 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1,19 +1,18 @@
 /**
  * core.h - DesignWare USB3 DRD Core Header
  *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/core.h) and ported
+ * to uboot.
+ *
+ * commit 460d098cb6 : usb: dwc3: make HIRD threshold configurable
+ *
+ * SPDX-License-Identifier:     GPL-2.0
  *
- * 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.
  */
 
 #ifndef __DRIVERS_USB_DWC3_CORE_H
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 172d64e..12b57cf 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -1,19 +1,17 @@
 /**
  * dwc3-omap.c - OMAP Specific Glue layer
  *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/dwc3-omap.c) and ported
+ * to uboot.
  *
- * 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.
+ * commit 7ee2566ff5 : usb: dwc3: dwc3-omap: get rid of ->prepare()/->complete()
+ *
+ * SPDX-License-Identifier:     GPL-2.0
  */
 
 #include <linux/module.h>
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 1bc77a3..c9fcb77 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -1,19 +1,17 @@
 /**
  * ep0.c - DesignWare USB3 DRD Controller Endpoint 0 Handling
  *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/ep0.c) and ported
+ * to uboot.
  *
- * 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.
+ * commit c00552ebaf : Merge 3.18-rc7 into usb-next
+ *
+ * SPDX-License-Identifier:     GPL-2.0
  */
 
 #include <linux/kernel.h>
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f03b136..0aefc5c 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1,19 +1,17 @@
 /**
  * gadget.c - DesignWare USB3 DRD Controller Gadget Framework Link
  *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/gadget.c) and ported
+ * to uboot.
  *
- * 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.
+ * commit 8e74475b0e : usb: dwc3: gadget: use udc-core's reset notifier
+ *
+ * SPDX-License-Identifier:     GPL-2.0
  */
 
 #include <linux/kernel.h>
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index 18ae3ea..042e247 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -1,19 +1,19 @@
 /**
  * gadget.h - DesignWare USB3 DRD Gadget Header
  *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/gadget.h) and ported
+ * to uboot.
+ *
+ * commit 7a60855972 : usb: dwc3: gadget: fix set_halt() bug with pending
+		       transfers
+ *
+ * SPDX-License-Identifier:     GPL-2.0
  *
- * 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.
  */
 
 #ifndef __DRIVERS_USB_DWC3_GADGET_H
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index 6a79c8e..87a1ae6 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -1,19 +1,18 @@
 /**
  * io.h - DesignWare USB3 DRD IO Header
  *
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2  of
- * the License as published by the Free Software Foundation.
+ * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/io.h) and ported
+ * to uboot.
+ *
+ * commit 2c4cbe6e5a : usb: dwc3: add tracepoints to aid debugging
+ *
+ * SPDX-License-Identifier:     GPL-2.0
  *
- * 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.
  */
 
 #ifndef __DRIVERS_USB_DWC3_IO_H
-- 
1.7.9.5

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

* [U-Boot] [u-boot 10/40] usb: dwc3: remove trace_* APIs from dwc3 driver
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (8 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 09/40] usb: dwc3: Modify the file headers to u-boot format Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:24   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 11/40] usb: dwc3: fix dwc3 header files Kishon Vijay Abraham I
                   ` (30 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Removed most of the trace_* APIs from dwc3 driver since tracepoints are not
supported in u-boot. Replaced some of the trace_* API with dev_dbg/dev/vdbg.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/Makefile |    5 +---
 drivers/usb/dwc3/ep0.c    |   70 ++++++++++++++++++---------------------------
 drivers/usb/dwc3/gadget.c |   17 -----------
 drivers/usb/dwc3/io.h     |   17 -----------
 4 files changed, 29 insertions(+), 80 deletions(-)

diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index bb34fbc..afaa767 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -1,12 +1,9 @@
-# define_trace.h needs to know how to find our header
-CFLAGS_trace.o				:= -I$(src)
-
 ccflags-$(CONFIG_USB_DWC3_DEBUG)	:= -DDEBUG
 ccflags-$(CONFIG_USB_DWC3_VERBOSE)	+= -DVERBOSE_DEBUG
 
 obj-$(CONFIG_USB_DWC3)			+= dwc3.o
 
-dwc3-y					:= core.o debug.o trace.o
+dwc3-y					:= core.o debug.o
 
 ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
 	dwc3-y				+= host.o
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index c9fcb77..1751b1d 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -64,7 +64,7 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
 
 	dep = dwc->eps[epnum];
 	if (dep->flags & DWC3_EP_BUSY) {
-		dwc3_trace(trace_dwc3_ep0, "%s still busy", dep->name);
+		dev_vdbg(dwc->dev, "%s still busy", dep->name);
 		return 0;
 	}
 
@@ -84,13 +84,10 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
 	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
 	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
 
-	trace_dwc3_prepare_trb(dep, trb);
-
 	ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
 			DWC3_DEPCMD_STARTTRANSFER, &params);
 	if (ret < 0) {
-		dwc3_trace(trace_dwc3_ep0, "%s STARTTRANSFER failed",
-				dep->name);
+		dev_dbg(dwc->dev, "%s STARTTRANSFER failed", dep->name);
 		return ret;
 	}
 
@@ -155,8 +152,7 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
 		if (dwc->ep0state == EP0_STATUS_PHASE)
 			__dwc3_ep0_do_control_status(dwc, dwc->eps[direction]);
 		else
-			dwc3_trace(trace_dwc3_ep0,
-					"too early for delayed status");
+			dev_dbg(dwc->dev, "too early for delayed status");
 
 		return 0;
 	}
@@ -220,8 +216,7 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
 
 	spin_lock_irqsave(&dwc->lock, flags);
 	if (!dep->endpoint.desc) {
-		dwc3_trace(trace_dwc3_ep0,
-				"trying to queue request %p to disabled %s",
+		dev_dbg(dwc->dev, "trying to queue request %p to disabled %s",
 				request, dep->name);
 		ret = -ESHUTDOWN;
 		goto out;
@@ -233,8 +228,7 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
 		goto out;
 	}
 
-	dwc3_trace(trace_dwc3_ep0,
-			"queueing request %p to %s length %d state '%s'",
+	dev_vdbg(dwc->dev, "queueing request %p to %s length %d state '%s'",
 			request, dep->name, request->length,
 			dwc3_ep0_state_string(dwc->ep0state));
 
@@ -503,13 +497,12 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
 
 	addr = le16_to_cpu(ctrl->wValue);
 	if (addr > 127) {
-		dwc3_trace(trace_dwc3_ep0, "invalid device address %d", addr);
+		dev_dbg(dwc->dev, "invalid device address %d", addr);
 		return -EINVAL;
 	}
 
 	if (state == USB_STATE_CONFIGURED) {
-		dwc3_trace(trace_dwc3_ep0,
-				"trying to set address when configured");
+		dev_dbg(dwc->dev, "trying to set address when configured");
 		return -EINVAL;
 	}
 
@@ -574,7 +567,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
 			dwc3_writel(dwc->regs, DWC3_DCTL, reg);
 
 			dwc->resize_fifos = true;
-			dwc3_trace(trace_dwc3_ep0, "resize FIFOs flag SET");
+			dev_dbg(dwc->dev, "resize FIFOs flag SET");
 		}
 		break;
 
@@ -698,35 +691,35 @@ static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
 
 	switch (ctrl->bRequest) {
 	case USB_REQ_GET_STATUS:
-		dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS");
+		dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS");
 		ret = dwc3_ep0_handle_status(dwc, ctrl);
 		break;
 	case USB_REQ_CLEAR_FEATURE:
-		dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE");
+		dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE");
 		ret = dwc3_ep0_handle_feature(dwc, ctrl, 0);
 		break;
 	case USB_REQ_SET_FEATURE:
-		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE");
+		dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE");
 		ret = dwc3_ep0_handle_feature(dwc, ctrl, 1);
 		break;
 	case USB_REQ_SET_ADDRESS:
-		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS");
+		dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS");
 		ret = dwc3_ep0_set_address(dwc, ctrl);
 		break;
 	case USB_REQ_SET_CONFIGURATION:
-		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_CONFIGURATION");
+		dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION");
 		ret = dwc3_ep0_set_config(dwc, ctrl);
 		break;
 	case USB_REQ_SET_SEL:
-		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL");
+		dev_vdbg(dwc->dev, "USB_REQ_SET_SEL");
 		ret = dwc3_ep0_set_sel(dwc, ctrl);
 		break;
 	case USB_REQ_SET_ISOCH_DELAY:
-		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ISOCH_DELAY");
+		dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY");
 		ret = dwc3_ep0_set_isoch_delay(dwc, ctrl);
 		break;
 	default:
-		dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget driver");
+		dev_vdbg(dwc->dev, "Forwarding to gadget driver");
 		ret = dwc3_ep0_delegate_req(dwc, ctrl);
 		break;
 	}
@@ -744,8 +737,6 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
 	if (!dwc->gadget_driver)
 		goto out;
 
-	trace_dwc3_ctrl_req(ctrl);
-
 	len = le16_to_cpu(ctrl->wLength);
 	if (!len) {
 		dwc->three_stage_setup = false;
@@ -789,15 +780,13 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 
 	trb = dwc->ep0_trb;
 
-	trace_dwc3_complete_trb(ep0, trb);
-
 	r = next_request(&ep0->request_list);
 	if (!r)
 		return;
 
 	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
 	if (status == DWC3_TRBSTS_SETUP_PENDING) {
-		dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
+		dev_dbg(dwc->dev, "Setup Pending received");
 
 		if (r)
 			dwc3_gadget_giveback(ep0, r, -ECONNRESET);
@@ -855,8 +844,6 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc,
 	dep = dwc->eps[0];
 	trb = dwc->ep0_trb;
 
-	trace_dwc3_complete_trb(dep, trb);
-
 	if (!list_empty(&dep->request_list)) {
 		r = next_request(&dep->request_list);
 
@@ -868,7 +855,7 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc,
 
 		ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr);
 		if (ret < 0) {
-			dwc3_trace(trace_dwc3_ep0, "Invalid Test #%d",
+			dev_dbg(dwc->dev, "Invalid Test #%d",
 					dwc->test_mode_nr);
 			dwc3_ep0_stall_and_restart(dwc);
 			return;
@@ -877,7 +864,7 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc,
 
 	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
 	if (status == DWC3_TRBSTS_SETUP_PENDING)
-		dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
+		dev_dbg(dwc->dev, "Setup Pending received");
 
 	dwc->ep0state = EP0_SETUP_PHASE;
 	dwc3_ep0_out_start(dwc);
@@ -894,17 +881,17 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
 
 	switch (dwc->ep0state) {
 	case EP0_SETUP_PHASE:
-		dwc3_trace(trace_dwc3_ep0, "Setup Phase");
+		dev_vdbg(dwc->dev, "Setup Phase");
 		dwc3_ep0_inspect_setup(dwc, event);
 		break;
 
 	case EP0_DATA_PHASE:
-		dwc3_trace(trace_dwc3_ep0, "Data Phase");
+		dev_vdbg(dwc->dev, "Data Phase");
 		dwc3_ep0_complete_data(dwc, event);
 		break;
 
 	case EP0_STATUS_PHASE:
-		dwc3_trace(trace_dwc3_ep0, "Status Phase");
+		dev_vdbg(dwc->dev, "Status Phase");
 		dwc3_ep0_complete_status(dwc, event);
 		break;
 	default:
@@ -980,7 +967,7 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
 {
 	if (dwc->resize_fifos) {
-		dwc3_trace(trace_dwc3_ep0, "Resizing FIFOs");
+		dev_dbg(dwc->dev, "Resizing FIFOs");
 		dwc3_gadget_resize_tx_fifos(dwc);
 		dwc->resize_fifos = 0;
 	}
@@ -1021,7 +1008,7 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
 
 	switch (event->status) {
 	case DEPEVT_STATUS_CONTROL_DATA:
-		dwc3_trace(trace_dwc3_ep0, "Control Data");
+		dev_vdbg(dwc->dev, "Control Data");
 
 		/*
 		 * We already have a DATA transfer in the controller's cache,
@@ -1035,8 +1022,7 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
 		if (dwc->ep0_expect_in != event->endpoint_number) {
 			struct dwc3_ep	*dep = dwc->eps[dwc->ep0_expect_in];
 
-			dwc3_trace(trace_dwc3_ep0,
-					"Wrong direction for Data phase");
+			dev_vdbg(dwc->dev, "Wrong direction for Data phase");
 			dwc3_ep0_end_control_data(dwc, dep);
 			dwc3_ep0_stall_and_restart(dwc);
 			return;
@@ -1048,13 +1034,13 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
 		if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS)
 			return;
 
-		dwc3_trace(trace_dwc3_ep0, "Control Status");
+		dev_vdbg(dwc->dev, "Control Status");
 
 		dwc->ep0state = EP0_STATUS_PHASE;
 
 		if (dwc->delayed_status) {
 			WARN_ON_ONCE(event->endpoint_number != 1);
-			dwc3_trace(trace_dwc3_ep0, "Delayed Status");
+			dev_vdbg(dwc->dev, "Delayed Status");
 			return;
 		}
 
@@ -1067,7 +1053,7 @@ void dwc3_ep0_interrupt(struct dwc3 *dwc,
 {
 	u8			epnum = event->endpoint_number;
 
-	dwc3_trace(trace_dwc3_ep0, "%s while ep%d%s in state '%s'",
+	dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'",
 			dwc3_ep_event_string(event->endpoint_event),
 			epnum >> 1, (epnum & 1) ? "in" : "out",
 			dwc3_ep0_state_string(dwc->ep0state));
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0aefc5c..ca0f0cd 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -265,7 +265,6 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 	dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n",
 			req, dep->name, req->request.actual,
 			req->request.length, status);
-	trace_dwc3_gadget_giveback(req);
 
 	spin_unlock(&dwc->lock);
 	usb_gadget_giveback_request(&dep->endpoint, &req->request);
@@ -277,8 +276,6 @@ int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param)
 	u32		timeout = 500;
 	u32		reg;
 
-	trace_dwc3_gadget_generic_cmd(cmd, param);
-
 	dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param);
 	dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT);
 
@@ -308,8 +305,6 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
 	u32			timeout = 500;
 	u32			reg;
 
-	trace_dwc3_gadget_ep_cmd(dep, cmd, params);
-
 	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0);
 	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1);
 	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR2(ep), params->param2);
@@ -704,8 +699,6 @@ static struct usb_request *dwc3_gadget_ep_alloc_request(struct usb_ep *ep,
 	req->epnum	= dep->number;
 	req->dep	= dep;
 
-	trace_dwc3_alloc_request(req);
-
 	return &req->request;
 }
 
@@ -714,7 +707,6 @@ static void dwc3_gadget_ep_free_request(struct usb_ep *ep,
 {
 	struct dwc3_request		*req = to_dwc3_request(request);
 
-	trace_dwc3_free_request(req);
 	kfree(req);
 }
 
@@ -796,8 +788,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
 		trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id);
 
 	trb->ctrl |= DWC3_TRB_CTRL_HWO;
-
-	trace_dwc3_prepare_trb(dep, trb);
 }
 
 /*
@@ -1150,7 +1140,6 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
 
 	dev_vdbg(dwc->dev, "queing request %p to %s length %d\n",
 			request, ep->name, request->length);
-	trace_dwc3_ep_queue(req);
 
 	ret = __dwc3_gadget_ep_queue(dep, req);
 
@@ -1172,8 +1161,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
 	unsigned long			flags;
 	int				ret = 0;
 
-	trace_dwc3_ep_dequeue(req);
-
 	spin_lock_irqsave(&dwc->lock, flags);
 
 	list_for_each_entry(r, &dep->request_list, list) {
@@ -1771,8 +1758,6 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
 	unsigned int		s_pkt = 0;
 	unsigned int		trb_status;
 
-	trace_dwc3_complete_trb(dep, trb);
-
 	if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN)
 		/*
 		 * We continue despite the error. There is not much we
@@ -2529,8 +2514,6 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc,
 static void dwc3_process_event_entry(struct dwc3 *dwc,
 		const union dwc3_event *event)
 {
-	trace_dwc3_event(event->raw);
-
 	/* Endpoint IRQ, handle it and return early */
 	if (event->type.is_devspec == 0) {
 		/* depevt */
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index 87a1ae6..f9f22b0 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -19,7 +19,6 @@
 #define __DRIVERS_USB_DWC3_IO_H
 
 #include <linux/io.h>
-#include "trace.h"
 #include "debug.h"
 #include "core.h"
 
@@ -35,14 +34,6 @@ static inline u32 dwc3_readl(void __iomem *base, u32 offset)
 	 */
 	value = readl(base + offs);
 
-	/*
-	 * When tracing we want to make it easy to find the correct address on
-	 * documentation, so we revert it back to the proper addresses, the
-	 * same way they are described on SNPS documentation
-	 */
-	dwc3_trace(trace_dwc3_readl, "addr %p value %08x",
-			base - DWC3_GLOBALS_REGS_START + offset, value);
-
 	return value;
 }
 
@@ -56,14 +47,6 @@ static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
 	 * However, the offsets are given starting from xHCI address space.
 	 */
 	writel(value, base + offs);
-
-	/*
-	 * When tracing we want to make it easy to find the correct address on
-	 * documentation, so we revert it back to the proper addresses, the
-	 * same way they are described on SNPS documentation
-	 */
-	dwc3_trace(trace_dwc3_writel, "addr %p value %08x",
-			base - DWC3_GLOBALS_REGS_START + offset, value);
 }
 
 #endif /* __DRIVERS_USB_DWC3_IO_H */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 11/40] usb: dwc3: fix dwc3 header files
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (9 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 10/40] usb: dwc3: remove trace_* APIs from dwc3 driver Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:25   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 12/40] usb: dwc3: remove pm related operations from dwc3 driver Kishon Vijay Abraham I
                   ` (29 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Changed the header files included in core.h and io.h to the u-boot header
files so that these files can be included in other dwc3 source files and
be compiled in uboot. Also added otg.h which has the defines for dr_mode.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.h |   13 ++-----------
 drivers/usb/dwc3/io.h   |    4 +---
 include/linux/usb/otg.h |   20 ++++++++++++++++++++
 3 files changed, 23 insertions(+), 14 deletions(-)
 create mode 100644 include/linux/usb/otg.h

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 09cec53..a7a7082 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -18,20 +18,11 @@
 #ifndef __DRIVERS_USB_DWC3_CORE_H
 #define __DRIVERS_USB_DWC3_CORE_H
 
-#include <linux/device.h>
-#include <linux/spinlock.h>
 #include <linux/ioport.h>
-#include <linux/list.h>
-#include <linux/dma-mapping.h>
-#include <linux/mm.h>
-#include <linux/debugfs.h>
 
 #include <linux/usb/ch9.h>
-#include <linux/usb/gadget.h>
 #include <linux/usb/otg.h>
 
-#include <linux/phy/phy.h>
-
 #define DWC3_MSG_MAX	500
 
 /* Global constants */
@@ -981,7 +972,7 @@ struct dwc3_gadget_ep_cmd_params {
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
 int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
 
-#if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
+#ifdef CONFIG_USB_DWC3_HOST
 int dwc3_host_init(struct dwc3 *dwc);
 void dwc3_host_exit(struct dwc3 *dwc);
 #else
@@ -991,7 +982,7 @@ static inline void dwc3_host_exit(struct dwc3 *dwc)
 { }
 #endif
 
-#if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
+#ifdef CONFIG_USB_DWC3_GADGET
 int dwc3_gadget_init(struct dwc3 *dwc);
 void dwc3_gadget_exit(struct dwc3 *dwc);
 int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index f9f22b0..b6da135 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -18,9 +18,7 @@
 #ifndef __DRIVERS_USB_DWC3_IO_H
 #define __DRIVERS_USB_DWC3_IO_H
 
-#include <linux/io.h>
-#include "debug.h"
-#include "core.h"
+#include <asm/io.h>
 
 static inline u32 dwc3_readl(void __iomem *base, u32 offset)
 {
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
new file mode 100644
index 0000000..7ec5550
--- /dev/null
+++ b/include/linux/usb/otg.h
@@ -0,0 +1,20 @@
+/* include/linux/usb/otg.h
+ *
+ * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * USB OTG (On The Go) defines
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#ifndef __LINUX_USB_OTG_H
+#define __LINUX_USB_OTG_H
+
+enum usb_dr_mode {
+	USB_DR_MODE_UNKNOWN,
+	USB_DR_MODE_HOST,
+	USB_DR_MODE_PERIPHERAL,
+	USB_DR_MODE_OTG,
+};
+
+#endif /* __LINUX_USB_OTG_H */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 12/40] usb: dwc3: remove pm related operations from dwc3 driver
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (10 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 11/40] usb: dwc3: fix dwc3 header files Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:26   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 13/40] arm: asm: dma-mapping: added dma_free_coherent API Kishon Vijay Abraham I
                   ` (28 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Removed all pm related operations including pm_runtime APIs,
suspend/resume hooks as support for these are not present in u-boot.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.c      |   96 ------------------------------------------
 drivers/usb/dwc3/core.h      |   16 -------
 drivers/usb/dwc3/dwc3-omap.c |   61 +++------------------------
 drivers/usb/dwc3/gadget.c    |   55 ------------------------
 4 files changed, 5 insertions(+), 223 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index b79a8b3..ebfb6ca 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -20,7 +20,6 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
-#include <linux/pm_runtime.h>
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
@@ -884,10 +883,6 @@ static int dwc3_probe(struct platform_device *pdev)
 		dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
 	}
 
-	pm_runtime_enable(dev);
-	pm_runtime_get_sync(dev);
-	pm_runtime_forbid(dev);
-
 	dwc3_cache_hwparams(dwc);
 
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
@@ -937,8 +932,6 @@ static int dwc3_probe(struct platform_device *pdev)
 		goto err3;
 	}
 
-	pm_runtime_allow(dev);
-
 	return 0;
 
 err3:
@@ -980,97 +973,9 @@ static int dwc3_remove(struct platform_device *pdev)
 
 	dwc3_core_exit(dwc);
 
-	pm_runtime_put_sync(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
-
-	return 0;
-}
-
-#ifdef CONFIG_PM_SLEEP
-static int dwc3_suspend(struct device *dev)
-{
-	struct dwc3	*dwc = dev_get_drvdata(dev);
-	unsigned long	flags;
-
-	spin_lock_irqsave(&dwc->lock, flags);
-
-	switch (dwc->dr_mode) {
-	case USB_DR_MODE_PERIPHERAL:
-	case USB_DR_MODE_OTG:
-		dwc3_gadget_suspend(dwc);
-		/* FALLTHROUGH */
-	case USB_DR_MODE_HOST:
-	default:
-		dwc3_event_buffers_cleanup(dwc);
-		break;
-	}
-
-	dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
-	spin_unlock_irqrestore(&dwc->lock, flags);
-
-	usb_phy_shutdown(dwc->usb3_phy);
-	usb_phy_shutdown(dwc->usb2_phy);
-	phy_exit(dwc->usb2_generic_phy);
-	phy_exit(dwc->usb3_generic_phy);
-
 	return 0;
 }
 
-static int dwc3_resume(struct device *dev)
-{
-	struct dwc3	*dwc = dev_get_drvdata(dev);
-	unsigned long	flags;
-	int		ret;
-
-	usb_phy_init(dwc->usb3_phy);
-	usb_phy_init(dwc->usb2_phy);
-	ret = phy_init(dwc->usb2_generic_phy);
-	if (ret < 0)
-		return ret;
-
-	ret = phy_init(dwc->usb3_generic_phy);
-	if (ret < 0)
-		goto err_usb2phy_init;
-
-	spin_lock_irqsave(&dwc->lock, flags);
-
-	dwc3_event_buffers_setup(dwc);
-	dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
-
-	switch (dwc->dr_mode) {
-	case USB_DR_MODE_PERIPHERAL:
-	case USB_DR_MODE_OTG:
-		dwc3_gadget_resume(dwc);
-		/* FALLTHROUGH */
-	case USB_DR_MODE_HOST:
-	default:
-		/* do nothing */
-		break;
-	}
-
-	spin_unlock_irqrestore(&dwc->lock, flags);
-
-	pm_runtime_disable(dev);
-	pm_runtime_set_active(dev);
-	pm_runtime_enable(dev);
-
-	return 0;
-
-err_usb2phy_init:
-	phy_exit(dwc->usb2_generic_phy);
-
-	return ret;
-}
-
-static const struct dev_pm_ops dwc3_dev_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
-};
-
-#define DWC3_PM_OPS	&(dwc3_dev_pm_ops)
-#else
-#define DWC3_PM_OPS	NULL
-#endif
-
 #ifdef CONFIG_OF
 static const struct of_device_id of_dwc3_match[] = {
 	{
@@ -1102,7 +1007,6 @@ static struct platform_driver dwc3_driver = {
 		.name	= "dwc3",
 		.of_match_table	= of_match_ptr(of_dwc3_match),
 		.acpi_match_table = ACPI_PTR(dwc3_acpi_match),
-		.pm	= DWC3_PM_OPS,
 	},
 };
 
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index a7a7082..97f71ad 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1012,20 +1012,4 @@ static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
 { return 0; }
 #endif
 
-/* power management interface */
-#if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
-int dwc3_gadget_suspend(struct dwc3 *dwc);
-int dwc3_gadget_resume(struct dwc3 *dwc);
-#else
-static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
-{
-	return 0;
-}
-
-static inline int dwc3_gadget_resume(struct dwc3 *dwc)
-{
-	return 0;
-}
-#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
-
 #endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 12b57cf..ce2d6a6 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -20,7 +20,6 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/platform_data/dwc3-omap.h>
-#include <linux/pm_runtime.h>
 #include <linux/dma-mapping.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
@@ -509,13 +508,6 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 	omap->vbus_reg	= vbus_reg;
 	dev->dma_mask	= &dwc3_omap_dma_mask;
 
-	pm_runtime_enable(dev);
-	ret = pm_runtime_get_sync(dev);
-	if (ret < 0) {
-		dev_err(dev, "get_sync failed with err %d\n", ret);
-		goto err0;
-	}
-
 	dwc3_omap_map_offset(omap);
 	dwc3_omap_set_utmi_mode(omap);
 
@@ -528,38 +520,33 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 	if (ret) {
 		dev_err(dev, "failed to request IRQ #%d --> %d\n",
 				omap->irq, ret);
-		goto err1;
+		goto err0;
 	}
 
 	dwc3_omap_enable_irqs(omap);
 
 	ret = dwc3_omap_extcon_register(omap);
 	if (ret < 0)
-		goto err2;
+		goto err1;
 
 	ret = of_platform_populate(node, NULL, NULL, dev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to create dwc3 core\n");
-		goto err3;
+		goto err2;
 	}
 
 	return 0;
 
-err3:
+err2:
 	if (omap->extcon_vbus_dev.edev)
 		extcon_unregister_interest(&omap->extcon_vbus_dev);
 	if (omap->extcon_id_dev.edev)
 		extcon_unregister_interest(&omap->extcon_id_dev);
 
-err2:
-	dwc3_omap_disable_irqs(omap);
-
 err1:
-	pm_runtime_put_sync(dev);
+	dwc3_omap_disable_irqs(omap);
 
 err0:
-	pm_runtime_disable(dev);
-
 	return ret;
 }
 
@@ -573,8 +560,6 @@ static int dwc3_omap_remove(struct platform_device *pdev)
 		extcon_unregister_interest(&omap->extcon_id_dev);
 	dwc3_omap_disable_irqs(omap);
 	device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
-	pm_runtime_put_sync(&pdev->dev);
-	pm_runtime_disable(&pdev->dev);
 
 	return 0;
 }
@@ -590,48 +575,12 @@ static const struct of_device_id of_dwc3_match[] = {
 };
 MODULE_DEVICE_TABLE(of, of_dwc3_match);
 
-#ifdef CONFIG_PM_SLEEP
-static int dwc3_omap_suspend(struct device *dev)
-{
-	struct dwc3_omap	*omap = dev_get_drvdata(dev);
-
-	omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap);
-	dwc3_omap_disable_irqs(omap);
-
-	return 0;
-}
-
-static int dwc3_omap_resume(struct device *dev)
-{
-	struct dwc3_omap	*omap = dev_get_drvdata(dev);
-
-	dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status);
-	dwc3_omap_enable_irqs(omap);
-
-	pm_runtime_disable(dev);
-	pm_runtime_set_active(dev);
-	pm_runtime_enable(dev);
-
-	return 0;
-}
-
-static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
-
-	SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
-};
-
-#define DEV_PM_OPS	(&dwc3_omap_dev_pm_ops)
-#else
-#define DEV_PM_OPS	NULL
-#endif /* CONFIG_PM_SLEEP */
-
 static struct platform_driver dwc3_omap_driver = {
 	.probe		= dwc3_omap_probe,
 	.remove		= dwc3_omap_remove,
 	.driver		= {
 		.name	= "omap-dwc3",
 		.of_match_table	= of_dwc3_match,
-		.pm	= DEV_PM_OPS,
 	},
 };
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index ca0f0cd..7c932c6 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2748,58 +2748,3 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
 	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
 			dwc->ctrl_req, dwc->ctrl_req_addr);
 }
-
-int dwc3_gadget_suspend(struct dwc3 *dwc)
-{
-	if (dwc->pullups_connected) {
-		dwc3_gadget_disable_irq(dwc);
-		dwc3_gadget_run_stop(dwc, true, true);
-	}
-
-	__dwc3_gadget_ep_disable(dwc->eps[0]);
-	__dwc3_gadget_ep_disable(dwc->eps[1]);
-
-	dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG);
-
-	return 0;
-}
-
-int dwc3_gadget_resume(struct dwc3 *dwc)
-{
-	struct dwc3_ep		*dep;
-	int			ret;
-
-	/* Start with SuperSpeed Default */
-	dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
-
-	dep = dwc->eps[0];
-	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
-			false);
-	if (ret)
-		goto err0;
-
-	dep = dwc->eps[1];
-	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
-			false);
-	if (ret)
-		goto err1;
-
-	/* begin to receive SETUP packets */
-	dwc->ep0state = EP0_SETUP_PHASE;
-	dwc3_ep0_out_start(dwc);
-
-	dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg);
-
-	if (dwc->pullups_connected) {
-		dwc3_gadget_enable_irq(dwc);
-		dwc3_gadget_run_stop(dwc, true, false);
-	}
-
-	return 0;
-
-err1:
-	__dwc3_gadget_ep_disable(dwc->eps[0]);
-
-err0:
-	return ret;
-}
-- 
1.7.9.5

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

* [U-Boot] [u-boot 13/40] arm: asm: dma-mapping: added dma_free_coherent API
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (11 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 12/40] usb: dwc3: remove pm related operations from dwc3 driver Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:26   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy Kishon Vijay Abraham I
                   ` (27 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added dma_free_coherent corresponding to the dma_alloc_coherent in
dma-mapping.h in order to free memory allocated using dma_alloc_coherent.
This API is used in dwc3 driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/include/asm/dma-mapping.h |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 14f00efd2..a5821f5 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -8,6 +8,8 @@
 #ifndef __ASM_ARM_DMA_MAPPING_H
 #define __ASM_ARM_DMA_MAPPING_H
 
+#define	dma_mapping_error(x, y)	0
+
 enum dma_data_direction {
 	DMA_BIDIRECTIONAL	= 0,
 	DMA_TO_DEVICE		= 1,
@@ -20,6 +22,11 @@ static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
 	return (void *)*handle;
 }
 
+static inline void dma_free_coherent(void *addr)
+{
+	free(addr);
+}
+
 static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
 					   enum dma_data_direction dir)
 {
-- 
1.7.9.5

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (12 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 13/40] arm: asm: dma-mapping: added dma_free_coherent API Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:32   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 15/40] usb: dwc3: gadget: make dwc3 gadget build in uboot Kishon Vijay Abraham I
                   ` (26 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added a header file to include various linux specific APIs like
pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid compilation
error while building dwc3 driver.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/linux-compat.h |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 drivers/usb/dwc3/linux-compat.h

diff --git a/drivers/usb/dwc3/linux-compat.h b/drivers/usb/dwc3/linux-compat.h
new file mode 100644
index 0000000..58c4716
--- /dev/null
+++ b/drivers/usb/dwc3/linux-compat.h
@@ -0,0 +1,30 @@
+/**
+ * linux-compat.h - DesignWare USB3 Linux Compatibiltiy Adapter  Header
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Kishon Vijay Abraham I <kishon@ti.com>
+ *
+ * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
+ * to uboot.
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ *
+ */
+
+#ifndef __DWC3_LINUX_COMPAT__
+#define __DWC3_LINUX_COMPAT__
+
+#define pr_debug(format)                debug(format)
+#define WARN(val, format, arg...)	debug(format, ##arg)
+#define WARN_ON_ONCE(val)		debug("Error %d\n", val)
+
+#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
+
+static inline size_t strlcat(char *dest, const char *src, size_t n)
+{
+	strcat(dest, src);
+	return strlen(dest) + strlen(src);
+}
+
+#endif
-- 
1.7.9.5

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

* [U-Boot] [u-boot 15/40] usb: dwc3: gadget: make dwc3 gadget build in uboot
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (13 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:52   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 16/40] include: asm: types: add resource_size_t type Kishon Vijay Abraham I
                   ` (25 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Did a bunch of things to get dwc3/gadget.c compile in u-boot without
build errors and warnings
*) Changed the included header files to that used in u-boot.
*) Used dma_alloc_coherent and dma_free_coherent APIs of u-boot
*) removed sg support
*) remove jiffies and used a simple while loop
*) removed irq support and added a function to call these interrupt handler.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/gadget.c       |  244 ++++++++++++++-------------------------
 drivers/usb/dwc3/gadget.h       |    1 +
 drivers/usb/dwc3/linux-compat.h |    3 -
 include/linux/compat.h          |    1 +
 include/linux/usb/gadget.h      |   39 +++++++
 5 files changed, 125 insertions(+), 163 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 7c932c6..1f97729 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -14,25 +14,22 @@
  * SPDX-License-Identifier:     GPL-2.0
  */
 
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <linux/platform_device.h>
-#include <linux/pm_runtime.h>
-#include <linux/interrupt.h>
-#include <linux/io.h>
+#include <common.h>
+#include <malloc.h>
+#include <asm/dma-mapping.h>
+#include <usb/lin_gadget_compat.h>
 #include <linux/list.h>
-#include <linux/dma-mapping.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
+#include <asm/arch/sys_proto.h>
 
-#include "debug.h"
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
 
+#include "linux-compat.h"
+
 /**
  * dwc3_gadget_set_test_mode - Enables USB2 Test Modes
  * @dwc: pointer to our context structure
@@ -166,7 +163,6 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
 int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
 {
 	int		last_fifo_depth = 0;
-	int		ram1_depth;
 	int		fifo_size;
 	int		mdwidth;
 	int		num;
@@ -174,7 +170,6 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
 	if (!dwc->needs_fifo_resize)
 		return 0;
 
-	ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7);
 	mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
 
 	/* MDWIDTH is represented in bits, we need it in bytes */
@@ -232,24 +227,21 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 		int status)
 {
 	struct dwc3			*dwc = dep->dwc;
-	int				i;
 
 	if (req->queued) {
-		i = 0;
-		do {
+		dep->busy_slot++;
+		/*
+		 * Skip LINK TRB. We can't use req->trb and check for
+		 * DWC3_TRBCTL_LINK_TRB because it points the TRB we
+		 * just completed (not the LINK TRB).
+		 */
+		if (((dep->busy_slot & DWC3_TRB_MASK) ==
+			DWC3_TRB_NUM- 1) &&
+			usb_endpoint_xfer_isoc(dep->endpoint.desc))
 			dep->busy_slot++;
-			/*
-			 * Skip LINK TRB. We can't use req->trb and check for
-			 * DWC3_TRBCTL_LINK_TRB because it points the TRB we
-			 * just completed (not the LINK TRB).
-			 */
-			if (((dep->busy_slot & DWC3_TRB_MASK) ==
-				DWC3_TRB_NUM- 1) &&
-				usb_endpoint_xfer_isoc(dep->endpoint.desc))
-				dep->busy_slot++;
-		} while(++i < req->request.num_mapped_sgs);
 		req->queued = false;
 	}
+
 	list_del(&req->list);
 	req->trb = NULL;
 
@@ -301,7 +293,6 @@ int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param)
 int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
 		unsigned cmd, struct dwc3_gadget_ep_cmd_params *params)
 {
-	struct dwc3_ep		*dep = dwc->eps[ep];
 	u32			timeout = 500;
 	u32			reg;
 
@@ -340,17 +331,15 @@ static dma_addr_t dwc3_trb_dma_offset(struct dwc3_ep *dep,
 
 static int dwc3_alloc_trb_pool(struct dwc3_ep *dep)
 {
-	struct dwc3		*dwc = dep->dwc;
-
 	if (dep->trb_pool)
 		return 0;
 
 	if (dep->number == 0 || dep->number == 1)
 		return 0;
 
-	dep->trb_pool = dma_alloc_coherent(dwc->dev,
-			sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
-			&dep->trb_pool_dma, GFP_KERNEL);
+	dep->trb_pool = dma_alloc_coherent(sizeof(struct dwc3_trb) *
+					   DWC3_TRB_NUM,
+					   (unsigned long *)&dep->trb_pool_dma);
 	if (!dep->trb_pool) {
 		dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n",
 				dep->name);
@@ -362,10 +351,7 @@ static int dwc3_alloc_trb_pool(struct dwc3_ep *dep)
 
 static void dwc3_free_trb_pool(struct dwc3_ep *dep)
 {
-	struct dwc3		*dwc = dep->dwc;
-
-	dma_free_coherent(dwc->dev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
-			dep->trb_pool, dep->trb_pool_dma);
+	dma_free_coherent(dep->trb_pool);
 
 	dep->trb_pool = NULL;
 	dep->trb_pool_dma = 0;
@@ -607,7 +593,6 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep,
 		const struct usb_endpoint_descriptor *desc)
 {
 	struct dwc3_ep			*dep;
-	struct dwc3			*dwc;
 	unsigned long			flags;
 	int				ret;
 
@@ -622,10 +607,9 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep,
 	}
 
 	dep = to_dwc3_ep(ep);
-	dwc = dep->dwc;
 
 	if (dep->flags & DWC3_EP_ENABLED) {
-		dev_WARN_ONCE(dwc->dev, true, "%s is already enabled\n",
+		WARN(true, "%s is already enabled\n",
 				dep->name);
 		return 0;
 	}
@@ -657,7 +641,6 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep,
 static int dwc3_gadget_ep_disable(struct usb_ep *ep)
 {
 	struct dwc3_ep			*dep;
-	struct dwc3			*dwc;
 	unsigned long			flags;
 	int				ret;
 
@@ -667,10 +650,9 @@ static int dwc3_gadget_ep_disable(struct usb_ep *ep)
 	}
 
 	dep = to_dwc3_ep(ep);
-	dwc = dep->dwc;
 
 	if (!(dep->flags & DWC3_EP_ENABLED)) {
-		dev_WARN_ONCE(dwc->dev, true, "%s is already disabled\n",
+		WARN(true, "%s is already disabled\n",
 				dep->name);
 		return 0;
 	}
@@ -719,7 +701,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
 		struct dwc3_request *req, dma_addr_t dma,
 		unsigned length, unsigned last, unsigned chain, unsigned node)
 {
-	struct dwc3		*dwc = dep->dwc;
 	struct dwc3_trb		*trb;
 
 	dev_vdbg(dwc->dev, "%s: req %p dma %08llx length %d%s%s\n",
@@ -856,57 +837,22 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep, bool starting)
 		dma_addr_t	dma;
 		last_one = false;
 
-		if (req->request.num_mapped_sgs > 0) {
-			struct usb_request *request = &req->request;
-			struct scatterlist *sg = request->sg;
-			struct scatterlist *s;
-			int		i;
-
-			for_each_sg(sg, s, request->num_mapped_sgs, i) {
-				unsigned chain = true;
+		dma = req->request.dma;
+		length = req->request.length;
+		trbs_left--;
 
-				length = sg_dma_len(s);
-				dma = sg_dma_address(s);
+		if (!trbs_left)
+			last_one = 1;
 
-				if (i == (request->num_mapped_sgs - 1) ||
-						sg_is_last(s)) {
-					if (list_is_last(&req->list,
-							&dep->request_list))
-						last_one = true;
-					chain = false;
-				}
+		/* Is this the last request? */
+		if (list_is_last(&req->list, &dep->request_list))
+			last_one = 1;
 
-				trbs_left--;
-				if (!trbs_left)
-					last_one = true;
+		dwc3_prepare_one_trb(dep, req, dma, length,
+				last_one, false, 0);
 
-				if (last_one)
-					chain = false;
-
-				dwc3_prepare_one_trb(dep, req, dma, length,
-						last_one, chain, i);
-
-				if (last_one)
-					break;
-			}
-		} else {
-			dma = req->request.dma;
-			length = req->request.length;
-			trbs_left--;
-
-			if (!trbs_left)
-				last_one = 1;
-
-			/* Is this the last request? */
-			if (list_is_last(&req->list, &dep->request_list))
-				last_one = 1;
-
-			dwc3_prepare_one_trb(dep, req, dma, length,
-					last_one, false, 0);
-
-			if (last_one)
-				break;
-		}
+		if (last_one)
+			break;
 	}
 }
 
@@ -1103,8 +1049,6 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
 
 		ret = __dwc3_gadget_kick_transfer(dep, 0, true);
 		if (ret && ret != -EBUSY) {
-			struct dwc3	*dwc = dep->dwc;
-
 			dev_dbg(dwc->dev, "%s: failed to kick transfers\n",
 					dep->name);
 		}
@@ -1118,7 +1062,6 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
 {
 	struct dwc3_request		*req = to_dwc3_request(request);
 	struct dwc3_ep			*dep = to_dwc3_ep(ep);
-	struct dwc3			*dwc = dep->dwc;
 
 	unsigned long			flags;
 
@@ -1132,8 +1075,9 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
 		goto out;
 	}
 
-	if (WARN(req->dep != dep, "request %p belongs to '%s'\n",
-				request, req->dep->name)) {
+	if (req->dep != dep) {
+		WARN(true, "request %p belongs to '%s'\n",
+				request, req->dep->name);
 		ret = -EINVAL;
 		goto out;
 	}
@@ -1239,7 +1183,6 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol)
 static int dwc3_gadget_ep_set_halt(struct usb_ep *ep, int value)
 {
 	struct dwc3_ep			*dep = to_dwc3_ep(ep);
-	struct dwc3			*dwc = dep->dwc;
 
 	unsigned long			flags;
 
@@ -1255,7 +1198,6 @@ static int dwc3_gadget_ep_set_halt(struct usb_ep *ep, int value)
 static int dwc3_gadget_ep_set_wedge(struct usb_ep *ep)
 {
 	struct dwc3_ep			*dep = to_dwc3_ep(ep);
-	struct dwc3			*dwc = dep->dwc;
 	unsigned long			flags;
 	int				ret;
 
@@ -1371,9 +1313,9 @@ static int dwc3_gadget_wakeup(struct usb_gadget *g)
 	}
 
 	/* poll until Link State changes to ON */
-	timeout = jiffies + msecs_to_jiffies(100);
+	timeout = 1000;
 
-	while (!time_after(jiffies, timeout)) {
+	while (timeout--) {
 		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
 
 		/* in HS, means ON */
@@ -1498,9 +1440,6 @@ static void dwc3_gadget_disable_irq(struct dwc3 *dwc)
 	dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
 }
 
-static irqreturn_t dwc3_interrupt(int irq, void *_dwc);
-static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc);
-
 static int dwc3_gadget_start(struct usb_gadget *g,
 		struct usb_gadget_driver *driver)
 {
@@ -1508,24 +1447,14 @@ static int dwc3_gadget_start(struct usb_gadget *g,
 	struct dwc3_ep		*dep;
 	unsigned long		flags;
 	int			ret = 0;
-	int			irq;
 	u32			reg;
 
-	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
-	ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
-			IRQF_SHARED, "dwc3", dwc);
-	if (ret) {
-		dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
-				irq, ret);
-		goto err0;
-	}
-
 	spin_lock_irqsave(&dwc->lock, flags);
 
 	if (dwc->gadget_driver) {
 		dev_err(dwc->dev, "%s is already bound to %s\n",
 				dwc->gadget.name,
-				dwc->gadget_driver->driver.name);
+				dwc->gadget_driver->function);
 		ret = -EBUSY;
 		goto err1;
 	}
@@ -1609,9 +1538,6 @@ err2:
 err1:
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
-	free_irq(irq, dwc);
-
-err0:
 	return ret;
 }
 
@@ -1619,7 +1545,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 {
 	struct dwc3		*dwc = gadget_to_dwc(g);
 	unsigned long		flags;
-	int			irq;
 
 	spin_lock_irqsave(&dwc->lock, flags);
 
@@ -1631,9 +1556,6 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
-	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
-	free_irq(irq, dwc);
-
 	return 0;
 }
 
@@ -1832,7 +1754,6 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
 	struct dwc3_request	*req;
 	struct dwc3_trb		*trb;
 	unsigned int		slot;
-	unsigned int		i;
 	int			ret;
 
 	do {
@@ -1841,20 +1762,18 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
 			WARN_ON_ONCE(1);
 			return 1;
 		}
-		i = 0;
-		do {
-			slot = req->start_slot + i;
-			if ((slot == DWC3_TRB_NUM - 1) &&
-				usb_endpoint_xfer_isoc(dep->endpoint.desc))
-				slot++;
-			slot %= DWC3_TRB_NUM;
-			trb = &dep->trb_pool[slot];
-
-			ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
-					event, status);
-			if (ret)
-				break;
-		}while (++i < req->request.num_mapped_sgs);
+
+		slot = req->start_slot;
+		if ((slot == DWC3_TRB_NUM - 1) &&
+			usb_endpoint_xfer_isoc(dep->endpoint.desc))
+			slot++;
+		slot %= DWC3_TRB_NUM;
+		trb = &dep->trb_pool[slot];
+
+		ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
+				event, status);
+		if (ret)
+			break;
 
 		dwc3_gadget_giveback(dep, req, status);
 
@@ -2293,9 +2212,8 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
 		 * BESL value in the LPM token is less than or equal to LPM
 		 * NYET threshold.
 		 */
-		WARN_ONCE(dwc->revision < DWC3_REVISION_240A
-				&& dwc->has_lpm_erratum,
-				"LPM Erratum not available on dwc3 revisisions < 2.40a\n");
+		if (dwc->revision < DWC3_REVISION_240A 	&& dwc->has_lpm_erratum)
+			WARN(true, "LPM Erratum not available on dwc3 revisisions < 2.40a\n");
 
 		if (dwc->has_lpm_erratum && dwc->revision >= DWC3_REVISION_240A)
 			reg |= DWC3_DCTL_LPM_ERRATA(dwc->lpm_nyet_threshold);
@@ -2482,10 +2400,10 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc,
 		dwc3_gadget_wakeup_interrupt(dwc);
 		break;
 	case DWC3_DEVICE_EVENT_HIBER_REQ:
-		if (dev_WARN_ONCE(dwc->dev, !dwc->has_hibernation,
-					"unexpected hibernation event\n"))
+		if (!dwc->has_hibernation) {
+			WARN(1 ,"unexpected hibernation event\n");
 			break;
-
+		}
 		dwc3_gadget_hibernation_interrupt(dwc, event->event_info);
 		break;
 	case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
@@ -2649,16 +2567,16 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 {
 	int					ret;
 
-	dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
-			&dwc->ctrl_req_addr, GFP_KERNEL);
+	dwc->ctrl_req = dma_alloc_coherent(sizeof(*dwc->ctrl_req),
+					(unsigned long *)&dwc->ctrl_req_addr);
 	if (!dwc->ctrl_req) {
 		dev_err(dwc->dev, "failed to allocate ctrl request\n");
 		ret = -ENOMEM;
 		goto err0;
 	}
 
-	dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
-			&dwc->ep0_trb_addr, GFP_KERNEL);
+	dwc->ep0_trb = dma_alloc_coherent(sizeof(*dwc->ep0_trb),
+					  (unsigned long *)&dwc->ep0_trb_addr);
 	if (!dwc->ep0_trb) {
 		dev_err(dwc->dev, "failed to allocate ep0 trb\n");
 		ret = -ENOMEM;
@@ -2671,9 +2589,8 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 		goto err2;
 	}
 
-	dwc->ep0_bounce = dma_alloc_coherent(dwc->dev,
-			DWC3_EP0_BOUNCE_SIZE, &dwc->ep0_bounce_addr,
-			GFP_KERNEL);
+	dwc->ep0_bounce = dma_alloc_coherent(DWC3_EP0_BOUNCE_SIZE,
+					(unsigned long *)&dwc->ep0_bounce_addr);
 	if (!dwc->ep0_bounce) {
 		dev_err(dwc->dev, "failed to allocate ep0 bounce buffer\n");
 		ret = -ENOMEM;
@@ -2683,7 +2600,6 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 	dwc->gadget.ops			= &dwc3_gadget_ops;
 	dwc->gadget.max_speed		= USB_SPEED_SUPER;
 	dwc->gadget.speed		= USB_SPEED_UNKNOWN;
-	dwc->gadget.sg_supported	= true;
 	dwc->gadget.name		= "dwc3-gadget";
 
 	/*
@@ -2711,19 +2627,16 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 
 err4:
 	dwc3_gadget_free_endpoints(dwc);
-	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
-			dwc->ep0_bounce, dwc->ep0_bounce_addr);
+	dma_free_coherent(dwc->ep0_bounce);
 
 err3:
 	kfree(dwc->setup_buf);
 
 err2:
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
-			dwc->ep0_trb, dwc->ep0_trb_addr);
+	dma_free_coherent(dwc->ep0_trb);
 
 err1:
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
-			dwc->ctrl_req, dwc->ctrl_req_addr);
+	dma_free_coherent(dwc->ctrl_req);
 
 err0:
 	return ret;
@@ -2737,14 +2650,25 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
 
 	dwc3_gadget_free_endpoints(dwc);
 
-	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
-			dwc->ep0_bounce, dwc->ep0_bounce_addr);
+	dma_free_coherent(dwc->ep0_bounce);
 
 	kfree(dwc->setup_buf);
 
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
-			dwc->ep0_trb, dwc->ep0_trb_addr);
+	dma_free_coherent(dwc->ep0_trb);
 
-	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
-			dwc->ctrl_req, dwc->ctrl_req_addr);
+	dma_free_coherent(dwc->ctrl_req);
+}
+
+/**
+ * dwc3_gadget_uboot_handle_interrupt - handle dwc3 gadget interrupt
+ * @dwc: struct dwce *
+ *
+ * Handles ep0 and gadget interrupt
+ *
+ * Should be called from dwc3 core.
+ */
+void dwc3_gadget_uboot_handle_interrupt(struct dwc3 *dwc)
+{
+	dwc3_interrupt(0, dwc);
+	dwc3_thread_interrupt(0, dwc);
 }
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index 042e247..c7db219 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -87,6 +87,7 @@ int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value);
 int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
 		gfp_t gfp_flags);
 int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol);
+void dwc3_gadget_uboot_handle_interrupt(struct dwc3 *dwc);
 
 /**
  * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
diff --git a/drivers/usb/dwc3/linux-compat.h b/drivers/usb/dwc3/linux-compat.h
index 58c4716..719e82e 100644
--- a/drivers/usb/dwc3/linux-compat.h
+++ b/drivers/usb/dwc3/linux-compat.h
@@ -5,9 +5,6 @@
  *
  * Authors: Kishon Vijay Abraham I <kishon@ti.com>
  *
- * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
- * to uboot.
- *
  * SPDX-License-Identifier:	GPL-2.0
  *
  */
diff --git a/include/linux/compat.h b/include/linux/compat.h
index b40133c..904425a 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -327,6 +327,7 @@ typedef unsigned long dmaaddr_t;
 
 #define IRQ_NONE 0
 #define IRQ_HANDLED 1
+#define IRQ_WAKE_THREAD 2
 
 #define dev_set_drvdata(dev, data) do {} while (0)
 
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 1960958..93a5ffc 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -31,6 +31,7 @@ struct usb_ep;
  * @dma: DMA address corresponding to 'buf'.  If you don't set this
  *	field, and the usb controller needs one, it is responsible
  *	for mapping and unmapping the buffer.
+ * @stream_id: The stream id, when USB3.0 bulk streams are being used
  * @length: Length of that data
  * @no_interrupt: If true, hints that no completion irq is needed.
  *	Helpful sometimes with deep request queues that are handled
@@ -85,6 +86,7 @@ struct usb_request {
 	unsigned		length;
 	dma_addr_t		dma;
 
+	unsigned		stream_id:16;
 	unsigned		no_interrupt:1;
 	unsigned		zero:1;
 	unsigned		short_not_ok:1;
@@ -121,6 +123,7 @@ struct usb_ep_ops {
 	int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
 
 	int (*set_halt) (struct usb_ep *ep, int value);
+	int (*set_wedge)(struct usb_ep *ep);
 	int (*fifo_status) (struct usb_ep *ep);
 	void (*fifo_flush) (struct usb_ep *ep);
 };
@@ -133,8 +136,18 @@ struct usb_ep_ops {
  * @maxpacket:The maximum packet size used on this endpoint.  The initial
  *	value can sometimes be reduced (hardware allowing), according to
  *      the endpoint descriptor used to configure the endpoint.
+ * @maxpacket_limit:The maximum packet size value which can be handled by this
+ *	endpoint. It's set once by UDC driver when endpoint is initialized, and
+ *	should not be changed. Should not be confused with maxpacket.
+ * @max_streams: The maximum number of streams supported
+ * 	by this EP (0 - 16, actual number is 2^n)
+ * @maxburst: the maximum number of bursts supported by this EP (for usb3)
  * @driver_data:for use by the gadget driver.  all other fields are
  *	read-only to gadget drivers.
+ * @desc: endpoint descriptor.  This pointer is set before the endpoint is
+ * 	enabled and remains valid until the endpoint is disabled.
+ * @comp_desc: In case of SuperSpeed support, this is the endpoint companion
+ * 	descriptor that is used to configure the endpoint
  *
  * the bus controller driver lists all the general purpose endpoints in
  * gadget->ep_list.  the control endpoint (gadget->ep0) is not in that list,
@@ -146,11 +159,31 @@ struct usb_ep {
 	const struct usb_ep_ops	*ops;
 	struct list_head	ep_list;
 	unsigned		maxpacket:16;
+	unsigned		maxpacket_limit:16;
+	unsigned		max_streams:16;
+	unsigned		maxburst:5;
+	const struct usb_endpoint_descriptor	*desc;
+	const struct usb_ss_ep_comp_descriptor	*comp_desc;
 };
 
 /*-------------------------------------------------------------------------*/
 
 /**
+ * usb_ep_set_maxpacket_limit - set maximum packet size limit for endpoint
+ * @ep:the endpoint being configured
+ * @maxpacket_limit:value of maximum packet size limit
+ *
+ * This function shoud be used only in UDC drivers to initialize endpoint
+ * (usually in probe function).
+ */
+static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
+					      unsigned maxpacket_limit)
+{
+	ep->maxpacket_limit = maxpacket_limit;
+	ep->maxpacket = maxpacket_limit;
+}
+
+/**
  * usb_ep_enable - configure endpoint, making it usable
  * @ep:the endpoint being configured.  may not be the endpoint named "ep0".
  *	drivers discover endpoints through the ep_list of a usb_gadget.
@@ -422,6 +455,8 @@ struct usb_gadget_ops {
  *	driver setup() requests
  * @ep_list: List of other endpoints supported by the device.
  * @speed: Speed of current connection to USB host.
+ * @max_speed: Maximal speed the UDC can handle.  UDC must support this
+ *      and all slower speeds.
  * @is_dualspeed: true if the controller supports both high and full speed
  *	operation.  If it does, the gadget driver must also support both.
  * @is_otg: true if the USB device port uses a Mini-AB jack, so that the
@@ -438,6 +473,8 @@ struct usb_gadget_ops {
  * @name: Identifies the controller hardware type.  Used in diagnostics
  *	and sometimes configuration.
  * @dev: Driver model state for this abstract device.
+ * @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to
+ *	MaxPacketSize.
  *
  * Gadgets have a mostly-portable "gadget driver" implementing device
  * functions, handling all usb configurations and interfaces.  Gadget
@@ -463,6 +500,7 @@ struct usb_gadget {
 	struct usb_ep			*ep0;
 	struct list_head		ep_list;	/* of usb_ep */
 	enum usb_device_speed		speed;
+	enum usb_device_speed		max_speed;
 	enum usb_device_state		state;
 	unsigned			is_dualspeed:1;
 	unsigned			is_otg:1;
@@ -472,6 +510,7 @@ struct usb_gadget {
 	unsigned			a_alt_hnp_support:1;
 	const char			*name;
 	struct device			dev;
+	unsigned			quirk_ep_out_aligned_size:1;
 };
 
 static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
-- 
1.7.9.5

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

* [U-Boot] [u-boot 16/40] include: asm: types: add resource_size_t type
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (14 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 15/40] usb: dwc3: gadget: make dwc3 gadget build in uboot Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:53   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 17/40] usb: dwc3: ep0: make dwc3 ep0 build in uboot Kishon Vijay Abraham I
                   ` (24 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added resource_size_t type in order to get rid of the following
compilation error whiel building dwc3 gadget.
include/linux/ioport.h:19:2: error: unknown type name ?resource_size_t?

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/include/asm/types.h |    1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/include/asm/types.h b/arch/arm/include/asm/types.h
index 2326420..ee77c41 100644
--- a/arch/arm/include/asm/types.h
+++ b/arch/arm/include/asm/types.h
@@ -54,4 +54,5 @@ typedef unsigned long phys_size_t;
 
 #endif /* __KERNEL__ */
 
+typedef unsigned long resource_size_t;
 #endif
-- 
1.7.9.5

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

* [U-Boot] [u-boot 17/40] usb: dwc3: ep0: make dwc3 ep0 build in uboot
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (15 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 16/40] include: asm: types: add resource_size_t type Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:54   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 18/40] include: usb: composite: add USB_GADGET_DELAYED_STATUS to avoid compilation error Kishon Vijay Abraham I
                   ` (23 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

*) Changed the included header files to that used in u-boot.
*) added dwc3_ep_event_string() used in ep0.c
*) Fixed other misc warnings

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.h         |   24 ++++++++++++++++++++++++
 drivers/usb/dwc3/ep0.c          |   14 ++------------
 drivers/usb/dwc3/linux-compat.h |    1 +
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 97f71ad..0ffcb7d 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -841,6 +841,30 @@ struct dwc3_event_type {
 #define DWC3_DEPEVT_EPCMDCMPLT		0x07
 
 /**
+ * dwc3_ep_event_string - returns event name
+ * @event: then event code
+ */
+static inline const char *dwc3_ep_event_string(u8 event)
+{
+	switch (event) {
+	case DWC3_DEPEVT_XFERCOMPLETE:
+		return "Transfer Complete";
+	case DWC3_DEPEVT_XFERINPROGRESS:
+		return "Transfer In-Progress";
+	case DWC3_DEPEVT_XFERNOTREADY:
+		return "Transfer Not Ready";
+	case DWC3_DEPEVT_RXTXFIFOEVT:
+		return "FIFO";
+	case DWC3_DEPEVT_STREAMEVT:
+		return "Stream";
+	case DWC3_DEPEVT_EPCMDCMPLT:
+		return "Endpoint Command Complete";
+	}
+
+	return "UNKNOWN";
+}
+
+/**
  * struct dwc3_event_depvt - Device Endpoint Events
  * @one_bit: indicates this is an endpoint event (not used)
  * @endpoint_number: number of the endpoint
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 1751b1d..803ba51 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -15,24 +15,18 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <linux/platform_device.h>
-#include <linux/pm_runtime.h>
-#include <linux/interrupt.h>
-#include <linux/io.h>
 #include <linux/list.h>
-#include <linux/dma-mapping.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/composite.h>
 
 #include "core.h"
-#include "debug.h"
 #include "gadget.h"
 #include "io.h"
 
+#include "linux-compat.h"
+
 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep);
 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 		struct dwc3_ep *dep, struct dwc3_request *req);
@@ -277,8 +271,6 @@ int __dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value)
 
 int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value)
 {
-	struct dwc3_ep			*dep = to_dwc3_ep(ep);
-	struct dwc3			*dwc = dep->dwc;
 	unsigned long			flags;
 	int				ret;
 
@@ -632,12 +624,10 @@ static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
 	struct dwc3_ep	*dep;
 	enum usb_device_state state = dwc->gadget.state;
 	u16		wLength;
-	u16		wValue;
 
 	if (state == USB_STATE_DEFAULT)
 		return -EINVAL;
 
-	wValue = le16_to_cpu(ctrl->wValue);
 	wLength = le16_to_cpu(ctrl->wLength);
 
 	if (wLength != 6) {
diff --git a/drivers/usb/dwc3/linux-compat.h b/drivers/usb/dwc3/linux-compat.h
index 719e82e..cbfb946 100644
--- a/drivers/usb/dwc3/linux-compat.h
+++ b/drivers/usb/dwc3/linux-compat.h
@@ -14,6 +14,7 @@
 
 #define pr_debug(format)                debug(format)
 #define WARN(val, format, arg...)	debug(format, ##arg)
+#define dev_WARN(dev, format, arg...)	debug(format, ##arg)
 #define WARN_ON_ONCE(val)		debug("Error %d\n", val)
 
 #define BUILD_BUG_ON_NOT_POWER_OF_2(n)
-- 
1.7.9.5

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

* [U-Boot] [u-boot 18/40] include: usb: composite: add USB_GADGET_DELAYED_STATUS to avoid compilation error
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (16 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 17/40] usb: dwc3: ep0: make dwc3 ep0 build in uboot Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:55   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 19/40] usb: dwc3: core: make dwc3 core build in uboot Kishon Vijay Abraham I
                   ` (22 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added USB_GADGET_DELAYED_STATUS to avoid the following compilation error.
error: ?USB_GADGET_DELAYED_STATUS? undeclared (first use in this function)
while compiling dwc3/ep0.c

While this is been added only to avoid compilation error, the complete fix
should be something like the one added in linux kernel. The complete fix
will be ported once we have the composite driver in u-boot look similar to
the one in linux kernel.
commit 1b9ba000177ee47bcc5b44c7c34e48e735f5f9b1
Author: Roger Quadros <roger.quadros@nokia.com>
Date:   Mon May 9 13:08:06 2011 +0300

    usb: gadget: composite: Allow function drivers to pause control transfers

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 include/linux/usb/composite.h |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index f833d10..86e1cea 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -27,6 +27,15 @@
 #include <linux/usb/gadget.h>
 #include <usb/lin_gadget_compat.h>
 
+/*
+ * USB function drivers should return USB_GADGET_DELAYED_STATUS if they
+ * wish to delay the data/status stages of the control transfer till they
+ * are ready. The control transfer will then be kept from completing till
+ * all the function drivers that requested for USB_GADGET_DELAYED_STAUS
+ * invoke usb_composite_setup_continue().
+ */
+#define	USB_GADGET_DELAYED_STATUS	0x7fff /* Impossibly large value */
+
 struct usb_configuration;
 
 /**
-- 
1.7.9.5

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

* [U-Boot] [u-boot 19/40] usb: dwc3: core: make dwc3 core build in uboot
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (17 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 18/40] include: usb: composite: add USB_GADGET_DELAYED_STATUS to avoid compilation error Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:57   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 20/40] include: dwc3-uboot: add a structure for populating platform data Kishon Vijay Abraham I
                   ` (21 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

*) Changed the include header files to that used in u-boot.
*) Removed phy_* APIs
*) Removed jiffies and used a simple while loop
*) Used dma_alloc_coherent and dma_free_coherent APIs of u-boot
*) Fixed other misc warnings

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.c         |  216 ++++++---------------------------------
 drivers/usb/dwc3/core.h         |   10 --
 drivers/usb/dwc3/linux-compat.h |   10 ++
 3 files changed, 40 insertions(+), 196 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index ebfb6ca..78322b7 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -14,32 +14,19 @@
  * SPDX-License-Identifier:     GPL-2.0
  */
 
-#include <linux/version.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/spinlock.h>
-#include <linux/platform_device.h>
-#include <linux/interrupt.h>
+#include <common.h>
+#include <malloc.h>
+#include <asm/dma-mapping.h>
 #include <linux/ioport.h>
-#include <linux/io.h>
-#include <linux/list.h>
-#include <linux/delay.h>
-#include <linux/dma-mapping.h>
-#include <linux/of.h>
-#include <linux/acpi.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
-#include <linux/usb/of.h>
-#include <linux/usb/otg.h>
 
-#include "platform_data.h"
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
 
-#include "debug.h"
+#include "linux-compat.h"
 
 /* -------------------------------------------------------------------------- */
 
@@ -60,7 +47,6 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
 static int dwc3_core_soft_reset(struct dwc3 *dwc)
 {
 	u32		reg;
-	int		ret;
 
 	/* Before Resetting PHY, put Core in Reset */
 	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
@@ -77,17 +63,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
 	reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
 	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
-	usb_phy_init(dwc->usb2_phy);
-	usb_phy_init(dwc->usb3_phy);
-	ret = phy_init(dwc->usb2_generic_phy);
-	if (ret < 0)
-		return ret;
-
-	ret = phy_init(dwc->usb3_generic_phy);
-	if (ret < 0) {
-		phy_exit(dwc->usb2_generic_phy);
-		return ret;
-	}
 	mdelay(100);
 
 	/* Clear USB3 PHY reset */
@@ -118,7 +93,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
 static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
 		struct dwc3_event_buffer *evt)
 {
-	dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
+	dma_free_coherent(evt->buf);
 }
 
 /**
@@ -140,8 +115,8 @@ static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
 
 	evt->dwc	= dwc;
 	evt->length	= length;
-	evt->buf	= dma_alloc_coherent(dwc->dev, length,
-			&evt->dma, GFP_KERNEL);
+	evt->buf	= dma_alloc_coherent(length,
+					     (unsigned long *)&evt->dma);
 	if (!evt->buf)
 		return ERR_PTR(-ENOMEM);
 
@@ -276,13 +251,9 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
 	if (!dwc->nr_scratch)
 		return 0;
 
-	 /* should never fall here */
-	if (!WARN_ON(dwc->scratchbuf))
-		return 0;
-
-	scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
-			dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
-			DMA_BIDIRECTIONAL);
+	scratch_addr = dma_map_single(dwc->scratchbuf,
+				      dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
+				      DMA_BIDIRECTIONAL);
 	if (dma_mapping_error(dwc->dev, scratch_addr)) {
 		dev_err(dwc->dev, "failed to map scratch buffer\n");
 		ret = -EFAULT;
@@ -308,8 +279,8 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
 	return 0;
 
 err1:
-	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
-			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+	dma_unmap_single((void *)dwc->scratch_addr, dwc->nr_scratch *
+			 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
 
 err0:
 	return ret;
@@ -323,12 +294,8 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
 	if (!dwc->nr_scratch)
 		return;
 
-	 /* should never fall here */
-	if (!WARN_ON(dwc->scratchbuf))
-		return;
-
-	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
-			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+	dma_unmap_single((void *)dwc->scratch_addr, dwc->nr_scratch *
+			 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
 	kfree(dwc->scratchbuf);
 }
 
@@ -446,12 +413,6 @@ static int dwc3_core_init(struct dwc3 *dwc)
 	}
 	dwc->revision = reg;
 
-	/*
-	 * Write Linux Version Code to our GUID register so it's easy to figure
-	 * out which kernel version a bug was found.
-	 */
-	dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
-
 	/* Handle USB2.0-only core configuration */
 	if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
 			DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
@@ -460,21 +421,19 @@ static int dwc3_core_init(struct dwc3 *dwc)
 	}
 
 	/* issue device SoftReset too */
-	timeout = jiffies + msecs_to_jiffies(500);
+	timeout = 5000;
 	dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
-	do {
+	while (timeout--) {
 		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 		if (!(reg & DWC3_DCTL_CSFTRST))
 			break;
+	};
 
-		if (time_after(jiffies, timeout)) {
-			dev_err(dwc->dev, "Reset Timed Out\n");
-			ret = -ETIMEDOUT;
-			goto err0;
-		}
-
-		cpu_relax();
-	} while (true);
+	if (!timeout) {
+		dev_err(dwc->dev, "Reset Timed Out\n");
+		ret = -ETIMEDOUT;
+		goto err0;
+	}
 
 	ret = dwc3_core_soft_reset(dwc);
 	if (ret)
@@ -525,8 +484,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
 		dwc->is_fpga = true;
 	}
 
-	WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
-			"disable_scramble cannot be used on non-FPGA builds\n");
+	if(dwc->disable_scramble_quirk && !dwc->is_fpga)
+		WARN(true,
+		     "disable_scramble cannot be used on non-FPGA builds\n");
 
 	if (dwc->disable_scramble_quirk && dwc->is_fpga)
 		reg |= DWC3_GCTL_DISSCRAMBLE;
@@ -553,22 +513,16 @@ static int dwc3_core_init(struct dwc3 *dwc)
 
 	ret = dwc3_alloc_scratch_buffers(dwc);
 	if (ret)
-		goto err1;
+		goto err0;
 
 	ret = dwc3_setup_scratch_buffers(dwc);
 	if (ret)
-		goto err2;
+		goto err1;
 
 	return 0;
 
-err2:
-	dwc3_free_scratch_buffers(dwc);
-
 err1:
-	usb_phy_shutdown(dwc->usb2_phy);
-	usb_phy_shutdown(dwc->usb3_phy);
-	phy_exit(dwc->usb2_generic_phy);
-	phy_exit(dwc->usb3_generic_phy);
+	dwc3_free_scratch_buffers(dwc);
 
 err0:
 	return ret;
@@ -577,82 +531,10 @@ err0:
 static void dwc3_core_exit(struct dwc3 *dwc)
 {
 	dwc3_free_scratch_buffers(dwc);
-	usb_phy_shutdown(dwc->usb2_phy);
-	usb_phy_shutdown(dwc->usb3_phy);
-	phy_exit(dwc->usb2_generic_phy);
-	phy_exit(dwc->usb3_generic_phy);
-}
-
-static int dwc3_core_get_phy(struct dwc3 *dwc)
-{
-	struct device		*dev = dwc->dev;
-	struct device_node	*node = dev->of_node;
-	int ret;
-
-	if (node) {
-		dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
-		dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
-	} else {
-		dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
-		dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
-	}
-
-	if (IS_ERR(dwc->usb2_phy)) {
-		ret = PTR_ERR(dwc->usb2_phy);
-		if (ret == -ENXIO || ret == -ENODEV) {
-			dwc->usb2_phy = NULL;
-		} else if (ret == -EPROBE_DEFER) {
-			return ret;
-		} else {
-			dev_err(dev, "no usb2 phy configured\n");
-			return ret;
-		}
-	}
-
-	if (IS_ERR(dwc->usb3_phy)) {
-		ret = PTR_ERR(dwc->usb3_phy);
-		if (ret == -ENXIO || ret == -ENODEV) {
-			dwc->usb3_phy = NULL;
-		} else if (ret == -EPROBE_DEFER) {
-			return ret;
-		} else {
-			dev_err(dev, "no usb3 phy configured\n");
-			return ret;
-		}
-	}
-
-	dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
-	if (IS_ERR(dwc->usb2_generic_phy)) {
-		ret = PTR_ERR(dwc->usb2_generic_phy);
-		if (ret == -ENOSYS || ret == -ENODEV) {
-			dwc->usb2_generic_phy = NULL;
-		} else if (ret == -EPROBE_DEFER) {
-			return ret;
-		} else {
-			dev_err(dev, "no usb2 phy configured\n");
-			return ret;
-		}
-	}
-
-	dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
-	if (IS_ERR(dwc->usb3_generic_phy)) {
-		ret = PTR_ERR(dwc->usb3_generic_phy);
-		if (ret == -ENOSYS || ret == -ENODEV) {
-			dwc->usb3_generic_phy = NULL;
-		} else if (ret == -EPROBE_DEFER) {
-			return ret;
-		} else {
-			dev_err(dev, "no usb3 phy configured\n");
-			return ret;
-		}
-	}
-
-	return 0;
 }
 
 static int dwc3_core_init_mode(struct dwc3 *dwc)
 {
-	struct device *dev = dwc->dev;
 	int ret;
 
 	switch (dwc->dr_mode) {
@@ -870,10 +752,6 @@ static int dwc3_probe(struct platform_device *pdev)
 	dwc->hird_threshold = hird_threshold
 		| (dwc->is_utmi_l1_suspend << 4);
 
-	ret = dwc3_core_get_phy(dwc);
-	if (ret)
-		return ret;
-
 	spin_lock_init(&dwc->lock);
 	platform_set_drvdata(pdev, dwc);
 
@@ -888,8 +766,7 @@ static int dwc3_probe(struct platform_device *pdev)
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
 	if (ret) {
 		dev_err(dwc->dev, "failed to allocate event buffers\n");
-		ret = -ENOMEM;
-		goto err0;
+		return -ENOMEM;
 	}
 
 	if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
@@ -906,49 +783,22 @@ static int dwc3_probe(struct platform_device *pdev)
 		goto err0;
 	}
 
-	usb_phy_set_suspend(dwc->usb2_phy, 0);
-	usb_phy_set_suspend(dwc->usb3_phy, 0);
-	ret = phy_power_on(dwc->usb2_generic_phy);
-	if (ret < 0)
-		goto err1;
-
-	ret = phy_power_on(dwc->usb3_generic_phy);
-	if (ret < 0)
-		goto err_usb2phy_power;
-
 	ret = dwc3_event_buffers_setup(dwc);
 	if (ret) {
 		dev_err(dwc->dev, "failed to setup event buffers\n");
-		goto err_usb3phy_power;
+		goto err1;
 	}
 
 	ret = dwc3_core_init_mode(dwc);
 	if (ret)
 		goto err2;
 
-	ret = dwc3_debugfs_init(dwc);
-	if (ret) {
-		dev_err(dev, "failed to initialize debugfs\n");
-		goto err3;
-	}
-
 	return 0;
 
-err3:
-	dwc3_core_exit_mode(dwc);
-
 err2:
 	dwc3_event_buffers_cleanup(dwc);
 
-err_usb3phy_power:
-	phy_power_off(dwc->usb3_generic_phy);
-
-err_usb2phy_power:
-	phy_power_off(dwc->usb2_generic_phy);
-
 err1:
-	usb_phy_set_suspend(dwc->usb2_phy, 1);
-	usb_phy_set_suspend(dwc->usb3_phy, 1);
 	dwc3_core_exit(dwc);
 
 err0:
@@ -961,16 +811,10 @@ static int dwc3_remove(struct platform_device *pdev)
 {
 	struct dwc3	*dwc = platform_get_drvdata(pdev);
 
-	dwc3_debugfs_exit(dwc);
 	dwc3_core_exit_mode(dwc);
 	dwc3_event_buffers_cleanup(dwc);
 	dwc3_free_event_buffers(dwc);
 
-	usb_phy_set_suspend(dwc->usb2_phy, 1);
-	usb_phy_set_suspend(dwc->usb3_phy, 1);
-	phy_power_off(dwc->usb2_generic_phy);
-	phy_power_off(dwc->usb3_generic_phy);
-
 	dwc3_core_exit(dwc);
 
 	return 0;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 0ffcb7d..0d507c1 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -641,10 +641,6 @@ struct dwc3_scratchpad_array {
  * @maximum_speed: maximum speed requested (mainly for testing purposes)
  * @revision: revision register contents
  * @dr_mode: requested mode of operation
- * @usb2_phy: pointer to USB2 PHY
- * @usb3_phy: pointer to USB3 PHY
- * @usb2_generic_phy: pointer to USB2 PHY
- * @usb3_generic_phy: pointer to USB3 PHY
  * @dcfg: saved contents of DCFG register
  * @gctl: saved contents of GCTL register
  * @isoch_delay: wValue from Set Isochronous Delay request;
@@ -726,12 +722,6 @@ struct dwc3 {
 	struct usb_gadget	gadget;
 	struct usb_gadget_driver *gadget_driver;
 
-	struct usb_phy		*usb2_phy;
-	struct usb_phy		*usb3_phy;
-
-	struct phy		*usb2_generic_phy;
-	struct phy		*usb3_generic_phy;
-
 	void __iomem		*regs;
 	size_t			regs_size;
 
diff --git a/drivers/usb/dwc3/linux-compat.h b/drivers/usb/dwc3/linux-compat.h
index cbfb946..b36f68f 100644
--- a/drivers/usb/dwc3/linux-compat.h
+++ b/drivers/usb/dwc3/linux-compat.h
@@ -25,4 +25,14 @@ static inline size_t strlcat(char *dest, const char *src, size_t n)
 	return strlen(dest) + strlen(src);
 }
 
+static inline void *devm_kzalloc(struct device *dev, unsigned int size,
+				 unsigned int flags)
+{
+	return kzalloc(size, flags);
+}
+
+static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+	return kzalloc(n * size, flags);
+}
 #endif
-- 
1.7.9.5

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

* [U-Boot] [u-boot 20/40] include: dwc3-uboot: add a structure for populating platform data
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (18 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 19/40] usb: dwc3: core: make dwc3 core build in uboot Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:58   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 21/40] dwc3: core: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
                   ` (20 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added a structure to populate dwc3 core platform data. The board file should
populate these platform data before invoking dwc3 driver.
This will be removed once we have dwc3 driver adapted to use the driver model.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 include/dwc3-uboot.h |   40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 include/dwc3-uboot.h

diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h
new file mode 100644
index 0000000..6d1b42a
--- /dev/null
+++ b/include/dwc3-uboot.h
@@ -0,0 +1,40 @@
+/* include/dwc3-uboot.h
+ *
+ * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Designware SuperSpeed USB uboot init
+ *
+ * SPDX-License-Identifier:     GPL-2.0
+ */
+
+#ifndef __DWC3_UBOOT_H_
+#define __DWC3_UBOOT_H_
+
+#include <linux/usb/otg.h>
+
+struct dwc3_device {
+	int base;
+	enum usb_dr_mode dr_mode;
+	u32 maximum_speed;
+	unsigned tx_fifo_resize:1;
+	unsigned has_lpm_erratum;
+	u8 lpm_nyet_threshold;
+	unsigned is_utmi_l1_suspend;
+	u8 hird_threshold;
+	unsigned disable_scramble_quirk;
+	unsigned u2exit_lfps_quirk;
+	unsigned u2ss_inp3_quirk;
+	unsigned req_p1p2p3_quirk;
+	unsigned del_p1p2p3_quirk;
+	unsigned del_phy_power_chg_quirk;
+	unsigned lfps_filter_quirk;
+	unsigned rx_detect_poll_quirk;
+	unsigned dis_u3_susphy_quirk;
+	unsigned dis_u2_susphy_quirk;
+	unsigned tx_de_emphasis_quirk;
+	unsigned tx_de_emphasis;
+};
+
+int dwc3_uboot_init(struct dwc3_device *dev);
+void dwc3_uboot_exit(void);
+#endif /* __DWC3_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 21/40] dwc3: core: change probe and remove to uboot init and uboot exit code
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (19 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 20/40] include: dwc3-uboot: add a structure for populating platform data Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 10:59   ` Lukasz Majewski
  2015-02-06  8:47 ` [U-Boot] [u-boot 22/40] dwc3: core: add support for multiple dwc3 controllers Kishon Vijay Abraham I
                   ` (19 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Removed probe and remove that are specific to linux and replaced it with
uboot init and uboot exit. These functions will be invoked from boardfile.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.c |  218 +++++++++++------------------------------------
 1 file changed, 52 insertions(+), 166 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 78322b7..58c3bfd 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -16,6 +16,7 @@
 
 #include <common.h>
 #include <malloc.h>
+#include <dwc3-uboot.h>
 #include <asm/dma-mapping.h>
 #include <linux/ioport.h>
 
@@ -28,6 +29,7 @@
 
 #include "linux-compat.h"
 
+struct dwc3 *dwc;
 /* -------------------------------------------------------------------------- */
 
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
@@ -597,20 +599,26 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
 
 #define DWC3_ALIGN_MASK		(16 - 1)
 
-static int dwc3_probe(struct platform_device *pdev)
+/**
+ * dwc3_uboot_init - dwc3 core uboot initialization code
+ * @dwc3_dev: struct dwc3_device containing initialization data
+ *
+ * Entry point for dwc3 driver (equivalent to dwc3_probe in linux
+ * kernel driver). Pointer to dwc3_device should be passed containing
+ * base address and other initialization data. Returns '0' on success and
+ * a negative value on failure.
+ *
+ * Generally called from board_usb_init() implemented in board file.
+ */
+int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 {
-	struct device		*dev = &pdev->dev;
-	struct dwc3_platform_data *pdata = dev_get_platdata(dev);
-	struct device_node	*node = dev->of_node;
-	struct resource		*res;
-	struct dwc3		*dwc;
+	struct device		*dev;
 	u8			lpm_nyet_threshold;
 	u8			tx_de_emphasis;
 	u8			hird_threshold;
 
 	int			ret;
 
-	void __iomem		*regs;
 	void			*mem;
 
 	mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
@@ -619,48 +627,8 @@ static int dwc3_probe(struct platform_device *pdev)
 
 	dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
 	dwc->mem = mem;
-	dwc->dev = dev;
-
-	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-	if (!res) {
-		dev_err(dev, "missing IRQ\n");
-		return -ENODEV;
-	}
-	dwc->xhci_resources[1].start = res->start;
-	dwc->xhci_resources[1].end = res->end;
-	dwc->xhci_resources[1].flags = res->flags;
-	dwc->xhci_resources[1].name = res->name;
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res) {
-		dev_err(dev, "missing memory resource\n");
-		return -ENODEV;
-	}
 
-	dwc->xhci_resources[0].start = res->start;
-	dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
-					DWC3_XHCI_REGS_END;
-	dwc->xhci_resources[0].flags = res->flags;
-	dwc->xhci_resources[0].name = res->name;
-
-	res->start += DWC3_GLOBALS_REGS_START;
-
-	/*
-	 * Request memory region but exclude xHCI regs,
-	 * since it will be requested by the xhci-plat driver.
-	 */
-	regs = devm_ioremap_resource(dev, res);
-	if (IS_ERR(regs))
-		return PTR_ERR(regs);
-
-	dwc->regs	= regs;
-	dwc->regs_size	= resource_size(res);
-	/*
-	 * restore res->start back to its original value so that,
-	 * in case the probe is deferred, we don't end up getting error in
-	 * request the memory region the next time probe is called.
-	 */
-	res->start -= DWC3_GLOBALS_REGS_START;
+	dwc->regs	= (int *)(dwc3_dev->base + DWC3_GLOBALS_REGS_START);
 
 	/* default to highest possible threshold */
 	lpm_nyet_threshold = 0xff;
@@ -674,73 +642,31 @@ static int dwc3_probe(struct platform_device *pdev)
 	 */
 	hird_threshold = 12;
 
-	if (node) {
-		dwc->maximum_speed = of_usb_get_maximum_speed(node);
-		dwc->has_lpm_erratum = of_property_read_bool(node,
-				"snps,has-lpm-erratum");
-		of_property_read_u8(node, "snps,lpm-nyet-threshold",
-				&lpm_nyet_threshold);
-		dwc->is_utmi_l1_suspend = of_property_read_bool(node,
-				"snps,is-utmi-l1-suspend");
-		of_property_read_u8(node, "snps,hird-threshold",
-				&hird_threshold);
-
-		dwc->needs_fifo_resize = of_property_read_bool(node,
-				"tx-fifo-resize");
-		dwc->dr_mode = of_usb_get_dr_mode(node);
-
-		dwc->disable_scramble_quirk = of_property_read_bool(node,
-				"snps,disable_scramble_quirk");
-		dwc->u2exit_lfps_quirk = of_property_read_bool(node,
-				"snps,u2exit_lfps_quirk");
-		dwc->u2ss_inp3_quirk = of_property_read_bool(node,
-				"snps,u2ss_inp3_quirk");
-		dwc->req_p1p2p3_quirk = of_property_read_bool(node,
-				"snps,req_p1p2p3_quirk");
-		dwc->del_p1p2p3_quirk = of_property_read_bool(node,
-				"snps,del_p1p2p3_quirk");
-		dwc->del_phy_power_chg_quirk = of_property_read_bool(node,
-				"snps,del_phy_power_chg_quirk");
-		dwc->lfps_filter_quirk = of_property_read_bool(node,
-				"snps,lfps_filter_quirk");
-		dwc->rx_detect_poll_quirk = of_property_read_bool(node,
-				"snps,rx_detect_poll_quirk");
-		dwc->dis_u3_susphy_quirk = of_property_read_bool(node,
-				"snps,dis_u3_susphy_quirk");
-		dwc->dis_u2_susphy_quirk = of_property_read_bool(node,
-				"snps,dis_u2_susphy_quirk");
-
-		dwc->tx_de_emphasis_quirk = of_property_read_bool(node,
-				"snps,tx_de_emphasis_quirk");
-		of_property_read_u8(node, "snps,tx_de_emphasis",
-				&tx_de_emphasis);
-	} else if (pdata) {
-		dwc->maximum_speed = pdata->maximum_speed;
-		dwc->has_lpm_erratum = pdata->has_lpm_erratum;
-		if (pdata->lpm_nyet_threshold)
-			lpm_nyet_threshold = pdata->lpm_nyet_threshold;
-		dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend;
-		if (pdata->hird_threshold)
-			hird_threshold = pdata->hird_threshold;
-
-		dwc->needs_fifo_resize = pdata->tx_fifo_resize;
-		dwc->dr_mode = pdata->dr_mode;
-
-		dwc->disable_scramble_quirk = pdata->disable_scramble_quirk;
-		dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk;
-		dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk;
-		dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk;
-		dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk;
-		dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk;
-		dwc->lfps_filter_quirk = pdata->lfps_filter_quirk;
-		dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk;
-		dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk;
-		dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk;
-
-		dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk;
-		if (pdata->tx_de_emphasis)
-			tx_de_emphasis = pdata->tx_de_emphasis;
-	}
+	dwc->maximum_speed = dwc3_dev->maximum_speed;
+	dwc->has_lpm_erratum = dwc3_dev->has_lpm_erratum;
+	if (dwc3_dev->lpm_nyet_threshold)
+		lpm_nyet_threshold = dwc3_dev->lpm_nyet_threshold;
+	dwc->is_utmi_l1_suspend = dwc3_dev->is_utmi_l1_suspend;
+	if (dwc3_dev->hird_threshold)
+		hird_threshold = dwc3_dev->hird_threshold;
+
+	dwc->needs_fifo_resize = dwc3_dev->tx_fifo_resize;
+	dwc->dr_mode = dwc3_dev->dr_mode;
+
+	dwc->disable_scramble_quirk = dwc3_dev->disable_scramble_quirk;
+	dwc->u2exit_lfps_quirk = dwc3_dev->u2exit_lfps_quirk;
+	dwc->u2ss_inp3_quirk = dwc3_dev->u2ss_inp3_quirk;
+	dwc->req_p1p2p3_quirk = dwc3_dev->req_p1p2p3_quirk;
+	dwc->del_p1p2p3_quirk = dwc3_dev->del_p1p2p3_quirk;
+	dwc->del_phy_power_chg_quirk = dwc3_dev->del_phy_power_chg_quirk;
+	dwc->lfps_filter_quirk = dwc3_dev->lfps_filter_quirk;
+	dwc->rx_detect_poll_quirk = dwc3_dev->rx_detect_poll_quirk;
+	dwc->dis_u3_susphy_quirk = dwc3_dev->dis_u3_susphy_quirk;
+	dwc->dis_u2_susphy_quirk = dwc3_dev->dis_u2_susphy_quirk;
+
+	dwc->tx_de_emphasis_quirk = dwc3_dev->tx_de_emphasis_quirk;
+	if (dwc3_dev->tx_de_emphasis)
+		tx_de_emphasis = dwc3_dev->tx_de_emphasis;
 
 	/* default to superspeed if no maximum_speed passed */
 	if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
@@ -752,15 +678,6 @@ static int dwc3_probe(struct platform_device *pdev)
 	dwc->hird_threshold = hird_threshold
 		| (dwc->is_utmi_l1_suspend << 4);
 
-	spin_lock_init(&dwc->lock);
-	platform_set_drvdata(pdev, dwc);
-
-	if (!dev->dma_mask) {
-		dev->dma_mask = dev->parent->dma_mask;
-		dev->dma_parms = dev->parent->dma_parms;
-		dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
-	}
-
 	dwc3_cache_hwparams(dwc);
 
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
@@ -807,55 +724,24 @@ err0:
 	return ret;
 }
 
-static int dwc3_remove(struct platform_device *pdev)
+/**
+ * dwc3_uboot_exit - dwc3 core uboot cleanup code
+ * @index: index of this controller
+ *
+ * Performs cleanup of memory allocated in dwc3_uboot_init and other misc
+ * cleanups (equivalent to dwc3_remove in linux).
+ *
+ * Generally called from board file.
+ */
+void dwc3_uboot_exit()
 {
-	struct dwc3	*dwc = platform_get_drvdata(pdev);
-
 	dwc3_core_exit_mode(dwc);
 	dwc3_event_buffers_cleanup(dwc);
 	dwc3_free_event_buffers(dwc);
-
 	dwc3_core_exit(dwc);
-
-	return 0;
+	kfree(dwc->mem);
 }
 
-#ifdef CONFIG_OF
-static const struct of_device_id of_dwc3_match[] = {
-	{
-		.compatible = "snps,dwc3"
-	},
-	{
-		.compatible = "synopsys,dwc3"
-	},
-	{ },
-};
-MODULE_DEVICE_TABLE(of, of_dwc3_match);
-#endif
-
-#ifdef CONFIG_ACPI
-
-#define ACPI_ID_INTEL_BSW	"808622B7"
-
-static const struct acpi_device_id dwc3_acpi_match[] = {
-	{ ACPI_ID_INTEL_BSW, 0 },
-	{ },
-};
-MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
-#endif
-
-static struct platform_driver dwc3_driver = {
-	.probe		= dwc3_probe,
-	.remove		= dwc3_remove,
-	.driver		= {
-		.name	= "dwc3",
-		.of_match_table	= of_match_ptr(of_dwc3_match),
-		.acpi_match_table = ACPI_PTR(dwc3_acpi_match),
-	},
-};
-
-module_platform_driver(dwc3_driver);
-
 MODULE_ALIAS("platform:dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("GPL v2");
-- 
1.7.9.5

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

* [U-Boot] [u-boot 22/40] dwc3: core: add support for multiple dwc3 controllers
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (20 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 21/40] dwc3: core: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
@ 2015-02-06  8:47 ` Kishon Vijay Abraham I
  2015-02-16 11:00   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 23/40] dwc3: core: added an API to invoke irq handlers Kishon Vijay Abraham I
                   ` (18 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:47 UTC (permalink / raw)
  To: u-boot

Added support for multiple dwc3 controllers. This gives uboot
the capability to control multiple dwc3 controllers.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.c |   32 ++++++++++++++++++++++++--------
 drivers/usb/dwc3/core.h |    4 ++++
 include/dwc3-uboot.h    |    3 ++-
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 58c3bfd..bd34dbd 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -29,7 +29,7 @@
 
 #include "linux-compat.h"
 
-struct dwc3 *dwc;
+static LIST_HEAD(dwc3_list);
 /* -------------------------------------------------------------------------- */
 
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
@@ -612,6 +612,7 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
  */
 int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 {
+	struct dwc3		*dwc;
 	struct device		*dev;
 	u8			lpm_nyet_threshold;
 	u8			tx_de_emphasis;
@@ -678,6 +679,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 	dwc->hird_threshold = hird_threshold
 		| (dwc->is_utmi_l1_suspend << 4);
 
+	dwc->index = dwc3_dev->index;
+
 	dwc3_cache_hwparams(dwc);
 
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
@@ -710,6 +713,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
 	if (ret)
 		goto err2;
 
+	list_add_tail(&dwc->list, &dwc3_list);
+
 	return 0;
 
 err2:
@@ -729,17 +734,28 @@ err0:
  * @index: index of this controller
  *
  * Performs cleanup of memory allocated in dwc3_uboot_init and other misc
- * cleanups (equivalent to dwc3_remove in linux).
+ * cleanups (equivalent to dwc3_remove in linux). index of _this_ controller
+ * should be passed and should match with the index passed in
+ * dwc3_device during init.
  *
  * Generally called from board file.
  */
-void dwc3_uboot_exit()
+void dwc3_uboot_exit(int index)
 {
-	dwc3_core_exit_mode(dwc);
-	dwc3_event_buffers_cleanup(dwc);
-	dwc3_free_event_buffers(dwc);
-	dwc3_core_exit(dwc);
-	kfree(dwc->mem);
+	struct dwc3 *dwc;
+
+	list_for_each_entry(dwc, &dwc3_list, list) {
+		if (dwc->index != index)
+			continue;
+
+		dwc3_core_exit_mode(dwc);
+		dwc3_event_buffers_cleanup(dwc);
+		dwc3_free_event_buffers(dwc);
+		dwc3_core_exit(dwc);
+		list_del(&dwc->list);
+		kfree(dwc->mem);
+		break;
+	}
 }
 
 MODULE_ALIAS("platform:dwc3");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 0d507c1..c5debf7 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -695,6 +695,8 @@ struct dwc3_scratchpad_array {
  * 	1	- -3.5dB de-emphasis
  * 	2	- No de-emphasis
  * 	3	- Reserved
+ * @index: index of _this_ controller
+ * @list: to maintain the list of dwc3 controllers
  */
 struct dwc3 {
 	struct usb_ctrlrequest	*ctrl_req;
@@ -811,6 +813,8 @@ struct dwc3 {
 
 	unsigned		tx_de_emphasis_quirk:1;
 	unsigned		tx_de_emphasis:2;
+	int			index;
+	struct list_head        list;
 };
 
 /* -------------------------------------------------------------------------- */
diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h
index 6d1b42a..272a020 100644
--- a/include/dwc3-uboot.h
+++ b/include/dwc3-uboot.h
@@ -33,8 +33,9 @@ struct dwc3_device {
 	unsigned dis_u2_susphy_quirk;
 	unsigned tx_de_emphasis_quirk;
 	unsigned tx_de_emphasis;
+	int index;
 };
 
 int dwc3_uboot_init(struct dwc3_device *dev);
-void dwc3_uboot_exit(void);
+void dwc3_uboot_exit(int index);
 #endif /* __DWC3_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 23/40] dwc3: core: added an API to invoke irq handlers
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (21 preceding siblings ...)
  2015-02-06  8:47 ` [U-Boot] [u-boot 22/40] dwc3: core: add support for multiple dwc3 controllers Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:01   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 24/40] usb: dwc3: dwc3-omap: make dwc3-omap build in uboot Kishon Vijay Abraham I
                   ` (17 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Since interrupt support is not present in u-boot, added an
API to handle the interrupts in dwc3 core. This API can be
polled to handle the interrupts.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.c |   21 +++++++++++++++++++++
 include/dwc3-uboot.h    |    1 +
 2 files changed, 22 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index bd34dbd..5a8d5ea 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -758,6 +758,27 @@ void dwc3_uboot_exit(int index)
 	}
 }
 
+/**
+ * dwc3_uboot_handle_interrupt - handle dwc3 core interrupt
+ * @index: index of this controller
+ *
+ * Invokes dwc3 gadget interrupts.
+ *
+ * Generally called from board file.
+ */
+void dwc3_uboot_handle_interrupt(int index)
+{
+	struct dwc3 *dwc = NULL;
+
+	list_for_each_entry(dwc, &dwc3_list, list) {
+		if (dwc->index != index)
+			continue;
+
+		dwc3_gadget_uboot_handle_interrupt(dwc);
+		break;
+	}
+}
+
 MODULE_ALIAS("platform:dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("GPL v2");
diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h
index 272a020..09ff8a7 100644
--- a/include/dwc3-uboot.h
+++ b/include/dwc3-uboot.h
@@ -38,4 +38,5 @@ struct dwc3_device {
 
 int dwc3_uboot_init(struct dwc3_device *dev);
 void dwc3_uboot_exit(int index);
+void dwc3_uboot_handle_interrupt(int index);
 #endif /* __DWC3_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 24/40] usb: dwc3: dwc3-omap: make dwc3-omap build in uboot
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (22 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 23/40] dwc3: core: added an API to invoke irq handlers Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:02   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 25/40] include: dwc3-omap-uboot: add a structure for populating dwc3-omap platform data Kishon Vijay Abraham I
                   ` (16 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

*) Changed the included header files to that used in u-boot.
*) Removed extcon_* APIs
*) Removed regulator_* APIs
*) Fixed other misc warnings
*) Added dwc3-omap.h to include the definitions of UTMI modes.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/dwc3-omap.c  |  144 +++--------------------------------------
 include/linux/usb/dwc3-omap.h |   19 ++++++
 2 files changed, 27 insertions(+), 136 deletions(-)
 create mode 100644 include/linux/usb/dwc3-omap.h

diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index ce2d6a6..b385987 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -14,21 +14,16 @@
  * SPDX-License-Identifier:     GPL-2.0
  */
 
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/interrupt.h>
-#include <linux/platform_device.h>
-#include <linux/platform_data/dwc3-omap.h>
-#include <linux/dma-mapping.h>
+#include <common.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <linux/usb/dwc3-omap.h>
 #include <linux/ioport.h>
-#include <linux/io.h>
-#include <linux/of.h>
-#include <linux/of_platform.h>
-#include <linux/extcon.h>
-#include <linux/regulator/consumer.h>
 
 #include <linux/usb/otg.h>
+#include <linux/compat.h>
+
+#include "linux-compat.h"
 
 /*
  * All these registers belong to OMAP's Wrapper around the
@@ -113,7 +108,6 @@
 struct dwc3_omap {
 	struct device		*dev;
 
-	int			irq;
 	void __iomem		*base;
 
 	u32			utmi_otg_status;
@@ -124,13 +118,6 @@ struct dwc3_omap {
 	u32			irq0_offset;
 
 	u32			dma_status:1;
-
-	struct extcon_specific_cable_nb extcon_vbus_dev;
-	struct extcon_specific_cable_nb extcon_id_dev;
-	struct notifier_block	vbus_nb;
-	struct notifier_block	id_nb;
-
-	struct regulator	*vbus_reg;
 };
 
 enum omap_dwc3_vbus_id_status {
@@ -205,21 +192,12 @@ static void dwc3_omap_write_irq0_set(struct dwc3_omap *omap, u32 value)
 static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
 	enum omap_dwc3_vbus_id_status status)
 {
-	int	ret;
 	u32	val;
 
 	switch (status) {
 	case OMAP_DWC3_ID_GROUND:
 		dev_dbg(omap->dev, "ID GND\n");
 
-		if (omap->vbus_reg) {
-			ret = regulator_enable(omap->vbus_reg);
-			if (ret) {
-				dev_dbg(omap->dev, "regulator enable failed\n");
-				return;
-			}
-		}
-
 		val = dwc3_omap_read_utmi_status(omap);
 		val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
 				| USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
@@ -242,9 +220,6 @@ static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
 		break;
 
 	case OMAP_DWC3_ID_FLOAT:
-		if (omap->vbus_reg)
-			regulator_disable(omap->vbus_reg);
-
 	case OMAP_DWC3_VBUS_OFF:
 		dev_dbg(omap->dev, "VBUS Disconnect\n");
 
@@ -349,32 +324,6 @@ static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
 
 static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
 
-static int dwc3_omap_id_notifier(struct notifier_block *nb,
-	unsigned long event, void *ptr)
-{
-	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb);
-
-	if (event)
-		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
-	else
-		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
-
-	return NOTIFY_DONE;
-}
-
-static int dwc3_omap_vbus_notifier(struct notifier_block *nb,
-	unsigned long event, void *ptr)
-{
-	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb);
-
-	if (event)
-		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
-	else
-		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
-
-	return NOTIFY_DONE;
-}
-
 static void dwc3_omap_map_offset(struct dwc3_omap *omap)
 {
 	struct device_node	*node = omap->dev->of_node;
@@ -420,42 +369,6 @@ static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
 	dwc3_omap_write_utmi_status(omap, reg);
 }
 
-static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
-{
-	int			ret;
-	struct device_node	*node = omap->dev->of_node;
-	struct extcon_dev	*edev;
-
-	if (of_property_read_bool(node, "extcon")) {
-		edev = extcon_get_edev_by_phandle(omap->dev, 0);
-		if (IS_ERR(edev)) {
-			dev_vdbg(omap->dev, "couldn't get extcon device\n");
-			return -EPROBE_DEFER;
-		}
-
-		omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
-		ret = extcon_register_interest(&omap->extcon_vbus_dev,
-					       edev->name, "USB",
-					       &omap->vbus_nb);
-		if (ret < 0)
-			dev_vdbg(omap->dev, "failed to register notifier for USB\n");
-
-		omap->id_nb.notifier_call = dwc3_omap_id_notifier;
-		ret = extcon_register_interest(&omap->extcon_id_dev,
-					       edev->name, "USB-HOST",
-					       &omap->id_nb);
-		if (ret < 0)
-			dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n");
-
-		if (extcon_get_cable_state(edev, "USB") == true)
-			dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
-		if (extcon_get_cable_state(edev, "USB-HOST") == true)
-			dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
-	}
-
-	return 0;
-}
-
 static int dwc3_omap_probe(struct platform_device *pdev)
 {
 	struct device_node	*node = pdev->dev.of_node;
@@ -463,11 +376,8 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 	struct dwc3_omap	*omap;
 	struct resource		*res;
 	struct device		*dev = &pdev->dev;
-	struct regulator	*vbus_reg = NULL;
 
 	int			ret;
-	int			irq;
-
 	u32			reg;
 
 	void __iomem		*base;
@@ -483,29 +393,13 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, omap);
 
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		dev_err(dev, "missing IRQ resource\n");
-		return -EINVAL;
-	}
-
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(base))
 		return PTR_ERR(base);
 
-	if (of_property_read_bool(node, "vbus-supply")) {
-		vbus_reg = devm_regulator_get(dev, "vbus");
-		if (IS_ERR(vbus_reg)) {
-			dev_err(dev, "vbus init failed\n");
-			return PTR_ERR(vbus_reg);
-		}
-	}
-
 	omap->dev	= dev;
-	omap->irq	= irq;
 	omap->base	= base;
-	omap->vbus_reg	= vbus_reg;
 	dev->dma_mask	= &dwc3_omap_dma_mask;
 
 	dwc3_omap_map_offset(omap);
@@ -515,34 +409,16 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 	reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
 	omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
 
-	ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0,
-			"dwc3-omap", omap);
-	if (ret) {
-		dev_err(dev, "failed to request IRQ #%d --> %d\n",
-				omap->irq, ret);
-		goto err0;
-	}
-
 	dwc3_omap_enable_irqs(omap);
 
-	ret = dwc3_omap_extcon_register(omap);
-	if (ret < 0)
-		goto err1;
-
 	ret = of_platform_populate(node, NULL, NULL, dev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to create dwc3 core\n");
-		goto err2;
+		goto err1;
 	}
 
 	return 0;
 
-err2:
-	if (omap->extcon_vbus_dev.edev)
-		extcon_unregister_interest(&omap->extcon_vbus_dev);
-	if (omap->extcon_id_dev.edev)
-		extcon_unregister_interest(&omap->extcon_id_dev);
-
 err1:
 	dwc3_omap_disable_irqs(omap);
 
@@ -554,10 +430,6 @@ static int dwc3_omap_remove(struct platform_device *pdev)
 {
 	struct dwc3_omap	*omap = platform_get_drvdata(pdev);
 
-	if (omap->extcon_vbus_dev.edev)
-		extcon_unregister_interest(&omap->extcon_vbus_dev);
-	if (omap->extcon_id_dev.edev)
-		extcon_unregister_interest(&omap->extcon_id_dev);
 	dwc3_omap_disable_irqs(omap);
 	device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
 
diff --git a/include/linux/usb/dwc3-omap.h b/include/linux/usb/dwc3-omap.h
new file mode 100644
index 0000000..8bf7b55
--- /dev/null
+++ b/include/linux/usb/dwc3-omap.h
@@ -0,0 +1,19 @@
+/* include/linux/usb/dwc3-omap.h
+ *
+ * Copyright (c) 2014 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Designware SuperSpeed Glue
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __DWC3_OMAP_H_
+#define __DWC3_OMAP_H_
+
+enum dwc3_omap_utmi_mode {
+	DWC3_OMAP_UTMI_MODE_UNKNOWN = 0,
+	DWC3_OMAP_UTMI_MODE_HW,
+	DWC3_OMAP_UTMI_MODE_SW,
+};
+
+#endif /* __DWC3_OMAP_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 25/40] include: dwc3-omap-uboot: add a structure for populating dwc3-omap platform data
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (23 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 24/40] usb: dwc3: dwc3-omap: make dwc3-omap build in uboot Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:03   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 26/40] usb: dwc3: dwc3-omap: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
                   ` (15 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Added a structure to populate dwc3 omap platform data. The board file should
populate these platform data before invoking dwc3 omap driver.

This will be removed once dwc3-omap driver is adapted to use the driver model.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/dwc3-omap.c |    7 -------
 include/dwc3-omap-uboot.h    |   27 +++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 7 deletions(-)
 create mode 100644 include/dwc3-omap-uboot.h

diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index b385987..31a2aa3 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -120,13 +120,6 @@ struct dwc3_omap {
 	u32			dma_status:1;
 };
 
-enum omap_dwc3_vbus_id_status {
-	OMAP_DWC3_ID_FLOAT,
-	OMAP_DWC3_ID_GROUND,
-	OMAP_DWC3_VBUS_OFF,
-	OMAP_DWC3_VBUS_VALID,
-};
-
 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
 {
 	return readl(base + offset);
diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
new file mode 100644
index 0000000..b313b64
--- /dev/null
+++ b/include/dwc3-omap-uboot.h
@@ -0,0 +1,27 @@
+/* include/dwc3_omap_uboot.h
+ *
+ * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Designware SuperSpeed OMAP Glue uboot init
+ *
+ * SPDX-License-Identifier:     GPL-2.0
+ */
+
+#ifndef __DWC3_OMAP_UBOOT_H_
+#define __DWC3_OMAP_UBOOT_H_
+
+#include <linux/usb/dwc3-omap.h>
+
+enum omap_dwc3_vbus_id_status {
+	OMAP_DWC3_ID_FLOAT,
+	OMAP_DWC3_ID_GROUND,
+	OMAP_DWC3_VBUS_OFF,
+	OMAP_DWC3_VBUS_VALID,
+};
+
+struct dwc3_omap_device {
+	void *base;
+	enum dwc3_omap_utmi_mode utmi_mode;
+	enum omap_dwc3_vbus_id_status vbus_id_status;
+};
+#endif /* __DWC3_OMAP_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 26/40] usb: dwc3: dwc3-omap: change probe and remove to uboot init and uboot exit code
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (24 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 25/40] include: dwc3-omap-uboot: add a structure for populating dwc3-omap platform data Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:04   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 27/40] dwc3: dwc3-omap: add support for multiple dwc3-omap controllers Kishon Vijay Abraham I
                   ` (14 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Removed probe and remove that are specific to linux and replaced it with
uboot init and uboot exit. These functions will be invoked from boardfile.

This will change once we have dwc3-omap driver adapted to use the uboot
driver model.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/dwc3-omap.c |  128 +++++++++++++-----------------------------
 include/dwc3-omap-uboot.h    |    3 +
 2 files changed, 42 insertions(+), 89 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 31a2aa3..30d7210 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -17,6 +17,7 @@
 #include <common.h>
 #include <malloc.h>
 #include <asm/io.h>
+#include <dwc3-omap-uboot.h>
 #include <linux/usb/dwc3-omap.h>
 #include <linux/ioport.h>
 
@@ -120,6 +121,8 @@ struct dwc3_omap {
 	u32			dma_status:1;
 };
 
+struct dwc3_omap *omap;
+
 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
 {
 	return readl(base + offset);
@@ -278,15 +281,6 @@ static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
 	return IRQ_HANDLED;
 }
 
-static int dwc3_omap_remove_core(struct device *dev, void *c)
-{
-	struct platform_device *pdev = to_platform_device(dev);
-
-	of_device_unregister(pdev);
-
-	return 0;
-}
-
 static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
 {
 	u32			reg;
@@ -315,12 +309,8 @@ static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
 	dwc3_omap_write_irq0_set(omap, 0x00);
 }
 
-static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
-
 static void dwc3_omap_map_offset(struct dwc3_omap *omap)
 {
-	struct device_node	*node = omap->dev->of_node;
-
 	/*
 	 * Differentiate between OMAP5 and AM437x.
 	 *
@@ -329,25 +319,21 @@ static void dwc3_omap_map_offset(struct dwc3_omap *omap)
 	 *
 	 * Using dt compatible to differentiate AM437x.
 	 */
-	if (of_device_is_compatible(node, "ti,am437x-dwc3")) {
-		omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
-		omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
-		omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
-		omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
-		omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
-	}
+#ifdef CONFIG_AM43XX
+	omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
+	omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
+	omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
+	omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
+	omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
+#endif
 }
 
-static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
+static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap, int utmi_mode)
 {
 	u32			reg;
-	struct device_node	*node = omap->dev->of_node;
-	int			utmi_mode = 0;
 
 	reg = dwc3_omap_read_utmi_status(omap);
 
-	of_property_read_u32(node, "utmi-mode", &utmi_mode);
-
 	switch (utmi_mode) {
 	case DWC3_OMAP_UTMI_MODE_SW:
 		reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
@@ -362,95 +348,59 @@ static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
 	dwc3_omap_write_utmi_status(omap, reg);
 }
 
-static int dwc3_omap_probe(struct platform_device *pdev)
+/**
+ * dwc3_omap_uboot_init - dwc3 omap uboot initialization code
+ * @dev: struct dwc3_omap_device containing initialization data
+ *
+ * Entry point for dwc3 omap driver (equivalent to dwc3_omap_probe in linux
+ * kernel driver). Pointer to dwc3_omap_device should be passed containing
+ * base address and other initialization data. Returns '0' on success and
+ * a negative value on failure.
+ *
+ * Generally called from board_usb_init() implemented in board file.
+ */
+int dwc3_omap_uboot_init(struct dwc3_omap_device *omap_dev)
 {
-	struct device_node	*node = pdev->dev.of_node;
-
-	struct dwc3_omap	*omap;
-	struct resource		*res;
-	struct device		*dev = &pdev->dev;
-
-	int			ret;
 	u32			reg;
-
-	void __iomem		*base;
-
-	if (!node) {
-		dev_err(dev, "device node not found\n");
-		return -EINVAL;
-	}
+	struct device		*dev;
 
 	omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
 	if (!omap)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, omap);
-
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	base = devm_ioremap_resource(dev, res);
-	if (IS_ERR(base))
-		return PTR_ERR(base);
-
-	omap->dev	= dev;
-	omap->base	= base;
-	dev->dma_mask	= &dwc3_omap_dma_mask;
+	omap->base	= omap_dev->base;
 
 	dwc3_omap_map_offset(omap);
-	dwc3_omap_set_utmi_mode(omap);
+	dwc3_omap_set_utmi_mode(omap, omap_dev->utmi_mode);
 
 	/* check the DMA Status */
 	reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
 	omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
 
-	dwc3_omap_enable_irqs(omap);
+	dwc3_omap_set_mailbox(omap, omap_dev->vbus_id_status);
 
-	ret = of_platform_populate(node, NULL, NULL, dev);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to create dwc3 core\n");
-		goto err1;
-	}
+	dwc3_omap_enable_irqs(omap);
 
 	return 0;
-
-err1:
-	dwc3_omap_disable_irqs(omap);
-
-err0:
-	return ret;
 }
 
-static int dwc3_omap_remove(struct platform_device *pdev)
+/**
+ * dwc3_omap_uboot_exit - dwc3 omap uboot cleanup code
+ * @index: index of this controller
+ *
+ * Performs cleanup of memory allocated in dwc3_omap_uboot_init
+ * (equivalent to dwc3_omap_remove in linux).
+ *
+ * Generally called from board file.
+ */
+void dwc3_omap_uboot_exit(void)
 {
-	struct dwc3_omap	*omap = platform_get_drvdata(pdev);
-
 	dwc3_omap_disable_irqs(omap);
-	device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
+	kfree(omap);
 
 	return 0;
 }
 
-static const struct of_device_id of_dwc3_match[] = {
-	{
-		.compatible =	"ti,dwc3"
-	},
-	{
-		.compatible =	"ti,am437x-dwc3"
-	},
-	{ },
-};
-MODULE_DEVICE_TABLE(of, of_dwc3_match);
-
-static struct platform_driver dwc3_omap_driver = {
-	.probe		= dwc3_omap_probe,
-	.remove		= dwc3_omap_remove,
-	.driver		= {
-		.name	= "omap-dwc3",
-		.of_match_table	= of_dwc3_match,
-	},
-};
-
-module_platform_driver(dwc3_omap_driver);
-
 MODULE_ALIAS("platform:omap-dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("GPL v2");
diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
index b313b64..99f8f38 100644
--- a/include/dwc3-omap-uboot.h
+++ b/include/dwc3-omap-uboot.h
@@ -24,4 +24,7 @@ struct dwc3_omap_device {
 	enum dwc3_omap_utmi_mode utmi_mode;
 	enum omap_dwc3_vbus_id_status vbus_id_status;
 };
+
+int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
+void dwc3_omap_uboot_exit(void);
 #endif /* __DWC3_OMAP_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 27/40] dwc3: dwc3-omap: add support for multiple dwc3-omap controllers
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (25 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 26/40] usb: dwc3: dwc3-omap: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:06   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 28/40] usb: dwc3: dwc3-omap: add interrupt status API to check for interrupts Kishon Vijay Abraham I
                   ` (13 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Added support for multiple dwc3 omap controllers. This gives uboot
the capability to control multiple dwc3 omap controllers.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/dwc3-omap.c |   26 ++++++++++++++++++++------
 include/dwc3-omap-uboot.h    |    3 ++-
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 30d7210..c8275c7 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -119,9 +119,11 @@ struct dwc3_omap {
 	u32			irq0_offset;
 
 	u32			dma_status:1;
+	struct list_head	list;
+	u32			index;
 };
 
-struct dwc3_omap *omap;
+static LIST_HEAD(dwc3_omap_list);
 
 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
 {
@@ -363,12 +365,14 @@ int dwc3_omap_uboot_init(struct dwc3_omap_device *omap_dev)
 {
 	u32			reg;
 	struct device		*dev;
+	struct dwc3_omap	*omap;
 
 	omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
 	if (!omap)
 		return -ENOMEM;
 
 	omap->base	= omap_dev->base;
+	omap->index	= omap_dev->index;
 
 	dwc3_omap_map_offset(omap);
 	dwc3_omap_set_utmi_mode(omap, omap_dev->utmi_mode);
@@ -380,6 +384,7 @@ int dwc3_omap_uboot_init(struct dwc3_omap_device *omap_dev)
 	dwc3_omap_set_mailbox(omap, omap_dev->vbus_id_status);
 
 	dwc3_omap_enable_irqs(omap);
+	list_add_tail(&omap->list, &dwc3_omap_list);
 
 	return 0;
 }
@@ -389,16 +394,25 @@ int dwc3_omap_uboot_init(struct dwc3_omap_device *omap_dev)
  * @index: index of this controller
  *
  * Performs cleanup of memory allocated in dwc3_omap_uboot_init
- * (equivalent to dwc3_omap_remove in linux).
+ * (equivalent to dwc3_omap_remove in linux). index of _this_ controller
+ * should be passed and should match with the index passed in
+ * dwc3_omap_device during init.
  *
  * Generally called from board file.
  */
-void dwc3_omap_uboot_exit(void)
+void dwc3_omap_uboot_exit(int index)
 {
-	dwc3_omap_disable_irqs(omap);
-	kfree(omap);
+	struct dwc3_omap *omap = NULL;
 
-	return 0;
+	list_for_each_entry(omap, &dwc3_omap_list, list) {
+		if (omap->index != index)
+			continue;
+
+		dwc3_omap_disable_irqs(omap);
+		list_del(&omap->list);
+		kfree(omap);
+		break;
+	}
 }
 
 MODULE_ALIAS("platform:omap-dwc3");
diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
index 99f8f38..29f02f8 100644
--- a/include/dwc3-omap-uboot.h
+++ b/include/dwc3-omap-uboot.h
@@ -21,10 +21,11 @@ enum omap_dwc3_vbus_id_status {
 
 struct dwc3_omap_device {
 	void *base;
+	int index;
 	enum dwc3_omap_utmi_mode utmi_mode;
 	enum omap_dwc3_vbus_id_status vbus_id_status;
 };
 
 int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
-void dwc3_omap_uboot_exit(void);
+void dwc3_omap_uboot_exit(int index);
 #endif /* __DWC3_OMAP_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 28/40] usb: dwc3: dwc3-omap: add interrupt status API to check for interrupts
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (26 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 27/40] dwc3: dwc3-omap: add support for multiple dwc3-omap controllers Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:07   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 29/40] usb: dwc3: TI PHY: PHY driver for dwc3 in TI platforms Kishon Vijay Abraham I
                   ` (12 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Added an API to check for interrupt status. This API is generally
called from board file to check for interrupt status.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/dwc3-omap.c |   20 ++++++++++++++++++++
 include/dwc3-omap-uboot.h    |    1 +
 2 files changed, 21 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index c8275c7..46af109 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -415,6 +415,26 @@ void dwc3_omap_uboot_exit(int index)
 	}
 }
 
+/**
+ * dwc3_omap_uboot_interrupt_status - check the status of interrupt
+ * @index: index of this controller
+ *
+ * Checks the status of interrupts and returns true if an interrupt
+ * is detected or false otherwise.
+ *
+ * Generally called from board file.
+ */
+int dwc3_omap_uboot_interrupt_status(int index)
+{
+	struct dwc3_omap *omap = NULL;
+
+	list_for_each_entry(omap, &dwc3_omap_list, list)
+		if (omap->index == index)
+			return dwc3_omap_interrupt(-1, omap);
+
+	return 0;
+}
+
 MODULE_ALIAS("platform:omap-dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("GPL v2");
diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
index 29f02f8..db002b9 100644
--- a/include/dwc3-omap-uboot.h
+++ b/include/dwc3-omap-uboot.h
@@ -28,4 +28,5 @@ struct dwc3_omap_device {
 
 int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
 void dwc3_omap_uboot_exit(int index);
+int dwc3_omap_uboot_interrupt_status(int index);
 #endif /* __DWC3_OMAP_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 29/40] usb: dwc3: TI PHY: PHY driver for dwc3 in TI platforms
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (27 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 28/40] usb: dwc3: dwc3-omap: add interrupt status API to check for interrupts Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:13   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 30/40] dwc3: flush the buffers before using it Kishon Vijay Abraham I
                   ` (11 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Added a single driver for both USB2 PHY programming and USB3 PHY
programming.

USB3 PHY is taken from drivers/phy/phy-ti-pipe3.c in linux kernel.
commit 56042e : phy: ti-pipe3: Fix suspend/resume and module reload.

USB2 PHY is taken from drivers/phy/phy-omap-usb2.c in linux kernel.
commit eb82a3 : phy: omap-usb2: Balance pm_runtime_enable() on probe
failure and remove.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/ti_usb_phy.c |  309 +++++++++++++++++++++++++++++++++++++++++
 include/ti-usb-phy-uboot.h    |   22 +++
 2 files changed, 331 insertions(+)
 create mode 100644 drivers/usb/dwc3/ti_usb_phy.c
 create mode 100644 include/ti-usb-phy-uboot.h

diff --git a/drivers/usb/dwc3/ti_usb_phy.c b/drivers/usb/dwc3/ti_usb_phy.c
new file mode 100644
index 0000000..e6048eb
--- /dev/null
+++ b/drivers/usb/dwc3/ti_usb_phy.c
@@ -0,0 +1,309 @@
+/**
+ * ti_usb_phy.c - USB3 and USB3 PHY programming for dwc3
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author: Kishon Vijay Abraham I <kishon@ti.com>
+ *
+ * Taken from Linux Kernel v3.16 (drivers/phy/phy-ti-pipe3.c and
+ * drivers/phy/phy-omap-usb2.c) and ported to uboot.
+ *
+ * "commit 56042e : phy: ti-pipe3: Fix suspend/resume and module reload" for
+ * phy-ti-pipe3.c
+ *
+ * "commit eb82a3 : phy: omap-usb2: Balance pm_runtime_enable() on probe failure
+ * and remove" for phy-omap-usb2.c
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <ti-usb-phy-uboot.h>
+#include <usb/lin_gadget_compat.h>
+#include <linux/ioport.h>
+#include <asm/io.h>
+#include <asm/arch/sys_proto.h>
+
+#include "linux-compat.h"
+
+#define PLL_STATUS		0x00000004
+#define PLL_GO			0x00000008
+#define PLL_CONFIGURATION1	0x0000000C
+#define PLL_CONFIGURATION2	0x00000010
+#define PLL_CONFIGURATION3	0x00000014
+#define PLL_CONFIGURATION4	0x00000020
+
+#define PLL_REGM_MASK		0x001FFE00
+#define PLL_REGM_SHIFT		0x9
+#define PLL_REGM_F_MASK		0x0003FFFF
+#define PLL_REGM_F_SHIFT	0x0
+#define PLL_REGN_MASK		0x000001FE
+#define PLL_REGN_SHIFT		0x1
+#define PLL_SELFREQDCO_MASK	0x0000000E
+#define PLL_SELFREQDCO_SHIFT	0x1
+#define PLL_SD_MASK		0x0003FC00
+#define PLL_SD_SHIFT		10
+#define SET_PLL_GO		0x1
+#define PLL_LDOPWDN		BIT(15)
+#define PLL_TICOPWDN		BIT(16)
+#define PLL_LOCK		0x2
+#define PLL_IDLE		0x1
+
+#define OMAP_CTRL_DEV_PHY_PD				BIT(0)
+#define OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_MASK		0x003FC000
+#define OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_SHIFT		0xE
+
+#define OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_MASK		0xFFC00000
+#define OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_SHIFT	0x16
+
+#define OMAP_CTRL_USB3_PHY_TX_RX_POWERON	0x3
+#define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF	0x0
+
+#define OMAP_CTRL_USB2_PHY_PD			BIT(28)
+
+#define AM437X_CTRL_USB2_PHY_PD			BIT(0)
+#define AM437X_CTRL_USB2_OTG_PD			BIT(1)
+#define AM437X_CTRL_USB2_OTGVDET_EN		BIT(19)
+#define AM437X_CTRL_USB2_OTGSESSEND_EN		BIT(20)
+
+static LIST_HEAD(ti_usb_phy_list);
+typedef unsigned int u32;
+
+struct usb3_dpll_params {
+	u16	m;
+	u8	n;
+	u8	freq:3;
+	u8	sd;
+	u32	mf;
+};
+
+struct usb3_dpll_map {
+	unsigned long rate;
+	struct usb3_dpll_params params;
+	struct usb3_dpll_map *dpll_map;
+};
+
+struct ti_usb_phy {
+	void __iomem *pll_ctrl_base;
+	void __iomem *usb2_phy_power;
+	void __iomem *usb3_phy_power;
+	struct usb3_dpll_map *dpll_map;
+	struct list_head list;
+	int index;
+};
+
+static struct usb3_dpll_map dpll_map_usb[] = {
+	{12000000, {1250, 5, 4, 20, 0} },	/* 12 MHz */
+	{16800000, {3125, 20, 4, 20, 0} },	/* 16.8 MHz */
+	{19200000, {1172, 8, 4, 20, 65537} },	/* 19.2 MHz */
+	{20000000, {1000, 7, 4, 10, 0} },	/* 20 MHz */
+	{26000000, {1250, 12, 4, 20, 0} },	/* 26 MHz */
+	{38400000, {3125, 47, 4, 20, 92843} },	/* 38.4 MHz */
+	{ },					/* Terminator */
+};
+
+static inline unsigned int ti_usb3_readl(void __iomem *base, u32 offset)
+{
+	return readl(base + offset);
+}
+
+static inline void ti_usb3_writel(void __iomem *base, u32 offset, u32 value)
+{
+	writel(value, base + offset);
+}
+
+#ifndef CONFIG_AM43XX
+static struct usb3_dpll_params *ti_usb3_get_dpll_params(struct ti_usb_phy *phy)
+{
+	unsigned long rate;
+	struct usb3_dpll_map *dpll_map = phy->dpll_map;
+
+	rate = get_sys_clk_freq();
+
+	for (; dpll_map->rate; dpll_map++) {
+		if (rate == dpll_map->rate)
+			return &dpll_map->params;
+	}
+
+	dev_err(phy->dev, "No DPLL configuration for %lu Hz SYS CLK\n", rate);
+
+	return NULL;
+}
+
+static int ti_usb3_dpll_wait_lock(struct ti_usb_phy *phy)
+{
+	u32 val;
+	do {
+		val = ti_usb3_readl(phy->pll_ctrl_base, PLL_STATUS);
+			if (val & PLL_LOCK)
+				break;
+	} while (1);
+
+	return 0;
+}
+
+static int ti_usb3_dpll_program(struct ti_usb_phy *phy)
+{
+	u32			val;
+	struct usb3_dpll_params	*dpll_params;
+
+	if (!phy->pll_ctrl_base)
+		return -EINVAL;
+
+	dpll_params = ti_usb3_get_dpll_params(phy);
+	if (!dpll_params)
+		return -EINVAL;
+
+	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1);
+	val &= ~PLL_REGN_MASK;
+	val |= dpll_params->n << PLL_REGN_SHIFT;
+	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val);
+
+	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
+	val &= ~PLL_SELFREQDCO_MASK;
+	val |= dpll_params->freq << PLL_SELFREQDCO_SHIFT;
+	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val);
+
+	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1);
+	val &= ~PLL_REGM_MASK;
+	val |= dpll_params->m << PLL_REGM_SHIFT;
+	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val);
+
+	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION4);
+	val &= ~PLL_REGM_F_MASK;
+	val |= dpll_params->mf << PLL_REGM_F_SHIFT;
+	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION4, val);
+
+	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION3);
+	val &= ~PLL_SD_MASK;
+	val |= dpll_params->sd << PLL_SD_SHIFT;
+	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION3, val);
+
+	ti_usb3_writel(phy->pll_ctrl_base, PLL_GO, SET_PLL_GO);
+
+	return ti_usb3_dpll_wait_lock(phy);
+}
+#endif
+
+void ti_usb2_phy_power(struct ti_usb_phy *phy, int on)
+{
+	u32 val;
+
+	val = readl(phy->usb2_phy_power);
+
+	if (on) {
+#ifdef CONFIG_DRA7XX
+		val &= ~OMAP_CTRL_DEV_PHY_PD;
+#elif defined(CONFIG_AM43XX)
+		val &= ~(AM437X_CTRL_USB2_PHY_PD |
+			 AM437X_CTRL_USB2_OTG_PD);
+		val |= (AM437X_CTRL_USB2_OTGVDET_EN |
+			AM437X_CTRL_USB2_OTGSESSEND_EN);
+#endif
+	} else {
+#ifdef CONFIG_DRA7XX
+		val |= OMAP_CTRL_DEV_PHY_PD;
+#elif defined(CONFIG_AM43XX)
+		val &= ~(AM437X_CTRL_USB2_OTGVDET_EN |
+			 AM437X_CTRL_USB2_OTGSESSEND_EN);
+		val |= (AM437X_CTRL_USB2_PHY_PD |
+			AM437X_CTRL_USB2_OTG_PD);
+#endif
+	}
+	writel(val, phy->usb2_phy_power);
+}
+
+#ifndef CONFIG_AM43XX
+void ti_usb3_phy_power(struct ti_usb_phy *phy, int on)
+{
+	u32 val;
+	u32 rate;
+	rate = get_sys_clk_freq();
+	rate = rate/1000000;
+
+	if (!phy->usb3_phy_power)
+		return;
+
+	val = readl(phy->usb3_phy_power);
+	if (on) {
+		val &= ~(OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_MASK |
+			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_MASK);
+		val |= (OMAP_CTRL_USB3_PHY_TX_RX_POWERON) <<
+			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_SHIFT;
+		val |= rate <<
+			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_SHIFT;
+	} else {
+		val &= ~OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_MASK;
+		val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
+			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_SHIFT;
+	}
+	writel(val, phy->usb3_phy_power);
+}
+#endif
+
+/**
+ * ti_usb_phy_uboot_init - usb phy uboot initialization code
+ * @dev: struct ti_usb_phy_device containing initialization data
+ *
+ * Entry point for ti usb phy driver. This driver handles initialization
+ * of both usb2 phy and usb3 phy. Pointer to ti_usb_phy_device should be
+ * passed containing base address and other initialization data.
+ * Returns '0' on success and a negative value on failure.
+ *
+ * Generally called from board_usb_init() implemented in board file.
+ */
+int ti_usb_phy_uboot_init(struct ti_usb_phy_device *dev)
+{
+	struct ti_usb_phy *phy;
+
+	phy = devm_kzalloc(NULL, sizeof(*phy), GFP_KERNEL);
+	if (!phy) {
+		dev_err(NULL, "unable to alloc mem for TI USB3 PHY\n");
+		return -ENOMEM;
+	}
+
+	phy->dpll_map = dpll_map_usb;
+	phy->index = dev->index;
+	phy->pll_ctrl_base = dev->pll_ctrl_base;
+	phy->usb2_phy_power = dev->usb2_phy_power;
+	phy->usb3_phy_power = dev->usb3_phy_power;
+
+#ifndef CONFIG_AM43XX
+	ti_usb3_dpll_program(phy);
+	ti_usb3_phy_power(phy, 1);
+#endif
+	ti_usb2_phy_power(phy, 1);
+	mdelay(150);
+	list_add_tail(&phy->list, &ti_usb_phy_list);
+
+	return 0;
+}
+
+/**
+ * ti_usb_phy_uboot_exit - usb phy uboot cleanup code
+ * @index: index of this controller
+ *
+ * Performs cleanup of memory allocated in ti_usb_phy_uboot_init.
+ * index of _this_ controller should be passed and should match with
+ * the index passed in ti_usb_phy_device during init.
+ *
+ * Generally called from board file.
+ */
+void ti_usb_phy_uboot_exit(int index)
+{
+	struct ti_usb_phy *phy = NULL;
+
+	list_for_each_entry(phy, &ti_usb_phy_list, list) {
+		if (phy->index != index)
+			continue;
+
+		ti_usb2_phy_power(phy, 0);
+#ifndef CONFIG_AM43XX
+		ti_usb3_phy_power(phy, 0);
+#endif
+		list_del(&phy->list);
+		kfree(phy);
+		break;
+	}
+}
diff --git a/include/ti-usb-phy-uboot.h b/include/ti-usb-phy-uboot.h
new file mode 100644
index 0000000..93f7101
--- /dev/null
+++ b/include/ti-usb-phy-uboot.h
@@ -0,0 +1,22 @@
+/* include/ti_usb_phy_uboot.h
+ *
+ * Copyright (c) 2014 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * USB2 and USB3 PHY uboot init
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#ifndef __TI_USB_PHY_UBOOT_H_
+#define __TI_USB_PHY_UBOOT_H_
+
+struct ti_usb_phy_device {
+	void *pll_ctrl_base;
+	void *usb2_phy_power;
+	void *usb3_phy_power;
+	int index;
+};
+
+int ti_usb_phy_uboot_init(struct ti_usb_phy_device *dev);
+void ti_usb_phy_uboot_exit(int index);
+#endif /* __TI_USB_PHY_UBOOT_H_ */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 30/40] dwc3: flush the buffers before using it
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (28 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 29/40] usb: dwc3: TI PHY: PHY driver for dwc3 in TI platforms Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:39   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 31/40] usb: dwc3: ep0: preparation for implementing chained TRB Kishon Vijay Abraham I
                   ` (10 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

In the linux kernel, non cacheable buffers are used. However in uboot
since there are no APIs to allocate non cacheable memory, all
the buffers should be flushed before using it.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/core.c   |    7 +++++++
 drivers/usb/dwc3/ep0.c    |    6 ++++++
 drivers/usb/dwc3/gadget.c |    5 +++++
 drivers/usb/dwc3/io.h     |    6 ++++++
 4 files changed, 24 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 5a8d5ea..4c3637f 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -769,11 +769,18 @@ void dwc3_uboot_exit(int index)
 void dwc3_uboot_handle_interrupt(int index)
 {
 	struct dwc3 *dwc = NULL;
+	int i;
+	struct dwc3_event_buffer *evt;
 
 	list_for_each_entry(dwc, &dwc3_list, list) {
 		if (dwc->index != index)
 			continue;
 
+		for (i = 0; i < dwc->num_event_buffers; i++) {
+			evt = dwc->ev_buffs[i];
+			dwc3_flush_cache((int)evt->buf, evt->length);
+		}
+
 		dwc3_gadget_uboot_handle_interrupt(dwc);
 		break;
 	}
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 803ba51..977d6d4 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -74,6 +74,9 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
 			| DWC3_TRB_CTRL_IOC
 			| DWC3_TRB_CTRL_ISP_IMI);
 
+	dwc3_flush_cache((int)buf_dma, len);
+	dwc3_flush_cache((int)trb, sizeof(*trb));
+
 	memset(&params, 0, sizeof(params));
 	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
 	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
@@ -774,6 +777,8 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 	if (!r)
 		return;
 
+	dwc3_flush_cache((int)trb, sizeof(*trb));
+
 	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
 	if (status == DWC3_TRBSTS_SETUP_PENDING) {
 		dev_dbg(dwc->dev, "Setup Pending received");
@@ -795,6 +800,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 		transfer_size += (maxp - (transfer_size % maxp));
 		transferred = min_t(u32, ur->length,
 				transfer_size - length);
+		dwc3_flush_cache((int)dwc->ep0_bounce, DWC3_EP0_BOUNCE_SIZE);
 		memcpy(ur->buf, dwc->ep0_bounce, transferred);
 	} else {
 		transferred = ur->length - length;
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 1f97729..b68b6a4 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -244,6 +244,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 
 	list_del(&req->list);
 	req->trb = NULL;
+	dwc3_flush_cache((int)req->request.dma, req->request.length);
 
 	if (req->request.status == -EINPROGRESS)
 		req->request.status = status;
@@ -769,6 +770,9 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
 		trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id);
 
 	trb->ctrl |= DWC3_TRB_CTRL_HWO;
+
+	dwc3_flush_cache((int)dma, length);
+	dwc3_flush_cache((int)trb, sizeof(*trb));
 }
 
 /*
@@ -1770,6 +1774,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
 		slot %= DWC3_TRB_NUM;
 		trb = &dep->trb_pool[slot];
 
+		dwc3_flush_cache((int)trb, sizeof(*trb));
 		ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
 				event, status);
 		if (ret)
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index b6da135..31606de 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -20,6 +20,7 @@
 
 #include <asm/io.h>
 
+#define	CACHELINE_SIZE		CONFIG_SYS_CACHELINE_SIZE
 static inline u32 dwc3_readl(void __iomem *base, u32 offset)
 {
 	u32 offs = offset - DWC3_GLOBALS_REGS_START;
@@ -47,4 +48,9 @@ static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
 	writel(value, base + offs);
 }
 
+static inline void dwc3_flush_cache(int addr, int length)
+{
+	flush_dcache_range(addr & ~(CACHELINE_SIZE - 1),
+			   ALIGN(addr + length, CACHELINE_SIZE));
+}
 #endif /* __DRIVERS_USB_DWC3_IO_H */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 31/40] usb: dwc3: ep0: preparation for implementing chained TRB
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (29 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 30/40] dwc3: flush the buffers before using it Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:40   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0 Kishon Vijay Abraham I
                   ` (9 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

No functional change. Modified few things so that there are no
code duplication while implementing chained TRB.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/ep0.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 977d6d4..fce2558 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -761,7 +761,10 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 	struct usb_request	*ur;
 	struct dwc3_trb		*trb;
 	struct dwc3_ep		*ep0;
-	u32			transferred;
+	unsigned		transfer_size = 0;
+	unsigned		maxp;
+	void			*buf;
+	u32			transferred = 0;
 	u32			status;
 	u32			length;
 	u8			epnum;
@@ -790,18 +793,19 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 	}
 
 	ur = &r->request;
+	buf = ur->buf;
 
 	length = trb->size & DWC3_TRB_SIZE_MASK;
 
-	if (dwc->ep0_bounced) {
-		unsigned transfer_size = ur->length;
-		unsigned maxp = ep0->endpoint.maxpacket;
+	maxp = ep0->endpoint.maxpacket;
 
-		transfer_size += (maxp - (transfer_size % maxp));
-		transferred = min_t(u32, ur->length,
-				transfer_size - length);
+	if (dwc->ep0_bounced) {
+		transfer_size = roundup((ur->length - transfer_size),
+					maxp);
+		transferred = min_t(u32, ur->length - transferred,
+				    transfer_size - length);
 		dwc3_flush_cache((int)dwc->ep0_bounce, DWC3_EP0_BOUNCE_SIZE);
-		memcpy(ur->buf, dwc->ep0_bounce, transferred);
+		memcpy(buf, dwc->ep0_bounce, transferred);
 	} else {
 		transferred = ur->length - length;
 	}
-- 
1.7.9.5

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

* [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (30 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 31/40] usb: dwc3: ep0: preparation for implementing chained TRB Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:42   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 33/40] usb: dwc3: Makefile: Make dwc3 driver compile in u-boot Kishon Vijay Abraham I
                   ` (8 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

dwc3 can do only max packet aligned transfers. So in case request length
is not max packet aligned and is bigger than DWC3_EP0_BOUNCE_SIZE
two chained TRBs is required to handle the transfer.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/dwc3/ep0.c    |   72 +++++++++++++++++++++++++++++++++------------
 drivers/usb/dwc3/gadget.c |    2 +-
 2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index fce2558..c2fe0ec 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -48,7 +48,7 @@ static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
 }
 
 static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
-		u32 len, u32 type)
+				u32 len, u32 type, unsigned chain)
 {
 	struct dwc3_gadget_ep_cmd_params params;
 	struct dwc3_trb			*trb;
@@ -62,7 +62,10 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
 		return 0;
 	}
 
-	trb = dwc->ep0_trb;
+	trb = &dwc->ep0_trb[dep->free_slot];
+
+	if (chain)
+		dep->free_slot++;
 
 	trb->bpl = lower_32_bits(buf_dma);
 	trb->bph = upper_32_bits(buf_dma);
@@ -70,13 +73,20 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
 	trb->ctrl = type;
 
 	trb->ctrl |= (DWC3_TRB_CTRL_HWO
-			| DWC3_TRB_CTRL_LST
-			| DWC3_TRB_CTRL_IOC
 			| DWC3_TRB_CTRL_ISP_IMI);
 
+	if (chain)
+		trb->ctrl |= DWC3_TRB_CTRL_CHN;
+	else
+		trb->ctrl |= (DWC3_TRB_CTRL_IOC
+				| DWC3_TRB_CTRL_LST);
+
 	dwc3_flush_cache((int)buf_dma, len);
 	dwc3_flush_cache((int)trb, sizeof(*trb));
 
+	if (chain)
+		return 0;
+
 	memset(&params, 0, sizeof(params));
 	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
 	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
@@ -289,7 +299,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
 	int				ret;
 
 	ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
-			DWC3_TRBCTL_CONTROL_SETUP);
+				   DWC3_TRBCTL_CONTROL_SETUP, 0);
 	WARN_ON(ret < 0);
 }
 
@@ -799,6 +809,23 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 
 	maxp = ep0->endpoint.maxpacket;
 
+	/* Handle the first TRB before handling the bounce buffer if the request
+	 * length is greater than the bounce buffer size
+	 */
+	if (!IS_ALIGNED(ur->length, maxp) &&
+	    ur->length > DWC3_EP0_BOUNCE_SIZE) {
+		transfer_size = (ur->length / maxp) * maxp;
+		transferred = transfer_size - length;
+		buf = (u8 *)buf + transferred;
+		ur->actual += transferred;
+
+		trb++;
+		dwc3_flush_cache((int)trb, sizeof(*trb));
+		length = trb->size & DWC3_TRB_SIZE_MASK;
+
+		ep0->free_slot = 0;
+	}
+
 	if (dwc->ep0_bounced) {
 		transfer_size = roundup((ur->length - transfer_size),
 					maxp);
@@ -827,7 +854,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
 
 			ret = dwc3_ep0_start_trans(dwc, epnum,
 					dwc->ctrl_req_addr, 0,
-					DWC3_TRBCTL_CONTROL_DATA);
+					DWC3_TRBCTL_CONTROL_DATA, 0);
 			WARN_ON(ret < 0);
 		}
 	}
@@ -908,11 +935,11 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 
 	if (req->request.length == 0) {
 		ret = dwc3_ep0_start_trans(dwc, dep->number,
-				dwc->ctrl_req_addr, 0,
-				DWC3_TRBCTL_CONTROL_DATA);
-	} else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket)
-			&& (dep->number == 0)) {
-		u32	transfer_size;
+					   dwc->ctrl_req_addr, 0,
+					   DWC3_TRBCTL_CONTROL_DATA, 0);
+	} else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) &&
+			(dep->number == 0)) {
+		u32	transfer_size = 0;
 		u32	maxpacket;
 
 		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
@@ -922,10 +949,18 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 			return;
 		}
 
-		WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
-
 		maxpacket = dep->endpoint.maxpacket;
-		transfer_size = roundup(req->request.length, maxpacket);
+		if (req->request.length > DWC3_EP0_BOUNCE_SIZE) {
+			transfer_size = (req->request.length / maxpacket) *
+						maxpacket;
+			ret = dwc3_ep0_start_trans(dwc, dep->number,
+						   req->request.dma,
+						   transfer_size,
+						   DWC3_TRBCTL_CONTROL_DATA, 1);
+		}
+
+		transfer_size = roundup((req->request.length - transfer_size),
+					maxpacket);
 
 		dwc->ep0_bounced = true;
 
@@ -935,8 +970,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 		 * TRBs to handle the transfer.
 		 */
 		ret = dwc3_ep0_start_trans(dwc, dep->number,
-				dwc->ep0_bounce_addr, transfer_size,
-				DWC3_TRBCTL_CONTROL_DATA);
+					   dwc->ep0_bounce_addr, transfer_size,
+					   DWC3_TRBCTL_CONTROL_DATA, 0);
 	} else {
 		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
 				dep->number);
@@ -946,7 +981,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 		}
 
 		ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma,
-				req->request.length, DWC3_TRBCTL_CONTROL_DATA);
+					   req->request.length,
+					   DWC3_TRBCTL_CONTROL_DATA, 0);
 	}
 
 	WARN_ON(ret < 0);
@@ -961,7 +997,7 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
 		: DWC3_TRBCTL_CONTROL_STATUS2;
 
 	return dwc3_ep0_start_trans(dwc, dep->number,
-			dwc->ctrl_req_addr, 0, type);
+			dwc->ctrl_req_addr, 0, type, 0);
 }
 
 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index b68b6a4..01bc83b 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2580,7 +2580,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 		goto err0;
 	}
 
-	dwc->ep0_trb = dma_alloc_coherent(sizeof(*dwc->ep0_trb),
+	dwc->ep0_trb = dma_alloc_coherent(sizeof(*dwc->ep0_trb) * 2,
 					  (unsigned long *)&dwc->ep0_trb_addr);
 	if (!dwc->ep0_trb) {
 		dev_err(dwc->dev, "failed to allocate ep0 trb\n");
-- 
1.7.9.5

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

* [U-Boot] [u-boot 33/40] usb: dwc3: Makefile: Make dwc3 driver compile in u-boot
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (31 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0 Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:43   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 34/40] usb: gadget: defer setting maxpacket till ->setup() Kishon Vijay Abraham I
                   ` (7 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Now that the entire dwc3 driver is adapted to compile with uboot build,
modify the Makefiles so that the dwc3 driver can be built.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 Makefile                        |    2 ++
 drivers/usb/dwc3/Makefile       |   35 +++--------------------------------
 drivers/usb/gadget/udc/Makefile |    2 +-
 3 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/Makefile b/Makefile
index 1eb6821..ca0fd76 100644
--- a/Makefile
+++ b/Makefile
@@ -632,8 +632,10 @@ libs-y += drivers/spi/
 libs-$(CONFIG_FMAN_ENET) += drivers/net/fm/
 libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-y += drivers/serial/
+libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/eth/
 libs-y += drivers/usb/gadget/
+libs-y += drivers/usb/gadget/udc/
 libs-y += drivers/usb/host/
 libs-y += drivers/usb/musb/
 libs-y += drivers/usb/musb-new/
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index afaa767..e455a52 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -1,37 +1,8 @@
-ccflags-$(CONFIG_USB_DWC3_DEBUG)	:= -DDEBUG
-ccflags-$(CONFIG_USB_DWC3_VERBOSE)	+= -DVERBOSE_DEBUG
-
 obj-$(CONFIG_USB_DWC3)			+= dwc3.o
 
-dwc3-y					:= core.o debug.o
-
-ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
-	dwc3-y				+= host.o
-endif
-
-ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
-	dwc3-y				+= gadget.o ep0.o
-endif
-
-ifneq ($(CONFIG_DEBUG_FS),)
-	dwc3-y				+= debugfs.o
-endif
+dwc3-y					:= core.o
 
-##
-# Platform-specific glue layers go here
-#
-# NOTICE: Make sure your glue layer doesn't depend on anything
-# which is arch-specific and that it compiles on all situations.
-#
-# We want to keep this requirement in order to be able to compile
-# the entire driver (with all its glue layers) on several architectures
-# and make sure it compiles fine. This will also help with allmodconfig
-# and allyesconfig builds.
-##
+dwc3-y					+= gadget.o ep0.o
 
 obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
-obj-$(CONFIG_USB_DWC3_EXYNOS)		+= dwc3-exynos.o
-obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
-obj-$(CONFIG_USB_DWC3_KEYSTONE)		+= dwc3-keystone.o
-obj-$(CONFIG_USB_DWC3_QCOM)		+= dwc3-qcom.o
-obj-$(CONFIG_USB_DWC3_ST)		+= dwc3-st.o
+obj-$(CONFIG_USB_DWC3_PHY_OMAP)		+= ti_usb_phy.o
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index be265aa..12380f4 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -1,4 +1,4 @@
 #
 # USB peripheral controller drivers
 #
-obj-$(CONFIG_USB_GADGET)	+= udc-core.o
+obj-$(CONFIG_USB_DWC3_GADGET)	+= udc-core.o
-- 
1.7.9.5

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

* [U-Boot] [u-boot 34/40] usb: gadget: defer setting maxpacket till ->setup()
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (32 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 33/40] usb: dwc3: Makefile: Make dwc3 driver compile in u-boot Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:44   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 35/40] common: cmd_dfu: invoke board_usb_cleanup() for cleaning up Kishon Vijay Abraham I
                   ` (6 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Taken from linux kernel with commit
commit 765f5b830e547229bb752e7b232ee83e2b3d49d5
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date:   Thu Jun 23 14:26:11 2011 +0200

usb: gadget: defer setting maxpacket till ->setup()

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 drivers/usb/gadget/composite.c |    4 +++-
 drivers/usb/gadget/ether.c     |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index a4c5606..5cedc9e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -283,7 +283,7 @@ static void device_qual(struct usb_composite_dev *cdev)
 	qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
 	qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
 	/* ASSUME same EP0 fifo size at both speeds */
-	qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0;
+	qual->bMaxPacketSize0 = cdev->gadget->ep0->maxpacket;
 	qual->bNumConfigurations = count_configs(cdev, USB_DT_DEVICE_QUALIFIER);
 	qual->bRESERVED = 0;
 }
@@ -736,6 +736,8 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 		case USB_DT_DEVICE:
 			cdev->desc.bNumConfigurations =
 				count_configs(cdev, USB_DT_DEVICE);
+			cdev->desc.bMaxPacketSize0 =
+				cdev->gadget->ep0->maxpacket;
 			value = min(w_length, (u16) sizeof cdev->desc);
 			memcpy(req->buf, &cdev->desc, value);
 			break;
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index ba442d5..8ccf9b0 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1249,6 +1249,7 @@ eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 		switch (wValue >> 8) {
 
 		case USB_DT_DEVICE:
+			device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 			value = min(wLength, (u16) sizeof device_desc);
 			memcpy(req->buf, &device_desc, value);
 			break;
@@ -2133,7 +2134,6 @@ autoconf_fail:
 		hs_subset_descriptors();
 	}
 
-	device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 	usb_gadget_set_selfpowered(gadget);
 
 	/* For now RNDIS is always a second config */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 35/40] common: cmd_dfu: invoke board_usb_cleanup() for cleaning up
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (33 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 34/40] usb: gadget: defer setting maxpacket till ->setup() Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:47   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 36/40] board: ti: DRA7: added USB initializtion code Kishon Vijay Abraham I
                   ` (5 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Invoked board_usb_cleanup for cleaning up initialized USB. It
will be invoked if the user enterts ctrl-C.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 common/cmd_dfu.c |    1 +
 common/usb.c     |    7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
index e975abe..161d38b 100644
--- a/common/cmd_dfu.c
+++ b/common/cmd_dfu.c
@@ -68,6 +68,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 exit:
 	g_dnl_unregister();
+	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
 done:
 	dfu_free_entities();
 
diff --git a/common/usb.c b/common/usb.c
index 736cd9f..c7cc1b1 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -1063,4 +1063,11 @@ int board_usb_init(int index, enum usb_init_type init)
 {
 	return 0;
 }
+
+
+__weak
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+	return 0;
+}
 /* EOF */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 36/40] board: ti: DRA7: added USB initializtion code
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (34 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 35/40] common: cmd_dfu: invoke board_usb_cleanup() for cleaning up Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:49   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 37/40] include: configs: Enable DWC3 and DFU in DRA7xx Kishon Vijay Abraham I
                   ` (4 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Implemented board_usb_init(), board_usb_cleanup() and
usb_gadget_handle_interrupts() in dra7xx board file that
can be invoked by various gadget drivers.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/include/asm/arch-omap5/omap.h |   12 ++++
 board/ti/dra7xx/evm.c                  |  109 ++++++++++++++++++++++++++++++++
 2 files changed, 121 insertions(+)

diff --git a/arch/arm/include/asm/arch-omap5/omap.h b/arch/arm/include/asm/arch-omap5/omap.h
index e218159..e844bfb 100644
--- a/arch/arm/include/asm/arch-omap5/omap.h
+++ b/arch/arm/include/asm/arch-omap5/omap.h
@@ -33,6 +33,18 @@
 #define CONTROL_ID_CODE		CONTROL_CORE_ID_CODE
 #endif
 
+#ifdef CONFIG_DRA7XX
+#define DRA7_USB_OTG_SS1_BASE		0x48890000
+#define DRA7_USB_OTG_SS1_GLUE_BASE	0x48880000
+#define DRA7_USB3_PHY1_PLL_CTRL		0x4A084C00
+#define DRA7_USB3_PHY1_POWER		0x4A002370
+#define DRA7_USB2_PHY1_POWER		0x4A002300
+
+#define DRA7_USB_OTG_SS2_BASE		0x488D0000
+#define DRA7_USB_OTG_SS2_GLUE_BASE	0x488C0000
+#define DRA7_USB2_PHY2_POWER		0x4A002E74
+#endif
+
 /* To be verified */
 #define OMAP5430_CONTROL_ID_CODE_ES1_0		0x0B94202F
 #define OMAP5430_CONTROL_ID_CODE_ES2_0          0x1B94202F
diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
index 6522241..284775c 100644
--- a/board/ti/dra7xx/evm.c
+++ b/board/ti/dra7xx/evm.c
@@ -14,11 +14,16 @@
 #include <palmas.h>
 #include <sata.h>
 #include <asm/gpio.h>
+#include <usb.h>
+#include <linux/usb/gadget.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/mmc_host_def.h>
 #include <asm/arch/sata.h>
 #include <environment.h>
+#include <dwc3-uboot.h>
+#include <dwc3-omap-uboot.h>
+#include <ti-usb-phy-uboot.h>
 
 #include "mux_data.h"
 
@@ -123,6 +128,110 @@ int board_mmc_init(bd_t *bis)
 }
 #endif
 
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device usb_otg_ss1 = {
+	.maximum_speed = USB_SPEED_SUPER,
+	.base = DRA7_USB_OTG_SS1_BASE,
+	.tx_fifo_resize = false,
+	.index = 0,
+};
+
+static struct dwc3_omap_device usb_otg_ss1_glue = {
+	.base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
+	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
+	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
+	.index = 0,
+};
+
+static struct ti_usb_phy_device usb_phy1_device = {
+	.pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
+	.usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
+	.usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
+	.index = 0,
+};
+
+static struct dwc3_device usb_otg_ss2 = {
+	.maximum_speed = USB_SPEED_SUPER,
+	.base = DRA7_USB_OTG_SS2_BASE,
+	.tx_fifo_resize = false,
+	.index = 1,
+};
+
+static struct dwc3_omap_device usb_otg_ss2_glue = {
+	.base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
+	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
+	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
+	.index = 1,
+};
+
+static struct ti_usb_phy_device usb_phy2_device = {
+	.usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
+	.index = 1,
+};
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	switch (index) {
+	case 0:
+		if (init == USB_INIT_DEVICE) {
+			usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
+			usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
+		} else {
+			usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
+			usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
+		}
+
+		ti_usb_phy_uboot_init(&usb_phy1_device);
+		dwc3_omap_uboot_init(&usb_otg_ss1_glue);
+		dwc3_uboot_init(&usb_otg_ss1);
+		break;
+	case 1:
+		if (init == USB_INIT_DEVICE) {
+			usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
+			usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
+		} else {
+			usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
+			usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
+		}
+
+		ti_usb_phy_uboot_init(&usb_phy2_device);
+		dwc3_omap_uboot_init(&usb_otg_ss2_glue);
+		dwc3_uboot_init(&usb_otg_ss2);
+		break;
+	default:
+		printf("Invalid Controller Index\n");
+	}
+
+	return 0;
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+	switch (index) {
+	case 0:
+	case 1:
+		ti_usb_phy_uboot_exit(index);
+		dwc3_uboot_exit(index);
+		dwc3_omap_uboot_exit(index);
+		break;
+	default:
+		printf("Invalid Controller Index\n");
+	}
+	return 0;
+}
+
+int usb_gadget_handle_interrupts(void)
+{
+	u32 status;
+
+	status = dwc3_omap_uboot_interrupt_status(0);
+	if (status)
+		dwc3_uboot_handle_interrupt(0);
+
+	return 0;
+}
+#endif
+
 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
 int spl_start_uboot(void)
 {
-- 
1.7.9.5

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

* [U-Boot] [u-boot 37/40] include: configs: Enable DWC3 and DFU in DRA7xx
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (35 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 36/40] board: ti: DRA7: added USB initializtion code Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:50   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 38/40] board: ti: AM43xx: added USB initializtion code Kishon Vijay Abraham I
                   ` (3 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Enabled dwc3, dwc3-omap and PHY for dwc3 are enabled. Also enabled
support for DFU.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 include/configs/dra7xx_evm.h      |   63 +++++++++++++++++++++++++++++++++++++
 include/configs/ti_omap5_common.h |    5 +++
 2 files changed, 68 insertions(+)

diff --git a/include/configs/dra7xx_evm.h b/include/configs/dra7xx_evm.h
index 174a711..75b55d9 100644
--- a/include/configs/dra7xx_evm.h
+++ b/include/configs/dra7xx_evm.h
@@ -43,6 +43,47 @@
 	"uuid_disk=${uuid_gpt_disk};" \
 	"name=rootfs,start=2MiB,size=-,uuid=${uuid_gpt_rootfs}"
 
+#define DFU_ALT_INFO_MMC \
+	"dfu_alt_info_mmc=" \
+	"boot part 0 1;" \
+	"rootfs part 0 2;" \
+	"MLO fat 0 1;" \
+	"MLO.raw raw 0x100 0x100;" \
+	"u-boot.img.raw raw 0x300 0x400;" \
+	"spl-os-args.raw raw 0x80 0x80;" \
+	"spl-os-image.raw raw 0x900 0x2000;" \
+	"spl-os-args fat 0 1;" \
+	"spl-os-image fat 0 1;" \
+	"u-boot.img fat 0 1;" \
+	"uEnv.txt fat 0 1\0"
+
+#define DFU_ALT_INFO_EMMC \
+	"dfu_alt_info_emmc=" \
+	"rawemmc raw 0 3751936;" \
+	"boot part 1 1;" \
+	"rootfs part 1 2;" \
+	"MLO fat 1 1;" \
+	"MLO.raw raw 0x100 0x100;" \
+	"u-boot.img.raw raw 0x300 0x400;" \
+	"spl-os-args.raw raw 0x80 0x80;" \
+	"spl-os-image.raw raw 0x900 0x2000;" \
+	"spl-os-args fat 1 1;" \
+	"spl-os-image fat 1 1;" \
+	"u-boot.img fat 1 1;" \
+	"uEnv.txt fat 1 1\0"
+
+#define DFU_ALT_INFO_RAM \
+	"dfu_alt_info_ram=" \
+	"kernel ram 0x80200000 0x4000000;" \
+	"fdt ram 0x80f80000 0x80000;" \
+	"ramdisk ram 0x81000000 0x4000000\0"
+
+#define DFUARGS \
+	"dfu_bufsiz=0x10000\0" \
+	DFU_ALT_INFO_MMC \
+	DFU_ALT_INFO_EMMC \
+	DFU_ALT_INFO_RAM
+
 #include <configs/ti_omap5_common.h>
 
 /* Enhance our eMMC support / experience. */
@@ -132,6 +173,28 @@
 #define CONFIG_OMAP_USB_PHY
 #define CONFIG_OMAP_USB2PHY2_HOST
 
+/* USB GADGET */
+#define CONFIG_USB_DWC3_PHY_OMAP
+#define CONFIG_USB_DWC3_OMAP
+#define CONFIG_USB_DWC3
+#define CONFIG_USB_DWC3_GADGET
+
+#define CONFIG_USB_GADGET
+#define CONFIG_USBDOWNLOAD_GADGET
+#define CONFIG_USB_GADGET_VBUS_DRAW 2
+#define CONFIG_G_DNL_MANUFACTURER "Texas Instruments"
+#define CONFIG_G_DNL_VENDOR_NUM 0x0403
+#define CONFIG_G_DNL_PRODUCT_NUM 0xBD00
+#define CONFIG_USB_GADGET_DUALSPEED
+
+/* USB Device Firmware Update support */
+#define CONFIG_DFU_FUNCTION
+#define CONFIG_DFU_RAM
+#define CONFIG_CMD_DFU
+
+#define CONFIG_DFU_MMC
+#define CONFIG_DFU_RAM
+
 /* SATA */
 #define CONFIG_BOARD_LATE_INIT
 #define CONFIG_CMD_SCSI
diff --git a/include/configs/ti_omap5_common.h b/include/configs/ti_omap5_common.h
index c47651d..cdc539c 100644
--- a/include/configs/ti_omap5_common.h
+++ b/include/configs/ti_omap5_common.h
@@ -65,6 +65,10 @@
 #define PARTS_DEFAULT
 #endif
 
+#ifndef DFUARGS
+#define DFUARGS
+#endif
+
 #define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	DEFAULT_LINUX_BOOT_ENV \
@@ -122,6 +126,7 @@
 		"if test $fdtfile = undefined; then " \
 			"echo WARNING: Could not determine device tree to use; fi; \0" \
 	"loadfdt=load mmc ${bootpart} ${fdtaddr} ${bootdir}/${fdtfile};\0" \
+	DFUARGS \
 
 #define CONFIG_BOOTCOMMAND \
 	"run findfdt; " \
-- 
1.7.9.5

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

* [U-Boot] [u-boot 38/40] board: ti: AM43xx: added USB initializtion code
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (36 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 37/40] include: configs: Enable DWC3 and DFU in DRA7xx Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:50   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 39/40] include: configs: Enable DWC3 and DFU in AM43xx Kishon Vijay Abraham I
                   ` (2 subsequent siblings)
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Implemented board_usb_init(), board_usb_cleanup() and
usb_gadget_handle_interrupts() in am43xx board file that
can be invoked by various gadget drivers.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 arch/arm/include/asm/arch-am33xx/hardware_am43xx.h |    9 ++
 board/ti/am43xx/board.c                            |  108 ++++++++++++++++++++
 2 files changed, 117 insertions(+)

diff --git a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
index 5f259da..110f329 100644
--- a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
+++ b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
@@ -61,6 +61,15 @@
 /* RTC base address */
 #define RTC_BASE			0x44E3E000
 
+/* USB OTG */
+#define USB_OTG_SS1_BASE		0x48390000
+#define USB_OTG_SS1_GLUE_BASE		0x48380000
+#define USB2_PHY1_POWER			0x44E10620
+
+#define USB_OTG_SS2_BASE		0x483D0000
+#define USB_OTG_SS2_GLUE_BASE		0x483C0000
+#define USB2_PHY2_POWER			0x44E10628
+
 /* USB Clock Control */
 #define PRM_PER_USB_OTG_SS0_CLKCTRL (CM_PER + 0x260)
 #define PRM_PER_USB_OTG_SS1_CLKCTRL (CM_PER + 0x268)
diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
index a1c3c17..a8796b1 100644
--- a/board/ti/am43xx/board.c
+++ b/board/ti/am43xx/board.c
@@ -12,6 +12,7 @@
 #include <i2c.h>
 #include <asm/errno.h>
 #include <spl.h>
+#include <usb.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/mux.h>
@@ -23,6 +24,10 @@
 #include <power/tps65218.h>
 #include <miiphy.h>
 #include <cpsw.h>
+#include <linux/usb/gadget.h>
+#include <dwc3-uboot.h>
+#include <dwc3-omap-uboot.h>
+#include <ti-usb-phy-uboot.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -686,6 +691,109 @@ int board_late_init(void)
 }
 #endif
 
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device usb_otg_ss1 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = USB_OTG_SS1_BASE,
+	.tx_fifo_resize = false,
+	.index = 0,
+};
+
+static struct dwc3_omap_device usb_otg_ss1_glue = {
+	.base = (void *)USB_OTG_SS1_GLUE_BASE,
+	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
+	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
+	.index = 0,
+};
+
+static struct ti_usb_phy_device usb_phy1_device = {
+	.usb2_phy_power = (void *)USB2_PHY1_POWER,
+	.index = 0,
+};
+
+static struct dwc3_device usb_otg_ss2 = {
+	.maximum_speed = USB_SPEED_HIGH,
+	.base = USB_OTG_SS2_BASE,
+	.tx_fifo_resize = false,
+	.index = 1,
+};
+
+static struct dwc3_omap_device usb_otg_ss2_glue = {
+	.base = (void *)USB_OTG_SS2_GLUE_BASE,
+	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
+	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
+	.index = 1,
+};
+
+static struct ti_usb_phy_device usb_phy2_device = {
+	.usb2_phy_power = (void *)USB2_PHY2_POWER,
+	.index = 1,
+};
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+	switch (index) {
+	case 0:
+		if (init == USB_INIT_DEVICE) {
+			usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
+			usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
+		} else {
+			usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
+			usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
+		}
+
+		dwc3_omap_uboot_init(&usb_otg_ss1_glue);
+		ti_usb_phy_uboot_init(&usb_phy1_device);
+		dwc3_uboot_init(&usb_otg_ss1);
+		break;
+	case 1:
+		if (init == USB_INIT_DEVICE) {
+			usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
+			usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
+		} else {
+			usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
+			usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
+		}
+
+		ti_usb_phy_uboot_init(&usb_phy2_device);
+		dwc3_omap_uboot_init(&usb_otg_ss2_glue);
+		dwc3_uboot_init(&usb_otg_ss2);
+		break;
+	default:
+		printf("Invalid Controller Index\n");
+	}
+
+	return 0;
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+	switch (index) {
+	case 0:
+	case 1:
+		ti_usb_phy_uboot_exit(index);
+		dwc3_uboot_exit(index);
+		dwc3_omap_uboot_exit(index);
+		break;
+	default:
+		printf("Invalid Controller Index\n");
+	}
+
+	return 0;
+}
+
+int usb_gadget_handle_interrupts(void)
+{
+	u32 status;
+
+	status = dwc3_omap_uboot_interrupt_status(0);
+	if (status)
+		dwc3_uboot_handle_interrupt(0);
+
+	return 0;
+}
+#endif
+
 #ifdef CONFIG_DRIVER_TI_CPSW
 
 static void cpsw_control(int enabled)
-- 
1.7.9.5

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

* [U-Boot] [u-boot 39/40] include: configs: Enable DWC3 and DFU in AM43xx
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (37 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 38/40] board: ti: AM43xx: added USB initializtion code Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:53   ` Lukasz Majewski
  2015-02-06  8:48 ` [U-Boot] [u-boot 40/40] usb: modify usb_gadget_handle_interrupts to take controller index Kishon Vijay Abraham I
  2015-02-07 13:32 ` [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Marek Vasut
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Enabled dwc3, dwc3-omap and PHY for dwc3 are enabled. Also enabled
support for DFU.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 include/configs/am43xx_evm.h |   61 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/include/configs/am43xx_evm.h b/include/configs/am43xx_evm.h
index 4472c3e..3fcd99e 100644
--- a/include/configs/am43xx_evm.h
+++ b/include/configs/am43xx_evm.h
@@ -108,6 +108,64 @@
 #define CONFIG_OMAP_USB_PHY
 #define CONFIG_AM437X_USB2PHY2_HOST
 
+/* USB GADGET */
+#if !defined(CONFIG_SPL_BUILD) || \
+	(defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_USBETH_SUPPORT))
+#define CONFIG_USB_DWC3_PHY_OMAP
+#define CONFIG_USB_DWC3_OMAP
+#define CONFIG_USB_DWC3
+#define CONFIG_USB_DWC3_GADGET
+
+#define CONFIG_USB_GADGET
+#define CONFIG_USB_ETHER
+#define CONFIG_USB_ETH_RNDIS
+#define CONFIG_USBNET_HOST_ADDR	"de:ad:be:af:00:00"
+#define CONFIG_USBDOWNLOAD_GADGET
+#define CONFIG_USB_GADGET_VBUS_DRAW 2
+#define CONFIG_G_DNL_MANUFACTURER "Texas Instruments"
+#define CONFIG_G_DNL_VENDOR_NUM 0x0403
+#define CONFIG_G_DNL_PRODUCT_NUM 0xBD00
+#define CONFIG_USB_GADGET_DUALSPEED
+#endif
+
+#ifndef CONFIG_SPL_BUILD
+/* USB Device Firmware Update support */
+#define CONFIG_DFU_FUNCTION
+#define CONFIG_DFU_RAM
+#define CONFIG_CMD_DFU
+
+#define CONFIG_DFU_MMC
+#define DFU_ALT_INFO_MMC \
+	"dfu_alt_info_mmc=" \
+	"boot part 0 1;" \
+	"rootfs part 0 2;" \
+	"MLO fat 0 1;" \
+	"spl-os-args fat 0 1;" \
+	"spl-os-image fat 0 1;" \
+	"u-boot.img fat 0 1;" \
+	"uEnv.txt fat 0 1\0"
+
+#define DFU_ALT_INFO_EMMC \
+	"dfu_alt_info_emmc=" \
+	"MLO raw 0x100 0x100 mmcpart 0;" \
+	"u-boot.img raw 0x300 0x1000 mmcpart 0\0"
+
+#define CONFIG_DFU_RAM
+#define DFU_ALT_INFO_RAM \
+	"dfu_alt_info_ram=" \
+	"kernel ram 0x80200000 0x4000000;" \
+	"fdt ram 0x80f80000 0x80000;" \
+	"ramdisk ram 0x81000000 0x4000000\0"
+
+#define DFUARGS \
+	"dfu_bufsiz=0x10000\0" \
+	DFU_ALT_INFO_MMC \
+	DFU_ALT_INFO_EMMC \
+	DFU_ALT_INFO_RAM
+#else
+#define DFUARGS
+#endif
+
 #ifdef CONFIG_QSPI_BOOT
 #define CONFIG_SYS_TEXT_BASE           0x30000000
 #undef CONFIG_ENV_IS_IN_FAT
@@ -238,7 +296,8 @@
 		"if test $board_name = AM43__SK; then " \
 			"setenv fdtfile am437x-sk-evm.dtb; fi; " \
 		"if test $fdtfile = undefined; then " \
-			"echo WARNING: Could not determine device tree; fi; \0"
+			"echo WARNING: Could not determine device tree; fi; \0" \
+	DFUARGS \
 
 #define CONFIG_BOOTCOMMAND \
 	"run findfdt; " \
-- 
1.7.9.5

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

* [U-Boot] [u-boot 40/40] usb: modify usb_gadget_handle_interrupts to take controller index
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (38 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 39/40] include: configs: Enable DWC3 and DFU in AM43xx Kishon Vijay Abraham I
@ 2015-02-06  8:48 ` Kishon Vijay Abraham I
  2015-02-16 11:56   ` Lukasz Majewski
  2015-02-07 13:32 ` [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Marek Vasut
  40 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-06  8:48 UTC (permalink / raw)
  To: u-boot

Since we support multiple dwc3 controllers to be existent at the same
time, in order to handle the interrupts of a particular dwc3 controller
usb_gadget_handle_interrutps should take controller index as an
argument.

Hence the API of usb_gadget_handle_interrupts is modified to take
controller index as an argument and made the corresponding changes to all
the usb_gadget_handle_interrupts calls.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
 board/ti/am43xx/board.c             |    6 +++---
 board/ti/dra7xx/evm.c               |    6 +++---
 common/cmd_dfu.c                    |    2 +-
 common/cmd_fastboot.c               |    2 +-
 common/cmd_usb_mass_storage.c       |    2 +-
 drivers/usb/gadget/atmel_usba_udc.c |    2 +-
 drivers/usb/gadget/ci_udc.c         |    2 +-
 drivers/usb/gadget/ether.c          |   10 +++++-----
 drivers/usb/gadget/f_mass_storage.c |    2 +-
 drivers/usb/gadget/f_thor.c         |    6 +++---
 drivers/usb/gadget/fotg210.c        |    2 +-
 drivers/usb/gadget/pxa25x_udc.c     |    2 +-
 drivers/usb/gadget/s3c_udc_otg.c    |    2 +-
 drivers/usb/musb-new/musb_uboot.c   |    2 +-
 include/linux/usb/gadget.h          |    2 +-
 15 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
index a8796b1..096e5db 100644
--- a/board/ti/am43xx/board.c
+++ b/board/ti/am43xx/board.c
@@ -782,13 +782,13 @@ int board_usb_cleanup(int index, enum usb_init_type init)
 	return 0;
 }
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	u32 status;
 
-	status = dwc3_omap_uboot_interrupt_status(0);
+	status = dwc3_omap_uboot_interrupt_status(index);
 	if (status)
-		dwc3_uboot_handle_interrupt(0);
+		dwc3_uboot_handle_interrupt(index);
 
 	return 0;
 }
diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
index 284775c..3089fa2 100644
--- a/board/ti/dra7xx/evm.c
+++ b/board/ti/dra7xx/evm.c
@@ -220,13 +220,13 @@ int board_usb_cleanup(int index, enum usb_init_type init)
 	return 0;
 }
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	u32 status;
 
-	status = dwc3_omap_uboot_interrupt_status(0);
+	status = dwc3_omap_uboot_interrupt_status(index);
 	if (status)
-		dwc3_uboot_handle_interrupt(0);
+		dwc3_uboot_handle_interrupt(index);
 
 	return 0;
 }
diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
index 161d38b..ec90998 100644
--- a/common/cmd_dfu.c
+++ b/common/cmd_dfu.c
@@ -64,7 +64,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		if (ctrlc())
 			goto exit;
 
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(controller_index);
 	}
 exit:
 	g_dnl_unregister();
diff --git a/common/cmd_fastboot.c b/common/cmd_fastboot.c
index b72f4f3..8281f8e 100644
--- a/common/cmd_fastboot.c
+++ b/common/cmd_fastboot.c
@@ -25,7 +25,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 			break;
 		if (ctrlc())
 			break;
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(0);
 	}
 
 	g_dnl_unregister();
diff --git a/common/cmd_usb_mass_storage.c b/common/cmd_usb_mass_storage.c
index 2c879ea..c5f909d 100644
--- a/common/cmd_usb_mass_storage.c
+++ b/common/cmd_usb_mass_storage.c
@@ -137,7 +137,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
 	}
 
 	while (1) {
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(controller_index);
 
 		rc = fsg_main_thread(NULL);
 		if (rc) {
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index fbc74f3..1e23d09 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1199,7 +1199,7 @@ static struct usba_udc controller = {
 	},
 };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	struct usba_udc *udc = &controller;
 
diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index b0ef35e..a7dc0b2 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -741,7 +741,7 @@ void udc_irq(void)
 	}
 }
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	u32 value;
 	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 8ccf9b0..ba79faf 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1908,7 +1908,7 @@ static int eth_stop(struct eth_dev *dev)
 		/* Wait until host receives OID_GEN_MEDIA_CONNECT_STATUS */
 		ts = get_timer(0);
 		while (get_timer(ts) < timeout)
-			usb_gadget_handle_interrupts();
+			usb_gadget_handle_interrupts(0);
 #endif
 
 		rndis_uninit(dev->rndis_config);
@@ -2359,7 +2359,7 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd)
 			error("The remote end did not respond in time.");
 			goto fail;
 		}
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(0);
 	}
 
 	packet_received = 0;
@@ -2427,7 +2427,7 @@ static int usb_eth_send(struct eth_device *netdev, void *packet, int length)
 			printf("timeout sending packets to usb ethernet\n");
 			return -1;
 		}
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(0);
 	}
 	if (rndis_pkt)
 		free(rndis_pkt);
@@ -2442,7 +2442,7 @@ static int usb_eth_recv(struct eth_device *netdev)
 {
 	struct eth_dev *dev = &l_ethdev;
 
-	usb_gadget_handle_interrupts();
+	usb_gadget_handle_interrupts(0);
 
 	if (packet_received) {
 		debug("%s: packet received\n", __func__);
@@ -2487,7 +2487,7 @@ void usb_eth_halt(struct eth_device *netdev)
 
 	/* Clear pending interrupt */
 	if (dev->network_started) {
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(0);
 		dev->network_started = 0;
 	}
 
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index e045957..4fab35e 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -689,7 +689,7 @@ static int sleep_thread(struct fsg_common *common)
 			k = 0;
 		}
 
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(0);
 	}
 	common->thread_wakeup_needed = 0;
 	return rc;
diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c
index 2d0410d..1fd41ff 100644
--- a/drivers/usb/gadget/f_thor.c
+++ b/drivers/usb/gadget/f_thor.c
@@ -543,7 +543,7 @@ static int thor_rx_data(void)
 		}
 
 		while (!dev->rxdata) {
-			usb_gadget_handle_interrupts();
+			usb_gadget_handle_interrupts(0);
 			if (ctrlc())
 				return -1;
 		}
@@ -577,7 +577,7 @@ static void thor_tx_data(unsigned char *data, int len)
 
 	/* Wait until tx interrupt received */
 	while (!dev->txdata)
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(0);
 
 	dev->txdata = 0;
 }
@@ -694,7 +694,7 @@ int thor_init(void)
 	/* Wait for a device enumeration and configuration settings */
 	debug("THOR enumeration/configuration setting....\n");
 	while (!dev->configuration_done)
-		usb_gadget_handle_interrupts();
+		usb_gadget_handle_interrupts(0);
 
 	thor_set_dma(thor_rx_data_buf, strlen("THOR"));
 	/* detect the download request from Host PC */
diff --git a/drivers/usb/gadget/fotg210.c b/drivers/usb/gadget/fotg210.c
index 3acf6a1..1d8f58f 100644
--- a/drivers/usb/gadget/fotg210.c
+++ b/drivers/usb/gadget/fotg210.c
@@ -832,7 +832,7 @@ static struct fotg210_chip controller = {
 	},
 };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	struct fotg210_chip *chip = &controller;
 	struct fotg210_regs *regs = chip->regs;
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index 8945c5b..1910227 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -2041,7 +2041,7 @@ extern void udc_disconnect(void)
 /*-------------------------------------------------------------------------*/
 
 extern int
-usb_gadget_handle_interrupts(void)
+usb_gadget_handle_interrupts(int index)
 {
 	return pxa25x_udc_irq();
 }
diff --git a/drivers/usb/gadget/s3c_udc_otg.c b/drivers/usb/gadget/s3c_udc_otg.c
index 7653f03..7a2d1e7 100644
--- a/drivers/usb/gadget/s3c_udc_otg.c
+++ b/drivers/usb/gadget/s3c_udc_otg.c
@@ -833,7 +833,7 @@ int s3c_udc_probe(struct s3c_plat_otg_data *pdata)
 	return retval;
 }
 
-int usb_gadget_handle_interrupts()
+int usb_gadget_handle_interrupts(int index)
 {
 	u32 intr_status = readl(&reg->gintsts);
 	u32 gintmsk = readl(&reg->gintmsk);
diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c
index 2676f09..79f29fb 100644
--- a/drivers/usb/musb-new/musb_uboot.c
+++ b/drivers/usb/musb-new/musb_uboot.c
@@ -162,7 +162,7 @@ int usb_lowlevel_stop(int index)
 #ifdef CONFIG_MUSB_GADGET
 static struct musb *gadget;
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
 	WATCHDOG_RESET();
 	if (!gadget || !gadget->isr)
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 93a5ffc..230f47d 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -937,6 +937,6 @@ extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
 
 extern void usb_ep_autoconfig_reset(struct usb_gadget *);
 
-extern int usb_gadget_handle_interrupts(void);
+extern int usb_gadget_handle_interrupts(int index);
 
 #endif	/* __LINUX_USB_GADGET_H */
-- 
1.7.9.5

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

* [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot
  2015-02-06  8:47 ` [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot Kishon Vijay Abraham I
@ 2015-02-07 13:27   ` Marek Vasut
  2015-02-16  9:58     ` Lukasz Majewski
  2015-02-16 10:11   ` Lukasz Majewski
  1 sibling, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-02-07 13:27 UTC (permalink / raw)
  To: u-boot

On Friday, February 06, 2015 at 09:47:40 AM, Kishon Vijay Abraham I wrote:
> Added udc-core.c from linux kernel 3.19-rc1 (97bf6af1f9) to u-boot.
> This will be adapted to work with u-boot in the
> following patches.
> Adding support for udc will help to seamlessly port dwc3 driver from
> linux kernel to u-boot (since dwc3 uses udc-core) and it'll also help
> to add support for multiple gadget controllers to be functional at the
> same time.
> All other gadget drivers can also be adapted to use udc-core.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

Lukasz, do you have any comments on this ? I'd like to pick this whole
thing via u-boot-usb for this MW if possible.

Best regards,
Marek Vasut

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

* [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu
  2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
                   ` (39 preceding siblings ...)
  2015-02-06  8:48 ` [U-Boot] [u-boot 40/40] usb: modify usb_gadget_handle_interrupts to take controller index Kishon Vijay Abraham I
@ 2015-02-07 13:32 ` Marek Vasut
  2015-02-11 11:33   ` Kishon Vijay Abraham I
  40 siblings, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-02-07 13:32 UTC (permalink / raw)
  To: u-boot

On Friday, February 06, 2015 at 09:47:37 AM, Kishon Vijay Abraham I wrote:
> This patch series ports dwc3 gadget driver from linux kernel (3.19-rc1)
> to u-boot.
> 
> Changes from RFC:
> *) A patch has been added to copy the driver from linux kernel to u-boot
> and then it's modfied to make it work in u-boot. This will help to
> understand the changes that's been done to make it work in u-boot and will
> also be easier to review. *) Implemented chained TRB support in dwc3 ep0
> so that we need not increase the size of bounce buffer
> 
> Testing:
> *) tested DFU RAM and DFU MMC in dra7xx and am43xx
> 
> TODO:
> *) Add Kconfig support
> *) Adapt dwc3 driver to use the driver model.
> *) Make composite driver similar to the one in linux kernel.
> 
> Pushed these patches to
> git://git.ti.com/~kishon/ti-u-boot/kishons-ti-u-boot.git dwc3_upstream_v1

Hi!

I'm fine with this series, maybe just replace "folder" with "directory" in
the commit messages ;-) But I can do that myself if you don't mind, no need
to repost.

I'd like to hear what Lukasz thinks and then I'll likely just pick it up for
this MW.

Thanks!

Best regards,
Marek Vasut

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

* [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu
  2015-02-07 13:32 ` [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Marek Vasut
@ 2015-02-11 11:33   ` Kishon Vijay Abraham I
  0 siblings, 0 replies; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-11 11:33 UTC (permalink / raw)
  To: u-boot

Hi,

On Saturday 07 February 2015 07:02 PM, Marek Vasut wrote:
> On Friday, February 06, 2015 at 09:47:37 AM, Kishon Vijay Abraham I wrote:
>> This patch series ports dwc3 gadget driver from linux kernel (3.19-rc1)
>> to u-boot.
>>
>> Changes from RFC:
>> *) A patch has been added to copy the driver from linux kernel to u-boot
>> and then it's modfied to make it work in u-boot. This will help to
>> understand the changes that's been done to make it work in u-boot and will
>> also be easier to review. *) Implemented chained TRB support in dwc3 ep0
>> so that we need not increase the size of bounce buffer
>>
>> Testing:
>> *) tested DFU RAM and DFU MMC in dra7xx and am43xx
>>
>> TODO:
>> *) Add Kconfig support
>> *) Adapt dwc3 driver to use the driver model.
>> *) Make composite driver similar to the one in linux kernel.
>>
>> Pushed these patches to
>> git://git.ti.com/~kishon/ti-u-boot/kishons-ti-u-boot.git dwc3_upstream_v1
>
> Hi!
>
> I'm fine with this series, maybe just replace "folder" with "directory" in
> the commit messages ;-) But I can do that myself if you don't mind, no need
> to repost.

I don't mind :-) Thanks for doing that :-)

Cheers
Kishon

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

* [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot
  2015-02-07 13:27   ` Marek Vasut
@ 2015-02-16  9:58     ` Lukasz Majewski
  2015-02-16 13:29       ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16  9:58 UTC (permalink / raw)
  To: u-boot

Hi Marek,

> On Friday, February 06, 2015 at 09:47:40 AM, Kishon Vijay Abraham I
> wrote:
> > Added udc-core.c from linux kernel 3.19-rc1 (97bf6af1f9) to u-boot.
> > This will be adapted to work with u-boot in the
> > following patches.
> > Adding support for udc will help to seamlessly port dwc3 driver from
> > linux kernel to u-boot (since dwc3 uses udc-core) and it'll also
> > help to add support for multiple gadget controllers to be
> > functional at the same time.
> > All other gadget drivers can also be adapted to use udc-core.
> > 
> > Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> 
> Lukasz, do you have any comments on this ? I'd like to pick this whole
> thing via u-boot-usb for this MW if possible.

I wasn't in the office for the last week. I will review this code ASAP.

> 
> Best regards,
> Marek Vasut


-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 01/40] ARM: DRA7: Enable clocks for USB OTGSS and USB PHY
  2015-02-06  8:47 ` [U-Boot] [u-boot 01/40] ARM: DRA7: Enable clocks for USB OTGSS and USB PHY Kishon Vijay Abraham I
@ 2015-02-16 10:04   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:04 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Enabled clocks for dwc3 controller and USB PHY present in DRA7.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/cpu/armv7/omap5/hw_data.c   |   14 ++++++++++++++
>  arch/arm/cpu/armv7/omap5/prcm-regs.c |   10 +++++-----
>  arch/arm/include/asm/omap_common.h   |    4 ++--
>  3 files changed, 21 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/arm/cpu/armv7/omap5/hw_data.c
> b/arch/arm/cpu/armv7/omap5/hw_data.c index 95f1686..9315bce 100644
> --- a/arch/arm/cpu/armv7/omap5/hw_data.c
> +++ b/arch/arm/cpu/armv7/omap5/hw_data.c
> @@ -455,6 +455,10 @@ void enable_basic_clocks(void)
>  		(*prcm)->cm_l4per_gpio6_clkctrl,
>  		(*prcm)->cm_l4per_gpio7_clkctrl,
>  		(*prcm)->cm_l4per_gpio8_clkctrl,
> +#ifdef CONFIG_USB_DWC3
> +		(*prcm)->cm_l3init_ocp2scp1_clkctrl,
> +		(*prcm)->cm_l3init_usb_otg_ss1_clkctrl,
> +#endif
>  		0
>  	};
>  
> @@ -486,6 +490,16 @@ void enable_basic_clocks(void)
>  	setbits_le32((*prcm)->cm_l3init_hsmmc2_clkctrl,
>  			HSMMC_CLKCTRL_CLKSEL_MASK);
>  
> +#ifdef CONFIG_USB_DWC3
> +	/* Enable 960 MHz clock for dwc3 */
> +	setbits_le32((*prcm)->cm_l3init_usb_otg_ss1_clkctrl,
> +		     OPTFCLKEN_REFCLK960M);
> +
> +	/* Enable 32 KHz clock for dwc3 */
> +	setbits_le32((*prcm)->cm_coreaon_usb_phy1_core_clkctrl,
> +		     USBPHY_CORE_CLKCTRL_OPTFCLKEN_CLK32K);
> +#endif
> +
>  	/* Set the correct clock dividers for mmc */
>  	setbits_le32((*prcm)->cm_l3init_hsmmc1_clkctrl,
>  			HSMMC_CLKCTRL_CLKSEL_DIV_MASK);
> diff --git a/arch/arm/cpu/armv7/omap5/prcm-regs.c
> b/arch/arm/cpu/armv7/omap5/prcm-regs.c index 0745d42..440bb40 100644
> --- a/arch/arm/cpu/armv7/omap5/prcm-regs.c
> +++ b/arch/arm/cpu/armv7/omap5/prcm-regs.c
> @@ -575,7 +575,7 @@ struct prcm_regs const omap5_es2_prcm = {
>  	.cm_div_m2_dpll_unipro = 0x4a0081d0,
>  	.cm_ssc_deltamstep_dpll_unipro = 0x4a0081e8,
>  	.cm_ssc_modfreqdiv_dpll_unipro = 0x4a0081ec,
> -	.cm_coreaon_usb_phy_core_clkctrl = 0x4A008640,
> +	.cm_coreaon_usb_phy1_core_clkctrl = 0x4A008640,
>  	.cm_coreaon_bandgap_clkctrl = 0x4a008648,
>  	.cm_coreaon_io_srcomp_clkctrl = 0x4a008650,
>  
> @@ -709,7 +709,7 @@ struct prcm_regs const omap5_es2_prcm = {
>  	.cm_l3init_fsusb_clkctrl = 0x4a0096d0,
>  	.cm_l3init_ocp2scp1_clkctrl = 0x4a0096e0,
>  	.cm_l3init_ocp2scp3_clkctrl = 0x4a0096e8,
> -	.cm_l3init_usb_otg_ss_clkctrl = 0x4a0096f0,
> +	.cm_l3init_usb_otg_ss1_clkctrl = 0x4a0096f0,
>  
>  	/* prm irqstatus regs */
>  	.prm_irqstatus_mpu_2 = 0x4ae06014,
> @@ -801,8 +801,8 @@ struct prcm_regs const dra7xx_prcm = {
>  	.cm_clkmode_dpll_dsp			= 0x4a005234,
>  	.cm_shadow_freq_config1			= 0x4a005260,
>  	.cm_clkmode_dpll_gmac			= 0x4a0052a8,
> -	.cm_coreaon_usb_phy_core_clkctrl	= 0x4a008640,
> -	.cm_coreaon_usb_phy2_core_clkctrl = 0x4a008688,
> +	.cm_coreaon_usb_phy1_core_clkctrl	= 0x4a008640,
> +	.cm_coreaon_usb_phy2_core_clkctrl	= 0x4a008688,
>  
>  	/* cm1.mpu */
>  	.cm_mpu_mpu_clkctrl			= 0x4a005320,
> @@ -908,7 +908,7 @@ struct prcm_regs const dra7xx_prcm = {
>  	.cm_gmac_gmac_clkctrl			= 0x4a0093d0,
>  	.cm_l3init_ocp2scp1_clkctrl		= 0x4a0093e0,
>  	.cm_l3init_ocp2scp3_clkctrl		= 0x4a0093e8,
> -	.cm_l3init_usb_otg_ss_clkctrl		= 0x4a0093f0,
> +	.cm_l3init_usb_otg_ss1_clkctrl		= 0x4a0093f0,
>  
>  	/* cm2.l4per */
>  	.cm_l4per_clkstctrl			= 0x4a009700,
> diff --git a/arch/arm/include/asm/omap_common.h
> b/arch/arm/include/asm/omap_common.h index 323952f..bd43099 100644
> --- a/arch/arm/include/asm/omap_common.h
> +++ b/arch/arm/include/asm/omap_common.h
> @@ -143,7 +143,7 @@ struct prcm_regs {
>  	u32 cm_div_m2_dpll_unipro;
>  	u32 cm_ssc_deltamstep_dpll_unipro;
>  	u32 cm_ssc_modfreqdiv_dpll_unipro;
> -	u32 cm_coreaon_usb_phy_core_clkctrl;
> +	u32 cm_coreaon_usb_phy1_core_clkctrl;
>  	u32 cm_coreaon_usb_phy2_core_clkctrl;
>  
>  	/* cm2.core */
> @@ -230,7 +230,7 @@ struct prcm_regs {
>  	u32 cm_l3init_fsusb_clkctrl;
>  	u32 cm_l3init_ocp2scp1_clkctrl;
>  	u32 cm_l3init_ocp2scp3_clkctrl;
> -	u32 cm_l3init_usb_otg_ss_clkctrl;
> +	u32 cm_l3init_usb_otg_ss1_clkctrl;
>  
>  	u32 prm_irqstatus_mpu_2;
>  

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 02/40] ARM: AM43xx: Enable clocks for USB OTGSS and USB PHY
  2015-02-06  8:47 ` [U-Boot] [u-boot 02/40] ARM: AM43xx: " Kishon Vijay Abraham I
@ 2015-02-16 10:07   ` Lukasz Majewski
  2015-02-16 13:29     ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:07 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Enabled clocks for dwc3 controller and USB PHY present in AM43xx.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/cpu/armv7/am33xx/clock_am43xx.c           |   12 +++++++++++
>  arch/arm/include/asm/arch-am33xx/cpu.h             |   22
> ++++++++++++++------
> arch/arm/include/asm/arch-am33xx/hardware_am43xx.h |    4 ++++ 3
> files changed, 32 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
> b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c index 31188c8..252135d
> 100644 --- a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
> +++ b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
> @@ -111,9 +111,21 @@ void enable_basic_clocks(void)
>  		&cmper->emifclkctrl,
>  		&cmper->otfaemifclkctrl,
>  		&cmper->qspiclkctrl,
> +		&cmper->usb0clkctrl,
> +		&cmper->usbphyocp2scp0clkctrl,
> +		&cmper->usb1clkctrl,
> +		&cmper->usbphyocp2scp1clkctrl,
>  		0
>  	};
>  
> +	setbits_le32(&cmper->usb0clkctrl,
> +		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
> +	setbits_le32(&cmwkup->usbphy0clkctrl,
> +		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
> +	setbits_le32(&cmper->usb1clkctrl,
> +		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
> +	setbits_le32(&cmwkup->usbphy1clkctrl,
> +		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
>  	do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
>  
>  	/* Select the Master osc clk as Timer2 clock source */
> diff --git a/arch/arm/include/asm/arch-am33xx/cpu.h
> b/arch/arm/include/asm/arch-am33xx/cpu.h index 8dd69b3..1caa24e 100644
> --- a/arch/arm/include/asm/arch-am33xx/cpu.h
> +++ b/arch/arm/include/asm/arch-am33xx/cpu.h
> @@ -224,7 +224,11 @@ struct cm_dpll {
>  struct cm_wkuppll {
>  	unsigned int resv0[136];
>  	unsigned int wkl4wkclkctrl;	/* offset 0x220 */
> -	unsigned int resv1[55];
> +	unsigned int resv1[7];
> +	unsigned int usbphy0clkctrl;	/* offset 0x240 */
> +	unsigned int resv112;
> +	unsigned int usbphy1clkctrl;	/* offset 0x248 */
> +	unsigned int resv113[45];
>  	unsigned int wkclkstctrl;	/* offset 0x300 */
>  	unsigned int resv2[15];
>  	unsigned int wkup_i2c0ctrl;	/* offset 0x340 */
> @@ -275,7 +279,7 @@ struct cm_wkuppll {
>  	unsigned int divm2dplldisp;	/* offset 0x630 */
>  };
>  
> -/*
> +/*get_sys_clk_freq

This comment doesn't comply with coding style.

It should be 

	/*
	 * get_sys_clk_freq
	 * En ...

	 */

>   * Encapsulating peripheral functional clocks
>   * pll registers
>   */
> @@ -283,7 +287,7 @@ struct cm_perpll {
>  	unsigned int l3clkstctrl;	/* offset 0x00 */
>  	unsigned int resv0[7];
>  	unsigned int l3clkctrl;		/* Offset 0x20 */
> -	unsigned int resv1[7];
> +	unsigned int resv112[7];
>  	unsigned int l3instrclkctrl;	/* offset 0x40 */
>  	unsigned int resv2[3];
>  	unsigned int ocmcramclkctrl;	/* offset 0x50 */
> @@ -310,7 +314,9 @@ struct cm_perpll {
>  	unsigned int qspiclkctrl;       /* offset 0x258 */
>  	unsigned int resv121;
>  	unsigned int usb0clkctrl;	/* offset 0x260 */
> -	unsigned int resv13[103];
> +	unsigned int resv122;
> +	unsigned int usb1clkctrl;	/* offset 0x268 */
> +	unsigned int resv13[101];
>  	unsigned int l4lsclkstctrl;	/* offset 0x400 */
>  	unsigned int resv14[7];
>  	unsigned int l4lsclkctrl;	/* offset 0x420 */
> @@ -364,10 +370,14 @@ struct cm_perpll {
>  	unsigned int uart4clkctrl;	/* offset 0x598 */
>  	unsigned int resv35;
>  	unsigned int uart5clkctrl;	/* offset 0x5A0 */
> -	unsigned int resv36[87];
> +	unsigned int resv36[5];
> +	unsigned int usbphyocp2scp0clkctrl;	/* offset 0x5B8 */
> +	unsigned int resv361;
> +	unsigned int usbphyocp2scp1clkctrl;	/* offset 0x5C0 */
> +	unsigned int resv3611[79];
>  
>  	unsigned int emifclkstctrl;	/* offset 0x700 */
> -	unsigned int resv361[7];
> +	unsigned int resv362[7];
>  	unsigned int emifclkctrl;	/* offset 0x720 */
>  	unsigned int resv37[3];
>  	unsigned int emiffwclkctrl;	/* offset 0x730 */
> diff --git a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
> b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h index
> efdecf4..5f259da 100644 ---
> a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h +++
> b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h @@ -72,6 +72,10
> @@ #define USBPHYOCPSCP_MODULE_EN	(1 << 1)
>  #define CM_DEVICE_INST			0x44df4100
>  
> +#define	USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960	(1 << 8)
> +#define	USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K	(1 << 8)
> +
> +

Two blank lines.

>  /* Control status register */
>  #define CTRL_CRYSTAL_FREQ_SRC_MASK		(1 << 31)
>  #define CTRL_CRYSTAL_FREQ_SRC_SHIFT		31

If Marek agrees to correct this minor issues (before adding it to -usb
tree), then

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot
  2015-02-06  8:47 ` [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot Kishon Vijay Abraham I
  2015-02-07 13:27   ` Marek Vasut
@ 2015-02-16 10:11   ` Lukasz Majewski
  1 sibling, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:11 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added udc-core.c from linux kernel 3.19-rc1 (97bf6af1f9) to u-boot.
> This will be adapted to work with u-boot in the
> following patches.
> Adding support for udc will help to seamlessly port dwc3 driver from
> linux kernel to u-boot (since dwc3 uses udc-core) and it'll also help
> to add support for multiple gadget controllers to be functional at the
> same time.
> All other gadget drivers can also be adapted to use udc-core.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/gadget/udc/Makefile   |    4 +
>  drivers/usb/gadget/udc/udc-core.c |  637
> +++++++++++++++++++++++++++++++++++++ 2 files changed, 641
> insertions(+) create mode 100644 drivers/usb/gadget/udc/Makefile
>  create mode 100644 drivers/usb/gadget/udc/udc-core.c
> 
> diff --git a/drivers/usb/gadget/udc/Makefile
> b/drivers/usb/gadget/udc/Makefile new file mode 100644
> index 0000000..be265aa
> --- /dev/null
> +++ b/drivers/usb/gadget/udc/Makefile
> @@ -0,0 +1,4 @@
> +#
> +# USB peripheral controller drivers
> +#
> +obj-$(CONFIG_USB_GADGET)	+= udc-core.o
> diff --git a/drivers/usb/gadget/udc/udc-core.c
> b/drivers/usb/gadget/udc/udc-core.c new file mode 100644
> index 0000000..e31d574
> --- /dev/null
> +++ b/drivers/usb/gadget/udc/udc-core.c
> @@ -0,0 +1,637 @@
> +/**
> + * udc.c - Core UDC Framework
> + *
> + * Copyright (C) 2010 Texas Instruments
> + * Author: Felipe Balbi <balbi@ti.com>
> + *
> + * This program is free software: you can redistribute it and/or
> modify
> + * it under the terms of the GNU General Public License version 2  of
> + * the License as published by the Free Software Foundation.
> + *
> + * 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, see
> <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/device.h>
> +#include <linux/list.h>
> +#include <linux/err.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/workqueue.h>
> +
> +#include <linux/usb/ch9.h>
> +#include <linux/usb/gadget.h>
> +#include <linux/usb.h>
> +
> +/**
> + * struct usb_udc - describes one usb device controller
> + * @driver - the gadget driver pointer. For use by the class code
> + * @dev - the child device to the actual controller
> + * @gadget - the gadget. For use by the class code
> + * @list - for use by the udc class driver
> + *
> + * This represents the internal data structure which is used by the
> UDC-class
> + * to hold information about udc driver and gadget together.
> + */
> +struct usb_udc {
> +	struct usb_gadget_driver	*driver;
> +	struct usb_gadget		*gadget;
> +	struct device			dev;
> +	struct list_head		list;
> +};
> +
> +static struct class *udc_class;
> +static LIST_HEAD(udc_list);
> +static DEFINE_MUTEX(udc_lock);
> +
> +/*
> -------------------------------------------------------------------------
> */ + +#ifdef	CONFIG_HAS_DMA
> +
> +int usb_gadget_map_request(struct usb_gadget *gadget,
> +		struct usb_request *req, int is_in)
> +{
> +	if (req->length == 0)
> +		return 0;
> +
> +	if (req->num_sgs) {
> +		int     mapped;
> +
> +		mapped = dma_map_sg(&gadget->dev, req->sg,
> req->num_sgs,
> +				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE);
> +		if (mapped == 0) {
> +			dev_err(&gadget->dev, "failed to map SGs\n");
> +			return -EFAULT;
> +		}
> +
> +		req->num_mapped_sgs = mapped;
> +	} else {
> +		req->dma = dma_map_single(&gadget->dev, req->buf,
> req->length,
> +				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE); +
> +		if (dma_mapping_error(&gadget->dev, req->dma)) {
> +			dev_err(&gadget->dev, "failed to map
> buffer\n");
> +			return -EFAULT;
> +		}
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_map_request);
> +
> +void usb_gadget_unmap_request(struct usb_gadget *gadget,
> +		struct usb_request *req, int is_in)
> +{
> +	if (req->length == 0)
> +		return;
> +
> +	if (req->num_mapped_sgs) {
> +		dma_unmap_sg(&gadget->dev, req->sg,
> req->num_mapped_sgs,
> +				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE); +
> +		req->num_mapped_sgs = 0;
> +	} else {
> +		dma_unmap_single(&gadget->dev, req->dma, req->length,
> +				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE);
> +	}
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
> +
> +#endif	/* CONFIG_HAS_DMA */
> +
> +/*
> -------------------------------------------------------------------------
> */ + +/**
> + * usb_gadget_giveback_request - give the request back to the gadget
> layer
> + * Context: in_interrupt()
> + *
> + * This is called by device controller drivers in order to return the
> + * completed request back to the gadget layer.
> + */
> +void usb_gadget_giveback_request(struct usb_ep *ep,
> +		struct usb_request *req)
> +{
> +	if (likely(req->status == 0))
> +		usb_led_activity(USB_LED_EVENT_GADGET);
> +
> +	req->complete(ep, req);
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
> +
> +/*
> -------------------------------------------------------------------------
> */ + +static void usb_gadget_state_work(struct work_struct *work)
> +{
> +	struct usb_gadget	*gadget = work_to_gadget(work);
> +	struct usb_udc		*udc = NULL;
> +
> +	mutex_lock(&udc_lock);
> +	list_for_each_entry(udc, &udc_list, list)
> +		if (udc->gadget == gadget)
> +			goto found;
> +	mutex_unlock(&udc_lock);
> +
> +	return;
> +
> +found:
> +	mutex_unlock(&udc_lock);
> +
> +	sysfs_notify(&udc->dev.kobj, NULL, "state");
> +}
> +
> +void usb_gadget_set_state(struct usb_gadget *gadget,
> +		enum usb_device_state state)
> +{
> +	gadget->state = state;
> +	schedule_work(&gadget->work);
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_set_state);
> +
> +/*
> -------------------------------------------------------------------------
> */ + +/**
> + * usb_gadget_udc_reset - notifies the udc core that bus reset occurs
> + * @gadget: The gadget which bus reset occurs
> + * @driver: The gadget driver we want to notify
> + *
> + * If the udc driver has bus reset handler, it needs to call this
> when the bus
> + * reset occurs, it notifies the gadget driver that the bus reset
> occurs as
> + * well as updates gadget state.
> + */
> +void usb_gadget_udc_reset(struct usb_gadget *gadget,
> +		struct usb_gadget_driver *driver)
> +{
> +	driver->reset(gadget);
> +	usb_gadget_set_state(gadget, USB_STATE_DEFAULT);
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
> +
> +/**
> + * usb_gadget_udc_start - tells usb device controller to start up
> + * @udc: The UDC to be started
> + *
> + * This call is issued by the UDC Class driver when it's about
> + * to register a gadget driver to the device controller, before
> + * calling gadget driver's bind() method.
> + *
> + * It allows the controller to be powered off until strictly
> + * necessary to have it powered on.
> + *
> + * Returns zero on success, else negative errno.
> + */
> +static inline int usb_gadget_udc_start(struct usb_udc *udc)
> +{
> +	return udc->gadget->ops->udc_start(udc->gadget, udc->driver);
> +}
> +
> +/**
> + * usb_gadget_udc_stop - tells usb device controller we don't need
> it anymore
> + * @gadget: The device we want to stop activity
> + * @driver: The driver to unbind from @gadget
> + *
> + * This call is issued by the UDC Class driver after calling
> + * gadget driver's unbind() method.
> + *
> + * The details are implementation specific, but it can go as
> + * far as powering off UDC completely and disable its data
> + * line pullups.
> + */
> +static inline void usb_gadget_udc_stop(struct usb_udc *udc)
> +{
> +	udc->gadget->ops->udc_stop(udc->gadget);
> +}
> +
> +/**
> + * usb_udc_release - release the usb_udc struct
> + * @dev: the dev member within usb_udc
> + *
> + * This is called by driver's core in order to free memory once the
> last
> + * reference is released.
> + */
> +static void usb_udc_release(struct device *dev)
> +{
> +	struct usb_udc *udc;
> +
> +	udc = container_of(dev, struct usb_udc, dev);
> +	dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
> +	kfree(udc);
> +}
> +
> +static const struct attribute_group *usb_udc_attr_groups[];
> +
> +static void usb_udc_nop_release(struct device *dev)
> +{
> +	dev_vdbg(dev, "%s\n", __func__);
> +}
> +
> +/**
> + * usb_add_gadget_udc_release - adds a new gadget to the udc class
> driver list
> + * @parent: the parent device to this udc. Usually the controller
> driver's
> + * device.
> + * @gadget: the gadget to be added to the list.
> + * @release: a gadget release function.
> + *
> + * Returns zero on success, negative errno otherwise.
> + */
> +int usb_add_gadget_udc_release(struct device *parent, struct
> usb_gadget *gadget,
> +		void (*release)(struct device *dev))
> +{
> +	struct usb_udc		*udc;
> +	int			ret = -ENOMEM;
> +
> +	udc = kzalloc(sizeof(*udc), GFP_KERNEL);
> +	if (!udc)
> +		goto err1;
> +
> +	dev_set_name(&gadget->dev, "gadget");
> +	INIT_WORK(&gadget->work, usb_gadget_state_work);
> +	gadget->dev.parent = parent;
> +
> +#ifdef	CONFIG_HAS_DMA
> +	dma_set_coherent_mask(&gadget->dev,
> parent->coherent_dma_mask);
> +	gadget->dev.dma_parms = parent->dma_parms;
> +	gadget->dev.dma_mask = parent->dma_mask;
> +#endif
> +
> +	if (release)
> +		gadget->dev.release = release;
> +	else
> +		gadget->dev.release = usb_udc_nop_release;
> +
> +	ret = device_register(&gadget->dev);
> +	if (ret)
> +		goto err2;
> +
> +	device_initialize(&udc->dev);
> +	udc->dev.release = usb_udc_release;
> +	udc->dev.class = udc_class;
> +	udc->dev.groups = usb_udc_attr_groups;
> +	udc->dev.parent = parent;
> +	ret = dev_set_name(&udc->dev, "%s",
> kobject_name(&parent->kobj));
> +	if (ret)
> +		goto err3;
> +
> +	udc->gadget = gadget;
> +
> +	mutex_lock(&udc_lock);
> +	list_add_tail(&udc->list, &udc_list);
> +
> +	ret = device_add(&udc->dev);
> +	if (ret)
> +		goto err4;
> +
> +	usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
> +
> +	mutex_unlock(&udc_lock);
> +
> +	return 0;
> +
> +err4:
> +	list_del(&udc->list);
> +	mutex_unlock(&udc_lock);
> +
> +err3:
> +	put_device(&udc->dev);
> +
> +err2:
> +	put_device(&gadget->dev);
> +	kfree(udc);
> +
> +err1:
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
> +
> +/**
> + * usb_add_gadget_udc - adds a new gadget to the udc class driver
> list
> + * @parent: the parent device to this udc. Usually the controller
> + * driver's device.
> + * @gadget: the gadget to be added to the list
> + *
> + * Returns zero on success, negative errno otherwise.
> + */
> +int usb_add_gadget_udc(struct device *parent, struct usb_gadget
> *gadget) +{
> +	return usb_add_gadget_udc_release(parent, gadget, NULL);
> +}
> +EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
> +
> +static void usb_gadget_remove_driver(struct usb_udc *udc)
> +{
> +	dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
> +			udc->driver->function);
> +
> +	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
> +
> +	usb_gadget_disconnect(udc->gadget);
> +	udc->driver->disconnect(udc->gadget);
> +	udc->driver->unbind(udc->gadget);
> +	usb_gadget_udc_stop(udc);
> +
> +	udc->driver = NULL;
> +	udc->dev.driver = NULL;
> +	udc->gadget->dev.driver = NULL;
> +}
> +
> +/**
> + * usb_del_gadget_udc - deletes @udc from udc_list
> + * @gadget: the gadget to be removed.
> + *
> + * This, will call usb_gadget_unregister_driver() if
> + * the @udc is still busy.
> + */
> +void usb_del_gadget_udc(struct usb_gadget *gadget)
> +{
> +	struct usb_udc		*udc = NULL;
> +
> +	mutex_lock(&udc_lock);
> +	list_for_each_entry(udc, &udc_list, list)
> +		if (udc->gadget == gadget)
> +			goto found;
> +
> +	dev_err(gadget->dev.parent, "gadget not registered.\n");
> +	mutex_unlock(&udc_lock);
> +
> +	return;
> +
> +found:
> +	dev_vdbg(gadget->dev.parent, "unregistering gadget\n");
> +
> +	list_del(&udc->list);
> +	mutex_unlock(&udc_lock);
> +
> +	if (udc->driver)
> +		usb_gadget_remove_driver(udc);
> +
> +	kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
> +	flush_work(&gadget->work);
> +	device_unregister(&udc->dev);
> +	device_unregister(&gadget->dev);
> +}
> +EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
> +
> +/*
> -------------------------------------------------------------------------
> */ + +static int udc_bind_to_driver(struct usb_udc *udc, struct
> usb_gadget_driver *driver) +{
> +	int ret;
> +
> +	dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
> +			driver->function);
> +
> +	udc->driver = driver;
> +	udc->dev.driver = &driver->driver;
> +	udc->gadget->dev.driver = &driver->driver;
> +
> +	ret = driver->bind(udc->gadget, driver);
> +	if (ret)
> +		goto err1;
> +	ret = usb_gadget_udc_start(udc);
> +	if (ret) {
> +		driver->unbind(udc->gadget);
> +		goto err1;
> +	}
> +	usb_gadget_connect(udc->gadget);
> +
> +	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
> +	return 0;
> +err1:
> +	if (ret != -EISNAM)
> +		dev_err(&udc->dev, "failed to start %s: %d\n",
> +			udc->driver->function, ret);
> +	udc->driver = NULL;
> +	udc->dev.driver = NULL;
> +	udc->gadget->dev.driver = NULL;
> +	return ret;
> +}
> +
> +int usb_udc_attach_driver(const char *name, struct usb_gadget_driver
> *driver) +{
> +	struct usb_udc *udc = NULL;
> +	int ret = -ENODEV;
> +
> +	mutex_lock(&udc_lock);
> +	list_for_each_entry(udc, &udc_list, list) {
> +		ret = strcmp(name, dev_name(&udc->dev));
> +		if (!ret)
> +			break;
> +	}
> +	if (ret) {
> +		ret = -ENODEV;
> +		goto out;
> +	}
> +	if (udc->driver) {
> +		ret = -EBUSY;
> +		goto out;
> +	}
> +	ret = udc_bind_to_driver(udc, driver);
> +out:
> +	mutex_unlock(&udc_lock);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(usb_udc_attach_driver);
> +
> +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
> +{
> +	struct usb_udc		*udc = NULL;
> +	int			ret;
> +
> +	if (!driver || !driver->bind || !driver->setup)
> +		return -EINVAL;
> +
> +	mutex_lock(&udc_lock);
> +	list_for_each_entry(udc, &udc_list, list) {
> +		/* For now we take the first one */
> +		if (!udc->driver)
> +			goto found;
> +	}
> +
> +	pr_debug("couldn't find an available UDC\n");
> +	mutex_unlock(&udc_lock);
> +	return -ENODEV;
> +found:
> +	ret = udc_bind_to_driver(udc, driver);
> +	mutex_unlock(&udc_lock);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
> +
> +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
> +{
> +	struct usb_udc		*udc = NULL;
> +	int			ret = -ENODEV;
> +
> +	if (!driver || !driver->unbind)
> +		return -EINVAL;
> +
> +	mutex_lock(&udc_lock);
> +	list_for_each_entry(udc, &udc_list, list)
> +		if (udc->driver == driver) {
> +			usb_gadget_remove_driver(udc);
> +			usb_gadget_set_state(udc->gadget,
> +					USB_STATE_NOTATTACHED);
> +			ret = 0;
> +			break;
> +		}
> +
> +	mutex_unlock(&udc_lock);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
> +
> +/*
> -------------------------------------------------------------------------
> */ + +static ssize_t usb_udc_srp_store(struct device *dev,
> +		struct device_attribute *attr, const char *buf,
> size_t n) +{
> +	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev); +
> +	if (sysfs_streq(buf, "1"))
> +		usb_gadget_wakeup(udc->gadget);
> +
> +	return n;
> +}
> +static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
> +
> +static ssize_t usb_udc_softconn_store(struct device *dev,
> +		struct device_attribute *attr, const char *buf,
> size_t n) +{
> +	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev); +
> +	if (!udc->driver) {
> +		dev_err(dev, "soft-connect without a gadget
> driver\n");
> +		return -EOPNOTSUPP;
> +	}
> +
> +	if (sysfs_streq(buf, "connect")) {
> +		usb_gadget_udc_start(udc);
> +		usb_gadget_connect(udc->gadget);
> +	} else if (sysfs_streq(buf, "disconnect")) {
> +		usb_gadget_disconnect(udc->gadget);
> +		udc->driver->disconnect(udc->gadget);
> +		usb_gadget_udc_stop(udc);
> +	} else {
> +		dev_err(dev, "unsupported command '%s'\n", buf);
> +		return -EINVAL;
> +	}
> +
> +	return n;
> +}
> +static DEVICE_ATTR(soft_connect, S_IWUSR, NULL,
> usb_udc_softconn_store); +
> +static ssize_t state_show(struct device *dev, struct
> device_attribute *attr,
> +			  char *buf)
> +{
> +	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev);
> +	struct usb_gadget	*gadget = udc->gadget;
> +
> +	return sprintf(buf, "%s\n", usb_state_string(gadget->state));
> +}
> +static DEVICE_ATTR_RO(state);
> +
> +#define USB_UDC_SPEED_ATTR(name,
> param)					\ +ssize_t
> name##_show(struct device
> *dev,					\
> +		struct device_attribute *attr, char
> *buf)		\
> +{
> \
> +	struct usb_udc *udc = container_of(dev, struct usb_udc,
> dev);	\
> +	return snprintf(buf, PAGE_SIZE,
> "%s\n",				\
> +
> usb_speed_string(udc->gadget->param));		\
> +}
> \ +static DEVICE_ATTR_RO(name) +
> +static USB_UDC_SPEED_ATTR(current_speed, speed);
> +static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
> +
> +#define USB_UDC_ATTR(name)					\
> +ssize_t name##_show(struct device
> *dev,				\
> +		struct device_attribute *attr, char *buf)	\
> +{								\
> +	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev); \
> +	struct usb_gadget	*gadget =
> udc->gadget;		\
> +								\
> +	return snprintf(buf, PAGE_SIZE, "%d\n",
> gadget->name);	\
> +}								\
> +static DEVICE_ATTR_RO(name) +
> +static USB_UDC_ATTR(is_otg);
> +static USB_UDC_ATTR(is_a_peripheral);
> +static USB_UDC_ATTR(b_hnp_enable);
> +static USB_UDC_ATTR(a_hnp_support);
> +static USB_UDC_ATTR(a_alt_hnp_support);
> +
> +static struct attribute *usb_udc_attrs[] = {
> +	&dev_attr_srp.attr,
> +	&dev_attr_soft_connect.attr,
> +	&dev_attr_state.attr,
> +	&dev_attr_current_speed.attr,
> +	&dev_attr_maximum_speed.attr,
> +
> +	&dev_attr_is_otg.attr,
> +	&dev_attr_is_a_peripheral.attr,
> +	&dev_attr_b_hnp_enable.attr,
> +	&dev_attr_a_hnp_support.attr,
> +	&dev_attr_a_alt_hnp_support.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group usb_udc_attr_group = {
> +	.attrs = usb_udc_attrs,
> +};
> +
> +static const struct attribute_group *usb_udc_attr_groups[] = {
> +	&usb_udc_attr_group,
> +	NULL,
> +};
> +
> +static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env
> *env) +{
> +	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev);
> +	int			ret;
> +
> +	ret = add_uevent_var(env, "USB_UDC_NAME=%s",
> udc->gadget->name);
> +	if (ret) {
> +		dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
> +		return ret;
> +	}
> +
> +	if (udc->driver) {
> +		ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
> +				udc->driver->function);
> +		if (ret) {
> +			dev_err(dev, "failed to add uevent
> USB_UDC_DRIVER\n");
> +			return ret;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
> +static int __init usb_udc_init(void)
> +{
> +	udc_class = class_create(THIS_MODULE, "udc");
> +	if (IS_ERR(udc_class)) {
> +		pr_err("failed to create udc class --> %ld\n",
> +				PTR_ERR(udc_class));
> +		return PTR_ERR(udc_class);
> +	}
> +
> +	udc_class->dev_uevent = usb_udc_uevent;
> +	return 0;
> +}
> +subsys_initcall(usb_udc_init);
> +
> +static void __exit usb_udc_exit(void)
> +{
> +	class_destroy(udc_class);
> +}
> +module_exit(usb_udc_exit);
> +
> +MODULE_DESCRIPTION("UDC Framework");
> +MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
> +MODULE_LICENSE("GPL v2");

Since this code was taken from a linux kernel I don't have any comments
:-)

However, I will thest this series to asses if it works with Odroid-XU3,
since it also uses DWC3.


-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 04/40] include: usb: modify gadget.h to include udc support
  2015-02-06  8:47 ` [U-Boot] [u-boot 04/40] include: usb: modify gadget.h to include udc support Kishon Vijay Abraham I
@ 2015-02-16 10:12   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:12 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Made changes in gadget.h that is required after adding udc-core.c
> except changes that might break other platforms.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  include/linux/usb/gadget.h |   43
> +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43
> insertions(+)
> 
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index 9bccd45..1960958 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -396,6 +396,7 @@ static inline void usb_ep_fifo_flush(struct
> usb_ep
> *ep) /*-------------------------------------------------------------------------*/ 
>  struct usb_gadget;
> +struct usb_gadget_driver;
>  
>  /* the rest of the api to the controller hardware: device operations,
>   * which don't involve endpoints (or i/o).
> @@ -409,6 +410,9 @@ struct usb_gadget_ops {
>  	int	(*pullup) (struct usb_gadget *, int is_on);
>  	int	(*ioctl)(struct usb_gadget *,
>  				unsigned code, unsigned long param);
> +	int	(*udc_start)(struct usb_gadget *,
> +			     struct usb_gadget_driver *);
> +	int	(*udc_stop)(struct usb_gadget *);
>  };
>  
>  /**
> @@ -459,6 +463,7 @@ struct usb_gadget {
>  	struct usb_ep			*ep0;
>  	struct list_head		ep_list;	/* of usb_ep
> */ enum usb_device_speed		speed;
> +	enum usb_device_state		state;
>  	unsigned			is_dualspeed:1;
>  	unsigned			is_otg:1;
>  	unsigned			is_a_peripheral:1;
> @@ -686,6 +691,7 @@ static inline int usb_gadget_disconnect(struct
> usb_gadget *gadget) 
>  /**
>   * struct usb_gadget_driver - driver for usb 'slave' devices
> + * @function: String describing the gadget's function
>   * @speed: Highest speed the driver handles.
>   * @bind: Invoked when the driver is bound to a gadget, usually
>   *	after registering the driver.
> @@ -707,6 +713,8 @@ static inline int usb_gadget_disconnect(struct
> usb_gadget *gadget)
>   *	Called in a context that permits sleeping.
>   * @suspend: Invoked on USB suspend.  May be called in_interrupt.
>   * @resume: Invoked on USB resume.  May be called in_interrupt.
> + * @reset: Invoked on USB bus reset. It is mandatory for all gadget
> drivers
> + *	and should be called in_interrupt.
>   *
>   * Devices are disabled till a gadget driver successfully bind()s,
> which
>   * means the driver will handle setup() requests needed to enumerate
> (and @@ -753,6 +761,7 @@ static inline int
> usb_gadget_disconnect(struct usb_gadget *gadget)
>   * power is maintained.
>   */
>  struct usb_gadget_driver {
> +	char			*function;
>  	enum usb_device_speed	speed;
>  	int			(*bind)(struct usb_gadget *);
>  	void			(*unbind)(struct usb_gadget *);
> @@ -761,6 +770,7 @@ struct usb_gadget_driver {
>  	void			(*disconnect)(struct usb_gadget
> *); void			(*suspend)(struct usb_gadget *);
>  	void			(*resume)(struct usb_gadget *);
> +	void			(*reset)(struct usb_gadget *);
>  };
>  
>  
> @@ -801,6 +811,10 @@ int usb_gadget_register_driver(struct
> usb_gadget_driver *driver); */
>  int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
>  
> +int usb_add_gadget_udc_release(struct device *parent,
> +		struct usb_gadget *gadget, void (*release)(struct
> device *dev)); +int usb_add_gadget_udc(struct device *parent, struct
> usb_gadget *gadget); +void usb_del_gadget_udc(struct usb_gadget
> *gadget); /*-------------------------------------------------------------------------*/
>  
>  /* utility to simplify dealing with string descriptors */
> @@ -847,6 +861,35 @@ int usb_gadget_config_buf(const struct
> usb_config_descriptor *config, void *buf, unsigned buflen, const
> struct usb_descriptor_header **desc); 
>  /*-------------------------------------------------------------------------*/
> +/* utility to simplify map/unmap of usb_requests to/from DMA */
> +
> +extern int usb_gadget_map_request(struct usb_gadget *gadget,
> +				  struct usb_request *req, int
> is_in); +
> +extern void usb_gadget_unmap_request(struct usb_gadget *gadget,
> +				     struct usb_request *req, int
> is_in); +
> +/*-------------------------------------------------------------------------*/
> +
> +/* utility to set gadget state properly */
> +
> +extern void usb_gadget_set_state(struct usb_gadget *gadget,
> +				 enum usb_device_state state);
> +
> +/*-------------------------------------------------------------------------*/
> +
> +/* utility to tell udc core that the bus reset occurs */
> +extern void usb_gadget_udc_reset(struct usb_gadget *gadget,
> +				 struct usb_gadget_driver *driver);
> +
> +/*-------------------------------------------------------------------------*/
> +
> +/* utility to give requests back to the gadget layer */
> +
> +extern void usb_gadget_giveback_request(struct usb_ep *ep,
> +					struct usb_request *req);
> +
> +/*-------------------------------------------------------------------------*/
>  
>  /* utility wrapping a simple endpoint selection policy */
>  

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 05/40] usb: gadget: udc: make udc-core compile in u-boot build
  2015-02-06  8:47 ` [U-Boot] [u-boot 05/40] usb: gadget: udc: make udc-core compile in u-boot build Kishon Vijay Abraham I
@ 2015-02-16 10:18   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:18 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Make udc-core compile in u-boot by removing all linux specific
> stuff and having only the bare minimal udc-core required for
> usb gadget drivers. Also modified the file header to a format that is
> generally being used in u-boot.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/gadget/udc/udc-core.c |  335
> +++---------------------------------- 1 file changed, 26
> insertions(+), 309 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/udc-core.c
> b/drivers/usb/gadget/udc/udc-core.c index e31d574..875e998 100644
> --- a/drivers/usb/gadget/udc/udc-core.c
> +++ b/drivers/usb/gadget/udc/udc-core.c
> @@ -1,33 +1,27 @@
>  /**
> - * udc.c - Core UDC Framework
> + * udc-core.c - Core UDC Framework
> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com *
> - * Copyright (C) 2010 Texas Instruments
>   * Author: Felipe Balbi <balbi@ti.com>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/gadget/udc-core.c)
> and ported
> + * to uboot.
>   *
> - * 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.
> + * commit 02e8c96627 : usb: gadget: udc: core: prepend
> udc_attach_driver with
> + *		       usb_
>   *
> - * You should have received a copy of the GNU General Public License
> - * along with this program.  If not, see
> <http://www.gnu.org/licenses/>.
> + * SPDX-License-Identifier:     GPL-2.0
>   */
>  
> -#include <linux/kernel.h>
> -#include <linux/module.h>
> -#include <linux/device.h>
> -#include <linux/list.h>
> -#include <linux/err.h>
> -#include <linux/dma-mapping.h>
> -#include <linux/workqueue.h>
> +#include <linux/compat.h>
> +#include <malloc.h>
> +#include <asm/cache.h>
> +#include <asm/dma-mapping.h>
> +#include <common.h>
>  
>  #include <linux/usb/ch9.h>
>  #include <linux/usb/gadget.h>
> -#include <linux/usb.h>
>  
>  /**
>   * struct usb_udc - describes one usb device controller
> @@ -48,38 +42,18 @@ struct usb_udc {
>  
>  static struct class *udc_class;
>  static LIST_HEAD(udc_list);
> -static DEFINE_MUTEX(udc_lock);
> +DEFINE_MUTEX(udc_lock);
>  
>  /*
> -------------------------------------------------------------------------
> */ -#ifdef	CONFIG_HAS_DMA
> -
>  int usb_gadget_map_request(struct usb_gadget *gadget,
>  		struct usb_request *req, int is_in)
>  {
>  	if (req->length == 0)
>  		return 0;
>  
> -	if (req->num_sgs) {
> -		int     mapped;
> -
> -		mapped = dma_map_sg(&gadget->dev, req->sg,
> req->num_sgs,
> -				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE);
> -		if (mapped == 0) {
> -			dev_err(&gadget->dev, "failed to map SGs\n");
> -			return -EFAULT;
> -		}
> -
> -		req->num_mapped_sgs = mapped;
> -	} else {
> -		req->dma = dma_map_single(&gadget->dev, req->buf,
> req->length,
> -				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE); -
> -		if (dma_mapping_error(&gadget->dev, req->dma)) {
> -			dev_err(&gadget->dev, "failed to map
> buffer\n");
> -			return -EFAULT;
> -		}
> -	}
> +	req->dma = dma_map_single(req->buf, req->length,
> +				  is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE); 
>  	return 0;
>  }
> @@ -91,20 +65,11 @@ void usb_gadget_unmap_request(struct usb_gadget
> *gadget, if (req->length == 0)
>  		return;
>  
> -	if (req->num_mapped_sgs) {
> -		dma_unmap_sg(&gadget->dev, req->sg,
> req->num_mapped_sgs,
> -				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE); -
> -		req->num_mapped_sgs = 0;
> -	} else {
> -		dma_unmap_single(&gadget->dev, req->dma, req->length,
> -				is_in ? DMA_TO_DEVICE :
> DMA_FROM_DEVICE);
> -	}
> +	dma_unmap_single((void *)req->dma, req->length,
> +			 is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
>  }
>  EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
>  
> -#endif	/* CONFIG_HAS_DMA */
> -
>  /*
> -------------------------------------------------------------------------
> */ /**
> @@ -117,39 +82,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
>  void usb_gadget_giveback_request(struct usb_ep *ep,
>  		struct usb_request *req)
>  {
> -	if (likely(req->status == 0))
> -		usb_led_activity(USB_LED_EVENT_GADGET);
> -
>  	req->complete(ep, req);
>  }
>  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
>  
>  /*
> -------------------------------------------------------------------------
> */ -static void usb_gadget_state_work(struct work_struct *work)
> -{
> -	struct usb_gadget	*gadget = work_to_gadget(work);
> -	struct usb_udc		*udc = NULL;
> -
> -	mutex_lock(&udc_lock);
> -	list_for_each_entry(udc, &udc_list, list)
> -		if (udc->gadget == gadget)
> -			goto found;
> -	mutex_unlock(&udc_lock);
> -
> -	return;
> -
> -found:
> -	mutex_unlock(&udc_lock);
> -
> -	sysfs_notify(&udc->dev.kobj, NULL, "state");
> -}
> -
>  void usb_gadget_set_state(struct usb_gadget *gadget,
>  		enum usb_device_state state)
>  {
>  	gadget->state = state;
> -	schedule_work(&gadget->work);
>  }
>  EXPORT_SYMBOL_GPL(usb_gadget_set_state);
>  
> @@ -219,17 +161,9 @@ static void usb_udc_release(struct device *dev)
>  	struct usb_udc *udc;
>  
>  	udc = container_of(dev, struct usb_udc, dev);
> -	dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
>  	kfree(udc);
>  }
>  
> -static const struct attribute_group *usb_udc_attr_groups[];
> -
> -static void usb_udc_nop_release(struct device *dev)
> -{
> -	dev_vdbg(dev, "%s\n", __func__);
> -}
> -
>  /**
>   * usb_add_gadget_udc_release - adds a new gadget to the udc class
> driver list
>   * @parent: the parent device to this udc. Usually the controller
> driver's @@ -250,59 +184,23 @@ int usb_add_gadget_udc_release(struct
> device *parent, struct usb_gadget *gadget, goto err1;
>  
>  	dev_set_name(&gadget->dev, "gadget");
> -	INIT_WORK(&gadget->work, usb_gadget_state_work);
>  	gadget->dev.parent = parent;
>  
> -#ifdef	CONFIG_HAS_DMA
> -	dma_set_coherent_mask(&gadget->dev,
> parent->coherent_dma_mask);
> -	gadget->dev.dma_parms = parent->dma_parms;
> -	gadget->dev.dma_mask = parent->dma_mask;
> -#endif
> -
> -	if (release)
> -		gadget->dev.release = release;
> -	else
> -		gadget->dev.release = usb_udc_nop_release;
> -
> -	ret = device_register(&gadget->dev);
> -	if (ret)
> -		goto err2;
> -
> -	device_initialize(&udc->dev);
>  	udc->dev.release = usb_udc_release;
>  	udc->dev.class = udc_class;
> -	udc->dev.groups = usb_udc_attr_groups;
>  	udc->dev.parent = parent;
> -	ret = dev_set_name(&udc->dev, "%s",
> kobject_name(&parent->kobj));
> -	if (ret)
> -		goto err3;
>  
>  	udc->gadget = gadget;
>  
>  	mutex_lock(&udc_lock);
>  	list_add_tail(&udc->list, &udc_list);
>  
> -	ret = device_add(&udc->dev);
> -	if (ret)
> -		goto err4;
> -
>  	usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
>  
>  	mutex_unlock(&udc_lock);
>  
>  	return 0;
>  
> -err4:
> -	list_del(&udc->list);
> -	mutex_unlock(&udc_lock);
> -
> -err3:
> -	put_device(&udc->dev);
> -
> -err2:
> -	put_device(&gadget->dev);
> -	kfree(udc);
> -
>  err1:
>  	return ret;
>  }
> @@ -327,16 +225,12 @@ static void usb_gadget_remove_driver(struct
> usb_udc *udc) dev_dbg(&udc->dev, "unregistering UDC driver [%s]\n",
>  			udc->driver->function);
>  
> -	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
> -
>  	usb_gadget_disconnect(udc->gadget);
>  	udc->driver->disconnect(udc->gadget);
>  	udc->driver->unbind(udc->gadget);
>  	usb_gadget_udc_stop(udc);
>  
>  	udc->driver = NULL;
> -	udc->dev.driver = NULL;
> -	udc->gadget->dev.driver = NULL;
>  }
>  
>  /**
> @@ -368,11 +262,6 @@ found:
>  
>  	if (udc->driver)
>  		usb_gadget_remove_driver(udc);
> -
> -	kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
> -	flush_work(&gadget->work);
> -	device_unregister(&udc->dev);
> -	device_unregister(&gadget->dev);
>  }
>  EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
>  
> @@ -386,10 +275,8 @@ static int udc_bind_to_driver(struct usb_udc
> *udc, struct usb_gadget_driver *dri driver->function);
>  
>  	udc->driver = driver;
> -	udc->dev.driver = &driver->driver;
> -	udc->gadget->dev.driver = &driver->driver;
>  
> -	ret = driver->bind(udc->gadget, driver);
> +	ret = driver->bind(udc->gadget);
>  	if (ret)
>  		goto err1;
>  	ret = usb_gadget_udc_start(udc);
> @@ -399,43 +286,14 @@ static int udc_bind_to_driver(struct usb_udc
> *udc, struct usb_gadget_driver *dri }
>  	usb_gadget_connect(udc->gadget);
>  
> -	kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
>  	return 0;
>  err1:
>  	if (ret != -EISNAM)
>  		dev_err(&udc->dev, "failed to start %s: %d\n",
>  			udc->driver->function, ret);
>  	udc->driver = NULL;
> -	udc->dev.driver = NULL;
> -	udc->gadget->dev.driver = NULL;
> -	return ret;
> -}
> -
> -int usb_udc_attach_driver(const char *name, struct usb_gadget_driver
> *driver) -{
> -	struct usb_udc *udc = NULL;
> -	int ret = -ENODEV;
> -
> -	mutex_lock(&udc_lock);
> -	list_for_each_entry(udc, &udc_list, list) {
> -		ret = strcmp(name, dev_name(&udc->dev));
> -		if (!ret)
> -			break;
> -	}
> -	if (ret) {
> -		ret = -ENODEV;
> -		goto out;
> -	}
> -	if (udc->driver) {
> -		ret = -EBUSY;
> -		goto out;
> -	}
> -	ret = udc_bind_to_driver(udc, driver);
> -out:
> -	mutex_unlock(&udc_lock);
>  	return ret;
>  }
> -EXPORT_SYMBOL_GPL(usb_udc_attach_driver);
>  
>  int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
>  {
> @@ -452,7 +310,7 @@ int usb_gadget_probe_driver(struct
> usb_gadget_driver *driver) goto found;
>  	}
>  
> -	pr_debug("couldn't find an available UDC\n");
> +	printf("couldn't find an available UDC\n");
>  	mutex_unlock(&udc_lock);
>  	return -ENODEV;
>  found:
> @@ -462,6 +320,12 @@ found:
>  }
>  EXPORT_SYMBOL_GPL(usb_gadget_probe_driver);
>  
> +int usb_gadget_register_driver(struct usb_gadget_driver *driver)
> +{
> +	return usb_gadget_probe_driver(driver);
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_register_driver);
> +
>  int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
>  {
>  	struct usb_udc		*udc = NULL;
> @@ -485,153 +349,6 @@ int usb_gadget_unregister_driver(struct
> usb_gadget_driver *driver) }
>  EXPORT_SYMBOL_GPL(usb_gadget_unregister_driver);
>  
> -/*
> -------------------------------------------------------------------------
> */ - -static ssize_t usb_udc_srp_store(struct device *dev,
> -		struct device_attribute *attr, const char *buf,
> size_t n) -{
> -	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev); -
> -	if (sysfs_streq(buf, "1"))
> -		usb_gadget_wakeup(udc->gadget);
> -
> -	return n;
> -}
> -static DEVICE_ATTR(srp, S_IWUSR, NULL, usb_udc_srp_store);
> -
> -static ssize_t usb_udc_softconn_store(struct device *dev,
> -		struct device_attribute *attr, const char *buf,
> size_t n) -{
> -	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev); -
> -	if (!udc->driver) {
> -		dev_err(dev, "soft-connect without a gadget
> driver\n");
> -		return -EOPNOTSUPP;
> -	}
> -
> -	if (sysfs_streq(buf, "connect")) {
> -		usb_gadget_udc_start(udc);
> -		usb_gadget_connect(udc->gadget);
> -	} else if (sysfs_streq(buf, "disconnect")) {
> -		usb_gadget_disconnect(udc->gadget);
> -		udc->driver->disconnect(udc->gadget);
> -		usb_gadget_udc_stop(udc);
> -	} else {
> -		dev_err(dev, "unsupported command '%s'\n", buf);
> -		return -EINVAL;
> -	}
> -
> -	return n;
> -}
> -static DEVICE_ATTR(soft_connect, S_IWUSR, NULL,
> usb_udc_softconn_store); -
> -static ssize_t state_show(struct device *dev, struct
> device_attribute *attr,
> -			  char *buf)
> -{
> -	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev);
> -	struct usb_gadget	*gadget = udc->gadget;
> -
> -	return sprintf(buf, "%s\n", usb_state_string(gadget->state));
> -}
> -static DEVICE_ATTR_RO(state);
> -
> -#define USB_UDC_SPEED_ATTR(name,
> param)					\ -ssize_t
> name##_show(struct device
> *dev,					\
> -		struct device_attribute *attr, char
> *buf)		\
> -{
> \
> -	struct usb_udc *udc = container_of(dev, struct usb_udc,
> dev);	\
> -	return snprintf(buf, PAGE_SIZE,
> "%s\n",				\
> -
> usb_speed_string(udc->gadget->param));		\
> -}
> \ -static DEVICE_ATTR_RO(name) -
> -static USB_UDC_SPEED_ATTR(current_speed, speed);
> -static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
> -
> -#define USB_UDC_ATTR(name)					\
> -ssize_t name##_show(struct device
> *dev,				\
> -		struct device_attribute *attr, char *buf)	\
> -{								\
> -	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev); \
> -	struct usb_gadget	*gadget =
> udc->gadget;		\
> -								\
> -	return snprintf(buf, PAGE_SIZE, "%d\n",
> gadget->name);	\
> -}								\
> -static DEVICE_ATTR_RO(name) -
> -static USB_UDC_ATTR(is_otg);
> -static USB_UDC_ATTR(is_a_peripheral);
> -static USB_UDC_ATTR(b_hnp_enable);
> -static USB_UDC_ATTR(a_hnp_support);
> -static USB_UDC_ATTR(a_alt_hnp_support);
> -
> -static struct attribute *usb_udc_attrs[] = {
> -	&dev_attr_srp.attr,
> -	&dev_attr_soft_connect.attr,
> -	&dev_attr_state.attr,
> -	&dev_attr_current_speed.attr,
> -	&dev_attr_maximum_speed.attr,
> -
> -	&dev_attr_is_otg.attr,
> -	&dev_attr_is_a_peripheral.attr,
> -	&dev_attr_b_hnp_enable.attr,
> -	&dev_attr_a_hnp_support.attr,
> -	&dev_attr_a_alt_hnp_support.attr,
> -	NULL,
> -};
> -
> -static const struct attribute_group usb_udc_attr_group = {
> -	.attrs = usb_udc_attrs,
> -};
> -
> -static const struct attribute_group *usb_udc_attr_groups[] = {
> -	&usb_udc_attr_group,
> -	NULL,
> -};
> -
> -static int usb_udc_uevent(struct device *dev, struct kobj_uevent_env
> *env) -{
> -	struct usb_udc		*udc = container_of(dev,
> struct usb_udc, dev);
> -	int			ret;
> -
> -	ret = add_uevent_var(env, "USB_UDC_NAME=%s",
> udc->gadget->name);
> -	if (ret) {
> -		dev_err(dev, "failed to add uevent USB_UDC_NAME\n");
> -		return ret;
> -	}
> -
> -	if (udc->driver) {
> -		ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
> -				udc->driver->function);
> -		if (ret) {
> -			dev_err(dev, "failed to add uevent
> USB_UDC_DRIVER\n");
> -			return ret;
> -		}
> -	}
> -
> -	return 0;
> -}
> -
> -static int __init usb_udc_init(void)
> -{
> -	udc_class = class_create(THIS_MODULE, "udc");
> -	if (IS_ERR(udc_class)) {
> -		pr_err("failed to create udc class --> %ld\n",
> -				PTR_ERR(udc_class));
> -		return PTR_ERR(udc_class);
> -	}
> -
> -	udc_class->dev_uevent = usb_udc_uevent;
> -	return 0;
> -}
> -subsys_initcall(usb_udc_init);
> -
> -static void __exit usb_udc_exit(void)
> -{
> -	class_destroy(udc_class);
> -}
> -module_exit(usb_udc_exit);
> -
>  MODULE_DESCRIPTION("UDC Framework");
>  MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
>  MODULE_LICENSE("GPL v2");

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 06/40] include: asm: dma-mapping: get rid of the compilation warning in udc-core
  2015-02-06  8:47 ` [U-Boot] [u-boot 06/40] include: asm: dma-mapping: get rid of the compilation warning in udc-core Kishon Vijay Abraham I
@ 2015-02-16 10:19   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:19 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Fixed the following warning here.
> "warning: ?dma_alloc_coherent? defined but not used" while compiling
> udc-core
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/include/asm/dma-mapping.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/include/asm/dma-mapping.h
> b/arch/arm/include/asm/dma-mapping.h index 55a4e26..14f00efd2 100644
> --- a/arch/arm/include/asm/dma-mapping.h
> +++ b/arch/arm/include/asm/dma-mapping.h
> @@ -14,7 +14,7 @@ enum dma_data_direction {
>  	DMA_FROM_DEVICE		= 2,
>  };
>  
> -static void *dma_alloc_coherent(size_t len, unsigned long *handle)
> +static inline void *dma_alloc_coherent(size_t len, unsigned long
> *handle) {
>  	*handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len);
>  	return (void *)*handle;

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 07/40] usb: dwc3: add dwc3 folder from linux kernel to u-boot
  2015-02-06  8:47 ` [U-Boot] [u-boot 07/40] usb: dwc3: add dwc3 folder from linux kernel to u-boot Kishon Vijay Abraham I
@ 2015-02-16 10:20   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:20 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added dwc3 folder from linux kernel 3.19-rc1 (97bf6af1f9)
> to u-boot. This will be adapted to work with u-boot in the
> following patches.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 08/40] usb: dwc3: remove un-used files from dwc3 folder
  2015-02-06  8:47 ` [U-Boot] [u-boot 08/40] usb: dwc3: remove un-used files from dwc3 folder Kishon Vijay Abraham I
@ 2015-02-16 10:21   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:21 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> removed un-used/un-supported files from dwc3. These files can be added
> later as and when the support is added.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 09/40] usb: dwc3: Modify the file headers to u-boot format
  2015-02-06  8:47 ` [U-Boot] [u-boot 09/40] usb: dwc3: Modify the file headers to u-boot format Kishon Vijay Abraham I
@ 2015-02-16 10:21   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:21 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Modified the file header to the format that is used in u-boot. Also
> included in the header, the commit in linux kernel from which each of
> these files are added.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.c      |   15 +++++----------
>  drivers/usb/dwc3/core.h      |   15 +++++++--------
>  drivers/usb/dwc3/dwc3-omap.c |   14 ++++++--------
>  drivers/usb/dwc3/ep0.c       |   14 ++++++--------
>  drivers/usb/dwc3/gadget.c    |   14 ++++++--------
>  drivers/usb/dwc3/gadget.h    |   16 ++++++++--------
>  drivers/usb/dwc3/io.h        |   15 +++++++--------
>  7 files changed, 45 insertions(+), 58 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 25ddc39..b79a8b3 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1,22 +1,17 @@
>  /**
>   * core.c - DesignWare USB3 DRD Controller Core file
>   *
> - * Copyright (C) 2010-2011 Texas Instruments Incorporated -
> http://www.ti.com
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com *
>   * Authors: Felipe Balbi <balbi@ti.com>,
>   *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/core.c) and
> ported
> + * to uboot.
>   *
> - * 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.
> + * commit cd72f890d2 : usb: dwc3: core: enable phy suspend quirk on
> non-FPGA *
> - * You should have received a copy of the GNU General Public License
> - * along with this program.  If not, see
> <http://www.gnu.org/licenses/>.
> + * SPDX-License-Identifier:     GPL-2.0
>   */
>  
>  #include <linux/version.h>
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 4bb9aa6..09cec53 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1,19 +1,18 @@
>  /**
>   * core.h - DesignWare USB3 DRD Core Header
>   *
> - * Copyright (C) 2010-2011 Texas Instruments Incorporated -
> http://www.ti.com
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com *
>   * Authors: Felipe Balbi <balbi@ti.com>,
>   *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/core.h) and
> ported
> + * to uboot.
> + *
> + * commit 460d098cb6 : usb: dwc3: make HIRD threshold configurable
> + *
> + * SPDX-License-Identifier:     GPL-2.0
>   *
> - * 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.
>   */
>  
>  #ifndef __DRIVERS_USB_DWC3_CORE_H
> diff --git a/drivers/usb/dwc3/dwc3-omap.c
> b/drivers/usb/dwc3/dwc3-omap.c index 172d64e..12b57cf 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -1,19 +1,17 @@
>  /**
>   * dwc3-omap.c - OMAP Specific Glue layer
>   *
> - * Copyright (C) 2010-2011 Texas Instruments Incorporated -
> http://www.ti.com
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com *
>   * Authors: Felipe Balbi <balbi@ti.com>,
>   *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/dwc3-omap.c)
> and ported
> + * to uboot.
>   *
> - * 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.
> + * commit 7ee2566ff5 : usb: dwc3: dwc3-omap: get rid of
> ->prepare()/->complete()
> + *
> + * SPDX-License-Identifier:     GPL-2.0
>   */
>  
>  #include <linux/module.h>
> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index 1bc77a3..c9fcb77 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -1,19 +1,17 @@
>  /**
>   * ep0.c - DesignWare USB3 DRD Controller Endpoint 0 Handling
>   *
> - * Copyright (C) 2010-2011 Texas Instruments Incorporated -
> http://www.ti.com
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com *
>   * Authors: Felipe Balbi <balbi@ti.com>,
>   *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/ep0.c) and
> ported
> + * to uboot.
>   *
> - * 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.
> + * commit c00552ebaf : Merge 3.18-rc7 into usb-next
> + *
> + * SPDX-License-Identifier:     GPL-2.0
>   */
>  
>  #include <linux/kernel.h>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index f03b136..0aefc5c 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1,19 +1,17 @@
>  /**
>   * gadget.c - DesignWare USB3 DRD Controller Gadget Framework Link
>   *
> - * Copyright (C) 2010-2011 Texas Instruments Incorporated -
> http://www.ti.com
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com *
>   * Authors: Felipe Balbi <balbi@ti.com>,
>   *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/gadget.c) and
> ported
> + * to uboot.
>   *
> - * 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.
> + * commit 8e74475b0e : usb: dwc3: gadget: use udc-core's reset
> notifier
> + *
> + * SPDX-License-Identifier:     GPL-2.0
>   */
>  
>  #include <linux/kernel.h>
> diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
> index 18ae3ea..042e247 100644
> --- a/drivers/usb/dwc3/gadget.h
> +++ b/drivers/usb/dwc3/gadget.h
> @@ -1,19 +1,19 @@
>  /**
>   * gadget.h - DesignWare USB3 DRD Gadget Header
>   *
> - * Copyright (C) 2010-2011 Texas Instruments Incorporated -
> http://www.ti.com
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com *
>   * Authors: Felipe Balbi <balbi@ti.com>,
>   *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/gadget.h) and
> ported
> + * to uboot.
> + *
> + * commit 7a60855972 : usb: dwc3: gadget: fix set_halt() bug with
> pending
> +		       transfers
> + *
> + * SPDX-License-Identifier:     GPL-2.0
>   *
> - * 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.
>   */
>  
>  #ifndef __DRIVERS_USB_DWC3_GADGET_H
> diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
> index 6a79c8e..87a1ae6 100644
> --- a/drivers/usb/dwc3/io.h
> +++ b/drivers/usb/dwc3/io.h
> @@ -1,19 +1,18 @@
>  /**
>   * io.h - DesignWare USB3 DRD IO Header
>   *
> - * Copyright (C) 2010-2011 Texas Instruments Incorporated -
> http://www.ti.com
> + * Copyright (C) 2014 Texas Instruments Incorporated -
> http://www.ti.com *
>   * Authors: Felipe Balbi <balbi@ti.com>,
>   *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>   *
> - * This program is free software: you can redistribute it and/or
> modify
> - * it under the terms of the GNU General Public License version 2  of
> - * the License as published by the Free Software Foundation.
> + * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/io.h) and
> ported
> + * to uboot.
> + *
> + * commit 2c4cbe6e5a : usb: dwc3: add tracepoints to aid debugging
> + *
> + * SPDX-License-Identifier:     GPL-2.0
>   *
> - * 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.
>   */
>  
>  #ifndef __DRIVERS_USB_DWC3_IO_H

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 10/40] usb: dwc3: remove trace_* APIs from dwc3 driver
  2015-02-06  8:47 ` [U-Boot] [u-boot 10/40] usb: dwc3: remove trace_* APIs from dwc3 driver Kishon Vijay Abraham I
@ 2015-02-16 10:24   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:24 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Removed most of the trace_* APIs from dwc3 driver since tracepoints
> are not supported in u-boot. Replaced some of the trace_* API with
> dev_dbg/dev/vdbg.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/Makefile |    5 +---
>  drivers/usb/dwc3/ep0.c    |   70
> ++++++++++++++++++---------------------------
> drivers/usb/dwc3/gadget.c |   17 -----------
> drivers/usb/dwc3/io.h     |   17 ----------- 4 files changed, 29
> insertions(+), 80 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
> index bb34fbc..afaa767 100644
> --- a/drivers/usb/dwc3/Makefile
> +++ b/drivers/usb/dwc3/Makefile
> @@ -1,12 +1,9 @@
> -# define_trace.h needs to know how to find our header
> -CFLAGS_trace.o				:= -I$(src)
> -
>  ccflags-$(CONFIG_USB_DWC3_DEBUG)	:= -DDEBUG
>  ccflags-$(CONFIG_USB_DWC3_VERBOSE)	+= -DVERBOSE_DEBUG
>  
>  obj-$(CONFIG_USB_DWC3)			+= dwc3.o
>  
> -dwc3-y					:= core.o debug.o
> trace.o +dwc3-y					:= core.o
> debug.o 
>  ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST)
> $(CONFIG_USB_DWC3_DUAL_ROLE)),) dwc3-y
> += host.o diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index c9fcb77..1751b1d 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -64,7 +64,7 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc,
> u8 epnum, dma_addr_t buf_dma, 
>  	dep = dwc->eps[epnum];
>  	if (dep->flags & DWC3_EP_BUSY) {
> -		dwc3_trace(trace_dwc3_ep0, "%s still busy",
> dep->name);
> +		dev_vdbg(dwc->dev, "%s still busy", dep->name);
>  		return 0;
>  	}
>  
> @@ -84,13 +84,10 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc,
> u8 epnum, dma_addr_t buf_dma, params.param0 =
> upper_32_bits(dwc->ep0_trb_addr); params.param1 =
> lower_32_bits(dwc->ep0_trb_addr); 
> -	trace_dwc3_prepare_trb(dep, trb);
> -
>  	ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
>  			DWC3_DEPCMD_STARTTRANSFER, &params);
>  	if (ret < 0) {
> -		dwc3_trace(trace_dwc3_ep0, "%s STARTTRANSFER failed",
> -				dep->name);
> +		dev_dbg(dwc->dev, "%s STARTTRANSFER failed",
> dep->name); return ret;
>  	}
>  
> @@ -155,8 +152,7 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep
> *dep, if (dwc->ep0state == EP0_STATUS_PHASE)
>  			__dwc3_ep0_do_control_status(dwc,
> dwc->eps[direction]); else
> -			dwc3_trace(trace_dwc3_ep0,
> -					"too early for delayed
> status");
> +			dev_dbg(dwc->dev, "too early for delayed
> status"); 
>  		return 0;
>  	}
> @@ -220,8 +216,7 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep,
> struct usb_request *request, 
>  	spin_lock_irqsave(&dwc->lock, flags);
>  	if (!dep->endpoint.desc) {
> -		dwc3_trace(trace_dwc3_ep0,
> -				"trying to queue request %p to
> disabled %s",
> +		dev_dbg(dwc->dev, "trying to queue request %p to
> disabled %s", request, dep->name);
>  		ret = -ESHUTDOWN;
>  		goto out;
> @@ -233,8 +228,7 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep,
> struct usb_request *request, goto out;
>  	}
>  
> -	dwc3_trace(trace_dwc3_ep0,
> -			"queueing request %p to %s length %d state
> '%s'",
> +	dev_vdbg(dwc->dev, "queueing request %p to %s length %d
> state '%s'", request, dep->name, request->length,
>  			dwc3_ep0_state_string(dwc->ep0state));
>  
> @@ -503,13 +497,12 @@ static int dwc3_ep0_set_address(struct dwc3
> *dwc, struct usb_ctrlrequest *ctrl) 
>  	addr = le16_to_cpu(ctrl->wValue);
>  	if (addr > 127) {
> -		dwc3_trace(trace_dwc3_ep0, "invalid device address
> %d", addr);
> +		dev_dbg(dwc->dev, "invalid device address %d", addr);
>  		return -EINVAL;
>  	}
>  
>  	if (state == USB_STATE_CONFIGURED) {
> -		dwc3_trace(trace_dwc3_ep0,
> -				"trying to set address when
> configured");
> +		dev_dbg(dwc->dev, "trying to set address when
> configured"); return -EINVAL;
>  	}
>  
> @@ -574,7 +567,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc,
> struct usb_ctrlrequest *ctrl) dwc3_writel(dwc->regs, DWC3_DCTL, reg);
>  
>  			dwc->resize_fifos = true;
> -			dwc3_trace(trace_dwc3_ep0, "resize FIFOs
> flag SET");
> +			dev_dbg(dwc->dev, "resize FIFOs flag SET");
>  		}
>  		break;
>  
> @@ -698,35 +691,35 @@ static int dwc3_ep0_std_request(struct dwc3
> *dwc, struct usb_ctrlrequest *ctrl) 
>  	switch (ctrl->bRequest) {
>  	case USB_REQ_GET_STATUS:
> -		dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS");
> +		dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS");
>  		ret = dwc3_ep0_handle_status(dwc, ctrl);
>  		break;
>  	case USB_REQ_CLEAR_FEATURE:
> -		dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE");
> +		dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE");
>  		ret = dwc3_ep0_handle_feature(dwc, ctrl, 0);
>  		break;
>  	case USB_REQ_SET_FEATURE:
> -		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE");
> +		dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE");
>  		ret = dwc3_ep0_handle_feature(dwc, ctrl, 1);
>  		break;
>  	case USB_REQ_SET_ADDRESS:
> -		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS");
> +		dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS");
>  		ret = dwc3_ep0_set_address(dwc, ctrl);
>  		break;
>  	case USB_REQ_SET_CONFIGURATION:
> -		dwc3_trace(trace_dwc3_ep0,
> "USB_REQ_SET_CONFIGURATION");
> +		dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION");
>  		ret = dwc3_ep0_set_config(dwc, ctrl);
>  		break;
>  	case USB_REQ_SET_SEL:
> -		dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL");
> +		dev_vdbg(dwc->dev, "USB_REQ_SET_SEL");
>  		ret = dwc3_ep0_set_sel(dwc, ctrl);
>  		break;
>  	case USB_REQ_SET_ISOCH_DELAY:
> -		dwc3_trace(trace_dwc3_ep0,
> "USB_REQ_SET_ISOCH_DELAY");
> +		dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY");
>  		ret = dwc3_ep0_set_isoch_delay(dwc, ctrl);
>  		break;
>  	default:
> -		dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget
> driver");
> +		dev_vdbg(dwc->dev, "Forwarding to gadget driver");
>  		ret = dwc3_ep0_delegate_req(dwc, ctrl);
>  		break;
>  	}
> @@ -744,8 +737,6 @@ static void dwc3_ep0_inspect_setup(struct dwc3
> *dwc, if (!dwc->gadget_driver)
>  		goto out;
>  
> -	trace_dwc3_ctrl_req(ctrl);
> -
>  	len = le16_to_cpu(ctrl->wLength);
>  	if (!len) {
>  		dwc->three_stage_setup = false;
> @@ -789,15 +780,13 @@ static void dwc3_ep0_complete_data(struct dwc3
> *dwc, 
>  	trb = dwc->ep0_trb;
>  
> -	trace_dwc3_complete_trb(ep0, trb);
> -
>  	r = next_request(&ep0->request_list);
>  	if (!r)
>  		return;
>  
>  	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
>  	if (status == DWC3_TRBSTS_SETUP_PENDING) {
> -		dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
> +		dev_dbg(dwc->dev, "Setup Pending received");
>  
>  		if (r)
>  			dwc3_gadget_giveback(ep0, r, -ECONNRESET);
> @@ -855,8 +844,6 @@ static void dwc3_ep0_complete_status(struct dwc3
> *dwc, dep = dwc->eps[0];
>  	trb = dwc->ep0_trb;
>  
> -	trace_dwc3_complete_trb(dep, trb);
> -
>  	if (!list_empty(&dep->request_list)) {
>  		r = next_request(&dep->request_list);
>  
> @@ -868,7 +855,7 @@ static void dwc3_ep0_complete_status(struct dwc3
> *dwc, 
>  		ret = dwc3_gadget_set_test_mode(dwc,
> dwc->test_mode_nr); if (ret < 0) {
> -			dwc3_trace(trace_dwc3_ep0, "Invalid Test
> #%d",
> +			dev_dbg(dwc->dev, "Invalid Test #%d",
>  					dwc->test_mode_nr);
>  			dwc3_ep0_stall_and_restart(dwc);
>  			return;
> @@ -877,7 +864,7 @@ static void dwc3_ep0_complete_status(struct dwc3
> *dwc, 
>  	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
>  	if (status == DWC3_TRBSTS_SETUP_PENDING)
> -		dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
> +		dev_dbg(dwc->dev, "Setup Pending received");
>  
>  	dwc->ep0state = EP0_SETUP_PHASE;
>  	dwc3_ep0_out_start(dwc);
> @@ -894,17 +881,17 @@ static void dwc3_ep0_xfer_complete(struct dwc3
> *dwc, 
>  	switch (dwc->ep0state) {
>  	case EP0_SETUP_PHASE:
> -		dwc3_trace(trace_dwc3_ep0, "Setup Phase");
> +		dev_vdbg(dwc->dev, "Setup Phase");
>  		dwc3_ep0_inspect_setup(dwc, event);
>  		break;
>  
>  	case EP0_DATA_PHASE:
> -		dwc3_trace(trace_dwc3_ep0, "Data Phase");
> +		dev_vdbg(dwc->dev, "Data Phase");
>  		dwc3_ep0_complete_data(dwc, event);
>  		break;
>  
>  	case EP0_STATUS_PHASE:
> -		dwc3_trace(trace_dwc3_ep0, "Status Phase");
> +		dev_vdbg(dwc->dev, "Status Phase");
>  		dwc3_ep0_complete_status(dwc, event);
>  		break;
>  	default:
> @@ -980,7 +967,7 @@ static int dwc3_ep0_start_control_status(struct
> dwc3_ep *dep) static void __dwc3_ep0_do_control_status(struct dwc3
> *dwc, struct dwc3_ep *dep) {
>  	if (dwc->resize_fifos) {
> -		dwc3_trace(trace_dwc3_ep0, "Resizing FIFOs");
> +		dev_dbg(dwc->dev, "Resizing FIFOs");
>  		dwc3_gadget_resize_tx_fifos(dwc);
>  		dwc->resize_fifos = 0;
>  	}
> @@ -1021,7 +1008,7 @@ static void dwc3_ep0_xfernotready(struct dwc3
> *dwc, 
>  	switch (event->status) {
>  	case DEPEVT_STATUS_CONTROL_DATA:
> -		dwc3_trace(trace_dwc3_ep0, "Control Data");
> +		dev_vdbg(dwc->dev, "Control Data");
>  
>  		/*
>  		 * We already have a DATA transfer in the
> controller's cache, @@ -1035,8 +1022,7 @@ static void
> dwc3_ep0_xfernotready(struct dwc3 *dwc, if (dwc->ep0_expect_in !=
> event->endpoint_number) { struct dwc3_ep	*dep =
> dwc->eps[dwc->ep0_expect_in]; 
> -			dwc3_trace(trace_dwc3_ep0,
> -					"Wrong direction for Data
> phase");
> +			dev_vdbg(dwc->dev, "Wrong direction for Data
> phase"); dwc3_ep0_end_control_data(dwc, dep);
>  			dwc3_ep0_stall_and_restart(dwc);
>  			return;
> @@ -1048,13 +1034,13 @@ static void dwc3_ep0_xfernotready(struct dwc3
> *dwc, if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS)
>  			return;
>  
> -		dwc3_trace(trace_dwc3_ep0, "Control Status");
> +		dev_vdbg(dwc->dev, "Control Status");
>  
>  		dwc->ep0state = EP0_STATUS_PHASE;
>  
>  		if (dwc->delayed_status) {
>  			WARN_ON_ONCE(event->endpoint_number != 1);
> -			dwc3_trace(trace_dwc3_ep0, "Delayed Status");
> +			dev_vdbg(dwc->dev, "Delayed Status");
>  			return;
>  		}
>  
> @@ -1067,7 +1053,7 @@ void dwc3_ep0_interrupt(struct dwc3 *dwc,
>  {
>  	u8			epnum = event->endpoint_number;
>  
> -	dwc3_trace(trace_dwc3_ep0, "%s while ep%d%s in state '%s'",
> +	dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'",
>  			dwc3_ep_event_string(event->endpoint_event),
>  			epnum >> 1, (epnum & 1) ? "in" : "out",
>  			dwc3_ep0_state_string(dwc->ep0state));
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 0aefc5c..ca0f0cd 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -265,7 +265,6 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep,
> struct dwc3_request *req, dev_dbg(dwc->dev, "request %p from %s
> completed %d/%d ===> %d\n", req, dep->name, req->request.actual,
>  			req->request.length, status);
> -	trace_dwc3_gadget_giveback(req);
>  
>  	spin_unlock(&dwc->lock);
>  	usb_gadget_giveback_request(&dep->endpoint, &req->request);
> @@ -277,8 +276,6 @@ int dwc3_send_gadget_generic_command(struct dwc3
> *dwc, unsigned cmd, u32 param) u32		timeout = 500;
>  	u32		reg;
>  
> -	trace_dwc3_gadget_generic_cmd(cmd, param);
> -
>  	dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param);
>  	dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT);
>  
> @@ -308,8 +305,6 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc,
> unsigned ep, u32			timeout = 500;
>  	u32			reg;
>  
> -	trace_dwc3_gadget_ep_cmd(dep, cmd, params);
> -
>  	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0);
>  	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1);
>  	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR2(ep), params->param2);
> @@ -704,8 +699,6 @@ static struct usb_request
> *dwc3_gadget_ep_alloc_request(struct usb_ep *ep, req->epnum	=
> dep->number; req->dep	= dep;
>  
> -	trace_dwc3_alloc_request(req);
> -
>  	return &req->request;
>  }
>  
> @@ -714,7 +707,6 @@ static void dwc3_gadget_ep_free_request(struct
> usb_ep *ep, {
>  	struct dwc3_request		*req =
> to_dwc3_request(request); 
> -	trace_dwc3_free_request(req);
>  	kfree(req);
>  }
>  
> @@ -796,8 +788,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep
> *dep, trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id);
>  
>  	trb->ctrl |= DWC3_TRB_CTRL_HWO;
> -
> -	trace_dwc3_prepare_trb(dep, trb);
>  }
>  
>  /*
> @@ -1150,7 +1140,6 @@ static int dwc3_gadget_ep_queue(struct usb_ep
> *ep, struct usb_request *request, 
>  	dev_vdbg(dwc->dev, "queing request %p to %s length %d\n",
>  			request, ep->name, request->length);
> -	trace_dwc3_ep_queue(req);
>  
>  	ret = __dwc3_gadget_ep_queue(dep, req);
>  
> @@ -1172,8 +1161,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep
> *ep, unsigned long			flags;
>  	int				ret = 0;
>  
> -	trace_dwc3_ep_dequeue(req);
> -
>  	spin_lock_irqsave(&dwc->lock, flags);
>  
>  	list_for_each_entry(r, &dep->request_list, list) {
> @@ -1771,8 +1758,6 @@ static int __dwc3_cleanup_done_trbs(struct dwc3
> *dwc, struct dwc3_ep *dep, unsigned int		s_pkt = 0;
>  	unsigned int		trb_status;
>  
> -	trace_dwc3_complete_trb(dep, trb);
> -
>  	if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN)
>  		/*
>  		 * We continue despite the error. There is not much
> we @@ -2529,8 +2514,6 @@ static void dwc3_gadget_interrupt(struct
> dwc3 *dwc, static void dwc3_process_event_entry(struct dwc3 *dwc,
>  		const union dwc3_event *event)
>  {
> -	trace_dwc3_event(event->raw);
> -
>  	/* Endpoint IRQ, handle it and return early */
>  	if (event->type.is_devspec == 0) {
>  		/* depevt */
> diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
> index 87a1ae6..f9f22b0 100644
> --- a/drivers/usb/dwc3/io.h
> +++ b/drivers/usb/dwc3/io.h
> @@ -19,7 +19,6 @@
>  #define __DRIVERS_USB_DWC3_IO_H
>  
>  #include <linux/io.h>
> -#include "trace.h"
>  #include "debug.h"
>  #include "core.h"
>  
> @@ -35,14 +34,6 @@ static inline u32 dwc3_readl(void __iomem *base,
> u32 offset) */
>  	value = readl(base + offs);
>  
> -	/*
> -	 * When tracing we want to make it easy to find the correct
> address on
> -	 * documentation, so we revert it back to the proper
> addresses, the
> -	 * same way they are described on SNPS documentation
> -	 */
> -	dwc3_trace(trace_dwc3_readl, "addr %p value %08x",
> -			base - DWC3_GLOBALS_REGS_START + offset,
> value); -
>  	return value;
>  }
>  
> @@ -56,14 +47,6 @@ static inline void dwc3_writel(void __iomem *base,
> u32 offset, u32 value)
>  	 * However, the offsets are given starting from xHCI address
> space. */
>  	writel(value, base + offs);
> -
> -	/*
> -	 * When tracing we want to make it easy to find the correct
> address on
> -	 * documentation, so we revert it back to the proper
> addresses, the
> -	 * same way they are described on SNPS documentation
> -	 */
> -	dwc3_trace(trace_dwc3_writel, "addr %p value %08x",
> -			base - DWC3_GLOBALS_REGS_START + offset,
> value); }
>  
>  #endif /* __DRIVERS_USB_DWC3_IO_H */

Review-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 11/40] usb: dwc3: fix dwc3 header files
  2015-02-06  8:47 ` [U-Boot] [u-boot 11/40] usb: dwc3: fix dwc3 header files Kishon Vijay Abraham I
@ 2015-02-16 10:25   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:25 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Changed the header files included in core.h and io.h to the u-boot
> header files so that these files can be included in other dwc3 source
> files and be compiled in uboot. Also added otg.h which has the
> defines for dr_mode.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.h |   13 ++-----------
>  drivers/usb/dwc3/io.h   |    4 +---
>  include/linux/usb/otg.h |   20 ++++++++++++++++++++
>  3 files changed, 23 insertions(+), 14 deletions(-)
>  create mode 100644 include/linux/usb/otg.h
> 
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 09cec53..a7a7082 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -18,20 +18,11 @@
>  #ifndef __DRIVERS_USB_DWC3_CORE_H
>  #define __DRIVERS_USB_DWC3_CORE_H
>  
> -#include <linux/device.h>
> -#include <linux/spinlock.h>
>  #include <linux/ioport.h>
> -#include <linux/list.h>
> -#include <linux/dma-mapping.h>
> -#include <linux/mm.h>
> -#include <linux/debugfs.h>
>  
>  #include <linux/usb/ch9.h>
> -#include <linux/usb/gadget.h>
>  #include <linux/usb/otg.h>
>  
> -#include <linux/phy/phy.h>
> -
>  #define DWC3_MSG_MAX	500
>  
>  /* Global constants */
> @@ -981,7 +972,7 @@ struct dwc3_gadget_ep_cmd_params {
>  void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
>  int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
>  
> -#if IS_ENABLED(CONFIG_USB_DWC3_HOST) ||
> IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) +#ifdef CONFIG_USB_DWC3_HOST
>  int dwc3_host_init(struct dwc3 *dwc);
>  void dwc3_host_exit(struct dwc3 *dwc);
>  #else
> @@ -991,7 +982,7 @@ static inline void dwc3_host_exit(struct dwc3
> *dwc) { }
>  #endif
>  
> -#if IS_ENABLED(CONFIG_USB_DWC3_GADGET) ||
> IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) +#ifdef CONFIG_USB_DWC3_GADGET
>  int dwc3_gadget_init(struct dwc3 *dwc);
>  void dwc3_gadget_exit(struct dwc3 *dwc);
>  int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
> diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
> index f9f22b0..b6da135 100644
> --- a/drivers/usb/dwc3/io.h
> +++ b/drivers/usb/dwc3/io.h
> @@ -18,9 +18,7 @@
>  #ifndef __DRIVERS_USB_DWC3_IO_H
>  #define __DRIVERS_USB_DWC3_IO_H
>  
> -#include <linux/io.h>
> -#include "debug.h"
> -#include "core.h"
> +#include <asm/io.h>
>  
>  static inline u32 dwc3_readl(void __iomem *base, u32 offset)
>  {
> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> new file mode 100644
> index 0000000..7ec5550
> --- /dev/null
> +++ b/include/linux/usb/otg.h
> @@ -0,0 +1,20 @@
> +/* include/linux/usb/otg.h
> + *
> + * Copyright (c) 2015 Texas Instruments Incorporated -
> http://www.ti.com
> + *
> + * USB OTG (On The Go) defines
> + *
> + * SPDX-License-Identifier:     GPL-2.0+
> + */
> +
> +#ifndef __LINUX_USB_OTG_H
> +#define __LINUX_USB_OTG_H
> +
> +enum usb_dr_mode {
> +	USB_DR_MODE_UNKNOWN,
> +	USB_DR_MODE_HOST,
> +	USB_DR_MODE_PERIPHERAL,
> +	USB_DR_MODE_OTG,
> +};
> +
> +#endif /* __LINUX_USB_OTG_H */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 12/40] usb: dwc3: remove pm related operations from dwc3 driver
  2015-02-06  8:47 ` [U-Boot] [u-boot 12/40] usb: dwc3: remove pm related operations from dwc3 driver Kishon Vijay Abraham I
@ 2015-02-16 10:26   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:26 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Removed all pm related operations including pm_runtime APIs,
> suspend/resume hooks as support for these are not present in u-boot.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.c      |   96
> ------------------------------------------
> drivers/usb/dwc3/core.h      |   16 -------
> drivers/usb/dwc3/dwc3-omap.c |   61 +++------------------------
> drivers/usb/dwc3/gadget.c    |   55 ------------------------ 4 files
> changed, 5 insertions(+), 223 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index b79a8b3..ebfb6ca 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -20,7 +20,6 @@
>  #include <linux/slab.h>
>  #include <linux/spinlock.h>
>  #include <linux/platform_device.h>
> -#include <linux/pm_runtime.h>
>  #include <linux/interrupt.h>
>  #include <linux/ioport.h>
>  #include <linux/io.h>
> @@ -884,10 +883,6 @@ static int dwc3_probe(struct platform_device
> *pdev) dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
>  	}
>  
> -	pm_runtime_enable(dev);
> -	pm_runtime_get_sync(dev);
> -	pm_runtime_forbid(dev);
> -
>  	dwc3_cache_hwparams(dwc);
>  
>  	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
> @@ -937,8 +932,6 @@ static int dwc3_probe(struct platform_device
> *pdev) goto err3;
>  	}
>  
> -	pm_runtime_allow(dev);
> -
>  	return 0;
>  
>  err3:
> @@ -980,97 +973,9 @@ static int dwc3_remove(struct platform_device
> *pdev) 
>  	dwc3_core_exit(dwc);
>  
> -	pm_runtime_put_sync(&pdev->dev);
> -	pm_runtime_disable(&pdev->dev);
> -
> -	return 0;
> -}
> -
> -#ifdef CONFIG_PM_SLEEP
> -static int dwc3_suspend(struct device *dev)
> -{
> -	struct dwc3	*dwc = dev_get_drvdata(dev);
> -	unsigned long	flags;
> -
> -	spin_lock_irqsave(&dwc->lock, flags);
> -
> -	switch (dwc->dr_mode) {
> -	case USB_DR_MODE_PERIPHERAL:
> -	case USB_DR_MODE_OTG:
> -		dwc3_gadget_suspend(dwc);
> -		/* FALLTHROUGH */
> -	case USB_DR_MODE_HOST:
> -	default:
> -		dwc3_event_buffers_cleanup(dwc);
> -		break;
> -	}
> -
> -	dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
> -	spin_unlock_irqrestore(&dwc->lock, flags);
> -
> -	usb_phy_shutdown(dwc->usb3_phy);
> -	usb_phy_shutdown(dwc->usb2_phy);
> -	phy_exit(dwc->usb2_generic_phy);
> -	phy_exit(dwc->usb3_generic_phy);
> -
>  	return 0;
>  }
>  
> -static int dwc3_resume(struct device *dev)
> -{
> -	struct dwc3	*dwc = dev_get_drvdata(dev);
> -	unsigned long	flags;
> -	int		ret;
> -
> -	usb_phy_init(dwc->usb3_phy);
> -	usb_phy_init(dwc->usb2_phy);
> -	ret = phy_init(dwc->usb2_generic_phy);
> -	if (ret < 0)
> -		return ret;
> -
> -	ret = phy_init(dwc->usb3_generic_phy);
> -	if (ret < 0)
> -		goto err_usb2phy_init;
> -
> -	spin_lock_irqsave(&dwc->lock, flags);
> -
> -	dwc3_event_buffers_setup(dwc);
> -	dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
> -
> -	switch (dwc->dr_mode) {
> -	case USB_DR_MODE_PERIPHERAL:
> -	case USB_DR_MODE_OTG:
> -		dwc3_gadget_resume(dwc);
> -		/* FALLTHROUGH */
> -	case USB_DR_MODE_HOST:
> -	default:
> -		/* do nothing */
> -		break;
> -	}
> -
> -	spin_unlock_irqrestore(&dwc->lock, flags);
> -
> -	pm_runtime_disable(dev);
> -	pm_runtime_set_active(dev);
> -	pm_runtime_enable(dev);
> -
> -	return 0;
> -
> -err_usb2phy_init:
> -	phy_exit(dwc->usb2_generic_phy);
> -
> -	return ret;
> -}
> -
> -static const struct dev_pm_ops dwc3_dev_pm_ops = {
> -	SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
> -};
> -
> -#define DWC3_PM_OPS	&(dwc3_dev_pm_ops)
> -#else
> -#define DWC3_PM_OPS	NULL
> -#endif
> -
>  #ifdef CONFIG_OF
>  static const struct of_device_id of_dwc3_match[] = {
>  	{
> @@ -1102,7 +1007,6 @@ static struct platform_driver dwc3_driver = {
>  		.name	= "dwc3",
>  		.of_match_table	= of_match_ptr(of_dwc3_match),
>  		.acpi_match_table = ACPI_PTR(dwc3_acpi_match),
> -		.pm	= DWC3_PM_OPS,
>  	},
>  };
>  
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index a7a7082..97f71ad 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1012,20 +1012,4 @@ static inline int
> dwc3_send_gadget_generic_command(struct dwc3 *dwc, { return 0; }
>  #endif
>  
> -/* power management interface */
> -#if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
> -int dwc3_gadget_suspend(struct dwc3 *dwc);
> -int dwc3_gadget_resume(struct dwc3 *dwc);
> -#else
> -static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
> -{
> -	return 0;
> -}
> -
> -static inline int dwc3_gadget_resume(struct dwc3 *dwc)
> -{
> -	return 0;
> -}
> -#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
> -
>  #endif /* __DRIVERS_USB_DWC3_CORE_H */
> diff --git a/drivers/usb/dwc3/dwc3-omap.c
> b/drivers/usb/dwc3/dwc3-omap.c index 12b57cf..ce2d6a6 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -20,7 +20,6 @@
>  #include <linux/interrupt.h>
>  #include <linux/platform_device.h>
>  #include <linux/platform_data/dwc3-omap.h>
> -#include <linux/pm_runtime.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/ioport.h>
>  #include <linux/io.h>
> @@ -509,13 +508,6 @@ static int dwc3_omap_probe(struct
> platform_device *pdev) omap->vbus_reg	= vbus_reg;
>  	dev->dma_mask	= &dwc3_omap_dma_mask;
>  
> -	pm_runtime_enable(dev);
> -	ret = pm_runtime_get_sync(dev);
> -	if (ret < 0) {
> -		dev_err(dev, "get_sync failed with err %d\n", ret);
> -		goto err0;
> -	}
> -
>  	dwc3_omap_map_offset(omap);
>  	dwc3_omap_set_utmi_mode(omap);
>  
> @@ -528,38 +520,33 @@ static int dwc3_omap_probe(struct
> platform_device *pdev) if (ret) {
>  		dev_err(dev, "failed to request IRQ #%d --> %d\n",
>  				omap->irq, ret);
> -		goto err1;
> +		goto err0;
>  	}
>  
>  	dwc3_omap_enable_irqs(omap);
>  
>  	ret = dwc3_omap_extcon_register(omap);
>  	if (ret < 0)
> -		goto err2;
> +		goto err1;
>  
>  	ret = of_platform_populate(node, NULL, NULL, dev);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to create dwc3 core\n");
> -		goto err3;
> +		goto err2;
>  	}
>  
>  	return 0;
>  
> -err3:
> +err2:
>  	if (omap->extcon_vbus_dev.edev)
>  		extcon_unregister_interest(&omap->extcon_vbus_dev);
>  	if (omap->extcon_id_dev.edev)
>  		extcon_unregister_interest(&omap->extcon_id_dev);
>  
> -err2:
> -	dwc3_omap_disable_irqs(omap);
> -
>  err1:
> -	pm_runtime_put_sync(dev);
> +	dwc3_omap_disable_irqs(omap);
>  
>  err0:
> -	pm_runtime_disable(dev);
> -
>  	return ret;
>  }
>  
> @@ -573,8 +560,6 @@ static int dwc3_omap_remove(struct
> platform_device *pdev)
> extcon_unregister_interest(&omap->extcon_id_dev);
> dwc3_omap_disable_irqs(omap); device_for_each_child(&pdev->dev, NULL,
> dwc3_omap_remove_core);
> -	pm_runtime_put_sync(&pdev->dev);
> -	pm_runtime_disable(&pdev->dev);
>  
>  	return 0;
>  }
> @@ -590,48 +575,12 @@ static const struct of_device_id
> of_dwc3_match[] = { };
>  MODULE_DEVICE_TABLE(of, of_dwc3_match);
>  
> -#ifdef CONFIG_PM_SLEEP
> -static int dwc3_omap_suspend(struct device *dev)
> -{
> -	struct dwc3_omap	*omap = dev_get_drvdata(dev);
> -
> -	omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap);
> -	dwc3_omap_disable_irqs(omap);
> -
> -	return 0;
> -}
> -
> -static int dwc3_omap_resume(struct device *dev)
> -{
> -	struct dwc3_omap	*omap = dev_get_drvdata(dev);
> -
> -	dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status);
> -	dwc3_omap_enable_irqs(omap);
> -
> -	pm_runtime_disable(dev);
> -	pm_runtime_set_active(dev);
> -	pm_runtime_enable(dev);
> -
> -	return 0;
> -}
> -
> -static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
> -
> -	SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
> -};
> -
> -#define DEV_PM_OPS	(&dwc3_omap_dev_pm_ops)
> -#else
> -#define DEV_PM_OPS	NULL
> -#endif /* CONFIG_PM_SLEEP */
> -
>  static struct platform_driver dwc3_omap_driver = {
>  	.probe		= dwc3_omap_probe,
>  	.remove		= dwc3_omap_remove,
>  	.driver		= {
>  		.name	= "omap-dwc3",
>  		.of_match_table	= of_dwc3_match,
> -		.pm	= DEV_PM_OPS,
>  	},
>  };
>  
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index ca0f0cd..7c932c6 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2748,58 +2748,3 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
>  	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
>  			dwc->ctrl_req, dwc->ctrl_req_addr);
>  }
> -
> -int dwc3_gadget_suspend(struct dwc3 *dwc)
> -{
> -	if (dwc->pullups_connected) {
> -		dwc3_gadget_disable_irq(dwc);
> -		dwc3_gadget_run_stop(dwc, true, true);
> -	}
> -
> -	__dwc3_gadget_ep_disable(dwc->eps[0]);
> -	__dwc3_gadget_ep_disable(dwc->eps[1]);
> -
> -	dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG);
> -
> -	return 0;
> -}
> -
> -int dwc3_gadget_resume(struct dwc3 *dwc)
> -{
> -	struct dwc3_ep		*dep;
> -	int			ret;
> -
> -	/* Start with SuperSpeed Default */
> -	dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
> -
> -	dep = dwc->eps[0];
> -	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc,
> NULL, false,
> -			false);
> -	if (ret)
> -		goto err0;
> -
> -	dep = dwc->eps[1];
> -	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc,
> NULL, false,
> -			false);
> -	if (ret)
> -		goto err1;
> -
> -	/* begin to receive SETUP packets */
> -	dwc->ep0state = EP0_SETUP_PHASE;
> -	dwc3_ep0_out_start(dwc);
> -
> -	dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg);
> -
> -	if (dwc->pullups_connected) {
> -		dwc3_gadget_enable_irq(dwc);
> -		dwc3_gadget_run_stop(dwc, true, false);
> -	}
> -
> -	return 0;
> -
> -err1:
> -	__dwc3_gadget_ep_disable(dwc->eps[0]);
> -
> -err0:
> -	return ret;
> -}

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>


-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 13/40] arm: asm: dma-mapping: added dma_free_coherent API
  2015-02-06  8:47 ` [U-Boot] [u-boot 13/40] arm: asm: dma-mapping: added dma_free_coherent API Kishon Vijay Abraham I
@ 2015-02-16 10:26   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:26 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added dma_free_coherent corresponding to the dma_alloc_coherent in
> dma-mapping.h in order to free memory allocated using
> dma_alloc_coherent. This API is used in dwc3 driver.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/include/asm/dma-mapping.h |    7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/arch/arm/include/asm/dma-mapping.h
> b/arch/arm/include/asm/dma-mapping.h index 14f00efd2..a5821f5 100644
> --- a/arch/arm/include/asm/dma-mapping.h
> +++ b/arch/arm/include/asm/dma-mapping.h
> @@ -8,6 +8,8 @@
>  #ifndef __ASM_ARM_DMA_MAPPING_H
>  #define __ASM_ARM_DMA_MAPPING_H
>  
> +#define	dma_mapping_error(x, y)	0
> +
>  enum dma_data_direction {
>  	DMA_BIDIRECTIONAL	= 0,
>  	DMA_TO_DEVICE		= 1,
> @@ -20,6 +22,11 @@ static inline void *dma_alloc_coherent(size_t len,
> unsigned long *handle) return (void *)*handle;
>  }
>  
> +static inline void dma_free_coherent(void *addr)
> +{
> +	free(addr);
> +}
> +
>  static inline unsigned long dma_map_single(volatile void *vaddr,
> size_t len, enum dma_data_direction dir)
>  {

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-06  8:47 ` [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy Kishon Vijay Abraham I
@ 2015-02-16 10:32   ` Lukasz Majewski
  2015-02-23  6:19     ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:32 UTC (permalink / raw)
  To: u-boot

Hi Kishon, Marek

> Added a header file to include various linux specific APIs like
> pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid compilation
> error while building dwc3 driver.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/linux-compat.h |   30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>  create mode 100644 drivers/usb/dwc3/linux-compat.h
> 
> diff --git a/drivers/usb/dwc3/linux-compat.h
> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
> index 0000000..58c4716
> --- /dev/null
> +++ b/drivers/usb/dwc3/linux-compat.h
> @@ -0,0 +1,30 @@
> +/**
> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy Adapter
> Header
> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com
> + *
> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
> + *
> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
> + * to uboot.
> + *
> + * SPDX-License-Identifier:	GPL-2.0
> + *
> + */
> +
> +#ifndef __DWC3_LINUX_COMPAT__
> +#define __DWC3_LINUX_COMPAT__
> +
> +#define pr_debug(format)                debug(format)
> +#define WARN(val, format, arg...)	debug(format, ##arg)
> +#define WARN_ON_ONCE(val)		debug("Error %d\n", val)
> +
> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
> +
> +static inline size_t strlcat(char *dest, const char *src, size_t n)
> +{
> +	strcat(dest, src);
> +	return strlen(dest) + strlen(src);
> +}
> +
> +#endif

Similar file has been already added to u-boot.
Please look into ./drivers/usb/musb-new/linux-compat.h

@Marek - maybe it is time to have a common one?

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 15/40] usb: dwc3: gadget: make dwc3 gadget build in uboot
  2015-02-06  8:47 ` [U-Boot] [u-boot 15/40] usb: dwc3: gadget: make dwc3 gadget build in uboot Kishon Vijay Abraham I
@ 2015-02-16 10:52   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:52 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Did a bunch of things to get dwc3/gadget.c compile in u-boot without
> build errors and warnings
> *) Changed the included header files to that used in u-boot.
> *) Used dma_alloc_coherent and dma_free_coherent APIs of u-boot
> *) removed sg support
> *) remove jiffies and used a simple while loop
> *) removed irq support and added a function to call these interrupt
> handler.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/gadget.c       |  244
> ++++++++++++++-------------------------
> drivers/usb/dwc3/gadget.h       |    1 +
> drivers/usb/dwc3/linux-compat.h |    3 -
> include/linux/compat.h          |    1 +
> include/linux/usb/gadget.h      |   39 +++++++ 5 files changed, 125
> insertions(+), 163 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 7c932c6..1f97729 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -14,25 +14,22 @@
>   * SPDX-License-Identifier:     GPL-2.0
>   */
>  
> -#include <linux/kernel.h>
> -#include <linux/delay.h>
> -#include <linux/slab.h>
> -#include <linux/spinlock.h>
> -#include <linux/platform_device.h>
> -#include <linux/pm_runtime.h>
> -#include <linux/interrupt.h>
> -#include <linux/io.h>
> +#include <common.h>
> +#include <malloc.h>
> +#include <asm/dma-mapping.h>
> +#include <usb/lin_gadget_compat.h>
>  #include <linux/list.h>
> -#include <linux/dma-mapping.h>
>  
>  #include <linux/usb/ch9.h>
>  #include <linux/usb/gadget.h>
> +#include <asm/arch/sys_proto.h>
>  
> -#include "debug.h"
>  #include "core.h"
>  #include "gadget.h"
>  #include "io.h"
>  
> +#include "linux-compat.h"
> +
>  /**
>   * dwc3_gadget_set_test_mode - Enables USB2 Test Modes
>   * @dwc: pointer to our context structure
> @@ -166,7 +163,6 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc,
> enum dwc3_link_state state) int dwc3_gadget_resize_tx_fifos(struct
> dwc3 *dwc) {
>  	int		last_fifo_depth = 0;
> -	int		ram1_depth;
>  	int		fifo_size;
>  	int		mdwidth;
>  	int		num;
> @@ -174,7 +170,6 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
>  	if (!dwc->needs_fifo_resize)
>  		return 0;
>  
> -	ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7);
>  	mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
>  
>  	/* MDWIDTH is represented in bits, we need it in bytes */
> @@ -232,24 +227,21 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep,
> struct dwc3_request *req, int status)
>  {
>  	struct dwc3			*dwc = dep->dwc;
> -	int				i;
>  
>  	if (req->queued) {
> -		i = 0;
> -		do {
> +		dep->busy_slot++;
> +		/*
> +		 * Skip LINK TRB. We can't use req->trb and check for
> +		 * DWC3_TRBCTL_LINK_TRB because it points the TRB we
> +		 * just completed (not the LINK TRB).
> +		 */
> +		if (((dep->busy_slot & DWC3_TRB_MASK) ==
> +			DWC3_TRB_NUM- 1) &&
> +			usb_endpoint_xfer_isoc(dep->endpoint.desc))
>  			dep->busy_slot++;
> -			/*
> -			 * Skip LINK TRB. We can't use req->trb and
> check for
> -			 * DWC3_TRBCTL_LINK_TRB because it points
> the TRB we
> -			 * just completed (not the LINK TRB).
> -			 */
> -			if (((dep->busy_slot & DWC3_TRB_MASK) ==
> -				DWC3_TRB_NUM- 1) &&
> -
> usb_endpoint_xfer_isoc(dep->endpoint.desc))
> -				dep->busy_slot++;
> -		} while(++i < req->request.num_mapped_sgs);
>  		req->queued = false;
>  	}
> +
>  	list_del(&req->list);
>  	req->trb = NULL;
>  
> @@ -301,7 +293,6 @@ int dwc3_send_gadget_generic_command(struct dwc3
> *dwc, unsigned cmd, u32 param) int dwc3_send_gadget_ep_cmd(struct
> dwc3 *dwc, unsigned ep, unsigned cmd, struct
> dwc3_gadget_ep_cmd_params *params) {
> -	struct dwc3_ep		*dep = dwc->eps[ep];
>  	u32			timeout = 500;
>  	u32			reg;
>  
> @@ -340,17 +331,15 @@ static dma_addr_t dwc3_trb_dma_offset(struct
> dwc3_ep *dep, 
>  static int dwc3_alloc_trb_pool(struct dwc3_ep *dep)
>  {
> -	struct dwc3		*dwc = dep->dwc;
> -
>  	if (dep->trb_pool)
>  		return 0;
>  
>  	if (dep->number == 0 || dep->number == 1)
>  		return 0;
>  
> -	dep->trb_pool = dma_alloc_coherent(dwc->dev,
> -			sizeof(struct dwc3_trb) * DWC3_TRB_NUM,
> -			&dep->trb_pool_dma, GFP_KERNEL);
> +	dep->trb_pool = dma_alloc_coherent(sizeof(struct dwc3_trb) *
> +					   DWC3_TRB_NUM,
> +					   (unsigned long
> *)&dep->trb_pool_dma); if (!dep->trb_pool) {
>  		dev_err(dep->dwc->dev, "failed to allocate trb pool
> for %s\n", dep->name);
> @@ -362,10 +351,7 @@ static int dwc3_alloc_trb_pool(struct dwc3_ep
> *dep) 
>  static void dwc3_free_trb_pool(struct dwc3_ep *dep)
>  {
> -	struct dwc3		*dwc = dep->dwc;
> -
> -	dma_free_coherent(dwc->dev, sizeof(struct dwc3_trb) *
> DWC3_TRB_NUM,
> -			dep->trb_pool, dep->trb_pool_dma);
> +	dma_free_coherent(dep->trb_pool);
>  
>  	dep->trb_pool = NULL;
>  	dep->trb_pool_dma = 0;
> @@ -607,7 +593,6 @@ static int dwc3_gadget_ep_enable(struct usb_ep
> *ep, const struct usb_endpoint_descriptor *desc)
>  {
>  	struct dwc3_ep			*dep;
> -	struct dwc3			*dwc;
>  	unsigned long			flags;
>  	int				ret;
>  
> @@ -622,10 +607,9 @@ static int dwc3_gadget_ep_enable(struct usb_ep
> *ep, }
>  
>  	dep = to_dwc3_ep(ep);
> -	dwc = dep->dwc;
>  
>  	if (dep->flags & DWC3_EP_ENABLED) {
> -		dev_WARN_ONCE(dwc->dev, true, "%s is already
> enabled\n",
> +		WARN(true, "%s is already enabled\n",
>  				dep->name);
>  		return 0;
>  	}
> @@ -657,7 +641,6 @@ static int dwc3_gadget_ep_enable(struct usb_ep
> *ep, static int dwc3_gadget_ep_disable(struct usb_ep *ep)
>  {
>  	struct dwc3_ep			*dep;
> -	struct dwc3			*dwc;
>  	unsigned long			flags;
>  	int				ret;
>  
> @@ -667,10 +650,9 @@ static int dwc3_gadget_ep_disable(struct usb_ep
> *ep) }
>  
>  	dep = to_dwc3_ep(ep);
> -	dwc = dep->dwc;
>  
>  	if (!(dep->flags & DWC3_EP_ENABLED)) {
> -		dev_WARN_ONCE(dwc->dev, true, "%s is already
> disabled\n",
> +		WARN(true, "%s is already disabled\n",
>  				dep->name);
>  		return 0;
>  	}
> @@ -719,7 +701,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep
> *dep, struct dwc3_request *req, dma_addr_t dma,
>  		unsigned length, unsigned last, unsigned chain,
> unsigned node) {
> -	struct dwc3		*dwc = dep->dwc;
>  	struct dwc3_trb		*trb;
>  
>  	dev_vdbg(dwc->dev, "%s: req %p dma %08llx length %d%s%s\n",
> @@ -856,57 +837,22 @@ static void dwc3_prepare_trbs(struct dwc3_ep
> *dep, bool starting) dma_addr_t	dma;
>  		last_one = false;
>  
> -		if (req->request.num_mapped_sgs > 0) {
> -			struct usb_request *request = &req->request;
> -			struct scatterlist *sg = request->sg;
> -			struct scatterlist *s;
> -			int		i;
> -
> -			for_each_sg(sg, s, request->num_mapped_sgs,
> i) {
> -				unsigned chain = true;
> +		dma = req->request.dma;
> +		length = req->request.length;
> +		trbs_left--;
>  
> -				length = sg_dma_len(s);
> -				dma = sg_dma_address(s);
> +		if (!trbs_left)
> +			last_one = 1;
>  
> -				if (i == (request->num_mapped_sgs -
> 1) ||
> -						sg_is_last(s)) {
> -					if (list_is_last(&req->list,
> -
> &dep->request_list))
> -						last_one = true;
> -					chain = false;
> -				}
> +		/* Is this the last request? */
> +		if (list_is_last(&req->list, &dep->request_list))
> +			last_one = 1;
>  
> -				trbs_left--;
> -				if (!trbs_left)
> -					last_one = true;
> +		dwc3_prepare_one_trb(dep, req, dma, length,
> +				last_one, false, 0);
>  
> -				if (last_one)
> -					chain = false;
> -
> -				dwc3_prepare_one_trb(dep, req, dma,
> length,
> -						last_one, chain, i);
> -
> -				if (last_one)
> -					break;
> -			}
> -		} else {
> -			dma = req->request.dma;
> -			length = req->request.length;
> -			trbs_left--;
> -
> -			if (!trbs_left)
> -				last_one = 1;
> -
> -			/* Is this the last request? */
> -			if (list_is_last(&req->list,
> &dep->request_list))
> -				last_one = 1;
> -
> -			dwc3_prepare_one_trb(dep, req, dma, length,
> -					last_one, false, 0);
> -
> -			if (last_one)
> -				break;
> -		}
> +		if (last_one)
> +			break;
>  	}
>  }
>  
> @@ -1103,8 +1049,6 @@ static int __dwc3_gadget_ep_queue(struct
> dwc3_ep *dep, struct dwc3_request *req) 
>  		ret = __dwc3_gadget_kick_transfer(dep, 0, true);
>  		if (ret && ret != -EBUSY) {
> -			struct dwc3	*dwc = dep->dwc;
> -
>  			dev_dbg(dwc->dev, "%s: failed to kick
> transfers\n", dep->name);
>  		}
> @@ -1118,7 +1062,6 @@ static int dwc3_gadget_ep_queue(struct usb_ep
> *ep, struct usb_request *request, {
>  	struct dwc3_request		*req =
> to_dwc3_request(request); struct dwc3_ep			*dep
> = to_dwc3_ep(ep);
> -	struct dwc3			*dwc = dep->dwc;
>  
>  	unsigned long			flags;
>  
> @@ -1132,8 +1075,9 @@ static int dwc3_gadget_ep_queue(struct usb_ep
> *ep, struct usb_request *request, goto out;
>  	}
>  
> -	if (WARN(req->dep != dep, "request %p belongs to '%s'\n",
> -				request, req->dep->name)) {
> +	if (req->dep != dep) {
> +		WARN(true, "request %p belongs to '%s'\n",
> +				request, req->dep->name);
>  		ret = -EINVAL;
>  		goto out;
>  	}
> @@ -1239,7 +1183,6 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep
> *dep, int value, int protocol) static int
> dwc3_gadget_ep_set_halt(struct usb_ep *ep, int value) {
>  	struct dwc3_ep			*dep = to_dwc3_ep(ep);
> -	struct dwc3			*dwc = dep->dwc;
>  
>  	unsigned long			flags;
>  
> @@ -1255,7 +1198,6 @@ static int dwc3_gadget_ep_set_halt(struct
> usb_ep *ep, int value) static int dwc3_gadget_ep_set_wedge(struct
> usb_ep *ep) {
>  	struct dwc3_ep			*dep = to_dwc3_ep(ep);
> -	struct dwc3			*dwc = dep->dwc;
>  	unsigned long			flags;
>  	int				ret;
>  
> @@ -1371,9 +1313,9 @@ static int dwc3_gadget_wakeup(struct usb_gadget
> *g) }
>  
>  	/* poll until Link State changes to ON */
> -	timeout = jiffies + msecs_to_jiffies(100);
> +	timeout = 1000;
>  
> -	while (!time_after(jiffies, timeout)) {
> +	while (timeout--) {
>  		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
>  
>  		/* in HS, means ON */
> @@ -1498,9 +1440,6 @@ static void dwc3_gadget_disable_irq(struct dwc3
> *dwc) dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
>  }
>  
> -static irqreturn_t dwc3_interrupt(int irq, void *_dwc);
> -static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc);
> -
>  static int dwc3_gadget_start(struct usb_gadget *g,
>  		struct usb_gadget_driver *driver)
>  {
> @@ -1508,24 +1447,14 @@ static int dwc3_gadget_start(struct
> usb_gadget *g, struct dwc3_ep		*dep;
>  	unsigned long		flags;
>  	int			ret = 0;
> -	int			irq;
>  	u32			reg;
>  
> -	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
> -	ret = request_threaded_irq(irq, dwc3_interrupt,
> dwc3_thread_interrupt,
> -			IRQF_SHARED, "dwc3", dwc);
> -	if (ret) {
> -		dev_err(dwc->dev, "failed to request irq #%d -->
> %d\n",
> -				irq, ret);
> -		goto err0;
> -	}
> -
>  	spin_lock_irqsave(&dwc->lock, flags);
>  
>  	if (dwc->gadget_driver) {
>  		dev_err(dwc->dev, "%s is already bound to %s\n",
>  				dwc->gadget.name,
> -				dwc->gadget_driver->driver.name);
> +				dwc->gadget_driver->function);
>  		ret = -EBUSY;
>  		goto err1;
>  	}
> @@ -1609,9 +1538,6 @@ err2:
>  err1:
>  	spin_unlock_irqrestore(&dwc->lock, flags);
>  
> -	free_irq(irq, dwc);
> -
> -err0:
>  	return ret;
>  }
>  
> @@ -1619,7 +1545,6 @@ static int dwc3_gadget_stop(struct usb_gadget
> *g) {
>  	struct dwc3		*dwc = gadget_to_dwc(g);
>  	unsigned long		flags;
> -	int			irq;
>  
>  	spin_lock_irqsave(&dwc->lock, flags);
>  
> @@ -1631,9 +1556,6 @@ static int dwc3_gadget_stop(struct usb_gadget
> *g) 
>  	spin_unlock_irqrestore(&dwc->lock, flags);
>  
> -	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
> -	free_irq(irq, dwc);
> -
>  	return 0;
>  }
>  
> @@ -1832,7 +1754,6 @@ static int dwc3_cleanup_done_reqs(struct dwc3
> *dwc, struct dwc3_ep *dep, struct dwc3_request	*req;
>  	struct dwc3_trb		*trb;
>  	unsigned int		slot;
> -	unsigned int		i;
>  	int			ret;
>  
>  	do {
> @@ -1841,20 +1762,18 @@ static int dwc3_cleanup_done_reqs(struct dwc3
> *dwc, struct dwc3_ep *dep, WARN_ON_ONCE(1);
>  			return 1;
>  		}
> -		i = 0;
> -		do {
> -			slot = req->start_slot + i;
> -			if ((slot == DWC3_TRB_NUM - 1) &&
> -
> usb_endpoint_xfer_isoc(dep->endpoint.desc))
> -				slot++;
> -			slot %= DWC3_TRB_NUM;
> -			trb = &dep->trb_pool[slot];
> -
> -			ret = __dwc3_cleanup_done_trbs(dwc, dep,
> req, trb,
> -					event, status);
> -			if (ret)
> -				break;
> -		}while (++i < req->request.num_mapped_sgs);
> +
> +		slot = req->start_slot;
> +		if ((slot == DWC3_TRB_NUM - 1) &&
> +			usb_endpoint_xfer_isoc(dep->endpoint.desc))
> +			slot++;
> +		slot %= DWC3_TRB_NUM;
> +		trb = &dep->trb_pool[slot];
> +
> +		ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
> +				event, status);
> +		if (ret)
> +			break;
>  
>  		dwc3_gadget_giveback(dep, req, status);
>  
> @@ -2293,9 +2212,8 @@ static void
> dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
>  		 * BESL value in the LPM token is less than or equal
> to LPM
>  		 * NYET threshold.
>  		 */
> -		WARN_ONCE(dwc->revision < DWC3_REVISION_240A
> -				&& dwc->has_lpm_erratum,
> -				"LPM Erratum not available on dwc3
> revisisions < 2.40a\n");
> +		if (dwc->revision < DWC3_REVISION_240A 	&&
> dwc->has_lpm_erratum)
> +			WARN(true, "LPM Erratum not available on
> dwc3 revisisions < 2.40a\n"); 
>  		if (dwc->has_lpm_erratum && dwc->revision >=
> DWC3_REVISION_240A) reg |=
> DWC3_DCTL_LPM_ERRATA(dwc->lpm_nyet_threshold); @@ -2482,10 +2400,10
> @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc,
> dwc3_gadget_wakeup_interrupt(dwc); break;
>  	case DWC3_DEVICE_EVENT_HIBER_REQ:
> -		if (dev_WARN_ONCE(dwc->dev, !dwc->has_hibernation,
> -					"unexpected hibernation
> event\n"))
> +		if (!dwc->has_hibernation) {
> +			WARN(1 ,"unexpected hibernation event\n");
>  			break;
> -
> +		}
>  		dwc3_gadget_hibernation_interrupt(dwc,
> event->event_info); break;
>  	case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
> @@ -2649,16 +2567,16 @@ int dwc3_gadget_init(struct dwc3 *dwc)
>  {
>  	int					ret;
>  
> -	dwc->ctrl_req = dma_alloc_coherent(dwc->dev,
> sizeof(*dwc->ctrl_req),
> -			&dwc->ctrl_req_addr, GFP_KERNEL);
> +	dwc->ctrl_req = dma_alloc_coherent(sizeof(*dwc->ctrl_req),
> +					(unsigned long
> *)&dwc->ctrl_req_addr); if (!dwc->ctrl_req) {
>  		dev_err(dwc->dev, "failed to allocate ctrl
> request\n"); ret = -ENOMEM;
>  		goto err0;
>  	}
>  
> -	dwc->ep0_trb = dma_alloc_coherent(dwc->dev,
> sizeof(*dwc->ep0_trb),
> -			&dwc->ep0_trb_addr, GFP_KERNEL);
> +	dwc->ep0_trb = dma_alloc_coherent(sizeof(*dwc->ep0_trb),
> +					  (unsigned long
> *)&dwc->ep0_trb_addr); if (!dwc->ep0_trb) {
>  		dev_err(dwc->dev, "failed to allocate ep0 trb\n");
>  		ret = -ENOMEM;
> @@ -2671,9 +2589,8 @@ int dwc3_gadget_init(struct dwc3 *dwc)
>  		goto err2;
>  	}
>  
> -	dwc->ep0_bounce = dma_alloc_coherent(dwc->dev,
> -			DWC3_EP0_BOUNCE_SIZE, &dwc->ep0_bounce_addr,
> -			GFP_KERNEL);
> +	dwc->ep0_bounce = dma_alloc_coherent(DWC3_EP0_BOUNCE_SIZE,
> +					(unsigned long
> *)&dwc->ep0_bounce_addr); if (!dwc->ep0_bounce) {
>  		dev_err(dwc->dev, "failed to allocate ep0 bounce
> buffer\n"); ret = -ENOMEM;
> @@ -2683,7 +2600,6 @@ int dwc3_gadget_init(struct dwc3 *dwc)
>  	dwc->gadget.ops			= &dwc3_gadget_ops;
>  	dwc->gadget.max_speed		= USB_SPEED_SUPER;
>  	dwc->gadget.speed		= USB_SPEED_UNKNOWN;
> -	dwc->gadget.sg_supported	= true;
>  	dwc->gadget.name		= "dwc3-gadget";
>  
>  	/*
> @@ -2711,19 +2627,16 @@ int dwc3_gadget_init(struct dwc3 *dwc)
>  
>  err4:
>  	dwc3_gadget_free_endpoints(dwc);
> -	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
> -			dwc->ep0_bounce, dwc->ep0_bounce_addr);
> +	dma_free_coherent(dwc->ep0_bounce);
>  
>  err3:
>  	kfree(dwc->setup_buf);
>  
>  err2:
> -	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
> -			dwc->ep0_trb, dwc->ep0_trb_addr);
> +	dma_free_coherent(dwc->ep0_trb);
>  
>  err1:
> -	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
> -			dwc->ctrl_req, dwc->ctrl_req_addr);
> +	dma_free_coherent(dwc->ctrl_req);
>  
>  err0:
>  	return ret;
> @@ -2737,14 +2650,25 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
>  
>  	dwc3_gadget_free_endpoints(dwc);
>  
> -	dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE,
> -			dwc->ep0_bounce, dwc->ep0_bounce_addr);
> +	dma_free_coherent(dwc->ep0_bounce);
>  
>  	kfree(dwc->setup_buf);
>  
> -	dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb),
> -			dwc->ep0_trb, dwc->ep0_trb_addr);
> +	dma_free_coherent(dwc->ep0_trb);
>  
> -	dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
> -			dwc->ctrl_req, dwc->ctrl_req_addr);
> +	dma_free_coherent(dwc->ctrl_req);
> +}
> +
> +/**
> + * dwc3_gadget_uboot_handle_interrupt - handle dwc3 gadget interrupt
> + * @dwc: struct dwce *
> + *
> + * Handles ep0 and gadget interrupt
> + *
> + * Should be called from dwc3 core.
> + */
> +void dwc3_gadget_uboot_handle_interrupt(struct dwc3 *dwc)
> +{
> +	dwc3_interrupt(0, dwc);
> +	dwc3_thread_interrupt(0, dwc);
>  }
> diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
> index 042e247..c7db219 100644
> --- a/drivers/usb/dwc3/gadget.h
> +++ b/drivers/usb/dwc3/gadget.h
> @@ -87,6 +87,7 @@ int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int
> value); int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct
> usb_request *request, gfp_t gfp_flags);
>  int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int
> protocol); +void dwc3_gadget_uboot_handle_interrupt(struct dwc3 *dwc);
>  
>  /**
>   * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
> diff --git a/drivers/usb/dwc3/linux-compat.h
> b/drivers/usb/dwc3/linux-compat.h index 58c4716..719e82e 100644
> --- a/drivers/usb/dwc3/linux-compat.h
> +++ b/drivers/usb/dwc3/linux-compat.h
> @@ -5,9 +5,6 @@
>   *
>   * Authors: Kishon Vijay Abraham I <kishon@ti.com>
>   *
> - * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
> - * to uboot.
> - *
>   * SPDX-License-Identifier:	GPL-2.0
>   *
>   */
> diff --git a/include/linux/compat.h b/include/linux/compat.h
> index b40133c..904425a 100644
> --- a/include/linux/compat.h
> +++ b/include/linux/compat.h
> @@ -327,6 +327,7 @@ typedef unsigned long dmaaddr_t;
>  
>  #define IRQ_NONE 0
>  #define IRQ_HANDLED 1
> +#define IRQ_WAKE_THREAD 2
>  
>  #define dev_set_drvdata(dev, data) do {} while (0)
>  
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index 1960958..93a5ffc 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -31,6 +31,7 @@ struct usb_ep;
>   * @dma: DMA address corresponding to 'buf'.  If you don't set this
>   *	field, and the usb controller needs one, it is responsible
>   *	for mapping and unmapping the buffer.
> + * @stream_id: The stream id, when USB3.0 bulk streams are being used
>   * @length: Length of that data
>   * @no_interrupt: If true, hints that no completion irq is needed.
>   *	Helpful sometimes with deep request queues that are handled
> @@ -85,6 +86,7 @@ struct usb_request {
>  	unsigned		length;
>  	dma_addr_t		dma;
>  
> +	unsigned		stream_id:16;
>  	unsigned		no_interrupt:1;
>  	unsigned		zero:1;
>  	unsigned		short_not_ok:1;
> @@ -121,6 +123,7 @@ struct usb_ep_ops {
>  	int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
>  
>  	int (*set_halt) (struct usb_ep *ep, int value);
> +	int (*set_wedge)(struct usb_ep *ep);
>  	int (*fifo_status) (struct usb_ep *ep);
>  	void (*fifo_flush) (struct usb_ep *ep);
>  };
> @@ -133,8 +136,18 @@ struct usb_ep_ops {
>   * @maxpacket:The maximum packet size used on this endpoint.  The
> initial
>   *	value can sometimes be reduced (hardware allowing),
> according to
>   *      the endpoint descriptor used to configure the endpoint.
> + * @maxpacket_limit:The maximum packet size value which can be
> handled by this
> + *	endpoint. It's set once by UDC driver when endpoint is
> initialized, and
> + *	should not be changed. Should not be confused with
> maxpacket.
> + * @max_streams: The maximum number of streams supported
> + * 	by this EP (0 - 16, actual number is 2^n)
> + * @maxburst: the maximum number of bursts supported by this EP (for
> usb3)
>   * @driver_data:for use by the gadget driver.  all other fields are
>   *	read-only to gadget drivers.
> + * @desc: endpoint descriptor.  This pointer is set before the
> endpoint is
> + * 	enabled and remains valid until the endpoint is disabled.
> + * @comp_desc: In case of SuperSpeed support, this is the endpoint
> companion
> + * 	descriptor that is used to configure the endpoint
>   *
>   * the bus controller driver lists all the general purpose endpoints
> in
>   * gadget->ep_list.  the control endpoint (gadget->ep0) is not in
> that list, @@ -146,11 +159,31 @@ struct usb_ep {
>  	const struct usb_ep_ops	*ops;
>  	struct list_head	ep_list;
>  	unsigned		maxpacket:16;
> +	unsigned		maxpacket_limit:16;
> +	unsigned		max_streams:16;
> +	unsigned		maxburst:5;
> +	const struct usb_endpoint_descriptor	*desc;
> +	const struct usb_ss_ep_comp_descriptor	*comp_desc;
>  };
>  
>  /*-------------------------------------------------------------------------*/
>  
>  /**
> + * usb_ep_set_maxpacket_limit - set maximum packet size limit for
> endpoint
> + * @ep:the endpoint being configured
> + * @maxpacket_limit:value of maximum packet size limit
> + *
> + * This function shoud be used only in UDC drivers to initialize
> endpoint
> + * (usually in probe function).
> + */
> +static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
> +					      unsigned
> maxpacket_limit) +{
> +	ep->maxpacket_limit = maxpacket_limit;
> +	ep->maxpacket = maxpacket_limit;
> +}
> +
> +/**
>   * usb_ep_enable - configure endpoint, making it usable
>   * @ep:the endpoint being configured.  may not be the endpoint named
> "ep0".
>   *	drivers discover endpoints through the ep_list of a
> usb_gadget. @@ -422,6 +455,8 @@ struct usb_gadget_ops {
>   *	driver setup() requests
>   * @ep_list: List of other endpoints supported by the device.
>   * @speed: Speed of current connection to USB host.
> + * @max_speed: Maximal speed the UDC can handle.  UDC must support
> this
> + *      and all slower speeds.
>   * @is_dualspeed: true if the controller supports both high and full
> speed
>   *	operation.  If it does, the gadget driver must also
> support both.
>   * @is_otg: true if the USB device port uses a Mini-AB jack, so that
> the @@ -438,6 +473,8 @@ struct usb_gadget_ops {
>   * @name: Identifies the controller hardware type.  Used in
> diagnostics
>   *	and sometimes configuration.
>   * @dev: Driver model state for this abstract device.
> + * @quirk_ep_out_aligned_size: epout requires buffer size to be
> aligned to
> + *	MaxPacketSize.
>   *
>   * Gadgets have a mostly-portable "gadget driver" implementing device
>   * functions, handling all usb configurations and interfaces.  Gadget
> @@ -463,6 +500,7 @@ struct usb_gadget {
>  	struct usb_ep			*ep0;
>  	struct list_head		ep_list;	/* of usb_ep
> */ enum usb_device_speed		speed;
> +	enum usb_device_speed		max_speed;
>  	enum usb_device_state		state;
>  	unsigned			is_dualspeed:1;
>  	unsigned			is_otg:1;
> @@ -472,6 +510,7 @@ struct usb_gadget {
>  	unsigned			a_alt_hnp_support:1;
>  	const char			*name;
>  	struct device			dev;
> +	unsigned			quirk_ep_out_aligned_size:1;
>  };
>  
>  static inline void set_gadget_data(struct usb_gadget *gadget, void
> *data)

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 16/40] include: asm: types: add resource_size_t type
  2015-02-06  8:47 ` [U-Boot] [u-boot 16/40] include: asm: types: add resource_size_t type Kishon Vijay Abraham I
@ 2015-02-16 10:53   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:53 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added resource_size_t type in order to get rid of the following
> compilation error whiel building dwc3 gadget.
> include/linux/ioport.h:19:2: error: unknown type name
> ?resource_size_t?
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/include/asm/types.h |    1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/include/asm/types.h
> b/arch/arm/include/asm/types.h index 2326420..ee77c41 100644
> --- a/arch/arm/include/asm/types.h
> +++ b/arch/arm/include/asm/types.h
> @@ -54,4 +54,5 @@ typedef unsigned long phys_size_t;
>  
>  #endif /* __KERNEL__ */
>  
> +typedef unsigned long resource_size_t;
>  #endif

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 17/40] usb: dwc3: ep0: make dwc3 ep0 build in uboot
  2015-02-06  8:47 ` [U-Boot] [u-boot 17/40] usb: dwc3: ep0: make dwc3 ep0 build in uboot Kishon Vijay Abraham I
@ 2015-02-16 10:54   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:54 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> *) Changed the included header files to that used in u-boot.
> *) added dwc3_ep_event_string() used in ep0.c
> *) Fixed other misc warnings
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.h         |   24 ++++++++++++++++++++++++
>  drivers/usb/dwc3/ep0.c          |   14 ++------------
>  drivers/usb/dwc3/linux-compat.h |    1 +
>  3 files changed, 27 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 97f71ad..0ffcb7d 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -841,6 +841,30 @@ struct dwc3_event_type {
>  #define DWC3_DEPEVT_EPCMDCMPLT		0x07
>  
>  /**
> + * dwc3_ep_event_string - returns event name
> + * @event: then event code
> + */
> +static inline const char *dwc3_ep_event_string(u8 event)
> +{
> +	switch (event) {
> +	case DWC3_DEPEVT_XFERCOMPLETE:
> +		return "Transfer Complete";
> +	case DWC3_DEPEVT_XFERINPROGRESS:
> +		return "Transfer In-Progress";
> +	case DWC3_DEPEVT_XFERNOTREADY:
> +		return "Transfer Not Ready";
> +	case DWC3_DEPEVT_RXTXFIFOEVT:
> +		return "FIFO";
> +	case DWC3_DEPEVT_STREAMEVT:
> +		return "Stream";
> +	case DWC3_DEPEVT_EPCMDCMPLT:
> +		return "Endpoint Command Complete";
> +	}
> +
> +	return "UNKNOWN";
> +}
> +
> +/**
>   * struct dwc3_event_depvt - Device Endpoint Events
>   * @one_bit: indicates this is an endpoint event (not used)
>   * @endpoint_number: number of the endpoint
> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index 1751b1d..803ba51 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -15,24 +15,18 @@
>   */
>  
>  #include <linux/kernel.h>
> -#include <linux/slab.h>
> -#include <linux/spinlock.h>
> -#include <linux/platform_device.h>
> -#include <linux/pm_runtime.h>
> -#include <linux/interrupt.h>
> -#include <linux/io.h>
>  #include <linux/list.h>
> -#include <linux/dma-mapping.h>
>  
>  #include <linux/usb/ch9.h>
>  #include <linux/usb/gadget.h>
>  #include <linux/usb/composite.h>
>  
>  #include "core.h"
> -#include "debug.h"
>  #include "gadget.h"
>  #include "io.h"
>  
> +#include "linux-compat.h"
> +
>  static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct
> dwc3_ep *dep); static void __dwc3_ep0_do_control_data(struct dwc3
> *dwc, struct dwc3_ep *dep, struct dwc3_request *req);
> @@ -277,8 +271,6 @@ int __dwc3_gadget_ep0_set_halt(struct usb_ep *ep,
> int value) 
>  int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value)
>  {
> -	struct dwc3_ep			*dep = to_dwc3_ep(ep);
> -	struct dwc3			*dwc = dep->dwc;
>  	unsigned long			flags;
>  	int				ret;
>  
> @@ -632,12 +624,10 @@ static int dwc3_ep0_set_sel(struct dwc3 *dwc,
> struct usb_ctrlrequest *ctrl) struct dwc3_ep	*dep;
>  	enum usb_device_state state = dwc->gadget.state;
>  	u16		wLength;
> -	u16		wValue;
>  
>  	if (state == USB_STATE_DEFAULT)
>  		return -EINVAL;
>  
> -	wValue = le16_to_cpu(ctrl->wValue);
>  	wLength = le16_to_cpu(ctrl->wLength);
>  
>  	if (wLength != 6) {
> diff --git a/drivers/usb/dwc3/linux-compat.h
> b/drivers/usb/dwc3/linux-compat.h index 719e82e..cbfb946 100644
> --- a/drivers/usb/dwc3/linux-compat.h
> +++ b/drivers/usb/dwc3/linux-compat.h
> @@ -14,6 +14,7 @@
>  
>  #define pr_debug(format)                debug(format)
>  #define WARN(val, format, arg...)	debug(format, ##arg)
> +#define dev_WARN(dev, format, arg...)	debug(format, ##arg)
>  #define WARN_ON_ONCE(val)		debug("Error %d\n", val)
>  
>  #define BUILD_BUG_ON_NOT_POWER_OF_2(n)

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 18/40] include: usb: composite: add USB_GADGET_DELAYED_STATUS to avoid compilation error
  2015-02-06  8:47 ` [U-Boot] [u-boot 18/40] include: usb: composite: add USB_GADGET_DELAYED_STATUS to avoid compilation error Kishon Vijay Abraham I
@ 2015-02-16 10:55   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:55 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added USB_GADGET_DELAYED_STATUS to avoid the following compilation
> error. error: ?USB_GADGET_DELAYED_STATUS? undeclared (first use in
> this function) while compiling dwc3/ep0.c
> 
> While this is been added only to avoid compilation error, the
> complete fix should be something like the one added in linux kernel.
> The complete fix will be ported once we have the composite driver in
> u-boot look similar to the one in linux kernel.
> commit 1b9ba000177ee47bcc5b44c7c34e48e735f5f9b1
> Author: Roger Quadros <roger.quadros@nokia.com>
> Date:   Mon May 9 13:08:06 2011 +0300
> 
>     usb: gadget: composite: Allow function drivers to pause control
> transfers
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  include/linux/usb/composite.h |    9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/include/linux/usb/composite.h
> b/include/linux/usb/composite.h index f833d10..86e1cea 100644
> --- a/include/linux/usb/composite.h
> +++ b/include/linux/usb/composite.h
> @@ -27,6 +27,15 @@
>  #include <linux/usb/gadget.h>
>  #include <usb/lin_gadget_compat.h>
>  
> +/*
> + * USB function drivers should return USB_GADGET_DELAYED_STATUS if
> they
> + * wish to delay the data/status stages of the control transfer till
> they
> + * are ready. The control transfer will then be kept from completing
> till
> + * all the function drivers that requested for
> USB_GADGET_DELAYED_STAUS
> + * invoke usb_composite_setup_continue().
> + */
> +#define	USB_GADGET_DELAYED_STATUS	0x7fff /* Impossibly
> large value */ +
>  struct usb_configuration;
>  
>  /**

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 19/40] usb: dwc3: core: make dwc3 core build in uboot
  2015-02-06  8:47 ` [U-Boot] [u-boot 19/40] usb: dwc3: core: make dwc3 core build in uboot Kishon Vijay Abraham I
@ 2015-02-16 10:57   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:57 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> *) Changed the include header files to that used in u-boot.
> *) Removed phy_* APIs
> *) Removed jiffies and used a simple while loop
> *) Used dma_alloc_coherent and dma_free_coherent APIs of u-boot
> *) Fixed other misc warnings
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.c         |  216
> ++++++---------------------------------
> drivers/usb/dwc3/core.h         |   10 --
> drivers/usb/dwc3/linux-compat.h |   10 ++ 3 files changed, 40
> insertions(+), 196 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index ebfb6ca..78322b7 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -14,32 +14,19 @@
>   * SPDX-License-Identifier:     GPL-2.0
>   */
>  
> -#include <linux/version.h>
> -#include <linux/module.h>
> -#include <linux/kernel.h>
> -#include <linux/slab.h>
> -#include <linux/spinlock.h>
> -#include <linux/platform_device.h>
> -#include <linux/interrupt.h>
> +#include <common.h>
> +#include <malloc.h>
> +#include <asm/dma-mapping.h>
>  #include <linux/ioport.h>
> -#include <linux/io.h>
> -#include <linux/list.h>
> -#include <linux/delay.h>
> -#include <linux/dma-mapping.h>
> -#include <linux/of.h>
> -#include <linux/acpi.h>
>  
>  #include <linux/usb/ch9.h>
>  #include <linux/usb/gadget.h>
> -#include <linux/usb/of.h>
> -#include <linux/usb/otg.h>
>  
> -#include "platform_data.h"
>  #include "core.h"
>  #include "gadget.h"
>  #include "io.h"
>  
> -#include "debug.h"
> +#include "linux-compat.h"
>  
>  /*
> --------------------------------------------------------------------------
> */ @@ -60,7 +47,6 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>  static int dwc3_core_soft_reset(struct dwc3 *dwc)
>  {
>  	u32		reg;
> -	int		ret;
>  
>  	/* Before Resetting PHY, put Core in Reset */
>  	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
> @@ -77,17 +63,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
>  	reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
>  	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
>  
> -	usb_phy_init(dwc->usb2_phy);
> -	usb_phy_init(dwc->usb3_phy);
> -	ret = phy_init(dwc->usb2_generic_phy);
> -	if (ret < 0)
> -		return ret;
> -
> -	ret = phy_init(dwc->usb3_generic_phy);
> -	if (ret < 0) {
> -		phy_exit(dwc->usb2_generic_phy);
> -		return ret;
> -	}
>  	mdelay(100);
>  
>  	/* Clear USB3 PHY reset */
> @@ -118,7 +93,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
>  static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
>  		struct dwc3_event_buffer *evt)
>  {
> -	dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
> +	dma_free_coherent(evt->buf);
>  }
>  
>  /**
> @@ -140,8 +115,8 @@ static struct dwc3_event_buffer
> *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, 
>  	evt->dwc	= dwc;
>  	evt->length	= length;
> -	evt->buf	= dma_alloc_coherent(dwc->dev, length,
> -			&evt->dma, GFP_KERNEL);
> +	evt->buf	= dma_alloc_coherent(length,
> +					     (unsigned long
> *)&evt->dma); if (!evt->buf)
>  		return ERR_PTR(-ENOMEM);
>  
> @@ -276,13 +251,9 @@ static int dwc3_setup_scratch_buffers(struct
> dwc3 *dwc) if (!dwc->nr_scratch)
>  		return 0;
>  
> -	 /* should never fall here */
> -	if (!WARN_ON(dwc->scratchbuf))
> -		return 0;
> -
> -	scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
> -			dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
> -			DMA_BIDIRECTIONAL);
> +	scratch_addr = dma_map_single(dwc->scratchbuf,
> +				      dwc->nr_scratch *
> DWC3_SCRATCHBUF_SIZE,
> +				      DMA_BIDIRECTIONAL);
>  	if (dma_mapping_error(dwc->dev, scratch_addr)) {
>  		dev_err(dwc->dev, "failed to map scratch buffer\n");
>  		ret = -EFAULT;
> @@ -308,8 +279,8 @@ static int dwc3_setup_scratch_buffers(struct dwc3
> *dwc) return 0;
>  
>  err1:
> -	dma_unmap_single(dwc->dev, dwc->scratch_addr,
> dwc->nr_scratch *
> -			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
> +	dma_unmap_single((void *)dwc->scratch_addr, dwc->nr_scratch *
> +			 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
>  
>  err0:
>  	return ret;
> @@ -323,12 +294,8 @@ static void dwc3_free_scratch_buffers(struct
> dwc3 *dwc) if (!dwc->nr_scratch)
>  		return;
>  
> -	 /* should never fall here */
> -	if (!WARN_ON(dwc->scratchbuf))
> -		return;
> -
> -	dma_unmap_single(dwc->dev, dwc->scratch_addr,
> dwc->nr_scratch *
> -			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
> +	dma_unmap_single((void *)dwc->scratch_addr, dwc->nr_scratch *
> +			 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
>  	kfree(dwc->scratchbuf);
>  }
>  
> @@ -446,12 +413,6 @@ static int dwc3_core_init(struct dwc3 *dwc)
>  	}
>  	dwc->revision = reg;
>  
> -	/*
> -	 * Write Linux Version Code to our GUID register so it's
> easy to figure
> -	 * out which kernel version a bug was found.
> -	 */
> -	dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
> -
>  	/* Handle USB2.0-only core configuration */
>  	if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
>  			DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
> @@ -460,21 +421,19 @@ static int dwc3_core_init(struct dwc3 *dwc)
>  	}
>  
>  	/* issue device SoftReset too */
> -	timeout = jiffies + msecs_to_jiffies(500);
> +	timeout = 5000;
>  	dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
> -	do {
> +	while (timeout--) {
>  		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
>  		if (!(reg & DWC3_DCTL_CSFTRST))
>  			break;
> +	};
>  
> -		if (time_after(jiffies, timeout)) {
> -			dev_err(dwc->dev, "Reset Timed Out\n");
> -			ret = -ETIMEDOUT;
> -			goto err0;
> -		}
> -
> -		cpu_relax();
> -	} while (true);
> +	if (!timeout) {
> +		dev_err(dwc->dev, "Reset Timed Out\n");
> +		ret = -ETIMEDOUT;
> +		goto err0;
> +	}
>  
>  	ret = dwc3_core_soft_reset(dwc);
>  	if (ret)
> @@ -525,8 +484,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
>  		dwc->is_fpga = true;
>  	}
>  
> -	WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
> -			"disable_scramble cannot be used on non-FPGA
> builds\n");
> +	if(dwc->disable_scramble_quirk && !dwc->is_fpga)
> +		WARN(true,
> +		     "disable_scramble cannot be used on non-FPGA
> builds\n"); 
>  	if (dwc->disable_scramble_quirk && dwc->is_fpga)
>  		reg |= DWC3_GCTL_DISSCRAMBLE;
> @@ -553,22 +513,16 @@ static int dwc3_core_init(struct dwc3 *dwc)
>  
>  	ret = dwc3_alloc_scratch_buffers(dwc);
>  	if (ret)
> -		goto err1;
> +		goto err0;
>  
>  	ret = dwc3_setup_scratch_buffers(dwc);
>  	if (ret)
> -		goto err2;
> +		goto err1;
>  
>  	return 0;
>  
> -err2:
> -	dwc3_free_scratch_buffers(dwc);
> -
>  err1:
> -	usb_phy_shutdown(dwc->usb2_phy);
> -	usb_phy_shutdown(dwc->usb3_phy);
> -	phy_exit(dwc->usb2_generic_phy);
> -	phy_exit(dwc->usb3_generic_phy);
> +	dwc3_free_scratch_buffers(dwc);
>  
>  err0:
>  	return ret;
> @@ -577,82 +531,10 @@ err0:
>  static void dwc3_core_exit(struct dwc3 *dwc)
>  {
>  	dwc3_free_scratch_buffers(dwc);
> -	usb_phy_shutdown(dwc->usb2_phy);
> -	usb_phy_shutdown(dwc->usb3_phy);
> -	phy_exit(dwc->usb2_generic_phy);
> -	phy_exit(dwc->usb3_generic_phy);
> -}
> -
> -static int dwc3_core_get_phy(struct dwc3 *dwc)
> -{
> -	struct device		*dev = dwc->dev;
> -	struct device_node	*node = dev->of_node;
> -	int ret;
> -
> -	if (node) {
> -		dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev,
> "usb-phy", 0);
> -		dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev,
> "usb-phy", 1);
> -	} else {
> -		dwc->usb2_phy = devm_usb_get_phy(dev,
> USB_PHY_TYPE_USB2);
> -		dwc->usb3_phy = devm_usb_get_phy(dev,
> USB_PHY_TYPE_USB3);
> -	}
> -
> -	if (IS_ERR(dwc->usb2_phy)) {
> -		ret = PTR_ERR(dwc->usb2_phy);
> -		if (ret == -ENXIO || ret == -ENODEV) {
> -			dwc->usb2_phy = NULL;
> -		} else if (ret == -EPROBE_DEFER) {
> -			return ret;
> -		} else {
> -			dev_err(dev, "no usb2 phy configured\n");
> -			return ret;
> -		}
> -	}
> -
> -	if (IS_ERR(dwc->usb3_phy)) {
> -		ret = PTR_ERR(dwc->usb3_phy);
> -		if (ret == -ENXIO || ret == -ENODEV) {
> -			dwc->usb3_phy = NULL;
> -		} else if (ret == -EPROBE_DEFER) {
> -			return ret;
> -		} else {
> -			dev_err(dev, "no usb3 phy configured\n");
> -			return ret;
> -		}
> -	}
> -
> -	dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
> -	if (IS_ERR(dwc->usb2_generic_phy)) {
> -		ret = PTR_ERR(dwc->usb2_generic_phy);
> -		if (ret == -ENOSYS || ret == -ENODEV) {
> -			dwc->usb2_generic_phy = NULL;
> -		} else if (ret == -EPROBE_DEFER) {
> -			return ret;
> -		} else {
> -			dev_err(dev, "no usb2 phy configured\n");
> -			return ret;
> -		}
> -	}
> -
> -	dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
> -	if (IS_ERR(dwc->usb3_generic_phy)) {
> -		ret = PTR_ERR(dwc->usb3_generic_phy);
> -		if (ret == -ENOSYS || ret == -ENODEV) {
> -			dwc->usb3_generic_phy = NULL;
> -		} else if (ret == -EPROBE_DEFER) {
> -			return ret;
> -		} else {
> -			dev_err(dev, "no usb3 phy configured\n");
> -			return ret;
> -		}
> -	}
> -
> -	return 0;
>  }
>  
>  static int dwc3_core_init_mode(struct dwc3 *dwc)
>  {
> -	struct device *dev = dwc->dev;
>  	int ret;
>  
>  	switch (dwc->dr_mode) {
> @@ -870,10 +752,6 @@ static int dwc3_probe(struct platform_device
> *pdev) dwc->hird_threshold = hird_threshold
>  		| (dwc->is_utmi_l1_suspend << 4);
>  
> -	ret = dwc3_core_get_phy(dwc);
> -	if (ret)
> -		return ret;
> -
>  	spin_lock_init(&dwc->lock);
>  	platform_set_drvdata(pdev, dwc);
>  
> @@ -888,8 +766,7 @@ static int dwc3_probe(struct platform_device
> *pdev) ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
>  	if (ret) {
>  		dev_err(dwc->dev, "failed to allocate event
> buffers\n");
> -		ret = -ENOMEM;
> -		goto err0;
> +		return -ENOMEM;
>  	}
>  
>  	if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
> @@ -906,49 +783,22 @@ static int dwc3_probe(struct platform_device
> *pdev) goto err0;
>  	}
>  
> -	usb_phy_set_suspend(dwc->usb2_phy, 0);
> -	usb_phy_set_suspend(dwc->usb3_phy, 0);
> -	ret = phy_power_on(dwc->usb2_generic_phy);
> -	if (ret < 0)
> -		goto err1;
> -
> -	ret = phy_power_on(dwc->usb3_generic_phy);
> -	if (ret < 0)
> -		goto err_usb2phy_power;
> -
>  	ret = dwc3_event_buffers_setup(dwc);
>  	if (ret) {
>  		dev_err(dwc->dev, "failed to setup event buffers\n");
> -		goto err_usb3phy_power;
> +		goto err1;
>  	}
>  
>  	ret = dwc3_core_init_mode(dwc);
>  	if (ret)
>  		goto err2;
>  
> -	ret = dwc3_debugfs_init(dwc);
> -	if (ret) {
> -		dev_err(dev, "failed to initialize debugfs\n");
> -		goto err3;
> -	}
> -
>  	return 0;
>  
> -err3:
> -	dwc3_core_exit_mode(dwc);
> -
>  err2:
>  	dwc3_event_buffers_cleanup(dwc);
>  
> -err_usb3phy_power:
> -	phy_power_off(dwc->usb3_generic_phy);
> -
> -err_usb2phy_power:
> -	phy_power_off(dwc->usb2_generic_phy);
> -
>  err1:
> -	usb_phy_set_suspend(dwc->usb2_phy, 1);
> -	usb_phy_set_suspend(dwc->usb3_phy, 1);
>  	dwc3_core_exit(dwc);
>  
>  err0:
> @@ -961,16 +811,10 @@ static int dwc3_remove(struct platform_device
> *pdev) {
>  	struct dwc3	*dwc = platform_get_drvdata(pdev);
>  
> -	dwc3_debugfs_exit(dwc);
>  	dwc3_core_exit_mode(dwc);
>  	dwc3_event_buffers_cleanup(dwc);
>  	dwc3_free_event_buffers(dwc);
>  
> -	usb_phy_set_suspend(dwc->usb2_phy, 1);
> -	usb_phy_set_suspend(dwc->usb3_phy, 1);
> -	phy_power_off(dwc->usb2_generic_phy);
> -	phy_power_off(dwc->usb3_generic_phy);
> -
>  	dwc3_core_exit(dwc);
>  
>  	return 0;
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 0ffcb7d..0d507c1 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -641,10 +641,6 @@ struct dwc3_scratchpad_array {
>   * @maximum_speed: maximum speed requested (mainly for testing
> purposes)
>   * @revision: revision register contents
>   * @dr_mode: requested mode of operation
> - * @usb2_phy: pointer to USB2 PHY
> - * @usb3_phy: pointer to USB3 PHY
> - * @usb2_generic_phy: pointer to USB2 PHY
> - * @usb3_generic_phy: pointer to USB3 PHY
>   * @dcfg: saved contents of DCFG register
>   * @gctl: saved contents of GCTL register
>   * @isoch_delay: wValue from Set Isochronous Delay request;
> @@ -726,12 +722,6 @@ struct dwc3 {
>  	struct usb_gadget	gadget;
>  	struct usb_gadget_driver *gadget_driver;
>  
> -	struct usb_phy		*usb2_phy;
> -	struct usb_phy		*usb3_phy;
> -
> -	struct phy		*usb2_generic_phy;
> -	struct phy		*usb3_generic_phy;
> -
>  	void __iomem		*regs;
>  	size_t			regs_size;
>  
> diff --git a/drivers/usb/dwc3/linux-compat.h
> b/drivers/usb/dwc3/linux-compat.h index cbfb946..b36f68f 100644
> --- a/drivers/usb/dwc3/linux-compat.h
> +++ b/drivers/usb/dwc3/linux-compat.h
> @@ -25,4 +25,14 @@ static inline size_t strlcat(char *dest, const
> char *src, size_t n) return strlen(dest) + strlen(src);
>  }
>  
> +static inline void *devm_kzalloc(struct device *dev, unsigned int
> size,
> +				 unsigned int flags)
> +{
> +	return kzalloc(size, flags);
> +}
> +
> +static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
> +{
> +	return kzalloc(n * size, flags);
> +}
>  #endif

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 20/40] include: dwc3-uboot: add a structure for populating platform data
  2015-02-06  8:47 ` [U-Boot] [u-boot 20/40] include: dwc3-uboot: add a structure for populating platform data Kishon Vijay Abraham I
@ 2015-02-16 10:58   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:58 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added a structure to populate dwc3 core platform data. The board file
> should populate these platform data before invoking dwc3 driver.
> This will be removed once we have dwc3 driver adapted to use the
> driver model.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  include/dwc3-uboot.h |   40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
>  create mode 100644 include/dwc3-uboot.h
> 
> diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h
> new file mode 100644
> index 0000000..6d1b42a
> --- /dev/null
> +++ b/include/dwc3-uboot.h
> @@ -0,0 +1,40 @@
> +/* include/dwc3-uboot.h
> + *
> + * Copyright (c) 2015 Texas Instruments Incorporated -
> http://www.ti.com
> + *
> + * Designware SuperSpeed USB uboot init
> + *
> + * SPDX-License-Identifier:     GPL-2.0
> + */
> +
> +#ifndef __DWC3_UBOOT_H_
> +#define __DWC3_UBOOT_H_
> +
> +#include <linux/usb/otg.h>
> +
> +struct dwc3_device {
> +	int base;
> +	enum usb_dr_mode dr_mode;
> +	u32 maximum_speed;
> +	unsigned tx_fifo_resize:1;
> +	unsigned has_lpm_erratum;
> +	u8 lpm_nyet_threshold;
> +	unsigned is_utmi_l1_suspend;
> +	u8 hird_threshold;
> +	unsigned disable_scramble_quirk;
> +	unsigned u2exit_lfps_quirk;
> +	unsigned u2ss_inp3_quirk;
> +	unsigned req_p1p2p3_quirk;
> +	unsigned del_p1p2p3_quirk;
> +	unsigned del_phy_power_chg_quirk;
> +	unsigned lfps_filter_quirk;
> +	unsigned rx_detect_poll_quirk;
> +	unsigned dis_u3_susphy_quirk;
> +	unsigned dis_u2_susphy_quirk;
> +	unsigned tx_de_emphasis_quirk;
> +	unsigned tx_de_emphasis;
> +};
> +
> +int dwc3_uboot_init(struct dwc3_device *dev);
> +void dwc3_uboot_exit(void);
> +#endif /* __DWC3_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 21/40] dwc3: core: change probe and remove to uboot init and uboot exit code
  2015-02-06  8:47 ` [U-Boot] [u-boot 21/40] dwc3: core: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
@ 2015-02-16 10:59   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 10:59 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Removed probe and remove that are specific to linux and replaced it
> with uboot init and uboot exit. These functions will be invoked from
> boardfile.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.c |  218
> +++++++++++------------------------------------ 1 file changed, 52
> insertions(+), 166 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 78322b7..58c3bfd 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -16,6 +16,7 @@
>  
>  #include <common.h>
>  #include <malloc.h>
> +#include <dwc3-uboot.h>
>  #include <asm/dma-mapping.h>
>  #include <linux/ioport.h>
>  
> @@ -28,6 +29,7 @@
>  
>  #include "linux-compat.h"
>  
> +struct dwc3 *dwc;
>  /*
> --------------------------------------------------------------------------
> */ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
> @@ -597,20 +599,26 @@ static void dwc3_core_exit_mode(struct dwc3
> *dwc) 
>  #define DWC3_ALIGN_MASK		(16 - 1)
>  
> -static int dwc3_probe(struct platform_device *pdev)
> +/**
> + * dwc3_uboot_init - dwc3 core uboot initialization code
> + * @dwc3_dev: struct dwc3_device containing initialization data
> + *
> + * Entry point for dwc3 driver (equivalent to dwc3_probe in linux
> + * kernel driver). Pointer to dwc3_device should be passed containing
> + * base address and other initialization data. Returns '0' on
> success and
> + * a negative value on failure.
> + *
> + * Generally called from board_usb_init() implemented in board file.
> + */
> +int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
>  {
> -	struct device		*dev = &pdev->dev;
> -	struct dwc3_platform_data *pdata = dev_get_platdata(dev);
> -	struct device_node	*node = dev->of_node;
> -	struct resource		*res;
> -	struct dwc3		*dwc;
> +	struct device		*dev;
>  	u8			lpm_nyet_threshold;
>  	u8			tx_de_emphasis;
>  	u8			hird_threshold;
>  
>  	int			ret;
>  
> -	void __iomem		*regs;
>  	void			*mem;
>  
>  	mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK,
> GFP_KERNEL); @@ -619,48 +627,8 @@ static int dwc3_probe(struct
> platform_device *pdev) 
>  	dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
>  	dwc->mem = mem;
> -	dwc->dev = dev;
> -
> -	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> -	if (!res) {
> -		dev_err(dev, "missing IRQ\n");
> -		return -ENODEV;
> -	}
> -	dwc->xhci_resources[1].start = res->start;
> -	dwc->xhci_resources[1].end = res->end;
> -	dwc->xhci_resources[1].flags = res->flags;
> -	dwc->xhci_resources[1].name = res->name;
> -
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	if (!res) {
> -		dev_err(dev, "missing memory resource\n");
> -		return -ENODEV;
> -	}
>  
> -	dwc->xhci_resources[0].start = res->start;
> -	dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
> -					DWC3_XHCI_REGS_END;
> -	dwc->xhci_resources[0].flags = res->flags;
> -	dwc->xhci_resources[0].name = res->name;
> -
> -	res->start += DWC3_GLOBALS_REGS_START;
> -
> -	/*
> -	 * Request memory region but exclude xHCI regs,
> -	 * since it will be requested by the xhci-plat driver.
> -	 */
> -	regs = devm_ioremap_resource(dev, res);
> -	if (IS_ERR(regs))
> -		return PTR_ERR(regs);
> -
> -	dwc->regs	= regs;
> -	dwc->regs_size	= resource_size(res);
> -	/*
> -	 * restore res->start back to its original value so that,
> -	 * in case the probe is deferred, we don't end up getting
> error in
> -	 * request the memory region the next time probe is called.
> -	 */
> -	res->start -= DWC3_GLOBALS_REGS_START;
> +	dwc->regs	= (int *)(dwc3_dev->base +
> DWC3_GLOBALS_REGS_START); 
>  	/* default to highest possible threshold */
>  	lpm_nyet_threshold = 0xff;
> @@ -674,73 +642,31 @@ static int dwc3_probe(struct platform_device
> *pdev) */
>  	hird_threshold = 12;
>  
> -	if (node) {
> -		dwc->maximum_speed = of_usb_get_maximum_speed(node);
> -		dwc->has_lpm_erratum = of_property_read_bool(node,
> -				"snps,has-lpm-erratum");
> -		of_property_read_u8(node, "snps,lpm-nyet-threshold",
> -				&lpm_nyet_threshold);
> -		dwc->is_utmi_l1_suspend = of_property_read_bool(node,
> -				"snps,is-utmi-l1-suspend");
> -		of_property_read_u8(node, "snps,hird-threshold",
> -				&hird_threshold);
> -
> -		dwc->needs_fifo_resize = of_property_read_bool(node,
> -				"tx-fifo-resize");
> -		dwc->dr_mode = of_usb_get_dr_mode(node);
> -
> -		dwc->disable_scramble_quirk =
> of_property_read_bool(node,
> -				"snps,disable_scramble_quirk");
> -		dwc->u2exit_lfps_quirk = of_property_read_bool(node,
> -				"snps,u2exit_lfps_quirk");
> -		dwc->u2ss_inp3_quirk = of_property_read_bool(node,
> -				"snps,u2ss_inp3_quirk");
> -		dwc->req_p1p2p3_quirk = of_property_read_bool(node,
> -				"snps,req_p1p2p3_quirk");
> -		dwc->del_p1p2p3_quirk = of_property_read_bool(node,
> -				"snps,del_p1p2p3_quirk");
> -		dwc->del_phy_power_chg_quirk =
> of_property_read_bool(node,
> -				"snps,del_phy_power_chg_quirk");
> -		dwc->lfps_filter_quirk = of_property_read_bool(node,
> -				"snps,lfps_filter_quirk");
> -		dwc->rx_detect_poll_quirk =
> of_property_read_bool(node,
> -				"snps,rx_detect_poll_quirk");
> -		dwc->dis_u3_susphy_quirk =
> of_property_read_bool(node,
> -				"snps,dis_u3_susphy_quirk");
> -		dwc->dis_u2_susphy_quirk =
> of_property_read_bool(node,
> -				"snps,dis_u2_susphy_quirk");
> -
> -		dwc->tx_de_emphasis_quirk =
> of_property_read_bool(node,
> -				"snps,tx_de_emphasis_quirk");
> -		of_property_read_u8(node, "snps,tx_de_emphasis",
> -				&tx_de_emphasis);
> -	} else if (pdata) {
> -		dwc->maximum_speed = pdata->maximum_speed;
> -		dwc->has_lpm_erratum = pdata->has_lpm_erratum;
> -		if (pdata->lpm_nyet_threshold)
> -			lpm_nyet_threshold =
> pdata->lpm_nyet_threshold;
> -		dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend;
> -		if (pdata->hird_threshold)
> -			hird_threshold = pdata->hird_threshold;
> -
> -		dwc->needs_fifo_resize = pdata->tx_fifo_resize;
> -		dwc->dr_mode = pdata->dr_mode;
> -
> -		dwc->disable_scramble_quirk =
> pdata->disable_scramble_quirk;
> -		dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk;
> -		dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk;
> -		dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk;
> -		dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk;
> -		dwc->del_phy_power_chg_quirk =
> pdata->del_phy_power_chg_quirk;
> -		dwc->lfps_filter_quirk = pdata->lfps_filter_quirk;
> -		dwc->rx_detect_poll_quirk =
> pdata->rx_detect_poll_quirk;
> -		dwc->dis_u3_susphy_quirk =
> pdata->dis_u3_susphy_quirk;
> -		dwc->dis_u2_susphy_quirk =
> pdata->dis_u2_susphy_quirk; -
> -		dwc->tx_de_emphasis_quirk =
> pdata->tx_de_emphasis_quirk;
> -		if (pdata->tx_de_emphasis)
> -			tx_de_emphasis = pdata->tx_de_emphasis;
> -	}
> +	dwc->maximum_speed = dwc3_dev->maximum_speed;
> +	dwc->has_lpm_erratum = dwc3_dev->has_lpm_erratum;
> +	if (dwc3_dev->lpm_nyet_threshold)
> +		lpm_nyet_threshold = dwc3_dev->lpm_nyet_threshold;
> +	dwc->is_utmi_l1_suspend = dwc3_dev->is_utmi_l1_suspend;
> +	if (dwc3_dev->hird_threshold)
> +		hird_threshold = dwc3_dev->hird_threshold;
> +
> +	dwc->needs_fifo_resize = dwc3_dev->tx_fifo_resize;
> +	dwc->dr_mode = dwc3_dev->dr_mode;
> +
> +	dwc->disable_scramble_quirk =
> dwc3_dev->disable_scramble_quirk;
> +	dwc->u2exit_lfps_quirk = dwc3_dev->u2exit_lfps_quirk;
> +	dwc->u2ss_inp3_quirk = dwc3_dev->u2ss_inp3_quirk;
> +	dwc->req_p1p2p3_quirk = dwc3_dev->req_p1p2p3_quirk;
> +	dwc->del_p1p2p3_quirk = dwc3_dev->del_p1p2p3_quirk;
> +	dwc->del_phy_power_chg_quirk =
> dwc3_dev->del_phy_power_chg_quirk;
> +	dwc->lfps_filter_quirk = dwc3_dev->lfps_filter_quirk;
> +	dwc->rx_detect_poll_quirk = dwc3_dev->rx_detect_poll_quirk;
> +	dwc->dis_u3_susphy_quirk = dwc3_dev->dis_u3_susphy_quirk;
> +	dwc->dis_u2_susphy_quirk = dwc3_dev->dis_u2_susphy_quirk;
> +
> +	dwc->tx_de_emphasis_quirk = dwc3_dev->tx_de_emphasis_quirk;
> +	if (dwc3_dev->tx_de_emphasis)
> +		tx_de_emphasis = dwc3_dev->tx_de_emphasis;
>  
>  	/* default to superspeed if no maximum_speed passed */
>  	if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
> @@ -752,15 +678,6 @@ static int dwc3_probe(struct platform_device
> *pdev) dwc->hird_threshold = hird_threshold
>  		| (dwc->is_utmi_l1_suspend << 4);
>  
> -	spin_lock_init(&dwc->lock);
> -	platform_set_drvdata(pdev, dwc);
> -
> -	if (!dev->dma_mask) {
> -		dev->dma_mask = dev->parent->dma_mask;
> -		dev->dma_parms = dev->parent->dma_parms;
> -		dma_set_coherent_mask(dev,
> dev->parent->coherent_dma_mask);
> -	}
> -
>  	dwc3_cache_hwparams(dwc);
>  
>  	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
> @@ -807,55 +724,24 @@ err0:
>  	return ret;
>  }
>  
> -static int dwc3_remove(struct platform_device *pdev)
> +/**
> + * dwc3_uboot_exit - dwc3 core uboot cleanup code
> + * @index: index of this controller
> + *
> + * Performs cleanup of memory allocated in dwc3_uboot_init and other
> misc
> + * cleanups (equivalent to dwc3_remove in linux).
> + *
> + * Generally called from board file.
> + */
> +void dwc3_uboot_exit()
>  {
> -	struct dwc3	*dwc = platform_get_drvdata(pdev);
> -
>  	dwc3_core_exit_mode(dwc);
>  	dwc3_event_buffers_cleanup(dwc);
>  	dwc3_free_event_buffers(dwc);
> -
>  	dwc3_core_exit(dwc);
> -
> -	return 0;
> +	kfree(dwc->mem);
>  }
>  
> -#ifdef CONFIG_OF
> -static const struct of_device_id of_dwc3_match[] = {
> -	{
> -		.compatible = "snps,dwc3"
> -	},
> -	{
> -		.compatible = "synopsys,dwc3"
> -	},
> -	{ },
> -};
> -MODULE_DEVICE_TABLE(of, of_dwc3_match);
> -#endif
> -
> -#ifdef CONFIG_ACPI
> -
> -#define ACPI_ID_INTEL_BSW	"808622B7"
> -
> -static const struct acpi_device_id dwc3_acpi_match[] = {
> -	{ ACPI_ID_INTEL_BSW, 0 },
> -	{ },
> -};
> -MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
> -#endif
> -
> -static struct platform_driver dwc3_driver = {
> -	.probe		= dwc3_probe,
> -	.remove		= dwc3_remove,
> -	.driver		= {
> -		.name	= "dwc3",
> -		.of_match_table	= of_match_ptr(of_dwc3_match),
> -		.acpi_match_table = ACPI_PTR(dwc3_acpi_match),
> -	},
> -};
> -
> -module_platform_driver(dwc3_driver);
> -
>  MODULE_ALIAS("platform:dwc3");
>  MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
>  MODULE_LICENSE("GPL v2");

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 22/40] dwc3: core: add support for multiple dwc3 controllers
  2015-02-06  8:47 ` [U-Boot] [u-boot 22/40] dwc3: core: add support for multiple dwc3 controllers Kishon Vijay Abraham I
@ 2015-02-16 11:00   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:00 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added support for multiple dwc3 controllers. This gives uboot
> the capability to control multiple dwc3 controllers.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.c |   32 ++++++++++++++++++++++++--------
>  drivers/usb/dwc3/core.h |    4 ++++
>  include/dwc3-uboot.h    |    3 ++-
>  3 files changed, 30 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 58c3bfd..bd34dbd 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -29,7 +29,7 @@
>  
>  #include "linux-compat.h"
>  
> -struct dwc3 *dwc;
> +static LIST_HEAD(dwc3_list);
>  /*
> --------------------------------------------------------------------------
> */ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
> @@ -612,6 +612,7 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
>   */
>  int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
>  {
> +	struct dwc3		*dwc;
>  	struct device		*dev;
>  	u8			lpm_nyet_threshold;
>  	u8			tx_de_emphasis;
> @@ -678,6 +679,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
>  	dwc->hird_threshold = hird_threshold
>  		| (dwc->is_utmi_l1_suspend << 4);
>  
> +	dwc->index = dwc3_dev->index;
> +
>  	dwc3_cache_hwparams(dwc);
>  
>  	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
> @@ -710,6 +713,8 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
>  	if (ret)
>  		goto err2;
>  
> +	list_add_tail(&dwc->list, &dwc3_list);
> +
>  	return 0;
>  
>  err2:
> @@ -729,17 +734,28 @@ err0:
>   * @index: index of this controller
>   *
>   * Performs cleanup of memory allocated in dwc3_uboot_init and other
> misc
> - * cleanups (equivalent to dwc3_remove in linux).
> + * cleanups (equivalent to dwc3_remove in linux). index of _this_
> controller
> + * should be passed and should match with the index passed in
> + * dwc3_device during init.
>   *
>   * Generally called from board file.
>   */
> -void dwc3_uboot_exit()
> +void dwc3_uboot_exit(int index)
>  {
> -	dwc3_core_exit_mode(dwc);
> -	dwc3_event_buffers_cleanup(dwc);
> -	dwc3_free_event_buffers(dwc);
> -	dwc3_core_exit(dwc);
> -	kfree(dwc->mem);
> +	struct dwc3 *dwc;
> +
> +	list_for_each_entry(dwc, &dwc3_list, list) {
> +		if (dwc->index != index)
> +			continue;
> +
> +		dwc3_core_exit_mode(dwc);
> +		dwc3_event_buffers_cleanup(dwc);
> +		dwc3_free_event_buffers(dwc);
> +		dwc3_core_exit(dwc);
> +		list_del(&dwc->list);
> +		kfree(dwc->mem);
> +		break;
> +	}
>  }
>  
>  MODULE_ALIAS("platform:dwc3");
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 0d507c1..c5debf7 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -695,6 +695,8 @@ struct dwc3_scratchpad_array {
>   * 	1	- -3.5dB de-emphasis
>   * 	2	- No de-emphasis
>   * 	3	- Reserved
> + * @index: index of _this_ controller
> + * @list: to maintain the list of dwc3 controllers
>   */
>  struct dwc3 {
>  	struct usb_ctrlrequest	*ctrl_req;
> @@ -811,6 +813,8 @@ struct dwc3 {
>  
>  	unsigned		tx_de_emphasis_quirk:1;
>  	unsigned		tx_de_emphasis:2;
> +	int			index;
> +	struct list_head        list;
>  };
>  
>  /*
> --------------------------------------------------------------------------
> */ diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h index
> 6d1b42a..272a020 100644 --- a/include/dwc3-uboot.h
> +++ b/include/dwc3-uboot.h
> @@ -33,8 +33,9 @@ struct dwc3_device {
>  	unsigned dis_u2_susphy_quirk;
>  	unsigned tx_de_emphasis_quirk;
>  	unsigned tx_de_emphasis;
> +	int index;
>  };
>  
>  int dwc3_uboot_init(struct dwc3_device *dev);
> -void dwc3_uboot_exit(void);
> +void dwc3_uboot_exit(int index);
>  #endif /* __DWC3_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 23/40] dwc3: core: added an API to invoke irq handlers
  2015-02-06  8:48 ` [U-Boot] [u-boot 23/40] dwc3: core: added an API to invoke irq handlers Kishon Vijay Abraham I
@ 2015-02-16 11:01   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:01 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Since interrupt support is not present in u-boot, added an
> API to handle the interrupts in dwc3 core. This API can be
> polled to handle the interrupts.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.c |   21 +++++++++++++++++++++
>  include/dwc3-uboot.h    |    1 +
>  2 files changed, 22 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index bd34dbd..5a8d5ea 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -758,6 +758,27 @@ void dwc3_uboot_exit(int index)
>  	}
>  }
>  
> +/**
> + * dwc3_uboot_handle_interrupt - handle dwc3 core interrupt
> + * @index: index of this controller
> + *
> + * Invokes dwc3 gadget interrupts.
> + *
> + * Generally called from board file.
> + */
> +void dwc3_uboot_handle_interrupt(int index)
> +{
> +	struct dwc3 *dwc = NULL;
> +
> +	list_for_each_entry(dwc, &dwc3_list, list) {
> +		if (dwc->index != index)
> +			continue;
> +
> +		dwc3_gadget_uboot_handle_interrupt(dwc);
> +		break;
> +	}
> +}
> +
>  MODULE_ALIAS("platform:dwc3");
>  MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
>  MODULE_LICENSE("GPL v2");
> diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h
> index 272a020..09ff8a7 100644
> --- a/include/dwc3-uboot.h
> +++ b/include/dwc3-uboot.h
> @@ -38,4 +38,5 @@ struct dwc3_device {
>  
>  int dwc3_uboot_init(struct dwc3_device *dev);
>  void dwc3_uboot_exit(int index);
> +void dwc3_uboot_handle_interrupt(int index);
>  #endif /* __DWC3_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 24/40] usb: dwc3: dwc3-omap: make dwc3-omap build in uboot
  2015-02-06  8:48 ` [U-Boot] [u-boot 24/40] usb: dwc3: dwc3-omap: make dwc3-omap build in uboot Kishon Vijay Abraham I
@ 2015-02-16 11:02   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:02 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> *) Changed the included header files to that used in u-boot.
> *) Removed extcon_* APIs
> *) Removed regulator_* APIs
> *) Fixed other misc warnings
> *) Added dwc3-omap.h to include the definitions of UTMI modes.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/dwc3-omap.c  |  144
> +++--------------------------------------
> include/linux/usb/dwc3-omap.h |   19 ++++++ 2 files changed, 27
> insertions(+), 136 deletions(-) create mode 100644
> include/linux/usb/dwc3-omap.h
> 
> diff --git a/drivers/usb/dwc3/dwc3-omap.c
> b/drivers/usb/dwc3/dwc3-omap.c index ce2d6a6..b385987 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -14,21 +14,16 @@
>   * SPDX-License-Identifier:     GPL-2.0
>   */
>  
> -#include <linux/module.h>
> -#include <linux/kernel.h>
> -#include <linux/slab.h>
> -#include <linux/interrupt.h>
> -#include <linux/platform_device.h>
> -#include <linux/platform_data/dwc3-omap.h>
> -#include <linux/dma-mapping.h>
> +#include <common.h>
> +#include <malloc.h>
> +#include <asm/io.h>
> +#include <linux/usb/dwc3-omap.h>
>  #include <linux/ioport.h>
> -#include <linux/io.h>
> -#include <linux/of.h>
> -#include <linux/of_platform.h>
> -#include <linux/extcon.h>
> -#include <linux/regulator/consumer.h>
>  
>  #include <linux/usb/otg.h>
> +#include <linux/compat.h>
> +
> +#include "linux-compat.h"
>  
>  /*
>   * All these registers belong to OMAP's Wrapper around the
> @@ -113,7 +108,6 @@
>  struct dwc3_omap {
>  	struct device		*dev;
>  
> -	int			irq;
>  	void __iomem		*base;
>  
>  	u32			utmi_otg_status;
> @@ -124,13 +118,6 @@ struct dwc3_omap {
>  	u32			irq0_offset;
>  
>  	u32			dma_status:1;
> -
> -	struct extcon_specific_cable_nb extcon_vbus_dev;
> -	struct extcon_specific_cable_nb extcon_id_dev;
> -	struct notifier_block	vbus_nb;
> -	struct notifier_block	id_nb;
> -
> -	struct regulator	*vbus_reg;
>  };
>  
>  enum omap_dwc3_vbus_id_status {
> @@ -205,21 +192,12 @@ static void dwc3_omap_write_irq0_set(struct
> dwc3_omap *omap, u32 value) static void dwc3_omap_set_mailbox(struct
> dwc3_omap *omap, enum omap_dwc3_vbus_id_status status)
>  {
> -	int	ret;
>  	u32	val;
>  
>  	switch (status) {
>  	case OMAP_DWC3_ID_GROUND:
>  		dev_dbg(omap->dev, "ID GND\n");
>  
> -		if (omap->vbus_reg) {
> -			ret = regulator_enable(omap->vbus_reg);
> -			if (ret) {
> -				dev_dbg(omap->dev, "regulator enable
> failed\n");
> -				return;
> -			}
> -		}
> -
>  		val = dwc3_omap_read_utmi_status(omap);
>  		val &= ~(USBOTGSS_UTMI_OTG_STATUS_IDDIG
>  				| USBOTGSS_UTMI_OTG_STATUS_VBUSVALID
> @@ -242,9 +220,6 @@ static void dwc3_omap_set_mailbox(struct
> dwc3_omap *omap, break;
>  
>  	case OMAP_DWC3_ID_FLOAT:
> -		if (omap->vbus_reg)
> -			regulator_disable(omap->vbus_reg);
> -
>  	case OMAP_DWC3_VBUS_OFF:
>  		dev_dbg(omap->dev, "VBUS Disconnect\n");
>  
> @@ -349,32 +324,6 @@ static void dwc3_omap_disable_irqs(struct
> dwc3_omap *omap) 
>  static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
>  
> -static int dwc3_omap_id_notifier(struct notifier_block *nb,
> -	unsigned long event, void *ptr)
> -{
> -	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap,
> id_nb); -
> -	if (event)
> -		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
> -	else
> -		dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
> -
> -	return NOTIFY_DONE;
> -}
> -
> -static int dwc3_omap_vbus_notifier(struct notifier_block *nb,
> -	unsigned long event, void *ptr)
> -{
> -	struct dwc3_omap *omap = container_of(nb, struct dwc3_omap,
> vbus_nb); -
> -	if (event)
> -		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
> -	else
> -		dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
> -
> -	return NOTIFY_DONE;
> -}
> -
>  static void dwc3_omap_map_offset(struct dwc3_omap *omap)
>  {
>  	struct device_node	*node = omap->dev->of_node;
> @@ -420,42 +369,6 @@ static void dwc3_omap_set_utmi_mode(struct
> dwc3_omap *omap) dwc3_omap_write_utmi_status(omap, reg);
>  }
>  
> -static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
> -{
> -	int			ret;
> -	struct device_node	*node = omap->dev->of_node;
> -	struct extcon_dev	*edev;
> -
> -	if (of_property_read_bool(node, "extcon")) {
> -		edev = extcon_get_edev_by_phandle(omap->dev, 0);
> -		if (IS_ERR(edev)) {
> -			dev_vdbg(omap->dev, "couldn't get extcon
> device\n");
> -			return -EPROBE_DEFER;
> -		}
> -
> -		omap->vbus_nb.notifier_call =
> dwc3_omap_vbus_notifier;
> -		ret =
> extcon_register_interest(&omap->extcon_vbus_dev,
> -					       edev->name, "USB",
> -					       &omap->vbus_nb);
> -		if (ret < 0)
> -			dev_vdbg(omap->dev, "failed to register
> notifier for USB\n"); -
> -		omap->id_nb.notifier_call = dwc3_omap_id_notifier;
> -		ret = extcon_register_interest(&omap->extcon_id_dev,
> -					       edev->name,
> "USB-HOST",
> -					       &omap->id_nb);
> -		if (ret < 0)
> -			dev_vdbg(omap->dev, "failed to register
> notifier for USB-HOST\n"); -
> -		if (extcon_get_cable_state(edev, "USB") == true)
> -			dwc3_omap_set_mailbox(omap,
> OMAP_DWC3_VBUS_VALID);
> -		if (extcon_get_cable_state(edev, "USB-HOST") == true)
> -			dwc3_omap_set_mailbox(omap,
> OMAP_DWC3_ID_GROUND);
> -	}
> -
> -	return 0;
> -}
> -
>  static int dwc3_omap_probe(struct platform_device *pdev)
>  {
>  	struct device_node	*node = pdev->dev.of_node;
> @@ -463,11 +376,8 @@ static int dwc3_omap_probe(struct
> platform_device *pdev) struct dwc3_omap	*omap;
>  	struct resource		*res;
>  	struct device		*dev = &pdev->dev;
> -	struct regulator	*vbus_reg = NULL;
>  
>  	int			ret;
> -	int			irq;
> -
>  	u32			reg;
>  
>  	void __iomem		*base;
> @@ -483,29 +393,13 @@ static int dwc3_omap_probe(struct
> platform_device *pdev) 
>  	platform_set_drvdata(pdev, omap);
>  
> -	irq = platform_get_irq(pdev, 0);
> -	if (irq < 0) {
> -		dev_err(dev, "missing IRQ resource\n");
> -		return -EINVAL;
> -	}
> -
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	base = devm_ioremap_resource(dev, res);
>  	if (IS_ERR(base))
>  		return PTR_ERR(base);
>  
> -	if (of_property_read_bool(node, "vbus-supply")) {
> -		vbus_reg = devm_regulator_get(dev, "vbus");
> -		if (IS_ERR(vbus_reg)) {
> -			dev_err(dev, "vbus init failed\n");
> -			return PTR_ERR(vbus_reg);
> -		}
> -	}
> -
>  	omap->dev	= dev;
> -	omap->irq	= irq;
>  	omap->base	= base;
> -	omap->vbus_reg	= vbus_reg;
>  	dev->dma_mask	= &dwc3_omap_dma_mask;
>  
>  	dwc3_omap_map_offset(omap);
> @@ -515,34 +409,16 @@ static int dwc3_omap_probe(struct
> platform_device *pdev) reg = dwc3_omap_readl(omap->base,
> USBOTGSS_SYSCONFIG); omap->dma_status = !!(reg &
> USBOTGSS_SYSCONFIG_DMADISABLE); 
> -	ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt,
> 0,
> -			"dwc3-omap", omap);
> -	if (ret) {
> -		dev_err(dev, "failed to request IRQ #%d --> %d\n",
> -				omap->irq, ret);
> -		goto err0;
> -	}
> -
>  	dwc3_omap_enable_irqs(omap);
>  
> -	ret = dwc3_omap_extcon_register(omap);
> -	if (ret < 0)
> -		goto err1;
> -
>  	ret = of_platform_populate(node, NULL, NULL, dev);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to create dwc3 core\n");
> -		goto err2;
> +		goto err1;
>  	}
>  
>  	return 0;
>  
> -err2:
> -	if (omap->extcon_vbus_dev.edev)
> -		extcon_unregister_interest(&omap->extcon_vbus_dev);
> -	if (omap->extcon_id_dev.edev)
> -		extcon_unregister_interest(&omap->extcon_id_dev);
> -
>  err1:
>  	dwc3_omap_disable_irqs(omap);
>  
> @@ -554,10 +430,6 @@ static int dwc3_omap_remove(struct
> platform_device *pdev) {
>  	struct dwc3_omap	*omap = platform_get_drvdata(pdev);
>  
> -	if (omap->extcon_vbus_dev.edev)
> -		extcon_unregister_interest(&omap->extcon_vbus_dev);
> -	if (omap->extcon_id_dev.edev)
> -		extcon_unregister_interest(&omap->extcon_id_dev);
>  	dwc3_omap_disable_irqs(omap);
>  	device_for_each_child(&pdev->dev, NULL,
> dwc3_omap_remove_core); 
> diff --git a/include/linux/usb/dwc3-omap.h
> b/include/linux/usb/dwc3-omap.h new file mode 100644
> index 0000000..8bf7b55
> --- /dev/null
> +++ b/include/linux/usb/dwc3-omap.h
> @@ -0,0 +1,19 @@
> +/* include/linux/usb/dwc3-omap.h
> + *
> + * Copyright (c) 2014 Texas Instruments Incorporated -
> http://www.ti.com
> + *
> + * Designware SuperSpeed Glue
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#ifndef __DWC3_OMAP_H_
> +#define __DWC3_OMAP_H_
> +
> +enum dwc3_omap_utmi_mode {
> +	DWC3_OMAP_UTMI_MODE_UNKNOWN = 0,
> +	DWC3_OMAP_UTMI_MODE_HW,
> +	DWC3_OMAP_UTMI_MODE_SW,
> +};
> +
> +#endif /* __DWC3_OMAP_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 25/40] include: dwc3-omap-uboot: add a structure for populating dwc3-omap platform data
  2015-02-06  8:48 ` [U-Boot] [u-boot 25/40] include: dwc3-omap-uboot: add a structure for populating dwc3-omap platform data Kishon Vijay Abraham I
@ 2015-02-16 11:03   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:03 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added a structure to populate dwc3 omap platform data. The board file
> should populate these platform data before invoking dwc3 omap driver.
> 
> This will be removed once dwc3-omap driver is adapted to use the
> driver model.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/dwc3-omap.c |    7 -------
>  include/dwc3-omap-uboot.h    |   27 +++++++++++++++++++++++++++
>  2 files changed, 27 insertions(+), 7 deletions(-)
>  create mode 100644 include/dwc3-omap-uboot.h
> 
> diff --git a/drivers/usb/dwc3/dwc3-omap.c
> b/drivers/usb/dwc3/dwc3-omap.c index b385987..31a2aa3 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -120,13 +120,6 @@ struct dwc3_omap {
>  	u32			dma_status:1;
>  };
>  
> -enum omap_dwc3_vbus_id_status {
> -	OMAP_DWC3_ID_FLOAT,
> -	OMAP_DWC3_ID_GROUND,
> -	OMAP_DWC3_VBUS_OFF,
> -	OMAP_DWC3_VBUS_VALID,
> -};
> -
>  static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
>  {
>  	return readl(base + offset);
> diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
> new file mode 100644
> index 0000000..b313b64
> --- /dev/null
> +++ b/include/dwc3-omap-uboot.h
> @@ -0,0 +1,27 @@
> +/* include/dwc3_omap_uboot.h
> + *
> + * Copyright (c) 2015 Texas Instruments Incorporated -
> http://www.ti.com
> + *
> + * Designware SuperSpeed OMAP Glue uboot init
> + *
> + * SPDX-License-Identifier:     GPL-2.0
> + */
> +
> +#ifndef __DWC3_OMAP_UBOOT_H_
> +#define __DWC3_OMAP_UBOOT_H_
> +
> +#include <linux/usb/dwc3-omap.h>
> +
> +enum omap_dwc3_vbus_id_status {
> +	OMAP_DWC3_ID_FLOAT,
> +	OMAP_DWC3_ID_GROUND,
> +	OMAP_DWC3_VBUS_OFF,
> +	OMAP_DWC3_VBUS_VALID,
> +};
> +
> +struct dwc3_omap_device {
> +	void *base;
> +	enum dwc3_omap_utmi_mode utmi_mode;
> +	enum omap_dwc3_vbus_id_status vbus_id_status;
> +};
> +#endif /* __DWC3_OMAP_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 26/40] usb: dwc3: dwc3-omap: change probe and remove to uboot init and uboot exit code
  2015-02-06  8:48 ` [U-Boot] [u-boot 26/40] usb: dwc3: dwc3-omap: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
@ 2015-02-16 11:04   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:04 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Removed probe and remove that are specific to linux and replaced it
> with uboot init and uboot exit. These functions will be invoked from
> boardfile.
> 
> This will change once we have dwc3-omap driver adapted to use the
> uboot driver model.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/dwc3-omap.c |  128
> +++++++++++++-----------------------------
> include/dwc3-omap-uboot.h    |    3 + 2 files changed, 42
> insertions(+), 89 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-omap.c
> b/drivers/usb/dwc3/dwc3-omap.c index 31a2aa3..30d7210 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -17,6 +17,7 @@
>  #include <common.h>
>  #include <malloc.h>
>  #include <asm/io.h>
> +#include <dwc3-omap-uboot.h>
>  #include <linux/usb/dwc3-omap.h>
>  #include <linux/ioport.h>
>  
> @@ -120,6 +121,8 @@ struct dwc3_omap {
>  	u32			dma_status:1;
>  };
>  
> +struct dwc3_omap *omap;
> +
>  static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
>  {
>  	return readl(base + offset);
> @@ -278,15 +281,6 @@ static irqreturn_t dwc3_omap_interrupt(int irq,
> void *_omap) return IRQ_HANDLED;
>  }
>  
> -static int dwc3_omap_remove_core(struct device *dev, void *c)
> -{
> -	struct platform_device *pdev = to_platform_device(dev);
> -
> -	of_device_unregister(pdev);
> -
> -	return 0;
> -}
> -
>  static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
>  {
>  	u32			reg;
> @@ -315,12 +309,8 @@ static void dwc3_omap_disable_irqs(struct
> dwc3_omap *omap) dwc3_omap_write_irq0_set(omap, 0x00);
>  }
>  
> -static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
> -
>  static void dwc3_omap_map_offset(struct dwc3_omap *omap)
>  {
> -	struct device_node	*node = omap->dev->of_node;
> -
>  	/*
>  	 * Differentiate between OMAP5 and AM437x.
>  	 *
> @@ -329,25 +319,21 @@ static void dwc3_omap_map_offset(struct
> dwc3_omap *omap) *
>  	 * Using dt compatible to differentiate AM437x.
>  	 */
> -	if (of_device_is_compatible(node, "ti,am437x-dwc3")) {
> -		omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
> -		omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
> -		omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
> -		omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
> -		omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
> -	}
> +#ifdef CONFIG_AM43XX
> +	omap->irq_eoi_offset = USBOTGSS_EOI_OFFSET;
> +	omap->irq0_offset = USBOTGSS_IRQ0_OFFSET;
> +	omap->irqmisc_offset = USBOTGSS_IRQMISC_OFFSET;
> +	omap->utmi_otg_offset = USBOTGSS_UTMI_OTG_OFFSET;
> +	omap->debug_offset = USBOTGSS_DEBUG_OFFSET;
> +#endif
>  }
>  
> -static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap)
> +static void dwc3_omap_set_utmi_mode(struct dwc3_omap *omap, int
> utmi_mode) {
>  	u32			reg;
> -	struct device_node	*node = omap->dev->of_node;
> -	int			utmi_mode = 0;
>  
>  	reg = dwc3_omap_read_utmi_status(omap);
>  
> -	of_property_read_u32(node, "utmi-mode", &utmi_mode);
> -
>  	switch (utmi_mode) {
>  	case DWC3_OMAP_UTMI_MODE_SW:
>  		reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
> @@ -362,95 +348,59 @@ static void dwc3_omap_set_utmi_mode(struct
> dwc3_omap *omap) dwc3_omap_write_utmi_status(omap, reg);
>  }
>  
> -static int dwc3_omap_probe(struct platform_device *pdev)
> +/**
> + * dwc3_omap_uboot_init - dwc3 omap uboot initialization code
> + * @dev: struct dwc3_omap_device containing initialization data
> + *
> + * Entry point for dwc3 omap driver (equivalent to dwc3_omap_probe
> in linux
> + * kernel driver). Pointer to dwc3_omap_device should be passed
> containing
> + * base address and other initialization data. Returns '0' on
> success and
> + * a negative value on failure.
> + *
> + * Generally called from board_usb_init() implemented in board file.
> + */
> +int dwc3_omap_uboot_init(struct dwc3_omap_device *omap_dev)
>  {
> -	struct device_node	*node = pdev->dev.of_node;
> -
> -	struct dwc3_omap	*omap;
> -	struct resource		*res;
> -	struct device		*dev = &pdev->dev;
> -
> -	int			ret;
>  	u32			reg;
> -
> -	void __iomem		*base;
> -
> -	if (!node) {
> -		dev_err(dev, "device node not found\n");
> -		return -EINVAL;
> -	}
> +	struct device		*dev;
>  
>  	omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
>  	if (!omap)
>  		return -ENOMEM;
>  
> -	platform_set_drvdata(pdev, omap);
> -
> -	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> -	base = devm_ioremap_resource(dev, res);
> -	if (IS_ERR(base))
> -		return PTR_ERR(base);
> -
> -	omap->dev	= dev;
> -	omap->base	= base;
> -	dev->dma_mask	= &dwc3_omap_dma_mask;
> +	omap->base	= omap_dev->base;
>  
>  	dwc3_omap_map_offset(omap);
> -	dwc3_omap_set_utmi_mode(omap);
> +	dwc3_omap_set_utmi_mode(omap, omap_dev->utmi_mode);
>  
>  	/* check the DMA Status */
>  	reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG);
>  	omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE);
>  
> -	dwc3_omap_enable_irqs(omap);
> +	dwc3_omap_set_mailbox(omap, omap_dev->vbus_id_status);
>  
> -	ret = of_platform_populate(node, NULL, NULL, dev);
> -	if (ret) {
> -		dev_err(&pdev->dev, "failed to create dwc3 core\n");
> -		goto err1;
> -	}
> +	dwc3_omap_enable_irqs(omap);
>  
>  	return 0;
> -
> -err1:
> -	dwc3_omap_disable_irqs(omap);
> -
> -err0:
> -	return ret;
>  }
>  
> -static int dwc3_omap_remove(struct platform_device *pdev)
> +/**
> + * dwc3_omap_uboot_exit - dwc3 omap uboot cleanup code
> + * @index: index of this controller
> + *
> + * Performs cleanup of memory allocated in dwc3_omap_uboot_init
> + * (equivalent to dwc3_omap_remove in linux).
> + *
> + * Generally called from board file.
> + */
> +void dwc3_omap_uboot_exit(void)
>  {
> -	struct dwc3_omap	*omap = platform_get_drvdata(pdev);
> -
>  	dwc3_omap_disable_irqs(omap);
> -	device_for_each_child(&pdev->dev, NULL,
> dwc3_omap_remove_core);
> +	kfree(omap);
>  
>  	return 0;
>  }
>  
> -static const struct of_device_id of_dwc3_match[] = {
> -	{
> -		.compatible =	"ti,dwc3"
> -	},
> -	{
> -		.compatible =	"ti,am437x-dwc3"
> -	},
> -	{ },
> -};
> -MODULE_DEVICE_TABLE(of, of_dwc3_match);
> -
> -static struct platform_driver dwc3_omap_driver = {
> -	.probe		= dwc3_omap_probe,
> -	.remove		= dwc3_omap_remove,
> -	.driver		= {
> -		.name	= "omap-dwc3",
> -		.of_match_table	= of_dwc3_match,
> -	},
> -};
> -
> -module_platform_driver(dwc3_omap_driver);
> -
>  MODULE_ALIAS("platform:omap-dwc3");
>  MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
>  MODULE_LICENSE("GPL v2");
> diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
> index b313b64..99f8f38 100644
> --- a/include/dwc3-omap-uboot.h
> +++ b/include/dwc3-omap-uboot.h
> @@ -24,4 +24,7 @@ struct dwc3_omap_device {
>  	enum dwc3_omap_utmi_mode utmi_mode;
>  	enum omap_dwc3_vbus_id_status vbus_id_status;
>  };
> +
> +int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
> +void dwc3_omap_uboot_exit(void);
>  #endif /* __DWC3_OMAP_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 27/40] dwc3: dwc3-omap: add support for multiple dwc3-omap controllers
  2015-02-06  8:48 ` [U-Boot] [u-boot 27/40] dwc3: dwc3-omap: add support for multiple dwc3-omap controllers Kishon Vijay Abraham I
@ 2015-02-16 11:06   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:06 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added support for multiple dwc3 omap controllers. This gives uboot
> the capability to control multiple dwc3 omap controllers.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/dwc3-omap.c |   26 ++++++++++++++++++++------
>  include/dwc3-omap-uboot.h    |    3 ++-
>  2 files changed, 22 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-omap.c
> b/drivers/usb/dwc3/dwc3-omap.c index 30d7210..c8275c7 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -119,9 +119,11 @@ struct dwc3_omap {
>  	u32			irq0_offset;
>  
>  	u32			dma_status:1;
> +	struct list_head	list;
> +	u32			index;
>  };
>  
> -struct dwc3_omap *omap;
> +static LIST_HEAD(dwc3_omap_list);
>  
>  static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
>  {
> @@ -363,12 +365,14 @@ int dwc3_omap_uboot_init(struct
> dwc3_omap_device *omap_dev) {
>  	u32			reg;
>  	struct device		*dev;
> +	struct dwc3_omap	*omap;
>  
>  	omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
>  	if (!omap)
>  		return -ENOMEM;
>  
>  	omap->base	= omap_dev->base;
> +	omap->index	= omap_dev->index;
>  
>  	dwc3_omap_map_offset(omap);
>  	dwc3_omap_set_utmi_mode(omap, omap_dev->utmi_mode);
> @@ -380,6 +384,7 @@ int dwc3_omap_uboot_init(struct dwc3_omap_device
> *omap_dev) dwc3_omap_set_mailbox(omap, omap_dev->vbus_id_status);
>  
>  	dwc3_omap_enable_irqs(omap);
> +	list_add_tail(&omap->list, &dwc3_omap_list);
>  
>  	return 0;
>  }
> @@ -389,16 +394,25 @@ int dwc3_omap_uboot_init(struct
> dwc3_omap_device *omap_dev)
>   * @index: index of this controller
>   *
>   * Performs cleanup of memory allocated in dwc3_omap_uboot_init
> - * (equivalent to dwc3_omap_remove in linux).
> + * (equivalent to dwc3_omap_remove in linux). index of _this_
> controller
> + * should be passed and should match with the index passed in
> + * dwc3_omap_device during init.
>   *
>   * Generally called from board file.
>   */
> -void dwc3_omap_uboot_exit(void)
> +void dwc3_omap_uboot_exit(int index)
>  {
> -	dwc3_omap_disable_irqs(omap);
> -	kfree(omap);
> +	struct dwc3_omap *omap = NULL;
>  
> -	return 0;
> +	list_for_each_entry(omap, &dwc3_omap_list, list) {
> +		if (omap->index != index)
> +			continue;
> +
> +		dwc3_omap_disable_irqs(omap);
> +		list_del(&omap->list);
> +		kfree(omap);
> +		break;
> +	}
>  }
>  
>  MODULE_ALIAS("platform:omap-dwc3");
> diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
> index 99f8f38..29f02f8 100644
> --- a/include/dwc3-omap-uboot.h
> +++ b/include/dwc3-omap-uboot.h
> @@ -21,10 +21,11 @@ enum omap_dwc3_vbus_id_status {
>  
>  struct dwc3_omap_device {
>  	void *base;
> +	int index;
>  	enum dwc3_omap_utmi_mode utmi_mode;
>  	enum omap_dwc3_vbus_id_status vbus_id_status;
>  };
>  
>  int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
> -void dwc3_omap_uboot_exit(void);
> +void dwc3_omap_uboot_exit(int index);
>  #endif /* __DWC3_OMAP_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 28/40] usb: dwc3: dwc3-omap: add interrupt status API to check for interrupts
  2015-02-06  8:48 ` [U-Boot] [u-boot 28/40] usb: dwc3: dwc3-omap: add interrupt status API to check for interrupts Kishon Vijay Abraham I
@ 2015-02-16 11:07   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:07 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added an API to check for interrupt status. This API is generally
> called from board file to check for interrupt status.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/dwc3-omap.c |   20 ++++++++++++++++++++
>  include/dwc3-omap-uboot.h    |    1 +
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/dwc3-omap.c
> b/drivers/usb/dwc3/dwc3-omap.c index c8275c7..46af109 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -415,6 +415,26 @@ void dwc3_omap_uboot_exit(int index)
>  	}
>  }
>  
> +/**
> + * dwc3_omap_uboot_interrupt_status - check the status of interrupt
> + * @index: index of this controller
> + *
> + * Checks the status of interrupts and returns true if an interrupt
> + * is detected or false otherwise.
> + *
> + * Generally called from board file.
> + */
> +int dwc3_omap_uboot_interrupt_status(int index)
> +{
> +	struct dwc3_omap *omap = NULL;
> +
> +	list_for_each_entry(omap, &dwc3_omap_list, list)
> +		if (omap->index == index)
> +			return dwc3_omap_interrupt(-1, omap);
> +
> +	return 0;
> +}
> +
>  MODULE_ALIAS("platform:omap-dwc3");
>  MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
>  MODULE_LICENSE("GPL v2");
> diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h
> index 29f02f8..db002b9 100644
> --- a/include/dwc3-omap-uboot.h
> +++ b/include/dwc3-omap-uboot.h
> @@ -28,4 +28,5 @@ struct dwc3_omap_device {
>  
>  int dwc3_omap_uboot_init(struct dwc3_omap_device *dev);
>  void dwc3_omap_uboot_exit(int index);
> +int dwc3_omap_uboot_interrupt_status(int index);
>  #endif /* __DWC3_OMAP_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 29/40] usb: dwc3: TI PHY: PHY driver for dwc3 in TI platforms
  2015-02-06  8:48 ` [U-Boot] [u-boot 29/40] usb: dwc3: TI PHY: PHY driver for dwc3 in TI platforms Kishon Vijay Abraham I
@ 2015-02-16 11:13   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:13 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Added a single driver for both USB2 PHY programming and USB3 PHY
> programming.
> 
> USB3 PHY is taken from drivers/phy/phy-ti-pipe3.c in linux kernel.
> commit 56042e : phy: ti-pipe3: Fix suspend/resume and module reload.
> 
> USB2 PHY is taken from drivers/phy/phy-omap-usb2.c in linux kernel.
> commit eb82a3 : phy: omap-usb2: Balance pm_runtime_enable() on probe
> failure and remove.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/ti_usb_phy.c |  309
> +++++++++++++++++++++++++++++++++++++++++
> include/ti-usb-phy-uboot.h    |   22 +++ 2 files changed, 331
> insertions(+) create mode 100644 drivers/usb/dwc3/ti_usb_phy.c
>  create mode 100644 include/ti-usb-phy-uboot.h
> 
> diff --git a/drivers/usb/dwc3/ti_usb_phy.c
> b/drivers/usb/dwc3/ti_usb_phy.c new file mode 100644
> index 0000000..e6048eb
> --- /dev/null
> +++ b/drivers/usb/dwc3/ti_usb_phy.c
> @@ -0,0 +1,309 @@
> +/**
> + * ti_usb_phy.c - USB3 and USB3 PHY programming for dwc3
> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated -
> http://www.ti.com
> + *
> + * Author: Kishon Vijay Abraham I <kishon@ti.com>
> + *
> + * Taken from Linux Kernel v3.16 (drivers/phy/phy-ti-pipe3.c and
> + * drivers/phy/phy-omap-usb2.c) and ported to uboot.
> + *
> + * "commit 56042e : phy: ti-pipe3: Fix suspend/resume and module
> reload" for
> + * phy-ti-pipe3.c
> + *
> + * "commit eb82a3 : phy: omap-usb2: Balance pm_runtime_enable() on
> probe failure
> + * and remove" for phy-omap-usb2.c
> + *
> + * SPDX-License-Identifier:     GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <malloc.h>
> +#include <ti-usb-phy-uboot.h>
> +#include <usb/lin_gadget_compat.h>
> +#include <linux/ioport.h>
> +#include <asm/io.h>
> +#include <asm/arch/sys_proto.h>
> +
> +#include "linux-compat.h"
> +
> +#define PLL_STATUS		0x00000004
> +#define PLL_GO			0x00000008
> +#define PLL_CONFIGURATION1	0x0000000C
> +#define PLL_CONFIGURATION2	0x00000010
> +#define PLL_CONFIGURATION3	0x00000014
> +#define PLL_CONFIGURATION4	0x00000020
> +
> +#define PLL_REGM_MASK		0x001FFE00
> +#define PLL_REGM_SHIFT		0x9
> +#define PLL_REGM_F_MASK		0x0003FFFF
> +#define PLL_REGM_F_SHIFT	0x0
> +#define PLL_REGN_MASK		0x000001FE
> +#define PLL_REGN_SHIFT		0x1
> +#define PLL_SELFREQDCO_MASK	0x0000000E
> +#define PLL_SELFREQDCO_SHIFT	0x1
> +#define PLL_SD_MASK		0x0003FC00
> +#define PLL_SD_SHIFT		10
> +#define SET_PLL_GO		0x1
> +#define PLL_LDOPWDN		BIT(15)
> +#define PLL_TICOPWDN		BIT(16)
> +#define PLL_LOCK		0x2
> +#define PLL_IDLE		0x1
> +
> +#define OMAP_CTRL_DEV_PHY_PD				BIT(0)
> +#define OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_MASK
> 0x003FC000 +#define
> OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_SHIFT		0xE +
> +#define OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_MASK
> 0xFFC00000 +#define OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_SHIFT
> 0x16 +
> +#define OMAP_CTRL_USB3_PHY_TX_RX_POWERON	0x3
> +#define OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF	0x0
> +
> +#define OMAP_CTRL_USB2_PHY_PD			BIT(28)
> +
> +#define AM437X_CTRL_USB2_PHY_PD			BIT(0)
> +#define AM437X_CTRL_USB2_OTG_PD			BIT(1)
> +#define AM437X_CTRL_USB2_OTGVDET_EN		BIT(19)
> +#define AM437X_CTRL_USB2_OTGSESSEND_EN		BIT(20)
> +
> +static LIST_HEAD(ti_usb_phy_list);
> +typedef unsigned int u32;
> +
> +struct usb3_dpll_params {
> +	u16	m;
> +	u8	n;
> +	u8	freq:3;
> +	u8	sd;
> +	u32	mf;
> +};
> +
> +struct usb3_dpll_map {
> +	unsigned long rate;
> +	struct usb3_dpll_params params;
> +	struct usb3_dpll_map *dpll_map;
> +};
> +
> +struct ti_usb_phy {
> +	void __iomem *pll_ctrl_base;
> +	void __iomem *usb2_phy_power;
> +	void __iomem *usb3_phy_power;
> +	struct usb3_dpll_map *dpll_map;
> +	struct list_head list;
> +	int index;
> +};
> +
> +static struct usb3_dpll_map dpll_map_usb[] = {
> +	{12000000, {1250, 5, 4, 20, 0} },	/* 12 MHz */
> +	{16800000, {3125, 20, 4, 20, 0} },	/* 16.8 MHz */
> +	{19200000, {1172, 8, 4, 20, 65537} },	/* 19.2 MHz */
> +	{20000000, {1000, 7, 4, 10, 0} },	/* 20 MHz */
> +	{26000000, {1250, 12, 4, 20, 0} },	/* 26 MHz */
> +	{38400000, {3125, 47, 4, 20, 92843} },	/* 38.4 MHz */
> +	{ },					/* Terminator */
> +};
> +
> +static inline unsigned int ti_usb3_readl(void __iomem *base, u32
> offset) +{
> +	return readl(base + offset);
> +}
> +
> +static inline void ti_usb3_writel(void __iomem *base, u32 offset,
> u32 value) +{
> +	writel(value, base + offset);
> +}
> +
> +#ifndef CONFIG_AM43XX
> +static struct usb3_dpll_params *ti_usb3_get_dpll_params(struct
> ti_usb_phy *phy) +{
> +	unsigned long rate;
> +	struct usb3_dpll_map *dpll_map = phy->dpll_map;
> +
> +	rate = get_sys_clk_freq();
> +
> +	for (; dpll_map->rate; dpll_map++) {
> +		if (rate == dpll_map->rate)
> +			return &dpll_map->params;
> +	}
> +
> +	dev_err(phy->dev, "No DPLL configuration for %lu Hz SYS
> CLK\n", rate); +
> +	return NULL;
> +}
> +
> +static int ti_usb3_dpll_wait_lock(struct ti_usb_phy *phy)
> +{
> +	u32 val;
> +	do {
> +		val = ti_usb3_readl(phy->pll_ctrl_base, PLL_STATUS);
> +			if (val & PLL_LOCK)
> +				break;
> +	} while (1);
> +
> +	return 0;
> +}
> +
> +static int ti_usb3_dpll_program(struct ti_usb_phy *phy)
> +{
> +	u32			val;
> +	struct usb3_dpll_params	*dpll_params;
> +
> +	if (!phy->pll_ctrl_base)
> +		return -EINVAL;
> +
> +	dpll_params = ti_usb3_get_dpll_params(phy);
> +	if (!dpll_params)
> +		return -EINVAL;
> +
> +	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1);
> +	val &= ~PLL_REGN_MASK;
> +	val |= dpll_params->n << PLL_REGN_SHIFT;
> +	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val);
> +
> +	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION2);
> +	val &= ~PLL_SELFREQDCO_MASK;
> +	val |= dpll_params->freq << PLL_SELFREQDCO_SHIFT;
> +	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION2, val);
> +
> +	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION1);
> +	val &= ~PLL_REGM_MASK;
> +	val |= dpll_params->m << PLL_REGM_SHIFT;
> +	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION1, val);
> +
> +	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION4);
> +	val &= ~PLL_REGM_F_MASK;
> +	val |= dpll_params->mf << PLL_REGM_F_SHIFT;
> +	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION4, val);
> +
> +	val = ti_usb3_readl(phy->pll_ctrl_base, PLL_CONFIGURATION3);
> +	val &= ~PLL_SD_MASK;
> +	val |= dpll_params->sd << PLL_SD_SHIFT;
> +	ti_usb3_writel(phy->pll_ctrl_base, PLL_CONFIGURATION3, val);
> +
> +	ti_usb3_writel(phy->pll_ctrl_base, PLL_GO, SET_PLL_GO);
> +
> +	return ti_usb3_dpll_wait_lock(phy);
> +}
> +#endif
> +
> +void ti_usb2_phy_power(struct ti_usb_phy *phy, int on)
> +{
> +	u32 val;
> +
> +	val = readl(phy->usb2_phy_power);
> +
> +	if (on) {
> +#ifdef CONFIG_DRA7XX
> +		val &= ~OMAP_CTRL_DEV_PHY_PD;
> +#elif defined(CONFIG_AM43XX)
> +		val &= ~(AM437X_CTRL_USB2_PHY_PD |
> +			 AM437X_CTRL_USB2_OTG_PD);
> +		val |= (AM437X_CTRL_USB2_OTGVDET_EN |
> +			AM437X_CTRL_USB2_OTGSESSEND_EN);
> +#endif
> +	} else {
> +#ifdef CONFIG_DRA7XX
> +		val |= OMAP_CTRL_DEV_PHY_PD;
> +#elif defined(CONFIG_AM43XX)
> +		val &= ~(AM437X_CTRL_USB2_OTGVDET_EN |
> +			 AM437X_CTRL_USB2_OTGSESSEND_EN);
> +		val |= (AM437X_CTRL_USB2_PHY_PD |
> +			AM437X_CTRL_USB2_OTG_PD);
> +#endif
> +	}
> +	writel(val, phy->usb2_phy_power);
> +}
> +
> +#ifndef CONFIG_AM43XX
> +void ti_usb3_phy_power(struct ti_usb_phy *phy, int on)
> +{
> +	u32 val;
> +	u32 rate;
> +	rate = get_sys_clk_freq();
> +	rate = rate/1000000;
> +
> +	if (!phy->usb3_phy_power)
> +		return;
> +
> +	val = readl(phy->usb3_phy_power);
> +	if (on) {
> +		val &= ~(OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_MASK |
> +			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_MASK);
> +		val |= (OMAP_CTRL_USB3_PHY_TX_RX_POWERON) <<
> +			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_SHIFT;
> +		val |= rate <<
> +			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_FREQ_SHIFT;
> +	} else {
> +		val &= ~OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_MASK;
> +		val |= OMAP_CTRL_USB3_PHY_TX_RX_POWEROFF <<
> +			OMAP_CTRL_USB3_PHY_PWRCTL_CLK_CMD_SHIFT;
> +	}
> +	writel(val, phy->usb3_phy_power);
> +}
> +#endif
> +
> +/**
> + * ti_usb_phy_uboot_init - usb phy uboot initialization code
> + * @dev: struct ti_usb_phy_device containing initialization data
> + *
> + * Entry point for ti usb phy driver. This driver handles
> initialization
> + * of both usb2 phy and usb3 phy. Pointer to ti_usb_phy_device
> should be
> + * passed containing base address and other initialization data.
> + * Returns '0' on success and a negative value on failure.
> + *
> + * Generally called from board_usb_init() implemented in board file.
> + */
> +int ti_usb_phy_uboot_init(struct ti_usb_phy_device *dev)
> +{
> +	struct ti_usb_phy *phy;
> +
> +	phy = devm_kzalloc(NULL, sizeof(*phy), GFP_KERNEL);
> +	if (!phy) {
> +		dev_err(NULL, "unable to alloc mem for TI USB3
> PHY\n");
> +		return -ENOMEM;
> +	}
> +
> +	phy->dpll_map = dpll_map_usb;
> +	phy->index = dev->index;
> +	phy->pll_ctrl_base = dev->pll_ctrl_base;
> +	phy->usb2_phy_power = dev->usb2_phy_power;
> +	phy->usb3_phy_power = dev->usb3_phy_power;
> +
> +#ifndef CONFIG_AM43XX
> +	ti_usb3_dpll_program(phy);
> +	ti_usb3_phy_power(phy, 1);
> +#endif
> +	ti_usb2_phy_power(phy, 1);
> +	mdelay(150);
> +	list_add_tail(&phy->list, &ti_usb_phy_list);
> +
> +	return 0;
> +}
> +
> +/**
> + * ti_usb_phy_uboot_exit - usb phy uboot cleanup code
> + * @index: index of this controller
> + *
> + * Performs cleanup of memory allocated in ti_usb_phy_uboot_init.
> + * index of _this_ controller should be passed and should match with
> + * the index passed in ti_usb_phy_device during init.
> + *
> + * Generally called from board file.
> + */
> +void ti_usb_phy_uboot_exit(int index)
> +{
> +	struct ti_usb_phy *phy = NULL;
> +
> +	list_for_each_entry(phy, &ti_usb_phy_list, list) {
> +		if (phy->index != index)
> +			continue;
> +
> +		ti_usb2_phy_power(phy, 0);
> +#ifndef CONFIG_AM43XX
> +		ti_usb3_phy_power(phy, 0);
> +#endif
> +		list_del(&phy->list);
> +		kfree(phy);
> +		break;
> +	}
> +}
> diff --git a/include/ti-usb-phy-uboot.h b/include/ti-usb-phy-uboot.h
> new file mode 100644
> index 0000000..93f7101
> --- /dev/null
> +++ b/include/ti-usb-phy-uboot.h
> @@ -0,0 +1,22 @@
> +/* include/ti_usb_phy_uboot.h
> + *
> + * Copyright (c) 2014 Texas Instruments Incorporated -
> http://www.ti.com
> + *
> + * USB2 and USB3 PHY uboot init
> + *
> + * SPDX-License-Identifier:     GPL-2.0+
> + */
> +
> +#ifndef __TI_USB_PHY_UBOOT_H_
> +#define __TI_USB_PHY_UBOOT_H_
> +
> +struct ti_usb_phy_device {
> +	void *pll_ctrl_base;
> +	void *usb2_phy_power;
> +	void *usb3_phy_power;
> +	int index;
> +};
> +
> +int ti_usb_phy_uboot_init(struct ti_usb_phy_device *dev);
> +void ti_usb_phy_uboot_exit(int index);
> +#endif /* __TI_USB_PHY_UBOOT_H_ */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 30/40] dwc3: flush the buffers before using it
  2015-02-06  8:48 ` [U-Boot] [u-boot 30/40] dwc3: flush the buffers before using it Kishon Vijay Abraham I
@ 2015-02-16 11:39   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:39 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> In the linux kernel, non cacheable buffers are used. However in uboot
> since there are no APIs to allocate non cacheable memory, all
> the buffers should be flushed before using it.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/core.c   |    7 +++++++
>  drivers/usb/dwc3/ep0.c    |    6 ++++++
>  drivers/usb/dwc3/gadget.c |    5 +++++
>  drivers/usb/dwc3/io.h     |    6 ++++++
>  4 files changed, 24 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 5a8d5ea..4c3637f 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -769,11 +769,18 @@ void dwc3_uboot_exit(int index)
>  void dwc3_uboot_handle_interrupt(int index)
>  {
>  	struct dwc3 *dwc = NULL;
> +	int i;
> +	struct dwc3_event_buffer *evt;
>  
>  	list_for_each_entry(dwc, &dwc3_list, list) {
>  		if (dwc->index != index)
>  			continue;
>  
> +		for (i = 0; i < dwc->num_event_buffers; i++) {
> +			evt = dwc->ev_buffs[i];
> +			dwc3_flush_cache((int)evt->buf, evt->length);
> +		}
> +
>  		dwc3_gadget_uboot_handle_interrupt(dwc);
>  		break;
>  	}
> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index 803ba51..977d6d4 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -74,6 +74,9 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc,
> u8 epnum, dma_addr_t buf_dma, | DWC3_TRB_CTRL_IOC
>  			| DWC3_TRB_CTRL_ISP_IMI);
>  
> +	dwc3_flush_cache((int)buf_dma, len);
> +	dwc3_flush_cache((int)trb, sizeof(*trb));
> +
>  	memset(&params, 0, sizeof(params));
>  	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
>  	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
> @@ -774,6 +777,8 @@ static void dwc3_ep0_complete_data(struct dwc3
> *dwc, if (!r)
>  		return;
>  
> +	dwc3_flush_cache((int)trb, sizeof(*trb));
> +
>  	status = DWC3_TRB_SIZE_TRBSTS(trb->size);
>  	if (status == DWC3_TRBSTS_SETUP_PENDING) {
>  		dev_dbg(dwc->dev, "Setup Pending received");
> @@ -795,6 +800,7 @@ static void dwc3_ep0_complete_data(struct dwc3
> *dwc, transfer_size += (maxp - (transfer_size % maxp));
>  		transferred = min_t(u32, ur->length,
>  				transfer_size - length);
> +		dwc3_flush_cache((int)dwc->ep0_bounce,
> DWC3_EP0_BOUNCE_SIZE); memcpy(ur->buf, dwc->ep0_bounce, transferred);
>  	} else {
>  		transferred = ur->length - length;
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 1f97729..b68b6a4 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -244,6 +244,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep,
> struct dwc3_request *req, 
>  	list_del(&req->list);
>  	req->trb = NULL;
> +	dwc3_flush_cache((int)req->request.dma, req->request.length);
>  
>  	if (req->request.status == -EINPROGRESS)
>  		req->request.status = status;
> @@ -769,6 +770,9 @@ static void dwc3_prepare_one_trb(struct dwc3_ep
> *dep, trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id);
>  
>  	trb->ctrl |= DWC3_TRB_CTRL_HWO;
> +
> +	dwc3_flush_cache((int)dma, length);
> +	dwc3_flush_cache((int)trb, sizeof(*trb));
>  }
>  
>  /*
> @@ -1770,6 +1774,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3
> *dwc, struct dwc3_ep *dep, slot %= DWC3_TRB_NUM;
>  		trb = &dep->trb_pool[slot];
>  
> +		dwc3_flush_cache((int)trb, sizeof(*trb));
>  		ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
>  				event, status);
>  		if (ret)
> diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
> index b6da135..31606de 100644
> --- a/drivers/usb/dwc3/io.h
> +++ b/drivers/usb/dwc3/io.h
> @@ -20,6 +20,7 @@
>  
>  #include <asm/io.h>
>  
> +#define	CACHELINE_SIZE
> CONFIG_SYS_CACHELINE_SIZE static inline u32 dwc3_readl(void __iomem
> *base, u32 offset) {
>  	u32 offs = offset - DWC3_GLOBALS_REGS_START;
> @@ -47,4 +48,9 @@ static inline void dwc3_writel(void __iomem *base,
> u32 offset, u32 value) writel(value, base + offs);
>  }
>  
> +static inline void dwc3_flush_cache(int addr, int length)
> +{
> +	flush_dcache_range(addr & ~(CACHELINE_SIZE - 1),
> +			   ALIGN(addr + length, CACHELINE_SIZE));

Is this safe cache operation?

For example, the size of struct dwc3_trb is 16B [1] and the
CACHELINE_SIZE is equal to 64B or 32B.

Since trb buffer is not padded to CACHELINE_SIZE it is perfectly
correct to flush the CACHELINE_SIZE bytes, which may be allocated to
hold other data. In this way we would have data corruption very
difficult to fix.

Please consider s3c_udc_otg_xfer_dma.c for a reference (dwc2 gadget
driver): (some useful code snippets)

flush_dcache_range((unsigned long) ep->dma_buf,
		   (unsigned long) ep->dma_buf +
		   ROUND(ep->len, CONFIG_SYS_CACHELINE_SIZE));

req = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*req));
if (!req)
	return 0;


And the buffers:

ALLOC_CACHE_ALIGN_BUFFER(struct data_rsp_box, rsp,
			 sizeof(struct data_rsp_box)); 

			[automatic variable allocation]

DEFINE_CACHE_ALIGN_BUFFER(unsigned char, thor_rx_data_buf,
			  sizeof(struct rqt_box));

			[global one]

All relevant structures should be allocated with using above API. Then
we can use presented above flush_dcache_range() function (with
CONFIG_SYS_CACHELINE_SIZE alignment). 

> +}
>  #endif /* __DRIVERS_USB_DWC3_IO_H */



-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 31/40] usb: dwc3: ep0: preparation for implementing chained TRB
  2015-02-06  8:48 ` [U-Boot] [u-boot 31/40] usb: dwc3: ep0: preparation for implementing chained TRB Kishon Vijay Abraham I
@ 2015-02-16 11:40   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:40 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> No functional change. Modified few things so that there are no
> code duplication while implementing chained TRB.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/ep0.c |   20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index 977d6d4..fce2558 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -761,7 +761,10 @@ static void dwc3_ep0_complete_data(struct dwc3
> *dwc, struct usb_request	*ur;
>  	struct dwc3_trb		*trb;
>  	struct dwc3_ep		*ep0;
> -	u32			transferred;
> +	unsigned		transfer_size = 0;
> +	unsigned		maxp;
> +	void			*buf;
> +	u32			transferred = 0;
>  	u32			status;
>  	u32			length;
>  	u8			epnum;
> @@ -790,18 +793,19 @@ static void dwc3_ep0_complete_data(struct dwc3
> *dwc, }
>  
>  	ur = &r->request;
> +	buf = ur->buf;
>  
>  	length = trb->size & DWC3_TRB_SIZE_MASK;
>  
> -	if (dwc->ep0_bounced) {
> -		unsigned transfer_size = ur->length;
> -		unsigned maxp = ep0->endpoint.maxpacket;
> +	maxp = ep0->endpoint.maxpacket;
>  
> -		transfer_size += (maxp - (transfer_size % maxp));
> -		transferred = min_t(u32, ur->length,
> -				transfer_size - length);
> +	if (dwc->ep0_bounced) {
> +		transfer_size = roundup((ur->length - transfer_size),
> +					maxp);
> +		transferred = min_t(u32, ur->length - transferred,
> +				    transfer_size - length);
>  		dwc3_flush_cache((int)dwc->ep0_bounce,
> DWC3_EP0_BOUNCE_SIZE);
> -		memcpy(ur->buf, dwc->ep0_bounce, transferred);
> +		memcpy(buf, dwc->ep0_bounce, transferred);
>  	} else {
>  		transferred = ur->length - length;
>  	}

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0
  2015-02-06  8:48 ` [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0 Kishon Vijay Abraham I
@ 2015-02-16 11:42   ` Lukasz Majewski
  2015-02-16 12:01     ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:42 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> dwc3 can do only max packet aligned transfers. So in case request
> length is not max packet aligned and is bigger than
> DWC3_EP0_BOUNCE_SIZE two chained TRBs is required to handle the
> transfer.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/dwc3/ep0.c    |   72
> +++++++++++++++++++++++++++++++++------------
> drivers/usb/dwc3/gadget.c |    2 +- 2 files changed, 55
> insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index fce2558..c2fe0ec 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -48,7 +48,7 @@ static const char *dwc3_ep0_state_string(enum
> dwc3_ep0_state state) }
>  
>  static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum,
> dma_addr_t buf_dma,
> -		u32 len, u32 type)
> +				u32 len, u32 type, unsigned chain)
>  {
>  	struct dwc3_gadget_ep_cmd_params params;
>  	struct dwc3_trb			*trb;
> @@ -62,7 +62,10 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc,
> u8 epnum, dma_addr_t buf_dma, return 0;
>  	}
>  
> -	trb = dwc->ep0_trb;
> +	trb = &dwc->ep0_trb[dep->free_slot];
> +
> +	if (chain)
> +		dep->free_slot++;
>  
>  	trb->bpl = lower_32_bits(buf_dma);
>  	trb->bph = upper_32_bits(buf_dma);
> @@ -70,13 +73,20 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc,
> u8 epnum, dma_addr_t buf_dma, trb->ctrl = type;
>  
>  	trb->ctrl |= (DWC3_TRB_CTRL_HWO
> -			| DWC3_TRB_CTRL_LST
> -			| DWC3_TRB_CTRL_IOC
>  			| DWC3_TRB_CTRL_ISP_IMI);
>  
> +	if (chain)
> +		trb->ctrl |= DWC3_TRB_CTRL_CHN;
> +	else
> +		trb->ctrl |= (DWC3_TRB_CTRL_IOC
> +				| DWC3_TRB_CTRL_LST);
> +
>  	dwc3_flush_cache((int)buf_dma, len);
>  	dwc3_flush_cache((int)trb, sizeof(*trb));
>  
> +	if (chain)
> +		return 0;
> +
>  	memset(&params, 0, sizeof(params));
>  	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
>  	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
> @@ -289,7 +299,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
>  	int				ret;
>  
>  	ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
> -			DWC3_TRBCTL_CONTROL_SETUP);
> +				   DWC3_TRBCTL_CONTROL_SETUP, 0);
>  	WARN_ON(ret < 0);
>  }
>  
> @@ -799,6 +809,23 @@ static void dwc3_ep0_complete_data(struct dwc3
> *dwc, 
>  	maxp = ep0->endpoint.maxpacket;
>  
> +	/* Handle the first TRB before handling the bounce buffer if
> the request

	Minor comment - please fix above comment.

> +	 * length is greater than the bounce buffer size
> +	 */
> +	if (!IS_ALIGNED(ur->length, maxp) &&
> +	    ur->length > DWC3_EP0_BOUNCE_SIZE) {
> +		transfer_size = (ur->length / maxp) * maxp;
> +		transferred = transfer_size - length;
> +		buf = (u8 *)buf + transferred;
> +		ur->actual += transferred;
> +
> +		trb++;
> +		dwc3_flush_cache((int)trb, sizeof(*trb));
> +		length = trb->size & DWC3_TRB_SIZE_MASK;
> +
> +		ep0->free_slot = 0;
> +	}
> +
>  	if (dwc->ep0_bounced) {
>  		transfer_size = roundup((ur->length - transfer_size),
>  					maxp);
> @@ -827,7 +854,7 @@ static void dwc3_ep0_complete_data(struct dwc3
> *dwc, 
>  			ret = dwc3_ep0_start_trans(dwc, epnum,
>  					dwc->ctrl_req_addr, 0,
> -					DWC3_TRBCTL_CONTROL_DATA);
> +					DWC3_TRBCTL_CONTROL_DATA, 0);
>  			WARN_ON(ret < 0);
>  		}
>  	}
> @@ -908,11 +935,11 @@ static void __dwc3_ep0_do_control_data(struct
> dwc3 *dwc, 
>  	if (req->request.length == 0) {
>  		ret = dwc3_ep0_start_trans(dwc, dep->number,
> -				dwc->ctrl_req_addr, 0,
> -				DWC3_TRBCTL_CONTROL_DATA);
> -	} else if (!IS_ALIGNED(req->request.length,
> dep->endpoint.maxpacket)
> -			&& (dep->number == 0)) {
> -		u32	transfer_size;
> +					   dwc->ctrl_req_addr, 0,
> +					   DWC3_TRBCTL_CONTROL_DATA,
> 0);
> +	} else if (!IS_ALIGNED(req->request.length,
> dep->endpoint.maxpacket) &&
> +			(dep->number == 0)) {
> +		u32	transfer_size = 0;
>  		u32	maxpacket;
>  
>  		ret = usb_gadget_map_request(&dwc->gadget,
> &req->request, @@ -922,10 +949,18 @@ static void
> __dwc3_ep0_do_control_data(struct dwc3 *dwc, return;
>  		}
>  
> -		WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
> -
>  		maxpacket = dep->endpoint.maxpacket;
> -		transfer_size = roundup(req->request.length,
> maxpacket);
> +		if (req->request.length > DWC3_EP0_BOUNCE_SIZE) {
> +			transfer_size = (req->request.length /
> maxpacket) *
> +						maxpacket;
> +			ret = dwc3_ep0_start_trans(dwc, dep->number,
> +						   req->request.dma,
> +						   transfer_size,
> +
> DWC3_TRBCTL_CONTROL_DATA, 1);
> +		}
> +
> +		transfer_size = roundup((req->request.length -
> transfer_size),
> +					maxpacket);
>  
>  		dwc->ep0_bounced = true;
>  
> @@ -935,8 +970,8 @@ static void __dwc3_ep0_do_control_data(struct
> dwc3 *dwc,
>  		 * TRBs to handle the transfer.
>  		 */
>  		ret = dwc3_ep0_start_trans(dwc, dep->number,
> -				dwc->ep0_bounce_addr, transfer_size,
> -				DWC3_TRBCTL_CONTROL_DATA);
> +					   dwc->ep0_bounce_addr,
> transfer_size,
> +					   DWC3_TRBCTL_CONTROL_DATA,
> 0); } else {
>  		ret = usb_gadget_map_request(&dwc->gadget,
> &req->request, dep->number);
> @@ -946,7 +981,8 @@ static void __dwc3_ep0_do_control_data(struct
> dwc3 *dwc, }
>  
>  		ret = dwc3_ep0_start_trans(dwc, dep->number,
> req->request.dma,
> -				req->request.length,
> DWC3_TRBCTL_CONTROL_DATA);
> +					   req->request.length,
> +					   DWC3_TRBCTL_CONTROL_DATA,
> 0); }
>  
>  	WARN_ON(ret < 0);
> @@ -961,7 +997,7 @@ static int dwc3_ep0_start_control_status(struct
> dwc3_ep *dep) : DWC3_TRBCTL_CONTROL_STATUS2;
>  
>  	return dwc3_ep0_start_trans(dwc, dep->number,
> -			dwc->ctrl_req_addr, 0, type);
> +			dwc->ctrl_req_addr, 0, type, 0);
>  }
>  
>  static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct
> dwc3_ep *dep) diff --git a/drivers/usb/dwc3/gadget.c
> b/drivers/usb/dwc3/gadget.c index b68b6a4..01bc83b 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2580,7 +2580,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
>  		goto err0;
>  	}
>  
> -	dwc->ep0_trb = dma_alloc_coherent(sizeof(*dwc->ep0_trb),
> +	dwc->ep0_trb = dma_alloc_coherent(sizeof(*dwc->ep0_trb) * 2,
>  					  (unsigned long
> *)&dwc->ep0_trb_addr); if (!dwc->ep0_trb) {
>  		dev_err(dwc->dev, "failed to allocate ep0 trb\n");

Apart minor comment issue,

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 33/40] usb: dwc3: Makefile: Make dwc3 driver compile in u-boot
  2015-02-06  8:48 ` [U-Boot] [u-boot 33/40] usb: dwc3: Makefile: Make dwc3 driver compile in u-boot Kishon Vijay Abraham I
@ 2015-02-16 11:43   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:43 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Now that the entire dwc3 driver is adapted to compile with uboot
> build, modify the Makefiles so that the dwc3 driver can be built.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  Makefile                        |    2 ++
>  drivers/usb/dwc3/Makefile       |   35
> +++-------------------------------- drivers/usb/gadget/udc/Makefile
> |    2 +- 3 files changed, 6 insertions(+), 33 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 1eb6821..ca0fd76 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -632,8 +632,10 @@ libs-y += drivers/spi/
>  libs-$(CONFIG_FMAN_ENET) += drivers/net/fm/
>  libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
>  libs-y += drivers/serial/
> +libs-y += drivers/usb/dwc3/
>  libs-y += drivers/usb/eth/
>  libs-y += drivers/usb/gadget/
> +libs-y += drivers/usb/gadget/udc/
>  libs-y += drivers/usb/host/
>  libs-y += drivers/usb/musb/
>  libs-y += drivers/usb/musb-new/
> diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
> index afaa767..e455a52 100644
> --- a/drivers/usb/dwc3/Makefile
> +++ b/drivers/usb/dwc3/Makefile
> @@ -1,37 +1,8 @@
> -ccflags-$(CONFIG_USB_DWC3_DEBUG)	:= -DDEBUG
> -ccflags-$(CONFIG_USB_DWC3_VERBOSE)	+= -DVERBOSE_DEBUG
> -
>  obj-$(CONFIG_USB_DWC3)			+= dwc3.o
>  
> -dwc3-y					:= core.o debug.o
> -
> -ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST)
> $(CONFIG_USB_DWC3_DUAL_ROLE)),)
> -	dwc3-y				+= host.o
> -endif
> -
> -ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET)
> $(CONFIG_USB_DWC3_DUAL_ROLE)),)
> -	dwc3-y				+= gadget.o ep0.o
> -endif
> -
> -ifneq ($(CONFIG_DEBUG_FS),)
> -	dwc3-y				+= debugfs.o
> -endif
> +dwc3-y					:= core.o
>  
> -##
> -# Platform-specific glue layers go here
> -#
> -# NOTICE: Make sure your glue layer doesn't depend on anything
> -# which is arch-specific and that it compiles on all situations.
> -#
> -# We want to keep this requirement in order to be able to compile
> -# the entire driver (with all its glue layers) on several
> architectures -# and make sure it compiles fine. This will also help
> with allmodconfig -# and allyesconfig builds.
> -##
> +dwc3-y					+= gadget.o ep0.o
>  
>  obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
> -obj-$(CONFIG_USB_DWC3_EXYNOS)		+= dwc3-exynos.o
> -obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
> -obj-$(CONFIG_USB_DWC3_KEYSTONE)		+= dwc3-keystone.o
> -obj-$(CONFIG_USB_DWC3_QCOM)		+= dwc3-qcom.o
> -obj-$(CONFIG_USB_DWC3_ST)		+= dwc3-st.o
> +obj-$(CONFIG_USB_DWC3_PHY_OMAP)		+= ti_usb_phy.o
> diff --git a/drivers/usb/gadget/udc/Makefile
> b/drivers/usb/gadget/udc/Makefile index be265aa..12380f4 100644
> --- a/drivers/usb/gadget/udc/Makefile
> +++ b/drivers/usb/gadget/udc/Makefile
> @@ -1,4 +1,4 @@
>  #
>  # USB peripheral controller drivers
>  #
> -obj-$(CONFIG_USB_GADGET)	+= udc-core.o
> +obj-$(CONFIG_USB_DWC3_GADGET)	+= udc-core.o

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 34/40] usb: gadget: defer setting maxpacket till ->setup()
  2015-02-06  8:48 ` [U-Boot] [u-boot 34/40] usb: gadget: defer setting maxpacket till ->setup() Kishon Vijay Abraham I
@ 2015-02-16 11:44   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:44 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Taken from linux kernel with commit
> commit 765f5b830e547229bb752e7b232ee83e2b3d49d5
> Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Date:   Thu Jun 23 14:26:11 2011 +0200
> 
> usb: gadget: defer setting maxpacket till ->setup()
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  drivers/usb/gadget/composite.c |    4 +++-
>  drivers/usb/gadget/ether.c     |    2 +-
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/composite.c
> b/drivers/usb/gadget/composite.c index a4c5606..5cedc9e 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c
> @@ -283,7 +283,7 @@ static void device_qual(struct usb_composite_dev
> *cdev) qual->bDeviceSubClass = cdev->desc.bDeviceSubClass;
>  	qual->bDeviceProtocol = cdev->desc.bDeviceProtocol;
>  	/* ASSUME same EP0 fifo size at both speeds */
> -	qual->bMaxPacketSize0 = cdev->desc.bMaxPacketSize0;
> +	qual->bMaxPacketSize0 = cdev->gadget->ep0->maxpacket;
>  	qual->bNumConfigurations = count_configs(cdev,
> USB_DT_DEVICE_QUALIFIER); qual->bRESERVED = 0;
>  }
> @@ -736,6 +736,8 @@ composite_setup(struct usb_gadget *gadget, const
> struct usb_ctrlrequest *ctrl) case USB_DT_DEVICE:
>  			cdev->desc.bNumConfigurations =
>  				count_configs(cdev, USB_DT_DEVICE);
> +			cdev->desc.bMaxPacketSize0 =
> +				cdev->gadget->ep0->maxpacket;
>  			value = min(w_length, (u16) sizeof
> cdev->desc); memcpy(req->buf, &cdev->desc, value);
>  			break;
> diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
> index ba442d5..8ccf9b0 100644
> --- a/drivers/usb/gadget/ether.c
> +++ b/drivers/usb/gadget/ether.c
> @@ -1249,6 +1249,7 @@ eth_setup(struct usb_gadget *gadget, const
> struct usb_ctrlrequest *ctrl) switch (wValue >> 8) {
>  
>  		case USB_DT_DEVICE:
> +			device_desc.bMaxPacketSize0 =
> gadget->ep0->maxpacket; value = min(wLength, (u16) sizeof
> device_desc); memcpy(req->buf, &device_desc, value);
>  			break;
> @@ -2133,7 +2134,6 @@ autoconf_fail:
>  		hs_subset_descriptors();
>  	}
>  
> -	device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
>  	usb_gadget_set_selfpowered(gadget);
>  
>  	/* For now RNDIS is always a second config */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 35/40] common: cmd_dfu: invoke board_usb_cleanup() for cleaning up
  2015-02-06  8:48 ` [U-Boot] [u-boot 35/40] common: cmd_dfu: invoke board_usb_cleanup() for cleaning up Kishon Vijay Abraham I
@ 2015-02-16 11:47   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:47 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Invoked board_usb_cleanup for cleaning up initialized USB. It
> will be invoked if the user enterts ctrl-C.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  common/cmd_dfu.c |    1 +
>  common/usb.c     |    7 +++++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
> index e975abe..161d38b 100644
> --- a/common/cmd_dfu.c
> +++ b/common/cmd_dfu.c
> @@ -68,6 +68,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int
> argc, char * const argv[]) }
>  exit:
>  	g_dnl_unregister();
> +	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
>  done:
>  	dfu_free_entities();
>  
> diff --git a/common/usb.c b/common/usb.c
> index 736cd9f..c7cc1b1 100644
> --- a/common/usb.c
> +++ b/common/usb.c
> @@ -1063,4 +1063,11 @@ int board_usb_init(int index, enum
> usb_init_type init) {
>  	return 0;
>  }
> +
> +

Extra blank line is not needed here.

> +__weak
> +int board_usb_cleanup(int index, enum usb_init_type init)
> +{
> +	return 0;
> +}
>  /* EOF */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 36/40] board: ti: DRA7: added USB initializtion code
  2015-02-06  8:48 ` [U-Boot] [u-boot 36/40] board: ti: DRA7: added USB initializtion code Kishon Vijay Abraham I
@ 2015-02-16 11:49   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:49 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Implemented board_usb_init(), board_usb_cleanup() and
> usb_gadget_handle_interrupts() in dra7xx board file that
> can be invoked by various gadget drivers.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/include/asm/arch-omap5/omap.h |   12 ++++
>  board/ti/dra7xx/evm.c                  |  109
> ++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+)
> 
> diff --git a/arch/arm/include/asm/arch-omap5/omap.h
> b/arch/arm/include/asm/arch-omap5/omap.h index e218159..e844bfb 100644
> --- a/arch/arm/include/asm/arch-omap5/omap.h
> +++ b/arch/arm/include/asm/arch-omap5/omap.h
> @@ -33,6 +33,18 @@
>  #define CONTROL_ID_CODE		CONTROL_CORE_ID_CODE
>  #endif
>  
> +#ifdef CONFIG_DRA7XX
> +#define DRA7_USB_OTG_SS1_BASE		0x48890000
> +#define DRA7_USB_OTG_SS1_GLUE_BASE	0x48880000
> +#define DRA7_USB3_PHY1_PLL_CTRL		0x4A084C00
> +#define DRA7_USB3_PHY1_POWER		0x4A002370
> +#define DRA7_USB2_PHY1_POWER		0x4A002300
> +
> +#define DRA7_USB_OTG_SS2_BASE		0x488D0000
> +#define DRA7_USB_OTG_SS2_GLUE_BASE	0x488C0000
> +#define DRA7_USB2_PHY2_POWER		0x4A002E74
> +#endif
> +
>  /* To be verified */
>  #define OMAP5430_CONTROL_ID_CODE_ES1_0		0x0B94202F
>  #define OMAP5430_CONTROL_ID_CODE_ES2_0          0x1B94202F
> diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
> index 6522241..284775c 100644
> --- a/board/ti/dra7xx/evm.c
> +++ b/board/ti/dra7xx/evm.c
> @@ -14,11 +14,16 @@
>  #include <palmas.h>
>  #include <sata.h>
>  #include <asm/gpio.h>
> +#include <usb.h>
> +#include <linux/usb/gadget.h>
>  #include <asm/arch/gpio.h>
>  #include <asm/arch/sys_proto.h>
>  #include <asm/arch/mmc_host_def.h>
>  #include <asm/arch/sata.h>
>  #include <environment.h>
> +#include <dwc3-uboot.h>
> +#include <dwc3-omap-uboot.h>
> +#include <ti-usb-phy-uboot.h>
>  
>  #include "mux_data.h"
>  
> @@ -123,6 +128,110 @@ int board_mmc_init(bd_t *bis)
>  }
>  #endif
>  
> +#ifdef CONFIG_USB_DWC3
> +static struct dwc3_device usb_otg_ss1 = {
> +	.maximum_speed = USB_SPEED_SUPER,
> +	.base = DRA7_USB_OTG_SS1_BASE,
> +	.tx_fifo_resize = false,
> +	.index = 0,
> +};
> +
> +static struct dwc3_omap_device usb_otg_ss1_glue = {
> +	.base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
> +	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
> +	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
> +	.index = 0,
> +};
> +
> +static struct ti_usb_phy_device usb_phy1_device = {
> +	.pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
> +	.usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
> +	.usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
> +	.index = 0,
> +};
> +
> +static struct dwc3_device usb_otg_ss2 = {
> +	.maximum_speed = USB_SPEED_SUPER,
> +	.base = DRA7_USB_OTG_SS2_BASE,
> +	.tx_fifo_resize = false,
> +	.index = 1,
> +};
> +
> +static struct dwc3_omap_device usb_otg_ss2_glue = {
> +	.base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
> +	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
> +	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
> +	.index = 1,
> +};
> +
> +static struct ti_usb_phy_device usb_phy2_device = {
> +	.usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
> +	.index = 1,
> +};
> +
> +int board_usb_init(int index, enum usb_init_type init)
> +{
> +	switch (index) {
> +	case 0:
> +		if (init == USB_INIT_DEVICE) {
> +			usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
> +			usb_otg_ss1_glue.vbus_id_status =
> OMAP_DWC3_VBUS_VALID;
> +		} else {
> +			usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
> +			usb_otg_ss1_glue.vbus_id_status =
> OMAP_DWC3_ID_GROUND;
> +		}
> +
> +		ti_usb_phy_uboot_init(&usb_phy1_device);
> +		dwc3_omap_uboot_init(&usb_otg_ss1_glue);
> +		dwc3_uboot_init(&usb_otg_ss1);
> +		break;
> +	case 1:
> +		if (init == USB_INIT_DEVICE) {
> +			usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
> +			usb_otg_ss2_glue.vbus_id_status =
> OMAP_DWC3_VBUS_VALID;
> +		} else {
> +			usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
> +			usb_otg_ss2_glue.vbus_id_status =
> OMAP_DWC3_ID_GROUND;
> +		}
> +
> +		ti_usb_phy_uboot_init(&usb_phy2_device);
> +		dwc3_omap_uboot_init(&usb_otg_ss2_glue);
> +		dwc3_uboot_init(&usb_otg_ss2);
> +		break;
> +	default:
> +		printf("Invalid Controller Index\n");
> +	}
> +
> +	return 0;
> +}
> +
> +int board_usb_cleanup(int index, enum usb_init_type init)
> +{
> +	switch (index) {
> +	case 0:
> +	case 1:
> +		ti_usb_phy_uboot_exit(index);
> +		dwc3_uboot_exit(index);
> +		dwc3_omap_uboot_exit(index);
> +		break;
> +	default:
> +		printf("Invalid Controller Index\n");
> +	}
> +	return 0;
> +}
> +
> +int usb_gadget_handle_interrupts(void)
> +{
> +	u32 status;
> +
> +	status = dwc3_omap_uboot_interrupt_status(0);
> +	if (status)
> +		dwc3_uboot_handle_interrupt(0);
> +
> +	return 0;
> +}
> +#endif
> +
>  #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
>  int spl_start_uboot(void)
>  {

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 37/40] include: configs: Enable DWC3 and DFU in DRA7xx
  2015-02-06  8:48 ` [U-Boot] [u-boot 37/40] include: configs: Enable DWC3 and DFU in DRA7xx Kishon Vijay Abraham I
@ 2015-02-16 11:50   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:50 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Enabled dwc3, dwc3-omap and PHY for dwc3 are enabled. Also enabled
> support for DFU.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  include/configs/dra7xx_evm.h      |   63
> +++++++++++++++++++++++++++++++++++++
> include/configs/ti_omap5_common.h |    5 +++ 2 files changed, 68
> insertions(+)
> 
> diff --git a/include/configs/dra7xx_evm.h
> b/include/configs/dra7xx_evm.h index 174a711..75b55d9 100644
> --- a/include/configs/dra7xx_evm.h
> +++ b/include/configs/dra7xx_evm.h
> @@ -43,6 +43,47 @@
>  	"uuid_disk=${uuid_gpt_disk};" \
>  	"name=rootfs,start=2MiB,size=-,uuid=${uuid_gpt_rootfs}"
>  
> +#define DFU_ALT_INFO_MMC \
> +	"dfu_alt_info_mmc=" \
> +	"boot part 0 1;" \
> +	"rootfs part 0 2;" \
> +	"MLO fat 0 1;" \
> +	"MLO.raw raw 0x100 0x100;" \
> +	"u-boot.img.raw raw 0x300 0x400;" \
> +	"spl-os-args.raw raw 0x80 0x80;" \
> +	"spl-os-image.raw raw 0x900 0x2000;" \
> +	"spl-os-args fat 0 1;" \
> +	"spl-os-image fat 0 1;" \
> +	"u-boot.img fat 0 1;" \
> +	"uEnv.txt fat 0 1\0"
> +
> +#define DFU_ALT_INFO_EMMC \
> +	"dfu_alt_info_emmc=" \
> +	"rawemmc raw 0 3751936;" \
> +	"boot part 1 1;" \
> +	"rootfs part 1 2;" \
> +	"MLO fat 1 1;" \
> +	"MLO.raw raw 0x100 0x100;" \
> +	"u-boot.img.raw raw 0x300 0x400;" \
> +	"spl-os-args.raw raw 0x80 0x80;" \
> +	"spl-os-image.raw raw 0x900 0x2000;" \
> +	"spl-os-args fat 1 1;" \
> +	"spl-os-image fat 1 1;" \
> +	"u-boot.img fat 1 1;" \
> +	"uEnv.txt fat 1 1\0"
> +
> +#define DFU_ALT_INFO_RAM \
> +	"dfu_alt_info_ram=" \
> +	"kernel ram 0x80200000 0x4000000;" \
> +	"fdt ram 0x80f80000 0x80000;" \
> +	"ramdisk ram 0x81000000 0x4000000\0"
> +
> +#define DFUARGS \
> +	"dfu_bufsiz=0x10000\0" \
> +	DFU_ALT_INFO_MMC \
> +	DFU_ALT_INFO_EMMC \
> +	DFU_ALT_INFO_RAM
> +
>  #include <configs/ti_omap5_common.h>
>  
>  /* Enhance our eMMC support / experience. */
> @@ -132,6 +173,28 @@
>  #define CONFIG_OMAP_USB_PHY
>  #define CONFIG_OMAP_USB2PHY2_HOST
>  
> +/* USB GADGET */
> +#define CONFIG_USB_DWC3_PHY_OMAP
> +#define CONFIG_USB_DWC3_OMAP
> +#define CONFIG_USB_DWC3
> +#define CONFIG_USB_DWC3_GADGET
> +
> +#define CONFIG_USB_GADGET
> +#define CONFIG_USBDOWNLOAD_GADGET
> +#define CONFIG_USB_GADGET_VBUS_DRAW 2
> +#define CONFIG_G_DNL_MANUFACTURER "Texas Instruments"
> +#define CONFIG_G_DNL_VENDOR_NUM 0x0403
> +#define CONFIG_G_DNL_PRODUCT_NUM 0xBD00
> +#define CONFIG_USB_GADGET_DUALSPEED
> +
> +/* USB Device Firmware Update support */
> +#define CONFIG_DFU_FUNCTION
> +#define CONFIG_DFU_RAM
> +#define CONFIG_CMD_DFU
> +
> +#define CONFIG_DFU_MMC
> +#define CONFIG_DFU_RAM
> +
>  /* SATA */
>  #define CONFIG_BOARD_LATE_INIT
>  #define CONFIG_CMD_SCSI
> diff --git a/include/configs/ti_omap5_common.h
> b/include/configs/ti_omap5_common.h index c47651d..cdc539c 100644
> --- a/include/configs/ti_omap5_common.h
> +++ b/include/configs/ti_omap5_common.h
> @@ -65,6 +65,10 @@
>  #define PARTS_DEFAULT
>  #endif
>  
> +#ifndef DFUARGS
> +#define DFUARGS
> +#endif
> +
>  #define CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
>  #define CONFIG_EXTRA_ENV_SETTINGS \
>  	DEFAULT_LINUX_BOOT_ENV \
> @@ -122,6 +126,7 @@
>  		"if test $fdtfile = undefined; then " \
>  			"echo WARNING: Could not determine device
> tree to use; fi; \0" \ "loadfdt=load mmc ${bootpart} ${fdtaddr}
> ${bootdir}/${fdtfile};\0" \
> +	DFUARGS \
>  
>  #define CONFIG_BOOTCOMMAND \
>  	"run findfdt; " \

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 38/40] board: ti: AM43xx: added USB initializtion code
  2015-02-06  8:48 ` [U-Boot] [u-boot 38/40] board: ti: AM43xx: added USB initializtion code Kishon Vijay Abraham I
@ 2015-02-16 11:50   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:50 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Implemented board_usb_init(), board_usb_cleanup() and
> usb_gadget_handle_interrupts() in am43xx board file that
> can be invoked by various gadget drivers.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  arch/arm/include/asm/arch-am33xx/hardware_am43xx.h |    9 ++
>  board/ti/am43xx/board.c                            |  108
> ++++++++++++++++++++ 2 files changed, 117 insertions(+)
> 
> diff --git a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
> b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h index
> 5f259da..110f329 100644 ---
> a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h +++
> b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h @@ -61,6 +61,15
> @@ /* RTC base address */
>  #define RTC_BASE			0x44E3E000
>  
> +/* USB OTG */
> +#define USB_OTG_SS1_BASE		0x48390000
> +#define USB_OTG_SS1_GLUE_BASE		0x48380000
> +#define USB2_PHY1_POWER			0x44E10620
> +
> +#define USB_OTG_SS2_BASE		0x483D0000
> +#define USB_OTG_SS2_GLUE_BASE		0x483C0000
> +#define USB2_PHY2_POWER			0x44E10628
> +
>  /* USB Clock Control */
>  #define PRM_PER_USB_OTG_SS0_CLKCTRL (CM_PER + 0x260)
>  #define PRM_PER_USB_OTG_SS1_CLKCTRL (CM_PER + 0x268)
> diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
> index a1c3c17..a8796b1 100644
> --- a/board/ti/am43xx/board.c
> +++ b/board/ti/am43xx/board.c
> @@ -12,6 +12,7 @@
>  #include <i2c.h>
>  #include <asm/errno.h>
>  #include <spl.h>
> +#include <usb.h>
>  #include <asm/arch/clock.h>
>  #include <asm/arch/sys_proto.h>
>  #include <asm/arch/mux.h>
> @@ -23,6 +24,10 @@
>  #include <power/tps65218.h>
>  #include <miiphy.h>
>  #include <cpsw.h>
> +#include <linux/usb/gadget.h>
> +#include <dwc3-uboot.h>
> +#include <dwc3-omap-uboot.h>
> +#include <ti-usb-phy-uboot.h>
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> @@ -686,6 +691,109 @@ int board_late_init(void)
>  }
>  #endif
>  
> +#ifdef CONFIG_USB_DWC3
> +static struct dwc3_device usb_otg_ss1 = {
> +	.maximum_speed = USB_SPEED_HIGH,
> +	.base = USB_OTG_SS1_BASE,
> +	.tx_fifo_resize = false,
> +	.index = 0,
> +};
> +
> +static struct dwc3_omap_device usb_otg_ss1_glue = {
> +	.base = (void *)USB_OTG_SS1_GLUE_BASE,
> +	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
> +	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
> +	.index = 0,
> +};
> +
> +static struct ti_usb_phy_device usb_phy1_device = {
> +	.usb2_phy_power = (void *)USB2_PHY1_POWER,
> +	.index = 0,
> +};
> +
> +static struct dwc3_device usb_otg_ss2 = {
> +	.maximum_speed = USB_SPEED_HIGH,
> +	.base = USB_OTG_SS2_BASE,
> +	.tx_fifo_resize = false,
> +	.index = 1,
> +};
> +
> +static struct dwc3_omap_device usb_otg_ss2_glue = {
> +	.base = (void *)USB_OTG_SS2_GLUE_BASE,
> +	.utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
> +	.vbus_id_status = OMAP_DWC3_VBUS_VALID,
> +	.index = 1,
> +};
> +
> +static struct ti_usb_phy_device usb_phy2_device = {
> +	.usb2_phy_power = (void *)USB2_PHY2_POWER,
> +	.index = 1,
> +};
> +
> +int board_usb_init(int index, enum usb_init_type init)
> +{
> +	switch (index) {
> +	case 0:
> +		if (init == USB_INIT_DEVICE) {
> +			usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
> +			usb_otg_ss1_glue.vbus_id_status =
> OMAP_DWC3_VBUS_VALID;
> +		} else {
> +			usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
> +			usb_otg_ss1_glue.vbus_id_status =
> OMAP_DWC3_ID_GROUND;
> +		}
> +
> +		dwc3_omap_uboot_init(&usb_otg_ss1_glue);
> +		ti_usb_phy_uboot_init(&usb_phy1_device);
> +		dwc3_uboot_init(&usb_otg_ss1);
> +		break;
> +	case 1:
> +		if (init == USB_INIT_DEVICE) {
> +			usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
> +			usb_otg_ss2_glue.vbus_id_status =
> OMAP_DWC3_VBUS_VALID;
> +		} else {
> +			usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
> +			usb_otg_ss2_glue.vbus_id_status =
> OMAP_DWC3_ID_GROUND;
> +		}
> +
> +		ti_usb_phy_uboot_init(&usb_phy2_device);
> +		dwc3_omap_uboot_init(&usb_otg_ss2_glue);
> +		dwc3_uboot_init(&usb_otg_ss2);
> +		break;
> +	default:
> +		printf("Invalid Controller Index\n");
> +	}
> +
> +	return 0;
> +}
> +
> +int board_usb_cleanup(int index, enum usb_init_type init)
> +{
> +	switch (index) {
> +	case 0:
> +	case 1:
> +		ti_usb_phy_uboot_exit(index);
> +		dwc3_uboot_exit(index);
> +		dwc3_omap_uboot_exit(index);
> +		break;
> +	default:
> +		printf("Invalid Controller Index\n");
> +	}
> +
> +	return 0;
> +}
> +
> +int usb_gadget_handle_interrupts(void)
> +{
> +	u32 status;
> +
> +	status = dwc3_omap_uboot_interrupt_status(0);
> +	if (status)
> +		dwc3_uboot_handle_interrupt(0);
> +
> +	return 0;
> +}
> +#endif
> +
>  #ifdef CONFIG_DRIVER_TI_CPSW
>  
>  static void cpsw_control(int enabled)

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 39/40] include: configs: Enable DWC3 and DFU in AM43xx
  2015-02-06  8:48 ` [U-Boot] [u-boot 39/40] include: configs: Enable DWC3 and DFU in AM43xx Kishon Vijay Abraham I
@ 2015-02-16 11:53   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:53 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Enabled dwc3, dwc3-omap and PHY for dwc3 are enabled. Also enabled
> support for DFU.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  include/configs/am43xx_evm.h |   61
> +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60
> insertions(+), 1 deletion(-)
> 
> diff --git a/include/configs/am43xx_evm.h
> b/include/configs/am43xx_evm.h index 4472c3e..3fcd99e 100644
> --- a/include/configs/am43xx_evm.h
> +++ b/include/configs/am43xx_evm.h
> @@ -108,6 +108,64 @@
>  #define CONFIG_OMAP_USB_PHY
>  #define CONFIG_AM437X_USB2PHY2_HOST
>  
> +/* USB GADGET */
> +#if !defined(CONFIG_SPL_BUILD) || \
> +	(defined(CONFIG_SPL_BUILD) &&
> defined(CONFIG_SPL_USBETH_SUPPORT)) +#define CONFIG_USB_DWC3_PHY_OMAP
> +#define CONFIG_USB_DWC3_OMAP
> +#define CONFIG_USB_DWC3
> +#define CONFIG_USB_DWC3_GADGET
> +
> +#define CONFIG_USB_GADGET
> +#define CONFIG_USB_ETHER
> +#define CONFIG_USB_ETH_RNDIS
> +#define CONFIG_USBNET_HOST_ADDR	"de:ad:be:af:00:00"

I saw somewhere a discussion which forbidden using hardcoded MAC
addresses.

This particular MAC looks like one for debug/development ;-)

> +#define CONFIG_USBDOWNLOAD_GADGET
> +#define CONFIG_USB_GADGET_VBUS_DRAW 2
> +#define CONFIG_G_DNL_MANUFACTURER "Texas Instruments"
> +#define CONFIG_G_DNL_VENDOR_NUM 0x0403
> +#define CONFIG_G_DNL_PRODUCT_NUM 0xBD00
> +#define CONFIG_USB_GADGET_DUALSPEED
> +#endif
> +
> +#ifndef CONFIG_SPL_BUILD
> +/* USB Device Firmware Update support */
> +#define CONFIG_DFU_FUNCTION
> +#define CONFIG_DFU_RAM
> +#define CONFIG_CMD_DFU
> +
> +#define CONFIG_DFU_MMC
> +#define DFU_ALT_INFO_MMC \
> +	"dfu_alt_info_mmc=" \
> +	"boot part 0 1;" \
> +	"rootfs part 0 2;" \
> +	"MLO fat 0 1;" \
> +	"spl-os-args fat 0 1;" \
> +	"spl-os-image fat 0 1;" \
> +	"u-boot.img fat 0 1;" \
> +	"uEnv.txt fat 0 1\0"
> +
> +#define DFU_ALT_INFO_EMMC \
> +	"dfu_alt_info_emmc=" \
> +	"MLO raw 0x100 0x100 mmcpart 0;" \
> +	"u-boot.img raw 0x300 0x1000 mmcpart 0\0"
> +
> +#define CONFIG_DFU_RAM
> +#define DFU_ALT_INFO_RAM \
> +	"dfu_alt_info_ram=" \
> +	"kernel ram 0x80200000 0x4000000;" \
> +	"fdt ram 0x80f80000 0x80000;" \
> +	"ramdisk ram 0x81000000 0x4000000\0"
> +
> +#define DFUARGS \
> +	"dfu_bufsiz=0x10000\0" \
> +	DFU_ALT_INFO_MMC \
> +	DFU_ALT_INFO_EMMC \
> +	DFU_ALT_INFO_RAM
> +#else
> +#define DFUARGS
> +#endif
> +
>  #ifdef CONFIG_QSPI_BOOT
>  #define CONFIG_SYS_TEXT_BASE           0x30000000
>  #undef CONFIG_ENV_IS_IN_FAT
> @@ -238,7 +296,8 @@
>  		"if test $board_name = AM43__SK; then " \
>  			"setenv fdtfile am437x-sk-evm.dtb; fi; " \
>  		"if test $fdtfile = undefined; then " \
> -			"echo WARNING: Could not determine device
> tree; fi; \0"
> +			"echo WARNING: Could not determine device
> tree; fi; \0" \
> +	DFUARGS \
>  
>  #define CONFIG_BOOTCOMMAND \
>  	"run findfdt; " \

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 40/40] usb: modify usb_gadget_handle_interrupts to take controller index
  2015-02-06  8:48 ` [U-Boot] [u-boot 40/40] usb: modify usb_gadget_handle_interrupts to take controller index Kishon Vijay Abraham I
@ 2015-02-16 11:56   ` Lukasz Majewski
  0 siblings, 0 replies; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 11:56 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Since we support multiple dwc3 controllers to be existent at the same
> time, in order to handle the interrupts of a particular dwc3
> controller usb_gadget_handle_interrutps should take controller index
> as an argument.
> 
> Hence the API of usb_gadget_handle_interrupts is modified to take
> controller index as an argument and made the corresponding changes to
> all the usb_gadget_handle_interrupts calls.
> 
> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> ---
>  board/ti/am43xx/board.c             |    6 +++---
>  board/ti/dra7xx/evm.c               |    6 +++---
>  common/cmd_dfu.c                    |    2 +-
>  common/cmd_fastboot.c               |    2 +-
>  common/cmd_usb_mass_storage.c       |    2 +-
>  drivers/usb/gadget/atmel_usba_udc.c |    2 +-
>  drivers/usb/gadget/ci_udc.c         |    2 +-
>  drivers/usb/gadget/ether.c          |   10 +++++-----
>  drivers/usb/gadget/f_mass_storage.c |    2 +-
>  drivers/usb/gadget/f_thor.c         |    6 +++---
>  drivers/usb/gadget/fotg210.c        |    2 +-
>  drivers/usb/gadget/pxa25x_udc.c     |    2 +-
>  drivers/usb/gadget/s3c_udc_otg.c    |    2 +-
>  drivers/usb/musb-new/musb_uboot.c   |    2 +-
>  include/linux/usb/gadget.h          |    2 +-
>  15 files changed, 25 insertions(+), 25 deletions(-)
> 
> diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
> index a8796b1..096e5db 100644
> --- a/board/ti/am43xx/board.c
> +++ b/board/ti/am43xx/board.c
> @@ -782,13 +782,13 @@ int board_usb_cleanup(int index, enum
> usb_init_type init) return 0;
>  }
>  
> -int usb_gadget_handle_interrupts(void)
> +int usb_gadget_handle_interrupts(int index)
>  {
>  	u32 status;
>  
> -	status = dwc3_omap_uboot_interrupt_status(0);
> +	status = dwc3_omap_uboot_interrupt_status(index);
>  	if (status)
> -		dwc3_uboot_handle_interrupt(0);
> +		dwc3_uboot_handle_interrupt(index);
>  
>  	return 0;
>  }
> diff --git a/board/ti/dra7xx/evm.c b/board/ti/dra7xx/evm.c
> index 284775c..3089fa2 100644
> --- a/board/ti/dra7xx/evm.c
> +++ b/board/ti/dra7xx/evm.c
> @@ -220,13 +220,13 @@ int board_usb_cleanup(int index, enum
> usb_init_type init) return 0;
>  }
>  
> -int usb_gadget_handle_interrupts(void)
> +int usb_gadget_handle_interrupts(int index)
>  {
>  	u32 status;
>  
> -	status = dwc3_omap_uboot_interrupt_status(0);
> +	status = dwc3_omap_uboot_interrupt_status(index);
>  	if (status)
> -		dwc3_uboot_handle_interrupt(0);
> +		dwc3_uboot_handle_interrupt(index);
>  
>  	return 0;
>  }
> diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c
> index 161d38b..ec90998 100644
> --- a/common/cmd_dfu.c
> +++ b/common/cmd_dfu.c
> @@ -64,7 +64,7 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int
> argc, char * const argv[]) if (ctrlc())
>  			goto exit;
>  
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(controller_index);
>  	}
>  exit:
>  	g_dnl_unregister();
> diff --git a/common/cmd_fastboot.c b/common/cmd_fastboot.c
> index b72f4f3..8281f8e 100644
> --- a/common/cmd_fastboot.c
> +++ b/common/cmd_fastboot.c
> @@ -25,7 +25,7 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag,
> int argc, char *const argv[]) break;
>  		if (ctrlc())
>  			break;
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(0);
>  	}
>  
>  	g_dnl_unregister();
> diff --git a/common/cmd_usb_mass_storage.c
> b/common/cmd_usb_mass_storage.c index 2c879ea..c5f909d 100644
> --- a/common/cmd_usb_mass_storage.c
> +++ b/common/cmd_usb_mass_storage.c
> @@ -137,7 +137,7 @@ int do_usb_mass_storage(cmd_tbl_t *cmdtp, int
> flag, }
>  
>  	while (1) {
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(controller_index);
>  
>  		rc = fsg_main_thread(NULL);
>  		if (rc) {
> diff --git a/drivers/usb/gadget/atmel_usba_udc.c
> b/drivers/usb/gadget/atmel_usba_udc.c index fbc74f3..1e23d09 100644
> --- a/drivers/usb/gadget/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/atmel_usba_udc.c
> @@ -1199,7 +1199,7 @@ static struct usba_udc controller = {
>  	},
>  };
>  
> -int usb_gadget_handle_interrupts(void)
> +int usb_gadget_handle_interrupts(int index)
>  {
>  	struct usba_udc *udc = &controller;
>  
> diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
> index b0ef35e..a7dc0b2 100644
> --- a/drivers/usb/gadget/ci_udc.c
> +++ b/drivers/usb/gadget/ci_udc.c
> @@ -741,7 +741,7 @@ void udc_irq(void)
>  	}
>  }
>  
> -int usb_gadget_handle_interrupts(void)
> +int usb_gadget_handle_interrupts(int index)
>  {
>  	u32 value;
>  	struct ci_udc *udc = (struct ci_udc *)controller.ctrl->hcor;
> diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
> index 8ccf9b0..ba79faf 100644
> --- a/drivers/usb/gadget/ether.c
> +++ b/drivers/usb/gadget/ether.c
> @@ -1908,7 +1908,7 @@ static int eth_stop(struct eth_dev *dev)
>  		/* Wait until host receives
> OID_GEN_MEDIA_CONNECT_STATUS */ ts = get_timer(0);
>  		while (get_timer(ts) < timeout)
> -			usb_gadget_handle_interrupts();
> +			usb_gadget_handle_interrupts(0);
>  #endif
>  
>  		rndis_uninit(dev->rndis_config);
> @@ -2359,7 +2359,7 @@ static int usb_eth_init(struct eth_device
> *netdev, bd_t *bd) error("The remote end did not respond in time.");
>  			goto fail;
>  		}
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(0);
>  	}
>  
>  	packet_received = 0;
> @@ -2427,7 +2427,7 @@ static int usb_eth_send(struct eth_device
> *netdev, void *packet, int length) printf("timeout sending packets to
> usb ethernet\n"); return -1;
>  		}
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(0);
>  	}
>  	if (rndis_pkt)
>  		free(rndis_pkt);
> @@ -2442,7 +2442,7 @@ static int usb_eth_recv(struct eth_device
> *netdev) {
>  	struct eth_dev *dev = &l_ethdev;
>  
> -	usb_gadget_handle_interrupts();
> +	usb_gadget_handle_interrupts(0);
>  
>  	if (packet_received) {
>  		debug("%s: packet received\n", __func__);
> @@ -2487,7 +2487,7 @@ void usb_eth_halt(struct eth_device *netdev)
>  
>  	/* Clear pending interrupt */
>  	if (dev->network_started) {
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(0);
>  		dev->network_started = 0;
>  	}
>  
> diff --git a/drivers/usb/gadget/f_mass_storage.c
> b/drivers/usb/gadget/f_mass_storage.c index e045957..4fab35e 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -689,7 +689,7 @@ static int sleep_thread(struct fsg_common *common)
>  			k = 0;
>  		}
>  
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(0);
>  	}
>  	common->thread_wakeup_needed = 0;
>  	return rc;
> diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c
> index 2d0410d..1fd41ff 100644
> --- a/drivers/usb/gadget/f_thor.c
> +++ b/drivers/usb/gadget/f_thor.c
> @@ -543,7 +543,7 @@ static int thor_rx_data(void)
>  		}
>  
>  		while (!dev->rxdata) {
> -			usb_gadget_handle_interrupts();
> +			usb_gadget_handle_interrupts(0);
>  			if (ctrlc())
>  				return -1;
>  		}
> @@ -577,7 +577,7 @@ static void thor_tx_data(unsigned char *data, int
> len) 
>  	/* Wait until tx interrupt received */
>  	while (!dev->txdata)
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(0);
>  
>  	dev->txdata = 0;
>  }
> @@ -694,7 +694,7 @@ int thor_init(void)
>  	/* Wait for a device enumeration and configuration settings
> */ debug("THOR enumeration/configuration setting....\n");
>  	while (!dev->configuration_done)
> -		usb_gadget_handle_interrupts();
> +		usb_gadget_handle_interrupts(0);
>  
>  	thor_set_dma(thor_rx_data_buf, strlen("THOR"));
>  	/* detect the download request from Host PC */
> diff --git a/drivers/usb/gadget/fotg210.c
> b/drivers/usb/gadget/fotg210.c index 3acf6a1..1d8f58f 100644
> --- a/drivers/usb/gadget/fotg210.c
> +++ b/drivers/usb/gadget/fotg210.c
> @@ -832,7 +832,7 @@ static struct fotg210_chip controller = {
>  	},
>  };
>  
> -int usb_gadget_handle_interrupts(void)
> +int usb_gadget_handle_interrupts(int index)
>  {
>  	struct fotg210_chip *chip = &controller;
>  	struct fotg210_regs *regs = chip->regs;
> diff --git a/drivers/usb/gadget/pxa25x_udc.c
> b/drivers/usb/gadget/pxa25x_udc.c index 8945c5b..1910227 100644
> --- a/drivers/usb/gadget/pxa25x_udc.c
> +++ b/drivers/usb/gadget/pxa25x_udc.c
> @@ -2041,7 +2041,7 @@ extern void udc_disconnect(void)
>  /*-------------------------------------------------------------------------*/
>  
>  extern int
> -usb_gadget_handle_interrupts(void)
> +usb_gadget_handle_interrupts(int index)
>  {
>  	return pxa25x_udc_irq();
>  }
> diff --git a/drivers/usb/gadget/s3c_udc_otg.c
> b/drivers/usb/gadget/s3c_udc_otg.c index 7653f03..7a2d1e7 100644
> --- a/drivers/usb/gadget/s3c_udc_otg.c
> +++ b/drivers/usb/gadget/s3c_udc_otg.c
> @@ -833,7 +833,7 @@ int s3c_udc_probe(struct s3c_plat_otg_data *pdata)
>  	return retval;
>  }
>  
> -int usb_gadget_handle_interrupts()
> +int usb_gadget_handle_interrupts(int index)
>  {
>  	u32 intr_status = readl(&reg->gintsts);
>  	u32 gintmsk = readl(&reg->gintmsk);
> diff --git a/drivers/usb/musb-new/musb_uboot.c
> b/drivers/usb/musb-new/musb_uboot.c index 2676f09..79f29fb 100644
> --- a/drivers/usb/musb-new/musb_uboot.c
> +++ b/drivers/usb/musb-new/musb_uboot.c
> @@ -162,7 +162,7 @@ int usb_lowlevel_stop(int index)
>  #ifdef CONFIG_MUSB_GADGET
>  static struct musb *gadget;
>  
> -int usb_gadget_handle_interrupts(void)
> +int usb_gadget_handle_interrupts(int index)
>  {
>  	WATCHDOG_RESET();
>  	if (!gadget || !gadget->isr)
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index 93a5ffc..230f47d 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -937,6 +937,6 @@ extern struct usb_ep *usb_ep_autoconfig(struct
> usb_gadget *, 
>  extern void usb_ep_autoconfig_reset(struct usb_gadget *);
>  
> -extern int usb_gadget_handle_interrupts(void);
> +extern int usb_gadget_handle_interrupts(int index);
>  
>  #endif	/* __LINUX_USB_GADGET_H */

Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0
  2015-02-16 11:42   ` Lukasz Majewski
@ 2015-02-16 12:01     ` Kishon Vijay Abraham I
  2015-02-16 13:04       ` Lukasz Majewski
  0 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-16 12:01 UTC (permalink / raw)
  To: u-boot

Hi Lukasz,

On Monday 16 February 2015 05:12 PM, Lukasz Majewski wrote:
> Hi Kishon,
>
>> dwc3 can do only max packet aligned transfers. So in case request
>> length is not max packet aligned and is bigger than
>> DWC3_EP0_BOUNCE_SIZE two chained TRBs is required to handle the
>> transfer.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>   drivers/usb/dwc3/ep0.c    |   72
>> +++++++++++++++++++++++++++++++++------------
>> drivers/usb/dwc3/gadget.c |    2 +- 2 files changed, 55
>> insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
>> index fce2558..c2fe0ec 100644
>> --- a/drivers/usb/dwc3/ep0.c
>> +++ b/drivers/usb/dwc3/ep0.c
>> @@ -48,7 +48,7 @@ static const char *dwc3_ep0_state_string(enum
>> dwc3_ep0_state state) }
>>
>>   static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum,
>> dma_addr_t buf_dma,
>> -		u32 len, u32 type)
>> +				u32 len, u32 type, unsigned chain)
>>   {
>>   	struct dwc3_gadget_ep_cmd_params params;
>>   	struct dwc3_trb			*trb;
>> @@ -62,7 +62,10 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc,
>> u8 epnum, dma_addr_t buf_dma, return 0;
>>   	}
>>
>> -	trb = dwc->ep0_trb;
>> +	trb = &dwc->ep0_trb[dep->free_slot];
>> +
>> +	if (chain)
>> +		dep->free_slot++;
>>
>>   	trb->bpl = lower_32_bits(buf_dma);
>>   	trb->bph = upper_32_bits(buf_dma);
>> @@ -70,13 +73,20 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc,
>> u8 epnum, dma_addr_t buf_dma, trb->ctrl = type;
>>
>>   	trb->ctrl |= (DWC3_TRB_CTRL_HWO
>> -			| DWC3_TRB_CTRL_LST
>> -			| DWC3_TRB_CTRL_IOC
>>   			| DWC3_TRB_CTRL_ISP_IMI);
>>
>> +	if (chain)
>> +		trb->ctrl |= DWC3_TRB_CTRL_CHN;
>> +	else
>> +		trb->ctrl |= (DWC3_TRB_CTRL_IOC
>> +				| DWC3_TRB_CTRL_LST);
>> +
>>   	dwc3_flush_cache((int)buf_dma, len);
>>   	dwc3_flush_cache((int)trb, sizeof(*trb));
>>
>> +	if (chain)
>> +		return 0;
>> +
>>   	memset(&params, 0, sizeof(params));
>>   	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
>>   	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
>> @@ -289,7 +299,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
>>   	int				ret;
>>
>>   	ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
>> -			DWC3_TRBCTL_CONTROL_SETUP);
>> +				   DWC3_TRBCTL_CONTROL_SETUP, 0);
>>   	WARN_ON(ret < 0);
>>   }
>>
>> @@ -799,6 +809,23 @@ static void dwc3_ep0_complete_data(struct dwc3
>> *dwc,
>>   	maxp = ep0->endpoint.maxpacket;
>>
>> +	/* Handle the first TRB before handling the bounce buffer if
>> the request
>
> 	Minor comment - please fix above comment.

Sorry. Didn't get what should I fix here?

Btw thanks for reviewing all the patches.

Cheers
Kishon

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

* [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0
  2015-02-16 12:01     ` Kishon Vijay Abraham I
@ 2015-02-16 13:04       ` Lukasz Majewski
  2015-02-16 13:06         ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-16 13:04 UTC (permalink / raw)
  To: u-boot

Hi Kishon,

> Hi Lukasz,
> 
> On Monday 16 February 2015 05:12 PM, Lukasz Majewski wrote:
> > Hi Kishon,
> >
> >> dwc3 can do only max packet aligned transfers. So in case request
> >> length is not max packet aligned and is bigger than
> >> DWC3_EP0_BOUNCE_SIZE two chained TRBs is required to handle the
> >> transfer.
> >>
> >> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> >> ---
> >>   drivers/usb/dwc3/ep0.c    |   72
> >> +++++++++++++++++++++++++++++++++------------
> >> drivers/usb/dwc3/gadget.c |    2 +- 2 files changed, 55
> >> insertions(+), 19 deletions(-)
> >>
> >> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> >> index fce2558..c2fe0ec 100644
> >> --- a/drivers/usb/dwc3/ep0.c
> >> +++ b/drivers/usb/dwc3/ep0.c
> >> @@ -48,7 +48,7 @@ static const char *dwc3_ep0_state_string(enum
> >> dwc3_ep0_state state) }
> >>
> >>   static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum,
> >> dma_addr_t buf_dma,
> >> -		u32 len, u32 type)
> >> +				u32 len, u32 type, unsigned chain)
> >>   {
> >>   	struct dwc3_gadget_ep_cmd_params params;
> >>   	struct dwc3_trb			*trb;
> >> @@ -62,7 +62,10 @@ static int dwc3_ep0_start_trans(struct dwc3
> >> *dwc, u8 epnum, dma_addr_t buf_dma, return 0;
> >>   	}
> >>
> >> -	trb = dwc->ep0_trb;
> >> +	trb = &dwc->ep0_trb[dep->free_slot];
> >> +
> >> +	if (chain)
> >> +		dep->free_slot++;
> >>
> >>   	trb->bpl = lower_32_bits(buf_dma);
> >>   	trb->bph = upper_32_bits(buf_dma);
> >> @@ -70,13 +73,20 @@ static int dwc3_ep0_start_trans(struct dwc3
> >> *dwc, u8 epnum, dma_addr_t buf_dma, trb->ctrl = type;
> >>
> >>   	trb->ctrl |= (DWC3_TRB_CTRL_HWO
> >> -			| DWC3_TRB_CTRL_LST
> >> -			| DWC3_TRB_CTRL_IOC
> >>   			| DWC3_TRB_CTRL_ISP_IMI);
> >>
> >> +	if (chain)
> >> +		trb->ctrl |= DWC3_TRB_CTRL_CHN;
> >> +	else
> >> +		trb->ctrl |= (DWC3_TRB_CTRL_IOC
> >> +				| DWC3_TRB_CTRL_LST);
> >> +
> >>   	dwc3_flush_cache((int)buf_dma, len);
> >>   	dwc3_flush_cache((int)trb, sizeof(*trb));
> >>
> >> +	if (chain)
> >> +		return 0;
> >> +
> >>   	memset(&params, 0, sizeof(params));
> >>   	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
> >>   	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
> >> @@ -289,7 +299,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
> >>   	int				ret;
> >>
> >>   	ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
> >> -			DWC3_TRBCTL_CONTROL_SETUP);
> >> +				   DWC3_TRBCTL_CONTROL_SETUP, 0);
> >>   	WARN_ON(ret < 0);
> >>   }
> >>
> >> @@ -799,6 +809,23 @@ static void dwc3_ep0_complete_data(struct dwc3
> >> *dwc,
> >>   	maxp = ep0->endpoint.maxpacket;
> >>
> >> +	/* Handle the first TRB before handling the bounce buffer
> >> if the request
> >
> > 	Minor comment - please fix above comment.
> 
> Sorry. Didn't get what should I fix here?

	The comment should be as follow:

	/*
	 * Handle the first .....
	 *
	 *
	 */

The first line is wrong (/* Handle ...).

> 
> Btw thanks for reviewing all the patches.
> 
> Cheers
> Kishon


-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0
  2015-02-16 13:04       ` Lukasz Majewski
@ 2015-02-16 13:06         ` Kishon Vijay Abraham I
  0 siblings, 0 replies; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-16 13:06 UTC (permalink / raw)
  To: u-boot

Hi,

On Monday 16 February 2015 06:34 PM, Lukasz Majewski wrote:
> Hi Kishon,
>
>> Hi Lukasz,
>>
>> On Monday 16 February 2015 05:12 PM, Lukasz Majewski wrote:
>>> Hi Kishon,
>>>
>>>> dwc3 can do only max packet aligned transfers. So in case request
>>>> length is not max packet aligned and is bigger than
>>>> DWC3_EP0_BOUNCE_SIZE two chained TRBs is required to handle the
>>>> transfer.
>>>>
>>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>>> ---
>>>>    drivers/usb/dwc3/ep0.c    |   72
>>>> +++++++++++++++++++++++++++++++++------------
>>>> drivers/usb/dwc3/gadget.c |    2 +- 2 files changed, 55
>>>> insertions(+), 19 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
>>>> index fce2558..c2fe0ec 100644
>>>> --- a/drivers/usb/dwc3/ep0.c
>>>> +++ b/drivers/usb/dwc3/ep0.c
>>>> @@ -48,7 +48,7 @@ static const char *dwc3_ep0_state_string(enum
>>>> dwc3_ep0_state state) }
>>>>
>>>>    static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum,
>>>> dma_addr_t buf_dma,
>>>> -		u32 len, u32 type)
>>>> +				u32 len, u32 type, unsigned chain)
>>>>    {
>>>>    	struct dwc3_gadget_ep_cmd_params params;
>>>>    	struct dwc3_trb			*trb;
>>>> @@ -62,7 +62,10 @@ static int dwc3_ep0_start_trans(struct dwc3
>>>> *dwc, u8 epnum, dma_addr_t buf_dma, return 0;
>>>>    	}
>>>>
>>>> -	trb = dwc->ep0_trb;
>>>> +	trb = &dwc->ep0_trb[dep->free_slot];
>>>> +
>>>> +	if (chain)
>>>> +		dep->free_slot++;
>>>>
>>>>    	trb->bpl = lower_32_bits(buf_dma);
>>>>    	trb->bph = upper_32_bits(buf_dma);
>>>> @@ -70,13 +73,20 @@ static int dwc3_ep0_start_trans(struct dwc3
>>>> *dwc, u8 epnum, dma_addr_t buf_dma, trb->ctrl = type;
>>>>
>>>>    	trb->ctrl |= (DWC3_TRB_CTRL_HWO
>>>> -			| DWC3_TRB_CTRL_LST
>>>> -			| DWC3_TRB_CTRL_IOC
>>>>    			| DWC3_TRB_CTRL_ISP_IMI);
>>>>
>>>> +	if (chain)
>>>> +		trb->ctrl |= DWC3_TRB_CTRL_CHN;
>>>> +	else
>>>> +		trb->ctrl |= (DWC3_TRB_CTRL_IOC
>>>> +				| DWC3_TRB_CTRL_LST);
>>>> +
>>>>    	dwc3_flush_cache((int)buf_dma, len);
>>>>    	dwc3_flush_cache((int)trb, sizeof(*trb));
>>>>
>>>> +	if (chain)
>>>> +		return 0;
>>>> +
>>>>    	memset(&params, 0, sizeof(params));
>>>>    	params.param0 = upper_32_bits(dwc->ep0_trb_addr);
>>>>    	params.param1 = lower_32_bits(dwc->ep0_trb_addr);
>>>> @@ -289,7 +299,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
>>>>    	int				ret;
>>>>
>>>>    	ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
>>>> -			DWC3_TRBCTL_CONTROL_SETUP);
>>>> +				   DWC3_TRBCTL_CONTROL_SETUP, 0);
>>>>    	WARN_ON(ret < 0);
>>>>    }
>>>>
>>>> @@ -799,6 +809,23 @@ static void dwc3_ep0_complete_data(struct dwc3
>>>> *dwc,
>>>>    	maxp = ep0->endpoint.maxpacket;
>>>>
>>>> +	/* Handle the first TRB before handling the bounce buffer
>>>> if the request
>>>
>>> 	Minor comment - please fix above comment.
>>
>> Sorry. Didn't get what should I fix here?
>
> 	The comment should be as follow:
>
> 	/*
> 	 * Handle the first .....
> 	 *
> 	 *
> 	 */
>
> The first line is wrong (/* Handle ...).

ah.. alright.

Thanks
Kishon

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

* [U-Boot] [u-boot 02/40] ARM: AM43xx: Enable clocks for USB OTGSS and USB PHY
  2015-02-16 10:07   ` Lukasz Majewski
@ 2015-02-16 13:29     ` Marek Vasut
  2015-02-20  9:30       ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-02-16 13:29 UTC (permalink / raw)
  To: u-boot

On Monday, February 16, 2015 at 11:07:39 AM, Lukasz Majewski wrote:
> Hi Kishon,
> 
> > Enabled clocks for dwc3 controller and USB PHY present in AM43xx.
> > 
> > Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> > ---
> > 
> >  arch/arm/cpu/armv7/am33xx/clock_am43xx.c           |   12 +++++++++++
> >  arch/arm/include/asm/arch-am33xx/cpu.h             |   22
> > 
> > ++++++++++++++------
> > arch/arm/include/asm/arch-am33xx/hardware_am43xx.h |    4 ++++ 3
> > files changed, 32 insertions(+), 6 deletions(-)
> > 
> > diff --git a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
> > b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c index 31188c8..252135d
> > 100644 --- a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
> > +++ b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
> > @@ -111,9 +111,21 @@ void enable_basic_clocks(void)
> > 
> >  		&cmper->emifclkctrl,
> >  		&cmper->otfaemifclkctrl,
> >  		&cmper->qspiclkctrl,
> > 
> > +		&cmper->usb0clkctrl,
> > +		&cmper->usbphyocp2scp0clkctrl,
> > +		&cmper->usb1clkctrl,
> > +		&cmper->usbphyocp2scp1clkctrl,
> > 
> >  		0
> >  	
> >  	};
> > 
> > +	setbits_le32(&cmper->usb0clkctrl,
> > +		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
> > +	setbits_le32(&cmwkup->usbphy0clkctrl,
> > +		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
> > +	setbits_le32(&cmper->usb1clkctrl,
> > +		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
> > +	setbits_le32(&cmwkup->usbphy1clkctrl,
> > +		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
> > 
> >  	do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
> >  	
> >  	/* Select the Master osc clk as Timer2 clock source */
> > 
> > diff --git a/arch/arm/include/asm/arch-am33xx/cpu.h
> > b/arch/arm/include/asm/arch-am33xx/cpu.h index 8dd69b3..1caa24e 100644
> > --- a/arch/arm/include/asm/arch-am33xx/cpu.h
> > +++ b/arch/arm/include/asm/arch-am33xx/cpu.h
> > @@ -224,7 +224,11 @@ struct cm_dpll {
> > 
> >  struct cm_wkuppll {
> >  
> >  	unsigned int resv0[136];
> >  	unsigned int wkl4wkclkctrl;	/* offset 0x220 */
> > 
> > -	unsigned int resv1[55];
> > +	unsigned int resv1[7];
> > +	unsigned int usbphy0clkctrl;	/* offset 0x240 */
> > +	unsigned int resv112;
> > +	unsigned int usbphy1clkctrl;	/* offset 0x248 */
> > +	unsigned int resv113[45];
> > 
> >  	unsigned int wkclkstctrl;	/* offset 0x300 */
> >  	unsigned int resv2[15];
> >  	unsigned int wkup_i2c0ctrl;	/* offset 0x340 */
> > 
> > @@ -275,7 +279,7 @@ struct cm_wkuppll {
> > 
> >  	unsigned int divm2dplldisp;	/* offset 0x630 */
> >  
> >  };
> > 
> > -/*
> > +/*get_sys_clk_freq
> 
> This comment doesn't comply with coding style.
> 
> It should be
> 
> 	/*
> 	 * get_sys_clk_freq
> 	 * En ...
> 
> 	 */
> 
> >   * Encapsulating peripheral functional clocks
> >   * pll registers
> >   */
> > 
> > @@ -283,7 +287,7 @@ struct cm_perpll {
> > 
> >  	unsigned int l3clkstctrl;	/* offset 0x00 */
> >  	unsigned int resv0[7];
> >  	unsigned int l3clkctrl;		/* Offset 0x20 */
> > 
> > -	unsigned int resv1[7];
> > +	unsigned int resv112[7];
> > 
> >  	unsigned int l3instrclkctrl;	/* offset 0x40 */
> >  	unsigned int resv2[3];
> >  	unsigned int ocmcramclkctrl;	/* offset 0x50 */
> > 
> > @@ -310,7 +314,9 @@ struct cm_perpll {
> > 
> >  	unsigned int qspiclkctrl;       /* offset 0x258 */
> >  	unsigned int resv121;
> >  	unsigned int usb0clkctrl;	/* offset 0x260 */
> > 
> > -	unsigned int resv13[103];
> > +	unsigned int resv122;
> > +	unsigned int usb1clkctrl;	/* offset 0x268 */
> > +	unsigned int resv13[101];
> > 
> >  	unsigned int l4lsclkstctrl;	/* offset 0x400 */
> >  	unsigned int resv14[7];
> >  	unsigned int l4lsclkctrl;	/* offset 0x420 */
> > 
> > @@ -364,10 +370,14 @@ struct cm_perpll {
> > 
> >  	unsigned int uart4clkctrl;	/* offset 0x598 */
> >  	unsigned int resv35;
> >  	unsigned int uart5clkctrl;	/* offset 0x5A0 */
> > 
> > -	unsigned int resv36[87];
> > +	unsigned int resv36[5];
> > +	unsigned int usbphyocp2scp0clkctrl;	/* offset 0x5B8 */
> > +	unsigned int resv361;
> > +	unsigned int usbphyocp2scp1clkctrl;	/* offset 0x5C0 */
> > +	unsigned int resv3611[79];
> > 
> >  	unsigned int emifclkstctrl;	/* offset 0x700 */
> > 
> > -	unsigned int resv361[7];
> > +	unsigned int resv362[7];
> > 
> >  	unsigned int emifclkctrl;	/* offset 0x720 */
> >  	unsigned int resv37[3];
> >  	unsigned int emiffwclkctrl;	/* offset 0x730 */
> > 
> > diff --git a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
> > b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h index
> > efdecf4..5f259da 100644 ---
> > a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h +++
> > b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h @@ -72,6 +72,10
> > @@ #define USBPHYOCPSCP_MODULE_EN	(1 << 1)
> > 
> >  #define CM_DEVICE_INST			0x44df4100
> > 
> > +#define	USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960	(1 << 8)
> > +#define	USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K	(1 << 8)
> > +
> > +
> 
> Two blank lines.
> 
> >  /* Control status register */
> >  #define CTRL_CRYSTAL_FREQ_SRC_MASK		(1 << 31)
> >  #define CTRL_CRYSTAL_FREQ_SRC_SHIFT		31
> 
> If Marek agrees to correct this minor issues (before adding it to -usb
> tree), then

OK, minor issues are pilinng up, so maybe a V2 of the series would be better.

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

* [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot
  2015-02-16  9:58     ` Lukasz Majewski
@ 2015-02-16 13:29       ` Marek Vasut
  0 siblings, 0 replies; 104+ messages in thread
From: Marek Vasut @ 2015-02-16 13:29 UTC (permalink / raw)
  To: u-boot

On Monday, February 16, 2015 at 10:58:46 AM, Lukasz Majewski wrote:
> Hi Marek,
> 
> > On Friday, February 06, 2015 at 09:47:40 AM, Kishon Vijay Abraham I
> > 
> > wrote:
> > > Added udc-core.c from linux kernel 3.19-rc1 (97bf6af1f9) to u-boot.
> > > This will be adapted to work with u-boot in the
> > > following patches.
> > > Adding support for udc will help to seamlessly port dwc3 driver from
> > > linux kernel to u-boot (since dwc3 uses udc-core) and it'll also
> > > help to add support for multiple gadget controllers to be
> > > functional at the same time.
> > > All other gadget drivers can also be adapted to use udc-core.
> > > 
> > > Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> > 
> > Lukasz, do you have any comments on this ? I'd like to pick this whole
> > thing via u-boot-usb for this MW if possible.
> 
> I wasn't in the office for the last week. I will review this code ASAP.

No worries, thanks :)

Best regards,
Marek Vasut

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

* [U-Boot] [u-boot 02/40] ARM: AM43xx: Enable clocks for USB OTGSS and USB PHY
  2015-02-16 13:29     ` Marek Vasut
@ 2015-02-20  9:30       ` Kishon Vijay Abraham I
  2015-02-20 10:48         ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-20  9:30 UTC (permalink / raw)
  To: u-boot

Hi,

On Monday 16 February 2015 06:59 PM, Marek Vasut wrote:
> On Monday, February 16, 2015 at 11:07:39 AM, Lukasz Majewski wrote:
>> Hi Kishon,
>>
>>> Enabled clocks for dwc3 controller and USB PHY present in AM43xx.
>>>
>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>> ---
>>>
>>>   arch/arm/cpu/armv7/am33xx/clock_am43xx.c           |   12 +++++++++++
>>>   arch/arm/include/asm/arch-am33xx/cpu.h             |   22
>>>
>>> ++++++++++++++------
>>> arch/arm/include/asm/arch-am33xx/hardware_am43xx.h |    4 ++++ 3
>>> files changed, 32 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
>>> b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c index 31188c8..252135d
>>> 100644 --- a/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
>>> +++ b/arch/arm/cpu/armv7/am33xx/clock_am43xx.c
>>> @@ -111,9 +111,21 @@ void enable_basic_clocks(void)
>>>
>>>   		&cmper->emifclkctrl,
>>>   		&cmper->otfaemifclkctrl,
>>>   		&cmper->qspiclkctrl,
>>>
>>> +		&cmper->usb0clkctrl,
>>> +		&cmper->usbphyocp2scp0clkctrl,
>>> +		&cmper->usb1clkctrl,
>>> +		&cmper->usbphyocp2scp1clkctrl,
>>>
>>>   		0
>>>   	
>>>   	};
>>>
>>> +	setbits_le32(&cmper->usb0clkctrl,
>>> +		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
>>> +	setbits_le32(&cmwkup->usbphy0clkctrl,
>>> +		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
>>> +	setbits_le32(&cmper->usb1clkctrl,
>>> +		     USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960);
>>> +	setbits_le32(&cmwkup->usbphy1clkctrl,
>>> +		     USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K);
>>>
>>>   	do_enable_clocks(clk_domains, clk_modules_explicit_en, 1);
>>>   	
>>>   	/* Select the Master osc clk as Timer2 clock source */
>>>
>>> diff --git a/arch/arm/include/asm/arch-am33xx/cpu.h
>>> b/arch/arm/include/asm/arch-am33xx/cpu.h index 8dd69b3..1caa24e 100644
>>> --- a/arch/arm/include/asm/arch-am33xx/cpu.h
>>> +++ b/arch/arm/include/asm/arch-am33xx/cpu.h
>>> @@ -224,7 +224,11 @@ struct cm_dpll {
>>>
>>>   struct cm_wkuppll {
>>>
>>>   	unsigned int resv0[136];
>>>   	unsigned int wkl4wkclkctrl;	/* offset 0x220 */
>>>
>>> -	unsigned int resv1[55];
>>> +	unsigned int resv1[7];
>>> +	unsigned int usbphy0clkctrl;	/* offset 0x240 */
>>> +	unsigned int resv112;
>>> +	unsigned int usbphy1clkctrl;	/* offset 0x248 */
>>> +	unsigned int resv113[45];
>>>
>>>   	unsigned int wkclkstctrl;	/* offset 0x300 */
>>>   	unsigned int resv2[15];
>>>   	unsigned int wkup_i2c0ctrl;	/* offset 0x340 */
>>>
>>> @@ -275,7 +279,7 @@ struct cm_wkuppll {
>>>
>>>   	unsigned int divm2dplldisp;	/* offset 0x630 */
>>>
>>>   };
>>>
>>> -/*
>>> +/*get_sys_clk_freq
>>
>> This comment doesn't comply with coding style.
>>
>> It should be
>>
>> 	/*
>> 	 * get_sys_clk_freq
>> 	 * En ...
>>
>> 	 */
>>
>>>    * Encapsulating peripheral functional clocks
>>>    * pll registers
>>>    */
>>>
>>> @@ -283,7 +287,7 @@ struct cm_perpll {
>>>
>>>   	unsigned int l3clkstctrl;	/* offset 0x00 */
>>>   	unsigned int resv0[7];
>>>   	unsigned int l3clkctrl;		/* Offset 0x20 */
>>>
>>> -	unsigned int resv1[7];
>>> +	unsigned int resv112[7];
>>>
>>>   	unsigned int l3instrclkctrl;	/* offset 0x40 */
>>>   	unsigned int resv2[3];
>>>   	unsigned int ocmcramclkctrl;	/* offset 0x50 */
>>>
>>> @@ -310,7 +314,9 @@ struct cm_perpll {
>>>
>>>   	unsigned int qspiclkctrl;       /* offset 0x258 */
>>>   	unsigned int resv121;
>>>   	unsigned int usb0clkctrl;	/* offset 0x260 */
>>>
>>> -	unsigned int resv13[103];
>>> +	unsigned int resv122;
>>> +	unsigned int usb1clkctrl;	/* offset 0x268 */
>>> +	unsigned int resv13[101];
>>>
>>>   	unsigned int l4lsclkstctrl;	/* offset 0x400 */
>>>   	unsigned int resv14[7];
>>>   	unsigned int l4lsclkctrl;	/* offset 0x420 */
>>>
>>> @@ -364,10 +370,14 @@ struct cm_perpll {
>>>
>>>   	unsigned int uart4clkctrl;	/* offset 0x598 */
>>>   	unsigned int resv35;
>>>   	unsigned int uart5clkctrl;	/* offset 0x5A0 */
>>>
>>> -	unsigned int resv36[87];
>>> +	unsigned int resv36[5];
>>> +	unsigned int usbphyocp2scp0clkctrl;	/* offset 0x5B8 */
>>> +	unsigned int resv361;
>>> +	unsigned int usbphyocp2scp1clkctrl;	/* offset 0x5C0 */
>>> +	unsigned int resv3611[79];
>>>
>>>   	unsigned int emifclkstctrl;	/* offset 0x700 */
>>>
>>> -	unsigned int resv361[7];
>>> +	unsigned int resv362[7];
>>>
>>>   	unsigned int emifclkctrl;	/* offset 0x720 */
>>>   	unsigned int resv37[3];
>>>   	unsigned int emiffwclkctrl;	/* offset 0x730 */
>>>
>>> diff --git a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h
>>> b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h index
>>> efdecf4..5f259da 100644 ---
>>> a/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h +++
>>> b/arch/arm/include/asm/arch-am33xx/hardware_am43xx.h @@ -72,6 +72,10
>>> @@ #define USBPHYOCPSCP_MODULE_EN	(1 << 1)
>>>
>>>   #define CM_DEVICE_INST			0x44df4100
>>>
>>> +#define	USBOTGSSX_CLKCTRL_OPTFCLKEN_REFCLK960	(1 << 8)
>>> +#define	USBPHY0_CLKCTRL_OPTFCLKEN_CLK32K	(1 << 8)
>>> +
>>> +
>>
>> Two blank lines.
>>
>>>   /* Control status register */
>>>   #define CTRL_CRYSTAL_FREQ_SRC_MASK		(1 << 31)
>>>   #define CTRL_CRYSTAL_FREQ_SRC_SHIFT		31
>>
>> If Marek agrees to correct this minor issues (before adding it to -usb
>> tree), then
>
> OK, minor issues are pilinng up, so maybe a V2 of the series would be better.
>
sure, I'll fix the comments and send v2.

Cheers
Kishon

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

* [U-Boot] [u-boot 02/40] ARM: AM43xx: Enable clocks for USB OTGSS and USB PHY
  2015-02-20  9:30       ` Kishon Vijay Abraham I
@ 2015-02-20 10:48         ` Marek Vasut
  0 siblings, 0 replies; 104+ messages in thread
From: Marek Vasut @ 2015-02-20 10:48 UTC (permalink / raw)
  To: u-boot

On Friday, February 20, 2015 at 10:30:34 AM, Kishon Vijay Abraham I wrote:
> Hi,
> 
> On Monday 16 February 2015 06:59 PM, Marek Vasut wrote:
> > On Monday, February 16, 2015 at 11:07:39 AM, Lukasz Majewski wrote:
> >> Hi Kishon,

[...]

> >> Two blank lines.
> >> 
> >>>   /* Control status register */
> >>>   #define CTRL_CRYSTAL_FREQ_SRC_MASK		(1 << 31)
> >>>   #define CTRL_CRYSTAL_FREQ_SRC_SHIFT		31
> >> 
> >> If Marek agrees to correct this minor issues (before adding it to -usb
> >> tree), then
> > 
> > OK, minor issues are pilinng up, so maybe a V2 of the series would be
> > better.
> 
> sure, I'll fix the comments and send v2.

Cool, thank you :) Please CC Lukasz and once he says it's OK, I will pick this.

Best regards,
Marek Vasut

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-16 10:32   ` Lukasz Majewski
@ 2015-02-23  6:19     ` Kishon Vijay Abraham I
  2015-02-23 14:59       ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-23  6:19 UTC (permalink / raw)
  To: u-boot

Hi,

On Monday 16 February 2015 04:02 PM, Lukasz Majewski wrote:
> Hi Kishon, Marek
>
>> Added a header file to include various linux specific APIs like
>> pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid compilation
>> error while building dwc3 driver.
>>
>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>> ---
>>   drivers/usb/dwc3/linux-compat.h |   30 ++++++++++++++++++++++++++++++
>>   1 file changed, 30 insertions(+)
>>   create mode 100644 drivers/usb/dwc3/linux-compat.h
>>
>> diff --git a/drivers/usb/dwc3/linux-compat.h
>> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
>> index 0000000..58c4716
>> --- /dev/null
>> +++ b/drivers/usb/dwc3/linux-compat.h
>> @@ -0,0 +1,30 @@
>> +/**
>> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy Adapter
>> Header
>> + *
>> + * Copyright (C) 2015 Texas Instruments Incorporated -
>> http://www.ti.com
>> + *
>> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
>> + *
>> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
>> + * to uboot.
>> + *
>> + * SPDX-License-Identifier:	GPL-2.0
>> + *
>> + */
>> +
>> +#ifndef __DWC3_LINUX_COMPAT__
>> +#define __DWC3_LINUX_COMPAT__
>> +
>> +#define pr_debug(format)                debug(format)
>> +#define WARN(val, format, arg...)	debug(format, ##arg)
>> +#define WARN_ON_ONCE(val)		debug("Error %d\n", val)
>> +
>> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
>> +
>> +static inline size_t strlcat(char *dest, const char *src, size_t n)
>> +{
>> +	strcat(dest, src);
>> +	return strlen(dest) + strlen(src);
>> +}
>> +
>> +#endif
>
> Similar file has been already added to u-boot.
> Please look into ./drivers/usb/musb-new/linux-compat.h
>
> @Marek - maybe it is time to have a common one?

Can we do this separately?

-Kishon

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-23  6:19     ` Kishon Vijay Abraham I
@ 2015-02-23 14:59       ` Marek Vasut
  2015-02-24 13:21         ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-02-23 14:59 UTC (permalink / raw)
  To: u-boot

On Monday, February 23, 2015 at 07:19:03 AM, Kishon Vijay Abraham I wrote:
> Hi,
> 
> On Monday 16 February 2015 04:02 PM, Lukasz Majewski wrote:
> > Hi Kishon, Marek
> > 
> >> Added a header file to include various linux specific APIs like
> >> pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid compilation
> >> error while building dwc3 driver.
> >> 
> >> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> >> ---
> >> 
> >>   drivers/usb/dwc3/linux-compat.h |   30 ++++++++++++++++++++++++++++++
> >>   1 file changed, 30 insertions(+)
> >>   create mode 100644 drivers/usb/dwc3/linux-compat.h
> >> 
> >> diff --git a/drivers/usb/dwc3/linux-compat.h
> >> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
> >> index 0000000..58c4716
> >> --- /dev/null
> >> +++ b/drivers/usb/dwc3/linux-compat.h
> >> @@ -0,0 +1,30 @@
> >> +/**
> >> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy Adapter
> >> Header
> >> + *
> >> + * Copyright (C) 2015 Texas Instruments Incorporated -
> >> http://www.ti.com
> >> + *
> >> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
> >> + *
> >> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
> >> + * to uboot.
> >> + *
> >> + * SPDX-License-Identifier:	GPL-2.0
> >> + *
> >> + */
> >> +
> >> +#ifndef __DWC3_LINUX_COMPAT__
> >> +#define __DWC3_LINUX_COMPAT__
> >> +
> >> +#define pr_debug(format)                debug(format)
> >> +#define WARN(val, format, arg...)	debug(format, ##arg)
> >> +#define WARN_ON_ONCE(val)		debug("Error %d\n", val)
> >> +
> >> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
> >> +
> >> +static inline size_t strlcat(char *dest, const char *src, size_t n)
> >> +{
> >> +	strcat(dest, src);
> >> +	return strlen(dest) + strlen(src);
> >> +}
> >> +
> >> +#endif
> > 
> > Similar file has been already added to u-boot.
> > Please look into ./drivers/usb/musb-new/linux-compat.h
> > 
> > @Marek - maybe it is time to have a common one?
> 
> Can we do this separately?

Would it be too much of a hassle to make a common one please ?

The musb-new (and musb) is a fine example why I don't want to let new drivers
add duplicit code. It was the same with musb-new -- this driver was supposed to
replace musb, but this never happened and now we have two drivers in various 
state of support.

Best regards,
Marek Vasut

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-23 14:59       ` Marek Vasut
@ 2015-02-24 13:21         ` Kishon Vijay Abraham I
  2015-02-24 17:42           ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Kishon Vijay Abraham I @ 2015-02-24 13:21 UTC (permalink / raw)
  To: u-boot

Hi,

On Monday 23 February 2015 08:29 PM, Marek Vasut wrote:
> On Monday, February 23, 2015 at 07:19:03 AM, Kishon Vijay Abraham I wrote:
>> Hi,
>>
>> On Monday 16 February 2015 04:02 PM, Lukasz Majewski wrote:
>>> Hi Kishon, Marek
>>>
>>>> Added a header file to include various linux specific APIs like
>>>> pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid compilation
>>>> error while building dwc3 driver.
>>>>
>>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
>>>> ---
>>>>
>>>>    drivers/usb/dwc3/linux-compat.h |   30 ++++++++++++++++++++++++++++++
>>>>    1 file changed, 30 insertions(+)
>>>>    create mode 100644 drivers/usb/dwc3/linux-compat.h
>>>>
>>>> diff --git a/drivers/usb/dwc3/linux-compat.h
>>>> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
>>>> index 0000000..58c4716
>>>> --- /dev/null
>>>> +++ b/drivers/usb/dwc3/linux-compat.h
>>>> @@ -0,0 +1,30 @@
>>>> +/**
>>>> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy Adapter
>>>> Header
>>>> + *
>>>> + * Copyright (C) 2015 Texas Instruments Incorporated -
>>>> http://www.ti.com
>>>> + *
>>>> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
>>>> + *
>>>> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
>>>> + * to uboot.
>>>> + *
>>>> + * SPDX-License-Identifier:	GPL-2.0
>>>> + *
>>>> + */
>>>> +
>>>> +#ifndef __DWC3_LINUX_COMPAT__
>>>> +#define __DWC3_LINUX_COMPAT__
>>>> +
>>>> +#define pr_debug(format)                debug(format)
>>>> +#define WARN(val, format, arg...)	debug(format, ##arg)
>>>> +#define WARN_ON_ONCE(val)		debug("Error %d\n", val)
>>>> +
>>>> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
>>>> +
>>>> +static inline size_t strlcat(char *dest, const char *src, size_t n)
>>>> +{
>>>> +	strcat(dest, src);
>>>> +	return strlen(dest) + strlen(src);
>>>> +}
>>>> +
>>>> +#endif
>>>
>>> Similar file has been already added to u-boot.
>>> Please look into ./drivers/usb/musb-new/linux-compat.h
>>>
>>> @Marek - maybe it is time to have a common one?
>>
>> Can we do this separately?
>
> Would it be too much of a hassle to make a common one please ?

Okay. I sent a new patch which should be applied on top of my v2 that removes 
creating a new linux compatibility header file for dwc3.

Thanks
Kishon

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-24 13:21         ` Kishon Vijay Abraham I
@ 2015-02-24 17:42           ` Marek Vasut
  2015-02-25  8:17             ` Lukasz Majewski
  0 siblings, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-02-24 17:42 UTC (permalink / raw)
  To: u-boot

On Tuesday, February 24, 2015 at 02:21:40 PM, Kishon Vijay Abraham I wrote:
> Hi,
> 
> On Monday 23 February 2015 08:29 PM, Marek Vasut wrote:
> > On Monday, February 23, 2015 at 07:19:03 AM, Kishon Vijay Abraham I wrote:
> >> Hi,
> >> 
> >> On Monday 16 February 2015 04:02 PM, Lukasz Majewski wrote:
> >>> Hi Kishon, Marek
> >>> 
> >>>> Added a header file to include various linux specific APIs like
> >>>> pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid compilation
> >>>> error while building dwc3 driver.
> >>>> 
> >>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> >>>> ---
> >>>> 
> >>>>    drivers/usb/dwc3/linux-compat.h |   30
> >>>>    ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
> >>>>    create mode 100644 drivers/usb/dwc3/linux-compat.h
> >>>> 
> >>>> diff --git a/drivers/usb/dwc3/linux-compat.h
> >>>> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
> >>>> index 0000000..58c4716
> >>>> --- /dev/null
> >>>> +++ b/drivers/usb/dwc3/linux-compat.h
> >>>> @@ -0,0 +1,30 @@
> >>>> +/**
> >>>> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy Adapter
> >>>> Header
> >>>> + *
> >>>> + * Copyright (C) 2015 Texas Instruments Incorporated -
> >>>> http://www.ti.com
> >>>> + *
> >>>> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
> >>>> + *
> >>>> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c) and ported
> >>>> + * to uboot.
> >>>> + *
> >>>> + * SPDX-License-Identifier:	GPL-2.0
> >>>> + *
> >>>> + */
> >>>> +
> >>>> +#ifndef __DWC3_LINUX_COMPAT__
> >>>> +#define __DWC3_LINUX_COMPAT__
> >>>> +
> >>>> +#define pr_debug(format)                debug(format)
> >>>> +#define WARN(val, format, arg...)	debug(format, ##arg)
> >>>> +#define WARN_ON_ONCE(val)		debug("Error %d\n", val)
> >>>> +
> >>>> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
> >>>> +
> >>>> +static inline size_t strlcat(char *dest, const char *src, size_t n)
> >>>> +{
> >>>> +	strcat(dest, src);
> >>>> +	return strlen(dest) + strlen(src);
> >>>> +}
> >>>> +
> >>>> +#endif
> >>> 
> >>> Similar file has been already added to u-boot.
> >>> Please look into ./drivers/usb/musb-new/linux-compat.h
> >>> 
> >>> @Marek - maybe it is time to have a common one?
> >> 
> >> Can we do this separately?
> > 
> > Would it be too much of a hassle to make a common one please ?
> 
> Okay. I sent a new patch which should be applied on top of my v2 that
> removes creating a new linux compatibility header file for dwc3.

Well you know that such patch should really go in first, right ? But it's
pretty pointless to push you to rework the entire thing I'd say, so let's
just apply all this stuff as is. Lukasz, do you plan to pick it all up?

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-24 17:42           ` Marek Vasut
@ 2015-02-25  8:17             ` Lukasz Majewski
  2015-02-25 12:16               ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-25  8:17 UTC (permalink / raw)
  To: u-boot

Hi Marek,

> On Tuesday, February 24, 2015 at 02:21:40 PM, Kishon Vijay Abraham I
> wrote:
> > Hi,
> > 
> > On Monday 23 February 2015 08:29 PM, Marek Vasut wrote:
> > > On Monday, February 23, 2015 at 07:19:03 AM, Kishon Vijay Abraham
> > > I wrote:
> > >> Hi,
> > >> 
> > >> On Monday 16 February 2015 04:02 PM, Lukasz Majewski wrote:
> > >>> Hi Kishon, Marek
> > >>> 
> > >>>> Added a header file to include various linux specific APIs like
> > >>>> pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid
> > >>>> compilation error while building dwc3 driver.
> > >>>> 
> > >>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> > >>>> ---
> > >>>> 
> > >>>>    drivers/usb/dwc3/linux-compat.h |   30
> > >>>>    ++++++++++++++++++++++++++++++ 1 file changed, 30
> > >>>> insertions(+) create mode 100644
> > >>>> drivers/usb/dwc3/linux-compat.h
> > >>>> 
> > >>>> diff --git a/drivers/usb/dwc3/linux-compat.h
> > >>>> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
> > >>>> index 0000000..58c4716
> > >>>> --- /dev/null
> > >>>> +++ b/drivers/usb/dwc3/linux-compat.h
> > >>>> @@ -0,0 +1,30 @@
> > >>>> +/**
> > >>>> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy
> > >>>> Adapter Header
> > >>>> + *
> > >>>> + * Copyright (C) 2015 Texas Instruments Incorporated -
> > >>>> http://www.ti.com
> > >>>> + *
> > >>>> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
> > >>>> + *
> > >>>> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c)
> > >>>> and ported
> > >>>> + * to uboot.
> > >>>> + *
> > >>>> + * SPDX-License-Identifier:	GPL-2.0
> > >>>> + *
> > >>>> + */
> > >>>> +
> > >>>> +#ifndef __DWC3_LINUX_COMPAT__
> > >>>> +#define __DWC3_LINUX_COMPAT__
> > >>>> +
> > >>>> +#define pr_debug(format)                debug(format)
> > >>>> +#define WARN(val, format, arg...)	debug(format, ##arg)
> > >>>> +#define WARN_ON_ONCE(val)		debug("Error %d\n",
> > >>>> val) +
> > >>>> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
> > >>>> +
> > >>>> +static inline size_t strlcat(char *dest, const char *src,
> > >>>> size_t n) +{
> > >>>> +	strcat(dest, src);
> > >>>> +	return strlen(dest) + strlen(src);
> > >>>> +}
> > >>>> +
> > >>>> +#endif
> > >>> 
> > >>> Similar file has been already added to u-boot.
> > >>> Please look into ./drivers/usb/musb-new/linux-compat.h
> > >>> 
> > >>> @Marek - maybe it is time to have a common one?
> > >> 
> > >> Can we do this separately?
> > > 
> > > Would it be too much of a hassle to make a common one please ?
> > 
> > Okay. I sent a new patch which should be applied on top of my v2
> > that removes creating a new linux compatibility header file for
> > dwc3.
> 
> Well you know that such patch should really go in first, right ? But
> it's pretty pointless to push you to rework the entire thing I'd say,
> so let's just apply all this stuff as is. Lukasz, do you plan to pick
> it all up?

It thought that it would be directly taken to -usb tree.

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-25  8:17             ` Lukasz Majewski
@ 2015-02-25 12:16               ` Marek Vasut
  2015-02-25 13:04                 ` Lukasz Majewski
  0 siblings, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-02-25 12:16 UTC (permalink / raw)
  To: u-boot

On Wednesday, February 25, 2015 at 09:17:53 AM, Lukasz Majewski wrote:
> Hi Marek,
> 
> > On Tuesday, February 24, 2015 at 02:21:40 PM, Kishon Vijay Abraham I
> > 
> > wrote:
> > > Hi,
> > > 
> > > On Monday 23 February 2015 08:29 PM, Marek Vasut wrote:
> > > > On Monday, February 23, 2015 at 07:19:03 AM, Kishon Vijay Abraham
> > > > 
> > > > I wrote:
> > > >> Hi,
> > > >> 
> > > >> On Monday 16 February 2015 04:02 PM, Lukasz Majewski wrote:
> > > >>> Hi Kishon, Marek
> > > >>> 
> > > >>>> Added a header file to include various linux specific APIs like
> > > >>>> pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid
> > > >>>> compilation error while building dwc3 driver.
> > > >>>> 
> > > >>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> > > >>>> ---
> > > >>>> 
> > > >>>>    drivers/usb/dwc3/linux-compat.h |   30
> > > >>>>    ++++++++++++++++++++++++++++++ 1 file changed, 30
> > > >>>> 
> > > >>>> insertions(+) create mode 100644
> > > >>>> drivers/usb/dwc3/linux-compat.h
> > > >>>> 
> > > >>>> diff --git a/drivers/usb/dwc3/linux-compat.h
> > > >>>> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
> > > >>>> index 0000000..58c4716
> > > >>>> --- /dev/null
> > > >>>> +++ b/drivers/usb/dwc3/linux-compat.h
> > > >>>> @@ -0,0 +1,30 @@
> > > >>>> +/**
> > > >>>> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy
> > > >>>> Adapter Header
> > > >>>> + *
> > > >>>> + * Copyright (C) 2015 Texas Instruments Incorporated -
> > > >>>> http://www.ti.com
> > > >>>> + *
> > > >>>> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
> > > >>>> + *
> > > >>>> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c)
> > > >>>> and ported
> > > >>>> + * to uboot.
> > > >>>> + *
> > > >>>> + * SPDX-License-Identifier:	GPL-2.0
> > > >>>> + *
> > > >>>> + */
> > > >>>> +
> > > >>>> +#ifndef __DWC3_LINUX_COMPAT__
> > > >>>> +#define __DWC3_LINUX_COMPAT__
> > > >>>> +
> > > >>>> +#define pr_debug(format)                debug(format)
> > > >>>> +#define WARN(val, format, arg...)	debug(format, ##arg)
> > > >>>> +#define WARN_ON_ONCE(val)		debug("Error %d\n",
> > > >>>> val) +
> > > >>>> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
> > > >>>> +
> > > >>>> +static inline size_t strlcat(char *dest, const char *src,
> > > >>>> size_t n) +{
> > > >>>> +	strcat(dest, src);
> > > >>>> +	return strlen(dest) + strlen(src);
> > > >>>> +}
> > > >>>> +
> > > >>>> +#endif
> > > >>> 
> > > >>> Similar file has been already added to u-boot.
> > > >>> Please look into ./drivers/usb/musb-new/linux-compat.h
> > > >>> 
> > > >>> @Marek - maybe it is time to have a common one?
> > > >> 
> > > >> Can we do this separately?
> > > > 
> > > > Would it be too much of a hassle to make a common one please ?
> > > 
> > > Okay. I sent a new patch which should be applied on top of my v2
> > > that removes creating a new linux compatibility header file for
> > > dwc3.
> > 
> > Well you know that such patch should really go in first, right ? But
> > it's pretty pointless to push you to rework the entire thing I'd say,
> > so let's just apply all this stuff as is. Lukasz, do you plan to pick
> > it all up?
> 
> It thought that it would be directly taken to -usb tree.

Oh, oops, right. You're OK with the patchset as-is, right ?

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-25 12:16               ` Marek Vasut
@ 2015-02-25 13:04                 ` Lukasz Majewski
  2015-02-27  9:43                   ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-25 13:04 UTC (permalink / raw)
  To: u-boot

Hi Marek,

> On Wednesday, February 25, 2015 at 09:17:53 AM, Lukasz Majewski wrote:
> > Hi Marek,
> > 
> > > On Tuesday, February 24, 2015 at 02:21:40 PM, Kishon Vijay
> > > Abraham I
> > > 
> > > wrote:
> > > > Hi,
> > > > 
> > > > On Monday 23 February 2015 08:29 PM, Marek Vasut wrote:
> > > > > On Monday, February 23, 2015 at 07:19:03 AM, Kishon Vijay
> > > > > Abraham
> > > > > 
> > > > > I wrote:
> > > > >> Hi,
> > > > >> 
> > > > >> On Monday 16 February 2015 04:02 PM, Lukasz Majewski wrote:
> > > > >>> Hi Kishon, Marek
> > > > >>> 
> > > > >>>> Added a header file to include various linux specific APIs
> > > > >>>> like pr_debug, WARN_ WARN_ON_ONCE etc.. in order to avoid
> > > > >>>> compilation error while building dwc3 driver.
> > > > >>>> 
> > > > >>>> Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
> > > > >>>> ---
> > > > >>>> 
> > > > >>>>    drivers/usb/dwc3/linux-compat.h |   30
> > > > >>>>    ++++++++++++++++++++++++++++++ 1 file changed, 30
> > > > >>>> 
> > > > >>>> insertions(+) create mode 100644
> > > > >>>> drivers/usb/dwc3/linux-compat.h
> > > > >>>> 
> > > > >>>> diff --git a/drivers/usb/dwc3/linux-compat.h
> > > > >>>> b/drivers/usb/dwc3/linux-compat.h new file mode 100644
> > > > >>>> index 0000000..58c4716
> > > > >>>> --- /dev/null
> > > > >>>> +++ b/drivers/usb/dwc3/linux-compat.h
> > > > >>>> @@ -0,0 +1,30 @@
> > > > >>>> +/**
> > > > >>>> + * linux-compat.h - DesignWare USB3 Linux Compatibiltiy
> > > > >>>> Adapter Header
> > > > >>>> + *
> > > > >>>> + * Copyright (C) 2015 Texas Instruments Incorporated -
> > > > >>>> http://www.ti.com
> > > > >>>> + *
> > > > >>>> + * Authors: Kishon Vijay Abraham I <kishon@ti.com>
> > > > >>>> + *
> > > > >>>> + * Taken from Linux Kernel v3.16 (drivers/usb/dwc3/core.c)
> > > > >>>> and ported
> > > > >>>> + * to uboot.
> > > > >>>> + *
> > > > >>>> + * SPDX-License-Identifier:	GPL-2.0
> > > > >>>> + *
> > > > >>>> + */
> > > > >>>> +
> > > > >>>> +#ifndef __DWC3_LINUX_COMPAT__
> > > > >>>> +#define __DWC3_LINUX_COMPAT__
> > > > >>>> +
> > > > >>>> +#define pr_debug(format)                debug(format)
> > > > >>>> +#define WARN(val, format, arg...)	debug(format,
> > > > >>>> ##arg) +#define WARN_ON_ONCE(val)
> > > > >>>> debug("Error %d\n", val) +
> > > > >>>> +#define BUILD_BUG_ON_NOT_POWER_OF_2(n)
> > > > >>>> +
> > > > >>>> +static inline size_t strlcat(char *dest, const char *src,
> > > > >>>> size_t n) +{
> > > > >>>> +	strcat(dest, src);
> > > > >>>> +	return strlen(dest) + strlen(src);
> > > > >>>> +}
> > > > >>>> +
> > > > >>>> +#endif
> > > > >>> 
> > > > >>> Similar file has been already added to u-boot.
> > > > >>> Please look into ./drivers/usb/musb-new/linux-compat.h
> > > > >>> 
> > > > >>> @Marek - maybe it is time to have a common one?
> > > > >> 
> > > > >> Can we do this separately?
> > > > > 
> > > > > Would it be too much of a hassle to make a common one please ?
> > > > 
> > > > Okay. I sent a new patch which should be applied on top of my v2
> > > > that removes creating a new linux compatibility header file for
> > > > dwc3.
> > > 
> > > Well you know that such patch should really go in first, right ?
> > > But it's pretty pointless to push you to rework the entire thing
> > > I'd say, so let's just apply all this stuff as is. Lukasz, do you
> > > plan to pick it all up?
> > 
> > It thought that it would be directly taken to -usb tree.
> 
> Oh, oops, right. You're OK with the patchset as-is, right ?

I have no objections to version 2 of this patch. Feel free to apply it
to -usb tree.

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-25 13:04                 ` Lukasz Majewski
@ 2015-02-27  9:43                   ` Marek Vasut
  2015-02-27 11:28                     ` Lukasz Majewski
  0 siblings, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-02-27  9:43 UTC (permalink / raw)
  To: u-boot

On Wednesday, February 25, 2015 at 02:04:54 PM, Lukasz Majewski wrote:
> Hi Marek,

Hi

[...]

> > > > Well you know that such patch should really go in first, right ?
> > > > But it's pretty pointless to push you to rework the entire thing
> > > > I'd say, so let's just apply all this stuff as is. Lukasz, do you
> > > > plan to pick it all up?
> > > 
> > > It thought that it would be directly taken to -usb tree.
> > 
> > Oh, oops, right. You're OK with the patchset as-is, right ?
> 
> I have no objections to version 2 of this patch. Feel free to apply it
> to -usb tree.

Should be in topic/dwc3 , everyone please check if all is good there.

Best regards,
Marek Vasut

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-27  9:43                   ` Marek Vasut
@ 2015-02-27 11:28                     ` Lukasz Majewski
  2015-03-02  9:51                       ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-02-27 11:28 UTC (permalink / raw)
  To: u-boot

Hi Marek,

> On Wednesday, February 25, 2015 at 02:04:54 PM, Lukasz Majewski wrote:
> > Hi Marek,
> 
> Hi
> 
> [...]
> 
> > > > > Well you know that such patch should really go in first,
> > > > > right ? But it's pretty pointless to push you to rework the
> > > > > entire thing I'd say, so let's just apply all this stuff as
> > > > > is. Lukasz, do you plan to pick it all up?
> > > > 
> > > > It thought that it would be directly taken to -usb tree.
> > > 
> > > Oh, oops, right. You're OK with the patchset as-is, right ?
> > 
> > I have no objections to version 2 of this patch. Feel free to apply
> > it to -usb tree.
> 
> Should be in topic/dwc3 , everyone please check if all is good there.
> 

I think that I've written some comments in the other mail.

In short:

In the topic/dwc3 we are missing linux compatibility rework done by
Kishon.

Only on top of it we could add my fixes for dwc3.

So, it should go as follow:
1. Kishon's 40 patches (dwc3 port)
2. Kishin's linux compat rework
3. Mine: usb: composite: Add .reset callback to usb_gadget_driver
structur

4. On top of point 3 I would need to prepare new patch set with fixes.


> Best regards,
> Marek Vasut



-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-02-27 11:28                     ` Lukasz Majewski
@ 2015-03-02  9:51                       ` Marek Vasut
  2015-03-02 12:56                         ` Lukasz Majewski
  0 siblings, 1 reply; 104+ messages in thread
From: Marek Vasut @ 2015-03-02  9:51 UTC (permalink / raw)
  To: u-boot

On Friday, February 27, 2015 at 12:28:18 PM, Lukasz Majewski wrote:
> Hi Marek,

Hi!

> > On Wednesday, February 25, 2015 at 02:04:54 PM, Lukasz Majewski wrote:
> > > Hi Marek,
> > 
> > Hi
> > 
> > [...]
> > 
> > > > > > Well you know that such patch should really go in first,
> > > > > > right ? But it's pretty pointless to push you to rework the
> > > > > > entire thing I'd say, so let's just apply all this stuff as
> > > > > > is. Lukasz, do you plan to pick it all up?
> > > > > 
> > > > > It thought that it would be directly taken to -usb tree.
> > > > 
> > > > Oh, oops, right. You're OK with the patchset as-is, right ?
> > > 
> > > I have no objections to version 2 of this patch. Feel free to apply
> > > it to -usb tree.
> > 
> > Should be in topic/dwc3 , everyone please check if all is good there.
> 
> I think that I've written some comments in the other mail.
> 
> In short:
> 
> In the topic/dwc3 we are missing linux compatibility rework done by
> Kishon.
> 
> Only on top of it we could add my fixes for dwc3.
> 
> So, it should go as follow:
> 1. Kishon's 40 patches (dwc3 port)
> 2. Kishin's linux compat rework
> 3. Mine: usb: composite: Add .reset callback to usb_gadget_driver
> structur
> 
> 4. On top of point 3 I would need to prepare new patch set with fixes.

Maybe you can prepare those fixes on top of the current ones ? Would that work?

Also, I'm a bit inclined to postpone applying all this stuff until 2015.04 is 
out, what do you think ?

Best regards,
Marek Vasut

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-03-02  9:51                       ` Marek Vasut
@ 2015-03-02 12:56                         ` Lukasz Majewski
  2015-03-02 14:30                           ` Marek Vasut
  0 siblings, 1 reply; 104+ messages in thread
From: Lukasz Majewski @ 2015-03-02 12:56 UTC (permalink / raw)
  To: u-boot

Hi Marek,

> On Friday, February 27, 2015 at 12:28:18 PM, Lukasz Majewski wrote:
> > Hi Marek,
> 
> Hi!
> 
> > > On Wednesday, February 25, 2015 at 02:04:54 PM, Lukasz Majewski
> > > wrote:
> > > > Hi Marek,
> > > 
> > > Hi
> > > 
> > > [...]
> > > 
> > > > > > > Well you know that such patch should really go in first,
> > > > > > > right ? But it's pretty pointless to push you to rework
> > > > > > > the entire thing I'd say, so let's just apply all this
> > > > > > > stuff as is. Lukasz, do you plan to pick it all up?
> > > > > > 
> > > > > > It thought that it would be directly taken to -usb tree.
> > > > > 
> > > > > Oh, oops, right. You're OK with the patchset as-is, right ?
> > > > 
> > > > I have no objections to version 2 of this patch. Feel free to
> > > > apply it to -usb tree.
> > > 
> > > Should be in topic/dwc3 , everyone please check if all is good
> > > there.
> > 
> > I think that I've written some comments in the other mail.
> > 
> > In short:
> > 
> > In the topic/dwc3 we are missing linux compatibility rework done by
> > Kishon.
> > 
> > Only on top of it we could add my fixes for dwc3.
> > 
> > So, it should go as follow:
> > 1. Kishon's 40 patches (dwc3 port)
> > 2. Kishin's linux compat rework
> > 3. Mine: usb: composite: Add .reset callback to usb_gadget_driver
> > structur
> > 
> > 4. On top of point 3 I would need to prepare new patch set with
> > fixes.
> 
> Maybe you can prepare those fixes on top of the current ones ? Would
> that work?

The problem here is with point 2. When do we want to apply linux-compat
rework from Kishon?

Marek, does the presented above scheme work for you?

> 
> Also, I'm a bit inclined to postpone applying all this stuff until
> 2015.04 is out, what do you think ?

We may look how things would go. I've scheduled some time in a very
near future to work on upstreaming dwc3.

> 
> Best regards,
> Marek Vasut



-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

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

* [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy
  2015-03-02 12:56                         ` Lukasz Majewski
@ 2015-03-02 14:30                           ` Marek Vasut
  0 siblings, 0 replies; 104+ messages in thread
From: Marek Vasut @ 2015-03-02 14:30 UTC (permalink / raw)
  To: u-boot

On Monday, March 02, 2015 at 01:56:03 PM, Lukasz Majewski wrote:
> Hi Marek,

Hi!

> > On Friday, February 27, 2015 at 12:28:18 PM, Lukasz Majewski wrote:
> > > Hi Marek,
> > 
> > Hi!
> > 
> > > > On Wednesday, February 25, 2015 at 02:04:54 PM, Lukasz Majewski
> > > > 
> > > > wrote:
> > > > > Hi Marek,
> > > > 
> > > > Hi
> > > > 
> > > > [...]
> > > > 
> > > > > > > > Well you know that such patch should really go in first,
> > > > > > > > right ? But it's pretty pointless to push you to rework
> > > > > > > > the entire thing I'd say, so let's just apply all this
> > > > > > > > stuff as is. Lukasz, do you plan to pick it all up?
> > > > > > > 
> > > > > > > It thought that it would be directly taken to -usb tree.
> > > > > > 
> > > > > > Oh, oops, right. You're OK with the patchset as-is, right ?
> > > > > 
> > > > > I have no objections to version 2 of this patch. Feel free to
> > > > > apply it to -usb tree.
> > > > 
> > > > Should be in topic/dwc3 , everyone please check if all is good
> > > > there.
> > > 
> > > I think that I've written some comments in the other mail.
> > > 
> > > In short:
> > > 
> > > In the topic/dwc3 we are missing linux compatibility rework done by
> > > Kishon.
> > > 
> > > Only on top of it we could add my fixes for dwc3.
> > > 
> > > So, it should go as follow:
> > > 1. Kishon's 40 patches (dwc3 port)
> > > 2. Kishin's linux compat rework
> > > 3. Mine: usb: composite: Add .reset callback to usb_gadget_driver
> > > structur
> > > 
> > > 4. On top of point 3 I would need to prepare new patch set with
> > > fixes.
> > 
> > Maybe you can prepare those fixes on top of the current ones ? Would
> > that work?
> 
> The problem here is with point 2. When do we want to apply linux-compat
> rework from Kishon?

I see we have at least 1. and 3. in topic/dwc3 already, right ? When is
the linux-compat rework coming and when are your patches coming ? Are
either patchsets gonna interfere with one another ?

> Marek, does the presented above scheme work for you?
> 
> > Also, I'm a bit inclined to postpone applying all this stuff until
> > 2015.04 is out, what do you think ?
> 
> We may look how things would go. I've scheduled some time in a very
> near future to work on upstreaming dwc3.

OK, but the RC is already out and there are still issues with the DWC3,
so I am inclined to simply merge apply this after 2015.04 .

Best regards,
Marek Vasut

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

end of thread, other threads:[~2015-03-02 14:30 UTC | newest]

Thread overview: 104+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-06  8:47 [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Kishon Vijay Abraham I
2015-02-06  8:47 ` [U-Boot] [u-boot 01/40] ARM: DRA7: Enable clocks for USB OTGSS and USB PHY Kishon Vijay Abraham I
2015-02-16 10:04   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 02/40] ARM: AM43xx: " Kishon Vijay Abraham I
2015-02-16 10:07   ` Lukasz Majewski
2015-02-16 13:29     ` Marek Vasut
2015-02-20  9:30       ` Kishon Vijay Abraham I
2015-02-20 10:48         ` Marek Vasut
2015-02-06  8:47 ` [U-Boot] [u-boot 03/40] usb: gadget: udc: add udc-core from linux kernel to u-boot Kishon Vijay Abraham I
2015-02-07 13:27   ` Marek Vasut
2015-02-16  9:58     ` Lukasz Majewski
2015-02-16 13:29       ` Marek Vasut
2015-02-16 10:11   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 04/40] include: usb: modify gadget.h to include udc support Kishon Vijay Abraham I
2015-02-16 10:12   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 05/40] usb: gadget: udc: make udc-core compile in u-boot build Kishon Vijay Abraham I
2015-02-16 10:18   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 06/40] include: asm: dma-mapping: get rid of the compilation warning in udc-core Kishon Vijay Abraham I
2015-02-16 10:19   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 07/40] usb: dwc3: add dwc3 folder from linux kernel to u-boot Kishon Vijay Abraham I
2015-02-16 10:20   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 08/40] usb: dwc3: remove un-used files from dwc3 folder Kishon Vijay Abraham I
2015-02-16 10:21   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 09/40] usb: dwc3: Modify the file headers to u-boot format Kishon Vijay Abraham I
2015-02-16 10:21   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 10/40] usb: dwc3: remove trace_* APIs from dwc3 driver Kishon Vijay Abraham I
2015-02-16 10:24   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 11/40] usb: dwc3: fix dwc3 header files Kishon Vijay Abraham I
2015-02-16 10:25   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 12/40] usb: dwc3: remove pm related operations from dwc3 driver Kishon Vijay Abraham I
2015-02-16 10:26   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 13/40] arm: asm: dma-mapping: added dma_free_coherent API Kishon Vijay Abraham I
2015-02-16 10:26   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 14/40] usb: dwc3: linux-compat: Add header for dwc3 linux compatibiltiy Kishon Vijay Abraham I
2015-02-16 10:32   ` Lukasz Majewski
2015-02-23  6:19     ` Kishon Vijay Abraham I
2015-02-23 14:59       ` Marek Vasut
2015-02-24 13:21         ` Kishon Vijay Abraham I
2015-02-24 17:42           ` Marek Vasut
2015-02-25  8:17             ` Lukasz Majewski
2015-02-25 12:16               ` Marek Vasut
2015-02-25 13:04                 ` Lukasz Majewski
2015-02-27  9:43                   ` Marek Vasut
2015-02-27 11:28                     ` Lukasz Majewski
2015-03-02  9:51                       ` Marek Vasut
2015-03-02 12:56                         ` Lukasz Majewski
2015-03-02 14:30                           ` Marek Vasut
2015-02-06  8:47 ` [U-Boot] [u-boot 15/40] usb: dwc3: gadget: make dwc3 gadget build in uboot Kishon Vijay Abraham I
2015-02-16 10:52   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 16/40] include: asm: types: add resource_size_t type Kishon Vijay Abraham I
2015-02-16 10:53   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 17/40] usb: dwc3: ep0: make dwc3 ep0 build in uboot Kishon Vijay Abraham I
2015-02-16 10:54   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 18/40] include: usb: composite: add USB_GADGET_DELAYED_STATUS to avoid compilation error Kishon Vijay Abraham I
2015-02-16 10:55   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 19/40] usb: dwc3: core: make dwc3 core build in uboot Kishon Vijay Abraham I
2015-02-16 10:57   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 20/40] include: dwc3-uboot: add a structure for populating platform data Kishon Vijay Abraham I
2015-02-16 10:58   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 21/40] dwc3: core: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
2015-02-16 10:59   ` Lukasz Majewski
2015-02-06  8:47 ` [U-Boot] [u-boot 22/40] dwc3: core: add support for multiple dwc3 controllers Kishon Vijay Abraham I
2015-02-16 11:00   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 23/40] dwc3: core: added an API to invoke irq handlers Kishon Vijay Abraham I
2015-02-16 11:01   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 24/40] usb: dwc3: dwc3-omap: make dwc3-omap build in uboot Kishon Vijay Abraham I
2015-02-16 11:02   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 25/40] include: dwc3-omap-uboot: add a structure for populating dwc3-omap platform data Kishon Vijay Abraham I
2015-02-16 11:03   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 26/40] usb: dwc3: dwc3-omap: change probe and remove to uboot init and uboot exit code Kishon Vijay Abraham I
2015-02-16 11:04   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 27/40] dwc3: dwc3-omap: add support for multiple dwc3-omap controllers Kishon Vijay Abraham I
2015-02-16 11:06   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 28/40] usb: dwc3: dwc3-omap: add interrupt status API to check for interrupts Kishon Vijay Abraham I
2015-02-16 11:07   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 29/40] usb: dwc3: TI PHY: PHY driver for dwc3 in TI platforms Kishon Vijay Abraham I
2015-02-16 11:13   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 30/40] dwc3: flush the buffers before using it Kishon Vijay Abraham I
2015-02-16 11:39   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 31/40] usb: dwc3: ep0: preparation for implementing chained TRB Kishon Vijay Abraham I
2015-02-16 11:40   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 32/40] usb: dwc3: Add chained TRB support for ep0 Kishon Vijay Abraham I
2015-02-16 11:42   ` Lukasz Majewski
2015-02-16 12:01     ` Kishon Vijay Abraham I
2015-02-16 13:04       ` Lukasz Majewski
2015-02-16 13:06         ` Kishon Vijay Abraham I
2015-02-06  8:48 ` [U-Boot] [u-boot 33/40] usb: dwc3: Makefile: Make dwc3 driver compile in u-boot Kishon Vijay Abraham I
2015-02-16 11:43   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 34/40] usb: gadget: defer setting maxpacket till ->setup() Kishon Vijay Abraham I
2015-02-16 11:44   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 35/40] common: cmd_dfu: invoke board_usb_cleanup() for cleaning up Kishon Vijay Abraham I
2015-02-16 11:47   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 36/40] board: ti: DRA7: added USB initializtion code Kishon Vijay Abraham I
2015-02-16 11:49   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 37/40] include: configs: Enable DWC3 and DFU in DRA7xx Kishon Vijay Abraham I
2015-02-16 11:50   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 38/40] board: ti: AM43xx: added USB initializtion code Kishon Vijay Abraham I
2015-02-16 11:50   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 39/40] include: configs: Enable DWC3 and DFU in AM43xx Kishon Vijay Abraham I
2015-02-16 11:53   ` Lukasz Majewski
2015-02-06  8:48 ` [U-Boot] [u-boot 40/40] usb: modify usb_gadget_handle_interrupts to take controller index Kishon Vijay Abraham I
2015-02-16 11:56   ` Lukasz Majewski
2015-02-07 13:32 ` [U-Boot] [u-boot 00/40] dra7xx: am43xx: add dwc3 gadget driver support and enable dfu Marek Vasut
2015-02-11 11:33   ` Kishon Vijay Abraham I

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.