xref: /linux/drivers/iio/accel/adxl380_i2c.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * ADXL380 3-Axis Digital Accelerometer I2C driver
4  *
5  * Copyright 2024 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 "adxl380.h"
14 
15 static const struct regmap_config adxl380_regmap_config = {
16 	.reg_bits = 8,
17 	.val_bits = 8,
18 	.readable_noinc_reg = adxl380_readable_noinc_reg,
19 };
20 
21 static int adxl380_i2c_probe(struct i2c_client *client)
22 {
23 	struct regmap *regmap;
24 	const struct adxl380_chip_info *chip_data;
25 
26 	chip_data = i2c_get_match_data(client);
27 
28 	regmap = devm_regmap_init_i2c(client, &adxl380_regmap_config);
29 	if (IS_ERR(regmap))
30 		return PTR_ERR(regmap);
31 
32 	return adxl380_probe(&client->dev, regmap, chip_data);
33 }
34 
35 static const struct i2c_device_id adxl380_i2c_id[] = {
36 	{ "adxl380", (kernel_ulong_t)&adxl380_chip_info },
37 	{ "adxl382", (kernel_ulong_t)&adxl382_chip_info },
38 	{ }
39 };
40 MODULE_DEVICE_TABLE(i2c, adxl380_i2c_id);
41 
42 static const struct of_device_id adxl380_of_match[] = {
43 	{ .compatible = "adi,adxl380", .data = &adxl380_chip_info },
44 	{ .compatible = "adi,adxl382", .data = &adxl382_chip_info },
45 	{ }
46 };
47 MODULE_DEVICE_TABLE(of, adxl380_of_match);
48 
49 static struct i2c_driver adxl380_i2c_driver = {
50 	.driver = {
51 		.name = "adxl380_i2c",
52 		.of_match_table = adxl380_of_match,
53 	},
54 	.probe = adxl380_i2c_probe,
55 	.id_table = adxl380_i2c_id,
56 };
57 
58 module_i2c_driver(adxl380_i2c_driver);
59 
60 MODULE_AUTHOR("Ramona Gradinariu <ramona.gradinariu@analog.com>");
61 MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>");
62 MODULE_DESCRIPTION("Analog Devices ADXL380 3-axis accelerometer I2C driver");
63 MODULE_LICENSE("GPL");
64 MODULE_IMPORT_NS(IIO_ADXL380);
65