All of lore.kernel.org
 help / color / mirror / Atom feed
From: ben@fluff.org
To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Cc: David Brownell <dbrownell@users.sourceforge.net>
Subject: gpiolib: add names file in gpio chip sysfs.
Date: Mon, 03 Aug 2009 17:55:36 +0100	[thread overview]
Message-ID: <20090803165536.345974601@fluff.org> (raw)

[-- Attachment #1: gpio-export-names.patch --]
[-- Type: text/plain, Size: 1566 bytes --]

Add a 'names' file to the sysfs entries for each chip to show which
have names.

Signed-off-by: Ben Dooks <ben@simtec.co.uk>
CC: David Brownell <dbrownell@users.sourceforge.net>

---
 drivers/gpio/gpiolib.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Index: b/drivers/gpio/gpiolib.c
===================================================================
--- a/drivers/gpio/gpiolib.c	2009-08-03 17:51:40.000000000 +0100
+++ b/drivers/gpio/gpiolib.c	2009-08-03 17:53:04.000000000 +0100
@@ -303,6 +303,7 @@ static const struct attribute_group gpio
  *   /base ... matching gpio_chip.base (N)
  *   /label ... matching gpio_chip.label
  *   /ngpio ... matching gpio_chip.ngpio
+ *   /names ... matching gpio_chip.names
  */
 
 static ssize_t chip_base_show(struct device *dev,
@@ -332,10 +333,30 @@ static ssize_t chip_ngpio_show(struct de
 }
 static DEVICE_ATTR(ngpio, 0444, chip_ngpio_show, NULL);
 
+static ssize_t chip_names_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	const struct gpio_chip*chip = dev_get_drvdata(dev);
+	char **names = chip->names;
+	int ptr = 0;
+	int name;
+
+	if (!names)
+		return -EINVAL;
+
+	for (name = 0; name < chip->ngpio && ptr < PAGE_SIZE; name++)
+		ptr += snprintf(buf + ptr, PAGE_SIZE - ptr,
+				"%s\n", names[name] ? names[name] : "");
+
+	return ptr;
+}
+DEVICE_ATTR(names, 0444, chip_names_show, NULL);
+
 static const struct attribute *gpiochip_attrs[] = {
 	&dev_attr_base.attr,
 	&dev_attr_label.attr,
 	&dev_attr_ngpio.attr,
+	&dev_attr_names.attr,
 	NULL,
 };
 

-- 

             reply	other threads:[~2009-08-03 16:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-03 16:55 ben [this message]
2009-08-04 21:02 ` gpiolib: add names file in gpio chip sysfs David Brownell
2009-08-04 23:43 ` Andrew Morton
2009-09-29 10:47   ` Ben Dooks
2009-09-29 19:34     ` Andrew Morton

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=20090803165536.345974601@fluff.org \
    --to=ben@fluff.org \
    --cc=akpm@linux-foundation.org \
    --cc=dbrownell@users.sourceforge.net \
    --cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.