Add USB support for Hikey 970
Subsystems (7)
cover Add USB support for Hikey 970
This RFC adds what seems to be needed for USB to work with Hikey 970. While this driver works fine on Kernel 4.9 and 4.19, there's a hack there, in the form of some special binding logic under dwg3 driver, that seems to
be just adding some delay, and doing some different initializations at
PM (basically, disabling autosuspend).
With upstream Kernel, however, I'm getting a hard to track
Kernel panic:
[ 1.837458] SError Interrupt on CPU0, code 0xbf000002 -- SError [ 1.837462] CPU: 0 PID: 74 Comm: kworker/0:1 Not tainted 5.8.0+ #205 [ 1.837463] Hardware name: HiKey970 (DT) [ 1.837465] Workqueue: events deferred_probe_work_func [ 1.837467] pstate: 20000005 (nzCv daif -PAN -UAO BTYPE=--) [ 1.837468] pc : _raw_spin_unlock_irqrestore+0x18/0x50 [ 1.837469] lr : regmap_unlock_spinlock+0x14/0x20 [ 1.837470] sp : ffff8000124dba60 [ 1.837471] x29: ffff8000124dba60 x28: 0000000000000000 [ 1.837474] x27: ffff0001b7e854c8 x26: ffff80001204ea18 [ 1.837476] x25: 0000000000000005 x24: ffff800011f918f8 [ 1.837479] x23: ffff800011fbb588 x22: ffff0001b7e40e00 [ 1.837481] x21: 0000000000000100 x20: 0000000000000000 [ 1.837483] x19: ffff0001b767ec00 x18: 00000000ff10c000 [ 1.837485] x17: 0000000000000002 x16: 0000b0740fdb9950 [ 1.837488] x15: ffff8000116c1198 x14: ffffffffffffffff [ 1.837490] x13: 0000000000000030 x12: 0101010101010101 [ 1.837493] x11: 0000000000000020 x10: ffff0001bf17d130 [ 1.837495] x9 : 0000000000000000 x8 : ffff0001b6938080 [ 1.837497] x7 : 0000000000000000 x6 : 000000000000003f [ 1.837500] x5 : 0000000000000000 x4 : 0000000000000000 [ 1.837502] x3 : ffff80001096a880 x2 : 0000000000000000 [ 1.837505] x1 : ffff0001b7e40e00 x0 : 0000000100000001 [ 1.837507] Kernel panic - not syncing: Asynchronous SError Interrupt [ 1.837509] CPU: 0 PID: 74 Comm: kworker/0:1 Not tainted 5.8.0+ #205 [ 1.837510] Hardware name: HiKey970 (DT) [ 1.837511] Workqueue: events deferred_probe_work_func [ 1.837513] Call trace: [ 1.837514] dump_backtrace+0x0/0x1e0 [ 1.837515] show_stack+0x18/0x24 [ 1.837516] dump_stack+0xc0/0x11c [ 1.837517] panic+0x15c/0x324 [ 1.837518] nmi_panic+0x8c/0x90 [ 1.837519] arm64_serror_panic+0x78/0x84 [ 1.837520] do_serror+0x158/0x15c [ 1.837521] el1_error+0x84/0x100 [ 1.837522] _raw_spin_unlock_irqrestore+0x18/0x50 [ 1.837523] regmap_write+0x58/0x80 [ 1.837524] hi3660_reset_deassert+0x28/0x34 [ 1.837526] reset_control_deassert+0x50/0x260 [ 1.837527] reset_control_deassert+0xf4/0x260 [ 1.837528] dwc3_probe+0x5dc/0xe6c [ 1.837529] platform_drv_probe+0x54/0xb0 [ 1.837530] really_probe+0xe0/0x490 [ 1.837531] driver_probe_device+0xf4/0x160 [ 1.837532] __device_attach_driver+0x8c/0x114 [ 1.837533] bus_for_each_drv+0x78/0xcc [ 1.837534] __device_attach+0x108/0x1a0 [ 1.837535] device_initial_probe+0x14/0x20 [ 1.837537] bus_probe_device+0x98/0xa0 [ 1.837538] deferred_probe_work_func+0x88/0xe0 [ 1.837539] process_one_work+0x1cc/0x350 [ 1.837540] worker_thread+0x2c0/0x470 [ 1.837541] kthread+0x154/0x160 [ 1.837542] ret_from_fork+0x10/0x30 [ 1.837569] SMP: stopping secondary CPUs [ 1.837570] Kernel Offset: 0x1d0000 from 0xffff800010000000 [ 1.837571] PHYS_OFFSET: 0x0 [ 1.837572] CPU features: 0x240002,20882004 [ 1.837573] Memory Limit: none
I suspect that the driver works downstream because of the extra delay of probing an additional driver, as porting such driver to upstream sometimes makes this driver to work. So, it could be due to some race condition.
The problem could also be due to something wrong at DT, as, with the additional driver, the DT bindings are different.
As I'm not familiar about the Serror error mechanism on ARM, I'm wondering if someone could give me some hint about how can I identify what's happening here. Due to the panic(), I can't check what wrong happened there. Not sure if it would be safe to just hack the error handling part of Serror, in order to let the boot to finish.
PS.: the driver/misc hisi_hikey_usb driver on this series came from the John Stultz Hikey 960 tree.
Thanks!
Mauro
Mauro Carvalho Chehab (7):
phy: hisilicon: phy-hi3670-usb3: use a consistent namespace
phy: hisilicon: phy-hi3670-usb3: fix coding style
phy: hisilicon: phy-hi3670-usb3: change some DT properties
dt-bindings: phy: convert phy-kirin970-usb3.txt to yaml
MAINTAINERS: add myself as maintainer for Kirin 970 USB PHY
misc: hisi_hikey_usb: add support for Hikey 970
dts: hisilicon: add support for USB3 on Hikey 970
Yu Chen (3):
phy: hisilicon: add USB physical layer for Kirin 3670
phy: hisilicon: phy-hi3670-usb3: fix some issues at the init code
misc: hisi_hikey_usb: Driver to support onboard USB gpio hub on
Hikey960
.../bindings/phy/hisilicon,hi3670-usb3.yaml | 72 ++ MAINTAINERS | 16 +- .../boot/dts/hisilicon/hi3670-hikey970.dts | 103 +++ arch/arm64/boot/dts/hisilicon/hi3670.dtsi | 49 ++ drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/hisi_hikey_usb.c | 272 +++++++ drivers/phy/hisilicon/Kconfig | 10 + drivers/phy/hisilicon/Makefile | 1 + drivers/phy/hisilicon/phy-hi3670-usb3.c | 671 ++++++++++++++++++ 10 files changed, 1203 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/phy/hisilicon,hi3670-usb3.yaml create mode 100644 drivers/misc/hisi_hikey_usb.c create mode 100644 drivers/phy/hisilicon/phy-hi3670-usb3.c
Signature · 1 line
2.26.2
RFC 1/10 phy: hisilicon: add USB physical layer for Kirin 3670
From: Yu Chen <[email protected]>
Add the Hisilicon Kirin 3670 USB phy driver just after the hi3660, using the same namespace.
This driver was imported from Linaro's official Hikey 970 tree, from the original patch, removing the addition of the dwg3-specific parts.
--- .../bindings/phy/phy-hi3670-usb3.txt | 25 + drivers/phy/hisilicon/Kconfig | 10 + drivers/phy/hisilicon/Makefile | 1 + drivers/phy/hisilicon/phy-hi3670-usb3.c | 682 ++++++++++++++++++ 4 files changed, 718 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt create mode 100644 drivers/phy/hisilicon/phy-hi3670-usb3.c
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt new file +25 -0
@@ -0,0 +1,25 @@ +Hisilicon Kirin970 usb PHY +----------------------- + +Required properties: +- compatible: should be "hisilicon,kirin970-usb-phy" +- #phy-cells: must be 0 +- hisilicon,pericrg-syscon: phandle of syscon used to control phy. +- hisilicon,pctrl-syscon: phandle of syscon used to control phy. +- hisilicon,sctrl-syscon: phandle of syscon used to control phy. +- hisilicon,usb31-misc-syscon: phandle of syscon used to control phy. +- eye-diagram-param: parameter set for phy +- usb3-phy-tx-vboost-lvl: parameter set for phy +Refer to phy/phy-bindings.txt for the generic PHY binding properties + +Example: + usb_phy: usbphy { + compatible = "hisilicon,kirin970-usb-phy"; + #phy-cells = <0>; + hisilicon,pericrg-syscon = <&crg_ctrl>; + hisilicon,pctrl-syscon = <&pctrl>; + hisilicon,sctrl-syscon = <&sctrl>; + hisilicon,usb31-misc-syscon = <&usb31_misc>; + eye-diagram-param = <0xFDFEE4>; + usb3-phy-tx-vboost-lvl = <0x5>; + };
drivers/phy/hisilicon/Kconfig +10 -0
@@ -23,6 +23,16 @@ config PHY_HI3660_USB To compile this driver as a module, choose M here. +config PHY_HI3670_USB + tristate "hi3670 USB PHY support" + depends on (ARCH_HISI && ARM64) || COMPILE_TEST + select GENERIC_PHY + select MFD_SYSCON + help + Enable this to support the HISILICON HI3670 USB PHY. + + To compile this driver as a module, choose M here. + config PHY_HISTB_COMBPHY tristate "HiSilicon STB SoCs COMBPHY support" depends on (ARCH_HISI && ARM64) || COMPILE_TEST
drivers/phy/hisilicon/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_PHY_HI6220_USB) += phy-hi6220-usb.o obj-$(CONFIG_PHY_HI3660_USB) += phy-hi3660-usb3.o +obj-$(CONFIG_PHY_HI3670_USB) += phy-hi3670-usb3.o obj-$(CONFIG_PHY_HISTB_COMBPHY) += phy-histb-combphy.o obj-$(CONFIG_PHY_HISI_INNO_USB2) += phy-hisi-inno-usb2.o obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
drivers/phy/hisilicon/phy-hi3670-usb3.c new file +682 -0
682 lines not on this page · raw message
Signature · 1 line
2.26.2
RFC 2/10 phy: hisilicon: phy-hi3670-usb3: fix some issues at the init code
In reply to Mauro Carvalho ChehabFrom: Yu Chen <[email protected]>
There are some problems at the initialization part of this phy. Solve them.
--- drivers/phy/hisilicon/phy-hi3670-usb3.c | 70 +++++++++++-------------- 1 file changed, 32 insertions(+), 38 deletions(-)
drivers/phy/hisilicon/phy-hi3670-usb3.c +32 -38
@@ -63,6 +63,7 @@#define TCA_INTR_STS (0x208)#define TCA_GCFG (0x210)#define TCA_TCPC (0x214) +#define TCA_SYSMODE_CFG (0x218)#define TCA_VBUS_CTRL (0x240)#define CTRL0_USB3_VBUSVLD BIT(7)
@@ -109,12 +110,16 @@#define CLK_RST_SUSPEND_CLK_EN BIT(0)#define GCFG_ROLE_HSTDEV BIT(4) +#define GCFG_OP_MODE (3 << 0) +#define GCFG_OP_MODE_CTRL_SYNC_MODE BIT(0)#define TCPC_VALID BIT(4)#define TCPC_LOW_POWER_EN BIT(3)#define TCPC_MUX_CONTROL_MASK (3 << 0)#define TCPC_MUX_CONTROL_USB31 (1 << 0) +#define SYSMODE_CFG_TYPEC_DISABLE BIT(3) +#define VBUS_CTRL_POWERPRESENT_OVERRD (3 << 2)#define VBUS_CTRL_VBUSVALID_OVERRD (3 << 0)
@@ -363,6 +368,11 @@ static int kirin970_config_phy_clock(struct kirin970_priv *priv)if (ret) goto out; +/* enable usb_tcxo_en */ + ret =regmap_write (priv->pctrl,PCTRL_PERI_CTRL3 , +USB_TCXO_EN | + (USB_TCXO_EN <<PCTRL_PERI_CTRL3_MSK_START )); +/* select usbphy clk from abb */ mask =SC_CLK_USB3PHY_3MUX1_SEL ; ret = regmap_update_bits(priv->pctrl,
@@ -437,7 +447,13 @@ static int kirin970_config_tca(struct kirin970_priv *priv) goto out; ret =regmap_update_bits (priv->usb31misc,TCA_GCFG , -GCFG_ROLE_HSTDEV ,GCFG_ROLE_HSTDEV ); +GCFG_ROLE_HSTDEV |GCFG_OP_MODE , +GCFG_ROLE_HSTDEV |GCFG_OP_MODE_CTRL_SYNC_MODE ); +if (ret) + goto out; + + ret =regmap_update_bits (priv->usb31misc,TCA_SYSMODE_CFG , +SYSMODE_CFG_TYPEC_DISABLE ,0 );if (ret) goto out;
@@ -461,18 +477,15 @@ static int kirin970_config_tca(struct kirin970_priv *priv)return ret; } -static int kirin970_phy_exit (struct phy *phy); -static int kirin970_phy_init (struct phy *phy) {struct kirin970_priv *priv =phy_get_drvdata (phy);u32 val;int ret; -kirin970_phy_exit (phy); -dev_info (priv->dev,"%s in\n" , __func__);/* assert controller */ - val =CFGA0_VAUX_RESET |CFGA0_USB31C_RESET ; + val =CFGA0_VAUX_RESET |CFGA0_USB31C_RESET | +CFGA0_USB3PHY_RESET |CFGA0_USB2PHY_POR ; ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , val,0 );if (ret) goto out;
@@ -493,6 +506,14 @@ static int kirin970_phy_init(struct phy *phy)if (ret) goto out; +/* Deassert phy */ + val =CFGA0_USB3PHY_RESET |CFGA0_USB2PHY_POR ; + ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , val, val); +if (ret) + goto out; + +udelay (100 ); +/* Tell the PHY power is stable */ val =CFG54_USB3_PHY0_ANA_PWR_EN |CFG54_PHY0_PCS_PWR_STABLE |CFG54_PHY0_PMA_PWR_STABLE ;
@@ -512,14 +533,6 @@ static int kirin970_phy_init(struct phy *phy)if (ret) goto out; -/* Deassert phy */ - val =CFGA0_USB3PHY_RESET |CFGA0_USB2PHY_POR ; - ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , val, val); -if (ret) - goto out; - -udelay (100 ); -/* Deassert controller */ val =CFGA0_VAUX_RESET |CFGA0_USB31C_RESET ; ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , val, val);
@@ -545,29 +558,6 @@ static int kirin970_phy_init(struct phy *phy)if (ret) goto out; - { - ret =regmap_read (priv->peri_crg,0x4c , - &val); -if (!ret) -dev_info (priv->dev,"peri_crg 0x4c %x\n" , val); - ret =regmap_read (priv->peri_crg,0x404 , - &val); -if (!ret) -dev_info (priv->dev,"peri_crg 0x404 %x\n" , val); - ret =regmap_read (priv->peri_crg,0xc , - &val); -if (!ret) -dev_info (priv->dev,"peri_crg 0xc %x\n" , val); - ret =regmap_read (priv->peri_crg,0xac , - &val); -if (!ret) -dev_info (priv->dev,"peri_crg 0xac %x\n" , val); - ret =regmap_read (priv->pctrl,0x10 , - &val); -if (!ret) -dev_info (priv->dev,"pctrl 0x10 %x\n" , val); - } -return 0 ; out:dev_err (priv->dev,"failed to init phy ret: %d\n" , ret);
@@ -586,7 +576,11 @@ static int kirin970_phy_exit(struct phy *phy)if (ret) goto out; -if (!kirin970_is_abbclk_seleted (priv)) { +if (kirin970_is_abbclk_seleted (priv)) { +/* disable usb_tcxo_en */ + ret =regmap_write (priv->pctrl,PCTRL_PERI_CTRL3 , +USB_TCXO_EN <<PCTRL_PERI_CTRL3_MSK_START ); + }else { ret =regmap_write (priv->peri_crg,PERI_CRG_PERDIS6 ,GT_CLK_USB2PHY_REF );if (ret)
Signature · 1 line
2.26.2
RFC 3/10 phy: hisilicon: phy-hi3670-usb3: use a consistent namespace
In reply to Mauro Carvalho ChehabRename hikey970 to hi3670, in order to use a namespace similar to hi3660 driver.
--- .../bindings/phy/phy-hi3670-usb3.txt | 4 +- drivers/phy/hisilicon/phy-hi3670-usb3.c | 98 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-)
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +2 -2
@@ -2,7 +2,7 @@ Hisilicon Kirin970 usb PHY ----------------------- Required properties: -- compatible: should be "hisilicon,kirin970-usb-phy" +- compatible: should be "hisilicon,hi3670-usb-phy" - #phy-cells: must be 0 - hisilicon,pericrg-syscon: phandle of syscon used to control phy. - hisilicon,pctrl-syscon: phandle of syscon used to control phy.
@@ -14,7 +14,7 @@ Refer to phy/phy-bindings.txt for the generic PHY binding properties Example: usb_phy: usbphy { - compatible = "hisilicon,kirin970-usb-phy"; + compatible = "hisilicon,hi3670-usb-phy"; #phy-cells = <0>; hisilicon,pericrg-syscon = <&crg_ctrl>; hisilicon,pctrl-syscon = <&pctrl>;
drivers/phy/hisilicon/phy-hi3670-usb3.c +49 -49
304 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [RFC 03/10] phy: hisilicon: phy-hi3670-usb3: use a consistent namespace
Quoted 7 lines · Mauro Carvalho Chehab
Rename hikey970 to hi3670, in order to use a namespace similar to hi3660 driver.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- .../bindings/phy/phy-hi3670-usb3.txt | 4 +-
Bindings should be a separate patch.
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt Hisilicon Kirin970 usb PHY · line 5
Quoted 13 lines
drivers/phy/hisilicon/phy-hi3670-usb3.c | 98 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-)Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +1
-1@@ -2,7 +2,7 @@ Hisilicon Kirin970 usb PHY ----------------------- Required properties: -- compatible: should be "hisilicon,kirin970-usb-phy" +- compatible: should be "hisilicon,hi3670-usb-phy"
Unless this is unused, we can't just change it. It's an ABI.
Quoted 12 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +1
-1- #phy-cells: must be 0 - hisilicon,pericrg-syscon: phandle of syscon used to control phy. - hisilicon,pctrl-syscon: phandle of syscon used to control phy.@@ -14,7 +14,7 @@ Refer to phy/phy-bindings.txt for the generic PHY binding properties Example: usb_phy: usbphy { - compatible = "hisilicon,kirin970-usb-phy"; + compatible = "hisilicon,hi3670-usb-phy"; #phy-cells = <0>; hisilicon,pericrg-syscon = <&crg_ctrl>; hisilicon,pctrl-syscon = <&pctrl>;
Re: [RFC 03/10] phy: hisilicon: phy-hi3670-usb3: use a consistent namespace
Em Wed, 9 Sep 2020 14:15:59 -0600
Rob Herring <[email protected]> escreveu:
Quoted 11 lines
Quoted 7 lines · Mauro Carvalho Chehab
Rename hikey970 to hi3670, in order to use a namespace similar to hi3660 driver.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- .../bindings/phy/phy-hi3670-usb3.txt | 4 +-Bindings should be a separate patch.
Ok. I'll split it.
Quoted 11 lines
Quoted 11 lines
drivers/phy/hisilicon/phy-hi3670-usb3.c | 98 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-)Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +0
-0@@ -2,7 +2,7 @@ Hisilicon Kirin970 usb PHY -----------------------
Quoted 5 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt Hisilicon Kirin970 usb PHY · line 5
Quoted 3 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +1
-1Required properties: -- compatible: should be "hisilicon,kirin970-usb-phy" +- compatible: should be "hisilicon,hi3670-usb-phy"Unless this is unused, we can't just change it. It's an ABI.
From upstream PoV, this binding is for a new driver that will be added via this patchset.
Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +0
-0- #phy-cells: must be 0 - hisilicon,pericrg-syscon: phandle of syscon used to control phy. - hisilicon,pctrl-syscon: phandle of syscon used to control phy.@@ -14,7 +14,7 @@ Refer to phy/phy-bindings.txt for the generic PHY binding properties
Quoted 7 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt Refer to phy/phy-bindings.txt for the generic PHY binding properties · line 20
Quoted 7 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +1
-1Example: usb_phy: usbphy { - compatible = "hisilicon,kirin970-usb-phy"; + compatible = "hisilicon,hi3670-usb-phy"; #phy-cells = <0>; hisilicon,pericrg-syscon = <&crg_ctrl>; hisilicon,pctrl-syscon = <&pctrl>;
Thanks,
Mauro
Re: [RFC 03/10] phy: hisilicon: phy-hi3670-usb3: use a consistent namespace
Quoted 29 lines · Mauro Carvalho Chehab
Em Wed, 9 Sep 2020 14:15:59 -0600
Rob Herring <[email protected]> escreveu:Quoted 11 lines
Quoted 7 lines · Mauro Carvalho Chehab
Rename hikey970 to hi3670, in order to use a namespace similar to hi3660 driver.
Signed-off-by Mauro Carvalho Chehab <[email protected]>--- .../bindings/phy/phy-hi3670-usb3.txt | 4 +-Bindings should be a separate patch.
Ok. I'll split it.
Quoted 11 lines
Quoted 11 lines
drivers/phy/hisilicon/phy-hi3670-usb3.c | 98 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-)Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +0
-0@@ -2,7 +2,7 @@ Hisilicon Kirin970 usb PHY -----------------------
Quoted 8 lines
Quoted 5 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt Hisilicon Kirin970 usb PHY · line 5
Quoted 3 lines
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt +1
-1Required properties: -- compatible: should be "hisilicon,kirin970-usb-phy" +- compatible: should be "hisilicon,hi3670-usb-phy"Unless this is unused, we can't just change it. It's an ABI.
From upstream PoV, this binding is for a new driver that will be added via this patchset.
Please squash this change then.
Rob
RFC 4/10 phy: hisilicon: phy-hi3670-usb3: fix coding style
In reply to Mauro Carvalho ChehabAddress the issues reported by checkpatch --strict, and add a SPDX tag.
--- drivers/phy/hisilicon/phy-hi3670-usb3.c | 157 ++++++++++++------------ 1 file changed, 76 insertions(+), 81 deletions(-)
drivers/phy/hisilicon/phy-hi3670-usb3.c +76 -81
@@ -1,28 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Phy provider for USB 3.1 controller on HiSilicon Kirin970 platform * -* Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd. +* Copyright (C) 2017-2020 Hilisicon Electronics Co., Ltd. * http://www.huawei.com * * Authors: Yu Chen <[email protected]> -* -* 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/kernel.h> #include <linux/mfd/syscon.h> #include <linux/module.h> -#include <linux/platform_device.h> #include <linux/phy/phy.h> +#include <linux/platform_device.h> #include <linux/regmap.h> -#include <linux/clk.h> #define SCTRL_SCDEEPSLEEPED (0x0)#define USB_CLK_SELECTED BIT(20)
@@ -116,7 +108,7 @@#define TCPC_VALID BIT(4)#define TCPC_LOW_POWER_EN BIT(3)#define TCPC_MUX_CONTROL_MASK (3 << 0) -#define TCPC_MUX_CONTROL_USB31 (1 << 0) +#define TCPC_MUX_CONTROL_USB31 BIT(0)#define SYSMODE_CFG_TYPEC_DISABLE BIT(3)
@@ -151,13 +143,13 @@ static int hi3670_phy_cr_clk(struct regmap *usb31misc)/* Clock up */ ret =regmap_update_bits (usb31misc,USB_MISC_CFG54 , -CFG54_USB31PHY_CR_CLK ,CFG54_USB31PHY_CR_CLK ); +CFG54_USB31PHY_CR_CLK ,CFG54_USB31PHY_CR_CLK );if (ret)return ret;/* Clock down */ ret =regmap_update_bits (usb31misc,USB_MISC_CFG54 , -CFG54_USB31PHY_CR_CLK ,0 ); +CFG54_USB31PHY_CR_CLK ,0 );return ret; }
@@ -165,7 +157,7 @@ static int hi3670_phy_cr_clk(struct regmap *usb31misc)static int hi3670_phy_cr_set_sel (struct regmap *usb31misc) {return regmap_update_bits (usb31misc,USB_MISC_CFG54 , -CFG54_USB31PHY_CR_SEL ,CFG54_USB31PHY_CR_SEL ); +CFG54_USB31PHY_CR_SEL ,CFG54_USB31PHY_CR_SEL ); }static int hi3670_phy_cr_start (struct regmap *usb31misc,int direction)
@@ -174,10 +166,12 @@ static int hi3670_phy_cr_start(struct regmap *usb31misc, int direction)if (direction) ret =regmap_update_bits (usb31misc,USB_MISC_CFG54 , -CFG54_USB31PHY_CR_WR_EN ,CFG54_USB31PHY_CR_WR_EN ); +CFG54_USB31PHY_CR_WR_EN , +CFG54_USB31PHY_CR_WR_EN );else ret =regmap_update_bits (usb31misc,USB_MISC_CFG54 , -CFG54_USB31PHY_CR_RD_EN ,CFG54_USB31PHY_CR_RD_EN ); +CFG54_USB31PHY_CR_RD_EN , +CFG54_USB31PHY_CR_RD_EN );if (ret)return ret;
@@ -187,7 +181,7 @@ static int hi3670_phy_cr_start(struct regmap *usb31misc, int direction)return ret; ret =regmap_update_bits (usb31misc,USB_MISC_CFG54 , -CFG54_USB31PHY_CR_RD_EN |CFG54_USB31PHY_CR_WR_EN ,0 ); +CFG54_USB31PHY_CR_RD_EN |CFG54_USB31PHY_CR_WR_EN ,0 );return ret; }
@@ -223,8 +217,7 @@ static int hi3670_phy_cr_set_addr(struct regmap *usb31misc, u32 addr)return ret; reg &= ~(CFG54_USB31PHY_CR_ADDR_MASK <<CFG54_USB31PHY_CR_ADDR_SHIFT ); - reg |= ((addr &CFG54_USB31PHY_CR_ADDR_MASK ) << -CFG54_USB31PHY_CR_ADDR_SHIFT ); + reg |= ((addr &CFG54_USB31PHY_CR_ADDR_MASK ) <<CFG54_USB31PHY_CR_ADDR_SHIFT ); ret =regmap_write (usb31misc,USB_MISC_CFG54 , reg);return ret;
@@ -288,7 +281,7 @@ static int hi3670_phy_cr_write(struct regmap *usb31misc, u32 addr, u32 val)return ret; ret =regmap_write (usb31misc,USB_MISC_CFG58 , - val &CFG58_USB31PHY_CR_DATA_MASK ); + val &CFG58_USB31PHY_CR_DATA_MASK );if (ret)return ret;
@@ -308,7 +301,7 @@ static int hi3670_phy_set_params(struct hi3670_priv *priv)int retry =3 ; ret =regmap_write (priv->usb31misc,USB3OTG_CTRL4 , - priv->eye_diagram_param); + priv->eye_diagram_param);if (ret) {dev_err (priv->dev,"set USB3OTG_CTRL4 failed\n" );return ret;
@@ -316,10 +309,11 @@ static int hi3670_phy_set_params(struct hi3670_priv *priv)while (retry-- >0 ) { ret =hi3670_phy_cr_read (priv->usb31misc, -TX_VBOOST_LVL_REG , ®); +TX_VBOOST_LVL_REG , ®);if (!ret)break ; -else if (ret != -ETIMEDOUT ) { + +if (ret != -ETIMEDOUT ) {dev_err (priv->dev,"read TX_VBOOST_LVL_REG failed\n" );return ret; }
@@ -327,8 +321,7 @@ static int hi3670_phy_set_params(struct hi3670_priv *priv)if (ret)return ret; - reg |= (TX_VBOOST_LVL_ENABLE | - (priv->tx_vboost_lvl <<TX_VBOOST_LVL_START )); + reg |= (TX_VBOOST_LVL_ENABLE | (priv->tx_vboost_lvl <<TX_VBOOST_LVL_START )); ret =hi3670_phy_cr_write (priv->usb31misc,TX_VBOOST_LVL_REG , reg);if (ret)dev_err (priv->dev,"write TX_VBOOST_LVL_REG failed\n" );
@@ -364,24 +357,24 @@ static int hi3670_config_phy_clock(struct hi3670_priv *priv)if (hi3670_is_abbclk_seleted (priv)) {/* usb refclk iso disable */ ret =regmap_write (priv->peri_crg,PERI_CRG_ISODIS , -USB_REFCLK_ISO_EN ); +USB_REFCLK_ISO_EN );if (ret) goto out;/* enable usb_tcxo_en */ ret =regmap_write (priv->pctrl,PCTRL_PERI_CTRL3 , -USB_TCXO_EN | - (USB_TCXO_EN <<PCTRL_PERI_CTRL3_MSK_START )); +USB_TCXO_EN | + (USB_TCXO_EN <<PCTRL_PERI_CTRL3_MSK_START ));/* select usbphy clk from abb */ mask =SC_CLK_USB3PHY_3MUX1_SEL ; ret =regmap_update_bits (priv->pctrl, -PCTRL_PERI_CTRL24 , mask,0 ); +PCTRL_PERI_CTRL24 , mask,0 );if (ret) goto out; ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , -CFGA0_USB2PHY_REFCLK_SELECT ,0 ); +CFGA0_USB2PHY_REFCLK_SELECT ,0 );if (ret) goto out;
@@ -393,34 +386,36 @@ static int hi3670_config_phy_clock(struct hi3670_priv *priv) ret =regmap_write (priv->usb31misc,USB3OTG_CTRL7 , val);if (ret) goto out; - }else { - ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFG54 , -CFG54_USB3PHY_REF_USE_PAD , -CFG54_USB3PHY_REF_USE_PAD ); -if (ret) - goto out; - ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , -CFGA0_USB2PHY_REFCLK_SELECT , -CFGA0_USB2PHY_REFCLK_SELECT ); -if (ret) - goto out; - - ret =regmap_read (priv->usb31misc,USB3OTG_CTRL7 , &val); -if (ret) - goto out; - val &= ~CTRL7_USB2_REFCLKSEL_MASK ; - val |=CTRL7_USB2_REFCLKSEL_PAD ; - ret =regmap_write (priv->usb31misc,USB3OTG_CTRL7 , val); -if (ret) - goto out; - - ret =regmap_write (priv->peri_crg, -PERI_CRG_PEREN6 ,GT_CLK_USB2PHY_REF ); -if (ret) - goto out; +return 0 ; } + ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFG54 , +CFG54_USB3PHY_REF_USE_PAD , +CFG54_USB3PHY_REF_USE_PAD ); +if (ret) + goto out; + + ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , +CFGA0_USB2PHY_REFCLK_SELECT , +CFGA0_USB2PHY_REFCLK_SELECT ); +if (ret) + goto out; + + ret =regmap_read (priv->usb31misc,USB3OTG_CTRL7 , &val); +if (ret) + goto out; + val &= ~CTRL7_USB2_REFCLKSEL_MASK ; + val |=CTRL7_USB2_REFCLKSEL_PAD ; + ret =regmap_write (priv->usb31misc,USB3OTG_CTRL7 , val); +if (ret) + goto out; + + ret =regmap_write (priv->peri_crg, +PERI_CRG_PEREN6 ,GT_CLK_USB2PHY_REF ); +if (ret) + goto out; +return 0 ; out:dev_err (priv->dev,"failed to config phy clock ret: %d\n" , ret);
@@ -437,7 +432,7 @@ static int hi3670_config_tca(struct hi3670_priv *priv) goto out; ret =regmap_write (priv->usb31misc,TCA_INTR_EN , -INTR_EN_XA_TIMEOUT_EVT_EN |INTR_EN_XA_ACK_EVT_EN ); +INTR_EN_XA_TIMEOUT_EVT_EN |INTR_EN_XA_ACK_EVT_EN );if (ret) goto out;
@@ -447,13 +442,13 @@ static int hi3670_config_tca(struct hi3670_priv *priv) goto out; ret =regmap_update_bits (priv->usb31misc,TCA_GCFG , -GCFG_ROLE_HSTDEV |GCFG_OP_MODE , -GCFG_ROLE_HSTDEV |GCFG_OP_MODE_CTRL_SYNC_MODE ); +GCFG_ROLE_HSTDEV |GCFG_OP_MODE , +GCFG_ROLE_HSTDEV |GCFG_OP_MODE_CTRL_SYNC_MODE );if (ret) goto out; ret =regmap_update_bits (priv->usb31misc,TCA_SYSMODE_CFG , -SYSMODE_CFG_TYPEC_DISABLE ,0 ); +SYSMODE_CFG_TYPEC_DISABLE ,0 );if (ret) goto out;
@@ -467,7 +462,7 @@ static int hi3670_config_tca(struct hi3670_priv *priv) goto out; ret =regmap_write (priv->usb31misc,TCA_VBUS_CTRL , -VBUS_CTRL_POWERPRESENT_OVERRD |VBUS_CTRL_VBUSVALID_OVERRD ); +VBUS_CTRL_POWERPRESENT_OVERRD |VBUS_CTRL_VBUSVALID_OVERRD );if (ret) goto out;
@@ -485,7 +480,7 @@ static int hi3670_phy_init(struct phy *phy)/* assert controller */ val =CFGA0_VAUX_RESET |CFGA0_USB31C_RESET | -CFGA0_USB3PHY_RESET |CFGA0_USB2PHY_POR ; +CFGA0_USB3PHY_RESET |CFGA0_USB2PHY_POR ; ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFGA0 , val,0 );if (ret) goto out;
@@ -496,13 +491,13 @@ static int hi3670_phy_init(struct phy *phy)/* Exit from IDDQ mode */ ret =regmap_update_bits (priv->usb31misc,USB3OTG_CTRL5 , -CTRL5_USB2_SIDDQ ,0 ); +CTRL5_USB2_SIDDQ ,0 );if (ret) goto out;/* Release USB31 PHY out of TestPowerDown mode */ ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFG50 , -CFG50_USB3_PHY_TEST_POWERDOWN ,0 ); +CFG50_USB3_PHY_TEST_POWERDOWN ,0 );if (ret) goto out;
@@ -512,13 +507,13 @@ static int hi3670_phy_init(struct phy *phy)if (ret) goto out; -udelay (100 ); +usleep_range (100 ,120 );/* Tell the PHY power is stable */ val =CFG54_USB3_PHY0_ANA_PWR_EN |CFG54_PHY0_PCS_PWR_STABLE | -CFG54_PHY0_PMA_PWR_STABLE ; +CFG54_PHY0_PMA_PWR_STABLE ; ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFG54 , - val, val); + val, val);if (ret) goto out;
@@ -528,8 +523,8 @@ static int hi3670_phy_init(struct phy *phy)/* Enable SSC */ ret =regmap_update_bits (priv->usb31misc,USB_MISC_CFG5C , -CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN , -CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN ); +CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN , +CFG5C_USB3_PHY0_SS_MPLLA_SSC_EN );if (ret) goto out;
@@ -539,7 +534,7 @@ static int hi3670_phy_init(struct phy *phy)if (ret) goto out; -udelay (100 ); +usleep_range (100 ,120 );/* Set fake vbus valid signal */ val =CTRL0_USB3_VBUSVLD |CTRL0_USB3_VBUSVLD_SEL ;
@@ -552,7 +547,7 @@ static int hi3670_phy_init(struct phy *phy)if (ret) goto out; -udelay (100 ); +usleep_range (100 ,120 ); ret =hi3670_phy_set_params (priv);if (ret)
@@ -579,10 +574,10 @@ static int hi3670_phy_exit(struct phy *phy)if (hi3670_is_abbclk_seleted (priv)) {/* disable usb_tcxo_en */ ret =regmap_write (priv->pctrl,PCTRL_PERI_CTRL3 , -USB_TCXO_EN <<PCTRL_PERI_CTRL3_MSK_START ); +USB_TCXO_EN <<PCTRL_PERI_CTRL3_MSK_START ); }else { ret =regmap_write (priv->peri_crg,PERI_CRG_PERDIS6 , -GT_CLK_USB2PHY_REF ); +GT_CLK_USB2PHY_REF );if (ret) goto out; }
@@ -612,39 +607,39 @@ static int hi3670_phy_probe(struct platform_device *pdev) priv->dev = dev; priv->peri_crg =syscon_regmap_lookup_by_phandle (dev->of_node, -"hisilicon,pericrg-syscon" ); +"hisilicon,pericrg-syscon" );if (IS_ERR (priv->peri_crg)) {dev_err (dev,"no hisilicon,pericrg-syscon\n" );return PTR_ERR (priv->peri_crg); } priv->pctrl =syscon_regmap_lookup_by_phandle (dev->of_node, -"hisilicon,pctrl-syscon" ); +"hisilicon,pctrl-syscon" );if (IS_ERR (priv->pctrl)) {dev_err (dev,"no hisilicon,pctrl-syscon\n" );return PTR_ERR (priv->pctrl); } priv->sctrl =syscon_regmap_lookup_by_phandle (dev->of_node, -"hisilicon,sctrl-syscon" ); +"hisilicon,sctrl-syscon" );if (IS_ERR (priv->sctrl)) {dev_err (dev,"no hisilicon,sctrl-syscon\n" );return PTR_ERR (priv->sctrl); } priv->usb31misc =syscon_regmap_lookup_by_phandle (dev->of_node, -"hisilicon,usb31-misc-syscon" ); +"hisilicon,usb31-misc-syscon" );if (IS_ERR (priv->usb31misc)) {dev_err (dev,"no hisilicon,usb31-misc-syscon\n" );return PTR_ERR (priv->usb31misc); }if (of_property_read_u32 (dev->of_node,"eye-diagram-param" , - &(priv->eye_diagram_param))) + &priv->eye_diagram_param)) priv->eye_diagram_param =KIRIN970_USB_DEFAULT_PHY_PARAM ;if (of_property_read_u32 (dev->of_node,"usb3-phy-tx-vboost-lvl" , - &(priv->tx_vboost_lvl))) + &priv->tx_vboost_lvl)) priv->eye_diagram_param =KIRIN970_USB_DEFAULT_PHY_VBOOST ; phy =devm_phy_create (dev,NULL , &hi3670_phy_ops);
@@ -657,7 +652,7 @@ static int hi3670_phy_probe(struct platform_device *pdev) }static const struct of_device_id hi3670_phy_of_match[] = { - {.compatible ="hisilicon,hi3670-usb-phy" ,}, + { .compatible ="hisilicon,hi3670-usb-phy" }, { }, };MODULE_DEVICE_TABLE (of, hi3670_phy_of_match);
Signature · 1 line
2.26.2
RFC 5/10 phy: hisilicon: phy-hi3670-usb3: change some DT properties
In reply to Mauro Carvalho ChehabDo some changes at the DT properties in order to make it follow the phy-hi3660-usb3 example and to simplify usb3-phy-tx-vboost-lvl name.
--- drivers/phy/hisilicon/phy-hi3670-usb3.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/phy/hisilicon/phy-hi3670-usb3.c +5 -5
@@ -627,18 +627,18 @@ static int hi3670_phy_probe(struct platform_device *pdev)return PTR_ERR (priv->sctrl); } - priv->usb31misc =syscon_regmap_lookup_by_phandle (dev->of_node, -"hisilicon,usb31-misc-syscon" ); +/* node of hi3670 phy is a sub-node of usb3_otg_bc */ + priv->usb31misc =syscon_node_to_regmap (dev->parent->of_node);if (IS_ERR (priv->usb31misc)) { -dev_err (dev,"no hisilicon,usb31-misc-syscon\n" ); +dev_err (dev,"no hisilicon,usb3-otg-bc-syscon\n" );return PTR_ERR (priv->usb31misc); } -if (of_property_read_u32 (dev->of_node,"eye-diagram-param" , +if (of_property_read_u32 (dev->of_node,"hisilicon,eye-diagram-param" , &priv->eye_diagram_param)) priv->eye_diagram_param =KIRIN970_USB_DEFAULT_PHY_PARAM ; -if (of_property_read_u32 (dev->of_node,"usb3-phy-tx-vboost-lvl" , +if (of_property_read_u32 (dev->of_node,"hisilicon,tx-vboost-lvl" , &priv->tx_vboost_lvl)) priv->eye_diagram_param =KIRIN970_USB_DEFAULT_PHY_VBOOST ;
Signature · 1 line
2.26.2
RFC 6/10 dt-bindings: phy: convert phy-kirin970-usb3.txt to yaml
In reply to Mauro Carvalho ChehabUse the new YAML for this physical layer.
--- .../bindings/phy/hisilicon,hi3670-usb3.yaml | 72 +++++++++++++++++++ .../bindings/phy/phy-hi3670-usb3.txt | 25 ------- 2 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 Documentation/devicetree/bindings/phy/hisilicon,hi3670-usb3.yaml delete mode 100644 Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt
Documentation/devicetree/bindings/phy/hisilicon,hi3670-usb3.yaml new file +72 -0
@@ -0,0 +1,72 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/hisilicon,hi3670-usb3.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hisilicon Kirin970 USB PHY + +maintainers: + - Mauro Carvalho Chehab <[email protected]> +description: |+ + Bindings for USB3 PHY on HiSilicon Kirin 970. + +properties: + compatible: + const: hisilicon,hi3670-usb-phy + + "#phy-cells": + const: 0 + + hisilicon,pericrg-syscon: + $ref: '/schemas/types.yaml#/definitions/phandle' + description: phandle of syscon used to control iso refclk. + + hisilicon,pctrl-syscon: + $ref: '/schemas/types.yaml#/definitions/phandle' + description: phandle of syscon used to control usb tcxo. + + hisilicon,sctrl-syscon: + $ref: '/schemas/types.yaml#/definitions/phandle' + description: phandle of syscon used to control phy deep sleep. + + hisilicon,eye-diagram-param: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Eye diagram for phy. + + hisilicon,tx-vboost-lvl: + $ref: /schemas/types.yaml#/definitions/uint32 + description: TX level vboost for phy. + +required: + - compatible + - hisilicon,pericrg-syscon + - hisilicon,pctrl-syscon + - hisilicon,sctrl-syscon + - hisilicon,eye-diagram-param + - hisilicon,tx-vboost-lvl + - "#phy-cells" + +additionalProperties: false + +examples: + - | + bus { + #address-cells = <2>; + #size-cells = <2>; + + usb3_otg_bc: usb3_otg_bc@ff200000 { + compatible = "syscon", "simple-mfd"; + reg = <0x0 0xff200000 0x0 0x1000>; + + usb_phy { + compatible = "hisilicon,hi3670-usb-phy"; + #phy-cells = <0>; + hisilicon,pericrg-syscon = <&crg_ctrl>; + hisilicon,pctrl-syscon = <&pctrl>; + hisilicon,sctrl-syscon = <&sctrl>; + hisilicon,eye-diagram-param = <0xfdfee4>; + hisilicon,tx-vboost-lvl = <0x5>; + }; + }; + };
Documentation/devicetree/bindings/phy/phy-hi3670-usb3.txt deleted +0 -25
@@ -1,25 +0,0 @@ -Hisilicon Kirin970 usb PHY ------------------------ - -Required properties: -- compatible: should be "hisilicon,hi3670-usb-phy" -- #phy-cells: must be 0 -- hisilicon,pericrg-syscon: phandle of syscon used to control phy. -- hisilicon,pctrl-syscon: phandle of syscon used to control phy. -- hisilicon,sctrl-syscon: phandle of syscon used to control phy. -- hisilicon,usb31-misc-syscon: phandle of syscon used to control phy. -- eye-diagram-param: parameter set for phy -- usb3-phy-tx-vboost-lvl: parameter set for phy -Refer to phy/phy-bindings.txt for the generic PHY binding properties - -Example: - usb_phy: usbphy { - compatible = "hisilicon,hi3670-usb-phy"; - #phy-cells = <0>; - hisilicon,pericrg-syscon = <&crg_ctrl>; - hisilicon,pctrl-syscon = <&pctrl>; - hisilicon,sctrl-syscon = <&sctrl>; - hisilicon,usb31-misc-syscon = <&usb31_misc>; - eye-diagram-param = <0xFDFEE4>; - usb3-phy-tx-vboost-lvl = <0x5>; - };
Signature · 1 line
2.26.2
RFC 7/10 MAINTAINERS: add myself as maintainer for Kirin 970 USB PHY
In reply to Mauro Carvalho ChehabNow that this driver was added upsream, it needs a maintainer.
--- MAINTAINERS | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
MAINTAINERS +8 -1
@@ -17711,7 +17711,7 @@ L: [email protected] S: Maintained F: drivers/usb/roles/intel-xhci-usb-role-switch.c -USB IP DRIVER FOR HISILICON KIRIN +USB IP DRIVER FOR HISILICON KIRIN 960 M: Yu Chen <[email protected]> M: Binghui Wang <[email protected]> L: [email protected]
@@ -17719,6 +17719,13 @@ S: Maintained F: Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt F: drivers/phy/hisilicon/phy-hi3660-usb3.c +USB IP DRIVER FOR HISILICON KIRIN 970 +M: Mauro Carvalho Chehab <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/phy/hisilicon,kirin970-usb3.yaml +F: drivers/phy/hisilicon/phy-kirin970-usb3.c + USB ISP116X DRIVER M: Olav Kongas <[email protected]> L: [email protected]
Signature · 1 line
2.26.2
RFC 8/10 misc: hisi_hikey_usb: Driver to support onboard USB gpio hub on Hikey960
In reply to Mauro Carvalho ChehabFrom: Yu Chen <[email protected]>
The HiKey960 has a fairly complex USB configuration due to it needing to support a USB-C port for host/device mode and multiple USB-A ports in host mode, all using a single USB controller.
See schematics here:
https://github.com/96boards/documentation/raw/master/consumer/hikey/hikey960/hardware-docs/HiKey960_Schematics.pdf
This driver acts as a usb-role-switch intermediary, intercepting the role switch notifications from the tcpm code, and passing them on to the dwc3 core.
In doing so, it also controls the onboard hub and power gpios in order to properly route the data lines between the USB-C port and the onboard hub to the USB-A ports.
[jstultz: Major rework to make the driver a usb-role-switch
intermediary]
--- MAINTAINERS | 7 ++ drivers/misc/Kconfig | 9 ++ drivers/misc/Makefile | 1 + drivers/misc/hisi_hikey_usb.c | 205 ++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+) create mode 100644 drivers/misc/hisi_hikey_usb.c
MAINTAINERS +7 -0
@@ -7781,6 +7781,13 @@ W: http://www.hisilicon.com F: Documentation/devicetree/bindings/net/hisilicon*.txt F: drivers/net/ethernet/hisilicon/ +HIKEY960 ONBOARD USB GPIO HUB DRIVER +M: John Stultz <[email protected]> +L: [email protected] +S: Maintained +F: drivers/misc/hisi_hikey_usb.c +F: Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml + HISILICON PMU DRIVER M: Shaokun Zhang <[email protected]> S: Supported
drivers/misc/Kconfig +9 -0
@@ -456,6 +456,15 @@ config PVPANIC a paravirtualized device provided by QEMU; it lets a virtual machine (guest) communicate panic events to the host. +config HISI_HIKEY_USB + tristate "USB GPIO Hub on HiSilicon Hikey960 Platform" + depends on OF && GPIOLIB + help + If you say yes here this adds support for the on-board USB gpio hub + found on the HiKey960, which is necssary to support switching between + the dual-role USB-C port and the USB-A host ports using only one USB + controller. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -57,3 +57,4 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HABANA_AI) += habanalabs/ obj-$(CONFIG_UACCE) += uacce/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o +obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o
drivers/misc/hisi_hikey_usb.c new file +205 -0
205 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [RFC 08/10] misc: hisi_hikey_usb: Driver to support onboard USB gpio hub on Hikey960
drivers/misc/Kconfig config PVPANIC · line 461
Quoted 11 lines · Mauro Carvalho Chehab
drivers/misc/Kconfig +3
-0@@ -456,6 +456,15 @@ config PVPANIC a paravirtualized device provided by QEMU; it lets a virtual machine (guest) communicate panic events to the host. +config HISI_HIKEY_USB + tristate "USB GPIO Hub on HiSilicon Hikey960 Platform" + depends on OF && GPIOLIB
depends on (OF && GPIOLIB) || COMPILE_TEST
?
Both of those have stubs if they are not enabled IIRC.
drivers/misc/Kconfig config PVPANIC · line 463
Quoted 2 lines
drivers/misc/Kconfig +2
-0+ help + If you say yes here this adds support for the on-board USB gpio hub
GPIO
drivers/misc/Kconfig config PVPANIC · line 464
Quoted 1 line
drivers/misc/Kconfig +1
-0+ found on the HiKey960, which is necssary to support switching between
necessary
drivers/misc/Kconfig config PVPANIC · line 470
Quoted 6 lines
drivers/misc/Kconfig +3
-0+ the dual-role USB-C port and the USB-A host ports using only one USB + controller. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
thanks.
Signature · 1 line
~Randy
RFC 9/10 misc: hisi_hikey_usb: add support for Hikey 970
In reply to Mauro Carvalho ChehabThe HiKey 970 board uses a voltage regulator and GPIO reset pin.
Add support for them.
--- drivers/misc/hisi_hikey_usb.c | 97 +++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 15 deletions(-)
drivers/misc/hisi_hikey_usb.c +82 -15
@@ -14,8 +14,10 @@#include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/notifier.h> +#include <linux/of_gpio.h> #include <linux/platform_device.h> #include <linux/property.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/usb/role.h>
@@ -46,23 +48,30 @@ struct hisi_hikey_usb {static void hub_power_ctrl (struct hisi_hikey_usb *hisi_hikey_usb,int value) { +if (!hisi_hikey_usb->hub_vbus) +return ; +gpiod_set_value_cansleep (hisi_hikey_usb->hub_vbus, value); }static void usb_switch_ctrl (struct hisi_hikey_usb *hisi_hikey_usb,int switch_to) { +if (!hisi_hikey_usb->otg_switch) +return ; +gpiod_set_value_cansleep (hisi_hikey_usb->otg_switch, switch_to); }static void usb_typec_power_ctrl (struct hisi_hikey_usb *hisi_hikey_usb,int value) { +if (!hisi_hikey_usb->typec_vbus) +return ; +gpiod_set_value_cansleep (hisi_hikey_usb->typec_vbus, value); } - -static void relay_set_role_switch (struct work_struct *work) { struct hisi_hikey_usb *hisi_hikey_usb = container_of(work,
@@ -117,31 +126,89 @@ static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rolreturn 0 ; } +static int hisi_hikey_usb_parse_kirin970 (struct platform_device *pdev) +{ +struct regulator *regulator; +int hub_reset_en_gpio; +int ret; + + regulator =devm_regulator_get_optional (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { +if (PTR_ERR (regulator) == -EPROBE_DEFER ) { +dev_info (&pdev->dev, +"waiting for hub-vdd-supply to be probed\n" ); +return PTR_ERR (regulator); + } + +/* let it fall back to regulator dummy */ + regulator =devm_regulator_get (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { +dev_err (&pdev->dev, +"get hub-vdd-supply failed with error %ld\n" , +PTR_ERR (regulator)); +return PTR_ERR (regulator); + } + } + + ret =regulator_set_voltage (regulator,3300000 ,3300000 ); +if (ret) +dev_err (&pdev->dev,"set hub-vdd-supply voltage failed\n" ); + + hub_reset_en_gpio =of_get_named_gpio (pdev->dev.of_node, +"hub_reset_en_gpio" ,0 ); +if (!gpio_is_valid (hub_reset_en_gpio)) { +dev_err (&pdev->dev,"Failed to get a valid reset gpio\n" ); +return -ENODEV ; + } + + ret =devm_gpio_request (&pdev->dev, hub_reset_en_gpio, +"hub_reset_en_gpio" ); +if (ret) { +dev_err (&pdev->dev,"Failed to request the reset gpio\n" ); +return ret; + } + ret =gpio_direction_output (hub_reset_en_gpio,1 ); +if (ret) +dev_err (&pdev->dev, +"Failed to set the direction of the reset gpio\n" ); + +return ret; +} +static int hisi_hikey_usb_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;struct hisi_hikey_usb *hisi_hikey_usb;struct usb_role_switch_desc hub_role_switch = {NULL }; +int ret; hisi_hikey_usb =devm_kzalloc (dev,sizeof (*hisi_hikey_usb),GFP_KERNEL );if (!hisi_hikey_usb)return -ENOMEM ; - hisi_hikey_usb->typec_vbus =devm_gpiod_get (dev,"typec-vbus" , -GPIOD_OUT_LOW ); -if (IS_ERR (hisi_hikey_usb->typec_vbus)) -return PTR_ERR (hisi_hikey_usb->typec_vbus); - hisi_hikey_usb->otg_switch =devm_gpiod_get (dev,"otg-switch" ,GPIOD_OUT_HIGH );if (IS_ERR (hisi_hikey_usb->otg_switch))return PTR_ERR (hisi_hikey_usb->otg_switch); -/* hub-vdd33-en is optional */ - hisi_hikey_usb->hub_vbus =devm_gpiod_get_optional (dev,"hub-vdd33-en" , -GPIOD_OUT_HIGH ); -if (IS_ERR (hisi_hikey_usb->hub_vbus)) -return PTR_ERR (hisi_hikey_usb->hub_vbus); + hisi_hikey_usb->typec_vbus =devm_gpiod_get (dev,"typec-vbus" , +GPIOD_OUT_LOW ); +if (IS_ERR (hisi_hikey_usb->typec_vbus)) +return PTR_ERR (hisi_hikey_usb->typec_vbus); + +/* Parse Kirin 970-specific OF data */ +if (of_device_is_compatible (pdev->dev.of_node, +"hisilicon,kirin970_hikey_usbhub" )) { + ret =hisi_hikey_usb_parse_kirin970 (pdev); +if (ret) +return ret; + }else { +/* hub-vdd33-en is optional */ + hisi_hikey_usb->hub_vbus =devm_gpiod_get_optional (dev,"hub-vdd33-en" , +GPIOD_OUT_HIGH ); +if (IS_ERR (hisi_hikey_usb->hub_vbus)) +return PTR_ERR (hisi_hikey_usb->hub_vbus); + } hisi_hikey_usb->dev_role_sw =usb_role_switch_get (dev);if (!hisi_hikey_usb->dev_role_sw)
@@ -149,7 +216,6 @@ static int hisi_hikey_usb_probe(struct platform_device *pdev)if (IS_ERR (hisi_hikey_usb->dev_role_sw))return PTR_ERR (hisi_hikey_usb->dev_role_sw); -INIT_WORK (&hisi_hikey_usb->work, relay_set_role_switch);mutex_init (&hisi_hikey_usb->lock);
@@ -158,7 +224,7 @@ static int hisi_hikey_usb_probe(struct platform_device *pdev) hub_role_switch.driver_data = hisi_hikey_usb; hisi_hikey_usb->hub_role_sw =usb_role_switch_register (dev, - &hub_role_switch); + &hub_role_switch);if (IS_ERR (hisi_hikey_usb->hub_role_sw)) {usb_role_switch_put (hisi_hikey_usb->dev_role_sw);
@@ -184,7 +250,8 @@ static int hisi_hikey_usb_remove(struct platform_device *pdev) }static const struct of_device_id id_table_hisi_hikey_usb[] = { - {.compatible ="hisilicon,gpio_hubv1" }, + { .compatible ="hisilicon,gpio_hubv1" }, + { .compatible ="hisilicon,kirin970_hikey_usbhub" }, {} };MODULE_DEVICE_TABLE (of, id_table_hisi_hikey_usb);
Signature · 1 line
2.26.2
Re: [RFC 09/10] misc: hisi_hikey_usb: add support for Hikey 970
Quoted 7 lines · Mauro Carvalho Chehab
drivers/misc/hisi_hikey_usb.c +7
-0+ regulator =devm_regulator_get_optional (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { +if (PTR_ERR (regulator) == -EPROBE_DEFER ) { +dev_info (&pdev->dev, +"waiting for hub-vdd-supply to be probed\n" ); +return PTR_ERR (regulator); + }
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 151
Quoted 10 lines
drivers/misc/hisi_hikey_usb.c +10
-0+ +/* let it fall back to regulator dummy */ + regulator =devm_regulator_get (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { +dev_err (&pdev->dev, +"get hub-vdd-supply failed with error %ld\n" , +PTR_ERR (regulator)); +return PTR_ERR (regulator); + } + }
This seems weird - if the supply is non-optional why is the code trying with devm_regulator_get_optional()? Just use normal get directly.
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 155
Quoted 3 lines
drivers/misc/hisi_hikey_usb.c +3
-0+ ret =regulator_set_voltage (regulator,3300000 ,3300000 ); +if (ret) +dev_err (&pdev->dev,"set hub-vdd-supply voltage failed\n" );
Unless the device is actively managing the voltage at runtime it should just let the voltage be set by machine constraints, most of the time this will do nothing. This only sets the voltage in this one place.
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 162
Quoted 6 lines
drivers/misc/hisi_hikey_usb.c +6
-0+ hub_reset_en_gpio =of_get_named_gpio (pdev->dev.of_node, +"hub_reset_en_gpio" ,0 ); +if (!gpio_is_valid (hub_reset_en_gpio)) { +dev_err (&pdev->dev,"Failed to get a valid reset gpio\n" ); +return -ENODEV ; + }
Why not just use devm_gpio_request() which already asks for the GPIO by name?
Re: [RFC 09/10] misc: hisi_hikey_usb: add support for Hikey 970
Em Fri, 4 Sep 2020 13:23:03 +0100
Mark Brown <[email protected]> escreveu:
Quoted 14 lines · Mauro Carvalho Chehab
Quoted 13 lines
drivers/misc/hisi_hikey_usb.c +12
-0+ regulator =devm_regulator_get_optional (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { +if (PTR_ERR (regulator) == -EPROBE_DEFER ) { +dev_info (&pdev->dev, +"waiting for hub-vdd-supply to be probed\n" ); +return PTR_ERR (regulator); + } + +/* let it fall back to regulator dummy */ + regulator =devm_regulator_get (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { + dev_err(&pdev->dev,
Quoted 8 lines
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 151
Quoted 5 lines
drivers/misc/hisi_hikey_usb.c +5
-0+"get hub-vdd-supply failed with error %ld\n" , + PTR_ERR(regulator)); +return PTR_ERR (regulator); + } + }This seems weird - if the supply is non-optional why is the code trying with
devm_regulator_get_optional()? Just use normal get directly.
That's meant to avoid problems with EPROBE_DEFER.
See, Hikey 970 need to initialize 4 drivers for the regulators:
SPMI core, SPMI bus controller, MFD and regulator. This can take some time. So, a first call to *regulator_get() may return EPROBE_DEFER, specially if both regulator drivers and USB HUB are builtin.
I ended doing the same as some other DRM drivers do (like adv7535).
Quoted 7 lines
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 155
Quoted 3 lines
drivers/misc/hisi_hikey_usb.c +3
-0+ ret =regulator_set_voltage (regulator,3300000 ,3300000 ); +if (ret) +dev_err (&pdev->dev,"set hub-vdd-supply voltage failed\n" );Unless the device is actively managing the voltage at runtime it should just let the voltage be set by machine constraints, most of the time this will do nothing. This only sets the voltage in this one place.
Ok, I'll drop this.
Quoted 9 lines
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 162
Quoted 6 lines
drivers/misc/hisi_hikey_usb.c +6
-0+ hub_reset_en_gpio =of_get_named_gpio (pdev->dev.of_node, +"hub_reset_en_gpio" ,0 ); +if (!gpio_is_valid (hub_reset_en_gpio)) { +dev_err (&pdev->dev,"Failed to get a valid reset gpio\n" ); +return -ENODEV ; + }Why not just use
devm_gpio_request()which already asks for the GPIO by name?
Makes sense.
Thanks,
Mauro
Re: [RFC 09/10] misc: hisi_hikey_usb: add support for Hikey 970
Quoted 26 lines · Mauro Carvalho Chehab
Em Fri, 4 Sep 2020 13:23:03 +0100
Mark Brown <[email protected]> escreveu:Quoted 14 lines · Mauro Carvalho Chehab
Quoted 13 lines
drivers/misc/hisi_hikey_usb.c +12
-0+ regulator =devm_regulator_get_optional (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { +if (PTR_ERR (regulator) == -EPROBE_DEFER ) { +dev_info (&pdev->dev, +"waiting for hub-vdd-supply to be probed\n" ); +return PTR_ERR (regulator); + } + +/* let it fall back to regulator dummy */ + regulator =devm_regulator_get (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { + dev_err(&pdev->dev,Quoted 8 lines
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 151
Quoted 5 lines
drivers/misc/hisi_hikey_usb.c +5
-0+"get hub-vdd-supply failed with error %ld\n" , + PTR_ERR(regulator)); +return PTR_ERR (regulator); + } + }This seems weird - if the supply is non-optional why is the code trying with
devm_regulator_get_optional()? Just use normal get directly.
Quoted 1 line
That's meant to avoid problems with
EPROBE_DEFER.
Which problems and in what way does it avoid them?
Quoted 5 lines
See, Hikey 970 need to initialize 4 drivers for the regulators:
SPMI core, SPMI bus controller, MFD and regulator. This can take some time. So, a first call to*regulator_get()may returnEPROBE_DEFER, specially if both regulator drivers and USB HUB are builtin.
This is totally normal and works fine with normal regulator_get().
Quoted 1 line
I ended doing the same as some other DRM drivers do (like adv7535).
I can't find any references to regulator_get_optional() drivers/gpu/drm/bridge/adv7511/adv7511_drv.c?
Re: [RFC 09/10] misc: hisi_hikey_usb: add support for Hikey 970
Em Fri, 4 Sep 2020 13:45:23 +0100
Mark Brown <[email protected]> escreveu:
Quoted 31 lines · Mauro Carvalho Chehab
Quoted 26 lines
Em Fri, 4 Sep 2020 13:23:03 +0100
Mark Brown <[email protected]> escreveu:Quoted 14 lines · Mauro Carvalho Chehab
Quoted 13 lines
drivers/misc/hisi_hikey_usb.c +12
-0+ regulator =devm_regulator_get_optional (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { +if (PTR_ERR (regulator) == -EPROBE_DEFER ) { +dev_info (&pdev->dev, +"waiting for hub-vdd-supply to be probed\n" ); +return PTR_ERR (regulator); + } + +/* let it fall back to regulator dummy */ + regulator =devm_regulator_get (&pdev->dev,"hub-vdd" ); +if (IS_ERR (regulator)) { + dev_err(&pdev->dev,Quoted 8 lines
drivers/misc/hisi_hikey_usb.c static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol · line 151
Quoted 5 lines
drivers/misc/hisi_hikey_usb.c +5
-0+"get hub-vdd-supply failed with error %ld\n" , + PTR_ERR(regulator)); +return PTR_ERR (regulator); + } + }This seems weird - if the supply is non-optional why is the code trying with
devm_regulator_get_optional()? Just use normal get directly.Quoted 1 line
That's meant to avoid problems with
EPROBE_DEFER.Which problems and in what way does it avoid them?
Quoted 7 lines
Quoted 5 lines
See, Hikey 970 need to initialize 4 drivers for the regulators:
SPMI core, SPMI bus controller, MFD and regulator. This can take some time. So, a first call to*regulator_get()may returnEPROBE_DEFER, specially if both regulator drivers and USB HUB are builtin.This is totally normal and works fine with normal
regulator_get().
When I was porting the drm driver (first from OOT Kernel 4.9 to 4.19.5, and then from 4.19.5 to 5.7), I'm pretty sure I got several of those messages:
"supply %s not found, using dummy regulator\n"
due to EPROBE_DEFER. I remember I ended checked the implementation of the regulator code on that time. Yet, looking at the current implementation of _regulator_get():
rdev = regulator_dev_lookup(dev, id);
if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);I see that devm_regulator_get() will do the right thing with EPROBE_DEFER.
So, I'll replace it at the driver. Thanks for the review!
Thanks,
Mauro
RFC 10/10 dts: hisilicon: add support for USB3 on Hikey 970
In reply to Mauro Carvalho ChehabAdd the USB3 bindings for Kirin 970 phy and Hikey 970 board.
--- .../boot/dts/hisilicon/hi3670-hikey970.dts | 103 ++++++++++++++++++ arch/arm64/boot/dts/hisilicon/hi3670.dtsi | 49 +++++++++ 2 files changed, 152 insertions(+)
arch/arm64/boot/dts/hisilicon/hi3670-hikey970.dts +103 -0
@@ -62,6 +62,29 @@ wlan_en: wlan-en-1-8v { startup-delay-us = <70000>; enable-active-high; }; + hikey_usbhub: hikey_usbhub { + compatible = "hisilicon,kirin970_hikey_usbhub"; + + typec-vbus-gpios = <&gpio26 1 0>; + otg-switch-gpios = <&gpio4 2 0>; + hub_reset_en_gpio = <&gpio0 3 0>; + hub-vdd-supply = <&ldo17>; + usb-role-switch; + + port { + #address-cells = <1>; + #size-cells = <0>; + + hikey_usb_ep0: endpoint@0 { + reg = <0>; + remote-endpoint = <&dwc3_role_switch>; + }; + hikey_usb_ep1: endpoint@1 { + reg = <1>; + remote-endpoint = <&rt1711h_ep>; + }; + }; + }; }; /*
@@ -440,6 +463,57 @@ &uart6 { status = "okay"; }; +&i2c1 { + status = "okay"; + + rt1711h: rt1711h@4e { + compatible = "richtek,rt1711h"; + reg = <0x4e>; + status = "ok"; + interrupt-parent = <&gpio27>; + interrupts = <5 IRQ_TYPE_LEVEL_LOW>; + pinctrl-names = "default"; + pinctrl-0 = <&usb_cfg_func>; + + usb_con: connector { + compatible = "usb-c-connector"; + label = "USB-C"; + data-role = "dual"; + power-role = "dual"; + try-power-role = "sink"; + source-pdos = <PDO_FIXED(5000, 500, PDO_FIXED_USB_COMM)>; + sink-pdos = <PDO_FIXED(5000, 500, PDO_FIXED_USB_COMM) + PDO_VAR(5000, 5000, 1000)>; + op-sink-microwatt = <10000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@1 { + reg = <1>; + usb_con_ss: endpoint { + remote-endpoint = <&dwc3_ss>; + }; + }; + }; + }; + port { + #address-cells = <1>; + #size-cells = <0>; + + rt1711h_ep: endpoint@0 { + reg = <0>; + remote-endpoint = <&hikey_usb_ep1>; + }; + }; + }; +}; + +&i2c2 { + /* USB HUB is on this bus at address 0x44 */ + status = "okay"; +}; + &i2c4 { status = "okay";
@@ -469,3 +543,32 @@ adv7533_in: endpoint { }; }; }; + +&dwc3 { /* USB */ + dr_mode = "otg"; + maximum-speed = "super-speed"; + phy_type = "utmi"; + snps,dis-del-phy-power-chg-quirk; + snps,lfps_filter_quirk; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + snps,tx_de_emphasis_quirk; + snps,tx_de_emphasis = <1>; + snps,dis_enblslpm_quirk; + snps,gctl-reset-quirk; + usb-role-switch; + role-switch-default-mode = "host"; + port { + #address-cells = <1>; + #size-cells = <0>; + dwc3_role_switch: endpoint@0 { + reg = <0>; + remote-endpoint = <&hikey_usb_ep0>; + }; + + dwc3_ss: endpoint@1 { + reg = <1>; + remote-endpoint = <&usb_con_ss>; + }; + }; +};
arch/arm64/boot/dts/hisilicon/hi3670.dtsi +49 -0
60 lines not on this page · raw message
Signature · 7 lines
2.26.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 78 lines · Mauro Carvalho Chehab
This RFC adds what seems to be needed for USB to work with Hikey 970. While this driver works fine on Kernel 4.9 and 4.19, there's a hack there, in the form of some special binding logic under dwg3 driver, that seems to
be just adding some delay, and doing some different initializations at
PM (basically, disabling autosuspend).With upstream Kernel, however, I'm getting a hard to track
Kernel panic:[ 1.837458] SError Interrupt on CPU0, code 0xbf000002 -- SError [ 1.837462] CPU: 0 PID: 74 Comm: kworker/0:1 Not tainted 5.8.0+ #205 [ 1.837463] Hardware name: HiKey970 (DT) [ 1.837465] Workqueue: events deferred_probe_work_func [ 1.837467] pstate: 20000005 (nzCv daif -PAN -UAO BTYPE=--) [ 1.837468] pc : _raw_spin_unlock_irqrestore+0x18/0x50 [ 1.837469] lr : regmap_unlock_spinlock+0x14/0x20 [ 1.837470] sp : ffff8000124dba60 [ 1.837471] x29: ffff8000124dba60 x28: 0000000000000000 [ 1.837474] x27: ffff0001b7e854c8 x26: ffff80001204ea18 [ 1.837476] x25: 0000000000000005 x24: ffff800011f918f8 [ 1.837479] x23: ffff800011fbb588 x22: ffff0001b7e40e00 [ 1.837481] x21: 0000000000000100 x20: 0000000000000000 [ 1.837483] x19: ffff0001b767ec00 x18: 00000000ff10c000 [ 1.837485] x17: 0000000000000002 x16: 0000b0740fdb9950 [ 1.837488] x15: ffff8000116c1198 x14: ffffffffffffffff [ 1.837490] x13: 0000000000000030 x12: 0101010101010101 [ 1.837493] x11: 0000000000000020 x10: ffff0001bf17d130 [ 1.837495] x9 : 0000000000000000 x8 : ffff0001b6938080 [ 1.837497] x7 : 0000000000000000 x6 : 000000000000003f [ 1.837500] x5 : 0000000000000000 x4 : 0000000000000000 [ 1.837502] x3 : ffff80001096a880 x2 : 0000000000000000 [ 1.837505] x1 : ffff0001b7e40e00 x0 : 0000000100000001 [ 1.837507] Kernel panic - not syncing: Asynchronous SError Interrupt [ 1.837509] CPU: 0 PID: 74 Comm: kworker/0:1 Not tainted 5.8.0+ #205 [ 1.837510] Hardware name: HiKey970 (DT) [ 1.837511] Workqueue: events deferred_probe_work_func [ 1.837513] Call trace: [ 1.837514] dump_backtrace+0x0/0x1e0 [ 1.837515] show_stack+0x18/0x24 [ 1.837516] dump_stack+0xc0/0x11c [ 1.837517] panic+0x15c/0x324 [ 1.837518] nmi_panic+0x8c/0x90 [ 1.837519] arm64_serror_panic+0x78/0x84 [ 1.837520] do_serror+0x158/0x15c [ 1.837521] el1_error+0x84/0x100 [ 1.837522] _raw_spin_unlock_irqrestore+0x18/0x50 [ 1.837523] regmap_write+0x58/0x80 [ 1.837524] hi3660_reset_deassert+0x28/0x34 [ 1.837526] reset_control_deassert+0x50/0x260 [ 1.837527] reset_control_deassert+0xf4/0x260 [ 1.837528] dwc3_probe+0x5dc/0xe6c [ 1.837529] platform_drv_probe+0x54/0xb0 [ 1.837530] really_probe+0xe0/0x490 [ 1.837531] driver_probe_device+0xf4/0x160 [ 1.837532] __device_attach_driver+0x8c/0x114 [ 1.837533] bus_for_each_drv+0x78/0xcc [ 1.837534] __device_attach+0x108/0x1a0 [ 1.837535] device_initial_probe+0x14/0x20 [ 1.837537] bus_probe_device+0x98/0xa0 [ 1.837538] deferred_probe_work_func+0x88/0xe0 [ 1.837539] process_one_work+0x1cc/0x350 [ 1.837540] worker_thread+0x2c0/0x470 [ 1.837541] kthread+0x154/0x160 [ 1.837542] ret_from_fork+0x10/0x30 [ 1.837569] SMP: stopping secondary CPUs [ 1.837570] Kernel Offset: 0x1d0000 from 0xffff800010000000 [ 1.837571] PHYS_OFFSET: 0x0 [ 1.837572] CPU features: 0x240002,20882004 [ 1.837573] Memory Limit: noneI suspect that the driver works downstream because of the extra delay of probing an additional driver, as porting such driver to upstream sometimes makes this driver to work. So, it could be due to some race condition.
The problem could also be due to something wrong at DT, as, with the additional driver, the DT bindings are different.
Quoted 6 lines
As I'm not familiar about the Serror error mechanism on ARM, I'm wondering if someone could give me some hint about how can I identify what's happening here. Due to the
panic(), I can't check what wrong happened there. Not sure if it would be safe to just hack the error handling part of Serror, in order to let the boot to finish.
As one of my colleagues so wonderfully puts it, SError is effectively "part of the SoC has fallen off" - it's an asynchronous notification of some serious error condition external to the CPU. In this case, it seems quite likely from trying to access a hardware block before it's powered up or has finished its reset cycle, and so some CPU access is raising an error in the interconnect instead of completing as expected.
Robin.
Quoted 36 lines
PS.: the driver/misc
hisi_hikey_usbdriver on this series came from the John Stultz Hikey 960 tree.Thanks!
MauroMauro Carvalho Chehab (7):
phy: hisilicon: phy-hi3670-usb3: use a consistent namespace
phy: hisilicon: phy-hi3670-usb3: fix coding style
phy: hisilicon: phy-hi3670-usb3: change some DT properties
dt-bindings: phy: convert phy-kirin970-usb3.txt to yaml
MAINTAINERS: add myself as maintainer for Kirin 970 USB PHY
misc:hisi_hikey_usb: add support for Hikey 970
dts: hisilicon: add support for USB3 on Hikey 970Yu Chen (3):
phy: hisilicon: add USB physical layer for Kirin 3670
phy: hisilicon: phy-hi3670-usb3: fix some issues at the init code
misc:hisi_hikey_usb: Driver to support onboard USB gpio hub onHikey960.../bindings/phy/hisilicon,hi3670-usb3.yaml | 72 ++ MAINTAINERS | 16 +- .../boot/dts/hisilicon/hi3670-hikey970.dts | 103 +++ arch/arm64/boot/dts/hisilicon/hi3670.dtsi | 49 ++ drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/hisi_hikey_usb.c | 272 +++++++ drivers/phy/hisilicon/Kconfig | 10 + drivers/phy/hisilicon/Makefile | 1 + drivers/phy/hisilicon/phy-hi3670-usb3.c | 671 ++++++++++++++++++ 10 files changed, 1203 insertions(+), 1 deletion(-)create mode 100644
Documentation/devicetree/bindings/phy/hisilicon,hi3670-usb3.yamlcreate mode 100644drivers/misc/hisi_hikey_usb.c
create mode 100644drivers/phy/hisilicon/phy-hi3670-usb3.c
Em Fri, 4 Sep 2020 11:53:10 +0100
Robin Murphy <[email protected]> escreveu:
Quoted 86 lines · Mauro Carvalho Chehab
Quoted 78 lines
This RFC adds what seems to be needed for USB to work with Hikey 970. While this driver works fine on Kernel 4.9 and 4.19, there's a hack there, in the form of some special binding logic under dwg3 driver, that seems to
be just adding some delay, and doing some different initializations at
PM (basically, disabling autosuspend).With upstream Kernel, however, I'm getting a hard to track
Kernel panic:[ 1.837458] SError Interrupt on CPU0, code 0xbf000002 -- SError [ 1.837462] CPU: 0 PID: 74 Comm: kworker/0:1 Not tainted 5.8.0+ #205 [ 1.837463] Hardware name: HiKey970 (DT) [ 1.837465] Workqueue: events deferred_probe_work_func [ 1.837467] pstate: 20000005 (nzCv daif -PAN -UAO BTYPE=--) [ 1.837468] pc : _raw_spin_unlock_irqrestore+0x18/0x50 [ 1.837469] lr : regmap_unlock_spinlock+0x14/0x20 [ 1.837470] sp : ffff8000124dba60 [ 1.837471] x29: ffff8000124dba60 x28: 0000000000000000 [ 1.837474] x27: ffff0001b7e854c8 x26: ffff80001204ea18 [ 1.837476] x25: 0000000000000005 x24: ffff800011f918f8 [ 1.837479] x23: ffff800011fbb588 x22: ffff0001b7e40e00 [ 1.837481] x21: 0000000000000100 x20: 0000000000000000 [ 1.837483] x19: ffff0001b767ec00 x18: 00000000ff10c000 [ 1.837485] x17: 0000000000000002 x16: 0000b0740fdb9950 [ 1.837488] x15: ffff8000116c1198 x14: ffffffffffffffff [ 1.837490] x13: 0000000000000030 x12: 0101010101010101 [ 1.837493] x11: 0000000000000020 x10: ffff0001bf17d130 [ 1.837495] x9 : 0000000000000000 x8 : ffff0001b6938080 [ 1.837497] x7 : 0000000000000000 x6 : 000000000000003f [ 1.837500] x5 : 0000000000000000 x4 : 0000000000000000 [ 1.837502] x3 : ffff80001096a880 x2 : 0000000000000000 [ 1.837505] x1 : ffff0001b7e40e00 x0 : 0000000100000001 [ 1.837507] Kernel panic - not syncing: Asynchronous SError Interrupt [ 1.837509] CPU: 0 PID: 74 Comm: kworker/0:1 Not tainted 5.8.0+ #205 [ 1.837510] Hardware name: HiKey970 (DT) [ 1.837511] Workqueue: events deferred_probe_work_func [ 1.837513] Call trace: [ 1.837514] dump_backtrace+0x0/0x1e0 [ 1.837515] show_stack+0x18/0x24 [ 1.837516] dump_stack+0xc0/0x11c [ 1.837517] panic+0x15c/0x324 [ 1.837518] nmi_panic+0x8c/0x90 [ 1.837519] arm64_serror_panic+0x78/0x84 [ 1.837520] do_serror+0x158/0x15c [ 1.837521] el1_error+0x84/0x100 [ 1.837522] _raw_spin_unlock_irqrestore+0x18/0x50 [ 1.837523] regmap_write+0x58/0x80 [ 1.837524] hi3660_reset_deassert+0x28/0x34 [ 1.837526] reset_control_deassert+0x50/0x260 [ 1.837527] reset_control_deassert+0xf4/0x260 [ 1.837528] dwc3_probe+0x5dc/0xe6c [ 1.837529] platform_drv_probe+0x54/0xb0 [ 1.837530] really_probe+0xe0/0x490 [ 1.837531] driver_probe_device+0xf4/0x160 [ 1.837532] __device_attach_driver+0x8c/0x114 [ 1.837533] bus_for_each_drv+0x78/0xcc [ 1.837534] __device_attach+0x108/0x1a0 [ 1.837535] device_initial_probe+0x14/0x20 [ 1.837537] bus_probe_device+0x98/0xa0 [ 1.837538] deferred_probe_work_func+0x88/0xe0 [ 1.837539] process_one_work+0x1cc/0x350 [ 1.837540] worker_thread+0x2c0/0x470 [ 1.837541] kthread+0x154/0x160 [ 1.837542] ret_from_fork+0x10/0x30 [ 1.837569] SMP: stopping secondary CPUs [ 1.837570] Kernel Offset: 0x1d0000 from 0xffff800010000000 [ 1.837571] PHYS_OFFSET: 0x0 [ 1.837572] CPU features: 0x240002,20882004 [ 1.837573] Memory Limit: noneI suspect that the driver works downstream because of the extra delay of probing an additional driver, as porting such driver to upstream sometimes makes this driver to work. So, it could be due to some race condition.
The problem could also be due to something wrong at DT, as, with the additional driver, the DT bindings are different.
Quoted 6 lines
As I'm not familiar about the Serror error mechanism on ARM, I'm wondering if someone could give me some hint about how can I identify what's happening here. Due to the
panic(), I can't check what wrong happened there. Not sure if it would be safe to just hack the error handling part of Serror, in order to let the boot to finish.
Quoted 6 lines
As one of my colleagues so wonderfully puts it, SError is effectively "part of the SoC has fallen off" - it's an asynchronous notification of some serious error condition external to the CPU. In this case, it seems quite likely from trying to access a hardware block before it's powered up or has finished its reset cycle, and so some CPU access is raising an error in the interconnect instead of completing as expected.
Looking at the datasheet:
It sounds that the only power supply related to USB is for the USB hub (ldo17), with sounds unlikely to affect dwc3. Yet, just in case, I added a dirty hack at dwc3_probe:
<snip>
drivers/usb/dwc3/core.c +5 -0
@@ -1491,6 +1491,11 @@ static int dwc3_probe(struct platform_device *pdev) } +struct regulator *reg; +reg =devm_regulator_get (dev,"ldo17" ); +ret =PTR_ERR_OR_ZERO (reg); +if (ret)return ret; + ret =reset_control_deassert (dwc->reset);if (ret)return ret;
</snip>
Nothing changed.
The enclosed patch is enough for it to stop panic'ing and for the driver to show signs of life:
$ lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
The probe code there is pretty much the same as the dwc3 one, but it doesn't contain calls to pm_* stuff. So, as far as I understood, this way, dwc3 won't touch the clocks.
Thanks,
Mauro
arch/arm64/boot/dts/hisilicon/hi3670.dtsi +17 -10
@@ -823,14 +823,16 @@ usb31_misc_rst: usb31_misc_rst_controller { hisi,rst-syscon = <&usb3_otg_bc>; }; - dwc3: dwc3@ff100000 { - compatible = "snps,dwc3"; - reg = <0x0 0xff100000 0x0 0x100000>; + usb3: hisi_dwc3 { + compatible = "hisilicon,kirin970-dwc3"; + #address-cells = <2>; + #size-cells = <2>; + ranges; clocks = <&crg_ctrl HI3670_CLK_GATE_ABB_USB>, - <&crg_ctrl HI3670_HCLK_GATE_USB3OTG>, - <&crg_ctrl HI3670_CLK_GATE_USB3OTG_REF>, - <&crg_ctrl HI3670_ACLK_GATE_USB3DVFS>; + <&crg_ctrl HI3670_HCLK_GATE_USB3OTG>, + <&crg_ctrl HI3670_CLK_GATE_USB3OTG_REF>, + <&crg_ctrl HI3670_ACLK_GATE_USB3DVFS>; clock-names = "clk_gate_abb_usb", "hclk_gate_usb3otg", "clk_gate_usb3otg_ref",
@@ -843,11 +845,16 @@ dwc3: dwc3@ff100000 { <&usb31_misc_rst 0xA0 8>, <&usb31_misc_rst 0xA0 9>; - interrupts = <0 159 IRQ_TYPE_LEVEL_HIGH>, - <0 161 IRQ_TYPE_LEVEL_HIGH>; + dwc3: dwc3@ff100000 { + compatible = "snps,dwc3"; + reg = <0x0 0xff100000 0x0 0x100000>; - phys = <&usb_phy>; - phy-names = "usb3-phy"; + interrupts = <0 159 IRQ_TYPE_LEVEL_HIGH>, + <0 161 IRQ_TYPE_LEVEL_HIGH>; + + phys = <&usb_phy>; + phy-names = "usb3-phy"; + }; }; }; };
drivers/usb/dwc3/Kconfig +8 -0
@@ -139,4 +139,12 @@ config USB_DWC3_QCOM for peripheral mode support. Say 'Y' or 'M' if you have one such device. +config USB_DWC3_HISI + tristate "HiSilicon Kirin Platforms" + depends on ((ARCH_HISI && ARM64) || COMPILE_TEST) && OF + default USB_DWC3 + help + Support of USB2/3 functionality in HiSilicon Kirin platforms. + Say 'Y' or 'M' if you have one such device. + endif
drivers/usb/dwc3/Makefile +1 -0
@@ -51,3 +51,4 @@ obj-$(CONFIG_USB_DWC3_MESON_G12A) += dwc3-meson-g12a.o obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o +obj-$(CONFIG_USB_DWC3_HISI) += dwc3-hisi.o
drivers/usb/dwc3/dwc3-hisi.c new file +329 -0
329 lines not on this page · raw message
Quoted 10 lines · Mauro Carvalho Chehab
It sounds that the only power supply related to USB is for the USB hub (ldo17), with sounds unlikely to affect dwc3. Yet, just in case, I added a dirty hack at
dwc3_probe:<snip>
drivers/usb/dwc3/core.c +0
-0
drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 1497
Quoted 7 lines
drivers/usb/dwc3/core.c +4
-0@@ -1491,6 +1491,11 @@ static int dwc3_probe(struct platform_device *pdev) } +struct regulator *reg; +reg =devm_regulator_get (dev,"ldo17" ); +ret =PTR_ERR_OR_ZERO (reg); +if (ret)return ret;
A regulator_get() is going to do absolutely nothing to the state of the regulator, if you're trying to enable it you need to do regulator_enable()