aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlliver Schinagl <oliver@schinagl.nl>2015-01-21 16:33:46 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-03-04 07:58:58 -0500
commit1feb57a245a4910b03202a814ffc51a900bd4aca (patch)
treeaa32b4a6ceb8132a7c89c4edae70ea83a7cbc1a0
parentb80eef95beb04760629822fa130aeed54cdfafca (diff)
gpio: add parameter to allow the use named gpios
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 <oliver@schinagl.nl> Acked-by: Bryan Wu <cooloney@gmail.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/devres.c18
-rw-r--r--drivers/input/keyboard/gpio_keys_polled.c2
-rw-r--r--drivers/leds/leds-gpio.c2
-rw-r--r--include/linux/gpio/consumer.h1
4 files changed, 20 insertions, 3 deletions
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 13dbd3dfc33a..12c2082f968e 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -111,23 +111,39 @@ EXPORT_SYMBOL(__devm_gpiod_get_index);
111/** 111/**
112 * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node 112 * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node
113 * @dev: GPIO consumer 113 * @dev: GPIO consumer
114 * @con_id: function within the GPIO consumer
114 * @child: firmware node (child of @dev) 115 * @child: firmware node (child of @dev)
115 * 116 *
116 * GPIO descriptors returned from this function are automatically disposed on 117 * GPIO descriptors returned from this function are automatically disposed on
117 * driver detach. 118 * driver detach.
118 */ 119 */
119struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, 120struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
121 const char *con_id,
120 struct fwnode_handle *child) 122 struct fwnode_handle *child)
121{ 123{
124 static const char const *suffixes[] = { "gpios", "gpio" };
125 char prop_name[32]; /* 32 is max size of property name */
122 struct gpio_desc **dr; 126 struct gpio_desc **dr;
123 struct gpio_desc *desc; 127 struct gpio_desc *desc;
128 unsigned int i;
124 129
125 dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), 130 dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *),
126 GFP_KERNEL); 131 GFP_KERNEL);
127 if (!dr) 132 if (!dr)
128 return ERR_PTR(-ENOMEM); 133 return ERR_PTR(-ENOMEM);
129 134
130 desc = fwnode_get_named_gpiod(child, "gpios"); 135 for (i = 0; i < ARRAY_SIZE(suffixes); i++) {
136 if (con_id)
137 snprintf(prop_name, sizeof(prop_name), "%s-%s",
138 con_id, suffixes[i]);
139 else
140 snprintf(prop_name, sizeof(prop_name), "%s",
141 suffixes[i]);
142
143 desc = fwnode_get_named_gpiod(child, prop_name);
144 if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER))
145 break;
146 }
131 if (IS_ERR(desc)) { 147 if (IS_ERR(desc)) {
132 devres_free(dr); 148 devres_free(dr);
133 return desc; 149 return desc;
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index 90df4df58b07..097d7216d98e 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -125,7 +125,7 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
125 device_for_each_child_node(dev, child) { 125 device_for_each_child_node(dev, child) {
126 struct gpio_desc *desc; 126 struct gpio_desc *desc;
127 127
128 desc = devm_get_gpiod_from_child(dev, child); 128 desc = devm_get_gpiod_from_child(dev, NULL, child);
129 if (IS_ERR(desc)) { 129 if (IS_ERR(desc)) {
130 error = PTR_ERR(desc); 130 error = PTR_ERR(desc);
131 if (error != -EPROBE_DEFER) 131 if (error != -EPROBE_DEFER)
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index d26af0a79a90..15eb3f86f670 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -184,7 +184,7 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
184 struct gpio_led led = {}; 184 struct gpio_led led = {};
185 const char *state = NULL; 185 const char *state = NULL;
186 186
187 led.gpiod = devm_get_gpiod_from_child(dev, child); 187 led.gpiod = devm_get_gpiod_from_child(dev, NULL, child);
188 if (IS_ERR(led.gpiod)) { 188 if (IS_ERR(led.gpiod)) {
189 fwnode_handle_put(child); 189 fwnode_handle_put(child);
190 ret = PTR_ERR(led.gpiod); 190 ret = PTR_ERR(led.gpiod);
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 45afc2dee560..ed20759229eb 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -110,6 +110,7 @@ struct fwnode_handle;
110struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, 110struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
111 const char *propname); 111 const char *propname);
112struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, 112struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
113 const char *con_id,
113 struct fwnode_handle *child); 114 struct fwnode_handle *child);
114#else /* CONFIG_GPIOLIB */ 115#else /* CONFIG_GPIOLIB */
115 116