2017-03-23 00:40:00

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 1/4] w83627ehf: Use hwmon_device_register_with_info and sensor groups

This patch replaces the old, deprecated call to hwmon_device_register
with the new hwmon_device_register_with_info and converts the whole
driver to the new hwmon interface using the hwmon_chip_info methods
and the attribute_group method.

Unfortunately this makes the patch quite large, but it is the most
sensible way to do so, without doing everything twice.

All standard attributes were converted to the corresponding
hwmon_chip_info methods.
For some functions a hwmon channel to device channel conversion had to
be performed, e.g. hwmon_in_alarm has the info for alert_5 in channel 8.

All non-standard attributes are converted to the attribute_group method,
by
- adding them statically to the attribute_group if they are available
for all variants of devices supported by this driver
- adding them at probe time to the attribute_group if the availability
is depending on the actual chip type.
The appropriate count of entries was reserved.

As a pre-condition a reference to the sio_data structure was moved into
w83627ehf_data for easier retrieval of the information, since this is
much easier than trying to access the platform_data.

The driver is now much more "checkpatch clean" than it used to be, but
still not completely.
The conversion saves about 20k in the resulting .ko

Tested with a NCT6776F chip.

Signed-off-by: Peter Huewe <[email protected]>
---
Target-Branch: groeck/hwmon

Please cherry-pick
46dc4a97 hwmon: Constify str parameter of hwmon_ops->read_string
before this patch series


drivers/hwmon/w83627ehf.c | 1387 +++++++++++++++++++++------------------------
1 file changed, 648 insertions(+), 739 deletions(-)

diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index ab346ed142de..785ddd47c588 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1,6 +1,7 @@
/*
* w83627ehf - Driver for the hardware monitoring functionality of
* the Winbond W83627EHF Super-I/O chip
+ * Copyright (C) 2017 Peter Huewe <[email protected]>
* Copyright (C) 2005-2012 Jean Delvare <[email protected]>
* Copyright (C) 2006 Yuan Mu (Winbond),
* Rudolf Marek <[email protected]>
@@ -420,6 +421,11 @@ static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scale_in)
/*
* Data structures and manipulation thereof
*/
+struct w83627ehf_sio_data {
+ int sioreg;
+ enum kinds kind;
+};
+

struct w83627ehf_data {
int addr; /* IO base of hw monitor block */
@@ -508,11 +514,7 @@ struct w83627ehf_data {
u8 fandiv1;
u8 fandiv2;
#endif
-};
-
-struct w83627ehf_sio_data {
- int sioreg;
- enum kinds kind;
+ struct w83627ehf_sio_data *sio_data;
};

/*
@@ -673,7 +675,7 @@ static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr)
static void w83627ehf_write_fan_div_common(struct device *dev,
struct w83627ehf_data *data, int nr)
{
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
+ struct w83627ehf_sio_data *sio_data = data->sio_data;

if (sio_data->kind == nct6776)
; /* no dividers, do nothing */
@@ -724,14 +726,14 @@ static void w83627ehf_update_fan_div(struct w83627ehf_data *data)
static void w83627ehf_update_fan_div_common(struct device *dev,
struct w83627ehf_data *data)
{
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
-
- if (sio_data->kind == nct6776)
- ; /* no dividers, do nothing */
- else if (sio_data->kind == nct6775)
- nct6775_update_fan_div(data);
- else
- w83627ehf_update_fan_div(data);
+ if (data->sio_data) {
+ if (data->sio_data->kind == nct6776)
+ ; /* no dividers, do nothing */
+ else if (data->sio_data->kind == nct6775)
+ nct6775_update_fan_div(data);
+ else
+ w83627ehf_update_fan_div(data);
+ }
}

static void nct6775_update_pwm(struct w83627ehf_data *data)
@@ -781,7 +783,7 @@ static void w83627ehf_update_pwm(struct w83627ehf_data *data)
static void w83627ehf_update_pwm_common(struct device *dev,
struct w83627ehf_data *data)
{
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
+ struct w83627ehf_sio_data *sio_data = data->sio_data;

if (sio_data->kind == nct6775 || sio_data->kind == nct6776)
nct6775_update_pwm(data);
@@ -792,8 +794,7 @@ static void w83627ehf_update_pwm_common(struct device *dev,
static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
-
+ struct w83627ehf_sio_data *sio_data = data->sio_data;
int i;

mutex_lock(&data->update_lock);
@@ -930,157 +931,15 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
return data;
}

-/*
- * Sysfs callback functions
- */
-#define show_in_reg(reg) \
-static ssize_t \
-show_##reg(struct device *dev, struct device_attribute *attr, \
- char *buf) \
-{ \
- struct w83627ehf_data *data = w83627ehf_update_device(dev); \
- struct sensor_device_attribute *sensor_attr = \
- to_sensor_dev_attr(attr); \
- int nr = sensor_attr->index; \
- return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr, \
- data->scale_in)); \
-}
-show_in_reg(in)
-show_in_reg(in_min)
-show_in_reg(in_max)
-
-#define store_in_reg(REG, reg) \
-static ssize_t \
-store_in_##reg(struct device *dev, struct device_attribute *attr, \
- const char *buf, size_t count) \
-{ \
- struct w83627ehf_data *data = dev_get_drvdata(dev); \
- struct sensor_device_attribute *sensor_attr = \
- to_sensor_dev_attr(attr); \
- int nr = sensor_attr->index; \
- unsigned long val; \
- int err; \
- err = kstrtoul(buf, 10, &val); \
- if (err < 0) \
- return err; \
- mutex_lock(&data->update_lock); \
- data->in_##reg[nr] = in_to_reg(val, nr, data->scale_in); \
- w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \
- data->in_##reg[nr]); \
- mutex_unlock(&data->update_lock); \
- return count; \
-}
-
-store_in_reg(MIN, min)
-store_in_reg(MAX, max)
-
-static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
- char *buf)
-{
- struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- return sprintf(buf, "%u\n", (data->alarms >> nr) & 0x01);
-}
-
-static struct sensor_device_attribute sda_in_input[] = {
- SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
- SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
- SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
- SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
- SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
- SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
- SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
- SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
- SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
- SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9),
-};
-
-static struct sensor_device_attribute sda_in_alarm[] = {
- SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0),
- SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1),
- SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2),
- SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3),
- SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8),
- SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 21),
- SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20),
- SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16),
- SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17),
- SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 19),
-};
-
-static struct sensor_device_attribute sda_in_min[] = {
- SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
- SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
- SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
- SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3),
- SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4),
- SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5),
- SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6),
- SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7),
- SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8),
- SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9),
-};
-
-static struct sensor_device_attribute sda_in_max[] = {
- SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
- SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
- SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
- SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3),
- SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4),
- SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5),
- SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6),
- SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7),
- SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8),
- SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9),
-};
-
-static ssize_t
-show_fan(struct device *dev, struct device_attribute *attr, char *buf)
-{
- struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- return sprintf(buf, "%d\n", data->rpm[nr]);
-}
-
-static ssize_t
-show_fan_min(struct device *dev, struct device_attribute *attr, char *buf)
-{
- struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- return sprintf(buf, "%d\n",
- data->fan_from_reg_min(data->fan_min[nr],
- data->fan_div[nr]));
-}
-
-static ssize_t
-show_fan_div(struct device *dev, struct device_attribute *attr,
- char *buf)
-{
- struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr]));
-}

-static ssize_t
-store_fan_min(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
+static void
+store_fan_min(struct device *dev, u32 channel, unsigned long val)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- unsigned long val;
- int err;
+ int nr = channel;
unsigned int reg;
u8 new_div;

- err = kstrtoul(buf, 10, &val);
- if (err < 0)
- return err;
-
mutex_lock(&data->update_lock);
if (!data->has_fan_div) {
/*
@@ -1155,336 +1014,8 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
data->fan_min[nr]);
mutex_unlock(&data->update_lock);

- return count;
-}
-
-static struct sensor_device_attribute sda_fan_input[] = {
- SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
- SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
- SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
- SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3),
- SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4),
-};
-
-static struct sensor_device_attribute sda_fan_alarm[] = {
- SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6),
- SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7),
- SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11),
- SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10),
- SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23),
-};
-
-static struct sensor_device_attribute sda_fan_min[] = {
- SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
- store_fan_min, 0),
- SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
- store_fan_min, 1),
- SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
- store_fan_min, 2),
- SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
- store_fan_min, 3),
- SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
- store_fan_min, 4),
-};
-
-static struct sensor_device_attribute sda_fan_div[] = {
- SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0),
- SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1),
- SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2),
- SENSOR_ATTR(fan4_div, S_IRUGO, show_fan_div, NULL, 3),
- SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
-};
-
-static ssize_t
-show_temp_label(struct device *dev, struct device_attribute *attr, char *buf)
-{
- struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- return sprintf(buf, "%s\n", data->temp_label[data->temp_src[nr]]);
-}
-
-#define show_temp_reg(addr, reg) \
-static ssize_t \
-show_##reg(struct device *dev, struct device_attribute *attr, \
- char *buf) \
-{ \
- struct w83627ehf_data *data = w83627ehf_update_device(dev); \
- struct sensor_device_attribute *sensor_attr = \
- to_sensor_dev_attr(attr); \
- int nr = sensor_attr->index; \
- return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->reg[nr])); \
-}
-show_temp_reg(reg_temp, temp);
-show_temp_reg(reg_temp_over, temp_max);
-show_temp_reg(reg_temp_hyst, temp_max_hyst);
-
-#define store_temp_reg(addr, reg) \
-static ssize_t \
-store_##reg(struct device *dev, struct device_attribute *attr, \
- const char *buf, size_t count) \
-{ \
- struct w83627ehf_data *data = dev_get_drvdata(dev); \
- struct sensor_device_attribute *sensor_attr = \
- to_sensor_dev_attr(attr); \
- int nr = sensor_attr->index; \
- int err; \
- long val; \
- err = kstrtol(buf, 10, &val); \
- if (err < 0) \
- return err; \
- mutex_lock(&data->update_lock); \
- data->reg[nr] = LM75_TEMP_TO_REG(val); \
- w83627ehf_write_temp(data, data->addr[nr], data->reg[nr]); \
- mutex_unlock(&data->update_lock); \
- return count; \
-}
-store_temp_reg(reg_temp_over, temp_max);
-store_temp_reg(reg_temp_hyst, temp_max_hyst);
-
-static ssize_t
-show_temp_offset(struct device *dev, struct device_attribute *attr, char *buf)
-{
- struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
-
- return sprintf(buf, "%d\n",
- data->temp_offset[sensor_attr->index] * 1000);
-}
-
-static ssize_t
-store_temp_offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- long val;
- int err;
-
- err = kstrtol(buf, 10, &val);
- if (err < 0)
- return err;
-
- val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
-
- mutex_lock(&data->update_lock);
- data->temp_offset[nr] = val;
- w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[nr], val);
- mutex_unlock(&data->update_lock);
- return count;
-}
-
-static ssize_t
-show_temp_type(struct device *dev, struct device_attribute *attr, char *buf)
-{
- struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- return sprintf(buf, "%d\n", (int)data->temp_type[nr]);
-}
-
-static struct sensor_device_attribute sda_temp_input[] = {
- SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
- SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
- SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
- SENSOR_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3),
- SENSOR_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4),
- SENSOR_ATTR(temp6_input, S_IRUGO, show_temp, NULL, 5),
- SENSOR_ATTR(temp7_input, S_IRUGO, show_temp, NULL, 6),
- SENSOR_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7),
- SENSOR_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8),
-};
-
-static struct sensor_device_attribute sda_temp_label[] = {
- SENSOR_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0),
- SENSOR_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1),
- SENSOR_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2),
- SENSOR_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3),
- SENSOR_ATTR(temp5_label, S_IRUGO, show_temp_label, NULL, 4),
- SENSOR_ATTR(temp6_label, S_IRUGO, show_temp_label, NULL, 5),
- SENSOR_ATTR(temp7_label, S_IRUGO, show_temp_label, NULL, 6),
- SENSOR_ATTR(temp8_label, S_IRUGO, show_temp_label, NULL, 7),
- SENSOR_ATTR(temp9_label, S_IRUGO, show_temp_label, NULL, 8),
-};
-
-static struct sensor_device_attribute sda_temp_max[] = {
- SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 0),
- SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 1),
- SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 2),
- SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 3),
- SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 4),
- SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 5),
- SENSOR_ATTR(temp7_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 6),
- SENSOR_ATTR(temp8_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 7),
- SENSOR_ATTR(temp9_max, S_IRUGO | S_IWUSR, show_temp_max,
- store_temp_max, 8),
-};
-
-static struct sensor_device_attribute sda_temp_max_hyst[] = {
- SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 0),
- SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 1),
- SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 2),
- SENSOR_ATTR(temp4_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 3),
- SENSOR_ATTR(temp5_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 4),
- SENSOR_ATTR(temp6_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 5),
- SENSOR_ATTR(temp7_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 6),
- SENSOR_ATTR(temp8_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 7),
- SENSOR_ATTR(temp9_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
- store_temp_max_hyst, 8),
-};
-
-static struct sensor_device_attribute sda_temp_alarm[] = {
- SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4),
- SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5),
- SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
-};
-
-static struct sensor_device_attribute sda_temp_type[] = {
- SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
- SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
- SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
-};
-
-static struct sensor_device_attribute sda_temp_offset[] = {
- SENSOR_ATTR(temp1_offset, S_IRUGO | S_IWUSR, show_temp_offset,
- store_temp_offset, 0),
- SENSOR_ATTR(temp2_offset, S_IRUGO | S_IWUSR, show_temp_offset,
- store_temp_offset, 1),
- SENSOR_ATTR(temp3_offset, S_IRUGO | S_IWUSR, show_temp_offset,
- store_temp_offset, 2),
-};
-
-#define show_pwm_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
- char *buf) \
-{ \
- struct w83627ehf_data *data = w83627ehf_update_device(dev); \
- struct sensor_device_attribute *sensor_attr = \
- to_sensor_dev_attr(attr); \
- int nr = sensor_attr->index; \
- return sprintf(buf, "%d\n", data->reg[nr]); \
-}
-
-show_pwm_reg(pwm_mode)
-show_pwm_reg(pwm_enable)
-show_pwm_reg(pwm)
-
-static ssize_t
-store_pwm_mode(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
- int nr = sensor_attr->index;
- unsigned long val;
- int err;
- u16 reg;
-
- err = kstrtoul(buf, 10, &val);
- if (err < 0)
- return err;
-
- if (val > 1)
- return -EINVAL;
-
- /* On NCT67766F, DC mode is only supported for pwm1 */
- if (sio_data->kind == nct6776 && nr && val != 1)
- return -EINVAL;
-
- mutex_lock(&data->update_lock);
- reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]);
- data->pwm_mode[nr] = val;
- reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]);
- if (!val)
- reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr];
- w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg);
- mutex_unlock(&data->update_lock);
- return count;
-}
-
-static ssize_t
-store_pwm(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- unsigned long val;
- int err;
-
- err = kstrtoul(buf, 10, &val);
- if (err < 0)
- return err;
-
- val = clamp_val(val, 0, 255);
-
- mutex_lock(&data->update_lock);
- data->pwm[nr] = val;
- w83627ehf_write_value(data, data->REG_PWM[nr], val);
- mutex_unlock(&data->update_lock);
- return count;
-}
-
-static ssize_t
-store_pwm_enable(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
-{
- struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
- struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
- int nr = sensor_attr->index;
- unsigned long val;
- int err;
- u16 reg;
-
- err = kstrtoul(buf, 10, &val);
- if (err < 0)
- return err;
-
- if (!val || (val > 4 && val != data->pwm_enable_orig[nr]))
- return -EINVAL;
- /* SmartFan III mode is not supported on NCT6776F */
- if (sio_data->kind == nct6776 && val == 4)
- return -EINVAL;
-
- mutex_lock(&data->update_lock);
- data->pwm_enable[nr] = val;
- if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
- reg = w83627ehf_read_value(data,
- NCT6775_REG_FAN_MODE[nr]);
- reg &= 0x0f;
- reg |= (val - 1) << 4;
- w83627ehf_write_value(data,
- NCT6775_REG_FAN_MODE[nr], reg);
- } else {
- reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]);
- reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]);
- reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr];
- w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg);
- }
- mutex_unlock(&data->update_lock);
- return count;
}

-
#define show_tol_temp(reg) \
static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
char *buf) \
@@ -1527,7 +1058,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
+ struct w83627ehf_sio_data *sio_data = data->sio_data;
struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
int nr = sensor_attr->index;
u16 reg;
@@ -1562,35 +1093,6 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
return count;
}

-static struct sensor_device_attribute sda_pwm[] = {
- SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
- SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
- SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
- SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3),
-};
-
-static struct sensor_device_attribute sda_pwm_mode[] = {
- SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
- store_pwm_mode, 0),
- SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
- store_pwm_mode, 1),
- SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
- store_pwm_mode, 2),
- SENSOR_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
- store_pwm_mode, 3),
-};
-
-static struct sensor_device_attribute sda_pwm_enable[] = {
- SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
- store_pwm_enable, 0),
- SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
- store_pwm_enable, 1),
- SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
- store_pwm_enable, 2),
- SENSOR_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
- store_pwm_enable, 3),
-};
-
static struct sensor_device_attribute sda_target_temp[] = {
SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp,
store_target_temp, 0),
@@ -1687,15 +1189,6 @@ store_##reg(struct device *dev, struct device_attribute *attr, \

fan_time_functions(fan_stop_time, FAN_STOP_TIME)

-static ssize_t name_show(struct device *dev, struct device_attribute *attr,
- char *buf)
-{
- struct w83627ehf_data *data = dev_get_drvdata(dev);
-
- return sprintf(buf, "%s\n", data->name);
-}
-static DEVICE_ATTR_RO(name);
-
static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
store_fan_stop_time, 3),
@@ -1718,21 +1211,18 @@ static struct sensor_device_attribute sda_sf3_arrays_fan3[] = {
store_fan_stop_output, 2),
};

-static struct sensor_device_attribute sda_sf3_arrays[] = {
- SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
- store_fan_stop_time, 0),
- SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
- store_fan_stop_time, 1),
- SENSOR_ATTR(pwm1_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
- store_fan_start_output, 0),
- SENSOR_ATTR(pwm2_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
- store_fan_start_output, 1),
- SENSOR_ATTR(pwm1_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
- store_fan_stop_output, 0),
- SENSOR_ATTR(pwm2_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
- store_fan_stop_output, 1),
-};
-
+static SENSOR_DEVICE_ATTR(pwm1_stop_time, 0644, show_fan_stop_time,
+ store_fan_stop_time, 0);
+static SENSOR_DEVICE_ATTR(pwm2_stop_time, 0644, show_fan_stop_time,
+ store_fan_stop_time, 1);
+static SENSOR_DEVICE_ATTR(pwm1_start_output, 0644, show_fan_start_output,
+ store_fan_start_output, 0);
+static SENSOR_DEVICE_ATTR(pwm2_start_output, 0644, show_fan_start_output,
+ store_fan_start_output, 1);
+static SENSOR_DEVICE_ATTR(pwm1_stop_output, 0644, show_fan_stop_output,
+ store_fan_stop_output, 0);
+static SENSOR_DEVICE_ATTR(pwm2_stop_output, 0644, show_fan_stop_output,
+ store_fan_stop_output, 1);

/*
* pwm1 and pwm3 don't support max and step settings on all chips.
@@ -1796,83 +1286,38 @@ clear_caseopen(struct device *dev, struct device_attribute *attr,
return count;
}

-static struct sensor_device_attribute_2 sda_caseopen[] = {
- SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_caseopen,
- clear_caseopen, 0x80, 0x10),
- SENSOR_ATTR_2(intrusion1_alarm, S_IWUSR | S_IRUGO, show_caseopen,
- clear_caseopen, 0x40, 0x40),
+static SENSOR_DEVICE_ATTR_2(intrusion0_alarm, 0644, show_caseopen,
+ clear_caseopen, 0x80, 0x10);
+static SENSOR_DEVICE_ATTR_2(intrusion1_alarm, 0644, show_caseopen,
+ clear_caseopen, 0x40, 0x40);
+
+#define NUMBER_OF_STATIC_SENSOR_ATTRS (7)
+#define NUMBER_OF_SENSOR_ATTRS ( \
+ NUMBER_OF_STATIC_SENSOR_ATTRS + \
+ ARRAY_SIZE(sda_sf3_max_step_arrays) + \
+ ARRAY_SIZE(sda_sf3_arrays_fan3) + \
+ ARRAY_SIZE(sda_sf3_arrays_fan4) + \
+ ARRAY_SIZE(sda_target_temp) + \
+ ARRAY_SIZE(sda_tolerance) + \
+ 1)
+
+static struct attribute *sensor_attrs[NUMBER_OF_SENSOR_ATTRS] = {
+ &sensor_dev_attr_pwm1_stop_time.dev_attr.attr, //0
+ &sensor_dev_attr_pwm2_stop_time.dev_attr.attr, //1
+ &sensor_dev_attr_pwm1_start_output.dev_attr.attr, //2
+ &sensor_dev_attr_pwm2_start_output.dev_attr.attr, //3
+ &sensor_dev_attr_pwm1_stop_output.dev_attr.attr, //4
+ &sensor_dev_attr_pwm2_stop_output.dev_attr.attr, //5
+ &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, //6
+ NULL /* all other entries are dynamically set, depending on the chip */
};

+ATTRIBUTE_GROUPS(sensor);
+
/*
* Driver and device management
*/

-static void w83627ehf_device_remove_files(struct device *dev)
-{
- /*
- * some entries in the following arrays may not have been used in
- * device_create_file(), but device_remove_file() will ignore them
- */
- int i;
- struct w83627ehf_data *data = dev_get_drvdata(dev);
-
- for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
- device_remove_file(dev, &sda_sf3_arrays[i].dev_attr);
- for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
- struct sensor_device_attribute *attr =
- &sda_sf3_max_step_arrays[i];
- if (data->REG_FAN_STEP_OUTPUT &&
- data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff)
- device_remove_file(dev, &attr->dev_attr);
- }
- for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++)
- device_remove_file(dev, &sda_sf3_arrays_fan3[i].dev_attr);
- for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
- device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
- for (i = 0; i < data->in_num; i++) {
- if ((i == 6) && data->in6_skip)
- continue;
- device_remove_file(dev, &sda_in_input[i].dev_attr);
- device_remove_file(dev, &sda_in_alarm[i].dev_attr);
- device_remove_file(dev, &sda_in_min[i].dev_attr);
- device_remove_file(dev, &sda_in_max[i].dev_attr);
- }
- for (i = 0; i < 5; i++) {
- device_remove_file(dev, &sda_fan_input[i].dev_attr);
- device_remove_file(dev, &sda_fan_alarm[i].dev_attr);
- device_remove_file(dev, &sda_fan_div[i].dev_attr);
- device_remove_file(dev, &sda_fan_min[i].dev_attr);
- }
- for (i = 0; i < data->pwm_num; i++) {
- device_remove_file(dev, &sda_pwm[i].dev_attr);
- device_remove_file(dev, &sda_pwm_mode[i].dev_attr);
- device_remove_file(dev, &sda_pwm_enable[i].dev_attr);
- device_remove_file(dev, &sda_target_temp[i].dev_attr);
- device_remove_file(dev, &sda_tolerance[i].dev_attr);
- }
- for (i = 0; i < NUM_REG_TEMP; i++) {
- if (!(data->have_temp & (1 << i)))
- continue;
- device_remove_file(dev, &sda_temp_input[i].dev_attr);
- device_remove_file(dev, &sda_temp_label[i].dev_attr);
- if (i == 2 && data->temp3_val_only)
- continue;
- device_remove_file(dev, &sda_temp_max[i].dev_attr);
- device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr);
- if (i > 2)
- continue;
- device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
- device_remove_file(dev, &sda_temp_type[i].dev_attr);
- device_remove_file(dev, &sda_temp_offset[i].dev_attr);
- }
-
- device_remove_file(dev, &sda_caseopen[0].dev_attr);
- device_remove_file(dev, &sda_caseopen[1].dev_attr);
-
- device_remove_file(dev, &dev_attr_name);
- device_remove_file(dev, &dev_attr_cpu0_vid);
-}
-
/* Get the monitoring functions started */
static inline void w83627ehf_init_device(struct w83627ehf_data *data,
enum kinds kind)
@@ -2046,15 +1491,577 @@ w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
}
}

+static int w3627ehf_read_temp(struct device *dev, u32 attr, int channel,
+ long *val)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+
+ switch (attr) {
+ case hwmon_temp_input:
+ *val = LM75_TEMP_FROM_REG(data->temp[channel]);
+ return 0;
+ case hwmon_temp_max:
+ *val = LM75_TEMP_FROM_REG(data->temp_max[channel]);
+ return 0;
+ case hwmon_temp_max_hyst:
+ *val = LM75_TEMP_FROM_REG(data->temp_max_hyst[channel]);
+ return 0;
+ case hwmon_temp_type:
+ *val = data->temp_type[channel];
+ return 0;
+ case hwmon_temp_offset:
+ *val = data->temp_offset[channel] * 1000;
+ return 0;
+ case hwmon_temp_alarm:
+ switch (channel) {
+ case 0:
+ channel = 4;
+ break;
+ case 1:
+ channel = 5;
+ break;
+ case 2:
+ channel = 13;
+ break;
+ default:
+ return -EINVAL;
+ }
+ *val = ((data->alarms >> channel) & 0x01);
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static int w3627ehf_write_temp(struct device *dev, u32 attr, int channel,
+ long val)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+
+ switch (attr) {
+ case hwmon_temp_offset:
+ val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
+ mutex_lock(&data->update_lock);
+ data->temp_offset[channel] = val;
+ w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[channel],
+ val);
+ mutex_unlock(&data->update_lock);
+ break;
+ case hwmon_temp_max:
+ mutex_lock(&data->update_lock);
+ data->temp_max[channel] = LM75_TEMP_TO_REG(val);
+ w83627ehf_write_temp(data, data->reg_temp_over[channel],
+ data->temp_max[channel]);
+ mutex_unlock(&data->update_lock);
+ break;
+ case hwmon_temp_max_hyst:
+ mutex_lock(&data->update_lock);
+ data->temp_max_hyst[channel] = LM75_TEMP_TO_REG(val);
+ w83627ehf_write_temp(data, data->reg_temp_hyst[channel],
+ data->temp_max_hyst[channel]);
+ mutex_unlock(&data->update_lock);
+ break;
+
+ default:
+ return -EOPNOTSUPP;
+ }
+ return 0;
+}
+
+static umode_t w3627ehf_temp_is_visible(const void *_data, u32 attr,
+ int channel)
+{
+ const struct w83627ehf_data *data = _data;
+
+ if (!(data->have_temp & (1 << channel)))
+ return 0;
+
+ switch (attr) {
+ case hwmon_temp_label:
+ if (data->temp_label)
+ return 0444;
+ return 0;
+ case hwmon_temp_input:
+ return 0444;
+ case hwmon_temp_max:
+ if (channel == 2 && data->temp3_val_only)
+ return 0;
+ else if (data->reg_temp_over[channel])
+ return 0644;
+ else
+ return 0;
+ case hwmon_temp_max_hyst:
+ if (channel == 2 && data->temp3_val_only)
+ return 0;
+ else if (data->reg_temp_hyst[channel])
+ return 0644;
+ else
+ return 0;
+ case hwmon_temp_alarm:
+ case hwmon_temp_type:
+ return 0444;
+ case hwmon_temp_offset:
+ if (data->have_temp_offset & (1 << channel))
+ return 0644;
+ return 0;
+ }
+ return 0;
+}
+
+static int w3627ehf_write_fan(struct device *dev, u32 attr, int channel,
+ long val)
+{
+ switch (attr) {
+ case hwmon_fan_min:
+ store_fan_min(dev, channel, val);
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
+static int w3627ehf_read_fan(struct device *dev, u32 attr, int channel,
+ long *val)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+
+ switch (attr) {
+ case hwmon_fan_alarm:
+ //the fan sensors have different offsets
+ switch (channel) {
+ case 0:
+ channel = 6;
+ break;
+ case 1:
+ channel = 7;
+ break;
+ case 2:
+ channel = 11;
+ break;
+ case 3:
+ channel = 10;
+ break;
+ case 4:
+ channel = 23;
+ break;
+ default:
+ return -EINVAL;
+ }
+ *val = ((data->alarms >> channel) & 0x01);
+ return 0;
+ case hwmon_fan_input:
+ *val = data->rpm[channel];
+ return 0;
+ case hwmon_fan_min:
+ *val = data->fan_from_reg_min(data->fan_min[channel],
+ data->fan_div[channel]);
+ return 0;
+ case hwmon_fan_div:
+ *val = div_from_reg(data->fan_div[channel]);
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static umode_t w3627ehf_fan_is_visible(const void *_data, u32 attr, int channel)
+{
+ const struct w83627ehf_data *data = _data;
+
+ if (!(data->has_fan & (1 << channel)))
+ return 0;
+
+ switch (attr) {
+ case hwmon_fan_alarm:
+ case hwmon_fan_input:
+ return 0444;
+ case hwmon_fan_div:
+ if (data->sio_data->kind != nct6776)
+ return 0444;
+ else
+ return 0;
+ case hwmon_fan_min:
+ return 0644;
+ }
+ return 0;
+}
+
+static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
+ long val)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+ struct w83627ehf_sio_data *sio_data = data->sio_data;
+ u16 reg;
+
+ switch (attr) {
+ case hwmon_pwm_input:
+ val = clamp_val(val, 0, 255);
+ mutex_lock(&data->update_lock);
+ data->pwm[channel] = val;
+ w83627ehf_write_value(data, data->REG_PWM[channel], val);
+ mutex_unlock(&data->update_lock);
+ return 0;
+ case hwmon_pwm_mode:
+ if (val > 1)
+ return -EINVAL;
+
+ /* On NCT67766F, DC mode is only supported for pwm1 */
+ if (sio_data->kind == nct6776 && channel && val != 1)
+ return -EINVAL;
+
+ mutex_lock(&data->update_lock);
+ reg = w83627ehf_read_value(data,
+ W83627EHF_REG_PWM_ENABLE[channel]);
+ data->pwm_mode[channel] = val;
+ reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[channel]);
+ if (!val)
+ reg |= 1 << W83627EHF_PWM_MODE_SHIFT[channel];
+ w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[channel],
+ reg);
+ mutex_unlock(&data->update_lock);
+ return 0;
+ case hwmon_pwm_enable:
+ if (!val || (val > 4 && val != data->pwm_enable_orig[channel]))
+ return -EINVAL;
+ /* SmartFan III mode is not supported on NCT6776F */
+ if (sio_data->kind == nct6776 && val == 4)
+ return -EINVAL;
+
+ mutex_lock(&data->update_lock);
+ data->pwm_enable[channel] = val;
+ if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
+ reg = w83627ehf_read_value(data,
+ NCT6775_REG_FAN_MODE[channel]);
+ reg &= 0x0f;
+ reg |= (val - 1) << 4;
+ w83627ehf_write_value(data,
+ NCT6775_REG_FAN_MODE[channel],
+ reg);
+ } else {
+ reg = w83627ehf_read_value(data,
+ W83627EHF_REG_PWM_ENABLE[channel]);
+ reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[channel]);
+ reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel];
+ w83627ehf_write_value(data,
+ W83627EHF_REG_PWM_ENABLE[channel],
+ reg);
+ }
+ mutex_unlock(&data->update_lock);
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static int w3627ehf_write_input(struct device *dev, u32 attr, int channel,
+ long val)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+
+ switch (attr) {
+ case hwmon_in_min:
+ mutex_lock(&data->update_lock);
+ data->in_min[channel] = in_to_reg(val, channel, data->scale_in);
+ w83627ehf_write_value(data, W83627EHF_REG_IN_MIN(channel),
+ data->in_min[channel]);
+ mutex_unlock(&data->update_lock);
+ return 0;
+ case hwmon_in_max:
+ mutex_lock(&data->update_lock);
+ data->in_max[channel] = in_to_reg(val, channel, data->scale_in);
+ w83627ehf_write_value(data, W83627EHF_REG_IN_MAX(channel),
+ data->in_max[channel]);
+ mutex_unlock(&data->update_lock);
+ return 0;
+ }
+ return -EOPNOTSUPP;
+}
+
+static int w3627ehf_read_pwm(struct device *dev, u32 attr, int channel,
+ long *val)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+
+ switch (attr) {
+ case hwmon_pwm_input:
+ *val = data->pwm[channel];
+ return 0;
+ case hwmon_pwm_mode:
+ *val = data->pwm_mode[channel];
+ return 0;
+ case hwmon_pwm_enable:
+ *val = data->pwm_enable[channel];
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static umode_t w3627ehf_pwm_is_visible(const void *_data, u32 attr, int channel)
+{
+ const struct w83627ehf_data *data = _data;
+
+ switch (attr) {
+ case hwmon_pwm_input:
+ case hwmon_pwm_mode:
+ case hwmon_pwm_enable:
+ if (data->has_fan & (1 << channel)) {
+ if (channel < data->pwm_num)
+ return 0644;
+ }
+ return 0;
+ }
+ return 0;
+}
+
+static int w3627ehf_read_input(struct device *dev, u32 attr, int channel,
+ long *val)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+
+ switch (attr) {
+ case hwmon_in_input:
+ *val = in_from_reg(data->in[channel], channel, data->scale_in);
+ return 0;
+ case hwmon_in_min:
+ *val = in_from_reg(data->in_min[channel], channel,
+ data->scale_in);
+ return 0;
+ case hwmon_in_max:
+ *val = in_from_reg(data->in_max[channel], channel,
+ data->scale_in);
+ return 0;
+ case hwmon_in_alarm:
+ switch (channel) {
+ case 0:
+ channel = 0;
+ break;
+ case 1:
+ channel = 1;
+ break;
+ case 2:
+ channel = 2;
+ break;
+ case 3:
+ channel = 3;
+ break;
+ case 4:
+ channel = 8;
+ break;
+ case 5:
+ channel = 21;
+ break;
+ case 6:
+ channel = 20;
+ break;
+ case 7:
+ channel = 16;
+ break;
+ case 8:
+ channel = 17;
+ break;
+ case 9:
+ channel = 19;
+ break;
+ default:
+ return -EINVAL;
+ }
+ *val = ((data->alarms >> channel) & 0x01);
+ return 0;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static umode_t w3627ehf_input_is_visible(const void *_data, u32 attr,
+ int channel)
+{
+ const struct w83627ehf_data *data = _data;
+
+ //skip channel 6 if requested
+ if ((channel == 6) && data->in6_skip)
+ return 0;
+
+ switch (attr) {
+ case hwmon_in_input:
+ case hwmon_in_alarm:
+ return 0444;
+ case hwmon_in_min:
+ case hwmon_in_max:
+ return 0644;
+ default:
+ return 0;
+ }
+}
+
+static int w3627ehf_read_string(struct device *dev,
+ enum hwmon_sensor_types type, u32 attr,
+ int channel, char **buf)
+{
+ struct w83627ehf_data *data = dev_get_drvdata(dev);
+
+ w83627ehf_update_device(dev);
+ if (((type == hwmon_fan) && (attr == hwmon_fan_label)) ||
+ ((type == hwmon_temp) && (attr == hwmon_temp_label))) {
+ *buf = data->temp_label[data->temp_src[channel]];
+ return 0;
+ }
+ return -EOPNOTSUPP;
+}
+
+static int w3627ehf_read(struct device *dev, enum hwmon_sensor_types type,
+ u32 attr, int channel, long *val)
+{
+ w83627ehf_update_device(dev);
+ switch (type) {
+ case hwmon_fan:
+ return w3627ehf_read_fan(dev, attr, channel, val);
+ case hwmon_temp:
+ return w3627ehf_read_temp(dev, attr, channel, val);
+ case hwmon_in:
+ return w3627ehf_read_input(dev, attr, channel, val);
+ case hwmon_pwm:
+ return w3627ehf_read_pwm(dev, attr, channel, val);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static int w3627ehf_write(struct device *dev, enum hwmon_sensor_types type,
+ u32 attr, int channel, long val)
+{
+ switch (type) {
+ case hwmon_fan:
+ return w3627ehf_write_fan(dev, attr, channel, val);
+ case hwmon_in:
+ return w3627ehf_write_input(dev, attr, channel, val);
+ case hwmon_pwm:
+ return w3627ehf_write_pwm(dev, attr, channel, val);
+ case hwmon_temp:
+ return w3627ehf_write_temp(dev, attr, channel, val);
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static umode_t w3627ehf_is_visible(const void *data,
+ enum hwmon_sensor_types type, u32 attr,
+ int channel)
+{
+ switch (type) {
+ case hwmon_fan:
+ return w3627ehf_fan_is_visible(data, attr, channel);
+ case hwmon_pwm:
+ return w3627ehf_pwm_is_visible(data, attr, channel);
+ case hwmon_in:
+ return w3627ehf_input_is_visible(data, attr, channel);
+ case hwmon_temp:
+ return w3627ehf_temp_is_visible(data, attr, channel);
+ default:
+ return 0;
+ }
+}
+
+static const u32 w3627ehf_temp_config[] = {
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST |
+ HWMON_T_ALARM | HWMON_T_TYPE | HWMON_T_OFFSET,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST |
+ HWMON_T_ALARM | HWMON_T_TYPE | HWMON_T_OFFSET,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST |
+ HWMON_T_ALARM | HWMON_T_TYPE | HWMON_T_OFFSET,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
+ HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
+ 0
+};
+
+static const u32 w3627ehf_fan_config[] = {
+ HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
+ HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
+ HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
+ HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
+ HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
+ 0
+};
+
+static const u32 w3627ehf_pwm_config[] = {
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
+ HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
+ 0
+};
+
+static const u32 w3627ehf_input_config[] = {
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
+ 0
+};
+
+static const struct hwmon_channel_info w3627ehf_temp = {
+ .type = hwmon_temp,
+ .config = w3627ehf_temp_config,
+};
+
+static const struct hwmon_channel_info w3627ehf_fan = {
+ .type = hwmon_fan,
+ .config = w3627ehf_fan_config,
+};
+
+static const struct hwmon_channel_info w3627ehf_pwm = {
+ .type = hwmon_pwm,
+ .config = w3627ehf_pwm_config,
+};
+
+static const struct hwmon_channel_info w3627ehf_input = {
+ .type = hwmon_in,
+ .config = w3627ehf_input_config,
+};
+
+static const struct hwmon_ops w3627ehf_hwmon_ops = {
+ .is_visible = w3627ehf_is_visible,
+ .read = w3627ehf_read,
+ .read_string = w3627ehf_read_string,
+ .write = w3627ehf_write,
+};
+
+static const struct hwmon_channel_info *w3627ehf_info[] = {
+ &w3627ehf_temp,
+ &w3627ehf_fan,
+ &w3627ehf_pwm,
+ &w3627ehf_input,
+ NULL
+};
+
+static const struct hwmon_chip_info w83627ehf_chip_info = {
+ .ops = &w3627ehf_hwmon_ops,
+ .info = w3627ehf_info,
+};
+
static int w83627ehf_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
+ struct w83627ehf_sio_data *sio_data;
struct w83627ehf_data *data;
struct resource *res;
u8 en_vrm10;
+ struct attribute **dynamic_attrs;
int i, err = 0;

+ dynamic_attrs = &sensor_attrs[NUMBER_OF_STATIC_SENSOR_ATTRS];
+
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (!request_region(res->start, IOREGION_LENGTH, DRVNAME)) {
err = -EBUSY;
@@ -2071,6 +2078,8 @@ static int w83627ehf_probe(struct platform_device *pdev)
goto exit_release;
}

+ data->sio_data = dev_get_platdata(dev);
+ sio_data = data->sio_data;
data->addr = res->start;
mutex_init(&data->lock);
mutex_init(&data->update_lock);
@@ -2363,9 +2372,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
*/
superio_select(sio_data->sioreg, W83667HG_LD_VID);
data->vid = superio_inb(sio_data->sioreg, 0xe3);
- err = device_create_file(dev, &dev_attr_cpu0_vid);
- if (err)
- goto exit_release;
+ *dynamic_attrs++ = &dev_attr_cpu0_vid.attr;
} else if (sio_data->kind != w83627uhg) {
superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) {
@@ -2400,9 +2407,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
if (sio_data->kind == w83627ehf) /* 6 VID pins only */
data->vid &= 0x3f;

- err = device_create_file(dev, &dev_attr_cpu0_vid);
- if (err)
- goto exit_release;
+ *dynamic_attrs++ = &dev_attr_cpu0_vid.attr;
} else {
dev_info(dev,
"VID pins in output mode, CPU VID not available\n");
@@ -2437,150 +2442,55 @@ static int w83627ehf_probe(struct platform_device *pdev)
data->pwm_enable_orig[i] = data->pwm_enable[i];

/* Register sysfs hooks */
- for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) {
- err = device_create_file(dev, &sda_sf3_arrays[i].dev_attr);
- if (err)
- goto exit_remove;
- }
-
for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
struct sensor_device_attribute *attr =
- &sda_sf3_max_step_arrays[i];
+ &sda_sf3_max_step_arrays[i];
+
if (data->REG_FAN_STEP_OUTPUT &&
data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) {
- err = device_create_file(dev, &attr->dev_attr);
- if (err)
- goto exit_remove;
+ *dynamic_attrs++ = &attr->dev_attr.attr;
}
}
/* if fan3 and fan4 are enabled create the sf3 files for them */
if ((data->has_fan & (1 << 2)) && data->pwm_num >= 3)
for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++) {
- err = device_create_file(dev,
- &sda_sf3_arrays_fan3[i].dev_attr);
- if (err)
- goto exit_remove;
+ *dynamic_attrs++ =
+ &sda_sf3_arrays_fan3[i].dev_attr.attr;
}
if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4)
for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) {
- err = device_create_file(dev,
- &sda_sf3_arrays_fan4[i].dev_attr);
- if (err)
- goto exit_remove;
+ *dynamic_attrs++ =
+ &sda_sf3_arrays_fan4[i].dev_attr.attr;
}

- for (i = 0; i < data->in_num; i++) {
- if ((i == 6) && data->in6_skip)
- continue;
- if ((err = device_create_file(dev, &sda_in_input[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_in_alarm[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_in_min[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_in_max[i].dev_attr)))
- goto exit_remove;
- }

for (i = 0; i < 5; i++) {
if (data->has_fan & (1 << i)) {
- if ((err = device_create_file(dev,
- &sda_fan_input[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_fan_alarm[i].dev_attr)))
- goto exit_remove;
- if (sio_data->kind != nct6776) {
- err = device_create_file(dev,
- &sda_fan_div[i].dev_attr);
- if (err)
- goto exit_remove;
+ if (i < data->pwm_num) {
+ *dynamic_attrs++ =
+ &sda_target_temp[i].dev_attr.attr;
+ *dynamic_attrs++ =
+ &sda_tolerance[i].dev_attr.attr;
}
- if (data->has_fan_min & (1 << i)) {
- err = device_create_file(dev,
- &sda_fan_min[i].dev_attr);
- if (err)
- goto exit_remove;
- }
- if (i < data->pwm_num &&
- ((err = device_create_file(dev,
- &sda_pwm[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_pwm_mode[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_pwm_enable[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_target_temp[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_tolerance[i].dev_attr))))
- goto exit_remove;
- }
- }
-
- for (i = 0; i < NUM_REG_TEMP; i++) {
- if (!(data->have_temp & (1 << i)))
- continue;
- err = device_create_file(dev, &sda_temp_input[i].dev_attr);
- if (err)
- goto exit_remove;
- if (data->temp_label) {
- err = device_create_file(dev,
- &sda_temp_label[i].dev_attr);
- if (err)
- goto exit_remove;
- }
- if (i == 2 && data->temp3_val_only)
- continue;
- if (data->reg_temp_over[i]) {
- err = device_create_file(dev,
- &sda_temp_max[i].dev_attr);
- if (err)
- goto exit_remove;
- }
- if (data->reg_temp_hyst[i]) {
- err = device_create_file(dev,
- &sda_temp_max_hyst[i].dev_attr);
- if (err)
- goto exit_remove;
- }
- if (i > 2)
- continue;
- if ((err = device_create_file(dev,
- &sda_temp_alarm[i].dev_attr))
- || (err = device_create_file(dev,
- &sda_temp_type[i].dev_attr)))
- goto exit_remove;
- if (data->have_temp_offset & (1 << i)) {
- err = device_create_file(dev,
- &sda_temp_offset[i].dev_attr);
- if (err)
- goto exit_remove;
}
}

- err = device_create_file(dev, &sda_caseopen[0].dev_attr);
- if (err)
- goto exit_remove;
-
if (sio_data->kind == nct6776) {
- err = device_create_file(dev, &sda_caseopen[1].dev_attr);
- if (err)
- goto exit_remove;
+ *dynamic_attrs++ =
+ &sensor_dev_attr_intrusion1_alarm.dev_attr.attr;
}

- err = device_create_file(dev, &dev_attr_name);
- if (err)
- goto exit_remove;
-
- data->hwmon_dev = hwmon_device_register(dev);
+ data->hwmon_dev = hwmon_device_register_with_info(dev, data->name,
+ data,
+ &w83627ehf_chip_info,
+ sensor_groups);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
- goto exit_remove;
+ goto exit_release;
}

return 0;

-exit_remove:
- w83627ehf_device_remove_files(dev);
exit_release:
release_region(res->start, IOREGION_LENGTH);
exit:
@@ -2592,7 +2502,6 @@ static int w83627ehf_remove(struct platform_device *pdev)
struct w83627ehf_data *data = platform_get_drvdata(pdev);

hwmon_device_unregister(data->hwmon_dev);
- w83627ehf_device_remove_files(&pdev->dev);
release_region(data->addr, IOREGION_LENGTH);

return 0;
@@ -2602,7 +2511,7 @@ static int w83627ehf_remove(struct platform_device *pdev)
static int w83627ehf_suspend(struct device *dev)
{
struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
+ struct w83627ehf_sio_data *sio_data = data->sio_data;

mutex_lock(&data->update_lock);
data->vbat = w83627ehf_read_value(data, W83627EHF_REG_VBAT);
@@ -2618,7 +2527,7 @@ static int w83627ehf_suspend(struct device *dev)
static int w83627ehf_resume(struct device *dev)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
+ struct w83627ehf_sio_data *sio_data = data->sio_data;
int i;

mutex_lock(&data->update_lock);
--
2.10.2


2017-03-23 00:38:52

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 4/4] w83627ehf: Drop FSFE template and replace with SPDX License information

As indicated by checkpatch it makes sense to not use the FSFE Template
about GPLv2+

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/hwmon/w83627ehf.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index dbe5735963ac..bba26623af36 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -18,19 +18,8 @@
* This driver also supports the W83627EHG, which is the lead-free
* version of the W83627EHF.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Released under the GPLv2 or later.
+ * SPDX-License-Identifier: GPL-2.0+
*
* Supports the following chips:
*
--
2.10.2

2017-03-23 00:39:28

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 3/4] w83627ehf: Minor readability fixes

just some cosmetics for better readability, proposed by Lindent/checkpatch

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/hwmon/w83627ehf.c | 41 +++++++++++++++--------------------------
1 file changed, 15 insertions(+), 26 deletions(-)

diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index b0eac8e35cc5..dbe5735963ac 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -404,6 +404,7 @@ div_from_reg(u8 reg)
static const u16 scale_in_common[10] = {
800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 800
};
+
static const u16 scale_in_w83627uhg[9] = {
800, 800, 3328, 3424, 800, 800, 0, 3328, 3400
};
@@ -426,7 +427,6 @@ struct w83627ehf_sio_data {
enum kinds kind;
};

-
struct w83627ehf_data {
int addr; /* IO base of hw monitor block */
const char *name;
@@ -526,6 +526,7 @@ struct w83627ehf_data {
static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg)
{
u8 bank = reg >> 8;
+
if (data->bank != bank) {
outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET);
outb_p(bank, data->addr + DATA_REG_OFFSET);
@@ -543,8 +544,7 @@ static u16 w83627ehf_read_value(struct w83627ehf_data *data, u16 reg)
outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET);
res = inb_p(data->addr + DATA_REG_OFFSET);
if (word_sized) {
- outb_p((reg & 0xff) + 1,
- data->addr + ADDR_REG_OFFSET);
+ outb_p((reg & 0xff) + 1, data->addr + ADDR_REG_OFFSET);
res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET);
}

@@ -563,8 +563,7 @@ static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg,
outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET);
if (word_sized) {
outb_p(value >> 8, data->addr + DATA_REG_OFFSET);
- outb_p((reg & 0xff) + 1,
- data->addr + ADDR_REG_OFFSET);
+ outb_p((reg & 0xff) + 1, data->addr + ADDR_REG_OFFSET);
}
outb_p(value & 0xff, data->addr + DATA_REG_OFFSET);

@@ -584,8 +583,7 @@ static u16 w83627ehf_read_temp(struct w83627ehf_data *data, u16 reg)
return res;
}

-static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg,
- u16 value)
+static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg, u16 value)
{
if (!is_word_sized(reg))
value >>= 8;
@@ -694,7 +692,7 @@ static void nct6775_update_fan_div(struct w83627ehf_data *data)
data->fan_div[1] = (i & 0x70) >> 4;
i = w83627ehf_read_value(data, NCT6775_REG_FANDIV2);
data->fan_div[2] = i & 0x7;
- if (data->has_fan & (1<<3))
+ if (data->has_fan & (1 << 3))
data->fan_div[3] = (i & 0x70) >> 4;
}

@@ -931,9 +929,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
return data;
}

-
-static void
-store_fan_min(struct device *dev, u32 channel, unsigned long val)
+static void store_fan_min(struct device *dev, u32 channel, unsigned long val)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
int nr = channel;
@@ -1010,10 +1006,8 @@ store_fan_min(struct device *dev, u32 channel, unsigned long val)
data->last_updated = jiffies;
}
done:
- w83627ehf_write_value(data, data->REG_FAN_MIN[nr],
- data->fan_min[nr]);
+ w83627ehf_write_value(data, data->REG_FAN_MIN[nr], data->fan_min[nr]);
mutex_unlock(&data->update_lock);
-
}

#define show_tol_temp(reg) \
@@ -1032,7 +1026,7 @@ show_tol_temp(target_temp)

static ssize_t
store_target_temp(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
+ const char *buf, size_t count)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
@@ -1055,7 +1049,7 @@ store_target_temp(struct device *dev, struct device_attribute *attr,

static ssize_t
store_tolerance(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
+ const char *buf, size_t count)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
struct w83627ehf_sio_data *sio_data = data->sio_data;
@@ -1239,11 +1233,11 @@ static ssize_t
cpu0_vid_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
+
return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
}
static DEVICE_ATTR_RO(cpu0_vid);

-
/* Case open detection */

static ssize_t
@@ -1320,8 +1314,7 @@ static inline void w83627ehf_init_device(struct w83627ehf_data *data,
/* Start monitoring is needed */
tmp = w83627ehf_read_value(data, W83627EHF_REG_CONFIG);
if (!(tmp & 0x01))
- w83627ehf_write_value(data, W83627EHF_REG_CONFIG,
- tmp | 0x01);
+ w83627ehf_write_value(data, W83627EHF_REG_CONFIG, tmp | 0x01);

/* Enable temperature sensors if needed */
for (i = 0; i < NUM_REG_TEMP; i++) {
@@ -1329,8 +1322,7 @@ static inline void w83627ehf_init_device(struct w83627ehf_data *data,
continue;
if (!data->reg_temp_config[i])
continue;
- tmp = w83627ehf_read_value(data,
- data->reg_temp_config[i]);
+ tmp = w83627ehf_read_value(data, data->reg_temp_config[i]);
if (tmp & 0x01)
w83627ehf_write_value(data,
data->reg_temp_config[i],
@@ -1371,8 +1363,7 @@ static inline void w83627ehf_init_device(struct w83627ehf_data *data,
}
}

-static void w82627ehf_swap_tempreg(struct w83627ehf_data *data,
- int r1, int r2)
+static void w82627ehf_swap_tempreg(struct w83627ehf_data *data, int r1, int r2)
{
swap(data->temp_src[r1], data->temp_src[r2]);
swap(data->reg_temp[r1], data->reg_temp[r2]);
@@ -1381,8 +1372,7 @@ static void w82627ehf_swap_tempreg(struct w83627ehf_data *data,
swap(data->reg_temp_config[r1], data->reg_temp_config[r2]);
}

-static void
-w83627ehf_set_temp_reg_ehf(struct w83627ehf_data *data, int n_temp)
+static void w83627ehf_set_temp_reg_ehf(struct w83627ehf_data *data, int n_temp)
{
int i;

@@ -2455,7 +2445,6 @@ static int w83627ehf_probe(struct platform_device *pdev)
&sda_sf3_arrays_fan4[i].dev_attr.attr;
}

-
for (i = 0; i < 5; i++) {
if (data->has_fan & (1 << i)) {
if (i < data->pwm_num) {
--
2.10.2

2017-03-23 00:39:41

by Peter Huewe

[permalink] [raw]
Subject: [PATCH 2/4] w83627ehf: Use octal values for access rights of sysfs files

As indicated by checkpatch, use the octal representation for the access
rights.

S_IWUSR | S_IRUGO => 0644
S_IRUGO => 0444

Signed-off-by: Peter Huewe <[email protected]>
---
drivers/hwmon/w83627ehf.c | 52 ++++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 30 deletions(-)

diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 785ddd47c588..b0eac8e35cc5 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1094,25 +1094,17 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
}

static struct sensor_device_attribute sda_target_temp[] = {
- SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp,
- store_target_temp, 0),
- SENSOR_ATTR(pwm2_target, S_IWUSR | S_IRUGO, show_target_temp,
- store_target_temp, 1),
- SENSOR_ATTR(pwm3_target, S_IWUSR | S_IRUGO, show_target_temp,
- store_target_temp, 2),
- SENSOR_ATTR(pwm4_target, S_IWUSR | S_IRUGO, show_target_temp,
- store_target_temp, 3),
+ SENSOR_ATTR(pwm1_target, 0644, show_target_temp, store_target_temp, 0),
+ SENSOR_ATTR(pwm2_target, 0644, show_target_temp, store_target_temp, 1),
+ SENSOR_ATTR(pwm3_target, 0644, show_target_temp, store_target_temp, 2),
+ SENSOR_ATTR(pwm4_target, 0644, show_target_temp, store_target_temp, 3),
};

static struct sensor_device_attribute sda_tolerance[] = {
- SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
- store_tolerance, 0),
- SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
- store_tolerance, 1),
- SENSOR_ATTR(pwm3_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
- store_tolerance, 2),
- SENSOR_ATTR(pwm4_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
- store_tolerance, 3),
+ SENSOR_ATTR(pwm1_tolerance, 0644, show_tolerance, store_tolerance, 0),
+ SENSOR_ATTR(pwm2_tolerance, 0644, show_tolerance, store_tolerance, 1),
+ SENSOR_ATTR(pwm3_tolerance, 0644, show_tolerance, store_tolerance, 2),
+ SENSOR_ATTR(pwm4_tolerance, 0644, show_tolerance, store_tolerance, 3),
};

/* Smart Fan registers */
@@ -1190,24 +1182,24 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
fan_time_functions(fan_stop_time, FAN_STOP_TIME)

static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
- SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
+ SENSOR_ATTR(pwm4_stop_time, 0644, show_fan_stop_time,
store_fan_stop_time, 3),
- SENSOR_ATTR(pwm4_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
+ SENSOR_ATTR(pwm4_start_output, 0644, show_fan_start_output,
store_fan_start_output, 3),
- SENSOR_ATTR(pwm4_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
+ SENSOR_ATTR(pwm4_stop_output, 0644, show_fan_stop_output,
store_fan_stop_output, 3),
- SENSOR_ATTR(pwm4_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
+ SENSOR_ATTR(pwm4_max_output, 0644, show_fan_max_output,
store_fan_max_output, 3),
- SENSOR_ATTR(pwm4_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
+ SENSOR_ATTR(pwm4_step_output, 0644, show_fan_step_output,
store_fan_step_output, 3),
};

static struct sensor_device_attribute sda_sf3_arrays_fan3[] = {
- SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
+ SENSOR_ATTR(pwm3_stop_time, 0644, show_fan_stop_time,
store_fan_stop_time, 2),
- SENSOR_ATTR(pwm3_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
+ SENSOR_ATTR(pwm3_start_output, 0644, show_fan_start_output,
store_fan_start_output, 2),
- SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
+ SENSOR_ATTR(pwm3_stop_output, 0644, show_fan_stop_output,
store_fan_stop_output, 2),
};

@@ -1229,17 +1221,17 @@ static SENSOR_DEVICE_ATTR(pwm2_stop_output, 0644, show_fan_stop_output,
* Need to check support while generating/removing attribute files.
*/
static struct sensor_device_attribute sda_sf3_max_step_arrays[] = {
- SENSOR_ATTR(pwm1_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
+ SENSOR_ATTR(pwm1_max_output, 0644, show_fan_max_output,
store_fan_max_output, 0),
- SENSOR_ATTR(pwm1_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
+ SENSOR_ATTR(pwm1_step_output, 0644, show_fan_step_output,
store_fan_step_output, 0),
- SENSOR_ATTR(pwm2_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
+ SENSOR_ATTR(pwm2_max_output, 0644, show_fan_max_output,
store_fan_max_output, 1),
- SENSOR_ATTR(pwm2_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
+ SENSOR_ATTR(pwm2_step_output, 0644, show_fan_step_output,
store_fan_step_output, 1),
- SENSOR_ATTR(pwm3_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
+ SENSOR_ATTR(pwm3_max_output, 0644, show_fan_max_output,
store_fan_max_output, 2),
- SENSOR_ATTR(pwm3_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
+ SENSOR_ATTR(pwm3_step_output, 0644, show_fan_step_output,
store_fan_step_output, 2),
};

--
2.10.2

2017-03-23 02:53:11

by Peter Huewe

[permalink] [raw]
Subject: [PATCH] w83627ehf: Drop support for nct6775/nct6776

Since there exists a dedicated driver for nct6775/nct6776 it makes sense
to remove support for these chips from this driver, in order to have
only one code base for these types of chips.

This also improves maintainability and readability (and size) of this
driver.

Some not so-obvious changes are:
- removal of fan_debounce module parameter (now unused)
- removal of has_fan_div flag (nct6776 specific)
- w83627ehf_update_fan_div_common -> w83627ehf_update_fan_div
(no distinction needed anymore)
- w83627ehf_update_pwm_common -> w83627ehf_update_pwm
(no distinction needed anymore)
- NUM_REG_TEMP changed to ARRAY_SIZE(W83627EHF_REG_TEMP)
(different number of max temp sensors)
- removal of intrusion1_alarm (nct6776 specific)

Tested with NCT6776F that it does not get probed anymore.

Signed-off-by: Peter Huewe <[email protected]>
---
Please apply after my conversion patch series.

drivers/hwmon/w83627ehf.c | 542 ++++------------------------------------------
1 file changed, 43 insertions(+), 499 deletions(-)

diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index bba26623af36..8e7ad86422ed 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -31,8 +31,6 @@
* w83627uhg 8 2 2 3 0xa230 0xc1 0x5ca3
* w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3
* w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3
- * nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3
- * nct6776f 9 5 3 9 0xC330 0xc1 0x5ca3
*/

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -53,7 +51,7 @@

enum kinds {
w83627ehf, w83627dhg, w83627dhg_p, w83627uhg,
- w83667hg, w83667hg_b, nct6775, nct6776,
+ w83667hg, w83667hg_b,
};

/* used to set data->name = w83627ehf_device_names[data->sio_kind] */
@@ -64,18 +62,12 @@ static const char * const w83627ehf_device_names[] = {
"w83627uhg",
"w83667hg",
"w83667hg",
- "nct6775",
- "nct6776",
};

static unsigned short force_id;
module_param(force_id, ushort, 0);
MODULE_PARM_DESC(force_id, "Override the detected device ID");

-static unsigned short fan_debounce;
-module_param(fan_debounce, ushort, 0);
-MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
-
#define DRVNAME "w83627ehf"

/*
@@ -100,8 +92,6 @@ MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
#define SIO_W83627UHG_ID 0xa230
#define SIO_W83667HG_ID 0xa510
#define SIO_W83667HG_B_ID 0xb350
-#define SIO_NCT6775_ID 0xb470
-#define SIO_NCT6776_ID 0xc330
#define SIO_ID_MASK 0xFFF0

static inline void
@@ -184,11 +174,6 @@ static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0, 0x152, 0x252, 0 };
#define W83627EHF_REG_DIODE 0x59
#define W83627EHF_REG_SMI_OVT 0x4C

-/* NCT6775F has its own fan divider registers */
-#define NCT6775_REG_FANDIV1 0x506
-#define NCT6775_REG_FANDIV2 0x507
-#define NCT6775_REG_FAN_DEBOUNCE 0xf0
-
#define W83627EHF_REG_ALARM1 0x459
#define W83627EHF_REG_ALARM2 0x45A
#define W83627EHF_REG_ALARM3 0x45B
@@ -232,28 +217,6 @@ static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[]

static const u16 W83627EHF_REG_TEMP_OFFSET[] = { 0x454, 0x455, 0x456 };

-static const u16 NCT6775_REG_TARGET[] = { 0x101, 0x201, 0x301 };
-static const u16 NCT6775_REG_FAN_MODE[] = { 0x102, 0x202, 0x302 };
-static const u16 NCT6775_REG_FAN_STOP_OUTPUT[] = { 0x105, 0x205, 0x305 };
-static const u16 NCT6775_REG_FAN_START_OUTPUT[] = { 0x106, 0x206, 0x306 };
-static const u16 NCT6775_REG_FAN_STOP_TIME[] = { 0x107, 0x207, 0x307 };
-static const u16 NCT6775_REG_PWM[] = { 0x109, 0x209, 0x309 };
-static const u16 NCT6775_REG_FAN_MAX_OUTPUT[] = { 0x10a, 0x20a, 0x30a };
-static const u16 NCT6775_REG_FAN_STEP_OUTPUT[] = { 0x10b, 0x20b, 0x30b };
-static const u16 NCT6775_REG_FAN[] = { 0x630, 0x632, 0x634, 0x636, 0x638 };
-static const u16 NCT6776_REG_FAN_MIN[] = { 0x63a, 0x63c, 0x63e, 0x640, 0x642};
-
-static const u16 NCT6775_REG_TEMP[]
- = { 0x27, 0x150, 0x250, 0x73, 0x75, 0x77, 0x62b, 0x62c, 0x62d };
-static const u16 NCT6775_REG_TEMP_CONFIG[]
- = { 0, 0x152, 0x252, 0, 0, 0, 0x628, 0x629, 0x62A };
-static const u16 NCT6775_REG_TEMP_HYST[]
- = { 0x3a, 0x153, 0x253, 0, 0, 0, 0x673, 0x678, 0x67D };
-static const u16 NCT6775_REG_TEMP_OVER[]
- = { 0x39, 0x155, 0x255, 0, 0, 0, 0x672, 0x677, 0x67C };
-static const u16 NCT6775_REG_TEMP_SOURCE[]
- = { 0x621, 0x622, 0x623, 0x100, 0x200, 0x300, 0x624, 0x625, 0x626 };
-
static const char *const w83667hg_b_temp_label[] = {
"SYSTIN",
"CPUTIN",
@@ -265,57 +228,7 @@ static const char *const w83667hg_b_temp_label[] = {
"PECI Agent 4"
};

-static const char *const nct6775_temp_label[] = {
- "",
- "SYSTIN",
- "CPUTIN",
- "AUXTIN",
- "AMD SB-TSI",
- "PECI Agent 0",
- "PECI Agent 1",
- "PECI Agent 2",
- "PECI Agent 3",
- "PECI Agent 4",
- "PECI Agent 5",
- "PECI Agent 6",
- "PECI Agent 7",
- "PCH_CHIP_CPU_MAX_TEMP",
- "PCH_CHIP_TEMP",
- "PCH_CPU_TEMP",
- "PCH_MCH_TEMP",
- "PCH_DIM0_TEMP",
- "PCH_DIM1_TEMP",
- "PCH_DIM2_TEMP",
- "PCH_DIM3_TEMP"
-};
-
-static const char *const nct6776_temp_label[] = {
- "",
- "SYSTIN",
- "CPUTIN",
- "AUXTIN",
- "SMBUSMASTER 0",
- "SMBUSMASTER 1",
- "SMBUSMASTER 2",
- "SMBUSMASTER 3",
- "SMBUSMASTER 4",
- "SMBUSMASTER 5",
- "SMBUSMASTER 6",
- "SMBUSMASTER 7",
- "PECI Agent 0",
- "PECI Agent 1",
- "PCH_CHIP_CPU_MAX_TEMP",
- "PCH_CHIP_TEMP",
- "PCH_CPU_TEMP",
- "PCH_MCH_TEMP",
- "PCH_DIM0_TEMP",
- "PCH_DIM1_TEMP",
- "PCH_DIM2_TEMP",
- "PCH_DIM3_TEMP",
- "BYTE_TEMP"
-};
-
-#define NUM_REG_TEMP ARRAY_SIZE(NCT6775_REG_TEMP)
+#define NUM_REG_TEMP ARRAY_SIZE(W83627EHF_REG_TEMP)

static int is_word_sized(u16 reg)
{
@@ -355,31 +268,6 @@ static unsigned int fan_from_reg8(u16 reg, unsigned int divreg)
return 1350000U / (reg << divreg);
}

-static unsigned int fan_from_reg13(u16 reg, unsigned int divreg)
-{
- if ((reg & 0xff1f) == 0xff1f)
- return 0;
-
- reg = (reg & 0x1f) | ((reg & 0xff00) >> 3);
-
- if (reg == 0)
- return 0;
-
- return 1350000U / reg;
-}
-
-static unsigned int fan_from_reg16(u16 reg, unsigned int divreg)
-{
- if (reg == 0 || reg == 0xffff)
- return 0;
-
- /*
- * Even though the registers are 16 bit wide, the fan divisor
- * still applies.
- */
- return 1350000U / (reg << divreg);
-}
-
static inline unsigned int
div_from_reg(u8 reg)
{
@@ -459,7 +347,6 @@ struct w83627ehf_data {
u8 fan_div[5];
u8 has_fan; /* some fan inputs can be disabled */
u8 has_fan_min; /* some fans don't have min register */
- bool has_fan_div;
u8 temp_type[3];
s8 temp_offset[3];
s16 temp[9];
@@ -580,35 +467,6 @@ static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg, u16 value)
}

/* This function assumes that the caller holds data->update_lock */
-static void nct6775_write_fan_div(struct w83627ehf_data *data, int nr)
-{
- u8 reg;
-
- switch (nr) {
- case 0:
- reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV1) & 0x70)
- | (data->fan_div[0] & 0x7);
- w83627ehf_write_value(data, NCT6775_REG_FANDIV1, reg);
- break;
- case 1:
- reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV1) & 0x7)
- | ((data->fan_div[1] << 4) & 0x70);
- w83627ehf_write_value(data, NCT6775_REG_FANDIV1, reg);
- break;
- case 2:
- reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV2) & 0x70)
- | (data->fan_div[2] & 0x7);
- w83627ehf_write_value(data, NCT6775_REG_FANDIV2, reg);
- break;
- case 3:
- reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV2) & 0x7)
- | ((data->fan_div[3] << 4) & 0x70);
- w83627ehf_write_value(data, NCT6775_REG_FANDIV2, reg);
- break;
- }
-}
-
-/* This function assumes that the caller holds data->update_lock */
static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr)
{
u8 reg;
@@ -659,32 +517,6 @@ static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr)
}
}

-static void w83627ehf_write_fan_div_common(struct device *dev,
- struct w83627ehf_data *data, int nr)
-{
- struct w83627ehf_sio_data *sio_data = data->sio_data;
-
- if (sio_data->kind == nct6776)
- ; /* no dividers, do nothing */
- else if (sio_data->kind == nct6775)
- nct6775_write_fan_div(data, nr);
- else
- w83627ehf_write_fan_div(data, nr);
-}
-
-static void nct6775_update_fan_div(struct w83627ehf_data *data)
-{
- u8 i;
-
- i = w83627ehf_read_value(data, NCT6775_REG_FANDIV1);
- data->fan_div[0] = i & 0x7;
- data->fan_div[1] = (i & 0x70) >> 4;
- i = w83627ehf_read_value(data, NCT6775_REG_FANDIV2);
- data->fan_div[2] = i & 0x7;
- if (data->has_fan & (1 << 3))
- data->fan_div[3] = (i & 0x70) >> 4;
-}
-
static void w83627ehf_update_fan_div(struct w83627ehf_data *data)
{
int i;
@@ -710,37 +542,6 @@ static void w83627ehf_update_fan_div(struct w83627ehf_data *data)
}
}

-static void w83627ehf_update_fan_div_common(struct device *dev,
- struct w83627ehf_data *data)
-{
- if (data->sio_data) {
- if (data->sio_data->kind == nct6776)
- ; /* no dividers, do nothing */
- else if (data->sio_data->kind == nct6775)
- nct6775_update_fan_div(data);
- else
- w83627ehf_update_fan_div(data);
- }
-}
-
-static void nct6775_update_pwm(struct w83627ehf_data *data)
-{
- int i;
- int pwmcfg, fanmodecfg;
-
- for (i = 0; i < data->pwm_num; i++) {
- pwmcfg = w83627ehf_read_value(data,
- W83627EHF_REG_PWM_ENABLE[i]);
- fanmodecfg = w83627ehf_read_value(data,
- NCT6775_REG_FAN_MODE[i]);
- data->pwm_mode[i] =
- ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1) ? 0 : 1;
- data->pwm_enable[i] = ((fanmodecfg >> 4) & 7) + 1;
- data->tolerance[i] = fanmodecfg & 0x0f;
- data->pwm[i] = w83627ehf_read_value(data, data->REG_PWM[i]);
- }
-}
-
static void w83627ehf_update_pwm(struct w83627ehf_data *data)
{
int i;
@@ -767,21 +568,9 @@ static void w83627ehf_update_pwm(struct w83627ehf_data *data)
}
}

-static void w83627ehf_update_pwm_common(struct device *dev,
- struct w83627ehf_data *data)
-{
- struct w83627ehf_sio_data *sio_data = data->sio_data;
-
- if (sio_data->kind == nct6775 || sio_data->kind == nct6776)
- nct6775_update_pwm(data);
- else
- w83627ehf_update_pwm(data);
-}
-
static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = data->sio_data;
int i;

mutex_lock(&data->update_lock);
@@ -789,7 +578,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
if (time_after(jiffies, data->last_updated + HZ + HZ/2)
|| !data->valid) {
/* Fan clock dividers */
- w83627ehf_update_fan_div_common(dev, data);
+ w83627ehf_update_fan_div(data);

/* Measured voltages and limits */
for (i = 0; i < data->in_num; i++) {
@@ -824,16 +613,13 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
* divider can be increased, let's try that for next
* time
*/
- if (data->has_fan_div
- && (reg >= 0xff || (sio_data->kind == nct6775
- && reg == 0x00))
- && data->fan_div[i] < 0x07) {
+ if (reg >= 0xff && data->fan_div[i] < 0x07) {
dev_dbg(dev,
"Increasing fan%d clock divider from %u to %u\n",
i + 1, div_from_reg(data->fan_div[i]),
div_from_reg(data->fan_div[i] + 1));
data->fan_div[i]++;
- w83627ehf_write_fan_div_common(dev, data, i);
+ w83627ehf_write_fan_div(data, i);
/* Preserve min limit if possible */
if ((data->has_fan_min & (1 << i))
&& data->fan_min[i] >= 2
@@ -844,7 +630,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
}
}

- w83627ehf_update_pwm_common(dev, data);
+ w83627ehf_update_pwm(data);

for (i = 0; i < data->pwm_num; i++) {
if (!(data->has_fan & (1 << i)))
@@ -926,22 +712,6 @@ static void store_fan_min(struct device *dev, u32 channel, unsigned long val)
u8 new_div;

mutex_lock(&data->update_lock);
- if (!data->has_fan_div) {
- /*
- * Only NCT6776F for now, so we know that this is a 13 bit
- * register
- */
- if (!val) {
- val = 0xff1f;
- } else {
- if (val > 1350000U)
- val = 135000U;
- val = 1350000U / val;
- val = (val & 0x1f) | ((val << 3) & 0xff00);
- }
- data->fan_min[nr] = val;
- goto done; /* Leave fan divider alone */
- }
if (!val) {
/* No min limit, alarm disabled */
data->fan_min[nr] = 255;
@@ -990,11 +760,11 @@ static void store_fan_min(struct device *dev, u32 channel, unsigned long val)
nr + 1, div_from_reg(data->fan_div[nr]),
div_from_reg(new_div));
data->fan_div[nr] = new_div;
- w83627ehf_write_fan_div_common(dev, data, nr);
+ w83627ehf_write_fan_div(data, nr);
/* Give the chip time to sample a new speed value */
data->last_updated = jiffies;
}
-done:
+
w83627ehf_write_value(data, data->REG_FAN_MIN[nr], data->fan_min[nr]);
mutex_unlock(&data->update_lock);
}
@@ -1041,7 +811,6 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = data->sio_data;
struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
int nr = sensor_attr->index;
u16 reg;
@@ -1056,21 +825,12 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 15);

mutex_lock(&data->update_lock);
- if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
- /* Limit tolerance further for NCT6776F */
- if (sio_data->kind == nct6776 && val > 7)
- val = 7;
- reg = w83627ehf_read_value(data, NCT6775_REG_FAN_MODE[nr]);
+ reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);
+ if (nr == 1)
+ reg = (reg & 0x0f) | (val << 4);
+ else
reg = (reg & 0xf0) | val;
- w83627ehf_write_value(data, NCT6775_REG_FAN_MODE[nr], reg);
- } else {
- reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);
- if (nr == 1)
- reg = (reg & 0x0f) | (val << 4);
- else
- reg = (reg & 0xf0) | val;
- w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg);
- }
+ w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg);
data->tolerance[nr] = val;
mutex_unlock(&data->update_lock);
return count;
@@ -1263,8 +1023,6 @@ clear_caseopen(struct device *dev, struct device_attribute *attr,

static SENSOR_DEVICE_ATTR_2(intrusion0_alarm, 0644, show_caseopen,
clear_caseopen, 0x80, 0x10);
-static SENSOR_DEVICE_ATTR_2(intrusion1_alarm, 0644, show_caseopen,
- clear_caseopen, 0x40, 0x40);

#define NUMBER_OF_STATIC_SENSOR_ATTRS (7)
#define NUMBER_OF_SENSOR_ATTRS ( \
@@ -1352,15 +1110,6 @@ static inline void w83627ehf_init_device(struct w83627ehf_data *data,
}
}

-static void w82627ehf_swap_tempreg(struct w83627ehf_data *data, int r1, int r2)
-{
- swap(data->temp_src[r1], data->temp_src[r2]);
- swap(data->reg_temp[r1], data->reg_temp[r2]);
- swap(data->reg_temp_over[r1], data->reg_temp_over[r2]);
- swap(data->reg_temp_hyst[r1], data->reg_temp_hyst[r2]);
- swap(data->reg_temp_config[r1], data->reg_temp_config[r2]);
-}
-
static void w83627ehf_set_temp_reg_ehf(struct w83627ehf_data *data, int n_temp)
{
int i;
@@ -1388,36 +1137,7 @@ w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,

superio_enter(sio_data->sioreg);

- /* fan4 and fan5 share some pins with the GPIO and serial flash */
- if (sio_data->kind == nct6775) {
- /* On NCT6775, fan4 shares pins with the fdc interface */
- fan3pin = 1;
- fan4pin = !(superio_inb(sio_data->sioreg, 0x2A) & 0x80);
- fan4min = 0;
- fan5pin = 0;
- } else if (sio_data->kind == nct6776) {
- bool gpok = superio_inb(sio_data->sioreg, 0x27) & 0x80;
-
- superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
- regval = superio_inb(sio_data->sioreg, SIO_REG_ENABLE);
-
- if (regval & 0x80)
- fan3pin = gpok;
- else
- fan3pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x40);
-
- if (regval & 0x40)
- fan4pin = gpok;
- else
- fan4pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x01);
-
- if (regval & 0x20)
- fan5pin = gpok;
- else
- fan5pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x02);
-
- fan4min = fan4pin;
- } else if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
+ if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
fan3pin = 1;
fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40;
fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20;
@@ -1435,30 +1155,21 @@ w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
data->has_fan |= (fan3pin << 2);
data->has_fan_min |= (fan3pin << 2);

- if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
- /*
- * NCT6775F and NCT6776F don't have the W83627EHF_REG_FANDIV1
- * register
- */
- data->has_fan |= (fan4pin << 3) | (fan5pin << 4);
- data->has_fan_min |= (fan4min << 3) | (fan5pin << 4);
- } else {
- /*
- * It looks like fan4 and fan5 pins can be alternatively used
- * as fan on/off switches, but fan5 control is write only :/
- * We assume that if the serial interface is disabled, designers
- * connected fan5 as input unless they are emitting log 1, which
- * is not the default.
- */
- regval = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1);
- if ((regval & (1 << 2)) && fan4pin) {
- data->has_fan |= (1 << 3);
- data->has_fan_min |= (1 << 3);
- }
- if (!(regval & (1 << 1)) && fan5pin) {
- data->has_fan |= (1 << 4);
- data->has_fan_min |= (1 << 4);
- }
+ /*
+ * It looks like fan4 and fan5 pins can be alternatively used
+ * as fan on/off switches, but fan5 control is write only :/
+ * We assume that if the serial interface is disabled, designers
+ * connected fan5 as input unless they are emitting log 1, which
+ * is not the default.
+ */
+ regval = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1);
+ if ((regval & (1 << 2)) && fan4pin) {
+ data->has_fan |= (1 << 3);
+ data->has_fan_min |= (1 << 3);
+ }
+ if (!(regval & (1 << 1)) && fan5pin) {
+ data->has_fan |= (1 << 4);
+ data->has_fan_min |= (1 << 4);
}
}

@@ -1649,10 +1360,7 @@ static umode_t w3627ehf_fan_is_visible(const void *_data, u32 attr, int channel)
case hwmon_fan_input:
return 0444;
case hwmon_fan_div:
- if (data->sio_data->kind != nct6776)
- return 0444;
- else
- return 0;
+ return 0444;
case hwmon_fan_min:
return 0644;
}
@@ -1663,7 +1371,6 @@ static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
long val)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = data->sio_data;
u16 reg;

switch (attr) {
@@ -1678,10 +1385,6 @@ static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
if (val > 1)
return -EINVAL;

- /* On NCT67766F, DC mode is only supported for pwm1 */
- if (sio_data->kind == nct6776 && channel && val != 1)
- return -EINVAL;
-
mutex_lock(&data->update_lock);
reg = w83627ehf_read_value(data,
W83627EHF_REG_PWM_ENABLE[channel]);
@@ -1696,29 +1399,15 @@ static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
case hwmon_pwm_enable:
if (!val || (val > 4 && val != data->pwm_enable_orig[channel]))
return -EINVAL;
- /* SmartFan III mode is not supported on NCT6776F */
- if (sio_data->kind == nct6776 && val == 4)
- return -EINVAL;
-
mutex_lock(&data->update_lock);
data->pwm_enable[channel] = val;
- if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
- reg = w83627ehf_read_value(data,
- NCT6775_REG_FAN_MODE[channel]);
- reg &= 0x0f;
- reg |= (val - 1) << 4;
- w83627ehf_write_value(data,
- NCT6775_REG_FAN_MODE[channel],
- reg);
- } else {
- reg = w83627ehf_read_value(data,
- W83627EHF_REG_PWM_ENABLE[channel]);
- reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[channel]);
- reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel];
- w83627ehf_write_value(data,
- W83627EHF_REG_PWM_ENABLE[channel],
- reg);
- }
+ reg = w83627ehf_read_value(data,
+ W83627EHF_REG_PWM_ENABLE[channel]);
+ reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[channel]);
+ reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel];
+ w83627ehf_write_value(data,
+ W83627EHF_REG_PWM_ENABLE[channel],
+ reg);
mutex_unlock(&data->update_lock);
return 0;
default:
@@ -2060,15 +1749,13 @@ static int w83627ehf_probe(struct platform_device *pdev)

/* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */
data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9;
- /* 667HG, NCT6775F, and NCT6776F have 3 pwms, and 627UHG has only 2 */
+ /* 667HG has 3 pwms, and 627UHG has only 2 */
switch (sio_data->kind) {
default:
data->pwm_num = 4;
break;
case w83667hg:
case w83667hg_b:
- case nct6775:
- case nct6776:
data->pwm_num = 3;
break;
case w83627uhg:
@@ -2080,83 +1767,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
data->have_temp = 0x07;

/* Deal with temperature register setup first. */
- if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
- int mask = 0;
-
- /*
- * Display temperature sensor output only if it monitors
- * a source other than one already reported. Always display
- * first three temperature registers, though.
- */
- for (i = 0; i < NUM_REG_TEMP; i++) {
- u8 src;
-
- data->reg_temp[i] = NCT6775_REG_TEMP[i];
- data->reg_temp_over[i] = NCT6775_REG_TEMP_OVER[i];
- data->reg_temp_hyst[i] = NCT6775_REG_TEMP_HYST[i];
- data->reg_temp_config[i] = NCT6775_REG_TEMP_CONFIG[i];
-
- src = w83627ehf_read_value(data,
- NCT6775_REG_TEMP_SOURCE[i]);
- src &= 0x1f;
- if (src && !(mask & (1 << src))) {
- data->have_temp |= 1 << i;
- mask |= 1 << src;
- }
-
- data->temp_src[i] = src;
-
- /*
- * Now do some register swapping if index 0..2 don't
- * point to SYSTIN(1), CPUIN(2), and AUXIN(3).
- * Idea is to have the first three attributes
- * report SYSTIN, CPUIN, and AUXIN if possible
- * without overriding the basic system configuration.
- */
- if (i > 0 && data->temp_src[0] != 1
- && data->temp_src[i] == 1)
- w82627ehf_swap_tempreg(data, 0, i);
- if (i > 1 && data->temp_src[1] != 2
- && data->temp_src[i] == 2)
- w82627ehf_swap_tempreg(data, 1, i);
- if (i > 2 && data->temp_src[2] != 3
- && data->temp_src[i] == 3)
- w82627ehf_swap_tempreg(data, 2, i);
- }
- if (sio_data->kind == nct6776) {
- /*
- * On NCT6776, AUXTIN and VIN3 pins are shared.
- * Only way to detect it is to check if AUXTIN is used
- * as a temperature source, and if that source is
- * enabled.
- *
- * If that is the case, disable in6, which reports VIN3.
- * Otherwise disable temp3.
- */
- if (data->temp_src[2] == 3) {
- u8 reg;
-
- if (data->reg_temp_config[2])
- reg = w83627ehf_read_value(data,
- data->reg_temp_config[2]);
- else
- reg = 0; /* Assume AUXTIN is used */
-
- if (reg & 0x01)
- data->have_temp &= ~(1 << 2);
- else
- data->in6_skip = 1;
- }
- data->temp_label = nct6776_temp_label;
- } else {
- data->temp_label = nct6775_temp_label;
- }
- data->have_temp_offset = data->have_temp & 0x07;
- for (i = 0; i < 3; i++) {
- if (data->temp_src[i] > 3)
- data->have_temp_offset &= ~(1 << i);
- }
- } else if (sio_data->kind == w83667hg_b) {
+ if (sio_data->kind == w83667hg_b) {
u8 reg;

w83627ehf_set_temp_reg_ehf(data, 4);
@@ -2266,32 +1877,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
data->have_temp_offset = data->have_temp & 0x07;
}

- if (sio_data->kind == nct6775) {
- data->has_fan_div = true;
- data->fan_from_reg = fan_from_reg16;
- data->fan_from_reg_min = fan_from_reg8;
- data->REG_PWM = NCT6775_REG_PWM;
- data->REG_TARGET = NCT6775_REG_TARGET;
- data->REG_FAN = NCT6775_REG_FAN;
- data->REG_FAN_MIN = W83627EHF_REG_FAN_MIN;
- data->REG_FAN_START_OUTPUT = NCT6775_REG_FAN_START_OUTPUT;
- data->REG_FAN_STOP_OUTPUT = NCT6775_REG_FAN_STOP_OUTPUT;
- data->REG_FAN_STOP_TIME = NCT6775_REG_FAN_STOP_TIME;
- data->REG_FAN_MAX_OUTPUT = NCT6775_REG_FAN_MAX_OUTPUT;
- data->REG_FAN_STEP_OUTPUT = NCT6775_REG_FAN_STEP_OUTPUT;
- } else if (sio_data->kind == nct6776) {
- data->has_fan_div = false;
- data->fan_from_reg = fan_from_reg13;
- data->fan_from_reg_min = fan_from_reg13;
- data->REG_PWM = NCT6775_REG_PWM;
- data->REG_TARGET = NCT6775_REG_TARGET;
- data->REG_FAN = NCT6775_REG_FAN;
- data->REG_FAN_MIN = NCT6776_REG_FAN_MIN;
- data->REG_FAN_START_OUTPUT = NCT6775_REG_FAN_START_OUTPUT;
- data->REG_FAN_STOP_OUTPUT = NCT6775_REG_FAN_STOP_OUTPUT;
- data->REG_FAN_STOP_TIME = NCT6775_REG_FAN_STOP_TIME;
- } else if (sio_data->kind == w83667hg_b) {
- data->has_fan_div = true;
+ if (sio_data->kind == w83667hg_b) {
data->fan_from_reg = fan_from_reg8;
data->fan_from_reg_min = fan_from_reg8;
data->REG_PWM = W83627EHF_REG_PWM;
@@ -2306,7 +1892,6 @@ static int w83627ehf_probe(struct platform_device *pdev)
data->REG_FAN_STEP_OUTPUT =
W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B;
} else {
- data->has_fan_div = true;
data->fan_from_reg = fan_from_reg8;
data->fan_from_reg_min = fan_from_reg8;
data->REG_PWM = W83627EHF_REG_PWM;
@@ -2334,8 +1919,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
data->vrm = vid_which_vrm();
superio_enter(sio_data->sioreg);
/* Read VID value */
- if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b ||
- sio_data->kind == nct6775 || sio_data->kind == nct6776) {
+ if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
/*
* W83667HG has different pins for VID input and output, so
* we can get the VID input values directly at logical device D
@@ -2385,30 +1969,15 @@ static int w83627ehf_probe(struct platform_device *pdev)
}
}

- if (fan_debounce &&
- (sio_data->kind == nct6775 || sio_data->kind == nct6776)) {
- u8 tmp;
-
- superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
- tmp = superio_inb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE);
- if (sio_data->kind == nct6776)
- superio_outb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE,
- 0x3e | tmp);
- else
- superio_outb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE,
- 0x1e | tmp);
- pr_info("Enabled fan debounce for chip %s\n", data->name);
- }
-
superio_exit(sio_data->sioreg);

w83627ehf_check_fan_inputs(sio_data, data);

/* Read fan clock dividers immediately */
- w83627ehf_update_fan_div_common(dev, data);
+ w83627ehf_update_fan_div(data);

/* Read pwm data to save original values */
- w83627ehf_update_pwm_common(dev, data);
+ w83627ehf_update_pwm(data);
for (i = 0; i < data->pwm_num; i++)
data->pwm_enable_orig[i] = data->pwm_enable[i];

@@ -2445,11 +2014,6 @@ static int w83627ehf_probe(struct platform_device *pdev)
}
}

- if (sio_data->kind == nct6776) {
- *dynamic_attrs++ =
- &sensor_dev_attr_intrusion1_alarm.dev_attr.attr;
- }
-
data->hwmon_dev = hwmon_device_register_with_info(dev, data->name,
data,
&w83627ehf_chip_info,
@@ -2481,14 +2045,9 @@ static int w83627ehf_remove(struct platform_device *pdev)
static int w83627ehf_suspend(struct device *dev)
{
struct w83627ehf_data *data = w83627ehf_update_device(dev);
- struct w83627ehf_sio_data *sio_data = data->sio_data;

mutex_lock(&data->update_lock);
data->vbat = w83627ehf_read_value(data, W83627EHF_REG_VBAT);
- if (sio_data->kind == nct6775) {
- data->fandiv1 = w83627ehf_read_value(data, NCT6775_REG_FANDIV1);
- data->fandiv2 = w83627ehf_read_value(data, NCT6775_REG_FANDIV2);
- }
mutex_unlock(&data->update_lock);

return 0;
@@ -2497,7 +2056,6 @@ static int w83627ehf_suspend(struct device *dev)
static int w83627ehf_resume(struct device *dev)
{
struct w83627ehf_data *data = dev_get_drvdata(dev);
- struct w83627ehf_sio_data *sio_data = data->sio_data;
int i;

mutex_lock(&data->update_lock);
@@ -2542,10 +2100,6 @@ static int w83627ehf_resume(struct device *dev)

/* Restore other settings */
w83627ehf_write_value(data, W83627EHF_REG_VBAT, data->vbat);
- if (sio_data->kind == nct6775) {
- w83627ehf_write_value(data, NCT6775_REG_FANDIV1, data->fandiv1);
- w83627ehf_write_value(data, NCT6775_REG_FANDIV2, data->fandiv2);
- }

/* Force re-reading all values */
data->valid = 0;
@@ -2586,8 +2140,6 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
static const char sio_name_W83627UHG[] __initconst = "W83627UHG";
static const char sio_name_W83667HG[] __initconst = "W83667HG";
static const char sio_name_W83667HG_B[] __initconst = "W83667HG-B";
- static const char sio_name_NCT6775[] __initconst = "NCT6775F";
- static const char sio_name_NCT6776[] __initconst = "NCT6776F";

u16 val;
const char *sio_name;
@@ -2628,14 +2180,6 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
sio_data->kind = w83667hg_b;
sio_name = sio_name_W83667HG_B;
break;
- case SIO_NCT6775_ID:
- sio_data->kind = nct6775;
- sio_name = sio_name_NCT6775;
- break;
- case SIO_NCT6776_ID:
- sio_data->kind = nct6776;
- sio_name = sio_name_NCT6776;
- break;
default:
if (val != 0xffff)
pr_debug("unsupported chip ID: 0x%04x\n", val);
--
2.10.2

2017-03-23 04:50:50

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 1/4] w83627ehf: Use hwmon_device_register_with_info and sensor groups

On 03/22/2017 05:40 PM, Peter Huewe wrote:
> This patch replaces the old, deprecated call to hwmon_device_register
> with the new hwmon_device_register_with_info and converts the whole
> driver to the new hwmon interface using the hwmon_chip_info methods
> and the attribute_group method.
>
> Unfortunately this makes the patch quite large, but it is the most
> sensible way to do so, without doing everything twice.
>

Not part of commit log.

> All standard attributes were converted to the corresponding
> hwmon_chip_info methods.
> For some functions a hwmon channel to device channel conversion had to
> be performed, e.g. hwmon_in_alarm has the info for alert_5 in channel 8.
>
> All non-standard attributes are converted to the attribute_group method,
> by
> - adding them statically to the attribute_group if they are available
> for all variants of devices supported by this driver
> - adding them at probe time to the attribute_group if the availability
> is depending on the actual chip type.
> The appropriate count of entries was reserved.
>
> As a pre-condition a reference to the sio_data structure was moved into
> w83627ehf_data for easier retrieval of the information, since this is
> much easier than trying to access the platform_data.
>
> The driver is now much more "checkpatch clean" than it used to be, but
> still not completely.
> The conversion saves about 20k in the resulting .ko
>
> Tested with a NCT6776F chip.
>
> Signed-off-by: Peter Huewe <[email protected]>
> ---
> Target-Branch: groeck/hwmon

Can you rebase to hwmon-next ? There is a non-trivial conflict.

>
> Please cherry-pick
> 46dc4a97 hwmon: Constify str parameter of hwmon_ops->read_string
> before this patch series
>
This is in hwmon-next.

Overall looks pretty good, except for the handling of
static struct attribute *sensor_attrs[]. Otherwise mostly nitpicks.

Thanks,
Guenter

>
> drivers/hwmon/w83627ehf.c | 1387 +++++++++++++++++++++------------------------
> 1 file changed, 648 insertions(+), 739 deletions(-)
>
> diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
> index ab346ed142de..785ddd47c588 100644
> --- a/drivers/hwmon/w83627ehf.c
> +++ b/drivers/hwmon/w83627ehf.c
> @@ -1,6 +1,7 @@
> /*
> * w83627ehf - Driver for the hardware monitoring functionality of
> * the Winbond W83627EHF Super-I/O chip
> + * Copyright (C) 2017 Peter Huewe <[email protected]>
> * Copyright (C) 2005-2012 Jean Delvare <[email protected]>
> * Copyright (C) 2006 Yuan Mu (Winbond),
> * Rudolf Marek <[email protected]>
> @@ -420,6 +421,11 @@ static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scale_in)
> /*
> * Data structures and manipulation thereof
> */
> +struct w83627ehf_sio_data {
> + int sioreg;
> + enum kinds kind;
> +};
> +
>
> struct w83627ehf_data {
> int addr; /* IO base of hw monitor block */
> @@ -508,11 +514,7 @@ struct w83627ehf_data {
> u8 fandiv1;
> u8 fandiv2;
> #endif
> -};
> -
> -struct w83627ehf_sio_data {
> - int sioreg;
> - enum kinds kind;
> + struct w83627ehf_sio_data *sio_data;
> };
>
> /*
> @@ -673,7 +675,7 @@ static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr)
> static void w83627ehf_write_fan_div_common(struct device *dev,
> struct w83627ehf_data *data, int nr)
> {
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> + struct w83627ehf_sio_data *sio_data = data->sio_data;
>
> if (sio_data->kind == nct6776)
> ; /* no dividers, do nothing */
> @@ -724,14 +726,14 @@ static void w83627ehf_update_fan_div(struct w83627ehf_data *data)
> static void w83627ehf_update_fan_div_common(struct device *dev,
> struct w83627ehf_data *data)
> {
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> -
> - if (sio_data->kind == nct6776)
> - ; /* no dividers, do nothing */
> - else if (sio_data->kind == nct6775)
> - nct6775_update_fan_div(data);
> - else
> - w83627ehf_update_fan_div(data);
> + if (data->sio_data) {

I am frowning on conditionals like this. It should not happen.
If it does, it would be a severe bug. Why do you think it is necessary ?

> + if (data->sio_data->kind == nct6776)
> + ; /* no dividers, do nothing */
> + else if (data->sio_data->kind == nct6775)
> + nct6775_update_fan_div(data);
> + else
> + w83627ehf_update_fan_div(data);
> + }
> }
>
> static void nct6775_update_pwm(struct w83627ehf_data *data)
> @@ -781,7 +783,7 @@ static void w83627ehf_update_pwm(struct w83627ehf_data *data)
> static void w83627ehf_update_pwm_common(struct device *dev,
> struct w83627ehf_data *data)
> {
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> + struct w83627ehf_sio_data *sio_data = data->sio_data;
>
> if (sio_data->kind == nct6775 || sio_data->kind == nct6776)
> nct6775_update_pwm(data);
> @@ -792,8 +794,7 @@ static void w83627ehf_update_pwm_common(struct device *dev,
> static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> -
> + struct w83627ehf_sio_data *sio_data = data->sio_data;
> int i;
>
> mutex_lock(&data->update_lock);
> @@ -930,157 +931,15 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
> return data;
> }
>
> -/*
> - * Sysfs callback functions
> - */
> -#define show_in_reg(reg) \
> -static ssize_t \
> -show_##reg(struct device *dev, struct device_attribute *attr, \
> - char *buf) \
> -{ \
> - struct w83627ehf_data *data = w83627ehf_update_device(dev); \
> - struct sensor_device_attribute *sensor_attr = \
> - to_sensor_dev_attr(attr); \
> - int nr = sensor_attr->index; \
> - return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr, \
> - data->scale_in)); \
> -}
> -show_in_reg(in)
> -show_in_reg(in_min)
> -show_in_reg(in_max)
> -
> -#define store_in_reg(REG, reg) \
> -static ssize_t \
> -store_in_##reg(struct device *dev, struct device_attribute *attr, \
> - const char *buf, size_t count) \
> -{ \
> - struct w83627ehf_data *data = dev_get_drvdata(dev); \
> - struct sensor_device_attribute *sensor_attr = \
> - to_sensor_dev_attr(attr); \
> - int nr = sensor_attr->index; \
> - unsigned long val; \
> - int err; \
> - err = kstrtoul(buf, 10, &val); \
> - if (err < 0) \
> - return err; \
> - mutex_lock(&data->update_lock); \
> - data->in_##reg[nr] = in_to_reg(val, nr, data->scale_in); \
> - w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \
> - data->in_##reg[nr]); \
> - mutex_unlock(&data->update_lock); \
> - return count; \
> -}
> -
> -store_in_reg(MIN, min)
> -store_in_reg(MAX, max)
> -
> -static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
> - char *buf)
> -{
> - struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - return sprintf(buf, "%u\n", (data->alarms >> nr) & 0x01);
> -}
> -
> -static struct sensor_device_attribute sda_in_input[] = {
> - SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
> - SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
> - SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
> - SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
> - SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
> - SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
> - SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
> - SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
> - SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
> - SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9),
> -};
> -
> -static struct sensor_device_attribute sda_in_alarm[] = {
> - SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0),
> - SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1),
> - SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2),
> - SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3),
> - SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8),
> - SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 21),
> - SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20),
> - SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16),
> - SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17),
> - SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 19),
> -};
> -
> -static struct sensor_device_attribute sda_in_min[] = {
> - SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
> - SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
> - SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
> - SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3),
> - SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4),
> - SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5),
> - SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6),
> - SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7),
> - SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8),
> - SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9),
> -};
> -
> -static struct sensor_device_attribute sda_in_max[] = {
> - SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
> - SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
> - SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
> - SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3),
> - SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4),
> - SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5),
> - SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6),
> - SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7),
> - SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8),
> - SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9),
> -};
> -
> -static ssize_t
> -show_fan(struct device *dev, struct device_attribute *attr, char *buf)
> -{
> - struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - return sprintf(buf, "%d\n", data->rpm[nr]);
> -}
> -
> -static ssize_t
> -show_fan_min(struct device *dev, struct device_attribute *attr, char *buf)
> -{
> - struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - return sprintf(buf, "%d\n",
> - data->fan_from_reg_min(data->fan_min[nr],
> - data->fan_div[nr]));
> -}
> -
> -static ssize_t
> -show_fan_div(struct device *dev, struct device_attribute *attr,
> - char *buf)
> -{
> - struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr]));
> -}
>
> -static ssize_t
> -store_fan_min(struct device *dev, struct device_attribute *attr,
> - const char *buf, size_t count)
> +static void
> +store_fan_min(struct device *dev, u32 channel, unsigned long val)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - unsigned long val;
> - int err;
> + int nr = channel;
> unsigned int reg;
> u8 new_div;
>
> - err = kstrtoul(buf, 10, &val);
> - if (err < 0)
> - return err;
> -
> mutex_lock(&data->update_lock);
> if (!data->has_fan_div) {
> /*
> @@ -1155,336 +1014,8 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
> data->fan_min[nr]);
> mutex_unlock(&data->update_lock);
>
> - return count;
> -}
> -
> -static struct sensor_device_attribute sda_fan_input[] = {
> - SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
> - SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
> - SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
> - SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3),
> - SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4),
> -};
> -
> -static struct sensor_device_attribute sda_fan_alarm[] = {
> - SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6),
> - SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7),
> - SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11),
> - SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10),
> - SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23),
> -};
> -
> -static struct sensor_device_attribute sda_fan_min[] = {
> - SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
> - store_fan_min, 0),
> - SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
> - store_fan_min, 1),
> - SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
> - store_fan_min, 2),
> - SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
> - store_fan_min, 3),
> - SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min,
> - store_fan_min, 4),
> -};
> -
> -static struct sensor_device_attribute sda_fan_div[] = {
> - SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0),
> - SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1),
> - SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2),
> - SENSOR_ATTR(fan4_div, S_IRUGO, show_fan_div, NULL, 3),
> - SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
> -};
> -
> -static ssize_t
> -show_temp_label(struct device *dev, struct device_attribute *attr, char *buf)
> -{
> - struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - return sprintf(buf, "%s\n", data->temp_label[data->temp_src[nr]]);
> -}
> -
> -#define show_temp_reg(addr, reg) \
> -static ssize_t \
> -show_##reg(struct device *dev, struct device_attribute *attr, \
> - char *buf) \
> -{ \
> - struct w83627ehf_data *data = w83627ehf_update_device(dev); \
> - struct sensor_device_attribute *sensor_attr = \
> - to_sensor_dev_attr(attr); \
> - int nr = sensor_attr->index; \
> - return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->reg[nr])); \
> -}
> -show_temp_reg(reg_temp, temp);
> -show_temp_reg(reg_temp_over, temp_max);
> -show_temp_reg(reg_temp_hyst, temp_max_hyst);
> -
> -#define store_temp_reg(addr, reg) \
> -static ssize_t \
> -store_##reg(struct device *dev, struct device_attribute *attr, \
> - const char *buf, size_t count) \
> -{ \
> - struct w83627ehf_data *data = dev_get_drvdata(dev); \
> - struct sensor_device_attribute *sensor_attr = \
> - to_sensor_dev_attr(attr); \
> - int nr = sensor_attr->index; \
> - int err; \
> - long val; \
> - err = kstrtol(buf, 10, &val); \
> - if (err < 0) \
> - return err; \
> - mutex_lock(&data->update_lock); \
> - data->reg[nr] = LM75_TEMP_TO_REG(val); \
> - w83627ehf_write_temp(data, data->addr[nr], data->reg[nr]); \
> - mutex_unlock(&data->update_lock); \
> - return count; \
> -}
> -store_temp_reg(reg_temp_over, temp_max);
> -store_temp_reg(reg_temp_hyst, temp_max_hyst);
> -
> -static ssize_t
> -show_temp_offset(struct device *dev, struct device_attribute *attr, char *buf)
> -{
> - struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> -
> - return sprintf(buf, "%d\n",
> - data->temp_offset[sensor_attr->index] * 1000);
> -}
> -
> -static ssize_t
> -store_temp_offset(struct device *dev, struct device_attribute *attr,
> - const char *buf, size_t count)
> -{
> - struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - long val;
> - int err;
> -
> - err = kstrtol(buf, 10, &val);
> - if (err < 0)
> - return err;
> -
> - val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
> -
> - mutex_lock(&data->update_lock);
> - data->temp_offset[nr] = val;
> - w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[nr], val);
> - mutex_unlock(&data->update_lock);
> - return count;
> -}
> -
> -static ssize_t
> -show_temp_type(struct device *dev, struct device_attribute *attr, char *buf)
> -{
> - struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - return sprintf(buf, "%d\n", (int)data->temp_type[nr]);
> -}
> -
> -static struct sensor_device_attribute sda_temp_input[] = {
> - SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
> - SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
> - SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
> - SENSOR_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3),
> - SENSOR_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4),
> - SENSOR_ATTR(temp6_input, S_IRUGO, show_temp, NULL, 5),
> - SENSOR_ATTR(temp7_input, S_IRUGO, show_temp, NULL, 6),
> - SENSOR_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7),
> - SENSOR_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8),
> -};
> -
> -static struct sensor_device_attribute sda_temp_label[] = {
> - SENSOR_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0),
> - SENSOR_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1),
> - SENSOR_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2),
> - SENSOR_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3),
> - SENSOR_ATTR(temp5_label, S_IRUGO, show_temp_label, NULL, 4),
> - SENSOR_ATTR(temp6_label, S_IRUGO, show_temp_label, NULL, 5),
> - SENSOR_ATTR(temp7_label, S_IRUGO, show_temp_label, NULL, 6),
> - SENSOR_ATTR(temp8_label, S_IRUGO, show_temp_label, NULL, 7),
> - SENSOR_ATTR(temp9_label, S_IRUGO, show_temp_label, NULL, 8),
> -};
> -
> -static struct sensor_device_attribute sda_temp_max[] = {
> - SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 0),
> - SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 1),
> - SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 2),
> - SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 3),
> - SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 4),
> - SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 5),
> - SENSOR_ATTR(temp7_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 6),
> - SENSOR_ATTR(temp8_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 7),
> - SENSOR_ATTR(temp9_max, S_IRUGO | S_IWUSR, show_temp_max,
> - store_temp_max, 8),
> -};
> -
> -static struct sensor_device_attribute sda_temp_max_hyst[] = {
> - SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 0),
> - SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 1),
> - SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 2),
> - SENSOR_ATTR(temp4_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 3),
> - SENSOR_ATTR(temp5_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 4),
> - SENSOR_ATTR(temp6_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 5),
> - SENSOR_ATTR(temp7_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 6),
> - SENSOR_ATTR(temp8_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 7),
> - SENSOR_ATTR(temp9_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst,
> - store_temp_max_hyst, 8),
> -};
> -
> -static struct sensor_device_attribute sda_temp_alarm[] = {
> - SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4),
> - SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5),
> - SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
> -};
> -
> -static struct sensor_device_attribute sda_temp_type[] = {
> - SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
> - SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
> - SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
> -};
> -
> -static struct sensor_device_attribute sda_temp_offset[] = {
> - SENSOR_ATTR(temp1_offset, S_IRUGO | S_IWUSR, show_temp_offset,
> - store_temp_offset, 0),
> - SENSOR_ATTR(temp2_offset, S_IRUGO | S_IWUSR, show_temp_offset,
> - store_temp_offset, 1),
> - SENSOR_ATTR(temp3_offset, S_IRUGO | S_IWUSR, show_temp_offset,
> - store_temp_offset, 2),
> -};
> -
> -#define show_pwm_reg(reg) \
> -static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
> - char *buf) \
> -{ \
> - struct w83627ehf_data *data = w83627ehf_update_device(dev); \
> - struct sensor_device_attribute *sensor_attr = \
> - to_sensor_dev_attr(attr); \
> - int nr = sensor_attr->index; \
> - return sprintf(buf, "%d\n", data->reg[nr]); \
> -}
> -
> -show_pwm_reg(pwm_mode)
> -show_pwm_reg(pwm_enable)
> -show_pwm_reg(pwm)
> -
> -static ssize_t
> -store_pwm_mode(struct device *dev, struct device_attribute *attr,
> - const char *buf, size_t count)
> -{
> - struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> - int nr = sensor_attr->index;
> - unsigned long val;
> - int err;
> - u16 reg;
> -
> - err = kstrtoul(buf, 10, &val);
> - if (err < 0)
> - return err;
> -
> - if (val > 1)
> - return -EINVAL;
> -
> - /* On NCT67766F, DC mode is only supported for pwm1 */
> - if (sio_data->kind == nct6776 && nr && val != 1)
> - return -EINVAL;
> -
> - mutex_lock(&data->update_lock);
> - reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]);
> - data->pwm_mode[nr] = val;
> - reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]);
> - if (!val)
> - reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr];
> - w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg);
> - mutex_unlock(&data->update_lock);
> - return count;
> -}
> -
> -static ssize_t
> -store_pwm(struct device *dev, struct device_attribute *attr,
> - const char *buf, size_t count)
> -{
> - struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - unsigned long val;
> - int err;
> -
> - err = kstrtoul(buf, 10, &val);
> - if (err < 0)
> - return err;
> -
> - val = clamp_val(val, 0, 255);
> -
> - mutex_lock(&data->update_lock);
> - data->pwm[nr] = val;
> - w83627ehf_write_value(data, data->REG_PWM[nr], val);
> - mutex_unlock(&data->update_lock);
> - return count;
> -}
> -
> -static ssize_t
> -store_pwm_enable(struct device *dev, struct device_attribute *attr,
> - const char *buf, size_t count)
> -{
> - struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> - struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> - int nr = sensor_attr->index;
> - unsigned long val;
> - int err;
> - u16 reg;
> -
> - err = kstrtoul(buf, 10, &val);
> - if (err < 0)
> - return err;
> -
> - if (!val || (val > 4 && val != data->pwm_enable_orig[nr]))
> - return -EINVAL;
> - /* SmartFan III mode is not supported on NCT6776F */
> - if (sio_data->kind == nct6776 && val == 4)
> - return -EINVAL;
> -
> - mutex_lock(&data->update_lock);
> - data->pwm_enable[nr] = val;
> - if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
> - reg = w83627ehf_read_value(data,
> - NCT6775_REG_FAN_MODE[nr]);
> - reg &= 0x0f;
> - reg |= (val - 1) << 4;
> - w83627ehf_write_value(data,
> - NCT6775_REG_FAN_MODE[nr], reg);
> - } else {
> - reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]);
> - reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]);
> - reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr];
> - w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg);
> - }
> - mutex_unlock(&data->update_lock);
> - return count;
> }
>
> -
> #define show_tol_temp(reg) \
> static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
> char *buf) \
> @@ -1527,7 +1058,7 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t count)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> + struct w83627ehf_sio_data *sio_data = data->sio_data;
> struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> int nr = sensor_attr->index;
> u16 reg;
> @@ -1562,35 +1093,6 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
> return count;
> }
>
> -static struct sensor_device_attribute sda_pwm[] = {
> - SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
> - SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
> - SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
> - SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3),
> -};
> -
> -static struct sensor_device_attribute sda_pwm_mode[] = {
> - SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
> - store_pwm_mode, 0),
> - SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
> - store_pwm_mode, 1),
> - SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
> - store_pwm_mode, 2),
> - SENSOR_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
> - store_pwm_mode, 3),
> -};
> -
> -static struct sensor_device_attribute sda_pwm_enable[] = {
> - SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
> - store_pwm_enable, 0),
> - SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
> - store_pwm_enable, 1),
> - SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
> - store_pwm_enable, 2),
> - SENSOR_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
> - store_pwm_enable, 3),
> -};
> -
> static struct sensor_device_attribute sda_target_temp[] = {
> SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp,
> store_target_temp, 0),
> @@ -1687,15 +1189,6 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
>
> fan_time_functions(fan_stop_time, FAN_STOP_TIME)
>
> -static ssize_t name_show(struct device *dev, struct device_attribute *attr,
> - char *buf)
> -{
> - struct w83627ehf_data *data = dev_get_drvdata(dev);
> -
> - return sprintf(buf, "%s\n", data->name);
> -}
> -static DEVICE_ATTR_RO(name);
> -
> static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
> SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
> store_fan_stop_time, 3),
> @@ -1718,21 +1211,18 @@ static struct sensor_device_attribute sda_sf3_arrays_fan3[] = {
> store_fan_stop_output, 2),
> };
>
> -static struct sensor_device_attribute sda_sf3_arrays[] = {
> - SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
> - store_fan_stop_time, 0),
> - SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
> - store_fan_stop_time, 1),
> - SENSOR_ATTR(pwm1_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
> - store_fan_start_output, 0),
> - SENSOR_ATTR(pwm2_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
> - store_fan_start_output, 1),
> - SENSOR_ATTR(pwm1_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
> - store_fan_stop_output, 0),
> - SENSOR_ATTR(pwm2_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
> - store_fan_stop_output, 1),
> -};
> -
> +static SENSOR_DEVICE_ATTR(pwm1_stop_time, 0644, show_fan_stop_time,
> + store_fan_stop_time, 0);
> +static SENSOR_DEVICE_ATTR(pwm2_stop_time, 0644, show_fan_stop_time,
> + store_fan_stop_time, 1);
> +static SENSOR_DEVICE_ATTR(pwm1_start_output, 0644, show_fan_start_output,
> + store_fan_start_output, 0);
> +static SENSOR_DEVICE_ATTR(pwm2_start_output, 0644, show_fan_start_output,
> + store_fan_start_output, 1);
> +static SENSOR_DEVICE_ATTR(pwm1_stop_output, 0644, show_fan_stop_output,
> + store_fan_stop_output, 0);
> +static SENSOR_DEVICE_ATTR(pwm2_stop_output, 0644, show_fan_stop_output,
> + store_fan_stop_output, 1);
>
> /*
> * pwm1 and pwm3 don't support max and step settings on all chips.
> @@ -1796,83 +1286,38 @@ clear_caseopen(struct device *dev, struct device_attribute *attr,
> return count;
> }
>
> -static struct sensor_device_attribute_2 sda_caseopen[] = {
> - SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_caseopen,
> - clear_caseopen, 0x80, 0x10),
> - SENSOR_ATTR_2(intrusion1_alarm, S_IWUSR | S_IRUGO, show_caseopen,
> - clear_caseopen, 0x40, 0x40),
> +static SENSOR_DEVICE_ATTR_2(intrusion0_alarm, 0644, show_caseopen,
> + clear_caseopen, 0x80, 0x10);
> +static SENSOR_DEVICE_ATTR_2(intrusion1_alarm, 0644, show_caseopen,
> + clear_caseopen, 0x40, 0x40);
> +
> +#define NUMBER_OF_STATIC_SENSOR_ATTRS (7)
> +#define NUMBER_OF_SENSOR_ATTRS ( \
> + NUMBER_OF_STATIC_SENSOR_ATTRS + \
> + ARRAY_SIZE(sda_sf3_max_step_arrays) + \
> + ARRAY_SIZE(sda_sf3_arrays_fan3) + \
> + ARRAY_SIZE(sda_sf3_arrays_fan4) + \
> + ARRAY_SIZE(sda_target_temp) + \
> + ARRAY_SIZE(sda_tolerance) + \
> + 1)
> +
> +static struct attribute *sensor_attrs[NUMBER_OF_SENSOR_ATTRS] = {
> + &sensor_dev_attr_pwm1_stop_time.dev_attr.attr, //0
> + &sensor_dev_attr_pwm2_stop_time.dev_attr.attr, //1
> + &sensor_dev_attr_pwm1_start_output.dev_attr.attr, //2
> + &sensor_dev_attr_pwm2_start_output.dev_attr.attr, //3
> + &sensor_dev_attr_pwm1_stop_output.dev_attr.attr, //4
> + &sensor_dev_attr_pwm2_stop_output.dev_attr.attr, //5
> + &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, //6

Surprise to me, c99 comments are now permitted. Interesting.
Nevertheless, I prefer a single comment style per file, so please use
/* standard */ comments throughout.

> + NULL /* all other entries are dynamically set, depending on the chip */
> };
>
> +ATTRIBUTE_GROUPS(sensor);
> +
> /*
> * Driver and device management
> */
>
> -static void w83627ehf_device_remove_files(struct device *dev)
> -{
> - /*
> - * some entries in the following arrays may not have been used in
> - * device_create_file(), but device_remove_file() will ignore them
> - */
> - int i;
> - struct w83627ehf_data *data = dev_get_drvdata(dev);
> -
> - for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
> - device_remove_file(dev, &sda_sf3_arrays[i].dev_attr);
> - for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
> - struct sensor_device_attribute *attr =
> - &sda_sf3_max_step_arrays[i];
> - if (data->REG_FAN_STEP_OUTPUT &&
> - data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff)
> - device_remove_file(dev, &attr->dev_attr);
> - }
> - for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++)
> - device_remove_file(dev, &sda_sf3_arrays_fan3[i].dev_attr);
> - for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
> - device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
> - for (i = 0; i < data->in_num; i++) {
> - if ((i == 6) && data->in6_skip)
> - continue;
> - device_remove_file(dev, &sda_in_input[i].dev_attr);
> - device_remove_file(dev, &sda_in_alarm[i].dev_attr);
> - device_remove_file(dev, &sda_in_min[i].dev_attr);
> - device_remove_file(dev, &sda_in_max[i].dev_attr);
> - }
> - for (i = 0; i < 5; i++) {
> - device_remove_file(dev, &sda_fan_input[i].dev_attr);
> - device_remove_file(dev, &sda_fan_alarm[i].dev_attr);
> - device_remove_file(dev, &sda_fan_div[i].dev_attr);
> - device_remove_file(dev, &sda_fan_min[i].dev_attr);
> - }
> - for (i = 0; i < data->pwm_num; i++) {
> - device_remove_file(dev, &sda_pwm[i].dev_attr);
> - device_remove_file(dev, &sda_pwm_mode[i].dev_attr);
> - device_remove_file(dev, &sda_pwm_enable[i].dev_attr);
> - device_remove_file(dev, &sda_target_temp[i].dev_attr);
> - device_remove_file(dev, &sda_tolerance[i].dev_attr);
> - }
> - for (i = 0; i < NUM_REG_TEMP; i++) {
> - if (!(data->have_temp & (1 << i)))
> - continue;
> - device_remove_file(dev, &sda_temp_input[i].dev_attr);
> - device_remove_file(dev, &sda_temp_label[i].dev_attr);
> - if (i == 2 && data->temp3_val_only)
> - continue;
> - device_remove_file(dev, &sda_temp_max[i].dev_attr);
> - device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr);
> - if (i > 2)
> - continue;
> - device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
> - device_remove_file(dev, &sda_temp_type[i].dev_attr);
> - device_remove_file(dev, &sda_temp_offset[i].dev_attr);
> - }
> -
> - device_remove_file(dev, &sda_caseopen[0].dev_attr);
> - device_remove_file(dev, &sda_caseopen[1].dev_attr);
> -
> - device_remove_file(dev, &dev_attr_name);
> - device_remove_file(dev, &dev_attr_cpu0_vid);
> -}
> -
> /* Get the monitoring functions started */
> static inline void w83627ehf_init_device(struct w83627ehf_data *data,
> enum kinds kind)
> @@ -2046,15 +1491,577 @@ w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
> }
> }
>
> +static int w3627ehf_read_temp(struct device *dev, u32 attr, int channel,
> + long *val)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> +
> + switch (attr) {
> + case hwmon_temp_input:
> + *val = LM75_TEMP_FROM_REG(data->temp[channel]);
> + return 0;
> + case hwmon_temp_max:
> + *val = LM75_TEMP_FROM_REG(data->temp_max[channel]);
> + return 0;
> + case hwmon_temp_max_hyst:
> + *val = LM75_TEMP_FROM_REG(data->temp_max_hyst[channel]);
> + return 0;
> + case hwmon_temp_type:
> + *val = data->temp_type[channel];
> + return 0;
> + case hwmon_temp_offset:
> + *val = data->temp_offset[channel] * 1000;
> + return 0;
> + case hwmon_temp_alarm:
> + switch (channel) {
> + case 0:
> + channel = 4;
> + break;
> + case 1:
> + channel = 5;
> + break;
> + case 2:
> + channel = 13;
> + break;
> + default:
> + return -EINVAL;
> + }
> + *val = ((data->alarms >> channel) & 0x01);
> + return 0;
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static int w3627ehf_write_temp(struct device *dev, u32 attr, int channel,
> + long val)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> +
> + switch (attr) {
> + case hwmon_temp_offset:
> + val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
> + mutex_lock(&data->update_lock);
> + data->temp_offset[channel] = val;
> + w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[channel],
> + val);
> + mutex_unlock(&data->update_lock);
> + break;
> + case hwmon_temp_max:
> + mutex_lock(&data->update_lock);
> + data->temp_max[channel] = LM75_TEMP_TO_REG(val);
> + w83627ehf_write_temp(data, data->reg_temp_over[channel],
> + data->temp_max[channel]);
> + mutex_unlock(&data->update_lock);
> + break;
> + case hwmon_temp_max_hyst:
> + mutex_lock(&data->update_lock);
> + data->temp_max_hyst[channel] = LM75_TEMP_TO_REG(val);
> + w83627ehf_write_temp(data, data->reg_temp_hyst[channel],
> + data->temp_max_hyst[channel]);
> + mutex_unlock(&data->update_lock);
> + break;
> +
> + default:
> + return -EOPNOTSUPP;
> + }
> + return 0;
> +}
> +
> +static umode_t w3627ehf_temp_is_visible(const void *_data, u32 attr,
> + int channel)
> +{
> + const struct w83627ehf_data *data = _data;
> +
> + if (!(data->have_temp & (1 << channel)))
> + return 0;
> +
> + switch (attr) {
> + case hwmon_temp_label:
> + if (data->temp_label)
> + return 0444;
> + return 0;
> + case hwmon_temp_input:
> + return 0444;
> + case hwmon_temp_max:
> + if (channel == 2 && data->temp3_val_only)
> + return 0;
> + else if (data->reg_temp_over[channel])
> + return 0644;
> + else
> + return 0;
> + case hwmon_temp_max_hyst:
> + if (channel == 2 && data->temp3_val_only)
> + return 0;
> + else if (data->reg_temp_hyst[channel])
> + return 0644;
> + else
> + return 0;
> + case hwmon_temp_alarm:
> + case hwmon_temp_type:
> + return 0444;
> + case hwmon_temp_offset:
> + if (data->have_temp_offset & (1 << channel))
> + return 0644;
> + return 0;
> + }
> + return 0;
> +}
> +
> +static int w3627ehf_write_fan(struct device *dev, u32 attr, int channel,
> + long val)
> +{
> + switch (attr) {
> + case hwmon_fan_min:
> + store_fan_min(dev, channel, val);
> + break;
> + default:
> + return -EOPNOTSUPP;
> + }
> +
> + return 0;
> +}
> +
> +static int w3627ehf_read_fan(struct device *dev, u32 attr, int channel,
> + long *val)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> +
> + switch (attr) {
> + case hwmon_fan_alarm:
> + //the fan sensors have different offsets
> + switch (channel) {
> + case 0:
> + channel = 6;
> + break;
> + case 1:
> + channel = 7;
> + break;
> + case 2:
> + channel = 11;
> + break;
> + case 3:
> + channel = 10;
> + break;
> + case 4:
> + channel = 23;
> + break;
> + default:
> + return -EINVAL;
> + }
> + *val = ((data->alarms >> channel) & 0x01);
> + return 0;
> + case hwmon_fan_input:
> + *val = data->rpm[channel];
> + return 0;
> + case hwmon_fan_min:
> + *val = data->fan_from_reg_min(data->fan_min[channel],
> + data->fan_div[channel]);
> + return 0;
> + case hwmon_fan_div:
> + *val = div_from_reg(data->fan_div[channel]);
> + return 0;
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static umode_t w3627ehf_fan_is_visible(const void *_data, u32 attr, int channel)
> +{
> + const struct w83627ehf_data *data = _data;
> +
> + if (!(data->has_fan & (1 << channel)))
> + return 0;
> +
> + switch (attr) {
> + case hwmon_fan_alarm:
> + case hwmon_fan_input:
> + return 0444;
> + case hwmon_fan_div:
> + if (data->sio_data->kind != nct6776)
> + return 0444;
> + else
> + return 0;
> + case hwmon_fan_min:
> + return 0644;
> + }
> + return 0;
> +}
> +
> +static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
> + long val)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> + struct w83627ehf_sio_data *sio_data = data->sio_data;
> + u16 reg;
> +
> + switch (attr) {
> + case hwmon_pwm_input:
> + val = clamp_val(val, 0, 255);
> + mutex_lock(&data->update_lock);
> + data->pwm[channel] = val;
> + w83627ehf_write_value(data, data->REG_PWM[channel], val);
> + mutex_unlock(&data->update_lock);
> + return 0;
> + case hwmon_pwm_mode:
> + if (val > 1)
> + return -EINVAL;
> +
> + /* On NCT67766F, DC mode is only supported for pwm1 */
> + if (sio_data->kind == nct6776 && channel && val != 1)
> + return -EINVAL;
> +
> + mutex_lock(&data->update_lock);
> + reg = w83627ehf_read_value(data,
> + W83627EHF_REG_PWM_ENABLE[channel]);
> + data->pwm_mode[channel] = val;
> + reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[channel]);
> + if (!val)
> + reg |= 1 << W83627EHF_PWM_MODE_SHIFT[channel];
> + w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[channel],
> + reg);
> + mutex_unlock(&data->update_lock);
> + return 0;
> + case hwmon_pwm_enable:
> + if (!val || (val > 4 && val != data->pwm_enable_orig[channel]))
> + return -EINVAL;
> + /* SmartFan III mode is not supported on NCT6776F */
> + if (sio_data->kind == nct6776 && val == 4)
> + return -EINVAL;
> +
> + mutex_lock(&data->update_lock);
> + data->pwm_enable[channel] = val;
> + if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
> + reg = w83627ehf_read_value(data,
> + NCT6775_REG_FAN_MODE[channel]);
> + reg &= 0x0f;
> + reg |= (val - 1) << 4;
> + w83627ehf_write_value(data,
> + NCT6775_REG_FAN_MODE[channel],
> + reg);
> + } else {
> + reg = w83627ehf_read_value(data,
> + W83627EHF_REG_PWM_ENABLE[channel]);
> + reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[channel]);
> + reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel];
> + w83627ehf_write_value(data,
> + W83627EHF_REG_PWM_ENABLE[channel],
> + reg);
> + }
> + mutex_unlock(&data->update_lock);
> + return 0;
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static int w3627ehf_write_input(struct device *dev, u32 attr, int channel,
> + long val)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> +
> + switch (attr) {
> + case hwmon_in_min:
> + mutex_lock(&data->update_lock);
> + data->in_min[channel] = in_to_reg(val, channel, data->scale_in);
> + w83627ehf_write_value(data, W83627EHF_REG_IN_MIN(channel),
> + data->in_min[channel]);
> + mutex_unlock(&data->update_lock);
> + return 0;
> + case hwmon_in_max:
> + mutex_lock(&data->update_lock);
> + data->in_max[channel] = in_to_reg(val, channel, data->scale_in);
> + w83627ehf_write_value(data, W83627EHF_REG_IN_MAX(channel),
> + data->in_max[channel]);
> + mutex_unlock(&data->update_lock);
> + return 0;
> + }
> + return -EOPNOTSUPP;
> +}
> +
> +static int w3627ehf_read_pwm(struct device *dev, u32 attr, int channel,
> + long *val)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> +
> + switch (attr) {
> + case hwmon_pwm_input:
> + *val = data->pwm[channel];
> + return 0;
> + case hwmon_pwm_mode:
> + *val = data->pwm_mode[channel];
> + return 0;
> + case hwmon_pwm_enable:
> + *val = data->pwm_enable[channel];
> + return 0;
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static umode_t w3627ehf_pwm_is_visible(const void *_data, u32 attr, int channel)
> +{
> + const struct w83627ehf_data *data = _data;
> +
> + switch (attr) {
> + case hwmon_pwm_input:
> + case hwmon_pwm_mode:
> + case hwmon_pwm_enable:
> + if (data->has_fan & (1 << channel)) {
> + if (channel < data->pwm_num)
> + return 0644;
> + }
> + return 0;
> + }
> + return 0;
> +}
> +
> +static int w3627ehf_read_input(struct device *dev, u32 attr, int channel,
> + long *val)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> +
> + switch (attr) {
> + case hwmon_in_input:
> + *val = in_from_reg(data->in[channel], channel, data->scale_in);
> + return 0;
> + case hwmon_in_min:
> + *val = in_from_reg(data->in_min[channel], channel,
> + data->scale_in);
> + return 0;
> + case hwmon_in_max:
> + *val = in_from_reg(data->in_max[channel], channel,
> + data->scale_in);
> + return 0;
> + case hwmon_in_alarm:
> + switch (channel) {
> + case 0:
> + channel = 0;
> + break;
> + case 1:
> + channel = 1;
> + break;
> + case 2:
> + channel = 2;
> + break;
> + case 3:
> + channel = 3;
> + break;
> + case 4:
> + channel = 8;
> + break;
> + case 5:
> + channel = 21;
> + break;
> + case 6:
> + channel = 20;
> + break;
> + case 7:
> + channel = 16;
> + break;
> + case 8:
> + channel = 17;
> + break;
> + case 9:
> + channel = 19;
> + break;
> + default:
> + return -EINVAL;
> + }
> + *val = ((data->alarms >> channel) & 0x01);
> + return 0;
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static umode_t w3627ehf_input_is_visible(const void *_data, u32 attr,
> + int channel)
> +{
> + const struct w83627ehf_data *data = _data;
> +
> + //skip channel 6 if requested
> + if ((channel == 6) && data->in6_skip)
> + return 0;
> +
> + switch (attr) {
> + case hwmon_in_input:
> + case hwmon_in_alarm:
> + return 0444;
> + case hwmon_in_min:
> + case hwmon_in_max:
> + return 0644;
> + default:
> + return 0;
> + }
> +}
> +
> +static int w3627ehf_read_string(struct device *dev,
> + enum hwmon_sensor_types type, u32 attr,
> + int channel, char **buf)
> +{
> + struct w83627ehf_data *data = dev_get_drvdata(dev);
> +
> + w83627ehf_update_device(dev);
> + if (((type == hwmon_fan) && (attr == hwmon_fan_label)) ||
> + ((type == hwmon_temp) && (attr == hwmon_temp_label))) {

There are so many (()) here that it is difficult to figure out what is intended.
Please no unnecessary ones.

> + *buf = data->temp_label[data->temp_src[channel]];
> + return 0;
> + }
> + return -EOPNOTSUPP;
> +}
> +
> +static int w3627ehf_read(struct device *dev, enum hwmon_sensor_types type,
> + u32 attr, int channel, long *val)
> +{
> + w83627ehf_update_device(dev);
> + switch (type) {
> + case hwmon_fan:
> + return w3627ehf_read_fan(dev, attr, channel, val);
> + case hwmon_temp:
> + return w3627ehf_read_temp(dev, attr, channel, val);
> + case hwmon_in:
> + return w3627ehf_read_input(dev, attr, channel, val);
> + case hwmon_pwm:
> + return w3627ehf_read_pwm(dev, attr, channel, val);
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static int w3627ehf_write(struct device *dev, enum hwmon_sensor_types type,
> + u32 attr, int channel, long val)
> +{
> + switch (type) {
> + case hwmon_fan:
> + return w3627ehf_write_fan(dev, attr, channel, val);
> + case hwmon_in:
> + return w3627ehf_write_input(dev, attr, channel, val);
> + case hwmon_pwm:
> + return w3627ehf_write_pwm(dev, attr, channel, val);
> + case hwmon_temp:
> + return w3627ehf_write_temp(dev, attr, channel, val);
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> +static umode_t w3627ehf_is_visible(const void *data,
> + enum hwmon_sensor_types type, u32 attr,
> + int channel)
> +{
> + switch (type) {
> + case hwmon_fan:
> + return w3627ehf_fan_is_visible(data, attr, channel);
> + case hwmon_pwm:
> + return w3627ehf_pwm_is_visible(data, attr, channel);
> + case hwmon_in:
> + return w3627ehf_input_is_visible(data, attr, channel);
> + case hwmon_temp:
> + return w3627ehf_temp_is_visible(data, attr, channel);
> + default:
> + return 0;
> + }
> +}
> +
> +static const u32 w3627ehf_temp_config[] = {
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST |
> + HWMON_T_ALARM | HWMON_T_TYPE | HWMON_T_OFFSET,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST |
> + HWMON_T_ALARM | HWMON_T_TYPE | HWMON_T_OFFSET,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST |
> + HWMON_T_ALARM | HWMON_T_TYPE | HWMON_T_OFFSET,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
> + HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MAX | HWMON_T_MAX_HYST,
> + 0
> +};
> +
> +static const u32 w3627ehf_fan_config[] = {
> + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
> + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
> + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
> + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
> + HWMON_F_INPUT | HWMON_F_ALARM | HWMON_F_DIV | HWMON_F_MIN,
> + 0
> +};
> +
> +static const u32 w3627ehf_pwm_config[] = {
> + HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
> + HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
> + HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
> + HWMON_PWM_INPUT | HWMON_PWM_ENABLE | HWMON_PWM_MODE,
> + 0
> +};
> +
> +static const u32 w3627ehf_input_config[] = {
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM,
> + 0
> +};
> +
> +static const struct hwmon_channel_info w3627ehf_temp = {
> + .type = hwmon_temp,
> + .config = w3627ehf_temp_config,
> +};
> +
> +static const struct hwmon_channel_info w3627ehf_fan = {
> + .type = hwmon_fan,
> + .config = w3627ehf_fan_config,
> +};
> +
> +static const struct hwmon_channel_info w3627ehf_pwm = {
> + .type = hwmon_pwm,
> + .config = w3627ehf_pwm_config,
> +};
> +
> +static const struct hwmon_channel_info w3627ehf_input = {
> + .type = hwmon_in,
> + .config = w3627ehf_input_config,
> +};
> +
> +static const struct hwmon_ops w3627ehf_hwmon_ops = {
> + .is_visible = w3627ehf_is_visible,
> + .read = w3627ehf_read,
> + .read_string = w3627ehf_read_string,
> + .write = w3627ehf_write,
> +};
> +
> +static const struct hwmon_channel_info *w3627ehf_info[] = {
> + &w3627ehf_temp,
> + &w3627ehf_fan,
> + &w3627ehf_pwm,
> + &w3627ehf_input,
> + NULL
> +};
> +
> +static const struct hwmon_chip_info w83627ehf_chip_info = {
> + .ops = &w3627ehf_hwmon_ops,
> + .info = w3627ehf_info,
> +};
> +
> static int w83627ehf_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> + struct w83627ehf_sio_data *sio_data;

I don't think this needs to change....

> struct w83627ehf_data *data;
> struct resource *res;
> u8 en_vrm10;
> + struct attribute **dynamic_attrs;
> int i, err = 0;
>
> + dynamic_attrs = &sensor_attrs[NUMBER_OF_STATIC_SENSOR_ATTRS];
> +
> res = platform_get_resource(pdev, IORESOURCE_IO, 0);
> if (!request_region(res->start, IOREGION_LENGTH, DRVNAME)) {
> err = -EBUSY;
> @@ -2071,6 +2078,8 @@ static int w83627ehf_probe(struct platform_device *pdev)
> goto exit_release;
> }
>
> + data->sio_data = dev_get_platdata(dev);
> + sio_data = data->sio_data;

... you can use
data->sio_data = sio_data;
here

> data->addr = res->start;
> mutex_init(&data->lock);
> mutex_init(&data->update_lock);
> @@ -2363,9 +2372,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
> */
> superio_select(sio_data->sioreg, W83667HG_LD_VID);
> data->vid = superio_inb(sio_data->sioreg, 0xe3);
> - err = device_create_file(dev, &dev_attr_cpu0_vid);
> - if (err)
> - goto exit_release;
> + *dynamic_attrs++ = &dev_attr_cpu0_vid.attr;

Overwriting the static variable struct attribute *sensor_attrs[] is a no-go.
I would suggest to keep the array static, add all attributes to it, and use
is_visible to determine if attributes are visible or not.

> } else if (sio_data->kind != w83627uhg) {
> superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
> if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) {
> @@ -2400,9 +2407,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
> if (sio_data->kind == w83627ehf) /* 6 VID pins only */
> data->vid &= 0x3f;
>
> - err = device_create_file(dev, &dev_attr_cpu0_vid);
> - if (err)
> - goto exit_release;
> + *dynamic_attrs++ = &dev_attr_cpu0_vid.attr;
> } else {
> dev_info(dev,
> "VID pins in output mode, CPU VID not available\n");
> @@ -2437,150 +2442,55 @@ static int w83627ehf_probe(struct platform_device *pdev)
> data->pwm_enable_orig[i] = data->pwm_enable[i];
>
> /* Register sysfs hooks */
> - for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) {
> - err = device_create_file(dev, &sda_sf3_arrays[i].dev_attr);
> - if (err)
> - goto exit_remove;
> - }
> -
> for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
> struct sensor_device_attribute *attr =
> - &sda_sf3_max_step_arrays[i];
> + &sda_sf3_max_step_arrays[i];
> +
> if (data->REG_FAN_STEP_OUTPUT &&
> data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) {
> - err = device_create_file(dev, &attr->dev_attr);
> - if (err)
> - goto exit_remove;
> + *dynamic_attrs++ = &attr->dev_attr.attr;
> }
> }
> /* if fan3 and fan4 are enabled create the sf3 files for them */
> if ((data->has_fan & (1 << 2)) && data->pwm_num >= 3)
> for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++) {
> - err = device_create_file(dev,
> - &sda_sf3_arrays_fan3[i].dev_attr);
> - if (err)
> - goto exit_remove;
> + *dynamic_attrs++ =
> + &sda_sf3_arrays_fan3[i].dev_attr.attr;
> }
> if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4)
> for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) {
> - err = device_create_file(dev,
> - &sda_sf3_arrays_fan4[i].dev_attr);
> - if (err)
> - goto exit_remove;
> + *dynamic_attrs++ =
> + &sda_sf3_arrays_fan4[i].dev_attr.attr;
> }
>
> - for (i = 0; i < data->in_num; i++) {
> - if ((i == 6) && data->in6_skip)
> - continue;
> - if ((err = device_create_file(dev, &sda_in_input[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_in_alarm[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_in_min[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_in_max[i].dev_attr)))
> - goto exit_remove;
> - }
>
> for (i = 0; i < 5; i++) {
> if (data->has_fan & (1 << i)) {
> - if ((err = device_create_file(dev,
> - &sda_fan_input[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_fan_alarm[i].dev_attr)))
> - goto exit_remove;
> - if (sio_data->kind != nct6776) {
> - err = device_create_file(dev,
> - &sda_fan_div[i].dev_attr);
> - if (err)
> - goto exit_remove;
> + if (i < data->pwm_num) {
> + *dynamic_attrs++ =
> + &sda_target_temp[i].dev_attr.attr;
> + *dynamic_attrs++ =
> + &sda_tolerance[i].dev_attr.attr;
> }
> - if (data->has_fan_min & (1 << i)) {
> - err = device_create_file(dev,
> - &sda_fan_min[i].dev_attr);
> - if (err)
> - goto exit_remove;
> - }
> - if (i < data->pwm_num &&
> - ((err = device_create_file(dev,
> - &sda_pwm[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_pwm_mode[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_pwm_enable[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_target_temp[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_tolerance[i].dev_attr))))
> - goto exit_remove;
> - }
> - }
> -
> - for (i = 0; i < NUM_REG_TEMP; i++) {
> - if (!(data->have_temp & (1 << i)))
> - continue;
> - err = device_create_file(dev, &sda_temp_input[i].dev_attr);
> - if (err)
> - goto exit_remove;
> - if (data->temp_label) {
> - err = device_create_file(dev,
> - &sda_temp_label[i].dev_attr);
> - if (err)
> - goto exit_remove;
> - }
> - if (i == 2 && data->temp3_val_only)
> - continue;
> - if (data->reg_temp_over[i]) {
> - err = device_create_file(dev,
> - &sda_temp_max[i].dev_attr);
> - if (err)
> - goto exit_remove;
> - }
> - if (data->reg_temp_hyst[i]) {
> - err = device_create_file(dev,
> - &sda_temp_max_hyst[i].dev_attr);
> - if (err)
> - goto exit_remove;
> - }
> - if (i > 2)
> - continue;
> - if ((err = device_create_file(dev,
> - &sda_temp_alarm[i].dev_attr))
> - || (err = device_create_file(dev,
> - &sda_temp_type[i].dev_attr)))
> - goto exit_remove;
> - if (data->have_temp_offset & (1 << i)) {
> - err = device_create_file(dev,
> - &sda_temp_offset[i].dev_attr);
> - if (err)
> - goto exit_remove;
> }
> }
>
> - err = device_create_file(dev, &sda_caseopen[0].dev_attr);
> - if (err)
> - goto exit_remove;
> -
> if (sio_data->kind == nct6776) {
> - err = device_create_file(dev, &sda_caseopen[1].dev_attr);
> - if (err)
> - goto exit_remove;
> + *dynamic_attrs++ =
> + &sensor_dev_attr_intrusion1_alarm.dev_attr.attr;
> }
>
> - err = device_create_file(dev, &dev_attr_name);
> - if (err)
> - goto exit_remove;
> -
> - data->hwmon_dev = hwmon_device_register(dev);
> + data->hwmon_dev = hwmon_device_register_with_info(dev, data->name,
> + data,
> + &w83627ehf_chip_info,
> + sensor_groups);
> if (IS_ERR(data->hwmon_dev)) {
> err = PTR_ERR(data->hwmon_dev);
> - goto exit_remove;
> + goto exit_release;
> }
>
> return 0;
>
> -exit_remove:
> - w83627ehf_device_remove_files(dev);
> exit_release:
> release_region(res->start, IOREGION_LENGTH);
> exit:
> @@ -2592,7 +2502,6 @@ static int w83627ehf_remove(struct platform_device *pdev)
> struct w83627ehf_data *data = platform_get_drvdata(pdev);
>
> hwmon_device_unregister(data->hwmon_dev);
> - w83627ehf_device_remove_files(&pdev->dev);
> release_region(data->addr, IOREGION_LENGTH);
>
> return 0;
> @@ -2602,7 +2511,7 @@ static int w83627ehf_remove(struct platform_device *pdev)
> static int w83627ehf_suspend(struct device *dev)
> {
> struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> + struct w83627ehf_sio_data *sio_data = data->sio_data;
>
> mutex_lock(&data->update_lock);
> data->vbat = w83627ehf_read_value(data, W83627EHF_REG_VBAT);
> @@ -2618,7 +2527,7 @@ static int w83627ehf_suspend(struct device *dev)
> static int w83627ehf_resume(struct device *dev)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = dev_get_platdata(dev);
> + struct w83627ehf_sio_data *sio_data = data->sio_data;
> int i;
>
> mutex_lock(&data->update_lock);
>

2017-03-23 04:54:26

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH] w83627ehf: Drop support for nct6775/nct6776

On 03/22/2017 07:54 PM, Peter Huewe wrote:
> Since there exists a dedicated driver for nct6775/nct6776 it makes sense
> to remove support for these chips from this driver, in order to have
> only one code base for these types of chips.
>
> This also improves maintainability and readability (and size) of this
> driver.
>
> Some not so-obvious changes are:
> - removal of fan_debounce module parameter (now unused)
> - removal of has_fan_div flag (nct6776 specific)
> - w83627ehf_update_fan_div_common -> w83627ehf_update_fan_div
> (no distinction needed anymore)
> - w83627ehf_update_pwm_common -> w83627ehf_update_pwm
> (no distinction needed anymore)
> - NUM_REG_TEMP changed to ARRAY_SIZE(W83627EHF_REG_TEMP)
> (different number of max temp sensors)
> - removal of intrusion1_alarm (nct6776 specific)
>
> Tested with NCT6776F that it does not get probed anymore.
>
> Signed-off-by: Peter Huewe <[email protected]>
> ---
> Please apply after my conversion patch series.
>
> drivers/hwmon/w83627ehf.c | 542 ++++------------------------------------------

Please also update drivers/hwmon/Kconfig and Documentation/hwmon/w83627ehf.

Thanks,
Guenter

> 1 file changed, 43 insertions(+), 499 deletions(-)
>
> diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
> index bba26623af36..8e7ad86422ed 100644
> --- a/drivers/hwmon/w83627ehf.c
> +++ b/drivers/hwmon/w83627ehf.c
> @@ -31,8 +31,6 @@
> * w83627uhg 8 2 2 3 0xa230 0xc1 0x5ca3
> * w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3
> * w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3
> - * nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3
> - * nct6776f 9 5 3 9 0xC330 0xc1 0x5ca3
> */
>
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> @@ -53,7 +51,7 @@
>
> enum kinds {
> w83627ehf, w83627dhg, w83627dhg_p, w83627uhg,
> - w83667hg, w83667hg_b, nct6775, nct6776,
> + w83667hg, w83667hg_b,
> };
>
> /* used to set data->name = w83627ehf_device_names[data->sio_kind] */
> @@ -64,18 +62,12 @@ static const char * const w83627ehf_device_names[] = {
> "w83627uhg",
> "w83667hg",
> "w83667hg",
> - "nct6775",
> - "nct6776",
> };
>
> static unsigned short force_id;
> module_param(force_id, ushort, 0);
> MODULE_PARM_DESC(force_id, "Override the detected device ID");
>
> -static unsigned short fan_debounce;
> -module_param(fan_debounce, ushort, 0);
> -MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
> -
> #define DRVNAME "w83627ehf"
>
> /*
> @@ -100,8 +92,6 @@ MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
> #define SIO_W83627UHG_ID 0xa230
> #define SIO_W83667HG_ID 0xa510
> #define SIO_W83667HG_B_ID 0xb350
> -#define SIO_NCT6775_ID 0xb470
> -#define SIO_NCT6776_ID 0xc330
> #define SIO_ID_MASK 0xFFF0
>
> static inline void
> @@ -184,11 +174,6 @@ static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0, 0x152, 0x252, 0 };
> #define W83627EHF_REG_DIODE 0x59
> #define W83627EHF_REG_SMI_OVT 0x4C
>
> -/* NCT6775F has its own fan divider registers */
> -#define NCT6775_REG_FANDIV1 0x506
> -#define NCT6775_REG_FANDIV2 0x507
> -#define NCT6775_REG_FAN_DEBOUNCE 0xf0
> -
> #define W83627EHF_REG_ALARM1 0x459
> #define W83627EHF_REG_ALARM2 0x45A
> #define W83627EHF_REG_ALARM3 0x45B
> @@ -232,28 +217,6 @@ static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[]
>
> static const u16 W83627EHF_REG_TEMP_OFFSET[] = { 0x454, 0x455, 0x456 };
>
> -static const u16 NCT6775_REG_TARGET[] = { 0x101, 0x201, 0x301 };
> -static const u16 NCT6775_REG_FAN_MODE[] = { 0x102, 0x202, 0x302 };
> -static const u16 NCT6775_REG_FAN_STOP_OUTPUT[] = { 0x105, 0x205, 0x305 };
> -static const u16 NCT6775_REG_FAN_START_OUTPUT[] = { 0x106, 0x206, 0x306 };
> -static const u16 NCT6775_REG_FAN_STOP_TIME[] = { 0x107, 0x207, 0x307 };
> -static const u16 NCT6775_REG_PWM[] = { 0x109, 0x209, 0x309 };
> -static const u16 NCT6775_REG_FAN_MAX_OUTPUT[] = { 0x10a, 0x20a, 0x30a };
> -static const u16 NCT6775_REG_FAN_STEP_OUTPUT[] = { 0x10b, 0x20b, 0x30b };
> -static const u16 NCT6775_REG_FAN[] = { 0x630, 0x632, 0x634, 0x636, 0x638 };
> -static const u16 NCT6776_REG_FAN_MIN[] = { 0x63a, 0x63c, 0x63e, 0x640, 0x642};
> -
> -static const u16 NCT6775_REG_TEMP[]
> - = { 0x27, 0x150, 0x250, 0x73, 0x75, 0x77, 0x62b, 0x62c, 0x62d };
> -static const u16 NCT6775_REG_TEMP_CONFIG[]
> - = { 0, 0x152, 0x252, 0, 0, 0, 0x628, 0x629, 0x62A };
> -static const u16 NCT6775_REG_TEMP_HYST[]
> - = { 0x3a, 0x153, 0x253, 0, 0, 0, 0x673, 0x678, 0x67D };
> -static const u16 NCT6775_REG_TEMP_OVER[]
> - = { 0x39, 0x155, 0x255, 0, 0, 0, 0x672, 0x677, 0x67C };
> -static const u16 NCT6775_REG_TEMP_SOURCE[]
> - = { 0x621, 0x622, 0x623, 0x100, 0x200, 0x300, 0x624, 0x625, 0x626 };
> -
> static const char *const w83667hg_b_temp_label[] = {
> "SYSTIN",
> "CPUTIN",
> @@ -265,57 +228,7 @@ static const char *const w83667hg_b_temp_label[] = {
> "PECI Agent 4"
> };
>
> -static const char *const nct6775_temp_label[] = {
> - "",
> - "SYSTIN",
> - "CPUTIN",
> - "AUXTIN",
> - "AMD SB-TSI",
> - "PECI Agent 0",
> - "PECI Agent 1",
> - "PECI Agent 2",
> - "PECI Agent 3",
> - "PECI Agent 4",
> - "PECI Agent 5",
> - "PECI Agent 6",
> - "PECI Agent 7",
> - "PCH_CHIP_CPU_MAX_TEMP",
> - "PCH_CHIP_TEMP",
> - "PCH_CPU_TEMP",
> - "PCH_MCH_TEMP",
> - "PCH_DIM0_TEMP",
> - "PCH_DIM1_TEMP",
> - "PCH_DIM2_TEMP",
> - "PCH_DIM3_TEMP"
> -};
> -
> -static const char *const nct6776_temp_label[] = {
> - "",
> - "SYSTIN",
> - "CPUTIN",
> - "AUXTIN",
> - "SMBUSMASTER 0",
> - "SMBUSMASTER 1",
> - "SMBUSMASTER 2",
> - "SMBUSMASTER 3",
> - "SMBUSMASTER 4",
> - "SMBUSMASTER 5",
> - "SMBUSMASTER 6",
> - "SMBUSMASTER 7",
> - "PECI Agent 0",
> - "PECI Agent 1",
> - "PCH_CHIP_CPU_MAX_TEMP",
> - "PCH_CHIP_TEMP",
> - "PCH_CPU_TEMP",
> - "PCH_MCH_TEMP",
> - "PCH_DIM0_TEMP",
> - "PCH_DIM1_TEMP",
> - "PCH_DIM2_TEMP",
> - "PCH_DIM3_TEMP",
> - "BYTE_TEMP"
> -};
> -
> -#define NUM_REG_TEMP ARRAY_SIZE(NCT6775_REG_TEMP)
> +#define NUM_REG_TEMP ARRAY_SIZE(W83627EHF_REG_TEMP)
>
> static int is_word_sized(u16 reg)
> {
> @@ -355,31 +268,6 @@ static unsigned int fan_from_reg8(u16 reg, unsigned int divreg)
> return 1350000U / (reg << divreg);
> }
>
> -static unsigned int fan_from_reg13(u16 reg, unsigned int divreg)
> -{
> - if ((reg & 0xff1f) == 0xff1f)
> - return 0;
> -
> - reg = (reg & 0x1f) | ((reg & 0xff00) >> 3);
> -
> - if (reg == 0)
> - return 0;
> -
> - return 1350000U / reg;
> -}
> -
> -static unsigned int fan_from_reg16(u16 reg, unsigned int divreg)
> -{
> - if (reg == 0 || reg == 0xffff)
> - return 0;
> -
> - /*
> - * Even though the registers are 16 bit wide, the fan divisor
> - * still applies.
> - */
> - return 1350000U / (reg << divreg);
> -}
> -
> static inline unsigned int
> div_from_reg(u8 reg)
> {
> @@ -459,7 +347,6 @@ struct w83627ehf_data {
> u8 fan_div[5];
> u8 has_fan; /* some fan inputs can be disabled */
> u8 has_fan_min; /* some fans don't have min register */
> - bool has_fan_div;
> u8 temp_type[3];
> s8 temp_offset[3];
> s16 temp[9];
> @@ -580,35 +467,6 @@ static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg, u16 value)
> }
>
> /* This function assumes that the caller holds data->update_lock */
> -static void nct6775_write_fan_div(struct w83627ehf_data *data, int nr)
> -{
> - u8 reg;
> -
> - switch (nr) {
> - case 0:
> - reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV1) & 0x70)
> - | (data->fan_div[0] & 0x7);
> - w83627ehf_write_value(data, NCT6775_REG_FANDIV1, reg);
> - break;
> - case 1:
> - reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV1) & 0x7)
> - | ((data->fan_div[1] << 4) & 0x70);
> - w83627ehf_write_value(data, NCT6775_REG_FANDIV1, reg);
> - break;
> - case 2:
> - reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV2) & 0x70)
> - | (data->fan_div[2] & 0x7);
> - w83627ehf_write_value(data, NCT6775_REG_FANDIV2, reg);
> - break;
> - case 3:
> - reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV2) & 0x7)
> - | ((data->fan_div[3] << 4) & 0x70);
> - w83627ehf_write_value(data, NCT6775_REG_FANDIV2, reg);
> - break;
> - }
> -}
> -
> -/* This function assumes that the caller holds data->update_lock */
> static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr)
> {
> u8 reg;
> @@ -659,32 +517,6 @@ static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr)
> }
> }
>
> -static void w83627ehf_write_fan_div_common(struct device *dev,
> - struct w83627ehf_data *data, int nr)
> -{
> - struct w83627ehf_sio_data *sio_data = data->sio_data;
> -
> - if (sio_data->kind == nct6776)
> - ; /* no dividers, do nothing */
> - else if (sio_data->kind == nct6775)
> - nct6775_write_fan_div(data, nr);
> - else
> - w83627ehf_write_fan_div(data, nr);
> -}
> -
> -static void nct6775_update_fan_div(struct w83627ehf_data *data)
> -{
> - u8 i;
> -
> - i = w83627ehf_read_value(data, NCT6775_REG_FANDIV1);
> - data->fan_div[0] = i & 0x7;
> - data->fan_div[1] = (i & 0x70) >> 4;
> - i = w83627ehf_read_value(data, NCT6775_REG_FANDIV2);
> - data->fan_div[2] = i & 0x7;
> - if (data->has_fan & (1 << 3))
> - data->fan_div[3] = (i & 0x70) >> 4;
> -}
> -
> static void w83627ehf_update_fan_div(struct w83627ehf_data *data)
> {
> int i;
> @@ -710,37 +542,6 @@ static void w83627ehf_update_fan_div(struct w83627ehf_data *data)
> }
> }
>
> -static void w83627ehf_update_fan_div_common(struct device *dev,
> - struct w83627ehf_data *data)
> -{
> - if (data->sio_data) {
> - if (data->sio_data->kind == nct6776)
> - ; /* no dividers, do nothing */
> - else if (data->sio_data->kind == nct6775)
> - nct6775_update_fan_div(data);
> - else
> - w83627ehf_update_fan_div(data);
> - }
> -}
> -
> -static void nct6775_update_pwm(struct w83627ehf_data *data)
> -{
> - int i;
> - int pwmcfg, fanmodecfg;
> -
> - for (i = 0; i < data->pwm_num; i++) {
> - pwmcfg = w83627ehf_read_value(data,
> - W83627EHF_REG_PWM_ENABLE[i]);
> - fanmodecfg = w83627ehf_read_value(data,
> - NCT6775_REG_FAN_MODE[i]);
> - data->pwm_mode[i] =
> - ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1) ? 0 : 1;
> - data->pwm_enable[i] = ((fanmodecfg >> 4) & 7) + 1;
> - data->tolerance[i] = fanmodecfg & 0x0f;
> - data->pwm[i] = w83627ehf_read_value(data, data->REG_PWM[i]);
> - }
> -}
> -
> static void w83627ehf_update_pwm(struct w83627ehf_data *data)
> {
> int i;
> @@ -767,21 +568,9 @@ static void w83627ehf_update_pwm(struct w83627ehf_data *data)
> }
> }
>
> -static void w83627ehf_update_pwm_common(struct device *dev,
> - struct w83627ehf_data *data)
> -{
> - struct w83627ehf_sio_data *sio_data = data->sio_data;
> -
> - if (sio_data->kind == nct6775 || sio_data->kind == nct6776)
> - nct6775_update_pwm(data);
> - else
> - w83627ehf_update_pwm(data);
> -}
> -
> static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = data->sio_data;
> int i;
>
> mutex_lock(&data->update_lock);
> @@ -789,7 +578,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
> if (time_after(jiffies, data->last_updated + HZ + HZ/2)
> || !data->valid) {
> /* Fan clock dividers */
> - w83627ehf_update_fan_div_common(dev, data);
> + w83627ehf_update_fan_div(data);
>
> /* Measured voltages and limits */
> for (i = 0; i < data->in_num; i++) {
> @@ -824,16 +613,13 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
> * divider can be increased, let's try that for next
> * time
> */
> - if (data->has_fan_div
> - && (reg >= 0xff || (sio_data->kind == nct6775
> - && reg == 0x00))
> - && data->fan_div[i] < 0x07) {
> + if (reg >= 0xff && data->fan_div[i] < 0x07) {
> dev_dbg(dev,
> "Increasing fan%d clock divider from %u to %u\n",
> i + 1, div_from_reg(data->fan_div[i]),
> div_from_reg(data->fan_div[i] + 1));
> data->fan_div[i]++;
> - w83627ehf_write_fan_div_common(dev, data, i);
> + w83627ehf_write_fan_div(data, i);
> /* Preserve min limit if possible */
> if ((data->has_fan_min & (1 << i))
> && data->fan_min[i] >= 2
> @@ -844,7 +630,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
> }
> }
>
> - w83627ehf_update_pwm_common(dev, data);
> + w83627ehf_update_pwm(data);
>
> for (i = 0; i < data->pwm_num; i++) {
> if (!(data->has_fan & (1 << i)))
> @@ -926,22 +712,6 @@ static void store_fan_min(struct device *dev, u32 channel, unsigned long val)
> u8 new_div;
>
> mutex_lock(&data->update_lock);
> - if (!data->has_fan_div) {
> - /*
> - * Only NCT6776F for now, so we know that this is a 13 bit
> - * register
> - */
> - if (!val) {
> - val = 0xff1f;
> - } else {
> - if (val > 1350000U)
> - val = 135000U;
> - val = 1350000U / val;
> - val = (val & 0x1f) | ((val << 3) & 0xff00);
> - }
> - data->fan_min[nr] = val;
> - goto done; /* Leave fan divider alone */
> - }
> if (!val) {
> /* No min limit, alarm disabled */
> data->fan_min[nr] = 255;
> @@ -990,11 +760,11 @@ static void store_fan_min(struct device *dev, u32 channel, unsigned long val)
> nr + 1, div_from_reg(data->fan_div[nr]),
> div_from_reg(new_div));
> data->fan_div[nr] = new_div;
> - w83627ehf_write_fan_div_common(dev, data, nr);
> + w83627ehf_write_fan_div(data, nr);
> /* Give the chip time to sample a new speed value */
> data->last_updated = jiffies;
> }
> -done:
> +
> w83627ehf_write_value(data, data->REG_FAN_MIN[nr], data->fan_min[nr]);
> mutex_unlock(&data->update_lock);
> }
> @@ -1041,7 +811,6 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t count)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = data->sio_data;
> struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
> int nr = sensor_attr->index;
> u16 reg;
> @@ -1056,21 +825,12 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
> val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 0, 15);
>
> mutex_lock(&data->update_lock);
> - if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
> - /* Limit tolerance further for NCT6776F */
> - if (sio_data->kind == nct6776 && val > 7)
> - val = 7;
> - reg = w83627ehf_read_value(data, NCT6775_REG_FAN_MODE[nr]);
> + reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);
> + if (nr == 1)
> + reg = (reg & 0x0f) | (val << 4);
> + else
> reg = (reg & 0xf0) | val;
> - w83627ehf_write_value(data, NCT6775_REG_FAN_MODE[nr], reg);
> - } else {
> - reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]);
> - if (nr == 1)
> - reg = (reg & 0x0f) | (val << 4);
> - else
> - reg = (reg & 0xf0) | val;
> - w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg);
> - }
> + w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg);
> data->tolerance[nr] = val;
> mutex_unlock(&data->update_lock);
> return count;
> @@ -1263,8 +1023,6 @@ clear_caseopen(struct device *dev, struct device_attribute *attr,
>
> static SENSOR_DEVICE_ATTR_2(intrusion0_alarm, 0644, show_caseopen,
> clear_caseopen, 0x80, 0x10);
> -static SENSOR_DEVICE_ATTR_2(intrusion1_alarm, 0644, show_caseopen,
> - clear_caseopen, 0x40, 0x40);
>
> #define NUMBER_OF_STATIC_SENSOR_ATTRS (7)
> #define NUMBER_OF_SENSOR_ATTRS ( \
> @@ -1352,15 +1110,6 @@ static inline void w83627ehf_init_device(struct w83627ehf_data *data,
> }
> }
>
> -static void w82627ehf_swap_tempreg(struct w83627ehf_data *data, int r1, int r2)
> -{
> - swap(data->temp_src[r1], data->temp_src[r2]);
> - swap(data->reg_temp[r1], data->reg_temp[r2]);
> - swap(data->reg_temp_over[r1], data->reg_temp_over[r2]);
> - swap(data->reg_temp_hyst[r1], data->reg_temp_hyst[r2]);
> - swap(data->reg_temp_config[r1], data->reg_temp_config[r2]);
> -}
> -
> static void w83627ehf_set_temp_reg_ehf(struct w83627ehf_data *data, int n_temp)
> {
> int i;
> @@ -1388,36 +1137,7 @@ w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
>
> superio_enter(sio_data->sioreg);
>
> - /* fan4 and fan5 share some pins with the GPIO and serial flash */
> - if (sio_data->kind == nct6775) {
> - /* On NCT6775, fan4 shares pins with the fdc interface */
> - fan3pin = 1;
> - fan4pin = !(superio_inb(sio_data->sioreg, 0x2A) & 0x80);
> - fan4min = 0;
> - fan5pin = 0;
> - } else if (sio_data->kind == nct6776) {
> - bool gpok = superio_inb(sio_data->sioreg, 0x27) & 0x80;
> -
> - superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
> - regval = superio_inb(sio_data->sioreg, SIO_REG_ENABLE);
> -
> - if (regval & 0x80)
> - fan3pin = gpok;
> - else
> - fan3pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x40);
> -
> - if (regval & 0x40)
> - fan4pin = gpok;
> - else
> - fan4pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x01);
> -
> - if (regval & 0x20)
> - fan5pin = gpok;
> - else
> - fan5pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x02);
> -
> - fan4min = fan4pin;
> - } else if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
> + if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
> fan3pin = 1;
> fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40;
> fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20;
> @@ -1435,30 +1155,21 @@ w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
> data->has_fan |= (fan3pin << 2);
> data->has_fan_min |= (fan3pin << 2);
>
> - if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
> - /*
> - * NCT6775F and NCT6776F don't have the W83627EHF_REG_FANDIV1
> - * register
> - */
> - data->has_fan |= (fan4pin << 3) | (fan5pin << 4);
> - data->has_fan_min |= (fan4min << 3) | (fan5pin << 4);
> - } else {
> - /*
> - * It looks like fan4 and fan5 pins can be alternatively used
> - * as fan on/off switches, but fan5 control is write only :/
> - * We assume that if the serial interface is disabled, designers
> - * connected fan5 as input unless they are emitting log 1, which
> - * is not the default.
> - */
> - regval = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1);
> - if ((regval & (1 << 2)) && fan4pin) {
> - data->has_fan |= (1 << 3);
> - data->has_fan_min |= (1 << 3);
> - }
> - if (!(regval & (1 << 1)) && fan5pin) {
> - data->has_fan |= (1 << 4);
> - data->has_fan_min |= (1 << 4);
> - }
> + /*
> + * It looks like fan4 and fan5 pins can be alternatively used
> + * as fan on/off switches, but fan5 control is write only :/
> + * We assume that if the serial interface is disabled, designers
> + * connected fan5 as input unless they are emitting log 1, which
> + * is not the default.
> + */
> + regval = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1);
> + if ((regval & (1 << 2)) && fan4pin) {
> + data->has_fan |= (1 << 3);
> + data->has_fan_min |= (1 << 3);
> + }
> + if (!(regval & (1 << 1)) && fan5pin) {
> + data->has_fan |= (1 << 4);
> + data->has_fan_min |= (1 << 4);
> }
> }
>
> @@ -1649,10 +1360,7 @@ static umode_t w3627ehf_fan_is_visible(const void *_data, u32 attr, int channel)
> case hwmon_fan_input:
> return 0444;
> case hwmon_fan_div:
> - if (data->sio_data->kind != nct6776)
> - return 0444;
> - else
> - return 0;
> + return 0444;
> case hwmon_fan_min:
> return 0644;
> }
> @@ -1663,7 +1371,6 @@ static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
> long val)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = data->sio_data;
> u16 reg;
>
> switch (attr) {
> @@ -1678,10 +1385,6 @@ static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
> if (val > 1)
> return -EINVAL;
>
> - /* On NCT67766F, DC mode is only supported for pwm1 */
> - if (sio_data->kind == nct6776 && channel && val != 1)
> - return -EINVAL;
> -
> mutex_lock(&data->update_lock);
> reg = w83627ehf_read_value(data,
> W83627EHF_REG_PWM_ENABLE[channel]);
> @@ -1696,29 +1399,15 @@ static int w3627ehf_write_pwm(struct device *dev, u32 attr, int channel,
> case hwmon_pwm_enable:
> if (!val || (val > 4 && val != data->pwm_enable_orig[channel]))
> return -EINVAL;
> - /* SmartFan III mode is not supported on NCT6776F */
> - if (sio_data->kind == nct6776 && val == 4)
> - return -EINVAL;
> -
> mutex_lock(&data->update_lock);
> data->pwm_enable[channel] = val;
> - if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
> - reg = w83627ehf_read_value(data,
> - NCT6775_REG_FAN_MODE[channel]);
> - reg &= 0x0f;
> - reg |= (val - 1) << 4;
> - w83627ehf_write_value(data,
> - NCT6775_REG_FAN_MODE[channel],
> - reg);
> - } else {
> - reg = w83627ehf_read_value(data,
> - W83627EHF_REG_PWM_ENABLE[channel]);
> - reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[channel]);
> - reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel];
> - w83627ehf_write_value(data,
> - W83627EHF_REG_PWM_ENABLE[channel],
> - reg);
> - }
> + reg = w83627ehf_read_value(data,
> + W83627EHF_REG_PWM_ENABLE[channel]);
> + reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[channel]);
> + reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[channel];
> + w83627ehf_write_value(data,
> + W83627EHF_REG_PWM_ENABLE[channel],
> + reg);
> mutex_unlock(&data->update_lock);
> return 0;
> default:
> @@ -2060,15 +1749,13 @@ static int w83627ehf_probe(struct platform_device *pdev)
>
> /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */
> data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9;
> - /* 667HG, NCT6775F, and NCT6776F have 3 pwms, and 627UHG has only 2 */
> + /* 667HG has 3 pwms, and 627UHG has only 2 */
> switch (sio_data->kind) {
> default:
> data->pwm_num = 4;
> break;
> case w83667hg:
> case w83667hg_b:
> - case nct6775:
> - case nct6776:
> data->pwm_num = 3;
> break;
> case w83627uhg:
> @@ -2080,83 +1767,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
> data->have_temp = 0x07;
>
> /* Deal with temperature register setup first. */
> - if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
> - int mask = 0;
> -
> - /*
> - * Display temperature sensor output only if it monitors
> - * a source other than one already reported. Always display
> - * first three temperature registers, though.
> - */
> - for (i = 0; i < NUM_REG_TEMP; i++) {
> - u8 src;
> -
> - data->reg_temp[i] = NCT6775_REG_TEMP[i];
> - data->reg_temp_over[i] = NCT6775_REG_TEMP_OVER[i];
> - data->reg_temp_hyst[i] = NCT6775_REG_TEMP_HYST[i];
> - data->reg_temp_config[i] = NCT6775_REG_TEMP_CONFIG[i];
> -
> - src = w83627ehf_read_value(data,
> - NCT6775_REG_TEMP_SOURCE[i]);
> - src &= 0x1f;
> - if (src && !(mask & (1 << src))) {
> - data->have_temp |= 1 << i;
> - mask |= 1 << src;
> - }
> -
> - data->temp_src[i] = src;
> -
> - /*
> - * Now do some register swapping if index 0..2 don't
> - * point to SYSTIN(1), CPUIN(2), and AUXIN(3).
> - * Idea is to have the first three attributes
> - * report SYSTIN, CPUIN, and AUXIN if possible
> - * without overriding the basic system configuration.
> - */
> - if (i > 0 && data->temp_src[0] != 1
> - && data->temp_src[i] == 1)
> - w82627ehf_swap_tempreg(data, 0, i);
> - if (i > 1 && data->temp_src[1] != 2
> - && data->temp_src[i] == 2)
> - w82627ehf_swap_tempreg(data, 1, i);
> - if (i > 2 && data->temp_src[2] != 3
> - && data->temp_src[i] == 3)
> - w82627ehf_swap_tempreg(data, 2, i);
> - }
> - if (sio_data->kind == nct6776) {
> - /*
> - * On NCT6776, AUXTIN and VIN3 pins are shared.
> - * Only way to detect it is to check if AUXTIN is used
> - * as a temperature source, and if that source is
> - * enabled.
> - *
> - * If that is the case, disable in6, which reports VIN3.
> - * Otherwise disable temp3.
> - */
> - if (data->temp_src[2] == 3) {
> - u8 reg;
> -
> - if (data->reg_temp_config[2])
> - reg = w83627ehf_read_value(data,
> - data->reg_temp_config[2]);
> - else
> - reg = 0; /* Assume AUXTIN is used */
> -
> - if (reg & 0x01)
> - data->have_temp &= ~(1 << 2);
> - else
> - data->in6_skip = 1;
> - }
> - data->temp_label = nct6776_temp_label;
> - } else {
> - data->temp_label = nct6775_temp_label;
> - }
> - data->have_temp_offset = data->have_temp & 0x07;
> - for (i = 0; i < 3; i++) {
> - if (data->temp_src[i] > 3)
> - data->have_temp_offset &= ~(1 << i);
> - }
> - } else if (sio_data->kind == w83667hg_b) {
> + if (sio_data->kind == w83667hg_b) {
> u8 reg;
>
> w83627ehf_set_temp_reg_ehf(data, 4);
> @@ -2266,32 +1877,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
> data->have_temp_offset = data->have_temp & 0x07;
> }
>
> - if (sio_data->kind == nct6775) {
> - data->has_fan_div = true;
> - data->fan_from_reg = fan_from_reg16;
> - data->fan_from_reg_min = fan_from_reg8;
> - data->REG_PWM = NCT6775_REG_PWM;
> - data->REG_TARGET = NCT6775_REG_TARGET;
> - data->REG_FAN = NCT6775_REG_FAN;
> - data->REG_FAN_MIN = W83627EHF_REG_FAN_MIN;
> - data->REG_FAN_START_OUTPUT = NCT6775_REG_FAN_START_OUTPUT;
> - data->REG_FAN_STOP_OUTPUT = NCT6775_REG_FAN_STOP_OUTPUT;
> - data->REG_FAN_STOP_TIME = NCT6775_REG_FAN_STOP_TIME;
> - data->REG_FAN_MAX_OUTPUT = NCT6775_REG_FAN_MAX_OUTPUT;
> - data->REG_FAN_STEP_OUTPUT = NCT6775_REG_FAN_STEP_OUTPUT;
> - } else if (sio_data->kind == nct6776) {
> - data->has_fan_div = false;
> - data->fan_from_reg = fan_from_reg13;
> - data->fan_from_reg_min = fan_from_reg13;
> - data->REG_PWM = NCT6775_REG_PWM;
> - data->REG_TARGET = NCT6775_REG_TARGET;
> - data->REG_FAN = NCT6775_REG_FAN;
> - data->REG_FAN_MIN = NCT6776_REG_FAN_MIN;
> - data->REG_FAN_START_OUTPUT = NCT6775_REG_FAN_START_OUTPUT;
> - data->REG_FAN_STOP_OUTPUT = NCT6775_REG_FAN_STOP_OUTPUT;
> - data->REG_FAN_STOP_TIME = NCT6775_REG_FAN_STOP_TIME;
> - } else if (sio_data->kind == w83667hg_b) {
> - data->has_fan_div = true;
> + if (sio_data->kind == w83667hg_b) {
> data->fan_from_reg = fan_from_reg8;
> data->fan_from_reg_min = fan_from_reg8;
> data->REG_PWM = W83627EHF_REG_PWM;
> @@ -2306,7 +1892,6 @@ static int w83627ehf_probe(struct platform_device *pdev)
> data->REG_FAN_STEP_OUTPUT =
> W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B;
> } else {
> - data->has_fan_div = true;
> data->fan_from_reg = fan_from_reg8;
> data->fan_from_reg_min = fan_from_reg8;
> data->REG_PWM = W83627EHF_REG_PWM;
> @@ -2334,8 +1919,7 @@ static int w83627ehf_probe(struct platform_device *pdev)
> data->vrm = vid_which_vrm();
> superio_enter(sio_data->sioreg);
> /* Read VID value */
> - if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b ||
> - sio_data->kind == nct6775 || sio_data->kind == nct6776) {
> + if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
> /*
> * W83667HG has different pins for VID input and output, so
> * we can get the VID input values directly at logical device D
> @@ -2385,30 +1969,15 @@ static int w83627ehf_probe(struct platform_device *pdev)
> }
> }
>
> - if (fan_debounce &&
> - (sio_data->kind == nct6775 || sio_data->kind == nct6776)) {
> - u8 tmp;
> -
> - superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
> - tmp = superio_inb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE);
> - if (sio_data->kind == nct6776)
> - superio_outb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE,
> - 0x3e | tmp);
> - else
> - superio_outb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE,
> - 0x1e | tmp);
> - pr_info("Enabled fan debounce for chip %s\n", data->name);
> - }
> -
> superio_exit(sio_data->sioreg);
>
> w83627ehf_check_fan_inputs(sio_data, data);
>
> /* Read fan clock dividers immediately */
> - w83627ehf_update_fan_div_common(dev, data);
> + w83627ehf_update_fan_div(data);
>
> /* Read pwm data to save original values */
> - w83627ehf_update_pwm_common(dev, data);
> + w83627ehf_update_pwm(data);
> for (i = 0; i < data->pwm_num; i++)
> data->pwm_enable_orig[i] = data->pwm_enable[i];
>
> @@ -2445,11 +2014,6 @@ static int w83627ehf_probe(struct platform_device *pdev)
> }
> }
>
> - if (sio_data->kind == nct6776) {
> - *dynamic_attrs++ =
> - &sensor_dev_attr_intrusion1_alarm.dev_attr.attr;
> - }
> -
> data->hwmon_dev = hwmon_device_register_with_info(dev, data->name,
> data,
> &w83627ehf_chip_info,
> @@ -2481,14 +2045,9 @@ static int w83627ehf_remove(struct platform_device *pdev)
> static int w83627ehf_suspend(struct device *dev)
> {
> struct w83627ehf_data *data = w83627ehf_update_device(dev);
> - struct w83627ehf_sio_data *sio_data = data->sio_data;
>
> mutex_lock(&data->update_lock);
> data->vbat = w83627ehf_read_value(data, W83627EHF_REG_VBAT);
> - if (sio_data->kind == nct6775) {
> - data->fandiv1 = w83627ehf_read_value(data, NCT6775_REG_FANDIV1);
> - data->fandiv2 = w83627ehf_read_value(data, NCT6775_REG_FANDIV2);
> - }
> mutex_unlock(&data->update_lock);
>
> return 0;
> @@ -2497,7 +2056,6 @@ static int w83627ehf_suspend(struct device *dev)
> static int w83627ehf_resume(struct device *dev)
> {
> struct w83627ehf_data *data = dev_get_drvdata(dev);
> - struct w83627ehf_sio_data *sio_data = data->sio_data;
> int i;
>
> mutex_lock(&data->update_lock);
> @@ -2542,10 +2100,6 @@ static int w83627ehf_resume(struct device *dev)
>
> /* Restore other settings */
> w83627ehf_write_value(data, W83627EHF_REG_VBAT, data->vbat);
> - if (sio_data->kind == nct6775) {
> - w83627ehf_write_value(data, NCT6775_REG_FANDIV1, data->fandiv1);
> - w83627ehf_write_value(data, NCT6775_REG_FANDIV2, data->fandiv2);
> - }
>
> /* Force re-reading all values */
> data->valid = 0;
> @@ -2586,8 +2140,6 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
> static const char sio_name_W83627UHG[] __initconst = "W83627UHG";
> static const char sio_name_W83667HG[] __initconst = "W83667HG";
> static const char sio_name_W83667HG_B[] __initconst = "W83667HG-B";
> - static const char sio_name_NCT6775[] __initconst = "NCT6775F";
> - static const char sio_name_NCT6776[] __initconst = "NCT6776F";
>
> u16 val;
> const char *sio_name;
> @@ -2628,14 +2180,6 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
> sio_data->kind = w83667hg_b;
> sio_name = sio_name_W83667HG_B;
> break;
> - case SIO_NCT6775_ID:
> - sio_data->kind = nct6775;
> - sio_name = sio_name_NCT6775;
> - break;
> - case SIO_NCT6776_ID:
> - sio_data->kind = nct6776;
> - sio_name = sio_name_NCT6776;
> - break;
> default:
> if (val != 0xffff)
> pr_debug("unsupported chip ID: 0x%04x\n", val);
>