batterydata-lib.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* Copyright (c) 2012-2013, 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. #ifndef __BMS_BATTERYDATA_H
  13. #define __BMS_BATTERYDATA_H
  14. #include <linux/errno.h>
  15. #define FCC_CC_COLS 5
  16. #define FCC_TEMP_COLS 8
  17. #define PC_CC_ROWS 31
  18. #define PC_CC_COLS 13
  19. #define PC_TEMP_ROWS 31
  20. #define PC_TEMP_COLS 8
  21. #define MAX_SINGLE_LUT_COLS 20
  22. #define MAX_BATT_ID_NUM 4
  23. #define DEGC_SCALE 10
  24. struct single_row_lut {
  25. int x[MAX_SINGLE_LUT_COLS];
  26. int y[MAX_SINGLE_LUT_COLS];
  27. int cols;
  28. };
  29. /**
  30. * struct sf_lut -
  31. * @rows: number of percent charge entries should be <= PC_CC_ROWS
  32. * @cols: number of charge cycle entries should be <= PC_CC_COLS
  33. * @row_entries: the charge cycles/temperature at which sf data
  34. * is available in the table.
  35. * The charge cycles must be in increasing order from 0 to rows.
  36. * @percent: the percent charge at which sf data is available in the table
  37. * The percentcharge must be in decreasing order from 0 to cols.
  38. * @sf: the scaling factor data
  39. */
  40. struct sf_lut {
  41. int rows;
  42. int cols;
  43. int row_entries[PC_CC_COLS];
  44. int percent[PC_CC_ROWS];
  45. int sf[PC_CC_ROWS][PC_CC_COLS];
  46. };
  47. /**
  48. * struct pc_temp_ocv_lut -
  49. * @rows: number of percent charge entries should be <= PC_TEMP_ROWS
  50. * @cols: number of temperature entries should be <= PC_TEMP_COLS
  51. * @temp: the temperatures at which ocv data is available in the table
  52. * The temperatures must be in increasing order from 0 to rows.
  53. * @percent: the percent charge at which ocv data is available in the table
  54. * The percentcharge must be in decreasing order from 0 to cols.
  55. * @ocv: the open circuit voltage
  56. */
  57. struct pc_temp_ocv_lut {
  58. int rows;
  59. int cols;
  60. int temp[PC_TEMP_COLS];
  61. int percent[PC_TEMP_ROWS];
  62. int ocv[PC_TEMP_ROWS][PC_TEMP_COLS];
  63. };
  64. struct batt_ids {
  65. int kohm[MAX_BATT_ID_NUM];
  66. int num;
  67. };
  68. enum battery_type {
  69. BATT_UNKNOWN = 0,
  70. BATT_PALLADIUM,
  71. BATT_DESAY,
  72. BATT_OEM,
  73. BATT_QRD_4V35_2000MAH,
  74. BATT_QRD_4V2_1300MAH,
  75. };
  76. /**
  77. * struct bms_battery_data -
  78. * @fcc: full charge capacity (mAmpHour)
  79. * @fcc_temp_lut: table to get fcc at a given temp
  80. * @pc_temp_ocv_lut: table to get percent charge given batt temp and cycles
  81. * @pc_sf_lut: table to get percent charge scaling factor given cycles
  82. * and percent charge
  83. * @rbatt_sf_lut: table to get battery resistance scaling factor given
  84. * temperature and percent charge
  85. * @default_rbatt_mohm: the default value of battery resistance to use when
  86. * readings from bms are not available.
  87. * @delta_rbatt_mohm: the resistance to be added towards lower soc to
  88. * compensate for battery capacitance.
  89. * @rbatt_capacitve_mohm: the resistance to be added to compensate for
  90. * battery capacitance
  91. * @flat_ocv_threshold_uv: the voltage where the battery's discharge curve
  92. * starts flattening out.
  93. * @max_voltage_uv: max voltage of the battery
  94. * @cutoff_uv: cutoff voltage of the battery
  95. * @iterm_ua: termination current of the battery when charging
  96. * to 100%
  97. * @batt_id_kohm: the best matched battery id resistor value
  98. */
  99. struct bms_battery_data {
  100. unsigned int fcc;
  101. struct single_row_lut *fcc_temp_lut;
  102. struct single_row_lut *fcc_sf_lut;
  103. struct pc_temp_ocv_lut *pc_temp_ocv_lut;
  104. struct sf_lut *pc_sf_lut;
  105. struct sf_lut *rbatt_sf_lut;
  106. int default_rbatt_mohm;
  107. int delta_rbatt_mohm;
  108. int rbatt_capacitive_mohm;
  109. int flat_ocv_threshold_uv;
  110. int max_voltage_uv;
  111. int cutoff_uv;
  112. int iterm_ua;
  113. int batt_id_kohm;
  114. };
  115. #if defined(CONFIG_PM8921_BMS) || \
  116. defined(CONFIG_PM8921_BMS_MODULE) || \
  117. defined(CONFIG_QPNP_BMS)
  118. extern struct bms_battery_data palladium_1500_data;
  119. extern struct bms_battery_data desay_5200_data;
  120. extern struct bms_battery_data oem_batt_data;
  121. extern struct bms_battery_data QRD_4v35_2000mAh_data;
  122. extern struct bms_battery_data qrd_4v2_1300mah_data;
  123. extern struct bms_battery_data samsung_4450mAH_data;
  124. extern struct bms_battery_data samsung_6800mAH_data;
  125. extern struct bms_battery_data samsung_2800mAH_data;
  126. extern struct bms_battery_data samsung_2100mAH_data;
  127. extern struct bms_battery_data samsung_2100mAH_4400mV_data;
  128. extern struct bms_battery_data samsung_2000mAH_data;
  129. extern struct bms_battery_data samsung_1720mAH_data;
  130. extern struct bms_battery_data samsung_2000mAH_victor_data;
  131. extern struct bms_battery_data samsung_lis_4450mAH_data;
  132. extern struct bms_battery_data samsung_8x26_2600mAh_data;
  133. int interpolate_fcc(struct single_row_lut *fcc_temp_lut, int batt_temp);
  134. int interpolate_scalingfactor(struct sf_lut *sf_lut, int row_entry, int pc);
  135. int interpolate_scalingfactor_fcc(struct single_row_lut *fcc_sf_lut,
  136. int cycles);
  137. int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
  138. int batt_temp_degc, int ocv);
  139. int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
  140. int batt_temp_degc, int pc);
  141. int linear_interpolate(int y0, int x0, int y1, int x1, int x);
  142. int is_between(int left, int right, int value);
  143. #else
  144. static inline int interpolate_fcc(struct single_row_lut *fcc_temp_lut,
  145. int batt_temp)
  146. {
  147. return -EINVAL;
  148. }
  149. static inline int interpolate_scalingfactor(struct sf_lut *sf_lut,
  150. int row_entry, int pc)
  151. {
  152. return -EINVAL;
  153. }
  154. static inline int interpolate_scalingfactor_fcc(
  155. struct single_row_lut *fcc_sf_lut, int cycles)
  156. {
  157. return -EINVAL;
  158. }
  159. static inline int interpolate_pc(struct pc_temp_ocv_lut *pc_temp_ocv,
  160. int batt_temp_degc, int ocv)
  161. {
  162. return -EINVAL;
  163. }
  164. static inline int interpolate_ocv(struct pc_temp_ocv_lut *pc_temp_ocv,
  165. int batt_temp_degc, int pc)
  166. {
  167. return -EINVAL;
  168. }
  169. static inline int linear_interpolate(int y0, int x0, int y1, int x1, int x)
  170. {
  171. return -EINVAL;
  172. }
  173. static inline int is_between(int left, int right, int value)
  174. {
  175. return -EINVAL;
  176. }
  177. #endif
  178. #endif