* [RFC][PATCH] gpiolib: add irq_wake (power-management) sysfs file
@ 2011-11-09 16:01 Patrick Combes
2011-11-10 18:50 ` Kevin Hilman
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Combes @ 2011-11-09 16:01 UTC (permalink / raw)
To: david-b, tony, linux-omap
Cc: b-cousson, f-mazard, dmurphy, Hugo Dupras, Patrick Combes
From: Hugo Dupras <h-dupras@ti.com>
By calling poll() on the /sys/class/gpio/gpioN/value sysfs file, usermode
application can take benefit of gpio interrupts.
However, depending on the power state reached, this interrupt may not wake-up
the CPU.
This patch creates a new sysfs file /sys/class/gpio/gpioN/irq_wake to enable
usermode application to set the wake properties of a gpio IRQ.
This option can be set or not for each gpio to preserve power consumption (e.g
embedded systems).
Signed-off-by: Hugo Dupras <h-dupras@ti.com>
Signed-off-by: Patrick Combes <p-combes@ti.com>
---
drivers/gpio/gpiolib.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a971e3d..cf03aed 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -543,6 +543,55 @@ static ssize_t gpio_active_low_store(struct device *dev,
static const DEVICE_ATTR(active_low, 0644,
gpio_active_low_show, gpio_active_low_store);
+static ssize_t gpio_irq_wake_store(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t size)
+{
+ const struct gpio_desc *desc = dev_get_drvdata(dev);
+ unsigned gpio = desc - gpio_desc;
+ ssize_t status;
+
+ mutex_lock(&sysfs_lock);
+
+ if (!test_bit(FLAG_EXPORT, &desc->flags))
+ status = -EIO;
+ else if (sysfs_streq(buf, "enable") || sysfs_streq(buf, "1"))
+ status = enable_irq_wake(gpio_to_irq(gpio));
+ else if (sysfs_streq(buf, "disable") || sysfs_streq(buf, "0"))
+ status = disable_irq_wake(gpio_to_irq(gpio));
+ else
+ status = -EINVAL;
+
+ mutex_unlock(&sysfs_lock);
+
+ return status ? : size;
+}
+
+static ssize_t gpio_irq_wake_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ const struct gpio_desc *desc = dev_get_drvdata(dev);
+ unsigned gpio = desc - gpio_desc;
+ int irq = gpio_to_irq(gpio);
+ ssize_t status;
+ struct irq_data *gpio_irq_data = irq_get_irq_data(irq);
+
+ mutex_lock(&sysfs_lock);
+
+ if (gpio_irq_data)
+ status = sprintf(buf, " Wakeup %s\n",
+ irqd_is_wakeup_set(gpio_irq_data)
+ ? " enable" : "disable");
+ else
+ status = -EINVAL;
+
+ mutex_unlock(&sysfs_lock);
+
+ return status;
+}
+
+static const DEVICE_ATTR(irq_wake, 0644,
+ gpio_irq_wake_show, gpio_irq_wake_store);
+
static const struct attribute *gpio_attrs[] = {
&dev_attr_value.attr,
&dev_attr_active_low.attr,
@@ -744,9 +793,13 @@ int gpio_export(unsigned gpio, bool direction_may_change)
if (!status && gpio_to_irq(gpio) >= 0
&& (direction_may_change
|| !test_bit(FLAG_IS_OUT,
- &desc->flags)))
+ &desc->flags))) {
status = device_create_file(dev,
&dev_attr_edge);
+ if (!status)
+ status = device_create_file(dev,
+ &dev_attr_irq_wake);
+ }
if (status != 0)
device_unregister(dev);
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC][PATCH] gpiolib: add irq_wake (power-management) sysfs file
2011-11-09 16:01 [RFC][PATCH] gpiolib: add irq_wake (power-management) sysfs file Patrick Combes
@ 2011-11-10 18:50 ` Kevin Hilman
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Hilman @ 2011-11-10 18:50 UTC (permalink / raw)
To: Patrick Combes
Cc: tony, linux-omap, b-cousson, f-mazard, dmurphy, Hugo Dupras
Patrick Combes <p-combes@ti.com> writes:
> From: Hugo Dupras <h-dupras@ti.com>
>
> By calling poll() on the /sys/class/gpio/gpioN/value sysfs file, usermode
> application can take benefit of gpio interrupts.
> However, depending on the power state reached, this interrupt may not wake-up
> the CPU.
> This patch creates a new sysfs file /sys/class/gpio/gpioN/irq_wake to enable
> usermode application to set the wake properties of a gpio IRQ.
> This option can be set or not for each gpio to preserve power consumption (e.g
> embedded systems).
>
> Signed-off-by: Hugo Dupras <h-dupras@ti.com>
> Signed-off-by: Patrick Combes <p-combes@ti.com>
Hello,
This is a change to the GPIO core but you only have the OMAP-specific
list here.
Please send this to the GPIO maintainer[1] and the lists.
Also, please copy linux-arm-kernel@lists.infradead.org where there are
lots of GPIOlib users who might be interested in this, and also copy
LKML (linux-kernel@vger.kernel.org)
Thanks,
Kevin
P.S. David Brownell passed away earlier this year, so I removed his
email from the to list: http://lkml.org/lkml/2011/6/6/32
[1] excerpt from MAINTAINERS file
GPIO SUBSYSTEM
M: Grant Likely <grant.likely@secretlab.ca>
S: Maintained
T: git git://git.secretlab.ca/git/linux-2.6.git
F: Documentation/gpio.txt
F: drivers/gpio/
F: include/linux/gpio*
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-11-10 18:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-09 16:01 [RFC][PATCH] gpiolib: add irq_wake (power-management) sysfs file Patrick Combes
2011-11-10 18:50 ` Kevin Hilman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox