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 | |
| 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 | |
| 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, |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * struct bms_battery_data - |
| 81 | * @fcc: full charge capacity (mAmpHour) |
| 82 | * @fcc_temp_lut: table to get fcc at a given temp |
| 83 | * @pc_temp_ocv_lut: table to get percent charge given batt temp and cycles |
| 84 | * @pc_sf_lut: table to get percent charge scaling factor given cycles |
| 85 | * and percent charge |
| 86 | * @rbatt_sf_lut: table to get battery resistance scaling factor given |
| 87 | * temperature and percent charge |
| 88 | * @default_rbatt_mohm: the default value of battery resistance to use when |
| 89 | * readings from bms are not available. |
| 90 | * @delta_rbatt_mohm: the resistance to be added towards lower soc to |
| 91 | * compensate for battery capacitance. |
Abhijeet Dharmapurikar | 03c6c23 | 2013-02-13 17:57:40 -0800 | [diff] [blame] | 92 | * @rbatt_capacitve_mohm: the resistance to be added to compensate for |
| 93 | * battery capacitance |
Xiaozhe Shi | 0ac7a00 | 2013-03-26 13:14:03 -0700 | [diff] [blame^] | 94 | * @flat_ocv_threshold_uv: the voltage where the battery's discharge curve |
| 95 | * starts flattening out. |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 96 | */ |
| 97 | |
| 98 | struct bms_battery_data { |
| 99 | unsigned int fcc; |
| 100 | struct single_row_lut *fcc_temp_lut; |
| 101 | struct single_row_lut *fcc_sf_lut; |
| 102 | struct pc_temp_ocv_lut *pc_temp_ocv_lut; |
| 103 | struct sf_lut *pc_sf_lut; |
| 104 | struct sf_lut *rbatt_sf_lut; |
| 105 | int default_rbatt_mohm; |
| 106 | int delta_rbatt_mohm; |
Abhijeet Dharmapurikar | 03c6c23 | 2013-02-13 17:57:40 -0800 | [diff] [blame] | 107 | int rbatt_capacitive_mohm; |
Xiaozhe Shi | 0ac7a00 | 2013-03-26 13:14:03 -0700 | [diff] [blame^] | 108 | int flat_ocv_threshold_uv; |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | #if defined(CONFIG_PM8921_BMS) || \ |
Xiaozhe Shi | 73a6569 | 2012-09-18 17:51:57 -0700 | [diff] [blame] | 112 | defined(CONFIG_PM8921_BMS_MODULE) || \ |
| 113 | defined(CONFIG_QPNP_BMS) |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 114 | extern struct bms_battery_data palladium_1500_data; |
| 115 | extern struct bms_battery_data desay_5200_data; |
Xiaozhe Shi | 77a5b05 | 2012-12-14 16:37:45 -0800 | [diff] [blame] | 116 | extern struct bms_battery_data oem_batt_data; |
Xiaozhe Shi | 5ee9519 | 2012-09-12 15:16:34 -0700 | [diff] [blame] | 117 | |
| 118 | int interpolate_fcc(struct single_row_lut *fcc_temp_lut, int batt_temp); |
| 119 | int interpolate_scalingfactor(struct sf_lut *sf_lut, int row_entry, int pc); |
| 120 | int interpolate_scalingfactor_fcc(struct single_row_lut *fcc_sf_lut, |
| 121 | int cycles); |
| 122 | int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 123 | int batt_temp_degc, int ocv); |
| 124 | int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 125 | int batt_temp_degc, int pc); |
| 126 | int linear_interpolate(int y0, int x0, int y1, int x1, int x); |
| 127 | int is_between(int left, int right, int value); |
| 128 | #else |
| 129 | static inline int interpolate_fcc(struct single_row_lut *fcc_temp_lut, |
| 130 | int batt_temp) |
| 131 | { |
| 132 | return -EINVAL; |
| 133 | } |
| 134 | static inline int interpolate_scalingfactor(struct sf_lut *sf_lut, |
| 135 | int row_entry, int pc) |
| 136 | { |
| 137 | return -EINVAL; |
| 138 | } |
| 139 | static inline int interpolate_scalingfactor_fcc( |
| 140 | struct single_row_lut *fcc_sf_lut, int cycles) |
| 141 | { |
| 142 | return -EINVAL; |
| 143 | } |
| 144 | static inline int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 145 | int batt_temp_degc, int ocv) |
| 146 | { |
| 147 | return -EINVAL; |
| 148 | } |
| 149 | static inline int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv, |
| 150 | int batt_temp_degc, int pc) |
| 151 | { |
| 152 | return -EINVAL; |
| 153 | } |
| 154 | static inline int linear_interpolate(int y0, int x0, int y1, int x1, int x) |
| 155 | { |
| 156 | return -EINVAL; |
| 157 | } |
| 158 | static inline int is_between(int left, int right, int value) |
| 159 | { |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | #endif |
| 163 | |
| 164 | #endif |