Skip to content

Commit bc27381

Browse files
gbarba-stmjic23
authored andcommitted
iio: st-sensors: add configuration for WhoAmI address
This patch permits to configure the WhoAmI register address because some device could have not a standard address for this register. Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com> Reviewed-by: Denis Ciocca <denis.ciocca@st.com> Acked-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent c176bec commit bc27381

6 files changed

Lines changed: 39 additions & 26 deletions

File tree

‎drivers/iio/accel/st_accel_core.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
226226
static const struct st_sensor_settings st_accel_sensors_settings[] = {
227227
{
228228
.wai = ST_ACCEL_1_WAI_EXP,
229+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
229230
.sensors_supported = {
230231
[0] = LIS3DH_ACCEL_DEV_NAME,
231232
[1] = LSM303DLHC_ACCEL_DEV_NAME,
@@ -297,6 +298,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
297298
},
298299
{
299300
.wai = ST_ACCEL_2_WAI_EXP,
301+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
300302
.sensors_supported = {
301303
[0] = LIS331DLH_ACCEL_DEV_NAME,
302304
[1] = LSM303DL_ACCEL_DEV_NAME,
@@ -359,6 +361,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
359361
},
360362
{
361363
.wai = ST_ACCEL_3_WAI_EXP,
364+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
362365
.sensors_supported = {
363366
[0] = LSM330_ACCEL_DEV_NAME,
364367
},
@@ -437,6 +440,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
437440
},
438441
{
439442
.wai = ST_ACCEL_4_WAI_EXP,
443+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
440444
.sensors_supported = {
441445
[0] = LIS3LV02DL_ACCEL_DEV_NAME,
442446
},
@@ -494,6 +498,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
494498
},
495499
{
496500
.wai = ST_ACCEL_5_WAI_EXP,
501+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
497502
.sensors_supported = {
498503
[0] = LIS331DL_ACCEL_DEV_NAME,
499504
},

‎drivers/iio/common/st_sensors/st_sensors_core.c‎

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -479,46 +479,43 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
479479
int num_sensors_list,
480480
const struct st_sensor_settings *sensor_settings)
481481
{
482-
u8 wai;
483482
int i, n, err;
483+
u8 wai;
484484
struct st_sensor_data *sdata = iio_priv(indio_dev);
485485

486-
err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
487-
ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
488-
if (err < 0) {
489-
dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
490-
goto read_wai_error;
491-
}
492-
493486
for (i = 0; i < num_sensors_list; i++) {
494-
if (sensor_settings[i].wai == wai)
487+
for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
488+
if (strcmp(indio_dev->name,
489+
sensor_settings[i].sensors_supported[n]) == 0) {
490+
break;
491+
}
492+
}
493+
if (n < ST_SENSORS_MAX_4WAI)
495494
break;
496495
}
497-
if (i == num_sensors_list)
498-
goto device_not_supported;
496+
if (i == num_sensors_list) {
497+
dev_err(&indio_dev->dev, "device name %s not recognized.\n",
498+
indio_dev->name);
499+
return -ENODEV;
500+
}
499501

500-
for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported); n++) {
501-
if (strcmp(indio_dev->name,
502-
&sensor_settings[i].sensors_supported[n][0]) == 0)
503-
break;
502+
err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
503+
sensor_settings[i].wai_addr, &wai);
504+
if (err < 0) {
505+
dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
506+
return err;
504507
}
505-
if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) {
506-
dev_err(&indio_dev->dev, "device name \"%s\" and WhoAmI (0x%02x) mismatch",
507-
indio_dev->name, wai);
508-
goto sensor_name_mismatch;
508+
509+
if (sensor_settings[i].wai != wai) {
510+
dev_err(&indio_dev->dev, "%s: WhoAmI mismatch (0x%x).\n",
511+
indio_dev->name, wai);
512+
return -EINVAL;
509513
}
510514

511515
sdata->sensor_settings =
512516
(struct st_sensor_settings *)&sensor_settings[i];
513517

514518
return i;
515-
516-
device_not_supported:
517-
dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai);
518-
sensor_name_mismatch:
519-
err = -ENODEV;
520-
read_wai_error:
521-
return err;
522519
}
523520
EXPORT_SYMBOL(st_sensors_check_device_support);
524521

‎drivers/iio/gyro/st_gyro_core.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
131131
static const struct st_sensor_settings st_gyro_sensors_settings[] = {
132132
{
133133
.wai = ST_GYRO_1_WAI_EXP,
134+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
134135
.sensors_supported = {
135136
[0] = L3G4200D_GYRO_DEV_NAME,
136137
[1] = LSM330DL_GYRO_DEV_NAME,
@@ -190,6 +191,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
190191
},
191192
{
192193
.wai = ST_GYRO_2_WAI_EXP,
194+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
193195
.sensors_supported = {
194196
[0] = L3GD20_GYRO_DEV_NAME,
195197
[1] = LSM330D_GYRO_DEV_NAME,
@@ -252,6 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
252254
},
253255
{
254256
.wai = ST_GYRO_3_WAI_EXP,
257+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
255258
.sensors_supported = {
256259
[0] = L3GD20_GYRO_DEV_NAME,
257260
},

‎drivers/iio/magnetometer/st_magn_core.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
192192
static const struct st_sensor_settings st_magn_sensors_settings[] = {
193193
{
194194
.wai = 0, /* This sensor has no valid WhoAmI report 0 */
195+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
195196
.sensors_supported = {
196197
[0] = LSM303DLH_MAGN_DEV_NAME,
197198
},
@@ -268,6 +269,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
268269
},
269270
{
270271
.wai = ST_MAGN_1_WAI_EXP,
272+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
271273
.sensors_supported = {
272274
[0] = LSM303DLHC_MAGN_DEV_NAME,
273275
[1] = LSM303DLM_MAGN_DEV_NAME,
@@ -346,6 +348,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
346348
},
347349
{
348350
.wai = ST_MAGN_2_WAI_EXP,
351+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
349352
.sensors_supported = {
350353
[0] = LIS3MDL_MAGN_DEV_NAME,
351354
},

‎drivers/iio/pressure/st_pressure_core.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
178178
static const struct st_sensor_settings st_press_sensors_settings[] = {
179179
{
180180
.wai = ST_PRESS_LPS331AP_WAI_EXP,
181+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
181182
.sensors_supported = {
182183
[0] = LPS331AP_PRESS_DEV_NAME,
183184
},
@@ -225,6 +226,7 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
225226
},
226227
{
227228
.wai = ST_PRESS_LPS001WP_WAI_EXP,
229+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
228230
.sensors_supported = {
229231
[0] = LPS001WP_PRESS_DEV_NAME,
230232
},
@@ -260,6 +262,7 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
260262
},
261263
{
262264
.wai = ST_PRESS_LPS25H_WAI_EXP,
265+
.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
263266
.sensors_supported = {
264267
[0] = LPS25H_PRESS_DEV_NAME,
265268
},

‎include/linux/iio/common/st_sensors.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct st_sensor_transfer_function {
166166
/**
167167
* struct st_sensor_settings - ST specific sensor settings
168168
* @wai: Contents of WhoAmI register.
169+
* @wai_addr: The address of WhoAmI register.
169170
* @sensors_supported: List of supported sensors by struct itself.
170171
* @ch: IIO channels for the sensor.
171172
* @odr: Output data rate register and ODR list available.
@@ -179,6 +180,7 @@ struct st_sensor_transfer_function {
179180
*/
180181
struct st_sensor_settings {
181182
u8 wai;
183+
u8 wai_addr;
182184
char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
183185
struct iio_chan_spec *ch;
184186
int num_ch;

0 commit comments

Comments
 (0)