Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2011, Code Aurora Forum. 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_H |
| 14 | #define __PM8XXX_BMS_H |
| 15 | |
| 16 | #include <linux/errno.h> |
| 17 | |
| 18 | #define PM8921_BMS_DEV_NAME "pm8921-bms" |
| 19 | |
| 20 | #define FCC_CC_COLS 5 |
| 21 | #define FCC_TEMP_COLS 8 |
| 22 | |
| 23 | #define PC_CC_ROWS 10 |
| 24 | #define PC_CC_COLS 5 |
| 25 | |
| 26 | #define PC_TEMP_ROWS 29 |
| 27 | #define PC_TEMP_COLS 8 |
| 28 | |
| 29 | #define MAX_SINGLE_LUT_COLS 20 |
| 30 | |
| 31 | struct 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 pc_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 | * @cycles: the charge cycles at which sf data is available in the table. |
| 42 | * The charge cycles must be in increasing order from 0 to rows. |
| 43 | * @percent: the percent charge at which sf data is available in the table |
| 44 | * The percentcharge must be in decreasing order from 0 to cols. |
| 45 | * @sf: the scaling factor data |
| 46 | */ |
| 47 | struct pc_sf_lut { |
| 48 | int rows; |
| 49 | int cols; |
| 50 | int cycles[PC_CC_COLS]; |
| 51 | int percent[PC_CC_ROWS]; |
| 52 | int sf[PC_CC_ROWS][PC_CC_COLS]; |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * struct pc_temp_ocv_lut - |
| 57 | * @rows: number of percent charge entries should be <= PC_TEMP_ROWS |
| 58 | * @cols: number of temperature entries should be <= PC_TEMP_COLS |
| 59 | * @temp: the temperatures at which ocv data is available in the table |
| 60 | * The temperatures must be in increasing order from 0 to rows. |
| 61 | * @percent: the percent charge at which ocv data is available in the table |
| 62 | * The percentcharge must be in decreasing order from 0 to cols. |
| 63 | * @ocv: the open circuit voltage |
| 64 | */ |
| 65 | struct pc_temp_ocv_lut { |
| 66 | int rows; |
| 67 | int cols; |
| 68 | int temp[PC_TEMP_COLS]; |
| 69 | int percent[PC_TEMP_ROWS]; |
| 70 | int ocv[PC_TEMP_ROWS][PC_TEMP_COLS]; |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * struct pm8921_bms_battery_data - |
| 75 | * @fcc: full charge capacity (mAmpHour) |
| 76 | * @fcc_temp_lut: table to get fcc at a given temp |
| 77 | * @fcc_sf_lut: table to get fcc scaling factor for given charge cycles |
| 78 | * @pc_temp_ocv_lut: table to get percent charge given batt temp and cycles |
| 79 | * @pc_sf_lut: table to get percent charge scaling factor given cycles |
| 80 | * and percent charge |
| 81 | */ |
| 82 | struct pm8921_bms_battery_data { |
| 83 | unsigned int fcc; |
| 84 | struct single_row_lut *fcc_temp_lut; |
| 85 | struct single_row_lut *fcc_sf_lut; |
| 86 | struct pc_temp_ocv_lut *pc_temp_ocv_lut; |
| 87 | struct pc_sf_lut *pc_sf_lut; |
| 88 | }; |
| 89 | |
| 90 | /** |
| 91 | * struct pm8921_bms_platform_data - |
| 92 | * @r_sense: sense resistor value in (mOhms) |
| 93 | * @i_test: current at which the unusable charger cutoff is to be |
| 94 | * calculated or the peak system current (mA) |
| 95 | * @v_failure: the voltage at which the battery is considered empty(mV) |
| 96 | * @calib_delay_ms: how often should the adc calculate gain and offset |
| 97 | * @batt_data: the battery profile data for the one used in the board |
| 98 | */ |
| 99 | struct pm8921_bms_platform_data { |
| 100 | unsigned int r_sense; |
| 101 | unsigned int i_test; |
| 102 | unsigned int v_failure; |
| 103 | unsigned int calib_delay_ms; |
| 104 | struct pm8921_bms_battery_data *batt_data; |
| 105 | }; |
| 106 | |
| 107 | #if defined(CONFIG_PM8921_BMS) || defined(CONFIG_PM8921_BMS_MODULE) |
| 108 | int pm8921_bms_get_percent_charge(void); |
| 109 | void pm8921_bms_charging_began(void); |
| 110 | void pm8921_bms_charging_end(void); |
| 111 | #else |
| 112 | static inline int pm8921_bms_get_percent_charge(void) |
| 113 | { |
| 114 | return -ENXIO; |
| 115 | } |
| 116 | static inline void pm8921_bms_charging_began(void) |
| 117 | { |
| 118 | } |
| 119 | static inline void pm8921_bms_charging_end(void) |
| 120 | { |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | #endif |