9 #include <linux/device.h>
10 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/module.h>
18 static int ade7854_spi_write_reg_8(
struct device *
dev,
24 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
34 st->tx[1] = (reg_address >> 8) & 0xFF;
35 st->tx[2] = reg_address & 0xFF;
36 st->tx[3] = value & 0xFF;
38 spi_message_init(&
msg);
39 spi_message_add_tail(&xfer, &
msg);
46 static int ade7854_spi_write_reg_16(
struct device *
dev,
52 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
62 st->tx[1] = (reg_address >> 8) & 0xFF;
63 st->tx[2] = reg_address & 0xFF;
64 st->tx[3] = (value >> 8) & 0xFF;
65 st->tx[4] = value & 0xFF;
67 spi_message_init(&
msg);
68 spi_message_add_tail(&xfer, &
msg);
75 static int ade7854_spi_write_reg_24(
struct device *
dev,
81 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
91 st->tx[1] = (reg_address >> 8) & 0xFF;
92 st->tx[2] = reg_address & 0xFF;
93 st->tx[3] = (value >> 16) & 0xFF;
94 st->tx[4] = (value >> 8) & 0xFF;
95 st->tx[5] = value & 0xFF;
97 spi_message_init(&
msg);
98 spi_message_add_tail(&xfer, &
msg);
105 static int ade7854_spi_write_reg_32(
struct device *
dev,
111 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
121 st->tx[1] = (reg_address >> 8) & 0xFF;
122 st->tx[2] = reg_address & 0xFF;
123 st->tx[3] = (value >> 24) & 0xFF;
124 st->tx[4] = (value >> 16) & 0xFF;
125 st->tx[5] = (value >> 8) & 0xFF;
126 st->tx[6] = value & 0xFF;
128 spi_message_init(&
msg);
129 spi_message_add_tail(&xfer, &
msg);
136 static int ade7854_spi_read_reg_8(
struct device *
dev,
141 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
159 st->tx[1] = (reg_address >> 8) & 0xFF;
160 st->tx[2] = reg_address & 0xFF;
162 spi_message_init(&
msg);
163 spi_message_add_tail(&xfers[0], &
msg);
164 spi_message_add_tail(&xfers[1], &
msg);
167 dev_err(&st->
spi->dev,
"problem when reading 8 bit register 0x%02X",
178 static int ade7854_spi_read_reg_16(
struct device *dev,
183 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
200 st->tx[1] = (reg_address >> 8) & 0xFF;
201 st->tx[2] = reg_address & 0xFF;
203 spi_message_init(&
msg);
204 spi_message_add_tail(&xfers[0], &
msg);
205 spi_message_add_tail(&xfers[1], &
msg);
208 dev_err(&st->
spi->dev,
"problem when reading 16 bit register 0x%02X",
219 static int ade7854_spi_read_reg_24(
struct device *dev,
224 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
242 st->tx[1] = (reg_address >> 8) & 0xFF;
243 st->tx[2] = reg_address & 0xFF;
245 spi_message_init(&
msg);
246 spi_message_add_tail(&xfers[0], &
msg);
247 spi_message_add_tail(&xfers[1], &
msg);
250 dev_err(&st->
spi->dev,
"problem when reading 24 bit register 0x%02X",
254 *val = (st->
rx[0] << 16) | (st->
rx[1] << 8) | st->
rx[2];
261 static int ade7854_spi_read_reg_32(
struct device *dev,
266 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
284 st->tx[1] = (reg_address >> 8) & 0xFF;
285 st->tx[2] = reg_address & 0xFF;
287 spi_message_init(&
msg);
288 spi_message_add_tail(&xfers[0], &
msg);
289 spi_message_add_tail(&xfers[1], &
msg);
292 dev_err(&st->
spi->dev,
"problem when reading 32 bit register 0x%02X",
310 if (indio_dev ==
NULL)
312 st = iio_priv(indio_dev);
313 spi_set_drvdata(spi, indio_dev);
353 .probe = ade7854_spi_probe,
355 .id_table = ade7854_id,