1
2
3
4
5
6
7
8
9#include <linux/property.h>
10#include <linux/slab.h>
11#include <linux/gpio/consumer.h>
12#include <linux/gpio/driver.h>
13#include <linux/export.h>
14
15#include "gpiolib.h"
16
17
18
19
20
21
22
23
24
25
26
27void devprop_gpiochip_set_names(struct gpio_chip *chip,
28 const struct fwnode_handle *fwnode)
29{
30 struct gpio_device *gdev = chip->gpiodev;
31 const char **names;
32 int ret, i;
33 int count;
34
35 count = fwnode_property_read_string_array(fwnode, "gpio-line-names",
36 NULL, 0);
37 if (count < 0)
38 return;
39
40 if (count > gdev->ngpio)
41 count = gdev->ngpio;
42
43 names = kcalloc(count, sizeof(*names), GFP_KERNEL);
44 if (!names)
45 return;
46
47 ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
48 names, count);
49 if (ret < 0) {
50 dev_warn(&gdev->dev, "failed to read GPIO line names\n");
51 kfree(names);
52 return;
53 }
54
55 for (i = 0; i < count; i++)
56 gdev->descs[i].name = names[i];
57
58 kfree(names);
59}
60EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names);
61