diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2017-01-26 04:00:31 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2017-01-26 04:00:31 -0500 |
commit | 8c541b11483b099b8ce49211e766c6df77dce11b (patch) | |
tree | 3b784d41e19dbfe9429e430c94508caafb032590 | |
parent | 49cec4d8326b27e64779f888c680466d7863558f (diff) | |
parent | b2987d7438e0ca949d81774ca8b43d370a1f9947 (diff) |
Merge branch 'ib-gpiod-flags' into devel
-rw-r--r-- | drivers/gpio/devres.c | 10 | ||||
-rw-r--r-- | drivers/gpio/gpiolib.c | 23 | ||||
-rw-r--r-- | drivers/input/keyboard/gpio_keys.c | 10 | ||||
-rw-r--r-- | drivers/input/keyboard/gpio_keys_polled.c | 12 | ||||
-rw-r--r-- | drivers/leds/leds-gpio.c | 13 | ||||
-rw-r--r-- | drivers/video/fbdev/amba-clcd-nomadik.c | 19 | ||||
-rw-r--r-- | include/linux/gpio/consumer.h | 23 |
7 files changed, 64 insertions, 46 deletions
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c index 2c49a8bc9e3f..d196be7ac352 100644 --- a/drivers/gpio/devres.c +++ b/drivers/gpio/devres.c | |||
@@ -129,13 +129,19 @@ EXPORT_SYMBOL(devm_gpiod_get_index); | |||
129 | * @dev: GPIO consumer | 129 | * @dev: GPIO consumer |
130 | * @con_id: function within the GPIO consumer | 130 | * @con_id: function within the GPIO consumer |
131 | * @child: firmware node (child of @dev) | 131 | * @child: firmware node (child of @dev) |
132 | * @flags: GPIO initialization flags | ||
132 | * | 133 | * |
133 | * GPIO descriptors returned from this function are automatically disposed on | 134 | * GPIO descriptors returned from this function are automatically disposed on |
134 | * driver detach. | 135 | * driver detach. |
136 | * | ||
137 | * On successfull request the GPIO pin is configured in accordance with | ||
138 | * provided @flags. | ||
135 | */ | 139 | */ |
136 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, | 140 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, |
137 | const char *con_id, | 141 | const char *con_id, |
138 | struct fwnode_handle *child) | 142 | struct fwnode_handle *child, |
143 | enum gpiod_flags flags, | ||
144 | const char *label) | ||
139 | { | 145 | { |
140 | char prop_name[32]; /* 32 is max size of property name */ | 146 | char prop_name[32]; /* 32 is max size of property name */ |
141 | struct gpio_desc **dr; | 147 | struct gpio_desc **dr; |
@@ -155,7 +161,7 @@ struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, | |||
155 | snprintf(prop_name, sizeof(prop_name), "%s", | 161 | snprintf(prop_name, sizeof(prop_name), "%s", |
156 | gpio_suffixes[i]); | 162 | gpio_suffixes[i]); |
157 | 163 | ||
158 | desc = fwnode_get_named_gpiod(child, prop_name); | 164 | desc = fwnode_get_named_gpiod(child, prop_name, flags, label); |
159 | if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) | 165 | if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) |
160 | break; | 166 | break; |
161 | } | 167 | } |
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c76fa4ffb59c..14ee088c80dd 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -3301,6 +3301,7 @@ EXPORT_SYMBOL_GPL(gpiod_get_index); | |||
3301 | * fwnode_get_named_gpiod - obtain a GPIO from firmware node | 3301 | * fwnode_get_named_gpiod - obtain a GPIO from firmware node |
3302 | * @fwnode: handle of the firmware node | 3302 | * @fwnode: handle of the firmware node |
3303 | * @propname: name of the firmware property representing the GPIO | 3303 | * @propname: name of the firmware property representing the GPIO |
3304 | * @dflags: GPIO initialization flags | ||
3304 | * | 3305 | * |
3305 | * This function can be used for drivers that get their configuration | 3306 | * This function can be used for drivers that get their configuration |
3306 | * from firmware. | 3307 | * from firmware. |
@@ -3309,12 +3310,18 @@ EXPORT_SYMBOL_GPL(gpiod_get_index); | |||
3309 | * underlying firmware interface and then makes sure that the GPIO | 3310 | * underlying firmware interface and then makes sure that the GPIO |
3310 | * descriptor is requested before it is returned to the caller. | 3311 | * descriptor is requested before it is returned to the caller. |
3311 | * | 3312 | * |
3313 | * On successfull request the GPIO pin is configured in accordance with | ||
3314 | * provided @dflags. | ||
3315 | * | ||
3312 | * In case of error an ERR_PTR() is returned. | 3316 | * In case of error an ERR_PTR() is returned. |
3313 | */ | 3317 | */ |
3314 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | 3318 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
3315 | const char *propname) | 3319 | const char *propname, |
3320 | enum gpiod_flags dflags, | ||
3321 | const char *label) | ||
3316 | { | 3322 | { |
3317 | struct gpio_desc *desc = ERR_PTR(-ENODEV); | 3323 | struct gpio_desc *desc = ERR_PTR(-ENODEV); |
3324 | unsigned long lflags = 0; | ||
3318 | bool active_low = false; | 3325 | bool active_low = false; |
3319 | bool single_ended = false; | 3326 | bool single_ended = false; |
3320 | int ret; | 3327 | int ret; |
@@ -3342,18 +3349,24 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | |||
3342 | if (IS_ERR(desc)) | 3349 | if (IS_ERR(desc)) |
3343 | return desc; | 3350 | return desc; |
3344 | 3351 | ||
3345 | ret = gpiod_request(desc, NULL); | 3352 | ret = gpiod_request(desc, label); |
3346 | if (ret) | 3353 | if (ret) |
3347 | return ERR_PTR(ret); | 3354 | return ERR_PTR(ret); |
3348 | 3355 | ||
3349 | if (active_low) | 3356 | if (active_low) |
3350 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); | 3357 | lflags |= GPIO_ACTIVE_LOW; |
3351 | 3358 | ||
3352 | if (single_ended) { | 3359 | if (single_ended) { |
3353 | if (active_low) | 3360 | if (active_low) |
3354 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | 3361 | lflags |= GPIO_OPEN_DRAIN; |
3355 | else | 3362 | else |
3356 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); | 3363 | lflags |= GPIO_OPEN_SOURCE; |
3364 | } | ||
3365 | |||
3366 | ret = gpiod_configure_flags(desc, propname, lflags, dflags); | ||
3367 | if (ret < 0) { | ||
3368 | gpiod_put(desc); | ||
3369 | return ERR_PTR(ret); | ||
3357 | } | 3370 | } |
3358 | 3371 | ||
3359 | return desc; | 3372 | return desc; |
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 582462d0af75..2ec74d90ef78 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c | |||
@@ -481,7 +481,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, | |||
481 | spin_lock_init(&bdata->lock); | 481 | spin_lock_init(&bdata->lock); |
482 | 482 | ||
483 | if (child) { | 483 | if (child) { |
484 | bdata->gpiod = devm_get_gpiod_from_child(dev, NULL, child); | 484 | bdata->gpiod = devm_get_gpiod_from_child(dev, NULL, child, |
485 | GPIOD_IN, desc); | ||
485 | if (IS_ERR(bdata->gpiod)) { | 486 | if (IS_ERR(bdata->gpiod)) { |
486 | error = PTR_ERR(bdata->gpiod); | 487 | error = PTR_ERR(bdata->gpiod); |
487 | if (error == -ENOENT) { | 488 | if (error == -ENOENT) { |
@@ -496,13 +497,6 @@ static int gpio_keys_setup_key(struct platform_device *pdev, | |||
496 | error); | 497 | error); |
497 | return error; | 498 | return error; |
498 | } | 499 | } |
499 | } else { | ||
500 | error = gpiod_direction_input(bdata->gpiod); | ||
501 | if (error) { | ||
502 | dev_err(dev, "Failed to configure GPIO %d as input: %d\n", | ||
503 | desc_to_gpio(bdata->gpiod), error); | ||
504 | return error; | ||
505 | } | ||
506 | } | 500 | } |
507 | } else if (gpio_is_valid(button->gpio)) { | 501 | } else if (gpio_is_valid(button->gpio)) { |
508 | /* | 502 | /* |
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index bed4f2086158..5e35c565e341 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c | |||
@@ -304,7 +304,9 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) | |||
304 | } | 304 | } |
305 | 305 | ||
306 | bdata->gpiod = devm_get_gpiod_from_child(dev, NULL, | 306 | bdata->gpiod = devm_get_gpiod_from_child(dev, NULL, |
307 | child); | 307 | child, |
308 | GPIOD_IN, | ||
309 | button->desc); | ||
308 | if (IS_ERR(bdata->gpiod)) { | 310 | if (IS_ERR(bdata->gpiod)) { |
309 | error = PTR_ERR(bdata->gpiod); | 311 | error = PTR_ERR(bdata->gpiod); |
310 | if (error != -EPROBE_DEFER) | 312 | if (error != -EPROBE_DEFER) |
@@ -314,14 +316,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) | |||
314 | fwnode_handle_put(child); | 316 | fwnode_handle_put(child); |
315 | return error; | 317 | return error; |
316 | } | 318 | } |
317 | |||
318 | error = gpiod_direction_input(bdata->gpiod); | ||
319 | if (error) { | ||
320 | dev_err(dev, "Failed to configure GPIO %d as input: %d\n", | ||
321 | desc_to_gpio(bdata->gpiod), error); | ||
322 | fwnode_handle_put(child); | ||
323 | return error; | ||
324 | } | ||
325 | } else if (gpio_is_valid(button->gpio)) { | 319 | } else if (gpio_is_valid(button->gpio)) { |
326 | /* | 320 | /* |
327 | * Legacy GPIO number so request the GPIO here and | 321 | * Legacy GPIO number so request the GPIO here and |
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index d400dcaf4d29..6c4825d96693 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c | |||
@@ -174,12 +174,6 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) | |||
174 | const char *state = NULL; | 174 | const char *state = NULL; |
175 | struct device_node *np = to_of_node(child); | 175 | struct device_node *np = to_of_node(child); |
176 | 176 | ||
177 | led.gpiod = devm_get_gpiod_from_child(dev, NULL, child); | ||
178 | if (IS_ERR(led.gpiod)) { | ||
179 | fwnode_handle_put(child); | ||
180 | return ERR_CAST(led.gpiod); | ||
181 | } | ||
182 | |||
183 | ret = fwnode_property_read_string(child, "label", &led.name); | 177 | ret = fwnode_property_read_string(child, "label", &led.name); |
184 | if (ret && IS_ENABLED(CONFIG_OF) && np) | 178 | if (ret && IS_ENABLED(CONFIG_OF) && np) |
185 | led.name = np->name; | 179 | led.name = np->name; |
@@ -188,6 +182,13 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) | |||
188 | return ERR_PTR(-EINVAL); | 182 | return ERR_PTR(-EINVAL); |
189 | } | 183 | } |
190 | 184 | ||
185 | led.gpiod = devm_get_gpiod_from_child(dev, NULL, child, | ||
186 | GPIOD_ASIS, led.name); | ||
187 | if (IS_ERR(led.gpiod)) { | ||
188 | fwnode_handle_put(child); | ||
189 | return ERR_CAST(led.gpiod); | ||
190 | } | ||
191 | |||
191 | fwnode_property_read_string(child, "linux,default-trigger", | 192 | fwnode_property_read_string(child, "linux,default-trigger", |
192 | &led.default_trigger); | 193 | &led.default_trigger); |
193 | 194 | ||
diff --git a/drivers/video/fbdev/amba-clcd-nomadik.c b/drivers/video/fbdev/amba-clcd-nomadik.c index 0c06fcaaa6e8..9175ad9034e1 100644 --- a/drivers/video/fbdev/amba-clcd-nomadik.c +++ b/drivers/video/fbdev/amba-clcd-nomadik.c | |||
@@ -184,32 +184,31 @@ static void tpg110_init(struct device *dev, struct device_node *np, | |||
184 | { | 184 | { |
185 | dev_info(dev, "TPG110 display init\n"); | 185 | dev_info(dev, "TPG110 display init\n"); |
186 | 186 | ||
187 | grestb = devm_get_gpiod_from_child(dev, "grestb", &np->fwnode); | 187 | /* This asserts the GRESTB signal, putting the display into reset */ |
188 | grestb = devm_get_gpiod_from_child(dev, "grestb", &np->fwnode, | ||
189 | GPIOD_OUT_HIGH, "grestb"); | ||
188 | if (IS_ERR(grestb)) { | 190 | if (IS_ERR(grestb)) { |
189 | dev_err(dev, "no GRESTB GPIO\n"); | 191 | dev_err(dev, "no GRESTB GPIO\n"); |
190 | return; | 192 | return; |
191 | } | 193 | } |
192 | /* This asserts the GRESTB signal, putting the display into reset */ | 194 | scen = devm_get_gpiod_from_child(dev, "scen", &np->fwnode, |
193 | gpiod_direction_output(grestb, 1); | 195 | GPIOD_OUT_LOW, "scen"); |
194 | |||
195 | scen = devm_get_gpiod_from_child(dev, "scen", &np->fwnode); | ||
196 | if (IS_ERR(scen)) { | 196 | if (IS_ERR(scen)) { |
197 | dev_err(dev, "no SCEN GPIO\n"); | 197 | dev_err(dev, "no SCEN GPIO\n"); |
198 | return; | 198 | return; |
199 | } | 199 | } |
200 | gpiod_direction_output(scen, 0); | 200 | scl = devm_get_gpiod_from_child(dev, "scl", &np->fwnode, GPIOD_OUT_LOW, |
201 | scl = devm_get_gpiod_from_child(dev, "scl", &np->fwnode); | 201 | "scl"); |
202 | if (IS_ERR(scl)) { | 202 | if (IS_ERR(scl)) { |
203 | dev_err(dev, "no SCL GPIO\n"); | 203 | dev_err(dev, "no SCL GPIO\n"); |
204 | return; | 204 | return; |
205 | } | 205 | } |
206 | gpiod_direction_output(scl, 0); | 206 | sda = devm_get_gpiod_from_child(dev, "sda", &np->fwnode, GPIOD_OUT_LOW, |
207 | sda = devm_get_gpiod_from_child(dev, "sda", &np->fwnode); | 207 | "sda"); |
208 | if (IS_ERR(sda)) { | 208 | if (IS_ERR(sda)) { |
209 | dev_err(dev, "no SDA GPIO\n"); | 209 | dev_err(dev, "no SDA GPIO\n"); |
210 | return; | 210 | return; |
211 | } | 211 | } |
212 | gpiod_direction_output(sda, 0); | ||
213 | board->enable = tpg110_enable; | 212 | board->enable = tpg110_enable; |
214 | board->disable = tpg110_disable; | 213 | board->disable = tpg110_disable; |
215 | } | 214 | } |
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index fb0fde686cb1..80bad7ebde04 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
@@ -135,10 +135,14 @@ int desc_to_gpio(const struct gpio_desc *desc); | |||
135 | struct fwnode_handle; | 135 | struct fwnode_handle; |
136 | 136 | ||
137 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | 137 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
138 | const char *propname); | 138 | const char *propname, |
139 | enum gpiod_flags dflags, | ||
140 | const char *label); | ||
139 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, | 141 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, |
140 | const char *con_id, | 142 | const char *con_id, |
141 | struct fwnode_handle *child); | 143 | struct fwnode_handle *child, |
144 | enum gpiod_flags flags, | ||
145 | const char *label); | ||
142 | #else /* CONFIG_GPIOLIB */ | 146 | #else /* CONFIG_GPIOLIB */ |
143 | 147 | ||
144 | static inline int gpiod_count(struct device *dev, const char *con_id) | 148 | static inline int gpiod_count(struct device *dev, const char *con_id) |
@@ -411,14 +415,21 @@ static inline int desc_to_gpio(const struct gpio_desc *desc) | |||
411 | /* Child properties interface */ | 415 | /* Child properties interface */ |
412 | struct fwnode_handle; | 416 | struct fwnode_handle; |
413 | 417 | ||
414 | static inline struct gpio_desc *fwnode_get_named_gpiod( | 418 | static inline |
415 | struct fwnode_handle *fwnode, const char *propname) | 419 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
420 | const char *propname, | ||
421 | enum gpiod_flags dflags, | ||
422 | const char *label) | ||
416 | { | 423 | { |
417 | return ERR_PTR(-ENOSYS); | 424 | return ERR_PTR(-ENOSYS); |
418 | } | 425 | } |
419 | 426 | ||
420 | static inline struct gpio_desc *devm_get_gpiod_from_child( | 427 | static inline |
421 | struct device *dev, const char *con_id, struct fwnode_handle *child) | 428 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, |
429 | const char *con_id, | ||
430 | struct fwnode_handle *child, | ||
431 | enum gpiod_flags flags, | ||
432 | const char *label) | ||
422 | { | 433 | { |
423 | return ERR_PTR(-ENOSYS); | 434 | return ERR_PTR(-ENOSYS); |
424 | } | 435 | } |