From: Carlos Bilbao <carlos.bilbao@amd.com>
To: <amitk@kernel.org>, <thara.gopinath@gmail.com>,
<agross@kernel.org>, <david.brown@linaro.org>,
<linux-pm@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <bilbao@vt.edu>
Cc: Carlos Bilbao <carlos.bilbao@amd.com>
Subject: [PATCH] thermal/drivers/qcom: Code refactoring
Date: Tue, 12 Jul 2022 12:31:27 -0500 [thread overview]
Message-ID: <20220712173127.3677491-1-carlos.bilbao@amd.com> (raw)
Some functions in tsens-8960.c can directly return ret instead of doing an
extra check. In function calibrate_8960(), a second check for IS_ERR(data)
can also be avoided in some cases. A constant could be used to represent
the maximum number of sensors (11). Finally, function code_to_degc() can be
simplified, avoiding using an extra variable.
Include these small refactoring changes.
Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
---
drivers/thermal/qcom/tsens-8960.c | 25 +++++++++----------------
drivers/thermal/qcom/tsens-common.c | 18 ++++++++----------
drivers/thermal/qcom/tsens-v0_1.c | 6 +++---
drivers/thermal/qcom/tsens-v1.c | 2 +-
drivers/thermal/qcom/tsens.h | 1 +
5 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
index 8d9b721dadb6..576bca871655 100644
--- a/drivers/thermal/qcom/tsens-8960.c
+++ b/drivers/thermal/qcom/tsens-8960.c
@@ -76,10 +76,8 @@ static int suspend_8960(struct tsens_priv *priv)
mask = SLP_CLK_ENA_8660 | EN;
ret = regmap_update_bits(map, CNTL_ADDR, mask, 0);
- if (ret)
- return ret;
- return 0;
+ return ret;
}
static int resume_8960(struct tsens_priv *priv)
@@ -106,10 +104,8 @@ static int resume_8960(struct tsens_priv *priv)
return ret;
ret = regmap_write(map, CNTL_ADDR, priv->ctx.control);
- if (ret)
- return ret;
- return 0;
+ return ret;
}
static int enable_8960(struct tsens_priv *priv, int id)
@@ -132,10 +128,8 @@ static int enable_8960(struct tsens_priv *priv, int id)
reg |= mask | SLP_CLK_ENA_8660 | EN;
ret = regmap_write(priv->tm_map, CNTL_ADDR, reg);
- if (ret)
- return ret;
- return 0;
+ return ret;
}
static void disable_8960(struct tsens_priv *priv)
@@ -206,10 +200,8 @@ static int init_8960(struct tsens_priv *priv)
reg_cntl |= EN;
ret = regmap_write(priv->tm_map, CNTL_ADDR, reg_cntl);
- if (ret)
- return ret;
- return 0;
+ return ret;
}
static int calibrate_8960(struct tsens_priv *priv)
@@ -221,10 +213,11 @@ static int calibrate_8960(struct tsens_priv *priv)
struct tsens_sensor *s = priv->sensor;
data = qfprom_read(priv->dev, "calib");
- if (IS_ERR(data))
+ if (IS_ERR(data)) {
data = qfprom_read(priv->dev, "calib_backup");
- if (IS_ERR(data))
- return PTR_ERR(data);
+ if (IS_ERR(data))
+ return PTR_ERR(data);
+ }
for (i = 0; i < num_read; i++, s++)
s->offset = data[i];
@@ -278,6 +271,6 @@ static const struct tsens_ops ops_8960 = {
};
const struct tsens_plat_data data_8960 = {
- .num_sensors = 11,
+ .num_sensors = MAX_NUM_SENSORS,
.ops = &ops_8960,
};
diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
index 528df8801254..fe5f4459e1cc 100644
--- a/drivers/thermal/qcom/tsens-common.c
+++ b/drivers/thermal/qcom/tsens-common.c
@@ -66,19 +66,17 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1,
static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s)
{
- int degc, num, den;
+ int degc, den;
- num = (adc_code * SLOPE_FACTOR) - s->offset;
+ degc = (adc_code * SLOPE_FACTOR) - s->offset;
den = s->slope;
- if (num > 0)
- degc = num + (den / 2);
- else if (num < 0)
- degc = num - (den / 2);
- else
- degc = num;
-
- degc /= den;
+ if (degc != 0) {
+ if (degc > 0)
+ degc = (degc + (den / 2)) / den;
+ else
+ degc = (degc - (den / 2)) / den;
+ }
return degc;
}
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 6f26fadf4c27..42e897526345 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -188,7 +188,7 @@ static int calibrate_8916(struct tsens_priv *priv)
static int calibrate_8974(struct tsens_priv *priv)
{
int base1 = 0, base2 = 0, i;
- u32 p1[11], p2[11];
+ u32 p1[MAX_NUM_SENSORS], p2[MAX_NUM_SENSORS];
int mode = 0;
u32 *calib, *bkp;
u32 calib_redun_sel;
@@ -324,7 +324,7 @@ static const struct tsens_features tsens_v0_1_feat = {
.crit_int = 0,
.adc = 1,
.srot_split = 1,
- .max_sensors = 11,
+ .max_sensors = MAX_NUM_SENSORS,
};
static const struct reg_field tsens_v0_1_regfields[MAX_REGFIELDS] = {
@@ -374,7 +374,7 @@ static const struct tsens_ops ops_8974 = {
};
const struct tsens_plat_data data_8974 = {
- .num_sensors = 11,
+ .num_sensors = MAX_NUM_SENSORS,
.ops = &ops_8974,
.feat = &tsens_v0_1_feat,
.fields = tsens_v0_1_regfields,
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 10b595d4f619..98acc9b64555 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -149,7 +149,7 @@ static const struct tsens_features tsens_v1_feat = {
.crit_int = 0,
.adc = 1,
.srot_split = 1,
- .max_sensors = 11,
+ .max_sensors = MAX_NUM_SENSORS,
};
static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index 2fd94997245b..d2d78c7e20c8 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -6,6 +6,7 @@
#ifndef __QCOM_TSENS_H__
#define __QCOM_TSENS_H__
+#define MAX_NUM_SENSORS 11
#define ONE_PT_CALIB 0x1
#define ONE_PT_CALIB2 0x2
#define TWO_PT_CALIB 0x3
--
2.31.1
next reply other threads:[~2022-07-12 17:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 17:31 Carlos Bilbao [this message]
2022-07-13 0:20 ` [PATCH] thermal/drivers/qcom: Code refactoring Konrad Dybcio
2022-07-13 4:30 ` Bjorn Andersson
2022-07-13 14:10 ` Carlos Bilbao
2022-07-13 19:47 ` Bjorn Andersson
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=20220712173127.3677491-1-carlos.bilbao@amd.com \
--to=carlos.bilbao@amd.com \
--cc=agross@kernel.org \
--cc=amitk@kernel.org \
--cc=bilbao@vt.edu \
--cc=david.brown@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=thara.gopinath@gmail.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