9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/i2c.h>
12 #include <linux/slab.h>
13 #include <linux/module.h>
18 static int ade7854_i2c_write_reg_8(
struct device *
dev,
23 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
27 st->tx[0] = (reg_address >> 8) & 0xFF;
28 st->tx[1] = reg_address & 0xFF;
37 static int ade7854_i2c_write_reg_16(
struct device *
dev,
42 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
46 st->tx[0] = (reg_address >> 8) & 0xFF;
47 st->tx[1] = reg_address & 0xFF;
48 st->tx[2] = (value >> 8) & 0xFF;
49 st->tx[3] = value & 0xFF;
57 static int ade7854_i2c_write_reg_24(
struct device *
dev,
62 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
66 st->tx[0] = (reg_address >> 8) & 0xFF;
67 st->tx[1] = reg_address & 0xFF;
68 st->tx[2] = (value >> 16) & 0xFF;
69 st->tx[3] = (value >> 8) & 0xFF;
70 st->tx[4] = value & 0xFF;
78 static int ade7854_i2c_write_reg_32(
struct device *
dev,
83 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
87 st->tx[0] = (reg_address >> 8) & 0xFF;
88 st->tx[1] = reg_address & 0xFF;
89 st->tx[2] = (value >> 24) & 0xFF;
90 st->tx[3] = (value >> 16) & 0xFF;
91 st->tx[4] = (value >> 8) & 0xFF;
92 st->tx[5] = value & 0xFF;
100 static int ade7854_i2c_read_reg_8(
struct device *
dev,
104 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
109 st->tx[0] = (reg_address >> 8) & 0xFF;
110 st->tx[1] = reg_address & 0xFF;
126 static int ade7854_i2c_read_reg_16(
struct device *dev,
130 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
135 st->tx[0] = (reg_address >> 8) & 0xFF;
136 st->tx[1] = reg_address & 0xFF;
146 *val = (st->
rx[0] << 8) | st->
rx[1];
152 static int ade7854_i2c_read_reg_24(
struct device *dev,
156 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
161 st->tx[0] = (reg_address >> 8) & 0xFF;
162 st->tx[1] = reg_address & 0xFF;
172 *val = (st->
rx[0] << 16) | (st->
rx[1] << 8) | st->
rx[2];
178 static int ade7854_i2c_read_reg_32(
struct device *dev,
182 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
187 st->tx[0] = (reg_address >> 8) & 0xFF;
188 st->tx[1] = reg_address & 0xFF;
198 *val = (st->
rx[0] << 24) | (st->
rx[1] << 16) | (st->
rx[2] << 8) | st->
rx[3];
212 if (indio_dev ==
NULL)
214 st = iio_priv(indio_dev);
215 i2c_set_clientdata(client, indio_dev);
248 static struct i2c_driver ade7854_i2c_driver = {
252 .probe = ade7854_i2c_probe,
254 .id_table = ade7854_id,
259 MODULE_DESCRIPTION(
"Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC I2C Driver");