blob: a29486f8f3356f1e56d0a1f364b0629c7ade6e10 [file] [log] [blame]
Abhijeet Dharmapurikar5389ebc2013-03-10 06:55:43 -07001/* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -08002 *
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 Shid035f6a2012-12-18 16:16:33 -080020struct pm8xxx_ccadc_core_data {
21 unsigned int batt_temp_channel;
22};
23
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080024/**
25 * struct pm8xxx_ccadc_platform_data -
Xiaozhe Shid035f6a2012-12-18 16:16:33 -080026 * @ccadc_cdata: core data for the ccadc driver containing channel info
Xiaozhe Shid69c91e2012-11-06 10:00:38 -080027 * @r_sense_uohm: sense resistor value in (micro Ohms)
David Keitel3c378822012-06-07 13:43:22 -070028 * @calib_delay_ms: how often should the adc calculate gain and offset
Abhijeet Dharmapurikar5389ebc2013-03-10 06:55:43 -070029 * @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 Dharmapurikar82d93982011-11-09 15:52:25 -080032 */
33struct pm8xxx_ccadc_platform_data {
Xiaozhe Shid035f6a2012-12-18 16:16:33 -080034 struct pm8xxx_ccadc_core_data ccadc_cdata;
35 int r_sense_uohm;
36 unsigned int calib_delay_ms;
Abhijeet Dharmapurikar5389ebc2013-03-10 06:55:43 -070037 bool periodic_wakeup;
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080038};
39
Abhijeet Dharmapurikar305c5292012-06-21 16:15:43 -070040#define CCADC_READING_RESOLUTION_N 542535
41#define CCADC_READING_RESOLUTION_D 100000
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080042
43static inline s64 pm8xxx_ccadc_reading_to_microvolt(int revision, s64 cc)
44{
Abhijeet Dharmapurikar305c5292012-06-21 16:15:43 -070045 return div_s64(cc * CCADC_READING_RESOLUTION_N,
46 CCADC_READING_RESOLUTION_D);
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080047}
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 */
58s64 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 */
65void pm8xxx_calib_ccadc(void);
66
67/**
68 * pm8xxx_ccadc_get_battery_current - return the battery current based on vsense
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -080069 * resitor in microamperes
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080070 * @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 */
78int pm8xxx_ccadc_get_battery_current(int *bat_current);
79#else
80static inline s64 pm8xxx_cc_adjust_for_gain(s64 uv)
81{
82 return -ENXIO;
83}
84static inline void pm8xxx_calib_ccadc(void)
85{
86}
87static inline int pm8xxx_ccadc_get_battery_current(int *bat_current)
88{
89 return -ENXIO;
90}
91#endif
92
93#endif /* __PMIC8XXX_CCADC_H__ */