2018-07-18 09:43:11 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-05-05 11:51:44 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
|
2018-07-18 09:43:11 +03:00
|
|
|
* Copyright (c) 2018, Linaro Limited
|
2016-05-05 11:51:44 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/regmap.h>
|
2018-07-26 13:33:10 +03:00
|
|
|
#include <linux/bitops.h>
|
2016-05-05 11:51:44 +03:00
|
|
|
#include "tsens.h"
|
|
|
|
|
2018-07-18 09:43:11 +03:00
|
|
|
#define STATUS_OFFSET 0xa0
|
|
|
|
#define LAST_TEMP_MASK 0xfff
|
2016-05-05 11:51:44 +03:00
|
|
|
#define STATUS_VALID_BIT BIT(21)
|
|
|
|
|
2018-07-18 09:43:11 +03:00
|
|
|
static int get_temp_tsens_v2(struct tsens_device *tmdev, int id, int *temp)
|
2016-05-05 11:51:44 +03:00
|
|
|
{
|
|
|
|
struct tsens_sensor *s = &tmdev->sensor[id];
|
|
|
|
u32 code;
|
2018-07-26 13:33:08 +03:00
|
|
|
unsigned int status_reg;
|
2018-07-26 13:33:10 +03:00
|
|
|
u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0;
|
|
|
|
int ret;
|
2016-05-05 11:51:44 +03:00
|
|
|
|
2018-07-26 13:33:08 +03:00
|
|
|
status_reg = tmdev->tm_offset + STATUS_OFFSET + s->hw_id * 4;
|
2018-09-12 12:52:49 +03:00
|
|
|
ret = regmap_read(tmdev->tm_map, status_reg, &code);
|
2016-05-05 11:51:44 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
last_temp = code & LAST_TEMP_MASK;
|
|
|
|
if (code & STATUS_VALID_BIT)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Try a second time */
|
2018-09-12 12:52:49 +03:00
|
|
|
ret = regmap_read(tmdev->tm_map, status_reg, &code);
|
2016-05-05 11:51:44 +03:00
|
|
|
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 */
|
2018-09-12 12:52:49 +03:00
|
|
|
ret = regmap_read(tmdev->tm_map, status_reg, &code);
|
2016-05-05 11:51:44 +03:00
|
|
|
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:
|
2018-07-26 13:33:10 +03:00
|
|
|
/* Convert temperature from deciCelsius to milliCelsius */
|
|
|
|
*temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100;
|
2016-05-05 11:51:44 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-18 09:43:11 +03:00
|
|
|
static const struct tsens_ops ops_generic_v2 = {
|
2016-05-05 11:51:44 +03:00
|
|
|
.init = init_common,
|
2018-07-18 09:43:11 +03:00
|
|
|
.get_temp = get_temp_tsens_v2,
|
2016-05-05 11:51:44 +03:00
|
|
|
};
|
|
|
|
|
2018-07-18 09:43:12 +03:00
|
|
|
const struct tsens_data data_tsens_v2 = {
|
|
|
|
.ops = &ops_generic_v2,
|
2018-09-12 12:52:52 +03:00
|
|
|
.reg_offsets = { [SROT_CTRL_OFFSET] = 0x4 },
|
2018-07-18 09:43:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Kept around for backward compatibility with old msm8996.dtsi */
|
2016-05-05 11:51:44 +03:00
|
|
|
const struct tsens_data data_8996 = {
|
|
|
|
.num_sensors = 13,
|
2018-07-18 09:43:11 +03:00
|
|
|
.ops = &ops_generic_v2,
|
2018-09-12 12:52:52 +03:00
|
|
|
.reg_offsets = { [SROT_CTRL_OFFSET] = 0x4 },
|
2016-05-05 11:51:44 +03:00
|
|
|
};
|