All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Jagath Jog J <jagathjog1996@gmail.com>
Cc: dan@dlrobertson.com, andy.shevchenko@gmail.com,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 4/5] iio: accel: bma400: Add separate channel for step counter
Date: Sun, 20 Mar 2022 17:30:21 +0000	[thread overview]
Message-ID: <20220320173021.220ee3c6@jic23-huawei> (raw)
In-Reply-To: <20220319181023.8090-5-jagathjog1996@gmail.com>

On Sat, 19 Mar 2022 23:40:22 +0530
Jagath Jog J <jagathjog1996@gmail.com> wrote:

> Added channel for step counter which can be enable or disable
> through the sysfs interface.
> 
> Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
hi Jagath,

Been a long time since we had a steps counter. Good to have 
support on another device.

One minor thing inline, but otherwise looks good to me.

Jonathan

> ---
>  drivers/iio/accel/bma400.h      |  1 +
>  drivers/iio/accel/bma400_core.c | 47 ++++++++++++++++++++++++++++++---
>  2 files changed, 44 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/accel/bma400.h b/drivers/iio/accel/bma400.h
> index b306a5ad513a..65bbc80cbb7f 100644
> --- a/drivers/iio/accel/bma400.h
> +++ b/drivers/iio/accel/bma400.h
> @@ -53,6 +53,7 @@
>  #define BMA400_STEP_CNT1_REG        0x16
>  #define BMA400_STEP_CNT3_REG        0x17
>  #define BMA400_STEP_STAT_REG        0x18
> +#define BMA400_STEP_INT_MSK         BIT(0)
>  
>  /*
>   * Read-write configuration registers
> diff --git a/drivers/iio/accel/bma400_core.c b/drivers/iio/accel/bma400_core.c
> index 797403c7dd85..305643e99eb5 100644
> --- a/drivers/iio/accel/bma400_core.c
> +++ b/drivers/iio/accel/bma400_core.c
> @@ -68,6 +68,7 @@ struct bma400_data {
>  	int oversampling_ratio;
>  	int scale;
>  	struct iio_trigger *trig;
> +	int steps_enabled;
>  	/* Correct time stamp alignment */
>  	struct {
>  		__be16 buff[3];
> @@ -202,6 +203,13 @@ static const struct iio_chan_spec bma400_channels[] = {
>  			.endianness = IIO_LE,
>  		},
>  	},
> +	{
> +		.type = IIO_STEPS,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
> +				      BIT(IIO_CHAN_INFO_ENABLE),
> +		.scan_index = -1, /* No buffer support */
> +	},
> +
>  	IIO_CHAN_SOFT_TIMESTAMP(4),
>  };
>  
> @@ -686,13 +694,28 @@ static int bma400_read_raw(struct iio_dev *indio_dev,
>  {
>  	struct bma400_data *data = iio_priv(indio_dev);
>  	int ret;
> +	u32 steps_raw;
>  
>  	switch (mask) {
>  	case IIO_CHAN_INFO_PROCESSED:
> -		mutex_lock(&data->mutex);
> -		ret = bma400_get_temp_reg(data, val, val2);
> -		mutex_unlock(&data->mutex);
> -		return ret;
> +		switch (chan->type) {
> +		case IIO_STEPS:
> +			mutex_lock(&data->mutex);
> +			ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG,
> +					       &steps_raw, 3 * sizeof(u8));
> +			mutex_unlock(&data->mutex);
> +			if (ret)
> +				return ret;
> +			*val = steps_raw & 0x00FFFFFF;

No need for an endian conversion in here?  I'd also intialize steps_raw = 0 before
the bulk read then you shouldn't need to mask as you only read 3 bytes in.

> +			return IIO_VAL_INT;
> +		case IIO_TEMP:
> +			mutex_lock(&data->mutex);
> +			ret = bma400_get_temp_reg(data, val, val2);
> +			mutex_unlock(&data->mutex);
> +			return ret;
> +		default:
> +			return -EINVAL;
> +		}
>  	case IIO_CHAN_INFO_RAW:
>  		mutex_lock(&data->mutex);
>  		ret = bma400_get_accel_reg(data, chan, val);
> @@ -733,6 +756,9 @@ static int bma400_read_raw(struct iio_dev *indio_dev,
>  
>  		*val = data->oversampling_ratio;
>  		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_ENABLE:
> +		*val = data->steps_enabled;
> +		return IIO_VAL_INT;
>  	default:
>  		return -EINVAL;
>  	}
> @@ -798,6 +824,17 @@ static int bma400_write_raw(struct iio_dev *indio_dev,
>  		ret = bma400_set_accel_oversampling_ratio(data, val);
>  		mutex_unlock(&data->mutex);
>  		return ret;
> +	case IIO_CHAN_INFO_ENABLE:
> +		if (data->steps_enabled == val)
> +			return 0;
> +
> +		mutex_lock(&data->mutex);
> +		ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG1_REG,
> +					 BMA400_STEP_INT_MSK,
> +					 FIELD_PREP(BMA400_STEP_INT_MSK, !!val));
> +		mutex_unlock(&data->mutex);
> +		data->steps_enabled = val;
> +		return ret;
>  	default:
>  		return -EINVAL;
>  	}
> @@ -814,6 +851,8 @@ static int bma400_write_raw_get_fmt(struct iio_dev *indio_dev,
>  		return IIO_VAL_INT_PLUS_MICRO;
>  	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
>  		return IIO_VAL_INT;
> +	case IIO_CHAN_INFO_ENABLE:
> +		return IIO_VAL_INT;
>  	default:
>  		return -EINVAL;
>  	}


  reply	other threads:[~2022-03-20 17:23 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-19 18:10 [PATCH v1 0/5] iio: accel: bma400: Add support for buffer and step Jagath Jog J
2022-03-19 18:10 ` [PATCH v1 1/5] iio: accel: bma400: conversion to device-managed function Jagath Jog J
2022-03-20 17:14   ` Jonathan Cameron
2022-03-21 21:12     ` Jagath Jog J
2022-03-22 20:41       ` Jonathan Cameron
2022-03-21  8:30   ` Andy Shevchenko
2022-03-21 21:20     ` Jagath Jog J
2022-03-19 18:10 ` [PATCH v1 2/5] iio: accel: bma400: changing scale min and max macro values Jagath Jog J
2022-03-20 17:17   ` Jonathan Cameron
2022-03-19 18:10 ` [PATCH v1 3/5] iio: accel: bma400: Add triggered buffer support Jagath Jog J
2022-03-20  3:30   ` kernel test robot
2022-03-20 17:26   ` Jonathan Cameron
2022-03-21  8:39   ` Andy Shevchenko
2022-03-21 22:21     ` Jagath Jog J
2022-03-22  8:54       ` Andy Shevchenko
2022-03-22 15:40         ` Jagath Jog J
2022-03-22 16:12           ` Andy Shevchenko
2022-03-19 18:10 ` [PATCH v1 4/5] iio: accel: bma400: Add separate channel for step counter Jagath Jog J
2022-03-20 17:30   ` Jonathan Cameron [this message]
2022-03-21  8:42   ` Andy Shevchenko
2022-03-21  8:43   ` Andy Shevchenko
2022-03-19 18:10 ` [PATCH v1 5/5] iio: accel: bma400: Add step change event Jagath Jog J
2022-03-20 17:37   ` Jonathan Cameron
2022-03-21 22:52     ` Jagath Jog J
2022-03-21  8:45   ` Andy Shevchenko
2022-03-20  4:21 [PATCH v1 4/5] iio: accel: bma400: Add separate channel for step counter kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220320173021.220ee3c6@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=dan@dlrobertson.com \
    --cc=jagathjog1996@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.