1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * ADXL372 3-Axis Digital Accelerometer SPI driver
4 *
5 * Copyright 2018 Analog Devices Inc.
6 */
7
8 #include <linux/module.h>
9 #include <linux/regmap.h>
10 #include <linux/of.h>
11 #include <linux/of_device.h>
12 #include <linux/spi/spi.h>
13
14 #include "adxl372.h"
15
16 static const struct regmap_config adxl372_spi_regmap_config = {
17 .reg_bits = 7,
18 .pad_bits = 1,
19 .val_bits = 8,
20 .read_flag_mask = BIT(0),
21 .readable_noinc_reg = adxl372_readable_noinc_reg,
22 };
23
adxl372_spi_probe(struct spi_device * spi)24 static int adxl372_spi_probe(struct spi_device *spi)
25 {
26 const struct spi_device_id *id = spi_get_device_id(spi);
27 struct regmap *regmap;
28
29 regmap = devm_regmap_init_spi(spi, &adxl372_spi_regmap_config);
30 if (IS_ERR(regmap))
31 return PTR_ERR(regmap);
32
33 return adxl372_probe(&spi->dev, regmap, spi->irq, id->name);
34 }
35
36 static const struct spi_device_id adxl372_spi_id[] = {
37 { "adxl372", 0 },
38 {}
39 };
40 MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
41
42 static const struct of_device_id adxl372_of_match[] = {
43 { .compatible = "adi,adxl372" },
44 { }
45 };
46 MODULE_DEVICE_TABLE(of, adxl372_of_match);
47
48 static struct spi_driver adxl372_spi_driver = {
49 .driver = {
50 .name = "adxl372_spi",
51 .of_match_table = adxl372_of_match,
52 },
53 .probe = adxl372_spi_probe,
54 .id_table = adxl372_spi_id,
55 };
56
57 module_spi_driver(adxl372_spi_driver);
58
59 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
60 MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
61 MODULE_LICENSE("GPL");
62