linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp
@ 2020-07-29 16:52 Guru Das Srinagesh
  2020-07-29 16:52 ` [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals Guru Das Srinagesh
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Guru Das Srinagesh @ 2020-07-29 16:52 UTC (permalink / raw)
  To: Amit Kucheria, Stephen Boyd, linux-pm, linux-arm-msm
  Cc: Subbaraman Narayanamurthy, David Collins, linux-kernel,
	Veera Vegivada, Guru Das Srinagesh

From: Veera Vegivada <vvegivad@codeaurora.org>

Currently driver is suppressing the negative temperature
readings from the vadc. Consumers of the thermal zones need
to read the negative temperature too. Don't suppress the
readings.

Fixes: c610afaa21d3c6e ("thermal: Add QPNP PMIC temperature alarm driver")
Signed-off-by: Veera Vegivada <vvegivad@codeaurora.org>
Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
---
 drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
index bf7bae4..6dc879f 100644
--- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
+++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2011-2015, 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011-2015, 2017, 2020, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/bitops.h>
@@ -191,7 +191,7 @@ static int qpnp_tm_get_temp(void *data, int *temp)
 		chip->temp = mili_celsius;
 	}
 
-	*temp = chip->temp < 0 ? 0 : chip->temp;
+	*temp = chip->temp;
 
 	return 0;
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals
  2020-07-29 16:52 [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp Guru Das Srinagesh
@ 2020-07-29 16:52 ` Guru Das Srinagesh
  2020-08-05  6:48   ` Stephen Boyd
  2020-08-05  6:48 ` [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp Stephen Boyd
  2020-08-24  7:15 ` Daniel Lezcano
  2 siblings, 1 reply; 7+ messages in thread
From: Guru Das Srinagesh @ 2020-07-29 16:52 UTC (permalink / raw)
  To: Amit Kucheria, Stephen Boyd, linux-pm, linux-arm-msm
  Cc: Subbaraman Narayanamurthy, David Collins, linux-kernel,
	Guru Das Srinagesh

From: David Collins <collinsd@codeaurora.org>

Add support for TEMP_ALARM GEN2 PMIC peripherals with digital
major revision 1.  This revision utilizes a different temperature
threshold mapping than earlier revisions.

Signed-off-by: David Collins <collinsd@codeaurora.org>
Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
---
Changes from v1:
- Added space padding for the arrays, moved "||" to previous line

 drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 91 +++++++++++++++++++----------
 1 file changed, 61 insertions(+), 30 deletions(-)

diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
index 6dc879f..7419e19 100644
--- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
+++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
@@ -17,6 +17,7 @@
 
 #include "../thermal_core.h"
 
+#define QPNP_TM_REG_DIG_MAJOR		0x01
 #define QPNP_TM_REG_TYPE		0x04
 #define QPNP_TM_REG_SUBTYPE		0x05
 #define QPNP_TM_REG_STATUS		0x08
@@ -38,26 +39,30 @@
 
 #define ALARM_CTRL_FORCE_ENABLE		BIT(7)
 
-/*
- * Trip point values based on threshold control
- * 0 = {105 C, 125 C, 145 C}
- * 1 = {110 C, 130 C, 150 C}
- * 2 = {115 C, 135 C, 155 C}
- * 3 = {120 C, 140 C, 160 C}
-*/
-#define TEMP_STAGE_STEP			20000	/* Stage step: 20.000 C */
-#define TEMP_STAGE_HYSTERESIS		2000
+#define THRESH_COUNT			4
+#define STAGE_COUNT			3
+
+/* Over-temperature trip point values in mC */
+static const long temp_map_gen1[THRESH_COUNT][STAGE_COUNT] = {
+	{ 105000, 125000, 145000 },
+	{ 110000, 130000, 150000 },
+	{ 115000, 135000, 155000 },
+	{ 120000, 140000, 160000 },
+};
+
+static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_COUNT] = {
+	{  90000, 110000, 140000 },
+	{  95000, 115000, 145000 },
+	{ 100000, 120000, 150000 },
+	{ 105000, 125000, 155000 },
+};
 
-#define TEMP_THRESH_MIN			105000	/* Threshold Min: 105 C */
-#define TEMP_THRESH_STEP		5000	/* Threshold step: 5 C */
+#define TEMP_THRESH_STEP		5000 /* Threshold step: 5 C */
 
 #define THRESH_MIN			0
 #define THRESH_MAX			3
 
-/* Stage 2 Threshold Min: 125 C */
-#define STAGE2_THRESHOLD_MIN		125000
-/* Stage 2 Threshold Max: 140 C */
-#define STAGE2_THRESHOLD_MAX		140000
+#define TEMP_STAGE_HYSTERESIS		2000
 
 /* Temperature in Milli Celsius reported during stage 0 if no ADC is present */
 #define DEFAULT_TEMP			37000
@@ -77,6 +82,7 @@ struct qpnp_tm_chip {
 	bool				initialized;
 
 	struct iio_channel		*adc;
+	const long			(*temp_map)[THRESH_COUNT][STAGE_COUNT];
 };
 
 /* This array maps from GEN2 alarm state to GEN1 alarm stage */
@@ -101,6 +107,23 @@ static int qpnp_tm_write(struct qpnp_tm_chip *chip, u16 addr, u8 data)
 }
 
 /**
+ * qpnp_tm_decode_temp() - return temperature in mC corresponding to the
+ *		specified over-temperature stage
+ * @chip:		Pointer to the qpnp_tm chip
+ * @stage:		Over-temperature stage
+ *
+ * Return: temperature in mC
+ */
+static long qpnp_tm_decode_temp(struct qpnp_tm_chip *chip, unsigned int stage)
+{
+	if (!chip->temp_map || chip->thresh >= THRESH_COUNT || stage == 0 ||
+	    stage > STAGE_COUNT)
+		return 0;
+
+	return (*chip->temp_map)[chip->thresh][stage - 1];
+}
+
+/**
  * qpnp_tm_get_temp_stage() - return over-temperature stage
  * @chip:		Pointer to the qpnp_tm chip
  *
@@ -149,14 +172,12 @@ static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip)
 
 	if (stage_new > stage_old) {
 		/* increasing stage, use lower bound */
-		chip->temp = (stage_new - 1) * TEMP_STAGE_STEP +
-			     chip->thresh * TEMP_THRESH_STEP +
-			     TEMP_STAGE_HYSTERESIS + TEMP_THRESH_MIN;
+		chip->temp = qpnp_tm_decode_temp(chip, stage_new)
+				+ TEMP_STAGE_HYSTERESIS;
 	} else if (stage_new < stage_old) {
 		/* decreasing stage, use upper bound */
-		chip->temp = stage_new * TEMP_STAGE_STEP +
-			     chip->thresh * TEMP_THRESH_STEP -
-			     TEMP_STAGE_HYSTERESIS + TEMP_THRESH_MIN;
+		chip->temp = qpnp_tm_decode_temp(chip, stage_new + 1)
+				- TEMP_STAGE_HYSTERESIS;
 	}
 
 	chip->stage = stage;
@@ -199,26 +220,28 @@ static int qpnp_tm_get_temp(void *data, int *temp)
 static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
 					     int temp)
 {
-	u8 reg;
+	long stage2_threshold_min = (*chip->temp_map)[THRESH_MIN][1];
+	long stage2_threshold_max = (*chip->temp_map)[THRESH_MAX][1];
 	bool disable_s2_shutdown = false;
+	u8 reg;
 
 	WARN_ON(!mutex_is_locked(&chip->lock));
 
 	/*
 	 * Default: S2 and S3 shutdown enabled, thresholds at
-	 * 105C/125C/145C, monitoring at 25Hz
+	 * lowest threshold set, monitoring at 25Hz
 	 */
 	reg = SHUTDOWN_CTRL1_RATE_25HZ;
 
 	if (temp == THERMAL_TEMP_INVALID ||
-	    temp < STAGE2_THRESHOLD_MIN) {
+	    temp < stage2_threshold_min) {
 		chip->thresh = THRESH_MIN;
 		goto skip;
 	}
 
-	if (temp <= STAGE2_THRESHOLD_MAX) {
+	if (temp <= stage2_threshold_max) {
 		chip->thresh = THRESH_MAX -
-			((STAGE2_THRESHOLD_MAX - temp) /
+			((stage2_threshold_max - temp) /
 			 TEMP_THRESH_STEP);
 		disable_s2_shutdown = true;
 	} else {
@@ -326,9 +349,7 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip)
 		? chip->stage : alarm_state_map[chip->stage];
 
 	if (stage)
-		chip->temp = chip->thresh * TEMP_THRESH_STEP +
-			     (stage - 1) * TEMP_STAGE_STEP +
-			     TEMP_THRESH_MIN;
+		chip->temp = qpnp_tm_decode_temp(chip, stage);
 
 	crit_temp = qpnp_tm_get_critical_trip_temp(chip);
 	ret = qpnp_tm_update_critical_trip_temp(chip, crit_temp);
@@ -350,7 +371,7 @@ static int qpnp_tm_probe(struct platform_device *pdev)
 {
 	struct qpnp_tm_chip *chip;
 	struct device_node *node;
-	u8 type, subtype;
+	u8 type, subtype, dig_major;
 	u32 res;
 	int ret, irq;
 
@@ -400,6 +421,12 @@ static int qpnp_tm_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = qpnp_tm_read(chip, QPNP_TM_REG_DIG_MAJOR, &dig_major);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "could not read dig_major\n");
+		return ret;
+	}
+
 	if (type != QPNP_TM_TYPE || (subtype != QPNP_TM_SUBTYPE_GEN1
 				     && subtype != QPNP_TM_SUBTYPE_GEN2)) {
 		dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n",
@@ -408,6 +435,10 @@ static int qpnp_tm_probe(struct platform_device *pdev)
 	}
 
 	chip->subtype = subtype;
+	if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major >= 1)
+		chip->temp_map = &temp_map_gen2_v1;
+	else
+		chip->temp_map = &temp_map_gen1;
 
 	/*
 	 * Register the sensor before initializing the hardware to be able to
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp
  2020-07-29 16:52 [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp Guru Das Srinagesh
  2020-07-29 16:52 ` [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals Guru Das Srinagesh
@ 2020-08-05  6:48 ` Stephen Boyd
  2020-08-24  7:15 ` Daniel Lezcano
  2 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2020-08-05  6:48 UTC (permalink / raw)
  To: Amit Kucheria, Guru Das Srinagesh, linux-arm-msm, linux-pm
  Cc: Subbaraman Narayanamurthy, David Collins, linux-kernel,
	Veera Vegivada, Guru Das Srinagesh

Quoting Guru Das Srinagesh (2020-07-29 09:52:51)
> From: Veera Vegivada <vvegivad@codeaurora.org>
> 
> Currently driver is suppressing the negative temperature
> readings from the vadc. Consumers of the thermal zones need
> to read the negative temperature too. Don't suppress the
> readings.
> 
> Fixes: c610afaa21d3c6e ("thermal: Add QPNP PMIC temperature alarm driver")
> Signed-off-by: Veera Vegivada <vvegivad@codeaurora.org>
> Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals
  2020-07-29 16:52 ` [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals Guru Das Srinagesh
@ 2020-08-05  6:48   ` Stephen Boyd
  2021-03-30 17:49     ` Guru Das Srinagesh
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Boyd @ 2020-08-05  6:48 UTC (permalink / raw)
  To: Amit Kucheria, Guru Das Srinagesh, linux-arm-msm, linux-pm
  Cc: Subbaraman Narayanamurthy, David Collins, linux-kernel,
	Guru Das Srinagesh

Quoting Guru Das Srinagesh (2020-07-29 09:52:52)
> From: David Collins <collinsd@codeaurora.org>
> 
> Add support for TEMP_ALARM GEN2 PMIC peripherals with digital
> major revision 1.  This revision utilizes a different temperature
> threshold mapping than earlier revisions.
> 
> Signed-off-by: David Collins <collinsd@codeaurora.org>
> Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp
  2020-07-29 16:52 [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp Guru Das Srinagesh
  2020-07-29 16:52 ` [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals Guru Das Srinagesh
  2020-08-05  6:48 ` [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp Stephen Boyd
@ 2020-08-24  7:15 ` Daniel Lezcano
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Lezcano @ 2020-08-24  7:15 UTC (permalink / raw)
  To: Guru Das Srinagesh, Amit Kucheria, Stephen Boyd, linux-pm, linux-arm-msm
  Cc: Subbaraman Narayanamurthy, David Collins, linux-kernel, Veera Vegivada

On 29/07/2020 18:52, Guru Das Srinagesh wrote:
> From: Veera Vegivada <vvegivad@codeaurora.org>
> 
> Currently driver is suppressing the negative temperature
> readings from the vadc. Consumers of the thermal zones need
> to read the negative temperature too. Don't suppress the
> readings.
> 
> Fixes: c610afaa21d3c6e ("thermal: Add QPNP PMIC temperature alarm driver")
> Signed-off-by: Veera Vegivada <vvegivad@codeaurora.org>
> Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
> ---

Applied, thanks



-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals
  2020-08-05  6:48   ` Stephen Boyd
@ 2021-03-30 17:49     ` Guru Das Srinagesh
  2021-03-30 18:00       ` Daniel Lezcano
  0 siblings, 1 reply; 7+ messages in thread
From: Guru Das Srinagesh @ 2021-03-30 17:49 UTC (permalink / raw)
  To: Stephen Boyd, Daniel Lezcano
  Cc: Amit Kucheria, linux-arm-msm, linux-pm,
	Subbaraman Narayanamurthy, David Collins, linux-kernel

On Tue, Aug 04, 2020 at 11:48:30PM -0700, Stephen Boyd wrote:
> Quoting Guru Das Srinagesh (2020-07-29 09:52:52)
> > From: David Collins <collinsd@codeaurora.org>
> > 
> > Add support for TEMP_ALARM GEN2 PMIC peripherals with digital
> > major revision 1.  This revision utilizes a different temperature
> > threshold mapping than earlier revisions.
> > 
> > Signed-off-by: David Collins <collinsd@codeaurora.org>
> > Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
> > ---
> 
> Reviewed-by: Stephen Boyd <sboyd@kernel.org>

+ Daniel Lezcano

Hi Daniel,

I just checked Linus' tree and discovered that this patch has not been
applied - only the other patch in this series. Since this patch has been
reviewed already, could you please check if it's good to be applied as
well?

Thank you.

Guru Das.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals
  2021-03-30 17:49     ` Guru Das Srinagesh
@ 2021-03-30 18:00       ` Daniel Lezcano
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Lezcano @ 2021-03-30 18:00 UTC (permalink / raw)
  To: Guru Das Srinagesh, Stephen Boyd
  Cc: Amit Kucheria, linux-arm-msm, linux-pm,
	Subbaraman Narayanamurthy, David Collins, linux-kernel

On 30/03/2021 19:49, Guru Das Srinagesh wrote:
> On Tue, Aug 04, 2020 at 11:48:30PM -0700, Stephen Boyd wrote:
>> Quoting Guru Das Srinagesh (2020-07-29 09:52:52)
>>> From: David Collins <collinsd@codeaurora.org>
>>>
>>> Add support for TEMP_ALARM GEN2 PMIC peripherals with digital
>>> major revision 1.  This revision utilizes a different temperature
>>> threshold mapping than earlier revisions.
>>>
>>> Signed-off-by: David Collins <collinsd@codeaurora.org>
>>> Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org>
>>> ---
>>
>> Reviewed-by: Stephen Boyd <sboyd@kernel.org>
> 
> + Daniel Lezcano
> 
> Hi Daniel,
> 
> I just checked Linus' tree and discovered that this patch has not been
> applied - only the other patch in this series. Since this patch has been
> reviewed already, could you please check if it's good to be applied as
> well?

Applied, thanks


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-30 18:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 16:52 [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp Guru Das Srinagesh
2020-07-29 16:52 ` [PATCH v2 2/2] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 1 PMIC peripherals Guru Das Srinagesh
2020-08-05  6:48   ` Stephen Boyd
2021-03-30 17:49     ` Guru Das Srinagesh
2021-03-30 18:00       ` Daniel Lezcano
2020-08-05  6:48 ` [PATCH v2 1/2] thermal: qcom-spmi-temp-alarm: Don't suppress negative temp Stephen Boyd
2020-08-24  7:15 ` Daniel Lezcano

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).