Skip to content

Commit

Permalink
iio: accel: bma400: Add separate channel for step counter
Browse files Browse the repository at this point in the history
Added channel for step counter which can be enable or disable
through the sysfs interface.

Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com>
  • Loading branch information
embeddeddiaries authored and intel-lab-lkp committed Mar 19, 2022
1 parent 8dc9a46 commit 3b579e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
1 change: 1 addition & 0 deletions drivers/iio/accel/bma400.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 43 additions & 4 deletions drivers/iio/accel/bma400_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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),
};

Expand Down Expand Up @@ -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;
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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 3b579e3

Please sign in to comment.