Commit 5b264a62 authored by Barry Song's avatar Barry Song Committed by Greg Kroah-Hartman

staging: iio: meter: new driver for ADE7854/58/68/78 devices

Signed-off-by: default avatarBarry Song <barry.song@analog.com>
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Acked-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 2919fa54
......@@ -32,3 +32,30 @@ config ADE7759
help
Say yes here to build support for Analog Devices ADE7758 Active Energy
Metering IC with di/dt Sensor Interface.
config ADE7854
tristate "Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver"
depends on SPI || I2C
help
Say yes here to build support for Analog Devices ADE7854/58/68/78 Polyphase
Multifunction Energy Metering IC Driver.
config ADE7854_I2C
tristate "support I2C bus connection"
depends on ADE7854 && I2C
default y
help
Say Y here if you have ADE7854/58/68/78 hooked to an I2C bus.
To compile this driver as a module, choose M here: the
module will be called ade7854-i2c.
config ADE7854_SPI
tristate "support SPI bus connection"
depends on ADE7854 && SPI
default y
help
Say Y here if you have ADE7854/58/68/78 hooked to a SPI bus.
To compile this driver as a module, choose M here: the
module will be called ade7854-spi.
......@@ -10,3 +10,6 @@ ade7758-$(CONFIG_IIO_RING_BUFFER) += ade7758_ring.o ade7758_trigger.o
obj-$(CONFIG_ADE7758) += ade7758.o
obj-$(CONFIG_ADE7759) += ade7759.o
obj-$(CONFIG_ADE7854) += ade7854.o
obj-$(CONFIG_ADE7854_I2C) += ade7854-i2c.o
obj-$(CONFIG_ADE7854_SPI) += ade7854-spi.o
/*
* ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver (I2C Bus)
*
* Copyright 2010 Analog Devices Inc.
*
* Licensed under the GPL-2 or later.
*/
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include "../iio.h"
#include "ade7854.h"
static int ade7854_i2c_write_reg_8(struct device *dev,
u16 reg_address,
u8 value)
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
st->tx[2] = value;
ret = i2c_master_send(st->i2c, st->tx, 3);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_write_reg_16(struct device *dev,
u16 reg_address,
u16 value)
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
st->tx[2] = (value >> 8) & 0xFF;
st->tx[3] = value & 0xFF;
ret = i2c_master_send(st->i2c, st->tx, 4);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_write_reg_24(struct device *dev,
u16 reg_address,
u32 value)
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
st->tx[2] = (value >> 16) & 0xFF;
st->tx[3] = (value >> 8) & 0xFF;
st->tx[4] = value & 0xFF;
ret = i2c_master_send(st->i2c, st->tx, 5);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_write_reg_32(struct device *dev,
u16 reg_address,
u32 value)
{
int ret;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
st->tx[2] = (value >> 24) & 0xFF;
st->tx[3] = (value >> 16) & 0xFF;
st->tx[4] = (value >> 8) & 0xFF;
st->tx[5] = value & 0xFF;
ret = i2c_master_send(st->i2c, st->tx, 6);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_read_reg_8(struct device *dev,
u16 reg_address,
u8 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
ret = i2c_master_send(st->i2c, st->tx, 2);
if (ret)
goto out;
ret = i2c_master_recv(st->i2c, st->rx, 1);
if (ret)
goto out;
*val = st->rx[0];
out:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_read_reg_16(struct device *dev,
u16 reg_address,
u16 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
ret = i2c_master_send(st->i2c, st->tx, 2);
if (ret)
goto out;
ret = i2c_master_recv(st->i2c, st->rx, 2);
if (ret)
goto out;
*val = (st->rx[0] << 8) | st->rx[1];
out:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_read_reg_24(struct device *dev,
u16 reg_address,
u32 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
ret = i2c_master_send(st->i2c, st->tx, 2);
if (ret)
goto out;
ret = i2c_master_recv(st->i2c, st->rx, 3);
if (ret)
goto out;
*val = (st->rx[0] << 16) | (st->rx[1] << 8) | st->rx[2];
out:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_read_reg_32(struct device *dev,
u16 reg_address,
u32 *val)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
ret = i2c_master_send(st->i2c, st->tx, 2);
if (ret)
goto out;
ret = i2c_master_recv(st->i2c, st->rx, 3);
if (ret)
goto out;
*val = (st->rx[0] << 24) | (st->rx[1] << 16) | (st->rx[2] << 8) | st->rx[3];
out:
mutex_unlock(&st->buf_lock);
return ret;
}
static int __devinit ade7854_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int ret;
struct ade7854_state *st = kzalloc(sizeof *st, GFP_KERNEL);
if (!st) {
ret = -ENOMEM;
return ret;
}
i2c_set_clientdata(client, st);
st->read_reg_8 = ade7854_i2c_read_reg_8;
st->read_reg_16 = ade7854_i2c_read_reg_16;
st->read_reg_24 = ade7854_i2c_read_reg_24;
st->read_reg_32 = ade7854_i2c_read_reg_32;
st->write_reg_8 = ade7854_i2c_write_reg_8;
st->write_reg_16 = ade7854_i2c_write_reg_16;
st->write_reg_24 = ade7854_i2c_write_reg_24;
st->write_reg_32 = ade7854_i2c_write_reg_32;
st->i2c = client;
st->irq = client->irq;
ret = ade7854_probe(st, &client->dev);
if (ret) {
kfree(st);
return ret;
}
return ret;
}
static int __devexit ade7854_i2c_remove(struct i2c_client *client)
{
return ade7854_remove(i2c_get_clientdata(client));
}
static const struct i2c_device_id ade7854_id[] = {
{ "ade7854", 0 },
{ "ade7858", 0 },
{ "ade7868", 0 },
{ "ade7878", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ade7854_id);
static struct i2c_driver ade7854_i2c_driver = {
.driver = {
.name = "ade7854",
},
.probe = ade7854_i2c_probe,
.remove = __devexit_p(ade7854_i2c_remove),
.id_table = ade7854_id,
};
static __init int ade7854_i2c_init(void)
{
return i2c_add_driver(&ade7854_i2c_driver);
}
module_init(ade7854_i2c_init);
static __exit void ade7854_i2c_exit(void)
{
i2c_del_driver(&ade7854_i2c_driver);
}
module_exit(ade7854_i2c_exit);
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
MODULE_DESCRIPTION("Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC I2C Driver");
MODULE_LICENSE("GPL v2");
/*
* ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver (SPI Bus)
*
* Copyright 2010 Analog Devices Inc.
*
* Licensed under the GPL-2 or later.
*/
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/spi/spi.h>
#include <linux/slab.h>
#include "../iio.h"
#include "ade7854.h"
static int ade7854_spi_write_reg_8(struct device *dev,
u16 reg_address,
u8 value)
{
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 4,
}
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_WRITE_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = value & 0xFF;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_write_reg_16(struct device *dev,
u16 reg_address,
u16 value)
{
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 5,
}
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_WRITE_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = (value >> 8) & 0xFF;
st->tx[4] = value & 0xFF;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_write_reg_24(struct device *dev,
u16 reg_address,
u32 value)
{
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 6,
}
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_WRITE_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = (value >> 16) & 0xFF;
st->tx[4] = (value >> 8) & 0xFF;
st->tx[5] = value & 0xFF;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_write_reg_32(struct device *dev,
u16 reg_address,
u32 value)
{
int ret;
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 7,
}
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_WRITE_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = (value >> 24) & 0xFF;
st->tx[4] = (value >> 16) & 0xFF;
st->tx[5] = (value >> 8) & 0xFF;
st->tx[6] = value & 0xFF;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_read_reg_8(struct device *dev,
u16 reg_address,
u8 *val)
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 4,
},
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_READ_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = 0;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
if (ret) {
dev_err(&st->spi->dev, "problem when reading 8 bit register 0x%02X",
reg_address);
goto error_ret;
}
*val = st->rx[3];
error_ret:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_read_reg_16(struct device *dev,
u16 reg_address,
u16 *val)
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 5,
},
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_READ_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = 0;
st->tx[4] = 0;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
if (ret) {
dev_err(&st->spi->dev, "problem when reading 16 bit register 0x%02X",
reg_address);
goto error_ret;
}
*val = (st->rx[3] << 8) | st->rx[4];
error_ret:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_read_reg_24(struct device *dev,
u16 reg_address,
u32 *val)
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 6,
},
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_READ_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = 0;
st->tx[4] = 0;
st->tx[5] = 0;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
if (ret) {
dev_err(&st->spi->dev, "problem when reading 24 bit register 0x%02X",
reg_address);
goto error_ret;
}
*val = (st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
error_ret:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_read_reg_32(struct device *dev,
u16 reg_address,
u32 *val)
{
struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 7,
},
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_READ_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
st->tx[3] = 0;
st->tx[4] = 0;
st->tx[5] = 0;
st->tx[6] = 0;
spi_message_init(&msg);
spi_message_add_tail(xfers, &msg);
ret = spi_sync(st->spi, &msg);
if (ret) {
dev_err(&st->spi->dev, "problem when reading 32 bit register 0x%02X",
reg_address);
goto error_ret;
}
*val = (st->rx[3] << 24) | (st->rx[4] << 16) | (st->rx[5] << 8) | st->rx[6];
error_ret:
mutex_unlock(&st->buf_lock);
return ret;
}
static int __devinit ade7854_spi_probe(struct spi_device *spi)
{
int ret;
struct ade7854_state *st = kzalloc(sizeof *st, GFP_KERNEL);
if (!st) {
ret = -ENOMEM;
return ret;
}
spi_set_drvdata(spi, st);
st->read_reg_8 = ade7854_spi_read_reg_8;
st->read_reg_16 = ade7854_spi_read_reg_16;
st->read_reg_24 = ade7854_spi_read_reg_24;
st->read_reg_32 = ade7854_spi_read_reg_32;
st->write_reg_8 = ade7854_spi_write_reg_8;
st->write_reg_16 = ade7854_spi_write_reg_16;
st->write_reg_24 = ade7854_spi_write_reg_24;
st->write_reg_32 = ade7854_spi_write_reg_32;
st->irq = spi->irq;
st->spi = spi;
ret = ade7854_probe(st, &spi->dev);
if (ret) {
kfree(st);
return ret;
}
return 0;
}
static int ade7854_spi_remove(struct spi_device *spi)
{
ade7854_remove(spi_get_drvdata(spi));
return 0;
}
static struct spi_driver ade7854_driver = {
.driver = {
.name = "ade7854",
.owner = THIS_MODULE,
},
.probe = ade7854_spi_probe,
.remove = __devexit_p(ade7854_spi_remove),
};
static __init int ade7854_init(void)
{
return spi_register_driver(&ade7854_driver);
}
module_init(ade7854_init);
static __exit void ade7854_exit(void)
{
spi_unregister_driver(&ade7854_driver);
}
module_exit(ade7854_exit);
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
MODULE_DESCRIPTION("Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC SPI Driver");
MODULE_LICENSE("GPL v2");
This diff is collapsed.
#ifndef _ADE7854_H
#define _ADE7854_H
#define ADE7854_AIGAIN 0x4380
#define ADE7854_AVGAIN 0x4381
#define ADE7854_BIGAIN 0x4382
#define ADE7854_BVGAIN 0x4383
#define ADE7854_CIGAIN 0x4384
#define ADE7854_CVGAIN 0x4385
#define ADE7854_NIGAIN 0x4386
#define ADE7854_AIRMSOS 0x4387
#define ADE7854_AVRMSOS 0x4388
#define ADE7854_BIRMSOS 0x4389
#define ADE7854_BVRMSOS 0x438A
#define ADE7854_CIRMSOS 0x438B
#define ADE7854_CVRMSOS 0x438C
#define ADE7854_NIRMSOS 0x438D
#define ADE7854_AVAGAIN 0x438E
#define ADE7854_BVAGAIN 0x438F
#define ADE7854_CVAGAIN 0x4390
#define ADE7854_AWGAIN 0x4391
#define ADE7854_AWATTOS 0x4392
#define ADE7854_BWGAIN 0x4393
#define ADE7854_BWATTOS 0x4394
#define ADE7854_CWGAIN 0x4395
#define ADE7854_CWATTOS 0x4396
#define ADE7854_AVARGAIN 0x4397
#define ADE7854_AVAROS 0x4398
#define ADE7854_BVARGAIN 0x4399
#define ADE7854_BVAROS 0x439A
#define ADE7854_CVARGAIN 0x439B
#define ADE7854_CVAROS 0x439C
#define ADE7854_AFWGAIN 0x439D
#define ADE7854_AFWATTOS 0x439E
#define ADE7854_BFWGAIN 0x439F
#define ADE7854_BFWATTOS 0x43A0
#define ADE7854_CFWGAIN 0x43A1
#define ADE7854_CFWATTOS 0x43A2
#define ADE7854_AFVARGAIN 0x43A3
#define ADE7854_AFVAROS 0x43A4
#define ADE7854_BFVARGAIN 0x43A5
#define ADE7854_BFVAROS 0x43A6
#define ADE7854_CFVARGAIN 0x43A7
#define ADE7854_CFVAROS 0x43A8
#define ADE7854_VATHR1 0x43A9
#define ADE7854_VATHR0 0x43AA
#define ADE7854_WTHR1 0x43AB
#define ADE7854_WTHR0 0x43AC
#define ADE7854_VARTHR1 0x43AD
#define ADE7854_VARTHR0 0x43AE
#define ADE7854_RSV 0x43AF
#define ADE7854_VANOLOAD 0x43B0
#define ADE7854_APNOLOAD 0x43B1
#define ADE7854_VARNOLOAD 0x43B2
#define ADE7854_VLEVEL 0x43B3
#define ADE7854_DICOEFF 0x43B5
#define ADE7854_HPFDIS 0x43B6
#define ADE7854_ISUMLVL 0x43B8
#define ADE7854_ISUM 0x43BF
#define ADE7854_AIRMS 0x43C0
#define ADE7854_AVRMS 0x43C1
#define ADE7854_BIRMS 0x43C2
#define ADE7854_BVRMS 0x43C3
#define ADE7854_CIRMS 0x43C4
#define ADE7854_CVRMS 0x43C5
#define ADE7854_NIRMS 0x43C6
#define ADE7854_RUN 0xE228
#define ADE7854_AWATTHR 0xE400
#define ADE7854_BWATTHR 0xE401
#define ADE7854_CWATTHR 0xE402
#define ADE7854_AFWATTHR 0xE403
#define ADE7854_BFWATTHR 0xE404
#define ADE7854_CFWATTHR 0xE405
#define ADE7854_AVARHR 0xE406
#define ADE7854_BVARHR 0xE407
#define ADE7854_CVARHR 0xE408
#define ADE7854_AFVARHR 0xE409
#define ADE7854_BFVARHR 0xE40A
#define ADE7854_CFVARHR 0xE40B
#define ADE7854_AVAHR 0xE40C
#define ADE7854_BVAHR 0xE40D
#define ADE7854_CVAHR 0xE40E
#define ADE7854_IPEAK 0xE500
#define ADE7854_VPEAK 0xE501
#define ADE7854_STATUS0 0xE502
#define ADE7854_STATUS1 0xE503
#define ADE7854_OILVL 0xE507
#define ADE7854_OVLVL 0xE508
#define ADE7854_SAGLVL 0xE509
#define ADE7854_MASK0 0xE50A
#define ADE7854_MASK1 0xE50B
#define ADE7854_IAWV 0xE50C
#define ADE7854_IBWV 0xE50D
#define ADE7854_ICWV 0xE50E
#define ADE7854_VAWV 0xE510
#define ADE7854_VBWV 0xE511
#define ADE7854_VCWV 0xE512
#define ADE7854_AWATT 0xE513
#define ADE7854_BWATT 0xE514
#define ADE7854_CWATT 0xE515
#define ADE7854_AVA 0xE519
#define ADE7854_BVA 0xE51A
#define ADE7854_CVA 0xE51B
#define ADE7854_CHECKSUM 0xE51F
#define ADE7854_VNOM 0xE520
#define ADE7854_PHSTATUS 0xE600
#define ADE7854_ANGLE0 0xE601
#define ADE7854_ANGLE1 0xE602
#define ADE7854_ANGLE2 0xE603
#define ADE7854_PERIOD 0xE607
#define ADE7854_PHNOLOAD 0xE608
#define ADE7854_LINECYC 0xE60C
#define ADE7854_ZXTOUT 0xE60D
#define ADE7854_COMPMODE 0xE60E
#define ADE7854_GAIN 0xE60F
#define ADE7854_CFMODE 0xE610
#define ADE7854_CF1DEN 0xE611
#define ADE7854_CF2DEN 0xE612
#define ADE7854_CF3DEN 0xE613
#define ADE7854_APHCAL 0xE614
#define ADE7854_BPHCAL 0xE615
#define ADE7854_CPHCAL 0xE616
#define ADE7854_PHSIGN 0xE617
#define ADE7854_CONFIG 0xE618
#define ADE7854_MMODE 0xE700
#define ADE7854_ACCMODE 0xE701
#define ADE7854_LCYCMODE 0xE702
#define ADE7854_PEAKCYC 0xE703
#define ADE7854_SAGCYC 0xE704
#define ADE7854_CFCYC 0xE705
#define ADE7854_HSDC_CFG 0xE706
#define ADE7854_CONFIG2 0xEC01
#define ADE7854_READ_REG 0x1
#define ADE7854_WRITE_REG 0x0
#define ADE7854_MAX_TX 7
#define ADE7854_MAX_RX 7
#define ADE7854_STARTUP_DELAY 1
#define ADE7854_SPI_SLOW (u32)(300 * 1000)
#define ADE7854_SPI_BURST (u32)(1000 * 1000)
#define ADE7854_SPI_FAST (u32)(2000 * 1000)
#define DRIVER_NAME "ade7854"
/**
* struct ade7854_state - device instance specific data
* @spi: actual spi_device
* @work_trigger_to_ring: bh for triggered event handling
* @inter: used to check if new interrupt has been triggered
* @last_timestamp: passing timestamp from th to bh of interrupt handler
* @indio_dev: industrial I/O device structure
* @trig: data ready trigger registered with iio
* @tx: transmit buffer
* @rx: recieve buffer
* @buf_lock: mutex to protect tx and rx
**/
struct ade7854_state {
struct spi_device *spi;
struct i2c_client *i2c;
struct work_struct work_trigger_to_ring;
s64 last_timestamp;
struct iio_dev *indio_dev;
struct iio_trigger *trig;
u8 *tx;
u8 *rx;
int (*read_reg_8) (struct device *, u16, u8 *);
int (*read_reg_16) (struct device *, u16, u16 *);
int (*read_reg_24) (struct device *, u16, u32 *);
int (*read_reg_32) (struct device *, u16, u32 *);
int (*write_reg_8) (struct device *, u16, u8);
int (*write_reg_16) (struct device *, u16, u16);
int (*write_reg_24) (struct device *, u16, u32);
int (*write_reg_32) (struct device *, u16, u32);
int irq;
struct mutex buf_lock;
};
extern int ade7854_probe(struct ade7854_state *st, struct device *dev);
extern int ade7854_remove(struct ade7854_state *st);
#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
/* At the moment triggers are only used for ring buffer
* filling. This may change!
*/
enum ade7854_scan {
ADE7854_SCAN_PHA_V,
ADE7854_SCAN_PHB_V,
ADE7854_SCAN_PHC_V,
ADE7854_SCAN_PHA_I,
ADE7854_SCAN_PHB_I,
ADE7854_SCAN_PHC_I,
};
void ade7854_remove_trigger(struct iio_dev *indio_dev);
int ade7854_probe_trigger(struct iio_dev *indio_dev);
ssize_t ade7854_read_data_from_ring(struct device *dev,
struct device_attribute *attr,
char *buf);
int ade7854_configure_ring(struct iio_dev *indio_dev);
void ade7854_unconfigure_ring(struct iio_dev *indio_dev);
int ade7854_initialize_ring(struct iio_ring_buffer *ring);
void ade7854_uninitialize_ring(struct iio_ring_buffer *ring);
#else /* CONFIG_IIO_RING_BUFFER */
static inline void ade7854_remove_trigger(struct iio_dev *indio_dev)
{
}
static inline int ade7854_probe_trigger(struct iio_dev *indio_dev)
{
return 0;
}
static inline ssize_t
ade7854_read_data_from_ring(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return 0;
}
static inline int ade7854_configure_ring(struct iio_dev *indio_dev)
{
return 0;
}
static inline void ade7854_unconfigure_ring(struct iio_dev *indio_dev)
{
}
static inline int ade7854_initialize_ring(struct iio_ring_buffer *ring)
{
return 0;
}
static inline void ade7854_uninitialize_ring(struct iio_ring_buffer *ring)
{
}
#endif /* CONFIG_IIO_RING_BUFFER */
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment