Commit f8710f03 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: express odr in mHZ

Express available frequencies in mHZ in order to support even
rational ODRs. This patch is need to fix an Android CTS failure
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent fc3f6ad7
...@@ -106,7 +106,7 @@ struct st_lsm6dsx_sensor; ...@@ -106,7 +106,7 @@ struct st_lsm6dsx_sensor;
struct st_lsm6dsx_hw; struct st_lsm6dsx_hw;
struct st_lsm6dsx_odr { struct st_lsm6dsx_odr {
u16 hz; u32 milli_hz;
u8 val; u8 val;
}; };
...@@ -330,7 +330,7 @@ struct st_lsm6dsx_sensor { ...@@ -330,7 +330,7 @@ struct st_lsm6dsx_sensor {
struct st_lsm6dsx_hw *hw; struct st_lsm6dsx_hw *hw;
u32 gain; u32 gain;
u16 odr; u32 odr;
u16 watermark; u16 watermark;
u8 sip; u8 sip;
...@@ -415,7 +415,7 @@ int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw, ...@@ -415,7 +415,7 @@ int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
enum st_lsm6dsx_fifo_mode fifo_mode); enum st_lsm6dsx_fifo_mode fifo_mode);
int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw);
int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw);
int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u16 odr, u8 *val); int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u32 odr, u8 *val);
int st_lsm6dsx_shub_probe(struct st_lsm6dsx_hw *hw, const char *name); int st_lsm6dsx_shub_probe(struct st_lsm6dsx_hw *hw, const char *name);
int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable); int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable);
int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable); int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable);
......
...@@ -91,7 +91,7 @@ static int st_lsm6dsx_get_decimator_val(u8 val) ...@@ -91,7 +91,7 @@ static int st_lsm6dsx_get_decimator_val(u8 val)
} }
static void st_lsm6dsx_get_max_min_odr(struct st_lsm6dsx_hw *hw, static void st_lsm6dsx_get_max_min_odr(struct st_lsm6dsx_hw *hw,
u16 *max_odr, u16 *min_odr) u32 *max_odr, u32 *min_odr)
{ {
struct st_lsm6dsx_sensor *sensor; struct st_lsm6dsx_sensor *sensor;
int i; int i;
...@@ -106,16 +106,17 @@ static void st_lsm6dsx_get_max_min_odr(struct st_lsm6dsx_hw *hw, ...@@ -106,16 +106,17 @@ static void st_lsm6dsx_get_max_min_odr(struct st_lsm6dsx_hw *hw,
if (!(hw->enable_mask & BIT(sensor->id))) if (!(hw->enable_mask & BIT(sensor->id)))
continue; continue;
*max_odr = max_t(u16, *max_odr, sensor->odr); *max_odr = max_t(u32, *max_odr, sensor->odr);
*min_odr = min_t(u16, *min_odr, sensor->odr); *min_odr = min_t(u32, *min_odr, sensor->odr);
} }
} }
static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw) static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
{ {
u16 max_odr, min_odr, sip = 0, ts_sip = 0;
const struct st_lsm6dsx_reg *ts_dec_reg; const struct st_lsm6dsx_reg *ts_dec_reg;
struct st_lsm6dsx_sensor *sensor; struct st_lsm6dsx_sensor *sensor;
u16 sip = 0, ts_sip = 0;
u32 max_odr, min_odr;
int err = 0, i; int err = 0, i;
u8 data; u8 data;
......
...@@ -51,10 +51,10 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = { ...@@ -51,10 +51,10 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
.addr = 0x60, .addr = 0x60,
.mask = GENMASK(3, 2), .mask = GENMASK(3, 2),
}, },
.odr_avl[0] = { 10, 0x0 }, .odr_avl[0] = { 10000, 0x0 },
.odr_avl[1] = { 20, 0x1 }, .odr_avl[1] = { 20000, 0x1 },
.odr_avl[2] = { 50, 0x2 }, .odr_avl[2] = { 50000, 0x2 },
.odr_avl[3] = { 100, 0x3 }, .odr_avl[3] = { 100000, 0x3 },
.odr_len = 4, .odr_len = 4,
}, },
.fs_table = { .fs_table = {
...@@ -94,11 +94,11 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = { ...@@ -94,11 +94,11 @@ static const struct st_lsm6dsx_ext_dev_settings st_lsm6dsx_ext_dev_table[] = {
static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw) static void st_lsm6dsx_shub_wait_complete(struct st_lsm6dsx_hw *hw)
{ {
struct st_lsm6dsx_sensor *sensor; struct st_lsm6dsx_sensor *sensor;
u16 odr; u32 odr;
sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 13; odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 12500;
msleep((2000U / odr) + 1); msleep((2000000U / odr) + 1);
} }
/** /**
...@@ -318,14 +318,14 @@ st_lsm6dsx_shub_write_with_mask(struct st_lsm6dsx_sensor *sensor, ...@@ -318,14 +318,14 @@ st_lsm6dsx_shub_write_with_mask(struct st_lsm6dsx_sensor *sensor,
static int static int
st_lsm6dsx_shub_get_odr_val(struct st_lsm6dsx_sensor *sensor, st_lsm6dsx_shub_get_odr_val(struct st_lsm6dsx_sensor *sensor,
u16 odr, u16 *val) u32 odr, u16 *val)
{ {
const struct st_lsm6dsx_ext_dev_settings *settings; const struct st_lsm6dsx_ext_dev_settings *settings;
int i; int i;
settings = sensor->ext_info.settings; settings = sensor->ext_info.settings;
for (i = 0; i < settings->odr_table.odr_len; i++) { for (i = 0; i < settings->odr_table.odr_len; i++) {
if (settings->odr_table.odr_avl[i].hz == odr) if (settings->odr_table.odr_avl[i].milli_hz == odr)
break; break;
} }
...@@ -337,7 +337,7 @@ st_lsm6dsx_shub_get_odr_val(struct st_lsm6dsx_sensor *sensor, ...@@ -337,7 +337,7 @@ st_lsm6dsx_shub_get_odr_val(struct st_lsm6dsx_sensor *sensor,
} }
static int static int
st_lsm6dsx_shub_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr) st_lsm6dsx_shub_set_odr(struct st_lsm6dsx_sensor *sensor, u32 odr)
{ {
const struct st_lsm6dsx_ext_dev_settings *settings; const struct st_lsm6dsx_ext_dev_settings *settings;
u16 val; u16 val;
...@@ -442,7 +442,7 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor, ...@@ -442,7 +442,7 @@ st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor,
if (err < 0) if (err < 0)
return err; return err;
delay = 1000000 / sensor->odr; delay = 1000000000 / sensor->odr;
usleep_range(delay, 2 * delay); usleep_range(delay, 2 * delay);
len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3); len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3);
...@@ -482,8 +482,9 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev, ...@@ -482,8 +482,9 @@ st_lsm6dsx_shub_read_raw(struct iio_dev *iio_dev,
iio_device_release_direct_mode(iio_dev); iio_device_release_direct_mode(iio_dev);
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
*val = sensor->odr; *val = sensor->odr / 1000;
ret = IIO_VAL_INT; *val2 = (sensor->odr % 1000) * 1000;
ret = IIO_VAL_INT_PLUS_MICRO;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
*val = 0; *val = 0;
...@@ -514,6 +515,7 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev, ...@@ -514,6 +515,7 @@ st_lsm6dsx_shub_write_raw(struct iio_dev *iio_dev,
case IIO_CHAN_INFO_SAMP_FREQ: { case IIO_CHAN_INFO_SAMP_FREQ: {
u16 data; u16 data;
val = val * 1000 + val2 / 1000;
err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data); err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data);
if (!err) if (!err)
sensor->odr = val; sensor->odr = val;
...@@ -540,9 +542,10 @@ st_lsm6dsx_shub_sampling_freq_avail(struct device *dev, ...@@ -540,9 +542,10 @@ st_lsm6dsx_shub_sampling_freq_avail(struct device *dev,
settings = sensor->ext_info.settings; settings = sensor->ext_info.settings;
for (i = 0; i < settings->odr_table.odr_len; i++) { for (i = 0; i < settings->odr_table.odr_len; i++) {
u16 val = settings->odr_table.odr_avl[i].hz; u32 val = settings->odr_table.odr_avl[i].milli_hz;
len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", val); len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%03d ",
val / 1000, val % 1000);
} }
buf[len - 1] = '\n'; buf[len - 1] = '\n';
...@@ -607,7 +610,7 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw, ...@@ -607,7 +610,7 @@ st_lsm6dsx_shub_alloc_iiodev(struct st_lsm6dsx_hw *hw,
sensor = iio_priv(iio_dev); sensor = iio_priv(iio_dev);
sensor->id = id; sensor->id = id;
sensor->hw = hw; sensor->hw = hw;
sensor->odr = info->odr_table.odr_avl[0].hz; sensor->odr = info->odr_table.odr_avl[0].milli_hz;
sensor->gain = info->fs_table.fs_avl[0].gain; sensor->gain = info->fs_table.fs_avl[0].gain;
sensor->ext_info.settings = info; sensor->ext_info.settings = info;
sensor->ext_info.addr = i2c_addr; sensor->ext_info.addr = i2c_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment