1770324a4SAmit Kucheria // SPDX-License-Identifier: GPL-2.0 2770324a4SAmit Kucheria /* 3770324a4SAmit Kucheria * Copyright (c) 2015, The Linux Foundation. All rights reserved. 4770324a4SAmit Kucheria * Copyright (c) 2018, Linaro Limited 5770324a4SAmit Kucheria */ 6770324a4SAmit Kucheria 7432121adSAmit Kucheria #include <linux/bitops.h> 8c1997054SAmit Kucheria #include <linux/regmap.h> 9770324a4SAmit Kucheria #include "tsens.h" 10770324a4SAmit Kucheria 11c1997054SAmit Kucheria /* ----- SROT ------ */ 12c1997054SAmit Kucheria #define SROT_HW_VER_OFF 0x0000 13c1997054SAmit Kucheria #define SROT_CTRL_OFF 0x0004 14c1997054SAmit Kucheria 15c1997054SAmit Kucheria /* ----- TM ------ */ 16c1997054SAmit Kucheria #define TM_INT_EN_OFF 0x0004 17c1997054SAmit Kucheria #define TM_UPPER_LOWER_INT_STATUS_OFF 0x0008 18c1997054SAmit Kucheria #define TM_UPPER_LOWER_INT_CLEAR_OFF 0x000c 19c1997054SAmit Kucheria #define TM_UPPER_LOWER_INT_MASK_OFF 0x0010 20c1997054SAmit Kucheria #define TM_CRITICAL_INT_STATUS_OFF 0x0014 21c1997054SAmit Kucheria #define TM_CRITICAL_INT_CLEAR_OFF 0x0018 22c1997054SAmit Kucheria #define TM_CRITICAL_INT_MASK_OFF 0x001c 23c1997054SAmit Kucheria #define TM_Sn_UPPER_LOWER_THRESHOLD_OFF 0x0020 24c1997054SAmit Kucheria #define TM_Sn_CRITICAL_THRESHOLD_OFF 0x0060 25c1997054SAmit Kucheria #define TM_Sn_STATUS_OFF 0x00a0 26c1997054SAmit Kucheria #define TM_TRDY_OFF 0x00e4 27d22066c1SAmit Kucheria #define TM_WDOG_LOG_OFF 0x013c 28c1997054SAmit Kucheria 29c1997054SAmit Kucheria /* v2.x: 8996, 8998, sdm845 */ 30c1997054SAmit Kucheria 310aef1ee5SAmit Kucheria static struct tsens_features tsens_v2_feat = { 32c1997054SAmit Kucheria .ver_major = VER_2_X, 33c1997054SAmit Kucheria .crit_int = 1, 344360af35SRobert Marko .combo_int = 0, 35c1997054SAmit Kucheria .adc = 0, 36c1997054SAmit Kucheria .srot_split = 1, 371b6e3e51SAmit Kucheria .max_sensors = 16, 38f63bacedSRobert Marko .trip_min_temp = -40000, 39f63bacedSRobert Marko .trip_max_temp = 120000, 40c1997054SAmit Kucheria }; 41c1997054SAmit Kucheria 426840455dSRobert Marko static struct tsens_features ipq8074_feat = { 436840455dSRobert Marko .ver_major = VER_2_X, 446840455dSRobert Marko .crit_int = 1, 456840455dSRobert Marko .combo_int = 1, 466840455dSRobert Marko .adc = 0, 476840455dSRobert Marko .srot_split = 1, 486840455dSRobert Marko .max_sensors = 16, 496840455dSRobert Marko .trip_min_temp = 0, 506840455dSRobert Marko .trip_max_temp = 204000, 516840455dSRobert Marko }; 526840455dSRobert Marko 53c1997054SAmit Kucheria static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = { 54c1997054SAmit Kucheria /* ----- SROT ------ */ 55c1997054SAmit Kucheria /* VERSION */ 56c1997054SAmit Kucheria [VER_MAJOR] = REG_FIELD(SROT_HW_VER_OFF, 28, 31), 57c1997054SAmit Kucheria [VER_MINOR] = REG_FIELD(SROT_HW_VER_OFF, 16, 27), 58c1997054SAmit Kucheria [VER_STEP] = REG_FIELD(SROT_HW_VER_OFF, 0, 15), 59c1997054SAmit Kucheria /* CTRL_OFF */ 60c1997054SAmit Kucheria [TSENS_EN] = REG_FIELD(SROT_CTRL_OFF, 0, 0), 61c1997054SAmit Kucheria [TSENS_SW_RST] = REG_FIELD(SROT_CTRL_OFF, 1, 1), 62c1997054SAmit Kucheria 63c1997054SAmit Kucheria /* ----- TM ------ */ 64c1997054SAmit Kucheria /* INTERRUPT ENABLE */ 65c1997054SAmit Kucheria /* v2 has separate enables for UPPER/LOWER/CRITICAL interrupts */ 66c1997054SAmit Kucheria [INT_EN] = REG_FIELD(TM_INT_EN_OFF, 0, 2), 67c1997054SAmit Kucheria 68634e11d5SAmit Kucheria /* TEMPERATURE THRESHOLDS */ 69634e11d5SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(LOW_THRESH, TM_Sn_UPPER_LOWER_THRESHOLD_OFF, 0, 11), 70634e11d5SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(UP_THRESH, TM_Sn_UPPER_LOWER_THRESHOLD_OFF, 12, 23), 7179125e03SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(CRIT_THRESH, TM_Sn_CRITICAL_THRESHOLD_OFF, 0, 11), 72634e11d5SAmit Kucheria 73634e11d5SAmit Kucheria /* INTERRUPTS [CLEAR/STATUS/MASK] */ 74634e11d5SAmit Kucheria REG_FIELD_SPLIT_BITS_0_15(LOW_INT_STATUS, TM_UPPER_LOWER_INT_STATUS_OFF), 75634e11d5SAmit Kucheria REG_FIELD_SPLIT_BITS_0_15(LOW_INT_CLEAR, TM_UPPER_LOWER_INT_CLEAR_OFF), 76634e11d5SAmit Kucheria REG_FIELD_SPLIT_BITS_0_15(LOW_INT_MASK, TM_UPPER_LOWER_INT_MASK_OFF), 77634e11d5SAmit Kucheria REG_FIELD_SPLIT_BITS_16_31(UP_INT_STATUS, TM_UPPER_LOWER_INT_STATUS_OFF), 78634e11d5SAmit Kucheria REG_FIELD_SPLIT_BITS_16_31(UP_INT_CLEAR, TM_UPPER_LOWER_INT_CLEAR_OFF), 79634e11d5SAmit Kucheria REG_FIELD_SPLIT_BITS_16_31(UP_INT_MASK, TM_UPPER_LOWER_INT_MASK_OFF), 8079125e03SAmit Kucheria REG_FIELD_SPLIT_BITS_0_15(CRIT_INT_STATUS, TM_CRITICAL_INT_STATUS_OFF), 8179125e03SAmit Kucheria REG_FIELD_SPLIT_BITS_0_15(CRIT_INT_CLEAR, TM_CRITICAL_INT_CLEAR_OFF), 8279125e03SAmit Kucheria REG_FIELD_SPLIT_BITS_0_15(CRIT_INT_MASK, TM_CRITICAL_INT_MASK_OFF), 83634e11d5SAmit Kucheria 84d22066c1SAmit Kucheria /* WATCHDOG on v2.3 or later */ 85d22066c1SAmit Kucheria [WDOG_BARK_STATUS] = REG_FIELD(TM_CRITICAL_INT_STATUS_OFF, 31, 31), 86d22066c1SAmit Kucheria [WDOG_BARK_CLEAR] = REG_FIELD(TM_CRITICAL_INT_CLEAR_OFF, 31, 31), 87d22066c1SAmit Kucheria [WDOG_BARK_MASK] = REG_FIELD(TM_CRITICAL_INT_MASK_OFF, 31, 31), 88d22066c1SAmit Kucheria [CC_MON_STATUS] = REG_FIELD(TM_CRITICAL_INT_STATUS_OFF, 30, 30), 89d22066c1SAmit Kucheria [CC_MON_CLEAR] = REG_FIELD(TM_CRITICAL_INT_CLEAR_OFF, 30, 30), 90d22066c1SAmit Kucheria [CC_MON_MASK] = REG_FIELD(TM_CRITICAL_INT_MASK_OFF, 30, 30), 91d22066c1SAmit Kucheria [WDOG_BARK_COUNT] = REG_FIELD(TM_WDOG_LOG_OFF, 0, 7), 92d22066c1SAmit Kucheria 93c1997054SAmit Kucheria /* Sn_STATUS */ 94c1997054SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(LAST_TEMP, TM_Sn_STATUS_OFF, 0, 11), 95c1997054SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(VALID, TM_Sn_STATUS_OFF, 21, 21), 96634e11d5SAmit Kucheria /* xxx_STATUS bits: 1 == threshold violated */ 97c1997054SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(MIN_STATUS, TM_Sn_STATUS_OFF, 16, 16), 98c1997054SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(LOWER_STATUS, TM_Sn_STATUS_OFF, 17, 17), 99c1997054SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(UPPER_STATUS, TM_Sn_STATUS_OFF, 18, 18), 100c1997054SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(CRITICAL_STATUS, TM_Sn_STATUS_OFF, 19, 19), 101c1997054SAmit Kucheria REG_FIELD_FOR_EACH_SENSOR16(MAX_STATUS, TM_Sn_STATUS_OFF, 20, 20), 102c1997054SAmit Kucheria 103c1997054SAmit Kucheria /* TRDY: 1=ready, 0=in progress */ 104c1997054SAmit Kucheria [TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0), 105c1997054SAmit Kucheria }; 106c1997054SAmit Kucheria 107770324a4SAmit Kucheria static const struct tsens_ops ops_generic_v2 = { 108770324a4SAmit Kucheria .init = init_common, 109c8b61690SAmit Kucheria .get_temp = get_temp_tsens_valid, 110*34b9a92bSPriyansh Jain .resume = tsens_resume_common, 111770324a4SAmit Kucheria }; 112770324a4SAmit Kucheria 1130aef1ee5SAmit Kucheria struct tsens_plat_data data_tsens_v2 = { 114191dc74bSAmit Kucheria .ops = &ops_generic_v2, 115c1997054SAmit Kucheria .feat = &tsens_v2_feat, 116c1997054SAmit Kucheria .fields = tsens_v2_regfields, 117191dc74bSAmit Kucheria }; 118191dc74bSAmit Kucheria 1196840455dSRobert Marko struct tsens_plat_data data_ipq8074 = { 1206840455dSRobert Marko .ops = &ops_generic_v2, 1216840455dSRobert Marko .feat = &ipq8074_feat, 1226840455dSRobert Marko .fields = tsens_v2_regfields, 1236840455dSRobert Marko }; 1246840455dSRobert Marko 125191dc74bSAmit Kucheria /* Kept around for backward compatibility with old msm8996.dtsi */ 1260aef1ee5SAmit Kucheria struct tsens_plat_data data_8996 = { 127770324a4SAmit Kucheria .num_sensors = 13, 128770324a4SAmit Kucheria .ops = &ops_generic_v2, 129c1997054SAmit Kucheria .feat = &tsens_v2_feat, 130c1997054SAmit Kucheria .fields = tsens_v2_regfields, 131770324a4SAmit Kucheria }; 132