• We had to restore from a backup today after a failed software update. Backup was from 0000 EDT and restored it at 0800 EDT so we lost about 8hrs. Today is 07/20/2024. More info here.

Can I modify regmap_config parameters, such as the .val_bits of regmap_config, in userspace?

kimedia

New Member
Joined
May 8, 2023
Messages
1
Reaction score
0
Credits
14
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);
}
 

Staff online


Top