I would like to know if it is possible to modify the regmap_config parameters, such as the .val_bits field, from user space. I am aware that the regmap_config structure is typically used by kernel drivers to describe the hardware characteristics, but I am wondering if there is any way to modify these parameters at runtime without rebuilding the kernel module. Code snippet below. I was expecting that the user could input its desired val_bits parameter value in user space.
C:
static int my_device_reg_access(struct iio_dev *indio_dev, unsigned int reg,
unsigned int writeval, unsigned int *readval)
{
struct my_device_state *st = iio_priv(indio_dev);
if (readval)
return regmap_read(st->regmap, reg, readval);
else
return regmap_write(st->regmap, reg, writeval);
}
static struct regmap_config my_device_regmap_config = {
.reg_bits = 16,
.val_bits = 16,
.write_flag_mask = BIT(7),
.max_register = 0x7FFF,
};
static const struct iio_info my_device_info = {
.debugfs_reg_access = &my_device_reg_access,
};
static int my_device_probe(struct spi_device *spi)
{
struct my_device_state *st;
struct iio_dev *indio_dev;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
st = iio_priv(indio_dev);
st->spi = spi;
st->regmap = devm_regmap_init_spi(spi, &my_device_regmap_config);
if (IS_ERR(st->regmap))
return PTR_ERR(st->regmap);
indio_dev->name = "my_device";
indio_dev->info = &my_device_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = NULL;
mutex_init(&st->lock);
return devm_iio_device_register(&spi->dev, indio_dev);
}