2018-07-18 14:43:11 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-05-05 16:51:44 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
|
2018-07-18 14:43:11 +08:00
|
|
|
* Copyright (c) 2018, Linaro Limited
|
2016-05-05 16:51:44 +08:00
|
|
|
*/
|
|
|
|
|
2018-07-26 18:33:10 +08:00
|
|
|
#include <linux/bitops.h>
|
2019-03-20 21:17:50 +08:00
|
|
|
#include <linux/regmap.h>
|
2016-05-05 16:51:44 +08:00
|
|
|
#include "tsens.h"
|
|
|
|
|
2019-03-20 21:17:50 +08:00
|
|
|
/* ----- SROT ------ */
|
|
|
|
#define SROT_HW_VER_OFF 0x0000
|
|
|
|
#define SROT_CTRL_OFF 0x0004
|
|
|
|
|
|
|
|
/* ----- TM ------ */
|
|
|
|
#define TM_INT_EN_OFF 0x0004
|
|
|
|
#define TM_UPPER_LOWER_INT_STATUS_OFF 0x0008
|
|
|
|
#define TM_UPPER_LOWER_INT_CLEAR_OFF 0x000c
|
|
|
|
#define TM_UPPER_LOWER_INT_MASK_OFF 0x0010
|
|
|
|
#define TM_CRITICAL_INT_STATUS_OFF 0x0014
|
|
|
|
#define TM_CRITICAL_INT_CLEAR_OFF 0x0018
|
|
|
|
#define TM_CRITICAL_INT_MASK_OFF 0x001c
|
|
|
|
#define TM_Sn_UPPER_LOWER_THRESHOLD_OFF 0x0020
|
|
|
|
#define TM_Sn_CRITICAL_THRESHOLD_OFF 0x0060
|
|
|
|
#define TM_Sn_STATUS_OFF 0x00a0
|
|
|
|
#define TM_TRDY_OFF 0x00e4
|
|
|
|
|
2018-07-18 14:43:11 +08:00
|
|
|
#define LAST_TEMP_MASK 0xfff
|
2016-05-05 16:51:44 +08:00
|
|
|
|
2019-03-20 21:17:44 +08:00
|
|
|
static int get_temp_tsens_v2(struct tsens_priv *priv, int id, int *temp)
|
2016-05-05 16:51:44 +08:00
|
|
|
{
|
2019-03-20 21:17:44 +08:00
|
|
|
struct tsens_sensor *s = &priv->sensor[id];
|
2019-03-20 21:17:50 +08:00
|
|
|
u32 temp_idx = LAST_TEMP_0 + s->hw_id;
|
|
|
|
u32 valid_idx = VALID_0 + s->hw_id;
|
|
|
|
u32 last_temp = 0, last_temp2 = 0, last_temp3 = 0, valid;
|
2018-07-26 18:33:10 +08:00
|
|
|
int ret;
|
2016-05-05 16:51:44 +08:00
|
|
|
|
2019-03-20 21:17:50 +08:00
|
|
|
ret = regmap_field_read(priv->rf[temp_idx], &last_temp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = regmap_field_read(priv->rf[valid_idx], &valid);
|
2016-05-05 16:51:44 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-03-20 21:17:50 +08:00
|
|
|
|
|
|
|
if (valid)
|
2016-05-05 16:51:44 +08:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Try a second time */
|
2019-03-20 21:17:50 +08:00
|
|
|
ret = regmap_field_read(priv->rf[valid_idx], &valid);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = regmap_field_read(priv->rf[temp_idx], &last_temp2);
|
2016-05-05 16:51:44 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-03-20 21:17:50 +08:00
|
|
|
if (valid) {
|
|
|
|
last_temp = last_temp2;
|
2016-05-05 16:51:44 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try a third/last time */
|
2019-03-20 21:17:50 +08:00
|
|
|
ret = regmap_field_read(priv->rf[valid_idx], &valid);
|
2016-05-05 16:51:44 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-03-20 21:17:50 +08:00
|
|
|
ret = regmap_field_read(priv->rf[temp_idx], &last_temp3);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
if (valid) {
|
|
|
|
last_temp = last_temp3;
|
2016-05-05 16:51:44 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_temp == last_temp2)
|
|
|
|
last_temp = last_temp2;
|
|
|
|
else if (last_temp2 == last_temp3)
|
|
|
|
last_temp = last_temp3;
|
|
|
|
done:
|
2018-07-26 18:33:10 +08:00
|
|
|
/* Convert temperature from deciCelsius to milliCelsius */
|
|
|
|
*temp = sign_extend32(last_temp, fls(LAST_TEMP_MASK) - 1) * 100;
|
2016-05-05 16:51:44 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-20 21:17:50 +08:00
|
|
|
/* v2.x: 8996, 8998, sdm845 */
|
|
|
|
|
|
|
|
static const struct tsens_features tsens_v2_feat = {
|
|
|
|
.ver_major = VER_2_X,
|
|
|
|
.crit_int = 1,
|
|
|
|
.adc = 0,
|
|
|
|
.srot_split = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
|
|
|
|
/* ----- SROT ------ */
|
|
|
|
/* VERSION */
|
|
|
|
[VER_MAJOR] = REG_FIELD(SROT_HW_VER_OFF, 28, 31),
|
|
|
|
[VER_MINOR] = REG_FIELD(SROT_HW_VER_OFF, 16, 27),
|
|
|
|
[VER_STEP] = REG_FIELD(SROT_HW_VER_OFF, 0, 15),
|
|
|
|
/* CTRL_OFF */
|
|
|
|
[TSENS_EN] = REG_FIELD(SROT_CTRL_OFF, 0, 0),
|
|
|
|
[TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF, 1, 1),
|
2019-03-20 21:17:53 +08:00
|
|
|
[SENSOR_EN] = REG_FIELD(SROT_CTRL_OFF, 3, 18),
|
2019-03-20 21:17:50 +08:00
|
|
|
|
|
|
|
/* ----- TM ------ */
|
|
|
|
/* INTERRUPT ENABLE */
|
|
|
|
/* v2 has separate enables for UPPER/LOWER/CRITICAL interrupts */
|
|
|
|
[INT_EN] = REG_FIELD(TM_INT_EN_OFF, 0, 2),
|
|
|
|
|
|
|
|
/* Sn_STATUS */
|
|
|
|
REG_FIELD_FOR_EACH_SENSOR16(LAST_TEMP, TM_Sn_STATUS_OFF, 0, 11),
|
|
|
|
REG_FIELD_FOR_EACH_SENSOR16(VALID, TM_Sn_STATUS_OFF, 21, 21),
|
|
|
|
REG_FIELD_FOR_EACH_SENSOR16(MIN_STATUS, TM_Sn_STATUS_OFF, 16, 16),
|
|
|
|
REG_FIELD_FOR_EACH_SENSOR16(LOWER_STATUS, TM_Sn_STATUS_OFF, 17, 17),
|
|
|
|
REG_FIELD_FOR_EACH_SENSOR16(UPPER_STATUS, TM_Sn_STATUS_OFF, 18, 18),
|
|
|
|
REG_FIELD_FOR_EACH_SENSOR16(CRITICAL_STATUS, TM_Sn_STATUS_OFF, 19, 19),
|
|
|
|
REG_FIELD_FOR_EACH_SENSOR16(MAX_STATUS, TM_Sn_STATUS_OFF, 20, 20),
|
|
|
|
|
|
|
|
/* TRDY: 1=ready, 0=in progress */
|
|
|
|
[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
|
|
|
|
};
|
|
|
|
|
2018-07-18 14:43:11 +08:00
|
|
|
static const struct tsens_ops ops_generic_v2 = {
|
2016-05-05 16:51:44 +08:00
|
|
|
.init = init_common,
|
2018-07-18 14:43:11 +08:00
|
|
|
.get_temp = get_temp_tsens_v2,
|
2016-05-05 16:51:44 +08:00
|
|
|
};
|
|
|
|
|
2019-03-20 21:17:42 +08:00
|
|
|
const struct tsens_plat_data data_tsens_v2 = {
|
2019-03-20 21:17:50 +08:00
|
|
|
.ops = &ops_generic_v2,
|
|
|
|
.feat = &tsens_v2_feat,
|
|
|
|
.fields = tsens_v2_regfields,
|
2018-07-18 14:43:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Kept around for backward compatibility with old msm8996.dtsi */
|
2019-03-20 21:17:42 +08:00
|
|
|
const struct tsens_plat_data data_8996 = {
|
2016-05-05 16:51:44 +08:00
|
|
|
.num_sensors = 13,
|
2018-07-18 14:43:11 +08:00
|
|
|
.ops = &ops_generic_v2,
|
2019-03-20 21:17:50 +08:00
|
|
|
.feat = &tsens_v2_feat,
|
|
|
|
.fields = tsens_v2_regfields,
|
2016-05-05 16:51:44 +08:00
|
|
|
};
|