]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ASoC: tas2770: Deal with bogus initial temperature value
authorJames Calligeros <jcalligeros99@gmail.com>
Sun, 3 May 2026 12:23:24 +0000 (22:23 +1000)
committerMark Brown <broonie@kernel.org>
Tue, 5 May 2026 01:49:21 +0000 (10:49 +0900)
TAS2770 initialises the temperature readout registers to 0.
This value persists until the chip is fully powered up and
the ADC starts sampling. The ADC then persists the last sampled
temperature during software shutdown.

The ADC should therefore never return 0 in normal operating
conditions, so return -ENODATA and mark it as a fault condition
using HWMON_T_FAULT.

Fixes: ff73e2780169 ("ASoC: tas2770: expose die temp to hwmon")
Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/tas2770.c

index 50501bcbe916780bea25acf12763c35facd78a3a..dbda9f3275351a15d756c171b9c46e28f3107699 100644 (file)
@@ -633,10 +633,27 @@ static int tas2770_read_die_temp(struct tas2770_priv *tas2770, long *result)
         * value read back from its registers will be the last value sampled
         * before entering software shutdown.
         */
+       if (reading == 0)
+               return -ENODATA;
+
        *result = (reading - (93 * 16)) * 1000 / 16;
        return 0;
 }
 
+static int tas2770_hwmon_is_fault(struct tas2770_priv *tas2770, long *result)
+{
+       int ret;
+       long temp;
+
+       ret = tas2770_read_die_temp(tas2770, &temp);
+       if (ret == -ENODATA) {
+               *result = true;
+               return 0;
+       }
+
+       return ret;
+}
+
 static umode_t tas2770_hwmon_is_visible(const void *data,
                                        enum hwmon_sensor_types type, u32 attr,
                                        int channel)
@@ -646,6 +663,7 @@ static umode_t tas2770_hwmon_is_visible(const void *data,
 
        switch (attr) {
        case hwmon_temp_input:
+       case hwmon_temp_fault:
                return 0444;
        default:
                break;
@@ -665,6 +683,9 @@ static int tas2770_hwmon_read(struct device *dev,
        case hwmon_temp_input:
                ret = tas2770_read_die_temp(tas2770, val);
                break;
+       case hwmon_temp_fault:
+               ret = tas2770_hwmon_is_fault(tas2770, val);
+               break;
        default:
                ret = -EOPNOTSUPP;
                break;
@@ -674,7 +695,7 @@ static int tas2770_hwmon_read(struct device *dev,
 }
 
 static const struct hwmon_channel_info *const tas2770_hwmon_info[] = {
-       HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
+       HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_FAULT),
        NULL
 };