realtek: extend simple thermal driver to support rtl839x
* 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>
This commit is contained in:
parent
079db0ab81
commit
cc5421128e
4 changed files with 76 additions and 2 deletions
|
@ -272,6 +272,11 @@
|
||||||
pinctrl-names = "default";
|
pinctrl-names = "default";
|
||||||
pinctrl-0 = <&mdio_aux_mdx>;
|
pinctrl-0 = <&mdio_aux_mdx>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
soc_thermal: thermal {
|
||||||
|
compatible = "realtek,rtl8390-thermal";
|
||||||
|
#thermal-sensor-cells = <0>;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pinmux@1b000004 {
|
pinmux@1b000004 {
|
||||||
|
@ -343,4 +348,20 @@
|
||||||
interrupt-parent = <&intc>;
|
interrupt-parent = <&intc>;
|
||||||
interrupts = <20 2>;
|
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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,18 @@
|
||||||
#define RTL8380_TEMP_VALID BIT(8)
|
#define RTL8380_TEMP_VALID BIT(8)
|
||||||
#define RTL8380_TEMP_OUT_MASK GENMASK(6, 0)
|
#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_CTRL0 0x60
|
||||||
#define RTL9300_THERMAL_METER_CTRL1 0x64
|
#define RTL9300_THERMAL_METER_CTRL1 0x64
|
||||||
#define RTL9300_THERMAL_METER_CTRL2 0x68
|
#define RTL9300_THERMAL_METER_CTRL2 0x68
|
||||||
|
@ -69,6 +81,37 @@ static const struct thermal_zone_device_ops rtl8380_ops = {
|
||||||
.get_temp = rtl8380_get_temp,
|
.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)
|
static void rtl9300_thermal_init(struct realtek_thermal_priv *priv)
|
||||||
{
|
{
|
||||||
/* increasing sample delay makes get_temp() succeed more often */
|
/* 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[] = {
|
static const struct of_device_id realtek_sensor_ids[] = {
|
||||||
{ .compatible = "realtek,rtl8380-thermal", .data = &rtl8380_ops, },
|
{ .compatible = "realtek,rtl8380-thermal", .data = &rtl8380_ops, },
|
||||||
|
{ .compatible = "realtek,rtl8390-thermal", .data = &rtl8390_ops, },
|
||||||
{ .compatible = "realtek,rtl9300-thermal", .data = &rtl9300_ops, },
|
{ .compatible = "realtek,rtl9300-thermal", .data = &rtl9300_ops, },
|
||||||
{ /* sentinel */ }
|
{ /* sentinel */ }
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
+config REALTEK_THERMAL
|
+config REALTEK_THERMAL
|
||||||
+ tristate "Realtek RTL838x and RTL930x thermal sensor support"
|
+ 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
|
+ depends on THERMAL_OF
|
||||||
+ help
|
+ help
|
||||||
+ Support thermal sensor in Realtek RTL838x and RTL930x SoCs
|
+ Support thermal sensor in Realtek RTL838x, RTL839x and RTL930x SoCs
|
||||||
+
|
+
|
||||||
endif
|
endif
|
||||||
--- a/drivers/thermal/Makefile
|
--- a/drivers/thermal/Makefile
|
||||||
|
|
|
@ -218,6 +218,7 @@ CONFIG_REALTEK_OTTO_WDT=y
|
||||||
CONFIG_REALTEK_PHY=y
|
CONFIG_REALTEK_PHY=y
|
||||||
CONFIG_REALTEK_PHY_HWMON=y
|
CONFIG_REALTEK_PHY_HWMON=y
|
||||||
CONFIG_REALTEK_SOC_PHY=y
|
CONFIG_REALTEK_SOC_PHY=y
|
||||||
|
CONFIG_REALTEK_THERMAL=y
|
||||||
CONFIG_REGMAP=y
|
CONFIG_REGMAP=y
|
||||||
CONFIG_REGMAP_I2C=y
|
CONFIG_REGMAP_I2C=y
|
||||||
CONFIG_REGMAP_MDIO=y
|
CONFIG_REGMAP_MDIO=y
|
||||||
|
@ -254,6 +255,14 @@ CONFIG_SYS_SUPPORTS_MULTITHREADING=y
|
||||||
CONFIG_SYS_SUPPORTS_SCHED_SMT=y
|
CONFIG_SYS_SUPPORTS_SCHED_SMT=y
|
||||||
CONFIG_SYS_SUPPORTS_SMP=y
|
CONFIG_SYS_SUPPORTS_SMP=y
|
||||||
CONFIG_TARGET_ISA_REV=2
|
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_TICK_CPU_ACCOUNTING=y
|
||||||
CONFIG_TIMER_OF=y
|
CONFIG_TIMER_OF=y
|
||||||
CONFIG_TIMER_PROBE=y
|
CONFIG_TIMER_PROBE=y
|
||||||
|
|
Loading…
Reference in a new issue