Xiaozhe Shi | 77a5b05 | 2012-12-14 16:37:45 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -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 | |
Xiaozhe Shi | 7ef86d9 | 2013-06-13 10:58:21 -0700 | [diff] [blame] | 13 | #ifndef __BMS_BATTERYDATA_H |
| 14 | #define __BMS_BATTERYDATA_H |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 15 | |
| 16 | #include <linux/errno.h> |
| 17 | |
| 18 | #define FCC_CC_COLS 5 |
| 19 | #define FCC_TEMP_COLS 8 |
| 20 | |
Wu Fenglin | 2ac88aa | 2013-04-25 12:43:40 +0800 | [diff] [blame] | 21 | #define PC_CC_ROWS 31 |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 22 | #define PC_CC_COLS 13 |
| 23 | |
Wu Fenglin | 2ac88aa | 2013-04-25 12:43:40 +0800 | [diff] [blame] | 24 | #define PC_TEMP_ROWS 31 |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 25 | #define PC_TEMP_COLS 8 |
| 26 | |
| 27 | #define MAX_SINGLE_LUT_COLS 20 |
| 28 | |
| 29 | struct single_row_lut { |
| 30 | int x[MAX_SINGLE_LUT_COLS]; |
| 31 | int y[MAX_SINGLE_LUT_COLS]; |
| 32 | int cols; |
| 33 | }; |
| 34 | |
| 35 | /** |
| 36 | * struct sf_lut - |
| 37 | * @rows: number of percent charge entries should be <= PC_CC_ROWS |
| 38 | * @cols: number of charge cycle entries should be <= PC_CC_COLS |
| 39 | * @row_entries: the charge cycles/temperature at which sf data |
| 40 | * is available in the table. |
| 41 | * The charge cycles must be in increasing order from 0 to rows. |
| 42 | * @percent: the percent charge at which sf data is available in the table |
| 43 | * The percentcharge must be in decreasing order from 0 to cols. |
| 44 | * @sf: the scaling factor data |
| 45 | */ |
| 46 | struct sf_lut { |
| 47 | int rows; |
| 48 | int cols; |
| 49 | int row_entries[PC_CC_COLS]; |
| 50 | int percent[PC_CC_ROWS]; |
| 51 | int sf[PC_CC_ROWS][PC_CC_COLS]; |
| 52 | }; |
| 53 | |
| 54 | /** |
| 55 | * struct pc_temp_ocv_lut - |
| 56 | * @rows: number of percent charge entries should be <= PC_TEMP_ROWS |
| 57 | * @cols: number of temperature entries should be <= PC_TEMP_COLS |
| 58 | * @temp: the temperatures at which ocv data is available in the table |
| 59 | * The temperatures must be in increasing order from 0 to rows. |
| 60 | * @percent: the percent charge at which ocv data is available in the table |
| 61 | * The percentcharge must be in decreasing order from 0 to cols. |
| 62 | * @ocv: the open circuit voltage |
| 63 | */ |
| 64 | struct pc_temp_ocv_lut { |
| 65 | int rows; |
| 66 | int cols; |
| 67 | int temp[PC_TEMP_COLS]; |
| 68 | int percent[PC_TEMP_ROWS]; |
| 69 | int ocv[PC_TEMP_ROWS][PC_TEMP_COLS]; |
| 70 | }; |
| 71 | |
| 72 | enum battery_type { |
| 73 | BATT_UNKNOWN = 0, |
| 74 | BATT_PALLADIUM, |
| 75 | BATT_DESAY, |
Xiaozhe Shi | 77a5b05 | 2012-12-14 16:37:45 -0800 | [diff] [blame] | 76 | BATT_OEM, |
Wu Fenglin | 2ac88aa | 2013-04-25 12:43:40 +0800 | [diff] [blame] | 77 | BATT_QRD_4V35_2000MAH, |
tingting | f50326f | 2013-06-05 15:07:24 +0800 | [diff] [blame] | 78 | BATT_QRD_4V2_1300MAH, |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * struct bms_battery_data - |
| 83 | * @fcc: full charge capacity (mAmpHour) |
| 84 | * @fcc_temp_lut: table to get fcc at a given temp |
| 85 | * @pc_temp_ocv_lut: table to get percent charge given batt temp and cycles |
| 86 | * @pc_sf_lut: table to get percent charge scaling factor given cycles |
| 87 | * and percent charge |
| 88 | * @rbatt_sf_lut: table to get battery resistance scaling factor given |
| 89 | * temperature and percent charge |
| 90 | * @default_rbatt_mohm: the default value of battery resistance to use when |
| 91 | * readings from bms are not available. |
| 92 | * @delta_rbatt_mohm: the resistance to be added towards lower soc to |
| 93 | * compensate for battery capacitance. |
Abhijeet Dharmapurikar | 03c6c23 | 2013-02-13 17:57:40 -0800 | [diff] [blame] | 94 | * @rbatt_capacitve_mohm: the resistance to be added to compensate for |
| 95 | * battery capacitance |
Xiaozhe Shi | 0ac7a00 | 2013-03-26 13:14:03 -0700 | [diff] [blame] | 96 | * @flat_ocv_threshold_uv: the voltage where the battery's discharge curve |
| 97 | * starts flattening out. |
Xiaozhe Shi | 7ef86d9 | 2013-06-13 10:58:21 -0700 | [diff] [blame] | 98 | * @max_voltage_uv: max voltage of the battery |
| 99 | * @cutoff_uv: cutoff voltage of the battery |
| 100 | * @iterm_ua: termination current of the battery when charging |
| 101 | * to 100% |
| 102 | * @batt_id_kohm: battery id resistor value |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 103 | */ |
| 104 | |
| 105 | struct bms_battery_data { |
| 106 | unsigned int fcc; |
| 107 | struct single_row_lut *fcc_temp_lut; |
| 108 | struct single_row_lut *fcc_sf_lut; |
| 109 | struct pc_temp_ocv_lut *pc_temp_ocv_lut; |
| 110 | struct sf_lut *pc_sf_lut; |
| 111 | struct sf_lut *rbatt_sf_lut; |
| 112 | int default_rbatt_mohm; |
| 113 | int delta_rbatt_mohm; |
Abhijeet Dharmapurikar | 03c6c23 | 2013-02-13 17:57:40 -0800 | [diff] [blame] | 114 | int rbatt_capacitive_mohm; |
Xiaozhe Shi | 0ac7a00 | 2013-03-26 13:14:03 -0700 | [diff] [blame] | 115 | int flat_ocv_threshold_uv; |
Xiaozhe Shi | 7ef86d9 | 2013-06-13 10:58:21 -0700 | [diff] [blame] | 116 | int max_voltage_uv; |
| 117 | int cutoff_uv; |
| 118 | int iterm_ua; |
| 119 | int batt_id_kohm; |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | #if defined(CONFIG_PM8921_BMS) || \ |
Xiaozhe Shi | 73a6569 | 2012-09-18 17:51:57 -0700 | [diff] [blame] | 123 | defined(CONFIG_PM8921_BMS_MODULE) || \ |
| 124 | defined(CONFIG_QPNP_BMS) |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 125 | extern struct bms_battery_data palladium_1500_data; |
| 126 | extern struct bms_battery_data desay_5200_data; |
Xiaozhe Shi | 77a5b05 | 2012-12-14 16:37:45 -0800 | [diff] [blame] | 127 | extern struct bms_battery_data oem_batt_data; |
Wu Fenglin | 2ac88aa | 2013-04-25 12:43:40 +0800 | [diff] [blame] | 128 | extern struct bms_battery_data QRD_4v35_2000mAh_data; |
tingting | f50326f | 2013-06-05 15:07:24 +0800 | [diff] [blame] | 129 | extern struct bms_battery_data qrd_4v2_1300mah_data; |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 130 | |
| 131 | int interpolate_fcc(struct single_row_lut *fcc_temp_lut, int batt_temp); |
| 132 | int interpolate_scalingfactor(struct sf_lut *sf_lut, int row_entry, int pc); |
| 133 | int interpolate_scalingfactor_fcc(struct single_row_lut *fcc_sf_lut, |
| 134 | int cycles); |
| 135 | int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 136 | int batt_temp_degc, int ocv); |
| 137 | int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 138 | int batt_temp_degc, int pc); |
| 139 | int linear_interpolate(int y0, int x0, int y1, int x1, int x); |
| 140 | int is_between(int left, int right, int value); |
| 141 | #else |
| 142 | static inline int interpolate_fcc(struct single_row_lut *fcc_temp_lut, |
| 143 | int batt_temp) |
| 144 | { |
| 145 | return -EINVAL; |
| 146 | } |
| 147 | static inline int interpolate_scalingfactor(struct sf_lut *sf_lut, |
| 148 | int row_entry, int pc) |
| 149 | { |
| 150 | return -EINVAL; |
| 151 | } |
| 152 | static inline int interpolate_scalingfactor_fcc( |
| 153 | struct single_row_lut *fcc_sf_lut, int cycles) |
| 154 | { |
| 155 | return -EINVAL; |
| 156 | } |
| 157 | static inline int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 158 | int batt_temp_degc, int ocv) |
| 159 | { |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | static inline int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 163 | int batt_temp_degc, int pc) |
| 164 | { |
| 165 | return -EINVAL; |
| 166 | } |
| 167 | static inline int linear_interpolate(int y0, int x0, int y1, int x1, int x) |
| 168 | { |
| 169 | return -EINVAL; |
| 170 | } |
| 171 | static inline int is_between(int left, int right, int value) |
| 172 | { |
| 173 | return -EINVAL; |
| 174 | } |
| 175 | #endif |
| 176 | |
| 177 | #endif |