linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: p-combes@ti.com (Patrick Combes)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC][PATCH] gpiolib: add irq_wake (power-management) sysfs file
Date: Fri, 11 Nov 2011 10:40:06 +0100	[thread overview]
Message-ID: <1321004406-15663-1-git-send-email-p-combes@ti.com> (raw)

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

             reply	other threads:[~2011-11-11  9:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-11  9:40 Patrick Combes [this message]
2011-11-15 13:16 ` [RFC][PATCH] gpiolib: add irq_wake (power-management) sysfs file Mark Brown
2011-11-15 17:20   ` Russell King - ARM Linux
2011-11-16 14:39     ` Patrick Combes
2011-11-16 14:30   ` Patrick Combes
2011-11-16 14:37     ` Mark Brown
2011-11-16 17:23       ` Patrick Combes
2011-11-21  7:47 ` Linus Walleij

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=1321004406-15663-1-git-send-email-p-combes@ti.com \
    --to=p-combes@ti.com \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).