diff mbox

[v2,3/5] thermal: tsens: Move 8996 get_temp() to common code for reuse

Message ID ed6b51a1b08e195968f5423a86e40146279a8807.1528799892.git.amit.kucheria@linaro.org (mailing list archive)
State Superseded, archived
Delegated to: Andy Gross
Headers show

Commit Message

Amit Kucheria June 12, 2018, 10:54 a.m. UTC
The TSENS block inside the 8996 is internally classified as version 2.
Several other SoC families use this block and can share this code. Rename
get_temp() to reflect that it can be used across the v2 family.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
---
 drivers/thermal/qcom/tsens-8996.c   | 73 ++-----------------------------------
 drivers/thermal/qcom/tsens-common.c | 69 ++++++++++++++++++++++++++++++-----
 drivers/thermal/qcom/tsens.h        |  1 +
 3 files changed, 63 insertions(+), 80 deletions(-)

Comments

Bjorn Andersson June 12, 2018, 7:43 p.m. UTC | #1
On Tue 12 Jun 03:54 PDT 2018, Amit Kucheria wrote:
> diff --git a/drivers/thermal/qcom/tsens-8996.c b/drivers/thermal/qcom/tsens-8996.c
[..]
>  static const struct tsens_ops ops_8996 = {
>  	.init		= init_common,
> -	.get_temp	= get_temp_8996,
> +	.get_temp	= get_temp_tsens_v2,
>  };
>  
>  const struct tsens_data data_8996 = {
> diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
[..]
> +int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp)

I like the function name, but it's not really common for tsens, it's
just common for tsens v2. Also as patch 4 shows we end up adding a set
of essentially empty platform specific files for referencing this
function.

I would suggest that you instead rename tsens-8996.c to tsens-v2.c,
rename ops_8996 to ops_v2 and either add new tsens_data for each
platform or simply rename that too to data_v2 which we point to from
tsens_table.


I think we should take it once step further and add "qcom,tsens-v2" as a
valid compatible in tsens_table and make the dts do:

	comaptible = "qcom,msm8996-tsens", "qcom,tsens-v2";

and
	compatible = "qcom,sdm845-tsens", "qcom,tsens-v2";

Regards,
Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Amit Kucheria June 12, 2018, 8:55 p.m. UTC | #2
On Tue, Jun 12, 2018 at 10:43 PM Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
>
> On Tue 12 Jun 03:54 PDT 2018, Amit Kucheria wrote:
> > diff --git a/drivers/thermal/qcom/tsens-8996.c b/drivers/thermal/qcom/tsens-8996.c
> [..]
> >  static const struct tsens_ops ops_8996 = {
> >       .init           = init_common,
> > -     .get_temp       = get_temp_8996,
> > +     .get_temp       = get_temp_tsens_v2,
> >  };
> >
> >  const struct tsens_data data_8996 = {
> > diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
> [..]
> > +int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp)
>
> I like the function name, but it's not really common for tsens, it's
> just common for tsens v2. Also as patch 4 shows we end up adding a set
> of essentially empty platform specific files for referencing this
> function.

> I would suggest that you instead rename tsens-8996.c to tsens-v2.c,
> rename ops_8996 to ops_v2 and either add new tsens_data for each
> platform or simply rename that too to data_v2 which we point to from
> tsens_table.

I was thinking of tsens-common.c as a library of tsens functions (v1
and v2). Do you want tsens-common.c to essentially become tsens-v1.c?
We'll end up with quite a bit of duplicated code in that case.

IIUC what you are suggesting, we'll still need to compile in
tsens-common.c even on v2 platforms.

> I think we should take it once step further and add "qcom,tsens-v2" as a
> valid compatible in tsens_table and make the dts do:

I like that idea.

>         comaptible = "qcom,msm8996-tsens", "qcom,tsens-v2";
>
> and
>         compatible = "qcom,sdm845-tsens", "qcom,tsens-v2";
>
> Regards,
> Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/thermal/qcom/tsens-8996.c b/drivers/thermal/qcom/tsens-8996.c
index 6e59078..a0d9096 100644
--- a/drivers/thermal/qcom/tsens-8996.c
+++ b/drivers/thermal/qcom/tsens-8996.c
@@ -1,81 +1,14 @@ 
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
+ * Copyright (c) 2018, Linaro Limited
  */
 
-#include <linux/platform_device.h>
-#include <linux/regmap.h>
 #include "tsens.h"
 
-#define STATUS_OFFSET	0x10a0
-#define LAST_TEMP_MASK	0xfff
-#define STATUS_VALID_BIT	BIT(21)
-#define CODE_SIGN_BIT		BIT(11)
-
-static int get_temp_8996(struct tsens_device *tmdev, int id, int *temp)
-{
-	struct tsens_sensor *s = &tmdev->sensor[id];
-	u32 code;
-	unsigned int sensor_addr;
-	int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret;
-
-	sensor_addr = STATUS_OFFSET + s->hw_id * 4;
-	ret = regmap_read(tmdev->map, sensor_addr, &code);
-	if (ret)
-		return ret;
-	last_temp = code & LAST_TEMP_MASK;
-	if (code & STATUS_VALID_BIT)
-		goto done;
-
-	/* Try a second time */
-	ret = regmap_read(tmdev->map, sensor_addr, &code);
-	if (ret)
-		return ret;
-	if (code & STATUS_VALID_BIT) {
-		last_temp = code & LAST_TEMP_MASK;
-		goto done;
-	} else {
-		last_temp2 = code & LAST_TEMP_MASK;
-	}
-
-	/* Try a third/last time */
-	ret = regmap_read(tmdev->map, sensor_addr, &code);
-	if (ret)
-		return ret;
-	if (code & STATUS_VALID_BIT) {
-		last_temp = code & LAST_TEMP_MASK;
-		goto done;
-	} else {
-		last_temp3 = code & LAST_TEMP_MASK;
-	}
-
-	if (last_temp == last_temp2)
-		last_temp = last_temp2;
-	else if (last_temp2 == last_temp3)
-		last_temp = last_temp3;
-done:
-	/* Code sign bit is the sign extension for a negative value */
-	if (last_temp & CODE_SIGN_BIT)
-		last_temp |= ~CODE_SIGN_BIT;
-
-	/* Temperatures are in deciCelicius */
-	*temp = last_temp * 100;
-
-	return 0;
-}
-
 static const struct tsens_ops ops_8996 = {
 	.init		= init_common,
-	.get_temp	= get_temp_8996,
+	.get_temp	= get_temp_tsens_v2,
 };
 
 const struct tsens_data data_8996 = {
diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
index b1449ad..961ace4 100644
--- a/drivers/thermal/qcom/tsens-common.c
+++ b/drivers/thermal/qcom/tsens-common.c
@@ -1,15 +1,7 @@ 
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
+ * Copyright (c) 2018, Linaro Limited
  */
 
 #include <linux/err.h>
@@ -117,6 +109,63 @@  int get_temp_common(struct tsens_device *tmdev, int id, int *temp)
 	return 0;
 }
 
+#define STATUS_OFFSET		0xa0
+#define LAST_TEMP_MASK		0xfff
+#define STATUS_VALID_BIT	BIT(21)
+#define CODE_SIGN_BIT		BIT(11)
+
+int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp)
+{
+	struct tsens_sensor *s = &tmdev->sensor[id];
+	u32 code;
+	unsigned int sensor_addr;
+	int last_temp = 0, last_temp2 = 0, last_temp3 = 0, ret;
+
+	sensor_addr = STATUS_OFFSET + s->hw_id * 4;
+	ret = regmap_read(tmdev->map, sensor_addr, &code);
+	if (ret)
+		return ret;
+	last_temp = code & LAST_TEMP_MASK;
+	if (code & STATUS_VALID_BIT)
+		goto done;
+
+	/* Try a second time */
+	ret = regmap_read(tmdev->map, sensor_addr, &code);
+	if (ret)
+		return ret;
+	if (code & STATUS_VALID_BIT) {
+		last_temp = code & LAST_TEMP_MASK;
+		goto done;
+	} else {
+		last_temp2 = code & LAST_TEMP_MASK;
+	}
+
+	/* Try a third/last time */
+	ret = regmap_read(tmdev->map, sensor_addr, &code);
+	if (ret)
+		return ret;
+	if (code & STATUS_VALID_BIT) {
+		last_temp = code & LAST_TEMP_MASK;
+		goto done;
+	} else {
+		last_temp3 = code & LAST_TEMP_MASK;
+	}
+
+	if (last_temp == last_temp2)
+		last_temp = last_temp2;
+	else if (last_temp2 == last_temp3)
+		last_temp = last_temp3;
+done:
+	/* Code sign bit is the sign extension for a negative value */
+	if (last_temp & CODE_SIGN_BIT)
+		last_temp |= ~CODE_SIGN_BIT;
+
+	/* Temperatures are in deciCelicius */
+	*temp = last_temp * 100;
+
+	return 0;
+}
+
 static const struct regmap_config tsens_config = {
 	.reg_bits	= 32,
 	.val_bits	= 32,
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index dc56e1e..80b273d 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -86,6 +86,7 @@  char *qfprom_read(struct device *, const char *);
 void compute_intercept_slope(struct tsens_device *, u32 *, u32 *, u32);
 int init_common(struct tsens_device *);
 int get_temp_common(struct tsens_device *, int, int *);
+int get_temp_tsens_v2(struct tsens_device *, int, int *);
 
 extern const struct tsens_data data_8916, data_8974, data_8960, data_8996;