gpio: ppc44x: assorted cleanups
cover gpio: ppc44x: assorted cleanups
A follow-up to the earlier ppc44x GPIO conversion to gpio-mmio. With the driver now built on gpio_generic_chip, a few leftovers can go:
- Patch 1 drops the label and parent assignments that gpio_generic_chip_init() already does.
- Patches 2-3 deduplicate the OSR/TSR source selection shared by both direction callbacks and fold the single-caller __ppc44x_gpio_set() into ppc44x_gpio_dir_out().
- Patch 4 expresses the MSB-first pin masks with BIT() and GENMASK().
- Patch 5 trims includes, switches to devm_kzalloc_obj() and tidies up probe and the OF match table.
No functional change intended.
An AI coding assistant (Claude) was used to help prepare this series.
Rosen Penev (5):
gpio: ppc44x: drop redundant label and parent assignments
gpio: ppc44x: factor out the OSR/TSR source selection
gpio: ppc44x: fold __ppc44x_gpio_set() into ppc44x_gpio_dir_out()
gpio: ppc44x: use BIT() and GENMASK() for the pin masks
gpio: ppc44x: tidy up includes and probe
drivers/gpio/gpio-ppc44x.c | 89 ++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 52 deletions(-)
Signature · 1 line
2.56.0
PATCH 1/5 gpio: ppc44x: drop redundant label and parent assignments
gpio_generic_chip_init() already sets gc->parent to the device and gc->label to dev_name() of it. Drop the duplicate assignments from probe.
--- drivers/gpio/gpio-ppc44x.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpio/gpio-ppc44x.c +0 -2
@@ -178,8 +178,6 @@ static int ppc44x_gpio_probe(struct platform_device *ofdev)return ret; gc = &chip->chip.gc; - gc->label =dev_name (dev); - gc->parent = dev; gc->direction_input = ppc44x_gpio_dir_in; gc->direction_output = ppc44x_gpio_dir_out;
Signature · 1 line
2.56.0
PATCH 2/5 gpio: ppc44x: factor out the OSR/TSR source selection
In reply to Rosen PenevBoth direction callbacks clear the pin's 2-bit field in the output source and three-state source registers, picking the low or high register by bank. Move that into a helper instead of duplicating the if/else in each callback.
No functional change; the registers are written in the same order.
--- drivers/gpio/gpio-ppc44x.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/gpio/gpio-ppc44x.c +17 -16
@@ -64,6 +64,21 @@ static inline void ppc44x_setbits32(void __iomem *addr, u32 mask)iowrite32be (val, addr); } +/* +* Route the pin's output and three-state control to the GPIO controller +* rather than an alternate function. Bits 0-15 use OSRL/TSRL, bits 16-31 +* use OSRH/TSRH. +*/ +static void ppc44x_gpio_select_gpio (struct ppc44x_gpio __iomem *regs, +unsigned int gpio) +{ +__be32 __iomem *osr = gpio <16 ? ®s->osrl : ®s->osrh; +__be32 __iomem *tsr = gpio <16 ? ®s->tsrl : ®s->tsrh; + +ppc44x_clrbits32 (osr,GPIO_MASK2 (gpio)); +ppc44x_clrbits32 (tsr,GPIO_MASK2 (gpio)); +} +/* * GPIO LIB API implementation for GPIOs *
@@ -99,14 +114,7 @@ static int ppc44x_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)ppc44x_clrbits32 (®s->tcr,GPIO_MASK (gpio)); gen_gc->sdir &= ~GPIO_MASK (gpio); -/* Bits 0-15 use TSRL/OSRL, bits 16-31 use TSRH/OSRH */ -if (gpio <16 ) { -ppc44x_clrbits32 (®s->osrl,GPIO_MASK2 (gpio)); -ppc44x_clrbits32 (®s->tsrl,GPIO_MASK2 (gpio)); - }else { -ppc44x_clrbits32 (®s->osrh,GPIO_MASK2 (gpio)); -ppc44x_clrbits32 (®s->tsrh,GPIO_MASK2 (gpio)); - } +ppc44x_gpio_select_gpio (regs, gpio);return 0 ; }
@@ -130,14 +138,7 @@ ppc44x_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)ppc44x_setbits32 (®s->tcr,GPIO_MASK (gpio)); gen_gc->sdir |=GPIO_MASK (gpio); -/* Bits 0-15 use TSRL, bits 16-31 use TSRH */ -if (gpio <16 ) { -ppc44x_clrbits32 (®s->osrl,GPIO_MASK2 (gpio)); -ppc44x_clrbits32 (®s->tsrl,GPIO_MASK2 (gpio)); - }else { -ppc44x_clrbits32 (®s->osrh,GPIO_MASK2 (gpio)); -ppc44x_clrbits32 (®s->tsrh,GPIO_MASK2 (gpio)); - } +ppc44x_gpio_select_gpio (regs, gpio);pr_debug ("%s: gpio: %d val: %d\n" , __func__, gpio, val);
Signature · 1 line
2.56.0
PATCH 3/5 gpio: ppc44x: fold __ppc44x_gpio_set() into ppc44x_gpio_dir_out()
In reply to Rosen Penev__ppc44x_gpio_set() has a single caller, and it looks up the driver data that the caller already has. Open-code it in the direction_output callback, with a comment explaining why gpio_generic_chip_set() can't be used there: the generic setter takes the chip lock, which is already held at that point.
While at it, drop the pr_debug(); gpiolib's tracepoints already report direction and value changes.
--- drivers/gpio/gpio-ppc44x.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
drivers/gpio/gpio-ppc44x.c +10 -18
@@ -85,20 +85,6 @@ static void ppc44x_gpio_select_gpio(struct ppc44x_gpio __iomem *regs,* There are a maximum of 32 gpios in each gpio controller. */ -static inline void -__ppc44x_gpio_set (struct gpio_chip *gc,unsigned int gpio,int val) -{ -struct ppc44x_gpio_chip *chip =gpiochip_get_data (gc); -struct gpio_generic_chip *gen_gc = &chip->chip; - -if (val) - gen_gc->sdata |=GPIO_MASK (gpio); -else - gen_gc->sdata &= ~GPIO_MASK (gpio); - -gpio_generic_write_reg (gen_gc, gen_gc->reg_set, gen_gc->sdata); -} -static int ppc44x_gpio_dir_in (struct gpio_chip *gc,unsigned int gpio) {struct ppc44x_gpio_chip *chip =gpiochip_get_data (gc);
@@ -128,8 +114,16 @@ ppc44x_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)guard (gpio_generic_lock_irqsave)(gen_gc); -/* First set initial value */ -__ppc44x_gpio_set (gc, gpio, val); +/* +* First set the initial value. This can't use gpio_generic_chip_set() +* as the generic setter takes the chip lock, which is already held. +*/ +if (val) + gen_gc->sdata |=GPIO_MASK (gpio); +else + gen_gc->sdata &= ~GPIO_MASK (gpio); + +gpio_generic_write_reg (gen_gc, gen_gc->reg_set, gen_gc->sdata);/* Disable open-drain function */ ppc44x_clrbits32 (®s->odr,GPIO_MASK (gpio));
@@ -140,8 +134,6 @@ ppc44x_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)ppc44x_gpio_select_gpio (regs, gpio); -pr_debug ("%s: gpio: %d val: %d\n" , __func__, gpio, val); -return 0 ; }
Signature · 1 line
2.56.0
PATCH 4/5 gpio: ppc44x: use BIT() and GENMASK() for the pin masks
In reply to Rosen PenevExpress the per-pin masks with BIT() and GENMASK() rather than open-coded shifts of 0x80000000 and 0xc0000000. The pins are numbered from the MSB, matching the bit mapping gpio-mmio uses for GPIO_GENERIC_BIG_ENDIAN.
No functional change; both forms yield the same mask for all 32 pins.
--- drivers/gpio/gpio-ppc44x.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpio/gpio-ppc44x.c +4 -2
@@ -9,6 +9,7 @@* Author: Steve Falco <[email protected]> */ +#include <linux/bits.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/io.h>
@@ -18,8 +19,9 @@#include <linux/slab.h> #include <linux/platform_device.h> -#define GPIO_MASK (gpio) (0x80000000 >> (gpio)) -#define GPIO_MASK2 (gpio) (0xc0000000 >> (((gpio) % 16) * 2)) +/* Pins are numbered from the MSB; the select registers use 2 bits per pin */ +#define GPIO_MASK (gpio) BIT(31 - (gpio)) +#define GPIO_MASK2 (gpio) (GENMASK(1, 0) << (30 - ((gpio) % 16) * 2))/* Physical GPIO register layout */ struct ppc44x_gpio {
Signature · 1 line
2.56.0
PATCH 5/5 gpio: ppc44x: tidy up includes and probe
In reply to Rosen PenevRemove some unused includes that are not used directly.
While at it:
- use devm_kzalloc_obj() for the chip allocation
- rename the platform_device from ofdev to the conventional pdev
- compact the OF match table
- move module_platform_driver() next to the driver struct
No functional change.
--- drivers/gpio/gpio-ppc44x.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/gpio/gpio-ppc44x.c +6 -14
@@ -10,13 +10,8 @@*/ #include <linux/bits.h> -#include <linux/kernel.h> -#include <linux/init.h> #include <linux/io.h> -#include <linux/of.h> #include <linux/gpio/generic.h> -#include <linux/types.h> -#include <linux/slab.h> #include <linux/platform_device.h> /* Pins are numbered from the MSB; the select registers use 2 bits per pin */
@@ -139,20 +134,20 @@ ppc44x_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)return 0 ; } -static int ppc44x_gpio_probe (struct platform_device *ofdev) +static int ppc44x_gpio_probe (struct platform_device *pdev) { -struct device *dev = &ofdev->dev; +struct device *dev = &pdev->dev;struct ppc44x_gpio __iomem *regs;struct ppc44x_gpio_chip *chip;struct gpio_generic_chip_config config;struct gpio_chip *gc;int ret; - regs =devm_platform_ioremap_resource (ofdev,0 ); + regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (regs))return PTR_ERR (regs); - chip =devm_kzalloc (dev,sizeof (*chip),GFP_KERNEL ); + chip =devm_kzalloc_obj (dev, *chip);if (!chip)return -ENOMEM ;
@@ -180,9 +175,7 @@ static int ppc44x_gpio_probe(struct platform_device *ofdev) }static const struct of_device_id ppc44x_gpio_match[] = { - { - .compatible ="ibm,ppc4xx-gpio" , - }, + { .compatible ="ibm,ppc4xx-gpio" }, {}, };MODULE_DEVICE_TABLE (of, ppc44x_gpio_match);
@@ -194,8 +187,7 @@ static struct platform_driver ppc44x_gpio_driver = { .of_match_table = ppc44x_gpio_match, }, }; +module_platform_driver (ppc44x_gpio_driver);MODULE_DESCRIPTION ("PPC44x gpio driver" );MODULE_LICENSE ("GPL" ); - -module_platform_driver (ppc44x_gpio_driver);
Signature · 1 line
2.56.0
Bartosz Golaszewski
maintainerRe: [PATCH 5/5] gpio: ppc44x: tidy up includes and probe
Quoted 59 lines · Rosen Penev
Remove some unused includes that are not used directly.
While at it:
- usedevm_kzalloc_obj()for the chip allocation
- rename theplatform_devicefrom ofdev to the conventional pdev
- compact the OF match table
- movemodule_platform_driver()next to the driver structNo functional change.
Signed-off-by Rosen Penev <[email protected]>--- drivers/gpio/gpio-ppc44x.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)drivers/gpio/gpio-ppc44x.c +4
-9@@ -10,13 +10,8 @@*/ #include <linux/bits.h> -#include <linux/kernel.h> -#include <linux/init.h> #include <linux/io.h> -#include <linux/of.h> #include <linux/gpio/generic.h> -#include <linux/types.h> -#include <linux/slab.h> #include <linux/platform_device.h> /* Pins are numbered from the MSB; the select registers use 2 bits per pin */ @@ -139,20 +134,20 @@ ppc44x_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)return 0 ; } -static int ppc44x_gpio_probe (struct platform_device *ofdev) +static int ppc44x_gpio_probe (struct platform_device *pdev) { -struct device *dev = &ofdev->dev; +struct device *dev = &pdev->dev;struct ppc44x_gpio __iomem *regs;struct ppc44x_gpio_chip *chip;struct gpio_generic_chip_config config;struct gpio_chip *gc;int ret; - regs =devm_platform_ioremap_resource (ofdev,0 ); + regs =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (regs))return PTR_ERR (regs); - chip =devm_kzalloc (dev,sizeof (*chip),GFP_KERNEL ); + chip =devm_kzalloc_obj (dev, *chip);if (!chip)return -ENOMEM ;
drivers/gpio/gpio-ppc44x.c static int ppc44x_gpio_probe(struct platform_device *ofdev) · line 179
Quoted 8 lines
drivers/gpio/gpio-ppc44x.c +1
-3@@ -180,9 +175,7 @@ static int ppc44x_gpio_probe(struct platform_device *ofdev) }static const struct of_device_id ppc44x_gpio_match[] = { - { - .compatible ="ibm,ppc4xx-gpio" , - }, + { .compatible ="ibm,ppc4xx-gpio" }, {},
Uwe: is this in line with your recent cleanups?
Bart
Bartosz Golaszewski
maintainerRe: [PATCH 3/5] gpio: ppc44x: fold __ppc44x_gpio_set() into ppc44x_gpio_dir_out()
In reply to Rosen PenevQuoted 11 lines · Rosen Penev
__ppc44x_gpio_set()has a single caller, and it looks up the driver data that the caller already has. Open-code it in thedirection_outputcallback, with a comment explaining whygpio_generic_chip_set()can't be used there: the generic setter takes the chip lock, which is already held at that point.While at it, drop the
pr_debug(); gpiolib's tracepoints already report direction and value changes.Signed-off-by Rosen Penev <[email protected]>---
Sigh... This is really just churn...
I'll take it with the rest of the series as sashiko doesn't seem to complain but this time would be better spent elsewhere. If you like fixing bugs, I can assign you a number of GPIO bugs sashiko found.
Bart
Re: [PATCH 5/5] gpio: ppc44x: tidy up includes and probe
In reply to Bartosz GolaszewskiHello Bart,
Quoted 8 lines · Bartosz Golaszewski
drivers/gpio/gpio-ppc44x.c static int ppc44x_gpio_probe(struct platform_device *ofdev) · line 179
Quoted 6 lines
static const struct
of_device_idppc44x_gpio_match[] = {drivers/gpio/gpio-ppc44x.c +1
-3- { - .compatible = "ibm,ppc4xx-gpio", - }, + { .compatible = "ibm,ppc4xx-gpio" }, {},Uwe: is this in line with your recent cleanups?
The change is fine, I'd appreciate to also do
- {},
+ { }
at the same time.
Best regards
Uwe
Re: [PATCH 5/5] gpio: ppc44x: tidy up includes and probe
Quoted 17 lines · Uwe Kleine-König
Hello Bart,
Quoted 8 lines · Bartosz Golaszewski
drivers/gpio/gpio-ppc44x.c static int ppc44x_gpio_probe(struct platform_device *ofdev) · line 179
Quoted 6 lines
static const struct
of_device_idppc44x_gpio_match[] = {drivers/gpio/gpio-ppc44x.c +1
-3- { - .compatible = "ibm,ppc4xx-gpio", - }, + { .compatible = "ibm,ppc4xx-gpio" }, {},Uwe: is this in line with your recent cleanups?
The change is fine, I'd appreciate to also do
(quoted diff) +1
-1- {}, + { }
Quoted 1 line
at the same time.
{} was done by clang-format IIRC.
Quoted 3 lines
Best regards
Uwe
Re: [PATCH 5/5] gpio: ppc44x: tidy up includes and probe
Quoted 12 lines · Rosen Penev
Quoted 11 lines · Uwe Kleine-König
Hello Bart,
Quoted 7 lines · Bartosz Golaszewski
Quoted 6 lines
static const struct
of_device_idppc44x_gpio_match[] = {drivers/gpio/gpio-ppc44x.c +1
-3- { - .compatible = "ibm,ppc4xx-gpio", - }, + { .compatible = "ibm,ppc4xx-gpio" }, {},
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Uwe: is this in line with your recent cleanups?
The change is fine, I'd appreciate to also do
(quoted diff) +1
-1- {}, + { }at the same time.
{} was done by clang-format IIRC.
I saw that already, too. I'd argue that clang-format is wrong here, with non-empty initializers we want a space after the opening brance and before the closing one.
Last time I looked (and IIRC), the kernel intended to still work with an old version of clang-format and that doesn't distinguish between a space between { } and ( ). For the latter we don't want a space, so there is no way to configure clang-format to do the right thing. That's better with newer clang-format versions, but I didn't find a way to specify { } and () without breaking older clang-format.
Best regards
Uwe
Bartosz Golaszewski
maintainerRe: [PATCH 5/5] gpio: ppc44x: tidy up includes and probe
In reply to Rosen PenevQuoted 12 lines · Rosen Penev
Quoted 11 lines · Uwe Kleine-König
Hello Bart,
Quoted 7 lines · Bartosz Golaszewski
Quoted 6 lines
static const struct
of_device_idppc44x_gpio_match[] = {drivers/gpio/gpio-ppc44x.c +1
-3- { - .compatible = "ibm,ppc4xx-gpio", - }, + { .compatible = "ibm,ppc4xx-gpio" }, {},
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
Uwe: is this in line with your recent cleanups?
The change is fine, I'd appreciate to also do
(quoted diff) +1
-1- {}, + { }at the same time.
{} was done by clang-format IIRC.
Uwe: you may want to update .clang-format if you care about this bit.
Bart