blob: ff38eb6f8d6268e8efcb6fc8c3c8afea59287f66 [file] [log] [blame]
Xiaozhe Shi77a5b052012-12-14 16:37:45 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Xiaozhe Shi5ee95192012-09-12 15:16:34 -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
Xiaozhe Shi7ef86d92013-06-13 10:58:21 -070013#ifndef __BMS_BATTERYDATA_H
14#define __BMS_BATTERYDATA_H
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070015
16#include <linux/errno.h>
17
18#define FCC_CC_COLS 5
19#define FCC_TEMP_COLS 8
20
Wu Fenglin2ac88aa2013-04-25 12:43:40 +080021#define PC_CC_ROWS 31
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070022#define PC_CC_COLS 13
23
Wu Fenglin2ac88aa2013-04-25 12:43:40 +080024#define PC_TEMP_ROWS 31
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070025#define PC_TEMP_COLS 8
26
27#define MAX_SINGLE_LUT_COLS 20
28
Xu Kai32c6bd02013-08-20 18:03:46 +080029#define MAX_BATT_ID_NUM 4
30
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070031struct single_row_lut {
32 int x[MAX_SINGLE_LUT_COLS];
33 int y[MAX_SINGLE_LUT_COLS];
34 int cols;
35};
36
37/**
38 * struct sf_lut -
39 * @rows: number of percent charge entries should be <= PC_CC_ROWS
40 * @cols: number of charge cycle entries should be <= PC_CC_COLS
41 * @row_entries: the charge cycles/temperature at which sf data
42 * is available in the table.
43 * The charge cycles must be in increasing order from 0 to rows.
44 * @percent: the percent charge at which sf data is available in the table
45 * The percentcharge must be in decreasing order from 0 to cols.
46 * @sf: the scaling factor data
47 */
48struct sf_lut {
49 int rows;
50 int cols;
51 int row_entries[PC_CC_COLS];
52 int percent[PC_CC_ROWS];
53 int sf[PC_CC_ROWS][PC_CC_COLS];
54};
55
56/**
57 * struct pc_temp_ocv_lut -
58 * @rows: number of percent charge entries should be <= PC_TEMP_ROWS
59 * @cols: number of temperature entries should be <= PC_TEMP_COLS
60 * @temp: the temperatures at which ocv data is available in the table
61 * The temperatures must be in increasing order from 0 to rows.
62 * @percent: the percent charge at which ocv data is available in the table
63 * The percentcharge must be in decreasing order from 0 to cols.
64 * @ocv: the open circuit voltage
65 */
66struct pc_temp_ocv_lut {
67 int rows;
68 int cols;
69 int temp[PC_TEMP_COLS];
70 int percent[PC_TEMP_ROWS];
71 int ocv[PC_TEMP_ROWS][PC_TEMP_COLS];
72};
73
Xu Kai32c6bd02013-08-20 18:03:46 +080074struct batt_ids {
75 int kohm[MAX_BATT_ID_NUM];
76 int num;
77};
78
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070079enum battery_type {
80 BATT_UNKNOWN = 0,
81 BATT_PALLADIUM,
82 BATT_DESAY,
Xiaozhe Shi77a5b052012-12-14 16:37:45 -080083 BATT_OEM,
Wu Fenglin2ac88aa2013-04-25 12:43:40 +080084 BATT_QRD_4V35_2000MAH,
tingtingf50326f2013-06-05 15:07:24 +080085 BATT_QRD_4V2_1300MAH,
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070086};
87
88/**
89 * struct bms_battery_data -
90 * @fcc: full charge capacity (mAmpHour)
91 * @fcc_temp_lut: table to get fcc at a given temp
92 * @pc_temp_ocv_lut: table to get percent charge given batt temp and cycles
93 * @pc_sf_lut: table to get percent charge scaling factor given cycles
94 * and percent charge
95 * @rbatt_sf_lut: table to get battery resistance scaling factor given
96 * temperature and percent charge
97 * @default_rbatt_mohm: the default value of battery resistance to use when
98 * readings from bms are not available.
99 * @delta_rbatt_mohm: the resistance to be added towards lower soc to
100 * compensate for battery capacitance.
Abhijeet Dharmapurikar03c6c232013-02-13 17:57:40 -0800101 * @rbatt_capacitve_mohm: the resistance to be added to compensate for
102 * battery capacitance
Xiaozhe Shi0ac7a002013-03-26 13:14:03 -0700103 * @flat_ocv_threshold_uv: the voltage where the battery's discharge curve
104 * starts flattening out.
Xiaozhe Shi7ef86d92013-06-13 10:58:21 -0700105 * @max_voltage_uv: max voltage of the battery
106 * @cutoff_uv: cutoff voltage of the battery
107 * @iterm_ua: termination current of the battery when charging
108 * to 100%
Xu Kai32c6bd02013-08-20 18:03:46 +0800109 * @batt_id_kohm: the best matched battery id resistor value
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700110 */
111
112struct bms_battery_data {
113 unsigned int fcc;
114 struct single_row_lut *fcc_temp_lut;
115 struct single_row_lut *fcc_sf_lut;
116 struct pc_temp_ocv_lut *pc_temp_ocv_lut;
117 struct sf_lut *pc_sf_lut;
118 struct sf_lut *rbatt_sf_lut;
119 int default_rbatt_mohm;
120 int delta_rbatt_mohm;
Abhijeet Dharmapurikar03c6c232013-02-13 17:57:40 -0800121 int rbatt_capacitive_mohm;
Xiaozhe Shi0ac7a002013-03-26 13:14:03 -0700122 int flat_ocv_threshold_uv;
Xiaozhe Shi7ef86d92013-06-13 10:58:21 -0700123 int max_voltage_uv;
124 int cutoff_uv;
125 int iterm_ua;
126 int batt_id_kohm;
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700127};
128
129#if defined(CONFIG_PM8921_BMS) || \
Xiaozhe Shi73a65692012-09-18 17:51:57 -0700130 defined(CONFIG_PM8921_BMS_MODULE) || \
131 defined(CONFIG_QPNP_BMS)
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700132extern struct bms_battery_data palladium_1500_data;
133extern struct bms_battery_data desay_5200_data;
Xiaozhe Shi77a5b052012-12-14 16:37:45 -0800134extern struct bms_battery_data oem_batt_data;
Wu Fenglin2ac88aa2013-04-25 12:43:40 +0800135extern struct bms_battery_data QRD_4v35_2000mAh_data;
tingtingf50326f2013-06-05 15:07:24 +0800136extern struct bms_battery_data qrd_4v2_1300mah_data;
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700137
138int interpolate_fcc(struct single_row_lut *fcc_temp_lut, int batt_temp);
139int interpolate_scalingfactor(struct sf_lut *sf_lut, int row_entry, int pc);
140int interpolate_scalingfactor_fcc(struct single_row_lut *fcc_sf_lut,
141 int cycles);
142int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
143 int batt_temp_degc, int ocv);
144int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
145 int batt_temp_degc, int pc);
146int linear_interpolate(int y0, int x0, int y1, int x1, int x);
147int is_between(int left, int right, int value);
148#else
149static inline int interpolate_fcc(struct single_row_lut *fcc_temp_lut,
150 int batt_temp)
151{
152 return -EINVAL;
153}
154static inline int interpolate_scalingfactor(struct sf_lut *sf_lut,
155 int row_entry, int pc)
156{
157 return -EINVAL;
158}
159static inline int interpolate_scalingfactor_fcc(
160 struct single_row_lut *fcc_sf_lut, int cycles)
161{
162 return -EINVAL;
163}
164static inline int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
165 int batt_temp_degc, int ocv)
166{
167 return -EINVAL;
168}
169static inline int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
170 int batt_temp_degc, int pc)
171{
172 return -EINVAL;
173}
174static inline int linear_interpolate(int y0, int x0, int y1, int x1, int x)
175{
176 return -EINVAL;
177}
178static inline int is_between(int left, int right, int value)
179{
180 return -EINVAL;
181}
182#endif
183
184#endif