linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] thermal/drivers/qcom: Code refactoring
@ 2022-07-13 14:56 Carlos Bilbao
  2022-07-13 14:56 ` [PATCH 1/4] thermal/drivers/qcom: Simplify returns for tsens-8060.c Carlos Bilbao
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Carlos Bilbao @ 2022-07-13 14:56 UTC (permalink / raw)
  To: bjorn.andersson, amitk, thara.gopinath, konrad.dybcio
  Cc: agross, david.brown, linux-pm, linux-arm-msm, linux-kernel,
	bilbao, Carlos Bilbao

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(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] thermal/drivers/qcom: Simplify returns for tsens-8060.c
  2022-07-13 14:56 [PATCH 0/4] thermal/drivers/qcom: Code refactoring Carlos Bilbao
@ 2022-07-13 14:56 ` Carlos Bilbao
  2022-07-13 14:56 ` [PATCH 2/4] thermal/drivers/qcom: Simplify function code_to_degc() Carlos Bilbao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Carlos Bilbao @ 2022-07-13 14:56 UTC (permalink / raw)
  To: bjorn.andersson, amitk, thara.gopinath, konrad.dybcio
  Cc: agross, david.brown, linux-pm, linux-arm-msm, linux-kernel,
	bilbao, Carlos Bilbao

Simplify return logic in file tsens-8060.c.

Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
---
 drivers/thermal/qcom/tsens-8960.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
index 8d9b721dadb6..f4fc8a1c161e 100644
--- a/drivers/thermal/qcom/tsens-8960.c
+++ b/drivers/thermal/qcom/tsens-8960.c
@@ -75,11 +75,7 @@ static int suspend_8960(struct tsens_priv *priv)
 	else
 		mask = SLP_CLK_ENA_8660 | EN;
 
-	ret = regmap_update_bits(map, CNTL_ADDR, mask, 0);
-	if (ret)
-		return ret;
-
-	return 0;
+	return regmap_update_bits(map, CNTL_ADDR, mask, 0);
 }
 
 static int resume_8960(struct tsens_priv *priv)
@@ -105,11 +101,7 @@ static int resume_8960(struct tsens_priv *priv)
 	if (ret)
 		return ret;
 
-	ret = regmap_write(map, CNTL_ADDR, priv->ctx.control);
-	if (ret)
-		return ret;
-
-	return 0;
+	return regmap_write(map, CNTL_ADDR, priv->ctx.control);
 }
 
 static int enable_8960(struct tsens_priv *priv, int id)
@@ -131,11 +123,7 @@ static int enable_8960(struct tsens_priv *priv, int id)
 	else
 		reg |= mask | SLP_CLK_ENA_8660 | EN;
 
-	ret = regmap_write(priv->tm_map, CNTL_ADDR, reg);
-	if (ret)
-		return ret;
-
-	return 0;
+	return regmap_write(priv->tm_map, CNTL_ADDR, reg);
 }
 
 static void disable_8960(struct tsens_priv *priv)
@@ -205,11 +193,7 @@ static int init_8960(struct tsens_priv *priv)
 		return ret;
 
 	reg_cntl |= EN;
-	ret = regmap_write(priv->tm_map, CNTL_ADDR, reg_cntl);
-	if (ret)
-		return ret;
-
-	return 0;
+	return regmap_write(priv->tm_map, CNTL_ADDR, reg_cntl);
 }
 
 static int calibrate_8960(struct tsens_priv *priv)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] thermal/drivers/qcom: Simplify function code_to_degc()
  2022-07-13 14:56 [PATCH 0/4] thermal/drivers/qcom: Code refactoring Carlos Bilbao
  2022-07-13 14:56 ` [PATCH 1/4] thermal/drivers/qcom: Simplify returns for tsens-8060.c Carlos Bilbao
@ 2022-07-13 14:56 ` Carlos Bilbao
  2022-07-13 14:56 ` [PATCH 3/4] thermal/drivers/qcom: Simplify function calibrate_8960() Carlos Bilbao
  2022-07-13 14:57 ` [PATCH 4/4] thermal/drivers/qcom: Use array for max num sensors per version Carlos Bilbao
  3 siblings, 0 replies; 5+ messages in thread
From: Carlos Bilbao @ 2022-07-13 14:56 UTC (permalink / raw)
  To: bjorn.andersson, amitk, thara.gopinath, konrad.dybcio
  Cc: agross, david.brown, linux-pm, linux-arm-msm, linux-kernel,
	bilbao, Carlos Bilbao

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] thermal/drivers/qcom: Simplify function calibrate_8960()
  2022-07-13 14:56 [PATCH 0/4] thermal/drivers/qcom: Code refactoring Carlos Bilbao
  2022-07-13 14:56 ` [PATCH 1/4] thermal/drivers/qcom: Simplify returns for tsens-8060.c Carlos Bilbao
  2022-07-13 14:56 ` [PATCH 2/4] thermal/drivers/qcom: Simplify function code_to_degc() Carlos Bilbao
@ 2022-07-13 14:56 ` Carlos Bilbao
  2022-07-13 14:57 ` [PATCH 4/4] thermal/drivers/qcom: Use array for max num sensors per version Carlos Bilbao
  3 siblings, 0 replies; 5+ messages in thread
From: Carlos Bilbao @ 2022-07-13 14:56 UTC (permalink / raw)
  To: bjorn.andersson, amitk, thara.gopinath, konrad.dybcio
  Cc: agross, david.brown, linux-pm, linux-arm-msm, linux-kernel,
	bilbao, Carlos Bilbao

Simply function calibrate_8960() so a second check to IS_ERR(data) may be
avoided.

Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
---
 drivers/thermal/qcom/tsens-8960.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
index f4fc8a1c161e..b41ff164e67a 100644
--- a/drivers/thermal/qcom/tsens-8960.c
+++ b/drivers/thermal/qcom/tsens-8960.c
@@ -205,10 +205,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];
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] thermal/drivers/qcom: Use array for max num sensors per version
  2022-07-13 14:56 [PATCH 0/4] thermal/drivers/qcom: Code refactoring Carlos Bilbao
                   ` (2 preceding siblings ...)
  2022-07-13 14:56 ` [PATCH 3/4] thermal/drivers/qcom: Simplify function calibrate_8960() Carlos Bilbao
@ 2022-07-13 14:57 ` Carlos Bilbao
  3 siblings, 0 replies; 5+ messages in thread
From: Carlos Bilbao @ 2022-07-13 14:57 UTC (permalink / raw)
  To: bjorn.andersson, amitk, thara.gopinath, konrad.dybcio
  Cc: agross, david.brown, linux-pm, linux-arm-msm, linux-kernel,
	bilbao, Carlos Bilbao

Use a constant array MAX_NUM_SENSORS[] for maximum number of sensors per
version (v0.1, v1, v2).

Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-13 14:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-13 14:56 [PATCH 0/4] thermal/drivers/qcom: Code refactoring Carlos Bilbao
2022-07-13 14:56 ` [PATCH 1/4] thermal/drivers/qcom: Simplify returns for tsens-8060.c Carlos Bilbao
2022-07-13 14:56 ` [PATCH 2/4] thermal/drivers/qcom: Simplify function code_to_degc() Carlos Bilbao
2022-07-13 14:56 ` [PATCH 3/4] thermal/drivers/qcom: Simplify function calibrate_8960() Carlos Bilbao
2022-07-13 14:57 ` [PATCH 4/4] thermal/drivers/qcom: Use array for max num sensors per version Carlos Bilbao

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).