public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>
To: Loic Poulain <loic.poulain@linaro.org>
Cc: robh@kernel.org, jirislaby@kernel.org,
	gregkh@linuxfoundation.org, linux-serial@vger.kernel.org,
	manjeet.gupta@nxp.com, amitkumar.karwar@nxp.com
Subject: Re: [PATCH] serdev: Add support for wakeup-source
Date: Fri, 21 Mar 2025 18:54:35 +0530	[thread overview]
Message-ID: <20250321132435.GA442087@PE-DT639> (raw)
In-Reply-To: <20250213143430.3893651-1-loic.poulain@linaro.org>

Hi Loic,

Thank you for the patch.

I have verified this patch with btnxpuart driver and I am able to wakeup the host with a GPIO interrupt signal from BT controller.

Tested-by: Neeraj Sanjay Kale <neeraj.sanjaykale@nxp.com>

Thanks,
Neeraj

On Thu, Feb 13, 2025 at 03:34:30PM +0100, Loic Poulain wrote:
> This brings support for dedicated interrupt as wakeup source into the
> serdev core, similarly to the I2C bus, and aligned with the documentation:
> Documentation/devicetree/bindings/power/wakeup-source.txt
> 
> As an example, this can be used for bluetooth serial devices with dedicated
> controller-to-host wakeup pin.
> 
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
> ---
>  drivers/tty/serdev/core.c | 48 +++++++++++++++++++++++++++++++++++++--
>  include/linux/serdev.h    |  1 +
>  2 files changed, 47 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
> index ebf0bbc2cff2..2d016fa546ca 100644
> --- a/drivers/tty/serdev/core.c
> +++ b/drivers/tty/serdev/core.c
> @@ -13,8 +13,10 @@
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
> +#include <linux/of_irq.h>
>  #include <linux/pm_domain.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/pm_wakeirq.h>
>  #include <linux/property.h>
>  #include <linux/sched.h>
>  #include <linux/serdev.h>
> @@ -164,6 +166,9 @@ int serdev_device_open(struct serdev_device *serdev)
>  		goto err_close;
>  	}
>  
> +	if (serdev->wakeup_source)
> +		device_wakeup_enable(&serdev->dev);
> +
>  	return 0;
>  
>  err_close:
> @@ -181,6 +186,9 @@ void serdev_device_close(struct serdev_device *serdev)
>  	if (!ctrl || !ctrl->ops->close)
>  		return;
>  
> +	if (serdev->wakeup_source)
> +		device_wakeup_disable(&serdev->dev);
> +
>  	pm_runtime_put(&ctrl->dev);
>  
>  	ctrl->ops->close(ctrl);
> @@ -406,18 +414,52 @@ int serdev_device_break_ctl(struct serdev_device *serdev, int break_state)
>  }
>  EXPORT_SYMBOL_GPL(serdev_device_break_ctl);
>  
> +static int serdev_wakeup_attach(struct device *dev)
> +{
> +	int wakeirq;
> +
> +	if (!of_property_read_bool(dev->of_node, "wakeup-source"))
> +		return 0;
> +
> +	to_serdev_device(dev)->wakeup_source = true;
> +
> +	device_set_wakeup_capable(dev, true);
> +
> +	wakeirq = of_irq_get_byname(dev->of_node, "wakeup");
> +	if (wakeirq == -EPROBE_DEFER)
> +		return -EPROBE_DEFER;
> +	else if (wakeirq > 0)
> +		return dev_pm_set_dedicated_wake_irq(dev, wakeirq);
> +
> +	return 0;
> +}
> +
> +static void serdev_wakeup_detach(struct device *dev)
> +{
> +	device_init_wakeup(dev, false);
> +	dev_pm_clear_wake_irq(dev);
> +}
> +
>  static int serdev_drv_probe(struct device *dev)
>  {
>  	const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver);
>  	int ret;
>  
> -	ret = dev_pm_domain_attach(dev, true);
> +	ret = serdev_wakeup_attach(dev);
>  	if (ret)
>  		return ret;
>  
> +	ret = dev_pm_domain_attach(dev, true);
> +	if (ret) {
> +		serdev_wakeup_detach(dev);
> +		return ret;
> +	}
> +
>  	ret = sdrv->probe(to_serdev_device(dev));
> -	if (ret)
> +	if (ret) {
>  		dev_pm_domain_detach(dev, true);
> +		serdev_wakeup_detach(dev);
> +	}
>  
>  	return ret;
>  }
> @@ -429,6 +471,8 @@ static void serdev_drv_remove(struct device *dev)
>  		sdrv->remove(to_serdev_device(dev));
>  
>  	dev_pm_domain_detach(dev, true);
> +
> +	serdev_wakeup_detach(dev);
>  }
>  
>  static const struct bus_type serdev_bus_type = {
> diff --git a/include/linux/serdev.h b/include/linux/serdev.h
> index ff78efc1f60d..2b3ee7b2c141 100644
> --- a/include/linux/serdev.h
> +++ b/include/linux/serdev.h
> @@ -47,6 +47,7 @@ struct serdev_device {
>  	const struct serdev_device_ops *ops;
>  	struct completion write_comp;
>  	struct mutex write_lock;
> +	bool wakeup_source;
>  };
>  
>  static inline struct serdev_device *to_serdev_device(struct device *d)
> -- 
> 2.34.1
> 

  reply	other threads:[~2025-03-21 13:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-13 14:34 [PATCH] serdev: Add support for wakeup-source Loic Poulain
2025-03-21 13:24 ` Neeraj Sanjay Kale [this message]
2025-04-07 13:29   ` Neeraj Sanjay Kale
2025-04-08 13:09 ` Rob Herring

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=20250321132435.GA442087@PE-DT639 \
    --to=neeraj.sanjaykale@nxp.com \
    --cc=amitkumar.karwar@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=manjeet.gupta@nxp.com \
    --cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox