drm/tests: hdmi: Fix memory leaks in drm_display_mode_from_cea_vic()
[drm/drm-misc.git] / drivers / iio / accel / adxl367_i2c.c
blobdeb82a43ec36fb8745c0c408e3b027501d3fb752
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2021 Analog Devices, Inc.
4 * Author: Cosmin Tanislav <cosmin.tanislav@analog.com>
5 */
7 #include <linux/i2c.h>
8 #include <linux/mod_devicetable.h>
9 #include <linux/module.h>
10 #include <linux/regmap.h>
12 #include "adxl367.h"
14 #define ADXL367_I2C_FIFO_DATA 0x18
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 = {
35 .reg_bits = 8,
36 .val_bits = 8,
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);
50 if (!st)
51 return -ENOMEM;
53 regmap = devm_regmap_init_i2c(client, &adxl367_i2c_regmap_config);
54 if (IS_ERR(regmap))
55 return PTR_ERR(regmap);
57 st->regmap = regmap;
59 return adxl367_probe(&client->dev, &adxl367_i2c_ops, st, regmap,
60 client->irq);
63 static const struct i2c_device_id adxl367_i2c_id[] = {
64 { "adxl367" },
65 { }
67 MODULE_DEVICE_TABLE(i2c, adxl367_i2c_id);
69 static const struct of_device_id adxl367_of_match[] = {
70 { .compatible = "adi,adxl367" },
71 { },
73 MODULE_DEVICE_TABLE(of, adxl367_of_match);
75 static struct i2c_driver adxl367_i2c_driver = {
76 .driver = {
77 .name = "adxl367_i2c",
78 .of_match_table = adxl367_of_match,
80 .probe = adxl367_i2c_probe,
81 .id_table = adxl367_i2c_id,
84 module_i2c_driver(adxl367_i2c_driver);
86 MODULE_IMPORT_NS(IIO_ADXL367);
87 MODULE_AUTHOR("Cosmin Tanislav <cosmin.tanislav@analog.com>");
88 MODULE_DESCRIPTION("Analog Devices ADXL367 3-axis accelerometer I2C driver");
89 MODULE_LICENSE("GPL");