| 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/mod_devicetable.h> |
| 10 |
#include <linux/module.h> |
| 11 |
#include <linux/regmap.h> |
| 12 |
|
| 13 |
#include "adxl372.h" |
| 14 |
|
| 15 |
static const struct regmap_config adxl372_regmap_config = { |
| 16 |
.reg_bits = 8, |
| 17 |
.val_bits = 8, |
| 18 |
.readable_noinc_reg = adxl372_readable_noinc_reg, |
| 19 |
}; |
| 20 |
|
| 21 |
static int adxl372_i2c_probe(struct i2c_client *client) |
| 22 |
{ |
| 23 |
const struct i2c_device_id *id = i2c_client_get_device_id(client); |
| 24 |
struct regmap *regmap; |
| 25 |
unsigned int regval; |
| 26 |
int ret; |
| 27 |
|
| 28 |
regmap = devm_regmap_init_i2c(client, &adxl372_regmap_config); |
| 29 |
if (IS_ERR(regmap)) |
| 30 |
return PTR_ERR(regmap); |
| 31 |
|
| 32 |
ret = regmap_read(regmap, ADXL372_REVID, ®val); |
| 33 |
if (ret < 0) |
| 34 |
return ret; |
| 35 |
|
| 36 |
/* Starting with the 3rd revision an I2C chip bug was fixed */ |
| 37 |
if (regval < 3) |
| 38 |
dev_warn(&client->dev, |
| 39 |
"I2C might not work properly with other devices on the bus"); |
| 40 |
|
| 41 |
return adxl372_probe(&client->dev, regmap, client->irq, id->name); |
| 42 |
} |
| 43 |
|
| 44 |
static const struct i2c_device_id adxl372_i2c_id[] = { |
| 45 |
{ "adxl372" }, |
| 46 |
{ } |
| 47 |
}; |
| 48 |
MODULE_DEVICE_TABLE(i2c, adxl372_i2c_id); |
| 49 |
|
| 50 |
static const struct of_device_id adxl372_of_match[] = { |
| 51 |
{ .compatible = "adi,adxl372" }, |
| 52 |
{ } |
| 53 |
}; |
| 54 |
MODULE_DEVICE_TABLE(of, adxl372_of_match); |
| 55 |
|
| 56 |
static struct i2c_driver adxl372_i2c_driver = { |
| 57 |
.driver = { |
| 58 |
.name = "adxl372_i2c", |
| 59 |
.of_match_table = adxl372_of_match, |
| 60 |
}, |
| 61 |
.probe = adxl372_i2c_probe, |
| 62 |
.id_table = adxl372_i2c_id, |
| 63 |
}; |
| 64 |
|
| 65 |
module_i2c_driver(adxl372_i2c_driver); |
| 66 |
|
| 67 |
MODULE_AUTHOR("Stefan Popa <[email protected]>"); |
| 68 |
MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver"); |
| 69 |
MODULE_LICENSE("GPL"); |
| 70 |
MODULE_IMPORT_NS("IIO_ADXL372"); |