]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: extend simple thermal driver to support rtl839x 18825/head
authorStephen Howell <howels@allthatwemight.be>
Sat, 17 May 2025 11:06:10 +0000 (12:06 +0100)
committerRobert Marko <robimarko@gmail.com>
Tue, 3 Jun 2025 09:14:45 +0000 (11:14 +0200)
* Extends SoC thermal sensor on rtl839x
* Tested on HP JG928A

Signed-off-by: Stephen Howell <howels@allthatwemight.be>
Link: https://github.com/openwrt/openwrt/pull/18825
Signed-off-by: Robert Marko <robimarko@gmail.com>
target/linux/realtek/dts/rtl839x.dtsi
target/linux/realtek/files-6.6/drivers/thermal/realtek-thermal.c
target/linux/realtek/patches-6.6/330-add-realtek-thernal-driver.patch
target/linux/realtek/rtl839x/config-6.6

index 7fc5aea70c49708f4187746676dd8eb193929651..84473fa2c3f1969e96558fd31b7dba752a8d4a3e 100644 (file)
                        pinctrl-names = "default";
                        pinctrl-0 = <&mdio_aux_mdx>;
                };
+
+               soc_thermal: thermal {
+                       compatible = "realtek,rtl8390-thermal";
+                       #thermal-sensor-cells = <0>;
+               };
        };
 
        pinmux@1b000004 {
                interrupt-parent = <&intc>;
                interrupts = <20 2>;
        };
+
+       thermal_zones: thermal-zones {
+               cpu-thermal {
+                       polling-delay-passive = <1000>;
+                       polling-delay = <1000>;
+                       coefficients = <1000 0>;
+                       thermal-sensors = <&soc_thermal>;
+                       trips {
+                               cpu-crit {
+                                       temperature = <105000>;
+                                       hysteresis = <2000>;
+                                       type = "critical";
+                               };
+                       };
+               };
+       };
 };
index 242f11bd89407b79b7c26da8742aa5e8157ad889..f91ddbccc007d2cfbe12a1134a53243c5621ed97 100644 (file)
 #define RTL8380_TEMP_VALID             BIT(8)
 #define RTL8380_TEMP_OUT_MASK          GENMASK(6, 0)
 
+#define RTL8390_THERMAL_METER0_CTRL0   0x274
+#define RTL8390_THERMAL_METER0_CTRL1   0x278
+#define RTL8390_THERMAL_METER0_CTRL2   0x27c
+#define RTL8390_THERMAL_METER0_RESULT  0x280
+#define RTL8390_THERMAL_METER1_CTRL0   0x284
+#define RTL8390_THERMAL_METER1_CTRL1   0x288
+#define RTL8390_THERMAL_METER1_CTRL2   0x28c
+#define RTL8390_THERMAL_METER1_RESULT  0x290
+#define RTL8390_TM_ENABLE              BIT(0)
+#define RTL8390_TEMP_VALID             BIT(8)
+#define RTL8390_TEMP_OUT_MASK          GENMASK(6, 0)
+
 #define RTL9300_THERMAL_METER_CTRL0    0x60
 #define RTL9300_THERMAL_METER_CTRL1    0x64
 #define RTL9300_THERMAL_METER_CTRL2    0x68
@@ -69,6 +81,37 @@ static const struct thermal_zone_device_ops rtl8380_ops = {
        .get_temp = rtl8380_get_temp,
 };
 
+static void rtl8390_thermal_init(struct realtek_thermal_priv *priv)
+{
+       priv->enabled = !regmap_update_bits(priv->regmap, RTL8390_THERMAL_METER0_CTRL0, RTL8390_TM_ENABLE, RTL8390_TM_ENABLE);
+}
+
+static int rtl8390_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)
+               rtl8390_thermal_init(priv);
+       /* assume sensor0 is the CPU, both sensor0 & sensor1 report same values +/- 1 degree C */
+       ret = regmap_read(priv->regmap, RTL8390_THERMAL_METER0_RESULT, &val);
+       if (ret)
+               return ret;
+
+       if (!(val & RTL8390_TEMP_VALID))
+               return -EAGAIN;
+
+       *res = FIELD_GET(RTL8390_TEMP_OUT_MASK, val) * slope + offset;
+       return 0;
+}
+
+static const struct thermal_zone_device_ops rtl8390_ops = {
+       .get_temp = rtl8390_get_temp,
+};
+
 static void rtl9300_thermal_init(struct realtek_thermal_priv *priv)
 {
        /* increasing sample delay makes get_temp() succeed more often */
@@ -126,6 +169,7 @@ static int realtek_thermal_probe(struct platform_device *pdev)
 
 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, },
        { /* sentinel */ }
 };
index 0c8d4ab3ab065664c380dafc653c610123412265..af550a8c2023103b952a25010edafda2321b2bea 100644 (file)
@@ -6,10 +6,10 @@
  
 +config REALTEK_THERMAL
 +      tristate "Realtek RTL838x and RTL930x thermal sensor support"
-+      depends on RTL838X || RTL930X || COMPILE_TEST
++      depends on RTL838X || RTL839X || RTL930X || COMPILE_TEST
 +      depends on THERMAL_OF
 +      help
-+        Support thermal sensor in Realtek RTL838x and RTL930x SoCs
++        Support thermal sensor in Realtek RTL838x, RTL839x and RTL930x SoCs
 +
  endif
 --- a/drivers/thermal/Makefile
index 7ea9f707cbc0ced6a5eae24420d21d2f3d304896..f71be029065a719d0fc8f62d25c1a95b2ddef9a8 100644 (file)
@@ -218,6 +218,7 @@ CONFIG_REALTEK_OTTO_WDT=y
 CONFIG_REALTEK_PHY=y
 CONFIG_REALTEK_PHY_HWMON=y
 CONFIG_REALTEK_SOC_PHY=y
+CONFIG_REALTEK_THERMAL=y
 CONFIG_REGMAP=y
 CONFIG_REGMAP_I2C=y
 CONFIG_REGMAP_MDIO=y
@@ -254,6 +255,14 @@ CONFIG_SYS_SUPPORTS_MULTITHREADING=y
 CONFIG_SYS_SUPPORTS_SCHED_SMT=y
 CONFIG_SYS_SUPPORTS_SMP=y
 CONFIG_TARGET_ISA_REV=2
+CONFIG_THERMAL=y
+CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE=y
+# CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE is not set
+# CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE is not set
+CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
+CONFIG_THERMAL_GOV_STEP_WISE=y
+CONFIG_THERMAL_HWMON=y
+CONFIG_THERMAL_OF=y
 CONFIG_TICK_CPU_ACCOUNTING=y
 CONFIG_TIMER_OF=y
 CONFIG_TIMER_PROBE=y