Commit | Line | Data |
---|---|---|
3c2a0909 S |
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 <linux/battery/sec_battery.h> | |
13 | ||
14 | const char *charger_chip_name; | |
15 | bool slate_mode_state; | |
16 | ||
17 | static struct device_attribute sec_battery_attrs[] = { | |
18 | SEC_BATTERY_ATTR(batt_reset_soc), | |
19 | SEC_BATTERY_ATTR(batt_read_raw_soc), | |
20 | SEC_BATTERY_ATTR(batt_read_adj_soc), | |
21 | SEC_BATTERY_ATTR(batt_type), | |
22 | SEC_BATTERY_ATTR(batt_vfocv), | |
23 | SEC_BATTERY_ATTR(batt_vol_adc), | |
24 | SEC_BATTERY_ATTR(batt_vol_adc_cal), | |
25 | SEC_BATTERY_ATTR(batt_vol_aver), | |
26 | SEC_BATTERY_ATTR(batt_vol_adc_aver), | |
27 | SEC_BATTERY_ATTR(batt_current_ua_now), | |
28 | SEC_BATTERY_ATTR(batt_current_ua_avg), | |
29 | SEC_BATTERY_ATTR(batt_temp), | |
30 | SEC_BATTERY_ATTR(batt_temp_adc), | |
31 | SEC_BATTERY_ATTR(batt_temp_aver), | |
32 | SEC_BATTERY_ATTR(batt_temp_adc_aver), | |
33 | SEC_BATTERY_ATTR(chg_temp), | |
34 | SEC_BATTERY_ATTR(chg_temp_adc), | |
35 | SEC_BATTERY_ATTR(batt_vf_adc), | |
36 | SEC_BATTERY_ATTR(batt_slate_mode), | |
37 | ||
38 | SEC_BATTERY_ATTR(batt_lp_charging), | |
39 | SEC_BATTERY_ATTR(siop_activated), | |
40 | SEC_BATTERY_ATTR(siop_level), | |
41 | SEC_BATTERY_ATTR(batt_charging_source), | |
42 | SEC_BATTERY_ATTR(fg_reg_dump), | |
43 | SEC_BATTERY_ATTR(fg_reset_cap), | |
44 | SEC_BATTERY_ATTR(fg_capacity), | |
45 | SEC_BATTERY_ATTR(fg_asoc), | |
46 | SEC_BATTERY_ATTR(auth), | |
47 | SEC_BATTERY_ATTR(chg_current_adc), | |
48 | SEC_BATTERY_ATTR(wc_adc), | |
49 | SEC_BATTERY_ATTR(wc_status), | |
50 | SEC_BATTERY_ATTR(wc_enable), | |
51 | SEC_BATTERY_ATTR(hv_charger_status), | |
52 | SEC_BATTERY_ATTR(hv_charger_set), | |
53 | SEC_BATTERY_ATTR(factory_mode), | |
54 | SEC_BATTERY_ATTR(store_mode), | |
55 | SEC_BATTERY_ATTR(update), | |
56 | SEC_BATTERY_ATTR(test_mode), | |
57 | ||
58 | SEC_BATTERY_ATTR(call), | |
59 | SEC_BATTERY_ATTR(2g_call), | |
60 | SEC_BATTERY_ATTR(talk_gsm), | |
61 | SEC_BATTERY_ATTR(3g_call), | |
62 | SEC_BATTERY_ATTR(talk_wcdma), | |
63 | SEC_BATTERY_ATTR(music), | |
64 | SEC_BATTERY_ATTR(video), | |
65 | SEC_BATTERY_ATTR(browser), | |
66 | SEC_BATTERY_ATTR(hotspot), | |
67 | SEC_BATTERY_ATTR(camera), | |
68 | SEC_BATTERY_ATTR(camcorder), | |
69 | SEC_BATTERY_ATTR(data_call), | |
70 | SEC_BATTERY_ATTR(wifi), | |
71 | SEC_BATTERY_ATTR(wibro), | |
72 | SEC_BATTERY_ATTR(lte), | |
73 | SEC_BATTERY_ATTR(lcd), | |
74 | SEC_BATTERY_ATTR(gps), | |
75 | SEC_BATTERY_ATTR(event), | |
76 | SEC_BATTERY_ATTR(batt_temp_table), | |
77 | SEC_BATTERY_ATTR(batt_high_current_usb), | |
78 | #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) | |
79 | SEC_BATTERY_ATTR(test_charge_current), | |
80 | #endif | |
81 | SEC_BATTERY_ATTR(set_stability_test), | |
82 | SEC_BATTERY_ATTR(batt_capacity_max), | |
83 | SEC_BATTERY_ATTR(batt_inbat_voltage), | |
84 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
85 | SEC_BATTERY_ATTR(batt_discharging_check), | |
86 | SEC_BATTERY_ATTR(batt_discharging_check_adc), | |
87 | SEC_BATTERY_ATTR(batt_discharging_ntc), | |
88 | SEC_BATTERY_ATTR(batt_discharging_ntc_adc), | |
89 | SEC_BATTERY_ATTR(batt_self_discharging_control), | |
90 | #endif | |
91 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
92 | SEC_BATTERY_ATTR(batt_inbat_wireless_cs100), | |
93 | #endif | |
94 | SEC_BATTERY_ATTR(hmt_ta_connected), | |
95 | SEC_BATTERY_ATTR(hmt_ta_charge), | |
96 | SEC_BATTERY_ATTR(fg_cycle), | |
97 | SEC_BATTERY_ATTR(fg_full_voltage), | |
98 | SEC_BATTERY_ATTR(fg_fullcapnom), | |
99 | SEC_BATTERY_ATTR(battery_cycle), | |
100 | SEC_BATTERY_ATTR(factory_mode_relieve), | |
101 | SEC_BATTERY_ATTR(factory_mode_bypass), | |
102 | }; | |
103 | ||
104 | static enum power_supply_property sec_battery_props[] = { | |
105 | POWER_SUPPLY_PROP_STATUS, | |
106 | POWER_SUPPLY_PROP_CHARGE_TYPE, | |
107 | POWER_SUPPLY_PROP_HEALTH, | |
108 | POWER_SUPPLY_PROP_PRESENT, | |
109 | POWER_SUPPLY_PROP_ONLINE, | |
110 | POWER_SUPPLY_PROP_TECHNOLOGY, | |
111 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | |
112 | POWER_SUPPLY_PROP_VOLTAGE_AVG, | |
113 | POWER_SUPPLY_PROP_CURRENT_NOW, | |
114 | POWER_SUPPLY_PROP_CURRENT_AVG, | |
115 | POWER_SUPPLY_PROP_CHARGE_NOW, | |
116 | POWER_SUPPLY_PROP_CAPACITY, | |
117 | POWER_SUPPLY_PROP_TEMP, | |
118 | POWER_SUPPLY_PROP_TEMP_AMBIENT, | |
119 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
120 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, | |
121 | #endif | |
122 | #if defined(CONFIG_BATTERY_SWELLING) | |
123 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, | |
124 | #endif | |
125 | }; | |
126 | ||
127 | static enum power_supply_property sec_power_props[] = { | |
128 | POWER_SUPPLY_PROP_ONLINE, | |
2a746c1b JC |
129 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
130 | POWER_SUPPLY_PROP_CURRENT_MAX, | |
3c2a0909 S |
131 | }; |
132 | ||
133 | static enum power_supply_property sec_ps_props[] = { | |
134 | POWER_SUPPLY_PROP_STATUS, | |
135 | POWER_SUPPLY_PROP_ONLINE, | |
136 | }; | |
137 | ||
138 | static char *supply_list[] = { | |
139 | "battery", | |
140 | }; | |
141 | ||
142 | char *sec_bat_charging_mode_str[] = { | |
143 | "None", | |
144 | "Normal", | |
145 | "Additional", | |
146 | "Re-Charging", | |
147 | "ABS" | |
148 | }; | |
149 | ||
150 | char *sec_bat_status_str[] = { | |
151 | "Unknown", | |
152 | "Charging", | |
153 | "Discharging", | |
154 | "Not-charging", | |
155 | "Full" | |
156 | }; | |
157 | ||
158 | char *sec_bat_health_str[] = { | |
159 | "Unknown", | |
160 | "Good", | |
161 | "Overheat", | |
162 | "Warm", | |
163 | "Dead", | |
164 | "OverVoltage", | |
165 | "UnspecFailure", | |
166 | "Cold", | |
167 | "Cool", | |
168 | "WatchdogTimerExpire", | |
169 | "SafetyTimerExpire", | |
170 | "UnderVoltage", | |
171 | "OverheatLimit" | |
172 | }; | |
173 | ||
174 | static void sec_bat_set_current_event(struct sec_battery_info *battery, | |
175 | unsigned int current_event_val, unsigned int current_event_mask) | |
176 | { | |
177 | unsigned int temp = battery->current_event; | |
178 | ||
179 | mutex_lock(&battery->current_eventlock); | |
180 | ||
181 | battery->current_event &= ~current_event_mask; | |
182 | battery->current_event |= current_event_val; | |
183 | ||
184 | pr_info("%s: current event before(0x%x), after(0x%x)\n", | |
185 | __func__, temp, battery->current_event); | |
186 | ||
187 | mutex_unlock(&battery->current_eventlock); | |
188 | } | |
189 | ||
190 | static int sec_bat_set_charge( | |
191 | struct sec_battery_info *battery, | |
192 | bool enable) | |
193 | { | |
194 | union power_supply_propval val; | |
195 | ktime_t current_time; | |
196 | struct timespec ts; | |
197 | ||
198 | if (battery->cable_type == POWER_SUPPLY_TYPE_OTG) | |
199 | return 0; | |
200 | val.intval = battery->status; | |
201 | psy_do_property(battery->pdata->charger_name, set, | |
202 | POWER_SUPPLY_PROP_STATUS, val); | |
203 | #if defined(ANDROID_ALARM_ACTIVATED) | |
204 | current_time = alarm_get_elapsed_realtime(); | |
205 | ts = ktime_to_timespec(current_time); | |
206 | #else | |
207 | current_time = ktime_get_boottime(); | |
208 | ts = ktime_to_timespec(current_time); | |
209 | #endif | |
210 | ||
211 | if (enable) { | |
212 | val.intval = battery->cable_type; | |
213 | /*Reset charging start time only in initial charging start */ | |
214 | if (battery->charging_start_time == 0) { | |
215 | if (ts.tv_sec < 1) | |
216 | ts.tv_sec = 1; | |
217 | battery->charging_start_time = ts.tv_sec; | |
218 | battery->charging_next_time = | |
219 | battery->pdata->charging_reset_time; | |
220 | } | |
221 | ||
222 | if (battery->siop_level < 100) | |
223 | battery->lcd_on_time = ts.tv_sec; | |
224 | } else { | |
225 | val.intval = POWER_SUPPLY_TYPE_BATTERY; | |
226 | battery->charging_start_time = 0; | |
227 | battery->charging_passed_time = 0; | |
228 | battery->charging_next_time = 0; | |
229 | battery->charging_fullcharged_time = 0; | |
230 | battery->full_check_cnt = 0; | |
231 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
232 | battery->cc_cv_mode = 0; | |
233 | #endif | |
234 | battery->lcd_on_total_time = 0; | |
235 | battery->lcd_on_time = 0; | |
236 | } | |
237 | ||
238 | battery->charging_block = !enable; | |
239 | ||
240 | battery->temp_highlimit_cnt = 0; | |
241 | battery->temp_high_cnt = 0; | |
242 | battery->temp_low_cnt = 0; | |
243 | battery->temp_recover_cnt = 0; | |
244 | ||
245 | val.intval = battery->pdata->always_enable ? battery->cable_type : | |
246 | enable ? battery->cable_type : POWER_SUPPLY_TYPE_BATTERY; | |
247 | ||
248 | psy_do_property(battery->pdata->charger_name, set, | |
249 | POWER_SUPPLY_PROP_ONLINE, val); | |
250 | ||
251 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
252 | POWER_SUPPLY_PROP_ONLINE, val); | |
253 | ||
254 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
255 | if (battery->wc_status) { | |
256 | psy_do_property(battery->pdata->charger_name, get, | |
257 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, val); | |
258 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
259 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, val); | |
260 | ||
261 | if (enable) { | |
262 | val.intval = POWER_SUPPLY_TYPE_WIRELESS; | |
263 | } else { | |
264 | val.intval = POWER_SUPPLY_TYPE_BATTERY; | |
265 | } | |
266 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
267 | POWER_SUPPLY_PROP_ONLINE, val); | |
268 | } | |
269 | #endif | |
270 | ||
271 | if (battery->pdata->always_enable) { | |
272 | if (battery->slate_mode) | |
273 | val.intval = 0; | |
274 | else if (battery->cable_type == POWER_SUPPLY_TYPE_BATTERY) | |
275 | val.intval = 1; | |
276 | else | |
277 | val.intval = enable; | |
278 | psy_do_property(battery->pdata->charger_name, set, | |
279 | POWER_SUPPLY_PROP_CHARGING_ENABLED, val); | |
280 | } | |
281 | ||
282 | return 0; | |
283 | } | |
284 | ||
285 | static int sec_bat_get_adc_data(struct sec_battery_info *battery, | |
286 | int adc_ch, int count) | |
287 | { | |
288 | int adc_data; | |
289 | int adc_max; | |
290 | int adc_min; | |
291 | int adc_total; | |
292 | int i; | |
293 | ||
294 | adc_data = 0; | |
295 | adc_max = 0; | |
296 | adc_min = 0; | |
297 | adc_total = 0; | |
298 | ||
299 | for (i = 0; i < count; i++) { | |
300 | mutex_lock(&battery->adclock); | |
301 | #ifdef CONFIG_OF | |
302 | adc_data = adc_read(battery, adc_ch); | |
303 | #else | |
304 | adc_data = adc_read(battery->pdata, adc_ch); | |
305 | #endif | |
306 | mutex_unlock(&battery->adclock); | |
307 | ||
308 | if (adc_data < 0) | |
309 | goto err; | |
310 | ||
311 | if (i != 0) { | |
312 | if (adc_data > adc_max) | |
313 | adc_max = adc_data; | |
314 | else if (adc_data < adc_min) | |
315 | adc_min = adc_data; | |
316 | } else { | |
317 | adc_max = adc_data; | |
318 | adc_min = adc_data; | |
319 | } | |
320 | adc_total += adc_data; | |
321 | } | |
322 | ||
323 | return (adc_total - adc_max - adc_min) / (count - 2); | |
324 | err: | |
325 | return adc_data; | |
326 | } | |
327 | ||
328 | /* | |
329 | static unsigned long calculate_average_adc( | |
330 | struct sec_battery_info *battery, | |
331 | int channel, int adc) | |
332 | { | |
333 | unsigned int cnt = 0; | |
334 | int total_adc = 0; | |
335 | int average_adc = 0; | |
336 | int index = 0; | |
337 | ||
338 | cnt = battery->adc_sample[channel].cnt; | |
339 | total_adc = battery->adc_sample[channel].total_adc; | |
340 | ||
341 | if (adc < 0) { | |
342 | dev_err(battery->dev, | |
343 | "%s : Invalid ADC : %d\n", __func__, adc); | |
344 | adc = battery->adc_sample[channel].average_adc; | |
345 | } | |
346 | ||
347 | if (cnt < ADC_SAMPLE_COUNT) { | |
348 | battery->adc_sample[channel].adc_arr[cnt] = adc; | |
349 | battery->adc_sample[channel].index = cnt; | |
350 | battery->adc_sample[channel].cnt = ++cnt; | |
351 | ||
352 | total_adc += adc; | |
353 | average_adc = total_adc / cnt; | |
354 | } else { | |
355 | index = battery->adc_sample[channel].index; | |
356 | if (++index >= ADC_SAMPLE_COUNT) | |
357 | index = 0; | |
358 | ||
359 | total_adc = total_adc - | |
360 | battery->adc_sample[channel].adc_arr[index] + adc; | |
361 | average_adc = total_adc / ADC_SAMPLE_COUNT; | |
362 | ||
363 | battery->adc_sample[channel].adc_arr[index] = adc; | |
364 | battery->adc_sample[channel].index = index; | |
365 | } | |
366 | ||
367 | battery->adc_sample[channel].total_adc = total_adc; | |
368 | battery->adc_sample[channel].average_adc = average_adc; | |
369 | ||
370 | return average_adc; | |
371 | } | |
372 | */ | |
373 | ||
374 | static int sec_bat_get_adc_value( | |
375 | struct sec_battery_info *battery, int channel) | |
376 | { | |
377 | int adc; | |
378 | ||
379 | adc = sec_bat_get_adc_data(battery, channel, | |
380 | battery->pdata->adc_check_count); | |
381 | ||
382 | if (adc < 0) { | |
383 | dev_err(battery->dev, | |
384 | "%s: Error in ADC\n", __func__); | |
385 | return adc; | |
386 | } | |
387 | ||
388 | return adc; | |
389 | } | |
390 | ||
391 | static int sec_bat_get_charger_type_adc | |
392 | (struct sec_battery_info *battery) | |
393 | { | |
394 | /* It is true something valid is | |
395 | connected to the device for charging. | |
396 | By default this something is considered to be USB.*/ | |
397 | int result = POWER_SUPPLY_TYPE_USB; | |
398 | ||
399 | int adc = 0; | |
400 | int i; | |
401 | ||
402 | /* Do NOT check cable type when cable_switch_check() returns false | |
403 | * and keep current cable type | |
404 | */ | |
405 | if (battery->pdata->cable_switch_check && | |
406 | !battery->pdata->cable_switch_check()) | |
407 | return battery->cable_type; | |
408 | ||
409 | adc = sec_bat_get_adc_value(battery, | |
410 | SEC_BAT_ADC_CHANNEL_CABLE_CHECK); | |
411 | ||
412 | /* Do NOT check cable type when cable_switch_normal() returns false | |
413 | * and keep current cable type | |
414 | */ | |
415 | if (battery->pdata->cable_switch_normal && | |
416 | !battery->pdata->cable_switch_normal()) | |
417 | return battery->cable_type; | |
418 | ||
419 | for (i = 0; i < SEC_SIZEOF_POWER_SUPPLY_TYPE; i++) | |
420 | if ((adc > battery->pdata->cable_adc_value[i].min) && | |
421 | (adc < battery->pdata->cable_adc_value[i].max)) | |
422 | break; | |
423 | if (i >= SEC_SIZEOF_POWER_SUPPLY_TYPE) | |
424 | dev_err(battery->dev, | |
425 | "%s : default USB\n", __func__); | |
426 | else | |
427 | result = i; | |
428 | ||
429 | dev_dbg(battery->dev, "%s : result(%d), adc(%d)\n", | |
430 | __func__, result, adc); | |
431 | ||
432 | return result; | |
433 | } | |
434 | ||
435 | static bool sec_bat_check_vf_adc(struct sec_battery_info *battery) | |
436 | { | |
437 | int adc; | |
438 | ||
439 | adc = sec_bat_get_adc_data(battery, | |
440 | SEC_BAT_ADC_CHANNEL_BAT_CHECK, | |
441 | battery->pdata->adc_check_count); | |
442 | ||
443 | if (adc < 0) { | |
444 | dev_err(battery->dev, "%s: VF ADC error\n", __func__); | |
445 | adc = battery->check_adc_value; | |
446 | } else | |
447 | battery->check_adc_value = adc; | |
448 | ||
449 | if ((battery->check_adc_value <= battery->pdata->check_adc_max) && | |
450 | (battery->check_adc_value >= battery->pdata->check_adc_min)) { | |
451 | return true; | |
452 | } else { | |
453 | dev_info(battery->dev, "%s: adc (%d)\n", __func__, battery->check_adc_value); | |
454 | return false; | |
455 | } | |
456 | } | |
457 | ||
458 | static bool sec_bat_check_by_psy(struct sec_battery_info *battery) | |
459 | { | |
460 | char *psy_name; | |
461 | union power_supply_propval value; | |
462 | bool ret; | |
463 | ret = true; | |
464 | ||
465 | switch (battery->pdata->battery_check_type) { | |
466 | case SEC_BATTERY_CHECK_PMIC: | |
467 | psy_name = battery->pdata->pmic_name; | |
468 | break; | |
469 | case SEC_BATTERY_CHECK_FUELGAUGE: | |
470 | psy_name = battery->pdata->fuelgauge_name; | |
471 | break; | |
472 | case SEC_BATTERY_CHECK_CHARGER: | |
473 | psy_name = battery->pdata->charger_name; | |
474 | break; | |
475 | default: | |
476 | dev_err(battery->dev, | |
477 | "%s: Invalid Battery Check Type\n", __func__); | |
478 | ret = false; | |
479 | goto battery_check_error; | |
480 | break; | |
481 | } | |
482 | ||
483 | psy_do_property(psy_name, get, | |
484 | POWER_SUPPLY_PROP_PRESENT, value); | |
485 | ret = (bool)value.intval; | |
486 | ||
487 | battery_check_error: | |
488 | return ret; | |
489 | } | |
490 | ||
491 | static bool sec_bat_check(struct sec_battery_info *battery) | |
492 | { | |
493 | bool ret; | |
494 | ret = true; | |
495 | ||
496 | if (battery->factory_mode || battery->is_jig_on) { | |
497 | dev_dbg(battery->dev, "%s: No need to check in factory mode\n", | |
498 | __func__); | |
499 | return ret; | |
500 | } | |
501 | ||
502 | if (battery->health != POWER_SUPPLY_HEALTH_GOOD && | |
503 | battery->health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) { | |
504 | dev_dbg(battery->dev, "%s: No need to check\n", __func__); | |
505 | return ret; | |
506 | } | |
507 | ||
508 | switch (battery->pdata->battery_check_type) { | |
509 | case SEC_BATTERY_CHECK_ADC: | |
510 | if(battery->cable_type == POWER_SUPPLY_TYPE_BATTERY) | |
511 | ret = battery->present; | |
512 | else | |
513 | ret = sec_bat_check_vf_adc(battery); | |
514 | break; | |
515 | case SEC_BATTERY_CHECK_INT: | |
516 | case SEC_BATTERY_CHECK_CALLBACK: | |
517 | if(battery->cable_type == POWER_SUPPLY_TYPE_BATTERY) { | |
518 | ret = battery->present; | |
519 | } else { | |
520 | if (battery->pdata->check_battery_callback) | |
521 | ret = battery->pdata->check_battery_callback(); | |
522 | } | |
523 | break; | |
524 | case SEC_BATTERY_CHECK_PMIC: | |
525 | case SEC_BATTERY_CHECK_FUELGAUGE: | |
526 | case SEC_BATTERY_CHECK_CHARGER: | |
527 | ret = sec_bat_check_by_psy(battery); | |
528 | break; | |
529 | case SEC_BATTERY_CHECK_NONE: | |
530 | dev_dbg(battery->dev, "%s: No Check\n", __func__); | |
531 | default: | |
532 | break; | |
533 | } | |
534 | ||
535 | return ret; | |
536 | } | |
537 | ||
538 | static bool sec_bat_get_cable_type( | |
539 | struct sec_battery_info *battery, | |
540 | int cable_source_type) | |
541 | { | |
542 | bool ret; | |
543 | int cable_type; | |
544 | ||
545 | ret = false; | |
546 | cable_type = battery->cable_type; | |
547 | ||
548 | if (cable_source_type & SEC_BATTERY_CABLE_SOURCE_CALLBACK) { | |
549 | if (battery->pdata->check_cable_callback) | |
550 | cable_type = | |
551 | battery->pdata->check_cable_callback(); | |
552 | } | |
553 | ||
554 | if (cable_source_type & SEC_BATTERY_CABLE_SOURCE_ADC) { | |
555 | if (gpio_get_value_cansleep( | |
556 | battery->pdata->bat_gpio_ta_nconnected) ^ | |
557 | battery->pdata->bat_polarity_ta_nconnected) | |
558 | cable_type = POWER_SUPPLY_TYPE_BATTERY; | |
559 | else | |
560 | cable_type = | |
561 | sec_bat_get_charger_type_adc(battery); | |
562 | } | |
563 | ||
564 | if (battery->cable_type == cable_type) { | |
565 | dev_dbg(battery->dev, | |
566 | "%s: No need to change cable status\n", __func__); | |
567 | } else { | |
568 | if (cable_type < POWER_SUPPLY_TYPE_BATTERY || | |
569 | cable_type >= SEC_SIZEOF_POWER_SUPPLY_TYPE) { | |
570 | dev_err(battery->dev, | |
571 | "%s: Invalid cable type\n", __func__); | |
572 | } else { | |
573 | battery->cable_type = cable_type; | |
574 | if (battery->pdata->check_cable_result_callback) | |
575 | battery->pdata->check_cable_result_callback( | |
576 | battery->cable_type); | |
577 | ||
578 | ret = true; | |
579 | ||
580 | dev_dbg(battery->dev, "%s: Cable Changed (%d)\n", | |
581 | __func__, battery->cable_type); | |
582 | } | |
583 | } | |
584 | ||
585 | return ret; | |
586 | } | |
587 | ||
588 | static void sec_bat_set_charging_status(struct sec_battery_info *battery, | |
589 | int status) { | |
590 | union power_supply_propval value; | |
591 | switch (status) { | |
592 | case POWER_SUPPLY_STATUS_NOT_CHARGING: | |
593 | case POWER_SUPPLY_STATUS_DISCHARGING: | |
594 | if((battery->status == POWER_SUPPLY_STATUS_FULL) || | |
595 | (battery->capacity == 100)){ | |
596 | #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP) | |
597 | value.intval = battery->capacity; | |
598 | #else | |
599 | value.intval = POWER_SUPPLY_TYPE_BATTERY; | |
600 | #endif | |
601 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
602 | POWER_SUPPLY_PROP_CHARGE_FULL, value); | |
603 | ||
604 | /* To get SOC value (NOT raw SOC), need to reset value */ | |
605 | value.intval = 0; | |
606 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
607 | POWER_SUPPLY_PROP_CAPACITY, value); | |
608 | battery->capacity = value.intval; | |
609 | } | |
610 | battery->expired_time = battery->pdata->expired_time; | |
611 | battery->prev_safety_time = 0; | |
612 | break; | |
613 | default: | |
614 | break; | |
615 | } | |
616 | battery->status = status; | |
617 | } | |
618 | ||
619 | static bool sec_bat_battery_cable_check(struct sec_battery_info *battery) | |
620 | { | |
621 | if (!sec_bat_check(battery)) { | |
622 | if (battery->check_count < battery->pdata->check_count) | |
623 | battery->check_count++; | |
624 | else { | |
625 | dev_err(battery->dev, | |
626 | "%s: Battery Disconnected\n", __func__); | |
627 | ||
628 | if (battery->pdata->always_enable) { | |
629 | union power_supply_propval val; | |
630 | ||
631 | val.intval = 0; | |
632 | psy_do_property(battery->pdata->charger_name, set, | |
633 | POWER_SUPPLY_PROP_CHARGING_ENABLED, val); | |
634 | } | |
635 | ||
636 | battery->present = false; | |
637 | battery->health = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; | |
638 | ||
639 | if (battery->status != | |
640 | POWER_SUPPLY_STATUS_DISCHARGING) { | |
641 | sec_bat_set_charging_status(battery, | |
642 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
643 | if(battery->siop_level != 100) | |
644 | battery->stop_timer = true ; | |
645 | sec_bat_set_charge(battery, false); | |
646 | } | |
647 | ||
648 | if (battery->pdata->check_battery_result_callback) | |
649 | battery->pdata-> | |
650 | check_battery_result_callback(); | |
651 | return false; | |
652 | } | |
653 | } else | |
654 | battery->check_count = 0; | |
655 | ||
656 | battery->present = true; | |
657 | ||
658 | if (battery->health == POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) { | |
659 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
660 | ||
661 | if (battery->status == POWER_SUPPLY_STATUS_NOT_CHARGING) { | |
662 | sec_bat_set_charging_status(battery, | |
663 | POWER_SUPPLY_STATUS_CHARGING); | |
664 | #if defined(CONFIG_BATTERY_SWELLING) | |
665 | if (!battery->swelling_mode) | |
666 | sec_bat_set_charge(battery, true); | |
667 | #else | |
668 | sec_bat_set_charge(battery, true); | |
669 | #endif | |
670 | } | |
671 | } | |
672 | ||
673 | dev_dbg(battery->dev, "%s: Battery Connected\n", __func__); | |
674 | ||
675 | if (battery->pdata->cable_check_type & | |
676 | SEC_BATTERY_CABLE_CHECK_POLLING) { | |
677 | if (sec_bat_get_cable_type(battery, | |
678 | battery->pdata->cable_source_type)) { | |
679 | wake_lock(&battery->cable_wake_lock); | |
680 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
681 | &battery->cable_work, 0); | |
682 | } | |
683 | } | |
684 | return true; | |
685 | } | |
686 | ||
687 | static int sec_bat_ovp_uvlo_by_psy(struct sec_battery_info *battery) | |
688 | { | |
689 | char *psy_name; | |
690 | union power_supply_propval value; | |
691 | ||
692 | value.intval = POWER_SUPPLY_HEALTH_GOOD; | |
693 | ||
694 | switch (battery->pdata->ovp_uvlo_check_type) { | |
695 | case SEC_BATTERY_OVP_UVLO_PMICPOLLING: | |
696 | psy_name = battery->pdata->pmic_name; | |
697 | break; | |
698 | case SEC_BATTERY_OVP_UVLO_CHGPOLLING: | |
699 | psy_name = battery->pdata->charger_name; | |
700 | break; | |
701 | default: | |
702 | dev_err(battery->dev, | |
703 | "%s: Invalid OVP/UVLO Check Type\n", __func__); | |
704 | goto ovp_uvlo_check_error; | |
705 | break; | |
706 | } | |
707 | ||
708 | psy_do_property(psy_name, get, | |
709 | POWER_SUPPLY_PROP_HEALTH, value); | |
710 | ||
711 | ovp_uvlo_check_error: | |
712 | return value.intval; | |
713 | } | |
714 | ||
715 | static bool sec_bat_ovp_uvlo_result( | |
716 | struct sec_battery_info *battery, int health) | |
717 | { | |
718 | if (battery->health != health) { | |
719 | battery->health = health; | |
720 | switch (health) { | |
721 | case POWER_SUPPLY_HEALTH_GOOD: | |
722 | dev_info(battery->dev, "%s: Safe voltage\n", __func__); | |
723 | dev_info(battery->dev, "%s: is_recharging : %d\n", __func__, battery->is_recharging); | |
724 | sec_bat_set_charging_status(battery, | |
725 | POWER_SUPPLY_STATUS_CHARGING); | |
726 | if (battery->siop_level != 100) | |
727 | battery->stop_timer = true; | |
728 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
729 | #if defined(CONFIG_BATTERY_SWELLING) | |
730 | if (!battery->swelling_mode) | |
731 | sec_bat_set_charge(battery, true); | |
732 | #else | |
733 | sec_bat_set_charge(battery, true); | |
734 | #endif | |
735 | break; | |
736 | case POWER_SUPPLY_HEALTH_OVERVOLTAGE: | |
737 | case POWER_SUPPLY_HEALTH_UNDERVOLTAGE: | |
738 | dev_info(battery->dev, | |
739 | "%s: Unsafe voltage (%d)\n", | |
740 | __func__, health); | |
741 | sec_bat_set_charging_status(battery, | |
742 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
743 | sec_bat_set_charge(battery, false); | |
744 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
745 | battery->is_recharging = false; | |
746 | /* Take the wakelock during 10 seconds | |
747 | when over-voltage status is detected */ | |
748 | wake_lock_timeout(&battery->vbus_wake_lock, HZ * 10); | |
749 | break; | |
750 | case POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE: | |
751 | dev_info(battery->dev, | |
752 | "%s: Watchdog Expired, Restart charger (%d)\n", | |
753 | __func__, health); | |
754 | sec_bat_set_charge(battery, true); | |
755 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
756 | break; | |
757 | } | |
758 | power_supply_changed(&battery->psy_bat); | |
759 | return true; | |
760 | } | |
761 | ||
762 | return false; | |
763 | } | |
764 | ||
765 | static bool sec_bat_ovp_uvlo(struct sec_battery_info *battery) | |
766 | { | |
767 | int health; | |
768 | ||
769 | if (battery->factory_mode || battery->is_jig_on) { | |
770 | dev_info(battery->dev, | |
771 | "%s: No need to check in factory mode\n", | |
772 | __func__); | |
773 | return false; | |
774 | } else if ((battery->status == POWER_SUPPLY_STATUS_FULL) && | |
775 | (battery->charging_mode == SEC_BATTERY_CHARGING_NONE)) { | |
776 | dev_dbg(battery->dev, "%s: No need to check in Full status", __func__); | |
777 | return false; | |
778 | } | |
779 | ||
780 | if (battery->health != POWER_SUPPLY_HEALTH_GOOD && | |
781 | battery->health != POWER_SUPPLY_HEALTH_OVERVOLTAGE && | |
782 | battery->health != POWER_SUPPLY_HEALTH_UNDERVOLTAGE && | |
783 | battery->health != POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE) { | |
784 | dev_dbg(battery->dev, "%s: No need to check\n", __func__); | |
785 | return false; | |
786 | } | |
787 | ||
788 | health = battery->health; | |
789 | ||
790 | switch (battery->pdata->ovp_uvlo_check_type) { | |
791 | case SEC_BATTERY_OVP_UVLO_CALLBACK: | |
792 | if (battery->pdata->ovp_uvlo_callback) | |
793 | health = battery->pdata->ovp_uvlo_callback(); | |
794 | break; | |
795 | case SEC_BATTERY_OVP_UVLO_PMICPOLLING: | |
796 | case SEC_BATTERY_OVP_UVLO_CHGPOLLING: | |
797 | health = sec_bat_ovp_uvlo_by_psy(battery); | |
798 | break; | |
799 | case SEC_BATTERY_OVP_UVLO_PMICINT: | |
800 | case SEC_BATTERY_OVP_UVLO_CHGINT: | |
801 | /* nothing for interrupt check */ | |
802 | default: | |
803 | break; | |
804 | } | |
805 | ||
806 | return sec_bat_ovp_uvlo_result(battery, health); | |
807 | } | |
808 | ||
809 | static bool sec_bat_check_recharge(struct sec_battery_info *battery) | |
810 | { | |
811 | int recharging_voltage; | |
812 | #if defined(CONFIG_BATTERY_SWELLING) | |
813 | if (battery->swelling_mode) { | |
814 | pr_info("%s: Skip normal recharge check routine for swelling mode\n", | |
815 | __func__); | |
816 | return false; | |
817 | } | |
818 | #endif | |
819 | if ((battery->status == POWER_SUPPLY_STATUS_CHARGING) && | |
820 | (battery->pdata->full_condition_type & | |
821 | SEC_BATTERY_FULL_CONDITION_NOTIMEFULL) && | |
822 | (battery->charging_mode == SEC_BATTERY_CHARGING_NONE)) { | |
823 | dev_info(battery->dev, | |
824 | "%s: Re-charging by NOTIMEFULL (%d)\n", | |
825 | __func__, battery->capacity); | |
826 | goto check_recharge_check_count; | |
827 | } | |
828 | ||
829 | if (battery->status == POWER_SUPPLY_STATUS_FULL && | |
830 | battery->charging_mode == SEC_BATTERY_CHARGING_NONE) { | |
831 | recharging_voltage = battery->pdata->recharge_condition_vcell; | |
832 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP) { | |
833 | recharging_voltage = battery->pdata->chg_float_voltage - 150; // float voltage - 150mV | |
834 | dev_info(battery->dev, "%s: recharge voltage changed by low temp(%d)\n", | |
835 | __func__, recharging_voltage); | |
836 | } | |
837 | if ((battery->pdata->recharge_condition_type & | |
838 | SEC_BATTERY_RECHARGE_CONDITION_SOC) && | |
839 | (battery->capacity <= | |
840 | battery->pdata->recharge_condition_soc)) { | |
841 | battery->expired_time = battery->pdata->recharging_expired_time; | |
842 | battery->prev_safety_time = 0; | |
843 | dev_info(battery->dev, | |
844 | "%s: Re-charging by SOC (%d)\n", | |
845 | __func__, battery->capacity); | |
846 | goto check_recharge_check_count; | |
847 | } | |
848 | ||
849 | if ((battery->pdata->recharge_condition_type & | |
850 | SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL) && | |
851 | (battery->voltage_avg <= | |
852 | recharging_voltage)) { | |
853 | battery->expired_time = battery->pdata->recharging_expired_time; | |
854 | battery->prev_safety_time = 0; | |
855 | dev_info(battery->dev, | |
856 | "%s: Re-charging by average VCELL (%d)\n", | |
857 | __func__, battery->voltage_avg); | |
858 | goto check_recharge_check_count; | |
859 | } | |
860 | ||
861 | if ((battery->pdata->recharge_condition_type & | |
862 | SEC_BATTERY_RECHARGE_CONDITION_VCELL) && | |
863 | (battery->voltage_now <= | |
864 | recharging_voltage)) { | |
865 | battery->expired_time = battery->pdata->recharging_expired_time; | |
866 | battery->prev_safety_time = 0; | |
867 | dev_info(battery->dev, | |
868 | "%s: Re-charging by VCELL (%d)\n", | |
869 | __func__, battery->voltage_now); | |
870 | goto check_recharge_check_count; | |
871 | } | |
872 | } | |
873 | ||
874 | battery->recharge_check_cnt = 0; | |
875 | return false; | |
876 | ||
877 | check_recharge_check_count: | |
878 | if (battery->recharge_check_cnt < | |
879 | battery->pdata->recharge_check_count) | |
880 | battery->recharge_check_cnt++; | |
881 | dev_dbg(battery->dev, | |
882 | "%s: recharge count = %d\n", | |
883 | __func__, battery->recharge_check_cnt); | |
884 | ||
885 | if (battery->recharge_check_cnt >= | |
886 | battery->pdata->recharge_check_count) | |
887 | return true; | |
888 | else | |
889 | return false; | |
890 | } | |
891 | ||
892 | static bool sec_bat_voltage_check(struct sec_battery_info *battery) | |
893 | { | |
894 | union power_supply_propval value; | |
895 | ||
896 | if (battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
897 | dev_dbg(battery->dev, | |
898 | "%s: Charging Disabled\n", __func__); | |
899 | return true; | |
900 | } | |
901 | ||
902 | /* OVP/UVLO check */ | |
903 | if (sec_bat_ovp_uvlo(battery)) { | |
904 | if (battery->pdata->ovp_uvlo_result_callback) | |
905 | battery->pdata-> | |
906 | ovp_uvlo_result_callback(battery->health); | |
907 | return false; | |
908 | } | |
909 | ||
910 | if ((battery->status == POWER_SUPPLY_STATUS_FULL) && | |
911 | #if defined(CONFIG_BATTERY_SWELLING) | |
912 | (battery->charging_mode == SEC_BATTERY_CHARGING_2ND || | |
913 | battery->is_recharging || battery->swelling_mode)) { | |
914 | #else | |
915 | (battery->charging_mode == SEC_BATTERY_CHARGING_2ND || | |
916 | battery->is_recharging)) { | |
917 | #endif | |
918 | value.intval = 0; | |
919 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
920 | POWER_SUPPLY_PROP_CAPACITY, value); | |
921 | if (value.intval < | |
922 | battery->pdata->full_condition_soc && | |
923 | battery->voltage_now < | |
924 | (battery->pdata->recharge_condition_vcell - 50)) { | |
925 | sec_bat_set_charging_status(battery, | |
926 | POWER_SUPPLY_STATUS_CHARGING); | |
927 | if (battery->siop_level != 100) | |
928 | battery->stop_timer = true; | |
929 | battery->voltage_now = 1080; | |
930 | battery->voltage_avg = 1080; | |
931 | power_supply_changed(&battery->psy_bat); | |
932 | dev_info(battery->dev, | |
933 | "%s: battery status full -> charging, RepSOC(%d)\n", __func__, value.intval); | |
934 | } | |
935 | } | |
936 | ||
937 | /* Re-Charging check */ | |
938 | if (sec_bat_check_recharge(battery)) { | |
939 | if (battery->pdata->full_check_type != | |
940 | SEC_BATTERY_FULLCHARGED_NONE) | |
941 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
942 | else | |
943 | battery->charging_mode = SEC_BATTERY_CHARGING_2ND; | |
944 | battery->is_recharging = true; | |
945 | #if defined(CONFIG_BATTERY_SWELLING) | |
946 | if (!battery->swelling_mode) | |
947 | sec_bat_set_charge(battery, true); | |
948 | #else | |
949 | sec_bat_set_charge(battery, true); | |
950 | #endif | |
951 | return false; | |
952 | } | |
953 | ||
954 | return true; | |
955 | } | |
956 | ||
957 | static bool sec_bat_get_temperature_by_adc( | |
958 | struct sec_battery_info *battery, | |
959 | enum sec_battery_adc_channel channel, | |
960 | union power_supply_propval *value) | |
961 | { | |
962 | int temp = 0; | |
963 | int temp_adc; | |
964 | int low = 0; | |
965 | int high = 0; | |
966 | int mid = 0; | |
967 | const sec_bat_adc_table_data_t *temp_adc_table; | |
968 | unsigned int temp_adc_table_size; | |
969 | ||
970 | temp_adc = sec_bat_get_adc_value(battery, channel); | |
971 | if (temp_adc < 0) | |
972 | return true; | |
973 | ||
974 | switch (channel) { | |
975 | case SEC_BAT_ADC_CHANNEL_TEMP: | |
976 | temp_adc_table = battery->pdata->temp_adc_table; | |
977 | temp_adc_table_size = | |
978 | battery->pdata->temp_adc_table_size; | |
979 | battery->temp_adc = temp_adc; | |
980 | break; | |
981 | case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT: | |
982 | temp_adc_table = battery->pdata->temp_amb_adc_table; | |
983 | temp_adc_table_size = | |
984 | battery->pdata->temp_amb_adc_table_size; | |
985 | battery->temp_ambient_adc = temp_adc; | |
986 | break; | |
987 | case SEC_BAT_ADC_CHANNEL_CHG_TEMP: | |
988 | temp_adc_table = battery->pdata->chg_temp_adc_table; | |
989 | temp_adc_table_size = | |
990 | battery->pdata->chg_temp_adc_table_size; | |
991 | battery->chg_temp_adc = temp_adc; | |
992 | break; | |
993 | default: | |
994 | dev_err(battery->dev, | |
995 | "%s: Invalid Property\n", __func__); | |
996 | return false; | |
997 | } | |
998 | ||
999 | if (temp_adc_table[0].adc >= temp_adc) { | |
1000 | temp = temp_adc_table[0].data; | |
1001 | goto temp_by_adc_goto; | |
1002 | } else if (temp_adc_table[temp_adc_table_size-1].adc <= temp_adc) { | |
1003 | temp = temp_adc_table[temp_adc_table_size-1].data; | |
1004 | goto temp_by_adc_goto; | |
1005 | } | |
1006 | ||
1007 | high = temp_adc_table_size - 1; | |
1008 | ||
1009 | while (low <= high) { | |
1010 | mid = (low + high) / 2; | |
1011 | if (temp_adc_table[mid].adc > temp_adc) | |
1012 | high = mid - 1; | |
1013 | else if (temp_adc_table[mid].adc < temp_adc) | |
1014 | low = mid + 1; | |
1015 | else { | |
1016 | temp = temp_adc_table[mid].data; | |
1017 | goto temp_by_adc_goto; | |
1018 | } | |
1019 | } | |
1020 | ||
1021 | temp = temp_adc_table[high].data; | |
1022 | temp += ((temp_adc_table[low].data - temp_adc_table[high].data) * | |
1023 | (temp_adc - temp_adc_table[high].adc)) / | |
1024 | (temp_adc_table[low].adc - temp_adc_table[high].adc); | |
1025 | ||
1026 | temp_by_adc_goto: | |
1027 | value->intval = temp; | |
1028 | ||
1029 | dev_dbg(battery->dev, | |
1030 | "%s: Temp(%d), Temp-ADC(%d)\n", | |
1031 | __func__, temp, temp_adc); | |
1032 | ||
1033 | return true; | |
1034 | } | |
1035 | ||
1036 | static bool sec_bat_temperature( | |
1037 | struct sec_battery_info *battery) | |
1038 | { | |
1039 | bool ret; | |
1040 | ret = true; | |
1041 | ||
1042 | if (battery->pdata->event_check && battery->event) { | |
1043 | battery->temp_highlimit_threshold = | |
1044 | battery->pdata->temp_highlimit_threshold_event; | |
1045 | battery->temp_highlimit_recovery = | |
1046 | battery->pdata->temp_highlimit_recovery_event; | |
1047 | battery->temp_high_threshold = | |
1048 | battery->pdata->temp_high_threshold_event; | |
1049 | battery->temp_high_recovery = | |
1050 | battery->pdata->temp_high_recovery_event; | |
1051 | battery->temp_low_recovery = | |
1052 | battery->pdata->temp_low_recovery_event; | |
1053 | battery->temp_low_threshold = | |
1054 | battery->pdata->temp_low_threshold_event; | |
1055 | } else if (lpcharge) { | |
1056 | battery->temp_highlimit_threshold = | |
1057 | battery->pdata->temp_highlimit_threshold_lpm; | |
1058 | battery->temp_highlimit_recovery = | |
1059 | battery->pdata->temp_highlimit_recovery_lpm; | |
1060 | battery->temp_high_threshold = | |
1061 | battery->pdata->temp_high_threshold_lpm; | |
1062 | battery->temp_high_recovery = | |
1063 | battery->pdata->temp_high_recovery_lpm; | |
1064 | battery->temp_low_recovery = | |
1065 | battery->pdata->temp_low_recovery_lpm; | |
1066 | battery->temp_low_threshold = | |
1067 | battery->pdata->temp_low_threshold_lpm; | |
1068 | } else { | |
1069 | battery->temp_highlimit_threshold = | |
1070 | battery->pdata->temp_highlimit_threshold_normal; | |
1071 | battery->temp_highlimit_recovery = | |
1072 | battery->pdata->temp_highlimit_recovery_normal; | |
1073 | battery->temp_high_threshold = | |
1074 | battery->pdata->temp_high_threshold_normal; | |
1075 | battery->temp_high_recovery = | |
1076 | battery->pdata->temp_high_recovery_normal; | |
1077 | battery->temp_low_recovery = | |
1078 | battery->pdata->temp_low_recovery_normal; | |
1079 | battery->temp_low_threshold = | |
1080 | battery->pdata->temp_low_threshold_normal; | |
1081 | } | |
1082 | ||
1083 | dev_info(battery->dev, | |
1084 | "%s: HLT(%d) HLR(%d) HT(%d), HR(%d), LT(%d), LR(%d)\n", | |
1085 | __func__, battery->temp_highlimit_threshold, | |
1086 | battery->temp_highlimit_recovery, | |
1087 | battery->temp_high_threshold, | |
1088 | battery->temp_high_recovery, | |
1089 | battery->temp_low_threshold, | |
1090 | battery->temp_low_recovery); | |
1091 | return ret; | |
1092 | } | |
1093 | ||
1094 | #if defined(CONFIG_BATTERY_SWELLING) | |
1095 | static void sec_bat_swelling_check(struct sec_battery_info *battery, int temperature) | |
1096 | { | |
1097 | union power_supply_propval val; | |
1098 | bool en_swelling = false, en_rechg = false; | |
1099 | int swelling_rechg_voltage; | |
1100 | ||
1101 | psy_do_property(battery->pdata->charger_name, get, | |
1102 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
1103 | ||
1104 | pr_info("%s: status(%d), swell_mode(%d:%d), cv(0x%02x), temp(%d)\n", | |
1105 | __func__, battery->status, battery->swelling_mode, | |
1106 | battery->charging_block, val.intval, temperature); | |
1107 | ||
1108 | /* swelling_mode | |
1109 | under voltage over voltage, battery missing */ | |
1110 | if ((battery->status == POWER_SUPPLY_STATUS_DISCHARGING) ||\ | |
1111 | (battery->status == POWER_SUPPLY_STATUS_NOT_CHARGING)) { | |
1112 | pr_info("%s: DISCHARGING or NOT-CHARGING. stop swelling mode\n", __func__); | |
1113 | battery->swelling_mode = false; | |
1114 | sec_bat_set_current_event(battery, 0, | |
1115 | (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING | SEC_BAT_CURRENT_EVENT_LOW_TEMP | | |
1116 | SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING)); | |
1117 | goto skip_swelling_chek; | |
1118 | } | |
1119 | ||
1120 | if (!battery->swelling_mode) { | |
1121 | if (((temperature >= battery->pdata->swelling_high_temp_block) || | |
1122 | (temperature <= battery->pdata->swelling_low_temp_block_2nd)) && | |
1123 | battery->pdata->temp_check_type) { | |
1124 | ||
1125 | if (temperature >= battery->pdata->swelling_high_temp_block && | |
1126 | battery->pdata->event_check && | |
1127 | !battery->event) { | |
1128 | pr_info("%s: skip check swelling in high temperature event mode(%d)\n", | |
1129 | __func__, battery->event); | |
1130 | return; | |
1131 | } | |
1132 | ||
1133 | pr_info("%s: swelling mode start. stop charging\n", __func__); | |
1134 | battery->swelling_mode = true; | |
1135 | battery->swelling_full_check_cnt = 0; | |
1136 | sec_bat_set_charge(battery, false); | |
1137 | en_swelling = true; | |
1138 | } else if ((battery->temperature <= battery->pdata->swelling_low_temp_block_1st) && | |
1139 | !(battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP)) { | |
1140 | pr_info("%s: low temperature reduce current\n", __func__); | |
1141 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP, | |
1142 | SEC_BAT_CURRENT_EVENT_LOW_TEMP); | |
1143 | } else if ((battery->temperature >= battery->pdata->swelling_low_temp_recov_1st) && | |
1144 | (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP)) { | |
1145 | pr_info("%s: normal temperature recover current\n", __func__); | |
1146 | sec_bat_set_current_event(battery, 0, SEC_BAT_CURRENT_EVENT_LOW_TEMP); | |
1147 | } | |
1148 | } | |
1149 | ||
1150 | if (!battery->voltage_now) | |
1151 | return; | |
1152 | ||
1153 | if (battery->swelling_mode) { | |
1154 | if (temperature <= battery->pdata->swelling_low_temp_recov_2nd) | |
1155 | swelling_rechg_voltage = battery->pdata->swelling_low_rechg_voltage; | |
1156 | else | |
1157 | swelling_rechg_voltage = battery->pdata->swelling_high_rechg_voltage; | |
1158 | ||
1159 | if ((temperature <= battery->pdata->swelling_high_temp_recov) && | |
1160 | (temperature >= battery->pdata->swelling_low_temp_recov_2nd)) { | |
1161 | pr_info("%s: swelling mode end. restart charging\n", __func__); | |
1162 | battery->swelling_mode = false; | |
1163 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
1164 | sec_bat_set_current_event(battery, 0, | |
1165 | (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING | | |
1166 | SEC_BAT_CURRENT_EVENT_LOW_TEMP | | |
1167 | SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING)); | |
1168 | sec_bat_set_charge(battery, true); | |
1169 | /* restore 4.4V float voltage */ | |
1170 | val.intval = battery->pdata->swelling_normal_float_voltage; | |
1171 | psy_do_property(battery->pdata->charger_name, set, | |
1172 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
1173 | } else if (battery->voltage_now < swelling_rechg_voltage && | |
1174 | battery->charging_block) { | |
1175 | pr_info("%s: swelling mode recharging start. Vbatt(%d)\n", | |
1176 | __func__, battery->voltage_now); | |
1177 | battery->charging_mode = SEC_BATTERY_CHARGING_1ST; | |
1178 | en_rechg = true; | |
1179 | sec_bat_set_charge(battery, true); | |
1180 | /* change 4.20V float voltage */ | |
1181 | val.intval = battery->pdata->swelling_drop_float_voltage; | |
1182 | psy_do_property(battery->pdata->charger_name, set, | |
1183 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
1184 | if ((temperature <= battery->pdata->swelling_low_temp_recov_2nd) && | |
1185 | (battery->pdata->swelling_low_temp_current > 0)) { | |
1186 | pr_info("%s: swelling mode reduce charging current(temp:%d)\n", | |
1187 | __func__, temperature); | |
1188 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING, | |
1189 | SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING); | |
1190 | } else if ((temperature >= battery->pdata->swelling_high_temp_recov) && | |
1191 | (battery->pdata->swelling_high_temp_current > 0)) { | |
1192 | pr_info("%s: swelling mode reduce charging current(temp:%d)\n", | |
1193 | __func__, temperature); | |
1194 | sec_bat_set_current_event(battery, SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING, | |
1195 | SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING); | |
1196 | } | |
1197 | } | |
1198 | } | |
1199 | ||
1200 | if (en_swelling && !en_rechg) { | |
1201 | pr_info("%s : SAFETY TIME RESET (SWELLING MODE CHARING STOP!)\n", __func__); | |
1202 | battery->expired_time = battery->pdata->expired_time; | |
1203 | battery->prev_safety_time = 0; | |
1204 | } | |
1205 | ||
1206 | skip_swelling_chek: | |
1207 | dev_dbg(battery->dev, "%s end\n", __func__); | |
1208 | } | |
1209 | #endif | |
1210 | ||
1211 | static void set_swelling_current(struct sec_battery_info *battery) | |
1212 | { | |
1213 | int charging_current = battery->pdata->charging_current[battery->cable_type].fast_charging_current; | |
1214 | ||
1215 | union power_supply_propval value = {0, }; | |
1216 | ||
1217 | if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING) { | |
1218 | charging_current = (charging_current > battery->pdata->swelling_low_temp_current) ? | |
1219 | battery->pdata->swelling_low_temp_current : charging_current; | |
1220 | } else if (battery->current_event & SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING) { | |
1221 | charging_current = (charging_current > battery->pdata->swelling_high_temp_current) ? | |
1222 | battery->pdata->swelling_high_temp_current : charging_current; | |
1223 | } else if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP) { | |
1224 | charging_current = (charging_current > battery->pdata->swelling_low_temp_current) ? | |
1225 | battery->pdata->swelling_low_temp_current : charging_current; | |
1226 | } | |
1227 | ||
1228 | if (battery->charging_current != charging_current) { | |
1229 | value.intval = charging_current; | |
1230 | pr_info(" %s Charging_current = %d \n", __func__ , charging_current ); | |
1231 | psy_do_property(battery->pdata->charger_name, set, | |
1232 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
1233 | battery->charging_current = charging_current; | |
1234 | } | |
1235 | } | |
1236 | ||
1237 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
1238 | static bool sec_bat_set_aging_step(struct sec_battery_info *battery, int step) | |
1239 | { | |
1240 | union power_supply_propval value; | |
1241 | ||
1242 | if (battery->pdata->num_age_step <= 0 || step < 0 || step >= battery->pdata->num_age_step) { | |
1243 | pr_info("%s: [AGE] abnormal age step : %d/%d\n", | |
1244 | __func__, step, battery->pdata->num_age_step-1); | |
1245 | return false; | |
1246 | } | |
1247 | ||
1248 | if (battery->temperature < 50) { | |
1249 | pr_info("%s: [AGE] skip (temperature:%d)\n", __func__, battery->temperature < 50); | |
1250 | return false; | |
1251 | } | |
1252 | ||
1253 | battery->pdata->age_step = step; | |
1254 | ||
1255 | /* float voltage */ | |
1256 | battery->pdata->chg_float_voltage = | |
1257 | battery->pdata->age_data[battery->pdata->age_step].float_voltage; | |
1258 | battery->pdata->swelling_normal_float_voltage = | |
1259 | battery->pdata->chg_float_voltage; | |
1260 | if (!battery->swelling_mode) { | |
1261 | value.intval = battery->pdata->chg_float_voltage; | |
1262 | psy_do_property(battery->pdata->charger_name, set, | |
1263 | POWER_SUPPLY_PROP_VOLTAGE_MAX, value); | |
1264 | } | |
1265 | ||
1266 | /* full/recharge condition */ | |
1267 | battery->pdata->recharge_condition_vcell = | |
1268 | battery->pdata->age_data[battery->pdata->age_step].recharge_condition_vcell; | |
1269 | battery->pdata->full_condition_soc = | |
1270 | battery->pdata->age_data[battery->pdata->age_step].full_condition_soc; | |
1271 | battery->pdata->full_condition_vcell = | |
1272 | battery->pdata->age_data[battery->pdata->age_step].full_condition_vcell; | |
6828552d DW |
1273 | #if defined(CONFIG_FUELGAUGE_S2MU003) |
1274 | value.intval = battery->pdata->age_step; | |
1275 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
1276 | POWER_SUPPLY_PROP_UPDATE_BATTERY_DATA, value); | |
1277 | #else | |
3c2a0909 S |
1278 | value.intval = battery->pdata->full_condition_soc; |
1279 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
1280 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, value); | |
6828552d | 1281 | #endif |
3c2a0909 S |
1282 | dev_info(battery->dev, |
1283 | "%s: Step(%d/%d), Cycle(%d), float_v(%d), r_v(%d), f_s(%d), f_vl(%d)\n", | |
1284 | __func__, | |
1285 | battery->pdata->age_step, battery->pdata->num_age_step-1, battery->batt_cycle, | |
1286 | battery->pdata->chg_float_voltage, | |
1287 | battery->pdata->recharge_condition_vcell, | |
1288 | battery->pdata->full_condition_soc, | |
1289 | battery->pdata->full_condition_vcell); | |
1290 | ||
1291 | return true; | |
1292 | } | |
1293 | ||
1294 | static void sec_bat_aging_check(struct sec_battery_info *battery) | |
1295 | { | |
1296 | int prev_step = battery->pdata->age_step; | |
1297 | int calc_step = -1; | |
1298 | bool ret; | |
1299 | ||
1300 | if (battery->pdata->num_age_step <= 0) | |
1301 | return; | |
1302 | ||
1303 | if (battery->temperature < 50) { | |
1304 | pr_info("%s: [AGE] skip (temperature:%d)\n", __func__, battery->temperature); | |
1305 | return; | |
1306 | } | |
1307 | ||
1308 | for (calc_step = battery->pdata->num_age_step - 1; calc_step >= 0; calc_step--) { | |
1309 | if (battery->pdata->age_data[calc_step].cycle <= battery->batt_cycle) | |
1310 | break; | |
1311 | } | |
6828552d DW |
1312 | dev_info(battery->dev, |
1313 | "%s: [Long life] prev_step = %d, calc_step = %d\n", __func__, prev_step, calc_step); | |
3c2a0909 S |
1314 | if (calc_step == prev_step) |
1315 | return; | |
1316 | ||
1317 | ret = sec_bat_set_aging_step(battery, calc_step); | |
1318 | dev_info(battery->dev, | |
1319 | "%s: %s change step (%d->%d), Cycle(%d)\n", | |
1320 | __func__, ret ? "Succeed in" : "Fail to", | |
1321 | prev_step, battery->pdata->age_step, battery->batt_cycle); | |
1322 | } | |
1323 | #endif | |
1324 | ||
1325 | static bool sec_bat_temperature_check( | |
1326 | struct sec_battery_info *battery) | |
1327 | { | |
1328 | int temp_value; | |
1329 | int pre_health; | |
1330 | ||
1331 | if (battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
1332 | dev_dbg(battery->dev, | |
1333 | "%s: Charging Disabled\n", __func__); | |
1334 | return true; | |
1335 | } | |
1336 | ||
1337 | if (battery->health != POWER_SUPPLY_HEALTH_GOOD && | |
1338 | battery->health != POWER_SUPPLY_HEALTH_OVERHEAT && | |
1339 | battery->health != POWER_SUPPLY_HEALTH_COLD && | |
1340 | battery->health != POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
1341 | dev_dbg(battery->dev, "%s: No need to check\n", __func__); | |
1342 | return false; | |
1343 | } | |
1344 | ||
1345 | sec_bat_temperature(battery); | |
1346 | ||
1347 | switch (battery->pdata->temp_check_type) { | |
1348 | case SEC_BATTERY_TEMP_CHECK_ADC: | |
1349 | temp_value = battery->temp_adc; | |
1350 | break; | |
1351 | case SEC_BATTERY_TEMP_CHECK_TEMP: | |
1352 | temp_value = battery->temperature; | |
1353 | break; | |
1354 | default: | |
1355 | dev_err(battery->dev, | |
1356 | "%s: Invalid Temp Check Type\n", __func__); | |
1357 | return true; | |
1358 | } | |
1359 | pre_health = battery->health; | |
1360 | ||
1361 | if (temp_value >= battery->temp_highlimit_threshold) { | |
1362 | if (battery->health != POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
1363 | if (battery->temp_highlimit_cnt < | |
1364 | battery->pdata->temp_check_count) { | |
1365 | battery->temp_highlimit_cnt++; | |
1366 | battery->temp_high_cnt = 0; | |
1367 | battery->temp_low_cnt = 0; | |
1368 | battery->temp_recover_cnt = 0; | |
1369 | } | |
1370 | dev_dbg(battery->dev, | |
1371 | "%s: highlimit count = %d\n", | |
1372 | __func__, battery->temp_highlimit_cnt); | |
1373 | } | |
1374 | } else if (temp_value >= battery->temp_high_threshold) { | |
1375 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
1376 | if (temp_value <= battery->temp_highlimit_recovery) { | |
1377 | if (battery->temp_recover_cnt < | |
1378 | battery->pdata->temp_check_count) { | |
1379 | battery->temp_recover_cnt++; | |
1380 | battery->temp_highlimit_cnt = 0; | |
1381 | battery->temp_high_cnt = 0; | |
1382 | battery->temp_low_cnt = 0; | |
1383 | } | |
1384 | dev_dbg(battery->dev, | |
1385 | "%s: recovery count = %d\n", | |
1386 | __func__, battery->temp_recover_cnt); | |
1387 | } | |
1388 | } else if (battery->health != POWER_SUPPLY_HEALTH_OVERHEAT) { | |
1389 | if (battery->temp_high_cnt < | |
1390 | battery->pdata->temp_check_count) { | |
1391 | battery->temp_high_cnt++; | |
1392 | battery->temp_highlimit_cnt = 0; | |
1393 | battery->temp_low_cnt = 0; | |
1394 | battery->temp_recover_cnt = 0; | |
1395 | } | |
1396 | dev_dbg(battery->dev, | |
1397 | "%s: high count = %d\n", | |
1398 | __func__, battery->temp_high_cnt); | |
1399 | } | |
1400 | } else if ((temp_value <= battery->temp_high_recovery) && | |
1401 | (temp_value >= battery->temp_low_recovery)) { | |
1402 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEAT || | |
1403 | battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT || | |
1404 | battery->health == POWER_SUPPLY_HEALTH_COLD) { | |
1405 | if (battery->temp_recover_cnt < | |
1406 | battery->pdata->temp_check_count) { | |
1407 | battery->temp_recover_cnt++; | |
1408 | battery->temp_highlimit_cnt = 0; | |
1409 | battery->temp_high_cnt = 0; | |
1410 | battery->temp_low_cnt = 0; | |
1411 | } | |
1412 | dev_dbg(battery->dev, | |
1413 | "%s: recovery count = %d\n", | |
1414 | __func__, battery->temp_recover_cnt); | |
1415 | } | |
1416 | } else if (temp_value <= battery->temp_low_threshold) { | |
1417 | if (battery->health != POWER_SUPPLY_HEALTH_COLD) { | |
1418 | if (battery->temp_low_cnt < | |
1419 | battery->pdata->temp_check_count) { | |
1420 | battery->temp_low_cnt++; | |
1421 | battery->temp_highlimit_cnt = 0; | |
1422 | battery->temp_high_cnt = 0; | |
1423 | battery->temp_recover_cnt = 0; | |
1424 | } | |
1425 | dev_dbg(battery->dev, | |
1426 | "%s: low count = %d\n", | |
1427 | __func__, battery->temp_low_cnt); | |
1428 | } | |
1429 | } else { | |
1430 | battery->temp_highlimit_cnt = 0; | |
1431 | battery->temp_high_cnt = 0; | |
1432 | battery->temp_low_cnt = 0; | |
1433 | battery->temp_recover_cnt = 0; | |
1434 | } | |
1435 | ||
1436 | if (battery->temp_highlimit_cnt >= | |
1437 | battery->pdata->temp_check_count) { | |
1438 | battery->health = POWER_SUPPLY_HEALTH_OVERHEATLIMIT; | |
1439 | battery->temp_highlimit_cnt = 0; | |
1440 | } else if (battery->temp_high_cnt >= | |
1441 | battery->pdata->temp_check_count) { | |
1442 | battery->health = POWER_SUPPLY_HEALTH_OVERHEAT; | |
1443 | battery->temp_high_cnt = 0; | |
1444 | } else if (battery->temp_low_cnt >= | |
1445 | battery->pdata->temp_check_count) { | |
1446 | battery->health = POWER_SUPPLY_HEALTH_COLD; | |
1447 | battery->temp_low_cnt = 0; | |
1448 | } else if (battery->temp_recover_cnt >= | |
1449 | battery->pdata->temp_check_count) { | |
1450 | if (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT) { | |
1451 | battery->health = POWER_SUPPLY_HEALTH_OVERHEAT; | |
1452 | } else { | |
1453 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
1454 | union power_supply_propval value; | |
1455 | ||
1456 | psy_do_property(battery->pdata->charger_name, get, | |
1457 | POWER_SUPPLY_PROP_VOLTAGE_MAX, value); | |
1458 | if (value.intval <= battery->pdata->swelling_normal_float_voltage) { | |
1459 | value.intval = battery->pdata->swelling_normal_float_voltage; | |
1460 | psy_do_property(battery->pdata->charger_name, set, | |
1461 | POWER_SUPPLY_PROP_VOLTAGE_MAX, value); | |
1462 | } | |
1463 | #endif | |
1464 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
1465 | } | |
1466 | battery->temp_recover_cnt = 0; | |
1467 | } | |
1468 | if (pre_health != battery->health) { | |
1469 | battery->health_change = true; | |
1470 | dev_info(battery->dev, "%s, health_change true\n", __func__); | |
1471 | } else { | |
1472 | battery->health_change = false; | |
1473 | } | |
1474 | ||
1475 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERHEAT) || | |
1476 | (battery->health == POWER_SUPPLY_HEALTH_COLD) || | |
1477 | (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT)) { | |
1478 | if (battery->status != POWER_SUPPLY_STATUS_NOT_CHARGING) { | |
1479 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
1480 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERHEAT) || | |
1481 | (battery->health == POWER_SUPPLY_HEALTH_OVERHEATLIMIT)) { | |
1482 | union power_supply_propval val; | |
1483 | /* change 4.20V float voltage */ | |
1484 | val.intval = battery->pdata->swelling_drop_float_voltage; | |
1485 | psy_do_property(battery->pdata->charger_name, set, | |
1486 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
1487 | } | |
1488 | #endif | |
1489 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
1490 | if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) { | |
1491 | union power_supply_propval val; | |
1492 | val.intval = battery->health; | |
1493 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
1494 | POWER_SUPPLY_PROP_HEALTH, val); | |
1495 | } | |
1496 | #endif | |
1497 | dev_info(battery->dev, | |
1498 | "%s: Unsafe Temperature\n", __func__); | |
1499 | sec_bat_set_charging_status(battery, | |
1500 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
1501 | /* change charging current to battery (default 0mA) */ | |
1502 | sec_bat_set_charge(battery, false); | |
1503 | return false; | |
1504 | } | |
1505 | } else { | |
1506 | /* if recovered from not charging */ | |
1507 | if ((battery->health == POWER_SUPPLY_HEALTH_GOOD) && | |
1508 | (battery->status == | |
1509 | POWER_SUPPLY_STATUS_NOT_CHARGING)) { | |
1510 | dev_info(battery->dev, | |
1511 | "%s: Safe Temperature\n", __func__); | |
1512 | if (battery->capacity >= 100) | |
1513 | sec_bat_set_charging_status(battery, | |
1514 | POWER_SUPPLY_STATUS_FULL); | |
1515 | else{ /* Normal Charging */ | |
1516 | sec_bat_set_charging_status(battery, | |
1517 | POWER_SUPPLY_STATUS_CHARGING); | |
1518 | if (battery->siop_level != 100) | |
1519 | battery->stop_timer = true; | |
1520 | } | |
1521 | #if defined(CONFIG_BATTERY_SWELLING) | |
1522 | if ((temp_value >= battery->pdata->swelling_high_temp_block) || | |
1523 | (temp_value <= battery->pdata->swelling_low_temp_block_2nd)) { | |
1524 | pr_info("%s: swelling mode start. stop charging\n", __func__); | |
1525 | battery->swelling_mode = true; | |
1526 | battery->swelling_full_check_cnt = 0; | |
1527 | sec_bat_set_charge(battery, false); | |
1528 | } else { | |
1529 | /* turn on charger by cable type */ | |
1530 | sec_bat_set_charge(battery, true); | |
1531 | } | |
1532 | #else | |
1533 | /* turn on charger by cable type */ | |
1534 | sec_bat_set_charge(battery, true); | |
1535 | #endif | |
1536 | return false; | |
1537 | } | |
1538 | } | |
1539 | return true; | |
1540 | } | |
1541 | ||
1542 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
1543 | static void sec_bat_self_discharging_check(struct sec_battery_info *battery) | |
1544 | { | |
1545 | unsigned int dis_adc; | |
1546 | union power_supply_propval value; | |
1547 | ||
1548 | switch(battery->pdata->self_discharging_type) { | |
1549 | case SEC_BAT_SELF_DISCHARGING_BY_ADC: | |
1550 | dis_adc = sec_bat_get_adc_value(battery, SEC_BAT_ADC_CHANNEL_DISCHARGING_CHECK); | |
1551 | if (dis_adc) | |
1552 | battery->self_discharging_adc = dis_adc; | |
1553 | else | |
1554 | battery->self_discharging_adc = 0; | |
1555 | ||
1556 | if ((dis_adc >= (int)battery->pdata->discharging_adc_min) && | |
1557 | (dis_adc <= (int)battery->pdata->discharging_adc_max)) | |
1558 | battery->self_discharging = true; | |
1559 | else | |
1560 | battery->self_discharging = false; | |
1561 | pr_info("%s : SELF_DISCHARGING(%d) SELF_DISCHARGING_ADC(%d)\n", | |
1562 | __func__, battery->self_discharging, battery->self_discharging_adc); | |
1563 | break; | |
1564 | case SEC_BAT_SELF_DISCHARGING_BY_FG: | |
1565 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
1566 | POWER_SUPPLY_PROP_CHARGE_ENABLED, value); | |
1567 | ||
1568 | battery->self_discharging = value.intval; | |
1569 | pr_info("%s: SELF_DISCHARGING : %s\n", __func__, | |
1570 | value.intval ? "Enabled" : "Disabled"); | |
1571 | break; | |
1572 | case SEC_BAT_SELF_DISCHARGING_BY_CHG: | |
1573 | psy_do_property(battery->pdata->charger_name, get, | |
1574 | POWER_SUPPLY_PROP_RESISTANCE, value); | |
1575 | ||
1576 | battery->self_discharging = value.intval; | |
1577 | pr_info("%s: SELF_DISCHARGING : %s\n", __func__, | |
1578 | value.intval ? "Enabled" : "Disabled"); | |
1579 | break; | |
1580 | default: | |
1581 | break; | |
1582 | } | |
1583 | } | |
1584 | ||
1585 | static void sec_bat_self_discharging_ntc_check(struct sec_battery_info *battery) | |
1586 | { | |
1587 | int ntc_adc; | |
1588 | ||
1589 | ntc_adc = sec_bat_get_adc_value(battery, SEC_BAT_ADC_CHANNEL_DISCHARGING_NTC); | |
1590 | if (ntc_adc) | |
1591 | battery->discharging_ntc_adc = ntc_adc; | |
1592 | else | |
1593 | battery->discharging_ntc_adc = 0; | |
1594 | ||
1595 | if (ntc_adc > battery->pdata->discharging_ntc_limit) | |
1596 | battery->discharging_ntc = true; | |
1597 | else | |
1598 | battery->discharging_ntc = false; | |
1599 | ||
1600 | pr_info("%s : DISCHARGING_NTC(%d) DISCHARGING_NTC_ADC(%d)\n", | |
1601 | __func__,battery->discharging_ntc, battery->discharging_ntc_adc); | |
1602 | } | |
1603 | ||
1604 | static void sec_bat_self_discharging_control(struct sec_battery_info *battery, bool dis_en) | |
1605 | { | |
1606 | union power_supply_propval value; | |
1607 | ||
1608 | switch(battery->pdata->self_discharging_type) { | |
1609 | case SEC_BAT_SELF_DISCHARGING_BY_ADC: | |
1610 | if (!battery->pdata->factory_discharging) { | |
1611 | pr_info("Can't control Self Discharging IC (No Factory Discharging Pin).\n"); | |
1612 | return; | |
1613 | } | |
1614 | ||
1615 | if (dis_en) { | |
1616 | dev_info(battery->dev, | |
1617 | "%s : Self Discharging IC doesn't act until (%d) degree & (%d) voltage. " | |
1618 | "Auto Discharging IC ENABLE\n", __func__, | |
1619 | battery->temperature, battery->voltage_now); | |
1620 | gpio_direction_output(battery->pdata->factory_discharging, 1); | |
1621 | battery->force_discharging = true; | |
1622 | } else { | |
1623 | dev_info(battery->dev, "%s : Self Discharging IC disable.\n", __func__); | |
1624 | gpio_direction_output(battery->pdata->factory_discharging, 0); | |
1625 | battery->force_discharging = false; | |
1626 | } | |
1627 | break; | |
1628 | case SEC_BAT_SELF_DISCHARGING_BY_FG: | |
1629 | value.intval = dis_en; | |
1630 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
1631 | POWER_SUPPLY_PROP_CHARGE_ENABLED, value); | |
1632 | ||
1633 | pr_info("%s: SELF_DISCHARGING Set to %s\n", __func__, | |
1634 | value.intval ? "Enabled" : "Disabled"); | |
1635 | break; | |
1636 | case SEC_BAT_SELF_DISCHARGING_BY_CHG: | |
1637 | if (dis_en) | |
1638 | battery->force_discharging = true; | |
1639 | else | |
1640 | battery->force_discharging = false; | |
1641 | ||
1642 | value.intval = dis_en; | |
1643 | psy_do_property(battery->pdata->charger_name, set, | |
1644 | POWER_SUPPLY_PROP_RESISTANCE, value); | |
1645 | ||
1646 | pr_info("%s: SELF_DISCHARGING Set to %s\n", __func__, | |
1647 | value.intval ? "Enabled" : "Disabled"); | |
1648 | break; | |
1649 | default: | |
1650 | break; | |
1651 | } | |
1652 | } | |
1653 | ||
1654 | static void sec_bat_discharging_check(struct sec_battery_info *battery) | |
1655 | { | |
1656 | if (!battery->pdata->self_discharging_en) | |
1657 | return; | |
1658 | ||
1659 | sec_bat_self_discharging_check(battery); | |
1660 | ||
1661 | if(battery->factory_self_discharging_mode_on) { | |
1662 | dev_info(battery->dev, | |
1663 | "%s: It is Factory mode by self discharging mode, Auto_DIS(%d), Force_DIS(%d)\n", | |
1664 | __func__, battery->self_discharging, battery->force_discharging); | |
1665 | return; | |
1666 | } | |
1667 | ||
1668 | if (!battery->self_discharging && | |
1669 | (battery->temperature >= battery->pdata->force_discharging_limit) && | |
1670 | (battery->voltage_now >= battery->pdata->self_discharging_voltage_limit)) { | |
1671 | sec_bat_self_discharging_control(battery, true); | |
1672 | } else if(battery->force_discharging && | |
1673 | ((battery->temperature <= battery->pdata->force_discharging_recov) || | |
1674 | (battery->voltage_now <= battery->pdata->swelling_drop_float_voltage))) { | |
1675 | sec_bat_self_discharging_control(battery, false); | |
1676 | } | |
1677 | dev_info(battery->dev, | |
1678 | "%s: Auto_DIS(%d), Force_DIS(%d)\n", | |
1679 | __func__, battery->self_discharging, battery->force_discharging); | |
1680 | } | |
1681 | #endif | |
1682 | ||
1683 | #if !defined(CONFIG_SEC_FACTORY) | |
1684 | static void sec_bat_chg_temperature_check( | |
1685 | struct sec_battery_info *battery) | |
1686 | { | |
1687 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
1688 | static bool is_vbus_changed = false; | |
1689 | union power_supply_propval value; | |
1690 | ||
1691 | pr_info("%s: called (is_vbus:%d, cable:%d))\n", __func__, is_vbus_changed, battery->cable_type); | |
1692 | if (battery->siop_level >= 100 && is_vbus_changed && | |
1693 | battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT) { | |
1694 | is_vbus_changed = false; | |
1695 | value.intval = SEC_INPUT_VOLTAGE_9V; | |
1696 | psy_do_property(battery->pdata->charger_name, set, | |
1697 | POWER_SUPPLY_PROP_SET_CHARGE_VOLTAGE, value); | |
1698 | pr_info("%s: changed vbus level 5V -> 9V\n", __func__); | |
1699 | return; | |
1700 | } else if (battery->siop_level < 100 && !is_vbus_changed && | |
1701 | battery->status == POWER_SUPPLY_STATUS_CHARGING && | |
1702 | is_hv_wire_type(battery->cable_type)) { | |
1703 | is_vbus_changed = true; | |
1704 | pr_info("%s: changed vbus level 9V -> 5V\n", __func__); | |
1705 | value.intval = SEC_INPUT_VOLTAGE_5V; | |
1706 | psy_do_property(battery->pdata->charger_name, set, | |
1707 | POWER_SUPPLY_PROP_SET_CHARGE_VOLTAGE, value); | |
1708 | return; | |
1709 | } else { | |
1710 | if ((is_vbus_changed && is_hv_wire_type(battery->cable_type)) || | |
1711 | (!is_vbus_changed && (battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT))) { | |
1712 | pr_info("%s: prevent abnormal case (cable_type:%d, is_vbus_changed:%d)\n", | |
1713 | __func__, battery->cable_type, is_vbus_changed); | |
1714 | return; | |
1715 | } else if (battery->cable_type == POWER_SUPPLY_TYPE_BATTERY) { | |
1716 | is_vbus_changed = false; | |
1717 | } | |
1718 | } | |
1719 | #endif | |
1720 | ||
1721 | if (battery->siop_level >= 100 && | |
1722 | ((battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS) || | |
1723 | (battery->cable_type == POWER_SUPPLY_TYPE_HV_ERR))) { | |
1724 | union power_supply_propval value; | |
1725 | if ((battery->chg_limit == SEC_BATTERY_CHG_TEMP_NONE) && | |
1726 | (battery->chg_temp > battery->pdata->chg_high_temp_1st)) { | |
1727 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_HIGH_1ST; | |
1728 | value.intval = battery->pdata->chg_charging_limit_current; | |
1729 | psy_do_property(battery->pdata->charger_name, set, | |
1730 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
1731 | dev_info(battery->dev,"%s: Chg current is reduced by Temp: %d\n", | |
1732 | __func__, battery->chg_temp); | |
1733 | } else if ((battery->chg_limit == SEC_BATTERY_CHG_TEMP_HIGH_1ST) && | |
1734 | (battery->pre_chg_temp < battery->pdata->chg_high_temp_2nd) && | |
1735 | (battery->chg_temp > battery->pdata->chg_high_temp_2nd)) { | |
1736 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_HIGH_2ND; | |
1737 | value.intval = battery->pdata->chg_charging_limit_current_2nd; | |
1738 | psy_do_property(battery->pdata->charger_name, set, | |
1739 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
1740 | dev_info(battery->dev,"%s: Chg current 2nd is reduced by Temp: %d\n", | |
1741 | __func__, battery->chg_temp); | |
1742 | } else if ((battery->chg_limit != SEC_BATTERY_CHG_TEMP_NONE) && | |
1743 | (battery->chg_temp < battery->pdata->chg_high_temp_recovery)) { | |
1744 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_NONE; | |
1745 | value.intval = battery->pdata->charging_current | |
1746 | [battery->cable_type].input_current_limit; | |
1747 | psy_do_property(battery->pdata->charger_name, set, | |
1748 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
1749 | dev_info(battery->dev,"%s: Chg current is recovered by Temp: %d\n", | |
1750 | __func__, battery->chg_temp); | |
1751 | } | |
1752 | } else if (battery->siop_level >= 100 && | |
1753 | (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) && battery->pdata->wpc_temp_check) { | |
1754 | union power_supply_propval value; | |
1755 | if ((battery->chg_limit == SEC_BATTERY_CHG_TEMP_NONE) && | |
1756 | (battery->chg_temp > battery->pdata->wpc_high_temp)) { | |
1757 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_HIGH_1ST; | |
1758 | value.intval = battery->pdata->wpc_charging_limit_current; | |
1759 | psy_do_property(battery->pdata->charger_name, set, | |
1760 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
1761 | dev_info(battery->dev,"%s: WPC Chg current is reduced by Temp: %d\n", | |
1762 | __func__, battery->chg_temp); | |
1763 | } else if ((battery->chg_limit != SEC_BATTERY_CHG_TEMP_NONE) && | |
1764 | (battery->chg_temp < battery->pdata->wpc_high_temp_recovery)) { | |
1765 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_NONE; | |
1766 | value.intval = battery->pdata->charging_current | |
1767 | [battery->cable_type].input_current_limit; | |
1768 | psy_do_property(battery->pdata->charger_name, set, | |
1769 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
1770 | dev_info(battery->dev,"%s: WPC Chg current is recovered by Temp: %d\n", | |
1771 | __func__, battery->chg_temp); | |
1772 | } | |
1773 | } else if (battery->chg_limit != SEC_BATTERY_CHG_TEMP_NONE) { | |
1774 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_NONE; | |
1775 | } | |
1776 | } | |
1777 | #endif | |
1778 | ||
1779 | static int sec_bat_get_inbat_vol_by_adc(struct sec_battery_info *battery) | |
1780 | { | |
1781 | int inbat = 0; | |
1782 | int inbat_adc; | |
1783 | int low = 0; | |
1784 | int high = 0; | |
1785 | int mid = 0; | |
1786 | const sec_bat_adc_table_data_t *inbat_adc_table; | |
1787 | unsigned int inbat_adc_table_size; | |
1788 | ||
1789 | if (!battery->pdata->inbat_adc_table) { | |
1790 | dev_err(battery->dev, "%s: not designed to read in-bat voltage\n", __func__); | |
1791 | return -1; | |
1792 | } | |
1793 | ||
1794 | inbat_adc_table = battery->pdata->inbat_adc_table; | |
1795 | inbat_adc_table_size = | |
1796 | battery->pdata->inbat_adc_table_size; | |
1797 | ||
1798 | inbat_adc = sec_bat_get_adc_value(battery, SEC_BAT_ADC_CHANNEL_INBAT_VOLTAGE); | |
1799 | if (inbat_adc <= 0) | |
1800 | return inbat_adc; | |
1801 | battery->inbat_adc = inbat_adc; | |
1802 | ||
1803 | if (inbat_adc_table[0].adc <= inbat_adc) { | |
1804 | inbat = inbat_adc_table[0].data; | |
1805 | goto inbat_by_adc_goto; | |
1806 | } else if (inbat_adc_table[inbat_adc_table_size-1].adc >= inbat_adc) { | |
1807 | inbat = inbat_adc_table[inbat_adc_table_size-1].data; | |
1808 | goto inbat_by_adc_goto; | |
1809 | } | |
1810 | ||
1811 | high = inbat_adc_table_size - 1; | |
1812 | ||
1813 | while (low <= high) { | |
1814 | mid = (low + high) / 2; | |
1815 | if (inbat_adc_table[mid].adc < inbat_adc) | |
1816 | high = mid - 1; | |
1817 | else if (inbat_adc_table[mid].adc > inbat_adc) | |
1818 | low = mid + 1; | |
1819 | else { | |
1820 | inbat = inbat_adc_table[mid].data; | |
1821 | goto inbat_by_adc_goto; | |
1822 | } | |
1823 | } | |
1824 | ||
1825 | inbat = inbat_adc_table[high].data; | |
1826 | inbat += | |
1827 | ((inbat_adc_table[low].data - inbat_adc_table[high].data) * | |
1828 | (inbat_adc - inbat_adc_table[high].adc)) / | |
1829 | (inbat_adc_table[low].adc - inbat_adc_table[high].adc); | |
1830 | ||
1831 | if (inbat < 0) | |
1832 | inbat = 0; | |
1833 | ||
1834 | inbat_by_adc_goto: | |
1835 | dev_info(battery->dev, | |
1836 | "%s: inbat(%d), inbat-ADC(%d)\n", | |
1837 | __func__, inbat, inbat_adc); | |
1838 | ||
1839 | return inbat; | |
1840 | } | |
1841 | ||
1842 | static void sec_bat_event_program_alarm( | |
1843 | struct sec_battery_info *battery, int seconds) | |
1844 | { | |
1845 | #if defined(ANDROID_ALARM_ACTIVATED) | |
1846 | ktime_t low_interval = ktime_set(seconds - 10, 0); | |
1847 | ktime_t slack = ktime_set(20, 0); | |
1848 | ktime_t next; | |
1849 | ||
1850 | next = ktime_add(battery->last_event_time, low_interval); | |
1851 | alarm_start_range(&battery->event_termination_alarm, | |
1852 | next, ktime_add(next, slack)); | |
1853 | #else | |
1854 | alarm_start(&battery->event_termination_alarm, | |
1855 | ktime_add(battery->last_event_time, ktime_set(seconds - 10, 0))); | |
1856 | #endif | |
1857 | } | |
1858 | ||
1859 | #if defined(ANDROID_ALARM_ACTIVATED) | |
1860 | static void sec_bat_event_expired_timer_func(struct alarm *alarm) | |
1861 | #else | |
1862 | static enum alarmtimer_restart sec_bat_event_expired_timer_func( | |
1863 | struct alarm *alarm, ktime_t now) | |
1864 | #endif | |
1865 | { | |
1866 | struct sec_battery_info *battery = | |
1867 | container_of(alarm, struct sec_battery_info, | |
1868 | event_termination_alarm); | |
1869 | ||
1870 | battery->event &= (~battery->event_wait); | |
1871 | dev_info(battery->dev, | |
1872 | "%s: event expired (0x%x)\n", __func__, battery->event); | |
1873 | ||
1874 | #if !defined(ANDROID_ALARM_ACTIVATED) | |
1875 | return ALARMTIMER_NORESTART; | |
1876 | #endif | |
1877 | } | |
1878 | ||
1879 | static void sec_bat_event_set( | |
1880 | struct sec_battery_info *battery, int event, int enable) | |
1881 | { | |
1882 | if (!battery->pdata->event_check) | |
1883 | return; | |
1884 | ||
1885 | /* ignore duplicated deactivation of same event | |
1886 | * only if the event is one last event | |
1887 | */ | |
1888 | if (!enable && (battery->event == battery->event_wait)) { | |
1889 | dev_info(battery->dev, | |
1890 | "%s: ignore duplicated deactivation of same event\n", | |
1891 | __func__); | |
1892 | return; | |
1893 | } | |
1894 | ||
1895 | alarm_cancel(&battery->event_termination_alarm); | |
1896 | battery->event &= (~battery->event_wait); | |
1897 | ||
1898 | if (enable) { | |
1899 | battery->event_wait = 0; | |
1900 | battery->event |= event; | |
1901 | ||
1902 | dev_info(battery->dev, | |
1903 | "%s: event set (0x%x)\n", __func__, battery->event); | |
1904 | } else { | |
1905 | if (battery->event == 0) { | |
1906 | dev_dbg(battery->dev, | |
1907 | "%s: nothing to clear\n", __func__); | |
1908 | return; /* nothing to clear */ | |
1909 | } | |
1910 | battery->event_wait = event; | |
1911 | #if defined(ANDROID_ALARM_ACTIVATED) | |
1912 | battery->last_event_time = alarm_get_elapsed_realtime(); | |
1913 | #else | |
1914 | battery->last_event_time = ktime_get_boottime(); | |
1915 | #endif | |
1916 | sec_bat_event_program_alarm(battery, | |
1917 | battery->pdata->event_waiting_time); | |
1918 | dev_info(battery->dev, | |
1919 | "%s: start timer (curr 0x%x, wait 0x%x)\n", | |
1920 | __func__, battery->event, battery->event_wait); | |
1921 | } | |
1922 | } | |
1923 | ||
1924 | static bool sec_bat_check_fullcharged_condition( | |
1925 | struct sec_battery_info *battery) | |
1926 | { | |
1927 | int full_check_type; | |
1928 | ||
1929 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST) | |
1930 | full_check_type = battery->pdata->full_check_type; | |
1931 | else | |
1932 | full_check_type = battery->pdata->full_check_type_2nd; | |
1933 | ||
1934 | switch (full_check_type) { | |
1935 | case SEC_BATTERY_FULLCHARGED_ADC: | |
1936 | case SEC_BATTERY_FULLCHARGED_FG_CURRENT: | |
1937 | case SEC_BATTERY_FULLCHARGED_SOC: | |
1938 | case SEC_BATTERY_FULLCHARGED_CHGGPIO: | |
1939 | case SEC_BATTERY_FULLCHARGED_CHGPSY: | |
1940 | break; | |
1941 | ||
1942 | /* If these is NOT full check type or NONE full check type, | |
1943 | * it is full-charged | |
1944 | */ | |
1945 | case SEC_BATTERY_FULLCHARGED_CHGINT: | |
1946 | case SEC_BATTERY_FULLCHARGED_TIME: | |
1947 | case SEC_BATTERY_FULLCHARGED_NONE: | |
1948 | default: | |
1949 | return true; | |
1950 | break; | |
1951 | } | |
1952 | ||
1953 | if (battery->pdata->full_condition_type & | |
1954 | SEC_BATTERY_FULL_CONDITION_SOC) { | |
1955 | if (battery->capacity < | |
1956 | battery->pdata->full_condition_soc) { | |
1957 | dev_dbg(battery->dev, | |
1958 | "%s: Not enough SOC (%d%%)\n", | |
1959 | __func__, battery->capacity); | |
1960 | return false; | |
1961 | } | |
1962 | } | |
1963 | ||
1964 | if (battery->pdata->full_condition_type & | |
1965 | SEC_BATTERY_FULL_CONDITION_VCELL) { | |
1966 | if (battery->voltage_now < | |
1967 | battery->pdata->full_condition_vcell) { | |
1968 | dev_dbg(battery->dev, | |
1969 | "%s: Not enough VCELL (%dmV)\n", | |
1970 | __func__, battery->voltage_now); | |
1971 | return false; | |
1972 | } | |
1973 | } | |
1974 | ||
1975 | if (battery->pdata->full_condition_type & | |
1976 | SEC_BATTERY_FULL_CONDITION_AVGVCELL) { | |
1977 | if (battery->voltage_avg < | |
1978 | battery->pdata->full_condition_avgvcell) { | |
1979 | dev_dbg(battery->dev, | |
1980 | "%s: Not enough AVGVCELL (%dmV)\n", | |
1981 | __func__, battery->voltage_avg); | |
1982 | return false; | |
1983 | } | |
1984 | } | |
1985 | ||
1986 | if (battery->pdata->full_condition_type & | |
1987 | SEC_BATTERY_FULL_CONDITION_OCV) { | |
1988 | if (battery->voltage_ocv < | |
1989 | battery->pdata->full_condition_ocv) { | |
1990 | dev_dbg(battery->dev, | |
1991 | "%s: Not enough OCV (%dmV)\n", | |
1992 | __func__, battery->voltage_ocv); | |
1993 | return false; | |
1994 | } | |
1995 | } | |
1996 | ||
1997 | return true; | |
1998 | } | |
1999 | ||
2000 | static void sec_bat_do_test_function( | |
2001 | struct sec_battery_info *battery) | |
2002 | { | |
2003 | union power_supply_propval value; | |
2004 | ||
2005 | switch (battery->test_mode) { | |
2006 | case 1: | |
2007 | if (battery->status == POWER_SUPPLY_STATUS_CHARGING) { | |
2008 | sec_bat_set_charge(battery, false); | |
2009 | sec_bat_set_charging_status(battery, | |
2010 | POWER_SUPPLY_STATUS_DISCHARGING); | |
2011 | } | |
2012 | break; | |
2013 | case 2: | |
2014 | if(battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
2015 | sec_bat_set_charge(battery, true); | |
2016 | psy_do_property(battery->pdata->charger_name, get, | |
2017 | POWER_SUPPLY_PROP_STATUS, value); | |
2018 | sec_bat_set_charging_status(battery, value.intval); | |
2019 | } | |
2020 | battery->test_mode = 0; | |
2021 | break; | |
2022 | case 3: // clear temp block | |
2023 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
2024 | sec_bat_set_charging_status(battery, | |
2025 | POWER_SUPPLY_STATUS_DISCHARGING); | |
2026 | break; | |
2027 | case 4: | |
2028 | if(battery->status == POWER_SUPPLY_STATUS_DISCHARGING) { | |
2029 | sec_bat_set_charge(battery, true); | |
2030 | psy_do_property(battery->pdata->charger_name, get, | |
2031 | POWER_SUPPLY_PROP_STATUS, value); | |
2032 | sec_bat_set_charging_status(battery, value.intval); | |
2033 | } | |
2034 | break; | |
2035 | default: | |
2036 | pr_info("%s: error test: unknown state\n", __func__); | |
2037 | break; | |
2038 | } | |
2039 | } | |
2040 | ||
2041 | static bool sec_bat_time_management( | |
2042 | struct sec_battery_info *battery) | |
2043 | { | |
2044 | unsigned long charging_time; | |
2045 | //unsigned long expired_time = 0; | |
2046 | struct timespec ts; | |
2047 | //unsigned int charging_total_time = 10 * 60 * 60; | |
2048 | #if defined(ANDROID_ALARM_ACTIVATED) | |
2049 | ktime_t current_time; | |
2050 | ||
2051 | current_time = alarm_get_elapsed_realtime(); | |
2052 | ts = ktime_to_timespec(current_time); | |
2053 | #else | |
2054 | get_monotonic_boottime(&ts); | |
2055 | #endif | |
2056 | ||
2057 | if(battery->charging_start_time == 0 || !battery->safety_timer_set) { | |
2058 | pr_info("%s: Charging Disabled\n" ,__func__); | |
2059 | return true; | |
2060 | } | |
2061 | ||
2062 | if (ts.tv_sec >= battery->charging_start_time) | |
2063 | charging_time = ts.tv_sec - battery->charging_start_time; | |
2064 | else | |
2065 | charging_time = 0xFFFFFFFF - battery->charging_start_time | |
2066 | + ts.tv_sec; | |
2067 | ||
2068 | battery->charging_passed_time = charging_time; | |
2069 | #if 0 | |
2070 | if (!battery->store_mode) { | |
2071 | if (battery->cable_type == POWER_SUPPLY_TYPE_HV_ERR || | |
2072 | battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS || | |
2073 | battery->cable_type == POWER_SUPPLY_TYPE_HV_UNKNOWN) { | |
2074 | charging_total_time = battery->pdata->hv_charging_total_time; | |
2075 | } else if (battery->cable_type == POWER_SUPPLY_TYPE_MAINS || | |
2076 | battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) { | |
2077 | charging_total_time = battery->pdata->normal_charging_total_time; | |
2078 | } else { | |
2079 | charging_total_time = battery->pdata->usb_charging_total_time; | |
2080 | } | |
2081 | } | |
2082 | #endif | |
2083 | dev_info(battery->dev, | |
2084 | "%s: Charging Time : %ld secs\n", __func__, | |
2085 | battery->charging_passed_time); | |
2086 | #if 0 | |
2087 | if (battery->siop_level >= 100) { | |
2088 | if (charging_time < battery->lcd_on_total_time) | |
2089 | battery->lcd_on_total_time = charging_time; | |
2090 | expired_time = charging_time - battery->lcd_on_total_time; | |
2091 | pr_info("%s: Total Charging time : %ld, Expired Time : %ld, LCD On total Time : %ld\n", | |
2092 | __func__, charging_time, expired_time, battery->lcd_on_total_time); | |
2093 | } else { | |
2094 | return true; | |
2095 | } | |
2096 | #endif | |
2097 | switch (battery->status) { | |
2098 | case POWER_SUPPLY_STATUS_FULL: | |
2099 | if (battery->expired_time == 0) { | |
2100 | dev_info(battery->dev, | |
2101 | "%s: Recharging Timer Expired\n", __func__); | |
2102 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2103 | battery->health = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; | |
2104 | sec_bat_set_charging_status(battery, | |
2105 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
2106 | battery->is_recharging = false; | |
2107 | if (sec_bat_set_charge(battery, false)) { | |
2108 | dev_err(battery->dev, | |
2109 | "%s: Fail to Set Charger\n", __func__); | |
2110 | return true; | |
2111 | } | |
2112 | ||
2113 | return false; | |
2114 | } | |
2115 | break; | |
2116 | case POWER_SUPPLY_STATUS_CHARGING: | |
2117 | if ((battery->pdata->full_condition_type & | |
2118 | SEC_BATTERY_FULL_CONDITION_NOTIMEFULL) && | |
2119 | (battery->is_recharging && (battery->expired_time == 0))) { | |
2120 | dev_info(battery->dev, | |
2121 | "%s: Recharging Timer Expired\n", __func__); | |
2122 | battery->health = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; | |
2123 | sec_bat_set_charging_status(battery, | |
2124 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
2125 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2126 | battery->is_recharging = false; | |
2127 | if (sec_bat_set_charge(battery, false)) { | |
2128 | dev_err(battery->dev, | |
2129 | "%s: Fail to Set Charger\n", __func__); | |
2130 | return true; | |
2131 | } | |
2132 | return false; | |
2133 | } else if (!battery->is_recharging && (battery->expired_time == 0)) { | |
2134 | dev_info(battery->dev, | |
2135 | "%s: Charging Timer Expired\n", __func__); | |
2136 | battery->health = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; | |
2137 | sec_bat_set_charging_status(battery, | |
2138 | POWER_SUPPLY_STATUS_NOT_CHARGING); | |
2139 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2140 | if (sec_bat_set_charge(battery, false)) { | |
2141 | dev_err(battery->dev, | |
2142 | "%s: Fail to Set Charger\n", __func__); | |
2143 | return true; | |
2144 | } | |
2145 | ||
2146 | return false; | |
2147 | } | |
2148 | #if 0 | |
2149 | if (battery->pdata->charging_reset_time) { | |
2150 | if (charging_time > battery->charging_next_time) { | |
2151 | /*reset current in charging status */ | |
2152 | battery->charging_next_time = | |
2153 | battery->charging_passed_time + | |
2154 | (battery->pdata->charging_reset_time); | |
2155 | ||
2156 | dev_dbg(battery->dev, | |
2157 | "%s: Reset charging current\n", | |
2158 | __func__); | |
2159 | #if defined(CONFIG_BATTERY_SWELLING) | |
2160 | if (!battery->swelling_mode) { | |
2161 | if (sec_bat_set_charge(battery, true)) { | |
2162 | dev_err(battery->dev, | |
2163 | "%s: Fail to Set Charger\n", | |
2164 | __func__); | |
2165 | return true; | |
2166 | } | |
2167 | } | |
2168 | #else | |
2169 | if (sec_bat_set_charge(battery, true)) { | |
2170 | dev_err(battery->dev, | |
2171 | "%s: Fail to Set Charger\n", | |
2172 | __func__); | |
2173 | return true; | |
2174 | } | |
2175 | #endif | |
2176 | } | |
2177 | } | |
2178 | #endif | |
2179 | break; | |
2180 | default: | |
2181 | dev_err(battery->dev, | |
2182 | "%s: Undefine Battery Status\n", __func__); | |
2183 | return true; | |
2184 | } | |
2185 | ||
2186 | return true; | |
2187 | } | |
2188 | ||
2189 | static bool sec_bat_check_fullcharged( | |
2190 | struct sec_battery_info *battery) | |
2191 | { | |
2192 | union power_supply_propval value; | |
2193 | int current_adc; | |
2194 | int full_check_type; | |
2195 | bool ret; | |
2196 | int err; | |
2197 | ||
2198 | ret = false; | |
2199 | ||
2200 | if (!sec_bat_check_fullcharged_condition(battery)) | |
2201 | goto not_full_charged; | |
2202 | ||
2203 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST) | |
2204 | full_check_type = battery->pdata->full_check_type; | |
2205 | else | |
2206 | full_check_type = battery->pdata->full_check_type_2nd; | |
2207 | ||
2208 | pr_info("%s : full_check_type(%d)\n", __func__, full_check_type); | |
2209 | ||
2210 | switch (full_check_type) { | |
2211 | case SEC_BATTERY_FULLCHARGED_ADC: | |
2212 | current_adc = | |
2213 | sec_bat_get_adc_value(battery, | |
2214 | SEC_BAT_ADC_CHANNEL_FULL_CHECK); | |
2215 | ||
2216 | dev_dbg(battery->dev, | |
2217 | "%s: Current ADC (%d)\n", | |
2218 | __func__, current_adc); | |
2219 | ||
2220 | if (current_adc < 0) | |
2221 | break; | |
2222 | battery->current_adc = current_adc; | |
2223 | ||
2224 | if (battery->current_adc < | |
2225 | (battery->charging_mode == | |
2226 | SEC_BATTERY_CHARGING_1ST ? | |
2227 | battery->pdata->charging_current[ | |
2228 | battery->cable_type].full_check_current_1st : | |
2229 | battery->pdata->charging_current[ | |
2230 | battery->cable_type].full_check_current_2nd)) { | |
2231 | battery->full_check_cnt++; | |
2232 | dev_dbg(battery->dev, | |
2233 | "%s: Full Check ADC (%d)\n", | |
2234 | __func__, | |
2235 | battery->full_check_cnt); | |
2236 | } else | |
2237 | battery->full_check_cnt = 0; | |
2238 | break; | |
2239 | ||
2240 | case SEC_BATTERY_FULLCHARGED_FG_CURRENT: | |
2241 | if ((battery->current_now > 0 && battery->current_now < | |
2242 | battery->pdata->charging_current[ | |
2243 | battery->cable_type].full_check_current_1st) && | |
2244 | (battery->current_avg > 0 && battery->current_avg < | |
2245 | (battery->charging_mode == | |
2246 | SEC_BATTERY_CHARGING_1ST ? | |
2247 | battery->pdata->charging_current[ | |
2248 | battery->cable_type].full_check_current_1st : | |
2249 | battery->pdata->charging_current[ | |
2250 | battery->cable_type].full_check_current_2nd))) { | |
2251 | battery->full_check_cnt++; | |
2252 | dev_dbg(battery->dev, | |
2253 | "%s: Full Check Current (%d)\n", | |
2254 | __func__, | |
2255 | battery->full_check_cnt); | |
2256 | } else | |
2257 | battery->full_check_cnt = 0; | |
2258 | break; | |
2259 | ||
2260 | case SEC_BATTERY_FULLCHARGED_TIME: | |
2261 | if ((battery->charging_mode == | |
2262 | SEC_BATTERY_CHARGING_2ND ? | |
2263 | (battery->charging_passed_time - | |
2264 | battery->charging_fullcharged_time) : | |
2265 | battery->charging_passed_time) > | |
2266 | (battery->charging_mode == | |
2267 | SEC_BATTERY_CHARGING_1ST ? | |
2268 | battery->pdata->charging_current[ | |
2269 | battery->cable_type].full_check_current_1st : | |
2270 | battery->pdata->charging_current[ | |
2271 | battery->cable_type].full_check_current_2nd)) { | |
2272 | battery->full_check_cnt++; | |
2273 | dev_dbg(battery->dev, | |
2274 | "%s: Full Check Time (%d)\n", | |
2275 | __func__, | |
2276 | battery->full_check_cnt); | |
2277 | } else | |
2278 | battery->full_check_cnt = 0; | |
2279 | break; | |
2280 | ||
2281 | case SEC_BATTERY_FULLCHARGED_SOC: | |
2282 | if (battery->capacity <= | |
2283 | (battery->charging_mode == | |
2284 | SEC_BATTERY_CHARGING_1ST ? | |
2285 | battery->pdata->charging_current[ | |
2286 | battery->cable_type].full_check_current_1st : | |
2287 | battery->pdata->charging_current[ | |
2288 | battery->cable_type].full_check_current_2nd)) { | |
2289 | battery->full_check_cnt++; | |
2290 | dev_dbg(battery->dev, | |
2291 | "%s: Full Check SOC (%d)\n", | |
2292 | __func__, | |
2293 | battery->full_check_cnt); | |
2294 | } else | |
2295 | battery->full_check_cnt = 0; | |
2296 | break; | |
2297 | ||
2298 | case SEC_BATTERY_FULLCHARGED_CHGGPIO: | |
2299 | err = gpio_request( | |
2300 | battery->pdata->chg_gpio_full_check, | |
2301 | "GPIO_CHG_FULL"); | |
2302 | if (err) { | |
2303 | dev_err(battery->dev, | |
2304 | "%s: Error in Request of GPIO\n", __func__); | |
2305 | break; | |
2306 | } | |
2307 | if (!(gpio_get_value_cansleep( | |
2308 | battery->pdata->chg_gpio_full_check) ^ | |
2309 | !battery->pdata->chg_polarity_full_check)) { | |
2310 | battery->full_check_cnt++; | |
2311 | dev_dbg(battery->dev, | |
2312 | "%s: Full Check GPIO (%d)\n", | |
2313 | __func__, battery->full_check_cnt); | |
2314 | } else | |
2315 | battery->full_check_cnt = 0; | |
2316 | gpio_free(battery->pdata->chg_gpio_full_check); | |
2317 | break; | |
2318 | ||
2319 | case SEC_BATTERY_FULLCHARGED_CHGINT: | |
2320 | case SEC_BATTERY_FULLCHARGED_CHGPSY: | |
2321 | psy_do_property(battery->pdata->charger_name, get, | |
2322 | POWER_SUPPLY_PROP_STATUS, value); | |
2323 | ||
2324 | if (value.intval == POWER_SUPPLY_STATUS_FULL) { | |
2325 | battery->full_check_cnt++; | |
2326 | dev_info(battery->dev, | |
2327 | "%s: Full Check Charger (%d)\n", | |
2328 | __func__, battery->full_check_cnt); | |
2329 | } else | |
2330 | battery->full_check_cnt = 0; | |
2331 | break; | |
2332 | ||
2333 | /* If these is NOT full check type or NONE full check type, | |
2334 | * it is full-charged | |
2335 | */ | |
2336 | case SEC_BATTERY_FULLCHARGED_NONE: | |
2337 | battery->full_check_cnt = 0; | |
2338 | ret = true; | |
2339 | break; | |
2340 | default: | |
2341 | dev_err(battery->dev, | |
2342 | "%s: Invalid Full Check\n", __func__); | |
2343 | break; | |
2344 | } | |
2345 | ||
2346 | if (battery->full_check_cnt >= | |
2347 | battery->pdata->full_check_count) { | |
2348 | battery->full_check_cnt = 0; | |
2349 | ret = true; | |
2350 | } | |
2351 | ||
2352 | not_full_charged: | |
2353 | return ret; | |
2354 | } | |
2355 | ||
2356 | static void sec_bat_do_fullcharged( | |
2357 | struct sec_battery_info *battery) | |
2358 | { | |
2359 | union power_supply_propval value; | |
2360 | ||
2361 | /* To let charger/fuel gauge know the full status, | |
2362 | * set status before calling sec_bat_set_charge() | |
2363 | */ | |
2364 | sec_bat_set_charging_status(battery, | |
2365 | POWER_SUPPLY_STATUS_FULL); | |
2366 | ||
2367 | ||
2368 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST) { | |
2369 | battery->charging_mode = SEC_BATTERY_CHARGING_2ND; | |
2370 | battery->charging_fullcharged_time = | |
2371 | battery->charging_passed_time; | |
2372 | sec_bat_set_charge(battery, true); | |
2373 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) && defined(CONFIG_WIRELESS_CHARGER_INBATTERY_CS100) | |
2374 | if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) { | |
2375 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
2376 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
2377 | POWER_SUPPLY_PROP_STATUS, value); | |
2378 | } | |
2379 | #endif | |
2380 | } else { | |
2381 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2382 | battery->is_recharging = false; | |
2383 | sec_bat_set_charge(battery, false); | |
2384 | ||
2385 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) && !defined(CONFIG_WIRELESS_CHARGER_INBATTERY_CS100) | |
2386 | if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) { | |
2387 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
2388 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
2389 | POWER_SUPPLY_PROP_STATUS, value); | |
2390 | } | |
2391 | #endif | |
2392 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
2393 | sec_bat_aging_check(battery); | |
2394 | #endif | |
2395 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
2396 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2397 | POWER_SUPPLY_PROP_STATUS, value); | |
2398 | } | |
2399 | ||
2400 | #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX) | |
2401 | #if defined(CONFIG_PREVENT_SOC_JUMP) | |
2402 | value.intval = battery->capacity; | |
2403 | #else | |
2404 | value.intval = POWER_SUPPLY_TYPE_BATTERY; | |
2405 | #endif | |
2406 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2407 | POWER_SUPPLY_PROP_CHARGE_FULL, value); | |
2408 | #endif | |
2409 | ||
2410 | /* platform can NOT get information of battery | |
2411 | * because wakeup time is too short to check uevent | |
2412 | * To make sure that target is wakeup if full-charged, | |
2413 | * activated wake lock in a few seconds | |
2414 | */ | |
2415 | if (battery->pdata->polling_type == SEC_BATTERY_MONITOR_ALARM) | |
2416 | wake_lock_timeout(&battery->vbus_wake_lock, HZ * 10); | |
2417 | } | |
2418 | ||
2419 | static bool sec_bat_fullcharged_check( | |
2420 | struct sec_battery_info *battery) | |
2421 | { | |
2422 | if ((battery->charging_mode == SEC_BATTERY_CHARGING_NONE) || | |
2423 | (battery->status == POWER_SUPPLY_STATUS_NOT_CHARGING)) { | |
2424 | dev_dbg(battery->dev, | |
2425 | "%s: No Need to Check Full-Charged\n", __func__); | |
2426 | return true; | |
2427 | } | |
2428 | ||
2429 | if (sec_bat_check_fullcharged(battery)) | |
2430 | sec_bat_do_fullcharged(battery); | |
2431 | ||
2432 | dev_info(battery->dev, | |
2433 | "%s: Charging Mode : %s\n", __func__, | |
2434 | battery->is_recharging ? | |
2435 | sec_bat_charging_mode_str[SEC_BATTERY_CHARGING_RECHARGING] : | |
2436 | sec_bat_charging_mode_str[battery->charging_mode]); | |
2437 | ||
2438 | return true; | |
2439 | } | |
2440 | ||
2441 | static void sec_bat_get_temperature_info( | |
2442 | struct sec_battery_info *battery) | |
2443 | { | |
2444 | union power_supply_propval value; | |
2445 | ||
2446 | switch (battery->pdata->thermal_source) { | |
2447 | case SEC_BATTERY_THERMAL_SOURCE_FG: | |
2448 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2449 | POWER_SUPPLY_PROP_TEMP, value); | |
2450 | battery->temperature = value.intval; | |
2451 | ||
2452 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2453 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
2454 | battery->temper_amb = value.intval; | |
2455 | break; | |
2456 | case SEC_BATTERY_THERMAL_SOURCE_CALLBACK: | |
2457 | if (battery->pdata->get_temperature_callback) { | |
2458 | battery->pdata->get_temperature_callback( | |
2459 | POWER_SUPPLY_PROP_TEMP, &value); | |
2460 | battery->temperature = value.intval; | |
2461 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2462 | POWER_SUPPLY_PROP_TEMP, value); | |
2463 | ||
2464 | battery->pdata->get_temperature_callback( | |
2465 | POWER_SUPPLY_PROP_TEMP_AMBIENT, &value); | |
2466 | battery->temper_amb = value.intval; | |
2467 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2468 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
2469 | } | |
2470 | break; | |
2471 | case SEC_BATTERY_THERMAL_SOURCE_ADC: | |
2472 | sec_bat_get_temperature_by_adc(battery, | |
2473 | SEC_BAT_ADC_CHANNEL_TEMP, &value); | |
2474 | battery->temperature = value.intval; | |
2475 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2476 | POWER_SUPPLY_PROP_TEMP, value); | |
2477 | ||
2478 | sec_bat_get_temperature_by_adc(battery, | |
2479 | SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT, &value); | |
2480 | battery->temper_amb = value.intval; | |
2481 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2482 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
2483 | ||
2484 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
2485 | sec_bat_get_temperature_by_adc(battery, | |
2486 | SEC_BAT_ADC_CHANNEL_CHG_TEMP, &value); | |
2487 | if (battery->pre_chg_temp == 0) { | |
2488 | battery->pre_chg_temp = value.intval; | |
2489 | battery->chg_temp = value.intval; | |
2490 | } else { | |
2491 | battery->pre_chg_temp = battery->chg_temp; | |
2492 | battery->chg_temp = value.intval; | |
2493 | } | |
2494 | #endif | |
2495 | break; | |
2496 | default: | |
2497 | break; | |
2498 | } | |
2499 | } | |
2500 | ||
2501 | static void sec_bat_get_battery_info( | |
2502 | struct sec_battery_info *battery) | |
2503 | { | |
2504 | union power_supply_propval value; | |
2505 | #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP) | |
2506 | static struct timespec old_ts; | |
2507 | struct timespec c_ts; | |
2508 | #if defined(ANDROID_ALARM_ACTIVATED) | |
2509 | c_ts = ktime_to_timespec(alarm_get_elapsed_realtime()); | |
2510 | #else | |
2511 | c_ts = ktime_to_timespec(ktime_get_boottime()); | |
2512 | #endif | |
2513 | #endif | |
2514 | ||
2515 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2516 | POWER_SUPPLY_PROP_VOLTAGE_NOW, value); | |
2517 | battery->voltage_now = value.intval; | |
2518 | ||
2519 | value.intval = SEC_BATTERY_VOLTAGE_AVERAGE; | |
2520 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2521 | POWER_SUPPLY_PROP_VOLTAGE_AVG, value); | |
2522 | battery->voltage_avg = value.intval; | |
2523 | ||
2524 | value.intval = SEC_BATTERY_VOLTAGE_OCV; | |
2525 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2526 | POWER_SUPPLY_PROP_VOLTAGE_AVG, value); | |
2527 | battery->voltage_ocv = value.intval; | |
2528 | ||
2529 | value.intval = SEC_BATTERY_CURRENT_MA; | |
2530 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2531 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
2532 | battery->current_now = value.intval; | |
2533 | ||
2534 | value.intval = SEC_BATTERY_CURRENT_MA; | |
2535 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2536 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
2537 | battery->current_avg = value.intval; | |
2538 | ||
2539 | /* input current limit in charger */ | |
2540 | psy_do_property(battery->pdata->charger_name, get, | |
2541 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
2542 | battery->current_max = value.intval; | |
2543 | ||
2544 | sec_bat_get_temperature_info(battery); | |
2545 | ||
2546 | /* To get SOC value (NOT raw SOC), need to reset value */ | |
2547 | value.intval = 0; | |
2548 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2549 | POWER_SUPPLY_PROP_CAPACITY, value); | |
2550 | #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP) | |
2551 | /* if the battery status was full, and SOC wasn't 100% yet, | |
2552 | then ignore FG SOC, and report (previous SOC +1)% */ | |
2553 | if (battery->status != POWER_SUPPLY_STATUS_FULL) { | |
2554 | battery->capacity = value.intval; | |
2555 | } else if ((c_ts.tv_sec - old_ts.tv_sec) >= 30) { | |
2556 | if (battery->capacity != 100) { | |
2557 | battery->capacity++; | |
2558 | pr_info("%s : forced full-charged sequence for the capacity(%d)\n", | |
2559 | __func__, battery->capacity); | |
2560 | } | |
2561 | ||
2562 | if (value.intval >= battery->pdata->full_condition_soc && | |
2563 | battery->voltage_now >= (battery->pdata->recharge_condition_vcell - 50)) { | |
2564 | /* update capacity max */ | |
2565 | value.intval = battery->capacity; | |
2566 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
2567 | POWER_SUPPLY_PROP_CHARGE_FULL, value); | |
2568 | } | |
2569 | old_ts = c_ts; | |
2570 | } | |
2571 | #else | |
2572 | battery->capacity = value.intval; | |
2573 | #endif | |
2574 | ||
2575 | if (battery->capacity > 5 && battery->ignore_siop && | |
2576 | (battery->r_siop_level != battery->siop_level)) { | |
2577 | battery->siop_level = battery->r_siop_level; | |
2578 | battery->ignore_siop = false; | |
2579 | if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) | |
2580 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->siop_work, | |
2581 | msecs_to_jiffies(1200)); | |
2582 | else | |
2583 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->siop_work, 0); | |
2584 | } | |
2585 | ||
2586 | #if !defined(CONFIG_SEC_FACTORY) | |
2587 | if (battery->capacity > 5 && battery->ignore_store_mode) { | |
2588 | battery->ignore_store_mode = false; | |
2589 | value.intval = battery->store_mode; | |
2590 | psy_do_property(battery->pdata->charger_name, set, | |
2591 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, value); | |
2592 | } | |
2593 | #endif | |
2594 | ||
2595 | dev_info(battery->dev, | |
2596 | "%s:Vnow(%dmV),Inow(%dmA),Imax(%dmA),SOC(%d%%),Tbat(%d),Tchg(%d),is_hc_usb(%d)\n", | |
2597 | __func__, | |
2598 | battery->voltage_now, battery->current_now, | |
2599 | battery->current_max, battery->capacity, | |
2600 | battery->temperature, battery->chg_temp, battery->is_hc_usb); | |
2601 | dev_dbg(battery->dev, | |
2602 | "%s,Vavg(%dmV),Vocv(%dmV),Tamb(%d)," | |
2603 | "Iavg(%dmA),Iadc(%d)\n", | |
2604 | battery->present ? "Connected" : "Disconnected", | |
2605 | battery->voltage_avg, battery->voltage_ocv, | |
2606 | battery->temper_amb, | |
2607 | battery->current_avg, battery->current_adc); | |
2608 | } | |
2609 | ||
2610 | static void sec_bat_polling_work(struct work_struct *work) | |
2611 | { | |
2612 | struct sec_battery_info *battery = container_of( | |
2613 | work, struct sec_battery_info, polling_work.work); | |
2614 | ||
2615 | wake_lock(&battery->monitor_wake_lock); | |
2616 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
2617 | dev_dbg(battery->dev, "%s: Activated\n", __func__); | |
2618 | } | |
2619 | ||
2620 | static void sec_bat_program_alarm( | |
2621 | struct sec_battery_info *battery, int seconds) | |
2622 | { | |
2623 | #if defined(ANDROID_ALARM_ACTIVATED) | |
2624 | ktime_t low_interval = ktime_set(seconds, 0); | |
2625 | ktime_t slack = ktime_set(10, 0); | |
2626 | ktime_t next; | |
2627 | ||
2628 | next = ktime_add(battery->last_poll_time, low_interval); | |
2629 | alarm_start_range(&battery->polling_alarm, | |
2630 | next, ktime_add(next, slack)); | |
2631 | #else | |
2632 | alarm_start(&battery->polling_alarm, | |
2633 | ktime_add(battery->last_poll_time, ktime_set(seconds, 0))); | |
2634 | #endif | |
2635 | } | |
2636 | ||
2637 | static unsigned int sec_bat_get_polling_time( | |
2638 | struct sec_battery_info *battery) | |
2639 | { | |
2640 | if (battery->status == | |
2641 | POWER_SUPPLY_STATUS_FULL) | |
2642 | battery->polling_time = | |
2643 | battery->pdata->polling_time[ | |
2644 | POWER_SUPPLY_STATUS_CHARGING]; | |
2645 | else | |
2646 | battery->polling_time = | |
2647 | battery->pdata->polling_time[ | |
2648 | battery->status]; | |
2649 | ||
2650 | battery->polling_short = true; | |
2651 | ||
2652 | switch (battery->status) { | |
2653 | case POWER_SUPPLY_STATUS_CHARGING: | |
2654 | if (battery->polling_in_sleep) | |
2655 | battery->polling_short = false; | |
2656 | break; | |
2657 | case POWER_SUPPLY_STATUS_DISCHARGING: | |
2658 | if (battery->polling_in_sleep && (battery->ps_enable != true)) { | |
2659 | battery->polling_time = | |
2660 | battery->pdata->polling_time[ | |
2661 | SEC_BATTERY_POLLING_TIME_SLEEP]; | |
2662 | } else | |
2663 | battery->polling_time = | |
2664 | battery->pdata->polling_time[ | |
2665 | battery->status]; | |
2666 | battery->polling_short = false; | |
2667 | break; | |
2668 | case POWER_SUPPLY_STATUS_FULL: | |
2669 | if (battery->polling_in_sleep) { | |
2670 | if (!(battery->pdata->full_condition_type & | |
2671 | SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL) && | |
2672 | battery->charging_mode == | |
2673 | SEC_BATTERY_CHARGING_NONE) { | |
2674 | battery->polling_time = | |
2675 | battery->pdata->polling_time[ | |
2676 | SEC_BATTERY_POLLING_TIME_SLEEP]; | |
2677 | } | |
2678 | battery->polling_short = false; | |
2679 | } else { | |
2680 | if (battery->charging_mode == | |
2681 | SEC_BATTERY_CHARGING_NONE) | |
2682 | battery->polling_short = false; | |
2683 | } | |
2684 | break; | |
2685 | } | |
2686 | ||
2687 | if (battery->polling_short) | |
2688 | return battery->pdata->polling_time[ | |
2689 | SEC_BATTERY_POLLING_TIME_BASIC]; | |
2690 | /* set polling time to 46s to reduce current noise on wc */ | |
2691 | else if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS && | |
2692 | battery->status == POWER_SUPPLY_STATUS_CHARGING) | |
2693 | battery->polling_time = 46; | |
2694 | ||
2695 | return battery->polling_time; | |
2696 | } | |
2697 | ||
2698 | static bool sec_bat_is_short_polling( | |
2699 | struct sec_battery_info *battery) | |
2700 | { | |
2701 | /* Change the full and short monitoring sequence | |
2702 | * Originally, full monitoring was the last time of polling_count | |
2703 | * But change full monitoring to first time | |
2704 | * because temperature check is too late | |
2705 | */ | |
2706 | if (!battery->polling_short || battery->polling_count == 1) | |
2707 | return false; | |
2708 | else | |
2709 | return true; | |
2710 | } | |
2711 | ||
2712 | static void sec_bat_update_polling_count( | |
2713 | struct sec_battery_info *battery) | |
2714 | { | |
2715 | /* do NOT change polling count in sleep | |
2716 | * even though it is short polling | |
2717 | * to keep polling count along sleep/wakeup | |
2718 | */ | |
2719 | if (battery->polling_short && battery->polling_in_sleep) | |
2720 | return; | |
2721 | ||
2722 | if (battery->polling_short && | |
2723 | ((battery->polling_time / | |
2724 | battery->pdata->polling_time[ | |
2725 | SEC_BATTERY_POLLING_TIME_BASIC]) | |
2726 | > battery->polling_count)) | |
2727 | battery->polling_count++; | |
2728 | else | |
2729 | battery->polling_count = 1; /* initial value = 1 */ | |
2730 | } | |
2731 | ||
2732 | static void sec_bat_set_polling( | |
2733 | struct sec_battery_info *battery) | |
2734 | { | |
2735 | unsigned int polling_time_temp; | |
2736 | ||
2737 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
2738 | ||
2739 | polling_time_temp = sec_bat_get_polling_time(battery); | |
2740 | ||
2741 | dev_dbg(battery->dev, | |
2742 | "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n", | |
2743 | __func__, sec_bat_status_str[battery->status], | |
2744 | battery->polling_in_sleep ? "Yes" : "No", | |
2745 | (battery->charging_mode == | |
2746 | SEC_BATTERY_CHARGING_NONE) ? "No" : "Yes", | |
2747 | battery->polling_short ? "Yes" : "No"); | |
2748 | dev_dbg(battery->dev, | |
2749 | "%s: Polling time %d/%d sec.\n", __func__, | |
2750 | battery->polling_short ? | |
2751 | (polling_time_temp * battery->polling_count) : | |
2752 | polling_time_temp, battery->polling_time); | |
2753 | ||
2754 | /* To sync with log above, | |
2755 | * change polling count after log is displayed | |
2756 | * Do NOT update polling count in initial monitor | |
2757 | */ | |
2758 | if (!battery->pdata->monitor_initial_count) | |
2759 | sec_bat_update_polling_count(battery); | |
2760 | else | |
2761 | dev_dbg(battery->dev, | |
2762 | "%s: Initial monitor %d times left.\n", __func__, | |
2763 | battery->pdata->monitor_initial_count); | |
2764 | ||
2765 | switch (battery->pdata->polling_type) { | |
2766 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
2767 | if (battery->pdata->monitor_initial_count) { | |
2768 | battery->pdata->monitor_initial_count--; | |
2769 | schedule_delayed_work(&battery->polling_work, HZ); | |
2770 | } else | |
2771 | schedule_delayed_work(&battery->polling_work, | |
2772 | polling_time_temp * HZ); | |
2773 | break; | |
2774 | case SEC_BATTERY_MONITOR_ALARM: | |
2775 | #if defined(ANDROID_ALARM_ACTIVATED) | |
2776 | battery->last_poll_time = alarm_get_elapsed_realtime(); | |
2777 | #else | |
2778 | battery->last_poll_time = ktime_get_boottime(); | |
2779 | #endif | |
2780 | ||
2781 | if (battery->pdata->monitor_initial_count) { | |
2782 | battery->pdata->monitor_initial_count--; | |
2783 | sec_bat_program_alarm(battery, 1); | |
2784 | } else | |
2785 | sec_bat_program_alarm(battery, polling_time_temp); | |
2786 | break; | |
2787 | case SEC_BATTERY_MONITOR_TIMER: | |
2788 | break; | |
2789 | default: | |
2790 | break; | |
2791 | } | |
2792 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
2793 | } | |
2794 | #if defined(CONFIG_BATTERY_SWELLING) | |
2795 | static void sec_bat_swelling_fullcharged_check(struct sec_battery_info *battery) | |
2796 | { | |
2797 | union power_supply_propval value = {0, }; | |
2798 | ||
2799 | switch (battery->pdata->full_check_type_2nd) { | |
2800 | case SEC_BATTERY_FULLCHARGED_FG_CURRENT: | |
2801 | if (battery->pdata->swelling_full_check_current_2nd > 0) { | |
2802 | if ((battery->current_now > 0 && battery->current_now < | |
2803 | battery->pdata->charging_current[ | |
2804 | battery->cable_type].full_check_current_1st) && | |
2805 | (battery->current_avg > 0 && battery->current_avg < | |
2806 | battery->pdata->swelling_full_check_current_2nd) && | |
2807 | ((battery->pdata->swelling_drop_float_voltage - 100) < battery->voltage_now)) { | |
2808 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
2809 | } | |
2810 | } else { | |
2811 | if ((battery->current_now > 0 && battery->current_now < | |
2812 | battery->pdata->charging_current[ | |
2813 | battery->cable_type].full_check_current_1st) && | |
2814 | (battery->current_avg > 0 && battery->current_avg < | |
2815 | battery->pdata->charging_current[ | |
2816 | battery->cable_type].full_check_current_2nd) && | |
2817 | ((battery->pdata->swelling_drop_float_voltage - 100) < battery->voltage_now)) { | |
2818 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
2819 | } | |
2820 | } | |
2821 | break; | |
2822 | default: | |
2823 | psy_do_property(battery->pdata->charger_name, get, | |
2824 | POWER_SUPPLY_PROP_STATUS, value); | |
2825 | break; | |
2826 | } | |
2827 | ||
2828 | if (value.intval == POWER_SUPPLY_STATUS_FULL) { | |
2829 | battery->swelling_full_check_cnt++; | |
2830 | pr_info("%s: Swelling mode full-charged check (%d)\n", | |
2831 | __func__, battery->swelling_full_check_cnt); | |
2832 | } else | |
2833 | battery->swelling_full_check_cnt = 0; | |
2834 | ||
2835 | if (battery->swelling_full_check_cnt >= | |
2836 | battery->pdata->full_check_count) { | |
2837 | battery->swelling_full_check_cnt = 0; | |
2838 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
2839 | battery->is_recharging = false; | |
2840 | sec_bat_set_charge(battery, false); | |
2841 | battery->expired_time = battery->pdata->expired_time; | |
2842 | battery->prev_safety_time = 0; | |
2843 | } | |
2844 | } | |
2845 | #endif | |
2846 | ||
2847 | static void sec_bat_calculate_safety_time(struct sec_battery_info *battery) | |
2848 | { | |
2849 | unsigned long expired_time = battery->expired_time; | |
2850 | struct timespec ts = {0, }; | |
2851 | int curr = 0; | |
2852 | int input_power = battery->current_max * battery->input_voltage * 1000; | |
2853 | int charging_power = battery->charging_current * battery->pdata->swelling_normal_float_voltage; | |
2854 | ||
2855 | if (battery->lcd_status && battery->stop_timer) { | |
2856 | battery->prev_safety_time = 0; | |
2857 | return; | |
2858 | } | |
2859 | ||
2860 | get_monotonic_boottime(&ts); | |
2861 | ||
2862 | if (battery->prev_safety_time == 0) { | |
2863 | battery->prev_safety_time = ts.tv_sec; | |
2864 | } | |
2865 | ||
2866 | if (input_power > charging_power) { | |
2867 | curr = battery->charging_current; | |
2868 | } else { | |
2869 | curr = input_power / battery->pdata->swelling_normal_float_voltage; | |
2870 | curr = (curr * 9) / 10; | |
2871 | } | |
2872 | ||
2873 | if (battery->lcd_status && !battery->stop_timer) { | |
2874 | battery->stop_timer = true; | |
2875 | } else if (!battery->lcd_status && battery->stop_timer) { | |
2876 | battery->stop_timer = false; | |
2877 | } | |
2878 | ||
2879 | pr_info("%s : EXPIRED_TIME(%ld), IP(%d), CP(%d), CURR(%d), STANDARD(%d)\n", | |
2880 | __func__, expired_time, input_power, charging_power, curr, battery->pdata->standard_curr); | |
2881 | ||
b14e866e DW |
2882 | /* We don't need to calculate the safety timer if charge current is 0 */ |
2883 | if (curr == 0) { | |
2884 | /* Update the prev_safety_time if the expired_time is still max */ | |
2885 | if(battery->expired_time == battery->pdata->expired_time) { | |
2886 | battery->prev_safety_time = ts.tv_sec; | |
2887 | } | |
3c2a0909 | 2888 | return; |
b14e866e | 2889 | } |
3c2a0909 S |
2890 | |
2891 | expired_time = (expired_time * battery->pdata->standard_curr) / curr; | |
2892 | ||
2893 | pr_info("%s : CAL_EXPIRED_TIME(%ld) TIME NOW(%ld) TIME PREV(%ld)\n", __func__, expired_time, ts.tv_sec, battery->prev_safety_time); | |
2894 | ||
2895 | if (expired_time <= ((ts.tv_sec - battery->prev_safety_time) * 100)) | |
2896 | expired_time = 0; | |
2897 | else | |
2898 | expired_time -= ((ts.tv_sec - battery->prev_safety_time) * 100); | |
2899 | ||
2900 | battery->cal_safety_time = expired_time; | |
2901 | expired_time = (expired_time * curr) / battery->pdata->standard_curr; | |
2902 | ||
2903 | battery->expired_time = expired_time; | |
2904 | battery->prev_safety_time = ts.tv_sec; | |
2905 | pr_info("%s : REMAIN_TIME(%ld) CAL_REMAIN_TIME(%ld)\n", __func__, battery->expired_time, battery->cal_safety_time); | |
2906 | } | |
2907 | ||
2908 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
2909 | static void sec_bat_calc_time_to_full(struct sec_battery_info * battery) | |
2910 | { | |
2911 | if (battery->status == POWER_SUPPLY_STATUS_CHARGING) { | |
2912 | union power_supply_propval value; | |
2913 | int input = battery->pdata->charging_current[battery->cable_type].input_current_limit; | |
2914 | int charge = battery->pdata->charging_current[battery->cable_type].fast_charging_current; | |
2915 | if ((battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS) || | |
2916 | (battery->cable_type == POWER_SUPPLY_TYPE_HV_ERR) || | |
2917 | (battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT)) { | |
2918 | value.intval = charge; | |
2919 | } else if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) { | |
2920 | value.intval = battery->current_max + 100; | |
2921 | } else if (input == battery->current_max) { | |
2922 | if (input == 1800) // TA cannot charge 2100 | |
2923 | value.intval = 1950; | |
2924 | else | |
2925 | value.intval = charge - 50; | |
2926 | } else { | |
2927 | value.intval = battery->current_max + 100; | |
2928 | } | |
2929 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
2930 | POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, value); | |
2931 | dev_info(battery->dev, "%s: T: %5d sec, passed time: %5ld\n", | |
2932 | __func__, value.intval, battery->charging_passed_time); | |
2933 | battery->timetofull = value.intval; | |
2934 | } else { | |
2935 | battery->timetofull = -1; | |
2936 | } | |
2937 | } | |
2938 | ||
2939 | static void sec_bat_time_to_full_work(struct work_struct *work) | |
2940 | { | |
2941 | struct sec_battery_info *battery = container_of(work, | |
2942 | struct sec_battery_info, timetofull_work.work); | |
2943 | union power_supply_propval value; | |
2944 | psy_do_property(battery->pdata->charger_name, get, | |
2945 | POWER_SUPPLY_PROP_CURRENT_MAX, value); | |
2946 | battery->current_max = value.intval; | |
2947 | sec_bat_calc_time_to_full(battery); | |
2948 | battery->complete_timetofull = true; | |
2949 | dev_info(battery->dev, "%s: \n",__func__); | |
2950 | if (battery->voltage_now > 0) | |
2951 | battery->voltage_now--; | |
2952 | power_supply_changed(&battery->psy_bat); | |
2953 | } | |
2954 | #endif | |
2955 | ||
2956 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
2957 | static void sec_bat_cc_cv_mode_check(struct sec_battery_info *battery) | |
2958 | { | |
2959 | union power_supply_propval value; | |
2960 | ||
2961 | if ((battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) && | |
2962 | (battery->status == POWER_SUPPLY_STATUS_CHARGING) && | |
2963 | (battery->capacity >= battery->pdata->wireless_cc_cv) && | |
2964 | !battery->cc_cv_mode && | |
2965 | (battery->charging_passed_time > 5)) { | |
2966 | pr_info("%s changed wireless vout voltage to default value \n",__func__); | |
2967 | battery->cc_cv_mode = 1; | |
2968 | value.intval = 1; | |
2969 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
2970 | POWER_SUPPLY_PROP_CHARGE_TYPE, value); | |
2971 | } | |
2972 | } | |
2973 | #endif | |
2974 | ||
2975 | static void sec_bat_siop_work(struct work_struct *work) | |
2976 | { | |
2977 | struct sec_battery_info *battery = container_of(work, | |
2978 | struct sec_battery_info, siop_work.work); | |
2979 | union power_supply_propval value; | |
2980 | ||
2981 | value.intval = battery->siop_level; | |
2982 | pr_info("%s : set current by siop level(%d)\n",__func__, battery->siop_level); | |
2983 | psy_do_property(battery->pdata->charger_name, set, | |
2984 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, value); | |
2985 | ||
2986 | #if !defined(CONFIG_SEC_FACTORY) | |
2987 | if (battery->pdata->chg_temp_check) | |
2988 | sec_bat_chg_temperature_check(battery); | |
2989 | #endif | |
2990 | ||
2991 | wake_unlock(&battery->siop_wake_lock); | |
2992 | } | |
2993 | ||
2994 | static void sec_bat_monitor_work( | |
2995 | struct work_struct *work) | |
2996 | { | |
2997 | struct sec_battery_info *battery = | |
2998 | container_of(work, struct sec_battery_info, | |
2999 | monitor_work.work); | |
3000 | static struct timespec old_ts; | |
3001 | struct timespec c_ts; | |
3002 | ||
3003 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
3004 | #if defined(ANDROID_ALARM_ACTIVATED) | |
3005 | c_ts = ktime_to_timespec(alarm_get_elapsed_realtime()); | |
3006 | #else | |
3007 | c_ts = ktime_to_timespec(ktime_get_boottime()); | |
3008 | #endif | |
3009 | ||
3010 | /* monitor once after wakeup */ | |
3011 | if (battery->polling_in_sleep) { | |
3012 | battery->polling_in_sleep = false; | |
3013 | if ((battery->status == POWER_SUPPLY_STATUS_DISCHARGING) && | |
3014 | (battery->ps_enable != true)) { | |
3015 | if ((unsigned long)(c_ts.tv_sec - old_ts.tv_sec) < 10 * 60) { | |
3016 | union power_supply_propval value; | |
3017 | ||
3018 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3019 | POWER_SUPPLY_PROP_VOLTAGE_NOW, value); | |
3020 | battery->voltage_now = value.intval; | |
3021 | sec_bat_get_temperature_info(battery); | |
3022 | power_supply_changed(&battery->psy_bat); | |
3023 | pr_info("Skip monitor work(%ld, Vnow:%dmV, Tbat:%d)\n", | |
3024 | c_ts.tv_sec - old_ts.tv_sec, battery->voltage_now, battery->temperature); | |
3025 | ||
3026 | goto skip_monitor; | |
3027 | } | |
3028 | } | |
3029 | } | |
3030 | /* update last monitor time */ | |
3031 | old_ts = c_ts; | |
3032 | ||
3033 | sec_bat_get_battery_info(battery); | |
3034 | ||
3035 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
3036 | /* time to full check */ | |
3037 | sec_bat_calc_time_to_full(battery); | |
3038 | #endif | |
3039 | ||
3040 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
3041 | sec_bat_cc_cv_mode_check(battery); | |
3042 | #endif | |
3043 | ||
3044 | /* 0. test mode */ | |
3045 | if (battery->test_mode) { | |
3046 | dev_err(battery->dev, "%s: Test Mode\n", __func__); | |
3047 | sec_bat_do_test_function(battery); | |
3048 | if (battery->test_mode != 0) | |
3049 | goto continue_monitor; | |
3050 | } | |
3051 | ||
3052 | /* 1. battery check */ | |
3053 | if (!sec_bat_battery_cable_check(battery)) | |
3054 | goto continue_monitor; | |
3055 | ||
3056 | /* 2. voltage check */ | |
3057 | if (!sec_bat_voltage_check(battery)) | |
3058 | goto continue_monitor; | |
3059 | ||
3060 | /* monitor short routine in initial monitor */ | |
3061 | if (battery->pdata->monitor_initial_count || | |
3062 | sec_bat_is_short_polling(battery)) | |
3063 | goto continue_monitor; | |
3064 | ||
3065 | /* 3. time management */ | |
3066 | if (!sec_bat_time_management(battery)) | |
3067 | goto continue_monitor; | |
3068 | ||
3069 | /* 4. temperature check */ | |
3070 | if (!sec_bat_temperature_check(battery)) | |
3071 | goto continue_monitor; | |
3072 | ||
3073 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
3074 | sec_bat_discharging_check(battery); | |
3075 | #endif | |
3076 | ||
3077 | #if defined(CONFIG_BATTERY_SWELLING) | |
3078 | sec_bat_swelling_check(battery, battery->temperature); | |
3079 | set_swelling_current(battery); | |
3080 | ||
3081 | if (battery->swelling_mode && !battery->charging_block) | |
3082 | sec_bat_swelling_fullcharged_check(battery); | |
3083 | else | |
3084 | sec_bat_fullcharged_check(battery); | |
3085 | #else | |
3086 | /* 5. full charging check */ | |
3087 | sec_bat_fullcharged_check(battery); | |
3088 | #endif /* CONFIG_BATTERY_SWELLING */ | |
3089 | ||
3090 | /* 6. additional check */ | |
3091 | if (battery->pdata->monitor_additional_check) | |
3092 | battery->pdata->monitor_additional_check(); | |
3093 | ||
3094 | #if !defined(CONFIG_SEC_FACTORY) | |
3095 | /* 7. charger temperature check */ | |
3096 | if (battery->pdata->chg_temp_check) | |
3097 | sec_bat_chg_temperature_check(battery); | |
3098 | #endif | |
3099 | ||
3100 | continue_monitor: | |
3101 | #if 1 | |
3102 | /* calculate safety time */ | |
3103 | if (!battery->charging_block) | |
3104 | sec_bat_calculate_safety_time(battery); | |
3105 | #endif | |
3106 | ||
3107 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
3108 | dev_info(battery->dev, | |
3109 | "%s: Status(%s), mode(%s), Health(%s), Cable(%d,%d), level(%d%%), HV(%s), Cycle(%d)\n", | |
3110 | __func__, | |
3111 | sec_bat_status_str[battery->status], | |
3112 | sec_bat_charging_mode_str[battery->charging_mode], | |
3113 | sec_bat_health_str[battery->health], | |
3114 | battery->cable_type, battery->muic_cable_type, battery->siop_level, | |
3115 | battery->hv_chg_name, battery->batt_cycle); | |
3116 | #else | |
3117 | dev_info(battery->dev, | |
3118 | "%s: Status(%s), mode(%s), Health(%s), Cable(%d,%d), level(%d%%), Cycle(%d)\n", | |
3119 | __func__, | |
3120 | sec_bat_status_str[battery->status], | |
3121 | sec_bat_charging_mode_str[battery->charging_mode], | |
3122 | sec_bat_health_str[battery->health], | |
3123 | battery->cable_type, battery->muic_cable_type, battery->siop_level, battery->batt_cycle); | |
3124 | #endif | |
3125 | #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) | |
3126 | dev_info(battery->dev, | |
3127 | "%s: battery->stability_test(%d), battery->eng_not_full_status(%d)\n", | |
3128 | __func__, battery->stability_test, battery->eng_not_full_status); | |
3129 | #endif | |
3130 | if (battery->store_mode && !lpcharge && (battery->cable_type != POWER_SUPPLY_TYPE_BATTERY)) { | |
3131 | ||
3132 | dev_info(battery->dev, | |
3133 | "%s: @battery->capacity = (%d), battery->status= (%d), battery->store_mode=(%d)\n", | |
3134 | __func__, battery->capacity, battery->status, battery->store_mode); | |
3135 | ||
3136 | if ((battery->capacity >= STORE_MODE_CHARGING_MAX) && (battery->status == POWER_SUPPLY_STATUS_CHARGING)) { | |
3137 | sec_bat_set_charging_status(battery, | |
3138 | POWER_SUPPLY_STATUS_DISCHARGING); | |
3139 | sec_bat_set_charge(battery, false); | |
3140 | } | |
3141 | if ((battery->capacity <= STORE_MODE_CHARGING_MIN) && (battery->status == POWER_SUPPLY_STATUS_DISCHARGING)) { | |
3142 | sec_bat_set_charging_status(battery, | |
3143 | POWER_SUPPLY_STATUS_CHARGING); | |
3144 | if (battery->siop_level != 100) | |
3145 | battery->stop_timer = true; | |
3146 | sec_bat_set_charge(battery, true); | |
3147 | } | |
3148 | } | |
3149 | power_supply_changed(&battery->psy_bat); | |
3150 | ||
3151 | skip_monitor: | |
3152 | sec_bat_set_polling(battery); | |
3153 | ||
3154 | if (battery->capacity <= 0 || battery->health_change) | |
3155 | wake_lock_timeout(&battery->monitor_wake_lock, HZ * 5); | |
3156 | else | |
3157 | wake_unlock(&battery->monitor_wake_lock); | |
3158 | ||
3159 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
3160 | ||
3161 | return; | |
3162 | } | |
3163 | ||
3164 | #if defined(ANDROID_ALARM_ACTIVATED) | |
3165 | static void sec_bat_alarm(struct alarm *alarm) | |
3166 | #else | |
3167 | static enum alarmtimer_restart sec_bat_alarm( | |
3168 | struct alarm *alarm, ktime_t now) | |
3169 | ||
3170 | #endif | |
3171 | { | |
3172 | struct sec_battery_info *battery = container_of(alarm, | |
3173 | struct sec_battery_info, polling_alarm); | |
3174 | ||
3175 | dev_dbg(battery->dev, | |
3176 | "%s\n", __func__); | |
3177 | ||
3178 | /* In wake up, monitor work will be queued in complete function | |
3179 | * To avoid duplicated queuing of monitor work, | |
3180 | * do NOT queue monitor work in wake up by polling alarm | |
3181 | */ | |
3182 | if (!battery->polling_in_sleep) { | |
3183 | wake_lock(&battery->monitor_wake_lock); | |
3184 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
3185 | dev_dbg(battery->dev, "%s: Activated\n", __func__); | |
3186 | } | |
3187 | #if !defined(ANDROID_ALARM_ACTIVATED) | |
3188 | return ALARMTIMER_NORESTART; | |
3189 | #endif | |
3190 | } | |
3191 | ||
3192 | ||
3193 | static void sec_bat_cable_work(struct work_struct *work) | |
3194 | { | |
3195 | struct sec_battery_info *battery = container_of(work, | |
3196 | struct sec_battery_info, cable_work.work); | |
3197 | union power_supply_propval val; | |
3198 | int wl_cur, wr_cur, current_cable_type; | |
3199 | bool keep_charging_state = false; | |
3200 | ||
3201 | dev_info(battery->dev, "%s: Start\n", __func__); | |
3202 | ||
3203 | wl_cur = battery->pdata->charging_current[ | |
3204 | POWER_SUPPLY_TYPE_WIRELESS].input_current_limit; | |
3205 | wr_cur = battery->pdata->charging_current[ | |
3206 | battery->wire_status].input_current_limit; | |
3207 | if (battery->wc_status && battery->wc_enable && | |
3208 | (wl_cur > wr_cur)) | |
3209 | current_cable_type = POWER_SUPPLY_TYPE_WIRELESS; | |
3210 | else | |
3211 | current_cable_type = battery->wire_status; | |
3212 | ||
3213 | if ((current_cable_type == battery->cable_type) && !battery->slate_mode) { | |
3214 | dev_dbg(battery->dev, | |
3215 | "%s: Cable is NOT Changed(%d)\n", | |
3216 | __func__, battery->cable_type); | |
3217 | /* Do NOT activate cable work for NOT changed */ | |
3218 | goto end_of_cable_work; | |
3219 | } | |
3220 | ||
3221 | #if defined(CONFIG_BATTERY_SWELLING) | |
3222 | if (current_cable_type == POWER_SUPPLY_TYPE_BATTERY || | |
3223 | battery->cable_type == POWER_SUPPLY_TYPE_BATTERY) { | |
3224 | battery->swelling_mode = false; | |
3225 | /* restore 4.4V float voltage */ | |
3226 | val.intval = battery->pdata->swelling_normal_float_voltage; | |
3227 | psy_do_property(battery->pdata->charger_name, set, | |
3228 | POWER_SUPPLY_PROP_VOLTAGE_MAX, val); | |
3229 | pr_info("%s: float voltage = %d\n", __func__, val.intval); | |
3230 | } else { | |
3231 | pr_info("%s: skip float_voltage setting, swelling_mode(%d)\n", | |
3232 | __func__, battery->swelling_mode); | |
3233 | } | |
3234 | #endif | |
3235 | ||
3236 | if (battery->charging_block && | |
3237 | ((battery->cable_type != POWER_SUPPLY_TYPE_BATTERY && current_cable_type == POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT) || | |
3238 | (current_cable_type != POWER_SUPPLY_TYPE_BATTERY && battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT) || | |
3239 | (current_cable_type != POWER_SUPPLY_TYPE_BATTERY && battery->cable_type == POWER_SUPPLY_TYPE_HV_PREPARE_MAINS) || | |
3240 | (current_cable_type == POWER_SUPPLY_TYPE_HV_PREPARE_MAINS) || battery->swelling_mode)) { | |
3241 | keep_charging_state = true; | |
3242 | pr_info("%s: keep charging state (prev cable type:%d, now cable type:%d, swelling_mode:%d)\n", | |
3243 | __func__, battery->cable_type, current_cable_type, battery->swelling_mode); | |
3244 | } | |
3245 | ||
3246 | battery->cable_type = current_cable_type; | |
3247 | if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) | |
3248 | power_supply_changed(&battery->psy_bat); | |
3249 | ||
3250 | if (battery->pdata->check_cable_result_callback) | |
3251 | battery->pdata->check_cable_result_callback( | |
3252 | battery->cable_type); | |
3253 | /* platform can NOT get information of cable connection | |
3254 | * because wakeup time is too short to check uevent | |
3255 | * To make sure that target is wakeup | |
3256 | * if cable is connected and disconnected, | |
3257 | * activated wake lock in a few seconds | |
3258 | */ | |
3259 | wake_lock_timeout(&battery->vbus_wake_lock, HZ * 10); | |
3260 | ||
3261 | if (battery->cable_type == POWER_SUPPLY_TYPE_BATTERY || | |
3262 | ((battery->pdata->cable_check_type & | |
3263 | SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE) && | |
3264 | battery->cable_type == POWER_SUPPLY_TYPE_UNKNOWN)) { | |
3265 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
3266 | battery->is_recharging = false; | |
3267 | sec_bat_set_charging_status(battery, | |
3268 | POWER_SUPPLY_STATUS_DISCHARGING); | |
3269 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
3270 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
3271 | battery->complete_timetofull = false; | |
3272 | cancel_delayed_work(&battery->timetofull_work); | |
3273 | #endif | |
3274 | if (sec_bat_set_charge(battery, false)) | |
3275 | goto end_of_cable_work; | |
3276 | } else if (battery->slate_mode == true) { | |
3277 | sec_bat_set_charging_status(battery, | |
3278 | POWER_SUPPLY_STATUS_DISCHARGING); | |
3279 | battery->cable_type = POWER_SUPPLY_TYPE_BATTERY; | |
3280 | ||
3281 | val.intval = 0; | |
3282 | psy_do_property(battery->pdata->charger_name, set, | |
3283 | POWER_SUPPLY_PROP_CURRENT_NOW, val); | |
3284 | ||
3285 | dev_info(battery->dev, | |
3286 | "%s:slate mode on\n",__func__); | |
3287 | ||
3288 | if (sec_bat_set_charge(battery, false)) | |
3289 | goto end_of_cable_work; | |
3290 | } else { | |
3291 | #if defined(CONFIG_EN_OOPS) | |
3292 | val.intval = battery->cable_type; | |
3293 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
3294 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, val); | |
3295 | #endif | |
3296 | /* Do NOT display the charging icon when OTG or HMT_CONNECTED is enabled */ | |
3297 | if (battery->cable_type == POWER_SUPPLY_TYPE_OTG) { | |
3298 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
3299 | sec_bat_set_charging_status(battery, | |
3300 | POWER_SUPPLY_STATUS_DISCHARGING); | |
3301 | } else { | |
3302 | if (!keep_charging_state) { | |
3303 | if (battery->pdata->full_check_type != | |
3304 | SEC_BATTERY_FULLCHARGED_NONE) | |
3305 | battery->charging_mode = | |
3306 | SEC_BATTERY_CHARGING_1ST; | |
3307 | else | |
3308 | battery->charging_mode = | |
3309 | SEC_BATTERY_CHARGING_2ND; | |
3310 | } | |
3311 | ||
3312 | if (battery->status == POWER_SUPPLY_STATUS_FULL) | |
3313 | sec_bat_set_charging_status(battery, | |
3314 | POWER_SUPPLY_STATUS_FULL); | |
3315 | else if (!keep_charging_state) | |
3316 | sec_bat_set_charging_status(battery, | |
3317 | POWER_SUPPLY_STATUS_CHARGING); | |
3318 | ||
3319 | if (!keep_charging_state) { | |
3320 | if (sec_bat_set_charge(battery, true)) | |
3321 | goto end_of_cable_work; | |
3322 | } | |
3323 | ||
3324 | if (battery->siop_level != 100) | |
3325 | battery->stop_timer = true; | |
3326 | } | |
3327 | ||
3328 | if (battery->status != POWER_SUPPLY_STATUS_DISCHARGING) { | |
3329 | battery->input_voltage = | |
3330 | battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS ? 9 : 5; | |
3331 | } | |
3332 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
3333 | if ((battery->cable_type != POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT) && | |
3334 | (current_cable_type != POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT)) | |
3335 | battery->complete_timetofull = false; | |
3336 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->timetofull_work, | |
3337 | msecs_to_jiffies(4000)); | |
3338 | #endif | |
3339 | #if defined(ANDROID_ALARM_ACTIVATED) | |
3340 | /* No need for wakelock in Alarm */ | |
3341 | if (battery->pdata->polling_type != SEC_BATTERY_MONITOR_ALARM) | |
3342 | wake_lock(&battery->vbus_wake_lock); | |
3343 | #endif | |
3344 | } | |
3345 | ||
3346 | /* polling time should be reset when cable is changed | |
3347 | * polling_in_sleep should be reset also | |
3348 | * before polling time is re-calculated | |
3349 | * to prevent from counting 1 for events | |
3350 | * right after cable is connected | |
3351 | */ | |
3352 | battery->polling_in_sleep = false; | |
3353 | sec_bat_get_polling_time(battery); | |
3354 | ||
3355 | dev_info(battery->dev, | |
3356 | "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n", | |
3357 | __func__, sec_bat_status_str[battery->status], | |
3358 | battery->polling_in_sleep ? "Yes" : "No", | |
3359 | (battery->charging_mode == | |
3360 | SEC_BATTERY_CHARGING_NONE) ? "No" : "Yes", | |
3361 | battery->polling_short ? "Yes" : "No"); | |
3362 | dev_info(battery->dev, | |
3363 | "%s: Polling time is reset to %d sec.\n", __func__, | |
3364 | battery->polling_time); | |
3365 | ||
3366 | battery->polling_count = 1; /* initial value = 1 */ | |
3367 | ||
3368 | wake_lock(&battery->monitor_wake_lock); | |
3369 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
3370 | end_of_cable_work: | |
3371 | wake_unlock(&battery->cable_wake_lock); | |
3372 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
3373 | } | |
3374 | ||
3375 | ssize_t sec_bat_show_attrs(struct device *dev, | |
3376 | struct device_attribute *attr, char *buf) | |
3377 | { | |
3378 | struct power_supply *psy = dev_get_drvdata(dev); | |
3379 | struct sec_battery_info *battery = | |
3380 | container_of(psy, struct sec_battery_info, psy_bat); | |
3381 | const ptrdiff_t offset = attr - sec_battery_attrs; | |
3382 | union power_supply_propval value; | |
3383 | int i = 0; | |
3384 | ||
3385 | switch (offset) { | |
3386 | case BATT_RESET_SOC: | |
3387 | break; | |
3388 | case BATT_READ_RAW_SOC: | |
3389 | { | |
3390 | union power_supply_propval value; | |
3391 | ||
3392 | value.intval = | |
3393 | SEC_FUELGAUGE_CAPACITY_TYPE_RAW; | |
3394 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3395 | POWER_SUPPLY_PROP_CAPACITY, value); | |
3396 | ||
3397 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3398 | value.intval); | |
3399 | } | |
3400 | break; | |
3401 | case BATT_READ_ADJ_SOC: | |
3402 | break; | |
3403 | case BATT_TYPE: | |
3404 | i += scnprintf(buf + i, PAGE_SIZE - i, "%s\n", | |
3405 | battery->pdata->vendor); | |
3406 | break; | |
3407 | case BATT_VFOCV: | |
3408 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3409 | battery->voltage_ocv); | |
3410 | break; | |
3411 | case BATT_VOL_ADC: | |
3412 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3413 | battery->inbat_adc); | |
3414 | break; | |
3415 | case BATT_VOL_ADC_CAL: | |
3416 | break; | |
3417 | case BATT_VOL_AVER: | |
3418 | break; | |
3419 | case BATT_VOL_ADC_AVER: | |
3420 | break; | |
3421 | ||
3422 | case BATT_CURRENT_UA_NOW: | |
3423 | { | |
3424 | union power_supply_propval value; | |
3425 | ||
3426 | value.intval = SEC_BATTERY_CURRENT_UA; | |
3427 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3428 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
3429 | ||
3430 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3431 | value.intval); | |
3432 | } | |
3433 | break; | |
3434 | case BATT_CURRENT_UA_AVG: | |
3435 | { | |
3436 | union power_supply_propval value; | |
3437 | ||
3438 | value.intval = SEC_BATTERY_CURRENT_UA; | |
3439 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3440 | POWER_SUPPLY_PROP_CURRENT_AVG, value); | |
3441 | ||
3442 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3443 | value.intval); | |
3444 | } | |
3445 | break; | |
3446 | ||
3447 | case BATT_TEMP: | |
3448 | switch (battery->pdata->thermal_source) { | |
3449 | case SEC_BATTERY_THERMAL_SOURCE_FG: | |
3450 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3451 | POWER_SUPPLY_PROP_TEMP, value); | |
3452 | break; | |
3453 | case SEC_BATTERY_THERMAL_SOURCE_CALLBACK: | |
3454 | if (battery->pdata->get_temperature_callback) { | |
3455 | battery->pdata->get_temperature_callback( | |
3456 | POWER_SUPPLY_PROP_TEMP, &value); | |
3457 | } | |
3458 | break; | |
3459 | case SEC_BATTERY_THERMAL_SOURCE_ADC: | |
3460 | sec_bat_get_temperature_by_adc(battery, | |
3461 | SEC_BAT_ADC_CHANNEL_TEMP, &value); | |
3462 | break; | |
3463 | default: | |
3464 | break; | |
3465 | } | |
3466 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3467 | value.intval); | |
3468 | break; | |
3469 | case BATT_TEMP_ADC: | |
3470 | /* | |
3471 | If F/G is used for reading the temperature and | |
3472 | compensation table is used, | |
3473 | the raw value that isn't compensated can be read by | |
3474 | POWER_SUPPLY_PROP_TEMP_AMBIENT | |
3475 | */ | |
3476 | switch (battery->pdata->thermal_source) { | |
3477 | case SEC_BATTERY_THERMAL_SOURCE_FG: | |
3478 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3479 | POWER_SUPPLY_PROP_TEMP_AMBIENT, value); | |
3480 | battery->temp_adc = value.intval; | |
3481 | break; | |
3482 | default: | |
3483 | break; | |
3484 | } | |
3485 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3486 | battery->temp_adc); | |
3487 | break; | |
3488 | case BATT_TEMP_AVER: | |
3489 | break; | |
3490 | case BATT_TEMP_ADC_AVER: | |
3491 | break; | |
3492 | case CHG_TEMP: | |
3493 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
3494 | sec_bat_get_temperature_by_adc(battery, | |
3495 | SEC_BAT_ADC_CHANNEL_CHG_TEMP, &value); | |
3496 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3497 | value.intval); | |
3498 | #else | |
3499 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3500 | 0); | |
3501 | #endif | |
3502 | break; | |
3503 | case CHG_TEMP_ADC: | |
3504 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
3505 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3506 | battery->chg_temp_adc); | |
3507 | #else | |
3508 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3509 | 0); | |
3510 | #endif | |
3511 | break; | |
3512 | case BATT_VF_ADC: | |
3513 | break; | |
3514 | case BATT_SLATE_MODE: | |
3515 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3516 | battery->slate_mode); | |
3517 | break; | |
3518 | ||
3519 | case BATT_LP_CHARGING: | |
3520 | if (lpcharge) { | |
3521 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3522 | lpcharge ? 1 : 0); | |
3523 | } | |
3524 | break; | |
3525 | case SIOP_ACTIVATED: | |
3526 | break; | |
3527 | case SIOP_LEVEL: | |
3528 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3529 | battery->siop_level); | |
3530 | break; | |
3531 | case BATT_CHARGING_SOURCE: | |
3532 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3533 | battery->cable_type); | |
3534 | break; | |
3535 | case FG_REG_DUMP: | |
3536 | break; | |
3537 | case FG_RESET_CAP: | |
3538 | break; | |
3539 | case FG_CAPACITY: | |
3540 | { | |
3541 | union power_supply_propval value; | |
3542 | ||
3543 | value.intval = | |
3544 | SEC_BATTERY_CAPACITY_DESIGNED; | |
3545 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3546 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
3547 | ||
3548 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x ", | |
3549 | value.intval); | |
3550 | ||
3551 | value.intval = | |
3552 | SEC_BATTERY_CAPACITY_ABSOLUTE; | |
3553 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3554 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
3555 | ||
3556 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x ", | |
3557 | value.intval); | |
3558 | ||
3559 | value.intval = | |
3560 | SEC_BATTERY_CAPACITY_TEMPERARY; | |
3561 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3562 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
3563 | ||
3564 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x ", | |
3565 | value.intval); | |
3566 | ||
3567 | value.intval = | |
3568 | SEC_BATTERY_CAPACITY_CURRENT; | |
3569 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3570 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
3571 | ||
3572 | i += scnprintf(buf + i, PAGE_SIZE - i, "0x%04x\n", | |
3573 | value.intval); | |
3574 | } | |
3575 | break; | |
3576 | case FG_ASOC: | |
3577 | #if defined(CONFIG_INBATTERY) | |
3578 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3579 | POWER_SUPPLY_PROP_ENERGY_FULL, value); | |
3580 | #else | |
3581 | value.intval = -1; | |
3582 | #endif | |
3583 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3584 | value.intval); | |
3585 | break; | |
3586 | case AUTH: | |
3587 | break; | |
3588 | case CHG_CURRENT_ADC: | |
3589 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3590 | battery->current_adc); | |
3591 | break; | |
3592 | case WC_ADC: | |
3593 | break; | |
3594 | case WC_STATUS: | |
3595 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3596 | (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS)); | |
3597 | break; | |
3598 | case WC_ENABLE: | |
3599 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3600 | battery->wc_enable); | |
3601 | break; | |
3602 | case HV_CHARGER_STATUS: | |
3603 | { | |
3604 | int check_val = 0; | |
3605 | if (battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS || | |
3606 | battery->cable_type == POWER_SUPPLY_TYPE_HV_ERR || | |
3607 | battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT) | |
3608 | check_val = 1; | |
3609 | #if defined(CONFIG_CHARGER_SM5705) | |
3610 | else if (battery->cable_type == POWER_SUPPLY_TYPE_HV_PREPARE_MAINS) | |
3611 | check_val = 1; | |
3612 | #endif | |
3613 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", check_val); | |
3614 | } | |
3615 | break; | |
3616 | case HV_CHARGER_SET: | |
3617 | break; | |
3618 | case FACTORY_MODE: | |
3619 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3620 | battery->factory_mode); | |
3621 | break; | |
3622 | case STORE_MODE: | |
3623 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3624 | battery->store_mode); | |
3625 | break; | |
3626 | case UPDATE: | |
3627 | break; | |
3628 | case TEST_MODE: | |
3629 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3630 | battery->test_mode); | |
3631 | break; | |
3632 | ||
3633 | case BATT_EVENT_CALL: | |
3634 | case BATT_EVENT_2G_CALL: | |
3635 | case BATT_EVENT_TALK_GSM: | |
3636 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3637 | (battery->event & EVENT_2G_CALL) ? 1 : 0); | |
3638 | break; | |
3639 | case BATT_EVENT_3G_CALL: | |
3640 | case BATT_EVENT_TALK_WCDMA: | |
3641 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3642 | (battery->event & EVENT_3G_CALL) ? 1 : 0); | |
3643 | break; | |
3644 | case BATT_EVENT_MUSIC: | |
3645 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3646 | (battery->event & EVENT_MUSIC) ? 1 : 0); | |
3647 | break; | |
3648 | case BATT_EVENT_VIDEO: | |
3649 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3650 | (battery->event & EVENT_VIDEO) ? 1 : 0); | |
3651 | break; | |
3652 | case BATT_EVENT_BROWSER: | |
3653 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3654 | (battery->event & EVENT_BROWSER) ? 1 : 0); | |
3655 | break; | |
3656 | case BATT_EVENT_HOTSPOT: | |
3657 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3658 | (battery->event & EVENT_HOTSPOT) ? 1 : 0); | |
3659 | break; | |
3660 | case BATT_EVENT_CAMERA: | |
3661 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3662 | (battery->event & EVENT_CAMERA) ? 1 : 0); | |
3663 | break; | |
3664 | case BATT_EVENT_CAMCORDER: | |
3665 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3666 | (battery->event & EVENT_CAMCORDER) ? 1 : 0); | |
3667 | break; | |
3668 | case BATT_EVENT_DATA_CALL: | |
3669 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3670 | (battery->event & EVENT_DATA_CALL) ? 1 : 0); | |
3671 | break; | |
3672 | case BATT_EVENT_WIFI: | |
3673 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3674 | (battery->event & EVENT_WIFI) ? 1 : 0); | |
3675 | break; | |
3676 | case BATT_EVENT_WIBRO: | |
3677 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3678 | (battery->event & EVENT_WIBRO) ? 1 : 0); | |
3679 | break; | |
3680 | case BATT_EVENT_LTE: | |
3681 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3682 | (battery->event & EVENT_LTE) ? 1 : 0); | |
3683 | break; | |
3684 | case BATT_EVENT_LCD: | |
3685 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3686 | (battery->event & EVENT_LCD) ? 1 : 0); | |
3687 | break; | |
3688 | case BATT_EVENT_GPS: | |
3689 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3690 | (battery->event & EVENT_GPS) ? 1 : 0); | |
3691 | break; | |
3692 | case BATT_EVENT: | |
3693 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3694 | battery->event); | |
3695 | break; | |
3696 | case BATT_TEMP_TABLE: | |
3697 | i += scnprintf(buf + i, PAGE_SIZE - i, | |
3698 | "%d %d %d %d %d %d %d %d %d %d %d %d\n", | |
3699 | battery->pdata->temp_high_threshold_event, | |
3700 | battery->pdata->temp_high_recovery_event, | |
3701 | battery->pdata->temp_low_threshold_event, | |
3702 | battery->pdata->temp_low_recovery_event, | |
3703 | battery->pdata->temp_high_threshold_normal, | |
3704 | battery->pdata->temp_high_recovery_normal, | |
3705 | battery->pdata->temp_low_threshold_normal, | |
3706 | battery->pdata->temp_low_recovery_normal, | |
3707 | battery->pdata->temp_high_threshold_lpm, | |
3708 | battery->pdata->temp_high_recovery_lpm, | |
3709 | battery->pdata->temp_low_threshold_lpm, | |
3710 | battery->pdata->temp_low_recovery_lpm); | |
3711 | break; | |
3712 | case BATT_HIGH_CURRENT_USB: | |
3713 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3714 | battery->is_hc_usb); | |
3715 | break; | |
3716 | #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) | |
3717 | case BATT_TEST_CHARGE_CURRENT: | |
3718 | { | |
3719 | union power_supply_propval value; | |
3720 | ||
3721 | psy_do_property(battery->pdata->charger_name, get, | |
3722 | POWER_SUPPLY_PROP_CURRENT_NOW, value); | |
3723 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3724 | value.intval); | |
3725 | } | |
3726 | break; | |
3727 | #endif | |
3728 | case BATT_STABILITY_TEST: | |
3729 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3730 | battery->stability_test); | |
3731 | break; | |
3732 | #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX) | |
3733 | case BATT_CAPACITY_MAX: | |
3734 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3735 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, value); | |
3736 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
3737 | break; | |
3738 | #endif | |
3739 | case BATT_INBAT_VOLTAGE: | |
3740 | { | |
3741 | int ret; | |
3742 | ret = sec_bat_get_inbat_vol_by_adc(battery); | |
3743 | dev_info(battery->dev, "in-battery voltage(%d)\n", ret); | |
3744 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3745 | ret); | |
3746 | } | |
3747 | break; | |
3748 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
3749 | case BATT_DISCHARGING_CHECK: | |
3750 | sec_bat_self_discharging_check(battery); | |
3751 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3752 | battery->self_discharging); | |
3753 | break; | |
3754 | case BATT_DISCHARGING_CHECK_ADC: | |
3755 | sec_bat_self_discharging_check(battery); | |
3756 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3757 | battery->self_discharging_adc); | |
3758 | break; | |
3759 | case BATT_DISCHARGING_NTC: | |
3760 | sec_bat_self_discharging_ntc_check(battery); | |
3761 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3762 | battery->discharging_ntc); | |
3763 | break; | |
3764 | case BATT_DISCHARGING_NTC_ADC: | |
3765 | sec_bat_self_discharging_ntc_check(battery); | |
3766 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3767 | battery->discharging_ntc_adc); | |
3768 | break; | |
3769 | case BATT_SELF_DISCHARGING_CONTROL: | |
3770 | break; | |
3771 | #endif | |
3772 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
3773 | case BATT_INBAT_WIRELESS_CS100: | |
3774 | psy_do_property(battery->pdata->wireless_charger_name, get, | |
3775 | POWER_SUPPLY_PROP_STATUS, value); | |
3776 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
3777 | #endif | |
3778 | break; | |
3779 | case HMT_TA_CONNECTED: | |
3780 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3781 | (battery->cable_type == POWER_SUPPLY_TYPE_HMT_CONNECTED) ? 1 : 0); | |
3782 | break; | |
3783 | case HMT_TA_CHARGE: | |
3784 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", | |
3785 | (battery->cable_type == POWER_SUPPLY_TYPE_HMT_CHARGE) ? 1 : 0); | |
3786 | break; | |
3787 | case FG_CYCLE: | |
3788 | value.intval = SEC_BATTERY_CAPACITY_CYCLE; | |
3789 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3790 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
3791 | value.intval = value.intval / 100; | |
3792 | dev_info(battery->dev, "fg cycle(%d)\n", value.intval); | |
3793 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
3794 | break; | |
3795 | case FG_FULL_VOLTAGE: | |
3796 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", battery->pdata->chg_float_voltage); | |
3797 | break; | |
3798 | case FG_FULLCAPNOM: | |
3799 | value.intval = | |
3800 | SEC_BATTERY_CAPACITY_AGEDCELL; | |
3801 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
3802 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
3803 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", value.intval); | |
3804 | break; | |
3805 | case BATTERY_CYCLE: | |
3806 | i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", battery->batt_cycle); | |
3807 | break; | |
3808 | default: | |
3809 | i = -EINVAL; | |
3810 | } | |
3811 | ||
3812 | return i; | |
3813 | } | |
3814 | void update_external_temp_table(struct sec_battery_info *battery, int temp[]) | |
3815 | { | |
3816 | battery->pdata->temp_high_threshold_event = temp[0]; | |
3817 | battery->pdata->temp_high_recovery_event = temp[1]; | |
3818 | battery->pdata->temp_low_threshold_event = temp[2]; | |
3819 | battery->pdata->temp_low_recovery_event = temp[3]; | |
3820 | battery->pdata->temp_high_threshold_normal = temp[4]; | |
3821 | battery->pdata->temp_high_recovery_normal = temp[5]; | |
3822 | battery->pdata->temp_low_threshold_normal = temp[6]; | |
3823 | battery->pdata->temp_low_recovery_normal = temp[7]; | |
3824 | battery->pdata->temp_high_threshold_lpm = temp[8]; | |
3825 | battery->pdata->temp_high_recovery_lpm = temp[9]; | |
3826 | battery->pdata->temp_low_threshold_lpm = temp[10]; | |
3827 | battery->pdata->temp_low_recovery_lpm = temp[11]; | |
3828 | ||
3829 | if (battery->pdata->temp_high_threshold_event != | |
3830 | battery->pdata->temp_high_threshold_normal) | |
3831 | battery->pdata->event_check = 1; | |
3832 | } | |
3833 | ||
3834 | ssize_t sec_bat_store_attrs( | |
3835 | struct device *dev, | |
3836 | struct device_attribute *attr, | |
3837 | const char *buf, size_t count) | |
3838 | { | |
3839 | struct power_supply *psy = dev_get_drvdata(dev); | |
3840 | struct sec_battery_info *battery = | |
3841 | container_of(psy, struct sec_battery_info, psy_bat); | |
3842 | const ptrdiff_t offset = attr - sec_battery_attrs; | |
3843 | int ret = -EINVAL; | |
3844 | int x = 0; | |
3845 | int t[12]; | |
3846 | switch (offset) { | |
3847 | case BATT_RESET_SOC: | |
3848 | /* Do NOT reset fuel gauge in charging mode */ | |
3849 | if (battery->cable_type == POWER_SUPPLY_TYPE_BATTERY || | |
3850 | battery->cable_type == POWER_SUPPLY_TYPE_UARTOFF) { | |
3851 | union power_supply_propval value; | |
3852 | battery->voltage_now = 1234; | |
3853 | battery->voltage_avg = 1234; | |
3854 | power_supply_changed(&battery->psy_bat); | |
3855 | ||
3856 | value.intval = | |
3857 | SEC_FUELGAUGE_CAPACITY_TYPE_RESET; | |
3858 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
3859 | POWER_SUPPLY_PROP_CAPACITY, value); | |
3860 | dev_info(battery->dev,"do reset SOC\n"); | |
3861 | /* update battery info */ | |
3862 | sec_bat_get_battery_info(battery); | |
3863 | } | |
3864 | ret = count; | |
3865 | break; | |
3866 | case BATT_READ_RAW_SOC: | |
3867 | break; | |
3868 | case BATT_READ_ADJ_SOC: | |
3869 | break; | |
3870 | case BATT_TYPE: | |
3871 | break; | |
3872 | case BATT_VFOCV: | |
3873 | break; | |
3874 | case BATT_VOL_ADC: | |
3875 | break; | |
3876 | case BATT_VOL_ADC_CAL: | |
3877 | break; | |
3878 | case BATT_VOL_AVER: | |
3879 | break; | |
3880 | case BATT_VOL_ADC_AVER: | |
3881 | break; | |
3882 | case BATT_CURRENT_UA_NOW: | |
3883 | break; | |
3884 | case BATT_CURRENT_UA_AVG: | |
3885 | break; | |
3886 | case BATT_TEMP: | |
3887 | break; | |
3888 | case BATT_TEMP_ADC: | |
3889 | break; | |
3890 | case BATT_TEMP_AVER: | |
3891 | break; | |
3892 | case BATT_TEMP_ADC_AVER: | |
3893 | break; | |
3894 | case CHG_TEMP: | |
3895 | break; | |
3896 | case CHG_TEMP_ADC: | |
3897 | break; | |
3898 | case BATT_VF_ADC: | |
3899 | break; | |
3900 | case BATT_SLATE_MODE: | |
3901 | if (sscanf(buf, "%d\n", &x) == 1) { | |
3902 | union power_supply_propval value; | |
3903 | if (x == 1) { | |
3904 | battery->slate_mode = true; | |
3905 | } else if (x == 0) { | |
3906 | battery->slate_mode = false; | |
3907 | } else { | |
3908 | dev_info(battery->dev, | |
3909 | "%s: SLATE MODE unknown command\n", | |
3910 | __func__); | |
3911 | return -EINVAL; | |
3912 | } | |
3913 | slate_mode_state = battery->slate_mode; | |
3914 | wake_lock(&battery->cable_wake_lock); | |
3915 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
3916 | &battery->cable_work, 0); | |
3917 | if (battery->slate_mode) { | |
3918 | value.intval = 0; | |
3919 | psy_do_property(battery->pdata->charger_name, set, | |
3920 | POWER_SUPPLY_PROP_CURRENT_NOW, | |
3921 | value); | |
3922 | if (battery->pdata->always_enable) | |
3923 | psy_do_property(battery->pdata->charger_name, set, | |
3924 | POWER_SUPPLY_PROP_CHARGING_ENABLED, | |
3925 | value); | |
3926 | } | |
3927 | ret = count; | |
3928 | } | |
3929 | break; | |
3930 | ||
3931 | case BATT_LP_CHARGING: | |
3932 | break; | |
3933 | case SIOP_ACTIVATED: | |
3934 | break; | |
3935 | case SIOP_LEVEL: | |
3936 | if (sscanf(buf, "%d\n", &x) == 1) { | |
3937 | struct timespec ts; | |
3938 | ||
3939 | dev_info(battery->dev, | |
3940 | "%s: siop level: %d\n", __func__, x); | |
3941 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_NONE; | |
3942 | ||
3943 | if (x == battery->siop_level && battery->capacity > 5) { | |
3944 | dev_info(battery->dev, | |
3945 | "%s: skip same siop level: %d\n", __func__, x); | |
3946 | return count; | |
3947 | } else if (x >= 0 && x <= 100) { | |
3948 | battery->siop_level = x; | |
3949 | } else { | |
3950 | battery->siop_level = 100; | |
3951 | } | |
3952 | ||
3953 | get_monotonic_boottime(&ts); | |
3954 | if ((battery->r_siop_level != battery->siop_level) && | |
3955 | (battery->status == POWER_SUPPLY_STATUS_CHARGING || | |
3956 | battery->status == POWER_SUPPLY_STATUS_FULL) && | |
3957 | !(battery->charging_block)) { | |
3958 | if (battery->siop_level >= 100) { | |
3959 | battery->lcd_on_total_time += ts.tv_sec - battery->lcd_on_time; | |
3960 | battery->lcd_on_time = 0; | |
3961 | } else { | |
3962 | if (!battery->lcd_on_time) | |
3963 | battery->lcd_on_time = ts.tv_sec; | |
3964 | } | |
3965 | } | |
3966 | ||
3967 | battery->r_siop_level = battery->siop_level; | |
3968 | ||
3969 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
3970 | union power_supply_propval value; | |
3971 | value.intval = battery->siop_level; | |
3972 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3973 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, value); | |
3974 | ||
3975 | if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS && | |
3976 | battery->status == POWER_SUPPLY_STATUS_CHARGING && | |
3977 | !battery->cc_cv_mode && | |
3978 | battery->siop_level == 100 ) { | |
3979 | value.intval = 0; /* 5.5 */ | |
3980 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3981 | POWER_SUPPLY_PROP_CHARGE_TYPE, value); | |
3982 | } else if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS && | |
3983 | battery->status == POWER_SUPPLY_STATUS_CHARGING && | |
3984 | !battery->cc_cv_mode && | |
3985 | battery->siop_level != 100) { | |
3986 | value.intval = 1; /* 5 */ | |
3987 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
3988 | POWER_SUPPLY_PROP_CHARGE_TYPE, value); | |
3989 | } | |
3990 | #endif | |
3991 | if (battery->capacity <= 5) { | |
3992 | battery->siop_level = 100; | |
3993 | battery->ignore_siop = true; | |
3994 | } else if (battery->ignore_siop) { | |
3995 | battery->ignore_siop = false; | |
3996 | } | |
3997 | ||
3998 | wake_lock(&battery->siop_wake_lock); | |
3999 | ||
4000 | if (battery->cable_type == POWER_SUPPLY_TYPE_WIRELESS) | |
4001 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->siop_work, | |
4002 | msecs_to_jiffies(1200)); | |
4003 | else | |
4004 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->siop_work, 0); | |
4005 | ||
4006 | ret = count; | |
4007 | } | |
4008 | break; | |
4009 | case BATT_CHARGING_SOURCE: | |
4010 | break; | |
4011 | case FG_REG_DUMP: | |
4012 | break; | |
4013 | case FG_RESET_CAP: | |
4014 | break; | |
4015 | case FG_CAPACITY: | |
4016 | break; | |
4017 | case AUTH: | |
4018 | break; | |
4019 | case CHG_CURRENT_ADC: | |
4020 | break; | |
4021 | case WC_ADC: | |
4022 | break; | |
4023 | case WC_STATUS: | |
4024 | break; | |
4025 | case WC_ENABLE: | |
4026 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4027 | if (x == 0) { | |
4028 | battery->wc_enable = false; | |
4029 | } else if (x == 1) { | |
4030 | battery->wc_enable = true; | |
4031 | } else { | |
4032 | dev_info(battery->dev, | |
4033 | "%s: WPC ENABLE unknown command\n", | |
4034 | __func__); | |
4035 | return -EINVAL; | |
4036 | } | |
4037 | wake_lock(&battery->cable_wake_lock); | |
4038 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
4039 | &battery->cable_work, 0); | |
4040 | ret = count; | |
4041 | } | |
4042 | break; | |
4043 | case HV_CHARGER_STATUS: | |
4044 | break; | |
4045 | case HV_CHARGER_SET: | |
4046 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4047 | dev_info(battery->dev, | |
4048 | "%s: HV_CHARGER_SET(%d)\n", __func__, x); | |
4049 | if (x == 1) { | |
4050 | battery->wire_status = POWER_SUPPLY_TYPE_HV_MAINS; | |
4051 | wake_lock(&battery->cable_wake_lock); | |
4052 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->cable_work, 0); | |
4053 | } else { | |
4054 | battery->wire_status = POWER_SUPPLY_TYPE_BATTERY; | |
4055 | wake_lock(&battery->cable_wake_lock); | |
4056 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->cable_work, 0); | |
4057 | } | |
4058 | ret = count; | |
4059 | } | |
4060 | break; | |
4061 | case FACTORY_MODE: | |
4062 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4063 | battery->factory_mode = x ? true : false; | |
4064 | ret = count; | |
4065 | } | |
4066 | break; | |
4067 | case STORE_MODE: | |
4068 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4069 | if (x) { | |
4070 | battery->store_mode = true; | |
4071 | #if !defined(CONFIG_SEC_FACTORY) | |
4072 | if (battery->capacity <= 5) { | |
4073 | battery->ignore_store_mode = true; | |
4074 | } else { | |
4075 | union power_supply_propval value; | |
4076 | value.intval = battery->store_mode; | |
4077 | psy_do_property(battery->pdata->charger_name, set, | |
4078 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, value); | |
4079 | } | |
4080 | #endif | |
4081 | } | |
4082 | ret = count; | |
4083 | } | |
4084 | break; | |
4085 | case UPDATE: | |
4086 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4087 | #ifdef CONFIG_FUELGAUGE_S2MU005 | |
4088 | union power_supply_propval value; | |
4089 | ||
4090 | /* update rVBAT register every 250ms for AT+BATTTEST */ | |
4091 | value.intval = 1; | |
4092 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
4093 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4094 | msleep(250); | |
4095 | ||
4096 | sec_bat_get_battery_info(battery); | |
4097 | ||
4098 | /* update rVBAT register every 4s for normal case */ | |
4099 | value.intval = 0; | |
4100 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
4101 | POWER_SUPPLY_PROP_ENERGY_NOW, value); | |
4102 | #else | |
4103 | /* update battery info */ | |
4104 | sec_bat_get_battery_info(battery); | |
4105 | #endif | |
4106 | ret = count; | |
4107 | } | |
4108 | break; | |
4109 | case TEST_MODE: | |
4110 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4111 | battery->test_mode = x; | |
4112 | wake_lock(&battery->monitor_wake_lock); | |
4113 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
4114 | &battery->monitor_work, 0); | |
4115 | ret = count; | |
4116 | } | |
4117 | break; | |
4118 | ||
4119 | case BATT_EVENT_CALL: | |
4120 | case BATT_EVENT_2G_CALL: | |
4121 | case BATT_EVENT_TALK_GSM: | |
4122 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4123 | sec_bat_event_set(battery, EVENT_2G_CALL, x); | |
4124 | ret = count; | |
4125 | } | |
4126 | break; | |
4127 | case BATT_EVENT_3G_CALL: | |
4128 | case BATT_EVENT_TALK_WCDMA: | |
4129 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4130 | sec_bat_event_set(battery, EVENT_3G_CALL, x); | |
4131 | ret = count; | |
4132 | } | |
4133 | break; | |
4134 | case BATT_EVENT_MUSIC: | |
4135 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4136 | sec_bat_event_set(battery, EVENT_MUSIC, x); | |
4137 | ret = count; | |
4138 | } | |
4139 | break; | |
4140 | case BATT_EVENT_VIDEO: | |
4141 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4142 | sec_bat_event_set(battery, EVENT_VIDEO, x); | |
4143 | ret = count; | |
4144 | } | |
4145 | break; | |
4146 | case BATT_EVENT_BROWSER: | |
4147 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4148 | sec_bat_event_set(battery, EVENT_BROWSER, x); | |
4149 | ret = count; | |
4150 | } | |
4151 | break; | |
4152 | case BATT_EVENT_HOTSPOT: | |
4153 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4154 | sec_bat_event_set(battery, EVENT_HOTSPOT, x); | |
4155 | ret = count; | |
4156 | } | |
4157 | break; | |
4158 | case BATT_EVENT_CAMERA: | |
4159 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4160 | sec_bat_event_set(battery, EVENT_CAMERA, x); | |
4161 | ret = count; | |
4162 | } | |
4163 | break; | |
4164 | case BATT_EVENT_CAMCORDER: | |
4165 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4166 | sec_bat_event_set(battery, EVENT_CAMCORDER, x); | |
4167 | ret = count; | |
4168 | } | |
4169 | break; | |
4170 | case BATT_EVENT_DATA_CALL: | |
4171 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4172 | sec_bat_event_set(battery, EVENT_DATA_CALL, x); | |
4173 | ret = count; | |
4174 | } | |
4175 | break; | |
4176 | case BATT_EVENT_WIFI: | |
4177 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4178 | sec_bat_event_set(battery, EVENT_WIFI, x); | |
4179 | ret = count; | |
4180 | } | |
4181 | break; | |
4182 | case BATT_EVENT_WIBRO: | |
4183 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4184 | sec_bat_event_set(battery, EVENT_WIBRO, x); | |
4185 | ret = count; | |
4186 | } | |
4187 | break; | |
4188 | case BATT_EVENT_LTE: | |
4189 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4190 | sec_bat_event_set(battery, EVENT_LTE, x); | |
4191 | ret = count; | |
4192 | } | |
4193 | break; | |
4194 | case BATT_EVENT_LCD: | |
4195 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4196 | /* we need to test | |
4197 | sec_bat_event_set(battery, EVENT_LCD, x); | |
4198 | */ | |
4199 | if (x) { | |
4200 | battery->lcd_status = true; | |
4201 | } else { | |
4202 | battery->lcd_status = false; | |
4203 | } | |
4204 | ret = count; | |
4205 | } | |
4206 | break; | |
4207 | case BATT_EVENT_GPS: | |
4208 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4209 | sec_bat_event_set(battery, EVENT_GPS, x); | |
4210 | ret = count; | |
4211 | } | |
4212 | break; | |
4213 | case BATT_TEMP_TABLE: | |
4214 | if (sscanf(buf, "%d %d %d %d %d %d %d %d %d %d %d %d\n", | |
4215 | &t[0], &t[1], &t[2], &t[3], &t[4], &t[5], &t[6], &t[7], &t[8], &t[9], &t[10], &t[11]) == 12) { | |
4216 | pr_info("%s: (new) %d %d %d %d %d %d %d %d %d %d %d %d\n", | |
4217 | __func__, t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9], t[10], t[11]); | |
4218 | pr_info("%s: (default) %d %d %d %d %d %d %d %d %d %d %d %d\n", | |
4219 | __func__, | |
4220 | battery->pdata->temp_high_threshold_event, | |
4221 | battery->pdata->temp_high_recovery_event, | |
4222 | battery->pdata->temp_low_threshold_event, | |
4223 | battery->pdata->temp_low_recovery_event, | |
4224 | battery->pdata->temp_high_threshold_normal, | |
4225 | battery->pdata->temp_high_recovery_normal, | |
4226 | battery->pdata->temp_low_threshold_normal, | |
4227 | battery->pdata->temp_low_recovery_normal, | |
4228 | battery->pdata->temp_high_threshold_lpm, | |
4229 | battery->pdata->temp_high_recovery_lpm, | |
4230 | battery->pdata->temp_low_threshold_lpm, | |
4231 | battery->pdata->temp_low_recovery_lpm); | |
4232 | update_external_temp_table(battery, t); | |
4233 | ret = count; | |
4234 | } | |
4235 | break; | |
4236 | case BATT_HIGH_CURRENT_USB: | |
4237 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4238 | union power_supply_propval value; | |
4239 | battery->is_hc_usb = x ? true : false; | |
4240 | value.intval = battery->is_hc_usb; | |
4241 | ||
4242 | psy_do_property(battery->pdata->charger_name, set, | |
4243 | POWER_SUPPLY_PROP_USB_HC, value); | |
4244 | ||
4245 | pr_info("%s: is_hc_usb (%d)\n", __func__, battery->is_hc_usb); | |
4246 | ret = count; | |
4247 | } | |
4248 | break; | |
4249 | #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) | |
4250 | case BATT_TEST_CHARGE_CURRENT: | |
4251 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4252 | if (x >= 0 && x <= 2000) { | |
4253 | union power_supply_propval value; | |
4254 | dev_err(battery->dev, | |
4255 | "%s: BATT_TEST_CHARGE_CURRENT(%d)\n", __func__, x); | |
4256 | battery->pdata->charging_current[ | |
4257 | POWER_SUPPLY_TYPE_USB].input_current_limit = x; | |
4258 | battery->pdata->charging_current[ | |
4259 | POWER_SUPPLY_TYPE_USB].fast_charging_current = x; | |
4260 | if (x > 500) { | |
4261 | battery->eng_not_full_status = true; | |
4262 | battery->pdata->temp_check_type = | |
4263 | SEC_BATTERY_TEMP_CHECK_NONE; | |
4264 | battery->pdata->charging_total_time = | |
4265 | 10000 * 60 * 60; | |
4266 | } | |
4267 | if (battery->cable_type == POWER_SUPPLY_TYPE_USB) { | |
4268 | value.intval = x; | |
4269 | psy_do_property(battery->pdata->charger_name, set, | |
4270 | POWER_SUPPLY_PROP_CURRENT_NOW, | |
4271 | value); | |
4272 | } | |
4273 | } | |
4274 | ret = count; | |
4275 | } | |
4276 | break; | |
4277 | #endif | |
4278 | case BATT_STABILITY_TEST: | |
4279 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4280 | dev_err(battery->dev, | |
4281 | "%s: BATT_STABILITY_TEST(%d)\n", __func__, x); | |
4282 | if (x) { | |
4283 | battery->stability_test = true; | |
4284 | battery->eng_not_full_status = true; | |
4285 | } | |
4286 | else { | |
4287 | battery->stability_test = false; | |
4288 | battery->eng_not_full_status = false; | |
4289 | } | |
4290 | ret = count; | |
4291 | } | |
4292 | break; | |
4293 | #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX) | |
4294 | case BATT_CAPACITY_MAX: | |
4295 | if (sscanf(buf, "%d\n", &x) == 1 && !fg_reset) { | |
4296 | union power_supply_propval value; | |
4297 | dev_err(battery->dev, | |
4298 | "%s: BATT_CAPACITY_MAX(%d)\n", __func__, x); | |
4299 | if (x > 800 && x < 1200) { | |
4300 | value.intval = x; | |
4301 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
4302 | POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, value); | |
4303 | } | |
4304 | ||
4305 | /* update soc */ | |
4306 | value.intval = 0; | |
4307 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4308 | POWER_SUPPLY_PROP_CAPACITY, value); | |
4309 | battery->capacity = value.intval; | |
4310 | power_supply_changed(&battery->psy_bat); | |
4311 | } | |
4312 | ret = count; | |
4313 | break; | |
4314 | #endif | |
4315 | case BATT_INBAT_VOLTAGE: | |
4316 | break; | |
4317 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
4318 | case BATT_DISCHARGING_CHECK: | |
4319 | break; | |
4320 | case BATT_DISCHARGING_CHECK_ADC: | |
4321 | break; | |
4322 | case BATT_DISCHARGING_NTC: | |
4323 | break; | |
4324 | case BATT_DISCHARGING_NTC_ADC: | |
4325 | break; | |
4326 | case BATT_SELF_DISCHARGING_CONTROL: | |
4327 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4328 | dev_err(battery->dev, | |
4329 | "%s: BATT_SELF_DISCHARGING_CONTROL(%d)\n", __func__, x); | |
4330 | if (x) { | |
4331 | battery->factory_self_discharging_mode_on = true; | |
4332 | pr_info("SELF DISCHARGING IC ENABLE\n"); | |
4333 | sec_bat_self_discharging_control(battery, true); | |
4334 | } else { | |
4335 | battery->factory_self_discharging_mode_on = false; | |
4336 | pr_info("SELF DISCHARGING IC DISENABLE\n"); | |
4337 | sec_bat_self_discharging_control(battery, false); | |
4338 | } | |
4339 | ret = count; | |
4340 | } | |
4341 | break; | |
4342 | #endif | |
4343 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
4344 | case BATT_INBAT_WIRELESS_CS100: | |
4345 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4346 | union power_supply_propval value; | |
4347 | ||
4348 | pr_info("%s send cs100 command \n",__func__); | |
4349 | value.intval = POWER_SUPPLY_STATUS_FULL; | |
4350 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
4351 | POWER_SUPPLY_PROP_STATUS, value); | |
4352 | ret = count; | |
4353 | } | |
4354 | break; | |
4355 | #endif | |
4356 | case HMT_TA_CONNECTED: | |
4357 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4358 | union power_supply_propval value; | |
4359 | dev_info(battery->dev, | |
4360 | "%s: HMT_TA_CONNECTED(%d)\n", __func__, x); | |
4361 | if (x) { | |
4362 | value.intval = false; | |
4363 | psy_do_property(battery->pdata->charger_name, set, | |
4364 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
4365 | value); | |
4366 | dev_info(battery->dev, | |
4367 | "%s: changed to OTG cable detached\n", __func__); | |
4368 | ||
4369 | battery->wire_status = POWER_SUPPLY_TYPE_HMT_CONNECTED; | |
4370 | wake_lock(&battery->cable_wake_lock); | |
4371 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->cable_work, 0); | |
4372 | } else { | |
4373 | value.intval = true; | |
4374 | psy_do_property(battery->pdata->charger_name, set, | |
4375 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
4376 | value); | |
4377 | dev_info(battery->dev, | |
4378 | "%s: changed to OTG cable attached\n", __func__); | |
4379 | ||
4380 | battery->wire_status = POWER_SUPPLY_TYPE_OTG; | |
4381 | wake_lock(&battery->cable_wake_lock); | |
4382 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->cable_work, 0); | |
4383 | } | |
4384 | ret = count; | |
4385 | } | |
4386 | break; | |
4387 | case HMT_TA_CHARGE: | |
4388 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4389 | union power_supply_propval value; | |
4390 | dev_info(battery->dev, | |
4391 | "%s: HMT_TA_CHARGE(%d)\n", __func__, x); | |
4392 | psy_do_property(battery->pdata->charger_name, get, | |
4393 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
4394 | if (value.intval) { | |
4395 | dev_info(battery->dev, | |
4396 | "%s: ignore HMT_TA_CHARGE(%d)\n", __func__, x); | |
4397 | } else { | |
4398 | if (x) { | |
4399 | value.intval = false; | |
4400 | psy_do_property(battery->pdata->charger_name, set, | |
4401 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
4402 | value); | |
4403 | dev_info(battery->dev, | |
4404 | "%s: changed to OTG cable detached\n", __func__); | |
4405 | battery->wire_status = POWER_SUPPLY_TYPE_HMT_CHARGE; | |
4406 | wake_lock(&battery->cable_wake_lock); | |
4407 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->cable_work, 0); | |
4408 | } else { | |
4409 | value.intval = false; | |
4410 | psy_do_property(battery->pdata->charger_name, set, | |
4411 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
4412 | value); | |
4413 | dev_info(battery->dev, | |
4414 | "%s: changed to OTG cable detached\n", __func__); | |
4415 | battery->wire_status = POWER_SUPPLY_TYPE_HMT_CONNECTED; | |
4416 | wake_lock(&battery->cable_wake_lock); | |
4417 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->cable_work, 0); | |
4418 | } | |
4419 | } | |
4420 | ret = count; | |
4421 | } | |
4422 | break; | |
4423 | case FG_CYCLE: | |
4424 | break; | |
4425 | case FG_FULL_VOLTAGE: | |
4426 | break; | |
4427 | case FG_FULLCAPNOM: | |
4428 | break; | |
4429 | case BATTERY_CYCLE: | |
4430 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4431 | dev_info(battery->dev, "%s: BATTERY_CYCLE(%d)\n", __func__, x); | |
4432 | if (x >= 0) { | |
4433 | int prev_battery_cycle; | |
4434 | prev_battery_cycle = battery->batt_cycle; | |
4435 | battery->batt_cycle = x; | |
4436 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
6828552d | 4437 | dev_info(battery->dev, "%s: [Long life] prev_battery_cycle = %d, new bat. cycle = %d\n", __func__, prev_battery_cycle, battery->batt_cycle); |
3c2a0909 | 4438 | if (prev_battery_cycle < 0) { |
6828552d | 4439 | dev_info(battery->dev, "%s: [Long life] Do sec_bat_aging_check()\n", __func__); |
3c2a0909 S |
4440 | sec_bat_aging_check(battery); |
4441 | } | |
4442 | #endif | |
4443 | } | |
4444 | ret = count; | |
4445 | } | |
4446 | break; | |
4447 | case FACTORY_MODE_RELIEVE: | |
4448 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4449 | union power_supply_propval value; | |
4450 | value.intval = x; | |
4451 | psy_do_property(battery->pdata->charger_name, set, | |
4452 | POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION, value); | |
4453 | ret = count; | |
4454 | } | |
4455 | break; | |
4456 | case FACTORY_MODE_BYPASS: | |
4457 | if (sscanf(buf, "%d\n", &x) == 1) { | |
4458 | union power_supply_propval value; | |
4459 | value.intval = x; | |
4460 | psy_do_property(battery->pdata->charger_name, set, | |
4461 | POWER_SUPPLY_PROP_AUTHENTIC, value); | |
4462 | ret = count; | |
4463 | } | |
4464 | break; | |
4465 | default: | |
4466 | ret = -EINVAL; | |
4467 | } | |
4468 | ||
4469 | return ret; | |
4470 | } | |
4471 | ||
4472 | static int sec_bat_create_attrs(struct device *dev) | |
4473 | { | |
4474 | unsigned long i; | |
4475 | int rc; | |
4476 | ||
4477 | for (i = 0; i < ARRAY_SIZE(sec_battery_attrs); i++) { | |
4478 | rc = device_create_file(dev, &sec_battery_attrs[i]); | |
4479 | if (rc) | |
4480 | goto create_attrs_failed; | |
4481 | } | |
4482 | goto create_attrs_succeed; | |
4483 | ||
4484 | create_attrs_failed: | |
4485 | while (i--) | |
4486 | device_remove_file(dev, &sec_battery_attrs[i]); | |
4487 | create_attrs_succeed: | |
4488 | return rc; | |
4489 | } | |
4490 | ||
4491 | static int sec_bat_set_property(struct power_supply *psy, | |
4492 | enum power_supply_property psp, | |
4493 | const union power_supply_propval *val) | |
4494 | { | |
4495 | struct sec_battery_info *battery = | |
4496 | container_of(psy, struct sec_battery_info, psy_bat); | |
4497 | int current_cable_type; | |
4498 | int full_check_type; | |
4499 | ||
4500 | dev_dbg(battery->dev, | |
4501 | "%s: (%d,%d)\n", __func__, psp, val->intval); | |
4502 | ||
4503 | switch (psp) { | |
4504 | case POWER_SUPPLY_PROP_STATUS: | |
4505 | if (battery->charging_mode == SEC_BATTERY_CHARGING_1ST) | |
4506 | full_check_type = battery->pdata->full_check_type; | |
4507 | else | |
4508 | full_check_type = battery->pdata->full_check_type_2nd; | |
4509 | if ((full_check_type == SEC_BATTERY_FULLCHARGED_CHGINT) && | |
4510 | (val->intval == POWER_SUPPLY_STATUS_FULL)) | |
4511 | sec_bat_do_fullcharged(battery); | |
4512 | sec_bat_set_charging_status(battery, val->intval); | |
4513 | break; | |
4514 | case POWER_SUPPLY_PROP_HEALTH: | |
4515 | sec_bat_ovp_uvlo_result(battery, val->intval); | |
4516 | break; | |
4517 | case POWER_SUPPLY_PROP_ONLINE: | |
4518 | current_cable_type = val->intval; | |
4519 | ||
4520 | if ((battery->muic_cable_type != ATTACHED_DEV_SMARTDOCK_TA_MUIC) | |
4521 | && ((current_cable_type == POWER_SUPPLY_TYPE_SMART_OTG) || | |
4522 | (current_cable_type == POWER_SUPPLY_TYPE_SMART_NOTG))) | |
4523 | break; | |
4524 | ||
4525 | if (current_cable_type < 0) { | |
4526 | dev_info(battery->dev, | |
4527 | "%s: ignore event(%d)\n", | |
4528 | __func__, current_cable_type); | |
4529 | } else if (current_cable_type == POWER_SUPPLY_TYPE_OTG) { | |
4530 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
4531 | battery->is_recharging = false; | |
4532 | sec_bat_set_charging_status(battery, | |
4533 | POWER_SUPPLY_STATUS_DISCHARGING); | |
4534 | battery->cable_type = current_cable_type; | |
4535 | wake_lock(&battery->monitor_wake_lock); | |
4536 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
4537 | &battery->monitor_work, 0); | |
4538 | break; | |
4539 | } else { | |
4540 | battery->wire_status = current_cable_type; | |
4541 | if ((battery->wire_status == POWER_SUPPLY_TYPE_BATTERY) | |
4542 | && battery->wc_status) | |
4543 | current_cable_type = POWER_SUPPLY_TYPE_WIRELESS; | |
4544 | } | |
4545 | dev_info(battery->dev, | |
4546 | "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n", | |
4547 | __func__, current_cable_type, battery->wc_status, | |
4548 | battery->wire_status); | |
4549 | ||
4550 | /* cable is attached or detached | |
4551 | * if current_cable_type is minus value, | |
4552 | * check cable by sec_bat_get_cable_type() | |
4553 | * although SEC_BATTERY_CABLE_SOURCE_EXTERNAL is set | |
4554 | * (0 is POWER_SUPPLY_TYPE_UNKNOWN) | |
4555 | */ | |
4556 | if ((current_cable_type >= 0) && | |
4557 | (current_cable_type < SEC_SIZEOF_POWER_SUPPLY_TYPE) && | |
4558 | (battery->pdata->cable_source_type & | |
4559 | SEC_BATTERY_CABLE_SOURCE_EXTERNAL)) { | |
4560 | ||
4561 | wake_lock(&battery->cable_wake_lock); | |
4562 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
4563 | &battery->cable_work,0); | |
4564 | } else { | |
4565 | if (sec_bat_get_cable_type(battery, | |
4566 | battery->pdata->cable_source_type)) { | |
4567 | wake_lock(&battery->cable_wake_lock); | |
4568 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
4569 | &battery->cable_work,0); | |
4570 | } | |
4571 | } | |
4572 | break; | |
4573 | case POWER_SUPPLY_PROP_CAPACITY: | |
4574 | battery->capacity = val->intval; | |
4575 | power_supply_changed(&battery->psy_bat); | |
4576 | break; | |
4577 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | |
4578 | /* If JIG is attached, the voltage is set as 1079 */ | |
4579 | pr_info("%s : set to the battery history : (%d)\n",__func__, val->intval); | |
4580 | if(val->intval == 1079) { | |
4581 | battery->voltage_now = 1079; | |
4582 | battery->voltage_avg = 1079; | |
4583 | power_supply_changed(&battery->psy_bat); | |
4584 | } | |
4585 | break; | |
4586 | case POWER_SUPPLY_PROP_CURRENT_AVG: | |
4587 | battery->charging_current = val->intval; | |
4588 | break; | |
4589 | case POWER_SUPPLY_PROP_CHARGE_TYPE: | |
4590 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
4591 | break; | |
4592 | case POWER_SUPPLY_PROP_PRESENT: | |
4593 | battery->present = val->intval; | |
4594 | ||
4595 | wake_lock(&battery->monitor_wake_lock); | |
4596 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
4597 | &battery->monitor_work, 0); | |
4598 | break; | |
4599 | #if defined(CONFIG_BATTERY_SWELLING) | |
4600 | case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: | |
4601 | break; | |
4602 | #endif | |
4603 | default: | |
4604 | return -EINVAL; | |
4605 | } | |
4606 | ||
4607 | return 0; | |
4608 | } | |
4609 | ||
4610 | static int sec_bat_get_property(struct power_supply *psy, | |
4611 | enum power_supply_property psp, | |
4612 | union power_supply_propval *val) | |
4613 | { | |
4614 | struct sec_battery_info *battery = | |
4615 | container_of(psy, struct sec_battery_info, psy_bat); | |
4616 | union power_supply_propval value; | |
4617 | #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY) | |
4618 | union power_supply_propval value_ac; | |
4619 | union power_supply_propval value_usb; | |
4620 | #endif | |
4621 | ||
4622 | switch (psp) { | |
4623 | case POWER_SUPPLY_PROP_STATUS: | |
4624 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERVOLTAGE) || | |
4625 | (battery->health == POWER_SUPPLY_HEALTH_UNDERVOLTAGE)) { | |
4626 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; | |
4627 | } else { | |
4628 | if ((battery->pdata->cable_check_type & | |
4629 | SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE) && | |
4630 | !lpcharge) { | |
4631 | switch (battery->cable_type) { | |
4632 | case POWER_SUPPLY_TYPE_USB: | |
4633 | case POWER_SUPPLY_TYPE_USB_DCP: | |
4634 | case POWER_SUPPLY_TYPE_USB_CDP: | |
4635 | case POWER_SUPPLY_TYPE_USB_ACA: | |
4636 | val->intval = | |
4637 | POWER_SUPPLY_STATUS_DISCHARGING; | |
4638 | return 0; | |
4639 | } | |
4640 | } | |
4641 | #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP) | |
4642 | if (battery->status == POWER_SUPPLY_STATUS_FULL && | |
4643 | battery->capacity != 100) { | |
4644 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | |
4645 | pr_info("%s: forced full-charged sequence progressing\n", __func__); | |
4646 | } else | |
4647 | #endif | |
4648 | val->intval = battery->status; | |
4649 | ||
4650 | #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY) | |
4651 | psy_do_property("ac", get, POWER_SUPPLY_PROP_ONLINE, value_ac); | |
4652 | psy_do_property("usb", get, POWER_SUPPLY_PROP_ONLINE, value_usb); | |
4653 | if (battery->store_mode && !lpcharge && (value_ac.intval || value_usb.intval)) { | |
4654 | val->intval = POWER_SUPPLY_STATUS_CHARGING; | |
4655 | } | |
4656 | #endif | |
4657 | } | |
4658 | break; | |
4659 | case POWER_SUPPLY_PROP_CHARGE_TYPE: | |
4660 | if (battery->cable_type == POWER_SUPPLY_TYPE_BATTERY || | |
4661 | battery->cable_type == POWER_SUPPLY_TYPE_MHL_USB_100) { | |
4662 | val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; | |
4663 | } else { | |
4664 | psy_do_property(battery->pdata->charger_name, get, | |
4665 | POWER_SUPPLY_PROP_CHARGE_TYPE, value); | |
4666 | if (value.intval == POWER_SUPPLY_CHARGE_TYPE_UNKNOWN) | |
4667 | /* if error in CHARGE_TYPE of charger | |
4668 | * set CHARGE_TYPE as NONE | |
4669 | */ | |
4670 | val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; | |
4671 | else | |
4672 | val->intval = value.intval; | |
4673 | } | |
4674 | break; | |
4675 | case POWER_SUPPLY_PROP_HEALTH: | |
4676 | val->intval = battery->health; | |
4677 | break; | |
4678 | case POWER_SUPPLY_PROP_PRESENT: | |
4679 | val->intval = battery->present; | |
4680 | break; | |
4681 | case POWER_SUPPLY_PROP_ONLINE: | |
4682 | val->intval = battery->cable_type; | |
4683 | break; | |
4684 | case POWER_SUPPLY_PROP_TECHNOLOGY: | |
4685 | val->intval = battery->pdata->technology; | |
4686 | break; | |
4687 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | |
4688 | #ifdef CONFIG_SEC_FACTORY | |
4689 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4690 | POWER_SUPPLY_PROP_VOLTAGE_NOW, value); | |
4691 | battery->voltage_now = value.intval; | |
4692 | dev_err(battery->dev, | |
4693 | "%s: voltage now(%d)\n", __func__, battery->voltage_now); | |
4694 | #endif | |
4695 | /* voltage value should be in uV */ | |
4696 | val->intval = battery->voltage_now * 1000; | |
4697 | break; | |
4698 | case POWER_SUPPLY_PROP_VOLTAGE_AVG: | |
4699 | #ifdef CONFIG_SEC_FACTORY | |
4700 | value.intval = SEC_BATTERY_VOLTAGE_AVERAGE; | |
4701 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
4702 | POWER_SUPPLY_PROP_VOLTAGE_AVG, value); | |
4703 | battery->voltage_avg = value.intval; | |
4704 | dev_err(battery->dev, | |
4705 | "%s: voltage avg(%d)\n", __func__, battery->voltage_avg); | |
4706 | #endif | |
4707 | /* voltage value should be in uV */ | |
4708 | val->intval = battery->voltage_avg * 1000; | |
4709 | break; | |
4710 | case POWER_SUPPLY_PROP_CURRENT_NOW: | |
4711 | val->intval = battery->current_now; | |
4712 | break; | |
4713 | case POWER_SUPPLY_PROP_CURRENT_AVG: | |
4714 | val->intval = battery->current_avg; | |
4715 | break; | |
4716 | /* charging mode (differ from power supply) */ | |
4717 | case POWER_SUPPLY_PROP_CHARGE_NOW: | |
4718 | val->intval = battery->charging_mode; | |
4719 | break; | |
4720 | case POWER_SUPPLY_PROP_CAPACITY: | |
4721 | if (battery->pdata->fake_capacity) { | |
4722 | val->intval = 90; | |
4723 | pr_info("%s : capacity(%d)\n", __func__, val->intval); | |
4724 | } else { | |
4725 | #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) | |
4726 | if (battery->status == POWER_SUPPLY_STATUS_FULL) { | |
4727 | if(battery->eng_not_full_status) | |
4728 | val->intval = battery->capacity; | |
4729 | else | |
4730 | val->intval = 100; | |
4731 | } else { | |
4732 | val->intval = battery->capacity; | |
4733 | } | |
4734 | #else | |
4735 | #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP) | |
4736 | val->intval = battery->capacity; | |
4737 | #else | |
4738 | /* In full-charged status, SOC is always 100% */ | |
4739 | if (battery->status == POWER_SUPPLY_STATUS_FULL) | |
4740 | val->intval = 100; | |
4741 | else | |
4742 | val->intval = battery->capacity; | |
4743 | #endif | |
4744 | #endif | |
4745 | } | |
4746 | break; | |
4747 | case POWER_SUPPLY_PROP_TEMP: | |
4748 | val->intval = battery->temperature; | |
4749 | break; | |
4750 | case POWER_SUPPLY_PROP_TEMP_AMBIENT: | |
4751 | val->intval = battery->temper_amb; | |
4752 | break; | |
4753 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
4754 | case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: | |
4755 | #if defined(CONFIG_CHARGING_VZWCONCEPT) | |
4756 | if (battery->capacity == 100) { | |
4757 | val->intval = -1; | |
4758 | break; | |
4759 | } | |
4760 | #endif | |
4761 | if (battery->status == POWER_SUPPLY_STATUS_CHARGING && battery->complete_timetofull && | |
4762 | !battery->swelling_mode) | |
4763 | val->intval = battery->timetofull; | |
4764 | else | |
4765 | val->intval = -1; | |
4766 | break; | |
4767 | #endif | |
4768 | #if defined(CONFIG_BATTERY_SWELLING) | |
4769 | case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: | |
4770 | if ((battery->swelling_mode) || (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP)) | |
4771 | val->intval = 1; | |
4772 | else | |
4773 | val->intval = 0; | |
4774 | break; | |
4775 | #endif | |
4776 | default: | |
4777 | return -EINVAL; | |
4778 | } | |
4779 | return 0; | |
4780 | } | |
4781 | ||
4782 | static int sec_usb_get_property(struct power_supply *psy, | |
4783 | enum power_supply_property psp, | |
4784 | union power_supply_propval *val) | |
4785 | { | |
4786 | struct sec_battery_info *battery = | |
4787 | container_of(psy, struct sec_battery_info, psy_usb); | |
4788 | ||
2a746c1b JC |
4789 | switch (psp) { |
4790 | case POWER_SUPPLY_PROP_ONLINE: | |
4791 | break; | |
4792 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: | |
4793 | /* V -> uV */ | |
4794 | val->intval = battery->input_voltage * 1000000; | |
4795 | return 0; | |
4796 | case POWER_SUPPLY_PROP_CURRENT_MAX: | |
4797 | /* mA -> uA */ | |
4798 | val->intval = battery->pdata->charging_current[battery->cable_type].input_current_limit * 1000; | |
4799 | return 0; | |
4800 | default: | |
3c2a0909 | 4801 | return -EINVAL; |
2a746c1b | 4802 | } |
3c2a0909 S |
4803 | |
4804 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERVOLTAGE) || | |
4805 | (battery->health == POWER_SUPPLY_HEALTH_UNDERVOLTAGE)) { | |
4806 | val->intval = 0; | |
4807 | return 0; | |
4808 | } | |
4809 | /* Set enable=1 only if the USB charger is connected */ | |
4810 | switch (battery->wire_status) { | |
4811 | case POWER_SUPPLY_TYPE_USB: | |
4812 | case POWER_SUPPLY_TYPE_USB_DCP: | |
4813 | case POWER_SUPPLY_TYPE_USB_CDP: | |
4814 | case POWER_SUPPLY_TYPE_USB_ACA: | |
4815 | case POWER_SUPPLY_TYPE_MHL_USB: | |
4816 | case POWER_SUPPLY_TYPE_MHL_USB_100: | |
4817 | val->intval = 1; | |
4818 | break; | |
4819 | default: | |
4820 | val->intval = 0; | |
4821 | break; | |
4822 | } | |
4823 | ||
4824 | if (battery->slate_mode) | |
4825 | val->intval = 0; | |
4826 | return 0; | |
4827 | } | |
4828 | ||
4829 | static int sec_ac_get_property(struct power_supply *psy, | |
4830 | enum power_supply_property psp, | |
4831 | union power_supply_propval *val) | |
4832 | { | |
4833 | struct sec_battery_info *battery = | |
4834 | container_of(psy, struct sec_battery_info, psy_ac); | |
4835 | ||
2a746c1b JC |
4836 | switch (psp) { |
4837 | case POWER_SUPPLY_PROP_ONLINE: | |
4838 | break; | |
4839 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: | |
4840 | /* V -> uV */ | |
4841 | val->intval = battery->input_voltage * 1000000; | |
4842 | return 0; | |
4843 | case POWER_SUPPLY_PROP_CURRENT_MAX: | |
4844 | /* mA -> uA */ | |
4845 | val->intval = battery->pdata->charging_current[battery->cable_type].input_current_limit * 1000; | |
4846 | return 0; | |
4847 | default: | |
3c2a0909 | 4848 | return -EINVAL; |
2a746c1b | 4849 | } |
3c2a0909 S |
4850 | |
4851 | if ((battery->health == POWER_SUPPLY_HEALTH_OVERVOLTAGE) || | |
4852 | (battery->health == POWER_SUPPLY_HEALTH_UNDERVOLTAGE)) { | |
4853 | val->intval = 0; | |
4854 | return 0; | |
4855 | } | |
4856 | ||
4857 | /* Set enable=1 only if the AC charger is connected */ | |
4858 | switch (battery->cable_type) { | |
4859 | case POWER_SUPPLY_TYPE_MAINS: | |
4860 | case POWER_SUPPLY_TYPE_MISC: | |
4861 | case POWER_SUPPLY_TYPE_CARDOCK: | |
4862 | case POWER_SUPPLY_TYPE_UARTOFF: | |
4863 | case POWER_SUPPLY_TYPE_LAN_HUB: | |
4864 | case POWER_SUPPLY_TYPE_UNKNOWN: | |
4865 | case POWER_SUPPLY_TYPE_MHL_500: | |
4866 | case POWER_SUPPLY_TYPE_MHL_900: | |
4867 | case POWER_SUPPLY_TYPE_MHL_1500: | |
4868 | case POWER_SUPPLY_TYPE_MHL_2000: | |
4869 | case POWER_SUPPLY_TYPE_SMART_OTG: | |
4870 | case POWER_SUPPLY_TYPE_SMART_NOTG: | |
4871 | case POWER_SUPPLY_TYPE_HV_PREPARE_MAINS: | |
4872 | case POWER_SUPPLY_TYPE_HV_ERR: | |
4873 | case POWER_SUPPLY_TYPE_HV_UNKNOWN: | |
4874 | case POWER_SUPPLY_TYPE_HV_MAINS: | |
4875 | case POWER_SUPPLY_TYPE_MDOCK_TA: | |
4876 | case POWER_SUPPLY_TYPE_HMT_CONNECTED: | |
4877 | case POWER_SUPPLY_TYPE_HMT_CHARGE: | |
4878 | case POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT: | |
4879 | val->intval = 1; | |
4880 | break; | |
4881 | default: | |
4882 | val->intval = 0; | |
4883 | break; | |
4884 | } | |
4885 | ||
4886 | return 0; | |
4887 | } | |
4888 | ||
4889 | static int sec_wireless_get_property(struct power_supply *psy, | |
4890 | enum power_supply_property psp, | |
4891 | union power_supply_propval *val) | |
4892 | { | |
4893 | struct sec_battery_info *battery = | |
4894 | container_of(psy, struct sec_battery_info, psy_wireless); | |
4895 | ||
2a746c1b JC |
4896 | switch (psp) { |
4897 | case POWER_SUPPLY_PROP_ONLINE: | |
4898 | break; | |
4899 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: | |
4900 | /* V -> uV */ | |
4901 | val->intval = battery->input_voltage * 1000000; | |
4902 | return 0; | |
4903 | case POWER_SUPPLY_PROP_CURRENT_MAX: | |
4904 | /* mA -> uA */ | |
4905 | val->intval = battery->pdata->charging_current[battery->cable_type].input_current_limit * 1000; | |
4906 | return 0; | |
4907 | default: | |
3c2a0909 | 4908 | return -EINVAL; |
2a746c1b | 4909 | } |
3c2a0909 S |
4910 | |
4911 | if (battery->wc_status) | |
4912 | val->intval = 1; | |
4913 | else | |
4914 | val->intval = 0; | |
4915 | ||
4916 | return 0; | |
4917 | } | |
4918 | ||
4919 | static int sec_wireless_set_property(struct power_supply *psy, | |
4920 | enum power_supply_property psp, | |
4921 | const union power_supply_propval *val) | |
4922 | { | |
4923 | struct sec_battery_info *battery = | |
4924 | container_of(psy, struct sec_battery_info, psy_wireless); | |
4925 | ||
4926 | switch (psp) { | |
4927 | case POWER_SUPPLY_PROP_ONLINE: | |
4928 | battery->wc_status = val->intval; | |
4929 | ||
4930 | wake_lock(&battery->cable_wake_lock); | |
4931 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
4932 | &battery->cable_work, 0); | |
4933 | break; | |
4934 | #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) | |
4935 | case POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL: | |
4936 | if (battery->wc_status) { | |
4937 | union power_supply_propval value; | |
4938 | value.intval = val->intval; | |
4939 | psy_do_property(battery->pdata->wireless_charger_name, set, | |
4940 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, value); | |
4941 | } | |
4942 | break; | |
4943 | #endif | |
4944 | default: | |
4945 | return -EINVAL; | |
4946 | } | |
4947 | ||
4948 | return 0; | |
4949 | } | |
4950 | ||
4951 | static int sec_ps_set_property(struct power_supply *psy, | |
4952 | enum power_supply_property psp, | |
4953 | const union power_supply_propval *val) | |
4954 | { | |
4955 | struct sec_battery_info *battery = | |
4956 | container_of(psy, struct sec_battery_info, psy_ps); | |
4957 | union power_supply_propval value; | |
4958 | ||
4959 | switch (psp) { | |
4960 | case POWER_SUPPLY_PROP_STATUS: | |
4961 | if (val->intval == 0) { | |
4962 | if (battery->ps_enable == true) { | |
4963 | battery->ps_enable = val->intval; | |
4964 | dev_info(battery->dev, | |
4965 | "%s: power sharing cable set (%d)\n", __func__, battery->ps_enable); | |
4966 | value.intval = POWER_SUPPLY_TYPE_POWER_SHARING; | |
4967 | psy_do_property(battery->pdata->charger_name, set, | |
4968 | POWER_SUPPLY_PROP_ONLINE, value); | |
4969 | } | |
4970 | } else if ((val->intval == 1) && (battery->ps_status == true)) { | |
4971 | battery->ps_enable = val->intval; | |
4972 | dev_info(battery->dev, | |
4973 | "%s: power sharing cable set (%d)\n", __func__, battery->ps_enable); | |
4974 | value.intval = POWER_SUPPLY_TYPE_POWER_SHARING; | |
4975 | psy_do_property(battery->pdata->charger_name, set, | |
4976 | POWER_SUPPLY_PROP_ONLINE, value); | |
4977 | } else { | |
4978 | dev_err(battery->dev, | |
4979 | "%s: invalid setting (%d) ps_status (%d)\n", | |
4980 | __func__, val->intval, battery->ps_status); | |
4981 | } | |
4982 | break; | |
4983 | case POWER_SUPPLY_PROP_ONLINE: | |
4984 | if (val->intval == POWER_SUPPLY_TYPE_POWER_SHARING) { | |
4985 | battery->ps_status = true; | |
4986 | battery->ps_enable = true; | |
4987 | battery->ps_changed = true; | |
4988 | dev_info(battery->dev, | |
4989 | "%s: power sharing cable plugin (%d)\n", __func__, battery->ps_status); | |
4990 | wake_lock(&battery->monitor_wake_lock); | |
4991 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
4992 | } else { | |
4993 | battery->ps_status = false; | |
4994 | battery->ps_enable = false; | |
4995 | battery->ps_changed = false; | |
4996 | dev_info(battery->dev, | |
4997 | "%s: power sharing cable plugout (%d)\n", __func__, battery->ps_status); | |
4998 | wake_lock(&battery->monitor_wake_lock); | |
4999 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
5000 | } | |
5001 | break; | |
5002 | default: | |
5003 | return -EINVAL; | |
5004 | } | |
5005 | ||
5006 | return 0; | |
5007 | } | |
5008 | ||
5009 | static int sec_ps_get_property(struct power_supply *psy, | |
5010 | enum power_supply_property psp, | |
5011 | union power_supply_propval *val) | |
5012 | { | |
5013 | struct sec_battery_info *battery = | |
5014 | container_of(psy, struct sec_battery_info, psy_ps); | |
5015 | union power_supply_propval value; | |
5016 | ||
5017 | switch (psp) { | |
5018 | case POWER_SUPPLY_PROP_STATUS: | |
5019 | if (battery->ps_enable) | |
5020 | val->intval = 1; | |
5021 | else | |
5022 | val->intval = 0; | |
5023 | break; | |
5024 | case POWER_SUPPLY_PROP_ONLINE: | |
5025 | if (battery->ps_status) { | |
5026 | if ((battery->ps_enable == true) && (battery->ps_changed == true)) { | |
5027 | battery->ps_changed = false; | |
5028 | ||
5029 | value.intval = POWER_SUPPLY_TYPE_POWER_SHARING; | |
5030 | psy_do_property(battery->pdata->charger_name, set, | |
5031 | POWER_SUPPLY_PROP_ONLINE, value); | |
5032 | } | |
5033 | val->intval = 1; | |
5034 | } else { | |
5035 | if (battery->ps_enable == true) { | |
5036 | battery->ps_enable = false; | |
5037 | dev_info(battery->dev, | |
5038 | "%s: power sharing cable disconnected! ps disable (%d)\n", | |
5039 | __func__, battery->ps_enable); | |
5040 | ||
5041 | value.intval = POWER_SUPPLY_TYPE_POWER_SHARING; | |
5042 | psy_do_property(battery->pdata->charger_name, set, | |
5043 | POWER_SUPPLY_PROP_ONLINE, value); | |
5044 | } | |
5045 | val->intval = 0; | |
5046 | } | |
5047 | break; | |
5048 | default: | |
5049 | return -EINVAL; | |
5050 | } | |
5051 | ||
5052 | return 0; | |
5053 | } | |
5054 | ||
5055 | /* TODO unused */ | |
5056 | #if 0 | |
5057 | static irqreturn_t sec_bat_irq_thread(int irq, void *irq_data) | |
5058 | { | |
5059 | struct sec_battery_info *battery = irq_data; | |
5060 | ||
5061 | dev_info(battery->dev, "%s:(bat_irq occured_start\n", __func__); | |
5062 | ||
5063 | if (battery->pdata->cable_check_type & | |
5064 | SEC_BATTERY_CABLE_CHECK_INT) { | |
5065 | if (battery->pdata->is_interrupt_cable_check_possible && | |
5066 | !battery->pdata->is_interrupt_cable_check_possible( | |
5067 | battery->extended_cable_type)) | |
5068 | goto no_cable_check; | |
5069 | else { | |
5070 | if (sec_bat_get_cable_type(battery, | |
5071 | battery->pdata->cable_source_type)) { | |
5072 | wake_lock(&battery->cable_wake_lock); | |
5073 | queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0); | |
5074 | } | |
5075 | ||
5076 | return IRQ_HANDLED; | |
5077 | } | |
5078 | ||
5079 | no_cable_check: | |
5080 | if (battery->pdata->battery_check_type == | |
5081 | SEC_BATTERY_CHECK_INT) { | |
5082 | if (battery_pdata->check_battery_callback) | |
5083 | battery->present = battery->pdata->check_battery_callback(); | |
5084 | ||
5085 | wake_lock(&battery->monitor_wake_lock); | |
5086 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
5087 | } | |
5088 | ||
5089 | return IRQ_HANDLED; | |
5090 | } | |
5091 | #endif | |
5092 | ||
5093 | #if defined(CONFIG_MUIC_NOTIFIER) | |
5094 | static int sec_bat_cable_check(struct sec_battery_info *battery, | |
5095 | muic_attached_dev_t attached_dev) | |
5096 | { | |
5097 | int current_cable_type = -1; | |
5098 | union power_supply_propval val; | |
5099 | ||
5100 | pr_info("[%s]ATTACHED(%d)\n", __func__, attached_dev); | |
5101 | battery->is_jig_on = false; | |
5102 | ||
5103 | switch (attached_dev) | |
5104 | { | |
5105 | case ATTACHED_DEV_JIG_UART_OFF_MUIC: | |
5106 | case ATTACHED_DEV_JIG_UART_ON_MUIC: | |
5107 | battery->is_jig_on = true; | |
5108 | case ATTACHED_DEV_SMARTDOCK_MUIC: | |
5109 | case ATTACHED_DEV_DESKDOCK_MUIC: | |
5110 | current_cable_type = POWER_SUPPLY_TYPE_BATTERY; | |
5111 | break; | |
5112 | case ATTACHED_DEV_OTG_MUIC: | |
5113 | case ATTACHED_DEV_JIG_UART_OFF_VB_OTG_MUIC: | |
5114 | case ATTACHED_DEV_HMT_MUIC: | |
5115 | current_cable_type = POWER_SUPPLY_TYPE_OTG; | |
5116 | break; | |
5117 | case ATTACHED_DEV_USB_MUIC: | |
5118 | case ATTACHED_DEV_JIG_USB_OFF_MUIC: | |
5119 | case ATTACHED_DEV_JIG_USB_ON_MUIC: | |
5120 | case ATTACHED_DEV_SMARTDOCK_USB_MUIC: | |
5121 | case ATTACHED_DEV_UNOFFICIAL_ID_USB_MUIC: | |
5122 | current_cable_type = POWER_SUPPLY_TYPE_USB; | |
5123 | break; | |
5124 | case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC: | |
5125 | case ATTACHED_DEV_JIG_UART_OFF_VB_FG_MUIC: | |
5126 | current_cable_type = factory_mode ? POWER_SUPPLY_TYPE_BATTERY : | |
5127 | POWER_SUPPLY_TYPE_UARTOFF; | |
5128 | break; | |
5129 | case ATTACHED_DEV_TA_MUIC: | |
5130 | case ATTACHED_DEV_CARDOCK_MUIC: | |
5131 | case ATTACHED_DEV_DESKDOCK_VB_MUIC: | |
5132 | case ATTACHED_DEV_SMARTDOCK_TA_MUIC: | |
5133 | case ATTACHED_DEV_UNOFFICIAL_TA_MUIC: | |
5134 | case ATTACHED_DEV_UNOFFICIAL_ID_TA_MUIC: | |
5135 | case ATTACHED_DEV_UNOFFICIAL_ID_ANY_MUIC: | |
5136 | case ATTACHED_DEV_UNSUPPORTED_ID_VB_MUIC: | |
5137 | current_cable_type = POWER_SUPPLY_TYPE_MAINS; | |
5138 | break; | |
5139 | case ATTACHED_DEV_QC_CHARGER_5V_MUIC: | |
5140 | case ATTACHED_DEV_AFC_CHARGER_5V_MUIC: | |
5141 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
5142 | if (is_hv_wire_type(battery->cable_type) || battery->cable_type == POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT) | |
5143 | current_cable_type = POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT; | |
5144 | else | |
5145 | current_cable_type = POWER_SUPPLY_TYPE_MAINS; | |
5146 | #else | |
5147 | current_cable_type = POWER_SUPPLY_TYPE_MAINS; | |
5148 | #endif | |
5149 | break; | |
5150 | case ATTACHED_DEV_CDP_MUIC: | |
5151 | case ATTACHED_DEV_UNOFFICIAL_ID_CDP_MUIC: | |
5152 | current_cable_type = POWER_SUPPLY_TYPE_USB_CDP; | |
5153 | break; | |
5154 | case ATTACHED_DEV_USB_LANHUB_MUIC: | |
5155 | current_cable_type = POWER_SUPPLY_TYPE_LAN_HUB; | |
5156 | break; | |
5157 | case ATTACHED_DEV_CHARGING_CABLE_MUIC: | |
5158 | current_cable_type = POWER_SUPPLY_TYPE_POWER_SHARING; | |
5159 | break; | |
5160 | case ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC: | |
5161 | case ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC: | |
5162 | current_cable_type = POWER_SUPPLY_TYPE_HV_PREPARE_MAINS; | |
5163 | break; | |
5164 | case ATTACHED_DEV_AFC_CHARGER_9V_MUIC: | |
5165 | case ATTACHED_DEV_QC_CHARGER_9V_MUIC: | |
5166 | current_cable_type = POWER_SUPPLY_TYPE_HV_MAINS; | |
5167 | break; | |
5168 | case ATTACHED_DEV_AFC_CHARGER_ERR_V_MUIC: | |
5169 | case ATTACHED_DEV_QC_CHARGER_ERR_V_MUIC: | |
5170 | current_cable_type = POWER_SUPPLY_TYPE_HV_ERR; | |
5171 | break; | |
5172 | case ATTACHED_DEV_UNDEFINED_CHARGING_MUIC: | |
5173 | current_cable_type = POWER_SUPPLY_TYPE_MAINS; | |
5174 | break; | |
5175 | case ATTACHED_DEV_HV_ID_ERR_UNDEFINED_MUIC: | |
5176 | case ATTACHED_DEV_HV_ID_ERR_UNSUPPORTED_MUIC: | |
5177 | case ATTACHED_DEV_HV_ID_ERR_SUPPORTED_MUIC: | |
5178 | current_cable_type = POWER_SUPPLY_TYPE_HV_UNKNOWN; | |
5179 | break; | |
5180 | case ATTACHED_DEV_VZW_INCOMPATIBLE_MUIC: | |
5181 | current_cable_type = POWER_SUPPLY_TYPE_UNKNOWN; | |
5182 | break; | |
5183 | default: | |
5184 | pr_err("%s: invalid type for charger:%d\n", | |
5185 | __func__, attached_dev); | |
5186 | } | |
5187 | #ifndef CONFIG_FUELGAUGE_S2MU005 | |
5188 | if (battery->is_jig_on) | |
5189 | psy_do_property(battery->pdata->fuelgauge_name, set, | |
5190 | POWER_SUPPLY_PROP_ENERGY_NOW, val); | |
5191 | #endif | |
5192 | ||
5193 | val.intval = battery->is_jig_on; | |
5194 | psy_do_property(battery->pdata->charger_name, set, | |
5195 | POWER_SUPPLY_PROP_ENERGY_NOW, val); | |
5196 | ||
5197 | return current_cable_type; | |
5198 | ||
5199 | } | |
5200 | ||
5201 | static int batt_handle_notification(struct notifier_block *nb, | |
5202 | unsigned long action, void *data) | |
5203 | { | |
5204 | muic_attached_dev_t attached_dev = *(muic_attached_dev_t *)data; | |
5205 | const char *cmd; | |
5206 | int cable_type; | |
5207 | struct sec_battery_info *battery = | |
5208 | container_of(nb, struct sec_battery_info, | |
5209 | batt_nb); | |
5210 | union power_supply_propval value; | |
5211 | ||
5212 | switch (action) { | |
5213 | case MUIC_NOTIFY_CMD_DETACH: | |
5214 | case MUIC_NOTIFY_CMD_LOGICALLY_DETACH: | |
5215 | cmd = "DETACH"; | |
5216 | cable_type = POWER_SUPPLY_TYPE_BATTERY; | |
5217 | battery->muic_cable_type = ATTACHED_DEV_NONE_MUIC; | |
5218 | break; | |
5219 | case MUIC_NOTIFY_CMD_ATTACH: | |
5220 | case MUIC_NOTIFY_CMD_LOGICALLY_ATTACH: | |
5221 | cmd = "ATTACH"; | |
5222 | cable_type = sec_bat_cable_check(battery, attached_dev); | |
5223 | battery->muic_cable_type = attached_dev; | |
5224 | break; | |
5225 | default: | |
5226 | cmd = "ERROR"; | |
5227 | cable_type = -1; | |
5228 | battery->muic_cable_type = ATTACHED_DEV_NONE_MUIC; | |
5229 | break; | |
5230 | } | |
5231 | ||
5232 | if (attached_dev == ATTACHED_DEV_MHL_MUIC) | |
5233 | return 0; | |
5234 | ||
5235 | if (cable_type < 0) { | |
5236 | dev_info(battery->dev, "%s: ignore event(%d)\n", | |
5237 | __func__, cable_type); | |
5238 | } else if (cable_type == POWER_SUPPLY_TYPE_POWER_SHARING) { | |
5239 | battery->ps_status = true; | |
5240 | battery->ps_enable = true; | |
5241 | battery->ps_changed = true; | |
5242 | ||
5243 | dev_info(battery->dev, | |
5244 | "%s: power sharing cable plugin (%d)\n", __func__, battery->ps_status); | |
5245 | } else if (cable_type == POWER_SUPPLY_TYPE_WIRELESS) { | |
5246 | battery->wc_status = true; | |
5247 | } else if ((cable_type == POWER_SUPPLY_TYPE_UNKNOWN) && | |
5248 | (battery->status != POWER_SUPPLY_STATUS_DISCHARGING)) { | |
5249 | battery->cable_type = cable_type; | |
5250 | wake_lock(&battery->monitor_wake_lock); | |
5251 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
5252 | dev_info(battery->dev, | |
5253 | "%s: UNKNOWN cable plugin\n", __func__); | |
5254 | return 0; | |
5255 | } else { | |
5256 | battery->wire_status = cable_type; | |
5257 | if ((battery->wire_status == POWER_SUPPLY_TYPE_BATTERY) | |
5258 | && battery->wc_status && !battery->ps_status) | |
5259 | cable_type = POWER_SUPPLY_TYPE_WIRELESS; | |
5260 | } | |
5261 | dev_info(battery->dev, | |
5262 | "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n", | |
5263 | __func__, cable_type, battery->wc_status, | |
5264 | battery->wire_status); | |
5265 | ||
5266 | if (attached_dev == ATTACHED_DEV_USB_LANHUB_MUIC) { | |
5267 | if (!strcmp(cmd, "ATTACH")) { | |
5268 | value.intval = true; | |
5269 | psy_do_property(battery->pdata->charger_name, set, | |
5270 | POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL, | |
5271 | value); | |
5272 | dev_info(battery->dev, | |
5273 | "%s: Powered OTG cable attached\n", __func__); | |
5274 | } else { | |
5275 | value.intval = false; | |
5276 | psy_do_property(battery->pdata->charger_name, set, | |
5277 | POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL, | |
5278 | value); | |
5279 | dev_info(battery->dev, | |
5280 | "%s: Powered OTG cable detached\n", __func__); | |
5281 | } | |
5282 | } | |
5283 | ||
5284 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
5285 | if (!strcmp(cmd, "ATTACH")) { | |
5286 | if ((battery->muic_cable_type >= ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC) && | |
5287 | (battery->muic_cable_type <= ATTACHED_DEV_QC_CHARGER_9V_MUIC)) | |
5288 | battery->hv_chg_name = "QC"; | |
5289 | else if ((battery->muic_cable_type >= ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC) && | |
5290 | (battery->muic_cable_type <= ATTACHED_DEV_AFC_CHARGER_ERR_V_DUPLI_MUIC)) | |
5291 | battery->hv_chg_name = "AFC"; | |
5292 | else | |
5293 | battery->hv_chg_name = "NONE"; | |
5294 | } else { | |
5295 | battery->hv_chg_name = "NONE"; | |
5296 | } | |
5297 | ||
5298 | pr_info("%s : HV_CHARGER_NAME(%s)\n", | |
5299 | __func__, battery->hv_chg_name); | |
5300 | #endif | |
5301 | ||
5302 | if ((cable_type >= 0) && | |
5303 | cable_type <= SEC_SIZEOF_POWER_SUPPLY_TYPE) { | |
5304 | if ((cable_type == POWER_SUPPLY_TYPE_POWER_SHARING) | |
5305 | || (cable_type == POWER_SUPPLY_TYPE_OTG)) { | |
5306 | wake_lock(&battery->monitor_wake_lock); | |
5307 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
5308 | } else if((cable_type == POWER_SUPPLY_TYPE_BATTERY) | |
5309 | && battery->ps_status) { | |
5310 | battery->ps_status = false; | |
5311 | dev_info(battery->dev, | |
5312 | "%s: power sharing cable plugout (%d)\n", __func__, battery->ps_status); | |
5313 | wake_lock(&battery->monitor_wake_lock); | |
5314 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
5315 | } else if(cable_type != battery->cable_type) { | |
5316 | wake_lock(&battery->cable_wake_lock); | |
5317 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
5318 | &battery->cable_work, 0); | |
5319 | } else { | |
5320 | dev_info(battery->dev, | |
5321 | "%s: Cable is Not Changed(%d)\n", | |
5322 | __func__, battery->cable_type); | |
5323 | } | |
5324 | } | |
5325 | ||
5326 | pr_info("%s: CMD=%s, attached_dev=%d\n", __func__, cmd, attached_dev); | |
5327 | ||
5328 | return 0; | |
5329 | } | |
5330 | #endif /* CONFIG_MUIC_NOTIFIER */ | |
5331 | ||
5332 | #if defined(CONFIG_VBUS_NOTIFIER) | |
5333 | static int vbus_handle_notification(struct notifier_block *nb, | |
5334 | unsigned long action, void *data) | |
5335 | { | |
5336 | vbus_status_t vbus_status = *(vbus_status_t *)data; | |
5337 | struct sec_battery_info *battery = | |
5338 | container_of(nb, struct sec_battery_info, | |
5339 | vbus_nb); | |
5340 | union power_supply_propval value; | |
5341 | ||
5342 | if (battery->muic_cable_type == ATTACHED_DEV_HMT_MUIC && | |
5343 | battery->muic_vbus_status != vbus_status && | |
5344 | battery->muic_vbus_status == STATUS_VBUS_HIGH && | |
5345 | vbus_status == STATUS_VBUS_LOW) { | |
5346 | sec_bat_set_charge(battery, false); | |
5347 | msleep(500); | |
5348 | value.intval = true; | |
5349 | psy_do_property(battery->pdata->charger_name, set, | |
5350 | POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL, | |
5351 | value); | |
5352 | dev_info(battery->dev, | |
5353 | "%s: changed to OTG cable attached\n", __func__); | |
5354 | ||
5355 | battery->wire_status = POWER_SUPPLY_TYPE_OTG; | |
5356 | wake_lock(&battery->cable_wake_lock); | |
5357 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->cable_work, 0); | |
5358 | } | |
5359 | pr_info("%s: action=%d, vbus_status=%d\n", __func__, (int)action, vbus_status); | |
5360 | battery->muic_vbus_status = vbus_status; | |
5361 | ||
5362 | return 0; | |
5363 | } | |
5364 | #endif | |
5365 | ||
5366 | ||
5367 | #ifdef CONFIG_OF | |
5368 | static int sec_bat_parse_dt(struct device *dev, | |
5369 | struct sec_battery_info *battery) | |
5370 | { | |
5371 | struct device_node *np = dev->of_node; | |
5372 | sec_battery_platform_data_t *pdata = battery->pdata; | |
5373 | int ret, len; | |
5374 | unsigned int i; | |
5375 | const u32 *p; | |
5376 | u32 temp = 0; | |
5377 | ||
5378 | if (!np) { | |
5379 | pr_info("%s: np NULL\n", __func__); | |
5380 | return 1; | |
5381 | } | |
5382 | ||
5383 | pdata->wchg_ctl_en = of_property_read_bool(np, | |
5384 | "battery,wchg_ctl_en"); | |
5385 | if (pdata->wchg_ctl_en) | |
5386 | pdata->wchg_ctl = of_get_named_gpio(np, "battery,wchg_ctl", 0); | |
5387 | ||
5388 | ret = of_property_read_string(np, | |
5389 | "battery,vendor", (char const **)&pdata->vendor); | |
5390 | if (ret) | |
5391 | pr_info("%s: Vendor is Empty\n", __func__); | |
5392 | ||
5393 | ret = of_property_read_string(np, | |
5394 | "battery,charger_name", (char const **)&pdata->charger_name); | |
5395 | if (ret) | |
5396 | pr_info("%s: Vendor is Empty\n", __func__); | |
5397 | ||
5398 | ret = of_property_read_string(np, | |
5399 | "battery,fuelgauge_name", (char const **)&pdata->fuelgauge_name); | |
5400 | if (ret) | |
5401 | pr_info("%s: Vendor is Empty\n", __func__); | |
5402 | ||
5403 | ret = of_property_read_string(np, | |
5404 | "battery,wirelss_charger_name", (char const **)&pdata->wireless_charger_name); | |
5405 | if (ret) | |
5406 | pr_info("%s: Vendor is Empty\n", __func__); | |
5407 | ||
5408 | ret = of_property_read_string(np, | |
5409 | "battery,chip_vendor", (char const **)&pdata->chip_vendor); | |
5410 | if (ret) | |
5411 | pr_info("%s: Vendor is Empty\n", __func__); | |
5412 | ||
5413 | ret = of_property_read_u32(np, "battery,technology", | |
5414 | &pdata->technology); | |
5415 | if (ret) | |
5416 | pr_info("%s : technology is Empty\n", __func__); | |
5417 | ||
5418 | ret = of_property_read_u32(np, | |
5419 | "battery,wireless_cc_cv", &pdata->wireless_cc_cv); | |
5420 | ||
5421 | pdata->fake_capacity = of_property_read_bool(np, | |
5422 | "battery,fake_capacity"); | |
5423 | ||
5424 | pdata->event_check = of_property_read_bool(np, | |
5425 | "battery,event_check"); | |
5426 | ||
5427 | p = of_get_property(np, "battery,polling_time", &len); | |
5428 | if (!p) | |
5429 | return 1; | |
5430 | ||
5431 | len = len / sizeof(u32); | |
5432 | pdata->polling_time = kzalloc(sizeof(*pdata->polling_time) * len, GFP_KERNEL); | |
5433 | ret = of_property_read_u32_array(np, "battery,polling_time", | |
5434 | pdata->polling_time, len); | |
5435 | ||
5436 | ret = of_property_read_u32(np, "battery,thermal_source", | |
5437 | &pdata->thermal_source); | |
5438 | if (ret) | |
5439 | pr_info("%s : Thermal source is Empty\n", __func__); | |
5440 | ||
5441 | if (pdata->thermal_source == SEC_BATTERY_THERMAL_SOURCE_ADC) { | |
5442 | p = of_get_property(np, "battery,temp_table_adc", &len); | |
5443 | if (!p) | |
5444 | return 1; | |
5445 | ||
5446 | len = len / sizeof(u32); | |
5447 | ||
5448 | pdata->temp_adc_table_size = len; | |
5449 | pdata->temp_amb_adc_table_size = len; | |
5450 | ||
5451 | pdata->temp_adc_table = | |
5452 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
5453 | pdata->temp_adc_table_size, GFP_KERNEL); | |
5454 | pdata->temp_amb_adc_table = | |
5455 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
5456 | pdata->temp_adc_table_size, GFP_KERNEL); | |
5457 | ||
5458 | for(i = 0; i < pdata->temp_adc_table_size; i++) { | |
5459 | ret = of_property_read_u32_index(np, | |
5460 | "battery,temp_table_adc", i, &temp); | |
5461 | pdata->temp_adc_table[i].adc = (int)temp; | |
5462 | if (ret) | |
5463 | pr_info("%s : Temp_adc_table(adc) is Empty\n", | |
5464 | __func__); | |
5465 | ||
5466 | ret = of_property_read_u32_index(np, | |
5467 | "battery,temp_table_data", i, &temp); | |
5468 | pdata->temp_adc_table[i].data = (int)temp; | |
5469 | if (ret) | |
5470 | pr_info("%s : Temp_adc_table(data) is Empty\n", | |
5471 | __func__); | |
5472 | ||
5473 | ret = of_property_read_u32_index(np, | |
5474 | "battery,temp_table_adc", i, &temp); | |
5475 | pdata->temp_amb_adc_table[i].adc = (int)temp; | |
5476 | if (ret) | |
5477 | pr_info("%s : Temp_amb_adc_table(adc) is Empty\n", | |
5478 | __func__); | |
5479 | ||
5480 | ret = of_property_read_u32_index(np, | |
5481 | "battery,temp_table_data", i, &temp); | |
5482 | pdata->temp_amb_adc_table[i].data = (int)temp; | |
5483 | if (ret) | |
5484 | pr_info("%s : Temp_amb_adc_table(data) is Empty\n", | |
5485 | __func__); | |
5486 | } | |
5487 | ||
5488 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
5489 | p = of_get_property(np, "battery,chg_temp_table_adc", &len); | |
5490 | if (!p) | |
5491 | return 1; | |
5492 | ||
5493 | len = len / sizeof(u32); | |
5494 | ||
5495 | pdata->chg_temp_adc_table_size = len; | |
5496 | ||
5497 | pdata->chg_temp_adc_table = | |
5498 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
5499 | pdata->chg_temp_adc_table_size, GFP_KERNEL); | |
5500 | ||
5501 | for(i = 0; i < pdata->chg_temp_adc_table_size; i++) { | |
5502 | ret = of_property_read_u32_index(np, | |
5503 | "battery,chg_temp_table_adc", i, &temp); | |
5504 | pdata->chg_temp_adc_table[i].adc = (int)temp; | |
5505 | if (ret) | |
5506 | pr_info("%s : CHG_Temp_adc_table(adc) is Empty\n", | |
5507 | __func__); | |
5508 | ||
5509 | ret = of_property_read_u32_index(np, | |
5510 | "battery,chg_temp_table_data", i, &temp); | |
5511 | pdata->chg_temp_adc_table[i].data = (int)temp; | |
5512 | if (ret) | |
5513 | pr_info("%s : CHG_Temp_adc_table(data) is Empty\n", | |
5514 | __func__); | |
5515 | } | |
5516 | #endif | |
5517 | } | |
5518 | ||
5519 | ret = of_property_read_u32(np, "battery,chg_temp_check", | |
5520 | &pdata->chg_temp_check); | |
5521 | if (ret) | |
5522 | pr_info("%s : chg_temp_check is Empty\n", __func__); | |
5523 | ||
5524 | if (pdata->chg_temp_check) { | |
5525 | ret = of_property_read_u32(np, "battery,chg_high_temp_1st", | |
5526 | &temp); | |
5527 | pdata->chg_high_temp_1st = (int)temp; | |
5528 | if (ret) | |
5529 | pr_info("%s : chg_high_temp_threshold is Empty\n", __func__); | |
5530 | ||
5531 | ret = of_property_read_u32(np, "battery,chg_high_temp_2nd", | |
5532 | &temp); | |
5533 | pdata->chg_high_temp_2nd = (int)temp; | |
5534 | if (ret) | |
5535 | pr_info("%s : chg_high_temp_threshold is Empty\n", __func__); | |
5536 | ||
5537 | ret = of_property_read_u32(np, "battery,chg_high_temp_recovery", | |
5538 | &temp); | |
5539 | pdata->chg_high_temp_recovery = (int)temp; | |
5540 | if (ret) | |
5541 | pr_info("%s : chg_temp_recovery is Empty\n", __func__); | |
5542 | ||
5543 | ret = of_property_read_u32(np, "battery,chg_charging_limit_current", | |
5544 | &pdata->chg_charging_limit_current); | |
5545 | if (ret) | |
5546 | pr_info("%s : chg_charging_limit_current is Empty\n", __func__); | |
5547 | ||
5548 | ret = of_property_read_u32(np, "battery,chg_charging_limit_current_2nd", | |
5549 | &pdata->chg_charging_limit_current_2nd); | |
5550 | if (ret) | |
5551 | pr_info("%s : chg_charging_limit_current_2nd is Empty\n", __func__); | |
5552 | ||
5553 | ret = of_property_read_u32(np, "battery,chg_skip_check_time", | |
5554 | &pdata->chg_skip_check_time); | |
5555 | if (ret) | |
5556 | pr_info("%s : chg_skip_check_time is Empty\n", __func__); | |
5557 | ||
5558 | ret = of_property_read_u32(np, "battery,chg_skip_check_capacity", | |
5559 | &pdata->chg_skip_check_capacity); | |
5560 | if (ret) | |
5561 | pr_info("%s : chg_skip_check_capacity is Empty\n", __func__); | |
5562 | ||
5563 | ret = of_property_read_u32(np, "battery,wpc_temp_check", | |
5564 | &pdata->wpc_temp_check); | |
5565 | if (ret) | |
5566 | pr_info("%s : wpc_temp_check is Empty\n", __func__); | |
5567 | ||
5568 | if (pdata->wpc_temp_check) { | |
5569 | ret = of_property_read_u32(np, "battery,wpc_high_temp", | |
5570 | &temp); | |
5571 | pdata->wpc_high_temp = (int)temp; | |
5572 | if (ret) | |
5573 | pr_info("%s : wpc_high_temp is Empty\n", __func__); | |
5574 | ||
5575 | ret = of_property_read_u32(np, "battery,wpc_high_temp_recovery", | |
5576 | &temp); | |
5577 | pdata->wpc_high_temp_recovery = (int)temp; | |
5578 | if (ret) | |
5579 | pr_info("%s : wpc_high_temp_recovery is Empty\n", __func__); | |
5580 | ||
5581 | ret = of_property_read_u32(np, "battery,wpc_charging_limit_current", | |
5582 | &pdata->wpc_charging_limit_current); | |
5583 | if (ret) | |
5584 | pr_info("%s : wpc_charging_limit_current is Empty\n", __func__); | |
5585 | } | |
5586 | } | |
5587 | ||
5588 | ret = of_property_read_u32(np, "battery,inbat_voltage", | |
5589 | &pdata->inbat_voltage); | |
5590 | if (ret) | |
5591 | pr_info("%s : inbat_voltage is Empty\n", __func__); | |
5592 | ||
5593 | if (pdata->inbat_voltage) { | |
5594 | p = of_get_property(np, "battery,inbat_voltage_table_adc", &len); | |
5595 | if (!p) | |
5596 | return 1; | |
5597 | ||
5598 | len = len / sizeof(u32); | |
5599 | ||
5600 | pdata->inbat_adc_table_size = len; | |
5601 | ||
5602 | pdata->inbat_adc_table = | |
5603 | kzalloc(sizeof(sec_bat_adc_table_data_t) * | |
5604 | pdata->inbat_adc_table_size, GFP_KERNEL); | |
5605 | ||
5606 | for(i = 0; i < pdata->inbat_adc_table_size; i++) { | |
5607 | ret = of_property_read_u32_index(np, | |
5608 | "battery,inbat_voltage_table_adc", i, &temp); | |
5609 | pdata->inbat_adc_table[i].adc = (int)temp; | |
5610 | if (ret) | |
5611 | pr_info("%s : inbat_adc_table(adc) is Empty\n", | |
5612 | __func__); | |
5613 | ||
5614 | ret = of_property_read_u32_index(np, | |
5615 | "battery,inbat_voltage_table_data", i, &temp); | |
5616 | pdata->inbat_adc_table[i].data = (int)temp; | |
5617 | if (ret) | |
5618 | pr_info("%s : inbat_adc_table(data) is Empty\n", | |
5619 | __func__); | |
5620 | } | |
5621 | } | |
5622 | ||
5623 | p = of_get_property(np, "battery,input_current_limit", &len); | |
5624 | if (!p) | |
5625 | return 1; | |
5626 | ||
5627 | len = len / sizeof(u32); | |
5628 | ||
5629 | pdata->charging_current = | |
5630 | kzalloc(sizeof(sec_charging_current_t) * len, | |
5631 | GFP_KERNEL); | |
5632 | ||
5633 | for(i = 0; i < len; i++) { | |
5634 | ret = of_property_read_u32_index(np, | |
5635 | "battery,input_current_limit", i, | |
5636 | &pdata->charging_current[i].input_current_limit); | |
5637 | if (ret) | |
5638 | pr_info("%s : Input_current_limit is Empty\n", | |
5639 | __func__); | |
5640 | ||
5641 | ret = of_property_read_u32_index(np, | |
5642 | "battery,fast_charging_current", i, | |
5643 | &pdata->charging_current[i].fast_charging_current); | |
5644 | if (ret) | |
5645 | pr_info("%s : Fast charging current is Empty\n", | |
5646 | __func__); | |
5647 | ||
5648 | ret = of_property_read_u32_index(np, | |
5649 | "battery,full_check_current_1st", i, | |
5650 | &pdata->charging_current[i].full_check_current_1st); | |
5651 | if (ret) | |
5652 | pr_info("%s : Full check current 1st is Empty\n", | |
5653 | __func__); | |
5654 | ||
5655 | ret = of_property_read_u32_index(np, | |
5656 | "battery,full_check_current_2nd", i, | |
5657 | &pdata->charging_current[i].full_check_current_2nd); | |
5658 | if (ret) | |
5659 | pr_info("%s : Full check current 2nd is Empty\n", | |
5660 | __func__); | |
5661 | } | |
5662 | ||
5663 | ret = of_property_read_u32(np, "battery,adc_check_count", | |
5664 | &pdata->adc_check_count); | |
5665 | if (ret) | |
5666 | pr_info("%s : Adc check count is Empty\n", __func__); | |
5667 | ||
5668 | ret = of_property_read_u32(np, "battery,temp_adc_type", | |
5669 | &pdata->temp_adc_type); | |
5670 | if (ret) | |
5671 | pr_info("%s : Temp adc type is Empty\n", __func__); | |
5672 | ||
5673 | ret = of_property_read_u32(np, "battery,cable_check_type", | |
5674 | &pdata->cable_check_type); | |
5675 | if (ret) | |
5676 | pr_info("%s : Cable check type is Empty\n", __func__); | |
5677 | ||
5678 | ret = of_property_read_u32(np, "battery,cable_source_type", | |
5679 | &pdata->cable_source_type); | |
5680 | #if defined(CONFIG_CHARGING_VZWCONCEPT) | |
5681 | pdata->cable_check_type &= ~SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE; | |
5682 | pdata->cable_check_type |= SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE; | |
5683 | #endif | |
5684 | if (ret) | |
5685 | pr_info("%s : Cable source type is Empty\n", __func__); | |
5686 | ||
5687 | ret = of_property_read_u32(np, "battery,event_waiting_time", | |
5688 | &pdata->event_waiting_time); | |
5689 | if (ret) | |
5690 | pr_info("%s : Event waiting time is Empty\n", __func__); | |
5691 | ||
5692 | ret = of_property_read_u32(np, "battery,polling_type", | |
5693 | &pdata->polling_type); | |
5694 | if (ret) | |
5695 | pr_info("%s : Polling type is Empty\n", __func__); | |
5696 | ||
5697 | ret = of_property_read_u32(np, "battery,monitor_initial_count", | |
5698 | &pdata->monitor_initial_count); | |
5699 | if (ret) | |
5700 | pr_info("%s : Monitor initial count is Empty\n", __func__); | |
5701 | ||
5702 | ret = of_property_read_u32(np, "battery,battery_check_type", | |
5703 | &pdata->battery_check_type); | |
5704 | if (ret) | |
5705 | pr_info("%s : Battery check type is Empty\n", __func__); | |
5706 | ||
5707 | ret = of_property_read_u32(np, "battery,check_count", | |
5708 | &pdata->check_count); | |
5709 | if (ret) | |
5710 | pr_info("%s : Check count is Empty\n", __func__); | |
5711 | ||
5712 | ret = of_property_read_u32(np, "battery,check_adc_max", | |
5713 | &pdata->check_adc_max); | |
5714 | if (ret) | |
5715 | pr_info("%s : Check adc max is Empty\n", __func__); | |
5716 | ||
5717 | ret = of_property_read_u32(np, "battery,check_adc_min", | |
5718 | &pdata->check_adc_min); | |
5719 | if (ret) | |
5720 | pr_info("%s : Check adc min is Empty\n", __func__); | |
5721 | ||
5722 | ret = of_property_read_u32(np, "battery,ovp_uvlo_check_type", | |
5723 | &pdata->ovp_uvlo_check_type); | |
5724 | if (ret) | |
5725 | pr_info("%s : Ovp Uvlo check type is Empty\n", __func__); | |
5726 | ||
5727 | ret = of_property_read_u32(np, "battery,temp_check_type", | |
5728 | &pdata->temp_check_type); | |
5729 | if (ret) | |
5730 | pr_info("%s : Temp check type is Empty\n", __func__); | |
5731 | ||
5732 | ret = of_property_read_u32(np, "battery,temp_check_count", | |
5733 | &pdata->temp_check_count); | |
5734 | if (ret) | |
5735 | pr_info("%s : Temp check count is Empty\n", __func__); | |
5736 | ||
5737 | ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_event", | |
5738 | &temp); | |
5739 | pdata->temp_highlimit_threshold_event = (int)temp; | |
5740 | if (ret) | |
5741 | pr_info("%s : Temp highlimit threshold event is Empty\n", __func__); | |
5742 | ||
5743 | ret = of_property_read_u32(np, "battery,temp_highlimit_recovery_event", | |
5744 | &temp); | |
5745 | pdata->temp_highlimit_recovery_event = (int)temp; | |
5746 | if (ret) | |
5747 | pr_info("%s : Temp highlimit recovery event is Empty\n", __func__); | |
5748 | ||
5749 | ret = of_property_read_u32(np, "battery,temp_high_threshold_event", | |
5750 | &temp); | |
5751 | pdata->temp_high_threshold_event = (int)temp; | |
5752 | if (ret) | |
5753 | pr_info("%s : Temp high threshold event is Empty\n", __func__); | |
5754 | ||
5755 | ret = of_property_read_u32(np, "battery,temp_high_recovery_event", | |
5756 | &temp); | |
5757 | pdata->temp_high_recovery_event = (int)temp; | |
5758 | if (ret) | |
5759 | pr_info("%s : Temp high recovery event is Empty\n", __func__); | |
5760 | ||
5761 | ret = of_property_read_u32(np, "battery,temp_low_threshold_event", | |
5762 | &temp); | |
5763 | pdata->temp_low_threshold_event = (int)temp; | |
5764 | if (ret) | |
5765 | pr_info("%s : Temp low threshold event is Empty\n", __func__); | |
5766 | ||
5767 | ret = of_property_read_u32(np, "battery,temp_low_recovery_event", | |
5768 | &temp); | |
5769 | pdata->temp_low_recovery_event = (int)temp; | |
5770 | if (ret) | |
5771 | pr_info("%s : Temp low recovery event is Empty\n", __func__); | |
5772 | ||
5773 | ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_normal", | |
5774 | &temp); | |
5775 | pdata->temp_highlimit_threshold_normal = (int)temp; | |
5776 | if (ret) | |
5777 | pr_info("%s : Temp highlimit threshold normal is Empty\n", __func__); | |
5778 | ||
5779 | ret = of_property_read_u32(np, "battery,temp_highlimit_recovery_normal", | |
5780 | &temp); | |
5781 | pdata->temp_highlimit_recovery_normal = (int)temp; | |
5782 | if (ret) | |
5783 | pr_info("%s : Temp highlimit recovery normal is Empty\n", __func__); | |
5784 | ||
5785 | ret = of_property_read_u32(np, "battery,temp_high_threshold_normal", | |
5786 | &temp); | |
5787 | pdata->temp_high_threshold_normal = (int)temp; | |
5788 | if (ret) | |
5789 | pr_info("%s : Temp high threshold normal is Empty\n", __func__); | |
5790 | ||
5791 | ret = of_property_read_u32(np, "battery,temp_high_recovery_normal", | |
5792 | &temp); | |
5793 | pdata->temp_high_recovery_normal = (int)temp; | |
5794 | if (ret) | |
5795 | pr_info("%s : Temp high recovery normal is Empty\n", __func__); | |
5796 | ||
5797 | ret = of_property_read_u32(np, "battery,temp_low_threshold_normal", | |
5798 | &temp); | |
5799 | pdata->temp_low_threshold_normal = (int)temp; | |
5800 | if (ret) | |
5801 | pr_info("%s : Temp low threshold normal is Empty\n", __func__); | |
5802 | ||
5803 | ret = of_property_read_u32(np, "battery,temp_low_recovery_normal", | |
5804 | &temp); | |
5805 | pdata->temp_low_recovery_normal = (int)temp; | |
5806 | if (ret) | |
5807 | pr_info("%s : Temp low recovery normal is Empty\n", __func__); | |
5808 | ||
5809 | ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_lpm", | |
5810 | &temp); | |
5811 | pdata->temp_highlimit_threshold_lpm = (int)temp; | |
5812 | if (ret) | |
5813 | pr_info("%s : Temp highlimit threshold lpm is Empty\n", __func__); | |
5814 | ||
5815 | ret = of_property_read_u32(np, "battery,temp_highlimit_recovery_lpm", | |
5816 | &temp); | |
5817 | pdata->temp_highlimit_recovery_lpm = (int)temp; | |
5818 | if (ret) | |
5819 | pr_info("%s : Temp highlimit recovery lpm is Empty\n", __func__); | |
5820 | ||
5821 | ret = of_property_read_u32(np, "battery,temp_high_threshold_lpm", | |
5822 | &temp); | |
5823 | pdata->temp_high_threshold_lpm = (int)temp; | |
5824 | if (ret) | |
5825 | pr_info("%s : Temp high threshold lpm is Empty\n", __func__); | |
5826 | ||
5827 | ret = of_property_read_u32(np, "battery,temp_high_recovery_lpm", | |
5828 | &temp); | |
5829 | pdata->temp_high_recovery_lpm = (int)temp; | |
5830 | if (ret) | |
5831 | pr_info("%s : Temp high recovery lpm is Empty\n", __func__); | |
5832 | ||
5833 | ret = of_property_read_u32(np, "battery,temp_low_threshold_lpm", | |
5834 | &temp); | |
5835 | pdata->temp_low_threshold_lpm = (int)temp; | |
5836 | if (ret) | |
5837 | pr_info("%s : Temp low threshold lpm is Empty\n", __func__); | |
5838 | ||
5839 | ret = of_property_read_u32(np, "battery,temp_low_recovery_lpm", | |
5840 | &temp); | |
5841 | pdata->temp_low_recovery_lpm = (int)temp; | |
5842 | if (ret) | |
5843 | pr_info("%s : Temp low recovery lpm is Empty\n", __func__); | |
5844 | ||
5845 | pr_info("%s : HIGHLIMIT_THRESHOLD_EVENT(%d), HIGHLIMIT_RECOVERY_EVENT(%d)\n" | |
5846 | "HIGH_THRESHOLD_EVENT(%d), HIGH_RECOVERY_EVENT(%d) LOW_THRESHOLD_EVENT(%d), LOW_RECOVERY_EVENT(%d)\n" | |
5847 | "HIGHLIMIT_THRESHOLD_NOLMAL(%d), HIGHLIMIT_RECOVERY_NORMAL(%d)\n" | |
5848 | "HIGH_THRESHOLD_NORMAL(%d), HIGH_RECOVERY_NORMAL(%d) LOW_THRESHOLD_NORMAL(%d), LOW_RECOVERY_NORMAL(%d)\n" | |
5849 | "HIGHLIMIT_THRESHOLD_LPM(%d), HIGHLIMIT_RECOVERY_LPM(%d)\n" | |
5850 | "HIGH_THRESHOLD_LPM(%d), HIGH_RECOVERY_LPM(%d) LOW_THRESHOLD_LPM(%d), LOW_RECOVERY_LPM(%d)\n", | |
5851 | __func__, pdata->temp_highlimit_threshold_event, pdata->temp_highlimit_recovery_event, | |
5852 | pdata->temp_high_threshold_event, pdata->temp_high_recovery_event, | |
5853 | pdata->temp_low_threshold_event, pdata->temp_low_recovery_event, | |
5854 | pdata->temp_highlimit_threshold_normal, pdata->temp_highlimit_recovery_normal, | |
5855 | pdata->temp_high_threshold_normal, pdata->temp_high_recovery_normal, | |
5856 | pdata->temp_low_threshold_normal, pdata->temp_low_recovery_normal, | |
5857 | pdata->temp_highlimit_threshold_lpm, pdata->temp_highlimit_recovery_lpm, | |
5858 | pdata->temp_high_threshold_lpm, pdata->temp_high_recovery_lpm, | |
5859 | pdata->temp_low_threshold_lpm, pdata->temp_low_recovery_lpm); | |
5860 | ||
5861 | ret = of_property_read_u32(np, "battery,full_check_type", | |
5862 | &pdata->full_check_type); | |
5863 | if (ret) | |
5864 | pr_info("%s : Full check type is Empty\n", __func__); | |
5865 | ||
5866 | ret = of_property_read_u32(np, "battery,full_check_type_2nd", | |
5867 | &pdata->full_check_type_2nd); | |
5868 | if (ret) | |
5869 | pr_info("%s : Full check type 2nd is Empty\n", __func__); | |
5870 | ||
5871 | ret = of_property_read_u32(np, "battery,full_check_count", | |
5872 | &pdata->full_check_count); | |
5873 | if (ret) | |
5874 | pr_info("%s : Full check count is Empty\n", __func__); | |
5875 | ||
5876 | ret = of_property_read_u32(np, "battery,chg_gpio_full_check", | |
5877 | &pdata->chg_gpio_full_check); | |
5878 | if (ret) | |
5879 | pr_info("%s : Chg gpio full check is Empty\n", __func__); | |
5880 | ||
5881 | ret = of_property_read_u32(np, "battery,chg_polarity_full_check", | |
5882 | &pdata->chg_polarity_full_check); | |
5883 | if (ret) | |
5884 | pr_info("%s : Chg polarity full check is Empty\n", __func__); | |
5885 | ||
5886 | ret = of_property_read_u32(np, "battery,full_condition_type", | |
5887 | &pdata->full_condition_type); | |
5888 | if (ret) | |
5889 | pr_info("%s : Full condition type is Empty\n", __func__); | |
5890 | ||
5891 | ret = of_property_read_u32(np, "battery,full_condition_soc", | |
5892 | &pdata->full_condition_soc); | |
5893 | if (ret) | |
5894 | pr_info("%s : Full condition soc is Empty\n", __func__); | |
5895 | ||
5896 | ret = of_property_read_u32(np, "battery,full_condition_vcell", | |
5897 | &pdata->full_condition_vcell); | |
5898 | if (ret) | |
5899 | pr_info("%s : Full condition vcell is Empty\n", __func__); | |
5900 | ||
5901 | ret = of_property_read_u32(np, "battery,recharge_check_count", | |
5902 | &pdata->recharge_check_count); | |
5903 | if (ret) | |
5904 | pr_info("%s : Recharge check count is Empty\n", __func__); | |
5905 | ||
5906 | ret = of_property_read_u32(np, "battery,recharge_condition_type", | |
5907 | &pdata->recharge_condition_type); | |
5908 | if (ret) | |
5909 | pr_info("%s : Recharge condition type is Empty\n", __func__); | |
5910 | ||
5911 | ret = of_property_read_u32(np, "battery,recharge_condition_soc", | |
5912 | &pdata->recharge_condition_soc); | |
5913 | if (ret) | |
5914 | pr_info("%s : Recharge condition soc is Empty\n", __func__); | |
5915 | ||
5916 | ret = of_property_read_u32(np, "battery,recharge_condition_vcell", | |
5917 | &pdata->recharge_condition_vcell); | |
5918 | if (ret) | |
5919 | pr_info("%s : Recharge condition vcell is Empty\n", __func__); | |
5920 | ||
5921 | ret = of_property_read_u32(np, "battery,charging_total_time", | |
5922 | (unsigned int *)&pdata->charging_total_time); | |
5923 | if (ret) | |
5924 | pr_info("%s : Charging total time is Empty\n", __func__); | |
5925 | ||
5926 | ret = of_property_read_u32(np, "battery,hv_charging_total_time", | |
5927 | (unsigned int *)&pdata->hv_charging_total_time); | |
5928 | if (ret) { | |
5929 | pdata->hv_charging_total_time = 3 * 60 * 60; | |
5930 | pr_info("%s : HV Charging total time is %d\n", | |
5931 | __func__, pdata->hv_charging_total_time); | |
5932 | } | |
5933 | ||
5934 | ret = of_property_read_u32(np, "battery,normal_charging_total_time", | |
5935 | (unsigned int *)&pdata->normal_charging_total_time); | |
5936 | if (ret) { | |
5937 | pdata->normal_charging_total_time = 5 * 60 * 60; | |
5938 | pr_info("%s : Normal(WC) Charging total time is %d\n", | |
5939 | __func__, pdata->normal_charging_total_time); | |
5940 | } | |
5941 | ||
5942 | ret = of_property_read_u32(np, "battery,usb_charging_total_time", | |
5943 | (unsigned int *)&pdata->usb_charging_total_time); | |
5944 | if (ret) { | |
5945 | pdata->usb_charging_total_time = 10 * 60 * 60; | |
5946 | pr_info("%s : USB Charging total time is %d\n", | |
5947 | __func__, pdata->usb_charging_total_time); | |
5948 | } | |
5949 | ||
5950 | ret = of_property_read_u32(np, "battery,recharging_total_time", | |
5951 | (unsigned int *)&pdata->recharging_total_time); | |
5952 | if (ret) | |
5953 | pr_info("%s : Recharging total time is Empty\n", __func__); | |
5954 | ||
5955 | ret = of_property_read_u32(np, "battery,charging_reset_time", | |
5956 | (unsigned int *)&pdata->charging_reset_time); | |
5957 | if (ret) | |
5958 | pr_info("%s : Charging reset time is Empty\n", __func__); | |
5959 | ||
5960 | ret = of_property_read_u32(np, "battery,charging_reset_time", | |
5961 | (unsigned int *)&pdata->charging_reset_time); | |
5962 | if (ret) | |
5963 | pr_info("%s : Charging reset time is Empty\n", __func__); | |
5964 | ||
5965 | ret = of_property_read_u32(np, | |
5966 | "battery,expired_time", &temp); | |
5967 | if (ret) { | |
5968 | pr_info("expired time is empty\n"); | |
5969 | pdata->expired_time = 3 * 60 * 60; | |
5970 | } else { | |
5971 | pdata->expired_time = (unsigned int) temp; | |
5972 | } | |
5973 | pdata->expired_time *= 100; | |
5974 | battery->expired_time = pdata->expired_time; | |
5975 | ||
5976 | ret = of_property_read_u32(np, | |
5977 | "battery,recharging_expired_time", &temp); | |
5978 | if (ret) { | |
5979 | pr_info("expired time is empty\n"); | |
5980 | pdata->recharging_expired_time = 90 * 60; | |
5981 | } else { | |
5982 | pdata->recharging_expired_time = (unsigned int) temp; | |
5983 | } | |
5984 | pdata->recharging_expired_time *= 1000; | |
5985 | ||
5986 | ret = of_property_read_u32(np, | |
5987 | "battery,standard_curr", &pdata->standard_curr); | |
5988 | if (ret) { | |
5989 | pr_info("standard_curr is empty\n"); | |
5990 | pdata->standard_curr = 2150; | |
5991 | } | |
5992 | ||
5993 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
5994 | ret = of_property_read_u32(np, "battery,self_discharging_type", | |
5995 | (unsigned int *)&pdata->self_discharging_type); | |
5996 | if (ret) { | |
5997 | pr_info("%s: Self discharging type is Empty, Set default\n", | |
5998 | __func__); | |
5999 | pdata->self_discharging_type = 0; | |
6000 | } | |
6001 | ||
6002 | pdata->factory_discharging = of_get_named_gpio(np, "battery,factory_discharging", 0); | |
6003 | if (pdata->factory_discharging < 0) | |
6004 | pdata->factory_discharging = 0; | |
6005 | ||
6006 | pdata->self_discharging_en = of_property_read_bool(np, | |
6007 | "battery,self_discharging_en"); | |
6008 | ||
6009 | ret = of_property_read_u32(np, "battery,force_discharging_limit", | |
6010 | &temp); | |
6011 | pdata->force_discharging_limit = (int)temp; | |
6012 | if (ret) | |
6013 | pr_info("%s : Force Discharging limit is Empty", __func__); | |
6014 | ||
6015 | ret = of_property_read_u32(np, "battery,force_discharging_recov", | |
6016 | &temp); | |
6017 | pdata->force_discharging_recov = (int)temp; | |
6018 | if (ret) | |
6019 | pr_info("%s : Force Discharging recov is Empty", __func__); | |
6020 | ||
6021 | pr_info("%s : FORCE_DISCHARGING_LIMT(%d), FORCE_DISCHARGING_RECOV(%d)\n", | |
6022 | __func__, pdata->force_discharging_limit, pdata->force_discharging_recov); | |
6023 | ||
6024 | if (!pdata->self_discharging_type) { | |
6025 | ret = of_property_read_u32(np, "battery,discharging_adc_min", | |
6026 | (unsigned int *)&pdata->discharging_adc_min); | |
6027 | if (ret) | |
6028 | pr_info("%s : Discharging ADC Min is Empty", __func__); | |
6029 | ||
6030 | ret = of_property_read_u32(np, "battery,discharging_adc_max", | |
6031 | (unsigned int *)&pdata->discharging_adc_max);; | |
6032 | if (ret) | |
6033 | pr_info("%s : Discharging ADC Max is Empty", __func__); | |
6034 | } | |
6035 | ||
6036 | ret = of_property_read_u32(np, "battery,self_discharging_voltage_limit", | |
6037 | (unsigned int *)&pdata->self_discharging_voltage_limit); | |
6038 | if (ret) | |
6039 | pr_info("%s : Force Discharging recov is Empty", __func__); | |
6040 | ||
6041 | ret = of_property_read_u32(np, "battery,discharging_ntc_limit", | |
6042 | (unsigned int *)&pdata->discharging_ntc_limit); | |
6043 | if (ret) | |
6044 | pr_info("%s : Discharging NTC LIMIT is Empty", __func__); | |
6045 | #endif | |
6046 | ||
6047 | #if defined(CONFIG_BATTERY_SWELLING) | |
6048 | ret = of_property_read_u32(np, "battery,swelling_normal_current", | |
6049 | (unsigned int *)&pdata->swelling_normal_current); | |
6050 | if (ret) | |
6051 | pr_info("%s: swelling_normal_current is Empty\n", __func__); | |
6052 | ||
6053 | ret = of_property_read_u32(np, "battery,chg_float_voltage", | |
6054 | (unsigned int *)&pdata->swelling_normal_float_voltage); | |
6055 | if (ret) | |
6056 | pr_info("%s: chg_float_voltage is Empty\n", __func__); | |
6057 | ||
6828552d DW |
6058 | ret = of_property_read_u32(np, "battery,chg_float_voltage", |
6059 | (unsigned int *)&pdata->chg_float_voltage); | |
6060 | if (ret) | |
6061 | pr_info("%s: chg_float_voltage is Empty\n", __func__); | |
6062 | ||
3c2a0909 S |
6063 | ret = of_property_read_u32(np, "battery,swelling_high_temp_block", |
6064 | &temp); | |
6065 | pdata->swelling_high_temp_block = (int)temp; | |
6066 | if (ret) | |
6067 | pr_info("%s: swelling high temp block is Empty\n", __func__); | |
6068 | ||
6069 | ret = of_property_read_u32(np, "battery,swelling_high_temp_recov", | |
6070 | &temp); | |
6071 | pdata->swelling_high_temp_recov = (int)temp; | |
6072 | if (ret) | |
6073 | pr_info("%s: swelling high temp recovery is Empty\n", __func__); | |
6074 | ||
6075 | ret = of_property_read_u32(np, "battery,swelling_high_chg_current", | |
6076 | &pdata->swelling_high_chg_current); | |
6077 | if (ret) { | |
6078 | pr_info("%s: swelling high temp chg current is Empty\n", __func__); | |
6079 | pdata->swelling_high_chg_current = 0; | |
6080 | } | |
6081 | ||
6082 | ret = of_property_read_u32(np, "battery,swelling_low_chg_current", | |
6083 | &pdata->swelling_low_chg_current); | |
6084 | if (ret) { | |
6085 | pr_info("%s: swelling low temp chg current is Empty\n", __func__); | |
6086 | pdata->swelling_low_chg_current = 0; | |
6087 | } | |
6088 | ||
6089 | ret = of_property_read_u32(np, "battery,swelling_full_check_current_2nd", | |
6090 | &pdata->swelling_full_check_current_2nd); | |
6091 | if (ret) { | |
6092 | pr_info("%s: swelling_full_check_current_2nd is Empty\n", __func__); | |
6093 | pdata->swelling_full_check_current_2nd = 0; | |
6094 | } | |
6095 | ||
6096 | ret = of_property_read_u32(np, "battery,swelling_drop_float_voltage", | |
6097 | (unsigned int *)&pdata->swelling_drop_float_voltage); | |
6098 | if (ret) | |
6099 | pr_info("%s: swelling drop float voltage is Empty\n", __func__); | |
6100 | ||
6101 | ret = of_property_read_u32(np, "battery,swelling_high_rechg_voltage", | |
6102 | (unsigned int *)&pdata->swelling_high_rechg_voltage); | |
6103 | if (ret) | |
6104 | pr_info("%s: swelling_high_rechg_voltage is Empty\n", __func__); | |
6105 | ||
6106 | ret = of_property_read_u32(np, "battery,swelling_low_rechg_voltage", | |
6107 | (unsigned int *)&pdata->swelling_low_rechg_voltage); | |
6108 | if (ret) | |
6109 | pr_info("%s: swelling_low_rechg_voltage is Empty\n", __func__); | |
6110 | ||
6828552d DW |
6111 | ret = of_property_read_u32(np, "battery,swelling_low_temp_2step_mode", |
6112 | &pdata->swelling_low_temp_2step_mode); | |
6113 | if (ret) { | |
6114 | pr_info("%s: swelling_low_temp_2step_mode is Empty\n", __func__); | |
6115 | pdata->swelling_low_temp_2step_mode = 0; | |
6116 | } | |
3c2a0909 | 6117 | |
6828552d DW |
6118 | if(pdata->swelling_low_temp_2step_mode) { |
6119 | ret = of_property_read_u32(np, "battery,swelling_low_temp_block_1st", | |
6120 | &temp); | |
6121 | pdata->swelling_low_temp_block_1st = (int)temp; | |
6122 | if (ret) | |
6123 | pr_info("%s: swelling low temp block is Empty\n", __func__); | |
6124 | ||
6125 | ret = of_property_read_u32(np, "battery,swelling_low_temp_recov_1st", | |
6126 | &temp); | |
6127 | pdata->swelling_low_temp_recov_1st = (int)temp; | |
6128 | if (ret) | |
6129 | pr_info("%s: swelling low temp recovery is Empty\n", __func__); | |
6130 | ||
6131 | ret = of_property_read_u32(np, "battery,swelling_low_temp_block_2nd", | |
6132 | &temp); | |
6133 | pdata->swelling_low_temp_block_2nd = (int)temp; | |
6134 | if (ret) | |
6135 | pr_info("%s: swelling low temp block is Empty\n", __func__); | |
3c2a0909 | 6136 | |
6828552d DW |
6137 | ret = of_property_read_u32(np, "battery,swelling_low_temp_recov_2nd", |
6138 | &temp); | |
6139 | pdata->swelling_low_temp_recov_2nd = (int)temp; | |
6140 | if (ret) | |
6141 | pr_info("%s: swelling low temp recovery 2nd is Empty\n", __func__); | |
6142 | } | |
6143 | else { | |
6144 | ret = of_property_read_u32(np, "battery,swelling_low_temp_block", | |
3c2a0909 | 6145 | &temp); |
6828552d DW |
6146 | pdata->swelling_low_temp_block_1st = (int)temp; |
6147 | pdata->swelling_low_temp_block_2nd = (int)temp; | |
6148 | if (ret) | |
6149 | pr_info("%s: swelling low temp block is Empty\n", __func__); | |
3c2a0909 | 6150 | |
6828552d | 6151 | ret = of_property_read_u32(np, "battery,swelling_low_temp_recov", |
3c2a0909 | 6152 | &temp); |
6828552d DW |
6153 | pdata->swelling_low_temp_recov_1st = (int)temp; |
6154 | pdata->swelling_low_temp_recov_2nd = (int)temp; | |
6155 | if (ret) | |
6156 | pr_info("%s: swelling low temp recovery is Empty\n", __func__); | |
6157 | } | |
3c2a0909 S |
6158 | |
6159 | ret = of_property_read_u32(np, "battery,swelling_low_temp_current", | |
6160 | &pdata->swelling_low_temp_current); | |
6161 | if (ret) { | |
6162 | pr_info("%s: swelling_low_temp_current is Empty, Defualt value 600mA \n", __func__); | |
6163 | pdata->swelling_low_temp_current = 600; | |
6164 | } | |
6165 | ||
6166 | ret = of_property_read_u32(np, "battery,swelling_low_temp_topoff", | |
6167 | &pdata->swelling_low_temp_topoff); | |
6168 | if (ret) { | |
6169 | pr_info("%s: swelling_low_temp_topoff is Empty, Defualt value 200mA \n", __func__); | |
6170 | pdata->swelling_low_temp_topoff = 200; | |
6171 | } | |
6172 | ||
6173 | ret = of_property_read_u32(np, "battery,swelling_high_temp_current", | |
6174 | &pdata->swelling_high_temp_current); | |
6175 | if (ret) { | |
6176 | pr_info("%s: swelling_hign_temp_current is Empty, Defualt value 1300mA \n", __func__); | |
6177 | pdata->swelling_high_temp_current = 1300; | |
6178 | } | |
6179 | ||
6180 | ret = of_property_read_u32(np, "battery,swelling_high_temp_topoff", | |
6181 | &pdata->swelling_high_temp_topoff); | |
6182 | if (ret) { | |
6183 | pr_info("%s: swelling_high_temp_topoff is Empty, Defualt value 200mA \n", __func__); | |
6184 | pdata->swelling_high_temp_topoff = 200; | |
6185 | } | |
6186 | ||
6187 | ret = of_property_read_u32(np, "battery,swelling_block_time", | |
6188 | (unsigned int *)&pdata->swelling_block_time); | |
6189 | if (ret) | |
6190 | pr_info("%s: swelling_block_time is Empty\n", __func__); | |
6191 | ||
6192 | pr_info("%s : SWELLING_HIGH_TEMP(%d) SWELLING_HIGH_TEMP_RECOVERY(%d)\n" | |
6193 | "SWELLING_LOW_TEMP_1st(%d) SWELLING_LOW_TEMP_RECOVERY_1st(%d) " | |
6194 | "SWELLING_LOW_TEMP_2nd(%d) SWELLING_LOW_TEMP_RECOVERY_2nd(%d) " | |
6195 | "SWELLING_LOW_CURRENT(%d, %d), SWELLING_HIGH_CURRENT(%d, %d)\n", | |
6196 | __func__, pdata->swelling_high_temp_block, pdata->swelling_high_temp_recov, | |
6197 | pdata->swelling_low_temp_block_1st, pdata->swelling_low_temp_recov_1st, | |
6198 | pdata->swelling_low_temp_block_2nd, pdata->swelling_low_temp_recov_2nd, | |
6199 | pdata->swelling_low_temp_current, pdata->swelling_low_temp_topoff, | |
6200 | pdata->swelling_high_temp_current, pdata->swelling_high_temp_topoff); | |
6201 | ||
6202 | #endif | |
6203 | ||
6204 | pdata->always_enable = of_property_read_bool(np, | |
6205 | "battery,always_enable"); | |
6206 | ||
6207 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
6208 | p = of_get_property(np, "battery,age_data", &len); | |
6209 | if (p) { | |
6210 | battery->pdata->num_age_step = len / sizeof(sec_age_data_t); | |
6211 | battery->pdata->age_data = kzalloc(len, GFP_KERNEL); | |
6212 | ret = of_property_read_u32_array(np, "battery,age_data", | |
6213 | (u32 *)battery->pdata->age_data, len/sizeof(u32)); | |
6214 | if (ret) { | |
6215 | pr_err("%s failed to read battery->pdata->age_data: %d\n", | |
6216 | __func__, ret); | |
6217 | kfree(battery->pdata->age_data); | |
6218 | battery->pdata->age_data = NULL; | |
6219 | battery->pdata->num_age_step = 0; | |
6220 | } | |
6221 | pr_err("%s num_age_step : %d\n", __func__, battery->pdata->num_age_step); | |
6222 | for (len = 0; len < battery->pdata->num_age_step; ++len) { | |
6223 | pr_err("[%d/%d]cycle:%d, float:%d, full_v:%d, recharge_v:%d, soc:%d\n", | |
6224 | len, battery->pdata->num_age_step-1, | |
6225 | battery->pdata->age_data[len].cycle, | |
6226 | battery->pdata->age_data[len].float_voltage, | |
6227 | battery->pdata->age_data[len].recharge_condition_vcell, | |
6228 | battery->pdata->age_data[len].full_condition_vcell, | |
6229 | battery->pdata->age_data[len].full_condition_soc); | |
6230 | } | |
6231 | } else { | |
6232 | battery->pdata->num_age_step = 0; | |
6233 | pr_err("%s there is not age_data\n", __func__); | |
6234 | } | |
6235 | #endif | |
6236 | return ret; | |
6237 | } | |
6238 | #endif | |
6239 | ||
6240 | #ifdef CONFIG_OF | |
6241 | extern sec_battery_platform_data_t sec_battery_pdata; | |
6242 | #endif | |
6243 | ||
6244 | static void cable_initial_check(struct sec_battery_info *battery) | |
6245 | { | |
6246 | union power_supply_propval value; | |
6247 | ||
6248 | pr_info("%s : current_cable_type : (%d)\n", __func__, battery->cable_type); | |
6249 | ||
6250 | if (battery->cable_type == POWER_SUPPLY_TYPE_BATTERY) { | |
6251 | psy_do_property(battery->pdata->charger_name, get, | |
6252 | POWER_SUPPLY_PROP_ONLINE, value); | |
6253 | if (value.intval == POWER_SUPPLY_TYPE_WIRELESS) { | |
6254 | value.intval = 1; | |
6255 | psy_do_property("wireless", set, | |
6256 | POWER_SUPPLY_PROP_ONLINE, value); | |
6257 | } | |
6258 | } | |
6259 | } | |
6260 | ||
6261 | static int __devinit sec_battery_probe(struct platform_device *pdev) | |
6262 | { | |
6263 | sec_battery_platform_data_t *pdata = NULL; | |
6264 | struct sec_battery_info *battery; | |
6265 | int ret = 0; | |
6266 | #ifndef CONFIG_OF | |
6267 | int i; | |
6268 | #endif | |
6269 | ||
6270 | union power_supply_propval value; | |
6271 | ||
6272 | dev_dbg(&pdev->dev, | |
6273 | "%s: SEC Battery Driver Loading\n", __func__); | |
6274 | ||
6275 | battery = kzalloc(sizeof(*battery), GFP_KERNEL); | |
6276 | if (!battery) | |
6277 | return -ENOMEM; | |
6278 | ||
6279 | if (pdev->dev.of_node) { | |
6280 | pdata = devm_kzalloc(&pdev->dev, | |
6281 | sizeof(sec_battery_platform_data_t), | |
6282 | GFP_KERNEL); | |
6283 | if (!pdata) { | |
6284 | dev_err(&pdev->dev, "Failed to allocate memory\n"); | |
6285 | ret = -ENOMEM; | |
6286 | goto err_bat_free; | |
6287 | } | |
6288 | ||
6289 | battery->pdata = pdata; | |
6290 | if (sec_bat_parse_dt(&pdev->dev, battery)) { | |
6291 | dev_err(&pdev->dev, | |
6292 | "%s: Failed to get battery dt\n", __func__); | |
6293 | ret = -EINVAL; | |
6294 | goto err_bat_free; | |
6295 | } | |
6296 | } else { | |
6297 | pdata = dev_get_platdata(&pdev->dev); | |
6298 | battery->pdata = pdata; | |
6299 | } | |
6300 | ||
6301 | platform_set_drvdata(pdev, battery); | |
6302 | ||
6303 | battery->dev = &pdev->dev; | |
6304 | ||
6305 | mutex_init(&battery->adclock); | |
6306 | mutex_init(&battery->current_eventlock); | |
6307 | ||
6308 | dev_dbg(battery->dev, "%s: ADC init\n", __func__); | |
6309 | ||
6310 | #ifdef CONFIG_OF | |
6311 | adc_init(pdev, battery); | |
6312 | #else | |
6313 | for (i = 0; i < SEC_BAT_ADC_CHANNEL_NUM; i++) | |
6314 | adc_init(pdev, pdata, i); | |
6315 | #endif | |
6316 | wake_lock_init(&battery->monitor_wake_lock, WAKE_LOCK_SUSPEND, | |
6317 | "sec-battery-monitor"); | |
6318 | wake_lock_init(&battery->cable_wake_lock, WAKE_LOCK_SUSPEND, | |
6319 | "sec-battery-cable"); | |
6320 | wake_lock_init(&battery->vbus_wake_lock, WAKE_LOCK_SUSPEND, | |
6321 | "sec-battery-vbus"); | |
6322 | wake_lock_init(&battery->siop_wake_lock, WAKE_LOCK_SUSPEND, | |
6323 | "sec-battery-siop"); | |
6324 | ||
6325 | /* initialization of battery info */ | |
6326 | sec_bat_set_charging_status(battery, | |
6327 | POWER_SUPPLY_STATUS_DISCHARGING); | |
6328 | battery->health = POWER_SUPPLY_HEALTH_GOOD; | |
6329 | battery->present = true; | |
6330 | battery->is_jig_on = false; | |
6331 | ||
6332 | battery->polling_count = 1; /* initial value = 1 */ | |
6333 | battery->polling_time = pdata->polling_time[ | |
6334 | SEC_BATTERY_POLLING_TIME_DISCHARGING]; | |
6335 | battery->polling_in_sleep = false; | |
6336 | battery->polling_short = false; | |
6337 | ||
6338 | battery->check_count = 0; | |
6339 | battery->check_adc_count = 0; | |
6340 | battery->check_adc_value = 0; | |
6341 | ||
6342 | battery->charging_start_time = 0; | |
6343 | battery->charging_passed_time = 0; | |
6344 | battery->charging_next_time = 0; | |
6345 | battery->charging_fullcharged_time = 0; | |
6346 | battery->siop_level = 100; | |
6347 | battery->r_siop_level = 100; | |
6348 | battery->wc_enable = 1; | |
6349 | battery->pre_chg_temp = 0; | |
6350 | #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST) | |
6351 | battery->stability_test = 0; | |
6352 | battery->eng_not_full_status = 0; | |
6353 | #endif | |
6354 | battery->wc_status = 0; | |
6355 | battery->ps_status= 0; | |
6356 | battery->ps_changed= 0; | |
6357 | battery->wire_status = POWER_SUPPLY_TYPE_BATTERY; | |
6358 | #if defined(CONFIG_BATTERY_SWELLING) | |
6359 | battery->swelling_mode = false; | |
6360 | #endif | |
6361 | battery->charging_block = false; | |
6362 | battery->chg_limit = SEC_BATTERY_CHG_TEMP_NONE; | |
6363 | ||
6364 | #if defined(ANDROID_ALARM_ACTIVATED) | |
6365 | alarm_init(&battery->event_termination_alarm, | |
6366 | ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, | |
6367 | sec_bat_event_expired_timer_func); | |
6368 | #else | |
6369 | alarm_init(&battery->event_termination_alarm, | |
6370 | ALARM_BOOTTIME, | |
6371 | sec_bat_event_expired_timer_func); | |
6372 | #endif | |
6373 | battery->temp_highlimit_threshold = | |
6374 | pdata->temp_highlimit_threshold_normal; | |
6375 | battery->temp_highlimit_recovery = | |
6376 | pdata->temp_highlimit_recovery_normal; | |
6377 | battery->temp_high_threshold = | |
6378 | pdata->temp_high_threshold_normal; | |
6379 | battery->temp_high_recovery = | |
6380 | pdata->temp_high_recovery_normal; | |
6381 | battery->temp_low_recovery = | |
6382 | pdata->temp_low_recovery_normal; | |
6383 | battery->temp_low_threshold = | |
6384 | pdata->temp_low_threshold_normal; | |
6385 | ||
6386 | battery->charging_mode = SEC_BATTERY_CHARGING_NONE; | |
6387 | battery->is_recharging = false; | |
6388 | battery->cable_type = POWER_SUPPLY_TYPE_BATTERY; | |
6389 | battery->test_mode = 0; | |
6390 | battery->factory_mode = false; | |
6391 | battery->store_mode = false; | |
6392 | battery->ignore_store_mode = false; | |
6393 | battery->slate_mode = false; | |
6394 | slate_mode_state = battery->slate_mode; | |
6395 | battery->is_hc_usb = false; | |
6396 | battery->ignore_siop = false; | |
6397 | ||
6398 | battery->safety_timer_set = true; | |
6399 | battery->stop_timer = false; | |
6400 | battery->prev_safety_time = 0; | |
6401 | battery->lcd_status = false; | |
6402 | battery->current_event = 0; | |
6403 | ||
6404 | battery->batt_cycle = -1; | |
6405 | #if defined(CONFIG_BATTERY_AGE_FORECAST) | |
6406 | battery->pdata->age_step = 0; | |
6407 | #endif | |
6408 | ||
6409 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
6410 | battery->self_discharging = false; | |
6411 | battery->force_discharging = false; | |
6412 | battery->factory_self_discharging_mode_on = false; | |
6413 | #endif | |
6414 | ||
6415 | if (battery->pdata->charger_name == NULL) | |
6416 | battery->pdata->charger_name = "sec-charger"; | |
6417 | if (battery->pdata->fuelgauge_name == NULL) | |
6418 | battery->pdata->fuelgauge_name = "sec-fuelgauge"; | |
6419 | ||
6420 | #if defined(CONFIG_CHARGER_MAX77843) || defined(CONFIG_CHARGER_MAX77833) | |
6421 | pr_info("%s : CHARGER CHIP NAME (%s)\n", __func__, charger_chip_name); | |
6422 | if (charger_chip_name != NULL && !strcmp(charger_chip_name,"max77843-charger")) { | |
6423 | battery->pdata->charger_name = "max77843-charger"; | |
6424 | battery->pdata->fuelgauge_name = "max77843-fuelgauge"; | |
6425 | } else if (!strcmp(charger_chip_name, "max77833-charger")) { | |
6426 | battery->pdata->charger_name = "max77833-charger"; | |
6427 | battery->pdata->fuelgauge_name = "max77833-fuelgauge"; | |
6428 | } | |
6429 | #endif | |
6430 | ||
6431 | battery->psy_bat.name = "battery", | |
6432 | battery->psy_bat.type = POWER_SUPPLY_TYPE_BATTERY, | |
6433 | battery->psy_bat.properties = sec_battery_props, | |
6434 | battery->psy_bat.num_properties = ARRAY_SIZE(sec_battery_props), | |
6435 | battery->psy_bat.get_property = sec_bat_get_property, | |
6436 | battery->psy_bat.set_property = sec_bat_set_property, | |
6437 | battery->psy_usb.name = "usb", | |
6438 | battery->psy_usb.type = POWER_SUPPLY_TYPE_USB, | |
6439 | battery->psy_usb.supplied_to = supply_list, | |
6440 | battery->psy_usb.num_supplicants = ARRAY_SIZE(supply_list), | |
6441 | battery->psy_usb.properties = sec_power_props, | |
6442 | battery->psy_usb.num_properties = ARRAY_SIZE(sec_power_props), | |
6443 | battery->psy_usb.get_property = sec_usb_get_property, | |
6444 | battery->psy_ac.name = "ac", | |
6445 | battery->psy_ac.type = POWER_SUPPLY_TYPE_MAINS, | |
6446 | battery->psy_ac.supplied_to = supply_list, | |
6447 | battery->psy_ac.num_supplicants = ARRAY_SIZE(supply_list), | |
6448 | battery->psy_ac.properties = sec_power_props, | |
6449 | battery->psy_ac.num_properties = ARRAY_SIZE(sec_power_props), | |
6450 | battery->psy_ac.get_property = sec_ac_get_property; | |
6451 | battery->psy_wireless.name = "wireless", | |
6452 | battery->psy_wireless.type = POWER_SUPPLY_TYPE_WIRELESS, | |
6453 | battery->psy_wireless.supplied_to = supply_list, | |
6454 | battery->psy_wireless.num_supplicants = ARRAY_SIZE(supply_list), | |
6455 | battery->psy_wireless.properties = sec_power_props, | |
6456 | battery->psy_wireless.num_properties = ARRAY_SIZE(sec_power_props), | |
6457 | battery->psy_wireless.get_property = sec_wireless_get_property; | |
6458 | battery->psy_wireless.set_property = sec_wireless_set_property; | |
6459 | battery->psy_ps.name = "ps", | |
6460 | battery->psy_ps.type = POWER_SUPPLY_TYPE_POWER_SHARING, | |
6461 | battery->psy_ps.supplied_to = supply_list, | |
6462 | battery->psy_ps.num_supplicants = ARRAY_SIZE(supply_list), | |
6463 | battery->psy_ps.properties = sec_ps_props, | |
6464 | battery->psy_ps.num_properties = ARRAY_SIZE(sec_ps_props), | |
6465 | battery->psy_ps.get_property = sec_ps_get_property; | |
6466 | battery->psy_ps.set_property = sec_ps_set_property; | |
6467 | ||
6468 | if (battery->pdata->wchg_ctl_en) { | |
6469 | ret = gpio_request(battery->pdata->wchg_ctl, "WCHG_CTL"); | |
6470 | if (ret) { | |
6471 | pr_err("failed to request GPIO %u\n", battery->pdata->wchg_ctl); | |
6472 | goto err_wake_lock; | |
6473 | } | |
6474 | gpio_direction_output(battery->pdata->wchg_ctl, 0); | |
6475 | pr_info("%s : GPIO %d\n", __func__, gpio_get_value(battery->pdata->wchg_ctl)); | |
6476 | } | |
6477 | ||
6478 | #if defined (CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
6479 | if (battery->pdata->factory_discharging) { | |
6480 | ret = gpio_request(battery->pdata->factory_discharging, "FACTORY_DISCHARGING"); | |
6481 | if (ret) { | |
6482 | pr_err("failed to request GPIO %u\n", battery->pdata->factory_discharging); | |
6483 | goto err_gpio; | |
6484 | } | |
6485 | } | |
6486 | #endif | |
6487 | /* create work queue */ | |
6488 | battery->monitor_wqueue = | |
6489 | alloc_workqueue(dev_name(&pdev->dev), WQ_MEM_RECLAIM, 1); | |
6490 | if (!battery->monitor_wqueue) { | |
6491 | dev_err(battery->dev, | |
6492 | "%s: Fail to Create Workqueue\n", __func__); | |
6493 | goto err_irq; | |
6494 | } | |
6495 | ||
6496 | INIT_DELAYED_WORK(&battery->monitor_work, sec_bat_monitor_work); | |
6497 | INIT_DELAYED_WORK(&battery->cable_work, sec_bat_cable_work); | |
6498 | #if defined(CONFIG_CALC_TIME_TO_FULL) | |
6499 | INIT_DELAYED_WORK(&battery->timetofull_work, sec_bat_time_to_full_work); | |
6500 | #endif | |
6501 | INIT_DELAYED_WORK(&battery->siop_work, sec_bat_siop_work); | |
6502 | ||
6503 | switch (pdata->polling_type) { | |
6504 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
6505 | INIT_DELAYED_WORK(&battery->polling_work, | |
6506 | sec_bat_polling_work); | |
6507 | break; | |
6508 | case SEC_BATTERY_MONITOR_ALARM: | |
6509 | #if defined(ANDROID_ALARM_ACTIVATED) | |
6510 | battery->last_poll_time = alarm_get_elapsed_realtime(); | |
6511 | alarm_init(&battery->polling_alarm, | |
6512 | ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP, | |
6513 | sec_bat_alarm); | |
6514 | #else | |
6515 | battery->last_poll_time = ktime_get_boottime(); | |
6516 | alarm_init(&battery->polling_alarm, ALARM_BOOTTIME, | |
6517 | sec_bat_alarm); | |
6518 | #endif | |
6519 | break; | |
6520 | default: | |
6521 | break; | |
6522 | } | |
6523 | ||
6524 | /* init power supplier framework */ | |
6525 | ret = power_supply_register(&pdev->dev, &battery->psy_ps); | |
6526 | if (ret) { | |
6527 | dev_err(battery->dev, | |
6528 | "%s: Failed to Register psy_ps\n", __func__); | |
6529 | goto err_workqueue; | |
6530 | } | |
6531 | ||
6532 | ret = power_supply_register(&pdev->dev, &battery->psy_wireless); | |
6533 | if (ret) { | |
6534 | dev_err(battery->dev, | |
6535 | "%s: Failed to Register psy_wireless\n", __func__); | |
6536 | goto err_supply_unreg_ps; | |
6537 | } | |
6538 | ||
6539 | ret = power_supply_register(&pdev->dev, &battery->psy_usb); | |
6540 | if (ret) { | |
6541 | dev_err(battery->dev, | |
6542 | "%s: Failed to Register psy_usb\n", __func__); | |
6543 | goto err_supply_unreg_wireless; | |
6544 | } | |
6545 | ||
6546 | ret = power_supply_register(&pdev->dev, &battery->psy_ac); | |
6547 | if (ret) { | |
6548 | dev_err(battery->dev, | |
6549 | "%s: Failed to Register psy_ac\n", __func__); | |
6550 | goto err_supply_unreg_usb; | |
6551 | } | |
6552 | ||
6553 | ret = power_supply_register(&pdev->dev, &battery->psy_bat); | |
6554 | if (ret) { | |
6555 | dev_err(battery->dev, | |
6556 | "%s: Failed to Register psy_bat\n", __func__); | |
6557 | goto err_supply_unreg_ac; | |
6558 | } | |
6559 | ||
6560 | if (battery->pdata->bat_gpio_init && !battery->pdata->bat_gpio_init()) { | |
6561 | dev_err(battery->dev, | |
6562 | "%s: Failed to Initialize GPIO\n", __func__); | |
6563 | goto err_supply_unreg_bat; | |
6564 | } | |
6565 | #if 0 | |
6566 | if (battery->pdata->bat_irq) { | |
6567 | ret = request_threaded_irq(battery->pdata->bat_irq, | |
6568 | NULL, sec_bat_irq_thread, | |
6569 | battery->pdata->bat_irq_attr | |
6570 | | IRQF_ONESHOT, | |
6571 | "battery-irq", battery); | |
6572 | if (ret) { | |
6573 | dev_err(battery->dev, | |
6574 | "%s: Failed to Request IRQ (bat_int)\n", __func__); | |
6575 | goto err_supply_unreg_bat; | |
6576 | } | |
6577 | if (battery->pdata->bat_irq_gpio) { | |
6578 | ret = enable_irq_wake(battery->pdata->bat_irq); | |
6579 | if (ret < 0) | |
6580 | dev_err(battery->dev, | |
6581 | "%s: Failed to Enable Wakeup Source(%d)(bat_int)\n", | |
6582 | __func__, ret); | |
6583 | } | |
6584 | } | |
6585 | #endif | |
6586 | ||
6587 | ret = sec_bat_create_attrs(battery->psy_bat.dev); | |
6588 | if (ret) { | |
6589 | dev_err(battery->dev, | |
6590 | "%s : Failed to create_attrs\n", __func__); | |
6591 | goto err_req_irq; | |
6592 | } | |
6593 | ||
6594 | #if defined(CONFIG_MUIC_NOTIFIER) | |
6595 | muic_notifier_register(&battery->batt_nb, | |
6596 | batt_handle_notification, | |
6597 | MUIC_NOTIFY_DEV_CHARGER); | |
6598 | #endif | |
6599 | #if defined(CONFIG_VBUS_NOTIFIER) | |
6600 | vbus_notifier_register(&battery->vbus_nb, | |
6601 | vbus_handle_notification, | |
6602 | VBUS_NOTIFY_DEV_CHARGER); | |
6603 | #endif | |
6604 | ||
6605 | #if defined(CONFIG_AFC_CHARGER_MODE) | |
6606 | value.intval = 1; | |
6607 | psy_do_property(battery->pdata->charger_name, set, | |
6608 | POWER_SUPPLY_PROP_AFC_CHARGER_MODE, | |
6609 | value); | |
6610 | #endif | |
6611 | #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY) | |
6612 | battery->store_mode = true; | |
6613 | value.intval = 0; | |
6614 | psy_do_property(battery->pdata->fuelgauge_name, get, | |
6615 | POWER_SUPPLY_PROP_CAPACITY, value); | |
6616 | if (value.intval <= 5) { | |
6617 | battery->ignore_store_mode = true; | |
6618 | } else { | |
6619 | value.intval = battery->store_mode; | |
6620 | psy_do_property(battery->pdata->charger_name, set, | |
6621 | POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, value); | |
6622 | } | |
6623 | #endif | |
6624 | if (pdata->initial_check) | |
6625 | pdata->initial_check(); | |
6626 | else | |
6627 | cable_initial_check(battery); | |
6628 | ||
6629 | psy_do_property("battery", get, | |
6630 | POWER_SUPPLY_PROP_ONLINE, value); | |
6631 | ||
6632 | if ((value.intval == POWER_SUPPLY_TYPE_BATTERY) || | |
6633 | (value.intval == POWER_SUPPLY_TYPE_HV_PREPARE_MAINS)) { | |
6634 | dev_info(&pdev->dev, | |
6635 | "%s: SEC Battery Driver Monitorwork\n", __func__); | |
6636 | wake_lock(&battery->monitor_wake_lock); | |
6637 | queue_delayed_work_on(0, battery->monitor_wqueue, &battery->monitor_work, 0); | |
6638 | } | |
6639 | ||
6640 | if (battery->pdata->check_battery_callback) | |
6641 | battery->present = battery->pdata->check_battery_callback(); | |
6642 | ||
6643 | dev_info(battery->dev, | |
6644 | "%s: SEC Battery Driver Loaded\n", __func__); | |
6645 | return 0; | |
6646 | ||
6647 | err_req_irq: | |
6648 | if (battery->pdata->bat_irq) | |
6649 | free_irq(battery->pdata->bat_irq, battery); | |
6650 | err_supply_unreg_bat: | |
6651 | power_supply_unregister(&battery->psy_bat); | |
6652 | err_supply_unreg_ac: | |
6653 | power_supply_unregister(&battery->psy_ac); | |
6654 | err_supply_unreg_usb: | |
6655 | power_supply_unregister(&battery->psy_usb); | |
6656 | err_supply_unreg_wireless: | |
6657 | power_supply_unregister(&battery->psy_wireless); | |
6658 | err_supply_unreg_ps: | |
6659 | power_supply_unregister(&battery->psy_ps); | |
6660 | err_workqueue: | |
6661 | destroy_workqueue(battery->monitor_wqueue); | |
6662 | err_irq: | |
6663 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
6664 | if (battery->pdata->factory_discharging) | |
6665 | gpio_free(battery->pdata->factory_discharging); | |
6666 | err_gpio: | |
6667 | #endif | |
6668 | gpio_free(battery->pdata->wchg_ctl); | |
6669 | err_wake_lock: | |
6670 | wake_lock_destroy(&battery->monitor_wake_lock); | |
6671 | wake_lock_destroy(&battery->cable_wake_lock); | |
6672 | wake_lock_destroy(&battery->vbus_wake_lock); | |
6673 | wake_lock_destroy(&battery->siop_wake_lock); | |
6674 | mutex_destroy(&battery->adclock); | |
6675 | mutex_destroy(&battery->current_eventlock); | |
6676 | kfree(pdata); | |
6677 | err_bat_free: | |
6678 | kfree(battery); | |
6679 | ||
6680 | return ret; | |
6681 | } | |
6682 | ||
6683 | static int __devexit sec_battery_remove(struct platform_device *pdev) | |
6684 | { | |
6685 | struct sec_battery_info *battery = platform_get_drvdata(pdev); | |
6686 | #ifndef CONFIG_OF | |
6687 | int i; | |
6688 | #endif | |
6689 | ||
6690 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
6691 | ||
6692 | switch (battery->pdata->polling_type) { | |
6693 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
6694 | cancel_delayed_work(&battery->polling_work); | |
6695 | break; | |
6696 | case SEC_BATTERY_MONITOR_ALARM: | |
6697 | alarm_cancel(&battery->polling_alarm); | |
6698 | break; | |
6699 | default: | |
6700 | break; | |
6701 | } | |
6702 | ||
6703 | alarm_cancel(&battery->event_termination_alarm); | |
6704 | flush_workqueue(battery->monitor_wqueue); | |
6705 | destroy_workqueue(battery->monitor_wqueue); | |
6706 | wake_lock_destroy(&battery->monitor_wake_lock); | |
6707 | wake_lock_destroy(&battery->cable_wake_lock); | |
6708 | wake_lock_destroy(&battery->vbus_wake_lock); | |
6709 | wake_lock_destroy(&battery->siop_wake_lock); | |
6710 | ||
6711 | mutex_destroy(&battery->adclock); | |
6712 | mutex_destroy(&battery->current_eventlock); | |
6713 | #ifdef CONFIG_OF | |
6714 | adc_exit(battery); | |
6715 | #else | |
6716 | for (i = 0; i < SEC_BAT_ADC_CHANNEL_NUM; i++) | |
6717 | adc_exit(battery->pdata, i); | |
6718 | #endif | |
6719 | power_supply_unregister(&battery->psy_ps); | |
6720 | power_supply_unregister(&battery->psy_wireless); | |
6721 | power_supply_unregister(&battery->psy_ac); | |
6722 | power_supply_unregister(&battery->psy_usb); | |
6723 | power_supply_unregister(&battery->psy_bat); | |
6724 | ||
6725 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
6726 | kfree(battery); | |
6727 | ||
6728 | return 0; | |
6729 | } | |
6730 | ||
6731 | static int sec_battery_prepare(struct device *dev) | |
6732 | { | |
6733 | struct sec_battery_info *battery | |
6734 | = dev_get_drvdata(dev); | |
6735 | ||
6736 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
6737 | ||
6738 | switch (battery->pdata->polling_type) { | |
6739 | case SEC_BATTERY_MONITOR_WORKQUEUE: | |
6740 | cancel_delayed_work(&battery->polling_work); | |
6741 | break; | |
6742 | case SEC_BATTERY_MONITOR_ALARM: | |
6743 | alarm_cancel(&battery->polling_alarm); | |
6744 | break; | |
6745 | default: | |
6746 | break; | |
6747 | } | |
6748 | cancel_delayed_work_sync(&battery->monitor_work); | |
6749 | ||
6750 | battery->polling_in_sleep = true; | |
6751 | ||
6752 | sec_bat_set_polling(battery); | |
6753 | ||
6754 | /* cancel work for polling | |
6755 | * that is set in sec_bat_set_polling() | |
6756 | * no need for polling in sleep | |
6757 | */ | |
6758 | if (battery->pdata->polling_type == | |
6759 | SEC_BATTERY_MONITOR_WORKQUEUE) | |
6760 | cancel_delayed_work(&battery->polling_work); | |
6761 | ||
6762 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
6763 | ||
6764 | return 0; | |
6765 | } | |
6766 | ||
6767 | static int sec_battery_suspend(struct device *dev) | |
6768 | { | |
6769 | return 0; | |
6770 | } | |
6771 | ||
6772 | static int sec_battery_resume(struct device *dev) | |
6773 | { | |
6774 | return 0; | |
6775 | } | |
6776 | ||
6777 | static void sec_battery_complete(struct device *dev) | |
6778 | { | |
6779 | struct sec_battery_info *battery | |
6780 | = dev_get_drvdata(dev); | |
6781 | ||
6782 | dev_dbg(battery->dev, "%s: Start\n", __func__); | |
6783 | ||
6784 | /* cancel current alarm and reset after monitor work */ | |
6785 | if (battery->pdata->polling_type == SEC_BATTERY_MONITOR_ALARM) | |
6786 | alarm_cancel(&battery->polling_alarm); | |
6787 | ||
6788 | wake_lock(&battery->monitor_wake_lock); | |
6789 | queue_delayed_work_on(0, battery->monitor_wqueue, | |
6790 | &battery->monitor_work, 0); | |
6791 | ||
6792 | dev_dbg(battery->dev, "%s: End\n", __func__); | |
6793 | ||
6794 | return; | |
6795 | } | |
6796 | ||
6797 | static void sec_battery_shutdown(struct device *dev) | |
6798 | { | |
6799 | struct sec_battery_info *battery | |
6800 | = dev_get_drvdata(dev); | |
6801 | union power_supply_propval val; | |
6802 | ||
6803 | if (battery->pdata->always_enable) { | |
6804 | val.intval = 1; | |
6805 | psy_do_property(battery->pdata->charger_name, set, | |
6806 | POWER_SUPPLY_PROP_CHARGING_ENABLED, val); | |
6807 | } | |
6808 | ||
6809 | #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING) | |
6810 | if (battery->force_discharging) { | |
6811 | pr_info("SELF DISCHARGING IC DISENABLE\n"); | |
6812 | sec_bat_self_discharging_control(battery, false); | |
6813 | } | |
6814 | #endif | |
6815 | } | |
6816 | ||
6817 | #ifdef CONFIG_OF | |
6818 | static struct of_device_id sec_battery_dt_ids[] = { | |
6819 | { .compatible = "samsung,sec-battery" }, | |
6820 | { } | |
6821 | }; | |
6822 | MODULE_DEVICE_TABLE(of, sec_battery_dt_ids); | |
6823 | #endif /* CONFIG_OF */ | |
6824 | ||
6825 | static const struct dev_pm_ops sec_battery_pm_ops = { | |
6826 | .prepare = sec_battery_prepare, | |
6827 | .suspend = sec_battery_suspend, | |
6828 | .resume = sec_battery_resume, | |
6829 | .complete = sec_battery_complete, | |
6830 | }; | |
6831 | ||
6832 | static struct platform_driver sec_battery_driver = { | |
6833 | .driver = { | |
6834 | .name = "sec-battery", | |
6835 | .owner = THIS_MODULE, | |
6836 | .pm = &sec_battery_pm_ops, | |
6837 | .shutdown = sec_battery_shutdown, | |
6838 | #ifdef CONFIG_OF | |
6839 | .of_match_table = sec_battery_dt_ids, | |
6840 | #endif | |
6841 | }, | |
6842 | .probe = sec_battery_probe, | |
6843 | .remove = __devexit_p(sec_battery_remove), | |
6844 | }; | |
6845 | ||
6846 | static int __init sec_battery_init(void) | |
6847 | { | |
6848 | return platform_driver_register(&sec_battery_driver); | |
6849 | } | |
6850 | ||
6851 | static void __exit sec_battery_exit(void) | |
6852 | { | |
6853 | platform_driver_unregister(&sec_battery_driver); | |
6854 | } | |
6855 | ||
6856 | late_initcall(sec_battery_init); | |
6857 | module_exit(sec_battery_exit); | |
6858 | ||
6859 | MODULE_DESCRIPTION("Samsung Battery Driver"); | |
6860 | MODULE_AUTHOR("Samsung Electronics"); | |
6861 | MODULE_LICENSE("GPL"); |