From: Matti Vaittinen <matti.vaittinen@linux.dev>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
Matti Vaittinen <matti.vaittinen@linux.dev>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"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>,
"Matti Vaittinen" <mazziesaccount@gmail.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] bd79703: Support ROHM BD7971x DACs
Date: Wed, 2 Dec 2026 15:39:21 +0200 [thread overview]
Message-ID: <dad8730304665b9a8bed56c3b7b5eaf3d58c78fb.1796049052.git.mazziesaccount@gmail.com> (raw)
In-Reply-To: <cover.1796049052.git.mazziesaccount@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 7192 bytes --]
From: Matti Vaittinen <mazziesaccount@gmail.com>
The BD7971x are logically similar to BD7970x. Main difference is the
amount of bits in DAC-word. The BD7970x had 8-bit DAC whereas the
BD7971x use 10-bit DAC word.
The SPI data format differs. The BD7971x requires two least significant
bits to be zeroes, and carries the DAC word in following 10 bits. The
channel number is in highest 4 bits.
Add support for the BD7971x family of DACs.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
drivers/iio/dac/rohm-bd79703.c | 91 ++++++++++++++++++++++++++++++++--
1 file changed, 87 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/dac/rohm-bd79703.c b/drivers/iio/dac/rohm-bd79703.c
index b6508e1e1c4f..32f283714852 100644
--- a/drivers/iio/dac/rohm-bd79703.c
+++ b/drivers/iio/dac/rohm-bd79703.c
@@ -17,6 +17,8 @@
#define BD79703_DAC_BITS 8
#define BD79703_REG_OUT_ALL GENMASK(2, 0)
+#define BD7971X_DAC_BITS 10
+
/*
* The BD79703 uses 12-bit SPI commands. First four bits (high bits) define
* channel(s) which are operated on, and also the mode. The mode can be to set
@@ -38,11 +40,27 @@ static const struct regmap_config bd79703_regmap_config = {
.cache_type = REGCACHE_MAPLE,
};
+/* The BD7971X uses 16-bit data transfers. Four high bits define the channel
+ * and following 10 bits define the DAC word. Two last bits must be zero.
+ *
+ * Let's try having the 4 channel-bits as an address and following bits as data
+ */
+static const struct regmap_config bd7971x_regmap_config = {
+ .reg_bits = 4,
+ .val_bits = 12,
+ .max_register = BD79703_MAX_REGISTER,
+ .cache_type = REGCACHE_MAPLE,
+};
+
/* Static, IC type specific data for different variants */
struct bd7970x_chip_data {
const char *name;
+ const struct regmap_config *regmap_conf;
const struct iio_chan_spec *channels;
int num_channels;
+ unsigned int num_bits;
+ unsigned int l_shift; /* BD7971x have DAC word shifted by 2 */
+
/*
* Some ICs use VFS-pin for full-scale voltage for first N channels.
* We need to know these channels to get correct scale
@@ -72,7 +90,7 @@ static int bd79703_read_raw(struct iio_dev *idev,
else
*val = data->vcc_mv;
- *val2 = BD79703_DAC_BITS;
+ *val2 = data->cd->num_bits;
return IIO_VAL_FRACTIONAL_LOG2;
}
@@ -82,14 +100,17 @@ static int bd79703_write_raw(struct iio_dev *idev,
int val2, long mask)
{
struct bd79703_data *data = iio_priv(idev);
+ unsigned int tmp = val;
if (mask != IIO_CHAN_INFO_RAW)
return -EINVAL;
- if (val < 0 || val >= 1 << BD79703_DAC_BITS)
+ if (tmp >= 1 << data->cd->num_bits)
return -EINVAL;
- return regmap_write(data->regmap, chan->address, val);
+ tmp <<= data->cd->l_shift;
+
+ return regmap_write(data->regmap, chan->address, tmp);
};
static const struct iio_info bd79703_info = {
@@ -156,30 +177,84 @@ static const struct iio_chan_spec bd79703_channels[] = {
static const struct bd7970x_chip_data bd79700_chip_data = {
.name = "bd79700",
+ .regmap_conf = &bd79703_regmap_config,
.channels = bd79700_channels,
.num_channels = ARRAY_SIZE(bd79700_channels),
.num_vfs_chan = 0,
+ .num_bits = BD79703_DAC_BITS,
};
static const struct bd7970x_chip_data bd79701_chip_data = {
.name = "bd79701",
+ .regmap_conf = &bd79703_regmap_config,
.channels = bd79701_channels,
.num_channels = ARRAY_SIZE(bd79701_channels),
.num_vfs_chan = 0,
+ .num_bits = BD79703_DAC_BITS,
};
static const struct bd7970x_chip_data bd79702_chip_data = {
.name = "bd79702",
+ .regmap_conf = &bd79703_regmap_config,
.channels = bd79702_channels,
.num_channels = ARRAY_SIZE(bd79702_channels),
.num_vfs_chan = 2,
+ .num_bits = BD79703_DAC_BITS,
};
static const struct bd7970x_chip_data bd79703_chip_data = {
.name = "bd79703",
+ .regmap_conf = &bd79703_regmap_config,
+ .channels = bd79703_channels,
+ .num_channels = ARRAY_SIZE(bd79703_channels),
+ .num_vfs_chan = 3,
+ .num_bits = BD79703_DAC_BITS,
+};
+
+/*
+ * The BD7971[0,3] have same amount of channels as BD7970[0,3]. Also the SPI
+ * command number for 'set DAC and output fir channel N' is same, although
+ * bits where the value is placed differ. We can still use the same channel
+ * config and only provide a different regmap config.
+ */
+static const struct bd7970x_chip_data bd79710_chip_data = {
+ .name = "bd79710",
+ .regmap_conf = &bd7971x_regmap_config,
+ .channels = bd79700_channels,
+ .num_channels = ARRAY_SIZE(bd79700_channels),
+ .num_vfs_chan = 0,
+ .num_bits = BD7971X_DAC_BITS,
+ .l_shift = 2,
+};
+
+static const struct bd7970x_chip_data bd79711_chip_data = {
+ .name = "bd79711",
+ .regmap_conf = &bd7971x_regmap_config,
+ .channels = bd79701_channels,
+ .num_channels = ARRAY_SIZE(bd79701_channels),
+ .num_vfs_chan = 0,
+ .num_bits = BD7971X_DAC_BITS,
+ .l_shift = 2,
+};
+
+static const struct bd7970x_chip_data bd79712_chip_data = {
+ .name = "bd79712",
+ .regmap_conf = &bd7971x_regmap_config,
+ .channels = bd79702_channels,
+ .num_channels = ARRAY_SIZE(bd79702_channels),
+ .num_vfs_chan = 2,
+ .num_bits = BD7971X_DAC_BITS,
+ .l_shift = 2,
+};
+
+static const struct bd7970x_chip_data bd79713_chip_data = {
+ .name = "bd79713",
+ .regmap_conf = &bd7971x_regmap_config,
.channels = bd79703_channels,
.num_channels = ARRAY_SIZE(bd79703_channels),
.num_vfs_chan = 3,
+ .num_bits = BD7971X_DAC_BITS,
+ .l_shift = 2,
};
static int bd79703_probe(struct spi_device *spi)
@@ -200,7 +275,7 @@ static int bd79703_probe(struct spi_device *spi)
data = iio_priv(idev);
- data->regmap = devm_regmap_init_spi(spi, &bd79703_regmap_config);
+ data->regmap = devm_regmap_init_spi(spi, cd->regmap_conf);
if (IS_ERR(data->regmap))
return dev_err_probe(dev, PTR_ERR(data->regmap),
"Failed to initialize Regmap\n");
@@ -247,6 +322,10 @@ static const struct spi_device_id bd79703_id[] = {
{ .name = "bd79701", .driver_data = (kernel_ulong_t)&bd79701_chip_data },
{ .name = "bd79702", .driver_data = (kernel_ulong_t)&bd79702_chip_data },
{ .name = "bd79703", .driver_data = (kernel_ulong_t)&bd79703_chip_data },
+ { .name = "bd79710", .driver_data = (kernel_ulong_t)&bd79710_chip_data },
+ { .name = "bd79711", .driver_data = (kernel_ulong_t)&bd79711_chip_data },
+ { .name = "bd79712", .driver_data = (kernel_ulong_t)&bd79712_chip_data },
+ { .name = "bd79713", .driver_data = (kernel_ulong_t)&bd79713_chip_data },
{ }
};
MODULE_DEVICE_TABLE(spi, bd79703_id);
@@ -256,6 +335,10 @@ static const struct of_device_id bd79703_of_match[] = {
{ .compatible = "rohm,bd79701", .data = &bd79701_chip_data },
{ .compatible = "rohm,bd79702", .data = &bd79702_chip_data },
{ .compatible = "rohm,bd79703", .data = &bd79703_chip_data },
+ { .compatible = "rohm,bd79710", .data = &bd79710_chip_data },
+ { .compatible = "rohm,bd79711", .data = &bd79711_chip_data },
+ { .compatible = "rohm,bd79712", .data = &bd79712_chip_data },
+ { .compatible = "rohm,bd79713", .data = &bd79713_chip_data },
{ }
};
MODULE_DEVICE_TABLE(of, bd79703_of_match);
--
2.56.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2026-12-02 13:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:38 [PATCH 0/4] Support ROHM BD7971x family of DACs Matti Vaittinen
2026-12-02 13:38 ` [PATCH 1/4] dt-bindings: iio: bd79703: Fix VFS explanation Matti Vaittinen
2026-12-02 13:38 ` [PATCH 2/4] dt-bindings: iio: dac: Add ROHM BD7971x Matti Vaittinen
2026-12-02 13:39 ` [PATCH 3/4] iio: dac: rohm-bd79703: Avoid copying chip-data Matti Vaittinen
2026-12-02 13:39 ` Matti Vaittinen [this message]
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=dad8730304665b9a8bed56c3b7b5eaf3d58c78fb.1796049052.git.mazziesaccount@gmail.com \
--to=matti.vaittinen@linux.dev \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=mazziesaccount@gmail.com \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
/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
all inboxes | Powered by JetHome®