blob: 1561364ae296bd6602b651114231fb72a527d26b [file] [log] [blame]
Thomas Gleixner36edc932019-05-29 16:57:44 -07001// SPDX-License-Identifier: GPL-2.0-only
Eva Rachel Retuya51705122017-03-04 16:31:25 +08002/*
3 * ADXL345 3-Axis Digital Accelerometer I2C driver
4 *
5 * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
6 *
Eva Rachel Retuya51705122017-03-04 16:31:25 +08007 * 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
17static const struct regmap_config adxl345_i2c_regmap_config = {
18 .reg_bits = 8,
19 .val_bits = 8,
20};
21
22static int adxl345_i2c_probe(struct i2c_client *client,
23 const struct i2c_device_id *id)
24{
25 struct regmap *regmap;
26
Alexandru Ardelean6b8471e2018-08-07 17:06:05 +030027 if (!id)
28 return -ENODEV;
29
Eva Rachel Retuya51705122017-03-04 16:31:25 +080030 regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
31 if (IS_ERR(regmap)) {
32 dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
33 PTR_ERR(regmap));
34 return PTR_ERR(regmap);
35 }
36
Lars-Peter Clausenef89f4b2018-07-13 14:50:44 +030037 return adxl345_core_probe(&client->dev, regmap, id->driver_data,
Alexandru Ardelean6b8471e2018-08-07 17:06:05 +030038 id->name);
Eva Rachel Retuya51705122017-03-04 16:31:25 +080039}
40
41static int adxl345_i2c_remove(struct i2c_client *client)
42{
43 return adxl345_core_remove(&client->dev);
44}
45
46static const struct i2c_device_id adxl345_i2c_id[] = {
Lars-Peter Clausenef89f4b2018-07-13 14:50:44 +030047 { "adxl345", ADXL345 },
48 { "adxl375", ADXL375 },
Eva Rachel Retuya51705122017-03-04 16:31:25 +080049 { }
50};
51
52MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
53
54static const struct of_device_id adxl345_of_match[] = {
55 { .compatible = "adi,adxl345" },
Lars-Peter Clausenef89f4b2018-07-13 14:50:44 +030056 { .compatible = "adi,adxl375" },
Eva Rachel Retuya51705122017-03-04 16:31:25 +080057 { },
58};
59
60MODULE_DEVICE_TABLE(of, adxl345_of_match);
61
62static struct i2c_driver adxl345_i2c_driver = {
63 .driver = {
64 .name = "adxl345_i2c",
65 .of_match_table = adxl345_of_match,
66 },
67 .probe = adxl345_i2c_probe,
68 .remove = adxl345_i2c_remove,
69 .id_table = adxl345_i2c_id,
70};
71
72module_i2c_driver(adxl345_i2c_driver);
73
74MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
75MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
76MODULE_LICENSE("GPL v2");