diff mbox series

[2/2] gpio: davinci: handle wakeup-source property, detect wake IRQs

Message ID 20240718000935.2573288-3-khilman@baylibre.com
State New
Headers show
Series gpio: davinci: improve wakeup capabilities | expand

Commit Message

Kevin Hilman July 18, 2024, 12:09 a.m. UTC
If the wakeup-source property is used for the GPIO controller, then
mark the controller as wakeup capable.

Further, if there are any GPIO IRQs that are marked as wakeup-enabled,
then mark the GPIO controller as wakeup enabled also.  Since the GPIO
IRQs that are wake-enabled are dynamic, this is (re)calculated during
each suspend (and cleared on resume.)

Signed-off-by: Kevin Hilman <khilman@baylibre.com>
---
 drivers/gpio/gpio-davinci.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Dhruva Gole July 18, 2024, 5:35 a.m. UTC | #1
On Jul 17, 2024 at 17:09:33 -0700, Kevin Hilman wrote:
> If the wakeup-source property is used for the GPIO controller, then
> mark the controller as wakeup capable.
> 
> Further, if there are any GPIO IRQs that are marked as wakeup-enabled,
> then mark the GPIO controller as wakeup enabled also.  Since the GPIO
> IRQs that are wake-enabled are dynamic, this is (re)calculated during
> each suspend (and cleared on resume.)
> 
> Signed-off-by: Kevin Hilman <khilman@baylibre.com>
> ---
>  drivers/gpio/gpio-davinci.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
> index 1d0175d6350b..031aa7c30855 100644
> --- a/drivers/gpio/gpio-davinci.c
> +++ b/drivers/gpio/gpio-davinci.c
> @@ -7,6 +7,7 @@
>   */
>  
>  #include <linux/gpio/driver.h>
> +#include <linux/gpio/consumer.h>

Please sort this...

[...]

With that taken care,
Reviewed-by: Dhruva Gole <d-gole@ti.com>
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 1d0175d6350b..031aa7c30855 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -7,6 +7,7 @@ 
  */
 
 #include <linux/gpio/driver.h>
+#include <linux/gpio/consumer.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <linux/clk.h>
@@ -195,6 +196,7 @@  static int davinci_gpio_probe(struct platform_device *pdev)
 	struct davinci_gpio_controller *chips;
 	struct davinci_gpio_platform_data *pdata;
 	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
 
 	pdata = davinci_gpio_get_pdata(pdev);
 	if (!pdata) {
@@ -274,6 +276,9 @@  static int davinci_gpio_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	if (of_property_read_bool(np, "wakeup-source"))
+		device_set_wakeup_capable(dev, true);
+
 	return 0;
 }
 
@@ -677,7 +682,24 @@  static int davinci_gpio_suspend(struct device *dev)
 	struct davinci_gpio_controller *chips = dev_get_drvdata(dev);
 	struct davinci_gpio_platform_data *pdata = dev_get_platdata(dev);
 	u32 nbank = DIV_ROUND_UP(pdata->ngpio, 32);
+	struct gpio_chip *chip = &chips->chip;
+	struct gpio_desc *desc;
+	bool wkup_set;
+	int irq;
 
+	/*
+	 * Check if any GPIO IRQs are wakeup enabled.  If so,
+	 * set the GPIO controller as wakeup enabled also.
+	 */
+	for_each_gpio_desc(chip, desc) {
+		irq = gpiod_to_irq(desc);
+		wkup_set = irqd_is_wakeup_set(irq_get_irq_data(irq));
+		if (wkup_set) {
+			dev_dbg(dev, "%s: IRQ %d wakeup enabled.", __func__, irq);
+			device_wakeup_enable(dev);
+			break;
+		}
+	}
 	davinci_gpio_save_context(chips, nbank);
 
 	return 0;
@@ -691,6 +713,9 @@  static int davinci_gpio_resume(struct device *dev)
 
 	davinci_gpio_restore_context(chips, nbank);
 
+	if (device_may_wakeup(dev))
+		device_wakeup_disable(dev);
+
 	return 0;
 }