blob: 3121998aa85a4ed949bbecb9d18275630beebfff [file] [log] [blame]
Abhijeet Dharmapurikar24fccfe2013-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
Abhijeet Dharmapurikar999ee572012-08-28 19:33:49 -070020struct 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 -
Abhijeet Dharmapurikar999ee572012-08-28 19:33:49 -070026 * @ccadc_cdata: core data for the ccadc driver containing channel info
27 * @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 Dharmapurikar24fccfe2013-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 {
Abhijeet Dharmapurikar999ee572012-08-28 19:33:49 -070034 struct pm8xxx_ccadc_core_data ccadc_cdata;
35 int r_sense_uohm;
36 unsigned int calib_delay_ms;
Abhijeet Dharmapurikar24fccfe2013-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);
Flemmarda01b5f62013-05-07 17:08:52 -070079
80#ifdef CONFIG_MACH_HTC
81/**
82 * pm8xxx_ccadc_dump_all - dump register contents to log
83 *
84 * RETURNS: 0
85 */
86int 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 */
95int pm8xxx_ccadc_get_attr_text(char *buf, int size);
96#endif /* CONFIG_MACH_HTC */
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -080097#else
98static inline s64 pm8xxx_cc_adjust_for_gain(s64 uv)
99{
100 return -ENXIO;
101}
102static inline void pm8xxx_calib_ccadc(void)
103{
104}
105static inline int pm8xxx_ccadc_get_battery_current(int *bat_current)
106{
107 return -ENXIO;
108}
Flemmarda01b5f62013-05-07 17:08:52 -0700109#ifdef CONFIG_MACH_HTC
110static inline int pm8xxx_ccadc_dump_all(void)
111{
112 return -ENXIO;
113}
114static inline int pm8xxx_ccadc_get_attr_text(char *buf, int size)
115{
116 return -ENXIO;
117}
118#endif /* CONFIG_MACH_HTC */
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -0800119#endif
120
121#endif /* __PMIC8XXX_CCADC_H__ */