All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: William Breathitt Gray <william.gray@linaro.org>
Cc: linus.walleij@linaro.org, brgl@bgdev.pl,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	michael@walle.cc, broonie@kernel.org
Subject: Re: [PATCH v3 7/9] gpio: 104-dio-48e: Migrate to regmap API
Date: Wed, 23 Nov 2022 19:43:59 +0200	[thread overview]
Message-ID: <Y35b38dVXJxI4fk+@smile.fi.intel.com> (raw)
In-Reply-To: <79705f8932321afd05df52156ef149dc1c9c632c.1669100542.git.william.gray@linaro.org>

On Tue, Nov 22, 2022 at 02:11:04AM -0500, William Breathitt Gray wrote:
> The regmap API supports IO port accessors so we can take advantage of
> regmap abstractions rather than handling access to the device registers
> directly in the driver. The 104-dio-48e module is migrated to the new
> i8255 library interface leveraging the gpio-regmap API.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

(see also below)

> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
> ---
>  drivers/gpio/gpio-104-dio-48e.c | 147 ++------------------------------
>  1 file changed, 7 insertions(+), 140 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-104-dio-48e.c b/drivers/gpio/gpio-104-dio-48e.c
> index fcee3dc81902..64f4044150b7 100644
> --- a/drivers/gpio/gpio-104-dio-48e.c
> +++ b/drivers/gpio/gpio-104-dio-48e.c
> @@ -9,7 +9,6 @@
>  #include <linux/bits.h>
>  #include <linux/device.h>
>  #include <linux/err.h>
> -#include <linux/gpio/driver.h>
>  #include <linux/ioport.h>
>  #include <linux/irq.h>
>  #include <linux/isa.h>
> @@ -42,90 +41,6 @@ MODULE_PARM_DESC(irq, "ACCES 104-DIO-48E interrupt line numbers");
>  
>  #define DIO48E_NUM_PPI 2
>  
> -/**
> - * struct dio48e_reg - device register structure
> - * @ppi:		Programmable Peripheral Interface groups
> - */
> -struct dio48e_reg {
> -	struct i8255 ppi[DIO48E_NUM_PPI];
> -};
> -
> -/**
> - * struct dio48e_gpio - GPIO device private data structure
> - * @chip:		instance of the gpio_chip
> - * @ppi_state:		PPI device states
> - * @reg:		I/O address offset for the device registers
> - */
> -struct dio48e_gpio {
> -	struct gpio_chip chip;
> -	struct i8255_state ppi_state[DIO48E_NUM_PPI];
> -	struct dio48e_reg __iomem *reg;
> -};
> -
> -static int dio48e_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
> -
> -	if (i8255_get_direction(dio48egpio->ppi_state, offset))
> -		return GPIO_LINE_DIRECTION_IN;
> -
> -	return GPIO_LINE_DIRECTION_OUT;
> -}
> -
> -static int dio48e_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
> -
> -	i8255_direction_input(dio48egpio->reg->ppi, dio48egpio->ppi_state,
> -			      offset);
> -
> -	return 0;
> -}
> -
> -static int dio48e_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
> -					int value)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
> -
> -	i8255_direction_output(dio48egpio->reg->ppi, dio48egpio->ppi_state,
> -			       offset, value);
> -
> -	return 0;
> -}
> -
> -static int dio48e_gpio_get(struct gpio_chip *chip, unsigned int offset)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
> -
> -	return i8255_get(dio48egpio->reg->ppi, offset);
> -}
> -
> -static int dio48e_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
> -	unsigned long *bits)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
> -
> -	i8255_get_multiple(dio48egpio->reg->ppi, mask, bits, chip->ngpio);
> -
> -	return 0;
> -}
> -
> -static void dio48e_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
> -
> -	i8255_set(dio48egpio->reg->ppi, dio48egpio->ppi_state, offset, value);
> -}
> -
> -static void dio48e_gpio_set_multiple(struct gpio_chip *chip,
> -	unsigned long *mask, unsigned long *bits)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(chip);
> -
> -	i8255_set_multiple(dio48egpio->reg->ppi, dio48egpio->ppi_state, mask,
> -			   bits, chip->ngpio);
> -}
> -
>  static const struct regmap_range dio48e_wr_ranges[] = {
>  	regmap_reg_range(0x0, 0x9), regmap_reg_range(0xB, 0xB),
>  	regmap_reg_range(0xD, 0xD), regmap_reg_range(0xF, 0xF),
> @@ -237,35 +152,10 @@ static const char *dio48e_names[DIO48E_NGPIO] = {
>  	"PPI Group 1 Port C 5", "PPI Group 1 Port C 6", "PPI Group 1 Port C 7"
>  };
>  
> -static int dio48e_irq_init_hw(struct gpio_chip *gc)
> -{
> -	struct dio48e_gpio *const dio48egpio = gpiochip_get_data(gc);
> -
> -	/* Disable IRQ by default */
> -	ioread8(&dio48egpio->reg->enable_interrupt);
> -
> -	return 0;
> -}
> -
> -static void dio48e_init_ppi(struct i8255 __iomem *const ppi,
> -			    struct i8255_state *const ppi_state)
> -{
> -	const unsigned long ngpio = 24;
> -	const unsigned long mask = GENMASK(ngpio - 1, 0);
> -	const unsigned long bits = 0;
> -	unsigned long i;
> -
> -	/* Initialize all GPIO to output 0 */
> -	for (i = 0; i < DIO48E_NUM_PPI; i++) {
> -		i8255_mode0_output(&ppi[i]);
> -		i8255_set_multiple(&ppi[i], &ppi_state[i], &mask, &bits, ngpio);
> -	}
> -}
> -
>  static int dio48e_probe(struct device *dev, unsigned int id)
>  {
> -	struct dio48e_gpio *dio48egpio;
>  	const char *const name = dev_name(dev);

> +	struct i8255_regmap_config config = {0};

{} will work okay.

>  	void __iomem *regs;
>  	struct regmap *map;
>  	unsigned int val;
> @@ -274,10 +164,6 @@ static int dio48e_probe(struct device *dev, unsigned int id)
>  	unsigned int irq_mask;
>  	struct regmap_irq_chip_data *chip_data;
>  
> -	dio48egpio = devm_kzalloc(dev, sizeof(*dio48egpio), GFP_KERNEL);
> -	if (!dio48egpio)
> -		return -ENOMEM;
> -
>  	if (!devm_request_region(dev, base[id], DIO48E_EXTENT, name)) {
>  		dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
>  			base[id], base[id] + DIO48E_EXTENT);
> @@ -287,7 +173,6 @@ static int dio48e_probe(struct device *dev, unsigned int id)
>  	regs = devm_ioport_map(dev, base[id], DIO48E_EXTENT);
>  	if (!regs)
>  		return -ENOMEM;
> -	dio48egpio->reg = regs;
>  
>  	map = devm_regmap_init_mmio(dev, regs, &dio48e_regmap_config);
>  	if (IS_ERR(map))
> @@ -324,31 +209,13 @@ static int dio48e_probe(struct device *dev, unsigned int id)
>  		return err;
>  	}
>  
> -	dio48egpio->chip.label = name;
> -	dio48egpio->chip.parent = dev;
> -	dio48egpio->chip.owner = THIS_MODULE;
> -	dio48egpio->chip.base = -1;
> -	dio48egpio->chip.ngpio = DIO48E_NGPIO;
> -	dio48egpio->chip.names = dio48e_names;
> -	dio48egpio->chip.get_direction = dio48e_gpio_get_direction;
> -	dio48egpio->chip.direction_input = dio48e_gpio_direction_input;
> -	dio48egpio->chip.direction_output = dio48e_gpio_direction_output;
> -	dio48egpio->chip.get = dio48e_gpio_get;
> -	dio48egpio->chip.get_multiple = dio48e_gpio_get_multiple;
> -	dio48egpio->chip.set = dio48e_gpio_set;
> -	dio48egpio->chip.set_multiple = dio48e_gpio_set_multiple;
> -
> -	i8255_state_init(dio48egpio->ppi_state, DIO48E_NUM_PPI);
> -	dio48e_init_ppi(dio48egpio->reg->ppi, dio48egpio->ppi_state);
> -
> -	err = devm_gpiochip_add_data(dev, &dio48egpio->chip, dio48egpio);
> -	if (err) {
> -		dev_err(dev, "GPIO registering failed (%d)\n", err);
> -		return err;
> -	}
> +	config.parent = dev;
> +	config.map = map;
> +	config.num_ppi = DIO48E_NUM_PPI;
> +	config.names = dio48e_names;
> +	config.domain = regmap_irq_get_domain(chip_data);
>  
> -	return gpiochip_irqchip_add_domain(&dio48egpio->chip,
> -					   regmap_irq_get_domain(chip_data));
> +	return devm_i8255_regmap_register(dev, &config);
>  }
>  
>  static struct isa_driver dio48e_driver = {
> -- 
> 2.38.1
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2022-11-23 17:44 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22  7:10 [PATCH v3 0/9] Migrate i8255 GPIO drivers to regmap API William Breathitt Gray
2022-11-22  7:10 ` [PATCH v3 1/9] gpio: regmap: Always set gpio_chip get_direction William Breathitt Gray
2022-11-22  7:10 ` [PATCH v3 2/9] regmap-irq: Add handle_mask_sync() callback William Breathitt Gray
2022-11-22  7:11 ` [PATCH v3 3/9] gpio: 104-dio-48e: Migrate to the regmap-irq API William Breathitt Gray
2022-11-23 15:01   ` Andy Shevchenko
2022-11-22 10:29     ` William Breathitt Gray
2022-11-27 18:31       ` Michael Walle
2022-11-27 22:00         ` William Breathitt Gray
2022-11-28  9:51           ` Andy Shevchenko
2022-11-28  9:56             ` Andy Shevchenko
2022-11-28 10:04               ` Andy Shevchenko
2022-11-28  9:41         ` Andy Shevchenko
2022-11-28  9:56           ` Michael Walle
2022-11-28 10:02             ` Andy Shevchenko
2022-11-22  7:11 ` [PATCH v3 4/9] gpio: 104-idi-48: " William Breathitt Gray
2022-11-23 17:28   ` Andy Shevchenko
2022-11-22  7:11 ` [PATCH v3 5/9] gpio: 104-idi-48: Migrate to gpio-regmap API William Breathitt Gray
2022-11-23 17:31   ` Andy Shevchenko
2022-11-22  7:11 ` [PATCH v3 6/9] gpio: i8255: " William Breathitt Gray
2022-11-23 17:42   ` Andy Shevchenko
2022-11-22 11:34     ` William Breathitt Gray
2022-11-22  7:11 ` [PATCH v3 7/9] gpio: 104-dio-48e: Migrate to regmap API William Breathitt Gray
2022-11-23 17:43   ` Andy Shevchenko [this message]
2022-11-22  7:11 ` [PATCH v3 8/9] gpio: gpio-mm: " William Breathitt Gray
2022-11-23 17:46   ` Andy Shevchenko
2022-11-22  7:11 ` [PATCH v3 9/9] gpio: i8255: Remove unused legacy interface William Breathitt Gray
2022-11-23 17:31   ` Andy Shevchenko
2022-12-09 18:59 ` (subset) [PATCH v3 0/9] Migrate i8255 GPIO drivers to regmap API Mark Brown

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=Y35b38dVXJxI4fk+@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=broonie@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=william.gray@linaro.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 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.