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

iio: adxl372: Add support for I2C communication

The adxl372 is designed to communicate in either SPI or I2C protocol. It
autodetects the format being used, requiring no configuration control to
select the format.

Signed-off-by: Stefan Popa <stefan.popa@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Stefan Popa and committed by
Jonathan Cameron
94dbb46c d9e8fd04

+76 -1
+1
MAINTAINERS
··· 549 549 S: Supported 550 550 F: drivers/iio/accel/adxl372.c 551 551 F: drivers/iio/accel/adxl372_spi.c 552 + F: drivers/iio/accel/adxl372_i2c.c 552 553 F: Documentation/devicetree/bindings/iio/accel/adxl372.txt 553 554 554 555 AF9013 MEDIA DRIVER
+11
drivers/iio/accel/Kconfig
··· 76 76 To compile this driver as a module, choose M here: the 77 77 module will be called adxl372_spi. 78 78 79 + config ADXL372_I2C 80 + tristate "Analog Devices ADXL372 3-Axis Accelerometer I2C Driver" 81 + depends on I2C 82 + select ADXL372 83 + select REGMAP_I2C 84 + help 85 + Say yes here to add support for the Analog Devices ADXL372 triaxial 86 + acceleration sensor. 87 + To compile this driver as a module, choose M here: the 88 + module will be called adxl372_i2c. 89 + 79 90 config BMA180 80 91 tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver" 81 92 depends on I2C
+1
drivers/iio/accel/Makefile
··· 10 10 obj-$(CONFIG_ADXL345_I2C) += adxl345_i2c.o 11 11 obj-$(CONFIG_ADXL345_SPI) += adxl345_spi.o 12 12 obj-$(CONFIG_ADXL372) += adxl372.o 13 + obj-$(CONFIG_ADXL372_I2C) += adxl372_i2c.o 13 14 obj-$(CONFIG_ADXL372_SPI) += adxl372_spi.o 14 15 obj-$(CONFIG_BMA180) += bma180.o 15 16 obj-$(CONFIG_BMA220) += bma220_spi.o
-1
drivers/iio/accel/adxl372.c
··· 26 26 #define ADXL372_DEVID 0x00 27 27 #define ADXL372_DEVID_MST 0x01 28 28 #define ADXL372_PARTID 0x02 29 - #define ADXL372_REVID 0x03 30 29 #define ADXL372_STATUS_1 0x04 31 30 #define ADXL372_STATUS_2 0x05 32 31 #define ADXL372_FIFO_ENTRIES_2 0x06
+2
drivers/iio/accel/adxl372.h
··· 8 8 #ifndef _ADXL372_H_ 9 9 #define _ADXL372_H_ 10 10 11 + #define ADXL372_REVID 0x03 12 + 11 13 int adxl372_probe(struct device *dev, struct regmap *regmap, 12 14 int irq, const char *name); 13 15 bool adxl372_readable_noinc_reg(struct device *dev, unsigned int reg);
+61
drivers/iio/accel/adxl372_i2c.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * ADXL372 3-Axis Digital Accelerometer I2C driver 4 + * 5 + * Copyright 2018 Analog Devices Inc. 6 + */ 7 + 8 + #include <linux/i2c.h> 9 + #include <linux/module.h> 10 + #include <linux/regmap.h> 11 + 12 + #include "adxl372.h" 13 + 14 + static const struct regmap_config adxl372_regmap_config = { 15 + .reg_bits = 8, 16 + .val_bits = 8, 17 + .readable_noinc_reg = adxl372_readable_noinc_reg, 18 + }; 19 + 20 + static int adxl372_i2c_probe(struct i2c_client *client, 21 + const struct i2c_device_id *id) 22 + { 23 + struct regmap *regmap; 24 + unsigned int regval; 25 + int ret; 26 + 27 + regmap = devm_regmap_init_i2c(client, &adxl372_regmap_config); 28 + if (IS_ERR(regmap)) 29 + return PTR_ERR(regmap); 30 + 31 + ret = regmap_read(regmap, ADXL372_REVID, &regval); 32 + if (ret < 0) 33 + return ret; 34 + 35 + /* Starting with the 3rd revision an I2C chip bug was fixed */ 36 + if (regval < 3) 37 + dev_warn(&client->dev, 38 + "I2C might not work properly with other devices on the bus"); 39 + 40 + return adxl372_probe(&client->dev, regmap, client->irq, id->name); 41 + } 42 + 43 + static const struct i2c_device_id adxl372_i2c_id[] = { 44 + { "adxl372", 0 }, 45 + {} 46 + }; 47 + MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id); 48 + 49 + static struct i2c_driver adxl372_i2c_driver = { 50 + .driver = { 51 + .name = "adxl372_i2c", 52 + }, 53 + .probe = adxl372_i2c_probe, 54 + .id_table = adxl372_i2c_id, 55 + }; 56 + 57 + module_i2c_driver(adxl372_i2c_driver); 58 + 59 + MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>"); 60 + MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver"); 61 + MODULE_LICENSE("GPL");