File Index
Files and directories
Sign in
FILE

adxl345_i2c.c

File preview with syntax highlighting.

linux-6.19.14/drivers/iio/accel/adxl345_i2c.c C
 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	.volatile_reg = adxl345_is_volatile_reg,
21	.cache_type = REGCACHE_MAPLE,
22};
23
24static int adxl345_i2c_probe(struct i2c_client *client)
25{
26	struct regmap *regmap;
27
28	regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
29	if (IS_ERR(regmap))
30		return dev_err_probe(&client->dev, PTR_ERR(regmap), "Error initializing regmap\n");
31
32	return adxl345_core_probe(&client->dev, regmap, false, NULL);
33}
34
35static const struct adxl345_chip_info adxl345_i2c_info = {
36	.name = "adxl345",
37	.uscale = ADXL345_USCALE,
38};
39
40static const struct adxl345_chip_info adxl375_i2c_info = {
41	.name = "adxl375",
42	.uscale = ADXL375_USCALE,
43};
44
45static const struct i2c_device_id adxl345_i2c_id[] = {
46	{ "adxl345", (kernel_ulong_t)&adxl345_i2c_info },
47	{ "adxl375", (kernel_ulong_t)&adxl375_i2c_info },
48	{ }
49};
50MODULE_DEVICE_TABLE(i2c, adxl345_i2c_id);
51
52static const struct of_device_id adxl345_of_match[] = {
53	{ .compatible = "adi,adxl345", .data = &adxl345_i2c_info },
54	{ .compatible = "adi,adxl375", .data = &adxl375_i2c_info },
55	{ }
56};
57MODULE_DEVICE_TABLE(of, adxl345_of_match);
58
59static const struct acpi_device_id adxl345_acpi_match[] = {
60	{ "ADS0345", (kernel_ulong_t)&adxl345_i2c_info },
61	{ }
62};
63MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
64
65static struct i2c_driver adxl345_i2c_driver = {
66	.driver = {
67		.name	= "adxl345_i2c",
68		.of_match_table = adxl345_of_match,
69		.acpi_match_table = adxl345_acpi_match,
70	},
71	.probe		= adxl345_i2c_probe,
72	.id_table	= adxl345_i2c_id,
73};
74module_i2c_driver(adxl345_i2c_driver);
75
76MODULE_AUTHOR("Eva Rachel Retuya <eraretuya@gmail.com>");
77MODULE_DESCRIPTION("ADXL345 3-Axis Digital Accelerometer I2C driver");
78MODULE_LICENSE("GPL v2");
79MODULE_IMPORT_NS("IIO_ADXL345");
~/ Read-only file preview.