cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

adxl367_i2c.c (2154B)


      1// SPDX-License-Identifier: GPL-2.0+
      2/*
      3 * Copyright (C) 2021 Analog Devices, Inc.
      4 * Author: Cosmin Tanislav <cosmin.tanislav@analog.com>
      5 */
      6
      7#include <linux/i2c.h>
      8#include <linux/mod_devicetable.h>
      9#include <linux/module.h>
     10#include <linux/regmap.h>
     11
     12#include "adxl367.h"
     13
     14#define ADXL367_I2C_FIFO_DATA	0x42
     15
     16struct adxl367_i2c_state {
     17	struct regmap *regmap;
     18};
     19
     20static bool adxl367_readable_noinc_reg(struct device *dev, unsigned int reg)
     21{
     22	return reg == ADXL367_I2C_FIFO_DATA;
     23}
     24
     25static int adxl367_i2c_read_fifo(void *context, __be16 *fifo_buf,
     26				 unsigned int fifo_entries)
     27{
     28	struct adxl367_i2c_state *st = context;
     29
     30	return regmap_noinc_read(st->regmap, ADXL367_I2C_FIFO_DATA, fifo_buf,
     31				 fifo_entries * sizeof(*fifo_buf));
     32}
     33
     34static const struct regmap_config adxl367_i2c_regmap_config = {
     35	.reg_bits = 8,
     36	.val_bits = 8,
     37	.readable_noinc_reg = adxl367_readable_noinc_reg,
     38};
     39
     40static const struct adxl367_ops adxl367_i2c_ops = {
     41	.read_fifo = adxl367_i2c_read_fifo,
     42};
     43
     44static int adxl367_i2c_probe(struct i2c_client *client,
     45			     const struct i2c_device_id *id)
     46{
     47	struct adxl367_i2c_state *st;
     48	struct regmap *regmap;
     49
     50	st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL);
     51	if (!st)
     52		return -ENOMEM;
     53
     54	regmap = devm_regmap_init_i2c(client, &adxl367_i2c_regmap_config);
     55	if (IS_ERR(regmap))
     56		return PTR_ERR(regmap);
     57
     58	st->regmap = regmap;
     59
     60	return adxl367_probe(&client->dev, &adxl367_i2c_ops, st, regmap,
     61			     client->irq);
     62}
     63
     64static const struct i2c_device_id adxl367_i2c_id[] = {
     65	{ "adxl367", 0 },
     66	{ },
     67};
     68MODULE_DEVICE_TABLE(i2c, adxl367_i2c_id);
     69
     70static const struct of_device_id adxl367_of_match[] = {
     71	{ .compatible = "adi,adxl367" },
     72	{ },
     73};
     74MODULE_DEVICE_TABLE(of, adxl367_of_match);
     75
     76static struct i2c_driver adxl367_i2c_driver = {
     77	.driver = {
     78		.name = "adxl367_i2c",
     79		.of_match_table = adxl367_of_match,
     80	},
     81	.probe = adxl367_i2c_probe,
     82	.id_table = adxl367_i2c_id,
     83};
     84
     85module_i2c_driver(adxl367_i2c_driver);
     86
     87MODULE_IMPORT_NS(IIO_ADXL367);
     88MODULE_AUTHOR("Cosmin Tanislav <cosmin.tanislav@analog.com>");
     89MODULE_DESCRIPTION("Analog Devices ADXL367 3-axis accelerometer I2C driver");
     90MODULE_LICENSE("GPL");