blob: 0806d31e6b6f9529582701408782730ab80783fc [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 __PM8XXX_BMS_H
14#define __PM8XXX_BMS_H
15
16#include <linux/errno.h>
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070017#include <linux/mfd/pm8xxx/batterydata-lib.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018
19#define PM8921_BMS_DEV_NAME "pm8921-bms"
20
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021
Abhijeet Dharmapurikarc448d982011-06-28 20:48:36 -070022struct pm8xxx_bms_core_data {
23 unsigned int batt_temp_channel;
24 unsigned int vbat_channel;
Abhijeet Dharmapurikar76d4db92011-07-19 11:54:52 -070025 unsigned int ref625mv_channel;
26 unsigned int ref1p25v_channel;
Abhijeet Dharmapurikare922bbb2011-09-01 13:05:06 -070027 unsigned int batt_id_channel;
Abhijeet Dharmapurikarc448d982011-06-28 20:48:36 -070028};
29
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030/**
31 * struct pm8921_bms_platform_data -
David Keitel35e11872012-02-17 17:40:42 -080032 * @batt_type: allows to force chose battery calibration data
Xiaozhe Shid69c91e2012-11-06 10:00:38 -080033 * @r_sense_uohm: sense resistor value in (micro Ohms)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034 * @i_test: current at which the unusable charger cutoff is to be
35 * calculated or the peak system current (mA)
Abhijeet Dharmapurikara51c87b2012-07-13 20:13:14 -070036 * @v_cutoff: the loaded voltage at which the battery
37 * is considered empty(mV)
Abhijeet Dharmapurikare88f2462012-04-25 18:22:38 -070038 * @enable_fcc_learning: if set the driver will learn full charge
39 * capacity of the battery upon end of charge
Abhijeet Dharmapurikar683472d2012-10-30 16:21:58 -070040 * @normal_voltage_calc_ms: The period of soc calculation in ms when battery
41 * voltage higher than cutoff voltage
42 * @low_voltage_calc_ms: The period of soc calculation in ms when battery
43 * voltage is near cutoff voltage
Abhijeet Dharmapurikar1939ede2013-01-10 15:59:33 -080044 * @disable_flat_portion_ocv: feature to disable ocv updates while in sleep
45 * @ocv_dis_high_soc: the high soc percent when ocv should be disabled
46 * @ocv_dis_low_soc: the low soc percent when ocv should be enabled
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047 */
48struct pm8921_bms_platform_data {
Abhijeet Dharmapurikarc448d982011-06-28 20:48:36 -070049 struct pm8xxx_bms_core_data bms_cdata;
David Keitel35e11872012-02-17 17:40:42 -080050 enum battery_type battery_type;
Xiaozhe Shid69c91e2012-11-06 10:00:38 -080051 int r_sense_uohm;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052 unsigned int i_test;
Abhijeet Dharmapurikara51c87b2012-07-13 20:13:14 -070053 unsigned int v_cutoff;
Abhijeet Dharmapurikara93ede82011-11-17 12:20:03 -080054 unsigned int max_voltage_uv;
Abhijeet Dharmapurikarbaffba42012-03-22 14:41:10 -070055 unsigned int rconn_mohm;
Anirudh Ghayal6fe4ffa2013-02-01 11:44:33 +053056 unsigned int alarm_low_mv;
57 unsigned int alarm_high_mv;
Abhijeet Dharmapurikare88f2462012-04-25 18:22:38 -070058 int enable_fcc_learning;
Abhijeet Dharmapurikar602dc272012-07-19 21:34:56 -070059 int shutdown_soc_valid_limit;
Abhijeet Dharmapurikar1f4cc512012-07-21 00:10:39 -070060 int ignore_shutdown_soc;
Abhijeet Dharmapurikar720b00e2012-08-01 21:33:09 -070061 int adjust_soc_low_threshold;
Abhijeet Dharmapurikard6d66c72012-08-06 14:02:51 -070062 int chg_term_ua;
Abhijeet Dharmapurikar683472d2012-10-30 16:21:58 -070063 int normal_voltage_calc_ms;
64 int low_voltage_calc_ms;
Abhijeet Dharmapurikar1939ede2013-01-10 15:59:33 -080065 int disable_flat_portion_ocv;
66 int ocv_dis_high_soc;
67 int ocv_dis_low_soc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068};
69
70#if defined(CONFIG_PM8921_BMS) || defined(CONFIG_PM8921_BMS_MODULE)
Abhijeet Dharmapurikar2fb6f082011-06-28 17:10:27 -070071/**
72 * pm8921_bms_get_vsense_avg - return the voltage across the sense
73 * resitor in microvolts
Abhijeet Dharmapurikare0c3e5f2011-07-11 21:17:23 -070074 * @result: The pointer where the voltage will be updated. A -ve
75 * result means that the current is flowing in
76 * the battery - during battery charging
Abhijeet Dharmapurikar2fb6f082011-06-28 17:10:27 -070077 *
78 * RETURNS: Error code if there was a problem reading vsense, Zero otherwise
79 * The result won't be updated in case of an error.
Abhijeet Dharmapurikare0c3e5f2011-07-11 21:17:23 -070080 *
81 *
Abhijeet Dharmapurikar2fb6f082011-06-28 17:10:27 -070082 */
83int pm8921_bms_get_vsense_avg(int *result);
Abhijeet Dharmapurikar52344ac2011-07-05 18:44:54 -070084
85/**
Abhijeet Dharmapurikare0c3e5f2011-07-11 21:17:23 -070086 * pm8921_bms_get_battery_current - return the battery current based on vsense
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -080087 * resitor in microamperes
Abhijeet Dharmapurikare0c3e5f2011-07-11 21:17:23 -070088 * @result: The pointer where the voltage will be updated. A -ve
89 * result means that the current is flowing in
90 * the battery - during battery charging
91 *
92 * RETURNS: Error code if there was a problem reading vsense, Zero otherwise
93 * The result won't be updated in case of an error.
94 *
95 */
96int pm8921_bms_get_battery_current(int *result);
97
98/**
Abhijeet Dharmapurikar52344ac2011-07-05 18:44:54 -070099 * pm8921_bms_get_percent_charge - returns the current battery charge in percent
100 *
101 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700102int pm8921_bms_get_percent_charge(void);
Abhijeet Dharmapurikar325bdc92011-09-07 20:45:49 -0700103
104/**
105 * pm8921_bms_get_fcc - returns fcc in mAh of the battery depending on its age
106 * and temperature
107 *
108 */
109int pm8921_bms_get_fcc(void);
110
Abhijeet Dharmapurikar52344ac2011-07-05 18:44:54 -0700111/**
112 * pm8921_bms_charging_began - function to notify the bms driver that charging
113 * has started. Used by the bms driver to keep
114 * track of chargecycles
115 */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116void pm8921_bms_charging_began(void);
Abhijeet Dharmapurikar52344ac2011-07-05 18:44:54 -0700117/**
118 * pm8921_bms_charging_end - function to notify the bms driver that charging
119 * has stopped. Used by the bms driver to keep
120 * track of chargecycles
121 */
Abhijeet Dharmapurikarfad72352011-09-25 23:06:05 -0700122void pm8921_bms_charging_end(int is_battery_full);
Abhijeet Dharmapurikar1b8e8292012-01-17 11:01:44 -0800123
124void pm8921_bms_calibrate_hkadc(void);
Abhijeet Dharmapurikarc9857ca2012-02-07 15:56:06 -0800125/**
126 * pm8921_bms_get_simultaneous_battery_voltage_and_current
127 * - function to take simultaneous vbat and vsense readings
128 * this puts the bms in override mode but keeps coulumb couting
129 * on. Useful when ir compensation needs to be implemented
130 */
131int pm8921_bms_get_simultaneous_battery_voltage_and_current(int *ibat_ua,
132 int *vbat_uv);
Abhijeet Dharmapurikarf6fdcaa02012-02-27 00:10:10 -0800133/**
Abhijeet Dharmapurikareca7b3e2012-12-26 21:30:29 -0800134 * pm8921_bms_get_current_max
135 * - function to get the max current that can be drawn from
136 * the battery before it dips below the min allowed voltage
Abhijeet Dharmapurikarf6fdcaa02012-02-27 00:10:10 -0800137 */
Abhijeet Dharmapurikareca7b3e2012-12-26 21:30:29 -0800138int pm8921_bms_get_current_max(void);
Abhijeet Dharmapurikared2d87e2012-06-26 20:15:36 -0700139/**
140 * pm8921_bms_invalidate_shutdown_soc - function to notify the bms driver that
141 * the battery was replaced between reboot
142 * and so it should not use the shutdown
143 * soc stored in a coincell backed register
144 */
145void pm8921_bms_invalidate_shutdown_soc(void);
Abhijeet Dharmapurikar4c78f462012-10-16 15:43:55 -0700146
147/**
148 * pm8921_bms_cc_uah - function to get the coulomb counter based charge. Note
149 * that the coulomb counter are reset when the current
150 * consumption is low (below 8mA for more than 5 minutes),
151 * This will lead in a very low coulomb counter charge
152 * value upon wakeup from sleep.
153 */
154int pm8921_bms_cc_uah(int *cc_uah);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700155#else
Abhijeet Dharmapurikar2fb6f082011-06-28 17:10:27 -0700156static inline int pm8921_bms_get_vsense_avg(int *result)
157{
158 return -ENXIO;
159}
Abhijeet Dharmapurikare0c3e5f2011-07-11 21:17:23 -0700160static inline int pm8921_bms_get_battery_current(int *result)
161{
162 return -ENXIO;
163}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700164static inline int pm8921_bms_get_percent_charge(void)
165{
166 return -ENXIO;
167}
Abhijeet Dharmapurikar325bdc92011-09-07 20:45:49 -0700168static inline int pm8921_bms_get_fcc(void)
169{
170 return -ENXIO;
171}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172static inline void pm8921_bms_charging_began(void)
173{
174}
Abhijeet Dharmapurikarfad72352011-09-25 23:06:05 -0700175static inline void pm8921_bms_charging_end(int is_battery_full)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176{
177}
Abhijeet Dharmapurikar1b8e8292012-01-17 11:01:44 -0800178static inline void pm8921_bms_calibrate_hkadc(void)
179{
180}
Abhijeet Dharmapurikarc9857ca2012-02-07 15:56:06 -0800181static inline int pm8921_bms_get_simultaneous_battery_voltage_and_current(
182 int *ibat_ua, int *vbat_uv)
183{
184 return -ENXIO;
185}
Abhijeet Dharmapurikarf6fdcaa02012-02-27 00:10:10 -0800186static inline int pm8921_bms_get_rbatt(void)
187{
188 return -EINVAL;
189}
Abhijeet Dharmapurikared2d87e2012-06-26 20:15:36 -0700190static inline void pm8921_bms_invalidate_shutdown_soc(void)
191{
192}
Abhijeet Dharmapurikar4c78f462012-10-16 15:43:55 -0700193static inline int pm8921_bms_cc_uah(int *cc_uah)
194{
195 return -ENXIO;
196}
Abhijeet Dharmapurikareca7b3e2012-12-26 21:30:29 -0800197static inline int pm8921_bms_get_current_max(void)
198{
199 return -ENXIO;
200}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201#endif
202
203#endif