xref: /linux/drivers/iio/accel/adxl313_i2c.c (revision 722ecdbce68a87de2d9296f91308f44ea900a039)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * ADXL313 3-Axis Digital Accelerometer
4  *
5  * Copyright (c) 2021 Lucas Stankus <lucas.p.stankus@gmail.com>
6  *
7  * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL313.pdf
8  */
9 
10 #include <linux/i2c.h>
11 #include <linux/mod_devicetable.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14 
15 #include "adxl313.h"
16 
17 static const struct regmap_config adxl313_i2c_regmap_config = {
18 	.reg_bits	= 8,
19 	.val_bits	= 8,
20 	.rd_table	= &adxl313_readable_regs_table,
21 	.wr_table	= &adxl313_writable_regs_table,
22 	.max_register	= 0x39,
23 };
24 
25 static int adxl313_i2c_probe(struct i2c_client *client)
26 {
27 	struct regmap *regmap;
28 
29 	regmap = devm_regmap_init_i2c(client, &adxl313_i2c_regmap_config);
30 	if (IS_ERR(regmap)) {
31 		dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
32 			PTR_ERR(regmap));
33 		return PTR_ERR(regmap);
34 	}
35 
36 	return adxl313_core_probe(&client->dev, regmap, client->name, NULL);
37 }
38 
39 static const struct i2c_device_id adxl313_i2c_id[] = {
40 	{ "adxl313" },
41 	{ }
42 };
43 
44 MODULE_DEVICE_TABLE(i2c, adxl313_i2c_id);
45 
46 static const struct of_device_id adxl313_of_match[] = {
47 	{ .compatible = "adi,adxl313" },
48 	{ }
49 };
50 
51 MODULE_DEVICE_TABLE(of, adxl313_of_match);
52 
53 static struct i2c_driver adxl313_i2c_driver = {
54 	.driver = {
55 		.name	= "adxl313_i2c",
56 		.of_match_table = adxl313_of_match,
57 	},
58 	.probe_new	= adxl313_i2c_probe,
59 	.id_table	= adxl313_i2c_id,
60 };
61 
62 module_i2c_driver(adxl313_i2c_driver);
63 
64 MODULE_AUTHOR("Lucas Stankus <lucas.p.stankus@gmail.com>");
65 MODULE_DESCRIPTION("ADXL313 3-Axis Digital Accelerometer I2C driver");
66 MODULE_LICENSE("GPL v2");
67 MODULE_IMPORT_NS(IIO_ADXL313);
68