blob: 29f7a62161c1eb037031152f1d6ea1ce24a6b25f [file] [log] [blame]
David Keitel3c378822012-06-07 13:43:22 -07001/* Copyright (c) 2010-2012, Code Aurora Forum. 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
20/**
21 * struct pm8xxx_ccadc_platform_data -
22 * @r_sense: sense resistor value in (mOhms)
David Keitel3c378822012-06-07 13:43:22 -070023 * @calib_delay_ms: how often should the adc calculate gain and offset
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080024 */
25struct pm8xxx_ccadc_platform_data {
David Keitel3c378822012-06-07 13:43:22 -070026 int r_sense;
27 unsigned int calib_delay_ms;
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080028};
29
Abhijeet Dharmapurikar305c5292012-06-21 16:15:43 -070030#define CCADC_READING_RESOLUTION_N 542535
31#define CCADC_READING_RESOLUTION_D 100000
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080032
33static inline s64 pm8xxx_ccadc_reading_to_microvolt(int revision, s64 cc)
34{
Abhijeet Dharmapurikar305c5292012-06-21 16:15:43 -070035 return div_s64(cc * CCADC_READING_RESOLUTION_N,
36 CCADC_READING_RESOLUTION_D);
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080037}
38
39#if defined(CONFIG_PM8XXX_CCADC) || defined(CONFIG_PM8XXX_CCADC_MODULE)
40/**
41 * pm8xxx_cc_adjust_for_gain - the function to adjust the voltage read from
42 * ccadc for gain compensation
43 * @v: the voltage which needs to be gain compensated in microVolts
44 *
45 *
46 * RETURNS: gain compensated voltage
47 */
48s64 pm8xxx_cc_adjust_for_gain(s64 uv);
49
50/**
51 * pm8xxx_calib_ccadc - calibration for ccadc. This will calculate gain
52 * and offset and reprogram them in the appropriate
53 * registers
54 */
55void pm8xxx_calib_ccadc(void);
56
57/**
58 * pm8xxx_ccadc_get_battery_current - return the battery current based on vsense
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -080059 * resitor in microamperes
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080060 * @result: The pointer where the voltage will be updated. A -ve
61 * result means that the current is flowing in
62 * the battery - during battery charging
63 *
64 * RETURNS: Error code if there was a problem reading vsense, Zero otherwise
65 * The result won't be updated in case of an error.
66 *
67 */
68int pm8xxx_ccadc_get_battery_current(int *bat_current);
69#else
70static inline s64 pm8xxx_cc_adjust_for_gain(s64 uv)
71{
72 return -ENXIO;
73}
74static inline void pm8xxx_calib_ccadc(void)
75{
76}
77static inline int pm8xxx_ccadc_get_battery_current(int *bat_current)
78{
79 return -ENXIO;
80}
81#endif
82
83#endif /* __PMIC8XXX_CCADC_H__ */