2022-04-14 14:34:41

by Samuel Holland

[permalink] [raw]
Subject: [PATCH 0/6] phy: rockchip-inno-usb2: RK356x OTG fix and enhancements

This series gets USB OTG working on the RK356x SoCs, as used in the
PineNote tablet.

- Patch 1 fixes an interrupt storm issue specific to RK356x.
- Patches 2 and 3 are a couple of small optimizations.
- Patches 4 and 5 reduce the delay when unplugging from the OTG port.
- Patch 6 allows OTG ports to work in host mode without depending on
another driver to provide an extcon. The specific use case here is
a Type-C port controller that provides a hardware "ID pin" output.


Samuel Holland (6):
phy: rockchip-inno-usb2: Fix muxed interrupt support
phy: rockchip-inno-usb2: Do not check bvalid twice
phy: rockchip-inno-usb2: Do not lock in bvalid IRQ handler
phy: rockchip-inno-usb2: Support multi-bit mask properties
phy: rockchip-inno-usb2: Handle bvalid falling
phy: rockchip-inno-usb2: Handle ID IRQ

drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 125 +++++++++++++++---
1 file changed, 105 insertions(+), 20 deletions(-)

--
2.35.1


2022-04-14 22:46:50

by Samuel Holland

[permalink] [raw]
Subject: [PATCH 1/6] phy: rockchip-inno-usb2: Fix muxed interrupt support

This commit fixes two issues with the muxed interrupt handler. First,
the OTG port has the "bvalid" interrupt enabled, not "linestate". Since
only the linestate interrupt was handled, and not the bvalid interrupt,
plugging in a cable to the OTG port caused an interrupt storm.

Second, the return values from the individual port IRQ handlers need to
be OR-ed together. Otherwise, the lack of an interrupt from the last
port would cause the handler to erroneously return IRQ_NONE.

Fixes: ed2b5a8e6b98 ("phy: phy-rockchip-inno-usb2: support muxed interrupts")
Signed-off-by: Samuel Holland <[email protected]>
---

drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index eca77e44a4c1..cba5c32cbaee 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -940,8 +940,14 @@ static irqreturn_t rockchip_usb2phy_irq(int irq, void *data)
if (!rport->phy)
continue;

- /* Handle linestate irq for both otg port and host port */
- ret = rockchip_usb2phy_linestate_irq(irq, rport);
+ switch (rport->port_id) {
+ case USB2PHY_PORT_OTG:
+ ret |= rockchip_usb2phy_otg_mux_irq(irq, rport);
+ break;
+ case USB2PHY_PORT_HOST:
+ ret |= rockchip_usb2phy_linestate_irq(irq, rport);
+ break;
+ }
}

return ret;
--
2.35.1

2022-04-15 08:35:46

by Samuel Holland

[permalink] [raw]
Subject: [PATCH 4/6] phy: rockchip-inno-usb2: Support multi-bit mask properties

The "bvalid" and "id" interrupts can trigger on either the rising edge
or the falling edge, so each interrupt has two enable bits and two
status bits. This change allows using a single property for both bits,
checking whether either bit is set.

Signed-off-by: Samuel Holland <[email protected]>
---

drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index 3422db56be76..c694517496f8 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -253,7 +253,7 @@ static inline bool property_enabled(struct regmap *base,
return false;

tmp = (orig & mask) >> reg->bitstart;
- return tmp == reg->enable;
+ return tmp != reg->disable;
}

static int rockchip_usb2phy_clk480m_prepare(struct clk_hw *hw)
--
2.35.1

2022-04-16 00:54:34

by Michael Riesch

[permalink] [raw]
Subject: Re: [PATCH 0/6] phy: rockchip-inno-usb2: RK356x OTG fix and enhancements

Hello Samuel,

On 4/14/22 05:22, Samuel Holland wrote:
> This series gets USB OTG working on the RK356x SoCs, as used in the
> PineNote tablet.
>
> - Patch 1 fixes an interrupt storm issue specific to RK356x.
> - Patches 2 and 3 are a couple of small optimizations.
> - Patches 4 and 5 reduce the delay when unplugging from the OTG port.
> - Patch 6 allows OTG ports to work in host mode without depending on
> another driver to provide an extcon. The specific use case here is
> a Type-C port controller that provides a hardware "ID pin" output.
>
>
> Samuel Holland (6):
> phy: rockchip-inno-usb2: Fix muxed interrupt support
> phy: rockchip-inno-usb2: Do not check bvalid twice
> phy: rockchip-inno-usb2: Do not lock in bvalid IRQ handler
> phy: rockchip-inno-usb2: Support multi-bit mask properties
> phy: rockchip-inno-usb2: Handle bvalid falling
> phy: rockchip-inno-usb2: Handle ID IRQ
>
> drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 125 +++++++++++++++---
> 1 file changed, 105 insertions(+), 20 deletions(-)

Thanks a lot! This series fixes the USB gadget operation of my RK356x
boards.

With suitable DTS changes, the zero gadget module, and usbtest

Tested-by: Michael Riesch <[email protected]>

on a RK3568 EVB1 and a Rock 3 Model A.

Best regards,
Michael

2022-04-16 01:07:06

by Samuel Holland

[permalink] [raw]
Subject: [PATCH 5/6] phy: rockchip-inno-usb2: Handle bvalid falling

Some SoCs have a bvalid falling interrupt, in addition to bvalid rising.
This interrupt can detect OTG cable plugout immediately, so it can avoid
the delay until the next scheduled work.

Signed-off-by: Samuel Holland <[email protected]>
---

drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index c694517496f8..2b29f5dd8873 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -1345,9 +1345,9 @@ static const struct rockchip_usb2phy_cfg rk3308_phy_cfgs[] = {
.port_cfgs = {
[USB2PHY_PORT_OTG] = {
.phy_sus = { 0x0100, 8, 0, 0, 0x1d1 },
- .bvalid_det_en = { 0x3020, 2, 2, 0, 1 },
- .bvalid_det_st = { 0x3024, 2, 2, 0, 1 },
- .bvalid_det_clr = { 0x3028, 2, 2, 0, 1 },
+ .bvalid_det_en = { 0x3020, 3, 2, 0, 3 },
+ .bvalid_det_st = { 0x3024, 3, 2, 0, 3 },
+ .bvalid_det_clr = { 0x3028, 3, 2, 0, 3 },
.ls_det_en = { 0x3020, 0, 0, 0, 1 },
.ls_det_st = { 0x3024, 0, 0, 0, 1 },
.ls_det_clr = { 0x3028, 0, 0, 0, 1 },
@@ -1388,9 +1388,9 @@ static const struct rockchip_usb2phy_cfg rk3328_phy_cfgs[] = {
.port_cfgs = {
[USB2PHY_PORT_OTG] = {
.phy_sus = { 0x0100, 15, 0, 0, 0x1d1 },
- .bvalid_det_en = { 0x0110, 2, 2, 0, 1 },
- .bvalid_det_st = { 0x0114, 2, 2, 0, 1 },
- .bvalid_det_clr = { 0x0118, 2, 2, 0, 1 },
+ .bvalid_det_en = { 0x0110, 3, 2, 0, 3 },
+ .bvalid_det_st = { 0x0114, 3, 2, 0, 3 },
+ .bvalid_det_clr = { 0x0118, 3, 2, 0, 3 },
.ls_det_en = { 0x0110, 0, 0, 0, 1 },
.ls_det_st = { 0x0114, 0, 0, 0, 1 },
.ls_det_clr = { 0x0118, 0, 0, 0, 1 },
@@ -1512,9 +1512,9 @@ static const struct rockchip_usb2phy_cfg rk3568_phy_cfgs[] = {
.port_cfgs = {
[USB2PHY_PORT_OTG] = {
.phy_sus = { 0x0000, 8, 0, 0, 0x1d1 },
- .bvalid_det_en = { 0x0080, 2, 2, 0, 1 },
- .bvalid_det_st = { 0x0084, 2, 2, 0, 1 },
- .bvalid_det_clr = { 0x0088, 2, 2, 0, 1 },
+ .bvalid_det_en = { 0x0080, 3, 2, 0, 3 },
+ .bvalid_det_st = { 0x0084, 3, 2, 0, 3 },
+ .bvalid_det_clr = { 0x0088, 3, 2, 0, 3 },
.utmi_avalid = { 0x00c0, 10, 10, 0, 1 },
.utmi_bvalid = { 0x00c0, 9, 9, 0, 1 },
},
--
2.35.1

2022-04-16 02:17:56

by Samuel Holland

[permalink] [raw]
Subject: [PATCH 3/6] phy: rockchip-inno-usb2: Do not lock in bvalid IRQ handler

Clearing the IRQ is atomic, so there is no need to hold the mutex.

Signed-off-by: Samuel Holland <[email protected]>
---

drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
index 29407b36f5fa..3422db56be76 100644
--- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
+++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c
@@ -905,13 +905,9 @@ static irqreturn_t rockchip_usb2phy_bvalid_irq(int irq, void *data)
if (!property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st))
return IRQ_NONE;

- mutex_lock(&rport->mutex);
-
/* clear bvalid detect irq pending status */
property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, true);

- mutex_unlock(&rport->mutex);
-
rockchip_usb2phy_otg_sm_work(&rport->otg_sm_work.work);

return IRQ_HANDLED;
--
2.35.1

2022-04-21 08:10:40

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 0/6] phy: rockchip-inno-usb2: RK356x OTG fix and enhancements

On 13-04-22, 22:22, Samuel Holland wrote:
> This series gets USB OTG working on the RK356x SoCs, as used in the
> PineNote tablet.

Applied, thanks

--
~Vinod