STMicroelectronics IIO driver
Hi Jonathan, Lars,
I modified the drivers following the advice of Lars (about code duplication) and Jonathan patches.
I also used coccicheck to verify the code. I couldn't test the drivers on the physical devices because I was not in office. I hope to do some tests Monday morning.
Thanks and Best Regards,
Denis
PATCH 1/4 iio:common: Add STMicroelectronics common library
This patch add a generic library for STMicroelectronics 3-axis sensors.
--- drivers/iio/common/Kconfig | 1 + drivers/iio/common/Makefile | 1 + drivers/iio/common/st_sensors/Kconfig | 14 + drivers/iio/common/st_sensors/Makefile | 10 + drivers/iio/common/st_sensors/st_sensors_buffer.c | 116 +++++ drivers/iio/common/st_sensors/st_sensors_core.c | 460 ++++++++++++++++++++ drivers/iio/common/st_sensors/st_sensors_i2c.c | 81 ++++ drivers/iio/common/st_sensors/st_sensors_spi.c | 128 ++++++ drivers/iio/common/st_sensors/st_sensors_trigger.c | 77 ++++ include/linux/iio/common/st_sensors.h | 274 ++++++++++++ include/linux/iio/common/st_sensors_i2c.h | 20 + include/linux/iio/common/st_sensors_spi.h | 20 + 12 files changed, 1202 insertions(+) create mode 100644 drivers/iio/common/st_sensors/Kconfig create mode 100644 drivers/iio/common/st_sensors/Makefile create mode 100644 drivers/iio/common/st_sensors/st_sensors_buffer.c create mode 100644 drivers/iio/common/st_sensors/st_sensors_core.c create mode 100644 drivers/iio/common/st_sensors/st_sensors_i2c.c create mode 100644 drivers/iio/common/st_sensors/st_sensors_spi.c create mode 100644 drivers/iio/common/st_sensors/st_sensors_trigger.c create mode 100644 include/linux/iio/common/st_sensors.h create mode 100644 include/linux/iio/common/st_sensors_i2c.h create mode 100644 include/linux/iio/common/st_sensors_spi.h
drivers/iio/common/Kconfig +1 -0
@@ -3,3 +3,4 @@ # source "drivers/iio/common/hid-sensors/Kconfig" +source "drivers/iio/common/st_sensors/Kconfig"
drivers/iio/common/Makefile +1 -0
@@ -7,3 +7,4 @@ # obj-y += hid-sensors/ +obj-y += st_sensors/
drivers/iio/common/st_sensors/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# +# Hid Sensor common modules +# + +config IIO_ST_SENSORS_I2C + tristate + +config IIO_ST_SENSORS_SPI + tristate + +config IIO_ST_SENSORS_CORE + tristate + select IIO_ST_SENSORS_I2C if I2C + select IIO_ST_SENSORS_SPI if SPI_MASTER
drivers/iio/common/st_sensors/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# +# Makefile for the STMicroelectronics sensor common modules. +# + +obj-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o +obj-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o +obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o +st_sensors-y := st_sensors_core.o +st_sensors-$(CONFIG_IIO_BUFFER) += st_sensors_buffer.o +st_sensors-$(CONFIG_IIO_TRIGGER) += st_sensors_trigger.o
drivers/iio/common/st_sensors/st_sensors_buffer.c new file +116 -0
116 lines not on this page · raw message
drivers/iio/common/st_sensors/st_sensors_core.c new file +460 -0
460 lines not on this page · raw message
drivers/iio/common/st_sensors/st_sensors_i2c.c new file +81 -0
81 lines not on this page · raw message
drivers/iio/common/st_sensors/st_sensors_spi.c new file +128 -0
128 lines not on this page · raw message
drivers/iio/common/st_sensors/st_sensors_trigger.c new file +77 -0
77 lines not on this page · raw message
include/linux/iio/common/st_sensors.h new file +274 -0
274 lines not on this page · raw message
include/linux/iio/common/st_sensors_i2c.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* STMicroelectronics sensors i2c library driver +* +* Copyright 2012-2013 STMicroelectronics Inc. +* +* Denis Ciocca <[email protected]> +* +* Licensed under the GPL-2. +*/ + +#ifndef ST_SENSORS_I2C_H +#define ST_SENSORS_I2C_H + +#include <linux/i2c.h> +#include <linux/iio/common/st_sensors.h> + +void st_sensors_i2c_configure (struct iio_dev *indio_dev, +struct i2c_client *client,struct st_sensor_data *sdata); + +#endif /* ST_SENSORS_I2C_H */
include/linux/iio/common/st_sensors_spi.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* STMicroelectronics sensors spi library driver +* +* Copyright 2012-2013 STMicroelectronics Inc. +* +* Denis Ciocca <[email protected]> +* +* Licensed under the GPL-2. +*/ + +#ifndef ST_SENSORS_SPI_H +#define ST_SENSORS_SPI_H + +#include <linux/spi/spi.h> +#include <linux/iio/common/st_sensors.h> + +void st_sensors_spi_configure (struct iio_dev *indio_dev, +struct spi_device *spi,struct st_sensor_data *sdata); + +#endif /* ST_SENSORS_SPI_H */
Signature · 1 line
1.7.9.5
Re: [PATCH 1/4] iio:common: Add STMicroelectronics common library
Hi,
here is one of the rough edges I was talking about earlier.
Quoted 9 lines · Denis Ciocca
drivers/iio/common/st_sensors/st_sensors_core.c new file +9
-0+int st_sensors_get_sampling_frequency_avl (struct iio_dev *indio_dev,char *buf) +{ +int i, len =0 ; +struct st_sensor_data *sdata =iio_priv (indio_dev); + +mutex_lock (&indio_dev->mlock); +for (i =0 ; i <ST_SENSORS_ODR_LIST_MAX ; i++) { +if (sdata->sensor->odr.odr_avl[i].hz ==0 ) +break ;
drivers/iio/common/st_sensors/st_sensors_core.c line 59
Quoted 10 lines
drivers/iio/common/st_sensors/st_sensors_core.c new file +10
-0+ + len +=scnprintf (buf + len,PAGE_SIZE - len,"%d " , + sdata->sensor->odr.odr_avl[i].hz); + } +mutex_unlock (&indio_dev->mlock); + buf[len -1 ] ='\n' ; + +return len; +} +EXPORT_SYMBOL (st_sensors_get_sampling_frequency_avl);
This function is no longer used outside the st_sensors core module, so there is no need to export it anymore. In fact it is only used in st_sensors_sysfs_sampling_frequency_avail, which itself is not more than the call to st_sensors_get_sampling_frequency_avl, so I'd just move the contents of st_sensors_get_sampling_frequency_avl to st_sensors_sysfs_sampling_frequency_avail.
Quoted 10 lines
drivers/iio/common/st_sensors/st_sensors_core.c new file +10
-0+ +int st_sensors_get_scale_avl (struct iio_dev *indio_dev,char *buf) +{ +int i, len =0 ; +struct st_sensor_data *sdata =iio_priv (indio_dev); + +mutex_lock (&indio_dev->mlock); +for (i =0 ; i <ST_SENSORS_FULLSCALE_AVL_MAX ; i++) { +if (sdata->sensor->fs.fs_avl[i].num ==0 ) +break ;
drivers/iio/common/st_sensors/st_sensors_core.c line 79
Quoted 10 lines
drivers/iio/common/st_sensors/st_sensors_core.c new file +10
-0+ + len +=scnprintf (buf + len,PAGE_SIZE - len,"0.%06u " , + sdata->sensor->fs.fs_avl[i].gain); + } +mutex_unlock (&indio_dev->mlock); + buf[len -1 ] ='\n' ; + +return len; +} +EXPORT_SYMBOL (st_sensors_get_scale_avl);
Similar here.
Quoted 1 line
+
[...]
PATCH 2/4 iio:accel: Add STMicroelectronics accelerometers driver
In reply to Denis CioccaThis patch adds a generic accelerometer driver for STMicroelectronics accelerometers, currently it supports:
LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, LIS331DLH, LSM303DL, LSM303DLM, LSM330.
--- drivers/iio/accel/Kconfig | 31 +++ drivers/iio/accel/Makefile | 7 + drivers/iio/accel/st_accel.h | 47 ++++ drivers/iio/accel/st_accel_buffer.c | 114 ++++++++ drivers/iio/accel/st_accel_core.c | 495 +++++++++++++++++++++++++++++++++++ drivers/iio/accel/st_accel_i2c.c | 87 ++++++ drivers/iio/accel/st_accel_spi.c | 86 ++++++ 7 files changed, 867 insertions(+) create mode 100644 drivers/iio/accel/st_accel.h create mode 100644 drivers/iio/accel/st_accel_buffer.c create mode 100644 drivers/iio/accel/st_accel_core.c create mode 100644 drivers/iio/accel/st_accel_i2c.c create mode 100644 drivers/iio/accel/st_accel_spi.c
drivers/iio/accel/Kconfig +31 -0
@@ -14,4 +14,35 @@ config HID_SENSOR_ACCEL_3D Say yes here to build support for the HID SENSOR accelerometers 3D. +config IIO_ST_ACCEL_3AXIS + tristate "STMicroelectronics accelerometers 3-Axis Driver" + depends on (I2C || SPI_MASTER) && SYSFS + select IIO_ST_SENSORS_CORE + select IIO_ST_ACCEL_I2C_3AXIS if (I2C) + select IIO_ST_ACCEL_SPI_3AXIS if (SPI_MASTER) + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) + select IIO_ST_ACCEL_BUFFER if (IIO_TRIGGERED_BUFFER) + help + Say yes here to build support for STMicroelectronics accelerometers: + LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC, + LIS331DLH, LSM303DL, LSM303DLM, LSM330. + + This driver can also be built as a module. If so, will be created + these modules: + - st_accel (core functions for the driver [it is mandatory]); + - st_accel_i2c (necessary for the I2C devices [optional*]); + - st_accel_spi (necessary for the SPI devices [optional*]); + + (*) one of these is necessary to do something. + +config IIO_ST_ACCEL_I2C_3AXIS + tristate + depends on IIO_ST_ACCEL_3AXIS + depends on IIO_ST_SENSORS_I2C + +config IIO_ST_ACCEL_SPI_3AXIS + tristate + depends on IIO_ST_ACCEL_3AXIS + depends on IIO_ST_SENSORS_SPI + endmenu
drivers/iio/accel/Makefile +7 -0
@@ -3,3 +3,10 @@ # obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o + +obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o +st_accel-y := st_accel_core.o +st_accel-$(CONFIG_IIO_BUFFER) += st_accel_buffer.o + +obj-$(CONFIG_IIO_ST_ACCEL_I2C_3AXIS) += st_accel_i2c.o +obj-$(CONFIG_IIO_ST_ACCEL_SPI_3AXIS) += st_accel_spi.o
drivers/iio/accel/st_accel.h new file +47 -0
47 lines not on this page · raw message
drivers/iio/accel/st_accel_buffer.c new file +114 -0
114 lines not on this page · raw message
drivers/iio/accel/st_accel_core.c new file +495 -0
495 lines not on this page · raw message
drivers/iio/accel/st_accel_i2c.c new file +87 -0
87 lines not on this page · raw message
drivers/iio/accel/st_accel_spi.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 3/4 iio:gyro: Add STMicroelectronics gyroscopes driver
In reply to Denis CioccaThis patch adds a generic gyroscope driver for STMicroelectronics gyroscopes, currently it supports:
L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330.
--- drivers/iio/gyro/Kconfig | 30 +++ drivers/iio/gyro/Makefile | 7 + drivers/iio/gyro/st_gyro.h | 45 +++++ drivers/iio/gyro/st_gyro_buffer.c | 114 ++++++++++++ drivers/iio/gyro/st_gyro_core.c | 363 +++++++++++++++++++++++++++++++++++++ drivers/iio/gyro/st_gyro_i2c.c | 85 +++++++++ drivers/iio/gyro/st_gyro_spi.c | 84 +++++++++ 7 files changed, 728 insertions(+) create mode 100644 drivers/iio/gyro/st_gyro.h create mode 100644 drivers/iio/gyro/st_gyro_buffer.c create mode 100644 drivers/iio/gyro/st_gyro_core.c create mode 100644 drivers/iio/gyro/st_gyro_i2c.c create mode 100644 drivers/iio/gyro/st_gyro_spi.c
drivers/iio/gyro/Kconfig +30 -0
@@ -23,4 +23,34 @@ config HID_SENSOR_GYRO_3D Say yes here to build support for the HID SENSOR Gyroscope 3D. +config IIO_ST_GYRO_3AXIS + tristate "STMicroelectronics gyroscopes 3-Axis Driver" + depends on (I2C || SPI_MASTER) && SYSFS + select IIO_ST_SENSORS_CORE + select IIO_ST_GYRO_I2C_3AXIS if (I2C) + select IIO_ST_GYRO_SPI_3AXIS if (SPI_MASTER) + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) + select IIO_ST_GYRO_BUFFER if (IIO_TRIGGERED_BUFFER) + help + Say yes here to build support for STMicroelectronics gyroscopes: + L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330. + + This driver can also be built as a module. If so, will be created + these modules: + - st_gyro (core functions for the driver [it is mandatory]); + - st_gyro_i2c (necessary for the I2C devices [optional*]); + - st_gyro_spi (necessary for the SPI devices [optional*]); + + (*) one of these is necessary to do something. + +config IIO_ST_GYRO_I2C_3AXIS + tristate + depends on IIO_ST_GYRO_3AXIS + depends on IIO_ST_SENSORS_I2C + +config IIO_ST_GYRO_SPI_3AXIS + tristate + depends on IIO_ST_GYRO_3AXIS + depends on IIO_ST_SENSORS_SPI + endmenu
drivers/iio/gyro/Makefile +7 -0
@@ -4,3 +4,10 @@ obj-$(CONFIG_ADIS16136) += adis16136.o obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o + +obj-$(CONFIG_IIO_ST_GYRO_3AXIS) += st_gyro.o +st_gyro-y := st_gyro_core.o +st_gyro-$(CONFIG_IIO_BUFFER) += st_gyro_buffer.o + +obj-$(CONFIG_IIO_ST_GYRO_I2C_3AXIS) += st_gyro_i2c.o +obj-$(CONFIG_IIO_ST_GYRO_SPI_3AXIS) += st_gyro_spi.o
drivers/iio/gyro/st_gyro.h new file +45 -0
45 lines not on this page · raw message
drivers/iio/gyro/st_gyro_buffer.c new file +114 -0
114 lines not on this page · raw message
drivers/iio/gyro/st_gyro_core.c new file +363 -0
363 lines not on this page · raw message
drivers/iio/gyro/st_gyro_i2c.c new file +85 -0
85 lines not on this page · raw message
drivers/iio/gyro/st_gyro_spi.c new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 4/4 iio:magnetometer: Add STMicroelectronics magnetometers driver
In reply to Denis CioccaThis patch adds a generic magnetometer driver for STMicroelectronics magnetometers, currently it supports:
LSM303DLHC, LSM303DLM, LIS3MDL.
--- drivers/iio/magnetometer/Kconfig | 30 +++ drivers/iio/magnetometer/Makefile | 7 + drivers/iio/magnetometer/st_magn.h | 45 ++++ drivers/iio/magnetometer/st_magn_buffer.c | 98 +++++++ drivers/iio/magnetometer/st_magn_core.c | 394 +++++++++++++++++++++++++++++ drivers/iio/magnetometer/st_magn_i2c.c | 81 ++++++ drivers/iio/magnetometer/st_magn_spi.c | 80 ++++++ 7 files changed, 735 insertions(+) create mode 100644 drivers/iio/magnetometer/st_magn.h create mode 100644 drivers/iio/magnetometer/st_magn_buffer.c create mode 100644 drivers/iio/magnetometer/st_magn_core.c create mode 100644 drivers/iio/magnetometer/st_magn_i2c.c create mode 100644 drivers/iio/magnetometer/st_magn_spi.c
drivers/iio/magnetometer/Kconfig +30 -0
@@ -14,4 +14,34 @@ config HID_SENSOR_MAGNETOMETER_3D Say yes here to build support for the HID SENSOR Magnetometer 3D. +config IIO_ST_MAGN_3AXIS + tristate "STMicroelectronics magnetometers 3-Axis Driver" + depends on (I2C || SPI_MASTER) && SYSFS + select IIO_ST_SENSORS_CORE + select IIO_ST_MAGN_I2C_3AXIS if (I2C) + select IIO_ST_MAGN_SPI_3AXIS if (SPI_MASTER) + select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) + select IIO_ST_MAGN_BUFFER if (IIO_TRIGGERED_BUFFER) + help + Say yes here to build support for STMicroelectronics magnetometers: + LSM303DLHC, LSM303DLM, LIS3MDL. + + This driver can also be built as a module. If so, will be created + these modules: + - st_magn (core functions for the driver [it is mandatory]); + - st_magn_i2c (necessary for the I2C devices [optional*]); + - st_magn_spi (necessary for the SPI devices [optional*]); + + (*) one of these is necessary to do something. + +config IIO_ST_MAGN_I2C_3AXIS + tristate + depends on IIO_ST_MAGN_3AXIS + depends on IIO_ST_SENSORS_I2C + +config IIO_ST_MAGN_SPI_3AXIS + tristate + depends on IIO_ST_MAGN_3AXIS + depends on IIO_ST_SENSORS_SPI + endmenu
drivers/iio/magnetometer/Makefile +7 -0
@@ -3,3 +3,10 @@ # obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o + +obj-$(CONFIG_IIO_ST_MAGN_3AXIS) += st_magn.o +st_magn-y := st_magn_core.o +st_magn-$(CONFIG_IIO_BUFFER) += st_magn_buffer.o + +obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o +obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o
drivers/iio/magnetometer/st_magn.h new file +45 -0
45 lines not on this page · raw message
drivers/iio/magnetometer/st_magn_buffer.c new file +98 -0
98 lines not on this page · raw message
drivers/iio/magnetometer/st_magn_core.c new file +394 -0
394 lines not on this page · raw message
drivers/iio/magnetometer/st_magn_i2c.c new file +81 -0
81 lines not on this page · raw message
drivers/iio/magnetometer/st_magn_spi.c new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Lars-Peter Clausen
Reviewed-byQuoted 9 lines · Denis Ciocca
Hi Jonathan, Lars,
I modified the drivers following the advice of Lars (about code duplication) and Jonathan patches.
I also used coccicheck to verify the code. I couldn't test the drivers on the physical devices because I was not in office. I hope to do some tests Monday morning.Thanks and Best Regards,
Denis
Hi,
I think the driver is now in a state where we can merge it, good work. There are one or two rough edges left, but no blockers and nothing that can't be fixed in follow up patches. (And to be honest I'm kind of tired of reviewing the same code over and over again ;))
So for the whole series:
- Lars
Quoted 13 lines · Lars-Peter Clausen
Quoted 9 lines · Denis Ciocca
Hi Jonathan, Lars,
I modified the drivers following the advice of Lars (about code duplication) and Jonathan patches.
I also used coccicheck to verify the code. I couldn't test the drivers on the physical devices because I was not in office. I hope to do some tests Monday morning.Thanks and Best Regards,
Denis
Hi,
Quoted 8 lines
I think the driver is now in a state where we can merge it, good work. There are one or two rough edges left, but no blockers and nothing that can't be fixed in follow up patches. (And to be honest I'm kind of tired of reviewing the same code over and over again ;))
So for the whole series:
Reviewed-by Lars-Peter Clausen <[email protected]>
Thanks Lars.
Applied to togreg branch of iio.git. Note there was some fuzz on patches 2 and 3 + need to do a merge on patch 2 due to makefile changes. Denis, could you verify I didn't mess it up (as I am occasionally known to do ;)
This won't go to Greg until next weekend anyway now.
Jonathan
Quoted 4 lines
- Lars
Quoted 3 lines
Applied to togreg branch of iio.git. Note there was some fuzz on patches 2 and 3 + need to do a merge on patch 2 due to makefile changes. Denis, could you verify I didn't mess it up (as I am occasionally known to do ;)
I tested the driver and I didn't find any problems, there is only one littl= e=20
wrong label in Kconfig of iio/st_sensors/Kconfig:
--- drivers/iio/common/st_sensors/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0
b/drivers/iio/common/st_sensors/Kconfig
index 84b2dca..865f1ca 100644
drivers/iio/common/st_sensors/Kconfig +1 -1
@@ -1,5 +1,5 @@ # -# Hid Sensor common modules +# STMicroelectronics sensors common library #
=20
config IIO_ST_SENSORS_I2C
--=20
1.7.9.5
Quoted 1 line
This won't go to Greg until next weekend anyway now.
Ok thanks!
Jonathan Cameron
maintainerQuoted 6 lines · Denis CIOCCA
Quoted 3 lines
Applied to togreg branch of iio.git. Note there was some fuzz on patches 2 and 3 + need to do a merge on patch 2 due to makefile changes. Denis, could you verify I didn't mess it up (as I am occasionally known to do ;)
I tested the driver and I didn't find any problems, there is only one little wrong label in
Kconfigof iio/st_sensors/Kconfig:
As I've never said my tree won't rebase or remain consistent, I've just applied this inside the original patch.
Quoted 18 lines
--- drivers/iio/common/st_sensors/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/common/st_sensors/Kconfig +1
-1@@ -1,5 +1,5 @@ # -# Hid Sensor common modules +# STMicroelectronics sensors common library # config IIO_ST_SENSORS_I2C
Quoted 2 lines
As I've never said my tree won't rebase or remain consistent, I've just applied this inside the original patch.
Ok Thanks!
Denis
Quoted 1 line
I think the driver is now in a state where we can merge it, good work.
Thanks Lars...
Quoted 2 lines
There are one or two rough edges left, but no blockers and nothing that can't be fixed in follow up patches.
Ok if you tell me where are these problems I can patch it.
Quoted 2 lines
(And to be honest I'm kind of tired of
reviewing the same code over and over again ;))
I'm sorry. I'm learning to write linux device driver... ;)
Thanks
Denis=