xref: /openbmc/linux/drivers/iio/accel/adxl345_i2c.c (revision 08b7cf13)
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 i2c_device_id adxl345_i2c_id[] = {
34 	{ "adxl345", ADXL345 },
35 	{ "adxl375", ADXL375 },
36 	{ }
37 };
38 MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
39 
40 static const struct of_device_id adxl345_of_match[] = {
41 	{ .compatible = "adi,adxl345", .data = (const void *)ADXL345 },
42 	{ .compatible = "adi,adxl375", .data = (const void *)ADXL375 },
43 	{ }
44 };
45 MODULE_DEVICE_TABLE(of, adxl345_of_match);
46 
47 static const struct acpi_device_id adxl345_acpi_match[] = {
48 	{ "ADS0345", ADXL345 },
49 	{ }
50 };
51 MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
52 
53 static struct i2c_driver adxl345_i2c_driver = {
54 	.driver = {
55 		.name	= "adxl345_i2c",
56 		.of_match_table = adxl345_of_match,
57 		.acpi_match_table = adxl345_acpi_match,
58 	},
59 	.probe_new	= adxl345_i2c_probe,
60 	.id_table	= adxl345_i2c_id,
61 };
62 module_i2c_driver(adxl345_i2c_driver);
63 
64 MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
65 MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
66 MODULE_LICENSE("GPL v2");
67 MODULE_IMPORT_NS(IIO_ADXL345);
68