Skip to contentSkip to conversation

USB: Modify dwc3 code for support Hikey960

RFC NAK Yu Chen 3 participants 8 messages Oct 24, 2017 – Oct 27, 2017

Subsystems (4)
lore
Share & tools
lore

Yu Chen

author
#0 lore raw

cover USB: Modify dwc3 code for support Hikey960

The HiKey960 development platform is based around the HiSilicon Kirin960. The patch sets add support for usb of HiKey960.

Fan Ning (3):
Add document for usb of Hikey960
Modify dwc3 code for support usb of Hikey960
Modify device tree for support Hikey960

 .../devicetree/bindings/usb/hisilicon-usb.txt      |   38 +
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi          |   39 +
 arch/arm64/configs/defconfig                       |    5 +
 drivers/usb/dwc3/Kconfig                           |   26 +
 drivers/usb/dwc3/Makefile                          |    5 +
 drivers/usb/dwc3/core.c                            |   78 +-
 drivers/usb/dwc3/core.h                            |   19 +-
 drivers/usb/dwc3/dwc3-hi3660.c                     |  310 +++
 drivers/usb/dwc3/dwc3-hisi.c                       | 1972 ++++++++++++++++++++
 drivers/usb/dwc3/dwc3-hisi.h                       |  293 +++
 drivers/usb/dwc3/dwc3-otg.c                        |  360 ++++
 drivers/usb/dwc3/dwc3-otg.h                        |  133 ++
 drivers/usb/dwc3/ep0.c                             |   55 +-
 drivers/usb/dwc3/gadget.c                          |   20 +-
 drivers/usb/dwc3/hisi_hikey_gpio.c                 |  300 +++
 drivers/usb/dwc3/host.c                            |   13 +
 drivers/usb/dwc3/io.h                              |   14 +
 include/linux/hisi/log/hisi_log.h                  |  143 ++
 include/linux/hisi/usb/hisi_hikey_gpio.h           |   24 +
 include/linux/hisi/usb/hisi_usb.h                  |   57 +
 20 files changed, 3896 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/hisilicon-usb.txt
 mode change 100644 => 100755 arch/arm64/boot/dts/hisilicon/hi3660.dtsi
 create mode 100644 drivers/usb/dwc3/dwc3-hi3660.c
 create mode 100644 drivers/usb/dwc3/dwc3-hisi.c
 create mode 100644 drivers/usb/dwc3/dwc3-hisi.h
 create mode 100644 drivers/usb/dwc3/dwc3-otg.c
 create mode 100644 drivers/usb/dwc3/dwc3-otg.h
 create mode 100644 drivers/usb/dwc3/hisi_hikey_gpio.c
 create mode 100644 include/linux/hisi/log/hisi_log.h
 create mode 100644 include/linux/hisi/usb/hisi_hikey_gpio.h
 create mode 100644 include/linux/hisi/usb/hisi_usb.h
Signature · 1 line
2.11.GIT
author
#1 lore raw

RFC 1/3 USB: Add document for usb of Hikey960

DT bindings for usb of Hikey960.

---
 .../devicetree/bindings/usb/hisilicon-usb.txt      | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hisilicon-usb.txt
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +38 -0
new file mode 100644
index 000000000000..dc4c460885d6
@@ -0,0 +1,38 @@
+* HISILICON USB HUB
+
+Required properties:
+- compatible: One of the specific types :"hisilicon,hi3660-dwc3",
+			"hisilicon,gpio_hubv1","hisilicon,gpio_hubv2"
+
+Optional properties of devices using ISP1301:
+- transceiver: phandle of isp1301 - this helps the ISP1301 driver to find the
+               ISP1301 instance associated with the respective USB driver
+
+Example:
+
+	hisi_usb at ff200000 {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		compatible = "hisilicon,hi3660-dwc3";
+		reg = <0x0 0xff200000 0x0 0x1000
+			 0x0 0xff100000 0x0 0x100000>;
+		ranges;
+		bc_again_flag = <0>;
+
+		clocks = <&crg_ctrl HI3660_CLK_ABB_USB>,
+			 <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+		clock-names = "clk_usb3phy_ref", "aclk_usb3otg";
+		eye_diagram_param = <0x1c466e3>;
+		eye_diagram_host_param = <0x1c466e3>;
+		usb3_phy_cr_param = <0xb80>;
+		usb3_phy_host_cr_param = <0x980>;
+		usb3_phy_tx_vboost_lvl = <0x5>;
+
+		dwc3 at ff100000 {
+			compatible = "snps,dwc3";
+			reg = <0x0 0xff100000 0x0 0x100000>;
+			interrupts = <0 159 4>, <0 161 4>;
+			dr_mode = "otg";
+			maximum-speed = "super-speed";
+		};
+	};
\ No newline at end of file
Signature · 1 line
2.11.GIT
maintainer
#2 lore raw

Re: [RFC 1/3] USB: Add document for usb of Hikey960

Documentation/devicetree/bindings/usb/hisilicon-usb.txt

Quoted 17 lines · Yu Chen

DT bindings for usb of Hikey960.

---
 .../devicetree/bindings/usb/hisilicon-usb.txt      | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hisilicon-usb.txt
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +0 -0
new file mode 100644
index 000000000000..dc4c460885d6

Should be 3660 specific?

Documentation/devicetree/bindings/usb/hisilicon-usb.txt line 1

Quoted 2 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +1 -0
@@ -0,0 +1,38 @@
+* HISILICON USB HUB

Looks like a controller, not a hub?

Documentation/devicetree/bindings/usb/hisilicon-usb.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +4 -0
+
+Required properties:
+- compatible: One of the specific types :"hisilicon,hi3660-dwc3",
 
+			"hisilicon,gpio_hubv1","hisilicon,gpio_hubv2"

What are these?

Documentation/devicetree/bindings/usb/hisilicon-usb.txt line 9

Quoted 4 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +4 -0
+
+Optional properties of devices using ISP1301:
+- transceiver: phandle of isp1301 - this helps the ISP1301 driver to find the
+               ISP1301 instance associated with the respective USB driver

Really? A full-speed transceiver?

Documentation/devicetree/bindings/usb/hisilicon-usb.txt line 13

Quoted 4 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +4 -0
+
+Example:
+
+	hisi_usb at ff200000 {

usb at ...

Documentation/devicetree/bindings/usb/hisilicon-usb.txt line 20

Quoted 7 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +7 -0
+		#address-cells = <2>;
+		#size-cells = <2>;
+		compatible = "hisilicon,hi3660-dwc3";
+		reg = <0x0 0xff200000 0x0 0x1000
+			 0x0 0xff100000 0x0 0x100000>;
+		ranges;
+		bc_again_flag = <0>;

Not documented. Don't use '_' in property names.

Documentation/devicetree/bindings/usb/hisilicon-usb.txt line 29

Quoted 9 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +9 -0
+
+		clocks = <&crg_ctrl HI3660_CLK_ABB_USB>,
+			 <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+		clock-names = "clk_usb3phy_ref", "aclk_usb3otg";
+		eye_diagram_param = <0x1c466e3>;
+		eye_diagram_host_param = <0x1c466e3>;
+		usb3_phy_cr_param = <0xb80>;
+		usb3_phy_host_cr_param = <0x980>;
+		usb3_phy_tx_vboost_lvl = <0x5>;

All of these have to be documented.

Documentation/devicetree/bindings/usb/hisilicon-usb.txt

Quoted 2 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +2 -0
+
+		dwc3 at ff100000 {

Ah, it's a DWC3 controller. No references to the common binding?

Documentation/devicetree/bindings/usb/hisilicon-usb.txt line 38

Quoted 8 lines
Documentation/devicetree/bindings/usb/hisilicon-usb.txt new file +7 -0
+			compatible = "snps,dwc3";
+			reg = <0x0 0xff100000 0x0 0x100000>;
+			interrupts = <0 159 4>, <0 161 4>;
+			dr_mode = "otg";
+			maximum-speed = "super-speed";
+		};
+	};
\ No newline at end of file

Fix what it says here.

Rob

author
#3 lore raw

RFC 2/3 USB: dwc3: Modify dwc3 code for support usb of Hikey960

In reply to Yu Chen

The usb controller of Kirin960 is DesignWare Cores SuperSpeed USB 3.0 Controller. The patch modifies dwc3 for support Kirin960 and adds codes for a USB Hub on board Hikey960.

---
 arch/arm64/configs/defconfig             |    5 +
 drivers/usb/dwc3/Kconfig                 |   26 +
 drivers/usb/dwc3/Makefile                |    5 +
 drivers/usb/dwc3/core.c                  |   78 +-
 drivers/usb/dwc3/core.h                  |   19 +-
 drivers/usb/dwc3/dwc3-hi3660.c           |  310 +++++
 drivers/usb/dwc3/dwc3-hisi.c             | 1972 ++++++++++++++++++++++++++++++
 drivers/usb/dwc3/dwc3-hisi.h             |  293 +++++
 drivers/usb/dwc3/dwc3-otg.c              |  360 ++++++
 drivers/usb/dwc3/dwc3-otg.h              |  133 ++
 drivers/usb/dwc3/ep0.c                   |   55 +-
 drivers/usb/dwc3/gadget.c                |   20 +-
 drivers/usb/dwc3/hisi_hikey_gpio.c       |  300 +++++
 drivers/usb/dwc3/host.c                  |   13 +
 drivers/usb/dwc3/io.h                    |   14 +
 include/linux/hisi/log/hisi_log.h        |  143 +++
 include/linux/hisi/usb/hisi_hikey_gpio.h |   24 +
 include/linux/hisi/usb/hisi_usb.h        |   57 +
 18 files changed, 3819 insertions(+), 8 deletions(-)
 create mode 100644 drivers/usb/dwc3/dwc3-hi3660.c
 create mode 100644 drivers/usb/dwc3/dwc3-hisi.c
 create mode 100644 drivers/usb/dwc3/dwc3-hisi.h
 create mode 100644 drivers/usb/dwc3/dwc3-otg.c
 create mode 100644 drivers/usb/dwc3/dwc3-otg.h
 create mode 100644 drivers/usb/dwc3/hisi_hikey_gpio.c
 create mode 100644 include/linux/hisi/log/hisi_log.h
 create mode 100644 include/linux/hisi/usb/hisi_hikey_gpio.h
 create mode 100644 include/linux/hisi/usb/hisi_usb.h
arch/arm64/configs/defconfig +5 -0
index 34480e9af2e7..8e61b7d96bba 100644
@@ -405,6 +405,7 @@ CONFIG_SND_SOC_SAMSUNG=y
 CONFIG_SND_SOC_RCAR=m
 CONFIG_SND_SOC_AK4613=m
 CONFIG_SND_SIMPLE_CARD=y
+CONFIG_HISI_HIKEY_GPIO=y
 CONFIG_USB=y
 CONFIG_USB_OTG=y
 CONFIG_USB_XHCI_HCD=y
@@ -419,6 +420,9 @@ CONFIG_USB_OHCI_HCD_PLATFORM=y
 CONFIG_USB_RENESAS_USBHS=m
 CONFIG_USB_STORAGE=y
 CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_DUAL_ROLE=y
+CONFIG_USB_DWC3_HISI=y
+CONFIG_USB_DWC3_OTG=y
 CONFIG_USB_DWC2=y
 CONFIG_USB_CHIPIDEA=y
 CONFIG_USB_CHIPIDEA_UDC=y
@@ -428,6 +432,7 @@ CONFIG_USB_HSIC_USB3503=y
 CONFIG_NOP_USB_XCEIV=y
 CONFIG_USB_MSM_OTG=y
 CONFIG_USB_QCOM_8X16_PHY=y
+CONFIG_EXTCON=y
 CONFIG_USB_ULPI=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_RENESAS_USBHS_UDC=m
drivers/usb/dwc3/Kconfig +26 -0
index ab8c0e0d3b60..5f7d9f19f503 100644
@@ -106,4 +106,30 @@ config USB_DWC3_ST
 	  inside (i.e. STiH407).
 	  Say 'Y' or 'M' if you have one such device.
 
+config USB_DWC3_HISI
+	tristate "Hisilicon Platforms"
+	select USB_DWC3_OTG
+	depends on USB_DWC3
+	default n
+	help
+	  Support of USB2/3 functionality in hisilicon platforms,
+	  Say 'Y' or 'M' here if you have one such device.
+	  Use for hisilicon device and it will select USB_DWC3_OTG
+	  if Say 'Y' or 'M' here.
+
+config USB_DWC3_OTG
+	bool "Enable DWC3 OTG"
+	default n
+	help
+	  Support of USB2/3 functionality in hisilicon platforms,
+	  Say 'Y' or 'M' here if you have one such device.
+	  Use for hisilicon device
+	  if Say 'Y' or 'M' here.
+
+config HISI_HIKEY_GPIO
+    tristate "HISI_HIKEY_GPIO"
+    depends on GPIOLIB
+    default n
+    help
+       If you say yes here you get support for hisi hikey gpio.
 endif
drivers/usb/dwc3/Makefile +5 -0
index f15fabbd1e59..c2c32a5effc7 100644
@@ -1,6 +1,7 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o				:= -I$(src)
 
+ccflags-$(CONFIG_USB_DWC3_OTG)		+= -DDWC3_OTG_FORCE_MODE
 obj-$(CONFIG_USB_DWC3)			+= dwc3.o
 
 dwc3-y					:= core.o
@@ -29,6 +30,8 @@ ifneq ($(CONFIG_DEBUG_FS),)
 	dwc3-y				+= debugfs.o
 endif
 
+dwc3-$(CONFIG_USB_DWC3_OTG)		+= dwc3-otg.o
+
 ##
 # Platform-specific glue layers go here
 #
@@ -47,3 +50,5 @@ obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
 obj-$(CONFIG_USB_DWC3_KEYSTONE)		+= dwc3-keystone.o
 obj-$(CONFIG_USB_DWC3_OF_SIMPLE)	+= dwc3-of-simple.o
 obj-$(CONFIG_USB_DWC3_ST)		+= dwc3-st.o
+obj-$(CONFIG_USB_DWC3_HISI)		+= dwc3-hisi.o  dwc3-hi3660.o
+obj-$(CONFIG_HISI_HIKEY_GPIO)		+= hisi_hikey_gpio.o
drivers/usb/dwc3/core.c +74 -4

164 lines not on this page · raw message

drivers/usb/dwc3/core.h +18 -1
index ea910acb4bb0..3b6dd99daf9a 100644
@@ -750,6 +750,7 @@ struct dwc3_request {
 	unsigned		mapped:1;
 	unsigned		started:1;
 	unsigned		zero:1;
+	unsigned		send_zlp:1;
 };
 
 /*
@@ -980,10 +981,17 @@ struct dwc3 {
 	u8			lpm_nyet_threshold;
 	u8			hird_threshold;
 
+	struct dwc3_otg *dwc_otg;
 	const char		*hsphy_interface;
 
 	unsigned		connected:1;
 	unsigned		delayed_status:1;
+
+	/* the delayed status may come before notready interrupt,
+	 * in this case, don't wait for delayed status
+	 */
+	unsigned		status_queued:1;
+
 	unsigned		ep0_bounced:1;
 	unsigned		ep0_expect_in:1;
 	unsigned		has_hibernation:1;
@@ -1175,7 +1183,7 @@ struct dwc3_gadget_ep_cmd_params {
 /* prototypes */
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
-
+void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode);
 /* check whether we are on the DWC_usb3 core */
 static inline bool dwc3_is_usb3(struct dwc3 *dwc)
 {
@@ -1209,6 +1217,8 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
 int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
 		struct dwc3_gadget_ep_cmd_params *params);
 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
+int dwc3_conndone_notifier_register(struct notifier_block *nb);
+int dwc3_conndone_notifier_unregister(struct notifier_block *nb);
 #else
 static inline int dwc3_gadget_init(struct dwc3 *dwc)
 { return 0; }
@@ -1228,6 +1238,10 @@ static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
 static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
 		int cmd, u32 param)
 { return 0; }
+static inline int dwc3_conndone_notifier_register(struct notifier_block *nb)
+{ return 0; }
+static inline int dwc3_conndone_notifier_unregister(struct notifier_block *nb)
+{ return 0; }
 #endif
 
 #if IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
@@ -1261,6 +1275,9 @@ static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
 }
 #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
 
+int dwc3_resume_device(struct dwc3 *dwc);
+void dwc3_suspend_device(struct dwc3 *dwc);
+
 #if IS_ENABLED(CONFIG_USB_DWC3_ULPI)
 int dwc3_ulpi_init(struct dwc3 *dwc);
 void dwc3_ulpi_exit(struct dwc3 *dwc);
drivers/usb/dwc3/dwc3-hi3660.c new file +310 -0

310 lines not on this page · raw message

drivers/usb/dwc3/dwc3-hisi.c new file +1972 -0

1,972 lines not on this page · raw message

drivers/usb/dwc3/dwc3-hisi.h new file +293 -0

293 lines not on this page · raw message

drivers/usb/dwc3/dwc3-otg.c new file +360 -0

129 lines not on this page · raw message

drivers/usb/dwc3/dwc3-otg.h new file +133 -0

133 lines not on this page · raw message

drivers/usb/dwc3/ep0.c +53 -2

55 lines not on this page · raw message

drivers/usb/dwc3/gadget.c +19 -1
index f064f1549333..069c6eb1cc5c 100644

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

drivers/usb/dwc3/hisi_hikey_gpio.c new file +300 -0

300 lines not on this page · raw message

drivers/usb/dwc3/host.c +13 -0
index 76f0b0df37c1..ccbf0c35a9b1 100644

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

drivers/usb/dwc3/io.h +14 -0
index c69b06696824..adc8648c92b2 100644

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

include/linux/hisi/log/hisi_log.h new file +143 -0

143 lines not on this page · raw message

include/linux/hisi/usb/hisi_hikey_gpio.h new file +24 -0
new file mode 100644
index 000000000000..99df5772df96

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

include/linux/hisi/usb/hisi_usb.h new file +57 -0

57 lines not on this page · raw message

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

Signature · 7 lines
2.11.GIT


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

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

#4 lore raw

Re: [RFC 2/3] USB: dwc3: Modify dwc3 code for support usb of Hikey960

Hi,

Quoted 7 lines · Yu Chen

The usb controller of Kirin960 is DesignWare Cores SuperSpeed USB 3.0 Controller. The patch modifies dwc3 for support Kirin960 and adds codes for a USB Hub on board Hikey960.

you have got to be kidding me if you think I'm gonna take this patch.

Quoted 1 line

+config USB_DWC3_OTG

we already have this using config USB_DWC3_DUAL_ROLE

drivers/usb/dwc3/Makefile line 4

Quoted 9 lines
drivers/usb/dwc3/Makefile +1 -0
index f15fabbd1e59..c2c32a5effc7 100644
@@ -1,6 +1,7 @@
 # define_trace.h needs to know how to find our header
 CFLAGS_trace.o				:= -I$(src)
 
+ccflags-$(CONFIG_USB_DWC3_OTG)		+= -DDWC3_OTG_FORCE_MODE

NOPE!

drivers/usb/dwc3/Makefile ifneq ($(CONFIG_DEBUG_FS),) · line 33

Quoted 1 line
drivers/usb/dwc3/Makefile +1 -0
+dwc3-$(CONFIG_USB_DWC3_OTG)		+= dwc3-otg.o

NOPE!

drivers/usb/dwc3/Makefile obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o · line 54

Quoted 1 line
drivers/usb/dwc3/Makefile +1 -0
+obj-$(CONFIG_HISI_HIKEY_GPIO)		+= hisi_hikey_gpio.o

hell no. You should write a real gpio driver.

drivers/usb/dwc3/core.c line 47

Quoted 10 lines
drivers/usb/dwc3/core.c +1 -1
index 03474d3575ab..d0105a26867d 100644
@@ -44,7 +44,7 @@
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
-
+#include "dwc3-otg.h"

nak

drivers/usb/dwc3/core.c static int dwc3_get_dr_mode(struct dwc3 *dwc) · line 92

Quoted 10 lines
drivers/usb/dwc3/core.c +2 -0
 #include "debug.h"
 
 #define DWC3_DEFAULT_AUTOSUSPEND_DELAY	5000 /* ms */
@@ -87,6 +87,8 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
 			mode = USB_DR_MODE_HOST;
 		else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
 			mode = USB_DR_MODE_PERIPHERAL;
+		else if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE))
+			mode = USB_DR_MODE_OTG;
 	}

why? Also, if this is really needed, it seems like it should be done as a separate patch.

drivers/usb/dwc3/core.c static int dwc3_get_dr_mode(struct dwc3 *dwc) · line 108

Quoted 8 lines
drivers/usb/dwc3/core.c +1 -1
 	if (mode != dwc->dr_mode) {
@@ -103,7 +105,7 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
 static void dwc3_event_buffers_cleanup(struct dwc3 *dwc);
 static int dwc3_event_buffers_setup(struct dwc3 *dwc);
 
-static void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
+void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)

no way you can expose this.

drivers/usb/dwc3/core.c static void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) · line 118

Quoted 5 lines
drivers/usb/dwc3/core.c +1 -0
@@ -113,6 +115,7 @@ static void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
 }
 
+#ifndef CONFIG_USB_DWC3_HISI

no ifdefs

Quoted 12 lines
drivers/usb/dwc3/core.c +1 -0
 static void __dwc3_set_mode(struct work_struct *work)
 {
 	struct dwc3 *dwc = work_to_dwc(work);
@@ -177,6 +180,7 @@ static void __dwc3_set_mode(struct work_struct *work)
 		break;
 	}
 }
+#endif
 
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
 {

drivers/usb/dwc3/core.c static int dwc3_event_buffers_setup(struct dwc3 *dwc) · line 373

Quoted 8 lines
drivers/usb/dwc3/core.c +5 -0
@@ -362,6 +366,12 @@ static int dwc3_event_buffers_setup(struct dwc3 *dwc)
 
 	evt = dwc->ev_buf;
 	evt->lpos = 0;
+	#ifdef CONFIG_USB_DWC3_HISI
+	evt->count = 0;
+	evt->flags = 0;
+	memset(evt->buf, 0, evt->length);
+	#endif

nope. Totally unnecessary. evt was allocated with kzalloc

drivers/usb/dwc3/core.c static void dwc3_core_setup_global_control(struct dwc3 *dwc) · line 743

Quoted 6 lines
drivers/usb/dwc3/core.c +1 -1
@@ -730,7 +740,13 @@ static void dwc3_core_setup_global_control(struct dwc3 *dwc)
 	 */
 	if (dwc->revision < DWC3_REVISION_190A)
 		reg |= DWC3_GCTL_U2RSTECN;
-
+	#ifdef DWC3_OTG_FORCE_MODE

nope

Quoted 10 lines
drivers/usb/dwc3/core.c +6 -0
+	/*
+	 * if ID status is detected by third module, default device mode.
+	 */
+	reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
+	reg |= DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_DEVICE);
+	#endif
 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
 }
 

drivers/usb/dwc3/core.c static int dwc3_core_init_mode(struct dwc3 *dwc) · line 976

Quoted 4 lines
drivers/usb/dwc3/core.c +1 -0
@@ -957,6 +973,7 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
 		}
 		break;
 	case USB_DR_MODE_OTG:
+		#ifndef CONFIG_USB_DWC3_HISI

nope

drivers/usb/dwc3/core.c static int dwc3_core_init_mode(struct dwc3 *dwc) · line 984

Quoted 8 lines
drivers/usb/dwc3/core.c +1 -0
 		INIT_WORK(&dwc->drd_work, __dwc3_set_mode);
 		ret = dwc3_drd_init(dwc);
 		if (ret) {
@@ -964,6 +981,30 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
 				dev_err(dev, "failed to initialize dual-role\n");
 			return ret;
 		}
+		#else

seriously, your platform is really not that important. You DON'T need special code for you platform. Use the generic code we have. If it works for Intel, TI, Xilinx, Altera, ST, Qcom and so many others, it works for you too.

Quoted 27 lines
drivers/usb/dwc3/core.c +23 -0
+		dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_OTG);
+
+		ret = dwc3_otg_init(dwc);
+		if (ret) {
+			dev_err(dev, "failed to initialize otg\n");
+			return ret;
+		}
+
+		ret = dwc3_host_init(dwc);
+		if (ret) {
+			dev_err(dev, "failed to initialize host\n");
+			dwc3_otg_exit(dwc);
+			return ret;
+		}
+
+		ret = dwc3_gadget_init(dwc);
+		if (ret) {
+			dev_err(dev, "failed to initialize gadget\n");
+			dwc3_host_exit(dwc);
+			dwc3_otg_exit(dwc);
+			return ret;
+		}
+		#endif
 		break;
 	default:
 		dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);

drivers/usb/dwc3/core.c static void dwc3_core_exit_mode(struct dwc3 *dwc) · line 1028

Quoted 4 lines
drivers/usb/dwc3/core.c +1 -0
@@ -984,6 +1025,7 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
 		break;
 	case USB_DR_MODE_OTG:
 		dwc3_drd_exit(dwc);
+		dwc3_otg_exit(dwc);

nope

drivers/usb/dwc3/core.c static int dwc3_runtime_checks(struct dwc3 *dwc) · line 1389

Quoted 11 lines
drivers/usb/dwc3/core.c +2 -0
 		break;
 	default:
 		/* do nothing */
@@ -1341,8 +1383,10 @@ static int dwc3_runtime_checks(struct dwc3 *dwc)
 	switch (dwc->dr_mode) {
 	case USB_DR_MODE_PERIPHERAL:
 	case USB_DR_MODE_OTG:
+#ifndef CONFIG_USB_DWC3_HISI
 		if (dwc->connected)
 			return -EBUSY;
+#endif

nope

drivers/usb/dwc3/core.c static int dwc3_runtime_suspend(struct device *dev) · line 1414

Quoted 5 lines
drivers/usb/dwc3/core.c +1 -0
@@ -1367,6 +1411,7 @@ static int dwc3_runtime_suspend(struct device *dev)
 
 	device_init_wakeup(dev, true);
 
+	pm_runtime_put(dev);

nope

drivers/usb/dwc3/core.c static int dwc3_runtime_resume(struct device *dev) · line 1441

Quoted 9 lines
drivers/usb/dwc3/core.c +1 -1
 	return 0;
 }
 
@@ -1393,7 +1438,7 @@ static int dwc3_runtime_resume(struct device *dev)
 	}
 
 	pm_runtime_mark_last_busy(dev);
-	pm_runtime_put(dev);
+	pm_runtime_get(dev);

nope

Quoted 19 lines
drivers/usb/dwc3/core.c +15 -0
@@ -1461,6 +1506,31 @@ static const struct dev_pm_ops dwc3_dev_pm_ops = {
 			dwc3_runtime_idle)
 };
 
+int dwc3_resume_device(struct dwc3 *dwc)
+{
+	int status;
+
+	pr_info("[%s] +\n", __func__);
+	status = dwc3_runtime_resume(dwc->dev);
+	if (status < 0)
+		pr_err("dwc3_runtime_resume err, status:%d\n", status);
+
+	pr_info("[%s] -\n", __func__);
+	return status;
+}
+
+void dwc3_suspend_device(struct dwc3 *dwc)
+{

drivers/usb/dwc3/core.c static const struct dev_pm_ops dwc3_dev_pm_ops = { · line 1533

Quoted 10 lines
drivers/usb/dwc3/core.c +10 -0
+	int status;
+
+	pr_info("[%s] +\n", __func__);
+	status = dwc3_runtime_suspend(dwc->dev);
+	if (status < 0)
+		pr_err("dwc3_runtime_suspend err, status:%d\n", status);
+
+	pr_info("[%s] -\n", __func__);
+}
+

nope. Specially not with pr_*(). That's a sign that you didn't even test this properly.

drivers/usb/dwc3/core.h struct dwc3_request { · line 753

Quoted 12 lines
drivers/usb/dwc3/core.c +0 -0
 #ifdef CONFIG_OF
 static const struct of_device_id of_dwc3_match[] = {
 	{
drivers/usb/dwc3/core.h +1 -0
index ea910acb4bb0..3b6dd99daf9a 100644
@@ -750,6 +750,7 @@ struct dwc3_request {
 	unsigned		mapped:1;
 	unsigned		started:1;
 	unsigned		zero:1;
+	unsigned		send_zlp:1;

nope. struct usb_request already has this.

drivers/usb/dwc3/core.h struct dwc3 { · line 984

Quoted 5 lines
drivers/usb/dwc3/core.h +1 -0
@@ -980,10 +981,17 @@ struct dwc3 {
 	u8			lpm_nyet_threshold;
 	u8			hird_threshold;
 
+	struct dwc3_otg *dwc_otg;

no

drivers/usb/dwc3/core.h struct dwc3 { · line 993

Quoted 9 lines
drivers/usb/dwc3/core.h +5 -0
 	const char		*hsphy_interface;
 
 	unsigned		connected:1;
 	unsigned		delayed_status:1;
+
+	/* the delayed status may come before notready interrupt,
+	 * in this case, don't wait for delayed status
+	 */
+	unsigned		status_queued:1;

we ALREADY cope with this situation. Why do you think mass storage gadget works?

drivers/usb/dwc3/core.h struct dwc3_gadget_ep_cmd_params { · line 1186

Quoted 6 lines
drivers/usb/dwc3/core.h +1 -1
@@ -1175,7 +1183,7 @@ struct dwc3_gadget_ep_cmd_params {
 /* prototypes */
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
-
+void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode);

nope

drivers/usb/dwc3/core.h int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); · line 1221

Quoted 9 lines
drivers/usb/dwc3/core.h +2 -0
 /* check whether we are on the DWC_usb3 core */
 static inline bool dwc3_is_usb3(struct dwc3 *dwc)
 {
@@ -1209,6 +1217,8 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
 int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
 		struct dwc3_gadget_ep_cmd_params *params);
 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
+int dwc3_conndone_notifier_register(struct notifier_block *nb);
+int dwc3_conndone_notifier_unregister(struct notifier_block *nb);

no way.

drivers/usb/dwc3/core.h static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, · line 1244

Quoted 8 lines
drivers/usb/dwc3/core.h +4 -0
@@ -1228,6 +1238,10 @@ static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
 static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
 		int cmd, u32 param)
 { return 0; }
+static inline int dwc3_conndone_notifier_register(struct notifier_block *nb)
+{ return 0; }
+static inline int dwc3_conndone_notifier_unregister(struct notifier_block *nb)
+{ return 0; }

nope

drivers/usb/dwc3/core.h static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc) · line 1279

Quoted 6 lines
drivers/usb/dwc3/core.h +2 -0
@@ -1261,6 +1275,9 @@ static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
 }
 #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
 
+int dwc3_resume_device(struct dwc3 *dwc);
+void dwc3_suspend_device(struct dwc3 *dwc);

and no. I think you see a pattern here.

Quoted 147 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +141 -0
new file mode 100644
index 000000000000..d8cdc0f7280b
@@ -0,0 +1,310 @@
+/*
+ * dwc3-hi3660.c
+ *
+ * Copyright: (C) 2008-2018 hisilicon.
+ * Contact: wangbinghui<[email protected]>
+ *
+ * USB vbus for Hisilicon device
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose this file to be licensed under the terms
+ * of the GNU General Public License (GPL) Version 2 or the 2-clause
+ * BSD license listed below:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ */
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+
+#include "dwc3-hisi.h"
+
+/*lint -e750 -esym(750,*)*/
+/* clk module will round to 228M */
+#define USB3OTG_ACLK_FREQ		229000000
+#ifndef BIT
+#define BIT(x)	(1 << (x))
+#endif
+#define SCTRL_SCDEEPSLEEPED				0x08
+#define USB_REFCLK_ISO_EN               BIT(25)
+#define PCTRL_PERI_CTRL3                0x10
+#define USB_TCXO_EN						BIT(1)
+#define PERI_CTRL3_MSK_START            (16)
+#define SC_CLK_USB3PHY_3MUX1_SEL        BIT(25)
+
+#define SC_SEL_ABB_BACKUP               BIT(8)
+#define CLKDIV_MASK_START               (16)
+
+#define PERI_CRG_CLKDIV21               0xFC
+
+#define GT_CLK_ABB_BACKUP               BIT(22)
+#define PERI_CRG_CLK_DIS5               0x54
+
+#define PMC_PPLL3CTRL0                  0x048
+#define PPLL3_FBDIV_START               (8)
+#define PPLL3_EN                        BIT(0)
+#define PPLL3_BP                        BIT(1)
+#define PPLL3_LOCK                      BIT(26)
+
+#define PMC_PPLL3CTRL1                  0x04C
+#define PPLL3_INT_MOD                   BIT(24)
+#define GT_CLK_PPLL3                    BIT(26)
+
+#define PERI_CRG_CLK_EN5                0x50
+
+#define SC_USB3PHY_ABB_GT_EN            BIT(15)
+#define REF_SSP_EN                      BIT(16)
+/*lint -e750 +esym(750,*)*/
+
+static int usb3_regu_init(struct hisi_dwc3_device *hisi_dwc3)
+{
+	if (hisi_dwc3->is_regu_on != 0) {
+		usb_dbg("ldo already opened!\n");
+		return 0;
+	}
+
+	hisi_dwc3->is_regu_on = 1;
+
+	return 0;
+}
+
+static int usb3_regu_shutdown(struct hisi_dwc3_device *hisi_dwc3)
+{
+	if (hisi_dwc3->is_regu_on == 0) {
+		usb_dbg("regu already closed!\n");
+		return 0;
+	}
+
+	hisi_dwc3->is_regu_on = 0;
+
+	return 0;
+}
+
+static int usb3_clk_init(struct hisi_dwc3_device *hisi_dwc3)
+{
+	int ret;
+	u32 temp;
+	void __iomem *pctrl_base = hisi_dwc3->pctrl_reg_base;
+	void __iomem *pericfg_base = hisi_dwc3->pericfg_reg_base;
+
+	/* set usb aclk 240MHz to improve performance */
+	ret = clk_set_rate(hisi_dwc3->gt_aclk_usb3otg, USB3OTG_ACLK_FREQ);
+	if (ret)
+		usb_err("usb aclk set rate failed\n");
+
+	ret = clk_prepare_enable(hisi_dwc3->gt_aclk_usb3otg);
+	if (ret) {
+		usb_err("clk_prepare_enable gt_aclk_usb3otg failed\n");
+		return ret;
+	}
+
+	/* usb refclk iso enable */
+	writel(USB_REFCLK_ISO_EN, pericfg_base + PERI_CRG_ISODIS);
+
+	/* enable usb_tcxo_en */
+	writel(USB_TCXO_EN | (USB_TCXO_EN << PERI_CTRL3_MSK_START),
+	       pctrl_base + PCTRL_PERI_CTRL3);
+
+	/* select usbphy clk from abb */
+	temp = readl(pctrl_base + PCTRL_PERI_CTRL24);
+	temp &= ~SC_CLK_USB3PHY_3MUX1_SEL;
+	writel(temp, pctrl_base + PCTRL_PERI_CTRL24);
+
+	/* open clk gate */
+	writel(GT_CLK_USB3OTG_REF | GT_ACLK_USB3OTG,
+	       pericfg_base + PERI_CRG_CLK_EN4);
+
+	ret = clk_prepare_enable(hisi_dwc3->clk);
+	if (ret) {
+		usb_err("clk_prepare_enable clk failed\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static void usb3_clk_shutdown(struct hisi_dwc3_device *hisi_dwc3)
+{
+	u32 temp;
+	void __iomem *pctrl_base = hisi_dwc3->pctrl_reg_base;
+	void __iomem *pericfg_base = hisi_dwc3->pericfg_reg_base;
+

drivers/usb/dwc3/dwc3-hi3660.c line 151

Quoted 10 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +10 -0
+	writel(GT_CLK_USB3OTG_REF | GT_ACLK_USB3OTG,
+	       pericfg_base + PERI_CRG_CLK_DIS4);
+
+	temp = readl(pctrl_base + PCTRL_PERI_CTRL24);
+	temp &= ~SC_CLK_USB3PHY_3MUX1_SEL;
+	writel(temp, pctrl_base + PCTRL_PERI_CTRL24);
+
+	/* disable usb_tcxo_en */
+	writel(0 | (USB_TCXO_EN << PERI_CTRL3_MSK_START),
+	       pctrl_base + PCTRL_PERI_CTRL3);

looks like this should be part of your clock driver.

Quoted 31 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +31 -0
+	clk_disable_unprepare(hisi_dwc3->clk);
+	clk_disable_unprepare(hisi_dwc3->gt_aclk_usb3otg);
+
+	msleep(20);
+}
+
+static void dwc3_release(struct hisi_dwc3_device *hisi_dwc3)
+{
+	u32 temp;
+	void __iomem *pericfg_base = hisi_dwc3->pericfg_reg_base;
+	void __iomem *otg_bc_base = hisi_dwc3->otg_bc_reg_base;
+
+	/* dis-reset the module */
+	writel(IP_RST_USB3OTG_MUX | IP_RST_USB3OTG_AHBIF | IP_RST_USB3OTG_32K,
+	       pericfg_base + PERI_CRG_RSTDIS4);
+
+	/* reset phy */
+	writel(IP_RST_USB3OTGPHY_POR | IP_RST_USB3OTG,
+	       pericfg_base + PERI_CRG_RSTEN4);
+
+	/* enable phy ref clk */
+	temp = readl(otg_bc_base + USBOTG3_CTRL0);
+	temp |= SC_USB3PHY_ABB_GT_EN;
+	writel(temp, otg_bc_base + USBOTG3_CTRL0);
+
+	temp = readl(otg_bc_base + USBOTG3_CTRL7);
+	temp |= REF_SSP_EN;
+	writel(temp, otg_bc_base + USBOTG3_CTRL7);
+
+	/* exit from IDDQ mode */
+	temp = readl(otg_bc_base + USBOTG3_CTRL2);

drivers/usb/dwc3/dwc3-hi3660.c line 193

Quoted 10 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +10 -0
+	temp &= ~(USBOTG3CTRL2_POWERDOWN_HSP | USBOTG3CTRL2_POWERDOWN_SSP);
+	writel(temp, otg_bc_base + USBOTG3_CTRL2);
+
+	usleep_range(100, 120);
+
+	/* dis-reset phy */
+	writel(IP_RST_USB3OTGPHY_POR, pericfg_base + PERI_CRG_RSTDIS4);
+
+	/* dis-reset controller */
+	writel(IP_RST_USB3OTG, pericfg_base + PERI_CRG_RSTDIS4);

and for this you need a PHY driver under drivers/phy/

Quoted 8 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +8 -0
+	msleep(20);
+
+	/* fake vbus valid signal */
+	temp = readl(otg_bc_base + USBOTG3_CTRL3);
+	temp |= (USBOTG3_CTRL3_VBUSVLDEXT | USBOTG3_CTRL3_VBUSVLDEXTSEL);
+	writel(temp, otg_bc_base + USBOTG3_CTRL3);
+
+	usleep_range(100, 120);

drivers/usb/dwc3/dwc3-hi3660.c line 212

Quoted 10 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +10 -0
+}
+
+static void dwc3_reset(struct hisi_dwc3_device *hisi_dwc3)
+{
+	void __iomem *pericfg_base = hisi_dwc3->pericfg_reg_base;
+
+	writel(IP_RST_USB3OTG, pericfg_base + PERI_CRG_RSTEN4);
+	writel(IP_RST_USB3OTGPHY_POR, pericfg_base + PERI_CRG_RSTEN4);
+	writel(IP_RST_USB3OTG_MUX | IP_RST_USB3OTG_AHBIF | IP_RST_USB3OTG_32K,
+	       pericfg_base + PERI_CRG_RSTEN4);

phy_reset()

drivers/usb/dwc3/dwc3-hi3660.c line 221

Quoted 9 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +9 -0
+}
+
+static int hi3660_usb3phy_init(struct hisi_dwc3_device *hisi_dwc3)
+{
+	int ret;
+
+	usb_dbg("+\n");
+
+	ret = usb3_regu_init(hisi_dwc3);

use regulator API

drivers/usb/dwc3/dwc3-hi3660.c line 225

Quoted 4 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +4 -0
+	if (ret)
+		return ret;
+
+	ret = usb3_clk_init(hisi_dwc3);

common clk framework

drivers/usb/dwc3/dwc3-hi3660.c line 230

Quoted 5 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +5 -0
+	if (ret)
+		return ret;
+
+	dwc3_release(hisi_dwc3);
+	config_femtophy_param(hisi_dwc3);

phy_init()

drivers/usb/dwc3/dwc3-hi3660.c line 234

Quoted 3 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +3 -0
+	set_hisi_dwc3_power_flag(1);
+
+	usb_dbg("-\n");

pointless debugging message.

Quoted 11 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +11 -0
+static int hi3660_usb3phy_shutdown(struct hisi_dwc3_device *hisi_dwc3)
+{
+	int ret;
+
+	usb_dbg("+\n");
+
+	set_hisi_dwc3_power_flag(0);
+
+	dwc3_reset(hisi_dwc3);
+	usb3_clk_shutdown(hisi_dwc3);
+

drivers/usb/dwc3/dwc3-hi3660.c line 259

Quoted 10 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +10 -0
+	ret = usb3_regu_shutdown(hisi_dwc3);
+	if (ret)
+		return ret;
+
+	usb_dbg("-\n");
+
+	return 0;
+}
+
+static struct usb3_phy_ops hi3660_phy_ops = {

you want your own special PHY API? Are you nuts?? No way dude. Use drivers/phy/

Quoted 37 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +37 -0
+	.init		= hi3660_usb3phy_init,
+	.shutdown	= hi3660_usb3phy_shutdown,
+};
+
+static int dwc3_hi3660_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+
+	ret = hisi_dwc3_probe(pdev, &hi3660_phy_ops);
+	if (ret)
+		usb_err("probe failed, ret=[%d]\n", ret);
+
+	return ret;
+}
+
+static int dwc3_hi3660_remove(struct platform_device *pdev)
+{
+	int ret = 0;
+
+	ret = hisi_dwc3_remove(pdev);
+	if (ret)
+		usb_err("hisi_dwc3_remove failed, ret=[%d]\n", ret);
+
+	return ret;
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id dwc3_hi3660_match[] = {
+	{ .compatible = "hisilicon,hi3660-dwc3" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, dwc3_hi3660_match);
+#else
+#define dwc3_hi3660_match NULL
+#endif
+
+static struct platform_driver dwc3_hi3660_driver = {

drivers/usb/dwc3/dwc3-hi3660.c line 306

Quoted 10 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +10 -0
+	.probe		= dwc3_hi3660_probe,
+	.remove		= dwc3_hi3660_remove,
+	.driver		= {
+		.name	= "usb3-hi3660",
+		.of_match_table = of_match_ptr(dwc3_hi3660_match),
+		.pm	= HISI_DWC3_PM_OPS,
+	},
+};
+
+module_platform_driver(dwc3_hi3660_driver);

seriously. All you need is for you compatible flag to be added to dwc3-of-simple.c. Everything else should be done elsewhere (regulator API, common clock framework, gpiolib, etc)

drivers/usb/dwc3/dwc3-hi3660.c line 302

Quoted 3 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +3 -0
+/*lint -save -e750 */
+DEVICE_ATTR(plugusb, (0644), plugusb_show, plugusb_store);
+/*lint -restore */

what?

drivers/usb/dwc3/dwc3-hi3660.c line 310

Quoted 8 lines
drivers/usb/dwc3/dwc3-hi3660.c new file +8 -0
+static const char * const charger_type_array[] = {
+	[CHARGER_TYPE_SDP]     = "sdp",       /* Standard Downstreame Port */
+	[CHARGER_TYPE_CDP]     = "cdp",       /* Charging Downstreame Port */
+	[CHARGER_TYPE_DCP]     = "dcp",       /* Dedicate Charging Port */
+	[CHARGER_TYPE_UNKNOWN] = "unknown",   /* non-standard */
+	[CHARGER_TYPE_NONE]    = "none",      /* not connected */
+	[PLEASE_PROVIDE_POWER] = "provide"   /* host mode, provide power */
+};

I think Linaro, recently, added support for chargers to mainline. You should use what they did.

I'm gonna stop here. There's no way I'm going through this much code in a single patch. Specially since 90% of it is either completely unnecessary or should be done using already-existing generic APIs.

Sorry, no cookie today.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20171024/2c30c195/attachment-0001.sig>
author
#5 lore raw

Re: [RFC 2/3] USB: dwc3: Modify dwc3 code for support usb of Hikey960

Hi, Felipe

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 4 lines · Yu Chen
Quoted 4 lines

The usb controller of Kirin960 is DesignWare Cores SuperSpeed USB 3.0 Controller. The patch modifies dwc3 for support Kirin960 and adds codes for a USB Hub on board Hikey960.

Signed-off-by Yu Chen

<[email protected]>

Quoted 3 lines
Quoted 8 lines

I think Linaro, recently, added support for chargers to mainline. You should use what they did.

I'm gonna stop here. There's no way I'm going through this much code in a single patch. Specially since 90% of it is either completely unnecessary or should be done using already-existing generic APIs.

Sorry, no cookie today.

Thanks a lot for your comments!
These codes have been tested on Hikey960 board and work well. But indeed the codes can be simplified and made comply with already-existing architecture.
We will work on these codes according to your reviews and make parted patch next time.

Thanks,
Yu Chen

author
#6 lore raw

Re: [RFC 2/3] USB: dwc3: Modify dwc3 code for support usb of Hikey960

Hi, Felipe

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 4 lines · Yu Chen
Quoted 4 lines

The usb controller of Kirin960 is DesignWare Cores SuperSpeed USB 3.0 Controller. The patch modifies dwc3 for support Kirin960 and adds codes for a USB Hub on board Hikey960.

Signed-off-by Yu Chen

<[email protected]>

Quoted 3 lines
Quoted 8 lines

I think Linaro, recently, added support for chargers to mainline. You should use what they did.

I'm gonna stop here. There's no way I'm going through this much code in a single patch. Specially since 90% of it is either completely unnecessary or should be done using already-existing generic APIs.

Sorry, no cookie today.

Thanks a lot for your comments!
These codes have been tested on Hikey960 board and work well. But indeed the codes can be simplified and made comply with already-existing architecture.
We will work on these codes according to your reviews and make parted patch next time.

Thanks,
Yu Chen

author
#7 lore raw

RFC 3/3 arm64: dts: Modify device tree for support Hikey960

In reply to Yu Chen

Add dts for usb module of Hikey960.

---
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi | 39 +++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
arch/arm64/boot/dts/hisilicon/hi3660.dtsi +39 -0
index b7a90d632959..dff3e68c5e38 100644
@@ -324,6 +324,18 @@
 			status = "disabled";
 		};
 
+		hubv2: gpio_hubv2 {
+			compatible = "hisilicon,gpio_hubv2";
+			typc_vbus_int_gpio,typec-gpios = <&gpio25 2 0>;
+			typc_vbus_enable_val = <1>;
+			otg_gpio = <&gpio25 6 0>;
+			hub_vdd12_en_gpio = <&gpio2 1 0>;
+			hub_vdd33_en_gpio = <&gpio5 6 0>;
+			hub_reset_en_gpio = <&gpio4 4 0>;
+			pinctrl-names = "default";
+			pinctrl-0 = <&usbhub5734_pmx_func>;
+		};
+
 		i2c3: i2c at fdf0c000 {
 			compatible = "snps,designware-i2c";
 			reg = <0x0 0xfdf0c000 0x0 0x1000>;
@@ -978,5 +990,32 @@
 			clocks = <&crg_ctrl HI3660_OSC32K>;
 			clock-names = "apb_pclk";
 		};
+
+		hisi_usb at ff200000 {
+			#address-cells = <2>;
+			#size-cells = <2>;
+			compatible = "hisilicon,hi3660-dwc3";
+			reg = <0x0 0xff200000 0x0 0x1000
+				 0x0 0xff100000 0x0 0x100000>;
+			ranges;
+			bc_again_flag = <0>;
+
+			clocks = <&crg_ctrl HI3660_CLK_ABB_USB>,
+				 <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+			clock-names = "clk_usb3phy_ref", "aclk_usb3otg";
+			eye_diagram_param = <0x1c466e3>;
+			eye_diagram_host_param = <0x1c466e3>;
+			usb3_phy_cr_param = <0xb80>;
+			usb3_phy_host_cr_param = <0x980>;
+			usb3_phy_tx_vboost_lvl = <0x5>;
+
+			dwc3 at ff100000 {
+				compatible = "snps,dwc3";
+				reg = <0x0 0xff100000 0x0 0x100000>;
+				interrupts = <0 159 4>, <0 161 4>;
+				dr_mode = "otg";
+				maximum-speed = "super-speed";
+			};
+		};
 	};
 };
Signature · 1 line
2.11.GIT