xref: /linux/drivers/iio/accel/adxl372_spi.c (revision 8dd765a5d769c521d73931850d1c8708fbc490cb)
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/spi/spi.h>
12 
13 #include "adxl372.h"
14 
15 static const struct regmap_config adxl372_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 = adxl372_readable_noinc_reg,
21 };
22 
23 static int adxl372_spi_probe(struct spi_device *spi)
24 {
25 	const struct spi_device_id *id = spi_get_device_id(spi);
26 	struct regmap *regmap;
27 
28 	regmap = devm_regmap_init_spi(spi, &adxl372_spi_regmap_config);
29 	if (IS_ERR(regmap))
30 		return PTR_ERR(regmap);
31 
32 	return adxl372_probe(&spi->dev, regmap, spi->irq, id->name);
33 }
34 
35 static const struct spi_device_id adxl372_spi_id[] = {
36 	{ "adxl372", 0 },
37 	{}
38 };
39 MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
40 
41 static const struct of_device_id adxl372_of_match[] = {
42 	{ .compatible = "adi,adxl372" },
43 	{ }
44 };
45 MODULE_DEVICE_TABLE(of, adxl372_of_match);
46 
47 static struct spi_driver adxl372_spi_driver = {
48 	.driver = {
49 		.name = "adxl372_spi",
50 		.of_match_table = adxl372_of_match,
51 	},
52 	.probe = adxl372_spi_probe,
53 	.id_table = adxl372_spi_id,
54 };
55 
56 module_spi_driver(adxl372_spi_driver);
57 
58 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
59 MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
60 MODULE_LICENSE("GPL");
61 MODULE_IMPORT_NS(IIO_ADXL372);
62