Skip to content

Commit adcad53

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
gpio: of: Make of_gpio_get_count() take firmware node as a parameter
Make of_gpio_get_count() take firmware node as a parameter in order to be aligned with other functions and decouple from unused device pointer. The latter helps to create a common fwnode_gpio_count() in the future. While at it, rename to be of_gpio_count() to be aligned with the others. Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 0d776cf commit adcad53

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int of_gpio_named_count(const struct device_node *np,
6868

6969
/**
7070
* of_gpio_spi_cs_get_count() - special GPIO counting for SPI
71-
* @dev: Consuming device
71+
* @np: Consuming device node
7272
* @con_id: Function within the GPIO consumer
7373
*
7474
* Some elder GPIO controllers need special quirks. Currently we handle
@@ -78,10 +78,9 @@ static int of_gpio_named_count(const struct device_node *np,
7878
* the counting of "cs-gpios" to count "gpios" transparent to the
7979
* driver.
8080
*/
81-
static int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
81+
static int of_gpio_spi_cs_get_count(const struct device_node *np,
82+
const char *con_id)
8283
{
83-
struct device_node *np = dev->of_node;
84-
8584
if (!IS_ENABLED(CONFIG_SPI_MASTER))
8685
return 0;
8786
if (!con_id || strcmp(con_id, "cs"))
@@ -93,13 +92,14 @@ static int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
9392
return of_gpio_named_count(np, "gpios");
9493
}
9594

96-
int of_gpio_get_count(struct device *dev, const char *con_id)
95+
int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
9796
{
97+
const struct device_node *np = to_of_node(fwnode);
9898
int ret;
9999
char propname[32];
100100
unsigned int i;
101101

102-
ret = of_gpio_spi_cs_get_count(dev, con_id);
102+
ret = of_gpio_spi_cs_get_count(np, con_id);
103103
if (ret > 0)
104104
return ret;
105105

@@ -111,7 +111,7 @@ int of_gpio_get_count(struct device *dev, const char *con_id)
111111
snprintf(propname, sizeof(propname), "%s",
112112
gpio_suffixes[i]);
113113

114-
ret = of_gpio_named_count(dev->of_node, propname);
114+
ret = of_gpio_named_count(np, propname);
115115
if (ret > 0)
116116
break;
117117
}

drivers/gpio/gpiolib-of.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/notifier.h>
1010

1111
struct device;
12+
struct fwnode_handle;
1213

1314
struct gpio_chip;
1415
struct gpio_desc;
@@ -21,7 +22,7 @@ struct gpio_desc *of_find_gpio(struct device_node *np,
2122
unsigned long *lookupflags);
2223
int of_gpiochip_add(struct gpio_chip *gc);
2324
void of_gpiochip_remove(struct gpio_chip *gc);
24-
int of_gpio_get_count(struct device *dev, const char *con_id);
25+
int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id);
2526
#else
2627
static inline struct gpio_desc *of_find_gpio(struct device_node *np,
2728
const char *con_id,
@@ -32,7 +33,8 @@ static inline struct gpio_desc *of_find_gpio(struct device_node *np,
3233
}
3334
static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; }
3435
static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
35-
static inline int of_gpio_get_count(struct device *dev, const char *con_id)
36+
static inline int of_gpio_count(const struct fwnode_handle *fwnode,
37+
const char *con_id)
3638
{
3739
return 0;
3840
}

drivers/gpio/gpiolib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4285,7 +4285,7 @@ int gpiod_count(struct device *dev, const char *con_id)
42854285
int count = -ENOENT;
42864286

42874287
if (is_of_node(fwnode))
4288-
count = of_gpio_get_count(dev, con_id);
4288+
count = of_gpio_count(fwnode, con_id);
42894289
else if (is_acpi_node(fwnode))
42904290
count = acpi_gpio_count(dev, con_id);
42914291
else if (is_software_node(fwnode))

0 commit comments

Comments
 (0)