]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: thermal: extend the driver to support rtl960x 22081/head
authorRustam Adilov <adilov@tutamail.com>
Wed, 18 Feb 2026 16:33:07 +0000 (21:33 +0500)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 14 Mar 2026 23:18:36 +0000 (00:18 +0100)
This commit adds support for RTL9607C / RTL8198D thermal controller.
Based on the Realtek SDK code.

Signed-off-by: Rustam Adilov <adilov@tutamail.com>
Link: https://github.com/openwrt/openwrt/pull/22081
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
target/linux/realtek/files-6.12/drivers/thermal/realtek-thermal.c
target/linux/realtek/patches-6.12/330-add-realtek-thernal-driver.patch

index 353860b0054f242ef09c93c76a6a399a48a1e399..e2cbf0c89a9def0ca27ac35eea90f42cec9648a3 100644 (file)
 #define RTL9300_COMPARE_DLY_SHIFT      (0)
 #define RTL9300_COMPARE_DLY_MASK       GENMASK(RTL9300_COMPARE_DLY_SHIFT + 15, RTL9300_COMPARE_DLY_SHIFT)
 
+#define RTL9607_THERMAL_CTRL_0         0x150
+#define RTL9607_REG_PPOW               BIT(29)
+#define RTL9607_THERMAL_CTRL_2         0x158
+#define RTL9607_THERMAL_CTRL_5         0x164
+#define RTL9607_THERMAL_STS_0          0x178
+#define RTL9607_TEMP_OUT_MASK          GENMASK(18, 0)
+#define RTL9607_TEMP_OUT_SIGN          BIT(18)
+#define RTL9607_TEMP_OUT_INT           GENMASK(17, 10)
+#define RTL9607_TEMP_OUT_FLOAT         GENMASK(9, 0)
+
 struct realtek_thermal_priv {
        struct regmap *regmap;
        bool enabled;
@@ -144,6 +154,40 @@ static const struct thermal_zone_device_ops rtl9300_ops = {
        .get_temp = rtl9300_get_temp,
 };
 
+static void rtl9607_thermal_init(struct realtek_thermal_priv *priv)
+{
+       priv->enabled = !regmap_update_bits(priv->regmap, RTL9607_THERMAL_CTRL_0, RTL9607_REG_PPOW, RTL9607_REG_PPOW);
+}
+
+static int rtl9607_get_temp(struct thermal_zone_device *tz, int *res)
+{
+       struct realtek_thermal_priv *priv = thermal_zone_device_priv(tz);
+       int offset = thermal_zone_get_offset(tz);
+       int slope = thermal_zone_get_slope(tz);
+       u32 val;
+       int ret;
+
+       if (!priv->enabled)
+               rtl9607_thermal_init(priv);
+
+       ret = regmap_read(priv->regmap, RTL9607_THERMAL_STS_0, &val);
+       if (ret)
+               return ret;
+
+       /*
+        * The temperature sensor output consist of sign at bit 18, integer part at bits 17~10
+        * and fractional point with 0.5 scaling at bits 9~0.
+        * For simplicity, we only care about the integer part.
+        */
+       *res = FIELD_GET(RTL9607_TEMP_OUT_INT, val) * slope + offset;
+
+       return 0;
+}
+
+static const struct thermal_zone_device_ops rtl9607_ops = {
+       .get_temp = rtl9607_get_temp,
+};
+
 static int realtek_thermal_probe(struct platform_device *pdev)
 {
        struct realtek_thermal_priv *priv;
@@ -171,6 +215,7 @@ static const struct of_device_id realtek_sensor_ids[] = {
        { .compatible = "realtek,rtl8380-thermal", .data = &rtl8380_ops, },
        { .compatible = "realtek,rtl8390-thermal", .data = &rtl8390_ops, },
        { .compatible = "realtek,rtl9300-thermal", .data = &rtl9300_ops, },
+       { .compatible = "realtek,rtl9607-thermal", .data = &rtl9607_ops, },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, realtek_sensor_ids);
index 055ee845d06bf0233cd18231076d1fb98353737d..ab466ba6d21aa2b1a8a1efa7586433cfa6ecf17c 100644 (file)
@@ -6,10 +6,10 @@
  
 +config REALTEK_THERMAL
 +      tristate "Realtek RTL838x and RTL930x thermal sensor support"
-+      depends on RTL838X || RTL839X || RTL930X || COMPILE_TEST
++      depends on RTL838X || RTL839X || RTL930X || RTL960X || COMPILE_TEST
 +      depends on THERMAL_OF
 +      help
-+        Support thermal sensor in Realtek RTL838x, RTL839x and RTL930x SoCs
++        Support thermal sensor in Realtek RTL838x, RTL839x, RTL930x and RTL960x SoCs
 +
  endif
 --- a/drivers/thermal/Makefile