mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-23 17:58:14 -04:00
hwmon: (ads7871) Convert to hwmon_device_register_with_info
Convert the ads7871 driver from the legacy hwmon_device_register() to the modern hwmon_device_register_with_info() API. This migration simplifies the driver by using the structured hwmon_channel_info approach and prepares the codebase for the transition to a shared DMA-safe buffer. While at it, fix checkpatch violations. Signed-off-by: Tabrez Ahmed <tabreztalks@gmail.com> Link: https://lore.kernel.org/r/20260502020844.110038-3-tabreztalks@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
committed by
Guenter Roeck
parent
07668f5ca3
commit
a2b0986398
@@ -56,7 +56,6 @@
|
||||
#include <linux/init.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
@@ -66,6 +65,16 @@ struct ads7871_data {
|
||||
struct spi_device *spi;
|
||||
};
|
||||
|
||||
static umode_t ads7871_is_visible(const void *data,
|
||||
enum hwmon_sensor_types type,
|
||||
u32 attr, int channel)
|
||||
{
|
||||
if (type == hwmon_in && attr == hwmon_in_input)
|
||||
return 0444;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ads7871_read_reg8(struct spi_device *spi, int reg)
|
||||
{
|
||||
int ret;
|
||||
@@ -89,19 +98,20 @@ static int ads7871_read_reg16(struct spi_device *spi, int reg)
|
||||
static int ads7871_write_reg8(struct spi_device *spi, int reg, u8 val)
|
||||
{
|
||||
u8 tmp[2] = {reg, val};
|
||||
|
||||
return spi_write(spi, tmp, sizeof(tmp));
|
||||
}
|
||||
|
||||
static ssize_t voltage_show(struct device *dev, struct device_attribute *da,
|
||||
char *buf)
|
||||
static int ads7871_read(struct device *dev, enum hwmon_sensor_types type,
|
||||
u32 attr, int channel, long *val)
|
||||
{
|
||||
struct ads7871_data *pdata = dev_get_drvdata(dev);
|
||||
struct spi_device *spi = pdata->spi;
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
int ret, val, i = 0;
|
||||
uint8_t channel, mux_cnv;
|
||||
int ret, raw_val, i = 0;
|
||||
u8 mux_cnv;
|
||||
|
||||
channel = attr->index;
|
||||
if (type != hwmon_in || attr != hwmon_in_input)
|
||||
return -EOPNOTSUPP;
|
||||
/*
|
||||
* TODO: add support for conversions
|
||||
* other than single ended with a gain of 1
|
||||
@@ -131,39 +141,34 @@ static ssize_t voltage_show(struct device *dev, struct device_attribute *da,
|
||||
}
|
||||
|
||||
if (mux_cnv == 0) {
|
||||
val = ads7871_read_reg16(spi, REG_LS_BYTE);
|
||||
if (val < 0)
|
||||
return val;
|
||||
raw_val = ads7871_read_reg16(spi, REG_LS_BYTE);
|
||||
if (raw_val < 0)
|
||||
return raw_val;
|
||||
|
||||
/*result in volts*10000 = (val/8192)*2.5*10000*/
|
||||
val = ((val >> 2) * 25000) / 8192;
|
||||
return sysfs_emit(buf, "%d\n", val);
|
||||
*val = ((raw_val >> 2) * 25000) / 8192;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
static SENSOR_DEVICE_ATTR_RO(in0_input, voltage, 0);
|
||||
static SENSOR_DEVICE_ATTR_RO(in1_input, voltage, 1);
|
||||
static SENSOR_DEVICE_ATTR_RO(in2_input, voltage, 2);
|
||||
static SENSOR_DEVICE_ATTR_RO(in3_input, voltage, 3);
|
||||
static SENSOR_DEVICE_ATTR_RO(in4_input, voltage, 4);
|
||||
static SENSOR_DEVICE_ATTR_RO(in5_input, voltage, 5);
|
||||
static SENSOR_DEVICE_ATTR_RO(in6_input, voltage, 6);
|
||||
static SENSOR_DEVICE_ATTR_RO(in7_input, voltage, 7);
|
||||
|
||||
static struct attribute *ads7871_attrs[] = {
|
||||
&sensor_dev_attr_in0_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in2_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in3_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in4_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in5_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in6_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in7_input.dev_attr.attr,
|
||||
static const struct hwmon_channel_info * const ads7871_info[] = {
|
||||
HWMON_CHANNEL_INFO(in,
|
||||
HWMON_I_INPUT, HWMON_I_INPUT, HWMON_I_INPUT, HWMON_I_INPUT,
|
||||
HWMON_I_INPUT, HWMON_I_INPUT, HWMON_I_INPUT, HWMON_I_INPUT),
|
||||
NULL
|
||||
};
|
||||
|
||||
ATTRIBUTE_GROUPS(ads7871);
|
||||
static const struct hwmon_ops ads7871_hwmon_ops = {
|
||||
.is_visible = ads7871_is_visible,
|
||||
.read = ads7871_read,
|
||||
};
|
||||
|
||||
static const struct hwmon_chip_info ads7871_chip_info = {
|
||||
.ops = &ads7871_hwmon_ops,
|
||||
.info = ads7871_info,
|
||||
};
|
||||
|
||||
static int ads7871_probe(struct spi_device *spi)
|
||||
{
|
||||
@@ -198,10 +203,10 @@ static int ads7871_probe(struct spi_device *spi)
|
||||
return -ENOMEM;
|
||||
|
||||
pdata->spi = spi;
|
||||
|
||||
hwmon_dev = devm_hwmon_device_register_with_groups(dev, spi->modalias,
|
||||
pdata,
|
||||
ads7871_groups);
|
||||
hwmon_dev = devm_hwmon_device_register_with_info(dev, spi->modalias,
|
||||
pdata,
|
||||
&ads7871_chip_info,
|
||||
NULL);
|
||||
return PTR_ERR_OR_ZERO(hwmon_dev);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user