public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] gpio: davinci: improve wakeup capabilities
@ 2024-07-18  0:09 Kevin Hilman
  2024-07-18  0:09 ` [PATCH 1/2] gpiolib: expose for_each_gpio_desc() to drivers Kevin Hilman
  2024-07-18  0:09 ` [PATCH 2/2] gpio: davinci: handle wakeup-source property, detect wake IRQs Kevin Hilman
  0 siblings, 2 replies; 5+ messages in thread
From: Kevin Hilman @ 2024-07-18  0:09 UTC (permalink / raw)
  To: linux-gpio; +Cc: Keerthy

Improve wakeup capabilities in the gpio-davinci driver by properly
handling the "wakeup-source" property from DT, but also by keeping
track of any wake-enabled IRQs.

Kevin Hilman (2):
  gpiolib: expose for_each_gpio_desc() to drivers
  gpio: davinci: handle wakeup-source property, detect wake IRQs

 drivers/gpio/gpio-davinci.c | 25 +++++++++++++++++++++++++
 drivers/gpio/gpiolib.h      |  5 -----
 include/linux/gpio/driver.h |  5 +++++
 3 files changed, 30 insertions(+), 5 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] gpiolib: expose for_each_gpio_desc() to drivers
  2024-07-18  0:09 [PATCH 0/2] gpio: davinci: improve wakeup capabilities Kevin Hilman
@ 2024-07-18  0:09 ` Kevin Hilman
  2024-07-18  4:52   ` Dhruva Gole
  2024-07-18  0:09 ` [PATCH 2/2] gpio: davinci: handle wakeup-source property, detect wake IRQs Kevin Hilman
  1 sibling, 1 reply; 5+ messages in thread
From: Kevin Hilman @ 2024-07-18  0:09 UTC (permalink / raw)
  To: linux-gpio; +Cc: Keerthy, Linus Walleij, Bartosz Golaszewski, open list

The for_each_gpio_desc() iterator is a convenient helper and is also
useful for GPIO controller drivers.  Move this helper from the
internal gpiolib.h to driver.h.

Signed-off-by: Kevin Hilman <khilman@baylibre.com>
---
 drivers/gpio/gpiolib.h      | 5 -----
 include/linux/gpio/driver.h | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 48e086c2f416..c68be135e137 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -115,11 +115,6 @@ struct gpio_array {
 	unsigned long		invert_mask[];
 };
 
-#define for_each_gpio_desc(gc, desc)					\
-	for (unsigned int __i = 0;					\
-	     __i < gc->ngpio && (desc = gpiochip_get_desc(gc, __i));	\
-	     __i++)							\
-
 #define for_each_gpio_desc_with_flag(gc, desc, flag)			\
 	for_each_gpio_desc(gc, desc)					\
 		if (!test_bit(flag, &desc->flags)) {} else
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 0032bb6e7d8f..3e7e58be31b4 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -813,6 +813,11 @@ const char *gpio_device_get_label(struct gpio_device *gdev);
 struct gpio_device *gpio_device_find_by_label(const char *label);
 struct gpio_device *gpio_device_find_by_fwnode(const struct fwnode_handle *fwnode);
 
+#define for_each_gpio_desc(gc, desc)					\
+	for (unsigned int __i = 0;					\
+	     __i < gc->ngpio && (desc = gpiochip_get_desc(gc, __i));	\
+	     __i++)							\
+
 #else /* CONFIG_GPIOLIB */
 
 #include <asm/bug.h>
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] gpio: davinci: handle wakeup-source property, detect wake IRQs
  2024-07-18  0:09 [PATCH 0/2] gpio: davinci: improve wakeup capabilities Kevin Hilman
  2024-07-18  0:09 ` [PATCH 1/2] gpiolib: expose for_each_gpio_desc() to drivers Kevin Hilman
@ 2024-07-18  0:09 ` Kevin Hilman
  2024-07-18  5:35   ` Dhruva Gole
  1 sibling, 1 reply; 5+ messages in thread
From: Kevin Hilman @ 2024-07-18  0:09 UTC (permalink / raw)
  To: linux-gpio; +Cc: Keerthy, Linus Walleij, Bartosz Golaszewski, open list

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>
 #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;
 }
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] gpiolib: expose for_each_gpio_desc() to drivers
  2024-07-18  0:09 ` [PATCH 1/2] gpiolib: expose for_each_gpio_desc() to drivers Kevin Hilman
@ 2024-07-18  4:52   ` Dhruva Gole
  0 siblings, 0 replies; 5+ messages in thread
From: Dhruva Gole @ 2024-07-18  4:52 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: linux-gpio, Keerthy, Linus Walleij, Bartosz Golaszewski,
	open list

On Jul 17, 2024 at 17:09:32 -0700, Kevin Hilman wrote:
> The for_each_gpio_desc() iterator is a convenient helper and is also
> useful for GPIO controller drivers.  Move this helper from the
> internal gpiolib.h to driver.h.
> 
> Signed-off-by: Kevin Hilman <khilman@baylibre.com>
> ---

Reviewed-by: Dhruva Gole <d-gole@ti.com>

-- 
Best regards,
Dhruva

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] gpio: davinci: handle wakeup-source property, detect wake IRQs
  2024-07-18  0:09 ` [PATCH 2/2] gpio: davinci: handle wakeup-source property, detect wake IRQs Kevin Hilman
@ 2024-07-18  5:35   ` Dhruva Gole
  0 siblings, 0 replies; 5+ messages in thread
From: Dhruva Gole @ 2024-07-18  5:35 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: linux-gpio, Keerthy, Linus Walleij, Bartosz Golaszewski,
	open list

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>

-- 
Best regards,
Dhruva

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-07-18  5:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-18  0:09 [PATCH 0/2] gpio: davinci: improve wakeup capabilities Kevin Hilman
2024-07-18  0:09 ` [PATCH 1/2] gpiolib: expose for_each_gpio_desc() to drivers Kevin Hilman
2024-07-18  4:52   ` Dhruva Gole
2024-07-18  0:09 ` [PATCH 2/2] gpio: davinci: handle wakeup-source property, detect wake IRQs Kevin Hilman
2024-07-18  5:35   ` Dhruva Gole

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox