Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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, |
| 31 | SPARE2_03, |
| 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, |
| 84 | LR_MUX10_USB_ID, |
| 85 | AMUX_PU1, |
| 86 | AMUX_PU2, |
| 87 | LR_MUX3_BUF_XO_THERM_BUF, |
| 88 | LR_MUX1_PU1_BAT_THERM, |
| 89 | LR_MUX2_PU1_BAT_ID, |
| 90 | LR_MUX3_PU1_XO_THERM, |
| 91 | LR_MUX4_PU1_AMUX_THM1, |
| 92 | LR_MUX5_PU1_AMUX_THM2, |
| 93 | LR_MUX6_PU1_AMUX_THM3, |
| 94 | LR_MUX7_PU1_AMUX_HW_ID, |
| 95 | LR_MUX8_PU1_AMUX_THM4, |
| 96 | LR_MUX9_PU1_AMUX_THM5, |
| 97 | LR_MUX10_PU1_AMUX_USB_ID, |
| 98 | LR_MUX3_BUF_PU1_XO_THERM_BUF, |
| 99 | LR_MUX1_PU2_BAT_THERM, |
| 100 | LR_MUX2_PU2_BAT_ID, |
| 101 | LR_MUX3_PU2_XO_THERM, |
| 102 | LR_MUX4_PU2_AMUX_THM1, |
| 103 | LR_MUX5_PU2_AMUX_THM2, |
| 104 | LR_MUX6_PU2_AMUX_THM3, |
| 105 | LR_MUX7_PU2_AMUX_HW_ID, |
| 106 | LR_MUX8_PU2_AMUX_THM4, |
| 107 | LR_MUX9_PU2_AMUX_THM5, |
| 108 | LR_MUX10_PU2_AMUX_USB_ID, |
| 109 | LR_MUX3_BUF_PU2_XO_THERM_BUF, |
| 110 | LR_MUX1_PU1_PU2_BAT_THERM, |
| 111 | LR_MUX2_PU1_PU2_BAT_ID, |
| 112 | LR_MUX3_PU1_PU2_XO_THERM, |
| 113 | LR_MUX4_PU1_PU2_AMUX_THM1, |
| 114 | LR_MUX5_PU1_PU2_AMUX_THM2, |
| 115 | LR_MUX6_PU1_PU2_AMUX_THM3, |
| 116 | LR_MUX7_PU1_PU2_AMUX_HW_ID, |
| 117 | LR_MUX8_PU1_PU2_AMUX_THM4, |
| 118 | LR_MUX9_PU1_PU2_AMUX_THM5, |
| 119 | LR_MUX10_PU1_PU2_AMUX_USB_ID, |
| 120 | LR_MUX3_BUF_PU1_PU2_XO_THERM_BUF, |
| 121 | ALL_OFF, |
| 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, |
| 132 | GAIN_CALIBRATION_25MV, |
| 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 | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 140 | #define QPNP_ADC_HWMON_NAME_LENGTH 16 |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * enum qpnp_adc_decimation_type - Sampling rate supported. |
| 144 | * %DECIMATION_TYPE1: 512 |
| 145 | * %DECIMATION_TYPE2: 1K |
| 146 | * %DECIMATION_TYPE3: 2K |
| 147 | * %DECIMATION_TYPE4: 4k |
| 148 | * %DECIMATION_NONE: Do not use this Sampling type. |
| 149 | * |
| 150 | * The Sampling rate is specific to each channel of the QPNP ADC arbiter. |
| 151 | */ |
| 152 | enum qpnp_adc_decimation_type { |
| 153 | DECIMATION_TYPE1 = 0, |
| 154 | DECIMATION_TYPE2, |
| 155 | DECIMATION_TYPE3, |
| 156 | DECIMATION_TYPE4, |
| 157 | DECIMATION_NONE, |
| 158 | }; |
| 159 | |
| 160 | /** |
| 161 | * enum qpnp_adc_calib_type - QPNP ADC Calibration type. |
| 162 | * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels. |
| 163 | * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND. |
| 164 | * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type. |
| 165 | * |
| 166 | * Use the input reference voltage depending on the calibration type |
| 167 | * to calcluate the offset and gain parameters. The calibration is |
| 168 | * specific to each channel of the QPNP ADC. |
| 169 | */ |
| 170 | enum qpnp_adc_calib_type { |
| 171 | CALIB_ABSOLUTE = 0, |
| 172 | CALIB_RATIOMETRIC, |
| 173 | CALIB_NONE, |
| 174 | }; |
| 175 | |
| 176 | /** |
| 177 | * enum qpnp_adc_channel_scaling_param - pre-scaling AMUX ratio. |
| 178 | * %CHAN_PATH_SCALING1: ratio of {1, 1} |
| 179 | * %CHAN_PATH_SCALING2: ratio of {1, 3} |
| 180 | * %CHAN_PATH_SCALING3: ratio of {1, 4} |
| 181 | * %CHAN_PATH_SCALING4: ratio of {1, 6} |
| 182 | * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type. |
| 183 | * |
| 184 | * The pre-scaling is applied for signals to be within the voltage range |
| 185 | * of the ADC. |
| 186 | */ |
| 187 | enum qpnp_adc_channel_scaling_param { |
| 188 | PATH_SCALING1 = 0, |
| 189 | PATH_SCALING2, |
| 190 | PATH_SCALING3, |
| 191 | PATH_SCALING4, |
| 192 | PATH_SCALING_NONE, |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * enum qpnp_adc_scale_fn_type - Scaling function for pm8921 pre calibrated |
| 197 | * digital data relative to ADC reference. |
| 198 | * %ADC_SCALE_DEFAULT: Default scaling to convert raw adc code to voltage. |
| 199 | * %ADC_SCALE_BATT_THERM: Conversion to temperature based on btm parameters. |
| 200 | * %ADC_SCALE_PMIC_THERM: Returns result in milli degree's Centigrade. |
| 201 | * %ADC_SCALE_XTERN_CHGR_CUR: Returns current across 0.1 ohm resistor. |
| 202 | * %ADC_SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade. |
| 203 | * %ADC_SCALE_NONE: Do not use this scaling type. |
| 204 | */ |
| 205 | enum qpnp_adc_scale_fn_type { |
| 206 | SCALE_DEFAULT = 0, |
| 207 | SCALE_BATT_THERM, |
| 208 | SCALE_PA_THERM, |
| 209 | SCALE_PMIC_THERM, |
| 210 | SCALE_XOTHERM, |
| 211 | SCALE_NONE, |
| 212 | }; |
| 213 | |
| 214 | /** |
| 215 | * enum qpnp_adc_fast_avg_ctl - Provides ability to obtain single result |
| 216 | * from the ADC that is an average of multiple measurement |
| 217 | * samples. Select number of samples for use in fast |
| 218 | * average mode (i.e. 2 ^ value). |
| 219 | * %ADC_FAST_AVG_SAMPLE_1: 0x0 = 1 |
| 220 | * %ADC_FAST_AVG_SAMPLE_2: 0x1 = 2 |
| 221 | * %ADC_FAST_AVG_SAMPLE_4: 0x2 = 4 |
| 222 | * %ADC_FAST_AVG_SAMPLE_8: 0x3 = 8 |
| 223 | * %ADC_FAST_AVG_SAMPLE_16: 0x4 = 16 |
| 224 | * %ADC_FAST_AVG_SAMPLE_32: 0x5 = 32 |
| 225 | * %ADC_FAST_AVG_SAMPLE_64: 0x6 = 64 |
| 226 | * %ADC_FAST_AVG_SAMPLE_128: 0x7 = 128 |
| 227 | * %ADC_FAST_AVG_SAMPLE_256: 0x8 = 256 |
| 228 | * %ADC_FAST_AVG_SAMPLE_512: 0x9 = 512 |
| 229 | */ |
| 230 | enum qpnp_adc_fast_avg_ctl { |
| 231 | ADC_FAST_AVG_SAMPLE_1 = 0, |
| 232 | ADC_FAST_AVG_SAMPLE_2, |
| 233 | ADC_FAST_AVG_SAMPLE_4, |
| 234 | ADC_FAST_AVG_SAMPLE_8, |
| 235 | ADC_FAST_AVG_SAMPLE_16, |
| 236 | ADC_FAST_AVG_SAMPLE_32, |
| 237 | ADC_FAST_AVG_SAMPLE_64, |
| 238 | ADC_FAST_AVG_SAMPLE_128, |
| 239 | ADC_FAST_AVG_SAMPLE_256, |
| 240 | ADC_FAST_AVG_SAMPLE_512, |
| 241 | ADC_FAST_AVG_SAMPLE_NONE, |
| 242 | }; |
| 243 | |
| 244 | /** |
| 245 | * enum qpnp_adc_hw_settle_time - Time between AMUX getting configured and |
| 246 | * the ADC starting conversion. Delay = 100us * value for |
| 247 | * value < 11 and 2ms * (value - 10) otherwise. |
| 248 | * %ADC_CHANNEL_HW_SETTLE_DELAY_0US: 0us |
| 249 | * %ADC_CHANNEL_HW_SETTLE_DELAY_100US: 100us |
| 250 | * %ADC_CHANNEL_HW_SETTLE_DELAY_200US: 200us |
| 251 | * %ADC_CHANNEL_HW_SETTLE_DELAY_300US: 300us |
| 252 | * %ADC_CHANNEL_HW_SETTLE_DELAY_400US: 400us |
| 253 | * %ADC_CHANNEL_HW_SETTLE_DELAY_500US: 500us |
| 254 | * %ADC_CHANNEL_HW_SETTLE_DELAY_600US: 600us |
| 255 | * %ADC_CHANNEL_HW_SETTLE_DELAY_700US: 700us |
| 256 | * %ADC_CHANNEL_HW_SETTLE_DELAY_800US: 800us |
| 257 | * %ADC_CHANNEL_HW_SETTLE_DELAY_900US: 900us |
| 258 | * %ADC_CHANNEL_HW_SETTLE_DELAY_1MS: 1ms |
| 259 | * %ADC_CHANNEL_HW_SETTLE_DELAY_2MS: 2ms |
| 260 | * %ADC_CHANNEL_HW_SETTLE_DELAY_4MS: 4ms |
| 261 | * %ADC_CHANNEL_HW_SETTLE_DELAY_6MS: 6ms |
| 262 | * %ADC_CHANNEL_HW_SETTLE_DELAY_8MS: 8ms |
| 263 | * %ADC_CHANNEL_HW_SETTLE_DELAY_10MS: 10ms |
| 264 | * %ADC_CHANNEL_HW_SETTLE_NONE |
| 265 | */ |
| 266 | enum qpnp_adc_hw_settle_time { |
| 267 | ADC_CHANNEL_HW_SETTLE_DELAY_0US = 0, |
| 268 | ADC_CHANNEL_HW_SETTLE_DELAY_100US, |
| 269 | ADC_CHANNEL_HW_SETTLE_DELAY_2000US, |
| 270 | ADC_CHANNEL_HW_SETTLE_DELAY_300US, |
| 271 | ADC_CHANNEL_HW_SETTLE_DELAY_400US, |
| 272 | ADC_CHANNEL_HW_SETTLE_DELAY_500US, |
| 273 | ADC_CHANNEL_HW_SETTLE_DELAY_600US, |
| 274 | ADC_CHANNEL_HW_SETTLE_DELAY_700US, |
| 275 | ADC_CHANNEL_HW_SETTLE_DELAY_800US, |
| 276 | ADC_CHANNEL_HW_SETTLE_DELAY_900US, |
| 277 | ADC_CHANNEL_HW_SETTLE_DELAY_1MS, |
| 278 | ADC_CHANNEL_HW_SETTLE_DELAY_2MS, |
| 279 | ADC_CHANNEL_HW_SETTLE_DELAY_4MS, |
| 280 | ADC_CHANNEL_HW_SETTLE_DELAY_6MS, |
| 281 | ADC_CHANNEL_HW_SETTLE_DELAY_8MS, |
| 282 | ADC_CHANNEL_HW_SETTLE_DELAY_10MS, |
| 283 | ADC_CHANNEL_HW_SETTLE_NONE, |
| 284 | }; |
| 285 | |
| 286 | /** |
| 287 | * enum qpnp_vadc_mode_sel - Selects the basic mode of operation. |
| 288 | * - The normal mode is used for single measurement. |
| 289 | * - The Conversion sequencer is used to trigger an |
| 290 | * ADC read when a HW trigger is selected. |
| 291 | * - The measurement interval performs a single or |
| 292 | * continous measurement at a specified interval/delay. |
| 293 | * %ADC_OP_NORMAL_MODE : Normal mode used for single measurement. |
| 294 | * %ADC_OP_CONVERSION_SEQUENCER : Conversion sequencer used to trigger |
| 295 | * an ADC read on a HW supported trigger. |
| 296 | * Refer to enum qpnp_vadc_trigger for |
| 297 | * supported HW triggers. |
| 298 | * %ADC_OP_MEASUREMENT_INTERVAL : The measurement interval performs a |
| 299 | * single or continous measurement after a specified delay. |
| 300 | * For delay look at qpnp_adc_meas_timer. |
| 301 | */ |
| 302 | enum qpnp_vadc_mode_sel { |
| 303 | ADC_OP_NORMAL_MODE = 0, |
| 304 | ADC_OP_CONVERSION_SEQUENCER, |
| 305 | ADC_OP_MEASUREMENT_INTERVAL, |
| 306 | ADC_OP_MODE_NONE, |
| 307 | }; |
| 308 | |
| 309 | /** |
| 310 | * enum qpnp_vadc_trigger - Select the HW trigger to be used while |
| 311 | * measuring the ADC reading. |
| 312 | * %ADC_GSM_PA_ON : GSM power amplifier on. |
| 313 | * %ADC_TX_GTR_THRES : Transmit power greater than threshold. |
| 314 | * %ADC_CAMERA_FLASH_RAMP : Flash ramp up done. |
| 315 | * %ADC_DTEST : DTEST. |
| 316 | */ |
| 317 | enum qpnp_vadc_trigger { |
| 318 | ADC_GSM_PA_ON = 0, |
| 319 | ADC_TX_GTR_THRES, |
| 320 | ADC_CAMERA_FLASH_RAMP, |
| 321 | ADC_DTEST, |
| 322 | ADC_SEQ_NONE, |
| 323 | }; |
| 324 | |
| 325 | /** |
| 326 | * enum qpnp_vadc_conv_seq_timeout - Select delay (0 to 15ms) from |
| 327 | * conversion request to triggering conversion sequencer |
| 328 | * hold off time. |
| 329 | */ |
| 330 | enum qpnp_vadc_conv_seq_timeout { |
| 331 | ADC_CONV_SEQ_TIMEOUT_0MS = 0, |
| 332 | ADC_CONV_SEQ_TIMEOUT_1MS, |
| 333 | ADC_CONV_SEQ_TIMEOUT_2MS, |
| 334 | ADC_CONV_SEQ_TIMEOUT_3MS, |
| 335 | ADC_CONV_SEQ_TIMEOUT_4MS, |
| 336 | ADC_CONV_SEQ_TIMEOUT_5MS, |
| 337 | ADC_CONV_SEQ_TIMEOUT_6MS, |
| 338 | ADC_CONV_SEQ_TIMEOUT_7MS, |
| 339 | ADC_CONV_SEQ_TIMEOUT_8MS, |
| 340 | ADC_CONV_SEQ_TIMEOUT_9MS, |
| 341 | ADC_CONV_SEQ_TIMEOUT_10MS, |
| 342 | ADC_CONV_SEQ_TIMEOUT_11MS, |
| 343 | ADC_CONV_SEQ_TIMEOUT_12MS, |
| 344 | ADC_CONV_SEQ_TIMEOUT_13MS, |
| 345 | ADC_CONV_SEQ_TIMEOUT_14MS, |
| 346 | ADC_CONV_SEQ_TIMEOUT_15MS, |
| 347 | ADC_CONV_SEQ_TIMEOUT_NONE, |
| 348 | }; |
| 349 | |
| 350 | /** |
| 351 | * enum qpnp_adc_conv_seq_holdoff - Select delay from conversion |
| 352 | * trigger signal (i.e. adc_conv_seq_trig) transition |
| 353 | * to ADC enable. Delay = 25us * (value + 1). |
| 354 | */ |
| 355 | enum qpnp_adc_conv_seq_holdoff { |
| 356 | ADC_SEQ_HOLD_25US = 0, |
| 357 | ADC_SEQ_HOLD_50US, |
| 358 | ADC_SEQ_HOLD_75US, |
| 359 | ADC_SEQ_HOLD_100US, |
| 360 | ADC_SEQ_HOLD_125US, |
| 361 | ADC_SEQ_HOLD_150US, |
| 362 | ADC_SEQ_HOLD_175US, |
| 363 | ADC_SEQ_HOLD_200US, |
| 364 | ADC_SEQ_HOLD_225US, |
| 365 | ADC_SEQ_HOLD_250US, |
| 366 | ADC_SEQ_HOLD_275US, |
| 367 | ADC_SEQ_HOLD_300US, |
| 368 | ADC_SEQ_HOLD_325US, |
| 369 | ADC_SEQ_HOLD_350US, |
| 370 | ADC_SEQ_HOLD_375US, |
| 371 | ADC_SEQ_HOLD_400US, |
| 372 | ADC_SEQ_HOLD_NONE, |
| 373 | }; |
| 374 | |
| 375 | /** |
| 376 | * enum qpnp_adc_conv_seq_state - Conversion sequencer operating state |
| 377 | * %ADC_CONV_SEQ_IDLE : Sequencer is in idle. |
| 378 | * %ADC_CONV_TRIG_RISE : Waiting for rising edge trigger. |
| 379 | * %ADC_CONV_TRIG_HOLDOFF : Waiting for rising trigger hold off time. |
| 380 | * %ADC_CONV_MEAS_RISE : Measuring selected ADC signal. |
| 381 | * %ADC_CONV_TRIG_FALL : Waiting for falling trigger edge. |
| 382 | * %ADC_CONV_FALL_HOLDOFF : Waiting for falling trigger hold off time. |
| 383 | * %ADC_CONV_MEAS_FALL : Measuring selected ADC signal. |
| 384 | * %ADC_CONV_ERROR : Aberrant Hardware problem. |
| 385 | */ |
| 386 | enum qpnp_adc_conv_seq_state { |
| 387 | ADC_CONV_SEQ_IDLE = 0, |
| 388 | ADC_CONV_TRIG_RISE, |
| 389 | ADC_CONV_TRIG_HOLDOFF, |
| 390 | ADC_CONV_MEAS_RISE, |
| 391 | ADC_CONV_TRIG_FALL, |
| 392 | ADC_CONV_FALL_HOLDOFF, |
| 393 | ADC_CONV_MEAS_FALL, |
| 394 | ADC_CONV_ERROR, |
| 395 | ADC_CONV_NONE, |
| 396 | }; |
| 397 | |
| 398 | /** |
| 399 | * enum qpnp_adc_meas_timer - Selects the measurement interval time. |
| 400 | * If value = 0, use 0ms else use 2^(value + 4)/ 32768). |
| 401 | * %ADC_MEAS_INTERVAL_0MS : 0ms |
| 402 | * %ADC_MEAS_INTERVAL_1P0MS : 1ms |
| 403 | * %ADC_MEAS_INTERVAL_2P0MS : 2ms |
| 404 | * %ADC_MEAS_INTERVAL_3P9MS : 3.9ms |
| 405 | * %ADC_MEAS_INTERVAL_7P8MS : 7.8ms |
| 406 | * %ADC_MEAS_INTERVAL_15P6MS : 15.6ms |
| 407 | * %ADC_MEAS_INTERVAL_31P3MS : 31.3ms |
| 408 | * %ADC_MEAS_INTERVAL_62P5MS : 62.5ms |
| 409 | * %ADC_MEAS_INTERVAL_125MS : 125ms |
| 410 | * %ADC_MEAS_INTERVAL_250MS : 250ms |
| 411 | * %ADC_MEAS_INTERVAL_500MS : 500ms |
| 412 | * %ADC_MEAS_INTERVAL_1S : 1seconds |
| 413 | * %ADC_MEAS_INTERVAL_2S : 2seconds |
| 414 | * %ADC_MEAS_INTERVAL_4S : 4seconds |
| 415 | * %ADC_MEAS_INTERVAL_8S : 8seconds |
| 416 | * %ADC_MEAS_INTERVAL_16S: 16seconds |
| 417 | */ |
| 418 | enum qpnp_adc_meas_timer { |
| 419 | ADC_MEAS_INTERVAL_0MS = 0, |
| 420 | ADC_MEAS_INTERVAL_1P0MS, |
| 421 | ADC_MEAS_INTERVAL_2P0MS, |
| 422 | ADC_MEAS_INTERVAL_3P9MS, |
| 423 | ADC_MEAS_INTERVAL_7P8MS, |
| 424 | ADC_MEAS_INTERVAL_15P6MS, |
| 425 | ADC_MEAS_INTERVAL_31P3MS, |
| 426 | ADC_MEAS_INTERVAL_62P5MS, |
| 427 | ADC_MEAS_INTERVAL_125MS, |
| 428 | ADC_MEAS_INTERVAL_250MS, |
| 429 | ADC_MEAS_INTERVAL_500MS, |
| 430 | ADC_MEAS_INTERVAL_1S, |
| 431 | ADC_MEAS_INTERVAL_2S, |
| 432 | ADC_MEAS_INTERVAL_4S, |
| 433 | ADC_MEAS_INTERVAL_8S, |
| 434 | ADC_MEAS_INTERVAL_16S, |
| 435 | ADC_MEAS_INTERVAL_NONE, |
| 436 | }; |
| 437 | |
| 438 | /** |
| 439 | * enum qpnp_adc_meas_interval_op_ctl - Select operating mode. |
| 440 | * %ADC_MEAS_INTERVAL_OP_SINGLE : Conduct single measurement at specified time |
| 441 | * delay. |
| 442 | * %ADC_MEAS_INTERVAL_OP_CONTINUOUS : Make measurements at measurement interval |
| 443 | * times. |
| 444 | */ |
| 445 | enum qpnp_adc_meas_interval_op_ctl { |
| 446 | ADC_MEAS_INTERVAL_OP_SINGLE = 0, |
| 447 | ADC_MEAS_INTERVAL_OP_CONTINUOUS, |
| 448 | ADC_MEAS_INTERVAL_OP_NONE, |
| 449 | }; |
| 450 | |
| 451 | /** |
| 452 | * struct qpnp_vadc_linear_graph - Represent ADC characteristics. |
| 453 | * @dy: Numerator slope to calculate the gain. |
| 454 | * @dx: Denominator slope to calculate the gain. |
| 455 | * @adc_vref: A/D word of the voltage reference used for the channel. |
| 456 | * @adc_gnd: A/D word of the ground reference used for the channel. |
| 457 | * |
| 458 | * Each ADC device has different offset and gain parameters which are computed |
| 459 | * to calibrate the device. |
| 460 | */ |
| 461 | struct qpnp_vadc_linear_graph { |
| 462 | int64_t dy; |
| 463 | int64_t dx; |
| 464 | int64_t adc_vref; |
| 465 | int64_t adc_gnd; |
| 466 | }; |
| 467 | |
| 468 | /** |
| 469 | * struct qpnp_vadc_map_pt - Map the graph representation for ADC channel |
| 470 | * @x: Represent the ADC digitized code. |
| 471 | * @y: Represent the physical data which can be temperature, voltage, |
| 472 | * resistance. |
| 473 | */ |
| 474 | struct qpnp_vadc_map_pt { |
| 475 | int32_t x; |
| 476 | int32_t y; |
| 477 | }; |
| 478 | |
| 479 | /** |
| 480 | * struct qpnp_vadc_scaling_ratio - Represent scaling ratio for adc input. |
| 481 | * @num: Numerator scaling parameter. |
| 482 | * @den: Denominator scaling parameter. |
| 483 | */ |
| 484 | struct qpnp_vadc_scaling_ratio { |
| 485 | int32_t num; |
| 486 | int32_t den; |
| 487 | }; |
| 488 | |
| 489 | /** |
| 490 | * struct qpnp_adc_properties - Represent the ADC properties. |
| 491 | * @adc_reference: Reference voltage for QPNP ADC. |
| 492 | * @bitresolution: ADC bit resolution for QPNP ADC. |
| 493 | * @biploar: Polarity for QPNP ADC. |
| 494 | */ |
| 495 | struct qpnp_adc_properties { |
| 496 | uint32_t adc_vdd_reference; |
| 497 | uint32_t bitresolution; |
| 498 | bool bipolar; |
| 499 | }; |
| 500 | |
| 501 | /** |
| 502 | * struct qpnp_vadc_chan_properties - Represent channel properties of the ADC. |
| 503 | * @offset_gain_numerator: The inverse numerator of the gain applied to the |
| 504 | * input channel. |
| 505 | * @offset_gain_denominator: The inverse denominator of the gain applied to the |
| 506 | * input channel. |
| 507 | * @adc_graph: ADC graph for the channel of struct type qpnp_adc_linear_graph. |
| 508 | */ |
| 509 | struct qpnp_vadc_chan_properties { |
| 510 | uint32_t offset_gain_numerator; |
| 511 | uint32_t offset_gain_denominator; |
| 512 | struct qpnp_vadc_linear_graph adc_graph[2]; |
| 513 | }; |
| 514 | |
| 515 | /** |
| 516 | * struct qpnp_adc_result - Represent the result of the QPNP ADC. |
| 517 | * @chan: The channel number of the requested conversion. |
| 518 | * @adc_code: The pre-calibrated digital output of a given ADC relative to the |
| 519 | * the ADC reference. |
| 520 | * @measurement: In units specific for a given ADC; most ADC uses reference |
| 521 | * voltage but some ADC uses reference current. This measurement |
| 522 | * here is a number relative to a reference of a given ADC. |
| 523 | * @physical: The data meaningful for each individual channel whether it is |
| 524 | * voltage, current, temperature, etc. |
| 525 | * All voltage units are represented in micro - volts. |
| 526 | * -Battery temperature units are represented as 0.1 DegC. |
| 527 | * -PA Therm temperature units are represented as DegC. |
| 528 | * -PMIC Die temperature units are represented as 0.001 DegC. |
| 529 | */ |
| 530 | struct qpnp_vadc_result { |
| 531 | uint32_t chan; |
| 532 | int32_t adc_code; |
| 533 | int64_t measurement; |
| 534 | int64_t physical; |
| 535 | }; |
| 536 | |
| 537 | /** |
| 538 | * struct qpnp_adc_amux - AMUX properties for individual channel |
| 539 | * @name: Channel string name. |
| 540 | * @channel_num: Channel in integer used from qpnp_adc_channels. |
| 541 | * @chan_path_prescaling: Channel scaling performed on the input signal. |
| 542 | * @adc_decimation: Sampling rate desired for the channel. |
| 543 | * adc_scale_fn: Scaling function to convert to the data meaningful for |
| 544 | * each individual channel whether it is voltage, current, |
| 545 | * temperature, etc and compensates the channel properties. |
| 546 | */ |
| 547 | struct qpnp_vadc_amux { |
| 548 | char *name; |
| 549 | enum qpnp_vadc_channels channel_num; |
| 550 | enum qpnp_adc_channel_scaling_param chan_path_prescaling; |
| 551 | enum qpnp_adc_decimation_type adc_decimation; |
| 552 | enum qpnp_adc_scale_fn_type adc_scale_fn; |
| 553 | enum qpnp_adc_fast_avg_ctl fast_avg_setup; |
| 554 | enum qpnp_adc_hw_settle_time hw_settle_time; |
| 555 | }; |
| 556 | |
| 557 | /** |
| 558 | * struct qpnp_vadc_scaling_ratio |
| 559 | * |
| 560 | */ |
| 561 | static const struct qpnp_vadc_scaling_ratio qpnp_vadc_amux_scaling_ratio[] = { |
| 562 | {1, 1}, |
| 563 | {1, 3}, |
| 564 | {1, 4}, |
| 565 | {1, 6}, |
| 566 | {1, 20} |
| 567 | }; |
| 568 | |
| 569 | /** |
| 570 | * struct qpnp_vadc_scale_fn - Scaling function prototype |
| 571 | * @chan: Function pointer to one of the scaling functions |
| 572 | * which takes the adc properties, channel properties, |
| 573 | * and returns the physical result |
| 574 | */ |
| 575 | struct qpnp_vadc_scale_fn { |
| 576 | int32_t (*chan) (int32_t, |
| 577 | const struct qpnp_adc_properties *, |
| 578 | const struct qpnp_vadc_chan_properties *, |
| 579 | struct qpnp_vadc_result *); |
| 580 | }; |
| 581 | |
| 582 | /** |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 583 | * struct qpnp_iadc_calib - IADC channel calibration structure. |
| 584 | * @channel - Channel for which the historical offset and gain is |
| 585 | * calculated. Available channels are internal rsense, |
| 586 | * external rsense and alternate lead pairs. |
| 587 | * @offset - Offset value for the channel. |
| 588 | * @gain - Gain of the channel. |
| 589 | */ |
| 590 | struct qpnp_iadc_calib { |
| 591 | enum qpnp_iadc_channels channel; |
| 592 | int32_t offset; |
| 593 | int32_t gain; |
| 594 | }; |
| 595 | |
| 596 | /** |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 597 | * struct qpnp_adc_drv - QPNP ADC device structure. |
| 598 | * @spmi - spmi device for ADC peripheral. |
| 599 | * @offset - base offset for the ADC peripheral. |
| 600 | * @adc_prop - ADC properties specific to the ADC peripheral. |
| 601 | * @amux_prop - AMUX properties representing the ADC peripheral. |
| 602 | * @adc_channels - ADC channel properties for the ADC peripheral. |
| 603 | * @adc_irq - IRQ number that is mapped to the ADC peripheral. |
| 604 | * @adc_lock - ADC lock for access to the peripheral. |
| 605 | * @adc_rslt_completion - ADC result notification after interrupt |
| 606 | * is received. |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 607 | * @calib - Internal rsens calibration values for gain and offset. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 608 | */ |
| 609 | struct qpnp_adc_drv { |
| 610 | struct spmi_device *spmi; |
| 611 | uint8_t slave; |
| 612 | uint16_t offset; |
| 613 | struct qpnp_adc_properties *adc_prop; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 614 | struct qpnp_adc_amux_properties *amux_prop; |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 615 | struct qpnp_vadc_amux *adc_channels; |
| 616 | int adc_irq; |
| 617 | struct mutex adc_lock; |
| 618 | struct completion adc_rslt_completion; |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 619 | struct qpnp_iadc_calib calib; |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 620 | }; |
| 621 | |
| 622 | /** |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 623 | * struct qpnp_adc_amux_properties - QPNP VADC amux channel property. |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 624 | * @amux_channel - Refer to the qpnp_vadc_channel list. |
| 625 | * @decimation - Sampling rate supported for the channel. |
| 626 | * @mode_sel - The basic mode of operation. |
| 627 | * @hw_settle_time - The time between AMUX being configured and the |
| 628 | * start of conversion. |
| 629 | * @fast_avg_setup - Ability to provide single result from the ADC |
| 630 | * that is an average of multiple measurements. |
| 631 | * @trigger_channel - HW trigger channel for conversion sequencer. |
| 632 | * @chan_prop - Represent the channel properties of the ADC. |
| 633 | */ |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 634 | struct qpnp_adc_amux_properties { |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 635 | uint32_t amux_channel; |
| 636 | uint32_t decimation; |
| 637 | uint32_t mode_sel; |
| 638 | uint32_t hw_settle_time; |
| 639 | uint32_t fast_avg_setup; |
| 640 | enum qpnp_vadc_trigger trigger_channel; |
| 641 | struct qpnp_vadc_chan_properties chan_prop[0]; |
| 642 | }; |
| 643 | |
| 644 | /* Public API */ |
| 645 | #if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \ |
| 646 | || defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE_MODULE) |
| 647 | /** |
| 648 | * qpnp_vadc_read() - Performs ADC read on the channel. |
| 649 | * @channel: Input channel to perform the ADC read. |
| 650 | * @result: Structure pointer of type adc_chan_result |
| 651 | * in which the ADC read results are stored. |
| 652 | */ |
| 653 | int32_t qpnp_vadc_read(enum qpnp_vadc_channels channel, |
| 654 | struct qpnp_vadc_result *result); |
| 655 | |
| 656 | /** |
| 657 | * qpnp_vadc_conv_seq_request() - Performs ADC read on the conversion |
| 658 | * sequencer channel. |
| 659 | * @channel: Input channel to perform the ADC read. |
| 660 | * @result: Structure pointer of type adc_chan_result |
| 661 | * in which the ADC read results are stored. |
| 662 | */ |
| 663 | int32_t qpnp_vadc_conv_seq_request( |
| 664 | enum qpnp_vadc_trigger trigger_channel, |
| 665 | enum qpnp_vadc_channels channel, |
| 666 | struct qpnp_vadc_result *result); |
| 667 | |
| 668 | /** |
| 669 | * qpnp_vadc_check_result() - Performs check on the ADC raw code. |
| 670 | * @data: Data used for verifying the range of the ADC code. |
| 671 | */ |
| 672 | int32_t qpnp_vadc_check_result(int32_t *data); |
| 673 | |
| 674 | /** |
| 675 | * qpnp_adc_get_devicetree_data() - Abstracts the ADC devicetree data. |
| 676 | * @spmi: spmi ADC device. |
| 677 | * @adc_qpnp: spmi device tree node structure |
| 678 | */ |
| 679 | int32_t qpnp_adc_get_devicetree_data(struct spmi_device *spmi, |
| 680 | struct qpnp_adc_drv *adc_qpnp); |
| 681 | |
| 682 | /** |
| 683 | * qpnp_vadc_configure() - Configure ADC device to start conversion. |
| 684 | * @chan_prop: Individual channel properties for the AMUX channel. |
| 685 | */ |
| 686 | int32_t qpnp_vadc_configure( |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 687 | struct qpnp_adc_amux_properties *chan_prop); |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 688 | |
| 689 | /** |
| 690 | * qpnp_adc_scale_default() - Scales the pre-calibrated digital output |
| 691 | * of an ADC to the ADC reference and compensates for the |
| 692 | * gain and offset. |
| 693 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 694 | * @adc_prop: adc properties of the qpnp adc such as bit resolution, |
| 695 | * reference voltage. |
| 696 | * @chan_prop: Individual channel properties to compensate the i/p scaling, |
| 697 | * slope and offset. |
| 698 | * @chan_rslt: Physical result to be stored. |
| 699 | */ |
| 700 | int32_t qpnp_adc_scale_default(int32_t adc_code, |
| 701 | const struct qpnp_adc_properties *adc_prop, |
| 702 | const struct qpnp_vadc_chan_properties *chan_prop, |
| 703 | struct qpnp_vadc_result *chan_rslt); |
| 704 | #else |
| 705 | static inline int32_t qpnp_vadc_read(uint32_t channel, |
| 706 | struct qpnp_vadc_result *result) |
| 707 | { return -ENXIO; } |
| 708 | static inline int32_t qpnp_vadc_conv_seq_request( |
| 709 | enum qpnp_vadc_trigger trigger_channel, |
| 710 | enum qpnp_vadc_channels channel, |
| 711 | struct qpnp_vadc_result *result) |
| 712 | { return -ENXIO; } |
| 713 | static inline int32_t qpnp_adc_scale_default(int32_t adc_code, |
| 714 | const struct qpnp_adc_properties *adc_prop, |
| 715 | const struct qpnp_adc_chan_properties *chan_prop, |
| 716 | struct qpnp_adc_chan_result *chan_rslt) |
| 717 | { return -ENXIO; } |
| 718 | #endif |
| 719 | |
Siddartha Mohanadoss | c4a6af1 | 2012-07-13 18:50:12 -0700 | [diff] [blame] | 720 | /* Public API */ |
| 721 | #if defined(CONFIG_SENSORS_QPNP_ADC_CURRENT) \ |
| 722 | || defined(CONFIG_SENSORS_QPNP_ADC_CURRENT_MODULE) |
| 723 | /** |
| 724 | * qpnp_iadc_read() - Performs ADC read on the current channel. |
| 725 | * @channel: Input channel to perform the ADC read. |
| 726 | * @result: Current across rsens in mV. |
| 727 | */ |
| 728 | int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel, |
| 729 | int32_t *result); |
| 730 | /** |
| 731 | * qpnp_iadc_get_gain() - Performs gain calibration over 25mV reference |
| 732 | * across CCADC. |
| 733 | * @result: Gain result across 25mV reference. |
| 734 | */ |
| 735 | int32_t qpnp_iadc_get_gain(int32_t *result); |
| 736 | |
| 737 | /** |
| 738 | * qpnp_iadc_get_offset() - Performs offset calibration over selected |
| 739 | * channel. Channel can be internal rsense, |
| 740 | * external rsense and alternate lead pair. |
| 741 | * @result: Gain result across 25mV reference. |
| 742 | */ |
| 743 | int32_t qpnp_iadc_get_offset(enum qpnp_iadc_channels channel, |
| 744 | int32_t *result); |
| 745 | #else |
| 746 | static inline int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel, |
| 747 | int *result) |
| 748 | { return -ENXIO; } |
| 749 | static inline int32_t qpnp_iadc_get_gain(int32_t *result) |
| 750 | { return -ENXIO; } |
| 751 | static inline int32_t qpnp_iadc_get_offset(enum qpnp_iadc_channels channel, |
| 752 | int32_t *result) |
| 753 | { return -ENXIO; } |
| 754 | #endif |
| 755 | |
Siddartha Mohanadoss | 7b116e1 | 2012-06-05 23:27:46 -0700 | [diff] [blame] | 756 | #endif |