devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>, nuno.sa@analog.com
Cc: linux-gpio@vger.kernel.org, linux-pwm@vger.kernel.org,
	devicetree@vger.kernel.org, linux-input@vger.kernel.org,
	"Lee Jones" <lee@kernel.org>, "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Uwe Kleine-König" <ukleinek@kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Liu Ying" <victor.liu@nxp.com>
Subject: Re: [PATCH v2 07/17] gpio: adp5585: add support for the ad5589 expander
Date: Mon, 21 Apr 2025 13:22:25 +0100	[thread overview]
Message-ID: <f478582f9d5af6b3ab55d6f84a6342bcf90f8707.camel@gmail.com> (raw)
In-Reply-To: <20250421092351.GF29968@pendragon.ideasonboard.com>

On Mon, 2025-04-21 at 12:23 +0300, Laurent Pinchart wrote:
> Hi Nuno,
> 
> Thank you for the patch.
> 
> On Tue, Apr 15, 2025 at 03:49:23PM +0100, Nuno Sá via B4 Relay wrote:
> > From: Nuno Sá <nuno.sa@analog.com>
> > 
> > Support the adp5589 I/O expander which supports up to 19 pins. We need
> > to add a chip_info based struct since accessing register "banks"
> > and "bits" differs between devices.
> > 
> > Also some register addresses are different.
> 
> Same comment as for 06/17, splitting the patch in two will make it
> easier to review.
> 
> > Acked-by: Linus Walleij <linus.walleij@linaro.org>
> > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> > ---
> >  drivers/gpio/gpio-adp5585.c | 121 ++++++++++++++++++++++++++++++++---------
> > ---
> >  1 file changed, 88 insertions(+), 33 deletions(-)
> > 
> > diff --git a/drivers/gpio/gpio-adp5585.c b/drivers/gpio/gpio-adp5585.c
> > index
> > d5c0f1b267c82a5002b50cbb7a108166439e4785..d8f8d5513d7f6a9acf5bdecccacc89c461
> > 5ce237 100644
> > --- a/drivers/gpio/gpio-adp5585.c
> > +++ b/drivers/gpio/gpio-adp5585.c
> > @@ -4,6 +4,7 @@
> >   *
> >   * Copyright 2022 NXP
> >   * Copyright 2024 Ideas on Board Oy
> > + * Copyright 2025 Analog Devices, Inc.
> >   */
> >  
> >  #include <linux/device.h>
> > @@ -14,21 +15,49 @@
> >  #include <linux/regmap.h>
> >  #include <linux/types.h>
> >  
> > -#define ADP5585_GPIO_MAX	11
> > +struct adp5585_gpio_chip {
> > +	unsigned int max_gpio;
> > +	int (*bank)(unsigned int off);
> > +	int (*bit)(unsigned int off);
> > +	bool has_bias_hole;
> > +};
> >  
> >  struct adp5585_gpio_dev {
> >  	struct gpio_chip gpio_chip;
> > +	const struct adp5585_gpio_chip *info;
> >  	struct regmap *regmap;
> > +	const struct adp5585_regs *regs;
> >  };
> >  
> > +static int adp5585_gpio_bank(unsigned int off)
> > +{
> > +	return ADP5585_BANK(off);
> 
> While at it, let's move the ADP558[59]_{BANK,BIT} macros to this file,
> and name them ADP558[59]_GPIO_{BANK_BIT}.

Sure...

> 
> > +}
> > +
> > +static int adp5585_gpio_bit(unsigned int off)
> > +{
> > +	return ADP5585_BIT(off);
> > +}
> > +
> > +static int adp5589_gpio_bank(unsigned int off)
> > +{
> > +	return ADP5589_BANK(off);
> > +}
> > +
> > +static int adp5589_gpio_bit(unsigned int off)
> > +{
> > +	return ADP5589_BIT(off);
> > +}
> > +
> >  static int adp5585_gpio_get_direction(struct gpio_chip *chip, unsigned int
> > off)
> >  {
> >  	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
> > -	unsigned int bank = ADP5585_BANK(off);
> > -	unsigned int bit = ADP5585_BIT(off);
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> > +	unsigned int bank = adp5585_gpio->info->bank(off);
> > +	unsigned int bit = adp5585_gpio->info->bit(off);
> >  	unsigned int val;
> >  
> > -	regmap_read(adp5585_gpio->regmap, ADP5585_GPIO_DIRECTION_A + bank,
> > &val);
> > +	regmap_read(adp5585_gpio->regmap, regs->gpio_dir_a + bank, &val);
> >  
> >  	return val & bit ? GPIO_LINE_DIRECTION_OUT :
> > GPIO_LINE_DIRECTION_IN;
> >  }
> > @@ -36,35 +65,37 @@ static int adp5585_gpio_get_direction(struct gpio_chip
> > *chip, unsigned int off)
> >  static int adp5585_gpio_direction_input(struct gpio_chip *chip, unsigned
> > int off)
> >  {
> >  	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
> > -	unsigned int bank = ADP5585_BANK(off);
> > -	unsigned int bit = ADP5585_BIT(off);
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> > +	unsigned int bank = adp5585_gpio->info->bank(off);
> > +	unsigned int bit = adp5585_gpio->info->bit(off);
> >  
> > -	return regmap_clear_bits(adp5585_gpio->regmap,
> > -				 ADP5585_GPIO_DIRECTION_A + bank, bit);
> > +	return regmap_clear_bits(adp5585_gpio->regmap, regs->gpio_dir_a +
> > bank,
> > +				 bit);
> >  }
> >  
> >  static int adp5585_gpio_direction_output(struct gpio_chip *chip, unsigned
> > int off, int val)
> >  {
> >  	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
> > -	unsigned int bank = ADP5585_BANK(off);
> > -	unsigned int bit = ADP5585_BIT(off);
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> > +	unsigned int bank = adp5585_gpio->info->bank(off);
> > +	unsigned int bit = adp5585_gpio->info->bit(off);
> >  	int ret;
> >  
> > -	ret = regmap_update_bits(adp5585_gpio->regmap,
> > -				 ADP5585_GPO_DATA_OUT_A + bank, bit,
> > -				 val ? bit : 0);
> > +	ret = regmap_update_bits(adp5585_gpio->regmap, regs->gpo_data_a +
> > bank,
> > +				 bit, val ? bit : 0);
> >  	if (ret)
> >  		return ret;
> >  
> > -	return regmap_set_bits(adp5585_gpio->regmap,
> > -			       ADP5585_GPIO_DIRECTION_A + bank, bit);
> > +	return regmap_set_bits(adp5585_gpio->regmap, regs->gpio_dir_a +
> > bank,
> > +			       bit);
> >  }
> >  
> >  static int adp5585_gpio_get_value(struct gpio_chip *chip, unsigned int off)
> >  {
> >  	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
> > -	unsigned int bank = ADP5585_BANK(off);
> > -	unsigned int bit = ADP5585_BIT(off);
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> > +	unsigned int bank = adp5585_gpio->info->bank(off);
> > +	unsigned int bit = adp5585_gpio->info->bit(off);
> >  	unsigned int reg;
> >  	unsigned int val;
> >  
> > @@ -79,8 +110,8 @@ static int adp5585_gpio_get_value(struct gpio_chip *chip,
> > unsigned int off)
> >  	 * .direction_input(), .direction_output() or .set() operations
> > racing
> >  	 * with this.
> >  	 */
> > -	regmap_read(adp5585_gpio->regmap, ADP5585_GPIO_DIRECTION_A + bank,
> > &val);
> > -	reg = val & bit ? ADP5585_GPO_DATA_OUT_A : ADP5585_GPI_STATUS_A;
> > +	regmap_read(adp5585_gpio->regmap, regs->gpio_dir_a + bank, &val);
> > +	reg = val & bit ? regs->gpo_data_a : regs->gpi_stat_a;
> >  	regmap_read(adp5585_gpio->regmap, reg + bank, &val);
> >  
> >  	return !!(val & bit);
> > @@ -90,17 +121,19 @@ static int adp5585_gpio_set_value(struct gpio_chip
> > *chip, unsigned int off,
> >  				  int val)
> >  {
> >  	struct adp5585_gpio_dev *adp5585_gpio = gpiochip_get_data(chip);
> > -	unsigned int bank = ADP5585_BANK(off);
> > -	unsigned int bit = ADP5585_BIT(off);
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> > +	unsigned int bank = adp5585_gpio->info->bank(off);
> > +	unsigned int bit = adp5585_gpio->info->bit(off);
> >  
> > -	return regmap_update_bits(adp5585_gpio->regmap,
> > -				  ADP5585_GPO_DATA_OUT_A + bank,
> > +	return regmap_update_bits(adp5585_gpio->regmap, regs->gpo_data_a +
> > bank,
> >  				  bit, val ? bit : 0);
> >  }
> >  
> >  static int adp5585_gpio_set_bias(struct adp5585_gpio_dev *adp5585_gpio,
> >  				 unsigned int off, unsigned int bias)
> >  {
> > +	const struct adp5585_gpio_chip *info = adp5585_gpio->info;
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> >  	unsigned int bit, reg, mask, val;
> >  
> >  	/*
> > @@ -108,8 +141,10 @@ static int adp5585_gpio_set_bias(struct
> > adp5585_gpio_dev *adp5585_gpio,
> >  	 * consecutive registers ADP5585_RPULL_CONFIG_*, with a hole of 4
> > bits
> >  	 * after R5.
> >  	 */
> > -	bit = off * 2 + (off > 5 ? 4 : 0);
> > -	reg = ADP5585_RPULL_CONFIG_A + bit / 8;
> > +	bit = off * 2;
> > +	if (info->has_bias_hole)
> > +		bit += (off > 5 ? 4 : 0);
> > +	reg = regs->rpull_cfg_a + bit / 8;
> >  	mask = ADP5585_Rx_PULL_CFG_MASK << (bit % 8);
> >  	val = bias << (bit % 8);
> >  
> > @@ -119,22 +154,24 @@ static int adp5585_gpio_set_bias(struct
> > adp5585_gpio_dev *adp5585_gpio,
> >  static int adp5585_gpio_set_drive(struct adp5585_gpio_dev *adp5585_gpio,
> >  				  unsigned int off, enum pin_config_param
> > drive)
> >  {
> > -	unsigned int bank = ADP5585_BANK(off);
> > -	unsigned int bit = ADP5585_BIT(off);
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> > +	unsigned int bank = adp5585_gpio->info->bank(off);
> > +	unsigned int bit = adp5585_gpio->info->bit(off);
> >  
> >  	return regmap_update_bits(adp5585_gpio->regmap,
> > -				  ADP5585_GPO_OUT_MODE_A + bank, bit,
> > +				  regs->gpo_out_a + bank, bit,
> >  				  drive == PIN_CONFIG_DRIVE_OPEN_DRAIN ?
> > bit : 0);
> >  }
> >  
> >  static int adp5585_gpio_set_debounce(struct adp5585_gpio_dev *adp5585_gpio,
> >  				     unsigned int off, unsigned int
> > debounce)
> >  {
> > -	unsigned int bank = ADP5585_BANK(off);
> > -	unsigned int bit = ADP5585_BIT(off);
> > +	const struct adp5585_regs *regs = adp5585_gpio->regs;
> > +	unsigned int bank = adp5585_gpio->info->bank(off);
> > +	unsigned int bit = adp5585_gpio->info->bit(off);
> >  
> >  	return regmap_update_bits(adp5585_gpio->regmap,
> > -				  ADP5585_DEBOUNCE_DIS_A + bank, bit,
> > +				  regs->debounce_dis_a + bank, bit,
> >  				  debounce ? 0 : bit);
> >  }
> >  
> > @@ -175,6 +212,7 @@ static int adp5585_gpio_set_config(struct gpio_chip
> > *chip, unsigned int off,
> >  static int adp5585_gpio_probe(struct platform_device *pdev)
> >  {
> >  	struct adp5585_dev *adp5585 = dev_get_drvdata(pdev->dev.parent);
> > +	const struct platform_device_id *id = platform_get_device_id(pdev);
> >  	struct adp5585_gpio_dev *adp5585_gpio;
> >  	struct device *dev = &pdev->dev;
> >  	struct gpio_chip *gc;
> > @@ -185,6 +223,11 @@ static int adp5585_gpio_probe(struct platform_device
> > *pdev)
> >  		return -ENOMEM;
> >  
> >  	adp5585_gpio->regmap = adp5585->regmap;
> > +	adp5585_gpio->regs = adp5585->info->regs;
> > +
> > +	adp5585_gpio->info = (const struct adp5585_gpio_chip *)id-
> > >driver_data;
> > +	if (!adp5585_gpio->info)
> > +		return -ENODEV;
> >  
> >  	device_set_of_node_from_dev(dev, dev->parent);
> >  
> > @@ -199,7 +242,7 @@ static int adp5585_gpio_probe(struct platform_device
> > *pdev)
> >  	gc->can_sleep = true;
> >  
> >  	gc->base = -1;
> > -	gc->ngpio = ADP5585_GPIO_MAX;
> > +	gc->ngpio = adp5585->info->max_cols + adp5585->info->max_rows;
> >  	gc->label = pdev->name;
> >  	gc->owner = THIS_MODULE;
> >  
> > @@ -211,8 +254,20 @@ static int adp5585_gpio_probe(struct platform_device
> > *pdev)
> >  	return 0;
> >  }
> >  
> > +static const struct adp5585_gpio_chip adp5585_gpio_chip_info = {
> > +	.bank = adp5585_gpio_bank,
> > +	.bit = adp5585_gpio_bit,
> > +	.has_bias_hole = true,
> > +};
> > +
> > +static const struct adp5585_gpio_chip adp5589_gpio_chip_info = {
> > +	.bank = adp5589_gpio_bank,
> > +	.bit = adp5589_gpio_bit,
> > +};
> > +
> >  static const struct platform_device_id adp5585_gpio_id_table[] = {
> > -	{ "adp5585-gpio" },
> > +	{ "adp5585-gpio", (kernel_ulong_t)&adp5585_gpio_chip_info },
> > +	{ "adp5589-gpio", (kernel_ulong_t)&adp5589_gpio_chip_info },
> >  	{ /* Sentinel */ }
> >  };
> >  MODULE_DEVICE_TABLE(platform, adp5585_gpio_id_table);

  reply	other threads:[~2025-04-21 12:22 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 14:49 [PATCH v2 00/17] mfd: adp5585: support keymap events and drop legacy Input driver Nuno Sá via B4 Relay
2025-04-15 14:49 ` [PATCH v2 01/17] dt-bindings: mfd: adp5585: ease on the required properties Nuno Sá via B4 Relay
2025-04-21  8:56   ` Laurent Pinchart
2025-04-21 12:12     ` Nuno Sá
2025-04-21 12:29       ` Laurent Pinchart
2025-04-21 12:45         ` Nuno Sá
2025-04-21 18:57   ` Rob Herring (Arm)
2025-04-15 14:49 ` [PATCH v2 02/17] mfd: adp5585: enable oscilator during probe Nuno Sá via B4 Relay
2025-04-21  8:57   ` Laurent Pinchart
2025-04-21 12:14     ` Nuno Sá
2025-04-21 22:03       ` Laurent Pinchart
2025-04-22  7:50         ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 03/17] pwm: adp5585: don't control OSC_EN in the pwm driver Nuno Sá via B4 Relay
2025-04-15 14:49 ` [PATCH v2 04/17] mfd: adp5585: make use of MFD_CELL_NAME() Nuno Sá via B4 Relay
2025-04-21  9:03   ` Laurent Pinchart
2025-04-24 15:55   ` Lee Jones
2025-04-15 14:49 ` [PATCH v2 05/17] dt-bindings: mfd: adp5585: document adp5589 I/O expander Nuno Sá via B4 Relay
2025-04-21  9:07   ` Laurent Pinchart
2025-04-21 18:59   ` Rob Herring (Arm)
2025-04-15 14:49 ` [PATCH v2 06/17] mfd: adp5585: add support for adp5589 Nuno Sá via B4 Relay
2025-04-21  9:15   ` Laurent Pinchart
2025-04-21 12:21     ` Nuno Sá
2025-04-21 22:06       ` Laurent Pinchart
2025-04-22  7:51         ` Nuno Sá
2025-04-24 16:01         ` Lee Jones
2025-04-24 16:18   ` Lee Jones
2025-04-24 16:30     ` Laurent Pinchart
2025-04-24 16:38       ` Lee Jones
2025-04-24 19:39         ` Laurent Pinchart
2025-04-25  7:58           ` Lee Jones
2025-04-25  9:13             ` Laurent Pinchart
2025-04-25  9:23               ` Lee Jones
2025-04-28  9:24               ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 07/17] gpio: adp5585: add support for the ad5589 expander Nuno Sá via B4 Relay
2025-04-17 12:27   ` Bartosz Golaszewski
2025-04-21  9:23   ` Laurent Pinchart
2025-04-21 12:22     ` Nuno Sá [this message]
2025-04-15 14:49 ` [PATCH v2 08/17] pwm: adp5585: add support for adp5589 Nuno Sá via B4 Relay
2025-04-15 14:49 ` [PATCH v2 09/17] dt-bindings: mfd: adp5585: add properties for input events Nuno Sá via B4 Relay
2025-04-21  9:28   ` Laurent Pinchart
2025-04-21 12:24     ` Nuno Sá
2025-04-29 15:03   ` Rob Herring (Arm)
2025-04-15 14:49 ` [PATCH v2 10/17] mfd: adp5585: add support for key events Nuno Sá via B4 Relay
2025-04-21  9:33   ` Laurent Pinchart
2025-04-21 12:32     ` Nuno Sá
2025-04-21 22:13       ` Laurent Pinchart
2025-04-24 16:07     ` Lee Jones
2025-04-24 16:24       ` Laurent Pinchart
2025-04-24 16:28         ` Lee Jones
2025-04-15 14:49 ` [PATCH v2 11/17] gpio: adp5585: support gpi events Nuno Sá via B4 Relay
2025-04-17 12:28   ` Bartosz Golaszewski
2025-04-15 14:49 ` [PATCH v2 12/17] Input: adp5585: Add Analog Devices ADP5585/89 support Nuno Sá via B4 Relay
2025-04-19  2:44   ` Dmitry Torokhov
2025-04-21  9:35   ` Laurent Pinchart
2025-04-21 12:33     ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 13/17] Input: adp5589: remove the driver Nuno Sá via B4 Relay
2025-04-19  2:45   ` Dmitry Torokhov
2025-04-21  9:40   ` Laurent Pinchart
2025-04-21 12:34     ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 14/17] mfd: adp5585: support getting vdd regulator Nuno Sá via B4 Relay
2025-04-21  9:48   ` Laurent Pinchart
2025-04-21 12:38     ` Nuno Sá
2025-04-21 22:09       ` Laurent Pinchart
2025-04-22  8:12         ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 15/17] dt-bindings: mfd: adp5585: document reset gpio Nuno Sá via B4 Relay
2025-04-21  9:36   ` Laurent Pinchart
2025-04-15 14:49 ` [PATCH v2 16/17] mfd: adp5585: add support for a reset pin Nuno Sá via B4 Relay
2025-04-21  9:46   ` Laurent Pinchart
2025-04-21 12:42     ` Nuno Sá
2025-04-21 22:10       ` Laurent Pinchart
2025-04-15 14:49 ` [PATCH v2 17/17] pwm: adp5585: make sure to include mod_devicetable.h Nuno Sá via B4 Relay
2025-04-21  9:50   ` Laurent Pinchart
2025-04-15 15:56 ` [PATCH v2 00/17] mfd: adp5585: support keymap events and drop legacy Input driver Laurent Pinchart
2025-04-21 10:08   ` Laurent Pinchart
2025-04-16  9:02 ` Liu Ying
2025-04-16 10:03   ` Nuno Sá
2025-05-01 12:00 ` Lee Jones
2025-05-01 14:09   ` Laurent Pinchart
2025-05-02  7:13     ` Lee Jones
2025-05-02  7:35       ` Nuno Sá
2025-05-02  8:30         ` Lee Jones

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=f478582f9d5af6b3ab55d6f84a6342bcf90f8707.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --cc=ukleinek@kernel.org \
    --cc=victor.liu@nxp.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).