Abhijeet Dharmapurikar | 24fccfe | 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 | |
Abhijeet Dharmapurikar | 999ee57 | 2012-08-28 19:33:49 -0700 | [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 - |
Abhijeet Dharmapurikar | 999ee57 | 2012-08-28 19:33:49 -0700 | [diff] [blame] | 26 | * @ccadc_cdata: core data for the ccadc driver containing channel info |
| 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 | 24fccfe | 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 { |
Abhijeet Dharmapurikar | 999ee57 | 2012-08-28 19:33:49 -0700 | [diff] [blame] | 34 | struct pm8xxx_ccadc_core_data ccadc_cdata; |
| 35 | int r_sense_uohm; |
| 36 | unsigned int calib_delay_ms; |
Abhijeet Dharmapurikar | 24fccfe | 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); |
Flemmard | a01b5f6 | 2013-05-07 17:08:52 -0700 | [diff] [blame] | 79 | |
| 80 | #ifdef CONFIG_MACH_HTC |
| 81 | /** |
| 82 | * pm8xxx_ccadc_dump_all - dump register contents to log |
| 83 | * |
| 84 | * RETURNS: 0 |
| 85 | */ |
| 86 | int pm8xxx_ccadc_dump_all(void); |
| 87 | |
| 88 | /** |
| 89 | * pm8xxx_ccadc_get_attr_text - get registers contents as text string |
| 90 | * @buf: The pointer to the buffer |
| 91 | * @size: The size in bytes of the buffer |
| 92 | * |
| 93 | * RETURNS: The length of the text string returned. |
| 94 | */ |
| 95 | int pm8xxx_ccadc_get_attr_text(char *buf, int size); |
| 96 | #endif /* CONFIG_MACH_HTC */ |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 97 | #else |
| 98 | static inline s64 pm8xxx_cc_adjust_for_gain(s64 uv) |
| 99 | { |
| 100 | return -ENXIO; |
| 101 | } |
| 102 | static inline void pm8xxx_calib_ccadc(void) |
| 103 | { |
| 104 | } |
| 105 | static inline int pm8xxx_ccadc_get_battery_current(int *bat_current) |
| 106 | { |
| 107 | return -ENXIO; |
| 108 | } |
Flemmard | a01b5f6 | 2013-05-07 17:08:52 -0700 | [diff] [blame] | 109 | #ifdef CONFIG_MACH_HTC |
| 110 | static inline int pm8xxx_ccadc_dump_all(void) |
| 111 | { |
| 112 | return -ENXIO; |
| 113 | } |
| 114 | static inline int pm8xxx_ccadc_get_attr_text(char *buf, int size) |
| 115 | { |
| 116 | return -ENXIO; |
| 117 | } |
| 118 | #endif /* CONFIG_MACH_HTC */ |
Abhijeet Dharmapurikar | 82d9398 | 2011-11-09 15:52:25 -0800 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | #endif /* __PMIC8XXX_CCADC_H__ */ |