[PATCH 2/6] hwmon: sparx5: separate temperature reading from sensor dispatch
Robert Marko
robert.marko at sartura.hr
Tue Oct 13 05:56:26 PDT 2026
Move temperature conversion into a helper and dispatch reads by sensor
type. Preserve the existing temperature calculation and error handling
in preparation for adding fan monitoring.
Signed-off-by: Robert Marko <robert.marko at sartura.hr>
---
drivers/hwmon/sparx5-temp.c | 54 +++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 23 deletions(-)
diff --git a/drivers/hwmon/sparx5-temp.c b/drivers/hwmon/sparx5-temp.c
index aa91780737446..0fd5c147f8167 100644
--- a/drivers/hwmon/sparx5-temp.c
+++ b/drivers/hwmon/sparx5-temp.c
@@ -37,38 +37,46 @@ static void s5_temp_enable(struct s5_hwmon *hwmon)
writel(val, hwmon->base + TEMP_CFG);
}
+static int s5_read_temp(struct s5_hwmon *hwmon, long *temp)
+{
+ int value;
+ u32 stat;
+
+ stat = readl_relaxed(hwmon->base + TEMP_STAT);
+ if (!(stat & TEMP_STAT_VALID))
+ return -EAGAIN;
+ value = stat & TEMP_STAT_TEMP;
+ /*
+ * From register documentation:
+ * Temp(C) = TEMP_SENSOR_STAT.TEMP / 4096 * 352.2 - 109.4
+ */
+ value = DIV_ROUND_CLOSEST(value * 3522, 4096) - 1094;
+ /*
+ * Scale down by 10 from above and multiply by 1000 to
+ * have millidegrees as specified by the hwmon sysfs
+ * interface.
+ */
+ value *= 100;
+ *temp = value;
+
+ return 0;
+}
+
static int s5_read(struct device *dev, enum hwmon_sensor_types type,
- u32 attr, int channel, long *temp)
+ u32 attr, int channel, long *val)
{
struct s5_hwmon *hwmon = dev_get_drvdata(dev);
- int rc = 0, value;
- u32 stat;
- switch (attr) {
- case hwmon_temp_input:
- stat = readl_relaxed(hwmon->base + TEMP_STAT);
- if (!(stat & TEMP_STAT_VALID))
- return -EAGAIN;
- value = stat & TEMP_STAT_TEMP;
- /*
- * From register documentation:
- * Temp(C) = TEMP_SENSOR_STAT.TEMP / 4096 * 352.2 - 109.4
- */
- value = DIV_ROUND_CLOSEST(value * 3522, 4096) - 1094;
- /*
- * Scale down by 10 from above and multiply by 1000 to
- * have millidegrees as specified by the hwmon sysfs
- * interface.
- */
- value *= 100;
- *temp = value;
+ switch (type) {
+ case hwmon_temp:
+ if (attr == hwmon_temp_input)
+ return s5_read_temp(hwmon, val);
break;
default:
- rc = -EOPNOTSUPP;
break;
}
- return rc;
+ return -EOPNOTSUPP;
}
static umode_t s5_is_visible(const void *_data, enum hwmon_sensor_types type,
--
2.56.0
More information about the linux-arm-kernel
mailing list