Commit 6d5f85de authored by Jonathan Cameron's avatar Jonathan Cameron

staging: iio: meter: Drop ade7854 driver

This driver is so far from making correct use of the IIO infrastructure
and ABI that if someone wanted to make the driver suitable for moving
out of staging, they would more or less be starting from scratch.

As such there is little point in keeping the existing code in staging.

Note this was only user of the meter.h header so that is dropped.
There are no other drivers in the staging/iio/meter directory so drop
the build system files as well.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Acked-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20230129160805.747745-1-jic23@kernel.org
parent f22ed8d9
......@@ -10,7 +10,6 @@ source "drivers/staging/iio/adc/Kconfig"
source "drivers/staging/iio/addac/Kconfig"
source "drivers/staging/iio/frequency/Kconfig"
source "drivers/staging/iio/impedance-analyzer/Kconfig"
source "drivers/staging/iio/meter/Kconfig"
source "drivers/staging/iio/resolver/Kconfig"
endmenu
......@@ -8,5 +8,4 @@ obj-y += adc/
obj-y += addac/
obj-y += frequency/
obj-y += impedance-analyzer/
obj-y += meter/
obj-y += resolver/
# SPDX-License-Identifier: GPL-2.0
#
# IIO meter drivers configuration
#
menu "Active energy metering IC"
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.
To compile this driver as a module, choose M here: the
module will be called ade7854.
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.
endmenu
# SPDX-License-Identifier: GPL-2.0
#
# Makefile for metering ic drivers
#
obj-$(CONFIG_ADE7854) += ade7854.o
obj-$(CONFIG_ADE7854_I2C) += ade7854-i2c.o
obj-$(CONFIG_ADE7854_SPI) += ade7854-spi.o
// SPDX-License-Identifier: GPL-2.0+
/*
* ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver (I2C Bus)
*
* Copyright 2010 Analog Devices Inc.
*/
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
#include "ade7854.h"
static int ade7854_i2c_write_reg(struct device *dev,
u16 reg_address,
u32 val,
int bits)
{
int ret;
int count;
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(indio_dev);
mutex_lock(&st->buf_lock);
st->tx[0] = (reg_address >> 8) & 0xFF;
st->tx[1] = reg_address & 0xFF;
switch (bits) {
case 8:
st->tx[2] = val & 0xFF;
count = 3;
break;
case 16:
st->tx[2] = (val >> 8) & 0xFF;
st->tx[3] = val & 0xFF;
count = 4;
break;
case 24:
st->tx[2] = (val >> 16) & 0xFF;
st->tx[3] = (val >> 8) & 0xFF;
st->tx[4] = val & 0xFF;
count = 5;
break;
case 32:
st->tx[2] = (val >> 24) & 0xFF;
st->tx[3] = (val >> 16) & 0xFF;
st->tx[4] = (val >> 8) & 0xFF;
st->tx[5] = val & 0xFF;
count = 6;
break;
default:
ret = -EINVAL;
goto unlock;
}
ret = i2c_master_send(st->i2c, st->tx, count);
unlock:
mutex_unlock(&st->buf_lock);
if (ret < 0)
return ret;
return 0;
}
static int ade7854_i2c_read_reg(struct device *dev,
u16 reg_address,
u32 *val,
int bits)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(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 < 0)
goto unlock;
ret = i2c_master_recv(st->i2c, st->rx, bits);
if (ret < 0)
goto unlock;
switch (bits) {
case 8:
*val = st->rx[0];
break;
case 16:
*val = (st->rx[0] << 8) | st->rx[1];
break;
case 24:
*val = (st->rx[0] << 16) | (st->rx[1] << 8) | st->rx[2];
break;
case 32:
*val = (st->rx[0] << 24) | (st->rx[1] << 16) |
(st->rx[2] << 8) | st->rx[3];
break;
default:
ret = -EINVAL;
goto unlock;
}
unlock:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_i2c_probe(struct i2c_client *client)
{
struct ade7854_state *st;
struct iio_dev *indio_dev;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
st = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
st->read_reg = ade7854_i2c_read_reg;
st->write_reg = ade7854_i2c_write_reg;
st->i2c = client;
st->irq = client->irq;
return ade7854_probe(indio_dev, &client->dev);
}
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_new = ade7854_i2c_probe,
.id_table = ade7854_id,
};
module_i2c_driver(ade7854_i2c_driver);
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");
// SPDX-License-Identifier: GPL-2.0+
/*
* ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver (SPI Bus)
*
* Copyright 2010 Analog Devices Inc.
*/
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/spi/spi.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/iio/iio.h>
#include "ade7854.h"
static int ade7854_spi_write_reg(struct device *dev,
u16 reg_address,
u32 val,
int bits)
{
int ret;
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(indio_dev);
struct spi_transfer xfer = {
.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;
switch (bits) {
case 8:
st->tx[3] = val & 0xFF;
break;
case 16:
xfer.len = 5;
st->tx[3] = (val >> 8) & 0xFF;
st->tx[4] = val & 0xFF;
break;
case 24:
xfer.len = 6;
st->tx[3] = (val >> 16) & 0xFF;
st->tx[4] = (val >> 8) & 0xFF;
st->tx[5] = val & 0xFF;
break;
case 32:
xfer.len = 7;
st->tx[3] = (val >> 24) & 0xFF;
st->tx[4] = (val >> 16) & 0xFF;
st->tx[5] = (val >> 8) & 0xFF;
st->tx[6] = val & 0xFF;
break;
default:
ret = -EINVAL;
goto unlock;
}
ret = spi_sync_transfer(st->spi, &xfer, 1);
unlock:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_read_reg(struct device *dev,
u16 reg_address,
u32 *val,
int bits)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ade7854_state *st = iio_priv(indio_dev);
int ret;
struct spi_transfer xfers[] = {
{
.tx_buf = st->tx,
.bits_per_word = 8,
.len = 3,
}, {
.rx_buf = st->rx,
.bits_per_word = 8,
.len = bits,
}
};
mutex_lock(&st->buf_lock);
st->tx[0] = ADE7854_READ_REG;
st->tx[1] = (reg_address >> 8) & 0xFF;
st->tx[2] = reg_address & 0xFF;
ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
if (ret < 0) {
dev_err(&st->spi->dev, "problem when reading register 0x%02X",
reg_address);
goto unlock;
}
switch (bits) {
case 8:
*val = st->rx[0];
break;
case 16:
*val = be16_to_cpup((const __be16 *)st->rx);
break;
case 24:
*val = (st->rx[0] << 16) | (st->rx[1] << 8) | st->rx[2];
break;
case 32:
*val = be32_to_cpup((const __be32 *)st->rx);
break;
}
unlock:
mutex_unlock(&st->buf_lock);
return ret;
}
static int ade7854_spi_probe(struct spi_device *spi)
{
struct ade7854_state *st;
struct iio_dev *indio_dev;
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);
st->read_reg = ade7854_spi_read_reg;
st->write_reg = ade7854_spi_write_reg;
st->irq = spi->irq;
st->spi = spi;
return ade7854_probe(indio_dev, &spi->dev);
}
static const struct spi_device_id ade7854_id[] = {
{ "ade7854", 0 },
{ "ade7858", 0 },
{ "ade7868", 0 },
{ "ade7878", 0 },
{ }
};
MODULE_DEVICE_TABLE(spi, ade7854_id);
static struct spi_driver ade7854_driver = {
.driver = {
.name = "ade7854",
},
.probe = ade7854_spi_probe,
.id_table = ade7854_id,
};
module_spi_driver(ade7854_driver);
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
MODULE_DESCRIPTION("Analog Devices ADE7854/58/68/78 SPI Driver");
MODULE_LICENSE("GPL v2");
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
#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 1000
#define ADE7854_SPI_SLOW (u32)(300 * 1000)
#define ADE7854_SPI_BURST (u32)(1000 * 1000)
#define ADE7854_SPI_FAST (u32)(2000 * 1000)
/**
* struct ade7854_state - device instance specific data
* @spi: actual spi_device
* @read_reg Wrapper function for I2C and SPI read
* @write_reg Wrapper function for I2C and SPI write
* @indio_dev: industrial I/O device structure
* @buf_lock: mutex to protect tx and rx
* @tx: transmit buffer
* @rx: receive buffer
**/
struct ade7854_state {
struct spi_device *spi;
struct i2c_client *i2c;
int (*read_reg)(struct device *dev, u16 reg_address, u32 *val,
int bits);
int (*write_reg)(struct device *dev, u16 reg_address, u32 val,
int bits);
int irq;
struct mutex buf_lock;
u8 tx[ADE7854_MAX_TX] __aligned(IIO_DMA_MINALIGN);
u8 rx[ADE7854_MAX_RX];
};
int ade7854_probe(struct iio_dev *indio_dev, struct device *dev);
int ade7854_remove(struct iio_dev *indio_dev);
#endif
This diff is collapsed.
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