Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Janani Sunil <janani.sunil@analog.com>
Cc: "Michael Walle" <mwalle@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Janani Sunil" <jananisunil.dev@gmail.com>
Subject: Re: [PATCH v6 3/3] gpio: ad7768: Add AD7768 GPIO auxiliary driver
Date: Thu, 3 Sep 2026 18:21:28 +0300	[thread overview]
Message-ID: <apmQePRVxyrWFiAZ@ashevche-desk.local> (raw)
In-Reply-To: <20260903-ad7768-gpio-v6-3-4254ef6c9b38@analog.com>

On Thu, Sep 03, 2026 at 02:01:28PM +0200, Janani Sunil wrote:
> The AD7768 provides five GPIOs controlled through registers shared
> with the parent IIO device. Register an auxiliary gpio-regmap driver
> and use the parent device for runtime PM.
> 
> The device has separate input-state and output-latch registers. Add a
> reg_mask_xlate() callback that checks the line direction and reads the
> programmed output latch for output lines while retaining input-state
> reads for input lines.

...

> +#include <linux/bitmap.h>

Hmm... as far as I can see this is an overkill and bitops.h should suffice.

...

> +static int ad7768_gpio_init_valid_mask(struct gpio_chip *gc,
> +				       unsigned long *valid_mask,
> +				       unsigned int ngpios)
> +{
> +	if (ngpios > AD7768_FILTER_GPIO &&
> +	    device_property_match_string(gc->parent->parent, "clock-names",
> +					 "mclk") < 0)
> +		bitmap_clear(valid_mask, AD7768_FILTER_GPIO, 1);

This is a single bit, we have __clear_bit() for that in bitops.h.

> +	return 0;
> +}

...

> +static int ad7768_gpio_probe(struct auxiliary_device *adev,
> +			     const struct auxiliary_device_id *id)
> +{
> +	struct gpio_regmap_config config;
> +	struct device *dev = &adev->dev;

> +	struct device *parent;

Assign it here, this callback must not be called with dev == NULL, so it's fine
to dereference it without validation.

	struct device *parent = dev->parent;

> +	struct regmap *map;
> +	int ret;

> +	parent = dev->parent;

And drop this.

> +	map = dev_get_regmap(parent, NULL);
> +	if (!map)
> +		return -ENODEV;
> +
> +	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(parent, pm);
> +	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_set_bits(map, AD7768_REG_GPIO_CONTROL, AD7768_GPIO_UGPIO_ENABLE);
> +	if (ret)
> +		return ret;
> +
> +	config = (struct gpio_regmap_config) {
> +		.parent = dev,
> +		.regmap = map,
> +		.label = dev_name(parent),
> +		.ngpio = AD7768_NUM_GPIOS,
> +		.reg_dat_base = AD7768_REG_GPIO_READ,
> +		.reg_set_base = AD7768_REG_GPIO_WRITE,
> +		.reg_dir_out_base = AD7768_REG_GPIO_CONTROL,
> +		.pm_dev = parent,
> +		.reg_mask_xlate = ad7768_gpio_reg_mask_xlate,
> +		.init_valid_mask = ad7768_gpio_init_valid_mask,
> +		.drvdata = map,
> +	};
> +
> +	return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &config));
> +}

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-09-03 15:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 12:01 [PATCH v6 0/3] gpio: Add AD7768 GPIO support Janani Sunil
2026-09-03 12:01 ` [PATCH v6 1/3] gpio: regmap: Use regmap_test_bits() for single bit reads Janani Sunil
2026-09-03 12:01 ` [PATCH v6 2/3] gpio: regmap: Add optional runtime PM support Janani Sunil
2026-09-04  6:44   ` Michael Walle
2026-09-03 12:01 ` [PATCH v6 3/3] gpio: ad7768: Add AD7768 GPIO auxiliary driver Janani Sunil
2026-09-03 15:21   ` Andy Shevchenko [this message]

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=apmQePRVxyrWFiAZ@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=brgl@kernel.org \
    --cc=janani.sunil@analog.com \
    --cc=jananisunil.dev@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mwalle@kernel.org \
    --cc=nuno.sa@analog.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