From: Ansuel Smith <ansuelsmth@gmail.com>
To: Amit Kucheria <amit.kucheria@linaro.org>
Cc: Ansuel Smith <ansuelsmth@gmail.com>,
Andy Gross <agross@kernel.org>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Zhang Rui <rui.zhang@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 6/6] drivers: thermal: tsens: add set_trip support for 8960
Date: Thu, 9 Jul 2020 23:51:36 +0200 [thread overview]
Message-ID: <20200709215136.28044-7-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20200709215136.28044-1-ansuelsmth@gmail.com>
Add custom set_trip function for 8960 needed to set trip point to the
tsens driver for 8960 driver.
Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
drivers/thermal/qcom/tsens-8960.c | 78 +++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
index 2dc670206896..321791b8aabf 100644
--- a/drivers/thermal/qcom/tsens-8960.c
+++ b/drivers/thermal/qcom/tsens-8960.c
@@ -93,6 +93,15 @@
TSENS_8064_SENSOR9_EN | \
TSENS_8064_SENSOR10_EN)
+/* Trips: from very hot to very cold */
+enum tsens_trip_type {
+ TSENS_TRIP_STAGE3 = 0,
+ TSENS_TRIP_STAGE2,
+ TSENS_TRIP_STAGE1,
+ TSENS_TRIP_STAGE0,
+ TSENS_TRIP_NUM,
+};
+
u32 tsens_8960_slope[] = {
1176, 1176, 1154, 1176,
1111, 1132, 1132, 1199,
@@ -110,6 +119,16 @@ static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s)
return adc_code * slope + offset;
}
+static int mdegC_to_code(int degC, const struct tsens_sensor *s)
+{
+ int slope, offset;
+
+ slope = thermal_zone_get_slope(s->tzd);
+ offset = CAL_MDEGC - slope * s->offset;
+
+ return degC / slope - offset;
+}
+
static void notify_uspace_tsens_fn(struct work_struct *work)
{
struct tsens_sensor *s = container_of(work, struct tsens_sensor,
@@ -442,6 +461,64 @@ static int get_temp_8960(const struct tsens_sensor *s, int *temp)
return -ETIMEDOUT;
}
+static int set_trip_temp_ipq8064(void *data, int trip, int temp)
+{
+ unsigned int reg_th, reg_cntl;
+ int ret, code, code_chk, hi_code, lo_code;
+ const struct tsens_sensor *s = data;
+ struct tsens_priv *priv = s->priv;
+
+ code = mdegC_to_code(temp, s);
+ code_chk = code;
+
+ if (code < THRESHOLD_MIN_CODE || code > THRESHOLD_MAX_CODE)
+ return -EINVAL;
+
+ ret = regmap_read(priv->tm_map, STATUS_CNTL_ADDR_8064, ®_cntl);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(priv->tm_map, THRESHOLD_ADDR, ®_th);
+ if (ret)
+ return ret;
+
+ hi_code = (reg_th & THRESHOLD_UPPER_LIMIT_MASK)
+ >> THRESHOLD_UPPER_LIMIT_SHIFT;
+ lo_code = (reg_th & THRESHOLD_LOWER_LIMIT_MASK)
+ >> THRESHOLD_LOWER_LIMIT_SHIFT;
+
+ switch (trip) {
+ case TSENS_TRIP_STAGE3:
+ code <<= THRESHOLD_MAX_LIMIT_SHIFT;
+ reg_th &= ~THRESHOLD_MAX_LIMIT_MASK;
+ break;
+ case TSENS_TRIP_STAGE2:
+ if (code_chk <= lo_code)
+ return -EINVAL;
+ code <<= THRESHOLD_UPPER_LIMIT_SHIFT;
+ reg_th &= ~THRESHOLD_UPPER_LIMIT_MASK;
+ break;
+ case TSENS_TRIP_STAGE1:
+ if (code_chk >= hi_code)
+ return -EINVAL;
+ code <<= THRESHOLD_LOWER_LIMIT_SHIFT;
+ reg_th &= ~THRESHOLD_LOWER_LIMIT_MASK;
+ break;
+ case TSENS_TRIP_STAGE0:
+ code <<= THRESHOLD_MIN_LIMIT_SHIFT;
+ reg_th &= ~THRESHOLD_MIN_LIMIT_MASK;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ ret = regmap_write(priv->tm_map, THRESHOLD_ADDR, reg_th | code);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
static const struct tsens_ops ops_8960 = {
.init = init_8960,
.calibrate = calibrate_8960,
@@ -450,6 +527,7 @@ static const struct tsens_ops ops_8960 = {
.disable = disable_8960,
.suspend = suspend_8960,
.resume = resume_8960,
+ .set_trip_temp = set_trip_temp_ipq8064,
};
struct tsens_plat_data data_8960 = {
--
2.27.0
prev parent reply other threads:[~2020-07-09 21:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-09 21:51 [PATCH 0/6] Add support for ipq8064 tsens Ansuel Smith
2020-07-09 21:51 ` [PATCH 1/6] drivers: thermal: tsens: load regmap from phandle for 8960 Ansuel Smith
2020-07-09 21:51 ` [PATCH 2/6] drivers: thermal: tsens: add ipq8064 support Ansuel Smith
2020-07-09 21:51 ` [PATCH 3/6] dt-bindings: thermal: tsens: document ipq8064 bindings Ansuel Smith
2020-07-10 16:24 ` Rob Herring
2020-07-10 16:26 ` Rob Herring
2020-07-10 20:07 ` R: " ansuelsmth
2020-07-14 14:26 ` Rob Herring
2020-07-09 21:51 ` [PATCH 4/6] drivers: thermal: tsens: add interrupt support for 9860 driver Ansuel Smith
2020-07-09 21:51 ` [PATCH 5/6] drivers: thermal: tsens: add support for custom set_trip function Ansuel Smith
2020-07-09 21:51 ` Ansuel Smith [this message]
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=20200709215136.28044-7-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=agross@kernel.org \
--cc=amit.kucheria@linaro.org \
--cc=bjorn.andersson@linaro.org \
--cc=daniel.lezcano@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=rui.zhang@intel.com \
/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).