0001
0002
0003
0004
0005
0006
0007 #include <linux/i2c.h>
0008 #include <linux/mod_devicetable.h>
0009 #include <linux/module.h>
0010 #include <linux/regmap.h>
0011
0012 #include "adxl367.h"
0013
0014 #define ADXL367_I2C_FIFO_DATA 0x42
0015
0016 struct adxl367_i2c_state {
0017 struct regmap *regmap;
0018 };
0019
0020 static bool adxl367_readable_noinc_reg(struct device *dev, unsigned int reg)
0021 {
0022 return reg == ADXL367_I2C_FIFO_DATA;
0023 }
0024
0025 static int adxl367_i2c_read_fifo(void *context, __be16 *fifo_buf,
0026 unsigned int fifo_entries)
0027 {
0028 struct adxl367_i2c_state *st = context;
0029
0030 return regmap_noinc_read(st->regmap, ADXL367_I2C_FIFO_DATA, fifo_buf,
0031 fifo_entries * sizeof(*fifo_buf));
0032 }
0033
0034 static const struct regmap_config adxl367_i2c_regmap_config = {
0035 .reg_bits = 8,
0036 .val_bits = 8,
0037 .readable_noinc_reg = adxl367_readable_noinc_reg,
0038 };
0039
0040 static const struct adxl367_ops adxl367_i2c_ops = {
0041 .read_fifo = adxl367_i2c_read_fifo,
0042 };
0043
0044 static int adxl367_i2c_probe(struct i2c_client *client,
0045 const struct i2c_device_id *id)
0046 {
0047 struct adxl367_i2c_state *st;
0048 struct regmap *regmap;
0049
0050 st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL);
0051 if (!st)
0052 return -ENOMEM;
0053
0054 regmap = devm_regmap_init_i2c(client, &adxl367_i2c_regmap_config);
0055 if (IS_ERR(regmap))
0056 return PTR_ERR(regmap);
0057
0058 st->regmap = regmap;
0059
0060 return adxl367_probe(&client->dev, &adxl367_i2c_ops, st, regmap,
0061 client->irq);
0062 }
0063
0064 static const struct i2c_device_id adxl367_i2c_id[] = {
0065 { "adxl367", 0 },
0066 { },
0067 };
0068 MODULE_DEVICE_TABLE(i2c, adxl367_i2c_id);
0069
0070 static const struct of_device_id adxl367_of_match[] = {
0071 { .compatible = "adi,adxl367" },
0072 { },
0073 };
0074 MODULE_DEVICE_TABLE(of, adxl367_of_match);
0075
0076 static struct i2c_driver adxl367_i2c_driver = {
0077 .driver = {
0078 .name = "adxl367_i2c",
0079 .of_match_table = adxl367_of_match,
0080 },
0081 .probe = adxl367_i2c_probe,
0082 .id_table = adxl367_i2c_id,
0083 };
0084
0085 module_i2c_driver(adxl367_i2c_driver);
0086
0087 MODULE_IMPORT_NS(IIO_ADXL367);
0088 MODULE_AUTHOR("Cosmin Tanislav <cosmin.tanislav@analog.com>");
0089 MODULE_DESCRIPTION("Analog Devices ADXL367 3-axis accelerometer I2C driver");
0090 MODULE_LICENSE("GPL");