xref: /linux/drivers/iio/accel/adxl372_spi.c (revision 23a12ddee1ce28065b71f14ccc695b5a0c8a64ff)
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/spi/spi.h>
11 
12 #include "adxl372.h"
13 
14 static const struct regmap_config adxl372_spi_regmap_config = {
15 	.reg_bits = 7,
16 	.pad_bits = 1,
17 	.val_bits = 8,
18 	.read_flag_mask = BIT(0),
19 	.readable_noinc_reg = adxl372_readable_noinc_reg,
20 };
21 
22 static int adxl372_spi_probe(struct spi_device *spi)
23 {
24 	const struct spi_device_id *id = spi_get_device_id(spi);
25 	struct regmap *regmap;
26 
27 	regmap = devm_regmap_init_spi(spi, &adxl372_spi_regmap_config);
28 	if (IS_ERR(regmap))
29 		return PTR_ERR(regmap);
30 
31 	return adxl372_probe(&spi->dev, regmap, spi->irq, id->name);
32 }
33 
34 static const struct spi_device_id adxl372_spi_id[] = {
35 	{ "adxl372", 0 },
36 	{}
37 };
38 MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
39 
40 static struct spi_driver adxl372_spi_driver = {
41 	.driver = {
42 		.name = "adxl372_spi",
43 	},
44 	.probe = adxl372_spi_probe,
45 	.id_table = adxl372_spi_id,
46 };
47 
48 module_spi_driver(adxl372_spi_driver);
49 
50 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
51 MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
52 MODULE_LICENSE("GPL");
53