devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matti Vaittinen <mazziesaccount@gmail.com>
To: David Lechner <dlechner@baylibre.com>,
	Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"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>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Marcelo Schmitt" <marcelo.schmitt@analog.com>,
	"Javier Carrasco" <javier.carrasco.cruz@gmail.com>,
	"Tobias Sperling" <tobias.sperling@softing.com>,
	"Antoniu Miclaus" <antoniu.miclaus@analog.com>,
	"Trevor Gamblin" <tgamblin@baylibre.com>,
	"Esteban Blanc" <eblanc@baylibre.com>,
	"Ramona Alexandra Nechita" <ramona.nechita@analog.com>,
	"Thomas Bonnefille" <thomas.bonnefille@bootlin.com>,
	"Hans de Goede" <hansg@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org
Subject: Re: [PATCH 2/3] iio: adc: Support ROHM BD79112 ADC/GPIO
Date: Wed, 3 Sep 2025 10:03:24 +0300	[thread overview]
Message-ID: <b2650751-2f23-4508-9959-c55bc0530dfa@gmail.com> (raw)
In-Reply-To: <a6ae372e-e0c9-4874-8be1-8070ee3e880f@baylibre.com>

On 02/09/2025 18:14, David Lechner wrote:
> On 9/2/25 7:24 AM, Matti Vaittinen wrote:
>> The ROHM BD79112 is an ADC/GPIO with 32 channels. The channel inputs can
>> be used as ADC or GPIO. Using the GPIOs as IRQ sources isn't supported.
>>
>> The ADC is 12-bit, supporting input voltages up to 5.7V, and separate I/O
>> voltage supply. Maximum SPI clock rate is 20 MHz (10 MHz with
>> daisy-chain configuration) and maximum sampling rate is 1MSPS.
>>
>> The IC does also support CRC but it is not implemented in the driver.
>>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>> ---
>>   drivers/iio/adc/Kconfig        |  10 +
>>   drivers/iio/adc/Makefile       |   1 +
>>   drivers/iio/adc/rohm-bd79112.c | 542 +++++++++++++++++++++++++++++++++
>>   3 files changed, 553 insertions(+)
>>   create mode 100644 drivers/iio/adc/rohm-bd79112.c
>>
>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>> index e3d3826c3357..4b78929bb257 100644
>> --- a/drivers/iio/adc/Kconfig
>> +++ b/drivers/iio/adc/Kconfig
>> @@ -1309,6 +1309,16 @@ config RN5T618_ADC
>>   	  This driver can also be built as a module. If so, the module
>>   	  will be called rn5t618-adc.
>>   
>> +config ROHM_BD79112
>> +	tristate "Rohm BD79112 ADC driver"
>> +	depends on I2C && GPIOLIB
>> +	select REGMAP_I2C
> 
> I think you want SPI rather than I2C. :-)

Ouch! :) Well spotted! Thanks!

> 
>> +	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, which analog
>> +	  inputs can also be used for GPIO.
>> +
> 
> 
> 
>> +struct bd79112_data {
>> +	struct spi_device *spi;
>> +	struct regmap *map;
>> +	struct device *dev;
>> +	struct gpio_chip gc;
>> +	unsigned long gpio_valid_mask;
>> +	unsigned int vref_mv;
>> +	struct spi_transfer read_xfer[2];
>> +	struct spi_transfer write_xfer;
>> +	struct spi_message read_msg;
>> +	struct spi_message write_msg;
>> +	/* 16-bit TX, valid data in high byte */
>> +	u8 read_tx[2] __aligned(IIO_DMA_MINALIGN);
>> +	/* 8-bit address followed by 8-bit data */
>> +	u8 reg_write_tx[2] __aligned(IIO_DMA_MINALIGN);
>> +	/* 12-bit of ADC data or 8 bit of reg data */
>> +	__be16 read_rx __aligned(IIO_DMA_MINALIGN);
> 
> Usually, we only need one __aligned(IIO_DMA_MINALIGN) (on the first
> field). Since these are only used for SPI messages and we can only
> send one message at a time, there isn't a way for there to be a
> problem that would require them to each need to be in their own
> cache line.

I was wondering about this and hoping to get a good comment explaining 
it :) I noticed I don't really know how different SPI controllers handle 
DMA or cache. Hence I just went with what felt like safest option - and 
hoped to get a comment like yours if it wasn't needed ;) So, Thanks!

> 
>> +};
>> +
> 
> 
> 
>> +static int bd79112_probe(struct spi_device *spi)
>> +{
> 
> ...
> 
>> +	iio_dev->channels = cs;
>> +	iio_dev->num_channels = ret;
> 
> This is quite far from where it is assigned. Better to have a dedicated
> local variable for this.

Gah! I agree. Actually there is now a bug where the 
iio_dev->num_channels is used before it is set. So, datasheet names 
won't be assigned correctly. (I did some re-ordering of stuff in probe 
to cover the 'all ADCs and all GPIOs cases. I must've messed this at 
that point!).

Thanks! I feel like I owe you a beer :] Just remind me if we meet! ;)

Yours,
	-- Matti

  reply	other threads:[~2025-09-03  7:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 12:23 [PATCH 0/3] Support ROHM BD79112 ADC Matti Vaittinen
2025-09-02 12:23 ` [PATCH 1/3] dt-bindings: iio: adc: ROHM BD79112 ADC/GPIO Matti Vaittinen
2025-09-02 17:57   ` Rob Herring (Arm)
2025-09-02 12:24 ` [PATCH 2/3] iio: adc: Support " Matti Vaittinen
2025-09-02 14:15   ` Andy Shevchenko
2025-09-03  6:52     ` Matti Vaittinen
2025-09-03 11:23       ` Andy Shevchenko
2025-09-03 12:14         ` Matti Vaittinen
2025-09-03 13:29           ` Andy Shevchenko
2025-09-04 12:35             ` Matti Vaittinen
2025-09-04 13:04               ` Andy Shevchenko
2025-09-05  5:47     ` Matti Vaittinen
2025-09-02 15:14   ` David Lechner
2025-09-03  7:03     ` Matti Vaittinen [this message]
2025-09-02 22:34   ` Linus Walleij
2025-09-03  5:23     ` Matti Vaittinen
2025-09-03  6:47       ` Linus Walleij
2025-09-03  7:17         ` Matti Vaittinen
2025-09-03  7:17         ` Matti Vaittinen
2025-09-03  8:17           ` Matti Vaittinen
2025-09-03 11:02         ` Nuno Sá
2025-09-03 11:27           ` Andy Shevchenko
2025-09-04 14:02   ` kernel test robot
2025-09-02 12:30 ` [PATCH 3/3] MAINTAINERS: Support ROHM BD79112 ADC 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=b2650751-2f23-4508-9959-c55bc0530dfa@gmail.com \
    --to=mazziesaccount@gmail.com \
    --cc=andy@kernel.org \
    --cc=antoniu.miclaus@analog.com \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eblanc@baylibre.com \
    --cc=hansg@kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.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=nuno.sa@analog.com \
    --cc=ramona.nechita@analog.com \
    --cc=robh@kernel.org \
    --cc=tgamblin@baylibre.com \
    --cc=thomas.bonnefille@bootlin.com \
    --cc=tobias.sperling@softing.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).