aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis CIOCCA <denis.ciocca@st.com>2013-06-19 04:28:00 -0400
committerJonathan Cameron <jic23@kernel.org>2013-08-03 13:40:28 -0400
commit23cde4d65cc7d11e2048d2b240cdf13927ac50d0 (patch)
tree3fd2d23f8c092056244e14703bce9842c203ba13
parent36e607a16b8def1b184d48a4489b716d6dbe3379 (diff)
iio: Added ST-sensors platform data to select the DRDY interrupt pin
This patch add support to redirect the DRDY interrupt on INT1 or INT2 on accelerometer and pressure sensors. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/accel/st_accel.h11
-rw-r--r--drivers/iio/accel/st_accel_core.c27
-rw-r--r--drivers/iio/accel/st_accel_i2c.c2
-rw-r--r--drivers/iio/accel/st_accel_spi.c2
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c41
-rw-r--r--drivers/iio/gyro/st_gyro.h11
-rw-r--r--drivers/iio/gyro/st_gyro_core.c13
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c3
-rw-r--r--drivers/iio/gyro/st_gyro_spi.c3
-rw-r--r--drivers/iio/magnetometer/st_magn.h3
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c5
-rw-r--r--drivers/iio/magnetometer/st_magn_i2c.c2
-rw-r--r--drivers/iio/magnetometer/st_magn_spi.c2
-rw-r--r--drivers/iio/pressure/st_pressure.h11
-rw-r--r--drivers/iio/pressure/st_pressure_core.c15
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c2
-rw-r--r--drivers/iio/pressure/st_pressure_spi.c2
-rw-r--r--include/linux/iio/common/st_sensors.h14
-rw-r--r--include/linux/platform_data/st_sensors_pdata.h24
19 files changed, 153 insertions, 40 deletions
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index 37949b94377d..c3877630b2e4 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -25,7 +25,16 @@
25#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel" 25#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel"
26#define LSM330_ACCEL_DEV_NAME "lsm330_accel" 26#define LSM330_ACCEL_DEV_NAME "lsm330_accel"
27 27
28int st_accel_common_probe(struct iio_dev *indio_dev); 28/**
29* struct st_sensors_platform_data - default accel platform data
30* @drdy_int_pin: default accel DRDY is available on INT1 pin.
31*/
32static const struct st_sensors_platform_data default_accel_pdata = {
33 .drdy_int_pin = 1,
34};
35
36int st_accel_common_probe(struct iio_dev *indio_dev,
37 struct st_sensors_platform_data *pdata);
29void st_accel_common_remove(struct iio_dev *indio_dev); 38void st_accel_common_remove(struct iio_dev *indio_dev);
30 39
31#ifdef CONFIG_IIO_BUFFER 40#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 4aec121261d7..aef3c9be7366 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -65,7 +65,8 @@
65#define ST_ACCEL_1_BDU_ADDR 0x23 65#define ST_ACCEL_1_BDU_ADDR 0x23
66#define ST_ACCEL_1_BDU_MASK 0x80 66#define ST_ACCEL_1_BDU_MASK 0x80
67#define ST_ACCEL_1_DRDY_IRQ_ADDR 0x22 67#define ST_ACCEL_1_DRDY_IRQ_ADDR 0x22
68#define ST_ACCEL_1_DRDY_IRQ_MASK 0x10 68#define ST_ACCEL_1_DRDY_IRQ_INT1_MASK 0x10
69#define ST_ACCEL_1_DRDY_IRQ_INT2_MASK 0x08
69#define ST_ACCEL_1_MULTIREAD_BIT true 70#define ST_ACCEL_1_MULTIREAD_BIT true
70 71
71/* CUSTOM VALUES FOR SENSOR 2 */ 72/* CUSTOM VALUES FOR SENSOR 2 */
@@ -89,7 +90,8 @@
89#define ST_ACCEL_2_BDU_ADDR 0x23 90#define ST_ACCEL_2_BDU_ADDR 0x23
90#define ST_ACCEL_2_BDU_MASK 0x80 91#define ST_ACCEL_2_BDU_MASK 0x80
91#define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22 92#define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22
92#define ST_ACCEL_2_DRDY_IRQ_MASK 0x02 93#define ST_ACCEL_2_DRDY_IRQ_INT1_MASK 0x02
94#define ST_ACCEL_2_DRDY_IRQ_INT2_MASK 0x10
93#define ST_ACCEL_2_MULTIREAD_BIT true 95#define ST_ACCEL_2_MULTIREAD_BIT true
94 96
95/* CUSTOM VALUES FOR SENSOR 3 */ 97/* CUSTOM VALUES FOR SENSOR 3 */
@@ -121,7 +123,8 @@
121#define ST_ACCEL_3_BDU_ADDR 0x20 123#define ST_ACCEL_3_BDU_ADDR 0x20
122#define ST_ACCEL_3_BDU_MASK 0x08 124#define ST_ACCEL_3_BDU_MASK 0x08
123#define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23 125#define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23
124#define ST_ACCEL_3_DRDY_IRQ_MASK 0x80 126#define ST_ACCEL_3_DRDY_IRQ_INT1_MASK 0x80
127#define ST_ACCEL_3_DRDY_IRQ_INT2_MASK 0x00
125#define ST_ACCEL_3_IG1_EN_ADDR 0x23 128#define ST_ACCEL_3_IG1_EN_ADDR 0x23
126#define ST_ACCEL_3_IG1_EN_MASK 0x08 129#define ST_ACCEL_3_IG1_EN_MASK 0x08
127#define ST_ACCEL_3_MULTIREAD_BIT false 130#define ST_ACCEL_3_MULTIREAD_BIT false
@@ -224,7 +227,8 @@ static const struct st_sensors st_accel_sensors[] = {
224 }, 227 },
225 .drdy_irq = { 228 .drdy_irq = {
226 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR, 229 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
227 .mask = ST_ACCEL_1_DRDY_IRQ_MASK, 230 .mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK,
231 .mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK,
228 }, 232 },
229 .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT, 233 .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,
230 .bootime = 2, 234 .bootime = 2,
@@ -285,7 +289,8 @@ static const struct st_sensors st_accel_sensors[] = {
285 }, 289 },
286 .drdy_irq = { 290 .drdy_irq = {
287 .addr = ST_ACCEL_2_DRDY_IRQ_ADDR, 291 .addr = ST_ACCEL_2_DRDY_IRQ_ADDR,
288 .mask = ST_ACCEL_2_DRDY_IRQ_MASK, 292 .mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK,
293 .mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK,
289 }, 294 },
290 .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT, 295 .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,
291 .bootime = 2, 296 .bootime = 2,
@@ -358,7 +363,8 @@ static const struct st_sensors st_accel_sensors[] = {
358 }, 363 },
359 .drdy_irq = { 364 .drdy_irq = {
360 .addr = ST_ACCEL_3_DRDY_IRQ_ADDR, 365 .addr = ST_ACCEL_3_DRDY_IRQ_ADDR,
361 .mask = ST_ACCEL_3_DRDY_IRQ_MASK, 366 .mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK,
367 .mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK,
362 .ig1 = { 368 .ig1 = {
363 .en_addr = ST_ACCEL_3_IG1_EN_ADDR, 369 .en_addr = ST_ACCEL_3_IG1_EN_ADDR,
364 .en_mask = ST_ACCEL_3_IG1_EN_MASK, 370 .en_mask = ST_ACCEL_3_IG1_EN_MASK,
@@ -443,7 +449,8 @@ static const struct iio_trigger_ops st_accel_trigger_ops = {
443#define ST_ACCEL_TRIGGER_OPS NULL 449#define ST_ACCEL_TRIGGER_OPS NULL
444#endif 450#endif
445 451
446int st_accel_common_probe(struct iio_dev *indio_dev) 452int st_accel_common_probe(struct iio_dev *indio_dev,
453 struct st_sensors_platform_data *plat_data)
447{ 454{
448 int err; 455 int err;
449 struct st_sensor_data *adata = iio_priv(indio_dev); 456 struct st_sensor_data *adata = iio_priv(indio_dev);
@@ -465,7 +472,11 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
465 &adata->sensor->fs.fs_avl[0]; 472 &adata->sensor->fs.fs_avl[0];
466 adata->odr = adata->sensor->odr.odr_avl[0].hz; 473 adata->odr = adata->sensor->odr.odr_avl[0].hz;
467 474
468 err = st_sensors_init_sensor(indio_dev); 475 if (!plat_data)
476 plat_data =
477 (struct st_sensors_platform_data *)&default_accel_pdata;
478
479 err = st_sensors_init_sensor(indio_dev, plat_data);
469 if (err < 0) 480 if (err < 0)
470 goto st_accel_common_probe_error; 481 goto st_accel_common_probe_error;
471 482
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index ffc9d097e484..58d164d90dca 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -36,7 +36,7 @@ static int st_accel_i2c_probe(struct i2c_client *client,
36 36
37 st_sensors_i2c_configure(indio_dev, client, adata); 37 st_sensors_i2c_configure(indio_dev, client, adata);
38 38
39 err = st_accel_common_probe(indio_dev); 39 err = st_accel_common_probe(indio_dev, client->dev.platform_data);
40 if (err < 0) 40 if (err < 0)
41 goto st_accel_common_probe_error; 41 goto st_accel_common_probe_error;
42 42
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 22b35bfea7d2..21ed9296311f 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -35,7 +35,7 @@ static int st_accel_spi_probe(struct spi_device *spi)
35 35
36 st_sensors_spi_configure(indio_dev, spi, adata); 36 st_sensors_spi_configure(indio_dev, spi, adata);
37 37
38 err = st_accel_common_probe(indio_dev); 38 err = st_accel_common_probe(indio_dev, spi->dev.platform_data);
39 if (err < 0) 39 if (err < 0)
40 goto st_accel_common_probe_error; 40 goto st_accel_common_probe_error;
41 41
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 865b1781df66..965ee22d3ac8 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -22,7 +22,7 @@
22 22
23static inline u32 st_sensors_get_unaligned_le24(const u8 *p) 23static inline u32 st_sensors_get_unaligned_le24(const u8 *p)
24{ 24{
25 return ((s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8); 25 return (s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8;
26} 26}
27 27
28static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, 28static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
@@ -118,7 +118,7 @@ st_sensors_match_odr_error:
118} 118}
119 119
120static int st_sensors_set_fullscale(struct iio_dev *indio_dev, 120static int st_sensors_set_fullscale(struct iio_dev *indio_dev,
121 unsigned int fs) 121 unsigned int fs)
122{ 122{
123 int err, i = 0; 123 int err, i = 0;
124 struct st_sensor_data *sdata = iio_priv(indio_dev); 124 struct st_sensor_data *sdata = iio_priv(indio_dev);
@@ -198,13 +198,39 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
198} 198}
199EXPORT_SYMBOL(st_sensors_set_axis_enable); 199EXPORT_SYMBOL(st_sensors_set_axis_enable);
200 200
201int st_sensors_init_sensor(struct iio_dev *indio_dev) 201int st_sensors_init_sensor(struct iio_dev *indio_dev,
202 struct st_sensors_platform_data *pdata)
202{ 203{
203 int err; 204 int err;
204 struct st_sensor_data *sdata = iio_priv(indio_dev); 205 struct st_sensor_data *sdata = iio_priv(indio_dev);
205 206
206 mutex_init(&sdata->tb.buf_lock); 207 mutex_init(&sdata->tb.buf_lock);
207 208
209 switch (pdata->drdy_int_pin) {
210 case 1:
211 if (sdata->sensor->drdy_irq.mask_int1 == 0) {
212 dev_err(&indio_dev->dev,
213 "DRDY on INT1 not available.\n");
214 err = -EINVAL;
215 goto init_error;
216 }
217 sdata->drdy_int_pin = 1;
218 break;
219 case 2:
220 if (sdata->sensor->drdy_irq.mask_int2 == 0) {
221 dev_err(&indio_dev->dev,
222 "DRDY on INT2 not available.\n");
223 err = -EINVAL;
224 goto init_error;
225 }
226 sdata->drdy_int_pin = 2;
227 break;
228 default:
229 dev_err(&indio_dev->dev, "DRDY on pdata not valid.\n");
230 err = -EINVAL;
231 goto init_error;
232 }
233
208 err = st_sensors_set_enable(indio_dev, false); 234 err = st_sensors_set_enable(indio_dev, false);
209 if (err < 0) 235 if (err < 0)
210 goto init_error; 236 goto init_error;
@@ -234,6 +260,7 @@ EXPORT_SYMBOL(st_sensors_init_sensor);
234int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable) 260int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
235{ 261{
236 int err; 262 int err;
263 u8 drdy_mask;
237 struct st_sensor_data *sdata = iio_priv(indio_dev); 264 struct st_sensor_data *sdata = iio_priv(indio_dev);
238 265
239 /* Enable/Disable the interrupt generator 1. */ 266 /* Enable/Disable the interrupt generator 1. */
@@ -245,10 +272,14 @@ int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
245 goto st_accel_set_dataready_irq_error; 272 goto st_accel_set_dataready_irq_error;
246 } 273 }
247 274
275 if (sdata->drdy_int_pin == 1)
276 drdy_mask = sdata->sensor->drdy_irq.mask_int1;
277 else
278 drdy_mask = sdata->sensor->drdy_irq.mask_int2;
279
248 /* Enable/Disable the interrupt generator for data ready. */ 280 /* Enable/Disable the interrupt generator for data ready. */
249 err = st_sensors_write_data_with_mask(indio_dev, 281 err = st_sensors_write_data_with_mask(indio_dev,
250 sdata->sensor->drdy_irq.addr, 282 sdata->sensor->drdy_irq.addr, drdy_mask, (int)enable);
251 sdata->sensor->drdy_irq.mask, (int)enable);
252 283
253st_accel_set_dataready_irq_error: 284st_accel_set_dataready_irq_error:
254 return err; 285 return err;
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
index 3ad9907bb154..f8f2bf84a5a2 100644
--- a/drivers/iio/gyro/st_gyro.h
+++ b/drivers/iio/gyro/st_gyro.h
@@ -23,7 +23,16 @@
23#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui" 23#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui"
24#define LSM330_GYRO_DEV_NAME "lsm330_gyro" 24#define LSM330_GYRO_DEV_NAME "lsm330_gyro"
25 25
26int st_gyro_common_probe(struct iio_dev *indio_dev); 26/**
27 * struct st_sensors_platform_data - gyro platform data
28 * @drdy_int_pin: DRDY on gyros is available only on INT2 pin.
29 */
30static const struct st_sensors_platform_data gyro_pdata = {
31 .drdy_int_pin = 2,
32};
33
34int st_gyro_common_probe(struct iio_dev *indio_dev,
35 struct st_sensors_platform_data *pdata);
27void st_gyro_common_remove(struct iio_dev *indio_dev); 36void st_gyro_common_remove(struct iio_dev *indio_dev);
28 37
29#ifdef CONFIG_IIO_BUFFER 38#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index f9ed3488c314..85fa8d343bb2 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -60,7 +60,7 @@
60#define ST_GYRO_1_BDU_ADDR 0x23 60#define ST_GYRO_1_BDU_ADDR 0x23
61#define ST_GYRO_1_BDU_MASK 0x80 61#define ST_GYRO_1_BDU_MASK 0x80
62#define ST_GYRO_1_DRDY_IRQ_ADDR 0x22 62#define ST_GYRO_1_DRDY_IRQ_ADDR 0x22
63#define ST_GYRO_1_DRDY_IRQ_MASK 0x08 63#define ST_GYRO_1_DRDY_IRQ_INT2_MASK 0x08
64#define ST_GYRO_1_MULTIREAD_BIT true 64#define ST_GYRO_1_MULTIREAD_BIT true
65 65
66/* CUSTOM VALUES FOR SENSOR 2 */ 66/* CUSTOM VALUES FOR SENSOR 2 */
@@ -84,7 +84,7 @@
84#define ST_GYRO_2_BDU_ADDR 0x23 84#define ST_GYRO_2_BDU_ADDR 0x23
85#define ST_GYRO_2_BDU_MASK 0x80 85#define ST_GYRO_2_BDU_MASK 0x80
86#define ST_GYRO_2_DRDY_IRQ_ADDR 0x22 86#define ST_GYRO_2_DRDY_IRQ_ADDR 0x22
87#define ST_GYRO_2_DRDY_IRQ_MASK 0x08 87#define ST_GYRO_2_DRDY_IRQ_INT2_MASK 0x08
88#define ST_GYRO_2_MULTIREAD_BIT true 88#define ST_GYRO_2_MULTIREAD_BIT true
89 89
90static const struct iio_chan_spec st_gyro_16bit_channels[] = { 90static const struct iio_chan_spec st_gyro_16bit_channels[] = {
@@ -158,7 +158,7 @@ static const struct st_sensors st_gyro_sensors[] = {
158 }, 158 },
159 .drdy_irq = { 159 .drdy_irq = {
160 .addr = ST_GYRO_1_DRDY_IRQ_ADDR, 160 .addr = ST_GYRO_1_DRDY_IRQ_ADDR,
161 .mask = ST_GYRO_1_DRDY_IRQ_MASK, 161 .mask_int2 = ST_GYRO_1_DRDY_IRQ_INT2_MASK,
162 }, 162 },
163 .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT, 163 .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,
164 .bootime = 2, 164 .bootime = 2,
@@ -221,7 +221,7 @@ static const struct st_sensors st_gyro_sensors[] = {
221 }, 221 },
222 .drdy_irq = { 222 .drdy_irq = {
223 .addr = ST_GYRO_2_DRDY_IRQ_ADDR, 223 .addr = ST_GYRO_2_DRDY_IRQ_ADDR,
224 .mask = ST_GYRO_2_DRDY_IRQ_MASK, 224 .mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK,
225 }, 225 },
226 .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT, 226 .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,
227 .bootime = 2, 227 .bootime = 2,
@@ -302,7 +302,8 @@ static const struct iio_trigger_ops st_gyro_trigger_ops = {
302#define ST_GYRO_TRIGGER_OPS NULL 302#define ST_GYRO_TRIGGER_OPS NULL
303#endif 303#endif
304 304
305int st_gyro_common_probe(struct iio_dev *indio_dev) 305int st_gyro_common_probe(struct iio_dev *indio_dev,
306 struct st_sensors_platform_data *pdata)
306{ 307{
307 int err; 308 int err;
308 struct st_sensor_data *gdata = iio_priv(indio_dev); 309 struct st_sensor_data *gdata = iio_priv(indio_dev);
@@ -324,7 +325,7 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
324 &gdata->sensor->fs.fs_avl[0]; 325 &gdata->sensor->fs.fs_avl[0];
325 gdata->odr = gdata->sensor->odr.odr_avl[0].hz; 326 gdata->odr = gdata->sensor->odr.odr_avl[0].hz;
326 327
327 err = st_sensors_init_sensor(indio_dev); 328 err = st_sensors_init_sensor(indio_dev, pdata);
328 if (err < 0) 329 if (err < 0)
329 goto st_gyro_common_probe_error; 330 goto st_gyro_common_probe_error;
330 331
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 8a310500573d..c7a29a4d7e82 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -36,7 +36,8 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
36 36
37 st_sensors_i2c_configure(indio_dev, client, gdata); 37 st_sensors_i2c_configure(indio_dev, client, gdata);
38 38
39 err = st_gyro_common_probe(indio_dev); 39 err = st_gyro_common_probe(indio_dev,
40 (struct st_sensors_platform_data *)&gyro_pdata);
40 if (err < 0) 41 if (err < 0)
41 goto st_gyro_common_probe_error; 42 goto st_gyro_common_probe_error;
42 43
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
index f3540390eb22..14b0762847f5 100644
--- a/drivers/iio/gyro/st_gyro_spi.c
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -35,7 +35,8 @@ static int st_gyro_spi_probe(struct spi_device *spi)
35 35
36 st_sensors_spi_configure(indio_dev, spi, gdata); 36 st_sensors_spi_configure(indio_dev, spi, gdata);
37 37
38 err = st_gyro_common_probe(indio_dev); 38 err = st_gyro_common_probe(indio_dev,
39 (struct st_sensors_platform_data *)&gyro_pdata);
39 if (err < 0) 40 if (err < 0)
40 goto st_gyro_common_probe_error; 41 goto st_gyro_common_probe_error;
41 42
diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
index 7e81d00ef0c3..694e33e0fb72 100644
--- a/drivers/iio/magnetometer/st_magn.h
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -18,7 +18,8 @@
18#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn" 18#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn"
19#define LIS3MDL_MAGN_DEV_NAME "lis3mdl" 19#define LIS3MDL_MAGN_DEV_NAME "lis3mdl"
20 20
21int st_magn_common_probe(struct iio_dev *indio_dev); 21int st_magn_common_probe(struct iio_dev *indio_dev,
22 struct st_sensors_platform_data *pdata);
22void st_magn_common_remove(struct iio_dev *indio_dev); 23void st_magn_common_remove(struct iio_dev *indio_dev);
23 24
24#ifdef CONFIG_IIO_BUFFER 25#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index ebfe8f11a0c2..7cd784f522e5 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -345,7 +345,8 @@ static const struct iio_info magn_info = {
345 .write_raw = &st_magn_write_raw, 345 .write_raw = &st_magn_write_raw,
346}; 346};
347 347
348int st_magn_common_probe(struct iio_dev *indio_dev) 348int st_magn_common_probe(struct iio_dev *indio_dev,
349 struct st_sensors_platform_data *pdata)
349{ 350{
350 int err; 351 int err;
351 struct st_sensor_data *mdata = iio_priv(indio_dev); 352 struct st_sensor_data *mdata = iio_priv(indio_dev);
@@ -367,7 +368,7 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
367 &mdata->sensor->fs.fs_avl[0]; 368 &mdata->sensor->fs.fs_avl[0];
368 mdata->odr = mdata->sensor->odr.odr_avl[0].hz; 369 mdata->odr = mdata->sensor->odr.odr_avl[0].hz;
369 370
370 err = st_sensors_init_sensor(indio_dev); 371 err = st_sensors_init_sensor(indio_dev, pdata);
371 if (err < 0) 372 if (err < 0)
372 goto st_magn_common_probe_error; 373 goto st_magn_common_probe_error;
373 374
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index e6adc4a86425..1bed117714c5 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -36,7 +36,7 @@ static int st_magn_i2c_probe(struct i2c_client *client,
36 36
37 st_sensors_i2c_configure(indio_dev, client, mdata); 37 st_sensors_i2c_configure(indio_dev, client, mdata);
38 38
39 err = st_magn_common_probe(indio_dev); 39 err = st_magn_common_probe(indio_dev, NULL);
40 if (err < 0) 40 if (err < 0)
41 goto st_magn_common_probe_error; 41 goto st_magn_common_probe_error;
42 42
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
index 51adb797cb7d..a2333a1e6061 100644
--- a/drivers/iio/magnetometer/st_magn_spi.c
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -35,7 +35,7 @@ static int st_magn_spi_probe(struct spi_device *spi)
35 35
36 st_sensors_spi_configure(indio_dev, spi, mdata); 36 st_sensors_spi_configure(indio_dev, spi, mdata);
37 37
38 err = st_magn_common_probe(indio_dev); 38 err = st_magn_common_probe(indio_dev, NULL);
39 if (err < 0) 39 if (err < 0)
40 goto st_magn_common_probe_error; 40 goto st_magn_common_probe_error;
41 41
diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h
index 414e45ac9b9b..b0b630688da6 100644
--- a/drivers/iio/pressure/st_pressure.h
+++ b/drivers/iio/pressure/st_pressure.h
@@ -16,7 +16,16 @@
16 16
17#define LPS331AP_PRESS_DEV_NAME "lps331ap" 17#define LPS331AP_PRESS_DEV_NAME "lps331ap"
18 18
19int st_press_common_probe(struct iio_dev *indio_dev); 19/**
20 * struct st_sensors_platform_data - default press platform data
21 * @drdy_int_pin: default press DRDY is available on INT1 pin.
22 */
23static const struct st_sensors_platform_data default_press_pdata = {
24 .drdy_int_pin = 1,
25};
26
27int st_press_common_probe(struct iio_dev *indio_dev,
28 struct st_sensors_platform_data *pdata);
20void st_press_common_remove(struct iio_dev *indio_dev); 29void st_press_common_remove(struct iio_dev *indio_dev);
21 30
22#ifdef CONFIG_IIO_BUFFER 31#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 3ffbc56917b4..81e2d5b030a6 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -58,7 +58,8 @@
58#define ST_PRESS_1_BDU_ADDR 0x20 58#define ST_PRESS_1_BDU_ADDR 0x20
59#define ST_PRESS_1_BDU_MASK 0x04 59#define ST_PRESS_1_BDU_MASK 0x04
60#define ST_PRESS_1_DRDY_IRQ_ADDR 0x22 60#define ST_PRESS_1_DRDY_IRQ_ADDR 0x22
61#define ST_PRESS_1_DRDY_IRQ_MASK 0x04 61#define ST_PRESS_1_DRDY_IRQ_INT1_MASK 0x04
62#define ST_PRESS_1_DRDY_IRQ_INT2_MASK 0x20
62#define ST_PRESS_1_MULTIREAD_BIT true 63#define ST_PRESS_1_MULTIREAD_BIT true
63#define ST_PRESS_1_TEMP_OFFSET 42500 64#define ST_PRESS_1_TEMP_OFFSET 42500
64 65
@@ -116,7 +117,8 @@ static const struct st_sensors st_press_sensors[] = {
116 }, 117 },
117 .drdy_irq = { 118 .drdy_irq = {
118 .addr = ST_PRESS_1_DRDY_IRQ_ADDR, 119 .addr = ST_PRESS_1_DRDY_IRQ_ADDR,
119 .mask = ST_PRESS_1_DRDY_IRQ_MASK, 120 .mask_int1 = ST_PRESS_1_DRDY_IRQ_INT1_MASK,
121 .mask_int2 = ST_PRESS_1_DRDY_IRQ_INT2_MASK,
120 }, 122 },
121 .multi_read_bit = ST_PRESS_1_MULTIREAD_BIT, 123 .multi_read_bit = ST_PRESS_1_MULTIREAD_BIT,
122 .bootime = 2, 124 .bootime = 2,
@@ -202,7 +204,8 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
202#define ST_PRESS_TRIGGER_OPS NULL 204#define ST_PRESS_TRIGGER_OPS NULL
203#endif 205#endif
204 206
205int st_press_common_probe(struct iio_dev *indio_dev) 207int st_press_common_probe(struct iio_dev *indio_dev,
208 struct st_sensors_platform_data *plat_data)
206{ 209{
207 int err; 210 int err;
208 struct st_sensor_data *pdata = iio_priv(indio_dev); 211 struct st_sensor_data *pdata = iio_priv(indio_dev);
@@ -224,7 +227,11 @@ int st_press_common_probe(struct iio_dev *indio_dev)
224 &pdata->sensor->fs.fs_avl[0]; 227 &pdata->sensor->fs.fs_avl[0];
225 pdata->odr = pdata->sensor->odr.odr_avl[0].hz; 228 pdata->odr = pdata->sensor->odr.odr_avl[0].hz;
226 229
227 err = st_sensors_init_sensor(indio_dev); 230 if (!plat_data)
231 plat_data =
232 (struct st_sensors_platform_data *)&default_press_pdata;
233
234 err = st_sensors_init_sensor(indio_dev, plat_data);
228 if (err < 0) 235 if (err < 0)
229 goto st_press_common_probe_error; 236 goto st_press_common_probe_error;
230 237
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index 7cebcc73bfb0..306599307a96 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -36,7 +36,7 @@ static int st_press_i2c_probe(struct i2c_client *client,
36 36
37 st_sensors_i2c_configure(indio_dev, client, pdata); 37 st_sensors_i2c_configure(indio_dev, client, pdata);
38 38
39 err = st_press_common_probe(indio_dev); 39 err = st_press_common_probe(indio_dev, client->dev.platform_data);
40 if (err < 0) 40 if (err < 0)
41 goto st_press_common_probe_error; 41 goto st_press_common_probe_error;
42 42
diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c
index 17a14907940a..b2aded6d2108 100644
--- a/drivers/iio/pressure/st_pressure_spi.c
+++ b/drivers/iio/pressure/st_pressure_spi.c
@@ -35,7 +35,7 @@ static int st_press_spi_probe(struct spi_device *spi)
35 35
36 st_sensors_spi_configure(indio_dev, spi, pdata); 36 st_sensors_spi_configure(indio_dev, spi, pdata);
37 37
38 err = st_press_common_probe(indio_dev); 38 err = st_press_common_probe(indio_dev, spi->dev.platform_data);
39 if (err < 0) 39 if (err < 0)
40 goto st_press_common_probe_error; 40 goto st_press_common_probe_error;
41 41
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 72b26940730d..e51f65480ea5 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -17,6 +17,8 @@
17#include <linux/iio/trigger.h> 17#include <linux/iio/trigger.h>
18#include <linux/bitops.h> 18#include <linux/bitops.h>
19 19
20#include <linux/platform_data/st_sensors_pdata.h>
21
20#define ST_SENSORS_TX_MAX_LENGTH 2 22#define ST_SENSORS_TX_MAX_LENGTH 2
21#define ST_SENSORS_RX_MAX_LENGTH 6 23#define ST_SENSORS_RX_MAX_LENGTH 6
22 24
@@ -118,14 +120,16 @@ struct st_sensor_bdu {
118/** 120/**
119 * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt 121 * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt
120 * @addr: address of the register. 122 * @addr: address of the register.
121 * @mask: mask to write the on/off value. 123 * @mask_int1: mask to enable/disable IRQ on INT1 pin.
124 * @mask_int2: mask to enable/disable IRQ on INT2 pin.
122 * struct ig1 - represents the Interrupt Generator 1 of sensors. 125 * struct ig1 - represents the Interrupt Generator 1 of sensors.
123 * @en_addr: address of the enable ig1 register. 126 * @en_addr: address of the enable ig1 register.
124 * @en_mask: mask to write the on/off value for enable. 127 * @en_mask: mask to write the on/off value for enable.
125 */ 128 */
126struct st_sensor_data_ready_irq { 129struct st_sensor_data_ready_irq {
127 u8 addr; 130 u8 addr;
128 u8 mask; 131 u8 mask_int1;
132 u8 mask_int2;
129 struct { 133 struct {
130 u8 en_addr; 134 u8 en_addr;
131 u8 en_mask; 135 u8 en_mask;
@@ -201,6 +205,7 @@ struct st_sensors {
201 * @buffer_data: Data used by buffer part. 205 * @buffer_data: Data used by buffer part.
202 * @odr: Output data rate of the sensor [Hz]. 206 * @odr: Output data rate of the sensor [Hz].
203 * num_data_channels: Number of data channels used in buffer. 207 * num_data_channels: Number of data channels used in buffer.
208 * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2).
204 * @get_irq_data_ready: Function to get the IRQ used for data ready signal. 209 * @get_irq_data_ready: Function to get the IRQ used for data ready signal.
205 * @tf: Transfer function structure used by I/O operations. 210 * @tf: Transfer function structure used by I/O operations.
206 * @tb: Transfer buffers and mutex used by I/O operations. 211 * @tb: Transfer buffers and mutex used by I/O operations.
@@ -219,6 +224,8 @@ struct st_sensor_data {
219 unsigned int odr; 224 unsigned int odr;
220 unsigned int num_data_channels; 225 unsigned int num_data_channels;
221 226
227 u8 drdy_int_pin;
228
222 unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev); 229 unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev);
223 230
224 const struct st_sensor_transfer_function *tf; 231 const struct st_sensor_transfer_function *tf;
@@ -249,7 +256,8 @@ static inline void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
249} 256}
250#endif 257#endif
251 258
252int st_sensors_init_sensor(struct iio_dev *indio_dev); 259int st_sensors_init_sensor(struct iio_dev *indio_dev,
260 struct st_sensors_platform_data *pdata);
253 261
254int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable); 262int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable);
255 263
diff --git a/include/linux/platform_data/st_sensors_pdata.h b/include/linux/platform_data/st_sensors_pdata.h
new file mode 100644
index 000000000000..753839187ba0
--- /dev/null
+++ b/include/linux/platform_data/st_sensors_pdata.h
@@ -0,0 +1,24 @@
1/*
2 * STMicroelectronics sensors platform-data driver
3 *
4 * Copyright 2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_SENSORS_PDATA_H
12#define ST_SENSORS_PDATA_H
13
14/**
15 * struct st_sensors_platform_data - Platform data for the ST sensors
16 * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2).
17 * Available only for accelerometer and pressure sensors.
18 * Accelerometer DRDY on LSM330 available only on pin 1 (see datasheet).
19 */
20struct st_sensors_platform_data {
21 u8 drdy_int_pin;
22};
23
24#endif /* ST_SENSORS_PDATA_H */