From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 05/11] gpiolib: don't use GPIO number API in of_hog_gpio
Date: Fri, 9 Aug 2024 16:23:59 +0200 [thread overview]
Message-ID: <20240809142405.315244-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240809142405.315244-1-a.fatoum@pengutronix.de>
The GPIO number API is legacy that's meant to be a layer on top
of GPIO descriptors, which should be used directly for new code.
of_hog_gpio which is called after registering adding GPIO chips also
uses the number API, which is quite unnecessary: gpio_get_num iterates
over all GPIO chips to find out the number only to convert it to a
descriptor inside of gpio_request_one.
Instead of that, let's use gpiochip_get_desc, which just does some
arithmetic to get the descriptor as we know the gpiochip must be there.
This prepares us for propagating OF flags in a later commit.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/gpio/gpiolib.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 70c78a9ad4af..0c6c0fcc1aeb 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -90,6 +90,11 @@ static unsigned gpiodesc_chip_offset(const struct gpio_desc *desc)
return (desc - gpio_desc) - desc->chip->base + desc->chip->gpio_offset;
}
+static __maybe_unused struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, int gpio)
+{
+ return gpio_desc + chip->base + gpio - chip->gpio_offset;
+}
+
static int gpiod_is_active_low(const struct gpio_desc *desc)
{
return desc->flags & OF_GPIO_ACTIVE_LOW;
@@ -643,6 +648,7 @@ static int gpiochip_find_base(int ngpio)
return base;
}
+
#ifdef CONFIG_OF_GPIO
static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
@@ -651,7 +657,7 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
struct device_node *chip_np = chip->dev->of_node;
unsigned long flags = 0;
u32 gpio_cells, gpio_num, gpio_flags;
- int ret, gpio;
+ int ret;
const char *name = NULL;
ret = of_property_read_u32(chip_np, "#gpio-cells", &gpio_cells);
@@ -678,16 +684,6 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
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'.
@@ -714,7 +710,8 @@ static int of_hog_gpio(struct device_node *np, struct gpio_chip *chip,
if (ret < 0)
name = np->name;
- return gpio_request_one(gpio, flags, name);
+ return gpiodesc_request_one(gpiochip_get_desc(chip, gpio_num),
+ flags, name);
}
static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
--
2.39.2
next prev parent reply other threads:[~2024-08-09 14:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-09 14:23 [PATCH 00/11] gpiolib: add support for OF GPIO configuration binding Ahmad Fatoum
2024-08-09 14:23 ` [PATCH 01/11] gpio: make gpio.h header self-contained Ahmad Fatoum
2024-08-09 14:23 ` [PATCH 02/11] gpiolib: permit GPIO drivers to implement struct gpio_ops::set_config Ahmad Fatoum
2024-08-09 14:23 ` [PATCH 03/11] pinctrl: stm32: implement generic " Ahmad Fatoum
2024-08-09 14:23 ` [PATCH 04/11] gpiolib: turn request/active_low into bit flags Ahmad Fatoum
2024-08-09 14:23 ` Ahmad Fatoum [this message]
2024-08-09 14:24 ` [PATCH 06/11] gpiolib: store all OF flags into GPIO descriptor Ahmad Fatoum
2024-08-09 14:24 ` [PATCH 07/11] gpiolib: add support for OF GPIO configuration binding Ahmad Fatoum
2024-08-09 14:24 ` [PATCH 08/11] gpiolib: use dev_gpiod_get_index device node argument throughout Ahmad Fatoum
2024-08-09 14:24 ` [PATCH 09/11] gpiolib: export function to get struct gpio_desc from index Ahmad Fatoum
2024-08-09 14:24 ` [PATCH 10/11] input: gpio_keys: switch to GPIO descriptor API Ahmad Fatoum
2024-08-09 14:24 ` [PATCH 11/11] input: gpio-keys: request with label in DT if available Ahmad Fatoum
2024-08-14 11:00 ` [PATCH 00/11] gpiolib: add support for OF GPIO configuration binding 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=20240809142405.315244-6-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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