Loading...
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
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{
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
33static const struct i2c_device_id adxl345_i2c_id[] = {
34 { "adxl345", ADXL345 },
35 { "adxl375", ADXL375 },
36 { }
37};
38MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
39
40static 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};
45MODULE_DEVICE_TABLE(of, adxl345_of_match);
46
47static const struct acpi_device_id adxl345_acpi_match[] = {
48 { "ADS0345", ADXL345 },
49 { }
50};
51MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
52
53static 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};
62module_i2c_driver(adxl345_i2c_driver);
63
64MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
65MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
66MODULE_LICENSE("GPL v2");
67MODULE_IMPORT_NS(IIO_ADXL345);
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
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{
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
33static const struct adxl345_chip_info adxl345_i2c_info = {
34 .name = "adxl345",
35 .uscale = ADXL345_USCALE,
36};
37
38static const struct adxl345_chip_info adxl375_i2c_info = {
39 .name = "adxl375",
40 .uscale = ADXL375_USCALE,
41};
42
43static 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};
48MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
49
50static 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};
55MODULE_DEVICE_TABLE(of, adxl345_of_match);
56
57static const struct acpi_device_id adxl345_acpi_match[] = {
58 { "ADS0345", (kernel_ulong_t)&adxl345_i2c_info },
59 { }
60};
61MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
62
63static 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};
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");
77MODULE_IMPORT_NS(IIO_ADXL345);