blob: e4d5a67f51c7082f328a9c8b6f728dd161b8dffc [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
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 Dharmapurikar82d93982011-11-09 15:52:25 -080029 */
30struct pm8xxx_ccadc_platform_data {
Xiaozhe Shid035f6a2012-12-18 16:16:33 -080031 struct pm8xxx_ccadc_core_data ccadc_cdata;
32 int r_sense_uohm;
33 unsigned int calib_delay_ms;
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080034};
35
Abhijeet Dharmapurikar305c5292012-06-21 16:15:43 -070036#define CCADC_READING_RESOLUTION_N 542535
37#define CCADC_READING_RESOLUTION_D 100000
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080038
39static inline s64 pm8xxx_ccadc_reading_to_microvolt(int revision, s64 cc)
40{
Abhijeet Dharmapurikar305c5292012-06-21 16:15:43 -070041 return div_s64(cc * CCADC_READING_RESOLUTION_N,
42 CCADC_READING_RESOLUTION_D);
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080043}
44
45#if defined(CONFIG_PM8XXX_CCADC) || defined(CONFIG_PM8XXX_CCADC_MODULE)
46/**
47 * pm8xxx_cc_adjust_for_gain - the function to adjust the voltage read from
48 * ccadc for gain compensation
49 * @v: the voltage which needs to be gain compensated in microVolts
50 *
51 *
52 * RETURNS: gain compensated voltage
53 */
54s64 pm8xxx_cc_adjust_for_gain(s64 uv);
55
56/**
57 * pm8xxx_calib_ccadc - calibration for ccadc. This will calculate gain
58 * and offset and reprogram them in the appropriate
59 * registers
60 */
61void pm8xxx_calib_ccadc(void);
62
63/**
64 * pm8xxx_ccadc_get_battery_current - return the battery current based on vsense
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -080065 * resitor in microamperes
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080066 * @result: The pointer where the voltage will be updated. A -ve
67 * result means that the current is flowing in
68 * the battery - during battery charging
69 *
70 * RETURNS: Error code if there was a problem reading vsense, Zero otherwise
71 * The result won't be updated in case of an error.
72 *
73 */
74int pm8xxx_ccadc_get_battery_current(int *bat_current);
75#else
76static inline s64 pm8xxx_cc_adjust_for_gain(s64 uv)
77{
78 return -ENXIO;
79}
80static inline void pm8xxx_calib_ccadc(void)
81{
82}
83static inline int pm8xxx_ccadc_get_battery_current(int *bat_current)
84{
85 return -ENXIO;
86}
87#endif
88
89#endif /* __PMIC8XXX_CCADC_H__ */