aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: f99d2870e587c0dd8baaa437c8418737c9392b7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Index
=======
	* Introduction
	* Integration details
	* More information
	* Copyright


Introduction
==============
This repository contains Linux kernel v3.18 with STMicroelectronics MEMS sensor support. STM sensor drivers are located under the directory [drivers/iio](https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/tree/linux-3.18-gh/drivers/iio)  organized by sensor type:

### Inertial Module Unit (IMU):

> LSM6DS3, LSM6DS3H, LSM6DSL, LSM6DSM, LSM9DS0, LSM9DS1, ISM330DLC, LSM6DSO, ASM330LHH, LSM6DSR

### 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

### 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



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][1] for more information.

All STM MEMS sensors support *I2C/SPI* digital interface. Please refer to [I2C][2] and [SPI][3] 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 3.18):

>         @@ -68,6 +76,7 @@ enum iio_event_type {
>                 IIO_EV_TYPE_ROC,
>                 IIO_EV_TYPE_THRESH_ADAPTIVE,
>                 IIO_EV_TYPE_MAG_ADAPTIVE,
>         +       IIO_EV_TYPE_FIFO_FLUSH,
>         };
>
>         @@ -81,6 +90,8 @@ enum iio_event_direction {
>                 IIO_EV_DIR_EITHER,
>                 IIO_EV_DIR_RISING,
>                 IIO_EV_DIR_FALLING,
>         +       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 3.18):

>         @@ -30,6 +30,14 @@ enum iio_chan_type {
>                 IIO_CCT,
>                 IIO_PRESSURE,
>                 IIO_HUMIDITYRELATIVE,
>         +       IIO_SIGN_MOTION,
>         +       IIO_STEP_DETECTOR,
>         +       IIO_STEP_COUNTER,
>         +       IIO_TILT,
>         +       IIO_TAP,
>         +       IIO_TAP_TAP,
>         +       IIO_WRIST_TILT_GESTURE,
>         +       IIO_GESTURE,
>         };

### 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][4]

> *- interrupts*: interrupt mapping for IRQ as documented in [interrupts][4]
>
>**Recommended properties for SPI bus usage:**

> *- spi-max-frequency*: maximum SPI bus frequency as documented in [SPI][3]
>
> **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](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/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/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/spi)

[https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bings/interrupt-controller/interrupts.txt](https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/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.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/iio/iio_configfs.txt "IIO"
[2]: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/i2c "I2C"
[3]: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/spi "SPI"
[4]: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt "interrupts"