2016-10-21 22:21:31 +08:00
|
|
|
/*
|
|
|
|
* Device property helpers for GPIO chips.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016, Intel Corporation
|
|
|
|
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/property.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/gpio/driver.h>
|
|
|
|
|
|
|
|
#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 22:02:33 +08:00
|
|
|
* @fwnode: Property Node containing the gpio-line-names property
|
2016-10-21 22:21:31 +08: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 22:02:33 +08:00
|
|
|
void devprop_gpiochip_set_names(struct gpio_chip *chip,
|
|
|
|
const struct fwnode_handle *fwnode)
|
2016-10-21 22:21:31 +08:00
|
|
|
{
|
|
|
|
struct gpio_device *gdev = chip->gpiodev;
|
|
|
|
const char **names;
|
|
|
|
int ret, i;
|
|
|
|
|
2017-12-15 22:02:33 +08:00
|
|
|
ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
|
2016-10-21 22:21:31 +08:00
|
|
|
NULL, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ret != gdev->ngpio) {
|
2017-12-15 22:02:33 +08:00
|
|
|
dev_warn(&gdev->dev,
|
2016-10-21 22:21:31 +08:00
|
|
|
"names %d do not match number of GPIOs %d\n", ret,
|
|
|
|
gdev->ngpio);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
names = kcalloc(gdev->ngpio, sizeof(*names), GFP_KERNEL);
|
|
|
|
if (!names)
|
|
|
|
return;
|
|
|
|
|
2017-12-15 22:02:33 +08:00
|
|
|
ret = fwnode_property_read_string_array(fwnode, "gpio-line-names",
|
2016-10-21 22:21:31 +08:00
|
|
|
names, gdev->ngpio);
|
|
|
|
if (ret < 0) {
|
2017-12-15 22:02:33 +08:00
|
|
|
dev_warn(&gdev->dev, "failed to read GPIO line names\n");
|
2016-10-21 22:21:31 +08:00
|
|
|
kfree(names);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < gdev->ngpio; i++)
|
|
|
|
gdev->descs[i].name = names[i];
|
|
|
|
|
|
|
|
kfree(names);
|
|
|
|
}
|