Skip to content

Commit 07445ae

Browse files
dtorBartosz Golaszewski
authored andcommitted
gpiolib: of: change of_find_gpio() to accept device node
In preparation of switching all OF-based GPIO lookups to go through of_find_gpio() let's change it to accept device node as its argument as we do not always have access to device structure. Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Linus Walleij <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 8dab99c commit 07445ae

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ static const of_find_gpio_quirk of_find_gpio_quirks[] = {
605605
NULL
606606
};
607607

608-
struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
608+
struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id,
609609
unsigned int idx, unsigned long *flags)
610610
{
611611
char prop_name[32]; /* 32 is max size of property name */
@@ -623,16 +623,15 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
623623
snprintf(prop_name, sizeof(prop_name), "%s",
624624
gpio_suffixes[i]);
625625

626-
desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
627-
&of_flags);
626+
desc = of_get_named_gpiod_flags(np, prop_name, idx, &of_flags);
628627

629628
if (!gpiod_not_found(desc))
630629
break;
631630
}
632631

633632
/* Properly named GPIO was not found, try workarounds */
634633
for (q = of_find_gpio_quirks; gpiod_not_found(desc) && *q; q++)
635-
desc = (*q)(dev->of_node, con_id, idx, &of_flags);
634+
desc = (*q)(np, con_id, idx, &of_flags);
636635

637636
if (IS_ERR(desc))
638637
return desc;

drivers/gpio/gpiolib-of.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct gpio_chip;
77
enum of_gpio_flags;
88

99
#ifdef CONFIG_OF_GPIO
10-
struct gpio_desc *of_find_gpio(struct device *dev,
10+
struct gpio_desc *of_find_gpio(struct device_node *np,
1111
const char *con_id,
1212
unsigned int idx,
1313
unsigned long *lookupflags);
@@ -16,7 +16,7 @@ void of_gpiochip_remove(struct gpio_chip *gc);
1616
int of_gpio_get_count(struct device *dev, const char *con_id);
1717
void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev);
1818
#else
19-
static inline struct gpio_desc *of_find_gpio(struct device *dev,
19+
static inline struct gpio_desc *of_find_gpio(struct device_node *np,
2020
const char *con_id,
2121
unsigned int idx,
2222
unsigned long *lookupflags)

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4122,14 +4122,15 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
41224122
int ret;
41234123
/* Maybe we have a device name, maybe not */
41244124
const char *devname = dev ? dev_name(dev) : "?";
4125-
const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL;
4125+
struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL;
41264126

41274127
dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
41284128

41294129
/* Using device tree? */
41304130
if (is_of_node(fwnode)) {
41314131
dev_dbg(dev, "using device tree for GPIO lookup\n");
4132-
desc = of_find_gpio(dev, con_id, idx, &lookupflags);
4132+
desc = of_find_gpio(to_of_node(fwnode),
4133+
con_id, idx, &lookupflags);
41334134
} else if (is_acpi_node(fwnode)) {
41344135
dev_dbg(dev, "using ACPI for GPIO lookup\n");
41354136
desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags);

0 commit comments

Comments
 (0)