Commit d8594fa2 authored by Linus Walleij's avatar Linus Walleij Committed by Jonathan Cameron

iio: gyro: st_gyro: inline per-sensor data

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: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 08f3ffce
...@@ -39,79 +39,6 @@ ...@@ -39,79 +39,6 @@
#define ST_GYRO_FS_AVL_500DPS 500 #define ST_GYRO_FS_AVL_500DPS 500
#define ST_GYRO_FS_AVL_2000DPS 2000 #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[] = { static const struct iio_chan_spec st_gyro_16bit_channels[] = {
ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL,
BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
...@@ -130,7 +57,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = { ...@@ -130,7 +57,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
static const struct st_sensor_settings st_gyro_sensors_settings[] = { 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, .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
.sensors_supported = { .sensors_supported = {
[0] = L3G4200D_GYRO_DEV_NAME, [0] = L3G4200D_GYRO_DEV_NAME,
...@@ -138,18 +65,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -138,18 +65,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
}, },
.ch = (struct iio_chan_spec *)st_gyro_16bit_channels, .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
.odr = { .odr = {
.addr = ST_GYRO_1_ODR_ADDR, .addr = 0x20,
.mask = ST_GYRO_1_ODR_MASK, .mask = 0xc0,
.odr_avl = { .odr_avl = {
{ 100, ST_GYRO_1_ODR_AVL_100HZ_VAL, }, { .hz = 100, .value = 0x00, },
{ 200, ST_GYRO_1_ODR_AVL_200HZ_VAL, }, { .hz = 200, .value = 0x01, },
{ 400, ST_GYRO_1_ODR_AVL_400HZ_VAL, }, { .hz = 400, .value = 0x02, },
{ 800, ST_GYRO_1_ODR_AVL_800HZ_VAL, }, { .hz = 800, .value = 0x03, },
}, },
}, },
.pw = { .pw = {
.addr = ST_GYRO_1_PW_ADDR, .addr = 0x20,
.mask = ST_GYRO_1_PW_MASK, .mask = 0x08,
.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
}, },
...@@ -158,33 +85,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -158,33 +85,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
.mask = ST_SENSORS_DEFAULT_AXIS_MASK, .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
}, },
.fs = { .fs = {
.addr = ST_GYRO_1_FS_ADDR, .addr = 0x23,
.mask = ST_GYRO_1_FS_MASK, .mask = 0x30,
.fs_avl = { .fs_avl = {
[0] = { [0] = {
.num = ST_GYRO_FS_AVL_250DPS, .num = ST_GYRO_FS_AVL_250DPS,
.value = ST_GYRO_1_FS_AVL_250_VAL, .value = 0x00,
.gain = ST_GYRO_1_FS_AVL_250_GAIN, .gain = IIO_DEGREE_TO_RAD(8750),
}, },
[1] = { [1] = {
.num = ST_GYRO_FS_AVL_500DPS, .num = ST_GYRO_FS_AVL_500DPS,
.value = ST_GYRO_1_FS_AVL_500_VAL, .value = 0x01,
.gain = ST_GYRO_1_FS_AVL_500_GAIN, .gain = IIO_DEGREE_TO_RAD(17500),
}, },
[2] = { [2] = {
.num = ST_GYRO_FS_AVL_2000DPS, .num = ST_GYRO_FS_AVL_2000DPS,
.value = ST_GYRO_1_FS_AVL_2000_VAL, .value = 0x02,
.gain = ST_GYRO_1_FS_AVL_2000_GAIN, .gain = IIO_DEGREE_TO_RAD(70000),
}, },
}, },
}, },
.bdu = { .bdu = {
.addr = ST_GYRO_1_BDU_ADDR, .addr = 0x23,
.mask = ST_GYRO_1_BDU_MASK, .mask = 0x80,
}, },
.drdy_irq = { .drdy_irq = {
.addr = ST_GYRO_1_DRDY_IRQ_ADDR, .addr = 0x22,
.mask_int2 = ST_GYRO_1_DRDY_IRQ_INT2_MASK, .mask_int2 = 0x08,
/* /*
* The sensor has IHL (active low) and open * The sensor has IHL (active low) and open
* drain settings, but only for INT1 and not * drain settings, but only for INT1 and not
...@@ -192,11 +119,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -192,11 +119,11 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
*/ */
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
}, },
.multi_read_bit = ST_GYRO_1_MULTIREAD_BIT, .multi_read_bit = true,
.bootime = 2, .bootime = 2,
}, },
{ {
.wai = ST_GYRO_2_WAI_EXP, .wai = 0xd4,
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
.sensors_supported = { .sensors_supported = {
[0] = L3GD20_GYRO_DEV_NAME, [0] = L3GD20_GYRO_DEV_NAME,
...@@ -208,18 +135,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -208,18 +135,18 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
}, },
.ch = (struct iio_chan_spec *)st_gyro_16bit_channels, .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
.odr = { .odr = {
.addr = ST_GYRO_2_ODR_ADDR, .addr = 0x20,
.mask = ST_GYRO_2_ODR_MASK, .mask = 0xc0,
.odr_avl = { .odr_avl = {
{ 95, ST_GYRO_2_ODR_AVL_95HZ_VAL, }, { .hz = 95, .value = 0x00, },
{ 190, ST_GYRO_2_ODR_AVL_190HZ_VAL, }, { .hz = 190, .value = 0x01, },
{ 380, ST_GYRO_2_ODR_AVL_380HZ_VAL, }, { .hz = 380, .value = 0x02, },
{ 760, ST_GYRO_2_ODR_AVL_760HZ_VAL, }, { .hz = 760, .value = 0x03, },
}, },
}, },
.pw = { .pw = {
.addr = ST_GYRO_2_PW_ADDR, .addr = 0x20,
.mask = ST_GYRO_2_PW_MASK, .mask = 0x08,
.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
}, },
...@@ -228,33 +155,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -228,33 +155,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
.mask = ST_SENSORS_DEFAULT_AXIS_MASK, .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
}, },
.fs = { .fs = {
.addr = ST_GYRO_2_FS_ADDR, .addr = 0x23,
.mask = ST_GYRO_2_FS_MASK, .mask = 0x30,
.fs_avl = { .fs_avl = {
[0] = { [0] = {
.num = ST_GYRO_FS_AVL_250DPS, .num = ST_GYRO_FS_AVL_250DPS,
.value = ST_GYRO_2_FS_AVL_250_VAL, .value = 0x00,
.gain = ST_GYRO_2_FS_AVL_250_GAIN, .gain = IIO_DEGREE_TO_RAD(8750),
}, },
[1] = { [1] = {
.num = ST_GYRO_FS_AVL_500DPS, .num = ST_GYRO_FS_AVL_500DPS,
.value = ST_GYRO_2_FS_AVL_500_VAL, .value = 0x01,
.gain = ST_GYRO_2_FS_AVL_500_GAIN, .gain = IIO_DEGREE_TO_RAD(17500),
}, },
[2] = { [2] = {
.num = ST_GYRO_FS_AVL_2000DPS, .num = ST_GYRO_FS_AVL_2000DPS,
.value = ST_GYRO_2_FS_AVL_2000_VAL, .value = 0x02,
.gain = ST_GYRO_2_FS_AVL_2000_GAIN, .gain = IIO_DEGREE_TO_RAD(70000),
}, },
}, },
}, },
.bdu = { .bdu = {
.addr = ST_GYRO_2_BDU_ADDR, .addr = 0x23,
.mask = ST_GYRO_2_BDU_MASK, .mask = 0x80,
}, },
.drdy_irq = { .drdy_irq = {
.addr = ST_GYRO_2_DRDY_IRQ_ADDR, .addr = 0x22,
.mask_int2 = ST_GYRO_2_DRDY_IRQ_INT2_MASK, .mask_int2 = 0x08,
/* /*
* The sensor has IHL (active low) and open * The sensor has IHL (active low) and open
* drain settings, but only for INT1 and not * drain settings, but only for INT1 and not
...@@ -262,29 +189,29 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -262,29 +189,29 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
*/ */
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
}, },
.multi_read_bit = ST_GYRO_2_MULTIREAD_BIT, .multi_read_bit = true,
.bootime = 2, .bootime = 2,
}, },
{ {
.wai = ST_GYRO_3_WAI_EXP, .wai = 0xd7,
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
.sensors_supported = { .sensors_supported = {
[0] = L3GD20_GYRO_DEV_NAME, [0] = L3GD20_GYRO_DEV_NAME,
}, },
.ch = (struct iio_chan_spec *)st_gyro_16bit_channels, .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
.odr = { .odr = {
.addr = ST_GYRO_3_ODR_ADDR, .addr = 0x20,
.mask = ST_GYRO_3_ODR_MASK, .mask = 0xc0,
.odr_avl = { .odr_avl = {
{ 95, ST_GYRO_3_ODR_AVL_95HZ_VAL, }, { .hz = 95, .value = 0x00, },
{ 190, ST_GYRO_3_ODR_AVL_190HZ_VAL, }, { .hz = 190, .value = 0x01, },
{ 380, ST_GYRO_3_ODR_AVL_380HZ_VAL, }, { .hz = 380, .value = 0x02, },
{ 760, ST_GYRO_3_ODR_AVL_760HZ_VAL, }, { .hz = 760, .value = 0x03, },
}, },
}, },
.pw = { .pw = {
.addr = ST_GYRO_3_PW_ADDR, .addr = 0x20,
.mask = ST_GYRO_3_PW_MASK, .mask = 0x08,
.value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE, .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE, .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
}, },
...@@ -293,33 +220,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -293,33 +220,33 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
.mask = ST_SENSORS_DEFAULT_AXIS_MASK, .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
}, },
.fs = { .fs = {
.addr = ST_GYRO_3_FS_ADDR, .addr = 0x23,
.mask = ST_GYRO_3_FS_MASK, .mask = 0x30,
.fs_avl = { .fs_avl = {
[0] = { [0] = {
.num = ST_GYRO_FS_AVL_250DPS, .num = ST_GYRO_FS_AVL_250DPS,
.value = ST_GYRO_3_FS_AVL_250_VAL, .value = 0x00,
.gain = ST_GYRO_3_FS_AVL_250_GAIN, .gain = IIO_DEGREE_TO_RAD(8750),
}, },
[1] = { [1] = {
.num = ST_GYRO_FS_AVL_500DPS, .num = ST_GYRO_FS_AVL_500DPS,
.value = ST_GYRO_3_FS_AVL_500_VAL, .value = 0x01,
.gain = ST_GYRO_3_FS_AVL_500_GAIN, .gain = IIO_DEGREE_TO_RAD(17500),
}, },
[2] = { [2] = {
.num = ST_GYRO_FS_AVL_2000DPS, .num = ST_GYRO_FS_AVL_2000DPS,
.value = ST_GYRO_3_FS_AVL_2000_VAL, .value = 0x02,
.gain = ST_GYRO_3_FS_AVL_2000_GAIN, .gain = IIO_DEGREE_TO_RAD(70000),
}, },
}, },
}, },
.bdu = { .bdu = {
.addr = ST_GYRO_3_BDU_ADDR, .addr = 0x23,
.mask = ST_GYRO_3_BDU_MASK, .mask = 0x80,
}, },
.drdy_irq = { .drdy_irq = {
.addr = ST_GYRO_3_DRDY_IRQ_ADDR, .addr = 0x22,
.mask_int2 = ST_GYRO_3_DRDY_IRQ_INT2_MASK, .mask_int2 = 0x08,
/* /*
* The sensor has IHL (active low) and open * The sensor has IHL (active low) and open
* drain settings, but only for INT1 and not * drain settings, but only for INT1 and not
...@@ -327,7 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = { ...@@ -327,7 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
*/ */
.addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR,
}, },
.multi_read_bit = ST_GYRO_3_MULTIREAD_BIT, .multi_read_bit = true,
.bootime = 2, .bootime = 2,
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment