Support ROHM BD797xx DACs
Subsystems (3)
Matti Vaittinen
maintainercover Support ROHM BD797xx DACs
Support ROHM BD797xx DACs
ROHM BD79700, BD79701 and BD79702 are very similar to the already sipported BD79703. Main difference is the reduced number of channels. Also, the *00 and *01 variants lack of the separate Vfs pin.
This series adds support for the BD79700, BD79701 and BD79702.
---
Matti Vaittinen (5):
dt-bindings: Add ROHM BD7970x variants
iio: dac: bd79703 Store device address to 'address'
dac: bd79703: Add chip data
iio: bd79703: Support BD79700 and BD79701
iio: dac: bd79703: Support ROHM BD79702
.../bindings/iio/dac/rohm,bd79703.yaml | 33 +++-- drivers/iio/dac/rohm-bd79703.c | 116 +++++++++++++++--- 2 files changed, 126 insertions(+), 23 deletions(-)
base-commit: 543da6252b48bbfe13e194fb980bdd2b161f6838
Signature · 1 line
2.49.0
Matti Vaittinen
maintainerPATCH 1/5 dt-bindings: Add ROHM BD7970x variants
The ROHM BD79700, BD79701 and BD79702 are subsets of the BD79703 DAC. The main difference is the number of the channels. BD79703 has 6 channels.
The BD79702 has 4, BD79701 3 and BD79700 2 channels. Additionally, the BD79700 and BD79701 do not have separate Vfs pin but use the Vcc also for the full-scale voltage.
Add properties for the BD79700, BD79701 and BD79702.
--- .../bindings/iio/dac/rohm,bd79703.yaml | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/iio/dac/rohm,bd79703.yaml +26 -7
@@ -5,19 +5,26 @@ $id: http://devicetree.org/schemas/iio/dac/rohm,bd79703.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ROHM BD79703 DAC device driver +title: ROHM BD79700, BD79701, BD79702 and BD79703 DACs maintainers: - Matti Vaittinen <[email protected]> description: | - The ROHM BD79703 is a 6 channel, 8-bit DAC. - Datasheet can be found here: + The ROHM BD7970[0,1,2,3] are 8-bit DACs. The BD79700 has 2 channels, + BD79701 3 channels, BD79702 4 channels and BD79703 has 6 channels. + Datasheets for BD79702 and BD79703 can be found from https://fscdn.rohm.com/en/products/databook/datasheet/ic/data_converter/dac/bd79702fv-lb_bd79703fv-lb-e.pdf + and for the BD79700 and the BD79701 from + https://fscdn.rohm.com/en/products/databook/datasheet/ic/data_converter/dac/bd79700fvm-lb_bd79701fvm-lb-e.pdf properties: compatible: - const: rohm,bd79703 + enum: + - rohm,bd79700 + - rohm,bd79701 + - rohm,bd79702 + - rohm,bd79703 reg: maxItems: 1
@@ -27,19 +34,31 @@ properties: vfs-supply: description: - The regulator to use as a full scale voltage. The voltage should be between 2.7V .. VCC + The regulator to use as a full scale voltage. The voltage should be + between 2.7V .. VCC. Not present on BD79700 and BD79701. vcc-supply: description: - The regulator supplying the operating voltage. Should be between 2.7V ... 5.5V + The regulator supplying the operating voltage. Should be between + 2.7V ... 5.5V. Is used also as a Vfs on BD79700 and BD79701. required: - compatible - reg - spi-max-frequency - - vfs-supply - vcc-supply +if: + properties: + compatible: + contains: + enum: + - rohm,bd79702 + - rohm,bd79703 +then: + required: + - vfs-supply + allOf: - $ref: /schemas/spi/spi-peripheral-props.yaml#
Signature · 1 line
2.49.0
Re: [PATCH 1/5] dt-bindings: Add ROHM BD7970x variants
Quoted 11 lines · Matti Vaittinen
The ROHM BD79700, BD79701 and BD79702 are subsets of the BD79703 DAC. The main difference is the number of the channels. BD79703 has 6 channels.
The BD79702 has 4, BD79701 3 and BD79700 2 channels. Additionally, the BD79700 and BD79701 do not have separate Vfs pin but use the Vcc also for the full-scale voltage.
Add properties for the BD79700, BD79701 and BD79702.
Signed-off-by Matti Vaittinen <[email protected]>
Matti Vaittinen
maintainerPATCH 2/5 iio: dac: bd79703 Store device address to 'address'
In reply to Matti VaittinenThe ROHM BD79703 needs to identify a channel which we are reading from in the SPI transfers. This can be seen as an address for the device.
For the bd79703 the address is nicely aligned with the channel number, so the driver uses the channel ID for the SPI transfers. This, however, does not need to be the case. The iio_chan_spec has a separate 'address' field, which we can populate directly with this information.
This helps adding new ICs like the ROHM BD79702 where the channel ID is different from this address to be handled by this driver, so we don't need to have separate, IC specific mapping for channel numbers <=> addresses.
Make the 'address' field in the iio_chan_spec to contain the SPI protocol address for the channel, and use this value in the transfers.
--- drivers/iio/dac/rohm-bd79703.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/dac/rohm-bd79703.c +2 -2
@@ -67,7 +67,7 @@ static int bd79703_write_raw(struct iio_dev *idev,if (val <0 || val >=1 <<BD79703_DAC_BITS )return -EINVAL ; -return regmap_write (data->regmap, chan->channel +1 , val); +return regmap_write (data->regmap, chan->address, val); };static const struct iio_info bd79703_info = {
@@ -82,7 +82,7 @@ static const struct iio_info bd79703_info = { .channel = (_chan), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ - .address = (_chan), \ + .address = (_chan + 1), \ }static const struct iio_chan_spec bd79703_channels[] = {
Signature · 1 line
2.49.0
Matti Vaittinen
maintainerPATCH 3/5 dac: bd79703: Add chip data
In reply to Matti VaittinenAdd a chip data structure which allows handling the different variants (ROHM BD79700, BD79701) with different number of channels.
--- drivers/iio/dac/rohm-bd79703.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-)
drivers/iio/dac/rohm-bd79703.c +24 -5
@@ -38,11 +38,19 @@ static const struct regmap_config bd79703_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +/* Dynamic driver private data */ struct bd79703_data {struct regmap *regmap;int vfs; }; +/* Static, IC type specific data for different variants */ +struct bd7970x_chip_data { +const char *name; +const struct iio_chan_spec *channels; +int num_channels; +}; +static int bd79703_read_raw (struct iio_dev *idev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)
@@ -94,13 +102,24 @@ static const struct iio_chan_spec bd79703_channels[] = { BD79703_CHAN(5), }; +static const struct bd7970x_chip_data bd79703_chip_data = { + .name ="bd79703" , + .channels = bd79703_channels, + .num_channels =ARRAY_SIZE (bd79703_channels), +}; +static int bd79703_probe (struct spi_device *spi) { +const struct bd7970x_chip_data *cd;struct device *dev = &spi->dev;struct bd79703_data *data;struct iio_dev *idev;int ret; + cd =spi_get_device_match_data (spi); +if (!cd) +return -ENODEV ; + idev =devm_iio_device_alloc (dev,sizeof (*data));if (!idev)return -ENOMEM ;
@@ -121,11 +140,11 @@ static int bd79703_probe(struct spi_device *spi)return dev_err_probe (dev, ret,"Failed to get Vfs\n" ); data->vfs = ret; - idev->channels = bd79703_channels; - idev->num_channels =ARRAY_SIZE (bd79703_channels); + idev->channels = cd->channels; + idev->num_channels = cd->num_channels; idev->modes =INDIO_DIRECT_MODE ; idev->info = &bd79703_info; - idev->name ="bd79703" ; + idev->name = cd->name;/* Initialize all to output zero */ ret =regmap_write (data->regmap,BD79703_REG_OUT_ALL ,0 );
@@ -136,13 +155,13 @@ static int bd79703_probe(struct spi_device *spi) }static const struct spi_device_id bd79703_id[] = { - {"bd79703" , }, + {"bd79703" , (kernel_ulong_t)&bd79703_chip_data }, { } };MODULE_DEVICE_TABLE (spi, bd79703_id);static const struct of_device_id bd79703_of_match[] = { - { .compatible ="rohm,bd79703" , }, + { .compatible ="rohm,bd79703" , .data = &bd79703_chip_data }, { } };MODULE_DEVICE_TABLE (of, bd79703_of_match);
Signature · 1 line
2.49.0
Matti Vaittinen
maintainerPATCH 4/5 iio: bd79703: Support BD79700 and BD79701
In reply to Matti VaittinenThe BD79700 and BD79701 look like almost exact subsets of the BD79703. The BD79703 contains 6 channels (channels 0 to 5). The BD79700 provides only 2 channels, matching the BD79703 channels 0 and 1. The BD79701 provides 3 channels (matching BD79703 channels 0, 1, and 2).
Furthermore, the BD79700 and BD79701 do not have separate VFS pin but use VCC for the full-scale voltage.
Suopport these ICs using the BD79703 driver.
--- drivers/iio/dac/rohm-bd79703.c | 57 +++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-)
drivers/iio/dac/rohm-bd79703.c +49 -8
@@ -49,6 +49,7 @@ struct bd7970x_chip_data {const char *name;const struct iio_chan_spec *channels;int num_channels; +bool has_vfs; }; static int bd79703_read_raw(struct iio_dev *idev,
@@ -93,6 +94,17 @@ static const struct iio_info bd79703_info = { .address = (_chan + 1), \ } +static const struct iio_chan_spec bd79700_channels[] = { +BD79703_CHAN (0 ), +BD79703_CHAN (1 ), +}; + +static const struct iio_chan_spec bd79701_channels[] = { +BD79703_CHAN (0 ), +BD79703_CHAN (1 ), +BD79703_CHAN (2 ), +}; +static const struct iio_chan_spec bd79703_channels[] = {BD79703_CHAN (0 ),BD79703_CHAN (1 ),
@@ -102,10 +114,25 @@ static const struct iio_chan_spec bd79703_channels[] = { BD79703_CHAN(5), }; +static const struct bd7970x_chip_data bd79700_chip_data = { + .name ="bd79700" , + .channels = bd79700_channels, + .num_channels =ARRAY_SIZE (bd79700_channels), + .has_vfs = false, +}; + +static const struct bd7970x_chip_data bd79701_chip_data = { + .name ="bd79701" , + .channels = bd79701_channels, + .num_channels =ARRAY_SIZE (bd79701_channels), + .has_vfs = false, +}; +static const struct bd7970x_chip_data bd79703_chip_data = { .name ="bd79703" , .channels = bd79703_channels, .num_channels =ARRAY_SIZE (bd79703_channels), + .has_vfs = true, };static int bd79703_probe (struct spi_device *spi)
@@ -131,15 +158,25 @@ static int bd79703_probe(struct spi_device *spi)return dev_err_probe (dev,PTR_ERR (data->regmap),"Failed to initialize Regmap\n" ); - ret =devm_regulator_get_enable (dev,"vcc" ); -if (ret) -return dev_err_probe (dev, ret,"Failed to enable VCC\n" ); - - ret =devm_regulator_get_enable_read_voltage (dev,"vfs" ); -if (ret <0 ) -return dev_err_probe (dev, ret,"Failed to get Vfs\n" ); - +/* +* BD79703 has a separate VFS pin, whereas the BD79700 and BD79701 use +* VCC for their full-scale output voltage. +*/ +if (cd->has_vfs) { + ret =devm_regulator_get_enable (dev,"vcc" ); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable VCC\n" ); + + ret =devm_regulator_get_enable_read_voltage (dev,"vfs" ); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to get Vfs\n" ); + }else { + ret =devm_regulator_get_enable_read_voltage (dev,"vcc" ); +if (ret <0 ) +return dev_err_probe (dev, ret,"Failed to get VCC\n" ); + } data->vfs = ret; + idev->channels = cd->channels; idev->num_channels = cd->num_channels; idev->modes =INDIO_DIRECT_MODE ;
@@ -155,12 +192,16 @@ static int bd79703_probe(struct spi_device *spi) }static const struct spi_device_id bd79703_id[] = { + {"bd79700" , (kernel_ulong_t)&bd79700_chip_data }, + {"bd79701" , (kernel_ulong_t)&bd79701_chip_data }, {"bd79703" , (kernel_ulong_t)&bd79703_chip_data }, { } };MODULE_DEVICE_TABLE (spi, bd79703_id);static const struct of_device_id bd79703_of_match[] = { + { .compatible ="rohm,bd79700" , .data = &bd79700_chip_data }, + { .compatible ="rohm,bd79701" , .data = &bd79701_chip_data }, { .compatible ="rohm,bd79703" , .data = &bd79703_chip_data }, { } };
Signature · 1 line
2.49.0
Matti Vaittinen
maintainerPATCH 5/5 iio: dac: bd79703: Support ROHM BD79702
In reply to Matti VaittinenThe ROHM BD79702 is similar to the BD79703, except that it has only 4 channels whereas BD79703 has 6 channels. The channel 'addresses' of the first two channels (used to identify the channel when data is read over SPI) are same for both ICs. The next two channels of the BD79702 have same addresses as the last two channels of the BD79703. This means the BD79702 channel addresses do not follow the channel numbers with a constant offset. Thus, we need to specify the addresses separately, instead of directly deriving them from the channel number with a constant offset.
It's worth noting that the data-sheet describes the BD79702 as a device having channels 1,2,5 and 6. The driver however represents channels 0,1,2,3 to the users - with no gaps in the numbering - which may be more familiar view for the application software.
Support ROHM BD79702 DAC.
--- drivers/iio/dac/rohm-bd79703.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/iio/dac/rohm-bd79703.c +26 -2
@@ -84,16 +84,18 @@ static const struct iio_info bd79703_info = { .write_raw = bd79703_write_raw, }; -#define BD79703_CHAN (_chan) { \ +#define BD79703_CHAN_ADDR (_chan, _addr) { \ .type = IIO_VOLTAGE, \ .indexed = 1, \ .output = 1, \ .channel = (_chan), \ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \ - .address = (_chan + 1), \ + .address = (_addr), \ } +#define BD79703_CHAN (_chan) BD79703_CHAN_ADDR((_chan), (_chan) + 1) +static const struct iio_chan_spec bd79700_channels[] = {BD79703_CHAN (0 ),BD79703_CHAN (1 ),
@@ -105,6 +107,19 @@ static const struct iio_chan_spec bd79701_channels[] = { BD79703_CHAN(2), }; +/* +* The BD79702 has 4 channels. They aren't mapped to BD79703 channels 0, 1, 2 +* and 3, but to the channels 0, 1, 4, 5. So the addressing used with SPI +* accesses is 1, 2, 5 and 6 for them. Thus, they're not constant offset to +* the channel number as with other IC variants. +*/ +static const struct iio_chan_spec bd79702_channels[] = { +BD79703_CHAN_ADDR (0 ,1 ), +BD79703_CHAN_ADDR (1 ,2 ), +BD79703_CHAN_ADDR (2 ,5 ), +BD79703_CHAN_ADDR (3 ,6 ), +}; +static const struct iio_chan_spec bd79703_channels[] = {BD79703_CHAN (0 ),BD79703_CHAN (1 ),
@@ -128,6 +143,13 @@ static const struct bd7970x_chip_data bd79701_chip_data = { .has_vfs = false, }; +static const struct bd7970x_chip_data bd79702_chip_data = { + .name ="bd79702" , + .channels = bd79702_channels, + .num_channels =ARRAY_SIZE (bd79702_channels), + .has_vfs = true, +}; +static const struct bd7970x_chip_data bd79703_chip_data = { .name ="bd79703" , .channels = bd79703_channels,
@@ -194,6 +216,7 @@ static int bd79703_probe(struct spi_device *spi)static const struct spi_device_id bd79703_id[] = { {"bd79700" , (kernel_ulong_t)&bd79700_chip_data }, {"bd79701" , (kernel_ulong_t)&bd79701_chip_data }, + {"bd79702" , (kernel_ulong_t)&bd79702_chip_data }, {"bd79703" , (kernel_ulong_t)&bd79703_chip_data }, { } };
@@ -202,6 +225,7 @@ MODULE_DEVICE_TABLE(spi, bd79703_id);static const struct of_device_id bd79703_of_match[] = { { .compatible ="rohm,bd79700" , .data = &bd79700_chip_data }, { .compatible ="rohm,bd79701" , .data = &bd79701_chip_data }, + { .compatible ="rohm,bd79702" , .data = &bd79702_chip_data }, { .compatible ="rohm,bd79703" , .data = &bd79703_chip_data }, { } };
Signature · 1 line
2.49.0
Jonathan Cameron
maintainerQuoted 4 lines · On Wed, 2 Apr 2025 09:44:20 +0300 Matti Vaittinen <[email protected]>…
Support ROHM BD797xx DACs
ROHM BD79700, BD79701 and BD79702 are very similar to the already sipported BD79703. Main difference is the reduced number of channels.
supported.
Quoted 3 lines
Also, the *00 and *01 variants lack of the separate Vfs pin.
This series adds support for the BD79700, BD79701 and BD79702.
Series was nearly perfect but I tweaked one thing...
Quoted 9 lines
---
Matti Vaittinen (5):
dt-bindings: Add ROHM BD7970x variants
iio: dac: bd79703 Store device address to 'address'
dac: bd79703: Add chip data
iio: bd79703: Support BD79700 and BD79701
iio: dac: bd79703: Support ROHM BD79702
Made the last 4 patch titles all start with
iio: dac: bd79703:
rather than this random mixture of prefixes.
Applied to the testing branch of iio.git which will get rebase on rc1 sometime in next few days.
Thanks,
Jonathan
Quoted 7 lines
.../bindings/iio/dac/rohm,bd79703.yaml | 33 +++-- drivers/iio/dac/rohm-bd79703.c | 116 +++++++++++++++--- 2 files changed, 126 insertions(+), 23 deletions(-)base-commit:
543da6252b48bbfe13e194fb980bdd2b161f6838
Matti Vaittinen
maintainerQuoted 22 lines · Jonathan Cameron
Quoted 4 lines · On Wed, 2 Apr 2025 09:44:20 +0300 Matti Vaittinen <[email protected]>…
Support ROHM BD797xx DACs
ROHM BD79700, BD79701 and BD79702 are very similar to the already sipported BD79703. Main difference is the reduced number of channels.
supported.
Quoted 3 lines
Also, the *00 and *01 variants lack of the separate Vfs pin.
This series adds support for the BD79700, BD79701 and BD79702.
Series was nearly perfect but I tweaked one thing...
Quoted 9 lines
---
Matti Vaittinen (5):
dt-bindings: Add ROHM BD7970x variants iio: dac: bd79703 Store device address to 'address' dac: bd79703: Add chip data iio: bd79703: Support BD79700 and BD79701 iio: dac: bd79703: Support ROHM BD79702
Quoted 3 lines
Made the last 4 patch titles all start with
iio: dac: bd79703:
rather than this random mixture of prefixes.
Oh! Thanks! "iio: dac:" is obviously the right prefix for all of them!
Quoted 2 lines
Applied to the testing branch of iio.git which will get rebase on rc1 sometime in next few days.
Yours,
-- Matti