2 * Device property helpers for GPIO chips.
4 * Copyright (C) 2016, Intel Corporation
5 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/property.h>
13 #include <linux/slab.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/gpio/driver.h>
20 * devprop_gpiochip_set_names - Set GPIO line names using device properties
21 * @chip: GPIO chip whose lines should be named, if possible
23 * Looks for device property "gpio-line-names" and if it exists assigns
24 * GPIO line names for the chip. The memory allocated for the assigned
25 * names belong to the underlying firmware node and should not be released
28 void devprop_gpiochip_set_names(struct gpio_chip
*chip
)
30 struct gpio_device
*gdev
= chip
->gpiodev
;
35 dev_warn(&gdev
->dev
, "GPIO chip parent is NULL\n");
39 ret
= device_property_read_string_array(chip
->parent
, "gpio-line-names",
44 if (ret
!= gdev
->ngpio
) {
45 dev_warn(chip
->parent
,
46 "names %d do not match number of GPIOs %d\n", ret
,
51 names
= kcalloc(gdev
->ngpio
, sizeof(*names
), GFP_KERNEL
);
55 ret
= device_property_read_string_array(chip
->parent
, "gpio-line-names",
58 dev_warn(chip
->parent
, "failed to read GPIO line names\n");
63 for (i
= 0; i
< gdev
->ngpio
; i
++)
64 gdev
->descs
[i
].name
= names
[i
];