All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] pinctrl: don't use gpiod_to_chip()
@ 2023-11-15 16:49 Bartosz Golaszewski
  2023-11-15 16:49 ` [PATCH 1/3] gpiolib: provide gpio_devie_get_label() Bartosz Golaszewski
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Bartosz Golaszewski @ 2023-11-15 16:49 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko
  Cc: linux-kernel, linux-gpio, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Let's start working towards removing gpiod_to_chip() from the kernel.
Start with pinctrl. The first patch should go through the GPIO tree
and become available through an immutable tag so that we can get more
conversions in this cycle elsewhere.

Bartosz Golaszewski (3):
  gpiolib: provide gpio_devie_get_label()
  pinctrl: stop using gpiod_to_chip()
  pinctrl: don't include GPIOLIB private header

 drivers/gpio/gpiolib.c      | 14 ++++++++++++++
 drivers/pinctrl/core.c      | 18 ++++++++----------
 include/linux/gpio/driver.h |  1 +
 3 files changed, 23 insertions(+), 10 deletions(-)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] gpiolib: provide gpio_devie_get_label()
  2023-11-15 16:49 [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Bartosz Golaszewski
@ 2023-11-15 16:49 ` Bartosz Golaszewski
  2023-11-15 16:50 ` [PATCH 2/3] pinctrl: stop using gpiod_to_chip() Bartosz Golaszewski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Bartosz Golaszewski @ 2023-11-15 16:49 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko
  Cc: linux-kernel, linux-gpio, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Provide a getter for the GPIO device label string so that users don't
have to dereference struct gpio_chip directly.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib.c      | 14 ++++++++++++++
 include/linux/gpio/driver.h |  1 +
 2 files changed, 15 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 95d2a7b2ea3e..a5faaea6915d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -254,6 +254,20 @@ int gpio_device_get_base(struct gpio_device *gdev)
 }
 EXPORT_SYMBOL_GPL(gpio_device_get_base);
 
+/**
+ * gpio_device_get_label() - Get the label of this GPIO device
+ * @gdev: GPIO device
+ *
+ * Returns:
+ * Pointer to the string containing the GPIO device label. The string's
+ * lifetime is tied to that of the underlying GPIO device.
+ */
+const char *gpio_device_get_label(struct gpio_device *gdev)
+{
+	return gdev->label;
+}
+EXPORT_SYMBOL(gpio_device_get_label);
+
 /**
  * gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device
  * @gdev: GPIO device
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 0aed62f0c633..100c329dc986 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -786,6 +786,7 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc);
 
 /* struct gpio_device getters */
 int gpio_device_get_base(struct gpio_device *gdev);
+const char *gpio_device_get_label(struct gpio_device *gdev);
 
 #else /* CONFIG_GPIOLIB */
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] pinctrl: stop using gpiod_to_chip()
  2023-11-15 16:49 [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Bartosz Golaszewski
  2023-11-15 16:49 ` [PATCH 1/3] gpiolib: provide gpio_devie_get_label() Bartosz Golaszewski
@ 2023-11-15 16:50 ` Bartosz Golaszewski
  2023-11-15 16:50 ` [PATCH 3/3] pinctrl: don't include GPIOLIB private header Bartosz Golaszewski
  2023-11-16 13:43 ` [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Linus Walleij
  3 siblings, 0 replies; 10+ messages in thread
From: Bartosz Golaszewski @ 2023-11-15 16:50 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko
  Cc: linux-kernel, linux-gpio, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Don't dereference struct gpio_chip directly, use dedicated gpio_device
getters instead.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/pinctrl/core.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 1fa89be29b8f..0b4d07aea387 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -13,6 +13,7 @@
 #define pr_fmt(fmt) "pinctrl core: " fmt
 
 #include <linux/array_size.h>
+#include <linux/cleanup.h>
 #include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/err.h>
@@ -1649,8 +1650,8 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 	const struct pinctrl_ops *ops = pctldev->desc->pctlops;
 	unsigned i, pin;
 #ifdef CONFIG_GPIOLIB
+	struct gpio_device *gdev __free(gpio_device_put) = NULL;
 	struct pinctrl_gpio_range *range;
-	struct gpio_chip *chip;
 	int gpio_num;
 #endif
 
@@ -1685,11 +1686,11 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
 			 * we need to get rid of the range->base eventually and
 			 * get the descriptor directly from the gpio_chip.
 			 */
-			chip = gpiod_to_chip(gpio_to_desc(gpio_num));
-		else
-			chip = NULL;
-		if (chip)
-			seq_printf(s, "%u:%s ", gpio_num - chip->gpiodev->base, chip->label);
+			gdev = gpiod_to_gpio_device(gpio_to_desc(gpio_num));
+		if (gdev)
+			seq_printf(s, "%u:%s ",
+				   gpio_num - gpio_device_get_base(gdev),
+				   gpio_device_get_label(gdev));
 		else
 			seq_puts(s, "0:? ");
 #endif
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] pinctrl: don't include GPIOLIB private header
  2023-11-15 16:49 [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Bartosz Golaszewski
  2023-11-15 16:49 ` [PATCH 1/3] gpiolib: provide gpio_devie_get_label() Bartosz Golaszewski
  2023-11-15 16:50 ` [PATCH 2/3] pinctrl: stop using gpiod_to_chip() Bartosz Golaszewski
@ 2023-11-15 16:50 ` Bartosz Golaszewski
  2023-11-17 21:09   ` Andy Shevchenko
  2023-11-16 13:43 ` [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Linus Walleij
  3 siblings, 1 reply; 10+ messages in thread
From: Bartosz Golaszewski @ 2023-11-15 16:50 UTC (permalink / raw)
  To: Linus Walleij, Andy Shevchenko
  Cc: linux-kernel, linux-gpio, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

gpio_to_desc() is declared in linux/gpio.h so there's no need to include
gpiolib.h directly.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/pinctrl/core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 0b4d07aea387..e55959e1af5a 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -24,6 +24,7 @@
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 
+#include <linux/gpio.h>
 #include <linux/gpio/driver.h>
 
 #include <linux/pinctrl/consumer.h>
@@ -31,10 +32,6 @@
 #include <linux/pinctrl/machine.h>
 #include <linux/pinctrl/pinctrl.h>
 
-#ifdef CONFIG_GPIOLIB
-#include "../gpio/gpiolib.h"
-#endif
-
 #include "core.h"
 #include "devicetree.h"
 #include "pinconf.h"
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] pinctrl: don't use gpiod_to_chip()
  2023-11-15 16:49 [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Bartosz Golaszewski
                   ` (2 preceding siblings ...)
  2023-11-15 16:50 ` [PATCH 3/3] pinctrl: don't include GPIOLIB private header Bartosz Golaszewski
@ 2023-11-16 13:43 ` Linus Walleij
  2023-11-20 15:06   ` Bartosz Golaszewski
  3 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2023-11-16 13:43 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, linux-kernel, linux-gpio, Bartosz Golaszewski

On Wed, Nov 15, 2023 at 5:50 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Let's start working towards removing gpiod_to_chip() from the kernel.
> Start with pinctrl. The first patch should go through the GPIO tree
> and become available through an immutable tag so that we can get more
> conversions in this cycle elsewhere.

Fair enough, maybe an immutable branch with all three patches?
Probably best to merga all three into both subsystems I think.

Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] pinctrl: don't include GPIOLIB private header
  2023-11-15 16:50 ` [PATCH 3/3] pinctrl: don't include GPIOLIB private header Bartosz Golaszewski
@ 2023-11-17 21:09   ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2023-11-17 21:09 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-kernel, linux-gpio, Bartosz Golaszewski

On Wed, Nov 15, 2023 at 05:50:01PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> gpio_to_desc() is declared in linux/gpio.h so there's no need to include
> gpiolib.h directly.

Oh, this is unfortunate we need it...

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] pinctrl: don't use gpiod_to_chip()
  2023-11-16 13:43 ` [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Linus Walleij
@ 2023-11-20 15:06   ` Bartosz Golaszewski
  2023-11-24 10:01     ` Linus Walleij
  0 siblings, 1 reply; 10+ messages in thread
From: Bartosz Golaszewski @ 2023-11-20 15:06 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, linux-kernel, linux-gpio, Bartosz Golaszewski

On Thu, Nov 16, 2023 at 2:43 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Wed, Nov 15, 2023 at 5:50 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > Let's start working towards removing gpiod_to_chip() from the kernel.
> > Start with pinctrl. The first patch should go through the GPIO tree
> > and become available through an immutable tag so that we can get more
> > conversions in this cycle elsewhere.
>
> Fair enough, maybe an immutable branch with all three patches?
> Probably best to merga all three into both subsystems I think.
>

Nah, I don't think I need to pollute the GPIO tree with every pinctrl
patch. It's enough to just merge the first one into GPIO and you do
the same in pinctrl.

Bart

> Acked-by: Linus Walleij <linus.walleij@linaro.org>
>
> Yours,
> Linus Walleij

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] pinctrl: don't use gpiod_to_chip()
  2023-11-20 15:06   ` Bartosz Golaszewski
@ 2023-11-24 10:01     ` Linus Walleij
  2023-11-24 19:40       ` Bartosz Golaszewski
  0 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2023-11-24 10:01 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, linux-kernel, linux-gpio, Bartosz Golaszewski

On Mon, Nov 20, 2023 at 4:06 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> On Thu, Nov 16, 2023 at 2:43 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> > On Wed, Nov 15, 2023 at 5:50 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >
> > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > >
> > > Let's start working towards removing gpiod_to_chip() from the kernel.
> > > Start with pinctrl. The first patch should go through the GPIO tree
> > > and become available through an immutable tag so that we can get more
> > > conversions in this cycle elsewhere.
> >
> > Fair enough, maybe an immutable branch with all three patches?
> > Probably best to merga all three into both subsystems I think.
> >
>
> Nah, I don't think I need to pollute the GPIO tree with every pinctrl
> patch. It's enough to just merge the first one into GPIO and you do
> the same in pinctrl.

Fair enough, but I need that immutable branch for patch 1 so I
can merge the rest on top.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] pinctrl: don't use gpiod_to_chip()
  2023-11-24 10:01     ` Linus Walleij
@ 2023-11-24 19:40       ` Bartosz Golaszewski
  2023-11-24 23:29         ` Linus Walleij
  0 siblings, 1 reply; 10+ messages in thread
From: Bartosz Golaszewski @ 2023-11-24 19:40 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Andy Shevchenko, linux-kernel, linux-gpio, Bartosz Golaszewski

On Fri, Nov 24, 2023 at 11:01 AM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Mon, Nov 20, 2023 at 4:06 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > On Thu, Nov 16, 2023 at 2:43 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> > > On Wed, Nov 15, 2023 at 5:50 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > >
> > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > > >
> > > > Let's start working towards removing gpiod_to_chip() from the kernel.
> > > > Start with pinctrl. The first patch should go through the GPIO tree
> > > > and become available through an immutable tag so that we can get more
> > > > conversions in this cycle elsewhere.
> > >
> > > Fair enough, maybe an immutable branch with all three patches?
> > > Probably best to merga all three into both subsystems I think.
> > >
> >
> > Nah, I don't think I need to pollute the GPIO tree with every pinctrl
> > patch. It's enough to just merge the first one into GPIO and you do
> > the same in pinctrl.
>
> Fair enough, but I need that immutable branch for patch 1 so I
> can merge the rest on top.
>
> Yours,
> Linus Walleij

I applied the first patch (after fixing the typo in the commit
message) and sent you the immutable branch to pull. Please apply the
remaining patches to the pinctrl tree directly.

Thanks!
Bart

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] pinctrl: don't use gpiod_to_chip()
  2023-11-24 19:40       ` Bartosz Golaszewski
@ 2023-11-24 23:29         ` Linus Walleij
  0 siblings, 0 replies; 10+ messages in thread
From: Linus Walleij @ 2023-11-24 23:29 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, linux-kernel, linux-gpio, Bartosz Golaszewski

On Fri, Nov 24, 2023 at 8:40 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> On Fri, Nov 24, 2023 at 11:01 AM Linus Walleij <linus.walleij@linaro.org> wrote:
> >
> > On Mon, Nov 20, 2023 at 4:06 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > > On Thu, Nov 16, 2023 at 2:43 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> > > > On Wed, Nov 15, 2023 at 5:50 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > > >
> > > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> > > > >
> > > > > Let's start working towards removing gpiod_to_chip() from the kernel.
> > > > > Start with pinctrl. The first patch should go through the GPIO tree
> > > > > and become available through an immutable tag so that we can get more
> > > > > conversions in this cycle elsewhere.
> > > >
> > > > Fair enough, maybe an immutable branch with all three patches?
> > > > Probably best to merga all three into both subsystems I think.
> > > >
> > >
> > > Nah, I don't think I need to pollute the GPIO tree with every pinctrl
> > > patch. It's enough to just merge the first one into GPIO and you do
> > > the same in pinctrl.
> >
> > Fair enough, but I need that immutable branch for patch 1 so I
> > can merge the rest on top.
> >
> > Yours,
> > Linus Walleij
>
> I applied the first patch (after fixing the typo in the commit
> message) and sent you the immutable branch to pull. Please apply the
> remaining patches to the pinctrl tree directly.

Pulled it and applied the other two patches on top, thanks!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-11-24 23:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-15 16:49 [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Bartosz Golaszewski
2023-11-15 16:49 ` [PATCH 1/3] gpiolib: provide gpio_devie_get_label() Bartosz Golaszewski
2023-11-15 16:50 ` [PATCH 2/3] pinctrl: stop using gpiod_to_chip() Bartosz Golaszewski
2023-11-15 16:50 ` [PATCH 3/3] pinctrl: don't include GPIOLIB private header Bartosz Golaszewski
2023-11-17 21:09   ` Andy Shevchenko
2023-11-16 13:43 ` [PATCH 0/3] pinctrl: don't use gpiod_to_chip() Linus Walleij
2023-11-20 15:06   ` Bartosz Golaszewski
2023-11-24 10:01     ` Linus Walleij
2023-11-24 19:40       ` Bartosz Golaszewski
2023-11-24 23:29         ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.