* [PATCH/RFC 0/3] thermal: rcar_gen3_thermal: Apply shared interrupts for thermal sensors
[not found] <57661211.7010900@rvc.renesas.com>
@ 2016-06-19 4:12 ` Khiem Nguyen
2016-06-19 4:13 ` [PATCH/RFC 1/3] thermal: rcar_gen3_thermal: Modify the shared irq with initialization Khiem Nguyen
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Khiem Nguyen @ 2016-06-19 4:12 UTC (permalink / raw)
To: linux-arm-kernel
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(-)
--
1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH/RFC 1/3] thermal: rcar_gen3_thermal: Modify the shared irq with initialization
2016-06-19 4:12 ` [PATCH/RFC 0/3] thermal: rcar_gen3_thermal: Apply shared interrupts for thermal sensors Khiem Nguyen
@ 2016-06-19 4:13 ` Khiem Nguyen
2016-06-19 4:15 ` [PATCH/RFC 2/3] thermal: rcar_gen3_thermal: Modify the way to detect the interrupts Khiem Nguyen
2016-06-19 4:16 ` [PATCH/RFC 3/3] arm64: dts: r8a7795: Support shared irq for thermal sensors Khiem Nguyen
2 siblings, 0 replies; 5+ messages in thread
From: Khiem Nguyen @ 2016-06-19 4:13 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: Gaku Inami <gaku.inami.xw@bp.renesas.com>
Signed-off-by: Khiem Nguyen <khiem.nguyen.xt@rvc.renesas.com>
---
drivers/thermal/rcar_gen3_thermal.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
index a9a372b..e640a14 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -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;
+ }
}
}
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH/RFC 2/3] thermal: rcar_gen3_thermal: Modify the way to detect the interrupts
2016-06-19 4:12 ` [PATCH/RFC 0/3] thermal: rcar_gen3_thermal: Apply shared interrupts for thermal sensors Khiem Nguyen
2016-06-19 4:13 ` [PATCH/RFC 1/3] thermal: rcar_gen3_thermal: Modify the shared irq with initialization Khiem Nguyen
@ 2016-06-19 4:15 ` Khiem Nguyen
2016-06-19 4:16 ` [PATCH/RFC 3/3] arm64: dts: r8a7795: Support shared irq for thermal sensors Khiem Nguyen
2 siblings, 0 replies; 5+ messages in thread
From: Khiem Nguyen @ 2016-06-19 4:15 UTC (permalink / raw)
To: linux-arm-kernel
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.
Signed-off-by: Gaku Inami <gaku.inami.xw@bp.renesas.com>
Signed-off-by: Khiem Nguyen <khiem.nguyen.xt@rvc.renesas.com>
---
drivers/thermal/rcar_gen3_thermal.c | 69 +++++++++++++++++++++++--------------
1 file changed, 44 insertions(+), 25 deletions(-)
diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c
index e640a14..dc5f231 100644
--- a/drivers/thermal/rcar_gen3_thermal.c
+++ b/drivers/thermal/rcar_gen3_thermal.c
@@ -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;
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH/RFC 3/3] arm64: dts: r8a7795: Support shared irq for thermal sensors
2016-06-19 4:12 ` [PATCH/RFC 0/3] thermal: rcar_gen3_thermal: Apply shared interrupts for thermal sensors Khiem Nguyen
2016-06-19 4:13 ` [PATCH/RFC 1/3] thermal: rcar_gen3_thermal: Modify the shared irq with initialization Khiem Nguyen
2016-06-19 4:15 ` [PATCH/RFC 2/3] thermal: rcar_gen3_thermal: Modify the way to detect the interrupts Khiem Nguyen
@ 2016-06-19 4:16 ` Khiem Nguyen
2016-06-20 7:53 ` Geert Uytterhoeven
2 siblings, 1 reply; 5+ messages in thread
From: Khiem Nguyen @ 2016-06-19 4:16 UTC (permalink / raw)
To: linux-arm-kernel
This patch adds the shared interrupts for thermal sensors
TSC1/TSC2/TSC3.
Signed-off-by: Gaku Inami <gaku.inami.xw@bp.renesas.com>
Signed-off-by: Khiem Nguyen <khiem.nguyen.xt@rvc.renesas.com>
---
arch/arm64/boot/dts/renesas/r8a7795.dtsi | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index db203db..761df2b 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -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>;
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH/RFC 3/3] arm64: dts: r8a7795: Support shared irq for thermal sensors
2016-06-19 4:16 ` [PATCH/RFC 3/3] arm64: dts: r8a7795: Support shared irq for thermal sensors Khiem Nguyen
@ 2016-06-20 7:53 ` Geert Uytterhoeven
0 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2016-06-20 7:53 UTC (permalink / raw)
To: linux-arm-kernel
Hi Khiem,
On Sun, Jun 19, 2016 at 6:16 AM, Khiem Nguyen
<khiem.nguyen.xt@rvc.renesas.com> wrote:
> This patch adds the shared interrupts for thermal sensors
> TSC1/TSC2/TSC3.
>
> Signed-off-by: Gaku Inami <gaku.inami.xw@bp.renesas.com>
> Signed-off-by: Khiem Nguyen <khiem.nguyen.xt@rvc.renesas.com>
> ---
> arch/arm64/boot/dts/renesas/r8a7795.dtsi | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
> index db203db..761df2b 100644
> --- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
> +++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
> @@ -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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-06-20 7:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <57661211.7010900@rvc.renesas.com>
2016-06-19 4:12 ` [PATCH/RFC 0/3] thermal: rcar_gen3_thermal: Apply shared interrupts for thermal sensors Khiem Nguyen
2016-06-19 4:13 ` [PATCH/RFC 1/3] thermal: rcar_gen3_thermal: Modify the shared irq with initialization Khiem Nguyen
2016-06-19 4:15 ` [PATCH/RFC 2/3] thermal: rcar_gen3_thermal: Modify the way to detect the interrupts Khiem Nguyen
2016-06-19 4:16 ` [PATCH/RFC 3/3] arm64: dts: r8a7795: Support shared irq for thermal sensors Khiem Nguyen
2016-06-20 7:53 ` Geert Uytterhoeven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).