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

Configure Feed

Select the types of activity you want to include in your feed.

gpiolib: introduce devm_fwnode_gpiod_get_optional() wrapper

The helper makes it easier to handle optional GPIOs and simplifies the
error handling code.

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/20260126-gpio-devm_fwnode_gpiod_get_optional-v2-1-ec34f8e35077@pengutronix.de
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

authored by

Stefan Kerkmann and committed by
Bartosz Golaszewski
36471374 3a6a36a3

+36
+36
include/linux/gpio/consumer.h
··· 607 607 flags, label); 608 608 } 609 609 610 + /** 611 + * devm_fwnode_gpiod_get_optional - obtain an optional GPIO from firmware node 612 + * @dev: GPIO consumer 613 + * @fwnode: handle of the firmware node 614 + * @con_id: function within the GPIO consumer 615 + * @flags: GPIO initialization flags 616 + * @label: label to attach to the requested GPIO 617 + * 618 + * This function can be used for drivers that get their configuration 619 + * from opaque firmware. 620 + * 621 + * GPIO descriptors returned from this function are automatically disposed on 622 + * driver detach. 623 + * 624 + * Returns: 625 + * The GPIO descriptor corresponding to the optional function @con_id of device 626 + * dev, NULL if no GPIO has been assigned to the requested function, or 627 + * another IS_ERR() code if an error occurred while trying to acquire the GPIO. 628 + */ 629 + static inline 630 + struct gpio_desc *devm_fwnode_gpiod_get_optional(struct device *dev, 631 + struct fwnode_handle *fwnode, 632 + const char *con_id, 633 + enum gpiod_flags flags, 634 + const char *label) 635 + { 636 + struct gpio_desc *desc; 637 + 638 + desc = devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0, 639 + flags, label); 640 + if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) 641 + return NULL; 642 + 643 + return desc; 644 + } 645 + 610 646 struct acpi_gpio_params { 611 647 unsigned int crs_entry_index; 612 648 unsigned short line_index;