Add Mediatek thermal support
Subsystems (3)
PATCH v8 1/1 Add Mediatek thermal support
This series adds support for the thermal sensors included in the MT8173 SoC. Currently only basic temperature reading is supported without any interrupt support.
The cpufreq driver for MT8173 is currently under review, so there's no real cooling device available in mainline. Until this is available the thermal driver can be tested with the following dts snippet. It creates a fake gpio fan and a fake trip point which is so low that it can easily be reached with a "cat /dev/zero > /dev/null" on the command line.
Please review and let me know what's missing to be included in mainline.
changes since v7:
- re-add some used defines removed in v5
- Use MT8173_THERMAL_ZONE_* defines as array indices in static initializers
changes since v6:
- remove dot in Hanyi Wus name
changes since v5:
- update copyright
- remove unused defines
Changes since v4:
- give calibration constants more meaningful names (offset, slope)
- Use define instead of 0x00c for register access.
Changes since v3:
- add include/dt-bindings/thermal/mt8173.h for to be able to use sensor names in dts files
- fix disabling wrong clock in error path
- remove now unused reset-names property from binding document
- rename MT8173_NUM_BANKS -> MT8173_NUM_ZONES
- rename MT8173_NUM_SENSING_POINTS -> MT8173_NUM_SENSORS_PER_ZONE
- rename struct thermal_zone_device *tz -> struct thermal_zone_device *tzd
Changes since v2:
- sort #includes alphabetically
- Add prefix to register defines
- drop some members from struct mtk_thermal
- simplify raw_to_mcelsius()
- add and use more register bit defines
- use device_reset() instead of devm_reset_control_get()/reset_control_reset()
- misc other stuff
Changes since v1:
- Use "mediatek," prefix for custom properties
- Drop "thermal: consistently use int for temperatures" dependency
Sascha
fan: gpio_fan {
compatible = "gpio-fan";
gpios = <&pio 24 0>;
gpio-fan,speed-map = <0 0
4500 1>;
#cooling-cells = <2>;
};
thermal-zones {
cpu_thermal: cpu_thermal {
polling-delay-passive = <1000>; /* milliseconds */
polling-delay = <1000>; /* milliseconds */
thermal-sensors = <&thermal 0>;
trips {
cpu_passive: cpu_passive {
temperature = <47000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
cpu_crit {
temperature = <90000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "critical";
};
};
cooling-maps {
map0 {
trip = <&cpu_passive>;
cooling-device = <&fan THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
};
};
};
};PATCH 1/3 dt-bindings: thermal: Add binding document for Mediatek thermal controller
--- .../bindings/thermal/mediatek-thermal.txt | 38 ++++++++++++++++++++++ include/dt-bindings/thermal/mt8173.h | 13 ++++++++ 2 files changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/mediatek-thermal.txt create mode 100644 include/dt-bindings/thermal/mt8173.h
Documentation/devicetree/bindings/thermal/mediatek-thermal.txt new file +38 -0
@@ -0,0 +1,38 @@ +* Mediatek Thermal + +This describes the device tree binding for the Mediatek thermal controller +which measures the on-SoC temperatures. This device does not have its own ADC, +instead it directly controls the AUXADC via AHB bus accesses. For this reason +this device needs phandles to the AUXADC. Also it controls a mux in the +apmixedsys register space via AHB bus accesses, so a phandle to the APMIXEDSYS +is also needed. + +Required properties: +- compatible: "mediatek,mt8173-thermal" +- reg: Address range of the thermal controller +- interrupts: IRQ for the thermal controller +- clocks, clock-names: Clocks needed for the thermal controller. required + clocks are: + "therm": Main clock needed for register access + "auxadc": The AUXADC clock +- resets: Reference to the reset controller controlling the thermal controller. +- mediatek,auxadc: A phandle to the AUXADC which the thermal controller uses +- mediatek,apmixedsys: A phandle to the APMIXEDSYS controller. +- #thermal-sensor-cells : Should be 1. See ./thermal.txt for a description. See + include/dt-bindings/thermal/mt8173.h for valid sensor + numbers. + +Example: + + thermal: thermal at 1100b000 { + #thermal-sensor-cells = <1>; + compatible = "mediatek,mt8173-thermal"; + reg = <0 0x1100b000 0 0x1000>; + interrupts = <0 70 IRQ_TYPE_LEVEL_LOW>; + clocks = <&pericfg CLK_PERI_THERM>, <&pericfg CLK_PERI_AUXADC>; + clock-names = "therm", "auxadc"; + resets = <&pericfg MT8173_PERI_THERM_SW_RST>; + reset-names = "therm"; + mediatek,auxadc = <&auxadc>; + mediatek,apmixedsys = <&apmixedsys>; + };
include/dt-bindings/thermal/mt8173.h new file +13 -0
@@ -0,0 +1,13 @@ +/* +* This header provides constants for mediatek,mt8173-thermal +*/ + +#ifndef _DT_BINDINGS_THERMAL_MEDIATEK_MT8173_H +#define _DT_BINDINGS_THERMAL_MEDIATEK_MT8173_H + +#define MT8173_THERMAL_ZONE_CA53 0 +#define MT8173_THERMAL_ZONE_CA57 1 +#define MT8173_THERMAL_ZONE_GPU 2 +#define MT8173_THERMAL_ZONE_CORE 3 + +#endif /* _DT_BINDINGS_THERMAL_MEDIATEK_MT8173_H */
Signature · 1 line
2.5.0
Re: [PATCH 1/3] dt-bindings: thermal: Add binding document for Mediatek thermal controller
Quoted 2 lines · Sascha Hauer
Signed-off-by Sascha Hauer <[email protected]>Reviewed-by Daniel Kurtz <[email protected]>
Uh, still forgot the commit log. Will add something like:
This adds the device tree binding documentation for the mediatek thermal controller found on Mediatek MT8173 and other SoCs.
Sascha
Quoted 74 lines
--- .../bindings/thermal/mediatek-thermal.txt | 38 ++++++++++++++++++++++ include/dt-bindings/thermal/mt8173.h | 13 ++++++++ 2 files changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/mediatek-thermal.txt create mode 100644 include/dt-bindings/thermal/mt8173.hDocumentation/devicetree/bindings/thermal/mediatek-thermal.txt new file +38
-0@@ -0,0 +1,38 @@ +* Mediatek Thermal + +This describes the device tree binding for the Mediatek thermal controller +which measures the on-SoC temperatures. This device does not have its own ADC, +instead it directly controls the AUXADC via AHB bus accesses. For this reason +this device needs phandles to the AUXADC. Also it controls a mux in the +apmixedsys register space via AHB bus accesses, so a phandle to the APMIXEDSYS +is also needed. + +Required properties: +- compatible: "mediatek,mt8173-thermal" +- reg: Address range of the thermal controller +- interrupts: IRQ for the thermal controller +- clocks, clock-names: Clocks needed for the thermal controller. required + clocks are: + "therm": Main clock needed for register access + "auxadc": The AUXADC clock +- resets: Reference to the reset controller controlling the thermal controller. +- mediatek,auxadc: A phandle to the AUXADC which the thermal controller uses +- mediatek,apmixedsys: A phandle to the APMIXEDSYS controller. +- #thermal-sensor-cells : Should be 1. See ./thermal.txt for a description. See + include/dt-bindings/thermal/mt8173.h for valid sensor + numbers. + +Example: + + thermal: thermal at 1100b000 { + #thermal-sensor-cells = <1>; + compatible = "mediatek,mt8173-thermal"; + reg = <0 0x1100b000 0 0x1000>; + interrupts = <0 70 IRQ_TYPE_LEVEL_LOW>; + clocks = <&pericfg CLK_PERI_THERM>, <&pericfg CLK_PERI_AUXADC>; + clock-names = "therm", "auxadc"; + resets = <&pericfg MT8173_PERI_THERM_SW_RST>; + reset-names = "therm"; + mediatek,auxadc = <&auxadc>; + mediatek,apmixedsys = <&apmixedsys>; + };include/dt-bindings/thermal/mt8173.h new file +13
-0@@ -0,0 +1,13 @@ +/* +* This header provides constants for mediatek,mt8173-thermal +*/ + +#ifndef _DT_BINDINGS_THERMAL_MEDIATEK_MT8173_H +#define _DT_BINDINGS_THERMAL_MEDIATEK_MT8173_H + +#define MT8173_THERMAL_ZONE_CA53 0 +#define MT8173_THERMAL_ZONE_CA57 1 +#define MT8173_THERMAL_ZONE_GPU 2 +#define MT8173_THERMAL_ZONE_CORE 3 + +#endif /* _DT_BINDINGS_THERMAL_MEDIATEK_MT8173_H */ Signature · 1 line
2.5.0
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 2/3 thermal: Add Mediatek thermal controller support
In reply to Sascha HauerThis adds support for the Mediatek thermal controller found on MT8173 and likely other SoCs.
The controller is a bit special. It does not have its own ADC, instead it controls the on-SoC AUXADC via AHB bus accesses. For this reason we need the physical address of the AUXADC. Also it controls a mux using AHB bus accesses, so we need the APMIXEDSYS physical address aswell.
--- drivers/thermal/Kconfig | 8 + drivers/thermal/Makefile | 1 + drivers/thermal/mtk_thermal.c | 537 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 546 insertions(+) create mode 100644 drivers/thermal/mtk_thermal.c
drivers/thermal/Kconfig +8 -0
@@ -340,6 +340,14 @@ config ACPI_THERMAL_REL tristate depends on ACPI +config MTK_THERMAL + tristate "Temperature sensor driver for mediatek SoCs" + depends on ARCH_MEDIATEK || COMPILE_TEST + default y + help + Enable this option if you want to have support for thermal management + controller present in Mediatek SoCs + menu "Texas Instruments thermal drivers" source "drivers/thermal/ti-soc-thermal/Kconfig" endmenu
drivers/thermal/Makefile +1 -0
@@ -44,3 +44,4 @@ obj-$(CONFIG_INT340X_THERMAL) += int340x_thermal/ obj-$(CONFIG_ST_THERMAL) += st/ obj-$(CONFIG_TEGRA_SOCTHERM) += tegra_soctherm.o obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o +obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o
drivers/thermal/mtk_thermal.c new file +537 -0
537 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [PATCH 2/3] thermal: Add Mediatek thermal controller support
Hi Sascha,
Quoted 9 lines · Sascha Hauer
This adds support for the Mediatek thermal controller found on MT8173 and likely other SoCs.
The controller is a bit special. It does not have its own ADC, instead it controls the on-SoC AUXADC via AHB bus accesses. For this reason we need the physical address of the AUXADC. Also it controls a mux using AHB bus accesses, so we need the APMIXEDSYS physical address aswell.Signed-off-by Sascha Hauer <[email protected]>Reviewed-by Daniel Kurtz <[email protected]>
[snip...]
Quoted 5 lines
drivers/thermal/mtk_thermal.c new file +5
-0+static int mtk_read_temp (void *data,long *temp) +{ +struct mtk_thermal_bank *bank = data; + +mtk_thermal_get_bank (bank);
drivers/thermal/mtk_thermal.c line 288
Quoted 10 lines
drivers/thermal/mtk_thermal.c new file +10
-0+ + *temp =mtk_thermal_bank_temperature (bank); + +mtk_thermal_put_bank (bank); + +return 0 ; +} + +static const struct thermal_zone_of_device_ops mtk_thermal_ops = { + .get_temp = mtk_read_temp,
On v4.3-rc1, this now causes a compile warning, since the prototype for get_temp was changed to:
int (*get_temp)(void *, int *);
by:
commit 17e8351a77397e8a83727eb17e3a3e9b8ab5257a
thermal: consistently use int for temperatures
-Dan
Re: [PATCH 2/3] thermal: Add Mediatek thermal controller support
Quoted 35 lines · Daniel Kurtz
Hi Sascha,
Quoted 9 lines · Sascha Hauer
This adds support for the Mediatek thermal controller found on MT8173 and likely other SoCs.
The controller is a bit special. It does not have its own ADC, instead it controls the on-SoC AUXADC via AHB bus accesses. For this reason we need the physical address of the AUXADC. Also it controls a mux using AHB bus accesses, so we need the APMIXEDSYS physical address aswell.Signed-off-by Sascha Hauer <[email protected]>Reviewed-by Daniel Kurtz <[email protected]>[snip...]
Quoted 5 lines
drivers/thermal/mtk_thermal.c new file +5
-0+static int mtk_read_temp (void *data,long *temp) +{ +struct mtk_thermal_bank *bank = data; + +mtk_thermal_get_bank (bank);drivers/thermal/mtk_thermal.c line 288
Quoted 10 lines
drivers/thermal/mtk_thermal.c new file +10
-0+ + *temp =mtk_thermal_bank_temperature (bank); + +mtk_thermal_put_bank (bank); + +return 0 ; +} + +static const struct thermal_zone_of_device_ops mtk_thermal_ops = { + .get_temp = mtk_read_temp,On v4.3-rc1, this now causes a compile warning, since the prototype for
get_tempwas changed to:
Quoted 5 lines
int (*get_temp)(void *, int *);by:
commit17e8351a77397e8a83727eb17e3a3e9b8ab5257a
thermal: consistently use int for temperatures
It is actually a little worse than a warning. This actually causes a crash on boot.
Sascha, can you send out a rebased patch set on v4.3-rc1?
Thanks,
-Dan
Quoted 3 lines
-Dan
Re: [PATCH 2/3] thermal: Add Mediatek thermal controller support
Quoted 38 lines · Daniel Kurtz
Quoted 37 lines · Daniel Kurtz
Hi Sascha,
Quoted 9 lines · Sascha Hauer
This adds support for the Mediatek thermal controller found on MT8173 and likely other SoCs.
The controller is a bit special. It does not have its own ADC, instead it controls the on-SoC AUXADC via AHB bus accesses. For this reason we need the physical address of the AUXADC. Also it controls a mux using AHB bus accesses, so we need the APMIXEDSYS physical address aswell.Signed-off-by Sascha Hauer <[email protected]>Reviewed-by Daniel Kurtz <[email protected]>[snip...]
Quoted 5 lines
drivers/thermal/mtk_thermal.c new file +5
-0+static int mtk_read_temp (void *data,long *temp) +{ +struct mtk_thermal_bank *bank = data; + +mtk_thermal_get_bank (bank);drivers/thermal/mtk_thermal.c line 288
Quoted 10 lines
drivers/thermal/mtk_thermal.c new file +10
-0+ + *temp =mtk_thermal_bank_temperature (bank); + +mtk_thermal_put_bank (bank); + +return 0 ; +} + +static const struct thermal_zone_of_device_ops mtk_thermal_ops = { + .get_temp = mtk_read_temp,On v4.3-rc1, this now causes a compile warning, since the prototype for
get_tempwas changed to:int (*get_temp)(void *, int *);
Quoted 7 lines
Quoted 3 lines
by:
commit17e8351a77397e8a83727eb17e3a3e9b8ab5257a
thermal: consistently use int for temperaturesIt is actually a little worse than a warning. This actually causes a crash on boot.
Sascha, can you send out a rebased patch set on v4.3-rc1?
Yes, I'll send out a new version tomorrow. I am currently quite busy with another project.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 3/3 ARM64: dts: mt8173: Add thermal/auxadc device nodes
In reply to Sascha Hauer--- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm64/boot/dts/mediatek/mt8173.dtsi +17 -0
@@ -151,6 +151,11 @@ (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>; }; + auxadc: auxadc at 11001000 { + compatible = "mediatek,mt8173-auxadc"; + reg = <0 0x11001000 0 0x1000>; + }; + uart0: serial at 11002000 { compatible = "mediatek,mt8173-uart", "mediatek,mt6577-uart";
@@ -186,6 +191,18 @@ clocks = <&uart_clk>; status = "disabled"; }; + + thermal: thermal at 1100b000 { + #thermal-sensor-cells = <1>; + compatible = "mediatek,mt8173-thermal"; + reg = <0 0x1100b000 0 0x1000>; + interrupts = <0 70 IRQ_TYPE_LEVEL_LOW>; + clocks = <&pericfg CLK_PERI_THERM>, <&pericfg CLK_PERI_AUXADC>; + clock-names = "therm", "auxadc"; + resets = <&pericfg MT8173_PERI_THERM_SW_RST>; + mediatek,auxadc = <&auxadc>; + mediatek,apmixedsys = <&apmixedsys>; + }; }; };
Signature · 1 line
2.5.0