Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1 | /* |
Dipen Parmar | 46f8ac6 | 2014-01-19 22:45:11 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | /* |
| 14 | * Qualcomm PMIC QPNP ADC driver header file |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #ifndef __QPNP_ADC_H |
| 19 | #define __QPNP_ADC_H |
| 20 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/list.h> |
| 23 | /** |
| 24 | * enum qpnp_vadc_channels - QPNP AMUX arbiter channels |
| 25 | */ |
| 26 | enum qpnp_vadc_channels { |
| 27 | USBIN = 0, |
| 28 | DCIN, |
| 29 | VCHG_SNS, |
| 30 | SPARE1_03, |
Siddartha Mohanadoss | 2cadeba | 2012-11-13 18:40:27 -0800 | [diff] [blame] | 31 | USB_ID_MV, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 32 | VCOIN, |
| 33 | VBAT_SNS, |
| 34 | VSYS, |
| 35 | DIE_TEMP, |
| 36 | REF_625MV, |
| 37 | REF_125V, |
| 38 | CHG_TEMP, |
| 39 | SPARE1, |
| 40 | SPARE2, |
| 41 | GND_REF, |
| 42 | VDD_VADC, |
| 43 | P_MUX1_1_1, |
| 44 | P_MUX2_1_1, |
| 45 | P_MUX3_1_1, |
| 46 | P_MUX4_1_1, |
| 47 | P_MUX5_1_1, |
| 48 | P_MUX6_1_1, |
| 49 | P_MUX7_1_1, |
| 50 | P_MUX8_1_1, |
| 51 | P_MUX9_1_1, |
| 52 | P_MUX10_1_1, |
| 53 | P_MUX11_1_1, |
| 54 | P_MUX12_1_1, |
| 55 | P_MUX13_1_1, |
| 56 | P_MUX14_1_1, |
| 57 | P_MUX15_1_1, |
| 58 | P_MUX16_1_1, |
| 59 | P_MUX1_1_3, |
| 60 | P_MUX2_1_3, |
| 61 | P_MUX3_1_3, |
| 62 | P_MUX4_1_3, |
| 63 | P_MUX5_1_3, |
| 64 | P_MUX6_1_3, |
| 65 | P_MUX7_1_3, |
| 66 | P_MUX8_1_3, |
| 67 | P_MUX9_1_3, |
| 68 | P_MUX10_1_3, |
| 69 | P_MUX11_1_3, |
| 70 | P_MUX12_1_3, |
| 71 | P_MUX13_1_3, |
| 72 | P_MUX14_1_3, |
| 73 | P_MUX15_1_3, |
| 74 | P_MUX16_1_3, |
| 75 | LR_MUX1_BATT_THERM, |
| 76 | LR_MUX2_BAT_ID, |
| 77 | LR_MUX3_XO_THERM, |
| 78 | LR_MUX4_AMUX_THM1, |
| 79 | LR_MUX5_AMUX_THM2, |
| 80 | LR_MUX6_AMUX_THM3, |
| 81 | LR_MUX7_HW_ID, |
| 82 | LR_MUX8_AMUX_THM4, |
| 83 | LR_MUX9_AMUX_THM5, |
Siddartha Mohanadoss | 2cadeba | 2012-11-13 18:40:27 -0800 | [diff] [blame] | 84 | LR_MUX10_USB_ID_LV, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 85 | AMUX_PU1, |
| 86 | AMUX_PU2, |
| 87 | LR_MUX3_BUF_XO_THERM_BUF, |
Siddartha Mohanadoss | 2cadeba | 2012-11-13 18:40:27 -0800 | [diff] [blame] | 88 | LR_MUX1_PU1_BAT_THERM = 112, |
| 89 | LR_MUX2_PU1_BAT_ID = 113, |
| 90 | LR_MUX3_PU1_XO_THERM = 114, |
| 91 | LR_MUX4_PU1_AMUX_THM1 = 115, |
| 92 | LR_MUX5_PU1_AMUX_THM2 = 116, |
| 93 | LR_MUX6_PU1_AMUX_THM3 = 117, |
| 94 | LR_MUX7_PU1_AMUX_HW_ID = 118, |
| 95 | LR_MUX8_PU1_AMUX_THM4 = 119, |
| 96 | LR_MUX9_PU1_AMUX_THM5 = 120, |
| 97 | LR_MUX10_PU1_AMUX_USB_ID_LV = 121, |
| 98 | LR_MUX3_BUF_PU1_XO_THERM_BUF = 124, |
| 99 | LR_MUX1_PU2_BAT_THERM = 176, |
| 100 | LR_MUX2_PU2_BAT_ID = 177, |
| 101 | LR_MUX3_PU2_XO_THERM = 178, |
| 102 | LR_MUX4_PU2_AMUX_THM1 = 179, |
| 103 | LR_MUX5_PU2_AMUX_THM2 = 180, |
| 104 | LR_MUX6_PU2_AMUX_THM3 = 181, |
| 105 | LR_MUX7_PU2_AMUX_HW_ID = 182, |
| 106 | LR_MUX8_PU2_AMUX_THM4 = 183, |
| 107 | LR_MUX9_PU2_AMUX_THM5 = 184, |
| 108 | LR_MUX10_PU2_AMUX_USB_ID_LV = 185, |
| 109 | LR_MUX3_BUF_PU2_XO_THERM_BUF = 188, |
| 110 | LR_MUX1_PU1_PU2_BAT_THERM = 240, |
| 111 | LR_MUX2_PU1_PU2_BAT_ID = 241, |
| 112 | LR_MUX3_PU1_PU2_XO_THERM = 242, |
| 113 | LR_MUX4_PU1_PU2_AMUX_THM1 = 243, |
| 114 | LR_MUX5_PU1_PU2_AMUX_THM2 = 244, |
| 115 | LR_MUX6_PU1_PU2_AMUX_THM3 = 245, |
| 116 | LR_MUX7_PU1_PU2_AMUX_HW_ID = 246, |
| 117 | LR_MUX8_PU1_PU2_AMUX_THM4 = 247, |
| 118 | LR_MUX9_PU1_PU2_AMUX_THM5 = 248, |
| 119 | LR_MUX10_PU1_PU2_AMUX_USB_ID_LV = 249, |
| 120 | LR_MUX3_BUF_PU1_PU2_XO_THERM_BUF = 252, |
| 121 | ALL_OFF = 255, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 122 | ADC_MAX_NUM, |
| 123 | }; |
| 124 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 125 | /** |
| 126 | * enum qpnp_iadc_channels - QPNP IADC channel list |
| 127 | */ |
| 128 | enum qpnp_iadc_channels { |
| 129 | INTERNAL_RSENSE = 0, |
| 130 | EXTERNAL_RSENSE, |
| 131 | ALT_LEAD_PAIR, |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 132 | GAIN_CALIBRATION_17P857MV, |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 133 | OFFSET_CALIBRATION_SHORT_CADC_LEADS, |
| 134 | OFFSET_CALIBRATION_CSP_CSN, |
| 135 | OFFSET_CALIBRATION_CSP2_CSN2, |
| 136 | IADC_MUX_NUM, |
| 137 | }; |
| 138 | |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 139 | #define QPNP_ADC_625_UV 625000 |
Siddartha Mohanadoss | 1c21831 | 2012-11-08 11:30:43 -0800 | [diff] [blame] | 140 | #define QPNP_ADC_HWMON_NAME_LENGTH 64 |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 141 | #define QPNP_MAX_PROP_NAME_LEN 32 |
| 142 | |
| 143 | /* Structure device for qpnp vadc */ |
| 144 | struct qpnp_vadc_chip; |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 145 | |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 146 | /* Structure device for qpnp iadc */ |
| 147 | struct qpnp_iadc_chip; |
| 148 | |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 149 | /* Structure device for qpnp adc tm */ |
| 150 | struct qpnp_adc_tm_chip; |
| 151 | |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 152 | /** |
| 153 | * enum qpnp_adc_decimation_type - Sampling rate supported. |
| 154 | * %DECIMATION_TYPE1: 512 |
| 155 | * %DECIMATION_TYPE2: 1K |
| 156 | * %DECIMATION_TYPE3: 2K |
| 157 | * %DECIMATION_TYPE4: 4k |
| 158 | * %DECIMATION_NONE: Do not use this Sampling type. |
| 159 | * |
| 160 | * The Sampling rate is specific to each channel of the QPNP ADC arbiter. |
| 161 | */ |
| 162 | enum qpnp_adc_decimation_type { |
| 163 | DECIMATION_TYPE1 = 0, |
| 164 | DECIMATION_TYPE2, |
| 165 | DECIMATION_TYPE3, |
| 166 | DECIMATION_TYPE4, |
| 167 | DECIMATION_NONE, |
| 168 | }; |
| 169 | |
| 170 | /** |
| 171 | * enum qpnp_adc_calib_type - QPNP ADC Calibration type. |
| 172 | * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels. |
| 173 | * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND. |
| 174 | * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type. |
| 175 | * |
| 176 | * Use the input reference voltage depending on the calibration type |
| 177 | * to calcluate the offset and gain parameters. The calibration is |
| 178 | * specific to each channel of the QPNP ADC. |
| 179 | */ |
| 180 | enum qpnp_adc_calib_type { |
| 181 | CALIB_ABSOLUTE = 0, |
| 182 | CALIB_RATIOMETRIC, |
| 183 | CALIB_NONE, |
| 184 | }; |
| 185 | |
| 186 | /** |
| 187 | * enum qpnp_adc_channel_scaling_param - pre-scaling AMUX ratio. |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 188 | * %CHAN_PATH_SCALING0: ratio of {1, 1} |
| 189 | * %CHAN_PATH_SCALING1: ratio of {1, 3} |
| 190 | * %CHAN_PATH_SCALING2: ratio of {1, 4} |
| 191 | * %CHAN_PATH_SCALING3: ratio of {1, 6} |
| 192 | * %CHAN_PATH_SCALING4: ratio of {1, 20} |
Dipen Parmar | 46f8ac6 | 2014-01-19 22:45:11 +0530 | [diff] [blame] | 193 | * %CHAN_PATH_SCALING5: ratio of {1, 8} |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 194 | * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type. |
| 195 | * |
| 196 | * The pre-scaling is applied for signals to be within the voltage range |
| 197 | * of the ADC. |
| 198 | */ |
| 199 | enum qpnp_adc_channel_scaling_param { |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 200 | PATH_SCALING0 = 0, |
| 201 | PATH_SCALING1, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 202 | PATH_SCALING2, |
| 203 | PATH_SCALING3, |
| 204 | PATH_SCALING4, |
Dipen Parmar | 46f8ac6 | 2014-01-19 22:45:11 +0530 | [diff] [blame] | 205 | PATH_SCALING5, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 206 | PATH_SCALING_NONE, |
| 207 | }; |
| 208 | |
| 209 | /** |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 210 | * enum qpnp_adc_scale_fn_type - Scaling function for pm8941 pre calibrated |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 211 | * digital data relative to ADC reference. |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 212 | * %SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV). |
| 213 | * %SCALE_BATT_THERM: Conversion to temperature(decidegC) based on btm |
| 214 | * parameters. |
| 215 | * %SCALE_THERM_100K_PULLUP: Returns temperature in degC. |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 216 | * Uses a mapping table with 100K pullup. |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 217 | * %SCALE_PMIC_THERM: Returns result in milli degree's Centigrade. |
| 218 | * %SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade. |
| 219 | * %SCALE_THERM_150K_PULLUP: Returns temperature in degC. |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 220 | * Uses a mapping table with 150K pullup. |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 221 | * %SCALE_QRD_BATT_THERM: Conversion to temperature(decidegC) based on |
| 222 | * btm parameters. |
Xu Kai | 81c6052 | 2013-07-27 14:26:04 +0800 | [diff] [blame] | 223 | * %SCALE_QRD_SKUAA_BATT_THERM: Conversion to temperature(decidegC) based on |
| 224 | * btm parametersi for SKUAA. |
Wu Fenglin | 2c6ef8f | 2013-12-17 11:33:33 +0800 | [diff] [blame] | 225 | * %SCALE_QRD_SKUG_BATT_THERM: Conversion to temperature(decidegC) based on |
| 226 | * btm parametersi for SKUG. |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 227 | * %SCALE_NONE: Do not use this scaling type. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 228 | */ |
| 229 | enum qpnp_adc_scale_fn_type { |
| 230 | SCALE_DEFAULT = 0, |
| 231 | SCALE_BATT_THERM, |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 232 | SCALE_THERM_100K_PULLUP, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 233 | SCALE_PMIC_THERM, |
| 234 | SCALE_XOTHERM, |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 235 | SCALE_THERM_150K_PULLUP, |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 236 | SCALE_QRD_BATT_THERM, |
Xu Kai | 81c6052 | 2013-07-27 14:26:04 +0800 | [diff] [blame] | 237 | SCALE_QRD_SKUAA_BATT_THERM, |
Wu Fenglin | 2c6ef8f | 2013-12-17 11:33:33 +0800 | [diff] [blame] | 238 | SCALE_QRD_SKUG_BATT_THERM = 9, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 239 | SCALE_NONE, |
| 240 | }; |
| 241 | |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * enum qpnp_adc_tm_rscale_fn_type - Scaling function used to convert the |
| 245 | * channels input voltage/temperature to corresponding ADC code that is |
| 246 | * applied for thresholds. Check the corresponding channels scaling to |
| 247 | * determine the appropriate temperature/voltage units that are passed |
| 248 | * to the scaling function. Example battery follows the power supply |
| 249 | * framework that needs its units to be in decidegreesC so it passes |
| 250 | * deci-degreesC. PA_THERM clients pass the temperature in degrees. |
| 251 | * The order below should match the one in the driver for |
| 252 | * adc_tm_rscale_fn[]. |
| 253 | */ |
| 254 | enum qpnp_adc_tm_rscale_fn_type { |
| 255 | SCALE_R_VBATT = 0, |
| 256 | SCALE_RBATT_THERM, |
| 257 | SCALE_R_USB_ID, |
| 258 | SCALE_RPMIC_THERM, |
| 259 | SCALE_RSCALE_NONE, |
| 260 | }; |
| 261 | |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 262 | /** |
| 263 | * enum qpnp_adc_fast_avg_ctl - Provides ability to obtain single result |
| 264 | * from the ADC that is an average of multiple measurement |
| 265 | * samples. Select number of samples for use in fast |
| 266 | * average mode (i.e. 2 ^ value). |
| 267 | * %ADC_FAST_AVG_SAMPLE_1: 0x0 = 1 |
| 268 | * %ADC_FAST_AVG_SAMPLE_2: 0x1 = 2 |
| 269 | * %ADC_FAST_AVG_SAMPLE_4: 0x2 = 4 |
| 270 | * %ADC_FAST_AVG_SAMPLE_8: 0x3 = 8 |
| 271 | * %ADC_FAST_AVG_SAMPLE_16: 0x4 = 16 |
| 272 | * %ADC_FAST_AVG_SAMPLE_32: 0x5 = 32 |
| 273 | * %ADC_FAST_AVG_SAMPLE_64: 0x6 = 64 |
| 274 | * %ADC_FAST_AVG_SAMPLE_128: 0x7 = 128 |
| 275 | * %ADC_FAST_AVG_SAMPLE_256: 0x8 = 256 |
| 276 | * %ADC_FAST_AVG_SAMPLE_512: 0x9 = 512 |
| 277 | */ |
| 278 | enum qpnp_adc_fast_avg_ctl { |
| 279 | ADC_FAST_AVG_SAMPLE_1 = 0, |
| 280 | ADC_FAST_AVG_SAMPLE_2, |
| 281 | ADC_FAST_AVG_SAMPLE_4, |
| 282 | ADC_FAST_AVG_SAMPLE_8, |
| 283 | ADC_FAST_AVG_SAMPLE_16, |
| 284 | ADC_FAST_AVG_SAMPLE_32, |
| 285 | ADC_FAST_AVG_SAMPLE_64, |
| 286 | ADC_FAST_AVG_SAMPLE_128, |
| 287 | ADC_FAST_AVG_SAMPLE_256, |
| 288 | ADC_FAST_AVG_SAMPLE_512, |
| 289 | ADC_FAST_AVG_SAMPLE_NONE, |
| 290 | }; |
| 291 | |
| 292 | /** |
| 293 | * enum qpnp_adc_hw_settle_time - Time between AMUX getting configured and |
| 294 | * the ADC starting conversion. Delay = 100us * value for |
| 295 | * value < 11 and 2ms * (value - 10) otherwise. |
| 296 | * %ADC_CHANNEL_HW_SETTLE_DELAY_0US: 0us |
| 297 | * %ADC_CHANNEL_HW_SETTLE_DELAY_100US: 100us |
| 298 | * %ADC_CHANNEL_HW_SETTLE_DELAY_200US: 200us |
| 299 | * %ADC_CHANNEL_HW_SETTLE_DELAY_300US: 300us |
| 300 | * %ADC_CHANNEL_HW_SETTLE_DELAY_400US: 400us |
| 301 | * %ADC_CHANNEL_HW_SETTLE_DELAY_500US: 500us |
| 302 | * %ADC_CHANNEL_HW_SETTLE_DELAY_600US: 600us |
| 303 | * %ADC_CHANNEL_HW_SETTLE_DELAY_700US: 700us |
| 304 | * %ADC_CHANNEL_HW_SETTLE_DELAY_800US: 800us |
| 305 | * %ADC_CHANNEL_HW_SETTLE_DELAY_900US: 900us |
| 306 | * %ADC_CHANNEL_HW_SETTLE_DELAY_1MS: 1ms |
| 307 | * %ADC_CHANNEL_HW_SETTLE_DELAY_2MS: 2ms |
| 308 | * %ADC_CHANNEL_HW_SETTLE_DELAY_4MS: 4ms |
| 309 | * %ADC_CHANNEL_HW_SETTLE_DELAY_6MS: 6ms |
| 310 | * %ADC_CHANNEL_HW_SETTLE_DELAY_8MS: 8ms |
| 311 | * %ADC_CHANNEL_HW_SETTLE_DELAY_10MS: 10ms |
| 312 | * %ADC_CHANNEL_HW_SETTLE_NONE |
| 313 | */ |
| 314 | enum qpnp_adc_hw_settle_time { |
| 315 | ADC_CHANNEL_HW_SETTLE_DELAY_0US = 0, |
| 316 | ADC_CHANNEL_HW_SETTLE_DELAY_100US, |
| 317 | ADC_CHANNEL_HW_SETTLE_DELAY_2000US, |
| 318 | ADC_CHANNEL_HW_SETTLE_DELAY_300US, |
| 319 | ADC_CHANNEL_HW_SETTLE_DELAY_400US, |
| 320 | ADC_CHANNEL_HW_SETTLE_DELAY_500US, |
| 321 | ADC_CHANNEL_HW_SETTLE_DELAY_600US, |
| 322 | ADC_CHANNEL_HW_SETTLE_DELAY_700US, |
| 323 | ADC_CHANNEL_HW_SETTLE_DELAY_800US, |
| 324 | ADC_CHANNEL_HW_SETTLE_DELAY_900US, |
| 325 | ADC_CHANNEL_HW_SETTLE_DELAY_1MS, |
| 326 | ADC_CHANNEL_HW_SETTLE_DELAY_2MS, |
| 327 | ADC_CHANNEL_HW_SETTLE_DELAY_4MS, |
| 328 | ADC_CHANNEL_HW_SETTLE_DELAY_6MS, |
| 329 | ADC_CHANNEL_HW_SETTLE_DELAY_8MS, |
| 330 | ADC_CHANNEL_HW_SETTLE_DELAY_10MS, |
| 331 | ADC_CHANNEL_HW_SETTLE_NONE, |
| 332 | }; |
| 333 | |
| 334 | /** |
| 335 | * enum qpnp_vadc_mode_sel - Selects the basic mode of operation. |
| 336 | * - The normal mode is used for single measurement. |
| 337 | * - The Conversion sequencer is used to trigger an |
| 338 | * ADC read when a HW trigger is selected. |
| 339 | * - The measurement interval performs a single or |
| 340 | * continous measurement at a specified interval/delay. |
| 341 | * %ADC_OP_NORMAL_MODE : Normal mode used for single measurement. |
| 342 | * %ADC_OP_CONVERSION_SEQUENCER : Conversion sequencer used to trigger |
| 343 | * an ADC read on a HW supported trigger. |
| 344 | * Refer to enum qpnp_vadc_trigger for |
| 345 | * supported HW triggers. |
| 346 | * %ADC_OP_MEASUREMENT_INTERVAL : The measurement interval performs a |
| 347 | * single or continous measurement after a specified delay. |
| 348 | * For delay look at qpnp_adc_meas_timer. |
| 349 | */ |
| 350 | enum qpnp_vadc_mode_sel { |
| 351 | ADC_OP_NORMAL_MODE = 0, |
| 352 | ADC_OP_CONVERSION_SEQUENCER, |
| 353 | ADC_OP_MEASUREMENT_INTERVAL, |
| 354 | ADC_OP_MODE_NONE, |
| 355 | }; |
| 356 | |
| 357 | /** |
| 358 | * enum qpnp_vadc_trigger - Select the HW trigger to be used while |
| 359 | * measuring the ADC reading. |
| 360 | * %ADC_GSM_PA_ON : GSM power amplifier on. |
| 361 | * %ADC_TX_GTR_THRES : Transmit power greater than threshold. |
| 362 | * %ADC_CAMERA_FLASH_RAMP : Flash ramp up done. |
| 363 | * %ADC_DTEST : DTEST. |
| 364 | */ |
| 365 | enum qpnp_vadc_trigger { |
| 366 | ADC_GSM_PA_ON = 0, |
| 367 | ADC_TX_GTR_THRES, |
| 368 | ADC_CAMERA_FLASH_RAMP, |
| 369 | ADC_DTEST, |
| 370 | ADC_SEQ_NONE, |
| 371 | }; |
| 372 | |
| 373 | /** |
| 374 | * enum qpnp_vadc_conv_seq_timeout - Select delay (0 to 15ms) from |
| 375 | * conversion request to triggering conversion sequencer |
| 376 | * hold off time. |
| 377 | */ |
| 378 | enum qpnp_vadc_conv_seq_timeout { |
| 379 | ADC_CONV_SEQ_TIMEOUT_0MS = 0, |
| 380 | ADC_CONV_SEQ_TIMEOUT_1MS, |
| 381 | ADC_CONV_SEQ_TIMEOUT_2MS, |
| 382 | ADC_CONV_SEQ_TIMEOUT_3MS, |
| 383 | ADC_CONV_SEQ_TIMEOUT_4MS, |
| 384 | ADC_CONV_SEQ_TIMEOUT_5MS, |
| 385 | ADC_CONV_SEQ_TIMEOUT_6MS, |
| 386 | ADC_CONV_SEQ_TIMEOUT_7MS, |
| 387 | ADC_CONV_SEQ_TIMEOUT_8MS, |
| 388 | ADC_CONV_SEQ_TIMEOUT_9MS, |
| 389 | ADC_CONV_SEQ_TIMEOUT_10MS, |
| 390 | ADC_CONV_SEQ_TIMEOUT_11MS, |
| 391 | ADC_CONV_SEQ_TIMEOUT_12MS, |
| 392 | ADC_CONV_SEQ_TIMEOUT_13MS, |
| 393 | ADC_CONV_SEQ_TIMEOUT_14MS, |
| 394 | ADC_CONV_SEQ_TIMEOUT_15MS, |
| 395 | ADC_CONV_SEQ_TIMEOUT_NONE, |
| 396 | }; |
| 397 | |
| 398 | /** |
| 399 | * enum qpnp_adc_conv_seq_holdoff - Select delay from conversion |
| 400 | * trigger signal (i.e. adc_conv_seq_trig) transition |
| 401 | * to ADC enable. Delay = 25us * (value + 1). |
| 402 | */ |
| 403 | enum qpnp_adc_conv_seq_holdoff { |
| 404 | ADC_SEQ_HOLD_25US = 0, |
| 405 | ADC_SEQ_HOLD_50US, |
| 406 | ADC_SEQ_HOLD_75US, |
| 407 | ADC_SEQ_HOLD_100US, |
| 408 | ADC_SEQ_HOLD_125US, |
| 409 | ADC_SEQ_HOLD_150US, |
| 410 | ADC_SEQ_HOLD_175US, |
| 411 | ADC_SEQ_HOLD_200US, |
| 412 | ADC_SEQ_HOLD_225US, |
| 413 | ADC_SEQ_HOLD_250US, |
| 414 | ADC_SEQ_HOLD_275US, |
| 415 | ADC_SEQ_HOLD_300US, |
| 416 | ADC_SEQ_HOLD_325US, |
| 417 | ADC_SEQ_HOLD_350US, |
| 418 | ADC_SEQ_HOLD_375US, |
| 419 | ADC_SEQ_HOLD_400US, |
| 420 | ADC_SEQ_HOLD_NONE, |
| 421 | }; |
| 422 | |
| 423 | /** |
| 424 | * enum qpnp_adc_conv_seq_state - Conversion sequencer operating state |
| 425 | * %ADC_CONV_SEQ_IDLE : Sequencer is in idle. |
| 426 | * %ADC_CONV_TRIG_RISE : Waiting for rising edge trigger. |
| 427 | * %ADC_CONV_TRIG_HOLDOFF : Waiting for rising trigger hold off time. |
| 428 | * %ADC_CONV_MEAS_RISE : Measuring selected ADC signal. |
| 429 | * %ADC_CONV_TRIG_FALL : Waiting for falling trigger edge. |
| 430 | * %ADC_CONV_FALL_HOLDOFF : Waiting for falling trigger hold off time. |
| 431 | * %ADC_CONV_MEAS_FALL : Measuring selected ADC signal. |
| 432 | * %ADC_CONV_ERROR : Aberrant Hardware problem. |
| 433 | */ |
| 434 | enum qpnp_adc_conv_seq_state { |
| 435 | ADC_CONV_SEQ_IDLE = 0, |
| 436 | ADC_CONV_TRIG_RISE, |
| 437 | ADC_CONV_TRIG_HOLDOFF, |
| 438 | ADC_CONV_MEAS_RISE, |
| 439 | ADC_CONV_TRIG_FALL, |
| 440 | ADC_CONV_FALL_HOLDOFF, |
| 441 | ADC_CONV_MEAS_FALL, |
| 442 | ADC_CONV_ERROR, |
| 443 | ADC_CONV_NONE, |
| 444 | }; |
| 445 | |
| 446 | /** |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 447 | * enum qpnp_adc_meas_timer_1 - Selects the measurement interval time. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 448 | * If value = 0, use 0ms else use 2^(value + 4)/ 32768). |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 449 | * The timer period is used by the USB_ID. Do not set a polling rate |
| 450 | * greater than 1 second on PMIC 2.0. The max polling rate on the PMIC 2.0 |
| 451 | * appears to be limited to 1 second. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 452 | * %ADC_MEAS_INTERVAL_0MS : 0ms |
| 453 | * %ADC_MEAS_INTERVAL_1P0MS : 1ms |
| 454 | * %ADC_MEAS_INTERVAL_2P0MS : 2ms |
| 455 | * %ADC_MEAS_INTERVAL_3P9MS : 3.9ms |
| 456 | * %ADC_MEAS_INTERVAL_7P8MS : 7.8ms |
| 457 | * %ADC_MEAS_INTERVAL_15P6MS : 15.6ms |
| 458 | * %ADC_MEAS_INTERVAL_31P3MS : 31.3ms |
| 459 | * %ADC_MEAS_INTERVAL_62P5MS : 62.5ms |
| 460 | * %ADC_MEAS_INTERVAL_125MS : 125ms |
| 461 | * %ADC_MEAS_INTERVAL_250MS : 250ms |
| 462 | * %ADC_MEAS_INTERVAL_500MS : 500ms |
| 463 | * %ADC_MEAS_INTERVAL_1S : 1seconds |
| 464 | * %ADC_MEAS_INTERVAL_2S : 2seconds |
| 465 | * %ADC_MEAS_INTERVAL_4S : 4seconds |
| 466 | * %ADC_MEAS_INTERVAL_8S : 8seconds |
| 467 | * %ADC_MEAS_INTERVAL_16S: 16seconds |
| 468 | */ |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 469 | enum qpnp_adc_meas_timer_1 { |
| 470 | ADC_MEAS1_INTERVAL_0MS = 0, |
| 471 | ADC_MEAS1_INTERVAL_1P0MS, |
| 472 | ADC_MEAS1_INTERVAL_2P0MS, |
| 473 | ADC_MEAS1_INTERVAL_3P9MS, |
| 474 | ADC_MEAS1_INTERVAL_7P8MS, |
| 475 | ADC_MEAS1_INTERVAL_15P6MS, |
| 476 | ADC_MEAS1_INTERVAL_31P3MS, |
| 477 | ADC_MEAS1_INTERVAL_62P5MS, |
| 478 | ADC_MEAS1_INTERVAL_125MS, |
| 479 | ADC_MEAS1_INTERVAL_250MS, |
| 480 | ADC_MEAS1_INTERVAL_500MS, |
| 481 | ADC_MEAS1_INTERVAL_1S, |
| 482 | ADC_MEAS1_INTERVAL_2S, |
| 483 | ADC_MEAS1_INTERVAL_4S, |
| 484 | ADC_MEAS1_INTERVAL_8S, |
| 485 | ADC_MEAS1_INTERVAL_16S, |
| 486 | ADC_MEAS1_INTERVAL_NONE, |
| 487 | }; |
| 488 | |
| 489 | /** |
| 490 | * enum qpnp_adc_meas_timer_2 - Selects the measurement interval time. |
| 491 | * If value = 0, use 0ms else use 2^(value + 4)/ 32768). |
| 492 | * The timer period is used by the batt_therm. Do not set a polling rate |
| 493 | * greater than 1 second on PMIC 2.0. The max polling rate on the PMIC 2.0 |
| 494 | * appears to be limited to 1 second. |
| 495 | * %ADC_MEAS_INTERVAL_0MS : 0ms |
| 496 | * %ADC_MEAS_INTERVAL_100MS : 100ms |
| 497 | * %ADC_MEAS_INTERVAL_200MS : 200ms |
| 498 | * %ADC_MEAS_INTERVAL_300MS : 300ms |
| 499 | * %ADC_MEAS_INTERVAL_400MS : 400ms |
| 500 | * %ADC_MEAS_INTERVAL_500MS : 500ms |
| 501 | * %ADC_MEAS_INTERVAL_600MS : 600ms |
| 502 | * %ADC_MEAS_INTERVAL_700MS : 700ms |
| 503 | * %ADC_MEAS_INTERVAL_800MS : 800ms |
| 504 | * %ADC_MEAS_INTERVAL_900MS : 900ms |
| 505 | * %ADC_MEAS_INTERVAL_1S: 1seconds |
| 506 | * %ADC_MEAS_INTERVAL_1P1S: 1.1seconds |
| 507 | * %ADC_MEAS_INTERVAL_1P2S: 1.2seconds |
| 508 | * %ADC_MEAS_INTERVAL_1P3S: 1.3seconds |
| 509 | * %ADC_MEAS_INTERVAL_1P4S: 1.4seconds |
| 510 | * %ADC_MEAS_INTERVAL_1P5S: 1.5seconds |
| 511 | */ |
| 512 | enum qpnp_adc_meas_timer_2 { |
| 513 | ADC_MEAS2_INTERVAL_0MS = 0, |
| 514 | ADC_MEAS2_INTERVAL_100MS, |
| 515 | ADC_MEAS2_INTERVAL_200MS, |
| 516 | ADC_MEAS2_INTERVAL_300MS, |
| 517 | ADC_MEAS2_INTERVAL_400MS, |
| 518 | ADC_MEAS2_INTERVAL_500MS, |
| 519 | ADC_MEAS2_INTERVAL_600MS, |
| 520 | ADC_MEAS2_INTERVAL_700MS, |
| 521 | ADC_MEAS2_INTERVAL_800MS, |
| 522 | ADC_MEAS2_INTERVAL_900MS, |
| 523 | ADC_MEAS2_INTERVAL_1S, |
| 524 | ADC_MEAS2_INTERVAL_1P1S, |
| 525 | ADC_MEAS2_INTERVAL_1P2S, |
| 526 | ADC_MEAS2_INTERVAL_1P3S, |
| 527 | ADC_MEAS2_INTERVAL_1P4S, |
| 528 | ADC_MEAS2_INTERVAL_1P5S, |
| 529 | ADC_MEAS2_INTERVAL_NONE, |
| 530 | }; |
| 531 | |
| 532 | /** |
| 533 | * enum qpnp_adc_meas_timer_3 - Selects the measurement interval time. |
| 534 | * If value = 0, use 0ms else use 2^(value + 4)/ 32768). |
| 535 | * Do not set a polling rate greater than 1 second on PMIC 2.0. |
| 536 | * The max polling rate on the PMIC 2.0 appears to be limited to 1 second. |
| 537 | * %ADC_MEAS_INTERVAL_0MS : 0ms |
| 538 | * %ADC_MEAS_INTERVAL_1S : 1seconds |
| 539 | * %ADC_MEAS_INTERVAL_2S : 2seconds |
| 540 | * %ADC_MEAS_INTERVAL_3S : 3seconds |
| 541 | * %ADC_MEAS_INTERVAL_4S : 4seconds |
| 542 | * %ADC_MEAS_INTERVAL_5S : 5seconds |
| 543 | * %ADC_MEAS_INTERVAL_6S: 6seconds |
| 544 | * %ADC_MEAS_INTERVAL_7S : 7seconds |
| 545 | * %ADC_MEAS_INTERVAL_8S : 8seconds |
| 546 | * %ADC_MEAS_INTERVAL_9S : 9seconds |
| 547 | * %ADC_MEAS_INTERVAL_10S : 10seconds |
| 548 | * %ADC_MEAS_INTERVAL_11S : 11seconds |
| 549 | * %ADC_MEAS_INTERVAL_12S : 12seconds |
| 550 | * %ADC_MEAS_INTERVAL_13S : 13seconds |
| 551 | * %ADC_MEAS_INTERVAL_14S : 14seconds |
| 552 | * %ADC_MEAS_INTERVAL_15S : 15seconds |
| 553 | */ |
| 554 | enum qpnp_adc_meas_timer_3 { |
| 555 | ADC_MEAS3_INTERVAL_0S = 0, |
| 556 | ADC_MEAS3_INTERVAL_1S, |
| 557 | ADC_MEAS3_INTERVAL_2S, |
| 558 | ADC_MEAS3_INTERVAL_3S, |
| 559 | ADC_MEAS3_INTERVAL_4S, |
| 560 | ADC_MEAS3_INTERVAL_5S, |
| 561 | ADC_MEAS3_INTERVAL_6S, |
| 562 | ADC_MEAS3_INTERVAL_7S, |
| 563 | ADC_MEAS3_INTERVAL_8S, |
| 564 | ADC_MEAS3_INTERVAL_9S, |
| 565 | ADC_MEAS3_INTERVAL_10S, |
| 566 | ADC_MEAS3_INTERVAL_11S, |
| 567 | ADC_MEAS3_INTERVAL_12S, |
| 568 | ADC_MEAS3_INTERVAL_13S, |
| 569 | ADC_MEAS3_INTERVAL_14S, |
| 570 | ADC_MEAS3_INTERVAL_15S, |
| 571 | ADC_MEAS3_INTERVAL_NONE, |
| 572 | }; |
| 573 | |
| 574 | /** |
| 575 | * enum qpnp_adc_meas_timer_select - Selects the timer for which |
| 576 | * the appropriate polling frequency is set. |
Siddartha Mohanadoss | 58ffe0e | 2014-02-11 17:40:13 -0800 | [diff] [blame] | 577 | * %ADC_MEAS_TIMER_SELECT1 - Select this timer for measurement polling interval |
| 578 | * for 1 second. |
| 579 | * %ADC_MEAS_TIMER_SELECT2 - Select this timer for 500ms measurement interval. |
| 580 | * %ADC_MEAS_TIMER_SELECT3 - Select this timer for 5 second interval. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 581 | */ |
| 582 | enum qpnp_adc_meas_timer_select { |
| 583 | ADC_MEAS_TIMER_SELECT1 = 0, |
| 584 | ADC_MEAS_TIMER_SELECT2, |
| 585 | ADC_MEAS_TIMER_SELECT3, |
| 586 | ADC_MEAS_TIMER_NUM, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 587 | }; |
| 588 | |
| 589 | /** |
| 590 | * enum qpnp_adc_meas_interval_op_ctl - Select operating mode. |
| 591 | * %ADC_MEAS_INTERVAL_OP_SINGLE : Conduct single measurement at specified time |
| 592 | * delay. |
| 593 | * %ADC_MEAS_INTERVAL_OP_CONTINUOUS : Make measurements at measurement interval |
| 594 | * times. |
| 595 | */ |
| 596 | enum qpnp_adc_meas_interval_op_ctl { |
| 597 | ADC_MEAS_INTERVAL_OP_SINGLE = 0, |
| 598 | ADC_MEAS_INTERVAL_OP_CONTINUOUS, |
| 599 | ADC_MEAS_INTERVAL_OP_NONE, |
| 600 | }; |
| 601 | |
| 602 | /** |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 603 | * Channel selection registers for each of the configurable measurements |
| 604 | * Channels allotment is set at device config for a channel. |
| 605 | * The USB_ID, BATT_THERM, PMIC_THERM and VBAT channels are used by the |
| 606 | * kernel space USB, Battery and IADC drivers. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 607 | * The other 3 channels are configurable for use by userspace clients. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 608 | */ |
| 609 | enum qpnp_adc_tm_channel_select { |
| 610 | QPNP_ADC_TM_M0_ADC_CH_SEL_CTL = 0x48, |
| 611 | QPNP_ADC_TM_M1_ADC_CH_SEL_CTL = 0x68, |
| 612 | QPNP_ADC_TM_M2_ADC_CH_SEL_CTL = 0x70, |
| 613 | QPNP_ADC_TM_M3_ADC_CH_SEL_CTL = 0x78, |
| 614 | QPNP_ADC_TM_M4_ADC_CH_SEL_CTL = 0x80, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 615 | QPNP_ADC_TM_M5_ADC_CH_SEL_CTL = 0x88, |
| 616 | QPNP_ADC_TM_M6_ADC_CH_SEL_CTL = 0x90, |
| 617 | QPNP_ADC_TM_M7_ADC_CH_SEL_CTL = 0x98, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 618 | QPNP_ADC_TM_CH_SELECT_NONE |
| 619 | }; |
| 620 | |
Siddartha Mohanadoss | 71a8344 | 2013-08-29 11:43:24 -0700 | [diff] [blame] | 621 | /** |
| 622 | * Channel index for the corresponding index to qpnp_adc_tm_channel_selec |
| 623 | */ |
| 624 | enum qpnp_adc_tm_channel_num { |
| 625 | QPNP_ADC_TM_CHAN0 = 0, |
| 626 | QPNP_ADC_TM_CHAN1, |
| 627 | QPNP_ADC_TM_CHAN2, |
| 628 | QPNP_ADC_TM_CHAN3, |
| 629 | QPNP_ADC_TM_CHAN4, |
| 630 | QPNP_ADC_TM_CHAN5, |
| 631 | QPNP_ADC_TM_CHAN6, |
| 632 | QPNP_ADC_TM_CHAN7, |
| 633 | QPNP_ADC_TM_CHAN_NONE |
| 634 | }; |
| 635 | |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame] | 636 | enum qpnp_comp_scheme_type { |
| 637 | COMP_ID_GF = 0, |
| 638 | COMP_ID_SMIC, |
| 639 | COMP_ID_TSMC, |
| 640 | COMP_ID_NUM, |
| 641 | }; |
| 642 | |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 643 | /** |
| 644 | * struct qpnp_adc_tm_config - Represent ADC Thermal Monitor configuration. |
| 645 | * @channel: ADC channel for which thermal monitoring is requested. |
| 646 | * @adc_code: The pre-calibrated digital output of a given ADC releative to the |
| 647 | * ADC reference. |
| 648 | * @high_thr_temp: Temperature at which high threshold notification is required. |
| 649 | * @low_thr_temp: Temperature at which low threshold notification is required. |
| 650 | * @low_thr_voltage : Low threshold voltage ADC code used for reverse |
| 651 | * calibration. |
| 652 | * @high_thr_voltage: High threshold voltage ADC code used for reverse |
| 653 | * calibration. |
| 654 | */ |
| 655 | struct qpnp_adc_tm_config { |
| 656 | int channel; |
| 657 | int adc_code; |
| 658 | int high_thr_temp; |
| 659 | int low_thr_temp; |
| 660 | int64_t high_thr_voltage; |
| 661 | int64_t low_thr_voltage; |
| 662 | }; |
| 663 | |
| 664 | /** |
| 665 | * enum qpnp_adc_tm_trip_type - Type for setting high/low temperature/voltage. |
| 666 | * %ADC_TM_TRIP_HIGH_WARM: Setting high temperature. Note that high temperature |
| 667 | * corresponds to low voltage. Driver handles this case |
| 668 | * appropriately to set high/low thresholds for voltage. |
| 669 | * threshold. |
| 670 | * %ADC_TM_TRIP_LOW_COOL: Setting low temperature. |
| 671 | */ |
| 672 | enum qpnp_adc_tm_trip_type { |
| 673 | ADC_TM_TRIP_HIGH_WARM = 0, |
| 674 | ADC_TM_TRIP_LOW_COOL, |
| 675 | ADC_TM_TRIP_NUM, |
| 676 | }; |
| 677 | |
| 678 | /** |
| 679 | * enum qpnp_tm_state - This lets the client know whether the threshold |
| 680 | * that was crossed was high/low. |
| 681 | * %ADC_TM_HIGH_STATE: Client is notified of crossing the requested high |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 682 | * voltage threshold. |
| 683 | * %ADC_TM_COOL_STATE: Client is notified of crossing the requested cool |
| 684 | * temperature threshold. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 685 | * %ADC_TM_LOW_STATE: Client is notified of crossing the requested low |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 686 | * voltage threshold. |
| 687 | * %ADC_TM_WARM_STATE: Client is notified of crossing the requested high |
| 688 | * temperature threshold. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 689 | */ |
| 690 | enum qpnp_tm_state { |
| 691 | ADC_TM_HIGH_STATE = 0, |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 692 | ADC_TM_COOL_STATE = ADC_TM_HIGH_STATE, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 693 | ADC_TM_LOW_STATE, |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 694 | ADC_TM_WARM_STATE = ADC_TM_LOW_STATE, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 695 | ADC_TM_STATE_NUM, |
| 696 | }; |
| 697 | |
| 698 | /** |
| 699 | * enum qpnp_state_request - Request to enable/disable the corresponding |
| 700 | * high/low voltage/temperature thresholds. |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 701 | * %ADC_TM_HIGH_THR_ENABLE: Enable high voltage threshold. |
| 702 | * %ADC_TM_COOL_THR_ENABLE = Enables cool temperature threshold. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 703 | * %ADC_TM_LOW_THR_ENABLE: Enable low voltage/temperature threshold. |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 704 | * %ADC_TM_WARM_THR_ENABLE = Enables warm temperature threshold. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 705 | * %ADC_TM_HIGH_LOW_THR_ENABLE: Enable high and low voltage/temperature |
| 706 | * threshold. |
| 707 | * %ADC_TM_HIGH_THR_DISABLE: Disable high voltage/temperature threshold. |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 708 | * %ADC_TM_COOL_THR_ENABLE = Disables cool temperature threshold. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 709 | * %ADC_TM_LOW_THR_DISABLE: Disable low voltage/temperature threshold. |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 710 | * %ADC_TM_WARM_THR_ENABLE = Disables warm temperature threshold. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 711 | * %ADC_TM_HIGH_THR_DISABLE: Disable high and low voltage/temperature |
| 712 | * threshold. |
| 713 | */ |
| 714 | enum qpnp_state_request { |
| 715 | ADC_TM_HIGH_THR_ENABLE = 0, |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 716 | ADC_TM_COOL_THR_ENABLE = ADC_TM_HIGH_THR_ENABLE, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 717 | ADC_TM_LOW_THR_ENABLE, |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 718 | ADC_TM_WARM_THR_ENABLE = ADC_TM_LOW_THR_ENABLE, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 719 | ADC_TM_HIGH_LOW_THR_ENABLE, |
| 720 | ADC_TM_HIGH_THR_DISABLE, |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 721 | ADC_TM_COOL_THR_DISABLE = ADC_TM_HIGH_THR_DISABLE, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 722 | ADC_TM_LOW_THR_DISABLE, |
Siddartha Mohanadoss | b8109da | 2013-03-25 09:53:43 -0700 | [diff] [blame] | 723 | ADC_TM_WARM_THR_DISABLE = ADC_TM_LOW_THR_DISABLE, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 724 | ADC_TM_HIGH_LOW_THR_DISABLE, |
| 725 | ADC_TM_THR_NUM, |
| 726 | }; |
| 727 | |
| 728 | /** |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 729 | * struct qpnp_adc_tm_btm_param - Represent Battery temperature threshold |
| 730 | * monitoring configuration. |
| 731 | * @high_temp: High temperature threshold for which notification is requested. |
| 732 | * @low_temp: Low temperature threshold for which notification is requested. |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 733 | * @high_thr_voltage: High voltage for which notification is requested. |
| 734 | * @low_thr_voltage: Low voltage for which notification is requested. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 735 | * @state_request: Enable/disable the corresponding high and low temperature |
| 736 | * thresholds. |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 737 | * @timer_interval1: Select polling rate from qpnp_adc_meas_timer_1 type. |
| 738 | * @timer_interval2: Select polling rate from qpnp_adc_meas_timer_2 type. |
| 739 | * @timer_interval3: Select polling rate from qpnp_adc_meas_timer_3 type. |
Siddartha Mohanadoss | d71e240 | 2013-02-01 17:36:23 -0800 | [diff] [blame] | 740 | * @btmid_ctx: A context of void type. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 741 | * @threshold_notification: Notification callback once threshold are crossed. |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 742 | * units to be used for High/Low temperature and voltage notification - |
| 743 | * This depends on the clients usage. Check the rscaling function |
| 744 | * for the appropriate channel nodes. |
| 745 | * @Batt therm clients temperature units is decidegreesCentigrate. |
| 746 | * @USB_ID inputs the voltage units in milli-volts. |
| 747 | * @PA_THERM inputs the units in degC. |
| 748 | * @PMIC_THERM inputs the units in millidegC. |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 749 | */ |
| 750 | struct qpnp_adc_tm_btm_param { |
| 751 | int32_t high_temp; |
| 752 | int32_t low_temp; |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 753 | int32_t high_thr; |
| 754 | int32_t low_thr; |
| 755 | enum qpnp_vadc_channels channel; |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 756 | enum qpnp_state_request state_request; |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 757 | enum qpnp_adc_meas_timer_1 timer_interval; |
| 758 | enum qpnp_adc_meas_timer_2 timer_interval2; |
| 759 | enum qpnp_adc_meas_timer_3 timer_interval3; |
Siddartha Mohanadoss | d71e240 | 2013-02-01 17:36:23 -0800 | [diff] [blame] | 760 | void *btm_ctx; |
| 761 | void (*threshold_notification) (enum qpnp_tm_state state, |
| 762 | void *ctx); |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | /** |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 766 | * struct qpnp_vadc_linear_graph - Represent ADC characteristics. |
| 767 | * @dy: Numerator slope to calculate the gain. |
| 768 | * @dx: Denominator slope to calculate the gain. |
| 769 | * @adc_vref: A/D word of the voltage reference used for the channel. |
| 770 | * @adc_gnd: A/D word of the ground reference used for the channel. |
| 771 | * |
| 772 | * Each ADC device has different offset and gain parameters which are computed |
| 773 | * to calibrate the device. |
| 774 | */ |
| 775 | struct qpnp_vadc_linear_graph { |
| 776 | int64_t dy; |
| 777 | int64_t dx; |
| 778 | int64_t adc_vref; |
| 779 | int64_t adc_gnd; |
| 780 | }; |
| 781 | |
| 782 | /** |
| 783 | * struct qpnp_vadc_map_pt - Map the graph representation for ADC channel |
| 784 | * @x: Represent the ADC digitized code. |
| 785 | * @y: Represent the physical data which can be temperature, voltage, |
| 786 | * resistance. |
| 787 | */ |
| 788 | struct qpnp_vadc_map_pt { |
| 789 | int32_t x; |
| 790 | int32_t y; |
| 791 | }; |
| 792 | |
| 793 | /** |
| 794 | * struct qpnp_vadc_scaling_ratio - Represent scaling ratio for adc input. |
| 795 | * @num: Numerator scaling parameter. |
| 796 | * @den: Denominator scaling parameter. |
| 797 | */ |
| 798 | struct qpnp_vadc_scaling_ratio { |
| 799 | int32_t num; |
| 800 | int32_t den; |
| 801 | }; |
| 802 | |
| 803 | /** |
| 804 | * struct qpnp_adc_properties - Represent the ADC properties. |
| 805 | * @adc_reference: Reference voltage for QPNP ADC. |
| 806 | * @bitresolution: ADC bit resolution for QPNP ADC. |
| 807 | * @biploar: Polarity for QPNP ADC. |
| 808 | */ |
| 809 | struct qpnp_adc_properties { |
| 810 | uint32_t adc_vdd_reference; |
| 811 | uint32_t bitresolution; |
| 812 | bool bipolar; |
| 813 | }; |
| 814 | |
| 815 | /** |
| 816 | * struct qpnp_vadc_chan_properties - Represent channel properties of the ADC. |
| 817 | * @offset_gain_numerator: The inverse numerator of the gain applied to the |
| 818 | * input channel. |
| 819 | * @offset_gain_denominator: The inverse denominator of the gain applied to the |
| 820 | * input channel. |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 821 | * @high_thr: High threshold voltage that is requested to be set. |
| 822 | * @low_thr: Low threshold voltage that is requested to be set. |
| 823 | * @timer_select: Choosen from one of the 3 timers to set the polling rate for |
| 824 | * the VADC_BTM channel. |
| 825 | * @meas_interval1: Polling rate to set for timer 1. |
| 826 | * @meas_interval2: Polling rate to set for timer 2. |
| 827 | * @tm_channel_select: BTM channel number for the 5 VADC_BTM channels. |
| 828 | * @state_request: User can select either enable or disable high/low or both |
| 829 | * activation levels based on the qpnp_state_request type. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 830 | * @adc_graph: ADC graph for the channel of struct type qpnp_adc_linear_graph. |
| 831 | */ |
| 832 | struct qpnp_vadc_chan_properties { |
| 833 | uint32_t offset_gain_numerator; |
| 834 | uint32_t offset_gain_denominator; |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 835 | uint32_t high_thr; |
| 836 | uint32_t low_thr; |
| 837 | enum qpnp_adc_meas_timer_select timer_select; |
| 838 | enum qpnp_adc_meas_timer_1 meas_interval1; |
| 839 | enum qpnp_adc_meas_timer_2 meas_interval2; |
| 840 | enum qpnp_adc_tm_channel_select tm_channel_select; |
| 841 | enum qpnp_state_request state_request; |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 842 | struct qpnp_vadc_linear_graph adc_graph[2]; |
| 843 | }; |
| 844 | |
| 845 | /** |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 846 | * struct qpnp_vadc_result - Represent the result of the QPNP ADC. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 847 | * @chan: The channel number of the requested conversion. |
| 848 | * @adc_code: The pre-calibrated digital output of a given ADC relative to the |
| 849 | * the ADC reference. |
| 850 | * @measurement: In units specific for a given ADC; most ADC uses reference |
| 851 | * voltage but some ADC uses reference current. This measurement |
| 852 | * here is a number relative to a reference of a given ADC. |
| 853 | * @physical: The data meaningful for each individual channel whether it is |
| 854 | * voltage, current, temperature, etc. |
| 855 | * All voltage units are represented in micro - volts. |
| 856 | * -Battery temperature units are represented as 0.1 DegC. |
| 857 | * -PA Therm temperature units are represented as DegC. |
| 858 | * -PMIC Die temperature units are represented as 0.001 DegC. |
| 859 | */ |
| 860 | struct qpnp_vadc_result { |
| 861 | uint32_t chan; |
| 862 | int32_t adc_code; |
| 863 | int64_t measurement; |
| 864 | int64_t physical; |
| 865 | }; |
| 866 | |
| 867 | /** |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 868 | * struct qpnp_adc_amux - AMUX properties for individual channel |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 869 | * @name: Channel string name. |
| 870 | * @channel_num: Channel in integer used from qpnp_adc_channels. |
| 871 | * @chan_path_prescaling: Channel scaling performed on the input signal. |
| 872 | * @adc_decimation: Sampling rate desired for the channel. |
| 873 | * adc_scale_fn: Scaling function to convert to the data meaningful for |
| 874 | * each individual channel whether it is voltage, current, |
| 875 | * temperature, etc and compensates the channel properties. |
| 876 | */ |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 877 | struct qpnp_adc_amux { |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 878 | char *name; |
| 879 | enum qpnp_vadc_channels channel_num; |
| 880 | enum qpnp_adc_channel_scaling_param chan_path_prescaling; |
| 881 | enum qpnp_adc_decimation_type adc_decimation; |
| 882 | enum qpnp_adc_scale_fn_type adc_scale_fn; |
| 883 | enum qpnp_adc_fast_avg_ctl fast_avg_setup; |
| 884 | enum qpnp_adc_hw_settle_time hw_settle_time; |
| 885 | }; |
| 886 | |
| 887 | /** |
| 888 | * struct qpnp_vadc_scaling_ratio |
| 889 | * |
| 890 | */ |
| 891 | static const struct qpnp_vadc_scaling_ratio qpnp_vadc_amux_scaling_ratio[] = { |
| 892 | {1, 1}, |
| 893 | {1, 3}, |
| 894 | {1, 4}, |
| 895 | {1, 6}, |
Dipen Parmar | 46f8ac6 | 2014-01-19 22:45:11 +0530 | [diff] [blame] | 896 | {1, 20}, |
| 897 | {1, 8} |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 898 | }; |
| 899 | |
| 900 | /** |
| 901 | * struct qpnp_vadc_scale_fn - Scaling function prototype |
| 902 | * @chan: Function pointer to one of the scaling functions |
| 903 | * which takes the adc properties, channel properties, |
| 904 | * and returns the physical result |
| 905 | */ |
| 906 | struct qpnp_vadc_scale_fn { |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 907 | int32_t (*chan) (struct qpnp_vadc_chip *, int32_t, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 908 | const struct qpnp_adc_properties *, |
| 909 | const struct qpnp_vadc_chan_properties *, |
| 910 | struct qpnp_vadc_result *); |
| 911 | }; |
| 912 | |
| 913 | /** |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 914 | * struct qpnp_adc_tm_reverse_scale_fn - Reverse scaling prototype |
| 915 | * @chan: Function pointer to one of the scaling functions |
| 916 | * which takes the adc properties, channel properties, |
| 917 | * and returns the physical result |
| 918 | */ |
| 919 | struct qpnp_adc_tm_reverse_scale_fn { |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 920 | int32_t (*chan) (struct qpnp_vadc_chip *, |
| 921 | struct qpnp_adc_tm_btm_param *, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 922 | uint32_t *, uint32_t *); |
| 923 | }; |
| 924 | |
| 925 | /** |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 926 | * struct qpnp_iadc_calib - IADC channel calibration structure. |
| 927 | * @channel - Channel for which the historical offset and gain is |
| 928 | * calculated. Available channels are internal rsense, |
| 929 | * external rsense and alternate lead pairs. |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 930 | * @offset_raw - raw Offset value for the channel. |
| 931 | * @gain_raw - raw Gain of the channel. |
| 932 | * @ideal_offset_uv - ideal offset value for the channel. |
| 933 | * @ideal_gain_nv - ideal gain for the channel. |
| 934 | * @offset_uv - converted value of offset in uV. |
| 935 | * @gain_uv - converted value of gain in uV. |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 936 | */ |
| 937 | struct qpnp_iadc_calib { |
| 938 | enum qpnp_iadc_channels channel; |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 939 | uint16_t offset_raw; |
| 940 | uint16_t gain_raw; |
| 941 | uint32_t ideal_offset_uv; |
| 942 | uint32_t ideal_gain_nv; |
| 943 | uint32_t offset_uv; |
| 944 | uint32_t gain_uv; |
| 945 | }; |
| 946 | |
| 947 | /** |
| 948 | * struct qpnp_iadc_result - IADC read result structure. |
| 949 | * @oresult_uv - Result of ADC in uV. |
| 950 | * @result_ua - Result of ADC in uA. |
| 951 | */ |
| 952 | struct qpnp_iadc_result { |
| 953 | int32_t result_uv; |
| 954 | int32_t result_ua; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 955 | }; |
| 956 | |
| 957 | /** |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 958 | * struct qpnp_adc_drv - QPNP ADC device structure. |
| 959 | * @spmi - spmi device for ADC peripheral. |
| 960 | * @offset - base offset for the ADC peripheral. |
| 961 | * @adc_prop - ADC properties specific to the ADC peripheral. |
| 962 | * @amux_prop - AMUX properties representing the ADC peripheral. |
| 963 | * @adc_channels - ADC channel properties for the ADC peripheral. |
Siddartha Mohanadoss | 1210995 | 2012-11-20 14:57:51 -0800 | [diff] [blame] | 964 | * @adc_irq_eoc - End of Conversion IRQ. |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 965 | * @adc_irq_fifo_not_empty - Conversion sequencer request written |
| 966 | * to FIFO when not empty. |
| 967 | * @adc_irq_conv_seq_timeout - Conversion sequencer trigger timeout. |
| 968 | * @adc_high_thr_irq - Output higher than high threshold set for measurement. |
| 969 | * @adc_low_thr_irq - Output lower than low threshold set for measurement. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 970 | * @adc_lock - ADC lock for access to the peripheral. |
| 971 | * @adc_rslt_completion - ADC result notification after interrupt |
| 972 | * is received. |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 973 | * @calib - Internal rsens calibration values for gain and offset. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 974 | */ |
| 975 | struct qpnp_adc_drv { |
| 976 | struct spmi_device *spmi; |
| 977 | uint8_t slave; |
| 978 | uint16_t offset; |
| 979 | struct qpnp_adc_properties *adc_prop; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 980 | struct qpnp_adc_amux_properties *amux_prop; |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 981 | struct qpnp_adc_amux *adc_channels; |
Siddartha Mohanadoss | 1210995 | 2012-11-20 14:57:51 -0800 | [diff] [blame] | 982 | int adc_irq_eoc; |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 983 | int adc_irq_fifo_not_empty; |
| 984 | int adc_irq_conv_seq_timeout; |
| 985 | int adc_high_thr_irq; |
| 986 | int adc_low_thr_irq; |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 987 | struct mutex adc_lock; |
| 988 | struct completion adc_rslt_completion; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 989 | struct qpnp_iadc_calib calib; |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 990 | }; |
| 991 | |
| 992 | /** |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 993 | * struct qpnp_adc_amux_properties - QPNP VADC amux channel property. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 994 | * @amux_channel - Refer to the qpnp_vadc_channel list. |
| 995 | * @decimation - Sampling rate supported for the channel. |
| 996 | * @mode_sel - The basic mode of operation. |
| 997 | * @hw_settle_time - The time between AMUX being configured and the |
| 998 | * start of conversion. |
| 999 | * @fast_avg_setup - Ability to provide single result from the ADC |
| 1000 | * that is an average of multiple measurements. |
| 1001 | * @trigger_channel - HW trigger channel for conversion sequencer. |
| 1002 | * @chan_prop - Represent the channel properties of the ADC. |
| 1003 | */ |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1004 | struct qpnp_adc_amux_properties { |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1005 | uint32_t amux_channel; |
| 1006 | uint32_t decimation; |
| 1007 | uint32_t mode_sel; |
| 1008 | uint32_t hw_settle_time; |
| 1009 | uint32_t fast_avg_setup; |
| 1010 | enum qpnp_vadc_trigger trigger_channel; |
| 1011 | struct qpnp_vadc_chan_properties chan_prop[0]; |
| 1012 | }; |
| 1013 | |
| 1014 | /* Public API */ |
| 1015 | #if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \ |
| 1016 | || defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE_MODULE) |
| 1017 | /** |
| 1018 | * qpnp_vadc_read() - Performs ADC read on the channel. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1019 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1020 | * @channel: Input channel to perform the ADC read. |
| 1021 | * @result: Structure pointer of type adc_chan_result |
| 1022 | * in which the ADC read results are stored. |
| 1023 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1024 | int32_t qpnp_vadc_read(struct qpnp_vadc_chip *dev, |
| 1025 | enum qpnp_vadc_channels channel, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1026 | struct qpnp_vadc_result *result); |
| 1027 | |
| 1028 | /** |
| 1029 | * qpnp_vadc_conv_seq_request() - Performs ADC read on the conversion |
| 1030 | * sequencer channel. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1031 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1032 | * @channel: Input channel to perform the ADC read. |
| 1033 | * @result: Structure pointer of type adc_chan_result |
| 1034 | * in which the ADC read results are stored. |
| 1035 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1036 | int32_t qpnp_vadc_conv_seq_request(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1037 | enum qpnp_vadc_trigger trigger_channel, |
| 1038 | enum qpnp_vadc_channels channel, |
| 1039 | struct qpnp_vadc_result *result); |
| 1040 | |
| 1041 | /** |
| 1042 | * qpnp_vadc_check_result() - Performs check on the ADC raw code. |
| 1043 | * @data: Data used for verifying the range of the ADC code. |
| 1044 | */ |
| 1045 | int32_t qpnp_vadc_check_result(int32_t *data); |
| 1046 | |
| 1047 | /** |
| 1048 | * qpnp_adc_get_devicetree_data() - Abstracts the ADC devicetree data. |
| 1049 | * @spmi: spmi ADC device. |
| 1050 | * @adc_qpnp: spmi device tree node structure |
| 1051 | */ |
| 1052 | int32_t qpnp_adc_get_devicetree_data(struct spmi_device *spmi, |
| 1053 | struct qpnp_adc_drv *adc_qpnp); |
| 1054 | |
| 1055 | /** |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1056 | * qpnp_adc_scale_default() - Scales the pre-calibrated digital output |
| 1057 | * of an ADC to the ADC reference and compensates for the |
| 1058 | * gain and offset. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1059 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1060 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1061 | * @adc_prop: adc properties of the qpnp adc such as bit resolution, |
| 1062 | * reference voltage. |
| 1063 | * @chan_prop: Individual channel properties to compensate the i/p scaling, |
| 1064 | * slope and offset. |
| 1065 | * @chan_rslt: Physical result to be stored. |
| 1066 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1067 | int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *dev, |
| 1068 | int32_t adc_code, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1069 | const struct qpnp_adc_properties *adc_prop, |
| 1070 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1071 | struct qpnp_vadc_result *chan_rslt); |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1072 | /** |
| 1073 | * qpnp_adc_scale_pmic_therm() - Scales the pre-calibrated digital output |
| 1074 | * of an ADC to the ADC reference and compensates for the |
| 1075 | * gain and offset. Performs the AMUX out as 2mV/K and returns |
| 1076 | * the temperature in milli degC. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1077 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1078 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1079 | * @adc_prop: adc properties of the qpnp adc such as bit resolution, |
| 1080 | * reference voltage. |
| 1081 | * @chan_prop: Individual channel properties to compensate the i/p scaling, |
| 1082 | * slope and offset. |
| 1083 | * @chan_rslt: Physical result to be stored. |
| 1084 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1085 | int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *dev, |
| 1086 | int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1087 | const struct qpnp_adc_properties *adc_prop, |
| 1088 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1089 | struct qpnp_vadc_result *chan_rslt); |
| 1090 | /** |
| 1091 | * qpnp_adc_scale_batt_therm() - Scales the pre-calibrated digital output |
| 1092 | * of an ADC to the ADC reference and compensates for the |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 1093 | * gain and offset. Returns the temperature in decidegC. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1094 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1095 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1096 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1097 | * reference voltage. |
| 1098 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1099 | * slope and offset. |
| 1100 | * @chan_rslt: physical result to be stored. |
| 1101 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1102 | int32_t qpnp_adc_scale_batt_therm(struct qpnp_vadc_chip *dev, |
| 1103 | int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1104 | const struct qpnp_adc_properties *adc_prop, |
| 1105 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1106 | struct qpnp_vadc_result *chan_rslt); |
| 1107 | /** |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 1108 | * qpnp_adc_scale_qrd_batt_therm() - Scales the pre-calibrated digital output |
| 1109 | * of an ADC to the ADC reference and compensates for the |
| 1110 | * gain and offset. Returns the temperature in decidegC. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1111 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 1112 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1113 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1114 | * reference voltage. |
| 1115 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1116 | * slope and offset. |
| 1117 | * @chan_rslt: physical result to be stored. |
| 1118 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1119 | int32_t qpnp_adc_scale_qrd_batt_therm(struct qpnp_vadc_chip *dev, |
| 1120 | int32_t adc_code, |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 1121 | const struct qpnp_adc_properties *adc_prop, |
| 1122 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1123 | struct qpnp_vadc_result *chan_rslt); |
| 1124 | /** |
Xu Kai | 81c6052 | 2013-07-27 14:26:04 +0800 | [diff] [blame] | 1125 | * qpnp_adc_scale_qrd_skuaa_batt_therm() - Scales the pre-calibrated digital output |
| 1126 | * of an ADC to the ADC reference and compensates for the |
| 1127 | * gain and offset. Returns the temperature in decidegC. |
| 1128 | * @dev: Structure device for qpnp vadc |
| 1129 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1130 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1131 | * reference voltage. |
| 1132 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1133 | * slope and offset. |
| 1134 | * @chan_rslt: physical result to be stored. |
| 1135 | */ |
| 1136 | int32_t qpnp_adc_scale_qrd_skuaa_batt_therm(struct qpnp_vadc_chip *dev, |
| 1137 | int32_t adc_code, |
| 1138 | const struct qpnp_adc_properties *adc_prop, |
| 1139 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1140 | struct qpnp_vadc_result *chan_rslt); |
| 1141 | /** |
Wu Fenglin | 2c6ef8f | 2013-12-17 11:33:33 +0800 | [diff] [blame] | 1142 | * qpnp_adc_scale_qrd_skug_batt_therm() - Scales the pre-calibrated digital output |
| 1143 | * of an ADC to the ADC reference and compensates for the |
| 1144 | * gain and offset. Returns the temperature in decidegC. |
| 1145 | * @dev: Structure device for qpnp vadc |
| 1146 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1147 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1148 | * reference voltage. |
| 1149 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1150 | * slope and offset. |
| 1151 | * @chan_rslt: physical result to be stored. |
| 1152 | */ |
| 1153 | int32_t qpnp_adc_scale_qrd_skug_batt_therm(struct qpnp_vadc_chip *dev, |
| 1154 | int32_t adc_code, |
| 1155 | const struct qpnp_adc_properties *adc_prop, |
| 1156 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1157 | struct qpnp_vadc_result *chan_rslt); |
| 1158 | /** |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1159 | * qpnp_adc_scale_batt_id() - Scales the pre-calibrated digital output |
| 1160 | * of an ADC to the ADC reference and compensates for the |
| 1161 | * gain and offset. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1162 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1163 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1164 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1165 | * reference voltage. |
| 1166 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1167 | * slope and offset. |
| 1168 | * @chan_rslt: physical result to be stored. |
| 1169 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1170 | int32_t qpnp_adc_scale_batt_id(struct qpnp_vadc_chip *dev, int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1171 | const struct qpnp_adc_properties *adc_prop, |
| 1172 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1173 | struct qpnp_vadc_result *chan_rslt); |
| 1174 | /** |
| 1175 | * qpnp_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output |
| 1176 | * of an ADC to the ADC reference and compensates for the |
| 1177 | * gain and offset. Returns the temperature of the xo therm in mili |
| 1178 | degC. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1179 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1180 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1181 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1182 | * reference voltage. |
| 1183 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1184 | * slope and offset. |
| 1185 | * @chan_rslt: physical result to be stored. |
| 1186 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1187 | int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *dev, int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1188 | const struct qpnp_adc_properties *adc_prop, |
| 1189 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1190 | struct qpnp_vadc_result *chan_rslt); |
| 1191 | /** |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1192 | * qpnp_adc_scale_therm_pu1() - Scales the pre-calibrated digital output |
| 1193 | * of an ADC to the ADC reference and compensates for the |
| 1194 | * gain and offset. Returns the temperature of the therm in degC. |
| 1195 | * It uses a mapping table computed for a 150K pull-up. |
| 1196 | * Pull-up1 is an internal pull-up on the AMUX of 150K. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1197 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1198 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1199 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1200 | * reference voltage. |
| 1201 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1202 | * slope and offset. |
| 1203 | * @chan_rslt: physical result to be stored. |
| 1204 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1205 | int32_t qpnp_adc_scale_therm_pu1(struct qpnp_vadc_chip *dev, int32_t adc_code, |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1206 | const struct qpnp_adc_properties *adc_prop, |
| 1207 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1208 | struct qpnp_vadc_result *chan_rslt); |
| 1209 | /** |
| 1210 | * qpnp_adc_scale_therm_pu2() - Scales the pre-calibrated digital output |
| 1211 | * of an ADC to the ADC reference and compensates for the |
| 1212 | * gain and offset. Returns the temperature of the therm in degC. |
| 1213 | * It uses a mapping table computed for a 100K pull-up. |
| 1214 | * Pull-up2 is an internal pull-up on the AMUX of 100K. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1215 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1216 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 1217 | * @adc_prop: adc properties of the pm8xxx adc such as bit resolution, |
| 1218 | * reference voltage. |
| 1219 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 1220 | * slope and offset. |
| 1221 | * @chan_rslt: physical result to be stored. |
| 1222 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1223 | int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *dev, int32_t adc_code, |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1224 | const struct qpnp_adc_properties *adc_prop, |
| 1225 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1226 | struct qpnp_vadc_result *chan_rslt); |
| 1227 | /** |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1228 | * qpnp_get_vadc() - Clients need to register with the vadc using the |
| 1229 | * corresponding device instance it wants to read the channels |
| 1230 | * from. Read the bindings document on how to pass the phandle |
| 1231 | * for the corresponding vadc driver to register with. |
| 1232 | * @dev: Clients device structure |
| 1233 | * @name: Corresponding client's DT parser name. Read the DT bindings |
| 1234 | * document on how to register with the vadc |
| 1235 | * @struct qpnp_vadc_chip * - On success returns the vadc device structure |
| 1236 | * pointer that needs to be used during an ADC request. |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1237 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1238 | struct qpnp_vadc_chip *qpnp_get_vadc(struct device *dev, const char *name); |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1239 | /** |
| 1240 | * qpnp_adc_tm_scaler() - Performs reverse calibration. |
| 1241 | * @config: Thermal monitoring configuration. |
| 1242 | * @adc_prop: adc properties of the qpnp adc such as bit resolution and |
| 1243 | * reference voltage. |
| 1244 | * @chan_prop: Individual channel properties to compensate the i/p scaling, |
| 1245 | * slope and offset. |
| 1246 | */ |
| 1247 | static inline int32_t qpnp_adc_tm_scaler(struct qpnp_adc_tm_config *tm_config, |
| 1248 | const struct qpnp_adc_properties *adc_prop, |
| 1249 | const struct qpnp_vadc_chan_properties *chan_prop) |
| 1250 | { return -ENXIO; } |
| 1251 | /** |
| 1252 | * qpnp_get_vadc_gain_and_offset() - Obtains the VADC gain and offset |
| 1253 | * for absolute and ratiometric calibration. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1254 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1255 | * @param: The result in which the ADC offset and gain values are stored. |
| 1256 | * @type: The calibration type whether client needs the absolute or |
| 1257 | * ratiometric gain and offset values. |
| 1258 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1259 | int32_t qpnp_get_vadc_gain_and_offset(struct qpnp_vadc_chip *dev, |
| 1260 | struct qpnp_vadc_linear_graph *param, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1261 | enum qpnp_adc_calib_type calib_type); |
| 1262 | /** |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1263 | * qpnp_adc_scale_millidegc_pmic_voltage_thr() - Performs reverse calibration |
| 1264 | * on the low/high temperature threshold values passed by the |
| 1265 | * client. The function coverts milldegC to voltage threshold |
| 1266 | * and accounts for the corresponding channels scaling as (2mV/K). |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1267 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1268 | * @param: The input parameters that contain the low/high temperature |
| 1269 | * values. |
| 1270 | * @low_threshold: The low threshold value that needs to be updated with |
| 1271 | * the above calibrated voltage value. |
| 1272 | * @high_threshold: The low threshold value that needs to be updated with |
| 1273 | * the above calibrated voltage value. |
| 1274 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1275 | int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1276 | struct qpnp_adc_tm_btm_param *param, |
| 1277 | uint32_t *low_threshold, uint32_t *high_threshold); |
| 1278 | /** |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1279 | * qpnp_adc_btm_scaler() - Performs reverse calibration on the low/high |
| 1280 | * temperature threshold values passed by the client. |
| 1281 | * The function maps the temperature to voltage and applies |
| 1282 | * ratiometric calibration on the voltage values. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1283 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1284 | * @param: The input parameters that contain the low/high temperature |
| 1285 | * values. |
| 1286 | * @low_threshold: The low threshold value that needs to be updated with |
| 1287 | * the above calibrated voltage value. |
| 1288 | * @high_threshold: The low threshold value that needs to be updated with |
| 1289 | * the above calibrated voltage value. |
| 1290 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1291 | int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *dev, |
| 1292 | struct qpnp_adc_tm_btm_param *param, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1293 | uint32_t *low_threshold, uint32_t *high_threshold); |
| 1294 | /** |
| 1295 | * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration |
| 1296 | * and convert given temperature to voltage on supported |
| 1297 | * thermistor channels using 100k pull-up. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1298 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1299 | * @param: The input temperature values. |
| 1300 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1301 | int32_t qpnp_adc_tm_scale_therm_voltage_pu2(struct qpnp_vadc_chip *dev, |
| 1302 | struct qpnp_adc_tm_config *param); |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1303 | /** |
| 1304 | * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration |
| 1305 | * and converts the given ADC code to temperature for |
| 1306 | * thermistor channels using 100k pull-up. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1307 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1308 | * @reg: The input ADC code. |
| 1309 | * @result: The physical measurement temperature on the thermistor. |
| 1310 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1311 | int32_t qpnp_adc_tm_scale_voltage_therm_pu2(struct qpnp_vadc_chip *dev, |
| 1312 | uint32_t reg, int64_t *result); |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1313 | /** |
| 1314 | * qpnp_adc_usb_scaler() - Performs reverse calibration on the low/high |
| 1315 | * voltage threshold values passed by the client. |
| 1316 | * The function applies ratiometric calibration on the |
| 1317 | * voltage values. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1318 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1319 | * @param: The input parameters that contain the low/high voltage |
| 1320 | * threshold values. |
| 1321 | * @low_threshold: The low threshold value that needs to be updated with |
| 1322 | * the above calibrated voltage value. |
| 1323 | * @high_threshold: The low threshold value that needs to be updated with |
| 1324 | * the above calibrated voltage value. |
| 1325 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1326 | int32_t qpnp_adc_usb_scaler(struct qpnp_vadc_chip *dev, |
| 1327 | struct qpnp_adc_tm_btm_param *param, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1328 | uint32_t *low_threshold, uint32_t *high_threshold); |
| 1329 | /** |
| 1330 | * qpnp_adc_vbatt_rscaler() - Performs reverse calibration on the low/high |
| 1331 | * voltage threshold values passed by the client. |
| 1332 | * The function applies ratiometric calibration on the |
| 1333 | * voltage values. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1334 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1335 | * @param: The input parameters that contain the low/high voltage |
| 1336 | * threshold values. |
| 1337 | * @low_threshold: The low threshold value that needs to be updated with |
| 1338 | * the above calibrated voltage value. |
| 1339 | * @high_threshold: The low threshold value that needs to be updated with |
| 1340 | * the above calibrated voltage value. |
| 1341 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1342 | int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev, |
| 1343 | struct qpnp_adc_tm_btm_param *param, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1344 | uint32_t *low_threshold, uint32_t *high_threshold); |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1345 | /** |
| 1346 | * qpnp_vadc_iadc_sync_request() - Performs Voltage ADC read and |
| 1347 | * locks the peripheral. When performing simultaneous |
| 1348 | * voltage and current request the VADC peripheral is |
| 1349 | * prepared for conversion and the IADC sync conversion |
| 1350 | * is done from the IADC peripheral. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1351 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1352 | * @channel: Input channel to perform the voltage ADC read. |
| 1353 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1354 | int32_t qpnp_vadc_iadc_sync_request(struct qpnp_vadc_chip *dev, |
| 1355 | enum qpnp_vadc_channels channel); |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1356 | /** |
| 1357 | * qpnp_vadc_iadc_sync_complete_request() - Reads the ADC result and |
| 1358 | * unlocks the peripheral. |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1359 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1360 | * @result: Structure pointer of type adc_chan_result |
| 1361 | * in which the ADC read results are stored. |
| 1362 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1363 | int32_t qpnp_vadc_iadc_sync_complete_request(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1364 | enum qpnp_vadc_channels channel, struct qpnp_vadc_result *result); |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame] | 1365 | /** |
| 1366 | * qpnp_vadc_sns_comp_result() - Compensate vbatt readings based on temperature |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1367 | * @dev: Structure device for qpnp vadc |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame] | 1368 | * @result: Voltage in uV that needs compensation. |
| 1369 | */ |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1370 | int32_t qpnp_vbat_sns_comp_result(struct qpnp_vadc_chip *dev, |
| 1371 | int64_t *result); |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1372 | #else |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1373 | static inline int32_t qpnp_vadc_read(struct qpnp_vadc_chip *dev, |
| 1374 | uint32_t channel, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1375 | struct qpnp_vadc_result *result) |
| 1376 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1377 | static inline int32_t qpnp_vadc_conv_seq_request(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1378 | enum qpnp_vadc_trigger trigger_channel, |
| 1379 | enum qpnp_vadc_channels channel, |
| 1380 | struct qpnp_vadc_result *result) |
| 1381 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1382 | static inline int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *vadc, |
| 1383 | int32_t adc_code, |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1384 | const struct qpnp_adc_properties *adc_prop, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1385 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1386 | struct qpnp_vadc_result *chan_rslt) |
| 1387 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1388 | static inline int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *vadc, |
| 1389 | int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1390 | const struct qpnp_adc_properties *adc_prop, |
| 1391 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1392 | struct qpnp_vadc_result *chan_rslt) |
| 1393 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1394 | static inline int32_t qpnp_adc_scale_batt_therm(struct qpnp_vadc_chip *vadc, |
| 1395 | int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1396 | const struct qpnp_adc_properties *adc_prop, |
| 1397 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1398 | struct qpnp_vadc_result *chan_rslt) |
| 1399 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1400 | static inline int32_t qpnp_adc_scale_qrd_batt_therm( |
| 1401 | struct qpnp_vadc_chip *vadc, int32_t adc_code, |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 1402 | const struct qpnp_adc_properties *adc_prop, |
| 1403 | const struct qpnp_vadc_chan_properties *chan_prop, |
Xu Kai | 81c6052 | 2013-07-27 14:26:04 +0800 | [diff] [blame] | 1404 | struct qpnp_vadc_result *chan_rslt) |
| 1405 | { return -ENXIO; } |
| 1406 | static inline int32_t qpnp_adc_scale_qrd_skuaa_batt_therm( |
| 1407 | struct qpnp_vadc_chip *vadc, int32_t adc_code, |
| 1408 | const struct qpnp_adc_properties *adc_prop, |
| 1409 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1410 | struct qpnp_vadc_result *chan_rslt) |
Siddartha Mohanadoss | b99cfa9 | 2013-05-01 20:19:58 -0700 | [diff] [blame] | 1411 | { return -ENXIO; } |
Wu Fenglin | 2c6ef8f | 2013-12-17 11:33:33 +0800 | [diff] [blame] | 1412 | static inline int32_t qpnp_adc_scale_qrd_skug_batt_therm( |
| 1413 | struct qpnp_vadc_chip *vadc, int32_t adc_code, |
| 1414 | const struct qpnp_adc_properties *adc_prop, |
| 1415 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1416 | struct qpnp_vadc_result *chan_rslt) |
| 1417 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1418 | static inline int32_t qpnp_adc_scale_batt_id(struct qpnp_vadc_chip *vadc, |
| 1419 | int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1420 | const struct qpnp_adc_properties *adc_prop, |
| 1421 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1422 | struct qpnp_vadc_result *chan_rslt) |
| 1423 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1424 | static inline int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *vadc, |
| 1425 | int32_t adc_code, |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1426 | const struct qpnp_adc_properties *adc_prop, |
| 1427 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 1428 | struct qpnp_vadc_result *chan_rslt) |
| 1429 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1430 | static inline int32_t qpnp_adc_scale_therm_pu1(struct qpnp_vadc_chip *vadc, |
| 1431 | int32_t adc_code, |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1432 | const struct qpnp_adc_properties *adc_prop, |
| 1433 | const struct qpnp_vadc_chan_properties *chan_prop, |
David Keitel | c96dc85 | 2013-03-04 14:57:34 -0800 | [diff] [blame] | 1434 | struct qpnp_vadc_result *chan_rslt) |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1435 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1436 | static inline int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *vadc, |
| 1437 | int32_t adc_code, |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1438 | const struct qpnp_adc_properties *adc_prop, |
| 1439 | const struct qpnp_vadc_chan_properties *chan_prop, |
David Keitel | c96dc85 | 2013-03-04 14:57:34 -0800 | [diff] [blame] | 1440 | struct qpnp_vadc_result *chan_rslt) |
Siddartha Mohanadoss | e77edf1 | 2012-09-13 14:26:32 -0700 | [diff] [blame] | 1441 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1442 | static inline struct qpnp_vadc_chip *qpnp_get_vadc(struct device *dev, |
| 1443 | const char *name) |
| 1444 | { return ERR_PTR(-ENXIO); } |
| 1445 | static inline int32_t qpnp_get_vadc_gain_and_offset(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1446 | struct qpnp_vadc_linear_graph *param, |
| 1447 | enum qpnp_adc_calib_type calib_type) |
| 1448 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1449 | static inline int32_t qpnp_adc_usb_scaler(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1450 | struct qpnp_adc_tm_btm_param *param, |
| 1451 | uint32_t *low_threshold, uint32_t *high_threshold) |
| 1452 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1453 | static inline int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1454 | struct qpnp_adc_tm_btm_param *param, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1455 | uint32_t *low_threshold, uint32_t *high_threshold) |
| 1456 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1457 | static inline int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1458 | struct qpnp_adc_tm_btm_param *param, |
| 1459 | uint32_t *low_threshold, uint32_t *high_threshold) |
| 1460 | { return -ENXIO; } |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1461 | static inline int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr( |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1462 | struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1463 | struct qpnp_adc_tm_btm_param *param, |
| 1464 | uint32_t *low_threshold, uint32_t *high_threshold) |
| 1465 | { return -ENXIO; } |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1466 | static inline int32_t qpnp_adc_tm_scale_therm_voltage_pu2( |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1467 | struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1468 | struct qpnp_adc_tm_config *param) |
| 1469 | { return -ENXIO; } |
| 1470 | static inline int32_t qpnp_adc_tm_scale_voltage_therm_pu2( |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1471 | struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | d0f4fd1 | 2012-11-20 16:28:40 -0800 | [diff] [blame] | 1472 | uint32_t reg, int64_t *result) |
| 1473 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1474 | static inline int32_t qpnp_vadc_iadc_sync_request(struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1475 | enum qpnp_vadc_channels channel) |
| 1476 | { return -ENXIO; } |
| 1477 | static inline int32_t qpnp_vadc_iadc_sync_complete_request( |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1478 | struct qpnp_vadc_chip *dev, |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1479 | enum qpnp_vadc_channels channel, |
| 1480 | struct qpnp_vadc_result *result) |
| 1481 | { return -ENXIO; } |
Siddartha Mohanadoss | 3cb2b6b | 2013-06-21 12:07:05 -0700 | [diff] [blame] | 1482 | static inline int32_t qpnp_vbat_sns_comp_result(struct qpnp_vadc_chip *dev, |
| 1483 | int64_t *result) |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame] | 1484 | { return -ENXIO; } |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1485 | #endif |
| 1486 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1487 | /* Public API */ |
| 1488 | #if defined(CONFIG_SENSORS_QPNP_ADC_CURRENT) \ |
| 1489 | || defined(CONFIG_SENSORS_QPNP_ADC_CURRENT_MODULE) |
| 1490 | /** |
| 1491 | * qpnp_iadc_read() - Performs ADC read on the current channel. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1492 | * @dev: Structure device for qpnp iadc |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1493 | * @channel: Input channel to perform the ADC read. |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1494 | * @result: Current across rsense in mA. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1495 | * @return: 0 on success. |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1496 | */ |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1497 | int32_t qpnp_iadc_read(struct qpnp_iadc_chip *dev, |
| 1498 | enum qpnp_iadc_channels channel, |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 1499 | struct qpnp_iadc_result *result); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1500 | /** |
Xiaozhe Shi | 767fdb6 | 2013-01-10 15:09:08 -0800 | [diff] [blame] | 1501 | * qpnp_iadc_get_rsense() - Reads the RDS resistance value from the |
| 1502 | trim registers. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1503 | * @dev: Structure device for qpnp iadc |
Xiaozhe Shi | 767fdb6 | 2013-01-10 15:09:08 -0800 | [diff] [blame] | 1504 | * @rsense: RDS resistance in nOhms. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1505 | * @return: 0 on success. |
Xiaozhe Shi | 767fdb6 | 2013-01-10 15:09:08 -0800 | [diff] [blame] | 1506 | */ |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1507 | int32_t qpnp_iadc_get_rsense(struct qpnp_iadc_chip *dev, int32_t *rsense); |
Xiaozhe Shi | 767fdb6 | 2013-01-10 15:09:08 -0800 | [diff] [blame] | 1508 | /** |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 1509 | * qpnp_iadc_get_gain_and_offset() - Performs gain calibration |
| 1510 | * over 17.8571mV and offset over selected |
| 1511 | * channel. Channel can be internal rsense, |
| 1512 | * external rsense and alternate lead pair. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1513 | * @dev: Structure device for qpnp iadc |
Siddartha Mohanadoss | 5e2988d | 2012-09-24 17:03:56 -0700 | [diff] [blame] | 1514 | * @result: result structure where the gain and offset is stored of |
| 1515 | * type qpnp_iadc_calib. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1516 | * @return: 0 on success. |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1517 | */ |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1518 | int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_chip *dev, |
| 1519 | struct qpnp_iadc_calib *result); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1520 | /** |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1521 | * qpnp_get_iadc() - Clients need to register with the iadc with the |
| 1522 | * corresponding device instance it wants to read the channels. |
| 1523 | * Read the bindings document on how to pass the phandle for |
| 1524 | * the corresponding vadc driver to register with. |
| 1525 | * @dev: Clients device structure |
| 1526 | * @name: Corresponding client's DT parser name. Read the DT bindings |
| 1527 | * document on how to register with the iadc |
| 1528 | * @struct qpnp_iadc_chip * - On success returns the iadc device structure |
| 1529 | * pointer used everytime client makes an ADC request. |
Siddartha Mohanadoss | 5ace110 | 2012-08-20 23:18:10 -0700 | [diff] [blame] | 1530 | */ |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1531 | struct qpnp_iadc_chip *qpnp_get_iadc(struct device *dev, const char *name); |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1532 | /** |
| 1533 | * qpnp_iadc_vadc_sync_read() - Performs synchronous VADC and IADC read. |
| 1534 | * The api is to be used only by the BMS to perform |
| 1535 | * simultaneous VADC and IADC measurement for battery voltage |
| 1536 | * and current. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1537 | * @dev: Structure device for qpnp iadc |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1538 | * @i_channel: Input battery current channel to perform the IADC read. |
| 1539 | * @i_result: Current across the rsense in mA. |
| 1540 | * @v_channel: Input battery voltage channel to perform VADC read. |
| 1541 | * @v_result: Voltage on the vbatt channel with units in mV. |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1542 | * @return: 0 on success. |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1543 | */ |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1544 | int32_t qpnp_iadc_vadc_sync_read(struct qpnp_iadc_chip *dev, |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1545 | enum qpnp_iadc_channels i_channel, struct qpnp_iadc_result *i_result, |
| 1546 | enum qpnp_vadc_channels v_channel, struct qpnp_vadc_result *v_result); |
Siddartha Mohanadoss | 0667392 | 2013-03-27 11:14:19 -0700 | [diff] [blame] | 1547 | /** |
Abhijeet Dharmapurikar | 0ef9b5c | 2013-07-15 18:24:38 -0700 | [diff] [blame] | 1548 | * qpnp_iadc_calibrate_for_trim - Clients can use this API to re-calibrate |
| 1549 | * IADC. The offset and gain values are programmed in the trim |
| 1550 | * registers. The offset and the gain can be retrieved using |
| 1551 | * qpnp_iadc_get_gain_and_offset |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1552 | * @dev: Structure device for qpnp iadc |
Abhijeet Dharmapurikar | 0ef9b5c | 2013-07-15 18:24:38 -0700 | [diff] [blame] | 1553 | * @batfet_closed: batfet is opened or closed. The IADC chooses proper |
| 1554 | * channel (internal/external) based on batfet status |
| 1555 | * for calibration. |
| 1556 | * RETURNS: 0 on success. |
Siddartha Mohanadoss | 0667392 | 2013-03-27 11:14:19 -0700 | [diff] [blame] | 1557 | */ |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1558 | int32_t qpnp_iadc_calibrate_for_trim(struct qpnp_iadc_chip *dev, |
| 1559 | bool batfet_closed); |
| 1560 | /** |
| 1561 | * qpnp_iadc_comp_result() - Compensates the result of the current based on |
| 1562 | * the gain and offset co-effients and rsense parameters. |
| 1563 | * @dev: Structure device for qpnp iadc |
| 1564 | * @result: Current value to perform the compensation. |
| 1565 | * @return: 0 on success. |
| 1566 | */ |
| 1567 | int32_t qpnp_iadc_comp_result(struct qpnp_iadc_chip *dev, int64_t *result); |
| 1568 | /** |
| 1569 | * qpnp_iadc_skip_calibration() - Clients can use this API to ask the driver |
| 1570 | * to skip iadc calibrations |
| 1571 | * @dev: Structure device for qpnp iadc |
| 1572 | * @result: 0 on success and -EPROBE_DEFER when probe for the device |
| 1573 | * has not occured. |
| 1574 | */ |
| 1575 | int qpnp_iadc_skip_calibration(struct qpnp_iadc_chip *dev); |
| 1576 | /** |
| 1577 | * qpnp_iadc_resume_calibration() - Clients can use this API to ask the driver |
| 1578 | * to resume iadc calibrations |
| 1579 | * @dev: Structure device for qpnp iadc |
| 1580 | * @result: 0 on success and -EPROBE_DEFER when probe for the device |
| 1581 | * has not occured. |
| 1582 | */ |
| 1583 | int qpnp_iadc_resume_calibration(struct qpnp_iadc_chip *dev); |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1584 | #else |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1585 | static inline int32_t qpnp_iadc_read(struct qpnp_iadc_chip *iadc, |
| 1586 | enum qpnp_iadc_channels channel, struct qpnp_iadc_result *result) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1587 | { return -ENXIO; } |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1588 | static inline int32_t qpnp_iadc_get_rsense(struct qpnp_iadc_chip *iadc, |
| 1589 | int32_t *rsense) |
Siddartha Mohanadoss | 563166b | 2013-02-20 12:47:24 -0800 | [diff] [blame] | 1590 | { return -ENXIO; } |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1591 | static inline int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_chip *iadc, |
| 1592 | struct qpnp_iadc_calib *result) |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1593 | { return -ENXIO; } |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1594 | static inline struct qpnp_iadc_chip *qpnp_get_iadc(struct device *dev, |
| 1595 | const char *name) |
| 1596 | { return ERR_PTR(-ENXIO); } |
| 1597 | static inline int32_t qpnp_iadc_vadc_sync_read(struct qpnp_iadc_chip *iadc, |
Siddartha Mohanadoss | a32ea2a | 2013-02-12 09:58:31 -0800 | [diff] [blame] | 1598 | enum qpnp_iadc_channels i_channel, struct qpnp_iadc_result *i_result, |
| 1599 | enum qpnp_vadc_channels v_channel, struct qpnp_vadc_result *v_result) |
| 1600 | { return -ENXIO; } |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1601 | static inline int32_t qpnp_iadc_calibrate_for_trim(struct qpnp_iadc_chip *iadc, |
| 1602 | bool batfet_closed) |
Siddartha Mohanadoss | 0667392 | 2013-03-27 11:14:19 -0700 | [diff] [blame] | 1603 | { return -ENXIO; } |
Siddartha Mohanadoss | 55d0bca | 2013-06-24 08:29:34 -0700 | [diff] [blame] | 1604 | static inline int32_t qpnp_iadc_comp_result(struct qpnp_iadc_chip *iadc, |
| 1605 | int64_t *result, int32_t sign) |
Siddartha Mohanadoss | 4e64f8c | 2013-04-08 15:57:32 -0700 | [diff] [blame] | 1606 | { return -ENXIO; } |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 1607 | #endif |
| 1608 | |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1609 | /* Public API */ |
| 1610 | #if defined(CONFIG_THERMAL_QPNP_ADC_TM) \ |
| 1611 | || defined(CONFIG_THERMAL_QPNP_ADC_TM_MODULE) |
| 1612 | /** |
| 1613 | * qpnp_adc_tm_usbid_configure() - Configures Channel 0 of VADC_BTM to |
| 1614 | * monitor USB_ID channel using 100k internal pull-up. |
| 1615 | * USB driver passes the high/low voltage threshold along |
| 1616 | * with the notification callback once the set thresholds |
| 1617 | * are crossed. |
| 1618 | * @param: Structure pointer of qpnp_adc_tm_usbid_param type. |
| 1619 | * Clients pass the low/high voltage along with the threshold |
| 1620 | * notification callback. |
| 1621 | */ |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1622 | int32_t qpnp_adc_tm_usbid_configure(struct qpnp_adc_tm_chip *chip, |
| 1623 | struct qpnp_adc_tm_btm_param *param); |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1624 | /** |
| 1625 | * qpnp_adc_tm_usbid_end() - Disables the monitoring of channel 0 thats |
| 1626 | * assigned for monitoring USB_ID. Disables the low/high |
| 1627 | * threshold activation for channel 0 as well. |
| 1628 | * @param: none. |
| 1629 | */ |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1630 | int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip); |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1631 | /** |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1632 | * qpnp_adc_tm_channel_measure() - Configures kernel clients a channel to |
| 1633 | * monitor the corresponding ADC channel for threshold detection. |
| 1634 | * Driver passes the high/low voltage threshold along |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1635 | * with the notification callback once the set thresholds |
| 1636 | * are crossed. |
| 1637 | * @param: Structure pointer of qpnp_adc_tm_btm_param type. |
| 1638 | * Clients pass the low/high temperature along with the threshold |
| 1639 | * notification callback. |
| 1640 | */ |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1641 | int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip, |
| 1642 | struct qpnp_adc_tm_btm_param *param); |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1643 | /** |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1644 | * qpnp_adc_tm_disable_chan_meas() - Disables the monitoring of channel thats |
| 1645 | * assigned for monitoring kernel clients. Disables the low/high |
| 1646 | * threshold activation for the corresponding channel. |
| 1647 | * @param: Structure pointer of qpnp_adc_tm_btm_param type. |
| 1648 | * This is used to identify the channel for which the corresponding |
| 1649 | * channels high/low threshold notification will be disabled. |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1650 | */ |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1651 | int32_t qpnp_adc_tm_disable_chan_meas(struct qpnp_adc_tm_chip *chip, |
| 1652 | struct qpnp_adc_tm_btm_param *param); |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1653 | /** |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1654 | * qpnp_get_adc_tm() - Clients need to register with the adc_tm using the |
| 1655 | * corresponding device instance it wants to read the channels |
| 1656 | * from. Read the bindings document on how to pass the phandle |
| 1657 | * for the corresponding adc_tm driver to register with. |
| 1658 | * @name: Corresponding client's DT parser name. Read the DT bindings |
| 1659 | * document on how to register with the vadc |
| 1660 | * @struct qpnp_adc_tm_chip * - On success returns the vadc device structure |
| 1661 | * pointer that needs to be used during an ADC TM request. |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1662 | */ |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1663 | struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev, const char *name); |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1664 | #else |
| 1665 | static inline int32_t qpnp_adc_tm_usbid_configure( |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1666 | struct qpnp_adc_tm_chip *chip, |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1667 | struct qpnp_adc_tm_btm_param *param) |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1668 | { return -ENXIO; } |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1669 | static inline int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip) |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1670 | { return -ENXIO; } |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 1671 | static inline int32_t qpnp_adc_tm_channel_measure( |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1672 | struct qpnp_adc_tm_chip *chip, |
| 1673 | struct qpnp_adc_tm_btm_param *param) |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1674 | { return -ENXIO; } |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1675 | static inline int32_t qpnp_adc_tm_disable_chan_meas( |
| 1676 | struct qpnp_adc_tm_chip *chip) |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1677 | { return -ENXIO; } |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 1678 | static inline struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev, |
| 1679 | const char *name) |
| 1680 | { return ERR_PTR(-ENXIO); } |
Siddartha Mohanadoss | 31f6096 | 2012-11-27 14:11:02 -0800 | [diff] [blame] | 1681 | #endif |
| 1682 | |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1683 | #endif |