This patchset refactors the code of Qualcomm thermal drivers, with simpler
return values, logic for two functions, and a constant array for maximum
number of sensors per version.
Carlos Bilbao (4):
thermal/drivers/qcom: Simplify returns for tsens-8060.c
thermal/drivers/qcom: Simplify function code_to_degc()
thermal/drivers/qcom: Simplify function calibrate_8960()
thermal/drivers/qcom: Use array for max num sensors per version
---
drivers/thermal/qcom/tsens-8960.c | 33 ++++++++---------------------
drivers/thermal/qcom/tsens-common.c | 15 ++++++-------
drivers/thermal/qcom/tsens-v0_1.c | 4 ++--
drivers/thermal/qcom/tsens-v1.c | 2 +-
drivers/thermal/qcom/tsens-v2.c | 2 +-
drivers/thermal/qcom/tsens.h | 6 ++++++
6 files changed, 25 insertions(+), 37 deletions(-)
Simplify code_to_degc() so we don't need a third variable.
Signed-off-by: Carlos Bilbao <[email protected]>
---
drivers/thermal/qcom/tsens-common.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
index 528df8801254..492b0e9cc2a2 100644
--- a/drivers/thermal/qcom/tsens-common.c
+++ b/drivers/thermal/qcom/tsens-common.c
@@ -66,21 +66,18 @@ 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 num, den;
num = (adc_code * SLOPE_FACTOR) - s->offset;
den = s->slope;
+ if (!num)
+ return 0;
+
if (num > 0)
- degc = num + (den / 2);
- else if (num < 0)
- degc = num - (den / 2);
+ return (num + (den / 2)) / den;
else
- degc = num;
-
- degc /= den;
-
- return degc;
+ return (num - (den / 2)) / den;
}
int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp)
--
2.31.1
Use a constant array MAX_NUM_SENSORS[] for maximum number of sensors per
version (v0.1, v1, v2).
Signed-off-by: Carlos Bilbao <[email protected]>
---
drivers/thermal/qcom/tsens-8960.c | 2 +-
drivers/thermal/qcom/tsens-v0_1.c | 4 ++--
drivers/thermal/qcom/tsens-v1.c | 2 +-
drivers/thermal/qcom/tsens-v2.c | 2 +-
drivers/thermal/qcom/tsens.h | 6 ++++++
5 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
index b41ff164e67a..05db9bf0e2c6 100644
--- a/drivers/thermal/qcom/tsens-8960.c
+++ b/drivers/thermal/qcom/tsens-8960.c
@@ -263,6 +263,6 @@ static const struct tsens_ops ops_8960 = {
};
const struct tsens_plat_data data_8960 = {
- .num_sensors = 11,
+ .num_sensors = MAX_NUM_SENSORS[VER_0_1],
.ops = &ops_8960,
};
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 6f26fadf4c27..d29046cffc6b 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -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[VER_0_1],
};
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[VER_0_1],
.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..2007deb45723 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[VER_1_X],
};
static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c
index 0a4f2b8fcab6..002809e6a0b5 100644
--- a/drivers/thermal/qcom/tsens-v2.c
+++ b/drivers/thermal/qcom/tsens-v2.c
@@ -32,7 +32,7 @@ static const struct tsens_features tsens_v2_feat = {
.crit_int = 1,
.adc = 0,
.srot_split = 1,
- .max_sensors = 16,
+ .max_sensors = MAX_NUM_SENSORS[VER_2_X],
};
static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index 2fd94997245b..39645bbe9f95 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -26,6 +26,12 @@ enum tsens_ver {
VER_2_X,
};
+static const int MAX_NUM_SENSORS[] = {
+ [VER_0_1] = 11,
+ [VER_1_X] = 11,
+ [VER_2_X] = 16,
+};
+
/**
* struct tsens_sensor - data for each sensor connected to the tsens device
* @priv: tsens device instance that this sensor is connected to
--
2.31.1