hwmon: (it87) Generalise support for FAN_CTL ON/OFF
authorFrank Crawford <frank@crawford.emu.id.au>
Sat, 27 May 2023 09:47:56 +0000 (19:47 +1000)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 8 Jun 2023 13:44:14 +0000 (06:44 -0700)
Support for FAN_CTL ON/OFF is currently disabled only for IT8603E but
there are severl chips that don't support the configuration bits to turn
off fan control entirely.  Generalise this support for any chip.

Add feature flag FEAT_FANCTL_ONOFF for chips that support configuration
bits for management of fan control off and assign all chips that support
the configuration.

Signed-off-by: Frank Crawford <frank@crawford.emu.id.au>
Link: https://lore.kernel.org/r/20230527094756.3464256-1-frank@crawford.emu.id.au
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/it87.c

index 4c3641d..5deff5e 100644 (file)
@@ -320,31 +320,34 @@ struct it87_devices {
 #define FEAT_FOUR_FANS         BIT(20) /* Supports four fans */
 #define FEAT_FOUR_PWM          BIT(21) /* Supports four fan controls */
 #define FEAT_FOUR_TEMP         BIT(22)
+#define FEAT_FANCTL_ONOFF      BIT(23) /* chip has FAN_CTL ON/OFF */
 
 static const struct it87_devices it87_devices[] = {
        [it87] = {
                .name = "it87",
                .model = "IT87F",
-               .features = FEAT_OLD_AUTOPWM,   /* may need to overwrite */
+               .features = FEAT_OLD_AUTOPWM | FEAT_FANCTL_ONOFF,
+               /* may need to overwrite */
        },
        [it8712] = {
                .name = "it8712",
                .model = "IT8712F",
-               .features = FEAT_OLD_AUTOPWM | FEAT_VID,
-                                               /* may need to overwrite */
+               .features = FEAT_OLD_AUTOPWM | FEAT_VID | FEAT_FANCTL_ONOFF,
+               /* may need to overwrite */
        },
        [it8716] = {
                .name = "it8716",
                .model = "IT8716F",
                .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
-                 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2,
+                 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_PWM_FREQ2
+                 | FEAT_FANCTL_ONOFF,
        },
        [it8718] = {
                .name = "it8718",
                .model = "IT8718F",
                .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
                  | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
-                 | FEAT_PWM_FREQ2,
+                 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
                .old_peci_mask = 0x4,
        },
        [it8720] = {
@@ -352,7 +355,7 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT8720F",
                .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
                  | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS
-                 | FEAT_PWM_FREQ2,
+                 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
                .old_peci_mask = 0x4,
        },
        [it8721] = {
@@ -361,7 +364,7 @@ static const struct it87_devices it87_devices[] = {
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
                  | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL
-                 | FEAT_PWM_FREQ2,
+                 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
                .peci_mask = 0x05,
                .old_peci_mask = 0x02,  /* Actually reports PCH */
        },
@@ -370,7 +373,8 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT8728F",
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS
-                 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2,
+                 | FEAT_IN7_INTERNAL | FEAT_PWM_FREQ2
+                 | FEAT_FANCTL_ONOFF,
                .peci_mask = 0x07,
        },
        [it8732] = {
@@ -379,7 +383,7 @@ static const struct it87_devices it87_devices[] = {
                .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
                  | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_FOUR_FANS
-                 | FEAT_FOUR_PWM,
+                 | FEAT_FOUR_PWM | FEAT_FANCTL_ONOFF,
                .peci_mask = 0x07,
                .old_peci_mask = 0x02,  /* Actually reports PCH */
        },
@@ -388,7 +392,7 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT8771E",
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
-                 | FEAT_PWM_FREQ2,
+                 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
                                /* PECI: guesswork */
                                /* 12mV ADC (OHM) */
                                /* 16 bit fans (OHM) */
@@ -400,7 +404,7 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT8772E",
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
-                 | FEAT_PWM_FREQ2,
+                 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
                                /* PECI (coreboot) */
                                /* 12mV ADC (HWSensors4, OHM) */
                                /* 16 bit fans (HWSensors4, OHM) */
@@ -411,21 +415,24 @@ static const struct it87_devices it87_devices[] = {
                .name = "it8781",
                .model = "IT8781F",
                .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
-                 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2,
+                 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
+                 | FEAT_FANCTL_ONOFF,
                .old_peci_mask = 0x4,
        },
        [it8782] = {
                .name = "it8782",
                .model = "IT8782F",
                .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
-                 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2,
+                 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
+                 | FEAT_FANCTL_ONOFF,
                .old_peci_mask = 0x4,
        },
        [it8783] = {
                .name = "it8783",
                .model = "IT8783E/F",
                .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
-                 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2,
+                 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_PWM_FREQ2
+                 | FEAT_FANCTL_ONOFF,
                .old_peci_mask = 0x4,
        },
        [it8786] = {
@@ -433,7 +440,7 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT8786E",
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
-                 | FEAT_PWM_FREQ2,
+                 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF,
                .peci_mask = 0x07,
        },
        [it8790] = {
@@ -441,7 +448,7 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT8790E",
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL
-                 | FEAT_PWM_FREQ2 | FEAT_CONF_NOEXIT,
+                 | FEAT_PWM_FREQ2 | FEAT_FANCTL_ONOFF | FEAT_CONF_NOEXIT,
                .peci_mask = 0x07,
        },
        [it8792] = {
@@ -449,7 +456,8 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT8792E/IT8795E",
                .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
-                 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_CONF_NOEXIT,
+                 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_FANCTL_ONOFF
+                 | FEAT_CONF_NOEXIT,
                .peci_mask = 0x07,
                .old_peci_mask = 0x02,  /* Actually reports PCH */
        },
@@ -467,7 +475,7 @@ static const struct it87_devices it87_devices[] = {
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_SIX_FANS
                  | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
-                 | FEAT_SIX_TEMP | FEAT_VIN3_5V,
+                 | FEAT_SIX_TEMP | FEAT_VIN3_5V | FEAT_FANCTL_ONOFF,
                .peci_mask = 0x07,
        },
        [it8622] = {
@@ -486,7 +494,7 @@ static const struct it87_devices it87_devices[] = {
                .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_SIX_FANS
                  | FEAT_IN7_INTERNAL | FEAT_SIX_PWM | FEAT_PWM_FREQ2
-                 | FEAT_SIX_TEMP | FEAT_VIN3_5V,
+                 | FEAT_SIX_TEMP | FEAT_VIN3_5V | FEAT_FANCTL_ONOFF,
                .peci_mask = 0x07,
        },
        [it87952] = {
@@ -494,7 +502,8 @@ static const struct it87_devices it87_devices[] = {
                .model = "IT87952E",
                .features = FEAT_NEWER_AUTOPWM | FEAT_16BIT_FANS
                  | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
-                 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_CONF_NOEXIT,
+                 | FEAT_10_9MV_ADC | FEAT_IN7_INTERNAL | FEAT_FANCTL_ONOFF
+                 | FEAT_CONF_NOEXIT,
                .peci_mask = 0x07,
                .old_peci_mask = 0x02,  /* Actually reports PCH */
        },
@@ -534,6 +543,7 @@ static const struct it87_devices it87_devices[] = {
 #define has_conf_noexit(data)  ((data)->features & FEAT_CONF_NOEXIT)
 #define has_scaling(data)      ((data)->features & (FEAT_12MV_ADC | \
                                                     FEAT_10_9MV_ADC))
+#define has_fanctl_onoff(data) ((data)->features & FEAT_FANCTL_ONOFF)
 
 struct it87_sio_data {
        int sioaddr;
@@ -1240,11 +1250,12 @@ static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
 
 static int pwm_mode(const struct it87_data *data, int nr)
 {
-       if (data->type != it8603 && nr < 3 && !(data->fan_main_ctrl & BIT(nr)))
-               return 0;                               /* Full speed */
+       if (has_fanctl_onoff(data) && nr < 3 &&
+           !(data->fan_main_ctrl & BIT(nr)))
+               return 0;                       /* Full speed */
        if (data->pwm_ctrl[nr] & 0x80)
-               return 2;                               /* Automatic mode */
-       if ((data->type == it8603 || nr >= 3) &&
+               return 2;                       /* Automatic mode */
+       if ((!has_fanctl_onoff(data) || nr >= 3) &&
            data->pwm_duty[nr] == pwm_to_reg(data, 0xff))
                return 0;                       /* Full speed */
 
@@ -1481,7 +1492,7 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
                return err;
 
        if (val == 0) {
-               if (nr < 3 && data->type != it8603) {
+               if (nr < 3 && has_fanctl_onoff(data)) {
                        int tmp;
                        /* make sure the fan is on when in on/off mode */
                        tmp = it87_read_value(data, IT87_REG_FAN_CTL);
@@ -1521,7 +1532,7 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
                data->pwm_ctrl[nr] = ctrl;
                it87_write_value(data, IT87_REG_PWM[nr], ctrl);
 
-               if (data->type != it8603 && nr < 3) {
+               if (has_fanctl_onoff(data) && nr < 3) {
                        /* set SmartGuardian mode */
                        data->fan_main_ctrl |= BIT(nr);
                        it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,