18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2015, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (c) 2018, Linaro Limited
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/bitops.h>
88c2ecf20Sopenharmony_ci#include <linux/regmap.h>
98c2ecf20Sopenharmony_ci#include "tsens.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* ----- SROT ------ */
128c2ecf20Sopenharmony_ci#define SROT_HW_VER_OFF	0x0000
138c2ecf20Sopenharmony_ci#define SROT_CTRL_OFF		0x0004
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* ----- TM ------ */
168c2ecf20Sopenharmony_ci#define TM_INT_EN_OFF			0x0004
178c2ecf20Sopenharmony_ci#define TM_UPPER_LOWER_INT_STATUS_OFF	0x0008
188c2ecf20Sopenharmony_ci#define TM_UPPER_LOWER_INT_CLEAR_OFF	0x000c
198c2ecf20Sopenharmony_ci#define TM_UPPER_LOWER_INT_MASK_OFF	0x0010
208c2ecf20Sopenharmony_ci#define TM_CRITICAL_INT_STATUS_OFF	0x0014
218c2ecf20Sopenharmony_ci#define TM_CRITICAL_INT_CLEAR_OFF	0x0018
228c2ecf20Sopenharmony_ci#define TM_CRITICAL_INT_MASK_OFF	0x001c
238c2ecf20Sopenharmony_ci#define TM_Sn_UPPER_LOWER_THRESHOLD_OFF 0x0020
248c2ecf20Sopenharmony_ci#define TM_Sn_CRITICAL_THRESHOLD_OFF	0x0060
258c2ecf20Sopenharmony_ci#define TM_Sn_STATUS_OFF		0x00a0
268c2ecf20Sopenharmony_ci#define TM_TRDY_OFF			0x00e4
278c2ecf20Sopenharmony_ci#define TM_WDOG_LOG_OFF		0x013c
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* v2.x: 8996, 8998, sdm845 */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic struct tsens_features tsens_v2_feat = {
328c2ecf20Sopenharmony_ci	.ver_major	= VER_2_X,
338c2ecf20Sopenharmony_ci	.crit_int	= 1,
348c2ecf20Sopenharmony_ci	.adc		= 0,
358c2ecf20Sopenharmony_ci	.srot_split	= 1,
368c2ecf20Sopenharmony_ci	.max_sensors	= 16,
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
408c2ecf20Sopenharmony_ci	/* ----- SROT ------ */
418c2ecf20Sopenharmony_ci	/* VERSION */
428c2ecf20Sopenharmony_ci	[VER_MAJOR] = REG_FIELD(SROT_HW_VER_OFF, 28, 31),
438c2ecf20Sopenharmony_ci	[VER_MINOR] = REG_FIELD(SROT_HW_VER_OFF, 16, 27),
448c2ecf20Sopenharmony_ci	[VER_STEP]  = REG_FIELD(SROT_HW_VER_OFF,  0, 15),
458c2ecf20Sopenharmony_ci	/* CTRL_OFF */
468c2ecf20Sopenharmony_ci	[TSENS_EN]     = REG_FIELD(SROT_CTRL_OFF,    0,  0),
478c2ecf20Sopenharmony_ci	[TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF,    1,  1),
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	/* ----- TM ------ */
508c2ecf20Sopenharmony_ci	/* INTERRUPT ENABLE */
518c2ecf20Sopenharmony_ci	/* v2 has separate enables for UPPER/LOWER/CRITICAL interrupts */
528c2ecf20Sopenharmony_ci	[INT_EN]  = REG_FIELD(TM_INT_EN_OFF, 0, 2),
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	/* TEMPERATURE THRESHOLDS */
558c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(LOW_THRESH,  TM_Sn_UPPER_LOWER_THRESHOLD_OFF,  0,  11),
568c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(UP_THRESH,   TM_Sn_UPPER_LOWER_THRESHOLD_OFF, 12,  23),
578c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(CRIT_THRESH, TM_Sn_CRITICAL_THRESHOLD_OFF,     0,  11),
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	/* INTERRUPTS [CLEAR/STATUS/MASK] */
608c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_0_15(LOW_INT_STATUS,  TM_UPPER_LOWER_INT_STATUS_OFF),
618c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_0_15(LOW_INT_CLEAR,   TM_UPPER_LOWER_INT_CLEAR_OFF),
628c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_0_15(LOW_INT_MASK,    TM_UPPER_LOWER_INT_MASK_OFF),
638c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_16_31(UP_INT_STATUS,  TM_UPPER_LOWER_INT_STATUS_OFF),
648c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_16_31(UP_INT_CLEAR,   TM_UPPER_LOWER_INT_CLEAR_OFF),
658c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_16_31(UP_INT_MASK,    TM_UPPER_LOWER_INT_MASK_OFF),
668c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_0_15(CRIT_INT_STATUS, TM_CRITICAL_INT_STATUS_OFF),
678c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_0_15(CRIT_INT_CLEAR,  TM_CRITICAL_INT_CLEAR_OFF),
688c2ecf20Sopenharmony_ci	REG_FIELD_SPLIT_BITS_0_15(CRIT_INT_MASK,   TM_CRITICAL_INT_MASK_OFF),
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* WATCHDOG on v2.3 or later */
718c2ecf20Sopenharmony_ci	[WDOG_BARK_STATUS] = REG_FIELD(TM_CRITICAL_INT_STATUS_OFF, 31, 31),
728c2ecf20Sopenharmony_ci	[WDOG_BARK_CLEAR]  = REG_FIELD(TM_CRITICAL_INT_CLEAR_OFF,  31, 31),
738c2ecf20Sopenharmony_ci	[WDOG_BARK_MASK]   = REG_FIELD(TM_CRITICAL_INT_MASK_OFF,   31, 31),
748c2ecf20Sopenharmony_ci	[CC_MON_STATUS]    = REG_FIELD(TM_CRITICAL_INT_STATUS_OFF, 30, 30),
758c2ecf20Sopenharmony_ci	[CC_MON_CLEAR]     = REG_FIELD(TM_CRITICAL_INT_CLEAR_OFF,  30, 30),
768c2ecf20Sopenharmony_ci	[CC_MON_MASK]      = REG_FIELD(TM_CRITICAL_INT_MASK_OFF,   30, 30),
778c2ecf20Sopenharmony_ci	[WDOG_BARK_COUNT]  = REG_FIELD(TM_WDOG_LOG_OFF,             0,  7),
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	/* Sn_STATUS */
808c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(LAST_TEMP,       TM_Sn_STATUS_OFF,  0,  11),
818c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(VALID,           TM_Sn_STATUS_OFF, 21,  21),
828c2ecf20Sopenharmony_ci	/* xxx_STATUS bits: 1 == threshold violated */
838c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(MIN_STATUS,      TM_Sn_STATUS_OFF, 16,  16),
848c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(LOWER_STATUS,    TM_Sn_STATUS_OFF, 17,  17),
858c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(UPPER_STATUS,    TM_Sn_STATUS_OFF, 18,  18),
868c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(CRITICAL_STATUS, TM_Sn_STATUS_OFF, 19,  19),
878c2ecf20Sopenharmony_ci	REG_FIELD_FOR_EACH_SENSOR16(MAX_STATUS,      TM_Sn_STATUS_OFF, 20,  20),
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	/* TRDY: 1=ready, 0=in progress */
908c2ecf20Sopenharmony_ci	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic const struct tsens_ops ops_generic_v2 = {
948c2ecf20Sopenharmony_ci	.init		= init_common,
958c2ecf20Sopenharmony_ci	.get_temp	= get_temp_tsens_valid,
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistruct tsens_plat_data data_tsens_v2 = {
998c2ecf20Sopenharmony_ci	.ops		= &ops_generic_v2,
1008c2ecf20Sopenharmony_ci	.feat		= &tsens_v2_feat,
1018c2ecf20Sopenharmony_ci	.fields	= tsens_v2_regfields,
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* Kept around for backward compatibility with old msm8996.dtsi */
1058c2ecf20Sopenharmony_cistruct tsens_plat_data data_8996 = {
1068c2ecf20Sopenharmony_ci	.num_sensors	= 13,
1078c2ecf20Sopenharmony_ci	.ops		= &ops_generic_v2,
1088c2ecf20Sopenharmony_ci	.feat		= &tsens_v2_feat,
1098c2ecf20Sopenharmony_ci	.fields	= tsens_v2_regfields,
1108c2ecf20Sopenharmony_ci};
111