1 // SPDX-License-Identifier: GPL-2.0-only
3 * ADXL313 3-Axis Digital Accelerometer
5 * Copyright (c) 2021 Lucas Stankus <lucas.p.stankus@gmail.com>
7 * Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL313.pdf
10 #include <linux/i2c.h>
11 #include <linux/mod_devicetable.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
17 static const struct regmap_config adxl31x_i2c_regmap_config
[] = {
21 .rd_table
= &adxl312_readable_regs_table
,
22 .wr_table
= &adxl312_writable_regs_table
,
28 .rd_table
= &adxl313_readable_regs_table
,
29 .wr_table
= &adxl313_writable_regs_table
,
35 .rd_table
= &adxl314_readable_regs_table
,
36 .wr_table
= &adxl314_writable_regs_table
,
41 static const struct i2c_device_id adxl313_i2c_id
[] = {
42 { .name
= "adxl312", .driver_data
= (kernel_ulong_t
)&adxl31x_chip_info
[ADXL312
] },
43 { .name
= "adxl313", .driver_data
= (kernel_ulong_t
)&adxl31x_chip_info
[ADXL313
] },
44 { .name
= "adxl314", .driver_data
= (kernel_ulong_t
)&adxl31x_chip_info
[ADXL314
] },
48 MODULE_DEVICE_TABLE(i2c
, adxl313_i2c_id
);
50 static const struct of_device_id adxl313_of_match
[] = {
51 { .compatible
= "adi,adxl312", .data
= &adxl31x_chip_info
[ADXL312
] },
52 { .compatible
= "adi,adxl313", .data
= &adxl31x_chip_info
[ADXL313
] },
53 { .compatible
= "adi,adxl314", .data
= &adxl31x_chip_info
[ADXL314
] },
57 MODULE_DEVICE_TABLE(of
, adxl313_of_match
);
59 static int adxl313_i2c_probe(struct i2c_client
*client
)
61 const struct adxl313_chip_info
*chip_data
;
62 struct regmap
*regmap
;
65 * Retrieves device specific data as a pointer to a
66 * adxl313_chip_info structure
68 chip_data
= i2c_get_match_data(client
);
70 regmap
= devm_regmap_init_i2c(client
,
71 &adxl31x_i2c_regmap_config
[chip_data
->type
]);
73 dev_err(&client
->dev
, "Error initializing i2c regmap: %ld\n",
75 return PTR_ERR(regmap
);
78 return adxl313_core_probe(&client
->dev
, regmap
, chip_data
, NULL
);
81 static struct i2c_driver adxl313_i2c_driver
= {
83 .name
= "adxl313_i2c",
84 .of_match_table
= adxl313_of_match
,
86 .probe
= adxl313_i2c_probe
,
87 .id_table
= adxl313_i2c_id
,
90 module_i2c_driver(adxl313_i2c_driver
);
92 MODULE_AUTHOR("Lucas Stankus <lucas.p.stankus@gmail.com>");
93 MODULE_DESCRIPTION("ADXL313 3-Axis Digital Accelerometer I2C driver");
94 MODULE_LICENSE("GPL v2");
95 MODULE_IMPORT_NS("IIO_ADXL313");