12d71d8deSAmit Kucheria /* SPDX-License-Identifier: GPL-2.0 */ 29066073cSRajendra Nayak /* 39066073cSRajendra Nayak * Copyright (c) 2015, The Linux Foundation. All rights reserved. 49066073cSRajendra Nayak */ 52d71d8deSAmit Kucheria 69066073cSRajendra Nayak #ifndef __QCOM_TSENS_H__ 79066073cSRajendra Nayak #define __QCOM_TSENS_H__ 89066073cSRajendra Nayak 9498d2457SDmitry Baryshkov #define NO_PT_CALIB 0x0 109066073cSRajendra Nayak #define ONE_PT_CALIB 0x1 119066073cSRajendra Nayak #define ONE_PT_CALIB2 0x2 129066073cSRajendra Nayak #define TWO_PT_CALIB 0x3 13b6f739daSStephan Gerhold #define ONE_PT_CALIB2_NO_OFFSET 0x6 14b6f739daSStephan Gerhold #define TWO_PT_CALIB_NO_OFFSET 0x7 15e52bbd2fSAmit Kucheria #define CAL_DEGC_PT1 30 16e52bbd2fSAmit Kucheria #define CAL_DEGC_PT2 120 17e52bbd2fSAmit Kucheria #define SLOPE_FACTOR 1000 18e52bbd2fSAmit Kucheria #define SLOPE_DEFAULT 3200 1953e2a20eSAnsuel Smith #define TIMEOUT_US 100 20634e11d5SAmit Kucheria #define THRESHOLD_MAX_ADC_CODE 0x3ff 21634e11d5SAmit Kucheria #define THRESHOLD_MIN_ADC_CODE 0x0 22e52bbd2fSAmit Kucheria 23498d2457SDmitry Baryshkov #define MAX_SENSORS 16 24498d2457SDmitry Baryshkov 25634e11d5SAmit Kucheria #include <linux/interrupt.h> 26e78eaf45SSascha Hauer #include <linux/thermal.h> 27c1997054SAmit Kucheria #include <linux/regmap.h> 286b8249abSSrinivas Kandagatla #include <linux/slab.h> 29e78eaf45SSascha Hauer 3024ae4472SAmit Kucheria struct tsens_priv; 319066073cSRajendra Nayak 3279125e03SAmit Kucheria /* IP version numbers in ascending order */ 33c1997054SAmit Kucheria enum tsens_ver { 3453e2a20eSAnsuel Smith VER_0 = 0, 3553e2a20eSAnsuel Smith VER_0_1, 36c1997054SAmit Kucheria VER_1_X, 37c1997054SAmit Kucheria VER_2_X, 38c1997054SAmit Kucheria }; 39c1997054SAmit Kucheria 40634e11d5SAmit Kucheria enum tsens_irq_type { 41634e11d5SAmit Kucheria LOWER, 42634e11d5SAmit Kucheria UPPER, 4379125e03SAmit Kucheria CRITICAL, 44634e11d5SAmit Kucheria }; 45634e11d5SAmit Kucheria 4620a7a2dbSAmit Kucheria /** 4720a7a2dbSAmit Kucheria * struct tsens_sensor - data for each sensor connected to the tsens device 4869b628acSAmit Kucheria * @priv: tsens device instance that this sensor is connected to 4920a7a2dbSAmit Kucheria * @tzd: pointer to the thermal zone that this sensor is in 5020a7a2dbSAmit Kucheria * @offset: offset of temperature adjustment curve 5120a7a2dbSAmit Kucheria * @hw_id: HW ID can be used in case of platform-specific IDs 5220a7a2dbSAmit Kucheria * @slope: slope of temperature adjustment curve 5320a7a2dbSAmit Kucheria * @status: 8960-specific variable to track 8960 and 8660 status register offset 5420a7a2dbSAmit Kucheria */ 559066073cSRajendra Nayak struct tsens_sensor { 5669b628acSAmit Kucheria struct tsens_priv *priv; 579066073cSRajendra Nayak struct thermal_zone_device *tzd; 589066073cSRajendra Nayak int offset; 5966ad8a10SAmit Kucheria unsigned int hw_id; 609066073cSRajendra Nayak int slope; 619066073cSRajendra Nayak u32 status; 62b6f739daSStephan Gerhold int p1_calib_offset; 63b6f739daSStephan Gerhold int p2_calib_offset; 649066073cSRajendra Nayak }; 659066073cSRajendra Nayak 669066073cSRajendra Nayak /** 679066073cSRajendra Nayak * struct tsens_ops - operations as supported by the tsens device 689066073cSRajendra Nayak * @init: Function to initialize the tsens device 699066073cSRajendra Nayak * @calibrate: Function to calibrate the tsens device 709066073cSRajendra Nayak * @get_temp: Function which returns the temp in millidegC 719066073cSRajendra Nayak * @enable: Function to enable (clocks/power) tsens device 729066073cSRajendra Nayak * @disable: Function to disable the tsens device 739066073cSRajendra Nayak * @suspend: Function to suspend the tsens device 749066073cSRajendra Nayak * @resume: Function to resume the tsens device 759066073cSRajendra Nayak */ 769066073cSRajendra Nayak struct tsens_ops { 779066073cSRajendra Nayak /* mandatory callbacks */ 7868b3314dSAmit Kucheria int (*init)(struct tsens_priv *priv); 7968b3314dSAmit Kucheria int (*calibrate)(struct tsens_priv *priv); 80e604bdd2SAmit Kucheria int (*get_temp)(const struct tsens_sensor *s, int *temp); 819066073cSRajendra Nayak /* optional callbacks */ 8268b3314dSAmit Kucheria int (*enable)(struct tsens_priv *priv, int i); 8368b3314dSAmit Kucheria void (*disable)(struct tsens_priv *priv); 8468b3314dSAmit Kucheria int (*suspend)(struct tsens_priv *priv); 8568b3314dSAmit Kucheria int (*resume)(struct tsens_priv *priv); 869066073cSRajendra Nayak }; 879066073cSRajendra Nayak 88c1997054SAmit Kucheria #define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \ 89c1997054SAmit Kucheria [_name##_##0] = REG_FIELD(_offset, _startbit, _stopbit), \ 90c1997054SAmit Kucheria [_name##_##1] = REG_FIELD(_offset + 4, _startbit, _stopbit), \ 91c1997054SAmit Kucheria [_name##_##2] = REG_FIELD(_offset + 8, _startbit, _stopbit), \ 92c1997054SAmit Kucheria [_name##_##3] = REG_FIELD(_offset + 12, _startbit, _stopbit), \ 93c1997054SAmit Kucheria [_name##_##4] = REG_FIELD(_offset + 16, _startbit, _stopbit), \ 94c1997054SAmit Kucheria [_name##_##5] = REG_FIELD(_offset + 20, _startbit, _stopbit), \ 95c1997054SAmit Kucheria [_name##_##6] = REG_FIELD(_offset + 24, _startbit, _stopbit), \ 96c1997054SAmit Kucheria [_name##_##7] = REG_FIELD(_offset + 28, _startbit, _stopbit), \ 97c1997054SAmit Kucheria [_name##_##8] = REG_FIELD(_offset + 32, _startbit, _stopbit), \ 98c1997054SAmit Kucheria [_name##_##9] = REG_FIELD(_offset + 36, _startbit, _stopbit), \ 99c1997054SAmit Kucheria [_name##_##10] = REG_FIELD(_offset + 40, _startbit, _stopbit) 100c130a760SAmit Kucheria 101c1997054SAmit Kucheria #define REG_FIELD_FOR_EACH_SENSOR16(_name, _offset, _startbit, _stopbit) \ 102c1997054SAmit Kucheria [_name##_##0] = REG_FIELD(_offset, _startbit, _stopbit), \ 103c1997054SAmit Kucheria [_name##_##1] = REG_FIELD(_offset + 4, _startbit, _stopbit), \ 104c1997054SAmit Kucheria [_name##_##2] = REG_FIELD(_offset + 8, _startbit, _stopbit), \ 105c1997054SAmit Kucheria [_name##_##3] = REG_FIELD(_offset + 12, _startbit, _stopbit), \ 106c1997054SAmit Kucheria [_name##_##4] = REG_FIELD(_offset + 16, _startbit, _stopbit), \ 107c1997054SAmit Kucheria [_name##_##5] = REG_FIELD(_offset + 20, _startbit, _stopbit), \ 108c1997054SAmit Kucheria [_name##_##6] = REG_FIELD(_offset + 24, _startbit, _stopbit), \ 109c1997054SAmit Kucheria [_name##_##7] = REG_FIELD(_offset + 28, _startbit, _stopbit), \ 110c1997054SAmit Kucheria [_name##_##8] = REG_FIELD(_offset + 32, _startbit, _stopbit), \ 111c1997054SAmit Kucheria [_name##_##9] = REG_FIELD(_offset + 36, _startbit, _stopbit), \ 112c1997054SAmit Kucheria [_name##_##10] = REG_FIELD(_offset + 40, _startbit, _stopbit), \ 113c1997054SAmit Kucheria [_name##_##11] = REG_FIELD(_offset + 44, _startbit, _stopbit), \ 114c1997054SAmit Kucheria [_name##_##12] = REG_FIELD(_offset + 48, _startbit, _stopbit), \ 115c1997054SAmit Kucheria [_name##_##13] = REG_FIELD(_offset + 52, _startbit, _stopbit), \ 116c1997054SAmit Kucheria [_name##_##14] = REG_FIELD(_offset + 56, _startbit, _stopbit), \ 117c1997054SAmit Kucheria [_name##_##15] = REG_FIELD(_offset + 60, _startbit, _stopbit) 118c1997054SAmit Kucheria 119634e11d5SAmit Kucheria #define REG_FIELD_SPLIT_BITS_0_15(_name, _offset) \ 120634e11d5SAmit Kucheria [_name##_##0] = REG_FIELD(_offset, 0, 0), \ 121634e11d5SAmit Kucheria [_name##_##1] = REG_FIELD(_offset, 1, 1), \ 122634e11d5SAmit Kucheria [_name##_##2] = REG_FIELD(_offset, 2, 2), \ 123634e11d5SAmit Kucheria [_name##_##3] = REG_FIELD(_offset, 3, 3), \ 124634e11d5SAmit Kucheria [_name##_##4] = REG_FIELD(_offset, 4, 4), \ 125634e11d5SAmit Kucheria [_name##_##5] = REG_FIELD(_offset, 5, 5), \ 126634e11d5SAmit Kucheria [_name##_##6] = REG_FIELD(_offset, 6, 6), \ 127634e11d5SAmit Kucheria [_name##_##7] = REG_FIELD(_offset, 7, 7), \ 128634e11d5SAmit Kucheria [_name##_##8] = REG_FIELD(_offset, 8, 8), \ 129634e11d5SAmit Kucheria [_name##_##9] = REG_FIELD(_offset, 9, 9), \ 130634e11d5SAmit Kucheria [_name##_##10] = REG_FIELD(_offset, 10, 10), \ 131634e11d5SAmit Kucheria [_name##_##11] = REG_FIELD(_offset, 11, 11), \ 132634e11d5SAmit Kucheria [_name##_##12] = REG_FIELD(_offset, 12, 12), \ 133634e11d5SAmit Kucheria [_name##_##13] = REG_FIELD(_offset, 13, 13), \ 134634e11d5SAmit Kucheria [_name##_##14] = REG_FIELD(_offset, 14, 14), \ 135634e11d5SAmit Kucheria [_name##_##15] = REG_FIELD(_offset, 15, 15) 136634e11d5SAmit Kucheria 137634e11d5SAmit Kucheria #define REG_FIELD_SPLIT_BITS_16_31(_name, _offset) \ 138634e11d5SAmit Kucheria [_name##_##0] = REG_FIELD(_offset, 16, 16), \ 139634e11d5SAmit Kucheria [_name##_##1] = REG_FIELD(_offset, 17, 17), \ 140634e11d5SAmit Kucheria [_name##_##2] = REG_FIELD(_offset, 18, 18), \ 141634e11d5SAmit Kucheria [_name##_##3] = REG_FIELD(_offset, 19, 19), \ 142634e11d5SAmit Kucheria [_name##_##4] = REG_FIELD(_offset, 20, 20), \ 143634e11d5SAmit Kucheria [_name##_##5] = REG_FIELD(_offset, 21, 21), \ 144634e11d5SAmit Kucheria [_name##_##6] = REG_FIELD(_offset, 22, 22), \ 145634e11d5SAmit Kucheria [_name##_##7] = REG_FIELD(_offset, 23, 23), \ 146634e11d5SAmit Kucheria [_name##_##8] = REG_FIELD(_offset, 24, 24), \ 147634e11d5SAmit Kucheria [_name##_##9] = REG_FIELD(_offset, 25, 25), \ 148634e11d5SAmit Kucheria [_name##_##10] = REG_FIELD(_offset, 26, 26), \ 149634e11d5SAmit Kucheria [_name##_##11] = REG_FIELD(_offset, 27, 27), \ 150634e11d5SAmit Kucheria [_name##_##12] = REG_FIELD(_offset, 28, 28), \ 151634e11d5SAmit Kucheria [_name##_##13] = REG_FIELD(_offset, 29, 29), \ 152634e11d5SAmit Kucheria [_name##_##14] = REG_FIELD(_offset, 30, 30), \ 153634e11d5SAmit Kucheria [_name##_##15] = REG_FIELD(_offset, 31, 31) 154634e11d5SAmit Kucheria 155634e11d5SAmit Kucheria /* 156634e11d5SAmit Kucheria * reg_field IDs to use as an index into an array 157634e11d5SAmit Kucheria * If you change the order of the entries, check the devm_regmap_field_alloc() 158634e11d5SAmit Kucheria * calls in init_common() 159634e11d5SAmit Kucheria */ 160c1997054SAmit Kucheria enum regfield_ids { 161c1997054SAmit Kucheria /* ----- SROT ------ */ 162c1997054SAmit Kucheria /* HW_VER */ 163634e11d5SAmit Kucheria VER_MAJOR, 164c1997054SAmit Kucheria VER_MINOR, 165c1997054SAmit Kucheria VER_STEP, 166c1997054SAmit Kucheria /* CTRL_OFFSET */ 167634e11d5SAmit Kucheria TSENS_EN, 168c1997054SAmit Kucheria TSENS_SW_RST, 169c1997054SAmit Kucheria SENSOR_EN, 170c1997054SAmit Kucheria CODE_OR_TEMP, 171c1997054SAmit Kucheria 172c1997054SAmit Kucheria /* ----- TM ------ */ 173634e11d5SAmit Kucheria /* TRDY */ 174634e11d5SAmit Kucheria TRDY, 175634e11d5SAmit Kucheria /* INTERRUPT ENABLE */ 176634e11d5SAmit Kucheria INT_EN, /* v2+ has separate enables for crit, upper and lower irq */ 177c1997054SAmit Kucheria /* STATUS */ 178634e11d5SAmit Kucheria LAST_TEMP_0, /* Last temperature reading */ 179c1997054SAmit Kucheria LAST_TEMP_1, 180c1997054SAmit Kucheria LAST_TEMP_2, 181c1997054SAmit Kucheria LAST_TEMP_3, 182c1997054SAmit Kucheria LAST_TEMP_4, 183c1997054SAmit Kucheria LAST_TEMP_5, 184c1997054SAmit Kucheria LAST_TEMP_6, 185c1997054SAmit Kucheria LAST_TEMP_7, 186c1997054SAmit Kucheria LAST_TEMP_8, 187c1997054SAmit Kucheria LAST_TEMP_9, 188c1997054SAmit Kucheria LAST_TEMP_10, 189c1997054SAmit Kucheria LAST_TEMP_11, 190c1997054SAmit Kucheria LAST_TEMP_12, 191c1997054SAmit Kucheria LAST_TEMP_13, 192c1997054SAmit Kucheria LAST_TEMP_14, 193c1997054SAmit Kucheria LAST_TEMP_15, 194634e11d5SAmit Kucheria VALID_0, /* VALID reading or not */ 195c1997054SAmit Kucheria VALID_1, 196c1997054SAmit Kucheria VALID_2, 197c1997054SAmit Kucheria VALID_3, 198c1997054SAmit Kucheria VALID_4, 199c1997054SAmit Kucheria VALID_5, 200c1997054SAmit Kucheria VALID_6, 201c1997054SAmit Kucheria VALID_7, 202c1997054SAmit Kucheria VALID_8, 203c1997054SAmit Kucheria VALID_9, 204c1997054SAmit Kucheria VALID_10, 205c1997054SAmit Kucheria VALID_11, 206c1997054SAmit Kucheria VALID_12, 207c1997054SAmit Kucheria VALID_13, 208c1997054SAmit Kucheria VALID_14, 209c1997054SAmit Kucheria VALID_15, 210634e11d5SAmit Kucheria LOWER_STATUS_0, /* LOWER threshold violated */ 211634e11d5SAmit Kucheria LOWER_STATUS_1, 212634e11d5SAmit Kucheria LOWER_STATUS_2, 213634e11d5SAmit Kucheria LOWER_STATUS_3, 214634e11d5SAmit Kucheria LOWER_STATUS_4, 215634e11d5SAmit Kucheria LOWER_STATUS_5, 216634e11d5SAmit Kucheria LOWER_STATUS_6, 217634e11d5SAmit Kucheria LOWER_STATUS_7, 218634e11d5SAmit Kucheria LOWER_STATUS_8, 219634e11d5SAmit Kucheria LOWER_STATUS_9, 220634e11d5SAmit Kucheria LOWER_STATUS_10, 221634e11d5SAmit Kucheria LOWER_STATUS_11, 222634e11d5SAmit Kucheria LOWER_STATUS_12, 223634e11d5SAmit Kucheria LOWER_STATUS_13, 224634e11d5SAmit Kucheria LOWER_STATUS_14, 225634e11d5SAmit Kucheria LOWER_STATUS_15, 226634e11d5SAmit Kucheria LOW_INT_STATUS_0, /* LOWER interrupt status */ 227634e11d5SAmit Kucheria LOW_INT_STATUS_1, 228634e11d5SAmit Kucheria LOW_INT_STATUS_2, 229634e11d5SAmit Kucheria LOW_INT_STATUS_3, 230634e11d5SAmit Kucheria LOW_INT_STATUS_4, 231634e11d5SAmit Kucheria LOW_INT_STATUS_5, 232634e11d5SAmit Kucheria LOW_INT_STATUS_6, 233634e11d5SAmit Kucheria LOW_INT_STATUS_7, 234634e11d5SAmit Kucheria LOW_INT_STATUS_8, 235634e11d5SAmit Kucheria LOW_INT_STATUS_9, 236634e11d5SAmit Kucheria LOW_INT_STATUS_10, 237634e11d5SAmit Kucheria LOW_INT_STATUS_11, 238634e11d5SAmit Kucheria LOW_INT_STATUS_12, 239634e11d5SAmit Kucheria LOW_INT_STATUS_13, 240634e11d5SAmit Kucheria LOW_INT_STATUS_14, 241634e11d5SAmit Kucheria LOW_INT_STATUS_15, 242634e11d5SAmit Kucheria LOW_INT_CLEAR_0, /* LOWER interrupt clear */ 243634e11d5SAmit Kucheria LOW_INT_CLEAR_1, 244634e11d5SAmit Kucheria LOW_INT_CLEAR_2, 245634e11d5SAmit Kucheria LOW_INT_CLEAR_3, 246634e11d5SAmit Kucheria LOW_INT_CLEAR_4, 247634e11d5SAmit Kucheria LOW_INT_CLEAR_5, 248634e11d5SAmit Kucheria LOW_INT_CLEAR_6, 249634e11d5SAmit Kucheria LOW_INT_CLEAR_7, 250634e11d5SAmit Kucheria LOW_INT_CLEAR_8, 251634e11d5SAmit Kucheria LOW_INT_CLEAR_9, 252634e11d5SAmit Kucheria LOW_INT_CLEAR_10, 253634e11d5SAmit Kucheria LOW_INT_CLEAR_11, 254634e11d5SAmit Kucheria LOW_INT_CLEAR_12, 255634e11d5SAmit Kucheria LOW_INT_CLEAR_13, 256634e11d5SAmit Kucheria LOW_INT_CLEAR_14, 257634e11d5SAmit Kucheria LOW_INT_CLEAR_15, 258634e11d5SAmit Kucheria LOW_INT_MASK_0, /* LOWER interrupt mask */ 259634e11d5SAmit Kucheria LOW_INT_MASK_1, 260634e11d5SAmit Kucheria LOW_INT_MASK_2, 261634e11d5SAmit Kucheria LOW_INT_MASK_3, 262634e11d5SAmit Kucheria LOW_INT_MASK_4, 263634e11d5SAmit Kucheria LOW_INT_MASK_5, 264634e11d5SAmit Kucheria LOW_INT_MASK_6, 265634e11d5SAmit Kucheria LOW_INT_MASK_7, 266634e11d5SAmit Kucheria LOW_INT_MASK_8, 267634e11d5SAmit Kucheria LOW_INT_MASK_9, 268634e11d5SAmit Kucheria LOW_INT_MASK_10, 269634e11d5SAmit Kucheria LOW_INT_MASK_11, 270634e11d5SAmit Kucheria LOW_INT_MASK_12, 271634e11d5SAmit Kucheria LOW_INT_MASK_13, 272634e11d5SAmit Kucheria LOW_INT_MASK_14, 273634e11d5SAmit Kucheria LOW_INT_MASK_15, 274634e11d5SAmit Kucheria LOW_THRESH_0, /* LOWER threshold values */ 275634e11d5SAmit Kucheria LOW_THRESH_1, 276634e11d5SAmit Kucheria LOW_THRESH_2, 277634e11d5SAmit Kucheria LOW_THRESH_3, 278634e11d5SAmit Kucheria LOW_THRESH_4, 279634e11d5SAmit Kucheria LOW_THRESH_5, 280634e11d5SAmit Kucheria LOW_THRESH_6, 281634e11d5SAmit Kucheria LOW_THRESH_7, 282634e11d5SAmit Kucheria LOW_THRESH_8, 283634e11d5SAmit Kucheria LOW_THRESH_9, 284634e11d5SAmit Kucheria LOW_THRESH_10, 285634e11d5SAmit Kucheria LOW_THRESH_11, 286634e11d5SAmit Kucheria LOW_THRESH_12, 287634e11d5SAmit Kucheria LOW_THRESH_13, 288634e11d5SAmit Kucheria LOW_THRESH_14, 289634e11d5SAmit Kucheria LOW_THRESH_15, 290634e11d5SAmit Kucheria UPPER_STATUS_0, /* UPPER threshold violated */ 291634e11d5SAmit Kucheria UPPER_STATUS_1, 292634e11d5SAmit Kucheria UPPER_STATUS_2, 293634e11d5SAmit Kucheria UPPER_STATUS_3, 294634e11d5SAmit Kucheria UPPER_STATUS_4, 295634e11d5SAmit Kucheria UPPER_STATUS_5, 296634e11d5SAmit Kucheria UPPER_STATUS_6, 297634e11d5SAmit Kucheria UPPER_STATUS_7, 298634e11d5SAmit Kucheria UPPER_STATUS_8, 299634e11d5SAmit Kucheria UPPER_STATUS_9, 300634e11d5SAmit Kucheria UPPER_STATUS_10, 301634e11d5SAmit Kucheria UPPER_STATUS_11, 302634e11d5SAmit Kucheria UPPER_STATUS_12, 303634e11d5SAmit Kucheria UPPER_STATUS_13, 304634e11d5SAmit Kucheria UPPER_STATUS_14, 305634e11d5SAmit Kucheria UPPER_STATUS_15, 306634e11d5SAmit Kucheria UP_INT_STATUS_0, /* UPPER interrupt status */ 307634e11d5SAmit Kucheria UP_INT_STATUS_1, 308634e11d5SAmit Kucheria UP_INT_STATUS_2, 309634e11d5SAmit Kucheria UP_INT_STATUS_3, 310634e11d5SAmit Kucheria UP_INT_STATUS_4, 311634e11d5SAmit Kucheria UP_INT_STATUS_5, 312634e11d5SAmit Kucheria UP_INT_STATUS_6, 313634e11d5SAmit Kucheria UP_INT_STATUS_7, 314634e11d5SAmit Kucheria UP_INT_STATUS_8, 315634e11d5SAmit Kucheria UP_INT_STATUS_9, 316634e11d5SAmit Kucheria UP_INT_STATUS_10, 317634e11d5SAmit Kucheria UP_INT_STATUS_11, 318634e11d5SAmit Kucheria UP_INT_STATUS_12, 319634e11d5SAmit Kucheria UP_INT_STATUS_13, 320634e11d5SAmit Kucheria UP_INT_STATUS_14, 321634e11d5SAmit Kucheria UP_INT_STATUS_15, 322634e11d5SAmit Kucheria UP_INT_CLEAR_0, /* UPPER interrupt clear */ 323634e11d5SAmit Kucheria UP_INT_CLEAR_1, 324634e11d5SAmit Kucheria UP_INT_CLEAR_2, 325634e11d5SAmit Kucheria UP_INT_CLEAR_3, 326634e11d5SAmit Kucheria UP_INT_CLEAR_4, 327634e11d5SAmit Kucheria UP_INT_CLEAR_5, 328634e11d5SAmit Kucheria UP_INT_CLEAR_6, 329634e11d5SAmit Kucheria UP_INT_CLEAR_7, 330634e11d5SAmit Kucheria UP_INT_CLEAR_8, 331634e11d5SAmit Kucheria UP_INT_CLEAR_9, 332634e11d5SAmit Kucheria UP_INT_CLEAR_10, 333634e11d5SAmit Kucheria UP_INT_CLEAR_11, 334634e11d5SAmit Kucheria UP_INT_CLEAR_12, 335634e11d5SAmit Kucheria UP_INT_CLEAR_13, 336634e11d5SAmit Kucheria UP_INT_CLEAR_14, 337634e11d5SAmit Kucheria UP_INT_CLEAR_15, 338634e11d5SAmit Kucheria UP_INT_MASK_0, /* UPPER interrupt mask */ 339634e11d5SAmit Kucheria UP_INT_MASK_1, 340634e11d5SAmit Kucheria UP_INT_MASK_2, 341634e11d5SAmit Kucheria UP_INT_MASK_3, 342634e11d5SAmit Kucheria UP_INT_MASK_4, 343634e11d5SAmit Kucheria UP_INT_MASK_5, 344634e11d5SAmit Kucheria UP_INT_MASK_6, 345634e11d5SAmit Kucheria UP_INT_MASK_7, 346634e11d5SAmit Kucheria UP_INT_MASK_8, 347634e11d5SAmit Kucheria UP_INT_MASK_9, 348634e11d5SAmit Kucheria UP_INT_MASK_10, 349634e11d5SAmit Kucheria UP_INT_MASK_11, 350634e11d5SAmit Kucheria UP_INT_MASK_12, 351634e11d5SAmit Kucheria UP_INT_MASK_13, 352634e11d5SAmit Kucheria UP_INT_MASK_14, 353634e11d5SAmit Kucheria UP_INT_MASK_15, 354634e11d5SAmit Kucheria UP_THRESH_0, /* UPPER threshold values */ 355634e11d5SAmit Kucheria UP_THRESH_1, 356634e11d5SAmit Kucheria UP_THRESH_2, 357634e11d5SAmit Kucheria UP_THRESH_3, 358634e11d5SAmit Kucheria UP_THRESH_4, 359634e11d5SAmit Kucheria UP_THRESH_5, 360634e11d5SAmit Kucheria UP_THRESH_6, 361634e11d5SAmit Kucheria UP_THRESH_7, 362634e11d5SAmit Kucheria UP_THRESH_8, 363634e11d5SAmit Kucheria UP_THRESH_9, 364634e11d5SAmit Kucheria UP_THRESH_10, 365634e11d5SAmit Kucheria UP_THRESH_11, 366634e11d5SAmit Kucheria UP_THRESH_12, 367634e11d5SAmit Kucheria UP_THRESH_13, 368634e11d5SAmit Kucheria UP_THRESH_14, 369634e11d5SAmit Kucheria UP_THRESH_15, 370634e11d5SAmit Kucheria CRITICAL_STATUS_0, /* CRITICAL threshold violated */ 371634e11d5SAmit Kucheria CRITICAL_STATUS_1, 372634e11d5SAmit Kucheria CRITICAL_STATUS_2, 373634e11d5SAmit Kucheria CRITICAL_STATUS_3, 374634e11d5SAmit Kucheria CRITICAL_STATUS_4, 375634e11d5SAmit Kucheria CRITICAL_STATUS_5, 376634e11d5SAmit Kucheria CRITICAL_STATUS_6, 377634e11d5SAmit Kucheria CRITICAL_STATUS_7, 378634e11d5SAmit Kucheria CRITICAL_STATUS_8, 379634e11d5SAmit Kucheria CRITICAL_STATUS_9, 380634e11d5SAmit Kucheria CRITICAL_STATUS_10, 381634e11d5SAmit Kucheria CRITICAL_STATUS_11, 382634e11d5SAmit Kucheria CRITICAL_STATUS_12, 383634e11d5SAmit Kucheria CRITICAL_STATUS_13, 384634e11d5SAmit Kucheria CRITICAL_STATUS_14, 385634e11d5SAmit Kucheria CRITICAL_STATUS_15, 38679125e03SAmit Kucheria CRIT_INT_STATUS_0, /* CRITICAL interrupt status */ 38779125e03SAmit Kucheria CRIT_INT_STATUS_1, 38879125e03SAmit Kucheria CRIT_INT_STATUS_2, 38979125e03SAmit Kucheria CRIT_INT_STATUS_3, 39079125e03SAmit Kucheria CRIT_INT_STATUS_4, 39179125e03SAmit Kucheria CRIT_INT_STATUS_5, 39279125e03SAmit Kucheria CRIT_INT_STATUS_6, 39379125e03SAmit Kucheria CRIT_INT_STATUS_7, 39479125e03SAmit Kucheria CRIT_INT_STATUS_8, 39579125e03SAmit Kucheria CRIT_INT_STATUS_9, 39679125e03SAmit Kucheria CRIT_INT_STATUS_10, 39779125e03SAmit Kucheria CRIT_INT_STATUS_11, 39879125e03SAmit Kucheria CRIT_INT_STATUS_12, 39979125e03SAmit Kucheria CRIT_INT_STATUS_13, 40079125e03SAmit Kucheria CRIT_INT_STATUS_14, 40179125e03SAmit Kucheria CRIT_INT_STATUS_15, 40279125e03SAmit Kucheria CRIT_INT_CLEAR_0, /* CRITICAL interrupt clear */ 40379125e03SAmit Kucheria CRIT_INT_CLEAR_1, 40479125e03SAmit Kucheria CRIT_INT_CLEAR_2, 40579125e03SAmit Kucheria CRIT_INT_CLEAR_3, 40679125e03SAmit Kucheria CRIT_INT_CLEAR_4, 40779125e03SAmit Kucheria CRIT_INT_CLEAR_5, 40879125e03SAmit Kucheria CRIT_INT_CLEAR_6, 40979125e03SAmit Kucheria CRIT_INT_CLEAR_7, 41079125e03SAmit Kucheria CRIT_INT_CLEAR_8, 41179125e03SAmit Kucheria CRIT_INT_CLEAR_9, 41279125e03SAmit Kucheria CRIT_INT_CLEAR_10, 41379125e03SAmit Kucheria CRIT_INT_CLEAR_11, 41479125e03SAmit Kucheria CRIT_INT_CLEAR_12, 41579125e03SAmit Kucheria CRIT_INT_CLEAR_13, 41679125e03SAmit Kucheria CRIT_INT_CLEAR_14, 41779125e03SAmit Kucheria CRIT_INT_CLEAR_15, 41879125e03SAmit Kucheria CRIT_INT_MASK_0, /* CRITICAL interrupt mask */ 41979125e03SAmit Kucheria CRIT_INT_MASK_1, 42079125e03SAmit Kucheria CRIT_INT_MASK_2, 42179125e03SAmit Kucheria CRIT_INT_MASK_3, 42279125e03SAmit Kucheria CRIT_INT_MASK_4, 42379125e03SAmit Kucheria CRIT_INT_MASK_5, 42479125e03SAmit Kucheria CRIT_INT_MASK_6, 42579125e03SAmit Kucheria CRIT_INT_MASK_7, 42679125e03SAmit Kucheria CRIT_INT_MASK_8, 42779125e03SAmit Kucheria CRIT_INT_MASK_9, 42879125e03SAmit Kucheria CRIT_INT_MASK_10, 42979125e03SAmit Kucheria CRIT_INT_MASK_11, 43079125e03SAmit Kucheria CRIT_INT_MASK_12, 43179125e03SAmit Kucheria CRIT_INT_MASK_13, 43279125e03SAmit Kucheria CRIT_INT_MASK_14, 43379125e03SAmit Kucheria CRIT_INT_MASK_15, 43479125e03SAmit Kucheria CRIT_THRESH_0, /* CRITICAL threshold values */ 43579125e03SAmit Kucheria CRIT_THRESH_1, 43679125e03SAmit Kucheria CRIT_THRESH_2, 43779125e03SAmit Kucheria CRIT_THRESH_3, 43879125e03SAmit Kucheria CRIT_THRESH_4, 43979125e03SAmit Kucheria CRIT_THRESH_5, 44079125e03SAmit Kucheria CRIT_THRESH_6, 44179125e03SAmit Kucheria CRIT_THRESH_7, 44279125e03SAmit Kucheria CRIT_THRESH_8, 44379125e03SAmit Kucheria CRIT_THRESH_9, 44479125e03SAmit Kucheria CRIT_THRESH_10, 44579125e03SAmit Kucheria CRIT_THRESH_11, 44679125e03SAmit Kucheria CRIT_THRESH_12, 44779125e03SAmit Kucheria CRIT_THRESH_13, 44879125e03SAmit Kucheria CRIT_THRESH_14, 44979125e03SAmit Kucheria CRIT_THRESH_15, 450d22066c1SAmit Kucheria 451d22066c1SAmit Kucheria /* WATCHDOG */ 452d22066c1SAmit Kucheria WDOG_BARK_STATUS, 453d22066c1SAmit Kucheria WDOG_BARK_CLEAR, 454d22066c1SAmit Kucheria WDOG_BARK_MASK, 455d22066c1SAmit Kucheria WDOG_BARK_COUNT, 456d22066c1SAmit Kucheria 457d22066c1SAmit Kucheria /* CYCLE COMPLETION MONITOR */ 458d22066c1SAmit Kucheria CC_MON_STATUS, 459d22066c1SAmit Kucheria CC_MON_CLEAR, 460d22066c1SAmit Kucheria CC_MON_MASK, 461d22066c1SAmit Kucheria 462c1997054SAmit Kucheria MIN_STATUS_0, /* MIN threshold violated */ 463c1997054SAmit Kucheria MIN_STATUS_1, 464c1997054SAmit Kucheria MIN_STATUS_2, 465c1997054SAmit Kucheria MIN_STATUS_3, 466c1997054SAmit Kucheria MIN_STATUS_4, 467c1997054SAmit Kucheria MIN_STATUS_5, 468c1997054SAmit Kucheria MIN_STATUS_6, 469c1997054SAmit Kucheria MIN_STATUS_7, 470c1997054SAmit Kucheria MIN_STATUS_8, 471c1997054SAmit Kucheria MIN_STATUS_9, 472c1997054SAmit Kucheria MIN_STATUS_10, 473c1997054SAmit Kucheria MIN_STATUS_11, 474c1997054SAmit Kucheria MIN_STATUS_12, 475c1997054SAmit Kucheria MIN_STATUS_13, 476c1997054SAmit Kucheria MIN_STATUS_14, 477c1997054SAmit Kucheria MIN_STATUS_15, 478c1997054SAmit Kucheria MAX_STATUS_0, /* MAX threshold violated */ 479c1997054SAmit Kucheria MAX_STATUS_1, 480c1997054SAmit Kucheria MAX_STATUS_2, 481c1997054SAmit Kucheria MAX_STATUS_3, 482c1997054SAmit Kucheria MAX_STATUS_4, 483c1997054SAmit Kucheria MAX_STATUS_5, 484c1997054SAmit Kucheria MAX_STATUS_6, 485c1997054SAmit Kucheria MAX_STATUS_7, 486c1997054SAmit Kucheria MAX_STATUS_8, 487c1997054SAmit Kucheria MAX_STATUS_9, 488c1997054SAmit Kucheria MAX_STATUS_10, 489c1997054SAmit Kucheria MAX_STATUS_11, 490c1997054SAmit Kucheria MAX_STATUS_12, 491c1997054SAmit Kucheria MAX_STATUS_13, 492c1997054SAmit Kucheria MAX_STATUS_14, 493c1997054SAmit Kucheria MAX_STATUS_15, 494c1997054SAmit Kucheria 495c1997054SAmit Kucheria /* Keep last */ 496c1997054SAmit Kucheria MAX_REGFIELDS 497c1997054SAmit Kucheria }; 498c1997054SAmit Kucheria 499c1997054SAmit Kucheria /** 500c1997054SAmit Kucheria * struct tsens_features - Features supported by the IP 501c1997054SAmit Kucheria * @ver_major: Major number of IP version 502c1997054SAmit Kucheria * @crit_int: does the IP support critical interrupts? 5034360af35SRobert Marko * @combo_int: does the IP use one IRQ for up, low and critical thresholds? 504c1997054SAmit Kucheria * @adc: do the sensors only output adc code (instead of temperature)? 505c1997054SAmit Kucheria * @srot_split: does the IP neatly splits the register space into SROT and TM, 506c1997054SAmit Kucheria * with SROT only being available to secure boot firmware? 507d22066c1SAmit Kucheria * @has_watchdog: does this IP support watchdog functionality? 5081b6e3e51SAmit Kucheria * @max_sensors: maximum sensors supported by this version of the IP 509f63bacedSRobert Marko * @trip_min_temp: minimum trip temperature supported by this version of the IP 510f63bacedSRobert Marko * @trip_max_temp: maximum trip temperature supported by this version of the IP 511c1997054SAmit Kucheria */ 512c1997054SAmit Kucheria struct tsens_features { 513c1997054SAmit Kucheria unsigned int ver_major; 514c1997054SAmit Kucheria unsigned int crit_int:1; 5154360af35SRobert Marko unsigned int combo_int:1; 516c1997054SAmit Kucheria unsigned int adc:1; 517c1997054SAmit Kucheria unsigned int srot_split:1; 518d22066c1SAmit Kucheria unsigned int has_watchdog:1; 5191b6e3e51SAmit Kucheria unsigned int max_sensors; 520f63bacedSRobert Marko int trip_min_temp; 521f63bacedSRobert Marko int trip_max_temp; 522c130a760SAmit Kucheria }; 523c130a760SAmit Kucheria 5249066073cSRajendra Nayak /** 5253c040ce0SAmit Kucheria * struct tsens_plat_data - tsens compile-time platform data 52620a7a2dbSAmit Kucheria * @num_sensors: Number of sensors supported by platform 5279066073cSRajendra Nayak * @ops: operations the tsens instance supports 5289066073cSRajendra Nayak * @hw_ids: Subset of sensors ids supported by platform, if not the first n 529c1997054SAmit Kucheria * @feat: features of the IP 530c1997054SAmit Kucheria * @fields: bitfield locations 5319066073cSRajendra Nayak */ 5323c040ce0SAmit Kucheria struct tsens_plat_data { 5339066073cSRajendra Nayak const u32 num_sensors; 5349066073cSRajendra Nayak const struct tsens_ops *ops; 5359066073cSRajendra Nayak unsigned int *hw_ids; 5360aef1ee5SAmit Kucheria struct tsens_features *feat; 537c1997054SAmit Kucheria const struct reg_field *fields; 5389066073cSRajendra Nayak }; 5399066073cSRajendra Nayak 54020a7a2dbSAmit Kucheria /** 54120a7a2dbSAmit Kucheria * struct tsens_context - Registers to be saved/restored across a context loss 54234859696SAmit Kucheria * @threshold: Threshold register value 54334859696SAmit Kucheria * @control: Control register value 54420a7a2dbSAmit Kucheria */ 5459066073cSRajendra Nayak struct tsens_context { 5469066073cSRajendra Nayak int threshold; 5479066073cSRajendra Nayak int control; 5489066073cSRajendra Nayak }; 5499066073cSRajendra Nayak 55020a7a2dbSAmit Kucheria /** 55124ae4472SAmit Kucheria * struct tsens_priv - private data for each instance of the tsens IP 55220a7a2dbSAmit Kucheria * @dev: pointer to struct device 55320a7a2dbSAmit Kucheria * @num_sensors: number of sensors enabled on this device 55420a7a2dbSAmit Kucheria * @tm_map: pointer to TM register address space 55520a7a2dbSAmit Kucheria * @srot_map: pointer to SROT register address space 55620a7a2dbSAmit Kucheria * @tm_offset: deal with old device trees that don't address TM and SROT 55720a7a2dbSAmit Kucheria * address space separately 55834859696SAmit Kucheria * @ul_lock: lock while processing upper/lower threshold interrupts 55979125e03SAmit Kucheria * @crit_lock: lock while processing critical threshold interrupts 560c1997054SAmit Kucheria * @rf: array of regmap_fields used to store value of the field 56120a7a2dbSAmit Kucheria * @ctx: registers to be saved and restored during suspend/resume 562c1997054SAmit Kucheria * @feat: features of the IP 563c1997054SAmit Kucheria * @fields: bitfield locations 56420a7a2dbSAmit Kucheria * @ops: pointer to list of callbacks supported by this device 5657c938f48SAmit Kucheria * @debug_root: pointer to debugfs dentry for all tsens 5667c938f48SAmit Kucheria * @debug: pointer to debugfs dentry for tsens controller 56720a7a2dbSAmit Kucheria * @sensor: list of sensors attached to this device 56820a7a2dbSAmit Kucheria */ 56924ae4472SAmit Kucheria struct tsens_priv { 5709066073cSRajendra Nayak struct device *dev; 5719066073cSRajendra Nayak u32 num_sensors; 57267b0f5e0SAmit Kucheria struct regmap *tm_map; 573a15525b5SAmit Kucheria struct regmap *srot_map; 5745b128398SAmit Kucheria u32 tm_offset; 575634e11d5SAmit Kucheria 576634e11d5SAmit Kucheria /* lock for upper/lower threshold interrupts */ 577634e11d5SAmit Kucheria spinlock_t ul_lock; 578634e11d5SAmit Kucheria 579c1997054SAmit Kucheria struct regmap_field *rf[MAX_REGFIELDS]; 5809066073cSRajendra Nayak struct tsens_context ctx; 5810aef1ee5SAmit Kucheria struct tsens_features *feat; 582c1997054SAmit Kucheria const struct reg_field *fields; 5839066073cSRajendra Nayak const struct tsens_ops *ops; 5847c938f48SAmit Kucheria 5857c938f48SAmit Kucheria struct dentry *debug_root; 5867c938f48SAmit Kucheria struct dentry *debug; 5877c938f48SAmit Kucheria 5880a8cdc8bSGustavo A. R. Silva struct tsens_sensor sensor[]; 5899066073cSRajendra Nayak }; 5909066073cSRajendra Nayak 591913d32e2SDmitry Baryshkov /** 592913d32e2SDmitry Baryshkov * struct tsens_single_value - internal representation of a single field inside nvmem calibration data 593913d32e2SDmitry Baryshkov * @idx: index into the u32 data array 594913d32e2SDmitry Baryshkov * @shift: the shift of the first bit in the value 595913d32e2SDmitry Baryshkov * @blob: index of the data blob to use for this cell 596913d32e2SDmitry Baryshkov */ 597913d32e2SDmitry Baryshkov struct tsens_single_value { 598913d32e2SDmitry Baryshkov u8 idx; 599913d32e2SDmitry Baryshkov u8 shift; 600913d32e2SDmitry Baryshkov u8 blob; 601913d32e2SDmitry Baryshkov }; 602913d32e2SDmitry Baryshkov 603913d32e2SDmitry Baryshkov /** 604913d32e2SDmitry Baryshkov * struct tsens_legacy_calibration_format - description of calibration data used when parsing the legacy nvmem blob 605913d32e2SDmitry Baryshkov * @base_len: the length of the base fields inside calibration data 606913d32e2SDmitry Baryshkov * @base_shift: the shift to be applied to base data 607913d32e2SDmitry Baryshkov * @sp_len: the length of the sN_pM fields inside calibration data 608913d32e2SDmitry Baryshkov * @mode: descriptor of the calibration mode field 609913d32e2SDmitry Baryshkov * @invalid: descriptor of the calibration mode invalid field 610913d32e2SDmitry Baryshkov * @base: descriptors of the base0 and base1 fields 611913d32e2SDmitry Baryshkov * @sp: descriptors of the sN_pM fields 612913d32e2SDmitry Baryshkov */ 613913d32e2SDmitry Baryshkov struct tsens_legacy_calibration_format { 614913d32e2SDmitry Baryshkov unsigned int base_len; 615913d32e2SDmitry Baryshkov unsigned int base_shift; 616913d32e2SDmitry Baryshkov unsigned int sp_len; 617913d32e2SDmitry Baryshkov /* just two bits */ 618913d32e2SDmitry Baryshkov struct tsens_single_value mode; 619913d32e2SDmitry Baryshkov /* on all platforms except 8974 invalid is the third bit of what downstream calls 'mode' */ 620913d32e2SDmitry Baryshkov struct tsens_single_value invalid; 621913d32e2SDmitry Baryshkov struct tsens_single_value base[2]; 622913d32e2SDmitry Baryshkov struct tsens_single_value sp[][2]; 623913d32e2SDmitry Baryshkov }; 624913d32e2SDmitry Baryshkov 62568b3314dSAmit Kucheria char *qfprom_read(struct device *dev, const char *cname); 626913d32e2SDmitry Baryshkov int tsens_read_calibration_legacy(struct tsens_priv *priv, 627913d32e2SDmitry Baryshkov const struct tsens_legacy_calibration_format *format, 628913d32e2SDmitry Baryshkov u32 *p1, u32 *p2, 629913d32e2SDmitry Baryshkov u32 *cdata, u32 *csel); 630439f2409SDmitry Baryshkov int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, bool backup); 631498d2457SDmitry Baryshkov int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift); 632498d2457SDmitry Baryshkov int tsens_calibrate_common(struct tsens_priv *priv); 63368b3314dSAmit Kucheria void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode); 63468b3314dSAmit Kucheria int init_common(struct tsens_priv *priv); 635e604bdd2SAmit Kucheria int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp); 636e604bdd2SAmit Kucheria int get_temp_common(const struct tsens_sensor *s, int *temp); 6379066073cSRajendra Nayak 638582a0c41SAmit Kucheria /* TSENS target */ 6390aef1ee5SAmit Kucheria extern struct tsens_plat_data data_8960; 640582a0c41SAmit Kucheria 641582a0c41SAmit Kucheria /* TSENS v0.1 targets */ 6424af164c1SStephan Gerhold extern struct tsens_plat_data data_8226, data_8909, data_8916, data_8939, data_8974, data_9607; 643582a0c41SAmit Kucheria 644e8c24c6fSAmit Kucheria /* TSENS v1 targets */ 645*9e4828b7SBarnabás Czémán extern struct tsens_plat_data data_tsens_v1, data_8937, data_8976, data_8956; 646e8c24c6fSAmit Kucheria 647191dc74bSAmit Kucheria /* TSENS v2 targets */ 6486840455dSRobert Marko extern struct tsens_plat_data data_8996, data_ipq8074, data_tsens_v2; 649840a5bd3SRajendra Nayak 6509066073cSRajendra Nayak #endif /* __QCOM_TSENS_H__ */ 651