Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 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 Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 17 | #include <linux/mfd/pm8xxx/batterydata-lib.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | |
| 19 | #define PM8921_BMS_DEV_NAME "pm8921-bms" |
| 20 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
Abhijeet Dharmapurikar | c448d98 | 2011-06-28 20:48:36 -0700 | [diff] [blame] | 22 | struct pm8xxx_bms_core_data { |
| 23 | unsigned int batt_temp_channel; |
| 24 | unsigned int vbat_channel; |
Abhijeet Dharmapurikar | 76d4db9 | 2011-07-19 11:54:52 -0700 | [diff] [blame] | 25 | unsigned int ref625mv_channel; |
| 26 | unsigned int ref1p25v_channel; |
Abhijeet Dharmapurikar | e922bbb | 2011-09-01 13:05:06 -0700 | [diff] [blame] | 27 | unsigned int batt_id_channel; |
Abhijeet Dharmapurikar | c448d98 | 2011-06-28 20:48:36 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | /** |
| 31 | * struct pm8921_bms_platform_data - |
David Keitel | 35e1187 | 2012-02-17 17:40:42 -0800 | [diff] [blame] | 32 | * @batt_type: allows to force chose battery calibration data |
Xiaozhe Shi | d69c91e | 2012-11-06 10:00:38 -0800 | [diff] [blame] | 33 | * @r_sense_uohm: sense resistor value in (micro Ohms) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | * @i_test: current at which the unusable charger cutoff is to be |
| 35 | * calculated or the peak system current (mA) |
Abhijeet Dharmapurikar | a51c87b | 2012-07-13 20:13:14 -0700 | [diff] [blame] | 36 | * @v_cutoff: the loaded voltage at which the battery |
| 37 | * is considered empty(mV) |
Abhijeet Dharmapurikar | e88f246 | 2012-04-25 18:22:38 -0700 | [diff] [blame] | 38 | * @enable_fcc_learning: if set the driver will learn full charge |
| 39 | * capacity of the battery upon end of charge |
Abhijeet Dharmapurikar | 683472d | 2012-10-30 16:21:58 -0700 | [diff] [blame] | 40 | * @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 Dharmapurikar | 1939ede | 2013-01-10 15:59:33 -0800 | [diff] [blame] | 44 | * @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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 47 | */ |
| 48 | struct pm8921_bms_platform_data { |
Abhijeet Dharmapurikar | c448d98 | 2011-06-28 20:48:36 -0700 | [diff] [blame] | 49 | struct pm8xxx_bms_core_data bms_cdata; |
David Keitel | 35e1187 | 2012-02-17 17:40:42 -0800 | [diff] [blame] | 50 | enum battery_type battery_type; |
Xiaozhe Shi | d69c91e | 2012-11-06 10:00:38 -0800 | [diff] [blame] | 51 | int r_sense_uohm; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | unsigned int i_test; |
Abhijeet Dharmapurikar | a51c87b | 2012-07-13 20:13:14 -0700 | [diff] [blame] | 53 | unsigned int v_cutoff; |
Abhijeet Dharmapurikar | a93ede8 | 2011-11-17 12:20:03 -0800 | [diff] [blame] | 54 | unsigned int max_voltage_uv; |
Abhijeet Dharmapurikar | baffba4 | 2012-03-22 14:41:10 -0700 | [diff] [blame] | 55 | unsigned int rconn_mohm; |
Anirudh Ghayal | 6fe4ffa | 2013-02-01 11:44:33 +0530 | [diff] [blame] | 56 | unsigned int alarm_low_mv; |
| 57 | unsigned int alarm_high_mv; |
Abhijeet Dharmapurikar | e88f246 | 2012-04-25 18:22:38 -0700 | [diff] [blame] | 58 | int enable_fcc_learning; |
Abhijeet Dharmapurikar | 602dc27 | 2012-07-19 21:34:56 -0700 | [diff] [blame] | 59 | int shutdown_soc_valid_limit; |
Abhijeet Dharmapurikar | 1f4cc51 | 2012-07-21 00:10:39 -0700 | [diff] [blame] | 60 | int ignore_shutdown_soc; |
Abhijeet Dharmapurikar | 720b00e | 2012-08-01 21:33:09 -0700 | [diff] [blame] | 61 | int adjust_soc_low_threshold; |
Abhijeet Dharmapurikar | d6d66c7 | 2012-08-06 14:02:51 -0700 | [diff] [blame] | 62 | int chg_term_ua; |
Abhijeet Dharmapurikar | 683472d | 2012-10-30 16:21:58 -0700 | [diff] [blame] | 63 | int normal_voltage_calc_ms; |
| 64 | int low_voltage_calc_ms; |
Abhijeet Dharmapurikar | 1939ede | 2013-01-10 15:59:33 -0800 | [diff] [blame] | 65 | int disable_flat_portion_ocv; |
| 66 | int ocv_dis_high_soc; |
| 67 | int ocv_dis_low_soc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #if defined(CONFIG_PM8921_BMS) || defined(CONFIG_PM8921_BMS_MODULE) |
Abhijeet Dharmapurikar | 2fb6f08 | 2011-06-28 17:10:27 -0700 | [diff] [blame] | 71 | /** |
| 72 | * pm8921_bms_get_vsense_avg - return the voltage across the sense |
| 73 | * resitor in microvolts |
Abhijeet Dharmapurikar | e0c3e5f | 2011-07-11 21:17:23 -0700 | [diff] [blame] | 74 | * @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 Dharmapurikar | 2fb6f08 | 2011-06-28 17:10:27 -0700 | [diff] [blame] | 77 | * |
| 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 Dharmapurikar | e0c3e5f | 2011-07-11 21:17:23 -0700 | [diff] [blame] | 80 | * |
| 81 | * |
Abhijeet Dharmapurikar | 2fb6f08 | 2011-06-28 17:10:27 -0700 | [diff] [blame] | 82 | */ |
| 83 | int pm8921_bms_get_vsense_avg(int *result); |
Abhijeet Dharmapurikar | 52344ac | 2011-07-05 18:44:54 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
Abhijeet Dharmapurikar | e0c3e5f | 2011-07-11 21:17:23 -0700 | [diff] [blame] | 86 | * pm8921_bms_get_battery_current - return the battery current based on vsense |
Siddartha Mohanadoss | 37e6fc0 | 2011-11-16 16:57:03 -0800 | [diff] [blame] | 87 | * resitor in microamperes |
Abhijeet Dharmapurikar | e0c3e5f | 2011-07-11 21:17:23 -0700 | [diff] [blame] | 88 | * @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 | */ |
| 96 | int pm8921_bms_get_battery_current(int *result); |
| 97 | |
| 98 | /** |
Abhijeet Dharmapurikar | 52344ac | 2011-07-05 18:44:54 -0700 | [diff] [blame] | 99 | * pm8921_bms_get_percent_charge - returns the current battery charge in percent |
| 100 | * |
| 101 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 102 | int pm8921_bms_get_percent_charge(void); |
Abhijeet Dharmapurikar | 325bdc9 | 2011-09-07 20:45:49 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * pm8921_bms_get_fcc - returns fcc in mAh of the battery depending on its age |
| 106 | * and temperature |
| 107 | * |
| 108 | */ |
| 109 | int pm8921_bms_get_fcc(void); |
| 110 | |
Abhijeet Dharmapurikar | 52344ac | 2011-07-05 18:44:54 -0700 | [diff] [blame] | 111 | /** |
| 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 Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 116 | void pm8921_bms_charging_began(void); |
Abhijeet Dharmapurikar | 52344ac | 2011-07-05 18:44:54 -0700 | [diff] [blame] | 117 | /** |
| 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 Dharmapurikar | fad7235 | 2011-09-25 23:06:05 -0700 | [diff] [blame] | 122 | void pm8921_bms_charging_end(int is_battery_full); |
Abhijeet Dharmapurikar | 1b8e829 | 2012-01-17 11:01:44 -0800 | [diff] [blame] | 123 | |
| 124 | void pm8921_bms_calibrate_hkadc(void); |
Abhijeet Dharmapurikar | c9857ca | 2012-02-07 15:56:06 -0800 | [diff] [blame] | 125 | /** |
| 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 | */ |
| 131 | int pm8921_bms_get_simultaneous_battery_voltage_and_current(int *ibat_ua, |
| 132 | int *vbat_uv); |
Abhijeet Dharmapurikar | f6fdcaa0 | 2012-02-27 00:10:10 -0800 | [diff] [blame] | 133 | /** |
Abhijeet Dharmapurikar | eca7b3e | 2012-12-26 21:30:29 -0800 | [diff] [blame] | 134 | * 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 Dharmapurikar | f6fdcaa0 | 2012-02-27 00:10:10 -0800 | [diff] [blame] | 137 | */ |
Abhijeet Dharmapurikar | eca7b3e | 2012-12-26 21:30:29 -0800 | [diff] [blame] | 138 | int pm8921_bms_get_current_max(void); |
Abhijeet Dharmapurikar | ed2d87e | 2012-06-26 20:15:36 -0700 | [diff] [blame] | 139 | /** |
| 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 | */ |
| 145 | void pm8921_bms_invalidate_shutdown_soc(void); |
Abhijeet Dharmapurikar | 4c78f46 | 2012-10-16 15:43:55 -0700 | [diff] [blame] | 146 | |
| 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 | */ |
| 154 | int pm8921_bms_cc_uah(int *cc_uah); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 155 | #else |
Abhijeet Dharmapurikar | 2fb6f08 | 2011-06-28 17:10:27 -0700 | [diff] [blame] | 156 | static inline int pm8921_bms_get_vsense_avg(int *result) |
| 157 | { |
| 158 | return -ENXIO; |
| 159 | } |
Abhijeet Dharmapurikar | e0c3e5f | 2011-07-11 21:17:23 -0700 | [diff] [blame] | 160 | static inline int pm8921_bms_get_battery_current(int *result) |
| 161 | { |
| 162 | return -ENXIO; |
| 163 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 164 | static inline int pm8921_bms_get_percent_charge(void) |
| 165 | { |
| 166 | return -ENXIO; |
| 167 | } |
Abhijeet Dharmapurikar | 325bdc9 | 2011-09-07 20:45:49 -0700 | [diff] [blame] | 168 | static inline int pm8921_bms_get_fcc(void) |
| 169 | { |
| 170 | return -ENXIO; |
| 171 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 172 | static inline void pm8921_bms_charging_began(void) |
| 173 | { |
| 174 | } |
Abhijeet Dharmapurikar | fad7235 | 2011-09-25 23:06:05 -0700 | [diff] [blame] | 175 | static inline void pm8921_bms_charging_end(int is_battery_full) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 176 | { |
| 177 | } |
Abhijeet Dharmapurikar | 1b8e829 | 2012-01-17 11:01:44 -0800 | [diff] [blame] | 178 | static inline void pm8921_bms_calibrate_hkadc(void) |
| 179 | { |
| 180 | } |
Abhijeet Dharmapurikar | c9857ca | 2012-02-07 15:56:06 -0800 | [diff] [blame] | 181 | static inline int pm8921_bms_get_simultaneous_battery_voltage_and_current( |
| 182 | int *ibat_ua, int *vbat_uv) |
| 183 | { |
| 184 | return -ENXIO; |
| 185 | } |
Abhijeet Dharmapurikar | f6fdcaa0 | 2012-02-27 00:10:10 -0800 | [diff] [blame] | 186 | static inline int pm8921_bms_get_rbatt(void) |
| 187 | { |
| 188 | return -EINVAL; |
| 189 | } |
Abhijeet Dharmapurikar | ed2d87e | 2012-06-26 20:15:36 -0700 | [diff] [blame] | 190 | static inline void pm8921_bms_invalidate_shutdown_soc(void) |
| 191 | { |
| 192 | } |
Abhijeet Dharmapurikar | 4c78f46 | 2012-10-16 15:43:55 -0700 | [diff] [blame] | 193 | static inline int pm8921_bms_cc_uah(int *cc_uah) |
| 194 | { |
| 195 | return -ENXIO; |
| 196 | } |
Abhijeet Dharmapurikar | eca7b3e | 2012-12-26 21:30:29 -0800 | [diff] [blame] | 197 | static inline int pm8921_bms_get_current_max(void) |
| 198 | { |
| 199 | return -ENXIO; |
| 200 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 201 | #endif |
| 202 | |
| 203 | #endif |