aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/iio/accel/st_accel_i2c.c51
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_i2c.c30
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c39
-rw-r--r--drivers/iio/magnetometer/st_magn_i2c.c23
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c23
-rw-r--r--include/linux/iio/common/st_sensors_i2c.h11
6 files changed, 177 insertions, 0 deletions
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index d7bedbdfc81d..7164aeff3ab1 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -18,6 +18,55 @@
18#include <linux/iio/common/st_sensors_i2c.h> 18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_accel.h" 19#include "st_accel.h"
20 20
21#ifdef CONFIG_OF
22static const struct of_device_id st_accel_of_match[] = {
23 {
24 .compatible = "st,lsm303dlh-accel",
25 .data = LSM303DLH_ACCEL_DEV_NAME,
26 },
27 {
28 .compatible = "st,lsm303dlhc-accel",
29 .data = LSM303DLHC_ACCEL_DEV_NAME,
30 },
31 {
32 .compatible = "st,lis3dh-accel",
33 .data = LIS3DH_ACCEL_DEV_NAME,
34 },
35 {
36 .compatible = "st,lsm330d-accel",
37 .data = LSM330D_ACCEL_DEV_NAME,
38 },
39 {
40 .compatible = "st,lsm330dl-accel",
41 .data = LSM330DL_ACCEL_DEV_NAME,
42 },
43 {
44 .compatible = "st,lsm330dlc-accel",
45 .data = LSM330DLC_ACCEL_DEV_NAME,
46 },
47 {
48 .compatible = "st,lis331dlh-accel",
49 .data = LIS331DLH_ACCEL_DEV_NAME,
50 },
51 {
52 .compatible = "st,lsm303dl-accel",
53 .data = LSM303DL_ACCEL_DEV_NAME,
54 },
55 {
56 .compatible = "st,lsm303dlm-accel",
57 .data = LSM303DLM_ACCEL_DEV_NAME,
58 },
59 {
60 .compatible = "st,lsm330-accel",
61 .data = LSM330_ACCEL_DEV_NAME,
62 },
63 {},
64};
65MODULE_DEVICE_TABLE(of, st_accel_of_match);
66#else
67#define st_accel_of_match NULL
68#endif
69
21static int st_accel_i2c_probe(struct i2c_client *client, 70static int st_accel_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id) 71 const struct i2c_device_id *id)
23{ 72{
@@ -31,6 +80,7 @@ static int st_accel_i2c_probe(struct i2c_client *client,
31 80
32 adata = iio_priv(indio_dev); 81 adata = iio_priv(indio_dev);
33 adata->dev = &client->dev; 82 adata->dev = &client->dev;
83 st_sensors_of_i2c_probe(client, st_accel_of_match);
34 84
35 st_sensors_i2c_configure(indio_dev, client, adata); 85 st_sensors_i2c_configure(indio_dev, client, adata);
36 86
@@ -67,6 +117,7 @@ static struct i2c_driver st_accel_driver = {
67 .driver = { 117 .driver = {
68 .owner = THIS_MODULE, 118 .owner = THIS_MODULE,
69 .name = "st-accel-i2c", 119 .name = "st-accel-i2c",
120 .of_match_table = of_match_ptr(st_accel_of_match),
70 }, 121 },
71 .probe = st_accel_i2c_probe, 122 .probe = st_accel_i2c_probe,
72 .remove = st_accel_i2c_remove, 123 .remove = st_accel_i2c_remove,
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
index 38af9440c103..bb6f3085f57b 100644
--- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -12,6 +12,7 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/iio/iio.h> 14#include <linux/iio/iio.h>
15#include <linux/of_device.h>
15 16
16#include <linux/iio/common/st_sensors_i2c.h> 17#include <linux/iio/common/st_sensors_i2c.h>
17 18
@@ -76,6 +77,35 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev,
76} 77}
77EXPORT_SYMBOL(st_sensors_i2c_configure); 78EXPORT_SYMBOL(st_sensors_i2c_configure);
78 79
80#ifdef CONFIG_OF
81/**
82 * st_sensors_of_i2c_probe() - device tree probe for ST I2C sensors
83 * @client: the I2C client device for the sensor
84 * @match: the OF match table for the device, containing compatible strings
85 * but also a .data field with the corresponding internal kernel name
86 * used by this sensor.
87 *
88 * In effect this function matches a compatible string to an internal kernel
89 * name for a certain sensor device, so that the rest of the autodetection can
90 * rely on that name from this point on. I2C client devices will be renamed
91 * to match the internal kernel convention.
92 */
93void st_sensors_of_i2c_probe(struct i2c_client *client,
94 const struct of_device_id *match)
95{
96 const struct of_device_id *of_id;
97
98 of_id = of_match_device(match, &client->dev);
99 if (!of_id)
100 return;
101
102 /* The name from the OF match takes precedence if present */
103 strncpy(client->name, of_id->data, sizeof(client->name));
104 client->name[sizeof(client->name) - 1] = '\0';
105}
106EXPORT_SYMBOL(st_sensors_of_i2c_probe);
107#endif
108
79MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 109MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
80MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver"); 110MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
81MODULE_LICENSE("GPL v2"); 111MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 23c12f361b05..8fa0ad2ef4ef 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -18,6 +18,43 @@
18#include <linux/iio/common/st_sensors_i2c.h> 18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_gyro.h" 19#include "st_gyro.h"
20 20
21#ifdef CONFIG_OF
22static const struct of_device_id st_gyro_of_match[] = {
23 {
24 .compatible = "st,l3g4200d-gyro",
25 .data = L3G4200D_GYRO_DEV_NAME,
26 },
27 {
28 .compatible = "st,lsm330d-gyro",
29 .data = LSM330D_GYRO_DEV_NAME,
30 },
31 {
32 .compatible = "st,lsm330dl-gyro",
33 .data = LSM330DL_GYRO_DEV_NAME,
34 },
35 {
36 .compatible = "st,lsm330dlc-gyro",
37 .data = LSM330DLC_GYRO_DEV_NAME,
38 },
39 {
40 .compatible = "st,l3gd20-gyro",
41 .data = L3GD20_GYRO_DEV_NAME,
42 },
43 {
44 .compatible = "st,l3g4is-gyro",
45 .data = L3G4IS_GYRO_DEV_NAME,
46 },
47 {
48 .compatible = "st,lsm330-gyro",
49 .data = LSM330_GYRO_DEV_NAME,
50 },
51 {},
52};
53MODULE_DEVICE_TABLE(of, st_gyro_of_match);
54#else
55#define st_gyro_of_match NULL
56#endif
57
21static int st_gyro_i2c_probe(struct i2c_client *client, 58static int st_gyro_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id) 59 const struct i2c_device_id *id)
23{ 60{
@@ -31,6 +68,7 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
31 68
32 gdata = iio_priv(indio_dev); 69 gdata = iio_priv(indio_dev);
33 gdata->dev = &client->dev; 70 gdata->dev = &client->dev;
71 st_sensors_of_i2c_probe(client, st_gyro_of_match);
34 72
35 st_sensors_i2c_configure(indio_dev, client, gdata); 73 st_sensors_i2c_configure(indio_dev, client, gdata);
36 74
@@ -65,6 +103,7 @@ static struct i2c_driver st_gyro_driver = {
65 .driver = { 103 .driver = {
66 .owner = THIS_MODULE, 104 .owner = THIS_MODULE,
67 .name = "st-gyro-i2c", 105 .name = "st-gyro-i2c",
106 .of_match_table = of_match_ptr(st_gyro_of_match),
68 }, 107 },
69 .probe = st_gyro_i2c_probe, 108 .probe = st_gyro_i2c_probe,
70 .remove = st_gyro_i2c_remove, 109 .remove = st_gyro_i2c_remove,
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 892e0feeb5c1..689250058442 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -18,6 +18,27 @@
18#include <linux/iio/common/st_sensors_i2c.h> 18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_magn.h" 19#include "st_magn.h"
20 20
21#ifdef CONFIG_OF
22static const struct of_device_id st_magn_of_match[] = {
23 {
24 .compatible = "st,lsm303dlhc-magn",
25 .data = LSM303DLHC_MAGN_DEV_NAME,
26 },
27 {
28 .compatible = "st,lsm303dlm-magn",
29 .data = LSM303DLM_MAGN_DEV_NAME,
30 },
31 {
32 .compatible = "st,lis3mdl-magn",
33 .data = LIS3MDL_MAGN_DEV_NAME,
34 },
35 {},
36};
37MODULE_DEVICE_TABLE(of, st_magn_of_match);
38#else
39#define st_magn_of_match NULL
40#endif
41
21static int st_magn_i2c_probe(struct i2c_client *client, 42static int st_magn_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id) 43 const struct i2c_device_id *id)
23{ 44{
@@ -31,6 +52,7 @@ static int st_magn_i2c_probe(struct i2c_client *client,
31 52
32 mdata = iio_priv(indio_dev); 53 mdata = iio_priv(indio_dev);
33 mdata->dev = &client->dev; 54 mdata->dev = &client->dev;
55 st_sensors_of_i2c_probe(client, st_magn_of_match);
34 56
35 st_sensors_i2c_configure(indio_dev, client, mdata); 57 st_sensors_i2c_configure(indio_dev, client, mdata);
36 58
@@ -61,6 +83,7 @@ static struct i2c_driver st_magn_driver = {
61 .driver = { 83 .driver = {
62 .owner = THIS_MODULE, 84 .owner = THIS_MODULE,
63 .name = "st-magn-i2c", 85 .name = "st-magn-i2c",
86 .of_match_table = of_match_ptr(st_magn_of_match),
64 }, 87 },
65 .probe = st_magn_i2c_probe, 88 .probe = st_magn_i2c_probe,
66 .remove = st_magn_i2c_remove, 89 .remove = st_magn_i2c_remove,
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index 3cd73e39b840..acaf165260bb 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -18,6 +18,27 @@
18#include <linux/iio/common/st_sensors_i2c.h> 18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_pressure.h" 19#include "st_pressure.h"
20 20
21#ifdef CONFIG_OF
22static const struct of_device_id st_press_of_match[] = {
23 {
24 .compatible = "st,lps001wp-press",
25 .data = LPS001WP_PRESS_DEV_NAME,
26 },
27 {
28 .compatible = "st,lps25h-press",
29 .data = LPS25H_PRESS_DEV_NAME,
30 },
31 {
32 .compatible = "st,lps331ap-press",
33 .data = LPS331AP_PRESS_DEV_NAME,
34 },
35 {},
36};
37MODULE_DEVICE_TABLE(of, st_press_of_match);
38#else
39#define st_press_of_match NULL
40#endif
41
21static int st_press_i2c_probe(struct i2c_client *client, 42static int st_press_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id) 43 const struct i2c_device_id *id)
23{ 44{
@@ -31,6 +52,7 @@ static int st_press_i2c_probe(struct i2c_client *client,
31 52
32 pdata = iio_priv(indio_dev); 53 pdata = iio_priv(indio_dev);
33 pdata->dev = &client->dev; 54 pdata->dev = &client->dev;
55 st_sensors_of_i2c_probe(client, st_press_of_match);
34 56
35 st_sensors_i2c_configure(indio_dev, client, pdata); 57 st_sensors_i2c_configure(indio_dev, client, pdata);
36 58
@@ -60,6 +82,7 @@ static struct i2c_driver st_press_driver = {
60 .driver = { 82 .driver = {
61 .owner = THIS_MODULE, 83 .owner = THIS_MODULE,
62 .name = "st-press-i2c", 84 .name = "st-press-i2c",
85 .of_match_table = of_match_ptr(st_press_of_match),
63 }, 86 },
64 .probe = st_press_i2c_probe, 87 .probe = st_press_i2c_probe,
65 .remove = st_press_i2c_remove, 88 .remove = st_press_i2c_remove,
diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h
index 67d845385ae2..1796af093368 100644
--- a/include/linux/iio/common/st_sensors_i2c.h
+++ b/include/linux/iio/common/st_sensors_i2c.h
@@ -13,8 +13,19 @@
13 13
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/iio/common/st_sensors.h> 15#include <linux/iio/common/st_sensors.h>
16#include <linux/of.h>
16 17
17void st_sensors_i2c_configure(struct iio_dev *indio_dev, 18void st_sensors_i2c_configure(struct iio_dev *indio_dev,
18 struct i2c_client *client, struct st_sensor_data *sdata); 19 struct i2c_client *client, struct st_sensor_data *sdata);
19 20
21#ifdef CONFIG_OF
22void st_sensors_of_i2c_probe(struct i2c_client *client,
23 const struct of_device_id *match);
24#else
25static inline void st_sensors_of_i2c_probe(struct i2c_client *client,
26 const struct of_device_id *match)
27{
28}
29#endif
30
20#endif /* ST_SENSORS_I2C_H */ 31#endif /* ST_SENSORS_I2C_H */