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

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
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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
+0 −1
Original line number Diff line number Diff line
@@ -8,5 +8,4 @@ obj-y += adc/
obj-y += addac/
obj-y += frequency/
obj-y += impedance-analyzer/
obj-y += meter/
obj-y += resolver/

drivers/staging/iio/meter/Kconfig

deleted100644 → 0
+0 −37
Original line number Diff line number Diff line
# 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
+0 −8
Original line number Diff line number Diff line
# 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
+0 −153
Original line number Diff line number Diff line
// 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");
Loading