Blame view
drivers/gpio/gpiolib-devprop.c
1.69 KB
9427ecbed gpio: Rework of_g... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* * 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 |
822703354 gpio: fix "gpio-l... |
22 |
* @fwnode: Property Node containing the gpio-line-names property |
9427ecbed gpio: Rework of_g... |
23 24 25 26 27 28 |
* * 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. */ |
822703354 gpio: fix "gpio-l... |
29 30 |
void devprop_gpiochip_set_names(struct gpio_chip *chip, const struct fwnode_handle *fwnode) |
9427ecbed gpio: Rework of_g... |
31 32 33 34 |
{ struct gpio_device *gdev = chip->gpiodev; const char **names; int ret, i; |
822703354 gpio: fix "gpio-l... |
35 |
ret = fwnode_property_read_string_array(fwnode, "gpio-line-names", |
9427ecbed gpio: Rework of_g... |
36 37 38 39 40 |
NULL, 0); if (ret < 0) return; if (ret != gdev->ngpio) { |
822703354 gpio: fix "gpio-l... |
41 |
dev_warn(&gdev->dev, |
9427ecbed gpio: Rework of_g... |
42 43 44 45 46 47 48 49 50 |
"names %d do not match number of GPIOs %d ", ret, gdev->ngpio); return; } names = kcalloc(gdev->ngpio, sizeof(*names), GFP_KERNEL); if (!names) return; |
822703354 gpio: fix "gpio-l... |
51 |
ret = fwnode_property_read_string_array(fwnode, "gpio-line-names", |
9427ecbed gpio: Rework of_g... |
52 53 |
names, gdev->ngpio); if (ret < 0) { |
822703354 gpio: fix "gpio-l... |
54 55 |
dev_warn(&gdev->dev, "failed to read GPIO line names "); |
9427ecbed gpio: Rework of_g... |
56 57 58 59 60 61 62 63 64 |
kfree(names); return; } for (i = 0; i < gdev->ngpio; i++) gdev->descs[i].name = names[i]; kfree(names); } |