mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kim Kyuwon <q1.kim@samsung.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: "Guennadi Liakhovetski" <g.liakhovetski@pengutronix.de>,
	"David Brownell" <dbrownell@users.sourceforge.net>,
	"Greg KH" <greg@kroah.com>, "Kay Sievers" <kay.sievers@vrfy.org>,
	"\"???\"" <kyungmin.park@samsung.com>,
	chammoru@gmail.com
Subject: Suggestion on GPIO sysfs interface (gpio_export)
Date: Mon, 20 Apr 2009 14:22:46 +0900	[thread overview]
Message-ID: <49EC06A6.4040506@samsung.com> (raw)

Hi All,

Exporting GPIOs by using gpio_export() is very useful to me.
But I want to access each GPIO by its name(or label) instead of
GPIO number, because GPIO label is more descriptive.

So I just modified gpio_export() to show the label information as shown below.
(This patch just shows the idea)

==
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 42fb2fd..392303d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -363,7 +363,7 @@ static ssize_t export_store(struct class *class, const char *buf, size_t len)
 	if (status < 0)
 		goto done;
 
-	status = gpio_export(gpio, true);
+	status = gpio_export(gpio, true, false);
 	if (status < 0)
 		gpio_free(gpio);
 	else
@@ -422,6 +422,7 @@ static struct class gpio_class = {
  * gpio_export - export a GPIO through sysfs
  * @gpio: gpio to make available, already requested
  * @direction_may_change: true if userspace may change gpio direction
+ * @label_may_show: true if gpio label may show, instead of gpio number
  * Context: arch_initcall or later
  *
  * When drivers want to make a GPIO accessible to userspace after they
@@ -433,7 +434,7 @@ static struct class gpio_class = {
  *
  * Returns zero on success, else an error.
  */
-int gpio_export(unsigned gpio, bool direction_may_change)
+int gpio_export(unsigned gpio, bool direction_may_change, bool label_may_show)
 {
 	unsigned long		flags;
 	struct gpio_desc	*desc;
@@ -464,8 +465,15 @@ int gpio_export(unsigned gpio, bool direction_may_change)
 	if (status == 0) {
 		struct device	*dev;
 
-		dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0),
-					desc, "gpio%d", gpio);
+#ifdef CONFIG_DEBUG_FS
+		if (label_may_show && desc->label)
+			dev = device_create(&gpio_class, desc->chip->dev,
+				MKDEV(0, 0), desc, "%s", desc->label);
+		else
+#endif
+			dev = device_create(&gpio_class, desc->chip->dev,
+				MKDEV(0, 0), desc, "gpio%d", gpio);
+
 		if (dev) {
 			if (direction_may_change)
 				status = sysfs_create_group(&dev->kobj,
diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index 7ac12cb..4a37ff1 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -304,7 +304,7 @@ static int add_children(struct i2c_client *client)
 		gpio_direction_input(gpio);
 
 		/* make it easy for userspace to see these */
-		gpio_export(gpio, false);
+		gpio_export(gpio, false, false);
 	}
 
 	/* MMC/SD inputs -- right after the last config input */
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 81797ec..9852da4 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -135,7 +135,8 @@ extern int __gpio_to_irq(unsigned gpio);
  * A sysfs interface can be exported by individual drivers if they want,
  * but more typically is configured entirely from userspace.
  */
-extern int gpio_export(unsigned gpio, bool direction_may_change);
+extern int gpio_export(unsigned gpio, bool direction_may_change,
+							bool label_may_show);
 extern void gpio_unexport(unsigned gpio);
 
 #endif	/* CONFIG_GPIO_SYSFS */
@@ -175,7 +176,8 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
 
 /* sysfs support is only available with gpiolib, where it's optional */
 
-static inline int gpio_export(unsigned gpio, bool direction_may_change)
+static inline int gpio_export(unsigned gpio, bool direction_may_change,
+							bool label_may_show)
 {
 	return -ENOSYS;
 }
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index e10c49a..1209149 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -82,7 +82,8 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value)
 	WARN_ON(1);
 }
 
-static inline int gpio_export(unsigned gpio, bool direction_may_change)
+static inline int gpio_export(unsigned gpio, bool direction_may_change,
+							bool label_may_show)
 {
 	/* GPIO can never have been requested or set as {in,out}put */
 	WARN_ON(1);
==

Can I ask you opinion about this idea?
If I get the positive answer, I will send the full patch set which
changes all board files and documentation related to gpio_export.

Regards,
Kim Kyuwon



             reply	other threads:[~2009-04-20  5:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-20  5:22 Kim Kyuwon [this message]
2009-04-20 16:52 ` David Brownell
2009-04-22  2:09   ` Kim Kyuwon

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=49EC06A6.4040506@samsung.com \
    --to=q1.kim@samsung.com \
    --cc=chammoru@gmail.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=g.liakhovetski@pengutronix.de \
    --cc=greg@kroah.com \
    --cc=kay.sievers@vrfy.org \
    --cc=kyungmin.park@samsung.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome