Skip to content

Commit 7cba1a4

Browse files
committed
gpiolib: generalize devprop_gpiochip_set_names() for device properties
devprop_gpiochip_set_names() is overly complicated with taking the fwnode argument (which requires using dev_fwnode() & of_fwnode_handle() in ACPI and OF GPIO code respectively). Let's just switch to using the generic device properties. This allows us to pull the code setting line names directly into gpiochip_add_data_with_key() instead of handling it separately for ACPI and OF. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
1 parent 6b6ff4a commit 7cba1a4

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

drivers/gpio/gpiolib-acpi.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,9 +1221,6 @@ void acpi_gpiochip_add(struct gpio_chip *chip)
12211221
return;
12221222
}
12231223

1224-
if (!chip->names)
1225-
devprop_gpiochip_set_names(chip, dev_fwnode(chip->parent));
1226-
12271224
acpi_gpiochip_request_regions(acpi_gpio);
12281225
acpi_gpiochip_scan_gpios(acpi_gpio);
12291226
acpi_walk_dep_device_list(handle);

drivers/gpio/gpiolib-devprop.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,23 @@
1717
/**
1818
* devprop_gpiochip_set_names - Set GPIO line names using device properties
1919
* @chip: GPIO chip whose lines should be named, if possible
20-
* @fwnode: Property Node containing the gpio-line-names property
2120
*
2221
* Looks for device property "gpio-line-names" and if it exists assigns
2322
* GPIO line names for the chip. The memory allocated for the assigned
24-
* names belong to the underlying firmware node and should not be released
23+
* names belong to the underlying software node and should not be released
2524
* by the caller.
2625
*/
27-
void devprop_gpiochip_set_names(struct gpio_chip *chip,
28-
const struct fwnode_handle *fwnode)
26+
int devprop_gpiochip_set_names(struct gpio_chip *chip)
2927
{
3028
struct gpio_device *gdev = chip->gpiodev;
29+
struct device *dev = chip->parent;
3130
const char **names;
3231
int ret, i;
3332
int count;
3433

35-
count = fwnode_property_read_string_array(fwnode, "gpio-line-names",
36-
NULL, 0);
34+
count = device_property_string_array_count(dev, "gpio-line-names");
3735
if (count < 0)
38-
return;
36+
return 0;
3937

4038
if (count > gdev->ngpio) {
4139
dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d",
@@ -45,19 +43,21 @@ void devprop_gpiochip_set_names(struct gpio_chip *chip,
4543

4644
names = kcalloc(count, sizeof(*names), GFP_KERNEL);
4745
if (!names)
48-
return;
46+
return -ENOMEM;
4947

50-
ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
48+
ret = device_property_read_string_array(dev, "gpio-line-names",
5149
names, count);
5250
if (ret < 0) {
5351
dev_warn(&gdev->dev, "failed to read GPIO line names\n");
5452
kfree(names);
55-
return;
53+
return ret;
5654
}
5755

5856
for (i = 0; i < count; i++)
5957
gdev->descs[i].name = names[i];
6058

6159
kfree(names);
60+
61+
return 0;
6262
}
6363
EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names);

drivers/gpio/gpiolib-of.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,6 @@ int of_gpiochip_add(struct gpio_chip *chip)
10261026
if (ret)
10271027
return ret;
10281028

1029-
/* If the chip defines names itself, these take precedence */
1030-
if (!chip->names)
1031-
devprop_gpiochip_set_names(chip,
1032-
of_fwnode_handle(chip->of_node));
1033-
10341029
of_node_get(chip->of_node);
10351030

10361031
ret = of_gpiochip_scan_gpios(chip);

drivers/gpio/gpiolib.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,6 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc)
340340
struct gpio_device *gdev = gc->gpiodev;
341341
int i;
342342

343-
if (!gc->names)
344-
return 0;
345-
346343
/* First check all names if they are unique */
347344
for (i = 0; i != gc->ngpio; ++i) {
348345
struct gpio_desc *gpio;
@@ -621,7 +618,10 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
621618
INIT_LIST_HEAD(&gdev->pin_ranges);
622619
#endif
623620

624-
ret = gpiochip_set_desc_names(gc);
621+
if (gc->names)
622+
ret = gpiochip_set_desc_names(gc);
623+
else
624+
ret = devprop_gpiochip_set_names(gc);
625625
if (ret)
626626
goto err_remove_from_list;
627627

include/linux/gpio/driver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,7 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *gc,
756756
enum gpiod_flags dflags);
757757
void gpiochip_free_own_desc(struct gpio_desc *desc);
758758

759-
void devprop_gpiochip_set_names(struct gpio_chip *gc,
760-
const struct fwnode_handle *fwnode);
759+
int devprop_gpiochip_set_names(struct gpio_chip *gc);
761760

762761
#ifdef CONFIG_GPIOLIB
763762

0 commit comments

Comments
 (0)