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