lkml.org 
[lkml]   [2022]   [Jul]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/4] thermal/drivers/qcom: Simplify function code_to_degc()
Date
Simplify code_to_degc() so we don't need a third variable.

Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
---
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
\
 
 \ /
  Last update: 2022-07-13 16:58    [W:0.064 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site