xref: /openbmc/linux/drivers/iio/accel/adxl355_i2c.c (revision da1d9caf)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * ADXL355 3-Axis Digital Accelerometer I2C driver
4  *
5  * Copyright (c) 2021 Puranjay Mohan <puranjay12@gmail.com>
6  */
7 
8 #include <linux/i2c.h>
9 #include <linux/module.h>
10 #include <linux/mod_devicetable.h>
11 #include <linux/regmap.h>
12 
13 #include "adxl355.h"
14 
15 static const struct regmap_config adxl355_i2c_regmap_config = {
16 	.reg_bits = 8,
17 	.val_bits = 8,
18 	.max_register = 0x2F,
19 	.rd_table = &adxl355_readable_regs_tbl,
20 	.wr_table = &adxl355_writeable_regs_tbl,
21 };
22 
23 static int adxl355_i2c_probe(struct i2c_client *client)
24 {
25 	struct regmap *regmap;
26 
27 	regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config);
28 	if (IS_ERR(regmap)) {
29 		dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
30 			PTR_ERR(regmap));
31 
32 		return PTR_ERR(regmap);
33 	}
34 
35 	return adxl355_core_probe(&client->dev, regmap, client->name);
36 }
37 
38 static const struct i2c_device_id adxl355_i2c_id[] = {
39 	{ "adxl355", 0 },
40 	{ }
41 };
42 MODULE_DEVICE_TABLE(i2c, adxl355_i2c_id);
43 
44 static const struct of_device_id adxl355_of_match[] = {
45 	{ .compatible = "adi,adxl355" },
46 	{ }
47 };
48 MODULE_DEVICE_TABLE(of, adxl355_of_match);
49 
50 static struct i2c_driver adxl355_i2c_driver = {
51 	.driver = {
52 		.name	= "adxl355_i2c",
53 		.of_match_table = adxl355_of_match,
54 	},
55 	.probe_new	= adxl355_i2c_probe,
56 	.id_table	= adxl355_i2c_id,
57 };
58 module_i2c_driver(adxl355_i2c_driver);
59 
60 MODULE_AUTHOR("Puranjay Mohan <puranjay12@gmail.com>");
61 MODULE_DESCRIPTION("ADXL355 3-Axis Digital Accelerometer I2C driver");
62 MODULE_LICENSE("GPL v2");
63 MODULE_IMPORT_NS(IIO_ADXL355);
64