.. | .. |
---|
134 | 134 | int rdc = 0; |
---|
135 | 135 | int ret = 0; |
---|
136 | 136 | |
---|
| 137 | + int vbat = 0; |
---|
137 | 138 | int charging = 0; |
---|
138 | 139 | int ocv_pct = 0; |
---|
139 | 140 | int coul_pct = 0; |
---|
140 | 141 | int ac_valid = 0; |
---|
141 | 142 | int usb_valid = 0; |
---|
| 143 | + int bat_cur_dir = 0; |
---|
| 144 | + static int low_power_cnt = 0; |
---|
142 | 145 | static int pre_rest_vol, invalid_count; |
---|
143 | 146 | |
---|
144 | 147 | struct axp_config_info *axp_config = &bat_power->dts_info; |
---|
145 | 148 | |
---|
146 | 149 | regmap_bulk_read(bat_power->regmap, AXP803_OCVBATH_RES, temp_val, 2); |
---|
147 | 150 | ocv_vol = ((temp_val[0] << 4) | (temp_val[1] & 0xF)) * 1100 / 1000; |
---|
| 151 | + |
---|
| 152 | + regmap_read(bat_power->regmap, AXP803_STATUS, ®_value); |
---|
| 153 | + bat_cur_dir = (reg_value & 0x04) ? 1 : 0; |
---|
148 | 154 | |
---|
149 | 155 | ret = regmap_read(bat_power->regmap, AXP803_CAP, ®_value); |
---|
150 | 156 | if (ret) |
---|
.. | .. |
---|
163 | 169 | rest_vol = 100; |
---|
164 | 170 | } |
---|
165 | 171 | |
---|
166 | | - if (ocv_vol < axp_config->pmu_vol_min) { |
---|
167 | | - // pr_err("kickpi: ocv_vol %d < min %d, rest_vol %d -> 0\n", ocv_vol, axp_config->pmu_vol_min, rest_vol); |
---|
168 | | - rest_vol = 0; |
---|
| 172 | + /* read ocv percentage */ |
---|
| 173 | + regmap_read(bat_power->regmap, AXP803_OCV_PERCENT, ®_value); |
---|
| 174 | + ocv_pct = (int)(reg_value & 0x7F); |
---|
| 175 | + |
---|
| 176 | + /* read vol */ |
---|
| 177 | + vbat = axp803_get_vbat(bat_power); |
---|
| 178 | + if (unlikely(axp_debug_mask & AXP_CHG)) { |
---|
| 179 | + pr_err("kickpi: v1 ocv_pct = %d rest_vol = %d vbat = %d !\n", ocv_pct, rest_vol, vbat); |
---|
| 180 | + } |
---|
| 181 | + |
---|
| 182 | + if ((ocv_pct == 0 && vbat > 0) || (rest_vol == 0 && vbat > 0) ) { |
---|
| 183 | + return 77; |
---|
169 | 184 | } |
---|
170 | 185 | |
---|
171 | 186 | return rest_vol; |
---|
.. | .. |
---|
243 | 258 | ocv_vol, rdc, coulumb_counter, batt_max_cap); |
---|
244 | 259 | } |
---|
245 | 260 | |
---|
246 | | - if (ocv_vol < axp_config->pmu_vol_min) { |
---|
247 | | - // pr_err("kickpi: ocv_vol %d < min %d, rest_vol %d -> 0\n", ocv_vol, axp_config->pmu_vol_min, rest_vol); |
---|
248 | | - rest_vol = 0; |
---|
| 261 | + /* |
---|
| 262 | + 1. vol < low_power_protect when not charge |
---|
| 263 | + 2. need power down |
---|
| 264 | + */ |
---|
| 265 | + if (bat_cur_dir == 0 && ocv_vol < axp_config->pmu_vol_min) { |
---|
| 266 | + low_power_cnt++; |
---|
| 267 | + if (low_power_cnt >= 6) { |
---|
| 268 | + return 0; |
---|
| 269 | + } |
---|
| 270 | + } else { |
---|
| 271 | + low_power_cnt = 0; |
---|
249 | 272 | } |
---|
250 | 273 | |
---|
251 | | - return rest_vol; |
---|
| 274 | + if (unlikely(axp_debug_mask & AXP_CHG)) { |
---|
| 275 | + vbat = axp803_get_vbat(bat_power); |
---|
| 276 | + pr_err("kickpi: v2 ocv_pct = %d rest_vol = %d vbat = %d !\n", ocv_pct, rest_vol, vbat); |
---|
| 277 | + } |
---|
| 278 | + |
---|
| 279 | + return ocv_pct; |
---|
| 280 | + // return rest_vol; |
---|
252 | 281 | } |
---|
253 | 282 | |
---|
254 | 283 | static inline int axp_vts_to_mV(u16 reg) |
---|