| 1 |
// SPDX-License-Identifier: GPL-2.0+ |
| 2 |
/* |
| 3 |
* ADXL380 3-Axis Digital Accelerometer I2C driver |
| 4 |
* |
| 5 |
* Copyright 2024 Analog Devices Inc. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <linux/i2c.h> |
| 9 |
#include <linux/mod_devicetable.h> |
| 10 |
#include <linux/module.h> |
| 11 |
#include <linux/regmap.h> |
| 12 |
|
| 13 |
#include "adxl380.h" |
| 14 |
|
| 15 |
static const struct regmap_config adxl380_regmap_config = { |
| 16 |
.reg_bits = 8, |
| 17 |
.val_bits = 8, |
| 18 |
.readable_noinc_reg = adxl380_readable_noinc_reg, |
| 19 |
}; |
| 20 |
|
| 21 |
static int adxl380_i2c_probe(struct i2c_client *client) |
| 22 |
{ |
| 23 |
struct regmap *regmap; |
| 24 |
const struct adxl380_chip_info *chip_data; |
| 25 |
|
| 26 |
chip_data = i2c_get_match_data(client); |
| 27 |
|
| 28 |
regmap = devm_regmap_init_i2c(client, &adxl380_regmap_config); |
| 29 |
if (IS_ERR(regmap)) |
| 30 |
return PTR_ERR(regmap); |
| 31 |
|
| 32 |
return adxl380_probe(&client->dev, regmap, chip_data); |
| 33 |
} |
| 34 |
|
| 35 |
static const struct i2c_device_id adxl380_i2c_id[] = { |
| 36 |
{ "adxl318", (kernel_ulong_t)&adxl318_chip_info }, |
| 37 |
{ "adxl319", (kernel_ulong_t)&adxl319_chip_info }, |
| 38 |
{ "adxl380", (kernel_ulong_t)&adxl380_chip_info }, |
| 39 |
{ "adxl382", (kernel_ulong_t)&adxl382_chip_info }, |
| 40 |
{ } |
| 41 |
}; |
| 42 |
MODULE_DEVICE_TABLE(i2c, adxl380_i2c_id); |
| 43 |
|
| 44 |
static const struct of_device_id adxl380_of_match[] = { |
| 45 |
{ .compatible = "adi,adxl318", .data = &adxl318_chip_info }, |
| 46 |
{ .compatible = "adi,adxl319", .data = &adxl319_chip_info }, |
| 47 |
{ .compatible = "adi,adxl380", .data = &adxl380_chip_info }, |
| 48 |
{ .compatible = "adi,adxl382", .data = &adxl382_chip_info }, |
| 49 |
{ } |
| 50 |
}; |
| 51 |
MODULE_DEVICE_TABLE(of, adxl380_of_match); |
| 52 |
|
| 53 |
static struct i2c_driver adxl380_i2c_driver = { |
| 54 |
.driver = { |
| 55 |
.name = "adxl380_i2c", |
| 56 |
.of_match_table = adxl380_of_match, |
| 57 |
}, |
| 58 |
.probe = adxl380_i2c_probe, |
| 59 |
.id_table = adxl380_i2c_id, |
| 60 |
}; |
| 61 |
|
| 62 |
module_i2c_driver(adxl380_i2c_driver); |
| 63 |
|
| 64 |
MODULE_AUTHOR("Ramona Gradinariu <[email protected]>"); |
| 65 |
MODULE_AUTHOR("Antoniu Miclaus <[email protected]>"); |
| 66 |
MODULE_DESCRIPTION("Analog Devices ADXL380 3-axis accelerometer I2C driver"); |
| 67 |
MODULE_LICENSE("GPL"); |
| 68 |
MODULE_IMPORT_NS("IIO_ADXL380"); |