xref: /linux/drivers/iio/accel/adxl345_i2c.c (revision b7df4cc3a088a8ce6973c96731bc792dbf54ce28)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * ADXL345 3-Axis Digital Accelerometer I2C driver
4  *
5  * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
6  *
7  * 7-bit I2C slave address: 0x1D (ALT ADDRESS pin tied to VDDIO) or
8  * 0x53 (ALT ADDRESS pin grounded)
9  */
10 
11 #include <linux/i2c.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14 
15 #include "adxl345.h"
16 
17 static const struct regmap_config adxl345_i2c_regmap_config = {
18 	.reg_bits = 8,
19 	.val_bits = 8,
20 };
21 
22 static int adxl345_i2c_probe(struct i2c_client *client)
23 {
24 	struct regmap *regmap;
25 
26 	regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
27 	if (IS_ERR(regmap))
28 		return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n");
29 
30 	return adxl345_core_probe(&client->dev, regmap);
31 }
32 
33 static const struct adxl345_chip_info adxl345_i2c_info = {
34 	.name = "adxl345",
35 	.uscale = ADXL345_USCALE,
36 };
37 
38 static const struct adxl345_chip_info adxl375_i2c_info = {
39 	.name = "adxl375",
40 	.uscale = ADXL375_USCALE,
41 };
42 
43 static const struct i2c_device_id adxl345_i2c_id[] = {
44 	{ "adxl345", (kernel_ulong_t)&adxl345_i2c_info },
45 	{ "adxl375", (kernel_ulong_t)&adxl375_i2c_info },
46 	{ }
47 };
48 MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
49 
50 static const struct of_device_id adxl345_of_match[] = {
51 	{ .compatible = "adi,adxl345", .data = &adxl345_i2c_info },
52 	{ .compatible = "adi,adxl375", .data = &adxl375_i2c_info },
53 	{ }
54 };
55 MODULE_DEVICE_TABLE(of, adxl345_of_match);
56 
57 static const struct acpi_device_id adxl345_acpi_match[] = {
58 	{ "ADS0345", (kernel_ulong_t)&adxl345_i2c_info },
59 	{ }
60 };
61 MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
62 
63 static struct i2c_driver adxl345_i2c_driver = {
64 	.driver = {
65 		.name	= "adxl345_i2c",
66 		.of_match_table = adxl345_of_match,
67 		.acpi_match_table = adxl345_acpi_match,
68 	},
69 	.probe		= adxl345_i2c_probe,
70 	.id_table	= adxl345_i2c_id,
71 };
72 module_i2c_driver(adxl345_i2c_driver);
73 
74 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
75 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
76 MODULE_LICENSE("GPL v2");
77 MODULE_IMPORT_NS(IIO_ADXL345);
78