forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpio: Rework of_gpiochip_set_names() to use device property accessors
In order to use "gpio-line-names" property in systems not having DT as their boot firmware, rework of_gpiochip_set_names() to use device property accessors. This reworked function is placed in a separate file making it clear it deals with universal device properties. Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
- Loading branch information
Showing
4 changed files
with
66 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 | ||
* | ||
* 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. | ||
*/ | ||
void devprop_gpiochip_set_names(struct gpio_chip *chip) | ||
{ | ||
struct gpio_device *gdev = chip->gpiodev; | ||
const char **names; | ||
int ret, i; | ||
|
||
ret = device_property_read_string_array(chip->parent, "gpio-line-names", | ||
NULL, 0); | ||
if (ret < 0) | ||
return; | ||
|
||
if (ret != gdev->ngpio) { | ||
dev_warn(chip->parent, | ||
"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; | ||
|
||
ret = device_property_read_string_array(chip->parent, "gpio-line-names", | ||
names, gdev->ngpio); | ||
if (ret < 0) { | ||
dev_warn(chip->parent, "failed to read GPIO line names\n"); | ||
kfree(names); | ||
return; | ||
} | ||
|
||
for (i = 0; i < gdev->ngpio; i++) | ||
gdev->descs[i].name = names[i]; | ||
|
||
kfree(names); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters