1262569Simp// SPDX-License-Identifier: GPL-2.0+
2262569Simp/*
3262569Simp * ADXL372 3-Axis Digital Accelerometer I2C driver
4262569Simp *
5262569Simp * Copyright 2018 Analog Devices Inc.
6262569Simp */
7262569Simp
8262569Simp#include <linux/i2c.h>
9262569Simp#include <linux/mod_devicetable.h>
10262569Simp#include <linux/module.h>
11262569Simp#include <linux/regmap.h>
12262569Simp
13270864Simp#include "adxl372.h"
14262569Simp
15262569Simpstatic const struct regmap_config adxl372_regmap_config = {
16262569Simp	.reg_bits = 8,
17262569Simp	.val_bits = 8,
18262569Simp	.readable_noinc_reg = adxl372_readable_noinc_reg,
19270864Simp};
20270864Simp
21270864Simpstatic int adxl372_i2c_probe(struct i2c_client *client)
22270864Simp{
23270864Simp	const struct i2c_device_id *id = i2c_client_get_device_id(client);
24262569Simp	struct regmap *regmap;
25270864Simp	unsigned int regval;
26270864Simp	int ret;
27270864Simp
28270864Simp	regmap = devm_regmap_init_i2c(client, &adxl372_regmap_config);
29270864Simp	if (IS_ERR(regmap))
30270864Simp		return PTR_ERR(regmap);
31270864Simp
32270864Simp	ret = regmap_read(regmap, ADXL372_REVID, &regval);
33270864Simp	if (ret < 0)
34270864Simp		return ret;
35270864Simp
36270864Simp	/* Starting with the 3rd revision an I2C chip bug was fixed */
37270864Simp	if (regval < 3)
38270864Simp		dev_warn(&client->dev,
39270864Simp		"I2C might not work properly with other devices on the bus");
40262569Simp
41270864Simp	return adxl372_probe(&client->dev, regmap, client->irq, id->name);
42270864Simp}
43270864Simp
44262569Simpstatic const struct i2c_device_id adxl372_i2c_id[] = {
45262569Simp	{ "adxl372", 0 },
46262569Simp	{}
47262569Simp};
48262569SimpMODULE_DEVICE_TABLE(i2c, adxl372_i2c_id);
49262569Simp
50262569Simpstatic const struct of_device_id adxl372_of_match[] = {
51262569Simp	{ .compatible = "adi,adxl372" },
52262569Simp	{ }
53270864Simp};
54262569SimpMODULE_DEVICE_TABLE(of, adxl372_of_match);
55262569Simp
56262569Simpstatic struct i2c_driver adxl372_i2c_driver = {
57262569Simp	.driver = {
58262569Simp		.name = "adxl372_i2c",
59262569Simp		.of_match_table = adxl372_of_match,
60262569Simp	},
61262569Simp	.probe = adxl372_i2c_probe,
62262569Simp	.id_table = adxl372_i2c_id,
63262569Simp};
64262569Simp
65262569Simpmodule_i2c_driver(adxl372_i2c_driver);
66262569Simp
67262569SimpMODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
68262569SimpMODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer I2C driver");
69262569SimpMODULE_LICENSE("GPL");
70262569SimpMODULE_IMPORT_NS(IIO_ADXL372);
71262569Simp