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