1 // SPDX-License-Identifier: GPL-2.0
3 * Device property helpers for GPIO chips.
5 * Copyright (C) 2016, Intel Corporation
6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
9 #include <linux/property.h>
10 #include <linux/slab.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/gpio/driver.h>
17 * devprop_gpiochip_set_names - Set GPIO line names using device properties
18 * @chip: GPIO chip whose lines should be named, if possible
19 * @fwnode: Property Node containing the gpio-line-names property
21 * Looks for device property "gpio-line-names" and if it exists assigns
22 * GPIO line names for the chip. The memory allocated for the assigned
23 * names belong to the underlying firmware node and should not be released
26 void devprop_gpiochip_set_names(struct gpio_chip
*chip
,
27 const struct fwnode_handle
*fwnode
)
29 struct gpio_device
*gdev
= chip
->gpiodev
;
34 count
= fwnode_property_read_string_array(fwnode
, "gpio-line-names",
39 if (count
> gdev
->ngpio
)
42 names
= kcalloc(count
, sizeof(*names
), GFP_KERNEL
);
46 ret
= fwnode_property_read_string_array(fwnode
, "gpio-line-names",
49 dev_warn(&gdev
->dev
, "failed to read GPIO line names\n");
54 for (i
= 0; i
< count
; i
++)
55 gdev
->descs
[i
].name
= names
[i
];