Skip to content

DISCONTINUED (October 2022): the maintenance for this repository has been discontinued. Please refer to https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio for the up-to-date drivers repository. This repository contains Linux Kernel (v3.10, v3.14, v3.18, v4.9, v4.14, v4.19) including STMicroelectronics MEMS IIO sensor support

License

Notifications You must be signed in to change notification settings

STMicroelectronics/STMems_Linux_IIO_drivers

Repository files navigation

Important Notice

DISCONTINUED (October 2022): the maintenance for this repository has been discontinued.

Please refer to:

https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio

for the up-to-date drivers repository.

Index

* Introduction
* Integration details
* More information
* Copyright

Introduction

This repository contains Linux kernel v4.4 with STMicroelectronics MEMS sensor support. STM sensor drivers are located under the directory drivers/iio organized by sensor type:

Inertial Module Unit (IMU):

LSM6DS3, LSM6DS3H, LSM6DSL, LSM6DSM, LSM9DS0, LSM9DS1, ISM330DLC, LSM6DSO, ASM330LHH, LSM6DSR, ISM330DHCX, LSM6DSO32, LSM6DSOX, LSM6DSRX, LSM6DSO32X, ASM330LHHX

Accelerometer:

LIS2DH, LIS2DH12, LIS3DH, LIS2DG, LSM303AH, LIS2DS12, LIS2HH12, LIS2DW12, LIS3LV02DL, LSM303DLH, LSM303DLHC, LSM330D, LSM330DL, LSM330DLC, LIS331DL, LIS331DLH, LSM303DL, LSM303DLM, LSM330, LSM303AGR, LIS3DHH, IIS2DH, ISM303DAC, IIS3DHHC, IIS2DLPC, AIS2IH

Gyroscope:

L3G4200D, LSM330D, LSM330DL, L3GD20, L3GD20H, L3G4IS, LSM330, LSM330DLC

Magnetometer:

LIS3MDL, LSM9DS1, LSM303AH, LSM303AGR, LSM303DLH, LSM303DLHC, LSM303DLM, LIS2MDL, IIS2MDC, ISM303DAC

Humidity:

HTS221

Pressure:

LPS22HB, LPS22HD, LPS25H, LPS331AP, LPS001WP, LPS33HW, LPS35HW, LPS22HH, LPS27HHW, LPS22DF

Temperature

STTS22H

Data collected by STM sensors are pushed to userland through the kernel buffers of Linux IIO framework. User space applications can get sensor events by reading the related IIO devices created in the /dev directory (/dev/iio{x}). Please see IIO for more information.

All STM MEMS sensors support I2C/SPI digital interface. Please refer to I2C and SPI for detailed documentation.

Integration details

In order to explain how to integrate STM sensors in a different kernel, please consider the following LSM6DSM IMU example

Source code integration

  • Copy driver source code into the target directory (e.g. drivers/iio/imu)
  • Edit related Kconfig (e.g. drivers/iio/imu/Kconfig) to include LSM6DSM support:
    source "drivers/iio/imu/st_lsm6dsm/Kconfig"
  • Edit related Makefile (e.g. drivers/iio/imu/Makefile) adding the following line:
    obj-y += lsm6dsm/
  • Add custom events into include/uapi/linux/iio/types.h (follow a sample patch for kernel 4.4):
    @@ -85,6 +93,7 @@ enum iio_event_type {
              IIO_EV_TYPE_THRESH_ADAPTIVE,
              IIO_EV_TYPE_MAG_ADAPTIVE,
              IIO_EV_TYPE_CHANGE,
    +         IIO_EV_TYPE_FIFO_FLUSH,
    };

    @@ -92,6 +101,8 @@ enum iio_event_direction {
              IIO_EV_DIR_RISING,
              IIO_EV_DIR_FALLING,
              IIO_EV_DIR_NONE,
    +         IIO_EV_DIR_FIFO_EMPTY,
    +         IIO_EV_DIR_FIFO_DATA,
    };
  • Add custom channel types include/uapi/linux/iio/types.h depending on the custom sensor implemented into driver (follow a sample patch for kernel 4.4):
     @@ -37,6 +37,14 @@ enum iio_chan_type {
              IIO_VELOCITY,
              IIO_CONCENTRATION,
              IIO_RESISTANCE,
    +         IIO_SIGN_MOTION,
    +         IIO_STEP_DETECTOR,
    +         IIO_STEP_COUNTER,
    +         IIO_TILT,
    +         IIO_TAP,
    +         IIO_TAP_TAP,
    +         IIO_WRIST_TILT_GESTURE,
    +         IIO_GESTURE,
    +         IIO_WKUP,
    +         IIO_FREE_FALL,
    };

Device Tree configuration

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)

Device Tree Integration Examples

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_LEVEL_HIGH>;
  };

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_LEVEL_HIGH>;
  	};

Kernel configuration

Configure kernel with make menuconfig (alternatively use make xconfig or make qconfig)

  Device Drivers  --->
  	<M> Industrial I/O support  --->
  		Inertial measurement units  --->
  		<M>   STMicroelectronics LSM6DSM/LSM6DSL sensor  --->

More Information

http://st.com

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/iio

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

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bings/interrupt-controller/interrupts.txt

Copyright

Copyright (C) 2019 STMicroelectronics

This software is distributed under the GNU General Public License - see the accompanying COPYING file for more details.

About

DISCONTINUED (October 2022): the maintenance for this repository has been discontinued. Please refer to https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio for the up-to-date drivers repository. This repository contains Linux Kernel (v3.10, v3.14, v3.18, v4.9, v4.14, v4.19) including STMicroelectronics MEMS IIO sensor support

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published