hwmon: (ftsteutates) Replace fanX_source with pwmX_auto_channels_temp
authorArmin Wolf <W_Armin@gmx.de>
Thu, 5 Jan 2023 22:51:06 +0000 (23:51 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Fri, 3 Feb 2023 15:30:10 +0000 (07:30 -0800)
Replace the nonstandard fanX_source attributes with the standardized
pwmX_auto_channels_temp attributes and document the special behaviour
associated with those attributes.

Tested on a Fujitsu DS3401-B1.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20230105225107.58308-3-W_Armin@gmx.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Documentation/hwmon/ftsteutates.rst
drivers/hwmon/ftsteutates.c

index 198fa8e2819dad91bb05aae94d761a286fd0b032..b3bfec36661dc4eb96085859058cf2fc663b2076 100644 (file)
@@ -22,6 +22,11 @@ enhancements. It can monitor up to 4 voltages, 16 temperatures and
 8 fans. It also contains an integrated watchdog which is currently
 implemented in this driver.
 
+The ``pwmX_auto_channels_temp`` attributes show which temperature sensor
+is currently driving which fan channel. This value might dynamically change
+during runtime depending on the temperature sensor selected by
+the fan control circuit.
+
 The 4 voltages require a board-specific multiplier, since the BMC can
 only measure voltages up to 3.3V and thus relies on voltage dividers.
 Consult your motherboard manual for details.
index 23dc3a74f84b1317254989bf72f3a41370537bad..0d8ab94250a9febbdbe383c59574e1e8815b515b 100644 (file)
@@ -6,9 +6,7 @@
  *               Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com>
  */
 #include <linux/err.h>
-#include <linux/fs.h>
 #include <linux/hwmon.h>
-#include <linux/hwmon-sysfs.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/jiffies.h>
@@ -16,7 +14,6 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
-#include <linux/sysfs.h>
 #include <linux/watchdog.h>
 
 #define FTS_DEVICE_ID_REG              0x0000
@@ -48,6 +45,8 @@
 #define FTS_NO_TEMP_SENSORS            0x10
 #define FTS_NO_VOLT_SENSORS            0x04
 
+#define FTS_FAN_SOURCE_INVALID         0xff
+
 static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
 
 static const struct i2c_device_id fts_id[] = {
@@ -187,7 +186,7 @@ static int fts_update_device(struct fts_data *data)
                        data->fan_source[i] = err;
                } else {
                        data->fan_input[i] = 0;
-                       data->fan_source[i] = 0;
+                       data->fan_source[i] = FTS_FAN_SOURCE_INVALID;
                }
        }
 
@@ -339,50 +338,6 @@ static int fts_watchdog_init(struct fts_data *data)
        return devm_watchdog_register_device(&data->client->dev, &data->wdd);
 }
 
-static ssize_t fan_source_show(struct device *dev,
-                              struct device_attribute *devattr, char *buf)
-{
-       struct fts_data *data = dev_get_drvdata(dev);
-       int index = to_sensor_dev_attr(devattr)->index;
-       int err;
-
-       err = fts_update_device(data);
-       if (err < 0)
-               return err;
-
-       return sprintf(buf, "%u\n", data->fan_source[index]);
-}
-
-static SENSOR_DEVICE_ATTR_RO(fan1_source, fan_source, 0);
-static SENSOR_DEVICE_ATTR_RO(fan2_source, fan_source, 1);
-static SENSOR_DEVICE_ATTR_RO(fan3_source, fan_source, 2);
-static SENSOR_DEVICE_ATTR_RO(fan4_source, fan_source, 3);
-static SENSOR_DEVICE_ATTR_RO(fan5_source, fan_source, 4);
-static SENSOR_DEVICE_ATTR_RO(fan6_source, fan_source, 5);
-static SENSOR_DEVICE_ATTR_RO(fan7_source, fan_source, 6);
-static SENSOR_DEVICE_ATTR_RO(fan8_source, fan_source, 7);
-
-static struct attribute *fts_fan_attrs[] = {
-       &sensor_dev_attr_fan1_source.dev_attr.attr,
-       &sensor_dev_attr_fan2_source.dev_attr.attr,
-       &sensor_dev_attr_fan3_source.dev_attr.attr,
-       &sensor_dev_attr_fan4_source.dev_attr.attr,
-       &sensor_dev_attr_fan5_source.dev_attr.attr,
-       &sensor_dev_attr_fan6_source.dev_attr.attr,
-       &sensor_dev_attr_fan7_source.dev_attr.attr,
-       &sensor_dev_attr_fan8_source.dev_attr.attr,
-       NULL
-};
-
-static const struct attribute_group fts_attr_group = {
-       .attrs = fts_fan_attrs
-};
-
-static const struct attribute_group *fts_attr_groups[] = {
-       &fts_attr_group,
-       NULL
-};
-
 static umode_t fts_is_visible(const void *devdata, enum hwmon_sensor_types type, u32 attr,
                              int channel)
 {
@@ -408,6 +363,7 @@ static umode_t fts_is_visible(const void *devdata, enum hwmon_sensor_types type,
                        break;
                }
                break;
+       case hwmon_pwm:
        case hwmon_in:
                return 0444;
        default:
@@ -460,6 +416,19 @@ static int fts_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
                        break;
                }
                break;
+       case hwmon_pwm:
+               switch (attr) {
+               case hwmon_pwm_auto_channels_temp:
+                       if (data->fan_source[channel] == FTS_FAN_SOURCE_INVALID)
+                               *val = 0;
+                       else
+                               *val = BIT(data->fan_source[channel]);
+
+                       return 0;
+               default:
+                       break;
+               }
+               break;
        case hwmon_in:
                switch (attr) {
                case hwmon_in_input:
@@ -576,6 +545,16 @@ static const struct hwmon_channel_info *fts_info[] = {
                           HWMON_F_INPUT | HWMON_F_ALARM,
                           HWMON_F_INPUT | HWMON_F_ALARM
                           ),
+       HWMON_CHANNEL_INFO(pwm,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP,
+                          HWMON_PWM_AUTO_CHANNELS_TEMP
+                          ),
        HWMON_CHANNEL_INFO(in,
                           HWMON_I_INPUT,
                           HWMON_I_INPUT,
@@ -672,7 +651,7 @@ static int fts_probe(struct i2c_client *client)
        revision = err;
 
        hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, "ftsteutates", data,
-                                                        &fts_chip_info, fts_attr_groups);
+                                                        &fts_chip_info, NULL);
        if (IS_ERR(hwmon_dev))
                return PTR_ERR(hwmon_dev);