Skip to contentSkip to conversation

usb: dwc3: imx8mp: detect dwc3 core node via compatible string

PATCH In review Li Jun 3 participants 13 messages Apr 30, 2021 – Aug 2, 2021

Subsystems (4)
lore
Share & tools
lore

Li Jun

author
#0 lore raw

PATCH 1/1 usb: dwc3: imx8mp: detect dwc3 core node via compatible string

New schema of usb controller DT-node should be named with prefix "^usb(@.*)?", dt changed the node name, but missed counter part change in driver, fix it by switching to use compatible string as the dwc3 core compatible string keeps "snps,dwc3" in all dt.

Fixes d1689cd3c0f4 ("arm64: dts: imx8mp: Use the correct name for child node "snps, dwc3"")
---
 drivers/usb/dwc3/dwc3-imx8mp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-imx8mp.c +1 -1
index b13cfab89d53..e9fced6f7a7c 100644
@@ -165,7 +165,7 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev)
 	if (err < 0)
 		goto disable_rpm;
 
-	dwc3_np = of_get_child_by_name(node, "dwc3");
+	dwc3_np = of_get_compatible_child(node, "snps,dwc3");
 	if (!dwc3_np) {
 		dev_err(dev, "failed to find dwc3 core child\n");
 		goto disable_rpm;
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Li Jun

New schema of usb controller DT-node should be named with prefix "^usb(@.*)?", dt changed the node name, but missed counter part change in driver, fix it by switching to use compatible string as the dwc3 core compatible string keeps "snps,dwc3" in all dt.

Fixes d1689cd3c0f4 ("arm64: dts: imx8mp: Use the correct name for child node "snps, dwc3"")

Nice fix :-) It may break down if we have two dwc3 nodes as child of a single parent, but I guess that's very unlikely anyway.

That being said, why do need to keep a pointer to the child? I had a quick look at the driver and it doesn't seem like the pointer is necessary at all.

Signature · 1 line
balbi
author
#2 lore raw

Hi,

Quoted 21 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Friday, April 30, 2021 4:24 PM
To: Jun Li <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Quoted 8 lines · Li Jun

New schema of usb controller DT-node should be named with prefix "^usb(@.*)?", dt changed the node name, but missed counter part change in driver, fix it by switching to use compatible string as the dwc3 core compatible string keeps "snps,dwc3" in all dt.

Fixes d1689cd3c0f4 ("arm64: dts: imx8mp: Use the correct name for

child node "snps, dwc3"")

Quoted 7 lines

Nice fix :-) It may break down if we have two dwc3 nodes as child of a single parent, but I guess that's very unlikely anyway.

That being said, why do need to keep a pointer to the child? I had a quick look at the driver and it doesn't seem like the pointer is necessary at all.

I need keep the child pointer(dwc3 core platform device) to find the dwc3 core instance struct(struct dwc3), the wakeup setting need check the dwc3 core's current_dr_role and do runtime resume based on the child's dev.

Thanks
Li Jun

Quoted 3 lines

--
balbi

#3 lore raw

Hi,

Quoted 24 lines · Jun Li
Quoted 24 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Friday, April 30, 2021 4:24 PM
To: Jun Li <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Quoted 8 lines · Li Jun

New schema of usb controller DT-node should be named with prefix "^usb(@.*)?", dt changed the node name, but missed counter part change in driver, fix it by switching to use compatible string as the dwc3 core compatible string keeps "snps,dwc3" in all dt.

Fixes d1689cd3c0f4 ("arm64: dts: imx8mp: Use the correct name for

child node "snps, dwc3"")

Nice fix :-) It may break down if we have two dwc3 nodes as child of a single parent, but I guess that's very unlikely anyway.

Quoted 8 lines
Quoted 4 lines

That being said, why do need to keep a pointer to the child? I had a quick look at the driver and it doesn't seem like the pointer is necessary at all.

I need keep the child pointer(dwc3 core platform device) to find the dwc3 core instance struct(struct dwc3), the wakeup setting need check the dwc3 core's current_dr_role and do runtime resume based on the child's dev.

Right, you're talking about the code below. Some suggestions inline:

Quoted 7 lines

static void dwc3_imx8mp_wakeup_enable(struct dwc3_imx8mp *dwc3_imx)

{
	struct dwc3	*dwc3 = platform_get_drvdata(dwc3_imx->dwc3);
	u32		val;

	if (!dwc3)
		return;

I don't think you need to care if dwc3 has probed or not here.

Quoted 8 lines
	val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL);

	if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci)
		val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN |
		       USB_WAKEUP_U3_EN | USB_WAKEUP_DPDM_EN;
	else if (dwc3->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN |
		       USB_WAKEUP_VBUS_SRC_SESS_VAL;

for this, you could register a listener to the extcon notifier and update these bits accordingly. With that, you would already *know* that dwc3 is probed.

Quoted 11 lines

static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx)

{
	struct dwc3_imx8mp	*dwc3_imx = _dwc3_imx;
	struct dwc3		*dwc = platform_get_drvdata(dwc3_imx->dwc3);

	if (!dwc3_imx->pm_suspended)
		return IRQ_HANDLED;

	disable_irq_nosync(dwc3_imx->irq);
	dwc3_imx->wakeup_pending = true;
Quoted 7 lines
	if ((dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc->xhci)
		pm_runtime_resume(&dwc->xhci->dev);
	else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		pm_runtime_get(dwc->dev);

	return IRQ_HANDLED;
}

for this, maybe you need to teach dwc3 core about wakeup irqs instead. Have a look dev_pm_set_dedicated_wake_irq().

That would clean things up, I think ;)

Signature · 1 line
balbi
author
#4 lore raw

Hi,

Quoted 50 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Friday, April 30, 2021 6:00 PM
To: Jun Li <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Hi,

Quoted 21 lines · Jun Li
Quoted 21 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Friday, April 30, 2021 4:24 PM
To: Jun Li <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Quoted 8 lines · Li Jun

New schema of usb controller DT-node should be named with prefix "^usb(@.*)?", dt changed the node name, but missed counter part change in driver, fix it by switching to use compatible string as the dwc3 core compatible string keeps "snps,dwc3" in all dt.

Fixes d1689cd3c0f4 ("arm64: dts: imx8mp: Use the correct name for

child node "snps, dwc3"")

Quoted 7 lines
Quoted 7 lines

Nice fix :-) It may break down if we have two dwc3 nodes as child of a single parent, but I guess that's very unlikely anyway.

That being said, why do need to keep a pointer to the child? I had a quick look at the driver and it doesn't seem like the pointer is necessary

at all.

Quoted 4 lines

I need keep the child pointer(dwc3 core platform device) to find the dwc3 core instance struct(struct dwc3), the wakeup setting need check the dwc3 core's current_dr_role and do runtime resume based on the child's

dev.

Right, you're talking about the code below. Some suggestions inline:

Quoted 8 lines
Quoted 6 lines
static void dwc3_imx8mp_wakeup_enable(struct dwc3_imx8mp *dwc3_imx) {
	struct dwc3	*dwc3 = platform_get_drvdata(dwc3_imx->dwc3);
	u32		val;

	if (!dwc3)
		return;

I don't think you need to care if dwc3 has probed or not here.

Yes if there is other way to know current role.

Quoted 10 lines
Quoted 9 lines
	val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL);

	if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci)
		val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN |
		       USB_WAKEUP_U3_EN | USB_WAKEUP_DPDM_EN;
	else if (dwc3->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN |
		       USB_WAKEUP_VBUS_SRC_SESS_VAL;
Quoted 3 lines

for this, you could register a listener to the extcon notifier and update these bits accordingly. With that, you would already *know* that dwc3 is probed.

With usb role switch class, there no extcon provider, so I think this way can't work for me.

Quoted 16 lines
Quoted 16 lines
static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx) {
	struct dwc3_imx8mp	*dwc3_imx = _dwc3_imx;
	struct dwc3		*dwc = platform_get_drvdata(dwc3_imx->dwc3);

	if (!dwc3_imx->pm_suspended)
		return IRQ_HANDLED;

	disable_irq_nosync(dwc3_imx->irq);
	dwc3_imx->wakeup_pending = true;

	if ((dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc->xhci)
		pm_runtime_resume(&dwc->xhci->dev);
	else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		pm_runtime_get(dwc->dev);
Quoted 5 lines
Quoted 2 lines
	return IRQ_HANDLED;
}

for this, maybe you need to teach dwc3 core about wakeup irqs instead. Have a look dev_pm_set_dedicated_wake_irq().

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access dwc3 core instance struct, right?

Quoted 2 lines

That would clean things up, I think ;)

Yes, I may use dev_pm_set_dedicated_wake_irq() to attach the wakeup irq to dwc->dev and &dwc->xhci->dev for device and host mode, which will clean things up.

thanks
Li Jun

Quoted 3 lines

--
balbi

#5 lore raw

Hi,

Quoted 9 lines · Jun Li
Quoted 9 lines
Quoted 8 lines
	val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL);

	if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci)
		val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN |
		       USB_WAKEUP_U3_EN | USB_WAKEUP_DPDM_EN;
	else if (dwc3->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN |
		       USB_WAKEUP_VBUS_SRC_SESS_VAL;
Quoted 6 lines
Quoted 3 lines

for this, you could register a listener to the extcon notifier and update these bits accordingly. With that, you would already *know* that dwc3 is probed.

With usb role switch class, there no extcon provider, so I think this way can't work for me.

perhaps role switch class could learn about notifiers ;-)

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx) {
	struct dwc3_imx8mp	*dwc3_imx = _dwc3_imx;
	struct dwc3		*dwc = platform_get_drvdata(dwc3_imx->dwc3);

	if (!dwc3_imx->pm_suspended)
		return IRQ_HANDLED;

	disable_irq_nosync(dwc3_imx->irq);
	dwc3_imx->wakeup_pending = true;

	if ((dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc->xhci)
		pm_runtime_resume(&dwc->xhci->dev);
	else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		pm_runtime_get(dwc->dev);

	return IRQ_HANDLED;
}
Quoted 6 lines
Quoted 2 lines

for this, maybe you need to teach dwc3 core about wakeup irqs instead. Have a look dev_pm_set_dedicated_wake_irq().

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access dwc3 core instance struct, right?

for now, maybe. But it may be better to implement a notifier method in role switch class.

Signature · 1 line
balbi
author
#6 lore raw

Hi

Quoted 53 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Thursday, May 6, 2021 10:32 PM
To: Jun Li <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Hi,

Quoted 9 lines · Jun Li
Quoted 9 lines
Quoted 8 lines
	val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL);

	if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci)
		val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN |
		       USB_WAKEUP_U3_EN | USB_WAKEUP_DPDM_EN;
	else if (dwc3->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN |
		       USB_WAKEUP_VBUS_SRC_SESS_VAL;
Quoted 7 lines
Quoted 4 lines

for this, you could register a listener to the extcon notifier and update these bits accordingly. With that, you would already *know* that
dwc3 is probed.

With usb role switch class, there no extcon provider, so I think this way can't work for me.

perhaps role switch class could learn about notifiers ;-)

Quoted 21 lines
Quoted 20 lines
Quoted 10 lines
static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx) {
	struct dwc3_imx8mp	*dwc3_imx = _dwc3_imx;
	struct dwc3		*dwc = platform_get_drvdata(dwc3_imx->dwc3);

	if (!dwc3_imx->pm_suspended)
		return IRQ_HANDLED;

	disable_irq_nosync(dwc3_imx->irq);
	dwc3_imx->wakeup_pending = true;
Quoted 7 lines
	if ((dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc->xhci)
		pm_runtime_resume(&dwc->xhci->dev);
	else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		pm_runtime_get(dwc->dev);

	return IRQ_HANDLED;
}

for this, maybe you need to teach dwc3 core about wakeup irqs instead. Have a look dev_pm_set_dedicated_wake_irq().

Quoted 6 lines
Quoted 3 lines

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access dwc3 core instance struct, right?

for now, maybe. But it may be better to implement a notifier method in role switch class.

I am not sure if introduce notifier in role switch class is a good idea, I had the impression extcon is not encouraged to use if possible.

+ Heikki

Thanks
Li Jun

Quoted 3 lines

--
balbi

#7 lore raw

Hi guys,

Quoted 59 lines · Jun Li

Hi

Quoted 57 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Thursday, May 6, 2021 10:32 PM
To: Jun Li <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Hi,

Quoted 9 lines · Jun Li
Quoted 9 lines
Quoted 8 lines
	val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL);

	if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc3->xhci)
		val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN |
		       USB_WAKEUP_U3_EN | USB_WAKEUP_DPDM_EN;
	else if (dwc3->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN |
		       USB_WAKEUP_VBUS_SRC_SESS_VAL;
Quoted 7 lines
Quoted 4 lines

for this, you could register a listener to the extcon notifier and update these bits accordingly. With that, you would already *know* that
dwc3 is probed.

With usb role switch class, there no extcon provider, so I think this way can't work for me.

perhaps role switch class could learn about notifiers ;-)

Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx) {
	struct dwc3_imx8mp	*dwc3_imx = _dwc3_imx;
	struct dwc3		*dwc = platform_get_drvdata(dwc3_imx->dwc3);

	if (!dwc3_imx->pm_suspended)
		return IRQ_HANDLED;

	disable_irq_nosync(dwc3_imx->irq);
	dwc3_imx->wakeup_pending = true;

	if ((dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) && dwc->xhci)
		pm_runtime_resume(&dwc->xhci->dev);
	else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		pm_runtime_get(dwc->dev);
Quoted 5 lines
Quoted 2 lines
	return IRQ_HANDLED;
}

for this, maybe you need to teach dwc3 core about wakeup irqs instead. Have a look dev_pm_set_dedicated_wake_irq().

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access dwc3 core instance struct, right?

Quoted 5 lines
Quoted 2 lines

for now, maybe. But it may be better to implement a notifier method in role switch class.

I am not sure if introduce notifier in role switch class is a good idea, I had the impression extcon is not encouraged to use if possible.

I'm not against role switch notifiers. They were proposed before already couple of years ago, but at that time there just were no users them notifier, so the patch was just dropped from the series [1]. But I don't think anybody was against the idea. Please feel free to add them to the class if you have use for them.

Or, are we talking about some other notifier here?

[1] https://lore.kernel.org/linux-usb/[email protected]/

thanks,

Signature · 1 line
heikki
author
#8 lore raw

Hi,

Quoted 79 lines

-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Tuesday, May 11, 2021 3:59 PM
To: Jun Li <[email protected]>
Cc: Felipe Balbi <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Hi guys,

Quoted 18 lines · Jun Li

Hi

Quoted 16 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Thursday, May 6, 2021 10:32 PM
To: Jun Li <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Hi,

Quoted 3 lines · Jun Li
Quoted 3 lines
Quoted 3 lines
	val = readl(dwc3_imx->glue_base + USB_WAKEUP_CTRL);

	if ((dwc3->current_dr_role == DWC3_GCTL_PRTCAP_HOST) &&

dwc3->xhci)

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
		val |= USB_WAKEUP_EN | USB_WAKEUP_SS_CONN |
		       USB_WAKEUP_U3_EN | USB_WAKEUP_DPDM_EN;
	else if (dwc3->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		val |= USB_WAKEUP_EN | USB_WAKEUP_VBUS_EN |
		       USB_WAKEUP_VBUS_SRC_SESS_VAL;

for this, you could register a listener to the extcon notifier and update these bits accordingly. With that, you would already *know* that
dwc3 is probed.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

With usb role switch class, there no extcon provider, so I think this way can't work for me.

perhaps role switch class could learn about notifiers ;-)

Quoted 1 line
Quoted 1 line
Quoted 1 line

static irqreturn_t dwc3_imx8mp_interrupt(int irq, void *_dwc3_imx)

{

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
	struct dwc3_imx8mp	*dwc3_imx = _dwc3_imx;
	struct dwc3		*dwc = platform_get_drvdata(dwc3_imx->dwc3);

	if (!dwc3_imx->pm_suspended)
		return IRQ_HANDLED;

	disable_irq_nosync(dwc3_imx->irq);
	dwc3_imx->wakeup_pending = true;

	if ((dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) &&

dwc->xhci)

Quoted 18 lines
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
		pm_runtime_resume(&dwc->xhci->dev);
	else if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
		pm_runtime_get(dwc->dev);

	return IRQ_HANDLED;
}
Quoted 7 lines
Quoted 2 lines

for this, maybe you need to teach dwc3 core about wakeup irqs instead. Have a look dev_pm_set_dedicated_wake_irq().

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access
dwc3 core instance struct, right?

for now, maybe. But it may be better to implement a notifier method in role switch class.

Quoted 8 lines
Quoted 2 lines

I am not sure if introduce notifier in role switch class is a good idea, I had the impression extcon is not encouraged to use if possible.

I'm not against role switch notifiers. They were proposed before already couple of years ago, but at that time there just were no users them notifier, so the patch was just dropped from the series [1].
But I don't think anybody was against the idea. Please feel free to add them to the class if you have use for them.

So I had the incorrect impression.

Yes, that's the Felipe was referring to, I think.

I will pick up [1] and improve my driver as Felipe suggested.

Thanks
Li Jun

Quoted 17 lines

Or, are we talking about some other notifier here?

[1]
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.
kernel.org%2Flinux-usb%2F20191002231617.3670-3-john.stultz%40linaro.org %2F&amp;data=04%7C01%7Cjun.li%40nxp.com%7C9479f8f61e1a47245c2e08d91452a dd6%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637563167667138204%7CU nknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haW wiLCJXVCI6Mn0%3D%7C1000&amp;sdata=EhSPBC1sGeH65EPuFV22pEcVS6nDeRNPdN9Z1 3lPPYg%3D&amp;reserved=0

thanks,

--
heikki

#9 lore raw

Hi,

Quoted 17 lines · Jun Li
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access
dwc3 core instance struct, right?

for now, maybe. But it may be better to implement a notifier method in role switch class.

Quoted 8 lines
Quoted 2 lines

I am not sure if introduce notifier in role switch class is a good idea, I had the impression extcon is not encouraged to use if possible.

I'm not against role switch notifiers. They were proposed before already couple of years ago, but at that time there just were no users them notifier, so the patch was just dropped from the series [1].
But I don't think anybody was against the idea. Please feel free to add them to the class if you have use for them.

Quoted 5 lines

So I had the incorrect impression.

Yes, that's the Felipe was referring to, I think.

I will pick up [1] and improve my driver as Felipe suggested.

sounds great, thahnks Li Jun

Signature · 1 line
balbi
author
#10 lore raw

Hi,

Quoted 32 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Tuesday, May 11, 2021 5:27 PM
To: Jun Li <[email protected]>; Heikki Krogerus <[email protected]>
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: RE: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Hi,

Quoted 17 lines · Jun Li
Quoted 16 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access
dwc3 core instance struct, right?

for now, maybe. But it may be better to implement a notifier method in role switch class.

I am not sure if introduce notifier in role switch class is a good idea, I had the impression extcon is not encouraged to use if possible.

I'm not against role switch notifiers. They were proposed before already couple of years ago, but at that time there just were no users them notifier, so the patch was just dropped from the series [1]. But I don't think anybody was against the idea. Please feel free to add them to the class if you have use for them.

Quoted 7 lines
Quoted 5 lines

So I had the incorrect impression.

Yes, that's the Felipe was referring to, I think.

I will pick up [1] and improve my driver as Felipe suggested.

sounds great, thahnks Li Jun

Got chance to check this, but it turns out this glue driver still has to be care of the dwc3 core and its probe completion, because the role switch class is created by dwc3 core in its probe.

dev_pm_set_dedicated_wake_irq() is a good solution for case a sperate/glue driver is not required, in my imx8mp case, I need a glue driver anyway, so this seems can't make my driver much simpler. Rough change please see below:

arch/arm64/boot/dts/freescale/imx8mp.dtsi +6 -4
index 9f7c7f587d38..bcb63bcf27be 100644
@@ -874,7 +874,6 @@ usb3_0: usb@32f10100 {
 			clocks = <&clk IMX8MP_CLK_HSIO_ROOT>,
 				 <&clk IMX8MP_CLK_USB_ROOT>;
 			clock-names = "hsio", "suspend";
-			interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
 			#address-cells = <1>;
 			#size-cells = <1>;
 			dma-ranges = <0x40000000 0x40000000 0xc0000000>;
@@ -891,7 +890,9 @@ usb_dwc3_0: usb@38100000 {
 				assigned-clocks = <&clk IMX8MP_CLK_HSIO_AXI>;
 				assigned-clock-parents = <&clk IMX8MP_SYS_PLL2_500M>;
 				assigned-clock-rates = <500000000>;
-				interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
+				interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>,
+							<GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-names = "irq", "wakeup";
 				phys = <&usb3_phy0>, <&usb3_phy0>;
 				phy-names = "usb2-phy", "usb3-phy";
 				snps,dis-u2-freeclk-exists-quirk;
@@ -915,7 +916,6 @@ usb3_1: usb@32f10108 {
 			clocks = <&clk IMX8MP_CLK_HSIO_ROOT>,
 				 <&clk IMX8MP_CLK_USB_ROOT>;
 			clock-names = "hsio", "suspend";
-			interrupts = <GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
 			#address-cells = <1>;
 			#size-cells = <1>;
 			dma-ranges = <0x40000000 0x40000000 0xc0000000>;
@@ -932,7 +932,9 @@ usb_dwc3_1: usb@38200000 {
 				assigned-clocks = <&clk IMX8MP_CLK_HSIO_AXI>;
 				assigned-clock-parents = <&clk IMX8MP_SYS_PLL2_500M>;
 				assigned-clock-rates = <500000000>;
-				interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>;
+				interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>,
+							<GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-names = "irq", "wakeup";
 				phys = <&usb3_phy1>, <&usb3_phy1>;
 				phy-names = "usb2-phy", "usb3-phy";
 				snps,dis-u2-freeclk-exists-quirk;
drivers/usb/dwc3/core.c +6 -0
index b6871ee5e8ca..4dac7cd98a31 100644
@@ -1615,6 +1615,12 @@ static int dwc3_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	dwc->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
+	if (dwc->wakeup_irq == -EPROBE_DEFER)
+		goto assert_reset;
+	else
+		dev_err(dwc->dev, "the wakeup irq No. is %d\n", dwc->wakeup_irq);
+
 	ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks);
 	if (ret)
 		goto assert_reset;
drivers/usb/dwc3/core.h +2 -0
index 1c85f40a8dd8..264ae7def903 100644
@@ -32,6 +32,7 @@
 #include <linux/phy/phy.h>
 
 #include <linux/power_supply.h>
+#include <linux/pm_wakeirq.h>
 
 #define DWC3_MSG_MAX	500
 
@@ -1295,6 +1296,7 @@ struct dwc3 {
 	int			max_cfg_eps;
 	int			last_fifo_depth;
 	int			num_ep_resized;
+	int			wakeup_irq;
 };
 
 #define INCRX_BURST_MODE 0
drivers/usb/dwc3/dwc3-imx8mp.c +59 -70

226 lines not on this page · raw message

drivers/usb/dwc3/gadget.c +11 -0
index e56f1a6db2de..4ac9d262e608 100644
@@ -2666,6 +2666,16 @@ static int dwc3_gadget_start(struct usb_gadget *g,
 	dwc->gadget_driver	= driver;
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
+	if (dwc->wakeup_irq > 0) {
+		ret = dev_pm_set_dedicated_wake_irq(dwc->dev,
+						    dwc->wakeup_irq);
+		if (ret) {
+			dev_err(dwc->dev, "set wakeup irq %d failed\n",
+				dwc->wakeup_irq);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
@@ -2681,6 +2691,7 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 	struct dwc3		*dwc = gadget_to_dwc(g);
 	unsigned long		flags;
 
+	dev_pm_clear_wake_irq(dwc->dev);
 	spin_lock_irqsave(&dwc->lock, flags);
 	dwc->gadget_driver	= NULL;
 	dwc->max_cfg_eps = 0;
drivers/usb/dwc3/host.c +12 -0
index f29a264635aa..3df0523906e5 100644
@@ -121,6 +121,17 @@ int dwc3_host_init(struct dwc3 *dwc)
 		goto err;
 	}
 
+	if (dwc->wakeup_irq > 0) {
+		ret = dev_pm_set_dedicated_wake_irq(&xhci->dev,
+						    dwc->wakeup_irq);
+		if (ret) {
+			dev_err(dwc->dev, "set wakeup irq %d failed\n",
+				dwc->wakeup_irq);
+			goto err;
+		}
+		dev_err(&xhci->dev, "wakeup irq of xhci set OK.\n");
+	}
+
 	return 0;
 err:
 	platform_device_put(xhci);
@@ -129,5 +140,6 @@ int dwc3_host_init(struct dwc3 *dwc)
 
 void dwc3_host_exit(struct dwc3 *dwc)
 {
+	dev_pm_clear_wake_irq(&dwc->xhci->dev);
 	platform_device_unregister(dwc->xhci);
 }
Signature · 5 lines
2.25.1


Thanks
Li Jun
Quoted 3 lines

--
balbi

#11 lore raw

Hi,

Quoted 83 lines · Jun Li
Quoted 18 lines
Quoted 17 lines · Jun Li
Quoted 16 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access
dwc3 core instance struct, right?

for now, maybe. But it may be better to implement a notifier method in role switch class.

I am not sure if introduce notifier in role switch class is a good idea, I had the impression extcon is not encouraged to use if possible.

I'm not against role switch notifiers. They were proposed before already couple of years ago, but at that time there just were no users them notifier, so the patch was just dropped from the series [1]. But I don't think anybody was against the idea. Please feel free to add them to the class if you have use for them.

Quoted 7 lines
Quoted 5 lines

So I had the incorrect impression.

Yes, that's the Felipe was referring to, I think.

I will pick up [1] and improve my driver as Felipe suggested.

sounds great, thahnks Li Jun

Got chance to check this, but it turns out this glue driver still has to be care of the dwc3 core and its probe completion, because the role switch class is created by dwc3 core in its probe.

dev_pm_set_dedicated_wake_irq() is a good solution for case a sperate/glue driver is not required, in my imx8mp case, I need a glue driver anyway, so this seems can't make my driver much simpler. Rough change please see below:

arch/arm64/boot/dts/freescale/imx8mp.dtsi +6 -4
index 9f7c7f587d38..bcb63bcf27be 100644
@@ -874,7 +874,6 @@ usb3_0: usb@32f10100 {
 			clocks = <&clk IMX8MP_CLK_HSIO_ROOT>,
 				 <&clk IMX8MP_CLK_USB_ROOT>;
 			clock-names = "hsio", "suspend";
-			interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
 			#address-cells = <1>;
 			#size-cells = <1>;
 			dma-ranges = <0x40000000 0x40000000 0xc0000000>;
@@ -891,7 +890,9 @@ usb_dwc3_0: usb@38100000 {
 				assigned-clocks = <&clk IMX8MP_CLK_HSIO_AXI>;
 				assigned-clock-parents = <&clk IMX8MP_SYS_PLL2_500M>;
 				assigned-clock-rates = <500000000>;
-				interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
+				interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>,
+							<GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-names = "irq", "wakeup";
 				phys = <&usb3_phy0>, <&usb3_phy0>;
 				phy-names = "usb2-phy", "usb3-phy";
 				snps,dis-u2-freeclk-exists-quirk;
@@ -915,7 +916,6 @@ usb3_1: usb@32f10108 {
 			clocks = <&clk IMX8MP_CLK_HSIO_ROOT>,
 				 <&clk IMX8MP_CLK_USB_ROOT>;
 			clock-names = "hsio", "suspend";
-			interrupts = <GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
 			#address-cells = <1>;
 			#size-cells = <1>;
 			dma-ranges = <0x40000000 0x40000000 0xc0000000>;
@@ -932,7 +932,9 @@ usb_dwc3_1: usb@38200000 {
 				assigned-clocks = <&clk IMX8MP_CLK_HSIO_AXI>;
 				assigned-clock-parents = <&clk IMX8MP_SYS_PLL2_500M>;
 				assigned-clock-rates = <500000000>;
-				interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>;
+				interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>,
+							<GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-names = "irq", "wakeup";
 				phys = <&usb3_phy1>, <&usb3_phy1>;
 				phy-names = "usb2-phy", "usb3-phy";
 				snps,dis-u2-freeclk-exists-quirk;
drivers/usb/dwc3/core.c +0 -0
index b6871ee5e8ca..4dac7cd98a31 100644

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 1622

Quoted 8 lines
drivers/usb/dwc3/core.c +5 -0
@@ -1615,6 +1615,12 @@ static int dwc3_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	dwc->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
+	if (dwc->wakeup_irq == -EPROBE_DEFER)
+		goto assert_reset;
+	else
+		dev_err(dwc->dev, "the wakeup irq No. is %d\n", dwc->wakeup_irq);

why is this an error?

Signature · 1 line
balbi
author
#12 lore raw
Quoted 106 lines

-----Original Message-----
From: Felipe Balbi <[email protected]>
Sent: Monday, August 2, 2021 3:49 PM
To: Jun Li <[email protected]>
Cc: Heikki Krogerus <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] usb: dwc3: imx8mp: detect dwc3 core node via compatible string

Hi,

Quoted 11 lines · Jun Li
Quoted 11 lines
Quoted 10 lines · Jun Li
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Good suggestion, but if extcon notifier listener can't work for me, my understanding is this *teach* in glue layer driver still need access
dwc3 core instance struct, right?

for now, maybe. But it may be better to implement a notifier method in role switch class.

I am not sure if introduce notifier in role switch class is a good idea, I had the impression extcon is not encouraged to use if

possible.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I'm not against role switch notifiers. They were proposed before already couple of years ago, but at that time there just were no users them notifier, so the patch was just dropped from the series

[1].

Quoted 34 lines
Quoted 10 lines
Quoted 8 lines
Quoted 2 lines

But I don't think anybody was against the idea. Please feel free to add them to the class if you have use for them.

So I had the incorrect impression.

Yes, that's the Felipe was referring to, I think.

I will pick up [1] and improve my driver as Felipe suggested.

sounds great, thahnks Li Jun

Got chance to check this, but it turns out this glue driver still has to be care of the dwc3 core and its probe completion, because the role switch class is created by dwc3 core in its probe.

dev_pm_set_dedicated_wake_irq() is a good solution for case a sperate/glue driver is not required, in my imx8mp case, I need a glue driver anyway, so this seems can't make my driver much simpler. Rough change please see below:

arch/arm64/boot/dts/freescale/imx8mp.dtsi +0 -1
index 9f7c7f587d38..bcb63bcf27be 100644
@@ -874,7 +874,6 @@ usb3_0: usb@32f10100 {
 			clocks = <&clk IMX8MP_CLK_HSIO_ROOT>,
 				 <&clk IMX8MP_CLK_USB_ROOT>;
 			clock-names = "hsio", "suspend";
-			interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
 			#address-cells = <1>;
 			#size-cells = <1>;
 			dma-ranges = <0x40000000 0x40000000 0xc0000000>; @@ -891,7 +890,9

@@ usb_dwc3_0: usb@38100000 {

arch/arm64/boot/dts/freescale/imx8mp.dtsi usb_dwc3_0: usb@38100000 {

Quoted 10 lines
arch/arm64/boot/dts/freescale/imx8mp.dtsi +3 -1
 				assigned-clocks = <&clk IMX8MP_CLK_HSIO_AXI>;
 				assigned-clock-parents = <&clk IMX8MP_SYS_PLL2_500M>;
 				assigned-clock-rates = <500000000>;
-				interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
+				interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>,
+							<GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-names = "irq", "wakeup";
 				phys = <&usb3_phy0>, <&usb3_phy0>;
 				phy-names = "usb2-phy", "usb3-phy";
 				snps,dis-u2-freeclk-exists-quirk; @@ -915,7 +916,6 @@

usb3_1:

Quoted 27 lines

usb@32f10108 {

arch/arm64/boot/dts/freescale/imx8mp.dtsi +0 -1
 			clocks = <&clk IMX8MP_CLK_HSIO_ROOT>,
 				 <&clk IMX8MP_CLK_USB_ROOT>;
 			clock-names = "hsio", "suspend";
-			interrupts = <GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
 			#address-cells = <1>;
 			#size-cells = <1>;
 			dma-ranges = <0x40000000 0x40000000 0xc0000000>; @@ -932,7 +932,9

@@ usb_dwc3_1: usb@38200000 {

arch/arm64/boot/dts/freescale/imx8mp.dtsi +3 -1
 				assigned-clocks = <&clk IMX8MP_CLK_HSIO_AXI>;
 				assigned-clock-parents = <&clk IMX8MP_SYS_PLL2_500M>;
 				assigned-clock-rates = <500000000>;
-				interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>;
+				interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>,
+							<GIC_SPI 149 IRQ_TYPE_LEVEL_HIGH>;
+				interrupt-names = "irq", "wakeup";
 				phys = <&usb3_phy1>, <&usb3_phy1>;
 				phy-names = "usb2-phy", "usb3-phy";
 				snps,dis-u2-freeclk-exists-quirk; diff --git

a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index b6871ee5e8ca..4dac7cd98a31 100644

drivers/usb/dwc3/core.c +0 -0
@@ -1615,6 +1615,12 @@ static int dwc3_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
Quoted 7 lines

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 1622

Quoted 5 lines
drivers/usb/dwc3/core.c +5 -0
+	dwc->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup");
+	if (dwc->wakeup_irq == -EPROBE_DEFER)
+		goto assert_reset;
+	else
+		dev_err(dwc->dev, "the wakeup irq No. is %d\n", dwc->wakeup_irq);

why is this an error?

Forget to remove this debug purpose log, sorry.

Li Jun

Quoted 3 lines

--
balbi