summaryrefslogtreecommitdiffstats
path: root/drivers/thermal/qcom/tsens-common.c
diff options
context:
space:
mode:
authorAmit Kucheria <amit.kucheria@linaro.org>2019-03-20 18:47:57 +0530
committerEduardo Valentin <edubezval@gmail.com>2019-05-14 06:59:21 -0700
commitc8b6169093f66e9bae6eb5157ccc4ad426402caf (patch)
treea52a297a59b72ed5330673a74969454d8078d3b1 /drivers/thermal/qcom/tsens-common.c
parentdbdaa582e4ee38c9e2c2d500ebb102a350b7e1fc (diff)
downloadlinux-stable-c8b6169093f66e9bae6eb5157ccc4ad426402caf.tar.gz
linux-stable-c8b6169093f66e9bae6eb5157ccc4ad426402caf.tar.bz2
linux-stable-c8b6169093f66e9bae6eb5157ccc4ad426402caf.zip
drivers: thermal: tsens: Move get_temp_tsens_v2 to allow sharing
Just rename the function and move it to allow code sharing with future versions of TSENS IP Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal/qcom/tsens-common.c')
-rw-r--r--drivers/thermal/qcom/tsens-common.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
index 5607c5cc635c..5adbf1a2e0fb 100644
--- a/drivers/thermal/qcom/tsens-common.c
+++ b/drivers/thermal/qcom/tsens-common.c
@@ -102,6 +102,41 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s)
return degc;
}
+int get_temp_tsens_valid(struct tsens_priv *priv, int i, int *temp)
+{
+ struct tsens_sensor *s = &priv->sensor[i];
+ u32 temp_idx = LAST_TEMP_0 + s->hw_id;
+ u32 valid_idx = VALID_0 + s->hw_id;
+ u32 last_temp = 0, valid, mask;
+ int ret;
+
+ ret = regmap_field_read(priv->rf[valid_idx], &valid);
+ if (ret)
+ return ret;
+ while (!valid) {
+ /* Valid bit is 0 for 6 AHB clock cycles.
+ * At 19.2MHz, 1 AHB clock is ~60ns.
+ * We should enter this loop very, very rarely.
+ */
+ ndelay(400);
+ ret = regmap_field_read(priv->rf[valid_idx], &valid);
+ if (ret)
+ return ret;
+ }
+
+ /* Valid bit is set, OK to read the temperature */
+ ret = regmap_field_read(priv->rf[temp_idx], &last_temp);
+ if (ret)
+ return ret;
+
+ mask = GENMASK(priv->fields[LAST_TEMP_0].msb,
+ priv->fields[LAST_TEMP_0].lsb);
+ /* Convert temperature from deciCelsius to milliCelsius */
+ *temp = sign_extend32(last_temp, fls(mask) - 1) * 100;
+
+ return 0;
+}
+
int get_temp_common(struct tsens_priv *priv, int i, int *temp)
{
struct tsens_sensor *s = &priv->sensor[i];