blob: 05e1ec49700c93410609a5730cf1a4775191bd11 [file] [log] [blame]
Eva Rachel Retuya51705122017-03-04 16:31:25 +08001/*
2 * ADXL345 3-Axis Digital Accelerometer I2C driver
3 *
4 * Copyright (c) 2017 Eva Rachel Retuya <eraretuya@gmail.com>
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * 7-bit I2C slave address: 0x1D (ALT ADDRESS pin tied to VDDIO) or
11 * 0x53 (ALT ADDRESS pin grounded)
12 */
13
14#include <linux/i2c.h>
15#include <linux/module.h>
16#include <linux/regmap.h>
17
18#include "adxl345.h"
19
20static const struct regmap_config adxl345_i2c_regmap_config = {
21 .reg_bits = 8,
22 .val_bits = 8,
23};
24
25static int adxl345_i2c_probe(struct i2c_client *client,
26 const struct i2c_device_id *id)
27{
28 struct regmap *regmap;
29
30 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
37 return adxl345_core_probe(&client->dev, regmap, id ? id->name : NULL);
38}
39
40static int adxl345_i2c_remove(struct i2c_client *client)
41{
42 return adxl345_core_remove(&client->dev);
43}
44
45static const struct i2c_device_id adxl345_i2c_id[] = {
46 { "adxl345", 0 },
47 { }
48};
49
50MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
51
52static const struct of_device_id adxl345_of_match[] = {
53 { .compatible = "adi,adxl345" },
54 { },
55};
56
57MODULE_DEVICE_TABLE(of, adxl345_of_match);
58
59static struct i2c_driver adxl345_i2c_driver = {
60 .driver = {
61 .name = "adxl345_i2c",
62 .of_match_table = adxl345_of_match,
63 },
64 .probe = adxl345_i2c_probe,
65 .remove = adxl345_i2c_remove,
66 .id_table = adxl345_i2c_id,
67};
68
69module_i2c_driver(adxl345_i2c_driver);
70
71MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
72MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
73MODULE_LICENSE("GPL v2");