linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anson Huang <Anson.Huang@nxp.com>
To: rui.zhang@intel.com, daniel.lezcano@linaro.org,
	amit.kucheria@verdurent.com, shawnguo@kernel.org,
	s.hauer@pengutronix.de, kernel@pengutronix.de,
	festevam@gmail.com, linux-pm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Linux-imx@nxp.com
Subject: [PATCH] thermal: imx8mm: Add get_trend ops
Date: Wed, 13 May 2020 10:58:08 +0800	[thread overview]
Message-ID: <1589338689-15700-1-git-send-email-Anson.Huang@nxp.com> (raw)

Add get_trend ops for i.MX8MM thermal to apply fast cooling
mechanism, when temperature exceeds passive trip point, the
highest cooling action will be applied, and when temperature
drops to lower than the margin below passive trip point, the
lowest cooling action will be applied.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
 drivers/thermal/imx8mm_thermal.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c
index e6061e2..8f6a0b8 100644
--- a/drivers/thermal/imx8mm_thermal.c
+++ b/drivers/thermal/imx8mm_thermal.c
@@ -38,6 +38,8 @@
 #define TMU_VER1		0x1
 #define TMU_VER2		0x2
 
+#define IMX_TEMP_COOL_MARGIN	10000
+
 struct thermal_soc_data {
 	u32 num_sensors;
 	u32 version;
@@ -103,8 +105,33 @@ static int tmu_get_temp(void *data, int *temp)
 	return tmu->socdata->get_temp(data, temp);
 }
 
+static int tmu_get_trend(void *p, int trip, enum thermal_trend *trend)
+{
+	struct tmu_sensor *sensor = p;
+	int trip_temp, temp, ret;
+
+	if (!sensor->tzd)
+		return -EINVAL;
+
+	ret = sensor->tzd->ops->get_trip_temp(sensor->tzd, trip, &trip_temp);
+	if (ret)
+		return ret;
+
+	temp = READ_ONCE(sensor->tzd->temperature);
+
+	if (temp > trip_temp)
+		*trend = THERMAL_TREND_RAISE_FULL;
+	else if (temp < (trip_temp - IMX_TEMP_COOL_MARGIN))
+		*trend = THERMAL_TREND_DROP_FULL;
+	else
+		*trend = THERMAL_TREND_STABLE;
+
+	return 0;
+}
+
 static struct thermal_zone_of_device_ops tmu_tz_ops = {
 	.get_temp = tmu_get_temp,
+	.get_trend = tmu_get_trend,
 };
 
 static void imx8mm_tmu_enable(struct imx8mm_tmu *tmu, bool enable)
-- 
2.7.4


             reply	other threads:[~2020-05-13  3:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13  2:58 Anson Huang [this message]
2020-05-22 17:33 ` [PATCH] thermal: imx8mm: Add get_trend ops Daniel Lezcano
2020-05-23  0:35   ` Anson Huang
2020-05-23 12:33     ` Daniel Lezcano
2020-05-24  0:50       ` Anson Huang
2020-05-25  2:46         ` Anson Huang
2020-05-25 11:04           ` Daniel Lezcano
2020-05-25 15:05             ` Anson Huang
2020-05-27 12:26               ` Anson Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1589338689-15700-1-git-send-email-Anson.Huang@nxp.com \
    --to=anson.huang@nxp.com \
    --cc=Linux-imx@nxp.com \
    --cc=amit.kucheria@verdurent.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).