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

iio: accel: adxl345: Simplify adxl345_read_raw()

Simplify adxl345_read_raw() by adding uscale variable to
struct adxl345_chip_info. Also convert variables adxl3{4,7}5_uscale to
macros and use it in OF/ACPI/ID match table.

Drop enum adxl345_device_type as there is no user.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230903090051.39274-3-biju.das.jz@bp.renesas.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Biju Das and committed by
Jonathan Cameron
dcc3ac13 7d0ba6db

+20 -33
+15 -5
drivers/iio/accel/adxl345.h
··· 8 8 #ifndef _ADXL345_H_ 9 9 #define _ADXL345_H_ 10 10 11 - enum adxl345_device_type { 12 - ADXL345 = 1, 13 - ADXL375 = 2, 14 - }; 11 + /* 12 + * In full-resolution mode, scale factor is maintained at ~4 mg/LSB 13 + * in all g ranges. 14 + * 15 + * At +/- 16g with 13-bit resolution, scale is computed as: 16 + * (16 + 16) * 9.81 / (2^13 - 1) = 0.0383 17 + */ 18 + #define ADXL345_USCALE 38300 19 + 20 + /* 21 + * The Datasheet lists a resolution of Resolution is ~49 mg per LSB. That's 22 + * ~480mm/s**2 per LSB. 23 + */ 24 + #define ADXL375_USCALE 480000 15 25 16 26 struct adxl345_chip_info { 17 27 const char *name; 18 - unsigned int type; 28 + int uscale; 19 29 }; 20 30 21 31 int adxl345_core_probe(struct device *dev, struct regmap *regmap);
+1 -24
drivers/iio/accel/adxl345_core.c
··· 45 45 46 46 #define ADXL345_DEVID 0xE5 47 47 48 - /* 49 - * In full-resolution mode, scale factor is maintained at ~4 mg/LSB 50 - * in all g ranges. 51 - * 52 - * At +/- 16g with 13-bit resolution, scale is computed as: 53 - * (16 + 16) * 9.81 / (2^13 - 1) = 0.0383 54 - */ 55 - static const int adxl345_uscale = 38300; 56 - 57 - /* 58 - * The Datasheet lists a resolution of Resolution is ~49 mg per LSB. That's 59 - * ~480mm/s**2 per LSB. 60 - */ 61 - static const int adxl375_uscale = 480000; 62 - 63 48 struct adxl345_data { 64 49 const struct adxl345_chip_info *info; 65 50 struct regmap *regmap; ··· 95 110 return IIO_VAL_INT; 96 111 case IIO_CHAN_INFO_SCALE: 97 112 *val = 0; 98 - switch (data->info->type) { 99 - case ADXL345: 100 - *val2 = adxl345_uscale; 101 - break; 102 - case ADXL375: 103 - *val2 = adxl375_uscale; 104 - break; 105 - } 106 - 113 + *val2 = data->info->uscale; 107 114 return IIO_VAL_INT_PLUS_MICRO; 108 115 case IIO_CHAN_INFO_CALIBBIAS: 109 116 ret = regmap_read(data->regmap,
+2 -2
drivers/iio/accel/adxl345_i2c.c
··· 32 32 33 33 static const struct adxl345_chip_info adxl345_i2c_info = { 34 34 .name = "adxl345", 35 - .type = ADXL345, 35 + .uscale = ADXL345_USCALE, 36 36 }; 37 37 38 38 static const struct adxl345_chip_info adxl375_i2c_info = { 39 39 .name = "adxl375", 40 - .type = ADXL375, 40 + .uscale = ADXL375_USCALE, 41 41 }; 42 42 43 43 static const struct i2c_device_id adxl345_i2c_id[] = {
+2 -2
drivers/iio/accel/adxl345_spi.c
··· 38 38 39 39 static const struct adxl345_chip_info adxl345_spi_info = { 40 40 .name = "adxl345", 41 - .type = ADXL345, 41 + .uscale = ADXL345_USCALE, 42 42 }; 43 43 44 44 static const struct adxl345_chip_info adxl375_spi_info = { 45 45 .name = "adxl375", 46 - .type = ADXL375, 46 + .uscale = ADXL375_USCALE, 47 47 }; 48 48 49 49 static const struct spi_device_id adxl345_spi_id[] = {