The gpio binding docs ask to use named-gpios wherever possible, however 40b73183 probably forgot that. This patch makes the new devm_get_gpiod_from_child use named gpios.
Changed since v1:
Fix a few typo's
Fix of_find_gpio to remove hardcoded length of string
Check both for leds-gpios and if that fails, fall back to standard gpios for the users of devm_get_gpiod_from_child.
Olliver Schinagl (4):
gpio: use sizeof() instead of hardcoded values
gpio: add parameter to allow the use named gpios
leds: Let the binding document example for leds-gpio follow the gpio
bindings
leds: no longer use unnamed gpios
Documentation/devicetree/bindings/leds/leds-gpio.txt | 14 ++++++++------
drivers/gpio/devres.c | 18 +++++++++++++++++-
drivers/gpio/gpiolib.c | 6 ++++--
drivers/input/keyboard/gpio_keys_polled.c | 20 ++++++++++++--------
drivers/leds/leds-gpio.c | 2 +-
include/linux/gpio/consumer.h | 1 +
6 files changed, 43 insertions(+), 18 deletions(-)
--
2.1.4
From: Olliver Schinagl <redacted>
gpiolib uses a fixed string for the suffixes and defines it at 32 bytes.
Later in the code snprintf is used with this fixed value of 32. Using
sizeof() is safer in case the size for the suffixes is ever changed.
Signed-off-by: Olliver Schinagl <redacted>
---
drivers/gpio/gpiolib.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
From: Olliver Schinagl <redacted>
The gpio binding document says that new code should always use named
gpios. Patch 40b73183 added support to parse a list of gpios from child
nodes, but does not make it possible to use named gpios. This patch adds
the con_id property and implements it is done in gpiolib.c, where the
old-style of using unnamed gpios still works.
Signed-off-by: Olliver Schinagl <redacted>
---
drivers/gpio/devres.c | 18 +++++++++++++++++-
drivers/input/keyboard/gpio_keys_polled.c | 2 +-
drivers/leds/leds-gpio.c | 2 +-
include/linux/gpio/consumer.h | 1 +
4 files changed, 20 insertions(+), 3 deletions(-)
@@ -111,23 +111,39 @@ EXPORT_SYMBOL(__devm_gpiod_get_index);/***devm_get_gpiod_from_child-getaGPIOdescriptorfromadevice'schildnode*@dev:GPIOconsumer+*@con_id:functionwithintheGPIOconsumer*@child:firmwarenode(childof@dev)**GPIOdescriptorsreturnedfromthisfunctionareautomaticallydisposedon*driverdetach.*/structgpio_desc*devm_get_gpiod_from_child(structdevice*dev,+constchar*con_id,structfwnode_handle*child){+staticconstcharconst*suffixes[]={"gpios","gpio"};+charprop_name[32];/* 32 is max size of property name */structgpio_desc**dr;structgpio_desc*desc;+unsignedinti;dr=devres_alloc(devm_gpiod_release,sizeof(structgpio_desc*),GFP_KERNEL);if(!dr)returnERR_PTR(-ENOMEM);-desc=fwnode_get_named_gpiod(child,"gpios");+for(i=0;i<ARRAY_SIZE(suffixes);i++){+if(con_id)+snprintf(prop_name,sizeof(prop_name),"%s-%s",+con_id,suffixes[i]);+else+snprintf(prop_name,sizeof(prop_name),"%s",+suffixes[i]);++desc=fwnode_get_named_gpiod(child,prop_name);+if(!IS_ERR(desc)||(PTR_ERR(desc)==-EPROBE_DEFER))+break;+}if(IS_ERR(desc)){devres_free(dr);returndesc;
From: Olliver Schinagl <redacted>
In the gpio bindings documents it is requested to use the marco's in
include/dt-bindings/gpio/gpio.h whenever possible. The gpios in the led
drivers don't seem to form an exception, so update the example in the
document bindings.
Signed-off-by: Olliver Schinagl <redacted>
Acked-by: Rob Herring <robh@kernel.org>
Acked-by: Linus Walleij <redacted>
---
Documentation/devicetree/bindings/leds/leds-gpio.txt | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
From: Olliver Schinagl <redacted>
The gpio document says we should not use unnamed bindings for gpios.
This patch uses the 'led-' prefix to the gpios and updates code and
documents. Because the devm_get_gpiod_from_child() falls back to using
old-style unnamed gpios, we can update the code first, and update
dts files as time allows.
Signed-off-by: Olliver Schinagl <redacted>
---
Documentation/devicetree/bindings/leds/leds-gpio.txt | 12 ++++++------
drivers/input/keyboard/gpio_keys_polled.c | 20 ++++++++++++--------
drivers/leds/leds-gpio.c | 2 +-
3 files changed, 19 insertions(+), 15 deletions(-)
@@ -7,7 +7,7 @@ Each LED is represented as a sub-node of the gpio-leds device. Each node's name represents the name of the corresponding LED. LED sub-node properties:-- gpios : Should specify the LED's GPIO, see "gpios property" in+- led-gpios : Should specify the LED's GPIO, see "gpios property" in Documentation/devicetree/bindings/gpio/gpio.txt. Active low LEDs should be indicated using flags in the GPIO specifier. - label : (optional)
@@ -125,15 +125,19 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structdevice_for_each_child_node(dev,child){structgpio_desc*desc;-desc=devm_get_gpiod_from_child(dev,NULL,child);+desc=devm_get_gpiod_from_child(dev,"gpio_keys_polled",+child);if(IS_ERR(desc)){-error=PTR_ERR(desc);-if(error!=-EPROBE_DEFER)-dev_err(dev,-"Failed to get gpio flags, error: %d\n",-error);-fwnode_handle_put(child);-returnERR_PTR(error);+desc=devm_get_gpiod_from_child(dev,NULL,child);+if(IS_ERR(desc)){+error=PTR_ERR(desc);+if(error!=-EPROBE_DEFER)+dev_err(dev,+"Failed to get gpio flags, error: %d\n",+error);+fwnode_handle_put(child);+returnERR_PTR(error);+}}button=&pdata->buttons[pdata->nbuttons++];
From: Rojhalat Ibrahim <hidden> Date: 2015-01-22 09:32:59
On Wednesday 21 January 2015 22:33:48 Olliver Schinagl wrote:
From: Olliver Schinagl <redacted>
The gpio document says we should not use unnamed bindings for gpios.
This patch uses the 'led-' prefix to the gpios and updates code and
documents. Because the devm_get_gpiod_from_child() falls back to using
old-style unnamed gpios, we can update the code first, and update
dts files as time allows.
Signed-off-by: Olliver Schinagl <redacted>
Where does devm_get_gpiod_from_child() fall back "to using old-style
unnamed gpios"?
After applying this patch the leds defined in my devicetree do not
work anymore.
Rojhalat
Hey Rojhalat,
On 22-01-15 10:32, Rojhalat Ibrahim wrote:
On Wednesday 21 January 2015 22:33:48 Olliver Schinagl wrote:
quoted
From: Olliver Schinagl <redacted>
The gpio document says we should not use unnamed bindings for gpios.
This patch uses the 'led-' prefix to the gpios and updates code and
documents. Because the devm_get_gpiod_from_child() falls back to using
old-style unnamed gpios, we can update the code first, and update
dts files as time allows.
Signed-off-by: Olliver Schinagl <redacted>
Where does devm_get_gpiod_from_child() fall back "to using old-style
unnamed gpios"?
Your absolutly right, I accidentally forgot a patch that was supposed to
get squashed into this patchset. The idea is to do the same as in
gpio-keys-polled.c. I'll make sure it sits in v3 of the set! My appologies!
Olliver
After applying this patch the leds defined in my devicetree do not
work anymore.
Rojhalat
--
Met vriendelijke groeten, Kind regards, 与亲切的问候
Olliver Schinagl
Research & Development
Ultimaker B.V.
http://www.ultimaker.com
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
@@ -125,15 +125,19 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(structdevice_for_each_child_node(dev,child){structgpio_desc*desc;-desc=devm_get_gpiod_from_child(dev,NULL,child);+desc=devm_get_gpiod_from_child(dev,"gpio_keys_polled",+child);if(IS_ERR(desc)){-error=PTR_ERR(desc);-if(error!=-EPROBE_DEFER)-dev_err(dev,-"Failed to get gpio flags, error: %d\n",-error);-fwnode_handle_put(child);-returnERR_PTR(error);+desc=devm_get_gpiod_from_child(dev,NULL,child);+if(IS_ERR(desc)){+error=PTR_ERR(desc);+if(error!=-EPROBE_DEFER)+dev_err(dev,+"Failed to get gpio flags, error: %d\n",+error);+fwnode_handle_put(child);+returnERR_PTR(error);+}}
I do not think this is correct. If devm_get_gpiod_from_child(dev,
"gpio_keys_polled", child) retruns -EPROBE_DEFER we'll try
devm_get_gpiod_from_child(dev, NULL, child). If that returns some other
error we'll fail probing entire driver.
Did I mention how *I HATE* the -EPROBE_DEFER (the error that is not an
error)?
Thanks.
--
Dmitry
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
From: Olliver Schinagl <redacted>
gpiolib uses a fixed string for the suffixes and defines it at 32 bytes.
Later in the code snprintf is used with this fixed value of 32. Using
sizeof() is safer in case the size for the suffixes is ever changed.
Signed-off-by: Olliver Schinagl <redacted>
OK looks nice.
Patch applied.
Yours,
Linus Walleij
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
From: Olliver Schinagl <redacted>
The gpio binding document says that new code should always use named
gpios. Patch 40b73183 added support to parse a list of gpios from child
nodes, but does not make it possible to use named gpios. This patch adds
the con_id property and implements it is done in gpiolib.c, where the
old-style of using unnamed gpios still works.
Signed-off-by: Olliver Schinagl <redacted>
---
drivers/gpio/devres.c | 18 +++++++++++++++++-
drivers/input/keyboard/gpio_keys_polled.c | 2 +-
drivers/leds/leds-gpio.c | 2 +-
include/linux/gpio/consumer.h | 1 +
Alexandre: does this match your vision of how it should work, i.e. ACK?
Bryan/Dmitry: can you ACK the oneliners in your subsystems?
Yours,
Linus Walleij
On Fri, Jan 30, 2015 at 5:46 AM, Linus Walleij [off-list ref] wrote:
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
quoted
From: Olliver Schinagl <redacted>
The gpio binding document says that new code should always use named
gpios. Patch 40b73183 added support to parse a list of gpios from child
nodes, but does not make it possible to use named gpios. This patch adds
the con_id property and implements it is done in gpiolib.c, where the
old-style of using unnamed gpios still works.
Signed-off-by: Olliver Schinagl <redacted>
---
drivers/gpio/devres.c | 18 +++++++++++++++++-
drivers/input/keyboard/gpio_keys_polled.c | 2 +-
drivers/leds/leds-gpio.c | 2 +-
include/linux/gpio/consumer.h | 1 +
Alexandre: does this match your vision of how it should work, i.e. ACK?
Bryan/Dmitry: can you ACK the oneliners in your subsystems?
Sure, please take my Ack
Acked-by: Bryan Wu <redacted>
On Fri, Jan 30, 2015 at 11:12:53AM -0800, Bryan Wu wrote:
On Fri, Jan 30, 2015 at 5:46 AM, Linus Walleij [off-list ref] wrote:
quoted
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
quoted
From: Olliver Schinagl <redacted>
The gpio binding document says that new code should always use named
gpios. Patch 40b73183 added support to parse a list of gpios from child
nodes, but does not make it possible to use named gpios. This patch adds
the con_id property and implements it is done in gpiolib.c, where the
old-style of using unnamed gpios still works.
Signed-off-by: Olliver Schinagl <redacted>
---
drivers/gpio/devres.c | 18 +++++++++++++++++-
drivers/input/keyboard/gpio_keys_polled.c | 2 +-
drivers/leds/leds-gpio.c | 2 +-
include/linux/gpio/consumer.h | 1 +
Alexandre: does this match your vision of how it should work, i.e. ACK?
Bryan/Dmitry: can you ACK the oneliners in your subsystems?
Sure, please take my Ack
Acked-by: Bryan Wu <redacted>
Mine as well:
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Thanks.
--
Dmitry
On Fri, Jan 30, 2015 at 02:16:00PM -0800, Dmitry Torokhov wrote:
On Fri, Jan 30, 2015 at 11:12:53AM -0800, Bryan Wu wrote:
quoted
On Fri, Jan 30, 2015 at 5:46 AM, Linus Walleij [off-list ref] wrote:
quoted
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
quoted
From: Olliver Schinagl <redacted>
The gpio binding document says that new code should always use named
gpios. Patch 40b73183 added support to parse a list of gpios from child
nodes, but does not make it possible to use named gpios. This patch adds
the con_id property and implements it is done in gpiolib.c, where the
old-style of using unnamed gpios still works.
Signed-off-by: Olliver Schinagl <redacted>
---
drivers/gpio/devres.c | 18 +++++++++++++++++-
drivers/input/keyboard/gpio_keys_polled.c | 2 +-
drivers/leds/leds-gpio.c | 2 +-
include/linux/gpio/consumer.h | 1 +
Alexandre: does this match your vision of how it should work, i.e. ACK?
Bryan/Dmitry: can you ACK the oneliners in your subsystems?
Sure, please take my Ack
Acked-by: Bryan Wu <redacted>
Mine as well:
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Forgot to mention: the ack is for this patch only; the patch #4 is
NAKed because:
1. The logic of handling old and new name AFAICS is broken and
2. gpio_keys_polled-gpios as name is plain ugly.
Thanks.
--
Dmitry
On Fri, Jan 30, 2015 at 10:46 PM, Linus Walleij
[off-list ref] wrote:
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
quoted
From: Olliver Schinagl <redacted>
The gpio binding document says that new code should always use named
gpios. Patch 40b73183 added support to parse a list of gpios from child
nodes, but does not make it possible to use named gpios. This patch adds
the con_id property and implements it is done in gpiolib.c, where the
old-style of using unnamed gpios still works.
Signed-off-by: Olliver Schinagl <redacted>
---
drivers/gpio/devres.c | 18 +++++++++++++++++-
drivers/input/keyboard/gpio_keys_polled.c | 2 +-
drivers/leds/leds-gpio.c | 2 +-
include/linux/gpio/consumer.h | 1 +
Alexandre: does this match your vision of how it should work, i.e. ACK?
Pretty much, yes - as I mentioned in the previous versions there may
be shortcomings for ACPI, but we need a refactor of the whole thing -
nothing that this patch should address by itself.
So this patch:
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
From: Olliver Schinagl <redacted>
In the gpio bindings documents it is requested to use the marco's in
include/dt-bindings/gpio/gpio.h whenever possible. The gpios in the led
drivers don't seem to form an exception, so update the example in the
document bindings.
Signed-off-by: Olliver Schinagl <redacted>
Acked-by: Rob Herring <robh@kernel.org>
Acked-by: Linus Walleij <redacted>
Bryan: please merge this patch to the LED git tree.
Yours,
Linus Walleij
On Mon, Mar 2, 2015 at 3:24 AM, Linus Walleij [off-list ref] wrote:
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
quoted
From: Olliver Schinagl <redacted>
In the gpio bindings documents it is requested to use the marco's in
include/dt-bindings/gpio/gpio.h whenever possible. The gpios in the led
drivers don't seem to form an exception, so update the example in the
document bindings.
Signed-off-by: Olliver Schinagl <redacted>
Acked-by: Rob Herring <robh@kernel.org>
Acked-by: Linus Walleij <redacted>
Bryan: please merge this patch to the LED git tree.
On Wed, Jan 21, 2015 at 10:33 PM, Olliver Schinagl
[off-list ref] wrote:
From: Olliver Schinagl <redacted>
The gpio binding document says that new code should always use named
gpios. Patch 40b73183 added support to parse a list of gpios from child
nodes, but does not make it possible to use named gpios. This patch adds
the con_id property and implements it is done in gpiolib.c, where the
old-style of using unnamed gpios still works.
Signed-off-by: Olliver Schinagl <redacted>
Patch applied with the ACKs and tags.
Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html