18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2015, The Linux Foundation. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __QCOM_TSENS_H__ 78c2ecf20Sopenharmony_ci#define __QCOM_TSENS_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define ONE_PT_CALIB 0x1 108c2ecf20Sopenharmony_ci#define ONE_PT_CALIB2 0x2 118c2ecf20Sopenharmony_ci#define TWO_PT_CALIB 0x3 128c2ecf20Sopenharmony_ci#define CAL_DEGC_PT1 30 138c2ecf20Sopenharmony_ci#define CAL_DEGC_PT2 120 148c2ecf20Sopenharmony_ci#define SLOPE_FACTOR 1000 158c2ecf20Sopenharmony_ci#define SLOPE_DEFAULT 3200 168c2ecf20Sopenharmony_ci#define THRESHOLD_MAX_ADC_CODE 0x3ff 178c2ecf20Sopenharmony_ci#define THRESHOLD_MIN_ADC_CODE 0x0 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 208c2ecf20Sopenharmony_ci#include <linux/thermal.h> 218c2ecf20Sopenharmony_ci#include <linux/regmap.h> 228c2ecf20Sopenharmony_ci#include <linux/slab.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistruct tsens_priv; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* IP version numbers in ascending order */ 278c2ecf20Sopenharmony_cienum tsens_ver { 288c2ecf20Sopenharmony_ci VER_0_1 = 0, 298c2ecf20Sopenharmony_ci VER_1_X, 308c2ecf20Sopenharmony_ci VER_2_X, 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cienum tsens_irq_type { 348c2ecf20Sopenharmony_ci LOWER, 358c2ecf20Sopenharmony_ci UPPER, 368c2ecf20Sopenharmony_ci CRITICAL, 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/** 408c2ecf20Sopenharmony_ci * struct tsens_sensor - data for each sensor connected to the tsens device 418c2ecf20Sopenharmony_ci * @priv: tsens device instance that this sensor is connected to 428c2ecf20Sopenharmony_ci * @tzd: pointer to the thermal zone that this sensor is in 438c2ecf20Sopenharmony_ci * @offset: offset of temperature adjustment curve 448c2ecf20Sopenharmony_ci * @hw_id: HW ID can be used in case of platform-specific IDs 458c2ecf20Sopenharmony_ci * @slope: slope of temperature adjustment curve 468c2ecf20Sopenharmony_ci * @status: 8960-specific variable to track 8960 and 8660 status register offset 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_cistruct tsens_sensor { 498c2ecf20Sopenharmony_ci struct tsens_priv *priv; 508c2ecf20Sopenharmony_ci struct thermal_zone_device *tzd; 518c2ecf20Sopenharmony_ci int offset; 528c2ecf20Sopenharmony_ci unsigned int hw_id; 538c2ecf20Sopenharmony_ci int slope; 548c2ecf20Sopenharmony_ci u32 status; 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/** 588c2ecf20Sopenharmony_ci * struct tsens_ops - operations as supported by the tsens device 598c2ecf20Sopenharmony_ci * @init: Function to initialize the tsens device 608c2ecf20Sopenharmony_ci * @calibrate: Function to calibrate the tsens device 618c2ecf20Sopenharmony_ci * @get_temp: Function which returns the temp in millidegC 628c2ecf20Sopenharmony_ci * @enable: Function to enable (clocks/power) tsens device 638c2ecf20Sopenharmony_ci * @disable: Function to disable the tsens device 648c2ecf20Sopenharmony_ci * @suspend: Function to suspend the tsens device 658c2ecf20Sopenharmony_ci * @resume: Function to resume the tsens device 668c2ecf20Sopenharmony_ci * @get_trend: Function to get the thermal/temp trend 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_cistruct tsens_ops { 698c2ecf20Sopenharmony_ci /* mandatory callbacks */ 708c2ecf20Sopenharmony_ci int (*init)(struct tsens_priv *priv); 718c2ecf20Sopenharmony_ci int (*calibrate)(struct tsens_priv *priv); 728c2ecf20Sopenharmony_ci int (*get_temp)(const struct tsens_sensor *s, int *temp); 738c2ecf20Sopenharmony_ci /* optional callbacks */ 748c2ecf20Sopenharmony_ci int (*enable)(struct tsens_priv *priv, int i); 758c2ecf20Sopenharmony_ci void (*disable)(struct tsens_priv *priv); 768c2ecf20Sopenharmony_ci int (*suspend)(struct tsens_priv *priv); 778c2ecf20Sopenharmony_ci int (*resume)(struct tsens_priv *priv); 788c2ecf20Sopenharmony_ci int (*get_trend)(struct tsens_sensor *s, enum thermal_trend *trend); 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \ 828c2ecf20Sopenharmony_ci [_name##_##0] = REG_FIELD(_offset, _startbit, _stopbit), \ 838c2ecf20Sopenharmony_ci [_name##_##1] = REG_FIELD(_offset + 4, _startbit, _stopbit), \ 848c2ecf20Sopenharmony_ci [_name##_##2] = REG_FIELD(_offset + 8, _startbit, _stopbit), \ 858c2ecf20Sopenharmony_ci [_name##_##3] = REG_FIELD(_offset + 12, _startbit, _stopbit), \ 868c2ecf20Sopenharmony_ci [_name##_##4] = REG_FIELD(_offset + 16, _startbit, _stopbit), \ 878c2ecf20Sopenharmony_ci [_name##_##5] = REG_FIELD(_offset + 20, _startbit, _stopbit), \ 888c2ecf20Sopenharmony_ci [_name##_##6] = REG_FIELD(_offset + 24, _startbit, _stopbit), \ 898c2ecf20Sopenharmony_ci [_name##_##7] = REG_FIELD(_offset + 28, _startbit, _stopbit), \ 908c2ecf20Sopenharmony_ci [_name##_##8] = REG_FIELD(_offset + 32, _startbit, _stopbit), \ 918c2ecf20Sopenharmony_ci [_name##_##9] = REG_FIELD(_offset + 36, _startbit, _stopbit), \ 928c2ecf20Sopenharmony_ci [_name##_##10] = REG_FIELD(_offset + 40, _startbit, _stopbit) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#define REG_FIELD_FOR_EACH_SENSOR16(_name, _offset, _startbit, _stopbit) \ 958c2ecf20Sopenharmony_ci [_name##_##0] = REG_FIELD(_offset, _startbit, _stopbit), \ 968c2ecf20Sopenharmony_ci [_name##_##1] = REG_FIELD(_offset + 4, _startbit, _stopbit), \ 978c2ecf20Sopenharmony_ci [_name##_##2] = REG_FIELD(_offset + 8, _startbit, _stopbit), \ 988c2ecf20Sopenharmony_ci [_name##_##3] = REG_FIELD(_offset + 12, _startbit, _stopbit), \ 998c2ecf20Sopenharmony_ci [_name##_##4] = REG_FIELD(_offset + 16, _startbit, _stopbit), \ 1008c2ecf20Sopenharmony_ci [_name##_##5] = REG_FIELD(_offset + 20, _startbit, _stopbit), \ 1018c2ecf20Sopenharmony_ci [_name##_##6] = REG_FIELD(_offset + 24, _startbit, _stopbit), \ 1028c2ecf20Sopenharmony_ci [_name##_##7] = REG_FIELD(_offset + 28, _startbit, _stopbit), \ 1038c2ecf20Sopenharmony_ci [_name##_##8] = REG_FIELD(_offset + 32, _startbit, _stopbit), \ 1048c2ecf20Sopenharmony_ci [_name##_##9] = REG_FIELD(_offset + 36, _startbit, _stopbit), \ 1058c2ecf20Sopenharmony_ci [_name##_##10] = REG_FIELD(_offset + 40, _startbit, _stopbit), \ 1068c2ecf20Sopenharmony_ci [_name##_##11] = REG_FIELD(_offset + 44, _startbit, _stopbit), \ 1078c2ecf20Sopenharmony_ci [_name##_##12] = REG_FIELD(_offset + 48, _startbit, _stopbit), \ 1088c2ecf20Sopenharmony_ci [_name##_##13] = REG_FIELD(_offset + 52, _startbit, _stopbit), \ 1098c2ecf20Sopenharmony_ci [_name##_##14] = REG_FIELD(_offset + 56, _startbit, _stopbit), \ 1108c2ecf20Sopenharmony_ci [_name##_##15] = REG_FIELD(_offset + 60, _startbit, _stopbit) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define REG_FIELD_SPLIT_BITS_0_15(_name, _offset) \ 1138c2ecf20Sopenharmony_ci [_name##_##0] = REG_FIELD(_offset, 0, 0), \ 1148c2ecf20Sopenharmony_ci [_name##_##1] = REG_FIELD(_offset, 1, 1), \ 1158c2ecf20Sopenharmony_ci [_name##_##2] = REG_FIELD(_offset, 2, 2), \ 1168c2ecf20Sopenharmony_ci [_name##_##3] = REG_FIELD(_offset, 3, 3), \ 1178c2ecf20Sopenharmony_ci [_name##_##4] = REG_FIELD(_offset, 4, 4), \ 1188c2ecf20Sopenharmony_ci [_name##_##5] = REG_FIELD(_offset, 5, 5), \ 1198c2ecf20Sopenharmony_ci [_name##_##6] = REG_FIELD(_offset, 6, 6), \ 1208c2ecf20Sopenharmony_ci [_name##_##7] = REG_FIELD(_offset, 7, 7), \ 1218c2ecf20Sopenharmony_ci [_name##_##8] = REG_FIELD(_offset, 8, 8), \ 1228c2ecf20Sopenharmony_ci [_name##_##9] = REG_FIELD(_offset, 9, 9), \ 1238c2ecf20Sopenharmony_ci [_name##_##10] = REG_FIELD(_offset, 10, 10), \ 1248c2ecf20Sopenharmony_ci [_name##_##11] = REG_FIELD(_offset, 11, 11), \ 1258c2ecf20Sopenharmony_ci [_name##_##12] = REG_FIELD(_offset, 12, 12), \ 1268c2ecf20Sopenharmony_ci [_name##_##13] = REG_FIELD(_offset, 13, 13), \ 1278c2ecf20Sopenharmony_ci [_name##_##14] = REG_FIELD(_offset, 14, 14), \ 1288c2ecf20Sopenharmony_ci [_name##_##15] = REG_FIELD(_offset, 15, 15) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define REG_FIELD_SPLIT_BITS_16_31(_name, _offset) \ 1318c2ecf20Sopenharmony_ci [_name##_##0] = REG_FIELD(_offset, 16, 16), \ 1328c2ecf20Sopenharmony_ci [_name##_##1] = REG_FIELD(_offset, 17, 17), \ 1338c2ecf20Sopenharmony_ci [_name##_##2] = REG_FIELD(_offset, 18, 18), \ 1348c2ecf20Sopenharmony_ci [_name##_##3] = REG_FIELD(_offset, 19, 19), \ 1358c2ecf20Sopenharmony_ci [_name##_##4] = REG_FIELD(_offset, 20, 20), \ 1368c2ecf20Sopenharmony_ci [_name##_##5] = REG_FIELD(_offset, 21, 21), \ 1378c2ecf20Sopenharmony_ci [_name##_##6] = REG_FIELD(_offset, 22, 22), \ 1388c2ecf20Sopenharmony_ci [_name##_##7] = REG_FIELD(_offset, 23, 23), \ 1398c2ecf20Sopenharmony_ci [_name##_##8] = REG_FIELD(_offset, 24, 24), \ 1408c2ecf20Sopenharmony_ci [_name##_##9] = REG_FIELD(_offset, 25, 25), \ 1418c2ecf20Sopenharmony_ci [_name##_##10] = REG_FIELD(_offset, 26, 26), \ 1428c2ecf20Sopenharmony_ci [_name##_##11] = REG_FIELD(_offset, 27, 27), \ 1438c2ecf20Sopenharmony_ci [_name##_##12] = REG_FIELD(_offset, 28, 28), \ 1448c2ecf20Sopenharmony_ci [_name##_##13] = REG_FIELD(_offset, 29, 29), \ 1458c2ecf20Sopenharmony_ci [_name##_##14] = REG_FIELD(_offset, 30, 30), \ 1468c2ecf20Sopenharmony_ci [_name##_##15] = REG_FIELD(_offset, 31, 31) 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* 1498c2ecf20Sopenharmony_ci * reg_field IDs to use as an index into an array 1508c2ecf20Sopenharmony_ci * If you change the order of the entries, check the devm_regmap_field_alloc() 1518c2ecf20Sopenharmony_ci * calls in init_common() 1528c2ecf20Sopenharmony_ci */ 1538c2ecf20Sopenharmony_cienum regfield_ids { 1548c2ecf20Sopenharmony_ci /* ----- SROT ------ */ 1558c2ecf20Sopenharmony_ci /* HW_VER */ 1568c2ecf20Sopenharmony_ci VER_MAJOR, 1578c2ecf20Sopenharmony_ci VER_MINOR, 1588c2ecf20Sopenharmony_ci VER_STEP, 1598c2ecf20Sopenharmony_ci /* CTRL_OFFSET */ 1608c2ecf20Sopenharmony_ci TSENS_EN, 1618c2ecf20Sopenharmony_ci TSENS_SW_RST, 1628c2ecf20Sopenharmony_ci SENSOR_EN, 1638c2ecf20Sopenharmony_ci CODE_OR_TEMP, 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci /* ----- TM ------ */ 1668c2ecf20Sopenharmony_ci /* TRDY */ 1678c2ecf20Sopenharmony_ci TRDY, 1688c2ecf20Sopenharmony_ci /* INTERRUPT ENABLE */ 1698c2ecf20Sopenharmony_ci INT_EN, /* v2+ has separate enables for crit, upper and lower irq */ 1708c2ecf20Sopenharmony_ci /* STATUS */ 1718c2ecf20Sopenharmony_ci LAST_TEMP_0, /* Last temperature reading */ 1728c2ecf20Sopenharmony_ci LAST_TEMP_1, 1738c2ecf20Sopenharmony_ci LAST_TEMP_2, 1748c2ecf20Sopenharmony_ci LAST_TEMP_3, 1758c2ecf20Sopenharmony_ci LAST_TEMP_4, 1768c2ecf20Sopenharmony_ci LAST_TEMP_5, 1778c2ecf20Sopenharmony_ci LAST_TEMP_6, 1788c2ecf20Sopenharmony_ci LAST_TEMP_7, 1798c2ecf20Sopenharmony_ci LAST_TEMP_8, 1808c2ecf20Sopenharmony_ci LAST_TEMP_9, 1818c2ecf20Sopenharmony_ci LAST_TEMP_10, 1828c2ecf20Sopenharmony_ci LAST_TEMP_11, 1838c2ecf20Sopenharmony_ci LAST_TEMP_12, 1848c2ecf20Sopenharmony_ci LAST_TEMP_13, 1858c2ecf20Sopenharmony_ci LAST_TEMP_14, 1868c2ecf20Sopenharmony_ci LAST_TEMP_15, 1878c2ecf20Sopenharmony_ci VALID_0, /* VALID reading or not */ 1888c2ecf20Sopenharmony_ci VALID_1, 1898c2ecf20Sopenharmony_ci VALID_2, 1908c2ecf20Sopenharmony_ci VALID_3, 1918c2ecf20Sopenharmony_ci VALID_4, 1928c2ecf20Sopenharmony_ci VALID_5, 1938c2ecf20Sopenharmony_ci VALID_6, 1948c2ecf20Sopenharmony_ci VALID_7, 1958c2ecf20Sopenharmony_ci VALID_8, 1968c2ecf20Sopenharmony_ci VALID_9, 1978c2ecf20Sopenharmony_ci VALID_10, 1988c2ecf20Sopenharmony_ci VALID_11, 1998c2ecf20Sopenharmony_ci VALID_12, 2008c2ecf20Sopenharmony_ci VALID_13, 2018c2ecf20Sopenharmony_ci VALID_14, 2028c2ecf20Sopenharmony_ci VALID_15, 2038c2ecf20Sopenharmony_ci LOWER_STATUS_0, /* LOWER threshold violated */ 2048c2ecf20Sopenharmony_ci LOWER_STATUS_1, 2058c2ecf20Sopenharmony_ci LOWER_STATUS_2, 2068c2ecf20Sopenharmony_ci LOWER_STATUS_3, 2078c2ecf20Sopenharmony_ci LOWER_STATUS_4, 2088c2ecf20Sopenharmony_ci LOWER_STATUS_5, 2098c2ecf20Sopenharmony_ci LOWER_STATUS_6, 2108c2ecf20Sopenharmony_ci LOWER_STATUS_7, 2118c2ecf20Sopenharmony_ci LOWER_STATUS_8, 2128c2ecf20Sopenharmony_ci LOWER_STATUS_9, 2138c2ecf20Sopenharmony_ci LOWER_STATUS_10, 2148c2ecf20Sopenharmony_ci LOWER_STATUS_11, 2158c2ecf20Sopenharmony_ci LOWER_STATUS_12, 2168c2ecf20Sopenharmony_ci LOWER_STATUS_13, 2178c2ecf20Sopenharmony_ci LOWER_STATUS_14, 2188c2ecf20Sopenharmony_ci LOWER_STATUS_15, 2198c2ecf20Sopenharmony_ci LOW_INT_STATUS_0, /* LOWER interrupt status */ 2208c2ecf20Sopenharmony_ci LOW_INT_STATUS_1, 2218c2ecf20Sopenharmony_ci LOW_INT_STATUS_2, 2228c2ecf20Sopenharmony_ci LOW_INT_STATUS_3, 2238c2ecf20Sopenharmony_ci LOW_INT_STATUS_4, 2248c2ecf20Sopenharmony_ci LOW_INT_STATUS_5, 2258c2ecf20Sopenharmony_ci LOW_INT_STATUS_6, 2268c2ecf20Sopenharmony_ci LOW_INT_STATUS_7, 2278c2ecf20Sopenharmony_ci LOW_INT_STATUS_8, 2288c2ecf20Sopenharmony_ci LOW_INT_STATUS_9, 2298c2ecf20Sopenharmony_ci LOW_INT_STATUS_10, 2308c2ecf20Sopenharmony_ci LOW_INT_STATUS_11, 2318c2ecf20Sopenharmony_ci LOW_INT_STATUS_12, 2328c2ecf20Sopenharmony_ci LOW_INT_STATUS_13, 2338c2ecf20Sopenharmony_ci LOW_INT_STATUS_14, 2348c2ecf20Sopenharmony_ci LOW_INT_STATUS_15, 2358c2ecf20Sopenharmony_ci LOW_INT_CLEAR_0, /* LOWER interrupt clear */ 2368c2ecf20Sopenharmony_ci LOW_INT_CLEAR_1, 2378c2ecf20Sopenharmony_ci LOW_INT_CLEAR_2, 2388c2ecf20Sopenharmony_ci LOW_INT_CLEAR_3, 2398c2ecf20Sopenharmony_ci LOW_INT_CLEAR_4, 2408c2ecf20Sopenharmony_ci LOW_INT_CLEAR_5, 2418c2ecf20Sopenharmony_ci LOW_INT_CLEAR_6, 2428c2ecf20Sopenharmony_ci LOW_INT_CLEAR_7, 2438c2ecf20Sopenharmony_ci LOW_INT_CLEAR_8, 2448c2ecf20Sopenharmony_ci LOW_INT_CLEAR_9, 2458c2ecf20Sopenharmony_ci LOW_INT_CLEAR_10, 2468c2ecf20Sopenharmony_ci LOW_INT_CLEAR_11, 2478c2ecf20Sopenharmony_ci LOW_INT_CLEAR_12, 2488c2ecf20Sopenharmony_ci LOW_INT_CLEAR_13, 2498c2ecf20Sopenharmony_ci LOW_INT_CLEAR_14, 2508c2ecf20Sopenharmony_ci LOW_INT_CLEAR_15, 2518c2ecf20Sopenharmony_ci LOW_INT_MASK_0, /* LOWER interrupt mask */ 2528c2ecf20Sopenharmony_ci LOW_INT_MASK_1, 2538c2ecf20Sopenharmony_ci LOW_INT_MASK_2, 2548c2ecf20Sopenharmony_ci LOW_INT_MASK_3, 2558c2ecf20Sopenharmony_ci LOW_INT_MASK_4, 2568c2ecf20Sopenharmony_ci LOW_INT_MASK_5, 2578c2ecf20Sopenharmony_ci LOW_INT_MASK_6, 2588c2ecf20Sopenharmony_ci LOW_INT_MASK_7, 2598c2ecf20Sopenharmony_ci LOW_INT_MASK_8, 2608c2ecf20Sopenharmony_ci LOW_INT_MASK_9, 2618c2ecf20Sopenharmony_ci LOW_INT_MASK_10, 2628c2ecf20Sopenharmony_ci LOW_INT_MASK_11, 2638c2ecf20Sopenharmony_ci LOW_INT_MASK_12, 2648c2ecf20Sopenharmony_ci LOW_INT_MASK_13, 2658c2ecf20Sopenharmony_ci LOW_INT_MASK_14, 2668c2ecf20Sopenharmony_ci LOW_INT_MASK_15, 2678c2ecf20Sopenharmony_ci LOW_THRESH_0, /* LOWER threshold values */ 2688c2ecf20Sopenharmony_ci LOW_THRESH_1, 2698c2ecf20Sopenharmony_ci LOW_THRESH_2, 2708c2ecf20Sopenharmony_ci LOW_THRESH_3, 2718c2ecf20Sopenharmony_ci LOW_THRESH_4, 2728c2ecf20Sopenharmony_ci LOW_THRESH_5, 2738c2ecf20Sopenharmony_ci LOW_THRESH_6, 2748c2ecf20Sopenharmony_ci LOW_THRESH_7, 2758c2ecf20Sopenharmony_ci LOW_THRESH_8, 2768c2ecf20Sopenharmony_ci LOW_THRESH_9, 2778c2ecf20Sopenharmony_ci LOW_THRESH_10, 2788c2ecf20Sopenharmony_ci LOW_THRESH_11, 2798c2ecf20Sopenharmony_ci LOW_THRESH_12, 2808c2ecf20Sopenharmony_ci LOW_THRESH_13, 2818c2ecf20Sopenharmony_ci LOW_THRESH_14, 2828c2ecf20Sopenharmony_ci LOW_THRESH_15, 2838c2ecf20Sopenharmony_ci UPPER_STATUS_0, /* UPPER threshold violated */ 2848c2ecf20Sopenharmony_ci UPPER_STATUS_1, 2858c2ecf20Sopenharmony_ci UPPER_STATUS_2, 2868c2ecf20Sopenharmony_ci UPPER_STATUS_3, 2878c2ecf20Sopenharmony_ci UPPER_STATUS_4, 2888c2ecf20Sopenharmony_ci UPPER_STATUS_5, 2898c2ecf20Sopenharmony_ci UPPER_STATUS_6, 2908c2ecf20Sopenharmony_ci UPPER_STATUS_7, 2918c2ecf20Sopenharmony_ci UPPER_STATUS_8, 2928c2ecf20Sopenharmony_ci UPPER_STATUS_9, 2938c2ecf20Sopenharmony_ci UPPER_STATUS_10, 2948c2ecf20Sopenharmony_ci UPPER_STATUS_11, 2958c2ecf20Sopenharmony_ci UPPER_STATUS_12, 2968c2ecf20Sopenharmony_ci UPPER_STATUS_13, 2978c2ecf20Sopenharmony_ci UPPER_STATUS_14, 2988c2ecf20Sopenharmony_ci UPPER_STATUS_15, 2998c2ecf20Sopenharmony_ci UP_INT_STATUS_0, /* UPPER interrupt status */ 3008c2ecf20Sopenharmony_ci UP_INT_STATUS_1, 3018c2ecf20Sopenharmony_ci UP_INT_STATUS_2, 3028c2ecf20Sopenharmony_ci UP_INT_STATUS_3, 3038c2ecf20Sopenharmony_ci UP_INT_STATUS_4, 3048c2ecf20Sopenharmony_ci UP_INT_STATUS_5, 3058c2ecf20Sopenharmony_ci UP_INT_STATUS_6, 3068c2ecf20Sopenharmony_ci UP_INT_STATUS_7, 3078c2ecf20Sopenharmony_ci UP_INT_STATUS_8, 3088c2ecf20Sopenharmony_ci UP_INT_STATUS_9, 3098c2ecf20Sopenharmony_ci UP_INT_STATUS_10, 3108c2ecf20Sopenharmony_ci UP_INT_STATUS_11, 3118c2ecf20Sopenharmony_ci UP_INT_STATUS_12, 3128c2ecf20Sopenharmony_ci UP_INT_STATUS_13, 3138c2ecf20Sopenharmony_ci UP_INT_STATUS_14, 3148c2ecf20Sopenharmony_ci UP_INT_STATUS_15, 3158c2ecf20Sopenharmony_ci UP_INT_CLEAR_0, /* UPPER interrupt clear */ 3168c2ecf20Sopenharmony_ci UP_INT_CLEAR_1, 3178c2ecf20Sopenharmony_ci UP_INT_CLEAR_2, 3188c2ecf20Sopenharmony_ci UP_INT_CLEAR_3, 3198c2ecf20Sopenharmony_ci UP_INT_CLEAR_4, 3208c2ecf20Sopenharmony_ci UP_INT_CLEAR_5, 3218c2ecf20Sopenharmony_ci UP_INT_CLEAR_6, 3228c2ecf20Sopenharmony_ci UP_INT_CLEAR_7, 3238c2ecf20Sopenharmony_ci UP_INT_CLEAR_8, 3248c2ecf20Sopenharmony_ci UP_INT_CLEAR_9, 3258c2ecf20Sopenharmony_ci UP_INT_CLEAR_10, 3268c2ecf20Sopenharmony_ci UP_INT_CLEAR_11, 3278c2ecf20Sopenharmony_ci UP_INT_CLEAR_12, 3288c2ecf20Sopenharmony_ci UP_INT_CLEAR_13, 3298c2ecf20Sopenharmony_ci UP_INT_CLEAR_14, 3308c2ecf20Sopenharmony_ci UP_INT_CLEAR_15, 3318c2ecf20Sopenharmony_ci UP_INT_MASK_0, /* UPPER interrupt mask */ 3328c2ecf20Sopenharmony_ci UP_INT_MASK_1, 3338c2ecf20Sopenharmony_ci UP_INT_MASK_2, 3348c2ecf20Sopenharmony_ci UP_INT_MASK_3, 3358c2ecf20Sopenharmony_ci UP_INT_MASK_4, 3368c2ecf20Sopenharmony_ci UP_INT_MASK_5, 3378c2ecf20Sopenharmony_ci UP_INT_MASK_6, 3388c2ecf20Sopenharmony_ci UP_INT_MASK_7, 3398c2ecf20Sopenharmony_ci UP_INT_MASK_8, 3408c2ecf20Sopenharmony_ci UP_INT_MASK_9, 3418c2ecf20Sopenharmony_ci UP_INT_MASK_10, 3428c2ecf20Sopenharmony_ci UP_INT_MASK_11, 3438c2ecf20Sopenharmony_ci UP_INT_MASK_12, 3448c2ecf20Sopenharmony_ci UP_INT_MASK_13, 3458c2ecf20Sopenharmony_ci UP_INT_MASK_14, 3468c2ecf20Sopenharmony_ci UP_INT_MASK_15, 3478c2ecf20Sopenharmony_ci UP_THRESH_0, /* UPPER threshold values */ 3488c2ecf20Sopenharmony_ci UP_THRESH_1, 3498c2ecf20Sopenharmony_ci UP_THRESH_2, 3508c2ecf20Sopenharmony_ci UP_THRESH_3, 3518c2ecf20Sopenharmony_ci UP_THRESH_4, 3528c2ecf20Sopenharmony_ci UP_THRESH_5, 3538c2ecf20Sopenharmony_ci UP_THRESH_6, 3548c2ecf20Sopenharmony_ci UP_THRESH_7, 3558c2ecf20Sopenharmony_ci UP_THRESH_8, 3568c2ecf20Sopenharmony_ci UP_THRESH_9, 3578c2ecf20Sopenharmony_ci UP_THRESH_10, 3588c2ecf20Sopenharmony_ci UP_THRESH_11, 3598c2ecf20Sopenharmony_ci UP_THRESH_12, 3608c2ecf20Sopenharmony_ci UP_THRESH_13, 3618c2ecf20Sopenharmony_ci UP_THRESH_14, 3628c2ecf20Sopenharmony_ci UP_THRESH_15, 3638c2ecf20Sopenharmony_ci CRITICAL_STATUS_0, /* CRITICAL threshold violated */ 3648c2ecf20Sopenharmony_ci CRITICAL_STATUS_1, 3658c2ecf20Sopenharmony_ci CRITICAL_STATUS_2, 3668c2ecf20Sopenharmony_ci CRITICAL_STATUS_3, 3678c2ecf20Sopenharmony_ci CRITICAL_STATUS_4, 3688c2ecf20Sopenharmony_ci CRITICAL_STATUS_5, 3698c2ecf20Sopenharmony_ci CRITICAL_STATUS_6, 3708c2ecf20Sopenharmony_ci CRITICAL_STATUS_7, 3718c2ecf20Sopenharmony_ci CRITICAL_STATUS_8, 3728c2ecf20Sopenharmony_ci CRITICAL_STATUS_9, 3738c2ecf20Sopenharmony_ci CRITICAL_STATUS_10, 3748c2ecf20Sopenharmony_ci CRITICAL_STATUS_11, 3758c2ecf20Sopenharmony_ci CRITICAL_STATUS_12, 3768c2ecf20Sopenharmony_ci CRITICAL_STATUS_13, 3778c2ecf20Sopenharmony_ci CRITICAL_STATUS_14, 3788c2ecf20Sopenharmony_ci CRITICAL_STATUS_15, 3798c2ecf20Sopenharmony_ci CRIT_INT_STATUS_0, /* CRITICAL interrupt status */ 3808c2ecf20Sopenharmony_ci CRIT_INT_STATUS_1, 3818c2ecf20Sopenharmony_ci CRIT_INT_STATUS_2, 3828c2ecf20Sopenharmony_ci CRIT_INT_STATUS_3, 3838c2ecf20Sopenharmony_ci CRIT_INT_STATUS_4, 3848c2ecf20Sopenharmony_ci CRIT_INT_STATUS_5, 3858c2ecf20Sopenharmony_ci CRIT_INT_STATUS_6, 3868c2ecf20Sopenharmony_ci CRIT_INT_STATUS_7, 3878c2ecf20Sopenharmony_ci CRIT_INT_STATUS_8, 3888c2ecf20Sopenharmony_ci CRIT_INT_STATUS_9, 3898c2ecf20Sopenharmony_ci CRIT_INT_STATUS_10, 3908c2ecf20Sopenharmony_ci CRIT_INT_STATUS_11, 3918c2ecf20Sopenharmony_ci CRIT_INT_STATUS_12, 3928c2ecf20Sopenharmony_ci CRIT_INT_STATUS_13, 3938c2ecf20Sopenharmony_ci CRIT_INT_STATUS_14, 3948c2ecf20Sopenharmony_ci CRIT_INT_STATUS_15, 3958c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_0, /* CRITICAL interrupt clear */ 3968c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_1, 3978c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_2, 3988c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_3, 3998c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_4, 4008c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_5, 4018c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_6, 4028c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_7, 4038c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_8, 4048c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_9, 4058c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_10, 4068c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_11, 4078c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_12, 4088c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_13, 4098c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_14, 4108c2ecf20Sopenharmony_ci CRIT_INT_CLEAR_15, 4118c2ecf20Sopenharmony_ci CRIT_INT_MASK_0, /* CRITICAL interrupt mask */ 4128c2ecf20Sopenharmony_ci CRIT_INT_MASK_1, 4138c2ecf20Sopenharmony_ci CRIT_INT_MASK_2, 4148c2ecf20Sopenharmony_ci CRIT_INT_MASK_3, 4158c2ecf20Sopenharmony_ci CRIT_INT_MASK_4, 4168c2ecf20Sopenharmony_ci CRIT_INT_MASK_5, 4178c2ecf20Sopenharmony_ci CRIT_INT_MASK_6, 4188c2ecf20Sopenharmony_ci CRIT_INT_MASK_7, 4198c2ecf20Sopenharmony_ci CRIT_INT_MASK_8, 4208c2ecf20Sopenharmony_ci CRIT_INT_MASK_9, 4218c2ecf20Sopenharmony_ci CRIT_INT_MASK_10, 4228c2ecf20Sopenharmony_ci CRIT_INT_MASK_11, 4238c2ecf20Sopenharmony_ci CRIT_INT_MASK_12, 4248c2ecf20Sopenharmony_ci CRIT_INT_MASK_13, 4258c2ecf20Sopenharmony_ci CRIT_INT_MASK_14, 4268c2ecf20Sopenharmony_ci CRIT_INT_MASK_15, 4278c2ecf20Sopenharmony_ci CRIT_THRESH_0, /* CRITICAL threshold values */ 4288c2ecf20Sopenharmony_ci CRIT_THRESH_1, 4298c2ecf20Sopenharmony_ci CRIT_THRESH_2, 4308c2ecf20Sopenharmony_ci CRIT_THRESH_3, 4318c2ecf20Sopenharmony_ci CRIT_THRESH_4, 4328c2ecf20Sopenharmony_ci CRIT_THRESH_5, 4338c2ecf20Sopenharmony_ci CRIT_THRESH_6, 4348c2ecf20Sopenharmony_ci CRIT_THRESH_7, 4358c2ecf20Sopenharmony_ci CRIT_THRESH_8, 4368c2ecf20Sopenharmony_ci CRIT_THRESH_9, 4378c2ecf20Sopenharmony_ci CRIT_THRESH_10, 4388c2ecf20Sopenharmony_ci CRIT_THRESH_11, 4398c2ecf20Sopenharmony_ci CRIT_THRESH_12, 4408c2ecf20Sopenharmony_ci CRIT_THRESH_13, 4418c2ecf20Sopenharmony_ci CRIT_THRESH_14, 4428c2ecf20Sopenharmony_ci CRIT_THRESH_15, 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci /* WATCHDOG */ 4458c2ecf20Sopenharmony_ci WDOG_BARK_STATUS, 4468c2ecf20Sopenharmony_ci WDOG_BARK_CLEAR, 4478c2ecf20Sopenharmony_ci WDOG_BARK_MASK, 4488c2ecf20Sopenharmony_ci WDOG_BARK_COUNT, 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci /* CYCLE COMPLETION MONITOR */ 4518c2ecf20Sopenharmony_ci CC_MON_STATUS, 4528c2ecf20Sopenharmony_ci CC_MON_CLEAR, 4538c2ecf20Sopenharmony_ci CC_MON_MASK, 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci MIN_STATUS_0, /* MIN threshold violated */ 4568c2ecf20Sopenharmony_ci MIN_STATUS_1, 4578c2ecf20Sopenharmony_ci MIN_STATUS_2, 4588c2ecf20Sopenharmony_ci MIN_STATUS_3, 4598c2ecf20Sopenharmony_ci MIN_STATUS_4, 4608c2ecf20Sopenharmony_ci MIN_STATUS_5, 4618c2ecf20Sopenharmony_ci MIN_STATUS_6, 4628c2ecf20Sopenharmony_ci MIN_STATUS_7, 4638c2ecf20Sopenharmony_ci MIN_STATUS_8, 4648c2ecf20Sopenharmony_ci MIN_STATUS_9, 4658c2ecf20Sopenharmony_ci MIN_STATUS_10, 4668c2ecf20Sopenharmony_ci MIN_STATUS_11, 4678c2ecf20Sopenharmony_ci MIN_STATUS_12, 4688c2ecf20Sopenharmony_ci MIN_STATUS_13, 4698c2ecf20Sopenharmony_ci MIN_STATUS_14, 4708c2ecf20Sopenharmony_ci MIN_STATUS_15, 4718c2ecf20Sopenharmony_ci MAX_STATUS_0, /* MAX threshold violated */ 4728c2ecf20Sopenharmony_ci MAX_STATUS_1, 4738c2ecf20Sopenharmony_ci MAX_STATUS_2, 4748c2ecf20Sopenharmony_ci MAX_STATUS_3, 4758c2ecf20Sopenharmony_ci MAX_STATUS_4, 4768c2ecf20Sopenharmony_ci MAX_STATUS_5, 4778c2ecf20Sopenharmony_ci MAX_STATUS_6, 4788c2ecf20Sopenharmony_ci MAX_STATUS_7, 4798c2ecf20Sopenharmony_ci MAX_STATUS_8, 4808c2ecf20Sopenharmony_ci MAX_STATUS_9, 4818c2ecf20Sopenharmony_ci MAX_STATUS_10, 4828c2ecf20Sopenharmony_ci MAX_STATUS_11, 4838c2ecf20Sopenharmony_ci MAX_STATUS_12, 4848c2ecf20Sopenharmony_ci MAX_STATUS_13, 4858c2ecf20Sopenharmony_ci MAX_STATUS_14, 4868c2ecf20Sopenharmony_ci MAX_STATUS_15, 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci /* Keep last */ 4898c2ecf20Sopenharmony_ci MAX_REGFIELDS 4908c2ecf20Sopenharmony_ci}; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci/** 4938c2ecf20Sopenharmony_ci * struct tsens_features - Features supported by the IP 4948c2ecf20Sopenharmony_ci * @ver_major: Major number of IP version 4958c2ecf20Sopenharmony_ci * @crit_int: does the IP support critical interrupts? 4968c2ecf20Sopenharmony_ci * @adc: do the sensors only output adc code (instead of temperature)? 4978c2ecf20Sopenharmony_ci * @srot_split: does the IP neatly splits the register space into SROT and TM, 4988c2ecf20Sopenharmony_ci * with SROT only being available to secure boot firmware? 4998c2ecf20Sopenharmony_ci * @has_watchdog: does this IP support watchdog functionality? 5008c2ecf20Sopenharmony_ci * @max_sensors: maximum sensors supported by this version of the IP 5018c2ecf20Sopenharmony_ci */ 5028c2ecf20Sopenharmony_cistruct tsens_features { 5038c2ecf20Sopenharmony_ci unsigned int ver_major; 5048c2ecf20Sopenharmony_ci unsigned int crit_int:1; 5058c2ecf20Sopenharmony_ci unsigned int adc:1; 5068c2ecf20Sopenharmony_ci unsigned int srot_split:1; 5078c2ecf20Sopenharmony_ci unsigned int has_watchdog:1; 5088c2ecf20Sopenharmony_ci unsigned int max_sensors; 5098c2ecf20Sopenharmony_ci}; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci/** 5128c2ecf20Sopenharmony_ci * struct tsens_plat_data - tsens compile-time platform data 5138c2ecf20Sopenharmony_ci * @num_sensors: Number of sensors supported by platform 5148c2ecf20Sopenharmony_ci * @ops: operations the tsens instance supports 5158c2ecf20Sopenharmony_ci * @hw_ids: Subset of sensors ids supported by platform, if not the first n 5168c2ecf20Sopenharmony_ci * @feat: features of the IP 5178c2ecf20Sopenharmony_ci * @fields: bitfield locations 5188c2ecf20Sopenharmony_ci */ 5198c2ecf20Sopenharmony_cistruct tsens_plat_data { 5208c2ecf20Sopenharmony_ci const u32 num_sensors; 5218c2ecf20Sopenharmony_ci const struct tsens_ops *ops; 5228c2ecf20Sopenharmony_ci unsigned int *hw_ids; 5238c2ecf20Sopenharmony_ci struct tsens_features *feat; 5248c2ecf20Sopenharmony_ci const struct reg_field *fields; 5258c2ecf20Sopenharmony_ci}; 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_ci/** 5288c2ecf20Sopenharmony_ci * struct tsens_context - Registers to be saved/restored across a context loss 5298c2ecf20Sopenharmony_ci * @threshold: Threshold register value 5308c2ecf20Sopenharmony_ci * @control: Control register value 5318c2ecf20Sopenharmony_ci */ 5328c2ecf20Sopenharmony_cistruct tsens_context { 5338c2ecf20Sopenharmony_ci int threshold; 5348c2ecf20Sopenharmony_ci int control; 5358c2ecf20Sopenharmony_ci}; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci/** 5388c2ecf20Sopenharmony_ci * struct tsens_priv - private data for each instance of the tsens IP 5398c2ecf20Sopenharmony_ci * @dev: pointer to struct device 5408c2ecf20Sopenharmony_ci * @num_sensors: number of sensors enabled on this device 5418c2ecf20Sopenharmony_ci * @tm_map: pointer to TM register address space 5428c2ecf20Sopenharmony_ci * @srot_map: pointer to SROT register address space 5438c2ecf20Sopenharmony_ci * @tm_offset: deal with old device trees that don't address TM and SROT 5448c2ecf20Sopenharmony_ci * address space separately 5458c2ecf20Sopenharmony_ci * @ul_lock: lock while processing upper/lower threshold interrupts 5468c2ecf20Sopenharmony_ci * @crit_lock: lock while processing critical threshold interrupts 5478c2ecf20Sopenharmony_ci * @rf: array of regmap_fields used to store value of the field 5488c2ecf20Sopenharmony_ci * @ctx: registers to be saved and restored during suspend/resume 5498c2ecf20Sopenharmony_ci * @feat: features of the IP 5508c2ecf20Sopenharmony_ci * @fields: bitfield locations 5518c2ecf20Sopenharmony_ci * @ops: pointer to list of callbacks supported by this device 5528c2ecf20Sopenharmony_ci * @debug_root: pointer to debugfs dentry for all tsens 5538c2ecf20Sopenharmony_ci * @debug: pointer to debugfs dentry for tsens controller 5548c2ecf20Sopenharmony_ci * @sensor: list of sensors attached to this device 5558c2ecf20Sopenharmony_ci */ 5568c2ecf20Sopenharmony_cistruct tsens_priv { 5578c2ecf20Sopenharmony_ci struct device *dev; 5588c2ecf20Sopenharmony_ci u32 num_sensors; 5598c2ecf20Sopenharmony_ci struct regmap *tm_map; 5608c2ecf20Sopenharmony_ci struct regmap *srot_map; 5618c2ecf20Sopenharmony_ci u32 tm_offset; 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci /* lock for upper/lower threshold interrupts */ 5648c2ecf20Sopenharmony_ci spinlock_t ul_lock; 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci struct regmap_field *rf[MAX_REGFIELDS]; 5678c2ecf20Sopenharmony_ci struct tsens_context ctx; 5688c2ecf20Sopenharmony_ci struct tsens_features *feat; 5698c2ecf20Sopenharmony_ci const struct reg_field *fields; 5708c2ecf20Sopenharmony_ci const struct tsens_ops *ops; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci struct dentry *debug_root; 5738c2ecf20Sopenharmony_ci struct dentry *debug; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci struct tsens_sensor sensor[]; 5768c2ecf20Sopenharmony_ci}; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_cichar *qfprom_read(struct device *dev, const char *cname); 5798c2ecf20Sopenharmony_civoid compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode); 5808c2ecf20Sopenharmony_ciint init_common(struct tsens_priv *priv); 5818c2ecf20Sopenharmony_ciint get_temp_tsens_valid(const struct tsens_sensor *s, int *temp); 5828c2ecf20Sopenharmony_ciint get_temp_common(const struct tsens_sensor *s, int *temp); 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci/* TSENS target */ 5858c2ecf20Sopenharmony_ciextern struct tsens_plat_data data_8960; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci/* TSENS v0.1 targets */ 5888c2ecf20Sopenharmony_ciextern struct tsens_plat_data data_8916, data_8939, data_8974; 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci/* TSENS v1 targets */ 5918c2ecf20Sopenharmony_ciextern struct tsens_plat_data data_tsens_v1, data_8976, data_8956; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci/* TSENS v2 targets */ 5948c2ecf20Sopenharmony_ciextern struct tsens_plat_data data_8996, data_tsens_v2; 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci#endif /* __QCOM_TSENS_H__ */ 597