aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Bianconi <lorenzo.bianconi83@gmail.com>2017-07-05 14:30:01 -0400
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2017-07-06 14:32:29 -0400
commita7b8829d242b1a58107e9c02b09e93aec446d55c (patch)
tree95f3fd426b135148789c66f2f066b83cd91ab912
parent631b010abc5b57009c6a8328f51492665f6ef310 (diff)
iio: accel: st_accel: add SPI-3wire support
Add SPI Serial Interface Mode (SIM) register information in st_sensor_settings look up table to support devices (like LSM303AGR accel sensor) that allow just SPI-3wire communication mode. SIM mode has to be configured before any other operation since it is not enabled by default and the driver is not able to read without that configuration Whilst a fairly substantial patch, the actual logic is simple and it is better to have the generic fix than a band aid. Fixes: ddc05fa28606 (iio: st-accel: add support for lsm303agr accel) Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@st.com> Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r--drivers/iio/accel/st_accel_core.c32
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c29
-rw-r--r--include/linux/iio/common/st_sensors.h7
-rw-r--r--include/linux/platform_data/st_sensors_pdata.h2
4 files changed, 70 insertions, 0 deletions
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 784670e2736b..2ee3ae11eb2a 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -166,6 +166,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
166 .mask_ihl = 0x02, 166 .mask_ihl = 0x02,
167 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 167 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
168 }, 168 },
169 .sim = {
170 .addr = 0x23,
171 .value = BIT(0),
172 },
169 .multi_read_bit = true, 173 .multi_read_bit = true,
170 .bootime = 2, 174 .bootime = 2,
171 }, 175 },
@@ -234,6 +238,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
234 .mask_od = 0x40, 238 .mask_od = 0x40,
235 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 239 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
236 }, 240 },
241 .sim = {
242 .addr = 0x23,
243 .value = BIT(0),
244 },
237 .multi_read_bit = true, 245 .multi_read_bit = true,
238 .bootime = 2, 246 .bootime = 2,
239 }, 247 },
@@ -316,6 +324,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
316 .en_mask = 0x08, 324 .en_mask = 0x08,
317 }, 325 },
318 }, 326 },
327 .sim = {
328 .addr = 0x24,
329 .value = BIT(0),
330 },
319 .multi_read_bit = false, 331 .multi_read_bit = false,
320 .bootime = 2, 332 .bootime = 2,
321 }, 333 },
@@ -379,6 +391,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
379 .mask_int1 = 0x04, 391 .mask_int1 = 0x04,
380 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 392 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
381 }, 393 },
394 .sim = {
395 .addr = 0x21,
396 .value = BIT(1),
397 },
382 .multi_read_bit = true, 398 .multi_read_bit = true,
383 .bootime = 2, /* guess */ 399 .bootime = 2, /* guess */
384 }, 400 },
@@ -437,6 +453,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
437 .mask_od = 0x40, 453 .mask_od = 0x40,
438 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 454 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
439 }, 455 },
456 .sim = {
457 .addr = 0x21,
458 .value = BIT(7),
459 },
440 .multi_read_bit = false, 460 .multi_read_bit = false,
441 .bootime = 2, /* guess */ 461 .bootime = 2, /* guess */
442 }, 462 },
@@ -499,6 +519,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
499 .addr_ihl = 0x22, 519 .addr_ihl = 0x22,
500 .mask_ihl = 0x80, 520 .mask_ihl = 0x80,
501 }, 521 },
522 .sim = {
523 .addr = 0x23,
524 .value = BIT(0),
525 },
502 .multi_read_bit = true, 526 .multi_read_bit = true,
503 .bootime = 2, 527 .bootime = 2,
504 }, 528 },
@@ -547,6 +571,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
547 .mask_int1 = 0x04, 571 .mask_int1 = 0x04,
548 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 572 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
549 }, 573 },
574 .sim = {
575 .addr = 0x21,
576 .value = BIT(1),
577 },
550 .multi_read_bit = false, 578 .multi_read_bit = false,
551 .bootime = 2, 579 .bootime = 2,
552 }, 580 },
@@ -614,6 +642,10 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
614 .mask_ihl = 0x02, 642 .mask_ihl = 0x02,
615 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, 643 .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
616 }, 644 },
645 .sim = {
646 .addr = 0x23,
647 .value = BIT(0),
648 },
617 .multi_read_bit = true, 649 .multi_read_bit = true,
618 .bootime = 2, 650 .bootime = 2,
619 }, 651 },
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 79c8c7cd70d5..6e6a1ecc99dd 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -550,6 +550,31 @@ out:
550} 550}
551EXPORT_SYMBOL(st_sensors_read_info_raw); 551EXPORT_SYMBOL(st_sensors_read_info_raw);
552 552
553static int st_sensors_init_interface_mode(struct iio_dev *indio_dev,
554 const struct st_sensor_settings *sensor_settings)
555{
556 struct st_sensor_data *sdata = iio_priv(indio_dev);
557 struct device_node *np = sdata->dev->of_node;
558 struct st_sensors_platform_data *pdata;
559
560 pdata = (struct st_sensors_platform_data *)sdata->dev->platform_data;
561 if (((np && of_property_read_bool(np, "spi-3wire")) ||
562 (pdata && pdata->spi_3wire)) && sensor_settings->sim.addr) {
563 int err;
564
565 err = sdata->tf->write_byte(&sdata->tb, sdata->dev,
566 sensor_settings->sim.addr,
567 sensor_settings->sim.value);
568 if (err < 0) {
569 dev_err(&indio_dev->dev,
570 "failed to init interface mode\n");
571 return err;
572 }
573 }
574
575 return 0;
576}
577
553int st_sensors_check_device_support(struct iio_dev *indio_dev, 578int st_sensors_check_device_support(struct iio_dev *indio_dev,
554 int num_sensors_list, 579 int num_sensors_list,
555 const struct st_sensor_settings *sensor_settings) 580 const struct st_sensor_settings *sensor_settings)
@@ -574,6 +599,10 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
574 return -ENODEV; 599 return -ENODEV;
575 } 600 }
576 601
602 err = st_sensors_init_interface_mode(indio_dev, &sensor_settings[i]);
603 if (err < 0)
604 return err;
605
577 if (sensor_settings[i].wai_addr) { 606 if (sensor_settings[i].wai_addr) {
578 err = sdata->tf->read_byte(&sdata->tb, sdata->dev, 607 err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
579 sensor_settings[i].wai_addr, &wai); 608 sensor_settings[i].wai_addr, &wai);
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 497f2b3a5a62..97f1b465d04f 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -105,6 +105,11 @@ struct st_sensor_fullscale {
105 struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX]; 105 struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
106}; 106};
107 107
108struct st_sensor_sim {
109 u8 addr;
110 u8 value;
111};
112
108/** 113/**
109 * struct st_sensor_bdu - ST sensor device block data update 114 * struct st_sensor_bdu - ST sensor device block data update
110 * @addr: address of the register. 115 * @addr: address of the register.
@@ -197,6 +202,7 @@ struct st_sensor_transfer_function {
197 * @bdu: Block data update register. 202 * @bdu: Block data update register.
198 * @das: Data Alignment Selection register. 203 * @das: Data Alignment Selection register.
199 * @drdy_irq: Data ready register of the sensor. 204 * @drdy_irq: Data ready register of the sensor.
205 * @sim: SPI serial interface mode register of the sensor.
200 * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read. 206 * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
201 * @bootime: samples to discard when sensor passing from power-down to power-up. 207 * @bootime: samples to discard when sensor passing from power-down to power-up.
202 */ 208 */
@@ -213,6 +219,7 @@ struct st_sensor_settings {
213 struct st_sensor_bdu bdu; 219 struct st_sensor_bdu bdu;
214 struct st_sensor_das das; 220 struct st_sensor_das das;
215 struct st_sensor_data_ready_irq drdy_irq; 221 struct st_sensor_data_ready_irq drdy_irq;
222 struct st_sensor_sim sim;
216 bool multi_read_bit; 223 bool multi_read_bit;
217 unsigned int bootime; 224 unsigned int bootime;
218}; 225};
diff --git a/include/linux/platform_data/st_sensors_pdata.h b/include/linux/platform_data/st_sensors_pdata.h
index 79b0e4cdb814..f8274b0c6888 100644
--- a/include/linux/platform_data/st_sensors_pdata.h
+++ b/include/linux/platform_data/st_sensors_pdata.h
@@ -17,10 +17,12 @@
17 * Available only for accelerometer and pressure sensors. 17 * Available only for accelerometer and pressure sensors.
18 * Accelerometer DRDY on LSM330 available only on pin 1 (see datasheet). 18 * Accelerometer DRDY on LSM330 available only on pin 1 (see datasheet).
19 * @open_drain: set the interrupt line to be open drain if possible. 19 * @open_drain: set the interrupt line to be open drain if possible.
20 * @spi_3wire: enable spi-3wire mode.
20 */ 21 */
21struct st_sensors_platform_data { 22struct st_sensors_platform_data {
22 u8 drdy_int_pin; 23 u8 drdy_int_pin;
23 bool open_drain; 24 bool open_drain;
25 bool spi_3wire;
24}; 26};
25 27
26#endif /* ST_SENSORS_PDATA_H */ 28#endif /* ST_SENSORS_PDATA_H */