On 2/12/25 12:17 PM, Jonathan Santos wrote: > Convert the AD7768-1 driver to use the regmap API for register > access. This change simplifies and standardizes register interactions, > reducing code duplication and improving maintainability. > > Create two regmap configurations, one for 8-bit register values and > other for 24-bit register values. > > Since we are using regmap now, define the remaining registers from 0x32 > to 0x34. > > Signed-off-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx> > --- > v3 Changes: > * Included a second register map for the 24-bit register values. > * Added register tables to separate the 24-bit from the 8-bit values. > > v2 Changes: > * New patch in v2. > --- Should also add a `select REGMAP_SPI` line to the Kconfig for this driver to avoid compile errors for random configs. > drivers/iio/adc/ad7768-1.c | 148 +++++++++++++++++++++++++------------ > 1 file changed, 101 insertions(+), 47 deletions(-) > ... > @@ -260,15 +297,21 @@ static int ad7768_reg_access(struct iio_dev *indio_dev, > return ret; > I think we should set ret = -EINVAL; here, otherwise the ret from above can survive and we return 0 even though no read or write was done if the requested register was not valid. > if (readval) { > - ret = ad7768_spi_reg_read(st, reg, 1); > - if (ret < 0) > - goto err_release; > - *readval = ret; > - ret = 0; > + if (regmap_check_range_table(st->regmap, reg, &ad7768_regmap_rd_table)) > + ret = regmap_read(st->regmap, reg, readval); > + > + if (regmap_check_range_table(st->regmap24, reg, &ad7768_regmap24_rd_table)) > + ret = regmap_read(st->regmap24, reg, readval); > + > } else { > - ret = ad7768_spi_reg_write(st, reg, writeval); > + if (regmap_check_range_table(st->regmap, reg, &ad7768_regmap_wr_table)) > + ret = regmap_write(st->regmap, reg, writeval); > + > + if (regmap_check_range_table(st->regmap24, reg, &ad7768_regmap24_wr_table)) > + ret = regmap_write(st->regmap24, reg, writeval); > + > } > -err_release: > + > iio_device_release_direct_mode(indio_dev); > > return ret;