diff mbox series

[v2,3/4] iio: light: veml3235: extend regmap to add cache

Message ID 20241224-veml3235_scale-v2-3-2e1286846c77@gmail.com (mailing list archive)
State Accepted
Headers show
Series iio: light: fix scale in veml3235 and add helpers to iio-gts | expand

Commit Message

Javier Carrasco Dec. 24, 2024, 10:59 a.m. UTC
The configuration and ID registers are not volatile and are not affected
by read operations (i.e. not precious), making them suitable to be
cached in order to reduce the number of accesses to the device.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/iio/light/veml3235.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Jonathan Cameron Dec. 28, 2024, 3:43 p.m. UTC | #1
On Tue, 24 Dec 2024 11:59:02 +0100
Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote:

> The configuration and ID registers are not volatile and are not affected
> by read operations (i.e. not precious), making them suitable to be
> cached in order to reduce the number of accesses to the device.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
This is also fine on it's own.

Applied.

> ---
>  drivers/iio/light/veml3235.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/drivers/iio/light/veml3235.c b/drivers/iio/light/veml3235.c
> index fa5c7e7dfbfaec1b96428612b1dcba91ea51603f..f754980ea156a6e128ff159b816e09099197c5c7 100644
> --- a/drivers/iio/light/veml3235.c
> +++ b/drivers/iio/light/veml3235.c
> @@ -101,12 +101,43 @@ static const struct iio_chan_spec veml3235_channels[] = {
>  	},
>  };
>  
> +static const struct regmap_range veml3235_readable_ranges[] = {
> +	regmap_reg_range(VEML3235_REG_CONF, VEML3235_REG_ID),
> +};
> +
> +static const struct regmap_access_table veml3235_readable_table = {
> +	.yes_ranges = veml3235_readable_ranges,
> +	.n_yes_ranges = ARRAY_SIZE(veml3235_readable_ranges),
> +};
> +
> +static const struct regmap_range veml3235_writable_ranges[] = {
> +	regmap_reg_range(VEML3235_REG_CONF, VEML3235_REG_CONF),
> +};
> +
> +static const struct regmap_access_table veml3235_writable_table = {
> +	.yes_ranges = veml3235_writable_ranges,
> +	.n_yes_ranges = ARRAY_SIZE(veml3235_writable_ranges),
> +};
> +
> +static const struct regmap_range veml3235_volatile_ranges[] = {
> +	regmap_reg_range(VEML3235_REG_WH_DATA, VEML3235_REG_ALS_DATA),
> +};
> +
> +static const struct regmap_access_table veml3235_volatile_table = {
> +	.yes_ranges = veml3235_volatile_ranges,
> +	.n_yes_ranges = ARRAY_SIZE(veml3235_volatile_ranges),
> +};
> +
>  static const struct regmap_config veml3235_regmap_config = {
>  	.name = "veml3235_regmap",
>  	.reg_bits = 8,
>  	.val_bits = 16,
>  	.max_register = VEML3235_REG_ID,
>  	.val_format_endian = REGMAP_ENDIAN_LITTLE,
> +	.rd_table = &veml3235_readable_table,
> +	.wr_table = &veml3235_writable_table,
> +	.volatile_table = &veml3235_volatile_table,
> +	.cache_type = REGCACHE_RBTREE,
>  };
>  
>  static int veml3235_get_it(struct veml3235_data *data, int *val, int *val2)
>
diff mbox series

Patch

diff --git a/drivers/iio/light/veml3235.c b/drivers/iio/light/veml3235.c
index fa5c7e7dfbfaec1b96428612b1dcba91ea51603f..f754980ea156a6e128ff159b816e09099197c5c7 100644
--- a/drivers/iio/light/veml3235.c
+++ b/drivers/iio/light/veml3235.c
@@ -101,12 +101,43 @@  static const struct iio_chan_spec veml3235_channels[] = {
 	},
 };
 
+static const struct regmap_range veml3235_readable_ranges[] = {
+	regmap_reg_range(VEML3235_REG_CONF, VEML3235_REG_ID),
+};
+
+static const struct regmap_access_table veml3235_readable_table = {
+	.yes_ranges = veml3235_readable_ranges,
+	.n_yes_ranges = ARRAY_SIZE(veml3235_readable_ranges),
+};
+
+static const struct regmap_range veml3235_writable_ranges[] = {
+	regmap_reg_range(VEML3235_REG_CONF, VEML3235_REG_CONF),
+};
+
+static const struct regmap_access_table veml3235_writable_table = {
+	.yes_ranges = veml3235_writable_ranges,
+	.n_yes_ranges = ARRAY_SIZE(veml3235_writable_ranges),
+};
+
+static const struct regmap_range veml3235_volatile_ranges[] = {
+	regmap_reg_range(VEML3235_REG_WH_DATA, VEML3235_REG_ALS_DATA),
+};
+
+static const struct regmap_access_table veml3235_volatile_table = {
+	.yes_ranges = veml3235_volatile_ranges,
+	.n_yes_ranges = ARRAY_SIZE(veml3235_volatile_ranges),
+};
+
 static const struct regmap_config veml3235_regmap_config = {
 	.name = "veml3235_regmap",
 	.reg_bits = 8,
 	.val_bits = 16,
 	.max_register = VEML3235_REG_ID,
 	.val_format_endian = REGMAP_ENDIAN_LITTLE,
+	.rd_table = &veml3235_readable_table,
+	.wr_table = &veml3235_writable_table,
+	.volatile_table = &veml3235_volatile_table,
+	.cache_type = REGCACHE_RBTREE,
 };
 
 static int veml3235_get_it(struct veml3235_data *data, int *val, int *val2)