From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: mfe@pengutronix.de, Jules Maselbas <jmaselbas@kalray.eu>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 01/10] gpiolib: fix gpio-hog functionality
Date: Wed, 14 Jun 2023 12:07:38 +0200 [thread overview]
Message-ID: <20230614100747.3368109-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230614100747.3368109-1-a.fatoum@pengutronix.de>
From: Marco Felsch <m.felsch@pengutronix.de>
This reverts commit 3641d381e63321016e3bf09504852a6b2a2f879b.
Since the of_xlate support the gpio-hog support is broken because the
'gpio' property used to specify the gpio-hog pin does not contain any
phandle. Due to the fact that of_xlate was never implemented the easiest
way to fix the gpio-hog functionality is to revert the commit.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Fixes gpio-hog regression in master. sunxi problem is fixed in the
rest of series, but that's not upstream yet, so can go through next.
v1 -> v2:
no change
---
drivers/gpio/gpiolib.c | 64 ++++++++++++++++++++----------------------
drivers/of/of_gpio.c | 5 ++--
include/gpio.h | 4 +--
3 files changed, 33 insertions(+), 40 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6ec63b1119b5..b4a3a4e5504c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -444,28 +444,45 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
unsigned int idx)
{
struct device_node *chip_np = chip->dev->of_node;
- struct of_phandle_args gpiospec;
unsigned long flags = 0;
- u32 gpio_flags;
+ u32 gpio_cells, gpio_num, gpio_flags;
int ret, gpio;
const char *name = NULL;
- ret = of_parse_phandle_with_args(chip_np, "gpios", "#gpio-cells", idx,
- &gpiospec);
+ ret = of_property_read_u32(chip_np, "#gpio-cells", &gpio_cells);
if (ret)
return ret;
- gpio = gpio_of_xlate(chip->dev, &gpiospec, &gpio_flags);
- if (gpio == -EPROBE_DEFER)
- return gpio;
- if (gpio < 0) {
- dev_err(chip->dev, "unable to get gpio: %d\n", gpio);
- return gpio;
- }
+ /*
+ * Support for GPIOs that don't have #gpio-cells set to 2 is
+ * not implemented
+ */
+ if (WARN_ON(gpio_cells != 2))
+ return -ENOTSUPP;
+
+ ret = of_property_read_u32_index(np, "gpios", idx * gpio_cells,
+ &gpio_num);
+ if (ret)
+ return ret;
+
+ ret = of_property_read_u32_index(np, "gpios", idx * gpio_cells + 1,
+ &gpio_flags);
+ if (ret)
+ return ret;
if (gpio_flags & OF_GPIO_ACTIVE_LOW)
flags |= GPIOF_ACTIVE_LOW;
+ gpio = gpio_get_num(chip->dev, gpio_num);
+ if (gpio == -EPROBE_DEFER)
+ return gpio;
+
+ if (gpio < 0) {
+ dev_err(chip->dev, "unable to get gpio %u\n", gpio_num);
+ return gpio;
+ }
+
+
/*
* Note that, in order to be compatible with Linux, the code
* below interprets 'output-high' as to mean 'output-active'.
@@ -625,23 +642,6 @@ void gpiochip_remove(struct gpio_chip *chip)
list_del(&chip->list);
}
-static int of_gpio_simple_xlate(struct gpio_chip *chip,
- const struct of_phandle_args *gpiospec,
- u32 *flags)
-{
- /*
- * Support for GPIOs that don't have #gpio-cells set to 2 is
- * not implemented
- */
- if (WARN_ON(gpiospec->args_count != 2))
- return -ENOTSUPP;
-
- if (flags)
- *flags = gpiospec->args[1];
-
- return chip->base + gpiospec->args[0];
-}
-
struct gpio_chip *gpio_get_chip_by_dev(struct device *dev)
{
struct gpio_chip *chip;
@@ -654,8 +654,7 @@ struct gpio_chip *gpio_get_chip_by_dev(struct device *dev)
return NULL;
}
-int gpio_of_xlate(struct device *dev, struct of_phandle_args *gpiospec,
- int *flags)
+int gpio_get_num(struct device *dev, int gpio)
{
struct gpio_chip *chip;
@@ -666,10 +665,7 @@ int gpio_of_xlate(struct device *dev, struct of_phandle_args *gpiospec,
if (!chip)
return -EPROBE_DEFER;
- if (chip->ops->of_xlate)
- return chip->ops->of_xlate(chip, gpiospec, flags);
- else
- return of_gpio_simple_xlate(chip, gpiospec, flags);
+ return chip->base + gpio;
}
struct gpio_chip *gpio_get_chip(int gpio)
diff --git a/drivers/of/of_gpio.c b/drivers/of/of_gpio.c
index b6625637421b..5da80e249386 100644
--- a/drivers/of/of_gpio.c
+++ b/drivers/of/of_gpio.c
@@ -62,7 +62,6 @@ int of_get_named_gpio_flags(struct device_node *np, const char *propname,
{
struct of_phandle_args out_args;
struct device *dev;
- int of_flags;
int ret;
ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
@@ -80,7 +79,7 @@ int of_get_named_gpio_flags(struct device_node *np, const char *propname,
return -EPROBE_DEFER;
}
- ret = gpio_of_xlate(dev, &out_args, &of_flags);
+ ret = gpio_get_num(dev, out_args.args[0]);
if (ret == -EPROBE_DEFER)
return ret;
if (ret < 0) {
@@ -90,7 +89,7 @@ int of_get_named_gpio_flags(struct device_node *np, const char *propname,
}
if (flags) {
- *flags = of_flags;
+ *flags = out_args.args[1];
of_gpio_flags_quirks(np, propname, flags, index);
}
diff --git a/include/gpio.h b/include/gpio.h
index 10ac7fd7c4cb..5f2c16584c3b 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -177,7 +177,6 @@ struct gpio_ops {
int (*get_direction)(struct gpio_chip *chip, unsigned offset);
int (*get)(struct gpio_chip *chip, unsigned offset);
void (*set)(struct gpio_chip *chip, unsigned offset, int value);
- int (*of_xlate)(struct gpio_chip *chip, const struct of_phandle_args *gpiospec, u32 *flags);
};
struct gpio_chip {
@@ -194,8 +193,7 @@ struct gpio_chip {
int gpiochip_add(struct gpio_chip *chip);
void gpiochip_remove(struct gpio_chip *chip);
-int gpio_of_xlate(struct device *dev, struct of_phandle_args *gpiospec,
- int *flags);
+int gpio_get_num(struct device *dev, int gpio);
struct gpio_chip *gpio_get_chip(int gpio);
#endif /* __GPIO_H */
--
2.39.2
next prev parent reply other threads:[~2023-06-14 10:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-14 10:07 [PATCH v2 00/10] Fix gpio-hogs and sync with Linux gpiolib Ahmad Fatoum
2023-06-14 10:07 ` Ahmad Fatoum [this message]
2023-06-14 10:07 ` [PATCH v2 02/10] gpiolib: simplify for loop break condition Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 03/10] gpiolib: rename local gpio-line-names variable Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 04/10] gpiolib: fix gpio name memory leak Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 05/10] gpiolib: fix missing error check while query gpio-line-names Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 06/10] gpiolib: refactor gpio-line-names parsing Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 07/10] gpiolib: introduce of_gpiochip_add to bundle all of functions Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 08/10] OF: gpio: sync of_get_named_gpio_flags variable with kernel Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 09/10] OF: gpio: call of_node_put in of_get_named_gpio_flags Ahmad Fatoum
2023-06-14 10:07 ` [PATCH v2 10/10] gpiolib: add of_xlate support Ahmad Fatoum
2023-06-16 8:14 ` Sascha Hauer
2023-06-16 12:13 ` Marco Felsch
2023-06-14 14:19 ` [PATCH v2 00/10] Fix gpio-hogs and sync with Linux gpiolib Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230614100747.3368109-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=jmaselbas@kalray.eu \
--cc=mfe@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox