All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Added ST LSM303AGR sensor
@ 2015-07-16  9:17 Giuseppe Barba
  2015-07-16  9:17 ` [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address Giuseppe Barba
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-16  9:17 UTC (permalink / raw)
  To: linux-iio; +Cc: Giuseppe Barba

This patch set add support for STMicroelectronics LSM303AGR device,
which embeds an accelerometer and a magnetometer sensors.
These patches have been rebased on iio repo testing branch and tested on Panda
board.

Giuseppe Barba (5):
  iio: st-sensors: add configuration for WhoAmI address
  iio: st-sensors: add full scale counter field
  iio: st_magn: Add irq trigger handling
  iio: st-accel: add support for lsm303agr accelerometer
  iio: st-magn: add support for lsm303agr magnetometer

 .../devicetree/bindings/iio/st-sensors.txt         |   2 +
 drivers/iio/accel/st_accel.h                       |   1 +
 drivers/iio/accel/st_accel_core.c                  |   9 ++
 drivers/iio/accel/st_accel_i2c.c                   |   5 ++
 drivers/iio/accel/st_accel_spi.c                   |   1 +
 drivers/iio/common/st_sensors/st_sensors_core.c    |  54 ++++++-----
 drivers/iio/gyro/st_gyro_core.c                    |   6 ++
 drivers/iio/magnetometer/st_magn.h                 |   3 +
 drivers/iio/magnetometer/st_magn_buffer.c          |   7 ++
 drivers/iio/magnetometer/st_magn_core.c            | 100 ++++++++++++++++++++-
 drivers/iio/magnetometer/st_magn_i2c.c             |   5 ++
 drivers/iio/magnetometer/st_magn_spi.c             |   1 +
 include/linux/iio/common/st_sensors.h              |   3 +
 13 files changed, 173 insertions(+), 24 deletions(-)

--
1.9.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address
  2015-07-16  9:17 [PATCH 0/5] Added ST LSM303AGR sensor Giuseppe Barba
@ 2015-07-16  9:17 ` Giuseppe Barba
  2015-07-19 11:03   ` Jonathan Cameron
  2015-07-16  9:17 ` [PATCH 2/5] iio: st-sensors: add full scale counter field Giuseppe Barba
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-16  9:17 UTC (permalink / raw)
  To: linux-iio; +Cc: Giuseppe Barba

This patch permits to configure the WhoAmI register address
because some device could doesn't have a standard address
for this register.

Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
---
 drivers/iio/accel/st_accel_core.c               |  4 +++
 drivers/iio/common/st_sensors/st_sensors_core.c | 44 +++++++++++++++----------
 drivers/iio/gyro/st_gyro_core.c                 |  3 ++
 drivers/iio/magnetometer/st_magn_core.c         |  2 ++
 include/linux/iio/common/st_sensors.h           |  2 ++
 5 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 4002e64..7ce027b 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -226,6 +226,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
 static const struct st_sensor_settings st_accel_sensors_settings[] = {
 	{
 		.wai = ST_ACCEL_1_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS3DH_ACCEL_DEV_NAME,
 			[1] = LSM303DLHC_ACCEL_DEV_NAME,
@@ -297,6 +298,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 	},
 	{
 		.wai = ST_ACCEL_2_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS331DLH_ACCEL_DEV_NAME,
 			[1] = LSM303DL_ACCEL_DEV_NAME,
@@ -359,6 +361,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 	},
 	{
 		.wai = ST_ACCEL_3_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LSM330_ACCEL_DEV_NAME,
 		},
@@ -437,6 +440,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 	},
 	{
 		.wai = ST_ACCEL_4_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS3LV02DL_ACCEL_DEV_NAME,
 		},
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 8086cbc..c0a611e 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -479,35 +479,43 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
 			int num_sensors_list,
 			const struct st_sensor_settings *sensor_settings)
 {
-	u8 wai;
 	int i, n, err;
+	u8 wai, wai_addr, found_it;
 	struct st_sensor_data *sdata = iio_priv(indio_dev);
 
+	found_it = 0;
+	for (i = 0; i < num_sensors_list; i++) {
+		for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
+			if (strcmp(indio_dev->name,
+				sensor_settings[i].sensors_supported[n]) == 0) {
+				found_it = 1;
+				break;
+			}
+		}
+		if (found_it)
+			break;
+	}
+	if (!found_it) {
+		dev_err(&indio_dev->dev, "device name %s not recognized.\n",
+							indio_dev->name);
+		goto sensor_name_mismatch;
+	}
+
+	if (sensor_settings[i].wai_addr != 0)
+		wai_addr = sensor_settings[i].wai_addr;
+	else
+		wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS;
+
 	err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
-					ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
+					wai_addr, &wai);
 	if (err < 0) {
 		dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
 		goto read_wai_error;
 	}
 
-	for (i = 0; i < num_sensors_list; i++) {
-		if (sensor_settings[i].wai == wai)
-			break;
-	}
-	if (i == num_sensors_list)
+	if (sensor_settings[i].wai != wai)
 		goto device_not_supported;
 
-	for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported); n++) {
-		if (strcmp(indio_dev->name,
-				&sensor_settings[i].sensors_supported[n][0]) == 0)
-			break;
-	}
-	if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) {
-		dev_err(&indio_dev->dev, "device name \"%s\" and WhoAmI (0x%02x) mismatch",
-			indio_dev->name, wai);
-		goto sensor_name_mismatch;
-	}
-
 	sdata->sensor_settings =
 			(struct st_sensor_settings *)&sensor_settings[i];
 
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index ffe9664..4b993a5 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -131,6 +131,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
 static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 	{
 		.wai = ST_GYRO_1_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = L3G4200D_GYRO_DEV_NAME,
 			[1] = LSM330DL_GYRO_DEV_NAME,
@@ -190,6 +191,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 	},
 	{
 		.wai = ST_GYRO_2_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = L3GD20_GYRO_DEV_NAME,
 			[1] = LSM330D_GYRO_DEV_NAME,
@@ -252,6 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 	},
 	{
 		.wai = ST_GYRO_3_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = L3GD20_GYRO_DEV_NAME,
 		},
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index b4bcfb7..63da293 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -268,6 +268,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
 	},
 	{
 		.wai = ST_MAGN_1_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LSM303DLHC_MAGN_DEV_NAME,
 			[1] = LSM303DLM_MAGN_DEV_NAME,
@@ -346,6 +347,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
 	},
 	{
 		.wai = ST_MAGN_2_WAI_EXP,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS3MDL_MAGN_DEV_NAME,
 		},
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 2c476ac..f7c77b4 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -166,6 +166,7 @@ struct st_sensor_transfer_function {
 /**
  * struct st_sensor_settings - ST specific sensor settings
  * @wai: Contents of WhoAmI register.
+ * @wai_addr: The address of WhoAmI register
  * @sensors_supported: List of supported sensors by struct itself.
  * @ch: IIO channels for the sensor.
  * @odr: Output data rate register and ODR list available.
@@ -179,6 +180,7 @@ struct st_sensor_transfer_function {
  */
 struct st_sensor_settings {
 	u8 wai;
+	u8 wai_addr;
 	char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
 	struct iio_chan_spec *ch;
 	int num_ch;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/5] iio: st-sensors: add full scale counter field
  2015-07-16  9:17 [PATCH 0/5] Added ST LSM303AGR sensor Giuseppe Barba
  2015-07-16  9:17 ` [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address Giuseppe Barba
@ 2015-07-16  9:17 ` Giuseppe Barba
  2015-07-19 11:09   ` Jonathan Cameron
  2015-07-16  9:17 ` [PATCH 3/5] iio: st_magn: Add irq trigger handling Giuseppe Barba
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-16  9:17 UTC (permalink / raw)
  To: linux-iio; +Cc: Giuseppe Barba

This patch add the full scale list size variable. This is
needed for code clenup and to enable device with a single
full scale value.

Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
---
 drivers/iio/accel/st_accel_core.c               |  4 ++++
 drivers/iio/common/st_sensors/st_sensors_core.c | 10 +++++-----
 drivers/iio/gyro/st_gyro_core.c                 |  3 +++
 drivers/iio/magnetometer/st_magn_core.c         |  2 ++
 include/linux/iio/common/st_sensors.h           |  1 +
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 7ce027b..207f6ef 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -283,6 +283,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 					.gain = ST_ACCEL_1_FS_AVL_16_GAIN,
 				},
 			},
+			.fs_avl_cnt = 4,
 		},
 		.bdu = {
 			.addr = ST_ACCEL_1_BDU_ADDR,
@@ -346,6 +347,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 					.gain = ST_ACCEL_2_FS_AVL_8_GAIN,
 				},
 			},
+			.fs_avl_cnt = 3,
 		},
 		.bdu = {
 			.addr = ST_ACCEL_2_BDU_ADDR,
@@ -421,6 +423,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 					.gain = ST_ACCEL_3_FS_AVL_16_GAIN,
 				},
 			},
+			.fs_avl_cnt = 5,
 		},
 		.bdu = {
 			.addr = ST_ACCEL_3_BDU_ADDR,
@@ -480,6 +483,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 					.gain = ST_ACCEL_4_FS_AVL_6_GAIN,
 				},
 			},
+			.fs_avl_cnt = 2,
 		},
 		.bdu = {
 			.addr = ST_ACCEL_4_BDU_ADDR,
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index c0a611e..d9845a6 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -106,7 +106,7 @@ static int st_sensors_match_fs(struct st_sensor_settings *sensor_settings,
 {
 	int i, ret = -EINVAL;
 
-	for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
+	for (i = 0; i < sensor_settings->fs.fs_avl_cnt; i++) {
 		if (sensor_settings->fs.fs_avl[i].num == 0)
 			goto st_sensors_match_odr_error;
 
@@ -126,6 +126,9 @@ static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs)
 	int err, i = 0;
 	struct st_sensor_data *sdata = iio_priv(indio_dev);
 
+	if (sdata->sensor_settings->fs.fs_avl_cnt < 2)
+		return 0;
+
 	err = st_sensors_match_fs(sdata->sensor_settings, fs, &i);
 	if (err < 0)
 		goto st_accel_set_fullscale_error;
@@ -560,10 +563,7 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
 	struct st_sensor_data *sdata = iio_priv(indio_dev);
 
 	mutex_lock(&indio_dev->mlock);
-	for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
-		if (sdata->sensor_settings->fs.fs_avl[i].num == 0)
-			break;
-
+	for (i = 0; i < sdata->sensor_settings->fs.fs_avl_cnt; i++) {
 		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
 				sdata->sensor_settings->fs.fs_avl[i].gain);
 	}
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index 4b993a5..c06e8f7 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -177,6 +177,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 					.gain = ST_GYRO_1_FS_AVL_2000_GAIN,
 				},
 			},
+			.fs_avl_cnt = 3,
 		},
 		.bdu = {
 			.addr = ST_GYRO_1_BDU_ADDR,
@@ -240,6 +241,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 					.gain = ST_GYRO_2_FS_AVL_2000_GAIN,
 				},
 			},
+			.fs_avl_cnt = 3,
 		},
 		.bdu = {
 			.addr = ST_GYRO_2_BDU_ADDR,
@@ -299,6 +301,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 					.gain = ST_GYRO_3_FS_AVL_2000_GAIN,
 				},
 			},
+			.fs_avl_cnt = 3,
 		},
 		.bdu = {
 			.addr = ST_GYRO_3_BDU_ADDR,
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 63da293..4c0335b 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -341,6 +341,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
 					.gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z,
 				},
 			},
+			.fs_avl_cnt = 7,
 		},
 		.multi_read_bit = ST_MAGN_1_MULTIREAD_BIT,
 		.bootime = 2,
@@ -397,6 +398,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
 					.gain = ST_MAGN_2_FS_AVL_16000_GAIN,
 				},
 			},
+			.fs_avl_cnt = 4,
 		},
 		.multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
 		.bootime = 2,
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index f7c77b4..0d7d5bb 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -101,6 +101,7 @@ struct st_sensor_fullscale_avl {
 struct st_sensor_fullscale {
 	u8 addr;
 	u8 mask;
+	u8 fs_avl_cnt;
 	struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
 };
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/5] iio: st_magn: Add irq trigger handling
  2015-07-16  9:17 [PATCH 0/5] Added ST LSM303AGR sensor Giuseppe Barba
  2015-07-16  9:17 ` [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address Giuseppe Barba
  2015-07-16  9:17 ` [PATCH 2/5] iio: st-sensors: add full scale counter field Giuseppe Barba
@ 2015-07-16  9:17 ` Giuseppe Barba
  2015-07-16  9:17 ` [PATCH 4/5] iio: st-accel: add support for lsm303agr accelerometer Giuseppe Barba
  2015-07-16  9:17 ` [PATCH 5/5] iio: st-magn: add support for lsm303agr magnetometer Giuseppe Barba
  4 siblings, 0 replies; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-16  9:17 UTC (permalink / raw)
  To: linux-iio; +Cc: Giuseppe Barba

Add irq trigger handling for magnetometer also

Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
---
 drivers/iio/magnetometer/st_magn.h        |  2 ++
 drivers/iio/magnetometer/st_magn_buffer.c |  7 +++++++
 drivers/iio/magnetometer/st_magn_core.c   | 13 ++++++++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
index 287691c..60441023 100644
--- a/drivers/iio/magnetometer/st_magn.h
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -25,6 +25,8 @@ void st_magn_common_remove(struct iio_dev *indio_dev);
 #ifdef CONFIG_IIO_BUFFER
 int st_magn_allocate_ring(struct iio_dev *indio_dev);
 void st_magn_deallocate_ring(struct iio_dev *indio_dev);
+int st_magn_trig_set_state(struct iio_trigger *trig, bool state);
+#define ST_MAGN_TRIGGER_SET_STATE (&st_magn_trig_set_state)
 #else /* CONFIG_IIO_BUFFER */
 static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq)
 {
diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
index bf427dc..ecd3bd0 100644
--- a/drivers/iio/magnetometer/st_magn_buffer.c
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -23,6 +23,13 @@
 #include <linux/iio/common/st_sensors.h>
 #include "st_magn.h"
 
+int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
+{
+	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
+
+	return st_sensors_set_dataready_irq(indio_dev, state);
+}
+
 static int st_magn_buffer_preenable(struct iio_dev *indio_dev)
 {
 	return st_sensors_set_enable(indio_dev, true);
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 4c0335b..4948185 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -481,6 +481,16 @@ static const struct iio_info magn_info = {
 	.write_raw = &st_magn_write_raw,
 };
 
+#ifdef CONFIG_IIO_TRIGGER
+static const struct iio_trigger_ops st_magn_trigger_ops = {
+	.owner = THIS_MODULE,
+	.set_trigger_state = ST_MAGN_TRIGGER_SET_STATE,
+};
+#define ST_MAGN_TRIGGER_OPS (&st_magn_trigger_ops)
+#else
+#define ST_MAGN_TRIGGER_OPS NULL
+#endif
+
 int st_magn_common_probe(struct iio_dev *indio_dev)
 {
 	struct st_sensor_data *mdata = iio_priv(indio_dev);
@@ -517,7 +527,8 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
 		return err;
 
 	if (irq > 0) {
-		err = st_sensors_allocate_trigger(indio_dev, NULL);
+		err = st_sensors_allocate_trigger(indio_dev,
+						ST_MAGN_TRIGGER_OPS);
 		if (err < 0)
 			goto st_magn_probe_trigger_error;
 	}
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/5] iio: st-accel: add support for lsm303agr accelerometer
  2015-07-16  9:17 [PATCH 0/5] Added ST LSM303AGR sensor Giuseppe Barba
                   ` (2 preceding siblings ...)
  2015-07-16  9:17 ` [PATCH 3/5] iio: st_magn: Add irq trigger handling Giuseppe Barba
@ 2015-07-16  9:17 ` Giuseppe Barba
  2015-07-16  9:17 ` [PATCH 5/5] iio: st-magn: add support for lsm303agr magnetometer Giuseppe Barba
  4 siblings, 0 replies; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-16  9:17 UTC (permalink / raw)
  To: linux-iio; +Cc: Giuseppe Barba

This adds support for the lsm303agr accelerometer.

Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
---
 Documentation/devicetree/bindings/iio/st-sensors.txt | 1 +
 drivers/iio/accel/st_accel.h                         | 1 +
 drivers/iio/accel/st_accel_core.c                    | 1 +
 drivers/iio/accel/st_accel_i2c.c                     | 5 +++++
 drivers/iio/accel/st_accel_spi.c                     | 1 +
 5 files changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt
index 8a6be3b..d80bdaa 100644
--- a/Documentation/devicetree/bindings/iio/st-sensors.txt
+++ b/Documentation/devicetree/bindings/iio/st-sensors.txt
@@ -35,6 +35,7 @@ Accelerometers:
 - st,lsm303dl-accel
 - st,lsm303dlm-accel
 - st,lsm330-accel
+- st,lsm303agr-accel
 
 Gyroscopes:
 - st,l3g4200d-gyro
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index aa10019..468f21f 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -26,6 +26,7 @@
 #define LSM303DLH_ACCEL_DEV_NAME	"lsm303dlh_accel"
 #define LSM303DLM_ACCEL_DEV_NAME	"lsm303dlm_accel"
 #define LSM330_ACCEL_DEV_NAME		"lsm330_accel"
+#define LSM303AGR_ACCEL_DEV_NAME	"lsm303agr_accel"
 
 /**
 * struct st_sensors_platform_data - default accel platform data
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 207f6ef..3e55bf9 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -233,6 +233,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			[2] = LSM330D_ACCEL_DEV_NAME,
 			[3] = LSM330DL_ACCEL_DEV_NAME,
 			[4] = LSM330DLC_ACCEL_DEV_NAME,
+			[5] = LSM303AGR_ACCEL_DEV_NAME,
 		},
 		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
 		.odr = {
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index d4ad72c..7003542 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -68,6 +68,10 @@ static const struct of_device_id st_accel_of_match[] = {
 		.compatible = "st,lsm330-accel",
 		.data = LSM330_ACCEL_DEV_NAME,
 	},
+	{
+		.compatible = "st,lsm303agr-accel",
+		.data = LSM303AGR_ACCEL_DEV_NAME,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, st_accel_of_match);
@@ -116,6 +120,7 @@ static const struct i2c_device_id st_accel_id_table[] = {
 	{ LSM303DL_ACCEL_DEV_NAME },
 	{ LSM303DLM_ACCEL_DEV_NAME },
 	{ LSM330_ACCEL_DEV_NAME },
+	{ LSM303AGR_ACCEL_DEV_NAME },
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 12ec293..54b61a3 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -57,6 +57,7 @@ static const struct spi_device_id st_accel_id_table[] = {
 	{ LSM303DL_ACCEL_DEV_NAME },
 	{ LSM303DLM_ACCEL_DEV_NAME },
 	{ LSM330_ACCEL_DEV_NAME },
+	{ LSM303AGR_ACCEL_DEV_NAME },
 	{},
 };
 MODULE_DEVICE_TABLE(spi, st_accel_id_table);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 5/5] iio: st-magn: add support for lsm303agr magnetometer
  2015-07-16  9:17 [PATCH 0/5] Added ST LSM303AGR sensor Giuseppe Barba
                   ` (3 preceding siblings ...)
  2015-07-16  9:17 ` [PATCH 4/5] iio: st-accel: add support for lsm303agr accelerometer Giuseppe Barba
@ 2015-07-16  9:17 ` Giuseppe Barba
  2015-07-19 11:14   ` Jonathan Cameron
  4 siblings, 1 reply; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-16  9:17 UTC (permalink / raw)
  To: linux-iio; +Cc: Giuseppe Barba

This adds support for the lsm303agr magnetometer.

Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
---
 .../devicetree/bindings/iio/st-sensors.txt         |  1 +
 drivers/iio/magnetometer/st_magn.h                 |  1 +
 drivers/iio/magnetometer/st_magn_core.c            | 83 ++++++++++++++++++++++
 drivers/iio/magnetometer/st_magn_i2c.c             |  5 ++
 drivers/iio/magnetometer/st_magn_spi.c             |  1 +
 5 files changed, 91 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt
index d80bdaa..d3ccdb1 100644
--- a/Documentation/devicetree/bindings/iio/st-sensors.txt
+++ b/Documentation/devicetree/bindings/iio/st-sensors.txt
@@ -47,6 +47,7 @@ Gyroscopes:
 - st,lsm330-gyro
 
 Magnetometers:
+- st,lsm303agr-magn
 - st,lsm303dlh-magn
 - st,lsm303dlhc-magn
 - st,lsm303dlm-magn
diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
index 60441023..06a4d9c 100644
--- a/drivers/iio/magnetometer/st_magn.h
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -18,6 +18,7 @@
 #define LSM303DLHC_MAGN_DEV_NAME	"lsm303dlhc_magn"
 #define LSM303DLM_MAGN_DEV_NAME		"lsm303dlm_magn"
 #define LIS3MDL_MAGN_DEV_NAME		"lis3mdl"
+#define LSM303AGR_MAGN_DEV_NAME		"lsm303agr_magn"
 
 int st_magn_common_probe(struct iio_dev *indio_dev);
 void st_magn_common_remove(struct iio_dev *indio_dev);
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 4948185..8259e02 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -43,6 +43,7 @@
 #define ST_MAGN_FS_AVL_8000MG			8000
 #define ST_MAGN_FS_AVL_8100MG			8100
 #define ST_MAGN_FS_AVL_12000MG			12000
+#define ST_MAGN_FS_AVL_15000MG			15000
 #define ST_MAGN_FS_AVL_16000MG			16000
 
 /* CUSTOM VALUES FOR SENSOR 0 */
@@ -157,6 +158,29 @@
 #define ST_MAGN_2_OUT_Y_L_ADDR			0x2a
 #define ST_MAGN_2_OUT_Z_L_ADDR			0x2c
 
+/* CUSTOM VALUES FOR SENSOR 3 */
+#define ST_MAGN_3_WAI_ADDR			0x4f
+#define ST_MAGN_3_WAI_EXP			0x40
+#define ST_MAGN_3_ODR_ADDR			0x60
+#define ST_MAGN_3_ODR_MASK			0x0c
+#define ST_MAGN_3_ODR_AVL_10HZ_VAL		0x00
+#define ST_MAGN_3_ODR_AVL_20HZ_VAL		0x01
+#define ST_MAGN_3_ODR_AVL_50HZ_VAL		0x02
+#define ST_MAGN_3_ODR_AVL_100HZ_VAL		0x03
+#define ST_MAGN_3_PW_ADDR			0x60
+#define ST_MAGN_3_PW_MASK			0x03
+#define ST_MAGN_3_PW_ON				0x00
+#define ST_MAGN_3_PW_OFF			0x03
+#define ST_MAGN_3_BDU_ADDR			0x62
+#define ST_MAGN_3_BDU_MASK			0x10
+#define ST_MAGN_3_DRDY_IRQ_ADDR			0x62
+#define ST_MAGN_3_DRDY_INT_MASK			0x01
+#define ST_MAGN_3_FS_AVL_15000_GAIN		1500
+#define ST_MAGN_3_MULTIREAD_BIT			false
+#define ST_MAGN_3_OUT_X_L_ADDR			0x68
+#define ST_MAGN_3_OUT_Y_L_ADDR			0x6a
+#define ST_MAGN_3_OUT_Z_L_ADDR			0x6c
+
 static const struct iio_chan_spec st_magn_16bit_channels[] = {
 	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
@@ -189,6 +213,22 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
 	IIO_CHAN_SOFT_TIMESTAMP(3)
 };
 
+static const struct iio_chan_spec st_magn_3_16bit_channels[] = {
+	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
+			ST_MAGN_3_OUT_X_L_ADDR),
+	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
+			ST_MAGN_3_OUT_Y_L_ADDR),
+	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
+			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
+			ST_MAGN_3_OUT_Z_L_ADDR),
+	IIO_CHAN_SOFT_TIMESTAMP(3)
+};
+
 static const struct st_sensor_settings st_magn_sensors_settings[] = {
 	{
 		.wai = 0, /* This sensor has no valid WhoAmI report 0 */
@@ -403,6 +443,49 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
 		.multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
 		.bootime = 2,
 	},
+	{
+		.wai = ST_MAGN_3_WAI_EXP,
+		.wai_addr = ST_MAGN_3_WAI_ADDR,
+		.sensors_supported = {
+			[0] = LSM303AGR_MAGN_DEV_NAME,
+		},
+		.ch = (struct iio_chan_spec *)st_magn_3_16bit_channels,
+		.odr = {
+			.addr = ST_MAGN_3_ODR_ADDR,
+			.mask = ST_MAGN_3_ODR_MASK,
+			.odr_avl = {
+				{ 10, ST_MAGN_3_ODR_AVL_10HZ_VAL, },
+				{ 20, ST_MAGN_3_ODR_AVL_20HZ_VAL, },
+				{ 50, ST_MAGN_3_ODR_AVL_50HZ_VAL, },
+				{ 100, ST_MAGN_3_ODR_AVL_100HZ_VAL, },
+			},
+		},
+		.pw = {
+			.addr = ST_MAGN_3_PW_ADDR,
+			.mask = ST_MAGN_3_PW_MASK,
+			.value_on = ST_MAGN_3_PW_ON,
+			.value_off = ST_MAGN_3_PW_OFF,
+		},
+		.fs = {
+			.fs_avl = {
+				[0] = {
+					.num = ST_MAGN_FS_AVL_15000MG,
+					.gain = ST_MAGN_3_FS_AVL_15000_GAIN,
+				},
+			},
+			.fs_avl_cnt = 1,
+		},
+		.bdu = {
+			.addr = ST_MAGN_3_BDU_ADDR,
+			.mask = ST_MAGN_3_BDU_MASK,
+		},
+		.drdy_irq = {
+			.addr = ST_MAGN_3_DRDY_IRQ_ADDR,
+			.mask_int1 = ST_MAGN_3_DRDY_INT_MASK,
+		},
+		.multi_read_bit = ST_MAGN_3_MULTIREAD_BIT,
+		.bootime = 2,
+	},
 };
 
 static int st_magn_read_raw(struct iio_dev *indio_dev,
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 5311d8a..afe955b 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -36,6 +36,10 @@ static const struct of_device_id st_magn_of_match[] = {
 		.compatible = "st,lis3mdl-magn",
 		.data = LIS3MDL_MAGN_DEV_NAME,
 	},
+	{
+		.compatible = "st,lsm303agr-magn",
+		.data = LSM303AGR_MAGN_DEV_NAME,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, st_magn_of_match);
@@ -79,6 +83,7 @@ static const struct i2c_device_id st_magn_id_table[] = {
 	{ LSM303DLHC_MAGN_DEV_NAME },
 	{ LSM303DLM_MAGN_DEV_NAME },
 	{ LIS3MDL_MAGN_DEV_NAME },
+	{ LSM303AGR_MAGN_DEV_NAME },
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, st_magn_id_table);
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
index 7adacf1..0abca2c 100644
--- a/drivers/iio/magnetometer/st_magn_spi.c
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -51,6 +51,7 @@ static const struct spi_device_id st_magn_id_table[] = {
 	{ LSM303DLHC_MAGN_DEV_NAME },
 	{ LSM303DLM_MAGN_DEV_NAME },
 	{ LIS3MDL_MAGN_DEV_NAME },
+	{ LSM303AGR_MAGN_DEV_NAME },
 	{},
 };
 MODULE_DEVICE_TABLE(spi, st_magn_id_table);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address
  2015-07-16  9:17 ` [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address Giuseppe Barba
@ 2015-07-19 11:03   ` Jonathan Cameron
  2015-07-20  3:47     ` Denis Ciocca
  2015-07-20 13:04     ` Giuseppe Barba
  0 siblings, 2 replies; 14+ messages in thread
From: Jonathan Cameron @ 2015-07-19 11:03 UTC (permalink / raw)
  To: Giuseppe Barba, linux-iio, Denis CIOCCA

On 16/07/15 10:17, Giuseppe Barba wrote:
> This patch permits to configure the WhoAmI register address
> because some device could doesn't have a standard address
> for this register.
> 
> Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
Hmm. I'd be tempted to rename the DEFAULT WAIT ADDRESS as it's clearly
only the default in the sense it was there first.  Still probably not
worth the hassle..

Looks good to me, but will leave this (and the rest of the series)
on the list for a few days for others to comment. 

cc'd Denis for comments. Ideally patches should also cc the reviewers
listed in MAINTAINERS (I don't care if you cc me as I have filters
set to squash stuff that comes to me and the list into one).

>  drivers/iio/accel/st_accel_core.c               |  4 +++
>  drivers/iio/common/st_sensors/st_sensors_core.c | 44 +++++++++++++++----------
>  drivers/iio/gyro/st_gyro_core.c                 |  3 ++
>  drivers/iio/magnetometer/st_magn_core.c         |  2 ++
>  include/linux/iio/common/st_sensors.h           |  2 ++
>  5 files changed, 37 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
> index 4002e64..7ce027b 100644
> --- a/drivers/iio/accel/st_accel_core.c
> +++ b/drivers/iio/accel/st_accel_core.c
> @@ -226,6 +226,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
>  static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  	{
>  		.wai = ST_ACCEL_1_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS3DH_ACCEL_DEV_NAME,
>  			[1] = LSM303DLHC_ACCEL_DEV_NAME,
> @@ -297,6 +298,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  	},
>  	{
>  		.wai = ST_ACCEL_2_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS331DLH_ACCEL_DEV_NAME,
>  			[1] = LSM303DL_ACCEL_DEV_NAME,
> @@ -359,6 +361,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  	},
>  	{
>  		.wai = ST_ACCEL_3_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LSM330_ACCEL_DEV_NAME,
>  		},
> @@ -437,6 +440,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  	},
>  	{
>  		.wai = ST_ACCEL_4_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS3LV02DL_ACCEL_DEV_NAME,
>  		},
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> index 8086cbc..c0a611e 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -479,35 +479,43 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
>  			int num_sensors_list,
>  			const struct st_sensor_settings *sensor_settings)
>  {
> -	u8 wai;
>  	int i, n, err;
> +	u8 wai, wai_addr, found_it;
>  	struct st_sensor_data *sdata = iio_priv(indio_dev);
>  
> +	found_it = 0;
> +	for (i = 0; i < num_sensors_list; i++) {
> +		for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
> +			if (strcmp(indio_dev->name,
> +				sensor_settings[i].sensors_supported[n]) == 0) {
> +				found_it = 1;
> +				break;
> +			}
> +		}
> +		if (found_it)
> +			break;
> +	}
> +	if (!found_it) {
> +		dev_err(&indio_dev->dev, "device name %s not recognized.\n",
> +							indio_dev->name);
> +		goto sensor_name_mismatch;
> +	}
> +
> +	if (sensor_settings[i].wai_addr != 0)
> +		wai_addr = sensor_settings[i].wai_addr;
> +	else
> +		wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS;
> +
>  	err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
> -					ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
> +					wai_addr, &wai);
>  	if (err < 0) {
>  		dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
>  		goto read_wai_error;
>  	}
>  
> -	for (i = 0; i < num_sensors_list; i++) {
> -		if (sensor_settings[i].wai == wai)
> -			break;
> -	}
> -	if (i == num_sensors_list)
> +	if (sensor_settings[i].wai != wai)
>  		goto device_not_supported;
>  
> -	for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported); n++) {
> -		if (strcmp(indio_dev->name,
> -				&sensor_settings[i].sensors_supported[n][0]) == 0)
> -			break;
> -	}
> -	if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) {
> -		dev_err(&indio_dev->dev, "device name \"%s\" and WhoAmI (0x%02x) mismatch",
> -			indio_dev->name, wai);
> -		goto sensor_name_mismatch;
> -	}
> -
>  	sdata->sensor_settings =
>  			(struct st_sensor_settings *)&sensor_settings[i];
>  
> diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
> index ffe9664..4b993a5 100644
> --- a/drivers/iio/gyro/st_gyro_core.c
> +++ b/drivers/iio/gyro/st_gyro_core.c
> @@ -131,6 +131,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
>  static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  	{
>  		.wai = ST_GYRO_1_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = L3G4200D_GYRO_DEV_NAME,
>  			[1] = LSM330DL_GYRO_DEV_NAME,
> @@ -190,6 +191,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  	},
>  	{
>  		.wai = ST_GYRO_2_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = L3GD20_GYRO_DEV_NAME,
>  			[1] = LSM330D_GYRO_DEV_NAME,
> @@ -252,6 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  	},
>  	{
>  		.wai = ST_GYRO_3_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = L3GD20_GYRO_DEV_NAME,
>  		},
> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
> index b4bcfb7..63da293 100644
> --- a/drivers/iio/magnetometer/st_magn_core.c
> +++ b/drivers/iio/magnetometer/st_magn_core.c
> @@ -268,6 +268,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  	},
>  	{
>  		.wai = ST_MAGN_1_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LSM303DLHC_MAGN_DEV_NAME,
>  			[1] = LSM303DLM_MAGN_DEV_NAME,
> @@ -346,6 +347,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  	},
>  	{
>  		.wai = ST_MAGN_2_WAI_EXP,
> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS3MDL_MAGN_DEV_NAME,
>  		},
> diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
> index 2c476ac..f7c77b4 100644
> --- a/include/linux/iio/common/st_sensors.h
> +++ b/include/linux/iio/common/st_sensors.h
> @@ -166,6 +166,7 @@ struct st_sensor_transfer_function {
>  /**
>   * struct st_sensor_settings - ST specific sensor settings
>   * @wai: Contents of WhoAmI register.
> + * @wai_addr: The address of WhoAmI register
>   * @sensors_supported: List of supported sensors by struct itself.
>   * @ch: IIO channels for the sensor.
>   * @odr: Output data rate register and ODR list available.
> @@ -179,6 +180,7 @@ struct st_sensor_transfer_function {
>   */
>  struct st_sensor_settings {
>  	u8 wai;
> +	u8 wai_addr;
>  	char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
>  	struct iio_chan_spec *ch;
>  	int num_ch;
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/5] iio: st-sensors: add full scale counter field
  2015-07-16  9:17 ` [PATCH 2/5] iio: st-sensors: add full scale counter field Giuseppe Barba
@ 2015-07-19 11:09   ` Jonathan Cameron
  2015-07-20  3:49     ` Denis Ciocca
  0 siblings, 1 reply; 14+ messages in thread
From: Jonathan Cameron @ 2015-07-19 11:09 UTC (permalink / raw)
  To: Giuseppe Barba, linux-iio, Denis CIOCCA

On 16/07/15 10:17, Giuseppe Barba wrote:
> This patch add the full scale list size variable. This is
> needed for code clenup and to enable device with a single
> full scale value.
> 
> Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
Hmm. I guess it is a slightly cleanup.  Not convinced you couldn't have
continued using the 'null' test that was previously used though.
I'm not that bothered either way so will take it if the rest of
the series is fine.

Anyhow, Denis?
> ---
>  drivers/iio/accel/st_accel_core.c               |  4 ++++
>  drivers/iio/common/st_sensors/st_sensors_core.c | 10 +++++-----
>  drivers/iio/gyro/st_gyro_core.c                 |  3 +++
>  drivers/iio/magnetometer/st_magn_core.c         |  2 ++
>  include/linux/iio/common/st_sensors.h           |  1 +
>  5 files changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
> index 7ce027b..207f6ef 100644
> --- a/drivers/iio/accel/st_accel_core.c
> +++ b/drivers/iio/accel/st_accel_core.c
> @@ -283,6 +283,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  					.gain = ST_ACCEL_1_FS_AVL_16_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 4,
>  		},
>  		.bdu = {
>  			.addr = ST_ACCEL_1_BDU_ADDR,
> @@ -346,6 +347,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  					.gain = ST_ACCEL_2_FS_AVL_8_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 3,
>  		},
>  		.bdu = {
>  			.addr = ST_ACCEL_2_BDU_ADDR,
> @@ -421,6 +423,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  					.gain = ST_ACCEL_3_FS_AVL_16_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 5,
>  		},
>  		.bdu = {
>  			.addr = ST_ACCEL_3_BDU_ADDR,
> @@ -480,6 +483,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  					.gain = ST_ACCEL_4_FS_AVL_6_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 2,
>  		},
>  		.bdu = {
>  			.addr = ST_ACCEL_4_BDU_ADDR,
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> index c0a611e..d9845a6 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -106,7 +106,7 @@ static int st_sensors_match_fs(struct st_sensor_settings *sensor_settings,
>  {
>  	int i, ret = -EINVAL;
>  
> -	for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
> +	for (i = 0; i < sensor_settings->fs.fs_avl_cnt; i++) {
>  		if (sensor_settings->fs.fs_avl[i].num == 0)
>  			goto st_sensors_match_odr_error;
>  
> @@ -126,6 +126,9 @@ static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs)
>  	int err, i = 0;
>  	struct st_sensor_data *sdata = iio_priv(indio_dev);
>  
> +	if (sdata->sensor_settings->fs.fs_avl_cnt < 2)
> +		return 0;
> +
>  	err = st_sensors_match_fs(sdata->sensor_settings, fs, &i);
>  	if (err < 0)
>  		goto st_accel_set_fullscale_error;
> @@ -560,10 +563,7 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
>  	struct st_sensor_data *sdata = iio_priv(indio_dev);
>  
>  	mutex_lock(&indio_dev->mlock);
> -	for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
> -		if (sdata->sensor_settings->fs.fs_avl[i].num == 0)
> -			break;
> -
> +	for (i = 0; i < sdata->sensor_settings->fs.fs_avl_cnt; i++) {
>  		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
>  				sdata->sensor_settings->fs.fs_avl[i].gain);
>  	}
> diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
> index 4b993a5..c06e8f7 100644
> --- a/drivers/iio/gyro/st_gyro_core.c
> +++ b/drivers/iio/gyro/st_gyro_core.c
> @@ -177,6 +177,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  					.gain = ST_GYRO_1_FS_AVL_2000_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 3,
>  		},
>  		.bdu = {
>  			.addr = ST_GYRO_1_BDU_ADDR,
> @@ -240,6 +241,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  					.gain = ST_GYRO_2_FS_AVL_2000_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 3,
>  		},
>  		.bdu = {
>  			.addr = ST_GYRO_2_BDU_ADDR,
> @@ -299,6 +301,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  					.gain = ST_GYRO_3_FS_AVL_2000_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 3,
>  		},
>  		.bdu = {
>  			.addr = ST_GYRO_3_BDU_ADDR,
> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
> index 63da293..4c0335b 100644
> --- a/drivers/iio/magnetometer/st_magn_core.c
> +++ b/drivers/iio/magnetometer/st_magn_core.c
> @@ -341,6 +341,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  					.gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z,
>  				},
>  			},
> +			.fs_avl_cnt = 7,
>  		},
>  		.multi_read_bit = ST_MAGN_1_MULTIREAD_BIT,
>  		.bootime = 2,
> @@ -397,6 +398,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  					.gain = ST_MAGN_2_FS_AVL_16000_GAIN,
>  				},
>  			},
> +			.fs_avl_cnt = 4,
>  		},
>  		.multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
>  		.bootime = 2,
> diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
> index f7c77b4..0d7d5bb 100644
> --- a/include/linux/iio/common/st_sensors.h
> +++ b/include/linux/iio/common/st_sensors.h
> @@ -101,6 +101,7 @@ struct st_sensor_fullscale_avl {
>  struct st_sensor_fullscale {
>  	u8 addr;
>  	u8 mask;
> +	u8 fs_avl_cnt;
>  	struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
>  };
>  
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 5/5] iio: st-magn: add support for lsm303agr magnetometer
  2015-07-16  9:17 ` [PATCH 5/5] iio: st-magn: add support for lsm303agr magnetometer Giuseppe Barba
@ 2015-07-19 11:14   ` Jonathan Cameron
  0 siblings, 0 replies; 14+ messages in thread
From: Jonathan Cameron @ 2015-07-19 11:14 UTC (permalink / raw)
  To: Giuseppe Barba, linux-iio

On 16/07/15 10:17, Giuseppe Barba wrote:
> This adds support for the lsm303agr magnetometer.
> 
> Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
Rest of the series looks fine to me.
Will pickup if I get an Ack from Denis and others are happy.
(note I've been lazy and not dived into the datasheets to check
the registers etc). To great a backlog this weekend!

Might have a look at those before applying if I don't think
anyone else has.

Anyhow, good to have yet another part supported.
Don't suppose you fancy picking up the lis3l02dq so I can kill
off my ancient driver for that which is still in staging?
:)
> ---
>  .../devicetree/bindings/iio/st-sensors.txt         |  1 +
>  drivers/iio/magnetometer/st_magn.h                 |  1 +
>  drivers/iio/magnetometer/st_magn_core.c            | 83 ++++++++++++++++++++++
>  drivers/iio/magnetometer/st_magn_i2c.c             |  5 ++
>  drivers/iio/magnetometer/st_magn_spi.c             |  1 +
>  5 files changed, 91 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt
> index d80bdaa..d3ccdb1 100644
> --- a/Documentation/devicetree/bindings/iio/st-sensors.txt
> +++ b/Documentation/devicetree/bindings/iio/st-sensors.txt
> @@ -47,6 +47,7 @@ Gyroscopes:
>  - st,lsm330-gyro
>  
>  Magnetometers:
> +- st,lsm303agr-magn
>  - st,lsm303dlh-magn
>  - st,lsm303dlhc-magn
>  - st,lsm303dlm-magn
> diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
> index 60441023..06a4d9c 100644
> --- a/drivers/iio/magnetometer/st_magn.h
> +++ b/drivers/iio/magnetometer/st_magn.h
> @@ -18,6 +18,7 @@
>  #define LSM303DLHC_MAGN_DEV_NAME	"lsm303dlhc_magn"
>  #define LSM303DLM_MAGN_DEV_NAME		"lsm303dlm_magn"
>  #define LIS3MDL_MAGN_DEV_NAME		"lis3mdl"
> +#define LSM303AGR_MAGN_DEV_NAME		"lsm303agr_magn"
>  
>  int st_magn_common_probe(struct iio_dev *indio_dev);
>  void st_magn_common_remove(struct iio_dev *indio_dev);
> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
> index 4948185..8259e02 100644
> --- a/drivers/iio/magnetometer/st_magn_core.c
> +++ b/drivers/iio/magnetometer/st_magn_core.c
> @@ -43,6 +43,7 @@
>  #define ST_MAGN_FS_AVL_8000MG			8000
>  #define ST_MAGN_FS_AVL_8100MG			8100
>  #define ST_MAGN_FS_AVL_12000MG			12000
> +#define ST_MAGN_FS_AVL_15000MG			15000
>  #define ST_MAGN_FS_AVL_16000MG			16000
>  
>  /* CUSTOM VALUES FOR SENSOR 0 */
> @@ -157,6 +158,29 @@
>  #define ST_MAGN_2_OUT_Y_L_ADDR			0x2a
>  #define ST_MAGN_2_OUT_Z_L_ADDR			0x2c
>  
> +/* CUSTOM VALUES FOR SENSOR 3 */
> +#define ST_MAGN_3_WAI_ADDR			0x4f
> +#define ST_MAGN_3_WAI_EXP			0x40
> +#define ST_MAGN_3_ODR_ADDR			0x60
> +#define ST_MAGN_3_ODR_MASK			0x0c
> +#define ST_MAGN_3_ODR_AVL_10HZ_VAL		0x00
> +#define ST_MAGN_3_ODR_AVL_20HZ_VAL		0x01
> +#define ST_MAGN_3_ODR_AVL_50HZ_VAL		0x02
> +#define ST_MAGN_3_ODR_AVL_100HZ_VAL		0x03
> +#define ST_MAGN_3_PW_ADDR			0x60
> +#define ST_MAGN_3_PW_MASK			0x03
> +#define ST_MAGN_3_PW_ON				0x00
> +#define ST_MAGN_3_PW_OFF			0x03
> +#define ST_MAGN_3_BDU_ADDR			0x62
> +#define ST_MAGN_3_BDU_MASK			0x10
> +#define ST_MAGN_3_DRDY_IRQ_ADDR			0x62
> +#define ST_MAGN_3_DRDY_INT_MASK			0x01
> +#define ST_MAGN_3_FS_AVL_15000_GAIN		1500
> +#define ST_MAGN_3_MULTIREAD_BIT			false
> +#define ST_MAGN_3_OUT_X_L_ADDR			0x68
> +#define ST_MAGN_3_OUT_Y_L_ADDR			0x6a
> +#define ST_MAGN_3_OUT_Z_L_ADDR			0x6c
> +
>  static const struct iio_chan_spec st_magn_16bit_channels[] = {
>  	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
>  			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> @@ -189,6 +213,22 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
>  	IIO_CHAN_SOFT_TIMESTAMP(3)
>  };
>  
> +static const struct iio_chan_spec st_magn_3_16bit_channels[] = {
> +	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
> +			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> +			ST_SENSORS_SCAN_X, 1, IIO_MOD_X, 's', IIO_LE, 16, 16,
> +			ST_MAGN_3_OUT_X_L_ADDR),
> +	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
> +			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> +			ST_SENSORS_SCAN_Y, 1, IIO_MOD_Y, 's', IIO_LE, 16, 16,
> +			ST_MAGN_3_OUT_Y_L_ADDR),
> +	ST_SENSORS_LSM_CHANNELS(IIO_MAGN,
> +			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> +			ST_SENSORS_SCAN_Z, 1, IIO_MOD_Z, 's', IIO_LE, 16, 16,
> +			ST_MAGN_3_OUT_Z_L_ADDR),
> +	IIO_CHAN_SOFT_TIMESTAMP(3)
> +};
> +
>  static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  	{
>  		.wai = 0, /* This sensor has no valid WhoAmI report 0 */
> @@ -403,6 +443,49 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  		.multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
>  		.bootime = 2,
>  	},
> +	{
> +		.wai = ST_MAGN_3_WAI_EXP,
> +		.wai_addr = ST_MAGN_3_WAI_ADDR,
> +		.sensors_supported = {
> +			[0] = LSM303AGR_MAGN_DEV_NAME,
> +		},
> +		.ch = (struct iio_chan_spec *)st_magn_3_16bit_channels,
> +		.odr = {
> +			.addr = ST_MAGN_3_ODR_ADDR,
> +			.mask = ST_MAGN_3_ODR_MASK,
> +			.odr_avl = {
> +				{ 10, ST_MAGN_3_ODR_AVL_10HZ_VAL, },
> +				{ 20, ST_MAGN_3_ODR_AVL_20HZ_VAL, },
> +				{ 50, ST_MAGN_3_ODR_AVL_50HZ_VAL, },
> +				{ 100, ST_MAGN_3_ODR_AVL_100HZ_VAL, },
> +			},
> +		},
> +		.pw = {
> +			.addr = ST_MAGN_3_PW_ADDR,
> +			.mask = ST_MAGN_3_PW_MASK,
> +			.value_on = ST_MAGN_3_PW_ON,
> +			.value_off = ST_MAGN_3_PW_OFF,
> +		},
> +		.fs = {
> +			.fs_avl = {
> +				[0] = {
> +					.num = ST_MAGN_FS_AVL_15000MG,
> +					.gain = ST_MAGN_3_FS_AVL_15000_GAIN,
> +				},
> +			},
> +			.fs_avl_cnt = 1,
> +		},
> +		.bdu = {
> +			.addr = ST_MAGN_3_BDU_ADDR,
> +			.mask = ST_MAGN_3_BDU_MASK,
> +		},
> +		.drdy_irq = {
> +			.addr = ST_MAGN_3_DRDY_IRQ_ADDR,
> +			.mask_int1 = ST_MAGN_3_DRDY_INT_MASK,
> +		},
> +		.multi_read_bit = ST_MAGN_3_MULTIREAD_BIT,
> +		.bootime = 2,
> +	},
>  };
>  
>  static int st_magn_read_raw(struct iio_dev *indio_dev,
> diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
> index 5311d8a..afe955b 100644
> --- a/drivers/iio/magnetometer/st_magn_i2c.c
> +++ b/drivers/iio/magnetometer/st_magn_i2c.c
> @@ -36,6 +36,10 @@ static const struct of_device_id st_magn_of_match[] = {
>  		.compatible = "st,lis3mdl-magn",
>  		.data = LIS3MDL_MAGN_DEV_NAME,
>  	},
> +	{
> +		.compatible = "st,lsm303agr-magn",
> +		.data = LSM303AGR_MAGN_DEV_NAME,
> +	},
>  	{},
>  };
>  MODULE_DEVICE_TABLE(of, st_magn_of_match);
> @@ -79,6 +83,7 @@ static const struct i2c_device_id st_magn_id_table[] = {
>  	{ LSM303DLHC_MAGN_DEV_NAME },
>  	{ LSM303DLM_MAGN_DEV_NAME },
>  	{ LIS3MDL_MAGN_DEV_NAME },
> +	{ LSM303AGR_MAGN_DEV_NAME },
>  	{},
>  };
>  MODULE_DEVICE_TABLE(i2c, st_magn_id_table);
> diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
> index 7adacf1..0abca2c 100644
> --- a/drivers/iio/magnetometer/st_magn_spi.c
> +++ b/drivers/iio/magnetometer/st_magn_spi.c
> @@ -51,6 +51,7 @@ static const struct spi_device_id st_magn_id_table[] = {
>  	{ LSM303DLHC_MAGN_DEV_NAME },
>  	{ LSM303DLM_MAGN_DEV_NAME },
>  	{ LIS3MDL_MAGN_DEV_NAME },
> +	{ LSM303AGR_MAGN_DEV_NAME },
>  	{},
>  };
>  MODULE_DEVICE_TABLE(spi, st_magn_id_table);
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address
  2015-07-19 11:03   ` Jonathan Cameron
@ 2015-07-20  3:47     ` Denis Ciocca
  2015-07-20 12:41       ` Giuseppe Barba
  2015-07-20 13:04     ` Giuseppe Barba
  1 sibling, 1 reply; 14+ messages in thread
From: Denis Ciocca @ 2015-07-20  3:47 UTC (permalink / raw)
  To: Jonathan Cameron, Giuseppe BARBA, linux-iio

Hi Giuseppe, Jonathan,

my comments inline.


On 07/19/2015 07:03 PM, Jonathan Cameron wrote:
> On 16/07/15 10:17, Giuseppe Barba wrote:
>> This patch permits to configure the WhoAmI register address
>> because some device could doesn't have a standard address
>> for this register.
>>
>> Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
> Hmm. I'd be tempted to rename the DEFAULT WAIT ADDRESS as it's clearly
> only the default in the sense it was there first.  Still probably not
> worth the hassle..
>
> Looks good to me, but will leave this (and the rest of the series)
> on the list for a few days for others to comment.
>
> cc'd Denis for comments. Ideally patches should also cc the reviewers
> listed in MAINTAINERS (I don't care if you cc me as I have filters
> set to squash stuff that comes to me and the list into one).
>
>>   drivers/iio/accel/st_accel_core.c               |  4 +++
>>   drivers/iio/common/st_sensors/st_sensors_core.c | 44 +++++++++++++++----------
>>   drivers/iio/gyro/st_gyro_core.c                 |  3 ++
>>   drivers/iio/magnetometer/st_magn_core.c         |  2 ++
>>   include/linux/iio/common/st_sensors.h           |  2 ++
>>   5 files changed, 37 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
>> index 4002e64..7ce027b 100644
>> --- a/drivers/iio/accel/st_accel_core.c
>> +++ b/drivers/iio/accel/st_accel_core.c
>> @@ -226,6 +226,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
>>   static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   	{
>>   		.wai = ST_ACCEL_1_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = LIS3DH_ACCEL_DEV_NAME,
>>   			[1] = LSM303DLHC_ACCEL_DEV_NAME,
>> @@ -297,6 +298,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   	},
>>   	{
>>   		.wai = ST_ACCEL_2_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = LIS331DLH_ACCEL_DEV_NAME,
>>   			[1] = LSM303DL_ACCEL_DEV_NAME,
>> @@ -359,6 +361,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   	},
>>   	{
>>   		.wai = ST_ACCEL_3_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = LSM330_ACCEL_DEV_NAME,
>>   		},
>> @@ -437,6 +440,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   	},
>>   	{
>>   		.wai = ST_ACCEL_4_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = LIS3LV02DL_ACCEL_DEV_NAME,
>>   		},
>> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
>> index 8086cbc..c0a611e 100644
>> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
>> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
>> @@ -479,35 +479,43 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
>>   			int num_sensors_list,
>>   			const struct st_sensor_settings *sensor_settings)
>>   {
>> -	u8 wai;
>>   	int i, n, err;
>> +	u8 wai, wai_addr, found_it;
>>   	struct st_sensor_data *sdata = iio_priv(indio_dev);
>>   
>> +	found_it = 0;
>> +	for (i = 0; i < num_sensors_list; i++) {
>> +		for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
>> +			if (strcmp(indio_dev->name,
>> +				sensor_settings[i].sensors_supported[n]) == 0) {
>> +				found_it = 1;
>> +				break;
>> +			}
>> +		}
>> +		if (found_it)
>> +			break;
found_it is very ugly :). No need to use the variable, if (n != 
ST_SENSORS_MAX_4WAI) it means sensor found.

>> +	}
>> +	if (!found_it) {
here just if (i == num_sensors_list)

>> +		dev_err(&indio_dev->dev, "device name %s not recognized.\n",
>> +							indio_dev->name);
>> +		goto sensor_name_mismatch;
>> +	}
>> +
>> +	if (sensor_settings[i].wai_addr != 0)
>> +		wai_addr = sensor_settings[i].wai_addr;
>> +	else
>> +		wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS;
No need. All sensors must be filled with wai_addr in the static array. 
You forget to fill pressure sensors...

>> +
>>   	err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
>> -					ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
>> +					wai_addr, &wai);
>>   	if (err < 0) {
>>   		dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
>>   		goto read_wai_error;
>>   	}
>>   
>> -	for (i = 0; i < num_sensors_list; i++) {
>> -		if (sensor_settings[i].wai == wai)
>> -			break;
>> -	}
>> -	if (i == num_sensors_list)
>> +	if (sensor_settings[i].wai != wai)
>>   		goto device_not_supported;
>>   
>> -	for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported); n++) {
>> -		if (strcmp(indio_dev->name,
>> -				&sensor_settings[i].sensors_supported[n][0]) == 0)
>> -			break;
>> -	}
>> -	if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) {
>> -		dev_err(&indio_dev->dev, "device name \"%s\" and WhoAmI (0x%02x) mismatch",
>> -			indio_dev->name, wai);
>> -		goto sensor_name_mismatch;
>> -	}
>> -
>>   	sdata->sensor_settings =
>>   			(struct st_sensor_settings *)&sensor_settings[i];
>>   
>> diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
>> index ffe9664..4b993a5 100644
>> --- a/drivers/iio/gyro/st_gyro_core.c
>> +++ b/drivers/iio/gyro/st_gyro_core.c
>> @@ -131,6 +131,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
>>   static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>>   	{
>>   		.wai = ST_GYRO_1_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = L3G4200D_GYRO_DEV_NAME,
>>   			[1] = LSM330DL_GYRO_DEV_NAME,
>> @@ -190,6 +191,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>>   	},
>>   	{
>>   		.wai = ST_GYRO_2_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = L3GD20_GYRO_DEV_NAME,
>>   			[1] = LSM330D_GYRO_DEV_NAME,
>> @@ -252,6 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>>   	},
>>   	{
>>   		.wai = ST_GYRO_3_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = L3GD20_GYRO_DEV_NAME,
>>   		},
>> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
>> index b4bcfb7..63da293 100644
>> --- a/drivers/iio/magnetometer/st_magn_core.c
>> +++ b/drivers/iio/magnetometer/st_magn_core.c
>> @@ -268,6 +268,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>>   	},
>>   	{
>>   		.wai = ST_MAGN_1_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = LSM303DLHC_MAGN_DEV_NAME,
>>   			[1] = LSM303DLM_MAGN_DEV_NAME,
>> @@ -346,6 +347,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>>   	},
>>   	{
>>   		.wai = ST_MAGN_2_WAI_EXP,
>> +		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>   		.sensors_supported = {
>>   			[0] = LIS3MDL_MAGN_DEV_NAME,
>>   		},
>> diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
>> index 2c476ac..f7c77b4 100644
>> --- a/include/linux/iio/common/st_sensors.h
>> +++ b/include/linux/iio/common/st_sensors.h
>> @@ -166,6 +166,7 @@ struct st_sensor_transfer_function {
>>   /**
>>    * struct st_sensor_settings - ST specific sensor settings
>>    * @wai: Contents of WhoAmI register.
>> + * @wai_addr: The address of WhoAmI register
Forget . at the end.

>>    * @sensors_supported: List of supported sensors by struct itself.
>>    * @ch: IIO channels for the sensor.
>>    * @odr: Output data rate register and ODR list available.
>> @@ -179,6 +180,7 @@ struct st_sensor_transfer_function {
>>    */
>>   struct st_sensor_settings {
>>   	u8 wai;
>> +	u8 wai_addr;
>>   	char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
>>   	struct iio_chan_spec *ch;
>>   	int num_ch;
>>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/5] iio: st-sensors: add full scale counter field
  2015-07-19 11:09   ` Jonathan Cameron
@ 2015-07-20  3:49     ` Denis Ciocca
  2015-07-20 13:12       ` Giuseppe Barba
  0 siblings, 1 reply; 14+ messages in thread
From: Denis Ciocca @ 2015-07-20  3:49 UTC (permalink / raw)
  To: Jonathan Cameron, Giuseppe BARBA, linux-iio

I didn't get the benefit of this one...Just keep one more variable in 
memory in the long array. And also forget again pressure sensors...

Denis


On 07/19/2015 07:09 PM, Jonathan Cameron wrote:
> On 16/07/15 10:17, Giuseppe Barba wrote:
>> This patch add the full scale list size variable. This is
>> needed for code clenup and to enable device with a single
>> full scale value.
>>
>> Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
> Hmm. I guess it is a slightly cleanup.  Not convinced you couldn't have
> continued using the 'null' test that was previously used though.
> I'm not that bothered either way so will take it if the rest of
> the series is fine.
>
> Anyhow, Denis?
>> ---
>>   drivers/iio/accel/st_accel_core.c               |  4 ++++
>>   drivers/iio/common/st_sensors/st_sensors_core.c | 10 +++++-----
>>   drivers/iio/gyro/st_gyro_core.c                 |  3 +++
>>   drivers/iio/magnetometer/st_magn_core.c         |  2 ++
>>   include/linux/iio/common/st_sensors.h           |  1 +
>>   5 files changed, 15 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
>> index 7ce027b..207f6ef 100644
>> --- a/drivers/iio/accel/st_accel_core.c
>> +++ b/drivers/iio/accel/st_accel_core.c
>> @@ -283,6 +283,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   					.gain = ST_ACCEL_1_FS_AVL_16_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 4,
>>   		},
>>   		.bdu = {
>>   			.addr = ST_ACCEL_1_BDU_ADDR,
>> @@ -346,6 +347,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   					.gain = ST_ACCEL_2_FS_AVL_8_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 3,
>>   		},
>>   		.bdu = {
>>   			.addr = ST_ACCEL_2_BDU_ADDR,
>> @@ -421,6 +423,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   					.gain = ST_ACCEL_3_FS_AVL_16_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 5,
>>   		},
>>   		.bdu = {
>>   			.addr = ST_ACCEL_3_BDU_ADDR,
>> @@ -480,6 +483,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>   					.gain = ST_ACCEL_4_FS_AVL_6_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 2,
>>   		},
>>   		.bdu = {
>>   			.addr = ST_ACCEL_4_BDU_ADDR,
>> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
>> index c0a611e..d9845a6 100644
>> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
>> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
>> @@ -106,7 +106,7 @@ static int st_sensors_match_fs(struct st_sensor_settings *sensor_settings,
>>   {
>>   	int i, ret = -EINVAL;
>>   
>> -	for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
>> +	for (i = 0; i < sensor_settings->fs.fs_avl_cnt; i++) {
>>   		if (sensor_settings->fs.fs_avl[i].num == 0)
>>   			goto st_sensors_match_odr_error;
>>   
>> @@ -126,6 +126,9 @@ static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs)
>>   	int err, i = 0;
>>   	struct st_sensor_data *sdata = iio_priv(indio_dev);
>>   
>> +	if (sdata->sensor_settings->fs.fs_avl_cnt < 2)
>> +		return 0;
>> +
>>   	err = st_sensors_match_fs(sdata->sensor_settings, fs, &i);
>>   	if (err < 0)
>>   		goto st_accel_set_fullscale_error;
>> @@ -560,10 +563,7 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
>>   	struct st_sensor_data *sdata = iio_priv(indio_dev);
>>   
>>   	mutex_lock(&indio_dev->mlock);
>> -	for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
>> -		if (sdata->sensor_settings->fs.fs_avl[i].num == 0)
>> -			break;
>> -
>> +	for (i = 0; i < sdata->sensor_settings->fs.fs_avl_cnt; i++) {
>>   		len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
>>   				sdata->sensor_settings->fs.fs_avl[i].gain);
>>   	}
>> diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
>> index 4b993a5..c06e8f7 100644
>> --- a/drivers/iio/gyro/st_gyro_core.c
>> +++ b/drivers/iio/gyro/st_gyro_core.c
>> @@ -177,6 +177,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>>   					.gain = ST_GYRO_1_FS_AVL_2000_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 3,
>>   		},
>>   		.bdu = {
>>   			.addr = ST_GYRO_1_BDU_ADDR,
>> @@ -240,6 +241,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>>   					.gain = ST_GYRO_2_FS_AVL_2000_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 3,
>>   		},
>>   		.bdu = {
>>   			.addr = ST_GYRO_2_BDU_ADDR,
>> @@ -299,6 +301,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>>   					.gain = ST_GYRO_3_FS_AVL_2000_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 3,
>>   		},
>>   		.bdu = {
>>   			.addr = ST_GYRO_3_BDU_ADDR,
>> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
>> index 63da293..4c0335b 100644
>> --- a/drivers/iio/magnetometer/st_magn_core.c
>> +++ b/drivers/iio/magnetometer/st_magn_core.c
>> @@ -341,6 +341,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>>   					.gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 7,
>>   		},
>>   		.multi_read_bit = ST_MAGN_1_MULTIREAD_BIT,
>>   		.bootime = 2,
>> @@ -397,6 +398,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>>   					.gain = ST_MAGN_2_FS_AVL_16000_GAIN,
>>   				},
>>   			},
>> +			.fs_avl_cnt = 4,
>>   		},
>>   		.multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
>>   		.bootime = 2,
>> diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
>> index f7c77b4..0d7d5bb 100644
>> --- a/include/linux/iio/common/st_sensors.h
>> +++ b/include/linux/iio/common/st_sensors.h
>> @@ -101,6 +101,7 @@ struct st_sensor_fullscale_avl {
>>   struct st_sensor_fullscale {
>>   	u8 addr;
>>   	u8 mask;
>> +	u8 fs_avl_cnt;
>>   	struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
>>   };
>>   
>>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address
  2015-07-20  3:47     ` Denis Ciocca
@ 2015-07-20 12:41       ` Giuseppe Barba
  0 siblings, 0 replies; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-20 12:41 UTC (permalink / raw)
  To: Denis Ciocca; +Cc: Jonathan Cameron, Giuseppe BARBA, linux-iio

Hi Jonathan and Denis,

Thanks for your review. I'll fix the patch and send back to you the V2 version.

Regards,
Giuseppe.

2015-07-20 5:47 GMT+02:00 Denis Ciocca <denis.ciocca@st.com>:
> Hi Giuseppe, Jonathan,
>
> my comments inline.
>
>
> On 07/19/2015 07:03 PM, Jonathan Cameron wrote:
>>
>> On 16/07/15 10:17, Giuseppe Barba wrote:
>>>
>>> This patch permits to configure the WhoAmI register address
>>> because some device could doesn't have a standard address
>>> for this register.
>>>
>>> Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
>>
>> Hmm. I'd be tempted to rename the DEFAULT WAIT ADDRESS as it's clearly
>> only the default in the sense it was there first.  Still probably not
>> worth the hassle..
>>
>> Looks good to me, but will leave this (and the rest of the series)
>> on the list for a few days for others to comment.
>>
>> cc'd Denis for comments. Ideally patches should also cc the reviewers
>> listed in MAINTAINERS (I don't care if you cc me as I have filters
>> set to squash stuff that comes to me and the list into one).
>>
>>>   drivers/iio/accel/st_accel_core.c               |  4 +++
>>>   drivers/iio/common/st_sensors/st_sensors_core.c | 44
>>> +++++++++++++++----------
>>>   drivers/iio/gyro/st_gyro_core.c                 |  3 ++
>>>   drivers/iio/magnetometer/st_magn_core.c         |  2 ++
>>>   include/linux/iio/common/st_sensors.h           |  2 ++
>>>   5 files changed, 37 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/drivers/iio/accel/st_accel_core.c
>>> b/drivers/iio/accel/st_accel_core.c
>>> index 4002e64..7ce027b 100644
>>> --- a/drivers/iio/accel/st_accel_core.c
>>> +++ b/drivers/iio/accel/st_accel_core.c
>>> @@ -226,6 +226,7 @@ static const struct iio_chan_spec
>>> st_accel_16bit_channels[] = {
>>>   static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>>         {
>>>                 .wai = ST_ACCEL_1_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = LIS3DH_ACCEL_DEV_NAME,
>>>                         [1] = LSM303DLHC_ACCEL_DEV_NAME,
>>> @@ -297,6 +298,7 @@ static const struct st_sensor_settings
>>> st_accel_sensors_settings[] = {
>>>         },
>>>         {
>>>                 .wai = ST_ACCEL_2_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = LIS331DLH_ACCEL_DEV_NAME,
>>>                         [1] = LSM303DL_ACCEL_DEV_NAME,
>>> @@ -359,6 +361,7 @@ static const struct st_sensor_settings
>>> st_accel_sensors_settings[] = {
>>>         },
>>>         {
>>>                 .wai = ST_ACCEL_3_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = LSM330_ACCEL_DEV_NAME,
>>>                 },
>>> @@ -437,6 +440,7 @@ static const struct st_sensor_settings
>>> st_accel_sensors_settings[] = {
>>>         },
>>>         {
>>>                 .wai = ST_ACCEL_4_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = LIS3LV02DL_ACCEL_DEV_NAME,
>>>                 },
>>> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c
>>> b/drivers/iio/common/st_sensors/st_sensors_core.c
>>> index 8086cbc..c0a611e 100644
>>> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
>>> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
>>> @@ -479,35 +479,43 @@ int st_sensors_check_device_support(struct iio_dev
>>> *indio_dev,
>>>                         int num_sensors_list,
>>>                         const struct st_sensor_settings *sensor_settings)
>>>   {
>>> -       u8 wai;
>>>         int i, n, err;
>>> +       u8 wai, wai_addr, found_it;
>>>         struct st_sensor_data *sdata = iio_priv(indio_dev);
>>>   +     found_it = 0;
>>> +       for (i = 0; i < num_sensors_list; i++) {
>>> +               for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
>>> +                       if (strcmp(indio_dev->name,
>>> +                               sensor_settings[i].sensors_supported[n])
>>> == 0) {
>>> +                               found_it = 1;
>>> +                               break;
>>> +                       }
>>> +               }
>>> +               if (found_it)
>>> +                       break;
>
> found_it is very ugly :). No need to use the variable, if (n !=
> ST_SENSORS_MAX_4WAI) it means sensor found.
>
>>> +       }
>>> +       if (!found_it) {
>
> here just if (i == num_sensors_list)
>
>>> +               dev_err(&indio_dev->dev, "device name %s not
>>> recognized.\n",
>>> +                                                       indio_dev->name);
>>> +               goto sensor_name_mismatch;
>>> +       }
>>> +
>>> +       if (sensor_settings[i].wai_addr != 0)
>>> +               wai_addr = sensor_settings[i].wai_addr;
>>> +       else
>>> +               wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS;
>
> No need. All sensors must be filled with wai_addr in the static array. You
> forget to fill pressure sensors...
>
>
>>> +
>>>         err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
>>> -                                       ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>> &wai);
>>> +                                       wai_addr, &wai);
>>>         if (err < 0) {
>>>                 dev_err(&indio_dev->dev, "failed to read Who-Am-I
>>> register.\n");
>>>                 goto read_wai_error;
>>>         }
>>>   -     for (i = 0; i < num_sensors_list; i++) {
>>> -               if (sensor_settings[i].wai == wai)
>>> -                       break;
>>> -       }
>>> -       if (i == num_sensors_list)
>>> +       if (sensor_settings[i].wai != wai)
>>>                 goto device_not_supported;
>>>   -     for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported);
>>> n++) {
>>> -               if (strcmp(indio_dev->name,
>>> -
>>> &sensor_settings[i].sensors_supported[n][0]) == 0)
>>> -                       break;
>>> -       }
>>> -       if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) {
>>> -               dev_err(&indio_dev->dev, "device name \"%s\" and WhoAmI
>>> (0x%02x) mismatch",
>>> -                       indio_dev->name, wai);
>>> -               goto sensor_name_mismatch;
>>> -       }
>>> -
>>>         sdata->sensor_settings =
>>>                         (struct st_sensor_settings *)&sensor_settings[i];
>>>   diff --git a/drivers/iio/gyro/st_gyro_core.c
>>> b/drivers/iio/gyro/st_gyro_core.c
>>> index ffe9664..4b993a5 100644
>>> --- a/drivers/iio/gyro/st_gyro_core.c
>>> +++ b/drivers/iio/gyro/st_gyro_core.c
>>> @@ -131,6 +131,7 @@ static const struct iio_chan_spec
>>> st_gyro_16bit_channels[] = {
>>>   static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>>>         {
>>>                 .wai = ST_GYRO_1_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = L3G4200D_GYRO_DEV_NAME,
>>>                         [1] = LSM330DL_GYRO_DEV_NAME,
>>> @@ -190,6 +191,7 @@ static const struct st_sensor_settings
>>> st_gyro_sensors_settings[] = {
>>>         },
>>>         {
>>>                 .wai = ST_GYRO_2_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = L3GD20_GYRO_DEV_NAME,
>>>                         [1] = LSM330D_GYRO_DEV_NAME,
>>> @@ -252,6 +254,7 @@ static const struct st_sensor_settings
>>> st_gyro_sensors_settings[] = {
>>>         },
>>>         {
>>>                 .wai = ST_GYRO_3_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = L3GD20_GYRO_DEV_NAME,
>>>                 },
>>> diff --git a/drivers/iio/magnetometer/st_magn_core.c
>>> b/drivers/iio/magnetometer/st_magn_core.c
>>> index b4bcfb7..63da293 100644
>>> --- a/drivers/iio/magnetometer/st_magn_core.c
>>> +++ b/drivers/iio/magnetometer/st_magn_core.c
>>> @@ -268,6 +268,7 @@ static const struct st_sensor_settings
>>> st_magn_sensors_settings[] = {
>>>         },
>>>         {
>>>                 .wai = ST_MAGN_1_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = LSM303DLHC_MAGN_DEV_NAME,
>>>                         [1] = LSM303DLM_MAGN_DEV_NAME,
>>> @@ -346,6 +347,7 @@ static const struct st_sensor_settings
>>> st_magn_sensors_settings[] = {
>>>         },
>>>         {
>>>                 .wai = ST_MAGN_2_WAI_EXP,
>>> +               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>>                 .sensors_supported = {
>>>                         [0] = LIS3MDL_MAGN_DEV_NAME,
>>>                 },
>>> diff --git a/include/linux/iio/common/st_sensors.h
>>> b/include/linux/iio/common/st_sensors.h
>>> index 2c476ac..f7c77b4 100644
>>> --- a/include/linux/iio/common/st_sensors.h
>>> +++ b/include/linux/iio/common/st_sensors.h
>>> @@ -166,6 +166,7 @@ struct st_sensor_transfer_function {
>>>   /**
>>>    * struct st_sensor_settings - ST specific sensor settings
>>>    * @wai: Contents of WhoAmI register.
>>> + * @wai_addr: The address of WhoAmI register
>
> Forget . at the end.
>
>>>    * @sensors_supported: List of supported sensors by struct itself.
>>>    * @ch: IIO channels for the sensor.
>>>    * @odr: Output data rate register and ODR list available.
>>> @@ -179,6 +180,7 @@ struct st_sensor_transfer_function {
>>>    */
>>>   struct st_sensor_settings {
>>>         u8 wai;
>>> +       u8 wai_addr;
>>>         char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
>>>         struct iio_chan_spec *ch;
>>>         int num_ch;
>>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address
  2015-07-19 11:03   ` Jonathan Cameron
  2015-07-20  3:47     ` Denis Ciocca
@ 2015-07-20 13:04     ` Giuseppe Barba
  1 sibling, 0 replies; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-20 13:04 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Giuseppe Barba, linux-iio, Denis CIOCCA

Hi Jonathan,

> Hmm. I'd be tempted to rename the DEFAULT WAIT ADDRESS as it's clearly
> only the default in the sense it was there first.  Still probably not
> worth the hassle..

I would prefer to be consistent with the naming convention taken by
Denis that uses the ...DEFAULT... name for other macros.
What do you think?

Regards,
Giuseppe.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/5] iio: st-sensors: add full scale counter field
  2015-07-20  3:49     ` Denis Ciocca
@ 2015-07-20 13:12       ` Giuseppe Barba
  0 siblings, 0 replies; 14+ messages in thread
From: Giuseppe Barba @ 2015-07-20 13:12 UTC (permalink / raw)
  To: Denis Ciocca; +Cc: Jonathan Cameron, Giuseppe BARBA, linux-iio

Hi Denis,

2015-07-20 5:49 GMT+02:00 Denis Ciocca <denis.ciocca@st.com>:
> I didn't get the benefit of this one...Just keep one more variable in memory
> in the long array. And also forget again pressure sensors...

The intent of this was to consider the case of sensors that you haven't the
possibility to change its full scale.
I'm agree with you and I'll change the code to avoid this new field.

Thanks,
Giuseppe

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-07-20 13:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-16  9:17 [PATCH 0/5] Added ST LSM303AGR sensor Giuseppe Barba
2015-07-16  9:17 ` [PATCH 1/5] iio: st-sensors: add configuration for WhoAmI address Giuseppe Barba
2015-07-19 11:03   ` Jonathan Cameron
2015-07-20  3:47     ` Denis Ciocca
2015-07-20 12:41       ` Giuseppe Barba
2015-07-20 13:04     ` Giuseppe Barba
2015-07-16  9:17 ` [PATCH 2/5] iio: st-sensors: add full scale counter field Giuseppe Barba
2015-07-19 11:09   ` Jonathan Cameron
2015-07-20  3:49     ` Denis Ciocca
2015-07-20 13:12       ` Giuseppe Barba
2015-07-16  9:17 ` [PATCH 3/5] iio: st_magn: Add irq trigger handling Giuseppe Barba
2015-07-16  9:17 ` [PATCH 4/5] iio: st-accel: add support for lsm303agr accelerometer Giuseppe Barba
2015-07-16  9:17 ` [PATCH 5/5] iio: st-magn: add support for lsm303agr magnetometer Giuseppe Barba
2015-07-19 11:14   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.