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
,
129 POWER_SUPPLY_PROP_VOLTAGE_MAX
,
130 POWER_SUPPLY_PROP_CURRENT_MAX
,
133 static enum power_supply_property sec_ps_props
[] = {
134 POWER_SUPPLY_PROP_STATUS
,
135 POWER_SUPPLY_PROP_ONLINE
,
138 static char *supply_list
[] = {
142 char *sec_bat_charging_mode_str
[] = {
150 char *sec_bat_status_str
[] = {
158 char *sec_bat_health_str
[] = {
168 "WatchdogTimerExpire",
174 static void sec_bat_set_current_event(struct sec_battery_info
*battery
,
175 unsigned int current_event_val
, unsigned int current_event_mask
)
177 unsigned int temp
= battery
->current_event
;
179 mutex_lock(&battery
->current_eventlock
);
181 battery
->current_event
&= ~current_event_mask
;
182 battery
->current_event
|= current_event_val
;
184 pr_info("%s: current event before(0x%x), after(0x%x)\n",
185 __func__
, temp
, battery
->current_event
);
187 mutex_unlock(&battery
->current_eventlock
);
190 static int sec_bat_set_charge(
191 struct sec_battery_info
*battery
,
194 union power_supply_propval val
;
195 ktime_t current_time
;
198 if (battery
->cable_type
== POWER_SUPPLY_TYPE_OTG
)
200 val
.intval
= battery
->status
;
201 psy_do_property(battery
->pdata
->charger_name
, set
,
202 POWER_SUPPLY_PROP_STATUS
, val
);
203 #if defined(ANDROID_ALARM_ACTIVATED)
204 current_time
= alarm_get_elapsed_realtime();
205 ts
= ktime_to_timespec(current_time
);
207 current_time
= ktime_get_boottime();
208 ts
= ktime_to_timespec(current_time
);
212 val
.intval
= battery
->cable_type
;
213 /*Reset charging start time only in initial charging start */
214 if (battery
->charging_start_time
== 0) {
217 battery
->charging_start_time
= ts
.tv_sec
;
218 battery
->charging_next_time
=
219 battery
->pdata
->charging_reset_time
;
222 if (battery
->siop_level
< 100)
223 battery
->lcd_on_time
= ts
.tv_sec
;
225 val
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
226 battery
->charging_start_time
= 0;
227 battery
->charging_passed_time
= 0;
228 battery
->charging_next_time
= 0;
229 battery
->charging_fullcharged_time
= 0;
230 battery
->full_check_cnt
= 0;
231 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
232 battery
->cc_cv_mode
= 0;
234 battery
->lcd_on_total_time
= 0;
235 battery
->lcd_on_time
= 0;
238 battery
->charging_block
= !enable
;
240 battery
->temp_highlimit_cnt
= 0;
241 battery
->temp_high_cnt
= 0;
242 battery
->temp_low_cnt
= 0;
243 battery
->temp_recover_cnt
= 0;
245 val
.intval
= battery
->pdata
->always_enable
? battery
->cable_type
:
246 enable
? battery
->cable_type
: POWER_SUPPLY_TYPE_BATTERY
;
248 psy_do_property(battery
->pdata
->charger_name
, set
,
249 POWER_SUPPLY_PROP_ONLINE
, val
);
251 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
252 POWER_SUPPLY_PROP_ONLINE
, val
);
254 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
255 if (battery
->wc_status
) {
256 psy_do_property(battery
->pdata
->charger_name
, get
,
257 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, val
);
258 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
259 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, val
);
262 val
.intval
= POWER_SUPPLY_TYPE_WIRELESS
;
264 val
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
266 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
267 POWER_SUPPLY_PROP_ONLINE
, val
);
271 if (battery
->pdata
->always_enable
) {
272 if (battery
->slate_mode
)
274 else if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
)
278 psy_do_property(battery
->pdata
->charger_name
, set
,
279 POWER_SUPPLY_PROP_CHARGING_ENABLED
, val
);
285 static int sec_bat_get_adc_data(struct sec_battery_info
*battery
,
286 int adc_ch
, int count
)
299 for (i
= 0; i
< count
; i
++) {
300 mutex_lock(&battery
->adclock
);
302 adc_data
= adc_read(battery
, adc_ch
);
304 adc_data
= adc_read(battery
->pdata
, adc_ch
);
306 mutex_unlock(&battery
->adclock
);
312 if (adc_data
> adc_max
)
314 else if (adc_data
< adc_min
)
320 adc_total
+= adc_data
;
323 return (adc_total
- adc_max
- adc_min
) / (count
- 2);
329 static unsigned long calculate_average_adc(
330 struct sec_battery_info *battery,
331 int channel, int adc)
333 unsigned int cnt = 0;
338 cnt = battery->adc_sample[channel].cnt;
339 total_adc = battery->adc_sample[channel].total_adc;
342 dev_err(battery->dev,
343 "%s : Invalid ADC : %d\n", __func__, adc);
344 adc = battery->adc_sample[channel].average_adc;
347 if (cnt < ADC_SAMPLE_COUNT) {
348 battery->adc_sample[channel].adc_arr[cnt] = adc;
349 battery->adc_sample[channel].index = cnt;
350 battery->adc_sample[channel].cnt = ++cnt;
353 average_adc = total_adc / cnt;
355 index = battery->adc_sample[channel].index;
356 if (++index >= ADC_SAMPLE_COUNT)
359 total_adc = total_adc -
360 battery->adc_sample[channel].adc_arr[index] + adc;
361 average_adc = total_adc / ADC_SAMPLE_COUNT;
363 battery->adc_sample[channel].adc_arr[index] = adc;
364 battery->adc_sample[channel].index = index;
367 battery->adc_sample[channel].total_adc = total_adc;
368 battery->adc_sample[channel].average_adc = average_adc;
374 static int sec_bat_get_adc_value(
375 struct sec_battery_info
*battery
, int channel
)
379 adc
= sec_bat_get_adc_data(battery
, channel
,
380 battery
->pdata
->adc_check_count
);
383 dev_err(battery
->dev
,
384 "%s: Error in ADC\n", __func__
);
391 static int sec_bat_get_charger_type_adc
392 (struct sec_battery_info
*battery
)
394 /* It is true something valid is
395 connected to the device for charging.
396 By default this something is considered to be USB.*/
397 int result
= POWER_SUPPLY_TYPE_USB
;
402 /* Do NOT check cable type when cable_switch_check() returns false
403 * and keep current cable type
405 if (battery
->pdata
->cable_switch_check
&&
406 !battery
->pdata
->cable_switch_check())
407 return battery
->cable_type
;
409 adc
= sec_bat_get_adc_value(battery
,
410 SEC_BAT_ADC_CHANNEL_CABLE_CHECK
);
412 /* Do NOT check cable type when cable_switch_normal() returns false
413 * and keep current cable type
415 if (battery
->pdata
->cable_switch_normal
&&
416 !battery
->pdata
->cable_switch_normal())
417 return battery
->cable_type
;
419 for (i
= 0; i
< SEC_SIZEOF_POWER_SUPPLY_TYPE
; i
++)
420 if ((adc
> battery
->pdata
->cable_adc_value
[i
].min
) &&
421 (adc
< battery
->pdata
->cable_adc_value
[i
].max
))
423 if (i
>= SEC_SIZEOF_POWER_SUPPLY_TYPE
)
424 dev_err(battery
->dev
,
425 "%s : default USB\n", __func__
);
429 dev_dbg(battery
->dev
, "%s : result(%d), adc(%d)\n",
430 __func__
, result
, adc
);
435 static bool sec_bat_check_vf_adc(struct sec_battery_info
*battery
)
439 adc
= sec_bat_get_adc_data(battery
,
440 SEC_BAT_ADC_CHANNEL_BAT_CHECK
,
441 battery
->pdata
->adc_check_count
);
444 dev_err(battery
->dev
, "%s: VF ADC error\n", __func__
);
445 adc
= battery
->check_adc_value
;
447 battery
->check_adc_value
= adc
;
449 if ((battery
->check_adc_value
<= battery
->pdata
->check_adc_max
) &&
450 (battery
->check_adc_value
>= battery
->pdata
->check_adc_min
)) {
453 dev_info(battery
->dev
, "%s: adc (%d)\n", __func__
, battery
->check_adc_value
);
458 static bool sec_bat_check_by_psy(struct sec_battery_info
*battery
)
461 union power_supply_propval value
;
465 switch (battery
->pdata
->battery_check_type
) {
466 case SEC_BATTERY_CHECK_PMIC
:
467 psy_name
= battery
->pdata
->pmic_name
;
469 case SEC_BATTERY_CHECK_FUELGAUGE
:
470 psy_name
= battery
->pdata
->fuelgauge_name
;
472 case SEC_BATTERY_CHECK_CHARGER
:
473 psy_name
= battery
->pdata
->charger_name
;
476 dev_err(battery
->dev
,
477 "%s: Invalid Battery Check Type\n", __func__
);
479 goto battery_check_error
;
483 psy_do_property(psy_name
, get
,
484 POWER_SUPPLY_PROP_PRESENT
, value
);
485 ret
= (bool)value
.intval
;
491 static bool sec_bat_check(struct sec_battery_info
*battery
)
496 if (battery
->factory_mode
|| battery
->is_jig_on
) {
497 dev_dbg(battery
->dev
, "%s: No need to check in factory mode\n",
502 if (battery
->health
!= POWER_SUPPLY_HEALTH_GOOD
&&
503 battery
->health
!= POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
) {
504 dev_dbg(battery
->dev
, "%s: No need to check\n", __func__
);
508 switch (battery
->pdata
->battery_check_type
) {
509 case SEC_BATTERY_CHECK_ADC
:
510 if(battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
)
511 ret
= battery
->present
;
513 ret
= sec_bat_check_vf_adc(battery
);
515 case SEC_BATTERY_CHECK_INT
:
516 case SEC_BATTERY_CHECK_CALLBACK
:
517 if(battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
518 ret
= battery
->present
;
520 if (battery
->pdata
->check_battery_callback
)
521 ret
= battery
->pdata
->check_battery_callback();
524 case SEC_BATTERY_CHECK_PMIC
:
525 case SEC_BATTERY_CHECK_FUELGAUGE
:
526 case SEC_BATTERY_CHECK_CHARGER
:
527 ret
= sec_bat_check_by_psy(battery
);
529 case SEC_BATTERY_CHECK_NONE
:
530 dev_dbg(battery
->dev
, "%s: No Check\n", __func__
);
538 static bool sec_bat_get_cable_type(
539 struct sec_battery_info
*battery
,
540 int cable_source_type
)
546 cable_type
= battery
->cable_type
;
548 if (cable_source_type
& SEC_BATTERY_CABLE_SOURCE_CALLBACK
) {
549 if (battery
->pdata
->check_cable_callback
)
551 battery
->pdata
->check_cable_callback();
554 if (cable_source_type
& SEC_BATTERY_CABLE_SOURCE_ADC
) {
555 if (gpio_get_value_cansleep(
556 battery
->pdata
->bat_gpio_ta_nconnected
) ^
557 battery
->pdata
->bat_polarity_ta_nconnected
)
558 cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
561 sec_bat_get_charger_type_adc(battery
);
564 if (battery
->cable_type
== cable_type
) {
565 dev_dbg(battery
->dev
,
566 "%s: No need to change cable status\n", __func__
);
568 if (cable_type
< POWER_SUPPLY_TYPE_BATTERY
||
569 cable_type
>= SEC_SIZEOF_POWER_SUPPLY_TYPE
) {
570 dev_err(battery
->dev
,
571 "%s: Invalid cable type\n", __func__
);
573 battery
->cable_type
= cable_type
;
574 if (battery
->pdata
->check_cable_result_callback
)
575 battery
->pdata
->check_cable_result_callback(
576 battery
->cable_type
);
580 dev_dbg(battery
->dev
, "%s: Cable Changed (%d)\n",
581 __func__
, battery
->cable_type
);
588 static void sec_bat_set_charging_status(struct sec_battery_info
*battery
,
590 union power_supply_propval value
;
592 case POWER_SUPPLY_STATUS_NOT_CHARGING
:
593 case POWER_SUPPLY_STATUS_DISCHARGING
:
594 if((battery
->status
== POWER_SUPPLY_STATUS_FULL
) ||
595 (battery
->capacity
== 100)){
596 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
597 value
.intval
= battery
->capacity
;
599 value
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
601 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
602 POWER_SUPPLY_PROP_CHARGE_FULL
, value
);
604 /* To get SOC value (NOT raw SOC), need to reset value */
606 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
607 POWER_SUPPLY_PROP_CAPACITY
, value
);
608 battery
->capacity
= value
.intval
;
610 battery
->expired_time
= battery
->pdata
->expired_time
;
611 battery
->prev_safety_time
= 0;
616 battery
->status
= status
;
619 static bool sec_bat_battery_cable_check(struct sec_battery_info
*battery
)
621 if (!sec_bat_check(battery
)) {
622 if (battery
->check_count
< battery
->pdata
->check_count
)
623 battery
->check_count
++;
625 dev_err(battery
->dev
,
626 "%s: Battery Disconnected\n", __func__
);
628 if (battery
->pdata
->always_enable
) {
629 union power_supply_propval val
;
632 psy_do_property(battery
->pdata
->charger_name
, set
,
633 POWER_SUPPLY_PROP_CHARGING_ENABLED
, val
);
636 battery
->present
= false;
637 battery
->health
= POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
;
639 if (battery
->status
!=
640 POWER_SUPPLY_STATUS_DISCHARGING
) {
641 sec_bat_set_charging_status(battery
,
642 POWER_SUPPLY_STATUS_NOT_CHARGING
);
643 if(battery
->siop_level
!= 100)
644 battery
->stop_timer
= true ;
645 sec_bat_set_charge(battery
, false);
648 if (battery
->pdata
->check_battery_result_callback
)
650 check_battery_result_callback();
654 battery
->check_count
= 0;
656 battery
->present
= true;
658 if (battery
->health
== POWER_SUPPLY_HEALTH_UNSPEC_FAILURE
) {
659 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
661 if (battery
->status
== POWER_SUPPLY_STATUS_NOT_CHARGING
) {
662 sec_bat_set_charging_status(battery
,
663 POWER_SUPPLY_STATUS_CHARGING
);
664 #if defined(CONFIG_BATTERY_SWELLING)
665 if (!battery
->swelling_mode
)
666 sec_bat_set_charge(battery
, true);
668 sec_bat_set_charge(battery
, true);
673 dev_dbg(battery
->dev
, "%s: Battery Connected\n", __func__
);
675 if (battery
->pdata
->cable_check_type
&
676 SEC_BATTERY_CABLE_CHECK_POLLING
) {
677 if (sec_bat_get_cable_type(battery
,
678 battery
->pdata
->cable_source_type
)) {
679 wake_lock(&battery
->cable_wake_lock
);
680 queue_delayed_work_on(0, battery
->monitor_wqueue
,
681 &battery
->cable_work
, 0);
687 static int sec_bat_ovp_uvlo_by_psy(struct sec_battery_info
*battery
)
690 union power_supply_propval value
;
692 value
.intval
= POWER_SUPPLY_HEALTH_GOOD
;
694 switch (battery
->pdata
->ovp_uvlo_check_type
) {
695 case SEC_BATTERY_OVP_UVLO_PMICPOLLING
:
696 psy_name
= battery
->pdata
->pmic_name
;
698 case SEC_BATTERY_OVP_UVLO_CHGPOLLING
:
699 psy_name
= battery
->pdata
->charger_name
;
702 dev_err(battery
->dev
,
703 "%s: Invalid OVP/UVLO Check Type\n", __func__
);
704 goto ovp_uvlo_check_error
;
708 psy_do_property(psy_name
, get
,
709 POWER_SUPPLY_PROP_HEALTH
, value
);
711 ovp_uvlo_check_error
:
715 static bool sec_bat_ovp_uvlo_result(
716 struct sec_battery_info
*battery
, int health
)
718 if (battery
->health
!= health
) {
719 battery
->health
= health
;
721 case POWER_SUPPLY_HEALTH_GOOD
:
722 dev_info(battery
->dev
, "%s: Safe voltage\n", __func__
);
723 dev_info(battery
->dev
, "%s: is_recharging : %d\n", __func__
, battery
->is_recharging
);
724 sec_bat_set_charging_status(battery
,
725 POWER_SUPPLY_STATUS_CHARGING
);
726 if (battery
->siop_level
!= 100)
727 battery
->stop_timer
= true;
728 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
729 #if defined(CONFIG_BATTERY_SWELLING)
730 if (!battery
->swelling_mode
)
731 sec_bat_set_charge(battery
, true);
733 sec_bat_set_charge(battery
, true);
736 case POWER_SUPPLY_HEALTH_OVERVOLTAGE
:
737 case POWER_SUPPLY_HEALTH_UNDERVOLTAGE
:
738 dev_info(battery
->dev
,
739 "%s: Unsafe voltage (%d)\n",
741 sec_bat_set_charging_status(battery
,
742 POWER_SUPPLY_STATUS_NOT_CHARGING
);
743 sec_bat_set_charge(battery
, false);
744 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
745 battery
->is_recharging
= false;
746 /* Take the wakelock during 10 seconds
747 when over-voltage status is detected */
748 wake_lock_timeout(&battery
->vbus_wake_lock
, HZ
* 10);
750 case POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE
:
751 dev_info(battery
->dev
,
752 "%s: Watchdog Expired, Restart charger (%d)\n",
754 sec_bat_set_charge(battery
, true);
755 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
758 power_supply_changed(&battery
->psy_bat
);
765 static bool sec_bat_ovp_uvlo(struct sec_battery_info
*battery
)
769 if (battery
->factory_mode
|| battery
->is_jig_on
) {
770 dev_info(battery
->dev
,
771 "%s: No need to check in factory mode\n",
774 } else if ((battery
->status
== POWER_SUPPLY_STATUS_FULL
) &&
775 (battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
)) {
776 dev_dbg(battery
->dev
, "%s: No need to check in Full status", __func__
);
780 if (battery
->health
!= POWER_SUPPLY_HEALTH_GOOD
&&
781 battery
->health
!= POWER_SUPPLY_HEALTH_OVERVOLTAGE
&&
782 battery
->health
!= POWER_SUPPLY_HEALTH_UNDERVOLTAGE
&&
783 battery
->health
!= POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE
) {
784 dev_dbg(battery
->dev
, "%s: No need to check\n", __func__
);
788 health
= battery
->health
;
790 switch (battery
->pdata
->ovp_uvlo_check_type
) {
791 case SEC_BATTERY_OVP_UVLO_CALLBACK
:
792 if (battery
->pdata
->ovp_uvlo_callback
)
793 health
= battery
->pdata
->ovp_uvlo_callback();
795 case SEC_BATTERY_OVP_UVLO_PMICPOLLING
:
796 case SEC_BATTERY_OVP_UVLO_CHGPOLLING
:
797 health
= sec_bat_ovp_uvlo_by_psy(battery
);
799 case SEC_BATTERY_OVP_UVLO_PMICINT
:
800 case SEC_BATTERY_OVP_UVLO_CHGINT
:
801 /* nothing for interrupt check */
806 return sec_bat_ovp_uvlo_result(battery
, health
);
809 static bool sec_bat_check_recharge(struct sec_battery_info
*battery
)
811 int recharging_voltage
;
812 #if defined(CONFIG_BATTERY_SWELLING)
813 if (battery
->swelling_mode
) {
814 pr_info("%s: Skip normal recharge check routine for swelling mode\n",
819 if ((battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) &&
820 (battery
->pdata
->full_condition_type
&
821 SEC_BATTERY_FULL_CONDITION_NOTIMEFULL
) &&
822 (battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
)) {
823 dev_info(battery
->dev
,
824 "%s: Re-charging by NOTIMEFULL (%d)\n",
825 __func__
, battery
->capacity
);
826 goto check_recharge_check_count
;
829 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
&&
830 battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
) {
831 recharging_voltage
= battery
->pdata
->recharge_condition_vcell
;
832 if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
) {
833 recharging_voltage
= battery
->pdata
->chg_float_voltage
- 150; // float voltage - 150mV
834 dev_info(battery
->dev
, "%s: recharge voltage changed by low temp(%d)\n",
835 __func__
, recharging_voltage
);
837 if ((battery
->pdata
->recharge_condition_type
&
838 SEC_BATTERY_RECHARGE_CONDITION_SOC
) &&
839 (battery
->capacity
<=
840 battery
->pdata
->recharge_condition_soc
)) {
841 battery
->expired_time
= battery
->pdata
->recharging_expired_time
;
842 battery
->prev_safety_time
= 0;
843 dev_info(battery
->dev
,
844 "%s: Re-charging by SOC (%d)\n",
845 __func__
, battery
->capacity
);
846 goto check_recharge_check_count
;
849 if ((battery
->pdata
->recharge_condition_type
&
850 SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL
) &&
851 (battery
->voltage_avg
<=
852 recharging_voltage
)) {
853 battery
->expired_time
= battery
->pdata
->recharging_expired_time
;
854 battery
->prev_safety_time
= 0;
855 dev_info(battery
->dev
,
856 "%s: Re-charging by average VCELL (%d)\n",
857 __func__
, battery
->voltage_avg
);
858 goto check_recharge_check_count
;
861 if ((battery
->pdata
->recharge_condition_type
&
862 SEC_BATTERY_RECHARGE_CONDITION_VCELL
) &&
863 (battery
->voltage_now
<=
864 recharging_voltage
)) {
865 battery
->expired_time
= battery
->pdata
->recharging_expired_time
;
866 battery
->prev_safety_time
= 0;
867 dev_info(battery
->dev
,
868 "%s: Re-charging by VCELL (%d)\n",
869 __func__
, battery
->voltage_now
);
870 goto check_recharge_check_count
;
874 battery
->recharge_check_cnt
= 0;
877 check_recharge_check_count
:
878 if (battery
->recharge_check_cnt
<
879 battery
->pdata
->recharge_check_count
)
880 battery
->recharge_check_cnt
++;
881 dev_dbg(battery
->dev
,
882 "%s: recharge count = %d\n",
883 __func__
, battery
->recharge_check_cnt
);
885 if (battery
->recharge_check_cnt
>=
886 battery
->pdata
->recharge_check_count
)
892 static bool sec_bat_voltage_check(struct sec_battery_info
*battery
)
894 union power_supply_propval value
;
896 if (battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
897 dev_dbg(battery
->dev
,
898 "%s: Charging Disabled\n", __func__
);
903 if (sec_bat_ovp_uvlo(battery
)) {
904 if (battery
->pdata
->ovp_uvlo_result_callback
)
906 ovp_uvlo_result_callback(battery
->health
);
910 if ((battery
->status
== POWER_SUPPLY_STATUS_FULL
) &&
911 #if defined(CONFIG_BATTERY_SWELLING)
912 (battery
->charging_mode
== SEC_BATTERY_CHARGING_2ND
||
913 battery
->is_recharging
|| battery
->swelling_mode
)) {
915 (battery
->charging_mode
== SEC_BATTERY_CHARGING_2ND
||
916 battery
->is_recharging
)) {
919 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
920 POWER_SUPPLY_PROP_CAPACITY
, value
);
922 battery
->pdata
->full_condition_soc
&&
923 battery
->voltage_now
<
924 (battery
->pdata
->recharge_condition_vcell
- 50)) {
925 sec_bat_set_charging_status(battery
,
926 POWER_SUPPLY_STATUS_CHARGING
);
927 if (battery
->siop_level
!= 100)
928 battery
->stop_timer
= true;
929 battery
->voltage_now
= 1080;
930 battery
->voltage_avg
= 1080;
931 power_supply_changed(&battery
->psy_bat
);
932 dev_info(battery
->dev
,
933 "%s: battery status full -> charging, RepSOC(%d)\n", __func__
, value
.intval
);
937 /* Re-Charging check */
938 if (sec_bat_check_recharge(battery
)) {
939 if (battery
->pdata
->full_check_type
!=
940 SEC_BATTERY_FULLCHARGED_NONE
)
941 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
943 battery
->charging_mode
= SEC_BATTERY_CHARGING_2ND
;
944 battery
->is_recharging
= true;
945 #if defined(CONFIG_BATTERY_SWELLING)
946 if (!battery
->swelling_mode
)
947 sec_bat_set_charge(battery
, true);
949 sec_bat_set_charge(battery
, true);
957 static bool sec_bat_get_temperature_by_adc(
958 struct sec_battery_info
*battery
,
959 enum sec_battery_adc_channel channel
,
960 union power_supply_propval
*value
)
967 const sec_bat_adc_table_data_t
*temp_adc_table
;
968 unsigned int temp_adc_table_size
;
970 temp_adc
= sec_bat_get_adc_value(battery
, channel
);
975 case SEC_BAT_ADC_CHANNEL_TEMP
:
976 temp_adc_table
= battery
->pdata
->temp_adc_table
;
977 temp_adc_table_size
=
978 battery
->pdata
->temp_adc_table_size
;
979 battery
->temp_adc
= temp_adc
;
981 case SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT
:
982 temp_adc_table
= battery
->pdata
->temp_amb_adc_table
;
983 temp_adc_table_size
=
984 battery
->pdata
->temp_amb_adc_table_size
;
985 battery
->temp_ambient_adc
= temp_adc
;
987 case SEC_BAT_ADC_CHANNEL_CHG_TEMP
:
988 temp_adc_table
= battery
->pdata
->chg_temp_adc_table
;
989 temp_adc_table_size
=
990 battery
->pdata
->chg_temp_adc_table_size
;
991 battery
->chg_temp_adc
= temp_adc
;
994 dev_err(battery
->dev
,
995 "%s: Invalid Property\n", __func__
);
999 if (temp_adc_table
[0].adc
>= temp_adc
) {
1000 temp
= temp_adc_table
[0].data
;
1001 goto temp_by_adc_goto
;
1002 } else if (temp_adc_table
[temp_adc_table_size
-1].adc
<= temp_adc
) {
1003 temp
= temp_adc_table
[temp_adc_table_size
-1].data
;
1004 goto temp_by_adc_goto
;
1007 high
= temp_adc_table_size
- 1;
1009 while (low
<= high
) {
1010 mid
= (low
+ high
) / 2;
1011 if (temp_adc_table
[mid
].adc
> temp_adc
)
1013 else if (temp_adc_table
[mid
].adc
< temp_adc
)
1016 temp
= temp_adc_table
[mid
].data
;
1017 goto temp_by_adc_goto
;
1021 temp
= temp_adc_table
[high
].data
;
1022 temp
+= ((temp_adc_table
[low
].data
- temp_adc_table
[high
].data
) *
1023 (temp_adc
- temp_adc_table
[high
].adc
)) /
1024 (temp_adc_table
[low
].adc
- temp_adc_table
[high
].adc
);
1027 value
->intval
= temp
;
1029 dev_dbg(battery
->dev
,
1030 "%s: Temp(%d), Temp-ADC(%d)\n",
1031 __func__
, temp
, temp_adc
);
1036 static bool sec_bat_temperature(
1037 struct sec_battery_info
*battery
)
1042 if (battery
->pdata
->event_check
&& battery
->event
) {
1043 battery
->temp_highlimit_threshold
=
1044 battery
->pdata
->temp_highlimit_threshold_event
;
1045 battery
->temp_highlimit_recovery
=
1046 battery
->pdata
->temp_highlimit_recovery_event
;
1047 battery
->temp_high_threshold
=
1048 battery
->pdata
->temp_high_threshold_event
;
1049 battery
->temp_high_recovery
=
1050 battery
->pdata
->temp_high_recovery_event
;
1051 battery
->temp_low_recovery
=
1052 battery
->pdata
->temp_low_recovery_event
;
1053 battery
->temp_low_threshold
=
1054 battery
->pdata
->temp_low_threshold_event
;
1055 } else if (lpcharge
) {
1056 battery
->temp_highlimit_threshold
=
1057 battery
->pdata
->temp_highlimit_threshold_lpm
;
1058 battery
->temp_highlimit_recovery
=
1059 battery
->pdata
->temp_highlimit_recovery_lpm
;
1060 battery
->temp_high_threshold
=
1061 battery
->pdata
->temp_high_threshold_lpm
;
1062 battery
->temp_high_recovery
=
1063 battery
->pdata
->temp_high_recovery_lpm
;
1064 battery
->temp_low_recovery
=
1065 battery
->pdata
->temp_low_recovery_lpm
;
1066 battery
->temp_low_threshold
=
1067 battery
->pdata
->temp_low_threshold_lpm
;
1069 battery
->temp_highlimit_threshold
=
1070 battery
->pdata
->temp_highlimit_threshold_normal
;
1071 battery
->temp_highlimit_recovery
=
1072 battery
->pdata
->temp_highlimit_recovery_normal
;
1073 battery
->temp_high_threshold
=
1074 battery
->pdata
->temp_high_threshold_normal
;
1075 battery
->temp_high_recovery
=
1076 battery
->pdata
->temp_high_recovery_normal
;
1077 battery
->temp_low_recovery
=
1078 battery
->pdata
->temp_low_recovery_normal
;
1079 battery
->temp_low_threshold
=
1080 battery
->pdata
->temp_low_threshold_normal
;
1083 dev_info(battery
->dev
,
1084 "%s: HLT(%d) HLR(%d) HT(%d), HR(%d), LT(%d), LR(%d)\n",
1085 __func__
, battery
->temp_highlimit_threshold
,
1086 battery
->temp_highlimit_recovery
,
1087 battery
->temp_high_threshold
,
1088 battery
->temp_high_recovery
,
1089 battery
->temp_low_threshold
,
1090 battery
->temp_low_recovery
);
1094 #if defined(CONFIG_BATTERY_SWELLING)
1095 static void sec_bat_swelling_check(struct sec_battery_info
*battery
, int temperature
)
1097 union power_supply_propval val
;
1098 bool en_swelling
= false, en_rechg
= false;
1099 int swelling_rechg_voltage
;
1101 psy_do_property(battery
->pdata
->charger_name
, get
,
1102 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1104 pr_info("%s: status(%d), swell_mode(%d:%d), cv(0x%02x), temp(%d)\n",
1105 __func__
, battery
->status
, battery
->swelling_mode
,
1106 battery
->charging_block
, val
.intval
, temperature
);
1109 under voltage over voltage, battery missing */
1110 if ((battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) ||\
1111 (battery
->status
== POWER_SUPPLY_STATUS_NOT_CHARGING
)) {
1112 pr_info("%s: DISCHARGING or NOT-CHARGING. stop swelling mode\n", __func__
);
1113 battery
->swelling_mode
= false;
1114 sec_bat_set_current_event(battery
, 0,
1115 (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
| SEC_BAT_CURRENT_EVENT_LOW_TEMP
|
1116 SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
));
1117 goto skip_swelling_chek
;
1120 if (!battery
->swelling_mode
) {
1121 if (((temperature
>= battery
->pdata
->swelling_high_temp_block
) ||
1122 (temperature
<= battery
->pdata
->swelling_low_temp_block_2nd
)) &&
1123 battery
->pdata
->temp_check_type
) {
1125 if (temperature
>= battery
->pdata
->swelling_high_temp_block
&&
1126 battery
->pdata
->event_check
&&
1128 pr_info("%s: skip check swelling in high temperature event mode(%d)\n",
1129 __func__
, battery
->event
);
1133 pr_info("%s: swelling mode start. stop charging\n", __func__
);
1134 battery
->swelling_mode
= true;
1135 battery
->swelling_full_check_cnt
= 0;
1136 sec_bat_set_charge(battery
, false);
1138 } else if ((battery
->temperature
<= battery
->pdata
->swelling_low_temp_block_1st
) &&
1139 !(battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
)) {
1140 pr_info("%s: low temperature reduce current\n", __func__
);
1141 sec_bat_set_current_event(battery
, SEC_BAT_CURRENT_EVENT_LOW_TEMP
,
1142 SEC_BAT_CURRENT_EVENT_LOW_TEMP
);
1143 } else if ((battery
->temperature
>= battery
->pdata
->swelling_low_temp_recov_1st
) &&
1144 (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
)) {
1145 pr_info("%s: normal temperature recover current\n", __func__
);
1146 sec_bat_set_current_event(battery
, 0, SEC_BAT_CURRENT_EVENT_LOW_TEMP
);
1150 if (!battery
->voltage_now
)
1153 if (battery
->swelling_mode
) {
1154 if (temperature
<= battery
->pdata
->swelling_low_temp_recov_2nd
)
1155 swelling_rechg_voltage
= battery
->pdata
->swelling_low_rechg_voltage
;
1157 swelling_rechg_voltage
= battery
->pdata
->swelling_high_rechg_voltage
;
1159 if ((temperature
<= battery
->pdata
->swelling_high_temp_recov
) &&
1160 (temperature
>= battery
->pdata
->swelling_low_temp_recov_2nd
)) {
1161 pr_info("%s: swelling mode end. restart charging\n", __func__
);
1162 battery
->swelling_mode
= false;
1163 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
1164 sec_bat_set_current_event(battery
, 0,
1165 (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
|
1166 SEC_BAT_CURRENT_EVENT_LOW_TEMP
|
1167 SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
));
1168 sec_bat_set_charge(battery
, true);
1169 /* restore 4.4V float voltage */
1170 val
.intval
= battery
->pdata
->swelling_normal_float_voltage
;
1171 psy_do_property(battery
->pdata
->charger_name
, set
,
1172 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1173 } else if (battery
->voltage_now
< swelling_rechg_voltage
&&
1174 battery
->charging_block
) {
1175 pr_info("%s: swelling mode recharging start. Vbatt(%d)\n",
1176 __func__
, battery
->voltage_now
);
1177 battery
->charging_mode
= SEC_BATTERY_CHARGING_1ST
;
1179 sec_bat_set_charge(battery
, true);
1180 /* change 4.20V float voltage */
1181 val
.intval
= battery
->pdata
->swelling_drop_float_voltage
;
1182 psy_do_property(battery
->pdata
->charger_name
, set
,
1183 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1184 if ((temperature
<= battery
->pdata
->swelling_low_temp_recov_2nd
) &&
1185 (battery
->pdata
->swelling_low_temp_current
> 0)) {
1186 pr_info("%s: swelling mode reduce charging current(temp:%d)\n",
1187 __func__
, temperature
);
1188 sec_bat_set_current_event(battery
, SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
,
1189 SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
);
1190 } else if ((temperature
>= battery
->pdata
->swelling_high_temp_recov
) &&
1191 (battery
->pdata
->swelling_high_temp_current
> 0)) {
1192 pr_info("%s: swelling mode reduce charging current(temp:%d)\n",
1193 __func__
, temperature
);
1194 sec_bat_set_current_event(battery
, SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
,
1195 SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
);
1200 if (en_swelling
&& !en_rechg
) {
1201 pr_info("%s : SAFETY TIME RESET (SWELLING MODE CHARING STOP!)\n", __func__
);
1202 battery
->expired_time
= battery
->pdata
->expired_time
;
1203 battery
->prev_safety_time
= 0;
1207 dev_dbg(battery
->dev
, "%s end\n", __func__
);
1211 static void set_swelling_current(struct sec_battery_info
*battery
)
1213 int charging_current
= battery
->pdata
->charging_current
[battery
->cable_type
].fast_charging_current
;
1215 union power_supply_propval value
= {0, };
1217 if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING
) {
1218 charging_current
= (charging_current
> battery
->pdata
->swelling_low_temp_current
) ?
1219 battery
->pdata
->swelling_low_temp_current
: charging_current
;
1220 } else if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING
) {
1221 charging_current
= (charging_current
> battery
->pdata
->swelling_high_temp_current
) ?
1222 battery
->pdata
->swelling_high_temp_current
: charging_current
;
1223 } else if (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
) {
1224 charging_current
= (charging_current
> battery
->pdata
->swelling_low_temp_current
) ?
1225 battery
->pdata
->swelling_low_temp_current
: charging_current
;
1228 if (battery
->charging_current
!= charging_current
) {
1229 value
.intval
= charging_current
;
1230 pr_info(" %s Charging_current = %d \n", __func__
, charging_current
);
1231 psy_do_property(battery
->pdata
->charger_name
, set
,
1232 POWER_SUPPLY_PROP_CURRENT_AVG
, value
);
1233 battery
->charging_current
= charging_current
;
1237 #if defined(CONFIG_BATTERY_AGE_FORECAST)
1238 static bool sec_bat_set_aging_step(struct sec_battery_info
*battery
, int step
)
1240 union power_supply_propval value
;
1242 if (battery
->pdata
->num_age_step
<= 0 || step
< 0 || step
>= battery
->pdata
->num_age_step
) {
1243 pr_info("%s: [AGE] abnormal age step : %d/%d\n",
1244 __func__
, step
, battery
->pdata
->num_age_step
-1);
1248 if (battery
->temperature
< 50) {
1249 pr_info("%s: [AGE] skip (temperature:%d)\n", __func__
, battery
->temperature
< 50);
1253 battery
->pdata
->age_step
= step
;
1256 battery
->pdata
->chg_float_voltage
=
1257 battery
->pdata
->age_data
[battery
->pdata
->age_step
].float_voltage
;
1258 battery
->pdata
->swelling_normal_float_voltage
=
1259 battery
->pdata
->chg_float_voltage
;
1260 if (!battery
->swelling_mode
) {
1261 value
.intval
= battery
->pdata
->chg_float_voltage
;
1262 psy_do_property(battery
->pdata
->charger_name
, set
,
1263 POWER_SUPPLY_PROP_VOLTAGE_MAX
, value
);
1266 /* full/recharge condition */
1267 battery
->pdata
->recharge_condition_vcell
=
1268 battery
->pdata
->age_data
[battery
->pdata
->age_step
].recharge_condition_vcell
;
1269 battery
->pdata
->full_condition_soc
=
1270 battery
->pdata
->age_data
[battery
->pdata
->age_step
].full_condition_soc
;
1271 battery
->pdata
->full_condition_vcell
=
1272 battery
->pdata
->age_data
[battery
->pdata
->age_step
].full_condition_vcell
;
1273 #if defined(CONFIG_FUELGAUGE_S2MU003)
1274 value
.intval
= battery
->pdata
->age_step
;
1275 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
1276 POWER_SUPPLY_PROP_UPDATE_BATTERY_DATA
, value
);
1278 value
.intval
= battery
->pdata
->full_condition_soc
;
1279 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
1280 POWER_SUPPLY_PROP_CAPACITY_LEVEL
, value
);
1282 dev_info(battery
->dev
,
1283 "%s: Step(%d/%d), Cycle(%d), float_v(%d), r_v(%d), f_s(%d), f_vl(%d)\n",
1285 battery
->pdata
->age_step
, battery
->pdata
->num_age_step
-1, battery
->batt_cycle
,
1286 battery
->pdata
->chg_float_voltage
,
1287 battery
->pdata
->recharge_condition_vcell
,
1288 battery
->pdata
->full_condition_soc
,
1289 battery
->pdata
->full_condition_vcell
);
1294 static void sec_bat_aging_check(struct sec_battery_info
*battery
)
1296 int prev_step
= battery
->pdata
->age_step
;
1300 if (battery
->pdata
->num_age_step
<= 0)
1303 if (battery
->temperature
< 50) {
1304 pr_info("%s: [AGE] skip (temperature:%d)\n", __func__
, battery
->temperature
);
1308 for (calc_step
= battery
->pdata
->num_age_step
- 1; calc_step
>= 0; calc_step
--) {
1309 if (battery
->pdata
->age_data
[calc_step
].cycle
<= battery
->batt_cycle
)
1312 dev_info(battery
->dev
,
1313 "%s: [Long life] prev_step = %d, calc_step = %d\n", __func__
, prev_step
, calc_step
);
1314 if (calc_step
== prev_step
)
1317 ret
= sec_bat_set_aging_step(battery
, calc_step
);
1318 dev_info(battery
->dev
,
1319 "%s: %s change step (%d->%d), Cycle(%d)\n",
1320 __func__
, ret
? "Succeed in" : "Fail to",
1321 prev_step
, battery
->pdata
->age_step
, battery
->batt_cycle
);
1325 static bool sec_bat_temperature_check(
1326 struct sec_battery_info
*battery
)
1331 if (battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
1332 dev_dbg(battery
->dev
,
1333 "%s: Charging Disabled\n", __func__
);
1337 if (battery
->health
!= POWER_SUPPLY_HEALTH_GOOD
&&
1338 battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEAT
&&
1339 battery
->health
!= POWER_SUPPLY_HEALTH_COLD
&&
1340 battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1341 dev_dbg(battery
->dev
, "%s: No need to check\n", __func__
);
1345 sec_bat_temperature(battery
);
1347 switch (battery
->pdata
->temp_check_type
) {
1348 case SEC_BATTERY_TEMP_CHECK_ADC
:
1349 temp_value
= battery
->temp_adc
;
1351 case SEC_BATTERY_TEMP_CHECK_TEMP
:
1352 temp_value
= battery
->temperature
;
1355 dev_err(battery
->dev
,
1356 "%s: Invalid Temp Check Type\n", __func__
);
1359 pre_health
= battery
->health
;
1361 if (temp_value
>= battery
->temp_highlimit_threshold
) {
1362 if (battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1363 if (battery
->temp_highlimit_cnt
<
1364 battery
->pdata
->temp_check_count
) {
1365 battery
->temp_highlimit_cnt
++;
1366 battery
->temp_high_cnt
= 0;
1367 battery
->temp_low_cnt
= 0;
1368 battery
->temp_recover_cnt
= 0;
1370 dev_dbg(battery
->dev
,
1371 "%s: highlimit count = %d\n",
1372 __func__
, battery
->temp_highlimit_cnt
);
1374 } else if (temp_value
>= battery
->temp_high_threshold
) {
1375 if (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1376 if (temp_value
<= battery
->temp_highlimit_recovery
) {
1377 if (battery
->temp_recover_cnt
<
1378 battery
->pdata
->temp_check_count
) {
1379 battery
->temp_recover_cnt
++;
1380 battery
->temp_highlimit_cnt
= 0;
1381 battery
->temp_high_cnt
= 0;
1382 battery
->temp_low_cnt
= 0;
1384 dev_dbg(battery
->dev
,
1385 "%s: recovery count = %d\n",
1386 __func__
, battery
->temp_recover_cnt
);
1388 } else if (battery
->health
!= POWER_SUPPLY_HEALTH_OVERHEAT
) {
1389 if (battery
->temp_high_cnt
<
1390 battery
->pdata
->temp_check_count
) {
1391 battery
->temp_high_cnt
++;
1392 battery
->temp_highlimit_cnt
= 0;
1393 battery
->temp_low_cnt
= 0;
1394 battery
->temp_recover_cnt
= 0;
1396 dev_dbg(battery
->dev
,
1397 "%s: high count = %d\n",
1398 __func__
, battery
->temp_high_cnt
);
1400 } else if ((temp_value
<= battery
->temp_high_recovery
) &&
1401 (temp_value
>= battery
->temp_low_recovery
)) {
1402 if (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEAT
||
1403 battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
||
1404 battery
->health
== POWER_SUPPLY_HEALTH_COLD
) {
1405 if (battery
->temp_recover_cnt
<
1406 battery
->pdata
->temp_check_count
) {
1407 battery
->temp_recover_cnt
++;
1408 battery
->temp_highlimit_cnt
= 0;
1409 battery
->temp_high_cnt
= 0;
1410 battery
->temp_low_cnt
= 0;
1412 dev_dbg(battery
->dev
,
1413 "%s: recovery count = %d\n",
1414 __func__
, battery
->temp_recover_cnt
);
1416 } else if (temp_value
<= battery
->temp_low_threshold
) {
1417 if (battery
->health
!= POWER_SUPPLY_HEALTH_COLD
) {
1418 if (battery
->temp_low_cnt
<
1419 battery
->pdata
->temp_check_count
) {
1420 battery
->temp_low_cnt
++;
1421 battery
->temp_highlimit_cnt
= 0;
1422 battery
->temp_high_cnt
= 0;
1423 battery
->temp_recover_cnt
= 0;
1425 dev_dbg(battery
->dev
,
1426 "%s: low count = %d\n",
1427 __func__
, battery
->temp_low_cnt
);
1430 battery
->temp_highlimit_cnt
= 0;
1431 battery
->temp_high_cnt
= 0;
1432 battery
->temp_low_cnt
= 0;
1433 battery
->temp_recover_cnt
= 0;
1436 if (battery
->temp_highlimit_cnt
>=
1437 battery
->pdata
->temp_check_count
) {
1438 battery
->health
= POWER_SUPPLY_HEALTH_OVERHEATLIMIT
;
1439 battery
->temp_highlimit_cnt
= 0;
1440 } else if (battery
->temp_high_cnt
>=
1441 battery
->pdata
->temp_check_count
) {
1442 battery
->health
= POWER_SUPPLY_HEALTH_OVERHEAT
;
1443 battery
->temp_high_cnt
= 0;
1444 } else if (battery
->temp_low_cnt
>=
1445 battery
->pdata
->temp_check_count
) {
1446 battery
->health
= POWER_SUPPLY_HEALTH_COLD
;
1447 battery
->temp_low_cnt
= 0;
1448 } else if (battery
->temp_recover_cnt
>=
1449 battery
->pdata
->temp_check_count
) {
1450 if (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
) {
1451 battery
->health
= POWER_SUPPLY_HEALTH_OVERHEAT
;
1453 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
1454 union power_supply_propval value
;
1456 psy_do_property(battery
->pdata
->charger_name
, get
,
1457 POWER_SUPPLY_PROP_VOLTAGE_MAX
, value
);
1458 if (value
.intval
<= battery
->pdata
->swelling_normal_float_voltage
) {
1459 value
.intval
= battery
->pdata
->swelling_normal_float_voltage
;
1460 psy_do_property(battery
->pdata
->charger_name
, set
,
1461 POWER_SUPPLY_PROP_VOLTAGE_MAX
, value
);
1464 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
1466 battery
->temp_recover_cnt
= 0;
1468 if (pre_health
!= battery
->health
) {
1469 battery
->health_change
= true;
1470 dev_info(battery
->dev
, "%s, health_change true\n", __func__
);
1472 battery
->health_change
= false;
1475 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERHEAT
) ||
1476 (battery
->health
== POWER_SUPPLY_HEALTH_COLD
) ||
1477 (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
)) {
1478 if (battery
->status
!= POWER_SUPPLY_STATUS_NOT_CHARGING
) {
1479 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
1480 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERHEAT
) ||
1481 (battery
->health
== POWER_SUPPLY_HEALTH_OVERHEATLIMIT
)) {
1482 union power_supply_propval val
;
1483 /* change 4.20V float voltage */
1484 val
.intval
= battery
->pdata
->swelling_drop_float_voltage
;
1485 psy_do_property(battery
->pdata
->charger_name
, set
,
1486 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
1489 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
1490 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
1491 union power_supply_propval val
;
1492 val
.intval
= battery
->health
;
1493 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
1494 POWER_SUPPLY_PROP_HEALTH
, val
);
1497 dev_info(battery
->dev
,
1498 "%s: Unsafe Temperature\n", __func__
);
1499 sec_bat_set_charging_status(battery
,
1500 POWER_SUPPLY_STATUS_NOT_CHARGING
);
1501 /* change charging current to battery (default 0mA) */
1502 sec_bat_set_charge(battery
, false);
1506 /* if recovered from not charging */
1507 if ((battery
->health
== POWER_SUPPLY_HEALTH_GOOD
) &&
1509 POWER_SUPPLY_STATUS_NOT_CHARGING
)) {
1510 dev_info(battery
->dev
,
1511 "%s: Safe Temperature\n", __func__
);
1512 if (battery
->capacity
>= 100)
1513 sec_bat_set_charging_status(battery
,
1514 POWER_SUPPLY_STATUS_FULL
);
1515 else{ /* Normal Charging */
1516 sec_bat_set_charging_status(battery
,
1517 POWER_SUPPLY_STATUS_CHARGING
);
1518 if (battery
->siop_level
!= 100)
1519 battery
->stop_timer
= true;
1521 #if defined(CONFIG_BATTERY_SWELLING)
1522 if ((temp_value
>= battery
->pdata
->swelling_high_temp_block
) ||
1523 (temp_value
<= battery
->pdata
->swelling_low_temp_block_2nd
)) {
1524 pr_info("%s: swelling mode start. stop charging\n", __func__
);
1525 battery
->swelling_mode
= true;
1526 battery
->swelling_full_check_cnt
= 0;
1527 sec_bat_set_charge(battery
, false);
1529 /* turn on charger by cable type */
1530 sec_bat_set_charge(battery
, true);
1533 /* turn on charger by cable type */
1534 sec_bat_set_charge(battery
, true);
1542 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
1543 static void sec_bat_self_discharging_check(struct sec_battery_info
*battery
)
1545 unsigned int dis_adc
;
1546 union power_supply_propval value
;
1548 switch(battery
->pdata
->self_discharging_type
) {
1549 case SEC_BAT_SELF_DISCHARGING_BY_ADC
:
1550 dis_adc
= sec_bat_get_adc_value(battery
, SEC_BAT_ADC_CHANNEL_DISCHARGING_CHECK
);
1552 battery
->self_discharging_adc
= dis_adc
;
1554 battery
->self_discharging_adc
= 0;
1556 if ((dis_adc
>= (int)battery
->pdata
->discharging_adc_min
) &&
1557 (dis_adc
<= (int)battery
->pdata
->discharging_adc_max
))
1558 battery
->self_discharging
= true;
1560 battery
->self_discharging
= false;
1561 pr_info("%s : SELF_DISCHARGING(%d) SELF_DISCHARGING_ADC(%d)\n",
1562 __func__
, battery
->self_discharging
, battery
->self_discharging_adc
);
1564 case SEC_BAT_SELF_DISCHARGING_BY_FG
:
1565 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
1566 POWER_SUPPLY_PROP_CHARGE_ENABLED
, value
);
1568 battery
->self_discharging
= value
.intval
;
1569 pr_info("%s: SELF_DISCHARGING : %s\n", __func__
,
1570 value
.intval
? "Enabled" : "Disabled");
1572 case SEC_BAT_SELF_DISCHARGING_BY_CHG
:
1573 psy_do_property(battery
->pdata
->charger_name
, get
,
1574 POWER_SUPPLY_PROP_RESISTANCE
, value
);
1576 battery
->self_discharging
= value
.intval
;
1577 pr_info("%s: SELF_DISCHARGING : %s\n", __func__
,
1578 value
.intval
? "Enabled" : "Disabled");
1585 static void sec_bat_self_discharging_ntc_check(struct sec_battery_info
*battery
)
1589 ntc_adc
= sec_bat_get_adc_value(battery
, SEC_BAT_ADC_CHANNEL_DISCHARGING_NTC
);
1591 battery
->discharging_ntc_adc
= ntc_adc
;
1593 battery
->discharging_ntc_adc
= 0;
1595 if (ntc_adc
> battery
->pdata
->discharging_ntc_limit
)
1596 battery
->discharging_ntc
= true;
1598 battery
->discharging_ntc
= false;
1600 pr_info("%s : DISCHARGING_NTC(%d) DISCHARGING_NTC_ADC(%d)\n",
1601 __func__
,battery
->discharging_ntc
, battery
->discharging_ntc_adc
);
1604 static void sec_bat_self_discharging_control(struct sec_battery_info
*battery
, bool dis_en
)
1606 union power_supply_propval value
;
1608 switch(battery
->pdata
->self_discharging_type
) {
1609 case SEC_BAT_SELF_DISCHARGING_BY_ADC
:
1610 if (!battery
->pdata
->factory_discharging
) {
1611 pr_info("Can't control Self Discharging IC (No Factory Discharging Pin).\n");
1616 dev_info(battery
->dev
,
1617 "%s : Self Discharging IC doesn't act until (%d) degree & (%d) voltage. "
1618 "Auto Discharging IC ENABLE\n", __func__
,
1619 battery
->temperature
, battery
->voltage_now
);
1620 gpio_direction_output(battery
->pdata
->factory_discharging
, 1);
1621 battery
->force_discharging
= true;
1623 dev_info(battery
->dev
, "%s : Self Discharging IC disable.\n", __func__
);
1624 gpio_direction_output(battery
->pdata
->factory_discharging
, 0);
1625 battery
->force_discharging
= false;
1628 case SEC_BAT_SELF_DISCHARGING_BY_FG
:
1629 value
.intval
= dis_en
;
1630 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
1631 POWER_SUPPLY_PROP_CHARGE_ENABLED
, value
);
1633 pr_info("%s: SELF_DISCHARGING Set to %s\n", __func__
,
1634 value
.intval
? "Enabled" : "Disabled");
1636 case SEC_BAT_SELF_DISCHARGING_BY_CHG
:
1638 battery
->force_discharging
= true;
1640 battery
->force_discharging
= false;
1642 value
.intval
= dis_en
;
1643 psy_do_property(battery
->pdata
->charger_name
, set
,
1644 POWER_SUPPLY_PROP_RESISTANCE
, value
);
1646 pr_info("%s: SELF_DISCHARGING Set to %s\n", __func__
,
1647 value
.intval
? "Enabled" : "Disabled");
1654 static void sec_bat_discharging_check(struct sec_battery_info
*battery
)
1656 if (!battery
->pdata
->self_discharging_en
)
1659 sec_bat_self_discharging_check(battery
);
1661 if(battery
->factory_self_discharging_mode_on
) {
1662 dev_info(battery
->dev
,
1663 "%s: It is Factory mode by self discharging mode, Auto_DIS(%d), Force_DIS(%d)\n",
1664 __func__
, battery
->self_discharging
, battery
->force_discharging
);
1668 if (!battery
->self_discharging
&&
1669 (battery
->temperature
>= battery
->pdata
->force_discharging_limit
) &&
1670 (battery
->voltage_now
>= battery
->pdata
->self_discharging_voltage_limit
)) {
1671 sec_bat_self_discharging_control(battery
, true);
1672 } else if(battery
->force_discharging
&&
1673 ((battery
->temperature
<= battery
->pdata
->force_discharging_recov
) ||
1674 (battery
->voltage_now
<= battery
->pdata
->swelling_drop_float_voltage
))) {
1675 sec_bat_self_discharging_control(battery
, false);
1677 dev_info(battery
->dev
,
1678 "%s: Auto_DIS(%d), Force_DIS(%d)\n",
1679 __func__
, battery
->self_discharging
, battery
->force_discharging
);
1683 #if !defined(CONFIG_SEC_FACTORY)
1684 static void sec_bat_chg_temperature_check(
1685 struct sec_battery_info
*battery
)
1687 #if defined(CONFIG_AFC_CHARGER_MODE)
1688 static bool is_vbus_changed
= false;
1689 union power_supply_propval value
;
1691 pr_info("%s: called (is_vbus:%d, cable:%d))\n", __func__
, is_vbus_changed
, battery
->cable_type
);
1692 if (battery
->siop_level
>= 100 && is_vbus_changed
&&
1693 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) {
1694 is_vbus_changed
= false;
1695 value
.intval
= SEC_INPUT_VOLTAGE_9V
;
1696 psy_do_property(battery
->pdata
->charger_name
, set
,
1697 POWER_SUPPLY_PROP_SET_CHARGE_VOLTAGE
, value
);
1698 pr_info("%s: changed vbus level 5V -> 9V\n", __func__
);
1700 } else if (battery
->siop_level
< 100 && !is_vbus_changed
&&
1701 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&&
1702 is_hv_wire_type(battery
->cable_type
)) {
1703 is_vbus_changed
= true;
1704 pr_info("%s: changed vbus level 9V -> 5V\n", __func__
);
1705 value
.intval
= SEC_INPUT_VOLTAGE_5V
;
1706 psy_do_property(battery
->pdata
->charger_name
, set
,
1707 POWER_SUPPLY_PROP_SET_CHARGE_VOLTAGE
, value
);
1710 if ((is_vbus_changed
&& is_hv_wire_type(battery
->cable_type
)) ||
1711 (!is_vbus_changed
&& (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
))) {
1712 pr_info("%s: prevent abnormal case (cable_type:%d, is_vbus_changed:%d)\n",
1713 __func__
, battery
->cable_type
, is_vbus_changed
);
1715 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
1716 is_vbus_changed
= false;
1721 if (battery
->siop_level
>= 100 &&
1722 ((battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
) ||
1723 (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
))) {
1724 union power_supply_propval value
;
1725 if ((battery
->chg_limit
== SEC_BATTERY_CHG_TEMP_NONE
) &&
1726 (battery
->chg_temp
> battery
->pdata
->chg_high_temp_1st
)) {
1727 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_HIGH_1ST
;
1728 value
.intval
= battery
->pdata
->chg_charging_limit_current
;
1729 psy_do_property(battery
->pdata
->charger_name
, set
,
1730 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1731 dev_info(battery
->dev
,"%s: Chg current is reduced by Temp: %d\n",
1732 __func__
, battery
->chg_temp
);
1733 } else if ((battery
->chg_limit
== SEC_BATTERY_CHG_TEMP_HIGH_1ST
) &&
1734 (battery
->pre_chg_temp
< battery
->pdata
->chg_high_temp_2nd
) &&
1735 (battery
->chg_temp
> battery
->pdata
->chg_high_temp_2nd
)) {
1736 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_HIGH_2ND
;
1737 value
.intval
= battery
->pdata
->chg_charging_limit_current_2nd
;
1738 psy_do_property(battery
->pdata
->charger_name
, set
,
1739 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1740 dev_info(battery
->dev
,"%s: Chg current 2nd is reduced by Temp: %d\n",
1741 __func__
, battery
->chg_temp
);
1742 } else if ((battery
->chg_limit
!= SEC_BATTERY_CHG_TEMP_NONE
) &&
1743 (battery
->chg_temp
< battery
->pdata
->chg_high_temp_recovery
)) {
1744 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
1745 value
.intval
= battery
->pdata
->charging_current
1746 [battery
->cable_type
].input_current_limit
;
1747 psy_do_property(battery
->pdata
->charger_name
, set
,
1748 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1749 dev_info(battery
->dev
,"%s: Chg current is recovered by Temp: %d\n",
1750 __func__
, battery
->chg_temp
);
1752 } else if (battery
->siop_level
>= 100 &&
1753 (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) && battery
->pdata
->wpc_temp_check
) {
1754 union power_supply_propval value
;
1755 if ((battery
->chg_limit
== SEC_BATTERY_CHG_TEMP_NONE
) &&
1756 (battery
->chg_temp
> battery
->pdata
->wpc_high_temp
)) {
1757 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_HIGH_1ST
;
1758 value
.intval
= battery
->pdata
->wpc_charging_limit_current
;
1759 psy_do_property(battery
->pdata
->charger_name
, set
,
1760 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1761 dev_info(battery
->dev
,"%s: WPC Chg current is reduced by Temp: %d\n",
1762 __func__
, battery
->chg_temp
);
1763 } else if ((battery
->chg_limit
!= SEC_BATTERY_CHG_TEMP_NONE
) &&
1764 (battery
->chg_temp
< battery
->pdata
->wpc_high_temp_recovery
)) {
1765 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
1766 value
.intval
= battery
->pdata
->charging_current
1767 [battery
->cable_type
].input_current_limit
;
1768 psy_do_property(battery
->pdata
->charger_name
, set
,
1769 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
1770 dev_info(battery
->dev
,"%s: WPC Chg current is recovered by Temp: %d\n",
1771 __func__
, battery
->chg_temp
);
1773 } else if (battery
->chg_limit
!= SEC_BATTERY_CHG_TEMP_NONE
) {
1774 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
1779 static int sec_bat_get_inbat_vol_by_adc(struct sec_battery_info
*battery
)
1786 const sec_bat_adc_table_data_t
*inbat_adc_table
;
1787 unsigned int inbat_adc_table_size
;
1789 if (!battery
->pdata
->inbat_adc_table
) {
1790 dev_err(battery
->dev
, "%s: not designed to read in-bat voltage\n", __func__
);
1794 inbat_adc_table
= battery
->pdata
->inbat_adc_table
;
1795 inbat_adc_table_size
=
1796 battery
->pdata
->inbat_adc_table_size
;
1798 inbat_adc
= sec_bat_get_adc_value(battery
, SEC_BAT_ADC_CHANNEL_INBAT_VOLTAGE
);
1801 battery
->inbat_adc
= inbat_adc
;
1803 if (inbat_adc_table
[0].adc
<= inbat_adc
) {
1804 inbat
= inbat_adc_table
[0].data
;
1805 goto inbat_by_adc_goto
;
1806 } else if (inbat_adc_table
[inbat_adc_table_size
-1].adc
>= inbat_adc
) {
1807 inbat
= inbat_adc_table
[inbat_adc_table_size
-1].data
;
1808 goto inbat_by_adc_goto
;
1811 high
= inbat_adc_table_size
- 1;
1813 while (low
<= high
) {
1814 mid
= (low
+ high
) / 2;
1815 if (inbat_adc_table
[mid
].adc
< inbat_adc
)
1817 else if (inbat_adc_table
[mid
].adc
> inbat_adc
)
1820 inbat
= inbat_adc_table
[mid
].data
;
1821 goto inbat_by_adc_goto
;
1825 inbat
= inbat_adc_table
[high
].data
;
1827 ((inbat_adc_table
[low
].data
- inbat_adc_table
[high
].data
) *
1828 (inbat_adc
- inbat_adc_table
[high
].adc
)) /
1829 (inbat_adc_table
[low
].adc
- inbat_adc_table
[high
].adc
);
1835 dev_info(battery
->dev
,
1836 "%s: inbat(%d), inbat-ADC(%d)\n",
1837 __func__
, inbat
, inbat_adc
);
1842 static void sec_bat_event_program_alarm(
1843 struct sec_battery_info
*battery
, int seconds
)
1845 #if defined(ANDROID_ALARM_ACTIVATED)
1846 ktime_t low_interval
= ktime_set(seconds
- 10, 0);
1847 ktime_t slack
= ktime_set(20, 0);
1850 next
= ktime_add(battery
->last_event_time
, low_interval
);
1851 alarm_start_range(&battery
->event_termination_alarm
,
1852 next
, ktime_add(next
, slack
));
1854 alarm_start(&battery
->event_termination_alarm
,
1855 ktime_add(battery
->last_event_time
, ktime_set(seconds
- 10, 0)));
1859 #if defined(ANDROID_ALARM_ACTIVATED)
1860 static void sec_bat_event_expired_timer_func(struct alarm
*alarm
)
1862 static enum alarmtimer_restart
sec_bat_event_expired_timer_func(
1863 struct alarm
*alarm
, ktime_t now
)
1866 struct sec_battery_info
*battery
=
1867 container_of(alarm
, struct sec_battery_info
,
1868 event_termination_alarm
);
1870 battery
->event
&= (~battery
->event_wait
);
1871 dev_info(battery
->dev
,
1872 "%s: event expired (0x%x)\n", __func__
, battery
->event
);
1874 #if !defined(ANDROID_ALARM_ACTIVATED)
1875 return ALARMTIMER_NORESTART
;
1879 static void sec_bat_event_set(
1880 struct sec_battery_info
*battery
, int event
, int enable
)
1882 if (!battery
->pdata
->event_check
)
1885 /* ignore duplicated deactivation of same event
1886 * only if the event is one last event
1888 if (!enable
&& (battery
->event
== battery
->event_wait
)) {
1889 dev_info(battery
->dev
,
1890 "%s: ignore duplicated deactivation of same event\n",
1895 alarm_cancel(&battery
->event_termination_alarm
);
1896 battery
->event
&= (~battery
->event_wait
);
1899 battery
->event_wait
= 0;
1900 battery
->event
|= event
;
1902 dev_info(battery
->dev
,
1903 "%s: event set (0x%x)\n", __func__
, battery
->event
);
1905 if (battery
->event
== 0) {
1906 dev_dbg(battery
->dev
,
1907 "%s: nothing to clear\n", __func__
);
1908 return; /* nothing to clear */
1910 battery
->event_wait
= event
;
1911 #if defined(ANDROID_ALARM_ACTIVATED)
1912 battery
->last_event_time
= alarm_get_elapsed_realtime();
1914 battery
->last_event_time
= ktime_get_boottime();
1916 sec_bat_event_program_alarm(battery
,
1917 battery
->pdata
->event_waiting_time
);
1918 dev_info(battery
->dev
,
1919 "%s: start timer (curr 0x%x, wait 0x%x)\n",
1920 __func__
, battery
->event
, battery
->event_wait
);
1924 static bool sec_bat_check_fullcharged_condition(
1925 struct sec_battery_info
*battery
)
1927 int full_check_type
;
1929 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
)
1930 full_check_type
= battery
->pdata
->full_check_type
;
1932 full_check_type
= battery
->pdata
->full_check_type_2nd
;
1934 switch (full_check_type
) {
1935 case SEC_BATTERY_FULLCHARGED_ADC
:
1936 case SEC_BATTERY_FULLCHARGED_FG_CURRENT
:
1937 case SEC_BATTERY_FULLCHARGED_SOC
:
1938 case SEC_BATTERY_FULLCHARGED_CHGGPIO
:
1939 case SEC_BATTERY_FULLCHARGED_CHGPSY
:
1942 /* If these is NOT full check type or NONE full check type,
1943 * it is full-charged
1945 case SEC_BATTERY_FULLCHARGED_CHGINT
:
1946 case SEC_BATTERY_FULLCHARGED_TIME
:
1947 case SEC_BATTERY_FULLCHARGED_NONE
:
1953 if (battery
->pdata
->full_condition_type
&
1954 SEC_BATTERY_FULL_CONDITION_SOC
) {
1955 if (battery
->capacity
<
1956 battery
->pdata
->full_condition_soc
) {
1957 dev_dbg(battery
->dev
,
1958 "%s: Not enough SOC (%d%%)\n",
1959 __func__
, battery
->capacity
);
1964 if (battery
->pdata
->full_condition_type
&
1965 SEC_BATTERY_FULL_CONDITION_VCELL
) {
1966 if (battery
->voltage_now
<
1967 battery
->pdata
->full_condition_vcell
) {
1968 dev_dbg(battery
->dev
,
1969 "%s: Not enough VCELL (%dmV)\n",
1970 __func__
, battery
->voltage_now
);
1975 if (battery
->pdata
->full_condition_type
&
1976 SEC_BATTERY_FULL_CONDITION_AVGVCELL
) {
1977 if (battery
->voltage_avg
<
1978 battery
->pdata
->full_condition_avgvcell
) {
1979 dev_dbg(battery
->dev
,
1980 "%s: Not enough AVGVCELL (%dmV)\n",
1981 __func__
, battery
->voltage_avg
);
1986 if (battery
->pdata
->full_condition_type
&
1987 SEC_BATTERY_FULL_CONDITION_OCV
) {
1988 if (battery
->voltage_ocv
<
1989 battery
->pdata
->full_condition_ocv
) {
1990 dev_dbg(battery
->dev
,
1991 "%s: Not enough OCV (%dmV)\n",
1992 __func__
, battery
->voltage_ocv
);
2000 static void sec_bat_do_test_function(
2001 struct sec_battery_info
*battery
)
2003 union power_supply_propval value
;
2005 switch (battery
->test_mode
) {
2007 if (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) {
2008 sec_bat_set_charge(battery
, false);
2009 sec_bat_set_charging_status(battery
,
2010 POWER_SUPPLY_STATUS_DISCHARGING
);
2014 if(battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
2015 sec_bat_set_charge(battery
, true);
2016 psy_do_property(battery
->pdata
->charger_name
, get
,
2017 POWER_SUPPLY_PROP_STATUS
, value
);
2018 sec_bat_set_charging_status(battery
, value
.intval
);
2020 battery
->test_mode
= 0;
2022 case 3: // clear temp block
2023 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
2024 sec_bat_set_charging_status(battery
,
2025 POWER_SUPPLY_STATUS_DISCHARGING
);
2028 if(battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) {
2029 sec_bat_set_charge(battery
, true);
2030 psy_do_property(battery
->pdata
->charger_name
, get
,
2031 POWER_SUPPLY_PROP_STATUS
, value
);
2032 sec_bat_set_charging_status(battery
, value
.intval
);
2036 pr_info("%s: error test: unknown state\n", __func__
);
2041 static bool sec_bat_time_management(
2042 struct sec_battery_info
*battery
)
2044 unsigned long charging_time
;
2045 //unsigned long expired_time = 0;
2047 //unsigned int charging_total_time = 10 * 60 * 60;
2048 #if defined(ANDROID_ALARM_ACTIVATED)
2049 ktime_t current_time
;
2051 current_time
= alarm_get_elapsed_realtime();
2052 ts
= ktime_to_timespec(current_time
);
2054 get_monotonic_boottime(&ts
);
2057 if(battery
->charging_start_time
== 0 || !battery
->safety_timer_set
) {
2058 pr_info("%s: Charging Disabled\n" ,__func__
);
2062 if (ts
.tv_sec
>= battery
->charging_start_time
)
2063 charging_time
= ts
.tv_sec
- battery
->charging_start_time
;
2065 charging_time
= 0xFFFFFFFF - battery
->charging_start_time
2068 battery
->charging_passed_time
= charging_time
;
2070 if (!battery
->store_mode
) {
2071 if (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
||
2072 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
||
2073 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_UNKNOWN
) {
2074 charging_total_time
= battery
->pdata
->hv_charging_total_time
;
2075 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_MAINS
||
2076 battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2077 charging_total_time
= battery
->pdata
->normal_charging_total_time
;
2079 charging_total_time
= battery
->pdata
->usb_charging_total_time
;
2083 dev_info(battery
->dev
,
2084 "%s: Charging Time : %ld secs\n", __func__
,
2085 battery
->charging_passed_time
);
2087 if (battery
->siop_level
>= 100) {
2088 if (charging_time
< battery
->lcd_on_total_time
)
2089 battery
->lcd_on_total_time
= charging_time
;
2090 expired_time
= charging_time
- battery
->lcd_on_total_time
;
2091 pr_info("%s: Total Charging time : %ld, Expired Time : %ld, LCD On total Time : %ld\n",
2092 __func__
, charging_time
, expired_time
, battery
->lcd_on_total_time
);
2097 switch (battery
->status
) {
2098 case POWER_SUPPLY_STATUS_FULL
:
2099 if (battery
->expired_time
== 0) {
2100 dev_info(battery
->dev
,
2101 "%s: Recharging Timer Expired\n", __func__
);
2102 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2103 battery
->health
= POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
2104 sec_bat_set_charging_status(battery
,
2105 POWER_SUPPLY_STATUS_NOT_CHARGING
);
2106 battery
->is_recharging
= false;
2107 if (sec_bat_set_charge(battery
, false)) {
2108 dev_err(battery
->dev
,
2109 "%s: Fail to Set Charger\n", __func__
);
2116 case POWER_SUPPLY_STATUS_CHARGING
:
2117 if ((battery
->pdata
->full_condition_type
&
2118 SEC_BATTERY_FULL_CONDITION_NOTIMEFULL
) &&
2119 (battery
->is_recharging
&& (battery
->expired_time
== 0))) {
2120 dev_info(battery
->dev
,
2121 "%s: Recharging Timer Expired\n", __func__
);
2122 battery
->health
= POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
2123 sec_bat_set_charging_status(battery
,
2124 POWER_SUPPLY_STATUS_NOT_CHARGING
);
2125 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2126 battery
->is_recharging
= false;
2127 if (sec_bat_set_charge(battery
, false)) {
2128 dev_err(battery
->dev
,
2129 "%s: Fail to Set Charger\n", __func__
);
2133 } else if (!battery
->is_recharging
&& (battery
->expired_time
== 0)) {
2134 dev_info(battery
->dev
,
2135 "%s: Charging Timer Expired\n", __func__
);
2136 battery
->health
= POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE
;
2137 sec_bat_set_charging_status(battery
,
2138 POWER_SUPPLY_STATUS_NOT_CHARGING
);
2139 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2140 if (sec_bat_set_charge(battery
, false)) {
2141 dev_err(battery
->dev
,
2142 "%s: Fail to Set Charger\n", __func__
);
2149 if (battery
->pdata
->charging_reset_time
) {
2150 if (charging_time
> battery
->charging_next_time
) {
2151 /*reset current in charging status */
2152 battery
->charging_next_time
=
2153 battery
->charging_passed_time
+
2154 (battery
->pdata
->charging_reset_time
);
2156 dev_dbg(battery
->dev
,
2157 "%s: Reset charging current\n",
2159 #if defined(CONFIG_BATTERY_SWELLING)
2160 if (!battery
->swelling_mode
) {
2161 if (sec_bat_set_charge(battery
, true)) {
2162 dev_err(battery
->dev
,
2163 "%s: Fail to Set Charger\n",
2169 if (sec_bat_set_charge(battery
, true)) {
2170 dev_err(battery
->dev
,
2171 "%s: Fail to Set Charger\n",
2181 dev_err(battery
->dev
,
2182 "%s: Undefine Battery Status\n", __func__
);
2189 static bool sec_bat_check_fullcharged(
2190 struct sec_battery_info
*battery
)
2192 union power_supply_propval value
;
2194 int full_check_type
;
2200 if (!sec_bat_check_fullcharged_condition(battery
))
2201 goto not_full_charged
;
2203 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
)
2204 full_check_type
= battery
->pdata
->full_check_type
;
2206 full_check_type
= battery
->pdata
->full_check_type_2nd
;
2208 pr_info("%s : full_check_type(%d)\n", __func__
, full_check_type
);
2210 switch (full_check_type
) {
2211 case SEC_BATTERY_FULLCHARGED_ADC
:
2213 sec_bat_get_adc_value(battery
,
2214 SEC_BAT_ADC_CHANNEL_FULL_CHECK
);
2216 dev_dbg(battery
->dev
,
2217 "%s: Current ADC (%d)\n",
2218 __func__
, current_adc
);
2220 if (current_adc
< 0)
2222 battery
->current_adc
= current_adc
;
2224 if (battery
->current_adc
<
2225 (battery
->charging_mode
==
2226 SEC_BATTERY_CHARGING_1ST
?
2227 battery
->pdata
->charging_current
[
2228 battery
->cable_type
].full_check_current_1st
:
2229 battery
->pdata
->charging_current
[
2230 battery
->cable_type
].full_check_current_2nd
)) {
2231 battery
->full_check_cnt
++;
2232 dev_dbg(battery
->dev
,
2233 "%s: Full Check ADC (%d)\n",
2235 battery
->full_check_cnt
);
2237 battery
->full_check_cnt
= 0;
2240 case SEC_BATTERY_FULLCHARGED_FG_CURRENT
:
2241 if ((battery
->current_now
> 0 && battery
->current_now
<
2242 battery
->pdata
->charging_current
[
2243 battery
->cable_type
].full_check_current_1st
) &&
2244 (battery
->current_avg
> 0 && battery
->current_avg
<
2245 (battery
->charging_mode
==
2246 SEC_BATTERY_CHARGING_1ST
?
2247 battery
->pdata
->charging_current
[
2248 battery
->cable_type
].full_check_current_1st
:
2249 battery
->pdata
->charging_current
[
2250 battery
->cable_type
].full_check_current_2nd
))) {
2251 battery
->full_check_cnt
++;
2252 dev_dbg(battery
->dev
,
2253 "%s: Full Check Current (%d)\n",
2255 battery
->full_check_cnt
);
2257 battery
->full_check_cnt
= 0;
2260 case SEC_BATTERY_FULLCHARGED_TIME
:
2261 if ((battery
->charging_mode
==
2262 SEC_BATTERY_CHARGING_2ND
?
2263 (battery
->charging_passed_time
-
2264 battery
->charging_fullcharged_time
) :
2265 battery
->charging_passed_time
) >
2266 (battery
->charging_mode
==
2267 SEC_BATTERY_CHARGING_1ST
?
2268 battery
->pdata
->charging_current
[
2269 battery
->cable_type
].full_check_current_1st
:
2270 battery
->pdata
->charging_current
[
2271 battery
->cable_type
].full_check_current_2nd
)) {
2272 battery
->full_check_cnt
++;
2273 dev_dbg(battery
->dev
,
2274 "%s: Full Check Time (%d)\n",
2276 battery
->full_check_cnt
);
2278 battery
->full_check_cnt
= 0;
2281 case SEC_BATTERY_FULLCHARGED_SOC
:
2282 if (battery
->capacity
<=
2283 (battery
->charging_mode
==
2284 SEC_BATTERY_CHARGING_1ST
?
2285 battery
->pdata
->charging_current
[
2286 battery
->cable_type
].full_check_current_1st
:
2287 battery
->pdata
->charging_current
[
2288 battery
->cable_type
].full_check_current_2nd
)) {
2289 battery
->full_check_cnt
++;
2290 dev_dbg(battery
->dev
,
2291 "%s: Full Check SOC (%d)\n",
2293 battery
->full_check_cnt
);
2295 battery
->full_check_cnt
= 0;
2298 case SEC_BATTERY_FULLCHARGED_CHGGPIO
:
2300 battery
->pdata
->chg_gpio_full_check
,
2303 dev_err(battery
->dev
,
2304 "%s: Error in Request of GPIO\n", __func__
);
2307 if (!(gpio_get_value_cansleep(
2308 battery
->pdata
->chg_gpio_full_check
) ^
2309 !battery
->pdata
->chg_polarity_full_check
)) {
2310 battery
->full_check_cnt
++;
2311 dev_dbg(battery
->dev
,
2312 "%s: Full Check GPIO (%d)\n",
2313 __func__
, battery
->full_check_cnt
);
2315 battery
->full_check_cnt
= 0;
2316 gpio_free(battery
->pdata
->chg_gpio_full_check
);
2319 case SEC_BATTERY_FULLCHARGED_CHGINT
:
2320 case SEC_BATTERY_FULLCHARGED_CHGPSY
:
2321 psy_do_property(battery
->pdata
->charger_name
, get
,
2322 POWER_SUPPLY_PROP_STATUS
, value
);
2324 if (value
.intval
== POWER_SUPPLY_STATUS_FULL
) {
2325 battery
->full_check_cnt
++;
2326 dev_info(battery
->dev
,
2327 "%s: Full Check Charger (%d)\n",
2328 __func__
, battery
->full_check_cnt
);
2330 battery
->full_check_cnt
= 0;
2333 /* If these is NOT full check type or NONE full check type,
2334 * it is full-charged
2336 case SEC_BATTERY_FULLCHARGED_NONE
:
2337 battery
->full_check_cnt
= 0;
2341 dev_err(battery
->dev
,
2342 "%s: Invalid Full Check\n", __func__
);
2346 if (battery
->full_check_cnt
>=
2347 battery
->pdata
->full_check_count
) {
2348 battery
->full_check_cnt
= 0;
2356 static void sec_bat_do_fullcharged(
2357 struct sec_battery_info
*battery
)
2359 union power_supply_propval value
;
2361 /* To let charger/fuel gauge know the full status,
2362 * set status before calling sec_bat_set_charge()
2364 sec_bat_set_charging_status(battery
,
2365 POWER_SUPPLY_STATUS_FULL
);
2368 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
) {
2369 battery
->charging_mode
= SEC_BATTERY_CHARGING_2ND
;
2370 battery
->charging_fullcharged_time
=
2371 battery
->charging_passed_time
;
2372 sec_bat_set_charge(battery
, true);
2373 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) && defined(CONFIG_WIRELESS_CHARGER_INBATTERY_CS100)
2374 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2375 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2376 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
2377 POWER_SUPPLY_PROP_STATUS
, value
);
2381 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2382 battery
->is_recharging
= false;
2383 sec_bat_set_charge(battery
, false);
2385 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY) && !defined(CONFIG_WIRELESS_CHARGER_INBATTERY_CS100)
2386 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2387 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2388 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
2389 POWER_SUPPLY_PROP_STATUS
, value
);
2392 #if defined(CONFIG_BATTERY_AGE_FORECAST)
2393 sec_bat_aging_check(battery
);
2395 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2396 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2397 POWER_SUPPLY_PROP_STATUS
, value
);
2400 #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX)
2401 #if defined(CONFIG_PREVENT_SOC_JUMP)
2402 value
.intval
= battery
->capacity
;
2404 value
.intval
= POWER_SUPPLY_TYPE_BATTERY
;
2406 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2407 POWER_SUPPLY_PROP_CHARGE_FULL
, value
);
2410 /* platform can NOT get information of battery
2411 * because wakeup time is too short to check uevent
2412 * To make sure that target is wakeup if full-charged,
2413 * activated wake lock in a few seconds
2415 if (battery
->pdata
->polling_type
== SEC_BATTERY_MONITOR_ALARM
)
2416 wake_lock_timeout(&battery
->vbus_wake_lock
, HZ
* 10);
2419 static bool sec_bat_fullcharged_check(
2420 struct sec_battery_info
*battery
)
2422 if ((battery
->charging_mode
== SEC_BATTERY_CHARGING_NONE
) ||
2423 (battery
->status
== POWER_SUPPLY_STATUS_NOT_CHARGING
)) {
2424 dev_dbg(battery
->dev
,
2425 "%s: No Need to Check Full-Charged\n", __func__
);
2429 if (sec_bat_check_fullcharged(battery
))
2430 sec_bat_do_fullcharged(battery
);
2432 dev_info(battery
->dev
,
2433 "%s: Charging Mode : %s\n", __func__
,
2434 battery
->is_recharging
?
2435 sec_bat_charging_mode_str
[SEC_BATTERY_CHARGING_RECHARGING
] :
2436 sec_bat_charging_mode_str
[battery
->charging_mode
]);
2441 static void sec_bat_get_temperature_info(
2442 struct sec_battery_info
*battery
)
2444 union power_supply_propval value
;
2446 switch (battery
->pdata
->thermal_source
) {
2447 case SEC_BATTERY_THERMAL_SOURCE_FG
:
2448 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2449 POWER_SUPPLY_PROP_TEMP
, value
);
2450 battery
->temperature
= value
.intval
;
2452 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2453 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
2454 battery
->temper_amb
= value
.intval
;
2456 case SEC_BATTERY_THERMAL_SOURCE_CALLBACK
:
2457 if (battery
->pdata
->get_temperature_callback
) {
2458 battery
->pdata
->get_temperature_callback(
2459 POWER_SUPPLY_PROP_TEMP
, &value
);
2460 battery
->temperature
= value
.intval
;
2461 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2462 POWER_SUPPLY_PROP_TEMP
, value
);
2464 battery
->pdata
->get_temperature_callback(
2465 POWER_SUPPLY_PROP_TEMP_AMBIENT
, &value
);
2466 battery
->temper_amb
= value
.intval
;
2467 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2468 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
2471 case SEC_BATTERY_THERMAL_SOURCE_ADC
:
2472 sec_bat_get_temperature_by_adc(battery
,
2473 SEC_BAT_ADC_CHANNEL_TEMP
, &value
);
2474 battery
->temperature
= value
.intval
;
2475 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2476 POWER_SUPPLY_PROP_TEMP
, value
);
2478 sec_bat_get_temperature_by_adc(battery
,
2479 SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT
, &value
);
2480 battery
->temper_amb
= value
.intval
;
2481 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2482 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
2484 #if defined(CONFIG_AFC_CHARGER_MODE)
2485 sec_bat_get_temperature_by_adc(battery
,
2486 SEC_BAT_ADC_CHANNEL_CHG_TEMP
, &value
);
2487 if (battery
->pre_chg_temp
== 0) {
2488 battery
->pre_chg_temp
= value
.intval
;
2489 battery
->chg_temp
= value
.intval
;
2491 battery
->pre_chg_temp
= battery
->chg_temp
;
2492 battery
->chg_temp
= value
.intval
;
2501 static void sec_bat_get_battery_info(
2502 struct sec_battery_info
*battery
)
2504 union power_supply_propval value
;
2505 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
2506 static struct timespec old_ts
;
2507 struct timespec c_ts
;
2508 #if defined(ANDROID_ALARM_ACTIVATED)
2509 c_ts
= ktime_to_timespec(alarm_get_elapsed_realtime());
2511 c_ts
= ktime_to_timespec(ktime_get_boottime());
2515 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2516 POWER_SUPPLY_PROP_VOLTAGE_NOW
, value
);
2517 battery
->voltage_now
= value
.intval
;
2519 value
.intval
= SEC_BATTERY_VOLTAGE_AVERAGE
;
2520 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2521 POWER_SUPPLY_PROP_VOLTAGE_AVG
, value
);
2522 battery
->voltage_avg
= value
.intval
;
2524 value
.intval
= SEC_BATTERY_VOLTAGE_OCV
;
2525 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2526 POWER_SUPPLY_PROP_VOLTAGE_AVG
, value
);
2527 battery
->voltage_ocv
= value
.intval
;
2529 value
.intval
= SEC_BATTERY_CURRENT_MA
;
2530 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2531 POWER_SUPPLY_PROP_CURRENT_NOW
, value
);
2532 battery
->current_now
= value
.intval
;
2534 value
.intval
= SEC_BATTERY_CURRENT_MA
;
2535 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2536 POWER_SUPPLY_PROP_CURRENT_AVG
, value
);
2537 battery
->current_avg
= value
.intval
;
2539 /* input current limit in charger */
2540 psy_do_property(battery
->pdata
->charger_name
, get
,
2541 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
2542 battery
->current_max
= value
.intval
;
2544 sec_bat_get_temperature_info(battery
);
2546 /* To get SOC value (NOT raw SOC), need to reset value */
2548 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2549 POWER_SUPPLY_PROP_CAPACITY
, value
);
2550 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
2551 /* if the battery status was full, and SOC wasn't 100% yet,
2552 then ignore FG SOC, and report (previous SOC +1)% */
2553 if (battery
->status
!= POWER_SUPPLY_STATUS_FULL
) {
2554 battery
->capacity
= value
.intval
;
2555 } else if ((c_ts
.tv_sec
- old_ts
.tv_sec
) >= 30) {
2556 if (battery
->capacity
!= 100) {
2557 battery
->capacity
++;
2558 pr_info("%s : forced full-charged sequence for the capacity(%d)\n",
2559 __func__
, battery
->capacity
);
2562 if (value
.intval
>= battery
->pdata
->full_condition_soc
&&
2563 battery
->voltage_now
>= (battery
->pdata
->recharge_condition_vcell
- 50)) {
2564 /* update capacity max */
2565 value
.intval
= battery
->capacity
;
2566 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
2567 POWER_SUPPLY_PROP_CHARGE_FULL
, value
);
2572 battery
->capacity
= value
.intval
;
2575 if (battery
->capacity
> 5 && battery
->ignore_siop
&&
2576 (battery
->r_siop_level
!= battery
->siop_level
)) {
2577 battery
->siop_level
= battery
->r_siop_level
;
2578 battery
->ignore_siop
= false;
2579 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
)
2580 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
,
2581 msecs_to_jiffies(1200));
2583 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
, 0);
2586 #if !defined(CONFIG_SEC_FACTORY)
2587 if (battery
->capacity
> 5 && battery
->ignore_store_mode
) {
2588 battery
->ignore_store_mode
= false;
2589 value
.intval
= battery
->store_mode
;
2590 psy_do_property(battery
->pdata
->charger_name
, set
,
2591 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
, value
);
2595 dev_info(battery
->dev
,
2596 "%s:Vnow(%dmV),Inow(%dmA),Imax(%dmA),SOC(%d%%),Tbat(%d),Tchg(%d),is_hc_usb(%d)\n",
2598 battery
->voltage_now
, battery
->current_now
,
2599 battery
->current_max
, battery
->capacity
,
2600 battery
->temperature
, battery
->chg_temp
, battery
->is_hc_usb
);
2601 dev_dbg(battery
->dev
,
2602 "%s,Vavg(%dmV),Vocv(%dmV),Tamb(%d),"
2603 "Iavg(%dmA),Iadc(%d)\n",
2604 battery
->present
? "Connected" : "Disconnected",
2605 battery
->voltage_avg
, battery
->voltage_ocv
,
2606 battery
->temper_amb
,
2607 battery
->current_avg
, battery
->current_adc
);
2610 static void sec_bat_polling_work(struct work_struct
*work
)
2612 struct sec_battery_info
*battery
= container_of(
2613 work
, struct sec_battery_info
, polling_work
.work
);
2615 wake_lock(&battery
->monitor_wake_lock
);
2616 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
2617 dev_dbg(battery
->dev
, "%s: Activated\n", __func__
);
2620 static void sec_bat_program_alarm(
2621 struct sec_battery_info
*battery
, int seconds
)
2623 #if defined(ANDROID_ALARM_ACTIVATED)
2624 ktime_t low_interval
= ktime_set(seconds
, 0);
2625 ktime_t slack
= ktime_set(10, 0);
2628 next
= ktime_add(battery
->last_poll_time
, low_interval
);
2629 alarm_start_range(&battery
->polling_alarm
,
2630 next
, ktime_add(next
, slack
));
2632 alarm_start(&battery
->polling_alarm
,
2633 ktime_add(battery
->last_poll_time
, ktime_set(seconds
, 0)));
2637 static unsigned int sec_bat_get_polling_time(
2638 struct sec_battery_info
*battery
)
2640 if (battery
->status
==
2641 POWER_SUPPLY_STATUS_FULL
)
2642 battery
->polling_time
=
2643 battery
->pdata
->polling_time
[
2644 POWER_SUPPLY_STATUS_CHARGING
];
2646 battery
->polling_time
=
2647 battery
->pdata
->polling_time
[
2650 battery
->polling_short
= true;
2652 switch (battery
->status
) {
2653 case POWER_SUPPLY_STATUS_CHARGING
:
2654 if (battery
->polling_in_sleep
)
2655 battery
->polling_short
= false;
2657 case POWER_SUPPLY_STATUS_DISCHARGING
:
2658 if (battery
->polling_in_sleep
&& (battery
->ps_enable
!= true)) {
2659 battery
->polling_time
=
2660 battery
->pdata
->polling_time
[
2661 SEC_BATTERY_POLLING_TIME_SLEEP
];
2663 battery
->polling_time
=
2664 battery
->pdata
->polling_time
[
2666 battery
->polling_short
= false;
2668 case POWER_SUPPLY_STATUS_FULL
:
2669 if (battery
->polling_in_sleep
) {
2670 if (!(battery
->pdata
->full_condition_type
&
2671 SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL
) &&
2672 battery
->charging_mode
==
2673 SEC_BATTERY_CHARGING_NONE
) {
2674 battery
->polling_time
=
2675 battery
->pdata
->polling_time
[
2676 SEC_BATTERY_POLLING_TIME_SLEEP
];
2678 battery
->polling_short
= false;
2680 if (battery
->charging_mode
==
2681 SEC_BATTERY_CHARGING_NONE
)
2682 battery
->polling_short
= false;
2687 if (battery
->polling_short
)
2688 return battery
->pdata
->polling_time
[
2689 SEC_BATTERY_POLLING_TIME_BASIC
];
2690 /* set polling time to 46s to reduce current noise on wc */
2691 else if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
&&
2692 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
)
2693 battery
->polling_time
= 46;
2695 return battery
->polling_time
;
2698 static bool sec_bat_is_short_polling(
2699 struct sec_battery_info
*battery
)
2701 /* Change the full and short monitoring sequence
2702 * Originally, full monitoring was the last time of polling_count
2703 * But change full monitoring to first time
2704 * because temperature check is too late
2706 if (!battery
->polling_short
|| battery
->polling_count
== 1)
2712 static void sec_bat_update_polling_count(
2713 struct sec_battery_info
*battery
)
2715 /* do NOT change polling count in sleep
2716 * even though it is short polling
2717 * to keep polling count along sleep/wakeup
2719 if (battery
->polling_short
&& battery
->polling_in_sleep
)
2722 if (battery
->polling_short
&&
2723 ((battery
->polling_time
/
2724 battery
->pdata
->polling_time
[
2725 SEC_BATTERY_POLLING_TIME_BASIC
])
2726 > battery
->polling_count
))
2727 battery
->polling_count
++;
2729 battery
->polling_count
= 1; /* initial value = 1 */
2732 static void sec_bat_set_polling(
2733 struct sec_battery_info
*battery
)
2735 unsigned int polling_time_temp
;
2737 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
2739 polling_time_temp
= sec_bat_get_polling_time(battery
);
2741 dev_dbg(battery
->dev
,
2742 "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n",
2743 __func__
, sec_bat_status_str
[battery
->status
],
2744 battery
->polling_in_sleep
? "Yes" : "No",
2745 (battery
->charging_mode
==
2746 SEC_BATTERY_CHARGING_NONE
) ? "No" : "Yes",
2747 battery
->polling_short
? "Yes" : "No");
2748 dev_dbg(battery
->dev
,
2749 "%s: Polling time %d/%d sec.\n", __func__
,
2750 battery
->polling_short
?
2751 (polling_time_temp
* battery
->polling_count
) :
2752 polling_time_temp
, battery
->polling_time
);
2754 /* To sync with log above,
2755 * change polling count after log is displayed
2756 * Do NOT update polling count in initial monitor
2758 if (!battery
->pdata
->monitor_initial_count
)
2759 sec_bat_update_polling_count(battery
);
2761 dev_dbg(battery
->dev
,
2762 "%s: Initial monitor %d times left.\n", __func__
,
2763 battery
->pdata
->monitor_initial_count
);
2765 switch (battery
->pdata
->polling_type
) {
2766 case SEC_BATTERY_MONITOR_WORKQUEUE
:
2767 if (battery
->pdata
->monitor_initial_count
) {
2768 battery
->pdata
->monitor_initial_count
--;
2769 schedule_delayed_work(&battery
->polling_work
, HZ
);
2771 schedule_delayed_work(&battery
->polling_work
,
2772 polling_time_temp
* HZ
);
2774 case SEC_BATTERY_MONITOR_ALARM
:
2775 #if defined(ANDROID_ALARM_ACTIVATED)
2776 battery
->last_poll_time
= alarm_get_elapsed_realtime();
2778 battery
->last_poll_time
= ktime_get_boottime();
2781 if (battery
->pdata
->monitor_initial_count
) {
2782 battery
->pdata
->monitor_initial_count
--;
2783 sec_bat_program_alarm(battery
, 1);
2785 sec_bat_program_alarm(battery
, polling_time_temp
);
2787 case SEC_BATTERY_MONITOR_TIMER
:
2792 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
2794 #if defined(CONFIG_BATTERY_SWELLING)
2795 static void sec_bat_swelling_fullcharged_check(struct sec_battery_info
*battery
)
2797 union power_supply_propval value
= {0, };
2799 switch (battery
->pdata
->full_check_type_2nd
) {
2800 case SEC_BATTERY_FULLCHARGED_FG_CURRENT
:
2801 if (battery
->pdata
->swelling_full_check_current_2nd
> 0) {
2802 if ((battery
->current_now
> 0 && battery
->current_now
<
2803 battery
->pdata
->charging_current
[
2804 battery
->cable_type
].full_check_current_1st
) &&
2805 (battery
->current_avg
> 0 && battery
->current_avg
<
2806 battery
->pdata
->swelling_full_check_current_2nd
) &&
2807 ((battery
->pdata
->swelling_drop_float_voltage
- 100) < battery
->voltage_now
)) {
2808 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2811 if ((battery
->current_now
> 0 && battery
->current_now
<
2812 battery
->pdata
->charging_current
[
2813 battery
->cable_type
].full_check_current_1st
) &&
2814 (battery
->current_avg
> 0 && battery
->current_avg
<
2815 battery
->pdata
->charging_current
[
2816 battery
->cable_type
].full_check_current_2nd
) &&
2817 ((battery
->pdata
->swelling_drop_float_voltage
- 100) < battery
->voltage_now
)) {
2818 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
2823 psy_do_property(battery
->pdata
->charger_name
, get
,
2824 POWER_SUPPLY_PROP_STATUS
, value
);
2828 if (value
.intval
== POWER_SUPPLY_STATUS_FULL
) {
2829 battery
->swelling_full_check_cnt
++;
2830 pr_info("%s: Swelling mode full-charged check (%d)\n",
2831 __func__
, battery
->swelling_full_check_cnt
);
2833 battery
->swelling_full_check_cnt
= 0;
2835 if (battery
->swelling_full_check_cnt
>=
2836 battery
->pdata
->full_check_count
) {
2837 battery
->swelling_full_check_cnt
= 0;
2838 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
2839 battery
->is_recharging
= false;
2840 sec_bat_set_charge(battery
, false);
2841 battery
->expired_time
= battery
->pdata
->expired_time
;
2842 battery
->prev_safety_time
= 0;
2847 static void sec_bat_calculate_safety_time(struct sec_battery_info
*battery
)
2849 unsigned long expired_time
= battery
->expired_time
;
2850 struct timespec ts
= {0, };
2852 int input_power
= battery
->current_max
* battery
->input_voltage
* 1000;
2853 int charging_power
= battery
->charging_current
* battery
->pdata
->swelling_normal_float_voltage
;
2855 if (battery
->lcd_status
&& battery
->stop_timer
) {
2856 battery
->prev_safety_time
= 0;
2860 get_monotonic_boottime(&ts
);
2862 if (battery
->prev_safety_time
== 0) {
2863 battery
->prev_safety_time
= ts
.tv_sec
;
2866 if (input_power
> charging_power
) {
2867 curr
= battery
->charging_current
;
2869 curr
= input_power
/ battery
->pdata
->swelling_normal_float_voltage
;
2870 curr
= (curr
* 9) / 10;
2873 if (battery
->lcd_status
&& !battery
->stop_timer
) {
2874 battery
->stop_timer
= true;
2875 } else if (!battery
->lcd_status
&& battery
->stop_timer
) {
2876 battery
->stop_timer
= false;
2879 pr_info("%s : EXPIRED_TIME(%ld), IP(%d), CP(%d), CURR(%d), STANDARD(%d)\n",
2880 __func__
, expired_time
, input_power
, charging_power
, curr
, battery
->pdata
->standard_curr
);
2882 /* We don't need to calculate the safety timer if charge current is 0 */
2884 /* Update the prev_safety_time if the expired_time is still max */
2885 if(battery
->expired_time
== battery
->pdata
->expired_time
) {
2886 battery
->prev_safety_time
= ts
.tv_sec
;
2891 expired_time
= (expired_time
* battery
->pdata
->standard_curr
) / curr
;
2893 pr_info("%s : CAL_EXPIRED_TIME(%ld) TIME NOW(%ld) TIME PREV(%ld)\n", __func__
, expired_time
, ts
.tv_sec
, battery
->prev_safety_time
);
2895 if (expired_time
<= ((ts
.tv_sec
- battery
->prev_safety_time
) * 100))
2898 expired_time
-= ((ts
.tv_sec
- battery
->prev_safety_time
) * 100);
2900 battery
->cal_safety_time
= expired_time
;
2901 expired_time
= (expired_time
* curr
) / battery
->pdata
->standard_curr
;
2903 battery
->expired_time
= expired_time
;
2904 battery
->prev_safety_time
= ts
.tv_sec
;
2905 pr_info("%s : REMAIN_TIME(%ld) CAL_REMAIN_TIME(%ld)\n", __func__
, battery
->expired_time
, battery
->cal_safety_time
);
2908 #if defined(CONFIG_CALC_TIME_TO_FULL)
2909 static void sec_bat_calc_time_to_full(struct sec_battery_info
* battery
)
2911 if (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) {
2912 union power_supply_propval value
;
2913 int input
= battery
->pdata
->charging_current
[battery
->cable_type
].input_current_limit
;
2914 int charge
= battery
->pdata
->charging_current
[battery
->cable_type
].fast_charging_current
;
2915 if ((battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
) ||
2916 (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
) ||
2917 (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
)) {
2918 value
.intval
= charge
;
2919 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
2920 value
.intval
= battery
->current_max
+ 100;
2921 } else if (input
== battery
->current_max
) {
2922 if (input
== 1800) // TA cannot charge 2100
2923 value
.intval
= 1950;
2925 value
.intval
= charge
- 50;
2927 value
.intval
= battery
->current_max
+ 100;
2929 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
2930 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW
, value
);
2931 dev_info(battery
->dev
, "%s: T: %5d sec, passed time: %5ld\n",
2932 __func__
, value
.intval
, battery
->charging_passed_time
);
2933 battery
->timetofull
= value
.intval
;
2935 battery
->timetofull
= -1;
2939 static void sec_bat_time_to_full_work(struct work_struct
*work
)
2941 struct sec_battery_info
*battery
= container_of(work
,
2942 struct sec_battery_info
, timetofull_work
.work
);
2943 union power_supply_propval value
;
2944 psy_do_property(battery
->pdata
->charger_name
, get
,
2945 POWER_SUPPLY_PROP_CURRENT_MAX
, value
);
2946 battery
->current_max
= value
.intval
;
2947 sec_bat_calc_time_to_full(battery
);
2948 battery
->complete_timetofull
= true;
2949 dev_info(battery
->dev
, "%s: \n",__func__
);
2950 if (battery
->voltage_now
> 0)
2951 battery
->voltage_now
--;
2952 power_supply_changed(&battery
->psy_bat
);
2956 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
2957 static void sec_bat_cc_cv_mode_check(struct sec_battery_info
*battery
)
2959 union power_supply_propval value
;
2961 if ((battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) &&
2962 (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
) &&
2963 (battery
->capacity
>= battery
->pdata
->wireless_cc_cv
) &&
2964 !battery
->cc_cv_mode
&&
2965 (battery
->charging_passed_time
> 5)) {
2966 pr_info("%s changed wireless vout voltage to default value \n",__func__
);
2967 battery
->cc_cv_mode
= 1;
2969 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
2970 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
2975 static void sec_bat_siop_work(struct work_struct
*work
)
2977 struct sec_battery_info
*battery
= container_of(work
,
2978 struct sec_battery_info
, siop_work
.work
);
2979 union power_supply_propval value
;
2981 value
.intval
= battery
->siop_level
;
2982 pr_info("%s : set current by siop level(%d)\n",__func__
, battery
->siop_level
);
2983 psy_do_property(battery
->pdata
->charger_name
, set
,
2984 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN
, value
);
2986 #if !defined(CONFIG_SEC_FACTORY)
2987 if (battery
->pdata
->chg_temp_check
)
2988 sec_bat_chg_temperature_check(battery
);
2991 wake_unlock(&battery
->siop_wake_lock
);
2994 static void sec_bat_monitor_work(
2995 struct work_struct
*work
)
2997 struct sec_battery_info
*battery
=
2998 container_of(work
, struct sec_battery_info
,
3000 static struct timespec old_ts
;
3001 struct timespec c_ts
;
3003 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
3004 #if defined(ANDROID_ALARM_ACTIVATED)
3005 c_ts
= ktime_to_timespec(alarm_get_elapsed_realtime());
3007 c_ts
= ktime_to_timespec(ktime_get_boottime());
3010 /* monitor once after wakeup */
3011 if (battery
->polling_in_sleep
) {
3012 battery
->polling_in_sleep
= false;
3013 if ((battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
) &&
3014 (battery
->ps_enable
!= true)) {
3015 if ((unsigned long)(c_ts
.tv_sec
- old_ts
.tv_sec
) < 10 * 60) {
3016 union power_supply_propval value
;
3018 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3019 POWER_SUPPLY_PROP_VOLTAGE_NOW
, value
);
3020 battery
->voltage_now
= value
.intval
;
3021 sec_bat_get_temperature_info(battery
);
3022 power_supply_changed(&battery
->psy_bat
);
3023 pr_info("Skip monitor work(%ld, Vnow:%dmV, Tbat:%d)\n",
3024 c_ts
.tv_sec
- old_ts
.tv_sec
, battery
->voltage_now
, battery
->temperature
);
3030 /* update last monitor time */
3033 sec_bat_get_battery_info(battery
);
3035 #if defined(CONFIG_CALC_TIME_TO_FULL)
3036 /* time to full check */
3037 sec_bat_calc_time_to_full(battery
);
3040 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
3041 sec_bat_cc_cv_mode_check(battery
);
3045 if (battery
->test_mode
) {
3046 dev_err(battery
->dev
, "%s: Test Mode\n", __func__
);
3047 sec_bat_do_test_function(battery
);
3048 if (battery
->test_mode
!= 0)
3049 goto continue_monitor
;
3052 /* 1. battery check */
3053 if (!sec_bat_battery_cable_check(battery
))
3054 goto continue_monitor
;
3056 /* 2. voltage check */
3057 if (!sec_bat_voltage_check(battery
))
3058 goto continue_monitor
;
3060 /* monitor short routine in initial monitor */
3061 if (battery
->pdata
->monitor_initial_count
||
3062 sec_bat_is_short_polling(battery
))
3063 goto continue_monitor
;
3065 /* 3. time management */
3066 if (!sec_bat_time_management(battery
))
3067 goto continue_monitor
;
3069 /* 4. temperature check */
3070 if (!sec_bat_temperature_check(battery
))
3071 goto continue_monitor
;
3073 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
3074 sec_bat_discharging_check(battery
);
3077 #if defined(CONFIG_BATTERY_SWELLING)
3078 sec_bat_swelling_check(battery
, battery
->temperature
);
3079 set_swelling_current(battery
);
3081 if (battery
->swelling_mode
&& !battery
->charging_block
)
3082 sec_bat_swelling_fullcharged_check(battery
);
3084 sec_bat_fullcharged_check(battery
);
3086 /* 5. full charging check */
3087 sec_bat_fullcharged_check(battery
);
3088 #endif /* CONFIG_BATTERY_SWELLING */
3090 /* 6. additional check */
3091 if (battery
->pdata
->monitor_additional_check
)
3092 battery
->pdata
->monitor_additional_check();
3094 #if !defined(CONFIG_SEC_FACTORY)
3095 /* 7. charger temperature check */
3096 if (battery
->pdata
->chg_temp_check
)
3097 sec_bat_chg_temperature_check(battery
);
3102 /* calculate safety time */
3103 if (!battery
->charging_block
)
3104 sec_bat_calculate_safety_time(battery
);
3107 #if defined(CONFIG_AFC_CHARGER_MODE)
3108 dev_info(battery
->dev
,
3109 "%s: Status(%s), mode(%s), Health(%s), Cable(%d,%d), level(%d%%), HV(%s), Cycle(%d)\n",
3111 sec_bat_status_str
[battery
->status
],
3112 sec_bat_charging_mode_str
[battery
->charging_mode
],
3113 sec_bat_health_str
[battery
->health
],
3114 battery
->cable_type
, battery
->muic_cable_type
, battery
->siop_level
,
3115 battery
->hv_chg_name
, battery
->batt_cycle
);
3117 dev_info(battery
->dev
,
3118 "%s: Status(%s), mode(%s), Health(%s), Cable(%d,%d), level(%d%%), Cycle(%d)\n",
3120 sec_bat_status_str
[battery
->status
],
3121 sec_bat_charging_mode_str
[battery
->charging_mode
],
3122 sec_bat_health_str
[battery
->health
],
3123 battery
->cable_type
, battery
->muic_cable_type
, battery
->siop_level
, battery
->batt_cycle
);
3125 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
3126 dev_info(battery
->dev
,
3127 "%s: battery->stability_test(%d), battery->eng_not_full_status(%d)\n",
3128 __func__
, battery
->stability_test
, battery
->eng_not_full_status
);
3130 if (battery
->store_mode
&& !lpcharge
&& (battery
->cable_type
!= POWER_SUPPLY_TYPE_BATTERY
)) {
3132 dev_info(battery
->dev
,
3133 "%s: @battery->capacity = (%d), battery->status= (%d), battery->store_mode=(%d)\n",
3134 __func__
, battery
->capacity
, battery
->status
, battery
->store_mode
);
3136 if ((battery
->capacity
>= STORE_MODE_CHARGING_MAX
) && (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
)) {
3137 sec_bat_set_charging_status(battery
,
3138 POWER_SUPPLY_STATUS_DISCHARGING
);
3139 sec_bat_set_charge(battery
, false);
3141 if ((battery
->capacity
<= STORE_MODE_CHARGING_MIN
) && (battery
->status
== POWER_SUPPLY_STATUS_DISCHARGING
)) {
3142 sec_bat_set_charging_status(battery
,
3143 POWER_SUPPLY_STATUS_CHARGING
);
3144 if (battery
->siop_level
!= 100)
3145 battery
->stop_timer
= true;
3146 sec_bat_set_charge(battery
, true);
3149 power_supply_changed(&battery
->psy_bat
);
3152 sec_bat_set_polling(battery
);
3154 if (battery
->capacity
<= 0 || battery
->health_change
)
3155 wake_lock_timeout(&battery
->monitor_wake_lock
, HZ
* 5);
3157 wake_unlock(&battery
->monitor_wake_lock
);
3159 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
3164 #if defined(ANDROID_ALARM_ACTIVATED)
3165 static void sec_bat_alarm(struct alarm
*alarm
)
3167 static enum alarmtimer_restart
sec_bat_alarm(
3168 struct alarm
*alarm
, ktime_t now
)
3172 struct sec_battery_info
*battery
= container_of(alarm
,
3173 struct sec_battery_info
, polling_alarm
);
3175 dev_dbg(battery
->dev
,
3178 /* In wake up, monitor work will be queued in complete function
3179 * To avoid duplicated queuing of monitor work,
3180 * do NOT queue monitor work in wake up by polling alarm
3182 if (!battery
->polling_in_sleep
) {
3183 wake_lock(&battery
->monitor_wake_lock
);
3184 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
3185 dev_dbg(battery
->dev
, "%s: Activated\n", __func__
);
3187 #if !defined(ANDROID_ALARM_ACTIVATED)
3188 return ALARMTIMER_NORESTART
;
3193 static void sec_bat_cable_work(struct work_struct
*work
)
3195 struct sec_battery_info
*battery
= container_of(work
,
3196 struct sec_battery_info
, cable_work
.work
);
3197 union power_supply_propval val
;
3198 int wl_cur
, wr_cur
, current_cable_type
;
3199 bool keep_charging_state
= false;
3201 dev_info(battery
->dev
, "%s: Start\n", __func__
);
3203 wl_cur
= battery
->pdata
->charging_current
[
3204 POWER_SUPPLY_TYPE_WIRELESS
].input_current_limit
;
3205 wr_cur
= battery
->pdata
->charging_current
[
3206 battery
->wire_status
].input_current_limit
;
3207 if (battery
->wc_status
&& battery
->wc_enable
&&
3209 current_cable_type
= POWER_SUPPLY_TYPE_WIRELESS
;
3211 current_cable_type
= battery
->wire_status
;
3213 if ((current_cable_type
== battery
->cable_type
) && !battery
->slate_mode
) {
3214 dev_dbg(battery
->dev
,
3215 "%s: Cable is NOT Changed(%d)\n",
3216 __func__
, battery
->cable_type
);
3217 /* Do NOT activate cable work for NOT changed */
3218 goto end_of_cable_work
;
3221 #if defined(CONFIG_BATTERY_SWELLING)
3222 if (current_cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
3223 battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
3224 battery
->swelling_mode
= false;
3225 /* restore 4.4V float voltage */
3226 val
.intval
= battery
->pdata
->swelling_normal_float_voltage
;
3227 psy_do_property(battery
->pdata
->charger_name
, set
,
3228 POWER_SUPPLY_PROP_VOLTAGE_MAX
, val
);
3229 pr_info("%s: float voltage = %d\n", __func__
, val
.intval
);
3231 pr_info("%s: skip float_voltage setting, swelling_mode(%d)\n",
3232 __func__
, battery
->swelling_mode
);
3236 if (battery
->charging_block
&&
3237 ((battery
->cable_type
!= POWER_SUPPLY_TYPE_BATTERY
&& current_cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) ||
3238 (current_cable_type
!= POWER_SUPPLY_TYPE_BATTERY
&& battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) ||
3239 (current_cable_type
!= POWER_SUPPLY_TYPE_BATTERY
&& battery
->cable_type
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
) ||
3240 (current_cable_type
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
) || battery
->swelling_mode
)) {
3241 keep_charging_state
= true;
3242 pr_info("%s: keep charging state (prev cable type:%d, now cable type:%d, swelling_mode:%d)\n",
3243 __func__
, battery
->cable_type
, current_cable_type
, battery
->swelling_mode
);
3246 battery
->cable_type
= current_cable_type
;
3247 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
)
3248 power_supply_changed(&battery
->psy_bat
);
3250 if (battery
->pdata
->check_cable_result_callback
)
3251 battery
->pdata
->check_cable_result_callback(
3252 battery
->cable_type
);
3253 /* platform can NOT get information of cable connection
3254 * because wakeup time is too short to check uevent
3255 * To make sure that target is wakeup
3256 * if cable is connected and disconnected,
3257 * activated wake lock in a few seconds
3259 wake_lock_timeout(&battery
->vbus_wake_lock
, HZ
* 10);
3261 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
3262 ((battery
->pdata
->cable_check_type
&
3263 SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE
) &&
3264 battery
->cable_type
== POWER_SUPPLY_TYPE_UNKNOWN
)) {
3265 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
3266 battery
->is_recharging
= false;
3267 sec_bat_set_charging_status(battery
,
3268 POWER_SUPPLY_STATUS_DISCHARGING
);
3269 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
3270 #if defined(CONFIG_CALC_TIME_TO_FULL)
3271 battery
->complete_timetofull
= false;
3272 cancel_delayed_work(&battery
->timetofull_work
);
3274 if (sec_bat_set_charge(battery
, false))
3275 goto end_of_cable_work
;
3276 } else if (battery
->slate_mode
== true) {
3277 sec_bat_set_charging_status(battery
,
3278 POWER_SUPPLY_STATUS_DISCHARGING
);
3279 battery
->cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
3282 psy_do_property(battery
->pdata
->charger_name
, set
,
3283 POWER_SUPPLY_PROP_CURRENT_NOW
, val
);
3285 dev_info(battery
->dev
,
3286 "%s:slate mode on\n",__func__
);
3288 if (sec_bat_set_charge(battery
, false))
3289 goto end_of_cable_work
;
3291 #if defined(CONFIG_EN_OOPS)
3292 val
.intval
= battery
->cable_type
;
3293 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
3294 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN
, val
);
3296 /* Do NOT display the charging icon when OTG or HMT_CONNECTED is enabled */
3297 if (battery
->cable_type
== POWER_SUPPLY_TYPE_OTG
) {
3298 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
3299 sec_bat_set_charging_status(battery
,
3300 POWER_SUPPLY_STATUS_DISCHARGING
);
3302 if (!keep_charging_state
) {
3303 if (battery
->pdata
->full_check_type
!=
3304 SEC_BATTERY_FULLCHARGED_NONE
)
3305 battery
->charging_mode
=
3306 SEC_BATTERY_CHARGING_1ST
;
3308 battery
->charging_mode
=
3309 SEC_BATTERY_CHARGING_2ND
;
3312 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
)
3313 sec_bat_set_charging_status(battery
,
3314 POWER_SUPPLY_STATUS_FULL
);
3315 else if (!keep_charging_state
)
3316 sec_bat_set_charging_status(battery
,
3317 POWER_SUPPLY_STATUS_CHARGING
);
3319 if (!keep_charging_state
) {
3320 if (sec_bat_set_charge(battery
, true))
3321 goto end_of_cable_work
;
3324 if (battery
->siop_level
!= 100)
3325 battery
->stop_timer
= true;
3328 if (battery
->status
!= POWER_SUPPLY_STATUS_DISCHARGING
) {
3329 battery
->input_voltage
=
3330 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
? 9 : 5;
3332 #if defined(CONFIG_CALC_TIME_TO_FULL)
3333 if ((battery
->cable_type
!= POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
) &&
3334 (current_cable_type
!= POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
))
3335 battery
->complete_timetofull
= false;
3336 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->timetofull_work
,
3337 msecs_to_jiffies(4000));
3339 #if defined(ANDROID_ALARM_ACTIVATED)
3340 /* No need for wakelock in Alarm */
3341 if (battery
->pdata
->polling_type
!= SEC_BATTERY_MONITOR_ALARM
)
3342 wake_lock(&battery
->vbus_wake_lock
);
3346 /* polling time should be reset when cable is changed
3347 * polling_in_sleep should be reset also
3348 * before polling time is re-calculated
3349 * to prevent from counting 1 for events
3350 * right after cable is connected
3352 battery
->polling_in_sleep
= false;
3353 sec_bat_get_polling_time(battery
);
3355 dev_info(battery
->dev
,
3356 "%s: Status:%s, Sleep:%s, Charging:%s, Short Poll:%s\n",
3357 __func__
, sec_bat_status_str
[battery
->status
],
3358 battery
->polling_in_sleep
? "Yes" : "No",
3359 (battery
->charging_mode
==
3360 SEC_BATTERY_CHARGING_NONE
) ? "No" : "Yes",
3361 battery
->polling_short
? "Yes" : "No");
3362 dev_info(battery
->dev
,
3363 "%s: Polling time is reset to %d sec.\n", __func__
,
3364 battery
->polling_time
);
3366 battery
->polling_count
= 1; /* initial value = 1 */
3368 wake_lock(&battery
->monitor_wake_lock
);
3369 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
3371 wake_unlock(&battery
->cable_wake_lock
);
3372 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
3375 ssize_t
sec_bat_show_attrs(struct device
*dev
,
3376 struct device_attribute
*attr
, char *buf
)
3378 struct power_supply
*psy
= dev_get_drvdata(dev
);
3379 struct sec_battery_info
*battery
=
3380 container_of(psy
, struct sec_battery_info
, psy_bat
);
3381 const ptrdiff_t offset
= attr
- sec_battery_attrs
;
3382 union power_supply_propval value
;
3386 case BATT_RESET_SOC
:
3388 case BATT_READ_RAW_SOC
:
3390 union power_supply_propval value
;
3393 SEC_FUELGAUGE_CAPACITY_TYPE_RAW
;
3394 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3395 POWER_SUPPLY_PROP_CAPACITY
, value
);
3397 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3401 case BATT_READ_ADJ_SOC
:
3404 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%s\n",
3405 battery
->pdata
->vendor
);
3408 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3409 battery
->voltage_ocv
);
3412 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3413 battery
->inbat_adc
);
3415 case BATT_VOL_ADC_CAL
:
3419 case BATT_VOL_ADC_AVER
:
3422 case BATT_CURRENT_UA_NOW
:
3424 union power_supply_propval value
;
3426 value
.intval
= SEC_BATTERY_CURRENT_UA
;
3427 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3428 POWER_SUPPLY_PROP_CURRENT_NOW
, value
);
3430 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3434 case BATT_CURRENT_UA_AVG
:
3436 union power_supply_propval value
;
3438 value
.intval
= SEC_BATTERY_CURRENT_UA
;
3439 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3440 POWER_SUPPLY_PROP_CURRENT_AVG
, value
);
3442 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3448 switch (battery
->pdata
->thermal_source
) {
3449 case SEC_BATTERY_THERMAL_SOURCE_FG
:
3450 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3451 POWER_SUPPLY_PROP_TEMP
, value
);
3453 case SEC_BATTERY_THERMAL_SOURCE_CALLBACK
:
3454 if (battery
->pdata
->get_temperature_callback
) {
3455 battery
->pdata
->get_temperature_callback(
3456 POWER_SUPPLY_PROP_TEMP
, &value
);
3459 case SEC_BATTERY_THERMAL_SOURCE_ADC
:
3460 sec_bat_get_temperature_by_adc(battery
,
3461 SEC_BAT_ADC_CHANNEL_TEMP
, &value
);
3466 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3471 If F/G is used for reading the temperature and
3472 compensation table is used,
3473 the raw value that isn't compensated can be read by
3474 POWER_SUPPLY_PROP_TEMP_AMBIENT
3476 switch (battery
->pdata
->thermal_source
) {
3477 case SEC_BATTERY_THERMAL_SOURCE_FG
:
3478 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3479 POWER_SUPPLY_PROP_TEMP_AMBIENT
, value
);
3480 battery
->temp_adc
= value
.intval
;
3485 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3488 case BATT_TEMP_AVER
:
3490 case BATT_TEMP_ADC_AVER
:
3493 #if defined(CONFIG_AFC_CHARGER_MODE)
3494 sec_bat_get_temperature_by_adc(battery
,
3495 SEC_BAT_ADC_CHANNEL_CHG_TEMP
, &value
);
3496 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3499 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3504 #if defined(CONFIG_AFC_CHARGER_MODE)
3505 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3506 battery
->chg_temp_adc
);
3508 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3514 case BATT_SLATE_MODE
:
3515 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3516 battery
->slate_mode
);
3519 case BATT_LP_CHARGING
:
3521 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3525 case SIOP_ACTIVATED
:
3528 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3529 battery
->siop_level
);
3531 case BATT_CHARGING_SOURCE
:
3532 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3533 battery
->cable_type
);
3541 union power_supply_propval value
;
3544 SEC_BATTERY_CAPACITY_DESIGNED
;
3545 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3546 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3548 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x ",
3552 SEC_BATTERY_CAPACITY_ABSOLUTE
;
3553 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3554 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3556 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x ",
3560 SEC_BATTERY_CAPACITY_TEMPERARY
;
3561 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3562 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3564 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x ",
3568 SEC_BATTERY_CAPACITY_CURRENT
;
3569 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3570 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3572 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "0x%04x\n",
3577 #if defined(CONFIG_INBATTERY)
3578 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3579 POWER_SUPPLY_PROP_ENERGY_FULL
, value
);
3583 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3588 case CHG_CURRENT_ADC
:
3589 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3590 battery
->current_adc
);
3595 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3596 (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
));
3599 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3600 battery
->wc_enable
);
3602 case HV_CHARGER_STATUS
:
3605 if (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS
||
3606 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_ERR
||
3607 battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
)
3609 #if defined(CONFIG_CHARGER_SM5705)
3610 else if (battery
->cable_type
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
)
3613 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", check_val
);
3616 case HV_CHARGER_SET
:
3619 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3620 battery
->factory_mode
);
3623 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3624 battery
->store_mode
);
3629 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3630 battery
->test_mode
);
3633 case BATT_EVENT_CALL
:
3634 case BATT_EVENT_2G_CALL
:
3635 case BATT_EVENT_TALK_GSM
:
3636 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3637 (battery
->event
& EVENT_2G_CALL
) ? 1 : 0);
3639 case BATT_EVENT_3G_CALL
:
3640 case BATT_EVENT_TALK_WCDMA
:
3641 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3642 (battery
->event
& EVENT_3G_CALL
) ? 1 : 0);
3644 case BATT_EVENT_MUSIC
:
3645 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3646 (battery
->event
& EVENT_MUSIC
) ? 1 : 0);
3648 case BATT_EVENT_VIDEO
:
3649 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3650 (battery
->event
& EVENT_VIDEO
) ? 1 : 0);
3652 case BATT_EVENT_BROWSER
:
3653 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3654 (battery
->event
& EVENT_BROWSER
) ? 1 : 0);
3656 case BATT_EVENT_HOTSPOT
:
3657 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3658 (battery
->event
& EVENT_HOTSPOT
) ? 1 : 0);
3660 case BATT_EVENT_CAMERA
:
3661 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3662 (battery
->event
& EVENT_CAMERA
) ? 1 : 0);
3664 case BATT_EVENT_CAMCORDER
:
3665 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3666 (battery
->event
& EVENT_CAMCORDER
) ? 1 : 0);
3668 case BATT_EVENT_DATA_CALL
:
3669 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3670 (battery
->event
& EVENT_DATA_CALL
) ? 1 : 0);
3672 case BATT_EVENT_WIFI
:
3673 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3674 (battery
->event
& EVENT_WIFI
) ? 1 : 0);
3676 case BATT_EVENT_WIBRO
:
3677 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3678 (battery
->event
& EVENT_WIBRO
) ? 1 : 0);
3680 case BATT_EVENT_LTE
:
3681 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3682 (battery
->event
& EVENT_LTE
) ? 1 : 0);
3684 case BATT_EVENT_LCD
:
3685 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3686 (battery
->event
& EVENT_LCD
) ? 1 : 0);
3688 case BATT_EVENT_GPS
:
3689 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3690 (battery
->event
& EVENT_GPS
) ? 1 : 0);
3693 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3696 case BATT_TEMP_TABLE
:
3697 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
,
3698 "%d %d %d %d %d %d %d %d %d %d %d %d\n",
3699 battery
->pdata
->temp_high_threshold_event
,
3700 battery
->pdata
->temp_high_recovery_event
,
3701 battery
->pdata
->temp_low_threshold_event
,
3702 battery
->pdata
->temp_low_recovery_event
,
3703 battery
->pdata
->temp_high_threshold_normal
,
3704 battery
->pdata
->temp_high_recovery_normal
,
3705 battery
->pdata
->temp_low_threshold_normal
,
3706 battery
->pdata
->temp_low_recovery_normal
,
3707 battery
->pdata
->temp_high_threshold_lpm
,
3708 battery
->pdata
->temp_high_recovery_lpm
,
3709 battery
->pdata
->temp_low_threshold_lpm
,
3710 battery
->pdata
->temp_low_recovery_lpm
);
3712 case BATT_HIGH_CURRENT_USB
:
3713 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3714 battery
->is_hc_usb
);
3716 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
3717 case BATT_TEST_CHARGE_CURRENT
:
3719 union power_supply_propval value
;
3721 psy_do_property(battery
->pdata
->charger_name
, get
,
3722 POWER_SUPPLY_PROP_CURRENT_NOW
, value
);
3723 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3728 case BATT_STABILITY_TEST
:
3729 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3730 battery
->stability_test
);
3732 #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX)
3733 case BATT_CAPACITY_MAX
:
3734 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3735 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN
, value
);
3736 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3739 case BATT_INBAT_VOLTAGE
:
3742 ret
= sec_bat_get_inbat_vol_by_adc(battery
);
3743 dev_info(battery
->dev
, "in-battery voltage(%d)\n", ret
);
3744 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3748 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
3749 case BATT_DISCHARGING_CHECK
:
3750 sec_bat_self_discharging_check(battery
);
3751 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3752 battery
->self_discharging
);
3754 case BATT_DISCHARGING_CHECK_ADC
:
3755 sec_bat_self_discharging_check(battery
);
3756 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3757 battery
->self_discharging_adc
);
3759 case BATT_DISCHARGING_NTC
:
3760 sec_bat_self_discharging_ntc_check(battery
);
3761 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3762 battery
->discharging_ntc
);
3764 case BATT_DISCHARGING_NTC_ADC
:
3765 sec_bat_self_discharging_ntc_check(battery
);
3766 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3767 battery
->discharging_ntc_adc
);
3769 case BATT_SELF_DISCHARGING_CONTROL
:
3772 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
3773 case BATT_INBAT_WIRELESS_CS100
:
3774 psy_do_property(battery
->pdata
->wireless_charger_name
, get
,
3775 POWER_SUPPLY_PROP_STATUS
, value
);
3776 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3779 case HMT_TA_CONNECTED
:
3780 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3781 (battery
->cable_type
== POWER_SUPPLY_TYPE_HMT_CONNECTED
) ? 1 : 0);
3784 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n",
3785 (battery
->cable_type
== POWER_SUPPLY_TYPE_HMT_CHARGE
) ? 1 : 0);
3788 value
.intval
= SEC_BATTERY_CAPACITY_CYCLE
;
3789 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3790 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3791 value
.intval
= value
.intval
/ 100;
3792 dev_info(battery
->dev
, "fg cycle(%d)\n", value
.intval
);
3793 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3795 case FG_FULL_VOLTAGE
:
3796 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", battery
->pdata
->chg_float_voltage
);
3800 SEC_BATTERY_CAPACITY_AGEDCELL
;
3801 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
3802 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
3803 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", value
.intval
);
3806 i
+= scnprintf(buf
+ i
, PAGE_SIZE
- i
, "%d\n", battery
->batt_cycle
);
3814 void update_external_temp_table(struct sec_battery_info
*battery
, int temp
[])
3816 battery
->pdata
->temp_high_threshold_event
= temp
[0];
3817 battery
->pdata
->temp_high_recovery_event
= temp
[1];
3818 battery
->pdata
->temp_low_threshold_event
= temp
[2];
3819 battery
->pdata
->temp_low_recovery_event
= temp
[3];
3820 battery
->pdata
->temp_high_threshold_normal
= temp
[4];
3821 battery
->pdata
->temp_high_recovery_normal
= temp
[5];
3822 battery
->pdata
->temp_low_threshold_normal
= temp
[6];
3823 battery
->pdata
->temp_low_recovery_normal
= temp
[7];
3824 battery
->pdata
->temp_high_threshold_lpm
= temp
[8];
3825 battery
->pdata
->temp_high_recovery_lpm
= temp
[9];
3826 battery
->pdata
->temp_low_threshold_lpm
= temp
[10];
3827 battery
->pdata
->temp_low_recovery_lpm
= temp
[11];
3829 if (battery
->pdata
->temp_high_threshold_event
!=
3830 battery
->pdata
->temp_high_threshold_normal
)
3831 battery
->pdata
->event_check
= 1;
3834 ssize_t
sec_bat_store_attrs(
3836 struct device_attribute
*attr
,
3837 const char *buf
, size_t count
)
3839 struct power_supply
*psy
= dev_get_drvdata(dev
);
3840 struct sec_battery_info
*battery
=
3841 container_of(psy
, struct sec_battery_info
, psy_bat
);
3842 const ptrdiff_t offset
= attr
- sec_battery_attrs
;
3847 case BATT_RESET_SOC
:
3848 /* Do NOT reset fuel gauge in charging mode */
3849 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
3850 battery
->cable_type
== POWER_SUPPLY_TYPE_UARTOFF
) {
3851 union power_supply_propval value
;
3852 battery
->voltage_now
= 1234;
3853 battery
->voltage_avg
= 1234;
3854 power_supply_changed(&battery
->psy_bat
);
3857 SEC_FUELGAUGE_CAPACITY_TYPE_RESET
;
3858 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
3859 POWER_SUPPLY_PROP_CAPACITY
, value
);
3860 dev_info(battery
->dev
,"do reset SOC\n");
3861 /* update battery info */
3862 sec_bat_get_battery_info(battery
);
3866 case BATT_READ_RAW_SOC
:
3868 case BATT_READ_ADJ_SOC
:
3876 case BATT_VOL_ADC_CAL
:
3880 case BATT_VOL_ADC_AVER
:
3882 case BATT_CURRENT_UA_NOW
:
3884 case BATT_CURRENT_UA_AVG
:
3890 case BATT_TEMP_AVER
:
3892 case BATT_TEMP_ADC_AVER
:
3900 case BATT_SLATE_MODE
:
3901 if (sscanf(buf
, "%d\n", &x
) == 1) {
3902 union power_supply_propval value
;
3904 battery
->slate_mode
= true;
3905 } else if (x
== 0) {
3906 battery
->slate_mode
= false;
3908 dev_info(battery
->dev
,
3909 "%s: SLATE MODE unknown command\n",
3913 slate_mode_state
= battery
->slate_mode
;
3914 wake_lock(&battery
->cable_wake_lock
);
3915 queue_delayed_work_on(0, battery
->monitor_wqueue
,
3916 &battery
->cable_work
, 0);
3917 if (battery
->slate_mode
) {
3919 psy_do_property(battery
->pdata
->charger_name
, set
,
3920 POWER_SUPPLY_PROP_CURRENT_NOW
,
3922 if (battery
->pdata
->always_enable
)
3923 psy_do_property(battery
->pdata
->charger_name
, set
,
3924 POWER_SUPPLY_PROP_CHARGING_ENABLED
,
3931 case BATT_LP_CHARGING
:
3933 case SIOP_ACTIVATED
:
3936 if (sscanf(buf
, "%d\n", &x
) == 1) {
3939 dev_info(battery
->dev
,
3940 "%s: siop level: %d\n", __func__
, x
);
3941 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
3943 if (x
== battery
->siop_level
&& battery
->capacity
> 5) {
3944 dev_info(battery
->dev
,
3945 "%s: skip same siop level: %d\n", __func__
, x
);
3947 } else if (x
>= 0 && x
<= 100) {
3948 battery
->siop_level
= x
;
3950 battery
->siop_level
= 100;
3953 get_monotonic_boottime(&ts
);
3954 if ((battery
->r_siop_level
!= battery
->siop_level
) &&
3955 (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
||
3956 battery
->status
== POWER_SUPPLY_STATUS_FULL
) &&
3957 !(battery
->charging_block
)) {
3958 if (battery
->siop_level
>= 100) {
3959 battery
->lcd_on_total_time
+= ts
.tv_sec
- battery
->lcd_on_time
;
3960 battery
->lcd_on_time
= 0;
3962 if (!battery
->lcd_on_time
)
3963 battery
->lcd_on_time
= ts
.tv_sec
;
3967 battery
->r_siop_level
= battery
->siop_level
;
3969 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
3970 union power_supply_propval value
;
3971 value
.intval
= battery
->siop_level
;
3972 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
3973 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN
, value
);
3975 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
&&
3976 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&&
3977 !battery
->cc_cv_mode
&&
3978 battery
->siop_level
== 100 ) {
3979 value
.intval
= 0; /* 5.5 */
3980 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
3981 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
3982 } else if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
&&
3983 battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&&
3984 !battery
->cc_cv_mode
&&
3985 battery
->siop_level
!= 100) {
3986 value
.intval
= 1; /* 5 */
3987 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
3988 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
3991 if (battery
->capacity
<= 5) {
3992 battery
->siop_level
= 100;
3993 battery
->ignore_siop
= true;
3994 } else if (battery
->ignore_siop
) {
3995 battery
->ignore_siop
= false;
3998 wake_lock(&battery
->siop_wake_lock
);
4000 if (battery
->cable_type
== POWER_SUPPLY_TYPE_WIRELESS
)
4001 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
,
4002 msecs_to_jiffies(1200));
4004 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->siop_work
, 0);
4009 case BATT_CHARGING_SOURCE
:
4019 case CHG_CURRENT_ADC
:
4026 if (sscanf(buf
, "%d\n", &x
) == 1) {
4028 battery
->wc_enable
= false;
4029 } else if (x
== 1) {
4030 battery
->wc_enable
= true;
4032 dev_info(battery
->dev
,
4033 "%s: WPC ENABLE unknown command\n",
4037 wake_lock(&battery
->cable_wake_lock
);
4038 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4039 &battery
->cable_work
, 0);
4043 case HV_CHARGER_STATUS
:
4045 case HV_CHARGER_SET
:
4046 if (sscanf(buf
, "%d\n", &x
) == 1) {
4047 dev_info(battery
->dev
,
4048 "%s: HV_CHARGER_SET(%d)\n", __func__
, x
);
4050 battery
->wire_status
= POWER_SUPPLY_TYPE_HV_MAINS
;
4051 wake_lock(&battery
->cable_wake_lock
);
4052 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4054 battery
->wire_status
= POWER_SUPPLY_TYPE_BATTERY
;
4055 wake_lock(&battery
->cable_wake_lock
);
4056 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4062 if (sscanf(buf
, "%d\n", &x
) == 1) {
4063 battery
->factory_mode
= x
? true : false;
4068 if (sscanf(buf
, "%d\n", &x
) == 1) {
4070 battery
->store_mode
= true;
4071 #if !defined(CONFIG_SEC_FACTORY)
4072 if (battery
->capacity
<= 5) {
4073 battery
->ignore_store_mode
= true;
4075 union power_supply_propval value
;
4076 value
.intval
= battery
->store_mode
;
4077 psy_do_property(battery
->pdata
->charger_name
, set
,
4078 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
, value
);
4086 if (sscanf(buf
, "%d\n", &x
) == 1) {
4087 #ifdef CONFIG_FUELGAUGE_S2MU005
4088 union power_supply_propval value
;
4090 /* update rVBAT register every 250ms for AT+BATTTEST */
4092 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
4093 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
4096 sec_bat_get_battery_info(battery
);
4098 /* update rVBAT register every 4s for normal case */
4100 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
4101 POWER_SUPPLY_PROP_ENERGY_NOW
, value
);
4103 /* update battery info */
4104 sec_bat_get_battery_info(battery
);
4110 if (sscanf(buf
, "%d\n", &x
) == 1) {
4111 battery
->test_mode
= x
;
4112 wake_lock(&battery
->monitor_wake_lock
);
4113 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4114 &battery
->monitor_work
, 0);
4119 case BATT_EVENT_CALL
:
4120 case BATT_EVENT_2G_CALL
:
4121 case BATT_EVENT_TALK_GSM
:
4122 if (sscanf(buf
, "%d\n", &x
) == 1) {
4123 sec_bat_event_set(battery
, EVENT_2G_CALL
, x
);
4127 case BATT_EVENT_3G_CALL
:
4128 case BATT_EVENT_TALK_WCDMA
:
4129 if (sscanf(buf
, "%d\n", &x
) == 1) {
4130 sec_bat_event_set(battery
, EVENT_3G_CALL
, x
);
4134 case BATT_EVENT_MUSIC
:
4135 if (sscanf(buf
, "%d\n", &x
) == 1) {
4136 sec_bat_event_set(battery
, EVENT_MUSIC
, x
);
4140 case BATT_EVENT_VIDEO
:
4141 if (sscanf(buf
, "%d\n", &x
) == 1) {
4142 sec_bat_event_set(battery
, EVENT_VIDEO
, x
);
4146 case BATT_EVENT_BROWSER
:
4147 if (sscanf(buf
, "%d\n", &x
) == 1) {
4148 sec_bat_event_set(battery
, EVENT_BROWSER
, x
);
4152 case BATT_EVENT_HOTSPOT
:
4153 if (sscanf(buf
, "%d\n", &x
) == 1) {
4154 sec_bat_event_set(battery
, EVENT_HOTSPOT
, x
);
4158 case BATT_EVENT_CAMERA
:
4159 if (sscanf(buf
, "%d\n", &x
) == 1) {
4160 sec_bat_event_set(battery
, EVENT_CAMERA
, x
);
4164 case BATT_EVENT_CAMCORDER
:
4165 if (sscanf(buf
, "%d\n", &x
) == 1) {
4166 sec_bat_event_set(battery
, EVENT_CAMCORDER
, x
);
4170 case BATT_EVENT_DATA_CALL
:
4171 if (sscanf(buf
, "%d\n", &x
) == 1) {
4172 sec_bat_event_set(battery
, EVENT_DATA_CALL
, x
);
4176 case BATT_EVENT_WIFI
:
4177 if (sscanf(buf
, "%d\n", &x
) == 1) {
4178 sec_bat_event_set(battery
, EVENT_WIFI
, x
);
4182 case BATT_EVENT_WIBRO
:
4183 if (sscanf(buf
, "%d\n", &x
) == 1) {
4184 sec_bat_event_set(battery
, EVENT_WIBRO
, x
);
4188 case BATT_EVENT_LTE
:
4189 if (sscanf(buf
, "%d\n", &x
) == 1) {
4190 sec_bat_event_set(battery
, EVENT_LTE
, x
);
4194 case BATT_EVENT_LCD
:
4195 if (sscanf(buf
, "%d\n", &x
) == 1) {
4197 sec_bat_event_set(battery, EVENT_LCD, x);
4200 battery
->lcd_status
= true;
4202 battery
->lcd_status
= false;
4207 case BATT_EVENT_GPS
:
4208 if (sscanf(buf
, "%d\n", &x
) == 1) {
4209 sec_bat_event_set(battery
, EVENT_GPS
, x
);
4213 case BATT_TEMP_TABLE
:
4214 if (sscanf(buf
, "%d %d %d %d %d %d %d %d %d %d %d %d\n",
4215 &t
[0], &t
[1], &t
[2], &t
[3], &t
[4], &t
[5], &t
[6], &t
[7], &t
[8], &t
[9], &t
[10], &t
[11]) == 12) {
4216 pr_info("%s: (new) %d %d %d %d %d %d %d %d %d %d %d %d\n",
4217 __func__
, t
[0], t
[1], t
[2], t
[3], t
[4], t
[5], t
[6], t
[7], t
[8], t
[9], t
[10], t
[11]);
4218 pr_info("%s: (default) %d %d %d %d %d %d %d %d %d %d %d %d\n",
4220 battery
->pdata
->temp_high_threshold_event
,
4221 battery
->pdata
->temp_high_recovery_event
,
4222 battery
->pdata
->temp_low_threshold_event
,
4223 battery
->pdata
->temp_low_recovery_event
,
4224 battery
->pdata
->temp_high_threshold_normal
,
4225 battery
->pdata
->temp_high_recovery_normal
,
4226 battery
->pdata
->temp_low_threshold_normal
,
4227 battery
->pdata
->temp_low_recovery_normal
,
4228 battery
->pdata
->temp_high_threshold_lpm
,
4229 battery
->pdata
->temp_high_recovery_lpm
,
4230 battery
->pdata
->temp_low_threshold_lpm
,
4231 battery
->pdata
->temp_low_recovery_lpm
);
4232 update_external_temp_table(battery
, t
);
4236 case BATT_HIGH_CURRENT_USB
:
4237 if (sscanf(buf
, "%d\n", &x
) == 1) {
4238 union power_supply_propval value
;
4239 battery
->is_hc_usb
= x
? true : false;
4240 value
.intval
= battery
->is_hc_usb
;
4242 psy_do_property(battery
->pdata
->charger_name
, set
,
4243 POWER_SUPPLY_PROP_USB_HC
, value
);
4245 pr_info("%s: is_hc_usb (%d)\n", __func__
, battery
->is_hc_usb
);
4249 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
4250 case BATT_TEST_CHARGE_CURRENT
:
4251 if (sscanf(buf
, "%d\n", &x
) == 1) {
4252 if (x
>= 0 && x
<= 2000) {
4253 union power_supply_propval value
;
4254 dev_err(battery
->dev
,
4255 "%s: BATT_TEST_CHARGE_CURRENT(%d)\n", __func__
, x
);
4256 battery
->pdata
->charging_current
[
4257 POWER_SUPPLY_TYPE_USB
].input_current_limit
= x
;
4258 battery
->pdata
->charging_current
[
4259 POWER_SUPPLY_TYPE_USB
].fast_charging_current
= x
;
4261 battery
->eng_not_full_status
= true;
4262 battery
->pdata
->temp_check_type
=
4263 SEC_BATTERY_TEMP_CHECK_NONE
;
4264 battery
->pdata
->charging_total_time
=
4267 if (battery
->cable_type
== POWER_SUPPLY_TYPE_USB
) {
4269 psy_do_property(battery
->pdata
->charger_name
, set
,
4270 POWER_SUPPLY_PROP_CURRENT_NOW
,
4278 case BATT_STABILITY_TEST
:
4279 if (sscanf(buf
, "%d\n", &x
) == 1) {
4280 dev_err(battery
->dev
,
4281 "%s: BATT_STABILITY_TEST(%d)\n", __func__
, x
);
4283 battery
->stability_test
= true;
4284 battery
->eng_not_full_status
= true;
4287 battery
->stability_test
= false;
4288 battery
->eng_not_full_status
= false;
4293 #if !defined(CONFIG_DISABLE_SAVE_CAPACITY_MAX)
4294 case BATT_CAPACITY_MAX
:
4295 if (sscanf(buf
, "%d\n", &x
) == 1 && !fg_reset
) {
4296 union power_supply_propval value
;
4297 dev_err(battery
->dev
,
4298 "%s: BATT_CAPACITY_MAX(%d)\n", __func__
, x
);
4299 if (x
> 800 && x
< 1200) {
4301 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
4302 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN
, value
);
4307 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
4308 POWER_SUPPLY_PROP_CAPACITY
, value
);
4309 battery
->capacity
= value
.intval
;
4310 power_supply_changed(&battery
->psy_bat
);
4315 case BATT_INBAT_VOLTAGE
:
4317 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
4318 case BATT_DISCHARGING_CHECK
:
4320 case BATT_DISCHARGING_CHECK_ADC
:
4322 case BATT_DISCHARGING_NTC
:
4324 case BATT_DISCHARGING_NTC_ADC
:
4326 case BATT_SELF_DISCHARGING_CONTROL
:
4327 if (sscanf(buf
, "%d\n", &x
) == 1) {
4328 dev_err(battery
->dev
,
4329 "%s: BATT_SELF_DISCHARGING_CONTROL(%d)\n", __func__
, x
);
4331 battery
->factory_self_discharging_mode_on
= true;
4332 pr_info("SELF DISCHARGING IC ENABLE\n");
4333 sec_bat_self_discharging_control(battery
, true);
4335 battery
->factory_self_discharging_mode_on
= false;
4336 pr_info("SELF DISCHARGING IC DISENABLE\n");
4337 sec_bat_self_discharging_control(battery
, false);
4343 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
4344 case BATT_INBAT_WIRELESS_CS100
:
4345 if (sscanf(buf
, "%d\n", &x
) == 1) {
4346 union power_supply_propval value
;
4348 pr_info("%s send cs100 command \n",__func__
);
4349 value
.intval
= POWER_SUPPLY_STATUS_FULL
;
4350 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
4351 POWER_SUPPLY_PROP_STATUS
, value
);
4356 case HMT_TA_CONNECTED
:
4357 if (sscanf(buf
, "%d\n", &x
) == 1) {
4358 union power_supply_propval value
;
4359 dev_info(battery
->dev
,
4360 "%s: HMT_TA_CONNECTED(%d)\n", __func__
, x
);
4362 value
.intval
= false;
4363 psy_do_property(battery
->pdata
->charger_name
, set
,
4364 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4366 dev_info(battery
->dev
,
4367 "%s: changed to OTG cable detached\n", __func__
);
4369 battery
->wire_status
= POWER_SUPPLY_TYPE_HMT_CONNECTED
;
4370 wake_lock(&battery
->cable_wake_lock
);
4371 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4373 value
.intval
= true;
4374 psy_do_property(battery
->pdata
->charger_name
, set
,
4375 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4377 dev_info(battery
->dev
,
4378 "%s: changed to OTG cable attached\n", __func__
);
4380 battery
->wire_status
= POWER_SUPPLY_TYPE_OTG
;
4381 wake_lock(&battery
->cable_wake_lock
);
4382 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4388 if (sscanf(buf
, "%d\n", &x
) == 1) {
4389 union power_supply_propval value
;
4390 dev_info(battery
->dev
,
4391 "%s: HMT_TA_CHARGE(%d)\n", __func__
, x
);
4392 psy_do_property(battery
->pdata
->charger_name
, get
,
4393 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, value
);
4395 dev_info(battery
->dev
,
4396 "%s: ignore HMT_TA_CHARGE(%d)\n", __func__
, x
);
4399 value
.intval
= false;
4400 psy_do_property(battery
->pdata
->charger_name
, set
,
4401 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4403 dev_info(battery
->dev
,
4404 "%s: changed to OTG cable detached\n", __func__
);
4405 battery
->wire_status
= POWER_SUPPLY_TYPE_HMT_CHARGE
;
4406 wake_lock(&battery
->cable_wake_lock
);
4407 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4409 value
.intval
= false;
4410 psy_do_property(battery
->pdata
->charger_name
, set
,
4411 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
4413 dev_info(battery
->dev
,
4414 "%s: changed to OTG cable detached\n", __func__
);
4415 battery
->wire_status
= POWER_SUPPLY_TYPE_HMT_CONNECTED
;
4416 wake_lock(&battery
->cable_wake_lock
);
4417 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
4425 case FG_FULL_VOLTAGE
:
4430 if (sscanf(buf
, "%d\n", &x
) == 1) {
4431 dev_info(battery
->dev
, "%s: BATTERY_CYCLE(%d)\n", __func__
, x
);
4433 int prev_battery_cycle
;
4434 prev_battery_cycle
= battery
->batt_cycle
;
4435 battery
->batt_cycle
= x
;
4436 #if defined(CONFIG_BATTERY_AGE_FORECAST)
4437 dev_info(battery
->dev
, "%s: [Long life] prev_battery_cycle = %d, new bat. cycle = %d\n", __func__
, prev_battery_cycle
, battery
->batt_cycle
);
4438 if (prev_battery_cycle
< 0) {
4439 dev_info(battery
->dev
, "%s: [Long life] Do sec_bat_aging_check()\n", __func__
);
4440 sec_bat_aging_check(battery
);
4447 case FACTORY_MODE_RELIEVE
:
4448 if (sscanf(buf
, "%d\n", &x
) == 1) {
4449 union power_supply_propval value
;
4451 psy_do_property(battery
->pdata
->charger_name
, set
,
4452 POWER_SUPPLY_PROP_INPUT_VOLTAGE_REGULATION
, value
);
4456 case FACTORY_MODE_BYPASS
:
4457 if (sscanf(buf
, "%d\n", &x
) == 1) {
4458 union power_supply_propval value
;
4460 psy_do_property(battery
->pdata
->charger_name
, set
,
4461 POWER_SUPPLY_PROP_AUTHENTIC
, value
);
4472 static int sec_bat_create_attrs(struct device
*dev
)
4477 for (i
= 0; i
< ARRAY_SIZE(sec_battery_attrs
); i
++) {
4478 rc
= device_create_file(dev
, &sec_battery_attrs
[i
]);
4480 goto create_attrs_failed
;
4482 goto create_attrs_succeed
;
4484 create_attrs_failed
:
4486 device_remove_file(dev
, &sec_battery_attrs
[i
]);
4487 create_attrs_succeed
:
4491 static int sec_bat_set_property(struct power_supply
*psy
,
4492 enum power_supply_property psp
,
4493 const union power_supply_propval
*val
)
4495 struct sec_battery_info
*battery
=
4496 container_of(psy
, struct sec_battery_info
, psy_bat
);
4497 int current_cable_type
;
4498 int full_check_type
;
4500 dev_dbg(battery
->dev
,
4501 "%s: (%d,%d)\n", __func__
, psp
, val
->intval
);
4504 case POWER_SUPPLY_PROP_STATUS
:
4505 if (battery
->charging_mode
== SEC_BATTERY_CHARGING_1ST
)
4506 full_check_type
= battery
->pdata
->full_check_type
;
4508 full_check_type
= battery
->pdata
->full_check_type_2nd
;
4509 if ((full_check_type
== SEC_BATTERY_FULLCHARGED_CHGINT
) &&
4510 (val
->intval
== POWER_SUPPLY_STATUS_FULL
))
4511 sec_bat_do_fullcharged(battery
);
4512 sec_bat_set_charging_status(battery
, val
->intval
);
4514 case POWER_SUPPLY_PROP_HEALTH
:
4515 sec_bat_ovp_uvlo_result(battery
, val
->intval
);
4517 case POWER_SUPPLY_PROP_ONLINE
:
4518 current_cable_type
= val
->intval
;
4520 if ((battery
->muic_cable_type
!= ATTACHED_DEV_SMARTDOCK_TA_MUIC
)
4521 && ((current_cable_type
== POWER_SUPPLY_TYPE_SMART_OTG
) ||
4522 (current_cable_type
== POWER_SUPPLY_TYPE_SMART_NOTG
)))
4525 if (current_cable_type
< 0) {
4526 dev_info(battery
->dev
,
4527 "%s: ignore event(%d)\n",
4528 __func__
, current_cable_type
);
4529 } else if (current_cable_type
== POWER_SUPPLY_TYPE_OTG
) {
4530 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
4531 battery
->is_recharging
= false;
4532 sec_bat_set_charging_status(battery
,
4533 POWER_SUPPLY_STATUS_DISCHARGING
);
4534 battery
->cable_type
= current_cable_type
;
4535 wake_lock(&battery
->monitor_wake_lock
);
4536 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4537 &battery
->monitor_work
, 0);
4540 battery
->wire_status
= current_cable_type
;
4541 if ((battery
->wire_status
== POWER_SUPPLY_TYPE_BATTERY
)
4542 && battery
->wc_status
)
4543 current_cable_type
= POWER_SUPPLY_TYPE_WIRELESS
;
4545 dev_info(battery
->dev
,
4546 "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n",
4547 __func__
, current_cable_type
, battery
->wc_status
,
4548 battery
->wire_status
);
4550 /* cable is attached or detached
4551 * if current_cable_type is minus value,
4552 * check cable by sec_bat_get_cable_type()
4553 * although SEC_BATTERY_CABLE_SOURCE_EXTERNAL is set
4554 * (0 is POWER_SUPPLY_TYPE_UNKNOWN)
4556 if ((current_cable_type
>= 0) &&
4557 (current_cable_type
< SEC_SIZEOF_POWER_SUPPLY_TYPE
) &&
4558 (battery
->pdata
->cable_source_type
&
4559 SEC_BATTERY_CABLE_SOURCE_EXTERNAL
)) {
4561 wake_lock(&battery
->cable_wake_lock
);
4562 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4563 &battery
->cable_work
,0);
4565 if (sec_bat_get_cable_type(battery
,
4566 battery
->pdata
->cable_source_type
)) {
4567 wake_lock(&battery
->cable_wake_lock
);
4568 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4569 &battery
->cable_work
,0);
4573 case POWER_SUPPLY_PROP_CAPACITY
:
4574 battery
->capacity
= val
->intval
;
4575 power_supply_changed(&battery
->psy_bat
);
4577 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
4578 /* If JIG is attached, the voltage is set as 1079 */
4579 pr_info("%s : set to the battery history : (%d)\n",__func__
, val
->intval
);
4580 if(val
->intval
== 1079) {
4581 battery
->voltage_now
= 1079;
4582 battery
->voltage_avg
= 1079;
4583 power_supply_changed(&battery
->psy_bat
);
4586 case POWER_SUPPLY_PROP_CURRENT_AVG
:
4587 battery
->charging_current
= val
->intval
;
4589 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
4590 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
4592 case POWER_SUPPLY_PROP_PRESENT
:
4593 battery
->present
= val
->intval
;
4595 wake_lock(&battery
->monitor_wake_lock
);
4596 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4597 &battery
->monitor_work
, 0);
4599 #if defined(CONFIG_BATTERY_SWELLING)
4600 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT
:
4610 static int sec_bat_get_property(struct power_supply
*psy
,
4611 enum power_supply_property psp
,
4612 union power_supply_propval
*val
)
4614 struct sec_battery_info
*battery
=
4615 container_of(psy
, struct sec_battery_info
, psy_bat
);
4616 union power_supply_propval value
;
4617 #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY)
4618 union power_supply_propval value_ac
;
4619 union power_supply_propval value_usb
;
4623 case POWER_SUPPLY_PROP_STATUS
:
4624 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERVOLTAGE
) ||
4625 (battery
->health
== POWER_SUPPLY_HEALTH_UNDERVOLTAGE
)) {
4626 val
->intval
= POWER_SUPPLY_STATUS_DISCHARGING
;
4628 if ((battery
->pdata
->cable_check_type
&
4629 SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE
) &&
4631 switch (battery
->cable_type
) {
4632 case POWER_SUPPLY_TYPE_USB
:
4633 case POWER_SUPPLY_TYPE_USB_DCP
:
4634 case POWER_SUPPLY_TYPE_USB_CDP
:
4635 case POWER_SUPPLY_TYPE_USB_ACA
:
4637 POWER_SUPPLY_STATUS_DISCHARGING
;
4641 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
4642 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
&&
4643 battery
->capacity
!= 100) {
4644 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
4645 pr_info("%s: forced full-charged sequence progressing\n", __func__
);
4648 val
->intval
= battery
->status
;
4650 #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY)
4651 psy_do_property("ac", get
, POWER_SUPPLY_PROP_ONLINE
, value_ac
);
4652 psy_do_property("usb", get
, POWER_SUPPLY_PROP_ONLINE
, value_usb
);
4653 if (battery
->store_mode
&& !lpcharge
&& (value_ac
.intval
|| value_usb
.intval
)) {
4654 val
->intval
= POWER_SUPPLY_STATUS_CHARGING
;
4659 case POWER_SUPPLY_PROP_CHARGE_TYPE
:
4660 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
||
4661 battery
->cable_type
== POWER_SUPPLY_TYPE_MHL_USB_100
) {
4662 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_NONE
;
4664 psy_do_property(battery
->pdata
->charger_name
, get
,
4665 POWER_SUPPLY_PROP_CHARGE_TYPE
, value
);
4666 if (value
.intval
== POWER_SUPPLY_CHARGE_TYPE_UNKNOWN
)
4667 /* if error in CHARGE_TYPE of charger
4668 * set CHARGE_TYPE as NONE
4670 val
->intval
= POWER_SUPPLY_CHARGE_TYPE_NONE
;
4672 val
->intval
= value
.intval
;
4675 case POWER_SUPPLY_PROP_HEALTH
:
4676 val
->intval
= battery
->health
;
4678 case POWER_SUPPLY_PROP_PRESENT
:
4679 val
->intval
= battery
->present
;
4681 case POWER_SUPPLY_PROP_ONLINE
:
4682 val
->intval
= battery
->cable_type
;
4684 case POWER_SUPPLY_PROP_TECHNOLOGY
:
4685 val
->intval
= battery
->pdata
->technology
;
4687 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
4688 #ifdef CONFIG_SEC_FACTORY
4689 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
4690 POWER_SUPPLY_PROP_VOLTAGE_NOW
, value
);
4691 battery
->voltage_now
= value
.intval
;
4692 dev_err(battery
->dev
,
4693 "%s: voltage now(%d)\n", __func__
, battery
->voltage_now
);
4695 /* voltage value should be in uV */
4696 val
->intval
= battery
->voltage_now
* 1000;
4698 case POWER_SUPPLY_PROP_VOLTAGE_AVG
:
4699 #ifdef CONFIG_SEC_FACTORY
4700 value
.intval
= SEC_BATTERY_VOLTAGE_AVERAGE
;
4701 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
4702 POWER_SUPPLY_PROP_VOLTAGE_AVG
, value
);
4703 battery
->voltage_avg
= value
.intval
;
4704 dev_err(battery
->dev
,
4705 "%s: voltage avg(%d)\n", __func__
, battery
->voltage_avg
);
4707 /* voltage value should be in uV */
4708 val
->intval
= battery
->voltage_avg
* 1000;
4710 case POWER_SUPPLY_PROP_CURRENT_NOW
:
4711 val
->intval
= battery
->current_now
;
4713 case POWER_SUPPLY_PROP_CURRENT_AVG
:
4714 val
->intval
= battery
->current_avg
;
4716 /* charging mode (differ from power supply) */
4717 case POWER_SUPPLY_PROP_CHARGE_NOW
:
4718 val
->intval
= battery
->charging_mode
;
4720 case POWER_SUPPLY_PROP_CAPACITY
:
4721 if (battery
->pdata
->fake_capacity
) {
4723 pr_info("%s : capacity(%d)\n", __func__
, val
->intval
);
4725 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
4726 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
) {
4727 if(battery
->eng_not_full_status
)
4728 val
->intval
= battery
->capacity
;
4732 val
->intval
= battery
->capacity
;
4735 #if defined(CONFIG_AFC_CHARGER_MODE) || defined(CONFIG_PREVENT_SOC_JUMP)
4736 val
->intval
= battery
->capacity
;
4738 /* In full-charged status, SOC is always 100% */
4739 if (battery
->status
== POWER_SUPPLY_STATUS_FULL
)
4742 val
->intval
= battery
->capacity
;
4747 case POWER_SUPPLY_PROP_TEMP
:
4748 val
->intval
= battery
->temperature
;
4750 case POWER_SUPPLY_PROP_TEMP_AMBIENT
:
4751 val
->intval
= battery
->temper_amb
;
4753 #if defined(CONFIG_CALC_TIME_TO_FULL)
4754 case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW
:
4755 #if defined(CONFIG_CHARGING_VZWCONCEPT)
4756 if (battery
->capacity
== 100) {
4761 if (battery
->status
== POWER_SUPPLY_STATUS_CHARGING
&& battery
->complete_timetofull
&&
4762 !battery
->swelling_mode
)
4763 val
->intval
= battery
->timetofull
;
4768 #if defined(CONFIG_BATTERY_SWELLING)
4769 case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT
:
4770 if ((battery
->swelling_mode
) || (battery
->current_event
& SEC_BAT_CURRENT_EVENT_LOW_TEMP
))
4782 static int sec_usb_get_property(struct power_supply
*psy
,
4783 enum power_supply_property psp
,
4784 union power_supply_propval
*val
)
4786 struct sec_battery_info
*battery
=
4787 container_of(psy
, struct sec_battery_info
, psy_usb
);
4790 case POWER_SUPPLY_PROP_ONLINE
:
4792 case POWER_SUPPLY_PROP_VOLTAGE_MAX
:
4794 val
->intval
= battery
->input_voltage
* 1000000;
4796 case POWER_SUPPLY_PROP_CURRENT_MAX
:
4798 val
->intval
= battery
->pdata
->charging_current
[battery
->cable_type
].input_current_limit
* 1000;
4804 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERVOLTAGE
) ||
4805 (battery
->health
== POWER_SUPPLY_HEALTH_UNDERVOLTAGE
)) {
4809 /* Set enable=1 only if the USB charger is connected */
4810 switch (battery
->wire_status
) {
4811 case POWER_SUPPLY_TYPE_USB
:
4812 case POWER_SUPPLY_TYPE_USB_DCP
:
4813 case POWER_SUPPLY_TYPE_USB_CDP
:
4814 case POWER_SUPPLY_TYPE_USB_ACA
:
4815 case POWER_SUPPLY_TYPE_MHL_USB
:
4816 case POWER_SUPPLY_TYPE_MHL_USB_100
:
4824 if (battery
->slate_mode
)
4829 static int sec_ac_get_property(struct power_supply
*psy
,
4830 enum power_supply_property psp
,
4831 union power_supply_propval
*val
)
4833 struct sec_battery_info
*battery
=
4834 container_of(psy
, struct sec_battery_info
, psy_ac
);
4837 case POWER_SUPPLY_PROP_ONLINE
:
4839 case POWER_SUPPLY_PROP_VOLTAGE_MAX
:
4841 val
->intval
= battery
->input_voltage
* 1000000;
4843 case POWER_SUPPLY_PROP_CURRENT_MAX
:
4845 val
->intval
= battery
->pdata
->charging_current
[battery
->cable_type
].input_current_limit
* 1000;
4851 if ((battery
->health
== POWER_SUPPLY_HEALTH_OVERVOLTAGE
) ||
4852 (battery
->health
== POWER_SUPPLY_HEALTH_UNDERVOLTAGE
)) {
4857 /* Set enable=1 only if the AC charger is connected */
4858 switch (battery
->cable_type
) {
4859 case POWER_SUPPLY_TYPE_MAINS
:
4860 case POWER_SUPPLY_TYPE_MISC
:
4861 case POWER_SUPPLY_TYPE_CARDOCK
:
4862 case POWER_SUPPLY_TYPE_UARTOFF
:
4863 case POWER_SUPPLY_TYPE_LAN_HUB
:
4864 case POWER_SUPPLY_TYPE_UNKNOWN
:
4865 case POWER_SUPPLY_TYPE_MHL_500
:
4866 case POWER_SUPPLY_TYPE_MHL_900
:
4867 case POWER_SUPPLY_TYPE_MHL_1500
:
4868 case POWER_SUPPLY_TYPE_MHL_2000
:
4869 case POWER_SUPPLY_TYPE_SMART_OTG
:
4870 case POWER_SUPPLY_TYPE_SMART_NOTG
:
4871 case POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
:
4872 case POWER_SUPPLY_TYPE_HV_ERR
:
4873 case POWER_SUPPLY_TYPE_HV_UNKNOWN
:
4874 case POWER_SUPPLY_TYPE_HV_MAINS
:
4875 case POWER_SUPPLY_TYPE_MDOCK_TA
:
4876 case POWER_SUPPLY_TYPE_HMT_CONNECTED
:
4877 case POWER_SUPPLY_TYPE_HMT_CHARGE
:
4878 case POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
:
4889 static int sec_wireless_get_property(struct power_supply
*psy
,
4890 enum power_supply_property psp
,
4891 union power_supply_propval
*val
)
4893 struct sec_battery_info
*battery
=
4894 container_of(psy
, struct sec_battery_info
, psy_wireless
);
4897 case POWER_SUPPLY_PROP_ONLINE
:
4899 case POWER_SUPPLY_PROP_VOLTAGE_MAX
:
4901 val
->intval
= battery
->input_voltage
* 1000000;
4903 case POWER_SUPPLY_PROP_CURRENT_MAX
:
4905 val
->intval
= battery
->pdata
->charging_current
[battery
->cable_type
].input_current_limit
* 1000;
4911 if (battery
->wc_status
)
4919 static int sec_wireless_set_property(struct power_supply
*psy
,
4920 enum power_supply_property psp
,
4921 const union power_supply_propval
*val
)
4923 struct sec_battery_info
*battery
=
4924 container_of(psy
, struct sec_battery_info
, psy_wireless
);
4927 case POWER_SUPPLY_PROP_ONLINE
:
4928 battery
->wc_status
= val
->intval
;
4930 wake_lock(&battery
->cable_wake_lock
);
4931 queue_delayed_work_on(0, battery
->monitor_wqueue
,
4932 &battery
->cable_work
, 0);
4934 #if defined(CONFIG_WIRELESS_CHARGER_INBATTERY)
4935 case POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
:
4936 if (battery
->wc_status
) {
4937 union power_supply_propval value
;
4938 value
.intval
= val
->intval
;
4939 psy_do_property(battery
->pdata
->wireless_charger_name
, set
,
4940 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
, value
);
4951 static int sec_ps_set_property(struct power_supply
*psy
,
4952 enum power_supply_property psp
,
4953 const union power_supply_propval
*val
)
4955 struct sec_battery_info
*battery
=
4956 container_of(psy
, struct sec_battery_info
, psy_ps
);
4957 union power_supply_propval value
;
4960 case POWER_SUPPLY_PROP_STATUS
:
4961 if (val
->intval
== 0) {
4962 if (battery
->ps_enable
== true) {
4963 battery
->ps_enable
= val
->intval
;
4964 dev_info(battery
->dev
,
4965 "%s: power sharing cable set (%d)\n", __func__
, battery
->ps_enable
);
4966 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
4967 psy_do_property(battery
->pdata
->charger_name
, set
,
4968 POWER_SUPPLY_PROP_ONLINE
, value
);
4970 } else if ((val
->intval
== 1) && (battery
->ps_status
== true)) {
4971 battery
->ps_enable
= val
->intval
;
4972 dev_info(battery
->dev
,
4973 "%s: power sharing cable set (%d)\n", __func__
, battery
->ps_enable
);
4974 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
4975 psy_do_property(battery
->pdata
->charger_name
, set
,
4976 POWER_SUPPLY_PROP_ONLINE
, value
);
4978 dev_err(battery
->dev
,
4979 "%s: invalid setting (%d) ps_status (%d)\n",
4980 __func__
, val
->intval
, battery
->ps_status
);
4983 case POWER_SUPPLY_PROP_ONLINE
:
4984 if (val
->intval
== POWER_SUPPLY_TYPE_POWER_SHARING
) {
4985 battery
->ps_status
= true;
4986 battery
->ps_enable
= true;
4987 battery
->ps_changed
= true;
4988 dev_info(battery
->dev
,
4989 "%s: power sharing cable plugin (%d)\n", __func__
, battery
->ps_status
);
4990 wake_lock(&battery
->monitor_wake_lock
);
4991 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
4993 battery
->ps_status
= false;
4994 battery
->ps_enable
= false;
4995 battery
->ps_changed
= false;
4996 dev_info(battery
->dev
,
4997 "%s: power sharing cable plugout (%d)\n", __func__
, battery
->ps_status
);
4998 wake_lock(&battery
->monitor_wake_lock
);
4999 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5009 static int sec_ps_get_property(struct power_supply
*psy
,
5010 enum power_supply_property psp
,
5011 union power_supply_propval
*val
)
5013 struct sec_battery_info
*battery
=
5014 container_of(psy
, struct sec_battery_info
, psy_ps
);
5015 union power_supply_propval value
;
5018 case POWER_SUPPLY_PROP_STATUS
:
5019 if (battery
->ps_enable
)
5024 case POWER_SUPPLY_PROP_ONLINE
:
5025 if (battery
->ps_status
) {
5026 if ((battery
->ps_enable
== true) && (battery
->ps_changed
== true)) {
5027 battery
->ps_changed
= false;
5029 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
5030 psy_do_property(battery
->pdata
->charger_name
, set
,
5031 POWER_SUPPLY_PROP_ONLINE
, value
);
5035 if (battery
->ps_enable
== true) {
5036 battery
->ps_enable
= false;
5037 dev_info(battery
->dev
,
5038 "%s: power sharing cable disconnected! ps disable (%d)\n",
5039 __func__
, battery
->ps_enable
);
5041 value
.intval
= POWER_SUPPLY_TYPE_POWER_SHARING
;
5042 psy_do_property(battery
->pdata
->charger_name
, set
,
5043 POWER_SUPPLY_PROP_ONLINE
, value
);
5057 static irqreturn_t
sec_bat_irq_thread(int irq
, void *irq_data
)
5059 struct sec_battery_info
*battery
= irq_data
;
5061 dev_info(battery
->dev
, "%s:(bat_irq occured_start\n", __func__
);
5063 if (battery
->pdata
->cable_check_type
&
5064 SEC_BATTERY_CABLE_CHECK_INT
) {
5065 if (battery
->pdata
->is_interrupt_cable_check_possible
&&
5066 !battery
->pdata
->is_interrupt_cable_check_possible(
5067 battery
->extended_cable_type
))
5068 goto no_cable_check
;
5070 if (sec_bat_get_cable_type(battery
,
5071 battery
->pdata
->cable_source_type
)) {
5072 wake_lock(&battery
->cable_wake_lock
);
5073 queue_delayed_work(battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5080 if (battery
->pdata
->battery_check_type
==
5081 SEC_BATTERY_CHECK_INT
) {
5082 if (battery_pdata
->check_battery_callback
)
5083 battery
->present
= battery
->pdata
->check_battery_callback();
5085 wake_lock(&battery
->monitor_wake_lock
);
5086 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5093 #if defined(CONFIG_MUIC_NOTIFIER)
5094 static int sec_bat_cable_check(struct sec_battery_info
*battery
,
5095 muic_attached_dev_t attached_dev
)
5097 int current_cable_type
= -1;
5098 union power_supply_propval val
;
5100 pr_info("[%s]ATTACHED(%d)\n", __func__
, attached_dev
);
5101 battery
->is_jig_on
= false;
5103 switch (attached_dev
)
5105 case ATTACHED_DEV_JIG_UART_OFF_MUIC
:
5106 case ATTACHED_DEV_JIG_UART_ON_MUIC
:
5107 battery
->is_jig_on
= true;
5108 case ATTACHED_DEV_SMARTDOCK_MUIC
:
5109 case ATTACHED_DEV_DESKDOCK_MUIC
:
5110 current_cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
5112 case ATTACHED_DEV_OTG_MUIC
:
5113 case ATTACHED_DEV_JIG_UART_OFF_VB_OTG_MUIC
:
5114 case ATTACHED_DEV_HMT_MUIC
:
5115 current_cable_type
= POWER_SUPPLY_TYPE_OTG
;
5117 case ATTACHED_DEV_USB_MUIC
:
5118 case ATTACHED_DEV_JIG_USB_OFF_MUIC
:
5119 case ATTACHED_DEV_JIG_USB_ON_MUIC
:
5120 case ATTACHED_DEV_SMARTDOCK_USB_MUIC
:
5121 case ATTACHED_DEV_UNOFFICIAL_ID_USB_MUIC
:
5122 current_cable_type
= POWER_SUPPLY_TYPE_USB
;
5124 case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC
:
5125 case ATTACHED_DEV_JIG_UART_OFF_VB_FG_MUIC
:
5126 current_cable_type
= factory_mode
? POWER_SUPPLY_TYPE_BATTERY
:
5127 POWER_SUPPLY_TYPE_UARTOFF
;
5129 case ATTACHED_DEV_TA_MUIC
:
5130 case ATTACHED_DEV_CARDOCK_MUIC
:
5131 case ATTACHED_DEV_DESKDOCK_VB_MUIC
:
5132 case ATTACHED_DEV_SMARTDOCK_TA_MUIC
:
5133 case ATTACHED_DEV_UNOFFICIAL_TA_MUIC
:
5134 case ATTACHED_DEV_UNOFFICIAL_ID_TA_MUIC
:
5135 case ATTACHED_DEV_UNOFFICIAL_ID_ANY_MUIC
:
5136 case ATTACHED_DEV_UNSUPPORTED_ID_VB_MUIC
:
5137 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5139 case ATTACHED_DEV_QC_CHARGER_5V_MUIC
:
5140 case ATTACHED_DEV_AFC_CHARGER_5V_MUIC
:
5141 #if defined(CONFIG_AFC_CHARGER_MODE)
5142 if (is_hv_wire_type(battery
->cable_type
) || battery
->cable_type
== POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
)
5143 current_cable_type
= POWER_SUPPLY_TYPE_HV_MAINS_CHG_LIMIT
;
5145 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5147 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5150 case ATTACHED_DEV_CDP_MUIC
:
5151 case ATTACHED_DEV_UNOFFICIAL_ID_CDP_MUIC
:
5152 current_cable_type
= POWER_SUPPLY_TYPE_USB_CDP
;
5154 case ATTACHED_DEV_USB_LANHUB_MUIC
:
5155 current_cable_type
= POWER_SUPPLY_TYPE_LAN_HUB
;
5157 case ATTACHED_DEV_CHARGING_CABLE_MUIC
:
5158 current_cable_type
= POWER_SUPPLY_TYPE_POWER_SHARING
;
5160 case ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC
:
5161 case ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC
:
5162 current_cable_type
= POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
;
5164 case ATTACHED_DEV_AFC_CHARGER_9V_MUIC
:
5165 case ATTACHED_DEV_QC_CHARGER_9V_MUIC
:
5166 current_cable_type
= POWER_SUPPLY_TYPE_HV_MAINS
;
5168 case ATTACHED_DEV_AFC_CHARGER_ERR_V_MUIC
:
5169 case ATTACHED_DEV_QC_CHARGER_ERR_V_MUIC
:
5170 current_cable_type
= POWER_SUPPLY_TYPE_HV_ERR
;
5172 case ATTACHED_DEV_UNDEFINED_CHARGING_MUIC
:
5173 current_cable_type
= POWER_SUPPLY_TYPE_MAINS
;
5175 case ATTACHED_DEV_HV_ID_ERR_UNDEFINED_MUIC
:
5176 case ATTACHED_DEV_HV_ID_ERR_UNSUPPORTED_MUIC
:
5177 case ATTACHED_DEV_HV_ID_ERR_SUPPORTED_MUIC
:
5178 current_cable_type
= POWER_SUPPLY_TYPE_HV_UNKNOWN
;
5180 case ATTACHED_DEV_VZW_INCOMPATIBLE_MUIC
:
5181 current_cable_type
= POWER_SUPPLY_TYPE_UNKNOWN
;
5184 pr_err("%s: invalid type for charger:%d\n",
5185 __func__
, attached_dev
);
5187 #ifndef CONFIG_FUELGAUGE_S2MU005
5188 if (battery
->is_jig_on
)
5189 psy_do_property(battery
->pdata
->fuelgauge_name
, set
,
5190 POWER_SUPPLY_PROP_ENERGY_NOW
, val
);
5193 val
.intval
= battery
->is_jig_on
;
5194 psy_do_property(battery
->pdata
->charger_name
, set
,
5195 POWER_SUPPLY_PROP_ENERGY_NOW
, val
);
5197 return current_cable_type
;
5201 static int batt_handle_notification(struct notifier_block
*nb
,
5202 unsigned long action
, void *data
)
5204 muic_attached_dev_t attached_dev
= *(muic_attached_dev_t
*)data
;
5207 struct sec_battery_info
*battery
=
5208 container_of(nb
, struct sec_battery_info
,
5210 union power_supply_propval value
;
5213 case MUIC_NOTIFY_CMD_DETACH
:
5214 case MUIC_NOTIFY_CMD_LOGICALLY_DETACH
:
5216 cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
5217 battery
->muic_cable_type
= ATTACHED_DEV_NONE_MUIC
;
5219 case MUIC_NOTIFY_CMD_ATTACH
:
5220 case MUIC_NOTIFY_CMD_LOGICALLY_ATTACH
:
5222 cable_type
= sec_bat_cable_check(battery
, attached_dev
);
5223 battery
->muic_cable_type
= attached_dev
;
5228 battery
->muic_cable_type
= ATTACHED_DEV_NONE_MUIC
;
5232 if (attached_dev
== ATTACHED_DEV_MHL_MUIC
)
5235 if (cable_type
< 0) {
5236 dev_info(battery
->dev
, "%s: ignore event(%d)\n",
5237 __func__
, cable_type
);
5238 } else if (cable_type
== POWER_SUPPLY_TYPE_POWER_SHARING
) {
5239 battery
->ps_status
= true;
5240 battery
->ps_enable
= true;
5241 battery
->ps_changed
= true;
5243 dev_info(battery
->dev
,
5244 "%s: power sharing cable plugin (%d)\n", __func__
, battery
->ps_status
);
5245 } else if (cable_type
== POWER_SUPPLY_TYPE_WIRELESS
) {
5246 battery
->wc_status
= true;
5247 } else if ((cable_type
== POWER_SUPPLY_TYPE_UNKNOWN
) &&
5248 (battery
->status
!= POWER_SUPPLY_STATUS_DISCHARGING
)) {
5249 battery
->cable_type
= cable_type
;
5250 wake_lock(&battery
->monitor_wake_lock
);
5251 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5252 dev_info(battery
->dev
,
5253 "%s: UNKNOWN cable plugin\n", __func__
);
5256 battery
->wire_status
= cable_type
;
5257 if ((battery
->wire_status
== POWER_SUPPLY_TYPE_BATTERY
)
5258 && battery
->wc_status
&& !battery
->ps_status
)
5259 cable_type
= POWER_SUPPLY_TYPE_WIRELESS
;
5261 dev_info(battery
->dev
,
5262 "%s: current_cable(%d), wc_status(%d), wire_status(%d)\n",
5263 __func__
, cable_type
, battery
->wc_status
,
5264 battery
->wire_status
);
5266 if (attached_dev
== ATTACHED_DEV_USB_LANHUB_MUIC
) {
5267 if (!strcmp(cmd
, "ATTACH")) {
5268 value
.intval
= true;
5269 psy_do_property(battery
->pdata
->charger_name
, set
,
5270 POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL
,
5272 dev_info(battery
->dev
,
5273 "%s: Powered OTG cable attached\n", __func__
);
5275 value
.intval
= false;
5276 psy_do_property(battery
->pdata
->charger_name
, set
,
5277 POWER_SUPPLY_PROP_CHARGE_POWERED_OTG_CONTROL
,
5279 dev_info(battery
->dev
,
5280 "%s: Powered OTG cable detached\n", __func__
);
5284 #if defined(CONFIG_AFC_CHARGER_MODE)
5285 if (!strcmp(cmd
, "ATTACH")) {
5286 if ((battery
->muic_cable_type
>= ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC
) &&
5287 (battery
->muic_cable_type
<= ATTACHED_DEV_QC_CHARGER_9V_MUIC
))
5288 battery
->hv_chg_name
= "QC";
5289 else if ((battery
->muic_cable_type
>= ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC
) &&
5290 (battery
->muic_cable_type
<= ATTACHED_DEV_AFC_CHARGER_ERR_V_DUPLI_MUIC
))
5291 battery
->hv_chg_name
= "AFC";
5293 battery
->hv_chg_name
= "NONE";
5295 battery
->hv_chg_name
= "NONE";
5298 pr_info("%s : HV_CHARGER_NAME(%s)\n",
5299 __func__
, battery
->hv_chg_name
);
5302 if ((cable_type
>= 0) &&
5303 cable_type
<= SEC_SIZEOF_POWER_SUPPLY_TYPE
) {
5304 if ((cable_type
== POWER_SUPPLY_TYPE_POWER_SHARING
)
5305 || (cable_type
== POWER_SUPPLY_TYPE_OTG
)) {
5306 wake_lock(&battery
->monitor_wake_lock
);
5307 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5308 } else if((cable_type
== POWER_SUPPLY_TYPE_BATTERY
)
5309 && battery
->ps_status
) {
5310 battery
->ps_status
= false;
5311 dev_info(battery
->dev
,
5312 "%s: power sharing cable plugout (%d)\n", __func__
, battery
->ps_status
);
5313 wake_lock(&battery
->monitor_wake_lock
);
5314 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
5315 } else if(cable_type
!= battery
->cable_type
) {
5316 wake_lock(&battery
->cable_wake_lock
);
5317 queue_delayed_work_on(0, battery
->monitor_wqueue
,
5318 &battery
->cable_work
, 0);
5320 dev_info(battery
->dev
,
5321 "%s: Cable is Not Changed(%d)\n",
5322 __func__
, battery
->cable_type
);
5326 pr_info("%s: CMD=%s, attached_dev=%d\n", __func__
, cmd
, attached_dev
);
5330 #endif /* CONFIG_MUIC_NOTIFIER */
5332 #if defined(CONFIG_VBUS_NOTIFIER)
5333 static int vbus_handle_notification(struct notifier_block
*nb
,
5334 unsigned long action
, void *data
)
5336 vbus_status_t vbus_status
= *(vbus_status_t
*)data
;
5337 struct sec_battery_info
*battery
=
5338 container_of(nb
, struct sec_battery_info
,
5340 union power_supply_propval value
;
5342 if (battery
->muic_cable_type
== ATTACHED_DEV_HMT_MUIC
&&
5343 battery
->muic_vbus_status
!= vbus_status
&&
5344 battery
->muic_vbus_status
== STATUS_VBUS_HIGH
&&
5345 vbus_status
== STATUS_VBUS_LOW
) {
5346 sec_bat_set_charge(battery
, false);
5348 value
.intval
= true;
5349 psy_do_property(battery
->pdata
->charger_name
, set
,
5350 POWER_SUPPLY_PROP_CHARGE_OTG_CONTROL
,
5352 dev_info(battery
->dev
,
5353 "%s: changed to OTG cable attached\n", __func__
);
5355 battery
->wire_status
= POWER_SUPPLY_TYPE_OTG
;
5356 wake_lock(&battery
->cable_wake_lock
);
5357 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->cable_work
, 0);
5359 pr_info("%s: action=%d, vbus_status=%d\n", __func__
, (int)action
, vbus_status
);
5360 battery
->muic_vbus_status
= vbus_status
;
5368 static int sec_bat_parse_dt(struct device
*dev
,
5369 struct sec_battery_info
*battery
)
5371 struct device_node
*np
= dev
->of_node
;
5372 sec_battery_platform_data_t
*pdata
= battery
->pdata
;
5379 pr_info("%s: np NULL\n", __func__
);
5383 pdata
->wchg_ctl_en
= of_property_read_bool(np
,
5384 "battery,wchg_ctl_en");
5385 if (pdata
->wchg_ctl_en
)
5386 pdata
->wchg_ctl
= of_get_named_gpio(np
, "battery,wchg_ctl", 0);
5388 ret
= of_property_read_string(np
,
5389 "battery,vendor", (char const **)&pdata
->vendor
);
5391 pr_info("%s: Vendor is Empty\n", __func__
);
5393 ret
= of_property_read_string(np
,
5394 "battery,charger_name", (char const **)&pdata
->charger_name
);
5396 pr_info("%s: Vendor is Empty\n", __func__
);
5398 ret
= of_property_read_string(np
,
5399 "battery,fuelgauge_name", (char const **)&pdata
->fuelgauge_name
);
5401 pr_info("%s: Vendor is Empty\n", __func__
);
5403 ret
= of_property_read_string(np
,
5404 "battery,wirelss_charger_name", (char const **)&pdata
->wireless_charger_name
);
5406 pr_info("%s: Vendor is Empty\n", __func__
);
5408 ret
= of_property_read_string(np
,
5409 "battery,chip_vendor", (char const **)&pdata
->chip_vendor
);
5411 pr_info("%s: Vendor is Empty\n", __func__
);
5413 ret
= of_property_read_u32(np
, "battery,technology",
5414 &pdata
->technology
);
5416 pr_info("%s : technology is Empty\n", __func__
);
5418 ret
= of_property_read_u32(np
,
5419 "battery,wireless_cc_cv", &pdata
->wireless_cc_cv
);
5421 pdata
->fake_capacity
= of_property_read_bool(np
,
5422 "battery,fake_capacity");
5424 pdata
->event_check
= of_property_read_bool(np
,
5425 "battery,event_check");
5427 p
= of_get_property(np
, "battery,polling_time", &len
);
5431 len
= len
/ sizeof(u32
);
5432 pdata
->polling_time
= kzalloc(sizeof(*pdata
->polling_time
) * len
, GFP_KERNEL
);
5433 ret
= of_property_read_u32_array(np
, "battery,polling_time",
5434 pdata
->polling_time
, len
);
5436 ret
= of_property_read_u32(np
, "battery,thermal_source",
5437 &pdata
->thermal_source
);
5439 pr_info("%s : Thermal source is Empty\n", __func__
);
5441 if (pdata
->thermal_source
== SEC_BATTERY_THERMAL_SOURCE_ADC
) {
5442 p
= of_get_property(np
, "battery,temp_table_adc", &len
);
5446 len
= len
/ sizeof(u32
);
5448 pdata
->temp_adc_table_size
= len
;
5449 pdata
->temp_amb_adc_table_size
= len
;
5451 pdata
->temp_adc_table
=
5452 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5453 pdata
->temp_adc_table_size
, GFP_KERNEL
);
5454 pdata
->temp_amb_adc_table
=
5455 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5456 pdata
->temp_adc_table_size
, GFP_KERNEL
);
5458 for(i
= 0; i
< pdata
->temp_adc_table_size
; i
++) {
5459 ret
= of_property_read_u32_index(np
,
5460 "battery,temp_table_adc", i
, &temp
);
5461 pdata
->temp_adc_table
[i
].adc
= (int)temp
;
5463 pr_info("%s : Temp_adc_table(adc) is Empty\n",
5466 ret
= of_property_read_u32_index(np
,
5467 "battery,temp_table_data", i
, &temp
);
5468 pdata
->temp_adc_table
[i
].data
= (int)temp
;
5470 pr_info("%s : Temp_adc_table(data) is Empty\n",
5473 ret
= of_property_read_u32_index(np
,
5474 "battery,temp_table_adc", i
, &temp
);
5475 pdata
->temp_amb_adc_table
[i
].adc
= (int)temp
;
5477 pr_info("%s : Temp_amb_adc_table(adc) is Empty\n",
5480 ret
= of_property_read_u32_index(np
,
5481 "battery,temp_table_data", i
, &temp
);
5482 pdata
->temp_amb_adc_table
[i
].data
= (int)temp
;
5484 pr_info("%s : Temp_amb_adc_table(data) is Empty\n",
5488 #if defined(CONFIG_AFC_CHARGER_MODE)
5489 p
= of_get_property(np
, "battery,chg_temp_table_adc", &len
);
5493 len
= len
/ sizeof(u32
);
5495 pdata
->chg_temp_adc_table_size
= len
;
5497 pdata
->chg_temp_adc_table
=
5498 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5499 pdata
->chg_temp_adc_table_size
, GFP_KERNEL
);
5501 for(i
= 0; i
< pdata
->chg_temp_adc_table_size
; i
++) {
5502 ret
= of_property_read_u32_index(np
,
5503 "battery,chg_temp_table_adc", i
, &temp
);
5504 pdata
->chg_temp_adc_table
[i
].adc
= (int)temp
;
5506 pr_info("%s : CHG_Temp_adc_table(adc) is Empty\n",
5509 ret
= of_property_read_u32_index(np
,
5510 "battery,chg_temp_table_data", i
, &temp
);
5511 pdata
->chg_temp_adc_table
[i
].data
= (int)temp
;
5513 pr_info("%s : CHG_Temp_adc_table(data) is Empty\n",
5519 ret
= of_property_read_u32(np
, "battery,chg_temp_check",
5520 &pdata
->chg_temp_check
);
5522 pr_info("%s : chg_temp_check is Empty\n", __func__
);
5524 if (pdata
->chg_temp_check
) {
5525 ret
= of_property_read_u32(np
, "battery,chg_high_temp_1st",
5527 pdata
->chg_high_temp_1st
= (int)temp
;
5529 pr_info("%s : chg_high_temp_threshold is Empty\n", __func__
);
5531 ret
= of_property_read_u32(np
, "battery,chg_high_temp_2nd",
5533 pdata
->chg_high_temp_2nd
= (int)temp
;
5535 pr_info("%s : chg_high_temp_threshold is Empty\n", __func__
);
5537 ret
= of_property_read_u32(np
, "battery,chg_high_temp_recovery",
5539 pdata
->chg_high_temp_recovery
= (int)temp
;
5541 pr_info("%s : chg_temp_recovery is Empty\n", __func__
);
5543 ret
= of_property_read_u32(np
, "battery,chg_charging_limit_current",
5544 &pdata
->chg_charging_limit_current
);
5546 pr_info("%s : chg_charging_limit_current is Empty\n", __func__
);
5548 ret
= of_property_read_u32(np
, "battery,chg_charging_limit_current_2nd",
5549 &pdata
->chg_charging_limit_current_2nd
);
5551 pr_info("%s : chg_charging_limit_current_2nd is Empty\n", __func__
);
5553 ret
= of_property_read_u32(np
, "battery,chg_skip_check_time",
5554 &pdata
->chg_skip_check_time
);
5556 pr_info("%s : chg_skip_check_time is Empty\n", __func__
);
5558 ret
= of_property_read_u32(np
, "battery,chg_skip_check_capacity",
5559 &pdata
->chg_skip_check_capacity
);
5561 pr_info("%s : chg_skip_check_capacity is Empty\n", __func__
);
5563 ret
= of_property_read_u32(np
, "battery,wpc_temp_check",
5564 &pdata
->wpc_temp_check
);
5566 pr_info("%s : wpc_temp_check is Empty\n", __func__
);
5568 if (pdata
->wpc_temp_check
) {
5569 ret
= of_property_read_u32(np
, "battery,wpc_high_temp",
5571 pdata
->wpc_high_temp
= (int)temp
;
5573 pr_info("%s : wpc_high_temp is Empty\n", __func__
);
5575 ret
= of_property_read_u32(np
, "battery,wpc_high_temp_recovery",
5577 pdata
->wpc_high_temp_recovery
= (int)temp
;
5579 pr_info("%s : wpc_high_temp_recovery is Empty\n", __func__
);
5581 ret
= of_property_read_u32(np
, "battery,wpc_charging_limit_current",
5582 &pdata
->wpc_charging_limit_current
);
5584 pr_info("%s : wpc_charging_limit_current is Empty\n", __func__
);
5588 ret
= of_property_read_u32(np
, "battery,inbat_voltage",
5589 &pdata
->inbat_voltage
);
5591 pr_info("%s : inbat_voltage is Empty\n", __func__
);
5593 if (pdata
->inbat_voltage
) {
5594 p
= of_get_property(np
, "battery,inbat_voltage_table_adc", &len
);
5598 len
= len
/ sizeof(u32
);
5600 pdata
->inbat_adc_table_size
= len
;
5602 pdata
->inbat_adc_table
=
5603 kzalloc(sizeof(sec_bat_adc_table_data_t
) *
5604 pdata
->inbat_adc_table_size
, GFP_KERNEL
);
5606 for(i
= 0; i
< pdata
->inbat_adc_table_size
; i
++) {
5607 ret
= of_property_read_u32_index(np
,
5608 "battery,inbat_voltage_table_adc", i
, &temp
);
5609 pdata
->inbat_adc_table
[i
].adc
= (int)temp
;
5611 pr_info("%s : inbat_adc_table(adc) is Empty\n",
5614 ret
= of_property_read_u32_index(np
,
5615 "battery,inbat_voltage_table_data", i
, &temp
);
5616 pdata
->inbat_adc_table
[i
].data
= (int)temp
;
5618 pr_info("%s : inbat_adc_table(data) is Empty\n",
5623 p
= of_get_property(np
, "battery,input_current_limit", &len
);
5627 len
= len
/ sizeof(u32
);
5629 pdata
->charging_current
=
5630 kzalloc(sizeof(sec_charging_current_t
) * len
,
5633 for(i
= 0; i
< len
; i
++) {
5634 ret
= of_property_read_u32_index(np
,
5635 "battery,input_current_limit", i
,
5636 &pdata
->charging_current
[i
].input_current_limit
);
5638 pr_info("%s : Input_current_limit is Empty\n",
5641 ret
= of_property_read_u32_index(np
,
5642 "battery,fast_charging_current", i
,
5643 &pdata
->charging_current
[i
].fast_charging_current
);
5645 pr_info("%s : Fast charging current is Empty\n",
5648 ret
= of_property_read_u32_index(np
,
5649 "battery,full_check_current_1st", i
,
5650 &pdata
->charging_current
[i
].full_check_current_1st
);
5652 pr_info("%s : Full check current 1st is Empty\n",
5655 ret
= of_property_read_u32_index(np
,
5656 "battery,full_check_current_2nd", i
,
5657 &pdata
->charging_current
[i
].full_check_current_2nd
);
5659 pr_info("%s : Full check current 2nd is Empty\n",
5663 ret
= of_property_read_u32(np
, "battery,adc_check_count",
5664 &pdata
->adc_check_count
);
5666 pr_info("%s : Adc check count is Empty\n", __func__
);
5668 ret
= of_property_read_u32(np
, "battery,temp_adc_type",
5669 &pdata
->temp_adc_type
);
5671 pr_info("%s : Temp adc type is Empty\n", __func__
);
5673 ret
= of_property_read_u32(np
, "battery,cable_check_type",
5674 &pdata
->cable_check_type
);
5676 pr_info("%s : Cable check type is Empty\n", __func__
);
5678 ret
= of_property_read_u32(np
, "battery,cable_source_type",
5679 &pdata
->cable_source_type
);
5680 #if defined(CONFIG_CHARGING_VZWCONCEPT)
5681 pdata
->cable_check_type
&= ~SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE
;
5682 pdata
->cable_check_type
|= SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE
;
5685 pr_info("%s : Cable source type is Empty\n", __func__
);
5687 ret
= of_property_read_u32(np
, "battery,event_waiting_time",
5688 &pdata
->event_waiting_time
);
5690 pr_info("%s : Event waiting time is Empty\n", __func__
);
5692 ret
= of_property_read_u32(np
, "battery,polling_type",
5693 &pdata
->polling_type
);
5695 pr_info("%s : Polling type is Empty\n", __func__
);
5697 ret
= of_property_read_u32(np
, "battery,monitor_initial_count",
5698 &pdata
->monitor_initial_count
);
5700 pr_info("%s : Monitor initial count is Empty\n", __func__
);
5702 ret
= of_property_read_u32(np
, "battery,battery_check_type",
5703 &pdata
->battery_check_type
);
5705 pr_info("%s : Battery check type is Empty\n", __func__
);
5707 ret
= of_property_read_u32(np
, "battery,check_count",
5708 &pdata
->check_count
);
5710 pr_info("%s : Check count is Empty\n", __func__
);
5712 ret
= of_property_read_u32(np
, "battery,check_adc_max",
5713 &pdata
->check_adc_max
);
5715 pr_info("%s : Check adc max is Empty\n", __func__
);
5717 ret
= of_property_read_u32(np
, "battery,check_adc_min",
5718 &pdata
->check_adc_min
);
5720 pr_info("%s : Check adc min is Empty\n", __func__
);
5722 ret
= of_property_read_u32(np
, "battery,ovp_uvlo_check_type",
5723 &pdata
->ovp_uvlo_check_type
);
5725 pr_info("%s : Ovp Uvlo check type is Empty\n", __func__
);
5727 ret
= of_property_read_u32(np
, "battery,temp_check_type",
5728 &pdata
->temp_check_type
);
5730 pr_info("%s : Temp check type is Empty\n", __func__
);
5732 ret
= of_property_read_u32(np
, "battery,temp_check_count",
5733 &pdata
->temp_check_count
);
5735 pr_info("%s : Temp check count is Empty\n", __func__
);
5737 ret
= of_property_read_u32(np
, "battery,temp_highlimit_threshold_event",
5739 pdata
->temp_highlimit_threshold_event
= (int)temp
;
5741 pr_info("%s : Temp highlimit threshold event is Empty\n", __func__
);
5743 ret
= of_property_read_u32(np
, "battery,temp_highlimit_recovery_event",
5745 pdata
->temp_highlimit_recovery_event
= (int)temp
;
5747 pr_info("%s : Temp highlimit recovery event is Empty\n", __func__
);
5749 ret
= of_property_read_u32(np
, "battery,temp_high_threshold_event",
5751 pdata
->temp_high_threshold_event
= (int)temp
;
5753 pr_info("%s : Temp high threshold event is Empty\n", __func__
);
5755 ret
= of_property_read_u32(np
, "battery,temp_high_recovery_event",
5757 pdata
->temp_high_recovery_event
= (int)temp
;
5759 pr_info("%s : Temp high recovery event is Empty\n", __func__
);
5761 ret
= of_property_read_u32(np
, "battery,temp_low_threshold_event",
5763 pdata
->temp_low_threshold_event
= (int)temp
;
5765 pr_info("%s : Temp low threshold event is Empty\n", __func__
);
5767 ret
= of_property_read_u32(np
, "battery,temp_low_recovery_event",
5769 pdata
->temp_low_recovery_event
= (int)temp
;
5771 pr_info("%s : Temp low recovery event is Empty\n", __func__
);
5773 ret
= of_property_read_u32(np
, "battery,temp_highlimit_threshold_normal",
5775 pdata
->temp_highlimit_threshold_normal
= (int)temp
;
5777 pr_info("%s : Temp highlimit threshold normal is Empty\n", __func__
);
5779 ret
= of_property_read_u32(np
, "battery,temp_highlimit_recovery_normal",
5781 pdata
->temp_highlimit_recovery_normal
= (int)temp
;
5783 pr_info("%s : Temp highlimit recovery normal is Empty\n", __func__
);
5785 ret
= of_property_read_u32(np
, "battery,temp_high_threshold_normal",
5787 pdata
->temp_high_threshold_normal
= (int)temp
;
5789 pr_info("%s : Temp high threshold normal is Empty\n", __func__
);
5791 ret
= of_property_read_u32(np
, "battery,temp_high_recovery_normal",
5793 pdata
->temp_high_recovery_normal
= (int)temp
;
5795 pr_info("%s : Temp high recovery normal is Empty\n", __func__
);
5797 ret
= of_property_read_u32(np
, "battery,temp_low_threshold_normal",
5799 pdata
->temp_low_threshold_normal
= (int)temp
;
5801 pr_info("%s : Temp low threshold normal is Empty\n", __func__
);
5803 ret
= of_property_read_u32(np
, "battery,temp_low_recovery_normal",
5805 pdata
->temp_low_recovery_normal
= (int)temp
;
5807 pr_info("%s : Temp low recovery normal is Empty\n", __func__
);
5809 ret
= of_property_read_u32(np
, "battery,temp_highlimit_threshold_lpm",
5811 pdata
->temp_highlimit_threshold_lpm
= (int)temp
;
5813 pr_info("%s : Temp highlimit threshold lpm is Empty\n", __func__
);
5815 ret
= of_property_read_u32(np
, "battery,temp_highlimit_recovery_lpm",
5817 pdata
->temp_highlimit_recovery_lpm
= (int)temp
;
5819 pr_info("%s : Temp highlimit recovery lpm is Empty\n", __func__
);
5821 ret
= of_property_read_u32(np
, "battery,temp_high_threshold_lpm",
5823 pdata
->temp_high_threshold_lpm
= (int)temp
;
5825 pr_info("%s : Temp high threshold lpm is Empty\n", __func__
);
5827 ret
= of_property_read_u32(np
, "battery,temp_high_recovery_lpm",
5829 pdata
->temp_high_recovery_lpm
= (int)temp
;
5831 pr_info("%s : Temp high recovery lpm is Empty\n", __func__
);
5833 ret
= of_property_read_u32(np
, "battery,temp_low_threshold_lpm",
5835 pdata
->temp_low_threshold_lpm
= (int)temp
;
5837 pr_info("%s : Temp low threshold lpm is Empty\n", __func__
);
5839 ret
= of_property_read_u32(np
, "battery,temp_low_recovery_lpm",
5841 pdata
->temp_low_recovery_lpm
= (int)temp
;
5843 pr_info("%s : Temp low recovery lpm is Empty\n", __func__
);
5845 pr_info("%s : HIGHLIMIT_THRESHOLD_EVENT(%d), HIGHLIMIT_RECOVERY_EVENT(%d)\n"
5846 "HIGH_THRESHOLD_EVENT(%d), HIGH_RECOVERY_EVENT(%d) LOW_THRESHOLD_EVENT(%d), LOW_RECOVERY_EVENT(%d)\n"
5847 "HIGHLIMIT_THRESHOLD_NOLMAL(%d), HIGHLIMIT_RECOVERY_NORMAL(%d)\n"
5848 "HIGH_THRESHOLD_NORMAL(%d), HIGH_RECOVERY_NORMAL(%d) LOW_THRESHOLD_NORMAL(%d), LOW_RECOVERY_NORMAL(%d)\n"
5849 "HIGHLIMIT_THRESHOLD_LPM(%d), HIGHLIMIT_RECOVERY_LPM(%d)\n"
5850 "HIGH_THRESHOLD_LPM(%d), HIGH_RECOVERY_LPM(%d) LOW_THRESHOLD_LPM(%d), LOW_RECOVERY_LPM(%d)\n",
5851 __func__
, pdata
->temp_highlimit_threshold_event
, pdata
->temp_highlimit_recovery_event
,
5852 pdata
->temp_high_threshold_event
, pdata
->temp_high_recovery_event
,
5853 pdata
->temp_low_threshold_event
, pdata
->temp_low_recovery_event
,
5854 pdata
->temp_highlimit_threshold_normal
, pdata
->temp_highlimit_recovery_normal
,
5855 pdata
->temp_high_threshold_normal
, pdata
->temp_high_recovery_normal
,
5856 pdata
->temp_low_threshold_normal
, pdata
->temp_low_recovery_normal
,
5857 pdata
->temp_highlimit_threshold_lpm
, pdata
->temp_highlimit_recovery_lpm
,
5858 pdata
->temp_high_threshold_lpm
, pdata
->temp_high_recovery_lpm
,
5859 pdata
->temp_low_threshold_lpm
, pdata
->temp_low_recovery_lpm
);
5861 ret
= of_property_read_u32(np
, "battery,full_check_type",
5862 &pdata
->full_check_type
);
5864 pr_info("%s : Full check type is Empty\n", __func__
);
5866 ret
= of_property_read_u32(np
, "battery,full_check_type_2nd",
5867 &pdata
->full_check_type_2nd
);
5869 pr_info("%s : Full check type 2nd is Empty\n", __func__
);
5871 ret
= of_property_read_u32(np
, "battery,full_check_count",
5872 &pdata
->full_check_count
);
5874 pr_info("%s : Full check count is Empty\n", __func__
);
5876 ret
= of_property_read_u32(np
, "battery,chg_gpio_full_check",
5877 &pdata
->chg_gpio_full_check
);
5879 pr_info("%s : Chg gpio full check is Empty\n", __func__
);
5881 ret
= of_property_read_u32(np
, "battery,chg_polarity_full_check",
5882 &pdata
->chg_polarity_full_check
);
5884 pr_info("%s : Chg polarity full check is Empty\n", __func__
);
5886 ret
= of_property_read_u32(np
, "battery,full_condition_type",
5887 &pdata
->full_condition_type
);
5889 pr_info("%s : Full condition type is Empty\n", __func__
);
5891 ret
= of_property_read_u32(np
, "battery,full_condition_soc",
5892 &pdata
->full_condition_soc
);
5894 pr_info("%s : Full condition soc is Empty\n", __func__
);
5896 ret
= of_property_read_u32(np
, "battery,full_condition_vcell",
5897 &pdata
->full_condition_vcell
);
5899 pr_info("%s : Full condition vcell is Empty\n", __func__
);
5901 ret
= of_property_read_u32(np
, "battery,recharge_check_count",
5902 &pdata
->recharge_check_count
);
5904 pr_info("%s : Recharge check count is Empty\n", __func__
);
5906 ret
= of_property_read_u32(np
, "battery,recharge_condition_type",
5907 &pdata
->recharge_condition_type
);
5909 pr_info("%s : Recharge condition type is Empty\n", __func__
);
5911 ret
= of_property_read_u32(np
, "battery,recharge_condition_soc",
5912 &pdata
->recharge_condition_soc
);
5914 pr_info("%s : Recharge condition soc is Empty\n", __func__
);
5916 ret
= of_property_read_u32(np
, "battery,recharge_condition_vcell",
5917 &pdata
->recharge_condition_vcell
);
5919 pr_info("%s : Recharge condition vcell is Empty\n", __func__
);
5921 ret
= of_property_read_u32(np
, "battery,charging_total_time",
5922 (unsigned int *)&pdata
->charging_total_time
);
5924 pr_info("%s : Charging total time is Empty\n", __func__
);
5926 ret
= of_property_read_u32(np
, "battery,hv_charging_total_time",
5927 (unsigned int *)&pdata
->hv_charging_total_time
);
5929 pdata
->hv_charging_total_time
= 3 * 60 * 60;
5930 pr_info("%s : HV Charging total time is %d\n",
5931 __func__
, pdata
->hv_charging_total_time
);
5934 ret
= of_property_read_u32(np
, "battery,normal_charging_total_time",
5935 (unsigned int *)&pdata
->normal_charging_total_time
);
5937 pdata
->normal_charging_total_time
= 5 * 60 * 60;
5938 pr_info("%s : Normal(WC) Charging total time is %d\n",
5939 __func__
, pdata
->normal_charging_total_time
);
5942 ret
= of_property_read_u32(np
, "battery,usb_charging_total_time",
5943 (unsigned int *)&pdata
->usb_charging_total_time
);
5945 pdata
->usb_charging_total_time
= 10 * 60 * 60;
5946 pr_info("%s : USB Charging total time is %d\n",
5947 __func__
, pdata
->usb_charging_total_time
);
5950 ret
= of_property_read_u32(np
, "battery,recharging_total_time",
5951 (unsigned int *)&pdata
->recharging_total_time
);
5953 pr_info("%s : Recharging total time is Empty\n", __func__
);
5955 ret
= of_property_read_u32(np
, "battery,charging_reset_time",
5956 (unsigned int *)&pdata
->charging_reset_time
);
5958 pr_info("%s : Charging reset time is Empty\n", __func__
);
5960 ret
= of_property_read_u32(np
, "battery,charging_reset_time",
5961 (unsigned int *)&pdata
->charging_reset_time
);
5963 pr_info("%s : Charging reset time is Empty\n", __func__
);
5965 ret
= of_property_read_u32(np
,
5966 "battery,expired_time", &temp
);
5968 pr_info("expired time is empty\n");
5969 pdata
->expired_time
= 3 * 60 * 60;
5971 pdata
->expired_time
= (unsigned int) temp
;
5973 pdata
->expired_time
*= 100;
5974 battery
->expired_time
= pdata
->expired_time
;
5976 ret
= of_property_read_u32(np
,
5977 "battery,recharging_expired_time", &temp
);
5979 pr_info("expired time is empty\n");
5980 pdata
->recharging_expired_time
= 90 * 60;
5982 pdata
->recharging_expired_time
= (unsigned int) temp
;
5984 pdata
->recharging_expired_time
*= 1000;
5986 ret
= of_property_read_u32(np
,
5987 "battery,standard_curr", &pdata
->standard_curr
);
5989 pr_info("standard_curr is empty\n");
5990 pdata
->standard_curr
= 2150;
5993 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
5994 ret
= of_property_read_u32(np
, "battery,self_discharging_type",
5995 (unsigned int *)&pdata
->self_discharging_type
);
5997 pr_info("%s: Self discharging type is Empty, Set default\n",
5999 pdata
->self_discharging_type
= 0;
6002 pdata
->factory_discharging
= of_get_named_gpio(np
, "battery,factory_discharging", 0);
6003 if (pdata
->factory_discharging
< 0)
6004 pdata
->factory_discharging
= 0;
6006 pdata
->self_discharging_en
= of_property_read_bool(np
,
6007 "battery,self_discharging_en");
6009 ret
= of_property_read_u32(np
, "battery,force_discharging_limit",
6011 pdata
->force_discharging_limit
= (int)temp
;
6013 pr_info("%s : Force Discharging limit is Empty", __func__
);
6015 ret
= of_property_read_u32(np
, "battery,force_discharging_recov",
6017 pdata
->force_discharging_recov
= (int)temp
;
6019 pr_info("%s : Force Discharging recov is Empty", __func__
);
6021 pr_info("%s : FORCE_DISCHARGING_LIMT(%d), FORCE_DISCHARGING_RECOV(%d)\n",
6022 __func__
, pdata
->force_discharging_limit
, pdata
->force_discharging_recov
);
6024 if (!pdata
->self_discharging_type
) {
6025 ret
= of_property_read_u32(np
, "battery,discharging_adc_min",
6026 (unsigned int *)&pdata
->discharging_adc_min
);
6028 pr_info("%s : Discharging ADC Min is Empty", __func__
);
6030 ret
= of_property_read_u32(np
, "battery,discharging_adc_max",
6031 (unsigned int *)&pdata
->discharging_adc_max
);;
6033 pr_info("%s : Discharging ADC Max is Empty", __func__
);
6036 ret
= of_property_read_u32(np
, "battery,self_discharging_voltage_limit",
6037 (unsigned int *)&pdata
->self_discharging_voltage_limit
);
6039 pr_info("%s : Force Discharging recov is Empty", __func__
);
6041 ret
= of_property_read_u32(np
, "battery,discharging_ntc_limit",
6042 (unsigned int *)&pdata
->discharging_ntc_limit
);
6044 pr_info("%s : Discharging NTC LIMIT is Empty", __func__
);
6047 #if defined(CONFIG_BATTERY_SWELLING)
6048 ret
= of_property_read_u32(np
, "battery,swelling_normal_current",
6049 (unsigned int *)&pdata
->swelling_normal_current
);
6051 pr_info("%s: swelling_normal_current is Empty\n", __func__
);
6053 ret
= of_property_read_u32(np
, "battery,chg_float_voltage",
6054 (unsigned int *)&pdata
->swelling_normal_float_voltage
);
6056 pr_info("%s: chg_float_voltage is Empty\n", __func__
);
6058 ret
= of_property_read_u32(np
, "battery,chg_float_voltage",
6059 (unsigned int *)&pdata
->chg_float_voltage
);
6061 pr_info("%s: chg_float_voltage is Empty\n", __func__
);
6063 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_block",
6065 pdata
->swelling_high_temp_block
= (int)temp
;
6067 pr_info("%s: swelling high temp block is Empty\n", __func__
);
6069 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_recov",
6071 pdata
->swelling_high_temp_recov
= (int)temp
;
6073 pr_info("%s: swelling high temp recovery is Empty\n", __func__
);
6075 ret
= of_property_read_u32(np
, "battery,swelling_high_chg_current",
6076 &pdata
->swelling_high_chg_current
);
6078 pr_info("%s: swelling high temp chg current is Empty\n", __func__
);
6079 pdata
->swelling_high_chg_current
= 0;
6082 ret
= of_property_read_u32(np
, "battery,swelling_low_chg_current",
6083 &pdata
->swelling_low_chg_current
);
6085 pr_info("%s: swelling low temp chg current is Empty\n", __func__
);
6086 pdata
->swelling_low_chg_current
= 0;
6089 ret
= of_property_read_u32(np
, "battery,swelling_full_check_current_2nd",
6090 &pdata
->swelling_full_check_current_2nd
);
6092 pr_info("%s: swelling_full_check_current_2nd is Empty\n", __func__
);
6093 pdata
->swelling_full_check_current_2nd
= 0;
6096 ret
= of_property_read_u32(np
, "battery,swelling_drop_float_voltage",
6097 (unsigned int *)&pdata
->swelling_drop_float_voltage
);
6099 pr_info("%s: swelling drop float voltage is Empty\n", __func__
);
6101 ret
= of_property_read_u32(np
, "battery,swelling_high_rechg_voltage",
6102 (unsigned int *)&pdata
->swelling_high_rechg_voltage
);
6104 pr_info("%s: swelling_high_rechg_voltage is Empty\n", __func__
);
6106 ret
= of_property_read_u32(np
, "battery,swelling_low_rechg_voltage",
6107 (unsigned int *)&pdata
->swelling_low_rechg_voltage
);
6109 pr_info("%s: swelling_low_rechg_voltage is Empty\n", __func__
);
6111 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_2step_mode",
6112 &pdata
->swelling_low_temp_2step_mode
);
6114 pr_info("%s: swelling_low_temp_2step_mode is Empty\n", __func__
);
6115 pdata
->swelling_low_temp_2step_mode
= 0;
6118 if(pdata
->swelling_low_temp_2step_mode
) {
6119 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_block_1st",
6121 pdata
->swelling_low_temp_block_1st
= (int)temp
;
6123 pr_info("%s: swelling low temp block is Empty\n", __func__
);
6125 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_recov_1st",
6127 pdata
->swelling_low_temp_recov_1st
= (int)temp
;
6129 pr_info("%s: swelling low temp recovery is Empty\n", __func__
);
6131 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_block_2nd",
6133 pdata
->swelling_low_temp_block_2nd
= (int)temp
;
6135 pr_info("%s: swelling low temp block is Empty\n", __func__
);
6137 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_recov_2nd",
6139 pdata
->swelling_low_temp_recov_2nd
= (int)temp
;
6141 pr_info("%s: swelling low temp recovery 2nd is Empty\n", __func__
);
6144 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_block",
6146 pdata
->swelling_low_temp_block_1st
= (int)temp
;
6147 pdata
->swelling_low_temp_block_2nd
= (int)temp
;
6149 pr_info("%s: swelling low temp block is Empty\n", __func__
);
6151 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_recov",
6153 pdata
->swelling_low_temp_recov_1st
= (int)temp
;
6154 pdata
->swelling_low_temp_recov_2nd
= (int)temp
;
6156 pr_info("%s: swelling low temp recovery is Empty\n", __func__
);
6159 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_current",
6160 &pdata
->swelling_low_temp_current
);
6162 pr_info("%s: swelling_low_temp_current is Empty, Defualt value 600mA \n", __func__
);
6163 pdata
->swelling_low_temp_current
= 600;
6166 ret
= of_property_read_u32(np
, "battery,swelling_low_temp_topoff",
6167 &pdata
->swelling_low_temp_topoff
);
6169 pr_info("%s: swelling_low_temp_topoff is Empty, Defualt value 200mA \n", __func__
);
6170 pdata
->swelling_low_temp_topoff
= 200;
6173 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_current",
6174 &pdata
->swelling_high_temp_current
);
6176 pr_info("%s: swelling_hign_temp_current is Empty, Defualt value 1300mA \n", __func__
);
6177 pdata
->swelling_high_temp_current
= 1300;
6180 ret
= of_property_read_u32(np
, "battery,swelling_high_temp_topoff",
6181 &pdata
->swelling_high_temp_topoff
);
6183 pr_info("%s: swelling_high_temp_topoff is Empty, Defualt value 200mA \n", __func__
);
6184 pdata
->swelling_high_temp_topoff
= 200;
6187 ret
= of_property_read_u32(np
, "battery,swelling_block_time",
6188 (unsigned int *)&pdata
->swelling_block_time
);
6190 pr_info("%s: swelling_block_time is Empty\n", __func__
);
6192 pr_info("%s : SWELLING_HIGH_TEMP(%d) SWELLING_HIGH_TEMP_RECOVERY(%d)\n"
6193 "SWELLING_LOW_TEMP_1st(%d) SWELLING_LOW_TEMP_RECOVERY_1st(%d) "
6194 "SWELLING_LOW_TEMP_2nd(%d) SWELLING_LOW_TEMP_RECOVERY_2nd(%d) "
6195 "SWELLING_LOW_CURRENT(%d, %d), SWELLING_HIGH_CURRENT(%d, %d)\n",
6196 __func__
, pdata
->swelling_high_temp_block
, pdata
->swelling_high_temp_recov
,
6197 pdata
->swelling_low_temp_block_1st
, pdata
->swelling_low_temp_recov_1st
,
6198 pdata
->swelling_low_temp_block_2nd
, pdata
->swelling_low_temp_recov_2nd
,
6199 pdata
->swelling_low_temp_current
, pdata
->swelling_low_temp_topoff
,
6200 pdata
->swelling_high_temp_current
, pdata
->swelling_high_temp_topoff
);
6204 pdata
->always_enable
= of_property_read_bool(np
,
6205 "battery,always_enable");
6207 #if defined(CONFIG_BATTERY_AGE_FORECAST)
6208 p
= of_get_property(np
, "battery,age_data", &len
);
6210 battery
->pdata
->num_age_step
= len
/ sizeof(sec_age_data_t
);
6211 battery
->pdata
->age_data
= kzalloc(len
, GFP_KERNEL
);
6212 ret
= of_property_read_u32_array(np
, "battery,age_data",
6213 (u32
*)battery
->pdata
->age_data
, len
/sizeof(u32
));
6215 pr_err("%s failed to read battery->pdata->age_data: %d\n",
6217 kfree(battery
->pdata
->age_data
);
6218 battery
->pdata
->age_data
= NULL
;
6219 battery
->pdata
->num_age_step
= 0;
6221 pr_err("%s num_age_step : %d\n", __func__
, battery
->pdata
->num_age_step
);
6222 for (len
= 0; len
< battery
->pdata
->num_age_step
; ++len
) {
6223 pr_err("[%d/%d]cycle:%d, float:%d, full_v:%d, recharge_v:%d, soc:%d\n",
6224 len
, battery
->pdata
->num_age_step
-1,
6225 battery
->pdata
->age_data
[len
].cycle
,
6226 battery
->pdata
->age_data
[len
].float_voltage
,
6227 battery
->pdata
->age_data
[len
].recharge_condition_vcell
,
6228 battery
->pdata
->age_data
[len
].full_condition_vcell
,
6229 battery
->pdata
->age_data
[len
].full_condition_soc
);
6232 battery
->pdata
->num_age_step
= 0;
6233 pr_err("%s there is not age_data\n", __func__
);
6241 extern sec_battery_platform_data_t sec_battery_pdata
;
6244 static void cable_initial_check(struct sec_battery_info
*battery
)
6246 union power_supply_propval value
;
6248 pr_info("%s : current_cable_type : (%d)\n", __func__
, battery
->cable_type
);
6250 if (battery
->cable_type
== POWER_SUPPLY_TYPE_BATTERY
) {
6251 psy_do_property(battery
->pdata
->charger_name
, get
,
6252 POWER_SUPPLY_PROP_ONLINE
, value
);
6253 if (value
.intval
== POWER_SUPPLY_TYPE_WIRELESS
) {
6255 psy_do_property("wireless", set
,
6256 POWER_SUPPLY_PROP_ONLINE
, value
);
6261 static int __devinit
sec_battery_probe(struct platform_device
*pdev
)
6263 sec_battery_platform_data_t
*pdata
= NULL
;
6264 struct sec_battery_info
*battery
;
6270 union power_supply_propval value
;
6273 "%s: SEC Battery Driver Loading\n", __func__
);
6275 battery
= kzalloc(sizeof(*battery
), GFP_KERNEL
);
6279 if (pdev
->dev
.of_node
) {
6280 pdata
= devm_kzalloc(&pdev
->dev
,
6281 sizeof(sec_battery_platform_data_t
),
6284 dev_err(&pdev
->dev
, "Failed to allocate memory\n");
6289 battery
->pdata
= pdata
;
6290 if (sec_bat_parse_dt(&pdev
->dev
, battery
)) {
6292 "%s: Failed to get battery dt\n", __func__
);
6297 pdata
= dev_get_platdata(&pdev
->dev
);
6298 battery
->pdata
= pdata
;
6301 platform_set_drvdata(pdev
, battery
);
6303 battery
->dev
= &pdev
->dev
;
6305 mutex_init(&battery
->adclock
);
6306 mutex_init(&battery
->current_eventlock
);
6308 dev_dbg(battery
->dev
, "%s: ADC init\n", __func__
);
6311 adc_init(pdev
, battery
);
6313 for (i
= 0; i
< SEC_BAT_ADC_CHANNEL_NUM
; i
++)
6314 adc_init(pdev
, pdata
, i
);
6316 wake_lock_init(&battery
->monitor_wake_lock
, WAKE_LOCK_SUSPEND
,
6317 "sec-battery-monitor");
6318 wake_lock_init(&battery
->cable_wake_lock
, WAKE_LOCK_SUSPEND
,
6319 "sec-battery-cable");
6320 wake_lock_init(&battery
->vbus_wake_lock
, WAKE_LOCK_SUSPEND
,
6321 "sec-battery-vbus");
6322 wake_lock_init(&battery
->siop_wake_lock
, WAKE_LOCK_SUSPEND
,
6323 "sec-battery-siop");
6325 /* initialization of battery info */
6326 sec_bat_set_charging_status(battery
,
6327 POWER_SUPPLY_STATUS_DISCHARGING
);
6328 battery
->health
= POWER_SUPPLY_HEALTH_GOOD
;
6329 battery
->present
= true;
6330 battery
->is_jig_on
= false;
6332 battery
->polling_count
= 1; /* initial value = 1 */
6333 battery
->polling_time
= pdata
->polling_time
[
6334 SEC_BATTERY_POLLING_TIME_DISCHARGING
];
6335 battery
->polling_in_sleep
= false;
6336 battery
->polling_short
= false;
6338 battery
->check_count
= 0;
6339 battery
->check_adc_count
= 0;
6340 battery
->check_adc_value
= 0;
6342 battery
->charging_start_time
= 0;
6343 battery
->charging_passed_time
= 0;
6344 battery
->charging_next_time
= 0;
6345 battery
->charging_fullcharged_time
= 0;
6346 battery
->siop_level
= 100;
6347 battery
->r_siop_level
= 100;
6348 battery
->wc_enable
= 1;
6349 battery
->pre_chg_temp
= 0;
6350 #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
6351 battery
->stability_test
= 0;
6352 battery
->eng_not_full_status
= 0;
6354 battery
->wc_status
= 0;
6355 battery
->ps_status
= 0;
6356 battery
->ps_changed
= 0;
6357 battery
->wire_status
= POWER_SUPPLY_TYPE_BATTERY
;
6358 #if defined(CONFIG_BATTERY_SWELLING)
6359 battery
->swelling_mode
= false;
6361 battery
->charging_block
= false;
6362 battery
->chg_limit
= SEC_BATTERY_CHG_TEMP_NONE
;
6364 #if defined(ANDROID_ALARM_ACTIVATED)
6365 alarm_init(&battery
->event_termination_alarm
,
6366 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP
,
6367 sec_bat_event_expired_timer_func
);
6369 alarm_init(&battery
->event_termination_alarm
,
6371 sec_bat_event_expired_timer_func
);
6373 battery
->temp_highlimit_threshold
=
6374 pdata
->temp_highlimit_threshold_normal
;
6375 battery
->temp_highlimit_recovery
=
6376 pdata
->temp_highlimit_recovery_normal
;
6377 battery
->temp_high_threshold
=
6378 pdata
->temp_high_threshold_normal
;
6379 battery
->temp_high_recovery
=
6380 pdata
->temp_high_recovery_normal
;
6381 battery
->temp_low_recovery
=
6382 pdata
->temp_low_recovery_normal
;
6383 battery
->temp_low_threshold
=
6384 pdata
->temp_low_threshold_normal
;
6386 battery
->charging_mode
= SEC_BATTERY_CHARGING_NONE
;
6387 battery
->is_recharging
= false;
6388 battery
->cable_type
= POWER_SUPPLY_TYPE_BATTERY
;
6389 battery
->test_mode
= 0;
6390 battery
->factory_mode
= false;
6391 battery
->store_mode
= false;
6392 battery
->ignore_store_mode
= false;
6393 battery
->slate_mode
= false;
6394 slate_mode_state
= battery
->slate_mode
;
6395 battery
->is_hc_usb
= false;
6396 battery
->ignore_siop
= false;
6398 battery
->safety_timer_set
= true;
6399 battery
->stop_timer
= false;
6400 battery
->prev_safety_time
= 0;
6401 battery
->lcd_status
= false;
6402 battery
->current_event
= 0;
6404 battery
->batt_cycle
= -1;
6405 #if defined(CONFIG_BATTERY_AGE_FORECAST)
6406 battery
->pdata
->age_step
= 0;
6409 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6410 battery
->self_discharging
= false;
6411 battery
->force_discharging
= false;
6412 battery
->factory_self_discharging_mode_on
= false;
6415 if (battery
->pdata
->charger_name
== NULL
)
6416 battery
->pdata
->charger_name
= "sec-charger";
6417 if (battery
->pdata
->fuelgauge_name
== NULL
)
6418 battery
->pdata
->fuelgauge_name
= "sec-fuelgauge";
6420 #if defined(CONFIG_CHARGER_MAX77843) || defined(CONFIG_CHARGER_MAX77833)
6421 pr_info("%s : CHARGER CHIP NAME (%s)\n", __func__
, charger_chip_name
);
6422 if (charger_chip_name
!= NULL
&& !strcmp(charger_chip_name
,"max77843-charger")) {
6423 battery
->pdata
->charger_name
= "max77843-charger";
6424 battery
->pdata
->fuelgauge_name
= "max77843-fuelgauge";
6425 } else if (!strcmp(charger_chip_name
, "max77833-charger")) {
6426 battery
->pdata
->charger_name
= "max77833-charger";
6427 battery
->pdata
->fuelgauge_name
= "max77833-fuelgauge";
6431 battery
->psy_bat
.name
= "battery",
6432 battery
->psy_bat
.type
= POWER_SUPPLY_TYPE_BATTERY
,
6433 battery
->psy_bat
.properties
= sec_battery_props
,
6434 battery
->psy_bat
.num_properties
= ARRAY_SIZE(sec_battery_props
),
6435 battery
->psy_bat
.get_property
= sec_bat_get_property
,
6436 battery
->psy_bat
.set_property
= sec_bat_set_property
,
6437 battery
->psy_usb
.name
= "usb",
6438 battery
->psy_usb
.type
= POWER_SUPPLY_TYPE_USB
,
6439 battery
->psy_usb
.supplied_to
= supply_list
,
6440 battery
->psy_usb
.num_supplicants
= ARRAY_SIZE(supply_list
),
6441 battery
->psy_usb
.properties
= sec_power_props
,
6442 battery
->psy_usb
.num_properties
= ARRAY_SIZE(sec_power_props
),
6443 battery
->psy_usb
.get_property
= sec_usb_get_property
,
6444 battery
->psy_ac
.name
= "ac",
6445 battery
->psy_ac
.type
= POWER_SUPPLY_TYPE_MAINS
,
6446 battery
->psy_ac
.supplied_to
= supply_list
,
6447 battery
->psy_ac
.num_supplicants
= ARRAY_SIZE(supply_list
),
6448 battery
->psy_ac
.properties
= sec_power_props
,
6449 battery
->psy_ac
.num_properties
= ARRAY_SIZE(sec_power_props
),
6450 battery
->psy_ac
.get_property
= sec_ac_get_property
;
6451 battery
->psy_wireless
.name
= "wireless",
6452 battery
->psy_wireless
.type
= POWER_SUPPLY_TYPE_WIRELESS
,
6453 battery
->psy_wireless
.supplied_to
= supply_list
,
6454 battery
->psy_wireless
.num_supplicants
= ARRAY_SIZE(supply_list
),
6455 battery
->psy_wireless
.properties
= sec_power_props
,
6456 battery
->psy_wireless
.num_properties
= ARRAY_SIZE(sec_power_props
),
6457 battery
->psy_wireless
.get_property
= sec_wireless_get_property
;
6458 battery
->psy_wireless
.set_property
= sec_wireless_set_property
;
6459 battery
->psy_ps
.name
= "ps",
6460 battery
->psy_ps
.type
= POWER_SUPPLY_TYPE_POWER_SHARING
,
6461 battery
->psy_ps
.supplied_to
= supply_list
,
6462 battery
->psy_ps
.num_supplicants
= ARRAY_SIZE(supply_list
),
6463 battery
->psy_ps
.properties
= sec_ps_props
,
6464 battery
->psy_ps
.num_properties
= ARRAY_SIZE(sec_ps_props
),
6465 battery
->psy_ps
.get_property
= sec_ps_get_property
;
6466 battery
->psy_ps
.set_property
= sec_ps_set_property
;
6468 if (battery
->pdata
->wchg_ctl_en
) {
6469 ret
= gpio_request(battery
->pdata
->wchg_ctl
, "WCHG_CTL");
6471 pr_err("failed to request GPIO %u\n", battery
->pdata
->wchg_ctl
);
6474 gpio_direction_output(battery
->pdata
->wchg_ctl
, 0);
6475 pr_info("%s : GPIO %d\n", __func__
, gpio_get_value(battery
->pdata
->wchg_ctl
));
6478 #if defined (CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6479 if (battery
->pdata
->factory_discharging
) {
6480 ret
= gpio_request(battery
->pdata
->factory_discharging
, "FACTORY_DISCHARGING");
6482 pr_err("failed to request GPIO %u\n", battery
->pdata
->factory_discharging
);
6487 /* create work queue */
6488 battery
->monitor_wqueue
=
6489 alloc_workqueue(dev_name(&pdev
->dev
), WQ_MEM_RECLAIM
, 1);
6490 if (!battery
->monitor_wqueue
) {
6491 dev_err(battery
->dev
,
6492 "%s: Fail to Create Workqueue\n", __func__
);
6496 INIT_DELAYED_WORK(&battery
->monitor_work
, sec_bat_monitor_work
);
6497 INIT_DELAYED_WORK(&battery
->cable_work
, sec_bat_cable_work
);
6498 #if defined(CONFIG_CALC_TIME_TO_FULL)
6499 INIT_DELAYED_WORK(&battery
->timetofull_work
, sec_bat_time_to_full_work
);
6501 INIT_DELAYED_WORK(&battery
->siop_work
, sec_bat_siop_work
);
6503 switch (pdata
->polling_type
) {
6504 case SEC_BATTERY_MONITOR_WORKQUEUE
:
6505 INIT_DELAYED_WORK(&battery
->polling_work
,
6506 sec_bat_polling_work
);
6508 case SEC_BATTERY_MONITOR_ALARM
:
6509 #if defined(ANDROID_ALARM_ACTIVATED)
6510 battery
->last_poll_time
= alarm_get_elapsed_realtime();
6511 alarm_init(&battery
->polling_alarm
,
6512 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP
,
6515 battery
->last_poll_time
= ktime_get_boottime();
6516 alarm_init(&battery
->polling_alarm
, ALARM_BOOTTIME
,
6524 /* init power supplier framework */
6525 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_ps
);
6527 dev_err(battery
->dev
,
6528 "%s: Failed to Register psy_ps\n", __func__
);
6532 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_wireless
);
6534 dev_err(battery
->dev
,
6535 "%s: Failed to Register psy_wireless\n", __func__
);
6536 goto err_supply_unreg_ps
;
6539 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_usb
);
6541 dev_err(battery
->dev
,
6542 "%s: Failed to Register psy_usb\n", __func__
);
6543 goto err_supply_unreg_wireless
;
6546 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_ac
);
6548 dev_err(battery
->dev
,
6549 "%s: Failed to Register psy_ac\n", __func__
);
6550 goto err_supply_unreg_usb
;
6553 ret
= power_supply_register(&pdev
->dev
, &battery
->psy_bat
);
6555 dev_err(battery
->dev
,
6556 "%s: Failed to Register psy_bat\n", __func__
);
6557 goto err_supply_unreg_ac
;
6560 if (battery
->pdata
->bat_gpio_init
&& !battery
->pdata
->bat_gpio_init()) {
6561 dev_err(battery
->dev
,
6562 "%s: Failed to Initialize GPIO\n", __func__
);
6563 goto err_supply_unreg_bat
;
6566 if (battery
->pdata
->bat_irq
) {
6567 ret
= request_threaded_irq(battery
->pdata
->bat_irq
,
6568 NULL
, sec_bat_irq_thread
,
6569 battery
->pdata
->bat_irq_attr
6571 "battery-irq", battery
);
6573 dev_err(battery
->dev
,
6574 "%s: Failed to Request IRQ (bat_int)\n", __func__
);
6575 goto err_supply_unreg_bat
;
6577 if (battery
->pdata
->bat_irq_gpio
) {
6578 ret
= enable_irq_wake(battery
->pdata
->bat_irq
);
6580 dev_err(battery
->dev
,
6581 "%s: Failed to Enable Wakeup Source(%d)(bat_int)\n",
6587 ret
= sec_bat_create_attrs(battery
->psy_bat
.dev
);
6589 dev_err(battery
->dev
,
6590 "%s : Failed to create_attrs\n", __func__
);
6594 #if defined(CONFIG_MUIC_NOTIFIER)
6595 muic_notifier_register(&battery
->batt_nb
,
6596 batt_handle_notification
,
6597 MUIC_NOTIFY_DEV_CHARGER
);
6599 #if defined(CONFIG_VBUS_NOTIFIER)
6600 vbus_notifier_register(&battery
->vbus_nb
,
6601 vbus_handle_notification
,
6602 VBUS_NOTIFY_DEV_CHARGER
);
6605 #if defined(CONFIG_AFC_CHARGER_MODE)
6607 psy_do_property(battery
->pdata
->charger_name
, set
,
6608 POWER_SUPPLY_PROP_AFC_CHARGER_MODE
,
6611 #if defined(CONFIG_STORE_MODE) && !defined(CONFIG_SEC_FACTORY)
6612 battery
->store_mode
= true;
6614 psy_do_property(battery
->pdata
->fuelgauge_name
, get
,
6615 POWER_SUPPLY_PROP_CAPACITY
, value
);
6616 if (value
.intval
<= 5) {
6617 battery
->ignore_store_mode
= true;
6619 value
.intval
= battery
->store_mode
;
6620 psy_do_property(battery
->pdata
->charger_name
, set
,
6621 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX
, value
);
6624 if (pdata
->initial_check
)
6625 pdata
->initial_check();
6627 cable_initial_check(battery
);
6629 psy_do_property("battery", get
,
6630 POWER_SUPPLY_PROP_ONLINE
, value
);
6632 if ((value
.intval
== POWER_SUPPLY_TYPE_BATTERY
) ||
6633 (value
.intval
== POWER_SUPPLY_TYPE_HV_PREPARE_MAINS
)) {
6634 dev_info(&pdev
->dev
,
6635 "%s: SEC Battery Driver Monitorwork\n", __func__
);
6636 wake_lock(&battery
->monitor_wake_lock
);
6637 queue_delayed_work_on(0, battery
->monitor_wqueue
, &battery
->monitor_work
, 0);
6640 if (battery
->pdata
->check_battery_callback
)
6641 battery
->present
= battery
->pdata
->check_battery_callback();
6643 dev_info(battery
->dev
,
6644 "%s: SEC Battery Driver Loaded\n", __func__
);
6648 if (battery
->pdata
->bat_irq
)
6649 free_irq(battery
->pdata
->bat_irq
, battery
);
6650 err_supply_unreg_bat
:
6651 power_supply_unregister(&battery
->psy_bat
);
6652 err_supply_unreg_ac
:
6653 power_supply_unregister(&battery
->psy_ac
);
6654 err_supply_unreg_usb
:
6655 power_supply_unregister(&battery
->psy_usb
);
6656 err_supply_unreg_wireless
:
6657 power_supply_unregister(&battery
->psy_wireless
);
6658 err_supply_unreg_ps
:
6659 power_supply_unregister(&battery
->psy_ps
);
6661 destroy_workqueue(battery
->monitor_wqueue
);
6663 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6664 if (battery
->pdata
->factory_discharging
)
6665 gpio_free(battery
->pdata
->factory_discharging
);
6668 gpio_free(battery
->pdata
->wchg_ctl
);
6670 wake_lock_destroy(&battery
->monitor_wake_lock
);
6671 wake_lock_destroy(&battery
->cable_wake_lock
);
6672 wake_lock_destroy(&battery
->vbus_wake_lock
);
6673 wake_lock_destroy(&battery
->siop_wake_lock
);
6674 mutex_destroy(&battery
->adclock
);
6675 mutex_destroy(&battery
->current_eventlock
);
6683 static int __devexit
sec_battery_remove(struct platform_device
*pdev
)
6685 struct sec_battery_info
*battery
= platform_get_drvdata(pdev
);
6690 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
6692 switch (battery
->pdata
->polling_type
) {
6693 case SEC_BATTERY_MONITOR_WORKQUEUE
:
6694 cancel_delayed_work(&battery
->polling_work
);
6696 case SEC_BATTERY_MONITOR_ALARM
:
6697 alarm_cancel(&battery
->polling_alarm
);
6703 alarm_cancel(&battery
->event_termination_alarm
);
6704 flush_workqueue(battery
->monitor_wqueue
);
6705 destroy_workqueue(battery
->monitor_wqueue
);
6706 wake_lock_destroy(&battery
->monitor_wake_lock
);
6707 wake_lock_destroy(&battery
->cable_wake_lock
);
6708 wake_lock_destroy(&battery
->vbus_wake_lock
);
6709 wake_lock_destroy(&battery
->siop_wake_lock
);
6711 mutex_destroy(&battery
->adclock
);
6712 mutex_destroy(&battery
->current_eventlock
);
6716 for (i
= 0; i
< SEC_BAT_ADC_CHANNEL_NUM
; i
++)
6717 adc_exit(battery
->pdata
, i
);
6719 power_supply_unregister(&battery
->psy_ps
);
6720 power_supply_unregister(&battery
->psy_wireless
);
6721 power_supply_unregister(&battery
->psy_ac
);
6722 power_supply_unregister(&battery
->psy_usb
);
6723 power_supply_unregister(&battery
->psy_bat
);
6725 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
6731 static int sec_battery_prepare(struct device
*dev
)
6733 struct sec_battery_info
*battery
6734 = dev_get_drvdata(dev
);
6736 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
6738 switch (battery
->pdata
->polling_type
) {
6739 case SEC_BATTERY_MONITOR_WORKQUEUE
:
6740 cancel_delayed_work(&battery
->polling_work
);
6742 case SEC_BATTERY_MONITOR_ALARM
:
6743 alarm_cancel(&battery
->polling_alarm
);
6748 cancel_delayed_work_sync(&battery
->monitor_work
);
6750 battery
->polling_in_sleep
= true;
6752 sec_bat_set_polling(battery
);
6754 /* cancel work for polling
6755 * that is set in sec_bat_set_polling()
6756 * no need for polling in sleep
6758 if (battery
->pdata
->polling_type
==
6759 SEC_BATTERY_MONITOR_WORKQUEUE
)
6760 cancel_delayed_work(&battery
->polling_work
);
6762 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
6767 static int sec_battery_suspend(struct device
*dev
)
6772 static int sec_battery_resume(struct device
*dev
)
6777 static void sec_battery_complete(struct device
*dev
)
6779 struct sec_battery_info
*battery
6780 = dev_get_drvdata(dev
);
6782 dev_dbg(battery
->dev
, "%s: Start\n", __func__
);
6784 /* cancel current alarm and reset after monitor work */
6785 if (battery
->pdata
->polling_type
== SEC_BATTERY_MONITOR_ALARM
)
6786 alarm_cancel(&battery
->polling_alarm
);
6788 wake_lock(&battery
->monitor_wake_lock
);
6789 queue_delayed_work_on(0, battery
->monitor_wqueue
,
6790 &battery
->monitor_work
, 0);
6792 dev_dbg(battery
->dev
, "%s: End\n", __func__
);
6797 static void sec_battery_shutdown(struct device
*dev
)
6799 struct sec_battery_info
*battery
6800 = dev_get_drvdata(dev
);
6801 union power_supply_propval val
;
6803 if (battery
->pdata
->always_enable
) {
6805 psy_do_property(battery
->pdata
->charger_name
, set
,
6806 POWER_SUPPLY_PROP_CHARGING_ENABLED
, val
);
6809 #if defined(CONFIG_BATTERY_SWELLING_SELF_DISCHARGING)
6810 if (battery
->force_discharging
) {
6811 pr_info("SELF DISCHARGING IC DISENABLE\n");
6812 sec_bat_self_discharging_control(battery
, false);
6818 static struct of_device_id sec_battery_dt_ids
[] = {
6819 { .compatible
= "samsung,sec-battery" },
6822 MODULE_DEVICE_TABLE(of
, sec_battery_dt_ids
);
6823 #endif /* CONFIG_OF */
6825 static const struct dev_pm_ops sec_battery_pm_ops
= {
6826 .prepare
= sec_battery_prepare
,
6827 .suspend
= sec_battery_suspend
,
6828 .resume
= sec_battery_resume
,
6829 .complete
= sec_battery_complete
,
6832 static struct platform_driver sec_battery_driver
= {
6834 .name
= "sec-battery",
6835 .owner
= THIS_MODULE
,
6836 .pm
= &sec_battery_pm_ops
,
6837 .shutdown
= sec_battery_shutdown
,
6839 .of_match_table
= sec_battery_dt_ids
,
6842 .probe
= sec_battery_probe
,
6843 .remove
= __devexit_p(sec_battery_remove
),
6846 static int __init
sec_battery_init(void)
6848 return platform_driver_register(&sec_battery_driver
);
6851 static void __exit
sec_battery_exit(void)
6853 platform_driver_unregister(&sec_battery_driver
);
6856 late_initcall(sec_battery_init
);
6857 module_exit(sec_battery_exit
);
6859 MODULE_DESCRIPTION("Samsung Battery Driver");
6860 MODULE_AUTHOR("Samsung Electronics");
6861 MODULE_LICENSE("GPL");