iio: dac: bd79703: Support ROHM BD79702

The 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.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://patch.msgid.link/0ba243a63115dd4af03ebf9656c65b8c259a3e34.1743576022.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Matti Vaittinen 2025-04-02 09:46:44 +03:00 committed by Jonathan Cameron
parent 25468dbb81
commit 7a84e33afe

View File

@ -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 },
{ }
};