Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Matti Vaittinen <matti.vaittinen@linux.dev>,
	Jakub Szczudlo <jakubszczudlo40@gmail.com>
Cc: "Matti Vaittinen" <mazziesaccount@gmail.com>,
	"Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
	"Joshua Crofts" <joshua.crofts1@gmail.com>,
	"Radu Sabau" <radu.sabau@analog.com>,
	"Janani Sunil" <janani.sunil@analog.com>,
	"Salih Erim" <salih.erim@amd.com>,
	"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: adc: rohm-bd79112: Support ROHM BD79111
Date: Thu, 19 Nov 2026 02:51:47 +0000	[thread overview]
Message-ID: <20261119025137.6bfc27c2@jic23-hlaptop> (raw)
In-Reply-To: <ab74e547e892ccabb763a06e8231e8ed44f4fefb.1795009599.git.mazziesaccount@gmail.com>

On Wed, 18 Nov 2026 16:19:35 +0200
Matti Vaittinen <matti.vaittinen@linux.dev> wrote:

> From: Matti Vaittinen <mazziesaccount@gmail.com>
> 
> ROHM BD79111 is very similar to the BD79112. Both are ADC/GPIO devices,
> where pins can be configured to be either used as GPIO or ADC inputs.
> ADCs are 12-bit SAR ADCs and GPIOs support input/output but not being IRQ
> sources.
> 
> The main difference is amount of channels/GPIOs. The BD79112 has 32 pins
> for this use, the BD79111 has 16. Furthermore, the BD79111 data-sheet
> promises 0.5 MSPS sample rate with maximum of 10 MHz SPI clock,  whereas
> the BD79112 data-sheet mentioned 1MSPS rate with maximum of 20 MHz SPI
> clock.
> 
> NOTE: In order to achieve those speeds one needs to use more optimized
> protocol compared to the one implemented in this driver. This driver
> retrieves samples using two 16-bit SPI transactions. The first
> transaction writes the channel to be sampled, and ignores data on MISO.
> Then the next 16-bit transaction carries the data.
> 
> Achieving maximum sample-rate would require the driver to interpret the
> MISO data of each 16-bit transaction so, that when the
> channel-to-be-sampled was sent in transaction N, the data is read at
> transaction N+1 - which also already configures the channel to be
> sampled for transaction N+2. Supporting this would require the
> channel-to-be-read for the future read to be known when the current
> channel data is retrieved. For raw-reads this is not possible and for
> buffered reads it would make things a bit hairy.

FWIW there are quite a few drivers implementing that scheme for
buffered capture.  Look for drivers that preprepare an SPI transfer.
Absolutely fine to not support that optimization!

This seems like text that probably applies to both parts rather than
being directly relevant to what is added here?  If you did add that
support it would be in a different patch.  I'd cut most of that info
to keep the commit message focused.

> 
> So, here we aim for simplicity instead of the peak performance.
> 
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> ---
>  drivers/iio/adc/Kconfig        |   9 +--
>  drivers/iio/adc/rohm-bd79112.c | 113 +++++++++++++++++++++++++++------
>  2 files changed, 98 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index a802d8ee4dd9..db9e0a0713e1 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -1516,14 +1516,15 @@ config RN5T618_ADC
>  	  will be called rn5t618-adc.
>  
>  config ROHM_BD79112
> -	tristate "Rohm BD79112 ADC driver"
> +	tristate "ROHM BD79112 and BD79111 ADC/GPIO driver"
>  	depends on SPI && GPIOLIB
>  	select REGMAP_SPI
>  	select IIO_ADC_HELPER
>  	help
> -	  Say yes here to build support for the ROHM BD79112 ADC. The
> -	  ROHM BD79112 is a 12-bit, 32-channel, SAR ADC. Analog inputs
> -	  can also be used for GPIO.
> +	  Say yes here to build support for the ROHM BD79112 and BD79111
> +	  ADCs. Both of the ICs are 12-bit SAR ADCs. The ROHM BD79112 has
> +	  32-channels, the BD79111 has 16. Analog inputs can also be used
> +	  for GPIO.

Given it now supports 2 parts and I'm guessing more may be along in the future
you might want to jump directly to the style we have in some other kconfig
entries of vague option text and then a bulleted list of stuff about
specific devices.  That way a new part just requires a new bullet point,
nothing else changes.

>  
>  config ROHM_BD79124
>  	tristate "Rohm BD79124 ADC driver"
> diff --git a/drivers/iio/adc/rohm-bd79112.c b/drivers/iio/adc/rohm-bd79112.c
> index 2506fec7be84..604c6ccafb4f 100644
> --- a/drivers/iio/adc/rohm-bd79112.c
> +++ b/drivers/iio/adc/rohm-bd79112.c
> @@ -1,6 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0-only
>  /*
> - * ROHM ADC driver for BD79112 signal monitoring hub.
> + * ROHM ADC driver for BD79111 and BD79112 signal monitoring hubs.

Similar on possibly going vague. The firmware tables make it clear
on what is being supported.

>   * Copyright (C) 2025, ROHM Semiconductor.
>   *
>   * SPI communication derived from ad7923.c and ti-ads7950.c
> @@ -26,7 +26,17 @@
>  
>  #define BD79112_MAX_NUM_CHANNELS 32
>  
> +struct bd79112_data;
> +
> +struct bd7911x_chip_data {
> +	const char *name;
> +	const char * const *chan_names;
> +	unsigned int num_channels;
> +	int (*init_disable_gpios)(struct bd79112_data *data);
> +};
> +
>  struct bd79112_data {
> +	const struct bd7911x_chip_data *cd;
>  	struct spi_device *spi;
>  	struct regmap *map;
>  	struct device *dev;
> @@ -369,7 +379,6 @@ static int bd79112_gpio_output(struct gpio_chip *gc, unsigned int offset,
>  }
>  
>  static const struct gpio_chip bd79112_gpio_chip = {
> -	.label			= "bd79112-gpio",
>  	.get_direction		= bd79112_gpio_dir_get,
>  	.direction_input	= bd79112_gpio_input,
>  	.direction_output	= bd79112_gpio_output,
> @@ -378,20 +387,20 @@ static const struct gpio_chip bd79112_gpio_chip = {
>  	.set_multiple		= bd79112_gpio_set_multiple,
>  	.init_valid_mask	= bd79112_gpio_init_valid_mask,
>  	.can_sleep		= true,
> -	.ngpio			= 32,
>  	.base			= -1,
>  };

There are only two parts, maybe it is simpler to have dual gpio_chip
instances pointed to by your chip_data? Keep the full state of each in
one place?  I don't mind much either way on this.

> +static int bd79112_disable_gpios(struct bd79112_data *data)
> +{
> +	unsigned int i;
> +	int ret;
> +
> +	for (i = 0; i < BD79112_NUM_GPIO_EN_REGS; i++) {

These days the kernel style allows

	for (unsigned int i = 0; i < BD79112_NUM_GPIO_EN_REGS; i++) {
Same in various other places. Saves us a few lines of scrolling
and keeps the scope tight.

> +		ret = regmap_write(data->map, BD79112_FIRST_GPIO_EN_REG + i, 0);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}
>

...

> +
> +/* The BD79111 channel names as in the data-sheet */
> +static const char * const bd79111_chan_names[] = {
> +	"AGIO0", "AGIO1", "AGIO2", "AGIO3",		/* 0 - 3 */
> +	"AGIO4", "AGIO5", "AGIO6", "AGIO7",		/* 4 - 7 */
> +	"AGIO8", "AGIO9", "AGIO10", "AGIO11",		/* 8 - 11 */
> +	"AGIO12", "AGIO13", "AGIO14", "AGIO15",		/* 12 - 15 */
> +};
> +
> +static const struct bd7911x_chip_data bd79111_chip_data = {
> +	.name = "bd79111",
> +	.chan_names = bd79111_chan_names,
> +	.num_channels = 16,
> +	.init_disable_gpios = bd79111_disable_gpios,
> +};
Ordering seems a little strange with the bd79112_chan_names no
where near the ones for the 1111
> +
> +static const struct bd7911x_chip_data bd79112_chip_data = {
> +	.name = "bd79112",
> +	.chan_names = bd79112_chan_names,
> +	.num_channels = 32,
> +	.init_disable_gpios = bd79112_disable_gpios,
> +};


  reply	other threads:[~2026-11-19  2:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:18 [PATCH 0/2] Support ROHM BD79111 ADC/GPIO Matti Vaittinen
2026-11-18 14:19 ` [PATCH 1/2] dt-bindings: iio: Support ROHM BD79111 Matti Vaittinen
2026-11-18 14:34   ` sashiko-bot
2026-11-18 17:37   ` Conor Dooley
2026-11-18 17:46     ` Matti Vaittinen
2026-11-18 14:19 ` [PATCH 2/2] iio: adc: rohm-bd79112: " Matti Vaittinen
2026-11-19  2:51   ` Jonathan Cameron [this message]
2026-11-19  7:13     ` Matti Vaittinen
2026-11-19  9:00   ` Andy Shevchenko
2026-11-19  9:09     ` Matti Vaittinen

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=20261119025137.6bfc27c2@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=antoniu.miclaus@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jakubszczudlo40@gmail.com \
    --cc=janani.sunil@analog.com \
    --cc=joshua.crofts1@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt@analog.com \
    --cc=matti.vaittinen@fi.rohmeurope.com \
    --cc=matti.vaittinen@linux.dev \
    --cc=mazziesaccount@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=radu.sabau@analog.com \
    --cc=robh@kernel.org \
    --cc=salih.erim@amd.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