0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/i2c.h>
0009 #include <linux/mod_devicetable.h>
0010 #include <linux/module.h>
0011 #include <linux/regmap.h>
0012
0013 #include "adxl372.h"
0014
0015 static const struct regmap_config adxl372_regmap_config = {
0016 .reg_bits = 8,
0017 .val_bits = 8,
0018 .readable_noinc_reg = adxl372_readable_noinc_reg,
0019 };
0020
0021 static int adxl372_i2c_probe(struct i2c_client *client,
0022 const struct i2c_device_id *id)
0023 {
0024 struct regmap *regmap;
0025 unsigned int regval;
0026 int ret;
0027
0028 regmap = devm_regmap_init_i2c(client, &adxl372_regmap_config);
0029 if (IS_ERR(regmap))
0030 return PTR_ERR(regmap);
0031
0032 ret = regmap_read(regmap, ADXL372_REVID, ®val);
0033 if (ret < 0)
0034 return ret;
0035
0036
0037 if (regval < 3)
0038 dev_warn(&client->dev,
0039 "I2C might not work properly with other devices on the bus");
0040
0041 return adxl372_probe(&client->dev, regmap, client->irq, id->name);
0042 }
0043
0044 static const struct i2c_device_id adxl372_i2c_id[] = {
0045 { "adxl372", 0 },
0046 {}
0047 };
0048 MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id);
0049
0050 static const struct of_device_id adxl372_of_match[] = {
0051 { .compatible = "adi,adxl372" },
0052 { }
0053 };
0054 MODULE_DEVICE_TABLE(of, adxl372_of_match);
0055
0056 static struct i2c_driver adxl372_i2c_driver = {
0057 .driver = {
0058 .name = "adxl372_i2c",
0059 .of_match_table = adxl372_of_match,
0060 },
0061 .probe = adxl372_i2c_probe,
0062 .id_table = adxl372_i2c_id,
0063 };
0064
0065 module_i2c_driver(adxl372_i2c_driver);
0066
0067 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
0068 MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver");
0069 MODULE_LICENSE("GPL");
0070 MODULE_IMPORT_NS(IIO_ADXL372);