1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * ADXL380 3-Axis Digital Accelerometer SPI driver
4 *
5 * Copyright 2024 Analog Devices Inc.
6 */
7
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/regmap.h>
11 #include <linux/spi/spi.h>
12
13 #include "adxl380.h"
14
15 static const struct regmap_config adxl380_spi_regmap_config = {
16 .reg_bits = 7,
17 .pad_bits = 1,
18 .val_bits = 8,
19 .read_flag_mask = BIT(0),
20 .readable_noinc_reg = adxl380_readable_noinc_reg,
21 };
22
adxl380_spi_probe(struct spi_device * spi)23 static int adxl380_spi_probe(struct spi_device *spi)
24 {
25 const struct adxl380_chip_info *chip_data;
26 struct regmap *regmap;
27
28 chip_data = spi_get_device_match_data(spi);
29
30 regmap = devm_regmap_init_spi(spi, &adxl380_spi_regmap_config);
31 if (IS_ERR(regmap))
32 return PTR_ERR(regmap);
33
34 return adxl380_probe(&spi->dev, regmap, chip_data);
35 }
36
37 static const struct spi_device_id adxl380_spi_id[] = {
38 { "adxl318", (kernel_ulong_t)&adxl318_chip_info },
39 { "adxl319", (kernel_ulong_t)&adxl319_chip_info },
40 { "adxl380", (kernel_ulong_t)&adxl380_chip_info },
41 { "adxl382", (kernel_ulong_t)&adxl382_chip_info },
42 { }
43 };
44 MODULE_DEVICE_TABLE(spi, adxl380_spi_id);
45
46 static const struct of_device_id adxl380_of_match[] = {
47 { .compatible = "adi,adxl318", .data = &adxl318_chip_info },
48 { .compatible = "adi,adxl319", .data = &adxl319_chip_info },
49 { .compatible = "adi,adxl380", .data = &adxl380_chip_info },
50 { .compatible = "adi,adxl382", .data = &adxl382_chip_info },
51 { }
52 };
53 MODULE_DEVICE_TABLE(of, adxl380_of_match);
54
55 static struct spi_driver adxl380_spi_driver = {
56 .driver = {
57 .name = "adxl380_spi",
58 .of_match_table = adxl380_of_match,
59 },
60 .probe = adxl380_spi_probe,
61 .id_table = adxl380_spi_id,
62 };
63
64 module_spi_driver(adxl380_spi_driver);
65
66 MODULE_AUTHOR("Ramona Gradinariu <ramona.gradinariu@analog.com>");
67 MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>");
68 MODULE_DESCRIPTION("Analog Devices ADXL380 3-axis accelerometer SPI driver");
69 MODULE_LICENSE("GPL");
70 MODULE_IMPORT_NS("IIO_ADXL380");
71