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: adxl372: add support for ADXL371

Add support for the Analog Devices ADXL371, a +-200g 3-axis MEMS
accelerometer sharing the same register map as the ADXL372 but with
different ODR values (320/640/1280/2560/5120 Hz vs 400/800/1600/3200/
6400 Hz), different bandwidth values, and different timer scale
factors for activity/inactivity detection.

Due to a silicon anomaly (er001) causing FIFO data misalignment on
all current ADXL371 silicon, FIFO and triggered buffer support is
disabled for the ADXL371 - only direct mode reads are supported.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Antoniu Miclaus and committed by
Jonathan Cameron
e7ecdcbc 39df6dbf

+75 -18
+6 -6
drivers/iio/accel/Kconfig
··· 158 158 select IIO_TRIGGERED_BUFFER 159 159 160 160 config ADXL372_SPI 161 - tristate "Analog Devices ADXL372 3-Axis Accelerometer SPI Driver" 161 + tristate "Analog Devices ADXL371/ADXL372 3-Axis Accelerometer SPI Driver" 162 162 depends on SPI 163 163 select ADXL372 164 164 select REGMAP_SPI 165 165 help 166 - Say yes here to add support for the Analog Devices ADXL372 triaxial 167 - acceleration sensor. 166 + Say yes here to add support for the Analog Devices ADXL371/ADXL372 167 + triaxial acceleration sensor. 168 168 To compile this driver as a module, choose M here: the 169 169 module will be called adxl372_spi. 170 170 171 171 config ADXL372_I2C 172 - tristate "Analog Devices ADXL372 3-Axis Accelerometer I2C Driver" 172 + tristate "Analog Devices ADXL371/ADXL372 3-Axis Accelerometer I2C Driver" 173 173 depends on I2C 174 174 select ADXL372 175 175 select REGMAP_I2C 176 176 help 177 - Say yes here to add support for the Analog Devices ADXL372 triaxial 178 - acceleration sensor. 177 + Say yes here to add support for the Analog Devices ADXL371/ADXL372 178 + triaxial acceleration sensor. 179 179 To compile this driver as a module, choose M here: the 180 180 module will be called adxl372_i2c. 181 181
+56 -7
drivers/iio/accel/adxl372.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 /* 3 - * ADXL372 3-Axis Digital Accelerometer core driver 3 + * ADXL371/ADXL372 3-Axis Digital Accelerometer core driver 4 4 * 5 5 * Copyright 2018 Analog Devices Inc. 6 6 */ ··· 184 184 ADXL372_ODR_NUM 185 185 }; 186 186 187 + enum adxl371_odr { 188 + ADXL371_ODR_320HZ, 189 + ADXL371_ODR_640HZ, 190 + ADXL371_ODR_1280HZ, 191 + ADXL371_ODR_2560HZ, 192 + ADXL371_ODR_5120HZ, 193 + ADXL371_ODR_NUM 194 + }; 195 + 187 196 enum adxl372_bandwidth { 188 197 ADXL372_BW_200HZ, 189 198 ADXL372_BW_400HZ, ··· 241 232 [ADXL372_BW_3200HZ] = 3200, 242 233 }; 243 234 235 + static const int adxl371_samp_freq_tbl[ADXL371_ODR_NUM] = { 236 + [ADXL371_ODR_320HZ] = 320, 237 + [ADXL371_ODR_640HZ] = 640, 238 + [ADXL371_ODR_1280HZ] = 1280, 239 + [ADXL371_ODR_2560HZ] = 2560, 240 + [ADXL371_ODR_5120HZ] = 5120, 241 + }; 242 + 243 + static const int adxl371_bw_freq_tbl[ADXL371_ODR_NUM] = { 244 + [ADXL371_ODR_320HZ] = 160, 245 + [ADXL371_ODR_640HZ] = 320, 246 + [ADXL371_ODR_1280HZ] = 640, 247 + [ADXL371_ODR_2560HZ] = 1280, 248 + [ADXL371_ODR_5120HZ] = 2560, 249 + }; 250 + 251 + const struct adxl372_chip_info adxl371_chip_info = { 252 + .name = "adxl371", 253 + .samp_freq_tbl = adxl371_samp_freq_tbl, 254 + .bw_freq_tbl = adxl371_bw_freq_tbl, 255 + .num_freqs = ARRAY_SIZE(adxl371_samp_freq_tbl), 256 + .act_time_scale_us = 4125, 257 + .act_time_scale_low_us = 8250, 258 + .inact_time_scale_ms = 16, 259 + .inact_time_scale_low_ms = 32, 260 + .max_odr = ADXL371_ODR_5120HZ, 261 + /* Silicon erratum (er001) causes FIFO data misalignment on ADXL371 */ 262 + .fifo_supported = false, 263 + }; 264 + EXPORT_SYMBOL_NS_GPL(adxl371_chip_info, "IIO_ADXL372"); 265 + 244 266 const struct adxl372_chip_info adxl372_chip_info = { 245 267 .name = "adxl372", 246 268 .samp_freq_tbl = adxl372_samp_freq_tbl, ··· 282 242 .inact_time_scale_ms = 13, 283 243 .inact_time_scale_low_ms = 26, 284 244 .max_odr = ADXL372_ODR_6400HZ, 245 + .fifo_supported = true, 285 246 }; 286 247 EXPORT_SYMBOL_NS_GPL(adxl372_chip_info, "IIO_ADXL372"); 287 248 ··· 1303 1262 1304 1263 indio_dev->channels = adxl372_channels; 1305 1264 indio_dev->num_channels = ARRAY_SIZE(adxl372_channels); 1306 - indio_dev->available_scan_masks = adxl372_channel_masks; 1307 1265 indio_dev->name = chip_info->name; 1308 1266 indio_dev->info = &adxl372_info; 1309 - indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; 1267 + 1268 + if (chip_info->fifo_supported) { 1269 + indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; 1270 + indio_dev->available_scan_masks = adxl372_channel_masks; 1271 + } else { 1272 + indio_dev->modes = INDIO_DIRECT_MODE; 1273 + } 1310 1274 1311 1275 ret = adxl372_setup(st); 1312 1276 if (ret < 0) { ··· 1319 1273 return ret; 1320 1274 } 1321 1275 1322 - ret = adxl372_buffer_setup(indio_dev); 1323 - if (ret < 0) 1324 - return ret; 1276 + if (chip_info->fifo_supported) { 1277 + ret = adxl372_buffer_setup(indio_dev); 1278 + if (ret < 0) 1279 + return ret; 1280 + } 1325 1281 1326 1282 return devm_iio_device_register(dev, indio_dev); 1327 1283 } 1328 1284 EXPORT_SYMBOL_NS_GPL(adxl372_probe, "IIO_ADXL372"); 1329 1285 1330 1286 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>"); 1331 - MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer driver"); 1287 + MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>"); 1288 + MODULE_DESCRIPTION("Analog Devices ADXL371/ADXL372 3-axis accelerometer driver"); 1332 1289 MODULE_LICENSE("GPL");
+3 -1
drivers/iio/accel/adxl372.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 2 /* 3 - * ADXL372 3-Axis Digital Accelerometer 3 + * ADXL371/ADXL372 3-Axis Digital Accelerometer 4 4 * 5 5 * Copyright 2018 Analog Devices Inc. 6 6 */ ··· 20 20 unsigned int inact_time_scale_ms; 21 21 unsigned int inact_time_scale_low_ms; 22 22 unsigned int max_odr; 23 + bool fifo_supported; 23 24 }; 24 25 26 + extern const struct adxl372_chip_info adxl371_chip_info; 25 27 extern const struct adxl372_chip_info adxl372_chip_info; 26 28 27 29 int adxl372_probe(struct device *dev, struct regmap *regmap,
+5 -2
drivers/iio/accel/adxl372_i2c.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 /* 3 - * ADXL372 3-Axis Digital Accelerometer I2C driver 3 + * ADXL371/ADXL372 3-Axis Digital Accelerometer I2C driver 4 4 * 5 5 * Copyright 2018 Analog Devices Inc. 6 6 */ ··· 44 44 } 45 45 46 46 static const struct i2c_device_id adxl372_i2c_id[] = { 47 + { "adxl371", (kernel_ulong_t)&adxl371_chip_info }, 47 48 { "adxl372", (kernel_ulong_t)&adxl372_chip_info }, 48 49 { } 49 50 }; 50 51 MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id); 51 52 52 53 static const struct of_device_id adxl372_of_match[] = { 54 + { .compatible = "adi,adxl371", .data = &adxl371_chip_info }, 53 55 { .compatible = "adi,adxl372", .data = &adxl372_chip_info }, 54 56 { } 55 57 }; ··· 69 67 module_i2c_driver(adxl372_i2c_driver); 70 68 71 69 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>"); 72 - MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver"); 70 + MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>"); 71 + MODULE_DESCRIPTION("Analog Devices ADXL371/ADXL372 3-axis accelerometer I2C driver"); 73 72 MODULE_LICENSE("GPL"); 74 73 MODULE_IMPORT_NS("IIO_ADXL372");
+5 -2
drivers/iio/accel/adxl372_spi.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 /* 3 - * ADXL372 3-Axis Digital Accelerometer SPI driver 3 + * ADXL371/ADXL372 3-Axis Digital Accelerometer SPI driver 4 4 * 5 5 * Copyright 2018 Analog Devices Inc. 6 6 */ ··· 35 35 } 36 36 37 37 static const struct spi_device_id adxl372_spi_id[] = { 38 + { "adxl371", (kernel_ulong_t)&adxl371_chip_info }, 38 39 { "adxl372", (kernel_ulong_t)&adxl372_chip_info }, 39 40 { } 40 41 }; 41 42 MODULE_DEVICE_TABLE(spi, adxl372_spi_id); 42 43 43 44 static const struct of_device_id adxl372_of_match[] = { 45 + { .compatible = "adi,adxl371", .data = &adxl371_chip_info }, 44 46 { .compatible = "adi,adxl372", .data = &adxl372_chip_info }, 45 47 { } 46 48 }; ··· 60 58 module_spi_driver(adxl372_spi_driver); 61 59 62 60 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>"); 63 - MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver"); 61 + MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>"); 62 + MODULE_DESCRIPTION("Analog Devices ADXL371/ADXL372 3-axis accelerometer SPI driver"); 64 63 MODULE_LICENSE("GPL"); 65 64 MODULE_IMPORT_NS("IIO_ADXL372");