[PATCH 12/15] gpio: spacemit-k1: use new generic GPIO chip API

Yixun Lan dlan at gentoo.org
Tue Sep 9 02:39:58 PDT 2025


On 11:15 Tue 09 Sep     , Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski at linaro.org>
> 
> Convert the driver to using the new generic GPIO chip interfaces from
> linux/gpio/generic.h.
> 
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski at linaro.org>
Thanks for converting this

Reviewed-by: Yixun Lan <dlan at gentoo.org>

> ---
>  drivers/gpio/gpio-spacemit-k1.c | 28 ++++++++++++++++++++--------
>  1 file changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-spacemit-k1.c b/drivers/gpio/gpio-spacemit-k1.c
> index 3cc75c701ec40194e602b80d3f96f23204ce3b4d..9e57f43d3d13ad28fcd3327ecdc3f359691a44c9 100644
> --- a/drivers/gpio/gpio-spacemit-k1.c
> +++ b/drivers/gpio/gpio-spacemit-k1.c
> @@ -6,6 +6,7 @@
>  
>  #include <linux/clk.h>
>  #include <linux/gpio/driver.h>
> +#include <linux/gpio/generic.h>
>  #include <linux/init.h>
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
> @@ -38,7 +39,7 @@
>  struct spacemit_gpio;
>  
>  struct spacemit_gpio_bank {
> -	struct gpio_chip gc;
> +	struct gpio_generic_chip chip;
>  	struct spacemit_gpio *sg;
>  	void __iomem *base;
>  	u32 irq_mask;
> @@ -72,7 +73,7 @@ static irqreturn_t spacemit_gpio_irq_handler(int irq, void *dev_id)
>  		return IRQ_NONE;
>  
>  	for_each_set_bit(n, &pending, BITS_PER_LONG)
> -		handle_nested_irq(irq_find_mapping(gb->gc.irq.domain, n));
> +		handle_nested_irq(irq_find_mapping(gb->chip.gc.irq.domain, n));
>  
>  	return IRQ_HANDLED;
>  }
> @@ -143,7 +144,7 @@ static void spacemit_gpio_irq_print_chip(struct irq_data *data, struct seq_file
>  {
>  	struct spacemit_gpio_bank *gb = irq_data_get_irq_chip_data(data);
>  
> -	seq_printf(p, "%s-%d", dev_name(gb->gc.parent), spacemit_gpio_bank_index(gb));
> +	seq_printf(p, "%s-%d", dev_name(gb->chip.gc.parent), spacemit_gpio_bank_index(gb));
>  }
>  
>  static struct irq_chip spacemit_gpio_chip = {
> @@ -165,7 +166,7 @@ static bool spacemit_of_node_instance_match(struct gpio_chip *gc, unsigned int i
>  	if (i >= SPACEMIT_NR_BANKS)
>  		return false;
>  
> -	return (gc == &sg->sgb[i].gc);
> +	return (gc == &sg->sgb[i].chip.gc);
>  }
>  
>  static int spacemit_gpio_add_bank(struct spacemit_gpio *sg,
> @@ -173,7 +174,8 @@ static int spacemit_gpio_add_bank(struct spacemit_gpio *sg,
>  				  int index, int irq)
>  {
>  	struct spacemit_gpio_bank *gb = &sg->sgb[index];
> -	struct gpio_chip *gc = &gb->gc;
> +	struct gpio_generic_chip_config config;
> +	struct gpio_chip *gc = &gb->chip.gc;
>  	struct device *dev = sg->dev;
>  	struct gpio_irq_chip *girq;
>  	void __iomem *dat, *set, *clr, *dirin, *dirout;
> @@ -187,9 +189,19 @@ static int spacemit_gpio_add_bank(struct spacemit_gpio *sg,
>  	dirin	= gb->base + SPACEMIT_GCDR;
>  	dirout	= gb->base + SPACEMIT_GSDR;
>  
> +	config = (typeof(config)){
> +		.dev = dev,
> +		.sz = 4,
> +		.dat = dat,
> +		.set = set,
> +		.clr = clr,
> +		.dirout = dirout,
> +		.dirin = dirin,
> +		.flags = BGPIOF_UNREADABLE_REG_SET | BGPIOF_UNREADABLE_REG_DIR,
> +	};
> +
>  	/* This registers 32 GPIO lines per bank */
> -	ret = bgpio_init(gc, dev, 4, dat, set, clr, dirout, dirin,
> -			 BGPIOF_UNREADABLE_REG_SET | BGPIOF_UNREADABLE_REG_DIR);
> +	ret = gpio_generic_chip_init(&gb->chip, &config);
>  	if (ret)
>  		return dev_err_probe(dev, ret, "failed to init gpio chip\n");
>  
> @@ -221,7 +233,7 @@ static int spacemit_gpio_add_bank(struct spacemit_gpio *sg,
>  	ret = devm_request_threaded_irq(dev, irq, NULL,
>  					spacemit_gpio_irq_handler,
>  					IRQF_ONESHOT | IRQF_SHARED,
> -					gb->gc.label, gb);
> +					gb->chip.gc.label, gb);
>  	if (ret < 0)
>  		return dev_err_probe(dev, ret, "failed to register IRQ\n");
>  
> 
> -- 
> 2.48.1
> 

-- 
Yixun Lan (dlan)



More information about the Linux-mediatek mailing list