2022-04-16 01:49:52

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion

This is a spin-off (*) of the previous work of switching GPIO library
to use fwnode instead of of_node. Here we introduce a couple of
a new macro helpers, which allows to switch some of the drivers
to use fwnode and partially fwnode APIs. As a result of this cleanup
a few drivers switched to use GPIO fwnode instead of of_node.

*) it's subset of it with a new (patch 1) helper.

Marek, Martin, can you give this a try?
This requires at least two patches for GPIO library to be applied.

Bart, Linus, I can take it thru my tree with an immutable branch if
it's the way you prefer, otherwise please suggest on how to proceed.

Changelog v5:
- dropped tested patches (this series based on them, though)
- introduced a new helper (thanks Marek and Martin for reporting an issue)
- redone Armada and Meson code using newly introduced helper

Changelog v4:
- fixed compilation of the Samsung pin control drivers (LKP)
- explained in the commit message why namespacing is good for meson defs
- added tag to one of meson patches (Neil)

Changelog v3:
- moved count initialization to the definition in patch 2 (Geert)
- replaced of_args by args, used %pfwP in patch 7 (Geert)
- fixed kernel doc warning in patch 7
- added tags to patches 1, 2, 6, and 7 (Geert)
- added tag to patch 4 (Fabien)
- renamed MREG to MESON_REG in patch 9 (Neil)
- added tag to patch 10 (Neil)
- used --base for cover-letter

Changelog v2:
- properly based, so kbuild bot may test it (LKP)
- fixed typo in the macro (Geert)
- split to two macro helpers and rename the gpiochip_count()
- tagged one of stm32 and one of meson patches (Fabien, Neil)
- unified previously standalone armada patch
- due to above rewrote the armada patch from v1 completely (Sergey)
- added a lot of a new patches
- compile tested all of them on x86

Andy Shevchenko (6):
gpiolib: Introduce a helper to get first GPIO controller node
pinctrl: armada-37xx: Switch to use fwnode instead of of_node
pinctrl: armada-37xx: Reuse GPIO fwnode in
armada_37xx_irqchip_register()
pinctrl: meson: Rename REG_* to MESON_REG_*
pinctrl: meson: Enable COMPILE_TEST
pinctrl: meson: Replace custom code by gpiochip_node_count() call

drivers/pinctrl/meson/Kconfig | 2 +-
drivers/pinctrl/meson/pinctrl-meson.c | 52 ++++++++++-----------
drivers/pinctrl/meson/pinctrl-meson.h | 28 +++++------
drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 34 ++++----------
include/linux/gpio/driver.h | 10 ++++
5 files changed, 59 insertions(+), 67 deletions(-)

--
2.35.1


2022-04-16 02:01:09

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 6/6] pinctrl: meson: Replace custom code by gpiochip_node_count() call

Since we have generic function to count GPIO controller nodes
under a given device, there is no need to open code it. Replace
custom code by gpiochip_node_count() call.

Signed-off-by: Andy Shevchenko <[email protected]>
Reviewed-by: Neil Armstrong <[email protected]>
---
drivers/pinctrl/meson/pinctrl-meson.c | 28 ++++++++++++---------------
1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c
index 5b46a0979db7..cc2cd73ff8f9 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -49,6 +49,7 @@
#include <linux/pinctrl/pinctrl.h>
#include <linux/pinctrl/pinmux.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/seq_file.h>

@@ -662,27 +663,22 @@ static struct regmap *meson_map_resource(struct meson_pinctrl *pc,
return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config);
}

-static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc,
- struct device_node *node)
+static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc)
{
- struct device_node *np, *gpio_np = NULL;
+ struct device_node *gpio_np;
+ unsigned int chips;

- for_each_child_of_node(node, np) {
- if (!of_find_property(np, "gpio-controller", NULL))
- continue;
- if (gpio_np) {
- dev_err(pc->dev, "multiple gpio nodes\n");
- of_node_put(np);
- return -EINVAL;
- }
- gpio_np = np;
- }
-
- if (!gpio_np) {
+ chips = gpiochip_node_count(pc->dev);
+ if (!chips) {
dev_err(pc->dev, "no gpio node found\n");
return -EINVAL;
}
+ if (chips > 1) {
+ dev_err(pc->dev, "multiple gpio nodes\n");
+ return -EINVAL;
+ }

+ gpio_np = to_of_node(gpiochip_node_get_first(pc->dev));
pc->of_node = gpio_np;

pc->reg_mux = meson_map_resource(pc, gpio_np, "mux");
@@ -751,7 +747,7 @@ int meson_pinctrl_probe(struct platform_device *pdev)
pc->dev = dev;
pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev);

- ret = meson_pinctrl_parse_dt(pc, dev->of_node);
+ ret = meson_pinctrl_parse_dt(pc);
if (ret)
return ret;

--
2.35.1

2022-04-16 02:08:11

by Marek Szyprowski

[permalink] [raw]
Subject: Re: [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion

Hi Andy,

On 14.04.2022 21:02, Andy Shevchenko wrote:
> This is a spin-off (*) of the previous work of switching GPIO library
> to use fwnode instead of of_node. Here we introduce a couple of
> a new macro helpers, which allows to switch some of the drivers
> to use fwnode and partially fwnode APIs. As a result of this cleanup
> a few drivers switched to use GPIO fwnode instead of of_node.
>
> *) it's subset of it with a new (patch 1) helper.
>
> Marek, Martin, can you give this a try?
> This requires at least two patches for GPIO library to be applied.

I've applied patch #1 and #6 on top of linux next-20220413 with commit
88834c75cae5 ("pinctrl: meson: Replace custom code by
gpiochip_node_count() call") reverted. All my Meson-based test boards
(Odroid C4, N2, Khadas VIM3/3l) work fine now. Thanks! Feel free to add:

Tested-by: Marek Szyprowski <[email protected]>

> Bart, Linus, I can take it thru my tree with an immutable branch if
> it's the way you prefer, otherwise please suggest on how to proceed.
>
> Changelog v5:
> - dropped tested patches (this series based on them, though)
> - introduced a new helper (thanks Marek and Martin for reporting an issue)
> - redone Armada and Meson code using newly introduced helper
>
> Changelog v4:
> - fixed compilation of the Samsung pin control drivers (LKP)
> - explained in the commit message why namespacing is good for meson defs
> - added tag to one of meson patches (Neil)
>
> Changelog v3:
> - moved count initialization to the definition in patch 2 (Geert)
> - replaced of_args by args, used %pfwP in patch 7 (Geert)
> - fixed kernel doc warning in patch 7
> - added tags to patches 1, 2, 6, and 7 (Geert)
> - added tag to patch 4 (Fabien)
> - renamed MREG to MESON_REG in patch 9 (Neil)
> - added tag to patch 10 (Neil)
> - used --base for cover-letter
>
> Changelog v2:
> - properly based, so kbuild bot may test it (LKP)
> - fixed typo in the macro (Geert)
> - split to two macro helpers and rename the gpiochip_count()
> - tagged one of stm32 and one of meson patches (Fabien, Neil)
> - unified previously standalone armada patch
> - due to above rewrote the armada patch from v1 completely (Sergey)
> - added a lot of a new patches
> - compile tested all of them on x86
>
> Andy Shevchenko (6):
> gpiolib: Introduce a helper to get first GPIO controller node
> pinctrl: armada-37xx: Switch to use fwnode instead of of_node
> pinctrl: armada-37xx: Reuse GPIO fwnode in
> armada_37xx_irqchip_register()
> pinctrl: meson: Rename REG_* to MESON_REG_*
> pinctrl: meson: Enable COMPILE_TEST
> pinctrl: meson: Replace custom code by gpiochip_node_count() call
>
> drivers/pinctrl/meson/Kconfig | 2 +-
> drivers/pinctrl/meson/pinctrl-meson.c | 52 ++++++++++-----------
> drivers/pinctrl/meson/pinctrl-meson.h | 28 +++++------
> drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 34 ++++----------
> include/linux/gpio/driver.h | 10 ++++
> 5 files changed, 59 insertions(+), 67 deletions(-)
>
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

2022-04-22 20:37:39

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH v5 0/6] gpiolib: more helpers and fwnode conversion

On Thu, Apr 14, 2022 at 9:02 PM Andy Shevchenko
<[email protected]> wrote:

> This is a spin-off (*) of the previous work of switching GPIO library
> to use fwnode instead of of_node. Here we introduce a couple of
> a new macro helpers, which allows to switch some of the drivers
> to use fwnode and partially fwnode APIs. As a result of this cleanup
> a few drivers switched to use GPIO fwnode instead of of_node.
>
> *) it's subset of it with a new (patch 1) helper.
>
> Marek, Martin, can you give this a try?
> This requires at least two patches for GPIO library to be applied.
>
> Bart, Linus, I can take it thru my tree with an immutable branch if
> it's the way you prefer, otherwise please suggest on how to proceed.

Hmmm that sounds best, patch 1 does not apply to the pinctrl
tree so I suppose there are already dependencies in the GPIO
tree?

FWIW, the series:
Acked-by: Linus Walleij <[email protected]>

I'm of course a fan of this nice refactoring series.

Yours,
Linus Walleij