lkml.org 
[lkml]   [2022]   [May]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 8/9] iio: accel: bma400: Add debugfs register access support
On Thu, 21 Apr 2022 02:41:04 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:

> Add support to read/write byte from/to bma400 device from the userspace
> using debugfs interface.
>
> Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
> ---
> drivers/iio/accel/bma400_core.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c
> index 073fff7d64a3..5b1b28972ef9 100644
> --- a/drivers/iio/accel/bma400_core.c
> +++ b/drivers/iio/accel/bma400_core.c
> @@ -1030,6 +1030,19 @@ static int bma400_write_event_config(struct iio_dev *indio_dev,
> }
> }
>
> +static int bma400_debugfs_reg_access(struct iio_dev *indio_dev,
> + unsigned int reg,
> + unsigned int writeval,
> + unsigned int *readval)
> +{
> + struct bma400_data *data = iio_priv(indio_dev);
> +
> + if (readval)
> + return regmap_read(data->regmap, reg, readval);
> + else
> + return regmap_write(data->regmap, reg, writeval);

Hmm. So normally reads are safe, but not on this device because a read
of the status register has side effects. As such, I'd either block
reading that register or simply not provide debugfs access at all.

Writes are often likely to break things, so users tend to be aware
of that...

Jonathan

> +}
> +
> static int bma400_data_rdy_trigger_set_state(struct iio_trigger *trig,
> bool state)
> {
> @@ -1060,6 +1073,7 @@ static const struct iio_info bma400_info = {
> .write_raw_get_fmt = bma400_write_raw_get_fmt,
> .read_event_config = bma400_read_event_config,
> .write_event_config = bma400_write_event_config,
> + .debugfs_reg_access = bma400_debugfs_reg_access,
> };
>
> static const struct iio_trigger_ops bma400_trigger_ops = {

\
 
 \ /
  Last update: 2022-05-01 18:26    [W:0.241 / U:0.488 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site