1 // SPDX-License-Identifier: GPL-2.0-only
3 * ADXL355 3-Axis Digital Accelerometer SPI driver
5 * Copyright (c) 2021 Puranjay Mohan <puranjay12@gmail.com>
8 #include <linux/module.h>
9 #include <linux/mod_devicetable.h>
10 #include <linux/regmap.h>
11 #include <linux/spi/spi.h>
12 #include <linux/property.h>
16 static const struct regmap_config adxl355_spi_regmap_config
= {
20 .read_flag_mask
= BIT(0),
22 .rd_table
= &adxl355_readable_regs_tbl
,
23 .wr_table
= &adxl355_writeable_regs_tbl
,
26 static int adxl355_spi_probe(struct spi_device
*spi
)
28 const struct adxl355_chip_info
*chip_data
;
29 struct regmap
*regmap
;
31 chip_data
= spi_get_device_match_data(spi
);
35 regmap
= devm_regmap_init_spi(spi
, &adxl355_spi_regmap_config
);
37 dev_err(&spi
->dev
, "Error initializing spi regmap: %ld\n",
40 return PTR_ERR(regmap
);
43 return adxl355_core_probe(&spi
->dev
, regmap
, chip_data
);
46 static const struct spi_device_id adxl355_spi_id
[] = {
47 { "adxl355", (kernel_ulong_t
)&adxl35x_chip_info
[ADXL355
] },
48 { "adxl359", (kernel_ulong_t
)&adxl35x_chip_info
[ADXL359
] },
51 MODULE_DEVICE_TABLE(spi
, adxl355_spi_id
);
53 static const struct of_device_id adxl355_of_match
[] = {
54 { .compatible
= "adi,adxl355", .data
= &adxl35x_chip_info
[ADXL355
] },
55 { .compatible
= "adi,adxl359", .data
= &adxl35x_chip_info
[ADXL359
] },
58 MODULE_DEVICE_TABLE(of
, adxl355_of_match
);
60 static struct spi_driver adxl355_spi_driver
= {
62 .name
= "adxl355_spi",
63 .of_match_table
= adxl355_of_match
,
65 .probe
= adxl355_spi_probe
,
66 .id_table
= adxl355_spi_id
,
68 module_spi_driver(adxl355_spi_driver
);
70 MODULE_AUTHOR("Puranjay Mohan <puranjay12@gmail.com>");
71 MODULE_DESCRIPTION("ADXL355 3-Axis Digital Accelerometer SPI driver");
72 MODULE_LICENSE("GPL v2");
73 MODULE_IMPORT_NS(IIO_ADXL355
);