xref: /openbmc/linux/drivers/iio/accel/adxl355_spi.c (revision 982a8445)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * ADXL355 3-Axis Digital Accelerometer SPI driver
4  *
5  * Copyright (c) 2021 Puranjay Mohan <puranjay12@gmail.com>
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 "adxl355.h"
14 
15 static const struct regmap_config adxl355_spi_regmap_config = {
16 	.reg_bits = 7,
17 	.pad_bits = 1,
18 	.val_bits = 8,
19 	.read_flag_mask = BIT(0),
20 	.max_register = 0x2F,
21 	.rd_table = &adxl355_readable_regs_tbl,
22 	.wr_table = &adxl355_writeable_regs_tbl,
23 };
24 
25 static int adxl355_spi_probe(struct spi_device *spi)
26 {
27 	const struct spi_device_id *id = spi_get_device_id(spi);
28 	struct regmap *regmap;
29 
30 	regmap = devm_regmap_init_spi(spi, &adxl355_spi_regmap_config);
31 	if (IS_ERR(regmap)) {
32 		dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
33 			PTR_ERR(regmap));
34 
35 		return PTR_ERR(regmap);
36 	}
37 
38 	return adxl355_core_probe(&spi->dev, regmap, id->name);
39 }
40 
41 static const struct spi_device_id adxl355_spi_id[] = {
42 	{ "adxl355", 0 },
43 	{ }
44 };
45 MODULE_DEVICE_TABLE(spi, adxl355_spi_id);
46 
47 static const struct of_device_id adxl355_of_match[] = {
48 	{ .compatible = "adi,adxl355" },
49 	{ }
50 };
51 MODULE_DEVICE_TABLE(of, adxl355_of_match);
52 
53 static struct spi_driver adxl355_spi_driver = {
54 	.driver = {
55 		.name	= "adxl355_spi",
56 		.of_match_table = adxl355_of_match,
57 	},
58 	.probe		= adxl355_spi_probe,
59 	.id_table	= adxl355_spi_id,
60 };
61 module_spi_driver(adxl355_spi_driver);
62 
63 MODULE_AUTHOR("Puranjay Mohan <puranjay12@gmail.com>");
64 MODULE_DESCRIPTION("ADXL355 3-Axis Digital Accelerometer SPI driver");
65 MODULE_LICENSE("GPL v2");
66 MODULE_IMPORT_NS(IIO_ADXL355);
67