Commit a79fead5 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Linus Walleij

gpio: of: Add support for multiple GPIOs in a single GPIO hog

When listing multiple GPIOs in the "gpios" property of a GPIO hog, only
the first GPIO is affected.  The user is left clueless about the
dysfunctioning of the other GPIOs specified.

Fix this by adding and documenting support for specifying multiple
GPIOs in a single GPIO hog.
Signed-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Acked-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent baddc7ca
...@@ -187,10 +187,10 @@ gpio-controller's driver probe function. ...@@ -187,10 +187,10 @@ gpio-controller's driver probe function.
Each GPIO hog definition is represented as a child node of the GPIO controller. Each GPIO hog definition is represented as a child node of the GPIO controller.
Required properties: Required properties:
- gpio-hog: A property specifying that this child node represent a GPIO hog. - gpio-hog: A property specifying that this child node represents a GPIO hog.
- gpios: Store the GPIO information (id, flags, ...). Shall contain the - gpios: Store the GPIO information (id, flags, ...) for each GPIO to
number of cells specified in its parent node (GPIO controller affect. Shall contain an integer multiple of the number of cells
node). specified in its parent node (GPIO controller node).
Only one of the following properties scanned in the order shown below. Only one of the following properties scanned in the order shown below.
This means that when multiple properties are present they will be searched This means that when multiple properties are present they will be searched
in the order presented below and the first match is taken as the intended in the order presented below and the first match is taken as the intended
......
...@@ -160,6 +160,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, ...@@ -160,6 +160,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
* of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
* @np: device node to get GPIO from * @np: device node to get GPIO from
* @chip: GPIO chip whose hog is parsed * @chip: GPIO chip whose hog is parsed
* @idx: Index of the GPIO to parse
* @name: GPIO line name * @name: GPIO line name
* @lflags: gpio_lookup_flags - returned from of_find_gpio() or * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
* of_parse_own_gpio() * of_parse_own_gpio()
...@@ -170,7 +171,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, ...@@ -170,7 +171,7 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
*/ */
static struct gpio_desc *of_parse_own_gpio(struct device_node *np, static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
struct gpio_chip *chip, struct gpio_chip *chip,
const char **name, unsigned int idx, const char **name,
enum gpio_lookup_flags *lflags, enum gpio_lookup_flags *lflags,
enum gpiod_flags *dflags) enum gpiod_flags *dflags)
{ {
...@@ -178,6 +179,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ...@@ -178,6 +179,7 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
enum of_gpio_flags xlate_flags; enum of_gpio_flags xlate_flags;
struct of_phandle_args gpiospec; struct of_phandle_args gpiospec;
struct gpio_desc *desc; struct gpio_desc *desc;
unsigned int i;
u32 tmp; u32 tmp;
int ret; int ret;
...@@ -196,9 +198,12 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np, ...@@ -196,9 +198,12 @@ static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
gpiospec.np = chip_np; gpiospec.np = chip_np;
gpiospec.args_count = tmp; gpiospec.args_count = tmp;
ret = of_property_read_u32_array(np, "gpios", gpiospec.args, tmp); for (i = 0; i < tmp; i++) {
if (ret) ret = of_property_read_u32_index(np, "gpios", idx * tmp + i,
return ERR_PTR(ret); &gpiospec.args[i]);
if (ret)
return ERR_PTR(ret);
}
desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags); desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags);
if (IS_ERR(desc)) if (IS_ERR(desc))
...@@ -240,20 +245,24 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip) ...@@ -240,20 +245,24 @@ static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
const char *name; const char *name;
enum gpio_lookup_flags lflags; enum gpio_lookup_flags lflags;
enum gpiod_flags dflags; enum gpiod_flags dflags;
unsigned int i;
int ret; int ret;
for_each_available_child_of_node(chip->of_node, np) { for_each_available_child_of_node(chip->of_node, np) {
if (!of_property_read_bool(np, "gpio-hog")) if (!of_property_read_bool(np, "gpio-hog"))
continue; continue;
desc = of_parse_own_gpio(np, chip, &name, &lflags, &dflags); for (i = 0;; i++) {
if (IS_ERR(desc)) desc = of_parse_own_gpio(np, chip, i, &name, &lflags,
continue; &dflags);
if (IS_ERR(desc))
break;
ret = gpiod_hog(desc, name, lflags, dflags); ret = gpiod_hog(desc, name, lflags, dflags);
if (ret < 0) { if (ret < 0) {
of_node_put(np); of_node_put(np);
return ret; return ret;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment