Skip to contentSkip to conversation

gpio: davinci: improve wakeup capabilities

PATCH In review Kevin Hilman 2 participants 5 messages Jul 18, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio: davinci: improve wakeup capabilities

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(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 gpiolib: expose for_each_gpio_desc() to drivers

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.

---
 drivers/gpio/gpiolib.h      | 5 -----
 include/linux/gpio/driver.h | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpio/gpiolib.h +0 -5
index 48e086c2f416..c68be135e137 100644
@@ -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
include/linux/gpio/driver.h +5 -0
index 0032bb6e7d8f..3e7e58be31b4 100644
@@ -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>
Signature · 1 line
2.45.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] gpiolib: expose for_each_gpio_desc() to drivers

Quoted 6 lines · Kevin Hilman

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.

---

Signature · 2 lines
Best regards,
Dhruva
#3 lore raw

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

In reply to Kevin Hilman

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.)

---
 drivers/gpio/gpio-davinci.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/gpio/gpio-davinci.c +25 -0
index 1d0175d6350b..031aa7c30855 100644
@@ -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;
 }
 
Signature · 1 line
2.45.2
Reviewed-by on v1 2/2
#4 lore raw

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

Quoted 18 lines · Kevin Hilman

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.)

---
 drivers/gpio/gpio-davinci.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
drivers/gpio/gpio-davinci.c +0 -0
index 1d0175d6350b..031aa7c30855 100644

drivers/gpio/gpio-davinci.c line 10

Quoted 4 lines
drivers/gpio/gpio-davinci.c +1 -0
@@ -7,6 +7,7 @@
  */
 
 #include <linux/gpio/driver.h>
+#include <linux/gpio/consumer.h>

Please sort this...

[...]

With that taken care,

Signature · 2 lines
Best regards,
Dhruva