3 * Samsung Mobile Battery Driver
5 * Copyright (C) 2012 Samsung Electronics
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.
12 #include <linux/battery/sec_battery.h>
14 const char *charger_chip_name
;
15 bool slate_mode_state
;
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
),
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
),
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
),
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
),
91 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
92 SEC_BATTERY_ATTR(batt_inbat_wireless_cs100
),
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
),
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
,
122 #if defined(CONFIG_BATTERY_SWELLING)
123 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT
,
127 static enum power_supply_property sec_power_props
[] = {
128 POWER_SUPPLY_PROP_ONLINE
,
131 static enum power_supply_property sec_ps_props
[] = {
132 POWER_SUPPLY_PROP_STATUS
,
133 POWER_SUPPLY_PROP_ONLINE
,
136 static char *supply_list
[] = {
140 char *sec_bat_charging_mode_str
[] = {
148 char *sec_bat_status_str
[] = {
156 char *sec_bat_health_str
[] = {
166 "WatchdogTimerExpire",
172 static void sec_bat_set_current_event(struct sec_battery_info
*battery
,
173 unsigned int current_event_val
, unsigned int current_event_mask
)
175 unsigned int temp
= battery
->current_event
;
177 mutex_lock(&battery
->current_eventlock
);
179 battery
->current_event
&= ~current_event_mask
;
180 battery
->current_event
|= current_event_val
;
182 pr_info("%s: current event before(0x%x), after(0x%x)\n",
183 __func__
, temp
, battery
->current_event
);
185 mutex_unlock(&battery
->current_eventlock
);
188 static int sec_bat_set_charge(
189 struct sec_battery_info
*battery
,
192 union power_supply_propval val
;
193 ktime_t current_time
;
196 if (battery
->cable_type
== POWER_SUPPLY_TYPE_OTG
)
198 val
.intval
= battery
->status
;
199 psy_do_property(battery
->pdata
->charger_name
, set
,
200 POWER_SUPPLY_PROP_STATUS
, val
);
201 #if defined(ANDROID_ALARM_ACTIVATED)
202 current_time
= alarm_get_elapsed_realtime();
203 ts
= ktime_to_timespec(current_time
);
205 current_time
= ktime_get_boottime();
206 ts
= ktime_to_timespec(current_time
);
210 val
.intval
= battery
->cable_type
;
211 /*Reset charging start time only in initial charging start */
212 if (battery
->charging_start_time
== 0) {
215 battery
->charging_start_time
= ts
.tv_sec
;
216 battery
->charging_next_time
=
217 battery
->pdata
->charging_reset_time
;
220 if (battery
->siop_level
< 100)
221 battery
->lcd_on_time
= ts
.tv_sec
;
223 val
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
224 battery
->charging_start_time
= 0;
225 battery
->charging_passed_time
= 0;
226 battery
->charging_next_time
= 0;
227 battery
->charging_fullcharged_time
= 0;
228 battery
->full_check_cnt
= 0;
229 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
230 battery
->cc_cv_mode
= 0;
232 battery
->lcd_on_total_time
= 0;
233 battery
->lcd_on_time
= 0;
236 battery
->charging_block
= !enable
;
238 battery
->temp_highlimit_cnt
= 0;
239 battery
->temp_high_cnt
= 0;
240 battery
->temp_low_cnt
= 0;
241 battery
->temp_recover_cnt
= 0;
243 val
.intval
= battery
->pdata
->always_enable
? battery
->cable_type
:
244 enable
? battery
->cable_type
: POWER_SUPPLY_TYPE_BATTERY
;
246 psy_do_property(battery
->pdata
->charger_name
, set
,
247 POWER_SUPPLY_PROP_ONLINE
, val
);
249 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
250 POWER_SUPPLY_PROP_ONLINE
, val
);
252 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
253 if (battery
->wc_status
) {
254 psy_do_property(battery
->pdata
->charger_name
, get
,
255 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, val
);
256 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
257 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, val
);
260 val
.intval
= POWER_SUPPLY_TYPE_WIRELESS
;
262 val
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
264 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
265 POWER_SUPPLY_PROP_ONLINE
, val
);
269 if (battery
->pdata
->always_enable
) {
270 if (battery
->slate_mode
)
272 else if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
)
276 psy_do_property(battery
->pdata
->charger_name
, set
,
277 POWER_SUPPLY_PROP_CHARGING_ENABLED
, val
);
283 static int sec_bat_get_adc_data(struct sec_battery_info
*battery
,
284 int adc_ch
, int count
)
297 for (i
= 0; i
< count
; i
++) {
298 mutex_lock(&battery
->adclock
);
300 adc_data
= adc_read(battery
, adc_ch
);
302 adc_data
= adc_read(battery
->pdata
, adc_ch
);
304 mutex_unlock(&battery
->adclock
);
310 if (adc_data
> adc_max
)
312 else if (adc_data
< adc_min
)
318 adc_total
+= adc_data
;
321 return (adc_total
- adc_max
- adc_min
) / (count
- 2);
327 static unsigned long calculate_average_adc(
328 struct sec_battery_info *battery,
329 int channel, int adc)
331 unsigned int cnt = 0;
336 cnt = battery->adc_sample[channel].cnt;
337 total_adc = battery->adc_sample[channel].total_adc;
340 dev_err(battery->dev,
341 "%s : Invalid ADC : %d\n", __func__, adc);
342 adc = battery->adc_sample[channel].average_adc;
345 if (cnt < ADC_SAMPLE_COUNT) {
346 battery->adc_sample[channel].adc_arr[cnt] = adc;
347 battery->adc_sample[channel].index = cnt;
348 battery->adc_sample[channel].cnt = ++cnt;
351 average_adc = total_adc / cnt;
353 index = battery->adc_sample[channel].index;
354 if (++index >= ADC_SAMPLE_COUNT)
357 total_adc = total_adc -
358 battery->adc_sample[channel].adc_arr[index] + adc;
359 average_adc = total_adc / ADC_SAMPLE_COUNT;
361 battery->adc_sample[channel].adc_arr[index] = adc;
362 battery->adc_sample[channel].index = index;
365 battery->adc_sample[channel].total_adc = total_adc;
366 battery->adc_sample[channel].average_adc = average_adc;
372 static int sec_bat_get_adc_value(
373 struct sec_battery_info
*battery
, int channel
)
377 adc
= sec_bat_get_adc_data(battery
, channel
,
378 battery
->pdata
->adc_check_count
);
381 dev_err(battery
->dev
,
382 "%s: Error in ADC\n", __func__
);
389 static int sec_bat_get_charger_type_adc
390 (struct sec_battery_info
*battery
)
392 /* It is true something valid is
393 connected to the device for charging.
394 By default this something is considered to be USB.*/
395 int result
= POWER_SUPPLY_TYPE_USB
;
400 /* Do NOT check cable type when cable_switch_check() returns false
401 * and keep current cable type
403 if (battery
->pdata
->cable_switch_check
&&
404 !battery
->pdata
->cable_switch_check())
405 return battery
->cable_type
;
407 adc
= sec_bat_get_adc_value(battery
,
408 SEC_BAT_ADC_CHANNEL_CABLE_CHECK
);
410 /* Do NOT check cable type when cable_switch_normal() returns false
411 * and keep current cable type
413 if (battery
->pdata
->cable_switch_normal
&&
414 !battery
->pdata
->cable_switch_normal())
415 return battery
->cable_type
;
417 for (i
= 0; i
< SEC_SIZEOF_POWER_SUPPLY_TYPE
; i
++)
418 if ((adc
> battery
->pdata
->cable_adc_value
[i
].min
) &&
419 (adc
< battery
->pdata
->cable_adc_value
[i
].max
))
421 if (i
>= SEC_SIZEOF_POWER_SUPPLY_TYPE
)
422 dev_err(battery
->dev
,
423 "%s : default USB\n", __func__
);
427 dev_dbg(battery
->dev
, "%s : result(%d), adc(%d)\n",
428 __func__
, result
, adc
);
433 static bool sec_bat_check_vf_adc(struct sec_battery_info
*battery
)
437 adc
= sec_bat_get_adc_data(battery
,
438 SEC_BAT_ADC_CHANNEL_BAT_CHECK
,
439 battery
->pdata
->adc_check_count
);
442 dev_err(battery
->dev
, "%s: VF ADC error\n", __func__
);
443 adc
= battery
->check_adc_value
;
445 battery
->check_adc_value
= adc
;
447 if ((battery
->check_adc_value
<= battery
->pdata
->check_adc_max
) &&
448 (battery
->check_adc_value
>= battery
->pdata
->check_adc_min
)) {
451 dev_info(battery
->dev
, "%s: adc (%d)\n", __func__
, battery
->check_adc_value
);
456 static bool sec_bat_check_by_psy(struct sec_battery_info
*battery
)
459 union power_supply_propval value
;
463 switch (battery
->pdata
->battery_check_type
) {
464 case SEC_BATTERY_CHECK_PMIC
:
465 psy_name
= battery
->pdata
->pmic_name
;
467 case SEC_BATTERY_CHECK_FUELGAUGE
:
468 psy_name
= battery
->pdata
->fuelgauge_name
;
470 case SEC_BATTERY_CHECK_CHARGER
:
471 psy_name
= battery
->pdata
->charger_name
;
474 dev_err(battery
->dev
,
475 "%s: Invalid Battery Check Type\n", __func__
);
477 goto battery_check_error
;
481 psy_do_property(psy_name
, get
,
482 POWER_SUPPLY_PROP_PRESENT
, value
);
483 ret
= (bool)value
.intval
;
489 static bool sec_bat_check(struct sec_battery_info
*battery
)
494 if (battery
->factory_mode
|| battery
->is_jig_on
) {
495 dev_dbg(battery
->dev
, "%s: No need to check in factory mode\n",
500 if (battery
->health
!= POWER_SUPPLY_HEALTH_GOOD
&&
501 battery
->health
!= POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
) {
502 dev_dbg(battery
->dev
, "%s: No need to check\n", __func__
);
506 switch (battery
->pdata
->battery_check_type
) {
507 case SEC_BATTERY_CHECK_ADC
:
508 if(battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
)
509 ret
= battery
->present
;
511 ret
= sec_bat_check_vf_adc(battery
);
513 case SEC_BATTERY_CHECK_INT
:
514 case SEC_BATTERY_CHECK_CALLBACK
:
515 if(battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
516 ret
= battery
->present
;
518 if (battery
->pdata
->check_battery_callback
)
519 ret
= battery
->pdata
->check_battery_callback();
522 case SEC_BATTERY_CHECK_PMIC
:
523 case SEC_BATTERY_CHECK_FUELGAUGE
:
524 case SEC_BATTERY_CHECK_CHARGER
:
525 ret
= sec_bat_check_by_psy(battery
);
527 case SEC_BATTERY_CHECK_NONE
:
528 dev_dbg(battery
->dev
, "%s: No Check\n", __func__
);
536 static bool sec_bat_get_cable_type(
537 struct sec_battery_info
*battery
,
538 int cable_source_type
)
544 cable_type
= battery
->cable_type
;
546 if (cable_source_type
& SEC_BATTERY_CABLE_SOURCE_CALLBACK
) {
547 if (battery
->pdata
->check_cable_callback
)
549 battery
->pdata
->check_cable_callback();
552 if (cable_source_type
& SEC_BATTERY_CABLE_SOURCE_ADC
) {
553 if (gpio_get_value_cansleep(
554 battery
->pdata
->bat_gpio_ta_nconnected
) ^
555 battery
->pdata
->bat_polarity_ta_nconnected
)
556 cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
559 sec_bat_get_charger_type_adc(battery
);
562 if (battery
->cable_type
== cable_type
) {
563 dev_dbg(battery
->dev
,
564 "%s: No need to change cable status\n", __func__
);
566 if (cable_type
< POWER_SUPPLY_TYPE_BATTERY
||
567 cable_type
>= SEC_SIZEOF_POWER_SUPPLY_TYPE
) {
568 dev_err(battery
->dev
,
569 "%s: Invalid cable type\n", __func__
);
571 battery
->cable_type
= cable_type
;
572 if (battery
->pdata
->check_cable_result_callback
)
573 battery
->pdata
->check_cable_result_callback(
574 battery
->cable_type
);
578 dev_dbg(battery
->dev
, "%s: Cable Changed (%d)\n",
579 __func__
, battery
->cable_type
);
586 static void sec_bat_set_charging_status(struct sec_battery_info
*battery
,
588 union power_supply_propval value
;
590 case POWER_SUPPLY_STATUS_NOT_CHARGING
:
591 case POWER_SUPPLY_STATUS_DISCHARGING
:
592 if((battery
->status
== POWER_SUPPLY_STATUS_FULL
) ||
593 (battery
->capacity
== 100)){
594 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
595 value
.intval
= battery
->capacity
;
597 value
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
599 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
600 POWER_SUPPLY_PROP_CHARGE_FULL
, value
);
602 /* To get SOC value (NOT raw SOC), need to reset value */
604 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
605 POWER_SUPPLY_PROP_CAPACITY
, value
);
606 battery
->capacity
= value
.intval
;
608 battery
->expired_time
= battery
->pdata
->expired_time
;
609 battery
->prev_safety_time
= 0;
614 battery
->status
= status
;
617 static bool sec_bat_battery_cable_check(struct sec_battery_info
*battery
)
619 if (!sec_bat_check(battery
)) {
620 if (battery
->check_count
< battery
->pdata
->check_count
)
621 battery
->check_count
++;
623 dev_err(battery
->dev
,
624 "%s: Battery Disconnected\n", __func__
);
626 if (battery
->pdata
->always_enable
) {
627 union power_supply_propval val
;
630 psy_do_property(battery
->pdata
->charger_name
, set
,
631 POWER_SUPPLY_PROP_CHARGING_ENABLED
, val
);
634 battery
->present
= false;
635 battery
->health
= POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
;
637 if (battery
->status
!=
638 POWER_SUPPLY_STATUS_DISCHARGING
) {
639 sec_bat_set_charging_status(battery
,
640 POWER_SUPPLY_STATUS_NOT_CHARGING
);
641 if(battery
->siop_level
!= 100)
642 battery
->stop_timer
= true ;
643 sec_bat_set_charge(battery
, false);
646 if (battery
->pdata
->check_battery_result_callback
)
648 check_battery_result_callback();
652 battery
->check_count
= 0;
654 battery
->present
= true;
656 if (battery
->health
== POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
) {
657 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
659 if (battery
->status
== POWER_SUPPLY_STATUS_NOT_CHARGING
) {
660 sec_bat_set_charging_status(battery
,
661 POWER_SUPPLY_STATUS_CHARGING
);
662 #if defined(CONFIG_BATTERY_SWELLING)
663 if (!battery
->swelling_mode
)
664 sec_bat_set_charge(battery
, true);
666 sec_bat_set_charge(battery
, true);
671 dev_dbg(battery
->dev
, "%s: Battery Connected\n", __func__
);
673 if (battery
->pdata
->cable_check_type
&
674 SEC_BATTERY_CABLE_CHECK_POLLING
) {
675 if (sec_bat_get_cable_type(battery
,
676 battery
->pdata
->cable_source_type
)) {
677 wake_lock(&battery
->cable_wake_lock
);
678 queue_delayed_work_on(0, battery
->monitor_wqueue
,
679 &battery
->cable_work
, 0);
685 static int sec_bat_ovp_uvlo_by_psy(struct sec_battery_info
*battery
)
688 union power_supply_propval value
;
690 value
.intval
= POWER_SUPPLY_HEALTH_GOOD
;
692 switch (battery
->pdata
->ovp_uvlo_check_type
) {
693 case SEC_BATTERY_OVP_UVLO_PMICPOLLING
:
694 psy_name
= battery
->pdata
->pmic_name
;
696 case SEC_BATTERY_OVP_UVLO_CHGPOLLING
:
697 psy_name
= battery
->pdata
->charger_name
;
700 dev_err(battery
->dev
,
701 "%s: Invalid OVP/UVLO Check Type\n", __func__
);
702 goto ovp_uvlo_check_error
;
706 psy_do_property(psy_name
, get
,
707 POWER_SUPPLY_PROP_HEALTH
, value
);
709 ovp_uvlo_check_error
:
713 static bool sec_bat_ovp_uvlo_result(
714 struct sec_battery_info
*battery
, int health
)
716 if (battery
->health
!= health
) {
717 battery
->health
= health
;
719 case POWER_SUPPLY_HEALTH_GOOD
:
720 dev_info(battery
->dev
, "%s: Safe voltage\n", __func__
);
721 dev_info(battery
->dev
, "%s: is_recharging : %d\n", __func__
, battery
->is_recharging
);
722 sec_bat_set_charging_status(battery
,
723 POWER_SUPPLY_STATUS_CHARGING
);
724 if (battery
->siop_level
!= 100)
725 battery
->stop_timer
= true;
726 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
727 #if defined(CONFIG_BATTERY_SWELLING)
728 if (!battery
->swelling_mode
)
729 sec_bat_set_charge(battery
, true);
731 sec_bat_set_charge(battery
, true);
734 case POWER_SUPPLY_HEALTH_OVERVOLTAGE
:
735 case POWER_SUPPLY_HEALTH_UNDERVOLTAGE
:
736 dev_info(battery
->dev
,
737 "%s: Unsafe voltage (%d)\n",
739 sec_bat_set_charging_status(battery
,
740 POWER_SUPPLY_STATUS_NOT_CHARGING
);
741 sec_bat_set_charge(battery
, false);
742 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
743 battery
->is_recharging
= false;
744 /* Take the wakelock during 10 seconds
745 when over-voltage status is detected */
746 wake_lock_timeout(&battery
->vbus_wake_lock
, HZ
* 10);
748 case POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE
:
749 dev_info(battery
->dev
,
750 "%s: Watchdog Expired, Restart charger (%d)\n",
752 sec_bat_set_charge(battery
, true);
753 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
756 power_supply_changed(&battery
->psy_bat
);
763 static bool sec_bat_ovp_uvlo(struct sec_battery_info
*battery
)
767 if (battery
->factory_mode
|| battery
->is_jig_on
) {
768 dev_info(battery
->dev
,
769 "%s: No need to check in factory mode\n",
772 } else if ((battery
->status
== POWER_SUPPLY_STATUS_FULL
) &&
773 (battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
)) {
774 dev_dbg(battery
->dev
, "%s: No need to check in Full status", __func__
);
778 if (battery
->health
!= POWER_SUPPLY_HEALTH_GOOD
&&
779 battery
->health
!= POWER_SUPPLY_HEALTH_OVERVOLTAGE
&&
780 battery
->health
!= POWER_SUPPLY_HEALTH_UNDERVOLTAGE
&&
781 battery
->health
!= POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE
) {
782 dev_dbg(battery
->dev
, "%s: No need to check\n", __func__
);
786 health
= battery
->health
;
788 switch (battery
->pdata
->ovp_uvlo_check_type
) {
789 case SEC_BATTERY_OVP_UVLO_CALLBACK
:
790 if (battery
->pdata
->ovp_uvlo_callback
)
791 health
= battery
->pdata
->ovp_uvlo_callback();
793 case SEC_BATTERY_OVP_UVLO_PMICPOLLING
:
794 case SEC_BATTERY_OVP_UVLO_CHGPOLLING
:
795 health
= sec_bat_ovp_uvlo_by_psy(battery
);
797 case SEC_BATTERY_OVP_UVLO_PMICINT
:
798 case SEC_BATTERY_OVP_UVLO_CHGINT
:
799 /* nothing for interrupt check */
804 return sec_bat_ovp_uvlo_result(battery
, health
);
807 static bool sec_bat_check_recharge(struct sec_battery_info
*battery
)
809 int recharging_voltage
;
810 #if defined(CONFIG_BATTERY_SWELLING)
811 if (battery
->swelling_mode
) {
812 pr_info("%s: Skip normal recharge check routine for swelling mode\n",
817 if ((battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) &&
818 (battery
->pdata
->full_condition_type
&
819 SEC_BATTERY_FULL_CONDITION_NOTIMEFULL
) &&
820 (battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
)) {
821 dev_info(battery
->dev
,
822 "%s: Re-charging by NOTIMEFULL (%d)\n",
823 __func__
, battery
->capacity
);
824 goto check_recharge_check_count
;
827 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
&&
828 battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
) {
829 recharging_voltage
= battery
->pdata
->recharge_condition_vcell
;
830 if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
) {
831 recharging_voltage
= battery
->pdata
->chg_float_voltage
- 150; // float voltage - 150mV
832 dev_info(battery
->dev
, "%s: recharge voltage changed by low temp(%d)\n",
833 __func__
, recharging_voltage
);
835 if ((battery
->pdata
->recharge_condition_type
&
836 SEC_BATTERY_RECHARGE_CONDITION_SOC
) &&
837 (battery
->capacity
<=
838 battery
->pdata
->recharge_condition_soc
)) {
839 battery
->expired_time
= battery
->pdata
->recharging_expired_time
;
840 battery
->prev_safety_time
= 0;
841 dev_info(battery
->dev
,
842 "%s: Re-charging by SOC (%d)\n",
843 __func__
, battery
->capacity
);
844 goto check_recharge_check_count
;
847 if ((battery
->pdata
->recharge_condition_type
&
848 SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL
) &&
849 (battery
->voltage_avg
<=
850 recharging_voltage
)) {
851 battery
->expired_time
= battery
->pdata
->recharging_expired_time
;
852 battery
->prev_safety_time
= 0;
853 dev_info(battery
->dev
,
854 "%s: Re-charging by average VCELL (%d)\n",
855 __func__
, battery
->voltage_avg
);
856 goto check_recharge_check_count
;
859 if ((battery
->pdata
->recharge_condition_type
&
860 SEC_BATTERY_RECHARGE_CONDITION_VCELL
) &&
861 (battery
->voltage_now
<=
862 recharging_voltage
)) {
863 battery
->expired_time
= battery
->pdata
->recharging_expired_time
;
864 battery
->prev_safety_time
= 0;
865 dev_info(battery
->dev
,
866 "%s: Re-charging by VCELL (%d)\n",
867 __func__
, battery
->voltage_now
);
868 goto check_recharge_check_count
;
872 battery
->recharge_check_cnt
= 0;
875 check_recharge_check_count
:
876 if (battery
->recharge_check_cnt
<
877 battery
->pdata
->recharge_check_count
)
878 battery
->recharge_check_cnt
++;
879 dev_dbg(battery
->dev
,
880 "%s: recharge count = %d\n",
881 __func__
, battery
->recharge_check_cnt
);
883 if (battery
->recharge_check_cnt
>=
884 battery
->pdata
->recharge_check_count
)
890 static bool sec_bat_voltage_check(struct sec_battery_info
*battery
)
892 union power_supply_propval value
;
894 if (battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
895 dev_dbg(battery
->dev
,
896 "%s: Charging Disabled\n", __func__
);
901 if (sec_bat_ovp_uvlo(battery
)) {
902 if (battery
->pdata
->ovp_uvlo_result_callback
)
904 ovp_uvlo_result_callback(battery
->health
);
908 if ((battery
->status
== POWER_SUPPLY_STATUS_FULL
) &&
909 #if defined(CONFIG_BATTERY_SWELLING)
910 (battery
->charging_mode
== SEC_BATTERY_CHARGING_2ND
||
911 battery
->is_recharging
|| battery
->swelling_mode
)) {
913 (battery
->charging_mode
== SEC_BATTERY_CHARGING_2ND
||
914 battery
->is_recharging
)) {
917 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
918 POWER_SUPPLY_PROP_CAPACITY
, value
);
920 battery
->pdata
->full_condition_soc
&&
921 battery
->voltage_now
<
922 (battery
->pdata
->recharge_condition_vcell
- 50)) {
923 sec_bat_set_charging_status(battery
,
924 POWER_SUPPLY_STATUS_CHARGING
);
925 if (battery
->siop_level
!= 100)
926 battery
->stop_timer
= true;
927 battery
->voltage_now
= 1080;
928 battery
->voltage_avg
= 1080;
929 power_supply_changed(&battery
->psy_bat
);
930 dev_info(battery
->dev
,
931 "%s: battery status full -> charging, RepSOC(%d)\n", __func__
, value
.intval
);
935 /* Re-Charging check */
936 if (sec_bat_check_recharge(battery
)) {
937 if (battery
->pdata
->full_check_type
!=
938 SEC_BATTERY_FULLCHARGED_NONE
)
939 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
941 battery
->charging_mode
= SEC_BATTERY_CHARGING_2ND
;
942 battery
->is_recharging
= true;
943 #if defined(CONFIG_BATTERY_SWELLING)
944 if (!battery
->swelling_mode
)
945 sec_bat_set_charge(battery
, true);
947 sec_bat_set_charge(battery
, true);
955 static bool sec_bat_get_temperature_by_adc(
956 struct sec_battery_info
*battery
,
957 enum sec_battery_adc_channel channel
,
958 union power_supply_propval
*value
)
965 const sec_bat_adc_table_data_t
*temp_adc_table
;
966 unsigned int temp_adc_table_size
;
968 temp_adc
= sec_bat_get_adc_value(battery
, channel
);
973 case SEC_BAT_ADC_CHANNEL_TEMP
:
974 temp_adc_table
= battery
->pdata
->temp_adc_table
;
975 temp_adc_table_size
=
976 battery
->pdata
->temp_adc_table_size
;
977 battery
->temp_adc
= temp_adc
;
979 case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT
:
980 temp_adc_table
= battery
->pdata
->temp_amb_adc_table
;
981 temp_adc_table_size
=
982 battery
->pdata
->temp_amb_adc_table_size
;
983 battery
->temp_ambient_adc
= temp_adc
;
985 case SEC_BAT_ADC_CHANNEL_CHG_TEMP
:
986 temp_adc_table
= battery
->pdata
->chg_temp_adc_table
;
987 temp_adc_table_size
=
988 battery
->pdata
->chg_temp_adc_table_size
;
989 battery
->chg_temp_adc
= temp_adc
;
992 dev_err(battery
->dev
,
993 "%s: Invalid Property\n", __func__
);
997 if (temp_adc_table
[0].adc
>= temp_adc
) {
998 temp
= temp_adc_table
[0].data
;
999 goto temp_by_adc_goto
;
1000 } else if (temp_adc_table
[temp_adc_table_size
-1].adc
<= temp_adc
) {
1001 temp
= temp_adc_table
[temp_adc_table_size
-1].data
;
1002 goto temp_by_adc_goto
;
1005 high
= temp_adc_table_size
- 1;
1007 while (low
<= high
) {
1008 mid
= (low
+ high
) / 2;
1009 if (temp_adc_table
[mid
].adc
> temp_adc
)
1011 else if (temp_adc_table
[mid
].adc
< temp_adc
)
1014 temp
= temp_adc_table
[mid
].data
;
1015 goto temp_by_adc_goto
;
1019 temp
= temp_adc_table
[high
].data
;
1020 temp
+= ((temp_adc_table
[low
].data
- temp_adc_table
[high
].data
) *
1021 (temp_adc
- temp_adc_table
[high
].adc
)) /
1022 (temp_adc_table
[low
].adc
- temp_adc_table
[high
].adc
);
1025 value
->intval
= temp
;
1027 dev_dbg(battery
->dev
,
1028 "%s: Temp(%d), Temp-ADC(%d)\n",
1029 __func__
, temp
, temp_adc
);
1034 static bool sec_bat_temperature(
1035 struct sec_battery_info
*battery
)
1040 if (battery
->pdata
->event_check
&& battery
->event
) {
1041 battery
->temp_highlimit_threshold
=
1042 battery
->pdata
->temp_highlimit_threshold_event
;
1043 battery
->temp_highlimit_recovery
=
1044 battery
->pdata
->temp_highlimit_recovery_event
;
1045 battery
->temp_high_threshold
=
1046 battery
->pdata
->temp_high_threshold_event
;
1047 battery
->temp_high_recovery
=
1048 battery
->pdata
->temp_high_recovery_event
;
1049 battery
->temp_low_recovery
=
1050 battery
->pdata
->temp_low_recovery_event
;
1051 battery
->temp_low_threshold
=
1052 battery
->pdata
->temp_low_threshold_event
;
1053 } else if (lpcharge
) {
1054 battery
->temp_highlimit_threshold
=
1055 battery
->pdata
->temp_highlimit_threshold_lpm
;
1056 battery
->temp_highlimit_recovery
=
1057 battery
->pdata
->temp_highlimit_recovery_lpm
;
1058 battery
->temp_high_threshold
=
1059 battery
->pdata
->temp_high_threshold_lpm
;
1060 battery
->temp_high_recovery
=
1061 battery
->pdata
->temp_high_recovery_lpm
;
1062 battery
->temp_low_recovery
=
1063 battery
->pdata
->temp_low_recovery_lpm
;
1064 battery
->temp_low_threshold
=
1065 battery
->pdata
->temp_low_threshold_lpm
;
1067 battery
->temp_highlimit_threshold
=
1068 battery
->pdata
->temp_highlimit_threshold_normal
;
1069 battery
->temp_highlimit_recovery
=
1070 battery
->pdata
->temp_highlimit_recovery_normal
;
1071 battery
->temp_high_threshold
=
1072 battery
->pdata
->temp_high_threshold_normal
;
1073 battery
->temp_high_recovery
=
1074 battery
->pdata
->temp_high_recovery_normal
;
1075 battery
->temp_low_recovery
=
1076 battery
->pdata
->temp_low_recovery_normal
;
1077 battery
->temp_low_threshold
=
1078 battery
->pdata
->temp_low_threshold_normal
;
1081 dev_info(battery
->dev
,
1082 "%s: HLT(%d) HLR(%d) HT(%d), HR(%d), LT(%d), LR(%d)\n",
1083 __func__
, battery
->temp_highlimit_threshold
,
1084 battery
->temp_highlimit_recovery
,
1085 battery
->temp_high_threshold
,
1086 battery
->temp_high_recovery
,
1087 battery
->temp_low_threshold
,
1088 battery
->temp_low_recovery
);
1092 #if defined(CONFIG_BATTERY_SWELLING)
1093 static void sec_bat_swelling_check(struct sec_battery_info
*battery
, int temperature
)
1095 union power_supply_propval val
;
1096 bool en_swelling
= false, en_rechg
= false;
1097 int swelling_rechg_voltage
;
1099 psy_do_property(battery
->pdata
->charger_name
, get
,
1100 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1102 pr_info("%s: status(%d), swell_mode(%d:%d), cv(0x%02x), temp(%d)\n",
1103 __func__
, battery
->status
, battery
->swelling_mode
,
1104 battery
->charging_block
, val
.intval
, temperature
);
1107 under voltage over voltage, battery missing */
1108 if ((battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) ||\
1109 (battery
->status
== POWER_SUPPLY_STATUS_NOT_CHARGING
)) {
1110 pr_info("%s: DISCHARGING or NOT-CHARGING. stop swelling mode\n", __func__
);
1111 battery
->swelling_mode
= false;
1112 sec_bat_set_current_event(battery
, 0,
1113 (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
| SEC_BAT_CURRENT_EVENT_LOW_TEMP
|
1114 SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
));
1115 goto skip_swelling_chek
;
1118 if (!battery
->swelling_mode
) {
1119 if (((temperature
>= battery
->pdata
->swelling_high_temp_block
) ||
1120 (temperature
<= battery
->pdata
->swelling_low_temp_block_2nd
)) &&
1121 battery
->pdata
->temp_check_type
) {
1123 if (temperature
>= battery
->pdata
->swelling_high_temp_block
&&
1124 battery
->pdata
->event_check
&&
1126 pr_info("%s: skip check swelling in high temperature event mode(%d)\n",
1127 __func__
, battery
->event
);
1131 pr_info("%s: swelling mode start. stop charging\n", __func__
);
1132 battery
->swelling_mode
= true;
1133 battery
->swelling_full_check_cnt
= 0;
1134 sec_bat_set_charge(battery
, false);
1136 } else if ((battery
->temperature
<= battery
->pdata
->swelling_low_temp_block_1st
) &&
1137 !(battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
)) {
1138 pr_info("%s: low temperature reduce current\n", __func__
);
1139 sec_bat_set_current_event(battery
, SEC_BAT_CURRENT_EVENT_LOW_TEMP
,
1140 SEC_BAT_CURRENT_EVENT_LOW_TEMP
);
1141 } else if ((battery
->temperature
>= battery
->pdata
->swelling_low_temp_recov_1st
) &&
1142 (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
)) {
1143 pr_info("%s: normal temperature recover current\n", __func__
);
1144 sec_bat_set_current_event(battery
, 0, SEC_BAT_CURRENT_EVENT_LOW_TEMP
);
1148 if (!battery
->voltage_now
)
1151 if (battery
->swelling_mode
) {
1152 if (temperature
<= battery
->pdata
->swelling_low_temp_recov_2nd
)
1153 swelling_rechg_voltage
= battery
->pdata
->swelling_low_rechg_voltage
;
1155 swelling_rechg_voltage
= battery
->pdata
->swelling_high_rechg_voltage
;
1157 if ((temperature
<= battery
->pdata
->swelling_high_temp_recov
) &&
1158 (temperature
>= battery
->pdata
->swelling_low_temp_recov_2nd
)) {
1159 pr_info("%s: swelling mode end. restart charging\n", __func__
);
1160 battery
->swelling_mode
= false;
1161 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
1162 sec_bat_set_current_event(battery
, 0,
1163 (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
|
1164 SEC_BAT_CURRENT_EVENT_LOW_TEMP
|
1165 SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
));
1166 sec_bat_set_charge(battery
, true);
1167 /* restore 4.4V float voltage */
1168 val
.intval
= battery
->pdata
->swelling_normal_float_voltage
;
1169 psy_do_property(battery
->pdata
->charger_name
, set
,
1170 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1171 } else if (battery
->voltage_now
< swelling_rechg_voltage
&&
1172 battery
->charging_block
) {
1173 pr_info("%s: swelling mode recharging start. Vbatt(%d)\n",
1174 __func__
, battery
->voltage_now
);
1175 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
1177 sec_bat_set_charge(battery
, true);
1178 /* change 4.20V float voltage */
1179 val
.intval
= battery
->pdata
->swelling_drop_float_voltage
;
1180 psy_do_property(battery
->pdata
->charger_name
, set
,
1181 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1182 if ((temperature
<= battery
->pdata
->swelling_low_temp_recov_2nd
) &&
1183 (battery
->pdata
->swelling_low_temp_current
> 0)) {
1184 pr_info("%s: swelling mode reduce charging current(temp:%d)\n",
1185 __func__
, temperature
);
1186 sec_bat_set_current_event(battery
, SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
,
1187 SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
);
1188 } else if ((temperature
>= battery
->pdata
->swelling_high_temp_recov
) &&
1189 (battery
->pdata
->swelling_high_temp_current
> 0)) {
1190 pr_info("%s: swelling mode reduce charging current(temp:%d)\n",
1191 __func__
, temperature
);
1192 sec_bat_set_current_event(battery
, SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
,
1193 SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
);
1198 if (en_swelling
&& !en_rechg
) {
1199 pr_info("%s : SAFETY TIME RESET (SWELLING MODE CHARING STOP!)\n", __func__
);
1200 battery
->expired_time
= battery
->pdata
->expired_time
;
1201 battery
->prev_safety_time
= 0;
1205 dev_dbg(battery
->dev
, "%s end\n", __func__
);
1209 static void set_swelling_current(struct sec_battery_info
*battery
)
1211 int charging_current
= battery
->pdata
->charging_current
[battery
->cable_type
].fast_charging_current
;
1213 union power_supply_propval value
= {0, };
1215 if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
) {
1216 charging_current
= (charging_current
> battery
->pdata
->swelling_low_temp_current
) ?
1217 battery
->pdata
->swelling_low_temp_current
: charging_current
;
1218 } else if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
) {
1219 charging_current
= (charging_current
> battery
->pdata
->swelling_high_temp_current
) ?
1220 battery
->pdata
->swelling_high_temp_current
: charging_current
;
1221 } else if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
) {
1222 charging_current
= (charging_current
> battery
->pdata
->swelling_low_temp_current
) ?
1223 battery
->pdata
->swelling_low_temp_current
: charging_current
;
1226 if (battery
->charging_current
!= charging_current
) {
1227 value
.intval
= charging_current
;
1228 pr_info(" %s Charging_current = %d \n", __func__
, charging_current
);
1229 psy_do_property(battery
->pdata
->charger_name
, set
,
1230 POWER_SUPPLY_PROP_CURRENT_AVG
, value
);
1231 battery
->charging_current
= charging_current
;
1235 #if defined(CONFIG_BATTERY_AGE_FORECAST)
1236 static bool sec_bat_set_aging_step(struct sec_battery_info
*battery
, int step
)
1238 union power_supply_propval value
;
1240 if (battery
->pdata
->num_age_step
<= 0 || step
< 0 || step
>= battery
->pdata
->num_age_step
) {
1241 pr_info("%s: [AGE] abnormal age step : %d/%d\n",
1242 __func__
, step
, battery
->pdata
->num_age_step
-1);
1246 if (battery
->temperature
< 50) {
1247 pr_info("%s: [AGE] skip (temperature:%d)\n", __func__
, battery
->temperature
< 50);
1251 battery
->pdata
->age_step
= step
;
1254 battery
->pdata
->chg_float_voltage
=
1255 battery
->pdata
->age_data
[battery
->pdata
->age_step
].float_voltage
;
1256 battery
->pdata
->swelling_normal_float_voltage
=
1257 battery
->pdata
->chg_float_voltage
;
1258 if (!battery
->swelling_mode
) {
1259 value
.intval
= battery
->pdata
->chg_float_voltage
;
1260 psy_do_property(battery
->pdata
->charger_name
, set
,
1261 POWER_SUPPLY_PROP_VOLTAGE_MAX
, value
);
1264 /* full/recharge condition */
1265 battery
->pdata
->recharge_condition_vcell
=
1266 battery
->pdata
->age_data
[battery
->pdata
->age_step
].recharge_condition_vcell
;
1267 battery
->pdata
->full_condition_soc
=
1268 battery
->pdata
->age_data
[battery
->pdata
->age_step
].full_condition_soc
;
1269 battery
->pdata
->full_condition_vcell
=
1270 battery
->pdata
->age_data
[battery
->pdata
->age_step
].full_condition_vcell
;
1271 #if defined(CONFIG_FUELGAUGE_S2MU003)
1272 value
.intval
= battery
->pdata
->age_step
;
1273 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
1274 POWER_SUPPLY_PROP_UPDATE_BATTERY_DATA
, value
);
1276 value
.intval
= battery
->pdata
->full_condition_soc
;
1277 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
1278 POWER_SUPPLY_PROP_CAPACITY_LEVEL
, value
);
1280 dev_info(battery
->dev
,
1281 "%s: Step(%d/%d), Cycle(%d), float_v(%d), r_v(%d), f_s(%d), f_vl(%d)\n",
1283 battery
->pdata
->age_step
, battery
->pdata
->num_age_step
-1, battery
->batt_cycle
,
1284 battery
->pdata
->chg_float_voltage
,
1285 battery
->pdata
->recharge_condition_vcell
,
1286 battery
->pdata
->full_condition_soc
,
1287 battery
->pdata
->full_condition_vcell
);
1292 static void sec_bat_aging_check(struct sec_battery_info
*battery
)
1294 int prev_step
= battery
->pdata
->age_step
;
1298 if (battery
->pdata
->num_age_step
<= 0)
1301 if (battery
->temperature
< 50) {
1302 pr_info("%s: [AGE] skip (temperature:%d)\n", __func__
, battery
->temperature
);
1306 for (calc_step
= battery
->pdata
->num_age_step
- 1; calc_step
>= 0; calc_step
--) {
1307 if (battery
->pdata
->age_data
[calc_step
].cycle
<= battery
->batt_cycle
)
1310 dev_info(battery
->dev
,
1311 "%s: [Long life] prev_step = %d, calc_step = %d\n", __func__
, prev_step
, calc_step
);
1312 if (calc_step
== prev_step
)
1315 ret
= sec_bat_set_aging_step(battery
, calc_step
);
1316 dev_info(battery
->dev
,
1317 "%s: %s change step (%d->%d), Cycle(%d)\n",
1318 __func__
, ret
? "Succeed in" : "Fail to",
1319 prev_step
, battery
->pdata
->age_step
, battery
->batt_cycle
);
1323 static bool sec_bat_temperature_check(
1324 struct sec_battery_info
*battery
)
1329 if (battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
1330 dev_dbg(battery
->dev
,
1331 "%s: Charging Disabled\n", __func__
);
1335 if (battery
->health
!= POWER_SUPPLY_HEALTH_GOOD
&&
1336 battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEAT
&&
1337 battery
->health
!= POWER_SUPPLY_HEALTH_COLD
&&
1338 battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1339 dev_dbg(battery
->dev
, "%s: No need to check\n", __func__
);
1343 sec_bat_temperature(battery
);
1345 switch (battery
->pdata
->temp_check_type
) {
1346 case SEC_BATTERY_TEMP_CHECK_ADC
:
1347 temp_value
= battery
->temp_adc
;
1349 case SEC_BATTERY_TEMP_CHECK_TEMP
:
1350 temp_value
= battery
->temperature
;
1353 dev_err(battery
->dev
,
1354 "%s: Invalid Temp Check Type\n", __func__
);
1357 pre_health
= battery
->health
;
1359 if (temp_value
>= battery
->temp_highlimit_threshold
) {
1360 if (battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1361 if (battery
->temp_highlimit_cnt
<
1362 battery
->pdata
->temp_check_count
) {
1363 battery
->temp_highlimit_cnt
++;
1364 battery
->temp_high_cnt
= 0;
1365 battery
->temp_low_cnt
= 0;
1366 battery
->temp_recover_cnt
= 0;
1368 dev_dbg(battery
->dev
,
1369 "%s: highlimit count = %d\n",
1370 __func__
, battery
->temp_highlimit_cnt
);
1372 } else if (temp_value
>= battery
->temp_high_threshold
) {
1373 if (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1374 if (temp_value
<= battery
->temp_highlimit_recovery
) {
1375 if (battery
->temp_recover_cnt
<
1376 battery
->pdata
->temp_check_count
) {
1377 battery
->temp_recover_cnt
++;
1378 battery
->temp_highlimit_cnt
= 0;
1379 battery
->temp_high_cnt
= 0;
1380 battery
->temp_low_cnt
= 0;
1382 dev_dbg(battery
->dev
,
1383 "%s: recovery count = %d\n",
1384 __func__
, battery
->temp_recover_cnt
);
1386 } else if (battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEAT
) {
1387 if (battery
->temp_high_cnt
<
1388 battery
->pdata
->temp_check_count
) {
1389 battery
->temp_high_cnt
++;
1390 battery
->temp_highlimit_cnt
= 0;
1391 battery
->temp_low_cnt
= 0;
1392 battery
->temp_recover_cnt
= 0;
1394 dev_dbg(battery
->dev
,
1395 "%s: high count = %d\n",
1396 __func__
, battery
->temp_high_cnt
);
1398 } else if ((temp_value
<= battery
->temp_high_recovery
) &&
1399 (temp_value
>= battery
->temp_low_recovery
)) {
1400 if (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEAT
||
1401 battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
||
1402 battery
->health
== POWER_SUPPLY_HEALTH_COLD
) {
1403 if (battery
->temp_recover_cnt
<
1404 battery
->pdata
->temp_check_count
) {
1405 battery
->temp_recover_cnt
++;
1406 battery
->temp_highlimit_cnt
= 0;
1407 battery
->temp_high_cnt
= 0;
1408 battery
->temp_low_cnt
= 0;
1410 dev_dbg(battery
->dev
,
1411 "%s: recovery count = %d\n",
1412 __func__
, battery
->temp_recover_cnt
);
1414 } else if (temp_value
<= battery
->temp_low_threshold
) {
1415 if (battery
->health
!= POWER_SUPPLY_HEALTH_COLD
) {
1416 if (battery
->temp_low_cnt
<
1417 battery
->pdata
->temp_check_count
) {
1418 battery
->temp_low_cnt
++;
1419 battery
->temp_highlimit_cnt
= 0;
1420 battery
->temp_high_cnt
= 0;
1421 battery
->temp_recover_cnt
= 0;
1423 dev_dbg(battery
->dev
,
1424 "%s: low count = %d\n",
1425 __func__
, battery
->temp_low_cnt
);
1428 battery
->temp_highlimit_cnt
= 0;
1429 battery
->temp_high_cnt
= 0;
1430 battery
->temp_low_cnt
= 0;
1431 battery
->temp_recover_cnt
= 0;
1434 if (battery
->temp_highlimit_cnt
>=
1435 battery
->pdata
->temp_check_count
) {
1436 battery
->health
= POWER_SUPPLY_HEALTH_OVERHEATLIMIT
;
1437 battery
->temp_highlimit_cnt
= 0;
1438 } else if (battery
->temp_high_cnt
>=
1439 battery
->pdata
->temp_check_count
) {
1440 battery
->health
= POWER_SUPPLY_HEALTH_OVERHEAT
;
1441 battery
->temp_high_cnt
= 0;
1442 } else if (battery
->temp_low_cnt
>=
1443 battery
->pdata
->temp_check_count
) {
1444 battery
->health
= POWER_SUPPLY_HEALTH_COLD
;
1445 battery
->temp_low_cnt
= 0;
1446 } else if (battery
->temp_recover_cnt
>=
1447 battery
->pdata
->temp_check_count
) {
1448 if (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1449 battery
->health
= POWER_SUPPLY_HEALTH_OVERHEAT
;
1451 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
1452 union power_supply_propval value
;
1454 psy_do_property(battery
->pdata
->charger_name
, get
,
1455 POWER_SUPPLY_PROP_VOLTAGE_MAX
, value
);
1456 if (value
.intval
<= battery
->pdata
->swelling_normal_float_voltage
) {
1457 value
.intval
= battery
->pdata
->swelling_normal_float_voltage
;
1458 psy_do_property(battery
->pdata
->charger_name
, set
,
1459 POWER_SUPPLY_PROP_VOLTAGE_MAX
, value
);
1462 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
1464 battery
->temp_recover_cnt
= 0;
1466 if (pre_health
!= battery
->health
) {
1467 battery
->health_change
= true;
1468 dev_info(battery
->dev
, "%s, health_change true\n", __func__
);
1470 battery
->health_change
= false;
1473 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERHEAT
) ||
1474 (battery
->health
== POWER_SUPPLY_HEALTH_COLD
) ||
1475 (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
)) {
1476 if (battery
->status
!= POWER_SUPPLY_STATUS_NOT_CHARGING
) {
1477 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
1478 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERHEAT
) ||
1479 (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
)) {
1480 union power_supply_propval val
;
1481 /* change 4.20V float voltage */
1482 val
.intval
= battery
->pdata
->swelling_drop_float_voltage
;
1483 psy_do_property(battery
->pdata
->charger_name
, set
,
1484 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1487 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
1488 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
1489 union power_supply_propval val
;
1490 val
.intval
= battery
->health
;
1491 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
1492 POWER_SUPPLY_PROP_HEALTH
, val
);
1495 dev_info(battery
->dev
,
1496 "%s: Unsafe Temperature\n", __func__
);
1497 sec_bat_set_charging_status(battery
,
1498 POWER_SUPPLY_STATUS_NOT_CHARGING
);
1499 /* change charging current to battery (default 0mA) */
1500 sec_bat_set_charge(battery
, false);
1504 /* if recovered from not charging */
1505 if ((battery
->health
== POWER_SUPPLY_HEALTH_GOOD
) &&
1507 POWER_SUPPLY_STATUS_NOT_CHARGING
)) {
1508 dev_info(battery
->dev
,
1509 "%s: Safe Temperature\n", __func__
);
1510 if (battery
->capacity
>= 100)
1511 sec_bat_set_charging_status(battery
,
1512 POWER_SUPPLY_STATUS_FULL
);
1513 else{ /* Normal Charging */
1514 sec_bat_set_charging_status(battery
,
1515 POWER_SUPPLY_STATUS_CHARGING
);
1516 if (battery
->siop_level
!= 100)
1517 battery
->stop_timer
= true;
1519 #if defined(CONFIG_BATTERY_SWELLING)
1520 if ((temp_value
>= battery
->pdata
->swelling_high_temp_block
) ||
1521 (temp_value
<= battery
->pdata
->swelling_low_temp_block_2nd
)) {
1522 pr_info("%s: swelling mode start. stop charging\n", __func__
);
1523 battery
->swelling_mode
= true;
1524 battery
->swelling_full_check_cnt
= 0;
1525 sec_bat_set_charge(battery
, false);
1527 /* turn on charger by cable type */
1528 sec_bat_set_charge(battery
, true);
1531 /* turn on charger by cable type */
1532 sec_bat_set_charge(battery
, true);
1540 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
1541 static void sec_bat_self_discharging_check(struct sec_battery_info
*battery
)
1543 unsigned int dis_adc
;
1544 union power_supply_propval value
;
1546 switch(battery
->pdata
->self_discharging_type
) {
1547 case SEC_BAT_SELF_DISCHARGING_BY_ADC
:
1548 dis_adc
= sec_bat_get_adc_value(battery
, SEC_BAT_ADC_CHANNEL_DISCHARGING_CHECK
);
1550 battery
->self_discharging_adc
= dis_adc
;
1552 battery
->self_discharging_adc
= 0;
1554 if ((dis_adc
>= (int)battery
->pdata
->discharging_adc_min
) &&
1555 (dis_adc
<= (int)battery
->pdata
->discharging_adc_max
))
1556 battery
->self_discharging
= true;
1558 battery
->self_discharging
= false;
1559 pr_info("%s : SELF_DISCHARGING(%d) SELF_DISCHARGING_ADC(%d)\n",
1560 __func__
, battery
->self_discharging
, battery
->self_discharging_adc
);
1562 case SEC_BAT_SELF_DISCHARGING_BY_FG
:
1563 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
1564 POWER_SUPPLY_PROP_CHARGE_ENABLED
, value
);
1566 battery
->self_discharging
= value
.intval
;
1567 pr_info("%s: SELF_DISCHARGING : %s\n", __func__
,
1568 value
.intval
? "Enabled" : "Disabled");
1570 case SEC_BAT_SELF_DISCHARGING_BY_CHG
:
1571 psy_do_property(battery
->pdata
->charger_name
, get
,
1572 POWER_SUPPLY_PROP_RESISTANCE
, value
);
1574 battery
->self_discharging
= value
.intval
;
1575 pr_info("%s: SELF_DISCHARGING : %s\n", __func__
,
1576 value
.intval
? "Enabled" : "Disabled");
1583 static void sec_bat_self_discharging_ntc_check(struct sec_battery_info
*battery
)
1587 ntc_adc
= sec_bat_get_adc_value(battery
, SEC_BAT_ADC_CHANNEL_DISCHARGING_NTC
);
1589 battery
->discharging_ntc_adc
= ntc_adc
;
1591 battery
->discharging_ntc_adc
= 0;
1593 if (ntc_adc
> battery
->pdata
->discharging_ntc_limit
)
1594 battery
->discharging_ntc
= true;
1596 battery
->discharging_ntc
= false;
1598 pr_info("%s : DISCHARGING_NTC(%d) DISCHARGING_NTC_ADC(%d)\n",
1599 __func__
,battery
->discharging_ntc
, battery
->discharging_ntc_adc
);
1602 static void sec_bat_self_discharging_control(struct sec_battery_info
*battery
, bool dis_en
)
1604 union power_supply_propval value
;
1606 switch(battery
->pdata
->self_discharging_type
) {
1607 case SEC_BAT_SELF_DISCHARGING_BY_ADC
:
1608 if (!battery
->pdata
->factory_discharging
) {
1609 pr_info("Can't control Self Discharging IC (No Factory Discharging Pin).\n");
1614 dev_info(battery
->dev
,
1615 "%s : Self Discharging IC doesn't act until (%d) degree & (%d) voltage. "
1616 "Auto Discharging IC ENABLE\n", __func__
,
1617 battery
->temperature
, battery
->voltage_now
);
1618 gpio_direction_output(battery
->pdata
->factory_discharging
, 1);
1619 battery
->force_discharging
= true;
1621 dev_info(battery
->dev
, "%s : Self Discharging IC disable.\n", __func__
);
1622 gpio_direction_output(battery
->pdata
->factory_discharging
, 0);
1623 battery
->force_discharging
= false;
1626 case SEC_BAT_SELF_DISCHARGING_BY_FG
:
1627 value
.intval
= dis_en
;
1628 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
1629 POWER_SUPPLY_PROP_CHARGE_ENABLED
, value
);
1631 pr_info("%s: SELF_DISCHARGING Set to %s\n", __func__
,
1632 value
.intval
? "Enabled" : "Disabled");
1634 case SEC_BAT_SELF_DISCHARGING_BY_CHG
:
1636 battery
->force_discharging
= true;
1638 battery
->force_discharging
= false;
1640 value
.intval
= dis_en
;
1641 psy_do_property(battery
->pdata
->charger_name
, set
,
1642 POWER_SUPPLY_PROP_RESISTANCE
, value
);
1644 pr_info("%s: SELF_DISCHARGING Set to %s\n", __func__
,
1645 value
.intval
? "Enabled" : "Disabled");
1652 static void sec_bat_discharging_check(struct sec_battery_info
*battery
)
1654 if (!battery
->pdata
->self_discharging_en
)
1657 sec_bat_self_discharging_check(battery
);
1659 if(battery
->factory_self_discharging_mode_on
) {
1660 dev_info(battery
->dev
,
1661 "%s: It is Factory mode by self discharging mode, Auto_DIS(%d), Force_DIS(%d)\n",
1662 __func__
, battery
->self_discharging
, battery
->force_discharging
);
1666 if (!battery
->self_discharging
&&
1667 (battery
->temperature
>= battery
->pdata
->force_discharging_limit
) &&
1668 (battery
->voltage_now
>= battery
->pdata
->self_discharging_voltage_limit
)) {
1669 sec_bat_self_discharging_control(battery
, true);
1670 } else if(battery
->force_discharging
&&
1671 ((battery
->temperature
<= battery
->pdata
->force_discharging_recov
) ||
1672 (battery
->voltage_now
<= battery
->pdata
->swelling_drop_float_voltage
))) {
1673 sec_bat_self_discharging_control(battery
, false);
1675 dev_info(battery
->dev
,
1676 "%s: Auto_DIS(%d), Force_DIS(%d)\n",
1677 __func__
, battery
->self_discharging
, battery
->force_discharging
);
1681 #if !defined(CONFIG_SEC_FACTORY)
1682 static void sec_bat_chg_temperature_check(
1683 struct sec_battery_info
*battery
)
1685 #if defined(CONFIG_AFC_CHARGER_MODE)
1686 static bool is_vbus_changed
= false;
1687 union power_supply_propval value
;
1689 pr_info("%s: called (is_vbus:%d, cable:%d))\n", __func__
, is_vbus_changed
, battery
->cable_type
);
1690 if (battery
->siop_level
>= 100 && is_vbus_changed
&&
1691 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) {
1692 is_vbus_changed
= false;
1693 value
.intval
= SEC_INPUT_VOLTAGE_9V
;
1694 psy_do_property(battery
->pdata
->charger_name
, set
,
1695 POWER_SUPPLY_PROP_SET_CHARGE_VOLTAGE
, value
);
1696 pr_info("%s: changed vbus level 5V -> 9V\n", __func__
);
1698 } else if (battery
->siop_level
< 100 && !is_vbus_changed
&&
1699 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&&
1700 is_hv_wire_type(battery
->cable_type
)) {
1701 is_vbus_changed
= true;
1702 pr_info("%s: changed vbus level 9V -> 5V\n", __func__
);
1703 value
.intval
= SEC_INPUT_VOLTAGE_5V
;
1704 psy_do_property(battery
->pdata
->charger_name
, set
,
1705 POWER_SUPPLY_PROP_SET_CHARGE_VOLTAGE
, value
);
1708 if ((is_vbus_changed
&& is_hv_wire_type(battery
->cable_type
)) ||
1709 (!is_vbus_changed
&& (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
))) {
1710 pr_info("%s: prevent abnormal case (cable_type:%d, is_vbus_changed:%d)\n",
1711 __func__
, battery
->cable_type
, is_vbus_changed
);
1713 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
1714 is_vbus_changed
= false;
1719 if (battery
->siop_level
>= 100 &&
1720 ((battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
) ||
1721 (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
))) {
1722 union power_supply_propval value
;
1723 if ((battery
->chg_limit
== SEC_BATTERY_CHG_TEMP_NONE
) &&
1724 (battery
->chg_temp
> battery
->pdata
->chg_high_temp_1st
)) {
1725 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_HIGH_1ST
;
1726 value
.intval
= battery
->pdata
->chg_charging_limit_current
;
1727 psy_do_property(battery
->pdata
->charger_name
, set
,
1728 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1729 dev_info(battery
->dev
,"%s: Chg current is reduced by Temp: %d\n",
1730 __func__
, battery
->chg_temp
);
1731 } else if ((battery
->chg_limit
== SEC_BATTERY_CHG_TEMP_HIGH_1ST
) &&
1732 (battery
->pre_chg_temp
< battery
->pdata
->chg_high_temp_2nd
) &&
1733 (battery
->chg_temp
> battery
->pdata
->chg_high_temp_2nd
)) {
1734 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_HIGH_2ND
;
1735 value
.intval
= battery
->pdata
->chg_charging_limit_current_2nd
;
1736 psy_do_property(battery
->pdata
->charger_name
, set
,
1737 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1738 dev_info(battery
->dev
,"%s: Chg current 2nd is reduced by Temp: %d\n",
1739 __func__
, battery
->chg_temp
);
1740 } else if ((battery
->chg_limit
!= SEC_BATTERY_CHG_TEMP_NONE
) &&
1741 (battery
->chg_temp
< battery
->pdata
->chg_high_temp_recovery
)) {
1742 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
1743 value
.intval
= battery
->pdata
->charging_current
1744 [battery
->cable_type
].input_current_limit
;
1745 psy_do_property(battery
->pdata
->charger_name
, set
,
1746 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1747 dev_info(battery
->dev
,"%s: Chg current is recovered by Temp: %d\n",
1748 __func__
, battery
->chg_temp
);
1750 } else if (battery
->siop_level
>= 100 &&
1751 (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) && battery
->pdata
->wpc_temp_check
) {
1752 union power_supply_propval value
;
1753 if ((battery
->chg_limit
== SEC_BATTERY_CHG_TEMP_NONE
) &&
1754 (battery
->chg_temp
> battery
->pdata
->wpc_high_temp
)) {
1755 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_HIGH_1ST
;
1756 value
.intval
= battery
->pdata
->wpc_charging_limit_current
;
1757 psy_do_property(battery
->pdata
->charger_name
, set
,
1758 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1759 dev_info(battery
->dev
,"%s: WPC Chg current is reduced by Temp: %d\n",
1760 __func__
, battery
->chg_temp
);
1761 } else if ((battery
->chg_limit
!= SEC_BATTERY_CHG_TEMP_NONE
) &&
1762 (battery
->chg_temp
< battery
->pdata
->wpc_high_temp_recovery
)) {
1763 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
1764 value
.intval
= battery
->pdata
->charging_current
1765 [battery
->cable_type
].input_current_limit
;
1766 psy_do_property(battery
->pdata
->charger_name
, set
,
1767 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1768 dev_info(battery
->dev
,"%s: WPC Chg current is recovered by Temp: %d\n",
1769 __func__
, battery
->chg_temp
);
1771 } else if (battery
->chg_limit
!= SEC_BATTERY_CHG_TEMP_NONE
) {
1772 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
1777 static int sec_bat_get_inbat_vol_by_adc(struct sec_battery_info
*battery
)
1784 const sec_bat_adc_table_data_t
*inbat_adc_table
;
1785 unsigned int inbat_adc_table_size
;
1787 if (!battery
->pdata
->inbat_adc_table
) {
1788 dev_err(battery
->dev
, "%s: not designed to read in-bat voltage\n", __func__
);
1792 inbat_adc_table
= battery
->pdata
->inbat_adc_table
;
1793 inbat_adc_table_size
=
1794 battery
->pdata
->inbat_adc_table_size
;
1796 inbat_adc
= sec_bat_get_adc_value(battery
, SEC_BAT_ADC_CHANNEL_INBAT_VOLTAGE
);
1799 battery
->inbat_adc
= inbat_adc
;
1801 if (inbat_adc_table
[0].adc
<= inbat_adc
) {
1802 inbat
= inbat_adc_table
[0].data
;
1803 goto inbat_by_adc_goto
;
1804 } else if (inbat_adc_table
[inbat_adc_table_size
-1].adc
>= inbat_adc
) {
1805 inbat
= inbat_adc_table
[inbat_adc_table_size
-1].data
;
1806 goto inbat_by_adc_goto
;
1809 high
= inbat_adc_table_size
- 1;
1811 while (low
<= high
) {
1812 mid
= (low
+ high
) / 2;
1813 if (inbat_adc_table
[mid
].adc
< inbat_adc
)
1815 else if (inbat_adc_table
[mid
].adc
> inbat_adc
)
1818 inbat
= inbat_adc_table
[mid
].data
;
1819 goto inbat_by_adc_goto
;
1823 inbat
= inbat_adc_table
[high
].data
;
1825 ((inbat_adc_table
[low
].data
- inbat_adc_table
[high
].data
) *
1826 (inbat_adc
- inbat_adc_table
[high
].adc
)) /
1827 (inbat_adc_table
[low
].adc
- inbat_adc_table
[high
].adc
);
1833 dev_info(battery
->dev
,
1834 "%s: inbat(%d), inbat-ADC(%d)\n",
1835 __func__
, inbat
, inbat_adc
);
1840 static void sec_bat_event_program_alarm(
1841 struct sec_battery_info
*battery
, int seconds
)
1843 #if defined(ANDROID_ALARM_ACTIVATED)
1844 ktime_t low_interval
= ktime_set(seconds
- 10, 0);
1845 ktime_t slack
= ktime_set(20, 0);
1848 next
= ktime_add(battery
->last_event_time
, low_interval
);
1849 alarm_start_range(&battery
->event_termination_alarm
,
1850 next
, ktime_add(next
, slack
));
1852 alarm_start(&battery
->event_termination_alarm
,
1853 ktime_add(battery
->last_event_time
, ktime_set(seconds
- 10, 0)));
1857 #if defined(ANDROID_ALARM_ACTIVATED)
1858 static void sec_bat_event_expired_timer_func(struct alarm
*alarm
)
1860 static enum alarmtimer_restart
sec_bat_event_expired_timer_func(
1861 struct alarm
*alarm
, ktime_t now
)
1864 struct sec_battery_info
*battery
=
1865 container_of(alarm
, struct sec_battery_info
,
1866 event_termination_alarm
);
1868 battery
->event
&= (~battery
->event_wait
);
1869 dev_info(battery
->dev
,
1870 "%s: event expired (0x%x)\n", __func__
, battery
->event
);
1872 #if !defined(ANDROID_ALARM_ACTIVATED)
1873 return ALARMTIMER_NORESTART
;
1877 static void sec_bat_event_set(
1878 struct sec_battery_info
*battery
, int event
, int enable
)
1880 if (!battery
->pdata
->event_check
)
1883 /* ignore duplicated deactivation of same event
1884 * only if the event is one last event
1886 if (!enable
&& (battery
->event
== battery
->event_wait
)) {
1887 dev_info(battery
->dev
,
1888 "%s: ignore duplicated deactivation of same event\n",
1893 alarm_cancel(&battery
->event_termination_alarm
);
1894 battery
->event
&= (~battery
->event_wait
);
1897 battery
->event_wait
= 0;
1898 battery
->event
|= event
;
1900 dev_info(battery
->dev
,
1901 "%s: event set (0x%x)\n", __func__
, battery
->event
);
1903 if (battery
->event
== 0) {
1904 dev_dbg(battery
->dev
,
1905 "%s: nothing to clear\n", __func__
);
1906 return; /* nothing to clear */
1908 battery
->event_wait
= event
;
1909 #if defined(ANDROID_ALARM_ACTIVATED)
1910 battery
->last_event_time
= alarm_get_elapsed_realtime();
1912 battery
->last_event_time
= ktime_get_boottime();
1914 sec_bat_event_program_alarm(battery
,
1915 battery
->pdata
->event_waiting_time
);
1916 dev_info(battery
->dev
,
1917 "%s: start timer (curr 0x%x, wait 0x%x)\n",
1918 __func__
, battery
->event
, battery
->event_wait
);
1922 static bool sec_bat_check_fullcharged_condition(
1923 struct sec_battery_info
*battery
)
1925 int full_check_type
;
1927 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
)
1928 full_check_type
= battery
->pdata
->full_check_type
;
1930 full_check_type
= battery
->pdata
->full_check_type_2nd
;
1932 switch (full_check_type
) {
1933 case SEC_BATTERY_FULLCHARGED_ADC
:
1934 case SEC_BATTERY_FULLCHARGED_FG_CURRENT
:
1935 case SEC_BATTERY_FULLCHARGED_SOC
:
1936 case SEC_BATTERY_FULLCHARGED_CHGGPIO
:
1937 case SEC_BATTERY_FULLCHARGED_CHGPSY
:
1940 /* If these is NOT full check type or NONE full check type,
1941 * it is full-charged
1943 case SEC_BATTERY_FULLCHARGED_CHGINT
:
1944 case SEC_BATTERY_FULLCHARGED_TIME
:
1945 case SEC_BATTERY_FULLCHARGED_NONE
:
1951 if (battery
->pdata
->full_condition_type
&
1952 SEC_BATTERY_FULL_CONDITION_SOC
) {
1953 if (battery
->capacity
<
1954 battery
->pdata
->full_condition_soc
) {
1955 dev_dbg(battery
->dev
,
1956 "%s: Not enough SOC (%d%%)\n",
1957 __func__
, battery
->capacity
);
1962 if (battery
->pdata
->full_condition_type
&
1963 SEC_BATTERY_FULL_CONDITION_VCELL
) {
1964 if (battery
->voltage_now
<
1965 battery
->pdata
->full_condition_vcell
) {
1966 dev_dbg(battery
->dev
,
1967 "%s: Not enough VCELL (%dmV)\n",
1968 __func__
, battery
->voltage_now
);
1973 if (battery
->pdata
->full_condition_type
&
1974 SEC_BATTERY_FULL_CONDITION_AVGVCELL
) {
1975 if (battery
->voltage_avg
<
1976 battery
->pdata
->full_condition_avgvcell
) {
1977 dev_dbg(battery
->dev
,
1978 "%s: Not enough AVGVCELL (%dmV)\n",
1979 __func__
, battery
->voltage_avg
);
1984 if (battery
->pdata
->full_condition_type
&
1985 SEC_BATTERY_FULL_CONDITION_OCV
) {
1986 if (battery
->voltage_ocv
<
1987 battery
->pdata
->full_condition_ocv
) {
1988 dev_dbg(battery
->dev
,
1989 "%s: Not enough OCV (%dmV)\n",
1990 __func__
, battery
->voltage_ocv
);
1998 static void sec_bat_do_test_function(
1999 struct sec_battery_info
*battery
)
2001 union power_supply_propval value
;
2003 switch (battery
->test_mode
) {
2005 if (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) {
2006 sec_bat_set_charge(battery
, false);
2007 sec_bat_set_charging_status(battery
,
2008 POWER_SUPPLY_STATUS_DISCHARGING
);
2012 if(battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
2013 sec_bat_set_charge(battery
, true);
2014 psy_do_property(battery
->pdata
->charger_name
, get
,
2015 POWER_SUPPLY_PROP_STATUS
, value
);
2016 sec_bat_set_charging_status(battery
, value
.intval
);
2018 battery
->test_mode
= 0;
2020 case 3: // clear temp block
2021 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
2022 sec_bat_set_charging_status(battery
,
2023 POWER_SUPPLY_STATUS_DISCHARGING
);
2026 if(battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
2027 sec_bat_set_charge(battery
, true);
2028 psy_do_property(battery
->pdata
->charger_name
, get
,
2029 POWER_SUPPLY_PROP_STATUS
, value
);
2030 sec_bat_set_charging_status(battery
, value
.intval
);
2034 pr_info("%s: error test: unknown state\n", __func__
);
2039 static bool sec_bat_time_management(
2040 struct sec_battery_info
*battery
)
2042 unsigned long charging_time
;
2043 //unsigned long expired_time = 0;
2045 //unsigned int charging_total_time = 10 * 60 * 60;
2046 #if defined(ANDROID_ALARM_ACTIVATED)
2047 ktime_t current_time
;
2049 current_time
= alarm_get_elapsed_realtime();
2050 ts
= ktime_to_timespec(current_time
);
2052 get_monotonic_boottime(&ts
);
2055 if(battery
->charging_start_time
== 0 || !battery
->safety_timer_set
) {
2056 pr_info("%s: Charging Disabled\n" ,__func__
);
2060 if (ts
.tv_sec
>= battery
->charging_start_time
)
2061 charging_time
= ts
.tv_sec
- battery
->charging_start_time
;
2063 charging_time
= 0xFFFFFFFF - battery
->charging_start_time
2066 battery
->charging_passed_time
= charging_time
;
2068 if (!battery
->store_mode
) {
2069 if (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
||
2070 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
||
2071 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_UNKNOWN
) {
2072 charging_total_time
= battery
->pdata
->hv_charging_total_time
;
2073 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_MAINS
||
2074 battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2075 charging_total_time
= battery
->pdata
->normal_charging_total_time
;
2077 charging_total_time
= battery
->pdata
->usb_charging_total_time
;
2081 dev_info(battery
->dev
,
2082 "%s: Charging Time : %ld secs\n", __func__
,
2083 battery
->charging_passed_time
);
2085 if (battery
->siop_level
>= 100) {
2086 if (charging_time
< battery
->lcd_on_total_time
)
2087 battery
->lcd_on_total_time
= charging_time
;
2088 expired_time
= charging_time
- battery
->lcd_on_total_time
;
2089 pr_info("%s: Total Charging time : %ld, Expired Time : %ld, LCD On total Time : %ld\n",
2090 __func__
, charging_time
, expired_time
, battery
->lcd_on_total_time
);
2095 switch (battery
->status
) {
2096 case POWER_SUPPLY_STATUS_FULL
:
2097 if (battery
->expired_time
== 0) {
2098 dev_info(battery
->dev
,
2099 "%s: Recharging Timer Expired\n", __func__
);
2100 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2101 battery
->health
= POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
2102 sec_bat_set_charging_status(battery
,
2103 POWER_SUPPLY_STATUS_NOT_CHARGING
);
2104 battery
->is_recharging
= false;
2105 if (sec_bat_set_charge(battery
, false)) {
2106 dev_err(battery
->dev
,
2107 "%s: Fail to Set Charger\n", __func__
);
2114 case POWER_SUPPLY_STATUS_CHARGING
:
2115 if ((battery
->pdata
->full_condition_type
&
2116 SEC_BATTERY_FULL_CONDITION_NOTIMEFULL
) &&
2117 (battery
->is_recharging
&& (battery
->expired_time
== 0))) {
2118 dev_info(battery
->dev
,
2119 "%s: Recharging Timer Expired\n", __func__
);
2120 battery
->health
= POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
2121 sec_bat_set_charging_status(battery
,
2122 POWER_SUPPLY_STATUS_NOT_CHARGING
);
2123 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2124 battery
->is_recharging
= false;
2125 if (sec_bat_set_charge(battery
, false)) {
2126 dev_err(battery
->dev
,
2127 "%s: Fail to Set Charger\n", __func__
);
2131 } else if (!battery
->is_recharging
&& (battery
->expired_time
== 0)) {
2132 dev_info(battery
->dev
,
2133 "%s: Charging Timer Expired\n", __func__
);
2134 battery
->health
= POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
2135 sec_bat_set_charging_status(battery
,
2136 POWER_SUPPLY_STATUS_NOT_CHARGING
);
2137 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2138 if (sec_bat_set_charge(battery
, false)) {
2139 dev_err(battery
->dev
,
2140 "%s: Fail to Set Charger\n", __func__
);
2147 if (battery
->pdata
->charging_reset_time
) {
2148 if (charging_time
> battery
->charging_next_time
) {
2149 /*reset current in charging status */
2150 battery
->charging_next_time
=
2151 battery
->charging_passed_time
+
2152 (battery
->pdata
->charging_reset_time
);
2154 dev_dbg(battery
->dev
,
2155 "%s: Reset charging current\n",
2157 #if defined(CONFIG_BATTERY_SWELLING)
2158 if (!battery
->swelling_mode
) {
2159 if (sec_bat_set_charge(battery
, true)) {
2160 dev_err(battery
->dev
,
2161 "%s: Fail to Set Charger\n",
2167 if (sec_bat_set_charge(battery
, true)) {
2168 dev_err(battery
->dev
,
2169 "%s: Fail to Set Charger\n",
2179 dev_err(battery
->dev
,
2180 "%s: Undefine Battery Status\n", __func__
);
2187 static bool sec_bat_check_fullcharged(
2188 struct sec_battery_info
*battery
)
2190 union power_supply_propval value
;
2192 int full_check_type
;
2198 if (!sec_bat_check_fullcharged_condition(battery
))
2199 goto not_full_charged
;
2201 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
)
2202 full_check_type
= battery
->pdata
->full_check_type
;
2204 full_check_type
= battery
->pdata
->full_check_type_2nd
;
2206 pr_info("%s : full_check_type(%d)\n", __func__
, full_check_type
);
2208 switch (full_check_type
) {
2209 case SEC_BATTERY_FULLCHARGED_ADC
:
2211 sec_bat_get_adc_value(battery
,
2212 SEC_BAT_ADC_CHANNEL_FULL_CHECK
);
2214 dev_dbg(battery
->dev
,
2215 "%s: Current ADC (%d)\n",
2216 __func__
, current_adc
);
2218 if (current_adc
< 0)
2220 battery
->current_adc
= current_adc
;
2222 if (battery
->current_adc
<
2223 (battery
->charging_mode
==
2224 SEC_BATTERY_CHARGING_1ST
?
2225 battery
->pdata
->charging_current
[
2226 battery
->cable_type
].full_check_current_1st
:
2227 battery
->pdata
->charging_current
[
2228 battery
->cable_type
].full_check_current_2nd
)) {
2229 battery
->full_check_cnt
++;
2230 dev_dbg(battery
->dev
,
2231 "%s: Full Check ADC (%d)\n",
2233 battery
->full_check_cnt
);
2235 battery
->full_check_cnt
= 0;
2238 case SEC_BATTERY_FULLCHARGED_FG_CURRENT
:
2239 if ((battery
->current_now
> 0 && battery
->current_now
<
2240 battery
->pdata
->charging_current
[
2241 battery
->cable_type
].full_check_current_1st
) &&
2242 (battery
->current_avg
> 0 && battery
->current_avg
<
2243 (battery
->charging_mode
==
2244 SEC_BATTERY_CHARGING_1ST
?
2245 battery
->pdata
->charging_current
[
2246 battery
->cable_type
].full_check_current_1st
:
2247 battery
->pdata
->charging_current
[
2248 battery
->cable_type
].full_check_current_2nd
))) {
2249 battery
->full_check_cnt
++;
2250 dev_dbg(battery
->dev
,
2251 "%s: Full Check Current (%d)\n",
2253 battery
->full_check_cnt
);
2255 battery
->full_check_cnt
= 0;
2258 case SEC_BATTERY_FULLCHARGED_TIME
:
2259 if ((battery
->charging_mode
==
2260 SEC_BATTERY_CHARGING_2ND
?
2261 (battery
->charging_passed_time
-
2262 battery
->charging_fullcharged_time
) :
2263 battery
->charging_passed_time
) >
2264 (battery
->charging_mode
==
2265 SEC_BATTERY_CHARGING_1ST
?
2266 battery
->pdata
->charging_current
[
2267 battery
->cable_type
].full_check_current_1st
:
2268 battery
->pdata
->charging_current
[
2269 battery
->cable_type
].full_check_current_2nd
)) {
2270 battery
->full_check_cnt
++;
2271 dev_dbg(battery
->dev
,
2272 "%s: Full Check Time (%d)\n",
2274 battery
->full_check_cnt
);
2276 battery
->full_check_cnt
= 0;
2279 case SEC_BATTERY_FULLCHARGED_SOC
:
2280 if (battery
->capacity
<=
2281 (battery
->charging_mode
==
2282 SEC_BATTERY_CHARGING_1ST
?
2283 battery
->pdata
->charging_current
[
2284 battery
->cable_type
].full_check_current_1st
:
2285 battery
->pdata
->charging_current
[
2286 battery
->cable_type
].full_check_current_2nd
)) {
2287 battery
->full_check_cnt
++;
2288 dev_dbg(battery
->dev
,
2289 "%s: Full Check SOC (%d)\n",
2291 battery
->full_check_cnt
);
2293 battery
->full_check_cnt
= 0;
2296 case SEC_BATTERY_FULLCHARGED_CHGGPIO
:
2298 battery
->pdata
->chg_gpio_full_check
,
2301 dev_err(battery
->dev
,
2302 "%s: Error in Request of GPIO\n", __func__
);
2305 if (!(gpio_get_value_cansleep(
2306 battery
->pdata
->chg_gpio_full_check
) ^
2307 !battery
->pdata
->chg_polarity_full_check
)) {
2308 battery
->full_check_cnt
++;
2309 dev_dbg(battery
->dev
,
2310 "%s: Full Check GPIO (%d)\n",
2311 __func__
, battery
->full_check_cnt
);
2313 battery
->full_check_cnt
= 0;
2314 gpio_free(battery
->pdata
->chg_gpio_full_check
);
2317 case SEC_BATTERY_FULLCHARGED_CHGINT
:
2318 case SEC_BATTERY_FULLCHARGED_CHGPSY
:
2319 psy_do_property(battery
->pdata
->charger_name
, get
,
2320 POWER_SUPPLY_PROP_STATUS
, value
);
2322 if (value
.intval
== POWER_SUPPLY_STATUS_FULL
) {
2323 battery
->full_check_cnt
++;
2324 dev_info(battery
->dev
,
2325 "%s: Full Check Charger (%d)\n",
2326 __func__
, battery
->full_check_cnt
);
2328 battery
->full_check_cnt
= 0;
2331 /* If these is NOT full check type or NONE full check type,
2332 * it is full-charged
2334 case SEC_BATTERY_FULLCHARGED_NONE
:
2335 battery
->full_check_cnt
= 0;
2339 dev_err(battery
->dev
,
2340 "%s: Invalid Full Check\n", __func__
);
2344 if (battery
->full_check_cnt
>=
2345 battery
->pdata
->full_check_count
) {
2346 battery
->full_check_cnt
= 0;
2354 static void sec_bat_do_fullcharged(
2355 struct sec_battery_info
*battery
)
2357 union power_supply_propval value
;
2359 /* To let charger/fuel gauge know the full status,
2360 * set status before calling sec_bat_set_charge()
2362 sec_bat_set_charging_status(battery
,
2363 POWER_SUPPLY_STATUS_FULL
);
2366 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
) {
2367 battery
->charging_mode
= SEC_BATTERY_CHARGING_2ND
;
2368 battery
->charging_fullcharged_time
=
2369 battery
->charging_passed_time
;
2370 sec_bat_set_charge(battery
, true);
2371 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) && defined(CONFIG_WIRELESS_CHARGER_INBATTERY_CS100)
2372 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2373 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2374 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
2375 POWER_SUPPLY_PROP_STATUS
, value
);
2379 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2380 battery
->is_recharging
= false;
2381 sec_bat_set_charge(battery
, false);
2383 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) && !defined(CONFIG_WIRELESS_CHARGER_INBATTERY_CS100)
2384 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2385 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2386 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
2387 POWER_SUPPLY_PROP_STATUS
, value
);
2390 #if defined(CONFIG_BATTERY_AGE_FORECAST)
2391 sec_bat_aging_check(battery
);
2393 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2394 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2395 POWER_SUPPLY_PROP_STATUS
, value
);
2398 #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX)
2399 #if defined(CONFIG_PREVENT_SOC_JUMP)
2400 value
.intval
= battery
->capacity
;
2402 value
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
2404 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2405 POWER_SUPPLY_PROP_CHARGE_FULL
, value
);
2408 /* platform can NOT get information of battery
2409 * because wakeup time is too short to check uevent
2410 * To make sure that target is wakeup if full-charged,
2411 * activated wake lock in a few seconds
2413 if (battery
->pdata
->polling_type
== SEC_BATTERY_MONITOR_ALARM
)
2414 wake_lock_timeout(&battery
->vbus_wake_lock
, HZ
* 10);
2417 static bool sec_bat_fullcharged_check(
2418 struct sec_battery_info
*battery
)
2420 if ((battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
) ||
2421 (battery
->status
== POWER_SUPPLY_STATUS_NOT_CHARGING
)) {
2422 dev_dbg(battery
->dev
,
2423 "%s: No Need to Check Full-Charged\n", __func__
);
2427 if (sec_bat_check_fullcharged(battery
))
2428 sec_bat_do_fullcharged(battery
);
2430 dev_info(battery
->dev
,
2431 "%s: Charging Mode : %s\n", __func__
,
2432 battery
->is_recharging
?
2433 sec_bat_charging_mode_str
[SEC_BATTERY_CHARGING_RECHARGING
] :
2434 sec_bat_charging_mode_str
[battery
->charging_mode
]);
2439 static void sec_bat_get_temperature_info(
2440 struct sec_battery_info
*battery
)
2442 union power_supply_propval value
;
2444 switch (battery
->pdata
->thermal_source
) {
2445 case SEC_BATTERY_THERMAL_SOURCE_FG
:
2446 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2447 POWER_SUPPLY_PROP_TEMP
, value
);
2448 battery
->temperature
= value
.intval
;
2450 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2451 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
2452 battery
->temper_amb
= value
.intval
;
2454 case SEC_BATTERY_THERMAL_SOURCE_CALLBACK
:
2455 if (battery
->pdata
->get_temperature_callback
) {
2456 battery
->pdata
->get_temperature_callback(
2457 POWER_SUPPLY_PROP_TEMP
, &value
);
2458 battery
->temperature
= value
.intval
;
2459 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2460 POWER_SUPPLY_PROP_TEMP
, value
);
2462 battery
->pdata
->get_temperature_callback(
2463 POWER_SUPPLY_PROP_TEMP_AMBIENT
, &value
);
2464 battery
->temper_amb
= value
.intval
;
2465 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2466 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
2469 case SEC_BATTERY_THERMAL_SOURCE_ADC
:
2470 sec_bat_get_temperature_by_adc(battery
,
2471 SEC_BAT_ADC_CHANNEL_TEMP
, &value
);
2472 battery
->temperature
= value
.intval
;
2473 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2474 POWER_SUPPLY_PROP_TEMP
, value
);
2476 sec_bat_get_temperature_by_adc(battery
,
2477 SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT
, &value
);
2478 battery
->temper_amb
= value
.intval
;
2479 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2480 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
2482 #if defined(CONFIG_AFC_CHARGER_MODE)
2483 sec_bat_get_temperature_by_adc(battery
,
2484 SEC_BAT_ADC_CHANNEL_CHG_TEMP
, &value
);
2485 if (battery
->pre_chg_temp
== 0) {
2486 battery
->pre_chg_temp
= value
.intval
;
2487 battery
->chg_temp
= value
.intval
;
2489 battery
->pre_chg_temp
= battery
->chg_temp
;
2490 battery
->chg_temp
= value
.intval
;
2499 static void sec_bat_get_battery_info(
2500 struct sec_battery_info
*battery
)
2502 union power_supply_propval value
;
2503 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
2504 static struct timespec old_ts
;
2505 struct timespec c_ts
;
2506 #if defined(ANDROID_ALARM_ACTIVATED)
2507 c_ts
= ktime_to_timespec(alarm_get_elapsed_realtime());
2509 c_ts
= ktime_to_timespec(ktime_get_boottime());
2513 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2514 POWER_SUPPLY_PROP_VOLTAGE_NOW
, value
);
2515 battery
->voltage_now
= value
.intval
;
2517 value
.intval
= SEC_BATTERY_VOLTAGE_AVERAGE
;
2518 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2519 POWER_SUPPLY_PROP_VOLTAGE_AVG
, value
);
2520 battery
->voltage_avg
= value
.intval
;
2522 value
.intval
= SEC_BATTERY_VOLTAGE_OCV
;
2523 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2524 POWER_SUPPLY_PROP_VOLTAGE_AVG
, value
);
2525 battery
->voltage_ocv
= value
.intval
;
2527 value
.intval
= SEC_BATTERY_CURRENT_MA
;
2528 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2529 POWER_SUPPLY_PROP_CURRENT_NOW
, value
);
2530 battery
->current_now
= value
.intval
;
2532 value
.intval
= SEC_BATTERY_CURRENT_MA
;
2533 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2534 POWER_SUPPLY_PROP_CURRENT_AVG
, value
);
2535 battery
->current_avg
= value
.intval
;
2537 /* input current limit in charger */
2538 psy_do_property(battery
->pdata
->charger_name
, get
,
2539 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
2540 battery
->current_max
= value
.intval
;
2542 sec_bat_get_temperature_info(battery
);
2544 /* To get SOC value (NOT raw SOC), need to reset value */
2546 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2547 POWER_SUPPLY_PROP_CAPACITY
, value
);
2548 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
2549 /* if the battery status was full, and SOC wasn't 100% yet,
2550 then ignore FG SOC, and report (previous SOC +1)% */
2551 if (battery
->status
!= POWER_SUPPLY_STATUS_FULL
) {
2552 battery
->capacity
= value
.intval
;
2553 } else if ((c_ts
.tv_sec
- old_ts
.tv_sec
) >= 30) {
2554 if (battery
->capacity
!= 100) {
2555 battery
->capacity
++;
2556 pr_info("%s : forced full-charged sequence for the capacity(%d)\n",
2557 __func__
, battery
->capacity
);
2560 if (value
.intval
>= battery
->pdata
->full_condition_soc
&&
2561 battery
->voltage_now
>= (battery
->pdata
->recharge_condition_vcell
- 50)) {
2562 /* update capacity max */
2563 value
.intval
= battery
->capacity
;
2564 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2565 POWER_SUPPLY_PROP_CHARGE_FULL
, value
);
2570 battery
->capacity
= value
.intval
;
2573 if (battery
->capacity
> 5 && battery
->ignore_siop
&&
2574 (battery
->r_siop_level
!= battery
->siop_level
)) {
2575 battery
->siop_level
= battery
->r_siop_level
;
2576 battery
->ignore_siop
= false;
2577 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
)
2578 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
,
2579 msecs_to_jiffies(1200));
2581 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
, 0);
2584 #if !defined(CONFIG_SEC_FACTORY)
2585 if (battery
->capacity
> 5 && battery
->ignore_store_mode
) {
2586 battery
->ignore_store_mode
= false;
2587 value
.intval
= battery
->store_mode
;
2588 psy_do_property(battery
->pdata
->charger_name
, set
,
2589 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
, value
);
2593 dev_info(battery
->dev
,
2594 "%s:Vnow(%dmV),Inow(%dmA),Imax(%dmA),SOC(%d%%),Tbat(%d),Tchg(%d),is_hc_usb(%d)\n",
2596 battery
->voltage_now
, battery
->current_now
,
2597 battery
->current_max
, battery
->capacity
,
2598 battery
->temperature
, battery
->chg_temp
, battery
->is_hc_usb
);
2599 dev_dbg(battery
->dev
,
2600 "%s,Vavg(%dmV),Vocv(%dmV),Tamb(%d),"
2601 "Iavg(%dmA),Iadc(%d)\n",
2602 battery
->present
? "Connected" : "Disconnected",
2603 battery
->voltage_avg
, battery
->voltage_ocv
,
2604 battery
->temper_amb
,
2605 battery
->current_avg
, battery
->current_adc
);
2608 static void sec_bat_polling_work(struct work_struct
*work
)
2610 struct sec_battery_info
*battery
= container_of(
2611 work
, struct sec_battery_info
, polling_work
.work
);
2613 wake_lock(&battery
->monitor_wake_lock
);
2614 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
2615 dev_dbg(battery
->dev
, "%s: Activated\n", __func__
);
2618 static void sec_bat_program_alarm(
2619 struct sec_battery_info
*battery
, int seconds
)
2621 #if defined(ANDROID_ALARM_ACTIVATED)
2622 ktime_t low_interval
= ktime_set(seconds
, 0);
2623 ktime_t slack
= ktime_set(10, 0);
2626 next
= ktime_add(battery
->last_poll_time
, low_interval
);
2627 alarm_start_range(&battery
->polling_alarm
,
2628 next
, ktime_add(next
, slack
));
2630 alarm_start(&battery
->polling_alarm
,
2631 ktime_add(battery
->last_poll_time
, ktime_set(seconds
, 0)));
2635 static unsigned int sec_bat_get_polling_time(
2636 struct sec_battery_info
*battery
)
2638 if (battery
->status
==
2639 POWER_SUPPLY_STATUS_FULL
)
2640 battery
->polling_time
=
2641 battery
->pdata
->polling_time
[
2642 POWER_SUPPLY_STATUS_CHARGING
];
2644 battery
->polling_time
=
2645 battery
->pdata
->polling_time
[
2648 battery
->polling_short
= true;
2650 switch (battery
->status
) {
2651 case POWER_SUPPLY_STATUS_CHARGING
:
2652 if (battery
->polling_in_sleep
)
2653 battery
->polling_short
= false;
2655 case POWER_SUPPLY_STATUS_DISCHARGING
:
2656 if (battery
->polling_in_sleep
&& (battery
->ps_enable
!= true)) {
2657 battery
->polling_time
=
2658 battery
->pdata
->polling_time
[
2659 SEC_BATTERY_POLLING_TIME_SLEEP
];
2661 battery
->polling_time
=
2662 battery
->pdata
->polling_time
[
2664 battery
->polling_short
= false;
2666 case POWER_SUPPLY_STATUS_FULL
:
2667 if (battery
->polling_in_sleep
) {
2668 if (!(battery
->pdata
->full_condition_type
&
2669 SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL
) &&
2670 battery
->charging_mode
==
2671 SEC_BATTERY_CHARGING_NONE
) {
2672 battery
->polling_time
=
2673 battery
->pdata
->polling_time
[
2674 SEC_BATTERY_POLLING_TIME_SLEEP
];
2676 battery
->polling_short
= false;
2678 if (battery
->charging_mode
==
2679 SEC_BATTERY_CHARGING_NONE
)
2680 battery
->polling_short
= false;
2685 if (battery
->polling_short
)
2686 return battery
->pdata
->polling_time
[
2687 SEC_BATTERY_POLLING_TIME_BASIC
];
2688 /* set polling time to 46s to reduce current noise on wc */
2689 else if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
&&
2690 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
)
2691 battery
->polling_time
= 46;
2693 return battery
->polling_time
;
2696 static bool sec_bat_is_short_polling(
2697 struct sec_battery_info
*battery
)
2699 /* Change the full and short monitoring sequence
2700 * Originally, full monitoring was the last time of polling_count
2701 * But change full monitoring to first time
2702 * because temperature check is too late
2704 if (!battery
->polling_short
|| battery
->polling_count
== 1)
2710 static void sec_bat_update_polling_count(
2711 struct sec_battery_info
*battery
)
2713 /* do NOT change polling count in sleep
2714 * even though it is short polling
2715 * to keep polling count along sleep/wakeup
2717 if (battery
->polling_short
&& battery
->polling_in_sleep
)
2720 if (battery
->polling_short
&&
2721 ((battery
->polling_time
/
2722 battery
->pdata
->polling_time
[
2723 SEC_BATTERY_POLLING_TIME_BASIC
])
2724 > battery
->polling_count
))
2725 battery
->polling_count
++;
2727 battery
->polling_count
= 1; /* initial value = 1 */
2730 static void sec_bat_set_polling(
2731 struct sec_battery_info
*battery
)
2733 unsigned int polling_time_temp
;
2735 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
2737 polling_time_temp
= sec_bat_get_polling_time(battery
);
2739 dev_dbg(battery
->dev
,
2740 "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n",
2741 __func__
, sec_bat_status_str
[battery
->status
],
2742 battery
->polling_in_sleep
? "Yes" : "No",
2743 (battery
->charging_mode
==
2744 SEC_BATTERY_CHARGING_NONE
) ? "No" : "Yes",
2745 battery
->polling_short
? "Yes" : "No");
2746 dev_dbg(battery
->dev
,
2747 "%s: Polling time %d/%d sec.\n", __func__
,
2748 battery
->polling_short
?
2749 (polling_time_temp
* battery
->polling_count
) :
2750 polling_time_temp
, battery
->polling_time
);
2752 /* To sync with log above,
2753 * change polling count after log is displayed
2754 * Do NOT update polling count in initial monitor
2756 if (!battery
->pdata
->monitor_initial_count
)
2757 sec_bat_update_polling_count(battery
);
2759 dev_dbg(battery
->dev
,
2760 "%s: Initial monitor %d times left.\n", __func__
,
2761 battery
->pdata
->monitor_initial_count
);
2763 switch (battery
->pdata
->polling_type
) {
2764 case SEC_BATTERY_MONITOR_WORKQUEUE
:
2765 if (battery
->pdata
->monitor_initial_count
) {
2766 battery
->pdata
->monitor_initial_count
--;
2767 schedule_delayed_work(&battery
->polling_work
, HZ
);
2769 schedule_delayed_work(&battery
->polling_work
,
2770 polling_time_temp
* HZ
);
2772 case SEC_BATTERY_MONITOR_ALARM
:
2773 #if defined(ANDROID_ALARM_ACTIVATED)
2774 battery
->last_poll_time
= alarm_get_elapsed_realtime();
2776 battery
->last_poll_time
= ktime_get_boottime();
2779 if (battery
->pdata
->monitor_initial_count
) {
2780 battery
->pdata
->monitor_initial_count
--;
2781 sec_bat_program_alarm(battery
, 1);
2783 sec_bat_program_alarm(battery
, polling_time_temp
);
2785 case SEC_BATTERY_MONITOR_TIMER
:
2790 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
2792 #if defined(CONFIG_BATTERY_SWELLING)
2793 static void sec_bat_swelling_fullcharged_check(struct sec_battery_info
*battery
)
2795 union power_supply_propval value
= {0, };
2797 switch (battery
->pdata
->full_check_type_2nd
) {
2798 case SEC_BATTERY_FULLCHARGED_FG_CURRENT
:
2799 if (battery
->pdata
->swelling_full_check_current_2nd
> 0) {
2800 if ((battery
->current_now
> 0 && battery
->current_now
<
2801 battery
->pdata
->charging_current
[
2802 battery
->cable_type
].full_check_current_1st
) &&
2803 (battery
->current_avg
> 0 && battery
->current_avg
<
2804 battery
->pdata
->swelling_full_check_current_2nd
) &&
2805 ((battery
->pdata
->swelling_drop_float_voltage
- 100) < battery
->voltage_now
)) {
2806 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2809 if ((battery
->current_now
> 0 && battery
->current_now
<
2810 battery
->pdata
->charging_current
[
2811 battery
->cable_type
].full_check_current_1st
) &&
2812 (battery
->current_avg
> 0 && battery
->current_avg
<
2813 battery
->pdata
->charging_current
[
2814 battery
->cable_type
].full_check_current_2nd
) &&
2815 ((battery
->pdata
->swelling_drop_float_voltage
- 100) < battery
->voltage_now
)) {
2816 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2821 psy_do_property(battery
->pdata
->charger_name
, get
,
2822 POWER_SUPPLY_PROP_STATUS
, value
);
2826 if (value
.intval
== POWER_SUPPLY_STATUS_FULL
) {
2827 battery
->swelling_full_check_cnt
++;
2828 pr_info("%s: Swelling mode full-charged check (%d)\n",
2829 __func__
, battery
->swelling_full_check_cnt
);
2831 battery
->swelling_full_check_cnt
= 0;
2833 if (battery
->swelling_full_check_cnt
>=
2834 battery
->pdata
->full_check_count
) {
2835 battery
->swelling_full_check_cnt
= 0;
2836 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2837 battery
->is_recharging
= false;
2838 sec_bat_set_charge(battery
, false);
2839 battery
->expired_time
= battery
->pdata
->expired_time
;
2840 battery
->prev_safety_time
= 0;
2845 static void sec_bat_calculate_safety_time(struct sec_battery_info
*battery
)
2847 unsigned long expired_time
= battery
->expired_time
;
2848 struct timespec ts
= {0, };
2850 int input_power
= battery
->current_max
* battery
->input_voltage
* 1000;
2851 int charging_power
= battery
->charging_current
* battery
->pdata
->swelling_normal_float_voltage
;
2853 if (battery
->lcd_status
&& battery
->stop_timer
) {
2854 battery
->prev_safety_time
= 0;
2858 get_monotonic_boottime(&ts
);
2860 if (battery
->prev_safety_time
== 0) {
2861 battery
->prev_safety_time
= ts
.tv_sec
;
2864 if (input_power
> charging_power
) {
2865 curr
= battery
->charging_current
;
2867 curr
= input_power
/ battery
->pdata
->swelling_normal_float_voltage
;
2868 curr
= (curr
* 9) / 10;
2871 if (battery
->lcd_status
&& !battery
->stop_timer
) {
2872 battery
->stop_timer
= true;
2873 } else if (!battery
->lcd_status
&& battery
->stop_timer
) {
2874 battery
->stop_timer
= false;
2877 pr_info("%s : EXPIRED_TIME(%ld), IP(%d), CP(%d), CURR(%d), STANDARD(%d)\n",
2878 __func__
, expired_time
, input_power
, charging_power
, curr
, battery
->pdata
->standard_curr
);
2880 /* We don't need to calculate the safety timer if charge current is 0 */
2882 /* Update the prev_safety_time if the expired_time is still max */
2883 if(battery
->expired_time
== battery
->pdata
->expired_time
) {
2884 battery
->prev_safety_time
= ts
.tv_sec
;
2889 expired_time
= (expired_time
* battery
->pdata
->standard_curr
) / curr
;
2891 pr_info("%s : CAL_EXPIRED_TIME(%ld) TIME NOW(%ld) TIME PREV(%ld)\n", __func__
, expired_time
, ts
.tv_sec
, battery
->prev_safety_time
);
2893 if (expired_time
<= ((ts
.tv_sec
- battery
->prev_safety_time
) * 100))
2896 expired_time
-= ((ts
.tv_sec
- battery
->prev_safety_time
) * 100);
2898 battery
->cal_safety_time
= expired_time
;
2899 expired_time
= (expired_time
* curr
) / battery
->pdata
->standard_curr
;
2901 battery
->expired_time
= expired_time
;
2902 battery
->prev_safety_time
= ts
.tv_sec
;
2903 pr_info("%s : REMAIN_TIME(%ld) CAL_REMAIN_TIME(%ld)\n", __func__
, battery
->expired_time
, battery
->cal_safety_time
);
2906 #if defined(CONFIG_CALC_TIME_TO_FULL)
2907 static void sec_bat_calc_time_to_full(struct sec_battery_info
* battery
)
2909 if (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) {
2910 union power_supply_propval value
;
2911 int input
= battery
->pdata
->charging_current
[battery
->cable_type
].input_current_limit
;
2912 int charge
= battery
->pdata
->charging_current
[battery
->cable_type
].fast_charging_current
;
2913 if ((battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
) ||
2914 (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
) ||
2915 (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
)) {
2916 value
.intval
= charge
;
2917 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2918 value
.intval
= battery
->current_max
+ 100;
2919 } else if (input
== battery
->current_max
) {
2920 if (input
== 1800) // TA cannot charge 2100
2921 value
.intval
= 1950;
2923 value
.intval
= charge
- 50;
2925 value
.intval
= battery
->current_max
+ 100;
2927 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2928 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW
, value
);
2929 dev_info(battery
->dev
, "%s: T: %5d sec, passed time: %5ld\n",
2930 __func__
, value
.intval
, battery
->charging_passed_time
);
2931 battery
->timetofull
= value
.intval
;
2933 battery
->timetofull
= -1;
2937 static void sec_bat_time_to_full_work(struct work_struct
*work
)
2939 struct sec_battery_info
*battery
= container_of(work
,
2940 struct sec_battery_info
, timetofull_work
.work
);
2941 union power_supply_propval value
;
2942 psy_do_property(battery
->pdata
->charger_name
, get
,
2943 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
2944 battery
->current_max
= value
.intval
;
2945 sec_bat_calc_time_to_full(battery
);
2946 battery
->complete_timetofull
= true;
2947 dev_info(battery
->dev
, "%s: \n",__func__
);
2948 if (battery
->voltage_now
> 0)
2949 battery
->voltage_now
--;
2950 power_supply_changed(&battery
->psy_bat
);
2954 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
2955 static void sec_bat_cc_cv_mode_check(struct sec_battery_info
*battery
)
2957 union power_supply_propval value
;
2959 if ((battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) &&
2960 (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) &&
2961 (battery
->capacity
>= battery
->pdata
->wireless_cc_cv
) &&
2962 !battery
->cc_cv_mode
&&
2963 (battery
->charging_passed_time
> 5)) {
2964 pr_info("%s changed wireless vout voltage to default value \n",__func__
);
2965 battery
->cc_cv_mode
= 1;
2967 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
2968 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
2973 static void sec_bat_siop_work(struct work_struct
*work
)
2975 struct sec_battery_info
*battery
= container_of(work
,
2976 struct sec_battery_info
, siop_work
.work
);
2977 union power_supply_propval value
;
2979 value
.intval
= battery
->siop_level
;
2980 pr_info("%s : set current by siop level(%d)\n",__func__
, battery
->siop_level
);
2981 psy_do_property(battery
->pdata
->charger_name
, set
,
2982 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN
, value
);
2984 #if !defined(CONFIG_SEC_FACTORY)
2985 if (battery
->pdata
->chg_temp_check
)
2986 sec_bat_chg_temperature_check(battery
);
2989 wake_unlock(&battery
->siop_wake_lock
);
2992 static void sec_bat_monitor_work(
2993 struct work_struct
*work
)
2995 struct sec_battery_info
*battery
=
2996 container_of(work
, struct sec_battery_info
,
2998 static struct timespec old_ts
;
2999 struct timespec c_ts
;
3001 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
3002 #if defined(ANDROID_ALARM_ACTIVATED)
3003 c_ts
= ktime_to_timespec(alarm_get_elapsed_realtime());
3005 c_ts
= ktime_to_timespec(ktime_get_boottime());
3008 /* monitor once after wakeup */
3009 if (battery
->polling_in_sleep
) {
3010 battery
->polling_in_sleep
= false;
3011 if ((battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) &&
3012 (battery
->ps_enable
!= true)) {
3013 if ((unsigned long)(c_ts
.tv_sec
- old_ts
.tv_sec
) < 10 * 60) {
3014 union power_supply_propval value
;
3016 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3017 POWER_SUPPLY_PROP_VOLTAGE_NOW
, value
);
3018 battery
->voltage_now
= value
.intval
;
3019 sec_bat_get_temperature_info(battery
);
3020 power_supply_changed(&battery
->psy_bat
);
3021 pr_info("Skip monitor work(%ld, Vnow:%dmV, Tbat:%d)\n",
3022 c_ts
.tv_sec
- old_ts
.tv_sec
, battery
->voltage_now
, battery
->temperature
);
3028 /* update last monitor time */
3031 sec_bat_get_battery_info(battery
);
3033 #if defined(CONFIG_CALC_TIME_TO_FULL)
3034 /* time to full check */
3035 sec_bat_calc_time_to_full(battery
);
3038 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
3039 sec_bat_cc_cv_mode_check(battery
);
3043 if (battery
->test_mode
) {
3044 dev_err(battery
->dev
, "%s: Test Mode\n", __func__
);
3045 sec_bat_do_test_function(battery
);
3046 if (battery
->test_mode
!= 0)
3047 goto continue_monitor
;
3050 /* 1. battery check */
3051 if (!sec_bat_battery_cable_check(battery
))
3052 goto continue_monitor
;
3054 /* 2. voltage check */
3055 if (!sec_bat_voltage_check(battery
))
3056 goto continue_monitor
;
3058 /* monitor short routine in initial monitor */
3059 if (battery
->pdata
->monitor_initial_count
||
3060 sec_bat_is_short_polling(battery
))
3061 goto continue_monitor
;
3063 /* 3. time management */
3064 if (!sec_bat_time_management(battery
))
3065 goto continue_monitor
;
3067 /* 4. temperature check */
3068 if (!sec_bat_temperature_check(battery
))
3069 goto continue_monitor
;
3071 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
3072 sec_bat_discharging_check(battery
);
3075 #if defined(CONFIG_BATTERY_SWELLING)
3076 sec_bat_swelling_check(battery
, battery
->temperature
);
3077 set_swelling_current(battery
);
3079 if (battery
->swelling_mode
&& !battery
->charging_block
)
3080 sec_bat_swelling_fullcharged_check(battery
);
3082 sec_bat_fullcharged_check(battery
);
3084 /* 5. full charging check */
3085 sec_bat_fullcharged_check(battery
);
3086 #endif /* CONFIG_BATTERY_SWELLING */
3088 /* 6. additional check */
3089 if (battery
->pdata
->monitor_additional_check
)
3090 battery
->pdata
->monitor_additional_check();
3092 #if !defined(CONFIG_SEC_FACTORY)
3093 /* 7. charger temperature check */
3094 if (battery
->pdata
->chg_temp_check
)
3095 sec_bat_chg_temperature_check(battery
);
3100 /* calculate safety time */
3101 if (!battery
->charging_block
)
3102 sec_bat_calculate_safety_time(battery
);
3105 #if defined(CONFIG_AFC_CHARGER_MODE)
3106 dev_info(battery
->dev
,
3107 "%s: Status(%s), mode(%s), Health(%s), Cable(%d,%d), level(%d%%), HV(%s), Cycle(%d)\n",
3109 sec_bat_status_str
[battery
->status
],
3110 sec_bat_charging_mode_str
[battery
->charging_mode
],
3111 sec_bat_health_str
[battery
->health
],
3112 battery
->cable_type
, battery
->muic_cable_type
, battery
->siop_level
,
3113 battery
->hv_chg_name
, battery
->batt_cycle
);
3115 dev_info(battery
->dev
,
3116 "%s: Status(%s), mode(%s), Health(%s), Cable(%d,%d), level(%d%%), Cycle(%d)\n",
3118 sec_bat_status_str
[battery
->status
],
3119 sec_bat_charging_mode_str
[battery
->charging_mode
],
3120 sec_bat_health_str
[battery
->health
],
3121 battery
->cable_type
, battery
->muic_cable_type
, battery
->siop_level
, battery
->batt_cycle
);
3123 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
3124 dev_info(battery
->dev
,
3125 "%s: battery->stability_test(%d), battery->eng_not_full_status(%d)\n",
3126 __func__
, battery
->stability_test
, battery
->eng_not_full_status
);
3128 if (battery
->store_mode
&& !lpcharge
&& (battery
->cable_type
!= POWER_SUPPLY_TYPE_BATTERY
)) {
3130 dev_info(battery
->dev
,
3131 "%s: @battery->capacity = (%d), battery->status= (%d), battery->store_mode=(%d)\n",
3132 __func__
, battery
->capacity
, battery
->status
, battery
->store_mode
);
3134 if ((battery
->capacity
>= STORE_MODE_CHARGING_MAX
) && (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
)) {
3135 sec_bat_set_charging_status(battery
,
3136 POWER_SUPPLY_STATUS_DISCHARGING
);
3137 sec_bat_set_charge(battery
, false);
3139 if ((battery
->capacity
<= STORE_MODE_CHARGING_MIN
) && (battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
)) {
3140 sec_bat_set_charging_status(battery
,
3141 POWER_SUPPLY_STATUS_CHARGING
);
3142 if (battery
->siop_level
!= 100)
3143 battery
->stop_timer
= true;
3144 sec_bat_set_charge(battery
, true);
3147 power_supply_changed(&battery
->psy_bat
);
3150 sec_bat_set_polling(battery
);
3152 if (battery
->capacity
<= 0 || battery
->health_change
)
3153 wake_lock_timeout(&battery
->monitor_wake_lock
, HZ
* 5);
3155 wake_unlock(&battery
->monitor_wake_lock
);
3157 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
3162 #if defined(ANDROID_ALARM_ACTIVATED)
3163 static void sec_bat_alarm(struct alarm
*alarm
)
3165 static enum alarmtimer_restart
sec_bat_alarm(
3166 struct alarm
*alarm
, ktime_t now
)
3170 struct sec_battery_info
*battery
= container_of(alarm
,
3171 struct sec_battery_info
, polling_alarm
);
3173 dev_dbg(battery
->dev
,
3176 /* In wake up, monitor work will be queued in complete function
3177 * To avoid duplicated queuing of monitor work,
3178 * do NOT queue monitor work in wake up by polling alarm
3180 if (!battery
->polling_in_sleep
) {
3181 wake_lock(&battery
->monitor_wake_lock
);
3182 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
3183 dev_dbg(battery
->dev
, "%s: Activated\n", __func__
);
3185 #if !defined(ANDROID_ALARM_ACTIVATED)
3186 return ALARMTIMER_NORESTART
;
3191 static void sec_bat_cable_work(struct work_struct
*work
)
3193 struct sec_battery_info
*battery
= container_of(work
,
3194 struct sec_battery_info
, cable_work
.work
);
3195 union power_supply_propval val
;
3196 int wl_cur
, wr_cur
, current_cable_type
;
3197 bool keep_charging_state
= false;
3199 dev_info(battery
->dev
, "%s: Start\n", __func__
);
3201 wl_cur
= battery
->pdata
->charging_current
[
3202 POWER_SUPPLY_TYPE_WIRELESS
].input_current_limit
;
3203 wr_cur
= battery
->pdata
->charging_current
[
3204 battery
->wire_status
].input_current_limit
;
3205 if (battery
->wc_status
&& battery
->wc_enable
&&
3207 current_cable_type
= POWER_SUPPLY_TYPE_WIRELESS
;
3209 current_cable_type
= battery
->wire_status
;
3211 if ((current_cable_type
== battery
->cable_type
) && !battery
->slate_mode
) {
3212 dev_dbg(battery
->dev
,
3213 "%s: Cable is NOT Changed(%d)\n",
3214 __func__
, battery
->cable_type
);
3215 /* Do NOT activate cable work for NOT changed */
3216 goto end_of_cable_work
;
3219 #if defined(CONFIG_BATTERY_SWELLING)
3220 if (current_cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
3221 battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
3222 battery
->swelling_mode
= false;
3223 /* restore 4.4V float voltage */
3224 val
.intval
= battery
->pdata
->swelling_normal_float_voltage
;
3225 psy_do_property(battery
->pdata
->charger_name
, set
,
3226 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
3227 pr_info("%s: float voltage = %d\n", __func__
, val
.intval
);
3229 pr_info("%s: skip float_voltage setting, swelling_mode(%d)\n",
3230 __func__
, battery
->swelling_mode
);
3234 if (battery
->charging_block
&&
3235 ((battery
->cable_type
!= POWER_SUPPLY_TYPE_BATTERY
&& current_cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) ||
3236 (current_cable_type
!= POWER_SUPPLY_TYPE_BATTERY
&& battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) ||
3237 (current_cable_type
!= POWER_SUPPLY_TYPE_BATTERY
&& battery
->cable_type
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
) ||
3238 (current_cable_type
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
) || battery
->swelling_mode
)) {
3239 keep_charging_state
= true;
3240 pr_info("%s: keep charging state (prev cable type:%d, now cable type:%d, swelling_mode:%d)\n",
3241 __func__
, battery
->cable_type
, current_cable_type
, battery
->swelling_mode
);
3244 battery
->cable_type
= current_cable_type
;
3245 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
)
3246 power_supply_changed(&battery
->psy_bat
);
3248 if (battery
->pdata
->check_cable_result_callback
)
3249 battery
->pdata
->check_cable_result_callback(
3250 battery
->cable_type
);
3251 /* platform can NOT get information of cable connection
3252 * because wakeup time is too short to check uevent
3253 * To make sure that target is wakeup
3254 * if cable is connected and disconnected,
3255 * activated wake lock in a few seconds
3257 wake_lock_timeout(&battery
->vbus_wake_lock
, HZ
* 10);
3259 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
3260 ((battery
->pdata
->cable_check_type
&
3261 SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE
) &&
3262 battery
->cable_type
== POWER_SUPPLY_TYPE_UNKNOWN
)) {
3263 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
3264 battery
->is_recharging
= false;
3265 sec_bat_set_charging_status(battery
,
3266 POWER_SUPPLY_STATUS_DISCHARGING
);
3267 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
3268 #if defined(CONFIG_CALC_TIME_TO_FULL)
3269 battery
->complete_timetofull
= false;
3270 cancel_delayed_work(&battery
->timetofull_work
);
3272 if (sec_bat_set_charge(battery
, false))
3273 goto end_of_cable_work
;
3274 } else if (battery
->slate_mode
== true) {
3275 sec_bat_set_charging_status(battery
,
3276 POWER_SUPPLY_STATUS_DISCHARGING
);
3277 battery
->cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
3280 psy_do_property(battery
->pdata
->charger_name
, set
,
3281 POWER_SUPPLY_PROP_CURRENT_NOW
, val
);
3283 dev_info(battery
->dev
,
3284 "%s:slate mode on\n",__func__
);
3286 if (sec_bat_set_charge(battery
, false))
3287 goto end_of_cable_work
;
3289 #if defined(CONFIG_EN_OOPS)
3290 val
.intval
= battery
->cable_type
;
3291 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
3292 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN
, val
);
3294 /* Do NOT display the charging icon when OTG or HMT_CONNECTED is enabled */
3295 if (battery
->cable_type
== POWER_SUPPLY_TYPE_OTG
) {
3296 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
3297 sec_bat_set_charging_status(battery
,
3298 POWER_SUPPLY_STATUS_DISCHARGING
);
3300 if (!keep_charging_state
) {
3301 if (battery
->pdata
->full_check_type
!=
3302 SEC_BATTERY_FULLCHARGED_NONE
)
3303 battery
->charging_mode
=
3304 SEC_BATTERY_CHARGING_1ST
;
3306 battery
->charging_mode
=
3307 SEC_BATTERY_CHARGING_2ND
;
3310 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
)
3311 sec_bat_set_charging_status(battery
,
3312 POWER_SUPPLY_STATUS_FULL
);
3313 else if (!keep_charging_state
)
3314 sec_bat_set_charging_status(battery
,
3315 POWER_SUPPLY_STATUS_CHARGING
);
3317 if (!keep_charging_state
) {
3318 if (sec_bat_set_charge(battery
, true))
3319 goto end_of_cable_work
;
3322 if (battery
->siop_level
!= 100)
3323 battery
->stop_timer
= true;
3326 if (battery
->status
!= POWER_SUPPLY_STATUS_DISCHARGING
) {
3327 battery
->input_voltage
=
3328 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
? 9 : 5;
3330 #if defined(CONFIG_CALC_TIME_TO_FULL)
3331 if ((battery
->cable_type
!= POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) &&
3332 (current_cable_type
!= POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
))
3333 battery
->complete_timetofull
= false;
3334 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->timetofull_work
,
3335 msecs_to_jiffies(4000));
3337 #if defined(ANDROID_ALARM_ACTIVATED)
3338 /* No need for wakelock in Alarm */
3339 if (battery
->pdata
->polling_type
!= SEC_BATTERY_MONITOR_ALARM
)
3340 wake_lock(&battery
->vbus_wake_lock
);
3344 /* polling time should be reset when cable is changed
3345 * polling_in_sleep should be reset also
3346 * before polling time is re-calculated
3347 * to prevent from counting 1 for events
3348 * right after cable is connected
3350 battery
->polling_in_sleep
= false;
3351 sec_bat_get_polling_time(battery
);
3353 dev_info(battery
->dev
,
3354 "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n",
3355 __func__
, sec_bat_status_str
[battery
->status
],
3356 battery
->polling_in_sleep
? "Yes" : "No",
3357 (battery
->charging_mode
==
3358 SEC_BATTERY_CHARGING_NONE
) ? "No" : "Yes",
3359 battery
->polling_short
? "Yes" : "No");
3360 dev_info(battery
->dev
,
3361 "%s: Polling time is reset to %d sec.\n", __func__
,
3362 battery
->polling_time
);
3364 battery
->polling_count
= 1; /* initial value = 1 */
3366 wake_lock(&battery
->monitor_wake_lock
);
3367 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
3369 wake_unlock(&battery
->cable_wake_lock
);
3370 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
3373 ssize_t
sec_bat_show_attrs(struct device
*dev
,
3374 struct device_attribute
*attr
, char *buf
)
3376 struct power_supply
*psy
= dev_get_drvdata(dev
);
3377 struct sec_battery_info
*battery
=
3378 container_of(psy
, struct sec_battery_info
, psy_bat
);
3379 const ptrdiff_t offset
= attr
- sec_battery_attrs
;
3380 union power_supply_propval value
;
3384 case BATT_RESET_SOC
:
3386 case BATT_READ_RAW_SOC
:
3388 union power_supply_propval value
;
3391 SEC_FUELGAUGE_CAPACITY_TYPE_RAW
;
3392 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3393 POWER_SUPPLY_PROP_CAPACITY
, value
);
3395 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3399 case BATT_READ_ADJ_SOC
:
3402 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n",
3403 battery
->pdata
->vendor
);
3406 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3407 battery
->voltage_ocv
);
3410 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3411 battery
->inbat_adc
);
3413 case BATT_VOL_ADC_CAL
:
3417 case BATT_VOL_ADC_AVER
:
3420 case BATT_CURRENT_UA_NOW
:
3422 union power_supply_propval value
;
3424 value
.intval
= SEC_BATTERY_CURRENT_UA
;
3425 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3426 POWER_SUPPLY_PROP_CURRENT_NOW
, value
);
3428 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3432 case BATT_CURRENT_UA_AVG
:
3434 union power_supply_propval value
;
3436 value
.intval
= SEC_BATTERY_CURRENT_UA
;
3437 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3438 POWER_SUPPLY_PROP_CURRENT_AVG
, value
);
3440 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3446 switch (battery
->pdata
->thermal_source
) {
3447 case SEC_BATTERY_THERMAL_SOURCE_FG
:
3448 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3449 POWER_SUPPLY_PROP_TEMP
, value
);
3451 case SEC_BATTERY_THERMAL_SOURCE_CALLBACK
:
3452 if (battery
->pdata
->get_temperature_callback
) {
3453 battery
->pdata
->get_temperature_callback(
3454 POWER_SUPPLY_PROP_TEMP
, &value
);
3457 case SEC_BATTERY_THERMAL_SOURCE_ADC
:
3458 sec_bat_get_temperature_by_adc(battery
,
3459 SEC_BAT_ADC_CHANNEL_TEMP
, &value
);
3464 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3469 If F/G is used for reading the temperature and
3470 compensation table is used,
3471 the raw value that isn't compensated can be read by
3472 POWER_SUPPLY_PROP_TEMP_AMBIENT
3474 switch (battery
->pdata
->thermal_source
) {
3475 case SEC_BATTERY_THERMAL_SOURCE_FG
:
3476 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3477 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
3478 battery
->temp_adc
= value
.intval
;
3483 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3486 case BATT_TEMP_AVER
:
3488 case BATT_TEMP_ADC_AVER
:
3491 #if defined(CONFIG_AFC_CHARGER_MODE)
3492 sec_bat_get_temperature_by_adc(battery
,
3493 SEC_BAT_ADC_CHANNEL_CHG_TEMP
, &value
);
3494 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3497 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3502 #if defined(CONFIG_AFC_CHARGER_MODE)
3503 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3504 battery
->chg_temp_adc
);
3506 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3512 case BATT_SLATE_MODE
:
3513 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3514 battery
->slate_mode
);
3517 case BATT_LP_CHARGING
:
3519 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3523 case SIOP_ACTIVATED
:
3526 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3527 battery
->siop_level
);
3529 case BATT_CHARGING_SOURCE
:
3530 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3531 battery
->cable_type
);
3539 union power_supply_propval value
;
3542 SEC_BATTERY_CAPACITY_DESIGNED
;
3543 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3544 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3546 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x ",
3550 SEC_BATTERY_CAPACITY_ABSOLUTE
;
3551 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3552 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3554 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x ",
3558 SEC_BATTERY_CAPACITY_TEMPERARY
;
3559 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3560 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3562 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x ",
3566 SEC_BATTERY_CAPACITY_CURRENT
;
3567 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3568 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3570 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x\n",
3575 #if defined(CONFIG_INBATTERY)
3576 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3577 POWER_SUPPLY_PROP_ENERGY_FULL
, value
);
3581 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3586 case CHG_CURRENT_ADC
:
3587 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3588 battery
->current_adc
);
3593 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3594 (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
));
3597 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3598 battery
->wc_enable
);
3600 case HV_CHARGER_STATUS
:
3603 if (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
||
3604 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
||
3605 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
)
3607 #if defined(CONFIG_CHARGER_SM5705)
3608 else if (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
)
3611 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", check_val
);
3614 case HV_CHARGER_SET
:
3617 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3618 battery
->factory_mode
);
3621 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3622 battery
->store_mode
);
3627 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3628 battery
->test_mode
);
3631 case BATT_EVENT_CALL
:
3632 case BATT_EVENT_2G_CALL
:
3633 case BATT_EVENT_TALK_GSM
:
3634 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3635 (battery
->event
& EVENT_2G_CALL
) ? 1 : 0);
3637 case BATT_EVENT_3G_CALL
:
3638 case BATT_EVENT_TALK_WCDMA
:
3639 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3640 (battery
->event
& EVENT_3G_CALL
) ? 1 : 0);
3642 case BATT_EVENT_MUSIC
:
3643 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3644 (battery
->event
& EVENT_MUSIC
) ? 1 : 0);
3646 case BATT_EVENT_VIDEO
:
3647 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3648 (battery
->event
& EVENT_VIDEO
) ? 1 : 0);
3650 case BATT_EVENT_BROWSER
:
3651 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3652 (battery
->event
& EVENT_BROWSER
) ? 1 : 0);
3654 case BATT_EVENT_HOTSPOT
:
3655 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3656 (battery
->event
& EVENT_HOTSPOT
) ? 1 : 0);
3658 case BATT_EVENT_CAMERA
:
3659 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3660 (battery
->event
& EVENT_CAMERA
) ? 1 : 0);
3662 case BATT_EVENT_CAMCORDER
:
3663 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3664 (battery
->event
& EVENT_CAMCORDER
) ? 1 : 0);
3666 case BATT_EVENT_DATA_CALL
:
3667 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3668 (battery
->event
& EVENT_DATA_CALL
) ? 1 : 0);
3670 case BATT_EVENT_WIFI
:
3671 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3672 (battery
->event
& EVENT_WIFI
) ? 1 : 0);
3674 case BATT_EVENT_WIBRO
:
3675 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3676 (battery
->event
& EVENT_WIBRO
) ? 1 : 0);
3678 case BATT_EVENT_LTE
:
3679 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3680 (battery
->event
& EVENT_LTE
) ? 1 : 0);
3682 case BATT_EVENT_LCD
:
3683 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3684 (battery
->event
& EVENT_LCD
) ? 1 : 0);
3686 case BATT_EVENT_GPS
:
3687 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3688 (battery
->event
& EVENT_GPS
) ? 1 : 0);
3691 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3694 case BATT_TEMP_TABLE
:
3695 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
,
3696 "%d %d %d %d %d %d %d %d %d %d %d %d\n",
3697 battery
->pdata
->temp_high_threshold_event
,
3698 battery
->pdata
->temp_high_recovery_event
,
3699 battery
->pdata
->temp_low_threshold_event
,
3700 battery
->pdata
->temp_low_recovery_event
,
3701 battery
->pdata
->temp_high_threshold_normal
,
3702 battery
->pdata
->temp_high_recovery_normal
,
3703 battery
->pdata
->temp_low_threshold_normal
,
3704 battery
->pdata
->temp_low_recovery_normal
,
3705 battery
->pdata
->temp_high_threshold_lpm
,
3706 battery
->pdata
->temp_high_recovery_lpm
,
3707 battery
->pdata
->temp_low_threshold_lpm
,
3708 battery
->pdata
->temp_low_recovery_lpm
);
3710 case BATT_HIGH_CURRENT_USB
:
3711 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3712 battery
->is_hc_usb
);
3714 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
3715 case BATT_TEST_CHARGE_CURRENT
:
3717 union power_supply_propval value
;
3719 psy_do_property(battery
->pdata
->charger_name
, get
,
3720 POWER_SUPPLY_PROP_CURRENT_NOW
, value
);
3721 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3726 case BATT_STABILITY_TEST
:
3727 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3728 battery
->stability_test
);
3730 #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX)
3731 case BATT_CAPACITY_MAX
:
3732 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3733 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN
, value
);
3734 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3737 case BATT_INBAT_VOLTAGE
:
3740 ret
= sec_bat_get_inbat_vol_by_adc(battery
);
3741 dev_info(battery
->dev
, "in-battery voltage(%d)\n", ret
);
3742 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3746 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
3747 case BATT_DISCHARGING_CHECK
:
3748 sec_bat_self_discharging_check(battery
);
3749 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3750 battery
->self_discharging
);
3752 case BATT_DISCHARGING_CHECK_ADC
:
3753 sec_bat_self_discharging_check(battery
);
3754 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3755 battery
->self_discharging_adc
);
3757 case BATT_DISCHARGING_NTC
:
3758 sec_bat_self_discharging_ntc_check(battery
);
3759 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3760 battery
->discharging_ntc
);
3762 case BATT_DISCHARGING_NTC_ADC
:
3763 sec_bat_self_discharging_ntc_check(battery
);
3764 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3765 battery
->discharging_ntc_adc
);
3767 case BATT_SELF_DISCHARGING_CONTROL
:
3770 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
3771 case BATT_INBAT_WIRELESS_CS100
:
3772 psy_do_property(battery
->pdata
->wireless_charger_name
, get
,
3773 POWER_SUPPLY_PROP_STATUS
, value
);
3774 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3777 case HMT_TA_CONNECTED
:
3778 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3779 (battery
->cable_type
== POWER_SUPPLY_TYPE_HMT_CONNECTED
) ? 1 : 0);
3782 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3783 (battery
->cable_type
== POWER_SUPPLY_TYPE_HMT_CHARGE
) ? 1 : 0);
3786 value
.intval
= SEC_BATTERY_CAPACITY_CYCLE
;
3787 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3788 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3789 value
.intval
= value
.intval
/ 100;
3790 dev_info(battery
->dev
, "fg cycle(%d)\n", value
.intval
);
3791 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3793 case FG_FULL_VOLTAGE
:
3794 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", battery
->pdata
->chg_float_voltage
);
3798 SEC_BATTERY_CAPACITY_AGEDCELL
;
3799 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3800 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3801 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3804 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", battery
->batt_cycle
);
3812 void update_external_temp_table(struct sec_battery_info
*battery
, int temp
[])
3814 battery
->pdata
->temp_high_threshold_event
= temp
[0];
3815 battery
->pdata
->temp_high_recovery_event
= temp
[1];
3816 battery
->pdata
->temp_low_threshold_event
= temp
[2];
3817 battery
->pdata
->temp_low_recovery_event
= temp
[3];
3818 battery
->pdata
->temp_high_threshold_normal
= temp
[4];
3819 battery
->pdata
->temp_high_recovery_normal
= temp
[5];
3820 battery
->pdata
->temp_low_threshold_normal
= temp
[6];
3821 battery
->pdata
->temp_low_recovery_normal
= temp
[7];
3822 battery
->pdata
->temp_high_threshold_lpm
= temp
[8];
3823 battery
->pdata
->temp_high_recovery_lpm
= temp
[9];
3824 battery
->pdata
->temp_low_threshold_lpm
= temp
[10];
3825 battery
->pdata
->temp_low_recovery_lpm
= temp
[11];
3827 if (battery
->pdata
->temp_high_threshold_event
!=
3828 battery
->pdata
->temp_high_threshold_normal
)
3829 battery
->pdata
->event_check
= 1;
3832 ssize_t
sec_bat_store_attrs(
3834 struct device_attribute
*attr
,
3835 const char *buf
, size_t count
)
3837 struct power_supply
*psy
= dev_get_drvdata(dev
);
3838 struct sec_battery_info
*battery
=
3839 container_of(psy
, struct sec_battery_info
, psy_bat
);
3840 const ptrdiff_t offset
= attr
- sec_battery_attrs
;
3845 case BATT_RESET_SOC
:
3846 /* Do NOT reset fuel gauge in charging mode */
3847 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
3848 battery
->cable_type
== POWER_SUPPLY_TYPE_UARTOFF
) {
3849 union power_supply_propval value
;
3850 battery
->voltage_now
= 1234;
3851 battery
->voltage_avg
= 1234;
3852 power_supply_changed(&battery
->psy_bat
);
3855 SEC_FUELGAUGE_CAPACITY_TYPE_RESET
;
3856 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
3857 POWER_SUPPLY_PROP_CAPACITY
, value
);
3858 dev_info(battery
->dev
,"do reset SOC\n");
3859 /* update battery info */
3860 sec_bat_get_battery_info(battery
);
3864 case BATT_READ_RAW_SOC
:
3866 case BATT_READ_ADJ_SOC
:
3874 case BATT_VOL_ADC_CAL
:
3878 case BATT_VOL_ADC_AVER
:
3880 case BATT_CURRENT_UA_NOW
:
3882 case BATT_CURRENT_UA_AVG
:
3888 case BATT_TEMP_AVER
:
3890 case BATT_TEMP_ADC_AVER
:
3898 case BATT_SLATE_MODE
:
3899 if (sscanf(buf
, "%d\n", &x
) == 1) {
3900 union power_supply_propval value
;
3902 battery
->slate_mode
= true;
3903 } else if (x
== 0) {
3904 battery
->slate_mode
= false;
3906 dev_info(battery
->dev
,
3907 "%s: SLATE MODE unknown command\n",
3911 slate_mode_state
= battery
->slate_mode
;
3912 wake_lock(&battery
->cable_wake_lock
);
3913 queue_delayed_work_on(0, battery
->monitor_wqueue
,
3914 &battery
->cable_work
, 0);
3915 if (battery
->slate_mode
) {
3917 psy_do_property(battery
->pdata
->charger_name
, set
,
3918 POWER_SUPPLY_PROP_CURRENT_NOW
,
3920 if (battery
->pdata
->always_enable
)
3921 psy_do_property(battery
->pdata
->charger_name
, set
,
3922 POWER_SUPPLY_PROP_CHARGING_ENABLED
,
3929 case BATT_LP_CHARGING
:
3931 case SIOP_ACTIVATED
:
3934 if (sscanf(buf
, "%d\n", &x
) == 1) {
3937 dev_info(battery
->dev
,
3938 "%s: siop level: %d\n", __func__
, x
);
3939 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
3941 if (x
== battery
->siop_level
&& battery
->capacity
> 5) {
3942 dev_info(battery
->dev
,
3943 "%s: skip same siop level: %d\n", __func__
, x
);
3945 } else if (x
>= 0 && x
<= 100) {
3946 battery
->siop_level
= x
;
3948 battery
->siop_level
= 100;
3951 get_monotonic_boottime(&ts
);
3952 if ((battery
->r_siop_level
!= battery
->siop_level
) &&
3953 (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
||
3954 battery
->status
== POWER_SUPPLY_STATUS_FULL
) &&
3955 !(battery
->charging_block
)) {
3956 if (battery
->siop_level
>= 100) {
3957 battery
->lcd_on_total_time
+= ts
.tv_sec
- battery
->lcd_on_time
;
3958 battery
->lcd_on_time
= 0;
3960 if (!battery
->lcd_on_time
)
3961 battery
->lcd_on_time
= ts
.tv_sec
;
3965 battery
->r_siop_level
= battery
->siop_level
;
3967 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
3968 union power_supply_propval value
;
3969 value
.intval
= battery
->siop_level
;
3970 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
3971 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN
, value
);
3973 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
&&
3974 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&&
3975 !battery
->cc_cv_mode
&&
3976 battery
->siop_level
== 100 ) {
3977 value
.intval
= 0; /* 5.5 */
3978 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
3979 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
3980 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
&&
3981 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&&
3982 !battery
->cc_cv_mode
&&
3983 battery
->siop_level
!= 100) {
3984 value
.intval
= 1; /* 5 */
3985 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
3986 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
3989 if (battery
->capacity
<= 5) {
3990 battery
->siop_level
= 100;
3991 battery
->ignore_siop
= true;
3992 } else if (battery
->ignore_siop
) {
3993 battery
->ignore_siop
= false;
3996 wake_lock(&battery
->siop_wake_lock
);
3998 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
)
3999 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
,
4000 msecs_to_jiffies(1200));
4002 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
, 0);
4007 case BATT_CHARGING_SOURCE
:
4017 case CHG_CURRENT_ADC
:
4024 if (sscanf(buf
, "%d\n", &x
) == 1) {
4026 battery
->wc_enable
= false;
4027 } else if (x
== 1) {
4028 battery
->wc_enable
= true;
4030 dev_info(battery
->dev
,
4031 "%s: WPC ENABLE unknown command\n",
4035 wake_lock(&battery
->cable_wake_lock
);
4036 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4037 &battery
->cable_work
, 0);
4041 case HV_CHARGER_STATUS
:
4043 case HV_CHARGER_SET
:
4044 if (sscanf(buf
, "%d\n", &x
) == 1) {
4045 dev_info(battery
->dev
,
4046 "%s: HV_CHARGER_SET(%d)\n", __func__
, x
);
4048 battery
->wire_status
= POWER_SUPPLY_TYPE_HV_MAINS
;
4049 wake_lock(&battery
->cable_wake_lock
);
4050 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4052 battery
->wire_status
= POWER_SUPPLY_TYPE_BATTERY
;
4053 wake_lock(&battery
->cable_wake_lock
);
4054 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4060 if (sscanf(buf
, "%d\n", &x
) == 1) {
4061 battery
->factory_mode
= x
? true : false;
4066 if (sscanf(buf
, "%d\n", &x
) == 1) {
4068 battery
->store_mode
= true;
4069 #if !defined(CONFIG_SEC_FACTORY)
4070 if (battery
->capacity
<= 5) {
4071 battery
->ignore_store_mode
= true;
4073 union power_supply_propval value
;
4074 value
.intval
= battery
->store_mode
;
4075 psy_do_property(battery
->pdata
->charger_name
, set
,
4076 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
, value
);
4084 if (sscanf(buf
, "%d\n", &x
) == 1) {
4085 #ifdef CONFIG_FUELGAUGE_S2MU005
4086 union power_supply_propval value
;
4088 /* update rVBAT register every 250ms for AT+BATTTEST */
4090 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
4091 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
4094 sec_bat_get_battery_info(battery
);
4096 /* update rVBAT register every 4s for normal case */
4098 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
4099 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
4101 /* update battery info */
4102 sec_bat_get_battery_info(battery
);
4108 if (sscanf(buf
, "%d\n", &x
) == 1) {
4109 battery
->test_mode
= x
;
4110 wake_lock(&battery
->monitor_wake_lock
);
4111 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4112 &battery
->monitor_work
, 0);
4117 case BATT_EVENT_CALL
:
4118 case BATT_EVENT_2G_CALL
:
4119 case BATT_EVENT_TALK_GSM
:
4120 if (sscanf(buf
, "%d\n", &x
) == 1) {
4121 sec_bat_event_set(battery
, EVENT_2G_CALL
, x
);
4125 case BATT_EVENT_3G_CALL
:
4126 case BATT_EVENT_TALK_WCDMA
:
4127 if (sscanf(buf
, "%d\n", &x
) == 1) {
4128 sec_bat_event_set(battery
, EVENT_3G_CALL
, x
);
4132 case BATT_EVENT_MUSIC
:
4133 if (sscanf(buf
, "%d\n", &x
) == 1) {
4134 sec_bat_event_set(battery
, EVENT_MUSIC
, x
);
4138 case BATT_EVENT_VIDEO
:
4139 if (sscanf(buf
, "%d\n", &x
) == 1) {
4140 sec_bat_event_set(battery
, EVENT_VIDEO
, x
);
4144 case BATT_EVENT_BROWSER
:
4145 if (sscanf(buf
, "%d\n", &x
) == 1) {
4146 sec_bat_event_set(battery
, EVENT_BROWSER
, x
);
4150 case BATT_EVENT_HOTSPOT
:
4151 if (sscanf(buf
, "%d\n", &x
) == 1) {
4152 sec_bat_event_set(battery
, EVENT_HOTSPOT
, x
);
4156 case BATT_EVENT_CAMERA
:
4157 if (sscanf(buf
, "%d\n", &x
) == 1) {
4158 sec_bat_event_set(battery
, EVENT_CAMERA
, x
);
4162 case BATT_EVENT_CAMCORDER
:
4163 if (sscanf(buf
, "%d\n", &x
) == 1) {
4164 sec_bat_event_set(battery
, EVENT_CAMCORDER
, x
);
4168 case BATT_EVENT_DATA_CALL
:
4169 if (sscanf(buf
, "%d\n", &x
) == 1) {
4170 sec_bat_event_set(battery
, EVENT_DATA_CALL
, x
);
4174 case BATT_EVENT_WIFI
:
4175 if (sscanf(buf
, "%d\n", &x
) == 1) {
4176 sec_bat_event_set(battery
, EVENT_WIFI
, x
);
4180 case BATT_EVENT_WIBRO
:
4181 if (sscanf(buf
, "%d\n", &x
) == 1) {
4182 sec_bat_event_set(battery
, EVENT_WIBRO
, x
);
4186 case BATT_EVENT_LTE
:
4187 if (sscanf(buf
, "%d\n", &x
) == 1) {
4188 sec_bat_event_set(battery
, EVENT_LTE
, x
);
4192 case BATT_EVENT_LCD
:
4193 if (sscanf(buf
, "%d\n", &x
) == 1) {
4195 sec_bat_event_set(battery, EVENT_LCD, x);
4198 battery
->lcd_status
= true;
4200 battery
->lcd_status
= false;
4205 case BATT_EVENT_GPS
:
4206 if (sscanf(buf
, "%d\n", &x
) == 1) {
4207 sec_bat_event_set(battery
, EVENT_GPS
, x
);
4211 case BATT_TEMP_TABLE
:
4212 if (sscanf(buf
, "%d %d %d %d %d %d %d %d %d %d %d %d\n",
4213 &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) {
4214 pr_info("%s: (new) %d %d %d %d %d %d %d %d %d %d %d %d\n",
4215 __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]);
4216 pr_info("%s: (default) %d %d %d %d %d %d %d %d %d %d %d %d\n",
4218 battery
->pdata
->temp_high_threshold_event
,
4219 battery
->pdata
->temp_high_recovery_event
,
4220 battery
->pdata
->temp_low_threshold_event
,
4221 battery
->pdata
->temp_low_recovery_event
,
4222 battery
->pdata
->temp_high_threshold_normal
,
4223 battery
->pdata
->temp_high_recovery_normal
,
4224 battery
->pdata
->temp_low_threshold_normal
,
4225 battery
->pdata
->temp_low_recovery_normal
,
4226 battery
->pdata
->temp_high_threshold_lpm
,
4227 battery
->pdata
->temp_high_recovery_lpm
,
4228 battery
->pdata
->temp_low_threshold_lpm
,
4229 battery
->pdata
->temp_low_recovery_lpm
);
4230 update_external_temp_table(battery
, t
);
4234 case BATT_HIGH_CURRENT_USB
:
4235 if (sscanf(buf
, "%d\n", &x
) == 1) {
4236 union power_supply_propval value
;
4237 battery
->is_hc_usb
= x
? true : false;
4238 value
.intval
= battery
->is_hc_usb
;
4240 psy_do_property(battery
->pdata
->charger_name
, set
,
4241 POWER_SUPPLY_PROP_USB_HC
, value
);
4243 pr_info("%s: is_hc_usb (%d)\n", __func__
, battery
->is_hc_usb
);
4247 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
4248 case BATT_TEST_CHARGE_CURRENT
:
4249 if (sscanf(buf
, "%d\n", &x
) == 1) {
4250 if (x
>= 0 && x
<= 2000) {
4251 union power_supply_propval value
;
4252 dev_err(battery
->dev
,
4253 "%s: BATT_TEST_CHARGE_CURRENT(%d)\n", __func__
, x
);
4254 battery
->pdata
->charging_current
[
4255 POWER_SUPPLY_TYPE_USB
].input_current_limit
= x
;
4256 battery
->pdata
->charging_current
[
4257 POWER_SUPPLY_TYPE_USB
].fast_charging_current
= x
;
4259 battery
->eng_not_full_status
= true;
4260 battery
->pdata
->temp_check_type
=
4261 SEC_BATTERY_TEMP_CHECK_NONE
;
4262 battery
->pdata
->charging_total_time
=
4265 if (battery
->cable_type
== POWER_SUPPLY_TYPE_USB
) {
4267 psy_do_property(battery
->pdata
->charger_name
, set
,
4268 POWER_SUPPLY_PROP_CURRENT_NOW
,
4276 case BATT_STABILITY_TEST
:
4277 if (sscanf(buf
, "%d\n", &x
) == 1) {
4278 dev_err(battery
->dev
,
4279 "%s: BATT_STABILITY_TEST(%d)\n", __func__
, x
);
4281 battery
->stability_test
= true;
4282 battery
->eng_not_full_status
= true;
4285 battery
->stability_test
= false;
4286 battery
->eng_not_full_status
= false;
4291 #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX)
4292 case BATT_CAPACITY_MAX
:
4293 if (sscanf(buf
, "%d\n", &x
) == 1 && !fg_reset
) {
4294 union power_supply_propval value
;
4295 dev_err(battery
->dev
,
4296 "%s: BATT_CAPACITY_MAX(%d)\n", __func__
, x
);
4297 if (x
> 800 && x
< 1200) {
4299 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
4300 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN
, value
);
4305 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
4306 POWER_SUPPLY_PROP_CAPACITY
, value
);
4307 battery
->capacity
= value
.intval
;
4308 power_supply_changed(&battery
->psy_bat
);
4313 case BATT_INBAT_VOLTAGE
:
4315 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
4316 case BATT_DISCHARGING_CHECK
:
4318 case BATT_DISCHARGING_CHECK_ADC
:
4320 case BATT_DISCHARGING_NTC
:
4322 case BATT_DISCHARGING_NTC_ADC
:
4324 case BATT_SELF_DISCHARGING_CONTROL
:
4325 if (sscanf(buf
, "%d\n", &x
) == 1) {
4326 dev_err(battery
->dev
,
4327 "%s: BATT_SELF_DISCHARGING_CONTROL(%d)\n", __func__
, x
);
4329 battery
->factory_self_discharging_mode_on
= true;
4330 pr_info("SELF DISCHARGING IC ENABLE\n");
4331 sec_bat_self_discharging_control(battery
, true);
4333 battery
->factory_self_discharging_mode_on
= false;
4334 pr_info("SELF DISCHARGING IC DISENABLE\n");
4335 sec_bat_self_discharging_control(battery
, false);
4341 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
4342 case BATT_INBAT_WIRELESS_CS100
:
4343 if (sscanf(buf
, "%d\n", &x
) == 1) {
4344 union power_supply_propval value
;
4346 pr_info("%s send cs100 command \n",__func__
);
4347 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
4348 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
4349 POWER_SUPPLY_PROP_STATUS
, value
);
4354 case HMT_TA_CONNECTED
:
4355 if (sscanf(buf
, "%d\n", &x
) == 1) {
4356 union power_supply_propval value
;
4357 dev_info(battery
->dev
,
4358 "%s: HMT_TA_CONNECTED(%d)\n", __func__
, x
);
4360 value
.intval
= false;
4361 psy_do_property(battery
->pdata
->charger_name
, set
,
4362 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4364 dev_info(battery
->dev
,
4365 "%s: changed to OTG cable detached\n", __func__
);
4367 battery
->wire_status
= POWER_SUPPLY_TYPE_HMT_CONNECTED
;
4368 wake_lock(&battery
->cable_wake_lock
);
4369 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4371 value
.intval
= true;
4372 psy_do_property(battery
->pdata
->charger_name
, set
,
4373 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4375 dev_info(battery
->dev
,
4376 "%s: changed to OTG cable attached\n", __func__
);
4378 battery
->wire_status
= POWER_SUPPLY_TYPE_OTG
;
4379 wake_lock(&battery
->cable_wake_lock
);
4380 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4386 if (sscanf(buf
, "%d\n", &x
) == 1) {
4387 union power_supply_propval value
;
4388 dev_info(battery
->dev
,
4389 "%s: HMT_TA_CHARGE(%d)\n", __func__
, x
);
4390 psy_do_property(battery
->pdata
->charger_name
, get
,
4391 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, value
);
4393 dev_info(battery
->dev
,
4394 "%s: ignore HMT_TA_CHARGE(%d)\n", __func__
, x
);
4397 value
.intval
= false;
4398 psy_do_property(battery
->pdata
->charger_name
, set
,
4399 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4401 dev_info(battery
->dev
,
4402 "%s: changed to OTG cable detached\n", __func__
);
4403 battery
->wire_status
= POWER_SUPPLY_TYPE_HMT_CHARGE
;
4404 wake_lock(&battery
->cable_wake_lock
);
4405 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4407 value
.intval
= false;
4408 psy_do_property(battery
->pdata
->charger_name
, set
,
4409 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4411 dev_info(battery
->dev
,
4412 "%s: changed to OTG cable detached\n", __func__
);
4413 battery
->wire_status
= POWER_SUPPLY_TYPE_HMT_CONNECTED
;
4414 wake_lock(&battery
->cable_wake_lock
);
4415 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4423 case FG_FULL_VOLTAGE
:
4428 if (sscanf(buf
, "%d\n", &x
) == 1) {
4429 dev_info(battery
->dev
, "%s: BATTERY_CYCLE(%d)\n", __func__
, x
);
4431 int prev_battery_cycle
;
4432 prev_battery_cycle
= battery
->batt_cycle
;
4433 battery
->batt_cycle
= x
;
4434 #if defined(CONFIG_BATTERY_AGE_FORECAST)
4435 dev_info(battery
->dev
, "%s: [Long life] prev_battery_cycle = %d, new bat. cycle = %d\n", __func__
, prev_battery_cycle
, battery
->batt_cycle
);
4436 if (prev_battery_cycle
< 0) {
4437 dev_info(battery
->dev
, "%s: [Long life] Do sec_bat_aging_check()\n", __func__
);
4438 sec_bat_aging_check(battery
);
4445 case FACTORY_MODE_RELIEVE
:
4446 if (sscanf(buf
, "%d\n", &x
) == 1) {
4447 union power_supply_propval value
;
4449 psy_do_property(battery
->pdata
->charger_name
, set
,
4450 POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION
, value
);
4454 case FACTORY_MODE_BYPASS
:
4455 if (sscanf(buf
, "%d\n", &x
) == 1) {
4456 union power_supply_propval value
;
4458 psy_do_property(battery
->pdata
->charger_name
, set
,
4459 POWER_SUPPLY_PROP_AUTHENTIC
, value
);
4470 static int sec_bat_create_attrs(struct device
*dev
)
4475 for (i
= 0; i
< ARRAY_SIZE(sec_battery_attrs
); i
++) {
4476 rc
= device_create_file(dev
, &sec_battery_attrs
[i
]);
4478 goto create_attrs_failed
;
4480 goto create_attrs_succeed
;
4482 create_attrs_failed
:
4484 device_remove_file(dev
, &sec_battery_attrs
[i
]);
4485 create_attrs_succeed
:
4489 static int sec_bat_set_property(struct power_supply
*psy
,
4490 enum power_supply_property psp
,
4491 const union power_supply_propval
*val
)
4493 struct sec_battery_info
*battery
=
4494 container_of(psy
, struct sec_battery_info
, psy_bat
);
4495 int current_cable_type
;
4496 int full_check_type
;
4498 dev_dbg(battery
->dev
,
4499 "%s: (%d,%d)\n", __func__
, psp
, val
->intval
);
4502 case POWER_SUPPLY_PROP_STATUS
:
4503 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
)
4504 full_check_type
= battery
->pdata
->full_check_type
;
4506 full_check_type
= battery
->pdata
->full_check_type_2nd
;
4507 if ((full_check_type
== SEC_BATTERY_FULLCHARGED_CHGINT
) &&
4508 (val
->intval
== POWER_SUPPLY_STATUS_FULL
))
4509 sec_bat_do_fullcharged(battery
);
4510 sec_bat_set_charging_status(battery
, val
->intval
);
4512 case POWER_SUPPLY_PROP_HEALTH
:
4513 sec_bat_ovp_uvlo_result(battery
, val
->intval
);
4515 case POWER_SUPPLY_PROP_ONLINE
:
4516 current_cable_type
= val
->intval
;
4518 if ((battery
->muic_cable_type
!= ATTACHED_DEV_SMARTDOCK_TA_MUIC
)
4519 && ((current_cable_type
== POWER_SUPPLY_TYPE_SMART_OTG
) ||
4520 (current_cable_type
== POWER_SUPPLY_TYPE_SMART_NOTG
)))
4523 if (current_cable_type
< 0) {
4524 dev_info(battery
->dev
,
4525 "%s: ignore event(%d)\n",
4526 __func__
, current_cable_type
);
4527 } else if (current_cable_type
== POWER_SUPPLY_TYPE_OTG
) {
4528 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
4529 battery
->is_recharging
= false;
4530 sec_bat_set_charging_status(battery
,
4531 POWER_SUPPLY_STATUS_DISCHARGING
);
4532 battery
->cable_type
= current_cable_type
;
4533 wake_lock(&battery
->monitor_wake_lock
);
4534 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4535 &battery
->monitor_work
, 0);
4538 battery
->wire_status
= current_cable_type
;
4539 if ((battery
->wire_status
== POWER_SUPPLY_TYPE_BATTERY
)
4540 && battery
->wc_status
)
4541 current_cable_type
= POWER_SUPPLY_TYPE_WIRELESS
;
4543 dev_info(battery
->dev
,
4544 "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n",
4545 __func__
, current_cable_type
, battery
->wc_status
,
4546 battery
->wire_status
);
4548 /* cable is attached or detached
4549 * if current_cable_type is minus value,
4550 * check cable by sec_bat_get_cable_type()
4551 * although SEC_BATTERY_CABLE_SOURCE_EXTERNAL is set
4552 * (0 is POWER_SUPPLY_TYPE_UNKNOWN)
4554 if ((current_cable_type
>= 0) &&
4555 (current_cable_type
< SEC_SIZEOF_POWER_SUPPLY_TYPE
) &&
4556 (battery
->pdata
->cable_source_type
&
4557 SEC_BATTERY_CABLE_SOURCE_EXTERNAL
)) {
4559 wake_lock(&battery
->cable_wake_lock
);
4560 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4561 &battery
->cable_work
,0);
4563 if (sec_bat_get_cable_type(battery
,
4564 battery
->pdata
->cable_source_type
)) {
4565 wake_lock(&battery
->cable_wake_lock
);
4566 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4567 &battery
->cable_work
,0);
4571 case POWER_SUPPLY_PROP_CAPACITY
:
4572 battery
->capacity
= val
->intval
;
4573 power_supply_changed(&battery
->psy_bat
);
4575 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
4576 /* If JIG is attached, the voltage is set as 1079 */
4577 pr_info("%s : set to the battery history : (%d)\n",__func__
, val
->intval
);
4578 if(val
->intval
== 1079) {
4579 battery
->voltage_now
= 1079;
4580 battery
->voltage_avg
= 1079;
4581 power_supply_changed(&battery
->psy_bat
);
4584 case POWER_SUPPLY_PROP_CURRENT_AVG
:
4585 battery
->charging_current
= val
->intval
;
4587 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
4588 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
4590 case POWER_SUPPLY_PROP_PRESENT
:
4591 battery
->present
= val
->intval
;
4593 wake_lock(&battery
->monitor_wake_lock
);
4594 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4595 &battery
->monitor_work
, 0);
4597 #if defined(CONFIG_BATTERY_SWELLING)
4598 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT
:
4608 static int sec_bat_get_property(struct power_supply
*psy
,
4609 enum power_supply_property psp
,
4610 union power_supply_propval
*val
)
4612 struct sec_battery_info
*battery
=
4613 container_of(psy
, struct sec_battery_info
, psy_bat
);
4614 union power_supply_propval value
;
4615 #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY)
4616 union power_supply_propval value_ac
;
4617 union power_supply_propval value_usb
;
4621 case POWER_SUPPLY_PROP_STATUS
:
4622 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERVOLTAGE
) ||
4623 (battery
->health
== POWER_SUPPLY_HEALTH_UNDERVOLTAGE
)) {
4624 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
4626 if ((battery
->pdata
->cable_check_type
&
4627 SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE
) &&
4629 switch (battery
->cable_type
) {
4630 case POWER_SUPPLY_TYPE_USB
:
4631 case POWER_SUPPLY_TYPE_USB_DCP
:
4632 case POWER_SUPPLY_TYPE_USB_CDP
:
4633 case POWER_SUPPLY_TYPE_USB_ACA
:
4635 POWER_SUPPLY_STATUS_DISCHARGING
;
4639 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
4640 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
&&
4641 battery
->capacity
!= 100) {
4642 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
4643 pr_info("%s: forced full-charged sequence progressing\n", __func__
);
4646 val
->intval
= battery
->status
;
4648 #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY)
4649 psy_do_property("ac", get
, POWER_SUPPLY_PROP_ONLINE
, value_ac
);
4650 psy_do_property("usb", get
, POWER_SUPPLY_PROP_ONLINE
, value_usb
);
4651 if (battery
->store_mode
&& !lpcharge
&& (value_ac
.intval
|| value_usb
.intval
)) {
4652 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
4657 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
4658 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
4659 battery
->cable_type
== POWER_SUPPLY_TYPE_MHL_USB_100
) {
4660 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_NONE
;
4662 psy_do_property(battery
->pdata
->charger_name
, get
,
4663 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
4664 if (value
.intval
== POWER_SUPPLY_CHARGE_TYPE_UNKNOWN
)
4665 /* if error in CHARGE_TYPE of charger
4666 * set CHARGE_TYPE as NONE
4668 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_NONE
;
4670 val
->intval
= value
.intval
;
4673 case POWER_SUPPLY_PROP_HEALTH
:
4674 val
->intval
= battery
->health
;
4676 case POWER_SUPPLY_PROP_PRESENT
:
4677 val
->intval
= battery
->present
;
4679 case POWER_SUPPLY_PROP_ONLINE
:
4680 val
->intval
= battery
->cable_type
;
4682 case POWER_SUPPLY_PROP_TECHNOLOGY
:
4683 val
->intval
= battery
->pdata
->technology
;
4685 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
4686 #ifdef CONFIG_SEC_FACTORY
4687 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
4688 POWER_SUPPLY_PROP_VOLTAGE_NOW
, value
);
4689 battery
->voltage_now
= value
.intval
;
4690 dev_err(battery
->dev
,
4691 "%s: voltage now(%d)\n", __func__
, battery
->voltage_now
);
4693 /* voltage value should be in uV */
4694 val
->intval
= battery
->voltage_now
* 1000;
4696 case POWER_SUPPLY_PROP_VOLTAGE_AVG
:
4697 #ifdef CONFIG_SEC_FACTORY
4698 value
.intval
= SEC_BATTERY_VOLTAGE_AVERAGE
;
4699 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
4700 POWER_SUPPLY_PROP_VOLTAGE_AVG
, value
);
4701 battery
->voltage_avg
= value
.intval
;
4702 dev_err(battery
->dev
,
4703 "%s: voltage avg(%d)\n", __func__
, battery
->voltage_avg
);
4705 /* voltage value should be in uV */
4706 val
->intval
= battery
->voltage_avg
* 1000;
4708 case POWER_SUPPLY_PROP_CURRENT_NOW
:
4709 val
->intval
= battery
->current_now
;
4711 case POWER_SUPPLY_PROP_CURRENT_AVG
:
4712 val
->intval
= battery
->current_avg
;
4714 /* charging mode (differ from power supply) */
4715 case POWER_SUPPLY_PROP_CHARGE_NOW
:
4716 val
->intval
= battery
->charging_mode
;
4718 case POWER_SUPPLY_PROP_CAPACITY
:
4719 if (battery
->pdata
->fake_capacity
) {
4721 pr_info("%s : capacity(%d)\n", __func__
, val
->intval
);
4723 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
4724 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
) {
4725 if(battery
->eng_not_full_status
)
4726 val
->intval
= battery
->capacity
;
4730 val
->intval
= battery
->capacity
;
4733 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
4734 val
->intval
= battery
->capacity
;
4736 /* In full-charged status, SOC is always 100% */
4737 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
)
4740 val
->intval
= battery
->capacity
;
4745 case POWER_SUPPLY_PROP_TEMP
:
4746 val
->intval
= battery
->temperature
;
4748 case POWER_SUPPLY_PROP_TEMP_AMBIENT
:
4749 val
->intval
= battery
->temper_amb
;
4751 #if defined(CONFIG_CALC_TIME_TO_FULL)
4752 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW
:
4753 #if defined(CONFIG_CHARGING_VZWCONCEPT)
4754 if (battery
->capacity
== 100) {
4759 if (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&& battery
->complete_timetofull
&&
4760 !battery
->swelling_mode
)
4761 val
->intval
= battery
->timetofull
;
4766 #if defined(CONFIG_BATTERY_SWELLING)
4767 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT
:
4768 if ((battery
->swelling_mode
) || (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
))
4780 static int sec_usb_get_property(struct power_supply
*psy
,
4781 enum power_supply_property psp
,
4782 union power_supply_propval
*val
)
4784 struct sec_battery_info
*battery
=
4785 container_of(psy
, struct sec_battery_info
, psy_usb
);
4787 if (psp
!= POWER_SUPPLY_PROP_ONLINE
)
4790 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERVOLTAGE
) ||
4791 (battery
->health
== POWER_SUPPLY_HEALTH_UNDERVOLTAGE
)) {
4795 /* Set enable=1 only if the USB charger is connected */
4796 switch (battery
->wire_status
) {
4797 case POWER_SUPPLY_TYPE_USB
:
4798 case POWER_SUPPLY_TYPE_USB_DCP
:
4799 case POWER_SUPPLY_TYPE_USB_CDP
:
4800 case POWER_SUPPLY_TYPE_USB_ACA
:
4801 case POWER_SUPPLY_TYPE_MHL_USB
:
4802 case POWER_SUPPLY_TYPE_MHL_USB_100
:
4810 if (battery
->slate_mode
)
4815 static int sec_ac_get_property(struct power_supply
*psy
,
4816 enum power_supply_property psp
,
4817 union power_supply_propval
*val
)
4819 struct sec_battery_info
*battery
=
4820 container_of(psy
, struct sec_battery_info
, psy_ac
);
4822 if (psp
!= POWER_SUPPLY_PROP_ONLINE
)
4825 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERVOLTAGE
) ||
4826 (battery
->health
== POWER_SUPPLY_HEALTH_UNDERVOLTAGE
)) {
4831 /* Set enable=1 only if the AC charger is connected */
4832 switch (battery
->cable_type
) {
4833 case POWER_SUPPLY_TYPE_MAINS
:
4834 case POWER_SUPPLY_TYPE_MISC
:
4835 case POWER_SUPPLY_TYPE_CARDOCK
:
4836 case POWER_SUPPLY_TYPE_UARTOFF
:
4837 case POWER_SUPPLY_TYPE_LAN_HUB
:
4838 case POWER_SUPPLY_TYPE_UNKNOWN
:
4839 case POWER_SUPPLY_TYPE_MHL_500
:
4840 case POWER_SUPPLY_TYPE_MHL_900
:
4841 case POWER_SUPPLY_TYPE_MHL_1500
:
4842 case POWER_SUPPLY_TYPE_MHL_2000
:
4843 case POWER_SUPPLY_TYPE_SMART_OTG
:
4844 case POWER_SUPPLY_TYPE_SMART_NOTG
:
4845 case POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
:
4846 case POWER_SUPPLY_TYPE_HV_ERR
:
4847 case POWER_SUPPLY_TYPE_HV_UNKNOWN
:
4848 case POWER_SUPPLY_TYPE_HV_MAINS
:
4849 case POWER_SUPPLY_TYPE_MDOCK_TA
:
4850 case POWER_SUPPLY_TYPE_HMT_CONNECTED
:
4851 case POWER_SUPPLY_TYPE_HMT_CHARGE
:
4852 case POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
:
4863 static int sec_wireless_get_property(struct power_supply
*psy
,
4864 enum power_supply_property psp
,
4865 union power_supply_propval
*val
)
4867 struct sec_battery_info
*battery
=
4868 container_of(psy
, struct sec_battery_info
, psy_wireless
);
4870 if (psp
!= POWER_SUPPLY_PROP_ONLINE
)
4873 if (battery
->wc_status
)
4881 static int sec_wireless_set_property(struct power_supply
*psy
,
4882 enum power_supply_property psp
,
4883 const union power_supply_propval
*val
)
4885 struct sec_battery_info
*battery
=
4886 container_of(psy
, struct sec_battery_info
, psy_wireless
);
4889 case POWER_SUPPLY_PROP_ONLINE
:
4890 battery
->wc_status
= val
->intval
;
4892 wake_lock(&battery
->cable_wake_lock
);
4893 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4894 &battery
->cable_work
, 0);
4896 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
4897 case POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
:
4898 if (battery
->wc_status
) {
4899 union power_supply_propval value
;
4900 value
.intval
= val
->intval
;
4901 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
4902 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, value
);
4913 static int sec_ps_set_property(struct power_supply
*psy
,
4914 enum power_supply_property psp
,
4915 const union power_supply_propval
*val
)
4917 struct sec_battery_info
*battery
=
4918 container_of(psy
, struct sec_battery_info
, psy_ps
);
4919 union power_supply_propval value
;
4922 case POWER_SUPPLY_PROP_STATUS
:
4923 if (val
->intval
== 0) {
4924 if (battery
->ps_enable
== true) {
4925 battery
->ps_enable
= val
->intval
;
4926 dev_info(battery
->dev
,
4927 "%s: power sharing cable set (%d)\n", __func__
, battery
->ps_enable
);
4928 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
4929 psy_do_property(battery
->pdata
->charger_name
, set
,
4930 POWER_SUPPLY_PROP_ONLINE
, value
);
4932 } else if ((val
->intval
== 1) && (battery
->ps_status
== true)) {
4933 battery
->ps_enable
= val
->intval
;
4934 dev_info(battery
->dev
,
4935 "%s: power sharing cable set (%d)\n", __func__
, battery
->ps_enable
);
4936 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
4937 psy_do_property(battery
->pdata
->charger_name
, set
,
4938 POWER_SUPPLY_PROP_ONLINE
, value
);
4940 dev_err(battery
->dev
,
4941 "%s: invalid setting (%d) ps_status (%d)\n",
4942 __func__
, val
->intval
, battery
->ps_status
);
4945 case POWER_SUPPLY_PROP_ONLINE
:
4946 if (val
->intval
== POWER_SUPPLY_TYPE_POWER_SHARING
) {
4947 battery
->ps_status
= true;
4948 battery
->ps_enable
= true;
4949 battery
->ps_changed
= true;
4950 dev_info(battery
->dev
,
4951 "%s: power sharing cable plugin (%d)\n", __func__
, battery
->ps_status
);
4952 wake_lock(&battery
->monitor_wake_lock
);
4953 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
4955 battery
->ps_status
= false;
4956 battery
->ps_enable
= false;
4957 battery
->ps_changed
= false;
4958 dev_info(battery
->dev
,
4959 "%s: power sharing cable plugout (%d)\n", __func__
, battery
->ps_status
);
4960 wake_lock(&battery
->monitor_wake_lock
);
4961 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
4971 static int sec_ps_get_property(struct power_supply
*psy
,
4972 enum power_supply_property psp
,
4973 union power_supply_propval
*val
)
4975 struct sec_battery_info
*battery
=
4976 container_of(psy
, struct sec_battery_info
, psy_ps
);
4977 union power_supply_propval value
;
4980 case POWER_SUPPLY_PROP_STATUS
:
4981 if (battery
->ps_enable
)
4986 case POWER_SUPPLY_PROP_ONLINE
:
4987 if (battery
->ps_status
) {
4988 if ((battery
->ps_enable
== true) && (battery
->ps_changed
== true)) {
4989 battery
->ps_changed
= false;
4991 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
4992 psy_do_property(battery
->pdata
->charger_name
, set
,
4993 POWER_SUPPLY_PROP_ONLINE
, value
);
4997 if (battery
->ps_enable
== true) {
4998 battery
->ps_enable
= false;
4999 dev_info(battery
->dev
,
5000 "%s: power sharing cable disconnected! ps disable (%d)\n",
5001 __func__
, battery
->ps_enable
);
5003 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
5004 psy_do_property(battery
->pdata
->charger_name
, set
,
5005 POWER_SUPPLY_PROP_ONLINE
, value
);
5019 static irqreturn_t
sec_bat_irq_thread(int irq
, void *irq_data
)
5021 struct sec_battery_info
*battery
= irq_data
;
5023 dev_info(battery
->dev
, "%s:(bat_irq occured_start\n", __func__
);
5025 if (battery
->pdata
->cable_check_type
&
5026 SEC_BATTERY_CABLE_CHECK_INT
) {
5027 if (battery
->pdata
->is_interrupt_cable_check_possible
&&
5028 !battery
->pdata
->is_interrupt_cable_check_possible(
5029 battery
->extended_cable_type
))
5030 goto no_cable_check
;
5032 if (sec_bat_get_cable_type(battery
,
5033 battery
->pdata
->cable_source_type
)) {
5034 wake_lock(&battery
->cable_wake_lock
);
5035 queue_delayed_work(battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5042 if (battery
->pdata
->battery_check_type
==
5043 SEC_BATTERY_CHECK_INT
) {
5044 if (battery_pdata
->check_battery_callback
)
5045 battery
->present
= battery
->pdata
->check_battery_callback();
5047 wake_lock(&battery
->monitor_wake_lock
);
5048 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5055 #if defined(CONFIG_MUIC_NOTIFIER)
5056 static int sec_bat_cable_check(struct sec_battery_info
*battery
,
5057 muic_attached_dev_t attached_dev
)
5059 int current_cable_type
= -1;
5060 union power_supply_propval val
;
5062 pr_info("[%s]ATTACHED(%d)\n", __func__
, attached_dev
);
5063 battery
->is_jig_on
= false;
5065 switch (attached_dev
)
5067 case ATTACHED_DEV_JIG_UART_OFF_MUIC
:
5068 case ATTACHED_DEV_JIG_UART_ON_MUIC
:
5069 battery
->is_jig_on
= true;
5070 case ATTACHED_DEV_SMARTDOCK_MUIC
:
5071 case ATTACHED_DEV_DESKDOCK_MUIC
:
5072 current_cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
5074 case ATTACHED_DEV_OTG_MUIC
:
5075 case ATTACHED_DEV_JIG_UART_OFF_VB_OTG_MUIC
:
5076 case ATTACHED_DEV_HMT_MUIC
:
5077 current_cable_type
= POWER_SUPPLY_TYPE_OTG
;
5079 case ATTACHED_DEV_USB_MUIC
:
5080 case ATTACHED_DEV_JIG_USB_OFF_MUIC
:
5081 case ATTACHED_DEV_JIG_USB_ON_MUIC
:
5082 case ATTACHED_DEV_SMARTDOCK_USB_MUIC
:
5083 case ATTACHED_DEV_UNOFFICIAL_ID_USB_MUIC
:
5084 current_cable_type
= POWER_SUPPLY_TYPE_USB
;
5086 case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC
:
5087 case ATTACHED_DEV_JIG_UART_OFF_VB_FG_MUIC
:
5088 current_cable_type
= factory_mode
? POWER_SUPPLY_TYPE_BATTERY
:
5089 POWER_SUPPLY_TYPE_UARTOFF
;
5091 case ATTACHED_DEV_TA_MUIC
:
5092 case ATTACHED_DEV_CARDOCK_MUIC
:
5093 case ATTACHED_DEV_DESKDOCK_VB_MUIC
:
5094 case ATTACHED_DEV_SMARTDOCK_TA_MUIC
:
5095 case ATTACHED_DEV_UNOFFICIAL_TA_MUIC
:
5096 case ATTACHED_DEV_UNOFFICIAL_ID_TA_MUIC
:
5097 case ATTACHED_DEV_UNOFFICIAL_ID_ANY_MUIC
:
5098 case ATTACHED_DEV_UNSUPPORTED_ID_VB_MUIC
:
5099 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5101 case ATTACHED_DEV_QC_CHARGER_5V_MUIC
:
5102 case ATTACHED_DEV_AFC_CHARGER_5V_MUIC
:
5103 #if defined(CONFIG_AFC_CHARGER_MODE)
5104 if (is_hv_wire_type(battery
->cable_type
) || battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
)
5105 current_cable_type
= POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
;
5107 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5109 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5112 case ATTACHED_DEV_CDP_MUIC
:
5113 case ATTACHED_DEV_UNOFFICIAL_ID_CDP_MUIC
:
5114 current_cable_type
= POWER_SUPPLY_TYPE_USB_CDP
;
5116 case ATTACHED_DEV_USB_LANHUB_MUIC
:
5117 current_cable_type
= POWER_SUPPLY_TYPE_LAN_HUB
;
5119 case ATTACHED_DEV_CHARGING_CABLE_MUIC
:
5120 current_cable_type
= POWER_SUPPLY_TYPE_POWER_SHARING
;
5122 case ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC
:
5123 case ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC
:
5124 current_cable_type
= POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
;
5126 case ATTACHED_DEV_AFC_CHARGER_9V_MUIC
:
5127 case ATTACHED_DEV_QC_CHARGER_9V_MUIC
:
5128 current_cable_type
= POWER_SUPPLY_TYPE_HV_MAINS
;
5130 case ATTACHED_DEV_AFC_CHARGER_ERR_V_MUIC
:
5131 case ATTACHED_DEV_QC_CHARGER_ERR_V_MUIC
:
5132 current_cable_type
= POWER_SUPPLY_TYPE_HV_ERR
;
5134 case ATTACHED_DEV_UNDEFINED_CHARGING_MUIC
:
5135 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5137 case ATTACHED_DEV_HV_ID_ERR_UNDEFINED_MUIC
:
5138 case ATTACHED_DEV_HV_ID_ERR_UNSUPPORTED_MUIC
:
5139 case ATTACHED_DEV_HV_ID_ERR_SUPPORTED_MUIC
:
5140 current_cable_type
= POWER_SUPPLY_TYPE_HV_UNKNOWN
;
5142 case ATTACHED_DEV_VZW_INCOMPATIBLE_MUIC
:
5143 current_cable_type
= POWER_SUPPLY_TYPE_UNKNOWN
;
5146 pr_err("%s: invalid type for charger:%d\n",
5147 __func__
, attached_dev
);
5149 #ifndef CONFIG_FUELGAUGE_S2MU005
5150 if (battery
->is_jig_on
)
5151 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
5152 POWER_SUPPLY_PROP_ENERGY_NOW
, val
);
5155 val
.intval
= battery
->is_jig_on
;
5156 psy_do_property(battery
->pdata
->charger_name
, set
,
5157 POWER_SUPPLY_PROP_ENERGY_NOW
, val
);
5159 return current_cable_type
;
5163 static int batt_handle_notification(struct notifier_block
*nb
,
5164 unsigned long action
, void *data
)
5166 muic_attached_dev_t attached_dev
= *(muic_attached_dev_t
*)data
;
5169 struct sec_battery_info
*battery
=
5170 container_of(nb
, struct sec_battery_info
,
5172 union power_supply_propval value
;
5175 case MUIC_NOTIFY_CMD_DETACH
:
5176 case MUIC_NOTIFY_CMD_LOGICALLY_DETACH
:
5178 cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
5179 battery
->muic_cable_type
= ATTACHED_DEV_NONE_MUIC
;
5181 case MUIC_NOTIFY_CMD_ATTACH
:
5182 case MUIC_NOTIFY_CMD_LOGICALLY_ATTACH
:
5184 cable_type
= sec_bat_cable_check(battery
, attached_dev
);
5185 battery
->muic_cable_type
= attached_dev
;
5190 battery
->muic_cable_type
= ATTACHED_DEV_NONE_MUIC
;
5194 if (attached_dev
== ATTACHED_DEV_MHL_MUIC
)
5197 if (cable_type
< 0) {
5198 dev_info(battery
->dev
, "%s: ignore event(%d)\n",
5199 __func__
, cable_type
);
5200 } else if (cable_type
== POWER_SUPPLY_TYPE_POWER_SHARING
) {
5201 battery
->ps_status
= true;
5202 battery
->ps_enable
= true;
5203 battery
->ps_changed
= true;
5205 dev_info(battery
->dev
,
5206 "%s: power sharing cable plugin (%d)\n", __func__
, battery
->ps_status
);
5207 } else if (cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
5208 battery
->wc_status
= true;
5209 } else if ((cable_type
== POWER_SUPPLY_TYPE_UNKNOWN
) &&
5210 (battery
->status
!= POWER_SUPPLY_STATUS_DISCHARGING
)) {
5211 battery
->cable_type
= cable_type
;
5212 wake_lock(&battery
->monitor_wake_lock
);
5213 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5214 dev_info(battery
->dev
,
5215 "%s: UNKNOWN cable plugin\n", __func__
);
5218 battery
->wire_status
= cable_type
;
5219 if ((battery
->wire_status
== POWER_SUPPLY_TYPE_BATTERY
)
5220 && battery
->wc_status
&& !battery
->ps_status
)
5221 cable_type
= POWER_SUPPLY_TYPE_WIRELESS
;
5223 dev_info(battery
->dev
,
5224 "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n",
5225 __func__
, cable_type
, battery
->wc_status
,
5226 battery
->wire_status
);
5228 if (attached_dev
== ATTACHED_DEV_USB_LANHUB_MUIC
) {
5229 if (!strcmp(cmd
, "ATTACH")) {
5230 value
.intval
= true;
5231 psy_do_property(battery
->pdata
->charger_name
, set
,
5232 POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL
,
5234 dev_info(battery
->dev
,
5235 "%s: Powered OTG cable attached\n", __func__
);
5237 value
.intval
= false;
5238 psy_do_property(battery
->pdata
->charger_name
, set
,
5239 POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL
,
5241 dev_info(battery
->dev
,
5242 "%s: Powered OTG cable detached\n", __func__
);
5246 #if defined(CONFIG_AFC_CHARGER_MODE)
5247 if (!strcmp(cmd
, "ATTACH")) {
5248 if ((battery
->muic_cable_type
>= ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC
) &&
5249 (battery
->muic_cable_type
<= ATTACHED_DEV_QC_CHARGER_9V_MUIC
))
5250 battery
->hv_chg_name
= "QC";
5251 else if ((battery
->muic_cable_type
>= ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC
) &&
5252 (battery
->muic_cable_type
<= ATTACHED_DEV_AFC_CHARGER_ERR_V_DUPLI_MUIC
))
5253 battery
->hv_chg_name
= "AFC";
5255 battery
->hv_chg_name
= "NONE";
5257 battery
->hv_chg_name
= "NONE";
5260 pr_info("%s : HV_CHARGER_NAME(%s)\n",
5261 __func__
, battery
->hv_chg_name
);
5264 if ((cable_type
>= 0) &&
5265 cable_type
<= SEC_SIZEOF_POWER_SUPPLY_TYPE
) {
5266 if ((cable_type
== POWER_SUPPLY_TYPE_POWER_SHARING
)
5267 || (cable_type
== POWER_SUPPLY_TYPE_OTG
)) {
5268 wake_lock(&battery
->monitor_wake_lock
);
5269 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5270 } else if((cable_type
== POWER_SUPPLY_TYPE_BATTERY
)
5271 && battery
->ps_status
) {
5272 battery
->ps_status
= false;
5273 dev_info(battery
->dev
,
5274 "%s: power sharing cable plugout (%d)\n", __func__
, battery
->ps_status
);
5275 wake_lock(&battery
->monitor_wake_lock
);
5276 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5277 } else if(cable_type
!= battery
->cable_type
) {
5278 wake_lock(&battery
->cable_wake_lock
);
5279 queue_delayed_work_on(0, battery
->monitor_wqueue
,
5280 &battery
->cable_work
, 0);
5282 dev_info(battery
->dev
,
5283 "%s: Cable is Not Changed(%d)\n",
5284 __func__
, battery
->cable_type
);
5288 pr_info("%s: CMD=%s, attached_dev=%d\n", __func__
, cmd
, attached_dev
);
5292 #endif /* CONFIG_MUIC_NOTIFIER */
5294 #if defined(CONFIG_VBUS_NOTIFIER)
5295 static int vbus_handle_notification(struct notifier_block
*nb
,
5296 unsigned long action
, void *data
)
5298 vbus_status_t vbus_status
= *(vbus_status_t
*)data
;
5299 struct sec_battery_info
*battery
=
5300 container_of(nb
, struct sec_battery_info
,
5302 union power_supply_propval value
;
5304 if (battery
->muic_cable_type
== ATTACHED_DEV_HMT_MUIC
&&
5305 battery
->muic_vbus_status
!= vbus_status
&&
5306 battery
->muic_vbus_status
== STATUS_VBUS_HIGH
&&
5307 vbus_status
== STATUS_VBUS_LOW
) {
5308 sec_bat_set_charge(battery
, false);
5310 value
.intval
= true;
5311 psy_do_property(battery
->pdata
->charger_name
, set
,
5312 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
5314 dev_info(battery
->dev
,
5315 "%s: changed to OTG cable attached\n", __func__
);
5317 battery
->wire_status
= POWER_SUPPLY_TYPE_OTG
;
5318 wake_lock(&battery
->cable_wake_lock
);
5319 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
5321 pr_info("%s: action=%d, vbus_status=%d\n", __func__
, (int)action
, vbus_status
);
5322 battery
->muic_vbus_status
= vbus_status
;
5330 static int sec_bat_parse_dt(struct device
*dev
,
5331 struct sec_battery_info
*battery
)
5333 struct device_node
*np
= dev
->of_node
;
5334 sec_battery_platform_data_t
*pdata
= battery
->pdata
;
5341 pr_info("%s: np NULL\n", __func__
);
5345 pdata
->wchg_ctl_en
= of_property_read_bool(np
,
5346 "battery,wchg_ctl_en");
5347 if (pdata
->wchg_ctl_en
)
5348 pdata
->wchg_ctl
= of_get_named_gpio(np
, "battery,wchg_ctl", 0);
5350 ret
= of_property_read_string(np
,
5351 "battery,vendor", (char const **)&pdata
->vendor
);
5353 pr_info("%s: Vendor is Empty\n", __func__
);
5355 ret
= of_property_read_string(np
,
5356 "battery,charger_name", (char const **)&pdata
->charger_name
);
5358 pr_info("%s: Vendor is Empty\n", __func__
);
5360 ret
= of_property_read_string(np
,
5361 "battery,fuelgauge_name", (char const **)&pdata
->fuelgauge_name
);
5363 pr_info("%s: Vendor is Empty\n", __func__
);
5365 ret
= of_property_read_string(np
,
5366 "battery,wirelss_charger_name", (char const **)&pdata
->wireless_charger_name
);
5368 pr_info("%s: Vendor is Empty\n", __func__
);
5370 ret
= of_property_read_string(np
,
5371 "battery,chip_vendor", (char const **)&pdata
->chip_vendor
);
5373 pr_info("%s: Vendor is Empty\n", __func__
);
5375 ret
= of_property_read_u32(np
, "battery,technology",
5376 &pdata
->technology
);
5378 pr_info("%s : technology is Empty\n", __func__
);
5380 ret
= of_property_read_u32(np
,
5381 "battery,wireless_cc_cv", &pdata
->wireless_cc_cv
);
5383 pdata
->fake_capacity
= of_property_read_bool(np
,
5384 "battery,fake_capacity");
5386 pdata
->event_check
= of_property_read_bool(np
,
5387 "battery,event_check");
5389 p
= of_get_property(np
, "battery,polling_time", &len
);
5393 len
= len
/ sizeof(u32
);
5394 pdata
->polling_time
= kzalloc(sizeof(*pdata
->polling_time
) * len
, GFP_KERNEL
);
5395 ret
= of_property_read_u32_array(np
, "battery,polling_time",
5396 pdata
->polling_time
, len
);
5398 ret
= of_property_read_u32(np
, "battery,thermal_source",
5399 &pdata
->thermal_source
);
5401 pr_info("%s : Thermal source is Empty\n", __func__
);
5403 if (pdata
->thermal_source
== SEC_BATTERY_THERMAL_SOURCE_ADC
) {
5404 p
= of_get_property(np
, "battery,temp_table_adc", &len
);
5408 len
= len
/ sizeof(u32
);
5410 pdata
->temp_adc_table_size
= len
;
5411 pdata
->temp_amb_adc_table_size
= len
;
5413 pdata
->temp_adc_table
=
5414 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5415 pdata
->temp_adc_table_size
, GFP_KERNEL
);
5416 pdata
->temp_amb_adc_table
=
5417 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5418 pdata
->temp_adc_table_size
, GFP_KERNEL
);
5420 for(i
= 0; i
< pdata
->temp_adc_table_size
; i
++) {
5421 ret
= of_property_read_u32_index(np
,
5422 "battery,temp_table_adc", i
, &temp
);
5423 pdata
->temp_adc_table
[i
].adc
= (int)temp
;
5425 pr_info("%s : Temp_adc_table(adc) is Empty\n",
5428 ret
= of_property_read_u32_index(np
,
5429 "battery,temp_table_data", i
, &temp
);
5430 pdata
->temp_adc_table
[i
].data
= (int)temp
;
5432 pr_info("%s : Temp_adc_table(data) is Empty\n",
5435 ret
= of_property_read_u32_index(np
,
5436 "battery,temp_table_adc", i
, &temp
);
5437 pdata
->temp_amb_adc_table
[i
].adc
= (int)temp
;
5439 pr_info("%s : Temp_amb_adc_table(adc) is Empty\n",
5442 ret
= of_property_read_u32_index(np
,
5443 "battery,temp_table_data", i
, &temp
);
5444 pdata
->temp_amb_adc_table
[i
].data
= (int)temp
;
5446 pr_info("%s : Temp_amb_adc_table(data) is Empty\n",
5450 #if defined(CONFIG_AFC_CHARGER_MODE)
5451 p
= of_get_property(np
, "battery,chg_temp_table_adc", &len
);
5455 len
= len
/ sizeof(u32
);
5457 pdata
->chg_temp_adc_table_size
= len
;
5459 pdata
->chg_temp_adc_table
=
5460 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5461 pdata
->chg_temp_adc_table_size
, GFP_KERNEL
);
5463 for(i
= 0; i
< pdata
->chg_temp_adc_table_size
; i
++) {
5464 ret
= of_property_read_u32_index(np
,
5465 "battery,chg_temp_table_adc", i
, &temp
);
5466 pdata
->chg_temp_adc_table
[i
].adc
= (int)temp
;
5468 pr_info("%s : CHG_Temp_adc_table(adc) is Empty\n",
5471 ret
= of_property_read_u32_index(np
,
5472 "battery,chg_temp_table_data", i
, &temp
);
5473 pdata
->chg_temp_adc_table
[i
].data
= (int)temp
;
5475 pr_info("%s : CHG_Temp_adc_table(data) is Empty\n",
5481 ret
= of_property_read_u32(np
, "battery,chg_temp_check",
5482 &pdata
->chg_temp_check
);
5484 pr_info("%s : chg_temp_check is Empty\n", __func__
);
5486 if (pdata
->chg_temp_check
) {
5487 ret
= of_property_read_u32(np
, "battery,chg_high_temp_1st",
5489 pdata
->chg_high_temp_1st
= (int)temp
;
5491 pr_info("%s : chg_high_temp_threshold is Empty\n", __func__
);
5493 ret
= of_property_read_u32(np
, "battery,chg_high_temp_2nd",
5495 pdata
->chg_high_temp_2nd
= (int)temp
;
5497 pr_info("%s : chg_high_temp_threshold is Empty\n", __func__
);
5499 ret
= of_property_read_u32(np
, "battery,chg_high_temp_recovery",
5501 pdata
->chg_high_temp_recovery
= (int)temp
;
5503 pr_info("%s : chg_temp_recovery is Empty\n", __func__
);
5505 ret
= of_property_read_u32(np
, "battery,chg_charging_limit_current",
5506 &pdata
->chg_charging_limit_current
);
5508 pr_info("%s : chg_charging_limit_current is Empty\n", __func__
);
5510 ret
= of_property_read_u32(np
, "battery,chg_charging_limit_current_2nd",
5511 &pdata
->chg_charging_limit_current_2nd
);
5513 pr_info("%s : chg_charging_limit_current_2nd is Empty\n", __func__
);
5515 ret
= of_property_read_u32(np
, "battery,chg_skip_check_time",
5516 &pdata
->chg_skip_check_time
);
5518 pr_info("%s : chg_skip_check_time is Empty\n", __func__
);
5520 ret
= of_property_read_u32(np
, "battery,chg_skip_check_capacity",
5521 &pdata
->chg_skip_check_capacity
);
5523 pr_info("%s : chg_skip_check_capacity is Empty\n", __func__
);
5525 ret
= of_property_read_u32(np
, "battery,wpc_temp_check",
5526 &pdata
->wpc_temp_check
);
5528 pr_info("%s : wpc_temp_check is Empty\n", __func__
);
5530 if (pdata
->wpc_temp_check
) {
5531 ret
= of_property_read_u32(np
, "battery,wpc_high_temp",
5533 pdata
->wpc_high_temp
= (int)temp
;
5535 pr_info("%s : wpc_high_temp is Empty\n", __func__
);
5537 ret
= of_property_read_u32(np
, "battery,wpc_high_temp_recovery",
5539 pdata
->wpc_high_temp_recovery
= (int)temp
;
5541 pr_info("%s : wpc_high_temp_recovery is Empty\n", __func__
);
5543 ret
= of_property_read_u32(np
, "battery,wpc_charging_limit_current",
5544 &pdata
->wpc_charging_limit_current
);
5546 pr_info("%s : wpc_charging_limit_current is Empty\n", __func__
);
5550 ret
= of_property_read_u32(np
, "battery,inbat_voltage",
5551 &pdata
->inbat_voltage
);
5553 pr_info("%s : inbat_voltage is Empty\n", __func__
);
5555 if (pdata
->inbat_voltage
) {
5556 p
= of_get_property(np
, "battery,inbat_voltage_table_adc", &len
);
5560 len
= len
/ sizeof(u32
);
5562 pdata
->inbat_adc_table_size
= len
;
5564 pdata
->inbat_adc_table
=
5565 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5566 pdata
->inbat_adc_table_size
, GFP_KERNEL
);
5568 for(i
= 0; i
< pdata
->inbat_adc_table_size
; i
++) {
5569 ret
= of_property_read_u32_index(np
,
5570 "battery,inbat_voltage_table_adc", i
, &temp
);
5571 pdata
->inbat_adc_table
[i
].adc
= (int)temp
;
5573 pr_info("%s : inbat_adc_table(adc) is Empty\n",
5576 ret
= of_property_read_u32_index(np
,
5577 "battery,inbat_voltage_table_data", i
, &temp
);
5578 pdata
->inbat_adc_table
[i
].data
= (int)temp
;
5580 pr_info("%s : inbat_adc_table(data) is Empty\n",
5585 p
= of_get_property(np
, "battery,input_current_limit", &len
);
5589 len
= len
/ sizeof(u32
);
5591 pdata
->charging_current
=
5592 kzalloc(sizeof(sec_charging_current_t
) * len
,
5595 for(i
= 0; i
< len
; i
++) {
5596 ret
= of_property_read_u32_index(np
,
5597 "battery,input_current_limit", i
,
5598 &pdata
->charging_current
[i
].input_current_limit
);
5600 pr_info("%s : Input_current_limit is Empty\n",
5603 ret
= of_property_read_u32_index(np
,
5604 "battery,fast_charging_current", i
,
5605 &pdata
->charging_current
[i
].fast_charging_current
);
5607 pr_info("%s : Fast charging current is Empty\n",
5610 ret
= of_property_read_u32_index(np
,
5611 "battery,full_check_current_1st", i
,
5612 &pdata
->charging_current
[i
].full_check_current_1st
);
5614 pr_info("%s : Full check current 1st is Empty\n",
5617 ret
= of_property_read_u32_index(np
,
5618 "battery,full_check_current_2nd", i
,
5619 &pdata
->charging_current
[i
].full_check_current_2nd
);
5621 pr_info("%s : Full check current 2nd is Empty\n",
5625 ret
= of_property_read_u32(np
, "battery,adc_check_count",
5626 &pdata
->adc_check_count
);
5628 pr_info("%s : Adc check count is Empty\n", __func__
);
5630 ret
= of_property_read_u32(np
, "battery,temp_adc_type",
5631 &pdata
->temp_adc_type
);
5633 pr_info("%s : Temp adc type is Empty\n", __func__
);
5635 ret
= of_property_read_u32(np
, "battery,cable_check_type",
5636 &pdata
->cable_check_type
);
5638 pr_info("%s : Cable check type is Empty\n", __func__
);
5640 ret
= of_property_read_u32(np
, "battery,cable_source_type",
5641 &pdata
->cable_source_type
);
5642 #if defined(CONFIG_CHARGING_VZWCONCEPT)
5643 pdata
->cable_check_type
&= ~SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE
;
5644 pdata
->cable_check_type
|= SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE
;
5647 pr_info("%s : Cable source type is Empty\n", __func__
);
5649 ret
= of_property_read_u32(np
, "battery,event_waiting_time",
5650 &pdata
->event_waiting_time
);
5652 pr_info("%s : Event waiting time is Empty\n", __func__
);
5654 ret
= of_property_read_u32(np
, "battery,polling_type",
5655 &pdata
->polling_type
);
5657 pr_info("%s : Polling type is Empty\n", __func__
);
5659 ret
= of_property_read_u32(np
, "battery,monitor_initial_count",
5660 &pdata
->monitor_initial_count
);
5662 pr_info("%s : Monitor initial count is Empty\n", __func__
);
5664 ret
= of_property_read_u32(np
, "battery,battery_check_type",
5665 &pdata
->battery_check_type
);
5667 pr_info("%s : Battery check type is Empty\n", __func__
);
5669 ret
= of_property_read_u32(np
, "battery,check_count",
5670 &pdata
->check_count
);
5672 pr_info("%s : Check count is Empty\n", __func__
);
5674 ret
= of_property_read_u32(np
, "battery,check_adc_max",
5675 &pdata
->check_adc_max
);
5677 pr_info("%s : Check adc max is Empty\n", __func__
);
5679 ret
= of_property_read_u32(np
, "battery,check_adc_min",
5680 &pdata
->check_adc_min
);
5682 pr_info("%s : Check adc min is Empty\n", __func__
);
5684 ret
= of_property_read_u32(np
, "battery,ovp_uvlo_check_type",
5685 &pdata
->ovp_uvlo_check_type
);
5687 pr_info("%s : Ovp Uvlo check type is Empty\n", __func__
);
5689 ret
= of_property_read_u32(np
, "battery,temp_check_type",
5690 &pdata
->temp_check_type
);
5692 pr_info("%s : Temp check type is Empty\n", __func__
);
5694 ret
= of_property_read_u32(np
, "battery,temp_check_count",
5695 &pdata
->temp_check_count
);
5697 pr_info("%s : Temp check count is Empty\n", __func__
);
5699 ret
= of_property_read_u32(np
, "battery,temp_highlimit_threshold_event",
5701 pdata
->temp_highlimit_threshold_event
= (int)temp
;
5703 pr_info("%s : Temp highlimit threshold event is Empty\n", __func__
);
5705 ret
= of_property_read_u32(np
, "battery,temp_highlimit_recovery_event",
5707 pdata
->temp_highlimit_recovery_event
= (int)temp
;
5709 pr_info("%s : Temp highlimit recovery event is Empty\n", __func__
);
5711 ret
= of_property_read_u32(np
, "battery,temp_high_threshold_event",
5713 pdata
->temp_high_threshold_event
= (int)temp
;
5715 pr_info("%s : Temp high threshold event is Empty\n", __func__
);
5717 ret
= of_property_read_u32(np
, "battery,temp_high_recovery_event",
5719 pdata
->temp_high_recovery_event
= (int)temp
;
5721 pr_info("%s : Temp high recovery event is Empty\n", __func__
);
5723 ret
= of_property_read_u32(np
, "battery,temp_low_threshold_event",
5725 pdata
->temp_low_threshold_event
= (int)temp
;
5727 pr_info("%s : Temp low threshold event is Empty\n", __func__
);
5729 ret
= of_property_read_u32(np
, "battery,temp_low_recovery_event",
5731 pdata
->temp_low_recovery_event
= (int)temp
;
5733 pr_info("%s : Temp low recovery event is Empty\n", __func__
);
5735 ret
= of_property_read_u32(np
, "battery,temp_highlimit_threshold_normal",
5737 pdata
->temp_highlimit_threshold_normal
= (int)temp
;
5739 pr_info("%s : Temp highlimit threshold normal is Empty\n", __func__
);
5741 ret
= of_property_read_u32(np
, "battery,temp_highlimit_recovery_normal",
5743 pdata
->temp_highlimit_recovery_normal
= (int)temp
;
5745 pr_info("%s : Temp highlimit recovery normal is Empty\n", __func__
);
5747 ret
= of_property_read_u32(np
, "battery,temp_high_threshold_normal",
5749 pdata
->temp_high_threshold_normal
= (int)temp
;
5751 pr_info("%s : Temp high threshold normal is Empty\n", __func__
);
5753 ret
= of_property_read_u32(np
, "battery,temp_high_recovery_normal",
5755 pdata
->temp_high_recovery_normal
= (int)temp
;
5757 pr_info("%s : Temp high recovery normal is Empty\n", __func__
);
5759 ret
= of_property_read_u32(np
, "battery,temp_low_threshold_normal",
5761 pdata
->temp_low_threshold_normal
= (int)temp
;
5763 pr_info("%s : Temp low threshold normal is Empty\n", __func__
);
5765 ret
= of_property_read_u32(np
, "battery,temp_low_recovery_normal",
5767 pdata
->temp_low_recovery_normal
= (int)temp
;
5769 pr_info("%s : Temp low recovery normal is Empty\n", __func__
);
5771 ret
= of_property_read_u32(np
, "battery,temp_highlimit_threshold_lpm",
5773 pdata
->temp_highlimit_threshold_lpm
= (int)temp
;
5775 pr_info("%s : Temp highlimit threshold lpm is Empty\n", __func__
);
5777 ret
= of_property_read_u32(np
, "battery,temp_highlimit_recovery_lpm",
5779 pdata
->temp_highlimit_recovery_lpm
= (int)temp
;
5781 pr_info("%s : Temp highlimit recovery lpm is Empty\n", __func__
);
5783 ret
= of_property_read_u32(np
, "battery,temp_high_threshold_lpm",
5785 pdata
->temp_high_threshold_lpm
= (int)temp
;
5787 pr_info("%s : Temp high threshold lpm is Empty\n", __func__
);
5789 ret
= of_property_read_u32(np
, "battery,temp_high_recovery_lpm",
5791 pdata
->temp_high_recovery_lpm
= (int)temp
;
5793 pr_info("%s : Temp high recovery lpm is Empty\n", __func__
);
5795 ret
= of_property_read_u32(np
, "battery,temp_low_threshold_lpm",
5797 pdata
->temp_low_threshold_lpm
= (int)temp
;
5799 pr_info("%s : Temp low threshold lpm is Empty\n", __func__
);
5801 ret
= of_property_read_u32(np
, "battery,temp_low_recovery_lpm",
5803 pdata
->temp_low_recovery_lpm
= (int)temp
;
5805 pr_info("%s : Temp low recovery lpm is Empty\n", __func__
);
5807 pr_info("%s : HIGHLIMIT_THRESHOLD_EVENT(%d), HIGHLIMIT_RECOVERY_EVENT(%d)\n"
5808 "HIGH_THRESHOLD_EVENT(%d), HIGH_RECOVERY_EVENT(%d) LOW_THRESHOLD_EVENT(%d), LOW_RECOVERY_EVENT(%d)\n"
5809 "HIGHLIMIT_THRESHOLD_NOLMAL(%d), HIGHLIMIT_RECOVERY_NORMAL(%d)\n"
5810 "HIGH_THRESHOLD_NORMAL(%d), HIGH_RECOVERY_NORMAL(%d) LOW_THRESHOLD_NORMAL(%d), LOW_RECOVERY_NORMAL(%d)\n"
5811 "HIGHLIMIT_THRESHOLD_LPM(%d), HIGHLIMIT_RECOVERY_LPM(%d)\n"
5812 "HIGH_THRESHOLD_LPM(%d), HIGH_RECOVERY_LPM(%d) LOW_THRESHOLD_LPM(%d), LOW_RECOVERY_LPM(%d)\n",
5813 __func__
, pdata
->temp_highlimit_threshold_event
, pdata
->temp_highlimit_recovery_event
,
5814 pdata
->temp_high_threshold_event
, pdata
->temp_high_recovery_event
,
5815 pdata
->temp_low_threshold_event
, pdata
->temp_low_recovery_event
,
5816 pdata
->temp_highlimit_threshold_normal
, pdata
->temp_highlimit_recovery_normal
,
5817 pdata
->temp_high_threshold_normal
, pdata
->temp_high_recovery_normal
,
5818 pdata
->temp_low_threshold_normal
, pdata
->temp_low_recovery_normal
,
5819 pdata
->temp_highlimit_threshold_lpm
, pdata
->temp_highlimit_recovery_lpm
,
5820 pdata
->temp_high_threshold_lpm
, pdata
->temp_high_recovery_lpm
,
5821 pdata
->temp_low_threshold_lpm
, pdata
->temp_low_recovery_lpm
);
5823 ret
= of_property_read_u32(np
, "battery,full_check_type",
5824 &pdata
->full_check_type
);
5826 pr_info("%s : Full check type is Empty\n", __func__
);
5828 ret
= of_property_read_u32(np
, "battery,full_check_type_2nd",
5829 &pdata
->full_check_type_2nd
);
5831 pr_info("%s : Full check type 2nd is Empty\n", __func__
);
5833 ret
= of_property_read_u32(np
, "battery,full_check_count",
5834 &pdata
->full_check_count
);
5836 pr_info("%s : Full check count is Empty\n", __func__
);
5838 ret
= of_property_read_u32(np
, "battery,chg_gpio_full_check",
5839 &pdata
->chg_gpio_full_check
);
5841 pr_info("%s : Chg gpio full check is Empty\n", __func__
);
5843 ret
= of_property_read_u32(np
, "battery,chg_polarity_full_check",
5844 &pdata
->chg_polarity_full_check
);
5846 pr_info("%s : Chg polarity full check is Empty\n", __func__
);
5848 ret
= of_property_read_u32(np
, "battery,full_condition_type",
5849 &pdata
->full_condition_type
);
5851 pr_info("%s : Full condition type is Empty\n", __func__
);
5853 ret
= of_property_read_u32(np
, "battery,full_condition_soc",
5854 &pdata
->full_condition_soc
);
5856 pr_info("%s : Full condition soc is Empty\n", __func__
);
5858 ret
= of_property_read_u32(np
, "battery,full_condition_vcell",
5859 &pdata
->full_condition_vcell
);
5861 pr_info("%s : Full condition vcell is Empty\n", __func__
);
5863 ret
= of_property_read_u32(np
, "battery,recharge_check_count",
5864 &pdata
->recharge_check_count
);
5866 pr_info("%s : Recharge check count is Empty\n", __func__
);
5868 ret
= of_property_read_u32(np
, "battery,recharge_condition_type",
5869 &pdata
->recharge_condition_type
);
5871 pr_info("%s : Recharge condition type is Empty\n", __func__
);
5873 ret
= of_property_read_u32(np
, "battery,recharge_condition_soc",
5874 &pdata
->recharge_condition_soc
);
5876 pr_info("%s : Recharge condition soc is Empty\n", __func__
);
5878 ret
= of_property_read_u32(np
, "battery,recharge_condition_vcell",
5879 &pdata
->recharge_condition_vcell
);
5881 pr_info("%s : Recharge condition vcell is Empty\n", __func__
);
5883 ret
= of_property_read_u32(np
, "battery,charging_total_time",
5884 (unsigned int *)&pdata
->charging_total_time
);
5886 pr_info("%s : Charging total time is Empty\n", __func__
);
5888 ret
= of_property_read_u32(np
, "battery,hv_charging_total_time",
5889 (unsigned int *)&pdata
->hv_charging_total_time
);
5891 pdata
->hv_charging_total_time
= 3 * 60 * 60;
5892 pr_info("%s : HV Charging total time is %d\n",
5893 __func__
, pdata
->hv_charging_total_time
);
5896 ret
= of_property_read_u32(np
, "battery,normal_charging_total_time",
5897 (unsigned int *)&pdata
->normal_charging_total_time
);
5899 pdata
->normal_charging_total_time
= 5 * 60 * 60;
5900 pr_info("%s : Normal(WC) Charging total time is %d\n",
5901 __func__
, pdata
->normal_charging_total_time
);
5904 ret
= of_property_read_u32(np
, "battery,usb_charging_total_time",
5905 (unsigned int *)&pdata
->usb_charging_total_time
);
5907 pdata
->usb_charging_total_time
= 10 * 60 * 60;
5908 pr_info("%s : USB Charging total time is %d\n",
5909 __func__
, pdata
->usb_charging_total_time
);
5912 ret
= of_property_read_u32(np
, "battery,recharging_total_time",
5913 (unsigned int *)&pdata
->recharging_total_time
);
5915 pr_info("%s : Recharging total time is Empty\n", __func__
);
5917 ret
= of_property_read_u32(np
, "battery,charging_reset_time",
5918 (unsigned int *)&pdata
->charging_reset_time
);
5920 pr_info("%s : Charging reset time is Empty\n", __func__
);
5922 ret
= of_property_read_u32(np
, "battery,charging_reset_time",
5923 (unsigned int *)&pdata
->charging_reset_time
);
5925 pr_info("%s : Charging reset time is Empty\n", __func__
);
5927 ret
= of_property_read_u32(np
,
5928 "battery,expired_time", &temp
);
5930 pr_info("expired time is empty\n");
5931 pdata
->expired_time
= 3 * 60 * 60;
5933 pdata
->expired_time
= (unsigned int) temp
;
5935 pdata
->expired_time
*= 100;
5936 battery
->expired_time
= pdata
->expired_time
;
5938 ret
= of_property_read_u32(np
,
5939 "battery,recharging_expired_time", &temp
);
5941 pr_info("expired time is empty\n");
5942 pdata
->recharging_expired_time
= 90 * 60;
5944 pdata
->recharging_expired_time
= (unsigned int) temp
;
5946 pdata
->recharging_expired_time
*= 1000;
5948 ret
= of_property_read_u32(np
,
5949 "battery,standard_curr", &pdata
->standard_curr
);
5951 pr_info("standard_curr is empty\n");
5952 pdata
->standard_curr
= 2150;
5955 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
5956 ret
= of_property_read_u32(np
, "battery,self_discharging_type",
5957 (unsigned int *)&pdata
->self_discharging_type
);
5959 pr_info("%s: Self discharging type is Empty, Set default\n",
5961 pdata
->self_discharging_type
= 0;
5964 pdata
->factory_discharging
= of_get_named_gpio(np
, "battery,factory_discharging", 0);
5965 if (pdata
->factory_discharging
< 0)
5966 pdata
->factory_discharging
= 0;
5968 pdata
->self_discharging_en
= of_property_read_bool(np
,
5969 "battery,self_discharging_en");
5971 ret
= of_property_read_u32(np
, "battery,force_discharging_limit",
5973 pdata
->force_discharging_limit
= (int)temp
;
5975 pr_info("%s : Force Discharging limit is Empty", __func__
);
5977 ret
= of_property_read_u32(np
, "battery,force_discharging_recov",
5979 pdata
->force_discharging_recov
= (int)temp
;
5981 pr_info("%s : Force Discharging recov is Empty", __func__
);
5983 pr_info("%s : FORCE_DISCHARGING_LIMT(%d), FORCE_DISCHARGING_RECOV(%d)\n",
5984 __func__
, pdata
->force_discharging_limit
, pdata
->force_discharging_recov
);
5986 if (!pdata
->self_discharging_type
) {
5987 ret
= of_property_read_u32(np
, "battery,discharging_adc_min",
5988 (unsigned int *)&pdata
->discharging_adc_min
);
5990 pr_info("%s : Discharging ADC Min is Empty", __func__
);
5992 ret
= of_property_read_u32(np
, "battery,discharging_adc_max",
5993 (unsigned int *)&pdata
->discharging_adc_max
);;
5995 pr_info("%s : Discharging ADC Max is Empty", __func__
);
5998 ret
= of_property_read_u32(np
, "battery,self_discharging_voltage_limit",
5999 (unsigned int *)&pdata
->self_discharging_voltage_limit
);
6001 pr_info("%s : Force Discharging recov is Empty", __func__
);
6003 ret
= of_property_read_u32(np
, "battery,discharging_ntc_limit",
6004 (unsigned int *)&pdata
->discharging_ntc_limit
);
6006 pr_info("%s : Discharging NTC LIMIT is Empty", __func__
);
6009 #if defined(CONFIG_BATTERY_SWELLING)
6010 ret
= of_property_read_u32(np
, "battery,swelling_normal_current",
6011 (unsigned int *)&pdata
->swelling_normal_current
);
6013 pr_info("%s: swelling_normal_current is Empty\n", __func__
);
6015 ret
= of_property_read_u32(np
, "battery,chg_float_voltage",
6016 (unsigned int *)&pdata
->swelling_normal_float_voltage
);
6018 pr_info("%s: chg_float_voltage is Empty\n", __func__
);
6020 ret
= of_property_read_u32(np
, "battery,chg_float_voltage",
6021 (unsigned int *)&pdata
->chg_float_voltage
);
6023 pr_info("%s: chg_float_voltage is Empty\n", __func__
);
6025 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_block",
6027 pdata
->swelling_high_temp_block
= (int)temp
;
6029 pr_info("%s: swelling high temp block is Empty\n", __func__
);
6031 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_recov",
6033 pdata
->swelling_high_temp_recov
= (int)temp
;
6035 pr_info("%s: swelling high temp recovery is Empty\n", __func__
);
6037 ret
= of_property_read_u32(np
, "battery,swelling_high_chg_current",
6038 &pdata
->swelling_high_chg_current
);
6040 pr_info("%s: swelling high temp chg current is Empty\n", __func__
);
6041 pdata
->swelling_high_chg_current
= 0;
6044 ret
= of_property_read_u32(np
, "battery,swelling_low_chg_current",
6045 &pdata
->swelling_low_chg_current
);
6047 pr_info("%s: swelling low temp chg current is Empty\n", __func__
);
6048 pdata
->swelling_low_chg_current
= 0;
6051 ret
= of_property_read_u32(np
, "battery,swelling_full_check_current_2nd",
6052 &pdata
->swelling_full_check_current_2nd
);
6054 pr_info("%s: swelling_full_check_current_2nd is Empty\n", __func__
);
6055 pdata
->swelling_full_check_current_2nd
= 0;
6058 ret
= of_property_read_u32(np
, "battery,swelling_drop_float_voltage",
6059 (unsigned int *)&pdata
->swelling_drop_float_voltage
);
6061 pr_info("%s: swelling drop float voltage is Empty\n", __func__
);
6063 ret
= of_property_read_u32(np
, "battery,swelling_high_rechg_voltage",
6064 (unsigned int *)&pdata
->swelling_high_rechg_voltage
);
6066 pr_info("%s: swelling_high_rechg_voltage is Empty\n", __func__
);
6068 ret
= of_property_read_u32(np
, "battery,swelling_low_rechg_voltage",
6069 (unsigned int *)&pdata
->swelling_low_rechg_voltage
);
6071 pr_info("%s: swelling_low_rechg_voltage is Empty\n", __func__
);
6073 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_2step_mode",
6074 &pdata
->swelling_low_temp_2step_mode
);
6076 pr_info("%s: swelling_low_temp_2step_mode is Empty\n", __func__
);
6077 pdata
->swelling_low_temp_2step_mode
= 0;
6080 if(pdata
->swelling_low_temp_2step_mode
) {
6081 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_block_1st",
6083 pdata
->swelling_low_temp_block_1st
= (int)temp
;
6085 pr_info("%s: swelling low temp block is Empty\n", __func__
);
6087 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_recov_1st",
6089 pdata
->swelling_low_temp_recov_1st
= (int)temp
;
6091 pr_info("%s: swelling low temp recovery is Empty\n", __func__
);
6093 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_block_2nd",
6095 pdata
->swelling_low_temp_block_2nd
= (int)temp
;
6097 pr_info("%s: swelling low temp block is Empty\n", __func__
);
6099 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_recov_2nd",
6101 pdata
->swelling_low_temp_recov_2nd
= (int)temp
;
6103 pr_info("%s: swelling low temp recovery 2nd is Empty\n", __func__
);
6106 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_block",
6108 pdata
->swelling_low_temp_block_1st
= (int)temp
;
6109 pdata
->swelling_low_temp_block_2nd
= (int)temp
;
6111 pr_info("%s: swelling low temp block is Empty\n", __func__
);
6113 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_recov",
6115 pdata
->swelling_low_temp_recov_1st
= (int)temp
;
6116 pdata
->swelling_low_temp_recov_2nd
= (int)temp
;
6118 pr_info("%s: swelling low temp recovery is Empty\n", __func__
);
6121 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_current",
6122 &pdata
->swelling_low_temp_current
);
6124 pr_info("%s: swelling_low_temp_current is Empty, Defualt value 600mA \n", __func__
);
6125 pdata
->swelling_low_temp_current
= 600;
6128 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_topoff",
6129 &pdata
->swelling_low_temp_topoff
);
6131 pr_info("%s: swelling_low_temp_topoff is Empty, Defualt value 200mA \n", __func__
);
6132 pdata
->swelling_low_temp_topoff
= 200;
6135 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_current",
6136 &pdata
->swelling_high_temp_current
);
6138 pr_info("%s: swelling_hign_temp_current is Empty, Defualt value 1300mA \n", __func__
);
6139 pdata
->swelling_high_temp_current
= 1300;
6142 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_topoff",
6143 &pdata
->swelling_high_temp_topoff
);
6145 pr_info("%s: swelling_high_temp_topoff is Empty, Defualt value 200mA \n", __func__
);
6146 pdata
->swelling_high_temp_topoff
= 200;
6149 ret
= of_property_read_u32(np
, "battery,swelling_block_time",
6150 (unsigned int *)&pdata
->swelling_block_time
);
6152 pr_info("%s: swelling_block_time is Empty\n", __func__
);
6154 pr_info("%s : SWELLING_HIGH_TEMP(%d) SWELLING_HIGH_TEMP_RECOVERY(%d)\n"
6155 "SWELLING_LOW_TEMP_1st(%d) SWELLING_LOW_TEMP_RECOVERY_1st(%d) "
6156 "SWELLING_LOW_TEMP_2nd(%d) SWELLING_LOW_TEMP_RECOVERY_2nd(%d) "
6157 "SWELLING_LOW_CURRENT(%d, %d), SWELLING_HIGH_CURRENT(%d, %d)\n",
6158 __func__
, pdata
->swelling_high_temp_block
, pdata
->swelling_high_temp_recov
,
6159 pdata
->swelling_low_temp_block_1st
, pdata
->swelling_low_temp_recov_1st
,
6160 pdata
->swelling_low_temp_block_2nd
, pdata
->swelling_low_temp_recov_2nd
,
6161 pdata
->swelling_low_temp_current
, pdata
->swelling_low_temp_topoff
,
6162 pdata
->swelling_high_temp_current
, pdata
->swelling_high_temp_topoff
);
6166 pdata
->always_enable
= of_property_read_bool(np
,
6167 "battery,always_enable");
6169 #if defined(CONFIG_BATTERY_AGE_FORECAST)
6170 p
= of_get_property(np
, "battery,age_data", &len
);
6172 battery
->pdata
->num_age_step
= len
/ sizeof(sec_age_data_t
);
6173 battery
->pdata
->age_data
= kzalloc(len
, GFP_KERNEL
);
6174 ret
= of_property_read_u32_array(np
, "battery,age_data",
6175 (u32
*)battery
->pdata
->age_data
, len
/sizeof(u32
));
6177 pr_err("%s failed to read battery->pdata->age_data: %d\n",
6179 kfree(battery
->pdata
->age_data
);
6180 battery
->pdata
->age_data
= NULL
;
6181 battery
->pdata
->num_age_step
= 0;
6183 pr_err("%s num_age_step : %d\n", __func__
, battery
->pdata
->num_age_step
);
6184 for (len
= 0; len
< battery
->pdata
->num_age_step
; ++len
) {
6185 pr_err("[%d/%d]cycle:%d, float:%d, full_v:%d, recharge_v:%d, soc:%d\n",
6186 len
, battery
->pdata
->num_age_step
-1,
6187 battery
->pdata
->age_data
[len
].cycle
,
6188 battery
->pdata
->age_data
[len
].float_voltage
,
6189 battery
->pdata
->age_data
[len
].recharge_condition_vcell
,
6190 battery
->pdata
->age_data
[len
].full_condition_vcell
,
6191 battery
->pdata
->age_data
[len
].full_condition_soc
);
6194 battery
->pdata
->num_age_step
= 0;
6195 pr_err("%s there is not age_data\n", __func__
);
6203 extern sec_battery_platform_data_t sec_battery_pdata
;
6206 static void cable_initial_check(struct sec_battery_info
*battery
)
6208 union power_supply_propval value
;
6210 pr_info("%s : current_cable_type : (%d)\n", __func__
, battery
->cable_type
);
6212 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
6213 psy_do_property(battery
->pdata
->charger_name
, get
,
6214 POWER_SUPPLY_PROP_ONLINE
, value
);
6215 if (value
.intval
== POWER_SUPPLY_TYPE_WIRELESS
) {
6217 psy_do_property("wireless", set
,
6218 POWER_SUPPLY_PROP_ONLINE
, value
);
6223 static int __devinit
sec_battery_probe(struct platform_device
*pdev
)
6225 sec_battery_platform_data_t
*pdata
= NULL
;
6226 struct sec_battery_info
*battery
;
6232 union power_supply_propval value
;
6235 "%s: SEC Battery Driver Loading\n", __func__
);
6237 battery
= kzalloc(sizeof(*battery
), GFP_KERNEL
);
6241 if (pdev
->dev
.of_node
) {
6242 pdata
= devm_kzalloc(&pdev
->dev
,
6243 sizeof(sec_battery_platform_data_t
),
6246 dev_err(&pdev
->dev
, "Failed to allocate memory\n");
6251 battery
->pdata
= pdata
;
6252 if (sec_bat_parse_dt(&pdev
->dev
, battery
)) {
6254 "%s: Failed to get battery dt\n", __func__
);
6259 pdata
= dev_get_platdata(&pdev
->dev
);
6260 battery
->pdata
= pdata
;
6263 platform_set_drvdata(pdev
, battery
);
6265 battery
->dev
= &pdev
->dev
;
6267 mutex_init(&battery
->adclock
);
6268 mutex_init(&battery
->current_eventlock
);
6270 dev_dbg(battery
->dev
, "%s: ADC init\n", __func__
);
6273 adc_init(pdev
, battery
);
6275 for (i
= 0; i
< SEC_BAT_ADC_CHANNEL_NUM
; i
++)
6276 adc_init(pdev
, pdata
, i
);
6278 wake_lock_init(&battery
->monitor_wake_lock
, WAKE_LOCK_SUSPEND
,
6279 "sec-battery-monitor");
6280 wake_lock_init(&battery
->cable_wake_lock
, WAKE_LOCK_SUSPEND
,
6281 "sec-battery-cable");
6282 wake_lock_init(&battery
->vbus_wake_lock
, WAKE_LOCK_SUSPEND
,
6283 "sec-battery-vbus");
6284 wake_lock_init(&battery
->siop_wake_lock
, WAKE_LOCK_SUSPEND
,
6285 "sec-battery-siop");
6287 /* initialization of battery info */
6288 sec_bat_set_charging_status(battery
,
6289 POWER_SUPPLY_STATUS_DISCHARGING
);
6290 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
6291 battery
->present
= true;
6292 battery
->is_jig_on
= false;
6294 battery
->polling_count
= 1; /* initial value = 1 */
6295 battery
->polling_time
= pdata
->polling_time
[
6296 SEC_BATTERY_POLLING_TIME_DISCHARGING
];
6297 battery
->polling_in_sleep
= false;
6298 battery
->polling_short
= false;
6300 battery
->check_count
= 0;
6301 battery
->check_adc_count
= 0;
6302 battery
->check_adc_value
= 0;
6304 battery
->charging_start_time
= 0;
6305 battery
->charging_passed_time
= 0;
6306 battery
->charging_next_time
= 0;
6307 battery
->charging_fullcharged_time
= 0;
6308 battery
->siop_level
= 100;
6309 battery
->r_siop_level
= 100;
6310 battery
->wc_enable
= 1;
6311 battery
->pre_chg_temp
= 0;
6312 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
6313 battery
->stability_test
= 0;
6314 battery
->eng_not_full_status
= 0;
6316 battery
->wc_status
= 0;
6317 battery
->ps_status
= 0;
6318 battery
->ps_changed
= 0;
6319 battery
->wire_status
= POWER_SUPPLY_TYPE_BATTERY
;
6320 #if defined(CONFIG_BATTERY_SWELLING)
6321 battery
->swelling_mode
= false;
6323 battery
->charging_block
= false;
6324 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
6326 #if defined(ANDROID_ALARM_ACTIVATED)
6327 alarm_init(&battery
->event_termination_alarm
,
6328 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP
,
6329 sec_bat_event_expired_timer_func
);
6331 alarm_init(&battery
->event_termination_alarm
,
6333 sec_bat_event_expired_timer_func
);
6335 battery
->temp_highlimit_threshold
=
6336 pdata
->temp_highlimit_threshold_normal
;
6337 battery
->temp_highlimit_recovery
=
6338 pdata
->temp_highlimit_recovery_normal
;
6339 battery
->temp_high_threshold
=
6340 pdata
->temp_high_threshold_normal
;
6341 battery
->temp_high_recovery
=
6342 pdata
->temp_high_recovery_normal
;
6343 battery
->temp_low_recovery
=
6344 pdata
->temp_low_recovery_normal
;
6345 battery
->temp_low_threshold
=
6346 pdata
->temp_low_threshold_normal
;
6348 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
6349 battery
->is_recharging
= false;
6350 battery
->cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
6351 battery
->test_mode
= 0;
6352 battery
->factory_mode
= false;
6353 battery
->store_mode
= false;
6354 battery
->ignore_store_mode
= false;
6355 battery
->slate_mode
= false;
6356 slate_mode_state
= battery
->slate_mode
;
6357 battery
->is_hc_usb
= false;
6358 battery
->ignore_siop
= false;
6360 battery
->safety_timer_set
= true;
6361 battery
->stop_timer
= false;
6362 battery
->prev_safety_time
= 0;
6363 battery
->lcd_status
= false;
6364 battery
->current_event
= 0;
6366 battery
->batt_cycle
= -1;
6367 #if defined(CONFIG_BATTERY_AGE_FORECAST)
6368 battery
->pdata
->age_step
= 0;
6371 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6372 battery
->self_discharging
= false;
6373 battery
->force_discharging
= false;
6374 battery
->factory_self_discharging_mode_on
= false;
6377 if (battery
->pdata
->charger_name
== NULL
)
6378 battery
->pdata
->charger_name
= "sec-charger";
6379 if (battery
->pdata
->fuelgauge_name
== NULL
)
6380 battery
->pdata
->fuelgauge_name
= "sec-fuelgauge";
6382 #if defined(CONFIG_CHARGER_MAX77843) || defined(CONFIG_CHARGER_MAX77833)
6383 pr_info("%s : CHARGER CHIP NAME (%s)\n", __func__
, charger_chip_name
);
6384 if (charger_chip_name
!= NULL
&& !strcmp(charger_chip_name
,"max77843-charger")) {
6385 battery
->pdata
->charger_name
= "max77843-charger";
6386 battery
->pdata
->fuelgauge_name
= "max77843-fuelgauge";
6387 } else if (!strcmp(charger_chip_name
, "max77833-charger")) {
6388 battery
->pdata
->charger_name
= "max77833-charger";
6389 battery
->pdata
->fuelgauge_name
= "max77833-fuelgauge";
6393 battery
->psy_bat
.name
= "battery",
6394 battery
->psy_bat
.type
= POWER_SUPPLY_TYPE_BATTERY
,
6395 battery
->psy_bat
.properties
= sec_battery_props
,
6396 battery
->psy_bat
.num_properties
= ARRAY_SIZE(sec_battery_props
),
6397 battery
->psy_bat
.get_property
= sec_bat_get_property
,
6398 battery
->psy_bat
.set_property
= sec_bat_set_property
,
6399 battery
->psy_usb
.name
= "usb",
6400 battery
->psy_usb
.type
= POWER_SUPPLY_TYPE_USB
,
6401 battery
->psy_usb
.supplied_to
= supply_list
,
6402 battery
->psy_usb
.num_supplicants
= ARRAY_SIZE(supply_list
),
6403 battery
->psy_usb
.properties
= sec_power_props
,
6404 battery
->psy_usb
.num_properties
= ARRAY_SIZE(sec_power_props
),
6405 battery
->psy_usb
.get_property
= sec_usb_get_property
,
6406 battery
->psy_ac
.name
= "ac",
6407 battery
->psy_ac
.type
= POWER_SUPPLY_TYPE_MAINS
,
6408 battery
->psy_ac
.supplied_to
= supply_list
,
6409 battery
->psy_ac
.num_supplicants
= ARRAY_SIZE(supply_list
),
6410 battery
->psy_ac
.properties
= sec_power_props
,
6411 battery
->psy_ac
.num_properties
= ARRAY_SIZE(sec_power_props
),
6412 battery
->psy_ac
.get_property
= sec_ac_get_property
;
6413 battery
->psy_wireless
.name
= "wireless",
6414 battery
->psy_wireless
.type
= POWER_SUPPLY_TYPE_WIRELESS
,
6415 battery
->psy_wireless
.supplied_to
= supply_list
,
6416 battery
->psy_wireless
.num_supplicants
= ARRAY_SIZE(supply_list
),
6417 battery
->psy_wireless
.properties
= sec_power_props
,
6418 battery
->psy_wireless
.num_properties
= ARRAY_SIZE(sec_power_props
),
6419 battery
->psy_wireless
.get_property
= sec_wireless_get_property
;
6420 battery
->psy_wireless
.set_property
= sec_wireless_set_property
;
6421 battery
->psy_ps
.name
= "ps",
6422 battery
->psy_ps
.type
= POWER_SUPPLY_TYPE_POWER_SHARING
,
6423 battery
->psy_ps
.supplied_to
= supply_list
,
6424 battery
->psy_ps
.num_supplicants
= ARRAY_SIZE(supply_list
),
6425 battery
->psy_ps
.properties
= sec_ps_props
,
6426 battery
->psy_ps
.num_properties
= ARRAY_SIZE(sec_ps_props
),
6427 battery
->psy_ps
.get_property
= sec_ps_get_property
;
6428 battery
->psy_ps
.set_property
= sec_ps_set_property
;
6430 if (battery
->pdata
->wchg_ctl_en
) {
6431 ret
= gpio_request(battery
->pdata
->wchg_ctl
, "WCHG_CTL");
6433 pr_err("failed to request GPIO %u\n", battery
->pdata
->wchg_ctl
);
6436 gpio_direction_output(battery
->pdata
->wchg_ctl
, 0);
6437 pr_info("%s : GPIO %d\n", __func__
, gpio_get_value(battery
->pdata
->wchg_ctl
));
6440 #if defined (CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6441 if (battery
->pdata
->factory_discharging
) {
6442 ret
= gpio_request(battery
->pdata
->factory_discharging
, "FACTORY_DISCHARGING");
6444 pr_err("failed to request GPIO %u\n", battery
->pdata
->factory_discharging
);
6449 /* create work queue */
6450 battery
->monitor_wqueue
=
6451 alloc_workqueue(dev_name(&pdev
->dev
), WQ_MEM_RECLAIM
, 1);
6452 if (!battery
->monitor_wqueue
) {
6453 dev_err(battery
->dev
,
6454 "%s: Fail to Create Workqueue\n", __func__
);
6458 INIT_DELAYED_WORK(&battery
->monitor_work
, sec_bat_monitor_work
);
6459 INIT_DELAYED_WORK(&battery
->cable_work
, sec_bat_cable_work
);
6460 #if defined(CONFIG_CALC_TIME_TO_FULL)
6461 INIT_DELAYED_WORK(&battery
->timetofull_work
, sec_bat_time_to_full_work
);
6463 INIT_DELAYED_WORK(&battery
->siop_work
, sec_bat_siop_work
);
6465 switch (pdata
->polling_type
) {
6466 case SEC_BATTERY_MONITOR_WORKQUEUE
:
6467 INIT_DELAYED_WORK(&battery
->polling_work
,
6468 sec_bat_polling_work
);
6470 case SEC_BATTERY_MONITOR_ALARM
:
6471 #if defined(ANDROID_ALARM_ACTIVATED)
6472 battery
->last_poll_time
= alarm_get_elapsed_realtime();
6473 alarm_init(&battery
->polling_alarm
,
6474 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP
,
6477 battery
->last_poll_time
= ktime_get_boottime();
6478 alarm_init(&battery
->polling_alarm
, ALARM_BOOTTIME
,
6486 /* init power supplier framework */
6487 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_ps
);
6489 dev_err(battery
->dev
,
6490 "%s: Failed to Register psy_ps\n", __func__
);
6494 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_wireless
);
6496 dev_err(battery
->dev
,
6497 "%s: Failed to Register psy_wireless\n", __func__
);
6498 goto err_supply_unreg_ps
;
6501 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_usb
);
6503 dev_err(battery
->dev
,
6504 "%s: Failed to Register psy_usb\n", __func__
);
6505 goto err_supply_unreg_wireless
;
6508 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_ac
);
6510 dev_err(battery
->dev
,
6511 "%s: Failed to Register psy_ac\n", __func__
);
6512 goto err_supply_unreg_usb
;
6515 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_bat
);
6517 dev_err(battery
->dev
,
6518 "%s: Failed to Register psy_bat\n", __func__
);
6519 goto err_supply_unreg_ac
;
6522 if (battery
->pdata
->bat_gpio_init
&& !battery
->pdata
->bat_gpio_init()) {
6523 dev_err(battery
->dev
,
6524 "%s: Failed to Initialize GPIO\n", __func__
);
6525 goto err_supply_unreg_bat
;
6528 if (battery
->pdata
->bat_irq
) {
6529 ret
= request_threaded_irq(battery
->pdata
->bat_irq
,
6530 NULL
, sec_bat_irq_thread
,
6531 battery
->pdata
->bat_irq_attr
6533 "battery-irq", battery
);
6535 dev_err(battery
->dev
,
6536 "%s: Failed to Request IRQ (bat_int)\n", __func__
);
6537 goto err_supply_unreg_bat
;
6539 if (battery
->pdata
->bat_irq_gpio
) {
6540 ret
= enable_irq_wake(battery
->pdata
->bat_irq
);
6542 dev_err(battery
->dev
,
6543 "%s: Failed to Enable Wakeup Source(%d)(bat_int)\n",
6549 ret
= sec_bat_create_attrs(battery
->psy_bat
.dev
);
6551 dev_err(battery
->dev
,
6552 "%s : Failed to create_attrs\n", __func__
);
6556 #if defined(CONFIG_MUIC_NOTIFIER)
6557 muic_notifier_register(&battery
->batt_nb
,
6558 batt_handle_notification
,
6559 MUIC_NOTIFY_DEV_CHARGER
);
6561 #if defined(CONFIG_VBUS_NOTIFIER)
6562 vbus_notifier_register(&battery
->vbus_nb
,
6563 vbus_handle_notification
,
6564 VBUS_NOTIFY_DEV_CHARGER
);
6567 #if defined(CONFIG_AFC_CHARGER_MODE)
6569 psy_do_property(battery
->pdata
->charger_name
, set
,
6570 POWER_SUPPLY_PROP_AFC_CHARGER_MODE
,
6573 #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY)
6574 battery
->store_mode
= true;
6576 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
6577 POWER_SUPPLY_PROP_CAPACITY
, value
);
6578 if (value
.intval
<= 5) {
6579 battery
->ignore_store_mode
= true;
6581 value
.intval
= battery
->store_mode
;
6582 psy_do_property(battery
->pdata
->charger_name
, set
,
6583 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
, value
);
6586 if (pdata
->initial_check
)
6587 pdata
->initial_check();
6589 cable_initial_check(battery
);
6591 psy_do_property("battery", get
,
6592 POWER_SUPPLY_PROP_ONLINE
, value
);
6594 if ((value
.intval
== POWER_SUPPLY_TYPE_BATTERY
) ||
6595 (value
.intval
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
)) {
6596 dev_info(&pdev
->dev
,
6597 "%s: SEC Battery Driver Monitorwork\n", __func__
);
6598 wake_lock(&battery
->monitor_wake_lock
);
6599 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
6602 if (battery
->pdata
->check_battery_callback
)
6603 battery
->present
= battery
->pdata
->check_battery_callback();
6605 dev_info(battery
->dev
,
6606 "%s: SEC Battery Driver Loaded\n", __func__
);
6610 if (battery
->pdata
->bat_irq
)
6611 free_irq(battery
->pdata
->bat_irq
, battery
);
6612 err_supply_unreg_bat
:
6613 power_supply_unregister(&battery
->psy_bat
);
6614 err_supply_unreg_ac
:
6615 power_supply_unregister(&battery
->psy_ac
);
6616 err_supply_unreg_usb
:
6617 power_supply_unregister(&battery
->psy_usb
);
6618 err_supply_unreg_wireless
:
6619 power_supply_unregister(&battery
->psy_wireless
);
6620 err_supply_unreg_ps
:
6621 power_supply_unregister(&battery
->psy_ps
);
6623 destroy_workqueue(battery
->monitor_wqueue
);
6625 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6626 if (battery
->pdata
->factory_discharging
)
6627 gpio_free(battery
->pdata
->factory_discharging
);
6630 gpio_free(battery
->pdata
->wchg_ctl
);
6632 wake_lock_destroy(&battery
->monitor_wake_lock
);
6633 wake_lock_destroy(&battery
->cable_wake_lock
);
6634 wake_lock_destroy(&battery
->vbus_wake_lock
);
6635 wake_lock_destroy(&battery
->siop_wake_lock
);
6636 mutex_destroy(&battery
->adclock
);
6637 mutex_destroy(&battery
->current_eventlock
);
6645 static int __devexit
sec_battery_remove(struct platform_device
*pdev
)
6647 struct sec_battery_info
*battery
= platform_get_drvdata(pdev
);
6652 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
6654 switch (battery
->pdata
->polling_type
) {
6655 case SEC_BATTERY_MONITOR_WORKQUEUE
:
6656 cancel_delayed_work(&battery
->polling_work
);
6658 case SEC_BATTERY_MONITOR_ALARM
:
6659 alarm_cancel(&battery
->polling_alarm
);
6665 alarm_cancel(&battery
->event_termination_alarm
);
6666 flush_workqueue(battery
->monitor_wqueue
);
6667 destroy_workqueue(battery
->monitor_wqueue
);
6668 wake_lock_destroy(&battery
->monitor_wake_lock
);
6669 wake_lock_destroy(&battery
->cable_wake_lock
);
6670 wake_lock_destroy(&battery
->vbus_wake_lock
);
6671 wake_lock_destroy(&battery
->siop_wake_lock
);
6673 mutex_destroy(&battery
->adclock
);
6674 mutex_destroy(&battery
->current_eventlock
);
6678 for (i
= 0; i
< SEC_BAT_ADC_CHANNEL_NUM
; i
++)
6679 adc_exit(battery
->pdata
, i
);
6681 power_supply_unregister(&battery
->psy_ps
);
6682 power_supply_unregister(&battery
->psy_wireless
);
6683 power_supply_unregister(&battery
->psy_ac
);
6684 power_supply_unregister(&battery
->psy_usb
);
6685 power_supply_unregister(&battery
->psy_bat
);
6687 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
6693 static int sec_battery_prepare(struct device
*dev
)
6695 struct sec_battery_info
*battery
6696 = dev_get_drvdata(dev
);
6698 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
6700 switch (battery
->pdata
->polling_type
) {
6701 case SEC_BATTERY_MONITOR_WORKQUEUE
:
6702 cancel_delayed_work(&battery
->polling_work
);
6704 case SEC_BATTERY_MONITOR_ALARM
:
6705 alarm_cancel(&battery
->polling_alarm
);
6710 cancel_delayed_work_sync(&battery
->monitor_work
);
6712 battery
->polling_in_sleep
= true;
6714 sec_bat_set_polling(battery
);
6716 /* cancel work for polling
6717 * that is set in sec_bat_set_polling()
6718 * no need for polling in sleep
6720 if (battery
->pdata
->polling_type
==
6721 SEC_BATTERY_MONITOR_WORKQUEUE
)
6722 cancel_delayed_work(&battery
->polling_work
);
6724 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
6729 static int sec_battery_suspend(struct device
*dev
)
6734 static int sec_battery_resume(struct device
*dev
)
6739 static void sec_battery_complete(struct device
*dev
)
6741 struct sec_battery_info
*battery
6742 = dev_get_drvdata(dev
);
6744 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
6746 /* cancel current alarm and reset after monitor work */
6747 if (battery
->pdata
->polling_type
== SEC_BATTERY_MONITOR_ALARM
)
6748 alarm_cancel(&battery
->polling_alarm
);
6750 wake_lock(&battery
->monitor_wake_lock
);
6751 queue_delayed_work_on(0, battery
->monitor_wqueue
,
6752 &battery
->monitor_work
, 0);
6754 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
6759 static void sec_battery_shutdown(struct device
*dev
)
6761 struct sec_battery_info
*battery
6762 = dev_get_drvdata(dev
);
6763 union power_supply_propval val
;
6765 if (battery
->pdata
->always_enable
) {
6767 psy_do_property(battery
->pdata
->charger_name
, set
,
6768 POWER_SUPPLY_PROP_CHARGING_ENABLED
, val
);
6771 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6772 if (battery
->force_discharging
) {
6773 pr_info("SELF DISCHARGING IC DISENABLE\n");
6774 sec_bat_self_discharging_control(battery
, false);
6780 static struct of_device_id sec_battery_dt_ids
[] = {
6781 { .compatible
= "samsung,sec-battery" },
6784 MODULE_DEVICE_TABLE(of
, sec_battery_dt_ids
);
6785 #endif /* CONFIG_OF */
6787 static const struct dev_pm_ops sec_battery_pm_ops
= {
6788 .prepare
= sec_battery_prepare
,
6789 .suspend
= sec_battery_suspend
,
6790 .resume
= sec_battery_resume
,
6791 .complete
= sec_battery_complete
,
6794 static struct platform_driver sec_battery_driver
= {
6796 .name
= "sec-battery",
6797 .owner
= THIS_MODULE
,
6798 .pm
= &sec_battery_pm_ops
,
6799 .shutdown
= sec_battery_shutdown
,
6801 .of_match_table
= sec_battery_dt_ids
,
6804 .probe
= sec_battery_probe
,
6805 .remove
= __devexit_p(sec_battery_remove
),
6808 static int __init
sec_battery_init(void)
6810 return platform_driver_register(&sec_battery_driver
);
6813 static void __exit
sec_battery_exit(void)
6815 platform_driver_unregister(&sec_battery_driver
);
6818 late_initcall(sec_battery_init
);
6819 module_exit(sec_battery_exit
);
6821 MODULE_DESCRIPTION("Samsung Battery Driver");
6822 MODULE_AUTHOR("Samsung Electronics");
6823 MODULE_LICENSE("GPL");