Support ROHM BD79111 ADC/GPIO
Subsystems (3)
cover Support ROHM BD79111 ADC/GPIO
Support ROHM BD79111 ADC/GPIO
The ROHM BD79111 is a 12-bit, 16 channel SAR ADC / GPIO IC. Or, a "Signal Monitor Hub IC" as data-sheet describes it. The key difference compared to already supported BD79112 is the reduced number of channels (16, BD79112 had 32) and halved sampling rate (500 KSPS when BD79112 data-sheet stated 1 MSPS).
Matti Vaittinen (2):
dt-bindings: Support ROHM BD79111
iio: adc: rohm-bd79112: Support ROHM BD79111
.../bindings/iio/adc/rohm,bd79112.yaml | 72 +++++++---- drivers/iio/adc/Kconfig | 9 +- drivers/iio/adc/rohm-bd79112.c | 113 ++++++++++++++---- 3 files changed, 148 insertions(+), 46 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.1
PATCH 1/2 dt-bindings: iio: Support ROHM BD79111
From: Matti Vaittinen <[email protected]>
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, I had to change the 'root-level' additionalProperties: false to
unevaluatedProperties: false in order to allow the properties in the new allOf:
- if:
...
section. It seems to me this is what a few other bindings in IIO do, but I suppose it makes this "less strict". Well, since I am terrible with writing bindings, I'd better point this out and ask if it's ok, or if there are better way(s) to handle this?
--- .../bindings/iio/adc/rohm,bd79112.yaml | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-)
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +50 -22
@@ -4,18 +4,21 @@ $id: http://devicetree.org/schemas/iio/adc/rohm,bd79112.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ROHM BD79112 ADC/GPO +title: ROHM BD79111 and BD79112 ADC/GPIO maintainers: - Matti Vaittinen <[email protected]> description: | - The ROHM BD79112 is a 12-bit, 32-channel, SAR ADC. ADC input pins can be - also configured as general purpose inputs/outputs. SPI should use MODE 3. + The ROHM BD79112 is a 12-bit, 32-channel, SAR ADC. The ROHM BD79111 is + a 12-bit, 16-channel, SAR ADC. ADC input pins can be also configured as + general purpose inputs/outputs. SPI should use MODE 3. properties: compatible: - const: rohm,bd79112 + enum: + - rohm,bd79111 + - rohm,bd79112 reg: maxItems: 1
@@ -37,23 +40,6 @@ properties: "#size-cells": const: 0 -patternProperties: - "^channel@([0-9]|[12][0-9]|3[01])$": - type: object - $ref: /schemas/iio/adc/adc.yaml# - description: Represents ADC channel. Omitted channels' inputs are GPIOs. - - properties: - reg: - description: AIN pin number - minimum: 0 - maximum: 31 - - required: - - reg - - additionalProperties: false - required: - compatible - reg
@@ -62,7 +48,49 @@ required: - spi-cpha - spi-cpol -additionalProperties: false +unevaluatedProperties: false + +allOf: + - if: + properties: + compatible: + contains: + const: rohm,bd79112 + then: + patternProperties: + "^channel@([0-9]|[12][0-9]|3[01])$": + type: object + $ref: /schemas/iio/adc/adc.yaml# + description: Represents ADC channel. Omitted channels' inputs are GPIOs. + + properties: + reg: + description: AIN pin number + minimum: 0 + maximum: 31 + + required: + - reg + + additionalProperties: false + else: + # BD79111 has only 16 channels + patternProperties: + "^channel@([0-9]|1[0-5])$": + type: object + $ref: /schemas/iio/adc/adc.yaml# + description: Represents ADC channel. Omitted channels' inputs are GPIOs. + + properties: + reg: + description: AIN pin number + minimum: 0 + maximum: 15 + + required: + - reg + + additionalProperties: false examples: - |
Signature · 1 line
2.56.1
PATCH 2/2 iio: adc: rohm-bd79112: Support ROHM BD79111
In reply to Matti VaittinenFrom: Matti Vaittinen <[email protected]>
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.
So, here we aim for simplicity instead of the peak performance.
--- drivers/iio/adc/Kconfig | 9 +-- drivers/iio/adc/rohm-bd79112.c | 113 +++++++++++++++++++++++++++------ 2 files changed, 98 insertions(+), 24 deletions(-)
drivers/iio/adc/Kconfig +5 -4
@@ -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. config ROHM_BD79124 tristate "Rohm BD79124 ADC driver"
drivers/iio/adc/rohm-bd79112.c +93 -20
212 lines not on this page · raw message
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 1/2] dt-bindings: iio: Support ROHM BD79111
In reply to Matti VaittinenThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] dt-bindings: iio: adc: decimal instead of hex regex for channel nodes - [Low] dt-bindings: iio…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] dt-bindings: iio: adc: decimal instead of hex regex for channel nodes
- [Low] dt-bindings: iio: adc: duplicate channel patternProperties inside allOf
--
commit 1d2b4969234a59de95b2a054fda32ad7ef3510e0
Author: Matti Vaittinen <[email protected]>
dt-bindings: iio: Support ROHM BD79111
This commit adds device tree binding support for the 16-channel ROHM BD79111 ADC/GPIO alongside the 32-channel BD79112.
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +0
-0
[ ... ]
Quoted 48 lines
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +19
-18@@ -37,23 +40,6 @@ properties: "#size-cells": const: 0 -patternProperties: - "^channel@([0-9]|[12][0-9]|3[01])$": - type: object - $ref: /schemas/iio/adc/adc.yaml# - description: Represents ADC channel. Omitted channels' inputs are GPIOs. - - properties: - reg: - description: AIN pin number - minimum: 0 - maximum: 31 - - required: - - reg - - additionalProperties: false - required: - compatible - reg@@ -62,7 +48,49 @@ required: - spi-cpha - spi-cpol -additionalProperties: false +unevaluatedProperties: false + +allOf: + - if: + properties: + compatible: + contains: + const: rohm,bd79112 + then: + patternProperties: + "^channel@([0-9]|[12][0-9]|3[01])$": + type: object + $ref: /schemas/iio/adc/adc.yaml# + description: Represents ADC channel. Omitted channels' inputs are GPIOs. + + properties: + reg: + description: AIN pin number + minimum: 0
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml required: · line 79
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +10
-0+ maximum: 31 + + required: + - reg + + additionalProperties: false + else: + # BD79111 has only 16 channels + patternProperties: + "^channel@([0-9]|1[0-5])$":
[Severity: Medium]
Should the channel unit-address regexes match hexadecimal rather than decimal ranges?
Devicetree unit addresses and adc.yaml use lowercase hex without leading zeros, so "^channel@([0-9]|1[0-5])$" rejects valid nodes channel@a through channel@f on rohm,bd79111 while accepting out-of-range channel@10 through channel@15. Likewise, the 32-channel pattern rejects channel@a through channel@f and channel@1a through channel@1f while accepting channel@20 through channel@31; hex ranges would be "^channel@[0-9a-f]$" and "^channel@1?[0-9a-f]$".
Quoted 4 lines
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +4
-0+ type: object + $ref: /schemas/iio/adc/adc.yaml# + description: Represents ADC channel. Omitted channels' inputs are GPIOs. +
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml required: · line 93
Quoted 10 lines
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +10
-0+ properties: + reg: + description: AIN pin number + minimum: 0 + maximum: 15 + + required: + - reg + + additionalProperties: false
[Severity: Low]
Could patternProperties stay at the top level with the 32-channel definition, and have the allOf if/then block for rohm,bd79111 only narrow reg maximum to 15 and disallow the upper 16 channel patterns?
That avoids duplicating the entire channel sub-schema across both branches and allows keeping additionalProperties: false at the root level, matching Documentation/devicetree/bindings/writing-schema.rst.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/2] dt-bindings: iio: Support ROHM BD79111
In reply to Matti VaittinenQuoted 21 lines · Matti Vaittinen
From: Matti Vaittinen <[email protected]>
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.
Signed-off-by Matti Vaittinen <[email protected]>---
Note, I had to change the 'root-level' additionalProperties: false to
unevaluatedProperties: false in order to allow the properties in the new allOf:
- if:
Quoted 6 lines
...section. It seems to me this is what a few other bindings in IIO do, but I suppose it makes this "less strict". Well, since I am terrible with writing bindings, I'd better point this out and ask if it's ok, or if there are better way(s) to handle this?
I don't think you should have to do that though, since the children are described in the same file.
If you instead retained the pattern properties section, and lowered the restriction to channel@<any number> with reg with the max of 31 and in the conditional section constrained reg to a max of 16 does it work without the unevaluatedProperties change? We typically want properties defined at the top level and constrained in conditional sections anyway.
Chees,
Conor.
Quoted 112 lines
--- .../bindings/iio/adc/rohm,bd79112.yaml | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-)Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +50
-22@@ -4,18 +4,21 @@ $id: http://devicetree.org/schemas/iio/adc/rohm,bd79112.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ROHM BD79112 ADC/GPO +title: ROHM BD79111 and BD79112 ADC/GPIO maintainers: - Matti Vaittinen <[email protected]> description: | - The ROHM BD79112 is a 12-bit, 32-channel, SAR ADC. ADC input pins can be - also configured as general purpose inputs/outputs. SPI should use MODE 3. + The ROHM BD79112 is a 12-bit, 32-channel, SAR ADC. The ROHM BD79111 is + a 12-bit, 16-channel, SAR ADC. ADC input pins can be also configured as + general purpose inputs/outputs. SPI should use MODE 3. properties: compatible: - const: rohm,bd79112 + enum: + - rohm,bd79111 + - rohm,bd79112 reg: maxItems: 1@@ -37,23 +40,6 @@ properties: "#size-cells": const: 0 -patternProperties: - "^channel@([0-9]|[12][0-9]|3[01])$": - type: object - $ref: /schemas/iio/adc/adc.yaml# - description: Represents ADC channel. Omitted channels' inputs are GPIOs. - - properties: - reg: - description: AIN pin number - minimum: 0 - maximum: 31 - - required: - - reg - - additionalProperties: false - required: - compatible - reg@@ -62,7 +48,49 @@ required: - spi-cpha - spi-cpol -additionalProperties: false +unevaluatedProperties: false + +allOf: + - if: + properties: + compatible: + contains: + const: rohm,bd79112 + then: + patternProperties: + "^channel@([0-9]|[12][0-9]|3[01])$": + type: object + $ref: /schemas/iio/adc/adc.yaml# + description: Represents ADC channel. Omitted channels' inputs are GPIOs. + + properties: + reg: + description: AIN pin number + minimum: 0 + maximum: 31 + + required: + - reg + + additionalProperties: false + else: + # BD79111 has only 16 channels + patternProperties: + "^channel@([0-9]|1[0-5])$": + type: object + $ref: /schemas/iio/adc/adc.yaml# + description: Represents ADC channel. Omitted channels' inputs are GPIOs. + + properties: + reg: + description: AIN pin number + minimum: 0 + maximum: 15 + + required: + - reg + + additionalProperties: false examples: - |Signature · 1 line
2.56.1
Matti Vaittinen
maintainerRe: [PATCH 1/2] dt-bindings: iio: Support ROHM BD79111
Quoted 29 lines · Conor Dooley
Quoted 21 lines · Matti Vaittinen
From: Matti Vaittinen <[email protected]>
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.
Signed-off-by Matti Vaittinen <[email protected]>---
Note, I had to change the 'root-level' additionalProperties: false to
unevaluatedProperties: false in order to allow the properties in the new allOf:
- if:Quoted 6 lines
...section. It seems to me this is what a few other bindings in IIO do, but I suppose it makes this "less strict". Well, since I am terrible with writing bindings, I'd better point this out and ask if it's ok, or if there are better way(s) to handle this?
Quoted 5 lines
I don't think you should have to do that though, since the children are described in the same file.
If you instead retained the pattern properties section, and lowered the restriction to channel@<any number> with reg with the max of 31 and in the conditional section constrained reg to a max of 16 does it work
Ah. I think it will, thanks for the help! I'll do that in v2. I'll just wait for a while to see what other comments I may collect :)
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Jonathan Cameron
maintainerRe: [PATCH 2/2] iio: adc: rohm-bd79112: Support ROHM BD79111
In reply to Matti VaittinenQuoted 19 lines · On Wed, 18 Nov 2026 16:19:35 +0200 Matti Vaittinen <[email protected]>…
From: Matti Vaittinen <[email protected]>
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.
Quoted 8 lines
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.
Quoted 20 lines
So, here we aim for simplicity instead of the peak performance.
Signed-off-by Matti Vaittinen <[email protected]>--- drivers/iio/adc/Kconfig | 9 +-- drivers/iio/adc/rohm-bd79112.c | 113 +++++++++++++++++++++++++++------ 2 files changed, 98 insertions(+), 24 deletions(-)drivers/iio/adc/Kconfig +1
-1@@ -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
drivers/iio/adc/Kconfig config RN5T618_ADC · line 1527
Quoted 10 lines
drivers/iio/adc/Kconfig +4
-3select 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.
drivers/iio/adc/rohm-bd79112.c line 3
Quoted 12 lines
drivers/iio/adc/Kconfig +0
-0config ROHM_BD79124 tristate "Rohm BD79124 ADC driver"drivers/iio/adc/rohm-bd79112.c +1
-1@@ -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.
Quoted 30 lines
drivers/iio/adc/rohm-bd79112.c +10
-1* 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,
drivers/iio/adc/rohm-bd79112.c static const struct gpio_chip bd79112_gpio_chip = { · line 391
Quoted 6 lines
drivers/iio/adc/rohm-bd79112.c +0
-1@@ -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.
drivers/iio/adc/rohm-bd79112.c static const char * const bd79112_chan_names[] = { · line 427
Quoted 6 lines
drivers/iio/adc/rohm-bd79112.c +6
-0+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.
Quoted 8 lines
drivers/iio/adc/rohm-bd79112.c +7
-0+ ret =regmap_write (data->map,BD79112_FIRST_GPIO_EN_REG + i,0 ); +if (ret) +return ret; + } + +return 0 ; +}
...
Quoted 5 lines
drivers/iio/adc/rohm-bd79112.c +5
-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 */
drivers/iio/adc/rohm-bd79112.c static const char * const bd79112_chan_names[] = { · line 468
Quoted 10 lines
drivers/iio/adc/rohm-bd79112.c +10
-0+"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
Quoted 7 lines
drivers/iio/adc/rohm-bd79112.c +7
-0+ +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, +};
Matti Vaittinen
maintainerRe: [PATCH 2/2] iio: adc: rohm-bd79112: Support ROHM BD79111
Hi & Thanks Jonathan!
Quoted 31 lines · Jonathan Cameron
Quoted 19 lines · On Wed, 18 Nov 2026 16:19:35 +0200 Matti Vaittinen <[email protected]>…
From: Matti Vaittinen <[email protected]>
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.
Quoted 8 lines
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.
Quoted 5 lines
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
Yes. This applies to both of these ADCs. And thanks for the pointer! Once again, I really appreciate your help. I will definitely take a look at how this is done by other ADCs. These two aren't the only (ROHM) ICs using this type of mechanism, so spending some time is well justified :)
Quoted 2 lines
being directly relevant to what is added here? If you did add that support it would be in a different patch.
Sure.
Quoted 2 lines
I'd cut most of that info
to keep the commit message focused.
I kind of agree - while I also believe that noting the performance limitation coming from the driver itself makes sense. It does not need to be this verbose though. Besides, the verbosity already worked as it made you to drop me the above info ;) //snip
Quoted 8 lines
Quoted 8 lines
static const struct gpio_chip bd79112_gpio_chip = {drivers/iio/adc/rohm-bd79112.c +0
-1- .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,
Quoted 8 lines
drivers/iio/adc/rohm-bd79112.c static const struct gpio_chip bd79112_gpio_chip = { · line 391
Quoted 4 lines
drivers/iio/adc/rohm-bd79112.c +0
-1.can_sleep = true, - .ngpio = 32, .base = -1, };There are only two parts, maybe it is simpler to have dual
gpio_chipinstances pointed to by yourchip_data? Keep the full state of each in one place? I don't mind much either way on this.
I didn't even evaluate such option. I'll try it out and see how it looks like.
I agree with all other comments - even though declaring the indexer variable in a for-loop requires a bit of learning ;) (Which doesn't mean limiting the scope didn't make sense when index is not used outside the loop).
Thanks!
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Re: [PATCH 2/2] iio: adc: rohm-bd79112: Support ROHM BD79111
In reply to Matti VaittinenQuoted 28 lines · Matti Vaittinen
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.
So, here we aim for simplicity instead of the peak performance.
...
drivers/iio/adc/Kconfig config RN5T618_ADC · line 1519
Quoted 3 lines
config
ROHM_BD79112drivers/iio/adc/Kconfig +1
-1- tristate "Rohm BD79112 ADC driver" + tristate "ROHM BD79112 and BD79111 ADC/GPIO driver"
So, as Jonathan mentioned this should be rather relaxed, so we don't update it each time the new HW is got supported. Also in a new style we want a bit of an order by having this, text in top comment, and MODULE_DESCRIPTION() to be the same (or very similar, like with or without word 'driver').
drivers/iio/adc/Kconfig config RN5T618_ADC · line 1527
Quoted 11 lines
drivers/iio/adc/Kconfig +4
-3depends 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.
Yeah, and here the style is to have something like a list
Say yes here to build support for the following ROHM SAR ADCs:
- BD7911 (12-bit, 16 channels)
- BD7912 (12-bit, 32 channels)
Analog inputs can also be used for GPIO.
(feel free to amend, it's just an example).
...
drivers/iio/adc/rohm-bd79112.c static const char * const bd79112_chan_names[] = { · line 427
Quoted 6 lines
drivers/iio/adc/rohm-bd79112.c +5
-0+static int bd79112_disable_gpios (struct bd79112_data *data) +{ +unsigned int i; +int ret; +for (i =0 ; i <BD79112_NUM_GPIO_EN_REGS ; i++) {
for (unsigned int i = 0; i < BD79112_NUM_GPIO_EN_REGS; i++) {Quoted 7 lines
drivers/iio/adc/rohm-bd79112.c +7
-0+ ret =regmap_write (data->map,BD79112_FIRST_GPIO_EN_REG + i,0 ); +if (ret) +return ret; + } + +return 0 ; +}
...
drivers/iio/adc/rohm-bd79112.c static const char * const bd79112_chan_names[] = { · line 446
Quoted 11 lines
drivers/iio/adc/rohm-bd79112.c +10
-0+/* The BD79111 only has the registers for pins 0 - 15 */ +static int bd79111_disable_gpios (struct bd79112_data *data) +{ +static const unsigned int regs[] = { +BD79112_REG_GPI_EN_A8_A15 ,BD79112_REG_GPI_EN_A0_A7 , +BD79112_REG_GPO_EN_A8_A15 ,BD79112_REG_GPO_EN_A0_A7 , + }; +unsigned int i; +int ret; +for (i =0 ; i <ARRAY_SIZE (regs); i++) {
for (unsigned int i = 0; i < ARRAY_SIZE(regs); i++) {Quoted 7 lines
drivers/iio/adc/rohm-bd79112.c +7
-0+ ret =regmap_write (data->map, regs[i],0 ); +if (ret) +return ret; + } + +return 0 ; +}
...
drivers/iio/adc/rohm-bd79112.c static int bd79112_probe(struct spi_device *spi) · line 494
Quoted 4 lines
drivers/iio/adc/rohm-bd79112.c +3
-0data =iio_priv (iio_dev); + data->cd =spi_get_device_match_data (spi); +if (!data->cd) +return -ENODEV ;
-ENODATA
...
drivers/iio/adc/rohm-bd79112.c static int bd79112_probe(struct spi_device *spi) · line 589
Quoted 3 lines
drivers/iio/adc/rohm-bd79112.c +3
-0+ data->gc.ngpio = data->cd->num_channels; + data->gc.label =devm_kasprintf (dev,GFP_KERNEL ,"%s-gpio" , + data->cd->name);
I would use a single line.
Quoted 2 lines
drivers/iio/adc/rohm-bd79112.c +2
-0+if (!data->gc.label) +return -ENOMEM ;
...
drivers/iio/adc/rohm-bd79112.c static int bd79112_probe(struct spi_device *spi) · line 600
Quoted 6 lines
static const struct
of_device_idbd79112_of_match[] = {drivers/iio/adc/rohm-bd79112.c +2
-1- { .compatible = "rohm,bd79112" }, + { .compatible = "rohm,bd79111", .data = &bd79111_chip_data }, + { .compatible = "rohm,bd79112", .data = &bd79112_chip_data }, { } };
So, this can be split to two patches:
- introduction of chip_info
- adding a new HW.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Matti Vaittinen
maintainerRe: [PATCH 2/2] iio: adc: rohm-bd79112: Support ROHM BD79111
Quoted 55 lines · Andy Shevchenko
Quoted 28 lines · Matti Vaittinen
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.
So, here we aim for simplicity instead of the peak performance.
...
drivers/iio/adc/Kconfig config RN5T618_ADC · line 1519
Quoted 3 lines
config
ROHM_BD79112drivers/iio/adc/Kconfig +1
-1- tristate "Rohm BD79112 ADC driver" + tristate "ROHM BD79112 and BD79111 ADC/GPIO driver"So, as Jonathan mentioned this should be rather relaxed, so we don't update it each time the new HW is got supported. Also in a new style we want a bit of an order by having this, text in top comment, and
MODULE_DESCRIPTION()to be the same (or very similar, like with or without word 'driver').drivers/iio/adc/Kconfig config RN5T618_ADC · line 1527
Quoted 11 lines
depends on SPI && GPIOLIB select REGMAP_SPI select IIO_ADC_HELPER helpdrivers/iio/adc/Kconfig +4
-3- 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.Yeah, and here the style is to have something like a list
Quoted 7 lines
Say yes here to build support for the following ROHM SAR ADCs:
- BD7911 (12-bit, 16 channels)
- BD7912 (12-bit, 32 channels)Analog inputs can also be used for GPIO.
(feel free to amend, it's just an example).
//snip
Thanks for the examples ...
... and also for the other comments Andy. I'll create v2.
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Matti Vaittinen
maintainerRe: [PATCH 1/2] dt-bindings: iio: Support ROHM BD79111
In reply to Conor DooleyQuoted 29 lines · Conor Dooley
Quoted 21 lines · Matti Vaittinen
From: Matti Vaittinen <[email protected]>
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.
Signed-off-by Matti Vaittinen <[email protected]>---
Note, I had to change the 'root-level' additionalProperties: false to
unevaluatedProperties: false in order to allow the properties in the new allOf:
- if:Quoted 6 lines
...section. It seems to me this is what a few other bindings in IIO do, but I suppose it makes this "less strict". Well, since I am terrible with writing bindings, I'd better point this out and ask if it's ok, or if there are better way(s) to handle this?
Quoted 7 lines
I don't think you should have to do that though, since the children are described in the same file.
If you instead retained the pattern properties section, and lowered the restriction to channel@<any number> with reg with the max of 31 and in the conditional section constrained reg to a max of 16 does it work without the unevaluatedProperties change? We typically want properties defined at the top level and constrained in conditional sections anyway.
Gah. Either I don't know how to do this properly (which is likely), or there is a slight caveat. When I tried to do what you suggest, the binding allowed channel@X, where the <X> was is out of the range. Sure thing this was caught by 'reg' being out of the range, but it still allowed odd combination of
channel@X, reg = <Y>, if Y was in accepted range.
I suppose the 'X' and 'Y' in previous example are expected to always be the same, but I would still like to catch this type of an error.
I am about to spin v2 where I use the BD79112 limits (channels 0 to 31 allowed) in the pattern properties, and then do:
"^channel@(1[6-9]|2[0-9]|3[01])$": false
to exclude 16 - 31 from the BD79111.
I am not super happy with it, but it seems to work and is still decently understandable even for someone yaml -illiterate like myself. :/ (At least for as long as we only have ICs which don't increase the amount of default channels. That might cause the exclusion regexp on other ICs to become ridiculously long or hard to read. Well, I don't have such ICs on sight for now.)
Well, let's see what people think of it :)
Yours,
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~
Re: [PATCH 1/2] dt-bindings: iio: Support ROHM BD79111
Quoted 43 lines · Matti Vaittinen
Quoted 29 lines · Conor Dooley
Quoted 21 lines · Matti Vaittinen
From: Matti Vaittinen <[email protected]>
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.
Signed-off-by Matti Vaittinen <[email protected]>---
Note, I had to change the 'root-level' additionalProperties: false to
unevaluatedProperties: false in order to allow the properties in the new allOf:
- if:Quoted 6 lines
...section. It seems to me this is what a few other bindings in IIO do, but I suppose it makes this "less strict". Well, since I am terrible with writing bindings, I'd better point this out and ask if it's ok, or if there are better way(s) to handle this?
Quoted 7 lines
I don't think you should have to do that though, since the children are described in the same file.
If you instead retained the pattern properties section, and lowered the restriction to channel@<any number> with reg with the max of 31 and in the conditional section constrained reg to a max of 16 does it work without the unevaluatedProperties change? We typically want properties defined at the top level and constrained in conditional sections anyway.Gah. Either I don't know how to do this properly (which is likely), or there is a slight caveat. When I tried to do what you suggest, the binding allowed channel@X, where the <X> was is out of the range. Sure thing this was caught by 'reg' being out of the range, but it still allowed odd combination of
Quoted 7 lines
channel@X, reg = <Y>, if Y was in accepted range.
I suppose the 'X' and 'Y' in previous example are expected to always be the same, but I would still like to catch this type of an error.
I am about to spin v2 where I use the BD79112 limits (channels 0 to 31 allowed) in the pattern properties, and then do:
Yeah, I kinda fucked you a bit here sorry. I just mentioned this way as an easier way to fiddle around/debug it than having to meddle with the regexes, with the intention of following up promptly when you replied saying that what you have done for v2 is how you would implement it in practice.
Quoted 23 lines
"^channel@(1[6-9]|2[0-9]|3[01])$": false
to exclude 16 - 31 from the BD79111.I am not super happy with it, but it seems to work and is still decently understandable even for someone yaml -illiterate like myself. :/ (At least for as long as we only have ICs which don't increase the amount of default channels. That might cause the exclusion regexp on other ICs to become ridiculously long or hard to read. Well, I don't have such ICs on sight for now.)
Well, let's see what people think of it :)
Yours,
-- MattiSignature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~