Support ROHM BD79111 ADC/GPIO
Subsystems (3)
v3 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).
Revision history:
v2 => v3:
dt-bindings:
- No changes
driver:
- move 'Return -ENODATA instead of -ENODEV when no SPI match data is found' -fix to the patch 2/3, which introduces the SPI match data usage.
- Fix double semicolon and drop the unused macro.
- Suffle comment wording as was requested by Andy.
v1 => v2:
dt-bindings:
- Don't drop the 'root-level' additionalProperties: false
driver + Kconfig:
- Styling as suggested by Andy / Jonathan
- Split to two patches as suggested by Andy
- Return -ENODATA instead of -ENODEV when no SPI match data is found
Matti Vaittinen (3):
dt-bindings: iio: Support ROHM BD79111
iio: adc: rohm-bd79112: Add chip info structure
iio: adc: rohm-bd79112: Support ROHM BD79111
.../bindings/iio/adc/rohm,bd79112.yaml | 29 ++++- drivers/iio/adc/Kconfig | 10 +- drivers/iio/adc/rohm-bd79112.c | 112 ++++++++++++++---- 3 files changed, 120 insertions(+), 31 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.1
PATCH v3 1/3 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.
---
Revision history:
v2 =>
- No changes
--- .../bindings/iio/adc/rohm,bd79112.yaml | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/iio/adc/rohm,bd79112.yaml +24 -5
@@ -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
@@ -45,7 +48,9 @@ patternProperties: properties: reg: - description: AIN pin number + description: + AIN pin number. The BD79111 has pins 0 - 15, the BD79112 has pins + 0 - 31. minimum: 0 maximum: 31
@@ -64,6 +69,20 @@ required: additionalProperties: false +allOf: + - if: + properties: + compatible: + contains: + const: rohm,bd79111 + then: + patternProperties: + "^channel@([0-9]|1[0-5])$": + properties: + reg: + maximum: 15 + "^channel@(1[6-9]|2[0-9]|3[01])$": false + examples: - | spi {
Signature · 1 line
2.56.1
PATCH v3 2/3 iio: adc: rohm-bd79112: Add chip info structure
In reply to Matti VaittinenFrom: Matti Vaittinen <[email protected]>
A new ADC variant, ROHM BD79111 is going to be supported by this same driver. As a preparatory step, introduce chip-specific data and pick it at probe time based on the spi-match data. This allows describing the necessary hardware differencies in data structures, which tends to result cleaner solution than some CHIP_ID specific switch-case blocks.
---
Revision history:
v2 => v3:
- Use return -ENODATA if SPI match data is not available
v1 => v2:
- Split the chip-ID introduction into own patch as suggested by Andy.
--- drivers/iio/adc/rohm-bd79112.c | 45 +++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-)
drivers/iio/adc/rohm-bd79112.c +36 -9
@@ -26,7 +26,15 @@#define BD79112_MAX_NUM_CHANNELS 32 +struct bd79112_data ; + +struct bd7911x_chip_data { +const char *const *chan_names; +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;
@@ -398,6 +406,19 @@ static unsigned int bd79112_get_gpio_pins(const struct iio_chan_spec *cs, int nureturn gpio_channels; } +static int bd79112_disable_gpios (struct bd79112_data *data) +{ +int ret; + +for (unsigned int i =0 ; i <BD79112_NUM_GPIO_EN_REGS ; i++) { + ret =regmap_write (data->map,BD79112_FIRST_GPIO_EN_REG + i,0 ); +if (ret) +return ret; + } + +return 0 ; +} +/* ADC channels as named in the data-sheet */ static const char *const bd79112_chan_names[] = {"AGIO0A" ,"AGIO1A" ,"AGIO2A" ,"AGIO3A" ,/* 0 - 3 */
@@ -410,6 +431,11 @@ static const char * const bd79112_chan_names[] = { "AGIO12B", "AGIO13B", "AGIO14B", "AGIO15B", /* 28 - 31 */ }; +static const struct bd7911x_chip_data bd79112_chip_data = { + .chan_names = bd79112_chan_names, + .init_disable_gpios = bd79112_disable_gpios, +}; +static int bd79112_probe (struct spi_device *spi) {struct bd79112_data *data;
@@ -425,6 +451,10 @@ static int bd79112_probe(struct spi_device *spi)return -ENOMEM ; data =iio_priv (iio_dev); + data->cd =spi_get_device_match_data (spi); +if (!data->cd) +return -ENODATA ; + data->spi = spi; data->dev = dev; data->map =devm_regmap_init (dev,NULL , data, &bd79112_regmap);
@@ -476,7 +506,7 @@ static int bd79112_probe(struct spi_device *spi) iio_dev->channels = cs;for (i =0 ; i < iio_dev->num_channels; i++) - cs[i].datasheet_name = bd79112_chan_names[cs[i].channel]; + cs[i].datasheet_name = data->cd->chan_names[cs[i].channel]; iio_dev->info = &bd79112_info; iio_dev->name ="bd79112" ;
@@ -488,12 +518,9 @@ static int bd79112_probe(struct spi_device *spi)* without having to worry about some pins being initially used for * GPIO. */ -for (i =0 ; i <BD79112_NUM_GPIO_EN_REGS ; i++) { - ret =regmap_write (data->map,BD79112_FIRST_GPIO_EN_REG + i,0 ); -if (ret) -return dev_err_probe (dev, ret, -"Failed to initialize channels\n" ); - } + ret = data->cd->init_disable_gpios (data); +if (ret) +return dev_err_probe (dev, ret,"Failed to initialize channels\n" ); ret =devm_iio_device_register (data->dev, iio_dev);if (ret)
@@ -523,13 +550,13 @@ static int bd79112_probe(struct spi_device *spi) }static const struct of_device_id bd79112_of_match[] = { - { .compatible ="rohm,bd79112" }, + { .compatible ="rohm,bd79112" , .data = &bd79112_chip_data }, { } };MODULE_DEVICE_TABLE (of, bd79112_of_match);static const struct spi_device_id bd79112_id[] = { - { .name ="bd79112" }, + { .name ="bd79112" , .driver_data = (kernel_ulong_t)&bd79112_chip_data }, { } };MODULE_DEVICE_TABLE (spi, bd79112_id);
Signature · 1 line
2.56.1
PATCH v3 3/3 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.
Reviewed-by; Andy Shevchenko <[email protected]>
---
Revision history:
v2 => v3:
- Drop unused define
- Fix accidential double-semicolon
- Comment nitpick fix
v1 => v2:
- Various styling fixes as suggested by Jonathan and Andy
- Return -ENODATA instead of -ENODEV when SPI match data is not available.
--- drivers/iio/adc/Kconfig | 10 +++-- drivers/iio/adc/rohm-bd79112.c | 69 +++++++++++++++++++++++++++------- 2 files changed, 61 insertions(+), 18 deletions(-)
drivers/iio/adc/Kconfig +6 -4
@@ -1516,14 +1516,16 @@ config RN5T618_ADC will be called rn5t618-adc. config ROHM_BD79112 - tristate "Rohm BD79112 ADC driver" + tristate "ADC/GPIO Driver for ROHM BD79112 et al." 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 following ROHM SAR ADCs: + - BD79111 (12-bit, 16 channels) + - BD79112 (12-bit, 32 channels) + + Analog inputs can also be used for GPIO. config ROHM_BD79124 tristate "Rohm BD79124 ADC driver"
drivers/iio/adc/rohm-bd79112.c +55 -14
172 lines not on this page · raw message
Signature · 1 line
2.56.1