2018-09-25 14:08:48 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-10-21 21:21:31 +07:00
|
|
|
/*
|
|
|
|
* Device property helpers for GPIO chips.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016, Intel Corporation
|
|
|
|
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/property.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/gpio/driver.h>
|
2019-04-05 09:30:25 +07:00
|
|
|
#include <linux/export.h>
|
2016-10-21 21:21:31 +07:00
|
|
|
|
|
|
|
#include "gpiolib.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* devprop_gpiochip_set_names - Set GPIO line names using device properties
|
|
|
|
* @chip: GPIO chip whose lines should be named, if possible
|
2017-12-15 21:02:33 +07:00
|
|
|
* @fwnode: Property Node containing the gpio-line-names property
|
2016-10-21 21:21:31 +07:00
|
|
|
*
|
|
|
|
* Looks for device property "gpio-line-names" and if it exists assigns
|
|
|
|
* GPIO line names for the chip. The memory allocated for the assigned
|
|
|
|
* names belong to the underlying firmware node and should not be released
|
|
|
|
* by the caller.
|
|
|
|
*/
|
2017-12-15 21:02:33 +07:00
|
|
|
void devprop_gpiochip_set_names(struct gpio_chip *chip,
|
|
|
|
const struct fwnode_handle *fwnode)
|
2016-10-21 21:21:31 +07:00
|
|
|
{
|
|
|
|
struct gpio_device *gdev = chip->gpiodev;
|
|
|
|
const char **names;
|
|
|
|
int ret, i;
|
2018-09-28 20:38:43 +07:00
|
|
|
int count;
|
2016-10-21 21:21:31 +07:00
|
|
|
|
2018-09-28 20:38:43 +07:00
|
|
|
count = fwnode_property_read_string_array(fwnode, "gpio-line-names",
|
|
|
|
NULL, 0);
|
|
|
|
if (count < 0)
|
2016-10-21 21:21:31 +07:00
|
|
|
return;
|
|
|
|
|
2020-04-24 03:34:16 +07:00
|
|
|
if (count > gdev->ngpio) {
|
|
|
|
dev_warn(&gdev->dev, "gpio-line-names is length %d but should be at most length %d",
|
|
|
|
count, gdev->ngpio);
|
2018-09-28 20:38:43 +07:00
|
|
|
count = gdev->ngpio;
|
2020-04-24 03:34:16 +07:00
|
|
|
}
|
2016-10-21 21:21:31 +07:00
|
|
|
|
2018-09-28 20:38:43 +07:00
|
|
|
names = kcalloc(count, sizeof(*names), GFP_KERNEL);
|
2016-10-21 21:21:31 +07:00
|
|
|
if (!names)
|
|
|
|
return;
|
|
|
|
|
2017-12-15 21:02:33 +07:00
|
|
|
ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
|
2018-09-28 20:38:43 +07:00
|
|
|
names, count);
|
2016-10-21 21:21:31 +07:00
|
|
|
if (ret < 0) {
|
2017-12-15 21:02:33 +07:00
|
|
|
dev_warn(&gdev->dev, "failed to read GPIO line names\n");
|
2016-10-21 21:21:31 +07:00
|
|
|
kfree(names);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-28 20:38:43 +07:00
|
|
|
for (i = 0; i < count; i++)
|
2016-10-21 21:21:31 +07:00
|
|
|
gdev->descs[i].name = names[i];
|
|
|
|
|
|
|
|
kfree(names);
|
|
|
|
}
|
2019-04-05 09:30:25 +07:00
|
|
|
EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names);
|