1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2021 Analog Devices, Inc.
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/regmap.h>
14 #define ADXL367_I2C_FIFO_DATA 0x42
16 struct adxl367_i2c_state {
17 struct regmap *regmap;
20 static bool adxl367_readable_noinc_reg(struct device *dev, unsigned int reg)
22 return reg == ADXL367_I2C_FIFO_DATA;
25 static int adxl367_i2c_read_fifo(void *context, __be16 *fifo_buf,
26 unsigned int fifo_entries)
28 struct adxl367_i2c_state *st = context;
30 return regmap_noinc_read(st->regmap, ADXL367_I2C_FIFO_DATA, fifo_buf,
31 fifo_entries * sizeof(*fifo_buf));
34 static const struct regmap_config adxl367_i2c_regmap_config = {
37 .readable_noinc_reg = adxl367_readable_noinc_reg,
40 static const struct adxl367_ops adxl367_i2c_ops = {
41 .read_fifo = adxl367_i2c_read_fifo,
44 static int adxl367_i2c_probe(struct i2c_client *client)
46 struct adxl367_i2c_state *st;
47 struct regmap *regmap;
49 st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL);
53 regmap = devm_regmap_init_i2c(client, &adxl367_i2c_regmap_config);
55 return PTR_ERR(regmap);
59 return adxl367_probe(&client->dev, &adxl367_i2c_ops, st, regmap,
63 static const struct i2c_device_id adxl367_i2c_id[] = {
67 MODULE_DEVICE_TABLE(i2c, adxl367_i2c_id);
69 static const struct of_device_id adxl367_of_match[] = {
70 { .compatible = "adi,adxl367" },
73 MODULE_DEVICE_TABLE(of, adxl367_of_match);
75 static struct i2c_driver adxl367_i2c_driver = {
77 .name = "adxl367_i2c",
78 .of_match_table = adxl367_of_match,
80 .probe_new = adxl367_i2c_probe,
81 .id_table = adxl367_i2c_id,
84 module_i2c_driver(adxl367_i2c_driver);
86 MODULE_IMPORT_NS(IIO_ADXL367);
88 MODULE_DESCRIPTION("Analog Devices ADXL367 3-axis accelerometer I2C driver");
89 MODULE_LICENSE("GPL");