xref: /linux/drivers/iio/accel/adxl372_spi.c (revision fc2d791a43d3880496d1c729b8bd74d2c19cb4e7)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * ADXL371/ADXL372 3-Axis Digital Accelerometer SPI driver
4  *
5  * Copyright 2018 Analog Devices Inc.
6  */
7 
8 #include <linux/module.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/regmap.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 adxl372_chip_info *chip_info;
26 	struct regmap *regmap;
27 
28 	chip_info = spi_get_device_match_data(spi);
29 
30 	regmap = devm_regmap_init_spi(spi, &adxl372_spi_regmap_config);
31 	if (IS_ERR(regmap))
32 		return PTR_ERR(regmap);
33 
34 	return adxl372_probe(&spi->dev, regmap, spi->irq, chip_info);
35 }
36 
37 static const struct spi_device_id adxl372_spi_id[] = {
38 	{ "adxl371", (kernel_ulong_t)&adxl371_chip_info },
39 	{ "adxl372", (kernel_ulong_t)&adxl372_chip_info },
40 	{ }
41 };
42 MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
43 
44 static const struct of_device_id adxl372_of_match[] = {
45 	{ .compatible = "adi,adxl371", .data = &adxl371_chip_info },
46 	{ .compatible = "adi,adxl372", .data = &adxl372_chip_info },
47 	{ }
48 };
49 MODULE_DEVICE_TABLE(of, adxl372_of_match);
50 
51 static struct spi_driver adxl372_spi_driver = {
52 	.driver = {
53 		.name = "adxl372_spi",
54 		.of_match_table = adxl372_of_match,
55 	},
56 	.probe = adxl372_spi_probe,
57 	.id_table = adxl372_spi_id,
58 };
59 
60 module_spi_driver(adxl372_spi_driver);
61 
62 MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
63 MODULE_AUTHOR("Antoniu Miclaus <antoniu.miclaus@analog.com>");
64 MODULE_DESCRIPTION("Analog Devices ADXL371/ADXL372 3-axis accelerometer SPI driver");
65 MODULE_LICENSE("GPL");
66 MODULE_IMPORT_NS("IIO_ADXL372");
67