blob: afa18435d98adc6629682303c6a55ced84643af8 [file] [log] [blame]
Xiaozhe Shi5ee95192012-09-12 15:16:34 -07001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
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_BATTERYDATA_H
14#define __PM8XXX_BMS_BATTERYDATA_H
15
16#include <linux/errno.h>
17
18#define FCC_CC_COLS 5
19#define FCC_TEMP_COLS 8
20
21#define PC_CC_ROWS 29
22#define PC_CC_COLS 13
23
24#define PC_TEMP_ROWS 29
25#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,
76};
77
78/**
79 * struct bms_battery_data -
80 * @fcc: full charge capacity (mAmpHour)
81 * @fcc_temp_lut: table to get fcc at a given temp
82 * @pc_temp_ocv_lut: table to get percent charge given batt temp and cycles
83 * @pc_sf_lut: table to get percent charge scaling factor given cycles
84 * and percent charge
85 * @rbatt_sf_lut: table to get battery resistance scaling factor given
86 * temperature and percent charge
87 * @default_rbatt_mohm: the default value of battery resistance to use when
88 * readings from bms are not available.
89 * @delta_rbatt_mohm: the resistance to be added towards lower soc to
90 * compensate for battery capacitance.
91 */
92
93struct bms_battery_data {
94 unsigned int fcc;
95 struct single_row_lut *fcc_temp_lut;
96 struct single_row_lut *fcc_sf_lut;
97 struct pc_temp_ocv_lut *pc_temp_ocv_lut;
98 struct sf_lut *pc_sf_lut;
99 struct sf_lut *rbatt_sf_lut;
100 int default_rbatt_mohm;
101 int delta_rbatt_mohm;
102};
103
104#if defined(CONFIG_PM8921_BMS) || \
Xiaozhe Shi73a65692012-09-18 17:51:57 -0700105 defined(CONFIG_PM8921_BMS_MODULE) || \
106 defined(CONFIG_QPNP_BMS)
Xiaozhe Shi5ee95192012-09-12 15:16:34 -0700107extern struct bms_battery_data palladium_1500_data;
108extern struct bms_battery_data desay_5200_data;
109
110int interpolate_fcc(struct single_row_lut *fcc_temp_lut, int batt_temp);
111int interpolate_scalingfactor(struct sf_lut *sf_lut, int row_entry, int pc);
112int interpolate_scalingfactor_fcc(struct single_row_lut *fcc_sf_lut,
113 int cycles);
114int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
115 int batt_temp_degc, int ocv);
116int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
117 int batt_temp_degc, int pc);
118int linear_interpolate(int y0, int x0, int y1, int x1, int x);
119int is_between(int left, int right, int value);
120#else
121static inline int interpolate_fcc(struct single_row_lut *fcc_temp_lut,
122 int batt_temp)
123{
124 return -EINVAL;
125}
126static inline int interpolate_scalingfactor(struct sf_lut *sf_lut,
127 int row_entry, int pc)
128{
129 return -EINVAL;
130}
131static inline int interpolate_scalingfactor_fcc(
132 struct single_row_lut *fcc_sf_lut, int cycles)
133{
134 return -EINVAL;
135}
136static inline int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
137 int batt_temp_degc, int ocv)
138{
139 return -EINVAL;
140}
141static inline int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
142 int batt_temp_degc, int pc)
143{
144 return -EINVAL;
145}
146static inline int linear_interpolate(int y0, int x0, int y1, int x1, int x)
147{
148 return -EINVAL;
149}
150static inline int is_between(int left, int right, int value)
151{
152 return -EINVAL;
153}
154#endif
155
156#endif