Skip to contentSkip to conversation

thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal support

PATCH In review Khiem Nguyen 4 participants 14 messages Jun 19, 2016 – Sep 3, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal support

This patchset adds new thermal sensor driver to support 3 sensors found in R-Car Gen3 series.

It has been decided to create new driver, instead of using the existing thermal driver due to many differences in HW setting flows, the method to calculate temperatures value and some newly supported features.

The new driver can support both polling mode and interrupt mode. It has been tested with R-Car H3.

This driver is developed based on early work of Hien Dang and Thao Nguyen. All comments are welcome.

Khiem Nguyen (4):
thermal: rcar_gen3_thermal: Document the R-Car Gen3 thermal bindings
thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver support
arm64: dts: r8a7795: Add R-Car Gen3 thermal support
arm64: defconfig: Enable R-Car Gen3 thermal support

 .../bindings/thermal/rcar-gen3-thermal.txt         |  79 ++++
 arch/arm64/boot/dts/renesas/r8a7795.dtsi           |  86 ++++
 arch/arm64/configs/defconfig                       |   2 +
 drivers/thermal/Kconfig                            |   9 +
 drivers/thermal/Makefile                           |   1 +
 drivers/thermal/rcar_gen3_thermal.c                | 524 +++++++++++++++++++++
 6 files changed, 701 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt
 create mode 100644 drivers/thermal/rcar_gen3_thermal.c
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 thermal: rcar_gen3_thermal: Document the R-Car Gen3 thermal bindings

---
 .../bindings/thermal/rcar-gen3-thermal.txt         | 79 ++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +79 -0
new file mode 100644
index 0000000..ed6ce45
@@ -0,0 +1,79 @@
+* DT bindings for Renesas R-Car Gen3 Thermal Sensor driver
+
+Required properties:
+- compatible		: "renesas,thermal-<soctype>",
+			  Examples with soctypes are:
+			    - "renesas,thermal-r8a7795" (R-Car H3)
+			    - "renesas,thermal-r8a7796" (R-Car M3)
+			    - "renesas,rcar-gen3-thermal" as fallback
+- reg			: Address range of the thermal registers.
+- clocks		: Must contain a reference to the functional clock.
+- #thermal-sensor-cells : Please see ./thermal.txt
+
+Option properties:
+
+- interrupts		: Use interrupt
+- power-domain		: Must contain a reference to the power domain. This property is
+			  mandatory if the thermal sensor instance is part of a controllable power
+			  domain.
+
+Example (non interrupt support):
+
+	tsc1: thermal@e6198000 {
+		compatible = "renesas,thermal-r8a7795",
+			"renesas,rcar-gen3-thermal";
+		reg = <0 0xe6198000 0 0x5c>;
+		clocks = <&cpg CPG_MOD 522>;
+		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
+		#thermal-sensor-cells = <0>;
+		status = "okay";
+	};
+
+	thermal-zones {
+		sensor_thermal1: sensor-thermal1 {
+			polling-delay-passive = <250>;
+			polling-delay = <1000>;
+
+			/* sensor ID */
+			thermal-sensors = <&tsc1>;
+
+			trips {
+				sensor1_crit: sensor1-crit {
+					temperature = <90000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
+
+Example (interrupt support):
+
+	tsc1: thermal@e6198000 {
+		compatible = "renesas,thermal-r8a7795",
+			"renesas,rcar-gen3-thermal";
+		reg = <0 0xe6198000 0 0x5c>;
+		interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cpg CPG_MOD 522>;
+		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
+		#thermal-sensor-cells = <0>;
+		status = "okay";
+	};
+
+	thermal-zones {
+		sensor_thermal1: sensor-thermal1 {
+			polling-delay-passive = <250>;
+			polling-delay = <0>;
+
+			/* sensor ID */
+			thermal-sensors = <&tsc1>;
+
+			trips {
+				sensor1_crit: sensor1-crit {
+					temperature = <90000>;
+					hysteresis = <2000>;
+					type = "critical";
+				};
+			};
+		};
+	};
Signature · 1 line
1.9.1
#3 lore raw

PATCH 2/4 thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver support

In reply to Khiem Nguyen
---
 drivers/thermal/Kconfig             |   9 +
 drivers/thermal/Makefile            |   1 +
 drivers/thermal/rcar_gen3_thermal.c | 524 ++++++++++++++++++++++++++++++++++++
 3 files changed, 534 insertions(+)
 create mode 100644 drivers/thermal/rcar_gen3_thermal.c
drivers/thermal/Kconfig +9 -0
index 2d702ca..151feb7 100644
@@ -223,6 +223,15 @@ config RCAR_THERMAL
 	  Enable this to plug the R-Car thermal sensor driver into the Linux
 	  thermal framework.
 
+config RCAR_GEN3_THERMAL
+	tristate "Renesas R-Car Gen3 thermal driver"
+	depends on ARCH_RENESAS || COMPILE_TEST
+	depends on HAS_IOMEM
+	depends on OF
+	help
+	  Enable this to plug the R-Car Gen3 thermal sensor driver into the Linux
+	  thermal framework.
+
 config KIRKWOOD_THERMAL
 	tristate "Temperature sensor on Marvell Kirkwood SoCs"
 	depends on MACH_KIRKWOOD || COMPILE_TEST
drivers/thermal/Makefile +1 -0
index cded802..3ac9186 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM)	+= qcom-spmi-temp-alarm.o
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_ROCKCHIP_THERMAL)	+= rockchip_thermal.o
 obj-$(CONFIG_RCAR_THERMAL)	+= rcar_thermal.o
+obj-$(CONFIG_RCAR_GEN3_THERMAL)	+= rcar_gen3_thermal.o
 obj-$(CONFIG_KIRKWOOD_THERMAL)  += kirkwood_thermal.o
 obj-y				+= samsung/
 obj-$(CONFIG_DOVE_THERMAL)  	+= dove_thermal.o
drivers/thermal/rcar_gen3_thermal.c new file +524 -0

524 lines not on this page · raw message

Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH 3/4 arm64: dts: r8a7795: Add R-Car Gen3 thermal support

---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 86 ++++++++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
arch/arm64/boot/dts/renesas/r8a7795.dtsi +86 -0
index c14e89a..db203db 100644
@@ -25,6 +25,9 @@
 		i2c4 = &i2c4;
 		i2c5 = &i2c5;
 		i2c6 = &i2c6;
+		tsc0 = &tsc1;
+		tsc1 = &tsc2;
+		tsc2 = &tsc3;
 	};
 
 	psci {
@@ -1620,5 +1623,88 @@
 			clocks = <&cpg CPG_MOD 613>;
 			power-domains = <&sysc R8A7795_PD_A3VP>;
 		};
+
+		tsc1: thermal@e6198000 {
+			compatible = "renesas,thermal-r8a7795",
+				"renesas,rcar-gen3-thermal";
+			reg = <0 0xe6198000 0 0x5c>;
+			interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&cpg CPG_MOD 522>;
+			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
+			#thermal-sensor-cells = <0>;
+			status = "okay";
+		};
+
+		tsc2: thermal@e61a0000 {
+			compatible = "renesas,thermal-r8a7795",
+				"renesas,rcar-gen3-thermal";
+			reg = <0 0xe61a0000 0 0x5c>;
+			interrupts = <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&cpg CPG_MOD 522>;
+			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
+			#thermal-sensor-cells = <0>;
+			status = "okay";
+		};
+
+		tsc3: thermal@e61a8000 {
+			compatible = "renesas,thermal-r8a7795",
+				"renesas,rcar-gen3-thermal";
+			reg = <0 0xe61a8000 0 0x5c>;
+			interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&cpg CPG_MOD 522>;
+			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
+			#thermal-sensor-cells = <0>;
+			status = "okay";
+		};
+
+		thermal-zones {
+			sensor_thermal1: sensor-thermal1 {
+				polling-delay-passive = <250>;
+				polling-delay = <0>;
+
+				/* sensor ID */
+				thermal-sensors = <&tsc1>;
+
+				trips {
+					sensor1_crit: sensor1-crit {
+						temperature = <90000>;
+						hysteresis = <2000>;
+						type = "critical";
+					};
+				};
+			};
+
+			sensor_thermal2: sensor-thermal2 {
+				polling-delay-passive = <250>;
+				polling-delay = <0>;
+
+				/* sensor ID */
+				thermal-sensors = <&tsc2>;
+
+				trips {
+					sensor2_crit: sensor2-crit {
+						temperature = <90000>;
+						hysteresis = <2000>;
+						type = "critical";
+					};
+				};
+			};
+
+			sensor_thermal3: sensor-thermal3 {
+				polling-delay-passive = <250>;
+				polling-delay = <0>;
+
+				/* sensor ID */
+				thermal-sensors = <&tsc3>;
+
+				trips {
+					sensor3_crit: sensor3-crit {
+						temperature = <90000>;
+						hysteresis = <2000>;
+						type = "critical";
+					};
+				};
+			};
+		};
 	};
 };
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

PATCH 4/4 arm64: defconfig: Enable R-Car Gen3 thermal support

In reply to Khiem Nguyen
---
 arch/arm64/configs/defconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/configs/defconfig +2 -0
index 4f3e1f6..b5551d9 100644
@@ -200,8 +200,10 @@ CONFIG_POWER_RESET_SYSCON=y
 CONFIG_SENSORS_LM90=m
 CONFIG_SENSORS_INA2XX=m
 CONFIG_THERMAL=y
+CONFIG_THERMAL_OF=y
 CONFIG_THERMAL_EMULATION=y
 CONFIG_EXYNOS_THERMAL=y
+CONFIG_RCAR_GEN3_THERMAL=y
 CONFIG_WATCHDOG=y
 CONFIG_RENESAS_WDT=y
 CONFIG_MFD_SPMI_PMIC=y
Signature · 1 line
1.9.1
#8 lore raw

cover thermal: rcar_gen3_thermal: Apply shared interrupts for thermal sensors

In reply to Khiem Nguyen

This patchset intents to improve thermal driver operation in interrupt mode, which has been introduced in [1].

The original idea is using 1 interrupt for each thermal sensor, to detect both up and down temperature. It caused issue when the temperature is changing rapidly.

The new idea is about using shared interrupt I/F for all three sensors. Two interrupts will be set to detect temperature up and down. When interrupt occurs, the temperature will be updated in all 3 sensors, if the temperature value is changed.

All comments are welcome.

[1]
[PATCH 0/4] thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal support
https://www.spinics.net/lists/kernel/msg2282663.html

--
Gaku Inami (3):
thermal: rcar_gen3_thermal: Modify the shared irq with initialization
thermal: rcar_gen3_thermal: Modify the way to detect the interrupts
arm64: dts: r8a7795: Support shared irq for thermal sensors

 arch/arm64/boot/dts/renesas/r8a7795.dtsi |  9 ++--
 drivers/thermal/rcar_gen3_thermal.c      | 89 ++++++++++++++++++++------------
 2 files changed, 63 insertions(+), 35 deletions(-)
Signature · 1 line
1.9.1
#9 lore raw

PATCH 1/3 thermal: rcar_gen3_thermal: Modify the shared irq with initialization

In R-CAR Gen3 series, it has some thermal sensors. The interrupt I/F that can be used in thermal sensors is three. So it should be used the interrupt I/F as shared.

This patch changes the shared settings for the thermal interrupts.

---
 drivers/thermal/rcar_gen3_thermal.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/thermal/rcar_gen3_thermal.c +13 -7
index a9a372b..e640a14 100644
@@ -416,6 +416,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
 	int ret = -ENODEV;
 	int idle;
 	struct device_node *tz_nd, *tmp_nd;
+	int i, irq_cnt;
 
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -489,13 +490,18 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
 	rcar_gen3_thermal_irq_enable(priv);
 
 	/* Interrupt */
-	if (irq) {
-		ret = devm_request_irq(dev, irq->start,
-					rcar_gen3_thermal_irq, 0,
-				       dev_name(dev), priv);
-		if (ret) {
-			dev_err(dev, "IRQ request failed\n ");
-			goto error_unregister;
+	if (rcar_has_irq_support(priv)) {
+		irq_cnt = platform_irq_count(pdev);
+		for (i = 0; i < irq_cnt; i++) {
+			irq = platform_get_resource(pdev, IORESOURCE_IRQ, i);
+			ret = devm_request_irq(dev, irq->start,
+					       rcar_gen3_thermal_irq,
+					       IRQF_SHARED,
+					       dev_name(dev), priv);
+			if (ret) {
+				dev_err(dev, "IRQ request failed\n ");
+				goto error_unregister;
+			}
 		}
 	}
 
Signature · 1 line
1.9.1
#10 lore raw

PATCH 2/3 thermal: rcar_gen3_thermal: Modify the way to detect the interrupts

In reply to Khiem Nguyen

The current implementation is that the interrupt I/F and thermal sensor are assigned with one-to-one. So it can't be set the more interrupt trigger to one thermal sensor. Also, the interrupt is detected by a little bit change in temperature.

In order to solve the above problems, the interrupt of thermal sensor is changed as below.
- Change the shared interrupt in each thermal sensors.
- Detect the interrupt when the temperature is changed one degree up and down.

---
 drivers/thermal/rcar_gen3_thermal.c | 69 +++++++++++++++++++++++--------------
 1 file changed, 44 insertions(+), 25 deletions(-)
drivers/thermal/rcar_gen3_thermal.c +44 -25
index e640a14..dc5f231 100644
@@ -63,6 +63,11 @@
 
 #define CTEMP_MASK	0xFFF
 
+#define IRQ_TEMP1_BIT	(0x1 << 0)
+#define IRQ_TEMP2_BIT	(0x1 << 1)
+#define IRQ_TEMPD1_BIT	(0x1 << 3)
+#define IRQ_TEMPD2_BIT	(0x1 << 4)
+
 #define MCELSIUS(temp)			((temp) * 1000)
 #define TEMP_IRQ_SHIFT(tsc_id)	(0x1 << tsc_id)
 #define TEMPD_IRQ_SHIFT(tsc_id)	(0x1 << (tsc_id + 3))
@@ -216,28 +221,42 @@ int _linear_temp_converter(struct equation_coefs coef,
 	return _round_temp(temp);
 }
 
+int _linear_celsius_to_temp(struct equation_coefs coef,
+					int ctemp)
+{
+	int temp_code, temp1, temp2;
+
+	temp1 = (ctemp * coef.a1 / 1000 + coef.b1) / 1000;
+	temp2 = (ctemp * coef.a2 / 1000 + coef.b2) / 1000;
+	temp_code = (temp1 + temp2) / 2;
+
+	return temp_code;
+}
+
 /*
  *		Zone device functions
  */
 static int rcar_gen3_thermal_update_temp(struct rcar_gen3_thermal_priv *priv)
 {
 	u32 ctemp;
-	int i;
 	unsigned long flags;
-	u32 reg = REG_GEN3_IRQTEMP1 + (priv->id * 4);
+	int temp_cel, temp_code;
 
 	spin_lock_irqsave(&priv->lock, flags);
 
-	for (i = 0; i < 256; i++) {
-		ctemp = thermal_reg_read(priv, REG_GEN3_TEMP) & CTEMP_MASK;
-		if (rcar_has_irq_support(priv)) {
-			thermal_reg_write(priv, reg, ctemp);
-			if (thermal_reg_read(priv, REG_GEN3_IRQSTR) != 0)
-				break;
-		} else
-			break;
+	ctemp = thermal_reg_read(priv, REG_GEN3_TEMP) & CTEMP_MASK;
+	if (rcar_has_irq_support(priv)) {
+		temp_cel = _linear_temp_converter(priv->coef, ctemp);
+
+		/* set the interrupts to exceed the temperature */
+		temp_code = _linear_celsius_to_temp(priv->coef,
+						    temp_cel + MCELSIUS(1));
+		thermal_reg_write(priv, REG_GEN3_IRQTEMP1, temp_code);
 
-		udelay(150);
+		/* set the interrupts to fall below the temperature */
+		temp_code = _linear_celsius_to_temp(priv->coef,
+						    temp_cel - MCELSIUS(1));
+		thermal_reg_write(priv, REG_GEN3_IRQTEMP2, temp_code);
 	}
 
 	priv->ctemp = ctemp;
@@ -283,14 +302,14 @@ static int r8a7795_thermal_init(struct rcar_gen3_thermal_priv *priv)
 
 	thermal_reg_write(priv, REG_GEN3_CTSR, PONM);
 	thermal_reg_write(priv, REG_GEN3_IRQCTL, 0x3F);
-	thermal_reg_write(priv, REG_GEN3_IRQEN, TEMP_IRQ_SHIFT(priv->id) |
-						TEMPD_IRQ_SHIFT(priv->id));
+	thermal_reg_write(priv, REG_GEN3_IRQEN,
+			   IRQ_TEMP1_BIT | IRQ_TEMPD2_BIT);
 	thermal_reg_write(priv, REG_GEN3_CTSR,
-			PONM | AOUT | THBGR | VMEN);
+			   PONM | AOUT | THBGR | VMEN);
 	udelay(100);
 
 	thermal_reg_write(priv, REG_GEN3_CTSR,
-			PONM | AOUT | THBGR | VMEN | VMST | THSST);
+			   PONM | AOUT | THBGR | VMEN | VMST | THSST);
 
 	spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -305,11 +324,11 @@ static int r8a7796_thermal_init(struct rcar_gen3_thermal_priv *priv)
 	spin_lock_irqsave(&priv->lock, flags);
 	thermal_reg_write(priv, REG_GEN3_THCTR,  0x0);
 	udelay(1000);
+
 	thermal_reg_write(priv, REG_GEN3_IRQCTL, 0x3F);
-	thermal_reg_write(priv, REG_GEN3_IRQEN, TEMP_IRQ_SHIFT(priv->id) |
-						TEMPD_IRQ_SHIFT(priv->id));
-	thermal_reg_write(priv, REG_GEN3_THCTR,
-						CTCTL | THCNTSEN(BIT_LEN_12));
+	thermal_reg_write(priv, REG_GEN3_IRQEN,
+			   IRQ_TEMP1_BIT | IRQ_TEMPD2_BIT);
+	thermal_reg_write(priv, REG_GEN3_THCTR, CTCTL | THCNTSEN(BIT_LEN_12));
 	reg_val = thermal_reg_read(priv, REG_GEN3_THCTR);
 	reg_val &= ~CTCTL;
 	reg_val |= THSST;
@@ -334,8 +353,7 @@ static void _thermal_irq_ctrl(struct rcar_gen3_thermal_priv *priv, int enable)
 
 	spin_lock_irqsave(&priv->lock, flags);
 	thermal_reg_write(priv, REG_GEN3_IRQMSK,
-		enable ? (TEMP_IRQ_SHIFT(priv->id) |
-			TEMPD_IRQ_SHIFT(priv->id)) : 0);
+		enable ? (IRQ_TEMP1_BIT | IRQ_TEMPD2_BIT) : 0);
 	spin_unlock_irqrestore(&priv->lock, flags);
 }
 
@@ -361,11 +379,12 @@ static irqreturn_t rcar_gen3_thermal_irq(int irq, void *data)
 	thermal_reg_write(priv, REG_GEN3_IRQSTR, 0);
 	spin_unlock_irqrestore(&priv->lock, flags);
 
-	if ((status & TEMP_IRQ_SHIFT(priv->id)) ||
-		(status & TEMPD_IRQ_SHIFT(priv->id))) {
+	if (status == 0)
+		return IRQ_NONE;
+
+	if (status & (IRQ_TEMP1_BIT | IRQ_TEMPD2_BIT)) {
 		rcar_gen3_thermal_irq_disable(priv);
-		schedule_delayed_work(&priv->work,
-				      msecs_to_jiffies(300));
+		schedule_delayed_work(&priv->work, 0);
 	}
 
 	return IRQ_HANDLED;
Signature · 1 line
1.9.1
#11 lore raw

PATCH 3/3 arm64: dts: r8a7795: Support shared irq for thermal sensors

In reply to Khiem Nguyen

This patch adds the shared interrupts for thermal sensors TSC1/TSC2/TSC3.

---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/renesas/r8a7795.dtsi +6 -3
index db203db..761df2b 100644
@@ -1628,7 +1628,8 @@
 			compatible = "renesas,thermal-r8a7795",
 				"renesas,rcar-gen3-thermal";
 			reg = <0 0xe6198000 0 0x5c>;
-			interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>;
+			interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cpg CPG_MOD 522>;
 			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
 			#thermal-sensor-cells = <0>;
@@ -1639,7 +1640,8 @@
 			compatible = "renesas,thermal-r8a7795",
 				"renesas,rcar-gen3-thermal";
 			reg = <0 0xe61a0000 0 0x5c>;
-			interrupts = <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;
+			interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cpg CPG_MOD 522>;
 			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
 			#thermal-sensor-cells = <0>;
@@ -1650,7 +1652,8 @@
 			compatible = "renesas,thermal-r8a7795",
 				"renesas,rcar-gen3-thermal";
 			reg = <0 0xe61a8000 0 0x5c>;
-			interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
+			interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cpg CPG_MOD 522>;
 			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
 			#thermal-sensor-cells = <0>;
Signature · 1 line
1.9.1
#6 lore raw

Re: [PATCH 2/4] thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver support

In reply to Khiem Nguyen

Hi Khiem-san

Thank you for your patch

drivers/thermal/rcar_gen3_thermal.c line 217

Quoted 11 lines
drivers/thermal/rcar_gen3_thermal.c new file +11 -0
+int _linear_temp_converter(struct equation_coefs coef,
+					int temp_code)
+{
+	int temp, temp1, temp2;
+
+	temp1 = MCELSIUS((CODETSD(temp_code) - coef.b1)) / coef.a1;
+	temp2 = MCELSIUS((CODETSD(temp_code) - coef.b2)) / coef.a2;
+	temp = (temp1 + temp2) / 2;
+
+	return _round_temp(temp);
+}

You want to have "static" function here ?

drivers/thermal/rcar_gen3_thermal.c line 259

Quoted 11 lines
drivers/thermal/rcar_gen3_thermal.c new file +11 -0
+static int rcar_gen3_thermal_get_temp(void *devdata, int *temp)
+{
+	struct rcar_gen3_thermal_priv *priv = devdata;
+	int ctemp;
+	unsigned long flags;
+
+	rcar_gen3_thermal_update_temp(priv);
+
+	spin_lock_irqsave(&priv->lock, flags);
+	ctemp = _linear_temp_converter(priv->coef, priv->ctemp);
+	spin_unlock_irqrestore(&priv->lock, flags);

using pointer on _linear_temp_converter() is reasonable ? especially for struct equation_coefs coef

Quoted 5 lines
drivers/thermal/rcar_gen3_thermal.c new file +5 -0
+static const struct rcar_gen3_thermal_data r8a7795_data = {
+	.thermal_init = r8a7795_thermal_init,
+};
+
+static const struct rcar_gen3_thermal_data r8a7796_data = {

drivers/thermal/rcar_gen3_thermal.c line 409

Quoted 10 lines
drivers/thermal/rcar_gen3_thermal.c new file +10 -0
+	.thermal_init = r8a7796_thermal_init,
+};
+
+static const struct of_device_id rcar_gen3_thermal_dt_ids[] = {
+	{ .compatible = "renesas,thermal-r8a7795", .data = &r8a7795_data},
+	{ .compatible = "renesas,thermal-r8a7796", .data = &r8a7796_data},
+	{ .compatible = "renesas,rcar-gen3-thermal", .data = &r8a7796_data},
+	{},
+};
+MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids);

We can't have general case in this case ? "renesas,rcar-gen3-thermal" is not needed IMO.
Especially this driver doesn't need to care about back compatibility yet.

Quoted 29 lines
drivers/thermal/rcar_gen3_thermal.c new file +29 -0
+static int rcar_gen3_thermal_probe(struct platform_device *pdev)
+{
+	struct rcar_gen3_thermal_priv *priv;
+	struct device *dev = &pdev->dev;
+	struct resource *res, *irq;
+	int ret = -ENODEV;
+	int idle;
+	struct device_node *tz_nd, *tmp_nd;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, priv);
+
+	priv->dev = dev;
+
+	pm_runtime_enable(dev);
+	pm_runtime_get_sync(dev);
+
+	priv->data = of_device_get_match_data(dev);
+	if (!priv->data)
+		goto error_unregister;
+
+	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	priv->irq = 0;
+	if (irq) {
+		priv->irq = 1;
+		for_each_node_with_property(tz_nd, "polling-delay") {

drivers/thermal/rcar_gen3_thermal.c line 449

Quoted 10 lines
drivers/thermal/rcar_gen3_thermal.c new file +10 -0
+			tmp_nd = of_parse_phandle(tz_nd,
+					"thermal-sensors", 0);
+			if (tmp_nd && !strcmp(tmp_nd->full_name,
+					dev->of_node->full_name)) {
+				of_property_read_u32(tz_nd, "polling-delay",
+					&idle);
+				(idle > 0) ? (priv->irq = 0) :
+						(priv->irq = 1);
+				break;
+			}

it is not readable for me.

	if (idle > 0)
		priv->irq = 0;
	break;

is enough ?

Quoted 4 lines
drivers/thermal/rcar_gen3_thermal.c new file +4 -0
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		goto error_unregister;
+

drivers/thermal/rcar_gen3_thermal.c line 466

Quoted 10 lines
drivers/thermal/rcar_gen3_thermal.c new file +10 -0
+	priv->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(priv->base)) {
+		ret = PTR_ERR(priv->base);
+		goto error_unregister;
+	}
+
+	spin_lock_init(&priv->lock);
+	INIT_DELAYED_WORK(&priv->work, rcar_gen3_thermal_work);
+
+	priv->id = of_alias_get_id(dev->of_node, "tsc");

Do we really need alias ?
is "tsc" good naming ?
Having this explanation on [1/4] patch document is useful. of_alias_get_id() can return -ENODEV, but no error check ?

drivers/thermal/rcar_gen3_thermal.c line 476

Quoted 9 lines
drivers/thermal/rcar_gen3_thermal.c new file +9 -0
+	priv->zone = devm_thermal_zone_of_sensor_register(dev, 0, priv,
+				&rcar_gen3_tz_of_ops);
+
+	if (IS_ERR(priv->zone)) {
+		dev_err(dev, "Can't register thermal zone\n");
+		ret = PTR_ERR(priv->zone);
+		priv->zone = NULL;
+		goto error_unregister;
+	}

It is not bad operation, but not readable.
How about to have local struct thermal_zone_device *zone, like this ?

	zone = devm_thermal_zone_of_sensor_register(xxxx);
	if (IS_ERR(zone)) {
		...
		ret = PTR_ERR(zone);
		goto error_unregister;
	}
	priv->zone = zone;

drivers/thermal/rcar_gen3_thermal.c line 478

Quoted 1 line
drivers/thermal/rcar_gen3_thermal.c new file +1 -0
+	priv->data->thermal_init(priv);

thermal_init() has return value;

drivers/thermal/rcar_gen3_thermal.c line 486

Quoted 8 lines
drivers/thermal/rcar_gen3_thermal.c new file +8 -0
+	ret = _read_fuse_factor(priv);
+	if (ret)
+		goto error_unregister;
+	_linear_coefficient_calculation(priv);
+	ret = rcar_gen3_thermal_update_temp(priv);
+
+	if (ret < 0)
+		goto error_unregister;

This is very picky comment about empty line,
but this is readable for me

	ret = _read_fuse_factor(priv);
	if (ret)
		goto error_unregister;

	_linear_coefficient_calculation(priv);

	ret = rcar_gen3_thermal_update_temp(priv);
	if (ret < 0)
		goto error_unregister;
#13 lore raw
In reply to Khiem Nguyen

Hi Khiem,

Quoted 7 lines · Khiem Nguyen

This patchset adds new thermal sensor driver to support 3 sensors found in R-Car Gen3 series.

It has been decided to create new driver, instead of using the existing thermal driver due to many differences in HW setting flows, the method to calculate temperatures value and some newly supported features.

Quoted 5 lines

The new driver can support both polling mode and interrupt mode. It has been tested with R-Car H3.

This driver is developed based on early work of Hien Dang and Thao Nguyen. All comments are welcome.

Thanks for your series!

Please CC linux-renesas-soc for drivers related to Renesas SoCs. Please CC Simon for dts and defconfig updates that should go through his tree.

Quoted 6 lines

Khiem Nguyen (4):
thermal: rcar_gen3_thermal: Document the R-Car Gen3 thermal bindings
thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver support
arm64: dts: r8a7795: Add R-Car Gen3 thermal support
arm64: defconfig: Enable R-Car Gen3 thermal support

Quoted 9 lines
 .../bindings/thermal/rcar-gen3-thermal.txt         |  79 ++++
 arch/arm64/boot/dts/renesas/r8a7795.dtsi           |  86 ++++
 arch/arm64/configs/defconfig                       |   2 +
 drivers/thermal/Kconfig                            |   9 +
 drivers/thermal/Makefile                           |   1 +
 drivers/thermal/rcar_gen3_thermal.c                | 524 +++++++++++++++++++++
 6 files changed, 701 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt
 create mode 100644 drivers/thermal/rcar_gen3_thermal.c

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw

Re: [PATCH 1/4] thermal: rcar_gen3_thermal: Document the R-Car Gen3 thermal bindings

In reply to Khiem Nguyen

Hi Khiem,

Quoted 3 lines · Khiem Nguyen

Thanks for your patch!

Quoted 11 lines
---
 .../bindings/thermal/rcar-gen3-thermal.txt         | 79 ++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +0 -0
new file mode 100644
index 0000000..ed6ce45

Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +4 -0
@@ -0,0 +1,79 @@
+* DT bindings for Renesas R-Car Gen3 Thermal Sensor driver
+
+Required properties:
+- compatible           : "renesas,thermal-<soctype>",

Please use "renesas,<soctype>-thermal", as this is the preferred order for new bindings.

Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt line 6

Quoted 2 lines
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +2 -0
+                         Examples with soctypes are:
+                           - "renesas,thermal-r8a7795" (R-Car H3)

renesas,r8a7795-thermal

Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt line 7

Quoted 1 line
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +1 -0
+                           - "renesas,thermal-r8a7796" (R-Car M3)

renesas,r8a7796-thermal, M3-W

Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt line 10

Quoted 3 lines
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +3 -0
+                           - "renesas,rcar-gen3-thermal" as fallback
+- reg                  : Address range of the thermal registers.
+- clocks               : Must contain a reference to the functional clock.

According to the datasheet, the USB_EXTAL clock is also an input for the thermal block. Should it be added?

Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt line 13

Quoted 3 lines
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +3 -0
+- #thermal-sensor-cells : Please see ./thermal.txt
+
+Option properties:

Optional

Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt line 20

Quoted 7 lines
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +7 -0
+
+- interrupts           : Use interrupt
+- power-domain         : Must contain a reference to the power domain. This property is
+                         mandatory if the thermal sensor instance is part of a controllable power
+                         domain.
+
+Example (non interrupt support):

Is there a good reason why you wouldn't want to use interrupts? If not, please make it mandatory.

Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt line 25

Quoted 5 lines
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.txt new file +5 -0
+
+       tsc1: thermal@e6198000 {
+               compatible = "renesas,thermal-r8a7795",
+                       "renesas,rcar-gen3-thermal";
+               reg = <0 0xe6198000 0 0x5c>;

According to the datasheet, there are more registers beyond this range. Shouldn't it be "reg = <0 0xe6198000 0 0x68>;"?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [PATCH/RFC 3/3] arm64: dts: r8a7795: Support shared irq for thermal sensors

In reply to Khiem Nguyen

Hi Khiem,

Quoted 14 lines · Khiem Nguyen

This patch adds the shared interrupts for thermal sensors TSC1/TSC2/TSC3.

---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/renesas/r8a7795.dtsi +0 -0
index db203db..761df2b 100644

arch/arm64/boot/dts/renesas/r8a7795.dtsi line 1632

Quoted 6 lines
arch/arm64/boot/dts/renesas/r8a7795.dtsi +2 -1
@@ -1628,7 +1628,8 @@
                        compatible = "renesas,thermal-r8a7795",
                                "renesas,rcar-gen3-thermal";
                        reg = <0 0xe6198000 0 0x5c>;
-                       interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>;
+                       interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>,
+                                    <GIC_SPI 68 IRQ_TYPE_LEVEL_HIGH>;

If you make this change, the DT bindings should be updated first.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#7 lore raw

RE: [PATCH 2/4] thermal: rcar_gen3_thermal: Add R-Car Gen3 thermal driver support

In reply to Kuninori Morimoto

Hi Morimoto-san,

Thanks for your comments.

Quoted 5 lines
Quoted 5 lines
drivers/thermal/rcar_gen3_thermal.c new file +5 -0
+int _linear_temp_converter(struct equation_coefs coef,
+					int temp_code)
+{
+	int temp, temp1, temp2;
+
Quoted 8 lines

drivers/thermal/rcar_gen3_thermal.c line 217

Quoted 6 lines
drivers/thermal/rcar_gen3_thermal.c new file +6 -0
+	temp1 = MCELSIUS((CODETSD(temp_code) - coef.b1)) / coef.a1;
+	temp2 = MCELSIUS((CODETSD(temp_code) - coef.b2)) / coef.a2;
+	temp = (temp1 + temp2) / 2;
+
+	return _round_temp(temp);
+}

You want to have "static" function here ?

Sound good. Will update in v2.

Quoted 5 lines
Quoted 5 lines
drivers/thermal/rcar_gen3_thermal.c new file +5 -0
+static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) {
+	struct rcar_gen3_thermal_priv *priv = devdata;
+	int ctemp;
+	unsigned long flags;
+
Quoted 8 lines

drivers/thermal/rcar_gen3_thermal.c line 259

Quoted 5 lines
drivers/thermal/rcar_gen3_thermal.c new file +5 -0
+	rcar_gen3_thermal_update_temp(priv);
+
+	spin_lock_irqsave(&priv->lock, flags);
+	ctemp = _linear_temp_converter(priv->coef, priv->ctemp);
+	spin_unlock_irqrestore(&priv->lock, flags);

using pointer on _linear_temp_converter() is reasonable ? especially for struct equation_coefs coef

I failed to see the benefit of the change.
Could you elaborate the points ?
e.g better memory protection, faster byte-code execution, readability, etc

Quoted 9 lines
Quoted 9 lines
drivers/thermal/rcar_gen3_thermal.c new file +9 -0
+static const struct rcar_gen3_thermal_data r8a7795_data = {
+	.thermal_init = r8a7795_thermal_init, };
+
+static const struct rcar_gen3_thermal_data r8a7796_data = {
+	.thermal_init = r8a7796_thermal_init, };
+
+static const struct of_device_id rcar_gen3_thermal_dt_ids[] = {
+	{ .compatible = "renesas,thermal-r8a7795", .data = &r8a7795_data},
+	{ .compatible = "renesas,thermal-r8a7796", .data = &r8a7796_data},
Quoted 8 lines

drivers/thermal/rcar_gen3_thermal.c line 409

Quoted 4 lines
drivers/thermal/rcar_gen3_thermal.c new file +4 -0
+	{ .compatible = "renesas,rcar-gen3-thermal", .data = &r8a7796_data},
+	{},
+};
+MODULE_DEVICE_TABLE(of, rcar_gen3_thermal_dt_ids);

We can't have general case in this case ? "renesas,rcar-gen3-thermal" is not needed IMO.
Especially this driver doesn't need to care about back compatibility yet.

OK. I see your point. Will update in V2.

Quoted 41 lines
Quoted 28 lines
drivers/thermal/rcar_gen3_thermal.c new file +28 -0
+static int rcar_gen3_thermal_probe(struct platform_device *pdev) {
+	struct rcar_gen3_thermal_priv *priv;
+	struct device *dev = &pdev->dev;
+	struct resource *res, *irq;
+	int ret = -ENODEV;
+	int idle;
+	struct device_node *tz_nd, *tmp_nd;
+
+	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, priv);
+
+	priv->dev = dev;
+
+	pm_runtime_enable(dev);
+	pm_runtime_get_sync(dev);
+
+	priv->data = of_device_get_match_data(dev);
+	if (!priv->data)
+		goto error_unregister;
+
+	irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	priv->irq = 0;
+	if (irq) {
+		priv->irq = 1;
+		for_each_node_with_property(tz_nd, "polling-delay") {

drivers/thermal/rcar_gen3_thermal.c line 449

Quoted 10 lines
drivers/thermal/rcar_gen3_thermal.c new file +10 -0
+			tmp_nd = of_parse_phandle(tz_nd,
+					"thermal-sensors", 0);
+			if (tmp_nd && !strcmp(tmp_nd->full_name,
+					dev->of_node->full_name)) {
+				of_property_read_u32(tz_nd, "polling-delay",
+					&idle);
+				(idle > 0) ? (priv->irq = 0) :
+						(priv->irq = 1);
+				break;
+			}

it is not readable for me.

Quoted 5 lines
	if (idle > 0)
		priv->irq = 0;
	break;

is enough ?

Unfortunately, it's not.
The code tries to check "polling-delay" in order to select polling mode and get polling duration from DT. So, your proposal just do 1st part.

Quoted 10 lines
Quoted 10 lines
drivers/thermal/rcar_gen3_thermal.c new file +9 -0
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		goto error_unregister;
+
+	priv->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(priv->base)) {
+		ret = PTR_ERR(priv->base);
+		goto error_unregister;
+	}
Quoted 8 lines

drivers/thermal/rcar_gen3_thermal.c line 466

Quoted 5 lines
drivers/thermal/rcar_gen3_thermal.c new file +5 -0
+
+	spin_lock_init(&priv->lock);
+	INIT_DELAYED_WORK(&priv->work, rcar_gen3_thermal_work);
+
+	priv->id = of_alias_get_id(dev->of_node, "tsc");

Do we really need alias ?
is "tsc" good naming ?

It's the abbreviation of Thermal sensor controller.
The term has been described in HW manual. Therefore, I think it's 'reasonable' name.

Quoted 2 lines

Having this explanation on [1/4] patch document is useful. of_alias_get_id() can return -ENODEV, but no error check ?

Good point. Will fix in v2.

Quoted 4 lines
Quoted 4 lines
drivers/thermal/rcar_gen3_thermal.c new file +4 -0
+	priv->zone = devm_thermal_zone_of_sensor_register(dev, 0, priv,
+				&rcar_gen3_tz_of_ops);
+
+	if (IS_ERR(priv->zone)) {
Quoted 8 lines

drivers/thermal/rcar_gen3_thermal.c line 476

Quoted 5 lines
drivers/thermal/rcar_gen3_thermal.c new file +5 -0
+		dev_err(dev, "Can't register thermal zone\n");
+		ret = PTR_ERR(priv->zone);
+		priv->zone = NULL;
+		goto error_unregister;
+	}

It is not bad operation, but not readable.
How about to have local struct thermal_zone_device *zone, like this ?

It's good point.
I saw that other thermal drivers also did that way.

The original source code follows same code flow as rcar-thermal driver. Perhaps, we can change the code flow for both drivers, as your idea.

Quoted 11 lines
	zone = devm_thermal_zone_of_sensor_register(xxxx);
	if (IS_ERR(zone)) {
		...
		ret = PTR_ERR(zone);
		goto error_unregister;
	}
	priv->zone = zone;

drivers/thermal/rcar_gen3_thermal.c line 478

Quoted 1 line
drivers/thermal/rcar_gen3_thermal.c new file +1 -0
+	priv->data->thermal_init(priv);

thermal_init() has return value;

OK. Will fix in v2.

Quoted 12 lines

drivers/thermal/rcar_gen3_thermal.c line 486

Quoted 9 lines
drivers/thermal/rcar_gen3_thermal.c new file +8 -0
+	ret = _read_fuse_factor(priv);
+	if (ret)
+		goto error_unregister;
+	_linear_coefficient_calculation(priv);
+	ret = rcar_gen3_thermal_update_temp(priv);
+
+	if (ret < 0)
+		goto error_unregister;

This is very picky comment about empty line, but this is readable for me

Quoted 9 lines
	ret = _read_fuse_factor(priv);
	if (ret)
		goto error_unregister;

	_linear_coefficient_calculation(priv);

	ret = rcar_gen3_thermal_update_temp(priv);
	if (ret < 0)
		goto error_unregister;

OK. Newline does not harm anything.
Will add in v2.

Thanks.

Best regards,
KHIEM Nguyen