Since commit d1d564ec4992 ("gpio: move hogs into GPIO core"), gpiochip_add_hog() takes the hogged line from the first cell of the "gpios" property. The of_xlate() callback is still called for OF nodes but only to get the flags so on controllers that compute the offset in of_xlate() (sunxi, Qualcomm PMIC GPIOs, tegra186, ...) the wrong line is hogged. Use the descriptor returned by of_xlate() for OF nodes. Cc: stable@vger.kernel.org Fixes: d1d564ec4992 ("gpio: move hogs into GPIO core") Reported-by: Norman Herms Closes: https://lore.kernel.org/all/qh4LV99kGaQYdQuGbsPX4b9Fm6Cip_Ow7ImY4icfwI8IsbMQy_09FovZY82b-_HVkDmR2ELMlKe8bzCuBB5NpaZizoO-s4tc11zAX30FDhw=@proton.me/ Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-of.c | 10 +++++----- drivers/gpio/gpiolib-of.h | 15 ++++++++------- drivers/gpio/gpiolib.c | 14 +++++++------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 8bc4562608e1141983300132b90758ce68d7625d..072f84a83c3c657baebd88694f062849b7526a79 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -749,9 +749,9 @@ struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id, return desc; } -int of_gpiochip_get_lflags(struct gpio_chip *chip, - struct fwnode_reference_args *gpiospec, - unsigned long *lflags) +struct gpio_desc *of_gpiochip_get_hog_desc(struct gpio_chip *chip, + struct fwnode_reference_args *gpiospec, + unsigned long *lflags) { enum of_gpio_flags xlate_flags = 0; struct of_phandle_args args; @@ -765,11 +765,11 @@ int of_gpiochip_get_lflags(struct gpio_chip *chip, desc = of_xlate_and_get_gpiod_flags(chip, &args, &xlate_flags); if (IS_ERR(desc)) - return PTR_ERR(desc); + return desc; *lflags = of_convert_gpio_flags(xlate_flags); - return 0; + return desc; } #ifdef CONFIG_OF_DYNAMIC diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h index 9ca540d93f93be9c1b4791c7add0936527646849..347b82f9e3ff4dcca6b919c058270cc721c81541 100644 --- a/drivers/gpio/gpiolib-of.h +++ b/drivers/gpio/gpiolib-of.h @@ -25,9 +25,9 @@ int of_gpiochip_add(struct gpio_chip *gc); void of_gpiochip_remove(struct gpio_chip *gc); bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index); int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id); -int of_gpiochip_get_lflags(struct gpio_chip *chip, - struct fwnode_reference_args *gpiospec, - unsigned long *lflags); +struct gpio_desc *of_gpiochip_get_hog_desc(struct gpio_chip *chip, + struct fwnode_reference_args *gpiospec, + unsigned long *lflags); #else static inline struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id, @@ -48,11 +48,12 @@ static inline int of_gpio_count(const struct fwnode_handle *fwnode, { return -ENOENT; } -static inline int of_gpiochip_get_lflags(struct gpio_chip *chip, - struct fwnode_reference_args *gpiospec, - unsigned long *lflags) +static inline struct gpio_desc * +of_gpiochip_get_hog_desc(struct gpio_chip *chip, + struct fwnode_reference_args *gpiospec, + unsigned long *lflags) { - return -ENOENT; + return ERR_PTR(-ENOENT); } #endif /* CONFIG_OF_GPIO */ diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c09342fc52cb7fce163e807ba134ecd0e1389436..889ed7e420c19c9a69c9149ead3ea370d7cbbdea 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1036,9 +1036,9 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) for (unsigned int j = 0; j < cells; j++) gpiospec.args[j] = gpios[i * cells + j]; - ret = of_gpiochip_get_lflags(gc, &gpiospec, &lflags); - if (ret) - return ret; + desc = of_gpiochip_get_hog_desc(gc, &gpiospec, &lflags); + if (IS_ERR(desc)) + return PTR_ERR(desc); /* * If no line-name property is present, fall back to the OF @@ -1054,11 +1054,11 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode) */ if (cells > 1 && gpios[i * cells + 1]) lflags |= GPIO_ACTIVE_LOW; - } - desc = gpiochip_get_desc(gc, gpios[i * cells]); - if (IS_ERR(desc)) - return PTR_ERR(desc); + desc = gpiochip_get_desc(gc, gpios[i * cells]); + if (IS_ERR(desc)) + return PTR_ERR(desc); + } ret = gpiod_hog(desc, name, lflags, dflags); if (ret) --- base-commit: 3dd8c790a7b7027abdd568e36db5e82ffaea7c77 change-id: 20261125-gpio-three-cell-hog-22742394ea02 Best regards, -- Bartosz Golaszewski