0001
0002
0003
0004
0005
0006
0007 #ifndef __HWMON_BT1_PVT_H__
0008 #define __HWMON_BT1_PVT_H__
0009
0010 #include <linux/completion.h>
0011 #include <linux/hwmon.h>
0012 #include <linux/kernel.h>
0013 #include <linux/ktime.h>
0014 #include <linux/mutex.h>
0015 #include <linux/seqlock.h>
0016
0017
0018 #define PVT_CTRL 0x00
0019 #define PVT_CTRL_EN BIT(0)
0020 #define PVT_CTRL_MODE_FLD 1
0021 #define PVT_CTRL_MODE_MASK GENMASK(3, PVT_CTRL_MODE_FLD)
0022 #define PVT_CTRL_MODE_TEMP 0x0
0023 #define PVT_CTRL_MODE_VOLT 0x1
0024 #define PVT_CTRL_MODE_LVT 0x2
0025 #define PVT_CTRL_MODE_HVT 0x4
0026 #define PVT_CTRL_MODE_SVT 0x6
0027 #define PVT_CTRL_TRIM_FLD 4
0028 #define PVT_CTRL_TRIM_MASK GENMASK(8, PVT_CTRL_TRIM_FLD)
0029 #define PVT_DATA 0x04
0030 #define PVT_DATA_VALID BIT(10)
0031 #define PVT_DATA_DATA_FLD 0
0032 #define PVT_DATA_DATA_MASK GENMASK(9, PVT_DATA_DATA_FLD)
0033 #define PVT_TTHRES 0x08
0034 #define PVT_VTHRES 0x0C
0035 #define PVT_LTHRES 0x10
0036 #define PVT_HTHRES 0x14
0037 #define PVT_STHRES 0x18
0038 #define PVT_THRES_LO_FLD 0
0039 #define PVT_THRES_LO_MASK GENMASK(9, PVT_THRES_LO_FLD)
0040 #define PVT_THRES_HI_FLD 10
0041 #define PVT_THRES_HI_MASK GENMASK(19, PVT_THRES_HI_FLD)
0042 #define PVT_TTIMEOUT 0x1C
0043 #define PVT_INTR_STAT 0x20
0044 #define PVT_INTR_MASK 0x24
0045 #define PVT_RAW_INTR_STAT 0x28
0046 #define PVT_INTR_DVALID BIT(0)
0047 #define PVT_INTR_TTHRES_LO BIT(1)
0048 #define PVT_INTR_TTHRES_HI BIT(2)
0049 #define PVT_INTR_VTHRES_LO BIT(3)
0050 #define PVT_INTR_VTHRES_HI BIT(4)
0051 #define PVT_INTR_LTHRES_LO BIT(5)
0052 #define PVT_INTR_LTHRES_HI BIT(6)
0053 #define PVT_INTR_HTHRES_LO BIT(7)
0054 #define PVT_INTR_HTHRES_HI BIT(8)
0055 #define PVT_INTR_STHRES_LO BIT(9)
0056 #define PVT_INTR_STHRES_HI BIT(10)
0057 #define PVT_INTR_ALL GENMASK(10, 0)
0058 #define PVT_CLR_INTR 0x2C
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 #define PVT_TEMP_MIN -48380L
0085 #define PVT_TEMP_MAX 147438L
0086 #define PVT_TEMP_CHS 1
0087 #define PVT_VOLT_MIN 620L
0088 #define PVT_VOLT_MAX 1168L
0089 #define PVT_VOLT_CHS 4
0090 #define PVT_DATA_MIN 0
0091 #define PVT_DATA_MAX (PVT_DATA_DATA_MASK >> PVT_DATA_DATA_FLD)
0092 #define PVT_TRIM_MIN 0
0093 #define PVT_TRIM_MAX (PVT_CTRL_TRIM_MASK >> PVT_CTRL_TRIM_FLD)
0094 #define PVT_TRIM_TEMP 7130
0095 #define PVT_TRIM_STEP (PVT_TRIM_TEMP / PVT_TRIM_MAX)
0096 #define PVT_TRIM_DEF 0
0097 #define PVT_TOUT_MIN (NSEC_PER_SEC / 3000)
0098 #if defined(CONFIG_SENSORS_BT1_PVT_ALARMS)
0099 # define PVT_TOUT_DEF 60000
0100 #else
0101 # define PVT_TOUT_DEF 0
0102 #endif
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 enum pvt_sensor_type {
0115 PVT_SENSOR_FIRST,
0116 PVT_TEMP = PVT_SENSOR_FIRST,
0117 PVT_VOLT,
0118 PVT_LVT,
0119 PVT_HVT,
0120 PVT_SVT,
0121 PVT_SENSOR_LAST = PVT_SVT,
0122 PVT_SENSORS_NUM
0123 };
0124
0125
0126
0127
0128
0129
0130 enum pvt_clock_type {
0131 PVT_CLOCK_APB,
0132 PVT_CLOCK_REF,
0133 PVT_CLOCK_NUM
0134 };
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 struct pvt_sensor_info {
0149 int channel;
0150 const char *label;
0151 u32 mode;
0152 unsigned long thres_base;
0153 u32 thres_sts_lo;
0154 u32 thres_sts_hi;
0155 enum hwmon_sensor_types type;
0156 u32 attr_min_alarm;
0157 u32 attr_max_alarm;
0158 };
0159
0160 #define PVT_SENSOR_INFO(_ch, _label, _type, _mode, _thres) \
0161 { \
0162 .channel = _ch, \
0163 .label = _label, \
0164 .mode = PVT_CTRL_MODE_ ##_mode, \
0165 .thres_base = PVT_ ##_thres, \
0166 .thres_sts_lo = PVT_INTR_ ##_thres## _LO, \
0167 .thres_sts_hi = PVT_INTR_ ##_thres## _HI, \
0168 .type = _type, \
0169 .attr_min_alarm = _type## _min, \
0170 .attr_max_alarm = _type## _max, \
0171 }
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 struct pvt_cache {
0182 u32 data;
0183 #if defined(CONFIG_SENSORS_BT1_PVT_ALARMS)
0184 seqlock_t data_seqlock;
0185 u32 thres_sts_lo;
0186 u32 thres_sts_hi;
0187 #else
0188 struct completion conversion;
0189 #endif
0190 };
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207 struct pvt_hwmon {
0208 struct device *dev;
0209 struct device *hwmon;
0210
0211 void __iomem *regs;
0212 int irq;
0213
0214 struct clk_bulk_data clks[PVT_CLOCK_NUM];
0215
0216 struct mutex iface_mtx;
0217 enum pvt_sensor_type sensor;
0218 struct pvt_cache cache[PVT_SENSORS_NUM];
0219 ktime_t timeout;
0220 };
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 struct pvt_poly_term {
0231 unsigned int deg;
0232 long coef;
0233 long divider;
0234 long divider_leftover;
0235 };
0236
0237
0238
0239
0240
0241
0242 struct pvt_poly {
0243 long total_divider;
0244 struct pvt_poly_term terms[];
0245 };
0246
0247 #endif