Skip to contentSkip to conversation

Rockchip soc thermal driver

PATCH Superseded Caesar Wang 2 participants 8 messages Oct 11, 2014 – Oct 14, 2014

Subsystems (3)

v9 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

v9 cover Rockchip soc thermal driver

This series patchs tested on rk3288 SDK board and pinky-v1,v2 board. I believe the driver can be used on the rk3288-evb board.

Add this driver, The system can reset the entire chip when the thermal temperture over 120C, In case of rising over 125C when tha hardware shorting,The sodftware will shutdown via "critical".

Changes in v9:
* address comments from Dmitry Torokhov.
- fix some style be defined
- remove some unused code.
- clk_disable_unprepare->clk_disable in suspend()

Changes in v8:
* address comments from Dmitry Torokhov and Doug Anderson.
- add three Teperture Sensors.
- support CRU and GPIO reset chip.
- rename rk3xxx-cpu-thermal.dtsi as rk3288-thermal.dtsi
- alarm-temp via set_trips() callback
- remove "reset-gpios"

Changes in v7:
- fix get data->clk=0 when in probe() function.
- fix some style code.
- modify dts,main add rk3xxx-cpu-thermal.dtsi

Changes in v6:
* address comments from Tomeu Vizoso.
- use thermal's generic framework.

Changes in v5:
* address comments from Eduardo Valentin,rui.zhang and Heiko Stubner:
- with BIT() macro
- manage clocks in suspend/resume.
- license is fixed as GPLv2.
- #include "thermal_core.h"->#include <linux/thermal.h>
- use the generic trip-points.the hw-shut-temp isn't generic trip-points.
- The method of binding and unbinding be fixed.
- The pin-name tsadc->otp_out

Changes in v4:
* address comments from Jonathan Cameron,huangtao and zhaoyifeng:
- this series thermal driver still be put in driver/thermal/
- modify the thermal driver description.

Changes in v3:(add dts configure)
* address comments from Dmitry Torokhov and Arnd Bergmann:
- fix clock-names in rockchip-thermal.txt
- remove rockchip_thermal_control() in rockchip_set_mode()
- fix some code style.
- add dts configure.

Changes in v2:
* address comments from Heiko Stubner:
- fix dt-bindings in rockchip-thermal.txt
- remove Author mark
- rename TSADC_XXX->TSADCV2_XXX,it eill ready to merge compatible other SoCs.
- fix a identation
- remove clk_set_rate(),it's no necessary.
- fix the SIMPLE_DEV_PM_OPS() function style.

Caesar Wang (5):
thermal: rockchip: add driver for thermal
dt-bindings: document Rockchip thermal
ARM: dts: add RK3288 Thermal data
ARM: dts: add main Thermal info to rk3288
ARM: dts: enable Thermal on rk3288-evb board

 .../bindings/thermal/rockchip-thermal.txt          |  45 ++
 arch/arm/boot/dts/rk3288-evb.dtsi                  |   5 +
 arch/arm/boot/dts/rk3288-thermal.dtsi              |  58 ++
 arch/arm/boot/dts/rk3288.dtsi                      |  23 +
 drivers/thermal/Kconfig                            |   9 +
 drivers/thermal/Makefile                           |   1 +
 drivers/thermal/rockchip_thermal.c                 | 628 +++++++++++++++++++++
 7 files changed, 769 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txt
 create mode 100644 arch/arm/boot/dts/rk3288-thermal.dtsi
 create mode 100644 drivers/thermal/rockchip_thermal.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH v9 1/5 thermal: rockchip: add driver for thermal

Thermal is TS-ADC Controller module supports
user-defined mode and automatic mode.

User-defined mode refers,TSADC all the control signals entirely by software writing to register for direct control.

Automaic mode refers to the module automatically poll TSADC output, and the results were checked.If you find that the temperature High in a period of time,an interrupt is generated to the processor down-measures taken;If the temperature over a period of time High, the resulting TSHUT gave CRU module,let it reset the entire chip, or via GPIO give PMIC.

---
 drivers/thermal/Kconfig            |   9 +
 drivers/thermal/Makefile           |   1 +
 drivers/thermal/rockchip_thermal.c | 624 +++++++++++++++++++++++++++++++++++++
 3 files changed, 634 insertions(+)
 create mode 100644 drivers/thermal/rockchip_thermal.c
drivers/thermal/Kconfig +9 -0
index f9a1386..24845ae 100644
@@ -133,6 +133,15 @@ config SPEAR_THERMAL
 	  Enable this to plug the SPEAr thermal sensor driver into the Linux
 	  thermal framework.
 
+config ROCKCHIP_THERMAL
+	tristate "Rockchip thermal driver"
+	depends on ARCH_ROCKCHIP
+	help
+	  Rockchip thermal driver provides support for Temperature sensor
+	  ADC (TS-ADC) found on Rockchip SoCs. It supports one critical
+	  trip point. Cpufreq is used as the cooling device and will throttle
+	  CPUs when the Temperature crosses the passive trip point.
+
 config RCAR_THERMAL
 	tristate "Renesas R-Car thermal driver"
 	depends on ARCH_SHMOBILE || COMPILE_TEST
drivers/thermal/Makefile +1 -0
index de0636a..930554f 100644
@@ -19,6 +19,7 @@ thermal_sys-$(CONFIG_CPU_THERMAL)	+= cpu_cooling.o
 
 # platform thermal drivers
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
+obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
 obj-$(CONFIG_RCAR_THERMAL)	+= rcar_thermal.o
 obj-$(CONFIG_KIRKWOOD_THERMAL)  += kirkwood_thermal.o
 obj-y				+= samsung/
drivers/thermal/rockchip_thermal.c new file +624 -0

624 lines not on this page · raw message

Signature · 1 line
1.9.1
#4 lore raw

PATCH v9 2/5 dt-bindings: document Rockchip thermal

In reply to Caesar Wang

This add the necessary binding documentation for the thermal found on Rockchip SoCs

---
 .../bindings/thermal/rockchip-thermal.txt          | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rockchip-thermal.txt
Documentation/devicetree/bindings/thermal/rockchip-thermal.txt new file +45 -0
new file mode 100644
index 0000000..d5ff410
@@ -0,0 +1,45 @@
+* Temperature Sensor ADC (TSADC) on rockchip SoCs
+
+Required properties:
+- compatible: "rockchip,rk3288-tsadc"
+- reg: physical base address of the controller and length of memory mapped
+       region.
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+	      depends on the interrupt controller.
+- clocks: Must contain an entry for each entry in clock-names.
+- clock-names: Shall be "tsadc" for the converter-clock, and "apb_pclk" for
+	       the peripheral clock.
+- #thermal-sensor-cells: Should be 1. See ./thermal.txt for a description.
+
+Exiample:
+tsadc: tsadc at ff280000 {
+	compatible = "rockchip,rk3288-tsadc";
+	reg = <0xff280000 0x100>;
+	interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
+	clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>;
+	clock-names = "tsadc", "apb_pclk";
+};
+
+Example: referring to thermal sensors:
+thermal-zones {
+       cpu_thermal: cpu_thermal {
+	        polling-delay-passive = <500>; /* milliseconds */
+	        polling-delay = <1000>; /* milliseconds */
+
+			        /* sensor	ID */
+	        thermal-sensors = <&tsadc	1>;
+
+	        trips {
+		        cpu_alert0: cpu_alert {
+			        temperature = <80000>; /* millicelsius */
+			        hysteresis = <2000>; /* millicelsius */
+			        type = "passive";
+		        };
+		        cpu_crit: cpu_crit {
+			        temperature = <125000>; /* millicelsius */
+			        hysteresis = <2000>; /* millicelsius */
+			    type = "critical";
+		        };
+	        };
+       };
+};
Signature · 1 line
1.9.1
#5 lore raw

PATCH v9 3/5 ARM: dts: add RK3288 Thermal data

In reply to Caesar Wang

This patch changes a dtsi file to contain the thermal data on RK3288 and later SoCs. This data will
enable a thermal shutdown over 125C.

---
 arch/arm/boot/dts/rk3288-thermal.dtsi | 57 +++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 arch/arm/boot/dts/rk3288-thermal.dtsi
arch/arm/boot/dts/rk3288-thermal.dtsi new file +57 -0
new file mode 100644
index 0000000..c68c090
@@ -0,0 +1,57 @@
+/*
+ * Device Tree Source for RK3288 SoC thermal
+ *
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2.  This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+#include <dt-bindings/thermal/thermal.h>
+
+reserve_thermal: reserve_thermal {
+	polling-delay-passive = <500>; /* milliseconds */
+	polling-delay = <1000>; /* milliseconds */
+
+			/* sensor	ID */
+	thermal-sensors = <&tsadc	0>;
+
+};
+
+cpu_thermal: cpu_thermal {
+	polling-delay-passive = <500>; /* milliseconds */
+	polling-delay = <1000>; /* milliseconds */
+
+			/* sensor	ID */
+	thermal-sensors = <&tsadc	1>;
+
+	trips {
+		cpu_alert0: cpu_alert0 {
+			temperature = <80000>; /* millicelsius */
+			hysteresis = <2000>; /* millicelsius */
+			type = "passive";
+		};
+		cpu_crit: cpu_crit {
+			temperature = <125000>; /* millicelsius */
+			hysteresis = <2000>; /* millicelsius */
+			type = "critical";
+		};
+	};
+};
+
+gpu_thermal: gpu_thermal {
+	polling-delay-passive = <500>; /* milliseconds */
+	polling-delay = <1000>; /* milliseconds */
+
+			/* sensor	ID */
+	thermal-sensors = <&tsadc	2>;
+
+	trips {
+		gpu_crit: gpu_crit {
+			temperature = <125000>; /* millicelsius */
+			hysteresis = <2000>; /* millicelsius */
+			type = "critical";
+		};
+	};
+};
Signature · 1 line
1.9.1
#6 lore raw

PATCH v9 4/5 ARM: dts: add main Thermal info to rk3288

In reply to Caesar Wang

This patch is depend on rk3288-thermal.dtsi,or it will compile error.

If the temperature over a period of time High,over 120C the resulting TSHUT gave CRU module,let it reset the entire chip,or via GPIO give PMIC.

---
 arch/arm/boot/dts/rk3288.dtsi | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
arch/arm/boot/dts/rk3288.dtsi +24 -0
index 36be7bb..380b602 100644
@@ -15,6 +15,7 @@
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/pinctrl/rockchip.h>
 #include <dt-bindings/clock/rk3288-cru.h>
+#include <dt-bindings/thermal/thermal.h>
 #include "skeleton.dtsi"
 
 / {
@@ -215,6 +216,23 @@
 		status = "disabled";
 	};
 
+	thermal-zones {
+		#include "rk3288-thermal.dtsi"
+	};
+
+	tsadc: tsadc at ff280000 {
+		compatible = "rockchip,rk3288-tsadc";
+		reg = <0xff280000 0x100>;
+		interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>;
+		clock-names = "tsadc", "apb_pclk";
+		pinctrl-names = "default";
+		pinctrl-0 = <&otp_out>;
+		#thermal-sensor-cells = <1>;
+		hw-shut-temp = <120000>;
+		status = "disabled";
+	};
+
 	usb_host0_ehci: usb at ff500000 {
 		compatible = "generic-ehci";
 		reg = <0xff500000 0x100>;
@@ -611,5 +629,11 @@
 				rockchip,pins = <5 15 3 &pcfg_pull_none>;
 			};
 		};
+
+		tsadc {
+			otp_out: otp-out {
+				rockchip,pins = <0 10 RK_FUNC_1 &pcfg_pull_none>;
+			};
+		};
 	};
 };
Signature · 1 line
1.9.1
#7 lore raw

PATCH v9 5/5 ARM: dts: enable Thermal on rk3288-evb board

In reply to Caesar Wang

when a thermal temperature over TSHUT.Default to via CRU reset the entire chip on rk3288-evb Board

---
 arch/arm/boot/dts/rk3288-evb.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/boot/dts/rk3288-evb.dtsi +5 -0
index 2964370..d257cd8 100644
@@ -101,6 +101,11 @@
 	status = "okay";
 };
 
+&tsadc {
+	tsadc-ht-reset-mode = <0>; /* reset mode 0:CRU 1:GPIO */
+	status = "okay";
+};
+
 &pinctrl {
 	buttons {
 		pwrbtn: pwrbtn {
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v9 1/5] thermal: rockchip: add driver for thermal

In reply to Caesar Wang

Caesar,

Quoted 20 lines · Caesar Wang
drivers/thermal/rockchip_thermal.c new file +20 -0
+static void rk_tsadcv2_initialize(int reset_mode, int chn, void __iomem *regs,
+                                 unsigned long hw_shut_temp)
+{
+       u32 shutdown_value;
+
+       shutdown_value = rk_tsadcv2_temp_to_code(hw_shut_temp);
+
+       /* Enable measurements at ~ 10 Hz */
+       writel_relaxed(0 | TSADCV2_AUTO_TSHUT_POLARITY_HIGH, regs +
+                      TSADCV2_AUTO_CON);
+       writel_relaxed(TSADCV2_AUTO_PERIOD_TIME, regs + TSADCV2_AUTO_PERIOD);
+       writel_relaxed(TSADCV2_AUTO_PERIOD_HT_TIME, regs +
+                      TSADCV2_AUTO_PERIOD_HT);
+       writel_relaxed(shutdown_value, regs + TSADCV2_COMP_SHUT(chn));
+       writel_relaxed(TSADCV2_HIGHT_INT_DEBOUNCE_TIME, regs +
+                      TSADCV2_HIGHT_INT_DEBOUNCE);
+       writel_relaxed(TSADCV2_HIGHT_TSHUT_DEBOUNCE_TIME, regs +
+                      TSADCV2_HIGHT_TSHUT_DEBOUNCE);
+
+       if (reset_mode == GPIO)

drivers/thermal/rockchip_thermal.c line 239

Quoted 10 lines
drivers/thermal/rockchip_thermal.c new file +10 -0
+               writel_relaxed(TSADCV2_SHUT_2GPIO_SRC_EN(chn) |
+                              TSADCV2_INT_SRC_EN(chn), regs +
+                              TSADCV2_INT_EN);
+       else
+               writel_relaxed(TSADCV2_SHUT_2CRU_SRC_EN(chn) |
+                              TSADCV2_INT_SRC_EN(chn) , regs +
+                              TSADCV2_INT_EN);
+
+       writel_relaxed(TSADCV2_AUTO_SRC_EN(chn) | TSADCV2_AUTO_EN, regs +
+                      TSADCV2_AUTO_CON);

Aren't you clobbering the polarity here?

NOTE: I didn't do a full review of this driver, just noticed that while looking at another patch and figure'd I'd respond here, too.

#3 lore raw

Re: [PATCH v9 1/5] thermal: rockchip: add driver for thermal

Doug,

? 2014?10?14? 00:11, Doug Anderson ??:

Quoted 37 lines

Caesar,

Quoted 20 lines · Caesar Wang
drivers/thermal/rockchip_thermal.c new file +20 -0
+static void rk_tsadcv2_initialize(int reset_mode, int chn, void __iomem *regs,
+                                 unsigned long hw_shut_temp)
+{
+       u32 shutdown_value;
+
+       shutdown_value = rk_tsadcv2_temp_to_code(hw_shut_temp);
+
+       /* Enable measurements at ~ 10 Hz */
+       writel_relaxed(0 | TSADCV2_AUTO_TSHUT_POLARITY_HIGH, regs +
+                      TSADCV2_AUTO_CON);
+       writel_relaxed(TSADCV2_AUTO_PERIOD_TIME, regs + TSADCV2_AUTO_PERIOD);
+       writel_relaxed(TSADCV2_AUTO_PERIOD_HT_TIME, regs +
+                      TSADCV2_AUTO_PERIOD_HT);
+       writel_relaxed(shutdown_value, regs + TSADCV2_COMP_SHUT(chn));
+       writel_relaxed(TSADCV2_HIGHT_INT_DEBOUNCE_TIME, regs +
+                      TSADCV2_HIGHT_INT_DEBOUNCE);
+       writel_relaxed(TSADCV2_HIGHT_TSHUT_DEBOUNCE_TIME, regs +
+                      TSADCV2_HIGHT_TSHUT_DEBOUNCE);
+
+       if (reset_mode == GPIO)

drivers/thermal/rockchip_thermal.c line 239

Quoted 10 lines
drivers/thermal/rockchip_thermal.c new file +10 -0
+               writel_relaxed(TSADCV2_SHUT_2GPIO_SRC_EN(chn) |
+                              TSADCV2_INT_SRC_EN(chn), regs +
+                              TSADCV2_INT_EN);
+       else
+               writel_relaxed(TSADCV2_SHUT_2CRU_SRC_EN(chn) |
+                              TSADCV2_INT_SRC_EN(chn) , regs +
+                              TSADCV2_INT_EN);
+
+       writel_relaxed(TSADCV2_AUTO_SRC_EN(chn) | TSADCV2_AUTO_EN, regs +
+                      TSADCV2_AUTO_CON);

Aren't you clobbering the polarity here?

Quoted 3 lines

NOTE: I didn't do a full review of this driver, just noticed that while looking at another patch and figure'd I'd respond here, too.

Fixed. Maybe I should fix as follows:

/**
* rk_tsadcv2_get_tshut_polarity - get the tshut polarity
* the bit 8 is tshut polarity,default is low active.
* 0: low active, 1: high active
*/
static bool rk_tsadcv2_get_tshut_polarity(void __iomem *regs)

{
     u32 val;
     bool tshut_polarity;

     val = readl_relaxed(regs + TSADCV2_AUTO_CON);
     tshut_polarity = (val & BIT(8))? 1 : 0;

     return tshut_polarity;
}

...
....

writel_relaxed(TSADCV2_AUTO_SRC_EN(chn) & (tshut_polarity << 8) |

		       TSADCV2_AUTO_EN, regs + TSADCV2_AUTO_CON);
Quoted 1 line
Signature · 2 lines
Best regards,
Caesar