iio: accel: bma400: Add separate channel for step counter
Added channel for step counter which can be enable or disable through the sysfs interface. Signed-off-by: Jagath Jog J <jagathjog1996@gmail.com> Link: https://lore.kernel.org/r/20220505133021.22362-6-jagathjog1996@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
ffe0ab6a96
commit
d221de60ee
2 changed files with 67 additions and 4 deletions
|
@ -53,6 +53,8 @@
|
||||||
#define BMA400_STEP_CNT1_REG 0x16
|
#define BMA400_STEP_CNT1_REG 0x16
|
||||||
#define BMA400_STEP_CNT3_REG 0x17
|
#define BMA400_STEP_CNT3_REG 0x17
|
||||||
#define BMA400_STEP_STAT_REG 0x18
|
#define BMA400_STEP_STAT_REG 0x18
|
||||||
|
#define BMA400_STEP_INT_MSK BIT(0)
|
||||||
|
#define BMA400_STEP_RAW_LEN 0x03
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read-write configuration registers
|
* Read-write configuration registers
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
#include <linux/regulator/consumer.h>
|
#include <linux/regulator/consumer.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
|
||||||
|
#include <asm/unaligned.h>
|
||||||
|
|
||||||
#include <linux/iio/iio.h>
|
#include <linux/iio/iio.h>
|
||||||
#include <linux/iio/buffer.h>
|
#include <linux/iio/buffer.h>
|
||||||
|
@ -74,6 +77,7 @@ struct bma400_data {
|
||||||
int oversampling_ratio;
|
int oversampling_ratio;
|
||||||
int scale;
|
int scale;
|
||||||
struct iio_trigger *trig;
|
struct iio_trigger *trig;
|
||||||
|
int steps_enabled;
|
||||||
/* Correct time stamp alignment */
|
/* Correct time stamp alignment */
|
||||||
struct {
|
struct {
|
||||||
__le16 buff[3];
|
__le16 buff[3];
|
||||||
|
@ -209,6 +213,12 @@ static const struct iio_chan_spec bma400_channels[] = {
|
||||||
.endianness = IIO_LE,
|
.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),
|
IIO_CHAN_SOFT_TIMESTAMP(4),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -577,6 +587,40 @@ static int bma400_set_power_mode(struct bma400_data *data,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int bma400_enable_steps(struct bma400_data *data, int val)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (data->steps_enabled == val)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ret = regmap_update_bits(data->regmap, BMA400_INT_CONFIG1_REG,
|
||||||
|
BMA400_STEP_INT_MSK,
|
||||||
|
FIELD_PREP(BMA400_STEP_INT_MSK, val ? 1 : 0));
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
data->steps_enabled = val;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bma400_get_steps_reg(struct bma400_data *data, int *val)
|
||||||
|
{
|
||||||
|
u8 *steps_raw;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
steps_raw = kmalloc(BMA400_STEP_RAW_LEN, GFP_KERNEL);
|
||||||
|
if (!steps_raw)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
ret = regmap_bulk_read(data->regmap, BMA400_STEP_CNT0_REG,
|
||||||
|
steps_raw, BMA400_STEP_RAW_LEN);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
*val = get_unaligned_le24(steps_raw);
|
||||||
|
kfree(steps_raw);
|
||||||
|
return IIO_VAL_INT;
|
||||||
|
}
|
||||||
|
|
||||||
static void bma400_init_tables(void)
|
static void bma400_init_tables(void)
|
||||||
{
|
{
|
||||||
int raw;
|
int raw;
|
||||||
|
@ -716,10 +760,17 @@ static int bma400_read_raw(struct iio_dev *indio_dev,
|
||||||
|
|
||||||
switch (mask) {
|
switch (mask) {
|
||||||
case IIO_CHAN_INFO_PROCESSED:
|
case IIO_CHAN_INFO_PROCESSED:
|
||||||
mutex_lock(&data->mutex);
|
switch (chan->type) {
|
||||||
ret = bma400_get_temp_reg(data, val, val2);
|
case IIO_TEMP:
|
||||||
mutex_unlock(&data->mutex);
|
mutex_lock(&data->mutex);
|
||||||
return ret;
|
ret = bma400_get_temp_reg(data, val, val2);
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
|
return ret;
|
||||||
|
case IIO_STEPS:
|
||||||
|
return bma400_get_steps_reg(data, val);
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
case IIO_CHAN_INFO_RAW:
|
case IIO_CHAN_INFO_RAW:
|
||||||
mutex_lock(&data->mutex);
|
mutex_lock(&data->mutex);
|
||||||
ret = bma400_get_accel_reg(data, chan, val);
|
ret = bma400_get_accel_reg(data, chan, val);
|
||||||
|
@ -760,6 +811,9 @@ static int bma400_read_raw(struct iio_dev *indio_dev,
|
||||||
|
|
||||||
*val = data->oversampling_ratio;
|
*val = data->oversampling_ratio;
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
case IIO_CHAN_INFO_ENABLE:
|
||||||
|
*val = data->steps_enabled;
|
||||||
|
return IIO_VAL_INT;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -825,6 +879,11 @@ static int bma400_write_raw(struct iio_dev *indio_dev,
|
||||||
ret = bma400_set_accel_oversampling_ratio(data, val);
|
ret = bma400_set_accel_oversampling_ratio(data, val);
|
||||||
mutex_unlock(&data->mutex);
|
mutex_unlock(&data->mutex);
|
||||||
return ret;
|
return ret;
|
||||||
|
case IIO_CHAN_INFO_ENABLE:
|
||||||
|
mutex_lock(&data->mutex);
|
||||||
|
ret = bma400_enable_steps(data, val);
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
|
return ret;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -841,6 +900,8 @@ static int bma400_write_raw_get_fmt(struct iio_dev *indio_dev,
|
||||||
return IIO_VAL_INT_PLUS_MICRO;
|
return IIO_VAL_INT_PLUS_MICRO;
|
||||||
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
|
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
|
||||||
return IIO_VAL_INT;
|
return IIO_VAL_INT;
|
||||||
|
case IIO_CHAN_INFO_ENABLE:
|
||||||
|
return IIO_VAL_INT;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue