diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2019-12-10 05:41:24 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-12-10 05:41:24 +0100 |
commit | f8614d938b219d6a26b49cf3f163eda97cc33f7c (patch) | |
tree | 66968371d21cb7de989c11476f914cbc3765cebf /drivers | |
parent | 8cc83c48d06d9201e1b5cbe326ff59d88fddc0d1 (diff) | |
parent | 54850184bfc3e0ba85bd2e76470549e1cfc4c72d (diff) | |
download | barebox-f8614d938b219d6a26b49cf3f163eda97cc33f7c.tar.gz barebox-f8614d938b219d6a26b49cf3f163eda97cc33f7c.tar.xz |
Merge branch 'for-next/gpio'
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/gpiolib.c | 47 | ||||
-rw-r--r-- | drivers/of/base.c | 122 |
2 files changed, 77 insertions, 92 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f96009896a..9764ddf0f0 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -16,6 +16,7 @@ struct gpio_info { bool requested; bool active_low; char *label; + char *name; }; static struct gpio_info *gpio_desc; @@ -108,6 +109,23 @@ int gpio_find_by_label(const char *label) return -ENOENT; } +int gpio_find_by_name(const char *name) +{ + int i; + + for (i = 0; i < ARCH_NR_GPIOS; i++) { + struct gpio_info *info = &gpio_desc[i]; + + if (!info->chip || !info->name) + continue; + + if (!strcmp(info->name, name)) + return i; + } + + return -ENOENT; +} + void gpio_free(unsigned gpio) { struct gpio_info *gi = gpio_to_desc(gpio); @@ -410,11 +428,25 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip, static int of_gpiochip_scan_hogs(struct gpio_chip *chip) { struct device_node *np; - int ret, i; + int ret, i, count; if (!IS_ENABLED(CONFIG_OFDEVICE) || !chip->dev->device_node) return 0; + count = of_property_count_strings(chip->dev->device_node, "gpio-line-names"); + + if (count > 0) { + const char **arr = xzalloc(count * sizeof(char *)); + + of_property_read_string_array(chip->dev->device_node, + "gpio-line-names", arr, count); + + for (i = 0; i < chip->ngpio && i < count; i++) + gpio_desc[chip->base + i].name = xstrdup(arr[i]); + + free(arr); + } + for_each_available_child_of_node(chip->dev->device_node, np) { if (!of_property_read_bool(np, "gpio-hog")) continue; @@ -500,7 +532,7 @@ static int do_gpiolib(int argc, char *argv[]) gi->chip->base, gi->chip->base + gi->chip->ngpio - 1, gi->chip->dev->name); - printf("%*cdir val requested label\n", 13, ' '); + printf(" %-3s %-3s %-9s %-20s %-20s\n", "dir", "val", "requested", "name", "label"); } if (gi->chip->ops->get_direction) @@ -510,11 +542,12 @@ static int do_gpiolib(int argc, char *argv[]) val = gi->chip->ops->get(gi->chip, i - gi->chip->base); - printf(" GPIO %*d: %*s %*s %*s %s\n", 4, i, - 3, (dir < 0) ? "unk" : ((dir == GPIOF_DIR_IN) ? "in" : "out"), - 3, (val < 0) ? "unk" : ((val == 0) ? "lo" : "hi"), - 12, gi->requested ? (gi->active_low ? "active low" : "true") : "false", - (gi->requested && gi->label) ? gi->label : ""); + printf(" GPIO %4d: %-3s %-3s %-9s %-20s %-20s\n", i, + (dir < 0) ? "unk" : ((dir == GPIOF_DIR_IN) ? "in" : "out"), + (val < 0) ? "unk" : ((val == 0) ? "lo" : "hi"), + gi->requested ? (gi->active_low ? "active low" : "true") : "false", + gi->name ? gi->name : "", + gi->label ? gi->label : ""); } return 0; diff --git a/drivers/of/base.c b/drivers/of/base.c index 98ef5fc0d4..80ceeab13b 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -887,54 +887,6 @@ int of_property_read_string(struct device_node *np, const char *propname, EXPORT_SYMBOL_GPL(of_property_read_string); /** - * of_property_read_string_index - Find and read a string from a multiple - * strings property. - * @np: device node from which the property value is to be read. - * @propname: name of the property to be searched. - * @index: index of the string in the list of strings - * @out_string: pointer to null terminated return string, modified only if - * return value is 0. - * - * Search for a property in a device tree node and retrieve a null - * terminated string value (pointer to data, not a copy) in the list of strings - * contained in that property. - * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if - * property does not have a value, and -EILSEQ if the string is not - * null-terminated within the length of the property data. - * - * The out_string pointer is modified only if a valid string can be decoded. - */ -int of_property_read_string_index(struct device_node *np, const char *propname, - int index, const char **output) -{ - struct property *prop = of_find_property(np, propname, NULL); - int i = 0; - size_t l = 0, total = 0; - const char *p; - const void *value; - - if (!prop) - return -EINVAL; - value = of_property_get_value(prop); - if (!value) - return -ENODATA; - if (strnlen(value, prop->length) >= prop->length) - return -EILSEQ; - - p = value; - - for (i = 0; total < prop->length; total += l, p += l) { - l = strlen(p) + 1; - if (i++ == index) { - *output = p; - return 0; - } - } - return -ENODATA; -} -EXPORT_SYMBOL_GPL(of_property_read_string_index); - -/** * of_property_match_string() - Find string in a list and return index * @np: pointer to node containing string list property * @propname: string list property name @@ -972,43 +924,6 @@ int of_property_match_string(struct device_node *np, const char *propname, } EXPORT_SYMBOL_GPL(of_property_match_string); -/** - * of_property_count_strings - Find and return the number of strings from a - * multiple strings property. - * @np: device node from which the property value is to be read. - * @propname: name of the property to be searched. - * - * Search for a property in a device tree node and retrieve the number of null - * terminated string contain in it. Returns the number of strings on - * success, -EINVAL if the property does not exist, -ENODATA if property - * does not have a value, and -EILSEQ if the string is not null-terminated - * within the length of the property data. - */ -int of_property_count_strings(struct device_node *np, const char *propname) -{ - struct property *prop = of_find_property(np, propname, NULL); - int i = 0; - size_t l = 0, total = 0; - const char *p; - const void *value; - - if (!prop) - return -EINVAL; - value = of_property_get_value(prop); - if (!value) - return -ENODATA; - if (strnlen(value, prop->length) >= prop->length) - return -EILSEQ; - - p = value; - - for (i = 0; total < prop->length; total += l, p += l, i++) - l = strlen(p) + 1; - - return i; -} -EXPORT_SYMBOL_GPL(of_property_count_strings); - const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur, u32 *pu) { @@ -1777,6 +1692,43 @@ struct device_node *of_get_child_by_name(const struct device_node *node, } EXPORT_SYMBOL(of_get_child_by_name); +/** + * of_property_read_string_helper() - Utility helper for parsing string properties + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @out_strs: output array of string pointers. + * @sz: number of array elements to read. + * @skip: Number of strings to skip over at beginning of list. + * + * Don't call this function directly. It is a utility helper for the + * of_property_read_string*() family of functions. + */ +int of_property_read_string_helper(const struct device_node *np, + const char *propname, const char **out_strs, + size_t sz, int skip) +{ + const struct property *prop = of_find_property(np, propname, NULL); + int l = 0, i = 0; + const char *p, *end; + + if (!prop) + return -EINVAL; + if (!prop->value) + return -ENODATA; + p = prop->value; + end = p + prop->length; + + for (i = 0; p < end && (!out_strs || i < skip + sz); i++, p += l) { + l = strnlen(p, end - p) + 1; + if (p + l > end) + return -EILSEQ; + if (out_strs && i >= skip) + *out_strs++ = p; + } + i -= skip; + return i <= 0 ? -ENODATA : i; +} + static void __of_print_nodes(struct device_node *node, int indent, const char *prefix) { struct device_node *n; |