]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: (mcp9982) Add external diode fault read
authorVictor Duicu <victor.duicu@microchip.com>
Thu, 23 Apr 2026 10:56:40 +0000 (13:56 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 9 Jun 2026 15:22:41 +0000 (08:22 -0700)
Add external diode fault read capability to the
MCP998X/33 and MCP998XD/33D driver.

Signed-off-by: Victor Duicu <victor.duicu@microchip.com>
Link: https://lore.kernel.org/r/20260423-add-external-diode-fault-read-v2-1-4004bb5f7d55@microchip.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/mcp9982.c

index 26c69e3388ab82d09bfdd70a64430d0852fe2b84..9e19e2697e25ff226a4ba911924133ceb2fd07f1 100644 (file)
@@ -92,19 +92,19 @@ static const struct hwmon_channel_info * const mcp9985_info[] = {
                           HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MIN |
                           HWMON_T_MIN_ALARM | HWMON_T_MAX | HWMON_T_MAX_ALARM |
                           HWMON_T_MAX_HYST | HWMON_T_CRIT | HWMON_T_CRIT_ALARM |
-                          HWMON_T_CRIT_HYST,
+                          HWMON_T_CRIT_HYST | HWMON_T_FAULT,
                           HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MIN |
                           HWMON_T_MIN_ALARM | HWMON_T_MAX | HWMON_T_MAX_ALARM |
                           HWMON_T_MAX_HYST | HWMON_T_CRIT | HWMON_T_CRIT_ALARM |
-                          HWMON_T_CRIT_HYST,
+                          HWMON_T_CRIT_HYST | HWMON_T_FAULT,
                           HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MIN |
                           HWMON_T_MIN_ALARM | HWMON_T_MAX | HWMON_T_MAX_ALARM |
                           HWMON_T_MAX_HYST | HWMON_T_CRIT | HWMON_T_CRIT_ALARM |
-                          HWMON_T_CRIT_HYST,
+                          HWMON_T_CRIT_HYST | HWMON_T_FAULT,
                           HWMON_T_INPUT | HWMON_T_LABEL | HWMON_T_MIN |
                           HWMON_T_MIN_ALARM | HWMON_T_MAX | HWMON_T_MAX_ALARM |
                           HWMON_T_MAX_HYST | HWMON_T_CRIT | HWMON_T_CRIT_ALARM |
-                          HWMON_T_CRIT_HYST),
+                          HWMON_T_CRIT_HYST | HWMON_T_FAULT),
        HWMON_CHANNEL_INFO(chip,
                           HWMON_C_UPDATE_INTERVAL),
        NULL
@@ -369,7 +369,8 @@ static int mcp9982_read(struct device *dev, enum hwmon_sensor_types type, u32 at
 
        /*
         * In Standby State the conversion cycle must be initated manually in
-        * order to read fresh temperature values and the status of the alarms.
+        * order to read fresh temperature values, the status of the alarms and
+        * fault information.
         */
        if (!priv->run_state) {
                switch (type) {
@@ -379,6 +380,7 @@ static int mcp9982_read(struct device *dev, enum hwmon_sensor_types type, u32 at
                        case hwmon_temp_max_alarm:
                        case hwmon_temp_min_alarm:
                        case hwmon_temp_crit_alarm:
+                       case hwmon_temp_fault:
                                ret = regmap_write(priv->regmap, MCP9982_ONE_SHOT_ADDR, 1);
                                if (ret)
                                        return ret;
@@ -402,6 +404,11 @@ static int mcp9982_read(struct device *dev, enum hwmon_sensor_types type, u32 at
        }
 
        switch (type) {
+       /*
+        * Because the ALERT/THERM pin is set in Therm(Comparator) mode,
+        * the external diode fault status, high limit status and low
+        * limit status registers do not clear the bits after reading.
+        */
        case hwmon_temp:
                switch (attr) {
                case hwmon_temp_input:
@@ -510,6 +517,13 @@ static int mcp9982_read(struct device *dev, enum hwmon_sensor_types type, u32 at
 
                        *val -= hyst * 1000;
 
+                       return 0;
+               case hwmon_temp_fault:
+                       *val = regmap_test_bits(priv->regmap, MCP9982_EXT_FAULT_STATUS_ADDR,
+                                               BIT(channel));
+                       if (*val < 0)
+                               return *val;
+
                        return 0;
                default:
                        return -EINVAL;
@@ -681,6 +695,7 @@ static umode_t mcp9982_is_visible(const void *_data, enum hwmon_sensor_types typ
                case hwmon_temp_max_alarm:
                case hwmon_temp_max_hyst:
                case hwmon_temp_crit_alarm:
+               case hwmon_temp_fault:
                        return 0444;
                case hwmon_temp_min:
                case hwmon_temp_max: