Abhijeet Dharmapurikar | 5389ebc | 2013-03-10 06:55:43 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved. |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __PMIC8XXX_CCADC_H__ |
| 14 | #define __PMIC8XXX_CCADC_H__ |
| 15 | |
| 16 | #include <linux/mfd/pm8xxx/core.h> |
| 17 | |
| 18 | #define PM8XXX_CCADC_DEV_NAME "pm8xxx-ccadc" |
| 19 | |
Xiaozhe Shi | d035f6a | 2012-12-18 16:16:33 -0800 | [diff] [blame] | 20 | struct pm8xxx_ccadc_core_data { |
| 21 | unsigned int batt_temp_channel; |
| 22 | }; |
| 23 | |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 24 | /** |
| 25 | * struct pm8xxx_ccadc_platform_data - |
Xiaozhe Shi | d035f6a | 2012-12-18 16:16:33 -0800 | [diff] [blame] | 26 | * @ccadc_cdata: core data for the ccadc driver containing channel info |
Xiaozhe Shi | d69c91e | 2012-11-06 10:00:38 -0800 | [diff] [blame] | 27 | * @r_sense_uohm: sense resistor value in (micro Ohms) |
David Keitel | 3c37882 | 2012-06-07 13:43:22 -0700 | [diff] [blame] | 28 | * @calib_delay_ms: how often should the adc calculate gain and offset |
Abhijeet Dharmapurikar | 5389ebc | 2013-03-10 06:55:43 -0700 | [diff] [blame] | 29 | * @periodic_wakeup: a flag to indicate that this system wakeups periodically |
| 30 | * for calibration/other housekeeping activities. The ccadc |
| 31 | * does a quick calibration while resuming |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 32 | */ |
| 33 | struct pm8xxx_ccadc_platform_data { |
Xiaozhe Shi | d035f6a | 2012-12-18 16:16:33 -0800 | [diff] [blame] | 34 | struct pm8xxx_ccadc_core_data ccadc_cdata; |
| 35 | int r_sense_uohm; |
| 36 | unsigned int calib_delay_ms; |
Abhijeet Dharmapurikar | 5389ebc | 2013-03-10 06:55:43 -0700 | [diff] [blame] | 37 | bool periodic_wakeup; |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
Abhijeet Dharmapurikar | 305c529 | 2012-06-21 16:15:43 -0700 | [diff] [blame] | 40 | #define CCADC_READING_RESOLUTION_N 542535 |
| 41 | #define CCADC_READING_RESOLUTION_D 100000 |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 42 | |
| 43 | static inline s64 pm8xxx_ccadc_reading_to_microvolt(int revision, s64 cc) |
| 44 | { |
Abhijeet Dharmapurikar | 305c529 | 2012-06-21 16:15:43 -0700 | [diff] [blame] | 45 | return div_s64(cc * CCADC_READING_RESOLUTION_N, |
| 46 | CCADC_READING_RESOLUTION_D); |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | #if defined(CONFIG_PM8XXX_CCADC) || defined(CONFIG_PM8XXX_CCADC_MODULE) |
| 50 | /** |
| 51 | * pm8xxx_cc_adjust_for_gain - the function to adjust the voltage read from |
| 52 | * ccadc for gain compensation |
| 53 | * @v: the voltage which needs to be gain compensated in microVolts |
| 54 | * |
| 55 | * |
| 56 | * RETURNS: gain compensated voltage |
| 57 | */ |
| 58 | s64 pm8xxx_cc_adjust_for_gain(s64 uv); |
| 59 | |
| 60 | /** |
| 61 | * pm8xxx_calib_ccadc - calibration for ccadc. This will calculate gain |
| 62 | * and offset and reprogram them in the appropriate |
| 63 | * registers |
| 64 | */ |
| 65 | void pm8xxx_calib_ccadc(void); |
| 66 | |
| 67 | /** |
| 68 | * pm8xxx_ccadc_get_battery_current - return the battery current based on vsense |
Siddartha Mohanadoss | 37e6fc0 | 2011-11-16 16:57:03 -0800 | [diff] [blame] | 69 | * resitor in microamperes |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 70 | * @result: The pointer where the voltage will be updated. A -ve |
| 71 | * result means that the current is flowing in |
| 72 | * the battery - during battery charging |
| 73 | * |
| 74 | * RETURNS: Error code if there was a problem reading vsense, Zero otherwise |
| 75 | * The result won't be updated in case of an error. |
| 76 | * |
| 77 | */ |
| 78 | int pm8xxx_ccadc_get_battery_current(int *bat_current); |
| 79 | #else |
| 80 | static inline s64 pm8xxx_cc_adjust_for_gain(s64 uv) |
| 81 | { |
| 82 | return -ENXIO; |
| 83 | } |
| 84 | static inline void pm8xxx_calib_ccadc(void) |
| 85 | { |
| 86 | } |
| 87 | static inline int pm8xxx_ccadc_get_battery_current(int *bat_current) |
| 88 | { |
| 89 | return -ENXIO; |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | #endif /* __PMIC8XXX_CCADC_H__ */ |