diff mbox series

usb: common: usb-conn-gpio: Allow wakeup from system suspend

Message ID 1653634146-12215-1-git-send-email-quic_prashk@quicinc.com (mailing list archive)
State Accepted
Commit 7afe69ad9221a77dc782b81f49cd7f99987740ed
Headers show
Series usb: common: usb-conn-gpio: Allow wakeup from system suspend | expand

Commit Message

Prashanth K May 27, 2022, 6:49 a.m. UTC
Currently the VBUS/ID detection interrupts are disabled during system
suspend. So the USB cable connect/disconnect event can't wakeup the
system from low power mode. To allow this, we keep these interrupts
enabled and configure them as wakeup capable. This behavior can be
controlled through device wakeup source policy by the user space.

Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
---
 drivers/usb/common/usb-conn-gpio.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Pavan Kondeti May 27, 2022, 8:56 a.m. UTC | #1
On Fri, May 27, 2022 at 12:19:06PM +0530, Prashanth K wrote:
> Currently the VBUS/ID detection interrupts are disabled during system
> suspend. So the USB cable connect/disconnect event can't wakeup the
> system from low power mode. To allow this, we keep these interrupts
> enabled and configure them as wakeup capable. This behavior can be
> controlled through device wakeup source policy by the user space.
> 
> Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
> ---
>  drivers/usb/common/usb-conn-gpio.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c
> index 395f9bb..b39c9f1c 100644
> --- a/drivers/usb/common/usb-conn-gpio.c
> +++ b/drivers/usb/common/usb-conn-gpio.c
> @@ -257,6 +257,7 @@ static int usb_conn_probe(struct platform_device *pdev)
>  	}
>  
>  	platform_set_drvdata(pdev, info);
> +	device_set_wakeup_capable(&pdev->dev, true);
>  
>  	/* Perform initial detection */
>  	usb_conn_queue_dwork(info, 0);
> @@ -286,6 +287,14 @@ static int __maybe_unused usb_conn_suspend(struct device *dev)
>  {
>  	struct usb_conn_info *info = dev_get_drvdata(dev);
>  
> +	if (device_may_wakeup(dev)) {
> +		if (info->id_gpiod)
> +			enable_irq_wake(info->id_irq);
> +		if (info->vbus_gpiod)
> +			enable_irq_wake(info->vbus_irq);
> +		return 0;
> +	}
> +
>  	if (info->id_gpiod)
>  		disable_irq(info->id_irq);
>  	if (info->vbus_gpiod)
> @@ -300,6 +309,14 @@ static int __maybe_unused usb_conn_resume(struct device *dev)
>  {
>  	struct usb_conn_info *info = dev_get_drvdata(dev);
>  
> +	if (device_may_wakeup(dev)) {
> +		if (info->id_gpiod)
> +			disable_irq_wake(info->id_irq);
> +		if (info->vbus_gpiod)
> +			disable_irq_wake(info->vbus_irq);
> +		return 0;
> +	}
> +
>  	pinctrl_pm_select_default_state(dev);
>  
>  	if (info->id_gpiod)

Looks good to me.

Thanks,
Pavan
diff mbox series

Patch

diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c
index 395f9bb..b39c9f1c 100644
--- a/drivers/usb/common/usb-conn-gpio.c
+++ b/drivers/usb/common/usb-conn-gpio.c
@@ -257,6 +257,7 @@  static int usb_conn_probe(struct platform_device *pdev)
 	}
 
 	platform_set_drvdata(pdev, info);
+	device_set_wakeup_capable(&pdev->dev, true);
 
 	/* Perform initial detection */
 	usb_conn_queue_dwork(info, 0);
@@ -286,6 +287,14 @@  static int __maybe_unused usb_conn_suspend(struct device *dev)
 {
 	struct usb_conn_info *info = dev_get_drvdata(dev);
 
+	if (device_may_wakeup(dev)) {
+		if (info->id_gpiod)
+			enable_irq_wake(info->id_irq);
+		if (info->vbus_gpiod)
+			enable_irq_wake(info->vbus_irq);
+		return 0;
+	}
+
 	if (info->id_gpiod)
 		disable_irq(info->id_irq);
 	if (info->vbus_gpiod)
@@ -300,6 +309,14 @@  static int __maybe_unused usb_conn_resume(struct device *dev)
 {
 	struct usb_conn_info *info = dev_get_drvdata(dev);
 
+	if (device_may_wakeup(dev)) {
+		if (info->id_gpiod)
+			disable_irq_wake(info->id_irq);
+		if (info->vbus_gpiod)
+			disable_irq_wake(info->vbus_irq);
+		return 0;
+	}
+
 	pinctrl_pm_select_default_state(dev);
 
 	if (info->id_gpiod)