Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: accel: adxl345: Implement event scaling for ABI compliance

The ADXL345 uses a fixed threshold resolution of 62.5 mg/LSB for
event-related registers. Previously, the driver reported raw
values without a scale factor.

Implement IIO_EV_INFO_SCALE for all event types to provide the
conversion factor (0.612915 m/s^2) as required by the IIO ABI.

Consequently, remove the obsolete comment in adxl345_read_event_value()
which stated that the scale factor is not applied.

Add explicit write rejection for IIO_EV_INFO_SCALE in
adxl345_write_event_value() returning -EINVAL.

Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Taha Ed-Dafili and committed by
Jonathan Cameron
9fb00770 da29db0b

+21 -7
+21 -7
drivers/iio/accel/adxl345_core.c
··· 213 213 .dir = IIO_EV_DIR_RISING, 214 214 .mask_shared_by_type = 215 215 BIT(IIO_EV_INFO_ENABLE) | 216 + BIT(IIO_EV_INFO_SCALE) | 216 217 BIT(IIO_EV_INFO_VALUE), 217 218 }, 218 219 { ··· 222 221 .dir = IIO_EV_DIR_RISING, 223 222 .mask_shared_by_type = 224 223 BIT(IIO_EV_INFO_ENABLE) | 224 + BIT(IIO_EV_INFO_SCALE) | 225 225 BIT(IIO_EV_INFO_VALUE), 226 226 }, 227 227 { ··· 230 228 .type = IIO_EV_TYPE_GESTURE, 231 229 .dir = IIO_EV_DIR_SINGLETAP, 232 230 .mask_separate = BIT(IIO_EV_INFO_ENABLE), 233 - .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 231 + .mask_shared_by_type = 232 + BIT(IIO_EV_INFO_SCALE) | 233 + BIT(IIO_EV_INFO_VALUE) | 234 234 BIT(IIO_EV_INFO_TIMEOUT), 235 235 }, 236 236 { ··· 241 237 .dir = IIO_EV_DIR_DOUBLETAP, 242 238 .mask_shared_by_type = 243 239 BIT(IIO_EV_INFO_ENABLE) | 240 + BIT(IIO_EV_INFO_SCALE) | 244 241 BIT(IIO_EV_INFO_VALUE) | 245 242 BIT(IIO_EV_INFO_RESET_TIMEOUT) | 246 243 BIT(IIO_EV_INFO_TAP2_MIN_DELAY), ··· 281 276 .dir = IIO_EV_DIR_FALLING, 282 277 .mask_separate = BIT(IIO_EV_INFO_ENABLE), 283 278 .mask_shared_by_type = 279 + BIT(IIO_EV_INFO_SCALE) | 284 280 BIT(IIO_EV_INFO_VALUE) | 285 281 BIT(IIO_EV_INFO_PERIOD), 286 282 }, ··· 291 285 .dir = IIO_EV_DIR_FALLING, 292 286 .mask_separate = BIT(IIO_EV_INFO_ENABLE), 293 287 .mask_shared_by_type = 288 + BIT(IIO_EV_INFO_SCALE) | 294 289 BIT(IIO_EV_INFO_VALUE) | 295 290 BIT(IIO_EV_INFO_PERIOD), 296 291 }, ··· 1350 1343 unsigned int tap_threshold; 1351 1344 int ret; 1352 1345 1346 + /* 1347 + * The event threshold LSB is fixed at 62.5 mg/LSB 1348 + * 0.0625 * 9.80665 = 0.612915625 m/s^2 1349 + */ 1350 + if (info == IIO_EV_INFO_SCALE) { 1351 + *val = 0; 1352 + *val2 = 612915; 1353 + return IIO_VAL_INT_PLUS_MICRO; 1354 + } 1355 + 1353 1356 switch (type) { 1354 1357 case IIO_EV_TYPE_MAG: 1355 1358 return adxl345_read_mag_value(st, dir, info, ··· 1374 1357 case IIO_EV_TYPE_GESTURE: 1375 1358 switch (info) { 1376 1359 case IIO_EV_INFO_VALUE: 1377 - /* 1378 - * The scale factor would be 62.5mg/LSB (i.e. 0xFF = 16g) but 1379 - * not applied here. In context of this general purpose sensor, 1380 - * what imports is rather signal intensity than the absolute 1381 - * measured g value. 1382 - */ 1383 1360 ret = regmap_read(st->regmap, ADXL345_REG_THRESH_TAP, 1384 1361 &tap_threshold); 1385 1362 if (ret) ··· 1413 1402 ret = adxl345_set_measure_en(st, false); 1414 1403 if (ret) 1415 1404 return ret; 1405 + 1406 + if (info == IIO_EV_INFO_SCALE) 1407 + return -EINVAL; 1416 1408 1417 1409 switch (type) { 1418 1410 case IIO_EV_TYPE_MAG: