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
16static 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
24static 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
36static const struct spi_device_id adxl372_spi_id[] = {
37	{ "adxl372", 0 },
38	{}
39};
40MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
41
42static const struct of_device_id adxl372_of_match[] = {
43	{ .compatible = "adi,adxl372" },
44	{ }
45};
46MODULE_DEVICE_TABLE(of, adxl372_of_match);
47
48static 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
57module_spi_driver(adxl372_spi_driver);
58
59MODULE_AUTHOR("Stefan Popa <stefan.popa@analog.com>");
60MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
61MODULE_LICENSE("GPL");
62