Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpiolib: Convert fwnode_get_named_gpiod() to configure GPIO

Make fwnode_get_named_gpiod() consistent with the rest of
gpiod_get() like API, i.e. configure GPIO pin immediately after
request.

Besides obvious clean up it will help to configure pins based
on firmware provided resources.

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Andy Shevchenko and committed by
Linus Walleij
a264d10f 7ce7d89f

+45 -40
+7 -2
drivers/gpio/devres.c
··· 127 127 * @dev: GPIO consumer 128 128 * @con_id: function within the GPIO consumer 129 129 * @child: firmware node (child of @dev) 130 + * @flags: GPIO initialization flags 130 131 * 131 132 * GPIO descriptors returned from this function are automatically disposed on 132 133 * driver detach. 134 + * 135 + * On successfull request the GPIO pin is configured in accordance with 136 + * provided @flags. 133 137 */ 134 138 struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, 135 139 const char *con_id, 136 - struct fwnode_handle *child) 140 + struct fwnode_handle *child, 141 + enum gpiod_flags flags) 137 142 { 138 143 static const char * const suffixes[] = { "gpios", "gpio" }; 139 144 char prop_name[32]; /* 32 is max size of property name */ ··· 159 154 snprintf(prop_name, sizeof(prop_name), "%s", 160 155 suffixes[i]); 161 156 162 - desc = fwnode_get_named_gpiod(child, prop_name); 157 + desc = fwnode_get_named_gpiod(child, prop_name, flags); 163 158 if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) 164 159 break; 165 160 }
+16 -4
drivers/gpio/gpiolib.c
··· 3309 3309 * fwnode_get_named_gpiod - obtain a GPIO from firmware node 3310 3310 * @fwnode: handle of the firmware node 3311 3311 * @propname: name of the firmware property representing the GPIO 3312 + * @dflags: GPIO initialization flags 3312 3313 * 3313 3314 * This function can be used for drivers that get their configuration 3314 3315 * from firmware. ··· 3318 3317 * underlying firmware interface and then makes sure that the GPIO 3319 3318 * descriptor is requested before it is returned to the caller. 3320 3319 * 3320 + * On successfull request the GPIO pin is configured in accordance with 3321 + * provided @dflags. 3322 + * 3321 3323 * In case of error an ERR_PTR() is returned. 3322 3324 */ 3323 3325 struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, 3324 - const char *propname) 3326 + const char *propname, 3327 + enum gpiod_flags dflags) 3325 3328 { 3326 3329 struct gpio_desc *desc = ERR_PTR(-ENODEV); 3330 + unsigned long lflags = 0; 3327 3331 bool active_low = false; 3328 3332 bool single_ended = false; 3329 3333 int ret; ··· 3361 3355 return ERR_PTR(ret); 3362 3356 3363 3357 if (active_low) 3364 - set_bit(FLAG_ACTIVE_LOW, &desc->flags); 3358 + lflags |= GPIO_ACTIVE_LOW; 3365 3359 3366 3360 if (single_ended) { 3367 3361 if (active_low) 3368 - set_bit(FLAG_OPEN_DRAIN, &desc->flags); 3362 + lflags |= GPIO_OPEN_DRAIN; 3369 3363 else 3370 - set_bit(FLAG_OPEN_SOURCE, &desc->flags); 3364 + lflags |= GPIO_OPEN_SOURCE; 3365 + } 3366 + 3367 + ret = gpiod_configure_flags(desc, propname, lflags, dflags); 3368 + if (ret < 0) { 3369 + gpiod_put(desc); 3370 + return ERR_PTR(ret); 3371 3371 } 3372 3372 3373 3373 return desc;
+1 -8
drivers/input/keyboard/gpio_keys.c
··· 481 481 spin_lock_init(&bdata->lock); 482 482 483 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, GPIOD_IN); 485 485 if (IS_ERR(bdata->gpiod)) { 486 486 error = PTR_ERR(bdata->gpiod); 487 487 if (error == -ENOENT) { ··· 494 494 if (error != -EPROBE_DEFER) 495 495 dev_err(dev, "failed to get gpio: %d\n", 496 496 error); 497 - return error; 498 - } 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 497 return error; 505 498 } 506 499 }
+2 -9
drivers/input/keyboard/gpio_keys_polled.c
··· 304 304 } 305 305 306 306 bdata->gpiod = devm_get_gpiod_from_child(dev, NULL, 307 - child); 307 + child, 308 + GPIOD_IN); 308 309 if (IS_ERR(bdata->gpiod)) { 309 310 error = PTR_ERR(bdata->gpiod); 310 311 if (error != -EPROBE_DEFER) 311 312 dev_err(dev, 312 313 "failed to get gpio: %d\n", 313 314 error); 314 - fwnode_handle_put(child); 315 - return error; 316 - } 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 315 fwnode_handle_put(child); 323 316 return error; 324 317 }
+1 -1
drivers/leds/leds-gpio.c
··· 174 174 const char *state = NULL; 175 175 struct device_node *np = to_of_node(child); 176 176 177 - led.gpiod = devm_get_gpiod_from_child(dev, NULL, child); 177 + led.gpiod = devm_get_gpiod_from_child(dev, NULL, child, GPIOD_ASIS); 178 178 if (IS_ERR(led.gpiod)) { 179 179 fwnode_handle_put(child); 180 180 return ERR_CAST(led.gpiod);
+5 -10
drivers/video/fbdev/amba-clcd-nomadik.c
··· 184 184 { 185 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, GPIOD_OUT_HIGH); 188 189 if (IS_ERR(grestb)) { 189 190 dev_err(dev, "no GRESTB GPIO\n"); 190 191 return; 191 192 } 192 - /* This asserts the GRESTB signal, putting the display into reset */ 193 - gpiod_direction_output(grestb, 1); 194 - 195 - scen = devm_get_gpiod_from_child(dev, "scen", &np->fwnode); 193 + scen = devm_get_gpiod_from_child(dev, "scen", &np->fwnode, GPIOD_OUT_LOW); 196 194 if (IS_ERR(scen)) { 197 195 dev_err(dev, "no SCEN GPIO\n"); 198 196 return; 199 197 } 200 - gpiod_direction_output(scen, 0); 201 - scl = devm_get_gpiod_from_child(dev, "scl", &np->fwnode); 198 + scl = devm_get_gpiod_from_child(dev, "scl", &np->fwnode, GPIOD_OUT_LOW); 202 199 if (IS_ERR(scl)) { 203 200 dev_err(dev, "no SCL GPIO\n"); 204 201 return; 205 202 } 206 - gpiod_direction_output(scl, 0); 207 - sda = devm_get_gpiod_from_child(dev, "sda", &np->fwnode); 203 + sda = devm_get_gpiod_from_child(dev, "sda", &np->fwnode, GPIOD_OUT_LOW); 208 204 if (IS_ERR(sda)) { 209 205 dev_err(dev, "no SDA GPIO\n"); 210 206 return; 211 207 } 212 - gpiod_direction_output(sda, 0); 213 208 board->enable = tpg110_enable; 214 209 board->disable = tpg110_disable; 215 210 }
+13 -6
include/linux/gpio/consumer.h
··· 135 135 struct fwnode_handle; 136 136 137 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); 139 140 struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, 140 141 const char *con_id, 141 - struct fwnode_handle *child); 142 + struct fwnode_handle *child, 143 + enum gpiod_flags flags); 142 144 #else /* CONFIG_GPIOLIB */ 143 145 144 146 static inline int gpiod_count(struct device *dev, const char *con_id) ··· 413 411 /* Child properties interface */ 414 412 struct fwnode_handle; 415 413 416 - static inline struct gpio_desc *fwnode_get_named_gpiod( 417 - struct fwnode_handle *fwnode, const char *propname) 414 + static inline 415 + struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, 416 + const char *propname, 417 + enum gpiod_flags dflags) 418 418 { 419 419 return ERR_PTR(-ENOSYS); 420 420 } 421 421 422 - static inline struct gpio_desc *devm_get_gpiod_from_child( 423 - struct device *dev, const char *con_id, struct fwnode_handle *child) 422 + static inline 423 + struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, 424 + const char *con_id, 425 + struct fwnode_handle *child, 426 + enum gpiod_flags flags) 424 427 { 425 428 return ERR_PTR(-ENOSYS); 426 429 }