blob: fe2d86f73a7f1042f01b29f4ebee654aa6c85a49 [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
29struct 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 */
46struct 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 */
64struct 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
72enum battery_type {
73 BATT_UNKNOWN = 0,
74 BATT_PALLADIUM,
75 BATT_DESAY,
Xiaozhe Shi77a5b052012-12-14 16:37:45 -080076 BATT_OEM,
Wu Fenglin2ac88aa2013-04-25 12:43:40 +080077 BATT_QRD_4V35_2000MAH,
tingtingf50326f2013-06-05 15:07:24 +080078 BATT_QRD_4V2_1300MAH,
Xiaozhe Shi5ee95192012-09-12 15:16:34 -070079};
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 Dharmapurikar03c6c232013-02-13 17:57:40 -080094 * @rbatt_capacitve_mohm: the resistance to be added to compensate for
95 * battery capacitance
Xiaozhe Shi0ac7a002013-03-26 13:14:03 -070096 * @flat_ocv_threshold_uv: the voltage where the battery's discharge curve
97 * starts flattening out.
Xiaozhe Shi7ef86d92013-06-13 10:58:21 -070098 * @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 Shi5ee95192012-09-12 15:16:34 -0700103 */
104
105struct 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 Dharmapurikar03c6c232013-02-13 17:57:40 -0800114 int rbatt_capacitive_mohm;
Xiaozhe Shi0ac7a002013-03-26 13:14:03 -0700115 int flat_ocv_threshold_uv;
Xiaozhe Shi7ef86d92013-06-13 10:58:21 -0700116 int max_voltage_uv;
117 int cutoff_uv;
118 int iterm_ua;
119 int batt_id_kohm;
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700120};
121
122#if defined(CONFIG_PM8921_BMS) || \
Xiaozhe Shi73a65692012-09-18 17:51:57 -0700123 defined(CONFIG_PM8921_BMS_MODULE) || \
124 defined(CONFIG_QPNP_BMS)
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700125extern struct bms_battery_data palladium_1500_data;
126extern struct bms_battery_data desay_5200_data;
Xiaozhe Shi77a5b052012-12-14 16:37:45 -0800127extern struct bms_battery_data oem_batt_data;
Wu Fenglin2ac88aa2013-04-25 12:43:40 +0800128extern struct bms_battery_data QRD_4v35_2000mAh_data;
tingtingf50326f2013-06-05 15:07:24 +0800129extern struct bms_battery_data qrd_4v2_1300mah_data;
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700130
131int interpolate_fcc(struct single_row_lut *fcc_temp_lut, int batt_temp);
132int interpolate_scalingfactor(struct sf_lut *sf_lut, int row_entry, int pc);
133int interpolate_scalingfactor_fcc(struct single_row_lut *fcc_sf_lut,
134 int cycles);
135int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
136 int batt_temp_degc, int ocv);
137int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
138 int batt_temp_degc, int pc);
139int linear_interpolate(int y0, int x0, int y1, int x1, int x);
140int is_between(int left, int right, int value);
141#else
142static inline int interpolate_fcc(struct single_row_lut *fcc_temp_lut,
143 int batt_temp)
144{
145 return -EINVAL;
146}
147static inline int interpolate_scalingfactor(struct sf_lut *sf_lut,
148 int row_entry, int pc)
149{
150 return -EINVAL;
151}
152static inline int interpolate_scalingfactor_fcc(
153 struct single_row_lut *fcc_sf_lut, int cycles)
154{
155 return -EINVAL;
156}
157static inline int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
158 int batt_temp_degc, int ocv)
159{
160 return -EINVAL;
161}
162static inline int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
163 int batt_temp_degc, int pc)
164{
165 return -EINVAL;
166}
167static inline int linear_interpolate(int y0, int x0, int y1, int x1, int x)
168{
169 return -EINVAL;
170}
171static inline int is_between(int left, int right, int value)
172{
173 return -EINVAL;
174}
175#endif
176
177#endif