[PATCH 3/4] iio: dac: rohm-bd79703: Avoid copying chip-data
From: Matti Vaittinen
Date: Wed Dec 02 2026 - 08:39:22 EST
From: Matti Vaittinen <mazziesaccount@xxxxxxxxx>
The bd79703 driver data has been divided into a static, chip specific
data, and to an instance specific data, which can be modified at run-time.
At the moment, only the instance-specific data is usable after probe,
and only chip-type dependent constant 'num_vfs_chan', is copied to
instance-specific struct.
Upcoming support for bd7971x family of chips will introduce a need to
use a few more chip-specific static values at runtime. Copying them to
dynamic private data struct would get wasteful.
Save some bytes and minimize data copying by storing a pointer to the
constant, chip-type specific data, instead of copying all the values into
the instance specific data.
Signed-off-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>
---
drivers/iio/dac/rohm-bd79703.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/dac/rohm-bd79703.c b/drivers/iio/dac/rohm-bd79703.c
index 1d58bc1544a1..b6508e1e1c4f 100644
--- a/drivers/iio/dac/rohm-bd79703.c
+++ b/drivers/iio/dac/rohm-bd79703.c
@@ -38,14 +38,6 @@ static const struct regmap_config bd79703_regmap_config = {
.cache_type = REGCACHE_MAPLE,
};
-/* Dynamic driver private data */
-struct bd79703_data {
- struct regmap *regmap;
- int vcc_mv;
- int vfs_mv;
- unsigned int num_vfs_chan;
-};
-
/* Static, IC type specific data for different variants */
struct bd7970x_chip_data {
const char *name;
@@ -58,6 +50,14 @@ struct bd7970x_chip_data {
unsigned int num_vfs_chan;
};
+/* Dynamic driver private data */
+struct bd79703_data {
+ struct regmap *regmap;
+ const struct bd7970x_chip_data *cd;
+ int vcc_mv;
+ int vfs_mv;
+};
+
static int bd79703_read_raw(struct iio_dev *idev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
@@ -67,7 +67,7 @@ static int bd79703_read_raw(struct iio_dev *idev,
if (mask != IIO_CHAN_INFO_SCALE)
return -EINVAL;
- if (data->num_vfs_chan > chan->channel)
+ if (data->cd->num_vfs_chan > chan->channel)
*val = data->vfs_mv;
else
*val = data->vcc_mv;
@@ -224,9 +224,10 @@ static int bd79703_probe(struct spi_device *spi)
return dev_err_probe(dev, ret, "Failed to get Vfs\n");
data->vfs_mv = ret / 1000;
- data->num_vfs_chan = cd->num_vfs_chan;
}
+ data->cd = cd;
+
idev->channels = cd->channels;
idev->num_channels = cd->num_channels;
idev->modes = INDIO_DIRECT_MODE;
--
2.56.1
Attachment:
signature.asc
Description: PGP signature