Commit | Line | Data |
---|---|---|
1cac41cb MB |
1 | /* |
2 | * sec_battery.c | |
3 | * Samsung Mobile Battery Driver | |
4 | * | |
5 | * Copyright (C) 2012 Samsung Electronics | |
6 | * | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | */ | |
12 | #include "include/sec_battery.h" | |
13 | #include <linux/sec_ext.h> | |
14 | #include <linux/sec_debug.h> | |
15 | ||
16 | #if defined(CONFIG_SEC_ABC) | |
17 | #include <linux/sti/abc_common.h> | |
18 | #endif | |
19 | ||
20 | bool sleep_mode = false; | |
21 | ||
22 | static struct device_attribute sec_battery_attrs[] = { | |
23 | SEC_BATTERY_ATTR(batt_reset_soc), | |
24 | SEC_BATTERY_ATTR(batt_read_raw_soc), | |
25 | SEC_BATTERY_ATTR(batt_read_adj_soc), | |
26 | SEC_BATTERY_ATTR(batt_type), | |
27 | SEC_BATTERY_ATTR(batt_vfocv), | |
28 | SEC_BATTERY_ATTR(batt_vol_adc), | |
29 | SEC_BATTERY_ATTR(batt_vol_adc_cal), | |
30 | SEC_BATTERY_ATTR(batt_vol_aver), | |
31 | SEC_BATTERY_ATTR(batt_vol_adc_aver), | |
32 | SEC_BATTERY_ATTR(batt_current_ua_now), | |
33 | SEC_BATTERY_ATTR(batt_current_ua_avg), | |
34 | SEC_BATTERY_ATTR(batt_filter_cfg), | |
35 | SEC_BATTERY_ATTR(batt_temp), | |
36 | SEC_BATTERY_ATTR(batt_temp_adc), | |
37 | SEC_BATTERY_ATTR(batt_temp_aver), | |
38 | SEC_BATTERY_ATTR(batt_temp_adc_aver), | |
39 | SEC_BATTERY_ATTR(usb_temp), | |
40 | SEC_BATTERY_ATTR(usb_temp_adc), | |
41 | SEC_BATTERY_ATTR(chg_temp), | |
42 | SEC_BATTERY_ATTR(chg_temp_adc), | |
43 | SEC_BATTERY_ATTR(slave_chg_temp), | |
44 | SEC_BATTERY_ATTR(slave_chg_temp_adc), | |
45 | ||
46 | SEC_BATTERY_ATTR(batt_vf_adc), | |
47 | SEC_BATTERY_ATTR(batt_slate_mode), | |
48 | ||
49 | SEC_BATTERY_ATTR(batt_lp_charging), | |
50 | SEC_BATTERY_ATTR(siop_activated), | |
51 | SEC_BATTERY_ATTR(siop_level), | |
52 | SEC_BATTERY_ATTR(siop_event), | |
53 | SEC_BATTERY_ATTR(batt_charging_source), | |
54 | SEC_BATTERY_ATTR(fg_reg_dump), | |
55 | SEC_BATTERY_ATTR(fg_reset_cap), | |
56 | SEC_BATTERY_ATTR(fg_capacity), | |
57 | SEC_BATTERY_ATTR(fg_asoc), | |
58 | SEC_BATTERY_ATTR(auth), | |
59 | SEC_BATTERY_ATTR(chg_current_adc), | |
60 | SEC_BATTERY_ATTR(wc_adc), | |
61 | SEC_BATTERY_ATTR(wc_status), | |
62 | SEC_BATTERY_ATTR(wc_enable), | |
63 | SEC_BATTERY_ATTR(wc_control), | |
64 | SEC_BATTERY_ATTR(wc_control_cnt), | |
65 | SEC_BATTERY_ATTR(led_cover), | |
66 | SEC_BATTERY_ATTR(hv_charger_status), | |
67 | SEC_BATTERY_ATTR(hv_wc_charger_status), | |
68 | SEC_BATTERY_ATTR(hv_charger_set), | |
69 | SEC_BATTERY_ATTR(factory_mode), | |
70 | SEC_BATTERY_ATTR(store_mode), | |
71 | SEC_BATTERY_ATTR(update), | |
72 | SEC_BATTERY_ATTR(test_mode), | |
73 | ||
74 | SEC_BATTERY_ATTR(call), | |
75 | SEC_BATTERY_ATTR(2g_call), | |
76 | SEC_BATTERY_ATTR(talk_gsm), | |
77 | SEC_BATTERY_ATTR(3g_call), | |
78 | SEC_BATTERY_ATTR(talk_wcdma), | |
79 | SEC_BATTERY_ATTR(music), | |
80 | SEC_BATTERY_ATTR(video), | |
81 | SEC_BATTERY_ATTR(browser), | |
82 | SEC_BATTERY_ATTR(hotspot), | |
83 | SEC_BATTERY_ATTR(camera), | |
84 | SEC_BATTERY_ATTR(camcorder), | |
85 | SEC_BATTERY_ATTR(data_call), | |
86 | SEC_BATTERY_ATTR(wifi), | |
87 | SEC_BATTERY_ATTR(wibro), | |
88 | SEC_BATTERY_ATTR(lte), | |
89 | SEC_BATTERY_ATTR(lcd), | |
90 | SEC_BATTERY_ATTR(gps), | |
91 | SEC_BATTERY_ATTR(event), | |
92 | SEC_BATTERY_ATTR(batt_temp_table), | |
93 | SEC_BATTERY_ATTR(batt_high_current_usb), | |
94 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
95 | SEC_BATTERY_ATTR(test_charge_current), | |
96 | #endif | |
97 | SEC_BATTERY_ATTR(set_stability_test), | |
98 | SEC_BATTERY_ATTR(batt_capacity_max), | |
99 | SEC_BATTERY_ATTR(batt_inbat_voltage), | |
100 | SEC_BATTERY_ATTR(batt_inbat_voltage_ocv), | |
101 | SEC_BATTERY_ATTR(check_slave_chg), | |
102 | SEC_BATTERY_ATTR(batt_inbat_wireless_cs100), | |
103 | SEC_BATTERY_ATTR(hmt_ta_connected), | |
104 | SEC_BATTERY_ATTR(hmt_ta_charge), | |
105 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
106 | SEC_BATTERY_ATTR(fg_cycle), | |
107 | SEC_BATTERY_ATTR(fg_full_voltage), | |
108 | SEC_BATTERY_ATTR(fg_fullcapnom), | |
109 | SEC_BATTERY_ATTR(battery_cycle), | |
110 | #endif | |
111 | SEC_BATTERY_ATTR(batt_wpc_temp), | |
112 | SEC_BATTERY_ATTR(batt_wpc_temp_adc), | |
113 | SEC_BATTERY_ATTR(batt_coil_temp), /* Wireless Coil therm */ | |
114 | SEC_BATTERY_ATTR(batt_coil_temp_adc), /* Wireless Coil therm */ | |
115 | SEC_BATTERY_ATTR(mst_switch_test), /* MFC MST switch test */ | |
116 | #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE) | |
117 | SEC_BATTERY_ATTR(batt_wireless_firmware_update), | |
118 | SEC_BATTERY_ATTR(otp_firmware_result), | |
119 | SEC_BATTERY_ATTR(wc_ic_grade), | |
120 | SEC_BATTERY_ATTR(otp_firmware_ver_bin), | |
121 | SEC_BATTERY_ATTR(otp_firmware_ver), | |
122 | SEC_BATTERY_ATTR(tx_firmware_result), | |
123 | SEC_BATTERY_ATTR(tx_firmware_ver), | |
124 | SEC_BATTERY_ATTR(batt_tx_status), | |
125 | #endif | |
126 | SEC_BATTERY_ATTR(wc_vout), | |
127 | SEC_BATTERY_ATTR(wc_vrect), | |
128 | SEC_BATTERY_ATTR(batt_hv_wireless_status), | |
129 | SEC_BATTERY_ATTR(batt_hv_wireless_pad_ctrl), | |
130 | SEC_BATTERY_ATTR(wc_op_freq), | |
131 | SEC_BATTERY_ATTR(wc_cmd_info), | |
132 | SEC_BATTERY_ATTR(batt_tune_float_voltage), | |
133 | SEC_BATTERY_ATTR(batt_tune_input_charge_current), | |
134 | SEC_BATTERY_ATTR(batt_tune_fast_charge_current), | |
135 | SEC_BATTERY_ATTR(batt_tune_ui_term_cur_1st), | |
136 | SEC_BATTERY_ATTR(batt_tune_ui_term_cur_2nd), | |
137 | SEC_BATTERY_ATTR(batt_tune_temp_high_normal), | |
138 | SEC_BATTERY_ATTR(batt_tune_temp_high_rec_normal), | |
139 | SEC_BATTERY_ATTR(batt_tune_temp_low_normal), | |
140 | SEC_BATTERY_ATTR(batt_tune_temp_low_rec_normal), | |
141 | SEC_BATTERY_ATTR(batt_tune_chg_temp_high), | |
142 | SEC_BATTERY_ATTR(batt_tune_chg_temp_rec), | |
143 | SEC_BATTERY_ATTR(batt_tune_chg_limit_cur), | |
144 | SEC_BATTERY_ATTR(batt_tune_coil_temp_high), | |
145 | SEC_BATTERY_ATTR(batt_tune_coil_temp_rec), | |
146 | SEC_BATTERY_ATTR(batt_tune_coil_limit_cur), | |
147 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
148 | SEC_BATTERY_ATTR(batt_update_data), | |
149 | #endif | |
150 | SEC_BATTERY_ATTR(batt_misc_event), | |
151 | SEC_BATTERY_ATTR(batt_ext_dev_chg), | |
152 | SEC_BATTERY_ATTR(batt_wdt_control), | |
153 | SEC_BATTERY_ATTR(mode), | |
154 | SEC_BATTERY_ATTR(check_ps_ready), | |
155 | SEC_BATTERY_ATTR(batt_chip_id), | |
156 | SEC_BATTERY_ATTR(cisd_fullcaprep_max), | |
157 | #if defined(CONFIG_BATTERY_CISD) | |
158 | SEC_BATTERY_ATTR(cisd_data), | |
159 | SEC_BATTERY_ATTR(cisd_data_json), | |
160 | SEC_BATTERY_ATTR(cisd_data_d_json), | |
161 | SEC_BATTERY_ATTR(cisd_wire_count), | |
162 | SEC_BATTERY_ATTR(cisd_wc_data), | |
163 | SEC_BATTERY_ATTR(cisd_wc_data_json), | |
164 | SEC_BATTERY_ATTR(prev_battery_data), | |
165 | SEC_BATTERY_ATTR(prev_battery_info), | |
166 | #endif | |
167 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
168 | SEC_BATTERY_ATTR(sbm_data), | |
169 | #endif | |
170 | SEC_BATTERY_ATTR(safety_timer_set), | |
171 | SEC_BATTERY_ATTR(batt_swelling_control), | |
172 | SEC_BATTERY_ATTR(safety_timer_info), | |
173 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
174 | SEC_BATTERY_ATTR(batt_temp_test), | |
175 | #endif | |
176 | SEC_BATTERY_ATTR(batt_current_event), | |
177 | SEC_BATTERY_ATTR(cc_info), | |
178 | SEC_BATTERY_ATTR(ext_event), | |
179 | }; | |
180 | ||
181 | static enum power_supply_property sec_battery_props[] = { | |
182 | POWER_SUPPLY_PROP_STATUS, | |
183 | POWER_SUPPLY_PROP_CHARGE_TYPE, | |
184 | POWER_SUPPLY_PROP_HEALTH, | |
185 | POWER_SUPPLY_PROP_PRESENT, | |
186 | POWER_SUPPLY_PROP_ONLINE, | |
187 | POWER_SUPPLY_PROP_TECHNOLOGY, | |
188 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | |
189 | POWER_SUPPLY_PROP_VOLTAGE_AVG, | |
190 | POWER_SUPPLY_PROP_CURRENT_NOW, | |
191 | POWER_SUPPLY_PROP_CURRENT_AVG, | |
192 | POWER_SUPPLY_PROP_CHARGE_FULL, | |
193 | POWER_SUPPLY_PROP_CHARGE_NOW, | |
194 | POWER_SUPPLY_PROP_CAPACITY, | |
195 | POWER_SUPPLY_PROP_TEMP, | |
196 | POWER_SUPPLY_PROP_TEMP_AMBIENT, | |
197 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
198 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, | |
199 | #endif | |
200 | POWER_SUPPLY_PROP_CHARGE_COUNTER_SHADOW, | |
201 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
202 | POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL, | |
203 | POWER_SUPPLY_PROP_CHARGE_COUNTER, | |
204 | }; | |
205 | ||
206 | static enum power_supply_property sec_power_props[] = { | |
207 | POWER_SUPPLY_PROP_ONLINE, | |
9782eb9b JC |
208 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
209 | POWER_SUPPLY_PROP_CURRENT_MAX, | |
1cac41cb MB |
210 | }; |
211 | ||
212 | static enum power_supply_property sec_wireless_props[] = { | |
213 | POWER_SUPPLY_PROP_ONLINE, | |
214 | POWER_SUPPLY_PROP_PRESENT, | |
9782eb9b JC |
215 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
216 | POWER_SUPPLY_PROP_CURRENT_MAX, | |
1cac41cb MB |
217 | }; |
218 | ||
219 | static enum power_supply_property sec_ac_props[] = { | |
220 | POWER_SUPPLY_PROP_ONLINE, | |
221 | POWER_SUPPLY_PROP_TEMP, | |
9782eb9b JC |
222 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
223 | POWER_SUPPLY_PROP_CURRENT_MAX, | |
1cac41cb MB |
224 | }; |
225 | ||
226 | static enum power_supply_property sec_ps_props[] = { | |
227 | POWER_SUPPLY_PROP_STATUS, | |
228 | POWER_SUPPLY_PROP_ONLINE, | |
229 | }; | |
230 | ||
231 | static char *supply_list[] = { | |
232 | "battery", | |
233 | }; | |
234 | ||
235 | char *sec_cable_type[SEC_BATTERY_CABLE_MAX] = { | |
236 | "UNKNOWN", /* 0 */ | |
237 | "NONE", /* 1 */ | |
238 | "PREAPARE_TA", /* 2 */ | |
239 | "TA", /* 3 */ | |
240 | "USB", /* 4 */ | |
241 | "USB_CDP", /* 5 */ | |
242 | "9V_TA", /* 6 */ | |
243 | "9V_ERR", /* 7 */ | |
244 | "9V_UNKNOWN", /* 8 */ | |
245 | "12V_TA", /* 9 */ | |
246 | "WIRELESS", /* 10 */ | |
247 | "HV_WIRELESS", /* 11 */ | |
248 | "PMA_WIRELESS", /* 12 */ | |
249 | "WIRELESS_PACK", /* 13 */ | |
250 | "WIRELESS_HV_PACK", /* 14 */ | |
251 | "WIRELESS_STAND", /* 15 */ | |
252 | "WIRELESS_HV_STAND", /* 16 */ | |
253 | "OC20", /* 17 */ | |
254 | "QC30", /* 18 */ | |
255 | "PDIC", /* 19 */ | |
256 | "UARTOFF", /* 20 */ | |
257 | "OTG", /* 21 */ | |
258 | "LAN_HUB", /* 22 */ | |
259 | "POWER_SHARGING", /* 23 */ | |
260 | "HMT_CONNECTED", /* 24 */ | |
261 | "HMT_CHARGE", /* 25 */ | |
262 | "HV_TA_CHG_LIMIT", /* 26 */ | |
263 | "WIRELESS_VEHICLE", /* 27 */ | |
264 | "WIRELESS_HV_VEHICLE", /* 28 */ | |
265 | "WIRELESS_HV_PREPARE", /* 29 */ | |
266 | "TIMEOUT", /* 30 */ | |
267 | "SMART_OTG", /* 31 */ | |
268 | "SMART_NOTG", /* 32 */ | |
269 | "WIRELESS_TX", /* 33 */ | |
270 | }; | |
271 | ||
272 | char *sec_bat_charging_mode_str[] = { | |
273 | "None", | |
274 | "Normal", | |
275 | "Additional", | |
276 | "Re-Charging", | |
277 | "ABS" | |
278 | }; | |
279 | ||
280 | char *sec_bat_status_str[] = { | |
281 | "Unknown", | |
282 | "Charging", | |
283 | "Discharging", | |
284 | "Not-charging", | |
285 | "Full" | |
286 | }; | |
287 | ||
288 | char *sec_bat_health_str[] = { | |
289 | "Unknown", | |
290 | "Good", | |
291 | "Overheat", | |
292 | "Warm", | |
293 | "Dead", | |
294 | "OverVoltage", | |
295 | "UnspecFailure", | |
296 | "Cold", | |
297 | "Cool", | |
298 | "WatchdogTimerExpire", | |
299 | "SafetyTimerExpire", | |
300 | "UnderVoltage", | |
301 | "OverheatLimit", | |
302 | "VsysOVP", | |
303 | "VbatOVP", | |
304 | }; | |
305 | ||
306 | char *sec_bat_charge_mode_str[] = { | |
307 | "Charging-On", | |
308 | "Charging-Off", | |
309 | "Buck-Off", | |
310 | }; | |
311 | ||
312 | extern int bootmode; | |
313 | ||
314 | static void sec_bat_set_misc_event(struct sec_battery_info *battery, | |
315 | const int misc_event_type, bool do_clear) { | |
316 | ||
317 | mutex_lock(&battery->misclock); | |
318 | pr_info("%s: %s misc event(now=0x%x, value=0x%x)\n", | |
319 | __func__, ((do_clear) ? "clear" : "set"), battery->misc_event, misc_event_type); | |
320 | if (do_clear) { | |
321 | battery->misc_event &= ~misc_event_type; | |
322 | } else { | |
323 | battery->misc_event |= misc_event_type; | |
324 | } | |
325 | mutex_unlock(&battery->misclock); | |
326 | ||
327 | if (battery->prev_misc_event != battery->misc_event) { | |
328 | cancel_delayed_work(&battery->misc_event_work); | |
329 | wake_lock(&battery->misc_event_wake_lock); | |
330 | queue_delayed_work(battery->monitor_wqueue, | |
331 | &battery->misc_event_work, 0); | |
332 | } | |
333 | } | |
334 | ||
335 | static void sec_bat_set_current_event(struct sec_battery_info *battery, | |
336 | unsigned int current_event_val, unsigned int current_event_mask) | |
337 | { | |
338 | unsigned int temp = battery->current_event; | |
339 | ||
340 | mutex_lock(&battery->current_eventlock); | |
341 | ||
342 | battery->current_event &= ~current_event_mask; | |
343 | battery->current_event |= current_event_val; | |
344 | ||
345 | pr_info("%s: current event before(0x%x), after(0x%x)\n", | |
346 | __func__, temp, battery->current_event); | |
347 | ||
348 | mutex_unlock(&battery->current_eventlock); | |
349 | } | |
350 | ||
351 | static void sec_bat_change_default_current(struct sec_battery_info *battery, | |
352 | int cable_type, int input, int output) | |
353 | { | |
354 | battery->pdata->charging_current[cable_type].input_current_limit = input; | |
355 | battery->pdata->charging_current[cable_type].fast_charging_current = output; | |
356 | pr_info("%s: cable_type: %d input: %d output: %d\n",__func__, cable_type, input, output); | |
357 | } | |
358 | ||
359 | static int sec_bat_get_wireless_current(struct sec_battery_info *battery, int incurr) | |
360 | { | |
361 | /* 2. WPC_SLEEP_MODE */ | |
362 | if (is_hv_wireless_type(battery->cable_type) && sleep_mode) { | |
363 | if(incurr > battery->pdata->sleep_mode_limit_current) | |
364 | incurr = battery->pdata->sleep_mode_limit_current; | |
365 | pr_info("%s sleep_mode =%d, chg_limit =%d, in_curr = %d \n", __func__, | |
366 | sleep_mode, battery->chg_limit, incurr); | |
367 | } | |
368 | ||
369 | /* 3. WPC_TEMP_MODE */ | |
370 | if (is_wireless_type(battery->cable_type) && battery->chg_limit) { | |
371 | if ((battery->siop_level >= 100) && | |
372 | (incurr > battery->pdata->wpc_charging_limit_current)) | |
373 | incurr = battery->pdata->wpc_charging_limit_current; | |
374 | else if ((battery->siop_level < 100) && | |
375 | (incurr > battery->pdata->wpc_lcd_on_charging_limit_current)) | |
376 | incurr = battery->pdata->wpc_lcd_on_charging_limit_current; | |
377 | } | |
378 | ||
379 | /* 4. WPC_CV_MODE */ | |
380 | if (is_nv_wireless_type(battery->cable_type)) { | |
381 | if (battery->pdata->set_cv_vout_in_low_capacity) { | |
382 | union power_supply_propval value = {0,}; | |
383 | ||
384 | if (battery->capacity <= battery->pdata->set_cv_vout_in_low_capacity && | |
385 | !battery->wc_cv_mode) { | |
386 | battery->wc_cv_mode = true; | |
387 | value.intval = WIRELESS_VOUT_CC_CV_VOUT; // 5.5V | |
388 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
389 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
390 | } else if (battery->capacity > battery->pdata->set_cv_vout_in_low_capacity && | |
391 | battery->capacity < battery->pdata->wireless_cc_cv && | |
392 | battery->wc_cv_mode) { | |
393 | battery->wc_cv_mode = false; | |
394 | value.intval = WIRELESS_VOUT_5V; // 5V | |
395 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
396 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
397 | } | |
398 | } | |
399 | ||
400 | if (battery->wc_cv_mode) { | |
401 | if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_PACK) { | |
402 | if (incurr > battery->pdata->wc_cv_pack_current) | |
403 | incurr = battery->pdata->wc_cv_pack_current; | |
5a068558 MB |
404 | } else if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_TX) { |
405 | if (incurr > battery->pdata->wc_cv_tx_current) | |
406 | incurr = battery->pdata->wc_cv_tx_current; | |
1cac41cb MB |
407 | } else if (incurr > battery->pdata->wc_cv_current) { |
408 | incurr = battery->pdata->wc_cv_current; | |
409 | } | |
410 | } | |
411 | } | |
412 | ||
413 | /* 5. Full-Additional state */ | |
414 | if (battery->status == POWER_SUPPLY_STATUS_FULL && battery->charging_mode == SEC_BATTERY_CHARGING_2ND) { | |
415 | if (incurr > battery->pdata->siop_hv_wireless_input_limit_current) | |
416 | incurr = battery->pdata->siop_hv_wireless_input_limit_current; | |
417 | } | |
418 | ||
419 | /* 6. Hero Stand Pad CV */ | |
420 | if (battery->capacity >= battery->pdata->wc_hero_stand_cc_cv) { | |
421 | if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_STAND) { | |
422 | if (incurr > battery->pdata->wc_hero_stand_cv_current) | |
423 | incurr = battery->pdata->wc_hero_stand_cv_current; | |
424 | } else if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_STAND) { | |
425 | if (battery->chg_limit && | |
426 | incurr > battery->pdata->wc_hero_stand_cv_current) { | |
427 | incurr = battery->pdata->wc_hero_stand_cv_current; | |
428 | } else if (!battery->chg_limit && | |
429 | incurr > battery->pdata->wc_hero_stand_hv_cv_current) { | |
430 | incurr = battery->pdata->wc_hero_stand_hv_cv_current; | |
431 | } | |
432 | } | |
433 | } | |
434 | ||
435 | /* 7. Full-None state && SIOP_LEVEL 100 */ | |
436 | if (battery->siop_level == 100 && | |
437 | battery->status == POWER_SUPPLY_STATUS_FULL && battery->charging_mode == SEC_BATTERY_CHARGING_NONE) { | |
438 | incurr = battery->pdata->wc_full_input_limit_current; | |
439 | } | |
440 | ||
441 | return incurr; | |
442 | } | |
443 | ||
444 | static void sec_bat_get_charging_current_by_siop(struct sec_battery_info *battery, | |
445 | int *input_current, int *charging_current) { | |
446 | int usb_charging_current = 500; | |
447 | ||
448 | if (battery->siop_level < 100) { | |
449 | int max_charging_current; | |
450 | ||
451 | if (is_wireless_type(battery->cable_type)) { | |
452 | /* decrease the charging current according to siop level */ | |
453 | *charging_current = *charging_current * battery->siop_level / 100; | |
454 | ||
455 | /* do forced set charging current */ | |
456 | if (*charging_current > 0 && *charging_current < usb_charging_current) | |
457 | *charging_current = usb_charging_current; | |
458 | } else { | |
459 | max_charging_current = 1800; /* 1 step(70) */ | |
460 | ||
461 | /* do forced set charging current */ | |
462 | if (*charging_current > max_charging_current) | |
463 | *charging_current = max_charging_current; | |
464 | } | |
465 | ||
466 | if (is_nv_wireless_type(battery->cable_type)) { | |
467 | if (*input_current > battery->pdata->siop_wireless_input_limit_current) | |
468 | *input_current = battery->pdata->siop_wireless_input_limit_current; | |
469 | if (*charging_current > battery->pdata->siop_wireless_charging_limit_current) | |
470 | *charging_current = battery->pdata->siop_wireless_charging_limit_current; | |
471 | } else if (is_hv_wireless_type(battery->cable_type)) { | |
472 | if (*input_current > battery->pdata->siop_hv_wireless_input_limit_current) | |
473 | *input_current = battery->pdata->siop_hv_wireless_input_limit_current; | |
474 | if (*charging_current > battery->pdata->siop_hv_wireless_charging_limit_current) | |
475 | *charging_current = battery->pdata->siop_hv_wireless_charging_limit_current; | |
476 | } else if (is_hv_wire_type(battery->cable_type) && is_hv_wire_type(battery->wire_status)) { | |
477 | if (is_hv_wire_12v_type(battery->cable_type)) { | |
478 | if (*input_current > battery->pdata->siop_hv_12v_input_limit_current) | |
479 | *input_current = battery->pdata->siop_hv_12v_input_limit_current; | |
480 | } else { | |
481 | if (*input_current > battery->pdata->siop_hv_input_limit_current) | |
482 | *input_current = battery->pdata->siop_hv_input_limit_current; | |
483 | } | |
484 | #if defined(CONFIG_CCIC_NOTIFIER) | |
485 | } else if (battery->cable_type == SEC_BATTERY_CABLE_PDIC) { | |
486 | if (*input_current > (6000 / battery->input_voltage)) | |
487 | *input_current = 6000 / battery->input_voltage; | |
488 | #endif | |
489 | } else { | |
490 | if (*input_current > battery->pdata->siop_input_limit_current) | |
491 | *input_current = battery->pdata->siop_input_limit_current; | |
492 | } | |
493 | } | |
494 | ||
495 | pr_info("%s: incurr(%d), chgcurr(%d)\n", __func__, *input_current, *charging_current); | |
496 | } | |
497 | ||
498 | #if defined(CONFIG_MUIC_HV) || defined(CONFIG_SUPPORT_QC30) | |
499 | extern int muic_afc_set_voltage(int vol); | |
500 | #endif | |
501 | #if !defined(CONFIG_SEC_FACTORY) | |
502 | static int sec_bat_get_temp_by_temp_control_source(struct sec_battery_info *battery, | |
503 | enum sec_battery_temp_control_source tcs) | |
504 | { | |
505 | switch (tcs) { | |
506 | case TEMP_CONTROL_SOURCE_CHG_THM: | |
507 | return battery->chg_temp; | |
508 | case TEMP_CONTROL_SOURCE_USB_THM: | |
509 | return battery->usb_temp; | |
510 | case TEMP_CONTROL_SOURCE_WPC_THM: | |
511 | return battery->wpc_temp; | |
512 | case TEMP_CONTROL_SOURCE_NONE: | |
513 | case TEMP_CONTROL_SOURCE_BAT_THM: | |
514 | default: | |
515 | return battery->temperature; | |
516 | } | |
517 | } | |
518 | ||
519 | static int sec_bat_check_mix_temp(struct sec_battery_info *battery, int input_current) | |
520 | { | |
521 | if (battery->pdata->chg_temp_check && battery->siop_level >= 100 && is_not_wireless_type(battery->cable_type)) { | |
522 | if ((!battery->mix_limit && | |
523 | (battery->temperature >= battery->pdata->mix_high_temp) && | |
524 | (battery->chg_temp >= battery->pdata->mix_high_chg_temp)) || | |
525 | (battery->mix_limit && | |
526 | (battery->temperature > battery->pdata->mix_high_temp_recovery))) { | |
527 | int max_input_current = | |
528 | battery->pdata->full_check_current_1st + 50; | |
529 | ||
530 | /* inpu current = float voltage * (topoff_current_1st + 50mA(margin)) / (vbus_level * 0.9) */ | |
531 | input_current = ((battery->pdata->chg_float_voltage / battery->pdata->chg_float_voltage_conv) * max_input_current) / | |
532 | (battery->input_voltage * 90) / 10; | |
533 | if (input_current > max_input_current) | |
534 | input_current = max_input_current; | |
535 | ||
536 | battery->mix_limit = true; | |
537 | /* skip other heating control */ | |
538 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL, | |
539 | SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL); | |
540 | } else if (battery->mix_limit) { | |
541 | battery->mix_limit = false; | |
542 | } | |
543 | ||
544 | pr_info("%s: mix_limit(%d), temp(%d), chg_temp(%d), input_current(%d)\n", | |
545 | __func__, battery->mix_limit, battery->temperature, battery->chg_temp, input_current); | |
546 | } else { | |
547 | battery->mix_limit = false; | |
548 | } | |
549 | return input_current; | |
550 | } | |
551 | ||
552 | static int sec_bat_check_wpc_temp(struct sec_battery_info *battery, int input_current) | |
553 | { | |
554 | if (is_wireless_type(battery->cable_type)) { | |
555 | int wpc_vout_level = WIRELESS_VOUT_10V; | |
556 | ||
557 | if (battery->siop_level >= 100) { | |
558 | int temp_val = sec_bat_get_temp_by_temp_control_source(battery, | |
559 | battery->pdata->wpc_temp_control_source); | |
560 | ||
561 | if ((!battery->chg_limit && temp_val >= battery->pdata->wpc_high_temp) || | |
562 | (battery->chg_limit && temp_val > battery->pdata->wpc_high_temp_recovery)) { | |
563 | battery->chg_limit = true; | |
564 | input_current = battery->pdata->wpc_charging_limit_current; | |
565 | wpc_vout_level = WIRELESS_VOUT_5V_STEP; | |
566 | } else if (battery->chg_limit) { | |
567 | battery->chg_limit = false; | |
568 | } | |
569 | } else { | |
570 | if ((is_hv_wireless_type(battery->cable_type) && | |
571 | battery->cable_type != SEC_BATTERY_CABLE_WIRELESS_HV_VEHICLE) || | |
572 | battery->cable_type == SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV) { | |
573 | int temp_val = sec_bat_get_temp_by_temp_control_source(battery, | |
574 | battery->pdata->wpc_temp_lcd_on_control_source); | |
575 | ||
576 | if ((!battery->chg_limit && | |
577 | temp_val >= battery->pdata->wpc_lcd_on_high_temp) || | |
578 | (battery->chg_limit && | |
579 | temp_val > battery->pdata->wpc_lcd_on_high_temp_rec)) { | |
580 | input_current = battery->pdata->wpc_lcd_on_charging_limit_current; | |
581 | battery->chg_limit = true; | |
582 | wpc_vout_level = (battery->capacity < 95) ? | |
583 | WIRELESS_VOUT_5V_STEP : WIRELESS_VOUT_10V; | |
584 | } else if (battery->chg_limit) { | |
585 | battery->chg_limit = false; | |
586 | } | |
587 | } else if (battery->chg_limit) { | |
588 | battery->chg_limit = false; | |
589 | } | |
590 | } | |
591 | ||
592 | if (is_hv_wireless_type(battery->cable_type)) { | |
593 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_SWELLING_MODE) | |
594 | wpc_vout_level = WIRELESS_VOUT_5V_STEP; | |
595 | ||
596 | if (wpc_vout_level != battery->wpc_vout_level) { | |
597 | battery->wpc_vout_level = wpc_vout_level; | |
598 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_WPC_VOUT_LOCK) { | |
599 | pr_info("%s: block to set wpc vout level(%d) because otg on\n", | |
600 | __func__, wpc_vout_level); | |
601 | } else { | |
602 | union power_supply_propval value = {0, }; | |
603 | ||
604 | value.intval = wpc_vout_level; | |
605 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
606 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
607 | pr_info("%s: change vout level(%d)", | |
608 | __func__, battery->wpc_vout_level); | |
609 | battery->aicl_current = 0; /* reset aicl current */ | |
610 | } | |
611 | } else if (battery->wpc_vout_level == WIRELESS_VOUT_10V && !battery->chg_limit) | |
612 | /* reset aicl current to recover current for unexpected aicl during before vout boosting completion */ | |
613 | battery->aicl_current = 0; | |
614 | } | |
615 | pr_info("%s: change input_current(%d), vout_level(%d), chg_limit(%d)\n", | |
616 | __func__, input_current, battery->wpc_vout_level, battery->chg_limit); | |
617 | } | |
618 | ||
619 | return input_current; | |
620 | } | |
621 | ||
622 | static void sec_bat_check_afc_temp(struct sec_battery_info *battery, int *input_current, int *charging_current) | |
623 | { | |
624 | #if defined(CONFIG_MUIC_HV) || defined(CONFIG_SUPPORT_QC30) | |
625 | if (battery->siop_level >= 100) { | |
626 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_CHG_LIMIT) { | |
627 | battery->chg_limit = battery->vbus_chg_by_siop = false; | |
628 | *input_current = battery->pdata->pre_afc_input_current; | |
629 | { | |
630 | /* change input current */ | |
631 | union power_supply_propval value; | |
632 | battery->charge_power = battery->input_voltage * (*input_current); | |
633 | value.intval = *input_current; | |
634 | psy_do_property(battery->pdata->charger_name, set, | |
635 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
636 | battery->input_current = *input_current; | |
637 | } | |
638 | /* set current event */ | |
639 | cancel_delayed_work(&battery->afc_work); | |
640 | wake_unlock(&battery->afc_wake_lock); | |
641 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_AFC, | |
642 | (SEC_BAT_CURRENT_EVENT_CHG_LIMIT | SEC_BAT_CURRENT_EVENT_AFC)); | |
643 | /* vbus level : 5V --> 9V */ | |
644 | if (battery->chg_limit_recovery_cable == SEC_BATTERY_CABLE_12V_TA) { | |
645 | muic_afc_set_voltage(SEC_INPUT_VOLTAGE_12V); | |
646 | } else if (battery->chg_limit_recovery_cable == SEC_BATTERY_CABLE_9V_TA) { | |
647 | muic_afc_set_voltage(SEC_INPUT_VOLTAGE_9V); | |
648 | } else | |
649 | pr_info("%s: cable_type(%d), chg_limit_recovery_cable(%d) vbus_by_siop(%d)\n", __func__, | |
650 | battery->cable_type, battery->chg_limit_recovery_cable, battery->vbus_chg_by_siop); | |
651 | } else if (!battery->chg_limit && is_hv_wire_type(battery->cable_type) && (battery->chg_temp > battery->pdata->chg_high_temp)) { | |
652 | *input_current = battery->pdata->chg_input_limit_current; | |
653 | *charging_current = battery->pdata->chg_charging_limit_current; | |
654 | battery->chg_limit = true; | |
655 | } else if (!battery->chg_limit && battery->max_charge_power >= (battery->pdata->pd_charging_charge_power - 500) && (battery->chg_temp > battery->pdata->chg_high_temp)) { | |
656 | *input_current = battery->pdata->default_input_current; | |
657 | *charging_current = battery->pdata->default_charging_current; | |
658 | battery->chg_limit = true; | |
659 | } else if (battery->chg_limit && is_hv_wire_type(battery->cable_type)) { | |
660 | if (battery->chg_temp < battery->pdata->chg_high_temp_recovery) { | |
661 | *input_current = battery->pdata->charging_current[battery->cable_type].input_current_limit; | |
662 | *charging_current = battery->pdata->charging_current[battery->cable_type].fast_charging_current; | |
663 | battery->chg_limit = false; | |
664 | } else { | |
665 | *input_current = battery->pdata->chg_input_limit_current; | |
666 | *charging_current = battery->pdata->chg_charging_limit_current; | |
667 | battery->chg_limit = true; | |
668 | } | |
669 | } else if (battery->chg_limit && battery->max_charge_power >= (battery->pdata->pd_charging_charge_power - 500)) { | |
670 | if (battery->chg_temp < battery->pdata->chg_high_temp_recovery) { | |
671 | *input_current = battery->pdata->charging_current[battery->cable_type].input_current_limit; | |
672 | *charging_current = battery->pdata->charging_current[battery->cable_type].fast_charging_current; | |
673 | battery->chg_limit = false; | |
674 | } else { | |
675 | *input_current = battery->pdata->chg_input_limit_current; | |
676 | *charging_current = battery->pdata->chg_charging_limit_current; | |
677 | battery->chg_limit = true; | |
678 | } | |
679 | } | |
680 | pr_info("%s: cable_type(%d), chg_limit(%d) vbus_by_siop(%d)\n", __func__, | |
681 | battery->cable_type, battery->chg_limit, battery->vbus_chg_by_siop); | |
682 | } else if (is_hv_wire_type(battery->cable_type) && is_hv_wire_type(battery->wire_status) && | |
683 | !battery->store_mode && (battery->cable_type != SEC_BATTERY_CABLE_QC30) && | |
684 | (battery->status == POWER_SUPPLY_STATUS_CHARGING) && !battery->vbus_chg_by_siop) { | |
685 | battery->chg_limit_recovery_cable = battery->cable_type; | |
686 | battery->vbus_chg_by_siop = true; | |
687 | battery->chg_limit = false; | |
688 | /* vbus level : 9V --> 5V */ | |
689 | muic_afc_set_voltage(SEC_INPUT_VOLTAGE_5V); | |
690 | pr_info("%s: vbus set 5V by siop(recovery cable: %d)\n", __func__,battery->chg_limit_recovery_cable); | |
691 | } | |
692 | #else | |
693 | if (!battery->chg_limit && is_hv_wire_type(battery->cable_type) && (battery->chg_temp > battery->pdata->chg_high_temp)) { | |
694 | *input_current = battery->pdata->chg_input_limit_current; | |
695 | *charging_current = battery->pdata->chg_charging_limit_current; | |
696 | battery->chg_limit = true; | |
697 | } else if (battery->chg_limit && is_hv_wire_type(battery->cable_type) && (battery->chg_temp < battery->pdata->chg_high_temp_recovery)) { | |
698 | *input_current = battery->pdata->charging_current[battery->cable_type].input_current_limit; | |
699 | *charging_current = battery->pdata->charging_current[battery->cable_type].fast_charging_current; | |
700 | battery->chg_limit = false; | |
701 | } | |
702 | #endif | |
703 | } | |
704 | ||
705 | #if defined(CONFIG_CCIC_NOTIFIER) | |
706 | extern void select_pdo(int num); | |
707 | static int sec_bat_check_pdic_temp(struct sec_battery_info *battery, int input_current) | |
708 | { | |
709 | if (battery->pdic_ps_rdy && battery->siop_level >= 100) { | |
710 | ||
711 | struct sec_bat_pdic_list *pd_list = &battery->pd_list; | |
712 | int pd_index = pd_list->now_pd_index; | |
713 | ||
714 | if (!battery->chg_limit) { | |
715 | if (battery->chg_temp >= battery->pdata->chg_high_temp) { | |
716 | battery->chg_limit = true; | |
717 | pd_index--; | |
718 | } else | |
719 | pd_index++; | |
720 | } else { | |
721 | if (battery->chg_temp <= battery->pdata->chg_high_temp_recovery) | |
722 | battery->chg_limit = false; | |
723 | else if (battery->chg_temp >= battery->pdata->chg_high_temp) | |
724 | pd_index--; | |
725 | } | |
726 | ||
727 | if (pd_index < 0) { | |
728 | if (battery->chg_limit) { | |
729 | input_current = (input_current > (battery->pdata->nv_charge_power / (pd_list->pd_info[0].input_voltage / 1000))) ? | |
730 | (battery->pdata->nv_charge_power / (pd_list->pd_info[0].input_voltage / 1000)) : input_current; | |
731 | pd_index = -1; | |
732 | } else { | |
733 | pd_index = 0; | |
734 | } | |
735 | pd_list->now_pd_index = pd_index; | |
736 | } else { | |
737 | pd_index = | |
738 | (pd_index >= pd_list->max_pd_count) ? (pd_list->max_pd_count - 1) : pd_index; | |
739 | ||
740 | if (pd_list->now_pd_index != pd_index) { | |
741 | /* change input current before request new pdo | |
742 | * if new pdo's input current is less than now | |
743 | */ | |
744 | if (pd_list->pd_info[pd_index].input_current < input_current) { | |
745 | union power_supply_propval value = {0, }; | |
746 | ||
747 | input_current = pd_list->pd_info[pd_index].input_current; | |
748 | value.intval = input_current; | |
749 | battery->input_current = input_current; | |
750 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_SELECT_PDO, | |
751 | SEC_BAT_CURRENT_EVENT_SELECT_PDO); | |
752 | psy_do_property(battery->pdata->charger_name, set, | |
753 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
754 | } | |
755 | /* select next pdo */ | |
756 | battery->pdic_ps_rdy = false; | |
757 | select_pdo(pd_list->pd_info[pd_index].pdo_index); | |
758 | pr_info("%s: change pd_list - index: %d, pdo_index: %d\n", | |
759 | __func__, pd_index, pd_list->pd_info[pd_index].pdo_index); | |
760 | } | |
761 | } | |
762 | pr_info("%s: pd_index(%d), input_current(%d), chg_limit(%d)\n", | |
763 | __func__, pd_index, input_current, battery->chg_limit); | |
764 | } | |
765 | ||
766 | return input_current; | |
767 | } | |
768 | ||
769 | static int sec_bat_check_pd_input_current(struct sec_battery_info *battery, int input_current) | |
770 | { | |
771 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_SELECT_PDO) { | |
772 | input_current = battery->input_current; | |
773 | pr_info("%s: change input_current(%d), cable_type(%d)\n", __func__, input_current, battery->cable_type); | |
774 | } | |
775 | ||
776 | return input_current; | |
777 | } | |
778 | #endif | |
779 | #endif | |
780 | ||
781 | static int sec_bat_check_afc_input_current(struct sec_battery_info *battery, int input_current) | |
782 | { | |
783 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_AFC) { | |
784 | int work_delay = 0; | |
785 | ||
786 | if (!is_wireless_type(battery->cable_type)) { | |
787 | input_current = battery->pdata->pre_afc_input_current; // 1000mA | |
788 | work_delay = battery->pdata->pre_afc_work_delay; | |
789 | } else { | |
790 | input_current = battery->pdata->pre_wc_afc_input_current; | |
791 | /* do not reduce this time, this is for noble pad */ | |
792 | work_delay = battery->pdata->pre_wc_afc_work_delay; | |
793 | } | |
794 | ||
795 | wake_lock(&battery->afc_wake_lock); | |
796 | if (!delayed_work_pending(&battery->afc_work)) | |
797 | queue_delayed_work(battery->monitor_wqueue, | |
798 | &battery->afc_work , msecs_to_jiffies(work_delay)); | |
799 | ||
800 | pr_info("%s: change input_current(%d), cable_type(%d)\n", __func__, input_current, battery->cable_type); | |
801 | } | |
802 | ||
803 | return input_current; | |
804 | } | |
805 | ||
806 | #if defined(CONFIG_CCIC_NOTIFIER) | |
807 | static void sec_bat_get_input_current_in_power_list(struct sec_battery_info *battery) | |
808 | { | |
809 | int pdo_num = battery->pdic_info.sink_status.current_pdo_num; | |
810 | int max_input_current = 0; | |
811 | ||
812 | max_input_current = battery->pdata->charging_current[SEC_BATTERY_CABLE_PDIC].input_current_limit = | |
813 | battery->pdic_info.sink_status.power_list[pdo_num].max_current; | |
814 | ||
815 | pr_info("%s:max_input_current : %dmA\n", __func__, max_input_current); | |
816 | } | |
817 | ||
818 | static void sec_bat_get_charging_current_in_power_list(struct sec_battery_info *battery) | |
819 | { | |
820 | int max_charging_current = 0; | |
821 | int pdo_num = battery->pdic_info.sink_status.current_pdo_num; | |
822 | int pd_power = (battery->pdic_info.sink_status.power_list[pdo_num].max_voltage * | |
823 | battery->pdic_info.sink_status.power_list[pdo_num].max_current); | |
824 | ||
825 | /* We assume that output voltage to float voltage */ | |
826 | max_charging_current = pd_power / (battery->pdata->chg_float_voltage / battery->pdata->chg_float_voltage_conv); | |
827 | max_charging_current = max_charging_current > battery->pdata->max_charging_current ? | |
828 | battery->pdata->max_charging_current : max_charging_current; | |
829 | battery->pdata->charging_current[SEC_BATTERY_CABLE_PDIC].fast_charging_current = max_charging_current; | |
830 | battery->charge_power = pd_power; | |
831 | ||
832 | pr_info("%s:pd_charge_power : %dmW, max_charging_current : %dmA\n", __func__, | |
833 | battery->charge_power, max_charging_current); | |
834 | } | |
835 | #endif | |
836 | ||
837 | static int sec_bat_set_charging_current(struct sec_battery_info *battery) | |
838 | { | |
839 | static int afc_init = false; | |
840 | union power_supply_propval value = {0, }; | |
841 | int input_current = battery->pdata->charging_current[battery->cable_type].input_current_limit, | |
842 | charging_current = battery->pdata->charging_current[battery->cable_type].fast_charging_current, | |
843 | topoff_current = battery->pdata->full_check_current_1st; | |
844 | #if !defined(CONFIG_SEC_FACTORY) | |
845 | int temp = 0; | |
846 | #endif | |
847 | ||
848 | if (battery->aicl_current) | |
849 | input_current = battery->aicl_current; | |
850 | mutex_lock(&battery->iolock); | |
851 | if (battery->cable_type == SEC_BATTERY_CABLE_NONE) { | |
852 | } else { | |
853 | #if !defined(CONFIG_SEC_FACTORY) | |
854 | if (!(battery->current_event & SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL)) { | |
855 | input_current = sec_bat_check_mix_temp(battery, input_current); | |
856 | } | |
857 | #endif | |
858 | ||
859 | /* check input current */ | |
860 | #if !defined(CONFIG_SEC_FACTORY) | |
861 | if (!(battery->current_event & SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL)) { | |
862 | if (is_wireless_type(battery->cable_type) && battery->pdata->wpc_temp_check) { | |
863 | temp = sec_bat_check_wpc_temp(battery, input_current); | |
864 | if (input_current > temp) | |
865 | input_current = temp; | |
866 | } | |
867 | #if defined(CONFIG_CCIC_NOTIFIER) | |
868 | else if (battery->cable_type == SEC_BATTERY_CABLE_PDIC && battery->pdata->chg_temp_check) { | |
869 | input_current = sec_bat_check_pdic_temp(battery, input_current); | |
870 | input_current = sec_bat_check_pd_input_current(battery, input_current); | |
871 | } | |
872 | #endif | |
873 | else if (battery->pdata->chg_temp_check) | |
874 | sec_bat_check_afc_temp(battery, &input_current, &charging_current); | |
875 | } | |
876 | #endif | |
877 | ||
878 | input_current = sec_bat_check_afc_input_current(battery, input_current); | |
879 | /* Set limited max current with hv wire cable when store mode is set and LDU | |
880 | Limited max current should be set with over 5% capacity since target could be turned off during boot up */ | |
881 | if (battery->store_mode && is_hv_wire_type(battery->wire_status) && (battery->capacity >= 5)) { | |
882 | input_current = battery->pdata->store_mode_afc_input_current; | |
883 | } | |
884 | ||
885 | sec_bat_get_charging_current_by_siop(battery, &input_current, &charging_current); | |
886 | ||
887 | /* Calculate wireless input current under the specific conditions (wpc_sleep_mode, chg_limit)*/ | |
888 | if (battery->wc_status != SEC_WIRELESS_PAD_NONE) { | |
889 | input_current = sec_bat_get_wireless_current(battery, input_current); | |
890 | } | |
891 | ||
892 | /* check topoff current */ | |
893 | if (battery->charging_mode == SEC_BATTERY_CHARGING_2ND && | |
894 | battery->pdata->full_check_type_2nd == SEC_BATTERY_FULLCHARGED_CHGPSY) { | |
895 | topoff_current = | |
896 | battery->pdata->full_check_current_2nd; | |
897 | } | |
898 | ||
899 | /* check swelling state */ | |
900 | if (is_wireless_type(battery->cable_type)) { | |
901 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING) { | |
902 | charging_current = (charging_current > battery->pdata->swelling_wc_low_temp_current) ? | |
903 | battery->pdata->swelling_wc_low_temp_current : charging_current; | |
904 | topoff_current = (topoff_current > battery->pdata->swelling_low_temp_topoff) ? | |
905 | battery->pdata->swelling_low_temp_topoff : topoff_current; | |
906 | } else if (battery->current_event & SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING) { | |
907 | charging_current = (charging_current > battery->pdata->swelling_wc_high_temp_current) ? | |
908 | battery->pdata->swelling_wc_high_temp_current : charging_current; | |
909 | topoff_current = (topoff_current > battery->pdata->swelling_high_temp_topoff) ? | |
910 | battery->pdata->swelling_high_temp_topoff : topoff_current; | |
911 | } else if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP) { | |
912 | charging_current = (charging_current > battery->pdata->swelling_wc_low_temp_current) ? | |
913 | battery->pdata->swelling_wc_low_temp_current : charging_current; | |
914 | } | |
915 | } else { | |
916 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING) { | |
917 | charging_current = (charging_current > battery->pdata->swelling_low_temp_current) ? | |
918 | battery->pdata->swelling_low_temp_current : charging_current; | |
919 | topoff_current = (topoff_current > battery->pdata->swelling_low_temp_topoff) ? | |
920 | battery->pdata->swelling_low_temp_topoff : topoff_current; | |
921 | } else if (battery->current_event & SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING) { | |
922 | charging_current = (charging_current > battery->pdata->swelling_high_temp_current) ? | |
923 | battery->pdata->swelling_high_temp_current : charging_current; | |
924 | topoff_current = (topoff_current > battery->pdata->swelling_high_temp_topoff) ? | |
925 | battery->pdata->swelling_high_temp_topoff : topoff_current; | |
926 | } else if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP) { | |
927 | charging_current = (charging_current > battery->pdata->swelling_low_temp_current) ? | |
928 | battery->pdata->swelling_low_temp_current : charging_current; | |
929 | } | |
930 | ||
931 | /* usb unconfigured or suspend*/ | |
932 | if ((battery->cable_type == SEC_BATTERY_CABLE_USB) && !lpcharge && | |
933 | (battery->pdic_info.sink_status.rp_currentlvl == RP_CURRENT_LEVEL_DEFAULT)) { | |
934 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_USB_100MA) { | |
935 | pr_info("%s: usb unconfigured\n", __func__); | |
936 | input_current = USB_CURRENT_UNCONFIGURED; | |
937 | charging_current = USB_CURRENT_UNCONFIGURED; | |
938 | } | |
939 | } | |
940 | } | |
941 | } | |
942 | ||
943 | /* In wireless charging, must be set charging current before input current. */ | |
944 | if (is_wireless_type(battery->cable_type) && | |
945 | battery->charging_current != charging_current) { | |
946 | value.intval = charging_current; | |
947 | psy_do_property(battery->pdata->charger_name, set, | |
948 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
949 | battery->charging_current = charging_current; | |
950 | } | |
951 | /* set input current, charging current */ | |
952 | if ((battery->input_current != input_current) || | |
953 | (battery->charging_current != charging_current)) { | |
954 | /* update charge power */ | |
955 | battery->charge_power = battery->input_voltage * input_current; | |
956 | if (battery->charge_power > battery->max_charge_power) | |
957 | battery->max_charge_power = battery->charge_power; | |
958 | ||
959 | value.intval = input_current; | |
960 | psy_do_property(battery->pdata->charger_name, set, | |
961 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
962 | battery->input_current = input_current; | |
963 | ||
964 | value.intval = charging_current; | |
965 | psy_do_property(battery->pdata->charger_name, set, | |
966 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
967 | ||
968 | if (charging_current <= 100) | |
969 | battery->charging_current = 100; | |
970 | else | |
971 | battery->charging_current = charging_current; | |
972 | pr_info("%s: power(%d), input(%d), charge(%d)\n", __func__, | |
973 | battery->charge_power, battery->input_current, battery->charging_current); | |
974 | } | |
975 | ||
976 | /* set topoff current */ | |
977 | if (battery->topoff_current != topoff_current) { | |
978 | value.intval = topoff_current; | |
979 | psy_do_property(battery->pdata->charger_name, set, | |
980 | POWER_SUPPLY_PROP_CURRENT_FULL, value); | |
981 | battery->topoff_current = topoff_current; | |
982 | } | |
983 | if (!afc_init) { | |
984 | afc_init = true; | |
985 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
986 | value.intval = 1; | |
987 | psy_do_property(battery->pdata->charger_name, set, | |
988 | POWER_SUPPLY_PROP_AFC_CHARGER_MODE, | |
989 | value); | |
990 | #endif | |
991 | } | |
992 | mutex_unlock(&battery->iolock); | |
993 | return 0; | |
994 | } | |
995 | ||
996 | static int sec_bat_set_charge( | |
997 | struct sec_battery_info *battery, | |
998 | int chg_mode) | |
999 | { | |
1000 | union power_supply_propval val = {0, }; | |
1001 | ktime_t current_time = {0, }; | |
1002 | struct timespec ts = {0, }; | |
1003 | ||
1004 | if (battery->cable_type == SEC_BATTERY_CABLE_HMT_CONNECTED) | |
1005 | return 0; | |
1006 | ||
1007 | if ((battery->current_event & SEC_BAT_CURRENT_EVENT_CHARGE_DISABLE) && | |
1008 | (chg_mode == SEC_BAT_CHG_MODE_CHARGING)) { | |
1009 | dev_info(battery->dev, "%s: charge disable by HMT\n", __func__); | |
1010 | chg_mode = SEC_BAT_CHG_MODE_CHARGING_OFF; | |
1011 | } | |
1012 | ||
1013 | battery->charger_mode = chg_mode; | |
1014 | pr_info("%s set %s mode\n", __func__, sec_bat_charge_mode_str[chg_mode]); | |
1015 | ||
1016 | val.intval = battery->status; | |
1017 | psy_do_property(battery->pdata->charger_name, set, | |
1018 | POWER_SUPPLY_PROP_STATUS, val); | |
1019 | current_time = ktime_get_boottime(); | |
1020 | ts = ktime_to_timespec(current_time); | |
1021 | ||
1022 | if (chg_mode == SEC_BAT_CHG_MODE_CHARGING) { | |
1023 | /*Reset charging start time only in initial charging start */ | |
1024 | if (battery->charging_start_time == 0) { | |
1025 | if (ts.tv_sec < 1) | |
1026 | ts.tv_sec = 1; | |
1027 | battery->charging_start_time = ts.tv_sec; | |
1028 | battery->charging_next_time = | |
1029 | battery->pdata->charging_reset_time; | |
1030 | } | |
1031 | battery->charging_block = false; | |
1032 | ||
1033 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
1034 | sec_bat_add_sbm_data(battery, SBM_DATA_SET_CHARGE); | |
1035 | #endif | |
1036 | } else { | |
1037 | battery->charging_start_time = 0; | |
1038 | battery->charging_passed_time = 0; | |
1039 | battery->charging_next_time = 0; | |
1040 | battery->charging_fullcharged_time = 0; | |
1041 | battery->full_check_cnt = 0; | |
1042 | battery->charging_block = true; | |
1043 | #if defined(CONFIG_STEP_CHARGING) | |
1044 | sec_bat_reset_step_charging(battery); | |
1045 | #endif | |
1046 | #if defined(CONFIG_BATTERY_CISD) | |
1047 | battery->usb_overheat_check = false; | |
1048 | battery->cisd.ab_vbat_check_count = 0; | |
1049 | if (chg_mode == SEC_BAT_CHG_MODE_BUCK_OFF) { | |
1050 | battery->cisd.data[CISD_DATA_BUCK_OFF]++; | |
1051 | battery->cisd.data[CISD_DATA_BUCK_OFF_PER_DAY]++; | |
1052 | } | |
1053 | #endif | |
1054 | } | |
1055 | ||
1056 | battery->temp_highlimit_cnt = 0; | |
1057 | battery->temp_high_cnt = 0; | |
1058 | battery->temp_low_cnt = 0; | |
1059 | battery->temp_recover_cnt = 0; | |
1060 | ||
1061 | val.intval = chg_mode; | |
1062 | psy_do_property(battery->pdata->charger_name, set, | |
1063 | POWER_SUPPLY_PROP_CHARGING_ENABLED, val); | |
1064 | ||
1065 | return 0; | |
1066 | } | |
1067 | ||
1068 | static bool sec_bat_check_by_psy(struct sec_battery_info *battery) | |
1069 | { | |
1070 | char *psy_name = NULL; | |
1071 | union power_supply_propval value = {0, }; | |
1072 | bool ret = true; | |
1073 | ||
1074 | switch (battery->pdata->battery_check_type) { | |
1075 | case SEC_BATTERY_CHECK_PMIC: | |
1076 | psy_name = battery->pdata->pmic_name; | |
1077 | break; | |
1078 | case SEC_BATTERY_CHECK_FUELGAUGE: | |
1079 | psy_name = battery->pdata->fuelgauge_name; | |
1080 | break; | |
1081 | case SEC_BATTERY_CHECK_CHARGER: | |
1082 | psy_name = battery->pdata->charger_name; | |
1083 | break; | |
1084 | default: | |
1085 | dev_err(battery->dev, | |
1086 | "%s: Invalid Battery Check Type\n", __func__); | |
1087 | ret = false; | |
1088 | goto battery_check_error; | |
1089 | break; | |
1090 | } | |
1091 | ||
1092 | psy_do_property(psy_name, get, | |
1093 | POWER_SUPPLY_PROP_PRESENT, value); | |
1094 | ret = (bool)value.intval; | |
1095 | ||
1096 | battery_check_error: | |
1097 | return ret; | |
1098 | } | |
1099 | ||
1100 | static bool sec_bat_check(struct sec_battery_info *battery) | |
1101 | { | |
1102 | bool ret = true; | |
1103 | ||
1104 | if (battery->factory_mode || battery->is_jig_on) { | |
1105 | dev_dbg(battery->dev, "%s: No need to check in factory mode\n", | |
1106 | __func__); | |
1107 | return ret; | |
1108 | } | |
1109 | ||
1110 | if (battery->health != POWER_SUPPLY_HEALTH_GOOD && | |
1111 | battery->health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) { | |
1112 | dev_dbg(battery->dev, "%s: No need to check\n", __func__); | |
1113 | return ret; | |
1114 | } | |
1115 | ||
1116 | switch (battery->pdata->battery_check_type) { | |
1117 | case SEC_BATTERY_CHECK_ADC: | |
1118 | if(battery->cable_type == SEC_BATTERY_CABLE_NONE) | |
1119 | ret = battery->present; | |
1120 | else | |
1121 | ret = sec_bat_check_vf_adc(battery); | |
1122 | break; | |
1123 | case SEC_BATTERY_CHECK_INT: | |
1124 | case SEC_BATTERY_CHECK_CALLBACK: | |
1125 | if(battery->cable_type == SEC_BATTERY_CABLE_NONE) { | |
1126 | ret = battery->present; | |
1127 | } else { | |
1128 | if (battery->pdata->check_battery_callback) | |
1129 | ret = battery->pdata->check_battery_callback(); | |
1130 | } | |
1131 | break; | |
1132 | case SEC_BATTERY_CHECK_PMIC: | |
1133 | case SEC_BATTERY_CHECK_FUELGAUGE: | |
1134 | case SEC_BATTERY_CHECK_CHARGER: | |
1135 | ret = sec_bat_check_by_psy(battery); | |
1136 | break; | |
1137 | case SEC_BATTERY_CHECK_NONE: | |
1138 | dev_dbg(battery->dev, "%s: No Check\n", __func__); | |
1139 | default: | |
1140 | break; | |
1141 | } | |
1142 | ||
1143 | return ret; | |
1144 | } | |
1145 | ||
1146 | static bool sec_bat_get_cable_type( | |
1147 | struct sec_battery_info *battery, | |
1148 | int cable_source_type) | |
1149 | { | |
1150 | bool ret = false; | |
1151 | int cable_type = battery->cable_type; | |
1152 | ||
1153 | if (cable_source_type & SEC_BATTERY_CABLE_SOURCE_CALLBACK) { | |
1154 | if (battery->pdata->check_cable_callback) | |
1155 | cable_type = | |
1156 | battery->pdata->check_cable_callback(); | |
1157 | } | |
1158 | ||
1159 | if (cable_source_type & SEC_BATTERY_CABLE_SOURCE_ADC) { | |
1160 | if (gpio_get_value_cansleep( | |
1161 | battery->pdata->bat_gpio_ta_nconnected) ^ | |
1162 | battery->pdata->bat_polarity_ta_nconnected) | |
1163 | cable_type = SEC_BATTERY_CABLE_NONE; | |
1164 | else | |
1165 | cable_type = | |
1166 | sec_bat_get_charger_type_adc(battery); | |
1167 | } | |
1168 | ||
1169 | if (battery->cable_type == cable_type) { | |
1170 | dev_dbg(battery->dev, | |
1171 | "%s: No need to change cable status\n", __func__); | |
1172 | } else { | |
1173 | if (cable_type < SEC_BATTERY_CABLE_NONE || | |
1174 | cable_type >= SEC_BATTERY_CABLE_MAX) { | |
1175 | dev_err(battery->dev, | |
1176 | "%s: Invalid cable type\n", __func__); | |
1177 | } else { | |
1178 | battery->cable_type = cable_type; | |
1179 | if (battery->pdata->check_cable_result_callback) | |
1180 | battery->pdata->check_cable_result_callback( | |
1181 | battery->cable_type); | |
1182 | ||
1183 | ret = true; | |
1184 | ||
1185 | dev_dbg(battery->dev, "%s: Cable Changed (%d)\n", | |
1186 | __func__, battery->cable_type); | |
1187 | } | |
1188 | } | |
1189 | ||
1190 | return ret; | |
1191 | } | |
1192 | ||
1193 | static void sec_bat_set_charging_status(struct sec_battery_info *battery, | |
1194 | int status) { | |
1195 | union power_supply_propval value = {0, }; | |
1196 | ||
1197 | switch (status) { | |
1198 | case POWER_SUPPLY_STATUS_CHARGING: | |
1199 | if (battery->siop_level != 100) | |
1200 | battery->stop_timer = true; | |
1201 | break; | |
1202 | case POWER_SUPPLY_STATUS_NOT_CHARGING: | |
1203 | case POWER_SUPPLY_STATUS_DISCHARGING: | |
1204 | if ((battery->status == POWER_SUPPLY_STATUS_FULL || | |
1205 | (battery->capacity == 100 && !battery->slate_mode)) && | |
1206 | !battery->store_mode) { | |
1207 | value.intval = 100; | |
1208 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
1209 | POWER_SUPPLY_PROP_CHARGE_FULL, value); | |
1210 | /* To get SOC value (NOT raw SOC), need to reset value */ | |
1211 | value.intval = 0; | |
1212 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
1213 | POWER_SUPPLY_PROP_CAPACITY, value); | |
1214 | battery->capacity = value.intval; | |
1215 | } | |
1216 | battery->expired_time = battery->pdata->expired_time; | |
1217 | battery->prev_safety_time = 0; | |
1218 | break; | |
1219 | case POWER_SUPPLY_STATUS_FULL: | |
1220 | if (is_wireless_type(battery->cable_type)) { | |
1221 | bool send_cs100_cmd = true; | |
1222 | ||
1223 | #ifdef CONFIG_CS100_JPNCONCEPT | |
1224 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
1225 | POWER_SUPPLY_EXT_PROP_WIRELESS_TX_ID, value); | |
1226 | ||
1227 | /* In case of the JPN PAD, this pad blocks the charge after give the cs100 command. */ | |
1228 | send_cs100_cmd = (battery->charging_mode == SEC_BATTERY_CHARGING_2ND || value.intval); | |
1229 | #endif | |
1230 | if (send_cs100_cmd) { | |
1231 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
1232 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
1233 | POWER_SUPPLY_PROP_STATUS, value); | |
1234 | } | |
1235 | } | |
1236 | break; | |
1237 | default: | |
1238 | break; | |
1239 | } | |
1240 | battery->status = status; | |
1241 | } | |
1242 | ||
1243 | static bool sec_bat_battery_cable_check(struct sec_battery_info *battery) | |
1244 | { | |
1245 | if (!sec_bat_check(battery)) { | |
1246 | if (battery->check_count < battery->pdata->check_count) | |
1247 | battery->check_count++; | |
1248 | else { | |
1249 | dev_err(battery->dev, | |
1250 | "%s: Battery Disconnected\n", __func__); | |
1251 | battery->present = false; | |
1252 | battery->health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; | |
1253 | ||
1254 | if (battery->status != | |
1255 | POWER_SUPPLY_STATUS_DISCHARGING) { | |
1256 | sec_bat_set_charging_status(battery, | |
1257 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
1258 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_BUCK_OFF); | |
1259 | } | |
1260 | ||
1261 | if (battery->pdata->check_battery_result_callback) | |
1262 | battery->pdata-> | |
1263 | check_battery_result_callback(); | |
1264 | return false; | |
1265 | } | |
1266 | } else | |
1267 | battery->check_count = 0; | |
1268 | ||
1269 | battery->present = true; | |
1270 | ||
1271 | if (battery->health == POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) { | |
1272 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
1273 | ||
1274 | if (battery->status == POWER_SUPPLY_STATUS_NOT_CHARGING) { | |
1275 | sec_bat_set_charging_status(battery, | |
1276 | POWER_SUPPLY_STATUS_CHARGING); | |
1277 | #if defined(CONFIG_BATTERY_SWELLING) | |
1278 | if (!battery->swelling_mode) | |
1279 | #endif | |
1280 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
1281 | } | |
1282 | } | |
1283 | ||
1284 | dev_dbg(battery->dev, "%s: Battery Connected\n", __func__); | |
1285 | ||
1286 | if (battery->pdata->cable_check_type & | |
1287 | SEC_BATTERY_CABLE_CHECK_POLLING) { | |
1288 | if (sec_bat_get_cable_type(battery, | |
1289 | battery->pdata->cable_source_type)) { | |
1290 | wake_lock(&battery->cable_wake_lock); | |
1291 | queue_delayed_work(battery->monitor_wqueue, | |
1292 | &battery->cable_work, 0); | |
1293 | } | |
1294 | } | |
1295 | return true; | |
1296 | } | |
1297 | ||
1298 | static int sec_bat_ovp_uvlo_by_psy(struct sec_battery_info *battery) | |
1299 | { | |
1300 | char *psy_name = NULL; | |
1301 | union power_supply_propval value = {0, }; | |
1302 | ||
1303 | value.intval = POWER_SUPPLY_HEALTH_GOOD; | |
1304 | ||
1305 | switch (battery->pdata->ovp_uvlo_check_type) { | |
1306 | case SEC_BATTERY_OVP_UVLO_PMICPOLLING: | |
1307 | psy_name = battery->pdata->pmic_name; | |
1308 | break; | |
1309 | case SEC_BATTERY_OVP_UVLO_CHGPOLLING: | |
1310 | psy_name = battery->pdata->charger_name; | |
1311 | break; | |
1312 | default: | |
1313 | dev_err(battery->dev, | |
1314 | "%s: Invalid OVP/UVLO Check Type\n", __func__); | |
1315 | goto ovp_uvlo_check_error; | |
1316 | break; | |
1317 | } | |
1318 | ||
1319 | psy_do_property(psy_name, get, | |
1320 | POWER_SUPPLY_PROP_HEALTH, value); | |
1321 | ||
1322 | ovp_uvlo_check_error: | |
1323 | return value.intval; | |
1324 | } | |
1325 | ||
1326 | static bool sec_bat_ovp_uvlo_result( | |
1327 | struct sec_battery_info *battery, int health) | |
1328 | { | |
1329 | if (battery->health != health) { | |
1330 | battery->health = health; | |
1331 | switch (health) { | |
1332 | case POWER_SUPPLY_HEALTH_GOOD: | |
1333 | dev_info(battery->dev, "%s: Safe voltage\n", __func__); | |
1334 | dev_info(battery->dev, "%s: is_recharging : %d\n", __func__, battery->is_recharging); | |
1335 | sec_bat_set_charging_status(battery, | |
1336 | POWER_SUPPLY_STATUS_CHARGING); | |
1337 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
1338 | #if defined(CONFIG_BATTERY_SWELLING) | |
1339 | if (!battery->swelling_mode) | |
1340 | #endif | |
1341 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
1342 | battery->health_check_count = 0; | |
1343 | break; | |
1344 | case POWER_SUPPLY_HEALTH_OVERVOLTAGE: | |
1345 | case POWER_SUPPLY_HEALTH_UNDERVOLTAGE: | |
1346 | dev_info(battery->dev, | |
1347 | "%s: Unsafe voltage (%d)\n", | |
1348 | __func__, health); | |
1349 | sec_bat_set_charging_status(battery, | |
1350 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
1351 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
1352 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
1353 | battery->is_recharging = false; | |
1354 | battery->health_check_count = DEFAULT_HEALTH_CHECK_COUNT; | |
1355 | #if defined(CONFIG_BATTERY_CISD) | |
1356 | battery->cisd.data[CISD_DATA_UNSAFETY_VOLTAGE]++; | |
1357 | battery->cisd.data[CISD_DATA_UNSAFE_VOLTAGE_PER_DAY]++; | |
1358 | #endif | |
1359 | /* Take the wakelock during 10 seconds | |
1360 | when over-voltage status is detected */ | |
1361 | wake_lock_timeout(&battery->vbus_wake_lock, HZ * 10); | |
1362 | break; | |
1363 | } | |
1364 | power_supply_changed(battery->psy_bat); | |
1365 | return true; | |
1366 | } | |
1367 | ||
1368 | return false; | |
1369 | } | |
1370 | ||
1371 | static bool sec_bat_ovp_uvlo(struct sec_battery_info *battery) | |
1372 | { | |
1373 | int health = POWER_SUPPLY_HEALTH_GOOD; | |
1374 | ||
1375 | if (battery->wdt_kick_disable) { | |
1376 | dev_dbg(battery->dev, | |
1377 | "%s: No need to check in wdt test\n", | |
1378 | __func__); | |
1379 | return false; | |
1380 | } else if ((battery->status == POWER_SUPPLY_STATUS_FULL) && | |
1381 | (battery->charging_mode == SEC_BATTERY_CHARGING_NONE)) { | |
1382 | dev_dbg(battery->dev, "%s: No need to check in Full status", __func__); | |
1383 | return false; | |
1384 | } | |
1385 | ||
1386 | if (battery->health != POWER_SUPPLY_HEALTH_GOOD && | |
1387 | battery->health != POWER_SUPPLY_HEALTH_OVERVOLTAGE && | |
1388 | battery->health != POWER_SUPPLY_HEALTH_UNDERVOLTAGE) { | |
1389 | dev_dbg(battery->dev, "%s: No need to check\n", __func__); | |
1390 | return false; | |
1391 | } | |
1392 | ||
1393 | health = battery->health; | |
1394 | ||
1395 | switch (battery->pdata->ovp_uvlo_check_type) { | |
1396 | case SEC_BATTERY_OVP_UVLO_CALLBACK: | |
1397 | if (battery->pdata->ovp_uvlo_callback) | |
1398 | health = battery->pdata->ovp_uvlo_callback(); | |
1399 | break; | |
1400 | case SEC_BATTERY_OVP_UVLO_PMICPOLLING: | |
1401 | case SEC_BATTERY_OVP_UVLO_CHGPOLLING: | |
1402 | health = sec_bat_ovp_uvlo_by_psy(battery); | |
1403 | break; | |
1404 | case SEC_BATTERY_OVP_UVLO_PMICINT: | |
1405 | case SEC_BATTERY_OVP_UVLO_CHGINT: | |
1406 | /* nothing for interrupt check */ | |
1407 | default: | |
1408 | break; | |
1409 | } | |
1410 | ||
1411 | /* Move the location for calling the get_health | |
1412 | in case of attaching the jig */ | |
1413 | if (battery->factory_mode || battery->is_jig_on) { | |
1414 | dev_dbg(battery->dev, | |
1415 | "%s: No need to check in factory mode\n", | |
1416 | __func__); | |
1417 | return false; | |
1418 | } | |
1419 | ||
1420 | return sec_bat_ovp_uvlo_result(battery, health); | |
1421 | } | |
1422 | ||
1423 | static bool sec_bat_check_recharge(struct sec_battery_info *battery) | |
1424 | { | |
1425 | #if defined(CONFIG_BATTERY_SWELLING) | |
1426 | if (battery->swelling_mode == SWELLING_MODE_CHARGING || | |
1427 | battery->swelling_mode == SWELLING_MODE_FULL) { | |
1428 | pr_info("%s: Skip normal recharge check routine for swelling mode\n", | |
1429 | __func__); | |
1430 | return false; | |
1431 | } | |
1432 | #endif | |
1433 | if ((battery->status == POWER_SUPPLY_STATUS_CHARGING) && | |
1434 | (battery->pdata->full_condition_type & | |
1435 | SEC_BATTERY_FULL_CONDITION_NOTIMEFULL) && | |
1436 | (battery->charging_mode == SEC_BATTERY_CHARGING_NONE)) { | |
1437 | dev_info(battery->dev, | |
1438 | "%s: Re-charging by NOTIMEFULL (%d)\n", | |
1439 | __func__, battery->capacity); | |
1440 | goto check_recharge_check_count; | |
1441 | } | |
1442 | ||
1443 | if (battery->status == POWER_SUPPLY_STATUS_FULL && | |
1444 | battery->charging_mode == SEC_BATTERY_CHARGING_NONE) { | |
1445 | int recharging_voltage = battery->pdata->recharge_condition_vcell; | |
1446 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP) { | |
1447 | /* float voltage - 150mV */ | |
1448 | recharging_voltage =\ | |
1449 | (battery->pdata->chg_float_voltage /\ | |
1450 | battery->pdata->chg_float_voltage_conv) - 150; | |
1451 | dev_info(battery->dev, "%s: recharging voltage changed by low temp(%d)\n", | |
1452 | __func__, recharging_voltage); | |
1453 | } | |
1454 | dev_info(battery->dev, "%s: recharging voltage (%d)\n", | |
1455 | __func__, recharging_voltage); | |
1456 | ||
1457 | if ((battery->pdata->recharge_condition_type & | |
1458 | SEC_BATTERY_RECHARGE_CONDITION_SOC) && | |
1459 | (battery->capacity <= | |
1460 | battery->pdata->recharge_condition_soc)) { | |
1461 | battery->expired_time = battery->pdata->recharging_expired_time; | |
1462 | battery->prev_safety_time = 0; | |
1463 | dev_info(battery->dev, | |
1464 | "%s: Re-charging by SOC (%d)\n", | |
1465 | __func__, battery->capacity); | |
1466 | goto check_recharge_check_count; | |
1467 | } | |
1468 | ||
1469 | if ((battery->pdata->recharge_condition_type & | |
1470 | SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL) && | |
1471 | (battery->voltage_avg <= recharging_voltage)) { | |
1472 | battery->expired_time = battery->pdata->recharging_expired_time; | |
1473 | battery->prev_safety_time = 0; | |
1474 | dev_info(battery->dev, | |
1475 | "%s: Re-charging by average VCELL (%d)\n", | |
1476 | __func__, battery->voltage_avg); | |
1477 | goto check_recharge_check_count; | |
1478 | } | |
1479 | ||
1480 | if ((battery->pdata->recharge_condition_type & | |
1481 | SEC_BATTERY_RECHARGE_CONDITION_VCELL) && | |
1482 | (battery->voltage_now <= recharging_voltage)) { | |
1483 | battery->expired_time = battery->pdata->recharging_expired_time; | |
1484 | battery->prev_safety_time = 0; | |
1485 | dev_info(battery->dev, | |
1486 | "%s: Re-charging by VCELL (%d)\n", | |
1487 | __func__, battery->voltage_now); | |
1488 | goto check_recharge_check_count; | |
1489 | } | |
1490 | } | |
1491 | ||
1492 | battery->recharge_check_cnt = 0; | |
1493 | return false; | |
1494 | ||
1495 | check_recharge_check_count: | |
1496 | if (battery->recharge_check_cnt < | |
1497 | battery->pdata->recharge_check_count) | |
1498 | battery->recharge_check_cnt++; | |
1499 | dev_dbg(battery->dev, | |
1500 | "%s: recharge count = %d\n", | |
1501 | __func__, battery->recharge_check_cnt); | |
1502 | ||
1503 | if (battery->recharge_check_cnt >= | |
1504 | battery->pdata->recharge_check_count) | |
1505 | return true; | |
1506 | else | |
1507 | return false; | |
1508 | } | |
1509 | ||
1510 | static bool sec_bat_voltage_check(struct sec_battery_info *battery) | |
1511 | { | |
1512 | union power_supply_propval value = {0, }; | |
1513 | ||
1514 | if (battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
1515 | dev_dbg(battery->dev, | |
1516 | "%s: Charging Disabled\n", __func__); | |
1517 | return true; | |
1518 | } | |
1519 | ||
1520 | /* OVP/UVLO check */ | |
1521 | if (sec_bat_ovp_uvlo(battery)) { | |
1522 | if (battery->pdata->ovp_uvlo_result_callback) | |
1523 | battery->pdata-> | |
1524 | ovp_uvlo_result_callback(battery->health); | |
1525 | return false; | |
1526 | } | |
1527 | ||
1528 | if ((battery->status == POWER_SUPPLY_STATUS_FULL) && | |
1529 | #if defined(CONFIG_BATTERY_SWELLING) | |
1530 | (battery->charging_mode == SEC_BATTERY_CHARGING_2ND || | |
1531 | battery->is_recharging || battery->swelling_mode)) { | |
1532 | #else | |
1533 | (battery->charging_mode == SEC_BATTERY_CHARGING_2ND || | |
1534 | battery->is_recharging)) { | |
1535 | #endif | |
1536 | value.intval = 0; | |
1537 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
1538 | POWER_SUPPLY_PROP_CAPACITY, value); | |
1539 | if (value.intval < | |
1540 | battery->pdata->full_condition_soc && | |
1541 | battery->voltage_now < | |
1542 | (battery->pdata->recharge_condition_vcell - 50)) { | |
1543 | sec_bat_set_charging_status(battery, | |
1544 | POWER_SUPPLY_STATUS_CHARGING); | |
1545 | dev_info(battery->dev, | |
1546 | "%s: battery status full -> charging, RepSOC(%d)\n", __func__, value.intval); | |
1547 | return false; | |
1548 | } | |
1549 | } | |
1550 | ||
1551 | /* Re-Charging check */ | |
1552 | if (sec_bat_check_recharge(battery)) { | |
1553 | if (battery->pdata->full_check_type != | |
1554 | SEC_BATTERY_FULLCHARGED_NONE) | |
1555 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
1556 | else | |
1557 | battery->charging_mode = SEC_BATTERY_CHARGING_2ND; | |
1558 | battery->is_recharging = true; | |
1559 | #if defined(CONFIG_BATTERY_CISD) | |
1560 | battery->cisd.recharge_count++; | |
1561 | battery->cisd.recharge_count_2++; | |
1562 | battery->cisd.data[CISD_DATA_RECHARGING_COUNT]++; | |
1563 | battery->cisd.data[CISD_DATA_RECHARGING_COUNT_PER_DAY]++; | |
1564 | #endif | |
1565 | #if defined(CONFIG_BATTERY_SWELLING) | |
1566 | if (!battery->swelling_mode) | |
1567 | #endif | |
1568 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
1569 | return false; | |
1570 | } | |
1571 | ||
1572 | return true; | |
1573 | } | |
1574 | ||
1575 | #if defined(CONFIG_BATTERY_SWELLING) | |
1576 | static void sec_bat_swelling_check(struct sec_battery_info *battery) | |
1577 | { | |
1578 | union power_supply_propval val = {0, }; | |
1579 | int swelling_rechg_voltage = battery->pdata->swelling_high_rechg_voltage; | |
1580 | bool en_swelling = false, en_rechg = false; | |
1581 | int swelling_high_recovery = battery->pdata->swelling_high_temp_recov; | |
1582 | ||
1583 | if (is_wireless_type(battery->cable_type)) { | |
1584 | swelling_high_recovery = battery->pdata->swelling_wc_high_temp_recov; | |
1585 | } | |
1586 | pr_info("%s: swelling highblock(%d), highrecov(%d)\n", __func__, battery->pdata->swelling_high_temp_block, swelling_high_recovery); | |
1587 | ||
1588 | psy_do_property(battery->pdata->charger_name, get, | |
1589 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
1590 | ||
1591 | pr_info("%s: status(%d), swell_mode(%d:%d:%d), cv(%d)mV, temp(%d)\n", | |
1592 | __func__, battery->status, battery->swelling_mode, | |
1593 | battery->charging_block, (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP), | |
1594 | val.intval, battery->temperature); | |
1595 | ||
1596 | /* swelling_mode | |
1597 | under voltage over voltage, battery missing */ | |
1598 | if ((battery->status == POWER_SUPPLY_STATUS_DISCHARGING) ||\ | |
1599 | (battery->status == POWER_SUPPLY_STATUS_NOT_CHARGING) || | |
1600 | battery->skip_swelling) { | |
1601 | pr_debug("%s: DISCHARGING or NOT-CHARGING or 15 test mode. stop swelling mode\n", __func__); | |
1602 | battery->swelling_mode = SWELLING_MODE_NONE; | |
1603 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
1604 | goto skip_swelling_check; | |
1605 | } | |
1606 | ||
1607 | if (!battery->swelling_mode) { | |
1608 | if (((battery->temperature >= battery->pdata->swelling_high_temp_block) || | |
1609 | (battery->temperature <= battery->pdata->swelling_low_temp_block_2nd)) && | |
1610 | battery->pdata->temp_check_type) { | |
1611 | pr_info("%s: swelling mode start. stop charging\n", __func__); | |
1612 | battery->swelling_mode = SWELLING_MODE_CHARGING; | |
1613 | battery->swelling_full_check_cnt = 0; | |
1614 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_BUCK_OFF); | |
1615 | ||
1616 | if (battery->temperature >= battery->pdata->swelling_high_temp_block) { | |
1617 | #if defined(CONFIG_BATTERY_CISD) | |
1618 | battery->cisd.data[CISD_DATA_HIGH_TEMP_SWELLING]++; | |
1619 | battery->cisd.data[CISD_DATA_HIGH_TEMP_SWELLING_PER_DAY]++; | |
1620 | #endif | |
1621 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING, | |
1622 | SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
1623 | } else if (battery->temperature <= battery->pdata->swelling_low_temp_block_2nd) { | |
1624 | #if defined(CONFIG_BATTERY_CISD) | |
1625 | battery->cisd.data[CISD_DATA_LOW_TEMP_SWELLING]++; | |
1626 | battery->cisd.data[CISD_DATA_LOW_TEMP_SWELLING_PER_DAY]++; | |
1627 | #endif | |
1628 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING, | |
1629 | SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
1630 | } | |
1631 | en_swelling = true; | |
1632 | } else if ((battery->temperature <= battery->pdata->swelling_low_temp_block_1st) && | |
1633 | !(battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP)) { | |
1634 | pr_info("%s: low temperature reduce current\n", __func__); | |
1635 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP, | |
1636 | SEC_BAT_CURRENT_EVENT_LOW_TEMP); | |
1637 | } else if ((battery->temperature >= battery->pdata->swelling_low_temp_recov_1st) && | |
1638 | (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP)) { | |
1639 | pr_info("%s: normal temperature temperature recover current\n", __func__); | |
1640 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_LOW_TEMP); | |
1641 | } | |
1642 | } | |
1643 | ||
1644 | if (!battery->voltage_now) | |
1645 | return; | |
1646 | ||
1647 | if (battery->swelling_mode) { | |
1648 | if (battery->temperature <= battery->pdata->swelling_low_temp_recov_2nd) { | |
1649 | swelling_rechg_voltage = battery->pdata->swelling_low_rechg_voltage; | |
1650 | } | |
1651 | ||
1652 | if ((battery->temperature <= swelling_high_recovery) && | |
1653 | (battery->temperature >= battery->pdata->swelling_low_temp_recov_2nd)) { | |
1654 | pr_info("%s: swelling mode end. restart charging\n", __func__); | |
1655 | battery->swelling_mode = SWELLING_MODE_NONE; | |
1656 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
1657 | if ((battery->temperature <= battery->pdata->swelling_low_temp_block_1st) || | |
1658 | ((battery->temperature < battery->pdata->swelling_low_temp_recov_1st) && | |
1659 | (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING))) { | |
1660 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP, | |
1661 | SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
1662 | } else { | |
1663 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
1664 | } | |
1665 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
1666 | /* restore 4.4V float voltage */ | |
1667 | val.intval = battery->pdata->swelling_normal_float_voltage; | |
1668 | psy_do_property(battery->pdata->charger_name, set, | |
1669 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
1670 | #if defined(CONFIG_BATTERY_CISD) | |
1671 | battery->cisd.data[CISD_DATA_SWELLING_RECOVERY_CNT]++; | |
1672 | battery->cisd.data[CISD_DATA_SWELLING_RECOVERY_CNT_PER_DAY]++; | |
1673 | #endif | |
1674 | } else if (battery->voltage_now < swelling_rechg_voltage && | |
1675 | battery->charging_block) { | |
1676 | pr_info("%s: swelling mode recharging start. Vbatt(%d)\n", | |
1677 | __func__, battery->voltage_now); | |
1678 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
1679 | en_rechg = true; | |
1680 | /* change drop float voltage */ | |
1681 | val.intval = battery->pdata->swelling_drop_float_voltage; | |
1682 | psy_do_property(battery->pdata->charger_name, set, | |
1683 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
1684 | /* set charging enable */ | |
1685 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
1686 | if (battery->temperature < battery->pdata->swelling_low_temp_recov_2nd) { | |
1687 | pr_info("%s: swelling mode reduce charging current(LOW-temp:%d)\n", | |
1688 | __func__, battery->temperature); | |
1689 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING, | |
1690 | SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
1691 | } else if (battery->temperature > swelling_high_recovery) { | |
1692 | pr_info("%s: swelling mode reduce charging current(HIGH-temp:%d)\n", | |
1693 | __func__, battery->temperature); | |
1694 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING, | |
1695 | SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
1696 | } | |
1697 | #if defined(CONFIG_BATTERY_CISD) | |
1698 | battery->cisd.data[CISD_DATA_SWELLING_CHARGING_COUNT]++; | |
1699 | battery->cisd.data[CISD_DATA_SWELLING_CHARGING_COUNT_PER_DAY]++; | |
1700 | #endif | |
1701 | } | |
1702 | } | |
1703 | ||
1704 | if (en_swelling && !en_rechg) { | |
1705 | pr_info("%s : SAFETY TIME RESET (SWELLING MODE CHARING STOP!)\n", __func__); | |
1706 | battery->expired_time = battery->pdata->expired_time; | |
1707 | battery->prev_safety_time = 0; | |
1708 | } | |
1709 | ||
1710 | skip_swelling_check: | |
1711 | dev_dbg(battery->dev, "%s end\n", __func__); | |
1712 | } | |
1713 | #endif | |
1714 | ||
1715 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
1716 | static bool sec_bat_set_aging_step(struct sec_battery_info *battery, int step) | |
1717 | { | |
1718 | union power_supply_propval value = {0, }; | |
1719 | ||
1720 | if (battery->pdata->num_age_step <= 0 || step < 0 || step >= battery->pdata->num_age_step) { | |
1721 | pr_info("%s: [AGE] abnormal age step : %d/%d\n", | |
1722 | __func__, step, battery->pdata->num_age_step-1); | |
1723 | return false; | |
1724 | } | |
1725 | ||
1726 | battery->pdata->age_step = step; | |
1727 | ||
1728 | /* float voltage */ | |
1729 | battery->pdata->chg_float_voltage = | |
1730 | battery->pdata->age_data[battery->pdata->age_step].float_voltage; | |
1731 | battery->pdata->swelling_normal_float_voltage = | |
1732 | battery->pdata->chg_float_voltage; | |
1733 | if (!battery->swelling_mode) { | |
1734 | value.intval = battery->pdata->chg_float_voltage; | |
1735 | psy_do_property(battery->pdata->charger_name, set, | |
1736 | POWER_SUPPLY_PROP_VOLTAGE_MAX, value); | |
1737 | } | |
1738 | ||
1739 | /* full/recharge condition */ | |
1740 | battery->pdata->recharge_condition_vcell = | |
1741 | battery->pdata->age_data[battery->pdata->age_step].recharge_condition_vcell; | |
1742 | battery->pdata->full_condition_soc = | |
1743 | battery->pdata->age_data[battery->pdata->age_step].full_condition_soc; | |
1744 | battery->pdata->full_condition_vcell = | |
1745 | battery->pdata->age_data[battery->pdata->age_step].full_condition_vcell; | |
1746 | ||
1747 | value.intval = battery->pdata->full_condition_soc; | |
1748 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
1749 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, value); | |
1750 | ||
1751 | dev_info(battery->dev, | |
1752 | "%s: Step(%d/%d), Cycle(%d), float_v(%d), r_v(%d), f_s(%d), f_vl(%d)\n", | |
1753 | __func__, | |
1754 | battery->pdata->age_step, battery->pdata->num_age_step-1, battery->batt_cycle, | |
1755 | battery->pdata->chg_float_voltage, | |
1756 | battery->pdata->recharge_condition_vcell, | |
1757 | battery->pdata->full_condition_soc, | |
1758 | battery->pdata->full_condition_vcell); | |
1759 | ||
1760 | return true; | |
1761 | } | |
1762 | ||
1763 | static void sec_bat_aging_check(struct sec_battery_info *battery) | |
1764 | { | |
1765 | int prev_step = battery->pdata->age_step; | |
1766 | int calc_step = -1; | |
1767 | bool ret = 0; | |
1768 | ||
1769 | if (battery->pdata->num_age_step <= 0 || battery->batt_cycle < 0) | |
1770 | return; | |
1771 | ||
1772 | if (battery->temperature < 50) { | |
1773 | pr_info("%s: [AGE] skip (temperature:%d)\n", __func__, battery->temperature); | |
1774 | return; | |
1775 | } | |
1776 | ||
1777 | for (calc_step = battery->pdata->num_age_step - 1; calc_step >= 0; calc_step--) { | |
1778 | if (battery->pdata->age_data[calc_step].cycle <= battery->batt_cycle) | |
1779 | break; | |
1780 | } | |
1781 | ||
1782 | if (calc_step == prev_step) | |
1783 | return; | |
1784 | ||
1785 | ret = sec_bat_set_aging_step(battery, calc_step); | |
1786 | dev_info(battery->dev, | |
1787 | "%s: %s change step (%d->%d), Cycle(%d)\n", | |
1788 | __func__, ret ? "Succeed in" : "Fail to", | |
1789 | prev_step, battery->pdata->age_step, battery->batt_cycle); | |
1790 | } | |
1791 | #endif | |
1792 | ||
1793 | static bool sec_bat_temperature( | |
1794 | struct sec_battery_info *battery) | |
1795 | { | |
1796 | bool ret; | |
1797 | ret = true; | |
1798 | ||
1799 | if (is_wireless_type(battery->cable_type)) { | |
1800 | battery->temp_highlimit_threshold = | |
1801 | battery->pdata->temp_highlimit_threshold_normal; | |
1802 | battery->temp_highlimit_recovery = | |
1803 | battery->pdata->temp_highlimit_recovery_normal; | |
1804 | battery->temp_high_threshold = | |
1805 | battery->pdata->wpc_high_threshold_normal; | |
1806 | battery->temp_high_recovery = | |
1807 | battery->pdata->wpc_high_recovery_normal; | |
1808 | battery->temp_low_recovery = | |
1809 | battery->pdata->wpc_low_recovery_normal; | |
1810 | battery->temp_low_threshold = | |
1811 | battery->pdata->wpc_low_threshold_normal; | |
1812 | } else { | |
1813 | if (lpcharge) { | |
1814 | battery->temp_highlimit_threshold = | |
1815 | battery->pdata->temp_highlimit_threshold_lpm; | |
1816 | battery->temp_highlimit_recovery = | |
1817 | battery->pdata->temp_highlimit_recovery_lpm; | |
1818 | battery->temp_high_threshold = | |
1819 | battery->pdata->temp_high_threshold_lpm; | |
1820 | battery->temp_high_recovery = | |
1821 | battery->pdata->temp_high_recovery_lpm; | |
1822 | battery->temp_low_recovery = | |
1823 | battery->pdata->temp_low_recovery_lpm; | |
1824 | battery->temp_low_threshold = | |
1825 | battery->pdata->temp_low_threshold_lpm; | |
1826 | } else { | |
1827 | battery->temp_highlimit_threshold = | |
1828 | battery->pdata->temp_highlimit_threshold_normal; | |
1829 | battery->temp_highlimit_recovery = | |
1830 | battery->pdata->temp_highlimit_recovery_normal; | |
1831 | battery->temp_high_threshold = | |
1832 | battery->pdata->temp_high_threshold_normal; | |
1833 | battery->temp_high_recovery = | |
1834 | battery->pdata->temp_high_recovery_normal; | |
1835 | battery->temp_low_recovery = | |
1836 | battery->pdata->temp_low_recovery_normal; | |
1837 | battery->temp_low_threshold = | |
1838 | battery->pdata->temp_low_threshold_normal; | |
1839 | } | |
1840 | } | |
1841 | dev_info(battery->dev, | |
1842 | "%s: HLT(%d) HLR(%d) HT(%d), HR(%d), LT(%d), LR(%d)\n", | |
1843 | __func__, battery->temp_highlimit_threshold, | |
1844 | battery->temp_highlimit_recovery, | |
1845 | battery->temp_high_threshold, | |
1846 | battery->temp_high_recovery, | |
1847 | battery->temp_low_threshold, | |
1848 | battery->temp_low_recovery); | |
1849 | return ret; | |
1850 | } | |
1851 | ||
1852 | static bool sec_bat_temperature_check( | |
1853 | struct sec_battery_info *battery) | |
1854 | { | |
1855 | int temp_value = 0; | |
1856 | int pre_health = POWER_SUPPLY_HEALTH_GOOD; | |
1857 | ||
1858 | if (battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
1859 | battery->health_change = false; | |
1860 | dev_dbg(battery->dev, | |
1861 | "%s: Charging Disabled\n", __func__); | |
1862 | return true; | |
1863 | } | |
1864 | ||
1865 | if (battery->health != POWER_SUPPLY_HEALTH_GOOD && | |
1866 | battery->health != POWER_SUPPLY_HEALTH_OVERHEAT && | |
1867 | battery->health != POWER_SUPPLY_HEALTH_COLD && | |
1868 | battery->health != POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
1869 | dev_dbg(battery->dev, "%s: No need to check\n", __func__); | |
1870 | return false; | |
1871 | } | |
1872 | ||
1873 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) || defined(CONFIG_SEC_FACTORY) | |
1874 | if (!battery->cooldown_mode) { | |
1875 | dev_err(battery->dev, "%s: Forced temp check block\n", __func__); | |
1876 | return true; | |
1877 | } | |
1878 | #endif | |
1879 | ||
1880 | sec_bat_temperature(battery); | |
1881 | ||
1882 | switch (battery->pdata->temp_check_type) { | |
1883 | case SEC_BATTERY_TEMP_CHECK_ADC: | |
1884 | temp_value = battery->temp_adc; | |
1885 | break; | |
1886 | case SEC_BATTERY_TEMP_CHECK_TEMP: | |
1887 | temp_value = battery->temperature; | |
1888 | break; | |
1889 | default: | |
1890 | dev_err(battery->dev, | |
1891 | "%s: Invalid Temp Check Type\n", __func__); | |
1892 | return true; | |
1893 | } | |
1894 | pre_health = battery->health; | |
1895 | ||
1896 | if (battery->pdata->usb_thermal_source && (battery->usb_temp >= battery->temp_highlimit_threshold)) { | |
1897 | if (battery->health != POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
1898 | if (battery->temp_highlimit_cnt < | |
1899 | battery->pdata->temp_check_count) { | |
1900 | battery->temp_highlimit_cnt++; | |
1901 | battery->temp_high_cnt = 0; | |
1902 | battery->temp_low_cnt = 0; | |
1903 | battery->temp_recover_cnt = 0; | |
1904 | } | |
1905 | dev_err(battery->dev, | |
1906 | "%s: usb therm highlimit count = %d\n", | |
1907 | __func__, battery->temp_highlimit_cnt); | |
1908 | } | |
1909 | } else if (battery->pdata->usb_thermal_source && (battery->usb_temp > battery->temp_highlimit_recovery) | |
1910 | && (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT)) { | |
1911 | dev_err(battery->dev, | |
1912 | "%s: usb therm highlimit \n",__func__); | |
1913 | } else if (temp_value >= battery->temp_highlimit_threshold && !battery->pdata->usb_thermal_source) { | |
1914 | if (battery->health != POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
1915 | if (battery->temp_highlimit_cnt < | |
1916 | battery->pdata->temp_check_count) { | |
1917 | battery->temp_highlimit_cnt++; | |
1918 | battery->temp_high_cnt = 0; | |
1919 | battery->temp_low_cnt = 0; | |
1920 | battery->temp_recover_cnt = 0; | |
1921 | } | |
1922 | dev_err(battery->dev, | |
1923 | "%s: highlimit count = %d\n", | |
1924 | __func__, battery->temp_highlimit_cnt); | |
1925 | } | |
1926 | } else if (temp_value >= battery->temp_high_threshold) { | |
1927 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT && !battery->pdata->usb_thermal_source) { | |
1928 | if (temp_value <= battery->temp_highlimit_recovery) { | |
1929 | if (battery->temp_recover_cnt < | |
1930 | battery->pdata->temp_check_count) { | |
1931 | battery->temp_recover_cnt++; | |
1932 | battery->temp_highlimit_cnt = 0; | |
1933 | battery->temp_high_cnt = 0; | |
1934 | battery->temp_low_cnt = 0; | |
1935 | } | |
1936 | dev_err(battery->dev, | |
1937 | "%s: recovery count = %d\n", | |
1938 | __func__, battery->temp_recover_cnt); | |
1939 | } | |
1940 | } else if (battery->health != POWER_SUPPLY_HEALTH_OVERHEAT) { | |
1941 | if (battery->temp_high_cnt < | |
1942 | battery->pdata->temp_check_count) { | |
1943 | battery->temp_high_cnt++; | |
1944 | battery->temp_highlimit_cnt = 0; | |
1945 | battery->temp_low_cnt = 0; | |
1946 | battery->temp_recover_cnt = 0; | |
1947 | } | |
1948 | dev_err(battery->dev, | |
1949 | "%s: high count = %d\n", | |
1950 | __func__, battery->temp_high_cnt); | |
1951 | } | |
1952 | } else if ((temp_value <= battery->temp_high_recovery) && | |
1953 | (temp_value >= battery->temp_low_recovery)) { | |
1954 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEAT || | |
1955 | battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT || | |
1956 | battery->health == POWER_SUPPLY_HEALTH_COLD) { | |
1957 | if (battery->temp_recover_cnt < | |
1958 | battery->pdata->temp_check_count) { | |
1959 | battery->temp_recover_cnt++; | |
1960 | battery->temp_highlimit_cnt = 0; | |
1961 | battery->temp_high_cnt = 0; | |
1962 | battery->temp_low_cnt = 0; | |
1963 | } | |
1964 | dev_err(battery->dev, | |
1965 | "%s: recovery count = %d\n", | |
1966 | __func__, battery->temp_recover_cnt); | |
1967 | } | |
1968 | } else if (temp_value <= battery->temp_low_threshold) { | |
1969 | if (battery->health != POWER_SUPPLY_HEALTH_COLD) { | |
1970 | if (battery->temp_low_cnt < | |
1971 | battery->pdata->temp_check_count) { | |
1972 | battery->temp_low_cnt++; | |
1973 | battery->temp_highlimit_cnt = 0; | |
1974 | battery->temp_high_cnt = 0; | |
1975 | battery->temp_recover_cnt = 0; | |
1976 | } | |
1977 | dev_err(battery->dev, | |
1978 | "%s: low count = %d\n", | |
1979 | __func__, battery->temp_low_cnt); | |
1980 | } | |
1981 | } else { | |
1982 | battery->temp_highlimit_cnt = 0; | |
1983 | battery->temp_high_cnt = 0; | |
1984 | battery->temp_low_cnt = 0; | |
1985 | battery->temp_recover_cnt = 0; | |
1986 | } | |
1987 | ||
1988 | if (battery->temp_highlimit_cnt >= | |
1989 | battery->pdata->temp_check_count) { | |
1990 | battery->health = POWER_SUPPLY_HEALTH_OVERHEATLIMIT; | |
1991 | battery->temp_highlimit_cnt = 0; | |
1992 | } else if (battery->temp_high_cnt >= | |
1993 | battery->pdata->temp_check_count) { | |
1994 | battery->health = POWER_SUPPLY_HEALTH_OVERHEAT; | |
1995 | battery->temp_high_cnt = 0; | |
1996 | } else if (battery->temp_low_cnt >= | |
1997 | battery->pdata->temp_check_count) { | |
1998 | battery->health = POWER_SUPPLY_HEALTH_COLD; | |
1999 | battery->temp_low_cnt = 0; | |
2000 | } else if (battery->temp_recover_cnt >= | |
2001 | battery->pdata->temp_check_count) { | |
2002 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT && | |
2003 | temp_value > battery->temp_high_recovery) { | |
2004 | battery->health = POWER_SUPPLY_HEALTH_OVERHEAT; | |
2005 | } else { | |
2006 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
2007 | } | |
2008 | battery->temp_recover_cnt = 0; | |
2009 | } | |
2010 | if (pre_health != battery->health) { | |
2011 | battery->health_change = true; | |
2012 | dev_info(battery->dev, "%s, health_change true\n", __func__); | |
2013 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
2014 | sec_bat_add_sbm_data(battery, SBM_DATA_TEMP); | |
2015 | #endif | |
2016 | } else { | |
2017 | battery->health_change = false; | |
2018 | } | |
2019 | ||
2020 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERHEAT) || | |
2021 | (battery->health == POWER_SUPPLY_HEALTH_COLD) || | |
2022 | (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT)) { | |
2023 | union power_supply_propval val = {0, }; | |
2024 | if (battery->health_change) { | |
2025 | battery->is_abnormal_temp = true; | |
2026 | if (is_wireless_type(battery->cable_type)) { | |
2027 | val.intval = battery->health; | |
2028 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
2029 | POWER_SUPPLY_PROP_HEALTH, val); | |
2030 | } | |
2031 | dev_info(battery->dev, | |
2032 | "%s: Unsafe Temperature\n", __func__); | |
2033 | sec_bat_set_charging_status(battery, | |
2034 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
2035 | #if defined(CONFIG_BATTERY_CISD) | |
2036 | battery->cisd.data[CISD_DATA_UNSAFETY_TEMPERATURE]++; | |
2037 | battery->cisd.data[CISD_DATA_UNSAFE_TEMPERATURE_PER_DAY]++; | |
2038 | #endif | |
2039 | ||
2040 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
2041 | /* change charging current to battery (default 0mA) */ | |
2042 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_BUCK_OFF); | |
2043 | if (is_hv_afc_wire_type(battery->cable_type) && !battery->vbus_limit) { | |
2044 | #if defined(CONFIG_MUIC_HV) || defined(CONFIG_SUPPORT_QC30) | |
2045 | muic_afc_set_voltage(SEC_INPUT_VOLTAGE_0V); | |
2046 | #endif | |
2047 | battery->vbus_limit = true; | |
2048 | pr_info("%s: Set AFC TA to 0V\n", __func__); | |
2049 | } | |
2050 | } else if (battery->health == POWER_SUPPLY_HEALTH_OVERHEAT) { | |
2051 | /* to discharge battery */ | |
2052 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_BUCK_OFF); | |
2053 | } else { | |
2054 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
2055 | } | |
2056 | ||
2057 | return false; | |
2058 | } | |
2059 | /* dose not need buck control at low temperature */ | |
2060 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT || | |
2061 | battery->health == POWER_SUPPLY_HEALTH_OVERHEAT) { | |
2062 | if((battery->charger_mode == SEC_BAT_CHG_MODE_BUCK_OFF) && | |
2063 | (battery->voltage_now < (battery->pdata->swelling_drop_float_voltage / battery->pdata->chg_float_voltage_conv))) { | |
2064 | pr_info("%s: Vnow(%dmV) < %dmV has dropped enough to get buck on mode \n", __func__, | |
2065 | battery->voltage_now, | |
2066 | (battery->pdata->swelling_drop_float_voltage / battery->pdata->chg_float_voltage_conv)); | |
2067 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
2068 | } | |
2069 | } | |
2070 | } else { | |
2071 | /* if recovered from not charging */ | |
2072 | if ((battery->health == POWER_SUPPLY_HEALTH_GOOD) && | |
2073 | (battery->status == | |
2074 | POWER_SUPPLY_STATUS_NOT_CHARGING)) { | |
2075 | battery->is_abnormal_temp = false; | |
2076 | dev_info(battery->dev, | |
2077 | "%s: Safe Temperature\n", __func__); | |
2078 | if (battery->capacity >= 100) | |
2079 | sec_bat_set_charging_status(battery, | |
2080 | POWER_SUPPLY_STATUS_FULL); | |
2081 | else /* Normal Charging */ | |
2082 | sec_bat_set_charging_status(battery, | |
2083 | POWER_SUPPLY_STATUS_CHARGING); | |
2084 | #if defined(CONFIG_BATTERY_SWELLING) | |
2085 | if ((temp_value > battery->pdata->swelling_high_temp_recov) || | |
2086 | (temp_value < battery->pdata->swelling_low_temp_recov_2nd)) { | |
2087 | pr_info("%s: swelling mode start. stop charging\n", __func__); | |
2088 | battery->swelling_mode = SWELLING_MODE_CHARGING; | |
2089 | battery->swelling_full_check_cnt = 0; | |
2090 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_BUCK_OFF); | |
2091 | if (battery->temperature > battery->pdata->swelling_high_temp_recov) { | |
2092 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING, | |
2093 | SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING); | |
2094 | } else if (battery->temperature < battery->pdata->swelling_low_temp_recov_2nd) { | |
2095 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING, | |
2096 | SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING); | |
2097 | } | |
2098 | } else { | |
2099 | union power_supply_propval val = {0, }; | |
2100 | /* restore 4.4V float voltage */ | |
2101 | val.intval = battery->pdata->swelling_normal_float_voltage; | |
2102 | psy_do_property(battery->pdata->charger_name, set, | |
2103 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
2104 | /* turn on charger by cable type */ | |
2105 | if((battery->status == POWER_SUPPLY_STATUS_FULL) && | |
2106 | (battery->charging_mode == SEC_BATTERY_CHARGING_NONE)) { | |
2107 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
2108 | } else { | |
2109 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
2110 | } | |
2111 | ||
2112 | if (temp_value <= battery->pdata->swelling_low_temp_block_1st || | |
2113 | ((temp_value < battery->pdata->swelling_low_temp_recov_1st) && | |
2114 | (pre_health == POWER_SUPPLY_HEALTH_COLD))) { | |
2115 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP, | |
2116 | SEC_BAT_CURRENT_EVENT_SWELLING_MODE); | |
2117 | } | |
2118 | } | |
2119 | #else | |
2120 | /* turn on charger by cable type */ | |
2121 | if((battery->status == POWER_SUPPLY_STATUS_FULL) && | |
2122 | (battery->charging_mode == SEC_BATTERY_CHARGING_NONE)) { | |
2123 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
2124 | } else { | |
2125 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
2126 | } | |
2127 | #endif | |
2128 | return false; | |
2129 | } | |
2130 | } | |
2131 | return true; | |
2132 | } | |
2133 | ||
2134 | static bool sec_bat_check_fullcharged_condition( | |
2135 | struct sec_battery_info *battery) | |
2136 | { | |
2137 | int full_check_type = SEC_BATTERY_FULLCHARGED_NONE; | |
2138 | ||
2139 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST) | |
2140 | full_check_type = battery->pdata->full_check_type; | |
2141 | else | |
2142 | full_check_type = battery->pdata->full_check_type_2nd; | |
2143 | ||
2144 | switch (full_check_type) { | |
2145 | case SEC_BATTERY_FULLCHARGED_ADC: | |
2146 | case SEC_BATTERY_FULLCHARGED_FG_CURRENT: | |
2147 | case SEC_BATTERY_FULLCHARGED_SOC: | |
2148 | case SEC_BATTERY_FULLCHARGED_CHGGPIO: | |
2149 | case SEC_BATTERY_FULLCHARGED_CHGPSY: | |
2150 | break; | |
2151 | ||
2152 | /* If these is NOT full check type or NONE full check type, | |
2153 | * it is full-charged | |
2154 | */ | |
2155 | case SEC_BATTERY_FULLCHARGED_CHGINT: | |
2156 | case SEC_BATTERY_FULLCHARGED_TIME: | |
2157 | case SEC_BATTERY_FULLCHARGED_NONE: | |
2158 | default: | |
2159 | return true; | |
2160 | break; | |
2161 | } | |
2162 | ||
2163 | if (battery->pdata->full_condition_type & | |
2164 | SEC_BATTERY_FULL_CONDITION_SOC) { | |
2165 | if (battery->capacity < | |
2166 | battery->pdata->full_condition_soc) { | |
2167 | dev_dbg(battery->dev, | |
2168 | "%s: Not enough SOC (%d%%)\n", | |
2169 | __func__, battery->capacity); | |
2170 | return false; | |
2171 | } | |
2172 | } | |
2173 | ||
2174 | if (battery->pdata->full_condition_type & | |
2175 | SEC_BATTERY_FULL_CONDITION_VCELL) { | |
2176 | if (battery->voltage_now < | |
2177 | battery->pdata->full_condition_vcell) { | |
2178 | dev_dbg(battery->dev, | |
2179 | "%s: Not enough VCELL (%dmV)\n", | |
2180 | __func__, battery->voltage_now); | |
2181 | return false; | |
2182 | } | |
2183 | } | |
2184 | ||
2185 | if (battery->pdata->full_condition_type & | |
2186 | SEC_BATTERY_FULL_CONDITION_AVGVCELL) { | |
2187 | if (battery->voltage_avg < | |
2188 | battery->pdata->full_condition_avgvcell) { | |
2189 | dev_dbg(battery->dev, | |
2190 | "%s: Not enough AVGVCELL (%dmV)\n", | |
2191 | __func__, battery->voltage_avg); | |
2192 | return false; | |
2193 | } | |
2194 | } | |
2195 | ||
2196 | if (battery->pdata->full_condition_type & | |
2197 | SEC_BATTERY_FULL_CONDITION_OCV) { | |
2198 | if (battery->voltage_ocv < | |
2199 | battery->pdata->full_condition_ocv) { | |
2200 | dev_dbg(battery->dev, | |
2201 | "%s: Not enough OCV (%dmV)\n", | |
2202 | __func__, battery->voltage_ocv); | |
2203 | return false; | |
2204 | } | |
2205 | } | |
2206 | ||
2207 | return true; | |
2208 | } | |
2209 | ||
2210 | static void sec_bat_do_test_function( | |
2211 | struct sec_battery_info *battery) | |
2212 | { | |
2213 | union power_supply_propval value = {0, }; | |
2214 | ||
2215 | switch (battery->test_mode) { | |
2216 | case 1: | |
2217 | if (battery->status == POWER_SUPPLY_STATUS_CHARGING) { | |
2218 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
2219 | sec_bat_set_charging_status(battery, | |
2220 | POWER_SUPPLY_STATUS_DISCHARGING); | |
2221 | } | |
2222 | break; | |
2223 | case 2: | |
2224 | if(battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
2225 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
2226 | psy_do_property(battery->pdata->charger_name, get, | |
2227 | POWER_SUPPLY_PROP_STATUS, value); | |
2228 | sec_bat_set_charging_status(battery, value.intval); | |
2229 | } | |
2230 | battery->test_mode = 0; | |
2231 | break; | |
2232 | case 3: // clear temp block | |
2233 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
2234 | sec_bat_set_charging_status(battery, | |
2235 | POWER_SUPPLY_STATUS_DISCHARGING); | |
2236 | break; | |
2237 | case 4: | |
2238 | if(battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
2239 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
2240 | psy_do_property(battery->pdata->charger_name, get, | |
2241 | POWER_SUPPLY_PROP_STATUS, value); | |
2242 | sec_bat_set_charging_status(battery, value.intval); | |
2243 | } | |
2244 | break; | |
2245 | default: | |
2246 | pr_info("%s: error test: unknown state\n", __func__); | |
2247 | break; | |
2248 | } | |
2249 | } | |
2250 | ||
2251 | static bool sec_bat_time_management( | |
2252 | struct sec_battery_info *battery) | |
2253 | { | |
2254 | struct timespec ts = {0, }; | |
2255 | unsigned long charging_time; | |
2256 | ||
2257 | if (battery->charging_start_time == 0 || !battery->safety_timer_set) { | |
2258 | dev_dbg(battery->dev, | |
2259 | "%s: Charging Disabled\n", __func__); | |
2260 | return true; | |
2261 | } | |
2262 | ||
2263 | get_monotonic_boottime(&ts); | |
2264 | ||
2265 | if (ts.tv_sec >= battery->charging_start_time) { | |
2266 | charging_time = ts.tv_sec - battery->charging_start_time; | |
2267 | } else { | |
2268 | charging_time = 0xFFFFFFFF - battery->charging_start_time | |
2269 | + ts.tv_sec; | |
2270 | } | |
2271 | ||
2272 | battery->charging_passed_time = charging_time; | |
2273 | ||
2274 | switch (battery->status) { | |
2275 | case POWER_SUPPLY_STATUS_FULL: | |
2276 | if (battery->expired_time == 0) { | |
2277 | dev_info(battery->dev, | |
2278 | "%s: Recharging Timer Expired\n", __func__); | |
2279 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2280 | battery->health = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; | |
2281 | sec_bat_set_charging_status(battery, POWER_SUPPLY_STATUS_NOT_CHARGING); | |
2282 | battery->is_recharging = false; | |
2283 | if (sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF)) { | |
2284 | dev_err(battery->dev, | |
2285 | "%s: Fail to Set Charger\n", __func__); | |
2286 | return true; | |
2287 | } | |
2288 | ||
2289 | return false; | |
2290 | } | |
2291 | break; | |
2292 | case POWER_SUPPLY_STATUS_CHARGING: | |
2293 | if ((battery->pdata->full_condition_type & | |
2294 | SEC_BATTERY_FULL_CONDITION_NOTIMEFULL) && | |
2295 | (battery->is_recharging && (battery->expired_time == 0))) { | |
2296 | dev_info(battery->dev, | |
2297 | "%s: Recharging Timer Expired\n", __func__); | |
2298 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2299 | battery->health = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; | |
2300 | sec_bat_set_charging_status(battery, POWER_SUPPLY_STATUS_NOT_CHARGING); | |
2301 | battery->is_recharging = false; | |
2302 | if (sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF)) { | |
2303 | dev_err(battery->dev, | |
2304 | "%s: Fail to Set Charger\n", __func__); | |
2305 | return true; | |
2306 | } | |
2307 | return false; | |
2308 | } else if (!battery->is_recharging && | |
2309 | (battery->expired_time == 0)) { | |
2310 | dev_info(battery->dev, | |
2311 | "%s: Charging Timer Expired\n", __func__); | |
2312 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2313 | battery->health = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; | |
2314 | sec_bat_set_charging_status(battery, POWER_SUPPLY_STATUS_NOT_CHARGING); | |
2315 | #if defined(CONFIG_BATTERY_CISD) | |
2316 | battery->cisd.data[CISD_DATA_SAFETY_TIMER]++; | |
2317 | battery->cisd.data[CISD_DATA_SAFETY_TIMER_PER_DAY]++; | |
2318 | #endif | |
2319 | #if defined(CONFIG_SEC_ABC) | |
2320 | sec_abc_send_event("MODULE=battery@ERROR=safety_timer"); | |
2321 | #endif | |
2322 | if (sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF)) { | |
2323 | dev_err(battery->dev, | |
2324 | "%s: Fail to Set Charger\n", __func__); | |
2325 | return true; | |
2326 | } | |
2327 | return false; | |
2328 | } | |
2329 | break; | |
2330 | default: | |
2331 | dev_err(battery->dev, | |
2332 | "%s: Undefine Battery Status\n", __func__); | |
2333 | return true; | |
2334 | } | |
2335 | ||
2336 | return true; | |
2337 | } | |
2338 | ||
2339 | static bool sec_bat_check_fullcharged( | |
2340 | struct sec_battery_info *battery) | |
2341 | { | |
2342 | union power_supply_propval value = {0, }; | |
2343 | int current_adc = 0; | |
2344 | int full_check_type = SEC_BATTERY_FULLCHARGED_NONE; | |
2345 | bool ret = false; | |
2346 | int err = 0; | |
2347 | ||
2348 | if (!sec_bat_check_fullcharged_condition(battery)) | |
2349 | goto not_full_charged; | |
2350 | ||
2351 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST) | |
2352 | full_check_type = battery->pdata->full_check_type; | |
2353 | else | |
2354 | full_check_type = battery->pdata->full_check_type_2nd; | |
2355 | ||
2356 | switch (full_check_type) { | |
2357 | case SEC_BATTERY_FULLCHARGED_ADC: | |
2358 | current_adc = | |
2359 | sec_bat_get_adc_data(battery, | |
2360 | SEC_BAT_ADC_CHANNEL_FULL_CHECK, | |
2361 | battery->pdata->adc_check_count); | |
2362 | ||
2363 | dev_dbg(battery->dev, | |
2364 | "%s: Current ADC (%d)\n", | |
2365 | __func__, current_adc); | |
2366 | ||
2367 | if (current_adc < 0) | |
2368 | break; | |
2369 | battery->current_adc = current_adc; | |
2370 | ||
2371 | if (battery->current_adc < | |
2372 | (battery->charging_mode == | |
2373 | SEC_BATTERY_CHARGING_1ST ? | |
2374 | battery->pdata->full_check_current_1st : | |
2375 | battery->pdata->full_check_current_2nd)) { | |
2376 | battery->full_check_cnt++; | |
2377 | dev_dbg(battery->dev, | |
2378 | "%s: Full Check ADC (%d)\n", | |
2379 | __func__, | |
2380 | battery->full_check_cnt); | |
2381 | } else | |
2382 | battery->full_check_cnt = 0; | |
2383 | break; | |
2384 | ||
2385 | case SEC_BATTERY_FULLCHARGED_FG_CURRENT: | |
2386 | if ((battery->current_now > 0 && battery->current_now < | |
2387 | battery->pdata->full_check_current_1st) && | |
2388 | (battery->current_avg > 0 && battery->current_avg < | |
2389 | (battery->charging_mode == | |
2390 | SEC_BATTERY_CHARGING_1ST ? | |
2391 | battery->pdata->full_check_current_1st : | |
2392 | battery->pdata->full_check_current_2nd))) { | |
2393 | battery->full_check_cnt++; | |
2394 | dev_dbg(battery->dev, | |
2395 | "%s: Full Check Current (%d)\n", | |
2396 | __func__, | |
2397 | battery->full_check_cnt); | |
2398 | } else | |
2399 | battery->full_check_cnt = 0; | |
2400 | break; | |
2401 | ||
2402 | case SEC_BATTERY_FULLCHARGED_TIME: | |
2403 | if ((battery->charging_mode == | |
2404 | SEC_BATTERY_CHARGING_2ND ? | |
2405 | (battery->charging_passed_time - | |
2406 | battery->charging_fullcharged_time) : | |
2407 | battery->charging_passed_time) > | |
2408 | (battery->charging_mode == | |
2409 | SEC_BATTERY_CHARGING_1ST ? | |
2410 | battery->pdata->full_check_current_1st : | |
2411 | battery->pdata->full_check_current_2nd)) { | |
2412 | battery->full_check_cnt++; | |
2413 | dev_dbg(battery->dev, | |
2414 | "%s: Full Check Time (%d)\n", | |
2415 | __func__, | |
2416 | battery->full_check_cnt); | |
2417 | } else | |
2418 | battery->full_check_cnt = 0; | |
2419 | break; | |
2420 | ||
2421 | case SEC_BATTERY_FULLCHARGED_SOC: | |
2422 | if (battery->capacity <= | |
2423 | (battery->charging_mode == | |
2424 | SEC_BATTERY_CHARGING_1ST ? | |
2425 | battery->pdata->full_check_current_1st : | |
2426 | battery->pdata->full_check_current_2nd)) { | |
2427 | battery->full_check_cnt++; | |
2428 | dev_dbg(battery->dev, | |
2429 | "%s: Full Check SOC (%d)\n", | |
2430 | __func__, | |
2431 | battery->full_check_cnt); | |
2432 | } else | |
2433 | battery->full_check_cnt = 0; | |
2434 | break; | |
2435 | ||
2436 | case SEC_BATTERY_FULLCHARGED_CHGGPIO: | |
2437 | err = gpio_request( | |
2438 | battery->pdata->chg_gpio_full_check, | |
2439 | "GPIO_CHG_FULL"); | |
2440 | if (err) { | |
2441 | dev_err(battery->dev, | |
2442 | "%s: Error in Request of GPIO\n", __func__); | |
2443 | break; | |
2444 | } | |
2445 | if (!(gpio_get_value_cansleep( | |
2446 | battery->pdata->chg_gpio_full_check) ^ | |
2447 | !battery->pdata->chg_polarity_full_check)) { | |
2448 | battery->full_check_cnt++; | |
2449 | dev_dbg(battery->dev, | |
2450 | "%s: Full Check GPIO (%d)\n", | |
2451 | __func__, battery->full_check_cnt); | |
2452 | } else | |
2453 | battery->full_check_cnt = 0; | |
2454 | gpio_free(battery->pdata->chg_gpio_full_check); | |
2455 | break; | |
2456 | ||
2457 | case SEC_BATTERY_FULLCHARGED_CHGINT: | |
2458 | case SEC_BATTERY_FULLCHARGED_CHGPSY: | |
2459 | psy_do_property(battery->pdata->charger_name, get, | |
2460 | POWER_SUPPLY_PROP_STATUS, value); | |
2461 | ||
2462 | if (value.intval == POWER_SUPPLY_STATUS_FULL) { | |
2463 | battery->full_check_cnt++; | |
2464 | dev_info(battery->dev, | |
2465 | "%s: Full Check Charger (%d)\n", | |
2466 | __func__, battery->full_check_cnt); | |
2467 | } else | |
2468 | battery->full_check_cnt = 0; | |
2469 | break; | |
2470 | ||
2471 | /* If these is NOT full check type or NONE full check type, | |
2472 | * it is full-charged | |
2473 | */ | |
2474 | case SEC_BATTERY_FULLCHARGED_NONE: | |
2475 | battery->full_check_cnt = 0; | |
2476 | ret = true; | |
2477 | break; | |
2478 | default: | |
2479 | dev_err(battery->dev, | |
2480 | "%s: Invalid Full Check\n", __func__); | |
2481 | break; | |
2482 | } | |
2483 | ||
2484 | if (battery->full_check_cnt >= | |
2485 | battery->pdata->full_check_count) { | |
2486 | battery->full_check_cnt = 0; | |
2487 | ret = true; | |
2488 | } | |
2489 | ||
2490 | not_full_charged: | |
2491 | return ret; | |
2492 | } | |
2493 | ||
2494 | static void sec_bat_do_fullcharged( | |
2495 | struct sec_battery_info *battery) | |
2496 | { | |
2497 | union power_supply_propval value = {0, }; | |
2498 | ||
2499 | /* To let charger/fuel gauge know the full status, | |
2500 | * set status before calling sec_bat_set_charge() | |
2501 | */ | |
2502 | #if defined(CONFIG_BATTERY_CISD) | |
2503 | struct timespec now_ts; | |
2504 | ||
2505 | if (battery->status != POWER_SUPPLY_STATUS_FULL) { | |
2506 | battery->cisd.data[CISD_DATA_FULL_COUNT]++; | |
2507 | battery->cisd.data[CISD_DATA_FULL_COUNT_PER_DAY]++; | |
2508 | } | |
2509 | #endif | |
2510 | sec_bat_set_charging_status(battery, | |
2511 | POWER_SUPPLY_STATUS_FULL); | |
2512 | ||
2513 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST && | |
2514 | battery->pdata->full_check_type_2nd != SEC_BATTERY_FULLCHARGED_NONE) { | |
2515 | battery->charging_mode = SEC_BATTERY_CHARGING_2ND; | |
2516 | battery->charging_fullcharged_time = battery->charging_passed_time; | |
2517 | value.intval = SEC_BAT_CHG_MODE_CHARGING_OFF; | |
2518 | psy_do_property(battery->pdata->charger_name, set, | |
2519 | POWER_SUPPLY_PROP_CHARGING_ENABLED, value); | |
2520 | sec_bat_set_charging_current(battery); | |
2521 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
2522 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
2523 | sec_bat_add_sbm_data(battery, SBM_DATA_FULL_1ST); | |
2524 | #endif | |
2525 | } else { | |
2526 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2527 | #if defined(CONFIG_BATTERY_CISD) | |
2528 | now_ts = ktime_to_timespec(ktime_get_boottime()); | |
2529 | if (!battery->is_recharging) { | |
2530 | battery->cisd.charging_end_time = now_ts.tv_sec; | |
2531 | } | |
2532 | if (battery->siop_level == 100) { | |
2533 | dev_info(battery->dev, "%s: cisd - leakage EFGH start(%ld)\n", __func__, ((unsigned long)now_ts.tv_sec)); | |
2534 | battery->cisd.state &= ~(CISD_STATE_LEAK_E|CISD_STATE_LEAK_F|CISD_STATE_LEAK_G); | |
2535 | battery->cisd.charging_end_time_2 = now_ts.tv_sec; | |
2536 | battery->cisd.recharge_count_2 = 0; | |
2537 | } else { | |
2538 | battery->cisd.state &= ~(CISD_STATE_LEAK_E|CISD_STATE_LEAK_F|CISD_STATE_LEAK_G); | |
2539 | battery->cisd.recharge_count_2 = 0; | |
2540 | battery->cisd.charging_end_time_2 = 0; | |
2541 | } | |
2542 | #endif | |
2543 | battery->is_recharging = false; | |
2544 | ||
2545 | if (!battery->wdt_kick_disable) { | |
2546 | pr_info("%s: wdt kick enable -> Charger Off, %d\n", | |
2547 | __func__, battery->wdt_kick_disable); | |
2548 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
2549 | } else { | |
2550 | pr_info("%s: wdt kick disabled -> skip charger off, %d\n", | |
2551 | __func__, battery->wdt_kick_disable); | |
2552 | } | |
2553 | ||
2554 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
2555 | sec_bat_aging_check(battery); | |
2556 | #endif | |
2557 | ||
2558 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
2559 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2560 | POWER_SUPPLY_PROP_STATUS, value); | |
2561 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
2562 | sec_bat_add_sbm_data(battery, SBM_DATA_FULL_2ND); | |
2563 | #endif | |
2564 | } | |
2565 | ||
2566 | /* platform can NOT get information of battery | |
2567 | * because wakeup time is too short to check uevent | |
2568 | * To make sure that target is wakeup if full-charged, | |
2569 | * activated wake lock in a few seconds | |
2570 | */ | |
2571 | if (battery->pdata->polling_type == SEC_BATTERY_MONITOR_ALARM) | |
2572 | wake_lock_timeout(&battery->vbus_wake_lock, HZ * 10); | |
2573 | } | |
2574 | ||
2575 | static bool sec_bat_fullcharged_check( | |
2576 | struct sec_battery_info *battery) | |
2577 | { | |
2578 | if ((battery->charging_mode == SEC_BATTERY_CHARGING_NONE) || | |
2579 | (battery->status == POWER_SUPPLY_STATUS_NOT_CHARGING)) { | |
2580 | dev_dbg(battery->dev, | |
2581 | "%s: No Need to Check Full-Charged\n", __func__); | |
2582 | return true; | |
2583 | } | |
2584 | ||
2585 | if (sec_bat_check_fullcharged(battery)) { | |
2586 | union power_supply_propval value = {0, }; | |
2587 | if (battery->capacity < 100) { | |
2588 | battery->full_check_cnt = battery->pdata->full_check_count; | |
2589 | } else { | |
2590 | sec_bat_do_fullcharged(battery); | |
2591 | } | |
2592 | ||
2593 | /* update capacity max */ | |
2594 | value.intval = battery->capacity; | |
2595 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2596 | POWER_SUPPLY_PROP_CHARGE_FULL, value); | |
2597 | pr_info("%s : forced full-charged sequence for the capacity(%d)\n", | |
2598 | __func__, battery->capacity); | |
2599 | } | |
2600 | ||
2601 | dev_info(battery->dev, | |
2602 | "%s: Charging Mode : %s\n", __func__, | |
2603 | battery->is_recharging ? | |
2604 | sec_bat_charging_mode_str[SEC_BATTERY_CHARGING_RECHARGING] : | |
2605 | sec_bat_charging_mode_str[battery->charging_mode]); | |
2606 | ||
2607 | return true; | |
2608 | } | |
2609 | ||
2610 | static void sec_bat_get_temperature_info( | |
2611 | struct sec_battery_info *battery) | |
2612 | { | |
2613 | union power_supply_propval value = {0, }; | |
2614 | ||
2615 | switch (battery->pdata->thermal_source) { | |
2616 | case SEC_BATTERY_THERMAL_SOURCE_FG: | |
2617 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2618 | POWER_SUPPLY_PROP_TEMP, value); | |
2619 | battery->temperature = value.intval; | |
2620 | ||
2621 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2622 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
2623 | battery->temper_amb = value.intval; | |
2624 | break; | |
2625 | case SEC_BATTERY_THERMAL_SOURCE_CALLBACK: | |
2626 | if (battery->pdata->get_temperature_callback) { | |
2627 | battery->pdata->get_temperature_callback( | |
2628 | POWER_SUPPLY_PROP_TEMP, &value); | |
2629 | battery->temperature = value.intval; | |
2630 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2631 | POWER_SUPPLY_PROP_TEMP, value); | |
2632 | ||
2633 | battery->pdata->get_temperature_callback( | |
2634 | POWER_SUPPLY_PROP_TEMP_AMBIENT, &value); | |
2635 | battery->temper_amb = value.intval; | |
2636 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2637 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
2638 | } | |
2639 | break; | |
2640 | case SEC_BATTERY_THERMAL_SOURCE_ADC: | |
2641 | sec_bat_get_value_by_adc(battery, | |
2642 | SEC_BAT_ADC_CHANNEL_TEMP, &value); | |
2643 | battery->temperature = value.intval; | |
2644 | ||
2645 | sec_bat_get_value_by_adc(battery, | |
2646 | SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT, &value); | |
2647 | battery->temper_amb = value.intval; | |
2648 | ||
2649 | if (battery->pdata->usb_thermal_source) { | |
2650 | sec_bat_get_value_by_adc(battery, | |
2651 | SEC_BAT_ADC_CHANNEL_USB_TEMP, &value); | |
2652 | battery->usb_temp = value.intval; | |
2653 | if (battery->vbus_limit && battery->usb_temp <= battery->temp_highlimit_recovery) | |
2654 | battery->vbus_limit = false; | |
2655 | } | |
2656 | ||
2657 | if (battery->pdata->chg_thermal_source) { | |
2658 | sec_bat_get_value_by_adc(battery, | |
2659 | SEC_BAT_ADC_CHANNEL_CHG_TEMP, &value); | |
2660 | battery->chg_temp = value.intval; | |
2661 | } | |
2662 | ||
2663 | if (battery->pdata->wpc_thermal_source) { | |
2664 | sec_bat_get_value_by_adc(battery, | |
2665 | SEC_BAT_ADC_CHANNEL_WPC_TEMP, &value); | |
2666 | battery->wpc_temp = value.intval; | |
2667 | battery->coil_temp = value.intval; | |
2668 | } | |
2669 | ||
2670 | if (battery->pdata->slave_thermal_source) { | |
2671 | sec_bat_get_value_by_adc(battery, | |
2672 | SEC_BAT_ADC_CHANNEL_SLAVE_CHG_TEMP, &value); | |
2673 | battery->slave_chg_temp = value.intval; | |
2674 | ||
2675 | /* set temperature */ | |
2676 | value.intval = ((battery->slave_chg_temp) << 16) | (battery->chg_temp); | |
2677 | psy_do_property(battery->pdata->charger_name, set, | |
2678 | POWER_SUPPLY_PROP_TEMP, value); | |
2679 | } | |
2680 | ||
2681 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
2682 | if (battery->temperature_test_battery > -300 && battery->temperature_test_battery < 3000) { | |
2683 | pr_info("%s : battery temperature test %d\n", __func__, battery->temperature_test_battery); | |
2684 | battery->temperature = battery->temperature_test_battery; | |
2685 | } | |
2686 | if (battery->temperature_test_usb > -300 && battery->temperature_test_usb < 3000) { | |
2687 | pr_info("%s : usb temperature test %d\n", __func__, battery->temperature_test_usb); | |
2688 | battery->usb_temp = battery->temperature_test_usb; | |
2689 | } | |
2690 | if (battery->temperature_test_wpc > -300 && battery->temperature_test_wpc < 3000) { | |
2691 | pr_info("%s : wpc temperature test %d\n", __func__, battery->temperature_test_wpc); | |
2692 | battery->wpc_temp = battery->temperature_test_wpc; | |
2693 | battery->coil_temp = battery->temperature_test_wpc; | |
2694 | } | |
2695 | if (battery->temperature_test_chg > -300 && battery->temperature_test_chg < 3000) { | |
2696 | pr_info("%s : chg temperature test %d\n", __func__, battery->temperature_test_chg); | |
2697 | battery->chg_temp = battery->temperature_test_chg; | |
2698 | } | |
2699 | #endif | |
2700 | ||
2701 | #if defined(CONFIG_SEC_FACTORY) | |
2702 | if (battery->temperature <= (-200)) { | |
2703 | value.intval = battery->usb_temp; | |
2704 | } else { | |
2705 | value.intval = battery->temperature; | |
2706 | } | |
2707 | #else | |
2708 | value.intval = battery->temperature; | |
2709 | #endif | |
2710 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2711 | POWER_SUPPLY_PROP_TEMP, value); | |
2712 | ||
2713 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2714 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
2715 | ||
2716 | break; | |
2717 | default: | |
2718 | break; | |
2719 | } | |
2720 | } | |
2721 | ||
2722 | static void sec_bat_get_battery_info( | |
2723 | struct sec_battery_info *battery) | |
2724 | { | |
2725 | union power_supply_propval value = {0, }; | |
2726 | ||
2727 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2728 | POWER_SUPPLY_PROP_VOLTAGE_NOW, value); | |
2729 | battery->voltage_now = value.intval; | |
2730 | ||
2731 | value.intval = SEC_BATTERY_VOLTAGE_AVERAGE; | |
2732 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2733 | POWER_SUPPLY_PROP_VOLTAGE_AVG, value); | |
2734 | battery->voltage_avg = value.intval; | |
2735 | ||
2736 | /* Do not call it to reduce time after cable_work, this funtion call FG full log*/ | |
2737 | if (!(battery->current_event & SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL)) { | |
2738 | value.intval = SEC_BATTERY_VOLTAGE_OCV; | |
2739 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2740 | POWER_SUPPLY_PROP_VOLTAGE_AVG, value); | |
2741 | battery->voltage_ocv = value.intval; | |
2742 | } | |
2743 | ||
2744 | value.intval = SEC_BATTERY_CURRENT_MA; | |
2745 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2746 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
2747 | battery->current_now = value.intval; | |
2748 | ||
2749 | value.intval = SEC_BATTERY_CURRENT_MA; | |
2750 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2751 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
2752 | battery->current_avg = value.intval; | |
2753 | ||
2754 | /* input current limit in charger */ | |
2755 | psy_do_property(battery->pdata->charger_name, get, | |
2756 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
2757 | battery->current_max = value.intval; | |
2758 | ||
2759 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2760 | POWER_SUPPLY_PROP_CHARGE_COUNTER, value); | |
2761 | battery->charge_counter = value.intval; | |
2762 | ||
2763 | /* check abnormal status for wireless charging */ | |
2764 | if (!(battery->current_event & SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL) && | |
2765 | is_wireless_type(battery->cable_type)) { | |
2766 | value.intval = (battery->status == POWER_SUPPLY_STATUS_FULL) ? | |
2767 | 100 : battery->capacity; | |
2768 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
2769 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
2770 | } | |
2771 | ||
2772 | sec_bat_get_temperature_info(battery); | |
2773 | ||
2774 | /* To get SOC value (NOT raw SOC), need to reset value */ | |
2775 | value.intval = 0; | |
2776 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2777 | POWER_SUPPLY_PROP_CAPACITY, value); | |
2778 | /* if the battery status was full, and SOC wasn't 100% yet, | |
2779 | then ignore FG SOC, and report (previous SOC +1)% */ | |
2780 | battery->capacity = value.intval; | |
2781 | ||
2782 | dev_info(battery->dev, | |
2783 | "%s:Vnow(%dmV),Vavg(%dmV),Inow(%dmA),Imax(%dmA),Ichg(%dmA),SOC(%d%%)," | |
2784 | "Tbat(%d),Tusb(%d),Tchg(%d),Twpc(%d)\n", __func__, | |
2785 | battery->voltage_now, battery->voltage_avg, battery->current_now, | |
2786 | battery->current_max, battery->charging_current, | |
2787 | battery->capacity, battery->temperature, | |
2788 | battery->usb_temp,battery->chg_temp, battery->wpc_temp | |
2789 | ); | |
2790 | dev_dbg(battery->dev, | |
2791 | "%s,Vavg(%dmV),Vocv(%dmV),Tamb(%d)," | |
2792 | "Iavg(%dmA),Iadc(%d)\n", | |
2793 | battery->present ? "Connected" : "Disconnected", | |
2794 | battery->voltage_avg, battery->voltage_ocv, | |
2795 | battery->temper_amb, | |
2796 | battery->current_avg, battery->current_adc); | |
2797 | ||
2798 | sec_debug_set_extra_info_batt(battery->capacity, battery->voltage_avg, battery->temperature, battery->current_avg); | |
2799 | } | |
2800 | ||
2801 | static void sec_bat_polling_work(struct work_struct *work) | |
2802 | { | |
2803 | struct sec_battery_info *battery = container_of( | |
2804 | work, struct sec_battery_info, polling_work.work); | |
2805 | ||
2806 | wake_lock(&battery->monitor_wake_lock); | |
2807 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
2808 | dev_dbg(battery->dev, "%s: Activated\n", __func__); | |
2809 | } | |
2810 | ||
2811 | static void sec_bat_program_alarm( | |
2812 | struct sec_battery_info *battery, int seconds) | |
2813 | { | |
2814 | alarm_start(&battery->polling_alarm, | |
2815 | ktime_add(battery->last_poll_time, ktime_set(seconds, 0))); | |
2816 | } | |
2817 | ||
2818 | static unsigned int sec_bat_get_polling_time( | |
2819 | struct sec_battery_info *battery) | |
2820 | { | |
2821 | if (battery->status == | |
2822 | POWER_SUPPLY_STATUS_FULL) | |
2823 | battery->polling_time = | |
2824 | battery->pdata->polling_time[ | |
2825 | POWER_SUPPLY_STATUS_CHARGING]; | |
2826 | else | |
2827 | battery->polling_time = | |
2828 | battery->pdata->polling_time[ | |
2829 | battery->status]; | |
2830 | ||
2831 | battery->polling_short = true; | |
2832 | ||
2833 | switch (battery->status) { | |
2834 | case POWER_SUPPLY_STATUS_CHARGING: | |
2835 | if (battery->polling_in_sleep) | |
2836 | battery->polling_short = false; | |
2837 | break; | |
2838 | case POWER_SUPPLY_STATUS_DISCHARGING: | |
2839 | if (battery->polling_in_sleep && (battery->ps_enable != true)) { | |
2840 | battery->polling_time = | |
2841 | battery->pdata->polling_time[ | |
2842 | SEC_BATTERY_POLLING_TIME_SLEEP]; | |
2843 | } else | |
2844 | battery->polling_time = | |
2845 | battery->pdata->polling_time[ | |
2846 | battery->status]; | |
2847 | if (!battery->wc_enable) { | |
2848 | battery->polling_time = battery->pdata->polling_time[ | |
2849 | SEC_BATTERY_POLLING_TIME_CHARGING]; | |
2850 | pr_info("%s: wc_enable is false, polling time is 30sec\n", __func__); | |
2851 | } | |
2852 | battery->polling_short = false; | |
2853 | break; | |
2854 | case POWER_SUPPLY_STATUS_FULL: | |
2855 | if (battery->polling_in_sleep) { | |
2856 | if (!(battery->pdata->full_condition_type & | |
2857 | SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL) && | |
2858 | battery->charging_mode == | |
2859 | SEC_BATTERY_CHARGING_NONE) { | |
2860 | battery->polling_time = | |
2861 | battery->pdata->polling_time[ | |
2862 | SEC_BATTERY_POLLING_TIME_SLEEP]; | |
2863 | } | |
2864 | battery->polling_short = false; | |
2865 | } else { | |
2866 | if (battery->charging_mode == | |
2867 | SEC_BATTERY_CHARGING_NONE) | |
2868 | battery->polling_short = false; | |
2869 | } | |
2870 | break; | |
2871 | case POWER_SUPPLY_STATUS_NOT_CHARGING: | |
2872 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERVOLTAGE || | |
2873 | (battery->health == POWER_SUPPLY_HEALTH_UNDERVOLTAGE)) && | |
2874 | (battery->health_check_count > 0)) { | |
2875 | battery->health_check_count--; | |
2876 | battery->polling_time = 1; | |
2877 | battery->polling_short = false; | |
2878 | } | |
2879 | break; | |
2880 | } | |
2881 | ||
2882 | if (battery->polling_short) | |
2883 | return battery->pdata->polling_time[ | |
2884 | SEC_BATTERY_POLLING_TIME_BASIC]; | |
2885 | /* set polling time to 46s to reduce current noise on wc */ | |
2886 | else if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS && | |
2887 | battery->status == POWER_SUPPLY_STATUS_CHARGING) | |
2888 | battery->polling_time = 46; | |
2889 | ||
2890 | return battery->polling_time; | |
2891 | } | |
2892 | ||
2893 | static bool sec_bat_is_short_polling( | |
2894 | struct sec_battery_info *battery) | |
2895 | { | |
2896 | /* Change the full and short monitoring sequence | |
2897 | * Originally, full monitoring was the last time of polling_count | |
2898 | * But change full monitoring to first time | |
2899 | * because temperature check is too late | |
2900 | */ | |
2901 | if (!battery->polling_short || battery->polling_count == 1) | |
2902 | return false; | |
2903 | else | |
2904 | return true; | |
2905 | } | |
2906 | ||
2907 | static void sec_bat_update_polling_count( | |
2908 | struct sec_battery_info *battery) | |
2909 | { | |
2910 | /* do NOT change polling count in sleep | |
2911 | * even though it is short polling | |
2912 | * to keep polling count along sleep/wakeup | |
2913 | */ | |
2914 | if (battery->polling_short && battery->polling_in_sleep) | |
2915 | return; | |
2916 | ||
2917 | if (battery->polling_short && | |
2918 | ((battery->polling_time / | |
2919 | battery->pdata->polling_time[ | |
2920 | SEC_BATTERY_POLLING_TIME_BASIC]) | |
2921 | > battery->polling_count)) | |
2922 | battery->polling_count++; | |
2923 | else | |
2924 | battery->polling_count = 1; /* initial value = 1 */ | |
2925 | } | |
2926 | ||
2927 | static void sec_bat_set_polling( | |
2928 | struct sec_battery_info *battery) | |
2929 | { | |
2930 | unsigned int polling_time_temp = 0; | |
2931 | ||
2932 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
2933 | ||
2934 | polling_time_temp = sec_bat_get_polling_time(battery); | |
2935 | ||
2936 | dev_info(battery->dev, | |
2937 | "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n", | |
2938 | __func__, sec_bat_status_str[battery->status], | |
2939 | battery->polling_in_sleep ? "Yes" : "No", | |
2940 | (battery->charging_mode == | |
2941 | SEC_BATTERY_CHARGING_NONE) ? "No" : "Yes", | |
2942 | battery->polling_short ? "Yes" : "No"); | |
2943 | dev_info(battery->dev, | |
2944 | "%s: Polling time %d/%d sec.\n", __func__, | |
2945 | battery->polling_short ? | |
2946 | (polling_time_temp * battery->polling_count) : | |
2947 | polling_time_temp, battery->polling_time); | |
2948 | ||
2949 | /* To sync with log above, | |
2950 | * change polling count after log is displayed | |
2951 | * Do NOT update polling count in initial monitor | |
2952 | */ | |
2953 | if (!battery->pdata->monitor_initial_count) | |
2954 | sec_bat_update_polling_count(battery); | |
2955 | else | |
2956 | dev_dbg(battery->dev, | |
2957 | "%s: Initial monitor %d times left.\n", __func__, | |
2958 | battery->pdata->monitor_initial_count); | |
2959 | ||
2960 | switch (battery->pdata->polling_type) { | |
2961 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
2962 | if (battery->pdata->monitor_initial_count) { | |
2963 | battery->pdata->monitor_initial_count--; | |
2964 | schedule_delayed_work(&battery->polling_work, HZ); | |
2965 | } else | |
2966 | schedule_delayed_work(&battery->polling_work, | |
2967 | polling_time_temp * HZ); | |
2968 | break; | |
2969 | case SEC_BATTERY_MONITOR_ALARM: | |
2970 | battery->last_poll_time = ktime_get_boottime(); | |
2971 | ||
2972 | if (battery->pdata->monitor_initial_count) { | |
2973 | battery->pdata->monitor_initial_count--; | |
2974 | sec_bat_program_alarm(battery, 1); | |
2975 | } else | |
2976 | sec_bat_program_alarm(battery, polling_time_temp); | |
2977 | break; | |
2978 | case SEC_BATTERY_MONITOR_TIMER: | |
2979 | break; | |
2980 | default: | |
2981 | break; | |
2982 | } | |
2983 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
2984 | } | |
2985 | ||
2986 | /* OTG during HV wireless charging or sleep mode have 4.5W normal wireless charging UI */ | |
2987 | static bool sec_bat_hv_wc_normal_mode_check(struct sec_battery_info *battery) | |
2988 | { | |
2989 | union power_supply_propval value = {0, }; | |
2990 | ||
2991 | psy_do_property(battery->pdata->charger_name, get, | |
2992 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
2993 | if (value.intval || sleep_mode) { | |
2994 | pr_info("%s: otg(%d), sleep_mode(%d)\n", __func__, value.intval, sleep_mode); | |
2995 | return true; | |
2996 | } | |
2997 | return false; | |
2998 | } | |
2999 | ||
3000 | #if defined(CONFIG_BATTERY_SWELLING) | |
3001 | static void sec_bat_swelling_fullcharged_check(struct sec_battery_info *battery) | |
3002 | { | |
3003 | union power_supply_propval value = {0, }; | |
3004 | ||
3005 | psy_do_property(battery->pdata->charger_name, get, | |
3006 | POWER_SUPPLY_PROP_STATUS, value); | |
3007 | ||
3008 | if (value.intval == POWER_SUPPLY_STATUS_FULL) { | |
3009 | battery->swelling_full_check_cnt++; | |
3010 | pr_info("%s: Swelling mode full-charged check (%d)\n", | |
3011 | __func__, battery->swelling_full_check_cnt); | |
3012 | } else | |
3013 | battery->swelling_full_check_cnt = 0; | |
3014 | ||
3015 | if (battery->swelling_full_check_cnt >= | |
3016 | battery->pdata->full_check_count) { | |
3017 | battery->swelling_full_check_cnt = 0; | |
3018 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
3019 | battery->is_recharging = false; | |
3020 | battery->swelling_mode = SWELLING_MODE_FULL; | |
3021 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
3022 | battery->expired_time = battery->pdata->expired_time; | |
3023 | battery->prev_safety_time = 0; | |
3024 | #if defined(CONFIG_BATTERY_CISD) | |
3025 | battery->cisd.data[CISD_DATA_SWELLING_FULL_CNT]++; | |
3026 | battery->cisd.data[CISD_DATA_SWELLING_FULL_CNT_PER_DAY]++; | |
3027 | #endif | |
3028 | } | |
3029 | } | |
3030 | #endif | |
3031 | ||
3032 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
3033 | static void sec_bat_calc_time_to_full(struct sec_battery_info * battery) | |
3034 | { | |
3035 | if (delayed_work_pending(&battery->timetofull_work)) { | |
3036 | pr_info("%s: keep time_to_full(%5d sec)\n", __func__, battery->timetofull); | |
3037 | } else if (battery->status == POWER_SUPPLY_STATUS_CHARGING || | |
3038 | (battery->status == POWER_SUPPLY_STATUS_FULL && battery->capacity != 100)) { | |
3039 | union power_supply_propval value = {0, }; | |
3040 | int charge = 0; | |
3041 | ||
3042 | if (is_hv_wire_12v_type(battery->cable_type) || | |
3043 | battery->max_charge_power >= (battery->pdata->pd_charging_charge_power + 5000)) { /* 20000mW */ | |
3044 | charge = battery->pdata->ttf_hv_12v_charge_current; | |
3045 | } else if (is_hv_wire_type(battery->cable_type) || | |
3046 | /* if max_charge_power could support over than max_charging_current, calculate based on ttf_hv_charge_current */ | |
3047 | battery->max_charge_power >= (battery->pdata->max_charging_current * 5)) { | |
3048 | charge = battery->pdata->ttf_hv_charge_current; | |
3049 | } else if (is_hv_wireless_type(battery->cable_type) || | |
3050 | battery->cable_type == SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV) { | |
3051 | if (sec_bat_hv_wc_normal_mode_check(battery)) | |
3052 | charge = battery->pdata->ttf_wireless_charge_current; | |
3053 | else | |
3054 | charge = battery->pdata->ttf_hv_wireless_charge_current; | |
3055 | } else if (is_nv_wireless_type(battery->cable_type)) { | |
3056 | charge = battery->pdata->ttf_wireless_charge_current; | |
3057 | } else { | |
3058 | charge = battery->max_charge_power / 5; | |
3059 | } | |
3060 | value.intval = charge; | |
3061 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3062 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, value); | |
3063 | dev_info(battery->dev, "%s: T: %5d sec, passed time: %5ld, current: %d\n", | |
3064 | __func__, value.intval, battery->charging_passed_time, charge); | |
3065 | battery->timetofull = value.intval; | |
3066 | } else { | |
3067 | battery->timetofull = -1; | |
3068 | } | |
3069 | } | |
3070 | ||
3071 | static void sec_bat_time_to_full_work(struct work_struct *work) | |
3072 | { | |
3073 | struct sec_battery_info *battery = container_of(work, | |
3074 | struct sec_battery_info, timetofull_work.work); | |
3075 | union power_supply_propval value = {0, }; | |
3076 | ||
3077 | psy_do_property(battery->pdata->charger_name, get, | |
3078 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
3079 | battery->current_max = value.intval; | |
3080 | ||
3081 | value.intval = SEC_BATTERY_CURRENT_MA; | |
3082 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3083 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
3084 | battery->current_now = value.intval; | |
3085 | ||
3086 | value.intval = SEC_BATTERY_CURRENT_MA; | |
3087 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3088 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
3089 | battery->current_avg = value.intval; | |
3090 | ||
3091 | sec_bat_calc_time_to_full(battery); | |
3092 | dev_info(battery->dev, "%s: \n",__func__); | |
3093 | if (battery->voltage_now > 0) | |
3094 | battery->voltage_now--; | |
3095 | ||
3096 | power_supply_changed(battery->psy_bat); | |
3097 | } | |
3098 | #endif | |
3099 | ||
3100 | extern bool get_usb_enumeration_state(void); | |
3101 | /* To disaply slow charging when usb charging 100MA*/ | |
3102 | static void sec_bat_check_slowcharging_work(struct work_struct *work) | |
3103 | { | |
3104 | struct sec_battery_info *battery = container_of(work, | |
3105 | struct sec_battery_info, slowcharging_work.work); | |
3106 | ||
3107 | if (battery->pdic_info.sink_status.rp_currentlvl == RP_CURRENT_LEVEL_DEFAULT && | |
3108 | battery->cable_type == SEC_BATTERY_CABLE_USB) { | |
3109 | if (!get_usb_enumeration_state() && | |
3110 | (battery->current_event & SEC_BAT_CURRENT_EVENT_USB_100MA)) { | |
3111 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_TIMEOUT_OPEN_TYPE, 0); | |
3112 | battery->max_charge_power = battery->input_voltage * battery->current_max; | |
3113 | } | |
3114 | } | |
3115 | dev_info(battery->dev, "%s: \n",__func__); | |
3116 | } | |
3117 | ||
3118 | static void sec_bat_wc_cv_mode_check(struct sec_battery_info *battery) | |
3119 | { | |
3120 | union power_supply_propval value = {0, }; | |
3121 | ||
3122 | pr_info("%s: battery->wc_cv_mode = %d \n", __func__, battery->wc_cv_mode); | |
3123 | ||
3124 | if (battery->capacity >= battery->pdata->wireless_cc_cv) { | |
3125 | pr_info("%s: 4.5W WC Changed Vout input current limit\n", __func__); | |
3126 | battery->wc_cv_mode = true; | |
3127 | sec_bat_set_charging_current(battery); | |
3128 | value.intval = WIRELESS_VOUT_CC_CV_VOUT; // 5.5V | |
3129 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3130 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
3131 | value.intval = WIRELESS_VRECT_ADJ_ROOM_5; // 80mv | |
3132 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3133 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
3134 | if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS || | |
3135 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_STAND || | |
3136 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_TX) { | |
3137 | value.intval = WIRELESS_CLAMP_ENABLE; | |
3138 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3139 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
3140 | } | |
3141 | /* Change FOD values for CV mode */ | |
3142 | value.intval = POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE; | |
3143 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3144 | POWER_SUPPLY_PROP_STATUS, value); | |
3145 | } | |
3146 | } | |
3147 | ||
3148 | static void sec_bat_siop_level_work(struct work_struct *work) | |
3149 | { | |
3150 | struct sec_battery_info *battery = container_of(work, | |
3151 | struct sec_battery_info, siop_level_work.work); | |
3152 | ||
3153 | pr_info("%s : set current by siop level(%d)\n",__func__, battery->siop_level); | |
3154 | sec_bat_set_charging_current(battery); | |
3155 | wake_unlock(&battery->siop_level_wake_lock); | |
3156 | } | |
3157 | ||
3158 | static void sec_bat_wc_headroom_work(struct work_struct *work) | |
3159 | { | |
3160 | struct sec_battery_info *battery = container_of(work, | |
3161 | struct sec_battery_info, wc_headroom_work.work); | |
3162 | union power_supply_propval value = {0, }; | |
3163 | ||
3164 | /* The default headroom is high, because initial wireless charging state is unstable. | |
3165 | After 10sec wireless charging, however, recover headroom level to avoid chipset damage */ | |
3166 | if (battery->wc_status != SEC_WIRELESS_PAD_NONE) { | |
3167 | /* When the capacity is higher than 99, and the device is in 5V wireless charging state, | |
3168 | then Vrect headroom has to be headroom_2. | |
3169 | Refer to the sec_bat_siop_work function. */ | |
3170 | if (battery->capacity < 99 && battery->status != POWER_SUPPLY_STATUS_FULL) { | |
3171 | if (is_nv_wireless_type(battery->cable_type)) { | |
3172 | if (battery->capacity < battery->pdata->wireless_cc_cv) | |
3173 | value.intval = WIRELESS_VRECT_ADJ_ROOM_4; /* WPC 4.5W, Vrect Room 30mV */ | |
3174 | else | |
3175 | value.intval = WIRELESS_VRECT_ADJ_ROOM_5; /* WPC 4.5W, Vrect Room 80mV */ | |
3176 | } else if (is_hv_wireless_type(battery->cable_type)) { | |
3177 | value.intval = WIRELESS_VRECT_ADJ_ROOM_5; | |
3178 | } else { | |
3179 | value.intval = WIRELESS_VRECT_ADJ_OFF; | |
3180 | } | |
3181 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3182 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
3183 | pr_info("%s: Changed Vrect adjustment from Rx activation(10seconds)", __func__); | |
3184 | } | |
3185 | if (is_nv_wireless_type(battery->cable_type)) | |
3186 | sec_bat_wc_cv_mode_check(battery); | |
3187 | } | |
3188 | wake_unlock(&battery->wc_headroom_wake_lock); | |
3189 | } | |
3190 | ||
3191 | static void sec_bat_ext_event_work(struct work_struct *work) | |
3192 | { | |
3193 | struct sec_battery_info *battery = container_of(work, | |
3194 | struct sec_battery_info, ext_event_work.work); | |
3195 | ||
3196 | union power_supply_propval value = {0, }; | |
3197 | ||
3198 | /* TX OFF state, it has only call scenario */ | |
3199 | if (battery->ext_event & BATT_EXT_EVENT_CALL) { | |
3200 | pr_info("%s: Call ON\n", __func__); | |
3201 | ||
3202 | value.intval = BATT_EXT_EVENT_CALL; | |
3203 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3204 | POWER_SUPPLY_EXT_PROP_CALL_EVENT, value); | |
3205 | ||
3206 | if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_PACK || | |
3207 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_PACK || | |
3208 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_TX) { | |
3209 | pr_info("%s : Call is on during Wireless Pack or TX\n",__func__); | |
3210 | battery->wc_rx_phm_mode = true; | |
3211 | } | |
3212 | } else if (!(battery->ext_event & BATT_EXT_EVENT_CALL)) { | |
3213 | pr_info("%s: Call OFF\n", __func__); | |
3214 | ||
3215 | value.intval = BATT_EXT_EVENT_NONE; | |
3216 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3217 | POWER_SUPPLY_EXT_PROP_CALL_EVENT, value); | |
3218 | ||
3219 | if (battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_PACK || | |
3220 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_PACK || | |
3221 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_TX) { | |
3222 | pr_info("%s : Call is off during Wireless Pack or TX\n",__func__); | |
3223 | } | |
3224 | ||
3225 | /* process phm */ | |
3226 | if(battery->wc_rx_phm_mode) { | |
3227 | pr_info("%s: ESCAPE PHM STEP 1 - WC CONTROL: Enable", __func__); | |
3228 | gpio_direction_output(battery->pdata->wpc_en, 0); | |
3229 | msleep(100); | |
3230 | pr_info("%s: ESCAPE PHM STEP 2 - WC CONTROL: Disable", __func__); | |
3231 | gpio_direction_output(battery->pdata->wpc_en, 1); | |
3232 | msleep(510); | |
3233 | pr_info("%s: ESCAPE PHM STEP 3 - WC CONTROL: Enable", __func__); | |
3234 | gpio_direction_output(battery->pdata->wpc_en, 0); | |
3235 | } | |
3236 | battery->wc_rx_phm_mode = false; | |
3237 | } | |
3238 | wake_unlock(&battery->ext_event_wake_lock); | |
3239 | } | |
3240 | ||
3241 | #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE) | |
3242 | static void sec_bat_fw_update_work(struct sec_battery_info *battery, int mode) | |
3243 | { | |
3244 | union power_supply_propval value = {0, }; | |
3245 | ||
3246 | dev_info(battery->dev, "%s \n", __func__); | |
3247 | ||
3248 | wake_lock_timeout(&battery->vbus_wake_lock, HZ * 10); | |
3249 | ||
3250 | switch (mode) { | |
3251 | case SEC_WIRELESS_RX_SDCARD_MODE: | |
3252 | case SEC_WIRELESS_RX_BUILT_IN_MODE: | |
3253 | value.intval = mode; | |
3254 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3255 | POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL, value); | |
3256 | break; | |
3257 | case SEC_WIRELESS_TX_ON_MODE: | |
3258 | value.intval = true; | |
3259 | psy_do_property(battery->pdata->charger_name, set, | |
3260 | POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL, value); | |
3261 | ||
3262 | value.intval = mode; | |
3263 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3264 | POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL, value); | |
3265 | ||
3266 | break; | |
3267 | case SEC_WIRELESS_TX_OFF_MODE: | |
3268 | value.intval = false; | |
3269 | psy_do_property(battery->pdata->charger_name, set, | |
3270 | POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL, value); | |
3271 | break; | |
3272 | default: | |
3273 | break; | |
3274 | } | |
3275 | } | |
3276 | ||
3277 | static void sec_bat_fw_init_work(struct work_struct *work) | |
3278 | { | |
3279 | struct sec_battery_info *battery = container_of(work, | |
3280 | struct sec_battery_info, fw_init_work.work); | |
3281 | ||
3282 | union power_supply_propval value = {0, }; | |
3283 | int uno_status = 0, wpc_det = 0; | |
3284 | ||
3285 | dev_info(battery->dev, "%s \n", __func__); | |
3286 | ||
3287 | wpc_det = gpio_get_value(battery->pdata->wpc_det); | |
3288 | ||
3289 | pr_info("%s wpc_det = %d \n", __func__, wpc_det); | |
3290 | ||
3291 | psy_do_property(battery->pdata->charger_name, get, | |
3292 | POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL, value); | |
3293 | uno_status = value.intval; | |
3294 | pr_info("%s uno = %d \n", __func__, uno_status); | |
3295 | ||
3296 | if (!uno_status && !wpc_det) { | |
3297 | pr_info("%s uno on \n", __func__); | |
3298 | value.intval = true; | |
3299 | psy_do_property(battery->pdata->charger_name, set, | |
3300 | POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL, value); | |
3301 | } | |
3302 | ||
3303 | value.intval = SEC_WIRELESS_RX_INIT; | |
3304 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3305 | POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL, value); | |
3306 | ||
3307 | if (!uno_status && !wpc_det) { | |
3308 | pr_info("%s uno off \n", __func__); | |
3309 | value.intval = false; | |
3310 | psy_do_property(battery->pdata->charger_name, set, | |
3311 | POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL, value); | |
3312 | } | |
3313 | } | |
3314 | #endif | |
3315 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
3316 | static int sec_bat_parse_dt(struct device *dev, struct sec_battery_info *battery); | |
3317 | static void sec_bat_update_data_work(struct work_struct *work) | |
3318 | { | |
3319 | struct sec_battery_info *battery = container_of(work, | |
3320 | struct sec_battery_info, batt_data_work.work); | |
3321 | ||
3322 | sec_battery_update_data(battery->data_path); | |
3323 | wake_unlock(&battery->batt_data_wake_lock); | |
3324 | } | |
3325 | #endif | |
3326 | ||
3327 | static void sec_bat_misc_event_work(struct work_struct *work) | |
3328 | { | |
3329 | struct sec_battery_info *battery = container_of(work, | |
3330 | struct sec_battery_info, misc_event_work.work); | |
3331 | int xor_misc_event = battery->prev_misc_event ^ battery->misc_event; | |
3332 | ||
3333 | if ((xor_misc_event & BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE) && | |
3334 | (battery->cable_type == SEC_BATTERY_CABLE_NONE)) { | |
3335 | if (battery->misc_event & BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE) { | |
3336 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_BUCK_OFF); | |
3337 | } else if (battery->prev_misc_event & BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE) { | |
3338 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
3339 | } | |
3340 | } | |
3341 | ||
3342 | pr_info("%s: change misc event(0x%x --> 0x%x)\n", | |
3343 | __func__, battery->prev_misc_event, battery->misc_event); | |
3344 | battery->prev_misc_event = battery->misc_event; | |
3345 | wake_unlock(&battery->misc_event_wake_lock); | |
3346 | ||
3347 | wake_lock(&battery->monitor_wake_lock); | |
3348 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
3349 | } | |
3350 | ||
3351 | static void sec_bat_calculate_safety_time(struct sec_battery_info *battery) | |
3352 | { | |
3353 | unsigned long long expired_time = battery->expired_time; | |
3354 | struct timespec ts = {0, }; | |
3355 | int curr = 0; | |
3356 | int input_power = battery->current_max * battery->input_voltage * 1000; | |
3357 | int charging_power = battery->charging_current * (battery->pdata->chg_float_voltage / battery->pdata->chg_float_voltage_conv); | |
3358 | static int discharging_cnt = 0; | |
3359 | ||
3360 | if (battery->current_avg < 0) { | |
3361 | discharging_cnt++; | |
3362 | } else { | |
3363 | discharging_cnt = 0; | |
3364 | } | |
3365 | ||
3366 | if (discharging_cnt >= 5) { | |
3367 | battery->expired_time = battery->pdata->expired_time; | |
3368 | battery->prev_safety_time = 0; | |
3369 | pr_info("%s : SAFETY TIME RESET! DISCHARGING CNT(%d)\n", | |
3370 | __func__, discharging_cnt); | |
3371 | discharging_cnt = 0; | |
3372 | return; | |
3373 | } else if (battery->lcd_status && battery->stop_timer) { | |
3374 | battery->prev_safety_time = 0; | |
3375 | return; | |
3376 | } | |
3377 | ||
3378 | get_monotonic_boottime(&ts); | |
3379 | ||
3380 | if (battery->prev_safety_time == 0) { | |
3381 | battery->prev_safety_time = ts.tv_sec; | |
3382 | } | |
3383 | ||
3384 | if (input_power > charging_power) { | |
3385 | curr = battery->charging_current; | |
3386 | } else { | |
3387 | curr = input_power / (battery->pdata->chg_float_voltage / battery->pdata->chg_float_voltage_conv); | |
3388 | curr = (curr * 9) / 10; | |
3389 | } | |
3390 | ||
3391 | if (battery->lcd_status && !battery->stop_timer) { | |
3392 | battery->stop_timer = true; | |
3393 | } else if (!battery->lcd_status && battery->stop_timer) { | |
3394 | battery->stop_timer = false; | |
3395 | } | |
3396 | ||
3397 | pr_info("%s : EXPIRED_TIME(%llu), IP(%d), CP(%d), CURR(%d), STANDARD(%d)\n", | |
3398 | __func__, expired_time, input_power, charging_power, curr, battery->pdata->standard_curr); | |
3399 | ||
3400 | if (curr == 0) | |
3401 | return; | |
3402 | ||
3403 | expired_time = (expired_time * battery->pdata->standard_curr) / curr; | |
3404 | ||
3405 | pr_info("%s : CAL_EXPIRED_TIME(%llu) TIME NOW(%ld) TIME PREV(%ld)\n", __func__, expired_time, ts.tv_sec, battery->prev_safety_time); | |
3406 | ||
3407 | if (expired_time <= ((ts.tv_sec - battery->prev_safety_time) * 1000)) | |
3408 | expired_time = 0; | |
3409 | else | |
3410 | expired_time -= ((ts.tv_sec - battery->prev_safety_time) * 1000); | |
3411 | ||
3412 | battery->cal_safety_time = expired_time; | |
3413 | expired_time = (expired_time * curr) / battery->pdata->standard_curr; | |
3414 | ||
3415 | battery->expired_time = expired_time; | |
3416 | battery->prev_safety_time = ts.tv_sec; | |
3417 | pr_info("%s : REMAIN_TIME(%ld) CAL_REMAIN_TIME(%ld)\n", __func__, battery->expired_time, battery->cal_safety_time); | |
3418 | } | |
3419 | ||
3420 | static void sec_bat_monitor_work( | |
3421 | struct work_struct *work) | |
3422 | { | |
3423 | struct sec_battery_info *battery = | |
3424 | container_of(work, struct sec_battery_info, | |
3425 | monitor_work.work); | |
3426 | static struct timespec old_ts = {0, }; | |
3427 | struct timespec c_ts = {0, }; | |
3428 | ||
3429 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
3430 | c_ts = ktime_to_timespec(ktime_get_boottime()); | |
3431 | ||
3432 | mutex_lock(&battery->wclock); | |
3433 | if (!battery->wc_enable) { | |
3434 | pr_info("%s: wc_enable(%d), cnt(%d)\n", | |
3435 | __func__, battery->wc_enable, battery->wc_enable_cnt); | |
3436 | if (battery->wc_enable_cnt > battery->wc_enable_cnt_value) { | |
3437 | battery->wc_enable = true; | |
3438 | battery->wc_enable_cnt = 0; | |
3439 | if (battery->pdata->wpc_en) { | |
3440 | gpio_direction_output(battery->pdata->wpc_en, 0); | |
3441 | pr_info("%s: WC CONTROL: Enable", __func__); | |
3442 | } | |
3443 | pr_info("%s: wpc_en(%d)\n", | |
3444 | __func__, gpio_get_value(battery->pdata->wpc_en)); | |
3445 | } | |
3446 | battery->wc_enable_cnt++; | |
3447 | } | |
3448 | mutex_unlock(&battery->wclock); | |
3449 | ||
3450 | /* monitor once after wakeup */ | |
3451 | if (battery->polling_in_sleep) { | |
3452 | battery->polling_in_sleep = false; | |
3453 | if ((battery->status == POWER_SUPPLY_STATUS_DISCHARGING) && | |
3454 | (battery->ps_enable != true)) { | |
3455 | if ((unsigned long)(c_ts.tv_sec - old_ts.tv_sec) < 10 * 60) { | |
3456 | union power_supply_propval value = {0, }; | |
3457 | ||
3458 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3459 | POWER_SUPPLY_PROP_VOLTAGE_NOW, value); | |
3460 | battery->voltage_now = value.intval; | |
3461 | ||
3462 | value.intval = 0; | |
3463 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3464 | POWER_SUPPLY_PROP_CAPACITY, value); | |
3465 | battery->capacity = value.intval; | |
3466 | ||
3467 | sec_bat_get_temperature_info(battery); | |
3468 | #if defined(CONFIG_BATTERY_CISD) | |
3469 | sec_bat_cisd_check(battery); | |
3470 | #endif | |
3471 | power_supply_changed(battery->psy_bat); | |
3472 | pr_info("Skip monitor work(%ld, Vnow:%d(mV), SoC:%d(%%), Tbat:%d(0.1'C))\n", | |
3473 | c_ts.tv_sec - old_ts.tv_sec, battery->voltage_now, battery->capacity, battery->temperature); | |
3474 | ||
3475 | goto skip_monitor; | |
3476 | } | |
3477 | } | |
3478 | } | |
3479 | /* update last monitor time */ | |
3480 | old_ts = c_ts; | |
3481 | ||
3482 | sec_bat_get_battery_info(battery); | |
3483 | #if defined(CONFIG_BATTERY_CISD) | |
3484 | sec_bat_cisd_check(battery); | |
3485 | #endif | |
3486 | ||
3487 | #if defined(CONFIG_STEP_CHARGING) | |
3488 | sec_bat_check_step_charging(battery); | |
3489 | #endif | |
3490 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
3491 | /* time to full check */ | |
3492 | sec_bat_calc_time_to_full(battery); | |
3493 | #endif | |
3494 | ||
3495 | /* 0. test mode */ | |
3496 | if (battery->test_mode) { | |
3497 | dev_err(battery->dev, "%s: Test Mode\n", __func__); | |
3498 | sec_bat_do_test_function(battery); | |
3499 | if (battery->test_mode != 0) | |
3500 | goto continue_monitor; | |
3501 | } | |
3502 | ||
3503 | /* 1. battery check */ | |
3504 | if (!sec_bat_battery_cable_check(battery)) | |
3505 | goto continue_monitor; | |
3506 | ||
3507 | /* 2. voltage check */ | |
3508 | if (!sec_bat_voltage_check(battery)) | |
3509 | goto continue_monitor; | |
3510 | ||
3511 | /* monitor short routine in initial monitor */ | |
3512 | if (battery->pdata->monitor_initial_count || sec_bat_is_short_polling(battery)) | |
3513 | goto skip_current_monitor; | |
3514 | ||
3515 | /* 3. time management */ | |
3516 | if (!sec_bat_time_management(battery)) | |
3517 | goto continue_monitor; | |
3518 | ||
3519 | /* 4. temperature check */ | |
3520 | if (!sec_bat_temperature_check(battery)) | |
3521 | goto continue_monitor; | |
3522 | ||
3523 | #if defined(CONFIG_BATTERY_SWELLING) | |
3524 | sec_bat_swelling_check(battery); | |
3525 | ||
3526 | if ((battery->swelling_mode == SWELLING_MODE_CHARGING || battery->swelling_mode == SWELLING_MODE_FULL) && | |
3527 | (!battery->charging_block)) | |
3528 | sec_bat_swelling_fullcharged_check(battery); | |
3529 | else | |
3530 | sec_bat_fullcharged_check(battery); | |
3531 | #else | |
3532 | /* 5. full charging check */ | |
3533 | sec_bat_fullcharged_check(battery); | |
3534 | #endif /* CONFIG_BATTERY_SWELLING */ | |
3535 | ||
3536 | /* 6. additional check */ | |
3537 | if (battery->pdata->monitor_additional_check) | |
3538 | battery->pdata->monitor_additional_check(); | |
3539 | ||
3540 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
3541 | sec_bat_add_sbm_data(battery, SBM_DATA_COMMON_INFO); | |
3542 | #endif | |
3543 | ||
3544 | if ((battery->cable_type == SEC_BATTERY_CABLE_WIRELESS || | |
3545 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_STAND || | |
3546 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_TX) && | |
3547 | !battery->wc_cv_mode && battery->charging_passed_time > 10) | |
3548 | sec_bat_wc_cv_mode_check(battery); | |
3549 | ||
3550 | continue_monitor: | |
3551 | /* clear HEATING_CONTROL*/ | |
3552 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL); | |
3553 | ||
3554 | /* calculate safety time */ | |
3555 | if (!battery->charging_block) | |
3556 | sec_bat_calculate_safety_time(battery); | |
3557 | ||
3558 | /* set charging current */ | |
3559 | sec_bat_set_charging_current(battery); | |
3560 | ||
3561 | skip_current_monitor: | |
3562 | dev_info(battery->dev, | |
3563 | "%s: HLT(%d) HLR(%d) HT(%d), HR(%d), LT(%d), LR(%d), lpcharge(%d)\n", | |
3564 | __func__, battery->temp_highlimit_threshold, battery->temp_highlimit_recovery, | |
3565 | battery->temp_high_threshold, battery->temp_high_recovery, | |
3566 | battery->temp_low_threshold, battery->temp_low_recovery, lpcharge); | |
3567 | ||
3568 | dev_info(battery->dev, | |
3569 | "%s: Status(%s), mode(%s), Health(%s), Cable(%s, %s, %d, %d), level(%d%%), slate_mode(%d), store_mode(%d)" | |
3570 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
3571 | ", HV(%s), sleep_mode(%d)" | |
3572 | #endif | |
3573 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
3574 | ", Cycle(%d)" | |
3575 | #endif | |
3576 | "\n", __func__, | |
3577 | sec_bat_status_str[battery->status], | |
3578 | sec_bat_charging_mode_str[battery->charging_mode], | |
3579 | sec_bat_health_str[battery->health], | |
3580 | sec_cable_type[battery->cable_type], | |
3581 | sec_cable_type[battery->wire_status], | |
3582 | battery->muic_cable_type, | |
3583 | battery->pd_usb_attached, | |
3584 | battery->siop_level, | |
3585 | battery->slate_mode, | |
3586 | battery->store_mode | |
3587 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
3588 | , battery->hv_chg_name, sleep_mode | |
3589 | #endif | |
3590 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
3591 | , battery->batt_cycle | |
3592 | #endif | |
3593 | ); | |
3594 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
3595 | dev_info(battery->dev, | |
3596 | "%s: battery->stability_test(%d), battery->eng_not_full_status(%d)\n", | |
3597 | __func__, battery->stability_test, battery->eng_not_full_status); | |
3598 | #endif | |
3599 | #if defined(CONFIG_SEC_FACTORY) | |
3600 | if ((battery->cable_type != SEC_BATTERY_CABLE_NONE) && (battery->cable_type != SEC_BATTERY_CABLE_OTG)) { | |
3601 | #else | |
3602 | if ((battery->cable_type != SEC_BATTERY_CABLE_NONE) && (battery->cable_type != SEC_BATTERY_CABLE_OTG) && battery->store_mode) { | |
3603 | #endif | |
3604 | dev_info(battery->dev, | |
3605 | "%s: @battery->capacity = (%d), battery->status= (%d), battery->store_mode=(%d)\n", | |
3606 | __func__, battery->capacity, battery->status, battery->store_mode); | |
3607 | ||
3608 | if (battery->capacity >= STORE_MODE_CHARGING_MAX) { | |
3609 | int chg_mode = battery->misc_event & BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE ? | |
3610 | SEC_BAT_CHG_MODE_BUCK_OFF : SEC_BAT_CHG_MODE_CHARGING_OFF; | |
3611 | /* to discharge the battery, off buck */ | |
3612 | if (battery->capacity > STORE_MODE_CHARGING_MAX) | |
3613 | chg_mode = SEC_BAT_CHG_MODE_BUCK_OFF; | |
3614 | ||
3615 | sec_bat_set_charging_status(battery, | |
3616 | POWER_SUPPLY_STATUS_DISCHARGING); | |
3617 | sec_bat_set_charge(battery, chg_mode); | |
3618 | } | |
3619 | ||
3620 | if ((battery->capacity <= STORE_MODE_CHARGING_MIN) && (battery->status == POWER_SUPPLY_STATUS_DISCHARGING)) { | |
3621 | sec_bat_set_charging_status(battery, | |
3622 | POWER_SUPPLY_STATUS_CHARGING); | |
3623 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
3624 | } | |
3625 | } | |
3626 | power_supply_changed(battery->psy_bat); | |
3627 | ||
3628 | skip_monitor: | |
3629 | sec_bat_set_polling(battery); | |
3630 | ||
3631 | if (battery->capacity <= 0 || battery->health_change) | |
3632 | wake_lock_timeout(&battery->monitor_wake_lock, HZ * 5); | |
3633 | else | |
3634 | wake_unlock(&battery->monitor_wake_lock); | |
3635 | ||
3636 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
3637 | ||
3638 | return; | |
3639 | } | |
3640 | ||
3641 | static enum alarmtimer_restart sec_bat_alarm( | |
3642 | struct alarm *alarm, ktime_t now) | |
3643 | { | |
3644 | struct sec_battery_info *battery = container_of(alarm, | |
3645 | struct sec_battery_info, polling_alarm); | |
3646 | ||
3647 | dev_dbg(battery->dev, | |
3648 | "%s\n", __func__); | |
3649 | ||
3650 | /* In wake up, monitor work will be queued in complete function | |
3651 | * To avoid duplicated queuing of monitor work, | |
3652 | * do NOT queue monitor work in wake up by polling alarm | |
3653 | */ | |
3654 | if (!battery->polling_in_sleep) { | |
3655 | wake_lock(&battery->monitor_wake_lock); | |
3656 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
3657 | dev_dbg(battery->dev, "%s: Activated\n", __func__); | |
3658 | } | |
3659 | ||
3660 | return ALARMTIMER_NORESTART; | |
3661 | } | |
3662 | ||
3663 | static void sec_bat_check_input_voltage(struct sec_battery_info *battery) | |
3664 | { | |
3665 | unsigned int voltage = 0; | |
3666 | int input_current = battery->pdata->charging_current[battery->cable_type].input_current_limit; | |
3667 | ||
3668 | if (battery->cable_type == SEC_BATTERY_CABLE_PDIC) { | |
3669 | battery->max_charge_power = battery->pd_max_charge_power; | |
3670 | return; | |
3671 | } | |
3672 | else if (is_hv_wire_12v_type(battery->cable_type)) | |
3673 | voltage = SEC_INPUT_VOLTAGE_12V; | |
3674 | else if (is_hv_wire_9v_type(battery->cable_type)) | |
3675 | voltage = SEC_INPUT_VOLTAGE_9V; | |
3676 | else if (is_hv_wireless_type(battery->cable_type) || | |
3677 | battery->cable_type == SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV) | |
3678 | voltage = SEC_INPUT_VOLTAGE_10V; | |
3679 | else | |
3680 | voltage = SEC_INPUT_VOLTAGE_5V; | |
3681 | ||
3682 | battery->input_voltage = voltage; | |
3683 | battery->charge_power = voltage * input_current; | |
3684 | #if !defined(CONFIG_SEC_FACTORY) | |
3685 | if (battery->charge_power > battery->max_charge_power) | |
3686 | #endif | |
3687 | battery->max_charge_power = battery->charge_power; | |
3688 | ||
3689 | pr_info("%s: battery->input_voltage : %dV, %dmW, %dmW)\n", __func__, | |
3690 | battery->input_voltage, battery->charge_power, battery->max_charge_power); | |
3691 | } | |
3692 | ||
3693 | static void sec_bat_cable_work(struct work_struct *work) | |
3694 | { | |
3695 | struct sec_battery_info *battery = container_of(work, | |
3696 | struct sec_battery_info, cable_work.work); | |
3697 | union power_supply_propval val = {0, }; | |
3698 | int current_cable_type = SEC_BATTERY_CABLE_NONE; | |
3699 | ||
3700 | dev_info(battery->dev, "%s: Start\n", __func__); | |
3701 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL, | |
3702 | SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL); | |
3703 | #if defined(CONFIG_CCIC_NOTIFIER) | |
3704 | if (battery->wire_status == SEC_BATTERY_CABLE_PDIC) { | |
3705 | if (battery->pdic_info.sink_status.selected_pdo_num == | |
3706 | battery->pdic_info.sink_status.current_pdo_num) | |
3707 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_SELECT_PDO); | |
3708 | sec_bat_get_input_current_in_power_list(battery); | |
3709 | sec_bat_get_charging_current_in_power_list(battery); | |
3710 | } | |
3711 | #endif | |
3712 | ||
3713 | if (battery->wc_status && battery->wc_enable) { | |
3714 | int wireless_current, wire_current; | |
3715 | int temp_current_type; | |
3716 | ||
3717 | if (battery->wc_status == SEC_WIRELESS_PAD_WPC) | |
3718 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS; | |
3719 | else if (battery->wc_status == SEC_WIRELESS_PAD_WPC_HV) | |
3720 | current_cable_type = SEC_BATTERY_CABLE_HV_WIRELESS; | |
3721 | else if (battery->wc_status == SEC_WIRELESS_PAD_WPC_PACK) | |
3722 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS_PACK; | |
3723 | else if (battery->wc_status == SEC_WIRELESS_PAD_WPC_PACK_HV) | |
3724 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS_HV_PACK; | |
3725 | else if (battery->wc_status == SEC_WIRELESS_PAD_WPC_STAND) | |
3726 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS_STAND; | |
3727 | else if (battery->wc_status == SEC_WIRELESS_PAD_WPC_STAND_HV) | |
3728 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS_HV_STAND; | |
3729 | else if (battery->wc_status == SEC_WIRELESS_PAD_VEHICLE) | |
3730 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS_VEHICLE; | |
3731 | else if (battery->wc_status == SEC_WIRELESS_PAD_VEHICLE_HV) | |
3732 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS_HV_VEHICLE; | |
3733 | else if (battery->wc_status == SEC_WIRELESS_PAD_PREPARE_HV) | |
3734 | current_cable_type = SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV; | |
3735 | else if (battery->wc_status == SEC_WIRELESS_PAD_TX) | |
3736 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS_TX; | |
3737 | else | |
3738 | current_cable_type = SEC_BATTERY_CABLE_PMA_WIRELESS; | |
3739 | ||
3740 | if (current_cable_type == SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV) | |
3741 | temp_current_type = SEC_BATTERY_CABLE_HV_WIRELESS; | |
3742 | else | |
3743 | temp_current_type = current_cable_type; | |
3744 | ||
3745 | if (battery->wire_status != SEC_BATTERY_CABLE_NONE) { | |
3746 | wireless_current = battery->pdata->charging_current[temp_current_type].input_current_limit; | |
3747 | wireless_current = wireless_current * (is_hv_wireless_type(temp_current_type) ? | |
3748 | SEC_INPUT_VOLTAGE_9V : SEC_INPUT_VOLTAGE_5V); | |
3749 | if (battery->wire_status == SEC_BATTERY_CABLE_PDIC) { | |
3750 | if (wireless_current < battery->pd_max_charge_power) | |
3751 | current_cable_type = battery->wire_status; | |
3752 | } else { | |
3753 | wire_current = (battery->wire_status == SEC_BATTERY_CABLE_PREPARE_TA ? | |
3754 | battery->pdata->charging_current[SEC_BATTERY_CABLE_TA].input_current_limit : | |
3755 | battery->pdata->charging_current[battery->wire_status].input_current_limit); | |
3756 | ||
3757 | wire_current = wire_current * (is_hv_wire_type(battery->wire_status) ? | |
3758 | (battery->wire_status == SEC_BATTERY_CABLE_12V_TA ? SEC_INPUT_VOLTAGE_12V : SEC_INPUT_VOLTAGE_9V) | |
3759 | : SEC_INPUT_VOLTAGE_5V); | |
3760 | pr_info("%s: wl_cur(%d), wr_cur(%d), wc_cable_type(%d), wire_cable_type(%d)\n", | |
3761 | __func__, wireless_current, wire_current, current_cable_type, battery->wire_status); | |
3762 | ||
3763 | if (wireless_current < wire_current) | |
3764 | current_cable_type = battery->wire_status; | |
3765 | } | |
3766 | } | |
3767 | } else | |
3768 | current_cable_type = battery->wire_status; | |
3769 | ||
3770 | if (battery->wc_status) { | |
3771 | /* wired charger has priority, but wireless charger exist. */ | |
3772 | val.intval = is_wired_type(current_cable_type) ? | |
3773 | MFC_LDO_OFF : MFC_LDO_ON; | |
3774 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3775 | POWER_SUPPLY_PROP_CHARGE_EMPTY, val); | |
3776 | } | |
3777 | ||
3778 | if (current_cable_type == SEC_BATTERY_CABLE_PDIC && | |
3779 | battery->cable_type == SEC_BATTERY_CABLE_PDIC && | |
3780 | !battery->slate_mode) { | |
3781 | cancel_delayed_work(&battery->afc_work); | |
3782 | wake_unlock(&battery->afc_wake_lock); | |
3783 | sec_bat_set_current_event(battery, 0, | |
3784 | SEC_BAT_CURRENT_EVENT_AFC | SEC_BAT_CURRENT_EVENT_AICL); | |
3785 | battery->aicl_current = 0; | |
3786 | sec_bat_set_charging_current(battery); | |
3787 | power_supply_changed(battery->psy_bat); | |
3788 | goto end_of_cable_work; | |
3789 | } | |
3790 | ||
3791 | /* to clear this value when cable type switched without dettach */ | |
3792 | if ((is_wired_type(battery->cable_type) && is_wireless_type(current_cable_type)) || | |
3793 | (is_wireless_type(battery->cable_type) && is_wired_type(current_cable_type))) | |
3794 | battery->max_charge_power = 0; | |
3795 | ||
3796 | if ((current_cable_type == battery->cable_type) && !battery->slate_mode) { | |
3797 | dev_dbg(battery->dev, | |
3798 | "%s: Cable is NOT Changed(%d)\n", | |
3799 | __func__, battery->cable_type); | |
3800 | /* Do NOT activate cable work for NOT changed */ | |
3801 | goto end_of_cable_work; | |
3802 | } | |
3803 | ||
3804 | #if defined(CONFIG_BATTERY_SWELLING) | |
3805 | if ((current_cable_type == SEC_BATTERY_CABLE_NONE) || | |
3806 | (battery->cable_type == SEC_BATTERY_CABLE_NONE && battery->swelling_mode == SWELLING_MODE_NONE) || | |
3807 | (battery->cable_type == SEC_BATTERY_CABLE_OTG && battery->swelling_mode == SWELLING_MODE_NONE)) { | |
3808 | battery->swelling_mode = SWELLING_MODE_NONE; | |
3809 | /* restore 4.4V float voltage */ | |
3810 | val.intval = battery->pdata->swelling_normal_float_voltage; | |
3811 | psy_do_property(battery->pdata->charger_name, set, | |
3812 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
3813 | pr_info("%s: float voltage = %d\n", __func__, val.intval); | |
3814 | } else { | |
3815 | pr_info("%s: skip float_voltage setting, swelling_mode(%d)\n", | |
3816 | __func__, battery->swelling_mode); | |
3817 | } | |
3818 | #endif | |
3819 | ||
3820 | battery->cable_type = current_cable_type; | |
3821 | battery->wpc_vout_level = WIRELESS_VOUT_10V; | |
3822 | if (is_wireless_type(battery->cable_type)) { | |
3823 | power_supply_changed(battery->psy_bat); | |
3824 | /* After 10sec wireless charging, Vrect headroom has to be reduced */ | |
3825 | wake_lock(&battery->wc_headroom_wake_lock); | |
3826 | queue_delayed_work(battery->monitor_wqueue, &battery->wc_headroom_work, | |
3827 | msecs_to_jiffies(10000)); | |
3828 | } | |
3829 | ||
3830 | if (battery->pdata->check_cable_result_callback) | |
3831 | battery->pdata->check_cable_result_callback(battery->cable_type); | |
3832 | /* platform can NOT get information of cable connection | |
3833 | * because wakeup time is too short to check uevent | |
3834 | * To make sure that target is wakeup | |
3835 | * if cable is connected and disconnected, | |
3836 | * activated wake lock in a few seconds | |
3837 | */ | |
3838 | wake_lock_timeout(&battery->vbus_wake_lock, HZ * 10); | |
3839 | ||
3840 | if (battery->cable_type == SEC_BATTERY_CABLE_NONE || | |
3841 | ((battery->pdata->cable_check_type & | |
3842 | SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE) && | |
3843 | battery->cable_type == SEC_BATTERY_CABLE_UNKNOWN)) { | |
3844 | /* initialize all status */ | |
3845 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
3846 | battery->vbus_chg_by_siop = false; | |
3847 | battery->is_recharging = false; | |
3848 | #if defined(CONFIG_BATTERY_CISD) | |
3849 | battery->cisd.charging_end_time = 0; | |
3850 | battery->cisd.recharge_count = 0; | |
3851 | battery->cisd.charging_end_time_2 = 0; | |
3852 | battery->cisd.recharge_count_2 = 0; | |
3853 | battery->cisd.ab_vbat_check_count = 0; | |
3854 | battery->cisd.state &= ~CISD_STATE_OVER_VOLTAGE; | |
3855 | #endif | |
3856 | battery->input_voltage = 0; | |
3857 | battery->charge_power = 0; | |
3858 | battery->max_charge_power = 0; | |
3859 | battery->pd_max_charge_power = 0; | |
3860 | sec_bat_set_charging_status(battery, | |
3861 | POWER_SUPPLY_STATUS_DISCHARGING); | |
3862 | battery->chg_limit = false; | |
3863 | battery->mix_limit = false; | |
3864 | battery->chg_limit_recovery_cable = SEC_BATTERY_CABLE_NONE; | |
3865 | battery->wc_heating_start_time = 0; | |
3866 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
3867 | cancel_delayed_work(&battery->afc_work); | |
3868 | wake_unlock(&battery->afc_wake_lock); | |
3869 | sec_bat_change_default_current(battery, SEC_BATTERY_CABLE_USB, | |
3870 | USB_CURRENT_HIGH_SPEED, USB_CURRENT_HIGH_SPEED); | |
3871 | sec_bat_change_default_current(battery, SEC_BATTERY_CABLE_TA, | |
3872 | battery->pdata->default_input_current, battery->pdata->default_charging_current); | |
3873 | /* usb default current is 100mA before configured*/ | |
3874 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_USB_100MA, | |
3875 | (SEC_BAT_CURRENT_EVENT_CHARGE_DISABLE | | |
3876 | SEC_BAT_CURRENT_EVENT_AFC | | |
3877 | SEC_BAT_CURRENT_EVENT_USB_SUPER | | |
3878 | SEC_BAT_CURRENT_EVENT_USB_100MA | | |
3879 | SEC_BAT_CURRENT_EVENT_VBAT_OVP | | |
3880 | SEC_BAT_CURRENT_EVENT_VSYS_OVP | | |
3881 | SEC_BAT_CURRENT_EVENT_CHG_LIMIT | | |
3882 | SEC_BAT_CURRENT_EVENT_AICL | | |
3883 | SEC_BAT_CURRENT_EVENT_SELECT_PDO)); | |
3884 | ||
3885 | cancel_delayed_work(&battery->slowcharging_work); | |
3886 | battery->wc_cv_mode = false; | |
3887 | battery->is_sysovlo = false; | |
3888 | battery->is_vbatovlo = false; | |
3889 | battery->is_abnormal_temp = false; | |
3890 | ||
3891 | if (sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF)) | |
3892 | goto end_of_cable_work; | |
3893 | } else if(battery->slate_mode) { | |
3894 | dev_info(battery->dev, | |
3895 | "%s:slate mode on\n",__func__); | |
3896 | battery->is_recharging = false; | |
3897 | battery->cable_type = SEC_BATTERY_CABLE_NONE; | |
3898 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
3899 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
3900 | sec_bat_set_charging_status(battery, | |
3901 | POWER_SUPPLY_STATUS_DISCHARGING); | |
3902 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_BUCK_OFF); | |
3903 | } else { | |
3904 | #if defined(CONFIG_EN_OOPS) | |
3905 | val.intval = battery->cable_type; | |
3906 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
3907 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, val); | |
3908 | #endif | |
3909 | /* Do NOT display the charging icon when OTG or HMT_CONNECTED is enabled */ | |
3910 | if (battery->cable_type == SEC_BATTERY_CABLE_OTG || | |
3911 | battery->cable_type == SEC_BATTERY_CABLE_POWER_SHARING) { | |
3912 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
3913 | battery->status = POWER_SUPPLY_STATUS_DISCHARGING; | |
3914 | } else if (!battery->is_sysovlo && !battery->is_vbatovlo && !battery->is_abnormal_temp && | |
3915 | (!battery->charging_block || !battery->swelling_mode)) { | |
3916 | if (battery->pdata->full_check_type != | |
3917 | SEC_BATTERY_FULLCHARGED_NONE) | |
3918 | battery->charging_mode = | |
3919 | SEC_BATTERY_CHARGING_1ST; | |
3920 | else | |
3921 | battery->charging_mode = | |
3922 | SEC_BATTERY_CHARGING_2ND; | |
3923 | ||
3924 | if (battery->status == POWER_SUPPLY_STATUS_FULL) | |
3925 | sec_bat_set_charging_status(battery, | |
3926 | POWER_SUPPLY_STATUS_FULL); | |
3927 | else | |
3928 | sec_bat_set_charging_status(battery, | |
3929 | POWER_SUPPLY_STATUS_CHARGING); | |
3930 | } | |
3931 | ||
3932 | if (!battery->is_sysovlo && !battery->is_vbatovlo && !battery->is_abnormal_temp) | |
3933 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
3934 | ||
3935 | if (battery->cable_type == SEC_BATTERY_CABLE_TA || | |
3936 | battery->cable_type == SEC_BATTERY_CABLE_WIRELESS || | |
3937 | battery->cable_type == SEC_BATTERY_CABLE_PMA_WIRELESS) { | |
3938 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_AFC, SEC_BAT_CURRENT_EVENT_AFC); | |
3939 | } else { | |
3940 | cancel_delayed_work(&battery->afc_work); | |
3941 | wake_unlock(&battery->afc_wake_lock); | |
3942 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_AFC); | |
3943 | } | |
3944 | ||
3945 | if (battery->cable_type == SEC_BATTERY_CABLE_OTG || | |
3946 | battery->cable_type == SEC_BATTERY_CABLE_POWER_SHARING) { | |
3947 | if (sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF)) | |
3948 | goto end_of_cable_work; | |
3949 | } else if (!battery->is_sysovlo && !battery->is_vbatovlo && !battery->is_abnormal_temp && | |
3950 | (!battery->charging_block || !battery->swelling_mode)) { | |
3951 | if (sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING)) | |
3952 | goto end_of_cable_work; | |
3953 | } | |
3954 | ||
3955 | if (battery->cable_type == SEC_BATTERY_CABLE_USB && !lpcharge) | |
3956 | queue_delayed_work(battery->monitor_wqueue, &battery->slowcharging_work, | |
3957 | msecs_to_jiffies(3000)); | |
3958 | ||
3959 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
3960 | if (lpcharge) { | |
3961 | cancel_delayed_work(&battery->timetofull_work); | |
3962 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_AFC) { | |
3963 | int work_delay = 0; | |
3964 | ||
3965 | if (!is_wireless_type(battery->cable_type)) { | |
3966 | work_delay = battery->pdata->pre_afc_work_delay; | |
3967 | } else { | |
3968 | work_delay = battery->pdata->pre_wc_afc_work_delay; | |
3969 | } | |
3970 | ||
3971 | queue_delayed_work(battery->monitor_wqueue, | |
3972 | &battery->timetofull_work, msecs_to_jiffies(work_delay)); | |
3973 | } | |
3974 | } | |
3975 | #endif | |
3976 | } | |
3977 | ||
3978 | /* set online(cable type) */ | |
3979 | val.intval = battery->cable_type; | |
3980 | psy_do_property(battery->pdata->charger_name, set, | |
3981 | POWER_SUPPLY_PROP_ONLINE, val); | |
3982 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
3983 | POWER_SUPPLY_PROP_ONLINE, val); | |
3984 | /* set charging current */ | |
3985 | psy_do_property(battery->pdata->charger_name, get, | |
3986 | POWER_SUPPLY_PROP_CURRENT_AVG, val); | |
3987 | battery->aicl_current = 0; | |
3988 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_AICL); | |
3989 | battery->input_current = val.intval; | |
3990 | /* to init battery type current when wireless charging -> battery case */ | |
3991 | if (battery->cable_type == SEC_BATTERY_CABLE_NONE) | |
3992 | psy_do_property(battery->pdata->charger_name, set, | |
3993 | POWER_SUPPLY_PROP_CURRENT_MAX, val); | |
3994 | if (battery->status != POWER_SUPPLY_STATUS_DISCHARGING) | |
3995 | sec_bat_check_input_voltage(battery); | |
3996 | sec_bat_set_charging_current(battery); | |
3997 | ||
3998 | /* polling time should be reset when cable is changed | |
3999 | * polling_in_sleep should be reset also | |
4000 | * before polling time is re-calculated | |
4001 | * to prevent from counting 1 for events | |
4002 | * right after cable is connected | |
4003 | */ | |
4004 | battery->polling_in_sleep = false; | |
4005 | sec_bat_get_polling_time(battery); | |
4006 | ||
4007 | dev_info(battery->dev, | |
4008 | "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n", | |
4009 | __func__, sec_bat_status_str[battery->status], | |
4010 | battery->polling_in_sleep ? "Yes" : "No", | |
4011 | (battery->charging_mode == | |
4012 | SEC_BATTERY_CHARGING_NONE) ? "No" : "Yes", | |
4013 | battery->polling_short ? "Yes" : "No"); | |
4014 | dev_info(battery->dev, | |
4015 | "%s: Polling time is reset to %d sec.\n", __func__, | |
4016 | battery->polling_time); | |
4017 | ||
4018 | battery->polling_count = 1; /* initial value = 1 */ | |
4019 | ||
4020 | wake_lock(&battery->monitor_wake_lock); | |
4021 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
4022 | end_of_cable_work: | |
4023 | wake_unlock(&battery->cable_wake_lock); | |
4024 | dev_info(battery->dev, "%s: End\n", __func__); | |
4025 | } | |
4026 | ||
4027 | static void sec_bat_afc_work(struct work_struct *work) | |
4028 | { | |
4029 | struct sec_battery_info *battery = container_of(work, | |
4030 | struct sec_battery_info, afc_work.work); | |
4031 | union power_supply_propval value = {0, }; | |
4032 | ||
4033 | psy_do_property(battery->pdata->charger_name, get, | |
4034 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
4035 | battery->current_max = value.intval; | |
4036 | ||
4037 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_AFC) { | |
4038 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_AFC); | |
4039 | if ((battery->wc_status != SEC_WIRELESS_PAD_NONE && | |
4040 | battery->current_max >= battery->pdata->pre_wc_afc_input_current) || | |
4041 | ((battery->cable_type == SEC_BATTERY_CABLE_TA) && | |
4042 | battery->current_max >= battery->pdata->pre_afc_input_current)) { | |
4043 | sec_bat_set_charging_current(battery); | |
4044 | } | |
4045 | } | |
4046 | wake_unlock(&battery->afc_wake_lock); | |
4047 | } | |
4048 | ||
4049 | ssize_t sec_bat_show_attrs(struct device *dev, | |
4050 | struct device_attribute *attr, char *buf) | |
4051 | { | |
4052 | struct power_supply *psy = dev_get_drvdata(dev); | |
4053 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
4054 | const ptrdiff_t offset = attr - sec_battery_attrs; | |
4055 | union power_supply_propval value = {0, }; | |
4056 | int i = 0; | |
4057 | int ret = 0; | |
4058 | ||
4059 | switch (offset) { | |
4060 | case BATT_RESET_SOC: | |
4061 | break; | |
4062 | case BATT_READ_RAW_SOC: | |
4063 | { | |
4064 | value.intval = | |
4065 | SEC_FUELGAUGE_CAPACITY_TYPE_RAW; | |
4066 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4067 | POWER_SUPPLY_PROP_CAPACITY, value); | |
4068 | ||
4069 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4070 | value.intval); | |
4071 | } | |
4072 | break; | |
4073 | case BATT_READ_ADJ_SOC: | |
4074 | break; | |
4075 | case BATT_TYPE: | |
4076 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", | |
4077 | battery->batt_type); | |
4078 | break; | |
4079 | case BATT_VFOCV: | |
4080 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4081 | battery->voltage_ocv); | |
4082 | break; | |
4083 | case BATT_VOL_ADC: | |
4084 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4085 | battery->inbat_adc); | |
4086 | break; | |
4087 | case BATT_VOL_ADC_CAL: | |
4088 | break; | |
4089 | case BATT_VOL_AVER: | |
4090 | break; | |
4091 | case BATT_VOL_ADC_AVER: | |
4092 | break; | |
4093 | ||
4094 | case BATT_CURRENT_UA_NOW: | |
4095 | { | |
4096 | value.intval = SEC_BATTERY_CURRENT_UA; | |
4097 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4098 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
4099 | #if defined(CONFIG_SEC_FACTORY) | |
4100 | pr_err("%s: batt_current_ua_now (%d)\n", | |
4101 | __func__, value.intval); | |
4102 | #endif | |
4103 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4104 | value.intval); | |
4105 | } | |
4106 | break; | |
4107 | case BATT_CURRENT_UA_AVG: | |
4108 | { | |
4109 | value.intval = SEC_BATTERY_CURRENT_UA; | |
4110 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4111 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
4112 | ||
4113 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4114 | value.intval); | |
4115 | } | |
4116 | break; | |
4117 | ||
4118 | case BATT_FILTER_CFG: | |
4119 | { | |
4120 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4121 | POWER_SUPPLY_PROP_FILTER_CFG, value); | |
4122 | ||
4123 | i += scnprintf(buf + i, PAGE_SIZE - i, "%x\n", | |
4124 | value.intval); | |
4125 | } | |
4126 | break; | |
4127 | case BATT_TEMP: | |
4128 | switch (battery->pdata->thermal_source) { | |
4129 | case SEC_BATTERY_THERMAL_SOURCE_FG: | |
4130 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4131 | POWER_SUPPLY_PROP_TEMP, value); | |
4132 | break; | |
4133 | case SEC_BATTERY_THERMAL_SOURCE_CALLBACK: | |
4134 | if (battery->pdata->get_temperature_callback) { | |
4135 | battery->pdata->get_temperature_callback( | |
4136 | POWER_SUPPLY_PROP_TEMP, &value); | |
4137 | } | |
4138 | break; | |
4139 | case SEC_BATTERY_THERMAL_SOURCE_ADC: | |
4140 | sec_bat_get_value_by_adc(battery, | |
4141 | SEC_BAT_ADC_CHANNEL_TEMP, &value); | |
4142 | break; | |
4143 | default: | |
4144 | break; | |
4145 | } | |
4146 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4147 | value.intval); | |
4148 | break; | |
4149 | case BATT_TEMP_ADC: | |
4150 | /* | |
4151 | If F/G is used for reading the temperature and | |
4152 | compensation table is used, | |
4153 | the raw value that isn't compensated can be read by | |
4154 | POWER_SUPPLY_PROP_TEMP_AMBIENT | |
4155 | */ | |
4156 | switch (battery->pdata->thermal_source) { | |
4157 | case SEC_BATTERY_THERMAL_SOURCE_FG: | |
4158 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4159 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
4160 | battery->temp_adc = value.intval; | |
4161 | break; | |
4162 | default: | |
4163 | break; | |
4164 | } | |
4165 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4166 | battery->temp_adc); | |
4167 | break; | |
4168 | case BATT_TEMP_AVER: | |
4169 | break; | |
4170 | case BATT_TEMP_ADC_AVER: | |
4171 | break; | |
4172 | case USB_TEMP: | |
4173 | if (battery->pdata->usb_thermal_source) { | |
4174 | sec_bat_get_value_by_adc(battery, | |
4175 | SEC_BAT_ADC_CHANNEL_USB_TEMP, &value); | |
4176 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4177 | value.intval); | |
4178 | } else { | |
4179 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4180 | 0); | |
4181 | } | |
4182 | break; | |
4183 | case USB_TEMP_ADC: | |
4184 | if (battery->pdata->usb_thermal_source) { | |
4185 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4186 | battery->usb_temp_adc); | |
4187 | } else { | |
4188 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4189 | 0); | |
4190 | } | |
4191 | break; | |
4192 | case CHG_TEMP: | |
4193 | if (battery->pdata->chg_thermal_source) { | |
4194 | sec_bat_get_value_by_adc(battery, | |
4195 | SEC_BAT_ADC_CHANNEL_CHG_TEMP, &value); | |
4196 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4197 | value.intval); | |
4198 | } else { | |
4199 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4200 | 0); | |
4201 | } | |
4202 | break; | |
4203 | case CHG_TEMP_ADC: | |
4204 | if (battery->pdata->chg_thermal_source) { | |
4205 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4206 | battery->chg_temp_adc); | |
4207 | } else { | |
4208 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4209 | 0); | |
4210 | } | |
4211 | break; | |
4212 | case SLAVE_CHG_TEMP: | |
4213 | if (battery->pdata->slave_thermal_source) { | |
4214 | sec_bat_get_value_by_adc(battery, | |
4215 | SEC_BAT_ADC_CHANNEL_SLAVE_CHG_TEMP, &value); | |
4216 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4217 | value.intval); | |
4218 | } else { | |
4219 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4220 | 0); | |
4221 | } | |
4222 | break; | |
4223 | case SLAVE_CHG_TEMP_ADC: | |
4224 | if (battery->pdata->slave_thermal_source) { | |
4225 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4226 | battery->slave_chg_temp_adc); | |
4227 | } else { | |
4228 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4229 | 0); | |
4230 | } | |
4231 | break; | |
4232 | case BATT_VF_ADC: | |
4233 | break; | |
4234 | case BATT_SLATE_MODE: | |
4235 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4236 | battery->slate_mode); | |
4237 | break; | |
4238 | ||
4239 | case BATT_LP_CHARGING: | |
4240 | if (lpcharge) { | |
4241 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4242 | lpcharge ? 1 : 0); | |
4243 | } | |
4244 | break; | |
4245 | case SIOP_ACTIVATED: | |
4246 | break; | |
4247 | case SIOP_LEVEL: | |
4248 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4249 | battery->siop_level); | |
4250 | break; | |
4251 | case SIOP_EVENT: | |
4252 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", 0); | |
4253 | break; | |
4254 | case BATT_CHARGING_SOURCE: | |
4255 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4256 | battery->cable_type); | |
4257 | break; | |
4258 | case FG_REG_DUMP: | |
4259 | break; | |
4260 | case FG_RESET_CAP: | |
4261 | break; | |
4262 | case FG_CAPACITY: | |
4263 | { | |
4264 | value.intval = | |
4265 | SEC_BATTERY_CAPACITY_DESIGNED; | |
4266 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4267 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4268 | ||
4269 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x ", | |
4270 | value.intval); | |
4271 | ||
4272 | value.intval = | |
4273 | SEC_BATTERY_CAPACITY_ABSOLUTE; | |
4274 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4275 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4276 | ||
4277 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x ", | |
4278 | value.intval); | |
4279 | ||
4280 | value.intval = | |
4281 | SEC_BATTERY_CAPACITY_TEMPERARY; | |
4282 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4283 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4284 | ||
4285 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x ", | |
4286 | value.intval); | |
4287 | ||
4288 | value.intval = | |
4289 | SEC_BATTERY_CAPACITY_CURRENT; | |
4290 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4291 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4292 | ||
4293 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x\n", | |
4294 | value.intval); | |
4295 | } | |
4296 | break; | |
4297 | case FG_ASOC: | |
4298 | value.intval = -1; | |
4299 | { | |
4300 | struct power_supply *psy_fg = NULL; | |
4301 | psy_fg = get_power_supply_by_name(battery->pdata->fuelgauge_name); | |
4302 | if (!psy_fg) { | |
4303 | pr_err("%s: Fail to get psy (%s)\n", | |
4304 | __func__, battery->pdata->fuelgauge_name); | |
4305 | } else { | |
4306 | if (psy_fg->desc->get_property != NULL) { | |
4307 | ret = psy_fg->desc->get_property(psy_fg, | |
4308 | POWER_SUPPLY_PROP_ENERGY_FULL, &value); | |
4309 | if (ret < 0) { | |
4310 | pr_err("%s: Fail to %s get (%d=>%d)\n", | |
4311 | __func__, battery->pdata->fuelgauge_name, | |
4312 | POWER_SUPPLY_PROP_ENERGY_FULL, ret); | |
4313 | } | |
4314 | } | |
4315 | } | |
4316 | } | |
4317 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4318 | value.intval); | |
4319 | break; | |
4320 | case AUTH: | |
4321 | break; | |
4322 | case CHG_CURRENT_ADC: | |
4323 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4324 | battery->current_adc); | |
4325 | break; | |
4326 | case WC_ADC: | |
4327 | break; | |
4328 | case WC_STATUS: | |
4329 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4330 | is_wireless_type(battery->cable_type) ? 1: 0); | |
4331 | break; | |
4332 | case WC_ENABLE: | |
4333 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4334 | battery->wc_enable); | |
4335 | break; | |
4336 | case WC_CONTROL: | |
4337 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4338 | battery->wc_enable); | |
4339 | break; | |
4340 | case WC_CONTROL_CNT: | |
4341 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4342 | battery->wc_enable_cnt_value); | |
4343 | break; | |
4344 | case LED_COVER: | |
4345 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4346 | battery->led_cover); | |
4347 | break; | |
4348 | case HV_CHARGER_STATUS: | |
4349 | { | |
4350 | int check_val = 0; | |
4351 | if (is_hv_wire_12v_type(battery->cable_type) || | |
4352 | battery->max_charge_power >= HV_CHARGER_STATUS_STANDARD2) /* 20000mW */ | |
4353 | check_val = 2; | |
4354 | else if (is_hv_wire_type(battery->cable_type) || | |
4355 | (battery->cable_type == SEC_BATTERY_CABLE_PDIC && | |
4356 | battery->pd_max_charge_power >= HV_CHARGER_STATUS_STANDARD1 && | |
4357 | battery->pdic_info.sink_status.available_pdo_num > 1) || | |
4358 | battery->cable_type == SEC_BATTERY_CABLE_PREPARE_TA || | |
4359 | battery->max_charge_power >= HV_CHARGER_STATUS_STANDARD1) /* 12000mW */ | |
4360 | check_val = 1; | |
4361 | ||
4362 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", check_val); | |
4363 | } | |
4364 | break; | |
4365 | case HV_WC_CHARGER_STATUS: | |
4366 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4367 | is_hv_wireless_type(battery->cable_type) ? 1 : 0); | |
4368 | break; | |
4369 | case HV_CHARGER_SET: | |
4370 | break; | |
4371 | case FACTORY_MODE: | |
4372 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4373 | battery->factory_mode); | |
4374 | break; | |
4375 | case STORE_MODE: | |
4376 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4377 | battery->store_mode); | |
4378 | break; | |
4379 | case UPDATE: | |
4380 | break; | |
4381 | case TEST_MODE: | |
4382 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4383 | battery->test_mode); | |
4384 | break; | |
4385 | ||
4386 | case BATT_EVENT_CALL: | |
4387 | case BATT_EVENT_2G_CALL: | |
4388 | case BATT_EVENT_TALK_GSM: | |
4389 | break; | |
4390 | case BATT_EVENT_3G_CALL: | |
4391 | case BATT_EVENT_TALK_WCDMA: | |
4392 | break; | |
4393 | case BATT_EVENT_MUSIC: | |
4394 | break; | |
4395 | case BATT_EVENT_VIDEO: | |
4396 | break; | |
4397 | case BATT_EVENT_BROWSER: | |
4398 | break; | |
4399 | case BATT_EVENT_HOTSPOT: | |
4400 | break; | |
4401 | case BATT_EVENT_CAMERA: | |
4402 | break; | |
4403 | case BATT_EVENT_CAMCORDER: | |
4404 | break; | |
4405 | case BATT_EVENT_DATA_CALL: | |
4406 | break; | |
4407 | case BATT_EVENT_WIFI: | |
4408 | break; | |
4409 | case BATT_EVENT_WIBRO: | |
4410 | break; | |
4411 | case BATT_EVENT_LTE: | |
4412 | break; | |
4413 | case BATT_EVENT_LCD: | |
4414 | break; | |
4415 | case BATT_EVENT_GPS: | |
4416 | break; | |
4417 | case BATT_EVENT: | |
4418 | break; | |
4419 | case BATT_TEMP_TABLE: | |
4420 | i += scnprintf(buf + i, PAGE_SIZE - i, | |
4421 | "%d %d %d %d %d %d %d %d\n", | |
4422 | battery->pdata->temp_high_threshold_normal, | |
4423 | battery->pdata->temp_high_recovery_normal, | |
4424 | battery->pdata->temp_low_threshold_normal, | |
4425 | battery->pdata->temp_low_recovery_normal, | |
4426 | battery->pdata->temp_high_threshold_lpm, | |
4427 | battery->pdata->temp_high_recovery_lpm, | |
4428 | battery->pdata->temp_low_threshold_lpm, | |
4429 | battery->pdata->temp_low_recovery_lpm); | |
4430 | break; | |
4431 | case BATT_HIGH_CURRENT_USB: | |
4432 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4433 | battery->is_hc_usb); | |
4434 | break; | |
4435 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
4436 | case TEST_CHARGE_CURRENT: | |
4437 | { | |
4438 | psy_do_property(battery->pdata->charger_name, get, | |
4439 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
4440 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4441 | value.intval); | |
4442 | } | |
4443 | break; | |
4444 | #endif | |
4445 | case SET_STABILITY_TEST: | |
4446 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4447 | battery->stability_test); | |
4448 | break; | |
4449 | case BATT_CAPACITY_MAX: | |
4450 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4451 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, value); | |
4452 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4453 | break; | |
4454 | case BATT_INBAT_VOLTAGE: | |
4455 | case BATT_INBAT_VOLTAGE_OCV: | |
4456 | if(battery->pdata->support_fgsrc_change == true) { | |
4457 | int j, k, ocv, ocv_data[10]; | |
4458 | value.intval = 0; | |
4459 | psy_do_property(battery->pdata->fgsrc_switch_name, set, | |
4460 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4461 | for (j = 0; j < 10; j++) { | |
4462 | mdelay(175); | |
4463 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4464 | POWER_SUPPLY_PROP_VOLTAGE_NOW, value); | |
4465 | ocv_data[j] = value.intval; | |
4466 | } | |
4467 | value.intval = 1; | |
4468 | psy_do_property(battery->pdata->fgsrc_switch_name, set, | |
4469 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4470 | for (j = 1; j < 10; j++) { | |
4471 | ocv = ocv_data[j]; | |
4472 | k = j; | |
4473 | while (k > 0 && ocv_data[k-1] > ocv) { | |
4474 | ocv_data[k] = ocv_data[k-1]; | |
4475 | k--; | |
4476 | } | |
4477 | ocv_data[k] = ocv; | |
4478 | } | |
4479 | ocv = 0; | |
4480 | for (j = 2; j < 8; j++) { | |
4481 | ocv += ocv_data[j]; | |
4482 | } | |
4483 | ret = ocv / 6; | |
4484 | } else { | |
4485 | ret = sec_bat_get_inbat_vol_by_adc(battery); | |
4486 | } | |
4487 | dev_info(battery->dev, "in-battery voltage ocv(%d)\n", ret); | |
4488 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4489 | ret); | |
4490 | break; | |
4491 | case CHECK_SLAVE_CHG: | |
4492 | psy_do_property(battery->pdata->charger_name, get, | |
4493 | POWER_SUPPLY_EXT_PROP_CHECK_SLAVE_I2C, value); | |
4494 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4495 | value.intval); | |
4496 | pr_info("%s : CHECK_SLAVE_CHG=%d\n",__func__,value.intval); | |
4497 | break; | |
4498 | case BATT_INBAT_WIRELESS_CS100: | |
4499 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4500 | POWER_SUPPLY_PROP_STATUS, value); | |
4501 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4502 | break; | |
4503 | case HMT_TA_CONNECTED: | |
4504 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4505 | (battery->cable_type == SEC_BATTERY_CABLE_HMT_CONNECTED) ? 1 : 0); | |
4506 | break; | |
4507 | case HMT_TA_CHARGE: | |
4508 | #if defined(CONFIG_CCIC_NOTIFIER) | |
4509 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4510 | (battery->current_event & SEC_BAT_CURRENT_EVENT_CHARGE_DISABLE) ? 0 : 1); | |
4511 | #else | |
4512 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4513 | (battery->cable_type == SEC_BATTERY_CABLE_HMT_CHARGE) ? 1 : 0); | |
4514 | #endif | |
4515 | break; | |
4516 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
4517 | case FG_CYCLE: | |
4518 | value.intval = SEC_BATTERY_CAPACITY_CYCLE; | |
4519 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4520 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4521 | value.intval = value.intval / 100; | |
4522 | dev_info(battery->dev, "fg cycle(%d)\n", value.intval); | |
4523 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4524 | break; | |
4525 | case FG_FULL_VOLTAGE: | |
4526 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d %d\n", | |
4527 | battery->pdata->chg_float_voltage, battery->pdata->recharge_condition_vcell); | |
4528 | break; | |
4529 | case FG_FULLCAPNOM: | |
4530 | value.intval = | |
4531 | SEC_BATTERY_CAPACITY_AGEDCELL; | |
4532 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4533 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4534 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4535 | break; | |
4536 | case BATTERY_CYCLE: | |
4537 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", battery->batt_cycle); | |
4538 | break; | |
4539 | #endif | |
4540 | case BATT_WPC_TEMP: | |
4541 | if (battery->pdata->wpc_thermal_source) { | |
4542 | sec_bat_get_value_by_adc(battery, | |
4543 | SEC_BAT_ADC_CHANNEL_WPC_TEMP, &value); | |
4544 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4545 | value.intval); | |
4546 | } else { | |
4547 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4548 | 0); | |
4549 | } | |
4550 | break; | |
4551 | case BATT_WPC_TEMP_ADC: | |
4552 | if (battery->pdata->wpc_thermal_source) { | |
4553 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4554 | battery->wpc_temp_adc); | |
4555 | } else { | |
4556 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4557 | 0); | |
4558 | } | |
4559 | break; | |
4560 | case BATT_COIL_TEMP: | |
4561 | if (battery->pdata->coil_thermal_source) { | |
4562 | sec_bat_get_value_by_adc(battery, | |
4563 | SEC_BAT_ADC_CHANNEL_WPC_TEMP, &value); | |
4564 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4565 | value.intval); | |
4566 | } else { | |
4567 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4568 | 0); | |
4569 | } | |
4570 | break; | |
4571 | case BATT_COIL_TEMP_ADC: | |
4572 | if (battery->pdata->coil_thermal_source) { | |
4573 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4574 | battery->coil_temp_adc); | |
4575 | } else { | |
4576 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4577 | 0); | |
4578 | } | |
4579 | break; | |
4580 | case BATT_WIRELESS_MST_SWITCH_TEST: | |
4581 | value.intval = SEC_WIRELESS_MST_SWITCH_VERIFY; | |
4582 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4583 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4584 | pr_info("%s MST switch verify. result: %x\n", __func__, value.intval); | |
4585 | i += scnprintf(buf + i, PAGE_SIZE - i, "%x\n", value.intval); | |
4586 | break; | |
4587 | #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE) | |
4588 | case BATT_WIRELESS_FIRMWARE_UPDATE: | |
4589 | value.intval = SEC_WIRELESS_OTP_FIRM_VERIFY; | |
4590 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4591 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4592 | pr_info("%s RX firmware verify. result: %d\n", __func__, value.intval); | |
4593 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4594 | break; | |
4595 | case OTP_FIRMWARE_RESULT: | |
4596 | value.intval = SEC_WIRELESS_OTP_FIRM_RESULT; | |
4597 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4598 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4599 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4600 | break; | |
4601 | case WC_IC_GRADE: | |
4602 | value.intval = SEC_WIRELESS_IC_GRADE; | |
4603 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4604 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4605 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%x ", value.intval); | |
4606 | ||
4607 | value.intval = SEC_WIRELESS_IC_REVISION; | |
4608 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4609 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4610 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%x\n", value.intval); | |
4611 | break; | |
4612 | case OTP_FIRMWARE_VER_BIN: | |
4613 | value.intval = SEC_WIRELESS_OTP_FIRM_VER_BIN; | |
4614 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4615 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4616 | i += scnprintf(buf + i, PAGE_SIZE - i, "%x\n", value.intval); | |
4617 | break; | |
4618 | case OTP_FIRMWARE_VER: | |
4619 | value.intval = SEC_WIRELESS_OTP_FIRM_VER; | |
4620 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4621 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4622 | ||
4623 | i += scnprintf(buf + i, PAGE_SIZE - i, "%x\n", value.intval); | |
4624 | break; | |
4625 | case TX_FIRMWARE_RESULT: | |
4626 | value.intval = SEC_WIRELESS_TX_FIRM_RESULT; | |
4627 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4628 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4629 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4630 | break; | |
4631 | case TX_FIRMWARE_VER: | |
4632 | value.intval = SEC_WIRELESS_TX_FIRM_VER; | |
4633 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4634 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4635 | ||
4636 | i += scnprintf(buf + i, PAGE_SIZE - i, "%x\n", value.intval); | |
4637 | break; | |
4638 | case BATT_TX_STATUS: | |
4639 | value.intval = SEC_TX_FIRMWARE; | |
4640 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4641 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
4642 | ||
4643 | i += scnprintf(buf + i, PAGE_SIZE - i, "%x\n", value.intval); | |
4644 | break; | |
4645 | #endif | |
4646 | case WC_VOUT: | |
4647 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4648 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4649 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4650 | break; | |
4651 | case WC_VRECT: | |
4652 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4653 | POWER_SUPPLY_PROP_ENERGY_AVG, value); | |
4654 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4655 | break; | |
4656 | case BATT_HV_WIRELESS_STATUS: | |
4657 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4658 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
4659 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4660 | break; | |
4661 | case BATT_HV_WIRELESS_PAD_CTRL: | |
4662 | break; | |
4663 | case WC_OP_FREQ: | |
4664 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4665 | POWER_SUPPLY_EXT_PROP_WIRELESS_OP_FREQ, value); | |
4666 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
4667 | break; | |
4668 | case WC_CMD_INFO: | |
4669 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4670 | POWER_SUPPLY_EXT_PROP_WIRELESS_TX_CMD, value); | |
4671 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%02x ", | |
4672 | value.intval); | |
4673 | ||
4674 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
4675 | POWER_SUPPLY_EXT_PROP_WIRELESS_TX_VAL, value); | |
4676 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%02x ", | |
4677 | value.intval); | |
4678 | break; | |
4679 | case BATT_TUNE_FLOAT_VOLTAGE: | |
4680 | ret = battery->pdata->chg_float_voltage; | |
4681 | pr_info("%s float voltage = %d mA",__func__, ret); | |
4682 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4683 | ret); | |
4684 | break; | |
4685 | case BATT_TUNE_INPUT_CHARGE_CURRENT: | |
4686 | ret = battery->pdata->charging_current[i].input_current_limit; | |
4687 | pr_info("%s input charge current = %d mA",__func__, ret); | |
4688 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4689 | ret); | |
4690 | break; | |
4691 | case BATT_TUNE_FAST_CHARGE_CURRENT: | |
4692 | ret = battery->pdata->charging_current[i].fast_charging_current; | |
4693 | pr_info("%s fast charge current = %d mA",__func__, ret); | |
4694 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4695 | ret); | |
4696 | break; | |
4697 | case BATT_TUNE_UI_TERM_CURRENT_1ST: | |
4698 | ret = battery->pdata->full_check_current_1st; | |
4699 | pr_info("%s ui term current = %d mA",__func__, ret); | |
4700 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4701 | ret); | |
4702 | break; | |
4703 | case BATT_TUNE_UI_TERM_CURRENT_2ND: | |
4704 | ret = battery->pdata->full_check_current_2nd; | |
4705 | pr_info("%s ui term current = %d mA",__func__, ret); | |
4706 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4707 | ret); | |
4708 | break; | |
4709 | case BATT_TUNE_TEMP_HIGH_NORMAL: | |
4710 | ret = battery->pdata->temp_high_threshold_normal; | |
4711 | pr_info("%s temp high normal block = %d ",__func__, ret); | |
4712 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4713 | ret); | |
4714 | break; | |
4715 | case BATT_TUNE_TEMP_HIGH_REC_NORMAL: | |
4716 | ret = battery->pdata->temp_high_recovery_normal; | |
4717 | pr_info("%s temp high normal recover = %d ",__func__, ret); | |
4718 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4719 | ret); | |
4720 | break; | |
4721 | case BATT_TUNE_TEMP_LOW_NORMAL: | |
4722 | ret = battery->pdata->temp_low_threshold_normal; | |
4723 | pr_info("%s temp low normal block = %d ",__func__, ret); | |
4724 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4725 | ret); | |
4726 | break; | |
4727 | case BATT_TUNE_TEMP_LOW_REC_NORMAL: | |
4728 | ret = battery->pdata->temp_low_recovery_normal; | |
4729 | pr_info("%s temp low normal recover = %d ",__func__, ret); | |
4730 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4731 | ret); | |
4732 | break; | |
4733 | case BATT_TUNE_CHG_TEMP_HIGH: | |
4734 | ret = battery->pdata->chg_high_temp; | |
4735 | pr_info("%s chg_high_temp = %d ",__func__, ret); | |
4736 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4737 | ret); | |
4738 | break; | |
4739 | case BATT_TUNE_CHG_TEMP_REC: | |
4740 | ret = battery->pdata->chg_high_temp_recovery; | |
4741 | pr_info("%s chg_high_temp_recovery = %d ",__func__, ret); | |
4742 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4743 | ret); | |
4744 | break; | |
4745 | case BATT_TUNE_CHG_LIMMIT_CUR: | |
4746 | ret = battery->pdata->chg_charging_limit_current; | |
4747 | pr_info("%s chg_charging_limit_current = %d ",__func__, ret); | |
4748 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4749 | ret); | |
4750 | break; | |
4751 | case BATT_TUNE_COIL_TEMP_HIGH: | |
4752 | break; | |
4753 | case BATT_TUNE_COIL_TEMP_REC: | |
4754 | break; | |
4755 | case BATT_TUNE_COIL_LIMMIT_CUR: | |
4756 | break; | |
4757 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
4758 | case BATT_UPDATE_DATA: | |
4759 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", | |
4760 | battery->data_path ? "OK" : "NOK"); | |
4761 | break; | |
4762 | #endif | |
4763 | case BATT_MISC_EVENT: | |
4764 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4765 | battery->misc_event); | |
4766 | break; | |
4767 | case BATT_EXT_DEV_CHG: | |
4768 | break; | |
4769 | case BATT_WDT_CONTROL: | |
4770 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4771 | battery->wdt_kick_disable); | |
4772 | break; | |
4773 | case MODE: | |
4774 | value.strval = NULL; | |
4775 | psy_do_property(battery->pdata->charger_name, get, | |
4776 | POWER_SUPPLY_EXT_PROP_MULTI_CHARGER_MODE, value); | |
4777 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", | |
4778 | (value.strval) ? value.strval : "master"); | |
4779 | break; | |
4780 | case CHECK_PS_READY: | |
4781 | #if defined(CONFIG_CCIC_NOTIFIER) | |
4782 | value.intval = battery->pdic_ps_rdy; | |
4783 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4784 | value.intval); | |
4785 | pr_info("%s : CHECK_PS_READY=%d\n",__func__,value.intval); | |
4786 | #endif | |
4787 | break; | |
4788 | case BATT_CHIP_ID: | |
4789 | psy_do_property(battery->pdata->charger_name, get, | |
4790 | POWER_SUPPLY_EXT_PROP_CHIP_ID, value); | |
4791 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4792 | value.intval); | |
4793 | break; | |
4794 | case CISD_FULLCAPREP_MAX: | |
4795 | { | |
4796 | union power_supply_propval fullcaprep_val; | |
4797 | ||
4798 | fullcaprep_val.intval = SEC_BATTERY_CAPACITY_FULL; | |
4799 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4800 | POWER_SUPPLY_PROP_ENERGY_NOW, fullcaprep_val); | |
4801 | ||
4802 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4803 | fullcaprep_val.intval); | |
4804 | } | |
4805 | break; | |
4806 | #if defined(CONFIG_BATTERY_CISD) | |
4807 | case CISD_DATA: | |
4808 | { | |
4809 | struct cisd *pcisd = &battery->cisd; | |
4810 | char temp_buf[1024] = {0,}; | |
4811 | int j = 0; | |
4812 | ||
4813 | sprintf(temp_buf+strlen(temp_buf), "%d", pcisd->data[CISD_DATA_RESET_ALG]); | |
4814 | for (j = CISD_DATA_RESET_ALG + 1; j < CISD_DATA_MAX_PER_DAY; j++) | |
4815 | sprintf(temp_buf+strlen(temp_buf), " %d", pcisd->data[j]); | |
4816 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", temp_buf); | |
4817 | } | |
4818 | break; | |
4819 | case CISD_DATA_JSON: | |
4820 | { | |
4821 | struct cisd *pcisd = &battery->cisd; | |
4822 | char temp_buf[1920] = {0,}; | |
4823 | int j = 0; | |
4824 | ||
4825 | sprintf(temp_buf+strlen(temp_buf), "\"%s\":\"%d\"", | |
4826 | cisd_data_str[CISD_DATA_RESET_ALG], pcisd->data[CISD_DATA_RESET_ALG]); | |
4827 | for (j = CISD_DATA_RESET_ALG + 1; j < CISD_DATA_MAX; j++) | |
4828 | sprintf(temp_buf+strlen(temp_buf), ",\"%s\":\"%d\"", cisd_data_str[j], pcisd->data[j]); | |
4829 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", temp_buf); | |
4830 | } | |
4831 | break; | |
4832 | case CISD_DATA_D_JSON: | |
4833 | { | |
4834 | struct cisd *pcisd = &battery->cisd; | |
4835 | char temp_buf[1920] = {0,}; | |
4836 | int j = 0; | |
4837 | ||
4838 | sprintf(temp_buf+strlen(temp_buf), "\"%s\":\"%d\"", | |
4839 | cisd_data_str_d[CISD_DATA_FULL_COUNT_PER_DAY-CISD_DATA_MAX], | |
4840 | pcisd->data[CISD_DATA_FULL_COUNT_PER_DAY]); | |
4841 | for (j = CISD_DATA_FULL_COUNT_PER_DAY + 1; j < CISD_DATA_MAX_PER_DAY; j++) | |
4842 | sprintf(temp_buf+strlen(temp_buf), ",\"%s\":\"%d\"", | |
4843 | cisd_data_str_d[j-CISD_DATA_MAX], pcisd->data[j]); | |
4844 | ||
4845 | /* Clear Daily Data */ | |
4846 | for (j = CISD_DATA_FULL_COUNT_PER_DAY; j < CISD_DATA_MAX_PER_DAY; j++) | |
4847 | pcisd->data[j] = 0; | |
4848 | ||
4849 | pcisd->data[CISD_DATA_FULL_COUNT_PER_DAY] = 1; | |
4850 | pcisd->data[CISD_DATA_BATT_TEMP_MAX_PER_DAY] = -300; | |
4851 | pcisd->data[CISD_DATA_CHG_TEMP_MAX_PER_DAY] = -300; | |
4852 | pcisd->data[CISD_DATA_WPC_TEMP_MAX_PER_DAY] = -300; | |
4853 | pcisd->data[CISD_DATA_USB_TEMP_MAX_PER_DAY] = -300; | |
4854 | pcisd->data[CISD_DATA_BATT_TEMP_MIN_PER_DAY] = 1000; | |
4855 | pcisd->data[CISD_DATA_CHG_TEMP_MIN_PER_DAY] = 1000; | |
4856 | pcisd->data[CISD_DATA_WPC_TEMP_MIN_PER_DAY] = 1000; | |
4857 | pcisd->data[CISD_DATA_USB_TEMP_MIN_PER_DAY] = 1000; | |
4858 | ||
4859 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MAX_PER_DAY] = -300; | |
4860 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MAX_PER_DAY] = -300; | |
4861 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MAX_PER_DAY] = -300; | |
4862 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MAX_PER_DAY] = -300; | |
4863 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MIN_PER_DAY] = 1000; | |
4864 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MIN_PER_DAY] = 1000; | |
4865 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MIN_PER_DAY] = 1000; | |
4866 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MIN_PER_DAY] = 1000; | |
4867 | ||
4868 | pcisd->data[CISD_DATA_CAP_MIN_PER_DAY] = 0xFFFF; | |
4869 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", temp_buf); | |
4870 | } | |
4871 | break; | |
4872 | case CISD_WIRE_COUNT: | |
4873 | { | |
4874 | struct cisd *pcisd = &battery->cisd; | |
4875 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4876 | pcisd->data[CISD_DATA_WIRE_COUNT]); | |
4877 | } | |
4878 | break; | |
4879 | case CISD_WC_DATA: | |
4880 | { | |
4881 | struct cisd *pcisd = &battery->cisd; | |
4882 | struct pad_data *pad_data = pcisd->pad_array; | |
4883 | char temp_buf[1024] = {0,}; | |
4884 | int j = 0; | |
4885 | ||
4886 | sprintf(temp_buf+strlen(temp_buf), "%d %d", | |
4887 | PAD_INDEX_VALUE, pcisd->pad_count); | |
4888 | while ((pad_data != NULL) && ((pad_data = pad_data->next) != NULL) && | |
4889 | (pad_data->id < MAX_PAD_ID) && (j++ < pcisd->pad_count)) | |
4890 | sprintf(temp_buf+strlen(temp_buf), " 0x%02x:%d", pad_data->id, pad_data->count); | |
4891 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", temp_buf); | |
4892 | } | |
4893 | break; | |
4894 | case CISD_WC_DATA_JSON: | |
4895 | { | |
4896 | struct cisd *pcisd = &battery->cisd; | |
4897 | struct pad_data *pad_data = pcisd->pad_array; | |
4898 | char temp_buf[1024] = {0,}; | |
4899 | int j = 0; | |
4900 | ||
4901 | sprintf(temp_buf+strlen(temp_buf), "\"%s\":\"%d\"", | |
4902 | PAD_INDEX_STRING, PAD_INDEX_VALUE); | |
4903 | while ((pad_data != NULL) && ((pad_data = pad_data->next) != NULL) && | |
4904 | (pad_data->id < MAX_PAD_ID) && (j++ < pcisd->pad_count)) | |
4905 | sprintf(temp_buf+strlen(temp_buf), ",\"%s%02x\":\"%d\"", | |
4906 | PAD_JSON_STRING, pad_data->id, pad_data->count); | |
4907 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", temp_buf); | |
4908 | } | |
4909 | break; | |
4910 | case PREV_BATTERY_DATA: | |
4911 | { | |
4912 | if (battery->enable_update_data) | |
4913 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d, %d, %d, %d\n", | |
4914 | battery->voltage_now, battery->temperature, | |
4915 | battery->is_jig_on, !battery->charging_block); | |
4916 | } | |
4917 | break; | |
4918 | case PREV_BATTERY_INFO: | |
4919 | { | |
4920 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d,%d,%d,%d\n", | |
4921 | battery->prev_volt, battery->prev_temp, | |
4922 | battery->prev_jig_on, battery->prev_chg_on); | |
4923 | pr_info("%s: Read Prev Battery Info : %d, %d, %d, %d\n", __func__, | |
4924 | battery->prev_volt, battery->prev_temp, | |
4925 | battery->prev_jig_on, battery->prev_chg_on); | |
4926 | } | |
4927 | break; | |
4928 | #endif | |
4929 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
4930 | case SBM_DATA: | |
4931 | if (battery->sbm_data) { | |
4932 | sec_bat_get_sbm_data_string(&value); | |
4933 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", value.strval); | |
4934 | battery->sbm_data = false; | |
4935 | } else { | |
4936 | i = -EINVAL; | |
4937 | } | |
4938 | break; | |
4939 | #endif | |
4940 | case SAFETY_TIMER_SET: | |
4941 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4942 | battery->safety_timer_set); | |
4943 | break; | |
4944 | case BATT_SWELLING_CONTROL: | |
4945 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4946 | battery->skip_swelling); | |
4947 | break; | |
4948 | case SAFETY_TIMER_INFO: | |
4949 | i += scnprintf(buf + i, PAGE_SIZE - i, "%ld\n", | |
4950 | battery->cal_safety_time); | |
4951 | break; | |
4952 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
4953 | case BATT_TEMP_TEST: | |
4954 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d %d %d %d\n", | |
4955 | battery->temperature_test_battery, | |
4956 | battery->temperature_test_usb, | |
4957 | battery->temperature_test_wpc, | |
4958 | battery->temperature_test_chg); | |
4959 | break; | |
4960 | #endif | |
4961 | case BATT_CURRENT_EVENT: | |
4962 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4963 | battery->current_event); | |
4964 | break; | |
4965 | case CC_INFO: | |
4966 | { | |
4967 | union power_supply_propval cc_val; | |
4968 | ||
4969 | cc_val.intval = SEC_BATTERY_CAPACITY_QH; | |
4970 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4971 | POWER_SUPPLY_PROP_ENERGY_NOW, cc_val); | |
4972 | ||
4973 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
4974 | cc_val.intval); | |
4975 | } | |
4976 | break; | |
4977 | case EXT_EVENT: | |
4978 | break; | |
4979 | default: | |
4980 | i = -EINVAL; | |
4981 | break; | |
4982 | } | |
4983 | ||
4984 | return i; | |
4985 | } | |
4986 | ||
4987 | void update_external_temp_table(struct sec_battery_info *battery, int temp[]) | |
4988 | { | |
4989 | battery->pdata->temp_high_threshold_normal = temp[0]; | |
4990 | battery->pdata->temp_high_recovery_normal = temp[1]; | |
4991 | battery->pdata->temp_low_threshold_normal = temp[2]; | |
4992 | battery->pdata->temp_low_recovery_normal = temp[3]; | |
4993 | battery->pdata->temp_high_threshold_lpm = temp[4]; | |
4994 | battery->pdata->temp_high_recovery_lpm = temp[5]; | |
4995 | battery->pdata->temp_low_threshold_lpm = temp[6]; | |
4996 | battery->pdata->temp_low_recovery_lpm = temp[7]; | |
4997 | ||
4998 | } | |
4999 | ||
5000 | ssize_t sec_bat_store_attrs( | |
5001 | struct device *dev, | |
5002 | struct device_attribute *attr, | |
5003 | const char *buf, size_t count) | |
5004 | { | |
5005 | struct power_supply *psy = dev_get_drvdata(dev); | |
5006 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
5007 | const ptrdiff_t offset = attr - sec_battery_attrs; | |
5008 | int ret = -EINVAL; | |
5009 | int x = 0; | |
5010 | int t[12]; | |
5011 | int i = 0; | |
5012 | union power_supply_propval value = {0, }; | |
5013 | ||
5014 | switch (offset) { | |
5015 | case BATT_RESET_SOC: | |
5016 | /* Do NOT reset fuel gauge in charging mode */ | |
5017 | if ((battery->cable_type == SEC_BATTERY_CABLE_NONE) || | |
5018 | battery->is_jig_on) { | |
5019 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_BATT_RESET_SOC, 0); | |
5020 | ||
5021 | value.intval = | |
5022 | SEC_FUELGAUGE_CAPACITY_TYPE_RESET; | |
5023 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
5024 | POWER_SUPPLY_PROP_CAPACITY, value); | |
5025 | dev_info(battery->dev,"do reset SOC\n"); | |
5026 | /* update battery info */ | |
5027 | sec_bat_get_battery_info(battery); | |
5028 | } | |
5029 | ret = count; | |
5030 | break; | |
5031 | case BATT_READ_RAW_SOC: | |
5032 | break; | |
5033 | case BATT_READ_ADJ_SOC: | |
5034 | break; | |
5035 | case BATT_TYPE: | |
5036 | strncpy(battery->batt_type, buf, sizeof(battery->batt_type) - 1); | |
5037 | battery->batt_type[sizeof(battery->batt_type)-1] = '\0'; | |
5038 | ret = count; | |
5039 | break; | |
5040 | case BATT_VFOCV: | |
5041 | break; | |
5042 | case BATT_VOL_ADC: | |
5043 | break; | |
5044 | case BATT_VOL_ADC_CAL: | |
5045 | break; | |
5046 | case BATT_VOL_AVER: | |
5047 | break; | |
5048 | case BATT_VOL_ADC_AVER: | |
5049 | break; | |
5050 | case BATT_CURRENT_UA_NOW: | |
5051 | break; | |
5052 | case BATT_CURRENT_UA_AVG: | |
5053 | break; | |
5054 | case BATT_FILTER_CFG: | |
5055 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5056 | value.intval = x; | |
5057 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
5058 | POWER_SUPPLY_PROP_FILTER_CFG, value); | |
5059 | ret = count; | |
5060 | } | |
5061 | break; | |
5062 | case BATT_TEMP: | |
5063 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) || defined(CONFIG_SEC_FACTORY) | |
5064 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5065 | dev_info(battery->dev, | |
5066 | "%s: cooldown mode %s \n", __func__, (x ? "enable" : "disable")); | |
5067 | if (x == 0) | |
5068 | battery->cooldown_mode = false; | |
5069 | else | |
5070 | battery->cooldown_mode = true; | |
5071 | ret = count; | |
5072 | } | |
5073 | #endif | |
5074 | break; | |
5075 | case BATT_TEMP_ADC: | |
5076 | break; | |
5077 | case BATT_TEMP_AVER: | |
5078 | break; | |
5079 | case BATT_TEMP_ADC_AVER: | |
5080 | break; | |
5081 | case USB_TEMP: | |
5082 | break; | |
5083 | case USB_TEMP_ADC: | |
5084 | break; | |
5085 | case CHG_TEMP: | |
5086 | break; | |
5087 | case CHG_TEMP_ADC: | |
5088 | break; | |
5089 | case SLAVE_CHG_TEMP: | |
5090 | break; | |
5091 | case SLAVE_CHG_TEMP_ADC: | |
5092 | break; | |
5093 | case BATT_VF_ADC: | |
5094 | break; | |
5095 | case BATT_SLATE_MODE: | |
5096 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5097 | if (x == battery->slate_mode) { | |
5098 | dev_info(battery->dev, | |
5099 | "%s : skip same slate mode : %d\n", __func__, x); | |
5100 | return count; | |
5101 | } else if (x == 1) { | |
5102 | battery->slate_mode = true; | |
5103 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_SLATE, SEC_BAT_CURRENT_EVENT_SLATE); | |
5104 | dev_info(battery->dev, | |
5105 | "%s: enable slate mode : %d\n", __func__, x); | |
5106 | } else if (x == 0) { | |
5107 | battery->slate_mode = false; | |
5108 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_SLATE); | |
5109 | dev_info(battery->dev, | |
5110 | "%s: disable slate mode : %d\n", __func__, x); | |
5111 | } else { | |
5112 | dev_info(battery->dev, | |
5113 | "%s: SLATE MODE unknown command\n", __func__); | |
5114 | return -EINVAL; | |
5115 | } | |
5116 | wake_lock(&battery->cable_wake_lock); | |
5117 | queue_delayed_work(battery->monitor_wqueue, | |
5118 | &battery->cable_work, 0); | |
5119 | ret = count; | |
5120 | } | |
5121 | break; | |
5122 | case BATT_LP_CHARGING: | |
5123 | break; | |
5124 | case SIOP_ACTIVATED: | |
5125 | break; | |
5126 | case SIOP_LEVEL: | |
5127 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5128 | dev_info(battery->dev, | |
5129 | "%s: siop level: %d\n", __func__, x); | |
5130 | ||
5131 | battery->wc_heating_start_time = 0; | |
5132 | if (x == battery->siop_level) { | |
5133 | dev_info(battery->dev, | |
5134 | "%s: skip same siop level: %d\n", __func__, x); | |
5135 | return count; | |
5136 | } else if (x >= 0 && x <= 100) { | |
5137 | battery->siop_level = x; | |
5138 | } else { | |
5139 | battery->siop_level = 100; | |
5140 | } | |
5141 | ||
5142 | wake_lock(&battery->siop_level_wake_lock); | |
5143 | queue_delayed_work(battery->monitor_wqueue, &battery->siop_level_work, 0); | |
5144 | ||
5145 | ret = count; | |
5146 | } | |
5147 | break; | |
5148 | case SIOP_EVENT: | |
5149 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5150 | ret = count; | |
5151 | } | |
5152 | break; | |
5153 | case BATT_CHARGING_SOURCE: | |
5154 | break; | |
5155 | case FG_REG_DUMP: | |
5156 | break; | |
5157 | case FG_RESET_CAP: | |
5158 | break; | |
5159 | case FG_CAPACITY: | |
5160 | break; | |
5161 | case FG_ASOC: | |
5162 | break; | |
5163 | case AUTH: | |
5164 | break; | |
5165 | case CHG_CURRENT_ADC: | |
5166 | break; | |
5167 | case WC_ADC: | |
5168 | break; | |
5169 | case WC_STATUS: | |
5170 | break; | |
5171 | case WC_ENABLE: | |
5172 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5173 | if (x == 0) { | |
5174 | mutex_lock(&battery->wclock); | |
5175 | battery->wc_enable = false; | |
5176 | battery->wc_enable_cnt = 0; | |
5177 | mutex_unlock(&battery->wclock); | |
5178 | } else if (x == 1) { | |
5179 | mutex_lock(&battery->wclock); | |
5180 | battery->wc_enable = true; | |
5181 | battery->wc_enable_cnt = 0; | |
5182 | mutex_unlock(&battery->wclock); | |
5183 | } else { | |
5184 | dev_info(battery->dev, | |
5185 | "%s: WPC ENABLE unknown command\n", | |
5186 | __func__); | |
5187 | return -EINVAL; | |
5188 | } | |
5189 | wake_lock(&battery->cable_wake_lock); | |
5190 | queue_delayed_work(battery->monitor_wqueue, | |
5191 | &battery->cable_work, 0); | |
5192 | ret = count; | |
5193 | } | |
5194 | break; | |
5195 | case WC_CONTROL: | |
5196 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5197 | if (battery->pdata->wpc_en) { | |
5198 | if (x == 0) { | |
5199 | mutex_lock(&battery->wclock); | |
5200 | battery->wc_enable = false; | |
5201 | battery->wc_enable_cnt = 0; | |
5202 | value.intval = 0; | |
5203 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5204 | POWER_SUPPLY_EXT_PROP_WC_CONTROL, value); | |
5205 | gpio_direction_output(battery->pdata->wpc_en, 1); | |
5206 | pr_info("%s: WC CONTROL: Disable", __func__); | |
5207 | mutex_unlock(&battery->wclock); | |
5208 | } else if (x == 1) { | |
5209 | mutex_lock(&battery->wclock); | |
5210 | battery->wc_enable = true; | |
5211 | battery->wc_enable_cnt = 0; | |
5212 | value.intval = 1; | |
5213 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5214 | POWER_SUPPLY_EXT_PROP_WC_CONTROL, value); | |
5215 | gpio_direction_output(battery->pdata->wpc_en, 0); | |
5216 | pr_info("%s: WC CONTROL: Enable", __func__); | |
5217 | mutex_unlock(&battery->wclock); | |
5218 | } else { | |
5219 | dev_info(battery->dev, | |
5220 | "%s: WC CONTROL unknown command\n", | |
5221 | __func__); | |
5222 | return -EINVAL; | |
5223 | } | |
5224 | } | |
5225 | ret = count; | |
5226 | } | |
5227 | break; | |
5228 | case WC_CONTROL_CNT: | |
5229 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5230 | battery->wc_enable_cnt_value = x; | |
5231 | ret = count; | |
5232 | } | |
5233 | break; | |
5234 | case LED_COVER: | |
5235 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5236 | pr_info("%s: MFC, LED_COVER(%d)\n", __func__, x); | |
5237 | battery->led_cover = x; | |
5238 | value.intval = battery->led_cover; | |
5239 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5240 | POWER_SUPPLY_PROP_FILTER_CFG, value); | |
5241 | ret = count; | |
5242 | } | |
5243 | break; | |
5244 | case HV_CHARGER_STATUS: | |
5245 | break; | |
5246 | case HV_WC_CHARGER_STATUS: | |
5247 | break; | |
5248 | case HV_CHARGER_SET: | |
5249 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5250 | dev_info(battery->dev, | |
5251 | "%s: HV_CHARGER_SET(%d)\n", __func__, x); | |
5252 | if (x == 1) { | |
5253 | battery->wire_status = SEC_BATTERY_CABLE_9V_TA; | |
5254 | wake_lock(&battery->cable_wake_lock); | |
5255 | queue_delayed_work(battery->monitor_wqueue, &battery->cable_work, 0); | |
5256 | } else { | |
5257 | battery->wire_status = SEC_BATTERY_CABLE_NONE; | |
5258 | wake_lock(&battery->cable_wake_lock); | |
5259 | queue_delayed_work(battery->monitor_wqueue, &battery->cable_work, 0); | |
5260 | } | |
5261 | ret = count; | |
5262 | } | |
5263 | break; | |
5264 | case FACTORY_MODE: | |
5265 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5266 | battery->factory_mode = x ? true : false; | |
5267 | ret = count; | |
5268 | } | |
5269 | break; | |
5270 | case STORE_MODE: | |
5271 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5272 | #if !defined(CONFIG_SEC_FACTORY) | |
5273 | if (x) { | |
5274 | battery->store_mode = true; | |
5275 | wake_lock(&battery->parse_mode_dt_wake_lock); | |
5276 | queue_delayed_work(battery->monitor_wqueue, | |
5277 | &battery->parse_mode_dt_work, 0); | |
5278 | } | |
5279 | #endif | |
5280 | ret = count; | |
5281 | } | |
5282 | break; | |
5283 | case UPDATE: | |
5284 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5285 | /* update battery info */ | |
5286 | sec_bat_get_battery_info(battery); | |
5287 | ret = count; | |
5288 | } | |
5289 | break; | |
5290 | case TEST_MODE: | |
5291 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5292 | battery->test_mode = x; | |
5293 | wake_lock(&battery->monitor_wake_lock); | |
5294 | queue_delayed_work(battery->monitor_wqueue, | |
5295 | &battery->monitor_work, 0); | |
5296 | ret = count; | |
5297 | } | |
5298 | break; | |
5299 | ||
5300 | case BATT_EVENT_CALL: | |
5301 | case BATT_EVENT_2G_CALL: | |
5302 | case BATT_EVENT_TALK_GSM: | |
5303 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5304 | ret = count; | |
5305 | } | |
5306 | break; | |
5307 | case BATT_EVENT_3G_CALL: | |
5308 | case BATT_EVENT_TALK_WCDMA: | |
5309 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5310 | ret = count; | |
5311 | } | |
5312 | break; | |
5313 | case BATT_EVENT_MUSIC: | |
5314 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5315 | ret = count; | |
5316 | } | |
5317 | break; | |
5318 | case BATT_EVENT_VIDEO: | |
5319 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5320 | ret = count; | |
5321 | } | |
5322 | break; | |
5323 | case BATT_EVENT_BROWSER: | |
5324 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5325 | ret = count; | |
5326 | } | |
5327 | break; | |
5328 | case BATT_EVENT_HOTSPOT: | |
5329 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5330 | ret = count; | |
5331 | } | |
5332 | break; | |
5333 | case BATT_EVENT_CAMERA: | |
5334 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5335 | ret = count; | |
5336 | } | |
5337 | break; | |
5338 | case BATT_EVENT_CAMCORDER: | |
5339 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5340 | ret = count; | |
5341 | } | |
5342 | break; | |
5343 | case BATT_EVENT_DATA_CALL: | |
5344 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5345 | ret = count; | |
5346 | } | |
5347 | break; | |
5348 | case BATT_EVENT_WIFI: | |
5349 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5350 | ret = count; | |
5351 | } | |
5352 | break; | |
5353 | case BATT_EVENT_WIBRO: | |
5354 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5355 | ret = count; | |
5356 | } | |
5357 | break; | |
5358 | case BATT_EVENT_LTE: | |
5359 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5360 | ret = count; | |
5361 | } | |
5362 | break; | |
5363 | case BATT_EVENT_LCD: | |
5364 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5365 | struct timespec ts; | |
5366 | get_monotonic_boottime(&ts); | |
5367 | if (x) { | |
5368 | battery->lcd_status = true; | |
5369 | } else { | |
5370 | battery->lcd_status = false; | |
5371 | } | |
5372 | ret = count; | |
5373 | } | |
5374 | break; | |
5375 | case BATT_EVENT_GPS: | |
5376 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5377 | ret = count; | |
5378 | } | |
5379 | break; | |
5380 | case BATT_TEMP_TABLE: | |
5381 | if (sscanf(buf, "%10d %10d %10d %10d %10d %10d %10d %10d\n", | |
5382 | &t[0], &t[1], &t[2], &t[3], &t[4], &t[5], &t[6], &t[7]) == 8) { | |
5383 | pr_info("%s: (new) %d %d %d %d %d %d %d %d\n", | |
5384 | __func__, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]); | |
5385 | pr_info("%s: (default) %d %d %d %d %d %d %d %d\n", | |
5386 | __func__, | |
5387 | battery->pdata->temp_high_threshold_normal, | |
5388 | battery->pdata->temp_high_recovery_normal, | |
5389 | battery->pdata->temp_low_threshold_normal, | |
5390 | battery->pdata->temp_low_recovery_normal, | |
5391 | battery->pdata->temp_high_threshold_lpm, | |
5392 | battery->pdata->temp_high_recovery_lpm, | |
5393 | battery->pdata->temp_low_threshold_lpm, | |
5394 | battery->pdata->temp_low_recovery_lpm); | |
5395 | update_external_temp_table(battery, t); | |
5396 | ret = count; | |
5397 | } | |
5398 | break; | |
5399 | case BATT_HIGH_CURRENT_USB: | |
5400 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5401 | battery->is_hc_usb = x ? true : false; | |
5402 | value.intval = battery->is_hc_usb; | |
5403 | ||
5404 | psy_do_property(battery->pdata->charger_name, set, | |
5405 | POWER_SUPPLY_PROP_USB_HC, value); | |
5406 | ||
5407 | pr_info("%s: is_hc_usb (%d)\n", __func__, battery->is_hc_usb); | |
5408 | ret = count; | |
5409 | } | |
5410 | break; | |
5411 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
5412 | case TEST_CHARGE_CURRENT: | |
5413 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5414 | if (x >= 0 && x <= 2000) { | |
5415 | dev_err(battery->dev, | |
5416 | "%s: BATT_TEST_CHARGE_CURRENT(%d)\n", __func__, x); | |
5417 | battery->pdata->charging_current[ | |
5418 | SEC_BATTERY_CABLE_USB].input_current_limit = x; | |
5419 | battery->pdata->charging_current[ | |
5420 | SEC_BATTERY_CABLE_USB].fast_charging_current = x; | |
5421 | if (x > 500) { | |
5422 | battery->eng_not_full_status = true; | |
5423 | battery->pdata->temp_check_type = | |
5424 | SEC_BATTERY_TEMP_CHECK_NONE; | |
5425 | } | |
5426 | if (battery->cable_type == SEC_BATTERY_CABLE_USB) { | |
5427 | value.intval = x; | |
5428 | psy_do_property(battery->pdata->charger_name, set, | |
5429 | POWER_SUPPLY_PROP_CURRENT_NOW, | |
5430 | value); | |
5431 | } | |
5432 | } | |
5433 | ret = count; | |
5434 | } | |
5435 | break; | |
5436 | #endif | |
5437 | case SET_STABILITY_TEST: | |
5438 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5439 | dev_err(battery->dev, | |
5440 | "%s: BATT_STABILITY_TEST(%d)\n", __func__, x); | |
5441 | if (x) { | |
5442 | battery->stability_test = true; | |
5443 | battery->eng_not_full_status = true; | |
5444 | } | |
5445 | else { | |
5446 | battery->stability_test = false; | |
5447 | battery->eng_not_full_status = false; | |
5448 | } | |
5449 | ret = count; | |
5450 | } | |
5451 | break; | |
5452 | case BATT_CAPACITY_MAX: | |
5453 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5454 | dev_err(battery->dev, | |
5455 | "%s: BATT_CAPACITY_MAX(%d), fg_reset(%d)\n", __func__, x, fg_reset); | |
5456 | if (!fg_reset && !battery->store_mode) { | |
5457 | value.intval = x; | |
5458 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
5459 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, value); | |
5460 | ||
5461 | /* update soc */ | |
5462 | value.intval = 0; | |
5463 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
5464 | POWER_SUPPLY_PROP_CAPACITY, value); | |
5465 | battery->capacity = value.intval; | |
5466 | } else { | |
5467 | #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP) | |
5468 | battery->fg_reset = 1; | |
5469 | #endif | |
5470 | } | |
5471 | ret = count; | |
5472 | } | |
5473 | break; | |
5474 | case BATT_INBAT_VOLTAGE: | |
5475 | break; | |
5476 | case BATT_INBAT_VOLTAGE_OCV: | |
5477 | break; | |
5478 | case CHECK_SLAVE_CHG: | |
5479 | break; | |
5480 | case BATT_INBAT_WIRELESS_CS100: | |
5481 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5482 | pr_info("%s send cs100 command \n",__func__); | |
5483 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
5484 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5485 | POWER_SUPPLY_PROP_STATUS, value); | |
5486 | ret = count; | |
5487 | } | |
5488 | break; | |
5489 | case HMT_TA_CONNECTED: | |
5490 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5491 | #if !defined(CONFIG_CCIC_NOTIFIER) | |
5492 | dev_info(battery->dev, | |
5493 | "%s: HMT_TA_CONNECTED(%d)\n", __func__, x); | |
5494 | if (x) { | |
5495 | value.intval = false; | |
5496 | psy_do_property(battery->pdata->charger_name, set, | |
5497 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
5498 | value); | |
5499 | dev_info(battery->dev, | |
5500 | "%s: changed to OTG cable detached\n", __func__); | |
5501 | ||
5502 | battery->wire_status = SEC_BATTERY_CABLE_HMT_CONNECTED; | |
5503 | wake_lock(&battery->cable_wake_lock); | |
5504 | queue_delayed_work(battery->monitor_wqueue, &battery->cable_work, 0); | |
5505 | } else { | |
5506 | value.intval = true; | |
5507 | psy_do_property(battery->pdata->charger_name, set, | |
5508 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
5509 | value); | |
5510 | dev_info(battery->dev, | |
5511 | "%s: changed to OTG cable attached\n", __func__); | |
5512 | ||
5513 | battery->wire_status = SEC_BATTERY_CABLE_OTG; | |
5514 | wake_lock(&battery->cable_wake_lock); | |
5515 | queue_delayed_work(battery->monitor_wqueue, &battery->cable_work, 0); | |
5516 | } | |
5517 | #endif | |
5518 | ret = count; | |
5519 | } | |
5520 | break; | |
5521 | case HMT_TA_CHARGE: | |
5522 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5523 | #if defined(CONFIG_CCIC_NOTIFIER) | |
5524 | dev_info(battery->dev, | |
5525 | "%s: HMT_TA_CHARGE(%d)\n", __func__, x); | |
5526 | ||
5527 | /* do not charge off without cable type, since wdt could be expired */ | |
5528 | if (x && (battery->cable_type != SEC_BATTERY_CABLE_NONE) | |
5529 | && (battery->cable_type != SEC_BATTERY_CABLE_OTG)) { | |
5530 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_CHARGE_DISABLE); | |
5531 | /* No charging when FULL & NONE */ | |
5532 | if (!((battery->status == POWER_SUPPLY_STATUS_FULL) && | |
5533 | (battery->charging_mode == SEC_BATTERY_CHARGING_NONE))) { | |
5534 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING); | |
5535 | } | |
5536 | } else if (!x) { | |
5537 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_CHARGE_DISABLE, | |
5538 | SEC_BAT_CURRENT_EVENT_CHARGE_DISABLE); | |
5539 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
5540 | } else | |
5541 | dev_info(battery->dev, "%s: Wrong HMT control\n", __func__); | |
5542 | ||
5543 | ret = count; | |
5544 | #else | |
5545 | dev_info(battery->dev, | |
5546 | "%s: HMT_TA_CHARGE(%d)\n", __func__, x); | |
5547 | psy_do_property(battery->pdata->charger_name, get, | |
5548 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
5549 | if (value.intval) { | |
5550 | dev_info(battery->dev, | |
5551 | "%s: ignore HMT_TA_CHARGE(%d)\n", __func__, x); | |
5552 | } else { | |
5553 | if (x) { | |
5554 | value.intval = false; | |
5555 | psy_do_property(battery->pdata->charger_name, set, | |
5556 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
5557 | value); | |
5558 | dev_info(battery->dev, | |
5559 | "%s: changed to OTG cable detached\n", __func__); | |
5560 | battery->wire_status = SEC_BATTERY_CABLE_HMT_CHARGE; | |
5561 | wake_lock(&battery->cable_wake_lock); | |
5562 | queue_delayed_work(battery->monitor_wqueue, &battery->cable_work, 0); | |
5563 | } else { | |
5564 | value.intval = false; | |
5565 | psy_do_property(battery->pdata->charger_name, set, | |
5566 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
5567 | value); | |
5568 | dev_info(battery->dev, | |
5569 | "%s: changed to OTG cable detached\n", __func__); | |
5570 | battery->wire_status = SEC_BATTERY_CABLE_HMT_CONNECTED; | |
5571 | wake_lock(&battery->cable_wake_lock); | |
5572 | queue_delayed_work(battery->monitor_wqueue, &battery->cable_work, 0); | |
5573 | } | |
5574 | } | |
5575 | ret = count; | |
5576 | #endif | |
5577 | } | |
5578 | break; | |
5579 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
5580 | case FG_CYCLE: | |
5581 | break; | |
5582 | case FG_FULL_VOLTAGE: | |
5583 | break; | |
5584 | case FG_FULLCAPNOM: | |
5585 | break; | |
5586 | case BATTERY_CYCLE: | |
5587 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5588 | dev_info(battery->dev, "%s: BATTERY_CYCLE(%d)\n", __func__, x); | |
5589 | if (x >= 0) { | |
5590 | int prev_battery_cycle = battery->batt_cycle; | |
5591 | battery->batt_cycle = x; | |
5592 | #if defined(CONFIG_BATTERY_CISD) | |
5593 | battery->cisd.data[CISD_DATA_CYCLE] = x; | |
5594 | #endif | |
5595 | if (prev_battery_cycle < 0) { | |
5596 | sec_bat_aging_check(battery); | |
5597 | } | |
5598 | } | |
5599 | ret = count; | |
5600 | } | |
5601 | break; | |
5602 | #endif | |
5603 | case BATT_WPC_TEMP: | |
5604 | case BATT_WPC_TEMP_ADC: | |
5605 | case BATT_COIL_TEMP: | |
5606 | case BATT_COIL_TEMP_ADC: | |
5607 | break; | |
5608 | #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE) | |
5609 | case BATT_WIRELESS_FIRMWARE_UPDATE: | |
5610 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5611 | if (x == SEC_WIRELESS_RX_SDCARD_MODE) { | |
5612 | pr_info("%s fw mode is SDCARD \n", __func__); | |
5613 | sec_bat_fw_update_work(battery, SEC_WIRELESS_RX_SDCARD_MODE); | |
5614 | } else if (x == SEC_WIRELESS_RX_BUILT_IN_MODE) { | |
5615 | pr_info("%s fw mode is BUILD IN \n", __func__); | |
5616 | sec_bat_fw_update_work(battery, SEC_WIRELESS_RX_BUILT_IN_MODE); | |
5617 | } else if (x == SEC_WIRELESS_TX_ON_MODE) { | |
5618 | pr_info("%s tx mode is on \n", __func__); | |
5619 | sec_bat_fw_update_work(battery, SEC_WIRELESS_TX_ON_MODE); | |
5620 | } else if (x == SEC_WIRELESS_TX_OFF_MODE) { | |
5621 | pr_info("%s tx mode is off \n", __func__); | |
5622 | sec_bat_fw_update_work(battery, SEC_WIRELESS_TX_OFF_MODE); | |
5623 | } else { | |
5624 | dev_info(battery->dev, "%s: wireless firmware unknown command\n", __func__); | |
5625 | return -EINVAL; | |
5626 | } | |
5627 | ret = count; | |
5628 | } | |
5629 | break; | |
5630 | case OTP_FIRMWARE_RESULT: | |
5631 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5632 | if (x == 2) { | |
5633 | value.intval = x; | |
5634 | pr_info("%s RX firmware update ready!\n", __func__); | |
5635 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5636 | POWER_SUPPLY_PROP_MANUFACTURER, value); | |
5637 | } else { | |
5638 | dev_info(battery->dev, "%s: firmware unknown command\n", __func__); | |
5639 | return -EINVAL; | |
5640 | } | |
5641 | ret = count; | |
5642 | } | |
5643 | break; | |
5644 | case WC_IC_GRADE: | |
5645 | case OTP_FIRMWARE_VER_BIN: | |
5646 | case OTP_FIRMWARE_VER: | |
5647 | case TX_FIRMWARE_RESULT: | |
5648 | case TX_FIRMWARE_VER: | |
5649 | break; | |
5650 | case BATT_TX_STATUS: | |
5651 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5652 | if (x == SEC_TX_OFF) { | |
5653 | pr_info("%s TX mode is off \n", __func__); | |
5654 | sec_bat_fw_update_work(battery, SEC_WIRELESS_TX_OFF_MODE); | |
5655 | } else if (x == SEC_TX_STANDBY) { | |
5656 | pr_info("%s TX mode is on \n", __func__); | |
5657 | sec_bat_fw_update_work(battery, SEC_WIRELESS_TX_ON_MODE); | |
5658 | } else { | |
5659 | dev_info(battery->dev, "%s: TX firmware unknown command\n", __func__); | |
5660 | return -EINVAL; | |
5661 | } | |
5662 | ret = count; | |
5663 | } | |
5664 | break; | |
5665 | #endif | |
5666 | case WC_VOUT: | |
5667 | case WC_VRECT: | |
5668 | break; | |
5669 | case BATT_HV_WIRELESS_STATUS: | |
5670 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5671 | if (x == 1 && is_hv_wireless_type(battery->cable_type)) { | |
5672 | wake_lock(&battery->cable_wake_lock); | |
5673 | #ifdef CONFIG_SEC_FACTORY | |
5674 | pr_info("%s change cable type HV WIRELESS -> WIRELESS \n", __func__); | |
5675 | battery->wc_status = SEC_WIRELESS_PAD_WPC; | |
5676 | battery->cable_type = SEC_BATTERY_CABLE_WIRELESS; | |
5677 | sec_bat_set_charging_current(battery); | |
5678 | #endif | |
5679 | pr_info("%s HV_WIRELESS_STATUS set to 1. Vout set to 5V. \n", __func__); | |
5680 | value.intval = WIRELESS_VOUT_5V; | |
5681 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5682 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
5683 | wake_unlock(&battery->cable_wake_lock); | |
5684 | } else if (x == 3 && is_hv_wireless_type(battery->cable_type)) { | |
5685 | pr_info("%s HV_WIRELESS_STATUS set to 3. Vout set to 10V. \n", __func__); | |
5686 | value.intval = WIRELESS_VOUT_10V; | |
5687 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5688 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
5689 | } else { | |
5690 | dev_info(battery->dev, "%s: HV_WIRELESS_STATUS unknown command\n", __func__); | |
5691 | return -EINVAL; | |
5692 | } | |
5693 | ret = count; | |
5694 | } | |
5695 | break; | |
5696 | case BATT_HV_WIRELESS_PAD_CTRL: | |
5697 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5698 | ||
5699 | pr_err("%s: x : %d\n", __func__, x); | |
5700 | ||
5701 | if (x == 1) { | |
5702 | ret = sec_set_param(CM_OFFSET, '1'); | |
5703 | if (ret < 0) { | |
5704 | pr_err("%s:sec_set_param failed\n", __func__); | |
5705 | return ret; | |
5706 | } else { | |
5707 | pr_info("%s: hv wirelee charging is disabled\n", __func__); | |
5708 | sleep_mode = true; | |
5709 | } | |
5710 | } else if (x == 2) { | |
5711 | ret = sec_set_param(CM_OFFSET, '0'); | |
5712 | if (ret < 0) { | |
5713 | pr_err("%s: sec_set_param failed\n", __func__); | |
5714 | return ret; | |
5715 | } else { | |
5716 | pr_info("%s: hv wireless charging is enabled\n", __func__); | |
5717 | sleep_mode = false; | |
5718 | } | |
5719 | } else if (x == 3) { | |
5720 | pr_info("%s led off \n", __func__); | |
5721 | value.intval = WIRELESS_PAD_LED_OFF; | |
5722 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5723 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
5724 | } else if (x == 4) { | |
5725 | pr_info("%s led on \n", __func__); | |
5726 | value.intval = WIRELESS_PAD_LED_ON; | |
5727 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
5728 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
5729 | } else { | |
5730 | dev_info(battery->dev, "%s: BATT_HV_WIRELESS_PAD_CTRL unknown command\n", __func__); | |
5731 | return -EINVAL; | |
5732 | } | |
5733 | ret = count; | |
5734 | } | |
5735 | break; | |
5736 | case BATT_TUNE_FLOAT_VOLTAGE: | |
5737 | sscanf(buf, "%10d\n", &x); | |
5738 | pr_info("%s float voltage = %d mV",__func__, x); | |
5739 | ||
5740 | if(x > 4000 && x <= 4400 ){ | |
5741 | value.intval = x; | |
5742 | psy_do_property(battery->pdata->charger_name, set, | |
5743 | POWER_SUPPLY_PROP_VOLTAGE_MAX, value); | |
5744 | } | |
5745 | break; | |
5746 | case BATT_TUNE_INPUT_CHARGE_CURRENT: | |
5747 | sscanf(buf, "%10d\n", &x); | |
5748 | pr_info("%s input charge current = %d mA",__func__, x); | |
5749 | ||
5750 | if(x >= 0 && x <= 4000 ){ | |
5751 | for(i=0; i < SEC_BATTERY_CABLE_MAX; i++) | |
5752 | battery->pdata->charging_current[i].input_current_limit = x; | |
5753 | ||
5754 | value.intval = x; | |
5755 | psy_do_property(battery->pdata->charger_name, set, | |
5756 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
5757 | } | |
5758 | break; | |
5759 | case BATT_TUNE_FAST_CHARGE_CURRENT: | |
5760 | sscanf(buf, "%10d\n", &x); | |
5761 | pr_info("%s fast charge current = %d mA",__func__, x); | |
5762 | if(x >= 0 && x <= 4000 ){ | |
5763 | for(i=0; i < SEC_BATTERY_CABLE_MAX; i++) | |
5764 | battery->pdata->charging_current[i].fast_charging_current = x; | |
5765 | ||
5766 | value.intval = x; | |
5767 | psy_do_property(battery->pdata->charger_name, set, | |
5768 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
5769 | } | |
5770 | break; | |
5771 | case BATT_TUNE_UI_TERM_CURRENT_1ST: | |
5772 | sscanf(buf, "%10d\n", &x); | |
5773 | pr_info("%s ui term current = %d mA",__func__, x); | |
5774 | ||
5775 | if(x > 0 && x < 1000 ){ | |
5776 | battery->pdata->full_check_current_1st = x; | |
5777 | } | |
5778 | break; | |
5779 | case BATT_TUNE_UI_TERM_CURRENT_2ND: | |
5780 | sscanf(buf, "%10d\n", &x); | |
5781 | pr_info("%s ui term current = %d mA",__func__, x); | |
5782 | ||
5783 | if(x > 0 && x < 1000 ){ | |
5784 | battery->pdata->full_check_current_2nd = x; | |
5785 | } | |
5786 | break; | |
5787 | case BATT_TUNE_TEMP_HIGH_NORMAL: | |
5788 | sscanf(buf, "%10d\n", &x); | |
5789 | pr_info("%s temp high normal block = %d ",__func__, x); | |
5790 | if(x < 1000 && x >= -200) | |
5791 | battery->pdata->temp_high_threshold_normal = x; | |
5792 | break; | |
5793 | case BATT_TUNE_TEMP_HIGH_REC_NORMAL: | |
5794 | sscanf(buf, "%10d\n", &x); | |
5795 | pr_info("%s temp high normal recover = %d ",__func__, x); | |
5796 | if(x < 1000 && x >= -200) | |
5797 | battery->pdata->temp_high_recovery_normal = x; | |
5798 | break; | |
5799 | case BATT_TUNE_TEMP_LOW_NORMAL: | |
5800 | sscanf(buf, "%10d\n", &x); | |
5801 | pr_info("%s temp low normal block = %d ",__func__, x); | |
5802 | if(x < 1000 && x >= -200) | |
5803 | battery->pdata->temp_low_threshold_normal = x; | |
5804 | break; | |
5805 | case BATT_TUNE_TEMP_LOW_REC_NORMAL: | |
5806 | sscanf(buf, "%10d\n", &x); | |
5807 | pr_info("%s temp low normal recover = %d ",__func__, x); | |
5808 | if(x < 1000 && x >= -200) | |
5809 | battery->pdata->temp_low_recovery_normal = x; | |
5810 | break; | |
5811 | case BATT_TUNE_CHG_TEMP_HIGH: | |
5812 | sscanf(buf, "%10d\n", &x); | |
5813 | pr_info("%s chg_high_temp = %d ",__func__, x); | |
5814 | if(x < 1000 && x >= -200) | |
5815 | battery->pdata->chg_high_temp = x; | |
5816 | break; | |
5817 | case BATT_TUNE_CHG_TEMP_REC: | |
5818 | sscanf(buf, "%10d\n", &x); | |
5819 | pr_info("%s chg_high_temp_recovery = %d ",__func__, x); | |
5820 | if(x < 1000 && x >= -200) | |
5821 | battery->pdata->chg_high_temp_recovery = x; | |
5822 | break; | |
5823 | case BATT_TUNE_CHG_LIMMIT_CUR: | |
5824 | sscanf(buf, "%10d\n", &x); | |
5825 | pr_info("%s chg_charging_limit_current = %d ",__func__, x); | |
5826 | if(x < 3000 && x > 0) | |
5827 | { | |
5828 | battery->pdata->chg_charging_limit_current = x; | |
5829 | battery->pdata->charging_current[SEC_BATTERY_CABLE_9V_ERR].input_current_limit= x; | |
5830 | battery->pdata->charging_current[SEC_BATTERY_CABLE_9V_UNKNOWN].input_current_limit= x; | |
5831 | battery->pdata->charging_current[SEC_BATTERY_CABLE_9V_TA].input_current_limit= x; | |
5832 | } | |
5833 | break; | |
5834 | case BATT_TUNE_COIL_TEMP_HIGH: | |
5835 | break; | |
5836 | case BATT_TUNE_COIL_TEMP_REC: | |
5837 | break; | |
5838 | case BATT_TUNE_COIL_LIMMIT_CUR: | |
5839 | sscanf(buf, "%10d\n", &x); | |
5840 | pr_info("%s wpc_charging_limit_current = %d ",__func__, x); | |
5841 | if(x < 3000 && x > 0) | |
5842 | { | |
5843 | battery->pdata->charging_current[SEC_BATTERY_CABLE_9V_ERR].input_current_limit= x; | |
5844 | battery->pdata->charging_current[SEC_BATTERY_CABLE_9V_UNKNOWN].input_current_limit= x; | |
5845 | battery->pdata->charging_current[SEC_BATTERY_CABLE_9V_TA].input_current_limit= x; | |
5846 | } | |
5847 | break; | |
5848 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
5849 | case BATT_UPDATE_DATA: | |
5850 | if (!battery->data_path && (count * sizeof(char)) < 256) { | |
5851 | battery->data_path = kzalloc((count * sizeof(char) + 1), GFP_KERNEL); | |
5852 | if (battery->data_path) { | |
5853 | sscanf(buf, "%s\n", battery->data_path); | |
5854 | cancel_delayed_work(&battery->batt_data_work); | |
5855 | wake_lock(&battery->batt_data_wake_lock); | |
5856 | queue_delayed_work(battery->monitor_wqueue, | |
5857 | &battery->batt_data_work, msecs_to_jiffies(100)); | |
5858 | } else { | |
5859 | pr_info("%s: failed to alloc data_path buffer\n", __func__); | |
5860 | } | |
5861 | } | |
5862 | ret = count; | |
5863 | break; | |
5864 | #endif | |
5865 | case BATT_MISC_EVENT: | |
5866 | break; | |
5867 | case BATT_EXT_DEV_CHG: | |
5868 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5869 | pr_info("%s: Connect Ext Device : %d ",__func__, x); | |
5870 | ||
5871 | switch (x) { | |
5872 | case EXT_DEV_NONE: | |
5873 | battery->wire_status = SEC_BATTERY_CABLE_NONE; | |
5874 | value.intval = 0; | |
5875 | break; | |
5876 | case EXT_DEV_GAMEPAD_CHG: | |
5877 | battery->wire_status = SEC_BATTERY_CABLE_TA; | |
5878 | value.intval = 0; | |
5879 | break; | |
5880 | case EXT_DEV_GAMEPAD_OTG: | |
5881 | battery->wire_status = SEC_BATTERY_CABLE_OTG; | |
5882 | value.intval = 1; | |
5883 | break; | |
5884 | default: | |
5885 | break; | |
5886 | } | |
5887 | ||
5888 | psy_do_property(battery->pdata->charger_name, set, | |
5889 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
5890 | value); | |
5891 | ||
5892 | queue_delayed_work(battery->monitor_wqueue, | |
5893 | &battery->cable_work, 0); | |
5894 | ret = count; | |
5895 | } | |
5896 | break; | |
5897 | case BATT_WDT_CONTROL: | |
5898 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5899 | pr_info("%s: Charger WDT Set : %d\n", __func__, x); | |
5900 | battery->wdt_kick_disable = x; | |
5901 | } | |
5902 | ret = count; | |
5903 | break; | |
5904 | case MODE: | |
5905 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
5906 | value.intval = x; | |
5907 | psy_do_property(battery->pdata->charger_name, set, | |
5908 | POWER_SUPPLY_EXT_PROP_MULTI_CHARGER_MODE, value); | |
5909 | ret = count; | |
5910 | } | |
5911 | break; | |
5912 | case CHECK_PS_READY: | |
5913 | case BATT_CHIP_ID: | |
5914 | break; | |
5915 | case CISD_FULLCAPREP_MAX: | |
5916 | break; | |
5917 | #if defined(CONFIG_BATTERY_CISD) | |
5918 | case CISD_DATA: | |
5919 | { | |
5920 | struct cisd *pcisd = &battery->cisd; | |
5921 | int temp_data[CISD_DATA_MAX_PER_DAY] = {0,}; | |
5922 | ||
5923 | sscanf(buf, "%10d\n", &temp_data[0]); | |
5924 | ||
5925 | if (temp_data[CISD_DATA_RESET_ALG] > 0) { | |
5926 | if (sscanf(buf, "%10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d, %10d\n", | |
5927 | &temp_data[0], &temp_data[1], &temp_data[2], | |
5928 | &temp_data[3], &temp_data[4], &temp_data[5], | |
5929 | &temp_data[6], &temp_data[7], &temp_data[8], | |
5930 | &temp_data[9], &temp_data[10], &temp_data[11], | |
5931 | &temp_data[12], &temp_data[13], &temp_data[14], | |
5932 | &temp_data[15], &temp_data[16], &temp_data[17], | |
5933 | &temp_data[18], &temp_data[19], &temp_data[20], | |
5934 | &temp_data[21], &temp_data[22], &temp_data[23], | |
5935 | &temp_data[24], &temp_data[25], &temp_data[26], | |
5936 | &temp_data[27], &temp_data[28], &temp_data[29], | |
5937 | &temp_data[30], &temp_data[31], &temp_data[32], | |
5938 | &temp_data[33], &temp_data[34], &temp_data[35], | |
5939 | &temp_data[36], &temp_data[37], &temp_data[38], | |
5940 | &temp_data[39], &temp_data[40], &temp_data[41], | |
5941 | &temp_data[42], &temp_data[43], &temp_data[44], | |
5942 | &temp_data[45], &temp_data[46], &temp_data[47], | |
5943 | &temp_data[48], &temp_data[49], &temp_data[50], | |
5944 | &temp_data[51], &temp_data[52], &temp_data[53], | |
5945 | &temp_data[54], &temp_data[55], &temp_data[56], | |
5946 | &temp_data[57], &temp_data[58], &temp_data[59], | |
5947 | &temp_data[60], &temp_data[61], &temp_data[62], | |
5948 | &temp_data[63], &temp_data[64], &temp_data[65], | |
5949 | &temp_data[66], &temp_data[67], &temp_data[68], | |
5950 | &temp_data[69], &temp_data[70], &temp_data[71], | |
5951 | &temp_data[72], &temp_data[73], &temp_data[74], | |
5952 | &temp_data[75], &temp_data[76]) <= CISD_DATA_MAX_PER_DAY) { | |
5953 | for (i = 0; i < CISD_DATA_MAX_PER_DAY; i++) | |
5954 | pcisd->data[i] = 0; | |
5955 | pcisd->data[CISD_DATA_ALG_INDEX] = battery->pdata->cisd_alg_index; | |
5956 | pcisd->data[CISD_DATA_FULL_COUNT] = temp_data[0]; | |
5957 | pcisd->data[CISD_DATA_CAP_MAX] = temp_data[1]; | |
5958 | pcisd->data[CISD_DATA_CAP_MIN] = temp_data[2]; | |
5959 | pcisd->data[CISD_DATA_VALERT_COUNT] = temp_data[16]; | |
5960 | pcisd->data[CISD_DATA_CYCLE] = temp_data[17]; | |
5961 | pcisd->data[CISD_DATA_WIRE_COUNT] = temp_data[18]; | |
5962 | pcisd->data[CISD_DATA_WIRELESS_COUNT] = temp_data[19]; | |
5963 | pcisd->data[CISD_DATA_HIGH_TEMP_SWELLING] = temp_data[20]; | |
5964 | pcisd->data[CISD_DATA_LOW_TEMP_SWELLING] = temp_data[21]; | |
5965 | pcisd->data[CISD_DATA_SWELLING_CHARGING_COUNT] = temp_data[22]; | |
5966 | pcisd->data[CISD_DATA_AICL_COUNT] = temp_data[26]; | |
5967 | pcisd->data[CISD_DATA_BATT_TEMP_MAX] = temp_data[27]; | |
5968 | pcisd->data[CISD_DATA_BATT_TEMP_MIN] = temp_data[28]; | |
5969 | pcisd->data[CISD_DATA_CHG_TEMP_MAX] = temp_data[29]; | |
5970 | pcisd->data[CISD_DATA_CHG_TEMP_MIN] = temp_data[30]; | |
5971 | pcisd->data[CISD_DATA_WPC_TEMP_MAX] = temp_data[31]; | |
5972 | pcisd->data[CISD_DATA_WPC_TEMP_MIN] = temp_data[32]; | |
5973 | pcisd->data[CISD_DATA_UNSAFETY_VOLTAGE] = temp_data[33]; | |
5974 | pcisd->data[CISD_DATA_UNSAFETY_TEMPERATURE] = temp_data[34]; | |
5975 | pcisd->data[CISD_DATA_SAFETY_TIMER] = temp_data[35]; | |
5976 | pcisd->data[CISD_DATA_VSYS_OVP] = temp_data[36]; | |
5977 | pcisd->data[CISD_DATA_VBAT_OVP] = temp_data[37]; | |
5978 | pcisd->data[CISD_DATA_AFC_FAIL] = temp_data[39]; | |
5979 | pcisd->data[CISD_DATA_WATER_DETECT] = temp_data[38]; | |
5980 | } | |
5981 | } else { | |
5982 | const char *p = buf; | |
5983 | ||
5984 | pr_info("%s: %s\n", __func__, buf); | |
5985 | for (i = CISD_DATA_RESET_ALG; i < CISD_DATA_MAX_PER_DAY; i++) { | |
5986 | if (sscanf(p, "%10d%n", &pcisd->data[i], &x) > 0) | |
5987 | p += (size_t)x; | |
5988 | else { | |
5989 | pr_info("%s: NO DATA (cisd_data)\n", __func__); | |
5990 | temp_data[CISD_DATA_RESET_ALG] = -1; | |
5991 | break; | |
5992 | } | |
5993 | } | |
5994 | ||
5995 | pr_info("%s: %s cisd data\n", __func__, | |
5996 | ((temp_data[CISD_DATA_RESET_ALG] < 0 || battery->fg_reset) ? "init" : "update")); | |
5997 | ||
5998 | if (temp_data[CISD_DATA_RESET_ALG] < 0 || battery->fg_reset) { | |
5999 | /* initialize data */ | |
6000 | for (i = CISD_DATA_RESET_ALG; i < CISD_DATA_MAX_PER_DAY; i++) | |
6001 | pcisd->data[i] = 0; | |
6002 | ||
6003 | battery->fg_reset = 0; | |
6004 | ||
6005 | pcisd->data[CISD_DATA_ALG_INDEX] = battery->pdata->cisd_alg_index; | |
6006 | ||
6007 | pcisd->data[CISD_DATA_FULL_COUNT] = 1; | |
6008 | pcisd->data[CISD_DATA_BATT_TEMP_MAX] = -300; | |
6009 | pcisd->data[CISD_DATA_CHG_TEMP_MAX] = -300; | |
6010 | pcisd->data[CISD_DATA_WPC_TEMP_MAX] = -300; | |
6011 | pcisd->data[CISD_DATA_USB_TEMP_MAX] = -300; | |
6012 | pcisd->data[CISD_DATA_BATT_TEMP_MIN] = 1000; | |
6013 | pcisd->data[CISD_DATA_CHG_TEMP_MIN] = 1000; | |
6014 | pcisd->data[CISD_DATA_WPC_TEMP_MIN] = 1000; | |
6015 | pcisd->data[CISD_DATA_USB_TEMP_MIN] = 1000; | |
6016 | pcisd->data[CISD_DATA_CAP_MIN] = 0xFFFF; | |
6017 | ||
6018 | pcisd->data[CISD_DATA_FULL_COUNT_PER_DAY] = 1; | |
6019 | pcisd->data[CISD_DATA_BATT_TEMP_MAX_PER_DAY] = -300; | |
6020 | pcisd->data[CISD_DATA_CHG_TEMP_MAX_PER_DAY] = -300; | |
6021 | pcisd->data[CISD_DATA_WPC_TEMP_MAX_PER_DAY] = -300; | |
6022 | pcisd->data[CISD_DATA_USB_TEMP_MAX_PER_DAY] = -300; | |
6023 | pcisd->data[CISD_DATA_BATT_TEMP_MIN_PER_DAY] = 1000; | |
6024 | pcisd->data[CISD_DATA_CHG_TEMP_MIN_PER_DAY] = 1000; | |
6025 | pcisd->data[CISD_DATA_WPC_TEMP_MIN_PER_DAY] = 1000; | |
6026 | pcisd->data[CISD_DATA_USB_TEMP_MIN_PER_DAY] = 1000; | |
6027 | ||
6028 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MAX] = -300; | |
6029 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MAX] = -300; | |
6030 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MAX] = -300; | |
6031 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MAX] = -300; | |
6032 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MIN] = 1000; | |
6033 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MIN] = 1000; | |
6034 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MIN] = 1000; | |
6035 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MIN] = 1000; | |
6036 | ||
6037 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MAX_PER_DAY] = -300; | |
6038 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MAX_PER_DAY] = -300; | |
6039 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MAX_PER_DAY] = -300; | |
6040 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MAX_PER_DAY] = -300; | |
6041 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MIN_PER_DAY] = 1000; | |
6042 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MIN_PER_DAY] = 1000; | |
6043 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MIN_PER_DAY] = 1000; | |
6044 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MIN_PER_DAY] = 1000; | |
6045 | ||
6046 | pcisd->data[CISD_DATA_CAP_MIN_PER_DAY] = 0xFFFF; | |
6047 | ||
6048 | ||
6049 | /* initialize pad data */ | |
6050 | init_cisd_pad_data(&battery->cisd); | |
6051 | } | |
6052 | } | |
6053 | ret = count; | |
6054 | wake_lock(&battery->monitor_wake_lock); | |
6055 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
6056 | } | |
6057 | break; | |
6058 | case CISD_DATA_JSON: | |
6059 | { | |
6060 | char tc; | |
6061 | struct cisd *pcisd = &battery->cisd; | |
6062 | ||
6063 | if (sscanf(buf, "%1c\n", &tc) == 1) { | |
6064 | if (tc == 'c') { | |
6065 | for (i = 0; i < CISD_DATA_MAX; i++) | |
6066 | pcisd->data[i] = 0; | |
6067 | ||
6068 | pcisd->data[CISD_DATA_FULL_COUNT] = 1; | |
6069 | pcisd->data[CISD_DATA_BATT_TEMP_MAX] = -300; | |
6070 | pcisd->data[CISD_DATA_CHG_TEMP_MAX] = -300; | |
6071 | pcisd->data[CISD_DATA_WPC_TEMP_MAX] = -300; | |
6072 | pcisd->data[CISD_DATA_USB_TEMP_MAX] = -300; | |
6073 | pcisd->data[CISD_DATA_BATT_TEMP_MIN] = 1000; | |
6074 | pcisd->data[CISD_DATA_CHG_TEMP_MIN] = 1000; | |
6075 | pcisd->data[CISD_DATA_WPC_TEMP_MIN] = 1000; | |
6076 | pcisd->data[CISD_DATA_USB_TEMP_MIN] = 1000; | |
6077 | pcisd->data[CISD_DATA_CAP_MIN] = 0xFFFF; | |
6078 | ||
6079 | pcisd->data[CISD_DATA_FULL_COUNT_PER_DAY] = 1; | |
6080 | pcisd->data[CISD_DATA_BATT_TEMP_MAX_PER_DAY] = -300; | |
6081 | pcisd->data[CISD_DATA_CHG_TEMP_MAX_PER_DAY] = -300; | |
6082 | pcisd->data[CISD_DATA_WPC_TEMP_MAX_PER_DAY] = -300; | |
6083 | pcisd->data[CISD_DATA_USB_TEMP_MAX_PER_DAY] = -300; | |
6084 | pcisd->data[CISD_DATA_BATT_TEMP_MIN_PER_DAY] = 1000; | |
6085 | pcisd->data[CISD_DATA_CHG_TEMP_MIN_PER_DAY] = 1000; | |
6086 | pcisd->data[CISD_DATA_WPC_TEMP_MIN_PER_DAY] = 1000; | |
6087 | pcisd->data[CISD_DATA_USB_TEMP_MIN_PER_DAY] = 1000; | |
6088 | ||
6089 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MAX] = -300; | |
6090 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MAX] = -300; | |
6091 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MAX] = -300; | |
6092 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MAX] = -300; | |
6093 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MIN] = 1000; | |
6094 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MIN] = 1000; | |
6095 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MIN] = 1000; | |
6096 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MIN] = 1000; | |
6097 | ||
6098 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MAX_PER_DAY] = -300; | |
6099 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MAX_PER_DAY] = -300; | |
6100 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MAX_PER_DAY] = -300; | |
6101 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MAX_PER_DAY] = -300; | |
6102 | pcisd->data[CISD_DATA_CHG_BATT_TEMP_MIN_PER_DAY] = 1000; | |
6103 | pcisd->data[CISD_DATA_CHG_CHG_TEMP_MIN_PER_DAY] = 1000; | |
6104 | pcisd->data[CISD_DATA_CHG_WPC_TEMP_MIN_PER_DAY] = 1000; | |
6105 | pcisd->data[CISD_DATA_CHG_USB_TEMP_MIN_PER_DAY] = 1000; | |
6106 | ||
6107 | pcisd->data[CISD_DATA_CAP_MIN_PER_DAY] = 0xFFFF; | |
6108 | ||
6109 | } | |
6110 | } | |
6111 | ret = count; | |
6112 | } | |
6113 | break; | |
6114 | case CISD_DATA_D_JSON: | |
6115 | break; | |
6116 | case CISD_WIRE_COUNT: | |
6117 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
6118 | struct cisd *pcisd = &battery->cisd; | |
6119 | pr_info("%s: Wire Count : %d\n", __func__, x); | |
6120 | pcisd->data[CISD_DATA_WIRE_COUNT] = x; | |
6121 | pcisd->data[CISD_DATA_WIRE_COUNT_PER_DAY]++; | |
6122 | } | |
6123 | ret = count; | |
6124 | break; | |
6125 | case CISD_WC_DATA: | |
6126 | set_cisd_pad_data(battery, buf); | |
6127 | ret = count; | |
6128 | break; | |
6129 | case CISD_WC_DATA_JSON: | |
6130 | break; | |
6131 | case PREV_BATTERY_DATA: | |
6132 | if (sscanf(buf, "%10d, %10d, %10d, %10d\n", | |
6133 | &battery->prev_volt, &battery->prev_temp, | |
6134 | &battery->prev_jig_on, &battery->prev_chg_on) >= 4) { | |
6135 | pr_info("%s: prev voltage : %d, prev_temp : %d, prev_jig_on : %d, prev_chg_on : %d\n", | |
6136 | __func__, battery->prev_volt, battery->prev_temp, | |
6137 | battery->prev_jig_on, battery->prev_chg_on); | |
6138 | ||
6139 | if (battery->prev_volt >= 3700 && battery->prev_temp >= 150 && | |
6140 | !battery->prev_jig_on && battery->fg_reset) | |
6141 | pr_info("%s: Battery have been Removed\n", __func__); | |
6142 | ||
6143 | ret = count; | |
6144 | } | |
6145 | battery->enable_update_data = 1; | |
6146 | break; | |
6147 | case PREV_BATTERY_INFO: | |
6148 | break; | |
6149 | #endif | |
6150 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
6151 | case SBM_DATA: | |
6152 | break; | |
6153 | #endif | |
6154 | case SAFETY_TIMER_SET: | |
6155 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
6156 | if (x) { | |
6157 | battery->safety_timer_set = true; | |
6158 | } else { | |
6159 | battery->safety_timer_set = false; | |
6160 | } | |
6161 | ret = count; | |
6162 | } | |
6163 | break; | |
6164 | case BATT_SWELLING_CONTROL: | |
6165 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
6166 | if (x) { | |
6167 | pr_info("%s : 15TEST START!! SWELLING MODE DISABLE\n", __func__); | |
6168 | battery->skip_swelling = true; | |
6169 | } else { | |
6170 | pr_info("%s : 15TEST END!! SWELLING MODE END\n", __func__); | |
6171 | battery->skip_swelling = false; | |
6172 | } | |
6173 | ret = count; | |
6174 | } | |
6175 | break; | |
6176 | case SAFETY_TIMER_INFO: | |
6177 | break; | |
6178 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
6179 | case BATT_TEMP_TEST: | |
6180 | { | |
6181 | char tc; | |
6182 | if (sscanf(buf, "%c %10d\n", &tc, &x) == 2) { | |
6183 | pr_info("%s : temperature t: %c, temp: %d\n", __func__, tc, x); | |
6184 | if (tc == 'u') { | |
6185 | battery->temperature_test_usb = x; | |
6186 | } else if (tc == 'w') { | |
6187 | battery->temperature_test_wpc = x; | |
6188 | } else if (tc == 'b') { | |
6189 | battery->temperature_test_battery = x; | |
6190 | } else if (tc == 'c') { | |
6191 | battery->temperature_test_chg = x; | |
6192 | } | |
6193 | ret = count; | |
6194 | } | |
6195 | break; | |
6196 | } | |
6197 | #endif | |
6198 | case BATT_CURRENT_EVENT: | |
6199 | break; | |
6200 | case CC_INFO: | |
6201 | break; | |
6202 | case EXT_EVENT: | |
6203 | if (sscanf(buf, "%10d\n", &x) == 1) { | |
6204 | dev_info(battery->dev, | |
6205 | "%s: ext event 0x%x \n", __func__, x); | |
6206 | battery->ext_event = x; | |
6207 | wake_lock(&battery->ext_event_wake_lock); | |
6208 | queue_delayed_work(battery->monitor_wqueue, &battery->ext_event_work, 0); | |
6209 | ret = count; | |
6210 | } | |
6211 | break; | |
6212 | default: | |
6213 | ret = -EINVAL; | |
6214 | break; | |
6215 | } | |
6216 | ||
6217 | return ret; | |
6218 | } | |
6219 | ||
6220 | static int sec_bat_create_attrs(struct device *dev) | |
6221 | { | |
6222 | unsigned long i = 0; | |
6223 | int rc = 0; | |
6224 | ||
6225 | for (i = 0; i < ARRAY_SIZE(sec_battery_attrs); i++) { | |
6226 | rc = device_create_file(dev, &sec_battery_attrs[i]); | |
6227 | if (rc) | |
6228 | goto create_attrs_failed; | |
6229 | } | |
6230 | goto create_attrs_succeed; | |
6231 | ||
6232 | create_attrs_failed: | |
6233 | while (i--) | |
6234 | device_remove_file(dev, &sec_battery_attrs[i]); | |
6235 | create_attrs_succeed: | |
6236 | return rc; | |
6237 | } | |
6238 | ||
6239 | static int sec_bat_set_property(struct power_supply *psy, | |
6240 | enum power_supply_property psp, | |
6241 | const union power_supply_propval *val) | |
6242 | { | |
6243 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
6244 | int current_cable_type = SEC_BATTERY_CABLE_NONE; | |
6245 | int full_check_type = SEC_BATTERY_FULLCHARGED_NONE; | |
6246 | union power_supply_propval value = {0, }; | |
ca34248d | 6247 | enum power_supply_ext_property ext_psp = (enum power_supply_ext_property) psp; |
1cac41cb MB |
6248 | |
6249 | dev_dbg(battery->dev, | |
6250 | "%s: (%d,%d)\n", __func__, psp, val->intval); | |
6251 | ||
6252 | switch (psp) { | |
6253 | case POWER_SUPPLY_PROP_STATUS: | |
6254 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST) | |
6255 | full_check_type = battery->pdata->full_check_type; | |
6256 | else | |
6257 | full_check_type = battery->pdata->full_check_type_2nd; | |
6258 | if ((full_check_type == SEC_BATTERY_FULLCHARGED_CHGINT) && | |
6259 | (val->intval == POWER_SUPPLY_STATUS_FULL)) | |
6260 | sec_bat_do_fullcharged(battery); | |
6261 | sec_bat_set_charging_status(battery, val->intval); | |
6262 | break; | |
6263 | case POWER_SUPPLY_PROP_HEALTH: | |
6264 | sec_bat_ovp_uvlo_result(battery, val->intval); | |
6265 | break; | |
6266 | case POWER_SUPPLY_PROP_ONLINE: | |
6267 | current_cable_type = val->intval; | |
6268 | #if !defined(CONFIG_CCIC_NOTIFIER) | |
6269 | if ((battery->muic_cable_type != ATTACHED_DEV_SMARTDOCK_TA_MUIC) | |
6270 | && ((current_cable_type == SEC_BATTERY_CABLE_SMART_OTG) || | |
6271 | (current_cable_type == SEC_BATTERY_CABLE_SMART_NOTG))) | |
6272 | break; | |
6273 | #endif | |
6274 | ||
6275 | if (current_cable_type < 0) { | |
6276 | dev_info(battery->dev, | |
6277 | "%s: ignore event(%d)\n", | |
6278 | __func__, current_cable_type); | |
6279 | } else if (current_cable_type == SEC_BATTERY_CABLE_OTG) { | |
6280 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
6281 | battery->is_recharging = false; | |
6282 | sec_bat_set_charging_status(battery, | |
6283 | POWER_SUPPLY_STATUS_DISCHARGING); | |
6284 | battery->cable_type = current_cable_type; | |
6285 | wake_lock(&battery->monitor_wake_lock); | |
6286 | queue_delayed_work(battery->monitor_wqueue, | |
6287 | &battery->monitor_work, 0); | |
6288 | break; | |
6289 | } else { | |
6290 | battery->wire_status = current_cable_type; | |
6291 | if ((battery->wire_status == SEC_BATTERY_CABLE_NONE) && | |
6292 | (battery->wc_status != SEC_WIRELESS_PAD_NONE) ) | |
6293 | current_cable_type = SEC_BATTERY_CABLE_WIRELESS; | |
6294 | } | |
6295 | dev_info(battery->dev, | |
6296 | "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n", | |
6297 | __func__, current_cable_type, battery->wc_status, | |
6298 | battery->wire_status); | |
6299 | ||
6300 | /* cable is attached or detached | |
6301 | * if current_cable_type is minus value, | |
6302 | * check cable by sec_bat_get_cable_type() | |
6303 | * although SEC_BATTERY_CABLE_SOURCE_EXTERNAL is set | |
6304 | * (0 is SEC_BATTERY_CABLE_UNKNOWN) | |
6305 | */ | |
6306 | if ((current_cable_type >= 0) && | |
6307 | (current_cable_type < SEC_BATTERY_CABLE_MAX) && | |
6308 | (battery->pdata->cable_source_type & | |
6309 | SEC_BATTERY_CABLE_SOURCE_EXTERNAL)) { | |
6310 | ||
6311 | wake_lock(&battery->cable_wake_lock); | |
6312 | queue_delayed_work(battery->monitor_wqueue, | |
6313 | &battery->cable_work,0); | |
6314 | } else { | |
6315 | if (sec_bat_get_cable_type(battery, | |
6316 | battery->pdata->cable_source_type)) { | |
6317 | wake_lock(&battery->cable_wake_lock); | |
6318 | queue_delayed_work(battery->monitor_wqueue, | |
6319 | &battery->cable_work,0); | |
6320 | } | |
6321 | } | |
6322 | break; | |
6323 | case POWER_SUPPLY_PROP_CAPACITY: | |
6324 | battery->capacity = val->intval; | |
6325 | power_supply_changed(battery->psy_bat); | |
6326 | break; | |
6327 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | |
6328 | /* If JIG is attached, the voltage is set as 1079 */ | |
6329 | pr_info("%s : set to the battery history : (%d)\n",__func__, val->intval); | |
6330 | if(val->intval == 1079) { | |
6331 | battery->voltage_now = 1079; | |
6332 | battery->voltage_avg = 1079; | |
6333 | power_supply_changed(battery->psy_bat); | |
6334 | } | |
6335 | break; | |
6336 | case POWER_SUPPLY_PROP_CHARGE_TYPE: | |
6337 | wake_lock(&battery->monitor_wake_lock); | |
6338 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
6339 | break; | |
6340 | case POWER_SUPPLY_PROP_PRESENT: | |
6341 | battery->present = val->intval; | |
6342 | ||
6343 | wake_lock(&battery->monitor_wake_lock); | |
6344 | queue_delayed_work(battery->monitor_wqueue, | |
6345 | &battery->monitor_work, 0); | |
6346 | break; | |
6347 | #if defined(CONFIG_BATTERY_SWELLING) | |
6348 | case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: | |
6349 | break; | |
6350 | #endif | |
6351 | case POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION: | |
6352 | case POWER_SUPPLY_PROP_CHARGE_COUNTER_SHADOW: | |
6353 | break; | |
6354 | case POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL: | |
6355 | value.intval = val->intval; | |
6356 | pr_info("%s: CHGIN-OTG %s\n", __func__, value.intval > 0 ? "on" : "off"); | |
6357 | psy_do_property(battery->pdata->charger_name, set, | |
6358 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
6359 | break; | |
6360 | case POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL: | |
6361 | value.intval = val->intval; | |
6362 | pr_info("%s: WCIN-UNO %s\n", __func__, value.intval > 0 ? "on" : "off"); | |
6363 | psy_do_property(battery->pdata->charger_name, set, | |
6364 | POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL, value); | |
6365 | break; | |
6366 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
6367 | case POWER_SUPPLY_PROP_POWER_DESIGN: | |
6368 | sec_bat_parse_dt(battery->dev, battery); | |
6369 | break; | |
6370 | #endif | |
6371 | #if defined(CONFIG_BATTERY_CISD) | |
6372 | case POWER_SUPPLY_PROP_VOLTAGE_MIN: | |
6373 | pr_info("%s: Valert was occured! run monitor work for updating cisd data!\n", __func__); | |
6374 | battery->cisd.data[CISD_DATA_VALERT_COUNT]++; | |
6375 | battery->cisd.data[CISD_DATA_VALERT_COUNT_PER_DAY]++; | |
6376 | wake_lock(&battery->monitor_wake_lock); | |
6377 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
6378 | &battery->monitor_work, 0); | |
6379 | break; | |
6380 | #endif | |
6381 | case POWER_SUPPLY_PROP_MAX ... POWER_SUPPLY_EXT_PROP_MAX: | |
6382 | switch (ext_psp) { | |
6383 | case POWER_SUPPLY_EXT_PROP_AICL_CURRENT: | |
6384 | battery->aicl_current = val->intval; | |
6385 | battery->max_charge_power = battery->charge_power = battery->input_voltage * val->intval; | |
6386 | pr_info("%s: aicl : %dmA, %dmW)\n", __func__, | |
6387 | battery->aicl_current, battery->charge_power); | |
6388 | ||
6389 | if (is_wired_type(battery->cable_type)) | |
6390 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_AICL, | |
6391 | SEC_BAT_CURRENT_EVENT_AICL); | |
6392 | ||
6393 | #if defined(CONFIG_BATTERY_CISD) | |
6394 | battery->cisd.data[CISD_DATA_AICL_COUNT]++; | |
6395 | battery->cisd.data[CISD_DATA_AICL_COUNT_PER_DAY]++; | |
6396 | #endif | |
6397 | break; | |
6398 | case POWER_SUPPLY_EXT_PROP_SYSOVLO: | |
6399 | if (battery->status != POWER_SUPPLY_STATUS_DISCHARGING) { | |
6400 | pr_info("%s: Vsys is ovlo !!\n", __func__); | |
6401 | battery->is_sysovlo = true; | |
6402 | battery->is_recharging = false; | |
6403 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
6404 | battery->health = POWER_SUPPLY_HEALTH_VSYS_OVP; | |
6405 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_VSYS_OVP, SEC_BAT_CURRENT_EVENT_VSYS_OVP); | |
6406 | sec_bat_set_charging_status(battery, POWER_SUPPLY_STATUS_NOT_CHARGING); | |
6407 | #if defined(CONFIG_BATTERY_CISD) | |
6408 | battery->cisd.data[CISD_DATA_VSYS_OVP]++; | |
6409 | battery->cisd.data[CISD_DATA_VSYS_OVP_PER_DAY]++; | |
6410 | #endif | |
6411 | #if defined(CONFIG_SEC_ABC) | |
6412 | sec_abc_send_event("MODULE=battery@ERROR=vsys_ovp"); | |
6413 | #endif | |
6414 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
6415 | wake_lock(&battery->monitor_wake_lock); | |
6416 | queue_delayed_work(battery->monitor_wqueue, | |
6417 | &battery->monitor_work, 0); | |
6418 | } | |
6419 | break; | |
6420 | case POWER_SUPPLY_EXT_PROP_VBAT_OVP: | |
6421 | if (battery->status != POWER_SUPPLY_STATUS_DISCHARGING) { | |
6422 | pr_info("%s: Vbat is ovlo !!\n", __func__); | |
6423 | battery->is_vbatovlo = true; | |
6424 | battery->is_recharging = false; | |
6425 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
6426 | battery->health = POWER_SUPPLY_HEALTH_VBAT_OVP; | |
6427 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_VBAT_OVP, SEC_BAT_CURRENT_EVENT_VBAT_OVP); | |
6428 | sec_bat_set_charging_status(battery, POWER_SUPPLY_STATUS_NOT_CHARGING); | |
6429 | ||
6430 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
6431 | wake_lock(&battery->monitor_wake_lock); | |
6432 | queue_delayed_work(battery->monitor_wqueue, | |
6433 | &battery->monitor_work, 0); | |
6434 | } | |
6435 | break; | |
6436 | case POWER_SUPPLY_EXT_PROP_USB_CONFIGURE: | |
6437 | if (battery->pdic_info.sink_status.rp_currentlvl > RP_CURRENT_LEVEL_DEFAULT) | |
6438 | return 0; | |
6439 | pr_info("%s: usb configured %d\n", __func__, val->intval); | |
6440 | if (val->intval == USB_CURRENT_UNCONFIGURED) { | |
6441 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_USB_100MA, | |
6442 | (SEC_BAT_CURRENT_EVENT_USB_100MA | SEC_BAT_CURRENT_EVENT_USB_SUPER)); | |
6443 | } else if (val->intval == USB_CURRENT_HIGH_SPEED) { | |
6444 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_TIMEOUT_OPEN_TYPE, 1); | |
6445 | sec_bat_set_current_event(battery, 0, | |
6446 | (SEC_BAT_CURRENT_EVENT_USB_100MA | SEC_BAT_CURRENT_EVENT_USB_SUPER)); | |
6447 | sec_bat_change_default_current(battery, SEC_BATTERY_CABLE_USB, | |
6448 | USB_CURRENT_HIGH_SPEED, USB_CURRENT_HIGH_SPEED); | |
6449 | } else if (val->intval == USB_CURRENT_SUPER_SPEED) { | |
6450 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_TIMEOUT_OPEN_TYPE, 1); | |
6451 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_USB_SUPER, | |
6452 | (SEC_BAT_CURRENT_EVENT_USB_100MA | SEC_BAT_CURRENT_EVENT_USB_SUPER)); | |
6453 | sec_bat_change_default_current(battery, SEC_BATTERY_CABLE_USB, | |
6454 | USB_CURRENT_SUPER_SPEED, USB_CURRENT_SUPER_SPEED); | |
6455 | } | |
6456 | sec_bat_set_charging_current(battery); | |
6457 | break; | |
6458 | case POWER_SUPPLY_EXT_PROP_HV_DISABLE: | |
6459 | pr_info("HV wired charging mode is %s\n", (val->intval == CH_MODE_AFC_DISABLE_VAL ? "Disabled" : "Enabled")); | |
6460 | sec_bat_set_current_event(battery, (val->intval == CH_MODE_AFC_DISABLE_VAL ? | |
6461 | SEC_BAT_CURRENT_EVENT_HV_DISABLE : 0), SEC_BAT_CURRENT_EVENT_HV_DISABLE); | |
6462 | break; | |
6463 | case POWER_SUPPLY_EXT_PROP_WC_CONTROL: | |
6464 | pr_info("%s: Recover MFC IC (wc_enable: %d)\n", | |
6465 | __func__, battery->wc_enable); | |
6466 | ||
6467 | if (battery->pdata->wpc_en) { | |
6468 | mutex_lock(&battery->wclock); | |
6469 | if (battery->wc_enable) { | |
6470 | gpio_direction_output(battery->pdata->wpc_en, 1); | |
6471 | msleep(500); | |
6472 | gpio_direction_output(battery->pdata->wpc_en, 0); | |
6473 | } | |
6474 | mutex_unlock(&battery->wclock); | |
6475 | } | |
6476 | #if defined(CONFIG_BATTERY_CISD) | |
6477 | increase_cisd_count(CISD_DATA_DROP_VALUE); | |
6478 | #endif | |
6479 | break; | |
6480 | default: | |
6481 | return -EINVAL; | |
6482 | } | |
6483 | break; | |
6484 | default: | |
6485 | return -EINVAL; | |
6486 | } | |
6487 | ||
6488 | return 0; | |
6489 | } | |
6490 | ||
6491 | static int sec_bat_get_property(struct power_supply *psy, | |
6492 | enum power_supply_property psp, | |
6493 | union power_supply_propval *val) | |
6494 | { | |
6495 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
6496 | union power_supply_propval value = {0, }; | |
ca34248d | 6497 | enum power_supply_ext_property ext_psp = (enum power_supply_ext_property) psp; |
1cac41cb MB |
6498 | |
6499 | switch (psp) { | |
6500 | case POWER_SUPPLY_PROP_STATUS: | |
6501 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERVOLTAGE) || | |
6502 | (battery->health == POWER_SUPPLY_HEALTH_UNDERVOLTAGE)) { | |
6503 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; | |
6504 | } else { | |
6505 | if ((battery->pdata->cable_check_type & | |
6506 | SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE) && | |
6507 | !lpcharge) { | |
6508 | switch (battery->cable_type) { | |
6509 | case SEC_BATTERY_CABLE_USB: | |
6510 | case SEC_BATTERY_CABLE_USB_CDP: | |
6511 | val->intval = | |
6512 | POWER_SUPPLY_STATUS_DISCHARGING; | |
6513 | return 0; | |
6514 | } | |
6515 | } | |
6516 | #if defined(CONFIG_STORE_MODE) | |
6517 | if (battery->store_mode && !lpcharge && | |
6518 | battery->cable_type != SEC_BATTERY_CABLE_NONE && | |
6519 | battery->cable_type != SEC_BATTERY_CABLE_OTG && | |
6520 | battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
6521 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | |
6522 | } else | |
6523 | #endif | |
6524 | val->intval = battery->status; | |
6525 | } | |
6526 | break; | |
6527 | case POWER_SUPPLY_PROP_CHARGE_TYPE: | |
6528 | if (battery->cable_type == SEC_BATTERY_CABLE_NONE) { | |
6529 | val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; | |
6530 | } else { | |
6531 | psy_do_property(battery->pdata->charger_name, get, | |
6532 | POWER_SUPPLY_PROP_CHARGE_TYPE, value); | |
6533 | if (value.intval == SEC_BATTERY_CABLE_UNKNOWN) | |
6534 | /* if error in CHARGE_TYPE of charger | |
6535 | * set CHARGE_TYPE as NONE | |
6536 | */ | |
6537 | val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; | |
6538 | else | |
6539 | val->intval = value.intval; | |
6540 | } | |
6541 | break; | |
6542 | case POWER_SUPPLY_PROP_HEALTH: | |
6543 | if (battery->health >= POWER_SUPPLY_HEALTH_MAX) | |
6544 | val->intval = POWER_SUPPLY_HEALTH_UNKNOWN; | |
6545 | else | |
6546 | val->intval = battery->health; | |
6547 | break; | |
6548 | case POWER_SUPPLY_PROP_PRESENT: | |
6549 | val->intval = battery->present; | |
6550 | break; | |
6551 | case POWER_SUPPLY_PROP_ONLINE: | |
6552 | if (is_hv_wireless_type(battery->cable_type) || | |
6553 | (battery->cable_type == SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV)) { | |
6554 | if (sec_bat_hv_wc_normal_mode_check(battery)) | |
6555 | val->intval = SEC_BATTERY_CABLE_WIRELESS; | |
6556 | else | |
6557 | val->intval = SEC_BATTERY_CABLE_HV_WIRELESS_ETX; | |
6558 | } | |
6559 | else if(battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_PACK) | |
6560 | val->intval = SEC_BATTERY_CABLE_WIRELESS; | |
6561 | else if(battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_STAND) | |
6562 | val->intval = SEC_BATTERY_CABLE_WIRELESS; | |
6563 | else if(battery->cable_type == SEC_BATTERY_CABLE_PMA_WIRELESS) | |
6564 | val->intval = SEC_BATTERY_CABLE_WIRELESS; | |
6565 | else if(battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_VEHICLE) | |
6566 | val->intval = SEC_BATTERY_CABLE_WIRELESS; | |
6567 | else if(battery->cable_type == SEC_BATTERY_CABLE_WIRELESS_TX) | |
6568 | val->intval = SEC_BATTERY_CABLE_WIRELESS; | |
6569 | else | |
6570 | val->intval = battery->cable_type; | |
6571 | pr_info("%s cable type = %d sleep_mode = %d\n", __func__, val->intval, sleep_mode); | |
6572 | break; | |
6573 | case POWER_SUPPLY_PROP_TECHNOLOGY: | |
6574 | val->intval = battery->pdata->technology; | |
6575 | break; | |
6576 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | |
6577 | #ifdef CONFIG_SEC_FACTORY | |
6578 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
6579 | POWER_SUPPLY_PROP_VOLTAGE_NOW, value); | |
6580 | battery->voltage_now = value.intval; | |
6581 | dev_err(battery->dev, | |
6582 | "%s: voltage now(%d)\n", __func__, battery->voltage_now); | |
6583 | #endif | |
6584 | /* voltage value should be in uV */ | |
6585 | val->intval = battery->voltage_now * 1000; | |
6586 | break; | |
6587 | case POWER_SUPPLY_PROP_VOLTAGE_AVG: | |
6588 | #ifdef CONFIG_SEC_FACTORY | |
6589 | value.intval = SEC_BATTERY_VOLTAGE_AVERAGE; | |
6590 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
6591 | POWER_SUPPLY_PROP_VOLTAGE_AVG, value); | |
6592 | battery->voltage_avg = value.intval; | |
6593 | dev_err(battery->dev, | |
6594 | "%s: voltage avg(%d)\n", __func__, battery->voltage_avg); | |
6595 | #endif | |
6596 | /* voltage value should be in uV */ | |
6597 | val->intval = battery->voltage_avg * 1000; | |
6598 | break; | |
6599 | case POWER_SUPPLY_PROP_CURRENT_NOW: | |
6600 | val->intval = battery->current_now; | |
6601 | break; | |
6602 | case POWER_SUPPLY_PROP_CURRENT_AVG: | |
6603 | val->intval = battery->current_avg; | |
6604 | break; | |
6605 | case POWER_SUPPLY_PROP_CHARGE_FULL: | |
6606 | #if defined(CONFIG_BATTERY_CISD) | |
6607 | val->intval = battery->pdata->battery_full_capacity * 1000; | |
6608 | #else | |
6609 | val->intval = 0; | |
6610 | #endif | |
6611 | break; | |
6612 | /* charging mode (differ from power supply) */ | |
6613 | case POWER_SUPPLY_PROP_CHARGE_NOW: | |
6614 | val->intval = battery->charging_mode; | |
6615 | break; | |
6616 | case POWER_SUPPLY_PROP_CAPACITY: | |
6617 | if (battery->pdata->fake_capacity) { | |
6618 | val->intval = 90; | |
6619 | pr_info("%s : capacity(%d)\n", __func__, val->intval); | |
6620 | } else { | |
6621 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
6622 | if (battery->status == POWER_SUPPLY_STATUS_FULL) { | |
6623 | if(battery->eng_not_full_status) | |
6624 | val->intval = battery->capacity; | |
6625 | else | |
6626 | val->intval = 100; | |
6627 | } else { | |
6628 | val->intval = battery->capacity; | |
6629 | } | |
6630 | #else | |
6631 | if (battery->status == POWER_SUPPLY_STATUS_FULL) | |
6632 | val->intval = 100; | |
6633 | else | |
6634 | val->intval = battery->capacity; | |
6635 | #endif | |
6636 | } | |
6637 | break; | |
6638 | case POWER_SUPPLY_PROP_TEMP: | |
6639 | val->intval = battery->temperature; | |
6640 | break; | |
6641 | case POWER_SUPPLY_PROP_TEMP_AMBIENT: | |
6642 | val->intval = battery->temper_amb; | |
6643 | break; | |
6644 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
6645 | case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: | |
6646 | if (battery->capacity == 100) { | |
6647 | val->intval = -1; | |
6648 | break; | |
6649 | } | |
6650 | ||
6651 | if (((battery->status == POWER_SUPPLY_STATUS_CHARGING) || | |
6652 | (battery->status == POWER_SUPPLY_STATUS_FULL && battery->capacity != 100)) && | |
6653 | !battery->swelling_mode) | |
6654 | val->intval = battery->timetofull; | |
6655 | else | |
6656 | val->intval = -1; | |
6657 | break; | |
6658 | #endif | |
6659 | #if defined(CONFIG_BATTERY_SWELLING) | |
6660 | case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: | |
6661 | if (battery->swelling_mode) | |
6662 | val->intval = 1; | |
6663 | else | |
6664 | val->intval = 0; | |
6665 | break; | |
6666 | #endif | |
6667 | case POWER_SUPPLY_PROP_CHARGE_COUNTER_SHADOW: | |
6668 | val->intval = battery->wire_status; | |
6669 | break; | |
6670 | case POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL: | |
6671 | case POWER_SUPPLY_PROP_CHARGE_UNO_CONTROL: | |
6672 | break; | |
6673 | case POWER_SUPPLY_PROP_POWER_NOW: | |
6674 | val->intval = battery->charge_power; | |
6675 | break; | |
6676 | case POWER_SUPPLY_PROP_CHARGE_COUNTER: | |
6677 | val->intval = battery->charge_counter; | |
6678 | break; | |
6679 | case POWER_SUPPLY_PROP_MAX ... POWER_SUPPLY_EXT_PROP_MAX: | |
6680 | switch (ext_psp) { | |
6681 | case POWER_SUPPLY_EXT_PROP_SUB_PBA_TEMP_REC: | |
6682 | val->intval = !battery->vbus_limit; | |
6683 | break; | |
6684 | default: | |
6685 | return -EINVAL; | |
6686 | } | |
6687 | break; | |
6688 | default: | |
6689 | return -EINVAL; | |
6690 | } | |
6691 | return 0; | |
6692 | } | |
6693 | ||
6694 | static int sec_usb_get_property(struct power_supply *psy, | |
6695 | enum power_supply_property psp, | |
6696 | union power_supply_propval *val) | |
6697 | { | |
6698 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
6699 | ||
9782eb9b JC |
6700 | switch (psp) { |
6701 | case POWER_SUPPLY_PROP_ONLINE: | |
6702 | break; | |
6703 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: | |
6704 | /* V -> uV */ | |
6705 | val->intval = battery->input_voltage * 1000000; | |
6706 | return 0; | |
6707 | case POWER_SUPPLY_PROP_CURRENT_MAX: | |
6708 | /* mA -> uA */ | |
6709 | val->intval = battery->pdata->charging_current[battery->cable_type].input_current_limit * 1000; | |
6710 | return 0; | |
6711 | default: | |
1cac41cb | 6712 | return -EINVAL; |
9782eb9b | 6713 | } |
1cac41cb MB |
6714 | |
6715 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERVOLTAGE) || | |
6716 | (battery->health == POWER_SUPPLY_HEALTH_UNDERVOLTAGE)) { | |
6717 | val->intval = 0; | |
6718 | return 0; | |
6719 | } | |
6720 | /* Set enable=1 only if the USB charger is connected */ | |
6721 | switch (battery->wire_status) { | |
6722 | case SEC_BATTERY_CABLE_USB: | |
6723 | case SEC_BATTERY_CABLE_USB_CDP: | |
6724 | val->intval = 1; | |
6725 | break; | |
6726 | case SEC_BATTERY_CABLE_PDIC: | |
6727 | val->intval = (battery->pd_usb_attached) ? 1:0; | |
6728 | break; | |
6729 | default: | |
6730 | val->intval = 0; | |
6731 | break; | |
6732 | } | |
6733 | ||
6734 | if (battery->slate_mode) | |
6735 | val->intval = 0; | |
6736 | return 0; | |
6737 | } | |
6738 | ||
6739 | static int sec_ac_get_property(struct power_supply *psy, | |
6740 | enum power_supply_property psp, | |
6741 | union power_supply_propval *val) | |
6742 | { | |
6743 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
ca34248d | 6744 | enum power_supply_ext_property ext_psp = (enum power_supply_ext_property) psp; |
1cac41cb MB |
6745 | |
6746 | switch (psp) { | |
6747 | case POWER_SUPPLY_PROP_ONLINE: | |
6748 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERVOLTAGE) || | |
6749 | (battery->health == POWER_SUPPLY_HEALTH_UNDERVOLTAGE)) { | |
6750 | val->intval = 0; | |
6751 | return 0; | |
6752 | } | |
6753 | ||
6754 | /* Set enable=1 only if the AC charger is connected */ | |
6755 | switch (battery->cable_type) { | |
6756 | case SEC_BATTERY_CABLE_TA: | |
6757 | case SEC_BATTERY_CABLE_UARTOFF: | |
6758 | case SEC_BATTERY_CABLE_LAN_HUB: | |
6759 | case SEC_BATTERY_CABLE_UNKNOWN: | |
6760 | case SEC_BATTERY_CABLE_PREPARE_TA: | |
6761 | case SEC_BATTERY_CABLE_9V_ERR: | |
6762 | case SEC_BATTERY_CABLE_9V_UNKNOWN: | |
6763 | case SEC_BATTERY_CABLE_9V_TA: | |
6764 | case SEC_BATTERY_CABLE_12V_TA: | |
6765 | case SEC_BATTERY_CABLE_HMT_CONNECTED: | |
6766 | case SEC_BATTERY_CABLE_HMT_CHARGE: | |
6767 | case SEC_BATTERY_CABLE_HV_TA_CHG_LIMIT: | |
6768 | case SEC_BATTERY_CABLE_QC20: | |
6769 | case SEC_BATTERY_CABLE_QC30: | |
6770 | case SEC_BATTERY_CABLE_TIMEOUT: | |
6771 | case SEC_BATTERY_CABLE_SMART_OTG: | |
6772 | case SEC_BATTERY_CABLE_SMART_NOTG: | |
6773 | val->intval = 1; | |
6774 | break; | |
6775 | case SEC_BATTERY_CABLE_PDIC: | |
6776 | val->intval = (battery->pd_usb_attached) ? 0:1; | |
6777 | break; | |
6778 | default: | |
6779 | val->intval = 0; | |
6780 | break; | |
6781 | } | |
6782 | break; | |
6783 | case POWER_SUPPLY_PROP_TEMP: | |
6784 | val->intval = battery->chg_temp; | |
6785 | break; | |
9782eb9b JC |
6786 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: |
6787 | /* V -> uV */ | |
6788 | val->intval = battery->input_voltage * 1000000; | |
6789 | return 0; | |
6790 | case POWER_SUPPLY_PROP_CURRENT_MAX: | |
6791 | /* mA -> uA */ | |
6792 | val->intval = battery->pdata->charging_current[battery->cable_type].input_current_limit * 1000; | |
6793 | return 0; | |
1cac41cb MB |
6794 | case POWER_SUPPLY_PROP_MAX ... POWER_SUPPLY_EXT_PROP_MAX: |
6795 | switch (ext_psp) { | |
6796 | case POWER_SUPPLY_EXT_PROP_WATER_DETECT: | |
6797 | if (battery->misc_event & (BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE | | |
6798 | BATT_MISC_EVENT_HICCUP_TYPE)) { | |
6799 | val->intval = 1; | |
6800 | pr_info("%s: Water Detect\n", __func__); | |
6801 | } else { | |
6802 | val->intval = 0; | |
6803 | } | |
6804 | break; | |
6805 | default: | |
6806 | return -EINVAL; | |
6807 | } | |
6808 | break; | |
6809 | default: | |
6810 | return -EINVAL; | |
6811 | } | |
6812 | ||
6813 | if (lpcharge && (battery->misc_event & BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE)) { | |
6814 | val->intval = 1; | |
6815 | } | |
6816 | ||
6817 | return 0; | |
6818 | } | |
6819 | ||
6820 | static int sec_wireless_get_property(struct power_supply *psy, | |
6821 | enum power_supply_property psp, | |
6822 | union power_supply_propval *val) | |
6823 | { | |
6824 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
6825 | ||
6826 | switch (psp) { | |
6827 | case POWER_SUPPLY_PROP_ONLINE: | |
6828 | val->intval = is_wireless_type(battery->cable_type) ? | |
6829 | 1 : 0; | |
6830 | break; | |
6831 | case POWER_SUPPLY_PROP_PRESENT: | |
6832 | val->intval = (battery->pdata->wireless_charger_name) ? | |
6833 | 1 : 0; | |
6834 | break; | |
9782eb9b JC |
6835 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: |
6836 | /* V -> uV */ | |
6837 | val->intval = battery->input_voltage * 1000000; | |
6838 | return 0; | |
6839 | case POWER_SUPPLY_PROP_CURRENT_MAX: | |
6840 | /* mA -> uA */ | |
6841 | val->intval = battery->pdata->charging_current[battery->cable_type].input_current_limit * 1000; | |
6842 | return 0; | |
1cac41cb MB |
6843 | default: |
6844 | return -EINVAL; | |
6845 | } | |
6846 | ||
6847 | return 0; | |
6848 | } | |
6849 | ||
6850 | static int sec_wireless_set_property(struct power_supply *psy, | |
6851 | enum power_supply_property psp, | |
6852 | const union power_supply_propval *val) | |
6853 | { | |
6854 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
8ff4a2b5 | 6855 | enum power_supply_ext_property ext_psp = (enum power_supply_ext_property) psp; |
1cac41cb MB |
6856 | |
6857 | switch (psp) { | |
6858 | case POWER_SUPPLY_PROP_ONLINE: | |
6859 | #if defined(CONFIG_BATTERY_CISD) | |
6860 | if (val->intval != SEC_WIRELESS_PAD_NONE && battery->wc_status == SEC_WIRELESS_PAD_NONE) { | |
6861 | battery->cisd.data[CISD_DATA_WIRELESS_COUNT]++; | |
6862 | battery->cisd.data[CISD_DATA_WIRELESS_COUNT_PER_DAY]++; | |
6863 | } | |
6864 | #endif | |
6865 | /* Clear the FOD State */ | |
6866 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_WIRELESS_FOD, 1); | |
6867 | ||
6868 | if (val->intval == SEC_WIRELESS_PAD_A4WP) | |
6869 | battery->wc_status = SEC_WIRELESS_PAD_WPC; | |
6870 | else | |
6871 | battery->wc_status = val->intval; | |
6872 | ||
6873 | if ((battery->ext_event & BATT_EXT_EVENT_CALL) && | |
6874 | (battery->wc_status == SEC_WIRELESS_PAD_WPC_PACK || | |
6875 | battery->wc_status == SEC_WIRELESS_PAD_WPC_PACK_HV || | |
6876 | battery->wc_status == SEC_WIRELESS_PAD_TX)) { | |
6877 | battery->wc_rx_phm_mode = true; | |
6878 | } | |
6879 | ||
6880 | wake_lock(&battery->cable_wake_lock); | |
6881 | queue_delayed_work(battery->monitor_wqueue, | |
6882 | &battery->cable_work, 0); | |
6883 | break; | |
6884 | case POWER_SUPPLY_PROP_AUTHENTIC: | |
6885 | #if defined(CONFIG_BATTERY_CISD) | |
6886 | pr_info("%s : tx_type(0x%x)\n", __func__, val->intval); | |
6887 | count_cisd_pad_data(&battery->cisd, val->intval); | |
6888 | #endif | |
6889 | break; | |
6890 | case POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL: | |
6891 | if (val->intval) { | |
6892 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_WPC_VOUT_LOCK, | |
6893 | SEC_BAT_CURRENT_EVENT_WPC_VOUT_LOCK); | |
6894 | } else { | |
6895 | sec_bat_set_current_event(battery, 0, | |
6896 | SEC_BAT_CURRENT_EVENT_WPC_VOUT_LOCK); | |
6897 | } | |
6898 | ||
6899 | if (is_hv_wireless_type(battery->cable_type)) { | |
6900 | union power_supply_propval value = {0, }; | |
6901 | int cnt; | |
6902 | ||
6903 | mutex_lock(&battery->iolock); | |
6904 | value.intval = (val->intval) ? WIRELESS_VOUT_5V : | |
6905 | battery->wpc_vout_level; | |
6906 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
6907 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
6908 | battery->aicl_current = 0; /* reset aicl current */ | |
6909 | mutex_unlock(&battery->iolock); | |
6910 | ||
6911 | for (cnt = 0; cnt < 5; cnt++) { | |
6912 | msleep(100); | |
6913 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
6914 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
6915 | if (value.intval <= 6000) { | |
6916 | pr_info("%s: wireless vout goes to 5V Vout(%d).\n", | |
6917 | __func__, value.intval); | |
6918 | break; | |
6919 | } | |
6920 | } | |
6921 | } | |
6922 | break; | |
6923 | case POWER_SUPPLY_PROP_CURRENT_MAX: | |
6924 | battery->aicl_current = 0; /* reset aicl current */ | |
6925 | pr_info("%s: reset aicl\n", __func__); | |
6926 | break; | |
6927 | case POWER_SUPPLY_PROP_MAX ... POWER_SUPPLY_EXT_PROP_MAX: | |
6928 | switch (ext_psp) { | |
6929 | case POWER_SUPPLY_EXT_PROP_WIRELESS_TX_CHG_ERR: | |
6930 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_WIRELESS_FOD, !val->intval); | |
6931 | break; | |
6932 | case POWER_SUPPLY_EXT_PROP_CALL_EVENT: | |
6933 | if(val->intval == 1) { | |
6934 | pr_info("%s : PHM enabled\n",__func__); | |
6935 | battery->wc_rx_phm_mode = true; | |
6936 | } | |
6937 | break; | |
6938 | default: | |
6939 | return -EINVAL; | |
6940 | } | |
6941 | break; | |
6942 | default: | |
6943 | return -EINVAL; | |
6944 | } | |
6945 | ||
6946 | return 0; | |
6947 | } | |
6948 | ||
6949 | static int sec_ps_set_property(struct power_supply *psy, | |
6950 | enum power_supply_property psp, | |
6951 | const union power_supply_propval *val) | |
6952 | { | |
6953 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
6954 | union power_supply_propval value; | |
6955 | ||
6956 | switch (psp) { | |
6957 | case POWER_SUPPLY_PROP_STATUS: | |
6958 | if (val->intval == 0 && battery->ps_enable == true) { | |
6959 | battery->ps_enable = false; | |
6960 | value.intval = val->intval; | |
6961 | psy_do_property(battery->pdata->charger_name, set, | |
6962 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
6963 | } else if ((val->intval == 1) && (battery->ps_enable == false) && | |
6964 | (battery->ps_status == true)) { | |
6965 | battery->ps_enable = true; | |
6966 | value.intval = val->intval; | |
6967 | psy_do_property(battery->pdata->charger_name, set, | |
6968 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
6969 | } else { | |
6970 | dev_err(battery->dev, | |
6971 | "%s: invalid setting (%d)\n", __func__, val->intval); | |
6972 | } | |
6973 | break; | |
6974 | case POWER_SUPPLY_PROP_ONLINE: | |
6975 | if (val->intval == SEC_BATTERY_CABLE_POWER_SHARING) { | |
6976 | battery->ps_status = true; | |
6977 | battery->ps_enable = true; | |
6978 | value.intval = battery->ps_enable; | |
6979 | psy_do_property(battery->pdata->charger_name, set, | |
6980 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
6981 | } else { | |
6982 | battery->ps_status = false; | |
6983 | battery->ps_enable = false; | |
6984 | value.intval = battery->ps_enable; | |
6985 | psy_do_property(battery->pdata->charger_name, set, | |
6986 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
6987 | } | |
6988 | break; | |
6989 | default: | |
6990 | return -EINVAL; | |
6991 | } | |
6992 | ||
6993 | return 0; | |
6994 | } | |
6995 | ||
6996 | static int sec_ps_get_property(struct power_supply *psy, | |
6997 | enum power_supply_property psp, | |
6998 | union power_supply_propval *val) | |
6999 | { | |
7000 | struct sec_battery_info *battery = power_supply_get_drvdata(psy); | |
7001 | ||
7002 | switch (psp) { | |
7003 | case POWER_SUPPLY_PROP_STATUS: | |
7004 | val->intval = (battery->ps_enable) ? 1 : 0; | |
7005 | break; | |
7006 | case POWER_SUPPLY_PROP_ONLINE: | |
7007 | val->intval = (battery->ps_status) ? 1 : 0; | |
7008 | break; | |
7009 | default: | |
7010 | return -EINVAL; | |
7011 | } | |
7012 | ||
7013 | return 0; | |
7014 | } | |
7015 | ||
7016 | #if defined(CONFIG_USB_TYPEC_MANAGER_NOTIFIER) || defined(CONFIG_MUIC_NOTIFIER) | |
7017 | static int sec_bat_cable_check(struct sec_battery_info *battery, | |
7018 | muic_attached_dev_t attached_dev) | |
7019 | { | |
7020 | int current_cable_type = -1; | |
7021 | union power_supply_propval val = {0, }; | |
7022 | ||
7023 | pr_info("[%s]ATTACHED(%d)\n", __func__, attached_dev); | |
7024 | ||
7025 | switch (attached_dev) | |
7026 | { | |
7027 | case ATTACHED_DEV_JIG_UART_OFF_MUIC: | |
7028 | case ATTACHED_DEV_JIG_UART_ON_MUIC: | |
7029 | battery->is_jig_on = true; | |
7030 | #if defined(CONFIG_BATTERY_CISD) | |
7031 | battery->skip_cisd = true; | |
7032 | #endif | |
7033 | case ATTACHED_DEV_SMARTDOCK_MUIC: | |
7034 | case ATTACHED_DEV_DESKDOCK_MUIC: | |
7035 | case ATTACHED_DEV_JIG_USB_ON_MUIC: | |
7036 | current_cable_type = SEC_BATTERY_CABLE_NONE; | |
7037 | break; | |
7038 | case ATTACHED_DEV_UNDEFINED_CHARGING_MUIC: | |
7039 | case ATTACHED_DEV_UNDEFINED_RANGE_MUIC: | |
7040 | current_cable_type = SEC_BATTERY_CABLE_NONE; | |
7041 | #if defined(CONFIG_BATTERY_CISD) | |
7042 | battery->cisd.data[CISD_DATA_WATER_DETECT]++; | |
7043 | battery->cisd.data[CISD_DATA_WATER_DETECT_PER_DAY]++; | |
7044 | #endif | |
7045 | #if defined(CONFIG_SEC_ABC) | |
7046 | sec_abc_send_event("MODULE=battery@ERROR=water_detect"); | |
7047 | #endif | |
7048 | break; | |
7049 | case ATTACHED_DEV_OTG_MUIC: | |
7050 | case ATTACHED_DEV_JIG_UART_OFF_VB_OTG_MUIC: | |
7051 | case ATTACHED_DEV_HMT_MUIC: | |
7052 | current_cable_type = SEC_BATTERY_CABLE_OTG; | |
7053 | break; | |
7054 | case ATTACHED_DEV_TIMEOUT_OPEN_MUIC: | |
7055 | current_cable_type = SEC_BATTERY_CABLE_TIMEOUT; | |
7056 | break; | |
7057 | case ATTACHED_DEV_USB_MUIC: | |
7058 | case ATTACHED_DEV_JIG_USB_OFF_MUIC: | |
7059 | case ATTACHED_DEV_SMARTDOCK_USB_MUIC: | |
7060 | case ATTACHED_DEV_UNOFFICIAL_ID_USB_MUIC: | |
7061 | current_cable_type = SEC_BATTERY_CABLE_USB; | |
7062 | break; | |
7063 | case ATTACHED_DEV_JIG_UART_ON_VB_MUIC: | |
7064 | case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC: | |
7065 | case ATTACHED_DEV_JIG_UART_OFF_VB_FG_MUIC: | |
7066 | current_cable_type = SEC_BATTERY_CABLE_UARTOFF; | |
7067 | break; | |
7068 | case ATTACHED_DEV_RDU_TA_MUIC: | |
7069 | battery->store_mode = true; | |
7070 | wake_lock(&battery->parse_mode_dt_wake_lock); | |
7071 | queue_delayed_work(battery->monitor_wqueue, &battery->parse_mode_dt_work, 0); | |
7072 | case ATTACHED_DEV_TA_MUIC: | |
7073 | case ATTACHED_DEV_CARDOCK_MUIC: | |
7074 | case ATTACHED_DEV_DESKDOCK_VB_MUIC: | |
7075 | case ATTACHED_DEV_SMARTDOCK_TA_MUIC: | |
7076 | case ATTACHED_DEV_UNOFFICIAL_TA_MUIC: | |
7077 | case ATTACHED_DEV_UNOFFICIAL_ID_TA_MUIC: | |
7078 | case ATTACHED_DEV_UNOFFICIAL_ID_ANY_MUIC: | |
7079 | case ATTACHED_DEV_UNSUPPORTED_ID_VB_MUIC: | |
7080 | current_cable_type = SEC_BATTERY_CABLE_TA; | |
7081 | break; | |
7082 | case ATTACHED_DEV_AFC_CHARGER_5V_MUIC: | |
7083 | case ATTACHED_DEV_QC_CHARGER_5V_MUIC: | |
7084 | case ATTACHED_DEV_AFC_CHARGER_5V_DUPLI_MUIC: | |
7085 | if (is_hv_wire_type(battery->cable_type) && | |
7086 | (battery->chg_limit || battery->vbus_chg_by_siop)) { | |
7087 | current_cable_type = SEC_BATTERY_CABLE_HV_TA_CHG_LIMIT; | |
7088 | } else if (battery->current_event & SEC_BAT_CURRENT_EVENT_AFC && | |
7089 | battery->pdic_info.sink_status.rp_currentlvl == RP_CURRENT_LEVEL_DEFAULT) { | |
7090 | current_cable_type = SEC_BATTERY_CABLE_PREPARE_TA; | |
7091 | } else { | |
7092 | current_cable_type = SEC_BATTERY_CABLE_TA; | |
7093 | } | |
7094 | break; | |
7095 | case ATTACHED_DEV_CDP_MUIC: | |
7096 | case ATTACHED_DEV_UNOFFICIAL_ID_CDP_MUIC: | |
7097 | current_cable_type = SEC_BATTERY_CABLE_USB_CDP; | |
7098 | break; | |
7099 | case ATTACHED_DEV_USB_LANHUB_MUIC: | |
7100 | current_cable_type = SEC_BATTERY_CABLE_LAN_HUB; | |
7101 | break; | |
7102 | case ATTACHED_DEV_CHARGING_CABLE_MUIC: | |
7103 | current_cable_type = SEC_BATTERY_CABLE_POWER_SHARING; | |
7104 | break; | |
7105 | case ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC: | |
7106 | case ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC: | |
7107 | current_cable_type = SEC_BATTERY_CABLE_PREPARE_TA; | |
7108 | break; | |
7109 | case ATTACHED_DEV_AFC_CHARGER_9V_MUIC: | |
7110 | case ATTACHED_DEV_QC_CHARGER_9V_MUIC: | |
7111 | case ATTACHED_DEV_AFC_CHARGER_9V_DUPLI_MUIC: | |
7112 | current_cable_type = SEC_BATTERY_CABLE_9V_TA; | |
7113 | break; | |
7114 | #if defined(CONFIG_MUIC_HV_12V) | |
7115 | case ATTACHED_DEV_AFC_CHARGER_12V_MUIC: | |
7116 | case ATTACHED_DEV_AFC_CHARGER_12V_DUPLI_MUIC: | |
7117 | current_cable_type = SEC_BATTERY_CABLE_12V_TA; | |
7118 | break; | |
7119 | #endif | |
7120 | case ATTACHED_DEV_AFC_CHARGER_ERR_V_MUIC: | |
7121 | case ATTACHED_DEV_AFC_CHARGER_ERR_V_DUPLI_MUIC: | |
7122 | case ATTACHED_DEV_QC_CHARGER_ERR_V_MUIC: | |
7123 | current_cable_type = SEC_BATTERY_CABLE_9V_ERR; | |
7124 | #if defined(CONFIG_BATTERY_CISD) | |
7125 | battery->cisd.data[CISD_DATA_AFC_FAIL]++; | |
7126 | battery->cisd.data[CISD_DATA_AFC_FAIL_PER_DAY]++; | |
7127 | #endif | |
7128 | #if defined(CONFIG_SEC_ABC) | |
7129 | sec_abc_send_event("MODULE=battery@ERROR=afc_fail"); | |
7130 | #endif | |
7131 | break; | |
7132 | case ATTACHED_DEV_HV_ID_ERR_UNDEFINED_MUIC: | |
7133 | case ATTACHED_DEV_HV_ID_ERR_UNSUPPORTED_MUIC: | |
7134 | case ATTACHED_DEV_HV_ID_ERR_SUPPORTED_MUIC: | |
7135 | current_cable_type = SEC_BATTERY_CABLE_9V_UNKNOWN; | |
7136 | #if defined(CONFIG_BATTERY_CISD) | |
7137 | battery->cisd.data[CISD_DATA_AFC_FAIL]++; | |
7138 | battery->cisd.data[CISD_DATA_AFC_FAIL_PER_DAY]++; | |
7139 | #endif | |
7140 | #if defined(CONFIG_SEC_ABC) | |
7141 | sec_abc_send_event("MODULE=battery@ERROR=afc_fail"); | |
7142 | #endif | |
7143 | break; | |
7144 | case ATTACHED_DEV_VZW_INCOMPATIBLE_MUIC: | |
7145 | current_cable_type = SEC_BATTERY_CABLE_UNKNOWN; | |
7146 | break; | |
7147 | default: | |
7148 | pr_err("%s: invalid type for charger:%d\n", | |
7149 | __func__, attached_dev); | |
7150 | break; | |
7151 | } | |
7152 | ||
7153 | if (battery->is_jig_on && !battery->pdata->support_fgsrc_change) | |
7154 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
7155 | POWER_SUPPLY_PROP_ENERGY_NOW, val); | |
7156 | ||
7157 | return current_cable_type; | |
7158 | } | |
7159 | #endif | |
7160 | ||
7161 | #if defined(CONFIG_USB_TYPEC_MANAGER_NOTIFIER) | |
7162 | #if defined(CONFIG_CCIC_NOTIFIER) | |
7163 | static int sec_bat_get_pd_list_index(PDIC_SINK_STATUS *sink_status, struct sec_bat_pdic_list *pd_list) | |
7164 | { | |
7165 | int i = 0; | |
7166 | ||
7167 | for (i = 0; i < pd_list->max_pd_count; i++) { | |
7168 | if (pd_list->pd_info[i].pdo_index == sink_status->current_pdo_num) | |
7169 | return i; | |
7170 | } | |
7171 | ||
7172 | return 0; | |
7173 | } | |
7174 | ||
7175 | static void sec_bat_set_rp_current(struct sec_battery_info *battery, int cable_type) | |
7176 | { | |
7177 | if (battery->pdic_info.sink_status.rp_currentlvl == RP_CURRENT_LEVEL3) { | |
7178 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_HV_DISABLE) | |
7179 | sec_bat_change_default_current(battery, cable_type, | |
7180 | battery->pdata->default_input_current, battery->pdata->default_charging_current); | |
7181 | else | |
7182 | sec_bat_change_default_current(battery, cable_type, | |
7183 | RP_CURRENT_RP3, battery->pdata->max_charging_current); | |
7184 | } | |
7185 | else if (battery->pdic_info.sink_status.rp_currentlvl == RP_CURRENT_LEVEL2) | |
7186 | sec_bat_change_default_current(battery, cable_type, | |
7187 | RP_CURRENT_RP2, RP_CURRENT_RP2); | |
7188 | else if (cable_type == SEC_BATTERY_CABLE_USB) { | |
7189 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_USB_SUPER) | |
7190 | sec_bat_change_default_current(battery, SEC_BATTERY_CABLE_USB, | |
7191 | USB_CURRENT_SUPER_SPEED, USB_CURRENT_SUPER_SPEED); | |
7192 | else | |
7193 | sec_bat_change_default_current(battery, cable_type, | |
7194 | RP_CURRENT_RP1, RP_CURRENT_RP1); | |
7195 | } | |
7196 | ||
7197 | pr_info("%s:(%d)\n", __func__, battery->pdic_info.sink_status.rp_currentlvl); | |
7198 | battery->max_charge_power = 0; | |
7199 | sec_bat_set_charging_current(battery); | |
7200 | } | |
7201 | #endif | |
7202 | ||
7203 | static int make_pd_list(struct sec_battery_info *battery) | |
7204 | { | |
7205 | int i = 0, j = 0, min = 0, temp_voltage = 0, temp_current = 0, temp_index = 0; | |
7206 | int base_charge_power = 0, selected_pdo_voltage = 0, selected_pdo_num = 0; | |
7207 | int pd_list_index = 0; | |
7208 | int pd_charging_charge_power = battery->current_event & SEC_BAT_CURRENT_EVENT_HV_DISABLE ? | |
7209 | battery->pdata->nv_charge_power : battery->pdata->pd_charging_charge_power; | |
7210 | ||
7211 | for (base_charge_power = pd_charging_charge_power * 1000; | |
7212 | base_charge_power >= 1000000; base_charge_power -= 1000000) | |
7213 | { | |
7214 | selected_pdo_voltage = battery->pdata->max_input_voltage + 1; | |
7215 | selected_pdo_num = 0; | |
7216 | for(i=1; i<= battery->pdic_info.sink_status.available_pdo_num; i++) | |
7217 | { | |
7218 | if (battery->pdic_info.sink_status.power_list[i].max_voltage * | |
7219 | battery->pdic_info.sink_status.power_list[i].max_current > base_charge_power - 1000000 && | |
7220 | battery->pdic_info.sink_status.power_list[i].max_voltage * | |
7221 | battery->pdic_info.sink_status.power_list[i].max_current <= base_charge_power) | |
7222 | { | |
7223 | if (battery->pdic_info.sink_status.power_list[i].max_voltage < selected_pdo_voltage) | |
7224 | { | |
7225 | selected_pdo_voltage = battery->pdic_info.sink_status.power_list[i].max_voltage; | |
7226 | selected_pdo_num = i; | |
7227 | battery->pdic_info.sink_status.power_list[i].max_current = | |
7228 | battery->pdic_info.sink_status.power_list[i].max_current > | |
7229 | battery->pdata->max_input_current ? | |
7230 | battery->pdata->max_input_current : battery->pdic_info.sink_status.power_list[i].max_current; | |
7231 | } | |
7232 | } | |
7233 | } | |
7234 | if (selected_pdo_num) | |
7235 | { | |
7236 | battery->pd_list.pd_info[pd_list_index].input_voltage = | |
7237 | battery->pdic_info.sink_status.power_list[selected_pdo_num].max_voltage; | |
7238 | battery->pd_list.pd_info[pd_list_index].input_current = | |
7239 | battery->pdic_info.sink_status.power_list[selected_pdo_num].max_current; | |
7240 | battery->pd_list.pd_info[pd_list_index].pdo_index = selected_pdo_num; | |
7241 | pd_list_index++; | |
7242 | } | |
7243 | } | |
7244 | pr_info("%s: total pd_list_index: %d\n", __func__, pd_list_index); | |
7245 | if (pd_list_index <= 0) { | |
7246 | pr_info("%s : PDO list is empty!!\n", __func__); | |
7247 | return 0; | |
7248 | } | |
7249 | ||
7250 | for (i = 0; i < pd_list_index - 1; i++) { | |
7251 | min = i; | |
7252 | for (j = i + 1; j < pd_list_index; j++) { | |
7253 | if (battery->pd_list.pd_info[j].input_voltage < | |
7254 | battery->pd_list.pd_info[min].input_voltage) | |
7255 | min = j; | |
7256 | } | |
7257 | temp_voltage = battery->pd_list.pd_info[i].input_voltage; | |
7258 | battery->pd_list.pd_info[i].input_voltage = | |
7259 | battery->pd_list.pd_info[min].input_voltage; | |
7260 | battery->pd_list.pd_info[min].input_voltage = temp_voltage; | |
7261 | temp_current = battery->pd_list.pd_info[i].input_current; | |
7262 | battery->pd_list.pd_info[i].input_current = | |
7263 | battery->pd_list.pd_info[min].input_current; | |
7264 | battery->pd_list.pd_info[min].input_current = temp_current; | |
7265 | temp_index = battery->pd_list.pd_info[i].pdo_index; | |
7266 | battery->pd_list.pd_info[i].pdo_index = | |
7267 | battery->pd_list.pd_info[min].pdo_index; | |
7268 | battery->pd_list.pd_info[min].pdo_index = temp_index; | |
7269 | } | |
7270 | for(i = 0; i < pd_list_index; i++) { | |
7271 | pr_info("%s: Made pd_list[%d], voltage : %d, current : %d, index : %d\n", __func__, i, | |
7272 | battery->pd_list.pd_info[i].input_voltage, | |
7273 | battery->pd_list.pd_info[i].input_current, | |
7274 | battery->pd_list.pd_info[i].pdo_index); | |
7275 | } | |
7276 | battery->pd_list.max_pd_count = pd_list_index; | |
7277 | battery->max_charge_power = battery->pdic_info.sink_status.power_list[ \ | |
7278 | battery->pd_list.pd_info[pd_list_index-1].pdo_index].max_voltage * \ | |
7279 | battery->pdic_info.sink_status.power_list[battery->pd_list.pd_info[ \ | |
7280 | pd_list_index-1].pdo_index].max_current / 1000; | |
7281 | battery->pd_max_charge_power = battery->max_charge_power; | |
7282 | ||
7283 | if (battery->pdic_info.sink_status.selected_pdo_num == battery->pd_list.pd_info[pd_list_index-1].pdo_index) { | |
7284 | battery->pd_list.now_pd_index = pd_list_index - 1; | |
7285 | battery->pdic_ps_rdy = true; | |
7286 | dev_info(battery->dev, "%s: battery->pdic_ps_rdy(%d)\n", __func__, battery->pdic_ps_rdy); | |
7287 | } else { | |
7288 | /* change input current before request new pdo if new pdo's input current is less than now */ | |
7289 | if (battery->pd_list.pd_info[pd_list_index-1].input_current < battery->input_current) { | |
7290 | union power_supply_propval value = {0, }; | |
7291 | int input_current = battery->pd_list.pd_info[pd_list_index-1].input_current; | |
7292 | ||
7293 | value.intval = input_current; | |
7294 | battery->input_current = input_current; | |
7295 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_SELECT_PDO, | |
7296 | SEC_BAT_CURRENT_EVENT_SELECT_PDO); | |
7297 | psy_do_property(battery->pdata->charger_name, set, | |
7298 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
7299 | } | |
7300 | battery->pdic_ps_rdy = false; | |
7301 | select_pdo(battery->pd_list.pd_info[pd_list_index-1].pdo_index); | |
7302 | } | |
7303 | ||
7304 | return battery->pd_list.max_pd_count; | |
7305 | } | |
7306 | ||
7307 | static int usb_typec_handle_notification(struct notifier_block *nb, | |
7308 | unsigned long action, void *data) | |
7309 | { | |
7310 | const char *cmd; | |
7311 | struct sec_battery_info *battery = | |
7312 | container_of(nb, struct sec_battery_info, usb_typec_nb); | |
7313 | int cable_type = SEC_BATTERY_CABLE_NONE, i = 0, current_pdo = 0; | |
7314 | int pd_charging_charge_power = battery->current_event & SEC_BAT_CURRENT_EVENT_HV_DISABLE ? | |
7315 | battery->pdata->nv_charge_power : battery->pdata->pd_charging_charge_power; | |
7316 | CC_NOTI_ATTACH_TYPEDEF usb_typec_info = *(CC_NOTI_ATTACH_TYPEDEF *)data; | |
7317 | ||
7318 | dev_info(battery->dev, "%s: action (%ld) dump(0x%01x, 0x%01x, 0x%02x, 0x%04x, 0x%04x, 0x%04x)\n", | |
7319 | __func__, action, usb_typec_info.src, usb_typec_info.dest, usb_typec_info.id, | |
7320 | usb_typec_info.attach, usb_typec_info.rprd, usb_typec_info.cable_type); | |
7321 | ||
7322 | if (usb_typec_info.dest != CCIC_NOTIFY_DEV_BATTERY) { | |
7323 | dev_info(battery->dev, "%s: skip handler dest(%d)\n", | |
7324 | __func__, usb_typec_info.dest); | |
7325 | return 0; | |
7326 | } | |
7327 | ||
7328 | mutex_lock(&battery->typec_notylock); | |
7329 | switch (usb_typec_info.id) { | |
7330 | case CCIC_NOTIFY_ID_WATER: | |
7331 | case CCIC_NOTIFY_ID_ATTACH: | |
7332 | switch (usb_typec_info.attach) { | |
7333 | case MUIC_NOTIFY_CMD_DETACH: | |
7334 | case MUIC_NOTIFY_CMD_LOGICALLY_DETACH: | |
7335 | cmd = "DETACH"; | |
7336 | battery->is_jig_on = false; | |
7337 | battery->pd_usb_attached = false; | |
7338 | cable_type = SEC_BATTERY_CABLE_NONE; | |
7339 | battery->muic_cable_type = ATTACHED_DEV_NONE_MUIC; | |
7340 | battery->pdic_info.sink_status.rp_currentlvl = RP_CURRENT_LEVEL_NONE; | |
7341 | break; | |
7342 | case MUIC_NOTIFY_CMD_ATTACH: | |
7343 | case MUIC_NOTIFY_CMD_LOGICALLY_ATTACH: | |
7344 | /* Skip notify from MUIC if PDIC is attached already */ | |
7345 | if (battery->wire_status == SEC_BATTERY_CABLE_PDIC) { | |
7346 | mutex_unlock(&battery->typec_notylock); | |
7347 | return 0; | |
7348 | } | |
7349 | cmd = "ATTACH"; | |
7350 | battery->muic_cable_type = usb_typec_info.cable_type; | |
7351 | cable_type = sec_bat_cable_check(battery, battery->muic_cable_type); | |
7352 | if (battery->cable_type != cable_type && | |
7353 | battery->pdic_info.sink_status.rp_currentlvl >= RP_CURRENT_LEVEL_DEFAULT && | |
7354 | (cable_type == SEC_BATTERY_CABLE_USB || cable_type == SEC_BATTERY_CABLE_TA)) { | |
7355 | sec_bat_set_rp_current(battery, cable_type); | |
7356 | } else if ((struct pdic_notifier_struct *)usb_typec_info.pd != NULL && | |
7357 | (*(struct pdic_notifier_struct *)usb_typec_info.pd).event == PDIC_NOTIFY_EVENT_CCIC_ATTACH && | |
7358 | (*(struct pdic_notifier_struct *)usb_typec_info.pd).sink_status.rp_currentlvl >= RP_CURRENT_LEVEL_DEFAULT && | |
7359 | (cable_type == SEC_BATTERY_CABLE_USB || cable_type == SEC_BATTERY_CABLE_TA)) { | |
7360 | battery->pdic_info.sink_status.rp_currentlvl = | |
7361 | (*(struct pdic_notifier_struct *)usb_typec_info.pd).sink_status.rp_currentlvl; | |
7362 | sec_bat_set_rp_current(battery, cable_type); | |
7363 | } | |
7364 | break; | |
7365 | default: | |
7366 | cmd = "ERROR"; | |
7367 | cable_type = -1; | |
7368 | battery->muic_cable_type = usb_typec_info.cable_type; | |
7369 | break; | |
7370 | } | |
7371 | battery->pdic_attach = false; | |
7372 | battery->pdic_ps_rdy = false; | |
7373 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
7374 | if (battery->muic_cable_type == ATTACHED_DEV_QC_CHARGER_9V_MUIC || | |
7375 | battery->muic_cable_type == ATTACHED_DEV_QC_CHARGER_ERR_V_MUIC) | |
7376 | battery->hv_chg_name = "QC"; | |
7377 | else if (battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_9V_MUIC || | |
7378 | battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_9V_DUPLI_MUIC || | |
7379 | battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_ERR_V_MUIC || | |
7380 | battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_ERR_V_DUPLI_MUIC) | |
7381 | battery->hv_chg_name = "AFC"; | |
7382 | #if defined(CONFIG_MUIC_HV_12V) | |
7383 | else if (battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_12V_MUIC || | |
7384 | battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_12V_DUPLI_MUIC) | |
7385 | battery->hv_chg_name = "12V"; | |
7386 | #endif | |
7387 | else | |
7388 | battery->hv_chg_name = "NONE"; | |
7389 | #endif | |
7390 | break; | |
7391 | case CCIC_NOTIFY_ID_POWER_STATUS: | |
7392 | #ifdef CONFIG_SEC_FACTORY | |
7393 | dev_info(battery->dev, "%s: pd_event(%d)\n", __func__, | |
7394 | (*(struct pdic_notifier_struct *)usb_typec_info.pd).event); | |
7395 | #endif | |
7396 | if ((*(struct pdic_notifier_struct *)usb_typec_info.pd).event == PDIC_NOTIFY_EVENT_DETACH){ | |
7397 | dev_info(battery->dev, "%s: skip pd operation - attach(%d)\n", __func__, usb_typec_info.attach); | |
7398 | battery->pdic_attach = false; | |
7399 | battery->pdic_ps_rdy = false; | |
7400 | battery->pd_list.now_pd_index = 0; | |
7401 | mutex_unlock(&battery->typec_notylock); | |
7402 | return 0; | |
7403 | } | |
7404 | ||
7405 | cmd = "PD_ATTACH"; | |
7406 | if ((*(struct pdic_notifier_struct *)usb_typec_info.pd).event == PDIC_NOTIFY_EVENT_CCIC_ATTACH) { | |
7407 | battery->pdic_info.sink_status.rp_currentlvl = | |
7408 | (*(struct pdic_notifier_struct *)usb_typec_info.pd).sink_status.rp_currentlvl; | |
7409 | dev_info(battery->dev, "%s: battery->rp_currentlvl(%d)\n", __func__, battery->pdic_info.sink_status.rp_currentlvl); | |
7410 | if (battery->wire_status == SEC_BATTERY_CABLE_USB || battery->wire_status == SEC_BATTERY_CABLE_TA) { | |
7411 | cable_type = battery->wire_status; | |
7412 | battery->chg_limit = false; | |
7413 | sec_bat_set_rp_current(battery, cable_type); | |
7414 | goto skip_cable_check; | |
7415 | } | |
7416 | mutex_unlock(&battery->typec_notylock); | |
7417 | return 0; | |
7418 | } | |
7419 | if ((*(struct pdic_notifier_struct *)usb_typec_info.pd).event == PDIC_NOTIFY_EVENT_PD_SINK_CAP) | |
7420 | battery->pdic_attach = false; | |
7421 | if (!battery->pdic_attach) { | |
7422 | battery->pdic_info = *(struct pdic_notifier_struct *)usb_typec_info.pd; | |
7423 | battery->pd_list.now_pd_index = 0; | |
7424 | } else { | |
7425 | battery->pdic_info.sink_status.selected_pdo_num = | |
7426 | (*(struct pdic_notifier_struct *)usb_typec_info.pd).sink_status.selected_pdo_num; | |
7427 | battery->pdic_info.sink_status.current_pdo_num = | |
7428 | (*(struct pdic_notifier_struct *)usb_typec_info.pd).sink_status.current_pdo_num; | |
7429 | battery->pd_list.now_pd_index = sec_bat_get_pd_list_index(&battery->pdic_info.sink_status, | |
7430 | &battery->pd_list); | |
7431 | battery->pdic_ps_rdy = true; | |
7432 | dev_info(battery->dev, "%s: battery->pdic_ps_rdy(%d)\n", __func__, battery->pdic_ps_rdy); | |
7433 | } | |
7434 | current_pdo = battery->pdic_info.sink_status.current_pdo_num; | |
7435 | cable_type = SEC_BATTERY_CABLE_PDIC; | |
7436 | battery->muic_cable_type = ATTACHED_DEV_NONE_MUIC; | |
7437 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
7438 | battery->hv_chg_name = "PDIC"; | |
7439 | #endif | |
7440 | battery->input_voltage = | |
7441 | battery->pdic_info.sink_status.power_list[current_pdo].max_voltage / 1000; | |
7442 | dev_info(battery->dev, "%s: available pdo : %d, current pdo : %d\n", __func__, | |
7443 | battery->pdic_info.sink_status.available_pdo_num, current_pdo); | |
7444 | ||
7445 | for(i=1; i<= battery->pdic_info.sink_status.available_pdo_num; i++) { | |
7446 | pr_info("%s: power_list[%d], voltage : %d, current : %d, power : %d\n", __func__, i, | |
7447 | battery->pdic_info.sink_status.power_list[i].max_voltage, | |
7448 | battery->pdic_info.sink_status.power_list[i].max_current, | |
7449 | battery->pdic_info.sink_status.power_list[i].max_voltage * | |
7450 | battery->pdic_info.sink_status.power_list[i].max_current); | |
7451 | ||
7452 | if ((battery->pdic_info.sink_status.power_list[i].max_voltage * | |
7453 | battery->pdic_info.sink_status.power_list[i].max_current) > | |
7454 | (pd_charging_charge_power * 1000)) { | |
7455 | battery->pdic_info.sink_status.power_list[i].max_current = | |
7456 | (pd_charging_charge_power * 1000) / | |
7457 | battery->pdic_info.sink_status.power_list[i].max_voltage; | |
7458 | ||
7459 | pr_info("%s: ->updated [%d], voltage : %d, current : %d, power : %d\n", __func__, i, | |
7460 | battery->pdic_info.sink_status.power_list[i].max_voltage, | |
7461 | battery->pdic_info.sink_status.power_list[i].max_current, | |
7462 | battery->pdic_info.sink_status.power_list[i].max_voltage * | |
7463 | battery->pdic_info.sink_status.power_list[i].max_current); | |
7464 | } | |
7465 | ||
7466 | } | |
7467 | if (!battery->pdic_attach) { | |
7468 | if (make_pd_list(battery) <= 0) | |
7469 | goto skip_cable_work; | |
7470 | } | |
7471 | battery->pdic_attach = true; | |
7472 | break; | |
7473 | case CCIC_NOTIFY_ID_USB: | |
7474 | if(usb_typec_info.cable_type == PD_USB_TYPE) | |
7475 | battery->pd_usb_attached = true; | |
7476 | dev_info(battery->dev, "%s: CCIC_NOTIFY_ID_USB: %d\n",__func__, battery->pd_usb_attached); | |
7477 | wake_lock(&battery->monitor_wake_lock); | |
7478 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
7479 | mutex_unlock(&battery->typec_notylock); | |
7480 | return 0; | |
7481 | default: | |
7482 | cmd = "ERROR"; | |
7483 | cable_type = -1; | |
7484 | battery->muic_cable_type = ATTACHED_DEV_NONE_MUIC; | |
7485 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
7486 | battery->hv_chg_name = "NONE"; | |
7487 | #endif | |
7488 | break; | |
7489 | } | |
7490 | ||
7491 | skip_cable_check: | |
7492 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE, | |
7493 | (battery->muic_cable_type != ATTACHED_DEV_UNDEFINED_CHARGING_MUIC) && | |
7494 | (battery->muic_cable_type != ATTACHED_DEV_UNDEFINED_RANGE_MUIC)); | |
7495 | ||
7496 | /* showing charging icon and noti(no sound, vi, haptic) only | |
7497 | if slow insertion is detected by MUIC */ | |
7498 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_TIMEOUT_OPEN_TYPE, | |
7499 | (battery->muic_cable_type != ATTACHED_DEV_TIMEOUT_OPEN_MUIC)); | |
7500 | ||
7501 | if (cable_type < 0 || cable_type > SEC_BATTERY_CABLE_MAX) { | |
7502 | dev_info(battery->dev, "%s: ignore event(%d)\n", | |
7503 | __func__, battery->muic_cable_type); | |
7504 | goto skip_cable_work; | |
7505 | } else if ((cable_type == SEC_BATTERY_CABLE_UNKNOWN) && | |
7506 | (battery->status != POWER_SUPPLY_STATUS_DISCHARGING)) { | |
7507 | battery->cable_type = cable_type; | |
7508 | wake_lock(&battery->monitor_wake_lock); | |
7509 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
7510 | dev_info(battery->dev, "%s: UNKNOWN cable plugin\n", __func__); | |
7511 | goto skip_cable_work; | |
7512 | } | |
7513 | battery->wire_status = cable_type; | |
7514 | ||
7515 | cancel_delayed_work(&battery->cable_work); | |
7516 | wake_unlock(&battery->cable_wake_lock); | |
7517 | ||
7518 | if (cable_type == SEC_BATTERY_CABLE_HV_TA_CHG_LIMIT) { | |
7519 | /* set current event */ | |
7520 | cancel_delayed_work(&battery->afc_work); | |
7521 | wake_unlock(&battery->afc_wake_lock); | |
7522 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_CHG_LIMIT, | |
7523 | (SEC_BAT_CURRENT_EVENT_CHG_LIMIT | SEC_BAT_CURRENT_EVENT_AFC)); | |
7524 | wake_lock(&battery->monitor_wake_lock); | |
7525 | battery->polling_count = 1; /* initial value = 1 */ | |
7526 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
7527 | } else if ((battery->wire_status == battery->cable_type) && | |
7528 | (((battery->wire_status == SEC_BATTERY_CABLE_USB || battery->wire_status == SEC_BATTERY_CABLE_TA) && | |
7529 | battery->pdic_info.sink_status.rp_currentlvl > RP_CURRENT_LEVEL_DEFAULT) || | |
7530 | is_hv_wire_type(battery->wire_status))) { | |
7531 | cancel_delayed_work(&battery->afc_work); | |
7532 | wake_unlock(&battery->afc_wake_lock); | |
7533 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_AFC); | |
7534 | ||
7535 | wake_lock(&battery->monitor_wake_lock); | |
7536 | battery->polling_count = 1; /* initial value = 1 */ | |
7537 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
7538 | } else if (cable_type == SEC_BATTERY_CABLE_PREPARE_TA) { | |
7539 | wake_lock(&battery->cable_wake_lock); | |
7540 | queue_delayed_work(battery->monitor_wqueue, | |
7541 | &battery->cable_work, msecs_to_jiffies(500)); | |
7542 | } else { | |
7543 | wake_lock(&battery->cable_wake_lock); | |
7544 | queue_delayed_work(battery->monitor_wqueue, | |
7545 | &battery->cable_work, 0); | |
7546 | } | |
7547 | ||
7548 | skip_cable_work: | |
7549 | dev_info(battery->dev, "%s: CMD[%s], CABLE_TYPE[%d]\n", __func__, cmd, cable_type); | |
7550 | mutex_unlock(&battery->typec_notylock); | |
7551 | return 0; | |
7552 | } | |
7553 | #else | |
7554 | #if defined(CONFIG_CCIC_NOTIFIER) | |
7555 | static int batt_pdic_handle_notification(struct notifier_block *nb, | |
7556 | unsigned long action, void *data) | |
7557 | { | |
7558 | const char *cmd; | |
7559 | struct sec_battery_info *battery = | |
7560 | container_of(nb, struct sec_battery_info, | |
7561 | pdic_nb); | |
7562 | battery->pdic_info = *(struct pdic_notifier_struct *)data; | |
7563 | ||
7564 | mutex_lock(&battery->batt_handlelock); | |
7565 | pr_info("%s: pdic_event: %d\n", __func__, battery->pdic_info.event); | |
7566 | ||
7567 | switch (battery->pdic_info.event) { | |
7568 | int i, selected_pdo; | |
7569 | ||
7570 | case PDIC_NOTIFY_EVENT_DETACH: | |
7571 | cmd = "DETACH"; | |
7572 | battery->pdic_attach = false; | |
7573 | if (battery->wire_status == SEC_BATTERY_CABLE_PDIC) { | |
7574 | battery->wire_status = SEC_BATTERY_CABLE_NONE; | |
7575 | wake_lock(&battery->cable_wake_lock); | |
7576 | queue_delayed_work(battery->monitor_wqueue, | |
7577 | &battery->cable_work, 0); | |
7578 | } | |
7579 | break; | |
7580 | case PDIC_NOTIFY_EVENT_CCIC_ATTACH: | |
7581 | cmd = "ATTACH"; | |
7582 | break; | |
7583 | case PDIC_NOTIFY_EVENT_PD_SINK: | |
7584 | selected_pdo = battery->pdic_info.sink_status.selected_pdo_num; | |
7585 | cmd = "ATTACH"; | |
7586 | battery->wire_status = SEC_BATTERY_CABLE_PDIC; | |
7587 | battery->pdic_attach = true; | |
7588 | battery->input_voltage = | |
7589 | battery->pdic_info.sink_status.power_list[selected_pdo].max_voltage / 1000; | |
7590 | ||
7591 | pr_info("%s: total pdo : %d, selected pdo : %d\n", __func__, | |
7592 | battery->pdic_info.sink_status.available_pdo_num, selected_pdo); | |
7593 | for(i=1; i<= battery->pdic_info.sink_status.available_pdo_num; i++) | |
7594 | { | |
7595 | pr_info("%s: power_list[%d], voltage : %d, current : %d, power : %d\n", __func__, i, | |
7596 | battery->pdic_info.sink_status.power_list[i].max_voltage, | |
7597 | battery->pdic_info.sink_status.power_list[i].max_current, | |
7598 | battery->pdic_info.sink_status.power_list[i].max_voltage * | |
7599 | battery->pdic_info.sink_status.power_list[i].max_current); | |
7600 | } | |
7601 | wake_lock(&battery->cable_wake_lock); | |
7602 | queue_delayed_work(battery->monitor_wqueue, | |
7603 | &battery->cable_work, 0); | |
7604 | break; | |
7605 | case PDIC_NOTIFY_EVENT_PD_SOURCE: | |
7606 | cmd = "ATTACH"; | |
7607 | break; | |
7608 | default: | |
7609 | cmd = "ERROR"; | |
7610 | break; | |
7611 | } | |
7612 | pr_info("%s: CMD=%s, cable_type : %d\n", __func__, cmd, battery->cable_type); | |
7613 | mutex_unlock(&battery->batt_handlelock); | |
7614 | return 0; | |
7615 | } | |
7616 | #endif | |
7617 | ||
7618 | #if defined(CONFIG_MUIC_NOTIFIER) | |
7619 | static int batt_handle_notification(struct notifier_block *nb, | |
7620 | unsigned long action, void *data) | |
7621 | { | |
7622 | const char *cmd; | |
7623 | int cable_type = SEC_BATTERY_CABLE_NONE; | |
7624 | struct sec_battery_info *battery = | |
7625 | container_of(nb, struct sec_battery_info, | |
7626 | batt_nb); | |
7627 | union power_supply_propval value = {0, }; | |
7628 | ||
7629 | #if defined(CONFIG_CCIC_NOTIFIER) | |
7630 | CC_NOTI_ATTACH_TYPEDEF *p_noti = (CC_NOTI_ATTACH_TYPEDEF *)data; | |
7631 | muic_attached_dev_t attached_dev = p_noti->cable_type; | |
7632 | #else | |
7633 | muic_attached_dev_t attached_dev = *(muic_attached_dev_t *)data; | |
7634 | #endif | |
7635 | ||
7636 | mutex_lock(&battery->batt_handlelock); | |
7637 | switch (action) { | |
7638 | case MUIC_NOTIFY_CMD_DETACH: | |
7639 | case MUIC_NOTIFY_CMD_LOGICALLY_DETACH: | |
7640 | cmd = "DETACH"; | |
7641 | battery->is_jig_on = false; | |
7642 | cable_type = SEC_BATTERY_CABLE_NONE; | |
7643 | battery->muic_cable_type = ATTACHED_DEV_NONE_MUIC; | |
7644 | break; | |
7645 | case MUIC_NOTIFY_CMD_ATTACH: | |
7646 | case MUIC_NOTIFY_CMD_LOGICALLY_ATTACH: | |
7647 | cmd = "ATTACH"; | |
7648 | cable_type = sec_bat_cable_check(battery, attached_dev); | |
7649 | battery->muic_cable_type = attached_dev; | |
7650 | break; | |
7651 | default: | |
7652 | cmd = "ERROR"; | |
7653 | cable_type = -1; | |
7654 | battery->muic_cable_type = ATTACHED_DEV_NONE_MUIC; | |
7655 | break; | |
7656 | } | |
7657 | ||
7658 | sec_bat_set_misc_event(battery, BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE, | |
7659 | #if !defined(CONFIG_ENG_BATTERY_CONCEPT) && !defined(CONFIG_SEC_FACTORY) | |
7660 | (battery->muic_cable_type != ATTACHED_DEV_JIG_UART_ON_MUIC) && | |
7661 | (battery->muic_cable_type != ATTACHED_DEV_JIG_USB_ON_MUIC) && | |
7662 | #endif | |
7663 | (battery->muic_cable_type != ATTACHED_DEV_UNDEFINED_RANGE_MUIC)); | |
7664 | ||
7665 | #if defined(CONFIG_CCIC_NOTIFIER) | |
7666 | /* If PD cable is already attached, return this function */ | |
7667 | if(battery->pdic_attach) { | |
7668 | dev_info(battery->dev, "%s: ignore event pdic attached(%d)\n", | |
7669 | __func__, battery->pdic_attach); | |
7670 | mutex_unlock(&battery->batt_handlelock); | |
7671 | return 0; | |
7672 | } | |
7673 | #endif | |
7674 | ||
7675 | if (attached_dev == ATTACHED_DEV_MHL_MUIC) { | |
7676 | mutex_unlock(&battery->batt_handlelock); | |
7677 | return 0; | |
7678 | } | |
7679 | ||
7680 | if (cable_type < 0) { | |
7681 | dev_info(battery->dev, "%s: ignore event(%d)\n", | |
7682 | __func__, cable_type); | |
7683 | } else if (cable_type == SEC_BATTERY_CABLE_POWER_SHARING) { | |
7684 | battery->ps_status = true; | |
7685 | battery->ps_enable = true; | |
7686 | battery->wire_status = cable_type; | |
7687 | dev_info(battery->dev, "%s: power sharing cable plugin\n", __func__); | |
7688 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS) { | |
7689 | battery->wc_status = SEC_WIRELESS_PAD_WPC; | |
7690 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS_PACK) { | |
7691 | battery->wc_status = SEC_WIRELESS_PAD_WPC_PACK; | |
7692 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_PACK) { | |
7693 | battery->wc_status = SEC_WIRELESS_PAD_WPC_PACK_HV; | |
7694 | } else if (cable_type == SEC_BATTERY_CABLE_HV_WIRELESS) { | |
7695 | battery->wc_status = SEC_WIRELESS_PAD_WPC_HV; | |
7696 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS_STAND) { | |
7697 | battery->wc_status = SEC_WIRELESS_PAD_WPC_STAND; | |
7698 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_STAND) { | |
7699 | battery->wc_status = SEC_WIRELESS_PAD_WPC_STAND_HV; | |
7700 | } else if (cable_type == SEC_BATTERY_CABLE_PMA_WIRELESS) { | |
7701 | battery->wc_status = SEC_WIRELESS_PAD_PMA; | |
7702 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS_VEHICLE) { | |
7703 | battery->wc_status = SEC_WIRELESS_PAD_VEHICLE; | |
7704 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_VEHICLE) { | |
7705 | battery->wc_status = SEC_WIRELESS_PAD_VEHICLE_HV; | |
7706 | } else if (cable_type == SEC_BATTERY_CABLE_WIRELESS_TX) { | |
7707 | battery->wc_status = SEC_WIRELESS_PAD_TX; | |
7708 | } else if ((cable_type == SEC_BATTERY_CABLE_UNKNOWN) && | |
7709 | (battery->status != POWER_SUPPLY_STATUS_DISCHARGING)) { | |
7710 | battery->cable_type = cable_type; | |
7711 | wake_lock(&battery->monitor_wake_lock); | |
7712 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
7713 | dev_info(battery->dev, | |
7714 | "%s: UNKNOWN cable plugin\n", __func__); | |
7715 | mutex_unlock(&battery->batt_handlelock); | |
7716 | return 0; | |
7717 | } else { | |
7718 | battery->wire_status = cable_type; | |
7719 | if ((battery->wire_status == SEC_BATTERY_CABLE_NONE) && | |
7720 | (battery->wc_status) && (!battery->ps_status)) | |
7721 | cable_type = SEC_BATTERY_CABLE_WIRELESS; | |
7722 | } | |
7723 | dev_info(battery->dev, | |
7724 | "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n", | |
7725 | __func__, cable_type, battery->wc_status, | |
7726 | battery->wire_status); | |
7727 | ||
7728 | mutex_unlock(&battery->batt_handlelock); | |
7729 | if (attached_dev == ATTACHED_DEV_USB_LANHUB_MUIC) { | |
7730 | if (!strcmp(cmd, "ATTACH")) { | |
7731 | value.intval = true; | |
7732 | psy_do_property(battery->pdata->charger_name, set, | |
7733 | POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL, | |
7734 | value); | |
7735 | dev_info(battery->dev, | |
7736 | "%s: Powered OTG cable attached\n", __func__); | |
7737 | } else { | |
7738 | value.intval = false; | |
7739 | psy_do_property(battery->pdata->charger_name, set, | |
7740 | POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL, | |
7741 | value); | |
7742 | dev_info(battery->dev, | |
7743 | "%s: Powered OTG cable detached\n", __func__); | |
7744 | } | |
7745 | } | |
7746 | ||
7747 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
7748 | if (!strcmp(cmd, "ATTACH")) { | |
7749 | if ((battery->muic_cable_type >= ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC) && | |
7750 | (battery->muic_cable_type <= ATTACHED_DEV_QC_CHARGER_9V_MUIC)) { | |
7751 | battery->hv_chg_name = "QC"; | |
7752 | } else if ((battery->muic_cable_type >= ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC) && | |
7753 | (battery->muic_cable_type <= ATTACHED_DEV_AFC_CHARGER_ERR_V_DUPLI_MUIC)) { | |
7754 | battery->hv_chg_name = "AFC"; | |
7755 | #if defined(CONFIG_MUIC_HV_12V) | |
7756 | } else if (battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_12V_MUIC || | |
7757 | battery->muic_cable_type == ATTACHED_DEV_AFC_CHARGER_12V_DUPLI_MUIC) { | |
7758 | battery->hv_chg_name = "12V"; | |
7759 | #endif | |
7760 | } else | |
7761 | battery->hv_chg_name = "NONE"; | |
7762 | } else { | |
7763 | battery->hv_chg_name = "NONE"; | |
7764 | } | |
7765 | ||
7766 | pr_info("%s : HV_CHARGER_NAME(%s)\n", | |
7767 | __func__, battery->hv_chg_name); | |
7768 | #endif | |
7769 | ||
7770 | if ((cable_type >= 0) && | |
7771 | cable_type <= SEC_BATTERY_CABLE_MAX) { | |
7772 | if (cable_type == SEC_BATTERY_CABLE_POWER_SHARING) { | |
7773 | value.intval = battery->ps_enable; | |
7774 | psy_do_property(battery->pdata->charger_name, set, | |
7775 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
7776 | wake_lock(&battery->monitor_wake_lock); | |
7777 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
7778 | } else if((cable_type == SEC_BATTERY_CABLE_NONE) && (battery->ps_status)) { | |
7779 | if (battery->ps_enable) { | |
7780 | battery->ps_enable = false; | |
7781 | value.intval = battery->ps_enable; | |
7782 | psy_do_property(battery->pdata->charger_name, set, | |
7783 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
7784 | } | |
7785 | battery->ps_status = false; | |
7786 | wake_lock(&battery->monitor_wake_lock); | |
7787 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
7788 | } else if(cable_type != battery->cable_type) { | |
7789 | wake_lock(&battery->cable_wake_lock); | |
7790 | queue_delayed_work(battery->monitor_wqueue, | |
7791 | &battery->cable_work, 0); | |
7792 | } else { | |
7793 | dev_info(battery->dev, | |
7794 | "%s: Cable is Not Changed(%d)\n", | |
7795 | __func__, battery->cable_type); | |
7796 | } | |
7797 | } | |
7798 | ||
7799 | pr_info("%s: CMD=%s, attached_dev=%d\n", __func__, cmd, attached_dev); | |
7800 | ||
7801 | return 0; | |
7802 | } | |
7803 | #endif /* CONFIG_MUIC_NOTIFIER */ | |
7804 | #endif | |
7805 | ||
7806 | #if defined(CONFIG_VBUS_NOTIFIER) | |
7807 | static int vbus_handle_notification(struct notifier_block *nb, | |
7808 | unsigned long action, void *data) | |
7809 | { | |
7810 | vbus_status_t vbus_status = *(vbus_status_t *)data; | |
7811 | struct sec_battery_info *battery = | |
7812 | container_of(nb, struct sec_battery_info, | |
7813 | vbus_nb); | |
7814 | union power_supply_propval value = {0, }; | |
7815 | ||
7816 | mutex_lock(&battery->batt_handlelock); | |
7817 | if (battery->muic_cable_type == ATTACHED_DEV_HMT_MUIC && | |
7818 | battery->muic_vbus_status != vbus_status && | |
7819 | battery->muic_vbus_status == STATUS_VBUS_HIGH && | |
7820 | vbus_status == STATUS_VBUS_LOW) { | |
7821 | msleep(500); | |
7822 | value.intval = true; | |
7823 | psy_do_property(battery->pdata->charger_name, set, | |
7824 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
7825 | value); | |
7826 | dev_info(battery->dev, | |
7827 | "%s: changed to OTG cable attached\n", __func__); | |
7828 | ||
7829 | battery->wire_status = SEC_BATTERY_CABLE_OTG; | |
7830 | wake_lock(&battery->cable_wake_lock); | |
7831 | queue_delayed_work(battery->monitor_wqueue, &battery->cable_work, 0); | |
7832 | } | |
7833 | pr_info("%s: action=%d, vbus_status=%d\n", __func__, (int)action, vbus_status); | |
7834 | mutex_unlock(&battery->batt_handlelock); | |
7835 | battery->muic_vbus_status = vbus_status; | |
7836 | ||
7837 | return 0; | |
7838 | } | |
7839 | #endif | |
7840 | ||
7841 | #ifdef CONFIG_OF | |
7842 | static int sec_bat_parse_dt(struct device *dev, | |
7843 | struct sec_battery_info *battery) | |
7844 | { | |
7845 | struct device_node *np; | |
7846 | sec_battery_platform_data_t *pdata = battery->pdata; | |
7847 | int ret = 0, len = 0; | |
7848 | unsigned int i = 0; | |
7849 | const u32 *p; | |
7850 | u32 temp = 0; | |
7851 | ||
7852 | np = of_find_node_by_name(NULL, "cable-info"); | |
7853 | if (!np) { | |
7854 | pr_err ("%s : np NULL\n", __func__); | |
7855 | } else { | |
7856 | struct device_node *child; | |
7857 | u32 input_current = 0, charging_current = 0; | |
7858 | ||
7859 | ret = of_property_read_u32(np, "default_input_current", &input_current); | |
7860 | ret = of_property_read_u32(np, "default_charging_current", &charging_current); | |
7861 | ret = of_property_read_u32(np, "full_check_current_1st", &pdata->full_check_current_1st); | |
7862 | ret = of_property_read_u32(np, "full_check_current_2nd", &pdata->full_check_current_2nd); | |
7863 | ||
7864 | pdata->default_input_current = input_current; | |
7865 | pdata->default_charging_current = charging_current; | |
7866 | ||
7867 | pdata->charging_current = | |
7868 | kzalloc(sizeof(sec_charging_current_t) * SEC_BATTERY_CABLE_MAX, | |
7869 | GFP_KERNEL); | |
7870 | ||
7871 | for (i = 0; i < SEC_BATTERY_CABLE_MAX; i++) { | |
7872 | pdata->charging_current[i].input_current_limit = (unsigned int)input_current; | |
7873 | pdata->charging_current[i].fast_charging_current = (unsigned int)charging_current; | |
7874 | } | |
7875 | ||
7876 | for_each_child_of_node(np, child) { | |
7877 | ret = of_property_read_u32(child, "input_current", &input_current); | |
7878 | ret = of_property_read_u32(child, "charging_current", &charging_current); | |
7879 | ||
7880 | p = of_get_property(child, "cable_number", &len); | |
7881 | if (!p) | |
7882 | return 1; | |
7883 | ||
7884 | len = len / sizeof(u32); | |
7885 | ||
7886 | for (i = 0; i <= len; i++) { | |
7887 | ret = of_property_read_u32_index(child, "cable_number", i, &temp); | |
7888 | pdata->charging_current[temp].input_current_limit = (unsigned int)input_current; | |
7889 | pdata->charging_current[temp].fast_charging_current = (unsigned int)charging_current; | |
7890 | } | |
7891 | ||
7892 | } | |
7893 | } | |
7894 | ||
7895 | for (i = 0; i < SEC_BATTERY_CABLE_MAX; i++) { | |
7896 | pr_info("%s : CABLE_NUM(%d) INPUT(%d) CHARGING(%d)\n", | |
7897 | __func__, i, | |
7898 | pdata->charging_current[i].input_current_limit, | |
7899 | pdata->charging_current[i].fast_charging_current); | |
7900 | } | |
7901 | ||
7902 | pr_info("%s : TOPOFF_1ST(%d), TOPOFF_2ND(%d)\n", | |
7903 | __func__, pdata->full_check_current_1st, pdata->full_check_current_2nd); | |
7904 | #ifdef CONFIG_SEC_FACTORY | |
7905 | pdata->default_charging_current = 1500; | |
7906 | pdata->charging_current[SEC_BATTERY_CABLE_TA].fast_charging_current = 1500; | |
7907 | #endif | |
7908 | np = of_find_node_by_name(NULL, "battery"); | |
7909 | if (!np) { | |
7910 | pr_info("%s: np NULL\n", __func__); | |
7911 | return 1; | |
7912 | } | |
7913 | ||
7914 | #if defined(CONFIG_BATTERY_CISD) | |
7915 | ret = of_property_read_u32(np, "battery,battery_full_capacity", | |
7916 | &pdata->battery_full_capacity); | |
7917 | if (ret) { | |
7918 | pr_info("%s : battery_full_capacity is Empty\n", __func__); | |
7919 | } else { | |
7920 | pr_info("%s : battery_full_capacity : %d\n", __func__, pdata->battery_full_capacity); | |
7921 | pdata->cisd_cap_high_thr = pdata->battery_full_capacity + 1000; | |
7922 | pdata->cisd_cap_low_thr = pdata->battery_full_capacity + 500; | |
7923 | pdata->cisd_cap_limit = (pdata->battery_full_capacity * 11) / 10; | |
7924 | } | |
7925 | ||
7926 | ret = of_property_read_u32(np, "battery,cisd_max_voltage_thr", | |
7927 | &pdata->max_voltage_thr); | |
7928 | if (ret) { | |
7929 | pr_info("%s : cisd_max_voltage_thr is Empty\n", __func__); | |
7930 | pdata->max_voltage_thr = 4400; | |
7931 | } | |
7932 | ||
7933 | ret = of_property_read_u32(np, "battery,cisd_alg_index", | |
7934 | &pdata->cisd_alg_index); | |
7935 | if (ret) { | |
7936 | pr_info("%s : cisd_alg_index is Empty. Defalut set to six\n", __func__); | |
7937 | pdata->cisd_alg_index = 6; | |
7938 | } else { | |
7939 | pr_info("%s : set cisd_alg_index : %d\n", __func__, pdata->cisd_alg_index); | |
7940 | } | |
7941 | #endif | |
7942 | ||
7943 | ret = of_property_read_u32(np, | |
7944 | "battery,expired_time", &temp); | |
7945 | if (ret) { | |
7946 | pr_info("expired time is empty\n"); | |
7947 | pdata->expired_time = 3 * 60 * 60; | |
7948 | } else { | |
7949 | pdata->expired_time = (unsigned int) temp; | |
7950 | } | |
7951 | pdata->expired_time *= 1000; | |
7952 | battery->expired_time = pdata->expired_time; | |
7953 | ||
7954 | ret = of_property_read_u32(np, | |
7955 | "battery,recharging_expired_time", &temp); | |
7956 | if (ret) { | |
7957 | pr_info("expired time is empty\n"); | |
7958 | pdata->recharging_expired_time = 90 * 60; | |
7959 | } else { | |
7960 | pdata->recharging_expired_time = (unsigned int) temp; | |
7961 | } | |
7962 | pdata->recharging_expired_time *= 1000; | |
7963 | ||
7964 | ret = of_property_read_u32(np, | |
7965 | "battery,standard_curr", &pdata->standard_curr); | |
7966 | if (ret) { | |
7967 | pr_info("standard_curr is empty\n"); | |
7968 | pdata->standard_curr = 2150; | |
7969 | } | |
7970 | ||
7971 | ret = of_property_read_string(np, | |
7972 | "battery,vendor", (char const **)&pdata->vendor); | |
7973 | if (ret) | |
7974 | pr_info("%s: Vendor is Empty\n", __func__); | |
7975 | ||
7976 | ret = of_property_read_string(np, | |
7977 | "battery,charger_name", (char const **)&pdata->charger_name); | |
7978 | if (ret) | |
7979 | pr_info("%s: Charger name is Empty\n", __func__); | |
7980 | ||
7981 | ret = of_property_read_string(np, | |
7982 | "battery,fuelgauge_name", (char const **)&pdata->fuelgauge_name); | |
7983 | if (ret) | |
7984 | pr_info("%s: Fuelgauge name is Empty\n", __func__); | |
7985 | ||
7986 | ret = of_property_read_string(np, | |
7987 | "battery,wireless_charger_name", (char const **)&pdata->wireless_charger_name); | |
7988 | if (ret) | |
7989 | pr_info("%s: Wireless charger name is Empty\n", __func__); | |
7990 | ||
7991 | ret = of_property_read_string(np, | |
7992 | "battery,fgsrc_switch_name", (char const **)&pdata->fgsrc_switch_name); | |
7993 | if (ret) { | |
7994 | pdata->support_fgsrc_change = false; | |
7995 | pr_info("%s: fgsrc_switch_name is Empty\n", __func__); | |
7996 | } | |
7997 | else | |
7998 | pdata->support_fgsrc_change = true; | |
7999 | ||
8000 | ret = of_property_read_string(np, | |
8001 | "battery,wireless_charger_name", (char const **)&pdata->wireless_charger_name); | |
8002 | if (ret) | |
8003 | pr_info("%s: Wireless charger name is Empty\n", __func__); | |
8004 | ||
8005 | ret = of_property_read_string(np, | |
8006 | "battery,chip_vendor", (char const **)&pdata->chip_vendor); | |
8007 | if (ret) | |
8008 | pr_info("%s: Chip vendor is Empty\n", __func__); | |
8009 | ||
8010 | ret = of_property_read_u32(np, "battery,technology", | |
8011 | &pdata->technology); | |
8012 | if (ret) | |
8013 | pr_info("%s : technology is Empty\n", __func__); | |
8014 | ||
8015 | ret = of_property_read_u32(np, | |
8016 | "battery,wireless_cc_cv", &pdata->wireless_cc_cv); | |
8017 | ||
8018 | ret = of_property_read_u32(np, | |
8019 | "battery,set_cv_vout_in_low_capacity", &pdata->set_cv_vout_in_low_capacity); | |
8020 | ||
8021 | pdata->fake_capacity = of_property_read_bool(np, | |
8022 | "battery,fake_capacity"); | |
8023 | ||
8024 | p = of_get_property(np, "battery,polling_time", &len); | |
8025 | if (!p) | |
8026 | return 1; | |
8027 | ||
8028 | len = len / sizeof(u32); | |
8029 | pdata->polling_time = kzalloc(sizeof(*pdata->polling_time) * len, GFP_KERNEL); | |
8030 | ret = of_property_read_u32_array(np, "battery,polling_time", | |
8031 | pdata->polling_time, len); | |
8032 | if (ret) | |
8033 | pr_info("%s : battery,polling_time is Empty\n", __func__); | |
8034 | ||
8035 | ret = of_property_read_u32(np, "battery,thermal_source", | |
8036 | &pdata->thermal_source); | |
8037 | if (ret) | |
8038 | pr_info("%s : Thermal source is Empty\n", __func__); | |
8039 | ||
8040 | if (pdata->thermal_source == SEC_BATTERY_THERMAL_SOURCE_ADC) { | |
8041 | p = of_get_property(np, "battery,temp_table_adc", &len); | |
8042 | if (!p) | |
8043 | return 1; | |
8044 | ||
8045 | len = len / sizeof(u32); | |
8046 | ||
8047 | pdata->temp_adc_table_size = len; | |
8048 | pdata->temp_amb_adc_table_size = len; | |
8049 | ||
8050 | pdata->temp_adc_table = | |
8051 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
8052 | pdata->temp_adc_table_size, GFP_KERNEL); | |
8053 | pdata->temp_amb_adc_table = | |
8054 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
8055 | pdata->temp_adc_table_size, GFP_KERNEL); | |
8056 | ||
8057 | for(i = 0; i < pdata->temp_adc_table_size; i++) { | |
8058 | ret = of_property_read_u32_index(np, | |
8059 | "battery,temp_table_adc", i, &temp); | |
8060 | pdata->temp_adc_table[i].adc = (int)temp; | |
8061 | if (ret) | |
8062 | pr_info("%s : Temp_adc_table(adc) is Empty\n", | |
8063 | __func__); | |
8064 | ||
8065 | ret = of_property_read_u32_index(np, | |
8066 | "battery,temp_table_data", i, &temp); | |
8067 | pdata->temp_adc_table[i].data = (int)temp; | |
8068 | if (ret) | |
8069 | pr_info("%s : Temp_adc_table(data) is Empty\n", | |
8070 | __func__); | |
8071 | ||
8072 | ret = of_property_read_u32_index(np, | |
8073 | "battery,temp_table_adc", i, &temp); | |
8074 | pdata->temp_amb_adc_table[i].adc = (int)temp; | |
8075 | if (ret) | |
8076 | pr_info("%s : Temp_amb_adc_table(adc) is Empty\n", | |
8077 | __func__); | |
8078 | ||
8079 | ret = of_property_read_u32_index(np, | |
8080 | "battery,temp_table_data", i, &temp); | |
8081 | pdata->temp_amb_adc_table[i].data = (int)temp; | |
8082 | if (ret) | |
8083 | pr_info("%s : Temp_amb_adc_table(data) is Empty\n", | |
8084 | __func__); | |
8085 | } | |
8086 | } | |
8087 | ret = of_property_read_u32(np, "battery,usb_thermal_source", | |
8088 | &pdata->usb_thermal_source); | |
8089 | if (ret) | |
8090 | pr_info("%s : usb_thermal_source is Empty\n", __func__); | |
8091 | ||
8092 | if(pdata->usb_thermal_source) { | |
8093 | p = of_get_property(np, "battery,usb_temp_table_adc", &len); | |
8094 | if (!p) | |
8095 | return 1; | |
8096 | ||
8097 | len = len / sizeof(u32); | |
8098 | ||
8099 | pdata->usb_temp_adc_table_size = len; | |
8100 | ||
8101 | pdata->usb_temp_adc_table = | |
8102 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
8103 | pdata->usb_temp_adc_table_size, GFP_KERNEL); | |
8104 | ||
8105 | for(i = 0; i < pdata->usb_temp_adc_table_size; i++) { | |
8106 | ret = of_property_read_u32_index(np, | |
8107 | "battery,usb_temp_table_adc", i, &temp); | |
8108 | pdata->usb_temp_adc_table[i].adc = (int)temp; | |
8109 | if (ret) | |
8110 | pr_info("%s : Usb_Temp_adc_table(adc) is Empty\n", | |
8111 | __func__); | |
8112 | ||
8113 | ret = of_property_read_u32_index(np, | |
8114 | "battery,usb_temp_table_data", i, &temp); | |
8115 | pdata->usb_temp_adc_table[i].data = (int)temp; | |
8116 | if (ret) | |
8117 | pr_info("%s : Usb_Temp_adc_table(data) is Empty\n", | |
8118 | __func__); | |
8119 | } | |
8120 | } | |
8121 | ||
8122 | ret = of_property_read_u32(np, "battery,chg_thermal_source", | |
8123 | &pdata->chg_thermal_source); | |
8124 | if (ret) | |
8125 | pr_info("%s : chg_thermal_source is Empty\n", __func__); | |
8126 | ||
8127 | if(pdata->chg_thermal_source) { | |
8128 | p = of_get_property(np, "battery,chg_temp_table_adc", &len); | |
8129 | if (!p) | |
8130 | return 1; | |
8131 | ||
8132 | len = len / sizeof(u32); | |
8133 | ||
8134 | pdata->chg_temp_adc_table_size = len; | |
8135 | ||
8136 | pdata->chg_temp_adc_table = | |
8137 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
8138 | pdata->chg_temp_adc_table_size, GFP_KERNEL); | |
8139 | ||
8140 | for(i = 0; i < pdata->chg_temp_adc_table_size; i++) { | |
8141 | ret = of_property_read_u32_index(np, | |
8142 | "battery,chg_temp_table_adc", i, &temp); | |
8143 | pdata->chg_temp_adc_table[i].adc = (int)temp; | |
8144 | if (ret) | |
8145 | pr_info("%s : CHG_Temp_adc_table(adc) is Empty\n", | |
8146 | __func__); | |
8147 | ||
8148 | ret = of_property_read_u32_index(np, | |
8149 | "battery,chg_temp_table_data", i, &temp); | |
8150 | pdata->chg_temp_adc_table[i].data = (int)temp; | |
8151 | if (ret) | |
8152 | pr_info("%s : CHG_Temp_adc_table(data) is Empty\n", | |
8153 | __func__); | |
8154 | } | |
8155 | } | |
8156 | ||
8157 | ret = of_property_read_u32(np, "battery,wpc_thermal_source", | |
8158 | &pdata->wpc_thermal_source); | |
8159 | if (ret) | |
8160 | pr_info("%s : wpc_thermal_source is Empty\n", __func__); | |
8161 | ||
8162 | if(pdata->wpc_thermal_source) { | |
8163 | p = of_get_property(np, "battery,wpc_temp_table_adc", &len); | |
8164 | if (!p) { | |
8165 | pr_info("%s : wpc_temp_table_adc(adc) is Empty\n",__func__); | |
8166 | } else { | |
8167 | len = len / sizeof(u32); | |
8168 | ||
8169 | pdata->wpc_temp_adc_table_size = len; | |
8170 | ||
8171 | pdata->wpc_temp_adc_table = | |
8172 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
8173 | pdata->wpc_temp_adc_table_size, GFP_KERNEL); | |
8174 | ||
8175 | for(i = 0; i < pdata->wpc_temp_adc_table_size; i++) { | |
8176 | ret = of_property_read_u32_index(np, | |
8177 | "battery,wpc_temp_table_adc", i, &temp); | |
8178 | pdata->wpc_temp_adc_table[i].adc = (int)temp; | |
8179 | if (ret) | |
8180 | pr_info("%s : WPC_Temp_adc_table(adc) is Empty\n", | |
8181 | __func__); | |
8182 | ||
8183 | ret = of_property_read_u32_index(np, | |
8184 | "battery,wpc_temp_table_data", i, &temp); | |
8185 | pdata->wpc_temp_adc_table[i].data = (int)temp; | |
8186 | if (ret) | |
8187 | pr_info("%s : WPC_Temp_adc_table(data) is Empty\n", | |
8188 | __func__); | |
8189 | } | |
8190 | } | |
8191 | } | |
8192 | ||
8193 | ret = of_property_read_u32(np, "battery,coil_thermal_source", | |
8194 | &pdata->coil_thermal_source); | |
8195 | if (ret) | |
8196 | pr_info("%s : coil_thermal_source is Empty\n", __func__); | |
8197 | else | |
8198 | pr_info("%s : coil_thermal_source exists\n", __func__); | |
8199 | ||
8200 | ret = of_property_read_u32(np, "battery,slave_thermal_source", | |
8201 | &pdata->slave_thermal_source); | |
8202 | if (ret) | |
8203 | pr_info("%s : slave_thermal_source is Empty\n", __func__); | |
8204 | ||
8205 | if(pdata->slave_thermal_source) { | |
8206 | p = of_get_property(np, "battery,slave_chg_temp_table_adc", &len); | |
8207 | if (!p) | |
8208 | return 1; | |
8209 | ||
8210 | len = len / sizeof(u32); | |
8211 | ||
8212 | pdata->slave_chg_temp_adc_table_size = len; | |
8213 | ||
8214 | pdata->slave_chg_temp_adc_table = | |
8215 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
8216 | pdata->slave_chg_temp_adc_table_size, GFP_KERNEL); | |
8217 | ||
8218 | for(i = 0; i < pdata->slave_chg_temp_adc_table_size; i++) { | |
8219 | ret = of_property_read_u32_index(np, | |
8220 | "battery,slave_chg_temp_table_adc", i, &temp); | |
8221 | pdata->slave_chg_temp_adc_table[i].adc = (int)temp; | |
8222 | if (ret) | |
8223 | pr_info("%s : slave_chg_temp_adc_table(adc) is Empty\n", | |
8224 | __func__); | |
8225 | ||
8226 | ret = of_property_read_u32_index(np, | |
8227 | "battery,slave_chg_temp_table_data", i, &temp); | |
8228 | pdata->slave_chg_temp_adc_table[i].data = (int)temp; | |
8229 | if (ret) | |
8230 | pr_info("%s : slave_chg_temp_adc_table(data) is Empty\n", | |
8231 | __func__); | |
8232 | } | |
8233 | } | |
8234 | ret = of_property_read_u32(np, "battery,slave_chg_temp_check", | |
8235 | &pdata->slave_chg_temp_check); | |
8236 | if (ret) | |
8237 | pr_info("%s : slave_chg_temp_check is Empty\n", __func__); | |
8238 | ||
8239 | ret = of_property_read_u32(np, "battery,chg_temp_check", | |
8240 | &pdata->chg_temp_check); | |
8241 | if (ret) | |
8242 | pr_info("%s : chg_temp_check is Empty\n", __func__); | |
8243 | ||
8244 | if (pdata->chg_temp_check) { | |
8245 | ret = of_property_read_u32(np, "battery,chg_12v_high_temp", | |
8246 | &temp); | |
8247 | pdata->chg_12v_high_temp = (int)temp; | |
8248 | if (ret) | |
8249 | pr_info("%s : chg_12v_high_temp is Empty\n", __func__); | |
8250 | ||
8251 | ret = of_property_read_u32(np, "battery,chg_high_temp", | |
8252 | &temp); | |
8253 | pdata->chg_high_temp = (int)temp; | |
8254 | if (ret) | |
8255 | pr_info("%s : chg_high_temp is Empty\n", __func__); | |
8256 | ||
8257 | ret = of_property_read_u32(np, "battery,chg_high_temp_recovery", | |
8258 | &temp); | |
8259 | pdata->chg_high_temp_recovery = (int)temp; | |
8260 | if (ret) | |
8261 | pr_info("%s : chg_temp_recovery is Empty\n", __func__); | |
8262 | ||
8263 | ret = of_property_read_u32(np, "battery,chg_charging_limit_current", | |
8264 | &pdata->chg_charging_limit_current); | |
8265 | if (ret) | |
8266 | pr_info("%s : chg_charging_limit_current is Empty\n", __func__); | |
8267 | ||
8268 | ret = of_property_read_u32(np, "battery,chg_input_limit_current", | |
8269 | &pdata->chg_input_limit_current); | |
8270 | if (ret) | |
8271 | pr_info("%s : chg_input_limit_current is Empty\n", __func__); | |
8272 | ||
8273 | ret = of_property_read_u32(np, "battery,mix_high_temp", | |
8274 | &temp); | |
8275 | pdata->mix_high_temp = (int)temp; | |
8276 | if (ret) | |
8277 | pr_info("%s : mix_high_temp is Empty\n", __func__); | |
8278 | ||
8279 | ret = of_property_read_u32(np, "battery,mix_high_chg_temp", | |
8280 | &temp); | |
8281 | pdata->mix_high_chg_temp = (int)temp; | |
8282 | if (ret) | |
8283 | pr_info("%s : mix_high_chg_temp is Empty\n", __func__); | |
8284 | ||
8285 | ret = of_property_read_u32(np, "battery,mix_high_temp_recovery", | |
8286 | &temp); | |
8287 | pdata->mix_high_temp_recovery = (int)temp; | |
8288 | if (ret) | |
8289 | pr_info("%s : mix_high_temp_recovery is Empty\n", __func__); | |
8290 | } | |
8291 | ||
8292 | ret = of_property_read_u32(np, "battery,wpc_temp_check", | |
8293 | &pdata->wpc_temp_check); | |
8294 | if (ret) | |
8295 | pr_info("%s : wpc_temp_check is Empty\n", __func__); | |
8296 | ||
8297 | if (pdata->wpc_temp_check) { | |
8298 | ret = of_property_read_u32(np, "battery,wpc_temp_control_source", | |
8299 | &pdata->wpc_temp_control_source); | |
8300 | if (ret) { | |
8301 | pr_info("%s : wpc_temp_control_source is Empty\n", __func__); | |
8302 | pdata->wpc_temp_control_source = TEMP_CONTROL_SOURCE_CHG_THM; | |
8303 | } | |
8304 | ||
8305 | ret = of_property_read_u32(np, "battery,wpc_temp_lcd_on_control_source", | |
8306 | &pdata->wpc_temp_lcd_on_control_source); | |
8307 | if (ret) { | |
8308 | pr_info("%s : wpc_temp_lcd_on_control_source is Empty\n", __func__); | |
8309 | pdata->wpc_temp_lcd_on_control_source = TEMP_CONTROL_SOURCE_CHG_THM; | |
8310 | } | |
8311 | ||
8312 | ret = of_property_read_u32(np, "battery,wpc_high_temp", | |
8313 | &pdata->wpc_high_temp); | |
8314 | if (ret) | |
8315 | pr_info("%s : wpc_high_temp is Empty\n", __func__); | |
8316 | ||
8317 | ret = of_property_read_u32(np, "battery,wpc_high_temp_recovery", | |
8318 | &pdata->wpc_high_temp_recovery); | |
8319 | if (ret) | |
8320 | pr_info("%s : wpc_high_temp_recovery is Empty\n", __func__); | |
8321 | ||
8322 | ret = of_property_read_u32(np, "battery,wpc_charging_limit_current", | |
8323 | &pdata->wpc_charging_limit_current); | |
8324 | if (ret) | |
8325 | pr_info("%s : wpc_charging_limit_current is Empty\n", __func__); | |
8326 | ||
8327 | ret = of_property_read_u32(np, "battery,wpc_lcd_on_high_temp", | |
8328 | &pdata->wpc_lcd_on_high_temp); | |
8329 | if (ret) | |
8330 | pr_info("%s : wpc_lcd_on_high_temp is Empty\n", __func__); | |
8331 | ||
8332 | ret = of_property_read_u32(np, "battery,wpc_lcd_on_high_temp_rec", | |
8333 | &pdata->wpc_lcd_on_high_temp_rec); | |
8334 | if (ret) | |
8335 | pr_info("%s : wpc_lcd_on_high_temp_rec is Empty\n", __func__); | |
8336 | ||
8337 | ret = of_property_read_u32(np, "battery,wpc_lcd_on_charging_limit_current", | |
8338 | &pdata->wpc_lcd_on_charging_limit_current); | |
8339 | if (ret) { | |
8340 | pr_info("%s : wpc_lcd_on_charging_limit_current is Empty\n", __func__); | |
8341 | pdata->wpc_lcd_on_charging_limit_current = | |
8342 | pdata->wpc_charging_limit_current; | |
8343 | } | |
8344 | } | |
8345 | ||
8346 | ret = of_property_read_u32(np, "battery,wc_full_input_limit_current", | |
8347 | &pdata->wc_full_input_limit_current); | |
8348 | if (ret) | |
8349 | pr_info("%s : wc_full_input_limit_current is Empty\n", __func__); | |
8350 | ||
8351 | ret = of_property_read_u32(np, "battery,wc_cv_current", | |
8352 | &pdata->wc_cv_current); | |
8353 | if (ret) { | |
8354 | pr_info("%s : wc_cv_current is Empty\n", __func__); | |
8355 | pdata->wc_cv_current = 820; | |
8356 | } | |
8357 | ||
5a068558 MB |
8358 | ret = of_property_read_u32(np, "battery,wc_cv_tx_current", |
8359 | &pdata->wc_cv_tx_current); | |
8360 | if (ret) { | |
8361 | pr_info("%s : wc_cv_tx_current is Empty\n", __func__); | |
8362 | pdata->wc_cv_tx_current = 650; | |
8363 | } | |
8364 | ||
1cac41cb MB |
8365 | ret = of_property_read_u32(np, "battery,wc_cv_pack_current", |
8366 | &pdata->wc_cv_pack_current); | |
8367 | if (ret) { | |
8368 | pr_info("%s : wc_cv_pack_current is Empty\n", __func__); | |
8369 | pdata->wc_cv_pack_current = 500; | |
8370 | } | |
8371 | ||
8372 | ret = of_property_read_u32(np, "battery,wc_hero_stand_cc_cv", | |
8373 | &pdata->wc_hero_stand_cc_cv); | |
8374 | if (ret) { | |
8375 | pr_info("%s : wc_hero_stand_cc_cv is Empty\n", __func__); | |
8376 | pdata->wc_hero_stand_cc_cv = 70; | |
8377 | } | |
8378 | ret = of_property_read_u32(np, "battery,wc_hero_stand_cv_current", | |
8379 | &pdata->wc_hero_stand_cv_current); | |
8380 | if (ret) { | |
8381 | pr_info("%s : wc_hero_stand_cv_current is Empty\n", __func__); | |
8382 | pdata->wc_hero_stand_cv_current = 600; | |
8383 | } | |
8384 | ret = of_property_read_u32(np, "battery,wc_hero_stand_hv_cv_current", | |
8385 | &pdata->wc_hero_stand_hv_cv_current); | |
8386 | if (ret) { | |
8387 | pr_info("%s : wc_hero_stand_hv_cv_current is Empty\n", __func__); | |
8388 | pdata->wc_hero_stand_hv_cv_current = 450; | |
8389 | } | |
8390 | ||
8391 | ret = of_property_read_u32(np, "battery,sleep_mode_limit_current", | |
8392 | &pdata->sleep_mode_limit_current); | |
8393 | if (ret) | |
8394 | pr_info("%s : sleep_mode_limit_current is Empty\n", __func__); | |
8395 | ||
8396 | ret = of_property_read_u32(np, "battery,inbat_voltage", | |
8397 | &pdata->inbat_voltage); | |
8398 | if (ret) | |
8399 | pr_info("%s : inbat_voltage is Empty\n", __func__); | |
8400 | ||
8401 | if (pdata->inbat_voltage) { | |
8402 | p = of_get_property(np, "battery,inbat_voltage_table_adc", &len); | |
8403 | if (!p) | |
8404 | return 1; | |
8405 | ||
8406 | len = len / sizeof(u32); | |
8407 | ||
8408 | pdata->inbat_adc_table_size = len; | |
8409 | ||
8410 | pdata->inbat_adc_table = | |
8411 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
8412 | pdata->inbat_adc_table_size, GFP_KERNEL); | |
8413 | ||
8414 | for(i = 0; i < pdata->inbat_adc_table_size; i++) { | |
8415 | ret = of_property_read_u32_index(np, | |
8416 | "battery,inbat_voltage_table_adc", i, &temp); | |
8417 | pdata->inbat_adc_table[i].adc = (int)temp; | |
8418 | if (ret) | |
8419 | pr_info("%s : inbat_adc_table(adc) is Empty\n", | |
8420 | __func__); | |
8421 | ||
8422 | ret = of_property_read_u32_index(np, | |
8423 | "battery,inbat_voltage_table_data", i, &temp); | |
8424 | pdata->inbat_adc_table[i].data = (int)temp; | |
8425 | if (ret) | |
8426 | pr_info("%s : inbat_adc_table(data) is Empty\n", | |
8427 | __func__); | |
8428 | } | |
8429 | } | |
8430 | ||
8431 | ret = of_property_read_u32(np, "battery,pre_afc_input_current", | |
8432 | &pdata->pre_afc_input_current); | |
8433 | if (ret) { | |
8434 | pr_info("%s : pre_afc_input_current is Empty\n", __func__); | |
8435 | pdata->pre_afc_input_current = 1000; | |
8436 | } | |
8437 | ||
8438 | ret = of_property_read_u32(np, "battery,pre_afc_work_delay", | |
8439 | &pdata->pre_afc_work_delay); | |
8440 | if (ret) { | |
8441 | pr_info("%s : pre_afc_work_delay is Empty\n", __func__); | |
8442 | pdata->pre_afc_work_delay = 2000; | |
8443 | } | |
8444 | ||
8445 | ret = of_property_read_u32(np, "battery,pre_wc_afc_input_current", | |
8446 | &pdata->pre_wc_afc_input_current); | |
8447 | if (ret) { | |
8448 | pr_info("%s : pre_wc_afc_input_current is Empty\n", __func__); | |
8449 | pdata->pre_wc_afc_input_current = 500; /* wc input default */ | |
8450 | } | |
8451 | ||
8452 | ret = of_property_read_u32(np, "battery,pre_wc_afc_work_delay", | |
8453 | &pdata->pre_wc_afc_work_delay); | |
8454 | if (ret) { | |
8455 | pr_info("%s : pre_wc_afc_work_delay is Empty\n", __func__); | |
8456 | pdata->pre_wc_afc_work_delay = 4000; | |
8457 | } | |
8458 | ||
8459 | ret = of_property_read_u32(np, "battery,adc_check_count", | |
8460 | &pdata->adc_check_count); | |
8461 | if (ret) | |
8462 | pr_info("%s : Adc check count is Empty\n", __func__); | |
8463 | ||
8464 | ret = of_property_read_u32(np, "battery,temp_adc_type", | |
8465 | &pdata->temp_adc_type); | |
8466 | if (ret) | |
8467 | pr_info("%s : Temp adc type is Empty\n", __func__); | |
8468 | ||
8469 | ret = of_property_read_u32(np, "battery,cable_check_type", | |
8470 | &pdata->cable_check_type); | |
8471 | if (ret) | |
8472 | pr_info("%s : Cable check type is Empty\n", __func__); | |
8473 | ||
8474 | ret = of_property_read_u32(np, "battery,cable_source_type", | |
8475 | &pdata->cable_source_type); | |
8476 | if (ret) | |
8477 | pr_info("%s: Cable_source_type is Empty\n", __func__); | |
8478 | ret = of_property_read_u32(np, "battery,polling_type", | |
8479 | &pdata->polling_type); | |
8480 | if (ret) | |
8481 | pr_info("%s : Polling type is Empty\n", __func__); | |
8482 | ||
8483 | ret = of_property_read_u32(np, "battery,monitor_initial_count", | |
8484 | &pdata->monitor_initial_count); | |
8485 | if (ret) | |
8486 | pr_info("%s : Monitor initial count is Empty\n", __func__); | |
8487 | ||
8488 | ret = of_property_read_u32(np, "battery,battery_check_type", | |
8489 | &pdata->battery_check_type); | |
8490 | if (ret) | |
8491 | pr_info("%s : Battery check type is Empty\n", __func__); | |
8492 | ||
8493 | ret = of_property_read_u32(np, "battery,check_count", | |
8494 | &pdata->check_count); | |
8495 | if (ret) | |
8496 | pr_info("%s : Check count is Empty\n", __func__); | |
8497 | ||
8498 | ret = of_property_read_u32(np, "battery,check_adc_max", | |
8499 | &pdata->check_adc_max); | |
8500 | if (ret) | |
8501 | pr_info("%s : Check adc max is Empty\n", __func__); | |
8502 | ||
8503 | ret = of_property_read_u32(np, "battery,check_adc_min", | |
8504 | &pdata->check_adc_min); | |
8505 | if (ret) | |
8506 | pr_info("%s : Check adc min is Empty\n", __func__); | |
8507 | ||
8508 | ret = of_property_read_u32(np, "battery,ovp_uvlo_check_type", | |
8509 | &pdata->ovp_uvlo_check_type); | |
8510 | if (ret) | |
8511 | pr_info("%s : Ovp Uvlo check type is Empty\n", __func__); | |
8512 | ||
8513 | ret = of_property_read_u32(np, "battery,temp_check_type", | |
8514 | &pdata->temp_check_type); | |
8515 | if (ret) | |
8516 | pr_info("%s : Temp check type is Empty\n", __func__); | |
8517 | ||
8518 | ret = of_property_read_u32(np, "battery,temp_check_count", | |
8519 | &pdata->temp_check_count); | |
8520 | if (ret) | |
8521 | pr_info("%s : Temp check count is Empty\n", __func__); | |
8522 | ||
8523 | ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_normal", | |
8524 | &temp); | |
8525 | pdata->temp_highlimit_threshold_normal = (int)temp; | |
8526 | if (ret) | |
8527 | pr_info("%s : Temp highlimit threshold normal is Empty\n", __func__); | |
8528 | ||
8529 | ret = of_property_read_u32(np, "battery,temp_highlimit_recovery_normal", | |
8530 | &temp); | |
8531 | pdata->temp_highlimit_recovery_normal = (int)temp; | |
8532 | if (ret) | |
8533 | pr_info("%s : Temp highlimit recovery normal is Empty\n", __func__); | |
8534 | ||
8535 | ret = of_property_read_u32(np, "battery,temp_high_threshold_normal", | |
8536 | &temp); | |
8537 | pdata->temp_high_threshold_normal = (int)temp; | |
8538 | if (ret) | |
8539 | pr_info("%s : Temp high threshold normal is Empty\n", __func__); | |
8540 | ||
8541 | ret = of_property_read_u32(np, "battery,temp_high_recovery_normal", | |
8542 | &temp); | |
8543 | pdata->temp_high_recovery_normal = (int)temp; | |
8544 | if (ret) | |
8545 | pr_info("%s : Temp high recovery normal is Empty\n", __func__); | |
8546 | ||
8547 | ret = of_property_read_u32(np, "battery,temp_low_threshold_normal", | |
8548 | &temp); | |
8549 | pdata->temp_low_threshold_normal = (int)temp; | |
8550 | if (ret) | |
8551 | pr_info("%s : Temp low threshold normal is Empty\n", __func__); | |
8552 | ||
8553 | ret = of_property_read_u32(np, "battery,temp_low_recovery_normal", | |
8554 | &temp); | |
8555 | pdata->temp_low_recovery_normal = (int)temp; | |
8556 | if (ret) | |
8557 | pr_info("%s : Temp low recovery normal is Empty\n", __func__); | |
8558 | ||
8559 | ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_lpm", | |
8560 | &temp); | |
8561 | pdata->temp_highlimit_threshold_lpm = (int)temp; | |
8562 | if (ret) | |
8563 | pr_info("%s : Temp highlimit threshold lpm is Empty\n", __func__); | |
8564 | ||
8565 | ret = of_property_read_u32(np, "battery,temp_highlimit_recovery_lpm", | |
8566 | &temp); | |
8567 | pdata->temp_highlimit_recovery_lpm = (int)temp; | |
8568 | if (ret) | |
8569 | pr_info("%s : Temp highlimit recovery lpm is Empty\n", __func__); | |
8570 | ||
8571 | ret = of_property_read_u32(np, "battery,temp_high_threshold_lpm", | |
8572 | &temp); | |
8573 | pdata->temp_high_threshold_lpm = (int)temp; | |
8574 | if (ret) | |
8575 | pr_info("%s : Temp high threshold lpm is Empty\n", __func__); | |
8576 | ||
8577 | ret = of_property_read_u32(np, "battery,temp_high_recovery_lpm", | |
8578 | &temp); | |
8579 | pdata->temp_high_recovery_lpm = (int)temp; | |
8580 | if (ret) | |
8581 | pr_info("%s : Temp high recovery lpm is Empty\n", __func__); | |
8582 | ||
8583 | ret = of_property_read_u32(np, "battery,temp_low_threshold_lpm", | |
8584 | &temp); | |
8585 | pdata->temp_low_threshold_lpm = (int)temp; | |
8586 | if (ret) | |
8587 | pr_info("%s : Temp low threshold lpm is Empty\n", __func__); | |
8588 | ||
8589 | ret = of_property_read_u32(np, "battery,temp_low_recovery_lpm", | |
8590 | &temp); | |
8591 | pdata->temp_low_recovery_lpm = (int)temp; | |
8592 | if (ret) | |
8593 | pr_info("%s : Temp low recovery lpm is Empty\n", __func__); | |
8594 | ||
8595 | pr_info("%s : HIGHLIMIT_THRESHOLD_NOLMAL(%d), HIGHLIMIT_RECOVERY_NORMAL(%d)\n" | |
8596 | "HIGH_THRESHOLD_NORMAL(%d), HIGH_RECOVERY_NORMAL(%d) LOW_THRESHOLD_NORMAL(%d), LOW_RECOVERY_NORMAL(%d)\n" | |
8597 | "HIGHLIMIT_THRESHOLD_LPM(%d), HIGHLIMIT_RECOVERY_LPM(%d)\n" | |
8598 | "HIGH_THRESHOLD_LPM(%d), HIGH_RECOVERY_LPM(%d) LOW_THRESHOLD_LPM(%d), LOW_RECOVERY_LPM(%d)\n", | |
8599 | __func__, | |
8600 | pdata->temp_highlimit_threshold_normal, pdata->temp_highlimit_recovery_normal, | |
8601 | pdata->temp_high_threshold_normal, pdata->temp_high_recovery_normal, | |
8602 | pdata->temp_low_threshold_normal, pdata->temp_low_recovery_normal, | |
8603 | pdata->temp_highlimit_threshold_lpm, pdata->temp_highlimit_recovery_lpm, | |
8604 | pdata->temp_high_threshold_lpm, pdata->temp_high_recovery_lpm, | |
8605 | pdata->temp_low_threshold_lpm, pdata->temp_low_recovery_lpm); | |
8606 | ||
8607 | ret = of_property_read_u32(np, "battery,wpc_high_threshold_normal", | |
8608 | &temp); | |
8609 | pdata->wpc_high_threshold_normal = (int)temp; | |
8610 | if (ret) | |
8611 | pr_info("%s : wpc_high_threshold_normal is Empty\n", __func__); | |
8612 | ||
8613 | ret = of_property_read_u32(np, "battery,wpc_high_recovery_normal", | |
8614 | &temp); | |
8615 | pdata->wpc_high_recovery_normal = (int)temp; | |
8616 | if (ret) | |
8617 | pr_info("%s : wpc_high_recovery_normal is Empty\n", __func__); | |
8618 | ||
8619 | ret = of_property_read_u32(np, "battery,wpc_low_threshold_normal", | |
8620 | &temp); | |
8621 | pdata->wpc_low_threshold_normal = (int)temp; | |
8622 | if (ret) | |
8623 | pr_info("%s : wpc_low_threshold_normal is Empty\n", __func__); | |
8624 | ||
8625 | ret = of_property_read_u32(np, "battery,wpc_low_recovery_normal", | |
8626 | &temp); | |
8627 | pdata->wpc_low_recovery_normal = (int)temp; | |
8628 | if (ret) | |
8629 | pr_info("%s : wpc_low_recovery_normal is Empty\n", __func__); | |
8630 | ||
8631 | ret = of_property_read_u32(np, "battery,full_check_type", | |
8632 | &pdata->full_check_type); | |
8633 | if (ret) | |
8634 | pr_info("%s : Full check type is Empty\n", __func__); | |
8635 | ||
8636 | ret = of_property_read_u32(np, "battery,full_check_type_2nd", | |
8637 | &pdata->full_check_type_2nd); | |
8638 | if (ret) | |
8639 | pr_info("%s : Full check type 2nd is Empty\n", __func__); | |
8640 | ||
8641 | ret = of_property_read_u32(np, "battery,full_check_count", | |
8642 | &pdata->full_check_count); | |
8643 | if (ret) | |
8644 | pr_info("%s : Full check count is Empty\n", __func__); | |
8645 | ||
8646 | ret = of_property_read_u32(np, "battery,chg_gpio_full_check", | |
8647 | &pdata->chg_gpio_full_check); | |
8648 | if (ret) | |
8649 | pr_info("%s : Chg gpio full check is Empty\n", __func__); | |
8650 | ||
8651 | ret = of_property_read_u32(np, "battery,chg_polarity_full_check", | |
8652 | &pdata->chg_polarity_full_check); | |
8653 | if (ret) | |
8654 | pr_info("%s : Chg polarity full check is Empty\n", __func__); | |
8655 | ||
8656 | ret = of_property_read_u32(np, "battery,full_condition_type", | |
8657 | &pdata->full_condition_type); | |
8658 | if (ret) | |
8659 | pr_info("%s : Full condition type is Empty\n", __func__); | |
8660 | ||
8661 | ret = of_property_read_u32(np, "battery,full_condition_soc", | |
8662 | &pdata->full_condition_soc); | |
8663 | if (ret) | |
8664 | pr_info("%s : Full condition soc is Empty\n", __func__); | |
8665 | ||
8666 | ret = of_property_read_u32(np, "battery,full_condition_vcell", | |
8667 | &pdata->full_condition_vcell); | |
8668 | if (ret) | |
8669 | pr_info("%s : Full condition vcell is Empty\n", __func__); | |
8670 | ||
8671 | ret = of_property_read_u32(np, "battery,recharge_check_count", | |
8672 | &pdata->recharge_check_count); | |
8673 | if (ret) | |
8674 | pr_info("%s : Recharge check count is Empty\n", __func__); | |
8675 | ||
8676 | ret = of_property_read_u32(np, "battery,recharge_condition_type", | |
8677 | &pdata->recharge_condition_type); | |
8678 | if (ret) | |
8679 | pr_info("%s : Recharge condition type is Empty\n", __func__); | |
8680 | ||
8681 | ret = of_property_read_u32(np, "battery,recharge_condition_soc", | |
8682 | &pdata->recharge_condition_soc); | |
8683 | if (ret) | |
8684 | pr_info("%s : Recharge condition soc is Empty\n", __func__); | |
8685 | ||
8686 | ret = of_property_read_u32(np, "battery,recharge_condition_vcell", | |
8687 | &pdata->recharge_condition_vcell); | |
8688 | if (ret) | |
8689 | pr_info("%s : Recharge condition vcell is Empty\n", __func__); | |
8690 | ||
8691 | ret = of_property_read_u32(np, "battery,charging_total_time", | |
8692 | (unsigned int *)&pdata->charging_total_time); | |
8693 | if (ret) | |
8694 | pr_info("%s : Charging total time is Empty\n", __func__); | |
8695 | ||
8696 | ret = of_property_read_u32(np, "battery,hv_charging_total_time", | |
8697 | &pdata->hv_charging_total_time); | |
8698 | if (ret) { | |
8699 | pdata->hv_charging_total_time = 3 * 60 * 60; | |
8700 | pr_info("%s : HV Charging total time is %d\n", | |
8701 | __func__, pdata->hv_charging_total_time); | |
8702 | } | |
8703 | ||
8704 | ret = of_property_read_u32(np, "battery,normal_charging_total_time", | |
8705 | &pdata->normal_charging_total_time); | |
8706 | if (ret) { | |
8707 | pdata->normal_charging_total_time = 5 * 60 * 60; | |
8708 | pr_info("%s : Normal(WC) Charging total time is %d\n", | |
8709 | __func__, pdata->normal_charging_total_time); | |
8710 | } | |
8711 | ||
8712 | ret = of_property_read_u32(np, "battery,usb_charging_total_time", | |
8713 | &pdata->usb_charging_total_time); | |
8714 | if (ret) { | |
8715 | pdata->usb_charging_total_time = 10 * 60 * 60; | |
8716 | pr_info("%s : USB Charging total time is %d\n", | |
8717 | __func__, pdata->usb_charging_total_time); | |
8718 | } | |
8719 | ||
8720 | ret = of_property_read_u32(np, "battery,recharging_total_time", | |
8721 | (unsigned int *)&pdata->recharging_total_time); | |
8722 | if (ret) | |
8723 | pr_info("%s : Recharging total time is Empty\n", __func__); | |
8724 | ||
8725 | ret = of_property_read_u32(np, "battery,charging_reset_time", | |
8726 | (unsigned int *)&pdata->charging_reset_time); | |
8727 | if (ret) | |
8728 | pr_info("%s : Charging reset time is Empty\n", __func__); | |
8729 | ||
8730 | ret = of_property_read_u32(np, "battery,charging_reset_time", | |
8731 | (unsigned int *)&pdata->charging_reset_time); | |
8732 | if (ret) | |
8733 | pr_info("%s : Charging reset time is Empty\n", __func__); | |
8734 | ||
8735 | ret = of_property_read_u32(np, "battery,chg_float_voltage", | |
8736 | (unsigned int *)&pdata->chg_float_voltage); | |
8737 | if (ret) { | |
8738 | pr_info("%s: chg_float_voltage is Empty\n", __func__); | |
8739 | pdata->chg_float_voltage = 43500; | |
8740 | } | |
8741 | ||
8742 | ret = of_property_read_u32(np, "battery,chg_float_voltage_conv", | |
8743 | &pdata->chg_float_voltage_conv); | |
8744 | if (ret) { | |
8745 | pr_info("%s: chg_float_voltage_conv is Empty\n", __func__); | |
8746 | pdata->chg_float_voltage_conv = 1; | |
8747 | } | |
8748 | ||
8749 | ret = of_property_read_u32(np, "battery,wa_volt_recov", | |
8750 | (unsigned int *)&pdata->wa_volt_recov); | |
8751 | if (ret) { | |
8752 | pdata->wa_volt_recov = 4090; | |
8753 | pr_info("%s: wa volt recov is Empty\n", __func__); | |
8754 | } | |
8755 | ||
8756 | ret = of_property_read_u32(np, "battery,wa_volt_thr", | |
8757 | (unsigned int *)&pdata->wa_volt_thr); | |
8758 | if (ret) { | |
8759 | pdata->wa_volt_thr = 4100; | |
8760 | pr_info("%s: wa volt thr is Empty\n", __func__); | |
8761 | } | |
8762 | ||
8763 | ret = of_property_read_u32(np, "battery,wa_float_voltage", | |
8764 | (unsigned int *)&pdata->wa_float_voltage); | |
8765 | if (ret) { | |
8766 | pdata->wa_float_voltage = 40500; | |
8767 | pr_info("%s: wa float voltage is Empty\n", __func__); | |
8768 | } | |
8769 | ||
8770 | ret = of_property_read_u32(np, "battery,wa_fl_check_count", | |
8771 | &pdata->wa_fl_check_count); | |
8772 | if (ret) { | |
8773 | pdata->wa_fl_check_count = 3; | |
8774 | pr_info("%s : swelling fl check count is Empty\n", __func__); | |
8775 | } | |
8776 | ||
8777 | #if defined(CONFIG_BATTERY_SWELLING) | |
8778 | ret = of_property_read_u32(np, "battery,chg_float_voltage", | |
8779 | (unsigned int *)&pdata->swelling_normal_float_voltage); | |
8780 | if (ret) | |
8781 | pr_info("%s: chg_float_voltage is Empty\n", __func__); | |
8782 | ||
8783 | ret = of_property_read_u32(np, "battery,swelling_high_temp_block", | |
8784 | &temp); | |
8785 | pdata->swelling_high_temp_block = (int)temp; | |
8786 | if (ret) | |
8787 | pr_info("%s: swelling high temp block is Empty\n", __func__); | |
8788 | ||
8789 | ret = of_property_read_u32(np, "battery,swelling_high_temp_recov", | |
8790 | &temp); | |
8791 | pdata->swelling_high_temp_recov = (int)temp; | |
8792 | if (ret) | |
8793 | pr_info("%s: swelling high temp recovery is Empty\n", __func__); | |
8794 | ||
8795 | ret = of_property_read_u32(np, "battery,swelling_wc_high_temp_recov", | |
8796 | &temp); | |
8797 | pdata->swelling_wc_high_temp_recov = (int)temp; | |
8798 | if (ret) { | |
8799 | pdata->swelling_wc_high_temp_recov = pdata->swelling_high_temp_recov; | |
8800 | pr_info("%s: swelling wireless high temp recovery is %d\n", __func__, pdata->swelling_wc_high_temp_recov); | |
8801 | } | |
8802 | ||
8803 | ret = of_property_read_u32(np, "battery,swelling_low_temp_block_1st", | |
8804 | &temp); | |
8805 | pdata->swelling_low_temp_block_1st = (int)temp; | |
8806 | if (ret) | |
8807 | pr_info("%s: swelling low temp block is Empty\n", __func__); | |
8808 | ||
8809 | ret = of_property_read_u32(np, "battery,swelling_low_temp_recov_1st", | |
8810 | &temp); | |
8811 | pdata->swelling_low_temp_recov_1st = (int)temp; | |
8812 | if (ret) | |
8813 | pr_info("%s: swelling low temp recovery is Empty\n", __func__); | |
8814 | ||
8815 | ret = of_property_read_u32(np, "battery,swelling_low_temp_block_2nd", | |
8816 | &temp); | |
8817 | pdata->swelling_low_temp_block_2nd = (int)temp; | |
8818 | if (ret) | |
8819 | pr_info("%s: swelling low temp block is Empty\n", __func__); | |
8820 | ||
8821 | ret = of_property_read_u32(np, "battery,swelling_low_temp_recov_2nd", | |
8822 | &temp); | |
8823 | pdata->swelling_low_temp_recov_2nd = (int)temp; | |
8824 | if (ret) | |
8825 | pr_info("%s: swelling low temp recovery 2nd is Empty\n", __func__); | |
8826 | ||
8827 | ret = of_property_read_u32(np, "battery,swelling_low_temp_current", | |
8828 | &pdata->swelling_low_temp_current); | |
8829 | if (ret) { | |
8830 | pr_info("%s: swelling_low_temp_current is Empty, Defualt value 600mA \n", __func__); | |
8831 | pdata->swelling_low_temp_current = 600; | |
8832 | } | |
8833 | ||
8834 | ret = of_property_read_u32(np, "battery,swelling_low_temp_topoff", | |
8835 | &pdata->swelling_low_temp_topoff); | |
8836 | if (ret) { | |
8837 | pr_info("%s: swelling_low_temp_topoff is Empty, Defualt value 200mA \n", __func__); | |
8838 | pdata->swelling_low_temp_topoff = 200; | |
8839 | } | |
8840 | ||
8841 | ret = of_property_read_u32(np, "battery,swelling_high_temp_current", | |
8842 | &pdata->swelling_high_temp_current); | |
8843 | if (ret) { | |
8844 | pr_info("%s: swelling_low_temp_current is Empty, Defualt value 1300mA \n", __func__); | |
8845 | pdata->swelling_high_temp_current = 1300; | |
8846 | } | |
8847 | ||
8848 | ret = of_property_read_u32(np, "battery,swelling_high_temp_topoff", | |
8849 | &pdata->swelling_high_temp_topoff); | |
8850 | if (ret) { | |
8851 | pr_info("%s: swelling_high_temp_topoff is Empty, Defualt value 200mA \n", __func__); | |
8852 | pdata->swelling_high_temp_topoff = 200; | |
8853 | } | |
8854 | ||
8855 | ret = of_property_read_u32(np, "battery,swelling_wc_high_temp_current", | |
8856 | &pdata->swelling_wc_high_temp_current); | |
8857 | if (ret) { | |
8858 | pr_info("%s: swelling_wc_high_temp_current is Empty, Defualt value 600mA \n", __func__); | |
8859 | pdata->swelling_low_temp_current = 600; | |
8860 | } | |
8861 | ||
8862 | ret = of_property_read_u32(np, "battery,swelling_wc_low_temp_current", | |
8863 | &pdata->swelling_wc_low_temp_current); | |
8864 | if (ret) { | |
8865 | pr_info("%s: swelling_wc_low_temp_current is Empty, Defualt value 600mA \n", __func__); | |
8866 | pdata->swelling_low_temp_current = 600; | |
8867 | } | |
8868 | ||
8869 | ret = of_property_read_u32(np, "battery,swelling_drop_float_voltage", | |
8870 | (unsigned int *)&pdata->swelling_drop_float_voltage); | |
8871 | if (ret) { | |
8872 | pr_info("%s: swelling drop float voltage is Empty, Default value 4250mV \n", __func__); | |
8873 | pdata->swelling_drop_float_voltage = 4250; | |
8874 | pdata->swelling_drop_voltage_condition = 4250; | |
8875 | } else { | |
8876 | pdata->swelling_drop_voltage_condition = (pdata->swelling_drop_float_voltage > 10000) ? | |
8877 | (pdata->swelling_drop_float_voltage / 10) : (pdata->swelling_drop_float_voltage); | |
8878 | pr_info("%s : swelling drop voltage(set : %d, condition : %d)\n", __func__, | |
8879 | pdata->swelling_drop_float_voltage, pdata->swelling_drop_voltage_condition); | |
8880 | } | |
8881 | ||
8882 | ret = of_property_read_u32(np, "battery,swelling_high_rechg_voltage", | |
8883 | (unsigned int *)&pdata->swelling_high_rechg_voltage); | |
8884 | if (ret) { | |
8885 | pr_info("%s: swelling_high_rechg_voltage is Empty\n", __func__); | |
8886 | pdata->swelling_high_rechg_voltage = 4150; | |
8887 | } | |
8888 | ||
8889 | ret = of_property_read_u32(np, "battery,swelling_low_rechg_voltage", | |
8890 | (unsigned int *)&pdata->swelling_low_rechg_voltage); | |
8891 | if (ret) { | |
8892 | pr_info("%s: swelling_low_rechg_voltage is Empty\n", __func__); | |
8893 | pdata->swelling_low_rechg_voltage = 4000; | |
8894 | } | |
8895 | ||
8896 | pr_info("%s : SWELLING_HIGH_TEMP(%d) SWELLING_HIGH_TEMP_RECOVERY(%d)\n" | |
8897 | "SWELLING_LOW_TEMP_1st(%d) SWELLING_LOW_TEMP_RECOVERY_1st(%d) " | |
8898 | "SWELLING_LOW_TEMP_2nd(%d) SWELLING_LOW_TEMP_RECOVERY_2nd(%d) " | |
8899 | "SWELLING_LOW_CURRENT(%d, %d), SWELLING_HIGH_CURRENT(%d, %d)\n" | |
8900 | "SWELLING_LOW_RCHG_VOL(%d), SWELLING_HIGH_RCHG_VOL(%d)\n", | |
8901 | __func__, pdata->swelling_high_temp_block, pdata->swelling_high_temp_recov, | |
8902 | pdata->swelling_low_temp_block_1st, pdata->swelling_low_temp_recov_1st, | |
8903 | pdata->swelling_low_temp_block_2nd, pdata->swelling_low_temp_recov_2nd, | |
8904 | pdata->swelling_low_temp_current, pdata->swelling_low_temp_topoff, | |
8905 | pdata->swelling_high_temp_current, pdata->swelling_high_temp_topoff, | |
8906 | pdata->swelling_low_rechg_voltage, pdata->swelling_high_rechg_voltage); | |
8907 | #endif | |
8908 | ||
8909 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
8910 | ret = of_property_read_u32(np, "battery,ttf_hv_12v_charge_current", | |
8911 | &pdata->ttf_hv_12v_charge_current); | |
8912 | if (ret) { | |
8913 | pdata->ttf_hv_12v_charge_current = | |
8914 | pdata->charging_current[SEC_BATTERY_CABLE_12V_TA].fast_charging_current; | |
8915 | pr_info("%s: ttf_hv_12v_charge_current is Empty, Defualt value %d \n", | |
8916 | __func__, pdata->ttf_hv_12v_charge_current); | |
8917 | } | |
8918 | ret = of_property_read_u32(np, "battery,ttf_hv_charge_current", | |
8919 | &pdata->ttf_hv_charge_current); | |
8920 | if (ret) { | |
8921 | pdata->ttf_hv_charge_current = | |
8922 | pdata->charging_current[SEC_BATTERY_CABLE_9V_TA].fast_charging_current; | |
8923 | pr_info("%s: ttf_hv_charge_current is Empty, Defualt value %d \n", | |
8924 | __func__, pdata->ttf_hv_charge_current); | |
8925 | } | |
8926 | ||
8927 | ret = of_property_read_u32(np, "battery,ttf_hv_wireless_charge_current", | |
8928 | &pdata->ttf_hv_wireless_charge_current); | |
8929 | if (ret) { | |
8930 | pr_info("%s: ttf_hv_wireless_charge_current is Empty, Defualt value 0 \n", __func__); | |
8931 | pdata->ttf_hv_wireless_charge_current = | |
8932 | pdata->charging_current[SEC_BATTERY_CABLE_HV_WIRELESS].fast_charging_current - 300; | |
8933 | } | |
8934 | ||
8935 | ret = of_property_read_u32(np, "battery,ttf_wireless_charge_current", | |
8936 | &pdata->ttf_wireless_charge_current); | |
8937 | if (ret) { | |
8938 | pr_info("%s: ttf_wireless_charge_current is Empty, Defualt value 0 \n", __func__); | |
8939 | pdata->ttf_wireless_charge_current = | |
8940 | pdata->charging_current[SEC_BATTERY_CABLE_WIRELESS].input_current_limit; | |
8941 | } | |
8942 | #endif | |
8943 | ||
8944 | #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE) | |
8945 | /* wpc_det */ | |
8946 | ret = pdata->wpc_det = of_get_named_gpio(np, "battery,wpc_det", 0); | |
8947 | if (ret < 0) { | |
8948 | pr_info("%s : can't get wpc_det\n", __func__); | |
8949 | } | |
8950 | #endif | |
8951 | ||
8952 | /* wpc_en */ | |
8953 | ret = pdata->wpc_en = of_get_named_gpio(np, "battery,wpc_en", 0); | |
8954 | if (ret < 0) { | |
8955 | pr_info("%s : can't get wpc_en\n", __func__); | |
8956 | pdata->wpc_en = 0; | |
8957 | } | |
8958 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
8959 | p = of_get_property(np, "battery,age_data", &len); | |
8960 | if (p) { | |
8961 | battery->pdata->num_age_step = len / sizeof(sec_age_data_t); | |
8962 | battery->pdata->age_data = kzalloc(len, GFP_KERNEL); | |
8963 | ret = of_property_read_u32_array(np, "battery,age_data", | |
8964 | (u32 *)battery->pdata->age_data, len/sizeof(u32)); | |
8965 | if (ret) { | |
8966 | pr_err("%s failed to read battery->pdata->age_data: %d\n", | |
8967 | __func__, ret); | |
8968 | kfree(battery->pdata->age_data); | |
8969 | battery->pdata->age_data = NULL; | |
8970 | battery->pdata->num_age_step = 0; | |
8971 | } | |
8972 | pr_err("%s num_age_step : %d\n", __func__, battery->pdata->num_age_step); | |
8973 | for (len = 0; len < battery->pdata->num_age_step; ++len) { | |
8974 | pr_err("[%d/%d]cycle:%d, float:%d, full_v:%d, recharge_v:%d, soc:%d\n", | |
8975 | len, battery->pdata->num_age_step-1, | |
8976 | battery->pdata->age_data[len].cycle, | |
8977 | battery->pdata->age_data[len].float_voltage, | |
8978 | battery->pdata->age_data[len].full_condition_vcell, | |
8979 | battery->pdata->age_data[len].recharge_condition_vcell, | |
8980 | battery->pdata->age_data[len].full_condition_soc); | |
8981 | } | |
8982 | } else { | |
8983 | battery->pdata->num_age_step = 0; | |
8984 | pr_err("%s there is not age_data\n", __func__); | |
8985 | } | |
8986 | #endif | |
8987 | ||
8988 | ret = of_property_read_u32(np, "battery,siop_input_limit_current", | |
8989 | &pdata->siop_input_limit_current); | |
8990 | if (ret) | |
8991 | pdata->siop_input_limit_current = SIOP_INPUT_LIMIT_CURRENT; | |
8992 | ||
8993 | ret = of_property_read_u32(np, "battery,siop_charging_limit_current", | |
8994 | &pdata->siop_charging_limit_current); | |
8995 | if (ret) | |
8996 | pdata->siop_charging_limit_current = SIOP_CHARGING_LIMIT_CURRENT; | |
8997 | ||
8998 | ret = of_property_read_u32(np, "battery,siop_hv_12v_input_limit_current", | |
8999 | &pdata->siop_hv_12v_input_limit_current); | |
9000 | if (ret) | |
9001 | pdata->siop_hv_12v_input_limit_current = SIOP_HV_12V_INPUT_LIMIT_CURRENT; | |
9002 | ||
9003 | ret = of_property_read_u32(np, "battery,siop_hv_12v_charging_limit_current", | |
9004 | &pdata->siop_hv_12v_charging_limit_current); | |
9005 | if (ret) | |
9006 | pdata->siop_hv_12v_charging_limit_current = SIOP_HV_12V_CHARGING_LIMIT_CURRENT; | |
9007 | ||
9008 | ret = of_property_read_u32(np, "battery,siop_hv_input_limit_current", | |
9009 | &pdata->siop_hv_input_limit_current); | |
9010 | if (ret) | |
9011 | pdata->siop_hv_input_limit_current = SIOP_HV_INPUT_LIMIT_CURRENT; | |
9012 | ||
9013 | ret = of_property_read_u32(np, "battery,siop_hv_charging_limit_current", | |
9014 | &pdata->siop_hv_charging_limit_current); | |
9015 | if (ret) | |
9016 | pdata->siop_hv_charging_limit_current = SIOP_HV_CHARGING_LIMIT_CURRENT; | |
9017 | ||
9018 | ret = of_property_read_u32(np, "battery,siop_wireless_input_limit_current", | |
9019 | &pdata->siop_wireless_input_limit_current); | |
9020 | if (ret) | |
9021 | pdata->siop_wireless_input_limit_current = SIOP_WIRELESS_INPUT_LIMIT_CURRENT; | |
9022 | ||
9023 | ret = of_property_read_u32(np, "battery,siop_wireless_charging_limit_current", | |
9024 | &pdata->siop_wireless_charging_limit_current); | |
9025 | if (ret) | |
9026 | pdata->siop_wireless_charging_limit_current = SIOP_WIRELESS_CHARGING_LIMIT_CURRENT; | |
9027 | ||
9028 | ret = of_property_read_u32(np, "battery,siop_hv_wireless_input_limit_current", | |
9029 | &pdata->siop_hv_wireless_input_limit_current); | |
9030 | if (ret) | |
9031 | pdata->siop_hv_wireless_input_limit_current = SIOP_HV_WIRELESS_INPUT_LIMIT_CURRENT; | |
9032 | ||
9033 | ret = of_property_read_u32(np, "battery,siop_hv_wireless_charging_limit_current", | |
9034 | &pdata->siop_hv_wireless_charging_limit_current); | |
9035 | if (ret) | |
9036 | pdata->siop_hv_wireless_charging_limit_current = SIOP_HV_WIRELESS_CHARGING_LIMIT_CURRENT; | |
9037 | ||
9038 | ret = of_property_read_u32(np, "battery,max_input_voltage", | |
9039 | &pdata->max_input_voltage); | |
9040 | if (ret) | |
9041 | pdata->max_input_voltage = 12000; | |
9042 | ||
9043 | ret = of_property_read_u32(np, "battery,max_input_current", | |
9044 | &pdata->max_input_current); | |
9045 | if (ret) | |
9046 | pdata->max_input_current = 3000; | |
9047 | ||
9048 | ret = of_property_read_u32(np, "battery,pd_charging_charge_power", | |
9049 | &pdata->pd_charging_charge_power); | |
9050 | if (ret) { | |
9051 | pr_err("%s: pd_charging_charge_power is Empty\n", __func__); | |
9052 | pdata->pd_charging_charge_power = 15000; | |
9053 | } | |
9054 | ||
9055 | ret = of_property_read_u32(np, "battery,nv_charge_power", | |
9056 | &pdata->nv_charge_power); | |
9057 | if (ret) { | |
9058 | pr_err("%s: nv_charge_power is Empty\n", __func__); | |
9059 | pdata->nv_charge_power = | |
9060 | SEC_INPUT_VOLTAGE_5V * pdata->default_input_current; | |
9061 | } | |
9062 | ||
9063 | pr_info("%s: vendor : %s, technology : %d, cable_check_type : %d\n" | |
9064 | "cable_source_type : %d, event_waiting_time : %d\n" | |
9065 | "polling_type : %d, initial_count : %d, check_count : %d\n" | |
9066 | "check_adc_max : %d, check_adc_min : %d\n" | |
9067 | "ovp_uvlo_check_type : %d, thermal_source : %d\n" | |
9068 | "temp_check_type : %d, temp_check_count : %d, nv_charge_power : %d\n", | |
9069 | __func__, | |
9070 | pdata->vendor, pdata->technology,pdata->cable_check_type, | |
9071 | pdata->cable_source_type, pdata->event_waiting_time, | |
9072 | pdata->polling_type, pdata->monitor_initial_count, | |
9073 | pdata->check_count, pdata->check_adc_max, pdata->check_adc_min, | |
9074 | pdata->ovp_uvlo_check_type, pdata->thermal_source, | |
9075 | pdata->temp_check_type, pdata->temp_check_count, pdata->nv_charge_power); | |
9076 | ||
9077 | #if defined(CONFIG_STEP_CHARGING) | |
9078 | sec_step_charging_init(battery, dev); | |
9079 | #else | |
9080 | ret = of_property_read_u32(np, "battery,max_charging_current", | |
9081 | &pdata->max_charging_current); | |
9082 | if (ret) { | |
9083 | pr_err("%s: max_charging_current is Empty\n", __func__); | |
9084 | pdata->max_charging_current = 3000; | |
9085 | } | |
9086 | ||
9087 | #endif | |
9088 | return 0; | |
9089 | } | |
9090 | ||
9091 | static void sec_bat_parse_mode_dt(struct sec_battery_info *battery) | |
9092 | { | |
9093 | struct device_node *np; | |
9094 | sec_battery_platform_data_t *pdata = battery->pdata; | |
9095 | int ret = 0; | |
9096 | u32 temp = 0; | |
9097 | ||
9098 | np = of_find_node_by_name(NULL, "battery"); | |
9099 | if (!np) { | |
9100 | pr_err("%s np NULL\n", __func__); | |
9101 | return; | |
9102 | } | |
9103 | ||
9104 | if (battery->store_mode) { | |
9105 | ret = of_property_read_u32(np, "battery,store_mode_afc_input_current", | |
9106 | &pdata->store_mode_afc_input_current); | |
9107 | if (ret) { | |
9108 | pr_info("%s : store_mode_afc_input_current is Empty\n", __func__); | |
9109 | pdata->store_mode_afc_input_current = 440; | |
9110 | } | |
9111 | ||
9112 | ret = of_property_read_u32(np, "battery,store_mode_hv_wireless_input_current", | |
9113 | &pdata->store_mode_hv_wireless_input_current); | |
9114 | if (ret) { | |
9115 | pr_info("%s : store_mode_hv_wireless_input_current is Empty\n", __func__); | |
9116 | pdata->store_mode_hv_wireless_input_current = 400; | |
9117 | } | |
9118 | ||
9119 | if (pdata->wpc_temp_check) { | |
9120 | ret = of_property_read_u32(np, "battery,wpc_store_high_temp", | |
9121 | &temp); | |
9122 | if (!ret) | |
9123 | pdata->wpc_high_temp = temp; | |
9124 | ||
9125 | ret = of_property_read_u32(np, "battery,wpc_store_high_temp_recovery", | |
9126 | &temp); | |
9127 | if (!ret) | |
9128 | pdata->wpc_high_temp_recovery = temp; | |
9129 | ||
9130 | ret = of_property_read_u32(np, "battery,wpc_store_charging_limit_current", | |
9131 | &temp); | |
9132 | if (!ret) | |
9133 | pdata->wpc_charging_limit_current = temp; | |
9134 | ||
9135 | ret = of_property_read_u32(np, "battery,wpc_store_lcd_on_high_temp", | |
9136 | &temp); | |
9137 | if (!ret) | |
9138 | pdata->wpc_lcd_on_high_temp = (int)temp; | |
9139 | ||
9140 | ret = of_property_read_u32(np, "battery,wpc_store_lcd_on_high_temp_rec", | |
9141 | &temp); | |
9142 | if (!ret) | |
9143 | pdata->wpc_lcd_on_high_temp_rec = (int)temp; | |
9144 | ||
9145 | pr_info("%s: update store_mode - wpc high_temp(t:%d, r:%d), lcd_on_high_temp(t:%d, r:%d), curr(%d)\n", | |
9146 | __func__, | |
9147 | pdata->wpc_high_temp, pdata->wpc_high_temp_recovery, | |
9148 | pdata->wpc_lcd_on_high_temp, pdata->wpc_lcd_on_high_temp_rec, | |
9149 | pdata->wpc_charging_limit_current); | |
9150 | } | |
9151 | ||
9152 | ret = of_property_read_u32(np, "battery,siop_store_hv_wireless_input_limit_current", | |
9153 | &temp); | |
9154 | if (!ret) | |
9155 | pdata->siop_hv_wireless_input_limit_current = temp; | |
9156 | else | |
9157 | pdata->siop_hv_wireless_input_limit_current = SIOP_STORE_HV_WIRELESS_CHARGING_LIMIT_CURRENT; | |
9158 | pr_info("%s: update siop_hv_wireless_input_limit_current(%d)\n", | |
9159 | __func__, pdata->siop_hv_wireless_input_limit_current); | |
9160 | } | |
9161 | } | |
9162 | ||
9163 | static void sec_bat_parse_mode_dt_work(struct work_struct *work) | |
9164 | { | |
9165 | struct sec_battery_info *battery = container_of(work, | |
9166 | struct sec_battery_info, parse_mode_dt_work.work); | |
9167 | ||
9168 | sec_bat_parse_mode_dt(battery); | |
9169 | ||
9170 | if (is_hv_wire_type(battery->cable_type) || | |
9171 | is_hv_wireless_type(battery->cable_type)) { | |
9172 | sec_bat_set_charging_current(battery); | |
9173 | } | |
9174 | ||
9175 | wake_unlock(&battery->parse_mode_dt_wake_lock); | |
9176 | } | |
9177 | #endif | |
9178 | ||
9179 | #ifdef CONFIG_OF | |
9180 | extern sec_battery_platform_data_t sec_battery_pdata; | |
9181 | #endif | |
9182 | ||
9183 | #if !defined(CONFIG_MUIC_NOTIFIER) | |
9184 | static void cable_initial_check(struct sec_battery_info *battery) | |
9185 | { | |
9186 | union power_supply_propval value; | |
9187 | ||
9188 | pr_info("%s : current_cable_type : (%d)\n", __func__, battery->cable_type); | |
9189 | ||
9190 | if (SEC_BATTERY_CABLE_NONE != battery->cable_type) { | |
9191 | if (battery->cable_type == SEC_BATTERY_CABLE_POWER_SHARING) { | |
9192 | value.intval = battery->cable_type; | |
9193 | psy_do_property("ps", set, | |
9194 | POWER_SUPPLY_PROP_ONLINE, value); | |
9195 | } else { | |
9196 | value.intval = battery->cable_type; | |
9197 | psy_do_property("battery", set, | |
9198 | POWER_SUPPLY_PROP_ONLINE, value); | |
9199 | } | |
9200 | } else { | |
9201 | psy_do_property(battery->pdata->charger_name, get, | |
9202 | POWER_SUPPLY_PROP_ONLINE, value); | |
9203 | if (value.intval == SEC_BATTERY_CABLE_WIRELESS) { | |
9204 | value.intval = 1; | |
9205 | psy_do_property("wireless", set, | |
9206 | POWER_SUPPLY_PROP_ONLINE, value); | |
9207 | } | |
9208 | } | |
9209 | } | |
9210 | #endif | |
9211 | ||
9212 | static void sec_bat_init_chg_work(struct work_struct *work) | |
9213 | { | |
9214 | struct sec_battery_info *battery = container_of(work, | |
9215 | struct sec_battery_info, init_chg_work.work); | |
9216 | ||
9217 | if (battery->cable_type == SEC_BATTERY_CABLE_NONE && | |
9218 | !(battery->misc_event & BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE)) { | |
9219 | pr_info("%s: disable charging\n", __func__); | |
9220 | sec_bat_set_charge(battery, SEC_BAT_CHG_MODE_CHARGING_OFF); | |
9221 | } | |
9222 | } | |
9223 | ||
9224 | static const struct power_supply_desc battery_power_supply_desc = { | |
9225 | .name = "battery", | |
9226 | .type = POWER_SUPPLY_TYPE_BATTERY, | |
9227 | .properties = sec_battery_props, | |
9228 | .num_properties = ARRAY_SIZE(sec_battery_props), | |
9229 | .get_property = sec_bat_get_property, | |
9230 | .set_property = sec_bat_set_property, | |
9231 | }; | |
9232 | ||
9233 | static const struct power_supply_desc usb_power_supply_desc = { | |
9234 | .name = "usb", | |
9235 | .type = POWER_SUPPLY_TYPE_USB, | |
9236 | .properties = sec_power_props, | |
9237 | .num_properties = ARRAY_SIZE(sec_power_props), | |
9238 | .get_property = sec_usb_get_property, | |
9239 | }; | |
9240 | ||
9241 | static const struct power_supply_desc ac_power_supply_desc = { | |
9242 | .name = "ac", | |
9243 | .type = POWER_SUPPLY_TYPE_MAINS, | |
9244 | .properties = sec_ac_props, | |
9245 | .num_properties = ARRAY_SIZE(sec_ac_props), | |
9246 | .get_property = sec_ac_get_property, | |
9247 | }; | |
9248 | ||
9249 | static const struct power_supply_desc wireless_power_supply_desc = { | |
9250 | .name = "wireless", | |
9251 | .type = POWER_SUPPLY_TYPE_WIRELESS, | |
9252 | .properties = sec_wireless_props, | |
9253 | .num_properties = ARRAY_SIZE(sec_wireless_props), | |
9254 | .get_property = sec_wireless_get_property, | |
9255 | .set_property = sec_wireless_set_property, | |
9256 | }; | |
9257 | ||
9258 | static const struct power_supply_desc ps_power_supply_desc = { | |
9259 | .name = "ps", | |
9260 | .type = POWER_SUPPLY_TYPE_POWER_SHARING, | |
9261 | .properties = sec_ps_props, | |
9262 | .num_properties = ARRAY_SIZE(sec_ps_props), | |
9263 | .get_property = sec_ps_get_property, | |
9264 | .set_property = sec_ps_set_property, | |
9265 | }; | |
9266 | ||
9267 | static int sec_battery_probe(struct platform_device *pdev) | |
9268 | { | |
9269 | sec_battery_platform_data_t *pdata = NULL; | |
9270 | struct sec_battery_info *battery; | |
9271 | struct power_supply_config battery_cfg = {}; | |
9272 | ||
9273 | int ret = 0; | |
9274 | #ifndef CONFIG_OF | |
9275 | int i = 0; | |
9276 | #endif | |
9277 | ||
9278 | union power_supply_propval value = {0, }; | |
9279 | ||
9280 | dev_info(&pdev->dev, | |
9281 | "%s: SEC Battery Driver Loading\n", __func__); | |
9282 | ||
9283 | battery = kzalloc(sizeof(*battery), GFP_KERNEL); | |
9284 | if (!battery) | |
9285 | return -ENOMEM; | |
9286 | ||
9287 | if (pdev->dev.of_node) { | |
9288 | pdata = devm_kzalloc(&pdev->dev, | |
9289 | sizeof(sec_battery_platform_data_t), | |
9290 | GFP_KERNEL); | |
9291 | if (!pdata) { | |
9292 | dev_err(&pdev->dev, "Failed to allocate memory\n"); | |
9293 | ret = -ENOMEM; | |
9294 | goto err_bat_free; | |
9295 | } | |
9296 | ||
9297 | battery->pdata = pdata; | |
9298 | ||
9299 | if (sec_bat_parse_dt(&pdev->dev, battery)) { | |
9300 | dev_err(&pdev->dev, | |
9301 | "%s: Failed to get battery dt\n", __func__); | |
9302 | ret = -EINVAL; | |
9303 | goto err_bat_free; | |
9304 | } | |
9305 | } else { | |
9306 | pdata = dev_get_platdata(&pdev->dev); | |
9307 | battery->pdata = pdata; | |
9308 | } | |
9309 | ||
9310 | platform_set_drvdata(pdev, battery); | |
9311 | ||
9312 | battery->dev = &pdev->dev; | |
9313 | ||
9314 | mutex_init(&battery->adclock); | |
9315 | mutex_init(&battery->iolock); | |
9316 | mutex_init(&battery->misclock); | |
9317 | mutex_init(&battery->batt_handlelock); | |
9318 | mutex_init(&battery->current_eventlock); | |
9319 | mutex_init(&battery->typec_notylock); | |
9320 | mutex_init(&battery->wclock); | |
9321 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
9322 | mutex_init(&battery->sbmlock); | |
9323 | sec_bat_init_sbm(battery); | |
9324 | #endif | |
9325 | ||
9326 | dev_dbg(battery->dev, "%s: ADC init\n", __func__); | |
9327 | ||
9328 | #ifdef CONFIG_OF | |
9329 | adc_init(pdev, battery); | |
9330 | #else | |
9331 | for (i = 0; i < SEC_BAT_ADC_CHANNEL_NUM; i++) | |
9332 | adc_init(pdev, pdata, i); | |
9333 | #endif | |
9334 | wake_lock_init(&battery->monitor_wake_lock, WAKE_LOCK_SUSPEND, | |
9335 | "sec-battery-monitor"); | |
9336 | wake_lock_init(&battery->cable_wake_lock, WAKE_LOCK_SUSPEND, | |
9337 | "sec-battery-cable"); | |
9338 | wake_lock_init(&battery->vbus_wake_lock, WAKE_LOCK_SUSPEND, | |
9339 | "sec-battery-vbus"); | |
9340 | wake_lock_init(&battery->afc_wake_lock, WAKE_LOCK_SUSPEND, | |
9341 | "sec-battery-afc"); | |
9342 | wake_lock_init(&battery->siop_level_wake_lock, WAKE_LOCK_SUSPEND, | |
9343 | "sec-battery-siop_level"); | |
9344 | wake_lock_init(&battery->ext_event_wake_lock, WAKE_LOCK_SUSPEND, | |
9345 | "sec-battery-ext_event"); | |
9346 | wake_lock_init(&battery->wc_headroom_wake_lock, WAKE_LOCK_SUSPEND, | |
9347 | "sec-battery-wc_headroom"); | |
9348 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
9349 | wake_lock_init(&battery->batt_data_wake_lock, WAKE_LOCK_SUSPEND, | |
9350 | "sec-battery-update-data"); | |
9351 | #endif | |
9352 | wake_lock_init(&battery->misc_event_wake_lock, WAKE_LOCK_SUSPEND, | |
9353 | "sec-battery-misc-event"); | |
9354 | #ifdef CONFIG_OF | |
9355 | wake_lock_init(&battery->parse_mode_dt_wake_lock, WAKE_LOCK_SUSPEND, | |
9356 | "sec-battery-parse_mode_dt"); | |
9357 | #endif | |
9358 | ||
9359 | /* initialization of battery info */ | |
9360 | sec_bat_set_charging_status(battery, | |
9361 | POWER_SUPPLY_STATUS_DISCHARGING); | |
9362 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
9363 | battery->present = true; | |
9364 | battery->is_jig_on = false; | |
9365 | battery->wdt_kick_disable = 0; | |
9366 | ||
9367 | battery->polling_count = 1; /* initial value = 1 */ | |
9368 | battery->polling_time = pdata->polling_time[ | |
9369 | SEC_BATTERY_POLLING_TIME_DISCHARGING]; | |
9370 | battery->polling_in_sleep = false; | |
9371 | battery->polling_short = false; | |
9372 | ||
9373 | battery->check_count = 0; | |
9374 | battery->check_adc_count = 0; | |
9375 | battery->check_adc_value = 0; | |
9376 | ||
9377 | battery->input_current = 0; | |
9378 | battery->charging_current = 0; | |
9379 | battery->topoff_current = 0; | |
9380 | battery->wpc_vout_level = WIRELESS_VOUT_10V; | |
9381 | battery->charging_start_time = 0; | |
9382 | battery->charging_passed_time = 0; | |
9383 | battery->wc_heating_start_time = 0; | |
9384 | battery->wc_heating_passed_time = 0; | |
9385 | battery->charging_next_time = 0; | |
9386 | battery->charging_fullcharged_time = 0; | |
9387 | battery->siop_level = 100; | |
9388 | battery->ext_event = BATT_EXT_EVENT_NONE; | |
9389 | battery->wc_enable = 1; | |
9390 | battery->wc_enable_cnt = 0; | |
9391 | battery->wc_enable_cnt_value = 3; | |
9392 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) | |
9393 | battery->stability_test = 0; | |
9394 | battery->eng_not_full_status = 0; | |
9395 | battery->temperature_test_battery = 0x7FFF; | |
9396 | battery->temperature_test_usb = 0x7FFF; | |
9397 | battery->temperature_test_wpc = 0x7FFF; | |
9398 | battery->temperature_test_chg = 0x7FFF; | |
9399 | #endif | |
9400 | battery->ps_enable = false; | |
9401 | battery->wc_status = SEC_WIRELESS_PAD_NONE; | |
9402 | battery->wc_cv_mode = false; | |
9403 | battery->wire_status = SEC_BATTERY_CABLE_NONE; | |
9404 | ||
9405 | #if defined(CONFIG_BATTERY_SWELLING) | |
9406 | battery->swelling_mode = SWELLING_MODE_NONE; | |
9407 | #endif | |
9408 | battery->charging_block = false; | |
9409 | battery->chg_limit = false; | |
9410 | battery->mix_limit = false; | |
9411 | battery->vbus_limit = false; | |
9412 | battery->usb_temp = 0; | |
9413 | #if defined(CONFIG_ENG_BATTERY_CONCEPT) || defined(CONFIG_SEC_FACTORY) | |
9414 | battery->cooldown_mode = true; | |
9415 | #endif | |
9416 | battery->skip_swelling = false; | |
9417 | battery->led_cover = 0; | |
9418 | battery->wa_float_cnt = 0; | |
9419 | battery->wc_rx_phm_mode = false; | |
9420 | ||
9421 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_USB_100MA, SEC_BAT_CURRENT_EVENT_USB_100MA); | |
9422 | ||
9423 | if (lpcharge) { | |
9424 | battery->temp_highlimit_threshold = | |
9425 | battery->pdata->temp_highlimit_threshold_lpm; | |
9426 | battery->temp_highlimit_recovery = | |
9427 | battery->pdata->temp_highlimit_recovery_lpm; | |
9428 | battery->temp_high_threshold = | |
9429 | battery->pdata->temp_high_threshold_lpm; | |
9430 | battery->temp_high_recovery = | |
9431 | battery->pdata->temp_high_recovery_lpm; | |
9432 | battery->temp_low_recovery = | |
9433 | battery->pdata->temp_low_recovery_lpm; | |
9434 | battery->temp_low_threshold = | |
9435 | battery->pdata->temp_low_threshold_lpm; | |
9436 | } else { | |
9437 | battery->temp_highlimit_threshold = | |
9438 | battery->pdata->temp_highlimit_threshold_normal; | |
9439 | battery->temp_highlimit_recovery = | |
9440 | battery->pdata->temp_highlimit_recovery_normal; | |
9441 | battery->temp_high_threshold = | |
9442 | battery->pdata->temp_high_threshold_normal; | |
9443 | battery->temp_high_recovery = | |
9444 | battery->pdata->temp_high_recovery_normal; | |
9445 | battery->temp_low_recovery = | |
9446 | battery->pdata->temp_low_recovery_normal; | |
9447 | battery->temp_low_threshold = | |
9448 | battery->pdata->temp_low_threshold_normal; | |
9449 | } | |
9450 | ||
9451 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
9452 | battery->is_recharging = false; | |
9453 | battery->cable_type = SEC_BATTERY_CABLE_NONE; | |
9454 | battery->test_mode = 0; | |
9455 | battery->factory_mode = false; | |
9456 | battery->store_mode = false; | |
9457 | battery->slate_mode = false; | |
9458 | battery->is_hc_usb = false; | |
9459 | battery->is_sysovlo = false; | |
9460 | battery->is_vbatovlo = false; | |
9461 | battery->is_abnormal_temp = false; | |
9462 | ||
9463 | battery->safety_timer_set = true; | |
9464 | battery->stop_timer = false; | |
9465 | battery->prev_safety_time = 0; | |
9466 | battery->lcd_status = false; | |
9467 | ||
9468 | #if defined(CONFIG_BATTERY_CISD) | |
9469 | battery->usb_overheat_check = false; | |
9470 | battery->skip_cisd = false; | |
9471 | #endif | |
9472 | ||
9473 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
9474 | battery->batt_cycle = -1; | |
9475 | battery->pdata->age_step = 0; | |
9476 | #endif | |
9477 | ||
9478 | battery->health_change = false; | |
9479 | ||
9480 | /* Check High Voltage charging option for wireless charging */ | |
9481 | /* '1' means disabling High Voltage charging */ | |
9482 | if (charging_night_mode == '1') | |
9483 | sleep_mode = true; | |
9484 | else | |
9485 | sleep_mode = false; | |
9486 | ||
9487 | /* Check High Voltage charging option for wired charging */ | |
9488 | if (get_afc_mode() == CH_MODE_AFC_DISABLE_VAL) { | |
9489 | pr_info("HV wired charging mode is disabled\n"); | |
9490 | sec_bat_set_current_event(battery, | |
9491 | SEC_BAT_CURRENT_EVENT_HV_DISABLE, SEC_BAT_CURRENT_EVENT_HV_DISABLE); | |
9492 | } | |
9493 | ||
9494 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
9495 | battery->sbm_data = false; | |
9496 | #endif | |
9497 | ||
9498 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
9499 | battery->timetofull = -1; | |
9500 | #endif | |
9501 | ||
9502 | if (battery->pdata->charger_name == NULL) | |
9503 | battery->pdata->charger_name = "sec-charger"; | |
9504 | if (battery->pdata->fuelgauge_name == NULL) | |
9505 | battery->pdata->fuelgauge_name = "sec-fuelgauge"; | |
9506 | ||
9507 | /* create work queue */ | |
9508 | battery->monitor_wqueue = | |
9509 | create_singlethread_workqueue(dev_name(&pdev->dev)); | |
9510 | if (!battery->monitor_wqueue) { | |
9511 | dev_err(battery->dev, | |
9512 | "%s: Fail to Create Workqueue\n", __func__); | |
9513 | goto err_irq; | |
9514 | } | |
9515 | ||
9516 | INIT_DELAYED_WORK(&battery->monitor_work, sec_bat_monitor_work); | |
9517 | INIT_DELAYED_WORK(&battery->cable_work, sec_bat_cable_work); | |
9518 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
9519 | INIT_DELAYED_WORK(&battery->timetofull_work, sec_bat_time_to_full_work); | |
9520 | #endif | |
9521 | INIT_DELAYED_WORK(&battery->slowcharging_work, sec_bat_check_slowcharging_work); | |
9522 | INIT_DELAYED_WORK(&battery->afc_work, sec_bat_afc_work); | |
9523 | INIT_DELAYED_WORK(&battery->ext_event_work, sec_bat_ext_event_work); | |
9524 | INIT_DELAYED_WORK(&battery->siop_level_work, sec_bat_siop_level_work); | |
9525 | INIT_DELAYED_WORK(&battery->wc_headroom_work, sec_bat_wc_headroom_work); | |
9526 | #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE) | |
9527 | INIT_DELAYED_WORK(&battery->fw_init_work, sec_bat_fw_init_work); | |
9528 | #endif | |
9529 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
9530 | INIT_DELAYED_WORK(&battery->batt_data_work, sec_bat_update_data_work); | |
9531 | #endif | |
9532 | INIT_DELAYED_WORK(&battery->misc_event_work, sec_bat_misc_event_work); | |
9533 | #ifdef CONFIG_OF | |
9534 | INIT_DELAYED_WORK(&battery->parse_mode_dt_work, sec_bat_parse_mode_dt_work); | |
9535 | #endif | |
9536 | INIT_DELAYED_WORK(&battery->init_chg_work, sec_bat_init_chg_work); | |
9537 | ||
9538 | switch (pdata->polling_type) { | |
9539 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
9540 | INIT_DELAYED_WORK(&battery->polling_work, | |
9541 | sec_bat_polling_work); | |
9542 | break; | |
9543 | case SEC_BATTERY_MONITOR_ALARM: | |
9544 | battery->last_poll_time = ktime_get_boottime(); | |
9545 | alarm_init(&battery->polling_alarm, ALARM_BOOTTIME, | |
9546 | sec_bat_alarm); | |
9547 | break; | |
9548 | default: | |
9549 | break; | |
9550 | } | |
9551 | ||
9552 | #if defined(CONFIG_BATTERY_CISD) | |
9553 | sec_battery_cisd_init(battery); | |
9554 | #endif | |
9555 | ||
9556 | battery_cfg.drv_data = battery; | |
9557 | ||
9558 | /* init power supplier framework */ | |
9559 | battery->psy_ps = power_supply_register(&pdev->dev, &ps_power_supply_desc, &battery_cfg); | |
9560 | if (!battery->psy_ps) { | |
9561 | dev_err(battery->dev, | |
9562 | "%s: Failed to Register psy_ps\n", __func__); | |
9563 | goto err_workqueue; | |
9564 | } | |
9565 | battery->psy_ps->supplied_to = supply_list; | |
9566 | battery->psy_ps->num_supplicants = ARRAY_SIZE(supply_list); | |
9567 | ||
9568 | battery->psy_wireless = power_supply_register(&pdev->dev, &wireless_power_supply_desc, &battery_cfg); | |
9569 | if (!battery->psy_wireless) { | |
9570 | dev_err(battery->dev, | |
9571 | "%s: Failed to Register psy_wireless\n", __func__); | |
9572 | goto err_supply_unreg_ps; | |
9573 | } | |
9574 | battery->psy_wireless->supplied_to = supply_list; | |
9575 | battery->psy_wireless->num_supplicants = ARRAY_SIZE(supply_list); | |
9576 | ||
9577 | battery->psy_usb = power_supply_register(&pdev->dev, &usb_power_supply_desc, &battery_cfg); | |
9578 | if (!battery->psy_usb) { | |
9579 | dev_err(battery->dev, | |
9580 | "%s: Failed to Register psy_usb\n", __func__); | |
9581 | goto err_supply_unreg_wireless; | |
9582 | } | |
9583 | battery->psy_usb->supplied_to = supply_list; | |
9584 | battery->psy_usb->num_supplicants = ARRAY_SIZE(supply_list); | |
9585 | ||
9586 | battery->psy_ac = power_supply_register(&pdev->dev, &ac_power_supply_desc, &battery_cfg); | |
9587 | if (!battery->psy_ac) { | |
9588 | dev_err(battery->dev, | |
9589 | "%s: Failed to Register psy_ac\n", __func__); | |
9590 | goto err_supply_unreg_usb; | |
9591 | } | |
9592 | battery->psy_ac->supplied_to = supply_list; | |
9593 | battery->psy_ac->num_supplicants = ARRAY_SIZE(supply_list); | |
9594 | ||
9595 | battery->psy_bat = power_supply_register(&pdev->dev, &battery_power_supply_desc, &battery_cfg); | |
9596 | if (!battery->psy_bat) { | |
9597 | dev_err(battery->dev, | |
9598 | "%s: Failed to Register psy_bat\n", __func__); | |
9599 | goto err_supply_unreg_ac; | |
9600 | } | |
9601 | ||
9602 | ret = sec_bat_create_attrs(&battery->psy_bat->dev); | |
9603 | if (ret) { | |
9604 | dev_err(battery->dev, | |
9605 | "%s : Failed to create_attrs\n", __func__); | |
9606 | goto err_req_irq; | |
9607 | } | |
9608 | ||
9609 | /* initialize battery level*/ | |
9610 | value.intval = 0; | |
9611 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
9612 | POWER_SUPPLY_PROP_CAPACITY, value); | |
9613 | battery->capacity = value.intval; | |
9614 | ||
9615 | #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE) | |
9616 | /* queue_delayed_work(battery->monitor_wqueue, &battery->fw_init_work, 0); */ | |
9617 | #endif | |
9618 | ||
9619 | /* notify wireless charger driver when sec_battery probe is done, | |
9620 | if wireless charging is possible, POWER_SUPPLY_PROP_ONLINE of wireless property will be called. */ | |
9621 | value.intval = 0; | |
9622 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
9623 | POWER_SUPPLY_PROP_CHARGE_TYPE, value); | |
9624 | ||
9625 | #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY) | |
9626 | battery->store_mode = true; | |
9627 | sec_bat_parse_mode_dt(battery); | |
9628 | #endif | |
9629 | ||
9630 | #if defined(CONFIG_USB_TYPEC_MANAGER_NOTIFIER) | |
9631 | battery->pdic_info.sink_status.rp_currentlvl = RP_CURRENT_LEVEL_NONE; | |
9632 | manager_notifier_register(&battery->usb_typec_nb, | |
9633 | usb_typec_handle_notification, MANAGER_NOTIFY_CCIC_BATTERY); | |
9634 | #else | |
9635 | #if defined(CONFIG_MUIC_NOTIFIER) | |
9636 | muic_notifier_register(&battery->batt_nb, | |
9637 | batt_handle_notification, MUIC_NOTIFY_DEV_CHARGER); | |
9638 | #else | |
9639 | cable_initial_check(battery); | |
9640 | #endif | |
9641 | #if defined(CONFIG_CCIC_NOTIFIER) | |
9642 | pr_info("%s: Registering PDIC_NOTIFY.\n", __func__); | |
9643 | pdic_notifier_register(&battery->pdic_nb, | |
9644 | batt_pdic_handle_notification, PDIC_NOTIFY_DEV_BATTERY); | |
9645 | #endif | |
9646 | #endif | |
9647 | #if defined(CONFIG_VBUS_NOTIFIER) | |
9648 | vbus_notifier_register(&battery->vbus_nb, | |
9649 | vbus_handle_notification, VBUS_NOTIFY_DEV_CHARGER); | |
9650 | #endif | |
9651 | ||
9652 | value.intval = true; | |
9653 | psy_do_property(battery->pdata->charger_name, set, | |
9654 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, value); | |
9655 | ||
9656 | /* make fg_reset true again for actual normal booting after recovery kernel is done */ | |
9657 | if (fg_reset && (bootmode == 2)) { | |
9658 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
9659 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
9660 | pr_info("%s: make fg_reset true again for actual normal booting\n", __func__); | |
9661 | } | |
9662 | ||
9663 | if ((battery->cable_type == SEC_BATTERY_CABLE_NONE) || | |
9664 | (battery->cable_type == SEC_BATTERY_CABLE_PREPARE_TA)) { | |
9665 | queue_delayed_work(battery->monitor_wqueue, &battery->init_chg_work, 0); | |
9666 | ||
9667 | dev_info(&pdev->dev, | |
9668 | "%s: SEC Battery Driver Monitorwork\n", __func__); | |
9669 | wake_lock(&battery->monitor_wake_lock); | |
9670 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
9671 | } | |
9672 | ||
9673 | if (battery->pdata->check_battery_callback) | |
9674 | battery->present = battery->pdata->check_battery_callback(); | |
9675 | ||
9676 | dev_info(battery->dev, | |
9677 | "%s: SEC Battery Driver Loaded\n", __func__); | |
9678 | return 0; | |
9679 | ||
9680 | err_req_irq: | |
9681 | if (battery->pdata->bat_irq) | |
9682 | free_irq(battery->pdata->bat_irq, battery); | |
9683 | power_supply_unregister(battery->psy_bat); | |
9684 | err_supply_unreg_ac: | |
9685 | power_supply_unregister(battery->psy_ac); | |
9686 | err_supply_unreg_usb: | |
9687 | power_supply_unregister(battery->psy_usb); | |
9688 | err_supply_unreg_wireless: | |
9689 | power_supply_unregister(battery->psy_wireless); | |
9690 | err_supply_unreg_ps: | |
9691 | power_supply_unregister(battery->psy_ps); | |
9692 | err_workqueue: | |
9693 | destroy_workqueue(battery->monitor_wqueue); | |
9694 | err_irq: | |
9695 | wake_lock_destroy(&battery->monitor_wake_lock); | |
9696 | wake_lock_destroy(&battery->cable_wake_lock); | |
9697 | wake_lock_destroy(&battery->vbus_wake_lock); | |
9698 | wake_lock_destroy(&battery->afc_wake_lock); | |
9699 | wake_lock_destroy(&battery->siop_level_wake_lock); | |
9700 | wake_lock_destroy(&battery->ext_event_wake_lock); | |
9701 | wake_lock_destroy(&battery->wc_headroom_wake_lock); | |
9702 | #if defined(CONFIG_UPDATE_BATTERY_DATA) | |
9703 | wake_lock_destroy(&battery->batt_data_wake_lock); | |
9704 | #endif | |
9705 | wake_lock_destroy(&battery->misc_event_wake_lock); | |
9706 | #ifdef CONFIG_OF | |
9707 | wake_lock_destroy(&battery->parse_mode_dt_wake_lock); | |
9708 | #endif | |
9709 | mutex_destroy(&battery->adclock); | |
9710 | mutex_destroy(&battery->iolock); | |
9711 | mutex_destroy(&battery->misclock); | |
9712 | mutex_destroy(&battery->batt_handlelock); | |
9713 | mutex_destroy(&battery->current_eventlock); | |
9714 | mutex_destroy(&battery->typec_notylock); | |
9715 | mutex_destroy(&battery->wclock); | |
9716 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
9717 | mutex_destroy(&battery->sbmlock); | |
9718 | sec_bat_exit_sbm(battery); | |
9719 | #endif | |
9720 | kfree(pdata); | |
9721 | err_bat_free: | |
9722 | kfree(battery); | |
9723 | ||
9724 | return ret; | |
9725 | } | |
9726 | ||
9727 | static int sec_battery_remove(struct platform_device *pdev) | |
9728 | { | |
9729 | struct sec_battery_info *battery = platform_get_drvdata(pdev); | |
9730 | #ifndef CONFIG_OF | |
9731 | int i; | |
9732 | #endif | |
9733 | ||
9734 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
9735 | ||
9736 | switch (battery->pdata->polling_type) { | |
9737 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
9738 | cancel_delayed_work(&battery->polling_work); | |
9739 | break; | |
9740 | case SEC_BATTERY_MONITOR_ALARM: | |
9741 | alarm_cancel(&battery->polling_alarm); | |
9742 | break; | |
9743 | default: | |
9744 | break; | |
9745 | } | |
9746 | ||
9747 | flush_workqueue(battery->monitor_wqueue); | |
9748 | destroy_workqueue(battery->monitor_wqueue); | |
9749 | wake_lock_destroy(&battery->monitor_wake_lock); | |
9750 | wake_lock_destroy(&battery->cable_wake_lock); | |
9751 | wake_lock_destroy(&battery->vbus_wake_lock); | |
9752 | wake_lock_destroy(&battery->afc_wake_lock); | |
9753 | wake_lock_destroy(&battery->siop_level_wake_lock); | |
9754 | wake_lock_destroy(&battery->ext_event_wake_lock); | |
9755 | wake_lock_destroy(&battery->misc_event_wake_lock); | |
9756 | mutex_destroy(&battery->adclock); | |
9757 | mutex_destroy(&battery->iolock); | |
9758 | mutex_destroy(&battery->misclock); | |
9759 | mutex_destroy(&battery->batt_handlelock); | |
9760 | mutex_destroy(&battery->current_eventlock); | |
9761 | mutex_destroy(&battery->typec_notylock); | |
9762 | mutex_destroy(&battery->wclock); | |
9763 | ||
9764 | #if defined(CONFIG_BATTERY_SBM_DATA) | |
9765 | mutex_destroy(&battery->sbmlock); | |
9766 | sec_bat_exit_sbm(battery); | |
9767 | #endif | |
9768 | ||
9769 | #ifdef CONFIG_OF | |
9770 | adc_exit(battery); | |
9771 | #else | |
9772 | for (i = 0; i < SEC_BAT_ADC_CHANNEL_NUM; i++) | |
9773 | adc_exit(battery->pdata, i); | |
9774 | #endif | |
9775 | power_supply_unregister(battery->psy_ps); | |
9776 | power_supply_unregister(battery->psy_wireless); | |
9777 | power_supply_unregister(battery->psy_ac); | |
9778 | power_supply_unregister(battery->psy_usb); | |
9779 | power_supply_unregister(battery->psy_bat); | |
9780 | ||
9781 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
9782 | kfree(battery); | |
9783 | ||
9784 | return 0; | |
9785 | } | |
9786 | ||
9787 | static int sec_battery_prepare(struct device *dev) | |
9788 | { | |
9789 | struct sec_battery_info *battery | |
9790 | = dev_get_drvdata(dev); | |
9791 | ||
9792 | dev_info(battery->dev, "%s: Start\n", __func__); | |
9793 | ||
9794 | switch (battery->pdata->polling_type) { | |
9795 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
9796 | cancel_delayed_work(&battery->polling_work); | |
9797 | break; | |
9798 | case SEC_BATTERY_MONITOR_ALARM: | |
9799 | alarm_cancel(&battery->polling_alarm); | |
9800 | break; | |
9801 | default: | |
9802 | break; | |
9803 | } | |
9804 | ||
9805 | /* monitor_wake_lock should be unlocked before cancle monitor_work */ | |
9806 | wake_unlock(&battery->monitor_wake_lock); | |
9807 | cancel_delayed_work_sync(&battery->monitor_work); | |
9808 | ||
9809 | battery->polling_in_sleep = true; | |
9810 | ||
9811 | sec_bat_set_polling(battery); | |
9812 | ||
9813 | /* cancel work for polling | |
9814 | * that is set in sec_bat_set_polling() | |
9815 | * no need for polling in sleep | |
9816 | */ | |
9817 | if (battery->pdata->polling_type == | |
9818 | SEC_BATTERY_MONITOR_WORKQUEUE) | |
9819 | cancel_delayed_work(&battery->polling_work); | |
9820 | ||
9821 | dev_info(battery->dev, "%s: End\n", __func__); | |
9822 | ||
9823 | return 0; | |
9824 | } | |
9825 | ||
9826 | static int sec_battery_suspend(struct device *dev) | |
9827 | { | |
9828 | return 0; | |
9829 | } | |
9830 | ||
9831 | static int sec_battery_resume(struct device *dev) | |
9832 | { | |
9833 | return 0; | |
9834 | } | |
9835 | ||
9836 | static void sec_battery_complete(struct device *dev) | |
9837 | { | |
9838 | struct sec_battery_info *battery | |
9839 | = dev_get_drvdata(dev); | |
9840 | ||
9841 | dev_info(battery->dev, "%s: Start\n", __func__); | |
9842 | ||
9843 | /* cancel current alarm and reset after monitor work */ | |
9844 | if (battery->pdata->polling_type == SEC_BATTERY_MONITOR_ALARM) | |
9845 | alarm_cancel(&battery->polling_alarm); | |
9846 | ||
9847 | wake_lock(&battery->monitor_wake_lock); | |
9848 | queue_delayed_work(battery->monitor_wqueue, | |
9849 | &battery->monitor_work, 0); | |
9850 | ||
9851 | dev_info(battery->dev, "%s: End\n", __func__); | |
9852 | ||
9853 | return; | |
9854 | } | |
9855 | ||
9856 | static void sec_battery_shutdown(struct platform_device *pdev) | |
9857 | { | |
9858 | struct sec_battery_info *battery | |
9859 | = platform_get_drvdata(pdev); | |
9860 | ||
9861 | switch (battery->pdata->polling_type) { | |
9862 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
9863 | cancel_delayed_work(&battery->polling_work); | |
9864 | break; | |
9865 | case SEC_BATTERY_MONITOR_ALARM: | |
9866 | alarm_cancel(&battery->polling_alarm); | |
9867 | break; | |
9868 | default: | |
9869 | break; | |
9870 | } | |
9871 | } | |
9872 | ||
9873 | #ifdef CONFIG_OF | |
9874 | static struct of_device_id sec_battery_dt_ids[] = { | |
9875 | { .compatible = "samsung,sec-battery" }, | |
9876 | { } | |
9877 | }; | |
9878 | MODULE_DEVICE_TABLE(of, sec_battery_dt_ids); | |
9879 | #endif /* CONFIG_OF */ | |
9880 | ||
9881 | static const struct dev_pm_ops sec_battery_pm_ops = { | |
9882 | .prepare = sec_battery_prepare, | |
9883 | .suspend = sec_battery_suspend, | |
9884 | .resume = sec_battery_resume, | |
9885 | .complete = sec_battery_complete, | |
9886 | }; | |
9887 | ||
9888 | static struct platform_driver sec_battery_driver = { | |
9889 | .driver = { | |
9890 | .name = "sec-battery", | |
9891 | .owner = THIS_MODULE, | |
9892 | .pm = &sec_battery_pm_ops, | |
9893 | #ifdef CONFIG_OF | |
9894 | .of_match_table = sec_battery_dt_ids, | |
9895 | #endif | |
9896 | }, | |
9897 | .probe = sec_battery_probe, | |
9898 | .remove = sec_battery_remove, | |
9899 | .shutdown = sec_battery_shutdown, | |
9900 | }; | |
9901 | ||
9902 | static int __init sec_battery_init(void) | |
9903 | { | |
9904 | return platform_driver_register(&sec_battery_driver); | |
9905 | } | |
9906 | ||
9907 | static void __exit sec_battery_exit(void) | |
9908 | { | |
9909 | platform_driver_unregister(&sec_battery_driver); | |
9910 | } | |
9911 | ||
9912 | late_initcall(sec_battery_init); | |
9913 | module_exit(sec_battery_exit); | |
9914 | ||
9915 | MODULE_DESCRIPTION("Samsung Battery Driver"); | |
9916 | MODULE_AUTHOR("Samsung Electronics"); | |
9917 | MODULE_LICENSE("GPL"); |