gpiolib: add names file in gpio chip sysfs.
Add a 'names' file to the sysfs entries for each chip to show which have names.
--- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/gpio/gpiolib.c +21 -0
@@ -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 , };
Quoted 1 line · On Mon, 03 Aug 2009 17:55:36 +0100 [email protected] wrote:
Did you mean the commit to have an author of [email protected]? I assumed not and rewrote it to
Ben Dooks <[email protected]>
If you indeed want a different Author: and Signed-off-by: line then please indicate that explicitly by putting a From: line at the top of the changelog.
As your MUA didn't fill in the real-name part of the From: address, it's nice to provide a From: line in the changelog so the patch receiver doesn't have to type it in.
Quoted 2 lines
Add a 'names' file to the sysfs entries for each chip to show which have names.
Why?
Quoted 20 lines
Signed-off-by Ben Dooks <[email protected]>CC David Brownell <[email protected]>--- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)Index:
b/drivers/gpio/gpiolib.c
===================================================================drivers/gpio/gpiolib.c +1
-0@@ -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,
drivers/gpio/gpiolib.c static ssize_t chip_ngpio_show(struct de · line 339
Quoted 7 lines
drivers/gpio/gpiolib.c +4
-0@@ -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);
Please use checkpatch.
drivers/gpio/gpiolib.c static ssize_t chip_ngpio_show(struct de · line 345
Quoted 6 lines
drivers/gpio/gpiolib.c +6
-0+char **names = chip->names; +int ptr =0 ; +int name; + +if (!names) +return -EINVAL ;
Should this return -EINVAL? Or should we simply return an empty read()?
drivers/gpio/gpiolib.c static ssize_t chip_ngpio_show(struct de · line 353
Quoted 7 lines
drivers/gpio/gpiolib.c +7
-0+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 );
I shall make this static.
Quoted 10 lines
drivers/gpio/gpiolib.c +1
-0static const struct attribute *gpiochip_attrs[] = { &dev_attr_base.attr, &dev_attr_label.attr, &dev_attr_ngpio.attr, + &dev_attr_names.attr,NULL , };Signature · 1 line
--
Quoted 4 lines · Andrew Morton
Quoted 1 line · On Mon, 03 Aug 2009 17:55:36 +0100 [email protected] wrote:
Quoted 8 lines
Did you mean the commit to have an author of [email protected]? I assumed not and rewrote it to
Ben Dooks <[email protected]>
If you indeed want a different Author: and Signed-off-by: line then please indicate that explicitly by putting a From: line at the top of the changelog.
sorry, occasionally whilst using quilt mail I get this wrong.
Quoted 8 lines
As your MUA didn't fill in the real-name part of the From: address, it's nice to provide a From: line in the changelog so the patch receiver doesn't have to type it in.
Quoted 2 lines
Add a 'names' file to the sysfs entries for each chip to show which have names.
Why?
To export this information to the user. That was the only reason.
Signature · 4 lines
Ben Q: What's a light-year? A: One-third less calories than a regular year.
Quoted 20 lines · On Tue, 29 Sep 2009 11:47:35 +0100 Ben Dooks <[email protected]> wrote:
Quoted 4 lines · Andrew Morton
Quoted 1 line · On Mon, 03 Aug 2009 17:55:36 +0100 [email protected] wrote:
Quoted 8 lines
Did you mean the commit to have an author of [email protected]? I assumed not and rewrote it to
Ben Dooks <[email protected]>
If you indeed want a different Author: and Signed-off-by: line then please indicate that explicitly by putting a From: line at the top of the changelog.
sorry, occasionally whilst using quilt mail I get this wrong.
Quoted 4 lines
As your MUA didn't fill in the real-name part of the From: address, it's nice to provide a From: line in the changelog so the patch receiver doesn't have to type it in.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Add a 'names' file to the sysfs entries for each chip to show which have names.
Why?
To export this information to the user. That was the only reason.
hm, OK. I guess I just won't be understanding what value this patch has. Hopefully more gpio-inclined people do.
What's the status of this patch now? I have a note that David had issues with it - did they get resolved somehow?
Quoted 4 lines · On Monday 03 August 2009, [email protected] wrote:
drivers/gpio/gpiolib.c +4
-0+static ssize_t chip_names_show (struct device *dev, + struct device_attribute *attr, char *buf) +{ + const struct gpio_chip*chip = dev_get_drvdata(dev);
drivers/gpio/gpiolib.c static ssize_t chip_ngpio_show(struct de · line 349
Quoted 10 lines
drivers/gpio/gpiolib.c +10
-0+ 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] : "");
Surely the actual GPIO number should be there too?
This whole chip->names thing still seems odd to me, since it's creating a redundant namespace.
Quoted 5 lines
drivers/gpio/gpiolib.c +5
-0+ + return ptr; +} +DEVICE_ATTR (names,0444 , chip_names_show,NULL ); +