thermal: tsens: Rename tsens-8996 to tsens-v2 for reuse
authorAmit Kucheria <amit.kucheria@linaro.org>
Wed, 18 Jul 2018 06:43:11 +0000 (12:13 +0530)
committerEduardo Valentin <edubezval@gmail.com>
Fri, 27 Jul 2018 22:08:10 +0000 (15:08 -0700)
The TSENS block inside the 8996 is internally classified as version 2 of
the IP. Several other SoC families use this block and can share this code.

We rename get_temp() to reflect that it can be used across the v2 family.

Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Tested-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
drivers/thermal/qcom/Makefile
drivers/thermal/qcom/tsens-8996.c [deleted file]
drivers/thermal/qcom/tsens-v2.c [new file with mode: 0644]

index 2cc2193637e7f056c4fc446b9e3141409001d627..a821929ede0bd014c42437dd964605e06746fdf2 100644 (file)
@@ -1,2 +1,2 @@
 obj-$(CONFIG_QCOM_TSENS)       += qcom_tsens.o
-qcom_tsens-y                   += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o tsens-8996.o
+qcom_tsens-y                   += tsens.o tsens-common.o tsens-8916.o tsens-8974.o tsens-8960.o tsens-v2.o
diff --git a/drivers/thermal/qcom/tsens-8996.c b/drivers/thermal/qcom/tsens-8996.c
deleted file mode 100644 (file)
index 3e60cec..0000000
+++ /dev/null
@@ -1,84 +0,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.
- *
- */
-
-#include <linux/platform_device.h>
-#include <linux/regmap.h>
-#include "tsens.h"
-
-#define STATUS_OFFSET  0xa0
-#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 = tmdev->tm_offset + 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,
-};
-
-const struct tsens_data data_8996 = {
-       .num_sensors    = 13,
-       .ops            = &ops_8996,
-};
diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c
new file mode 100644 (file)
index 0000000..44d3736
--- /dev/null
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018, Linaro Limited
+ */
+
+#include <linux/regmap.h>
+#include "tsens.h"
+
+#define STATUS_OFFSET          0xa0
+#define LAST_TEMP_MASK         0xfff
+#define STATUS_VALID_BIT       BIT(21)
+#define CODE_SIGN_BIT          BIT(11)
+
+static 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 = tmdev->tm_offset + 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_generic_v2 = {
+       .init           = init_common,
+       .get_temp       = get_temp_tsens_v2,
+};
+
+const struct tsens_data data_8996 = {
+       .num_sensors    = 13,
+       .ops            = &ops_generic_v2,
+};