iio: st_sensors: Add lsm303d support
Subsystems (2)
v2 cover iio: st_sensors: Add lsm303d support
Hi!
This patch series adds support for the LSM303D accelerometer and magnetometer. As the LSM303D is basically, as far as I can tell, the LSM9DS0 without gyroscope, we can easily re-use its definitions.
This was tested on a Lenovo Yoga Tablet 2 1051-F.
Cheers,
Marius
Marius Hoch (6):
iio: accel: st_accel: Add LSM303D
iio: magnetometer: st_accel: Add LSM303D
iio: st_sensors: Add lsm303d support to the LSM9DS0 IMU driver
iio: st_sensors: Add ACPI support for lsm303d to the LSM9DS0 IMU
driver
iio: Comment that the LSM303D also has the Magnetometer DRDY
dt-bindings: iio: st-sensors: Add LSM303D accelerometer+magnetometer
.../devicetree/bindings/iio/st,st-sensors.yaml | 1 + drivers/iio/accel/st_accel_core.c | 1 + drivers/iio/imu/st_lsm9ds0/Kconfig | 3 ++- drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c | 15 +++++++++++++++ drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c | 15 +++++++++++++++ drivers/iio/magnetometer/st_magn_core.c | 1 + include/linux/iio/common/st_sensors.h | 1 + include/linux/platform_data/st_sensors_pdata.h | 2 +- 8 files changed, 37 insertions(+), 2 deletions(-)
base-commit: e62252bc55b6d4eddc6c2bdbf95a448180d6a08d
Signature · 1 line
2.39.2
PATCH v2 1/6 iio: accel: st_accel: Add LSM303D
The lsm303d has the same register mapping as the lsm9ds0, thus we can just re-use that.
Tested on a Lenovo Yoga Tablet 2 1051-F.
--- drivers/iio/accel/st_accel_core.c | 1 + include/linux/iio/common/st_sensors.h | 1 + 2 files changed, 2 insertions(+)
drivers/iio/accel/st_accel_core.c +1 -0
@@ -1006,6 +1006,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = { .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, .sensors_supported = { [0] = LSM9DS0_IMU_DEV_NAME, + [1] = LSM303D_IMU_DEV_NAME, }, .ch = (struct iio_chan_spec *)st_accel_16bit_channels, .odr = {
include/linux/iio/common/st_sensors.h +1 -0
@@ -22,6 +22,7 @@#include <linux/platform_data/st_sensors_pdata.h> #define LSM9DS0_IMU_DEV_NAME "lsm9ds0" +#define LSM303D_IMU_DEV_NAME "lsm303d"/* * Buffer size max case: 2bytes per channel, 3 channels in total +
Signature · 1 line
2.39.2
PATCH v2 2/6 iio: magnetometer: st_accel: Add LSM303D
In reply to Marius HochThe lsm303d has the same register mapping as the lsm9ds0, thus we can just re-use that.
Tested on a Lenovo Yoga Tablet 2 1051-F.
--- drivers/iio/magnetometer/st_magn_core.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/magnetometer/st_magn_core.c +1 -0
@@ -427,6 +427,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = { .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, .sensors_supported = { [0] = LSM9DS0_IMU_DEV_NAME, + [1] = LSM303D_IMU_DEV_NAME, }, .ch = (struct iio_chan_spec *)st_magn_4_16bit_channels, .odr = {
Signature · 1 line
2.39.2
PATCH v2 3/6 iio: st_sensors: Add lsm303d support to the LSM9DS0 IMU driver
In reply to Marius HochThe lsm303d is basically the lsm9ds0 without the gyroscope (which the LSM9DS0 IMU driver doesn't handle), as far as I can tell.
--- drivers/iio/imu/st_lsm9ds0/Kconfig | 3 ++- drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c | 5 +++++ drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-)
drivers/iio/imu/st_lsm9ds0/Kconfig +2 -1
@@ -10,7 +10,8 @@ config IIO_ST_LSM9DS0 help Say yes here to build support for STMicroelectronics LSM9DS0 IMU - sensor. Supported devices: accelerometer/magnetometer of lsm9ds0. + sensor. Supported devices: accelerometer/magnetometer of lsm9ds0 + and lsm303d. To compile this driver as a module, choose M here: the module will be called st_lsm9ds0.
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +5 -0
@@ -22,12 +22,17 @@ static const struct of_device_id st_lsm9ds0_of_match[] = { .compatible = "st,lsm9ds0-imu", .data = LSM9DS0_IMU_DEV_NAME, }, + { + .compatible = "st,lsm303d-imu", + .data = LSM303D_IMU_DEV_NAME, + }, {} };MODULE_DEVICE_TABLE (of, st_lsm9ds0_of_match);static const struct i2c_device_id st_lsm9ds0_id_table[] = { {LSM9DS0_IMU_DEV_NAME }, + {LSM303D_IMU_DEV_NAME }, {} };MODULE_DEVICE_TABLE (i2c, st_lsm9ds0_id_table);
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c +5 -0
@@ -22,12 +22,17 @@ static const struct of_device_id st_lsm9ds0_of_match[] = { .compatible = "st,lsm9ds0-imu", .data = LSM9DS0_IMU_DEV_NAME, }, + { + .compatible = "st,lsm303d-imu", + .data = LSM303D_IMU_DEV_NAME, + }, {} };MODULE_DEVICE_TABLE (of, st_lsm9ds0_of_match);static const struct spi_device_id st_lsm9ds0_id_table[] = { {LSM9DS0_IMU_DEV_NAME }, + {LSM303D_IMU_DEV_NAME }, {} };MODULE_DEVICE_TABLE (spi, st_lsm9ds0_id_table);
Signature · 1 line
2.39.2
PATCH v2 4/6 iio: st_sensors: Add ACPI support for lsm303d to the LSM9DS0 IMU driver
In reply to Marius HochThe lsm303d can be found as ACCL0001 on various Lenovo devices, including the Lenovo Yoga Tablet 2 1051-F, where I tested this patch.
--- drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c | 10 ++++++++++ drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c | 10 ++++++++++ 2 files changed, 20 insertions(+)
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +10 -0
@@ -12,6 +12,7 @@#include <linux/module.h> #include <linux/mod_devicetable.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <linux/iio/common/st_sensors_i2c.h>
@@ -37,6 +38,14 @@ static const struct i2c_device_id st_lsm9ds0_id_table[] = { };MODULE_DEVICE_TABLE (i2c, st_lsm9ds0_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id st_lsm9ds0_acpi_match[] = { + {"ACCL0001" , (kernel_ulong_t )LSM303D_IMU_DEV_NAME }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, st_lsm9ds0_acpi_match); +#endif +static const struct regmap_config st_lsm9ds0_regmap_config = { .reg_bits =8 , .val_bits =8 ,
@@ -73,6 +82,7 @@ static struct i2c_driver st_lsm9ds0_driver = { .driver = { .name = "st-lsm9ds0-i2c", .of_match_table = st_lsm9ds0_of_match, + .acpi_match_table = ACPI_PTR(st_lsm9ds0_acpi_match), }, .probe_new = st_lsm9ds0_i2c_probe, .id_table = st_lsm9ds0_id_table,
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c +10 -0
@@ -12,6 +12,7 @@#include <linux/mod_devicetable.h> #include <linux/regmap.h> #include <linux/spi/spi.h> +#include <linux/acpi.h> #include <linux/iio/common/st_sensors_spi.h>
@@ -37,6 +38,14 @@ static const struct spi_device_id st_lsm9ds0_id_table[] = { };MODULE_DEVICE_TABLE (spi, st_lsm9ds0_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id st_lsm9ds0_acpi_match[] = { + {"ACCL0001" , (kernel_ulong_t )LSM303D_IMU_DEV_NAME }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, st_lsm9ds0_acpi_match); +#endif +static const struct regmap_config st_lsm9ds0_regmap_config = { .reg_bits =8 , .val_bits =8 ,
@@ -72,6 +81,7 @@ static struct spi_driver st_lsm9ds0_driver = { .driver = { .name = "st-lsm9ds0-spi", .of_match_table = st_lsm9ds0_of_match, + .acpi_match_table = ACPI_PTR(st_lsm9ds0_acpi_match), }, .probe = st_lsm9ds0_spi_probe, .id_table = st_lsm9ds0_id_table,
Signature · 1 line
2.39.2
Jonathan Cameron
maintainerRe: [PATCH v2 4/6] iio: st_sensors: Add ACPI support for lsm303d to the LSM9DS0 IMU driver
Quoted 23 lines · On Thu, 13 Apr 2023 04:40:11 +0200 Marius Hoch <[email protected]> wrote:
The lsm303d can be found as ACCL0001 on various Lenovo devices, including the Lenovo Yoga Tablet 2 1051-F, where I tested this patch.
Signed-off-by Marius Hoch <[email protected]>--- drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c | 10 ++++++++++ drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c | 10 ++++++++++ 2 files changed, 20 insertions(+)drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +1
-0@@ -12,6 +12,7 @@#include <linux/module.h> #include <linux/mod_devicetable.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <linux/iio/common/st_sensors_i2c.h>
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c static const struct i2c_device_id st_lsm9ds0_id_table[] = { · line 47
Quoted 10 lines
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +7
-0@@ -37,6 +38,14 @@ static const struct i2c_device_id st_lsm9ds0_id_table[] = { };MODULE_DEVICE_TABLE (i2c, st_lsm9ds0_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id st_lsm9ds0_acpi_match[] = { + {"ACCL0001" , (kernel_ulong_t )LSM303D_IMU_DEV_NAME }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, st_lsm9ds0_acpi_match); +#endif
The table is tiny so I'd prefer dropping the complexity of ifdefs and getting rid of the ACPI_PTR() below. Just assign the pointer unconditionally.
Rest of the series looks good to me
Thanks,
Jonathan
Quoted 47 lines
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +2
-0+static const struct regmap_config st_lsm9ds0_regmap_config = { .reg_bits =8 , .val_bits =8 ,@@ -73,6 +82,7 @@ static struct i2c_driver st_lsm9ds0_driver = { .driver = { .name = "st-lsm9ds0-i2c", .of_match_table = st_lsm9ds0_of_match, + .acpi_match_table = ACPI_PTR(st_lsm9ds0_acpi_match), }, .probe_new = st_lsm9ds0_i2c_probe, .id_table = st_lsm9ds0_id_table,drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c +10
-0@@ -12,6 +12,7 @@#include <linux/mod_devicetable.h> #include <linux/regmap.h> #include <linux/spi/spi.h> +#include <linux/acpi.h> #include <linux/iio/common/st_sensors_spi.h> @@ -37,6 +38,14 @@ static const struct spi_device_id st_lsm9ds0_id_table[] = { };MODULE_DEVICE_TABLE (spi, st_lsm9ds0_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id st_lsm9ds0_acpi_match[] = { + {"ACCL0001" , (kernel_ulong_t )LSM303D_IMU_DEV_NAME }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, st_lsm9ds0_acpi_match); +#endif +static const struct regmap_config st_lsm9ds0_regmap_config = { .reg_bits =8 , .val_bits =8 ,@@ -72,6 +81,7 @@ static struct spi_driver st_lsm9ds0_driver = { .driver = { .name = "st-lsm9ds0-spi", .of_match_table = st_lsm9ds0_of_match, + .acpi_match_table = ACPI_PTR(st_lsm9ds0_acpi_match), }, .probe = st_lsm9ds0_spi_probe, .id_table = st_lsm9ds0_id_table,
Re: [PATCH v2 4/6] iio: st_sensors: Add ACPI support for lsm303d to the LSM9DS0 IMU driver
Quoted 40 lines · Jonathan Cameron
Quoted 23 lines · On Thu, 13 Apr 2023 04:40:11 +0200 Marius Hoch <[email protected]> wrote:
The lsm303d can be found as ACCL0001 on various Lenovo devices, including the Lenovo Yoga Tablet 2 1051-F, where I tested this patch.
Signed-off-by Marius Hoch <[email protected]>--- drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c | 10 ++++++++++ drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c | 10 ++++++++++ 2 files changed, 20 insertions(+)drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +1
-0@@ -12,6 +12,7 @@#include <linux/module.h> #include <linux/mod_devicetable.h> #include <linux/regmap.h> +#include <linux/acpi.h> #include <linux/iio/common/st_sensors_i2c.h> drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c static const struct i2c_device_id st_lsm9ds0_id_table[] = { · line 47
Quoted 10 lines
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +7
-0@@ -37,6 +38,14 @@ static const struct i2c_device_id st_lsm9ds0_id_table[] = { };MODULE_DEVICE_TABLE (i2c, st_lsm9ds0_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id st_lsm9ds0_acpi_match[] = { + {"ACCL0001" , (kernel_ulong_t )LSM303D_IMU_DEV_NAME }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, st_lsm9ds0_acpi_match); +#endif The table is tiny so I'd prefer dropping the complexity of ifdefs and getting rid of the
ACPI_PTR()below. Just assign the pointer unconditionally.
Quoted 5 lines
Rest of the series looks good to me
Thanks,
Jonathan
Thanks for your review, applied in v3.
Quoted 47 lines
Quoted 47 lines
drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c +2
-0+static const struct regmap_config st_lsm9ds0_regmap_config = { .reg_bits =8 , .val_bits =8 ,@@ -73,6 +82,7 @@ static struct i2c_driver st_lsm9ds0_driver = { .driver = { .name = "st-lsm9ds0-i2c", .of_match_table = st_lsm9ds0_of_match, + .acpi_match_table = ACPI_PTR(st_lsm9ds0_acpi_match), }, .probe_new = st_lsm9ds0_i2c_probe, .id_table = st_lsm9ds0_id_table,drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c +10
-0@@ -12,6 +12,7 @@#include <linux/mod_devicetable.h> #include <linux/regmap.h> #include <linux/spi/spi.h> +#include <linux/acpi.h> #include <linux/iio/common/st_sensors_spi.h> @@ -37,6 +38,14 @@ static const struct spi_device_id st_lsm9ds0_id_table[] = { };MODULE_DEVICE_TABLE (spi, st_lsm9ds0_id_table); +#ifdef CONFIG_ACPI +static const struct acpi_device_id st_lsm9ds0_acpi_match[] = { + {"ACCL0001" , (kernel_ulong_t )LSM303D_IMU_DEV_NAME }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, st_lsm9ds0_acpi_match); +#endif +static const struct regmap_config st_lsm9ds0_regmap_config = { .reg_bits =8 , .val_bits =8 ,@@ -72,6 +81,7 @@ static struct spi_driver st_lsm9ds0_driver = { .driver = { .name = "st-lsm9ds0-spi", .of_match_table = st_lsm9ds0_of_match, + .acpi_match_table = ACPI_PTR(st_lsm9ds0_acpi_match), }, .probe = st_lsm9ds0_spi_probe, .id_table = st_lsm9ds0_id_table,
PATCH v2 5/6 iio: Comment that the LSM303D also has the Magnetometer DRDY
In reply to Marius HochPer its datasheet, the LSM303D also features that
pin.
--- include/linux/platform_data/st_sensors_pdata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/platform_data/st_sensors_pdata.h +1 -1
@@ -15,7 +15,7 @@* @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2). * Available only for accelerometer, magnetometer and pressure sensors. * Accelerometer DRDY on LSM330 available only on pin 1 (see datasheet). -* Magnetometer DRDY is supported only on LSM9DS0. +* Magnetometer DRDY is supported only on LSM9DS0 and LSM303D. * @open_drain: set the interrupt line to be open drain if possible. * @spi_3wire: enable spi-3wire mode. * @pullups: enable/disable i2c controller pullup resistors.
Signature · 1 line
2.39.2
PATCH v2 6/6 dt-bindings: iio: st-sensors: Add LSM303D accelerometer+magnetometer
In reply to Marius HochSame as the lsm9ds0, except that the lsm303d doesn't feature a gyroscope.
--- Documentation/devicetree/bindings/iio/st,st-sensors.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/st,st-sensors.yaml +1 -0
@@ -85,6 +85,7 @@ properties: - description: IMUs enum: - st,lsm9ds0-imu + - st,lsm303d-imu - description: Deprecated bindings enum: - st,lis302dl-spi
Signature · 1 line
2.39.2
Re: [PATCH v2 6/6] dt-bindings: iio: st-sensors: Add LSM303D accelerometer+magnetometer
Quoted 4 lines · Marius Hoch
Same as the lsm9ds0, except that the lsm303d doesn't feature a gyroscope.
Signed-off-by Marius Hoch <[email protected]>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Best regards,
Krzysztof
Jonathan Cameron
maintainerRe: [PATCH v2 6/6] dt-bindings: iio: st-sensors: Add LSM303D accelerometer+magnetometer
Quoted 10 lines · On Thu, 13 Apr 2023 10:07:04 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 4 lines · Marius Hoch
Same as the lsm9ds0, except that the lsm303d doesn't feature a gyroscope.
Signed-off-by Marius Hoch <[email protected]>Please use
scripts/get_maintainers.plto get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Just to avoid any confusion. Point here is that the dt-binding maintainers and list should be cc'd on series that touch bindings.
Jonathan
Quoted 4 lines
Best regards,
Krzysztof
Re: [PATCH v2 6/6] dt-bindings: iio: st-sensors: Add LSM303D accelerometer+magnetometer
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Thu, 13 Apr 2023 10:07:04 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 4 lines · Marius Hoch
Same as the lsm9ds0, except that the lsm303d doesn't feature a gyroscope.
Signed-off-by Marius Hoch <[email protected]>
Quoted 8 lines
Quoted 4 lines
Please use
scripts/get_maintainers.plto get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.Just to avoid any confusion. Point here is that the dt-binding maintainers and list should be cc'd on series that touch bindings.
Jonathan
Thank you for your replies. Not sure what went wrong here initially, I probably only ran get_maintainer.pl on some of the patches.
For v3 I used a complete and up to date list of recipients.
Cheers,
Marius
Quoted 4 lines
Quoted 4 lines
Best regards,
Krzysztof
Re: [PATCH v2 6/6] dt-bindings: iio: st-sensors: Add LSM303D accelerometer+magnetometer
In reply to Jonathan CameronQuoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Thu, 13 Apr 2023 10:07:04 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 4 lines · Marius Hoch
Same as the lsm9ds0, except that the lsm303d doesn't feature a gyroscope.
Signed-off-by Marius Hoch <[email protected]>
Quoted 8 lines
Quoted 4 lines
Please use
scripts/get_maintainers.plto get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.Just to avoid any confusion. Point here is that the dt-binding maintainers and list should be cc'd on series that touch bindings.
Maybe not only there, maybe more people were missed.
Best regards,
Krzysztof