The current repository contains a collection of Linux kernel device drivers for our MEMS sensors using input API, which has become obsolete. The kernel support for sensors has evolved and an improved solution for kernel integration of MEMS sensors is provided by IIO API. Due to intrinsic limitations of the input framework, the drivers here contained are therefore limited in terms of performance and only the basic hardware embedded features of the MEMS sensors are supported. STMicroelectronics provides full support for our MEMS sensors through a complete suite of Linux Device Drivers (LDD) leveraging on the IIO API/framework made available on GitHub:
https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio/
We strongly encourage and recommend that users upgrade to the suite of IIO drivers when integrating our sensors in Linux kernel. These upgrades are especially important for our most recent devices and for targets expected to run Android distributions.
The current repository supports the simpler and/or old designs for pure Linux. The designs for the latest Android versions are supposed to fail their Android CTS tests for sensors due to tightening requirements impacting high-speed data read and use of buffers/FIFO.
This repository contains STMicroelectronics MEMS sensors for Linux/Android kernels leveraging on Input framework.
The repository currently contains drivers supporting the following Longterm Support (LTS) Kernel releases defined as for "The Linux Kernel Archives", see Longterm Kernel releases:
- 4.4
- 4.9
- 4.14
- 4.19
- 5.4
- 5.10
- 5.15
- 6.1
- 6.6
- 6.12
STM sensor drivers are located under the directory drivers/input/misc/st organized in folders by sensor type:
LSM330, LSM330DLC, LSM6DS0, LSM6DS3, LSM6DSL, LSM6DSM, LSM9DS0, LSM9DS1, ISM330DLC, ASM330LHH, LSM6DSO, LSM6DSO32, LSM6DSOX, LSM6DSO32X, LSM6DSR, ISM330DHCX
LSM303AGR, LSM303AH, LSM303C, LSM303D, LSM303DLHC, ISM303DAC
AIS2DW12, AIS2IH, AIS328DQ, AIS3624DQ, H3LIS100DL, H3LIS331DL, LIS2DE, LIS2DE12, LIS2DH, LIS2DH12, LIS2DS12, LIS2HH12, LIS331DLH, LIS331HH, LIS3DE, LIS3DH, LIS3DSH, LIS2DW12, LIS3DHH, IIS3DHHC, IIS2DH
A3G4250D, L3G4200D, L3GD20, L3GD20H
LIS3MDL, LIS2MDL, IIS2MDC
HTS221
LPS22CH, LPS22HB, LPS22HD, LPS22HH, LPS22DF, LPS25H, LPS25HB, LPS27HHW, LPS27HHTW, LPS33HW, LPS35HW
UVIS25
STTS751, STTS22H
Data collected by STM sensors are pushed from kernel-space to user-space through the Linux kernel Input framework using EV_MSC events. User space applications can get sensor events by reading the related input device created in the /dev directory. Please see Input for more information.
All STM MEMS sensors support I2C/SPI digital interface. Please refer to I2C and SPI for detailed documentation.
Important
In-tree integration risk (merge/rebase with kernel source):
This repository also contains top-level project files (for example README.md and LICENSE.txt).
When integrating with the kernel tree using merge/rebase, a conflict on README.md may occur because some kernel trees already provide their own top-level README.md.
The operation may also introduce a new LICENSE.txt file that refers to this ST project repository ONLY and IS NOT meant to be the full Linux kernel licensing files.
Please review and resolve accordingly these files explicitly during conflict resolution and merging rebase operations.
From your kernel source code root directory add the git remote (i.e. stmems_input_github) for this repository:
git remote add stmems_input_github \
https://github.com/STMicroelectronics/st-mems-android-linux-drivers-input.gitFetch the just added remote:
git fetch stmems_input_githubThere are now two ways you may choose for integrating the drivers code into your kernel target branch:
- merge (suggested strategy)
- rebase
Merge the remote branch stmems_input_github/master with your target kernel source branch (i.e branch linux-4.19.y):
git merge --allow-unrelated-histories \
linux-4.19.y \
stmems_input_github/masterRebase the remote branch stmems_input_github/master on top of your target kernel source branch (i.e branch linux-4.19.y):
git rebase --no-fork-point \
linux-4.19.y \
stmems_input_github/masterNote: older git versions (i.e.: 2.7.4) would require to use sligthly different options:
git merge --no-fork-point \
linux-4.19.y \
stmems_input_github/mastergit rebase -Xno-renames \
--no-fork-point \
linux-4.19.y \
stmems_input_github/masterNow that drivers code has been added to the target kernel branch, few patches needs to be added in order to add STM drivers into Kconfig & Makefile systems
Apply the patches available in the just added repository selecting the proper kernel release directory (i.e for branch linux-4.19.y):
git am stm_input_patches/4.19.y/*-stm-*.patchSupported LTS kernel versions have patches for enabling their build system in directory:
stm_input_patches/<K.[X]X>.y/
where K stands for VERSION and [X]X for PATCHLEVEL according to kernel Makefile.
On the opposite, directories identified with suffix .WIP:
stm_input_patches/<K.[X]X>.y.WIP/
are for LTS kernel version whose support is WIP, hence using the above described procedure for enabling their build system and building them is premature and may result in errors.
A folder named stm_input_configs is provided containing the default configs for the supported drivers. Following are two proposed alternative ways (beside the traditional ones) for enabling configurations.
common_defconfig is mandatory for enabling STM MEMS Sensors drivers' configuration.
Sensors defconfig can be appended to the board defconfig (i.e. if your current configuration file is arch/arm/configs/stm32_defconfig):
cat stm_input_configs/common_defconfig >> all_sensors_defconfig
cat stm_input_configs/accel_defconfig >> all_sensors_defconfig
cat all_sensors_defconfig >> arch/arm/configs/stm32_defconfigAlternatively, it can be done at build time without altering the board config file, as follow.
Driver config can be merged into current target pre-configured kernel using a script available in the kernel itself:
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnu-
cat stm_input_configs/common_defconfig >> ./all_sensors_defconfig
cat stm_input_configs/imus_defconfig >> ./all_sensors_defconfig
scripts/kconfig/merge_config.sh -n .config ./all_sensors_defconfigConfigure kernel with make menuconfig (alternatively use make xconfig or make qconfig).
In order to explain how to integrate STM sensors in a different kernel, please consider the following LSM6DSM IMU example
Device Drivers ---> Input device support ---> [*] Miscellaneous devices ---> <*> STM MEMs Device Drivers ---> <M> Inertial motion unit ---> <M> STMicroelectronics LSM6DSM sensor
Documentation Device Tree Bindings are published under: Documentation/devicetree/bindings/input
To enable driver probing, add the lsm6dsm node to the platform device tree as described below.
Required properties:
- compatible: "st,lsm6dsm"
- reg: the I2C address or SPI chip select the device will respond to
- interrupt-parent: phandle to the parent interrupt controller as documented in interrupts
- interrupts: interrupt mapping for IRQ as documented in interrupts
Recommended properties for SPI bus usage:
- spi-max-frequency: maximum SPI bus frequency as documented in SPI
Optional properties:
- st,drdy-int-pin: MEMS sensor interrupt line to use (default 1)
I2C example (based on Raspberry PI 3):
&i2c0 { status = "ok"; #address-cells = <0x1>; #size-cells = <0x0>; lsm6dsm@6b { compatible = "st,lsm6dsm"; reg = <0x6b>; interrupt-parent = <&gpio>; interrupts = <26 IRQ_TYPE_EDGE_RISING>; };
SPI example (based on Raspberry PI 3):
&spi0 { status = "ok"; #address-cells = <0x1>; #size-cells = <0x0>; lsm6dsm@0 { spi-max-frequency = <500000>; compatible = "st,lsm6dsm"; reg = <0>; interrupt-parent = <&gpio>; interrupts = <26 IRQ_TYPE_EDGE_RISING>; };
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/input
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/i2c
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/spi
This software is distributed under the GNU General Public License v2.0
The project is released under GPLv2 to remain fully compatible with the Linux kernel licensing model and with in-tree kernel integration workflows. This choice also aligns the driver sources with the broader kernel driver ecosystem, where derivative works and redistributed binaries are expected to preserve source availability under the same copyleft terms.
Note: the repository LICENSE.txt file is project-specific metadata for this ST driver package and is not a replacement for Linux kernel licensing documentation.
Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026 STMicroelectronics