All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xu Yang <xu.yang_2@nxp.com>
To: peter.chen@kernel.org
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-imx@nxp.com, jun.li@nxp.com
Subject: [PATCH] usb: chipidea: core: complement wakeup support for usb role switch
Date: Fri, 12 Aug 2022 18:57:19 +0800	[thread overview]
Message-ID: <20220812105719.143556-1-xu.yang_2@nxp.com> (raw)

In current design, ci_usb_role_switch_set() will call pm_runtime_get_sync()
firstly, then handle role switch events. But pm_runtime_get_sync() may fail
to resume controller sometimes. This may happen when doing system suspend
and enabled typec wakeup source as below:
  1. starting system suspend, controller is suspended by runtime pm before.
  2. somehow controller get resumed by runtime pm.
  3. ci_suspend() is called. runtime_status = RPM_ACTIVE now.
  4. ci_usb_role_switch_set() is called due to role switch events.
  5. pm_runtime_get_sync() return 1.

This is because pm.runtime_status is still RPM_ACTIVE after ci_suspend().
Then the driver execute wakeup operations in ci_irq(). So there is a need
to call ci_irq() again like extcon do.

Fixes: 876d4e1e8298 ("usb: chipidea: core: add wakeup support for extcon")
Cc: <stable@vger.kernel.org>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/chipidea/core.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 6330fa911792..886b68e45826 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -1305,12 +1305,14 @@ static void ci_extcon_wakeup_int(struct ci_hdrc *ci)
 	cable_id = &ci->platdata->id_extcon;
 	cable_vbus = &ci->platdata->vbus_extcon;
 
-	if (!IS_ERR(cable_id->edev) && ci->is_otg &&
-		(otgsc & OTGSC_IDIE) && (otgsc & OTGSC_IDIS))
+	if ((!IS_ERR(cable_id->edev) || !IS_ERR(ci->role_switch))
+		&& ci->is_otg && (otgsc & OTGSC_IDIE)
+		&& (otgsc & OTGSC_IDIS))
 		ci_irq(ci);
 
-	if (!IS_ERR(cable_vbus->edev) && ci->is_otg &&
-		(otgsc & OTGSC_BSVIE) && (otgsc & OTGSC_BSVIS))
+	if ((!IS_ERR(cable_vbus->edev) || !IS_ERR(ci->role_switch))
+		&& ci->is_otg && (otgsc & OTGSC_BSVIE)
+		&& (otgsc & OTGSC_BSVIS))
 		ci_irq(ci);
 }
 
-- 
2.25.1


             reply	other threads:[~2022-08-12 11:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12 10:57 Xu Yang [this message]
2022-08-18 22:43 ` [PATCH] usb: chipidea: core: complement wakeup support for usb role switch Peter Chen
2022-08-20 14:05   ` Jun Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220812105719.143556-1-xu.yang_2@nxp.com \
    --to=xu.yang_2@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jun.li@nxp.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.chen@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.