1 /* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
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.
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.
13 #ifndef __BMS_BATTERYDATA_H
14 #define __BMS_BATTERYDATA_H
16 #include <linux/errno.h>
19 #define FCC_TEMP_COLS 8
24 #define PC_TEMP_ROWS 31
25 #define PC_TEMP_COLS 8
27 #define ACC_IBAT_ROWS 4
28 #define ACC_TEMP_COLS 3
30 #define MAX_SINGLE_LUT_COLS 20
32 #define MAX_BATT_ID_NUM 4
35 struct single_row_lut {
36 int x[MAX_SINGLE_LUT_COLS];
37 int y[MAX_SINGLE_LUT_COLS];
43 * @rows: number of percent charge entries should be <= PC_CC_ROWS
44 * @cols: number of charge cycle entries should be <= PC_CC_COLS
45 * @row_entries: the charge cycles/temperature at which sf data
46 * is available in the table.
47 * The charge cycles must be in increasing order from 0 to rows.
48 * @percent: the percent charge at which sf data is available in the table
49 * The percentcharge must be in decreasing order from 0 to cols.
50 * @sf: the scaling factor data
55 int row_entries[PC_CC_COLS];
56 int percent[PC_CC_ROWS];
57 int sf[PC_CC_ROWS][PC_CC_COLS];
61 * struct pc_temp_ocv_lut -
62 * @rows: number of percent charge entries should be <= PC_TEMP_ROWS
63 * @cols: number of temperature entries should be <= PC_TEMP_COLS
64 * @temp: the temperatures at which ocv data is available in the table
65 * The temperatures must be in increasing order from 0 to rows.
66 * @percent: the percent charge at which ocv data is available in the table
67 * The percentcharge must be in decreasing order from 0 to cols.
68 * @ocv: the open circuit voltage
70 struct pc_temp_ocv_lut {
73 int temp[PC_TEMP_COLS];
74 int percent[PC_TEMP_ROWS];
75 int ocv[PC_TEMP_ROWS][PC_TEMP_COLS];
78 struct ibat_temp_acc_lut {
81 int temp[ACC_TEMP_COLS];
82 int ibat[ACC_IBAT_ROWS];
83 int acc[ACC_IBAT_ROWS][ACC_TEMP_COLS];
87 int kohm[MAX_BATT_ID_NUM];
96 BATT_QRD_4V35_2000MAH,
101 * struct bms_battery_data -
102 * @fcc: full charge capacity (mAmpHour)
103 * @fcc_temp_lut: table to get fcc at a given temp
104 * @pc_temp_ocv_lut: table to get percent charge given batt temp and cycles
105 * @pc_sf_lut: table to get percent charge scaling factor given cycles
107 * @rbatt_sf_lut: table to get battery resistance scaling factor given
108 * temperature and percent charge
109 * @default_rbatt_mohm: the default value of battery resistance to use when
110 * readings from bms are not available.
111 * @delta_rbatt_mohm: the resistance to be added towards lower soc to
112 * compensate for battery capacitance.
113 * @rbatt_capacitve_mohm: the resistance to be added to compensate for
114 * battery capacitance
115 * @flat_ocv_threshold_uv: the voltage where the battery's discharge curve
116 * starts flattening out.
117 * @max_voltage_uv: max voltage of the battery
118 * @cutoff_uv: cutoff voltage of the battery
119 * @iterm_ua: termination current of the battery when charging
121 * @batt_id_kohm: the best matched battery id resistor value
122 * @fastchg_current_ma: maximum fast charge current
123 * @fg_cc_cv_threshold_mv: CC to CV threashold voltage
126 struct bms_battery_data {
128 struct single_row_lut *fcc_temp_lut;
129 struct single_row_lut *fcc_sf_lut;
130 struct pc_temp_ocv_lut *pc_temp_ocv_lut;
131 struct ibat_temp_acc_lut *ibat_acc_lut;
132 struct sf_lut *pc_sf_lut;
133 struct sf_lut *rbatt_sf_lut;
134 int default_rbatt_mohm;
135 int delta_rbatt_mohm;
136 int rbatt_capacitive_mohm;
137 int flat_ocv_threshold_uv;
142 int fastchg_current_ma;
143 int fg_cc_cv_threshold_mv;
144 const char *battery_type;
147 #define is_between(left, right, value) \
148 (((left) >= (right) && (left) >= (value) \
149 && (value) >= (right)) \
150 || ((left) <= (right) && (left) <= (value) \
151 && (value) <= (right)))
153 extern struct bms_battery_data palladium_1500_data;
154 extern struct bms_battery_data desay_5200_data;
155 extern struct bms_battery_data oem_batt_data;
156 extern struct bms_battery_data QRD_4v35_2000mAh_data;
157 extern struct bms_battery_data qrd_4v2_1300mah_data;
159 int interpolate_fcc(struct single_row_lut *fcc_temp_lut, int batt_temp);
160 int interpolate_scalingfactor(struct sf_lut *sf_lut, int row_entry, int pc);
161 int interpolate_scalingfactor_fcc(struct single_row_lut *fcc_sf_lut,
163 int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
164 int batt_temp_degc, int ocv);
165 int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
166 int batt_temp_degc, int pc);
167 int interpolate_slope(struct pc_temp_ocv_lut *pc_temp_ocv,
168 int batt_temp, int pc);
169 int interpolate_acc(struct ibat_temp_acc_lut *ibat_acc_lut,
170 int batt_temp, int ibat);
171 int linear_interpolate(int y0, int x0, int y1, int x1, int x);