2023-04-12 22:38:53

by Marius Hoch

[permalink] [raw]
Subject: [PATCH] iio: st_sensors: Add lsm303d support

From: Marius Hoch <[email protected]>

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(-)

--
2.39.2


2023-04-12 22:38:59

by Marius Hoch

[permalink] [raw]
Subject: [PATCH] iio: magnetometer: st_accel: Add LSM303D

From: Marius Hoch <[email protected]>

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.

Signed-off-by: Marius Hoch <[email protected]>
---
drivers/iio/magnetometer/st_magn_core.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 8faa7409d9e1..6cc0dfd31821 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -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 = {
--
2.39.2

2023-04-12 22:39:49

by Marius Hoch

[permalink] [raw]
Subject: [PATCH] iio: st_sensors: Add lsm303d support to the LSM9DS0 IMU driver

From: Marius Hoch <[email protected]>

The lsm303d is basically the lsm9ds0 without the gyroscope
(which the LSM9DS0 IMU driver doesn't handle), as far as I
can tell.

Signed-off-by: Marius Hoch <[email protected]>
---
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(-)

diff --git a/drivers/iio/imu/st_lsm9ds0/Kconfig b/drivers/iio/imu/st_lsm9ds0/Kconfig
index d29558edee60..7aef714b6ecb 100644
--- a/drivers/iio/imu/st_lsm9ds0/Kconfig
+++ b/drivers/iio/imu/st_lsm9ds0/Kconfig
@@ -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.
diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
index a90138d8b06a..64fa77d302e2 100644
--- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
+++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
@@ -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);
diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
index b743bf3546a7..997b5ff792be 100644
--- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
+++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
@@ -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);
--
2.39.2

2023-04-12 22:40:14

by Marius Hoch

[permalink] [raw]
Subject: [PATCH] iio: Comment that the LSM303D also has the Magnetometer DRDY

From: Marius Hoch <[email protected]>

Per its datasheet, the LSM303D also features that
pin.

Signed-off-by: Marius Hoch <[email protected]>
---
include/linux/platform_data/st_sensors_pdata.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/platform_data/st_sensors_pdata.h b/include/linux/platform_data/st_sensors_pdata.h
index 897051e51b78..a657830232ae 100644
--- a/include/linux/platform_data/st_sensors_pdata.h
+++ b/include/linux/platform_data/st_sensors_pdata.h
@@ -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.
--
2.39.2

2023-04-12 22:40:30

by Marius Hoch

[permalink] [raw]
Subject: [PATCH] iio: st_sensors: Add ACPI support for lsm303d to the LSM9DS0 IMU driver

From: Marius Hoch <[email protected]>

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(+)

diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
index 64fa77d302e2..79be8d28d965 100644
--- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
+++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c
@@ -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,
diff --git a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
index 997b5ff792be..27c5d99ce0e3 100644
--- a/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
+++ b/drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c
@@ -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,
--
2.39.2

2023-04-12 22:40:56

by Marius Hoch

[permalink] [raw]
Subject: [PATCH] dt-bindings: iio: st-sensors: Add LSM303D accelerometer+magnetometer

From: Marius Hoch <[email protected]>

Same as the lsm9ds0, except that the lsm303d doesn't
feature a gyroscope.

Signed-off-by: Marius Hoch <[email protected]>
---
Documentation/devicetree/bindings/iio/st,st-sensors.yaml | 1 +
1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iio/st,st-sensors.yaml b/Documentation/devicetree/bindings/iio/st,st-sensors.yaml
index c6201976378f..194aca5542c2 100644
--- a/Documentation/devicetree/bindings/iio/st,st-sensors.yaml
+++ b/Documentation/devicetree/bindings/iio/st,st-sensors.yaml
@@ -85,6 +85,7 @@ properties:
- description: IMUs
enum:
- st,lsm9ds0-imu
+ - st,lsm303d-imu
- description: Deprecated bindings
enum:
- st,lis302dl-spi
--
2.39.2

2023-04-13 00:38:35

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] iio: st_sensors: Add ACPI support for lsm303d to the LSM9DS0 IMU driver

Hi,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on linus/master v6.3-rc6 next-20230412]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/mail-mariushoch-de/iio-st_sensors-Add-ACPI-support-for-lsm303d-to-the-LSM9DS0-IMU-driver/20230413-064417
base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link: https://lore.kernel.org/r/20230412223627.442963-5-mail%40mariushoch.de
patch subject: [PATCH] iio: st_sensors: Add ACPI support for lsm303d to the LSM9DS0 IMU driver
config: x86_64-allmodconfig (https://download.01.org/0day-ci/archive/20230413/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/ec35631841a31e357cf4f6781b4c8f78a468a4ef
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review mail-mariushoch-de/iio-st_sensors-Add-ACPI-support-for-lsm303d-to-the-LSM9DS0-IMU-driver/20230413-064417
git checkout ec35631841a31e357cf4f6781b4c8f78a468a4ef
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 olddefconfig
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/iio/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c:38:38: error: 'LSM303D_IMU_DEV_NAME' undeclared here (not in a function); did you mean 'LSM9DS0_IMU_DEV_NAME'?
38 | {"ACCL0001", (kernel_ulong_t)LSM303D_IMU_DEV_NAME},
| ^~~~~~~~~~~~~~~~~~~~
| LSM9DS0_IMU_DEV_NAME
--
>> drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_spi.c:38:38: error: 'LSM303D_IMU_DEV_NAME' undeclared here (not in a function); did you mean 'LSM9DS0_IMU_DEV_NAME'?
38 | {"ACCL0001", (kernel_ulong_t)LSM303D_IMU_DEV_NAME},
| ^~~~~~~~~~~~~~~~~~~~
| LSM9DS0_IMU_DEV_NAME


vim +38 drivers/iio/imu/st_lsm9ds0/st_lsm9ds0_i2c.c

35
36 #ifdef CONFIG_ACPI
37 static const struct acpi_device_id st_lsm9ds0_acpi_match[] = {
> 38 {"ACCL0001", (kernel_ulong_t)LSM303D_IMU_DEV_NAME},
39 { },
40 };
41 MODULE_DEVICE_TABLE(acpi, st_lsm9ds0_acpi_match);
42 #endif
43

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests