2019-08-21 15:02:04

by Martin Kepplinger

[permalink] [raw]
Subject: [PATCH v5 0/4] iio: imu: st_lsm6dsx: Add support for LSM9DS1

Add basic functionality for LSM9DS1. This has become a trivial addition
by now.

revision history
----------------
v5: struct rename and add one patch from Lorenzo in order handle fifo-enable
correctly. thanks.
v4: rebase on top of today's iio testing branch with Lorenzo's recent work
v3: rebase and add Lorenzo's patches in order to apply to the iio testing brach
v2: further simplifications based on Lorenzo's feedback
v1: initial change for adding lsm9ds1 support



Lorenzo Bianconi (1):
iio: imu: st_lsm6dsx: introduce update_fifo function pointer

Martin Kepplinger (3):
iio: imu: st_lsm6sdx: move register definitions to sensor_settings
struct
iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9sd1
dt-bindings: iio: imu: st_lsm6dsx: add lsm9ds1 device bindings

.../bindings/iio/imu/st_lsm6dsx.txt | 1 +
drivers/iio/imu/st_lsm6dsx/Kconfig | 2 +-
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 12 ++
.../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 19 ++-
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 124 ++++++++++++++++--
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c | 5 +
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c | 5 +
7 files changed, 154 insertions(+), 14 deletions(-)

--
2.20.1


2019-08-21 15:30:13

by Martin Kepplinger

[permalink] [raw]
Subject: [PATCH v5 2/4] iio: imu: st_lsm6sdx: move register definitions to sensor_settings struct

Move some register definitions to the per-device array of struct
st_lsm6dsx_sensor_settings in order to simplify adding new sensor
devices to the driver.

Also, remove completely unused register definitions.

Signed-off-by: Martin Kepplinger <[email protected]>
Acked-by: Lorenzo Bianconi <[email protected]>
---
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 6 ++++
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 31 ++++++++++++++------
2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
index 055e52dec36a..090b7bd3c5b0 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -203,6 +203,9 @@ struct st_lsm6dsx_ext_dev_settings {
/**
* struct st_lsm6dsx_settings - ST IMU sensor settings
* @wai: Sensor WhoAmI default value.
+ * @int1_addr: Control Register address for INT1
+ * @int2_addr: Control Register address for INT2
+ * @reset_addr: register address for reset/reboot
* @max_fifo_size: Sensor max fifo length in FIFO words.
* @id: List of hw id/device name supported by the driver configuration.
* @channels: IIO channels supported by the device.
@@ -216,6 +219,9 @@ struct st_lsm6dsx_ext_dev_settings {
*/
struct st_lsm6dsx_settings {
u8 wai;
+ u8 int1_addr;
+ u8 int2_addr;
+ u8 reset_addr;
u16 max_fifo_size;
struct {
enum st_lsm6dsx_hw_id hw_id;
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 0aa93b45d772..1b46d9dc2089 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -49,17 +49,12 @@

#include "st_lsm6dsx.h"

-#define ST_LSM6DSX_REG_INT1_ADDR 0x0d
-#define ST_LSM6DSX_REG_INT2_ADDR 0x0e
#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3)
#define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f
-#define ST_LSM6DSX_REG_RESET_ADDR 0x12
#define ST_LSM6DSX_REG_RESET_MASK BIT(0)
#define ST_LSM6DSX_REG_BOOT_MASK BIT(7)
#define ST_LSM6DSX_REG_BDU_ADDR 0x12
#define ST_LSM6DSX_REG_BDU_MASK BIT(6)
-#define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13
-#define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5)

static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
@@ -78,6 +73,9 @@ static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
{
.wai = 0x69,
+ .int1_addr = 0x0d,
+ .int2_addr = 0x0e,
+ .reset_addr = 0x12,
.max_fifo_size = 1365,
.id = {
{
@@ -187,6 +185,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
},
{
.wai = 0x69,
+ .int1_addr = 0x0d,
+ .int2_addr = 0x0e,
+ .reset_addr = 0x12,
.max_fifo_size = 682,
.id = {
{
@@ -296,6 +297,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
},
{
.wai = 0x6a,
+ .int1_addr = 0x0d,
+ .int2_addr = 0x0e,
+ .reset_addr = 0x12,
.max_fifo_size = 682,
.id = {
{
@@ -414,6 +418,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
},
{
.wai = 0x6c,
+ .int1_addr = 0x0d,
+ .int2_addr = 0x0e,
+ .reset_addr = 0x12,
.max_fifo_size = 512,
.id = {
{
@@ -544,6 +551,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
},
{
.wai = 0x6b,
+ .int1_addr = 0x0d,
+ .int2_addr = 0x0e,
+ .reset_addr = 0x12,
.max_fifo_size = 512,
.id = {
{
@@ -645,6 +655,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
},
{
.wai = 0x6b,
+ .int1_addr = 0x0d,
+ .int2_addr = 0x0e,
+ .reset_addr = 0x12,
.max_fifo_size = 512,
.id = {
{
@@ -1172,10 +1185,10 @@ static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)

switch (drdy_pin) {
case 1:
- *drdy_reg = ST_LSM6DSX_REG_INT1_ADDR;
+ *drdy_reg = hw->settings->int1_addr;
break;
case 2:
- *drdy_reg = ST_LSM6DSX_REG_INT2_ADDR;
+ *drdy_reg = hw->settings->int2_addr;
break;
default:
dev_err(hw->dev, "unsupported data ready pin\n");
@@ -1275,7 +1288,7 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
int err;

/* device sw reset */
- err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR,
+ err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
ST_LSM6DSX_REG_RESET_MASK,
FIELD_PREP(ST_LSM6DSX_REG_RESET_MASK, 1));
if (err < 0)
@@ -1284,7 +1297,7 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
msleep(50);

/* reload trimming parameter */
- err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR,
+ err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
ST_LSM6DSX_REG_BOOT_MASK,
FIELD_PREP(ST_LSM6DSX_REG_BOOT_MASK, 1));
if (err < 0)
--
2.20.1

2019-08-27 06:56:12

by Martin Kepplinger

[permalink] [raw]
Subject: Re: [PATCH v5 2/4] iio: imu: st_lsm6sdx: move register definitions to sensor_settings struct

On 21.08.19 15:25, Martin Kepplinger wrote:
> Move some register definitions to the per-device array of struct
> st_lsm6dsx_sensor_settings in order to simplify adding new sensor
> devices to the driver.
>
> Also, remove completely unused register definitions.
>
> Signed-off-by: Martin Kepplinger <[email protected]>
> Acked-by: Lorenzo Bianconi <[email protected]>
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 6 ++++
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 31 ++++++++++++++------
> 2 files changed, 28 insertions(+), 9 deletions(-)
>

I just notices the commit message header typo "st_lsm6sdx" should be
"st_lsm6dsx" of course. If you can still rebase/force-push to testing,
would you be able to fix that? If it's too far out there already, so be
it :) sorry for the typo, and thanks for adding "-imu" yourself where
applicable.

thanks,

martin

2019-08-27 19:52:56

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v5 2/4] iio: imu: st_lsm6sdx: move register definitions to sensor_settings struct

On Wed, 21 Aug 2019 15:25:18 +0200
Martin Kepplinger <[email protected]> wrote:

> Move some register definitions to the per-device array of struct
> st_lsm6dsx_sensor_settings in order to simplify adding new sensor
> devices to the driver.
>
> Also, remove completely unused register definitions.
>
> Signed-off-by: Martin Kepplinger <[email protected]>
> Acked-by: Lorenzo Bianconi <[email protected]>

Applied to the togreg branch of iio.git and pushed out as
testing for the autobuilders to play with it,

Thanks,

Jonathan

> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 6 ++++
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 31 ++++++++++++++------
> 2 files changed, 28 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 055e52dec36a..090b7bd3c5b0 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -203,6 +203,9 @@ struct st_lsm6dsx_ext_dev_settings {
> /**
> * struct st_lsm6dsx_settings - ST IMU sensor settings
> * @wai: Sensor WhoAmI default value.
> + * @int1_addr: Control Register address for INT1
> + * @int2_addr: Control Register address for INT2
> + * @reset_addr: register address for reset/reboot
> * @max_fifo_size: Sensor max fifo length in FIFO words.
> * @id: List of hw id/device name supported by the driver configuration.
> * @channels: IIO channels supported by the device.
> @@ -216,6 +219,9 @@ struct st_lsm6dsx_ext_dev_settings {
> */
> struct st_lsm6dsx_settings {
> u8 wai;
> + u8 int1_addr;
> + u8 int2_addr;
> + u8 reset_addr;
> u16 max_fifo_size;
> struct {
> enum st_lsm6dsx_hw_id hw_id;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 0aa93b45d772..1b46d9dc2089 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -49,17 +49,12 @@
>
> #include "st_lsm6dsx.h"
>
> -#define ST_LSM6DSX_REG_INT1_ADDR 0x0d
> -#define ST_LSM6DSX_REG_INT2_ADDR 0x0e
> #define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3)
> #define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f
> -#define ST_LSM6DSX_REG_RESET_ADDR 0x12
> #define ST_LSM6DSX_REG_RESET_MASK BIT(0)
> #define ST_LSM6DSX_REG_BOOT_MASK BIT(7)
> #define ST_LSM6DSX_REG_BDU_ADDR 0x12
> #define ST_LSM6DSX_REG_BDU_MASK BIT(6)
> -#define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13
> -#define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5)
>
> static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
> ST_LSM6DSX_CHANNEL(IIO_ACCEL, 0x28, IIO_MOD_X, 0),
> @@ -78,6 +73,9 @@ static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
> static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> {
> .wai = 0x69,
> + .int1_addr = 0x0d,
> + .int2_addr = 0x0e,
> + .reset_addr = 0x12,
> .max_fifo_size = 1365,
> .id = {
> {
> @@ -187,6 +185,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> },
> {
> .wai = 0x69,
> + .int1_addr = 0x0d,
> + .int2_addr = 0x0e,
> + .reset_addr = 0x12,
> .max_fifo_size = 682,
> .id = {
> {
> @@ -296,6 +297,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> },
> {
> .wai = 0x6a,
> + .int1_addr = 0x0d,
> + .int2_addr = 0x0e,
> + .reset_addr = 0x12,
> .max_fifo_size = 682,
> .id = {
> {
> @@ -414,6 +418,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> },
> {
> .wai = 0x6c,
> + .int1_addr = 0x0d,
> + .int2_addr = 0x0e,
> + .reset_addr = 0x12,
> .max_fifo_size = 512,
> .id = {
> {
> @@ -544,6 +551,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> },
> {
> .wai = 0x6b,
> + .int1_addr = 0x0d,
> + .int2_addr = 0x0e,
> + .reset_addr = 0x12,
> .max_fifo_size = 512,
> .id = {
> {
> @@ -645,6 +655,9 @@ static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
> },
> {
> .wai = 0x6b,
> + .int1_addr = 0x0d,
> + .int2_addr = 0x0e,
> + .reset_addr = 0x12,
> .max_fifo_size = 512,
> .id = {
> {
> @@ -1172,10 +1185,10 @@ static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
>
> switch (drdy_pin) {
> case 1:
> - *drdy_reg = ST_LSM6DSX_REG_INT1_ADDR;
> + *drdy_reg = hw->settings->int1_addr;
> break;
> case 2:
> - *drdy_reg = ST_LSM6DSX_REG_INT2_ADDR;
> + *drdy_reg = hw->settings->int2_addr;
> break;
> default:
> dev_err(hw->dev, "unsupported data ready pin\n");
> @@ -1275,7 +1288,7 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> int err;
>
> /* device sw reset */
> - err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR,
> + err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
> ST_LSM6DSX_REG_RESET_MASK,
> FIELD_PREP(ST_LSM6DSX_REG_RESET_MASK, 1));
> if (err < 0)
> @@ -1284,7 +1297,7 @@ static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
> msleep(50);
>
> /* reload trimming parameter */
> - err = regmap_update_bits(hw->regmap, ST_LSM6DSX_REG_RESET_ADDR,
> + err = regmap_update_bits(hw->regmap, hw->settings->reset_addr,
> ST_LSM6DSX_REG_BOOT_MASK,
> FIELD_PREP(ST_LSM6DSX_REG_BOOT_MASK, 1));
> if (err < 0)

2019-08-27 20:01:53

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v5 2/4] iio: imu: st_lsm6sdx: move register definitions to sensor_settings struct

On Tue, 27 Aug 2019 08:54:57 +0200
Martin Kepplinger <[email protected]> wrote:

> On 21.08.19 15:25, Martin Kepplinger wrote:
> > Move some register definitions to the per-device array of struct
> > st_lsm6dsx_sensor_settings in order to simplify adding new sensor
> > devices to the driver.
> >
> > Also, remove completely unused register definitions.
> >
> > Signed-off-by: Martin Kepplinger <[email protected]>
> > Acked-by: Lorenzo Bianconi <[email protected]>
> > ---
> > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 6 ++++
> > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 31 ++++++++++++++------
> > 2 files changed, 28 insertions(+), 9 deletions(-)
> >
>
> I just notices the commit message header typo "st_lsm6sdx" should be
> "st_lsm6dsx" of course. If you can still rebase/force-push to testing,
> would you be able to fix that? If it's too far out there already, so be
> it :) sorry for the typo, and thanks for adding "-imu" yourself where
> applicable.

I can indeed. Fixed up.

Added Rob's ack to the dt patch as well.

Thanks,

Jonathan

>
> thanks,
>
> martin