1 /*****************************************************************************
13 * This Module defines functions of mt6323 Battery charging algorithm
14 * and the Anroid Battery service for updating the battery status
20 ****************************************************************************/
21 #include <linux/init.h> /* For init/exit macros */
22 #include <linux/module.h> /* For MODULE_ marcros */
24 #include <linux/device.h>
25 #include <linux/interrupt.h>
26 #include <linux/spinlock.h>
27 #include <linux/platform_device.h>
28 #include <linux/device.h>
29 #include <linux/kdev_t.h>
31 #include <linux/cdev.h>
32 #include <linux/delay.h>
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/wait.h>
37 #include <linux/slab.h>
39 #include <linux/sched.h>
40 #include <linux/poll.h>
41 #include <linux/power_supply.h>
42 #include <linux/wakelock.h>
43 #include <linux/time.h>
44 #include <linux/mutex.h>
45 #include <linux/kthread.h>
46 #include <linux/proc_fs.h>
47 #include <linux/platform_device.h>
48 #include <linux/seq_file.h>
49 #include <linux/scatterlist.h>
52 #include <linux/of_irq.h>
53 #include <linux/of_address.h>
55 #include <linux/suspend.h>
57 #include <asm/scatterlist.h>
58 #include <asm/uaccess.h>
61 #include <mach/hardware.h>
62 #include <mach/system.h>
63 #include <mach/mt_sleep.h>
65 #include <mach/mt_typedefs.h>
66 #include <mach/mt_gpt.h>
67 #include <mach/mt_boot.h>
69 #include <cust_charging.h>
70 #include <mach/upmu_common.h>
71 #include <mach/upmu_hw.h>
72 #include <mach/upmu_sw.h>
73 #include <mach/charging.h>
74 #include <mach/battery_common.h>
75 #include <mach/battery_meter.h>
76 #include "cust_battery_meter.h"
77 #include "cust_charging.h"
78 #include <mach/mt_boot.h>
79 #include "mach/mtk_rtc.h"
81 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
82 #include <mach/diso.h>
85 #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
88 /* ////////////////////////////////////////////////////////////////////////////// */
89 /* Battery Logging Entry */
90 /* ////////////////////////////////////////////////////////////////////////////// */
91 int Enable_BATDRV_LOG
= BAT_LOG_CRTI
;
93 /* ///////////////////////////////////////////////////////////////////////////////////////// */
94 /* // Smart Battery Structure */
95 /* ///////////////////////////////////////////////////////////////////////////////////////// */
96 PMU_ChargerStruct BMT_status
;
97 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
98 DISO_ChargerStruct DISO_data
;
100 static char *DISO_state_s
[8] = {
112 /* ///////////////////////////////////////////////////////////////////////////////////////// */
113 /* // Thermal related flags */
114 /* ///////////////////////////////////////////////////////////////////////////////////////// */
115 int g_battery_thermal_throttling_flag
= 3; /* 0:nothing, 1:enable batTT&chrTimer, 2:disable batTT&chrTimer, 3:enable batTT, disable chrTimer */
116 int battery_cmd_thermal_test_mode
= 0;
117 int battery_cmd_thermal_test_mode_value
= 0;
118 int g_battery_tt_check_flag
= 0; /* 0:default enable check batteryTT, 1:default disable check batteryTT */
120 /*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015, pr-975290, add standby current */
121 static kal_int32 cur_timer_counter
= 0;
122 static kal_int32 pre_timer_counter
= 0;
123 static kal_int32 sleep_timer
= 0;
124 static kal_int32 soc_reduce_step
= 0;
125 /*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
127 /* ///////////////////////////////////////////////////////////////////////////////////////// */
128 /* // Global Variable */
129 /* ///////////////////////////////////////////////////////////////////////////////////////// */
130 struct wake_lock battery_suspend_lock
;
131 CHARGING_CONTROL battery_charging_control
;
132 unsigned int g_BatteryNotifyCode
= 0x0000;
133 unsigned int g_BN_TestMode
= 0x0000;
134 kal_bool g_bat_init_flag
= 0;
135 unsigned int g_call_state
= CALL_IDLE
;
136 kal_bool g_charging_full_reset_bat_meter
= KAL_FALSE
;
137 int g_platform_boot_mode
= 0;
138 struct timespec g_bat_time_before_sleep
;
139 int g_smartbook_update
= 0;
141 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
142 kal_bool g_vcdt_irq_delay_flag
= 0;
145 #if defined(MTK_TEMPERATURE_RECHARGE_SUPPORT)
146 kal_uint32 g_batt_temp_status
= TEMP_POS_NORMAL
;
149 kal_bool battery_suspended
= KAL_FALSE
;
150 #ifdef MTK_ENABLE_AGING_ALGORITHM
151 extern U32 suspend_time
;
154 #if defined(CUST_SYSTEM_OFF_VOLTAGE)
155 #define SYSTEM_OFF_VOLTAGE CUST_SYSTEM_OFF_VOLTAGE
158 /* ////////////////////////////////////////////////////////////////////////////// */
159 /* Integrate with NVRAM */
160 /* ////////////////////////////////////////////////////////////////////////////// */
161 #define ADC_CALI_DEVNAME "MT_pmic_adc_cali"
162 #define TEST_ADC_CALI_PRINT _IO('k', 0)
163 #define SET_ADC_CALI_Slop _IOW('k', 1, int)
164 #define SET_ADC_CALI_Offset _IOW('k', 2, int)
165 #define SET_ADC_CALI_Cal _IOW('k', 3, int)
166 #define ADC_CHANNEL_READ _IOW('k', 4, int)
167 #define BAT_STATUS_READ _IOW('k', 5, int)
168 #define Set_Charger_Current _IOW('k', 6, int)
169 /* add for meta tool----------------------------------------- */
170 #define Get_META_BAT_VOL _IOW('k', 10, int)
171 #define Get_META_BAT_SOC _IOW('k', 11, int)
172 /* add for meta tool----------------------------------------- */
174 static struct class *adc_cali_class
;
175 static int adc_cali_major
;
176 static dev_t adc_cali_devno
;
177 static struct cdev
*adc_cali_cdev
;
179 int adc_cali_slop
[14] =
180 { 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 };
181 int adc_cali_offset
[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
182 int adc_cali_cal
[1] = { 0 };
183 int battery_in_data
[1] = { 0 };
184 int battery_out_data
[1] = { 0 };
185 int charging_level_data
[1] = { 0 };
187 kal_bool g_ADC_Cali
= KAL_FALSE
;
188 kal_bool g_ftm_battery_flag
= KAL_FALSE
;
189 #if !defined(CONFIG_POWER_EXT)
190 static int g_wireless_state
;
193 /* ///////////////////////////////////////////////////////////////////////////////////////// */
194 /* // Thread related */
195 /* ///////////////////////////////////////////////////////////////////////////////////////// */
196 #define BAT_MS_TO_NS(x) (x * 1000 * 1000)
197 static kal_bool bat_thread_timeout
= KAL_FALSE
;
198 static kal_bool chr_wake_up_bat
= KAL_FALSE
; /* charger in/out to wake up battery thread */
199 static kal_bool bat_meter_timeout
= KAL_FALSE
;
200 static DEFINE_MUTEX(bat_mutex
);
201 static DEFINE_MUTEX(charger_type_mutex
);
202 static DECLARE_WAIT_QUEUE_HEAD(bat_thread_wq
);
203 static struct hrtimer charger_hv_detect_timer
;
204 static struct task_struct
*charger_hv_detect_thread
= NULL
;
205 static kal_bool charger_hv_detect_flag
= KAL_FALSE
;
206 static DECLARE_WAIT_QUEUE_HEAD(charger_hv_detect_waiter
);
207 static struct hrtimer battery_kthread_timer
;
208 static kal_bool g_battery_soc_ready
= KAL_FALSE
;
209 extern BOOL bat_spm_timeout
;
210 extern U32 _g_bat_sleep_total_time
;
212 /* ////////////////////////////////////////////////////////////////////////////// */
214 /* ////////////////////////////////////////////////////////////////////////////// */
216 int g_status_smb
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
217 int g_capacity_smb
= 50;
218 int g_present_smb
= 0;
219 /* ADB charging CMD */
220 static int cmd_discharging
= -1;
221 static int adjust_power
= -1;
222 static int suspend_discharging
= -1;
224 /* ////////////////////////////////////////////////////////////////////////////// */
225 /* FOR ANDROID BATTERY SERVICE */
226 /* ////////////////////////////////////////////////////////////////////////////// */
228 struct wireless_data
{
229 struct power_supply psy
;
234 struct power_supply psy
;
239 struct power_supply psy
;
243 struct battery_data
{
244 struct power_supply psy
;
250 /* Add for Battery Service */
254 int BAT_TemperatureR
;
255 int BAT_TempBattVoltage
;
257 int BAT_BatteryAverageCurrent
;
258 int BAT_BatterySenseVoltage
;
259 int BAT_ISenseVoltage
;
260 int BAT_ChargerVoltage
;
268 static enum power_supply_property wireless_props
[] = {
269 POWER_SUPPLY_PROP_ONLINE
,
272 static enum power_supply_property ac_props
[] = {
273 POWER_SUPPLY_PROP_ONLINE
,
276 static enum power_supply_property usb_props
[] = {
277 POWER_SUPPLY_PROP_ONLINE
,
280 static enum power_supply_property battery_props
[] = {
281 POWER_SUPPLY_PROP_STATUS
,
282 POWER_SUPPLY_PROP_HEALTH
,
283 POWER_SUPPLY_PROP_PRESENT
,
284 POWER_SUPPLY_PROP_TECHNOLOGY
,
285 POWER_SUPPLY_PROP_CAPACITY
,
286 /* Add for Battery Service */
287 POWER_SUPPLY_PROP_batt_vol
,
288 POWER_SUPPLY_PROP_batt_temp
,
290 POWER_SUPPLY_PROP_TemperatureR
,
291 POWER_SUPPLY_PROP_TempBattVoltage
,
292 POWER_SUPPLY_PROP_InstatVolt
,
293 POWER_SUPPLY_PROP_BatteryAverageCurrent
,
294 POWER_SUPPLY_PROP_BatterySenseVoltage
,
295 POWER_SUPPLY_PROP_ISenseVoltage
,
296 POWER_SUPPLY_PROP_ChargerVoltage
,
298 POWER_SUPPLY_PROP_status_smb
,
299 POWER_SUPPLY_PROP_capacity_smb
,
300 POWER_SUPPLY_PROP_present_smb
,
301 /* ADB CMD Discharging */
302 POWER_SUPPLY_PROP_adjust_power
,
305 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, add ntc simulation function */
306 //#define MTK_NTC_DEBUG_SIMULATE
307 #if (defined MTK_NTC_DEBUG_SIMULATE)
308 static kal_int32 battery_temp
= 25;
310 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
312 /* ///////////////////////////////////////////////////////////////////////////////////////// */
313 /* // extern function */
314 /* ///////////////////////////////////////////////////////////////////////////////////////// */
315 /* extern void mt_power_off(void); */
316 extern bool mt_usb_is_device(void);
317 #if defined(CONFIG_USB_MTK_HDRC) || defined(CONFIG_USB_MU3D_DRV)
318 extern void mt_usb_connect(void);
319 extern void mt_usb_disconnect(void);
321 #define mt_usb_connect() do { } while (0)
322 #define mt_usb_disconnect() do { } while (0)
324 /* extern int set_rtc_spare_fg_value(int val); */
326 #if defined(CUST_CAPACITY_OCV2CV_TRANSFORM)
327 extern void battery_meter_set_reset_soc(kal_bool bUSE_UI_SOC
);
328 extern kal_int32
battery_meter_get_battery_soc(void);
331 void check_battery_exist(void);
332 void charging_suspend_enable(void)
334 U32 charging_enable
= true;
336 suspend_discharging
= 0;
337 battery_charging_control(CHARGING_CMD_ENABLE
,&charging_enable
);
340 void charging_suspend_disable(void)
342 U32 charging_enable
= false;
344 suspend_discharging
= 1;
345 battery_charging_control(CHARGING_CMD_ENABLE
,&charging_enable
);
348 int read_tbat_value(void)
350 return BMT_status
.temperature
;
353 int get_charger_detect_status(void)
357 battery_charging_control(CHARGING_CMD_GET_CHARGER_DET_STATUS
, &chr_status
);
361 #if defined(CONFIG_MTK_POWER_EXT_DETECT)
362 kal_bool
bat_is_ext_power(void)
364 kal_bool pwr_src
= 0;
366 battery_charging_control(CHARGING_CMD_GET_POWER_SOURCE
, &pwr_src
);
367 battery_xlog_printk(BAT_LOG_FULL
, "[BAT_IS_EXT_POWER] is_ext_power = %d\n", pwr_src
);
371 /* ///////////////////////////////////////////////////////////////////////////////////////// */
372 /* // PMIC PCHR Related APIs */
373 /* ///////////////////////////////////////////////////////////////////////////////////////// */
374 kal_bool
upmu_is_chr_det(void)
376 #if !defined(CONFIG_POWER_EXT)
380 if(battery_charging_control
== NULL
)
382 battery_charging_control
= chr_control_interface
;
384 #if defined(CONFIG_POWER_EXT)
385 /* return KAL_TRUE; */
386 return get_charger_detect_status();
388 if (suspend_discharging
==1)
391 tmp32
= get_charger_detect_status();
393 #ifdef CONFIG_MTK_POWER_EXT_DETECT
394 if (KAL_TRUE
== bat_is_ext_power())
401 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
402 if (mt_usb_is_device()) {
403 battery_xlog_printk(BAT_LOG_FULL
,
404 "[upmu_is_chr_det] Charger exist and USB is not host\n");
408 battery_xlog_printk(BAT_LOG_CRTI
,
409 "[upmu_is_chr_det] Charger exist but USB is host\n");
419 EXPORT_SYMBOL(upmu_is_chr_det
);
422 void wake_up_bat(void)
424 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] wake_up_bat. \r\n");
426 chr_wake_up_bat
= KAL_TRUE
;
427 bat_thread_timeout
= KAL_TRUE
;
428 #ifdef MTK_ENABLE_AGING_ALGORITHM
431 _g_bat_sleep_total_time
= 0;
432 wake_up(&bat_thread_wq
);
434 EXPORT_SYMBOL(wake_up_bat
);
437 static ssize_t
bat_log_write(struct file
*filp
, const char __user
*buff
, size_t len
, loff_t
*data
)
441 if ((len
<= 0) || copy_from_user(&proc_bat_data
, buff
, 1)) {
442 battery_xlog_printk(BAT_LOG_FULL
, "bat_log_write error.\n");
446 if (proc_bat_data
== '1') {
447 battery_xlog_printk(BAT_LOG_CRTI
, "enable battery driver log system\n");
448 Enable_BATDRV_LOG
= 1;
449 } else if (proc_bat_data
== '2') {
450 battery_xlog_printk(BAT_LOG_CRTI
, "enable battery driver log system:2\n");
451 Enable_BATDRV_LOG
= 2;
453 battery_xlog_printk(BAT_LOG_CRTI
, "Disable battery driver log system\n");
454 Enable_BATDRV_LOG
= 0;
460 static const struct file_operations bat_proc_fops
= {
461 .write
= bat_log_write
,
464 int init_proc_log(void)
469 proc_create("batdrv_log", 0644, NULL
, &bat_proc_fops
);
470 battery_xlog_printk(BAT_LOG_CRTI
, "proc_create bat_proc_fops\n");
472 proc_entry
= create_proc_entry("batdrv_log", 0644, NULL
);
474 if (proc_entry
== NULL
) {
476 battery_xlog_printk(BAT_LOG_FULL
, "init_proc_log: Couldn't create proc entry\n");
478 proc_entry
->write_proc
= bat_log_write
;
479 battery_xlog_printk(BAT_LOG_CRTI
, "init_proc_log loaded.\n");
487 static int wireless_get_property(struct power_supply
*psy
,
488 enum power_supply_property psp
, union power_supply_propval
*val
)
491 struct wireless_data
*data
= container_of(psy
, struct wireless_data
, psy
);
494 case POWER_SUPPLY_PROP_ONLINE
:
495 val
->intval
= data
->WIRELESS_ONLINE
;
504 static int ac_get_property(struct power_supply
*psy
,
505 enum power_supply_property psp
, union power_supply_propval
*val
)
508 struct ac_data
*data
= container_of(psy
, struct ac_data
, psy
);
511 case POWER_SUPPLY_PROP_ONLINE
:
512 val
->intval
= data
->AC_ONLINE
;
521 static int usb_get_property(struct power_supply
*psy
,
522 enum power_supply_property psp
, union power_supply_propval
*val
)
525 struct usb_data
*data
= container_of(psy
, struct usb_data
, psy
);
528 case POWER_SUPPLY_PROP_ONLINE
:
529 #if defined(CONFIG_POWER_EXT)
531 data
->USB_ONLINE
= 1;
532 val
->intval
= data
->USB_ONLINE
;
534 #if defined(CONFIG_MTK_POWER_EXT_DETECT)
535 if (KAL_TRUE
== bat_is_ext_power())
536 data
->USB_ONLINE
= 1;
538 val
->intval
= data
->USB_ONLINE
;
548 static int battery_get_property(struct power_supply
*psy
,
549 enum power_supply_property psp
, union power_supply_propval
*val
)
552 struct battery_data
*data
= container_of(psy
, struct battery_data
, psy
);
555 case POWER_SUPPLY_PROP_STATUS
:
556 val
->intval
= data
->BAT_STATUS
;
558 case POWER_SUPPLY_PROP_HEALTH
:
559 val
->intval
= data
->BAT_HEALTH
;
561 case POWER_SUPPLY_PROP_PRESENT
:
562 val
->intval
= data
->BAT_PRESENT
;
564 case POWER_SUPPLY_PROP_TECHNOLOGY
:
565 val
->intval
= data
->BAT_TECHNOLOGY
;
567 case POWER_SUPPLY_PROP_CAPACITY
:
568 val
->intval
= data
->BAT_CAPACITY
;
570 case POWER_SUPPLY_PROP_batt_vol
:
571 val
->intval
= data
->BAT_batt_vol
;
573 case POWER_SUPPLY_PROP_batt_temp
:
574 val
->intval
= data
->BAT_batt_temp
;
576 case POWER_SUPPLY_PROP_TemperatureR
:
577 val
->intval
= data
->BAT_TemperatureR
;
579 case POWER_SUPPLY_PROP_TempBattVoltage
:
580 val
->intval
= data
->BAT_TempBattVoltage
;
582 case POWER_SUPPLY_PROP_InstatVolt
:
583 val
->intval
= data
->BAT_InstatVolt
;
585 case POWER_SUPPLY_PROP_BatteryAverageCurrent
:
586 val
->intval
= data
->BAT_BatteryAverageCurrent
;
588 case POWER_SUPPLY_PROP_BatterySenseVoltage
:
589 val
->intval
= data
->BAT_BatterySenseVoltage
;
591 case POWER_SUPPLY_PROP_ISenseVoltage
:
592 val
->intval
= data
->BAT_ISenseVoltage
;
594 case POWER_SUPPLY_PROP_ChargerVoltage
:
595 val
->intval
= data
->BAT_ChargerVoltage
;
598 case POWER_SUPPLY_PROP_status_smb
:
599 val
->intval
= data
->status_smb
;
601 case POWER_SUPPLY_PROP_capacity_smb
:
602 val
->intval
= data
->capacity_smb
;
604 case POWER_SUPPLY_PROP_present_smb
:
605 val
->intval
= data
->present_smb
;
607 case POWER_SUPPLY_PROP_adjust_power
:
608 val
->intval
= data
->adjust_power
;
619 /* wireless_data initialization */
620 static struct wireless_data wireless_main
= {
623 .type
= POWER_SUPPLY_TYPE_WIRELESS
,
624 .properties
= wireless_props
,
625 .num_properties
= ARRAY_SIZE(wireless_props
),
626 .get_property
= wireless_get_property
,
628 .WIRELESS_ONLINE
= 0,
631 /* ac_data initialization */
632 static struct ac_data ac_main
= {
635 .type
= POWER_SUPPLY_TYPE_MAINS
,
636 .properties
= ac_props
,
637 .num_properties
= ARRAY_SIZE(ac_props
),
638 .get_property
= ac_get_property
,
643 /* usb_data initialization */
644 static struct usb_data usb_main
= {
647 .type
= POWER_SUPPLY_TYPE_USB
,
648 .properties
= usb_props
,
649 .num_properties
= ARRAY_SIZE(usb_props
),
650 .get_property
= usb_get_property
,
655 /* battery_data initialization */
656 static struct battery_data battery_main
= {
659 .type
= POWER_SUPPLY_TYPE_BATTERY
,
660 .properties
= battery_props
,
661 .num_properties
= ARRAY_SIZE(battery_props
),
662 .get_property
= battery_get_property
,
664 /* CC: modify to have a full power supply status */
665 #if defined(CONFIG_POWER_EXT)
666 .BAT_STATUS
= POWER_SUPPLY_STATUS_FULL
,
667 .BAT_HEALTH
= POWER_SUPPLY_HEALTH_GOOD
,
669 .BAT_TECHNOLOGY
= POWER_SUPPLY_TECHNOLOGY_LION
,
671 .BAT_batt_vol
= 4200,
674 .status_smb
= POWER_SUPPLY_STATUS_NOT_CHARGING
,
677 /* ADB CMD discharging*/
680 .BAT_STATUS
= POWER_SUPPLY_STATUS_NOT_CHARGING
,
681 .BAT_HEALTH
= POWER_SUPPLY_HEALTH_GOOD
,
683 .BAT_TECHNOLOGY
= POWER_SUPPLY_TECHNOLOGY_LION
,
684 #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) || defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
692 .status_smb
= POWER_SUPPLY_STATUS_NOT_CHARGING
,
695 /* ADB CMD discharging*/
701 #if !defined(CONFIG_POWER_EXT)
702 /* ///////////////////////////////////////////////////////////////////////////////////////// */
703 /* // Create File For EM : ADC_Charger_Voltage */
704 /* ///////////////////////////////////////////////////////////////////////////////////////// */
705 static ssize_t
show_ADC_Charger_Voltage(struct device
*dev
, struct device_attribute
*attr
,
708 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] show_ADC_Charger_Voltage : %d\n",
709 BMT_status
.charger_vol
);
710 return sprintf(buf
, "%d\n", BMT_status
.charger_vol
);
713 static ssize_t
store_ADC_Charger_Voltage(struct device
*dev
, struct device_attribute
*attr
,
714 const char *buf
, size_t size
)
716 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
720 static DEVICE_ATTR(ADC_Charger_Voltage
, 0664, show_ADC_Charger_Voltage
, store_ADC_Charger_Voltage
);
722 /* ///////////////////////////////////////////////////////////////////////////////////////// */
723 /* // Create File For EM : ADC_Channel_0_Slope */
724 /* ///////////////////////////////////////////////////////////////////////////////////////// */
725 static ssize_t
show_ADC_Channel_0_Slope(struct device
*dev
, struct device_attribute
*attr
,
729 ret_value
= (*(adc_cali_slop
+ 0));
730 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_0_Slope : %d\n", ret_value
);
731 return sprintf(buf
, "%u\n", ret_value
);
734 static ssize_t
store_ADC_Channel_0_Slope(struct device
*dev
, struct device_attribute
*attr
,
735 const char *buf
, size_t size
)
737 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
741 static DEVICE_ATTR(ADC_Channel_0_Slope
, 0664, show_ADC_Channel_0_Slope
, store_ADC_Channel_0_Slope
);
743 /* ///////////////////////////////////////////////////////////////////////////////////////// */
744 /* // Create File For EM : ADC_Channel_1_Slope */
745 /* ///////////////////////////////////////////////////////////////////////////////////////// */
746 static ssize_t
show_ADC_Channel_1_Slope(struct device
*dev
, struct device_attribute
*attr
,
750 ret_value
= (*(adc_cali_slop
+ 1));
751 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_1_Slope : %d\n", ret_value
);
752 return sprintf(buf
, "%u\n", ret_value
);
755 static ssize_t
store_ADC_Channel_1_Slope(struct device
*dev
, struct device_attribute
*attr
,
756 const char *buf
, size_t size
)
758 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
762 static DEVICE_ATTR(ADC_Channel_1_Slope
, 0664, show_ADC_Channel_1_Slope
, store_ADC_Channel_1_Slope
);
764 /* ///////////////////////////////////////////////////////////////////////////////////////// */
765 /* // Create File For EM : ADC_Channel_2_Slope */
766 /* ///////////////////////////////////////////////////////////////////////////////////////// */
767 static ssize_t
show_ADC_Channel_2_Slope(struct device
*dev
, struct device_attribute
*attr
,
771 ret_value
= (*(adc_cali_slop
+ 2));
772 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_2_Slope : %d\n", ret_value
);
773 return sprintf(buf
, "%u\n", ret_value
);
776 static ssize_t
store_ADC_Channel_2_Slope(struct device
*dev
, struct device_attribute
*attr
,
777 const char *buf
, size_t size
)
779 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
783 static DEVICE_ATTR(ADC_Channel_2_Slope
, 0664, show_ADC_Channel_2_Slope
, store_ADC_Channel_2_Slope
);
785 /* ///////////////////////////////////////////////////////////////////////////////////////// */
786 /* // Create File For EM : ADC_Channel_3_Slope */
787 /* ///////////////////////////////////////////////////////////////////////////////////////// */
788 static ssize_t
show_ADC_Channel_3_Slope(struct device
*dev
, struct device_attribute
*attr
,
792 ret_value
= (*(adc_cali_slop
+ 3));
793 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_3_Slope : %d\n", ret_value
);
794 return sprintf(buf
, "%u\n", ret_value
);
797 static ssize_t
store_ADC_Channel_3_Slope(struct device
*dev
, struct device_attribute
*attr
,
798 const char *buf
, size_t size
)
800 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
804 static DEVICE_ATTR(ADC_Channel_3_Slope
, 0664, show_ADC_Channel_3_Slope
, store_ADC_Channel_3_Slope
);
806 /* ///////////////////////////////////////////////////////////////////////////////////////// */
807 /* // Create File For EM : ADC_Channel_4_Slope */
808 /* ///////////////////////////////////////////////////////////////////////////////////////// */
809 static ssize_t
show_ADC_Channel_4_Slope(struct device
*dev
, struct device_attribute
*attr
,
813 ret_value
= (*(adc_cali_slop
+ 4));
814 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_4_Slope : %d\n", ret_value
);
815 return sprintf(buf
, "%u\n", ret_value
);
818 static ssize_t
store_ADC_Channel_4_Slope(struct device
*dev
, struct device_attribute
*attr
,
819 const char *buf
, size_t size
)
821 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
825 static DEVICE_ATTR(ADC_Channel_4_Slope
, 0664, show_ADC_Channel_4_Slope
, store_ADC_Channel_4_Slope
);
827 /* ///////////////////////////////////////////////////////////////////////////////////////// */
828 /* // Create File For EM : ADC_Channel_5_Slope */
829 /* ///////////////////////////////////////////////////////////////////////////////////////// */
830 static ssize_t
show_ADC_Channel_5_Slope(struct device
*dev
, struct device_attribute
*attr
,
834 ret_value
= (*(adc_cali_slop
+ 5));
835 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_5_Slope : %d\n", ret_value
);
836 return sprintf(buf
, "%u\n", ret_value
);
839 static ssize_t
store_ADC_Channel_5_Slope(struct device
*dev
, struct device_attribute
*attr
,
840 const char *buf
, size_t size
)
842 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
846 static DEVICE_ATTR(ADC_Channel_5_Slope
, 0664, show_ADC_Channel_5_Slope
, store_ADC_Channel_5_Slope
);
848 /* ///////////////////////////////////////////////////////////////////////////////////////// */
849 /* // Create File For EM : ADC_Channel_6_Slope */
850 /* ///////////////////////////////////////////////////////////////////////////////////////// */
851 static ssize_t
show_ADC_Channel_6_Slope(struct device
*dev
, struct device_attribute
*attr
,
855 ret_value
= (*(adc_cali_slop
+ 6));
856 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_6_Slope : %d\n", ret_value
);
857 return sprintf(buf
, "%u\n", ret_value
);
860 static ssize_t
store_ADC_Channel_6_Slope(struct device
*dev
, struct device_attribute
*attr
,
861 const char *buf
, size_t size
)
863 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
867 static DEVICE_ATTR(ADC_Channel_6_Slope
, 0664, show_ADC_Channel_6_Slope
, store_ADC_Channel_6_Slope
);
869 /* ///////////////////////////////////////////////////////////////////////////////////////// */
870 /* // Create File For EM : ADC_Channel_7_Slope */
871 /* ///////////////////////////////////////////////////////////////////////////////////////// */
872 static ssize_t
show_ADC_Channel_7_Slope(struct device
*dev
, struct device_attribute
*attr
,
876 ret_value
= (*(adc_cali_slop
+ 7));
877 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_7_Slope : %d\n", ret_value
);
878 return sprintf(buf
, "%u\n", ret_value
);
881 static ssize_t
store_ADC_Channel_7_Slope(struct device
*dev
, struct device_attribute
*attr
,
882 const char *buf
, size_t size
)
884 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
888 static DEVICE_ATTR(ADC_Channel_7_Slope
, 0664, show_ADC_Channel_7_Slope
, store_ADC_Channel_7_Slope
);
890 /* ///////////////////////////////////////////////////////////////////////////////////////// */
891 /* // Create File For EM : ADC_Channel_8_Slope */
892 /* ///////////////////////////////////////////////////////////////////////////////////////// */
893 static ssize_t
show_ADC_Channel_8_Slope(struct device
*dev
, struct device_attribute
*attr
,
897 ret_value
= (*(adc_cali_slop
+ 8));
898 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_8_Slope : %d\n", ret_value
);
899 return sprintf(buf
, "%u\n", ret_value
);
902 static ssize_t
store_ADC_Channel_8_Slope(struct device
*dev
, struct device_attribute
*attr
,
903 const char *buf
, size_t size
)
905 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
909 static DEVICE_ATTR(ADC_Channel_8_Slope
, 0664, show_ADC_Channel_8_Slope
, store_ADC_Channel_8_Slope
);
911 /* ///////////////////////////////////////////////////////////////////////////////////////// */
912 /* // Create File For EM : ADC_Channel_9_Slope */
913 /* ///////////////////////////////////////////////////////////////////////////////////////// */
914 static ssize_t
show_ADC_Channel_9_Slope(struct device
*dev
, struct device_attribute
*attr
,
918 ret_value
= (*(adc_cali_slop
+ 9));
919 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_9_Slope : %d\n", ret_value
);
920 return sprintf(buf
, "%u\n", ret_value
);
923 static ssize_t
store_ADC_Channel_9_Slope(struct device
*dev
, struct device_attribute
*attr
,
924 const char *buf
, size_t size
)
926 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
930 static DEVICE_ATTR(ADC_Channel_9_Slope
, 0664, show_ADC_Channel_9_Slope
, store_ADC_Channel_9_Slope
);
932 /* ///////////////////////////////////////////////////////////////////////////////////////// */
933 /* // Create File For EM : ADC_Channel_10_Slope */
934 /* ///////////////////////////////////////////////////////////////////////////////////////// */
935 static ssize_t
show_ADC_Channel_10_Slope(struct device
*dev
, struct device_attribute
*attr
,
939 ret_value
= (*(adc_cali_slop
+ 10));
940 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_10_Slope : %d\n", ret_value
);
941 return sprintf(buf
, "%u\n", ret_value
);
944 static ssize_t
store_ADC_Channel_10_Slope(struct device
*dev
, struct device_attribute
*attr
,
945 const char *buf
, size_t size
)
947 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
951 static DEVICE_ATTR(ADC_Channel_10_Slope
, 0664, show_ADC_Channel_10_Slope
,
952 store_ADC_Channel_10_Slope
);
954 /* ///////////////////////////////////////////////////////////////////////////////////////// */
955 /* // Create File For EM : ADC_Channel_11_Slope */
956 /* ///////////////////////////////////////////////////////////////////////////////////////// */
957 static ssize_t
show_ADC_Channel_11_Slope(struct device
*dev
, struct device_attribute
*attr
,
961 ret_value
= (*(adc_cali_slop
+ 11));
962 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_11_Slope : %d\n", ret_value
);
963 return sprintf(buf
, "%u\n", ret_value
);
966 static ssize_t
store_ADC_Channel_11_Slope(struct device
*dev
, struct device_attribute
*attr
,
967 const char *buf
, size_t size
)
969 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
973 static DEVICE_ATTR(ADC_Channel_11_Slope
, 0664, show_ADC_Channel_11_Slope
,
974 store_ADC_Channel_11_Slope
);
976 /* ///////////////////////////////////////////////////////////////////////////////////////// */
977 /* // Create File For EM : ADC_Channel_12_Slope */
978 /* ///////////////////////////////////////////////////////////////////////////////////////// */
979 static ssize_t
show_ADC_Channel_12_Slope(struct device
*dev
, struct device_attribute
*attr
,
983 ret_value
= (*(adc_cali_slop
+ 12));
984 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_12_Slope : %d\n", ret_value
);
985 return sprintf(buf
, "%u\n", ret_value
);
988 static ssize_t
store_ADC_Channel_12_Slope(struct device
*dev
, struct device_attribute
*attr
,
989 const char *buf
, size_t size
)
991 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
995 static DEVICE_ATTR(ADC_Channel_12_Slope
, 0664, show_ADC_Channel_12_Slope
,
996 store_ADC_Channel_12_Slope
);
998 /* ///////////////////////////////////////////////////////////////////////////////////////// */
999 /* // Create File For EM : ADC_Channel_13_Slope */
1000 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1001 static ssize_t
show_ADC_Channel_13_Slope(struct device
*dev
, struct device_attribute
*attr
,
1005 ret_value
= (*(adc_cali_slop
+ 13));
1006 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_13_Slope : %d\n", ret_value
);
1007 return sprintf(buf
, "%u\n", ret_value
);
1010 static ssize_t
store_ADC_Channel_13_Slope(struct device
*dev
, struct device_attribute
*attr
,
1011 const char *buf
, size_t size
)
1013 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1017 static DEVICE_ATTR(ADC_Channel_13_Slope
, 0664, show_ADC_Channel_13_Slope
,
1018 store_ADC_Channel_13_Slope
);
1021 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1022 /* // Create File For EM : ADC_Channel_0_Offset */
1023 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1024 static ssize_t
show_ADC_Channel_0_Offset(struct device
*dev
, struct device_attribute
*attr
,
1028 ret_value
= (*(adc_cali_offset
+ 0));
1029 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_0_Offset : %d\n", ret_value
);
1030 return sprintf(buf
, "%u\n", ret_value
);
1033 static ssize_t
store_ADC_Channel_0_Offset(struct device
*dev
, struct device_attribute
*attr
,
1034 const char *buf
, size_t size
)
1036 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1040 static DEVICE_ATTR(ADC_Channel_0_Offset
, 0664, show_ADC_Channel_0_Offset
,
1041 store_ADC_Channel_0_Offset
);
1043 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1044 /* // Create File For EM : ADC_Channel_1_Offset */
1045 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1046 static ssize_t
show_ADC_Channel_1_Offset(struct device
*dev
, struct device_attribute
*attr
,
1050 ret_value
= (*(adc_cali_offset
+ 1));
1051 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_1_Offset : %d\n", ret_value
);
1052 return sprintf(buf
, "%u\n", ret_value
);
1055 static ssize_t
store_ADC_Channel_1_Offset(struct device
*dev
, struct device_attribute
*attr
,
1056 const char *buf
, size_t size
)
1058 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1062 static DEVICE_ATTR(ADC_Channel_1_Offset
, 0664, show_ADC_Channel_1_Offset
,
1063 store_ADC_Channel_1_Offset
);
1065 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1066 /* // Create File For EM : ADC_Channel_2_Offset */
1067 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1068 static ssize_t
show_ADC_Channel_2_Offset(struct device
*dev
, struct device_attribute
*attr
,
1072 ret_value
= (*(adc_cali_offset
+ 2));
1073 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_2_Offset : %d\n", ret_value
);
1074 return sprintf(buf
, "%u\n", ret_value
);
1077 static ssize_t
store_ADC_Channel_2_Offset(struct device
*dev
, struct device_attribute
*attr
,
1078 const char *buf
, size_t size
)
1080 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1084 static DEVICE_ATTR(ADC_Channel_2_Offset
, 0664, show_ADC_Channel_2_Offset
,
1085 store_ADC_Channel_2_Offset
);
1087 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1088 /* // Create File For EM : ADC_Channel_3_Offset */
1089 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1090 static ssize_t
show_ADC_Channel_3_Offset(struct device
*dev
, struct device_attribute
*attr
,
1094 ret_value
= (*(adc_cali_offset
+ 3));
1095 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_3_Offset : %d\n", ret_value
);
1096 return sprintf(buf
, "%u\n", ret_value
);
1099 static ssize_t
store_ADC_Channel_3_Offset(struct device
*dev
, struct device_attribute
*attr
,
1100 const char *buf
, size_t size
)
1102 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1106 static DEVICE_ATTR(ADC_Channel_3_Offset
, 0664, show_ADC_Channel_3_Offset
,
1107 store_ADC_Channel_3_Offset
);
1109 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1110 /* // Create File For EM : ADC_Channel_4_Offset */
1111 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1112 static ssize_t
show_ADC_Channel_4_Offset(struct device
*dev
, struct device_attribute
*attr
,
1116 ret_value
= (*(adc_cali_offset
+ 4));
1117 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_4_Offset : %d\n", ret_value
);
1118 return sprintf(buf
, "%u\n", ret_value
);
1121 static ssize_t
store_ADC_Channel_4_Offset(struct device
*dev
, struct device_attribute
*attr
,
1122 const char *buf
, size_t size
)
1124 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1128 static DEVICE_ATTR(ADC_Channel_4_Offset
, 0664, show_ADC_Channel_4_Offset
,
1129 store_ADC_Channel_4_Offset
);
1131 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1132 /* // Create File For EM : ADC_Channel_5_Offset */
1133 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1134 static ssize_t
show_ADC_Channel_5_Offset(struct device
*dev
, struct device_attribute
*attr
,
1138 ret_value
= (*(adc_cali_offset
+ 5));
1139 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_5_Offset : %d\n", ret_value
);
1140 return sprintf(buf
, "%u\n", ret_value
);
1143 static ssize_t
store_ADC_Channel_5_Offset(struct device
*dev
, struct device_attribute
*attr
,
1144 const char *buf
, size_t size
)
1146 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1150 static DEVICE_ATTR(ADC_Channel_5_Offset
, 0664, show_ADC_Channel_5_Offset
,
1151 store_ADC_Channel_5_Offset
);
1153 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1154 /* // Create File For EM : ADC_Channel_6_Offset */
1155 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1156 static ssize_t
show_ADC_Channel_6_Offset(struct device
*dev
, struct device_attribute
*attr
,
1160 ret_value
= (*(adc_cali_offset
+ 6));
1161 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_6_Offset : %d\n", ret_value
);
1162 return sprintf(buf
, "%u\n", ret_value
);
1165 static ssize_t
store_ADC_Channel_6_Offset(struct device
*dev
, struct device_attribute
*attr
,
1166 const char *buf
, size_t size
)
1168 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1172 static DEVICE_ATTR(ADC_Channel_6_Offset
, 0664, show_ADC_Channel_6_Offset
,
1173 store_ADC_Channel_6_Offset
);
1175 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1176 /* // Create File For EM : ADC_Channel_7_Offset */
1177 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1178 static ssize_t
show_ADC_Channel_7_Offset(struct device
*dev
, struct device_attribute
*attr
,
1182 ret_value
= (*(adc_cali_offset
+ 7));
1183 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_7_Offset : %d\n", ret_value
);
1184 return sprintf(buf
, "%u\n", ret_value
);
1187 static ssize_t
store_ADC_Channel_7_Offset(struct device
*dev
, struct device_attribute
*attr
,
1188 const char *buf
, size_t size
)
1190 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1194 static DEVICE_ATTR(ADC_Channel_7_Offset
, 0664, show_ADC_Channel_7_Offset
,
1195 store_ADC_Channel_7_Offset
);
1197 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1198 /* // Create File For EM : ADC_Channel_8_Offset */
1199 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1200 static ssize_t
show_ADC_Channel_8_Offset(struct device
*dev
, struct device_attribute
*attr
,
1204 ret_value
= (*(adc_cali_offset
+ 8));
1205 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_8_Offset : %d\n", ret_value
);
1206 return sprintf(buf
, "%u\n", ret_value
);
1209 static ssize_t
store_ADC_Channel_8_Offset(struct device
*dev
, struct device_attribute
*attr
,
1210 const char *buf
, size_t size
)
1212 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1216 static DEVICE_ATTR(ADC_Channel_8_Offset
, 0664, show_ADC_Channel_8_Offset
,
1217 store_ADC_Channel_8_Offset
);
1219 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1220 /* // Create File For EM : ADC_Channel_9_Offset */
1221 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1222 static ssize_t
show_ADC_Channel_9_Offset(struct device
*dev
, struct device_attribute
*attr
,
1226 ret_value
= (*(adc_cali_offset
+ 9));
1227 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_9_Offset : %d\n", ret_value
);
1228 return sprintf(buf
, "%u\n", ret_value
);
1231 static ssize_t
store_ADC_Channel_9_Offset(struct device
*dev
, struct device_attribute
*attr
,
1232 const char *buf
, size_t size
)
1234 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1238 static DEVICE_ATTR(ADC_Channel_9_Offset
, 0664, show_ADC_Channel_9_Offset
,
1239 store_ADC_Channel_9_Offset
);
1241 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1242 /* // Create File For EM : ADC_Channel_10_Offset */
1243 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1244 static ssize_t
show_ADC_Channel_10_Offset(struct device
*dev
, struct device_attribute
*attr
,
1248 ret_value
= (*(adc_cali_offset
+ 10));
1249 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_10_Offset : %d\n", ret_value
);
1250 return sprintf(buf
, "%u\n", ret_value
);
1253 static ssize_t
store_ADC_Channel_10_Offset(struct device
*dev
, struct device_attribute
*attr
,
1254 const char *buf
, size_t size
)
1256 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1260 static DEVICE_ATTR(ADC_Channel_10_Offset
, 0664, show_ADC_Channel_10_Offset
,
1261 store_ADC_Channel_10_Offset
);
1263 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1264 /* // Create File For EM : ADC_Channel_11_Offset */
1265 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1266 static ssize_t
show_ADC_Channel_11_Offset(struct device
*dev
, struct device_attribute
*attr
,
1270 ret_value
= (*(adc_cali_offset
+ 11));
1271 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_11_Offset : %d\n", ret_value
);
1272 return sprintf(buf
, "%u\n", ret_value
);
1275 static ssize_t
store_ADC_Channel_11_Offset(struct device
*dev
, struct device_attribute
*attr
,
1276 const char *buf
, size_t size
)
1278 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1282 static DEVICE_ATTR(ADC_Channel_11_Offset
, 0664, show_ADC_Channel_11_Offset
,
1283 store_ADC_Channel_11_Offset
);
1285 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1286 /* // Create File For EM : ADC_Channel_12_Offset */
1287 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1288 static ssize_t
show_ADC_Channel_12_Offset(struct device
*dev
, struct device_attribute
*attr
,
1292 ret_value
= (*(adc_cali_offset
+ 12));
1293 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_12_Offset : %d\n", ret_value
);
1294 return sprintf(buf
, "%u\n", ret_value
);
1297 static ssize_t
store_ADC_Channel_12_Offset(struct device
*dev
, struct device_attribute
*attr
,
1298 const char *buf
, size_t size
)
1300 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1304 static DEVICE_ATTR(ADC_Channel_12_Offset
, 0664, show_ADC_Channel_12_Offset
,
1305 store_ADC_Channel_12_Offset
);
1307 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1308 /* // Create File For EM : ADC_Channel_13_Offset */
1309 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1310 static ssize_t
show_ADC_Channel_13_Offset(struct device
*dev
, struct device_attribute
*attr
,
1314 ret_value
= (*(adc_cali_offset
+ 13));
1315 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_13_Offset : %d\n", ret_value
);
1316 return sprintf(buf
, "%u\n", ret_value
);
1319 static ssize_t
store_ADC_Channel_13_Offset(struct device
*dev
, struct device_attribute
*attr
,
1320 const char *buf
, size_t size
)
1322 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1326 static DEVICE_ATTR(ADC_Channel_13_Offset
, 0664, show_ADC_Channel_13_Offset
,
1327 store_ADC_Channel_13_Offset
);
1329 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1330 /* // Create File For EM : ADC_Channel_Is_Calibration */
1331 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1332 static ssize_t
show_ADC_Channel_Is_Calibration(struct device
*dev
, struct device_attribute
*attr
,
1336 ret_value
= g_ADC_Cali
;
1337 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] ADC_Channel_Is_Calibration : %d\n", ret_value
);
1338 return sprintf(buf
, "%u\n", ret_value
);
1341 static ssize_t
store_ADC_Channel_Is_Calibration(struct device
*dev
, struct device_attribute
*attr
,
1342 const char *buf
, size_t size
)
1344 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1348 static DEVICE_ATTR(ADC_Channel_Is_Calibration
, 0664, show_ADC_Channel_Is_Calibration
,
1349 store_ADC_Channel_Is_Calibration
);
1351 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1352 /* // Create File For EM : Power_On_Voltage */
1353 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1354 static ssize_t
show_Power_On_Voltage(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1358 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Power_On_Voltage : %d\n", ret_value
);
1359 return sprintf(buf
, "%u\n", ret_value
);
1362 static ssize_t
store_Power_On_Voltage(struct device
*dev
, struct device_attribute
*attr
,
1363 const char *buf
, size_t size
)
1365 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1369 static DEVICE_ATTR(Power_On_Voltage
, 0664, show_Power_On_Voltage
, store_Power_On_Voltage
);
1371 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1372 /* // Create File For EM : Power_Off_Voltage */
1373 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1374 static ssize_t
show_Power_Off_Voltage(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1378 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Power_Off_Voltage : %d\n", ret_value
);
1379 return sprintf(buf
, "%u\n", ret_value
);
1382 static ssize_t
store_Power_Off_Voltage(struct device
*dev
, struct device_attribute
*attr
,
1383 const char *buf
, size_t size
)
1385 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1389 static DEVICE_ATTR(Power_Off_Voltage
, 0664, show_Power_Off_Voltage
, store_Power_Off_Voltage
);
1391 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1392 /* // Create File For EM : Charger_TopOff_Value */
1393 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1394 static ssize_t
show_Charger_TopOff_Value(struct device
*dev
, struct device_attribute
*attr
,
1399 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Charger_TopOff_Value : %d\n", ret_value
);
1400 return sprintf(buf
, "%u\n", ret_value
);
1403 static ssize_t
store_Charger_TopOff_Value(struct device
*dev
, struct device_attribute
*attr
,
1404 const char *buf
, size_t size
)
1406 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1410 static DEVICE_ATTR(Charger_TopOff_Value
, 0664, show_Charger_TopOff_Value
,
1411 store_Charger_TopOff_Value
);
1413 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1414 /* // Create File For EM : FG_Battery_CurrentConsumption */
1415 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1416 static ssize_t
show_FG_Battery_CurrentConsumption(struct device
*dev
, struct device_attribute
*attr
,
1419 int ret_value
= 8888;
1420 ret_value
= battery_meter_get_battery_current();
1421 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] FG_Battery_CurrentConsumption : %d/10 mA\n",
1423 return sprintf(buf
, "%u\n", ret_value
);
1426 static ssize_t
store_FG_Battery_CurrentConsumption(struct device
*dev
,
1427 struct device_attribute
*attr
, const char *buf
,
1430 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1434 static DEVICE_ATTR(FG_Battery_CurrentConsumption
, 0664, show_FG_Battery_CurrentConsumption
,
1435 store_FG_Battery_CurrentConsumption
);
1437 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1438 /* // Create File For EM : FG_SW_CoulombCounter */
1439 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1440 static ssize_t
show_FG_SW_CoulombCounter(struct device
*dev
, struct device_attribute
*attr
,
1443 kal_int32 ret_value
= 7777;
1444 ret_value
= battery_meter_get_car();
1445 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] FG_SW_CoulombCounter : %d\n", ret_value
);
1446 return sprintf(buf
, "%u\n", ret_value
);
1449 static ssize_t
store_FG_SW_CoulombCounter(struct device
*dev
, struct device_attribute
*attr
,
1450 const char *buf
, size_t size
)
1452 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1456 static DEVICE_ATTR(FG_SW_CoulombCounter
, 0664, show_FG_SW_CoulombCounter
,
1457 store_FG_SW_CoulombCounter
);
1460 static ssize_t
show_Charging_CallState(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1462 battery_xlog_printk(BAT_LOG_CRTI
, "call state = %d\n", g_call_state
);
1463 return sprintf(buf
, "%u\n", g_call_state
);
1466 static ssize_t
store_Charging_CallState(struct device
*dev
, struct device_attribute
*attr
,
1467 const char *buf
, size_t size
)
1469 sscanf(buf
, "%u", &g_call_state
);
1470 battery_xlog_printk(BAT_LOG_CRTI
, "call state = %d\n", g_call_state
);
1474 static DEVICE_ATTR(Charging_CallState
, 0664, show_Charging_CallState
, store_Charging_CallState
);
1476 static ssize_t
show_Charger_Type(struct device
*dev
,struct device_attribute
*attr
,
1479 UINT32 chr_ype
= CHARGER_UNKNOWN
;
1480 chr_ype
= BMT_status
.charger_exist
? BMT_status
.charger_type
: CHARGER_UNKNOWN
;
1482 battery_xlog_printk(BAT_LOG_CRTI
, "CHARGER_TYPE = %d\n",chr_ype
);
1483 return sprintf(buf
, "%u\n", chr_ype
);
1485 static ssize_t
store_Charger_Type(struct device
*dev
,struct device_attribute
*attr
, const char *buf
, size_t size
)
1487 battery_xlog_printk(BAT_LOG_CRTI
, "[EM] Not Support Write Function\n");
1490 static DEVICE_ATTR(Charger_Type
, 0664, show_Charger_Type
, store_Charger_Type
);
1492 #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) || defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
1493 static ssize_t
show_Pump_Express(struct device
*dev
,struct device_attribute
*attr
,
1496 #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
1497 int icount
= 20; //max debouncing time 20 * 0.2 sec
1499 if (KAL_TRUE
== ta_check_chr_type
&&
1500 STANDARD_CHARGER
== BMT_status
.charger_type
&&
1501 BMT_status
.SOC
>= TA_START_BATTERY_SOC
&&
1502 BMT_status
.SOC
< TA_STOP_BATTERY_SOC
)
1504 battery_xlog_printk(BAT_LOG_CRTI
, "[%s]Wait for PE detection\n", __func__
);
1509 }while(icount
&& ta_check_chr_type
);
1513 #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT)
1515 if ( (KAL_TRUE
== ta_check_chr_type
) &&
1516 (STANDARD_CHARGER
== BMT_status
.charger_type
) )
1518 battery_xlog_printk(BAT_LOG_CRTI
, "[%s]Wait for PE detection\n", __func__
);
1522 }while(ta_check_chr_type
);
1525 battery_xlog_printk(BAT_LOG_CRTI
, "Pump express = %d\n",is_ta_connect
);
1526 return sprintf(buf
, "%u\n", is_ta_connect
);
1528 static ssize_t
store_Pump_Express(struct device
*dev
,struct device_attribute
*attr
, const char *buf
, size_t size
)
1530 sscanf(buf
, "%u", &is_ta_connect
);
1531 battery_xlog_printk(BAT_LOG_CRTI
, "Pump express= %d\n",is_ta_connect
);
1534 static DEVICE_ATTR(Pump_Express
, 0664, show_Pump_Express
, store_Pump_Express
);
1537 static void mt_battery_update_EM(struct battery_data
*bat_data
)
1539 bat_data
->BAT_CAPACITY
= BMT_status
.UI_SOC
;
1540 bat_data
->BAT_TemperatureR
= BMT_status
.temperatureR
; /* API */
1541 bat_data
->BAT_TempBattVoltage
= BMT_status
.temperatureV
; /* API */
1542 bat_data
->BAT_InstatVolt
= BMT_status
.bat_vol
; /* VBAT */
1543 bat_data
->BAT_BatteryAverageCurrent
= BMT_status
.ICharging
;
1544 bat_data
->BAT_BatterySenseVoltage
= BMT_status
.bat_vol
;
1545 bat_data
->BAT_ISenseVoltage
= BMT_status
.Vsense
; /* API */
1546 bat_data
->BAT_ChargerVoltage
= BMT_status
.charger_vol
;
1548 bat_data
->status_smb
= g_status_smb
;
1549 bat_data
->capacity_smb
= g_capacity_smb
;
1550 bat_data
->present_smb
= g_present_smb
;
1551 battery_xlog_printk(BAT_LOG_FULL
, "status_smb = %d, capacity_smb = %d, present_smb = %d\n",
1552 bat_data
->status_smb
, bat_data
->capacity_smb
, bat_data
->present_smb
);
1553 if ((BMT_status
.UI_SOC
== 100) && (BMT_status
.charger_exist
== KAL_TRUE
))
1554 bat_data
->BAT_STATUS
= POWER_SUPPLY_STATUS_FULL
;
1556 #ifdef CONFIG_MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION
1557 if (bat_data
->BAT_CAPACITY
<= 0)
1558 bat_data
->BAT_CAPACITY
= 1;
1560 battery_xlog_printk(BAT_LOG_CRTI
,
1561 "BAT_CAPACITY=1, due to define CONFIG_MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION\r\n");
1566 static kal_bool
mt_battery_100Percent_tracking_check(void)
1568 kal_bool resetBatteryMeter
= KAL_FALSE
;
1570 #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
1571 kal_uint32 cust_sync_time
= CUST_SOC_JEITA_SYNC_TIME
;
1572 static kal_uint32 timer_counter
= (CUST_SOC_JEITA_SYNC_TIME
/ BAT_TASK_PERIOD
);
1574 kal_uint32 cust_sync_time
= ONEHUNDRED_PERCENT_TRACKING_TIME
;
1575 static kal_uint32 timer_counter
= (ONEHUNDRED_PERCENT_TRACKING_TIME
/ BAT_TASK_PERIOD
);
1578 if (BMT_status
.bat_full
== KAL_TRUE
) /* charging full first, UI tracking to 100% */
1580 if (BMT_status
.UI_SOC
>= 100) {
1581 BMT_status
.UI_SOC
= 100;
1583 if ((g_charging_full_reset_bat_meter
== KAL_TRUE
)
1584 && (BMT_status
.bat_charging_state
== CHR_BATFULL
)) {
1585 resetBatteryMeter
= KAL_TRUE
;
1586 g_charging_full_reset_bat_meter
= KAL_FALSE
;
1588 resetBatteryMeter
= KAL_FALSE
;
1591 /* increase UI percentage every xxs */
1592 if (timer_counter
>= (cust_sync_time
/ BAT_TASK_PERIOD
)) {
1594 BMT_status
.UI_SOC
++;
1598 return resetBatteryMeter
;
1601 resetBatteryMeter
= KAL_TRUE
;
1604 battery_xlog_printk(BAT_LOG_CRTI
, "[100percent], UI_SOC(%d), reset(%d)\n",
1605 BMT_status
.UI_SOC
, resetBatteryMeter
);
1607 /* charging is not full, UI keep 99% if reaching 100%, */
1609 if (BMT_status
.UI_SOC
>= 99) {
1610 BMT_status
.UI_SOC
= 99;
1611 resetBatteryMeter
= KAL_FALSE
;
1613 battery_xlog_printk(BAT_LOG_CRTI
, "[100percent],UI_SOC = %d\n",
1617 timer_counter
= (cust_sync_time
/ BAT_TASK_PERIOD
);
1621 return resetBatteryMeter
;
1625 static kal_bool
mt_battery_nPercent_tracking_check(void)
1627 kal_bool resetBatteryMeter
= KAL_FALSE
;
1628 #if defined(SOC_BY_HW_FG)
1629 static kal_uint32 timer_counter
= (NPERCENT_TRACKING_TIME
/ BAT_TASK_PERIOD
);
1631 if (BMT_status
.nPrecent_UI_SOC_check_point
== 0)
1634 /* fuel gauge ZCV < 15%, but UI > 15%, 15% can be customized */
1635 if ((BMT_status
.ZCV
<= BMT_status
.nPercent_ZCV
)
1636 && (BMT_status
.UI_SOC
> BMT_status
.nPrecent_UI_SOC_check_point
)) {
1637 if (timer_counter
== (NPERCENT_TRACKING_TIME
/ BAT_TASK_PERIOD
)) /* every x sec decrease UI percentage */
1639 BMT_status
.UI_SOC
--;
1643 return resetBatteryMeter
;
1646 resetBatteryMeter
= KAL_TRUE
;
1648 battery_xlog_printk(BAT_LOG_CRTI
,
1649 "[nPercent] ZCV %d <= nPercent_ZCV %d, UI_SOC=%d., tracking UI_SOC=%d\n",
1650 BMT_status
.ZCV
, BMT_status
.nPercent_ZCV
, BMT_status
.UI_SOC
,
1651 BMT_status
.nPrecent_UI_SOC_check_point
);
1652 } else if ((BMT_status
.ZCV
> BMT_status
.nPercent_ZCV
)
1653 && (BMT_status
.UI_SOC
== BMT_status
.nPrecent_UI_SOC_check_point
)) {
1654 /* UI less than 15 , but fuel gague is more than 15, hold UI 15% */
1655 timer_counter
= (NPERCENT_TRACKING_TIME
/ BAT_TASK_PERIOD
);
1656 resetBatteryMeter
= KAL_TRUE
;
1658 battery_xlog_printk(BAT_LOG_CRTI
,
1659 "[nPercent] ZCV %d > BMT_status.nPercent_ZCV %d and UI SOC=%d, then keep %d.\n",
1660 BMT_status
.ZCV
, BMT_status
.nPercent_ZCV
, BMT_status
.UI_SOC
,
1661 BMT_status
.nPrecent_UI_SOC_check_point
);
1663 timer_counter
= (NPERCENT_TRACKING_TIME
/ BAT_TASK_PERIOD
);
1666 return resetBatteryMeter
;
1670 static kal_bool
mt_battery_0Percent_tracking_check(void)
1672 kal_bool resetBatteryMeter
= KAL_TRUE
;
1674 if (BMT_status
.UI_SOC
<= 0) {
1675 BMT_status
.UI_SOC
= 0;
1677 if (BMT_status
.bat_vol
> SYSTEM_OFF_VOLTAGE
&& BMT_status
.UI_SOC
> 1) {
1678 BMT_status
.UI_SOC
--;
1679 } else if (BMT_status
.bat_vol
<= SYSTEM_OFF_VOLTAGE
) {
1680 BMT_status
.UI_SOC
--;
1684 battery_xlog_printk(BAT_LOG_CRTI
, "0Percent, VBAT < %d UI_SOC=%d\r\n", SYSTEM_OFF_VOLTAGE
,
1687 return resetBatteryMeter
;
1691 static void mt_battery_Sync_UI_Percentage_to_Real(void)
1693 static kal_uint32 timer_counter
;
1695 if ((BMT_status
.UI_SOC
> BMT_status
.SOC
) && ((BMT_status
.UI_SOC
!= 1))) {
1696 #if !defined (SYNC_UI_SOC_IMM)
1697 /*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015, pr-975290, add standby current */
1698 sleep_timer
= cur_timer_counter
- pre_timer_counter
;
1700 if (sleep_timer
> 80) //80 s
1702 soc_reduce_step
= (sleep_timer
/60)/10 + 1; //10min UI reduce 1
1703 battery_xlog_printk(BAT_LOG_CRTI
, "soc_reduce_step = %d, sleeptime=(%d)s\n", soc_reduce_step
, sleep_timer
);
1705 if (soc_reduce_step
> (BMT_status
.UI_SOC
- BMT_status
.SOC
))
1707 BMT_status
.UI_SOC
= BMT_status
.SOC
;
1711 BMT_status
.UI_SOC
= BMT_status
.UI_SOC
- soc_reduce_step
;
1716 /* reduce after xxs */
1717 if (timer_counter
== (SYNC_TO_REAL_TRACKING_TIME
/ BAT_TASK_PERIOD
)) {
1718 BMT_status
.UI_SOC
--;
1724 /*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
1726 BMT_status
.UI_SOC
--;
1728 battery_xlog_printk(BAT_LOG_CRTI
, "[Sync_Real] UI_SOC=%d, SOC=%d, counter = %d\n",
1729 BMT_status
.UI_SOC
, BMT_status
.SOC
, timer_counter
);
1733 #ifdef CUST_CAPACITY_OCV2CV_TRANSFORM
1734 if (BMT_status
.UI_SOC
!= -1 && BMT_status
.UI_SOC
< BMT_status
.SOC
&& (BMT_status
.SOC
- BMT_status
.UI_SOC
> 1))
1736 if( upmu_is_chr_det() == KAL_TRUE
)
1737 BMT_status
.UI_SOC
++;
1741 BMT_status
.UI_SOC
= BMT_status
.SOC
;
1744 BMT_status
.UI_SOC
= BMT_status
.SOC
;
1748 /* [PLATFORM]-Add-BEGIN by TCTSZ.pingao.yang, 2015.03.30, refer pr 951694 */
1750 if (BMT_status
.UI_SOC
<= 0) {
1751 BMT_status
.UI_SOC
= 1;
1752 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery]UI_SOC get 0 first (%d)\r\n",
1756 /* [PLATFORM]-Add-END by TCTSZ.pingao.yang, 2015.03.30 */
1760 static void battery_update(struct battery_data
*bat_data
)
1762 struct power_supply
*bat_psy
= &bat_data
->psy
;
1763 kal_bool resetBatteryMeter
= KAL_FALSE
;
1765 bat_data
->BAT_TECHNOLOGY
= POWER_SUPPLY_TECHNOLOGY_LION
;
1766 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, modify ntc temperature function */
1767 #ifdef MTK_BATTERY_PROTECT_FEATURE
1768 switch( g_batt_temp_status
){
1770 bat_data
->BAT_HEALTH
= POWER_SUPPLY_HEALTH_COLD
;
1772 case TEMP_POS_NORMAL
:
1773 bat_data
->BAT_HEALTH
= POWER_SUPPLY_HEALTH_GOOD
;
1776 bat_data
->BAT_HEALTH
= POWER_SUPPLY_HEALTH_OVERHEAT
;
1779 bat_data
->BAT_HEALTH
= POWER_SUPPLY_HEALTH_UNKNOWN
;
1783 bat_data
->BAT_HEALTH
= POWER_SUPPLY_HEALTH_GOOD
;
1785 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
1786 bat_data
->BAT_batt_vol
= BMT_status
.bat_vol
;
1787 bat_data
->BAT_batt_temp
= BMT_status
.temperature
* 10;
1788 bat_data
->BAT_PRESENT
= BMT_status
.bat_exist
;
1790 /*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015, pr-975290, add standby current */
1791 cur_timer_counter
= rtc_read_hw_time();
1792 /*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
1794 if ((BMT_status
.charger_exist
== KAL_TRUE
) && (BMT_status
.bat_charging_state
!= CHR_ERROR
)) {
1795 if (BMT_status
.bat_exist
) { /* charging */
1796 if (BMT_status
.bat_vol
<= V_0PERCENT_TRACKING
) {
1797 resetBatteryMeter
= mt_battery_0Percent_tracking_check();
1799 resetBatteryMeter
= mt_battery_100Percent_tracking_check();
1802 bat_data
->BAT_STATUS
= POWER_SUPPLY_STATUS_CHARGING
;
1803 } else { /* No Battery, Only Charger */
1805 bat_data
->BAT_STATUS
= POWER_SUPPLY_STATUS_UNKNOWN
;
1806 BMT_status
.UI_SOC
= 0;
1809 } else { /* Only Battery */
1811 bat_data
->BAT_STATUS
= POWER_SUPPLY_STATUS_NOT_CHARGING
;
1812 if (BMT_status
.bat_vol
<= V_0PERCENT_TRACKING
)
1813 resetBatteryMeter
= mt_battery_0Percent_tracking_check();
1815 resetBatteryMeter
= mt_battery_nPercent_tracking_check();
1818 if (resetBatteryMeter
== KAL_TRUE
) {
1819 battery_meter_reset();
1821 if (bat_is_recharging_phase() == KAL_TRUE
) {
1822 BMT_status
.UI_SOC
= 100;
1823 battery_xlog_printk(BAT_LOG_CRTI
, "[recharging] UI_SOC=%d, SOC=%d\n",
1824 BMT_status
.UI_SOC
, BMT_status
.SOC
);
1826 mt_battery_Sync_UI_Percentage_to_Real();
1830 battery_xlog_printk(BAT_LOG_CRTI
, "UI_SOC=(%d), resetBatteryMeter=(%d)\n",
1831 BMT_status
.UI_SOC
, resetBatteryMeter
);
1833 /*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015, pr-975290, add standby current */
1834 pre_timer_counter
= cur_timer_counter
;
1835 /*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
1836 #ifdef CUST_CAPACITY_OCV2CV_TRANSFORM
1837 //restore battery UI capacity to rtc
1838 if (battery_meter_get_battery_soc() <= 1) {
1839 set_rtc_spare_fg_value(1);
1842 set_rtc_spare_fg_value(battery_meter_get_battery_soc()); /*use battery_soc*/
1846 /* set RTC SOC to 1 to avoid SOC jump in charger boot. */
1847 if (BMT_status
.UI_SOC
<= 1) {
1848 set_rtc_spare_fg_value(1);
1850 set_rtc_spare_fg_value(BMT_status
.UI_SOC
);
1854 mt_battery_update_EM(bat_data
);
1856 if (cmd_discharging
== 1) {
1857 bat_data
->BAT_STATUS
= POWER_SUPPLY_STATUS_CMD_DISCHARGING
;
1859 if (adjust_power
!= -1) {
1860 bat_data
->adjust_power
= adjust_power
;
1861 battery_xlog_printk(BAT_LOG_CRTI
, "adjust_power=(%d)\n", adjust_power
);
1864 power_supply_changed(bat_psy
);
1867 void update_charger_info(int wireless_state
)
1869 #if defined(CONFIG_POWER_VERIFY)
1870 battery_xlog_printk(BAT_LOG_CRTI
, "[update_charger_info] no support\n");
1872 g_wireless_state
= wireless_state
;
1873 battery_xlog_printk(BAT_LOG_CRTI
, "[update_charger_info] get wireless_state=%d\n",
1880 static void wireless_update(struct wireless_data
*wireless_data
)
1882 struct power_supply
*wireless_psy
= &wireless_data
->psy
;
1884 if (BMT_status
.charger_exist
== KAL_TRUE
|| g_wireless_state
) {
1885 if ((BMT_status
.charger_type
== WIRELESS_CHARGER
) || g_wireless_state
) {
1886 wireless_data
->WIRELESS_ONLINE
= 1;
1887 wireless_psy
->type
= POWER_SUPPLY_TYPE_WIRELESS
;
1889 wireless_data
->WIRELESS_ONLINE
= 0;
1892 wireless_data
->WIRELESS_ONLINE
= 0;
1895 power_supply_changed(wireless_psy
);
1898 static void ac_update(struct ac_data
*ac_data
)
1900 struct power_supply
*ac_psy
= &ac_data
->psy
;
1902 if (BMT_status
.charger_exist
== KAL_TRUE
) {
1903 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
1904 if ((BMT_status
.charger_type
== NONSTANDARD_CHARGER
) ||
1905 (BMT_status
.charger_type
== STANDARD_CHARGER
) ||
1906 (BMT_status
.charger_type
== APPLE_2_1A_CHARGER
) ||
1907 (BMT_status
.charger_type
== APPLE_1_0A_CHARGER
) ||
1908 (BMT_status
.charger_type
== APPLE_0_5A_CHARGER
)) {
1910 if ((BMT_status
.charger_type
== NONSTANDARD_CHARGER
) ||
1911 (BMT_status
.charger_type
== STANDARD_CHARGER
) ||
1912 (BMT_status
.charger_type
== APPLE_2_1A_CHARGER
) ||
1913 (BMT_status
.charger_type
== APPLE_1_0A_CHARGER
) ||
1914 (BMT_status
.charger_type
== APPLE_0_5A_CHARGER
) ||
1915 (DISO_data
.diso_state
.cur_vdc_state
== DISO_ONLINE
)) {
1917 ac_data
->AC_ONLINE
= 1;
1918 ac_psy
->type
= POWER_SUPPLY_TYPE_MAINS
;
1920 ac_data
->AC_ONLINE
= 0;
1923 ac_data
->AC_ONLINE
= 0;
1926 power_supply_changed(ac_psy
);
1929 static void usb_update(struct usb_data
*usb_data
)
1931 struct power_supply
*usb_psy
= &usb_data
->psy
;
1933 if (BMT_status
.charger_exist
== KAL_TRUE
) {
1934 if ((BMT_status
.charger_type
== STANDARD_HOST
) ||
1935 (BMT_status
.charger_type
== CHARGING_HOST
)) {
1936 usb_data
->USB_ONLINE
= 1;
1937 usb_psy
->type
= POWER_SUPPLY_TYPE_USB
;
1939 usb_data
->USB_ONLINE
= 0;
1942 usb_data
->USB_ONLINE
= 0;
1945 power_supply_changed(usb_psy
);
1950 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, add ntc simulation function */
1951 #if (defined MTK_NTC_DEBUG_SIMULATE)
1952 static ssize_t
chg_ntc_debugfs_store(struct device
*dev
,
1953 struct device_attribute
*attr
,
1954 const char *buf
, ssize_t count
)
1956 battery_temp
= simple_strtol(buf
, NULL
, 10);
1957 battery_xlog_printk(BAT_LOG_CRTI
,
1958 "Usage: echo [temp] > sys/devices/platform/battery/ntc_debug: battery_temp = %d\n",
1964 static ssize_t
chg_ntc_debugfs_show(struct device
*dev
, struct device_attribute
*attr
,
1967 return sprintf(buf
, "battery_temp = %d\n", battery_temp
);
1970 static DEVICE_ATTR(ntc_debug
, 0644, chg_ntc_debugfs_show
, chg_ntc_debugfs_store
);
1972 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
1974 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1975 /* // Battery Temprature Parameters and functions */
1976 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1977 kal_bool
pmic_chrdet_status(void)
1979 if (upmu_is_chr_det() == KAL_TRUE
) {
1982 battery_xlog_printk(BAT_LOG_CRTI
, "[pmic_chrdet_status] No charger\r\n");
1987 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1988 /* // Pulse Charging Algorithm */
1989 /* ///////////////////////////////////////////////////////////////////////////////////////// */
1990 kal_bool
bat_is_charger_exist(void)
1992 return get_charger_detect_status();
1996 kal_bool
bat_is_charging_full(void)
1998 if ((BMT_status
.bat_full
== KAL_TRUE
) && (BMT_status
.bat_in_recharging_state
== KAL_FALSE
))
2005 kal_uint32
bat_get_ui_percentage(void)
2007 /* for plugging out charger in recharge phase, using SOC as UI_SOC */
2008 if (chr_wake_up_bat
== KAL_TRUE
)
2009 return BMT_status
.SOC
;
2011 return BMT_status
.UI_SOC
;
2014 /* Full state --> recharge voltage --> full state */
2015 kal_uint32
bat_is_recharging_phase(void)
2017 return (BMT_status
.bat_in_recharging_state
|| BMT_status
.bat_full
== KAL_TRUE
);
2021 int get_bat_charging_current_level(void)
2023 CHR_CURRENT_ENUM charging_current
;
2025 battery_charging_control(CHARGING_CMD_GET_CURRENT
, &charging_current
);
2027 return charging_current
;
2030 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, modify ntc temperature function */
2031 #ifdef MTK_BATTERY_PROTECT_FEATURE
2032 extern kal_bool high_temp_stop_charge
;
2034 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
2036 #if defined(MTK_TEMPERATURE_RECHARGE_SUPPORT)
2037 PMU_STATUS
do_batt_temp_state_machine(void)
2039 if (BMT_status
.temperature
== ERR_CHARGE_TEMPERATURE
) {
2040 return PMU_STATUS_FAIL
;
2042 #ifdef BAT_LOW_TEMP_PROTECT_ENABLE
2043 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, modify ntc temperature function */
2044 #ifdef MTK_BATTERY_PROTECT_FEATURE
2045 /* Battery temperature less than 2 degree, stop charging */
2046 if (BMT_status
.temperature
<= MIN_CHARGE_TEMPERATURE
) {
2048 if (BMT_status
.temperature
< MIN_CHARGE_TEMPERATURE
) {
2050 battery_xlog_printk(BAT_LOG_CRTI
,
2051 "[BATTERY] Battery Under Temperature or NTC fail !!\n\r");
2052 g_batt_temp_status
= TEMP_POS_LOW
;
2053 return PMU_STATUS_FAIL
;
2054 } else if (g_batt_temp_status
== TEMP_POS_LOW
) {
2055 /*Battery temperature more than 4 degree, recharging again*/
2056 if (BMT_status
.temperature
>= MIN_CHARGE_TEMPERATURE_PLUS_X_DEGREE
) {
2057 battery_xlog_printk(BAT_LOG_CRTI
,
2058 "[BATTERY] Battery Temperature raise from %d to %d(%d), allow charging!!\n\r",
2059 MIN_CHARGE_TEMPERATURE
, BMT_status
.temperature
,
2060 MIN_CHARGE_TEMPERATURE_PLUS_X_DEGREE
);
2061 g_batt_temp_status
= TEMP_POS_NORMAL
;
2062 BMT_status
.bat_charging_state
= CHR_PRE
;
2063 return PMU_STATUS_OK
;
2065 return PMU_STATUS_FAIL
;
2070 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, modify ntc temperature function */
2071 #ifdef MTK_BATTERY_PROTECT_FEATURE
2072 /* Battery temperature more than 55 degree, stop charging */
2073 if ((BMT_status
.temperature
>= MAX_CHARGE_TEMPERATURE
)
2074 || ((BMT_status
.temperature
>= MAX_LIMIT_CHARGE_TEMPERATURE
) && (high_temp_stop_charge
== KAL_TRUE
))){
2076 if (BMT_status
.temperature
>= MAX_CHARGE_TEMPERATURE
) {
2078 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
2079 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] Battery Over Temperature !!\n\r");
2080 g_batt_temp_status
= TEMP_POS_HIGH
;
2081 return PMU_STATUS_FAIL
;
2082 } else if (g_batt_temp_status
== TEMP_POS_HIGH
) {
2083 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, modify ntc temperature function */
2084 #ifdef MTK_BATTERY_PROTECT_FEATURE
2085 /* Battery temperature less than 50 degree. recharging again */
2086 if ((BMT_status
.temperature
<= MAX_CHARGE_TEMPERATURE_MINUS_X_DEGREE
)
2087 || ((BMT_status
.temperature
>= MAX_LIMIT_CHARGE_TEMPERATURE
) && (high_temp_stop_charge
== KAL_TRUE
))){
2088 high_temp_stop_charge
= KAL_FALSE
;
2090 if (BMT_status
.temperature
< MAX_CHARGE_TEMPERATURE_MINUS_X_DEGREE
) {
2092 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
2093 battery_xlog_printk(BAT_LOG_CRTI
,
2094 "[BATTERY] Battery Temperature down from %d to %d(%d), allow charging!!\n\r",
2095 MAX_CHARGE_TEMPERATURE
, BMT_status
.temperature
,
2096 MAX_CHARGE_TEMPERATURE_MINUS_X_DEGREE
);
2097 g_batt_temp_status
= TEMP_POS_NORMAL
;
2098 BMT_status
.bat_charging_state
= CHR_PRE
;
2099 return PMU_STATUS_OK
;
2101 return PMU_STATUS_FAIL
;
2104 g_batt_temp_status
= TEMP_POS_NORMAL
;
2106 return PMU_STATUS_OK
;
2110 unsigned long BAT_Get_Battery_Voltage(int polling_mode
)
2112 unsigned long ret_val
= 0;
2114 #if defined(CONFIG_POWER_EXT)
2117 ret_val
=battery_meter_get_battery_voltage(KAL_FALSE
);
2124 static void mt_battery_average_method_init(kal_uint32
*bufferdata
, kal_uint32 data
,
2128 static kal_bool batteryBufferFirst
= KAL_TRUE
;
2129 static kal_bool previous_charger_exist
= KAL_FALSE
;
2130 static kal_bool previous_in_recharge_state
= KAL_FALSE
;
2131 static kal_uint8 index
;
2133 /* reset charging current window while plug in/out { */
2134 if (BMT_status
.charger_exist
== KAL_TRUE
) {
2135 if (previous_charger_exist
== KAL_FALSE
) {
2136 batteryBufferFirst
= KAL_TRUE
;
2137 previous_charger_exist
= KAL_TRUE
;
2138 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2139 if (BMT_status
.charger_type
== STANDARD_CHARGER
) {
2141 if ((BMT_status
.charger_type
== STANDARD_CHARGER
) ||
2142 (DISO_data
.diso_state
.cur_vdc_state
== DISO_ONLINE
)) {
2144 data
= AC_CHARGER_CURRENT
/ 100;
2145 } else if (BMT_status
.charger_type
== CHARGING_HOST
) {
2146 data
= CHARGING_HOST_CHARGER_CURRENT
/ 100;
2147 } else if (BMT_status
.charger_type
== NONSTANDARD_CHARGER
)
2148 data
= NON_STD_AC_CHARGER_CURRENT
/ 100; /* mA */
2150 data
= USB_CHARGER_CURRENT
/ 100; /* mA */
2151 } else if ((previous_in_recharge_state
== KAL_FALSE
)
2152 && (BMT_status
.bat_in_recharging_state
== KAL_TRUE
)) {
2153 batteryBufferFirst
= KAL_TRUE
;
2154 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2155 if (BMT_status
.charger_type
== STANDARD_CHARGER
) {
2157 if ((BMT_status
.charger_type
== STANDARD_CHARGER
) ||
2158 (DISO_data
.diso_state
.cur_vdc_state
== DISO_ONLINE
)) {
2160 data
= AC_CHARGER_CURRENT
/ 100;
2161 } else if (BMT_status
.charger_type
== CHARGING_HOST
) {
2162 data
= CHARGING_HOST_CHARGER_CURRENT
/ 100;
2163 } else if (BMT_status
.charger_type
== NONSTANDARD_CHARGER
)
2164 data
= NON_STD_AC_CHARGER_CURRENT
/ 100; /* mA */
2166 data
= USB_CHARGER_CURRENT
/ 100; /* mA */
2169 previous_in_recharge_state
= BMT_status
.bat_in_recharging_state
;
2171 if (previous_charger_exist
== KAL_TRUE
) {
2172 batteryBufferFirst
= KAL_TRUE
;
2173 previous_charger_exist
= KAL_FALSE
;
2177 /* reset charging current window while plug in/out } */
2179 battery_xlog_printk(BAT_LOG_FULL
, "batteryBufferFirst =%d, data= (%d)\n",
2180 batteryBufferFirst
, data
);
2182 if (batteryBufferFirst
== KAL_TRUE
) {
2183 for (i
= 0; i
< BATTERY_AVERAGE_SIZE
; i
++) {
2184 bufferdata
[i
] = data
;
2187 *sum
= data
* BATTERY_AVERAGE_SIZE
;
2191 if (index
>= BATTERY_AVERAGE_DATA_NUMBER
) {
2192 index
= BATTERY_AVERAGE_DATA_NUMBER
;
2193 batteryBufferFirst
= KAL_FALSE
;
2198 static kal_uint32
mt_battery_average_method(kal_uint32
*bufferdata
, kal_uint32 data
,
2199 kal_int32
*sum
, kal_uint8 batteryIndex
)
2203 mt_battery_average_method_init(bufferdata
, data
, sum
);
2205 *sum
-= bufferdata
[batteryIndex
];
2207 bufferdata
[batteryIndex
] = data
;
2208 avgdata
= (*sum
) / BATTERY_AVERAGE_SIZE
;
2210 battery_xlog_printk(BAT_LOG_FULL
, "bufferdata[%d]= (%d)\n", batteryIndex
,
2211 bufferdata
[batteryIndex
]);
2215 void mt_battery_GetBatteryData(void)
2217 kal_uint32 bat_vol
, charger_vol
, Vsense
, ZCV
;
2218 kal_int32 ICharging
, temperature
, temperatureR
, temperatureV
, SOC
;
2219 static kal_int32 bat_sum
, icharging_sum
, temperature_sum
;
2220 static kal_int32 batteryVoltageBuffer
[BATTERY_AVERAGE_SIZE
];
2221 static kal_int32 batteryCurrentBuffer
[BATTERY_AVERAGE_SIZE
];
2222 static kal_int32 batteryTempBuffer
[BATTERY_AVERAGE_SIZE
];
2223 static kal_uint8 batteryIndex
= 0;
2224 static kal_int32 previous_SOC
= -1;
2226 bat_vol
= battery_meter_get_battery_voltage(KAL_TRUE
);
2227 Vsense
= battery_meter_get_VSense();
2228 if( upmu_is_chr_det() == KAL_TRUE
) {
2229 ICharging
= battery_meter_get_charging_current();
2234 charger_vol
= battery_meter_get_charger_voltage();
2235 temperature
= battery_meter_get_battery_temperature();
2236 temperatureV
= battery_meter_get_tempV();
2237 temperatureR
= battery_meter_get_tempR(temperatureV
);
2239 if (bat_meter_timeout
== KAL_TRUE
|| bat_spm_timeout
== TRUE
) {
2240 SOC
= battery_meter_get_battery_percentage();
2241 //if (bat_spm_timeout == true)
2242 //BMT_status.UI_SOC = battery_meter_get_battery_percentage();
2244 bat_meter_timeout
= KAL_FALSE
;
2245 bat_spm_timeout
= FALSE
;
2247 if (previous_SOC
== -1)
2248 SOC
= battery_meter_get_battery_percentage();
2253 ZCV
= battery_meter_get_battery_zcv();
2255 BMT_status
.ICharging
=
2256 mt_battery_average_method(&batteryCurrentBuffer
[0], ICharging
, &icharging_sum
,
2260 if (previous_SOC
== -1 && bat_vol
<= V_0PERCENT_TRACKING
) {
2261 battery_xlog_printk(BAT_LOG_CRTI
,
2262 "battery voltage too low, use ZCV to init average data.\n");
2263 BMT_status
.bat_vol
=
2264 mt_battery_average_method(&batteryVoltageBuffer
[0], ZCV
, &bat_sum
,
2267 BMT_status
.bat_vol
=
2268 mt_battery_average_method(&batteryVoltageBuffer
[0], bat_vol
, &bat_sum
,
2271 BMT_status
.temperature
=
2272 mt_battery_average_method(&batteryTempBuffer
[0], temperature
, &temperature_sum
,
2274 BMT_status
.Vsense
= Vsense
;
2275 BMT_status
.charger_vol
= charger_vol
;
2276 BMT_status
.temperatureV
= temperatureV
;
2277 BMT_status
.temperatureR
= temperatureR
;
2278 BMT_status
.SOC
= SOC
;
2279 BMT_status
.ZCV
= ZCV
;
2281 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, add ntc simulation function */
2282 #if (defined MTK_NTC_DEBUG_SIMULATE)
2283 BMT_status
.temperature
= battery_temp
;
2285 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
2286 if (BMT_status
.charger_exist
== KAL_FALSE
) {
2287 if (BMT_status
.SOC
> previous_SOC
&& previous_SOC
>= 0)
2288 BMT_status
.SOC
= previous_SOC
;
2291 previous_SOC
= BMT_status
.SOC
;
2294 if (batteryIndex
>= BATTERY_AVERAGE_SIZE
)
2298 if (g_battery_soc_ready
== KAL_FALSE
)
2299 g_battery_soc_ready
= KAL_TRUE
;
2301 battery_xlog_printk(BAT_LOG_CRTI
,
2302 "AvgVbat=(%d),bat_vol=(%d),AvgI=(%d),I=(%d),VChr=(%d),AvgT=(%d),T=(%d),pre_SOC=(%d),SOC=(%d),ZCV=(%d)\n",
2303 BMT_status
.bat_vol
, bat_vol
, BMT_status
.ICharging
, ICharging
,
2304 BMT_status
.charger_vol
, BMT_status
.temperature
, temperature
,
2305 previous_SOC
, BMT_status
.SOC
, BMT_status
.ZCV
);
2311 static PMU_STATUS
mt_battery_CheckBatteryTemp(void)
2313 PMU_STATUS status
= PMU_STATUS_OK
;
2315 #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
2317 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] support JEITA, temperature=%d\n",
2318 BMT_status
.temperature
);
2320 if (do_jeita_state_machine() == PMU_STATUS_FAIL
) {
2321 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] JEITA : fail\n");
2322 status
= PMU_STATUS_FAIL
;
2326 #if defined(MTK_TEMPERATURE_RECHARGE_SUPPORT)
2327 if (do_batt_temp_state_machine() == PMU_STATUS_FAIL
) {
2328 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] Batt temp check : fail\n");
2329 status
= PMU_STATUS_FAIL
;
2332 #ifdef BAT_LOW_TEMP_PROTECT_ENABLE
2333 if ((BMT_status
.temperature
< MIN_CHARGE_TEMPERATURE
)
2334 || (BMT_status
.temperature
== ERR_CHARGE_TEMPERATURE
)) {
2335 battery_xlog_printk(BAT_LOG_CRTI
,
2336 "[BATTERY] Battery Under Temperature or NTC fail !!\n\r");
2337 status
= PMU_STATUS_FAIL
;
2340 if (BMT_status
.temperature
>= MAX_CHARGE_TEMPERATURE
) {
2341 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] Battery Over Temperature !!\n\r");
2342 status
= PMU_STATUS_FAIL
;
2352 static PMU_STATUS
mt_battery_CheckChargerVoltage(void)
2354 PMU_STATUS status
= PMU_STATUS_OK
;
2355 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2356 kal_uint32 v_charger_max
= DISO_data
.hv_voltage
;
2359 if (BMT_status
.charger_exist
== KAL_TRUE
) {
2360 #if (V_CHARGER_ENABLE == 1)
2361 if (BMT_status
.charger_vol
<= V_CHARGER_MIN
) {
2362 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY]Charger under voltage!!\r\n");
2363 BMT_status
.bat_charging_state
= CHR_ERROR
;
2364 status
= PMU_STATUS_FAIL
;
2367 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2368 if (BMT_status
.charger_vol
>= V_CHARGER_MAX
) {
2370 if (BMT_status
.charger_vol
>= v_charger_max
) {
2372 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY]Charger over voltage !!\r\n");
2373 BMT_status
.charger_protect_status
= charger_OVER_VOL
;
2374 BMT_status
.bat_charging_state
= CHR_ERROR
;
2375 status
= PMU_STATUS_FAIL
;
2383 static PMU_STATUS
mt_battery_CheckChargingTime(void)
2385 PMU_STATUS status
= PMU_STATUS_OK
;
2387 if ((g_battery_thermal_throttling_flag
== 2) || (g_battery_thermal_throttling_flag
== 3)) {
2388 battery_xlog_printk(BAT_LOG_FULL
,
2389 "[TestMode] Disable Safty Timer. bat_tt_enable=%d, bat_thr_test_mode=%d, bat_thr_test_value=%d\n",
2390 g_battery_thermal_throttling_flag
,
2391 battery_cmd_thermal_test_mode
,
2392 battery_cmd_thermal_test_mode_value
);
2396 if (BMT_status
.total_charging_time
>= MAX_CHARGING_TIME
) {
2397 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] Charging Over Time.\n");
2399 status
= PMU_STATUS_FAIL
;
2407 #if defined(STOP_CHARGING_IN_TAKLING)
2408 static PMU_STATUS
mt_battery_CheckCallState(void)
2410 PMU_STATUS status
= PMU_STATUS_OK
;
2412 if ((g_call_state
== CALL_ACTIVE
) && (BMT_status
.bat_vol
> V_CC2TOPOFF_THRES
))
2413 status
= PMU_STATUS_FAIL
;
2419 static void mt_battery_CheckBatteryStatus(void)
2421 battery_xlog_printk(BAT_LOG_FULL
, "[mt_battery_CheckBatteryStatus] cmd_discharging=(%d)\n",
2423 if (cmd_discharging
== 1) {
2424 battery_xlog_printk(BAT_LOG_CRTI
,
2425 "[mt_battery_CheckBatteryStatus] cmd_discharging=(%d)\n",
2427 BMT_status
.bat_charging_state
= CHR_ERROR
;
2428 battery_charging_control(CHARGING_CMD_SET_ERROR_STATE
, &cmd_discharging
);
2430 } else if (cmd_discharging
== 0) {
2431 BMT_status
.bat_charging_state
= CHR_PRE
;
2432 battery_charging_control(CHARGING_CMD_SET_ERROR_STATE
, &cmd_discharging
);
2433 cmd_discharging
= -1;
2435 if (mt_battery_CheckBatteryTemp() != PMU_STATUS_OK
) {
2436 BMT_status
.bat_charging_state
= CHR_ERROR
;
2440 if (mt_battery_CheckChargerVoltage() != PMU_STATUS_OK
) {
2441 BMT_status
.bat_charging_state
= CHR_ERROR
;
2444 #if defined(STOP_CHARGING_IN_TAKLING)
2445 if (mt_battery_CheckCallState() != PMU_STATUS_OK
) {
2446 BMT_status
.bat_charging_state
= CHR_HOLD
;
2451 if (mt_battery_CheckChargingTime() != PMU_STATUS_OK
) {
2452 BMT_status
.bat_charging_state
= CHR_ERROR
;
2458 static void mt_battery_notify_TotalChargingTime_check(void)
2460 #if defined(BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME)
2461 if ((g_battery_thermal_throttling_flag
== 2) || (g_battery_thermal_throttling_flag
== 3)) {
2462 battery_xlog_printk(BAT_LOG_FULL
,
2463 "[TestMode] Disable Safty Timer : no UI display\n");
2465 if (BMT_status
.total_charging_time
>= MAX_CHARGING_TIME
)
2466 /* if(BMT_status.total_charging_time >= 60) //test */
2468 g_BatteryNotifyCode
|= 0x0010;
2469 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] Charging Over Time\n");
2471 g_BatteryNotifyCode
&= ~(0x0010);
2475 battery_xlog_printk(BAT_LOG_CRTI
,
2476 "[BATTERY] BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME (%x)\n",
2477 g_BatteryNotifyCode
);
2482 static void mt_battery_notify_VBat_check(void)
2484 #if defined(BATTERY_NOTIFY_CASE_0004_VBAT)
2485 if (BMT_status
.bat_vol
> 4350)
2486 /* if(BMT_status.bat_vol > 3800) //test */
2488 g_BatteryNotifyCode
|= 0x0008;
2489 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] bat_vlot(%ld) > 4350mV\n",
2490 BMT_status
.bat_vol
);
2492 g_BatteryNotifyCode
&= ~(0x0008);
2495 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] BATTERY_NOTIFY_CASE_0004_VBAT (%x)\n",
2496 g_BatteryNotifyCode
);
2502 static void mt_battery_notify_ICharging_check(void)
2504 #if defined(BATTERY_NOTIFY_CASE_0003_ICHARGING)
2505 if ((BMT_status
.ICharging
> 1000) && (BMT_status
.total_charging_time
> 300)) {
2506 g_BatteryNotifyCode
|= 0x0004;
2507 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] I_charging(%ld) > 1000mA\n",
2508 BMT_status
.ICharging
);
2510 g_BatteryNotifyCode
&= ~(0x0004);
2513 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] BATTERY_NOTIFY_CASE_0003_ICHARGING (%x)\n",
2514 g_BatteryNotifyCode
);
2520 static void mt_battery_notify_VBatTemp_check(void)
2522 #if defined(BATTERY_NOTIFY_CASE_0002_VBATTEMP)
2524 if (BMT_status
.temperature
>= MAX_CHARGE_TEMPERATURE
) {
2525 /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015, BATTERY Notify PR-1018754*/
2526 if(BMT_status
.temperature
>= MAX_RAISING_CHARGE_TEMPERATURE
)
2527 g_BatteryNotifyCode
|= (0x0040 | (!!BMT_status
.charger_exist
) << 8);
2529 g_BatteryNotifyCode
|= (0x0002 | (!!BMT_status
.charger_exist
) << 8);
2530 /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/
2531 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] bat_temp(%d) out of range(too high)\n",
2532 BMT_status
.temperature
);
2534 #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
2535 else if (BMT_status
.temperature
< TEMP_NEG_10_THRESHOLD
) {
2536 /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015, BATTERY Notify PR-1018754*/
2537 if(BMT_status
.temperature
<= MIN_DROPPING_CHARGE_TEMPERATURE
)
2538 g_BatteryNotifyCode
|= (0x0080 | (!!BMT_status
.charger_exist
) << 8);
2540 g_BatteryNotifyCode
|= (0x0020 | (!!BMT_status
.charger_exist
) << 8);
2541 /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/
2542 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] bat_temp(%d) out of range(too low)\n",
2543 BMT_status
.temperature
);
2546 #ifdef BAT_LOW_TEMP_PROTECT_ENABLE
2547 else if (BMT_status
.temperature
< MIN_CHARGE_TEMPERATURE
) {
2548 /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015, BATTERY Notify PR-1018754*/
2549 if(BMT_status
.temperature
<= MIN_DROPPING_CHARGE_TEMPERATURE
)
2550 g_BatteryNotifyCode
|= (0x0080 | (!!BMT_status
.charger_exist
) << 8);
2552 g_BatteryNotifyCode
|= (0x0020 | (!!BMT_status
.charger_exist
) << 8);
2553 /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/
2554 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] bat_temp(%d) out of range(too low)\n",
2555 BMT_status
.temperature
);
2560 battery_xlog_printk(BAT_LOG_FULL
, "[BATTERY] BATTERY_NOTIFY_CASE_0002_VBATTEMP (%x)\n",
2561 g_BatteryNotifyCode
);
2567 static void mt_battery_notify_VCharger_check(void)
2569 #if defined(BATTERY_NOTIFY_CASE_0001_VCHARGER)
2570 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2571 kal_uint32 v_charger_max
= DISO_data
.hv_voltage
;
2574 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2575 if (BMT_status
.charger_vol
> V_CHARGER_MAX
) {
2577 if (BMT_status
.charger_vol
> v_charger_max
) {
2579 g_BatteryNotifyCode
|= 0x0001;
2580 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] BMT_status.charger_vol(%d) > %d mV\n",
2581 BMT_status
.charger_vol
, V_CHARGER_MAX
);
2583 g_BatteryNotifyCode
&= ~(0x0001);
2585 if (g_BatteryNotifyCode
!= 0x0000)
2586 battery_xlog_printk(BAT_LOG_CRTI
,
2587 "[BATTERY] BATTERY_NOTIFY_CASE_0001_VCHARGER (%x)\n",
2588 g_BatteryNotifyCode
);
2593 static void mt_battery_notify_UI_test(void)
2595 if (g_BN_TestMode
== 0x0001) {
2596 g_BatteryNotifyCode
= 0x0001;
2597 battery_xlog_printk(BAT_LOG_CRTI
,
2598 "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0001_VCHARGER\n");
2599 } else if (g_BN_TestMode
== 0x0002) {
2600 g_BatteryNotifyCode
= 0x0002;
2601 battery_xlog_printk(BAT_LOG_CRTI
,
2602 "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0002_VBATTEMP\n");
2603 } else if (g_BN_TestMode
== 0x0003) {
2604 g_BatteryNotifyCode
= 0x0004;
2605 battery_xlog_printk(BAT_LOG_CRTI
,
2606 "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0003_ICHARGING\n");
2607 } else if (g_BN_TestMode
== 0x0004) {
2608 g_BatteryNotifyCode
= 0x0008;
2609 battery_xlog_printk(BAT_LOG_CRTI
,
2610 "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0004_VBAT\n");
2611 } else if (g_BN_TestMode
== 0x0005) {
2612 g_BatteryNotifyCode
= 0x0010;
2613 battery_xlog_printk(BAT_LOG_CRTI
,
2614 "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME\n");
2616 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] Unknown BN_TestMode Code : %x\n",
2622 void mt_battery_notify_check(void)
2624 g_BatteryNotifyCode
= 0x0000;
2626 if (g_BN_TestMode
== 0x0000) { /* for normal case */
2627 battery_xlog_printk(BAT_LOG_FULL
, "[BATTERY] mt_battery_notify_check\n");
2629 mt_battery_notify_VCharger_check();
2631 mt_battery_notify_VBatTemp_check();
2633 mt_battery_notify_ICharging_check();
2635 mt_battery_notify_VBat_check();
2637 mt_battery_notify_TotalChargingTime_check();
2638 } else { /* for UI test */
2640 mt_battery_notify_UI_test();
2644 static void mt_battery_thermal_check(void)
2646 if ((g_battery_thermal_throttling_flag
== 1) || (g_battery_thermal_throttling_flag
== 3)) {
2647 if (battery_cmd_thermal_test_mode
== 1) {
2648 BMT_status
.temperature
= battery_cmd_thermal_test_mode_value
;
2649 battery_xlog_printk(BAT_LOG_FULL
,
2650 "[Battery] In thermal_test_mode , Tbat=%d\n",
2651 BMT_status
.temperature
);
2653 #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
2654 /* ignore default rule */
2656 if (BMT_status
.temperature
>= 60 || BMT_status
.temperature
<=-20) {
2657 #if defined(CONFIG_POWER_EXT)
2658 battery_xlog_printk(BAT_LOG_CRTI
,
2659 "[BATTERY] CONFIG_POWER_EXT, no update battery update power down.\n");
2662 if ((g_platform_boot_mode
== META_BOOT
)
2663 || (g_platform_boot_mode
== ADVMETA_BOOT
)
2664 || (g_platform_boot_mode
== ATE_FACTORY_BOOT
)) {
2665 battery_xlog_printk(BAT_LOG_FULL
,
2666 "[BATTERY] boot mode = %d, bypass temperature check\n",
2667 g_platform_boot_mode
);
2669 struct battery_data
*bat_data
= &battery_main
;
2670 struct power_supply
*bat_psy
= &bat_data
->psy
;
2672 battery_xlog_printk(BAT_LOG_CRTI
,
2673 "[Battery] Tbat(%d)>=60 or <=-20 , system need power down.\n",
2674 BMT_status
.temperature
);
2676 bat_data
->BAT_CAPACITY
= 0;
2678 power_supply_changed(bat_psy
);
2680 if (BMT_status
.charger_exist
== KAL_TRUE
) {
2681 /* can not power down due to charger exist, so need reset system */
2682 battery_charging_control
2683 (CHARGING_CMD_SET_PLATFORM_RESET
, NULL
);
2685 /* avoid SW no feedback */
2686 battery_charging_control(CHARGING_CMD_SET_POWER_OFF
, NULL
);
2687 /* mt_power_off(); */
2699 static void mt_battery_update_status(void)
2701 #if defined(CONFIG_POWER_EXT)
2702 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] CONFIG_POWER_EXT, no update Android.\n");
2705 wireless_update(&wireless_main
);
2706 battery_update(&battery_main
);
2707 ac_update(&ac_main
);
2708 usb_update(&usb_main
);
2715 CHARGER_TYPE
mt_charger_type_detection(void)
2717 CHARGER_TYPE CHR_Type_num
= CHARGER_UNKNOWN
;
2719 mutex_lock(&charger_type_mutex
);
2721 #if defined(CONFIG_MTK_WIRELESS_CHARGER_SUPPORT)
2722 battery_charging_control(CHARGING_CMD_GET_CHARGER_TYPE
, &CHR_Type_num
);
2723 BMT_status
.charger_type
= CHR_Type_num
;
2725 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2726 if (BMT_status
.charger_type
== CHARGER_UNKNOWN
) {
2728 if ((BMT_status
.charger_type
== CHARGER_UNKNOWN
) &&
2729 (DISO_data
.diso_state
.cur_vusb_state
== DISO_ONLINE
)) {
2731 battery_charging_control(CHARGING_CMD_GET_CHARGER_TYPE
, &CHR_Type_num
);
2732 BMT_status
.charger_type
= CHR_Type_num
;
2734 #if defined(CONFIG_MTK_KERNEL_POWER_OFF_CHARGING)&&(defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) || defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT))
2735 if (BMT_status
.UI_SOC
== 100)
2737 BMT_status
.bat_charging_state
= CHR_BATFULL
;
2738 BMT_status
.bat_full
= KAL_TRUE
;
2739 g_charging_full_reset_bat_meter
= KAL_TRUE
;
2742 if(g_battery_soc_ready
== KAL_FALSE
) {
2743 if(BMT_status
.nPercent_ZCV
== 0)
2744 battery_meter_initial();
2746 BMT_status
.SOC
= battery_meter_get_battery_percentage();
2749 if (BMT_status
.bat_vol
> 0)
2751 mt_battery_update_status();
2757 mutex_unlock(&charger_type_mutex
);
2759 return BMT_status
.charger_type
;
2762 CHARGER_TYPE
mt_get_charger_type(void)
2764 #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
2765 return STANDARD_HOST
;
2767 return BMT_status
.charger_type
;
2771 static void mt_battery_charger_detect_check(void)
2773 if (upmu_is_chr_det() == KAL_TRUE
) {
2774 wake_lock(&battery_suspend_lock
);
2776 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2777 BMT_status
.charger_exist
= KAL_TRUE
;
2780 #if defined(CONFIG_MTK_WIRELESS_CHARGER_SUPPORT)
2781 mt_charger_type_detection();
2783 if ((BMT_status
.charger_type
== STANDARD_HOST
)
2784 || (BMT_status
.charger_type
== CHARGING_HOST
)) {
2788 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2789 if (BMT_status
.charger_type
== CHARGER_UNKNOWN
) {
2791 if ((BMT_status
.charger_type
== CHARGER_UNKNOWN
) &&
2792 (DISO_data
.diso_state
.cur_vusb_state
== DISO_ONLINE
)) {
2794 mt_charger_type_detection();
2796 if ((BMT_status
.charger_type
== STANDARD_HOST
)
2797 || (BMT_status
.charger_type
== CHARGING_HOST
)) {
2803 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_thread]Cable in, CHR_Type_num=%d\r\n",
2804 BMT_status
.charger_type
);
2807 wake_unlock(&battery_suspend_lock
);
2809 BMT_status
.charger_exist
= KAL_FALSE
;
2810 BMT_status
.charger_type
= CHARGER_UNKNOWN
;
2811 BMT_status
.bat_full
= KAL_FALSE
;
2812 BMT_status
.bat_in_recharging_state
= KAL_FALSE
;
2813 BMT_status
.bat_charging_state
= CHR_PRE
;
2814 BMT_status
.total_charging_time
= 0;
2815 BMT_status
.PRE_charging_time
= 0;
2816 BMT_status
.CC_charging_time
= 0;
2817 BMT_status
.TOPOFF_charging_time
= 0;
2818 BMT_status
.POSTFULL_charging_time
= 0;
2820 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_thread]Cable out \r\n");
2822 mt_usb_disconnect();
2826 static void mt_kpoc_power_off_check(void)
2828 #ifdef CONFIG_MTK_KERNEL_POWER_OFF_CHARGING
2829 battery_xlog_printk(BAT_LOG_CRTI
,
2830 "[mt_kpoc_power_off_check] , chr_vol=%d, boot_mode=%d\r\n", BMT_status
.charger_vol
,
2831 g_platform_boot_mode
);
2832 if (g_platform_boot_mode
== KERNEL_POWER_OFF_CHARGING_BOOT
2833 || g_platform_boot_mode
== LOW_POWER_OFF_CHARGING_BOOT
) {
2834 if ((upmu_is_chr_det() == KAL_FALSE
) && (BMT_status
.charger_vol
< 2500)) /* vbus < 2.5V */
2836 battery_xlog_printk(BAT_LOG_CRTI
,
2837 "[bat_thread_kthread] Unplug Charger/USB In Kernel Power Off Charging Mode! Shutdown OS!\r\n");
2838 battery_charging_control(CHARGING_CMD_SET_POWER_OFF
, NULL
);
2844 void update_battery_2nd_info(int status_smb
, int capacity_smb
, int present_smb
)
2846 #if defined(CONFIG_POWER_VERIFY)
2847 battery_xlog_printk(BAT_LOG_CRTI
, "[update_battery_smb_info] no support\n");
2849 g_status_smb
= status_smb
;
2850 g_capacity_smb
= capacity_smb
;
2851 g_present_smb
= present_smb
;
2852 battery_xlog_printk(BAT_LOG_CRTI
,
2853 "[update_battery_smb_info] get status_smb=%d,capacity_smb=%d,present_smb=%d\n",
2854 status_smb
, capacity_smb
, present_smb
);
2857 g_smartbook_update
= 1;
2861 void do_chrdet_int_task(void)
2863 if (g_bat_init_flag
== KAL_TRUE
) {
2864 #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2865 if (upmu_is_chr_det() == KAL_TRUE
) {
2867 battery_charging_control(CHARGING_CMD_GET_DISO_STATE
, &DISO_data
);
2868 if ((DISO_data
.diso_state
.cur_vusb_state
== DISO_ONLINE
) ||
2869 (DISO_data
.diso_state
.cur_vdc_state
== DISO_ONLINE
)) {
2871 battery_xlog_printk(BAT_LOG_CRTI
, "[do_chrdet_int_task] charger exist!\n");
2872 BMT_status
.charger_exist
= KAL_TRUE
;
2874 wake_lock(&battery_suspend_lock
);
2876 #if defined(CONFIG_POWER_EXT)
2878 battery_xlog_printk(BAT_LOG_CRTI
,
2879 "[do_chrdet_int_task] call mt_usb_connect() in EVB\n");
2880 #elif defined(CONFIG_MTK_POWER_EXT_DETECT)
2881 if (KAL_TRUE
== bat_is_ext_power()) {
2883 battery_xlog_printk(BAT_LOG_CRTI
,
2884 "[do_chrdet_int_task] call mt_usb_connect() in EVB\n");
2889 battery_xlog_printk(BAT_LOG_CRTI
,
2890 "[do_chrdet_int_task] charger NOT exist!\n");
2891 BMT_status
.charger_exist
= KAL_FALSE
;
2893 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2894 battery_xlog_printk(BAT_LOG_CRTI
,
2895 "turn off charging for no avaliable charging source\n");
2896 battery_charging_control(CHARGING_CMD_ENABLE
,&BMT_status
.charger_exist
);
2899 #ifdef CONFIG_MTK_KERNEL_POWER_OFF_CHARGING
2900 if (g_platform_boot_mode
== KERNEL_POWER_OFF_CHARGING_BOOT
2901 || g_platform_boot_mode
== LOW_POWER_OFF_CHARGING_BOOT
) {
2902 battery_xlog_printk(BAT_LOG_CRTI
,
2903 "[pmic_thread_kthread] Unplug Charger/USB In Kernel Power Off Charging Mode! Shutdown OS!\r\n");
2904 battery_charging_control(CHARGING_CMD_SET_POWER_OFF
, NULL
);
2905 /* mt_power_off(); */
2909 wake_unlock(&battery_suspend_lock
);
2911 #if defined(CONFIG_POWER_EXT)
2912 mt_usb_disconnect();
2913 battery_xlog_printk(BAT_LOG_CRTI
,
2914 "[do_chrdet_int_task] call mt_usb_disconnect() in EVB\n");
2915 #elif defined(CONFIG_MTK_POWER_EXT_DETECT)
2916 if (KAL_TRUE
== bat_is_ext_power()) {
2917 mt_usb_disconnect();
2918 battery_xlog_printk(BAT_LOG_CRTI
,
2919 "[do_chrdet_int_task] call mt_usb_disconnect() in EVB\n");
2923 #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) || defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
2924 is_ta_connect
= KAL_FALSE
;
2925 ta_check_chr_type
= KAL_TRUE
;
2926 ta_cable_out_occur
= KAL_TRUE
;
2931 /* Place charger detection and battery update here is used to speed up charging icon display. */
2933 mt_battery_charger_detect_check();
2934 if (BMT_status
.UI_SOC
== 100 && BMT_status
.charger_exist
== KAL_TRUE
) {
2935 BMT_status
.bat_charging_state
= CHR_BATFULL
;
2936 BMT_status
.bat_full
= KAL_TRUE
;
2937 g_charging_full_reset_bat_meter
= KAL_TRUE
;
2940 if (g_battery_soc_ready
== KAL_FALSE
) {
2941 if (BMT_status
.nPercent_ZCV
== 0)
2942 battery_meter_initial();
2944 BMT_status
.SOC
= battery_meter_get_battery_percentage();
2947 if (BMT_status
.bat_vol
> 0) {
2948 mt_battery_update_status();
2951 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2952 DISO_data
.chr_get_diso_state
= KAL_TRUE
;
2957 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
2958 g_vcdt_irq_delay_flag
= KAL_TRUE
;
2960 battery_xlog_printk(BAT_LOG_CRTI
,
2961 "[do_chrdet_int_task] battery thread not ready, will do after bettery init.\n");
2967 void BAT_thread(void)
2969 static kal_bool battery_meter_initilized
= KAL_FALSE
;
2970 if (battery_meter_initilized
== KAL_FALSE
) {
2971 battery_meter_initial(); /* move from battery_probe() to decrease booting time */
2972 BMT_status
.nPercent_ZCV
= battery_meter_get_battery_nPercent_zcv();
2973 battery_meter_initilized
= KAL_TRUE
;
2975 /*[BUGFIX]-Add-BEGIN by TCTSZ.pingao.yang, 4/15/2015, pr-975290, add standby current */
2976 pre_timer_counter
= rtc_read_hw_time();
2977 /*[BUGFIX]-Add-END by TCTSZ.pingao.yang */
2981 mt_battery_charger_detect_check();
2982 mt_battery_GetBatteryData();
2983 if (BMT_status
.charger_exist
== KAL_TRUE
) {
2984 check_battery_exist();
2986 mt_battery_thermal_check();
2987 mt_battery_notify_check();
2989 if (BMT_status
.charger_exist
== KAL_TRUE
) {
2990 mt_battery_CheckBatteryStatus();
2991 mt_battery_charging_algorithm();
2994 mt_battery_update_status();
2995 mt_kpoc_power_off_check();
2998 /* ///////////////////////////////////////////////////////////////////////////////////////// */
2999 /* // Internal API */
3000 /* ///////////////////////////////////////////////////////////////////////////////////////// */
3002 #ifdef BATTERY_CDP_WORKAROUND
3003 extern kal_bool
is_charger_detection_rdy(void);
3006 int bat_thread_kthread(void *x
)
3008 ktime_t ktime
= ktime_set(3, 0); /* 10s, 10* 1000 ms */
3011 #ifdef BATTERY_CDP_WORKAROUND
3012 if(is_charger_detection_rdy()==KAL_FALSE
){
3013 printk("xiaohu_cdp:CDP, block\n");
3014 wait_event(bat_thread_wq
, (is_charger_detection_rdy()==KAL_TRUE
));
3015 printk("xiaohu_cdp:CDP, free\n");
3017 printk("xiaohu_cdp:CDP, PASS\n");
3022 /* Run on a process content */
3024 mutex_lock(&bat_mutex
);
3026 if ((chargin_hw_init_done
== KAL_TRUE
) && (battery_suspended
== KAL_FALSE
))
3029 mutex_unlock(&bat_mutex
);
3031 battery_xlog_printk(BAT_LOG_FULL
, "wait event \n" );
3033 wait_event(bat_thread_wq
, (bat_thread_timeout
== KAL_TRUE
));
3035 bat_thread_timeout
= KAL_FALSE
;
3036 hrtimer_start(&battery_kthread_timer
, ktime
, HRTIMER_MODE_REL
);
3037 ktime
= ktime_set(BAT_TASK_PERIOD
, 0); /* 10s, 10* 1000 ms */
3038 if (chr_wake_up_bat
== KAL_TRUE
&& g_smartbook_update
!= 1) /* for charger plug in/ out */
3040 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
3041 if (DISO_data
.chr_get_diso_state
) {
3042 DISO_data
.chr_get_diso_state
= KAL_FALSE
;
3043 battery_charging_control(CHARGING_CMD_GET_DISO_STATE
, &DISO_data
);
3047 g_smartbook_update
= 0;
3048 #if defined(CUST_CAPACITY_OCV2CV_TRANSFORM)
3049 battery_meter_set_reset_soc(KAL_FALSE
);
3051 battery_meter_reset();
3052 chr_wake_up_bat
= KAL_FALSE
;
3054 battery_xlog_printk(BAT_LOG_CRTI
,
3055 "[BATTERY] Charger plug in/out, Call battery_meter_reset. (%d)\n",
3064 void bat_thread_wakeup(void)
3066 battery_xlog_printk(BAT_LOG_FULL
, "******** battery : bat_thread_wakeup ********\n");
3068 bat_thread_timeout
= KAL_TRUE
;
3069 bat_meter_timeout
= KAL_TRUE
;
3070 #ifdef MTK_ENABLE_AGING_ALGORITHM
3073 _g_bat_sleep_total_time
= 0;
3074 wake_up(&bat_thread_wq
);
3077 /* ///////////////////////////////////////////////////////////////////////////////////////// */
3079 /* ///////////////////////////////////////////////////////////////////////////////////////// */
3080 static long adc_cali_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
3082 int *user_data_addr
;
3083 int *naram_data_addr
;
3086 int adc_in_data
[2] = { 1, 1 };
3087 int adc_out_data
[2] = { 1, 1 };
3089 mutex_lock(&bat_mutex
);
3092 case TEST_ADC_CALI_PRINT
:
3093 g_ADC_Cali
= KAL_FALSE
;
3096 case SET_ADC_CALI_Slop
:
3097 naram_data_addr
= (int *)arg
;
3098 ret
= copy_from_user(adc_cali_slop
, naram_data_addr
, 36);
3099 g_ADC_Cali
= KAL_FALSE
; /* enable calibration after setting ADC_CALI_Cal */
3101 for (i
= 0; i
< 14; i
++) {
3102 if ((*(adc_cali_slop
+ i
) == 0) || (*(adc_cali_slop
+ i
) == 1)) {
3103 *(adc_cali_slop
+ i
) = 1000;
3106 for (i
= 0; i
< 14; i
++)
3107 battery_xlog_printk(BAT_LOG_CRTI
, "adc_cali_slop[%d] = %d\n", i
,
3108 *(adc_cali_slop
+ i
));
3109 battery_xlog_printk(BAT_LOG_FULL
,
3110 "**** unlocked_ioctl : SET_ADC_CALI_Slop Done!\n");
3113 case SET_ADC_CALI_Offset
:
3114 naram_data_addr
= (int *)arg
;
3115 ret
= copy_from_user(adc_cali_offset
, naram_data_addr
, 36);
3116 g_ADC_Cali
= KAL_FALSE
; /* enable calibration after setting ADC_CALI_Cal */
3117 for (i
= 0; i
< 14; i
++)
3118 battery_xlog_printk(BAT_LOG_CRTI
, "adc_cali_offset[%d] = %d\n", i
,
3119 *(adc_cali_offset
+ i
));
3120 battery_xlog_printk(BAT_LOG_FULL
,
3121 "**** unlocked_ioctl : SET_ADC_CALI_Offset Done!\n");
3124 case SET_ADC_CALI_Cal
:
3125 naram_data_addr
= (int *)arg
;
3126 ret
= copy_from_user(adc_cali_cal
, naram_data_addr
, 4);
3127 g_ADC_Cali
= KAL_TRUE
;
3128 if (adc_cali_cal
[0] == 1) {
3129 g_ADC_Cali
= KAL_TRUE
;
3131 g_ADC_Cali
= KAL_FALSE
;
3133 for (i
= 0; i
< 1; i
++)
3134 battery_xlog_printk(BAT_LOG_CRTI
, "adc_cali_cal[%d] = %d\n", i
,
3135 *(adc_cali_cal
+ i
));
3136 battery_xlog_printk(BAT_LOG_FULL
, "**** unlocked_ioctl : SET_ADC_CALI_Cal Done!\n");
3139 case ADC_CHANNEL_READ
:
3140 /* g_ADC_Cali = KAL_FALSE; */ /* 20100508 Infinity */
3141 user_data_addr
= (int *)arg
;
3142 ret
= copy_from_user(adc_in_data
, user_data_addr
, 8); /* 2*int = 2*4 */
3144 if (adc_in_data
[0] == 0) /* I_SENSE */
3146 adc_out_data
[0] = battery_meter_get_VSense() * adc_in_data
[1];
3147 } else if (adc_in_data
[0] == 1) /* BAT_SENSE */
3149 adc_out_data
[0] = battery_meter_get_battery_voltage(KAL_TRUE
) * adc_in_data
[1];
3150 } else if (adc_in_data
[0] == 3) /* V_Charger */
3152 adc_out_data
[0] = battery_meter_get_charger_voltage() * adc_in_data
[1];
3153 /* adc_out_data[0] = adc_out_data[0] / 100; */
3154 } else if (adc_in_data
[0] == 30) /* V_Bat_temp magic number */
3156 adc_out_data
[0] = battery_meter_get_battery_temperature() * adc_in_data
[1];
3157 } else if (adc_in_data
[0] == 66) {
3158 adc_out_data
[0] = (battery_meter_get_battery_current()) / 10;
3160 if (battery_meter_get_battery_current_sign() == KAL_TRUE
) {
3161 adc_out_data
[0] = 0 - adc_out_data
[0]; /* charging */
3164 battery_xlog_printk(BAT_LOG_FULL
, "unknown channel(%d,%d)\n",
3165 adc_in_data
[0], adc_in_data
[1]);
3168 if (adc_out_data
[0] < 0)
3169 adc_out_data
[1] = 1; /* failed */
3171 adc_out_data
[1] = 0; /* success */
3173 if (adc_in_data
[0] == 30)
3174 adc_out_data
[1] = 0; /* success */
3176 if (adc_in_data
[0] == 66)
3177 adc_out_data
[1] = 0; /* success */
3179 ret
= copy_to_user(user_data_addr
, adc_out_data
, 8);
3180 battery_xlog_printk(BAT_LOG_CRTI
,
3181 "**** unlocked_ioctl : Channel %d * %d times = %d\n",
3182 adc_in_data
[0], adc_in_data
[1], adc_out_data
[0]);
3185 case BAT_STATUS_READ
:
3186 user_data_addr
= (int *)arg
;
3187 ret
= copy_from_user(battery_in_data
, user_data_addr
, 4);
3190 battery_out_data
[0] = 1;
3192 battery_out_data
[0] = 0;
3194 ret
= copy_to_user(user_data_addr
, battery_out_data
, 4);
3195 battery_xlog_printk(BAT_LOG_CRTI
, "**** unlocked_ioctl : CAL:%d\n",
3196 battery_out_data
[0]);
3199 case Set_Charger_Current
: /* For Factory Mode */
3200 user_data_addr
= (int *)arg
;
3201 ret
= copy_from_user(charging_level_data
, user_data_addr
, 4);
3202 g_ftm_battery_flag
= KAL_TRUE
;
3203 if (charging_level_data
[0] == 0) {
3204 charging_level_data
[0] = CHARGE_CURRENT_70_00_MA
;
3205 } else if (charging_level_data
[0] == 1) {
3206 charging_level_data
[0] = CHARGE_CURRENT_200_00_MA
;
3207 } else if (charging_level_data
[0] == 2) {
3208 charging_level_data
[0] = CHARGE_CURRENT_400_00_MA
;
3209 } else if (charging_level_data
[0] == 3) {
3210 charging_level_data
[0] = CHARGE_CURRENT_450_00_MA
;
3211 } else if (charging_level_data
[0] == 4) {
3212 charging_level_data
[0] = CHARGE_CURRENT_550_00_MA
;
3213 } else if (charging_level_data
[0] == 5) {
3214 charging_level_data
[0] = CHARGE_CURRENT_650_00_MA
;
3215 } else if (charging_level_data
[0] == 6) {
3216 charging_level_data
[0] = CHARGE_CURRENT_700_00_MA
;
3217 } else if (charging_level_data
[0] == 7) {
3218 charging_level_data
[0] = CHARGE_CURRENT_800_00_MA
;
3219 } else if (charging_level_data
[0] == 8) {
3220 charging_level_data
[0] = CHARGE_CURRENT_900_00_MA
;
3221 } else if (charging_level_data
[0] == 9) {
3222 charging_level_data
[0] = CHARGE_CURRENT_1000_00_MA
;
3223 } else if (charging_level_data
[0] == 10) {
3224 charging_level_data
[0] = CHARGE_CURRENT_1100_00_MA
;
3225 } else if (charging_level_data
[0] == 11) {
3226 charging_level_data
[0] = CHARGE_CURRENT_1200_00_MA
;
3227 } else if (charging_level_data
[0] == 12) {
3228 charging_level_data
[0] = CHARGE_CURRENT_1300_00_MA
;
3229 } else if (charging_level_data
[0] == 13) {
3230 charging_level_data
[0] = CHARGE_CURRENT_1400_00_MA
;
3231 } else if (charging_level_data
[0] == 14) {
3232 charging_level_data
[0] = CHARGE_CURRENT_1500_00_MA
;
3233 } else if (charging_level_data
[0] == 15) {
3234 charging_level_data
[0] = CHARGE_CURRENT_1600_00_MA
;
3236 charging_level_data
[0] = CHARGE_CURRENT_450_00_MA
;
3239 battery_xlog_printk(BAT_LOG_CRTI
, "**** unlocked_ioctl : set_Charger_Current:%d\n",
3240 charging_level_data
[0]);
3242 /* add for meta tool------------------------------- */
3243 case Get_META_BAT_VOL
:
3244 user_data_addr
= (int *)arg
;
3245 ret
= copy_from_user(adc_in_data
, user_data_addr
, 8);
3246 adc_out_data
[0] = BMT_status
.bat_vol
;
3247 ret
= copy_to_user(user_data_addr
, adc_out_data
, 8);
3250 case Get_META_BAT_SOC
:
3251 user_data_addr
= (int *)arg
;
3252 ret
= copy_from_user(adc_in_data
, user_data_addr
, 8);
3253 adc_out_data
[0] = BMT_status
.UI_SOC
;
3254 ret
= copy_to_user(user_data_addr
, adc_out_data
, 8);
3257 /* add bing meta tool------------------------------- */
3260 g_ADC_Cali
= KAL_FALSE
;
3264 mutex_unlock(&bat_mutex
);
3269 static int adc_cali_open(struct inode
*inode
, struct file
*file
)
3274 static int adc_cali_release(struct inode
*inode
, struct file
*file
)
3280 static struct file_operations adc_cali_fops
= {
3281 .owner
= THIS_MODULE
,
3282 .unlocked_ioctl
= adc_cali_ioctl
,
3283 .open
= adc_cali_open
,
3284 .release
= adc_cali_release
,
3288 void check_battery_exist(void)
3290 #if defined(CONFIG_DIS_CHECK_BATTERY)
3291 battery_xlog_printk(BAT_LOG_CRTI
, "[BATTERY] Disable check battery exist.\n");
3293 kal_uint32 baton_count
= 0;
3294 kal_uint32 charging_enable
= KAL_FALSE
;
3295 kal_uint32 battery_status
;
3298 for (i
= 0; i
< 3; i
++) {
3299 battery_charging_control(CHARGING_CMD_GET_BATTERY_STATUS
, &battery_status
);
3300 baton_count
+= battery_status
;
3304 if (baton_count
>= 3) {
3305 if ((g_platform_boot_mode
== META_BOOT
) || (g_platform_boot_mode
== ADVMETA_BOOT
)
3306 || (g_platform_boot_mode
== ATE_FACTORY_BOOT
)) {
3307 battery_xlog_printk(BAT_LOG_FULL
,
3308 "[BATTERY] boot mode = %d, bypass battery check\n",
3309 g_platform_boot_mode
);
3311 battery_xlog_printk(BAT_LOG_CRTI
,
3312 "[BATTERY] Battery is not exist, power off FAN5405 and system (%d)\n",
3315 battery_charging_control(CHARGING_CMD_ENABLE
, &charging_enable
);
3316 battery_charging_control(CHARGING_CMD_SET_POWER_OFF
, NULL
);
3323 int charger_hv_detect_sw_thread_handler(void *unused
)
3326 kal_uint32 charging_enable
;
3327 kal_uint32 hv_voltage
= V_CHARGER_MAX
*1000;
3330 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
3331 hv_voltage
= DISO_data
.hv_voltage
;
3335 ktime
= ktime_set(0, BAT_MS_TO_NS(1000));
3337 if (chargin_hw_init_done
)
3338 battery_charging_control(CHARGING_CMD_SET_HV_THRESHOLD
, &hv_voltage
);
3340 wait_event_interruptible(charger_hv_detect_waiter
,
3341 (charger_hv_detect_flag
== KAL_TRUE
));
3343 if ((upmu_is_chr_det() == KAL_TRUE
)) {
3344 check_battery_exist();
3347 charger_hv_detect_flag
= KAL_FALSE
;
3349 if (chargin_hw_init_done
)
3350 battery_charging_control(CHARGING_CMD_GET_HV_STATUS
, &hv_status
);
3352 if (hv_status
== KAL_TRUE
) {
3353 battery_xlog_printk(BAT_LOG_CRTI
,
3354 "[charger_hv_detect_sw_thread_handler] charger hv\n");
3356 charging_enable
= KAL_FALSE
;
3357 if (chargin_hw_init_done
)
3358 battery_charging_control(CHARGING_CMD_ENABLE
, &charging_enable
);
3360 battery_xlog_printk(BAT_LOG_FULL
,
3361 "[charger_hv_detect_sw_thread_handler] upmu_chr_get_vcdt_hv_det() != 1\n");
3364 if (chargin_hw_init_done
)
3365 battery_charging_control(CHARGING_CMD_RESET_WATCH_DOG_TIMER
, NULL
);
3367 hrtimer_start(&charger_hv_detect_timer
, ktime
, HRTIMER_MODE_REL
);
3369 } while (!kthread_should_stop());
3374 enum hrtimer_restart
charger_hv_detect_sw_workaround(struct hrtimer
*timer
)
3376 charger_hv_detect_flag
= KAL_TRUE
;
3377 wake_up_interruptible(&charger_hv_detect_waiter
);
3379 battery_xlog_printk(BAT_LOG_FULL
, "[charger_hv_detect_sw_workaround]\n");
3381 return HRTIMER_NORESTART
;
3384 void charger_hv_detect_sw_workaround_init(void)
3388 ktime
= ktime_set(0, BAT_MS_TO_NS(2000));
3389 hrtimer_init(&charger_hv_detect_timer
, CLOCK_MONOTONIC
, HRTIMER_MODE_REL
);
3390 charger_hv_detect_timer
.function
= charger_hv_detect_sw_workaround
;
3391 hrtimer_start(&charger_hv_detect_timer
, ktime
, HRTIMER_MODE_REL
);
3393 charger_hv_detect_thread
=
3394 kthread_run(charger_hv_detect_sw_thread_handler
, 0,
3395 "mtk charger_hv_detect_sw_workaround");
3396 if (IS_ERR(charger_hv_detect_thread
)) {
3397 battery_xlog_printk(BAT_LOG_FULL
,
3398 "[%s]: failed to create charger_hv_detect_sw_workaround thread\n",
3401 check_battery_exist();
3402 battery_xlog_printk(BAT_LOG_CRTI
, "charger_hv_detect_sw_workaround_init : done\n");
3406 enum hrtimer_restart
battery_kthread_hrtimer_func(struct hrtimer
*timer
)
3408 bat_thread_wakeup();
3410 return HRTIMER_NORESTART
;
3413 void battery_kthread_hrtimer_init(void)
3417 ktime
= ktime_set(1, 0); /* 3s, 10* 1000 ms */
3418 hrtimer_init(&battery_kthread_timer
, CLOCK_MONOTONIC
, HRTIMER_MODE_REL
);
3419 battery_kthread_timer
.function
= battery_kthread_hrtimer_func
;
3420 hrtimer_start(&battery_kthread_timer
, ktime
, HRTIMER_MODE_REL
);
3422 battery_xlog_printk(BAT_LOG_CRTI
, "battery_kthread_hrtimer_init : done\n");
3426 static void get_charging_control(void)
3428 battery_charging_control
= chr_control_interface
;
3431 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
3432 static irqreturn_t
diso_auxadc_irq_thread(int irq
, void *dev_id
)
3434 int pre_diso_state
= (DISO_data
.diso_state
.pre_otg_state
|
3435 (DISO_data
.diso_state
.pre_vusb_state
<< 1) |
3436 (DISO_data
.diso_state
.pre_vdc_state
<< 2)) & 0x7;
3438 battery_xlog_printk(BAT_LOG_CRTI
,
3439 "[DISO]auxadc IRQ threaded handler triggered, pre_diso_state is %s\n",
3440 DISO_state_s
[pre_diso_state
]);
3442 switch (pre_diso_state
) {
3443 #ifdef MTK_DISCRETE_SWITCH /*for DSC DC plugin handle */
3447 BMT_status
.charger_exist
= KAL_TRUE
;
3448 wake_lock(&battery_suspend_lock
);
3452 BMT_status
.charger_exist
= KAL_FALSE
;
3453 battery_charging_control(CHARGING_CMD_ENABLE
,&BMT_status
.charger_exist
); // need stop charger quickly
3454 BMT_status
.charger_exist
= KAL_FALSE
; //reset charger status
3455 BMT_status
.charger_type
= CHARGER_UNKNOWN
;
3456 wake_unlock(&battery_suspend_lock
);
3460 /*usb delayed work will reflact BMT_staus , so need update state ASAP*/
3461 if((BMT_status
.charger_type
==STANDARD_HOST
) || (BMT_status
.charger_type
==CHARGING_HOST
))
3462 mt_usb_disconnect(); /* disconnect if connected */
3463 BMT_status
.charger_type
= CHARGER_UNKNOWN
;// reset chr_type
3467 BMT_status
.charger_type
= CHARGER_UNKNOWN
;
3468 mt_battery_charger_detect_check(); //plug in VUSB, check if need connect usb
3471 battery_xlog_printk(BAT_LOG_CRTI
,
3472 "[DISO]VUSB auxadc threaded handler triggered ERROR OR TEST\n");
3478 static void dual_input_init(void)
3480 DISO_data
.irq_callback_func
= diso_auxadc_irq_thread
;
3481 battery_charging_control(CHARGING_CMD_DISO_INIT
, &DISO_data
);
3484 static int battery_probe(struct platform_device
*dev
)
3486 struct class_device
*class_dev
= NULL
;
3489 battery_xlog_printk(BAT_LOG_CRTI
, "******** battery driver probe!! ********\n");
3491 /* Integrate with NVRAM */
3492 ret
= alloc_chrdev_region(&adc_cali_devno
, 0, 1, ADC_CALI_DEVNAME
);
3494 battery_xlog_printk(BAT_LOG_CRTI
, "Error: Can't Get Major number for adc_cali\n");
3495 adc_cali_cdev
= cdev_alloc();
3496 adc_cali_cdev
->owner
= THIS_MODULE
;
3497 adc_cali_cdev
->ops
= &adc_cali_fops
;
3498 ret
= cdev_add(adc_cali_cdev
, adc_cali_devno
, 1);
3500 battery_xlog_printk(BAT_LOG_CRTI
, "adc_cali Error: cdev_add\n");
3501 adc_cali_major
= MAJOR(adc_cali_devno
);
3502 adc_cali_class
= class_create(THIS_MODULE
, ADC_CALI_DEVNAME
);
3503 class_dev
= (struct class_device
*)device_create(adc_cali_class
,
3505 adc_cali_devno
, NULL
, ADC_CALI_DEVNAME
);
3506 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_probe] adc_cali prepare : done !!\n ");
3508 get_charging_control();
3510 battery_charging_control(CHARGING_CMD_GET_PLATFORM_BOOT_MODE
, &g_platform_boot_mode
);
3511 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_probe] g_platform_boot_mode = %d\n ",
3512 g_platform_boot_mode
);
3514 wake_lock_init(&battery_suspend_lock
, WAKE_LOCK_SUSPEND
, "battery suspend wakelock");
3515 #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) || defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
3516 wake_lock_init(&TA_charger_suspend_lock
, WAKE_LOCK_SUSPEND
, "TA charger suspend wakelock");
3519 /* Integrate with Android Battery Service */
3520 ret
= power_supply_register(&(dev
->dev
), &ac_main
.psy
);
3522 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_probe] power_supply_register AC Fail !!\n");
3525 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_probe] power_supply_register AC Success !!\n");
3527 ret
= power_supply_register(&(dev
->dev
), &usb_main
.psy
);
3529 battery_xlog_printk(BAT_LOG_CRTI
,
3530 "[BAT_probe] power_supply_register USB Fail !!\n");
3533 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_probe] power_supply_register USB Success !!\n");
3535 ret
= power_supply_register(&(dev
->dev
), &wireless_main
.psy
);
3537 battery_xlog_printk(BAT_LOG_CRTI
,
3538 "[BAT_probe] power_supply_register WIRELESS Fail !!\n");
3541 battery_xlog_printk(BAT_LOG_CRTI
,
3542 "[BAT_probe] power_supply_register WIRELESS Success !!\n");
3544 ret
= power_supply_register(&(dev
->dev
), &battery_main
.psy
);
3546 battery_xlog_printk(BAT_LOG_CRTI
,
3547 "[BAT_probe] power_supply_register Battery Fail !!\n");
3550 battery_xlog_printk(BAT_LOG_CRTI
, "[BAT_probe] power_supply_register Battery Success !!\n");
3552 #if !defined(CONFIG_POWER_EXT)
3554 #ifdef CONFIG_MTK_POWER_EXT_DETECT
3555 if (KAL_TRUE
== bat_is_ext_power()) {
3556 battery_main
.BAT_STATUS
= POWER_SUPPLY_STATUS_FULL
;
3557 battery_main
.BAT_HEALTH
= POWER_SUPPLY_HEALTH_GOOD
;
3558 battery_main
.BAT_PRESENT
= 1;
3559 battery_main
.BAT_TECHNOLOGY
= POWER_SUPPLY_TECHNOLOGY_LION
;
3560 battery_main
.BAT_CAPACITY
= 100;
3561 battery_main
.BAT_batt_vol
= 4200;
3562 battery_main
.BAT_batt_temp
= 220;
3564 g_bat_init_flag
= KAL_TRUE
;
3570 int ret_device_file
= 0;
3572 /* [PLATFORM]-Add-BEGIN by TCTSZ.leo.guo, 04/15/2015, add ntc simulation function */
3573 #if (defined MTK_NTC_DEBUG_SIMULATE)
3574 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ntc_debug
);
3576 /* [PLATFORM]-Add-END by TCTSZ.leo.guo */
3577 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Charger_Voltage
);
3579 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_0_Slope
);
3580 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_1_Slope
);
3581 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_2_Slope
);
3582 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_3_Slope
);
3583 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_4_Slope
);
3584 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_5_Slope
);
3585 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_6_Slope
);
3586 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_7_Slope
);
3587 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_8_Slope
);
3588 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_9_Slope
);
3589 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_10_Slope
);
3590 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_11_Slope
);
3591 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_12_Slope
);
3592 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_13_Slope
);
3594 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_0_Offset
);
3595 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_1_Offset
);
3596 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_2_Offset
);
3597 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_3_Offset
);
3598 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_4_Offset
);
3599 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_5_Offset
);
3600 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_6_Offset
);
3601 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_7_Offset
);
3602 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_8_Offset
);
3603 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_9_Offset
);
3604 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_10_Offset
);
3605 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_11_Offset
);
3606 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_12_Offset
);
3607 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_13_Offset
);
3610 device_create_file(&(dev
->dev
), &dev_attr_ADC_Channel_Is_Calibration
);
3612 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_Power_On_Voltage
);
3613 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_Power_Off_Voltage
);
3614 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_Charger_TopOff_Value
);
3617 device_create_file(&(dev
->dev
), &dev_attr_FG_Battery_CurrentConsumption
);
3618 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_FG_SW_CoulombCounter
);
3619 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_Charging_CallState
);
3620 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_Charger_Type
);
3621 #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) || defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
3622 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_Pump_Express
);
3626 /* battery_meter_initial(); //move to mt_battery_GetBatteryData() to decrease booting time */
3628 /* Initialization BMT Struct */
3629 BMT_status
.bat_exist
= KAL_TRUE
; /* phone must have battery */
3630 BMT_status
.charger_exist
= KAL_FALSE
; /* for default, no charger */
3631 BMT_status
.bat_vol
= 0;
3632 BMT_status
.ICharging
= 0;
3633 BMT_status
.temperature
= 0;
3634 BMT_status
.charger_vol
= 0;
3635 BMT_status
.total_charging_time
= 0;
3636 BMT_status
.PRE_charging_time
= 0;
3637 BMT_status
.CC_charging_time
= 0;
3638 BMT_status
.TOPOFF_charging_time
= 0;
3639 BMT_status
.POSTFULL_charging_time
= 0;
3641 #ifdef CUST_CAPACITY_OCV2CV_TRANSFORM
3642 BMT_status
.UI_SOC
= -1;
3644 BMT_status
.UI_SOC
= 0;
3647 BMT_status
.bat_charging_state
= CHR_PRE
;
3648 BMT_status
.bat_in_recharging_state
= KAL_FALSE
;
3649 BMT_status
.bat_full
= KAL_FALSE
;
3650 BMT_status
.nPercent_ZCV
= 0;
3651 BMT_status
.nPrecent_UI_SOC_check_point
= battery_meter_get_battery_nPercent_UI_SOC();
3653 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
3657 /* battery kernel thread for 10s check and charger in/out event */
3658 /* Replace GPT timer by hrtime */
3659 battery_kthread_hrtimer_init();
3661 kthread_run(bat_thread_kthread
, NULL
, "bat_thread_kthread");
3662 battery_xlog_printk(BAT_LOG_CRTI
, "[battery_probe] bat_thread_kthread Done\n");
3664 charger_hv_detect_sw_workaround_init();
3671 charger_hv_detect_sw_workaround_init();
3673 g_bat_init_flag
= KAL_TRUE
;
3675 #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT)
3676 if (g_vcdt_irq_delay_flag
== KAL_TRUE
)
3677 do_chrdet_int_task();
3684 static void battery_timer_pause(void)
3686 struct timespec xts
, tom
;
3688 //battery_xlog_printk(BAT_LOG_CRTI, "******** battery driver suspend!! ********\n" );
3689 #ifdef CONFIG_POWER_EXT
3692 #ifdef CONFIG_MTK_POWER_EXT_DETECT
3693 if (KAL_TRUE
== bat_is_ext_power())
3696 mutex_lock(&bat_mutex
);
3698 hrtimer_cancel(&battery_kthread_timer
);
3699 hrtimer_cancel(&charger_hv_detect_timer
);
3701 battery_suspended
= KAL_TRUE
;
3702 mutex_unlock(&bat_mutex
);
3704 battery_xlog_printk(BAT_LOG_CRTI
, "@bs=1@\n" );
3707 get_xtime_and_monotonic_and_sleep_offset(&xts
, &tom
, &g_bat_time_before_sleep
);
3710 static void battery_timer_resume(void)
3712 #ifdef CONFIG_POWER_EXT
3714 kal_bool is_pcm_timer_trigger
= KAL_FALSE
;
3715 struct timespec xts
, tom
, bat_time_after_sleep
;
3716 ktime_t ktime
, hvtime
;
3718 #ifdef CONFIG_MTK_POWER_EXT_DETECT
3719 if (KAL_TRUE
== bat_is_ext_power())
3723 ktime
= ktime_set(BAT_TASK_PERIOD
, 0); // 10s, 10* 1000 ms
3724 hvtime
= ktime_set(0, BAT_MS_TO_NS(2000));
3726 get_xtime_and_monotonic_and_sleep_offset(&xts
, &tom
, &bat_time_after_sleep
);
3727 battery_charging_control(CHARGING_CMD_GET_IS_PCM_TIMER_TRIGGER
,&is_pcm_timer_trigger
);
3729 if(is_pcm_timer_trigger
== KAL_TRUE
|| bat_spm_timeout
)
3731 mutex_lock(&bat_mutex
);
3733 mutex_unlock(&bat_mutex
);
3737 battery_xlog_printk(BAT_LOG_CRTI
, "battery resume NOT by pcm timer!!\n" );
3740 if(g_call_state
== CALL_ACTIVE
&& (bat_time_after_sleep
.tv_sec
- g_bat_time_before_sleep
.tv_sec
>= TALKING_SYNC_TIME
)) // phone call last than x min
3742 BMT_status
.UI_SOC
= battery_meter_get_battery_percentage();
3743 battery_xlog_printk(BAT_LOG_CRTI
, "Sync UI SOC to SOC immediately\n" );
3746 mutex_lock(&bat_mutex
);
3749 hrtimer_start(&battery_kthread_timer
, ktime
, HRTIMER_MODE_REL
);
3750 hrtimer_start(&charger_hv_detect_timer
, hvtime
, HRTIMER_MODE_REL
);
3752 battery_suspended
= KAL_FALSE
;
3753 battery_xlog_printk(BAT_LOG_CRTI
, "@bs=0@\n");
3754 mutex_unlock(&bat_mutex
);
3759 static int battery_remove(struct platform_device
*dev
)
3761 battery_xlog_printk(BAT_LOG_CRTI
, "******** battery driver remove!! ********\n");
3766 static void battery_shutdown(struct platform_device
*dev
)
3768 battery_xlog_printk(BAT_LOG_CRTI
, "******** battery driver shutdown!! ********\n");
3772 /* ///////////////////////////////////////////////////////////////////////////////////////// */
3773 /* // Battery Notify API */
3774 /* ///////////////////////////////////////////////////////////////////////////////////////// */
3775 static ssize_t
show_BatteryNotify(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3777 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] show_BatteryNotify : %x\n",
3778 g_BatteryNotifyCode
);
3780 return sprintf(buf
, "%u\n", g_BatteryNotifyCode
);
3783 static ssize_t
store_BatteryNotify(struct device
*dev
, struct device_attribute
*attr
,
3784 const char *buf
, size_t size
)
3786 char *pvalue
= NULL
;
3787 unsigned int reg_BatteryNotifyCode
= 0;
3788 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] store_BatteryNotify\n");
3789 if (buf
!= NULL
&& size
!= 0) {
3790 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] buf is %s and size is %Zu\n", buf
,
3792 reg_BatteryNotifyCode
= simple_strtoul(buf
, &pvalue
, 16);
3793 g_BatteryNotifyCode
= reg_BatteryNotifyCode
;
3794 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] store code : %x\n",
3795 g_BatteryNotifyCode
);
3800 static DEVICE_ATTR(BatteryNotify
, 0664, show_BatteryNotify
, store_BatteryNotify
);
3802 static ssize_t
show_BN_TestMode(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3804 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] show_BN_TestMode : %x\n", g_BN_TestMode
);
3805 return sprintf(buf
, "%u\n", g_BN_TestMode
);
3808 static ssize_t
store_BN_TestMode(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
3811 char *pvalue
= NULL
;
3812 unsigned int reg_BN_TestMode
= 0;
3813 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] store_BN_TestMode\n");
3814 if (buf
!= NULL
&& size
!= 0) {
3815 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] buf is %s and size is %Zu\n", buf
,
3817 reg_BN_TestMode
= simple_strtoul(buf
, &pvalue
, 16);
3818 g_BN_TestMode
= reg_BN_TestMode
;
3819 battery_xlog_printk(BAT_LOG_CRTI
, "[Battery] store g_BN_TestMode : %x\n",
3825 static DEVICE_ATTR(BN_TestMode
, 0664, show_BN_TestMode
, store_BN_TestMode
);
3828 /* ///////////////////////////////////////////////////////////////////////////////////////// */
3829 /* // platform_driver API */
3830 /* ///////////////////////////////////////////////////////////////////////////////////////// */
3832 static int battery_cmd_read(char *buf
, char **start
, off_t off
, int count
, int *eof
, void *data
)
3838 "g_battery_thermal_throttling_flag=%d,\nbattery_cmd_thermal_test_mode=%d,\nbattery_cmd_thermal_test_mode_value=%d\n",
3839 g_battery_thermal_throttling_flag
, battery_cmd_thermal_test_mode
,
3840 battery_cmd_thermal_test_mode_value
);
3850 return len
< count
? len
: count
;
3854 static ssize_t
battery_cmd_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
3856 int len
= 0, bat_tt_enable
= 0, bat_thr_test_mode
= 0, bat_thr_test_value
= 0;
3859 len
= (count
< (sizeof(desc
) - 1)) ? count
: (sizeof(desc
) - 1);
3860 if (copy_from_user(desc
, buffer
, len
)) {
3865 if (sscanf(desc
, "%d %d %d", &bat_tt_enable
, &bat_thr_test_mode
, &bat_thr_test_value
) == 3) {
3866 g_battery_thermal_throttling_flag
= bat_tt_enable
;
3867 battery_cmd_thermal_test_mode
= bat_thr_test_mode
;
3868 battery_cmd_thermal_test_mode_value
= bat_thr_test_value
;
3870 battery_xlog_printk(BAT_LOG_CRTI
,
3871 "bat_tt_enable=%d, bat_thr_test_mode=%d, bat_thr_test_value=%d\n",
3872 g_battery_thermal_throttling_flag
,
3873 battery_cmd_thermal_test_mode
,
3874 battery_cmd_thermal_test_mode_value
);
3878 battery_xlog_printk(BAT_LOG_CRTI
,
3879 " bad argument, echo [bat_tt_enable] [bat_thr_test_mode] [bat_thr_test_value] > battery_cmd\n");
3885 static int proc_utilization_show(struct seq_file
*m
, void *v
)
3888 "=> g_battery_thermal_throttling_flag=%d,\nbattery_cmd_thermal_test_mode=%d,\nbattery_cmd_thermal_test_mode_value=%d\n",
3889 g_battery_thermal_throttling_flag
, battery_cmd_thermal_test_mode
,
3890 battery_cmd_thermal_test_mode_value
);
3892 seq_printf(m
, "=> get_usb_current_unlimited=%d,\ncmd_discharging = %d\n",
3893 get_usb_current_unlimited(), cmd_discharging
);
3897 static int proc_utilization_open(struct inode
*inode
, struct file
*file
)
3899 return single_open(file
, proc_utilization_show
, NULL
);
3902 static const struct file_operations battery_cmd_proc_fops
= {
3903 .open
= proc_utilization_open
,
3905 .write
= battery_cmd_write
,
3908 static ssize_t
current_cmd_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
3912 int cmd_current_unlimited
= false;
3913 U32 charging_enable
= false;
3915 len
= (count
< (sizeof(desc
) - 1)) ? count
: (sizeof(desc
) - 1);
3916 if (copy_from_user(desc
, buffer
, len
)) {
3921 if (sscanf(desc
, "%d %d", &cmd_current_unlimited
, &cmd_discharging
) == 2) {
3922 set_usb_current_unlimited(cmd_current_unlimited
);
3923 if (cmd_discharging
== 1) {
3924 charging_enable
= false;
3926 } else if (cmd_discharging
== 0) {
3927 charging_enable
= true;
3930 battery_charging_control(CHARGING_CMD_ENABLE
, &charging_enable
);
3932 battery_xlog_printk(BAT_LOG_CRTI
,
3933 "[current_cmd_write] cmd_current_unlimited=%d, cmd_discharging=%d\n",
3934 cmd_current_unlimited
, cmd_discharging
);
3937 battery_xlog_printk(BAT_LOG_CRTI
, " bad argument, echo [enable] > current_cmd\n");
3943 static int current_cmd_read(struct seq_file
*m
, void *v
)
3945 U32 charging_enable
= false;
3947 cmd_discharging
= 1;
3948 charging_enable
= false;
3951 battery_charging_control(CHARGING_CMD_ENABLE
, &charging_enable
);
3953 battery_xlog_printk(BAT_LOG_CRTI
,
3954 "[current_cmd_write] cmd_discharging=%d\n", cmd_discharging
);
3959 static int proc_utilization_open_cur_stop(struct inode
*inode
, struct file
*file
)
3961 return single_open(file
, current_cmd_read
, NULL
);
3963 static ssize_t
discharging_cmd_write(struct file
*file
, const char *buffer
, size_t count
, loff_t
*data
)
3967 U32 charging_enable
= false;
3969 len
= (count
< (sizeof(desc
) - 1)) ? count
: (sizeof(desc
) - 1);
3970 if (copy_from_user(desc
, buffer
, len
)) {
3975 if (sscanf(desc
, "%d %d", &charging_enable
, &adjust_power
) == 2) {
3976 battery_xlog_printk(BAT_LOG_CRTI
, "[current_cmd_write] adjust_power = %d\n", adjust_power
);
3979 battery_xlog_printk(BAT_LOG_CRTI
, " bad argument, echo [enable] > current_cmd\n");
3985 static const struct file_operations discharging_cmd_proc_fops
= {
3986 .open
= proc_utilization_open
,
3988 .write
= discharging_cmd_write
,
3991 static const struct file_operations current_cmd_proc_fops
= {
3992 .open
= proc_utilization_open_cur_stop
,
3994 .write
= current_cmd_write
,
3997 static int mt_batteryNotify_probe(struct platform_device
*dev
)
3999 int ret_device_file
= 0;
4000 /* struct proc_dir_entry *entry = NULL; */
4001 struct proc_dir_entry
*battery_dir
= NULL
;
4003 battery_xlog_printk(BAT_LOG_CRTI
, "******** mt_batteryNotify_probe!! ********\n");
4005 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_BatteryNotify
);
4006 ret_device_file
= device_create_file(&(dev
->dev
), &dev_attr_BN_TestMode
);
4008 battery_dir
= proc_mkdir("mtk_battery_cmd", NULL
);
4010 pr_err("[%s]: mkdir /proc/mtk_battery_cmd failed\n", __func__
);
4013 proc_create("battery_cmd", S_IRUGO
| S_IWUSR
, battery_dir
, &battery_cmd_proc_fops
);
4014 battery_xlog_printk(BAT_LOG_CRTI
, "proc_create battery_cmd_proc_fops\n");
4016 proc_create("current_cmd", S_IRUGO
| S_IWUSR
, battery_dir
, ¤t_cmd_proc_fops
);
4017 battery_xlog_printk(BAT_LOG_CRTI
, "proc_create current_cmd_proc_fops\n");
4018 proc_create("discharging_cmd", S_IRUGO
| S_IWUSR
, battery_dir
, &discharging_cmd_proc_fops
);
4019 battery_xlog_printk(BAT_LOG_CRTI
, "proc_create discharging_cmd_proc_fops\n");
4023 entry
= create_proc_entry("battery_cmd", S_IRUGO
| S_IWUSR
, battery_dir
);
4025 entry
->read_proc
= battery_cmd_read
;
4026 entry
->write_proc
= battery_cmd_write
;
4031 battery_xlog_printk(BAT_LOG_CRTI
, "******** mtk_battery_cmd!! ********\n");
4037 static const struct of_device_id mt_battery_of_match
[] = {
4038 { .compatible
= "mediatek,battery", },
4042 MODULE_DEVICE_TABLE(of
, mt_battery_of_match
);
4045 static int battery_pm_suspend(struct device
*device
)
4048 struct platform_device
*pdev
= to_platform_device(device
);
4049 BUG_ON(pdev
== NULL
);
4054 static int battery_pm_resume(struct device
*device
)
4057 struct platform_device
*pdev
= to_platform_device(device
);
4058 BUG_ON(pdev
== NULL
);
4063 static int battery_pm_freeze(struct device
*device
)
4066 struct platform_device
*pdev
= to_platform_device(device
);
4067 BUG_ON(pdev
== NULL
);
4072 static int battery_pm_restore(struct device
*device
)
4075 struct platform_device
*pdev
= to_platform_device(device
);
4076 BUG_ON(pdev
== NULL
);
4081 static int battery_pm_restore_noirq(struct device
*device
)
4084 struct platform_device
*pdev
= to_platform_device(device
);
4085 BUG_ON(pdev
== NULL
);
4090 struct dev_pm_ops battery_pm_ops
= {
4091 .suspend
= battery_pm_suspend
,
4092 .resume
= battery_pm_resume
,
4093 .freeze
= battery_pm_freeze
,
4094 .thaw
= battery_pm_restore
,
4095 .restore
= battery_pm_restore
,
4096 .restore_noirq
= battery_pm_restore_noirq
,
4099 #if defined(CONFIG_OF) || defined(BATTERY_MODULE_INIT)
4100 struct platform_device battery_device
= {
4106 static struct platform_driver battery_driver
= {
4107 .probe
= battery_probe
,
4108 .remove
= battery_remove
,
4109 .shutdown
= battery_shutdown
,
4112 .pm
= &battery_pm_ops
,
4117 static int battery_dts_probe(struct platform_device
*dev
)
4120 /* struct proc_dir_entry *entry = NULL; */
4121 struct proc_dir_entry
*battery_dir
= NULL
;
4123 battery_xlog_printk(BAT_LOG_CRTI
, "******** battery_dts_probe!! ********\n");
4125 battery_device
.dev
.of_node
= dev
->dev
.of_node
;
4126 ret
= platform_device_register(&battery_device
);
4128 battery_xlog_printk(BAT_LOG_CRTI
,
4129 "****[battery_dts_probe] Unable to register device (%d)\n", ret
);
4136 static struct platform_driver battery_dts_driver
= {
4137 .probe
= battery_dts_probe
,
4141 .name
= "battery-dts",
4143 .of_match_table
= mt_battery_of_match
,
4148 //--------------------------------------------------------
4150 static const struct of_device_id mt_bat_notify_of_match
[] = {
4151 { .compatible
= "mediatek,bat_notify", },
4155 MODULE_DEVICE_TABLE(of
, mt_bat_notify_of_match
);
4158 struct platform_device MT_batteryNotify_device
= {
4159 .name
= "mt-battery",
4163 static struct platform_driver mt_batteryNotify_driver
= {
4164 .probe
= mt_batteryNotify_probe
,
4166 .name
= "mt-battery",
4171 static int mt_batteryNotify_dts_probe(struct platform_device
*dev
)
4174 /* struct proc_dir_entry *entry = NULL; */
4175 struct proc_dir_entry
*battery_dir
= NULL
;
4177 battery_xlog_printk(BAT_LOG_CRTI
, "******** mt_batteryNotify_dts_probe!! ********\n");
4179 MT_batteryNotify_device
.dev
.of_node
= dev
->dev
.of_node
;
4180 ret
= platform_device_register(&MT_batteryNotify_device
);
4182 battery_xlog_printk(BAT_LOG_CRTI
,
4183 "****[mt_batteryNotify_dts] Unable to register device (%d)\n", ret
);
4191 static struct platform_driver mt_batteryNotify_dts_driver
= {
4192 .probe
= mt_batteryNotify_dts_probe
,
4194 .name
= "mt-dts-battery",
4196 .of_match_table
= mt_bat_notify_of_match
,
4201 //--------------------------------------------------------
4203 static int battery_pm_event(struct notifier_block
*notifier
, unsigned long pm_event
, void *unused
)
4206 case PM_HIBERNATION_PREPARE
: /* Going to hibernate */
4207 case PM_RESTORE_PREPARE
: /* Going to restore a saved image */
4208 case PM_SUSPEND_PREPARE
: /* Going to suspend the system */
4209 pr_warn("[%s] pm_event %lu\n", __func__
, pm_event
);
4210 battery_timer_pause();
4212 case PM_POST_HIBERNATION
: /* Hibernation finished */
4213 case PM_POST_SUSPEND
: /* Suspend finished */
4214 case PM_POST_RESTORE
: /* Restore failed */
4215 pr_warn("[%s] pm_event %lu\n", __func__
, pm_event
);
4216 battery_timer_resume();
4222 static struct notifier_block battery_pm_notifier_block
= {
4223 .notifier_call
= battery_pm_event
,
4227 static int __init
battery_init(void)
4231 printk("battery_init\n");
4237 #ifdef BATTERY_MODULE_INIT
4238 ret
= platform_device_register(&battery_device
);
4240 battery_xlog_printk(BAT_LOG_CRTI
,
4241 "****[battery_device] Unable to device register(%d)\n", ret
);
4247 ret
= platform_driver_register(&battery_driver
);
4249 battery_xlog_printk(BAT_LOG_CRTI
,
4250 "****[battery_driver] Unable to register driver (%d)\n", ret
);
4253 /* battery notofy UI */
4257 ret
= platform_device_register(&MT_batteryNotify_device
);
4259 battery_xlog_printk(BAT_LOG_CRTI
,
4260 "****[mt_batteryNotify] Unable to device register(%d)\n", ret
);
4264 ret
= platform_driver_register(&mt_batteryNotify_driver
);
4266 battery_xlog_printk(BAT_LOG_CRTI
,
4267 "****[mt_batteryNotify] Unable to register driver (%d)\n", ret
);
4271 ret
= platform_driver_register(&battery_dts_driver
);
4272 ret
= platform_driver_register(&mt_batteryNotify_dts_driver
);
4274 ret
= register_pm_notifier(&battery_pm_notifier_block
);
4276 printk("[%s] failed to register PM notifier %d\n", __func__
, ret
);
4278 battery_xlog_printk(BAT_LOG_CRTI
, "****[battery_driver] Initialization : DONE !!\n");
4282 #ifdef BATTERY_MODULE_INIT
4283 late_initcall(battery_init
);
4285 static void __exit
battery_exit(void)
4288 module_init(battery_init
);
4289 module_exit(battery_exit
);
4292 MODULE_AUTHOR("Oscar Liu");
4293 MODULE_DESCRIPTION("Battery Device Driver");
4294 MODULE_LICENSE("GPL");