All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] ST Sensors: inline sensor data
@ 2016-11-09 15:09 Linus Walleij
  2016-11-09 15:09 ` [PATCH 1/4] iio: accel: st_accel: inline per-sensor data Linus Walleij
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Linus Walleij @ 2016-11-09 15:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard,
	Linus Walleij

Based on a comment from Jonathan that he would not do this kludgy
define-then-use for all the sensor properties today, refactor all
the ST sensors by inlining the per-sensor data.

Linus Walleij (4):
  iio: accel: st_accel: inline per-sensor data
  iio: gyro: st_gyro: inline per-sensor data
  iio: magn: st_magn: inline per-sensor data
  iio: pressure: st_pressure: inline per-sensor data

 drivers/iio/accel/st_accel_core.c       | 538 +++++++++++---------------------
 drivers/iio/gyro/st_gyro_core.c         | 205 ++++--------
 drivers/iio/magnetometer/st_magn_core.c | 376 ++++++++--------------
 drivers/iio/pressure/st_pressure_core.c | 257 ++++++---------
 4 files changed, 460 insertions(+), 916 deletions(-)

-- 
2.7.4


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

* [PATCH 1/4] iio: accel: st_accel: inline per-sensor data
  2016-11-09 15:09 [PATCH 0/4] ST Sensors: inline sensor data Linus Walleij
@ 2016-11-09 15:09 ` Linus Walleij
  2016-11-12 15:29   ` Jonathan Cameron
  2016-11-09 15:09 ` [PATCH 2/4] iio: gyro: st_gyro: " Linus Walleij
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2016-11-09 15:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard,
	Linus Walleij

We have #defines for all the individual sensor registers and
value/mask pairs #defined at the top of the file and used at
exactly one spot.

This is usually good if the #defines give a meaning to the
opaque magic numbers.

However in this case, the semantic meaning is inherent in the
name of the C99-addressable fields, and that means duplication
of information, and only makes the code hard to maintain since
you every time have to add a new #define AND update the site
where it is to be used.

Get rid of the #defines and just open code the values into the
appropriate struct elements. Make sure to explicitly address
the .hz and .value fields in the st_sensor_odr_avl struct
so that the meaning of all values is clear.

This patch is purely syntactic should have no semantic effect.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/accel/st_accel_core.c | 538 +++++++++++++-------------------------
 1 file changed, 177 insertions(+), 361 deletions(-)

diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index da3fb069ec5c..d21b2dbe7432 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -43,194 +43,6 @@
 #define ST_ACCEL_FS_AVL_200G			200
 #define ST_ACCEL_FS_AVL_400G			400
 
-/* CUSTOM VALUES FOR SENSOR 1 */
-#define ST_ACCEL_1_WAI_EXP			0x33
-#define ST_ACCEL_1_ODR_ADDR			0x20
-#define ST_ACCEL_1_ODR_MASK			0xf0
-#define ST_ACCEL_1_ODR_AVL_1HZ_VAL		0x01
-#define ST_ACCEL_1_ODR_AVL_10HZ_VAL		0x02
-#define ST_ACCEL_1_ODR_AVL_25HZ_VAL		0x03
-#define ST_ACCEL_1_ODR_AVL_50HZ_VAL		0x04
-#define ST_ACCEL_1_ODR_AVL_100HZ_VAL		0x05
-#define ST_ACCEL_1_ODR_AVL_200HZ_VAL		0x06
-#define ST_ACCEL_1_ODR_AVL_400HZ_VAL		0x07
-#define ST_ACCEL_1_ODR_AVL_1600HZ_VAL		0x08
-#define ST_ACCEL_1_FS_ADDR			0x23
-#define ST_ACCEL_1_FS_MASK			0x30
-#define ST_ACCEL_1_FS_AVL_2_VAL			0x00
-#define ST_ACCEL_1_FS_AVL_4_VAL			0x01
-#define ST_ACCEL_1_FS_AVL_8_VAL			0x02
-#define ST_ACCEL_1_FS_AVL_16_VAL		0x03
-#define ST_ACCEL_1_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1000)
-#define ST_ACCEL_1_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(2000)
-#define ST_ACCEL_1_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(4000)
-#define ST_ACCEL_1_FS_AVL_16_GAIN		IIO_G_TO_M_S_2(12000)
-#define ST_ACCEL_1_BDU_ADDR			0x23
-#define ST_ACCEL_1_BDU_MASK			0x80
-#define ST_ACCEL_1_DRDY_IRQ_ADDR		0x22
-#define ST_ACCEL_1_DRDY_IRQ_INT1_MASK		0x10
-#define ST_ACCEL_1_DRDY_IRQ_INT2_MASK		0x08
-#define ST_ACCEL_1_IHL_IRQ_ADDR			0x25
-#define ST_ACCEL_1_IHL_IRQ_MASK			0x02
-#define ST_ACCEL_1_MULTIREAD_BIT		true
-
-/* CUSTOM VALUES FOR SENSOR 2 */
-#define ST_ACCEL_2_WAI_EXP			0x32
-#define ST_ACCEL_2_ODR_ADDR			0x20
-#define ST_ACCEL_2_ODR_MASK			0x18
-#define ST_ACCEL_2_ODR_AVL_50HZ_VAL		0x00
-#define ST_ACCEL_2_ODR_AVL_100HZ_VAL		0x01
-#define ST_ACCEL_2_ODR_AVL_400HZ_VAL		0x02
-#define ST_ACCEL_2_ODR_AVL_1000HZ_VAL		0x03
-#define ST_ACCEL_2_PW_ADDR			0x20
-#define ST_ACCEL_2_PW_MASK			0xe0
-#define ST_ACCEL_2_FS_ADDR			0x23
-#define ST_ACCEL_2_FS_MASK			0x30
-#define ST_ACCEL_2_FS_AVL_2_VAL			0X00
-#define ST_ACCEL_2_FS_AVL_4_VAL			0X01
-#define ST_ACCEL_2_FS_AVL_8_VAL			0x03
-#define ST_ACCEL_2_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1000)
-#define ST_ACCEL_2_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(2000)
-#define ST_ACCEL_2_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(3900)
-#define ST_ACCEL_2_BDU_ADDR			0x23
-#define ST_ACCEL_2_BDU_MASK			0x80
-#define ST_ACCEL_2_DRDY_IRQ_ADDR		0x22
-#define ST_ACCEL_2_DRDY_IRQ_INT1_MASK		0x02
-#define ST_ACCEL_2_DRDY_IRQ_INT2_MASK		0x10
-#define ST_ACCEL_2_IHL_IRQ_ADDR			0x22
-#define ST_ACCEL_2_IHL_IRQ_MASK			0x80
-#define ST_ACCEL_2_OD_IRQ_ADDR			0x22
-#define ST_ACCEL_2_OD_IRQ_MASK			0x40
-#define ST_ACCEL_2_MULTIREAD_BIT		true
-
-/* CUSTOM VALUES FOR SENSOR 3 */
-#define ST_ACCEL_3_WAI_EXP			0x40
-#define ST_ACCEL_3_ODR_ADDR			0x20
-#define ST_ACCEL_3_ODR_MASK			0xf0
-#define ST_ACCEL_3_ODR_AVL_3HZ_VAL		0x01
-#define ST_ACCEL_3_ODR_AVL_6HZ_VAL		0x02
-#define ST_ACCEL_3_ODR_AVL_12HZ_VAL		0x03
-#define ST_ACCEL_3_ODR_AVL_25HZ_VAL		0x04
-#define ST_ACCEL_3_ODR_AVL_50HZ_VAL		0x05
-#define ST_ACCEL_3_ODR_AVL_100HZ_VAL		0x06
-#define ST_ACCEL_3_ODR_AVL_200HZ_VAL		0x07
-#define ST_ACCEL_3_ODR_AVL_400HZ_VAL		0x08
-#define ST_ACCEL_3_ODR_AVL_800HZ_VAL		0x09
-#define ST_ACCEL_3_ODR_AVL_1600HZ_VAL		0x0a
-#define ST_ACCEL_3_FS_ADDR			0x24
-#define ST_ACCEL_3_FS_MASK			0x38
-#define ST_ACCEL_3_FS_AVL_2_VAL			0X00
-#define ST_ACCEL_3_FS_AVL_4_VAL			0X01
-#define ST_ACCEL_3_FS_AVL_6_VAL			0x02
-#define ST_ACCEL_3_FS_AVL_8_VAL			0x03
-#define ST_ACCEL_3_FS_AVL_16_VAL		0x04
-#define ST_ACCEL_3_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(61)
-#define ST_ACCEL_3_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(122)
-#define ST_ACCEL_3_FS_AVL_6_GAIN		IIO_G_TO_M_S_2(183)
-#define ST_ACCEL_3_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(244)
-#define ST_ACCEL_3_FS_AVL_16_GAIN		IIO_G_TO_M_S_2(732)
-#define ST_ACCEL_3_BDU_ADDR			0x20
-#define ST_ACCEL_3_BDU_MASK			0x08
-#define ST_ACCEL_3_DRDY_IRQ_ADDR		0x23
-#define ST_ACCEL_3_DRDY_IRQ_INT1_MASK		0x80
-#define ST_ACCEL_3_DRDY_IRQ_INT2_MASK		0x00
-#define ST_ACCEL_3_IHL_IRQ_ADDR			0x23
-#define ST_ACCEL_3_IHL_IRQ_MASK			0x40
-#define ST_ACCEL_3_IG1_EN_ADDR			0x23
-#define ST_ACCEL_3_IG1_EN_MASK			0x08
-#define ST_ACCEL_3_MULTIREAD_BIT		false
-
-/* CUSTOM VALUES FOR SENSOR 4 */
-#define ST_ACCEL_4_WAI_EXP			0x3a
-#define ST_ACCEL_4_ODR_ADDR			0x20
-#define ST_ACCEL_4_ODR_MASK			0x30 /* DF1 and DF0 */
-#define ST_ACCEL_4_ODR_AVL_40HZ_VAL		0x00
-#define ST_ACCEL_4_ODR_AVL_160HZ_VAL		0x01
-#define ST_ACCEL_4_ODR_AVL_640HZ_VAL		0x02
-#define ST_ACCEL_4_ODR_AVL_2560HZ_VAL		0x03
-#define ST_ACCEL_4_PW_ADDR			0x20
-#define ST_ACCEL_4_PW_MASK			0xc0
-#define ST_ACCEL_4_FS_ADDR			0x21
-#define ST_ACCEL_4_FS_MASK			0x80
-#define ST_ACCEL_4_FS_AVL_2_VAL			0X00
-#define ST_ACCEL_4_FS_AVL_6_VAL			0X01
-#define ST_ACCEL_4_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1024)
-#define ST_ACCEL_4_FS_AVL_6_GAIN		IIO_G_TO_M_S_2(340)
-#define ST_ACCEL_4_BDU_ADDR			0x21
-#define ST_ACCEL_4_BDU_MASK			0x40
-#define ST_ACCEL_4_DRDY_IRQ_ADDR		0x21
-#define ST_ACCEL_4_DRDY_IRQ_INT1_MASK		0x04
-#define ST_ACCEL_4_MULTIREAD_BIT		true
-
-/* CUSTOM VALUES FOR SENSOR 5 */
-#define ST_ACCEL_5_WAI_EXP			0x3b
-#define ST_ACCEL_5_ODR_ADDR			0x20
-#define ST_ACCEL_5_ODR_MASK			0x80
-#define ST_ACCEL_5_ODR_AVL_100HZ_VAL		0x00
-#define ST_ACCEL_5_ODR_AVL_400HZ_VAL		0x01
-#define ST_ACCEL_5_PW_ADDR			0x20
-#define ST_ACCEL_5_PW_MASK			0x40
-#define ST_ACCEL_5_FS_ADDR			0x20
-#define ST_ACCEL_5_FS_MASK			0x20
-#define ST_ACCEL_5_FS_AVL_2_VAL			0X00
-#define ST_ACCEL_5_FS_AVL_8_VAL			0X01
-/* TODO: check these resulting gain settings, these are not in the datsheet */
-#define ST_ACCEL_5_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(18000)
-#define ST_ACCEL_5_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(72000)
-#define ST_ACCEL_5_DRDY_IRQ_ADDR		0x22
-#define ST_ACCEL_5_DRDY_IRQ_INT1_MASK		0x04
-#define ST_ACCEL_5_DRDY_IRQ_INT2_MASK		0x20
-#define ST_ACCEL_5_IHL_IRQ_ADDR			0x22
-#define ST_ACCEL_5_IHL_IRQ_MASK			0x80
-#define ST_ACCEL_5_OD_IRQ_ADDR			0x22
-#define ST_ACCEL_5_OD_IRQ_MASK			0x40
-#define ST_ACCEL_5_IG1_EN_ADDR			0x21
-#define ST_ACCEL_5_IG1_EN_MASK			0x08
-#define ST_ACCEL_5_MULTIREAD_BIT		false
-
-/* CUSTOM VALUES FOR SENSOR 6 */
-#define ST_ACCEL_6_WAI_EXP			0x32
-#define ST_ACCEL_6_ODR_ADDR			0x20
-#define ST_ACCEL_6_ODR_MASK			0x18
-#define ST_ACCEL_6_ODR_AVL_50HZ_VAL		0x00
-#define ST_ACCEL_6_ODR_AVL_100HZ_VAL		0x01
-#define ST_ACCEL_6_ODR_AVL_400HZ_VAL		0x02
-#define ST_ACCEL_6_ODR_AVL_1000HZ_VAL		0x03
-#define ST_ACCEL_6_PW_ADDR			0x20
-#define ST_ACCEL_6_PW_MASK			0x20
-#define ST_ACCEL_6_FS_ADDR			0x23
-#define ST_ACCEL_6_FS_MASK			0x30
-#define ST_ACCEL_6_FS_AVL_100_VAL		0x00
-#define ST_ACCEL_6_FS_AVL_200_VAL		0x01
-#define ST_ACCEL_6_FS_AVL_400_VAL		0x03
-#define ST_ACCEL_6_FS_AVL_100_GAIN		IIO_G_TO_M_S_2(49000)
-#define ST_ACCEL_6_FS_AVL_200_GAIN		IIO_G_TO_M_S_2(98000)
-#define ST_ACCEL_6_FS_AVL_400_GAIN		IIO_G_TO_M_S_2(195000)
-#define ST_ACCEL_6_BDU_ADDR			0x23
-#define ST_ACCEL_6_BDU_MASK			0x80
-#define ST_ACCEL_6_DRDY_IRQ_ADDR		0x22
-#define ST_ACCEL_6_DRDY_IRQ_INT1_MASK		0x02
-#define ST_ACCEL_6_DRDY_IRQ_INT2_MASK		0x10
-#define ST_ACCEL_6_IHL_IRQ_ADDR			0x22
-#define ST_ACCEL_6_IHL_IRQ_MASK			0x80
-#define ST_ACCEL_6_MULTIREAD_BIT		true
-
-/* CUSTOM VALUES FOR SENSOR 7 */
-#define ST_ACCEL_7_ODR_ADDR			0x20
-#define ST_ACCEL_7_ODR_MASK			0x30
-#define ST_ACCEL_7_ODR_AVL_280HZ_VAL		0x00
-#define ST_ACCEL_7_ODR_AVL_560HZ_VAL		0x01
-#define ST_ACCEL_7_ODR_AVL_1120HZ_VAL		0x02
-#define ST_ACCEL_7_ODR_AVL_4480HZ_VAL		0x03
-#define ST_ACCEL_7_PW_ADDR			0x20
-#define ST_ACCEL_7_PW_MASK			0xc0
-#define ST_ACCEL_7_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(488)
-#define ST_ACCEL_7_BDU_ADDR			0x21
-#define ST_ACCEL_7_BDU_MASK			0x40
-#define ST_ACCEL_7_DRDY_IRQ_ADDR		0x21
-#define ST_ACCEL_7_DRDY_IRQ_INT1_MASK		0x04
-#define ST_ACCEL_7_MULTIREAD_BIT		false
-
 static const struct iio_chan_spec st_accel_8bit_channels[] = {
 	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
@@ -281,7 +93,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 = 0x33,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS3DH_ACCEL_DEV_NAME,
@@ -294,22 +106,22 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 		},
 		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
 		.odr = {
-			.addr = ST_ACCEL_1_ODR_ADDR,
-			.mask = ST_ACCEL_1_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0xf0,
 			.odr_avl = {
-				{ 1, ST_ACCEL_1_ODR_AVL_1HZ_VAL, },
-				{ 10, ST_ACCEL_1_ODR_AVL_10HZ_VAL, },
-				{ 25, ST_ACCEL_1_ODR_AVL_25HZ_VAL, },
-				{ 50, ST_ACCEL_1_ODR_AVL_50HZ_VAL, },
-				{ 100, ST_ACCEL_1_ODR_AVL_100HZ_VAL, },
-				{ 200, ST_ACCEL_1_ODR_AVL_200HZ_VAL, },
-				{ 400, ST_ACCEL_1_ODR_AVL_400HZ_VAL, },
-				{ 1600, ST_ACCEL_1_ODR_AVL_1600HZ_VAL, },
+				{ .hz = 1, .value = 0x01, },
+				{ .hz = 10, .value = 0x02, },
+				{ .hz = 25, .value = 0x03, },
+				{ .hz = 50, .value = 0x04, },
+				{ .hz = 100, .value = 0x05, },
+				{ .hz = 200, .value = 0x06, },
+				{ .hz = 400, .value = 0x07, },
+				{ .hz = 1600, .value = 0x08, },
 			},
 		},
 		.pw = {
-			.addr = ST_ACCEL_1_ODR_ADDR,
-			.mask = ST_ACCEL_1_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0xf0,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
 		.enable_axis = {
@@ -317,48 +129,48 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_ACCEL_1_FS_ADDR,
-			.mask = ST_ACCEL_1_FS_MASK,
+			.addr = 0x23,
+			.mask = 0x30,
 			.fs_avl = {
 				[0] = {
 					.num = ST_ACCEL_FS_AVL_2G,
-					.value = ST_ACCEL_1_FS_AVL_2_VAL,
-					.gain = ST_ACCEL_1_FS_AVL_2_GAIN,
+					.value = 0x00,
+					.gain = IIO_G_TO_M_S_2(1000),
 				},
 				[1] = {
 					.num = ST_ACCEL_FS_AVL_4G,
-					.value = ST_ACCEL_1_FS_AVL_4_VAL,
-					.gain = ST_ACCEL_1_FS_AVL_4_GAIN,
+					.value = 0x01,
+					.gain = IIO_G_TO_M_S_2(2000),
 				},
 				[2] = {
 					.num = ST_ACCEL_FS_AVL_8G,
-					.value = ST_ACCEL_1_FS_AVL_8_VAL,
-					.gain = ST_ACCEL_1_FS_AVL_8_GAIN,
+					.value = 0x02,
+					.gain = IIO_G_TO_M_S_2(4000),
 				},
 				[3] = {
 					.num = ST_ACCEL_FS_AVL_16G,
-					.value = ST_ACCEL_1_FS_AVL_16_VAL,
-					.gain = ST_ACCEL_1_FS_AVL_16_GAIN,
+					.value = 0x03,
+					.gain = IIO_G_TO_M_S_2(12000),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_ACCEL_1_BDU_ADDR,
-			.mask = ST_ACCEL_1_BDU_MASK,
+			.addr = 0x23,
+			.mask = 0x80,
 		},
 		.drdy_irq = {
-			.addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_ACCEL_1_IHL_IRQ_ADDR,
-			.mask_ihl = ST_ACCEL_1_IHL_IRQ_MASK,
+			.addr = 0x22,
+			.mask_int1 = 0x10,
+			.mask_int2 = 0x08,
+			.addr_ihl = 0x25,
+			.mask_ihl = 0x02,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_ACCEL_2_WAI_EXP,
+		.wai = 0x32,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS331DLH_ACCEL_DEV_NAME,
@@ -368,18 +180,18 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 		},
 		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
 		.odr = {
-			.addr = ST_ACCEL_2_ODR_ADDR,
-			.mask = ST_ACCEL_2_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x18,
 			.odr_avl = {
-				{ 50, ST_ACCEL_2_ODR_AVL_50HZ_VAL, },
-				{ 100, ST_ACCEL_2_ODR_AVL_100HZ_VAL, },
-				{ 400, ST_ACCEL_2_ODR_AVL_400HZ_VAL, },
-				{ 1000, ST_ACCEL_2_ODR_AVL_1000HZ_VAL, },
+				{ .hz = 50, .value = 0x00, },
+				{ .hz = 100, .value = 0x01, },
+				{ .hz = 400, .value = 0x02, },
+				{ .hz = 1000, .value = 0x03, },
 			},
 		},
 		.pw = {
-			.addr = ST_ACCEL_2_PW_ADDR,
-			.mask = ST_ACCEL_2_PW_MASK,
+			.addr = 0x20,
+			.mask = 0xe0,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -388,69 +200,69 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_ACCEL_2_FS_ADDR,
-			.mask = ST_ACCEL_2_FS_MASK,
+			.addr = 0x23,
+			.mask = 0x30,
 			.fs_avl = {
 				[0] = {
 					.num = ST_ACCEL_FS_AVL_2G,
-					.value = ST_ACCEL_2_FS_AVL_2_VAL,
-					.gain = ST_ACCEL_2_FS_AVL_2_GAIN,
+					.value = 0x00,
+					.gain = IIO_G_TO_M_S_2(1000),
 				},
 				[1] = {
 					.num = ST_ACCEL_FS_AVL_4G,
-					.value = ST_ACCEL_2_FS_AVL_4_VAL,
-					.gain = ST_ACCEL_2_FS_AVL_4_GAIN,
+					.value = 0x01,
+					.gain = IIO_G_TO_M_S_2(2000),
 				},
 				[2] = {
 					.num = ST_ACCEL_FS_AVL_8G,
-					.value = ST_ACCEL_2_FS_AVL_8_VAL,
-					.gain = ST_ACCEL_2_FS_AVL_8_GAIN,
+					.value = 0x03,
+					.gain = IIO_G_TO_M_S_2(3900),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_ACCEL_2_BDU_ADDR,
-			.mask = ST_ACCEL_2_BDU_MASK,
+			.addr = 0x23,
+			.mask = 0x80,
 		},
 		.drdy_irq = {
-			.addr = ST_ACCEL_2_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_ACCEL_2_IHL_IRQ_ADDR,
-			.mask_ihl = ST_ACCEL_2_IHL_IRQ_MASK,
-			.addr_od = ST_ACCEL_2_OD_IRQ_ADDR,
-			.mask_od = ST_ACCEL_2_OD_IRQ_MASK,
+			.addr = 0x22,
+			.mask_int1 = 0x02,
+			.mask_int2 = 0x10,
+			.addr_ihl = 0x22,
+			.mask_ihl = 0x80,
+			.addr_od = 0x22,
+			.mask_od = 0x40,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_ACCEL_3_WAI_EXP,
+		.wai = 0x40,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LSM330_ACCEL_DEV_NAME,
 		},
 		.ch = (struct iio_chan_spec *)st_accel_16bit_channels,
 		.odr = {
-			.addr = ST_ACCEL_3_ODR_ADDR,
-			.mask = ST_ACCEL_3_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0xf0,
 			.odr_avl = {
-				{ 3, ST_ACCEL_3_ODR_AVL_3HZ_VAL },
-				{ 6, ST_ACCEL_3_ODR_AVL_6HZ_VAL, },
-				{ 12, ST_ACCEL_3_ODR_AVL_12HZ_VAL, },
-				{ 25, ST_ACCEL_3_ODR_AVL_25HZ_VAL, },
-				{ 50, ST_ACCEL_3_ODR_AVL_50HZ_VAL, },
-				{ 100, ST_ACCEL_3_ODR_AVL_100HZ_VAL, },
-				{ 200, ST_ACCEL_3_ODR_AVL_200HZ_VAL, },
-				{ 400, ST_ACCEL_3_ODR_AVL_400HZ_VAL, },
-				{ 800, ST_ACCEL_3_ODR_AVL_800HZ_VAL, },
-				{ 1600, ST_ACCEL_3_ODR_AVL_1600HZ_VAL, },
+				{ .hz = 3, .value = 0x01, },
+				{ .hz = 6, .value = 0x02, },
+				{ .hz = 12, .value = 0x03, },
+				{ .hz = 25, .value = 0x04, },
+				{ .hz = 50, .value = 0x05, },
+				{ .hz = 100, .value = 0x06, },
+				{ .hz = 200, .value = 0x07, },
+				{ .hz = 400, .value = 0x08, },
+				{ .hz = 800, .value = 0x09, },
+				{ .hz = 1600, .value = 0x0a, },
 			},
 		},
 		.pw = {
-			.addr = ST_ACCEL_3_ODR_ADDR,
-			.mask = ST_ACCEL_3_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0xf0,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
 		.enable_axis = {
@@ -458,75 +270,75 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_ACCEL_3_FS_ADDR,
-			.mask = ST_ACCEL_3_FS_MASK,
+			.addr = 0x24,
+			.mask = 0x38,
 			.fs_avl = {
 				[0] = {
 					.num = ST_ACCEL_FS_AVL_2G,
-					.value = ST_ACCEL_3_FS_AVL_2_VAL,
-					.gain = ST_ACCEL_3_FS_AVL_2_GAIN,
+					.value = 0x00,
+					.gain = IIO_G_TO_M_S_2(61),
 				},
 				[1] = {
 					.num = ST_ACCEL_FS_AVL_4G,
-					.value = ST_ACCEL_3_FS_AVL_4_VAL,
-					.gain = ST_ACCEL_3_FS_AVL_4_GAIN,
+					.value = 0x01,
+					.gain = IIO_G_TO_M_S_2(122),
 				},
 				[2] = {
 					.num = ST_ACCEL_FS_AVL_6G,
-					.value = ST_ACCEL_3_FS_AVL_6_VAL,
-					.gain = ST_ACCEL_3_FS_AVL_6_GAIN,
+					.value = 0x02,
+					.gain = IIO_G_TO_M_S_2(183),
 				},
 				[3] = {
 					.num = ST_ACCEL_FS_AVL_8G,
-					.value = ST_ACCEL_3_FS_AVL_8_VAL,
-					.gain = ST_ACCEL_3_FS_AVL_8_GAIN,
+					.value = 0x03,
+					.gain = IIO_G_TO_M_S_2(244),
 				},
 				[4] = {
 					.num = ST_ACCEL_FS_AVL_16G,
-					.value = ST_ACCEL_3_FS_AVL_16_VAL,
-					.gain = ST_ACCEL_3_FS_AVL_16_GAIN,
+					.value = 0x04,
+					.gain = IIO_G_TO_M_S_2(732),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_ACCEL_3_BDU_ADDR,
-			.mask = ST_ACCEL_3_BDU_MASK,
+			.addr = 0x20,
+			.mask = 0x08,
 		},
 		.drdy_irq = {
-			.addr = ST_ACCEL_3_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_ACCEL_3_IHL_IRQ_ADDR,
-			.mask_ihl = ST_ACCEL_3_IHL_IRQ_MASK,
+			.addr = 0x23,
+			.mask_int1 = 0x80,
+			.mask_int2 = 0x00,
+			.addr_ihl = 0x23,
+			.mask_ihl = 0x40,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 			.ig1 = {
-				.en_addr = ST_ACCEL_3_IG1_EN_ADDR,
-				.en_mask = ST_ACCEL_3_IG1_EN_MASK,
+				.en_addr = 0x23,
+				.en_mask = 0x08,
 			},
 		},
-		.multi_read_bit = ST_ACCEL_3_MULTIREAD_BIT,
+		.multi_read_bit = false,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_ACCEL_4_WAI_EXP,
+		.wai = 0x3a,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS3LV02DL_ACCEL_DEV_NAME,
 		},
 		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
 		.odr = {
-			.addr = ST_ACCEL_4_ODR_ADDR,
-			.mask = ST_ACCEL_4_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x30, /* DF1 and DF0 */
 			.odr_avl = {
-				{ 40, ST_ACCEL_4_ODR_AVL_40HZ_VAL },
-				{ 160, ST_ACCEL_4_ODR_AVL_160HZ_VAL, },
-				{ 640, ST_ACCEL_4_ODR_AVL_640HZ_VAL, },
-				{ 2560, ST_ACCEL_4_ODR_AVL_2560HZ_VAL, },
+				{ .hz = 40, .value = 0x00, },
+				{ .hz = 160, .value = 0x01, },
+				{ .hz = 640, .value = 0x02, },
+				{ .hz = 2560, .value = 0x03, },
 			},
 		},
 		.pw = {
-			.addr = ST_ACCEL_4_PW_ADDR,
-			.mask = ST_ACCEL_4_PW_MASK,
+			.addr = 0x20,
+			.mask = 0xc0,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -535,51 +347,51 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_ACCEL_4_FS_ADDR,
-			.mask = ST_ACCEL_4_FS_MASK,
+			.addr = 0x21,
+			.mask = 0x80,
 			.fs_avl = {
 				[0] = {
 					.num = ST_ACCEL_FS_AVL_2G,
-					.value = ST_ACCEL_4_FS_AVL_2_VAL,
-					.gain = ST_ACCEL_4_FS_AVL_2_GAIN,
+					.value = 0x00,
+					.gain = IIO_G_TO_M_S_2(1024),
 				},
 				[1] = {
 					.num = ST_ACCEL_FS_AVL_6G,
-					.value = ST_ACCEL_4_FS_AVL_6_VAL,
-					.gain = ST_ACCEL_4_FS_AVL_6_GAIN,
+					.value = 0x01,
+					.gain = IIO_G_TO_M_S_2(340),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_ACCEL_4_BDU_ADDR,
-			.mask = ST_ACCEL_4_BDU_MASK,
+			.addr = 0x21,
+			.mask = 0x40,
 		},
 		.drdy_irq = {
-			.addr = ST_ACCEL_4_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_ACCEL_4_DRDY_IRQ_INT1_MASK,
+			.addr = 0x21,
+			.mask_int1 = 0x04,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_ACCEL_4_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2, /* guess */
 	},
 	{
-		.wai = ST_ACCEL_5_WAI_EXP,
+		.wai = 0x3b,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS331DL_ACCEL_DEV_NAME,
 		},
 		.ch = (struct iio_chan_spec *)st_accel_8bit_channels,
 		.odr = {
-			.addr = ST_ACCEL_5_ODR_ADDR,
-			.mask = ST_ACCEL_5_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x80,
 			.odr_avl = {
-				{ 100, ST_ACCEL_5_ODR_AVL_100HZ_VAL },
-				{ 400, ST_ACCEL_5_ODR_AVL_400HZ_VAL, },
+				{ .hz = 100, .value = 0x00, },
+				{ .hz = 400, .value = 0x01, },
 			},
 		},
 		.pw = {
-			.addr = ST_ACCEL_5_PW_ADDR,
-			.mask = ST_ACCEL_5_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x40,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -588,54 +400,58 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_ACCEL_5_FS_ADDR,
-			.mask = ST_ACCEL_5_FS_MASK,
+			.addr = 0x20,
+			.mask = 0x20,
+			/*
+			 * TODO: check these resulting gain settings, these are
+			 * not in the datsheet
+			 */
 			.fs_avl = {
 				[0] = {
 					.num = ST_ACCEL_FS_AVL_2G,
-					.value = ST_ACCEL_5_FS_AVL_2_VAL,
-					.gain = ST_ACCEL_5_FS_AVL_2_GAIN,
+					.value = 0x00,
+					.gain = IIO_G_TO_M_S_2(18000),
 				},
 				[1] = {
 					.num = ST_ACCEL_FS_AVL_8G,
-					.value = ST_ACCEL_5_FS_AVL_8_VAL,
-					.gain = ST_ACCEL_5_FS_AVL_8_GAIN,
+					.value = 0x01,
+					.gain = IIO_G_TO_M_S_2(72000),
 				},
 			},
 		},
 		.drdy_irq = {
-			.addr = ST_ACCEL_5_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_ACCEL_5_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_ACCEL_5_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_ACCEL_5_IHL_IRQ_ADDR,
-			.mask_ihl = ST_ACCEL_5_IHL_IRQ_MASK,
-			.addr_od = ST_ACCEL_5_OD_IRQ_ADDR,
-			.mask_od = ST_ACCEL_5_OD_IRQ_MASK,
+			.addr = 0x22,
+			.mask_int1 = 0x04,
+			.mask_int2 = 0x20,
+			.addr_ihl = 0x22,
+			.mask_ihl = 0x80,
+			.addr_od = 0x22,
+			.mask_od = 0x40,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT,
+		.multi_read_bit = false,
 		.bootime = 2, /* guess */
 	},
 	{
-		.wai = ST_ACCEL_6_WAI_EXP,
+		.wai = 0x32,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = H3LIS331DL_DRIVER_NAME,
 		},
 		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
 		.odr = {
-			.addr = ST_ACCEL_6_ODR_ADDR,
-			.mask = ST_ACCEL_6_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x18,
 			.odr_avl = {
-				{ 50, ST_ACCEL_6_ODR_AVL_50HZ_VAL },
-				{ 100, ST_ACCEL_6_ODR_AVL_100HZ_VAL, },
-				{ 400, ST_ACCEL_6_ODR_AVL_400HZ_VAL, },
-				{ 1000, ST_ACCEL_6_ODR_AVL_1000HZ_VAL, },
+				{ .hz = 50, .value = 0x00, },
+				{ .hz = 100, .value = 0x01, },
+				{ .hz = 400, .value = 0x02, },
+				{ .hz = 1000, .value = 0x03, },
 			},
 		},
 		.pw = {
-			.addr = ST_ACCEL_6_PW_ADDR,
-			.mask = ST_ACCEL_6_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x20,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -644,38 +460,38 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_ACCEL_6_FS_ADDR,
-			.mask = ST_ACCEL_6_FS_MASK,
+			.addr = 0x23,
+			.mask = 0x30,
 			.fs_avl = {
 				[0] = {
 					.num = ST_ACCEL_FS_AVL_100G,
-					.value = ST_ACCEL_6_FS_AVL_100_VAL,
-					.gain = ST_ACCEL_6_FS_AVL_100_GAIN,
+					.value = 0x00,
+					.gain = IIO_G_TO_M_S_2(49000),
 				},
 				[1] = {
 					.num = ST_ACCEL_FS_AVL_200G,
-					.value = ST_ACCEL_6_FS_AVL_200_VAL,
-					.gain = ST_ACCEL_6_FS_AVL_200_GAIN,
+					.value = 0x01,
+					.gain = IIO_G_TO_M_S_2(98000),
 				},
 				[2] = {
 					.num = ST_ACCEL_FS_AVL_400G,
-					.value = ST_ACCEL_6_FS_AVL_400_VAL,
-					.gain = ST_ACCEL_6_FS_AVL_400_GAIN,
+					.value = 0x03,
+					.gain = IIO_G_TO_M_S_2(195000),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_ACCEL_6_BDU_ADDR,
-			.mask = ST_ACCEL_6_BDU_MASK,
+			.addr = 0x23,
+			.mask = 0x80,
 		},
 		.drdy_irq = {
-			.addr = ST_ACCEL_6_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_ACCEL_6_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_ACCEL_6_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_ACCEL_6_IHL_IRQ_ADDR,
-			.mask_ihl = ST_ACCEL_6_IHL_IRQ_MASK,
+			.addr = 0x22,
+			.mask_int1 = 0x02,
+			.mask_int2 = 0x10,
+			.addr_ihl = 0x22,
+			.mask_ihl = 0x80,
 		},
-		.multi_read_bit = ST_ACCEL_6_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
@@ -685,18 +501,18 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 		},
 		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
 		.odr = {
-			.addr = ST_ACCEL_7_ODR_ADDR,
-			.mask = ST_ACCEL_7_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x30,
 			.odr_avl = {
-				{ 280, ST_ACCEL_7_ODR_AVL_280HZ_VAL, },
-				{ 560, ST_ACCEL_7_ODR_AVL_560HZ_VAL, },
-				{ 1120, ST_ACCEL_7_ODR_AVL_1120HZ_VAL, },
-				{ 4480, ST_ACCEL_7_ODR_AVL_4480HZ_VAL, },
+				{ .hz = 280, .value = 0x00, },
+				{ .hz = 560, .value = 0x01, },
+				{ .hz = 1120, .value = 0x02, },
+				{ .hz = 4480, .value = 0x03, },
 			},
 		},
 		.pw = {
-			.addr = ST_ACCEL_7_PW_ADDR,
-			.mask = ST_ACCEL_7_PW_MASK,
+			.addr = 0x20,
+			.mask = 0xc0,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -708,7 +524,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 			.fs_avl = {
 				[0] = {
 					.num = ST_ACCEL_FS_AVL_2G,
-					.gain = ST_ACCEL_7_FS_AVL_2_GAIN,
+					.gain = IIO_G_TO_M_S_2(488),
 				},
 			},
 		},
@@ -719,11 +535,11 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 		.bdu = {
 		},
 		.drdy_irq = {
-			.addr = ST_ACCEL_7_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_ACCEL_7_DRDY_IRQ_INT1_MASK,
+			.addr = 0x21,
+			.mask_int1 = 0x04,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_ACCEL_7_MULTIREAD_BIT,
+		.multi_read_bit = false,
 		.bootime = 2,
 	},
 };
-- 
2.7.4


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

* [PATCH 2/4] iio: gyro: st_gyro: inline per-sensor data
  2016-11-09 15:09 [PATCH 0/4] ST Sensors: inline sensor data Linus Walleij
  2016-11-09 15:09 ` [PATCH 1/4] iio: accel: st_accel: inline per-sensor data Linus Walleij
@ 2016-11-09 15:09 ` Linus Walleij
  2016-11-12 15:38   ` Jonathan Cameron
  2016-11-09 15:09 ` [PATCH 3/4] iio: magn: st_magn: " Linus Walleij
  2016-11-09 15:10 ` [PATCH 4/4] iio: pressure: st_pressure: " Linus Walleij
  3 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2016-11-09 15:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard,
	Linus Walleij

We have #defines for all the individual sensor registers and
value/mask pairs #defined at the top of the file and used at
exactly one spot.

This is usually good if the #defines give a meaning to the
opaque magic numbers.

However in this case, the semantic meaning is inherent in the
name of the C99-addressable fields, and that means duplication
of information, and only makes the code hard to maintain since
you every time have to add a new #define AND update the site
where it is to be used.

Get rid of the #defines and just open code the values into the
appropriate struct elements. Make sure to explicitly address
the .hz and .value fields in the st_sensor_odr_avl struct
so that the meaning of all values is clear.

This patch is purely syntactic should have no semantic effect.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/gyro/st_gyro_core.c | 205 +++++++++++++---------------------------
 1 file changed, 66 insertions(+), 139 deletions(-)

diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index aea034d8fe0f..2a42b3d583e8 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -39,79 +39,6 @@
 #define ST_GYRO_FS_AVL_500DPS			500
 #define ST_GYRO_FS_AVL_2000DPS			2000
 
-/* CUSTOM VALUES FOR SENSOR 1 */
-#define ST_GYRO_1_WAI_EXP			0xd3
-#define ST_GYRO_1_ODR_ADDR			0x20
-#define ST_GYRO_1_ODR_MASK			0xc0
-#define ST_GYRO_1_ODR_AVL_100HZ_VAL		0x00
-#define ST_GYRO_1_ODR_AVL_200HZ_VAL		0x01
-#define ST_GYRO_1_ODR_AVL_400HZ_VAL		0x02
-#define ST_GYRO_1_ODR_AVL_800HZ_VAL		0x03
-#define ST_GYRO_1_PW_ADDR			0x20
-#define ST_GYRO_1_PW_MASK			0x08
-#define ST_GYRO_1_FS_ADDR			0x23
-#define ST_GYRO_1_FS_MASK			0x30
-#define ST_GYRO_1_FS_AVL_250_VAL		0x00
-#define ST_GYRO_1_FS_AVL_500_VAL		0x01
-#define ST_GYRO_1_FS_AVL_2000_VAL		0x02
-#define ST_GYRO_1_FS_AVL_250_GAIN		IIO_DEGREE_TO_RAD(8750)
-#define ST_GYRO_1_FS_AVL_500_GAIN		IIO_DEGREE_TO_RAD(17500)
-#define ST_GYRO_1_FS_AVL_2000_GAIN		IIO_DEGREE_TO_RAD(70000)
-#define ST_GYRO_1_BDU_ADDR			0x23
-#define ST_GYRO_1_BDU_MASK			0x80
-#define ST_GYRO_1_DRDY_IRQ_ADDR			0x22
-#define ST_GYRO_1_DRDY_IRQ_INT2_MASK		0x08
-#define ST_GYRO_1_MULTIREAD_BIT			true
-
-/* CUSTOM VALUES FOR SENSOR 2 */
-#define ST_GYRO_2_WAI_EXP			0xd4
-#define ST_GYRO_2_ODR_ADDR			0x20
-#define ST_GYRO_2_ODR_MASK			0xc0
-#define ST_GYRO_2_ODR_AVL_95HZ_VAL		0x00
-#define ST_GYRO_2_ODR_AVL_190HZ_VAL		0x01
-#define ST_GYRO_2_ODR_AVL_380HZ_VAL		0x02
-#define ST_GYRO_2_ODR_AVL_760HZ_VAL		0x03
-#define ST_GYRO_2_PW_ADDR			0x20
-#define ST_GYRO_2_PW_MASK			0x08
-#define ST_GYRO_2_FS_ADDR			0x23
-#define ST_GYRO_2_FS_MASK			0x30
-#define ST_GYRO_2_FS_AVL_250_VAL		0x00
-#define ST_GYRO_2_FS_AVL_500_VAL		0x01
-#define ST_GYRO_2_FS_AVL_2000_VAL		0x02
-#define ST_GYRO_2_FS_AVL_250_GAIN		IIO_DEGREE_TO_RAD(8750)
-#define ST_GYRO_2_FS_AVL_500_GAIN		IIO_DEGREE_TO_RAD(17500)
-#define ST_GYRO_2_FS_AVL_2000_GAIN		IIO_DEGREE_TO_RAD(70000)
-#define ST_GYRO_2_BDU_ADDR			0x23
-#define ST_GYRO_2_BDU_MASK			0x80
-#define ST_GYRO_2_DRDY_IRQ_ADDR			0x22
-#define ST_GYRO_2_DRDY_IRQ_INT2_MASK		0x08
-#define ST_GYRO_2_MULTIREAD_BIT			true
-
-/* CUSTOM VALUES FOR SENSOR 3 */
-#define ST_GYRO_3_WAI_EXP			0xd7
-#define ST_GYRO_3_ODR_ADDR			0x20
-#define ST_GYRO_3_ODR_MASK			0xc0
-#define ST_GYRO_3_ODR_AVL_95HZ_VAL		0x00
-#define ST_GYRO_3_ODR_AVL_190HZ_VAL		0x01
-#define ST_GYRO_3_ODR_AVL_380HZ_VAL		0x02
-#define ST_GYRO_3_ODR_AVL_760HZ_VAL		0x03
-#define ST_GYRO_3_PW_ADDR			0x20
-#define ST_GYRO_3_PW_MASK			0x08
-#define ST_GYRO_3_FS_ADDR			0x23
-#define ST_GYRO_3_FS_MASK			0x30
-#define ST_GYRO_3_FS_AVL_250_VAL		0x00
-#define ST_GYRO_3_FS_AVL_500_VAL		0x01
-#define ST_GYRO_3_FS_AVL_2000_VAL		0x02
-#define ST_GYRO_3_FS_AVL_250_GAIN		IIO_DEGREE_TO_RAD(8750)
-#define ST_GYRO_3_FS_AVL_500_GAIN		IIO_DEGREE_TO_RAD(17500)
-#define ST_GYRO_3_FS_AVL_2000_GAIN		IIO_DEGREE_TO_RAD(70000)
-#define ST_GYRO_3_BDU_ADDR			0x23
-#define ST_GYRO_3_BDU_MASK			0x80
-#define ST_GYRO_3_DRDY_IRQ_ADDR			0x22
-#define ST_GYRO_3_DRDY_IRQ_INT2_MASK		0x08
-#define ST_GYRO_3_MULTIREAD_BIT			true
-
-
 static const struct iio_chan_spec st_gyro_16bit_channels[] = {
 	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
 			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
@@ -130,7 +57,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 = 0xd3,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = L3G4200D_GYRO_DEV_NAME,
@@ -138,18 +65,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 		},
 		.ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
 		.odr = {
-			.addr = ST_GYRO_1_ODR_ADDR,
-			.mask = ST_GYRO_1_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0xc0,
 			.odr_avl = {
-				{ 100, ST_GYRO_1_ODR_AVL_100HZ_VAL, },
-				{ 200, ST_GYRO_1_ODR_AVL_200HZ_VAL, },
-				{ 400, ST_GYRO_1_ODR_AVL_400HZ_VAL, },
-				{ 800, ST_GYRO_1_ODR_AVL_800HZ_VAL, },
+				{ .hz = 100, .value = 0x00, },
+				{ .hz = 200, .value = 0x01, },
+				{ .hz = 400, .value = 0x02, },
+				{ .hz = 800, .value = 0x03, },
 			},
 		},
 		.pw = {
-			.addr = ST_GYRO_1_PW_ADDR,
-			.mask = ST_GYRO_1_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x08,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -158,33 +85,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_GYRO_1_FS_ADDR,
-			.mask = ST_GYRO_1_FS_MASK,
+			.addr = 0x23,
+			.mask = 0x30,
 			.fs_avl = {
 				[0] = {
 					.num = ST_GYRO_FS_AVL_250DPS,
-					.value = ST_GYRO_1_FS_AVL_250_VAL,
-					.gain = ST_GYRO_1_FS_AVL_250_GAIN,
+					.value = 0x00,
+					.gain = IIO_DEGREE_TO_RAD(8750),
 				},
 				[1] = {
 					.num = ST_GYRO_FS_AVL_500DPS,
-					.value = ST_GYRO_1_FS_AVL_500_VAL,
-					.gain = ST_GYRO_1_FS_AVL_500_GAIN,
+					.value = 0x01,
+					.gain = IIO_DEGREE_TO_RAD(17500),
 				},
 				[2] = {
 					.num = ST_GYRO_FS_AVL_2000DPS,
-					.value = ST_GYRO_1_FS_AVL_2000_VAL,
-					.gain = ST_GYRO_1_FS_AVL_2000_GAIN,
+					.value = 0x02,
+					.gain = IIO_DEGREE_TO_RAD(70000),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_GYRO_1_BDU_ADDR,
-			.mask = ST_GYRO_1_BDU_MASK,
+			.addr = 0x23,
+			.mask = 0x80,
 		},
 		.drdy_irq = {
-			.addr = ST_GYRO_1_DRDY_IRQ_ADDR,
-			.mask_int2 = ST_GYRO_1_DRDY_IRQ_INT2_MASK,
+			.addr = 0x22,
+			.mask_int2 = 0x08,
 			/*
 			 * The sensor has IHL (active low) and open
 			 * drain settings, but only for INT1 and not
@@ -192,11 +119,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 			 */
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_GYRO_2_WAI_EXP,
+		.wai = 0xd4,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = L3GD20_GYRO_DEV_NAME,
@@ -208,18 +135,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 		},
 		.ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
 		.odr = {
-			.addr = ST_GYRO_2_ODR_ADDR,
-			.mask = ST_GYRO_2_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0xc0,
 			.odr_avl = {
-				{ 95, ST_GYRO_2_ODR_AVL_95HZ_VAL, },
-				{ 190, ST_GYRO_2_ODR_AVL_190HZ_VAL, },
-				{ 380, ST_GYRO_2_ODR_AVL_380HZ_VAL, },
-				{ 760, ST_GYRO_2_ODR_AVL_760HZ_VAL, },
+				{ .hz = 95, .value = 0x00, },
+				{ .hz = 190, .value = 0x01, },
+				{ .hz = 380, .value = 0x02, },
+				{ .hz = 760, .value = 0x03, },
 			},
 		},
 		.pw = {
-			.addr = ST_GYRO_2_PW_ADDR,
-			.mask = ST_GYRO_2_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x08,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -228,33 +155,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_GYRO_2_FS_ADDR,
-			.mask = ST_GYRO_2_FS_MASK,
+			.addr = 0x23,
+			.mask = 0x30,
 			.fs_avl = {
 				[0] = {
 					.num = ST_GYRO_FS_AVL_250DPS,
-					.value = ST_GYRO_2_FS_AVL_250_VAL,
-					.gain = ST_GYRO_2_FS_AVL_250_GAIN,
+					.value = 0x00,
+					.gain = IIO_DEGREE_TO_RAD(8750),
 				},
 				[1] = {
 					.num = ST_GYRO_FS_AVL_500DPS,
-					.value = ST_GYRO_2_FS_AVL_500_VAL,
-					.gain = ST_GYRO_2_FS_AVL_500_GAIN,
+					.value = 0x01,
+					.gain = IIO_DEGREE_TO_RAD(17500),
 				},
 				[2] = {
 					.num = ST_GYRO_FS_AVL_2000DPS,
-					.value = ST_GYRO_2_FS_AVL_2000_VAL,
-					.gain = ST_GYRO_2_FS_AVL_2000_GAIN,
+					.value = 0x02,
+					.gain = IIO_DEGREE_TO_RAD(70000),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_GYRO_2_BDU_ADDR,
-			.mask = ST_GYRO_2_BDU_MASK,
+			.addr = 0x23,
+			.mask = 0x80,
 		},
 		.drdy_irq = {
-			.addr = ST_GYRO_2_DRDY_IRQ_ADDR,
-			.mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK,
+			.addr = 0x22,
+			.mask_int2 = 0x08,
 			/*
 			 * The sensor has IHL (active low) and open
 			 * drain settings, but only for INT1 and not
@@ -262,29 +189,29 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 			 */
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_GYRO_3_WAI_EXP,
+		.wai = 0xd7,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = L3GD20_GYRO_DEV_NAME,
 		},
 		.ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
 		.odr = {
-			.addr = ST_GYRO_3_ODR_ADDR,
-			.mask = ST_GYRO_3_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0xc0,
 			.odr_avl = {
-				{ 95, ST_GYRO_3_ODR_AVL_95HZ_VAL, },
-				{ 190, ST_GYRO_3_ODR_AVL_190HZ_VAL, },
-				{ 380, ST_GYRO_3_ODR_AVL_380HZ_VAL, },
-				{ 760, ST_GYRO_3_ODR_AVL_760HZ_VAL, },
+				{ .hz = 95, .value = 0x00, },
+				{ .hz = 190, .value = 0x01, },
+				{ .hz = 380, .value = 0x02, },
+				{ .hz = 760, .value = 0x03, },
 			},
 		},
 		.pw = {
-			.addr = ST_GYRO_3_PW_ADDR,
-			.mask = ST_GYRO_3_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x08,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -293,33 +220,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
 		},
 		.fs = {
-			.addr = ST_GYRO_3_FS_ADDR,
-			.mask = ST_GYRO_3_FS_MASK,
+			.addr = 0x23,
+			.mask = 0x30,
 			.fs_avl = {
 				[0] = {
 					.num = ST_GYRO_FS_AVL_250DPS,
-					.value = ST_GYRO_3_FS_AVL_250_VAL,
-					.gain = ST_GYRO_3_FS_AVL_250_GAIN,
+					.value = 0x00,
+					.gain = IIO_DEGREE_TO_RAD(8750),
 				},
 				[1] = {
 					.num = ST_GYRO_FS_AVL_500DPS,
-					.value = ST_GYRO_3_FS_AVL_500_VAL,
-					.gain = ST_GYRO_3_FS_AVL_500_GAIN,
+					.value = 0x01,
+					.gain = IIO_DEGREE_TO_RAD(17500),
 				},
 				[2] = {
 					.num = ST_GYRO_FS_AVL_2000DPS,
-					.value = ST_GYRO_3_FS_AVL_2000_VAL,
-					.gain = ST_GYRO_3_FS_AVL_2000_GAIN,
+					.value = 0x02,
+					.gain = IIO_DEGREE_TO_RAD(70000),
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_GYRO_3_BDU_ADDR,
-			.mask = ST_GYRO_3_BDU_MASK,
+			.addr = 0x23,
+			.mask = 0x80,
 		},
 		.drdy_irq = {
-			.addr = ST_GYRO_3_DRDY_IRQ_ADDR,
-			.mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK,
+			.addr = 0x22,
+			.mask_int2 = 0x08,
 			/*
 			 * The sensor has IHL (active low) and open
 			 * drain settings, but only for INT1 and not
@@ -327,7 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
 			 */
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_GYRO_3_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 };
-- 
2.7.4


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

* [PATCH 3/4] iio: magn: st_magn: inline per-sensor data
  2016-11-09 15:09 [PATCH 0/4] ST Sensors: inline sensor data Linus Walleij
  2016-11-09 15:09 ` [PATCH 1/4] iio: accel: st_accel: inline per-sensor data Linus Walleij
  2016-11-09 15:09 ` [PATCH 2/4] iio: gyro: st_gyro: " Linus Walleij
@ 2016-11-09 15:09 ` Linus Walleij
  2016-11-12 15:45   ` Jonathan Cameron
  2016-11-09 15:10 ` [PATCH 4/4] iio: pressure: st_pressure: " Linus Walleij
  3 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2016-11-09 15:09 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard,
	Linus Walleij

We have #defines for all the individual sensor registers and
value/mask pairs #defined at the top of the file and used at
exactly one spot.

This is usually good if the #defines give a meaning to the
opaque magic numbers.

However in this case, the semantic meaning is inherent in the
name of the C99-addressable fields, and that means duplication
of information, and only makes the code hard to maintain since
you every time have to add a new #define AND update the site
where it is to be used.

Get rid of the #defines and just open code the values into the
appropriate struct elements. Make sure to explicitly address
the .hz and .value fields in the st_sensor_odr_avl struct
so that the meaning of all values is clear.

This patch is purely syntactic should have no semantic effect.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/magnetometer/st_magn_core.c | 376 +++++++++++---------------------
 1 file changed, 125 insertions(+), 251 deletions(-)

diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 3e1f06b2224c..8e1b0861fbe4 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -46,139 +46,12 @@
 #define ST_MAGN_FS_AVL_15000MG			15000
 #define ST_MAGN_FS_AVL_16000MG			16000
 
-/* CUSTOM VALUES FOR SENSOR 0 */
-#define ST_MAGN_0_ODR_ADDR			0x00
-#define ST_MAGN_0_ODR_MASK			0x1c
-#define ST_MAGN_0_ODR_AVL_1HZ_VAL		0x00
-#define ST_MAGN_0_ODR_AVL_2HZ_VAL		0x01
-#define ST_MAGN_0_ODR_AVL_3HZ_VAL		0x02
-#define ST_MAGN_0_ODR_AVL_8HZ_VAL		0x03
-#define ST_MAGN_0_ODR_AVL_15HZ_VAL		0x04
-#define ST_MAGN_0_ODR_AVL_30HZ_VAL		0x05
-#define ST_MAGN_0_ODR_AVL_75HZ_VAL		0x06
-#define ST_MAGN_0_ODR_AVL_220HZ_VAL		0x07
-#define ST_MAGN_0_PW_ADDR			0x02
-#define ST_MAGN_0_PW_MASK			0x03
-#define ST_MAGN_0_PW_ON				0x00
-#define ST_MAGN_0_PW_OFF			0x03
-#define ST_MAGN_0_FS_ADDR			0x01
-#define ST_MAGN_0_FS_MASK			0xe0
-#define ST_MAGN_0_FS_AVL_1300_VAL		0x01
-#define ST_MAGN_0_FS_AVL_1900_VAL		0x02
-#define ST_MAGN_0_FS_AVL_2500_VAL		0x03
-#define ST_MAGN_0_FS_AVL_4000_VAL		0x04
-#define ST_MAGN_0_FS_AVL_4700_VAL		0x05
-#define ST_MAGN_0_FS_AVL_5600_VAL		0x06
-#define ST_MAGN_0_FS_AVL_8100_VAL		0x07
-#define ST_MAGN_0_FS_AVL_1300_GAIN_XY		1100
-#define ST_MAGN_0_FS_AVL_1900_GAIN_XY		855
-#define ST_MAGN_0_FS_AVL_2500_GAIN_XY		670
-#define ST_MAGN_0_FS_AVL_4000_GAIN_XY		450
-#define ST_MAGN_0_FS_AVL_4700_GAIN_XY		400
-#define ST_MAGN_0_FS_AVL_5600_GAIN_XY		330
-#define ST_MAGN_0_FS_AVL_8100_GAIN_XY		230
-#define ST_MAGN_0_FS_AVL_1300_GAIN_Z		980
-#define ST_MAGN_0_FS_AVL_1900_GAIN_Z		760
-#define ST_MAGN_0_FS_AVL_2500_GAIN_Z		600
-#define ST_MAGN_0_FS_AVL_4000_GAIN_Z		400
-#define ST_MAGN_0_FS_AVL_4700_GAIN_Z		355
-#define ST_MAGN_0_FS_AVL_5600_GAIN_Z		295
-#define ST_MAGN_0_FS_AVL_8100_GAIN_Z		205
-#define ST_MAGN_0_MULTIREAD_BIT			false
-
-/* CUSTOM VALUES FOR SENSOR 1 */
-#define ST_MAGN_1_WAI_EXP			0x3c
-#define ST_MAGN_1_ODR_ADDR			0x00
-#define ST_MAGN_1_ODR_MASK			0x1c
-#define ST_MAGN_1_ODR_AVL_1HZ_VAL		0x00
-#define ST_MAGN_1_ODR_AVL_2HZ_VAL		0x01
-#define ST_MAGN_1_ODR_AVL_3HZ_VAL		0x02
-#define ST_MAGN_1_ODR_AVL_8HZ_VAL		0x03
-#define ST_MAGN_1_ODR_AVL_15HZ_VAL		0x04
-#define ST_MAGN_1_ODR_AVL_30HZ_VAL		0x05
-#define ST_MAGN_1_ODR_AVL_75HZ_VAL		0x06
-#define ST_MAGN_1_ODR_AVL_220HZ_VAL		0x07
-#define ST_MAGN_1_PW_ADDR			0x02
-#define ST_MAGN_1_PW_MASK			0x03
-#define ST_MAGN_1_PW_ON				0x00
-#define ST_MAGN_1_PW_OFF			0x03
-#define ST_MAGN_1_FS_ADDR			0x01
-#define ST_MAGN_1_FS_MASK			0xe0
-#define ST_MAGN_1_FS_AVL_1300_VAL		0x01
-#define ST_MAGN_1_FS_AVL_1900_VAL		0x02
-#define ST_MAGN_1_FS_AVL_2500_VAL		0x03
-#define ST_MAGN_1_FS_AVL_4000_VAL		0x04
-#define ST_MAGN_1_FS_AVL_4700_VAL		0x05
-#define ST_MAGN_1_FS_AVL_5600_VAL		0x06
-#define ST_MAGN_1_FS_AVL_8100_VAL		0x07
-#define ST_MAGN_1_FS_AVL_1300_GAIN_XY		909
-#define ST_MAGN_1_FS_AVL_1900_GAIN_XY		1169
-#define ST_MAGN_1_FS_AVL_2500_GAIN_XY		1492
-#define ST_MAGN_1_FS_AVL_4000_GAIN_XY		2222
-#define ST_MAGN_1_FS_AVL_4700_GAIN_XY		2500
-#define ST_MAGN_1_FS_AVL_5600_GAIN_XY		3030
-#define ST_MAGN_1_FS_AVL_8100_GAIN_XY		4347
-#define ST_MAGN_1_FS_AVL_1300_GAIN_Z		1020
-#define ST_MAGN_1_FS_AVL_1900_GAIN_Z		1315
-#define ST_MAGN_1_FS_AVL_2500_GAIN_Z		1666
-#define ST_MAGN_1_FS_AVL_4000_GAIN_Z		2500
-#define ST_MAGN_1_FS_AVL_4700_GAIN_Z		2816
-#define ST_MAGN_1_FS_AVL_5600_GAIN_Z		3389
-#define ST_MAGN_1_FS_AVL_8100_GAIN_Z		4878
-#define ST_MAGN_1_MULTIREAD_BIT			false
-
-/* CUSTOM VALUES FOR SENSOR 2 */
-#define ST_MAGN_2_WAI_EXP			0x3d
-#define ST_MAGN_2_ODR_ADDR			0x20
-#define ST_MAGN_2_ODR_MASK			0x1c
-#define ST_MAGN_2_ODR_AVL_1HZ_VAL		0x00
-#define ST_MAGN_2_ODR_AVL_2HZ_VAL		0x01
-#define ST_MAGN_2_ODR_AVL_3HZ_VAL		0x02
-#define ST_MAGN_2_ODR_AVL_5HZ_VAL		0x03
-#define ST_MAGN_2_ODR_AVL_10HZ_VAL		0x04
-#define ST_MAGN_2_ODR_AVL_20HZ_VAL		0x05
-#define ST_MAGN_2_ODR_AVL_40HZ_VAL		0x06
-#define ST_MAGN_2_ODR_AVL_80HZ_VAL		0x07
-#define ST_MAGN_2_PW_ADDR			0x22
-#define ST_MAGN_2_PW_MASK			0x03
-#define ST_MAGN_2_PW_ON				0x00
-#define ST_MAGN_2_PW_OFF			0x03
-#define ST_MAGN_2_FS_ADDR			0x21
-#define ST_MAGN_2_FS_MASK			0x60
-#define ST_MAGN_2_FS_AVL_4000_VAL		0x00
-#define ST_MAGN_2_FS_AVL_8000_VAL		0x01
-#define ST_MAGN_2_FS_AVL_12000_VAL		0x02
-#define ST_MAGN_2_FS_AVL_16000_VAL		0x03
-#define ST_MAGN_2_FS_AVL_4000_GAIN		146
-#define ST_MAGN_2_FS_AVL_8000_GAIN		292
-#define ST_MAGN_2_FS_AVL_12000_GAIN		438
-#define ST_MAGN_2_FS_AVL_16000_GAIN		584
-#define ST_MAGN_2_MULTIREAD_BIT			false
+/* Special L addresses for Sensor 2 */
 #define ST_MAGN_2_OUT_X_L_ADDR			0x28
 #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_IHL_IRQ_ADDR			0x63
-#define ST_MAGN_3_IHL_IRQ_MASK			0x04
-#define ST_MAGN_3_FS_AVL_15000_GAIN		1500
-#define ST_MAGN_3_MULTIREAD_BIT			false
+/* Special L addresses for sensor 3 */
 #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
@@ -240,77 +113,78 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
 		},
 		.ch = (struct iio_chan_spec *)st_magn_16bit_channels,
 		.odr = {
-			.addr = ST_MAGN_0_ODR_ADDR,
-			.mask = ST_MAGN_0_ODR_MASK,
+			.addr = 0x00,
+			.mask = 0x1c,
 			.odr_avl = {
-				{ 1, ST_MAGN_0_ODR_AVL_1HZ_VAL, },
-				{ 2, ST_MAGN_0_ODR_AVL_2HZ_VAL, },
-				{ 3, ST_MAGN_0_ODR_AVL_3HZ_VAL, },
-				{ 8, ST_MAGN_0_ODR_AVL_8HZ_VAL, },
-				{ 15, ST_MAGN_0_ODR_AVL_15HZ_VAL, },
-				{ 30, ST_MAGN_0_ODR_AVL_30HZ_VAL, },
-				{ 75, ST_MAGN_0_ODR_AVL_75HZ_VAL, },
+				{ .hz = 1, .value = 0x00 },
+				{ .hz = 2, .value = 0x01 },
+				{ .hz = 3, .value = 0x02 },
+				{ .hz = 8, .value = 0x03 },
+				{ .hz = 15, .value = 0x04 },
+				{ .hz = 30, .value = 0x05 },
+				{ .hz = 75, .value = 0x06 },
+				/* 220 Hz, 0x07 reportedly exist */
 			},
 		},
 		.pw = {
-			.addr = ST_MAGN_0_PW_ADDR,
-			.mask = ST_MAGN_0_PW_MASK,
-			.value_on = ST_MAGN_0_PW_ON,
-			.value_off = ST_MAGN_0_PW_OFF,
+			.addr = 0x02,
+			.mask = 0x03,
+			.value_on = 0x00,
+			.value_off = 0x03,
 		},
 		.fs = {
-			.addr = ST_MAGN_0_FS_ADDR,
-			.mask = ST_MAGN_0_FS_MASK,
+			.addr = 0x01,
+			.mask = 0xe0,
 			.fs_avl = {
 				[0] = {
 					.num = ST_MAGN_FS_AVL_1300MG,
-					.value = ST_MAGN_0_FS_AVL_1300_VAL,
-					.gain = ST_MAGN_0_FS_AVL_1300_GAIN_XY,
-					.gain2 = ST_MAGN_0_FS_AVL_1300_GAIN_Z,
+					.value = 0x01,
+					.gain = 1100,
+					.gain2 = 980,
 				},
 				[1] = {
 					.num = ST_MAGN_FS_AVL_1900MG,
-					.value = ST_MAGN_0_FS_AVL_1900_VAL,
-					.gain = ST_MAGN_0_FS_AVL_1900_GAIN_XY,
-					.gain2 = ST_MAGN_0_FS_AVL_1900_GAIN_Z,
+					.value = 0x02,
+					.gain = 855,
+					.gain2 = 760,
 				},
 				[2] = {
 					.num = ST_MAGN_FS_AVL_2500MG,
-					.value = ST_MAGN_0_FS_AVL_2500_VAL,
-					.gain = ST_MAGN_0_FS_AVL_2500_GAIN_XY,
-					.gain2 = ST_MAGN_0_FS_AVL_2500_GAIN_Z,
+					.value = 0x03,
+					.gain = 670,
+					.gain2 = 600,
 				},
 				[3] = {
 					.num = ST_MAGN_FS_AVL_4000MG,
-					.value = ST_MAGN_0_FS_AVL_4000_VAL,
-					.gain = ST_MAGN_0_FS_AVL_4000_GAIN_XY,
-					.gain2 = ST_MAGN_0_FS_AVL_4000_GAIN_Z,
+					.value = 0x04,
+					.gain = 450,
+					.gain2 = 400,
 				},
 				[4] = {
 					.num = ST_MAGN_FS_AVL_4700MG,
-					.value = ST_MAGN_0_FS_AVL_4700_VAL,
-					.gain = ST_MAGN_0_FS_AVL_4700_GAIN_XY,
-					.gain2 = ST_MAGN_0_FS_AVL_4700_GAIN_Z,
+					.value = 0x05,
+					.gain = 400,
+					.gain2 = 355,
 				},
 				[5] = {
 					.num = ST_MAGN_FS_AVL_5600MG,
-					.value = ST_MAGN_0_FS_AVL_5600_VAL,
-					.gain = ST_MAGN_0_FS_AVL_5600_GAIN_XY,
-					.gain2 = ST_MAGN_0_FS_AVL_5600_GAIN_Z,
+					.value = 0x06,
+					.gain = 330,
+					.gain2 = 295,
 				},
 				[6] = {
 					.num = ST_MAGN_FS_AVL_8100MG,
-					.value = ST_MAGN_0_FS_AVL_8100_VAL,
-					.gain = ST_MAGN_0_FS_AVL_8100_GAIN_XY,
-					.gain2 = ST_MAGN_0_FS_AVL_8100_GAIN_Z,
+					.value = 0x07,
+					.gain = 230,
+					.gain2 = 205,
 				},
 			},
 		},
-		.multi_read_bit = ST_MAGN_0_MULTIREAD_BIT,
+		.multi_read_bit = false,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_MAGN_1_WAI_EXP,
+		.wai = 0x3c,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LSM303DLHC_MAGN_DEV_NAME,
@@ -318,175 +192,175 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
 		},
 		.ch = (struct iio_chan_spec *)st_magn_16bit_channels,
 		.odr = {
-			.addr = ST_MAGN_1_ODR_ADDR,
-			.mask = ST_MAGN_1_ODR_MASK,
+			.addr = 0x00,
+			.mask = 0x1c,
 			.odr_avl = {
-				{ 1, ST_MAGN_1_ODR_AVL_1HZ_VAL, },
-				{ 2, ST_MAGN_1_ODR_AVL_2HZ_VAL, },
-				{ 3, ST_MAGN_1_ODR_AVL_3HZ_VAL, },
-				{ 8, ST_MAGN_1_ODR_AVL_8HZ_VAL, },
-				{ 15, ST_MAGN_1_ODR_AVL_15HZ_VAL, },
-				{ 30, ST_MAGN_1_ODR_AVL_30HZ_VAL, },
-				{ 75, ST_MAGN_1_ODR_AVL_75HZ_VAL, },
-				{ 220, ST_MAGN_1_ODR_AVL_220HZ_VAL, },
+				{ .hz = 1, .value = 0x00 },
+				{ .hz = 2, .value = 0x01 },
+				{ .hz = 3, .value = 0x02 },
+				{ .hz = 8, .value = 0x03 },
+				{ .hz = 15, .value = 0x04 },
+				{ .hz = 30, .value = 0x05 },
+				{ .hz = 75, .value = 0x06 },
+				{ .hz = 220, .value = 0x07 },
 			},
 		},
 		.pw = {
-			.addr = ST_MAGN_1_PW_ADDR,
-			.mask = ST_MAGN_1_PW_MASK,
-			.value_on = ST_MAGN_1_PW_ON,
-			.value_off = ST_MAGN_1_PW_OFF,
+			.addr = 0x02,
+			.mask = 0x03,
+			.value_on = 0x00,
+			.value_off = 0x03,
 		},
 		.fs = {
-			.addr = ST_MAGN_1_FS_ADDR,
-			.mask = ST_MAGN_1_FS_MASK,
+			.addr = 0x01,
+			.mask = 0xe0,
 			.fs_avl = {
 				[0] = {
 					.num = ST_MAGN_FS_AVL_1300MG,
-					.value = ST_MAGN_1_FS_AVL_1300_VAL,
-					.gain = ST_MAGN_1_FS_AVL_1300_GAIN_XY,
-					.gain2 = ST_MAGN_1_FS_AVL_1300_GAIN_Z,
+					.value = 0x01,
+					.gain = 909,
+					.gain2 = 1020,
 				},
 				[1] = {
 					.num = ST_MAGN_FS_AVL_1900MG,
-					.value = ST_MAGN_1_FS_AVL_1900_VAL,
-					.gain = ST_MAGN_1_FS_AVL_1900_GAIN_XY,
-					.gain2 = ST_MAGN_1_FS_AVL_1900_GAIN_Z,
+					.value = 0x02,
+					.gain = 1169,
+					.gain2 = 1315,
 				},
 				[2] = {
 					.num = ST_MAGN_FS_AVL_2500MG,
-					.value = ST_MAGN_1_FS_AVL_2500_VAL,
-					.gain = ST_MAGN_1_FS_AVL_2500_GAIN_XY,
-					.gain2 = ST_MAGN_1_FS_AVL_2500_GAIN_Z,
+					.value = 0x03,
+					.gain = 1492,
+					.gain2 = 1666,
 				},
 				[3] = {
 					.num = ST_MAGN_FS_AVL_4000MG,
-					.value = ST_MAGN_1_FS_AVL_4000_VAL,
-					.gain = ST_MAGN_1_FS_AVL_4000_GAIN_XY,
-					.gain2 = ST_MAGN_1_FS_AVL_4000_GAIN_Z,
+					.value = 0x04,
+					.gain = 2222,
+					.gain2 = 2500,
 				},
 				[4] = {
 					.num = ST_MAGN_FS_AVL_4700MG,
-					.value = ST_MAGN_1_FS_AVL_4700_VAL,
-					.gain = ST_MAGN_1_FS_AVL_4700_GAIN_XY,
-					.gain2 = ST_MAGN_1_FS_AVL_4700_GAIN_Z,
+					.value = 0x05,
+					.gain = 2500,
+					.gain2 = 2816,
 				},
 				[5] = {
 					.num = ST_MAGN_FS_AVL_5600MG,
-					.value = ST_MAGN_1_FS_AVL_5600_VAL,
-					.gain = ST_MAGN_1_FS_AVL_5600_GAIN_XY,
-					.gain2 = ST_MAGN_1_FS_AVL_5600_GAIN_Z,
+					.value = 0x06,
+					.gain = 3030,
+					.gain2 = 3389,
 				},
 				[6] = {
 					.num = ST_MAGN_FS_AVL_8100MG,
-					.value = ST_MAGN_1_FS_AVL_8100_VAL,
-					.gain = ST_MAGN_1_FS_AVL_8100_GAIN_XY,
-					.gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z,
+					.value = 0x07,
+					.gain = 4347,
+					.gain2 = 4878,
 				},
 			},
 		},
-		.multi_read_bit = ST_MAGN_1_MULTIREAD_BIT,
+		.multi_read_bit = false,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_MAGN_2_WAI_EXP,
+		.wai = 0x3d,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LIS3MDL_MAGN_DEV_NAME,
 		},
 		.ch = (struct iio_chan_spec *)st_magn_2_16bit_channels,
 		.odr = {
-			.addr = ST_MAGN_2_ODR_ADDR,
-			.mask = ST_MAGN_2_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x1c,
 			.odr_avl = {
-				{ 1, ST_MAGN_2_ODR_AVL_1HZ_VAL, },
-				{ 2, ST_MAGN_2_ODR_AVL_2HZ_VAL, },
-				{ 3, ST_MAGN_2_ODR_AVL_3HZ_VAL, },
-				{ 5, ST_MAGN_2_ODR_AVL_5HZ_VAL, },
-				{ 10, ST_MAGN_2_ODR_AVL_10HZ_VAL, },
-				{ 20, ST_MAGN_2_ODR_AVL_20HZ_VAL, },
-				{ 40, ST_MAGN_2_ODR_AVL_40HZ_VAL, },
-				{ 80, ST_MAGN_2_ODR_AVL_80HZ_VAL, },
+				{ .hz = 1, .value = 0x00 },
+				{ .hz = 2, .value = 0x01 },
+				{ .hz = 3, .value = 0x02 },
+				{ .hz = 5, .value = 0x03 },
+				{ .hz = 10, .value = 0x04 },
+				{ .hz = 20, .value = 0x05 },
+				{ .hz = 40, .value = 0x06 },
+				{ .hz = 80, .value = 0x07 },
 			},
 		},
 		.pw = {
-			.addr = ST_MAGN_2_PW_ADDR,
-			.mask = ST_MAGN_2_PW_MASK,
-			.value_on = ST_MAGN_2_PW_ON,
-			.value_off = ST_MAGN_2_PW_OFF,
+			.addr = 0x22,
+			.mask = 0x03,
+			.value_on = 0x00,
+			.value_off = 0x03,
 		},
 		.fs = {
-			.addr = ST_MAGN_2_FS_ADDR,
-			.mask = ST_MAGN_2_FS_MASK,
+			.addr = 0x21,
+			.mask = 0x60,
 			.fs_avl = {
 				[0] = {
 					.num = ST_MAGN_FS_AVL_4000MG,
-					.value = ST_MAGN_2_FS_AVL_4000_VAL,
-					.gain = ST_MAGN_2_FS_AVL_4000_GAIN,
+					.value = 0x00,
+					.gain = 146,
 				},
 				[1] = {
 					.num = ST_MAGN_FS_AVL_8000MG,
-					.value = ST_MAGN_2_FS_AVL_8000_VAL,
-					.gain = ST_MAGN_2_FS_AVL_8000_GAIN,
+					.value = 0x01,
+					.gain = 292,
 				},
 				[2] = {
 					.num = ST_MAGN_FS_AVL_12000MG,
-					.value = ST_MAGN_2_FS_AVL_12000_VAL,
-					.gain = ST_MAGN_2_FS_AVL_12000_GAIN,
+					.value = 0x02,
+					.gain = 438,
 				},
 				[3] = {
 					.num = ST_MAGN_FS_AVL_16000MG,
-					.value = ST_MAGN_2_FS_AVL_16000_VAL,
-					.gain = ST_MAGN_2_FS_AVL_16000_GAIN,
+					.value = 0x03,
+					.gain = 584,
 				},
 			},
 		},
-		.multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
+		.multi_read_bit = false,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_MAGN_3_WAI_EXP,
-		.wai_addr = ST_MAGN_3_WAI_ADDR,
+		.wai = 0x40,
+		.wai_addr = 0x4f,
 		.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,
+			.addr = 0x60,
+			.mask = 0x0c,
 			.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, },
+				{ .hz = 10, .value = 0x00 },
+				{ .hz = 20, .value = 0x01 },
+				{ .hz = 50, .value = 0x02 },
+				{ .hz = 100, .value = 0x03 },
 			},
 		},
 		.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,
+			.addr = 0x60,
+			.mask = 0x03,
+			.value_on = 0x00,
+			.value_off = 0x03,
 		},
 		.fs = {
 			.fs_avl = {
 				[0] = {
 					.num = ST_MAGN_FS_AVL_15000MG,
-					.gain = ST_MAGN_3_FS_AVL_15000_GAIN,
+					.gain = 1500,
 				},
 			},
 		},
 		.bdu = {
-			.addr = ST_MAGN_3_BDU_ADDR,
-			.mask = ST_MAGN_3_BDU_MASK,
+			.addr = 0x62,
+			.mask = 0x10,
 		},
 		.drdy_irq = {
-			.addr = ST_MAGN_3_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_MAGN_3_DRDY_INT_MASK,
-			.addr_ihl = ST_MAGN_3_IHL_IRQ_ADDR,
-			.mask_ihl = ST_MAGN_3_IHL_IRQ_MASK,
+			.addr = 0x62,
+			.mask_int1 = 0x01,
+			.addr_ihl = 0x63,
+			.mask_ihl = 0x04,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_MAGN_3_MULTIREAD_BIT,
+		.multi_read_bit = false,
 		.bootime = 2,
 	},
 };
-- 
2.7.4

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

* [PATCH 4/4] iio: pressure: st_pressure: inline per-sensor data
  2016-11-09 15:09 [PATCH 0/4] ST Sensors: inline sensor data Linus Walleij
                   ` (2 preceding siblings ...)
  2016-11-09 15:09 ` [PATCH 3/4] iio: magn: st_magn: " Linus Walleij
@ 2016-11-09 15:10 ` Linus Walleij
  2016-11-12 15:50   ` Jonathan Cameron
  3 siblings, 1 reply; 10+ messages in thread
From: Linus Walleij @ 2016-11-09 15:10 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard,
	Linus Walleij

We have #defines for all the individual sensor registers and
value/mask pairs #defined at the top of the file and used at
exactly one spot.

This is usually good if the #defines give a meaning to the
opaque magic numbers.

However in this case, the semantic meaning is inherent in the
name of the C99-addressable fields, and that means duplication
of information, and only makes the code hard to maintain since
you every time have to add a new #define AND update the site
where it is to be used.

Get rid of the #defines and just open code the values into the
appropriate struct elements. Make sure to explicitly address
the .hz and .value fields in the st_sensor_odr_avl struct
so that the meaning of all values is clear.

This patch is purely syntactic should have no semantic effect.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/pressure/st_pressure_core.c | 257 ++++++++++++--------------------
 1 file changed, 92 insertions(+), 165 deletions(-)

diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 55df9a75eb3a..e19e0787864c 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -112,115 +112,24 @@
 #define ST_PRESS_1_OUT_XL_ADDR			0x28
 #define ST_TEMP_1_OUT_L_ADDR			0x2b
 
-/*
- * CUSTOM VALUES FOR LPS331AP SENSOR
- * See LPS331AP datasheet:
- * http://www2.st.com/resource/en/datasheet/lps331ap.pdf
- */
-#define ST_PRESS_LPS331AP_WAI_EXP		0xbb
-#define ST_PRESS_LPS331AP_ODR_ADDR		0x20
-#define ST_PRESS_LPS331AP_ODR_MASK		0x70
-#define ST_PRESS_LPS331AP_ODR_AVL_1HZ_VAL	0x01
-#define ST_PRESS_LPS331AP_ODR_AVL_7HZ_VAL	0x05
-#define ST_PRESS_LPS331AP_ODR_AVL_13HZ_VAL	0x06
-#define ST_PRESS_LPS331AP_ODR_AVL_25HZ_VAL	0x07
-#define ST_PRESS_LPS331AP_PW_ADDR		0x20
-#define ST_PRESS_LPS331AP_PW_MASK		0x80
-#define ST_PRESS_LPS331AP_FS_ADDR		0x23
-#define ST_PRESS_LPS331AP_FS_MASK		0x30
-#define ST_PRESS_LPS331AP_BDU_ADDR		0x20
-#define ST_PRESS_LPS331AP_BDU_MASK		0x04
-#define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR		0x22
-#define ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK	0x04
-#define ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK	0x20
-#define ST_PRESS_LPS331AP_IHL_IRQ_ADDR		0x22
-#define ST_PRESS_LPS331AP_IHL_IRQ_MASK		0x80
-#define ST_PRESS_LPS331AP_OD_IRQ_ADDR		0x22
-#define ST_PRESS_LPS331AP_OD_IRQ_MASK		0x40
-#define ST_PRESS_LPS331AP_MULTIREAD_BIT		true
-
-/*
- * CUSTOM VALUES FOR THE OBSOLETE LPS001WP SENSOR
- */
-
 /* LPS001WP pressure resolution */
 #define ST_PRESS_LPS001WP_LSB_PER_MBAR		16UL
 /* LPS001WP temperature resolution */
 #define ST_PRESS_LPS001WP_LSB_PER_CELSIUS	64UL
-
-#define ST_PRESS_LPS001WP_WAI_EXP		0xba
-#define ST_PRESS_LPS001WP_ODR_ADDR		0x20
-#define ST_PRESS_LPS001WP_ODR_MASK		0x30
-#define ST_PRESS_LPS001WP_ODR_AVL_1HZ_VAL	0x01
-#define ST_PRESS_LPS001WP_ODR_AVL_7HZ_VAL	0x02
-#define ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL	0x03
-#define ST_PRESS_LPS001WP_PW_ADDR		0x20
-#define ST_PRESS_LPS001WP_PW_MASK		0x40
+/* LPS001WP pressure gain */
 #define ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN \
 	(100000000UL / ST_PRESS_LPS001WP_LSB_PER_MBAR)
-#define ST_PRESS_LPS001WP_BDU_ADDR		0x20
-#define ST_PRESS_LPS001WP_BDU_MASK		0x04
-#define ST_PRESS_LPS001WP_MULTIREAD_BIT		true
+/* LPS001WP pressure and temp L addresses */
 #define ST_PRESS_LPS001WP_OUT_L_ADDR		0x28
 #define ST_TEMP_LPS001WP_OUT_L_ADDR		0x2a
 
-/*
- * CUSTOM VALUES FOR LPS25H SENSOR
- * See LPS25H datasheet:
- * http://www2.st.com/resource/en/datasheet/lps25h.pdf
- */
-#define ST_PRESS_LPS25H_WAI_EXP			0xbd
-#define ST_PRESS_LPS25H_ODR_ADDR		0x20
-#define ST_PRESS_LPS25H_ODR_MASK		0x70
-#define ST_PRESS_LPS25H_ODR_AVL_1HZ_VAL		0x01
-#define ST_PRESS_LPS25H_ODR_AVL_7HZ_VAL		0x02
-#define ST_PRESS_LPS25H_ODR_AVL_13HZ_VAL	0x03
-#define ST_PRESS_LPS25H_ODR_AVL_25HZ_VAL	0x04
-#define ST_PRESS_LPS25H_PW_ADDR			0x20
-#define ST_PRESS_LPS25H_PW_MASK			0x80
-#define ST_PRESS_LPS25H_BDU_ADDR		0x20
-#define ST_PRESS_LPS25H_BDU_MASK		0x04
-#define ST_PRESS_LPS25H_DRDY_IRQ_ADDR		0x23
-#define ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK	0x01
-#define ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK	0x10
-#define ST_PRESS_LPS25H_IHL_IRQ_ADDR		0x22
-#define ST_PRESS_LPS25H_IHL_IRQ_MASK		0x80
-#define ST_PRESS_LPS25H_OD_IRQ_ADDR		0x22
-#define ST_PRESS_LPS25H_OD_IRQ_MASK		0x40
-#define ST_PRESS_LPS25H_MULTIREAD_BIT		true
+/* LPS25H pressure and temp L addresses */
 #define ST_PRESS_LPS25H_OUT_XL_ADDR		0x28
 #define ST_TEMP_LPS25H_OUT_L_ADDR		0x2b
 
-/*
- * CUSTOM VALUES FOR LPS22HB SENSOR
- * See LPS22HB datasheet:
- * http://www2.st.com/resource/en/datasheet/lps22hb.pdf
- */
-
 /* LPS22HB temperature sensitivity */
 #define ST_PRESS_LPS22HB_LSB_PER_CELSIUS	100UL
 
-#define ST_PRESS_LPS22HB_WAI_EXP		0xb1
-#define ST_PRESS_LPS22HB_ODR_ADDR		0x10
-#define ST_PRESS_LPS22HB_ODR_MASK		0x70
-#define ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL	0x01
-#define ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL	0x02
-#define ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL	0x03
-#define ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL	0x04
-#define ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL	0x05
-#define ST_PRESS_LPS22HB_PW_ADDR		0x10
-#define ST_PRESS_LPS22HB_PW_MASK		0x70
-#define ST_PRESS_LPS22HB_BDU_ADDR		0x10
-#define ST_PRESS_LPS22HB_BDU_MASK		0x02
-#define ST_PRESS_LPS22HB_DRDY_IRQ_ADDR		0x12
-#define ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK	0x04
-#define ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK	0x08
-#define ST_PRESS_LPS22HB_IHL_IRQ_ADDR		0x12
-#define ST_PRESS_LPS22HB_IHL_IRQ_MASK		0x80
-#define ST_PRESS_LPS22HB_OD_IRQ_ADDR		0x12
-#define ST_PRESS_LPS22HB_OD_IRQ_MASK		0x40
-#define ST_PRESS_LPS22HB_MULTIREAD_BIT		true
-
 static const struct iio_chan_spec st_press_1_channels[] = {
 	{
 		.type = IIO_PRESSURE,
@@ -321,7 +230,12 @@ static const struct iio_chan_spec st_press_lps22hb_channels[] = {
 
 static const struct st_sensor_settings st_press_sensors_settings[] = {
 	{
-		.wai = ST_PRESS_LPS331AP_WAI_EXP,
+		/*
+		 * CUSTOM VALUES FOR LPS331AP SENSOR
+		 * See LPS331AP datasheet:
+		 * http://www2.st.com/resource/en/datasheet/lps331ap.pdf
+		 */
+		.wai = 0xbb,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LPS331AP_PRESS_DEV_NAME,
@@ -329,24 +243,24 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 		.ch = (struct iio_chan_spec *)st_press_1_channels,
 		.num_ch = ARRAY_SIZE(st_press_1_channels),
 		.odr = {
-			.addr = ST_PRESS_LPS331AP_ODR_ADDR,
-			.mask = ST_PRESS_LPS331AP_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x70,
 			.odr_avl = {
-				{ 1, ST_PRESS_LPS331AP_ODR_AVL_1HZ_VAL, },
-				{ 7, ST_PRESS_LPS331AP_ODR_AVL_7HZ_VAL, },
-				{ 13, ST_PRESS_LPS331AP_ODR_AVL_13HZ_VAL, },
-				{ 25, ST_PRESS_LPS331AP_ODR_AVL_25HZ_VAL, },
+				{ .hz = 1, .value = 0x01 },
+				{ .hz = 7, .value = 0x05 },
+				{ .hz = 13, .value = 0x06 },
+				{ .hz = 25, .value = 0x07 },
 			},
 		},
 		.pw = {
-			.addr = ST_PRESS_LPS331AP_PW_ADDR,
-			.mask = ST_PRESS_LPS331AP_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x80,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
 		.fs = {
-			.addr = ST_PRESS_LPS331AP_FS_ADDR,
-			.mask = ST_PRESS_LPS331AP_FS_MASK,
+			.addr = 0x23,
+			.mask = 0x30,
 			.fs_avl = {
 				/*
 				 * Pressure and temperature sensitivity values
@@ -360,24 +274,27 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 			},
 		},
 		.bdu = {
-			.addr = ST_PRESS_LPS331AP_BDU_ADDR,
-			.mask = ST_PRESS_LPS331AP_BDU_MASK,
+			.addr = 0x20,
+			.mask = 0x04,
 		},
 		.drdy_irq = {
-			.addr = ST_PRESS_LPS331AP_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_PRESS_LPS331AP_IHL_IRQ_ADDR,
-			.mask_ihl = ST_PRESS_LPS331AP_IHL_IRQ_MASK,
-			.addr_od = ST_PRESS_LPS331AP_OD_IRQ_ADDR,
-			.mask_od = ST_PRESS_LPS331AP_OD_IRQ_MASK,
+			.addr = 0x22,
+			.mask_int1 = 0x04,
+			.mask_int2 = 0x20,
+			.addr_ihl = 0x22,
+			.mask_ihl = 0x80,
+			.addr_od = 0x22,
+			.mask_od = 0x40,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_PRESS_LPS331AP_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_PRESS_LPS001WP_WAI_EXP,
+		/*
+		 * CUSTOM VALUES FOR LPS001WP SENSOR
+		 */
+		.wai = 0xba,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LPS001WP_PRESS_DEV_NAME,
@@ -385,17 +302,17 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 		.ch = (struct iio_chan_spec *)st_press_lps001wp_channels,
 		.num_ch = ARRAY_SIZE(st_press_lps001wp_channels),
 		.odr = {
-			.addr = ST_PRESS_LPS001WP_ODR_ADDR,
-			.mask = ST_PRESS_LPS001WP_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x30,
 			.odr_avl = {
-				{ 1, ST_PRESS_LPS001WP_ODR_AVL_1HZ_VAL, },
-				{ 7, ST_PRESS_LPS001WP_ODR_AVL_7HZ_VAL, },
-				{ 13, ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL, },
+				{ .hz = 1, .value = 0x01 },
+				{ .hz = 7, .value = 0x02 },
+				{ .hz = 13, .value = 0x03 },
 			},
 		},
 		.pw = {
-			.addr = ST_PRESS_LPS001WP_PW_ADDR,
-			.mask = ST_PRESS_LPS001WP_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x40,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -413,17 +330,22 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 			},
 		},
 		.bdu = {
-			.addr = ST_PRESS_LPS001WP_BDU_ADDR,
-			.mask = ST_PRESS_LPS001WP_BDU_MASK,
+			.addr = 0x20,
+			.mask = 0x04,
 		},
 		.drdy_irq = {
 			.addr = 0,
 		},
-		.multi_read_bit = ST_PRESS_LPS001WP_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_PRESS_LPS25H_WAI_EXP,
+		/*
+		 * CUSTOM VALUES FOR LPS25H SENSOR
+		 * See LPS25H datasheet:
+		 * http://www2.st.com/resource/en/datasheet/lps25h.pdf
+		 */
+		.wai = 0xbd,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LPS25H_PRESS_DEV_NAME,
@@ -431,18 +353,18 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 		.ch = (struct iio_chan_spec *)st_press_1_channels,
 		.num_ch = ARRAY_SIZE(st_press_1_channels),
 		.odr = {
-			.addr = ST_PRESS_LPS25H_ODR_ADDR,
-			.mask = ST_PRESS_LPS25H_ODR_MASK,
+			.addr = 0x20,
+			.mask = 0x70,
 			.odr_avl = {
-				{ 1, ST_PRESS_LPS25H_ODR_AVL_1HZ_VAL, },
-				{ 7, ST_PRESS_LPS25H_ODR_AVL_7HZ_VAL, },
-				{ 13, ST_PRESS_LPS25H_ODR_AVL_13HZ_VAL, },
-				{ 25, ST_PRESS_LPS25H_ODR_AVL_25HZ_VAL, },
+				{ .hz = 1, .value = 0x01 },
+				{ .hz = 7, .value = 0x02 },
+				{ .hz = 13, .value = 0x03 },
+				{ .hz = 25, .value = 0x04 },
 			},
 		},
 		.pw = {
-			.addr = ST_PRESS_LPS25H_PW_ADDR,
-			.mask = ST_PRESS_LPS25H_PW_MASK,
+			.addr = 0x20,
+			.mask = 0x80,
 			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
@@ -460,24 +382,29 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 			},
 		},
 		.bdu = {
-			.addr = ST_PRESS_LPS25H_BDU_ADDR,
-			.mask = ST_PRESS_LPS25H_BDU_MASK,
+			.addr = 0x20,
+			.mask = 0x04,
 		},
 		.drdy_irq = {
-			.addr = ST_PRESS_LPS25H_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_PRESS_LPS25H_IHL_IRQ_ADDR,
-			.mask_ihl = ST_PRESS_LPS25H_IHL_IRQ_MASK,
-			.addr_od = ST_PRESS_LPS25H_OD_IRQ_ADDR,
-			.mask_od = ST_PRESS_LPS25H_OD_IRQ_MASK,
+			.addr = 0x23,
+			.mask_int1 = 0x01,
+			.mask_int2 = 0x10,
+			.addr_ihl = 0x22,
+			.mask_ihl = 0x80,
+			.addr_od = 0x22,
+			.mask_od = 0x40,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT,
+		.multi_read_bit = true,
 		.bootime = 2,
 	},
 	{
-		.wai = ST_PRESS_LPS22HB_WAI_EXP,
+		/*
+		 * CUSTOM VALUES FOR LPS22HB SENSOR
+		 * See LPS22HB datasheet:
+		 * http://www2.st.com/resource/en/datasheet/lps22hb.pdf
+		 */
+		.wai = 0xb1,
 		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
 		.sensors_supported = {
 			[0] = LPS22HB_PRESS_DEV_NAME,
@@ -485,19 +412,19 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 		.ch = (struct iio_chan_spec *)st_press_lps22hb_channels,
 		.num_ch = ARRAY_SIZE(st_press_lps22hb_channels),
 		.odr = {
-			.addr = ST_PRESS_LPS22HB_ODR_ADDR,
-			.mask = ST_PRESS_LPS22HB_ODR_MASK,
+			.addr = 0x10,
+			.mask = 0x70,
 			.odr_avl = {
-				{ 1, ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL, },
-				{ 10, ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL, },
-				{ 25, ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL, },
-				{ 50, ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL, },
-				{ 75, ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL, },
+				{ .hz = 1, .value = 0x01 },
+				{ .hz = 10, .value = 0x02 },
+				{ .hz = 25, .value = 0x03 },
+				{ .hz = 50, .value = 0x04 },
+				{ .hz = 75, .value = 0x05 },
 			},
 		},
 		.pw = {
-			.addr = ST_PRESS_LPS22HB_PW_ADDR,
-			.mask = ST_PRESS_LPS22HB_PW_MASK,
+			.addr = 0x10,
+			.mask = 0x70,
 			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
 		},
 		.fs = {
@@ -514,20 +441,20 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
 			},
 		},
 		.bdu = {
-			.addr = ST_PRESS_LPS22HB_BDU_ADDR,
-			.mask = ST_PRESS_LPS22HB_BDU_MASK,
+			.addr = 0x10,
+			.mask = 0x02,
 		},
 		.drdy_irq = {
-			.addr = ST_PRESS_LPS22HB_DRDY_IRQ_ADDR,
-			.mask_int1 = ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK,
-			.mask_int2 = ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK,
-			.addr_ihl = ST_PRESS_LPS22HB_IHL_IRQ_ADDR,
-			.mask_ihl = ST_PRESS_LPS22HB_IHL_IRQ_MASK,
-			.addr_od = ST_PRESS_LPS22HB_OD_IRQ_ADDR,
-			.mask_od = ST_PRESS_LPS22HB_OD_IRQ_MASK,
+			.addr = 0x12,
+			.mask_int1 = 0x04,
+			.mask_int2 = 0x08,
+			.addr_ihl = 0x12,
+			.mask_ihl = 0x80,
+			.addr_od = 0x12,
+			.mask_od = 0x40,
 			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
 		},
-		.multi_read_bit = ST_PRESS_LPS22HB_MULTIREAD_BIT,
+		.multi_read_bit = true,
 	},
 };
 
-- 
2.7.4

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

* Re: [PATCH 1/4] iio: accel: st_accel: inline per-sensor data
  2016-11-09 15:09 ` [PATCH 1/4] iio: accel: st_accel: inline per-sensor data Linus Walleij
@ 2016-11-12 15:29   ` Jonathan Cameron
  2016-11-12 15:34     ` Jonathan Cameron
  0 siblings, 1 reply; 10+ messages in thread
From: Jonathan Cameron @ 2016-11-12 15:29 UTC (permalink / raw)
  To: Linus Walleij, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard

On 09/11/16 15:09, Linus Walleij wrote:
> We have #defines for all the individual sensor registers and
> value/mask pairs #defined at the top of the file and used at
> exactly one spot.
> 
> This is usually good if the #defines give a meaning to the
> opaque magic numbers.
> 
> However in this case, the semantic meaning is inherent in the
> name of the C99-addressable fields, and that means duplication
> of information, and only makes the code hard to maintain since
> you every time have to add a new #define AND update the site
> where it is to be used.
> 
> Get rid of the #defines and just open code the values into the
> appropriate struct elements. Make sure to explicitly address
> the .hz and .value fields in the st_sensor_odr_avl struct
> so that the meaning of all values is clear.
> 
> This patch is purely syntactic should have no semantic effect.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Interesting that sensor type 5 has IG1 address / mask defined (previously) but
not used... hohum. I have no idea what those even are ;)

My only conselation in having just checked this is it must have
been even more boring to write as a patch!

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/accel/st_accel_core.c | 538 +++++++++++++-------------------------
>  1 file changed, 177 insertions(+), 361 deletions(-)
> 
> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
> index da3fb069ec5c..d21b2dbe7432 100644
> --- a/drivers/iio/accel/st_accel_core.c
> +++ b/drivers/iio/accel/st_accel_core.c
> @@ -43,194 +43,6 @@
>  #define ST_ACCEL_FS_AVL_200G			200
>  #define ST_ACCEL_FS_AVL_400G			400
>  
> -/* CUSTOM VALUES FOR SENSOR 1 */
> -#define ST_ACCEL_1_WAI_EXP			0x33
> -#define ST_ACCEL_1_ODR_ADDR			0x20
> -#define ST_ACCEL_1_ODR_MASK			0xf0
> -#define ST_ACCEL_1_ODR_AVL_1HZ_VAL		0x01
> -#define ST_ACCEL_1_ODR_AVL_10HZ_VAL		0x02
> -#define ST_ACCEL_1_ODR_AVL_25HZ_VAL		0x03
> -#define ST_ACCEL_1_ODR_AVL_50HZ_VAL		0x04
> -#define ST_ACCEL_1_ODR_AVL_100HZ_VAL		0x05
> -#define ST_ACCEL_1_ODR_AVL_200HZ_VAL		0x06
> -#define ST_ACCEL_1_ODR_AVL_400HZ_VAL		0x07
> -#define ST_ACCEL_1_ODR_AVL_1600HZ_VAL		0x08
> -#define ST_ACCEL_1_FS_ADDR			0x23
> -#define ST_ACCEL_1_FS_MASK			0x30
> -#define ST_ACCEL_1_FS_AVL_2_VAL			0x00
> -#define ST_ACCEL_1_FS_AVL_4_VAL			0x01
> -#define ST_ACCEL_1_FS_AVL_8_VAL			0x02
> -#define ST_ACCEL_1_FS_AVL_16_VAL		0x03
> -#define ST_ACCEL_1_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1000)
> -#define ST_ACCEL_1_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(2000)
> -#define ST_ACCEL_1_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(4000)
> -#define ST_ACCEL_1_FS_AVL_16_GAIN		IIO_G_TO_M_S_2(12000)
> -#define ST_ACCEL_1_BDU_ADDR			0x23
> -#define ST_ACCEL_1_BDU_MASK			0x80
> -#define ST_ACCEL_1_DRDY_IRQ_ADDR		0x22
> -#define ST_ACCEL_1_DRDY_IRQ_INT1_MASK		0x10
> -#define ST_ACCEL_1_DRDY_IRQ_INT2_MASK		0x08
> -#define ST_ACCEL_1_IHL_IRQ_ADDR			0x25
> -#define ST_ACCEL_1_IHL_IRQ_MASK			0x02
> -#define ST_ACCEL_1_MULTIREAD_BIT		true
> -
> -/* CUSTOM VALUES FOR SENSOR 2 */
> -#define ST_ACCEL_2_WAI_EXP			0x32
> -#define ST_ACCEL_2_ODR_ADDR			0x20
> -#define ST_ACCEL_2_ODR_MASK			0x18
> -#define ST_ACCEL_2_ODR_AVL_50HZ_VAL		0x00
> -#define ST_ACCEL_2_ODR_AVL_100HZ_VAL		0x01
> -#define ST_ACCEL_2_ODR_AVL_400HZ_VAL		0x02
> -#define ST_ACCEL_2_ODR_AVL_1000HZ_VAL		0x03
> -#define ST_ACCEL_2_PW_ADDR			0x20
> -#define ST_ACCEL_2_PW_MASK			0xe0
> -#define ST_ACCEL_2_FS_ADDR			0x23
> -#define ST_ACCEL_2_FS_MASK			0x30
> -#define ST_ACCEL_2_FS_AVL_2_VAL			0X00
> -#define ST_ACCEL_2_FS_AVL_4_VAL			0X01
> -#define ST_ACCEL_2_FS_AVL_8_VAL			0x03
> -#define ST_ACCEL_2_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1000)
> -#define ST_ACCEL_2_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(2000)
> -#define ST_ACCEL_2_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(3900)
> -#define ST_ACCEL_2_BDU_ADDR			0x23
> -#define ST_ACCEL_2_BDU_MASK			0x80
> -#define ST_ACCEL_2_DRDY_IRQ_ADDR		0x22
> -#define ST_ACCEL_2_DRDY_IRQ_INT1_MASK		0x02
> -#define ST_ACCEL_2_DRDY_IRQ_INT2_MASK		0x10
> -#define ST_ACCEL_2_IHL_IRQ_ADDR			0x22
> -#define ST_ACCEL_2_IHL_IRQ_MASK			0x80
> -#define ST_ACCEL_2_OD_IRQ_ADDR			0x22
> -#define ST_ACCEL_2_OD_IRQ_MASK			0x40
> -#define ST_ACCEL_2_MULTIREAD_BIT		true
> -
> -/* CUSTOM VALUES FOR SENSOR 3 */
> -#define ST_ACCEL_3_WAI_EXP			0x40
> -#define ST_ACCEL_3_ODR_ADDR			0x20
> -#define ST_ACCEL_3_ODR_MASK			0xf0
> -#define ST_ACCEL_3_ODR_AVL_3HZ_VAL		0x01
> -#define ST_ACCEL_3_ODR_AVL_6HZ_VAL		0x02
> -#define ST_ACCEL_3_ODR_AVL_12HZ_VAL		0x03
> -#define ST_ACCEL_3_ODR_AVL_25HZ_VAL		0x04
> -#define ST_ACCEL_3_ODR_AVL_50HZ_VAL		0x05
> -#define ST_ACCEL_3_ODR_AVL_100HZ_VAL		0x06
> -#define ST_ACCEL_3_ODR_AVL_200HZ_VAL		0x07
> -#define ST_ACCEL_3_ODR_AVL_400HZ_VAL		0x08
> -#define ST_ACCEL_3_ODR_AVL_800HZ_VAL		0x09
> -#define ST_ACCEL_3_ODR_AVL_1600HZ_VAL		0x0a
> -#define ST_ACCEL_3_FS_ADDR			0x24
> -#define ST_ACCEL_3_FS_MASK			0x38
> -#define ST_ACCEL_3_FS_AVL_2_VAL			0X00
> -#define ST_ACCEL_3_FS_AVL_4_VAL			0X01
> -#define ST_ACCEL_3_FS_AVL_6_VAL			0x02
> -#define ST_ACCEL_3_FS_AVL_8_VAL			0x03
> -#define ST_ACCEL_3_FS_AVL_16_VAL		0x04
> -#define ST_ACCEL_3_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(61)
> -#define ST_ACCEL_3_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(122)
> -#define ST_ACCEL_3_FS_AVL_6_GAIN		IIO_G_TO_M_S_2(183)
> -#define ST_ACCEL_3_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(244)
> -#define ST_ACCEL_3_FS_AVL_16_GAIN		IIO_G_TO_M_S_2(732)
> -#define ST_ACCEL_3_BDU_ADDR			0x20
> -#define ST_ACCEL_3_BDU_MASK			0x08
> -#define ST_ACCEL_3_DRDY_IRQ_ADDR		0x23
> -#define ST_ACCEL_3_DRDY_IRQ_INT1_MASK		0x80
> -#define ST_ACCEL_3_DRDY_IRQ_INT2_MASK		0x00
> -#define ST_ACCEL_3_IHL_IRQ_ADDR			0x23
> -#define ST_ACCEL_3_IHL_IRQ_MASK			0x40
> -#define ST_ACCEL_3_IG1_EN_ADDR			0x23
> -#define ST_ACCEL_3_IG1_EN_MASK			0x08
> -#define ST_ACCEL_3_MULTIREAD_BIT		false
> -
> -/* CUSTOM VALUES FOR SENSOR 4 */
> -#define ST_ACCEL_4_WAI_EXP			0x3a
> -#define ST_ACCEL_4_ODR_ADDR			0x20
> -#define ST_ACCEL_4_ODR_MASK			0x30 /* DF1 and DF0 */
> -#define ST_ACCEL_4_ODR_AVL_40HZ_VAL		0x00
> -#define ST_ACCEL_4_ODR_AVL_160HZ_VAL		0x01
> -#define ST_ACCEL_4_ODR_AVL_640HZ_VAL		0x02
> -#define ST_ACCEL_4_ODR_AVL_2560HZ_VAL		0x03
> -#define ST_ACCEL_4_PW_ADDR			0x20
> -#define ST_ACCEL_4_PW_MASK			0xc0
> -#define ST_ACCEL_4_FS_ADDR			0x21
> -#define ST_ACCEL_4_FS_MASK			0x80
> -#define ST_ACCEL_4_FS_AVL_2_VAL			0X00
> -#define ST_ACCEL_4_FS_AVL_6_VAL			0X01
> -#define ST_ACCEL_4_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1024)
> -#define ST_ACCEL_4_FS_AVL_6_GAIN		IIO_G_TO_M_S_2(340)
> -#define ST_ACCEL_4_BDU_ADDR			0x21
> -#define ST_ACCEL_4_BDU_MASK			0x40
> -#define ST_ACCEL_4_DRDY_IRQ_ADDR		0x21
> -#define ST_ACCEL_4_DRDY_IRQ_INT1_MASK		0x04
> -#define ST_ACCEL_4_MULTIREAD_BIT		true
> -
> -/* CUSTOM VALUES FOR SENSOR 5 */
> -#define ST_ACCEL_5_WAI_EXP			0x3b
> -#define ST_ACCEL_5_ODR_ADDR			0x20
> -#define ST_ACCEL_5_ODR_MASK			0x80
> -#define ST_ACCEL_5_ODR_AVL_100HZ_VAL		0x00
> -#define ST_ACCEL_5_ODR_AVL_400HZ_VAL		0x01
> -#define ST_ACCEL_5_PW_ADDR			0x20
> -#define ST_ACCEL_5_PW_MASK			0x40
> -#define ST_ACCEL_5_FS_ADDR			0x20
> -#define ST_ACCEL_5_FS_MASK			0x20
> -#define ST_ACCEL_5_FS_AVL_2_VAL			0X00
> -#define ST_ACCEL_5_FS_AVL_8_VAL			0X01
> -/* TODO: check these resulting gain settings, these are not in the datsheet */
> -#define ST_ACCEL_5_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(18000)
> -#define ST_ACCEL_5_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(72000)
> -#define ST_ACCEL_5_DRDY_IRQ_ADDR		0x22
> -#define ST_ACCEL_5_DRDY_IRQ_INT1_MASK		0x04
> -#define ST_ACCEL_5_DRDY_IRQ_INT2_MASK		0x20
> -#define ST_ACCEL_5_IHL_IRQ_ADDR			0x22
> -#define ST_ACCEL_5_IHL_IRQ_MASK			0x80
> -#define ST_ACCEL_5_OD_IRQ_ADDR			0x22
> -#define ST_ACCEL_5_OD_IRQ_MASK			0x40
> -#define ST_ACCEL_5_IG1_EN_ADDR			0x21
> -#define ST_ACCEL_5_IG1_EN_MASK			0x08
> -#define ST_ACCEL_5_MULTIREAD_BIT		false
> -
> -/* CUSTOM VALUES FOR SENSOR 6 */
> -#define ST_ACCEL_6_WAI_EXP			0x32
> -#define ST_ACCEL_6_ODR_ADDR			0x20
> -#define ST_ACCEL_6_ODR_MASK			0x18
> -#define ST_ACCEL_6_ODR_AVL_50HZ_VAL		0x00
> -#define ST_ACCEL_6_ODR_AVL_100HZ_VAL		0x01
> -#define ST_ACCEL_6_ODR_AVL_400HZ_VAL		0x02
> -#define ST_ACCEL_6_ODR_AVL_1000HZ_VAL		0x03
> -#define ST_ACCEL_6_PW_ADDR			0x20
> -#define ST_ACCEL_6_PW_MASK			0x20
> -#define ST_ACCEL_6_FS_ADDR			0x23
> -#define ST_ACCEL_6_FS_MASK			0x30
> -#define ST_ACCEL_6_FS_AVL_100_VAL		0x00
> -#define ST_ACCEL_6_FS_AVL_200_VAL		0x01
> -#define ST_ACCEL_6_FS_AVL_400_VAL		0x03
> -#define ST_ACCEL_6_FS_AVL_100_GAIN		IIO_G_TO_M_S_2(49000)
> -#define ST_ACCEL_6_FS_AVL_200_GAIN		IIO_G_TO_M_S_2(98000)
> -#define ST_ACCEL_6_FS_AVL_400_GAIN		IIO_G_TO_M_S_2(195000)
> -#define ST_ACCEL_6_BDU_ADDR			0x23
> -#define ST_ACCEL_6_BDU_MASK			0x80
> -#define ST_ACCEL_6_DRDY_IRQ_ADDR		0x22
> -#define ST_ACCEL_6_DRDY_IRQ_INT1_MASK		0x02
> -#define ST_ACCEL_6_DRDY_IRQ_INT2_MASK		0x10
> -#define ST_ACCEL_6_IHL_IRQ_ADDR			0x22
> -#define ST_ACCEL_6_IHL_IRQ_MASK			0x80
> -#define ST_ACCEL_6_MULTIREAD_BIT		true
> -
> -/* CUSTOM VALUES FOR SENSOR 7 */
> -#define ST_ACCEL_7_ODR_ADDR			0x20
> -#define ST_ACCEL_7_ODR_MASK			0x30
> -#define ST_ACCEL_7_ODR_AVL_280HZ_VAL		0x00
> -#define ST_ACCEL_7_ODR_AVL_560HZ_VAL		0x01
> -#define ST_ACCEL_7_ODR_AVL_1120HZ_VAL		0x02
> -#define ST_ACCEL_7_ODR_AVL_4480HZ_VAL		0x03
> -#define ST_ACCEL_7_PW_ADDR			0x20
> -#define ST_ACCEL_7_PW_MASK			0xc0
> -#define ST_ACCEL_7_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(488)
> -#define ST_ACCEL_7_BDU_ADDR			0x21
> -#define ST_ACCEL_7_BDU_MASK			0x40
> -#define ST_ACCEL_7_DRDY_IRQ_ADDR		0x21
> -#define ST_ACCEL_7_DRDY_IRQ_INT1_MASK		0x04
> -#define ST_ACCEL_7_MULTIREAD_BIT		false
> -
>  static const struct iio_chan_spec st_accel_8bit_channels[] = {
>  	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
>  			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> @@ -281,7 +93,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 = 0x33,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS3DH_ACCEL_DEV_NAME,
> @@ -294,22 +106,22 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  		},
>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>  		.odr = {
> -			.addr = ST_ACCEL_1_ODR_ADDR,
> -			.mask = ST_ACCEL_1_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0xf0,
>  			.odr_avl = {
> -				{ 1, ST_ACCEL_1_ODR_AVL_1HZ_VAL, },
> -				{ 10, ST_ACCEL_1_ODR_AVL_10HZ_VAL, },
> -				{ 25, ST_ACCEL_1_ODR_AVL_25HZ_VAL, },
> -				{ 50, ST_ACCEL_1_ODR_AVL_50HZ_VAL, },
> -				{ 100, ST_ACCEL_1_ODR_AVL_100HZ_VAL, },
> -				{ 200, ST_ACCEL_1_ODR_AVL_200HZ_VAL, },
> -				{ 400, ST_ACCEL_1_ODR_AVL_400HZ_VAL, },
> -				{ 1600, ST_ACCEL_1_ODR_AVL_1600HZ_VAL, },
> +				{ .hz = 1, .value = 0x01, },
> +				{ .hz = 10, .value = 0x02, },
> +				{ .hz = 25, .value = 0x03, },
> +				{ .hz = 50, .value = 0x04, },
> +				{ .hz = 100, .value = 0x05, },
> +				{ .hz = 200, .value = 0x06, },
> +				{ .hz = 400, .value = 0x07, },
> +				{ .hz = 1600, .value = 0x08, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_ACCEL_1_ODR_ADDR,
> -			.mask = ST_ACCEL_1_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0xf0,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
>  		.enable_axis = {
> @@ -317,48 +129,48 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_ACCEL_1_FS_ADDR,
> -			.mask = ST_ACCEL_1_FS_MASK,
> +			.addr = 0x23,
> +			.mask = 0x30,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_ACCEL_FS_AVL_2G,
> -					.value = ST_ACCEL_1_FS_AVL_2_VAL,
> -					.gain = ST_ACCEL_1_FS_AVL_2_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_G_TO_M_S_2(1000),
>  				},
>  				[1] = {
>  					.num = ST_ACCEL_FS_AVL_4G,
> -					.value = ST_ACCEL_1_FS_AVL_4_VAL,
> -					.gain = ST_ACCEL_1_FS_AVL_4_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_G_TO_M_S_2(2000),
>  				},
>  				[2] = {
>  					.num = ST_ACCEL_FS_AVL_8G,
> -					.value = ST_ACCEL_1_FS_AVL_8_VAL,
> -					.gain = ST_ACCEL_1_FS_AVL_8_GAIN,
> +					.value = 0x02,
> +					.gain = IIO_G_TO_M_S_2(4000),
>  				},
>  				[3] = {
>  					.num = ST_ACCEL_FS_AVL_16G,
> -					.value = ST_ACCEL_1_FS_AVL_16_VAL,
> -					.gain = ST_ACCEL_1_FS_AVL_16_GAIN,
> +					.value = 0x03,
> +					.gain = IIO_G_TO_M_S_2(12000),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_ACCEL_1_BDU_ADDR,
> -			.mask = ST_ACCEL_1_BDU_MASK,
> +			.addr = 0x23,
> +			.mask = 0x80,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_ACCEL_1_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_ACCEL_1_IHL_IRQ_MASK,
> +			.addr = 0x22,
> +			.mask_int1 = 0x10,
> +			.mask_int2 = 0x08,
> +			.addr_ihl = 0x25,
> +			.mask_ihl = 0x02,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_ACCEL_2_WAI_EXP,
> +		.wai = 0x32,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS331DLH_ACCEL_DEV_NAME,
> @@ -368,18 +180,18 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  		},
>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>  		.odr = {
> -			.addr = ST_ACCEL_2_ODR_ADDR,
> -			.mask = ST_ACCEL_2_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x18,
>  			.odr_avl = {
> -				{ 50, ST_ACCEL_2_ODR_AVL_50HZ_VAL, },
> -				{ 100, ST_ACCEL_2_ODR_AVL_100HZ_VAL, },
> -				{ 400, ST_ACCEL_2_ODR_AVL_400HZ_VAL, },
> -				{ 1000, ST_ACCEL_2_ODR_AVL_1000HZ_VAL, },
> +				{ .hz = 50, .value = 0x00, },
> +				{ .hz = 100, .value = 0x01, },
> +				{ .hz = 400, .value = 0x02, },
> +				{ .hz = 1000, .value = 0x03, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_ACCEL_2_PW_ADDR,
> -			.mask = ST_ACCEL_2_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0xe0,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -388,69 +200,69 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_ACCEL_2_FS_ADDR,
> -			.mask = ST_ACCEL_2_FS_MASK,
> +			.addr = 0x23,
> +			.mask = 0x30,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_ACCEL_FS_AVL_2G,
> -					.value = ST_ACCEL_2_FS_AVL_2_VAL,
> -					.gain = ST_ACCEL_2_FS_AVL_2_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_G_TO_M_S_2(1000),
>  				},
>  				[1] = {
>  					.num = ST_ACCEL_FS_AVL_4G,
> -					.value = ST_ACCEL_2_FS_AVL_4_VAL,
> -					.gain = ST_ACCEL_2_FS_AVL_4_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_G_TO_M_S_2(2000),
>  				},
>  				[2] = {
>  					.num = ST_ACCEL_FS_AVL_8G,
> -					.value = ST_ACCEL_2_FS_AVL_8_VAL,
> -					.gain = ST_ACCEL_2_FS_AVL_8_GAIN,
> +					.value = 0x03,
> +					.gain = IIO_G_TO_M_S_2(3900),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_ACCEL_2_BDU_ADDR,
> -			.mask = ST_ACCEL_2_BDU_MASK,
> +			.addr = 0x23,
> +			.mask = 0x80,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_ACCEL_2_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_ACCEL_2_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_ACCEL_2_IHL_IRQ_MASK,
> -			.addr_od = ST_ACCEL_2_OD_IRQ_ADDR,
> -			.mask_od = ST_ACCEL_2_OD_IRQ_MASK,
> +			.addr = 0x22,
> +			.mask_int1 = 0x02,
> +			.mask_int2 = 0x10,
> +			.addr_ihl = 0x22,
> +			.mask_ihl = 0x80,
> +			.addr_od = 0x22,
> +			.mask_od = 0x40,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_ACCEL_3_WAI_EXP,
> +		.wai = 0x40,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LSM330_ACCEL_DEV_NAME,
>  		},
>  		.ch = (struct iio_chan_spec *)st_accel_16bit_channels,
>  		.odr = {
> -			.addr = ST_ACCEL_3_ODR_ADDR,
> -			.mask = ST_ACCEL_3_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0xf0,
>  			.odr_avl = {
> -				{ 3, ST_ACCEL_3_ODR_AVL_3HZ_VAL },
> -				{ 6, ST_ACCEL_3_ODR_AVL_6HZ_VAL, },
> -				{ 12, ST_ACCEL_3_ODR_AVL_12HZ_VAL, },
> -				{ 25, ST_ACCEL_3_ODR_AVL_25HZ_VAL, },
> -				{ 50, ST_ACCEL_3_ODR_AVL_50HZ_VAL, },
> -				{ 100, ST_ACCEL_3_ODR_AVL_100HZ_VAL, },
> -				{ 200, ST_ACCEL_3_ODR_AVL_200HZ_VAL, },
> -				{ 400, ST_ACCEL_3_ODR_AVL_400HZ_VAL, },
> -				{ 800, ST_ACCEL_3_ODR_AVL_800HZ_VAL, },
> -				{ 1600, ST_ACCEL_3_ODR_AVL_1600HZ_VAL, },
> +				{ .hz = 3, .value = 0x01, },
> +				{ .hz = 6, .value = 0x02, },
> +				{ .hz = 12, .value = 0x03, },
> +				{ .hz = 25, .value = 0x04, },
> +				{ .hz = 50, .value = 0x05, },
> +				{ .hz = 100, .value = 0x06, },
> +				{ .hz = 200, .value = 0x07, },
> +				{ .hz = 400, .value = 0x08, },
> +				{ .hz = 800, .value = 0x09, },
> +				{ .hz = 1600, .value = 0x0a, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_ACCEL_3_ODR_ADDR,
> -			.mask = ST_ACCEL_3_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0xf0,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
>  		.enable_axis = {
> @@ -458,75 +270,75 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_ACCEL_3_FS_ADDR,
> -			.mask = ST_ACCEL_3_FS_MASK,
> +			.addr = 0x24,
> +			.mask = 0x38,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_ACCEL_FS_AVL_2G,
> -					.value = ST_ACCEL_3_FS_AVL_2_VAL,
> -					.gain = ST_ACCEL_3_FS_AVL_2_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_G_TO_M_S_2(61),
>  				},
>  				[1] = {
>  					.num = ST_ACCEL_FS_AVL_4G,
> -					.value = ST_ACCEL_3_FS_AVL_4_VAL,
> -					.gain = ST_ACCEL_3_FS_AVL_4_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_G_TO_M_S_2(122),
>  				},
>  				[2] = {
>  					.num = ST_ACCEL_FS_AVL_6G,
> -					.value = ST_ACCEL_3_FS_AVL_6_VAL,
> -					.gain = ST_ACCEL_3_FS_AVL_6_GAIN,
> +					.value = 0x02,
> +					.gain = IIO_G_TO_M_S_2(183),
>  				},
>  				[3] = {
>  					.num = ST_ACCEL_FS_AVL_8G,
> -					.value = ST_ACCEL_3_FS_AVL_8_VAL,
> -					.gain = ST_ACCEL_3_FS_AVL_8_GAIN,
> +					.value = 0x03,
> +					.gain = IIO_G_TO_M_S_2(244),
>  				},
>  				[4] = {
>  					.num = ST_ACCEL_FS_AVL_16G,
> -					.value = ST_ACCEL_3_FS_AVL_16_VAL,
> -					.gain = ST_ACCEL_3_FS_AVL_16_GAIN,
> +					.value = 0x04,
> +					.gain = IIO_G_TO_M_S_2(732),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_ACCEL_3_BDU_ADDR,
> -			.mask = ST_ACCEL_3_BDU_MASK,
> +			.addr = 0x20,
> +			.mask = 0x08,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_ACCEL_3_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_ACCEL_3_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_ACCEL_3_IHL_IRQ_MASK,
> +			.addr = 0x23,
> +			.mask_int1 = 0x80,
> +			.mask_int2 = 0x00,
> +			.addr_ihl = 0x23,
> +			.mask_ihl = 0x40,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  			.ig1 = {
> -				.en_addr = ST_ACCEL_3_IG1_EN_ADDR,
> -				.en_mask = ST_ACCEL_3_IG1_EN_MASK,
> +				.en_addr = 0x23,
> +				.en_mask = 0x08,
>  			},
>  		},
> -		.multi_read_bit = ST_ACCEL_3_MULTIREAD_BIT,
> +		.multi_read_bit = false,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_ACCEL_4_WAI_EXP,
> +		.wai = 0x3a,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS3LV02DL_ACCEL_DEV_NAME,
>  		},
>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>  		.odr = {
> -			.addr = ST_ACCEL_4_ODR_ADDR,
> -			.mask = ST_ACCEL_4_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x30, /* DF1 and DF0 */
>  			.odr_avl = {
> -				{ 40, ST_ACCEL_4_ODR_AVL_40HZ_VAL },
> -				{ 160, ST_ACCEL_4_ODR_AVL_160HZ_VAL, },
> -				{ 640, ST_ACCEL_4_ODR_AVL_640HZ_VAL, },
> -				{ 2560, ST_ACCEL_4_ODR_AVL_2560HZ_VAL, },
> +				{ .hz = 40, .value = 0x00, },
> +				{ .hz = 160, .value = 0x01, },
> +				{ .hz = 640, .value = 0x02, },
> +				{ .hz = 2560, .value = 0x03, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_ACCEL_4_PW_ADDR,
> -			.mask = ST_ACCEL_4_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0xc0,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -535,51 +347,51 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_ACCEL_4_FS_ADDR,
> -			.mask = ST_ACCEL_4_FS_MASK,
> +			.addr = 0x21,
> +			.mask = 0x80,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_ACCEL_FS_AVL_2G,
> -					.value = ST_ACCEL_4_FS_AVL_2_VAL,
> -					.gain = ST_ACCEL_4_FS_AVL_2_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_G_TO_M_S_2(1024),
>  				},
>  				[1] = {
>  					.num = ST_ACCEL_FS_AVL_6G,
> -					.value = ST_ACCEL_4_FS_AVL_6_VAL,
> -					.gain = ST_ACCEL_4_FS_AVL_6_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_G_TO_M_S_2(340),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_ACCEL_4_BDU_ADDR,
> -			.mask = ST_ACCEL_4_BDU_MASK,
> +			.addr = 0x21,
> +			.mask = 0x40,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_ACCEL_4_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_ACCEL_4_DRDY_IRQ_INT1_MASK,
> +			.addr = 0x21,
> +			.mask_int1 = 0x04,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_ACCEL_4_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2, /* guess */
>  	},
>  	{
> -		.wai = ST_ACCEL_5_WAI_EXP,
> +		.wai = 0x3b,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS331DL_ACCEL_DEV_NAME,
>  		},
>  		.ch = (struct iio_chan_spec *)st_accel_8bit_channels,
>  		.odr = {
> -			.addr = ST_ACCEL_5_ODR_ADDR,
> -			.mask = ST_ACCEL_5_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x80,
>  			.odr_avl = {
> -				{ 100, ST_ACCEL_5_ODR_AVL_100HZ_VAL },
> -				{ 400, ST_ACCEL_5_ODR_AVL_400HZ_VAL, },
> +				{ .hz = 100, .value = 0x00, },
> +				{ .hz = 400, .value = 0x01, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_ACCEL_5_PW_ADDR,
> -			.mask = ST_ACCEL_5_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x40,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -588,54 +400,58 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_ACCEL_5_FS_ADDR,
> -			.mask = ST_ACCEL_5_FS_MASK,
> +			.addr = 0x20,
> +			.mask = 0x20,
> +			/*
> +			 * TODO: check these resulting gain settings, these are
> +			 * not in the datsheet
> +			 */
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_ACCEL_FS_AVL_2G,
> -					.value = ST_ACCEL_5_FS_AVL_2_VAL,
> -					.gain = ST_ACCEL_5_FS_AVL_2_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_G_TO_M_S_2(18000),
>  				},
>  				[1] = {
>  					.num = ST_ACCEL_FS_AVL_8G,
> -					.value = ST_ACCEL_5_FS_AVL_8_VAL,
> -					.gain = ST_ACCEL_5_FS_AVL_8_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_G_TO_M_S_2(72000),
>  				},
>  			},
>  		},
>  		.drdy_irq = {
> -			.addr = ST_ACCEL_5_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_ACCEL_5_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_ACCEL_5_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_ACCEL_5_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_ACCEL_5_IHL_IRQ_MASK,
> -			.addr_od = ST_ACCEL_5_OD_IRQ_ADDR,
> -			.mask_od = ST_ACCEL_5_OD_IRQ_MASK,
> +			.addr = 0x22,
> +			.mask_int1 = 0x04,
> +			.mask_int2 = 0x20,
> +			.addr_ihl = 0x22,
> +			.mask_ihl = 0x80,
> +			.addr_od = 0x22,
> +			.mask_od = 0x40,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT,
> +		.multi_read_bit = false,
>  		.bootime = 2, /* guess */
>  	},
>  	{
> -		.wai = ST_ACCEL_6_WAI_EXP,
> +		.wai = 0x32,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = H3LIS331DL_DRIVER_NAME,
>  		},
>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>  		.odr = {
> -			.addr = ST_ACCEL_6_ODR_ADDR,
> -			.mask = ST_ACCEL_6_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x18,
>  			.odr_avl = {
> -				{ 50, ST_ACCEL_6_ODR_AVL_50HZ_VAL },
> -				{ 100, ST_ACCEL_6_ODR_AVL_100HZ_VAL, },
> -				{ 400, ST_ACCEL_6_ODR_AVL_400HZ_VAL, },
> -				{ 1000, ST_ACCEL_6_ODR_AVL_1000HZ_VAL, },
> +				{ .hz = 50, .value = 0x00, },
> +				{ .hz = 100, .value = 0x01, },
> +				{ .hz = 400, .value = 0x02, },
> +				{ .hz = 1000, .value = 0x03, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_ACCEL_6_PW_ADDR,
> -			.mask = ST_ACCEL_6_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x20,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -644,38 +460,38 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_ACCEL_6_FS_ADDR,
> -			.mask = ST_ACCEL_6_FS_MASK,
> +			.addr = 0x23,
> +			.mask = 0x30,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_ACCEL_FS_AVL_100G,
> -					.value = ST_ACCEL_6_FS_AVL_100_VAL,
> -					.gain = ST_ACCEL_6_FS_AVL_100_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_G_TO_M_S_2(49000),
>  				},
>  				[1] = {
>  					.num = ST_ACCEL_FS_AVL_200G,
> -					.value = ST_ACCEL_6_FS_AVL_200_VAL,
> -					.gain = ST_ACCEL_6_FS_AVL_200_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_G_TO_M_S_2(98000),
>  				},
>  				[2] = {
>  					.num = ST_ACCEL_FS_AVL_400G,
> -					.value = ST_ACCEL_6_FS_AVL_400_VAL,
> -					.gain = ST_ACCEL_6_FS_AVL_400_GAIN,
> +					.value = 0x03,
> +					.gain = IIO_G_TO_M_S_2(195000),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_ACCEL_6_BDU_ADDR,
> -			.mask = ST_ACCEL_6_BDU_MASK,
> +			.addr = 0x23,
> +			.mask = 0x80,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_ACCEL_6_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_ACCEL_6_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_ACCEL_6_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_ACCEL_6_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_ACCEL_6_IHL_IRQ_MASK,
> +			.addr = 0x22,
> +			.mask_int1 = 0x02,
> +			.mask_int2 = 0x10,
> +			.addr_ihl = 0x22,
> +			.mask_ihl = 0x80,
>  		},
> -		.multi_read_bit = ST_ACCEL_6_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> @@ -685,18 +501,18 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  		},
>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>  		.odr = {
> -			.addr = ST_ACCEL_7_ODR_ADDR,
> -			.mask = ST_ACCEL_7_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x30,
>  			.odr_avl = {
> -				{ 280, ST_ACCEL_7_ODR_AVL_280HZ_VAL, },
> -				{ 560, ST_ACCEL_7_ODR_AVL_560HZ_VAL, },
> -				{ 1120, ST_ACCEL_7_ODR_AVL_1120HZ_VAL, },
> -				{ 4480, ST_ACCEL_7_ODR_AVL_4480HZ_VAL, },
> +				{ .hz = 280, .value = 0x00, },
> +				{ .hz = 560, .value = 0x01, },
> +				{ .hz = 1120, .value = 0x02, },
> +				{ .hz = 4480, .value = 0x03, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_ACCEL_7_PW_ADDR,
> -			.mask = ST_ACCEL_7_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0xc0,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -708,7 +524,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_ACCEL_FS_AVL_2G,
> -					.gain = ST_ACCEL_7_FS_AVL_2_GAIN,
> +					.gain = IIO_G_TO_M_S_2(488),
>  				},
>  			},
>  		},
> @@ -719,11 +535,11 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>  		.bdu = {
>  		},
>  		.drdy_irq = {
> -			.addr = ST_ACCEL_7_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_ACCEL_7_DRDY_IRQ_INT1_MASK,
> +			.addr = 0x21,
> +			.mask_int1 = 0x04,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_ACCEL_7_MULTIREAD_BIT,
> +		.multi_read_bit = false,
>  		.bootime = 2,
>  	},
>  };
> 


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

* Re: [PATCH 1/4] iio: accel: st_accel: inline per-sensor data
  2016-11-12 15:29   ` Jonathan Cameron
@ 2016-11-12 15:34     ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2016-11-12 15:34 UTC (permalink / raw)
  To: Linus Walleij, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard

On 12/11/16 15:29, Jonathan Cameron wrote:
> On 09/11/16 15:09, Linus Walleij wrote:
>> We have #defines for all the individual sensor registers and
>> value/mask pairs #defined at the top of the file and used at
>> exactly one spot.
>>
>> This is usually good if the #defines give a meaning to the
>> opaque magic numbers.
>>
>> However in this case, the semantic meaning is inherent in the
>> name of the C99-addressable fields, and that means duplication
>> of information, and only makes the code hard to maintain since
>> you every time have to add a new #define AND update the site
>> where it is to be used.
>>
>> Get rid of the #defines and just open code the values into the
>> appropriate struct elements. Make sure to explicitly address
>> the .hz and .value fields in the st_sensor_odr_avl struct
>> so that the meaning of all values is clear.
>>
>> This patch is purely syntactic should have no semantic effect.
>>
>> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> Interesting that sensor type 5 has IG1 address / mask defined (previously) but
> not used... hohum. I have no idea what those even are ;)
> 
> My only conselation in having just checked this is it must have
> been even more boring to write as a patch!
> 
> Applied to the togreg branch of iio.git and pushed out as testing for
> the autobuilders to play with it.
Spoke too soon.  Doesn't apply because we have had a new driver
added just recently.  Can you update against my togreg branch
and resend?

Thanks,

Jonathan
> 
> Thanks,
> 
> Jonathan
>> ---
>>  drivers/iio/accel/st_accel_core.c | 538 +++++++++++++-------------------------
>>  1 file changed, 177 insertions(+), 361 deletions(-)
>>
>> diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
>> index da3fb069ec5c..d21b2dbe7432 100644
>> --- a/drivers/iio/accel/st_accel_core.c
>> +++ b/drivers/iio/accel/st_accel_core.c
>> @@ -43,194 +43,6 @@
>>  #define ST_ACCEL_FS_AVL_200G			200
>>  #define ST_ACCEL_FS_AVL_400G			400
>>  
>> -/* CUSTOM VALUES FOR SENSOR 1 */
>> -#define ST_ACCEL_1_WAI_EXP			0x33
>> -#define ST_ACCEL_1_ODR_ADDR			0x20
>> -#define ST_ACCEL_1_ODR_MASK			0xf0
>> -#define ST_ACCEL_1_ODR_AVL_1HZ_VAL		0x01
>> -#define ST_ACCEL_1_ODR_AVL_10HZ_VAL		0x02
>> -#define ST_ACCEL_1_ODR_AVL_25HZ_VAL		0x03
>> -#define ST_ACCEL_1_ODR_AVL_50HZ_VAL		0x04
>> -#define ST_ACCEL_1_ODR_AVL_100HZ_VAL		0x05
>> -#define ST_ACCEL_1_ODR_AVL_200HZ_VAL		0x06
>> -#define ST_ACCEL_1_ODR_AVL_400HZ_VAL		0x07
>> -#define ST_ACCEL_1_ODR_AVL_1600HZ_VAL		0x08
>> -#define ST_ACCEL_1_FS_ADDR			0x23
>> -#define ST_ACCEL_1_FS_MASK			0x30
>> -#define ST_ACCEL_1_FS_AVL_2_VAL			0x00
>> -#define ST_ACCEL_1_FS_AVL_4_VAL			0x01
>> -#define ST_ACCEL_1_FS_AVL_8_VAL			0x02
>> -#define ST_ACCEL_1_FS_AVL_16_VAL		0x03
>> -#define ST_ACCEL_1_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1000)
>> -#define ST_ACCEL_1_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(2000)
>> -#define ST_ACCEL_1_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(4000)
>> -#define ST_ACCEL_1_FS_AVL_16_GAIN		IIO_G_TO_M_S_2(12000)
>> -#define ST_ACCEL_1_BDU_ADDR			0x23
>> -#define ST_ACCEL_1_BDU_MASK			0x80
>> -#define ST_ACCEL_1_DRDY_IRQ_ADDR		0x22
>> -#define ST_ACCEL_1_DRDY_IRQ_INT1_MASK		0x10
>> -#define ST_ACCEL_1_DRDY_IRQ_INT2_MASK		0x08
>> -#define ST_ACCEL_1_IHL_IRQ_ADDR			0x25
>> -#define ST_ACCEL_1_IHL_IRQ_MASK			0x02
>> -#define ST_ACCEL_1_MULTIREAD_BIT		true
>> -
>> -/* CUSTOM VALUES FOR SENSOR 2 */
>> -#define ST_ACCEL_2_WAI_EXP			0x32
>> -#define ST_ACCEL_2_ODR_ADDR			0x20
>> -#define ST_ACCEL_2_ODR_MASK			0x18
>> -#define ST_ACCEL_2_ODR_AVL_50HZ_VAL		0x00
>> -#define ST_ACCEL_2_ODR_AVL_100HZ_VAL		0x01
>> -#define ST_ACCEL_2_ODR_AVL_400HZ_VAL		0x02
>> -#define ST_ACCEL_2_ODR_AVL_1000HZ_VAL		0x03
>> -#define ST_ACCEL_2_PW_ADDR			0x20
>> -#define ST_ACCEL_2_PW_MASK			0xe0
>> -#define ST_ACCEL_2_FS_ADDR			0x23
>> -#define ST_ACCEL_2_FS_MASK			0x30
>> -#define ST_ACCEL_2_FS_AVL_2_VAL			0X00
>> -#define ST_ACCEL_2_FS_AVL_4_VAL			0X01
>> -#define ST_ACCEL_2_FS_AVL_8_VAL			0x03
>> -#define ST_ACCEL_2_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1000)
>> -#define ST_ACCEL_2_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(2000)
>> -#define ST_ACCEL_2_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(3900)
>> -#define ST_ACCEL_2_BDU_ADDR			0x23
>> -#define ST_ACCEL_2_BDU_MASK			0x80
>> -#define ST_ACCEL_2_DRDY_IRQ_ADDR		0x22
>> -#define ST_ACCEL_2_DRDY_IRQ_INT1_MASK		0x02
>> -#define ST_ACCEL_2_DRDY_IRQ_INT2_MASK		0x10
>> -#define ST_ACCEL_2_IHL_IRQ_ADDR			0x22
>> -#define ST_ACCEL_2_IHL_IRQ_MASK			0x80
>> -#define ST_ACCEL_2_OD_IRQ_ADDR			0x22
>> -#define ST_ACCEL_2_OD_IRQ_MASK			0x40
>> -#define ST_ACCEL_2_MULTIREAD_BIT		true
>> -
>> -/* CUSTOM VALUES FOR SENSOR 3 */
>> -#define ST_ACCEL_3_WAI_EXP			0x40
>> -#define ST_ACCEL_3_ODR_ADDR			0x20
>> -#define ST_ACCEL_3_ODR_MASK			0xf0
>> -#define ST_ACCEL_3_ODR_AVL_3HZ_VAL		0x01
>> -#define ST_ACCEL_3_ODR_AVL_6HZ_VAL		0x02
>> -#define ST_ACCEL_3_ODR_AVL_12HZ_VAL		0x03
>> -#define ST_ACCEL_3_ODR_AVL_25HZ_VAL		0x04
>> -#define ST_ACCEL_3_ODR_AVL_50HZ_VAL		0x05
>> -#define ST_ACCEL_3_ODR_AVL_100HZ_VAL		0x06
>> -#define ST_ACCEL_3_ODR_AVL_200HZ_VAL		0x07
>> -#define ST_ACCEL_3_ODR_AVL_400HZ_VAL		0x08
>> -#define ST_ACCEL_3_ODR_AVL_800HZ_VAL		0x09
>> -#define ST_ACCEL_3_ODR_AVL_1600HZ_VAL		0x0a
>> -#define ST_ACCEL_3_FS_ADDR			0x24
>> -#define ST_ACCEL_3_FS_MASK			0x38
>> -#define ST_ACCEL_3_FS_AVL_2_VAL			0X00
>> -#define ST_ACCEL_3_FS_AVL_4_VAL			0X01
>> -#define ST_ACCEL_3_FS_AVL_6_VAL			0x02
>> -#define ST_ACCEL_3_FS_AVL_8_VAL			0x03
>> -#define ST_ACCEL_3_FS_AVL_16_VAL		0x04
>> -#define ST_ACCEL_3_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(61)
>> -#define ST_ACCEL_3_FS_AVL_4_GAIN		IIO_G_TO_M_S_2(122)
>> -#define ST_ACCEL_3_FS_AVL_6_GAIN		IIO_G_TO_M_S_2(183)
>> -#define ST_ACCEL_3_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(244)
>> -#define ST_ACCEL_3_FS_AVL_16_GAIN		IIO_G_TO_M_S_2(732)
>> -#define ST_ACCEL_3_BDU_ADDR			0x20
>> -#define ST_ACCEL_3_BDU_MASK			0x08
>> -#define ST_ACCEL_3_DRDY_IRQ_ADDR		0x23
>> -#define ST_ACCEL_3_DRDY_IRQ_INT1_MASK		0x80
>> -#define ST_ACCEL_3_DRDY_IRQ_INT2_MASK		0x00
>> -#define ST_ACCEL_3_IHL_IRQ_ADDR			0x23
>> -#define ST_ACCEL_3_IHL_IRQ_MASK			0x40
>> -#define ST_ACCEL_3_IG1_EN_ADDR			0x23
>> -#define ST_ACCEL_3_IG1_EN_MASK			0x08
>> -#define ST_ACCEL_3_MULTIREAD_BIT		false
>> -
>> -/* CUSTOM VALUES FOR SENSOR 4 */
>> -#define ST_ACCEL_4_WAI_EXP			0x3a
>> -#define ST_ACCEL_4_ODR_ADDR			0x20
>> -#define ST_ACCEL_4_ODR_MASK			0x30 /* DF1 and DF0 */
>> -#define ST_ACCEL_4_ODR_AVL_40HZ_VAL		0x00
>> -#define ST_ACCEL_4_ODR_AVL_160HZ_VAL		0x01
>> -#define ST_ACCEL_4_ODR_AVL_640HZ_VAL		0x02
>> -#define ST_ACCEL_4_ODR_AVL_2560HZ_VAL		0x03
>> -#define ST_ACCEL_4_PW_ADDR			0x20
>> -#define ST_ACCEL_4_PW_MASK			0xc0
>> -#define ST_ACCEL_4_FS_ADDR			0x21
>> -#define ST_ACCEL_4_FS_MASK			0x80
>> -#define ST_ACCEL_4_FS_AVL_2_VAL			0X00
>> -#define ST_ACCEL_4_FS_AVL_6_VAL			0X01
>> -#define ST_ACCEL_4_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(1024)
>> -#define ST_ACCEL_4_FS_AVL_6_GAIN		IIO_G_TO_M_S_2(340)
>> -#define ST_ACCEL_4_BDU_ADDR			0x21
>> -#define ST_ACCEL_4_BDU_MASK			0x40
>> -#define ST_ACCEL_4_DRDY_IRQ_ADDR		0x21
>> -#define ST_ACCEL_4_DRDY_IRQ_INT1_MASK		0x04
>> -#define ST_ACCEL_4_MULTIREAD_BIT		true
>> -
>> -/* CUSTOM VALUES FOR SENSOR 5 */
>> -#define ST_ACCEL_5_WAI_EXP			0x3b
>> -#define ST_ACCEL_5_ODR_ADDR			0x20
>> -#define ST_ACCEL_5_ODR_MASK			0x80
>> -#define ST_ACCEL_5_ODR_AVL_100HZ_VAL		0x00
>> -#define ST_ACCEL_5_ODR_AVL_400HZ_VAL		0x01
>> -#define ST_ACCEL_5_PW_ADDR			0x20
>> -#define ST_ACCEL_5_PW_MASK			0x40
>> -#define ST_ACCEL_5_FS_ADDR			0x20
>> -#define ST_ACCEL_5_FS_MASK			0x20
>> -#define ST_ACCEL_5_FS_AVL_2_VAL			0X00
>> -#define ST_ACCEL_5_FS_AVL_8_VAL			0X01
>> -/* TODO: check these resulting gain settings, these are not in the datsheet */
>> -#define ST_ACCEL_5_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(18000)
>> -#define ST_ACCEL_5_FS_AVL_8_GAIN		IIO_G_TO_M_S_2(72000)
>> -#define ST_ACCEL_5_DRDY_IRQ_ADDR		0x22
>> -#define ST_ACCEL_5_DRDY_IRQ_INT1_MASK		0x04
>> -#define ST_ACCEL_5_DRDY_IRQ_INT2_MASK		0x20
>> -#define ST_ACCEL_5_IHL_IRQ_ADDR			0x22
>> -#define ST_ACCEL_5_IHL_IRQ_MASK			0x80
>> -#define ST_ACCEL_5_OD_IRQ_ADDR			0x22
>> -#define ST_ACCEL_5_OD_IRQ_MASK			0x40
>> -#define ST_ACCEL_5_IG1_EN_ADDR			0x21
>> -#define ST_ACCEL_5_IG1_EN_MASK			0x08
>> -#define ST_ACCEL_5_MULTIREAD_BIT		false
>> -
>> -/* CUSTOM VALUES FOR SENSOR 6 */
>> -#define ST_ACCEL_6_WAI_EXP			0x32
>> -#define ST_ACCEL_6_ODR_ADDR			0x20
>> -#define ST_ACCEL_6_ODR_MASK			0x18
>> -#define ST_ACCEL_6_ODR_AVL_50HZ_VAL		0x00
>> -#define ST_ACCEL_6_ODR_AVL_100HZ_VAL		0x01
>> -#define ST_ACCEL_6_ODR_AVL_400HZ_VAL		0x02
>> -#define ST_ACCEL_6_ODR_AVL_1000HZ_VAL		0x03
>> -#define ST_ACCEL_6_PW_ADDR			0x20
>> -#define ST_ACCEL_6_PW_MASK			0x20
>> -#define ST_ACCEL_6_FS_ADDR			0x23
>> -#define ST_ACCEL_6_FS_MASK			0x30
>> -#define ST_ACCEL_6_FS_AVL_100_VAL		0x00
>> -#define ST_ACCEL_6_FS_AVL_200_VAL		0x01
>> -#define ST_ACCEL_6_FS_AVL_400_VAL		0x03
>> -#define ST_ACCEL_6_FS_AVL_100_GAIN		IIO_G_TO_M_S_2(49000)
>> -#define ST_ACCEL_6_FS_AVL_200_GAIN		IIO_G_TO_M_S_2(98000)
>> -#define ST_ACCEL_6_FS_AVL_400_GAIN		IIO_G_TO_M_S_2(195000)
>> -#define ST_ACCEL_6_BDU_ADDR			0x23
>> -#define ST_ACCEL_6_BDU_MASK			0x80
>> -#define ST_ACCEL_6_DRDY_IRQ_ADDR		0x22
>> -#define ST_ACCEL_6_DRDY_IRQ_INT1_MASK		0x02
>> -#define ST_ACCEL_6_DRDY_IRQ_INT2_MASK		0x10
>> -#define ST_ACCEL_6_IHL_IRQ_ADDR			0x22
>> -#define ST_ACCEL_6_IHL_IRQ_MASK			0x80
>> -#define ST_ACCEL_6_MULTIREAD_BIT		true
>> -
>> -/* CUSTOM VALUES FOR SENSOR 7 */
>> -#define ST_ACCEL_7_ODR_ADDR			0x20
>> -#define ST_ACCEL_7_ODR_MASK			0x30
>> -#define ST_ACCEL_7_ODR_AVL_280HZ_VAL		0x00
>> -#define ST_ACCEL_7_ODR_AVL_560HZ_VAL		0x01
>> -#define ST_ACCEL_7_ODR_AVL_1120HZ_VAL		0x02
>> -#define ST_ACCEL_7_ODR_AVL_4480HZ_VAL		0x03
>> -#define ST_ACCEL_7_PW_ADDR			0x20
>> -#define ST_ACCEL_7_PW_MASK			0xc0
>> -#define ST_ACCEL_7_FS_AVL_2_GAIN		IIO_G_TO_M_S_2(488)
>> -#define ST_ACCEL_7_BDU_ADDR			0x21
>> -#define ST_ACCEL_7_BDU_MASK			0x40
>> -#define ST_ACCEL_7_DRDY_IRQ_ADDR		0x21
>> -#define ST_ACCEL_7_DRDY_IRQ_INT1_MASK		0x04
>> -#define ST_ACCEL_7_MULTIREAD_BIT		false
>> -
>>  static const struct iio_chan_spec st_accel_8bit_channels[] = {
>>  	ST_SENSORS_LSM_CHANNELS(IIO_ACCEL,
>>  			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
>> @@ -281,7 +93,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 = 0x33,
>>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>  		.sensors_supported = {
>>  			[0] = LIS3DH_ACCEL_DEV_NAME,
>> @@ -294,22 +106,22 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  		},
>>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>>  		.odr = {
>> -			.addr = ST_ACCEL_1_ODR_ADDR,
>> -			.mask = ST_ACCEL_1_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0xf0,
>>  			.odr_avl = {
>> -				{ 1, ST_ACCEL_1_ODR_AVL_1HZ_VAL, },
>> -				{ 10, ST_ACCEL_1_ODR_AVL_10HZ_VAL, },
>> -				{ 25, ST_ACCEL_1_ODR_AVL_25HZ_VAL, },
>> -				{ 50, ST_ACCEL_1_ODR_AVL_50HZ_VAL, },
>> -				{ 100, ST_ACCEL_1_ODR_AVL_100HZ_VAL, },
>> -				{ 200, ST_ACCEL_1_ODR_AVL_200HZ_VAL, },
>> -				{ 400, ST_ACCEL_1_ODR_AVL_400HZ_VAL, },
>> -				{ 1600, ST_ACCEL_1_ODR_AVL_1600HZ_VAL, },
>> +				{ .hz = 1, .value = 0x01, },
>> +				{ .hz = 10, .value = 0x02, },
>> +				{ .hz = 25, .value = 0x03, },
>> +				{ .hz = 50, .value = 0x04, },
>> +				{ .hz = 100, .value = 0x05, },
>> +				{ .hz = 200, .value = 0x06, },
>> +				{ .hz = 400, .value = 0x07, },
>> +				{ .hz = 1600, .value = 0x08, },
>>  			},
>>  		},
>>  		.pw = {
>> -			.addr = ST_ACCEL_1_ODR_ADDR,
>> -			.mask = ST_ACCEL_1_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0xf0,
>>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>>  		},
>>  		.enable_axis = {
>> @@ -317,48 +129,48 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>>  		},
>>  		.fs = {
>> -			.addr = ST_ACCEL_1_FS_ADDR,
>> -			.mask = ST_ACCEL_1_FS_MASK,
>> +			.addr = 0x23,
>> +			.mask = 0x30,
>>  			.fs_avl = {
>>  				[0] = {
>>  					.num = ST_ACCEL_FS_AVL_2G,
>> -					.value = ST_ACCEL_1_FS_AVL_2_VAL,
>> -					.gain = ST_ACCEL_1_FS_AVL_2_GAIN,
>> +					.value = 0x00,
>> +					.gain = IIO_G_TO_M_S_2(1000),
>>  				},
>>  				[1] = {
>>  					.num = ST_ACCEL_FS_AVL_4G,
>> -					.value = ST_ACCEL_1_FS_AVL_4_VAL,
>> -					.gain = ST_ACCEL_1_FS_AVL_4_GAIN,
>> +					.value = 0x01,
>> +					.gain = IIO_G_TO_M_S_2(2000),
>>  				},
>>  				[2] = {
>>  					.num = ST_ACCEL_FS_AVL_8G,
>> -					.value = ST_ACCEL_1_FS_AVL_8_VAL,
>> -					.gain = ST_ACCEL_1_FS_AVL_8_GAIN,
>> +					.value = 0x02,
>> +					.gain = IIO_G_TO_M_S_2(4000),
>>  				},
>>  				[3] = {
>>  					.num = ST_ACCEL_FS_AVL_16G,
>> -					.value = ST_ACCEL_1_FS_AVL_16_VAL,
>> -					.gain = ST_ACCEL_1_FS_AVL_16_GAIN,
>> +					.value = 0x03,
>> +					.gain = IIO_G_TO_M_S_2(12000),
>>  				},
>>  			},
>>  		},
>>  		.bdu = {
>> -			.addr = ST_ACCEL_1_BDU_ADDR,
>> -			.mask = ST_ACCEL_1_BDU_MASK,
>> +			.addr = 0x23,
>> +			.mask = 0x80,
>>  		},
>>  		.drdy_irq = {
>> -			.addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
>> -			.mask_int1 = ST_ACCEL_1_DRDY_IRQ_INT1_MASK,
>> -			.mask_int2 = ST_ACCEL_1_DRDY_IRQ_INT2_MASK,
>> -			.addr_ihl = ST_ACCEL_1_IHL_IRQ_ADDR,
>> -			.mask_ihl = ST_ACCEL_1_IHL_IRQ_MASK,
>> +			.addr = 0x22,
>> +			.mask_int1 = 0x10,
>> +			.mask_int2 = 0x08,
>> +			.addr_ihl = 0x25,
>> +			.mask_ihl = 0x02,
>>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>>  		},
>> -		.multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,
>> +		.multi_read_bit = true,
>>  		.bootime = 2,
>>  	},
>>  	{
>> -		.wai = ST_ACCEL_2_WAI_EXP,
>> +		.wai = 0x32,
>>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>  		.sensors_supported = {
>>  			[0] = LIS331DLH_ACCEL_DEV_NAME,
>> @@ -368,18 +180,18 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  		},
>>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>>  		.odr = {
>> -			.addr = ST_ACCEL_2_ODR_ADDR,
>> -			.mask = ST_ACCEL_2_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x18,
>>  			.odr_avl = {
>> -				{ 50, ST_ACCEL_2_ODR_AVL_50HZ_VAL, },
>> -				{ 100, ST_ACCEL_2_ODR_AVL_100HZ_VAL, },
>> -				{ 400, ST_ACCEL_2_ODR_AVL_400HZ_VAL, },
>> -				{ 1000, ST_ACCEL_2_ODR_AVL_1000HZ_VAL, },
>> +				{ .hz = 50, .value = 0x00, },
>> +				{ .hz = 100, .value = 0x01, },
>> +				{ .hz = 400, .value = 0x02, },
>> +				{ .hz = 1000, .value = 0x03, },
>>  			},
>>  		},
>>  		.pw = {
>> -			.addr = ST_ACCEL_2_PW_ADDR,
>> -			.mask = ST_ACCEL_2_PW_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0xe0,
>>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>>  		},
>> @@ -388,69 +200,69 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>>  		},
>>  		.fs = {
>> -			.addr = ST_ACCEL_2_FS_ADDR,
>> -			.mask = ST_ACCEL_2_FS_MASK,
>> +			.addr = 0x23,
>> +			.mask = 0x30,
>>  			.fs_avl = {
>>  				[0] = {
>>  					.num = ST_ACCEL_FS_AVL_2G,
>> -					.value = ST_ACCEL_2_FS_AVL_2_VAL,
>> -					.gain = ST_ACCEL_2_FS_AVL_2_GAIN,
>> +					.value = 0x00,
>> +					.gain = IIO_G_TO_M_S_2(1000),
>>  				},
>>  				[1] = {
>>  					.num = ST_ACCEL_FS_AVL_4G,
>> -					.value = ST_ACCEL_2_FS_AVL_4_VAL,
>> -					.gain = ST_ACCEL_2_FS_AVL_4_GAIN,
>> +					.value = 0x01,
>> +					.gain = IIO_G_TO_M_S_2(2000),
>>  				},
>>  				[2] = {
>>  					.num = ST_ACCEL_FS_AVL_8G,
>> -					.value = ST_ACCEL_2_FS_AVL_8_VAL,
>> -					.gain = ST_ACCEL_2_FS_AVL_8_GAIN,
>> +					.value = 0x03,
>> +					.gain = IIO_G_TO_M_S_2(3900),
>>  				},
>>  			},
>>  		},
>>  		.bdu = {
>> -			.addr = ST_ACCEL_2_BDU_ADDR,
>> -			.mask = ST_ACCEL_2_BDU_MASK,
>> +			.addr = 0x23,
>> +			.mask = 0x80,
>>  		},
>>  		.drdy_irq = {
>> -			.addr = ST_ACCEL_2_DRDY_IRQ_ADDR,
>> -			.mask_int1 = ST_ACCEL_2_DRDY_IRQ_INT1_MASK,
>> -			.mask_int2 = ST_ACCEL_2_DRDY_IRQ_INT2_MASK,
>> -			.addr_ihl = ST_ACCEL_2_IHL_IRQ_ADDR,
>> -			.mask_ihl = ST_ACCEL_2_IHL_IRQ_MASK,
>> -			.addr_od = ST_ACCEL_2_OD_IRQ_ADDR,
>> -			.mask_od = ST_ACCEL_2_OD_IRQ_MASK,
>> +			.addr = 0x22,
>> +			.mask_int1 = 0x02,
>> +			.mask_int2 = 0x10,
>> +			.addr_ihl = 0x22,
>> +			.mask_ihl = 0x80,
>> +			.addr_od = 0x22,
>> +			.mask_od = 0x40,
>>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>>  		},
>> -		.multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,
>> +		.multi_read_bit = true,
>>  		.bootime = 2,
>>  	},
>>  	{
>> -		.wai = ST_ACCEL_3_WAI_EXP,
>> +		.wai = 0x40,
>>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>  		.sensors_supported = {
>>  			[0] = LSM330_ACCEL_DEV_NAME,
>>  		},
>>  		.ch = (struct iio_chan_spec *)st_accel_16bit_channels,
>>  		.odr = {
>> -			.addr = ST_ACCEL_3_ODR_ADDR,
>> -			.mask = ST_ACCEL_3_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0xf0,
>>  			.odr_avl = {
>> -				{ 3, ST_ACCEL_3_ODR_AVL_3HZ_VAL },
>> -				{ 6, ST_ACCEL_3_ODR_AVL_6HZ_VAL, },
>> -				{ 12, ST_ACCEL_3_ODR_AVL_12HZ_VAL, },
>> -				{ 25, ST_ACCEL_3_ODR_AVL_25HZ_VAL, },
>> -				{ 50, ST_ACCEL_3_ODR_AVL_50HZ_VAL, },
>> -				{ 100, ST_ACCEL_3_ODR_AVL_100HZ_VAL, },
>> -				{ 200, ST_ACCEL_3_ODR_AVL_200HZ_VAL, },
>> -				{ 400, ST_ACCEL_3_ODR_AVL_400HZ_VAL, },
>> -				{ 800, ST_ACCEL_3_ODR_AVL_800HZ_VAL, },
>> -				{ 1600, ST_ACCEL_3_ODR_AVL_1600HZ_VAL, },
>> +				{ .hz = 3, .value = 0x01, },
>> +				{ .hz = 6, .value = 0x02, },
>> +				{ .hz = 12, .value = 0x03, },
>> +				{ .hz = 25, .value = 0x04, },
>> +				{ .hz = 50, .value = 0x05, },
>> +				{ .hz = 100, .value = 0x06, },
>> +				{ .hz = 200, .value = 0x07, },
>> +				{ .hz = 400, .value = 0x08, },
>> +				{ .hz = 800, .value = 0x09, },
>> +				{ .hz = 1600, .value = 0x0a, },
>>  			},
>>  		},
>>  		.pw = {
>> -			.addr = ST_ACCEL_3_ODR_ADDR,
>> -			.mask = ST_ACCEL_3_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0xf0,
>>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>>  		},
>>  		.enable_axis = {
>> @@ -458,75 +270,75 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>>  		},
>>  		.fs = {
>> -			.addr = ST_ACCEL_3_FS_ADDR,
>> -			.mask = ST_ACCEL_3_FS_MASK,
>> +			.addr = 0x24,
>> +			.mask = 0x38,
>>  			.fs_avl = {
>>  				[0] = {
>>  					.num = ST_ACCEL_FS_AVL_2G,
>> -					.value = ST_ACCEL_3_FS_AVL_2_VAL,
>> -					.gain = ST_ACCEL_3_FS_AVL_2_GAIN,
>> +					.value = 0x00,
>> +					.gain = IIO_G_TO_M_S_2(61),
>>  				},
>>  				[1] = {
>>  					.num = ST_ACCEL_FS_AVL_4G,
>> -					.value = ST_ACCEL_3_FS_AVL_4_VAL,
>> -					.gain = ST_ACCEL_3_FS_AVL_4_GAIN,
>> +					.value = 0x01,
>> +					.gain = IIO_G_TO_M_S_2(122),
>>  				},
>>  				[2] = {
>>  					.num = ST_ACCEL_FS_AVL_6G,
>> -					.value = ST_ACCEL_3_FS_AVL_6_VAL,
>> -					.gain = ST_ACCEL_3_FS_AVL_6_GAIN,
>> +					.value = 0x02,
>> +					.gain = IIO_G_TO_M_S_2(183),
>>  				},
>>  				[3] = {
>>  					.num = ST_ACCEL_FS_AVL_8G,
>> -					.value = ST_ACCEL_3_FS_AVL_8_VAL,
>> -					.gain = ST_ACCEL_3_FS_AVL_8_GAIN,
>> +					.value = 0x03,
>> +					.gain = IIO_G_TO_M_S_2(244),
>>  				},
>>  				[4] = {
>>  					.num = ST_ACCEL_FS_AVL_16G,
>> -					.value = ST_ACCEL_3_FS_AVL_16_VAL,
>> -					.gain = ST_ACCEL_3_FS_AVL_16_GAIN,
>> +					.value = 0x04,
>> +					.gain = IIO_G_TO_M_S_2(732),
>>  				},
>>  			},
>>  		},
>>  		.bdu = {
>> -			.addr = ST_ACCEL_3_BDU_ADDR,
>> -			.mask = ST_ACCEL_3_BDU_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x08,
>>  		},
>>  		.drdy_irq = {
>> -			.addr = ST_ACCEL_3_DRDY_IRQ_ADDR,
>> -			.mask_int1 = ST_ACCEL_3_DRDY_IRQ_INT1_MASK,
>> -			.mask_int2 = ST_ACCEL_3_DRDY_IRQ_INT2_MASK,
>> -			.addr_ihl = ST_ACCEL_3_IHL_IRQ_ADDR,
>> -			.mask_ihl = ST_ACCEL_3_IHL_IRQ_MASK,
>> +			.addr = 0x23,
>> +			.mask_int1 = 0x80,
>> +			.mask_int2 = 0x00,
>> +			.addr_ihl = 0x23,
>> +			.mask_ihl = 0x40,
>>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>>  			.ig1 = {
>> -				.en_addr = ST_ACCEL_3_IG1_EN_ADDR,
>> -				.en_mask = ST_ACCEL_3_IG1_EN_MASK,
>> +				.en_addr = 0x23,
>> +				.en_mask = 0x08,
>>  			},
>>  		},
>> -		.multi_read_bit = ST_ACCEL_3_MULTIREAD_BIT,
>> +		.multi_read_bit = false,
>>  		.bootime = 2,
>>  	},
>>  	{
>> -		.wai = ST_ACCEL_4_WAI_EXP,
>> +		.wai = 0x3a,
>>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>  		.sensors_supported = {
>>  			[0] = LIS3LV02DL_ACCEL_DEV_NAME,
>>  		},
>>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>>  		.odr = {
>> -			.addr = ST_ACCEL_4_ODR_ADDR,
>> -			.mask = ST_ACCEL_4_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x30, /* DF1 and DF0 */
>>  			.odr_avl = {
>> -				{ 40, ST_ACCEL_4_ODR_AVL_40HZ_VAL },
>> -				{ 160, ST_ACCEL_4_ODR_AVL_160HZ_VAL, },
>> -				{ 640, ST_ACCEL_4_ODR_AVL_640HZ_VAL, },
>> -				{ 2560, ST_ACCEL_4_ODR_AVL_2560HZ_VAL, },
>> +				{ .hz = 40, .value = 0x00, },
>> +				{ .hz = 160, .value = 0x01, },
>> +				{ .hz = 640, .value = 0x02, },
>> +				{ .hz = 2560, .value = 0x03, },
>>  			},
>>  		},
>>  		.pw = {
>> -			.addr = ST_ACCEL_4_PW_ADDR,
>> -			.mask = ST_ACCEL_4_PW_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0xc0,
>>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>>  		},
>> @@ -535,51 +347,51 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>>  		},
>>  		.fs = {
>> -			.addr = ST_ACCEL_4_FS_ADDR,
>> -			.mask = ST_ACCEL_4_FS_MASK,
>> +			.addr = 0x21,
>> +			.mask = 0x80,
>>  			.fs_avl = {
>>  				[0] = {
>>  					.num = ST_ACCEL_FS_AVL_2G,
>> -					.value = ST_ACCEL_4_FS_AVL_2_VAL,
>> -					.gain = ST_ACCEL_4_FS_AVL_2_GAIN,
>> +					.value = 0x00,
>> +					.gain = IIO_G_TO_M_S_2(1024),
>>  				},
>>  				[1] = {
>>  					.num = ST_ACCEL_FS_AVL_6G,
>> -					.value = ST_ACCEL_4_FS_AVL_6_VAL,
>> -					.gain = ST_ACCEL_4_FS_AVL_6_GAIN,
>> +					.value = 0x01,
>> +					.gain = IIO_G_TO_M_S_2(340),
>>  				},
>>  			},
>>  		},
>>  		.bdu = {
>> -			.addr = ST_ACCEL_4_BDU_ADDR,
>> -			.mask = ST_ACCEL_4_BDU_MASK,
>> +			.addr = 0x21,
>> +			.mask = 0x40,
>>  		},
>>  		.drdy_irq = {
>> -			.addr = ST_ACCEL_4_DRDY_IRQ_ADDR,
>> -			.mask_int1 = ST_ACCEL_4_DRDY_IRQ_INT1_MASK,
>> +			.addr = 0x21,
>> +			.mask_int1 = 0x04,
>>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>>  		},
>> -		.multi_read_bit = ST_ACCEL_4_MULTIREAD_BIT,
>> +		.multi_read_bit = true,
>>  		.bootime = 2, /* guess */
>>  	},
>>  	{
>> -		.wai = ST_ACCEL_5_WAI_EXP,
>> +		.wai = 0x3b,
>>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>  		.sensors_supported = {
>>  			[0] = LIS331DL_ACCEL_DEV_NAME,
>>  		},
>>  		.ch = (struct iio_chan_spec *)st_accel_8bit_channels,
>>  		.odr = {
>> -			.addr = ST_ACCEL_5_ODR_ADDR,
>> -			.mask = ST_ACCEL_5_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x80,
>>  			.odr_avl = {
>> -				{ 100, ST_ACCEL_5_ODR_AVL_100HZ_VAL },
>> -				{ 400, ST_ACCEL_5_ODR_AVL_400HZ_VAL, },
>> +				{ .hz = 100, .value = 0x00, },
>> +				{ .hz = 400, .value = 0x01, },
>>  			},
>>  		},
>>  		.pw = {
>> -			.addr = ST_ACCEL_5_PW_ADDR,
>> -			.mask = ST_ACCEL_5_PW_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x40,
>>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>>  		},
>> @@ -588,54 +400,58 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>>  		},
>>  		.fs = {
>> -			.addr = ST_ACCEL_5_FS_ADDR,
>> -			.mask = ST_ACCEL_5_FS_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x20,
>> +			/*
>> +			 * TODO: check these resulting gain settings, these are
>> +			 * not in the datsheet
>> +			 */
>>  			.fs_avl = {
>>  				[0] = {
>>  					.num = ST_ACCEL_FS_AVL_2G,
>> -					.value = ST_ACCEL_5_FS_AVL_2_VAL,
>> -					.gain = ST_ACCEL_5_FS_AVL_2_GAIN,
>> +					.value = 0x00,
>> +					.gain = IIO_G_TO_M_S_2(18000),
>>  				},
>>  				[1] = {
>>  					.num = ST_ACCEL_FS_AVL_8G,
>> -					.value = ST_ACCEL_5_FS_AVL_8_VAL,
>> -					.gain = ST_ACCEL_5_FS_AVL_8_GAIN,
>> +					.value = 0x01,
>> +					.gain = IIO_G_TO_M_S_2(72000),
>>  				},
>>  			},
>>  		},
>>  		.drdy_irq = {
>> -			.addr = ST_ACCEL_5_DRDY_IRQ_ADDR,
>> -			.mask_int1 = ST_ACCEL_5_DRDY_IRQ_INT1_MASK,
>> -			.mask_int2 = ST_ACCEL_5_DRDY_IRQ_INT2_MASK,
>> -			.addr_ihl = ST_ACCEL_5_IHL_IRQ_ADDR,
>> -			.mask_ihl = ST_ACCEL_5_IHL_IRQ_MASK,
>> -			.addr_od = ST_ACCEL_5_OD_IRQ_ADDR,
>> -			.mask_od = ST_ACCEL_5_OD_IRQ_MASK,
>> +			.addr = 0x22,
>> +			.mask_int1 = 0x04,
>> +			.mask_int2 = 0x20,
>> +			.addr_ihl = 0x22,
>> +			.mask_ihl = 0x80,
>> +			.addr_od = 0x22,
>> +			.mask_od = 0x40,
>>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>>  		},
>> -		.multi_read_bit = ST_ACCEL_5_MULTIREAD_BIT,
>> +		.multi_read_bit = false,
>>  		.bootime = 2, /* guess */
>>  	},
>>  	{
>> -		.wai = ST_ACCEL_6_WAI_EXP,
>> +		.wai = 0x32,
>>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>>  		.sensors_supported = {
>>  			[0] = H3LIS331DL_DRIVER_NAME,
>>  		},
>>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>>  		.odr = {
>> -			.addr = ST_ACCEL_6_ODR_ADDR,
>> -			.mask = ST_ACCEL_6_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x18,
>>  			.odr_avl = {
>> -				{ 50, ST_ACCEL_6_ODR_AVL_50HZ_VAL },
>> -				{ 100, ST_ACCEL_6_ODR_AVL_100HZ_VAL, },
>> -				{ 400, ST_ACCEL_6_ODR_AVL_400HZ_VAL, },
>> -				{ 1000, ST_ACCEL_6_ODR_AVL_1000HZ_VAL, },
>> +				{ .hz = 50, .value = 0x00, },
>> +				{ .hz = 100, .value = 0x01, },
>> +				{ .hz = 400, .value = 0x02, },
>> +				{ .hz = 1000, .value = 0x03, },
>>  			},
>>  		},
>>  		.pw = {
>> -			.addr = ST_ACCEL_6_PW_ADDR,
>> -			.mask = ST_ACCEL_6_PW_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x20,
>>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>>  		},
>> @@ -644,38 +460,38 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>>  		},
>>  		.fs = {
>> -			.addr = ST_ACCEL_6_FS_ADDR,
>> -			.mask = ST_ACCEL_6_FS_MASK,
>> +			.addr = 0x23,
>> +			.mask = 0x30,
>>  			.fs_avl = {
>>  				[0] = {
>>  					.num = ST_ACCEL_FS_AVL_100G,
>> -					.value = ST_ACCEL_6_FS_AVL_100_VAL,
>> -					.gain = ST_ACCEL_6_FS_AVL_100_GAIN,
>> +					.value = 0x00,
>> +					.gain = IIO_G_TO_M_S_2(49000),
>>  				},
>>  				[1] = {
>>  					.num = ST_ACCEL_FS_AVL_200G,
>> -					.value = ST_ACCEL_6_FS_AVL_200_VAL,
>> -					.gain = ST_ACCEL_6_FS_AVL_200_GAIN,
>> +					.value = 0x01,
>> +					.gain = IIO_G_TO_M_S_2(98000),
>>  				},
>>  				[2] = {
>>  					.num = ST_ACCEL_FS_AVL_400G,
>> -					.value = ST_ACCEL_6_FS_AVL_400_VAL,
>> -					.gain = ST_ACCEL_6_FS_AVL_400_GAIN,
>> +					.value = 0x03,
>> +					.gain = IIO_G_TO_M_S_2(195000),
>>  				},
>>  			},
>>  		},
>>  		.bdu = {
>> -			.addr = ST_ACCEL_6_BDU_ADDR,
>> -			.mask = ST_ACCEL_6_BDU_MASK,
>> +			.addr = 0x23,
>> +			.mask = 0x80,
>>  		},
>>  		.drdy_irq = {
>> -			.addr = ST_ACCEL_6_DRDY_IRQ_ADDR,
>> -			.mask_int1 = ST_ACCEL_6_DRDY_IRQ_INT1_MASK,
>> -			.mask_int2 = ST_ACCEL_6_DRDY_IRQ_INT2_MASK,
>> -			.addr_ihl = ST_ACCEL_6_IHL_IRQ_ADDR,
>> -			.mask_ihl = ST_ACCEL_6_IHL_IRQ_MASK,
>> +			.addr = 0x22,
>> +			.mask_int1 = 0x02,
>> +			.mask_int2 = 0x10,
>> +			.addr_ihl = 0x22,
>> +			.mask_ihl = 0x80,
>>  		},
>> -		.multi_read_bit = ST_ACCEL_6_MULTIREAD_BIT,
>> +		.multi_read_bit = true,
>>  		.bootime = 2,
>>  	},
>>  	{
>> @@ -685,18 +501,18 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  		},
>>  		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
>>  		.odr = {
>> -			.addr = ST_ACCEL_7_ODR_ADDR,
>> -			.mask = ST_ACCEL_7_ODR_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0x30,
>>  			.odr_avl = {
>> -				{ 280, ST_ACCEL_7_ODR_AVL_280HZ_VAL, },
>> -				{ 560, ST_ACCEL_7_ODR_AVL_560HZ_VAL, },
>> -				{ 1120, ST_ACCEL_7_ODR_AVL_1120HZ_VAL, },
>> -				{ 4480, ST_ACCEL_7_ODR_AVL_4480HZ_VAL, },
>> +				{ .hz = 280, .value = 0x00, },
>> +				{ .hz = 560, .value = 0x01, },
>> +				{ .hz = 1120, .value = 0x02, },
>> +				{ .hz = 4480, .value = 0x03, },
>>  			},
>>  		},
>>  		.pw = {
>> -			.addr = ST_ACCEL_7_PW_ADDR,
>> -			.mask = ST_ACCEL_7_PW_MASK,
>> +			.addr = 0x20,
>> +			.mask = 0xc0,
>>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>>  		},
>> @@ -708,7 +524,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  			.fs_avl = {
>>  				[0] = {
>>  					.num = ST_ACCEL_FS_AVL_2G,
>> -					.gain = ST_ACCEL_7_FS_AVL_2_GAIN,
>> +					.gain = IIO_G_TO_M_S_2(488),
>>  				},
>>  			},
>>  		},
>> @@ -719,11 +535,11 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
>>  		.bdu = {
>>  		},
>>  		.drdy_irq = {
>> -			.addr = ST_ACCEL_7_DRDY_IRQ_ADDR,
>> -			.mask_int1 = ST_ACCEL_7_DRDY_IRQ_INT1_MASK,
>> +			.addr = 0x21,
>> +			.mask_int1 = 0x04,
>>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>>  		},
>> -		.multi_read_bit = ST_ACCEL_7_MULTIREAD_BIT,
>> +		.multi_read_bit = false,
>>  		.bootime = 2,
>>  	},
>>  };
>>
> 
> --
> 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] 10+ messages in thread

* Re: [PATCH 2/4] iio: gyro: st_gyro: inline per-sensor data
  2016-11-09 15:09 ` [PATCH 2/4] iio: gyro: st_gyro: " Linus Walleij
@ 2016-11-12 15:38   ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2016-11-12 15:38 UTC (permalink / raw)
  To: Linus Walleij, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard

On 09/11/16 15:09, Linus Walleij wrote:
> We have #defines for all the individual sensor registers and
> value/mask pairs #defined at the top of the file and used at
> exactly one spot.
> 
> This is usually good if the #defines give a meaning to the
> opaque magic numbers.
> 
> However in this case, the semantic meaning is inherent in the
> name of the C99-addressable fields, and that means duplication
> of information, and only makes the code hard to maintain since
> you every time have to add a new #define AND update the site
> where it is to be used.
> 
> Get rid of the #defines and just open code the values into the
> appropriate struct elements. Make sure to explicitly address
> the .hz and .value fields in the st_sensor_odr_avl struct
> so that the meaning of all values is clear.
> 
> This patch is purely syntactic should have no semantic effect.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Great and applied.
> ---
>  drivers/iio/gyro/st_gyro_core.c | 205 +++++++++++++---------------------------
>  1 file changed, 66 insertions(+), 139 deletions(-)
> 
> diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
> index aea034d8fe0f..2a42b3d583e8 100644
> --- a/drivers/iio/gyro/st_gyro_core.c
> +++ b/drivers/iio/gyro/st_gyro_core.c
> @@ -39,79 +39,6 @@
>  #define ST_GYRO_FS_AVL_500DPS			500
>  #define ST_GYRO_FS_AVL_2000DPS			2000
>  
> -/* CUSTOM VALUES FOR SENSOR 1 */
> -#define ST_GYRO_1_WAI_EXP			0xd3
> -#define ST_GYRO_1_ODR_ADDR			0x20
> -#define ST_GYRO_1_ODR_MASK			0xc0
> -#define ST_GYRO_1_ODR_AVL_100HZ_VAL		0x00
> -#define ST_GYRO_1_ODR_AVL_200HZ_VAL		0x01
> -#define ST_GYRO_1_ODR_AVL_400HZ_VAL		0x02
> -#define ST_GYRO_1_ODR_AVL_800HZ_VAL		0x03
> -#define ST_GYRO_1_PW_ADDR			0x20
> -#define ST_GYRO_1_PW_MASK			0x08
> -#define ST_GYRO_1_FS_ADDR			0x23
> -#define ST_GYRO_1_FS_MASK			0x30
> -#define ST_GYRO_1_FS_AVL_250_VAL		0x00
> -#define ST_GYRO_1_FS_AVL_500_VAL		0x01
> -#define ST_GYRO_1_FS_AVL_2000_VAL		0x02
> -#define ST_GYRO_1_FS_AVL_250_GAIN		IIO_DEGREE_TO_RAD(8750)
> -#define ST_GYRO_1_FS_AVL_500_GAIN		IIO_DEGREE_TO_RAD(17500)
> -#define ST_GYRO_1_FS_AVL_2000_GAIN		IIO_DEGREE_TO_RAD(70000)
> -#define ST_GYRO_1_BDU_ADDR			0x23
> -#define ST_GYRO_1_BDU_MASK			0x80
> -#define ST_GYRO_1_DRDY_IRQ_ADDR			0x22
> -#define ST_GYRO_1_DRDY_IRQ_INT2_MASK		0x08
> -#define ST_GYRO_1_MULTIREAD_BIT			true
> -
> -/* CUSTOM VALUES FOR SENSOR 2 */
> -#define ST_GYRO_2_WAI_EXP			0xd4
> -#define ST_GYRO_2_ODR_ADDR			0x20
> -#define ST_GYRO_2_ODR_MASK			0xc0
> -#define ST_GYRO_2_ODR_AVL_95HZ_VAL		0x00
> -#define ST_GYRO_2_ODR_AVL_190HZ_VAL		0x01
> -#define ST_GYRO_2_ODR_AVL_380HZ_VAL		0x02
> -#define ST_GYRO_2_ODR_AVL_760HZ_VAL		0x03
> -#define ST_GYRO_2_PW_ADDR			0x20
> -#define ST_GYRO_2_PW_MASK			0x08
> -#define ST_GYRO_2_FS_ADDR			0x23
> -#define ST_GYRO_2_FS_MASK			0x30
> -#define ST_GYRO_2_FS_AVL_250_VAL		0x00
> -#define ST_GYRO_2_FS_AVL_500_VAL		0x01
> -#define ST_GYRO_2_FS_AVL_2000_VAL		0x02
> -#define ST_GYRO_2_FS_AVL_250_GAIN		IIO_DEGREE_TO_RAD(8750)
> -#define ST_GYRO_2_FS_AVL_500_GAIN		IIO_DEGREE_TO_RAD(17500)
> -#define ST_GYRO_2_FS_AVL_2000_GAIN		IIO_DEGREE_TO_RAD(70000)
> -#define ST_GYRO_2_BDU_ADDR			0x23
> -#define ST_GYRO_2_BDU_MASK			0x80
> -#define ST_GYRO_2_DRDY_IRQ_ADDR			0x22
> -#define ST_GYRO_2_DRDY_IRQ_INT2_MASK		0x08
> -#define ST_GYRO_2_MULTIREAD_BIT			true
> -
> -/* CUSTOM VALUES FOR SENSOR 3 */
> -#define ST_GYRO_3_WAI_EXP			0xd7
> -#define ST_GYRO_3_ODR_ADDR			0x20
> -#define ST_GYRO_3_ODR_MASK			0xc0
> -#define ST_GYRO_3_ODR_AVL_95HZ_VAL		0x00
> -#define ST_GYRO_3_ODR_AVL_190HZ_VAL		0x01
> -#define ST_GYRO_3_ODR_AVL_380HZ_VAL		0x02
> -#define ST_GYRO_3_ODR_AVL_760HZ_VAL		0x03
> -#define ST_GYRO_3_PW_ADDR			0x20
> -#define ST_GYRO_3_PW_MASK			0x08
> -#define ST_GYRO_3_FS_ADDR			0x23
> -#define ST_GYRO_3_FS_MASK			0x30
> -#define ST_GYRO_3_FS_AVL_250_VAL		0x00
> -#define ST_GYRO_3_FS_AVL_500_VAL		0x01
> -#define ST_GYRO_3_FS_AVL_2000_VAL		0x02
> -#define ST_GYRO_3_FS_AVL_250_GAIN		IIO_DEGREE_TO_RAD(8750)
> -#define ST_GYRO_3_FS_AVL_500_GAIN		IIO_DEGREE_TO_RAD(17500)
> -#define ST_GYRO_3_FS_AVL_2000_GAIN		IIO_DEGREE_TO_RAD(70000)
> -#define ST_GYRO_3_BDU_ADDR			0x23
> -#define ST_GYRO_3_BDU_MASK			0x80
> -#define ST_GYRO_3_DRDY_IRQ_ADDR			0x22
> -#define ST_GYRO_3_DRDY_IRQ_INT2_MASK		0x08
> -#define ST_GYRO_3_MULTIREAD_BIT			true
> -
> -
>  static const struct iio_chan_spec st_gyro_16bit_channels[] = {
>  	ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
>  			BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
> @@ -130,7 +57,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 = 0xd3,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = L3G4200D_GYRO_DEV_NAME,
> @@ -138,18 +65,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  		},
>  		.ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
>  		.odr = {
> -			.addr = ST_GYRO_1_ODR_ADDR,
> -			.mask = ST_GYRO_1_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0xc0,
>  			.odr_avl = {
> -				{ 100, ST_GYRO_1_ODR_AVL_100HZ_VAL, },
> -				{ 200, ST_GYRO_1_ODR_AVL_200HZ_VAL, },
> -				{ 400, ST_GYRO_1_ODR_AVL_400HZ_VAL, },
> -				{ 800, ST_GYRO_1_ODR_AVL_800HZ_VAL, },
> +				{ .hz = 100, .value = 0x00, },
> +				{ .hz = 200, .value = 0x01, },
> +				{ .hz = 400, .value = 0x02, },
> +				{ .hz = 800, .value = 0x03, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_GYRO_1_PW_ADDR,
> -			.mask = ST_GYRO_1_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x08,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -158,33 +85,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_GYRO_1_FS_ADDR,
> -			.mask = ST_GYRO_1_FS_MASK,
> +			.addr = 0x23,
> +			.mask = 0x30,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_GYRO_FS_AVL_250DPS,
> -					.value = ST_GYRO_1_FS_AVL_250_VAL,
> -					.gain = ST_GYRO_1_FS_AVL_250_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_DEGREE_TO_RAD(8750),
>  				},
>  				[1] = {
>  					.num = ST_GYRO_FS_AVL_500DPS,
> -					.value = ST_GYRO_1_FS_AVL_500_VAL,
> -					.gain = ST_GYRO_1_FS_AVL_500_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_DEGREE_TO_RAD(17500),
>  				},
>  				[2] = {
>  					.num = ST_GYRO_FS_AVL_2000DPS,
> -					.value = ST_GYRO_1_FS_AVL_2000_VAL,
> -					.gain = ST_GYRO_1_FS_AVL_2000_GAIN,
> +					.value = 0x02,
> +					.gain = IIO_DEGREE_TO_RAD(70000),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_GYRO_1_BDU_ADDR,
> -			.mask = ST_GYRO_1_BDU_MASK,
> +			.addr = 0x23,
> +			.mask = 0x80,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_GYRO_1_DRDY_IRQ_ADDR,
> -			.mask_int2 = ST_GYRO_1_DRDY_IRQ_INT2_MASK,
> +			.addr = 0x22,
> +			.mask_int2 = 0x08,
>  			/*
>  			 * The sensor has IHL (active low) and open
>  			 * drain settings, but only for INT1 and not
> @@ -192,11 +119,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  			 */
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_GYRO_2_WAI_EXP,
> +		.wai = 0xd4,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = L3GD20_GYRO_DEV_NAME,
> @@ -208,18 +135,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  		},
>  		.ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
>  		.odr = {
> -			.addr = ST_GYRO_2_ODR_ADDR,
> -			.mask = ST_GYRO_2_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0xc0,
>  			.odr_avl = {
> -				{ 95, ST_GYRO_2_ODR_AVL_95HZ_VAL, },
> -				{ 190, ST_GYRO_2_ODR_AVL_190HZ_VAL, },
> -				{ 380, ST_GYRO_2_ODR_AVL_380HZ_VAL, },
> -				{ 760, ST_GYRO_2_ODR_AVL_760HZ_VAL, },
> +				{ .hz = 95, .value = 0x00, },
> +				{ .hz = 190, .value = 0x01, },
> +				{ .hz = 380, .value = 0x02, },
> +				{ .hz = 760, .value = 0x03, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_GYRO_2_PW_ADDR,
> -			.mask = ST_GYRO_2_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x08,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -228,33 +155,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_GYRO_2_FS_ADDR,
> -			.mask = ST_GYRO_2_FS_MASK,
> +			.addr = 0x23,
> +			.mask = 0x30,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_GYRO_FS_AVL_250DPS,
> -					.value = ST_GYRO_2_FS_AVL_250_VAL,
> -					.gain = ST_GYRO_2_FS_AVL_250_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_DEGREE_TO_RAD(8750),
>  				},
>  				[1] = {
>  					.num = ST_GYRO_FS_AVL_500DPS,
> -					.value = ST_GYRO_2_FS_AVL_500_VAL,
> -					.gain = ST_GYRO_2_FS_AVL_500_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_DEGREE_TO_RAD(17500),
>  				},
>  				[2] = {
>  					.num = ST_GYRO_FS_AVL_2000DPS,
> -					.value = ST_GYRO_2_FS_AVL_2000_VAL,
> -					.gain = ST_GYRO_2_FS_AVL_2000_GAIN,
> +					.value = 0x02,
> +					.gain = IIO_DEGREE_TO_RAD(70000),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_GYRO_2_BDU_ADDR,
> -			.mask = ST_GYRO_2_BDU_MASK,
> +			.addr = 0x23,
> +			.mask = 0x80,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_GYRO_2_DRDY_IRQ_ADDR,
> -			.mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK,
> +			.addr = 0x22,
> +			.mask_int2 = 0x08,
>  			/*
>  			 * The sensor has IHL (active low) and open
>  			 * drain settings, but only for INT1 and not
> @@ -262,29 +189,29 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  			 */
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_GYRO_3_WAI_EXP,
> +		.wai = 0xd7,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = L3GD20_GYRO_DEV_NAME,
>  		},
>  		.ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
>  		.odr = {
> -			.addr = ST_GYRO_3_ODR_ADDR,
> -			.mask = ST_GYRO_3_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0xc0,
>  			.odr_avl = {
> -				{ 95, ST_GYRO_3_ODR_AVL_95HZ_VAL, },
> -				{ 190, ST_GYRO_3_ODR_AVL_190HZ_VAL, },
> -				{ 380, ST_GYRO_3_ODR_AVL_380HZ_VAL, },
> -				{ 760, ST_GYRO_3_ODR_AVL_760HZ_VAL, },
> +				{ .hz = 95, .value = 0x00, },
> +				{ .hz = 190, .value = 0x01, },
> +				{ .hz = 380, .value = 0x02, },
> +				{ .hz = 760, .value = 0x03, },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_GYRO_3_PW_ADDR,
> -			.mask = ST_GYRO_3_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x08,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -293,33 +220,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
>  		},
>  		.fs = {
> -			.addr = ST_GYRO_3_FS_ADDR,
> -			.mask = ST_GYRO_3_FS_MASK,
> +			.addr = 0x23,
> +			.mask = 0x30,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_GYRO_FS_AVL_250DPS,
> -					.value = ST_GYRO_3_FS_AVL_250_VAL,
> -					.gain = ST_GYRO_3_FS_AVL_250_GAIN,
> +					.value = 0x00,
> +					.gain = IIO_DEGREE_TO_RAD(8750),
>  				},
>  				[1] = {
>  					.num = ST_GYRO_FS_AVL_500DPS,
> -					.value = ST_GYRO_3_FS_AVL_500_VAL,
> -					.gain = ST_GYRO_3_FS_AVL_500_GAIN,
> +					.value = 0x01,
> +					.gain = IIO_DEGREE_TO_RAD(17500),
>  				},
>  				[2] = {
>  					.num = ST_GYRO_FS_AVL_2000DPS,
> -					.value = ST_GYRO_3_FS_AVL_2000_VAL,
> -					.gain = ST_GYRO_3_FS_AVL_2000_GAIN,
> +					.value = 0x02,
> +					.gain = IIO_DEGREE_TO_RAD(70000),
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_GYRO_3_BDU_ADDR,
> -			.mask = ST_GYRO_3_BDU_MASK,
> +			.addr = 0x23,
> +			.mask = 0x80,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_GYRO_3_DRDY_IRQ_ADDR,
> -			.mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK,
> +			.addr = 0x22,
> +			.mask_int2 = 0x08,
>  			/*
>  			 * The sensor has IHL (active low) and open
>  			 * drain settings, but only for INT1 and not
> @@ -327,7 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
>  			 */
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_GYRO_3_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  };
> 


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

* Re: [PATCH 3/4] iio: magn: st_magn: inline per-sensor data
  2016-11-09 15:09 ` [PATCH 3/4] iio: magn: st_magn: " Linus Walleij
@ 2016-11-12 15:45   ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2016-11-12 15:45 UTC (permalink / raw)
  To: Linus Walleij, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard

On 09/11/16 15:09, Linus Walleij wrote:
> We have #defines for all the individual sensor registers and
> value/mask pairs #defined at the top of the file and used at
> exactly one spot.
> 
> This is usually good if the #defines give a meaning to the
> opaque magic numbers.
> 
> However in this case, the semantic meaning is inherent in the
> name of the C99-addressable fields, and that means duplication
> of information, and only makes the code hard to maintain since
> you every time have to add a new #define AND update the site
> where it is to be used.
> 
> Get rid of the #defines and just open code the values into the
> appropriate struct elements. Make sure to explicitly address
> the .hz and .value fields in the st_sensor_odr_avl struct
> so that the meaning of all values is clear.
> 
> This patch is purely syntactic should have no semantic effect.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Looks good and applied.

Thanks,

Jonathan
> ---
>  drivers/iio/magnetometer/st_magn_core.c | 376 +++++++++++---------------------
>  1 file changed, 125 insertions(+), 251 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
> index 3e1f06b2224c..8e1b0861fbe4 100644
> --- a/drivers/iio/magnetometer/st_magn_core.c
> +++ b/drivers/iio/magnetometer/st_magn_core.c
> @@ -46,139 +46,12 @@
>  #define ST_MAGN_FS_AVL_15000MG			15000
>  #define ST_MAGN_FS_AVL_16000MG			16000
>  
> -/* CUSTOM VALUES FOR SENSOR 0 */
> -#define ST_MAGN_0_ODR_ADDR			0x00
> -#define ST_MAGN_0_ODR_MASK			0x1c
> -#define ST_MAGN_0_ODR_AVL_1HZ_VAL		0x00
> -#define ST_MAGN_0_ODR_AVL_2HZ_VAL		0x01
> -#define ST_MAGN_0_ODR_AVL_3HZ_VAL		0x02
> -#define ST_MAGN_0_ODR_AVL_8HZ_VAL		0x03
> -#define ST_MAGN_0_ODR_AVL_15HZ_VAL		0x04
> -#define ST_MAGN_0_ODR_AVL_30HZ_VAL		0x05
> -#define ST_MAGN_0_ODR_AVL_75HZ_VAL		0x06
> -#define ST_MAGN_0_ODR_AVL_220HZ_VAL		0x07
> -#define ST_MAGN_0_PW_ADDR			0x02
> -#define ST_MAGN_0_PW_MASK			0x03
> -#define ST_MAGN_0_PW_ON				0x00
> -#define ST_MAGN_0_PW_OFF			0x03
> -#define ST_MAGN_0_FS_ADDR			0x01
> -#define ST_MAGN_0_FS_MASK			0xe0
> -#define ST_MAGN_0_FS_AVL_1300_VAL		0x01
> -#define ST_MAGN_0_FS_AVL_1900_VAL		0x02
> -#define ST_MAGN_0_FS_AVL_2500_VAL		0x03
> -#define ST_MAGN_0_FS_AVL_4000_VAL		0x04
> -#define ST_MAGN_0_FS_AVL_4700_VAL		0x05
> -#define ST_MAGN_0_FS_AVL_5600_VAL		0x06
> -#define ST_MAGN_0_FS_AVL_8100_VAL		0x07
> -#define ST_MAGN_0_FS_AVL_1300_GAIN_XY		1100
> -#define ST_MAGN_0_FS_AVL_1900_GAIN_XY		855
> -#define ST_MAGN_0_FS_AVL_2500_GAIN_XY		670
> -#define ST_MAGN_0_FS_AVL_4000_GAIN_XY		450
> -#define ST_MAGN_0_FS_AVL_4700_GAIN_XY		400
> -#define ST_MAGN_0_FS_AVL_5600_GAIN_XY		330
> -#define ST_MAGN_0_FS_AVL_8100_GAIN_XY		230
> -#define ST_MAGN_0_FS_AVL_1300_GAIN_Z		980
> -#define ST_MAGN_0_FS_AVL_1900_GAIN_Z		760
> -#define ST_MAGN_0_FS_AVL_2500_GAIN_Z		600
> -#define ST_MAGN_0_FS_AVL_4000_GAIN_Z		400
> -#define ST_MAGN_0_FS_AVL_4700_GAIN_Z		355
> -#define ST_MAGN_0_FS_AVL_5600_GAIN_Z		295
> -#define ST_MAGN_0_FS_AVL_8100_GAIN_Z		205
> -#define ST_MAGN_0_MULTIREAD_BIT			false
> -
> -/* CUSTOM VALUES FOR SENSOR 1 */
> -#define ST_MAGN_1_WAI_EXP			0x3c
> -#define ST_MAGN_1_ODR_ADDR			0x00
> -#define ST_MAGN_1_ODR_MASK			0x1c
> -#define ST_MAGN_1_ODR_AVL_1HZ_VAL		0x00
> -#define ST_MAGN_1_ODR_AVL_2HZ_VAL		0x01
> -#define ST_MAGN_1_ODR_AVL_3HZ_VAL		0x02
> -#define ST_MAGN_1_ODR_AVL_8HZ_VAL		0x03
> -#define ST_MAGN_1_ODR_AVL_15HZ_VAL		0x04
> -#define ST_MAGN_1_ODR_AVL_30HZ_VAL		0x05
> -#define ST_MAGN_1_ODR_AVL_75HZ_VAL		0x06
> -#define ST_MAGN_1_ODR_AVL_220HZ_VAL		0x07
> -#define ST_MAGN_1_PW_ADDR			0x02
> -#define ST_MAGN_1_PW_MASK			0x03
> -#define ST_MAGN_1_PW_ON				0x00
> -#define ST_MAGN_1_PW_OFF			0x03
> -#define ST_MAGN_1_FS_ADDR			0x01
> -#define ST_MAGN_1_FS_MASK			0xe0
> -#define ST_MAGN_1_FS_AVL_1300_VAL		0x01
> -#define ST_MAGN_1_FS_AVL_1900_VAL		0x02
> -#define ST_MAGN_1_FS_AVL_2500_VAL		0x03
> -#define ST_MAGN_1_FS_AVL_4000_VAL		0x04
> -#define ST_MAGN_1_FS_AVL_4700_VAL		0x05
> -#define ST_MAGN_1_FS_AVL_5600_VAL		0x06
> -#define ST_MAGN_1_FS_AVL_8100_VAL		0x07
> -#define ST_MAGN_1_FS_AVL_1300_GAIN_XY		909
> -#define ST_MAGN_1_FS_AVL_1900_GAIN_XY		1169
> -#define ST_MAGN_1_FS_AVL_2500_GAIN_XY		1492
> -#define ST_MAGN_1_FS_AVL_4000_GAIN_XY		2222
> -#define ST_MAGN_1_FS_AVL_4700_GAIN_XY		2500
> -#define ST_MAGN_1_FS_AVL_5600_GAIN_XY		3030
> -#define ST_MAGN_1_FS_AVL_8100_GAIN_XY		4347
> -#define ST_MAGN_1_FS_AVL_1300_GAIN_Z		1020
> -#define ST_MAGN_1_FS_AVL_1900_GAIN_Z		1315
> -#define ST_MAGN_1_FS_AVL_2500_GAIN_Z		1666
> -#define ST_MAGN_1_FS_AVL_4000_GAIN_Z		2500
> -#define ST_MAGN_1_FS_AVL_4700_GAIN_Z		2816
> -#define ST_MAGN_1_FS_AVL_5600_GAIN_Z		3389
> -#define ST_MAGN_1_FS_AVL_8100_GAIN_Z		4878
> -#define ST_MAGN_1_MULTIREAD_BIT			false
> -
> -/* CUSTOM VALUES FOR SENSOR 2 */
> -#define ST_MAGN_2_WAI_EXP			0x3d
> -#define ST_MAGN_2_ODR_ADDR			0x20
> -#define ST_MAGN_2_ODR_MASK			0x1c
> -#define ST_MAGN_2_ODR_AVL_1HZ_VAL		0x00
> -#define ST_MAGN_2_ODR_AVL_2HZ_VAL		0x01
> -#define ST_MAGN_2_ODR_AVL_3HZ_VAL		0x02
> -#define ST_MAGN_2_ODR_AVL_5HZ_VAL		0x03
> -#define ST_MAGN_2_ODR_AVL_10HZ_VAL		0x04
> -#define ST_MAGN_2_ODR_AVL_20HZ_VAL		0x05
> -#define ST_MAGN_2_ODR_AVL_40HZ_VAL		0x06
> -#define ST_MAGN_2_ODR_AVL_80HZ_VAL		0x07
> -#define ST_MAGN_2_PW_ADDR			0x22
> -#define ST_MAGN_2_PW_MASK			0x03
> -#define ST_MAGN_2_PW_ON				0x00
> -#define ST_MAGN_2_PW_OFF			0x03
> -#define ST_MAGN_2_FS_ADDR			0x21
> -#define ST_MAGN_2_FS_MASK			0x60
> -#define ST_MAGN_2_FS_AVL_4000_VAL		0x00
> -#define ST_MAGN_2_FS_AVL_8000_VAL		0x01
> -#define ST_MAGN_2_FS_AVL_12000_VAL		0x02
> -#define ST_MAGN_2_FS_AVL_16000_VAL		0x03
> -#define ST_MAGN_2_FS_AVL_4000_GAIN		146
> -#define ST_MAGN_2_FS_AVL_8000_GAIN		292
> -#define ST_MAGN_2_FS_AVL_12000_GAIN		438
> -#define ST_MAGN_2_FS_AVL_16000_GAIN		584
> -#define ST_MAGN_2_MULTIREAD_BIT			false
> +/* Special L addresses for Sensor 2 */
>  #define ST_MAGN_2_OUT_X_L_ADDR			0x28
>  #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_IHL_IRQ_ADDR			0x63
> -#define ST_MAGN_3_IHL_IRQ_MASK			0x04
> -#define ST_MAGN_3_FS_AVL_15000_GAIN		1500
> -#define ST_MAGN_3_MULTIREAD_BIT			false
> +/* Special L addresses for sensor 3 */
>  #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
> @@ -240,77 +113,78 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  		},
>  		.ch = (struct iio_chan_spec *)st_magn_16bit_channels,
>  		.odr = {
> -			.addr = ST_MAGN_0_ODR_ADDR,
> -			.mask = ST_MAGN_0_ODR_MASK,
> +			.addr = 0x00,
> +			.mask = 0x1c,
>  			.odr_avl = {
> -				{ 1, ST_MAGN_0_ODR_AVL_1HZ_VAL, },
> -				{ 2, ST_MAGN_0_ODR_AVL_2HZ_VAL, },
> -				{ 3, ST_MAGN_0_ODR_AVL_3HZ_VAL, },
> -				{ 8, ST_MAGN_0_ODR_AVL_8HZ_VAL, },
> -				{ 15, ST_MAGN_0_ODR_AVL_15HZ_VAL, },
> -				{ 30, ST_MAGN_0_ODR_AVL_30HZ_VAL, },
> -				{ 75, ST_MAGN_0_ODR_AVL_75HZ_VAL, },
> +				{ .hz = 1, .value = 0x00 },
> +				{ .hz = 2, .value = 0x01 },
> +				{ .hz = 3, .value = 0x02 },
> +				{ .hz = 8, .value = 0x03 },
> +				{ .hz = 15, .value = 0x04 },
> +				{ .hz = 30, .value = 0x05 },
> +				{ .hz = 75, .value = 0x06 },
> +				/* 220 Hz, 0x07 reportedly exist */
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_MAGN_0_PW_ADDR,
> -			.mask = ST_MAGN_0_PW_MASK,
> -			.value_on = ST_MAGN_0_PW_ON,
> -			.value_off = ST_MAGN_0_PW_OFF,
> +			.addr = 0x02,
> +			.mask = 0x03,
> +			.value_on = 0x00,
> +			.value_off = 0x03,
>  		},
>  		.fs = {
> -			.addr = ST_MAGN_0_FS_ADDR,
> -			.mask = ST_MAGN_0_FS_MASK,
> +			.addr = 0x01,
> +			.mask = 0xe0,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_MAGN_FS_AVL_1300MG,
> -					.value = ST_MAGN_0_FS_AVL_1300_VAL,
> -					.gain = ST_MAGN_0_FS_AVL_1300_GAIN_XY,
> -					.gain2 = ST_MAGN_0_FS_AVL_1300_GAIN_Z,
> +					.value = 0x01,
> +					.gain = 1100,
> +					.gain2 = 980,
>  				},
>  				[1] = {
>  					.num = ST_MAGN_FS_AVL_1900MG,
> -					.value = ST_MAGN_0_FS_AVL_1900_VAL,
> -					.gain = ST_MAGN_0_FS_AVL_1900_GAIN_XY,
> -					.gain2 = ST_MAGN_0_FS_AVL_1900_GAIN_Z,
> +					.value = 0x02,
> +					.gain = 855,
> +					.gain2 = 760,
>  				},
>  				[2] = {
>  					.num = ST_MAGN_FS_AVL_2500MG,
> -					.value = ST_MAGN_0_FS_AVL_2500_VAL,
> -					.gain = ST_MAGN_0_FS_AVL_2500_GAIN_XY,
> -					.gain2 = ST_MAGN_0_FS_AVL_2500_GAIN_Z,
> +					.value = 0x03,
> +					.gain = 670,
> +					.gain2 = 600,
>  				},
>  				[3] = {
>  					.num = ST_MAGN_FS_AVL_4000MG,
> -					.value = ST_MAGN_0_FS_AVL_4000_VAL,
> -					.gain = ST_MAGN_0_FS_AVL_4000_GAIN_XY,
> -					.gain2 = ST_MAGN_0_FS_AVL_4000_GAIN_Z,
> +					.value = 0x04,
> +					.gain = 450,
> +					.gain2 = 400,
>  				},
>  				[4] = {
>  					.num = ST_MAGN_FS_AVL_4700MG,
> -					.value = ST_MAGN_0_FS_AVL_4700_VAL,
> -					.gain = ST_MAGN_0_FS_AVL_4700_GAIN_XY,
> -					.gain2 = ST_MAGN_0_FS_AVL_4700_GAIN_Z,
> +					.value = 0x05,
> +					.gain = 400,
> +					.gain2 = 355,
>  				},
>  				[5] = {
>  					.num = ST_MAGN_FS_AVL_5600MG,
> -					.value = ST_MAGN_0_FS_AVL_5600_VAL,
> -					.gain = ST_MAGN_0_FS_AVL_5600_GAIN_XY,
> -					.gain2 = ST_MAGN_0_FS_AVL_5600_GAIN_Z,
> +					.value = 0x06,
> +					.gain = 330,
> +					.gain2 = 295,
>  				},
>  				[6] = {
>  					.num = ST_MAGN_FS_AVL_8100MG,
> -					.value = ST_MAGN_0_FS_AVL_8100_VAL,
> -					.gain = ST_MAGN_0_FS_AVL_8100_GAIN_XY,
> -					.gain2 = ST_MAGN_0_FS_AVL_8100_GAIN_Z,
> +					.value = 0x07,
> +					.gain = 230,
> +					.gain2 = 205,
>  				},
>  			},
>  		},
> -		.multi_read_bit = ST_MAGN_0_MULTIREAD_BIT,
> +		.multi_read_bit = false,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_MAGN_1_WAI_EXP,
> +		.wai = 0x3c,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LSM303DLHC_MAGN_DEV_NAME,
> @@ -318,175 +192,175 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
>  		},
>  		.ch = (struct iio_chan_spec *)st_magn_16bit_channels,
>  		.odr = {
> -			.addr = ST_MAGN_1_ODR_ADDR,
> -			.mask = ST_MAGN_1_ODR_MASK,
> +			.addr = 0x00,
> +			.mask = 0x1c,
>  			.odr_avl = {
> -				{ 1, ST_MAGN_1_ODR_AVL_1HZ_VAL, },
> -				{ 2, ST_MAGN_1_ODR_AVL_2HZ_VAL, },
> -				{ 3, ST_MAGN_1_ODR_AVL_3HZ_VAL, },
> -				{ 8, ST_MAGN_1_ODR_AVL_8HZ_VAL, },
> -				{ 15, ST_MAGN_1_ODR_AVL_15HZ_VAL, },
> -				{ 30, ST_MAGN_1_ODR_AVL_30HZ_VAL, },
> -				{ 75, ST_MAGN_1_ODR_AVL_75HZ_VAL, },
> -				{ 220, ST_MAGN_1_ODR_AVL_220HZ_VAL, },
> +				{ .hz = 1, .value = 0x00 },
> +				{ .hz = 2, .value = 0x01 },
> +				{ .hz = 3, .value = 0x02 },
> +				{ .hz = 8, .value = 0x03 },
> +				{ .hz = 15, .value = 0x04 },
> +				{ .hz = 30, .value = 0x05 },
> +				{ .hz = 75, .value = 0x06 },
> +				{ .hz = 220, .value = 0x07 },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_MAGN_1_PW_ADDR,
> -			.mask = ST_MAGN_1_PW_MASK,
> -			.value_on = ST_MAGN_1_PW_ON,
> -			.value_off = ST_MAGN_1_PW_OFF,
> +			.addr = 0x02,
> +			.mask = 0x03,
> +			.value_on = 0x00,
> +			.value_off = 0x03,
>  		},
>  		.fs = {
> -			.addr = ST_MAGN_1_FS_ADDR,
> -			.mask = ST_MAGN_1_FS_MASK,
> +			.addr = 0x01,
> +			.mask = 0xe0,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_MAGN_FS_AVL_1300MG,
> -					.value = ST_MAGN_1_FS_AVL_1300_VAL,
> -					.gain = ST_MAGN_1_FS_AVL_1300_GAIN_XY,
> -					.gain2 = ST_MAGN_1_FS_AVL_1300_GAIN_Z,
> +					.value = 0x01,
> +					.gain = 909,
> +					.gain2 = 1020,
>  				},
>  				[1] = {
>  					.num = ST_MAGN_FS_AVL_1900MG,
> -					.value = ST_MAGN_1_FS_AVL_1900_VAL,
> -					.gain = ST_MAGN_1_FS_AVL_1900_GAIN_XY,
> -					.gain2 = ST_MAGN_1_FS_AVL_1900_GAIN_Z,
> +					.value = 0x02,
> +					.gain = 1169,
> +					.gain2 = 1315,
>  				},
>  				[2] = {
>  					.num = ST_MAGN_FS_AVL_2500MG,
> -					.value = ST_MAGN_1_FS_AVL_2500_VAL,
> -					.gain = ST_MAGN_1_FS_AVL_2500_GAIN_XY,
> -					.gain2 = ST_MAGN_1_FS_AVL_2500_GAIN_Z,
> +					.value = 0x03,
> +					.gain = 1492,
> +					.gain2 = 1666,
>  				},
>  				[3] = {
>  					.num = ST_MAGN_FS_AVL_4000MG,
> -					.value = ST_MAGN_1_FS_AVL_4000_VAL,
> -					.gain = ST_MAGN_1_FS_AVL_4000_GAIN_XY,
> -					.gain2 = ST_MAGN_1_FS_AVL_4000_GAIN_Z,
> +					.value = 0x04,
> +					.gain = 2222,
> +					.gain2 = 2500,
>  				},
>  				[4] = {
>  					.num = ST_MAGN_FS_AVL_4700MG,
> -					.value = ST_MAGN_1_FS_AVL_4700_VAL,
> -					.gain = ST_MAGN_1_FS_AVL_4700_GAIN_XY,
> -					.gain2 = ST_MAGN_1_FS_AVL_4700_GAIN_Z,
> +					.value = 0x05,
> +					.gain = 2500,
> +					.gain2 = 2816,
>  				},
>  				[5] = {
>  					.num = ST_MAGN_FS_AVL_5600MG,
> -					.value = ST_MAGN_1_FS_AVL_5600_VAL,
> -					.gain = ST_MAGN_1_FS_AVL_5600_GAIN_XY,
> -					.gain2 = ST_MAGN_1_FS_AVL_5600_GAIN_Z,
> +					.value = 0x06,
> +					.gain = 3030,
> +					.gain2 = 3389,
>  				},
>  				[6] = {
>  					.num = ST_MAGN_FS_AVL_8100MG,
> -					.value = ST_MAGN_1_FS_AVL_8100_VAL,
> -					.gain = ST_MAGN_1_FS_AVL_8100_GAIN_XY,
> -					.gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z,
> +					.value = 0x07,
> +					.gain = 4347,
> +					.gain2 = 4878,
>  				},
>  			},
>  		},
> -		.multi_read_bit = ST_MAGN_1_MULTIREAD_BIT,
> +		.multi_read_bit = false,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_MAGN_2_WAI_EXP,
> +		.wai = 0x3d,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LIS3MDL_MAGN_DEV_NAME,
>  		},
>  		.ch = (struct iio_chan_spec *)st_magn_2_16bit_channels,
>  		.odr = {
> -			.addr = ST_MAGN_2_ODR_ADDR,
> -			.mask = ST_MAGN_2_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x1c,
>  			.odr_avl = {
> -				{ 1, ST_MAGN_2_ODR_AVL_1HZ_VAL, },
> -				{ 2, ST_MAGN_2_ODR_AVL_2HZ_VAL, },
> -				{ 3, ST_MAGN_2_ODR_AVL_3HZ_VAL, },
> -				{ 5, ST_MAGN_2_ODR_AVL_5HZ_VAL, },
> -				{ 10, ST_MAGN_2_ODR_AVL_10HZ_VAL, },
> -				{ 20, ST_MAGN_2_ODR_AVL_20HZ_VAL, },
> -				{ 40, ST_MAGN_2_ODR_AVL_40HZ_VAL, },
> -				{ 80, ST_MAGN_2_ODR_AVL_80HZ_VAL, },
> +				{ .hz = 1, .value = 0x00 },
> +				{ .hz = 2, .value = 0x01 },
> +				{ .hz = 3, .value = 0x02 },
> +				{ .hz = 5, .value = 0x03 },
> +				{ .hz = 10, .value = 0x04 },
> +				{ .hz = 20, .value = 0x05 },
> +				{ .hz = 40, .value = 0x06 },
> +				{ .hz = 80, .value = 0x07 },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_MAGN_2_PW_ADDR,
> -			.mask = ST_MAGN_2_PW_MASK,
> -			.value_on = ST_MAGN_2_PW_ON,
> -			.value_off = ST_MAGN_2_PW_OFF,
> +			.addr = 0x22,
> +			.mask = 0x03,
> +			.value_on = 0x00,
> +			.value_off = 0x03,
>  		},
>  		.fs = {
> -			.addr = ST_MAGN_2_FS_ADDR,
> -			.mask = ST_MAGN_2_FS_MASK,
> +			.addr = 0x21,
> +			.mask = 0x60,
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_MAGN_FS_AVL_4000MG,
> -					.value = ST_MAGN_2_FS_AVL_4000_VAL,
> -					.gain = ST_MAGN_2_FS_AVL_4000_GAIN,
> +					.value = 0x00,
> +					.gain = 146,
>  				},
>  				[1] = {
>  					.num = ST_MAGN_FS_AVL_8000MG,
> -					.value = ST_MAGN_2_FS_AVL_8000_VAL,
> -					.gain = ST_MAGN_2_FS_AVL_8000_GAIN,
> +					.value = 0x01,
> +					.gain = 292,
>  				},
>  				[2] = {
>  					.num = ST_MAGN_FS_AVL_12000MG,
> -					.value = ST_MAGN_2_FS_AVL_12000_VAL,
> -					.gain = ST_MAGN_2_FS_AVL_12000_GAIN,
> +					.value = 0x02,
> +					.gain = 438,
>  				},
>  				[3] = {
>  					.num = ST_MAGN_FS_AVL_16000MG,
> -					.value = ST_MAGN_2_FS_AVL_16000_VAL,
> -					.gain = ST_MAGN_2_FS_AVL_16000_GAIN,
> +					.value = 0x03,
> +					.gain = 584,
>  				},
>  			},
>  		},
> -		.multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
> +		.multi_read_bit = false,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_MAGN_3_WAI_EXP,
> -		.wai_addr = ST_MAGN_3_WAI_ADDR,
> +		.wai = 0x40,
> +		.wai_addr = 0x4f,
>  		.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,
> +			.addr = 0x60,
> +			.mask = 0x0c,
>  			.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, },
> +				{ .hz = 10, .value = 0x00 },
> +				{ .hz = 20, .value = 0x01 },
> +				{ .hz = 50, .value = 0x02 },
> +				{ .hz = 100, .value = 0x03 },
>  			},
>  		},
>  		.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,
> +			.addr = 0x60,
> +			.mask = 0x03,
> +			.value_on = 0x00,
> +			.value_off = 0x03,
>  		},
>  		.fs = {
>  			.fs_avl = {
>  				[0] = {
>  					.num = ST_MAGN_FS_AVL_15000MG,
> -					.gain = ST_MAGN_3_FS_AVL_15000_GAIN,
> +					.gain = 1500,
>  				},
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_MAGN_3_BDU_ADDR,
> -			.mask = ST_MAGN_3_BDU_MASK,
> +			.addr = 0x62,
> +			.mask = 0x10,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_MAGN_3_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_MAGN_3_DRDY_INT_MASK,
> -			.addr_ihl = ST_MAGN_3_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_MAGN_3_IHL_IRQ_MASK,
> +			.addr = 0x62,
> +			.mask_int1 = 0x01,
> +			.addr_ihl = 0x63,
> +			.mask_ihl = 0x04,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_MAGN_3_MULTIREAD_BIT,
> +		.multi_read_bit = false,
>  		.bootime = 2,
>  	},
>  };
> 


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

* Re: [PATCH 4/4] iio: pressure: st_pressure: inline per-sensor data
  2016-11-09 15:10 ` [PATCH 4/4] iio: pressure: st_pressure: " Linus Walleij
@ 2016-11-12 15:50   ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2016-11-12 15:50 UTC (permalink / raw)
  To: Linus Walleij, linux-iio
  Cc: Giuseppe Barba, Denis Ciocca, Gregor Boirie, Crestez Dan Leonard

On 09/11/16 15:10, Linus Walleij wrote:
> We have #defines for all the individual sensor registers and
> value/mask pairs #defined at the top of the file and used at
> exactly one spot.
> 
> This is usually good if the #defines give a meaning to the
> opaque magic numbers.
> 
> However in this case, the semantic meaning is inherent in the
> name of the C99-addressable fields, and that means duplication
> of information, and only makes the code hard to maintain since
> you every time have to add a new #define AND update the site
> where it is to be used.
> 
> Get rid of the #defines and just open code the values into the
> appropriate struct elements. Make sure to explicitly address
> the .hz and .value fields in the st_sensor_odr_avl struct
> so that the meaning of all values is clear.
> 
> This patch is purely syntactic should have no semantic effect.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Also good. Applied to the togreg branch of iio.git and pushed out
soon as testing for the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/pressure/st_pressure_core.c | 257 ++++++++++++--------------------
>  1 file changed, 92 insertions(+), 165 deletions(-)
> 
> diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
> index 55df9a75eb3a..e19e0787864c 100644
> --- a/drivers/iio/pressure/st_pressure_core.c
> +++ b/drivers/iio/pressure/st_pressure_core.c
> @@ -112,115 +112,24 @@
>  #define ST_PRESS_1_OUT_XL_ADDR			0x28
>  #define ST_TEMP_1_OUT_L_ADDR			0x2b
>  
> -/*
> - * CUSTOM VALUES FOR LPS331AP SENSOR
> - * See LPS331AP datasheet:
> - * http://www2.st.com/resource/en/datasheet/lps331ap.pdf
> - */
> -#define ST_PRESS_LPS331AP_WAI_EXP		0xbb
> -#define ST_PRESS_LPS331AP_ODR_ADDR		0x20
> -#define ST_PRESS_LPS331AP_ODR_MASK		0x70
> -#define ST_PRESS_LPS331AP_ODR_AVL_1HZ_VAL	0x01
> -#define ST_PRESS_LPS331AP_ODR_AVL_7HZ_VAL	0x05
> -#define ST_PRESS_LPS331AP_ODR_AVL_13HZ_VAL	0x06
> -#define ST_PRESS_LPS331AP_ODR_AVL_25HZ_VAL	0x07
> -#define ST_PRESS_LPS331AP_PW_ADDR		0x20
> -#define ST_PRESS_LPS331AP_PW_MASK		0x80
> -#define ST_PRESS_LPS331AP_FS_ADDR		0x23
> -#define ST_PRESS_LPS331AP_FS_MASK		0x30
> -#define ST_PRESS_LPS331AP_BDU_ADDR		0x20
> -#define ST_PRESS_LPS331AP_BDU_MASK		0x04
> -#define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR		0x22
> -#define ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK	0x04
> -#define ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK	0x20
> -#define ST_PRESS_LPS331AP_IHL_IRQ_ADDR		0x22
> -#define ST_PRESS_LPS331AP_IHL_IRQ_MASK		0x80
> -#define ST_PRESS_LPS331AP_OD_IRQ_ADDR		0x22
> -#define ST_PRESS_LPS331AP_OD_IRQ_MASK		0x40
> -#define ST_PRESS_LPS331AP_MULTIREAD_BIT		true
> -
> -/*
> - * CUSTOM VALUES FOR THE OBSOLETE LPS001WP SENSOR
> - */
> -
>  /* LPS001WP pressure resolution */
>  #define ST_PRESS_LPS001WP_LSB_PER_MBAR		16UL
>  /* LPS001WP temperature resolution */
>  #define ST_PRESS_LPS001WP_LSB_PER_CELSIUS	64UL
> -
> -#define ST_PRESS_LPS001WP_WAI_EXP		0xba
> -#define ST_PRESS_LPS001WP_ODR_ADDR		0x20
> -#define ST_PRESS_LPS001WP_ODR_MASK		0x30
> -#define ST_PRESS_LPS001WP_ODR_AVL_1HZ_VAL	0x01
> -#define ST_PRESS_LPS001WP_ODR_AVL_7HZ_VAL	0x02
> -#define ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL	0x03
> -#define ST_PRESS_LPS001WP_PW_ADDR		0x20
> -#define ST_PRESS_LPS001WP_PW_MASK		0x40
> +/* LPS001WP pressure gain */
>  #define ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN \
>  	(100000000UL / ST_PRESS_LPS001WP_LSB_PER_MBAR)
> -#define ST_PRESS_LPS001WP_BDU_ADDR		0x20
> -#define ST_PRESS_LPS001WP_BDU_MASK		0x04
> -#define ST_PRESS_LPS001WP_MULTIREAD_BIT		true
> +/* LPS001WP pressure and temp L addresses */
>  #define ST_PRESS_LPS001WP_OUT_L_ADDR		0x28
>  #define ST_TEMP_LPS001WP_OUT_L_ADDR		0x2a
>  
> -/*
> - * CUSTOM VALUES FOR LPS25H SENSOR
> - * See LPS25H datasheet:
> - * http://www2.st.com/resource/en/datasheet/lps25h.pdf
> - */
> -#define ST_PRESS_LPS25H_WAI_EXP			0xbd
> -#define ST_PRESS_LPS25H_ODR_ADDR		0x20
> -#define ST_PRESS_LPS25H_ODR_MASK		0x70
> -#define ST_PRESS_LPS25H_ODR_AVL_1HZ_VAL		0x01
> -#define ST_PRESS_LPS25H_ODR_AVL_7HZ_VAL		0x02
> -#define ST_PRESS_LPS25H_ODR_AVL_13HZ_VAL	0x03
> -#define ST_PRESS_LPS25H_ODR_AVL_25HZ_VAL	0x04
> -#define ST_PRESS_LPS25H_PW_ADDR			0x20
> -#define ST_PRESS_LPS25H_PW_MASK			0x80
> -#define ST_PRESS_LPS25H_BDU_ADDR		0x20
> -#define ST_PRESS_LPS25H_BDU_MASK		0x04
> -#define ST_PRESS_LPS25H_DRDY_IRQ_ADDR		0x23
> -#define ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK	0x01
> -#define ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK	0x10
> -#define ST_PRESS_LPS25H_IHL_IRQ_ADDR		0x22
> -#define ST_PRESS_LPS25H_IHL_IRQ_MASK		0x80
> -#define ST_PRESS_LPS25H_OD_IRQ_ADDR		0x22
> -#define ST_PRESS_LPS25H_OD_IRQ_MASK		0x40
> -#define ST_PRESS_LPS25H_MULTIREAD_BIT		true
> +/* LPS25H pressure and temp L addresses */
>  #define ST_PRESS_LPS25H_OUT_XL_ADDR		0x28
>  #define ST_TEMP_LPS25H_OUT_L_ADDR		0x2b
>  
> -/*
> - * CUSTOM VALUES FOR LPS22HB SENSOR
> - * See LPS22HB datasheet:
> - * http://www2.st.com/resource/en/datasheet/lps22hb.pdf
> - */
> -
>  /* LPS22HB temperature sensitivity */
>  #define ST_PRESS_LPS22HB_LSB_PER_CELSIUS	100UL
>  
> -#define ST_PRESS_LPS22HB_WAI_EXP		0xb1
> -#define ST_PRESS_LPS22HB_ODR_ADDR		0x10
> -#define ST_PRESS_LPS22HB_ODR_MASK		0x70
> -#define ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL	0x01
> -#define ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL	0x02
> -#define ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL	0x03
> -#define ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL	0x04
> -#define ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL	0x05
> -#define ST_PRESS_LPS22HB_PW_ADDR		0x10
> -#define ST_PRESS_LPS22HB_PW_MASK		0x70
> -#define ST_PRESS_LPS22HB_BDU_ADDR		0x10
> -#define ST_PRESS_LPS22HB_BDU_MASK		0x02
> -#define ST_PRESS_LPS22HB_DRDY_IRQ_ADDR		0x12
> -#define ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK	0x04
> -#define ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK	0x08
> -#define ST_PRESS_LPS22HB_IHL_IRQ_ADDR		0x12
> -#define ST_PRESS_LPS22HB_IHL_IRQ_MASK		0x80
> -#define ST_PRESS_LPS22HB_OD_IRQ_ADDR		0x12
> -#define ST_PRESS_LPS22HB_OD_IRQ_MASK		0x40
> -#define ST_PRESS_LPS22HB_MULTIREAD_BIT		true
> -
>  static const struct iio_chan_spec st_press_1_channels[] = {
>  	{
>  		.type = IIO_PRESSURE,
> @@ -321,7 +230,12 @@ static const struct iio_chan_spec st_press_lps22hb_channels[] = {
>  
>  static const struct st_sensor_settings st_press_sensors_settings[] = {
>  	{
> -		.wai = ST_PRESS_LPS331AP_WAI_EXP,
> +		/*
> +		 * CUSTOM VALUES FOR LPS331AP SENSOR
> +		 * See LPS331AP datasheet:
> +		 * http://www2.st.com/resource/en/datasheet/lps331ap.pdf
> +		 */
> +		.wai = 0xbb,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LPS331AP_PRESS_DEV_NAME,
> @@ -329,24 +243,24 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  		.ch = (struct iio_chan_spec *)st_press_1_channels,
>  		.num_ch = ARRAY_SIZE(st_press_1_channels),
>  		.odr = {
> -			.addr = ST_PRESS_LPS331AP_ODR_ADDR,
> -			.mask = ST_PRESS_LPS331AP_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x70,
>  			.odr_avl = {
> -				{ 1, ST_PRESS_LPS331AP_ODR_AVL_1HZ_VAL, },
> -				{ 7, ST_PRESS_LPS331AP_ODR_AVL_7HZ_VAL, },
> -				{ 13, ST_PRESS_LPS331AP_ODR_AVL_13HZ_VAL, },
> -				{ 25, ST_PRESS_LPS331AP_ODR_AVL_25HZ_VAL, },
> +				{ .hz = 1, .value = 0x01 },
> +				{ .hz = 7, .value = 0x05 },
> +				{ .hz = 13, .value = 0x06 },
> +				{ .hz = 25, .value = 0x07 },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_PRESS_LPS331AP_PW_ADDR,
> -			.mask = ST_PRESS_LPS331AP_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x80,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
>  		.fs = {
> -			.addr = ST_PRESS_LPS331AP_FS_ADDR,
> -			.mask = ST_PRESS_LPS331AP_FS_MASK,
> +			.addr = 0x23,
> +			.mask = 0x30,
>  			.fs_avl = {
>  				/*
>  				 * Pressure and temperature sensitivity values
> @@ -360,24 +274,27 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_PRESS_LPS331AP_BDU_ADDR,
> -			.mask = ST_PRESS_LPS331AP_BDU_MASK,
> +			.addr = 0x20,
> +			.mask = 0x04,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_PRESS_LPS331AP_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_PRESS_LPS331AP_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_PRESS_LPS331AP_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_PRESS_LPS331AP_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_PRESS_LPS331AP_IHL_IRQ_MASK,
> -			.addr_od = ST_PRESS_LPS331AP_OD_IRQ_ADDR,
> -			.mask_od = ST_PRESS_LPS331AP_OD_IRQ_MASK,
> +			.addr = 0x22,
> +			.mask_int1 = 0x04,
> +			.mask_int2 = 0x20,
> +			.addr_ihl = 0x22,
> +			.mask_ihl = 0x80,
> +			.addr_od = 0x22,
> +			.mask_od = 0x40,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_PRESS_LPS331AP_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_PRESS_LPS001WP_WAI_EXP,
> +		/*
> +		 * CUSTOM VALUES FOR LPS001WP SENSOR
> +		 */
> +		.wai = 0xba,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LPS001WP_PRESS_DEV_NAME,
> @@ -385,17 +302,17 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  		.ch = (struct iio_chan_spec *)st_press_lps001wp_channels,
>  		.num_ch = ARRAY_SIZE(st_press_lps001wp_channels),
>  		.odr = {
> -			.addr = ST_PRESS_LPS001WP_ODR_ADDR,
> -			.mask = ST_PRESS_LPS001WP_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x30,
>  			.odr_avl = {
> -				{ 1, ST_PRESS_LPS001WP_ODR_AVL_1HZ_VAL, },
> -				{ 7, ST_PRESS_LPS001WP_ODR_AVL_7HZ_VAL, },
> -				{ 13, ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL, },
> +				{ .hz = 1, .value = 0x01 },
> +				{ .hz = 7, .value = 0x02 },
> +				{ .hz = 13, .value = 0x03 },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_PRESS_LPS001WP_PW_ADDR,
> -			.mask = ST_PRESS_LPS001WP_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x40,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -413,17 +330,22 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_PRESS_LPS001WP_BDU_ADDR,
> -			.mask = ST_PRESS_LPS001WP_BDU_MASK,
> +			.addr = 0x20,
> +			.mask = 0x04,
>  		},
>  		.drdy_irq = {
>  			.addr = 0,
>  		},
> -		.multi_read_bit = ST_PRESS_LPS001WP_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_PRESS_LPS25H_WAI_EXP,
> +		/*
> +		 * CUSTOM VALUES FOR LPS25H SENSOR
> +		 * See LPS25H datasheet:
> +		 * http://www2.st.com/resource/en/datasheet/lps25h.pdf
> +		 */
> +		.wai = 0xbd,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LPS25H_PRESS_DEV_NAME,
> @@ -431,18 +353,18 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  		.ch = (struct iio_chan_spec *)st_press_1_channels,
>  		.num_ch = ARRAY_SIZE(st_press_1_channels),
>  		.odr = {
> -			.addr = ST_PRESS_LPS25H_ODR_ADDR,
> -			.mask = ST_PRESS_LPS25H_ODR_MASK,
> +			.addr = 0x20,
> +			.mask = 0x70,
>  			.odr_avl = {
> -				{ 1, ST_PRESS_LPS25H_ODR_AVL_1HZ_VAL, },
> -				{ 7, ST_PRESS_LPS25H_ODR_AVL_7HZ_VAL, },
> -				{ 13, ST_PRESS_LPS25H_ODR_AVL_13HZ_VAL, },
> -				{ 25, ST_PRESS_LPS25H_ODR_AVL_25HZ_VAL, },
> +				{ .hz = 1, .value = 0x01 },
> +				{ .hz = 7, .value = 0x02 },
> +				{ .hz = 13, .value = 0x03 },
> +				{ .hz = 25, .value = 0x04 },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_PRESS_LPS25H_PW_ADDR,
> -			.mask = ST_PRESS_LPS25H_PW_MASK,
> +			.addr = 0x20,
> +			.mask = 0x80,
>  			.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
> @@ -460,24 +382,29 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_PRESS_LPS25H_BDU_ADDR,
> -			.mask = ST_PRESS_LPS25H_BDU_MASK,
> +			.addr = 0x20,
> +			.mask = 0x04,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_PRESS_LPS25H_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_PRESS_LPS25H_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_PRESS_LPS25H_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_PRESS_LPS25H_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_PRESS_LPS25H_IHL_IRQ_MASK,
> -			.addr_od = ST_PRESS_LPS25H_OD_IRQ_ADDR,
> -			.mask_od = ST_PRESS_LPS25H_OD_IRQ_MASK,
> +			.addr = 0x23,
> +			.mask_int1 = 0x01,
> +			.mask_int2 = 0x10,
> +			.addr_ihl = 0x22,
> +			.mask_ihl = 0x80,
> +			.addr_od = 0x22,
> +			.mask_od = 0x40,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  		.bootime = 2,
>  	},
>  	{
> -		.wai = ST_PRESS_LPS22HB_WAI_EXP,
> +		/*
> +		 * CUSTOM VALUES FOR LPS22HB SENSOR
> +		 * See LPS22HB datasheet:
> +		 * http://www2.st.com/resource/en/datasheet/lps22hb.pdf
> +		 */
> +		.wai = 0xb1,
>  		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
>  		.sensors_supported = {
>  			[0] = LPS22HB_PRESS_DEV_NAME,
> @@ -485,19 +412,19 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  		.ch = (struct iio_chan_spec *)st_press_lps22hb_channels,
>  		.num_ch = ARRAY_SIZE(st_press_lps22hb_channels),
>  		.odr = {
> -			.addr = ST_PRESS_LPS22HB_ODR_ADDR,
> -			.mask = ST_PRESS_LPS22HB_ODR_MASK,
> +			.addr = 0x10,
> +			.mask = 0x70,
>  			.odr_avl = {
> -				{ 1, ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL, },
> -				{ 10, ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL, },
> -				{ 25, ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL, },
> -				{ 50, ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL, },
> -				{ 75, ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL, },
> +				{ .hz = 1, .value = 0x01 },
> +				{ .hz = 10, .value = 0x02 },
> +				{ .hz = 25, .value = 0x03 },
> +				{ .hz = 50, .value = 0x04 },
> +				{ .hz = 75, .value = 0x05 },
>  			},
>  		},
>  		.pw = {
> -			.addr = ST_PRESS_LPS22HB_PW_ADDR,
> -			.mask = ST_PRESS_LPS22HB_PW_MASK,
> +			.addr = 0x10,
> +			.mask = 0x70,
>  			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
>  		},
>  		.fs = {
> @@ -514,20 +441,20 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
>  			},
>  		},
>  		.bdu = {
> -			.addr = ST_PRESS_LPS22HB_BDU_ADDR,
> -			.mask = ST_PRESS_LPS22HB_BDU_MASK,
> +			.addr = 0x10,
> +			.mask = 0x02,
>  		},
>  		.drdy_irq = {
> -			.addr = ST_PRESS_LPS22HB_DRDY_IRQ_ADDR,
> -			.mask_int1 = ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK,
> -			.mask_int2 = ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK,
> -			.addr_ihl = ST_PRESS_LPS22HB_IHL_IRQ_ADDR,
> -			.mask_ihl = ST_PRESS_LPS22HB_IHL_IRQ_MASK,
> -			.addr_od = ST_PRESS_LPS22HB_OD_IRQ_ADDR,
> -			.mask_od = ST_PRESS_LPS22HB_OD_IRQ_MASK,
> +			.addr = 0x12,
> +			.mask_int1 = 0x04,
> +			.mask_int2 = 0x08,
> +			.addr_ihl = 0x12,
> +			.mask_ihl = 0x80,
> +			.addr_od = 0x12,
> +			.mask_od = 0x40,
>  			.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
>  		},
> -		.multi_read_bit = ST_PRESS_LPS22HB_MULTIREAD_BIT,
> +		.multi_read_bit = true,
>  	},
>  };
>  
> 


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

end of thread, other threads:[~2016-11-12 15:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-09 15:09 [PATCH 0/4] ST Sensors: inline sensor data Linus Walleij
2016-11-09 15:09 ` [PATCH 1/4] iio: accel: st_accel: inline per-sensor data Linus Walleij
2016-11-12 15:29   ` Jonathan Cameron
2016-11-12 15:34     ` Jonathan Cameron
2016-11-09 15:09 ` [PATCH 2/4] iio: gyro: st_gyro: " Linus Walleij
2016-11-12 15:38   ` Jonathan Cameron
2016-11-09 15:09 ` [PATCH 3/4] iio: magn: st_magn: " Linus Walleij
2016-11-12 15:45   ` Jonathan Cameron
2016-11-09 15:10 ` [PATCH 4/4] iio: pressure: st_pressure: " Linus Walleij
2016-11-12 15:50   ` 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.