Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011, 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 8921 ADC driver header file |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #ifndef __MFD_PM8921_ADC_H |
| 19 | #define __MFD_PM8921_ADC_H |
| 20 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/list.h> |
| 23 | |
| 24 | /** |
| 25 | * enum pm8921_adc_channels - PM8921 AMUX arbiter channels |
| 26 | * %CHANNEL_VCOIN: Backup voltage for certain register set |
| 27 | * %CHANNEL_VBAT: Battery voltage |
| 28 | * %CHANNEL_DCIN: Charger input voltage without internal OVP |
| 29 | * %CHANNEL_ICHG: Charge-current monitor |
| 30 | * %CHANNEL_VPH_PWR: Main system power |
| 31 | * %CHANNEL_IBAT: Battery charge current |
| 32 | * %CHANNEL_MPP_1: 16:1 pre-mux unity scale MPP input |
| 33 | * %CHANNEL_MPP_2: 16:1 pre-mux 1/3 scale MPP input |
| 34 | * %CHANNEL_BATT_THERM: Battery temperature |
| 35 | * %CHANNEL_BATT_ID: Battery detection |
| 36 | * %CHANNEL_USBIN: Charger input voltage with internal OVP |
| 37 | * %CHANNEL_DIE_TEMP: Pmic_die temperature |
| 38 | * %CHANNEL_625MV: 625mv reference channel |
| 39 | * %CHANNEL_125V: 1.25v reference channel |
| 40 | * %CHANNEL_CHG_TEMP: Charger temperature |
| 41 | * %CHANNEL_MUXOFF: Channel to reduce input load on the mux |
| 42 | * %CHANNEL_NONE: Do not use this channel |
| 43 | */ |
| 44 | enum pm8921_adc_channels { |
| 45 | CHANNEL_VCOIN = 0, |
| 46 | CHANNEL_VBAT, |
| 47 | CHANNEL_DCIN, |
| 48 | CHANNEL_ICHG, |
| 49 | CHANNEL_VPH_PWR, |
| 50 | CHANNEL_IBAT, |
| 51 | CHANNEL_MPP_1, |
| 52 | CHANNEL_MPP_2, |
| 53 | CHANNEL_BATT_THERM, |
| 54 | CHANNEL_BATT_ID, |
| 55 | CHANNEL_USBIN, |
| 56 | CHANNEL_DIE_TEMP, |
| 57 | CHANNEL_625MV, |
| 58 | CHANNEL_125V, |
| 59 | CHANNEL_CHG_TEMP, |
| 60 | CHANNEL_MUXOFF, |
| 61 | CHANNEL_NONE, |
| 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * enum pm8921_adc_mpp_channels - PM8921 AMUX arbiter MPP channels |
| 66 | * Yet to be defined, each of the value is representative |
| 67 | * of the device connected to the MPP |
| 68 | * %ADC_MPP_AMUX8: Fixed mappaing to PA THERM |
| 69 | */ |
| 70 | enum pm8921_adc_mpp_channels { |
| 71 | ADC_MPP_ATEST_8 = 0, |
| 72 | ADC_MPP_USB_SNS_DIV20, |
| 73 | ADC_MPP_DCIN_SNS_DIV20, |
| 74 | ADC_MPP_AMUX3, |
| 75 | ADC_MPP_AMUX4, |
| 76 | ADC_MPP_AMUX5, |
| 77 | ADC_MPP_AMUX6, |
| 78 | ADC_MPP_AMUX7, |
| 79 | ADC_MPP_AMUX8, |
| 80 | ADC_MPP_ATEST_1, |
| 81 | ADC_MPP_ATEST_2, |
| 82 | ADC_MPP_ATEST_3, |
| 83 | ADC_MPP_ATEST_4, |
| 84 | ADC_MPP_ATEST_5, |
| 85 | ADC_MPP_ATEST_6, |
| 86 | ADC_MPP_ATEST_7, |
| 87 | ADC_MPP_CHANNEL_NONE, |
| 88 | }; |
| 89 | |
| 90 | #define PM8921_ADC_PMIC_0 0x0 |
| 91 | |
| 92 | #define PM8921_CHANNEL_ADC_625_MV 625 |
| 93 | |
| 94 | #define PM8921_AMUX_MPP_3 0x3 |
| 95 | #define PM8921_AMUX_MPP_4 0x4 |
| 96 | #define PM8921_AMUX_MPP_5 0x5 |
| 97 | #define PM8921_AMUX_MPP_6 0x6 |
| 98 | #define PM8921_AMUX_MPP_8 0x8 |
| 99 | |
| 100 | #define PM8921_ADC_DEV_NAME "pm8921-adc" |
| 101 | |
| 102 | /** |
| 103 | * enum pm8921_adc_decimation_type - Sampling rate supported |
| 104 | * %ADC_DECIMATION_TYPE1: 512 |
| 105 | * %ADC_DECIMATION_TYPE2: 1K |
| 106 | * %ADC_DECIMATION_TYPE3: 2K |
| 107 | * %ADC_DECIMATION_TYPE4: 4k |
| 108 | * %ADC_DECIMATION_NONE: Do not use this Sampling type |
| 109 | * |
| 110 | * The Sampling rate is specific to each channel of the PM8921 ADC arbiter. |
| 111 | */ |
| 112 | enum pm8921_adc_decimation_type { |
| 113 | ADC_DECIMATION_TYPE1 = 0, |
| 114 | ADC_DECIMATION_TYPE2, |
| 115 | ADC_DECIMATION_TYPE3, |
| 116 | ADC_DECIMATION_TYPE4, |
| 117 | ADC_DECIMATION_NONE, |
| 118 | }; |
| 119 | |
| 120 | /** |
| 121 | * enum pm8921_adc_calib_type - PM8921 ADC Calibration type |
| 122 | * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels |
| 123 | * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND |
| 124 | * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type |
| 125 | * |
| 126 | * Use the input reference voltage depending on the calibration type |
| 127 | * to calcluate the offset and gain parameters. The calibration is |
| 128 | * specific to each channel of the PM8921 ADC. |
| 129 | */ |
| 130 | enum pm8921_adc_calib_type { |
| 131 | ADC_CALIB_ABSOLUTE = 0, |
| 132 | ADC_CALIB_RATIOMETRIC, |
| 133 | ADC_CALIB_CONFIG_NONE, |
| 134 | }; |
| 135 | |
| 136 | /** |
| 137 | * enum pm8921_adc_channel_scaling_param - pre-scaling AMUX ratio |
| 138 | * %CHAN_PATH_SCALING1: ratio of {1, 1} |
| 139 | * %CHAN_PATH_SCALING2: ratio of {1, 3} |
| 140 | * %CHAN_PATH_SCALING3: ratio of {1, 4} |
| 141 | * %CHAN_PATH_SCALING4: ratio of {1, 6} |
| 142 | * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type |
| 143 | * |
| 144 | * The pre-scaling is applied for signals to be within the voltage range |
| 145 | * of the ADC. |
| 146 | */ |
| 147 | enum pm8921_adc_channel_scaling_param { |
| 148 | CHAN_PATH_SCALING1 = 0, |
| 149 | CHAN_PATH_SCALING2, |
| 150 | CHAN_PATH_SCALING3, |
| 151 | CHAN_PATH_SCALING4, |
| 152 | CHAN_PATH_SCALING_NONE, |
| 153 | }; |
| 154 | |
| 155 | /** |
| 156 | * enum pm8921_adc_amux_input_rsv - HK/XOADC reference voltage |
| 157 | * %AMUX_RSV0: XO_IN/XOADC_GND |
| 158 | * %AMUX_RSV1: PMIC_IN/XOADC_GND |
| 159 | * %AMUX_RSV2: PMIC_IN/BMS_CSP |
| 160 | * %AMUX_RSV3: not used |
| 161 | * %AMUX_RSV4: XOADC_GND/XOADC_GND |
| 162 | * %AMUX_RSV5: XOADC_VREF/XOADC_GND |
| 163 | * %AMUX_NONE: Do not use this input reference voltage selection |
| 164 | */ |
| 165 | enum pm8921_adc_amux_input_rsv { |
| 166 | AMUX_RSV0 = 0, |
| 167 | AMUX_RSV1, |
| 168 | AMUX_RSV2, |
| 169 | AMUX_RSV3, |
| 170 | AMUX_RSV4, |
| 171 | AMUX_RSV5, |
| 172 | AMUX_NONE, |
| 173 | }; |
| 174 | |
| 175 | /** |
| 176 | * enum pm8921_adc_premux_mpp_scale_type - 16:1 pre-mux scale ratio |
| 177 | * %PREMUX_MPP_SCALE_0: No scaling to the input signal |
| 178 | * %PREMUX_MPP_SCALE_1: Unity scaling selected by the user for MPP input |
| 179 | * %PREMUX_MPP_SCALE_1_DIV3: 1/3 pre-scale to the input MPP signal |
| 180 | * %PREMUX_MPP_NONE: Do not use this pre-scale mpp type |
| 181 | */ |
| 182 | enum pm8921_adc_premux_mpp_scale_type { |
| 183 | PREMUX_MPP_SCALE_0 = 0, |
| 184 | PREMUX_MPP_SCALE_1, |
| 185 | PREMUX_MPP_SCALE_1_DIV3, |
| 186 | PREMUX_MPP_NONE, |
| 187 | }; |
| 188 | |
| 189 | /** |
| 190 | * enum pm8921_adc_scale_fn_type - Scaling function for pm8921 pre calibrated |
| 191 | * digital data relative to ADC reference |
| 192 | * %ADC_SCALE_DEFAULT: Default scaling to convert raw adc code to voltage |
| 193 | * %ADC_SCALE_BATT_THERM: Conversion to temperature based on btm parameters |
| 194 | * %ADC_SCALE_PMIC_THERM: Returns result in milli degree's Centigrade |
| 195 | * %ADC_SCALE_XTERN_CHGR_CUR: Returns current across 0.1 ohm resistor |
| 196 | * %ADC_SCALE_NONE: Do not use this scaling type |
| 197 | */ |
| 198 | enum pm8921_adc_scale_fn_type { |
| 199 | ADC_SCALE_DEFAULT = 0, |
| 200 | ADC_SCALE_BATT_THERM, |
| 201 | ADC_SCALE_PMIC_THERM, |
| 202 | ADC_SCALE_XTERN_CHGR_CUR, |
| 203 | ADC_SCALE_NONE, |
| 204 | }; |
| 205 | |
| 206 | /** |
| 207 | * struct pm8921_adc_linear_graph - Represent ADC characteristics |
| 208 | * @offset: Offset with respect to the actual curve |
| 209 | * @dy: Numerator slope to calculate the gain |
| 210 | * @dx: Denominator slope to calculate the gain |
| 211 | * |
| 212 | * Each ADC device has different offset and gain parameters which are computed |
| 213 | * to calibrate the device. |
| 214 | */ |
| 215 | struct pm8921_adc_linear_graph { |
| 216 | int32_t offset; |
| 217 | int32_t dy; |
| 218 | int32_t dx; |
| 219 | }; |
| 220 | |
| 221 | /** |
| 222 | * struct pm8921_adc_map_pt - Map the graph representation for ADC channel |
| 223 | * @x: Represent the ADC digitized code |
| 224 | * @y: Represent the physical data which can be temperature, voltage, |
| 225 | * resistance |
| 226 | */ |
| 227 | struct pm8921_adc_map_pt { |
| 228 | int32_t x; |
| 229 | int32_t y; |
| 230 | }; |
| 231 | |
| 232 | /** |
| 233 | * struct pm8921_adc_scaling_ratio - Represent scaling ratio for adc input |
| 234 | * @num: Numerator scaling parameter |
| 235 | * @den: Denominator scaling parameter |
| 236 | */ |
| 237 | struct pm8921_adc_scaling_ratio { |
| 238 | int32_t num; |
| 239 | int32_t den; |
| 240 | }; |
| 241 | |
| 242 | /** |
| 243 | * struct pm8921_adc_properties - Represent the ADC properties |
| 244 | * @adc_reference: Reference voltage for PM8921 ADC |
| 245 | * @bitresolution: ADC bit resolution for PM8921 ADC |
| 246 | * @biploar: Polarity for PM8921 ADC |
| 247 | */ |
| 248 | struct pm8921_adc_properties { |
| 249 | uint32_t adc_vdd_reference; |
| 250 | uint32_t bitresolution; |
| 251 | bool bipolar; |
| 252 | }; |
| 253 | |
| 254 | /** |
| 255 | * struct pm8921_adc_chan_properties - Represent channel properties of the ADC |
| 256 | * @offset_gain_numerator: The inverse numerator of the gain applied to the |
| 257 | * input channel |
| 258 | * @offset_gain_denominator: The inverse denominator of the gain applied to the |
| 259 | * input channel |
| 260 | * @adc_graph: ADC graph for the channel of struct type pm8921_adc_linear_graph |
| 261 | */ |
| 262 | struct pm8921_adc_chan_properties { |
| 263 | uint32_t offset_gain_numerator; |
| 264 | uint32_t offset_gain_denominator; |
| 265 | struct pm8921_adc_linear_graph adc_graph[2]; |
| 266 | }; |
| 267 | |
| 268 | /** |
| 269 | * struct pm8921_adc_chan_result - Represent the result of the PM8921 ADC |
| 270 | * @chan: The channel number of the requested conversion |
| 271 | * @adc_code: The pre-calibrated digital output of a given ADC relative to the |
| 272 | * the ADC reference |
| 273 | * @measurement: In units specific for a given ADC; most ADC uses reference |
| 274 | * voltage but some ADC uses reference current. This measurement |
| 275 | * here is a number relative to a reference of a given ADC |
| 276 | * @physical: The data meaningful for each individual channel whether it is |
| 277 | * voltage, current, temperature, etc. |
| 278 | */ |
| 279 | struct pm8921_adc_chan_result { |
| 280 | uint32_t chan; |
| 281 | int32_t adc_code; |
| 282 | int64_t measurement; |
| 283 | int64_t physical; |
| 284 | }; |
| 285 | |
| 286 | #if defined(CONFIG_MFD_PM8921_ADC) || defined(CONFIG_MFD_PM8921_ADC_MODULE) |
| 287 | /** |
| 288 | * pm8921_adc_scale_default() - Scales the pre-calibrated digital output |
| 289 | * of an ADC to the ADC reference and compensates for the |
| 290 | * gain and offset. |
| 291 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 292 | * @adc_prop: adc properties of the pm8921 adc such as bit resolution, |
| 293 | * reference voltage. |
| 294 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 295 | * slope and offset. |
| 296 | * @chan_rslt: Physical result to be stored. |
| 297 | */ |
| 298 | int32_t pm8921_adc_scale_default(int32_t adc_code, |
| 299 | const struct pm8921_adc_properties *adc_prop, |
| 300 | const struct pm8921_adc_chan_properties *chan_prop, |
| 301 | struct pm8921_adc_chan_result *chan_rslt); |
| 302 | /** |
| 303 | * pm8921_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output |
| 304 | * of an ADC to the ADC reference and compensates for the |
| 305 | * gain and offset. Returns the temperature of the xo therm in mili |
| 306 | degC. |
| 307 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 308 | * @adc_prop: adc properties of the pm8921 adc such as bit resolution, |
| 309 | * reference voltage. |
| 310 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 311 | * slope and offset. |
| 312 | * @chan_rslt: physical result to be stored. |
| 313 | */ |
| 314 | int32_t pm8921_adc_tdkntcg_therm(int32_t adc_code, |
| 315 | const struct pm8921_adc_properties *adc_prop, |
| 316 | const struct pm8921_adc_chan_properties *chan_prop, |
| 317 | struct pm8921_adc_chan_result *chan_rslt); |
| 318 | /** |
| 319 | * pm8921_adc_scale_batt_therm() - Scales the pre-calibrated digital output |
| 320 | * of an ADC to the ADC reference and compensates for the |
| 321 | * gain and offset. Returns the temperature in degC. |
| 322 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 323 | * @adc_prop: adc properties of the pm8921 adc such as bit resolution, |
| 324 | * reference voltage. |
| 325 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 326 | * slope and offset. |
| 327 | * @chan_rslt: physical result to be stored. |
| 328 | */ |
| 329 | int32_t pm8921_adc_scale_batt_therm(int32_t adc_code, |
| 330 | const struct pm8921_adc_properties *adc_prop, |
| 331 | const struct pm8921_adc_chan_properties *chan_prop, |
| 332 | struct pm8921_adc_chan_result *chan_rslt); |
| 333 | /** |
| 334 | * pm8921_adc_scale_pmic_therm() - Scales the pre-calibrated digital output |
| 335 | * of an ADC to the ADC reference and compensates for the |
| 336 | * gain and offset. Performs the AMUX out as 2mv/K and returns |
| 337 | * the temperature in mili degC. |
| 338 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 339 | * @adc_prop: adc properties of the pm8921 adc such as bit resolution, |
| 340 | * reference voltage. |
| 341 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 342 | * slope and offset. |
| 343 | * @chan_rslt: physical result to be stored. |
| 344 | */ |
| 345 | int32_t pm8921_adc_scale_pmic_therm(int32_t adc_code, |
| 346 | const struct pm8921_adc_properties *adc_prop, |
| 347 | const struct pm8921_adc_chan_properties *chan_prop, |
| 348 | struct pm8921_adc_chan_result *chan_rslt); |
| 349 | /** |
| 350 | * pm8921_adc_scale_xtern_chgr_cur() - Scales the pre-calibrated digital output |
| 351 | * of an ADC to the ADC reference and compensates for the |
| 352 | * gain and offset. Returns the current across the 10m ohm |
| 353 | * resistor. |
| 354 | * @adc_code: pre-calibrated digital ouput of the ADC. |
| 355 | * @adc_prop: adc properties of the pm8921 adc such as bit resolution, |
| 356 | * reference voltage. |
| 357 | * @chan_prop: individual channel properties to compensate the i/p scaling, |
| 358 | * slope and offset. |
| 359 | * @chan_rslt: physical result to be stored. |
| 360 | */ |
| 361 | int32_t pm8921_adc_scale_xtern_chgr_cur(int32_t adc_code, |
| 362 | const struct pm8921_adc_properties *adc_prop, |
| 363 | const struct pm8921_adc_chan_properties *chan_prop, |
| 364 | struct pm8921_adc_chan_result *chan_rslt); |
| 365 | |
| 366 | #else |
| 367 | static inline int32_t pm8921_adc_scale_default(int32_t adc_code, |
| 368 | const struct pm8921_adc_properties *adc_prop, |
| 369 | const struct pm8921_adc_chan_properties *chan_prop, |
| 370 | struct pm8921_adc_chan_result *chan_rslt) |
| 371 | { return -ENXIO; } |
| 372 | static inline int32_t pm8921_adc_tdkntcg_therm(int32_t adc_code, |
| 373 | const struct pm8921_adc_properties *adc_prop, |
| 374 | const struct pm8921_adc_chan_properties *chan_prop, |
| 375 | struct pm8921_adc_chan_result *chan_rslt) |
| 376 | { return -ENXIO; } |
| 377 | static inline int32_t pm8921_adc_scale_batt_therm(int32_t adc_code, |
| 378 | const struct pm8921_adc_properties *adc_prop, |
| 379 | const struct pm8921_adc_chan_properties *chan_prop, |
| 380 | struct pm8921_adc_chan_result *chan_rslt) |
| 381 | { return -ENXIO; } |
| 382 | static inline int32_t pm8921_adc_scale_pmic_therm(int32_t adc_code, |
| 383 | const struct pm8921_adc_properties *adc_prop, |
| 384 | const struct pm8921_adc_chan_properties *chan_prop, |
| 385 | struct pm8921_adc_chan_result *chan_rslt) |
| 386 | { return -ENXIO; } |
| 387 | static inline int32_t pm8921_adc_scale_xtern_chgr_cur(int32_t adc_code, |
| 388 | const struct pm8921_adc_properties *adc_prop, |
| 389 | const struct pm8921_adc_chan_properties *chan_prop, |
| 390 | struct pm8921_adc_chan_result *chan_rslt) |
| 391 | { return -ENXIO; } |
| 392 | #endif |
| 393 | |
| 394 | /** |
| 395 | * struct pm8921_adc_scale_fn - Scaling function prototype |
| 396 | * @chan: Function pointer to one of the scaling functions |
| 397 | * which takes the adc properties, channel properties, |
| 398 | * and returns the physical result |
| 399 | */ |
| 400 | struct pm8921_adc_scale_fn { |
| 401 | int32_t (*chan) (int32_t, |
| 402 | const struct pm8921_adc_properties *, |
| 403 | const struct pm8921_adc_chan_properties *, |
| 404 | struct pm8921_adc_chan_result *); |
| 405 | }; |
| 406 | |
| 407 | /** |
| 408 | * struct pm8921_adc_amux - AMUX properties for individual channel |
| 409 | * @name: Channel name |
| 410 | * @channel_name: Channel in integer used from pm8921_adc_channels |
| 411 | * @chan_path_prescaling: Channel scaling performed on the input signal |
| 412 | * @adc_rsv: Input reference Voltage/GND selection to the ADC |
| 413 | * @adc_decimation: Sampling rate desired for the channel |
| 414 | * adc_scale_fn: Scaling function to convert to the data meaningful for |
| 415 | * each individual channel whether it is voltage, current, |
| 416 | * temperature, etc and compensates the channel properties |
| 417 | */ |
| 418 | struct pm8921_adc_amux { |
| 419 | char *name; |
| 420 | enum pm8921_adc_channels channel_name; |
| 421 | enum pm8921_adc_channel_scaling_param chan_path_prescaling; |
| 422 | enum pm8921_adc_amux_input_rsv adc_rsv; |
| 423 | enum pm8921_adc_decimation_type adc_decimation; |
| 424 | enum pm8921_adc_scale_fn_type adc_scale_fn; |
| 425 | }; |
| 426 | |
| 427 | /** |
| 428 | * struct pm8921_adc_arb_btm - PM8921 ADC BTM parameters |
| 429 | * @btm_prop: BTM parameters such as input resistance, voltage and Rtherm across |
| 430 | * the thermistor |
| 431 | * @btm_param: BTM temperature thresholds and interval to program the BTM |
| 432 | * @btm_channel_prop: Channel specific properties of the BTM channel |
| 433 | */ |
| 434 | struct pm8921_adc_arb_btm { |
| 435 | struct pm8921_adc_btm_prop *btm_prop; |
| 436 | struct pm8921_adc_arb_btm_param *btm_param; |
| 437 | struct pm8921_adc_btm_channel_properties *btm_channel_prop; |
| 438 | }; |
| 439 | |
| 440 | /** |
| 441 | * struct pm8921_adc_btm_channel_properties - PM8921 ADC BTM channel properties |
| 442 | * @btm_channel: Channel name |
| 443 | * @decimation: Sampling rate |
| 444 | * @btm_rsv: Input selection of Vref/GND |
| 445 | * @chan_prop: Channel properties for the BTM channel |
| 446 | */ |
| 447 | struct pm8921_adc_btm_channel_properties { |
| 448 | enum pm8921_adc_channels btm_channel; |
| 449 | enum pm8921_adc_decimation_type decimation; |
| 450 | enum pm8921_adc_amux_input_rsv btm_rsv; |
| 451 | struct pm8921_adc_chan_properties *chan_prop; |
| 452 | }; |
| 453 | |
| 454 | /** |
| 455 | * struct pm8921_adc_btm_prop - BTM specific resistors, voltage reference to |
| 456 | * calcluate the temperature across Rthm |
| 457 | * @rs1: Resistor of the Vref_therm |
| 458 | * @rs2: Resistor of BTM |
| 459 | * @r_thm: Resistance of the thermistor |
| 460 | * vref_thm: Voltage of vref_therm |
| 461 | */ |
| 462 | struct pm8921_adc_btm_prop { |
| 463 | uint32_t rs_1; |
| 464 | uint32_t rs_2; |
| 465 | uint32_t r_thm; |
| 466 | uint32_t vref_thm; |
| 467 | }; |
| 468 | |
| 469 | /** |
| 470 | * struct pm8921_adc_arb_btm_param - PM8921 ADC BTM parameters to set threshold |
| 471 | * temperature for client notification |
| 472 | * @low_thr_temp: low temperature threshold request for notification |
| 473 | * @high_thr_temp: high temperature threshold request for notification |
| 474 | * @low_thr_voltage: low temperature converted to voltage by arbiter driver |
| 475 | * @high_thr_voltage: high temperature converted to voltage by arbiter driver |
| 476 | * @interval: Interval period to check for temperature notification |
| 477 | * @btm_warm_fn: Remote function call for warm threshold |
| 478 | * @btm_cold_fn: Remote function call for cold threshold |
| 479 | * |
| 480 | * BTM client passes the parameters to be set for the |
| 481 | * temperature threshold notifications. The client is |
| 482 | * responsible for setting the new threshold |
| 483 | * levels once the thresholds are reached |
| 484 | */ |
| 485 | struct pm8921_adc_arb_btm_param { |
| 486 | uint32_t low_thr_temp; |
| 487 | uint32_t high_thr_temp; |
| 488 | uint32_t low_thr_voltage; |
| 489 | uint32_t high_thr_voltage; |
| 490 | int32_t interval; |
| 491 | void (*btm_warm_fn) (void); |
| 492 | void (*btm_cold_fn) (void); |
| 493 | }; |
| 494 | |
| 495 | int32_t pm8921_adc_batt_scaler(struct pm8921_adc_arb_btm_param *); |
| 496 | |
| 497 | /** |
| 498 | * struct pm8921_adc_platform_data - PM8921 ADC platform data |
| 499 | * @adc_prop: ADC specific parameters, voltage and channel setup |
| 500 | * @adc_channel: Channel properties of the ADC arbiter |
| 501 | * @adc_num_channel: Total number of chanels supported |
| 502 | */ |
| 503 | struct pm8921_adc_platform_data { |
| 504 | struct pm8921_adc_properties *adc_prop; |
| 505 | struct pm8921_adc_amux *adc_channel; |
| 506 | uint32_t adc_num_channel; |
| 507 | u32 adc_wakeup; |
| 508 | }; |
| 509 | |
| 510 | /* Public API */ |
| 511 | #if defined(CONFIG_MFD_PM8921_ADC) || defined(CONFIG_MFD_PM8921_ADC_MODULE) |
| 512 | /** |
| 513 | * pm8921_adc_read() - Performs ADC read on the channel. |
| 514 | * @channel: Input channel to perform the ADC read. |
| 515 | * @result: Structure pointer of type adc_chan_result |
| 516 | * in which the ADC read results are stored. |
| 517 | */ |
| 518 | uint32_t pm8921_adc_read(enum pm8921_adc_channels channel, |
| 519 | struct pm8921_adc_chan_result *result); |
| 520 | /** |
| 521 | * pm8921_mpp_adc_read() - Performs ADC read on the channel. |
| 522 | * @channel: Input channel to perform the ADC read. |
| 523 | * @result: Structure pointer of type adc_chan_result |
| 524 | * in which the ADC read results are stored. |
| 525 | * @mpp_scale: The pre scale value to be performed to the input signal |
| 526 | * passed. Currently the pre-scale support is for 1 and 1/3. |
| 527 | */ |
| 528 | uint32_t pm8921_adc_mpp_read(enum pm8921_adc_mpp_channels channel, |
| 529 | struct pm8921_adc_chan_result *result, |
| 530 | enum pm8921_adc_premux_mpp_scale_type); |
| 531 | /** |
| 532 | * pm8921_adc_btm_start() - Configure the BTM registers and start |
| 533 | monitoring the BATT_THERM channel for |
| 534 | threshold warm/cold temperature set |
| 535 | by the Battery client. The btm_start |
| 536 | api is to be used after calling the |
| 537 | pm8921_btm_configure() api which sets |
| 538 | the temperature thresholds, interval |
| 539 | and functions to call when warm/cold |
| 540 | events are triggered. |
| 541 | * @param: none. |
| 542 | */ |
| 543 | uint32_t pm8921_adc_btm_start(void); |
| 544 | |
| 545 | /** |
| 546 | * pm8921_adc_btm_end() - Configures the BTM registers to stop |
| 547 | * monitoring the BATT_THERM channel for |
| 548 | * warm/cold events and disables the |
| 549 | * interval timer. |
| 550 | * @param: none. |
| 551 | */ |
| 552 | uint32_t pm8921_adc_btm_end(void); |
| 553 | |
| 554 | /** |
| 555 | * pm8921_adc_btm_configure() - Configures the BATT_THERM channel |
| 556 | * parameters for warm/cold thresholds. |
| 557 | * Sets the interval timer for perfoming |
| 558 | * reading the temperature done by the HW. |
| 559 | * @btm_param: Structure pointer of type adc_arb_btm_param * |
| 560 | * which client provides for threshold warm/cold, |
| 561 | * interval and functions to call when warm/cold |
| 562 | * events are triggered. |
| 563 | */ |
| 564 | uint32_t pm8921_adc_btm_configure(struct pm8921_adc_arb_btm_param *); |
| 565 | #else |
| 566 | static inline uint32_t pm8921_adc_read(uint32_t channel, |
| 567 | struct pm8921_adc_chan_result *result) |
| 568 | { return -ENXIO; } |
| 569 | static inline uint32_t pm8921_mpp_adc_read(uint32_t channel, |
| 570 | struct pm8921_adc_chan_result *result, |
| 571 | enum pm8921_adc_premux_mpp_scale_type scale) |
| 572 | { return -ENXIO; } |
| 573 | static inline uint32_t pm8921_adc_btm_start(void) |
| 574 | { return -ENXIO; } |
| 575 | static inline uint32_t pm8921_adc_btm_end(void) |
| 576 | { return -ENXIO; } |
| 577 | static inline uint32_t pm8921_adc_btm_configure( |
| 578 | struct pm8921_adc_arb_btm_param *param) |
| 579 | { return -ENXIO; } |
| 580 | #endif |
| 581 | |
| 582 | #endif /* MFD_PM8921_ADC_H */ |